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
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 ;; Recursive :-(.
41 ;; (require 'gnus-art)
42 (require 'nnoo)
43 (require 'mime-view)
44
45 (eval-when-compile
46   (require 'mime-play)
47   (require 'static))
48
49 (eval-and-compile
50   (autoload 'gnus-cache-articles-in-group "gnus-cache")
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-zcore-fuzz 0
216   "*Fuzziness factor for the zcore in the summary buffer.
217 Articles with scores closer than this to `gnus-summary-default-score'
218 will not be marked."
219   :group 'gnus-summary-format
220   :type 'integer)
221
222 (defcustom gnus-simplify-subject-fuzzy-regexp nil
223   "*Strings to be removed when doing fuzzy matches.
224 This can either be a regular expression or list of regular expressions
225 that will be removed from subject strings if fuzzy subject
226 simplification is selected."
227   :group 'gnus-thread
228   :type '(repeat regexp))
229
230 (defcustom gnus-show-threads t
231   "*If non-nil, display threads in summary mode."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-hide-subtree nil
236   "*If non-nil, hide all threads initially.
237 If threads are hidden, you have to run the command
238 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
239 to expose hidden threads."
240   :group 'gnus-thread
241   :type 'boolean)
242
243 (defcustom gnus-thread-hide-killed t
244   "*If non-nil, hide killed threads automatically."
245   :group 'gnus-thread
246   :type 'boolean)
247
248 (defcustom gnus-thread-ignore-subject t
249   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
250 If nil, articles that have different subjects from their parents will
251 start separate threads."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-operation-ignore-subject t
256   "*If non-nil, subjects will be ignored when doing thread commands.
257 This affects commands like `gnus-summary-kill-thread' and
258 `gnus-summary-lower-thread'.
259
260 If this variable is nil, articles in the same thread with different
261 subjects will not be included in the operation in question.  If this
262 variable is `fuzzy', only articles that have subjects that are fuzzily
263 equal will be included."
264   :group 'gnus-thread
265   :type '(choice (const :tag "off" nil)
266                  (const fuzzy)
267                  (sexp :tag "on" t)))
268
269 (defcustom gnus-thread-indent-level 4
270   "*Number that says how much each sub-thread should be indented."
271   :group 'gnus-thread
272   :type 'integer)
273
274 (defcustom gnus-auto-extend-newsgroup t
275   "*If non-nil, extend newsgroup forward and backward when requested."
276   :group 'gnus-summary-choose
277   :type 'boolean)
278
279 (defcustom gnus-auto-select-first t
280   "*If nil, don't select the first unread article when entering a group.
281 If this variable is `best', select the highest-scored unread article
282 in the group.  If t, select the first unread article.
283
284 This variable can also be a function to place point on a likely
285 subject line.  Useful values include `gnus-summary-first-unread-subject',
286 `gnus-summary-first-unread-article' and
287 `gnus-summary-best-unread-article'.
288
289 If you want to prevent automatic selection of the first unread article
290 in some newsgroups, set the variable to nil in
291 `gnus-select-group-hook'."
292   :group 'gnus-group-select
293   :type '(choice (const :tag "none" nil)
294                  (const best)
295                  (sexp :menu-tag "first" t)
296                  (function-item gnus-summary-first-unread-subject)
297                  (function-item gnus-summary-first-unread-article)
298                  (function-item gnus-summary-best-unread-article)))
299
300 (defcustom gnus-dont-select-after-jump-to-other-group nil
301   "If non-nil, don't select the first unread article after entering the
302 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
303 it is depend on the value of `gnus-auto-select-first' whether to select
304 or not."
305   :group 'gnus-group-select
306   :type 'boolean)
307
308 (defcustom gnus-auto-select-next t
309   "*If non-nil, offer to go to the next group from the end of the previous.
310 If the value is t and the next newsgroup is empty, Gnus will exit
311 summary mode and go back to group mode.  If the value is neither nil
312 nor t, Gnus will select the following unread newsgroup.  In
313 particular, if the value is the symbol `quietly', the next unread
314 newsgroup will be selected without any confirmation, and if it is
315 `almost-quietly', the next group will be selected without any
316 confirmation if you are located on the last article in the group.
317 Finally, if this variable is `slightly-quietly', the `Z n' command
318 will go to the next group without confirmation."
319   :group 'gnus-summary-maneuvering
320   :type '(choice (const :tag "off" nil)
321                  (const quietly)
322                  (const almost-quietly)
323                  (const slightly-quietly)
324                  (sexp :menu-tag "on" t)))
325
326 (defcustom gnus-auto-select-same nil
327   "*If non-nil, select the next article with the same subject.
328 If there are no more articles with the same subject, go to
329 the first unread article."
330   :group 'gnus-summary-maneuvering
331   :type 'boolean)
332
333 (defcustom gnus-summary-check-current nil
334   "*If non-nil, consider the current article when moving.
335 The \"unread\" movement commands will stay on the same line if the
336 current article is unread."
337   :group 'gnus-summary-maneuvering
338   :type 'boolean)
339
340 (defcustom gnus-auto-center-summary t
341   "*If non-nil, always center the current summary buffer.
342 In particular, if `vertical' do only vertical recentering.  If non-nil
343 and non-`vertical', do both horizontal and vertical recentering."
344   :group 'gnus-summary-maneuvering
345   :type '(choice (const :tag "none" nil)
346                  (const vertical)
347                  (integer :tag "height")
348                  (sexp :menu-tag "both" t)))
349
350 (defcustom gnus-show-all-headers nil
351   "*If non-nil, don't hide any headers."
352   :group 'gnus-article-hiding
353   :group 'gnus-article-headers
354   :type 'boolean)
355
356 (defcustom gnus-summary-ignore-duplicates nil
357   "*If non-nil, ignore articles with identical Message-ID headers."
358   :group 'gnus-summary
359   :type 'boolean)
360
361 (defcustom gnus-single-article-buffer t
362   "*If non-nil, display all articles in the same buffer.
363 If nil, each group will get its own article buffer."
364   :group 'gnus-article-various
365   :type 'boolean)
366
367 (defcustom gnus-break-pages t
368   "*If non-nil, do page breaking on articles.
369 The page delimiter is specified by the `gnus-page-delimiter'
370 variable."
371   :group 'gnus-article-various
372   :type 'boolean)
373
374 (defcustom gnus-show-mime t
375   "*If non-nil, do mime processing of articles.
376 The articles will simply be fed to the function given by
377 `gnus-article-display-method-for-mime'."
378   :group 'gnus-article-mime
379   :type 'boolean)
380
381 (defcustom gnus-move-split-methods nil
382   "*Variable used to suggest where articles are to be moved to.
383 It uses the same syntax as the `gnus-split-methods' variable.
384 However, whereas `gnus-split-methods' specifies file names as targets,
385 this variable specifies group names."
386   :group 'gnus-summary-mail
387   :type '(repeat (choice (list :value (fun) function)
388                          (cons :value ("" "") regexp (repeat string))
389                          (sexp :value nil))))
390
391 (defcustom gnus-unread-mark ?  ;Whitespace
392   "*Mark used for unread articles."
393   :group 'gnus-summary-marks
394   :type 'character)
395
396 (defcustom gnus-ticked-mark ?!
397   "*Mark used for ticked articles."
398   :group 'gnus-summary-marks
399   :type 'character)
400
401 (defcustom gnus-dormant-mark ??
402   "*Mark used for dormant articles."
403   :group 'gnus-summary-marks
404   :type 'character)
405
406 (defcustom gnus-del-mark ?r
407   "*Mark used for del'd articles."
408   :group 'gnus-summary-marks
409   :type 'character)
410
411 (defcustom gnus-read-mark ?R
412   "*Mark used for read articles."
413   :group 'gnus-summary-marks
414   :type 'character)
415
416 (defcustom gnus-expirable-mark ?E
417   "*Mark used for expirable articles."
418   :group 'gnus-summary-marks
419   :type 'character)
420
421 (defcustom gnus-killed-mark ?K
422   "*Mark used for killed articles."
423   :group 'gnus-summary-marks
424   :type 'character)
425
426 (defcustom gnus-souped-mark ?F
427   "*Mark used for killed articles."
428   :group 'gnus-summary-marks
429   :type 'character)
430
431 (defcustom gnus-kill-file-mark ?X
432   "*Mark used for articles killed by kill files."
433   :group 'gnus-summary-marks
434   :type 'character)
435
436 (defcustom gnus-low-score-mark ?Y
437   "*Mark used for articles with a low score."
438   :group 'gnus-summary-marks
439   :type 'character)
440
441 (defcustom gnus-catchup-mark ?C
442   "*Mark used for articles that are caught up."
443   :group 'gnus-summary-marks
444   :type 'character)
445
446 (defcustom gnus-replied-mark ?A
447   "*Mark used for articles that have been replied to."
448   :group 'gnus-summary-marks
449   :type 'character)
450
451 (defcustom gnus-cached-mark ?*
452   "*Mark used for articles that are in the cache."
453   :group 'gnus-summary-marks
454   :type 'character)
455
456 (defcustom gnus-saved-mark ?S
457   "*Mark used for articles that have been saved to."
458   :group 'gnus-summary-marks
459   :type 'character)
460
461 (defcustom gnus-no-mark ?  ;Whitespace
462   "*Mark used for articles that have no other secondary mark."
463   :group 'gnus-summary-marks
464   :type 'character)
465
466 (defcustom gnus-ancient-mark ?O
467   "*Mark used for ancient articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-sparse-mark ?Q
472   "*Mark used for sparsely reffed articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-canceled-mark ?G
477   "*Mark used for canceled articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-duplicate-mark ?M
482   "*Mark used for duplicate articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-undownloaded-mark ?@
487   "*Mark used for articles that weren't downloaded."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-downloadable-mark ?%
492   "*Mark used for articles that are to be downloaded."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-unsendable-mark ?=
497   "*Mark used for articles that won't be sent."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-score-over-mark ?+
502   "*Score mark used for articles with high scores."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-score-below-mark ?-
507   "*Score mark used for articles with low scores."
508   :group 'gnus-summary-marks
509   :type 'character)
510
511 (defcustom gnus-empty-thread-mark ?  ;Whitespace
512   "*There is no thread under the article."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-not-empty-thread-mark ?=
517   "*There is a thread under the article."
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-view-pseudo-asynchronously nil
522   "*If non-nil, Gnus will view pseudo-articles asynchronously."
523   :group 'gnus-extract-view
524   :type 'boolean)
525
526 (defcustom gnus-auto-expirable-marks
527   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
528         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
529         gnus-souped-mark gnus-duplicate-mark)
530   "*The list of marks converted into expiration if a group is auto-expirable."
531   :version "21.1"
532   :group 'gnus-summary
533   :type '(repeat character))
534
535 (defcustom gnus-inhibit-user-auto-expire t
536   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
537   :version "21.1"
538   :group 'gnus-summary
539   :type 'boolean)
540
541 (defcustom gnus-view-pseudos nil
542   "*If `automatic', pseudo-articles will be viewed automatically.
543 If `not-confirm', pseudos will be viewed automatically, and the user
544 will not be asked to confirm the command."
545   :group 'gnus-extract-view
546   :type '(choice (const :tag "off" nil)
547                  (const automatic)
548                  (const not-confirm)))
549
550 (defcustom gnus-view-pseudos-separately t
551   "*If non-nil, one pseudo-article will be created for each file to be viewed.
552 If nil, all files that use the same viewing command will be given as a
553 list of parameters to that command."
554   :group 'gnus-extract-view
555   :type 'boolean)
556
557 (defcustom gnus-insert-pseudo-articles t
558   "*If non-nil, insert pseudo-articles when decoding articles."
559   :group 'gnus-extract-view
560   :type 'boolean)
561
562 (defcustom gnus-summary-dummy-line-format
563   "  %(:                          :%) %S\n"
564   "*The format specification for the dummy roots in the summary buffer.
565 It works along the same lines as a normal formatting string,
566 with some simple extensions.
567
568 %S  The subject"
569   :group 'gnus-threading
570   :type 'string)
571
572 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
573   "*The format specification for the summary mode line.
574 It works along the same lines as a normal formatting string,
575 with some simple extensions:
576
577 %G  Group name
578 %p  Unprefixed group name
579 %A  Current article number
580 %z  Current article score
581 %V  Gnus version
582 %U  Number of unread articles in the group
583 %e  Number of unselected articles in the group
584 %Z  A string with unread/unselected article counts
585 %g  Shortish group name
586 %S  Subject of the current article
587 %u  User-defined spec
588 %s  Current score file name
589 %d  Number of dormant articles
590 %r  Number of articles that have been marked as read in this session
591 %E  Number of articles expunged by the score files"
592   :group 'gnus-summary-format
593   :type 'string)
594
595 (defcustom gnus-list-identifiers nil
596   "Regexp that matches list identifiers to be removed from subject.
597 This can also be a list of regexps."
598   :version "21.1"
599   :group 'gnus-summary-format
600   :group 'gnus-article-hiding
601   :type '(choice (const :tag "none" nil)
602                  (regexp :value ".*")
603                  (repeat :value (".*") regexp)))
604
605 (defcustom gnus-summary-mark-below 0
606   "*Mark all articles with a score below this variable as read.
607 This variable is local to each summary buffer and usually set by the
608 score file."
609   :group 'gnus-score-default
610   :type 'integer)
611
612 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
613   "*List of functions used for sorting articles in the summary buffer.
614 This variable is only used when not using a threaded display."
615   :group 'gnus-summary-sort
616   :type '(repeat (choice (function-item gnus-article-sort-by-number)
617                          (function-item gnus-article-sort-by-author)
618                          (function-item gnus-article-sort-by-subject)
619                          (function-item gnus-article-sort-by-date)
620                          (function-item gnus-article-sort-by-score)
621                          (function :tag "other"))))
622
623 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
624   "*List of functions used for sorting threads in the summary buffer.
625 By default, threads are sorted by article number.
626
627 Each function takes two threads and return non-nil if the first thread
628 should be sorted before the other.  If you use more than one function,
629 the primary sort function should be the last.  You should probably
630 always include `gnus-thread-sort-by-number' in the list of sorting
631 functions -- preferably first.
632
633 Ready-made functions include `gnus-thread-sort-by-number',
634 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
635 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
636 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
637   :group 'gnus-summary-sort
638   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
639                          (function-item gnus-thread-sort-by-author)
640                          (function-item gnus-thread-sort-by-subject)
641                          (function-item gnus-thread-sort-by-date)
642                          (function-item gnus-thread-sort-by-score)
643                          (function-item gnus-thread-sort-by-total-score)
644                          (function :tag "other"))))
645
646 (defcustom gnus-thread-score-function '+
647   "*Function used for calculating the total score of a thread.
648
649 The function is called with the scores of the article and each
650 subthread and should then return the score of the thread.
651
652 Some functions you can use are `+', `max', or `min'."
653   :group 'gnus-summary-sort
654   :type 'function)
655
656 (defcustom gnus-summary-expunge-below nil
657   "All articles that have a score less than this variable will be expunged.
658 This variable is local to the summary buffers."
659   :group 'gnus-score-default
660   :type '(choice (const :tag "off" nil)
661                  integer))
662
663 (defcustom gnus-thread-expunge-below nil
664   "All threads that have a total score less than this variable will be expunged.
665 See `gnus-thread-score-function' for en explanation of what a
666 \"thread score\" is.
667
668 This variable is local to the summary buffers."
669   :group 'gnus-threading
670   :group 'gnus-score-default
671   :type '(choice (const :tag "off" nil)
672                  integer))
673
674 (defcustom gnus-summary-mode-hook nil
675   "*A hook for Gnus summary mode.
676 This hook is run before any variables are set in the summary buffer."
677   :options '(turn-on-gnus-mailing-list-mode)
678   :group 'gnus-summary-various
679   :type 'hook)
680
681 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
682 (when (featurep 'xemacs)
683   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
684   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
685   (add-hook 'gnus-summary-mode-hook
686             'gnus-xmas-switch-horizontal-scrollbar-off))
687
688 (defcustom gnus-summary-menu-hook nil
689   "*Hook run after the creation of the summary mode menu."
690   :group 'gnus-summary-visual
691   :type 'hook)
692
693 (defcustom gnus-summary-exit-hook nil
694   "*A hook called on exit from the summary buffer.
695 It will be called with point in the group buffer."
696   :group 'gnus-summary-exit
697   :type 'hook)
698
699 (defcustom gnus-summary-prepare-hook nil
700   "*A hook called after the summary buffer has been generated.
701 If you want to modify the summary buffer, you can use this hook."
702   :group 'gnus-summary-various
703   :type 'hook)
704
705 (defcustom gnus-summary-prepared-hook nil
706   "*A hook called as the last thing after the summary buffer has been generated."
707   :group 'gnus-summary-various
708   :type 'hook)
709
710 (defcustom gnus-summary-generate-hook nil
711   "*A hook run just before generating the summary buffer.
712 This hook is commonly used to customize threading variables and the
713 like."
714   :group 'gnus-summary-various
715   :type 'hook)
716
717 (defcustom gnus-select-group-hook nil
718   "*A hook called when a newsgroup is selected.
719
720 If you'd like to simplify subjects like the
721 `gnus-summary-next-same-subject' command does, you can use the
722 following hook:
723
724  (setq gnus-select-group-hook
725       (list
726         (lambda ()
727           (mapcar (lambda (header)
728                      (mail-header-set-subject
729                       header
730                       (gnus-simplify-subject
731                        (mail-header-subject header) 're-only)))
732                   gnus-newsgroup-headers))))"
733   :group 'gnus-group-select
734   :type 'hook)
735
736 (defcustom gnus-select-article-hook nil
737   "*A hook called when an article is selected."
738   :group 'gnus-summary-choose
739   :type 'hook)
740
741 (defcustom gnus-visual-mark-article-hook
742   (list 'gnus-highlight-selected-summary)
743   "*Hook run after selecting an article in the summary buffer.
744 It is meant to be used for highlighting the article in some way.  It
745 is not run if `gnus-visual' is nil."
746   :group 'gnus-summary-visual
747   :type 'hook)
748
749 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
750   "*A hook called before parsing the headers."
751   :group 'gnus-various
752   :type 'hook)
753
754 (defcustom gnus-exit-group-hook nil
755   "*A hook called when exiting summary mode.
756 This hook is not called from the non-updating exit commands like `Q'."
757   :group 'gnus-various
758   :type 'hook)
759
760 (defcustom gnus-summary-update-hook
761   (list 'gnus-summary-highlight-line)
762   "*A hook called when a summary line is changed.
763 The hook will not be called if `gnus-visual' is nil.
764
765 The default function `gnus-summary-highlight-line' will
766 highlight the line according to the `gnus-summary-highlight'
767 variable."
768   :group 'gnus-summary-visual
769   :type 'hook)
770
771 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
772   "*A hook called when an article is selected for the first time.
773 The hook is intended to mark an article as read (or unread)
774 automatically when it is selected."
775   :group 'gnus-summary-choose
776   :type 'hook)
777
778 (defcustom gnus-group-no-more-groups-hook nil
779   "*A hook run when returning to group mode having no more (unread) groups."
780   :group 'gnus-group-select
781   :type 'hook)
782
783 (defcustom gnus-ps-print-hook nil
784   "*A hook run before ps-printing something from Gnus."
785   :group 'gnus-summary
786   :type 'hook)
787
788 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
789   "Face used for highlighting the current article in the summary buffer."
790   :group 'gnus-summary-visual
791   :type 'face)
792
793 (defcustom gnus-summary-highlight
794   '(((= mark gnus-canceled-mark)
795      . gnus-summary-cancelled-face)
796     ((and (> score default)
797           (or (= mark gnus-dormant-mark)
798               (= mark gnus-ticked-mark)))
799      . gnus-summary-high-ticked-face)
800     ((and (< score default)
801           (or (= mark gnus-dormant-mark)
802               (= mark gnus-ticked-mark)))
803      . gnus-summary-low-ticked-face)
804     ((or (= mark gnus-dormant-mark)
805          (= mark gnus-ticked-mark))
806      . gnus-summary-normal-ticked-face)
807     ((and (> score default) (= mark gnus-ancient-mark))
808      . gnus-summary-high-ancient-face)
809     ((and (< score default) (= mark gnus-ancient-mark))
810      . gnus-summary-low-ancient-face)
811     ((= mark gnus-ancient-mark)
812      . gnus-summary-normal-ancient-face)
813     ((and (> score default) (= mark gnus-unread-mark))
814      . gnus-summary-high-unread-face)
815     ((and (< score default) (= mark gnus-unread-mark))
816      . gnus-summary-low-unread-face)
817     ((and (memq article gnus-newsgroup-incorporated)
818           (= mark gnus-unread-mark))
819      . gnus-summary-incorporated-face)
820     ((= mark gnus-unread-mark)
821      . gnus-summary-normal-unread-face)
822     ((and (> score default) (memq mark (list gnus-downloadable-mark
823                                              gnus-undownloaded-mark)))
824      . gnus-summary-high-unread-face)
825     ((and (< score default) (memq mark (list gnus-downloadable-mark
826                                              gnus-undownloaded-mark)))
827      . gnus-summary-low-unread-face)
828     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
829      . gnus-summary-normal-unread-face)
830     ((> score default)
831      . gnus-summary-high-read-face)
832     ((< score default)
833      . gnus-summary-low-read-face)
834     (t
835      . gnus-summary-normal-read-face))
836   "*Controls the highlighting of summary buffer lines.
837
838 A list of (FORM . FACE) pairs.  When deciding how a a particular
839 summary line should be displayed, each form is evaluated.  The content
840 of the face field after the first true form is used.  You can change
841 how those summary lines are displayed, by editing the face field.
842
843 You can use the following variables in the FORM field.
844
845 score:   The articles score
846 default: The default article score.
847 below:   The score below which articles are automatically marked as read.
848 mark:    The articles mark."
849   :group 'gnus-summary-visual
850   :type '(repeat (cons (sexp :tag "Form" nil)
851                        face)))
852
853 (defcustom gnus-alter-header-function nil
854   "Function called to allow alteration of article header structures.
855 The function is called with one parameter, the article header vector,
856 which it may alter in any way.")
857
858 (defvar gnus-decode-encoded-word-function
859   (mime-find-field-decoder 'From 'nov)
860   "Variable that says which function should be used to decode a string with encoded words.")
861
862 (defcustom gnus-extra-headers nil
863   "*Extra headers to parse."
864   :version "21.1"
865   :group 'gnus-summary
866   :type '(repeat symbol))
867
868 (defcustom gnus-ignored-from-addresses
869   (and user-mail-address (regexp-quote user-mail-address))
870   "*Regexp of From headers that may be suppressed in favor of To headers."
871   :version "21.1"
872   :group 'gnus-summary
873   :type 'regexp)
874
875 (defcustom gnus-group-charset-alist
876   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
877     ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
878     ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
879     ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
880     ("^relcom\\>" koi8-r)
881     ("^fido7\\>" koi8-r)
882     ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
883     ("^israel\\>" iso-8859-1)
884     ("^han\\>" euc-kr)
885     ("^alt.chinese.text.big5\\>" chinese-big5)
886     ("^soc.culture.vietnamese\\>" vietnamese-viqr)
887     ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
888     (".*" iso-8859-1))
889   "Alist of regexps (to match group names) and default charsets to be used when reading."
890   :type '(repeat (list (regexp :tag "Group")
891                        (symbol :tag "Charset")))
892   :group 'gnus-charset)
893
894 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
895   "List of charsets that should be ignored.
896 When these charsets are used in the \"charset\" parameter, the
897 default charset will be used instead."
898   :version "21.1"
899   :type '(repeat symbol)
900   :group 'gnus-charset)
901
902 (defcustom gnus-group-ignored-charsets-alist
903   '(("alt\\.chinese\\.text" iso-8859-1))
904   "Alist of regexps (to match group names) and charsets that should be ignored.
905 When these charsets are used in the \"charset\" parameter, the
906 default charset will be used instead."
907   :type '(repeat (cons (regexp :tag "Group")
908                        (repeat symbol)))
909   :group 'gnus-charset)
910
911 (defcustom gnus-group-highlight-words-alist nil
912   "Alist of group regexps and highlight regexps.
913 This variable uses the same syntax as `gnus-emphasis-alist'."
914   :version "21.1"
915   :type '(repeat (cons (regexp :tag "Group")
916                        (repeat (list (regexp :tag "Highlight regexp")
917                                      (number :tag "Group for entire word" 0)
918                                      (number :tag "Group for displayed part" 0)
919                                      (symbol :tag "Face"
920                                              gnus-emphasis-highlight-words)))))
921   :group 'gnus-summary-visual)
922
923 (defcustom gnus-use-wheel nil
924   "Use Intelli-mouse on summary movement"
925   :type 'boolean
926   :group 'gnus-summary-maneuvering)
927
928 (defcustom gnus-wheel-scroll-amount '(5 . 1)
929   "Amount to scroll messages by spinning the mouse wheel.
930 This is actually a cons cell, where the first item is the amount to scroll
931 on a normal wheel event, and the second is the amount to scroll when the
932 wheel is moved with the shift key depressed."
933   :type '(cons (integer :tag "Shift") integer)
934   :group 'gnus-summary-maneuvering)
935
936 (defcustom gnus-wheel-edge-resistance 2
937   "How hard it should be to change the current article
938 by moving the mouse over the edge of the article window."
939   :type 'integer
940   :group 'gnus-summary-maneuvering)
941
942 (defcustom gnus-summary-show-article-charset-alist
943   nil
944   "Alist of number and charset.
945 The article will be shown with the charset corresponding to the
946 numbered argument.
947 For example: ((1 . cn-gb-2312) (2 . big5))."
948   :version "21.1"
949   :type '(repeat (cons (number :tag "Argument" 1)
950                        (symbol :tag "Charset")))
951   :group 'gnus-charset)
952
953 (defcustom gnus-preserve-marks t
954   "Whether marks are preserved when moving, copying and respooling messages."
955   :version "21.1"
956   :type 'boolean
957   :group 'gnus-summary-marks)
958
959 (defcustom gnus-alter-articles-to-read-function nil
960   "Function to be called to alter the list of articles to be selected."
961   :type 'function
962   :group 'gnus-summary)
963
964 (defcustom gnus-orphan-score nil
965   "*All orphans get this score added.  Set in the score file."
966   :group 'gnus-score-default
967   :type '(choice (const nil)
968                  integer))
969
970 (defcustom gnus-summary-save-parts-default-mime "image/.*"
971   "*A regexp to match MIME parts when saving multiple parts of a message
972 with gnus-summary-save-parts (X m). This regexp will be used by default
973 when prompting the user for which type of files to save."
974   :group 'gnus-summary
975   :type 'regexp)
976
977
978 (defcustom gnus-summary-save-parts-default-mime "image/.*"
979   "*A regexp to match MIME parts when saving multiple parts of a message
980 with gnus-summary-save-parts (X m). This regexp will be used by default
981 when prompting the user for which type of files to save."
982   :group 'gnus-summary
983   :type 'regexp)
984
985
986 ;;; Internal variables
987
988 (defvar gnus-article-mime-handles nil)
989 (defvar gnus-article-decoded-p nil)
990 (defvar gnus-article-charset nil)
991 (defvar gnus-article-ignored-charsets nil)
992 (defvar gnus-scores-exclude-files nil)
993 (defvar gnus-page-broken nil)
994 (defvar gnus-inhibit-mime-unbuttonizing nil)
995
996 (defvar gnus-original-article nil)
997 (defvar gnus-article-internal-prepare-hook nil)
998 (defvar gnus-newsgroup-process-stack nil)
999
1000 (defvar gnus-thread-indent-array nil)
1001 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1002 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1003   "Function called to sort the articles within a thread after it has been gathered together.")
1004
1005 (defvar gnus-summary-save-parts-type-history nil)
1006 (defvar gnus-summary-save-parts-last-directory nil)
1007
1008 (defvar gnus-summary-save-parts-type-history nil)
1009 (defvar gnus-summary-save-parts-last-directory nil)
1010
1011 ;; Avoid highlighting in kill files.
1012 (defvar gnus-summary-inhibit-highlight nil)
1013 (defvar gnus-newsgroup-selected-overlay nil)
1014 (defvar gnus-inhibit-limiting nil)
1015 (defvar gnus-newsgroup-adaptive-score-file nil)
1016 (defvar gnus-current-score-file nil)
1017 (defvar gnus-current-move-group nil)
1018 (defvar gnus-current-copy-group nil)
1019 (defvar gnus-current-crosspost-group nil)
1020
1021 (defvar gnus-newsgroup-dependencies nil)
1022 (defvar gnus-newsgroup-adaptive nil)
1023 (defvar gnus-summary-display-article-function nil)
1024 (defvar gnus-summary-highlight-line-function nil
1025   "Function called after highlighting a summary line.")
1026
1027 (defvar gnus-summary-line-format-alist
1028   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1029     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1030     (?s gnus-tmp-subject-or-nil ?s)
1031     (?n gnus-tmp-name ?s)
1032     (?A (std11-address-string
1033          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1034     (?a (or (std11-full-name-string
1035              (car (mime-entity-read-field gnus-tmp-header 'From)))
1036             gnus-tmp-from) ?s)
1037     (?F gnus-tmp-from ?s)
1038     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1039     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1040     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1041     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1042     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1043     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1044     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1045     (?L gnus-tmp-lines ?d)
1046     (?I gnus-tmp-indentation ?s)
1047     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1048     (?R gnus-tmp-replied ?c)
1049     (?\[ gnus-tmp-opening-bracket ?c)
1050     (?\] gnus-tmp-closing-bracket ?c)
1051     (?\> (make-string gnus-tmp-level ? ) ?s)
1052     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1053     (?i gnus-tmp-score ?d)
1054     (?z gnus-tmp-score-char ?c)
1055     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1056     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1057     (?U gnus-tmp-unread ?c)
1058     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
1059     (?t (gnus-summary-number-of-articles-in-thread
1060          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1061         ?d)
1062     (?e (gnus-summary-number-of-articles-in-thread
1063          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1064         ?c)
1065     (?u gnus-tmp-user-defined ?s)
1066     (?P (gnus-pick-line-number) ?d))
1067   "An alist of format specifications that can appear in summary lines.
1068 These are paired with what variables they correspond with, along with
1069 the type of the variable (string, integer, character, etc).")
1070
1071 (defvar gnus-summary-dummy-line-format-alist
1072   `((?S gnus-tmp-subject ?s)
1073     (?N gnus-tmp-number ?d)
1074     (?u gnus-tmp-user-defined ?s)))
1075
1076 (defvar gnus-summary-mode-line-format-alist
1077   `((?G gnus-tmp-group-name ?s)
1078     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1079     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1080     (?A gnus-tmp-article-number ?d)
1081     (?Z gnus-tmp-unread-and-unselected ?s)
1082     (?V gnus-version ?s)
1083     (?U gnus-tmp-unread-and-unticked ?d)
1084     (?S gnus-tmp-subject ?s)
1085     (?e gnus-tmp-unselected ?d)
1086     (?u gnus-tmp-user-defined ?s)
1087     (?d (length gnus-newsgroup-dormant) ?d)
1088     (?t (length gnus-newsgroup-marked) ?d)
1089     (?r (length gnus-newsgroup-reads) ?d)
1090     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1091     (?E gnus-newsgroup-expunged-tally ?d)
1092     (?s (gnus-current-score-file-nondirectory) ?s)))
1093
1094 (defvar gnus-last-search-regexp nil
1095   "Default regexp for article search command.")
1096
1097 (defvar gnus-summary-search-article-matched-data nil
1098   "Last matched data of article search command.  It is the local variable
1099 in `gnus-article-buffer' which consists of the list of start position,
1100 end position and text.")
1101
1102 (defvar gnus-last-shell-command nil
1103   "Default shell command on article.")
1104
1105 (defvar gnus-newsgroup-begin nil)
1106 (defvar gnus-newsgroup-end nil)
1107 (defvar gnus-newsgroup-last-rmail nil)
1108 (defvar gnus-newsgroup-last-mail nil)
1109 (defvar gnus-newsgroup-last-folder nil)
1110 (defvar gnus-newsgroup-last-file nil)
1111 (defvar gnus-newsgroup-auto-expire nil)
1112 (defvar gnus-newsgroup-active nil)
1113
1114 (defvar gnus-newsgroup-data nil)
1115 (defvar gnus-newsgroup-data-reverse nil)
1116 (defvar gnus-newsgroup-limit nil)
1117 (defvar gnus-newsgroup-limits nil)
1118
1119 (defvar gnus-newsgroup-unreads nil
1120   "List of unread articles in the current newsgroup.")
1121
1122 (defvar gnus-newsgroup-unselected nil
1123   "List of unselected unread articles in the current newsgroup.")
1124
1125 (defvar gnus-newsgroup-reads nil
1126   "Alist of read articles and article marks in the current newsgroup.")
1127
1128 (defvar gnus-newsgroup-expunged-tally nil)
1129
1130 (defvar gnus-newsgroup-marked nil
1131   "List of ticked articles in the current newsgroup (a subset of unread art).")
1132
1133 (defvar gnus-newsgroup-killed nil
1134   "List of ranges of articles that have been through the scoring process.")
1135
1136 (defvar gnus-newsgroup-cached nil
1137   "List of articles that come from the article cache.")
1138
1139 (defvar gnus-newsgroup-saved nil
1140   "List of articles that have been saved.")
1141
1142 (defvar gnus-newsgroup-kill-headers nil)
1143
1144 (defvar gnus-newsgroup-replied nil
1145   "List of articles that have been replied to in the current newsgroup.")
1146
1147 (defvar gnus-newsgroup-expirable nil
1148   "List of articles in the current newsgroup that can be expired.")
1149
1150 (defvar gnus-newsgroup-processable nil
1151   "List of articles in the current newsgroup that can be processed.")
1152
1153 (defvar gnus-newsgroup-downloadable nil
1154   "List of articles in the current newsgroup that can be processed.")
1155
1156 (defvar gnus-newsgroup-undownloaded nil
1157   "List of articles in the current newsgroup that haven't been downloaded..")
1158
1159 (defvar gnus-newsgroup-unsendable nil
1160   "List of articles in the current newsgroup that won't be sent.")
1161
1162 (defvar gnus-newsgroup-bookmarks nil
1163   "List of articles in the current newsgroup that have bookmarks.")
1164
1165 (defvar gnus-newsgroup-dormant nil
1166   "List of dormant articles in the current newsgroup.")
1167
1168 (defvar gnus-newsgroup-scored nil
1169   "List of scored articles in the current newsgroup.")
1170
1171 (defvar gnus-newsgroup-incorporated nil
1172   "List of incorporated articles in the current newsgroup.")
1173
1174 (defvar gnus-newsgroup-headers nil
1175   "List of article headers in the current newsgroup.")
1176
1177 (defvar gnus-newsgroup-threads nil)
1178
1179 (defvar gnus-newsgroup-prepared nil
1180   "Whether the current group has been prepared properly.")
1181
1182 (defvar gnus-newsgroup-ancient nil
1183   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1184
1185 (defvar gnus-newsgroup-sparse nil)
1186
1187 (defvar gnus-current-article nil)
1188 (defvar gnus-article-current nil)
1189 (defvar gnus-current-headers nil)
1190 (defvar gnus-have-all-headers nil)
1191 (defvar gnus-last-article nil)
1192 (defvar gnus-newsgroup-history nil)
1193 (defvar gnus-newsgroup-charset nil)
1194 (defvar gnus-newsgroup-ephemeral-charset nil)
1195 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1196
1197 (defvar gnus-article-before-search nil)
1198
1199 (defconst gnus-summary-local-variables
1200   '(gnus-newsgroup-name
1201     gnus-newsgroup-begin gnus-newsgroup-end
1202     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1203     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1204     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1205     gnus-newsgroup-unselected gnus-newsgroup-marked
1206     gnus-newsgroup-reads gnus-newsgroup-saved
1207     gnus-newsgroup-replied gnus-newsgroup-expirable
1208     gnus-newsgroup-processable gnus-newsgroup-killed
1209     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1210     gnus-newsgroup-unsendable
1211     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1212     gnus-newsgroup-headers gnus-newsgroup-threads
1213     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1214     gnus-current-article gnus-current-headers gnus-have-all-headers
1215     gnus-last-article gnus-article-internal-prepare-hook
1216     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1217     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1218     gnus-thread-expunge-below
1219     gnus-score-alist gnus-current-score-file
1220     (gnus-summary-expunge-below . global)
1221     (gnus-summary-mark-below . global)
1222     (gnus-orphan-score . global)
1223     gnus-newsgroup-active gnus-scores-exclude-files
1224     gnus-newsgroup-history gnus-newsgroup-ancient
1225     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1226     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1227     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1228     (gnus-newsgroup-expunged-tally . 0)
1229     gnus-cache-removable-articles gnus-newsgroup-cached
1230     gnus-newsgroup-data gnus-newsgroup-data-reverse
1231     gnus-newsgroup-limit gnus-newsgroup-limits
1232     gnus-newsgroup-charset
1233     gnus-newsgroup-incorporated)
1234   "Variables that are buffer-local to the summary buffers.")
1235
1236 (defvar gnus-newsgroup-variables nil
1237   "Variables that have separate values in the newsgroups.")
1238
1239 ;; Byte-compiler warning.
1240 (eval-when-compile (defvar gnus-article-mode-map))
1241
1242 ;; Subject simplification.
1243
1244 (defun gnus-simplify-whitespace (str)
1245   "Remove excessive whitespace from STR."
1246   (let ((mystr str))
1247     ;; Multiple spaces.
1248     (while (string-match "[ \t][ \t]+" mystr)
1249       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1250                           " "
1251                           (substring mystr (match-end 0)))))
1252     ;; Leading spaces.
1253     (when (string-match "^[ \t]+" mystr)
1254       (setq mystr (substring mystr (match-end 0))))
1255     ;; Trailing spaces.
1256     (when (string-match "[ \t]+$" mystr)
1257       (setq mystr (substring mystr 0 (match-beginning 0))))
1258     mystr))
1259
1260 (defsubst gnus-simplify-subject-re (subject)
1261   "Remove \"Re:\" from subject lines."
1262   (if (string-match message-subject-re-regexp subject)
1263       (substring subject (match-end 0))
1264     subject))
1265
1266 (defun gnus-simplify-subject (subject &optional re-only)
1267   "Remove `Re:' and words in parentheses.
1268 If RE-ONLY is non-nil, strip leading `Re:'s only."
1269   (let ((case-fold-search t))           ;Ignore case.
1270     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1271     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1272       (setq subject (substring subject (match-end 0))))
1273     ;; Remove uninteresting prefixes.
1274     (when (and (not re-only)
1275                gnus-simplify-ignored-prefixes
1276                (string-match gnus-simplify-ignored-prefixes subject))
1277       (setq subject (substring subject (match-end 0))))
1278     ;; Remove words in parentheses from end.
1279     (unless re-only
1280       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1281         (setq subject (substring subject 0 (match-beginning 0)))))
1282     ;; Return subject string.
1283     subject))
1284
1285 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1286 ;; all whitespace.
1287 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1288   (goto-char (point-min))
1289   (while (re-search-forward regexp nil t)
1290     (replace-match (or newtext ""))))
1291
1292 (defun gnus-simplify-buffer-fuzzy ()
1293   "Simplify string in the buffer fuzzily.
1294 The string in the accessible portion of the current buffer is simplified.
1295 It is assumed to be a single-line subject.
1296 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1297 matter is removed.  Additional things can be deleted by setting
1298 `gnus-simplify-subject-fuzzy-regexp'."
1299   (let ((case-fold-search t)
1300         (modified-tick))
1301     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1302
1303     (while (not (eq modified-tick (buffer-modified-tick)))
1304       (setq modified-tick (buffer-modified-tick))
1305       (cond
1306        ((listp gnus-simplify-subject-fuzzy-regexp)
1307         (mapcar 'gnus-simplify-buffer-fuzzy-step
1308                 gnus-simplify-subject-fuzzy-regexp))
1309        (gnus-simplify-subject-fuzzy-regexp
1310         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1311       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1312       (gnus-simplify-buffer-fuzzy-step
1313        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1314       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1315
1316     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1317     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1318     (gnus-simplify-buffer-fuzzy-step " $")
1319     (gnus-simplify-buffer-fuzzy-step "^ +")))
1320
1321 (defun gnus-simplify-subject-fuzzy (subject)
1322   "Simplify a subject string fuzzily.
1323 See `gnus-simplify-buffer-fuzzy' for details."
1324   (save-excursion
1325     (gnus-set-work-buffer)
1326     (let ((case-fold-search t))
1327       ;; Remove uninteresting prefixes.
1328       (when (and gnus-simplify-ignored-prefixes
1329                  (string-match gnus-simplify-ignored-prefixes subject))
1330         (setq subject (substring subject (match-end 0))))
1331       (insert subject)
1332       (inline (gnus-simplify-buffer-fuzzy))
1333       (buffer-string))))
1334
1335 (defsubst gnus-simplify-subject-fully (subject)
1336   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1337   (cond
1338    (gnus-simplify-subject-functions
1339     (gnus-map-function gnus-simplify-subject-functions subject))
1340    ((null gnus-summary-gather-subject-limit)
1341     (gnus-simplify-subject-re subject))
1342    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1343     (gnus-simplify-subject-fuzzy subject))
1344    ((numberp gnus-summary-gather-subject-limit)
1345     (gnus-limit-string (gnus-simplify-subject-re subject)
1346                        gnus-summary-gather-subject-limit))
1347    (t
1348     subject)))
1349
1350 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1351   "Check whether two subjects are equal.
1352 If optional argument simple-first is t, first argument is already
1353 simplified."
1354   (cond
1355    ((null simple-first)
1356     (equal (gnus-simplify-subject-fully s1)
1357            (gnus-simplify-subject-fully s2)))
1358    (t
1359     (equal s1
1360            (gnus-simplify-subject-fully s2)))))
1361
1362 (defun gnus-summary-bubble-group ()
1363   "Increase the score of the current group.
1364 This is a handy function to add to `gnus-summary-exit-hook' to
1365 increase the score of each group you read."
1366   (gnus-group-add-score gnus-newsgroup-name))
1367
1368 \f
1369 ;;;
1370 ;;; Gnus summary mode
1371 ;;;
1372
1373 (put 'gnus-summary-mode 'mode-class 'special)
1374
1375 (defvar gnus-article-commands-menu)
1376
1377 (when t
1378   ;; Non-orthogonal keys
1379
1380   (gnus-define-keys gnus-summary-mode-map
1381     " " gnus-summary-next-page
1382     "\177" gnus-summary-prev-page
1383     [delete] gnus-summary-prev-page
1384     [backspace] gnus-summary-prev-page
1385     "\r" gnus-summary-scroll-up
1386     "\M-\r" gnus-summary-scroll-down
1387     "n" gnus-summary-next-unread-article
1388     "p" gnus-summary-prev-unread-article
1389     "N" gnus-summary-next-article
1390     "P" gnus-summary-prev-article
1391     "\M-\C-n" gnus-summary-next-same-subject
1392     "\M-\C-p" gnus-summary-prev-same-subject
1393     "\M-n" gnus-summary-next-unread-subject
1394     "\M-p" gnus-summary-prev-unread-subject
1395     "." gnus-summary-first-unread-article
1396     "," gnus-summary-best-unread-article
1397     "\M-s" gnus-summary-search-article-forward
1398     "\M-r" gnus-summary-search-article-backward
1399     "<" gnus-summary-beginning-of-article
1400     ">" gnus-summary-end-of-article
1401     "j" gnus-summary-goto-article
1402     "^" gnus-summary-refer-parent-article
1403     "\M-^" gnus-summary-refer-article
1404     "u" gnus-summary-tick-article-forward
1405     "!" gnus-summary-tick-article-forward
1406     "U" gnus-summary-tick-article-backward
1407     "d" gnus-summary-mark-as-read-forward
1408     "D" gnus-summary-mark-as-read-backward
1409     "E" gnus-summary-mark-as-expirable
1410     "\M-u" gnus-summary-clear-mark-forward
1411     "\M-U" gnus-summary-clear-mark-backward
1412     "k" gnus-summary-kill-same-subject-and-select
1413     "\C-k" gnus-summary-kill-same-subject
1414     "\M-\C-k" gnus-summary-kill-thread
1415     "\M-\C-l" gnus-summary-lower-thread
1416     "e" gnus-summary-edit-article
1417     "#" gnus-summary-mark-as-processable
1418     "\M-#" gnus-summary-unmark-as-processable
1419     "\M-\C-t" gnus-summary-toggle-threads
1420     "\M-\C-s" gnus-summary-show-thread
1421     "\M-\C-h" gnus-summary-hide-thread
1422     "\M-\C-f" gnus-summary-next-thread
1423     "\M-\C-b" gnus-summary-prev-thread
1424     [(meta down)] gnus-summary-next-thread
1425     [(meta up)] gnus-summary-prev-thread
1426     "\M-\C-u" gnus-summary-up-thread
1427     "\M-\C-d" gnus-summary-down-thread
1428     "&" gnus-summary-execute-command
1429     "c" gnus-summary-catchup-and-exit
1430     "\C-w" gnus-summary-mark-region-as-read
1431     "\C-t" gnus-summary-toggle-truncation
1432     "?" gnus-summary-mark-as-dormant
1433     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1434     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1435     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1436     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1437     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1438     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1439     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1440     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1441     "=" gnus-summary-expand-window
1442     "\C-x\C-s" gnus-summary-reselect-current-group
1443     "\M-g" gnus-summary-rescan-group
1444     "w" gnus-summary-stop-page-breaking
1445     "\C-c\C-r" gnus-summary-caesar-message
1446     "\M-t" gnus-summary-toggle-mime
1447     "f" gnus-summary-followup
1448     "F" gnus-summary-followup-with-original
1449     "C" gnus-summary-cancel-article
1450     "r" gnus-summary-reply
1451     "R" gnus-summary-reply-with-original
1452     "\C-c\C-f" gnus-summary-mail-forward
1453     "o" gnus-summary-save-article
1454     "\C-o" gnus-summary-save-article-mail
1455     "|" gnus-summary-pipe-output
1456     "\M-k" gnus-summary-edit-local-kill
1457     "\M-K" gnus-summary-edit-global-kill
1458     ;; "V" gnus-version
1459     "\C-c\C-d" gnus-summary-describe-group
1460     "q" gnus-summary-exit
1461     "Q" gnus-summary-exit-no-update
1462     "\C-c\C-i" gnus-info-find-node
1463     gnus-mouse-2 gnus-mouse-pick-article
1464     "m" gnus-summary-mail-other-window
1465     "a" gnus-summary-post-news
1466     "x" gnus-summary-limit-to-unread
1467     "s" gnus-summary-isearch-article
1468     "t" gnus-article-toggle-headers
1469     "g" gnus-summary-show-article
1470     "l" gnus-summary-goto-last-article
1471     "v" gnus-summary-preview-mime-message
1472     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1473     "\C-d" gnus-summary-enter-digest-group
1474     "\M-\C-d" gnus-summary-read-document
1475     "\M-\C-e" gnus-summary-edit-parameters
1476     "\M-\C-a" gnus-summary-customize-parameters
1477     "\C-c\C-b" gnus-bug
1478     "*" gnus-cache-enter-article
1479     "\M-*" gnus-cache-remove-article
1480     "\M-&" gnus-summary-universal-argument
1481     "\C-l" gnus-recenter
1482     "I" gnus-summary-increase-score
1483     "L" gnus-summary-lower-score
1484     "\M-i" gnus-symbolic-argument
1485     "h" gnus-summary-select-article-buffer
1486
1487     "V" gnus-summary-score-map
1488     "X" gnus-uu-extract-map
1489     "S" gnus-summary-send-map)
1490
1491   ;; Sort of orthogonal keymap
1492   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1493     "t" gnus-summary-tick-article-forward
1494     "!" gnus-summary-tick-article-forward
1495     "d" gnus-summary-mark-as-read-forward
1496     "r" gnus-summary-mark-as-read-forward
1497     "c" gnus-summary-clear-mark-forward
1498     " " gnus-summary-clear-mark-forward
1499     "e" gnus-summary-mark-as-expirable
1500     "x" gnus-summary-mark-as-expirable
1501     "?" gnus-summary-mark-as-dormant
1502     "b" gnus-summary-set-bookmark
1503     "B" gnus-summary-remove-bookmark
1504     "#" gnus-summary-mark-as-processable
1505     "\M-#" gnus-summary-unmark-as-processable
1506     "S" gnus-summary-limit-include-expunged
1507     "C" gnus-summary-catchup
1508     "H" gnus-summary-catchup-to-here
1509     "\C-c" gnus-summary-catchup-all
1510     "k" gnus-summary-kill-same-subject-and-select
1511     "K" gnus-summary-kill-same-subject
1512     "P" gnus-uu-mark-map)
1513
1514   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1515     "c" gnus-summary-clear-above
1516     "u" gnus-summary-tick-above
1517     "m" gnus-summary-mark-above
1518     "k" gnus-summary-kill-below)
1519
1520   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1521     "/" gnus-summary-limit-to-subject
1522     "n" gnus-summary-limit-to-articles
1523     "w" gnus-summary-pop-limit
1524     "s" gnus-summary-limit-to-subject
1525     "a" gnus-summary-limit-to-author
1526     "u" gnus-summary-limit-to-unread
1527     "m" gnus-summary-limit-to-marks
1528     "M" gnus-summary-limit-exclude-marks
1529     "v" gnus-summary-limit-to-score
1530     "*" gnus-summary-limit-include-cached
1531     "D" gnus-summary-limit-include-dormant
1532     "T" gnus-summary-limit-include-thread
1533     "d" gnus-summary-limit-exclude-dormant
1534     "t" gnus-summary-limit-to-age
1535     "x" gnus-summary-limit-to-extra
1536     "E" gnus-summary-limit-include-expunged
1537     "c" gnus-summary-limit-exclude-childless-dormant
1538     "C" gnus-summary-limit-mark-excluded-as-read)
1539
1540   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1541     "n" gnus-summary-next-unread-article
1542     "p" gnus-summary-prev-unread-article
1543     "N" gnus-summary-next-article
1544     "P" gnus-summary-prev-article
1545     "\C-n" gnus-summary-next-same-subject
1546     "\C-p" gnus-summary-prev-same-subject
1547     "\M-n" gnus-summary-next-unread-subject
1548     "\M-p" gnus-summary-prev-unread-subject
1549     "f" gnus-summary-first-unread-article
1550     "b" gnus-summary-best-unread-article
1551     "j" gnus-summary-goto-article
1552     "g" gnus-summary-goto-subject
1553     "l" gnus-summary-goto-last-article
1554     "o" gnus-summary-pop-article)
1555
1556   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1557     "k" gnus-summary-kill-thread
1558     "l" gnus-summary-lower-thread
1559     "i" gnus-summary-raise-thread
1560     "T" gnus-summary-toggle-threads
1561     "t" gnus-summary-rethread-current
1562     "^" gnus-summary-reparent-thread
1563     "s" gnus-summary-show-thread
1564     "S" gnus-summary-show-all-threads
1565     "h" gnus-summary-hide-thread
1566     "H" gnus-summary-hide-all-threads
1567     "n" gnus-summary-next-thread
1568     "p" gnus-summary-prev-thread
1569     "u" gnus-summary-up-thread
1570     "o" gnus-summary-top-thread
1571     "d" gnus-summary-down-thread
1572     "#" gnus-uu-mark-thread
1573     "\M-#" gnus-uu-unmark-thread)
1574
1575   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1576     "g" gnus-summary-prepare
1577     "c" gnus-summary-insert-cached-articles)
1578
1579   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1580     "c" gnus-summary-catchup-and-exit
1581     "C" gnus-summary-catchup-all-and-exit
1582     "E" gnus-summary-exit-no-update
1583     "J" gnus-summary-jump-to-other-group
1584     "Q" gnus-summary-exit
1585     "Z" gnus-summary-exit
1586     "n" gnus-summary-catchup-and-goto-next-group
1587     "R" gnus-summary-reselect-current-group
1588     "G" gnus-summary-rescan-group
1589     "N" gnus-summary-next-group
1590     "s" gnus-summary-save-newsrc
1591     "P" gnus-summary-prev-group)
1592
1593   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1594     " " gnus-summary-next-page
1595     "n" gnus-summary-next-page
1596     "\177" gnus-summary-prev-page
1597     [delete] gnus-summary-prev-page
1598     "p" gnus-summary-prev-page
1599     "\r" gnus-summary-scroll-up
1600     "\M-\r" gnus-summary-scroll-down
1601     "<" gnus-summary-beginning-of-article
1602     ">" gnus-summary-end-of-article
1603     "b" gnus-summary-beginning-of-article
1604     "e" gnus-summary-end-of-article
1605     "^" gnus-summary-refer-parent-article
1606     "r" gnus-summary-refer-parent-article
1607     "D" gnus-summary-enter-digest-group
1608     "R" gnus-summary-refer-references
1609     "T" gnus-summary-refer-thread
1610     "g" gnus-summary-show-article
1611     "s" gnus-summary-isearch-article
1612     "P" gnus-summary-print-article
1613     "M" gnus-mailing-list-insinuate
1614     "t" gnus-article-babel)
1615
1616   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1617     "b" gnus-article-add-buttons
1618     "B" gnus-article-add-buttons-to-head
1619     "o" gnus-article-treat-overstrike
1620     "e" gnus-article-emphasize
1621     "w" gnus-article-fill-cited-article
1622     "Q" gnus-article-fill-long-lines
1623     "C" gnus-article-capitalize-sentences
1624     "c" gnus-article-remove-cr
1625     "Z" gnus-article-decode-HZ
1626     "f" gnus-article-display-x-face
1627     "l" gnus-summary-stop-page-breaking
1628     "r" gnus-summary-caesar-message
1629     "t" gnus-article-toggle-headers
1630     "v" gnus-summary-verbose-headers
1631     "m" gnus-summary-toggle-mime
1632     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1633     "p" gnus-article-verify-x-pgp-sig
1634     "d" gnus-article-treat-dumbquotes
1635     "s" gnus-smiley-display)
1636
1637   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1638     "a" gnus-article-hide
1639     "h" gnus-article-toggle-headers
1640     "b" gnus-article-hide-boring-headers
1641     "s" gnus-article-hide-signature
1642     "c" gnus-article-hide-citation
1643     "C" gnus-article-hide-citation-in-followups
1644     "l" gnus-article-hide-list-identifiers
1645     "p" gnus-article-hide-pgp
1646     "B" gnus-article-strip-banner
1647     "P" gnus-article-hide-pem
1648     "\C-c" gnus-article-hide-citation-maybe)
1649
1650   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1651     "a" gnus-article-highlight
1652     "h" gnus-article-highlight-headers
1653     "c" gnus-article-highlight-citation
1654     "s" gnus-article-highlight-signature)
1655
1656   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1657     "z" gnus-article-date-ut
1658     "u" gnus-article-date-ut
1659     "l" gnus-article-date-local
1660     "p" gnus-article-date-english
1661     "e" gnus-article-date-lapsed
1662     "o" gnus-article-date-original
1663     "i" gnus-article-date-iso8601
1664     "s" gnus-article-date-user)
1665
1666   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1667     "t" gnus-article-remove-trailing-blank-lines
1668     "l" gnus-article-strip-leading-blank-lines
1669     "m" gnus-article-strip-multiple-blank-lines
1670     "a" gnus-article-strip-blank-lines
1671     "A" gnus-article-strip-all-blank-lines
1672     "s" gnus-article-strip-leading-space
1673     "e" gnus-article-strip-trailing-space
1674     "w" gnus-article-remove-leading-whitespace)
1675
1676   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1677     "v" gnus-version
1678     "f" gnus-summary-fetch-faq
1679     "d" gnus-summary-describe-group
1680     "h" gnus-summary-describe-briefly
1681     "i" gnus-info-find-node)
1682
1683   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1684     "e" gnus-summary-expire-articles
1685     "\M-\C-e" gnus-summary-expire-articles-now
1686     "\177" gnus-summary-delete-article
1687     [delete] gnus-summary-delete-article
1688     [backspace] gnus-summary-delete-article
1689     "m" gnus-summary-move-article
1690     "r" gnus-summary-respool-article
1691     "w" gnus-summary-edit-article
1692     "c" gnus-summary-copy-article
1693     "B" gnus-summary-crosspost-article
1694     "q" gnus-summary-respool-query
1695     "t" gnus-summary-respool-trace
1696     "i" gnus-summary-import-article
1697     "p" gnus-summary-article-posted-p)
1698
1699   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1700     "o" gnus-summary-save-article
1701     "m" gnus-summary-save-article-mail
1702     "F" gnus-summary-write-article-file
1703     "r" gnus-summary-save-article-rmail
1704     "f" gnus-summary-save-article-file
1705     "b" gnus-summary-save-article-body-file
1706     "h" gnus-summary-save-article-folder
1707     "v" gnus-summary-save-article-vm
1708     "p" gnus-summary-pipe-output
1709     "s" gnus-soup-add-article)
1710
1711   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1712     "b" gnus-summary-display-buttonized
1713     "m" gnus-summary-repair-multipart
1714     "v" gnus-article-view-part
1715     "o" gnus-article-save-part
1716     "c" gnus-article-copy-part
1717     "C" gnus-article-view-part-as-charset
1718     "e" gnus-article-externalize-part
1719     "E" gnus-article-encrypt-body
1720     "i" gnus-article-inline-part
1721     "|" gnus-article-pipe-part))
1722
1723 (defun gnus-summary-make-menu-bar ()
1724   (gnus-turn-off-edit-menu 'summary)
1725
1726   (unless (boundp 'gnus-summary-misc-menu)
1727
1728     (easy-menu-define
1729      gnus-summary-kill-menu gnus-summary-mode-map ""
1730      (cons
1731       "Score"
1732       (nconc
1733        (list
1734         ["Customize" gnus-score-customize t])
1735        (gnus-make-score-map 'increase)
1736        (gnus-make-score-map 'lower)
1737        '(("Mark"
1738           ["Kill below" gnus-summary-kill-below t]
1739           ["Mark above" gnus-summary-mark-above t]
1740           ["Tick above" gnus-summary-tick-above t]
1741           ["Clear above" gnus-summary-clear-above t])
1742          ["Current score" gnus-summary-current-score t]
1743          ["Set score" gnus-summary-set-score t]
1744          ["Switch current score file..." gnus-score-change-score-file t]
1745          ["Set mark below..." gnus-score-set-mark-below t]
1746          ["Set expunge below..." gnus-score-set-expunge-below t]
1747          ["Edit current score file" gnus-score-edit-current-scores t]
1748          ["Edit score file" gnus-score-edit-file t]
1749          ["Trace score" gnus-score-find-trace t]
1750          ["Find words" gnus-score-find-favourite-words t]
1751          ["Rescore buffer" gnus-summary-rescore t]
1752          ["Increase score..." gnus-summary-increase-score t]
1753          ["Lower score..." gnus-summary-lower-score t]))))
1754
1755     ;; Define both the Article menu in the summary buffer and the equivalent
1756     ;; Commands menu in the article buffer here for consistency.
1757     (let ((innards
1758            `(("Hide"
1759               ["All" gnus-article-hide t]
1760               ["Headers" gnus-article-toggle-headers t]
1761               ["Signature" gnus-article-hide-signature t]
1762               ["Citation" gnus-article-hide-citation t]
1763               ["List identifiers" gnus-article-hide-list-identifiers t]
1764               ["PGP" gnus-article-hide-pgp t]
1765               ["Banner" gnus-article-strip-banner t]
1766               ["Boring headers" gnus-article-hide-boring-headers t])
1767              ("Highlight"
1768               ["All" gnus-article-highlight t]
1769               ["Headers" gnus-article-highlight-headers t]
1770               ["Signature" gnus-article-highlight-signature t]
1771               ["Citation" gnus-article-highlight-citation t])
1772              ("Date"
1773               ["Local" gnus-article-date-local t]
1774               ["ISO8601" gnus-article-date-iso8601 t]
1775               ["UT" gnus-article-date-ut t]
1776               ["Original" gnus-article-date-original t]
1777               ["Lapsed" gnus-article-date-lapsed t]
1778               ["User-defined" gnus-article-date-user t])
1779              ("Washing"
1780               ("Remove Blanks"
1781                ["Leading" gnus-article-strip-leading-blank-lines t]
1782                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1783                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1784                ["All of the above" gnus-article-strip-blank-lines t]
1785                ["All" gnus-article-strip-all-blank-lines t]
1786                ["Leading space" gnus-article-strip-leading-space t]
1787                ["Trailing space" gnus-article-strip-trailing-space t]
1788                ["Leading space in headers" 
1789                 gnus-article-remove-leading-whitespace t])
1790               ["Overstrike" gnus-article-treat-overstrike t]
1791               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1792               ["Emphasis" gnus-article-emphasize t]
1793               ["Word wrap" gnus-article-fill-cited-article t]
1794               ["Fill long lines" gnus-article-fill-long-lines t]
1795               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1796               ["CR" gnus-article-remove-cr t]
1797               ["Show X-Face" gnus-article-display-x-face t]
1798               ["Rot 13" gnus-summary-caesar-message
1799                ,@(if (featurep 'xemacs) '(t)
1800                    '(:help "\"Caesar rotate\" article by 13"))]
1801               ["Unix pipe" gnus-summary-pipe-message t]
1802               ["Add buttons" gnus-article-add-buttons t]
1803               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1804               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1805               ["Toggle MIME" gnus-summary-toggle-mime t]
1806               ["Verbose header" gnus-summary-verbose-headers t]
1807               ["Toggle header" gnus-summary-toggle-header t]
1808               ["Toggle smileys" gnus-smiley-display t]
1809               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1810               ["HZ" gnus-article-decode-HZ t])
1811              ("Output"
1812               ["Save in default format" gnus-summary-save-article
1813                ,@(if (featurep 'xemacs) '(t)
1814                    '(:help "Save article using default method"))]
1815               ["Save in file" gnus-summary-save-article-file
1816                ,@(if (featurep 'xemacs) '(t)
1817                    '(:help "Save article in file"))]
1818               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1819               ["Save in MH folder" gnus-summary-save-article-folder t]
1820               ["Save in VM folder" gnus-summary-save-article-vm t]
1821               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1822               ["Save body in file" gnus-summary-save-article-body-file t]
1823               ["Pipe through a filter" gnus-summary-pipe-output t]
1824               ["Add to SOUP packet" gnus-soup-add-article t]
1825               ["Print" gnus-summary-print-article t])
1826              ("Backend"
1827               ["Respool article..." gnus-summary-respool-article t]
1828               ["Move article..." gnus-summary-move-article
1829                (gnus-check-backend-function
1830                 'request-move-article gnus-newsgroup-name)]
1831               ["Copy article..." gnus-summary-copy-article t]
1832               ["Crosspost article..." gnus-summary-crosspost-article
1833                (gnus-check-backend-function
1834                 'request-replace-article gnus-newsgroup-name)]
1835               ["Import file..." gnus-summary-import-article t]
1836               ["Check if posted" gnus-summary-article-posted-p t]
1837               ["Edit article" gnus-summary-edit-article
1838                (not (gnus-group-read-only-p))]
1839               ["Delete article" gnus-summary-delete-article
1840                (gnus-check-backend-function
1841                 'request-expire-articles gnus-newsgroup-name)]
1842               ["Query respool" gnus-summary-respool-query t]
1843               ["Trace respool" gnus-summary-respool-trace t]
1844               ["Delete expirable articles" gnus-summary-expire-articles-now
1845                (gnus-check-backend-function
1846                 'request-expire-articles gnus-newsgroup-name)])
1847              ("Extract"
1848               ["Uudecode" gnus-uu-decode-uu
1849                ,@(if (featurep 'xemacs) '(t)
1850                    '(:help "Decode uuencoded article(s)"))]
1851               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1852               ["Unshar" gnus-uu-decode-unshar t]
1853               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1854               ["Save" gnus-uu-decode-save t]
1855               ["Binhex" gnus-uu-decode-binhex t]
1856               ["Postscript" gnus-uu-decode-postscript t])
1857              ("Cache"
1858               ["Enter article" gnus-cache-enter-article t]
1859               ["Remove article" gnus-cache-remove-article t])
1860              ["Translate" gnus-article-babel t]
1861              ["Select article buffer" gnus-summary-select-article-buffer t]
1862              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1863              ["Isearch article..." gnus-summary-isearch-article t]
1864              ["Beginning of the article" gnus-summary-beginning-of-article t]
1865              ["End of the article" gnus-summary-end-of-article t]
1866              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1867              ["Fetch referenced articles" gnus-summary-refer-references t]
1868              ["Fetch current thread" gnus-summary-refer-thread t]
1869              ["Fetch article with id..." gnus-summary-refer-article t]
1870              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1871              ["Redisplay" gnus-summary-show-article t])))
1872       (easy-menu-define
1873        gnus-summary-article-menu gnus-summary-mode-map ""
1874        (cons "Article" innards))
1875
1876       (if (not (keymapp gnus-summary-article-menu))
1877           (easy-menu-define
1878             gnus-article-commands-menu gnus-article-mode-map ""
1879             (cons "Commands" innards))
1880         ;; in Emacs, don't share menu.
1881         (setq gnus-article-commands-menu 
1882               (copy-keymap gnus-summary-article-menu))
1883         (define-key gnus-article-mode-map [menu-bar commands]
1884           (cons "Commands" gnus-article-commands-menu))))
1885
1886     (easy-menu-define
1887      gnus-summary-thread-menu gnus-summary-mode-map ""
1888      '("Threads"
1889        ["Toggle threading" gnus-summary-toggle-threads t]
1890        ["Hide threads" gnus-summary-hide-all-threads t]
1891        ["Show threads" gnus-summary-show-all-threads t]
1892        ["Hide thread" gnus-summary-hide-thread t]
1893        ["Show thread" gnus-summary-show-thread t]
1894        ["Go to next thread" gnus-summary-next-thread t]
1895        ["Go to previous thread" gnus-summary-prev-thread t]
1896        ["Go down thread" gnus-summary-down-thread t]
1897        ["Go up thread" gnus-summary-up-thread t]
1898        ["Top of thread" gnus-summary-top-thread t]
1899        ["Mark thread as read" gnus-summary-kill-thread t]
1900        ["Lower thread score" gnus-summary-lower-thread t]
1901        ["Raise thread score" gnus-summary-raise-thread t]
1902        ["Rethread current" gnus-summary-rethread-current t]))
1903
1904     (easy-menu-define
1905      gnus-summary-post-menu gnus-summary-mode-map ""
1906      `("Post"
1907        ["Post an article" gnus-summary-post-news
1908         ,@(if (featurep 'xemacs) '(t)
1909             '(:help "Post an article"))]
1910        ["Followup" gnus-summary-followup
1911         ,@(if (featurep 'xemacs) '(t)
1912             '(:help "Post followup to this article"))]
1913        ["Followup and yank" gnus-summary-followup-with-original
1914         ,@(if (featurep 'xemacs) '(t)
1915             '(:help "Post followup to this article, quoting its contents"))]
1916        ["Supersede article" gnus-summary-supersede-article t]
1917        ["Cancel article" gnus-summary-cancel-article
1918         ,@(if (featurep 'xemacs) '(t)
1919             '(:help "Cancel an article you posted"))]
1920        ["Reply" gnus-summary-reply t]
1921        ["Reply and yank" gnus-summary-reply-with-original t]
1922        ["Wide reply" gnus-summary-wide-reply t]
1923        ["Wide reply and yank" gnus-summary-wide-reply-with-original
1924         ,@(if (featurep 'xemacs) '(t)
1925             '(:help "Mail a reply, quoting this article"))]
1926        ["Mail forward" gnus-summary-mail-forward t]
1927        ["Post forward" gnus-summary-post-forward t]
1928        ["Digest and mail" gnus-uu-digest-mail-forward t]
1929        ["Digest and post" gnus-uu-digest-post-forward t]
1930        ["Resend message" gnus-summary-resend-message t]
1931        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1932        ["Send a mail" gnus-summary-mail-other-window t]
1933        ["Uuencode and post" gnus-uu-post-news
1934         ,@(if (featurep 'xemacs) '(t)
1935             '(:help "Post a uuencoded article"))]
1936        ["Followup via news" gnus-summary-followup-to-mail t]
1937        ["Followup via news and yank"
1938         gnus-summary-followup-to-mail-with-original t]
1939        ;;("Draft"
1940        ;;["Send" gnus-summary-send-draft t]
1941        ;;["Send bounced" gnus-resend-bounced-mail t])
1942        ))
1943
1944     (easy-menu-define
1945      gnus-summary-misc-menu gnus-summary-mode-map ""
1946      `("Misc"
1947        ("Mark Read"
1948         ["Mark as read" gnus-summary-mark-as-read-forward t]
1949         ["Mark same subject and select"
1950          gnus-summary-kill-same-subject-and-select t]
1951         ["Mark same subject" gnus-summary-kill-same-subject t]
1952         ["Catchup" gnus-summary-catchup
1953          ,@(if (featurep 'xemacs) '(t)
1954              '(:help "Mark unread articles in this group as read"))]
1955         ["Catchup all" gnus-summary-catchup-all t]
1956         ["Catchup to here" gnus-summary-catchup-to-here t]
1957         ["Catchup region" gnus-summary-mark-region-as-read t]
1958         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1959        ("Mark Various"
1960         ["Tick" gnus-summary-tick-article-forward t]
1961         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1962         ["Remove marks" gnus-summary-clear-mark-forward t]
1963         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1964         ["Set bookmark" gnus-summary-set-bookmark t]
1965         ["Remove bookmark" gnus-summary-remove-bookmark t])
1966        ("Mark Limit"
1967         ["Marks..." gnus-summary-limit-to-marks t]
1968         ["Subject..." gnus-summary-limit-to-subject t]
1969         ["Author..." gnus-summary-limit-to-author t]
1970         ["Age..." gnus-summary-limit-to-age t]
1971         ["Extra..." gnus-summary-limit-to-extra t]
1972         ["Score" gnus-summary-limit-to-score t]
1973         ["Unread" gnus-summary-limit-to-unread t]
1974         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1975         ["Articles" gnus-summary-limit-to-articles t]
1976         ["Pop limit" gnus-summary-pop-limit t]
1977         ["Show dormant" gnus-summary-limit-include-dormant t]
1978         ["Hide childless dormant"
1979          gnus-summary-limit-exclude-childless-dormant t]
1980         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1981         ["Hide marked" gnus-summary-limit-exclude-marks t]
1982         ["Show expunged" gnus-summary-show-all-expunged t])
1983        ("Process Mark"
1984         ["Set mark" gnus-summary-mark-as-processable t]
1985         ["Remove mark" gnus-summary-unmark-as-processable t]
1986         ["Remove all marks" gnus-summary-unmark-all-processable t]
1987         ["Mark above" gnus-uu-mark-over t]
1988         ["Mark series" gnus-uu-mark-series t]
1989         ["Mark region" gnus-uu-mark-region t]
1990         ["Unmark region" gnus-uu-unmark-region t]
1991         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1992         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1993         ["Mark all" gnus-uu-mark-all t]
1994         ["Mark buffer" gnus-uu-mark-buffer t]
1995         ["Mark sparse" gnus-uu-mark-sparse t]
1996         ["Mark thread" gnus-uu-mark-thread t]
1997         ["Unmark thread" gnus-uu-unmark-thread t]
1998         ("Process Mark Sets"
1999          ["Kill" gnus-summary-kill-process-mark t]
2000          ["Yank" gnus-summary-yank-process-mark
2001           gnus-newsgroup-process-stack]
2002          ["Save" gnus-summary-save-process-mark t]))
2003        ("Scroll article"
2004         ["Page forward" gnus-summary-next-page
2005          ,@(if (featurep 'xemacs) '(t)
2006              '(:help "Show next page of article"))]
2007         ["Page backward" gnus-summary-prev-page
2008          ,@(if (featurep 'xemacs) '(t)
2009              '(:help "Show previous page of article"))]
2010         ["Line forward" gnus-summary-scroll-up t])
2011        ("Move"
2012         ["Next unread article" gnus-summary-next-unread-article t]
2013         ["Previous unread article" gnus-summary-prev-unread-article t]
2014         ["Next article" gnus-summary-next-article t]
2015         ["Previous article" gnus-summary-prev-article t]
2016         ["Next unread subject" gnus-summary-next-unread-subject t]
2017         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2018         ["Next article same subject" gnus-summary-next-same-subject t]
2019         ["Previous article same subject" gnus-summary-prev-same-subject t]
2020         ["First unread article" gnus-summary-first-unread-article t]
2021         ["Best unread article" gnus-summary-best-unread-article t]
2022         ["Go to subject number..." gnus-summary-goto-subject t]
2023         ["Go to article number..." gnus-summary-goto-article t]
2024         ["Go to the last article" gnus-summary-goto-last-article t]
2025         ["Pop article off history" gnus-summary-pop-article t])
2026        ("Sort"
2027         ["Sort by number" gnus-summary-sort-by-number t]
2028         ["Sort by author" gnus-summary-sort-by-author t]
2029         ["Sort by subject" gnus-summary-sort-by-subject t]
2030         ["Sort by date" gnus-summary-sort-by-date t]
2031         ["Sort by score" gnus-summary-sort-by-score t]
2032         ["Sort by lines" gnus-summary-sort-by-lines t]
2033         ["Sort by characters" gnus-summary-sort-by-chars t])
2034        ("Help"
2035         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2036         ["Describe group" gnus-summary-describe-group t]
2037         ["Read manual" gnus-info-find-node t])
2038        ("Modes"
2039         ["Pick and read" gnus-pick-mode t]
2040         ["Binary" gnus-binary-mode t])
2041        ("Regeneration"
2042         ["Regenerate" gnus-summary-prepare t]
2043         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2044         ["Toggle threading" gnus-summary-toggle-threads t])
2045        ["Filter articles..." gnus-summary-execute-command t]
2046        ["Run command on subjects..." gnus-summary-universal-argument t]
2047        ["Search articles forward..." gnus-summary-search-article-forward t]
2048        ["Search articles backward..." gnus-summary-search-article-backward t]
2049        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2050        ["Expand window" gnus-summary-expand-window t]
2051        ["Expire expirable articles" gnus-summary-expire-articles
2052         (gnus-check-backend-function
2053          'request-expire-articles gnus-newsgroup-name)]
2054        ["Edit local kill file" gnus-summary-edit-local-kill t]
2055        ["Edit main kill file" gnus-summary-edit-global-kill t]
2056        ["Edit group parameters" gnus-summary-edit-parameters t]
2057        ["Customize group parameters" gnus-summary-customize-parameters t]
2058        ["Send a bug report" gnus-bug t]
2059        ("Exit"
2060         ["Catchup and exit" gnus-summary-catchup-and-exit
2061          ,@(if (featurep 'xemacs) '(t)
2062              '(:help "Mark unread articles in this group as read, then exit"))]
2063         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2064         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2065         ["Exit group" gnus-summary-exit
2066          ,@(if (featurep 'xemacs) '(t)
2067              '(:help "Exit current group, return to group selection mode"))]
2068         ["Exit group without updating" gnus-summary-exit-no-update t]
2069         ["Exit and goto next group" gnus-summary-next-group t]
2070         ["Exit and goto prev group" gnus-summary-prev-group t]
2071         ["Reselect group" gnus-summary-reselect-current-group t]
2072         ["Rescan group" gnus-summary-rescan-group t]
2073         ["Update dribble" gnus-summary-save-newsrc t])))
2074
2075     (gnus-run-hooks 'gnus-summary-menu-hook)))
2076
2077 (defvar gnus-summary-tool-bar-map nil)
2078
2079 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2080 (defun gnus-summary-make-tool-bar ()
2081   (if (and (fboundp 'tool-bar-add-item-from-menu)
2082            (default-value 'tool-bar-mode)
2083            (not gnus-summary-tool-bar-map))
2084       (setq gnus-summary-tool-bar-map
2085             (let ((tool-bar-map (make-sparse-keymap))
2086                   (load-path (mm-image-load-path)))
2087               (tool-bar-add-item-from-menu
2088                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2089               (tool-bar-add-item-from-menu
2090                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2091               (tool-bar-add-item-from-menu
2092                'gnus-summary-post-news "post" gnus-summary-mode-map)
2093               (tool-bar-add-item-from-menu
2094                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2095               (tool-bar-add-item-from-menu
2096                'gnus-summary-followup "followup" gnus-summary-mode-map)
2097               (tool-bar-add-item-from-menu
2098                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2099               (tool-bar-add-item-from-menu
2100                'gnus-summary-reply "reply" gnus-summary-mode-map)
2101               (tool-bar-add-item-from-menu
2102                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2103               (tool-bar-add-item-from-menu
2104                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2105               (tool-bar-add-item-from-menu
2106                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2107               (tool-bar-add-item-from-menu
2108                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2109               (tool-bar-add-item-from-menu
2110                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2111               (tool-bar-add-item-from-menu
2112                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2113               (tool-bar-add-item-from-menu
2114                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2115               (tool-bar-add-item-from-menu
2116                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2117               tool-bar-map)))
2118   (if gnus-summary-tool-bar-map
2119       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2120
2121 (defun gnus-score-set-default (var value)
2122   "A version of set that updates the GNU Emacs menu-bar."
2123   (set var value)
2124   ;; It is the message that forces the active status to be updated.
2125   (message ""))
2126
2127 (defun gnus-make-score-map (type)
2128   "Make a summary score map of type TYPE."
2129   (if t
2130       nil
2131     (let ((headers '(("author" "from" string)
2132                      ("subject" "subject" string)
2133                      ("article body" "body" string)
2134                      ("article head" "head" string)
2135                      ("xref" "xref" string)
2136                      ("extra header" "extra" string)
2137                      ("lines" "lines" number)
2138                      ("followups to author" "followup" string)))
2139           (types '((number ("less than" <)
2140                            ("greater than" >)
2141                            ("equal" =))
2142                    (string ("substring" s)
2143                            ("exact string" e)
2144                            ("fuzzy string" f)
2145                            ("regexp" r))))
2146           (perms '(("temporary" (current-time-string))
2147                    ("permanent" nil)
2148                    ("immediate" now)))
2149           header)
2150       (list
2151        (apply
2152         'nconc
2153         (list
2154          (if (eq type 'lower)
2155              "Lower score"
2156            "Increase score"))
2157         (let (outh)
2158           (while headers
2159             (setq header (car headers))
2160             (setq outh
2161                   (cons
2162                    (apply
2163                     'nconc
2164                     (list (car header))
2165                     (let ((ts (cdr (assoc (nth 2 header) types)))
2166                           outt)
2167                       (while ts
2168                         (setq outt
2169                               (cons
2170                                (apply
2171                                 'nconc
2172                                 (list (caar ts))
2173                                 (let ((ps perms)
2174                                       outp)
2175                                   (while ps
2176                                     (setq outp
2177                                           (cons
2178                                            (vector
2179                                             (caar ps)
2180                                             (list
2181                                              'gnus-summary-score-entry
2182                                              (nth 1 header)
2183                                              (if (or (string= (nth 1 header)
2184                                                               "head")
2185                                                      (string= (nth 1 header)
2186                                                               "body"))
2187                                                  ""
2188                                                (list 'gnus-summary-header
2189                                                      (nth 1 header)))
2190                                              (list 'quote (nth 1 (car ts)))
2191                                              (list 'gnus-score-delta-default
2192                                                    nil)
2193                                              (nth 1 (car ps))
2194                                              t)
2195                                             t)
2196                                            outp))
2197                                     (setq ps (cdr ps)))
2198                                   (list (nreverse outp))))
2199                                outt))
2200                         (setq ts (cdr ts)))
2201                       (list (nreverse outt))))
2202                    outh))
2203             (setq headers (cdr headers)))
2204           (list (nreverse outh))))))))
2205
2206 \f
2207
2208 (defun gnus-summary-mode (&optional group)
2209   "Major mode for reading articles.
2210
2211 All normal editing commands are switched off.
2212 \\<gnus-summary-mode-map>
2213 Each line in this buffer represents one article.  To read an
2214 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2215 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2216 respectively.
2217
2218 You can also post articles and send mail from this buffer.  To
2219 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2220 of an article, type `\\[gnus-summary-reply]'.
2221
2222 There are approx. one gazillion commands you can execute in this
2223 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2224
2225 The following commands are available:
2226
2227 \\{gnus-summary-mode-map}"
2228   (interactive)
2229   (kill-all-local-variables)
2230   (when (gnus-visual-p 'summary-menu 'menu)
2231     (gnus-summary-make-menu-bar)
2232     (gnus-summary-make-tool-bar))
2233   (gnus-summary-make-local-variables)
2234   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2235     (gnus-summary-make-local-variables))
2236   (gnus-make-thread-indent-array)
2237   (gnus-simplify-mode-line)
2238   (setq major-mode 'gnus-summary-mode)
2239   (setq mode-name "Summary")
2240   (make-local-variable 'minor-mode-alist)
2241   (use-local-map gnus-summary-mode-map)
2242   (buffer-disable-undo)
2243   (setq buffer-read-only t)             ;Disable modification
2244   (setq truncate-lines t)
2245   (setq selective-display t)
2246   (setq selective-display-ellipses t)   ;Display `...'
2247   (gnus-summary-set-display-table)
2248   (gnus-set-default-directory)
2249   (setq gnus-newsgroup-name group)
2250   (unless (gnus-news-group-p group)
2251     (setq gnus-newsgroup-incorporated
2252           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2253   (make-local-variable 'gnus-summary-line-format)
2254   (make-local-variable 'gnus-summary-line-format-spec)
2255   (make-local-variable 'gnus-summary-dummy-line-format)
2256   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2257   (make-local-variable 'gnus-summary-mark-positions)
2258   (make-local-hook 'pre-command-hook)
2259   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2260   (gnus-run-hooks 'gnus-summary-mode-hook)
2261   (turn-on-gnus-mailing-list-mode)
2262   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2263   (gnus-update-summary-mark-positions))
2264
2265 (defun gnus-summary-make-local-variables ()
2266   "Make all the local summary buffer variables."
2267   (let (global)
2268     (dolist (local gnus-summary-local-variables)
2269       (if (consp local)
2270           (progn
2271             (if (eq (cdr local) 'global)
2272                 ;; Copy the global value of the variable.
2273                 (setq global (symbol-value (car local)))
2274               ;; Use the value from the list.
2275               (setq global (eval (cdr local))))
2276             (set (make-local-variable (car local)) global))
2277         ;; Simple nil-valued local variable.
2278         (set (make-local-variable local) nil)))))
2279
2280 (defun gnus-summary-clear-local-variables ()
2281   (let ((locals gnus-summary-local-variables))
2282     (while locals
2283       (if (consp (car locals))
2284           (and (vectorp (caar locals))
2285                (set (caar locals) nil))
2286         (and (vectorp (car locals))
2287              (set (car locals) nil)))
2288       (setq locals (cdr locals)))))
2289
2290 ;; Summary data functions.
2291
2292 (defmacro gnus-data-number (data)
2293   `(car ,data))
2294
2295 (defmacro gnus-data-set-number (data number)
2296   `(setcar ,data ,number))
2297
2298 (defmacro gnus-data-mark (data)
2299   `(nth 1 ,data))
2300
2301 (defmacro gnus-data-set-mark (data mark)
2302   `(setcar (nthcdr 1 ,data) ,mark))
2303
2304 (defmacro gnus-data-pos (data)
2305   `(nth 2 ,data))
2306
2307 (defmacro gnus-data-set-pos (data pos)
2308   `(setcar (nthcdr 2 ,data) ,pos))
2309
2310 (defmacro gnus-data-header (data)
2311   `(nth 3 ,data))
2312
2313 (defmacro gnus-data-set-header (data header)
2314   `(setcar (nthcdr 3 ,data) ,header))
2315
2316 (defmacro gnus-data-level (data)
2317   `(nth 4 ,data))
2318
2319 (defmacro gnus-data-unread-p (data)
2320   `(= (nth 1 ,data) gnus-unread-mark))
2321
2322 (defmacro gnus-data-read-p (data)
2323   `(/= (nth 1 ,data) gnus-unread-mark))
2324
2325 (defmacro gnus-data-pseudo-p (data)
2326   `(consp (nth 3 ,data)))
2327
2328 (defmacro gnus-data-find (number)
2329   `(assq ,number gnus-newsgroup-data))
2330
2331 (defmacro gnus-data-find-list (number &optional data)
2332   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2333      (memq (assq ,number bdata)
2334            bdata)))
2335
2336 (defmacro gnus-data-make (number mark pos header level)
2337   `(list ,number ,mark ,pos ,header ,level))
2338
2339 (defun gnus-data-enter (after-article number mark pos header level offset)
2340   (let ((data (gnus-data-find-list after-article)))
2341     (unless data
2342       (error "No such article: %d" after-article))
2343     (setcdr data (cons (gnus-data-make number mark pos header level)
2344                        (cdr data)))
2345     (setq gnus-newsgroup-data-reverse nil)
2346     (gnus-data-update-list (cddr data) offset)))
2347
2348 (defun gnus-data-enter-list (after-article list &optional offset)
2349   (when list
2350     (let ((data (and after-article (gnus-data-find-list after-article)))
2351           (ilist list))
2352       (if (not (or data
2353                    after-article))
2354           (let ((odata gnus-newsgroup-data))
2355             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2356             (when offset
2357               (gnus-data-update-list odata offset)))
2358         ;; Find the last element in the list to be spliced into the main
2359         ;; list.
2360         (while (cdr list)
2361           (setq list (cdr list)))
2362         (if (not data)
2363             (progn
2364               (setcdr list gnus-newsgroup-data)
2365               (setq gnus-newsgroup-data ilist)
2366               (when offset
2367                 (gnus-data-update-list (cdr list) offset)))
2368           (setcdr list (cdr data))
2369           (setcdr data ilist)
2370           (when offset
2371             (gnus-data-update-list (cdr list) offset))))
2372       (setq gnus-newsgroup-data-reverse nil))))
2373
2374 (defun gnus-data-remove (article &optional offset)
2375   (let ((data gnus-newsgroup-data))
2376     (if (= (gnus-data-number (car data)) article)
2377         (progn
2378           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2379                 gnus-newsgroup-data-reverse nil)
2380           (when offset
2381             (gnus-data-update-list gnus-newsgroup-data offset)))
2382       (while (cdr data)
2383         (when (= (gnus-data-number (cadr data)) article)
2384           (setcdr data (cddr data))
2385           (when offset
2386             (gnus-data-update-list (cdr data) offset))
2387           (setq data nil
2388                 gnus-newsgroup-data-reverse nil))
2389         (setq data (cdr data))))))
2390
2391 (defmacro gnus-data-list (backward)
2392   `(if ,backward
2393        (or gnus-newsgroup-data-reverse
2394            (setq gnus-newsgroup-data-reverse
2395                  (reverse gnus-newsgroup-data)))
2396      gnus-newsgroup-data))
2397
2398 (defun gnus-data-update-list (data offset)
2399   "Add OFFSET to the POS of all data entries in DATA."
2400   (setq gnus-newsgroup-data-reverse nil)
2401   (while data
2402     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2403     (setq data (cdr data))))
2404
2405 (defun gnus-summary-article-pseudo-p (article)
2406   "Say whether this article is a pseudo article or not."
2407   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2408
2409 (defmacro gnus-summary-article-sparse-p (article)
2410   "Say whether this article is a sparse article or not."
2411   `(memq ,article gnus-newsgroup-sparse))
2412
2413 (defmacro gnus-summary-article-ancient-p (article)
2414   "Say whether this article is a sparse article or not."
2415   `(memq ,article gnus-newsgroup-ancient))
2416
2417 (defun gnus-article-parent-p (number)
2418   "Say whether this article is a parent or not."
2419   (let ((data (gnus-data-find-list number)))
2420     (and (cdr data)                     ; There has to be an article after...
2421          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2422             (gnus-data-level (nth 1 data))))))
2423
2424 (defun gnus-article-children (number)
2425   "Return a list of all children to NUMBER."
2426   (let* ((data (gnus-data-find-list number))
2427          (level (gnus-data-level (car data)))
2428          children)
2429     (setq data (cdr data))
2430     (while (and data
2431                 (= (gnus-data-level (car data)) (1+ level)))
2432       (push (gnus-data-number (car data)) children)
2433       (setq data (cdr data)))
2434     children))
2435
2436 (defmacro gnus-summary-skip-intangible ()
2437   "If the current article is intangible, then jump to a different article."
2438   '(let ((to (get-text-property (point) 'gnus-intangible)))
2439      (and to (gnus-summary-goto-subject to))))
2440
2441 (defmacro gnus-summary-article-intangible-p ()
2442   "Say whether this article is intangible or not."
2443   '(get-text-property (point) 'gnus-intangible))
2444
2445 (defun gnus-article-read-p (article)
2446   "Say whether ARTICLE is read or not."
2447   (not (or (memq article gnus-newsgroup-marked)
2448            (memq article gnus-newsgroup-unreads)
2449            (memq article gnus-newsgroup-unselected)
2450            (memq article gnus-newsgroup-dormant))))
2451
2452 ;; Some summary mode macros.
2453
2454 (defmacro gnus-summary-article-number ()
2455   "The article number of the article on the current line.
2456 If there isn's an article number here, then we return the current
2457 article number."
2458   '(progn
2459      (gnus-summary-skip-intangible)
2460      (or (get-text-property (point) 'gnus-number)
2461          (gnus-summary-last-subject))))
2462
2463 (defmacro gnus-summary-article-header (&optional number)
2464   "Return the header of article NUMBER."
2465   `(gnus-data-header (gnus-data-find
2466                       ,(or number '(gnus-summary-article-number)))))
2467
2468 (defmacro gnus-summary-thread-level (&optional number)
2469   "Return the level of thread that starts with article NUMBER."
2470   `(if (and (eq gnus-summary-make-false-root 'dummy)
2471             (get-text-property (point) 'gnus-intangible))
2472        0
2473      (gnus-data-level (gnus-data-find
2474                        ,(or number '(gnus-summary-article-number))))))
2475
2476 (defmacro gnus-summary-article-mark (&optional number)
2477   "Return the mark of article NUMBER."
2478   `(gnus-data-mark (gnus-data-find
2479                     ,(or number '(gnus-summary-article-number)))))
2480
2481 (defmacro gnus-summary-article-pos (&optional number)
2482   "Return the position of the line of article NUMBER."
2483   `(gnus-data-pos (gnus-data-find
2484                    ,(or number '(gnus-summary-article-number)))))
2485
2486 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2487 (defmacro gnus-summary-article-subject (&optional number)
2488   "Return current subject string or nil if nothing."
2489   `(let ((headers
2490           ,(if number
2491                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2492              '(gnus-data-header (assq (gnus-summary-article-number)
2493                                       gnus-newsgroup-data)))))
2494      (and headers
2495           (vectorp headers)
2496           (mail-header-subject headers))))
2497
2498 (defmacro gnus-summary-article-score (&optional number)
2499   "Return current article score."
2500   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2501                   gnus-newsgroup-scored))
2502        gnus-summary-default-score 0))
2503
2504 (defun gnus-summary-article-children (&optional number)
2505   "Return a list of article numbers that are children of article NUMBER."
2506   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2507          (level (gnus-data-level (car data)))
2508          l children)
2509     (while (and (setq data (cdr data))
2510                 (> (setq l (gnus-data-level (car data))) level))
2511       (and (= (1+ level) l)
2512            (push (gnus-data-number (car data))
2513                  children)))
2514     (nreverse children)))
2515
2516 (defun gnus-summary-article-parent (&optional number)
2517   "Return the article number of the parent of article NUMBER."
2518   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2519                                     (gnus-data-list t)))
2520          (level (gnus-data-level (car data))))
2521     (if (zerop level)
2522         ()                              ; This is a root.
2523       ;; We search until we find an article with a level less than
2524       ;; this one.  That function has to be the parent.
2525       (while (and (setq data (cdr data))
2526                   (not (< (gnus-data-level (car data)) level))))
2527       (and data (gnus-data-number (car data))))))
2528
2529 (defun gnus-unread-mark-p (mark)
2530   "Say whether MARK is the unread mark."
2531   (= mark gnus-unread-mark))
2532
2533 (defun gnus-read-mark-p (mark)
2534   "Say whether MARK is one of the marks that mark as read.
2535 This is all marks except unread, ticked, dormant, and expirable."
2536   (not (or (= mark gnus-unread-mark)
2537            (= mark gnus-ticked-mark)
2538            (= mark gnus-dormant-mark)
2539            (= mark gnus-expirable-mark))))
2540
2541 (defmacro gnus-article-mark (number)
2542   "Return the MARK of article NUMBER.
2543 This macro should only be used when computing the mark the \"first\"
2544 time; i.e., when generating the summary lines.  After that,
2545 `gnus-summary-article-mark' should be used to examine the
2546 marks of articles."
2547   `(cond
2548     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2549     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2550     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2551     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2552     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2553     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2554     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2555     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2556            gnus-ancient-mark))))
2557
2558 ;; Saving hidden threads.
2559
2560 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2561 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2562
2563 (defmacro gnus-save-hidden-threads (&rest forms)
2564   "Save hidden threads, eval FORMS, and restore the hidden threads."
2565   (let ((config (make-symbol "config")))
2566     `(let ((,config (gnus-hidden-threads-configuration)))
2567        (unwind-protect
2568            (save-excursion
2569              ,@forms)
2570          (gnus-restore-hidden-threads-configuration ,config)))))
2571
2572 (defun gnus-data-compute-positions ()
2573   "Compute the positions of all articles."
2574   (setq gnus-newsgroup-data-reverse nil)
2575   (let ((data gnus-newsgroup-data))
2576     (save-excursion
2577       (gnus-save-hidden-threads
2578         (gnus-summary-show-all-threads)
2579         (goto-char (point-min))
2580         (while data
2581           (while (get-text-property (point) 'gnus-intangible)
2582             (forward-line 1))
2583           (gnus-data-set-pos (car data) (+ (point) 3))
2584           (setq data (cdr data))
2585           (forward-line 1))))))
2586
2587 (defun gnus-hidden-threads-configuration ()
2588   "Return the current hidden threads configuration."
2589   (save-excursion
2590     (let (config)
2591       (goto-char (point-min))
2592       (while (search-forward "\r" nil t)
2593         (push (1- (point)) config))
2594       config)))
2595
2596 (defun gnus-restore-hidden-threads-configuration (config)
2597   "Restore hidden threads configuration from CONFIG."
2598   (save-excursion
2599     (let (point buffer-read-only)
2600       (while (setq point (pop config))
2601         (when (and (< point (point-max))
2602                    (goto-char point)
2603                    (eq (char-after) ?\n))
2604           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2605
2606 ;; Various summary mode internalish functions.
2607
2608 (defun gnus-mouse-pick-article (e)
2609   (interactive "e")
2610   (mouse-set-point e)
2611   (gnus-summary-next-page nil t))
2612
2613 (defun gnus-summary-set-display-table ()
2614   "Change the display table.
2615 Odd characters have a tendency to mess
2616 up nicely formatted displays - we make all possible glyphs
2617 display only a single character."
2618
2619   ;; We start from the standard display table, if any.
2620   (let ((table (or (copy-sequence standard-display-table)
2621                    (make-display-table)))
2622         (i 32))
2623     ;; Nix out all the control chars...
2624     (while (>= (setq i (1- i)) 0)
2625       (aset table i [??]))
2626     ;; ... but not newline and cr, of course.  (cr is necessary for the
2627     ;; selective display).
2628     (aset table ?\n nil)
2629     (aset table ?\r nil)
2630     ;; We keep TAB as well.
2631     (aset table ?\t nil)
2632     ;; We nix out any glyphs over 126 that are not set already.
2633     (let ((i 256))
2634       (while (>= (setq i (1- i)) 127)
2635         ;; Only modify if the entry is nil.
2636         (unless (aref table i)
2637           (aset table i [??]))))
2638     (setq buffer-display-table table)))
2639
2640 (defun gnus-summary-buffer-name (group)
2641   "Return the summary buffer name of GROUP."
2642   (concat "*Summary " group "*"))
2643
2644 (defun gnus-summary-setup-buffer (group)
2645   "Initialize summary buffer."
2646   (let ((buffer (gnus-summary-buffer-name group)))
2647     (if (get-buffer buffer)
2648         (progn
2649           (set-buffer buffer)
2650           (setq gnus-summary-buffer (current-buffer))
2651           (not gnus-newsgroup-prepared))
2652       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2653       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2654       (gnus-summary-mode group)
2655       (when gnus-carpal
2656         (gnus-carpal-setup-buffer 'summary))
2657       (unless gnus-single-article-buffer
2658         (make-local-variable 'gnus-article-buffer)
2659         (make-local-variable 'gnus-article-current)
2660         (make-local-variable 'gnus-original-article-buffer))
2661       (setq gnus-newsgroup-name group)
2662       t)))
2663
2664 (defun gnus-set-global-variables ()
2665   "Set the global equivalents of the buffer-local variables.
2666 They are set to the latest values they had.  These reflect the summary
2667 buffer that was in action when the last article was fetched."
2668   (when (eq major-mode 'gnus-summary-mode)
2669     (setq gnus-summary-buffer (current-buffer))
2670     (let ((name gnus-newsgroup-name)
2671           (marked gnus-newsgroup-marked)
2672           (unread gnus-newsgroup-unreads)
2673           (headers gnus-current-headers)
2674           (data gnus-newsgroup-data)
2675           (summary gnus-summary-buffer)
2676           (article-buffer gnus-article-buffer)
2677           (original gnus-original-article-buffer)
2678           (gac gnus-article-current)
2679           (reffed gnus-reffed-article-number)
2680           (score-file gnus-current-score-file)
2681           (default-charset gnus-newsgroup-charset)
2682           vlist)
2683       (let ((locals gnus-newsgroup-variables))
2684         (while locals
2685           (if (consp (car locals))
2686               (push (eval (caar locals)) vlist)
2687             (push (eval (car locals)) vlist))
2688           (setq locals (cdr locals)))
2689         (setq vlist (nreverse vlist)))
2690       (save-excursion
2691         (set-buffer gnus-group-buffer)
2692         (setq gnus-newsgroup-name name
2693               gnus-newsgroup-marked marked
2694               gnus-newsgroup-unreads unread
2695               gnus-current-headers headers
2696               gnus-newsgroup-data data
2697               gnus-article-current gac
2698               gnus-summary-buffer summary
2699               gnus-article-buffer article-buffer
2700               gnus-original-article-buffer original
2701               gnus-reffed-article-number reffed
2702               gnus-current-score-file score-file
2703               gnus-newsgroup-charset default-charset)
2704         (let ((locals gnus-newsgroup-variables))
2705           (while locals
2706             (if (consp (car locals))
2707                 (set (caar locals) (pop vlist))
2708               (set (car locals) (pop vlist)))
2709             (setq locals (cdr locals))))
2710         ;; The article buffer also has local variables.
2711         (when (gnus-buffer-live-p gnus-article-buffer)
2712           (set-buffer gnus-article-buffer)
2713           (setq gnus-summary-buffer summary))))))
2714
2715 (defun gnus-summary-article-unread-p (article)
2716   "Say whether ARTICLE is unread or not."
2717   (memq article gnus-newsgroup-unreads))
2718
2719 (defun gnus-summary-first-article-p (&optional article)
2720   "Return whether ARTICLE is the first article in the buffer."
2721   (if (not (setq article (or article (gnus-summary-article-number))))
2722       nil
2723     (eq article (caar gnus-newsgroup-data))))
2724
2725 (defun gnus-summary-last-article-p (&optional article)
2726   "Return whether ARTICLE is the last article in the buffer."
2727   (if (not (setq article (or article (gnus-summary-article-number))))
2728       ;; All non-existent numbers are the last article.  :-)
2729       t
2730     (not (cdr (gnus-data-find-list article)))))
2731
2732 (defun gnus-make-thread-indent-array ()
2733   (let ((n 200))
2734     (unless (and gnus-thread-indent-array
2735                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2736       (setq gnus-thread-indent-array (make-vector 201 "")
2737             gnus-thread-indent-array-level gnus-thread-indent-level)
2738       (while (>= n 0)
2739         (aset gnus-thread-indent-array n
2740               (make-string (* n gnus-thread-indent-level) ? ))
2741         (setq n (1- n))))))
2742
2743 (defun gnus-update-summary-mark-positions ()
2744   "Compute where the summary marks are to go."
2745   (save-excursion
2746     (when (gnus-buffer-exists-p gnus-summary-buffer)
2747       (set-buffer gnus-summary-buffer))
2748     (let ((gnus-replied-mark 129)
2749           (gnus-score-below-mark 130)
2750           (gnus-score-over-mark 130)
2751           (gnus-download-mark 131)
2752           (spec gnus-summary-line-format-spec)
2753           gnus-visual pos)
2754       (save-excursion
2755         (gnus-set-work-buffer)
2756         (let ((gnus-summary-line-format-spec spec)
2757               (gnus-newsgroup-downloadable '((0 . t))))
2758           (gnus-summary-insert-line
2759            (make-full-mail-header 0 "" "nobody" "" "" "" 0 0 "" nil)
2760            0 nil 128 t nil "" nil 1)
2761           (goto-char (point-min))
2762           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2763                                              (- (point) 2)))))
2764           (goto-char (point-min))
2765           (push (cons 'replied (and (search-forward "\201" nil t)
2766                                     (- (point) 2)))
2767                 pos)
2768           (goto-char (point-min))
2769           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2770                 pos)
2771           (goto-char (point-min))
2772           (push (cons 'download
2773                       (and (search-forward "\203" nil t) (- (point) 2)))
2774                 pos)))
2775       (setq gnus-summary-mark-positions pos))))
2776
2777 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2778   "Insert a dummy root in the summary buffer."
2779   (beginning-of-line)
2780   (gnus-add-text-properties
2781    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2782    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2783
2784 (defun gnus-summary-from-or-to-or-newsgroups (header)
2785   (let ((to (cdr (assq 'To (mail-header-extra header))))
2786         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2787         (default-mime-charset (with-current-buffer gnus-summary-buffer
2788                                 default-mime-charset)))
2789     (cond
2790      ((and to
2791            gnus-ignored-from-addresses
2792            (string-match gnus-ignored-from-addresses
2793                          (mail-header-from header)))
2794       (concat "-> "
2795               (or (car (funcall gnus-extract-address-components
2796                                 (funcall
2797                                  gnus-decode-encoded-word-function to)))
2798                   (funcall gnus-decode-encoded-word-function to))))
2799      ((and newsgroups
2800            gnus-ignored-from-addresses
2801            (string-match gnus-ignored-from-addresses
2802                          (mail-header-from header)))
2803       (concat "=> " newsgroups))
2804      (t
2805       (or (car (funcall gnus-extract-address-components
2806                         (mail-header-from header)))
2807           (mail-header-from header))))))
2808
2809 (defun gnus-summary-insert-line (gnus-tmp-header
2810                                  gnus-tmp-level gnus-tmp-current
2811                                  gnus-tmp-unread gnus-tmp-replied
2812                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2813                                  &optional gnus-tmp-dummy gnus-tmp-score
2814                                  gnus-tmp-process)
2815   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2816          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2817          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2818          (gnus-tmp-score-char
2819           (if (or (null gnus-summary-default-score)
2820                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2821                       gnus-summary-zcore-fuzz))
2822               ?  ;Whitespace
2823             (if (< gnus-tmp-score gnus-summary-default-score)
2824                 gnus-score-below-mark gnus-score-over-mark)))
2825          (gnus-tmp-replied
2826           (cond (gnus-tmp-process gnus-process-mark)
2827                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2828                  gnus-cached-mark)
2829                 (gnus-tmp-replied gnus-replied-mark)
2830                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2831                  gnus-saved-mark)
2832                 (t gnus-no-mark)))
2833          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2834          (gnus-tmp-name
2835           (cond
2836            ((string-match "<[^>]+> *$" gnus-tmp-from)
2837             (let ((beg (match-beginning 0)))
2838               (or (and (string-match "^\".+\"" gnus-tmp-from)
2839                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2840                   (substring gnus-tmp-from 0 beg))))
2841            ((string-match "(.+)" gnus-tmp-from)
2842             (substring gnus-tmp-from
2843                        (1+ (match-beginning 0)) (1- (match-end 0))))
2844            (t gnus-tmp-from)))
2845          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2846          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2847          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2848          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2849          (buffer-read-only nil))
2850     (when (string= gnus-tmp-name "")
2851       (setq gnus-tmp-name gnus-tmp-from))
2852     (unless (numberp gnus-tmp-lines)
2853       (setq gnus-tmp-lines 0))
2854     (gnus-put-text-property-excluding-characters-with-faces
2855      (point)
2856      (progn (eval gnus-summary-line-format-spec) (point))
2857      'gnus-number gnus-tmp-number)
2858     (when (gnus-visual-p 'summary-highlight 'highlight)
2859       (forward-line -1)
2860       (gnus-run-hooks 'gnus-summary-update-hook)
2861       (forward-line 1))))
2862
2863 (defun gnus-summary-update-line (&optional dont-update)
2864   "Update summary line after change."
2865   (when (and gnus-summary-default-score
2866              (not gnus-summary-inhibit-highlight))
2867     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2868            (article (gnus-summary-article-number))
2869            (score (gnus-summary-article-score article)))
2870       (unless dont-update
2871         (if (and gnus-summary-mark-below
2872                  (< (gnus-summary-article-score)
2873                     gnus-summary-mark-below))
2874             ;; This article has a low score, so we mark it as read.
2875             (when (memq article gnus-newsgroup-unreads)
2876               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2877           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2878             ;; This article was previously marked as read on account
2879             ;; of a low score, but now it has risen, so we mark it as
2880             ;; unread.
2881             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2882         (gnus-summary-update-mark
2883          (if (or (null gnus-summary-default-score)
2884                  (<= (abs (- score gnus-summary-default-score))
2885                      gnus-summary-zcore-fuzz))
2886              ?  ;Whitespace
2887            (if (< score gnus-summary-default-score)
2888                gnus-score-below-mark gnus-score-over-mark))
2889          'score))
2890       ;; Do visual highlighting.
2891       (when (gnus-visual-p 'summary-highlight 'highlight)
2892         (gnus-run-hooks 'gnus-summary-update-hook)))))
2893
2894 (defvar gnus-tmp-new-adopts nil)
2895
2896 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2897   "Return the number of articles in THREAD.
2898 This may be 0 in some cases -- if none of the articles in
2899 the thread are to be displayed."
2900   (let* ((number
2901           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2902           (cond
2903            ((not (listp thread))
2904             1)
2905            ((and (consp thread) (cdr thread))
2906             (apply
2907              '+ 1 (mapcar
2908                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2909            ((null thread)
2910             1)
2911            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2912             1)
2913            (t 0))))
2914     (when (and level (zerop level) gnus-tmp-new-adopts)
2915       (incf number
2916             (apply '+ (mapcar
2917                        'gnus-summary-number-of-articles-in-thread
2918                        gnus-tmp-new-adopts))))
2919     (if char
2920         (if (> number 1) gnus-not-empty-thread-mark
2921           gnus-empty-thread-mark)
2922       number)))
2923
2924 (defun gnus-summary-set-local-parameters (group)
2925   "Go through the local params of GROUP and set all variable specs in that list."
2926   (let ((params (gnus-group-find-parameter group))
2927         elem)
2928     (while params
2929       (setq elem (car params)
2930             params (cdr params))
2931       (and (consp elem)                 ; Has to be a cons.
2932            (consp (cdr elem))           ; The cdr has to be a list.
2933            (symbolp (car elem))         ; Has to be a symbol in there.
2934            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2935            (ignore-errors               ; So we set it.
2936              (make-local-variable (car elem))
2937              (set (car elem) (eval (nth 1 elem))))))))
2938
2939 (defun gnus-summary-read-group (group &optional show-all no-article
2940                                       kill-buffer no-display backward
2941                                       select-articles)
2942   "Start reading news in newsgroup GROUP.
2943 If SHOW-ALL is non-nil, already read articles are also listed.
2944 If NO-ARTICLE is non-nil, no article is selected initially.
2945 If NO-DISPLAY, don't generate a summary buffer."
2946   (let (result)
2947     (while (and group
2948                 (null (setq result
2949                             (let ((gnus-auto-select-next nil))
2950                               (or (gnus-summary-read-group-1
2951                                    group show-all no-article
2952                                    kill-buffer no-display
2953                                    select-articles)
2954                                   (setq show-all nil
2955                                         select-articles nil)))))
2956                 (eq gnus-auto-select-next 'quietly))
2957       (set-buffer gnus-group-buffer)
2958       ;; The entry function called above goes to the next
2959       ;; group automatically, so we go two groups back
2960       ;; if we are searching for the previous group.
2961       (when backward
2962         (gnus-group-prev-unread-group 2))
2963       (if (not (equal group (gnus-group-group-name)))
2964           (setq group (gnus-group-group-name))
2965         (setq group nil)))
2966     result))
2967
2968 (defun gnus-summary-jump-to-other-group (group &optional show-all)
2969   "Directly jump to the other GROUP from summary buffer.
2970 If SHOW-ALL is non-nil, already read articles are also listed."
2971   (interactive
2972    (if (eq gnus-summary-buffer (current-buffer))
2973        (list (completing-read
2974               "Group: " gnus-active-hashtb nil t
2975               (when (and gnus-newsgroup-name
2976                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
2977                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
2978               'gnus-group-history)
2979              current-prefix-arg)
2980      (error "%s must be invoked from a gnus summary buffer." this-command)))
2981   (unless (or (zerop (length group))
2982               (and gnus-newsgroup-name
2983                    (string-equal gnus-newsgroup-name group)))
2984     (gnus-summary-exit)
2985     (gnus-summary-read-group group show-all
2986                              gnus-dont-select-after-jump-to-other-group)))
2987
2988 (defun gnus-summary-read-group-1 (group show-all no-article
2989                                         kill-buffer no-display
2990                                         &optional select-articles)
2991   ;; Killed foreign groups can't be entered.
2992   ;;  (when (and (not (gnus-group-native-p group))
2993   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
2994   ;;    (error "Dead non-native groups can't be entered"))
2995   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2996   (let* ((new-group (gnus-summary-setup-buffer group))
2997          (quit-config (gnus-group-quit-config group))
2998          (did-select (and new-group (gnus-select-newsgroup
2999                                      group show-all select-articles))))
3000     (cond
3001      ;; This summary buffer exists already, so we just select it.
3002      ((not new-group)
3003       (gnus-set-global-variables)
3004       (when kill-buffer
3005         (gnus-kill-or-deaden-summary kill-buffer))
3006       (gnus-configure-windows 'summary 'force)
3007       (gnus-set-mode-line 'summary)
3008       (gnus-summary-position-point)
3009       (message "")
3010       t)
3011      ;; We couldn't select this group.
3012      ((null did-select)
3013       (when (and (eq major-mode 'gnus-summary-mode)
3014                  (not (equal (current-buffer) kill-buffer)))
3015         (kill-buffer (current-buffer))
3016         (if (not quit-config)
3017             (progn
3018               ;; Update the info -- marks might need to be removed,
3019               ;; for instance.
3020               (gnus-summary-update-info)
3021               (set-buffer gnus-group-buffer)
3022               (gnus-group-jump-to-group group)
3023               (gnus-group-next-unread-group 1))
3024           (gnus-handle-ephemeral-exit quit-config)))
3025       (let ((grpinfo (gnus-get-info group)))
3026         (if (null (gnus-info-read grpinfo))
3027             (gnus-message 3 "Group %s contains no messages" group)
3028           (gnus-message 3 "Can't select group")))
3029       nil)
3030      ;; The user did a `C-g' while prompting for number of articles,
3031      ;; so we exit this group.
3032      ((eq did-select 'quit)
3033       (and (eq major-mode 'gnus-summary-mode)
3034            (not (equal (current-buffer) kill-buffer))
3035            (kill-buffer (current-buffer)))
3036       (when kill-buffer
3037         (gnus-kill-or-deaden-summary kill-buffer))
3038       (if (not quit-config)
3039           (progn
3040             (set-buffer gnus-group-buffer)
3041             (gnus-group-jump-to-group group)
3042             (gnus-group-next-unread-group 1)
3043             (gnus-configure-windows 'group 'force))
3044         (gnus-handle-ephemeral-exit quit-config))
3045       ;; Finally signal the quit.
3046       (signal 'quit nil))
3047      ;; The group was successfully selected.
3048      (t
3049       (gnus-set-global-variables)
3050       ;; Save the active value in effect when the group was entered.
3051       (setq gnus-newsgroup-active
3052             (gnus-copy-sequence
3053              (gnus-active gnus-newsgroup-name)))
3054       ;; You can change the summary buffer in some way with this hook.
3055       (gnus-run-hooks 'gnus-select-group-hook)
3056       ;; Set any local variables in the group parameters.
3057       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3058       (gnus-update-format-specifications
3059        nil 'summary 'summary-mode 'summary-dummy)
3060       (gnus-update-summary-mark-positions)
3061       ;; Do score processing.
3062       (when gnus-use-scoring
3063         (gnus-possibly-score-headers))
3064       ;; Check whether to fill in the gaps in the threads.
3065       (when gnus-build-sparse-threads
3066         (gnus-build-sparse-threads))
3067       ;; Find the initial limit.
3068       (if gnus-show-threads
3069           (if show-all
3070               (let ((gnus-newsgroup-dormant nil))
3071                 (gnus-summary-initial-limit show-all))
3072             (gnus-summary-initial-limit show-all))
3073         ;; When untreaded, all articles are always shown.
3074         (setq gnus-newsgroup-limit
3075               (mapcar
3076                (lambda (header) (mail-header-number header))
3077                gnus-newsgroup-headers)))
3078       ;; Generate the summary buffer.
3079       (unless no-display
3080         (gnus-summary-prepare))
3081       (when gnus-use-trees
3082         (gnus-tree-open group)
3083         (setq gnus-summary-highlight-line-function
3084               'gnus-tree-highlight-article))
3085       ;; If the summary buffer is empty, but there are some low-scored
3086       ;; articles or some excluded dormants, we include these in the
3087       ;; buffer.
3088       (when (and (zerop (buffer-size))
3089                  (not no-display))
3090         (cond (gnus-newsgroup-dormant
3091                (gnus-summary-limit-include-dormant))
3092               ((and gnus-newsgroup-scored show-all)
3093                (gnus-summary-limit-include-expunged t))))
3094       ;; Function `gnus-apply-kill-file' must be called in this hook.
3095       (gnus-run-hooks 'gnus-apply-kill-hook)
3096       (if (and (zerop (buffer-size))
3097                (not no-display))
3098           (progn
3099             ;; This newsgroup is empty.
3100             (gnus-summary-catchup-and-exit nil t)
3101             (gnus-message 6 "No unread news")
3102             (when kill-buffer
3103               (gnus-kill-or-deaden-summary kill-buffer))
3104             ;; Return nil from this function.
3105             nil)
3106         ;; Hide conversation thread subtrees.  We cannot do this in
3107         ;; gnus-summary-prepare-hook since kill processing may not
3108         ;; work with hidden articles.
3109         (and gnus-show-threads
3110              gnus-thread-hide-subtree
3111              (gnus-summary-hide-all-threads))
3112         (when kill-buffer
3113           (gnus-kill-or-deaden-summary kill-buffer))
3114         ;; Show first unread article if requested.
3115         (if (and (not no-article)
3116                  (not no-display)
3117                  gnus-newsgroup-unreads
3118                  gnus-auto-select-first)
3119             (progn
3120               (gnus-configure-windows 'summary)
3121               (cond
3122                ((eq gnus-auto-select-first 'best)
3123                 (gnus-summary-best-unread-article))
3124                ((eq gnus-auto-select-first t)
3125                 (gnus-summary-first-unread-article))
3126                ((gnus-functionp gnus-auto-select-first)
3127                 (funcall gnus-auto-select-first))))
3128           ;; Don't select any articles, just move point to the first
3129           ;; article in the group.
3130           (goto-char (point-min))
3131           (gnus-summary-position-point)
3132           (gnus-configure-windows 'summary 'force)
3133           (gnus-set-mode-line 'summary))
3134         (when (get-buffer-window gnus-group-buffer t)
3135           ;; Gotta use windows, because recenter does weird stuff if
3136           ;; the current buffer ain't the displayed window.
3137           (let ((owin (selected-window)))
3138             (select-window (get-buffer-window gnus-group-buffer t))
3139             (when (gnus-group-goto-group group)
3140               (recenter))
3141             (select-window owin)))
3142         ;; Mark this buffer as "prepared".
3143         (setq gnus-newsgroup-prepared t)
3144         (gnus-run-hooks 'gnus-summary-prepared-hook)
3145         t)))))
3146
3147 (defun gnus-summary-prepare ()
3148   "Generate the summary buffer."
3149   (interactive)
3150   (let ((buffer-read-only nil))
3151     (erase-buffer)
3152     (setq gnus-newsgroup-data nil
3153           gnus-newsgroup-data-reverse nil)
3154     (gnus-run-hooks 'gnus-summary-generate-hook)
3155     ;; Generate the buffer, either with threads or without.
3156     (when gnus-newsgroup-headers
3157       (gnus-summary-prepare-threads
3158        (if gnus-show-threads
3159            (gnus-sort-gathered-threads
3160             (funcall gnus-summary-thread-gathering-function
3161                      (gnus-sort-threads
3162                       (gnus-cut-threads (gnus-make-threads)))))
3163          ;; Unthreaded display.
3164          (gnus-sort-articles gnus-newsgroup-headers))))
3165     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3166     ;; Call hooks for modifying summary buffer.
3167     (goto-char (point-min))
3168     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3169
3170 (defsubst gnus-general-simplify-subject (subject)
3171   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3172   (setq subject
3173         (cond
3174          ;; Truncate the subject.
3175          (gnus-simplify-subject-functions
3176           (gnus-map-function gnus-simplify-subject-functions subject))
3177          ((numberp gnus-summary-gather-subject-limit)
3178           (setq subject (gnus-simplify-subject-re subject))
3179           (if (> (length subject) gnus-summary-gather-subject-limit)
3180               (substring subject 0 gnus-summary-gather-subject-limit)
3181             subject))
3182          ;; Fuzzily simplify it.
3183          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3184           (gnus-simplify-subject-fuzzy subject))
3185          ;; Just remove the leading "Re:".
3186          (t
3187           (gnus-simplify-subject-re subject))))
3188
3189   (if (and gnus-summary-gather-exclude-subject
3190            (string-match gnus-summary-gather-exclude-subject subject))
3191       nil                               ; This article shouldn't be gathered
3192     subject))
3193
3194 (defun gnus-summary-simplify-subject-query ()
3195   "Query where the respool algorithm would put this article."
3196   (interactive)
3197   (gnus-summary-select-article)
3198   (message "%s"
3199            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3200
3201 (defun gnus-gather-threads-by-subject (threads)
3202   "Gather threads by looking at Subject headers."
3203   (if (not gnus-summary-make-false-root)
3204       threads
3205     (let ((hashtb (gnus-make-hashtable 1024))
3206           (prev threads)
3207           (result threads)
3208           subject hthread whole-subject)
3209       (while threads
3210         (setq subject (gnus-general-simplify-subject
3211                        (setq whole-subject (mail-header-subject
3212                                             (caar threads)))))
3213         (when subject
3214           (if (setq hthread (gnus-gethash subject hashtb))
3215               (progn
3216                 ;; We enter a dummy root into the thread, if we
3217                 ;; haven't done that already.
3218                 (unless (stringp (caar hthread))
3219                   (setcar hthread (list whole-subject (car hthread))))
3220                 ;; We add this new gathered thread to this gathered
3221                 ;; thread.
3222                 (setcdr (car hthread)
3223                         (nconc (cdar hthread) (list (car threads))))
3224                 ;; Remove it from the list of threads.
3225                 (setcdr prev (cdr threads))
3226                 (setq threads prev))
3227             ;; Enter this thread into the hash table.
3228             (gnus-sethash subject threads hashtb)))
3229         (setq prev threads)
3230         (setq threads (cdr threads)))
3231       result)))
3232
3233 (defun gnus-gather-threads-by-references (threads)
3234   "Gather threads by looking at References headers."
3235   (let ((idhashtb (gnus-make-hashtable 1024))
3236         (thhashtb (gnus-make-hashtable 1024))
3237         (prev threads)
3238         (result threads)
3239         ids references id gthread gid entered ref)
3240     (while threads
3241       (when (setq references (mail-header-references (caar threads)))
3242         (setq id (mail-header-id (caar threads))
3243               ids (gnus-split-references references)
3244               entered nil)
3245         (while (setq ref (pop ids))
3246           (setq ids (delete ref ids))
3247           (if (not (setq gid (gnus-gethash ref idhashtb)))
3248               (progn
3249                 (gnus-sethash ref id idhashtb)
3250                 (gnus-sethash id threads thhashtb))
3251             (setq gthread (gnus-gethash gid thhashtb))
3252             (unless entered
3253               ;; We enter a dummy root into the thread, if we
3254               ;; haven't done that already.
3255               (unless (stringp (caar gthread))
3256                 (setcar gthread (list (mail-header-subject (caar gthread))
3257                                       (car gthread))))
3258               ;; We add this new gathered thread to this gathered
3259               ;; thread.
3260               (setcdr (car gthread)
3261                       (nconc (cdar gthread) (list (car threads)))))
3262             ;; Add it into the thread hash table.
3263             (gnus-sethash id gthread thhashtb)
3264             (setq entered t)
3265             ;; Remove it from the list of threads.
3266             (setcdr prev (cdr threads))
3267             (setq threads prev))))
3268       (setq prev threads)
3269       (setq threads (cdr threads)))
3270     result))
3271
3272 (defun gnus-sort-gathered-threads (threads)
3273   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3274   (let ((result threads))
3275     (while threads
3276       (when (stringp (caar threads))
3277         (setcdr (car threads)
3278                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3279       (setq threads (cdr threads)))
3280     result))
3281
3282 (defun gnus-thread-loop-p (root thread)
3283   "Say whether ROOT is in THREAD."
3284   (let ((stack (list thread))
3285         (infloop 0)
3286         th)
3287     (while (setq thread (pop stack))
3288       (setq th (cdr thread))
3289       (while (and th
3290                   (not (eq (caar th) root)))
3291         (pop th))
3292       (if th
3293           ;; We have found a loop.
3294           (let (ref-dep)
3295             (setcdr thread (delq (car th) (cdr thread)))
3296             (if (boundp (setq ref-dep (intern "none"
3297                                               gnus-newsgroup-dependencies)))
3298                 (setcdr (symbol-value ref-dep)
3299                         (nconc (cdr (symbol-value ref-dep))
3300                                (list (car th))))
3301               (set ref-dep (list nil (car th))))
3302             (setq infloop 1
3303                   stack nil))
3304         ;; Push all the subthreads onto the stack.
3305         (push (cdr thread) stack)))
3306     infloop))
3307
3308 (defun gnus-make-threads ()
3309   "Go through the dependency hashtb and find the roots.  Return all threads."
3310   (let (threads)
3311     (while (catch 'infloop
3312              (mapatoms
3313               (lambda (refs)
3314                 ;; Deal with self-referencing References loops.
3315                 (when (and (car (symbol-value refs))
3316                            (not (zerop
3317                                  (apply
3318                                   '+
3319                                   (mapcar
3320                                    (lambda (thread)
3321                                      (gnus-thread-loop-p
3322                                       (car (symbol-value refs)) thread))
3323                                    (cdr (symbol-value refs)))))))
3324                   (setq threads nil)
3325                   (throw 'infloop t))
3326                 (unless (car (symbol-value refs))
3327                   ;; These threads do not refer back to any other articles,
3328                   ;; so they're roots.
3329                   (setq threads (append (cdr (symbol-value refs)) threads))))
3330               gnus-newsgroup-dependencies)))
3331     threads))
3332
3333 ;; Build the thread tree.
3334 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3335   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3336
3337 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3338 if it was already present.
3339
3340 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3341 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3342 Message-IDs will be renamed be renamed to a unique Message-ID before
3343 being entered.
3344
3345 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3346   (let* ((id (mail-header-id header))
3347          (id-dep (and id (intern id dependencies)))
3348          ref ref-dep ref-header)
3349     ;; Enter this `header' in the `dependencies' table.
3350     (cond
3351      ((not id-dep)
3352       (setq header nil))
3353      ;; The first two cases do the normal part: enter a new `header'
3354      ;; in the `dependencies' table.
3355      ((not (boundp id-dep))
3356       (set id-dep (list header)))
3357      ((null (car (symbol-value id-dep)))
3358       (setcar (symbol-value id-dep) header))
3359
3360      ;; From here the `header' was already present in the
3361      ;; `dependencies' table.
3362      (force-new
3363       ;; Overrides an existing entry;
3364       ;; just set the header part of the entry.
3365       (setcar (symbol-value id-dep) header))
3366
3367      ;; Renames the existing `header' to a unique Message-ID.
3368      ((not gnus-summary-ignore-duplicates)
3369       ;; An article with this Message-ID has already been seen.
3370       ;; We rename the Message-ID.
3371       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3372            (list header))
3373       (mail-header-set-id header id))
3374
3375      ;; The last case ignores an existing entry, except it adds any
3376      ;; additional Xrefs (in case the two articles came from different
3377      ;; servers.
3378      ;; Also sets `header' to `nil' meaning that the `dependencies'
3379      ;; table was *not* modified.
3380      (t
3381       (mail-header-set-xref
3382        (car (symbol-value id-dep))
3383        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3384                    "")
3385                (or (mail-header-xref header) "")))
3386       (setq header nil)))
3387
3388     (when header
3389       ;; First check if that we are not creating a References loop.
3390       (setq ref (gnus-parent-id (mail-header-references header)))
3391       (while (and ref
3392                   (setq ref-dep (intern-soft ref dependencies))
3393                   (boundp ref-dep)
3394                   (setq ref-header (car (symbol-value ref-dep))))
3395         (if (string= id ref)
3396             ;; Yuk!  This is a reference loop.  Make the article be a
3397             ;; root article.
3398             (progn
3399               (mail-header-set-references (car (symbol-value id-dep)) "none")
3400               (setq ref nil))
3401           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3402       (setq ref (gnus-parent-id (mail-header-references header)))
3403       (setq ref-dep (intern (or ref "none") dependencies))
3404       (if (boundp ref-dep)
3405           (setcdr (symbol-value ref-dep)
3406                   (nconc (cdr (symbol-value ref-dep))
3407                          (list (symbol-value id-dep))))
3408         (set ref-dep (list nil (symbol-value id-dep)))))
3409     header))
3410
3411 (defun gnus-build-sparse-threads ()
3412   (let ((headers gnus-newsgroup-headers)
3413         (mail-parse-charset gnus-newsgroup-charset)
3414         (gnus-summary-ignore-duplicates t)
3415         header references generation relations
3416         subject child end new-child date)
3417     ;; First we create an alist of generations/relations, where
3418     ;; generations is how much we trust the relation, and the relation
3419     ;; is parent/child.
3420     (gnus-message 7 "Making sparse threads...")
3421     (save-excursion
3422       (nnheader-set-temp-buffer " *gnus sparse threads*")
3423       (while (setq header (pop headers))
3424         (when (and (setq references (mail-header-references header))
3425                    (not (string= references "")))
3426           (insert references)
3427           (setq child (mail-header-id header)
3428                 subject (mail-header-subject header)
3429                 date (mail-header-date header)
3430                 generation 0)
3431           (while (search-backward ">" nil t)
3432             (setq end (1+ (point)))
3433             (when (search-backward "<" nil t)
3434               (setq new-child (buffer-substring (point) end))
3435               (push (list (incf generation)
3436                           child (setq child new-child)
3437                           subject date)
3438                     relations)))
3439           (when child
3440             (push (list (1+ generation) child nil subject) relations))
3441           (erase-buffer)))
3442       (kill-buffer (current-buffer)))
3443     ;; Sort over trustworthiness.
3444     (mapcar
3445      (lambda (relation)
3446        (when (gnus-dependencies-add-header
3447               (make-full-mail-header-from-decoded-header
3448                gnus-reffed-article-number
3449                (nth 3 relation) "" (or (nth 4 relation) "")
3450                (nth 1 relation)
3451                (or (nth 2 relation) "") 0 0 "")
3452               gnus-newsgroup-dependencies nil)
3453          (push gnus-reffed-article-number gnus-newsgroup-limit)
3454          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3455          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3456                gnus-newsgroup-reads)
3457          (decf gnus-reffed-article-number)))
3458      (sort relations 'car-less-than-car))
3459     (gnus-message 7 "Making sparse threads...done")))
3460
3461 (defun gnus-build-old-threads ()
3462   ;; Look at all the articles that refer back to old articles, and
3463   ;; fetch the headers for the articles that aren't there.  This will
3464   ;; build complete threads - if the roots haven't been expired by the
3465   ;; server, that is.
3466   (let ((mail-parse-charset gnus-newsgroup-charset)
3467         id heads)
3468     (mapatoms
3469      (lambda (refs)
3470        (when (not (car (symbol-value refs)))
3471          (setq heads (cdr (symbol-value refs)))
3472          (while heads
3473            (if (memq (mail-header-number (caar heads))
3474                      gnus-newsgroup-dormant)
3475                (setq heads (cdr heads))
3476              (setq id (symbol-name refs))
3477              (while (and (setq id (gnus-build-get-header id))
3478                          (not (car (gnus-id-to-thread id)))))
3479              (setq heads nil)))))
3480      gnus-newsgroup-dependencies)))
3481
3482 ;; This function has to be called with point after the article number
3483 ;; on the beginning of the line.
3484 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3485   (let ((eol (gnus-point-at-eol))
3486         (buffer (current-buffer))
3487         header)
3488
3489     ;; overview: [num subject from date id refs chars lines misc]
3490     (unwind-protect
3491         (progn
3492           (narrow-to-region (point) eol)
3493           (unless (eobp)
3494             (forward-char))
3495
3496           (setq header
3497                 (make-full-mail-header
3498                  number                         ; number
3499                  (nnheader-nov-field)           ; subject
3500                  (nnheader-nov-field)           ; from
3501                  (nnheader-nov-field)           ; date
3502                  (nnheader-nov-read-message-id) ; id
3503                  (nnheader-nov-field)           ; refs
3504                  (nnheader-nov-read-integer)    ; chars
3505                  (nnheader-nov-read-integer)    ; lines
3506                  (unless (eobp)
3507                    (if (looking-at "Xref: ")
3508                        (goto-char (match-end 0)))
3509                    (nnheader-nov-field))        ; Xref
3510                  (nnheader-nov-parse-extra))))  ; extra
3511
3512       (widen))
3513
3514     (when gnus-alter-header-function
3515       (funcall gnus-alter-header-function header))
3516     (gnus-dependencies-add-header header dependencies force-new)))
3517
3518 (defun gnus-build-get-header (id)
3519   "Look through the buffer of NOV lines and find the header to ID.
3520 Enter this line into the dependencies hash table, and return
3521 the id of the parent article (if any)."
3522   (let ((deps gnus-newsgroup-dependencies)
3523         found header)
3524     (prog1
3525         (save-excursion
3526           (set-buffer nntp-server-buffer)
3527           (let ((case-fold-search nil))
3528             (goto-char (point-min))
3529             (while (and (not found)
3530                         (search-forward id nil t))
3531               (beginning-of-line)
3532               (setq found (looking-at
3533                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3534                                    (regexp-quote id))))
3535               (or found (beginning-of-line 2)))
3536             (when found
3537               (beginning-of-line)
3538               (and
3539                (setq header (gnus-nov-parse-line
3540                              (read (current-buffer)) deps))
3541                (gnus-parent-id (mail-header-references header))))))
3542       (when header
3543         (let ((number (mail-header-number header)))
3544           (push number gnus-newsgroup-limit)
3545           (push header gnus-newsgroup-headers)
3546           (if (memq number gnus-newsgroup-unselected)
3547               (progn
3548                 (push number gnus-newsgroup-unreads)
3549                 (setq gnus-newsgroup-unselected
3550                       (delq number gnus-newsgroup-unselected)))
3551             (push number gnus-newsgroup-ancient)))))))
3552
3553 (defun gnus-build-all-threads ()
3554   "Read all the headers."
3555   (let ((gnus-summary-ignore-duplicates t)
3556         (mail-parse-charset gnus-newsgroup-charset)
3557         (dependencies gnus-newsgroup-dependencies)
3558         header article)
3559     (save-excursion
3560       (set-buffer nntp-server-buffer)
3561       (let ((case-fold-search nil))
3562         (goto-char (point-min))
3563         (while (not (eobp))
3564           (ignore-errors
3565             (setq article (read (current-buffer))
3566                   header (gnus-nov-parse-line article dependencies)))
3567           (when header
3568             (save-excursion
3569               (set-buffer gnus-summary-buffer)
3570               (push header gnus-newsgroup-headers)
3571               (if (memq (setq article (mail-header-number header))
3572                         gnus-newsgroup-unselected)
3573                   (progn
3574                     (push article gnus-newsgroup-unreads)
3575                     (setq gnus-newsgroup-unselected
3576                           (delq article gnus-newsgroup-unselected)))
3577                 (push article gnus-newsgroup-ancient)))
3578             (forward-line 1)))))))
3579
3580 (defun gnus-summary-update-article-line (article header)
3581   "Update the line for ARTICLE using HEADERS."
3582   (let* ((id (mail-header-id header))
3583          (thread (gnus-id-to-thread id)))
3584     (unless thread
3585       (error "Article in no thread"))
3586     ;; Update the thread.
3587     (setcar thread header)
3588     (gnus-summary-goto-subject article)
3589     (let* ((datal (gnus-data-find-list article))
3590            (data (car datal))
3591            (length (when (cdr datal)
3592                      (- (gnus-data-pos data)
3593                         (gnus-data-pos (cadr datal)))))
3594            (buffer-read-only nil)
3595            (level (gnus-summary-thread-level)))
3596       (gnus-delete-line)
3597       (gnus-summary-insert-line
3598        header level nil (gnus-article-mark article)
3599        (memq article gnus-newsgroup-replied)
3600        (memq article gnus-newsgroup-expirable)
3601        ;; Only insert the Subject string when it's different
3602        ;; from the previous Subject string.
3603        (if (and
3604             gnus-show-threads
3605             (gnus-subject-equal
3606              (condition-case ()
3607                  (mail-header-subject
3608                   (gnus-data-header
3609                    (cadr
3610                     (gnus-data-find-list
3611                      article
3612                      (gnus-data-list t)))))
3613                ;; Error on the side of excessive subjects.
3614                (error ""))
3615              (mail-header-subject header)))
3616            ""
3617          (mail-header-subject header))
3618        nil (cdr (assq article gnus-newsgroup-scored))
3619        (memq article gnus-newsgroup-processable))
3620       (when length
3621         (gnus-data-update-list
3622          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3623
3624 (defun gnus-summary-update-article (article &optional iheader)
3625   "Update ARTICLE in the summary buffer."
3626   (set-buffer gnus-summary-buffer)
3627   (let* ((header (gnus-summary-article-header article))
3628          (id (mail-header-id header))
3629          (data (gnus-data-find article))
3630          (thread (gnus-id-to-thread id))
3631          (references (mail-header-references header))
3632          (parent
3633           (gnus-id-to-thread
3634            (or (gnus-parent-id
3635                 (when (and references
3636                            (not (equal "" references)))
3637                   references))
3638                "none")))
3639          (buffer-read-only nil)
3640          (old (car thread)))
3641     (when thread
3642       (unless iheader
3643         (setcar thread nil)
3644         (when parent
3645           (delq thread parent)))
3646       (if (gnus-summary-insert-subject id header)
3647           ;; Set the (possibly) new article number in the data structure.
3648           (gnus-data-set-number data (gnus-id-to-article id))
3649         (setcar thread old)
3650         nil))))
3651
3652 (defun gnus-rebuild-thread (id &optional line)
3653   "Rebuild the thread containing ID.
3654 If LINE, insert the rebuilt thread starting on line LINE."
3655   (let ((buffer-read-only nil)
3656         old-pos current thread data)
3657     (if (not gnus-show-threads)
3658         (setq thread (list (car (gnus-id-to-thread id))))
3659       ;; Get the thread this article is part of.
3660       (setq thread (gnus-remove-thread id)))
3661     (setq old-pos (gnus-point-at-bol))
3662     (setq current (save-excursion
3663                     (and (zerop (forward-line -1))
3664                          (gnus-summary-article-number))))
3665     ;; If this is a gathered thread, we have to go some re-gathering.
3666     (when (stringp (car thread))
3667       (let ((subject (car thread))
3668             roots thr)
3669         (setq thread (cdr thread))
3670         (while thread
3671           (unless (memq (setq thr (gnus-id-to-thread
3672                                    (gnus-root-id
3673                                     (mail-header-id (caar thread)))))
3674                         roots)
3675             (push thr roots))
3676           (setq thread (cdr thread)))
3677         ;; We now have all (unique) roots.
3678         (if (= (length roots) 1)
3679             ;; All the loose roots are now one solid root.
3680             (setq thread (car roots))
3681           (setq thread (cons subject (gnus-sort-threads roots))))))
3682     (let (threads)
3683       ;; We then insert this thread into the summary buffer.
3684       (when line
3685         (goto-char (point-min))
3686         (forward-line (1- line)))
3687       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3688         (if gnus-show-threads
3689             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3690           (gnus-summary-prepare-unthreaded thread))
3691         (setq data (nreverse gnus-newsgroup-data))
3692         (setq threads gnus-newsgroup-threads))
3693       ;; We splice the new data into the data structure.
3694       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3695       ;;!!! then we want to insert at the beginning of the buffer.
3696       ;;!!! That happens to be true with Gnus now, but that may
3697       ;;!!! change in the future.  Perhaps.
3698       (gnus-data-enter-list
3699        (if line nil current) data (- (point) old-pos))
3700       (setq gnus-newsgroup-threads
3701             (nconc threads gnus-newsgroup-threads))
3702       (gnus-data-compute-positions))))
3703
3704 (defun gnus-number-to-header (number)
3705   "Return the header for article NUMBER."
3706   (let ((headers gnus-newsgroup-headers))
3707     (while (and headers
3708                 (not (= number (mail-header-number (car headers)))))
3709       (pop headers))
3710     (when headers
3711       (car headers))))
3712
3713 (defun gnus-parent-headers (in-headers &optional generation)
3714   "Return the headers of the GENERATIONeth parent of HEADERS."
3715   (unless generation
3716     (setq generation 1))
3717   (let ((parent t)
3718         (headers in-headers)
3719         references)
3720     (while (and parent
3721                 (not (zerop generation))
3722                 (setq references (mail-header-references headers)))
3723       (setq headers (if (and references
3724                              (setq parent (gnus-parent-id references)))
3725                         (car (gnus-id-to-thread parent))
3726                       nil))
3727       (decf generation))
3728     (and (not (eq headers in-headers))
3729          headers)))
3730
3731 (defun gnus-id-to-thread (id)
3732   "Return the (sub-)thread where ID appears."
3733   (gnus-gethash id gnus-newsgroup-dependencies))
3734
3735 (defun gnus-id-to-article (id)
3736   "Return the article number of ID."
3737   (let ((thread (gnus-id-to-thread id)))
3738     (when (and thread
3739                (car thread))
3740       (mail-header-number (car thread)))))
3741
3742 (defun gnus-id-to-header (id)
3743   "Return the article headers of ID."
3744   (car (gnus-id-to-thread id)))
3745
3746 (defun gnus-article-displayed-root-p (article)
3747   "Say whether ARTICLE is a root(ish) article."
3748   (let ((level (gnus-summary-thread-level article))
3749         (refs (mail-header-references  (gnus-summary-article-header article)))
3750         particle)
3751     (cond
3752      ((null level) nil)
3753      ((zerop level) t)
3754      ((null refs) t)
3755      ((null (gnus-parent-id refs)) t)
3756      ((and (= 1 level)
3757            (null (setq particle (gnus-id-to-article
3758                                  (gnus-parent-id refs))))
3759            (null (gnus-summary-thread-level particle)))))))
3760
3761 (defun gnus-root-id (id)
3762   "Return the id of the root of the thread where ID appears."
3763   (let (last-id prev)
3764     (while (and id (setq prev (car (gnus-id-to-thread id))))
3765       (setq last-id id
3766             id (gnus-parent-id (mail-header-references prev))))
3767     last-id))
3768
3769 (defun gnus-articles-in-thread (thread)
3770   "Return the list of articles in THREAD."
3771   (cons (mail-header-number (car thread))
3772         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3773
3774 (defun gnus-remove-thread (id &optional dont-remove)
3775   "Remove the thread that has ID in it."
3776   (let (headers thread last-id)
3777     ;; First go up in this thread until we find the root.
3778     (setq last-id (gnus-root-id id)
3779           headers (message-flatten-list (gnus-id-to-thread last-id)))
3780     ;; We have now found the real root of this thread.  It might have
3781     ;; been gathered into some loose thread, so we have to search
3782     ;; through the threads to find the thread we wanted.
3783     (let ((threads gnus-newsgroup-threads)
3784           sub)
3785       (while threads
3786         (setq sub (car threads))
3787         (if (stringp (car sub))
3788             ;; This is a gathered thread, so we look at the roots
3789             ;; below it to find whether this article is in this
3790             ;; gathered root.
3791             (progn
3792               (setq sub (cdr sub))
3793               (while sub
3794                 (when (member (caar sub) headers)
3795                   (setq thread (car threads)
3796                         threads nil
3797                         sub nil))
3798                 (setq sub (cdr sub))))
3799           ;; It's an ordinary thread, so we check it.
3800           (when (eq (car sub) (car headers))
3801             (setq thread sub
3802                   threads nil)))
3803         (setq threads (cdr threads)))
3804       ;; If this article is in no thread, then it's a root.
3805       (if thread
3806           (unless dont-remove
3807             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3808         (setq thread (gnus-id-to-thread last-id)))
3809       (when thread
3810         (prog1
3811             thread                      ; We return this thread.
3812           (unless dont-remove
3813             (if (stringp (car thread))
3814                 (progn
3815                   ;; If we use dummy roots, then we have to remove the
3816                   ;; dummy root as well.
3817                   (when (eq gnus-summary-make-false-root 'dummy)
3818                     ;; We go to the dummy root by going to
3819                     ;; the first sub-"thread", and then one line up.
3820                     (gnus-summary-goto-article
3821                      (mail-header-number (caadr thread)))
3822                     (forward-line -1)
3823                     (gnus-delete-line)
3824                     (gnus-data-compute-positions))
3825                   (setq thread (cdr thread))
3826                   (while thread
3827                     (gnus-remove-thread-1 (car thread))
3828                     (setq thread (cdr thread))))
3829               (gnus-remove-thread-1 thread))))))))
3830
3831 (defun gnus-remove-thread-1 (thread)
3832   "Remove the thread THREAD recursively."
3833   (let ((number (mail-header-number (pop thread)))
3834         d)
3835     (setq thread (reverse thread))
3836     (while thread
3837       (gnus-remove-thread-1 (pop thread)))
3838     (when (setq d (gnus-data-find number))
3839       (goto-char (gnus-data-pos d))
3840       (gnus-summary-show-thread)
3841       (gnus-data-remove
3842        number
3843        (- (gnus-point-at-bol)
3844           (prog1
3845               (1+ (gnus-point-at-eol))
3846             (gnus-delete-line)))))))
3847
3848 (defun gnus-sort-threads-1 (threads func)
3849   (sort (mapcar (lambda (thread)
3850                   (cons (car thread)
3851                         (and (cdr thread)
3852                              (gnus-sort-threads-1 (cdr thread) func))))
3853                 threads) func))
3854
3855 (defun gnus-sort-threads (threads)
3856   "Sort THREADS."
3857   (if (not gnus-thread-sort-functions)
3858       threads
3859     (gnus-message 8 "Sorting threads...")
3860     (prog1
3861         (gnus-sort-threads-1
3862          threads
3863          (gnus-make-sort-function gnus-thread-sort-functions))
3864       (gnus-message 8 "Sorting threads...done"))))
3865
3866 (defun gnus-sort-articles (articles)
3867   "Sort ARTICLES."
3868   (when gnus-article-sort-functions
3869     (gnus-message 7 "Sorting articles...")
3870     (prog1
3871         (setq gnus-newsgroup-headers
3872               (sort articles (gnus-make-sort-function
3873                               gnus-article-sort-functions)))
3874       (gnus-message 7 "Sorting articles...done"))))
3875
3876 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3877 (defmacro gnus-thread-header (thread)
3878   "Return header of first article in THREAD.
3879 Note that THREAD must never, ever be anything else than a variable -
3880 using some other form will lead to serious barfage."
3881   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3882   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3883   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
3884         (vector thread) 2))
3885
3886 (defsubst gnus-article-sort-by-number (h1 h2)
3887   "Sort articles by article number."
3888   (< (mail-header-number h1)
3889      (mail-header-number h2)))
3890
3891 (defun gnus-thread-sort-by-number (h1 h2)
3892   "Sort threads by root article number."
3893   (gnus-article-sort-by-number
3894    (gnus-thread-header h1) (gnus-thread-header h2)))
3895
3896 (defsubst gnus-article-sort-by-lines (h1 h2)
3897   "Sort articles by article Lines header."
3898   (< (mail-header-lines h1)
3899      (mail-header-lines h2)))
3900
3901 (defun gnus-thread-sort-by-lines (h1 h2)
3902   "Sort threads by root article Lines header."
3903   (gnus-article-sort-by-lines
3904    (gnus-thread-header h1) (gnus-thread-header h2)))
3905
3906 (defsubst gnus-article-sort-by-chars (h1 h2)
3907   "Sort articles by octet length."
3908   (< (mail-header-chars h1)
3909      (mail-header-chars h2)))
3910
3911 (defun gnus-thread-sort-by-chars (h1 h2)
3912   "Sort threads by root article octet length."
3913   (gnus-article-sort-by-chars
3914    (gnus-thread-header h1) (gnus-thread-header h2)))
3915
3916 (defsubst gnus-article-sort-by-author (h1 h2)
3917   "Sort articles by root author."
3918   (string-lessp
3919    (let ((addr (car (mime-entity-read-field h1 'From))))
3920      (or (std11-full-name-string addr)
3921          (std11-address-string addr)
3922          ""))
3923    (let ((addr (car (mime-entity-read-field h2 'From))))
3924      (or (std11-full-name-string addr)
3925          (std11-address-string addr)
3926          ""))
3927    ))
3928
3929 (defun gnus-thread-sort-by-author (h1 h2)
3930   "Sort threads by root author."
3931   (gnus-article-sort-by-author
3932    (gnus-thread-header h1)  (gnus-thread-header h2)))
3933
3934 (defsubst gnus-article-sort-by-subject (h1 h2)
3935   "Sort articles by root subject."
3936   (string-lessp
3937    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3938    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3939
3940 (defun gnus-thread-sort-by-subject (h1 h2)
3941   "Sort threads by root subject."
3942   (gnus-article-sort-by-subject
3943    (gnus-thread-header h1) (gnus-thread-header h2)))
3944
3945 (defsubst gnus-article-sort-by-date (h1 h2)
3946   "Sort articles by root article date."
3947   (time-less-p
3948    (gnus-date-get-time (mail-header-date h1))
3949    (gnus-date-get-time (mail-header-date h2))))
3950
3951 (defun gnus-thread-sort-by-date (h1 h2)
3952   "Sort threads by root article date."
3953   (gnus-article-sort-by-date
3954    (gnus-thread-header h1) (gnus-thread-header h2)))
3955
3956 (defsubst gnus-article-sort-by-score (h1 h2)
3957   "Sort articles by root article score.
3958 Unscored articles will be counted as having a score of zero."
3959   (> (or (cdr (assq (mail-header-number h1)
3960                     gnus-newsgroup-scored))
3961          gnus-summary-default-score 0)
3962      (or (cdr (assq (mail-header-number h2)
3963                     gnus-newsgroup-scored))
3964          gnus-summary-default-score 0)))
3965
3966 (defun gnus-thread-sort-by-score (h1 h2)
3967   "Sort threads by root article score."
3968   (gnus-article-sort-by-score
3969    (gnus-thread-header h1) (gnus-thread-header h2)))
3970
3971 (defun gnus-thread-sort-by-total-score (h1 h2)
3972   "Sort threads by the sum of all scores in the thread.
3973 Unscored articles will be counted as having a score of zero."
3974   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3975
3976 (defun gnus-thread-total-score (thread)
3977   ;; This function find the total score of THREAD.
3978   (cond ((null thread)
3979          0)
3980         ((consp thread)
3981          (if (stringp (car thread))
3982              (apply gnus-thread-score-function 0
3983                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3984            (gnus-thread-total-score-1 thread)))
3985         (t
3986          (gnus-thread-total-score-1 (list thread)))))
3987
3988 (defun gnus-thread-total-score-1 (root)
3989   ;; This function find the total score of the thread below ROOT.
3990   (setq root (car root))
3991   (apply gnus-thread-score-function
3992          (or (append
3993               (mapcar 'gnus-thread-total-score
3994                       (cdr (gnus-id-to-thread (mail-header-id root))))
3995               (when (> (mail-header-number root) 0)
3996                 (list (or (cdr (assq (mail-header-number root)
3997                                      gnus-newsgroup-scored))
3998                           gnus-summary-default-score 0))))
3999              (list gnus-summary-default-score)
4000              '(0))))
4001
4002 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4003 (defvar gnus-tmp-prev-subject nil)
4004 (defvar gnus-tmp-false-parent nil)
4005 (defvar gnus-tmp-root-expunged nil)
4006 (defvar gnus-tmp-dummy-line nil)
4007
4008 (eval-when-compile (defvar gnus-tmp-header))
4009 (defun gnus-extra-header (type &optional header)
4010   "Return the extra header of TYPE."
4011   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4012       ""))
4013
4014 (defun gnus-summary-prepare-threads (threads)
4015   "Prepare summary buffer from THREADS and indentation LEVEL.
4016 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4017 or a straight list of headers."
4018   (gnus-message 7 "Generating summary...")
4019
4020   (setq gnus-newsgroup-threads threads)
4021   (beginning-of-line)
4022
4023   (let ((gnus-tmp-level 0)
4024         (default-score (or gnus-summary-default-score 0))
4025         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4026         thread number subject stack state gnus-tmp-gathered beg-match
4027         new-roots gnus-tmp-new-adopts thread-end
4028         gnus-tmp-header gnus-tmp-unread
4029         gnus-tmp-replied gnus-tmp-subject-or-nil
4030         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4031         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4032         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
4033
4034     (setq gnus-tmp-prev-subject nil)
4035
4036     (if (vectorp (car threads))
4037         ;; If this is a straight (sic) list of headers, then a
4038         ;; threaded summary display isn't required, so we just create
4039         ;; an unthreaded one.
4040         (gnus-summary-prepare-unthreaded threads)
4041
4042       ;; Do the threaded display.
4043
4044       (while (or threads stack gnus-tmp-new-adopts new-roots)
4045
4046         (if (and (= gnus-tmp-level 0)
4047                  (or (not stack)
4048                      (= (caar stack) 0))
4049                  (not gnus-tmp-false-parent)
4050                  (or gnus-tmp-new-adopts new-roots))
4051             (if gnus-tmp-new-adopts
4052                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4053                       thread (list (car gnus-tmp-new-adopts))
4054                       gnus-tmp-header (caar thread)
4055                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4056               (when new-roots
4057                 (setq thread (list (car new-roots))
4058                       gnus-tmp-header (caar thread)
4059                       new-roots (cdr new-roots))))
4060
4061           (if threads
4062               ;; If there are some threads, we do them before the
4063               ;; threads on the stack.
4064               (setq thread threads
4065                     gnus-tmp-header (caar thread))
4066             ;; There were no current threads, so we pop something off
4067             ;; the stack.
4068             (setq state (car stack)
4069                   gnus-tmp-level (car state)
4070                   thread (cdr state)
4071                   stack (cdr stack)
4072                   gnus-tmp-header (caar thread))))
4073
4074         (setq gnus-tmp-false-parent nil)
4075         (setq gnus-tmp-root-expunged nil)
4076         (setq thread-end nil)
4077
4078         (if (stringp gnus-tmp-header)
4079             ;; The header is a dummy root.
4080             (cond
4081              ((eq gnus-summary-make-false-root 'adopt)
4082               ;; We let the first article adopt the rest.
4083               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4084                                                (cddar thread)))
4085               (setq gnus-tmp-gathered
4086                     (nconc (mapcar
4087                             (lambda (h) (mail-header-number (car h)))
4088                             (cddar thread))
4089                            gnus-tmp-gathered))
4090               (setq thread (cons (list (caar thread)
4091                                        (cadar thread))
4092                                  (cdr thread)))
4093               (setq gnus-tmp-level -1
4094                     gnus-tmp-false-parent t))
4095              ((eq gnus-summary-make-false-root 'empty)
4096               ;; We print adopted articles with empty subject fields.
4097               (setq gnus-tmp-gathered
4098                     (nconc (mapcar
4099                             (lambda (h) (mail-header-number (car h)))
4100                             (cddar thread))
4101                            gnus-tmp-gathered))
4102               (setq gnus-tmp-level -1))
4103              ((eq gnus-summary-make-false-root 'dummy)
4104               ;; We remember that we probably want to output a dummy
4105               ;; root.
4106               (setq gnus-tmp-dummy-line gnus-tmp-header)
4107               (setq gnus-tmp-prev-subject gnus-tmp-header))
4108              (t
4109               ;; We do not make a root for the gathered
4110               ;; sub-threads at all.
4111               (setq gnus-tmp-level -1)))
4112
4113           (setq number (mail-header-number gnus-tmp-header)
4114                 subject (mail-header-subject gnus-tmp-header))
4115
4116           (cond
4117            ;; If the thread has changed subject, we might want to make
4118            ;; this subthread into a root.
4119            ((and (null gnus-thread-ignore-subject)
4120                  (not (zerop gnus-tmp-level))
4121                  gnus-tmp-prev-subject
4122                  (not (inline
4123                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4124             (setq new-roots (nconc new-roots (list (car thread)))
4125                   thread-end t
4126                   gnus-tmp-header nil))
4127            ;; If the article lies outside the current limit,
4128            ;; then we do not display it.
4129            ((not (memq number gnus-newsgroup-limit))
4130             (setq gnus-tmp-gathered
4131                   (nconc (mapcar
4132                           (lambda (h) (mail-header-number (car h)))
4133                           (cdar thread))
4134                          gnus-tmp-gathered))
4135             (setq gnus-tmp-new-adopts (if (cdar thread)
4136                                           (append gnus-tmp-new-adopts
4137                                                   (cdar thread))
4138                                         gnus-tmp-new-adopts)
4139                   thread-end t
4140                   gnus-tmp-header nil)
4141             (when (zerop gnus-tmp-level)
4142               (setq gnus-tmp-root-expunged t)))
4143            ;; Perhaps this article is to be marked as read?
4144            ((and gnus-summary-mark-below
4145                  (< (or (cdr (assq number gnus-newsgroup-scored))
4146                         default-score)
4147                     gnus-summary-mark-below)
4148                  ;; Don't touch sparse articles.
4149                  (not (gnus-summary-article-sparse-p number))
4150                  (not (gnus-summary-article-ancient-p number)))
4151             (setq gnus-newsgroup-unreads
4152                   (delq number gnus-newsgroup-unreads))
4153             (if gnus-newsgroup-auto-expire
4154                 (push number gnus-newsgroup-expirable)
4155               (push (cons number gnus-low-score-mark)
4156                     gnus-newsgroup-reads))))
4157
4158           (when gnus-tmp-header
4159             ;; We may have an old dummy line to output before this
4160             ;; article.
4161             (when (and gnus-tmp-dummy-line
4162                        (gnus-subject-equal
4163                         gnus-tmp-dummy-line
4164                         (mail-header-subject gnus-tmp-header)))
4165               (gnus-summary-insert-dummy-line
4166                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4167               (setq gnus-tmp-dummy-line nil))
4168
4169             ;; Compute the mark.
4170             (setq gnus-tmp-unread (gnus-article-mark number))
4171
4172             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4173                                   gnus-tmp-header gnus-tmp-level)
4174                   gnus-newsgroup-data)
4175
4176             ;; Actually insert the line.
4177             (setq
4178              gnus-tmp-subject-or-nil
4179              (cond
4180               ((and gnus-thread-ignore-subject
4181                     gnus-tmp-prev-subject
4182                     (not (inline (gnus-subject-equal
4183                                   gnus-tmp-prev-subject subject))))
4184                subject)
4185               ((zerop gnus-tmp-level)
4186                (if (and (eq gnus-summary-make-false-root 'empty)
4187                         (memq number gnus-tmp-gathered)
4188                         gnus-tmp-prev-subject
4189                         (inline (gnus-subject-equal
4190                                  gnus-tmp-prev-subject subject)))
4191                    gnus-summary-same-subject
4192                  subject))
4193               (t gnus-summary-same-subject)))
4194             (if (and (eq gnus-summary-make-false-root 'adopt)
4195                      (= gnus-tmp-level 1)
4196                      (memq number gnus-tmp-gathered))
4197                 (setq gnus-tmp-opening-bracket ?\<
4198                       gnus-tmp-closing-bracket ?\>)
4199               (setq gnus-tmp-opening-bracket ?\[
4200                     gnus-tmp-closing-bracket ?\]))
4201             (setq
4202              gnus-tmp-indentation
4203              (aref gnus-thread-indent-array gnus-tmp-level)
4204              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4205              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4206                                 gnus-summary-default-score 0)
4207              gnus-tmp-score-char
4208              (if (or (null gnus-summary-default-score)
4209                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4210                          gnus-summary-zcore-fuzz))
4211                  ?  ;Whitespace
4212                (if (< gnus-tmp-score gnus-summary-default-score)
4213                    gnus-score-below-mark gnus-score-over-mark))
4214              gnus-tmp-replied
4215              (cond ((memq number gnus-newsgroup-processable)
4216                     gnus-process-mark)
4217                    ((memq number gnus-newsgroup-cached)
4218                     gnus-cached-mark)
4219                    ((memq number gnus-newsgroup-replied)
4220                     gnus-replied-mark)
4221                    ((memq number gnus-newsgroup-saved)
4222                     gnus-saved-mark)
4223                    (t gnus-no-mark))
4224              gnus-tmp-from (mail-header-from gnus-tmp-header)
4225              gnus-tmp-name
4226              (cond
4227               ((string-match "<[^>]+> *$" gnus-tmp-from)
4228                (setq beg-match (match-beginning 0))
4229                (or (and (string-match "^\".+\"" gnus-tmp-from)
4230                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4231                    (substring gnus-tmp-from 0 beg-match)))
4232               ((string-match "(.+)" gnus-tmp-from)
4233                (substring gnus-tmp-from
4234                           (1+ (match-beginning 0)) (1- (match-end 0))))
4235               (t gnus-tmp-from)))
4236             (when (string= gnus-tmp-name "")
4237               (setq gnus-tmp-name gnus-tmp-from))
4238             (unless (numberp gnus-tmp-lines)
4239               (setq gnus-tmp-lines 0))
4240             (gnus-put-text-property
4241              (point)
4242              (progn (eval gnus-summary-line-format-spec) (point))
4243              'gnus-number number)
4244             (when gnus-visual-p
4245               (forward-line -1)
4246               (gnus-run-hooks 'gnus-summary-update-hook)
4247               (forward-line 1))
4248
4249             (setq gnus-tmp-prev-subject subject)))
4250
4251         (when (nth 1 thread)
4252           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4253         (incf gnus-tmp-level)
4254         (setq threads (if thread-end nil (cdar thread)))
4255         (unless threads
4256           (setq gnus-tmp-level 0)))))
4257   (gnus-message 7 "Generating summary...done"))
4258
4259 (defun gnus-summary-prepare-unthreaded (headers)
4260   "Generate an unthreaded summary buffer based on HEADERS."
4261   (let (header number mark)
4262
4263     (beginning-of-line)
4264
4265     (while headers
4266       ;; We may have to root out some bad articles...
4267       (when (memq (setq number (mail-header-number
4268                                 (setq header (pop headers))))
4269                   gnus-newsgroup-limit)
4270         ;; Mark article as read when it has a low score.
4271         (when (and gnus-summary-mark-below
4272                    (< (or (cdr (assq number gnus-newsgroup-scored))
4273                           gnus-summary-default-score 0)
4274                       gnus-summary-mark-below)
4275                    (not (gnus-summary-article-ancient-p number)))
4276           (setq gnus-newsgroup-unreads
4277                 (delq number gnus-newsgroup-unreads))
4278           (if gnus-newsgroup-auto-expire
4279               (push number gnus-newsgroup-expirable)
4280             (push (cons number gnus-low-score-mark)
4281                   gnus-newsgroup-reads)))
4282
4283         (setq mark (gnus-article-mark number))
4284         (push (gnus-data-make number mark (1+ (point)) header 0)
4285               gnus-newsgroup-data)
4286         (gnus-summary-insert-line
4287          header 0 number
4288          mark (memq number gnus-newsgroup-replied)
4289          (memq number gnus-newsgroup-expirable)
4290          (mail-header-subject header) nil
4291          (cdr (assq number gnus-newsgroup-scored))
4292          (memq number gnus-newsgroup-processable))))))
4293
4294 (defun gnus-summary-remove-list-identifiers ()
4295   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4296   (let ((regexp (if (consp gnus-list-identifiers)
4297                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4298                   gnus-list-identifiers))
4299         changed subject)
4300     (when regexp
4301       (dolist (header gnus-newsgroup-headers)
4302         (setq subject (mail-header-subject header)
4303               changed nil)
4304         (while (string-match
4305                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4306                 subject)
4307           (setq subject
4308                 (concat (substring subject 0 (match-beginning 2))
4309                         (substring subject (match-end 0)))
4310                 changed t))
4311         (when (and changed
4312                    (string-match
4313                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4314           (setq subject
4315                 (concat (substring subject 0 (match-beginning 1))
4316                         (substring subject (match-end 1)))))
4317         (when changed
4318           (mail-header-set-subject header subject))))))
4319
4320 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4321   "Select newsgroup GROUP.
4322 If READ-ALL is non-nil, all articles in the group are selected.
4323 If SELECT-ARTICLES, only select those articles from GROUP."
4324   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4325          ;;!!! Dirty hack; should be removed.
4326          (gnus-summary-ignore-duplicates
4327           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4328               t
4329             gnus-summary-ignore-duplicates))
4330          (info (nth 2 entry))
4331          articles fetched-articles cached)
4332
4333     (unless (gnus-check-server
4334              (setq gnus-current-select-method
4335                    (gnus-find-method-for-group group)))
4336       (error "Couldn't open server"))
4337
4338     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4339         (gnus-activate-group group)     ; Or we can activate it...
4340         (progn                          ; Or we bug out.
4341           (when (equal major-mode 'gnus-summary-mode)
4342             (kill-buffer (current-buffer)))
4343           (error "Couldn't activate group %s: %s"
4344                  group (gnus-status-message group))))
4345
4346     (unless (gnus-request-group group t)
4347       (when (equal major-mode 'gnus-summary-mode)
4348         (kill-buffer (current-buffer)))
4349       (error "Couldn't request group %s: %s"
4350              group (gnus-status-message group)))
4351
4352     (setq gnus-newsgroup-name group)
4353     (setq gnus-newsgroup-unselected nil)
4354     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4355     (gnus-summary-setup-default-charset)
4356
4357     ;; Adjust and set lists of article marks.
4358     (when info
4359       (gnus-adjust-marked-articles info))
4360
4361     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4362     (setq cached
4363           (if (gnus-virtual-group-p group)
4364               gnus-newsgroup-cached
4365             (gnus-cache-articles-in-group group)))
4366
4367     (setq gnus-newsgroup-unreads
4368           (gnus-set-difference
4369            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4370            gnus-newsgroup-dormant))
4371
4372     (setq gnus-newsgroup-processable nil)
4373
4374     (gnus-update-read-articles group gnus-newsgroup-unreads)
4375
4376     (if (setq articles select-articles)
4377         (setq gnus-newsgroup-unselected
4378               (gnus-sorted-intersection
4379                gnus-newsgroup-unreads
4380                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4381       (setq articles (gnus-articles-to-read group read-all)))
4382
4383     (cond
4384      ((null articles)
4385       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4386       'quit)
4387      ((eq articles 0) nil)
4388      (t
4389       ;; Init the dependencies hash table.
4390       (setq gnus-newsgroup-dependencies
4391             (gnus-make-hashtable (length articles)))
4392       (gnus-set-global-variables)
4393       ;; Retrieve the headers and read them in.
4394       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4395       (setq gnus-newsgroup-headers
4396             (gnus-retrieve-parsed-headers
4397              articles gnus-newsgroup-name
4398              ;; We might want to fetch old headers, but
4399              ;; not if there is only 1 article.
4400              (and (or (and (not (eq gnus-fetch-old-headers 'some))
4401                            (not (numberp gnus-fetch-old-headers)))
4402                       (> (length articles) 1))
4403                   gnus-fetch-old-headers)))
4404       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4405
4406       ;; Suppress duplicates?
4407       (when gnus-suppress-duplicates
4408         (gnus-dup-suppress-articles))
4409
4410       ;; Set the initial limit.
4411       (setq gnus-newsgroup-limit (copy-sequence articles))
4412       ;; Remove canceled articles from the list of unread articles.
4413       (setq gnus-newsgroup-unreads
4414             (gnus-set-sorted-intersection
4415              gnus-newsgroup-unreads
4416              (setq fetched-articles
4417                    (mapcar (lambda (headers) (mail-header-number headers))
4418                            gnus-newsgroup-headers))))
4419       ;; Removed marked articles that do not exist.
4420       (gnus-update-missing-marks
4421        (gnus-sorted-complement fetched-articles articles))
4422
4423       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4424       (when cached
4425         (setq gnus-newsgroup-cached cached))
4426
4427       ;; We might want to build some more threads first.
4428       (when (and gnus-fetch-old-headers
4429                  (eq gnus-headers-retrieved-by 'nov))
4430         (if (eq gnus-fetch-old-headers 'invisible)
4431             (gnus-build-all-threads)
4432           (gnus-build-old-threads)))
4433       ;; Let the Gnus agent mark articles as read.
4434       (when gnus-agent
4435         (gnus-agent-get-undownloaded-list))
4436       ;; Remove list identifiers from subject
4437       (when gnus-list-identifiers
4438         (gnus-summary-remove-list-identifiers))
4439       ;; Check whether auto-expire is to be done in this group.
4440       (setq gnus-newsgroup-auto-expire
4441             (gnus-group-auto-expirable-p group))
4442       ;; Set up the article buffer now, if necessary.
4443       (unless gnus-single-article-buffer
4444         (gnus-article-setup-buffer))
4445       ;; First and last article in this newsgroup.
4446       (when gnus-newsgroup-headers
4447         (setq gnus-newsgroup-begin
4448               (mail-header-number (car gnus-newsgroup-headers))
4449               gnus-newsgroup-end
4450               (mail-header-number
4451                (gnus-last-element gnus-newsgroup-headers))))
4452       ;; GROUP is successfully selected.
4453       (or gnus-newsgroup-headers t)))))
4454
4455 (defun gnus-articles-to-read (group &optional read-all)
4456   "Find out what articles the user wants to read."
4457   (let* ((articles
4458           ;; Select all articles if `read-all' is non-nil, or if there
4459           ;; are no unread articles.
4460           (if (or read-all
4461                   (and (zerop (length gnus-newsgroup-marked))
4462                        (zerop (length gnus-newsgroup-unreads)))
4463                   (eq (gnus-group-find-parameter group 'display)
4464                       'all))
4465               (or
4466                (gnus-uncompress-range (gnus-active group))
4467                (gnus-cache-articles-in-group group))
4468             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4469                           (copy-sequence gnus-newsgroup-unreads))
4470                   '<)))
4471          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4472          (scored (length scored-list))
4473          (number (length articles))
4474          (marked (+ (length gnus-newsgroup-marked)
4475                     (length gnus-newsgroup-dormant)))
4476          (select
4477           (cond
4478            ((numberp read-all)
4479             read-all)
4480            (t
4481             (condition-case ()
4482                 (cond
4483                  ((and (or (<= scored marked) (= scored number))
4484                        (natnump gnus-large-newsgroup)
4485                        (> number gnus-large-newsgroup))
4486                   (let* ((cursor-in-echo-area nil)
4487                          (input (read-from-minibuffer
4488                                  (format
4489                                   "How many articles from %s (max %d): "
4490                                   (gnus-limit-string gnus-newsgroup-name 35)
4491                                   number)
4492                                  (cons (number-to-string gnus-large-newsgroup)
4493                                        0))))
4494                     (if (string-match "^[ \t]*$" input)
4495                         number
4496                       input)))
4497                  ((and (> scored marked) (< scored number)
4498                        (> (- scored number) 20))
4499                   (let ((input
4500                          (read-string
4501                           (format "%s %s (%d scored, %d total): "
4502                                   "How many articles from"
4503                                   group scored number))))
4504                     (if (string-match "^[ \t]*$" input)
4505                         number input)))
4506                  (t number))
4507               (quit
4508                (message "Quit getting the articles to read")
4509                nil))))))
4510     (setq select (if (stringp select) (string-to-number select) select))
4511     (if (or (null select) (zerop select))
4512         select
4513       (if (and (not (zerop scored)) (<= (abs select) scored))
4514           (progn
4515             (setq articles (sort scored-list '<))
4516             (setq number (length articles)))
4517         (setq articles (copy-sequence articles)))
4518
4519       (when (< (abs select) number)
4520         (if (< select 0)
4521             ;; Select the N oldest articles.
4522             (setcdr (nthcdr (1- (abs select)) articles) nil)
4523           ;; Select the N most recent articles.
4524           (setq articles (nthcdr (- number select) articles))))
4525       (setq gnus-newsgroup-unselected
4526             (gnus-sorted-intersection
4527              gnus-newsgroup-unreads
4528              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4529       (when gnus-alter-articles-to-read-function
4530         (setq gnus-newsgroup-unreads
4531               (sort
4532                (funcall gnus-alter-articles-to-read-function
4533                         gnus-newsgroup-name gnus-newsgroup-unreads)
4534                '<)))
4535       articles)))
4536
4537 (defun gnus-killed-articles (killed articles)
4538   (let (out)
4539     (while articles
4540       (when (inline (gnus-member-of-range (car articles) killed))
4541         (push (car articles) out))
4542       (setq articles (cdr articles)))
4543     out))
4544
4545 (defun gnus-uncompress-marks (marks)
4546   "Uncompress the mark ranges in MARKS."
4547   (let ((uncompressed '(score bookmark))
4548         out)
4549     (while marks
4550       (if (memq (caar marks) uncompressed)
4551           (push (car marks) out)
4552         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4553       (setq marks (cdr marks)))
4554     out))
4555
4556 (defun gnus-adjust-marked-articles (info)
4557   "Set all article lists and remove all marks that are no longer valid."
4558   (let* ((marked-lists (gnus-info-marks info))
4559          (active (gnus-active (gnus-info-group info)))
4560          (min (car active))
4561          (max (cdr active))
4562          (types gnus-article-mark-lists)
4563          (uncompressed '(score bookmark killed))
4564          marks var articles article mark)
4565
4566     (while marked-lists
4567       (setq marks (pop marked-lists))
4568       (set (setq var (intern (format "gnus-newsgroup-%s"
4569                                      (car (rassq (setq mark (car marks))
4570                                                  types)))))
4571            (if (memq (car marks) uncompressed) (cdr marks)
4572              (gnus-uncompress-range (cdr marks))))
4573
4574       (setq articles (symbol-value var))
4575
4576       ;; All articles have to be subsets of the active articles.
4577       (cond
4578        ;; Adjust "simple" lists.
4579        ((memq mark '(tick dormant expire reply save))
4580         (while articles
4581           (when (or (< (setq article (pop articles)) min) (> article max))
4582             (set var (delq article (symbol-value var))))))
4583        ;; Adjust assocs.
4584        ((memq mark uncompressed)
4585         (when (not (listp (cdr (symbol-value var))))
4586           (set var (list (symbol-value var))))
4587         (when (not (listp (cdr articles)))
4588           (setq articles (list articles)))
4589         (while articles
4590           (when (or (not (consp (setq article (pop articles))))
4591                     (< (car article) min)
4592                     (> (car article) max))
4593             (set var (delq article (symbol-value var))))))))))
4594
4595 (defun gnus-update-missing-marks (missing)
4596   "Go through the list of MISSING articles and remove them from the mark lists."
4597   (when missing
4598     (let ((types gnus-article-mark-lists)
4599           var m)
4600       ;; Go through all types.
4601       (while types
4602         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4603         (when (symbol-value var)
4604           ;; This list has articles.  So we delete all missing articles
4605           ;; from it.
4606           (setq m missing)
4607           (while m
4608             (set var (delq (pop m) (symbol-value var)))))))))
4609
4610 (defun gnus-update-marks ()
4611   "Enter the various lists of marked articles into the newsgroup info list."
4612   (let ((types gnus-article-mark-lists)
4613         (info (gnus-get-info gnus-newsgroup-name))
4614         (uncompressed '(score bookmark killed))
4615         type list newmarked symbol delta-marks)
4616     (when info
4617       ;; Add all marks lists to the list of marks lists.
4618       (while (setq type (pop types))
4619         (setq list (symbol-value
4620                     (setq symbol
4621                           (intern (format "gnus-newsgroup-%s"
4622                                           (car type))))))
4623
4624         (when list
4625           ;; Get rid of the entries of the articles that have the
4626           ;; default score.
4627           (when (and (eq (cdr type) 'score)
4628                      gnus-save-score
4629                      list)
4630             (let* ((arts list)
4631                    (prev (cons nil list))
4632                    (all prev))
4633               (while arts
4634                 (if (or (not (consp (car arts)))
4635                         (= (cdar arts) gnus-summary-default-score))
4636                     (setcdr prev (cdr arts))
4637                   (setq prev arts))
4638                 (setq arts (cdr arts)))
4639               (setq list (cdr all)))))
4640
4641         (unless (memq (cdr type) uncompressed)
4642           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4643
4644         (when (gnus-check-backend-function
4645                'request-set-mark gnus-newsgroup-name)
4646           ;; propagate flags to server, with the following exceptions:
4647           ;; uncompressed:s are not proper flags (they are cons cells)
4648           ;; cache is a internal gnus flag
4649           ;; download are local to one gnus installation (well)
4650           ;; unsend are for nndraft groups only
4651           ;; xxx: generality of this?  this suits nnimap anyway
4652           (unless (memq (cdr type) (append '(cache download unsend)
4653                                            uncompressed))
4654             (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4655                    (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4656                    (add (gnus-remove-from-range
4657                          (gnus-copy-sequence list) old)))
4658               (when add
4659                 (push (list add 'add (list (cdr type))) delta-marks))
4660               (when del
4661                 (push (list del 'del (list (cdr type))) delta-marks)))))
4662
4663         (when list
4664           (push (cons (cdr type) list) newmarked)))
4665
4666       (when delta-marks
4667         (unless (gnus-check-group gnus-newsgroup-name)
4668           (error "Can't open server for %s" gnus-newsgroup-name))
4669         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4670
4671       ;; Enter these new marks into the info of the group.
4672       (if (nthcdr 3 info)
4673           (setcar (nthcdr 3 info) newmarked)
4674         ;; Add the marks lists to the end of the info.
4675         (when newmarked
4676           (setcdr (nthcdr 2 info) (list newmarked))))
4677
4678       ;; Cut off the end of the info if there's nothing else there.
4679       (let ((i 5))
4680         (while (and (> i 2)
4681                     (not (nth i info)))
4682           (when (nthcdr (decf i) info)
4683             (setcdr (nthcdr i info) nil)))))))
4684
4685 (defun gnus-set-mode-line (where)
4686   "Set the mode line of the article or summary buffers.
4687 If WHERE is `summary', the summary mode line format will be used."
4688   ;; Is this mode line one we keep updated?
4689   (when (and (memq where gnus-updated-mode-lines)
4690              (symbol-value
4691               (intern (format "gnus-%s-mode-line-format-spec" where))))
4692     (let (mode-string)
4693       (save-excursion
4694         ;; We evaluate this in the summary buffer since these
4695         ;; variables are buffer-local to that buffer.
4696         (set-buffer gnus-summary-buffer)
4697         ;; We bind all these variables that are used in the `eval' form
4698         ;; below.
4699         (let* ((mformat (symbol-value
4700                          (intern
4701                           (format "gnus-%s-mode-line-format-spec" where))))
4702                (gnus-tmp-group-name (gnus-group-name-decode
4703                                      gnus-newsgroup-name
4704                                      (gnus-group-name-charset
4705                                       nil
4706                                       gnus-newsgroup-name)))
4707                (gnus-tmp-article-number (or gnus-current-article 0))
4708                (gnus-tmp-unread gnus-newsgroup-unreads)
4709                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4710                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4711                (gnus-tmp-unread-and-unselected
4712                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4713                             (zerop gnus-tmp-unselected))
4714                        "")
4715                       ((zerop gnus-tmp-unselected)
4716                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4717                       (t (format "{%d(+%d) more}"
4718                                  gnus-tmp-unread-and-unticked
4719                                  gnus-tmp-unselected))))
4720                (gnus-tmp-subject
4721                 (if (and gnus-current-headers
4722                          (vectorp gnus-current-headers))
4723                     (gnus-mode-string-quote
4724                      (mail-header-subject gnus-current-headers))
4725                   ""))
4726                bufname-length max-len
4727                gnus-tmp-header);; passed as argument to any user-format-funcs
4728           (setq mode-string (eval mformat))
4729           (setq bufname-length (if (string-match "%b" mode-string)
4730                                    (- (length
4731                                        (buffer-name
4732                                         (if (eq where 'summary)
4733                                             nil
4734                                           (get-buffer gnus-article-buffer))))
4735                                       2)
4736                                  0))
4737           (setq max-len (max 4 (if gnus-mode-non-string-length
4738                                    (- (window-width)
4739                                       gnus-mode-non-string-length
4740                                       bufname-length)
4741                                  (length mode-string))))
4742           ;; We might have to chop a bit of the string off...
4743           (when (> (length mode-string) max-len)
4744             (setq mode-string
4745                   (concat (gnus-truncate-string mode-string (- max-len 3))
4746                           "...")))
4747           ;; Pad the mode string a bit.
4748           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4749       ;; Update the mode line.
4750       (setq mode-line-buffer-identification
4751             (gnus-mode-line-buffer-identification (list mode-string)))
4752       (set-buffer-modified-p t))))
4753
4754 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4755   "Go through the HEADERS list and add all Xrefs to a hash table.
4756 The resulting hash table is returned, or nil if no Xrefs were found."
4757   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4758          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4759          (xref-hashtb (gnus-make-hashtable))
4760          start group entry number xrefs header)
4761     (while headers
4762       (setq header (pop headers))
4763       (when (and (setq xrefs (mail-header-xref header))
4764                  (not (memq (setq number (mail-header-number header))
4765                             unreads)))
4766         (setq start 0)
4767         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4768           (setq start (match-end 0))
4769           (setq group (if prefix
4770                           (concat prefix (substring xrefs (match-beginning 1)
4771                                                     (match-end 1)))
4772                         (substring xrefs (match-beginning 1) (match-end 1))))
4773           (setq number
4774                 (string-to-int (substring xrefs (match-beginning 2)
4775                                           (match-end 2))))
4776           (if (setq entry (gnus-gethash group xref-hashtb))
4777               (setcdr entry (cons number (cdr entry)))
4778             (gnus-sethash group (cons number nil) xref-hashtb)))))
4779     (and start xref-hashtb)))
4780
4781 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4782   "Look through all the headers and mark the Xrefs as read."
4783   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4784         name entry info xref-hashtb idlist method nth4)
4785     (save-excursion
4786       (set-buffer gnus-group-buffer)
4787       (when (setq xref-hashtb
4788                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4789         (mapatoms
4790          (lambda (group)
4791            (unless (string= from-newsgroup (setq name (symbol-name group)))
4792              (setq idlist (symbol-value group))
4793              ;; Dead groups are not updated.
4794              (and (prog1
4795                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4796                             info (nth 2 entry))
4797                     (when (stringp (setq nth4 (gnus-info-method info)))
4798                       (setq nth4 (gnus-server-to-method nth4))))
4799                   ;; Only do the xrefs if the group has the same
4800                   ;; select method as the group we have just read.
4801                   (or (gnus-methods-equal-p
4802                        nth4 (gnus-find-method-for-group from-newsgroup))
4803                       virtual
4804                       (equal nth4 (setq method (gnus-find-method-for-group
4805                                                 from-newsgroup)))
4806                       (and (equal (car nth4) (car method))
4807                            (equal (nth 1 nth4) (nth 1 method))))
4808                   gnus-use-cross-reference
4809                   (or (not (eq gnus-use-cross-reference t))
4810                       virtual
4811                       ;; Only do cross-references on subscribed
4812                       ;; groups, if that is what is wanted.
4813                       (<= (gnus-info-level info) gnus-level-subscribed))
4814                   (gnus-group-make-articles-read name idlist))))
4815          xref-hashtb)))))
4816
4817 (defun gnus-compute-read-articles (group articles)
4818   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4819          (info (nth 2 entry))
4820          (active (gnus-active group))
4821          ninfo)
4822     (when entry
4823       ;; First peel off all invalid article numbers.
4824       (when active
4825         (let ((ids articles)
4826               id first)
4827           (while (setq id (pop ids))
4828             (when (and first (> id (cdr active)))
4829               ;; We'll end up in this situation in one particular
4830               ;; obscure situation.  If you re-scan a group and get
4831               ;; a new article that is cross-posted to a different
4832               ;; group that has not been re-scanned, you might get
4833               ;; crossposted article that has a higher number than
4834               ;; Gnus believes possible.  So we re-activate this
4835               ;; group as well.  This might mean doing the
4836               ;; crossposting thingy will *increase* the number
4837               ;; of articles in some groups.  Tsk, tsk.
4838               (setq active (or (gnus-activate-group group) active)))
4839             (when (or (> id (cdr active))
4840                       (< id (car active)))
4841               (setq articles (delq id articles))))))
4842       ;; If the read list is nil, we init it.
4843       (if (and active
4844                (null (gnus-info-read info))
4845                (> (car active) 1))
4846           (setq ninfo (cons 1 (1- (car active))))
4847         (setq ninfo (gnus-info-read info)))
4848       ;; Then we add the read articles to the range.
4849       (gnus-add-to-range
4850        ninfo (setq articles (sort articles '<))))))
4851
4852 (defun gnus-group-make-articles-read (group articles)
4853   "Update the info of GROUP to say that ARTICLES are read."
4854   (let* ((num 0)
4855          (entry (gnus-gethash group gnus-newsrc-hashtb))
4856          (info (nth 2 entry))
4857          (active (gnus-active group))
4858          range)
4859     (when entry
4860       (setq range (gnus-compute-read-articles group articles))
4861       (save-excursion
4862         (set-buffer gnus-group-buffer)
4863         (gnus-undo-register
4864           `(progn
4865              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4866              (gnus-info-set-read ',info ',(gnus-info-read info))
4867              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4868              (gnus-group-update-group ,group t))))
4869       ;; Add the read articles to the range.
4870       (gnus-info-set-read info range)
4871       ;; Then we have to re-compute how many unread
4872       ;; articles there are in this group.
4873       (when active
4874         (cond
4875          ((not range)
4876           (setq num (- (1+ (cdr active)) (car active))))
4877          ((not (listp (cdr range)))
4878           (setq num (- (cdr active) (- (1+ (cdr range))
4879                                        (car range)))))
4880          (t
4881           (while range
4882             (if (numberp (car range))
4883                 (setq num (1+ num))
4884               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4885             (setq range (cdr range)))
4886           (setq num (- (cdr active) num))))
4887         ;; Update the number of unread articles.
4888         (setcar entry num)
4889         ;; Update the group buffer.
4890         (gnus-group-update-group group t)))))
4891
4892 (defvar gnus-newsgroup-none-id 0)
4893
4894 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4895   (let ((cur nntp-server-buffer)
4896         (dependencies
4897          (or dependencies
4898              (save-excursion (set-buffer gnus-summary-buffer)
4899                              gnus-newsgroup-dependencies)))
4900         headers id end ref
4901         (mail-parse-charset gnus-newsgroup-charset)
4902         (mail-parse-ignored-charsets
4903          (save-excursion (condition-case nil
4904                              (set-buffer gnus-summary-buffer)
4905                            (error))
4906                          gnus-newsgroup-ignored-charsets)))
4907     (save-excursion
4908       (set-buffer nntp-server-buffer)
4909       ;; Translate all TAB characters into SPACE characters.
4910       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4911       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4912       (gnus-run-hooks 'gnus-parse-headers-hook)
4913       (let ((case-fold-search t)
4914             in-reply-to header p lines chars ctype)
4915         (goto-char (point-min))
4916         ;; Search to the beginning of the next header.  Error messages
4917         ;; do not begin with 2 or 3.
4918         (while (re-search-forward "^[23][0-9]+ " nil t)
4919           (setq id nil
4920                 ref nil)
4921           ;; This implementation of this function, with nine
4922           ;; search-forwards instead of the one re-search-forward and
4923           ;; a case (which basically was the old function) is actually
4924           ;; about twice as fast, even though it looks messier.  You
4925           ;; can't have everything, I guess.  Speed and elegance
4926           ;; doesn't always go hand in hand.
4927           (setq
4928            header
4929            (make-full-mail-header
4930             ;; Number.
4931             (prog1
4932                 (read cur)
4933               (end-of-line)
4934               (setq p (point))
4935               (narrow-to-region (point)
4936                                 (or (and (search-forward "\n.\n" nil t)
4937                                          (- (point) 2))
4938                                     (point))))
4939             ;; Subject.
4940             (progn
4941               (goto-char p)
4942               (if (search-forward "\nsubject: " nil t)
4943                   (nnheader-header-value)
4944                 "(none)"))
4945             ;; From.
4946             (progn
4947               (goto-char p)
4948               (if (or (search-forward "\nfrom: " nil t)
4949                       (search-forward "\nfrom:" nil t))
4950                   (nnheader-header-value)
4951                 "(nobody)"))
4952             ;; Date.
4953             (progn
4954               (goto-char p)
4955               (if (search-forward "\ndate: " nil t)
4956                   (nnheader-header-value)
4957                 ""))
4958             ;; Message-ID.
4959             (progn
4960               (goto-char p)
4961               (setq id (if (re-search-forward
4962                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4963                            ;; We do it this way to make sure the Message-ID
4964                            ;; is (somewhat) syntactically valid.
4965                            (buffer-substring (match-beginning 1)
4966                                              (match-end 1))
4967                          ;; If there was no message-id, we just fake one
4968                          ;; to make subsequent routines simpler.
4969                          (nnheader-generate-fake-message-id))))
4970             ;; References.
4971             (progn
4972               (goto-char p)
4973               (if (search-forward "\nreferences: " nil t)
4974                   (progn
4975                     (setq end (point))
4976                     (prog1
4977                         (nnheader-header-value)
4978                       (setq ref
4979                             (buffer-substring
4980                              (progn
4981                                ;; (end-of-line)
4982                                (search-backward ">" end t)
4983                                (1+ (point)))
4984                              (progn
4985                                (search-backward "<" end t)
4986                                (point))))))
4987                 ;; Get the references from the in-reply-to header if there
4988                 ;; were no references and the in-reply-to header looks
4989                 ;; promising.
4990                 (if (and (search-forward "\nin-reply-to: " nil t)
4991                          (setq in-reply-to (nnheader-header-value))
4992                          (string-match "<[^>]+>" in-reply-to))
4993                     (let (ref2)
4994                       (setq ref (substring in-reply-to (match-beginning 0)
4995                                            (match-end 0)))
4996                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4997                         (setq ref2 (substring in-reply-to (match-beginning 0)
4998                                               (match-end 0)))
4999                         (when (> (length ref2) (length ref))
5000                           (setq ref ref2)))
5001                       ref)
5002                   (setq ref nil))))
5003             ;; Chars.
5004             (progn
5005               (goto-char p)
5006               (if (search-forward "\nchars: " nil t)
5007                   (if (numberp (setq chars (ignore-errors (read cur))))
5008                       chars 0)
5009                 0))
5010             ;; Lines.
5011             (progn
5012               (goto-char p)
5013               (if (search-forward "\nlines: " nil t)
5014                   (if (numberp (setq lines (ignore-errors (read cur))))
5015                       lines 0)
5016                 0))
5017             ;; Xref.
5018             (progn
5019               (goto-char p)
5020               (and (search-forward "\nxref: " nil t)
5021                    (nnheader-header-value)))
5022             ;; Extra.
5023             (when gnus-extra-headers
5024               (let ((extra gnus-extra-headers)
5025                     out)
5026                 (while extra
5027                   (goto-char p)
5028                   (when (search-forward
5029                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
5030                     (push (cons (car extra) (nnheader-header-value)) out))
5031                   (pop extra))
5032                 out))))
5033           (goto-char p)
5034           (if (and (search-forward "\ncontent-type: " nil t)
5035                    (setq ctype (nnheader-header-value)))
5036               (mime-entity-set-content-type-internal
5037                header (mime-parse-Content-Type ctype)))
5038           (when (equal id ref)
5039             (setq ref nil))
5040
5041           (when gnus-alter-header-function
5042             (funcall gnus-alter-header-function header)
5043             (setq id (mail-header-id header)
5044                   ref (gnus-parent-id (mail-header-references header))))
5045
5046           (when (setq header
5047                       (gnus-dependencies-add-header
5048                        header dependencies force-new))
5049             (push header headers))
5050           (goto-char (point-max))
5051           (widen))
5052         (nreverse headers)))))
5053
5054 ;; Goes through the xover lines and returns a list of vectors
5055 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5056                                                   force-new dependencies
5057                                                   group also-fetch-heads)
5058   "Parse the news overview data in the server buffer.
5059 Return a list of headers that match SEQUENCE (see
5060 `nntp-retrieve-headers')."
5061   ;; Get the Xref when the users reads the articles since most/some
5062   ;; NNTP servers do not include Xrefs when using XOVER.
5063   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5064   (let ((mail-parse-charset gnus-newsgroup-charset)
5065         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5066         (cur nntp-server-buffer)
5067         (dependencies (or dependencies gnus-newsgroup-dependencies))
5068         number headers header)
5069     (save-excursion
5070       (set-buffer nntp-server-buffer)
5071       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5072       ;; Allow the user to mangle the headers before parsing them.
5073       (gnus-run-hooks 'gnus-parse-headers-hook)
5074       (goto-char (point-min))
5075       (while (not (eobp))
5076         (condition-case ()
5077             (while (and sequence (not (eobp)))
5078               (setq number (read cur))
5079               (while (and sequence
5080                           (< (car sequence) number))
5081                 (setq sequence (cdr sequence)))
5082               (and sequence
5083                    (eq number (car sequence))
5084                    (progn
5085                      (setq sequence (cdr sequence))
5086                      (setq header (inline
5087                                     (gnus-nov-parse-line
5088                                      number dependencies force-new))))
5089                    (push header headers))
5090               (forward-line 1))
5091           (error
5092            (gnus-error 4 "Strange nov line (%d)"
5093                        (count-lines (point-min) (point)))))
5094         (forward-line 1))
5095       ;; A common bug in inn is that if you have posted an article and
5096       ;; then retrieves the active file, it will answer correctly --
5097       ;; the new article is included.  However, a NOV entry for the
5098       ;; article may not have been generated yet, so this may fail.
5099       ;; We work around this problem by retrieving the last few
5100       ;; headers using HEAD.
5101       (if (or (not also-fetch-heads)
5102               (not sequence))
5103           ;; We (probably) got all the headers.
5104           (nreverse headers)
5105         (let ((gnus-nov-is-evil t))
5106           (nconc
5107            (nreverse headers)
5108            (gnus-retrieve-parsed-headers sequence group)
5109            ))))))
5110
5111 (defun gnus-article-get-xrefs ()
5112   "Fill in the Xref value in `gnus-current-headers', if necessary.
5113 This is meant to be called in `gnus-article-internal-prepare-hook'."
5114   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5115                                  gnus-current-headers)))
5116     (or (not gnus-use-cross-reference)
5117         (not headers)
5118         (and (mail-header-xref headers)
5119              (not (string= (mail-header-xref headers) "")))
5120         (let ((case-fold-search t)
5121               xref)
5122           (save-restriction
5123             (nnheader-narrow-to-headers)
5124             (goto-char (point-min))
5125             (when (or (and (not (eobp))
5126                            (eq (downcase (char-after)) ?x)
5127                            (looking-at "Xref:"))
5128                       (search-forward "\nXref:" nil t))
5129               (goto-char (1+ (match-end 0)))
5130               (setq xref (buffer-substring (point)
5131                                            (progn (end-of-line) (point))))
5132               (mail-header-set-xref headers xref)))))))
5133
5134 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5135   "Find article ID and insert the summary line for that article.
5136 OLD-HEADER can either be a header or a line number to insert
5137 the subject line on."
5138   (let* ((line (and (numberp old-header) old-header))
5139          (old-header (and (vectorp old-header) old-header))
5140          (header (cond ((and old-header use-old-header)
5141                         old-header)
5142                        ((and (numberp id)
5143                              (gnus-number-to-header id))
5144                         (gnus-number-to-header id))
5145                        (t
5146                         (gnus-read-header id))))
5147          (number (and (numberp id) id))
5148          d)
5149     (when header
5150       ;; Rebuild the thread that this article is part of and go to the
5151       ;; article we have fetched.
5152       (when (and (not gnus-show-threads)
5153                  old-header)
5154         (when (and number
5155                    (setq d (gnus-data-find (mail-header-number old-header))))
5156           (goto-char (gnus-data-pos d))
5157           (gnus-data-remove
5158            number
5159            (- (gnus-point-at-bol)
5160               (prog1
5161                   (1+ (gnus-point-at-eol))
5162                 (gnus-delete-line))))))
5163       (when old-header
5164         (mail-header-set-number header (mail-header-number old-header)))
5165       (setq gnus-newsgroup-sparse
5166             (delq (setq number (mail-header-number header))
5167                   gnus-newsgroup-sparse))
5168       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5169       (push number gnus-newsgroup-limit)
5170       (gnus-rebuild-thread (mail-header-id header) line)
5171       (gnus-summary-goto-subject number nil t))
5172     (when (and (numberp number)
5173                (> number 0))
5174       ;; We have to update the boundaries even if we can't fetch the
5175       ;; article if ID is a number -- so that the next `P' or `N'
5176       ;; command will fetch the previous (or next) article even
5177       ;; if the one we tried to fetch this time has been canceled.
5178       (when (> number gnus-newsgroup-end)
5179         (setq gnus-newsgroup-end number))
5180       (when (< number gnus-newsgroup-begin)
5181         (setq gnus-newsgroup-begin number))
5182       (setq gnus-newsgroup-unselected
5183             (delq number gnus-newsgroup-unselected)))
5184     ;; Report back a success?
5185     (and header (mail-header-number header))))
5186
5187 ;;; Process/prefix in the summary buffer
5188
5189 (defun gnus-summary-work-articles (n)
5190   "Return a list of articles to be worked upon.
5191 The prefix argument, the list of process marked articles, and the
5192 current article will be taken into consideration."
5193   (save-excursion
5194     (set-buffer gnus-summary-buffer)
5195     (cond
5196      (n
5197       ;; A numerical prefix has been given.
5198       (setq n (prefix-numeric-value n))
5199       (let ((backward (< n 0))
5200             (n (abs (prefix-numeric-value n)))
5201             articles article)
5202         (save-excursion
5203           (while
5204               (and (> n 0)
5205                    (push (setq article (gnus-summary-article-number))
5206                          articles)
5207                    (if backward
5208                        (gnus-summary-find-prev nil article)
5209                      (gnus-summary-find-next nil article)))
5210             (decf n)))
5211         (nreverse articles)))
5212      ((and (gnus-region-active-p) (mark))
5213       (message "region active")
5214       ;; Work on the region between point and mark.
5215       (let ((max (max (point) (mark)))
5216             articles article)
5217         (save-excursion
5218           (goto-char (min (point) (mark)))
5219           (while
5220               (and
5221                (push (setq article (gnus-summary-article-number)) articles)
5222                (gnus-summary-find-next nil article)
5223                (< (point) max)))
5224           (nreverse articles))))
5225      (gnus-newsgroup-processable
5226       ;; There are process-marked articles present.
5227       ;; Save current state.
5228       (gnus-summary-save-process-mark)
5229       ;; Return the list.
5230       (reverse gnus-newsgroup-processable))
5231      (t
5232       ;; Just return the current article.
5233       (list (gnus-summary-article-number))))))
5234
5235 (defmacro gnus-summary-iterate (arg &rest forms)
5236   "Iterate over the process/prefixed articles and do FORMS.
5237 ARG is the interactive prefix given to the command.  FORMS will be
5238 executed with point over the summary line of the articles."
5239   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5240     `(let ((,articles (gnus-summary-work-articles ,arg)))
5241        (while ,articles
5242          (gnus-summary-goto-subject (car ,articles))
5243          ,@forms
5244          (pop ,articles)))))
5245
5246 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5247 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5248
5249 (defun gnus-summary-save-process-mark ()
5250   "Push the current set of process marked articles on the stack."
5251   (interactive)
5252   (push (copy-sequence gnus-newsgroup-processable)
5253         gnus-newsgroup-process-stack))
5254
5255 (defun gnus-summary-kill-process-mark ()
5256   "Push the current set of process marked articles on the stack and unmark."
5257   (interactive)
5258   (gnus-summary-save-process-mark)
5259   (gnus-summary-unmark-all-processable))
5260
5261 (defun gnus-summary-yank-process-mark ()
5262   "Pop the last process mark state off the stack and restore it."
5263   (interactive)
5264   (unless gnus-newsgroup-process-stack
5265     (error "Empty mark stack"))
5266   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5267
5268 (defun gnus-summary-process-mark-set (set)
5269   "Make SET into the current process marked articles."
5270   (gnus-summary-unmark-all-processable)
5271   (while set
5272     (gnus-summary-set-process-mark (pop set))))
5273
5274 ;;; Searching and stuff
5275
5276 (defun gnus-summary-search-group (&optional backward use-level)
5277   "Search for next unread newsgroup.
5278 If optional argument BACKWARD is non-nil, search backward instead."
5279   (save-excursion
5280     (set-buffer gnus-group-buffer)
5281     (when (gnus-group-search-forward
5282            backward nil (if use-level (gnus-group-group-level) nil))
5283       (gnus-group-group-name))))
5284
5285 (defun gnus-summary-best-group (&optional exclude-group)
5286   "Find the name of the best unread group.
5287 If EXCLUDE-GROUP, do not go to this group."
5288   (save-excursion
5289     (set-buffer gnus-group-buffer)
5290     (save-excursion
5291       (gnus-group-best-unread-group exclude-group))))
5292
5293 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5294   (if backward (gnus-summary-find-prev)
5295     (let* ((dummy (gnus-summary-article-intangible-p))
5296            (article (or article (gnus-summary-article-number)))
5297            (arts (gnus-data-find-list article))
5298            result)
5299       (when (and (not dummy)
5300                  (or (not gnus-summary-check-current)
5301                      (not unread)
5302                      (not (gnus-data-unread-p (car arts)))))
5303         (setq arts (cdr arts)))
5304       (when (setq result
5305                   (if unread
5306                       (progn
5307                         (while arts
5308                           (when (or (and undownloaded
5309                                          (eq gnus-undownloaded-mark
5310                                              (gnus-data-mark (car arts))))
5311                                     (gnus-data-unread-p (car arts)))
5312                             (setq result (car arts)
5313                                   arts nil))
5314                           (setq arts (cdr arts)))
5315                         result)
5316                     (car arts)))
5317         (goto-char (gnus-data-pos result))
5318         (gnus-data-number result)))))
5319
5320 (defun gnus-summary-find-prev (&optional unread article)
5321   (let* ((eobp (eobp))
5322          (article (or article (gnus-summary-article-number)))
5323          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5324          result)
5325     (when (and (not eobp)
5326                (or (not gnus-summary-check-current)
5327                    (not unread)
5328                    (not (gnus-data-unread-p (car arts)))))
5329       (setq arts (cdr arts)))
5330     (when (setq result
5331                 (if unread
5332                     (progn
5333                       (while arts
5334                         (when (gnus-data-unread-p (car arts))
5335                           (setq result (car arts)
5336                                 arts nil))
5337                         (setq arts (cdr arts)))
5338                       result)
5339                   (car arts)))
5340       (goto-char (gnus-data-pos result))
5341       (gnus-data-number result))))
5342
5343 (defun gnus-summary-find-subject (subject &optional unread backward article)
5344   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5345          (article (or article (gnus-summary-article-number)))
5346          (articles (gnus-data-list backward))
5347          (arts (gnus-data-find-list article articles))
5348          result)
5349     (when (or (not gnus-summary-check-current)
5350               (not unread)
5351               (not (gnus-data-unread-p (car arts))))
5352       (setq arts (cdr arts)))
5353     (while arts
5354       (and (or (not unread)
5355                (gnus-data-unread-p (car arts)))
5356            (vectorp (gnus-data-header (car arts)))
5357            (gnus-subject-equal
5358             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5359            (setq result (car arts)
5360                  arts nil))
5361       (setq arts (cdr arts)))
5362     (and result
5363          (goto-char (gnus-data-pos result))
5364          (gnus-data-number result))))
5365
5366 (defun gnus-summary-search-forward (&optional unread subject backward)
5367   "Search forward for an article.
5368 If UNREAD, look for unread articles.  If SUBJECT, look for
5369 articles with that subject.  If BACKWARD, search backward instead."
5370   (cond (subject (gnus-summary-find-subject subject unread backward))
5371         (backward (gnus-summary-find-prev unread))
5372         (t (gnus-summary-find-next unread))))
5373
5374 (defun gnus-recenter (&optional n)
5375   "Center point in window and redisplay frame.
5376 Also do horizontal recentering."
5377   (interactive "P")
5378   (when (and gnus-auto-center-summary
5379              (not (eq gnus-auto-center-summary 'vertical)))
5380     (gnus-horizontal-recenter))
5381   (recenter n))
5382
5383 (defun gnus-summary-recenter ()
5384   "Center point in the summary window.
5385 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5386 displayed, no centering will be performed."
5387   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5388   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5389   (interactive)
5390   (let* ((top (cond ((< (window-height) 4) 0)
5391                     ((< (window-height) 7) 1)
5392                     (t (if (numberp gnus-auto-center-summary)
5393                            gnus-auto-center-summary
5394                          2))))
5395          (height (1- (window-height)))
5396          (bottom (save-excursion (goto-char (point-max))
5397                                  (forward-line (- height))
5398                                  (point)))
5399          (window (get-buffer-window (current-buffer))))
5400     ;; The user has to want it.
5401     (when gnus-auto-center-summary
5402       (when (get-buffer-window gnus-article-buffer)
5403         ;; Only do recentering when the article buffer is displayed,
5404         ;; Set the window start to either `bottom', which is the biggest
5405         ;; possible valid number, or the second line from the top,
5406         ;; whichever is the least.
5407         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5408           (if (> bottom top-pos)
5409               ;; Keep the second line from the top visible
5410               (set-window-start window top-pos t)
5411             ;; Try to keep the bottom line visible; if it's partially
5412             ;; obscured, either scroll one more line to make it fully
5413             ;; visible, or revert to using TOP-POS.
5414             (save-excursion
5415               (goto-char (point-max))
5416               (forward-line -1)
5417               (let ((last-line-start (point)))
5418                 (goto-char bottom)
5419                 (set-window-start window (point) t)
5420                 (when (not (pos-visible-in-window-p last-line-start window))
5421                   (forward-line 1)
5422                   (set-window-start window (min (point) top-pos) t)))))))
5423       ;; Do horizontal recentering while we're at it.
5424       (when (and (get-buffer-window (current-buffer) t)
5425                  (not (eq gnus-auto-center-summary 'vertical)))
5426         (let ((selected (selected-window)))
5427           (select-window (get-buffer-window (current-buffer) t))
5428           (gnus-summary-position-point)
5429           (gnus-horizontal-recenter)
5430           (select-window selected))))))
5431
5432 (defun gnus-summary-jump-to-group (newsgroup)
5433   "Move point to NEWSGROUP in group mode buffer."
5434   ;; Keep update point of group mode buffer if visible.
5435   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5436       (save-window-excursion
5437         ;; Take care of tree window mode.
5438         (when (get-buffer-window gnus-group-buffer)
5439           (pop-to-buffer gnus-group-buffer))
5440         (gnus-group-jump-to-group newsgroup))
5441     (save-excursion
5442       ;; Take care of tree window mode.
5443       (if (get-buffer-window gnus-group-buffer)
5444           (pop-to-buffer gnus-group-buffer)
5445         (set-buffer gnus-group-buffer))
5446       (gnus-group-jump-to-group newsgroup))))
5447
5448 ;; This function returns a list of article numbers based on the
5449 ;; difference between the ranges of read articles in this group and
5450 ;; the range of active articles.
5451 (defun gnus-list-of-unread-articles (group)
5452   (let* ((read (gnus-info-read (gnus-get-info group)))
5453          (active (or (gnus-active group) (gnus-activate-group group)))
5454          (last (cdr active))
5455          first nlast unread)
5456     ;; If none are read, then all are unread.
5457     (if (not read)
5458         (setq first (car active))
5459       ;; If the range of read articles is a single range, then the
5460       ;; first unread article is the article after the last read
5461       ;; article.  Sounds logical, doesn't it?
5462       (if (and (not (listp (cdr read)))
5463                (or (< (car read) (car active))
5464                    (progn (setq read (list read))
5465                           nil)))
5466           (setq first (max (car active) (1+ (cdr read))))
5467         ;; `read' is a list of ranges.
5468         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5469                                   (caar read)))
5470                   1)
5471           (setq first (car active)))
5472         (while read
5473           (when first
5474             (while (< first nlast)
5475               (push first unread)
5476               (setq first (1+ first))))
5477           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5478           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5479           (setq read (cdr read)))))
5480     ;; And add the last unread articles.
5481     (while (<= first last)
5482       (push first unread)
5483       (setq first (1+ first)))
5484     ;; Return the list of unread articles.
5485     (delq 0 (nreverse unread))))
5486
5487 (defun gnus-list-of-read-articles (group)
5488   "Return a list of unread, unticked and non-dormant articles."
5489   (let* ((info (gnus-get-info group))
5490          (marked (gnus-info-marks info))
5491          (active (gnus-active group)))
5492     (and info active
5493          (gnus-set-difference
5494           (gnus-sorted-complement
5495            (gnus-uncompress-range active)
5496            (gnus-list-of-unread-articles group))
5497           (append
5498            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5499            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5500
5501 ;; Various summary commands
5502
5503 (defun gnus-summary-select-article-buffer ()
5504   "Reconfigure windows to show article buffer."
5505   (interactive)
5506   (if (not (gnus-buffer-live-p gnus-article-buffer))
5507       (error "There is no article buffer for this summary buffer")
5508     (gnus-configure-windows 'article)
5509     (select-window (get-buffer-window gnus-article-buffer))))
5510
5511 (defun gnus-summary-universal-argument (arg)
5512   "Perform any operation on all articles that are process/prefixed."
5513   (interactive "P")
5514   (let ((articles (gnus-summary-work-articles arg))
5515         func article)
5516     (if (eq
5517          (setq
5518           func
5519           (key-binding
5520            (read-key-sequence
5521             (substitute-command-keys
5522              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5523          'undefined)
5524         (gnus-error 1 "Undefined key")
5525       (save-excursion
5526         (while articles
5527           (gnus-summary-goto-subject (setq article (pop articles)))
5528           (let (gnus-newsgroup-processable)
5529             (command-execute func))
5530           (gnus-summary-remove-process-mark article)))))
5531   (gnus-summary-position-point))
5532
5533 (defun gnus-summary-toggle-truncation (&optional arg)
5534   "Toggle truncation of summary lines.
5535 With arg, turn line truncation on iff arg is positive."
5536   (interactive "P")
5537   (setq truncate-lines
5538         (if (null arg) (not truncate-lines)
5539           (> (prefix-numeric-value arg) 0)))
5540   (redraw-display))
5541
5542 (defun gnus-summary-reselect-current-group (&optional all rescan)
5543   "Exit and then reselect the current newsgroup.
5544 The prefix argument ALL means to select all articles."
5545   (interactive "P")
5546   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5547     (error "Ephemeral groups can't be reselected"))
5548   (let ((current-subject (gnus-summary-article-number))
5549         (group gnus-newsgroup-name))
5550     (setq gnus-newsgroup-begin nil)
5551     (gnus-summary-exit)
5552     ;; We have to adjust the point of group mode buffer because
5553     ;; point was moved to the next unread newsgroup by exiting.
5554     (gnus-summary-jump-to-group group)
5555     (when rescan
5556       (save-excursion
5557         (save-window-excursion
5558           ;; Don't show group contents.
5559           (set-window-start (selected-window) (point-max))
5560           (gnus-group-get-new-news-this-group 1))))
5561     (gnus-group-read-group all t)
5562     (gnus-summary-goto-subject current-subject nil t)))
5563
5564 (defun gnus-summary-rescan-group (&optional all)
5565   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5566   (interactive "P")
5567   (gnus-summary-reselect-current-group all t))
5568
5569 (defun gnus-summary-update-info (&optional non-destructive)
5570   (save-excursion
5571     (let ((group gnus-newsgroup-name))
5572       (when group
5573         (when gnus-newsgroup-kill-headers
5574           (setq gnus-newsgroup-killed
5575                 (gnus-compress-sequence
5576                  (nconc
5577                   (gnus-set-sorted-intersection
5578                    (gnus-uncompress-range gnus-newsgroup-killed)
5579                    (setq gnus-newsgroup-unselected
5580                          (sort gnus-newsgroup-unselected '<)))
5581                   (setq gnus-newsgroup-unreads
5582                         (sort gnus-newsgroup-unreads '<)))
5583                  t)))
5584         (unless (listp (cdr gnus-newsgroup-killed))
5585           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5586         (let ((headers gnus-newsgroup-headers))
5587           ;; Set the new ranges of read articles.
5588           (save-excursion
5589             (set-buffer gnus-group-buffer)
5590             (gnus-undo-force-boundary))
5591           (gnus-update-read-articles
5592            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5593           ;; Set the current article marks.
5594           (let ((gnus-newsgroup-scored
5595                  (if (and (not gnus-save-score)
5596                           (not non-destructive))
5597                      nil
5598                    gnus-newsgroup-scored)))
5599             (save-excursion
5600               (gnus-update-marks)))
5601           ;; Do the cross-ref thing.
5602           (when gnus-use-cross-reference
5603             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5604           ;; Do not switch windows but change the buffer to work.
5605           (set-buffer gnus-group-buffer)
5606           (unless (gnus-ephemeral-group-p group)
5607             (gnus-group-update-group group)))))))
5608
5609 (defun gnus-summary-save-newsrc (&optional force)
5610   "Save the current number of read/marked articles in the dribble buffer.
5611 The dribble buffer will then be saved.
5612 If FORCE (the prefix), also save the .newsrc file(s)."
5613   (interactive "P")
5614   (gnus-summary-update-info t)
5615   (if force
5616       (gnus-save-newsrc-file)
5617     (gnus-dribble-save)))
5618
5619 (defun gnus-summary-exit (&optional temporary)
5620   "Exit reading current newsgroup, and then return to group selection mode.
5621 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5622   (interactive)
5623   (gnus-set-global-variables)
5624   (gnus-kill-save-kill-buffer)
5625   (gnus-async-halt-prefetch)
5626   (let* ((group gnus-newsgroup-name)
5627          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5628          (mode major-mode)
5629          (group-point nil)
5630          (buf (current-buffer)))
5631     (unless quit-config
5632       ;; Do adaptive scoring, and possibly save score files.
5633       (when gnus-newsgroup-adaptive
5634         (gnus-score-adaptive))
5635       (when gnus-use-scoring
5636         (gnus-score-save)))
5637     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5638     ;; If we have several article buffers, we kill them at exit.
5639     (unless gnus-single-article-buffer
5640       (gnus-kill-buffer gnus-original-article-buffer)
5641       (setq gnus-article-current nil))
5642     (when gnus-use-cache
5643       (gnus-cache-possibly-remove-articles)
5644       (gnus-cache-save-buffers))
5645     (gnus-async-prefetch-remove-group group)
5646     (when gnus-suppress-duplicates
5647       (gnus-dup-enter-articles))
5648     (when gnus-use-trees
5649       (gnus-tree-close group))
5650     (when gnus-use-cache
5651       (gnus-cache-write-active))
5652     ;; Remove entries for this group.
5653     (nnmail-purge-split-history (gnus-group-real-name group))
5654     ;; Make all changes in this group permanent.
5655     (unless quit-config
5656       (gnus-run-hooks 'gnus-exit-group-hook)
5657       (gnus-summary-update-info))
5658     (gnus-close-group group)
5659     ;; Make sure where we were, and go to next newsgroup.
5660     (set-buffer gnus-group-buffer)
5661     (unless quit-config
5662       (gnus-group-jump-to-group group))
5663     (gnus-run-hooks 'gnus-summary-exit-hook)
5664     (unless (or quit-config
5665                 ;; If this group has disappeared from the summary
5666                 ;; buffer, don't skip forwards.
5667                 (not (string= group (gnus-group-group-name))))
5668       (gnus-group-next-unread-group 1))
5669     (setq group-point (point))
5670     (if temporary
5671         nil                             ;Nothing to do.
5672       ;; If we have several article buffers, we kill them at exit.
5673       (unless gnus-single-article-buffer
5674         (gnus-kill-buffer gnus-article-buffer)
5675         (gnus-kill-buffer gnus-original-article-buffer)
5676         (setq gnus-article-current nil))
5677       (set-buffer buf)
5678       (if (not gnus-kill-summary-on-exit)
5679           (gnus-deaden-summary)
5680         ;; We set all buffer-local variables to nil.  It is unclear why
5681         ;; this is needed, but if we don't, buffer-local variables are
5682         ;; not garbage-collected, it seems.  This would the lead to en
5683         ;; ever-growing Emacs.
5684         (gnus-summary-clear-local-variables)
5685         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5686           (gnus-summary-clear-local-variables))
5687         (when (get-buffer gnus-article-buffer)
5688           (bury-buffer gnus-article-buffer))
5689         ;; We clear the global counterparts of the buffer-local
5690         ;; variables as well, just to be on the safe side.
5691         (set-buffer gnus-group-buffer)
5692         (gnus-summary-clear-local-variables)
5693         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5694           (gnus-summary-clear-local-variables))
5695         ;; Return to group mode buffer.
5696         (when (eq mode 'gnus-summary-mode)
5697           (gnus-kill-buffer buf)))
5698       (setq gnus-current-select-method gnus-select-method)
5699       (pop-to-buffer gnus-group-buffer)
5700       (if (not quit-config)
5701           (progn
5702             (goto-char group-point)
5703             (gnus-configure-windows 'group 'force)
5704             (unless (pos-visible-in-window-p)
5705               (forward-line (/ (static-if (featurep 'xemacs)
5706                                    (window-displayed-height)
5707                                  (1- (window-height)))
5708                                -2))
5709               (set-window-start (selected-window) (point))
5710               (goto-char group-point)))
5711         (gnus-handle-ephemeral-exit quit-config))
5712       ;; Clear the current group name.
5713       (unless quit-config
5714         (setq gnus-newsgroup-name nil)))))
5715
5716 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5717 (defun gnus-summary-exit-no-update (&optional no-questions)
5718   "Quit reading current newsgroup without updating read article info."
5719   (interactive)
5720   (let* ((group gnus-newsgroup-name)
5721          (quit-config (gnus-group-quit-config group)))
5722     (when (or no-questions
5723               gnus-expert-user
5724               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5725       (gnus-async-halt-prefetch)
5726       (mapcar 'funcall
5727               (delq 'gnus-summary-expire-articles
5728                     (copy-sequence gnus-summary-prepare-exit-hook)))
5729       ;; If we have several article buffers, we kill them at exit.
5730       (unless gnus-single-article-buffer
5731         (gnus-kill-buffer gnus-article-buffer)
5732         (gnus-kill-buffer gnus-original-article-buffer)
5733         (setq gnus-article-current nil))
5734       (if (not gnus-kill-summary-on-exit)
5735           (gnus-deaden-summary)
5736         (gnus-close-group group)
5737         (gnus-summary-clear-local-variables)
5738         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5739           (gnus-summary-clear-local-variables))
5740         (set-buffer gnus-group-buffer)
5741         (gnus-summary-clear-local-variables)
5742         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5743           (gnus-summary-clear-local-variables))
5744         (when (get-buffer gnus-summary-buffer)
5745           (kill-buffer gnus-summary-buffer)))
5746       (unless gnus-single-article-buffer
5747         (setq gnus-article-current nil))
5748       (when gnus-use-trees
5749         (gnus-tree-close group))
5750       (gnus-async-prefetch-remove-group group)
5751       (when (get-buffer gnus-article-buffer)
5752         (bury-buffer gnus-article-buffer))
5753       ;; Return to the group buffer.
5754       (gnus-configure-windows 'group 'force)
5755       ;; Clear the current group name.
5756       (setq gnus-newsgroup-name nil)
5757       (when (equal (gnus-group-group-name) group)
5758         (gnus-group-next-unread-group 1))
5759       (when quit-config
5760         (gnus-handle-ephemeral-exit quit-config)))))
5761
5762 (defun gnus-handle-ephemeral-exit (quit-config)
5763   "Handle movement when leaving an ephemeral group.
5764 The state which existed when entering the ephemeral is reset."
5765   (if (not (buffer-name (car quit-config)))
5766       (gnus-configure-windows 'group 'force)
5767     (set-buffer (car quit-config))
5768     (cond ((eq major-mode 'gnus-summary-mode)
5769            (gnus-set-global-variables))
5770           ((eq major-mode 'gnus-article-mode)
5771            (save-excursion
5772              ;; The `gnus-summary-buffer' variable may point
5773              ;; to the old summary buffer when using a single
5774              ;; article buffer.
5775              (unless (gnus-buffer-live-p gnus-summary-buffer)
5776                (set-buffer gnus-group-buffer))
5777              (set-buffer gnus-summary-buffer)
5778              (gnus-set-global-variables))))
5779     (if (or (eq (cdr quit-config) 'article)
5780             (eq (cdr quit-config) 'pick))
5781         (progn
5782           ;; The current article may be from the ephemeral group
5783           ;; thus it is best that we reload this article
5784           (gnus-summary-show-article)
5785           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5786               (gnus-configure-windows 'pick 'force)
5787             (gnus-configure-windows (cdr quit-config) 'force)))
5788       (gnus-configure-windows (cdr quit-config) 'force))
5789     (when (eq major-mode 'gnus-summary-mode)
5790       (gnus-summary-next-subject 1 nil t)
5791       (gnus-summary-recenter)
5792       (gnus-summary-position-point))))
5793
5794 (defun gnus-summary-preview-mime-message ()
5795   "MIME decode and play this message."
5796   (interactive)
5797   (let ((gnus-break-pages nil)
5798         (gnus-show-mime t))
5799     (gnus-summary-select-article gnus-show-all-headers t))
5800   (select-window (get-buffer-window gnus-article-buffer)))
5801
5802 ;;; Dead summaries.
5803
5804 (defvar gnus-dead-summary-mode-map nil)
5805
5806 (unless gnus-dead-summary-mode-map
5807   (setq gnus-dead-summary-mode-map (make-keymap))
5808   (suppress-keymap gnus-dead-summary-mode-map)
5809   (substitute-key-definition
5810    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5811   (let ((keys '("\C-d" "\r" "\177" [delete])))
5812     (while keys
5813       (define-key gnus-dead-summary-mode-map
5814         (pop keys) 'gnus-summary-wake-up-the-dead))))
5815
5816 (defvar gnus-dead-summary-mode nil
5817   "Minor mode for Gnus summary buffers.")
5818
5819 (defun gnus-dead-summary-mode (&optional arg)
5820   "Minor mode for Gnus summary buffers."
5821   (interactive "P")
5822   (when (eq major-mode 'gnus-summary-mode)
5823     (make-local-variable 'gnus-dead-summary-mode)
5824     (setq gnus-dead-summary-mode
5825           (if (null arg) (not gnus-dead-summary-mode)
5826             (> (prefix-numeric-value arg) 0)))
5827     (when gnus-dead-summary-mode
5828       (gnus-add-minor-mode
5829        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5830
5831 (defun gnus-deaden-summary ()
5832   "Make the current summary buffer into a dead summary buffer."
5833   ;; Kill any previous dead summary buffer.
5834   (when (and gnus-dead-summary
5835              (buffer-name gnus-dead-summary))
5836     (save-excursion
5837       (set-buffer gnus-dead-summary)
5838       (when gnus-dead-summary-mode
5839         (kill-buffer (current-buffer)))))
5840   ;; Make this the current dead summary.
5841   (setq gnus-dead-summary (current-buffer))
5842   (gnus-dead-summary-mode 1)
5843   (let ((name (buffer-name)))
5844     (when (string-match "Summary" name)
5845       (rename-buffer
5846        (concat (substring name 0 (match-beginning 0)) "Dead "
5847                (substring name (match-beginning 0)))
5848        t)
5849       (bury-buffer))))
5850
5851 (defun gnus-kill-or-deaden-summary (buffer)
5852   "Kill or deaden the summary BUFFER."
5853   (save-excursion
5854     (when (and (buffer-name buffer)
5855                (not gnus-single-article-buffer))
5856       (save-excursion
5857         (set-buffer buffer)
5858         (gnus-kill-buffer gnus-article-buffer)
5859         (gnus-kill-buffer gnus-original-article-buffer)))
5860     (cond (gnus-kill-summary-on-exit
5861            (when (and gnus-use-trees
5862                       (gnus-buffer-exists-p buffer))
5863              (save-excursion
5864                (set-buffer buffer)
5865                (gnus-tree-close gnus-newsgroup-name)))
5866            (gnus-kill-buffer buffer))
5867           ((gnus-buffer-exists-p buffer)
5868            (save-excursion
5869              (set-buffer buffer)
5870              (gnus-deaden-summary))))))
5871
5872 (defun gnus-summary-wake-up-the-dead (&rest args)
5873   "Wake up the dead summary buffer."
5874   (interactive)
5875   (gnus-dead-summary-mode -1)
5876   (let ((name (buffer-name)))
5877     (when (string-match "Dead " name)
5878       (rename-buffer
5879        (concat (substring name 0 (match-beginning 0))
5880                (substring name (match-end 0)))
5881        t)))
5882   (gnus-message 3 "This dead summary is now alive again"))
5883
5884 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5885 (defun gnus-summary-fetch-faq (&optional faq-dir)
5886   "Fetch the FAQ for the current group.
5887 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5888 in."
5889   (interactive
5890    (list
5891     (when current-prefix-arg
5892       (completing-read
5893        "Faq dir: " (and (listp gnus-group-faq-directory)
5894                         (mapcar (lambda (file) (list file))
5895                                 gnus-group-faq-directory))))))
5896   (let (gnus-faq-buffer)
5897     (when (setq gnus-faq-buffer
5898                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5899       (gnus-configure-windows 'summary-faq))))
5900
5901 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5902 (defun gnus-summary-describe-group (&optional force)
5903   "Describe the current newsgroup."
5904   (interactive "P")
5905   (gnus-group-describe-group force gnus-newsgroup-name))
5906
5907 (defun gnus-summary-describe-briefly ()
5908   "Describe summary mode commands briefly."
5909   (interactive)
5910   (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")))
5911
5912 ;; Walking around group mode buffer from summary mode.
5913
5914 (defun gnus-summary-next-group (&optional no-article target-group backward)
5915   "Exit current newsgroup and then select next unread newsgroup.
5916 If prefix argument NO-ARTICLE is non-nil, no article is selected
5917 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5918 previous group instead."
5919   (interactive "P")
5920   ;; Stop pre-fetching.
5921   (gnus-async-halt-prefetch)
5922   (let ((current-group gnus-newsgroup-name)
5923         (current-buffer (current-buffer))
5924         entered)
5925     ;; First we semi-exit this group to update Xrefs and all variables.
5926     ;; We can't do a real exit, because the window conf must remain
5927     ;; the same in case the user is prompted for info, and we don't
5928     ;; want the window conf to change before that...
5929     (gnus-summary-exit t)
5930     (while (not entered)
5931       ;; Then we find what group we are supposed to enter.
5932       (set-buffer gnus-group-buffer)
5933       (gnus-group-jump-to-group current-group)
5934       (setq target-group
5935             (or target-group
5936                 (if (eq gnus-keep-same-level 'best)
5937                     (gnus-summary-best-group gnus-newsgroup-name)
5938                   (gnus-summary-search-group backward gnus-keep-same-level))))
5939       (if (not target-group)
5940           ;; There are no further groups, so we return to the group
5941           ;; buffer.
5942           (progn
5943             (gnus-message 5 "Returning to the group buffer")
5944             (setq entered t)
5945             (when (gnus-buffer-live-p current-buffer)
5946               (set-buffer current-buffer)
5947               (gnus-summary-exit))
5948             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5949         ;; We try to enter the target group.
5950         (gnus-group-jump-to-group target-group)
5951         (let ((unreads (gnus-group-group-unread)))
5952           (if (and (or (eq t unreads)
5953                        (and unreads (not (zerop unreads))))
5954                    (gnus-summary-read-group
5955                     target-group nil no-article
5956                     (and (buffer-name current-buffer) current-buffer)
5957                     nil backward))
5958               (setq entered t)
5959             (setq current-group target-group
5960                   target-group nil)))))))
5961
5962 (defun gnus-summary-prev-group (&optional no-article)
5963   "Exit current newsgroup and then select previous unread newsgroup.
5964 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5965   (interactive "P")
5966   (gnus-summary-next-group no-article nil t))
5967
5968 ;; Walking around summary lines.
5969
5970 (defun gnus-summary-first-subject (&optional unread undownloaded)
5971   "Go to the first unread subject.
5972 If UNREAD is non-nil, go to the first unread article.
5973 Returns the article selected or nil if there are no unread articles."
5974   (interactive "P")
5975   (prog1
5976       (cond
5977        ;; Empty summary.
5978        ((null gnus-newsgroup-data)
5979         (gnus-message 3 "No articles in the group")
5980         nil)
5981        ;; Pick the first article.
5982        ((not unread)
5983         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5984         (gnus-data-number (car gnus-newsgroup-data)))
5985        ;; No unread articles.
5986        ((null gnus-newsgroup-unreads)
5987         (gnus-message 3 "No more unread articles")
5988         nil)
5989        ;; Find the first unread article.
5990        (t
5991         (let ((data gnus-newsgroup-data))
5992           (while (and data
5993                       (and (not (and undownloaded
5994                                      (eq gnus-undownloaded-mark
5995                                          (gnus-data-mark (car data)))))
5996                            (not (gnus-data-unread-p (car data)))))
5997             (setq data (cdr data)))
5998           (when data
5999             (goto-char (gnus-data-pos (car data)))
6000             (gnus-data-number (car data))))))
6001     (gnus-summary-position-point)))
6002
6003 (defun gnus-summary-next-subject (n &optional unread dont-display)
6004   "Go to next N'th summary line.
6005 If N is negative, go to the previous N'th subject line.
6006 If UNREAD is non-nil, only unread articles are selected.
6007 The difference between N and the actual number of steps taken is
6008 returned."
6009   (interactive "p")
6010   (let ((backward (< n 0))
6011         (n (abs n)))
6012     (while (and (> n 0)
6013                 (if backward
6014                     (gnus-summary-find-prev unread)
6015                   (gnus-summary-find-next unread)))
6016       (unless (zerop (setq n (1- n)))
6017         (gnus-summary-show-thread)))
6018     (when (/= 0 n)
6019       (gnus-message 7 "No more%s articles"
6020                     (if unread " unread" "")))
6021     (unless dont-display
6022       (gnus-summary-recenter)
6023       (gnus-summary-position-point))
6024     n))
6025
6026 (defun gnus-summary-next-unread-subject (n)
6027   "Go to next N'th unread summary line."
6028   (interactive "p")
6029   (gnus-summary-next-subject n t))
6030
6031 (defun gnus-summary-prev-subject (n &optional unread)
6032   "Go to previous N'th summary line.
6033 If optional argument UNREAD is non-nil, only unread article is selected."
6034   (interactive "p")
6035   (gnus-summary-next-subject (- n) unread))
6036
6037 (defun gnus-summary-prev-unread-subject (n)
6038   "Go to previous N'th unread summary line."
6039   (interactive "p")
6040   (gnus-summary-next-subject (- n) t))
6041
6042 (defun gnus-summary-goto-subject (article &optional force silent)
6043   "Go the subject line of ARTICLE.
6044 If FORCE, also allow jumping to articles not currently shown."
6045   (interactive "nArticle number: ")
6046   (let ((b (point))
6047         (data (gnus-data-find article)))
6048     ;; We read in the article if we have to.
6049     (and (not data)
6050          force
6051          (gnus-summary-insert-subject
6052           article
6053           (if (or (numberp force) (vectorp force)) force)
6054           t)
6055          (setq data (gnus-data-find article)))
6056     (goto-char b)
6057     (if (not data)
6058         (progn
6059           (unless silent
6060             (gnus-message 3 "Can't find article %d" article))
6061           nil)
6062       (goto-char (gnus-data-pos data))
6063       (gnus-summary-position-point)
6064       article)))
6065
6066 ;; Walking around summary lines with displaying articles.
6067
6068 (defun gnus-summary-expand-window (&optional arg)
6069   "Make the summary buffer take up the entire Emacs frame.
6070 Given a prefix, will force an `article' buffer configuration."
6071   (interactive "P")
6072   (if arg
6073       (gnus-configure-windows 'article 'force)
6074     (gnus-configure-windows 'summary 'force)))
6075
6076 (defun gnus-summary-display-article (article &optional all-header)
6077   "Display ARTICLE in article buffer."
6078   (when (gnus-buffer-live-p gnus-article-buffer)
6079     (with-current-buffer gnus-article-buffer
6080       (set-buffer-multibyte t)))
6081   (gnus-set-global-variables)
6082   (when (gnus-buffer-live-p gnus-article-buffer)
6083     (with-current-buffer gnus-article-buffer
6084       (setq gnus-article-charset gnus-newsgroup-charset)
6085       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6086   (if (null article)
6087       nil
6088     (prog1
6089         (if gnus-summary-display-article-function
6090             (funcall gnus-summary-display-article-function article all-header)
6091           (gnus-article-prepare article all-header))
6092       (with-current-buffer gnus-article-buffer
6093         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6094              nil))
6095       (gnus-run-hooks 'gnus-select-article-hook)
6096       (when (and gnus-current-article
6097                  (not (zerop gnus-current-article)))
6098         (gnus-summary-goto-subject gnus-current-article))
6099       (gnus-summary-recenter)
6100       (when (and gnus-use-trees gnus-show-threads)
6101         (gnus-possibly-generate-tree article)
6102         (gnus-highlight-selected-tree article))
6103       ;; Successfully display article.
6104       (gnus-article-set-window-start
6105        (cdr (assq article gnus-newsgroup-bookmarks))))))
6106
6107 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6108   "Select the current article.
6109 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6110 non-nil, the article will be re-fetched even if it already present in
6111 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6112 be displayed."
6113   ;; Make sure we are in the summary buffer to work around bbdb bug.
6114   (unless (eq major-mode 'gnus-summary-mode)
6115     (set-buffer gnus-summary-buffer))
6116   (let ((article (or article (gnus-summary-article-number)))
6117         (all-headers (not (not all-headers))) ;Must be T or NIL.
6118         gnus-summary-display-article-function)
6119     (and (not pseudo)
6120          (gnus-summary-article-pseudo-p article)
6121          (error "This is a pseudo-article"))
6122     (save-excursion
6123       (set-buffer gnus-summary-buffer)
6124       (if (or (and gnus-single-article-buffer
6125                    (or (null gnus-current-article)
6126                        (null gnus-article-current)
6127                        (null (get-buffer gnus-article-buffer))
6128                        (not (eq article (cdr gnus-article-current)))
6129                        (not (equal (car gnus-article-current)
6130                                    gnus-newsgroup-name))))
6131               (and (not gnus-single-article-buffer)
6132                    (or (null gnus-current-article)
6133                        (not (eq gnus-current-article article))))
6134               force)
6135           ;; The requested article is different from the current article.
6136           (progn
6137             (gnus-summary-display-article article all-headers)
6138             (when (or all-headers gnus-show-all-headers)
6139               (gnus-article-show-all-headers))
6140             (gnus-article-set-window-start
6141              (cdr (assq article gnus-newsgroup-bookmarks)))
6142             article)
6143         (when (or all-headers gnus-show-all-headers)
6144           (gnus-article-show-all-headers))
6145         'old))))
6146
6147 (defun gnus-summary-force-verify-and-decrypt ()
6148   (interactive)
6149   (let ((mm-verify-option 'known)
6150         (mm-decrypt-option 'known))
6151     (gnus-summary-select-article nil 'force)))
6152
6153 (defun gnus-summary-set-current-mark (&optional current-mark)
6154   "Obsolete function."
6155   nil)
6156
6157 (defun gnus-summary-next-article (&optional unread subject backward push)
6158   "Select the next article.
6159 If UNREAD, only unread articles are selected.
6160 If SUBJECT, only articles with SUBJECT are selected.
6161 If BACKWARD, the previous article is selected instead of the next."
6162   (interactive "P")
6163   (cond
6164    ;; Is there such an article?
6165    ((and (gnus-summary-search-forward unread subject backward)
6166          (or (gnus-summary-display-article (gnus-summary-article-number))
6167              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6168     (gnus-summary-position-point))
6169    ;; If not, we try the first unread, if that is wanted.
6170    ((and subject
6171          gnus-auto-select-same
6172          (gnus-summary-first-unread-article))
6173     (gnus-summary-position-point)
6174     (gnus-message 6 "Wrapped"))
6175    ;; Try to get next/previous article not displayed in this group.
6176    ((and gnus-auto-extend-newsgroup
6177          (not unread) (not subject))
6178     (gnus-summary-goto-article
6179      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6180      nil (count-lines (point-min) (point))))
6181    ;; Go to next/previous group.
6182    (t
6183     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6184       (gnus-summary-jump-to-group gnus-newsgroup-name))
6185     (let ((cmd last-command-char)
6186           (point
6187            (save-excursion
6188              (set-buffer gnus-group-buffer)
6189              (point)))
6190           (group
6191            (if (eq gnus-keep-same-level 'best)
6192                (gnus-summary-best-group gnus-newsgroup-name)
6193              (gnus-summary-search-group backward gnus-keep-same-level))))
6194       ;; For some reason, the group window gets selected.  We change
6195       ;; it back.
6196       (select-window (get-buffer-window (current-buffer)))
6197       ;; Select next unread newsgroup automagically.
6198       (cond
6199        ((or (not gnus-auto-select-next)
6200             (not cmd))
6201         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6202        ((or (eq gnus-auto-select-next 'quietly)
6203             (and (eq gnus-auto-select-next 'slightly-quietly)
6204                  push)
6205             (and (eq gnus-auto-select-next 'almost-quietly)
6206                  (gnus-summary-last-article-p)))
6207         ;; Select quietly.
6208         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6209             (gnus-summary-exit)
6210           (gnus-message 7 "No more%s articles (%s)..."
6211                         (if unread " unread" "")
6212                         (if group (concat "selecting " group)
6213                           "exiting"))
6214           (gnus-summary-next-group nil group backward)))
6215        (t
6216         (when (gnus-key-press-event-p last-input-event)
6217           (gnus-summary-walk-group-buffer
6218            gnus-newsgroup-name cmd unread backward point))))))))
6219
6220 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6221   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6222                       (?\C-p (gnus-group-prev-unread-group 1))))
6223         (cursor-in-echo-area t)
6224         keve key group ended)
6225     (save-excursion
6226       (set-buffer gnus-group-buffer)
6227       (goto-char start)
6228       (setq group
6229             (if (eq gnus-keep-same-level 'best)
6230                 (gnus-summary-best-group gnus-newsgroup-name)
6231               (gnus-summary-search-group backward gnus-keep-same-level))))
6232     (while (not ended)
6233       (gnus-message
6234        5 "No more%s articles%s" (if unread " unread" "")
6235        (if (and group
6236                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6237            (format " (Type %s for %s [%s])"
6238                    (single-key-description cmd) group
6239                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6240          (format " (Type %s to exit %s)"
6241                  (single-key-description cmd)
6242                  gnus-newsgroup-name)))
6243       ;; Confirm auto selection.
6244       (setq key (car (setq keve (gnus-read-event-char))))
6245       (setq ended t)
6246       (cond
6247        ((assq key keystrokes)
6248         (let ((obuf (current-buffer)))
6249           (switch-to-buffer gnus-group-buffer)
6250           (when group
6251             (gnus-group-jump-to-group group))
6252           (eval (cadr (assq key keystrokes)))
6253           (setq group (gnus-group-group-name))
6254           (switch-to-buffer obuf))
6255         (setq ended nil))
6256        ((equal key cmd)
6257         (if (or (not group)
6258                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6259             (gnus-summary-exit)
6260           (gnus-summary-next-group nil group backward)))
6261        (t
6262         (push (cdr keve) unread-command-events))))))
6263
6264 (defun gnus-summary-next-unread-article ()
6265   "Select unread article after current one."
6266   (interactive)
6267   (gnus-summary-next-article
6268    (or (not (eq gnus-summary-goto-unread 'never))
6269        (gnus-summary-last-article-p (gnus-summary-article-number)))
6270    (and gnus-auto-select-same
6271         (gnus-summary-article-subject))))
6272
6273 (defun gnus-summary-prev-article (&optional unread subject)
6274   "Select the article after the current one.
6275 If UNREAD is non-nil, only unread articles are selected."
6276   (interactive "P")
6277   (gnus-summary-next-article unread subject t))
6278
6279 (defun gnus-summary-prev-unread-article ()
6280   "Select unread article before current one."
6281   (interactive)
6282   (gnus-summary-prev-article
6283    (or (not (eq gnus-summary-goto-unread 'never))
6284        (gnus-summary-first-article-p (gnus-summary-article-number)))
6285    (and gnus-auto-select-same
6286         (gnus-summary-article-subject))))
6287
6288 (defun gnus-summary-next-page (&optional lines circular)
6289   "Show next page of the selected article.
6290 If at the end of the current article, select the next article.
6291 LINES says how many lines should be scrolled up.
6292
6293 If CIRCULAR is non-nil, go to the start of the article instead of
6294 selecting the next article when reaching the end of the current
6295 article."
6296   (interactive "P")
6297   (setq gnus-summary-buffer (current-buffer))
6298   (gnus-set-global-variables)
6299   (let ((article (gnus-summary-article-number))
6300         (article-window (get-buffer-window gnus-article-buffer t))
6301         endp)
6302     ;; If the buffer is empty, we have no article.
6303     (unless article
6304       (error "No article to select"))
6305     (gnus-configure-windows 'article)
6306     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6307         (if (and (eq gnus-summary-goto-unread 'never)
6308                  (not (gnus-summary-last-article-p article)))
6309             (gnus-summary-next-article)
6310           (gnus-summary-next-unread-article))
6311       (if (or (null gnus-current-article)
6312               (null gnus-article-current)
6313               (/= article (cdr gnus-article-current))
6314               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6315           ;; Selected subject is different from current article's.
6316           (gnus-summary-display-article article)
6317         (when article-window
6318           (gnus-eval-in-buffer-window gnus-article-buffer
6319             (setq endp (gnus-article-next-page lines)))
6320           (when endp
6321             (cond (circular
6322                    (gnus-summary-beginning-of-article))
6323                   (lines
6324                    (gnus-message 3 "End of message"))
6325                   ((null lines)
6326                    (if (and (eq gnus-summary-goto-unread 'never)
6327                             (not (gnus-summary-last-article-p article)))
6328                        (gnus-summary-next-article)
6329                      (gnus-summary-next-unread-article))))))))
6330     (gnus-summary-recenter)
6331     (gnus-summary-position-point)))
6332
6333 (defun gnus-summary-prev-page (&optional lines move)
6334   "Show previous page of selected article.
6335 Argument LINES specifies lines to be scrolled down.
6336 If MOVE, move to the previous unread article if point is at
6337 the beginning of the buffer."
6338   (interactive "P")
6339   (let ((article (gnus-summary-article-number))
6340         (article-window (get-buffer-window gnus-article-buffer t))
6341         endp)
6342     (gnus-configure-windows 'article)
6343     (if (or (null gnus-current-article)
6344             (null gnus-article-current)
6345             (/= article (cdr gnus-article-current))
6346             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6347         ;; Selected subject is different from current article's.
6348         (gnus-summary-display-article article)
6349       (gnus-summary-recenter)
6350       (when article-window
6351         (gnus-eval-in-buffer-window gnus-article-buffer
6352           (setq endp (gnus-article-prev-page lines)))
6353         (when (and move endp)
6354           (cond (lines
6355                  (gnus-message 3 "Beginning of message"))
6356                 ((null lines)
6357                  (if (and (eq gnus-summary-goto-unread 'never)
6358                           (not (gnus-summary-first-article-p article)))
6359                      (gnus-summary-prev-article)
6360                    (gnus-summary-prev-unread-article))))))))
6361   (gnus-summary-position-point))
6362
6363 (defun gnus-summary-prev-page-or-article (&optional lines)
6364   "Show previous page of selected article.
6365 Argument LINES specifies lines to be scrolled down.
6366 If at the beginning of the article, go to the next article."
6367   (interactive "P")
6368   (gnus-summary-prev-page lines t))
6369
6370 (defun gnus-summary-scroll-up (lines)
6371   "Scroll up (or down) one line current article.
6372 Argument LINES specifies lines to be scrolled up (or down if negative)."
6373   (interactive "p")
6374   (gnus-configure-windows 'article)
6375   (gnus-summary-show-thread)
6376   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6377     (gnus-eval-in-buffer-window gnus-article-buffer
6378       (cond ((> lines 0)
6379              (when (gnus-article-next-page lines)
6380                (gnus-message 3 "End of message")))
6381             ((< lines 0)
6382              (gnus-article-prev-page (- lines))))))
6383   (gnus-summary-recenter)
6384   (gnus-summary-position-point))
6385
6386 (defun gnus-summary-scroll-down (lines)
6387   "Scroll down (or up) one line current article.
6388 Argument LINES specifies lines to be scrolled down (or up if negative)."
6389   (interactive "p")
6390   (gnus-summary-scroll-up (- lines)))
6391
6392 (defun gnus-summary-next-same-subject ()
6393   "Select next article which has the same subject as current one."
6394   (interactive)
6395   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6396
6397 (defun gnus-summary-prev-same-subject ()
6398   "Select previous article which has the same subject as current one."
6399   (interactive)
6400   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6401
6402 (defun gnus-summary-next-unread-same-subject ()
6403   "Select next unread article which has the same subject as current one."
6404   (interactive)
6405   (gnus-summary-next-article t (gnus-summary-article-subject)))
6406
6407 (defun gnus-summary-prev-unread-same-subject ()
6408   "Select previous unread article which has the same subject as current one."
6409   (interactive)
6410   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6411
6412 (defun gnus-summary-first-unread-article ()
6413   "Select the first unread article.
6414 Return nil if there are no unread articles."
6415   (interactive)
6416   (prog1
6417       (when (gnus-summary-first-subject t)
6418         (gnus-summary-show-thread)
6419         (gnus-summary-first-subject t)
6420         (gnus-summary-display-article (gnus-summary-article-number)))
6421     (gnus-summary-position-point)))
6422
6423 (defun gnus-summary-first-unread-subject ()
6424   "Place the point on the subject line of the first unread article.
6425 Return nil if there are no unread articles."
6426   (interactive)
6427   (prog1
6428       (when (gnus-summary-first-subject t)
6429         (gnus-summary-show-thread)
6430         (gnus-summary-first-subject t))
6431     (gnus-summary-position-point)))
6432
6433 (defun gnus-summary-first-article ()
6434   "Select the first article.
6435 Return nil if there are no articles."
6436   (interactive)
6437   (prog1
6438       (when (gnus-summary-first-subject)
6439         (gnus-summary-show-thread)
6440         (gnus-summary-first-subject)
6441         (gnus-summary-display-article (gnus-summary-article-number)))
6442     (gnus-summary-position-point)))
6443
6444 (defun gnus-summary-best-unread-article ()
6445   "Select the unread article with the highest score."
6446   (interactive)
6447   (let ((best -1000000)
6448         (data gnus-newsgroup-data)
6449         article score)
6450     (while data
6451       (and (gnus-data-unread-p (car data))
6452            (> (setq score
6453                     (gnus-summary-article-score (gnus-data-number (car data))))
6454               best)
6455            (setq best score
6456                  article (gnus-data-number (car data))))
6457       (setq data (cdr data)))
6458     (prog1
6459         (if article
6460             (gnus-summary-goto-article article)
6461           (error "No unread articles"))
6462       (gnus-summary-position-point))))
6463
6464 (defun gnus-summary-last-subject ()
6465   "Go to the last displayed subject line in the group."
6466   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6467     (when article
6468       (gnus-summary-goto-subject article))))
6469
6470 (defun gnus-summary-goto-article (article &optional all-headers force)
6471   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6472 If ALL-HEADERS is non-nil, no header lines are hidden.
6473 If FORCE, go to the article even if it isn't displayed.  If FORCE
6474 is a number, it is the line the article is to be displayed on."
6475   (interactive
6476    (list
6477     (completing-read
6478      "Article number or Message-ID: "
6479      (mapcar (lambda (number) (list (int-to-string number)))
6480              gnus-newsgroup-limit))
6481     current-prefix-arg
6482     t))
6483   (prog1
6484       (if (and (stringp article)
6485                (string-match "@" article))
6486           (gnus-summary-refer-article article)
6487         (when (stringp article)
6488           (setq article (string-to-number article)))
6489         (if (gnus-summary-goto-subject article force)
6490             (gnus-summary-display-article article all-headers)
6491           (gnus-message 4 "Couldn't go to article %s" article) nil))
6492     (gnus-summary-position-point)))
6493
6494 (defun gnus-summary-goto-last-article ()
6495   "Go to the previously read article."
6496   (interactive)
6497   (prog1
6498       (when gnus-last-article
6499         (gnus-summary-goto-article gnus-last-article nil t))
6500     (gnus-summary-position-point)))
6501
6502 (defun gnus-summary-pop-article (number)
6503   "Pop one article off the history and go to the previous.
6504 NUMBER articles will be popped off."
6505   (interactive "p")
6506   (let (to)
6507     (setq gnus-newsgroup-history
6508           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6509     (if to
6510         (gnus-summary-goto-article (car to) nil t)
6511       (error "Article history empty")))
6512   (gnus-summary-position-point))
6513
6514 ;; Summary commands and functions for limiting the summary buffer.
6515
6516 (defun gnus-summary-limit-to-articles (n)
6517   "Limit the summary buffer to the next N articles.
6518 If not given a prefix, use the process marked articles instead."
6519   (interactive "P")
6520   (prog1
6521       (let ((articles (gnus-summary-work-articles n)))
6522         (setq gnus-newsgroup-processable nil)
6523         (gnus-summary-limit articles))
6524     (gnus-summary-position-point)))
6525
6526 (defun gnus-summary-pop-limit (&optional total)
6527   "Restore the previous limit.
6528 If given a prefix, remove all limits."
6529   (interactive "P")
6530   (when total
6531     (setq gnus-newsgroup-limits
6532           (list (mapcar (lambda (h) (mail-header-number h))
6533                         gnus-newsgroup-headers))))
6534   (unless gnus-newsgroup-limits
6535     (error "No limit to pop"))
6536   (prog1
6537       (gnus-summary-limit nil 'pop)
6538     (gnus-summary-position-point)))
6539
6540 (defun gnus-summary-limit-to-subject (subject &optional header)
6541   "Limit the summary buffer to articles that have subjects that match a regexp."
6542   (interactive "sLimit to subject (regexp): ")
6543   (unless header
6544     (setq header "subject"))
6545   (when (not (equal "" subject))
6546     (prog1
6547         (let ((articles (gnus-summary-find-matching
6548                          (or header "subject") subject 'all)))
6549           (unless articles
6550             (error "Found no matches for \"%s\"" subject))
6551           (gnus-summary-limit articles))
6552       (gnus-summary-position-point))))
6553
6554 (defun gnus-summary-limit-to-author (from)
6555   "Limit the summary buffer to articles that have authors that match a regexp."
6556   (interactive "sLimit to author (regexp): ")
6557   (gnus-summary-limit-to-subject from "from"))
6558
6559 (defun gnus-summary-limit-to-age (age &optional younger-p)
6560   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6561 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6562 articles that are younger than AGE days."
6563   (interactive
6564    (let ((younger current-prefix-arg)
6565          (days-got nil)
6566          days)
6567      (while (not days-got)
6568        (setq days (if younger
6569                       (read-string "Limit to articles within (in days): ")
6570                     (read-string "Limit to articles older than (in days): ")))
6571        (when (> (length days) 0)
6572          (setq days (read days)))
6573        (if (numberp days)
6574            (setq days-got t)
6575          (message "Please enter a number.")
6576          (sleep-for 1)))
6577      (list days younger)))
6578   (prog1
6579       (let ((data gnus-newsgroup-data)
6580             (cutoff (days-to-time age))
6581             articles d date is-younger)
6582         (while (setq d (pop data))
6583           (when (and (vectorp (gnus-data-header d))
6584                      (setq date (mail-header-date (gnus-data-header d))))
6585             (setq is-younger (time-less-p
6586                               (time-since (condition-case ()
6587                                               (date-to-time date)
6588                                             (error '(0 0))))
6589                               cutoff))
6590             (when (if younger-p
6591                       is-younger
6592                     (not is-younger))
6593               (push (gnus-data-number d) articles))))
6594         (gnus-summary-limit (nreverse articles)))
6595     (gnus-summary-position-point)))
6596
6597 (defun gnus-summary-limit-to-extra (header regexp)
6598   "Limit the summary buffer to articles that match an 'extra' header."
6599   (interactive
6600    (let ((header
6601           (intern
6602            (gnus-completing-read
6603             (symbol-name (car gnus-extra-headers))
6604             "Limit extra header:"
6605             (mapcar (lambda (x)
6606                       (cons (symbol-name x) x))
6607                     gnus-extra-headers)
6608             nil
6609             t))))
6610      (list header
6611            (read-string (format "Limit to header %s (regexp): " header)))))
6612   (when (not (equal "" regexp))
6613     (prog1
6614         (let ((articles (gnus-summary-find-matching
6615                          (cons 'extra header) regexp 'all)))
6616           (unless articles
6617             (error "Found no matches for \"%s\"" regexp))
6618           (gnus-summary-limit articles))
6619       (gnus-summary-position-point))))
6620
6621 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6622 (make-obsolete
6623  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6624
6625 (defun gnus-summary-limit-to-unread (&optional all)
6626   "Limit the summary buffer to articles that are not marked as read.
6627 If ALL is non-nil, limit strictly to unread articles."
6628   (interactive "P")
6629   (if all
6630       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6631     (gnus-summary-limit-to-marks
6632      ;; Concat all the marks that say that an article is read and have
6633      ;; those removed.
6634      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6635            gnus-killed-mark gnus-kill-file-mark
6636            gnus-low-score-mark gnus-expirable-mark
6637            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6638            gnus-duplicate-mark gnus-souped-mark)
6639      'reverse)))
6640
6641 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6642 (make-obsolete 'gnus-summary-delete-marked-with
6643                'gnus-summary-limit-exlude-marks)
6644
6645 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6646   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6647 If REVERSE, limit the summary buffer to articles that are marked
6648 with MARKS.  MARKS can either be a string of marks or a list of marks.
6649 Returns how many articles were removed."
6650   (interactive "sMarks: ")
6651   (gnus-summary-limit-to-marks marks t))
6652
6653 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6654   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6655 If REVERSE (the prefix), limit the summary buffer to articles that are
6656 not marked with MARKS.  MARKS can either be a string of marks or a
6657 list of marks.
6658 Returns how many articles were removed."
6659   (interactive "sMarks: \nP")
6660   (prog1
6661       (let ((data gnus-newsgroup-data)
6662             (marks (if (listp marks) marks
6663                      (append marks nil))) ; Transform to list.
6664             articles)
6665         (while data
6666           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6667                   (memq (gnus-data-mark (car data)) marks))
6668             (push (gnus-data-number (car data)) articles))
6669           (setq data (cdr data)))
6670         (gnus-summary-limit articles))
6671     (gnus-summary-position-point)))
6672
6673 (defun gnus-summary-limit-to-score (&optional score)
6674   "Limit to articles with score at or above SCORE."
6675   (interactive "P")
6676   (setq score (if score
6677                   (prefix-numeric-value score)
6678                 (or gnus-summary-default-score 0)))
6679   (let ((data gnus-newsgroup-data)
6680         articles)
6681     (while data
6682       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6683                 score)
6684         (push (gnus-data-number (car data)) articles))
6685       (setq data (cdr data)))
6686     (prog1
6687         (gnus-summary-limit articles)
6688       (gnus-summary-position-point))))
6689
6690 (defun gnus-summary-limit-include-thread (id)
6691   "Display all the hidden articles that in the current thread."
6692   (interactive (list (mail-header-id (gnus-summary-article-header))))
6693   (let ((articles (gnus-articles-in-thread
6694                    (gnus-id-to-thread (gnus-root-id id)))))
6695     (prog1
6696         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6697       (gnus-summary-position-point))))
6698
6699 (defun gnus-summary-limit-include-dormant ()
6700   "Display all the hidden articles that are marked as dormant.
6701 Note that this command only works on a subset of the articles currently
6702 fetched for this group."
6703   (interactive)
6704   (unless gnus-newsgroup-dormant
6705     (error "There are no dormant articles in this group"))
6706   (prog1
6707       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6708     (gnus-summary-position-point)))
6709
6710 (defun gnus-summary-limit-exclude-dormant ()
6711   "Hide all dormant articles."
6712   (interactive)
6713   (prog1
6714       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6715     (gnus-summary-position-point)))
6716
6717 (defun gnus-summary-limit-exclude-childless-dormant ()
6718   "Hide all dormant articles that have no children."
6719   (interactive)
6720   (let ((data (gnus-data-list t))
6721         articles d children)
6722     ;; Find all articles that are either not dormant or have
6723     ;; children.
6724     (while (setq d (pop data))
6725       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6726                 (and (setq children
6727                            (gnus-article-children (gnus-data-number d)))
6728                      (let (found)
6729                        (while children
6730                          (when (memq (car children) articles)
6731                            (setq children nil
6732                                  found t))
6733                          (pop children))
6734                        found)))
6735         (push (gnus-data-number d) articles)))
6736     ;; Do the limiting.
6737     (prog1
6738         (gnus-summary-limit articles)
6739       (gnus-summary-position-point))))
6740
6741 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6742   "Mark all unread excluded articles as read.
6743 If ALL, mark even excluded ticked and dormants as read."
6744   (interactive "P")
6745   (let ((articles (gnus-sorted-complement
6746                    (sort
6747                     (mapcar (lambda (h) (mail-header-number h))
6748                             gnus-newsgroup-headers)
6749                     '<)
6750                    (sort gnus-newsgroup-limit '<)))
6751         article)
6752     (setq gnus-newsgroup-unreads
6753           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6754     (if all
6755         (setq gnus-newsgroup-dormant nil
6756               gnus-newsgroup-marked nil
6757               gnus-newsgroup-reads
6758               (nconc
6759                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6760                gnus-newsgroup-reads))
6761       (while (setq article (pop articles))
6762         (unless (or (memq article gnus-newsgroup-dormant)
6763                     (memq article gnus-newsgroup-marked))
6764           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6765
6766 (defun gnus-summary-limit (articles &optional pop)
6767   (if pop
6768       ;; We pop the previous limit off the stack and use that.
6769       (setq articles (car gnus-newsgroup-limits)
6770             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6771     ;; We use the new limit, so we push the old limit on the stack.
6772     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6773   ;; Set the limit.
6774   (setq gnus-newsgroup-limit articles)
6775   (let ((total (length gnus-newsgroup-data))
6776         (data (gnus-data-find-list (gnus-summary-article-number)))
6777         (gnus-summary-mark-below nil)   ; Inhibit this.
6778         found)
6779     ;; This will do all the work of generating the new summary buffer
6780     ;; according to the new limit.
6781     (gnus-summary-prepare)
6782     ;; Hide any threads, possibly.
6783     (and gnus-show-threads
6784          gnus-thread-hide-subtree
6785          (gnus-summary-hide-all-threads))
6786     ;; Try to return to the article you were at, or one in the
6787     ;; neighborhood.
6788     (when data
6789       ;; We try to find some article after the current one.
6790       (while data
6791         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6792           (setq data nil
6793                 found t))
6794         (setq data (cdr data))))
6795     (unless found
6796       ;; If there is no data, that means that we were after the last
6797       ;; article.  The same goes when we can't find any articles
6798       ;; after the current one.
6799       (goto-char (point-max))
6800       (gnus-summary-find-prev))
6801     (gnus-set-mode-line 'summary)
6802     ;; We return how many articles were removed from the summary
6803     ;; buffer as a result of the new limit.
6804     (- total (length gnus-newsgroup-data))))
6805
6806 (defsubst gnus-invisible-cut-children (threads)
6807   (let ((num 0))
6808     (while threads
6809       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6810         (incf num))
6811       (pop threads))
6812     (< num 2)))
6813
6814 (defsubst gnus-cut-thread (thread)
6815   "Go forwards in the thread until we find an article that we want to display."
6816   (when (or (eq gnus-fetch-old-headers 'some)
6817             (eq gnus-fetch-old-headers 'invisible)
6818             (numberp gnus-fetch-old-headers)
6819             (eq gnus-build-sparse-threads 'some)
6820             (eq gnus-build-sparse-threads 'more))
6821     ;; Deal with old-fetched headers and sparse threads.
6822     (while (and
6823             thread
6824             (or
6825              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6826              (gnus-summary-article-ancient-p
6827               (mail-header-number (car thread))))
6828             (if (or (<= (length (cdr thread)) 1)
6829                     (eq gnus-fetch-old-headers 'invisible))
6830                 (setq gnus-newsgroup-limit
6831                       (delq (mail-header-number (car thread))
6832                             gnus-newsgroup-limit)
6833                       thread (cadr thread))
6834               (when (gnus-invisible-cut-children (cdr thread))
6835                 (let ((th (cdr thread)))
6836                   (while th
6837                     (if (memq (mail-header-number (caar th))
6838                               gnus-newsgroup-limit)
6839                         (setq thread (car th)
6840                               th nil)
6841                       (setq th (cdr th))))))))))
6842   thread)
6843
6844 (defun gnus-cut-threads (threads)
6845   "Cut off all uninteresting articles from the beginning of threads."
6846   (when (or (eq gnus-fetch-old-headers 'some)
6847             (eq gnus-fetch-old-headers 'invisible)
6848             (numberp gnus-fetch-old-headers)
6849             (eq gnus-build-sparse-threads 'some)
6850             (eq gnus-build-sparse-threads 'more))
6851     (let ((th threads))
6852       (while th
6853         (setcar th (gnus-cut-thread (car th)))
6854         (setq th (cdr th)))))
6855   ;; Remove nixed out threads.
6856   (delq nil threads))
6857
6858 (defun gnus-summary-initial-limit (&optional show-if-empty)
6859   "Figure out what the initial limit is supposed to be on group entry.
6860 This entails weeding out unwanted dormants, low-scored articles,
6861 fetch-old-headers verbiage, and so on."
6862   ;; Most groups have nothing to remove.
6863   (if (or gnus-inhibit-limiting
6864           (and (null gnus-newsgroup-dormant)
6865                (not (eq gnus-fetch-old-headers 'some))
6866                (not (numberp gnus-fetch-old-headers))
6867                (not (eq gnus-fetch-old-headers 'invisible))
6868                (null gnus-summary-expunge-below)
6869                (not (eq gnus-build-sparse-threads 'some))
6870                (not (eq gnus-build-sparse-threads 'more))
6871                (null gnus-thread-expunge-below)
6872                (not gnus-use-nocem)))
6873       ()                                ; Do nothing.
6874     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6875     (setq gnus-newsgroup-limit nil)
6876     (mapatoms
6877      (lambda (node)
6878        (unless (car (symbol-value node))
6879          ;; These threads have no parents -- they are roots.
6880          (let ((nodes (cdr (symbol-value node)))
6881                thread)
6882            (while nodes
6883              (if (and gnus-thread-expunge-below
6884                       (< (gnus-thread-total-score (car nodes))
6885                          gnus-thread-expunge-below))
6886                  (gnus-expunge-thread (pop nodes))
6887                (setq thread (pop nodes))
6888                (gnus-summary-limit-children thread))))))
6889      gnus-newsgroup-dependencies)
6890     ;; If this limitation resulted in an empty group, we might
6891     ;; pop the previous limit and use it instead.
6892     (when (and (not gnus-newsgroup-limit)
6893                show-if-empty)
6894       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6895     gnus-newsgroup-limit))
6896
6897 (defun gnus-summary-limit-children (thread)
6898   "Return 1 if this subthread is visible and 0 if it is not."
6899   ;; First we get the number of visible children to this thread.  This
6900   ;; is done by recursing down the thread using this function, so this
6901   ;; will really go down to a leaf article first, before slowly
6902   ;; working its way up towards the root.
6903   (when thread
6904     (let ((children
6905            (if (cdr thread)
6906                (apply '+ (mapcar 'gnus-summary-limit-children
6907                                  (cdr thread)))
6908              0))
6909           (number (mail-header-number (car thread)))
6910           score)
6911       (if (and
6912            (not (memq number gnus-newsgroup-marked))
6913            (or
6914             ;; If this article is dormant and has absolutely no visible
6915             ;; children, then this article isn't visible.
6916             (and (memq number gnus-newsgroup-dormant)
6917                  (zerop children))
6918             ;; If this is "fetch-old-headered" and there is no
6919             ;; visible children, then we don't want this article.
6920             (and (or (eq gnus-fetch-old-headers 'some)
6921                      (numberp gnus-fetch-old-headers))
6922                  (gnus-summary-article-ancient-p number)
6923                  (zerop children))
6924             ;; If this is "fetch-old-headered" and `invisible', then
6925             ;; we don't want this article.
6926             (and (eq gnus-fetch-old-headers 'invisible)
6927                  (gnus-summary-article-ancient-p number))
6928             ;; If this is a sparsely inserted article with no children,
6929             ;; we don't want it.
6930             (and (eq gnus-build-sparse-threads 'some)
6931                  (gnus-summary-article-sparse-p number)
6932                  (zerop children))
6933             ;; If we use expunging, and this article is really
6934             ;; low-scored, then we don't want this article.
6935             (when (and gnus-summary-expunge-below
6936                        (< (setq score
6937                                 (or (cdr (assq number gnus-newsgroup-scored))
6938                                     gnus-summary-default-score))
6939                           gnus-summary-expunge-below))
6940               ;; We increase the expunge-tally here, but that has
6941               ;; nothing to do with the limits, really.
6942               (incf gnus-newsgroup-expunged-tally)
6943               ;; We also mark as read here, if that's wanted.
6944               (when (and gnus-summary-mark-below
6945                          (< score gnus-summary-mark-below))
6946                 (setq gnus-newsgroup-unreads
6947                       (delq number gnus-newsgroup-unreads))
6948                 (if gnus-newsgroup-auto-expire
6949                     (push number gnus-newsgroup-expirable)
6950                   (push (cons number gnus-low-score-mark)
6951                         gnus-newsgroup-reads)))
6952               t)
6953             ;; Check NoCeM things.
6954             (if (and gnus-use-nocem
6955                      (gnus-nocem-unwanted-article-p
6956                       (mail-header-id (car thread))))
6957                 (progn
6958                   (setq gnus-newsgroup-unreads
6959                         (delq number gnus-newsgroup-unreads))
6960                   t))))
6961           ;; Nope, invisible article.
6962           0
6963         ;; Ok, this article is to be visible, so we add it to the limit
6964         ;; and return 1.
6965         (push number gnus-newsgroup-limit)
6966         1))))
6967
6968 (defun gnus-expunge-thread (thread)
6969   "Mark all articles in THREAD as read."
6970   (let* ((number (mail-header-number (car thread))))
6971     (incf gnus-newsgroup-expunged-tally)
6972     ;; We also mark as read here, if that's wanted.
6973     (setq gnus-newsgroup-unreads
6974           (delq number gnus-newsgroup-unreads))
6975     (if gnus-newsgroup-auto-expire
6976         (push number gnus-newsgroup-expirable)
6977       (push (cons number gnus-low-score-mark)
6978             gnus-newsgroup-reads)))
6979   ;; Go recursively through all subthreads.
6980   (mapcar 'gnus-expunge-thread (cdr thread)))
6981
6982 ;; Summary article oriented commands
6983
6984 (defun gnus-summary-refer-parent-article (n)
6985   "Refer parent article N times.
6986 If N is negative, go to ancestor -N instead.
6987 The difference between N and the number of articles fetched is returned."
6988   (interactive "p")
6989   (let ((skip 1)
6990         error header ref)
6991     (when (not (natnump n))
6992       (setq skip (abs n)
6993             n 1))
6994     (while (and (> n 0)
6995                 (not error))
6996       (setq header (gnus-summary-article-header))
6997       (if (and (eq (mail-header-number header)
6998                    (cdr gnus-article-current))
6999                (equal gnus-newsgroup-name
7000                       (car gnus-article-current)))
7001           ;; If we try to find the parent of the currently
7002           ;; displayed article, then we take a look at the actual
7003           ;; References header, since this is slightly more
7004           ;; reliable than the References field we got from the
7005           ;; server.
7006           (save-excursion
7007             (set-buffer gnus-original-article-buffer)
7008             (nnheader-narrow-to-headers)
7009             (unless (setq ref (message-fetch-field "references"))
7010               (setq ref (message-fetch-field "in-reply-to")))
7011             (widen))
7012         (setq ref
7013               ;; It's not the current article, so we take a bet on
7014               ;; the value we got from the server.
7015               (mail-header-references header)))
7016       (if (and ref
7017                (not (equal ref "")))
7018           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7019             (gnus-message 1 "Couldn't find parent"))
7020         (gnus-message 1 "No references in article %d"
7021                       (gnus-summary-article-number))
7022         (setq error t))
7023       (decf n))
7024     (gnus-summary-position-point)
7025     n))
7026
7027 (defun gnus-summary-refer-references ()
7028   "Fetch all articles mentioned in the References header.
7029 Return the number of articles fetched."
7030   (interactive)
7031   (let ((ref (mail-header-references (gnus-summary-article-header)))
7032         (current (gnus-summary-article-number))
7033         (n 0))
7034     (if (or (not ref)
7035             (equal ref ""))
7036         (error "No References in the current article")
7037       ;; For each Message-ID in the References header...
7038       (while (string-match "<[^>]*>" ref)
7039         (incf n)
7040         ;; ... fetch that article.
7041         (gnus-summary-refer-article
7042          (prog1 (match-string 0 ref)
7043            (setq ref (substring ref (match-end 0))))))
7044       (gnus-summary-goto-subject current)
7045       (gnus-summary-position-point)
7046       n)))
7047
7048 (defun gnus-summary-refer-thread (&optional limit)
7049   "Fetch all articles in the current thread.
7050 If LIMIT (the numerical prefix), fetch that many old headers instead
7051 of what's specified by the `gnus-refer-thread-limit' variable."
7052   (interactive "P")
7053   (let ((id (mail-header-id (gnus-summary-article-header)))
7054         (limit (if limit (prefix-numeric-value limit)
7055                  gnus-refer-thread-limit)))
7056     ;; We want to fetch LIMIT *old* headers, but we also have to
7057     ;; re-fetch all the headers in the current buffer, because many of
7058     ;; them may be undisplayed.  So we adjust LIMIT.
7059     (when (numberp limit)
7060       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7061     (unless (eq gnus-fetch-old-headers 'invisible)
7062       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7063       ;; Retrieve the headers and read them in.
7064       (if (eq (gnus-retrieve-headers
7065                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7066               'nov)
7067           (gnus-build-all-threads)
7068         (error "Can't fetch thread from backends that don't support NOV"))
7069       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7070     (gnus-summary-limit-include-thread id)))
7071
7072 (defun gnus-summary-refer-article (message-id)
7073   "Fetch an article specified by MESSAGE-ID."
7074   (interactive "sMessage-ID: ")
7075   (when (and (stringp message-id)
7076              (not (zerop (length message-id))))
7077     ;; Construct the correct Message-ID if necessary.
7078     ;; Suggested by tale@pawl.rpi.edu.
7079     (unless (string-match "^<" message-id)
7080       (setq message-id (concat "<" message-id)))
7081     (unless (string-match ">$" message-id)
7082       (setq message-id (concat message-id ">")))
7083     (let* ((header (gnus-id-to-header message-id))
7084            (sparse (and header
7085                         (gnus-summary-article-sparse-p
7086                          (mail-header-number header))
7087                         (memq (mail-header-number header)
7088                               gnus-newsgroup-limit)))
7089            number)
7090       (cond
7091        ;; If the article is present in the buffer we just go to it.
7092        ((and header
7093              (or (not (gnus-summary-article-sparse-p
7094                        (mail-header-number header)))
7095                  sparse))
7096         (prog1
7097             (gnus-summary-goto-article
7098              (mail-header-number header) nil t)
7099           (when sparse
7100             (gnus-summary-update-article (mail-header-number header)))))
7101        (t
7102         ;; We fetch the article.
7103         (catch 'found
7104           (dolist (gnus-override-method (gnus-refer-article-methods))
7105             (gnus-check-server gnus-override-method)
7106             ;; Fetch the header, and display the article.
7107             (when (setq number (gnus-summary-insert-subject message-id))
7108               (gnus-summary-select-article nil nil nil number)
7109               (throw 'found t)))
7110           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7111
7112 (defun gnus-refer-article-methods ()
7113   "Return a list of referrable methods."
7114   (cond
7115    ;; No method, so we default to current and native.
7116    ((null gnus-refer-article-method)
7117     (list gnus-current-select-method gnus-select-method))
7118    ;; Current.
7119    ((eq 'current gnus-refer-article-method)
7120     (list gnus-current-select-method))
7121    ;; List of select methods.
7122    ((not (and (symbolp (car gnus-refer-article-method))
7123               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7124     (let (out)
7125       (dolist (method gnus-refer-article-method)
7126         (push (if (eq 'current method)
7127                   gnus-current-select-method
7128                 method)
7129               out))
7130       (nreverse out)))
7131    ;; One single select method.
7132    (t
7133     (list gnus-refer-article-method))))
7134
7135 (defun gnus-summary-edit-parameters ()
7136   "Edit the group parameters of the current group."
7137   (interactive)
7138   (gnus-group-edit-group gnus-newsgroup-name 'params))
7139
7140 (defun gnus-summary-customize-parameters ()
7141   "Customize the group parameters of the current group."
7142   (interactive)
7143   (gnus-group-customize gnus-newsgroup-name))
7144
7145 (defun gnus-summary-enter-digest-group (&optional force)
7146   "Enter an nndoc group based on the current article.
7147 If FORCE, force a digest interpretation.  If not, try
7148 to guess what the document format is."
7149   (interactive "P")
7150   (let ((conf gnus-current-window-configuration))
7151     (save-excursion
7152       (gnus-summary-select-article))
7153     (setq gnus-current-window-configuration conf)
7154     (let* ((name (format "%s-%d"
7155                          (gnus-group-prefixed-name
7156                           gnus-newsgroup-name (list 'nndoc ""))
7157                          (save-excursion
7158                            (set-buffer gnus-summary-buffer)
7159                            gnus-current-article)))
7160            (ogroup gnus-newsgroup-name)
7161            (params (append (gnus-info-params (gnus-get-info ogroup))
7162                            (list (cons 'to-group ogroup))
7163                            (list (cons 'save-article-group ogroup))))
7164            (case-fold-search t)
7165            (buf (current-buffer))
7166            dig to-address)
7167       (save-excursion
7168         (set-buffer gnus-original-article-buffer)
7169         ;; Have the digest group inherit the main mail address of
7170         ;; the parent article.
7171         (when (setq to-address (or (message-fetch-field "reply-to")
7172                                    (message-fetch-field "from")))
7173           (setq params (append
7174                         (list (cons 'to-address
7175                                     (funcall gnus-decode-encoded-word-function
7176                                              to-address))))))
7177         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7178         (insert-buffer-substring gnus-original-article-buffer)
7179         ;; Remove lines that may lead nndoc to misinterpret the
7180         ;; document type.
7181         (narrow-to-region
7182          (goto-char (point-min))
7183          (or (search-forward "\n\n" nil t) (point)))
7184         (goto-char (point-min))
7185         (delete-matching-lines "^Path:\\|^From ")
7186         (widen))
7187       (unwind-protect
7188           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7189                     (gnus-newsgroup-ephemeral-ignored-charsets
7190                      gnus-newsgroup-ignored-charsets))
7191                 (gnus-group-read-ephemeral-group
7192                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7193                               (nndoc-article-type
7194                                ,(if force 'mbox 'guess))) t))
7195               ;; Make all postings to this group go to the parent group.
7196               (nconc (gnus-info-params (gnus-get-info name))
7197                      params)
7198             ;; Couldn't select this doc group.
7199             (switch-to-buffer buf)
7200             (gnus-set-global-variables)
7201             (gnus-configure-windows 'summary)
7202             (gnus-message 3 "Article couldn't be entered?"))
7203         (kill-buffer dig)))))
7204
7205 (defun gnus-summary-read-document (n)
7206   "Open a new group based on the current article(s).
7207 This will allow you to read digests and other similar
7208 documents as newsgroups.
7209 Obeys the standard process/prefix convention."
7210   (interactive "P")
7211   (let* ((articles (gnus-summary-work-articles n))
7212          (ogroup gnus-newsgroup-name)
7213          (params (append (gnus-info-params (gnus-get-info ogroup))
7214                          (list (cons 'to-group ogroup))))
7215          article group egroup groups vgroup)
7216     (while (setq article (pop articles))
7217       (setq group (format "%s-%d" gnus-newsgroup-name article))
7218       (gnus-summary-remove-process-mark article)
7219       (when (gnus-summary-display-article article)
7220         (save-excursion
7221           (with-temp-buffer
7222             (insert-buffer-substring gnus-original-article-buffer)
7223             ;; Remove some headers that may lead nndoc to make
7224             ;; the wrong guess.
7225             (message-narrow-to-head)
7226             (goto-char (point-min))
7227             (delete-matching-lines "^\\(Path\\):\\|^From ")
7228             (widen)
7229             (if (setq egroup
7230                       (gnus-group-read-ephemeral-group
7231                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7232                                      (nndoc-article-type guess))
7233                        t nil t))
7234                 (progn
7235                   ;; Make all postings to this group go to the parent group.
7236                   (nconc (gnus-info-params (gnus-get-info egroup))
7237                          params)
7238                   (push egroup groups))
7239               ;; Couldn't select this doc group.
7240               (gnus-error 3 "Article couldn't be entered"))))))
7241     ;; Now we have selected all the documents.
7242     (cond
7243      ((not groups)
7244       (error "None of the articles could be interpreted as documents"))
7245      ((gnus-group-read-ephemeral-group
7246        (setq vgroup (format
7247                      "nnvirtual:%s-%s" gnus-newsgroup-name
7248                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7249        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7250        t
7251        (cons (current-buffer) 'summary)))
7252      (t
7253       (error "Couldn't select virtual nndoc group")))))
7254
7255 (defun gnus-summary-isearch-article (&optional regexp-p)
7256   "Do incremental search forward on the current article.
7257 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7258   (interactive "P")
7259   (let* ((gnus-inhibit-treatment t)
7260          (old (gnus-summary-select-article)))
7261     (gnus-configure-windows 'article)
7262     (gnus-eval-in-buffer-window gnus-article-buffer
7263       (save-restriction
7264         (widen)
7265         (when (eq 'old old)
7266           (gnus-article-show-all-headers))
7267         (goto-char (point-min))
7268         (isearch-forward regexp-p)))))
7269
7270 (defun gnus-summary-search-article-forward (regexp &optional backward)
7271   "Search for an article containing REGEXP forward.
7272 If BACKWARD, search backward instead."
7273   (interactive
7274    (list (read-string
7275           (format "Search article %s (regexp%s): "
7276                   (if current-prefix-arg "backward" "forward")
7277                   (if gnus-last-search-regexp
7278                       (concat ", default " gnus-last-search-regexp)
7279                     "")))
7280          current-prefix-arg))
7281   (if (string-equal regexp "")
7282       (setq regexp (or gnus-last-search-regexp ""))
7283     (setq gnus-last-search-regexp regexp)
7284     (setq gnus-article-before-search gnus-current-article))
7285   ;; Intentionally set gnus-last-article.
7286   (setq gnus-last-article gnus-article-before-search)
7287   (let ((gnus-last-article gnus-last-article))
7288     (if (gnus-summary-search-article regexp backward)
7289         (gnus-summary-show-thread)
7290       (error "Search failed: \"%s\"" regexp))))
7291
7292 (defun gnus-summary-search-article-backward (regexp)
7293   "Search for an article containing REGEXP backward."
7294   (interactive
7295    (list (read-string
7296           (format "Search article backward (regexp%s): "
7297                   (if gnus-last-search-regexp
7298                       (concat ", default " gnus-last-search-regexp)
7299                     "")))))
7300   (gnus-summary-search-article-forward regexp 'backward))
7301
7302 (eval-when-compile
7303   (defmacro gnus-summary-search-article-position-point (regexp backward)
7304     "Dehighlight the last matched text and goto the beginning position."
7305     (` (if (and gnus-summary-search-article-matched-data
7306                 (let ((text (caddr gnus-summary-search-article-matched-data))
7307                       (inhibit-read-only t)
7308                       buffer-read-only)
7309                   (delete-region
7310                    (goto-char (car gnus-summary-search-article-matched-data))
7311                    (cadr gnus-summary-search-article-matched-data))
7312                   (insert text)
7313                   (string-match (, regexp) text)))
7314            (if (, backward) (beginning-of-line) (end-of-line))
7315          (goto-char (if (, backward) (point-max) (point-min))))))
7316
7317   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7318     "Place point where X-Face image is displayed."
7319     (if (featurep 'xemacs)
7320         (` (let ((end (if (search-forward "\n\n" nil t)
7321                           (goto-char (1- (point)))
7322                         (point-min)))
7323                  extent)
7324              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7325              (unless (and (re-search-forward "^From:" end t)
7326                           (setq extent (extent-at (point)))
7327                           (extent-begin-glyph extent))
7328                (goto-char (, opoint)))))
7329       (` (let ((end (if (search-forward "\n\n" nil t)
7330                         (goto-char (1- (point)))
7331                       (point-min)))
7332                (start (or (search-backward "\n\n" nil t) (point-min))))
7333            (goto-char
7334             (or (text-property-any start end 'x-face-image t);; x-face-e21
7335                 (text-property-any start end 'x-face-mule-bitmap-image t)
7336                 (, opoint)))))))
7337
7338   (defmacro gnus-summary-search-article-highlight-matched-text
7339     (backward treated x-face)
7340     "Highlight matched text in the function `gnus-summary-search-article'."
7341     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7342              (end (set-marker (make-marker) (match-end 0)))
7343              (inhibit-read-only t)
7344              buffer-read-only)
7345          (unless treated
7346            (let ((,@
7347                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7348                     (mapcar
7349                      (lambda (item) (setq items (delq item items)))
7350                      '(gnus-treat-buttonize
7351                        gnus-treat-fill-article
7352                        gnus-treat-fill-long-lines
7353                        gnus-treat-emphasize
7354                        gnus-treat-highlight-headers
7355                        gnus-treat-highlight-citation
7356                        gnus-treat-highlight-signature
7357                        gnus-treat-overstrike
7358                        gnus-treat-display-xface
7359                        gnus-treat-buttonize-head
7360                        gnus-treat-decode-article-as-default-mime-charset))
7361                     (static-if (featurep 'xemacs)
7362                         items
7363                       (cons '(x-face-mule-delete-x-face-field
7364                               (quote never))
7365                             items))))
7366                  (gnus-treat-display-xface
7367                   (when (, x-face) gnus-treat-display-xface)))
7368              (gnus-article-prepare-mime-display)))
7369          (goto-char (if (, backward) start end))
7370          (when (, x-face)
7371            (gnus-summary-search-article-highlight-goto-x-face (point)))
7372          (setq gnus-summary-search-article-matched-data
7373                (list start end (buffer-substring start end)))
7374          (unless (eq start end);; matched text has been deleted. :-<
7375            (put-text-property start end 'face
7376                               (or (find-face 'isearch)
7377                                   'secondary-selection))))))
7378   )
7379
7380 (defun gnus-summary-search-article (regexp &optional backward)
7381   "Search for an article containing REGEXP.
7382 Optional argument BACKWARD means do search for backward.
7383 `gnus-select-article-hook' is not called during the search."
7384   ;; We have to require this here to make sure that the following
7385   ;; dynamic binding isn't shadowed by autoloading.
7386   (require 'gnus-async)
7387   (require 'gnus-art)
7388   (let ((gnus-select-article-hook nil)  ;Disable hook.
7389         (gnus-article-display-hook nil)
7390         (gnus-article-prepare-hook nil)
7391         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7392         (gnus-use-article-prefetch nil)
7393         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7394         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7395         (sum (current-buffer))
7396         (found nil)
7397         point treated)
7398     (gnus-save-hidden-threads
7399       (static-if (featurep 'xemacs)
7400           (let ((gnus-inhibit-treatment t))
7401             (setq treated (eq 'old (gnus-summary-select-article)))
7402             (when (and treated
7403                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7404                                  (window-live-p (get-buffer-window
7405                                                  gnus-article-buffer t)))))
7406               (gnus-summary-select-article nil t)
7407               (setq treated nil)))
7408         (let ((gnus-inhibit-treatment t)
7409               (x-face-mule-delete-x-face-field 'never))
7410           (setq treated (eq 'old (gnus-summary-select-article)))
7411           (when (and treated
7412                      (not
7413                       (and (gnus-buffer-live-p gnus-article-buffer)
7414                            (window-live-p (get-buffer-window
7415                                            gnus-article-buffer t))
7416                            (or (not (string-match "^\\^X-Face:" regexp))
7417                                (with-current-buffer gnus-article-buffer
7418                                  gnus-summary-search-article-matched-data)))))
7419             (gnus-summary-select-article nil t)
7420             (setq treated nil))))
7421       (set-buffer gnus-article-buffer)
7422       (widen)
7423       (if treated
7424           (progn
7425             (gnus-article-show-all-headers)
7426             (gnus-summary-search-article-position-point regexp backward))
7427         (goto-char (if backward (point-max) (point-min))))
7428       (while (not found)
7429         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7430         (if (if backward
7431                 (re-search-backward regexp nil t)
7432               (re-search-forward regexp nil t))
7433             ;; We found the regexp.
7434             (progn
7435               (gnus-summary-search-article-highlight-matched-text
7436                backward treated (string-match "^\\^X-Face:" regexp))
7437               (setq found 'found)
7438               (forward-line
7439                (/ (- 2 (window-height
7440                         (get-buffer-window gnus-article-buffer t)))
7441                   2))
7442               (set-window-start
7443                (get-buffer-window (current-buffer))
7444                (point))
7445               (set-buffer sum)
7446               (setq point (point)))
7447           ;; We didn't find it, so we go to the next article.
7448           (set-buffer sum)
7449           (setq found 'not)
7450           (while (eq found 'not)
7451             (if (not (if backward (gnus-summary-find-prev)
7452                        (gnus-summary-find-next)))
7453                 ;; No more articles.
7454                 (setq found t)
7455               ;; Select the next article and adjust point.
7456               (unless (gnus-summary-article-sparse-p
7457                        (gnus-summary-article-number))
7458                 (setq found nil)
7459                 (let ((gnus-inhibit-treatment t))
7460                   (gnus-summary-select-article))
7461                 (setq treated nil)
7462                 (set-buffer gnus-article-buffer)
7463                 (widen)
7464                 (goto-char (if backward (point-max) (point-min))))))))
7465       (gnus-message 7 ""))
7466     ;; Return whether we found the regexp.
7467     (when (eq found 'found)
7468       (goto-char point)
7469       (gnus-summary-show-thread)
7470       (gnus-summary-goto-subject gnus-current-article)
7471       (gnus-summary-position-point)
7472       t)))
7473
7474 (defun gnus-summary-find-matching (header regexp &optional backward unread
7475                                           not-case-fold)
7476   "Return a list of all articles that match REGEXP on HEADER.
7477 The search stars on the current article and goes forwards unless
7478 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7479 If UNREAD is non-nil, only unread articles will
7480 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7481 in the comparisons."
7482   (let ((data (if (eq backward 'all) gnus-newsgroup-data
7483                 (gnus-data-find-list
7484                  (gnus-summary-article-number) (gnus-data-list backward))))
7485         (case-fold-search (not not-case-fold))
7486         articles d func)
7487     (if (consp header)
7488         (if (eq (car header) 'extra)
7489             (setq func
7490                   `(lambda (h)
7491                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7492                          "")))
7493           (error "%s is an invalid header" header))
7494       (unless (fboundp (intern (concat "mail-header-" header)))
7495         (error "%s is not a valid header" header))
7496       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7497     (while data
7498       (setq d (car data))
7499       (and (or (not unread)             ; We want all articles...
7500                (gnus-data-unread-p d))  ; Or just unreads.
7501            (vectorp (gnus-data-header d)) ; It's not a pseudo.
7502            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
7503            (push (gnus-data-number d) articles)) ; Success!
7504       (setq data (cdr data)))
7505     (nreverse articles)))
7506
7507 (defun gnus-summary-execute-command (header regexp command &optional backward)
7508   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7509 If HEADER is an empty string (or nil), the match is done on the entire
7510 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7511   (interactive
7512    (list (let ((completion-ignore-case t))
7513            (completing-read
7514             "Header name: "
7515             (mapcar (lambda (string) (list string))
7516                     '("Number" "Subject" "From" "Lines" "Date"
7517                       "Message-ID" "Xref" "References" "Body"))
7518             nil 'require-match))
7519          (read-string "Regexp: ")
7520          (read-key-sequence "Command: ")
7521          current-prefix-arg))
7522   (when (equal header "Body")
7523     (setq header ""))
7524   ;; Hidden thread subtrees must be searched as well.
7525   (gnus-summary-show-all-threads)
7526   ;; We don't want to change current point nor window configuration.
7527   (save-excursion
7528     (save-window-excursion
7529       (gnus-message 6 "Executing %s..." (key-description command))
7530       ;; We'd like to execute COMMAND interactively so as to give arguments.
7531       (gnus-execute header regexp
7532                     `(call-interactively ',(key-binding command))
7533                     backward)
7534       (gnus-message 6 "Executing %s...done" (key-description command)))))
7535
7536 (defun gnus-summary-beginning-of-article ()
7537   "Scroll the article back to the beginning."
7538   (interactive)
7539   (gnus-summary-select-article)
7540   (gnus-configure-windows 'article)
7541   (gnus-eval-in-buffer-window gnus-article-buffer
7542     (widen)
7543     (goto-char (point-min))
7544     (when gnus-page-broken
7545       (gnus-narrow-to-page))))
7546
7547 (defun gnus-summary-end-of-article ()
7548   "Scroll to the end of the article."
7549   (interactive)
7550   (gnus-summary-select-article)
7551   (gnus-configure-windows 'article)
7552   (gnus-eval-in-buffer-window gnus-article-buffer
7553     (widen)
7554     (goto-char (point-max))
7555     (recenter -3)
7556     (when gnus-page-broken
7557       (gnus-narrow-to-page))))
7558
7559 (defun gnus-summary-print-article (&optional filename n)
7560   "Generate and print a PostScript image of the N next (mail) articles.
7561
7562 If N is negative, print the N previous articles.  If N is nil and articles
7563 have been marked with the process mark, print these instead.
7564
7565 If the optional first argument FILENAME is nil, send the image to the
7566 printer.  If FILENAME is a string, save the PostScript image in a file with
7567 that name.  If FILENAME is a number, prompt the user for the name of the file
7568 to save in."
7569   (interactive (list (ps-print-preprint current-prefix-arg)))
7570   (dolist (article (gnus-summary-work-articles n))
7571     (gnus-summary-select-article nil nil 'pseudo article)
7572     (gnus-eval-in-buffer-window gnus-article-buffer
7573       (let ((buffer (generate-new-buffer " *print*")))
7574         (unwind-protect
7575             (progn
7576               (copy-to-buffer buffer (point-min) (point-max))
7577               (set-buffer buffer)
7578               (gnus-article-delete-invisible-text)
7579               (let ((ps-left-header
7580                      (list
7581                       (concat "("
7582                               (mail-header-subject gnus-current-headers) ")")
7583                       (concat "("
7584                               (mail-header-from gnus-current-headers) ")")))
7585                     (ps-right-header
7586                      (list
7587                       "/pagenumberstring load"
7588                       (concat "("
7589                               (mail-header-date gnus-current-headers) ")"))))
7590                 (gnus-run-hooks 'gnus-ps-print-hook)
7591                 (save-excursion
7592                   (ps-spool-buffer-with-faces))))
7593           (kill-buffer buffer))))
7594     (gnus-summary-remove-process-mark article))
7595   (ps-despool filename))
7596
7597 (defun gnus-summary-show-article (&optional arg)
7598   "Force re-fetching of the current article.
7599 If ARG (the prefix) is a number, show the article with the charset
7600 defined in `gnus-summary-show-article-charset-alist', or the charset
7601 inputed.
7602 If ARG (the prefix) is non-nil and not a number, show the raw article
7603 without any article massaging functions being run."
7604   (interactive "P")
7605   (cond
7606    ((numberp arg)
7607     (let ((gnus-newsgroup-charset
7608            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7609                (read-coding-system "Charset: ")))
7610           (gnus-newsgroup-ignored-charsets 'gnus-all))
7611       (gnus-summary-select-article nil 'force)
7612       (let ((deps gnus-newsgroup-dependencies)
7613             head header)
7614         (save-excursion
7615           (set-buffer gnus-original-article-buffer)
7616           (save-restriction
7617             (message-narrow-to-head)
7618             (setq head (buffer-string)))
7619           (with-temp-buffer
7620             (insert (format "211 %d Article retrieved.\n"
7621                             (cdr gnus-article-current)))
7622             (insert head)
7623             (insert ".\n")
7624             (let ((nntp-server-buffer (current-buffer)))
7625               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7626         (gnus-data-set-header
7627          (gnus-data-find (cdr gnus-article-current))
7628          header)
7629         (gnus-summary-update-article-line
7630          (cdr gnus-article-current) header))))
7631    ((not arg)
7632     ;; Select the article the normal way.
7633     (gnus-summary-select-article nil 'force))
7634    (t
7635     ;; We have to require this here to make sure that the following
7636     ;; dynamic binding isn't shadowed by autoloading.
7637     (require 'gnus-async)
7638     (require 'gnus-art)
7639     ;; Bind the article treatment functions to nil.
7640     (let ((gnus-have-all-headers t)
7641           gnus-article-display-hook
7642           gnus-article-prepare-hook
7643           gnus-article-decode-hook
7644           gnus-break-pages
7645           gnus-show-mime)
7646       (gnus-summary-select-article nil 'force))))
7647   (gnus-summary-goto-subject gnus-current-article)
7648   (gnus-summary-position-point))
7649
7650 (defun gnus-summary-verbose-headers (&optional arg)
7651   "Toggle permanent full header display.
7652 If ARG is a positive number, turn header display on.
7653 If ARG is a negative number, turn header display off."
7654   (interactive "P")
7655   (setq gnus-show-all-headers
7656         (cond ((or (not (numberp arg))
7657                    (zerop arg))
7658                (not gnus-show-all-headers))
7659               ((natnump arg)
7660                t)))
7661   (gnus-summary-show-article))
7662
7663 (defun gnus-summary-toggle-header (&optional arg)
7664   "Show the headers if they are hidden, or hide them if they are shown.
7665 If ARG is a positive number, show the entire header.
7666 If ARG is a negative number, hide the unwanted header lines."
7667   (interactive "P")
7668   (save-excursion
7669     (set-buffer gnus-article-buffer)
7670     (save-restriction
7671       (let* ((buffer-read-only nil)
7672              (inhibit-point-motion-hooks t)
7673              hidden e)
7674         (setq hidden
7675               (if (numberp arg)
7676                   (>= arg 0)
7677                 (save-restriction
7678                   (article-narrow-to-head)
7679                   (gnus-article-hidden-text-p 'headers))))
7680         (goto-char (point-min))
7681         (when (search-forward "\n\n" nil t)
7682           (delete-region (point-min) (1- (point))))
7683         (goto-char (point-min))
7684         (save-excursion
7685           (set-buffer gnus-original-article-buffer)
7686           (goto-char (point-min))
7687           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7688         (insert-buffer-substring gnus-original-article-buffer 1 e)
7689         (save-restriction
7690           (narrow-to-region (point-min) (point))
7691           (article-decode-encoded-words)
7692           (if  hidden
7693               (let ((gnus-treat-hide-headers nil)
7694                     (gnus-treat-hide-boring-headers nil))
7695                 (setq gnus-article-wash-types
7696                       (delq 'headers gnus-article-wash-types))
7697                 (gnus-treat-article 'head))
7698             (gnus-treat-article 'head)))
7699         (gnus-set-mode-line 'article)))))
7700
7701 (defun gnus-summary-show-all-headers ()
7702   "Make all header lines visible."
7703   (interactive)
7704   (gnus-article-show-all-headers))
7705
7706 (defun gnus-summary-toggle-mime (&optional arg)
7707   "Toggle MIME processing.
7708 If ARG is a positive number, turn MIME processing on."
7709   (interactive "P")
7710   (setq gnus-show-mime
7711         (if (null arg)
7712             (not gnus-show-mime)
7713           (> (prefix-numeric-value arg) 0)))
7714   (gnus-summary-select-article t 'force))
7715
7716 (defun gnus-summary-caesar-message (&optional arg)
7717   "Caesar rotate the current article by 13.
7718 The numerical prefix specifies how many places to rotate each letter
7719 forward."
7720   (interactive "P")
7721   (gnus-summary-select-article)
7722   (let ((mail-header-separator ""))
7723     (gnus-eval-in-buffer-window gnus-article-buffer
7724       (save-restriction
7725         (widen)
7726         (let ((start (window-start))
7727               buffer-read-only)
7728           (message-caesar-buffer-body arg)
7729           (set-window-start (get-buffer-window (current-buffer)) start))))))
7730
7731 (defun gnus-summary-stop-page-breaking ()
7732   "Stop page breaking in the current article."
7733   (interactive)
7734   (gnus-summary-select-article)
7735   (gnus-eval-in-buffer-window gnus-article-buffer
7736     (widen)
7737     (when (gnus-visual-p 'page-marker)
7738       (let ((buffer-read-only nil))
7739         (gnus-remove-text-with-property 'gnus-prev)
7740         (gnus-remove-text-with-property 'gnus-next))
7741       (setq gnus-page-broken nil))))
7742
7743 (defun gnus-summary-move-article (&optional n to-newsgroup
7744                                             select-method action)
7745   "Move the current article to a different newsgroup.
7746 If N is a positive number, move the N next articles.
7747 If N is a negative number, move the N previous articles.
7748 If N is nil and any articles have been marked with the process mark,
7749 move those articles instead.
7750 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7751 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7752 re-spool using this method.
7753
7754 For this function to work, both the current newsgroup and the
7755 newsgroup that you want to move to have to support the `request-move'
7756 and `request-accept' functions.
7757
7758 ACTION can be either `move' (the default), `crosspost' or `copy'."
7759   (interactive "P")
7760   (unless action
7761     (setq action 'move))
7762   ;; Disable marking as read.
7763   (let (gnus-mark-article-hook)
7764     (save-window-excursion
7765       (gnus-summary-select-article)))
7766   ;; Check whether the source group supports the required functions.
7767   (cond ((and (eq action 'move)
7768               (not (gnus-check-backend-function
7769                     'request-move-article gnus-newsgroup-name)))
7770          (error "The current group does not support article moving"))
7771         ((and (eq action 'crosspost)
7772               (not (gnus-check-backend-function
7773                     'request-replace-article gnus-newsgroup-name)))
7774          (error "The current group does not support article editing")))
7775   (let ((articles (gnus-summary-work-articles n))
7776         (prefix (if (gnus-check-backend-function
7777                     'request-move-article gnus-newsgroup-name)
7778                     (gnus-group-real-prefix gnus-newsgroup-name)
7779                   ""))
7780         (names '((move "Move" "Moving")
7781                  (copy "Copy" "Copying")
7782                  (crosspost "Crosspost" "Crossposting")))
7783         (copy-buf (save-excursion
7784                     (nnheader-set-temp-buffer " *copy article*")))
7785         (default-marks gnus-article-mark-lists)
7786         (no-expire-marks (delete '(expirable . expire)
7787                                  (copy-sequence gnus-article-mark-lists)))
7788         art-group to-method new-xref article to-groups)
7789     (unless (assq action names)
7790       (error "Unknown action %s" action))
7791     ;; Read the newsgroup name.
7792     (when (and (not to-newsgroup)
7793                (not select-method))
7794       (setq to-newsgroup
7795             (gnus-read-move-group-name
7796              (cadr (assq action names))
7797              (symbol-value (intern (format "gnus-current-%s-group" action)))
7798              articles prefix))
7799       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7800     (setq to-method (or select-method
7801                         (gnus-server-to-method
7802                          (gnus-group-method to-newsgroup))))
7803     ;; Check the method we are to move this article to...
7804     (unless (gnus-check-backend-function
7805              'request-accept-article (car to-method))
7806       (error "%s does not support article copying" (car to-method)))
7807     (unless (gnus-check-server to-method)
7808       (error "Can't open server %s" (car to-method)))
7809     (gnus-message 6 "%s to %s: %s..."
7810                   (caddr (assq action names))
7811                   (or (car select-method) to-newsgroup) articles)
7812     (while articles
7813       (setq article (pop articles))
7814       (setq
7815        art-group
7816        (cond
7817         ;; Move the article.
7818         ((eq action 'move)
7819          ;; Remove this article from future suppression.
7820          (gnus-dup-unsuppress-article article)
7821          (gnus-request-move-article
7822           article                       ; Article to move
7823           gnus-newsgroup-name           ; From newsgroup
7824           (nth 1 (gnus-find-method-for-group
7825                   gnus-newsgroup-name)) ; Server
7826           (list 'gnus-request-accept-article
7827                 to-newsgroup (list 'quote select-method)
7828                 (not articles) t)       ; Accept form
7829           (not articles)))              ; Only save nov last time
7830         ;; Copy the article.
7831         ((eq action 'copy)
7832          (save-excursion
7833            (set-buffer copy-buf)
7834            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7835              (gnus-request-accept-article
7836               to-newsgroup select-method (not articles) t))))
7837         ;; Crosspost the article.
7838         ((eq action 'crosspost)
7839          (let ((xref (message-tokenize-header
7840                       (mail-header-xref (gnus-summary-article-header article))
7841                       " ")))
7842            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7843                                   ":" article))
7844            (unless xref
7845              (setq xref (list (system-name))))
7846            (setq new-xref
7847                  (concat
7848                   (mapconcat 'identity
7849                              (delete "Xref:" (delete new-xref xref))
7850                              " ")
7851                   " " new-xref))
7852            (save-excursion
7853              (set-buffer copy-buf)
7854              ;; First put the article in the destination group.
7855              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7856              (when (consp (setq art-group
7857                                 (gnus-request-accept-article
7858                                  to-newsgroup select-method (not articles))))
7859                (setq new-xref (concat new-xref " " (car art-group)
7860                                       ":" (cdr art-group)))
7861                ;; Now we have the new Xrefs header, so we insert
7862                ;; it and replace the new article.
7863                (nnheader-replace-header "Xref" new-xref)
7864                (gnus-request-replace-article
7865                 (cdr art-group) to-newsgroup (current-buffer))
7866                art-group))))))
7867       (cond
7868        ((not art-group)
7869         (gnus-message 1 "Couldn't %s article %s: %s"
7870                       (cadr (assq action names)) article
7871                       (nnheader-get-report (car to-method))))
7872        ((eq art-group 'junk)
7873         (when (eq action 'move)
7874           (gnus-summary-mark-article article gnus-canceled-mark)
7875           (gnus-message 4 "Deleted article %s" article)))
7876        (t
7877         (let* ((pto-group (gnus-group-prefixed-name
7878                            (car art-group) to-method))
7879                (entry
7880                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7881                (info (nth 2 entry))
7882                (to-group (gnus-info-group info))
7883                to-marks)
7884           ;; Update the group that has been moved to.
7885           (when (and info
7886                      (memq action '(move copy)))
7887             (unless (member to-group to-groups)
7888               (push to-group to-groups))
7889
7890             (unless (memq article gnus-newsgroup-unreads)
7891               (push 'read to-marks)
7892               (gnus-info-set-read
7893                info (gnus-add-to-range (gnus-info-read info)
7894                                        (list (cdr art-group)))))
7895
7896             ;; See whether the article is to be put in the cache.
7897             (let ((marks (if (gnus-group-auto-expirable-p to-group)
7898                              default-marks
7899                            no-expire-marks))
7900                   (to-article (cdr art-group)))
7901
7902               ;; Enter the article into the cache in the new group,
7903               ;; if that is required.
7904               (when gnus-use-cache
7905                 (gnus-cache-possibly-enter-article
7906                  to-group to-article
7907                  (let ((header (copy-sequence
7908                                 (gnus-summary-article-header article))))
7909                    (mail-header-set-number header to-article)
7910                    header)
7911                  (memq article gnus-newsgroup-marked)
7912                  (memq article gnus-newsgroup-dormant)
7913                  (memq article gnus-newsgroup-unreads)))
7914
7915               (when gnus-preserve-marks
7916                 ;; Copy any marks over to the new group.
7917                 (when (and (equal to-group gnus-newsgroup-name)
7918                            (not (memq article gnus-newsgroup-unreads)))
7919                   ;; Mark this article as read in this group.
7920                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7921                   (setcdr (gnus-active to-group) to-article)
7922                   (setcdr gnus-newsgroup-active to-article))
7923
7924                 (while marks
7925                   (when (memq article (symbol-value
7926                                        (intern (format "gnus-newsgroup-%s"
7927                                                        (caar marks)))))
7928                     (push (cdar marks) to-marks)
7929                     ;; If the other group is the same as this group,
7930                     ;; then we have to add the mark to the list.
7931                     (when (equal to-group gnus-newsgroup-name)
7932                       (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7933                            (cons to-article
7934                                  (symbol-value
7935                                   (intern (format "gnus-newsgroup-%s"
7936                                                   (caar marks)))))))
7937                     ;; Copy the marks to other group.
7938                     (gnus-add-marked-articles
7939                      to-group (cdar marks) (list to-article) info))
7940                   (setq marks (cdr marks)))
7941
7942                 (gnus-request-set-mark to-group (list (list (list to-article)
7943                                                             'set
7944                                                             to-marks))))
7945
7946               (gnus-dribble-enter
7947                (concat "(gnus-group-set-info '"
7948                        (gnus-prin1-to-string (gnus-get-info to-group))
7949                        ")"))))
7950
7951           ;; Update the Xref header in this article to point to
7952           ;; the new crossposted article we have just created.
7953           (when (eq action 'crosspost)
7954             (save-excursion
7955               (set-buffer copy-buf)
7956               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7957               (nnheader-replace-header "Xref" new-xref)
7958               (gnus-request-replace-article
7959                article gnus-newsgroup-name (current-buffer)))))
7960
7961         ;;;!!!Why is this necessary?
7962         (set-buffer gnus-summary-buffer)
7963
7964         (gnus-summary-goto-subject article)
7965         (when (eq action 'move)
7966           (gnus-summary-mark-article article gnus-canceled-mark))))
7967       (gnus-summary-remove-process-mark article))
7968     ;; Re-activate all groups that have been moved to.
7969     (while to-groups
7970       (save-excursion
7971         (set-buffer gnus-group-buffer)
7972         (when (gnus-group-goto-group (car to-groups) t)
7973           (gnus-group-get-new-news-this-group 1 t))
7974         (pop to-groups)))
7975
7976     (gnus-kill-buffer copy-buf)
7977     (gnus-summary-position-point)
7978     (gnus-set-mode-line 'summary)))
7979
7980 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7981   "Move the current article to a different newsgroup.
7982 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7983 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7984 re-spool using this method."
7985   (interactive "P")
7986   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7987
7988 (defun gnus-summary-crosspost-article (&optional n)
7989   "Crosspost the current article to some other group."
7990   (interactive "P")
7991   (gnus-summary-move-article n nil nil 'crosspost))
7992
7993 (defcustom gnus-summary-respool-default-method nil
7994   "Default method for respooling an article.
7995 If nil, use to the current newsgroup method."
7996   :type '(choice (gnus-select-method :value (nnml ""))
7997                  (const nil))
7998   :group 'gnus-summary-mail)
7999
8000 (defun gnus-summary-respool-article (&optional n method)
8001   "Respool the current article.
8002 The article will be squeezed through the mail spooling process again,
8003 which means that it will be put in some mail newsgroup or other
8004 depending on `nnmail-split-methods'.
8005 If N is a positive number, respool the N next articles.
8006 If N is a negative number, respool the N previous articles.
8007 If N is nil and any articles have been marked with the process mark,
8008 respool those articles instead.
8009
8010 Respooling can be done both from mail groups and \"real\" newsgroups.
8011 In the former case, the articles in question will be moved from the
8012 current group into whatever groups they are destined to.  In the
8013 latter case, they will be copied into the relevant groups."
8014   (interactive
8015    (list current-prefix-arg
8016          (let* ((methods (gnus-methods-using 'respool))
8017                 (methname
8018                  (symbol-name (or gnus-summary-respool-default-method
8019                                   (car (gnus-find-method-for-group
8020                                         gnus-newsgroup-name)))))
8021                 (method
8022                  (gnus-completing-read
8023                   methname "What backend do you want to use when respooling?"
8024                   methods nil t nil 'gnus-mail-method-history))
8025                 ms)
8026            (cond
8027             ((zerop (length (setq ms (gnus-servers-using-backend
8028                                       (intern method)))))
8029              (list (intern method) ""))
8030             ((= 1 (length ms))
8031              (car ms))
8032             (t
8033              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8034                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8035                            ms-alist))))))))
8036   (unless method
8037     (error "No method given for respooling"))
8038   (if (assoc (symbol-name
8039               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8040              (gnus-methods-using 'respool))
8041       (gnus-summary-move-article n nil method)
8042     (gnus-summary-copy-article n nil method)))
8043
8044 (defun gnus-summary-import-article (file)
8045   "Import an arbitrary file into a mail newsgroup."
8046   (interactive "fImport file: ")
8047   (let ((group gnus-newsgroup-name)
8048         (now (current-time))
8049         atts lines)
8050     (unless (gnus-check-backend-function 'request-accept-article group)
8051       (error "%s does not support article importing" group))
8052     (or (file-readable-p file)
8053         (not (file-regular-p file))
8054         (error "Can't read %s" file))
8055     (save-excursion
8056       (set-buffer (gnus-get-buffer-create " *import file*"))
8057       (erase-buffer)
8058       (nnheader-insert-file-contents file)
8059       (goto-char (point-min))
8060       (unless (nnheader-article-p)
8061         ;; This doesn't look like an article, so we fudge some headers.
8062         (setq atts (file-attributes file)
8063               lines (count-lines (point-min) (point-max)))
8064         (insert "From: " (read-string "From: ") "\n"
8065                 "Subject: " (read-string "Subject: ") "\n"
8066                 "Date: " (message-make-date (nth 5 atts))
8067                 "\n"
8068                 "Message-ID: " (message-make-message-id) "\n"
8069                 "Lines: " (int-to-string lines) "\n"
8070                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8071       (gnus-request-accept-article group nil t)
8072       (kill-buffer (current-buffer)))))
8073
8074 (defun gnus-summary-article-posted-p ()
8075   "Say whether the current (mail) article is available from news as well.
8076 This will be the case if the article has both been mailed and posted."
8077   (interactive)
8078   (let ((id (mail-header-references (gnus-summary-article-header)))
8079         (gnus-override-method (car (gnus-refer-article-methods))))
8080     (if (gnus-request-head id "")
8081         (gnus-message 2 "The current message was found on %s"
8082                       gnus-override-method)
8083       (gnus-message 2 "The current message couldn't be found on %s"
8084                     gnus-override-method)
8085       nil)))
8086
8087 (defun gnus-summary-expire-articles (&optional now)
8088   "Expire all articles that are marked as expirable in the current group."
8089   (interactive)
8090   (when (gnus-check-backend-function
8091          'request-expire-articles gnus-newsgroup-name)
8092     ;; This backend supports expiry.
8093     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8094            (expirable (if total
8095                           (progn
8096                             ;; We need to update the info for
8097                             ;; this group for `gnus-list-of-read-articles'
8098                             ;; to give us the right answer.
8099                             (gnus-run-hooks 'gnus-exit-group-hook)
8100                             (gnus-summary-update-info)
8101                             (gnus-list-of-read-articles gnus-newsgroup-name))
8102                         (setq gnus-newsgroup-expirable
8103                               (sort gnus-newsgroup-expirable '<))))
8104            (expiry-wait (if now 'immediate
8105                           (gnus-group-find-parameter
8106                            gnus-newsgroup-name 'expiry-wait)))
8107            (nnmail-expiry-target
8108             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8109                 nnmail-expiry-target))
8110            es)
8111       (when expirable
8112         ;; There are expirable articles in this group, so we run them
8113         ;; through the expiry process.
8114         (gnus-message 6 "Expiring articles...")
8115         (unless (gnus-check-group gnus-newsgroup-name)
8116           (error "Can't open server for %s" gnus-newsgroup-name))
8117         ;; The list of articles that weren't expired is returned.
8118         (save-excursion
8119           (if expiry-wait
8120               (let ((nnmail-expiry-wait-function nil)
8121                     (nnmail-expiry-wait expiry-wait))
8122                 (setq es (gnus-request-expire-articles
8123                           expirable gnus-newsgroup-name)))
8124             (setq es (gnus-request-expire-articles
8125                       expirable gnus-newsgroup-name)))
8126           (unless total
8127             (setq gnus-newsgroup-expirable es))
8128           ;; We go through the old list of expirable, and mark all
8129           ;; really expired articles as nonexistent.
8130           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8131             (let ((gnus-use-cache nil))
8132               (while expirable
8133                 (unless (memq (car expirable) es)
8134                   (when (gnus-data-find (car expirable))
8135                     (gnus-summary-mark-article
8136                      (car expirable) gnus-canceled-mark)))
8137                 (setq expirable (cdr expirable))))))
8138         (gnus-message 6 "Expiring articles...done")))))
8139
8140 (defun gnus-summary-expire-articles-now ()
8141   "Expunge all expirable articles in the current group.
8142 This means that *all* articles that are marked as expirable will be
8143 deleted forever, right now."
8144   (interactive)
8145   (or gnus-expert-user
8146       (gnus-yes-or-no-p
8147        "Are you really, really, really sure you want to delete all these messages? ")
8148       (error "Phew!"))
8149   (gnus-summary-expire-articles t))
8150
8151 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8152 (defun gnus-summary-delete-article (&optional n)
8153   "Delete the N next (mail) articles.
8154 This command actually deletes articles.  This is not a marking
8155 command.  The article will disappear forever from your life, never to
8156 return.
8157 If N is negative, delete backwards.
8158 If N is nil and articles have been marked with the process mark,
8159 delete these instead."
8160   (interactive "P")
8161   (unless (gnus-check-backend-function 'request-expire-articles
8162                                        gnus-newsgroup-name)
8163     (error "The current newsgroup does not support article deletion"))
8164   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8165     (error "Couldn't open server"))
8166   ;; Compute the list of articles to delete.
8167   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8168         not-deleted)
8169     (if (and gnus-novice-user
8170              (not (gnus-yes-or-no-p
8171                    (format "Do you really want to delete %s forever? "
8172                            (if (> (length articles) 1)
8173                                (format "these %s articles" (length articles))
8174                              "this article")))))
8175         ()
8176       ;; Delete the articles.
8177       (setq not-deleted (gnus-request-expire-articles
8178                          articles gnus-newsgroup-name 'force))
8179       (while articles
8180         (gnus-summary-remove-process-mark (car articles))
8181         ;; The backend might not have been able to delete the article
8182         ;; after all.
8183         (unless (memq (car articles) not-deleted)
8184           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8185         (setq articles (cdr articles)))
8186       (when not-deleted
8187         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8188     (gnus-summary-position-point)
8189     (gnus-set-mode-line 'summary)
8190     not-deleted))
8191
8192 (defun gnus-summary-edit-article (&optional force)
8193   "Edit the current article.
8194 This will have permanent effect only in mail groups.
8195 If FORCE is non-nil, allow editing of articles even in read-only
8196 groups."
8197   (interactive "P")
8198   (save-excursion
8199     (set-buffer gnus-summary-buffer)
8200     (let ((mail-parse-charset gnus-newsgroup-charset)
8201           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8202       (gnus-set-global-variables)
8203       (when (and (not force)
8204                  (gnus-group-read-only-p))
8205         (error "The current newsgroup does not support article editing"))
8206       (gnus-summary-show-article t)
8207       (gnus-article-edit-article
8208        'ignore
8209        `(lambda (no-highlight)
8210           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8211                 (message-options message-options)
8212                 (message-options-set-recipient)
8213                 (mail-parse-ignored-charsets
8214                  ',gnus-newsgroup-ignored-charsets))
8215             (gnus-summary-edit-article-done
8216              ,(or (mail-header-references gnus-current-headers) "")
8217              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8218
8219 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8220
8221 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8222                                                  no-highlight)
8223   "Make edits to the current article permanent."
8224   (interactive)
8225   (save-excursion
8226     ;; The buffer restriction contains the entire article if it exists.
8227     (when (article-goto-body)
8228       (let ((lines (count-lines (point) (point-max)))
8229             (length (- (point-max) (point)))
8230             (case-fold-search t)
8231             (body (copy-marker (point))))
8232         (goto-char (point-min))
8233         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8234           (delete-region (match-beginning 1) (match-end 1))
8235           (insert (number-to-string length)))
8236         (goto-char (point-min))
8237         (when (re-search-forward
8238                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8239           (delete-region (match-beginning 1) (match-end 1))
8240           (insert (number-to-string length)))
8241         (goto-char (point-min))
8242         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8243           (delete-region (match-beginning 1) (match-end 1))
8244           (insert (number-to-string lines))))))
8245   ;; Replace the article.
8246   (let ((buf (current-buffer)))
8247     (with-temp-buffer
8248       (insert-buffer-substring buf)
8249
8250       (if (and (not read-only)
8251                (not (gnus-request-replace-article
8252                      (cdr gnus-article-current) (car gnus-article-current)
8253                      (current-buffer) t)))
8254           (error "Couldn't replace article")
8255         ;; Update the summary buffer.
8256         (if (and references
8257                  (equal (message-tokenize-header references " ")
8258                         (message-tokenize-header
8259                          (or (message-fetch-field "references") "") " ")))
8260             ;; We only have to update this line.
8261             (save-excursion
8262               (save-restriction
8263                 (message-narrow-to-head)
8264                 (let ((head (buffer-string))
8265                       header)
8266                   (with-temp-buffer
8267                     (insert (format "211 %d Article retrieved.\n"
8268                                     (cdr gnus-article-current)))
8269                     (insert head)
8270                     (insert ".\n")
8271                     (let ((nntp-server-buffer (current-buffer)))
8272                       (setq header (car (gnus-get-newsgroup-headers
8273                                          (save-excursion
8274                                            (set-buffer gnus-summary-buffer)
8275                                            gnus-newsgroup-dependencies)
8276                                          t))))
8277                     (save-excursion
8278                       (set-buffer gnus-summary-buffer)
8279                       (gnus-data-set-header
8280                        (gnus-data-find (cdr gnus-article-current))
8281                        header)
8282                       (gnus-summary-update-article-line
8283                        (cdr gnus-article-current) header))))))
8284           ;; Update threads.
8285           (set-buffer (or buffer gnus-summary-buffer))
8286           (gnus-summary-update-article (cdr gnus-article-current)))
8287         ;; Prettify the article buffer again.
8288         (unless no-highlight
8289           (save-excursion
8290             (set-buffer gnus-article-buffer)
8291             ;;;!!! Fix this -- article should be rehighlighted.
8292             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8293             (set-buffer gnus-original-article-buffer)
8294             (gnus-request-article
8295              (cdr gnus-article-current)
8296              (car gnus-article-current) (current-buffer))))
8297         ;; Prettify the summary buffer line.
8298         (when (gnus-visual-p 'summary-highlight 'highlight)
8299           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8300
8301 (defun gnus-summary-edit-wash (key)
8302   "Perform editing command KEY in the article buffer."
8303   (interactive
8304    (list
8305     (progn
8306       (message "%s" (concat (this-command-keys) "- "))
8307       (read-char))))
8308   (message "")
8309   (gnus-summary-edit-article)
8310   (execute-kbd-macro (concat (this-command-keys) key))
8311   (gnus-article-edit-done))
8312
8313 ;;; Respooling
8314
8315 (defun gnus-summary-respool-query (&optional silent trace)
8316   "Query where the respool algorithm would put this article."
8317   (interactive)
8318   (let (gnus-mark-article-hook)
8319     (gnus-summary-select-article)
8320     (save-excursion
8321       (set-buffer gnus-original-article-buffer)
8322       (save-restriction
8323         (message-narrow-to-head)
8324         (let ((groups (nnmail-article-group 'identity trace)))
8325           (unless silent
8326             (if groups
8327                 (message "This message would go to %s"
8328                          (mapconcat 'car groups ", "))
8329               (message "This message would go to no groups"))
8330             groups))))))
8331
8332 (defun gnus-summary-respool-trace ()
8333   "Trace where the respool algorithm would put this article.
8334 Display a buffer showing all fancy splitting patterns which matched."
8335   (interactive)
8336   (gnus-summary-respool-query nil t))
8337
8338 ;; Summary marking commands.
8339
8340 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8341   "Mark articles which has the same subject as read, and then select the next.
8342 If UNMARK is positive, remove any kind of mark.
8343 If UNMARK is negative, tick articles."
8344   (interactive "P")
8345   (when unmark
8346     (setq unmark (prefix-numeric-value unmark)))
8347   (let ((count
8348          (gnus-summary-mark-same-subject
8349           (gnus-summary-article-subject) unmark)))
8350     ;; Select next unread article.  If auto-select-same mode, should
8351     ;; select the first unread article.
8352     (gnus-summary-next-article t (and gnus-auto-select-same
8353                                       (gnus-summary-article-subject)))
8354     (gnus-message 7 "%d article%s marked as %s"
8355                   count (if (= count 1) " is" "s are")
8356                   (if unmark "unread" "read"))))
8357
8358 (defun gnus-summary-kill-same-subject (&optional unmark)
8359   "Mark articles which has the same subject as read.
8360 If UNMARK is positive, remove any kind of mark.
8361 If UNMARK is negative, tick articles."
8362   (interactive "P")
8363   (when unmark
8364     (setq unmark (prefix-numeric-value unmark)))
8365   (let ((count
8366          (gnus-summary-mark-same-subject
8367           (gnus-summary-article-subject) unmark)))
8368     ;; If marked as read, go to next unread subject.
8369     (when (null unmark)
8370       ;; Go to next unread subject.
8371       (gnus-summary-next-subject 1 t))
8372     (gnus-message 7 "%d articles are marked as %s"
8373                   count (if unmark "unread" "read"))))
8374
8375 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8376   "Mark articles with same SUBJECT as read, and return marked number.
8377 If optional argument UNMARK is positive, remove any kinds of marks.
8378 If optional argument UNMARK is negative, mark articles as unread instead."
8379   (let ((count 1))
8380     (save-excursion
8381       (cond
8382        ((null unmark)                   ; Mark as read.
8383         (while (and
8384                 (progn
8385                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8386                   (gnus-summary-show-thread) t)
8387                 (gnus-summary-find-subject subject))
8388           (setq count (1+ count))))
8389        ((> unmark 0)                    ; Tick.
8390         (while (and
8391                 (progn
8392                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8393                   (gnus-summary-show-thread) t)
8394                 (gnus-summary-find-subject subject))
8395           (setq count (1+ count))))
8396        (t                               ; Mark as unread.
8397         (while (and
8398                 (progn
8399                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8400                   (gnus-summary-show-thread) t)
8401                 (gnus-summary-find-subject subject))
8402           (setq count (1+ count)))))
8403       (gnus-set-mode-line 'summary)
8404       ;; Return the number of marked articles.
8405       count)))
8406
8407 (defun gnus-summary-mark-as-processable (n &optional unmark)
8408   "Set the process mark on the next N articles.
8409 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8410 the process mark instead.  The difference between N and the actual
8411 number of articles marked is returned."
8412   (interactive "P")
8413   (if (and (null n) (gnus-region-active-p))
8414       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8415     (setq n (prefix-numeric-value n))
8416     (let ((backward (< n 0))
8417           (n (abs n)))
8418       (while (and
8419               (> n 0)
8420               (if unmark
8421                 (gnus-summary-remove-process-mark
8422                  (gnus-summary-article-number))
8423                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8424               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8425         (setq n (1- n)))
8426       (when (/= 0 n)
8427         (gnus-message 7 "No more articles"))
8428       (gnus-summary-recenter)
8429       (gnus-summary-position-point)
8430       n)))
8431
8432 (defun gnus-summary-unmark-as-processable (n)
8433   "Remove the process mark from the next N articles.
8434 If N is negative, unmark backward instead.  The difference between N and
8435 the actual number of articles unmarked is returned."
8436   (interactive "P")
8437   (gnus-summary-mark-as-processable n t))
8438
8439 (defun gnus-summary-unmark-all-processable ()
8440   "Remove the process mark from all articles."
8441   (interactive)
8442   (save-excursion
8443     (while gnus-newsgroup-processable
8444       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8445   (gnus-summary-position-point))
8446
8447 (defun gnus-summary-add-mark (article type)
8448   "Mark ARTICLE with a mark of TYPE."
8449   (let ((vtype (car (assq type gnus-article-mark-lists)))
8450         var)
8451     (if (not vtype)
8452         (error "No such mark type: %s" type)
8453       (setq var (intern (format "gnus-newsgroup-%s" type)))
8454       (set var (cons article (symbol-value var)))
8455       (if (memq type '(processable cached replied saved))
8456           (gnus-summary-update-secondary-mark article)
8457         ;;; !!! This is bobus.  We should find out what primary
8458         ;;; !!! mark we want to set.
8459         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8460
8461 (defun gnus-summary-mark-as-expirable (n)
8462   "Mark N articles forward as expirable.
8463 If N is negative, mark backward instead.  The difference between N and
8464 the actual number of articles marked is returned."
8465   (interactive "p")
8466   (gnus-summary-mark-forward n gnus-expirable-mark))
8467
8468 (defun gnus-summary-mark-article-as-replied (article)
8469   "Mark ARTICLE replied and update the summary line."
8470   (push article gnus-newsgroup-replied)
8471   (let ((buffer-read-only nil))
8472     (when (gnus-summary-goto-subject article nil t)
8473       (gnus-summary-update-secondary-mark article))))
8474
8475 (defun gnus-summary-set-bookmark (article)
8476   "Set a bookmark in current article."
8477   (interactive (list (gnus-summary-article-number)))
8478   (when (or (not (get-buffer gnus-article-buffer))
8479             (not gnus-current-article)
8480             (not gnus-article-current)
8481             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8482     (error "No current article selected"))
8483   ;; Remove old bookmark, if one exists.
8484   (let ((old (assq article gnus-newsgroup-bookmarks)))
8485     (when old
8486       (setq gnus-newsgroup-bookmarks
8487             (delq old gnus-newsgroup-bookmarks))))
8488   ;; Set the new bookmark, which is on the form
8489   ;; (article-number . line-number-in-body).
8490   (push
8491    (cons article
8492          (save-excursion
8493            (set-buffer gnus-article-buffer)
8494            (count-lines
8495             (min (point)
8496                  (save-excursion
8497                    (goto-char (point-min))
8498                    (search-forward "\n\n" nil t)
8499                    (point)))
8500             (point))))
8501    gnus-newsgroup-bookmarks)
8502   (gnus-message 6 "A bookmark has been added to the current article."))
8503
8504 (defun gnus-summary-remove-bookmark (article)
8505   "Remove the bookmark from the current article."
8506   (interactive (list (gnus-summary-article-number)))
8507   ;; Remove old bookmark, if one exists.
8508   (let ((old (assq article gnus-newsgroup-bookmarks)))
8509     (if old
8510         (progn
8511           (setq gnus-newsgroup-bookmarks
8512                 (delq old gnus-newsgroup-bookmarks))
8513           (gnus-message 6 "Removed bookmark."))
8514       (gnus-message 6 "No bookmark in current article."))))
8515
8516 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8517 (defun gnus-summary-mark-as-dormant (n)
8518   "Mark N articles forward as dormant.
8519 If N is negative, mark backward instead.  The difference between N and
8520 the actual number of articles marked is returned."
8521   (interactive "p")
8522   (gnus-summary-mark-forward n gnus-dormant-mark))
8523
8524 (defun gnus-summary-set-process-mark (article)
8525   "Set the process mark on ARTICLE and update the summary line."
8526   (setq gnus-newsgroup-processable
8527         (cons article
8528               (delq article gnus-newsgroup-processable)))
8529   (when (gnus-summary-goto-subject article)
8530     (gnus-summary-show-thread)
8531     (gnus-summary-goto-subject article)
8532     (gnus-summary-update-secondary-mark article)))
8533
8534 (defun gnus-summary-remove-process-mark (article)
8535   "Remove the process mark from ARTICLE and update the summary line."
8536   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8537   (when (gnus-summary-goto-subject article)
8538     (gnus-summary-show-thread)
8539     (gnus-summary-goto-subject article)
8540     (gnus-summary-update-secondary-mark article)))
8541
8542 (defun gnus-summary-set-saved-mark (article)
8543   "Set the process mark on ARTICLE and update the summary line."
8544   (push article gnus-newsgroup-saved)
8545   (when (gnus-summary-goto-subject article)
8546     (gnus-summary-update-secondary-mark article)))
8547
8548 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8549   "Mark N articles as read forwards.
8550 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8551 The difference between N and the actual number of articles marked is
8552 returned.
8553 Iff NO-EXPIRE, auto-expiry will be inhibited."
8554   (interactive "p")
8555   (gnus-summary-show-thread)
8556   (let ((backward (< n 0))
8557         (gnus-summary-goto-unread
8558          (and gnus-summary-goto-unread
8559               (not (eq gnus-summary-goto-unread 'never))
8560               (not (memq mark (list gnus-unread-mark
8561                                     gnus-ticked-mark gnus-dormant-mark)))))
8562         (n (abs n))
8563         (mark (or mark gnus-del-mark)))
8564     (while (and (> n 0)
8565                 (gnus-summary-mark-article nil mark no-expire)
8566                 (zerop (gnus-summary-next-subject
8567                         (if backward -1 1)
8568                         (and gnus-summary-goto-unread
8569                              (not (eq gnus-summary-goto-unread 'never)))
8570                         t)))
8571       (setq n (1- n)))
8572     (when (/= 0 n)
8573       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8574     (gnus-summary-recenter)
8575     (gnus-summary-position-point)
8576     (gnus-set-mode-line 'summary)
8577     n))
8578
8579 (defun gnus-summary-mark-article-as-read (mark)
8580   "Mark the current article quickly as read with MARK."
8581   (let ((article (gnus-summary-article-number)))
8582     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8583     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8584     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8585     (push (cons article mark) gnus-newsgroup-reads)
8586     ;; Possibly remove from cache, if that is used.
8587     (when gnus-use-cache
8588       (gnus-cache-enter-remove-article article))
8589     ;; Allow the backend to change the mark.
8590     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8591     ;; Check for auto-expiry.
8592     (when (and gnus-newsgroup-auto-expire
8593                (memq mark gnus-auto-expirable-marks))
8594       (setq mark gnus-expirable-mark)
8595       ;; Let the backend know about the mark change.
8596       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8597       (push article gnus-newsgroup-expirable))
8598     ;; Set the mark in the buffer.
8599     (gnus-summary-update-mark mark 'unread)
8600     t))
8601
8602 (defun gnus-summary-mark-article-as-unread (mark)
8603   "Mark the current article quickly as unread with MARK."
8604   (let* ((article (gnus-summary-article-number))
8605          (old-mark (gnus-summary-article-mark article)))
8606     ;; Allow the backend to change the mark.
8607     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8608     (if (eq mark old-mark)
8609         t
8610       (if (<= article 0)
8611           (progn
8612             (gnus-error 1 "Can't mark negative article numbers")
8613             nil)
8614         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8615         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8616         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8617         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8618         (cond ((= mark gnus-ticked-mark)
8619                (push article gnus-newsgroup-marked))
8620               ((= mark gnus-dormant-mark)
8621                (push article gnus-newsgroup-dormant))
8622               (t
8623                (push article gnus-newsgroup-unreads)))
8624         (gnus-pull article gnus-newsgroup-reads)
8625
8626         ;; See whether the article is to be put in the cache.
8627         (and gnus-use-cache
8628              (vectorp (gnus-summary-article-header article))
8629              (save-excursion
8630                (gnus-cache-possibly-enter-article
8631                 gnus-newsgroup-name article
8632                 (gnus-summary-article-header article)
8633                 (= mark gnus-ticked-mark)
8634                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8635
8636         ;; Fix the mark.
8637         (gnus-summary-update-mark mark 'unread)
8638         t))))
8639
8640 (defun gnus-summary-mark-article (&optional article mark no-expire)
8641   "Mark ARTICLE with MARK.  MARK can be any character.
8642 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8643 `??' (dormant) and `?E' (expirable).
8644 If MARK is nil, then the default character `?r' is used.
8645 If ARTICLE is nil, then the article on the current line will be
8646 marked.
8647 Iff NO-EXPIRE, auto-expiry will be inhibited."
8648   ;; The mark might be a string.
8649   (when (stringp mark)
8650     (setq mark (aref mark 0)))
8651   ;; If no mark is given, then we check auto-expiring.
8652   (when (null mark)
8653     (setq mark gnus-del-mark))
8654   (when (and (not no-expire)
8655              gnus-newsgroup-auto-expire
8656              (memq mark gnus-auto-expirable-marks))
8657     (setq mark gnus-expirable-mark))
8658   (let ((article (or article (gnus-summary-article-number)))
8659         (old-mark (gnus-summary-article-mark article)))
8660     ;; Allow the backend to change the mark.
8661     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8662     (if (eq mark old-mark)
8663         t
8664       (unless article
8665         (error "No article on current line"))
8666       (if (not (if (or (= mark gnus-unread-mark)
8667                        (= mark gnus-ticked-mark)
8668                        (= mark gnus-dormant-mark))
8669                    (gnus-mark-article-as-unread article mark)
8670                  (gnus-mark-article-as-read article mark)))
8671           t
8672         ;; See whether the article is to be put in the cache.
8673         (and gnus-use-cache
8674              (not (= mark gnus-canceled-mark))
8675              (vectorp (gnus-summary-article-header article))
8676              (save-excursion
8677                (gnus-cache-possibly-enter-article
8678                 gnus-newsgroup-name article
8679                 (gnus-summary-article-header article)
8680                 (= mark gnus-ticked-mark)
8681                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8682
8683         (when (gnus-summary-goto-subject article nil t)
8684           (let ((buffer-read-only nil))
8685             (gnus-summary-show-thread)
8686             ;; Fix the mark.
8687             (gnus-summary-update-mark mark 'unread)
8688             t))))))
8689
8690 (defun gnus-summary-update-secondary-mark (article)
8691   "Update the secondary (read, process, cache) mark."
8692   (gnus-summary-update-mark
8693    (cond ((memq article gnus-newsgroup-processable)
8694           gnus-process-mark)
8695          ((memq article gnus-newsgroup-cached)
8696           gnus-cached-mark)
8697          ((memq article gnus-newsgroup-replied)
8698           gnus-replied-mark)
8699          ((memq article gnus-newsgroup-saved)
8700           gnus-saved-mark)
8701          (t gnus-no-mark))
8702    'replied)
8703   (when (gnus-visual-p 'summary-highlight 'highlight)
8704     (gnus-run-hooks 'gnus-summary-update-hook))
8705   t)
8706
8707 (defun gnus-summary-update-mark (mark type)
8708   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8709         (buffer-read-only nil))
8710     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8711     (when forward
8712       (when (looking-at "\r")
8713         (incf forward))
8714       (when (<= (+ forward (point)) (point-max))
8715         ;; Go to the right position on the line.
8716         (goto-char (+ forward (point)))
8717         ;; Replace the old mark with the new mark.
8718         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8719         ;; Optionally update the marks by some user rule.
8720         (when (eq type 'unread)
8721           (gnus-data-set-mark
8722            (gnus-data-find (gnus-summary-article-number)) mark)
8723           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
8724
8725 (defun gnus-mark-article-as-read (article &optional mark)
8726   "Enter ARTICLE in the pertinent lists and remove it from others."
8727   ;; Make the article expirable.
8728   (let ((mark (or mark gnus-del-mark)))
8729     (if (= mark gnus-expirable-mark)
8730         (push article gnus-newsgroup-expirable)
8731       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8732     ;; Remove from unread and marked lists.
8733     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8734     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8735     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8736     (push (cons article mark) gnus-newsgroup-reads)
8737     ;; Possibly remove from cache, if that is used.
8738     (when gnus-use-cache
8739       (gnus-cache-enter-remove-article article))
8740     t))
8741
8742 (defun gnus-mark-article-as-unread (article &optional mark)
8743   "Enter ARTICLE in the pertinent lists and remove it from others."
8744   (let ((mark (or mark gnus-ticked-mark)))
8745     (if (<= article 0)
8746         (progn
8747           (gnus-error 1 "Can't mark negative article numbers")
8748           nil)
8749       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8750             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8751             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8752             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8753
8754       ;; Unsuppress duplicates?
8755       (when gnus-suppress-duplicates
8756         (gnus-dup-unsuppress-article article))
8757
8758       (cond ((= mark gnus-ticked-mark)
8759              (push article gnus-newsgroup-marked))
8760             ((= mark gnus-dormant-mark)
8761              (push article gnus-newsgroup-dormant))
8762             (t
8763              (push article gnus-newsgroup-unreads)))
8764       (gnus-pull article gnus-newsgroup-reads)
8765       t)))
8766
8767 (defalias 'gnus-summary-mark-as-unread-forward
8768   'gnus-summary-tick-article-forward)
8769 (make-obsolete 'gnus-summary-mark-as-unread-forward
8770                'gnus-summary-tick-article-forward)
8771 (defun gnus-summary-tick-article-forward (n)
8772   "Tick N articles forwards.
8773 If N is negative, tick backwards instead.
8774 The difference between N and the number of articles ticked is returned."
8775   (interactive "p")
8776   (gnus-summary-mark-forward n gnus-ticked-mark))
8777
8778 (defalias 'gnus-summary-mark-as-unread-backward
8779   'gnus-summary-tick-article-backward)
8780 (make-obsolete 'gnus-summary-mark-as-unread-backward
8781                'gnus-summary-tick-article-backward)
8782 (defun gnus-summary-tick-article-backward (n)
8783   "Tick N articles backwards.
8784 The difference between N and the number of articles ticked is returned."
8785   (interactive "p")
8786   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8787
8788 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8789 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8790 (defun gnus-summary-tick-article (&optional article clear-mark)
8791   "Mark current article as unread.
8792 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8793 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8794   (interactive)
8795   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8796                                        gnus-ticked-mark)))
8797
8798 (defun gnus-summary-mark-as-read-forward (n)
8799   "Mark N articles as read forwards.
8800 If N is negative, mark backwards instead.
8801 The difference between N and the actual number of articles marked is
8802 returned."
8803   (interactive "p")
8804   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8805
8806 (defun gnus-summary-mark-as-read-backward (n)
8807   "Mark the N articles as read backwards.
8808 The difference between N and the actual number of articles marked is
8809 returned."
8810   (interactive "p")
8811   (gnus-summary-mark-forward
8812    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8813
8814 (defun gnus-summary-mark-as-read (&optional article mark)
8815   "Mark current article as read.
8816 ARTICLE specifies the article to be marked as read.
8817 MARK specifies a string to be inserted at the beginning of the line."
8818   (gnus-summary-mark-article article mark))
8819
8820 (defun gnus-summary-clear-mark-forward (n)
8821   "Clear marks from N articles forward.
8822 If N is negative, clear backward instead.
8823 The difference between N and the number of marks cleared is returned."
8824   (interactive "p")
8825   (gnus-summary-mark-forward n gnus-unread-mark))
8826
8827 (defun gnus-summary-clear-mark-backward (n)
8828   "Clear marks from N articles backward.
8829 The difference between N and the number of marks cleared is returned."
8830   (interactive "p")
8831   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8832
8833 (defun gnus-summary-mark-unread-as-read ()
8834   "Intended to be used by `gnus-summary-mark-article-hook'."
8835   (when (memq gnus-current-article gnus-newsgroup-unreads)
8836     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8837
8838 (defun gnus-summary-mark-read-and-unread-as-read ()
8839   "Intended to be used by `gnus-summary-mark-article-hook'."
8840   (let ((mark (gnus-summary-article-mark)))
8841     (when (or (gnus-unread-mark-p mark)
8842               (gnus-read-mark-p mark))
8843       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8844
8845 (defun gnus-summary-mark-unread-as-ticked ()
8846    "Intended to be used by `gnus-summary-mark-article-hook'."
8847   (when (memq gnus-current-article gnus-newsgroup-unreads)
8848     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
8849
8850 (defun gnus-summary-mark-region-as-read (point mark all)
8851   "Mark all unread articles between point and mark as read.
8852 If given a prefix, mark all articles between point and mark as read,
8853 even ticked and dormant ones."
8854   (interactive "r\nP")
8855   (save-excursion
8856     (let (article)
8857       (goto-char point)
8858       (beginning-of-line)
8859       (while (and
8860               (< (point) mark)
8861               (progn
8862                 (when (or all
8863                           (memq (setq article (gnus-summary-article-number))
8864                                 gnus-newsgroup-unreads))
8865                   (gnus-summary-mark-article article gnus-del-mark))
8866                 t)
8867               (gnus-summary-find-next))))))
8868
8869 (defun gnus-summary-mark-below (score mark)
8870   "Mark articles with score less than SCORE with MARK."
8871   (interactive "P\ncMark: ")
8872   (setq score (if score
8873                   (prefix-numeric-value score)
8874                 (or gnus-summary-default-score 0)))
8875   (save-excursion
8876     (set-buffer gnus-summary-buffer)
8877     (goto-char (point-min))
8878     (while
8879         (progn
8880           (and (< (gnus-summary-article-score) score)
8881                (gnus-summary-mark-article nil mark))
8882           (gnus-summary-find-next)))))
8883
8884 (defun gnus-summary-kill-below (&optional score)
8885   "Mark articles with score below SCORE as read."
8886   (interactive "P")
8887   (gnus-summary-mark-below score gnus-killed-mark))
8888
8889 (defun gnus-summary-clear-above (&optional score)
8890   "Clear all marks from articles with score above SCORE."
8891   (interactive "P")
8892   (gnus-summary-mark-above score gnus-unread-mark))
8893
8894 (defun gnus-summary-tick-above (&optional score)
8895   "Tick all articles with score above SCORE."
8896   (interactive "P")
8897   (gnus-summary-mark-above score gnus-ticked-mark))
8898
8899 (defun gnus-summary-mark-above (score mark)
8900   "Mark articles with score over SCORE with MARK."
8901   (interactive "P\ncMark: ")
8902   (setq score (if score
8903                   (prefix-numeric-value score)
8904                 (or gnus-summary-default-score 0)))
8905   (save-excursion
8906     (set-buffer gnus-summary-buffer)
8907     (goto-char (point-min))
8908     (while (and (progn
8909                   (when (> (gnus-summary-article-score) score)
8910                     (gnus-summary-mark-article nil mark))
8911                   t)
8912                 (gnus-summary-find-next)))))
8913
8914 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8915 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8916 (defun gnus-summary-limit-include-expunged (&optional no-error)
8917   "Display all the hidden articles that were expunged for low scores."
8918   (interactive)
8919   (let ((buffer-read-only nil))
8920     (let ((scored gnus-newsgroup-scored)
8921           headers h)
8922       (while scored
8923         (unless (gnus-number-to-header (caar scored))
8924           (and (setq h (gnus-summary-article-header (caar scored)))
8925                (< (cdar scored) gnus-summary-expunge-below)
8926                (push h headers)))
8927         (setq scored (cdr scored)))
8928       (if (not headers)
8929           (when (not no-error)
8930             (error "No expunged articles hidden"))
8931         (goto-char (point-min))
8932         (gnus-summary-prepare-unthreaded (nreverse headers))
8933         (goto-char (point-min))
8934         (gnus-summary-position-point)
8935         t))))
8936
8937 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8938   "Mark all unread articles in this newsgroup as read.
8939 If prefix argument ALL is non-nil, ticked and dormant articles will
8940 also be marked as read.
8941 If QUIETLY is non-nil, no questions will be asked.
8942 If TO-HERE is non-nil, it should be a point in the buffer.  All
8943 articles before this point will be marked as read.
8944 Note that this function will only catch up the unread article
8945 in the current summary buffer limitation.
8946 The number of articles marked as read is returned."
8947   (interactive "P")
8948   (prog1
8949       (save-excursion
8950         (when (or quietly
8951                   (not gnus-interactive-catchup) ;Without confirmation?
8952                   gnus-expert-user
8953                   (gnus-y-or-n-p
8954                    (if all
8955                        "Mark absolutely all articles as read? "
8956                      "Mark all unread articles as read? ")))
8957           (if (and not-mark
8958                    (not gnus-newsgroup-adaptive)
8959                    (not gnus-newsgroup-auto-expire)
8960                    (not gnus-suppress-duplicates)
8961                    (or (not gnus-use-cache)
8962                        (eq gnus-use-cache 'passive)))
8963               (progn
8964                 (when all
8965                   (setq gnus-newsgroup-marked nil
8966                         gnus-newsgroup-dormant nil))
8967                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8968             ;; We actually mark all articles as canceled, which we
8969             ;; have to do when using auto-expiry or adaptive scoring.
8970             (gnus-summary-show-all-threads)
8971             (when (gnus-summary-first-subject (not all) t)
8972               (while (and
8973                       (if to-here (< (point) to-here) t)
8974                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8975                       (gnus-summary-find-next (not all) nil nil t))))
8976             (gnus-set-mode-line 'summary))
8977           t))
8978     (gnus-summary-position-point)))
8979
8980 (defun gnus-summary-catchup-to-here (&optional all)
8981   "Mark all unticked articles before the current one as read.
8982 If ALL is non-nil, also mark ticked and dormant articles as read."
8983   (interactive "P")
8984   (save-excursion
8985     (gnus-save-hidden-threads
8986       (let ((beg (point)))
8987         ;; We check that there are unread articles.
8988         (when (or all (gnus-summary-find-prev))
8989           (gnus-summary-catchup all t beg)))))
8990   (gnus-summary-position-point))
8991
8992 (defun gnus-summary-catchup-all (&optional quietly)
8993   "Mark all articles in this newsgroup as read."
8994   (interactive "P")
8995   (gnus-summary-catchup t quietly))
8996
8997 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8998   "Mark all unread articles in this group as read, then exit.
8999 If prefix argument ALL is non-nil, all articles are marked as read."
9000   (interactive "P")
9001   (when (gnus-summary-catchup all quietly nil 'fast)
9002     ;; Select next newsgroup or exit.
9003     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9004              (eq gnus-auto-select-next 'quietly))
9005         (gnus-summary-next-group nil)
9006       (gnus-summary-exit))))
9007
9008 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9009   "Mark all articles in this newsgroup as read, and then exit."
9010   (interactive "P")
9011   (gnus-summary-catchup-and-exit t quietly))
9012
9013 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9014   "Mark all articles in this group as read and select the next group.
9015 If given a prefix, mark all articles, unread as well as ticked, as
9016 read."
9017   (interactive "P")
9018   (save-excursion
9019     (gnus-summary-catchup all))
9020   (gnus-summary-next-group))
9021
9022 ;;;
9023 ;;; with article
9024 ;;;
9025
9026 (defmacro gnus-with-article (article &rest forms)
9027   "Select ARTICLE and perform FORMS in the original article buffer.
9028 Then replace the article with the result."
9029   `(progn
9030      ;; We don't want the article to be marked as read.
9031      (let (gnus-mark-article-hook)
9032        (gnus-summary-select-article t t nil ,article))
9033      (set-buffer gnus-original-article-buffer)
9034      ,@forms
9035      (if (not (gnus-check-backend-function
9036                'request-replace-article (car gnus-article-current)))
9037          (gnus-message 5 "Read-only group; not replacing")
9038        (unless (gnus-request-replace-article
9039                 ,article (car gnus-article-current)
9040                 (current-buffer) t)
9041          (error "Couldn't replace article")))
9042      ;; The cache and backlog have to be flushed somewhat.
9043      (when gnus-keep-backlog
9044        (gnus-backlog-remove-article
9045         (car gnus-article-current) (cdr gnus-article-current)))
9046      (when gnus-use-cache
9047        (gnus-cache-update-article
9048         (car gnus-article-current) (cdr gnus-article-current)))))
9049
9050 (put 'gnus-with-article 'lisp-indent-function 1)
9051 (put 'gnus-with-article 'edebug-form-spec '(form body))
9052
9053 ;; Thread-based commands.
9054
9055 (defun gnus-summary-articles-in-thread (&optional article)
9056   "Return a list of all articles in the current thread.
9057 If ARTICLE is non-nil, return all articles in the thread that starts
9058 with that article."
9059   (let* ((article (or article (gnus-summary-article-number)))
9060          (data (gnus-data-find-list article))
9061          (top-level (gnus-data-level (car data)))
9062          (top-subject
9063           (cond ((null gnus-thread-operation-ignore-subject)
9064                  (gnus-simplify-subject-re
9065                   (mail-header-subject (gnus-data-header (car data)))))
9066                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9067                  (gnus-simplify-subject-fuzzy
9068                   (mail-header-subject (gnus-data-header (car data)))))
9069                 (t nil)))
9070          (end-point (save-excursion
9071                       (if (gnus-summary-go-to-next-thread)
9072                           (point) (point-max))))
9073          articles)
9074     (while (and data
9075                 (< (gnus-data-pos (car data)) end-point))
9076       (when (or (not top-subject)
9077                 (string= top-subject
9078                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9079                              (gnus-simplify-subject-fuzzy
9080                               (mail-header-subject
9081                                (gnus-data-header (car data))))
9082                            (gnus-simplify-subject-re
9083                             (mail-header-subject
9084                              (gnus-data-header (car data)))))))
9085         (push (gnus-data-number (car data)) articles))
9086       (unless (and (setq data (cdr data))
9087                    (> (gnus-data-level (car data)) top-level))
9088         (setq data nil)))
9089     ;; Return the list of articles.
9090     (nreverse articles)))
9091
9092 (defun gnus-summary-rethread-current ()
9093   "Rethread the thread the current article is part of."
9094   (interactive)
9095   (let* ((gnus-show-threads t)
9096          (article (gnus-summary-article-number))
9097          (id (mail-header-id (gnus-summary-article-header)))
9098          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9099     (unless id
9100       (error "No article on the current line"))
9101     (gnus-rebuild-thread id)
9102     (gnus-summary-goto-subject article)))
9103
9104 (defun gnus-summary-reparent-thread ()
9105   "Make the current article child of the marked (or previous) article.
9106
9107 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9108 is non-nil or the Subject: of both articles are the same."
9109   (interactive)
9110   (unless (not (gnus-group-read-only-p))
9111     (error "The current newsgroup does not support article editing"))
9112   (unless (<= (length gnus-newsgroup-processable) 1)
9113     (error "No more than one article may be marked"))
9114   (save-window-excursion
9115     (let ((gnus-article-buffer " *reparent*")
9116           (current-article (gnus-summary-article-number))
9117           ;; First grab the marked article, otherwise one line up.
9118           (parent-article (if (not (null gnus-newsgroup-processable))
9119                               (car gnus-newsgroup-processable)
9120                             (save-excursion
9121                               (if (eq (forward-line -1) 0)
9122                                   (gnus-summary-article-number)
9123                                 (error "Beginning of summary buffer"))))))
9124       (unless (not (eq current-article parent-article))
9125         (error "An article may not be self-referential"))
9126       (let ((message-id (mail-header-id
9127                          (gnus-summary-article-header parent-article))))
9128         (unless (and message-id (not (equal message-id "")))
9129           (error "No message-id in desired parent"))
9130         (gnus-with-article current-article
9131           (save-restriction
9132             (goto-char (point-min))
9133             (message-narrow-to-head)
9134             (if (re-search-forward "^References: " nil t)
9135                 (progn
9136                   (re-search-forward "^[^ \t]" nil t)
9137                   (forward-line -1)
9138                   (end-of-line)
9139                   (insert " " message-id))
9140               (insert "References: " message-id "\n"))))
9141         (set-buffer gnus-summary-buffer)
9142         (gnus-summary-unmark-all-processable)
9143         (gnus-summary-update-article current-article)
9144         (gnus-summary-rethread-current)
9145         (gnus-message 3 "Article %d is now the child of article %d"
9146                       current-article parent-article)))))
9147
9148 (defun gnus-summary-toggle-threads (&optional arg)
9149   "Toggle showing conversation threads.
9150 If ARG is positive number, turn showing conversation threads on."
9151   (interactive "P")
9152   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9153     (setq gnus-show-threads
9154           (if (null arg) (not gnus-show-threads)
9155             (> (prefix-numeric-value arg) 0)))
9156     (gnus-summary-prepare)
9157     (gnus-summary-goto-subject current)
9158     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9159     (gnus-summary-position-point)))
9160
9161 (defun gnus-summary-show-all-threads ()
9162   "Show all threads."
9163   (interactive)
9164   (save-excursion
9165     (let ((buffer-read-only nil))
9166       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9167   (gnus-summary-position-point))
9168
9169 (defun gnus-summary-show-thread ()
9170   "Show thread subtrees.
9171 Returns nil if no thread was there to be shown."
9172   (interactive)
9173   (let ((buffer-read-only nil)
9174         (orig (point))
9175         ;; first goto end then to beg, to have point at beg after let
9176         (end (progn (end-of-line) (point)))
9177         (beg (progn (beginning-of-line) (point))))
9178     (prog1
9179         ;; Any hidden lines here?
9180         (search-forward "\r" end t)
9181       (subst-char-in-region beg end ?\^M ?\n t)
9182       (goto-char orig)
9183       (gnus-summary-position-point))))
9184
9185 (defun gnus-summary-hide-all-threads ()
9186   "Hide all thread subtrees."
9187   (interactive)
9188   (save-excursion
9189     (goto-char (point-min))
9190     (gnus-summary-hide-thread)
9191     (while (zerop (gnus-summary-next-thread 1 t))
9192       (gnus-summary-hide-thread)))
9193   (gnus-summary-position-point))
9194
9195 (defun gnus-summary-hide-thread ()
9196   "Hide thread subtrees.
9197 Returns nil if no threads were there to be hidden."
9198   (interactive)
9199   (let ((buffer-read-only nil)
9200         (start (point))
9201         (article (gnus-summary-article-number)))
9202     (goto-char start)
9203     ;; Go forward until either the buffer ends or the subthread
9204     ;; ends.
9205     (when (and (not (eobp))
9206                (or (zerop (gnus-summary-next-thread 1 t))
9207                    (goto-char (point-max))))
9208       (prog1
9209           (if (and (> (point) start)
9210                    (search-backward "\n" start t))
9211               (progn
9212                 (subst-char-in-region start (point) ?\n ?\^M)
9213                 (gnus-summary-goto-subject article))
9214             (goto-char start)
9215             nil)))))
9216
9217 (defun gnus-summary-go-to-next-thread (&optional previous)
9218   "Go to the same level (or less) next thread.
9219 If PREVIOUS is non-nil, go to previous thread instead.
9220 Return the article number moved to, or nil if moving was impossible."
9221   (let ((level (gnus-summary-thread-level))
9222         (way (if previous -1 1))
9223         (beg (point)))
9224     (forward-line way)
9225     (while (and (not (eobp))
9226                 (< level (gnus-summary-thread-level)))
9227       (forward-line way))
9228     (if (eobp)
9229         (progn
9230           (goto-char beg)
9231           nil)
9232       (setq beg (point))
9233       (prog1
9234           (gnus-summary-article-number)
9235         (goto-char beg)))))
9236
9237 (defun gnus-summary-next-thread (n &optional silent)
9238   "Go to the same level next N'th thread.
9239 If N is negative, search backward instead.
9240 Returns the difference between N and the number of skips actually
9241 done.
9242
9243 If SILENT, don't output messages."
9244   (interactive "p")
9245   (let ((backward (< n 0))
9246         (n (abs n)))
9247     (while (and (> n 0)
9248                 (gnus-summary-go-to-next-thread backward))
9249       (decf n))
9250     (unless silent
9251       (gnus-summary-position-point))
9252     (when (and (not silent) (/= 0 n))
9253       (gnus-message 7 "No more threads"))
9254     n))
9255
9256 (defun gnus-summary-prev-thread (n)
9257   "Go to the same level previous N'th thread.
9258 Returns the difference between N and the number of skips actually
9259 done."
9260   (interactive "p")
9261   (gnus-summary-next-thread (- n)))
9262
9263 (defun gnus-summary-go-down-thread ()
9264   "Go down one level in the current thread."
9265   (let ((children (gnus-summary-article-children)))
9266     (when children
9267       (gnus-summary-goto-subject (car children)))))
9268
9269 (defun gnus-summary-go-up-thread ()
9270   "Go up one level in the current thread."
9271   (let ((parent (gnus-summary-article-parent)))
9272     (when parent
9273       (gnus-summary-goto-subject parent))))
9274
9275 (defun gnus-summary-down-thread (n)
9276   "Go down thread N steps.
9277 If N is negative, go up instead.
9278 Returns the difference between N and how many steps down that were
9279 taken."
9280   (interactive "p")
9281   (let ((up (< n 0))
9282         (n (abs n)))
9283     (while (and (> n 0)
9284                 (if up (gnus-summary-go-up-thread)
9285                   (gnus-summary-go-down-thread)))
9286       (setq n (1- n)))
9287     (gnus-summary-position-point)
9288     (when (/= 0 n)
9289       (gnus-message 7 "Can't go further"))
9290     n))
9291
9292 (defun gnus-summary-up-thread (n)
9293   "Go up thread N steps.
9294 If N is negative, go up instead.
9295 Returns the difference between N and how many steps down that were
9296 taken."
9297   (interactive "p")
9298   (gnus-summary-down-thread (- n)))
9299
9300 (defun gnus-summary-top-thread ()
9301   "Go to the top of the thread."
9302   (interactive)
9303   (while (gnus-summary-go-up-thread))
9304   (gnus-summary-article-number))
9305
9306 (defun gnus-summary-kill-thread (&optional unmark)
9307   "Mark articles under current thread as read.
9308 If the prefix argument is positive, remove any kinds of marks.
9309 If the prefix argument is negative, tick articles instead."
9310   (interactive "P")
9311   (when unmark
9312     (setq unmark (prefix-numeric-value unmark)))
9313   (let ((articles (gnus-summary-articles-in-thread)))
9314     (save-excursion
9315       ;; Expand the thread.
9316       (gnus-summary-show-thread)
9317       ;; Mark all the articles.
9318       (while articles
9319         (gnus-summary-goto-subject (car articles))
9320         (cond ((null unmark)
9321                (gnus-summary-mark-article-as-read gnus-killed-mark))
9322               ((> unmark 0)
9323                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9324               (t
9325                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9326         (setq articles (cdr articles))))
9327     ;; Hide killed subtrees.
9328     (and (null unmark)
9329          gnus-thread-hide-killed
9330          (gnus-summary-hide-thread))
9331     ;; If marked as read, go to next unread subject.
9332     (when (null unmark)
9333       ;; Go to next unread subject.
9334       (gnus-summary-next-subject 1 t)))
9335   (gnus-set-mode-line 'summary))
9336
9337 ;; Summary sorting commands
9338
9339 (defun gnus-summary-sort-by-number (&optional reverse)
9340   "Sort the summary buffer by article number.
9341 Argument REVERSE means reverse order."
9342   (interactive "P")
9343   (gnus-summary-sort 'number reverse))
9344
9345 (defun gnus-summary-sort-by-author (&optional reverse)
9346   "Sort the summary buffer by author name alphabetically.
9347 If `case-fold-search' is non-nil, case of letters is ignored.
9348 Argument REVERSE means reverse order."
9349   (interactive "P")
9350   (gnus-summary-sort 'author reverse))
9351
9352 (defun gnus-summary-sort-by-subject (&optional reverse)
9353   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9354 If `case-fold-search' is non-nil, case of letters is ignored.
9355 Argument REVERSE means reverse order."
9356   (interactive "P")
9357   (gnus-summary-sort 'subject reverse))
9358
9359 (defun gnus-summary-sort-by-date (&optional reverse)
9360   "Sort the summary buffer by date.
9361 Argument REVERSE means reverse order."
9362   (interactive "P")
9363   (gnus-summary-sort 'date reverse))
9364
9365 (defun gnus-summary-sort-by-score (&optional reverse)
9366   "Sort the summary buffer by score.
9367 Argument REVERSE means reverse order."
9368   (interactive "P")
9369   (gnus-summary-sort 'score reverse))
9370
9371 (defun gnus-summary-sort-by-lines (&optional reverse)
9372   "Sort the summary buffer by the number of lines.
9373 Argument REVERSE means reverse order."
9374   (interactive "P")
9375   (gnus-summary-sort 'lines reverse))
9376
9377 (defun gnus-summary-sort-by-chars (&optional reverse)
9378   "Sort the summary buffer by article length.
9379 Argument REVERSE means reverse order."
9380   (interactive "P")
9381   (gnus-summary-sort 'chars reverse))
9382
9383 (defun gnus-summary-sort (predicate reverse)
9384   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9385   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9386          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9387          (gnus-thread-sort-functions
9388           (if (not reverse)
9389               thread
9390             `(lambda (t1 t2)
9391                (,thread t2 t1))))
9392          (gnus-sort-gathered-threads-function
9393           gnus-thread-sort-functions)
9394          (gnus-article-sort-functions
9395           (if (not reverse)
9396               article
9397             `(lambda (t1 t2)
9398                (,article t2 t1))))
9399          (buffer-read-only)
9400          (gnus-summary-prepare-hook nil))
9401     ;; We do the sorting by regenerating the threads.
9402     (gnus-summary-prepare)
9403     ;; Hide subthreads if needed.
9404     (when (and gnus-show-threads gnus-thread-hide-subtree)
9405       (gnus-summary-hide-all-threads))))
9406
9407 ;; Summary saving commands.
9408
9409 (defun gnus-summary-save-article (&optional n not-saved)
9410   "Save the current article using the default saver function.
9411 If N is a positive number, save the N next articles.
9412 If N is a negative number, save the N previous articles.
9413 If N is nil and any articles have been marked with the process mark,
9414 save those articles instead.
9415 The variable `gnus-default-article-saver' specifies the saver function."
9416   (interactive "P")
9417   (let* ((articles (gnus-summary-work-articles n))
9418          (save-buffer (save-excursion
9419                         (nnheader-set-temp-buffer " *Gnus Save*")))
9420          (num (length articles))
9421          header file)
9422     (dolist (article articles)
9423       (setq header (gnus-summary-article-header article))
9424       (if (not (vectorp header))
9425           ;; This is a pseudo-article.
9426           (if (assq 'name header)
9427               (gnus-copy-file (cdr (assq 'name header)))
9428             (gnus-message 1 "Article %d is unsaveable" article))
9429         ;; This is a real article.
9430         (save-window-excursion
9431           (gnus-summary-select-article t nil nil article))
9432         (save-excursion
9433           (set-buffer save-buffer)
9434           (erase-buffer)
9435           (insert-buffer-substring gnus-original-article-buffer))
9436         (setq file (gnus-article-save save-buffer file num))
9437         (gnus-summary-remove-process-mark article)
9438         (unless not-saved
9439           (gnus-summary-set-saved-mark article))))
9440     (gnus-kill-buffer save-buffer)
9441     (gnus-summary-position-point)
9442     (gnus-set-mode-line 'summary)
9443     n))
9444
9445 (defun gnus-summary-pipe-output (&optional arg)
9446   "Pipe the current article to a subprocess.
9447 If N is a positive number, pipe the N next articles.
9448 If N is a negative number, pipe the N previous articles.
9449 If N is nil and any articles have been marked with the process mark,
9450 pipe those articles instead."
9451   (interactive "P")
9452   (require 'gnus-art)
9453   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9454     (gnus-summary-save-article arg t))
9455   (gnus-configure-windows 'pipe))
9456
9457 (defun gnus-summary-save-article-mail (&optional arg)
9458   "Append the current article to an mail file.
9459 If N is a positive number, save the N next articles.
9460 If N is a negative number, save the N previous articles.
9461 If N is nil and any articles have been marked with the process mark,
9462 save those articles instead."
9463   (interactive "P")
9464   (require 'gnus-art)
9465   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9466     (gnus-summary-save-article arg)))
9467
9468 (defun gnus-summary-save-article-rmail (&optional arg)
9469   "Append the current article to an rmail file.
9470 If N is a positive number, save the N next articles.
9471 If N is a negative number, save the N previous articles.
9472 If N is nil and any articles have been marked with the process mark,
9473 save those articles instead."
9474   (interactive "P")
9475   (require 'gnus-art)
9476   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9477     (gnus-summary-save-article arg)))
9478
9479 (defun gnus-summary-save-article-file (&optional arg)
9480   "Append the current article to a file.
9481 If N is a positive number, save the N next articles.
9482 If N is a negative number, save the N previous articles.
9483 If N is nil and any articles have been marked with the process mark,
9484 save those articles instead."
9485   (interactive "P")
9486   (require 'gnus-art)
9487   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9488     (gnus-summary-save-article arg)))
9489
9490 (defun gnus-summary-write-article-file (&optional arg)
9491   "Write the current article to a file, deleting the previous file.
9492 If N is a positive number, save the N next articles.
9493 If N is a negative number, save the N previous articles.
9494 If N is nil and any articles have been marked with the process mark,
9495 save those articles instead."
9496   (interactive "P")
9497   (require 'gnus-art)
9498   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9499     (gnus-summary-save-article arg)))
9500
9501 (defun gnus-summary-save-article-body-file (&optional arg)
9502   "Append the current article body to a file.
9503 If N is a positive number, save the N next articles.
9504 If N is a negative number, save the N previous articles.
9505 If N is nil and any articles have been marked with the process mark,
9506 save those articles instead."
9507   (interactive "P")
9508   (require 'gnus-art)
9509   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9510     (gnus-summary-save-article arg)))
9511
9512 (defun gnus-summary-pipe-message (program)
9513   "Pipe the current article through PROGRAM."
9514   (interactive "sProgram: ")
9515   (gnus-summary-select-article)
9516   (let ((mail-header-separator ""))
9517     (gnus-eval-in-buffer-window gnus-article-buffer
9518       (save-restriction
9519         (widen)
9520         (let ((start (window-start))
9521               buffer-read-only)
9522           (message-pipe-buffer-body program)
9523           (set-window-start (get-buffer-window (current-buffer)) start))))))
9524
9525 (defun gnus-get-split-value (methods)
9526   "Return a value based on the split METHODS."
9527   (let (split-name method result match)
9528     (when methods
9529       (save-excursion
9530         (set-buffer gnus-original-article-buffer)
9531         (save-restriction
9532           (nnheader-narrow-to-headers)
9533           (while (and methods (not split-name))
9534             (goto-char (point-min))
9535             (setq method (pop methods))
9536             (setq match (car method))
9537             (when (cond
9538                    ((stringp match)
9539                     ;; Regular expression.
9540                     (ignore-errors
9541                       (re-search-forward match nil t)))
9542                    ((gnus-functionp match)
9543                     ;; Function.
9544                     (save-restriction
9545                       (widen)
9546                       (setq result (funcall match gnus-newsgroup-name))))
9547                    ((consp match)
9548                     ;; Form.
9549                     (save-restriction
9550                       (widen)
9551                       (setq result (eval match)))))
9552               (setq split-name (cdr method))
9553               (cond ((stringp result)
9554                      (push (expand-file-name
9555                             result gnus-article-save-directory)
9556                            split-name))
9557                     ((consp result)
9558                      (setq split-name (append result split-name)))))))))
9559     (nreverse split-name)))
9560
9561 (defun gnus-valid-move-group-p (group)
9562   (and (boundp group)
9563        (symbol-name group)
9564        (symbol-value group)
9565        (gnus-get-function (gnus-find-method-for-group
9566                            (symbol-name group)) 'request-accept-article t)))
9567
9568 (defun gnus-read-move-group-name (prompt default articles prefix)
9569   "Read a group name."
9570   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9571          (minibuffer-confirm-incomplete nil) ; XEmacs
9572          (prom
9573           (format "%s %s to:"
9574                   prompt
9575                   (if (> (length articles) 1)
9576                       (format "these %d articles" (length articles))
9577                     "this article")))
9578          (to-newsgroup
9579           (cond
9580            ((null split-name)
9581             (gnus-completing-read default prom
9582                                   gnus-active-hashtb
9583                                   'gnus-valid-move-group-p
9584                                   nil prefix
9585                                   'gnus-group-history))
9586            ((= 1 (length split-name))
9587             (gnus-completing-read (car split-name) prom
9588                                   gnus-active-hashtb
9589                                   'gnus-valid-move-group-p
9590                                   nil nil
9591                                   'gnus-group-history))
9592            (t
9593             (gnus-completing-read nil prom
9594                                   (mapcar (lambda (el) (list el))
9595                                           (nreverse split-name))
9596                                   nil nil nil
9597                                   'gnus-group-history))))
9598          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
9599     (when to-newsgroup
9600       (if (or (string= to-newsgroup "")
9601               (string= to-newsgroup prefix))
9602           (setq to-newsgroup default))
9603       (unless to-newsgroup
9604         (error "No group name entered"))
9605       (or (gnus-active to-newsgroup)
9606           (gnus-activate-group to-newsgroup nil nil to-method)
9607           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
9608                                      to-newsgroup))
9609               (or (and (gnus-request-create-group to-newsgroup to-method)
9610                        (gnus-activate-group
9611                         to-newsgroup nil nil to-method)
9612                        (gnus-subscribe-group to-newsgroup))
9613                   (error "Couldn't create group %s" to-newsgroup)))
9614           (error "No such group: %s" to-newsgroup)))
9615     to-newsgroup))
9616
9617 (defun gnus-summary-save-parts (type dir n &optional reverse)
9618   "Save parts matching TYPE to DIR.
9619 If REVERSE, save parts that do not match TYPE."
9620   (interactive
9621    (list (read-string "Save parts of type: "
9622                       (or (car gnus-summary-save-parts-type-history)
9623                           gnus-summary-save-parts-default-mime)
9624                       'gnus-summary-save-parts-type-history)
9625          (setq gnus-summary-save-parts-last-directory
9626                (read-file-name "Save to directory: "
9627                                gnus-summary-save-parts-last-directory
9628                                nil t))
9629          current-prefix-arg))
9630   (gnus-summary-iterate n
9631     (let ((gnus-display-mime-function nil)
9632           (gnus-inhibit-treatment t))
9633       (gnus-summary-select-article))
9634     (save-excursion
9635       (set-buffer gnus-article-buffer)
9636       (let ((handles (or gnus-article-mime-handles
9637                          (mm-dissect-buffer) (mm-uu-dissect))))
9638         (when handles
9639           (gnus-summary-save-parts-1 type dir handles reverse)
9640           (unless gnus-article-mime-handles ;; Don't destroy this case.
9641             (mm-destroy-parts handles)))))))
9642
9643 (defun gnus-summary-save-parts-1 (type dir handle reverse)
9644   (if (stringp (car handle))
9645       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9646               (cdr handle))
9647     (when (if reverse
9648               (not (string-match type (mm-handle-media-type handle)))
9649             (string-match type (mm-handle-media-type handle)))
9650       (let ((file (expand-file-name
9651                    (file-name-nondirectory
9652                     (or
9653                      (mail-content-type-get
9654                       (mm-handle-disposition handle) 'filename)
9655                      (concat gnus-newsgroup-name
9656                              "." (number-to-string
9657                                   (cdr gnus-article-current)))))
9658                    dir)))
9659         (unless (file-exists-p file)
9660           (mm-save-part-to-file handle file))))))
9661
9662 ;; Summary extract commands
9663
9664 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
9665   (let ((buffer-read-only nil)
9666         (article (gnus-summary-article-number))
9667         after-article b e)
9668     (unless (gnus-summary-goto-subject article)
9669       (error "No such article: %d" article))
9670     (gnus-summary-position-point)
9671     ;; If all commands are to be bunched up on one line, we collect
9672     ;; them here.
9673     (unless gnus-view-pseudos-separately
9674       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9675             files action)
9676         (while ps
9677           (setq action (cdr (assq 'action (car ps))))
9678           (setq files (list (cdr (assq 'name (car ps)))))
9679           (while (and ps (cdr ps)
9680                       (string= (or action "1")
9681                                (or (cdr (assq 'action (cadr ps))) "2")))
9682             (push (cdr (assq 'name (cadr ps))) files)
9683             (setcdr ps (cddr ps)))
9684           (when files
9685             (when (not (string-match "%s" action))
9686               (push " " files))
9687             (push " " files)
9688             (when (assq 'execute (car ps))
9689               (setcdr (assq 'execute (car ps))
9690                       (funcall (if (string-match "%s" action)
9691                                    'format 'concat)
9692                                action
9693                                (mapconcat
9694                                 (lambda (f)
9695                                   (if (equal f " ")
9696                                       f
9697                                     (gnus-quote-arg-for-sh-or-csh f)))
9698                                 files " ")))))
9699           (setq ps (cdr ps)))))
9700     (if (and gnus-view-pseudos (not not-view))
9701         (while pslist
9702           (when (assq 'execute (car pslist))
9703             (gnus-execute-command (cdr (assq 'execute (car pslist)))
9704                                   (eq gnus-view-pseudos 'not-confirm)))
9705           (setq pslist (cdr pslist)))
9706       (save-excursion
9707         (while pslist
9708           (setq after-article (or (cdr (assq 'article (car pslist)))
9709                                   (gnus-summary-article-number)))
9710           (gnus-summary-goto-subject after-article)
9711           (forward-line 1)
9712           (setq b (point))
9713           (insert "    " (file-name-nondirectory
9714                           (cdr (assq 'name (car pslist))))
9715                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9716           (setq e (point))
9717           (forward-line -1)             ; back to `b'
9718           (gnus-add-text-properties
9719            b (1- e) (list 'gnus-number gnus-reffed-article-number
9720                           gnus-mouse-face-prop gnus-mouse-face))
9721           (gnus-data-enter
9722            after-article gnus-reffed-article-number
9723            gnus-unread-mark b (car pslist) 0 (- e b))
9724           (push gnus-reffed-article-number gnus-newsgroup-unreads)
9725           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9726           (setq pslist (cdr pslist)))))))
9727
9728 (defun gnus-pseudos< (p1 p2)
9729   (let ((c1 (cdr (assq 'action p1)))
9730         (c2 (cdr (assq 'action p2))))
9731     (and c1 c2 (string< c1 c2))))
9732
9733 (defun gnus-request-pseudo-article (props)
9734   (cond ((assq 'execute props)
9735          (gnus-execute-command (cdr (assq 'execute props)))))
9736   (let ((gnus-current-article (gnus-summary-article-number)))
9737     (gnus-run-hooks 'gnus-mark-article-hook)))
9738
9739 (defun gnus-execute-command (command &optional automatic)
9740   (save-excursion
9741     (gnus-article-setup-buffer)
9742     (set-buffer gnus-article-buffer)
9743     (setq buffer-read-only nil)
9744     (let ((command (if automatic command
9745                      (read-string "Command: " (cons command 0)))))
9746       (erase-buffer)
9747       (insert "$ " command "\n\n")
9748       (if gnus-view-pseudo-asynchronously
9749           (start-process "gnus-execute" (current-buffer) shell-file-name
9750                          shell-command-switch command)
9751         (call-process shell-file-name nil t nil
9752                       shell-command-switch command)))))
9753
9754 ;; Summary kill commands.
9755
9756 (defun gnus-summary-edit-global-kill (article)
9757   "Edit the \"global\" kill file."
9758   (interactive (list (gnus-summary-article-number)))
9759   (gnus-group-edit-global-kill article))
9760
9761 (defun gnus-summary-edit-local-kill ()
9762   "Edit a local kill file applied to the current newsgroup."
9763   (interactive)
9764   (setq gnus-current-headers (gnus-summary-article-header))
9765   (gnus-group-edit-local-kill
9766    (gnus-summary-article-number) gnus-newsgroup-name))
9767
9768 ;;; Header reading.
9769
9770 (defun gnus-read-header (id &optional header)
9771   "Read the headers of article ID and enter them into the Gnus system."
9772   (let ((group gnus-newsgroup-name)
9773         (gnus-override-method
9774          (or
9775           gnus-override-method
9776           (and (gnus-news-group-p gnus-newsgroup-name)
9777                (car (gnus-refer-article-methods)))))
9778         where)
9779     ;; First we check to see whether the header in question is already
9780     ;; fetched.
9781     (if (stringp id)
9782         ;; This is a Message-ID.
9783         (setq header (or header (gnus-id-to-header id)))
9784       ;; This is an article number.
9785       (setq header (or header (gnus-summary-article-header id))))
9786     (if (and header
9787              (not (gnus-summary-article-sparse-p (mail-header-number header))))
9788         ;; We have found the header.
9789         header
9790       ;; If this is a sparse article, we have to nix out its
9791       ;; previous entry in the thread hashtb.
9792       (when (and header
9793                  (gnus-summary-article-sparse-p (mail-header-number header)))
9794         (let* ((parent (gnus-parent-id (mail-header-references header)))
9795                (thread (and parent (gnus-id-to-thread parent))))
9796           (when thread
9797             (delq (assq header thread) thread))))
9798       ;; We have to really fetch the header to this article.
9799       (save-excursion
9800         (set-buffer nntp-server-buffer)
9801         (when (setq where (gnus-request-head id group))
9802           (nnheader-fold-continuation-lines)
9803           (goto-char (point-max))
9804           (insert ".\n")
9805           (goto-char (point-min))
9806           (insert "211 ")
9807           (princ (cond
9808                   ((numberp id) id)
9809                   ((cdr where) (cdr where))
9810                   (header (mail-header-number header))
9811                   (t gnus-reffed-article-number))
9812                  (current-buffer))
9813           (insert " Article retrieved.\n"))
9814         (if (or (not where)
9815                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9816             ()                          ; Malformed head.
9817           (unless (gnus-summary-article-sparse-p (mail-header-number header))
9818             (when (and (stringp id)
9819                        (not (string= (gnus-group-real-name group)
9820                                      (car where))))
9821               ;; If we fetched by Message-ID and the article came
9822               ;; from a different group, we fudge some bogus article
9823               ;; numbers for this article.
9824               (mail-header-set-number header gnus-reffed-article-number))
9825             (save-excursion
9826               (set-buffer gnus-summary-buffer)
9827               (decf gnus-reffed-article-number)
9828               (gnus-remove-header (mail-header-number header))
9829               (push header gnus-newsgroup-headers)
9830               (setq gnus-current-headers header)
9831               (push (mail-header-number header) gnus-newsgroup-limit)))
9832           header)))))
9833
9834 (defun gnus-remove-header (number)
9835   "Remove header NUMBER from `gnus-newsgroup-headers'."
9836   (if (and gnus-newsgroup-headers
9837            (= number (mail-header-number (car gnus-newsgroup-headers))))
9838       (pop gnus-newsgroup-headers)
9839     (let ((headers gnus-newsgroup-headers))
9840       (while (and (cdr headers)
9841                   (not (= number (mail-header-number (cadr headers)))))
9842         (pop headers))
9843       (when (cdr headers)
9844         (setcdr headers (cddr headers))))))
9845
9846 ;;;
9847 ;;; summary highlights
9848 ;;;
9849
9850 (defun gnus-highlight-selected-summary ()
9851   "Highlight selected article in summary buffer."
9852   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9853   (when gnus-summary-selected-face
9854     (save-excursion
9855       (let* ((beg (progn (beginning-of-line) (point)))
9856              (end (progn (end-of-line) (point)))
9857              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9858              (from (if (get-text-property beg gnus-mouse-face-prop)
9859                        beg
9860                      (or (next-single-property-change
9861                           beg gnus-mouse-face-prop nil end)
9862                          beg)))
9863              (to
9864               (if (= from end)
9865                   (- from 2)
9866                 (or (next-single-property-change
9867                      from gnus-mouse-face-prop nil end)
9868                     end))))
9869         ;; If no mouse-face prop on line we will have to = from = end,
9870         ;; so we highlight the entire line instead.
9871         (when (= (+ to 2) from)
9872           (setq from beg)
9873           (setq to end))
9874         (if gnus-newsgroup-selected-overlay
9875             ;; Move old overlay.
9876             (gnus-move-overlay
9877              gnus-newsgroup-selected-overlay from to (current-buffer))
9878           ;; Create new overlay.
9879           (gnus-overlay-put
9880            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9881            'face gnus-summary-selected-face))))))
9882
9883 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9884 (defun gnus-summary-highlight-line ()
9885   "Highlight current line according to `gnus-summary-highlight'."
9886   (let* ((list gnus-summary-highlight)
9887          (p (point))
9888          (end (progn (end-of-line) (point)))
9889          ;; now find out where the line starts and leave point there.
9890          (beg (progn (beginning-of-line) (point)))
9891          (article (gnus-summary-article-number))
9892          (score (or (cdr (assq (or article gnus-current-article)
9893                                gnus-newsgroup-scored))
9894                     gnus-summary-default-score 0))
9895          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9896          (inhibit-read-only t))
9897     ;; Eval the cars of the lists until we find a match.
9898     (let ((default gnus-summary-default-score))
9899       (while (and list
9900                   (not (eval (caar list))))
9901         (setq list (cdr list))))
9902     (let ((face (cdar list)))
9903       (unless (eq face (get-text-property beg 'face))
9904         (gnus-put-text-property-excluding-characters-with-faces
9905          beg end 'face
9906          (setq face (if (boundp face) (symbol-value face) face)))
9907         (when gnus-summary-highlight-line-function
9908           (funcall gnus-summary-highlight-line-function article face))))
9909     (goto-char p)))
9910
9911 (defun gnus-update-read-articles (group unread &optional compute)
9912   "Update the list of read articles in GROUP."
9913   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9914          (entry (gnus-gethash group gnus-newsrc-hashtb))
9915          (info (nth 2 entry))
9916          (prev 1)
9917          (unread (sort (copy-sequence unread) '<))
9918          read)
9919     (if (or (not info) (not active))
9920         ;; There is no info on this group if it was, in fact,
9921         ;; killed.  Gnus stores no information on killed groups, so
9922         ;; there's nothing to be done.
9923         ;; One could store the information somewhere temporarily,
9924         ;; perhaps...  Hmmm...
9925         ()
9926       ;; Remove any negative articles numbers.
9927       (while (and unread (< (car unread) 0))
9928         (setq unread (cdr unread)))
9929       ;; Remove any expired article numbers
9930       (while (and unread (< (car unread) (car active)))
9931         (setq unread (cdr unread)))
9932       ;; Compute the ranges of read articles by looking at the list of
9933       ;; unread articles.
9934       (while unread
9935         (when (/= (car unread) prev)
9936           (push (if (= prev (1- (car unread))) prev
9937                   (cons prev (1- (car unread))))
9938                 read))
9939         (setq prev (1+ (car unread)))
9940         (setq unread (cdr unread)))
9941       (when (<= prev (cdr active))
9942         (push (cons prev (cdr active)) read))
9943       (setq read (if (> (length read) 1) (nreverse read) read))
9944       (if compute
9945           read
9946         (save-excursion
9947           (let (setmarkundo)
9948             ;; Propagate the read marks to the backend.
9949             (when (gnus-check-backend-function 'request-set-mark group)
9950               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9951                     (add (gnus-remove-from-range read (gnus-info-read info))))
9952                 (when (or add del)
9953                   (unless (gnus-check-group group)
9954                     (error "Can't open server for %s" group))
9955                   (gnus-request-set-mark
9956                    group (delq nil (list (if add (list add 'add '(read)))
9957                                          (if del (list del 'del '(read))))))
9958                   (setq setmarkundo
9959                         `(gnus-request-set-mark
9960                           ,group
9961                           ',(delq nil (list
9962                                        (if del (list del 'add '(read)))
9963                                        (if add (list add 'del '(read))))))))))
9964             (set-buffer gnus-group-buffer)
9965             (gnus-undo-register
9966               `(progn
9967                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9968                  (gnus-info-set-read ',info ',(gnus-info-read info))
9969                  (gnus-get-unread-articles-in-group ',info
9970                                                     (gnus-active ,group))
9971                  (gnus-group-update-group ,group t)
9972                  ,setmarkundo))))
9973         ;; Enter this list into the group info.
9974         (gnus-info-set-read info read)
9975         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9976         (gnus-get-unread-articles-in-group info (gnus-active group))
9977         t))))
9978
9979 (defun gnus-offer-save-summaries ()
9980   "Offer to save all active summary buffers."
9981   (save-excursion
9982     (let ((buflist (buffer-list))
9983           buffers bufname)
9984       ;; Go through all buffers and find all summaries.
9985       (while buflist
9986         (and (setq bufname (buffer-name (car buflist)))
9987              (string-match "Summary" bufname)
9988              (save-excursion
9989                (set-buffer bufname)
9990                ;; We check that this is, indeed, a summary buffer.
9991                (and (eq major-mode 'gnus-summary-mode)
9992                     ;; Also make sure this isn't bogus.
9993                     gnus-newsgroup-prepared
9994                     ;; Also make sure that this isn't a dead summary buffer.
9995                     (not gnus-dead-summary-mode)))
9996              (push bufname buffers))
9997         (setq buflist (cdr buflist)))
9998       ;; Go through all these summary buffers and offer to save them.
9999       (when buffers
10000         (map-y-or-n-p
10001          "Update summary buffer %s? "
10002          (lambda (buf)
10003            (switch-to-buffer buf)
10004            (gnus-summary-exit))
10005          buffers)))))
10006
10007
10008 ;;; @ for mime-partial
10009 ;;;
10010
10011 (defun gnus-request-partial-message ()
10012   (save-excursion
10013     (let ((number (gnus-summary-article-number))
10014           (group gnus-newsgroup-name)
10015           (mother gnus-article-buffer))
10016       (set-buffer (get-buffer-create " *Partial Article*"))
10017       (erase-buffer)
10018       (setq mime-preview-buffer mother)
10019       (gnus-request-article-this-buffer number group)
10020       (mime-parse-buffer)
10021       )))
10022
10023 (autoload 'mime-combine-message/partial-pieces-automatically
10024   "mime-partial"
10025   "Internal method to combine message/partial messages automatically.")
10026
10027 (mime-add-condition
10028  'action '((type . message)(subtype . partial)
10029            (major-mode . gnus-original-article-mode)
10030            (method . mime-combine-message/partial-pieces-automatically)
10031            (summary-buffer-exp . gnus-summary-buffer)
10032            (request-partial-message-method . gnus-request-partial-message)
10033            ))
10034
10035
10036 ;;; @ for message/rfc822
10037 ;;;
10038
10039 (defun gnus-mime-extract-message/rfc822 (entity situation)
10040   (let (group article num cwin swin cur)
10041     (with-temp-buffer
10042       (mime-insert-entity-content entity)
10043       (setq group (or (cdr (assq 'group situation))
10044                       (completing-read "Group: "
10045                                        gnus-active-hashtb
10046                                        nil
10047                                        (gnus-read-active-file-p)
10048                                        gnus-newsgroup-name))
10049             article (gnus-request-accept-article group)))
10050     (when (and (consp article)
10051                (numberp (setq article (cdr article))))
10052       (setq num (1+ (or (cdr (assq 'number situation)) 0))
10053             cwin (get-buffer-window (current-buffer) t))
10054       (save-window-excursion
10055         (if (setq swin (get-buffer-window gnus-summary-buffer t))
10056             (select-window swin)
10057           (set-buffer gnus-summary-buffer))
10058         (setq cur gnus-current-article)
10059         (forward-line num)
10060         (let (gnus-show-threads)
10061           (gnus-summary-goto-subject article t))
10062         (gnus-summary-clear-mark-forward 1)
10063         (gnus-summary-goto-subject cur))
10064       (when (and cwin (window-frame cwin))
10065         (select-frame (window-frame cwin)))
10066       (when (boundp 'mime-acting-situation-to-override)
10067         (set-alist 'mime-acting-situation-to-override
10068                    'group
10069                    group)
10070         (set-alist 'mime-acting-situation-to-override
10071                    'after-method
10072                    `(progn
10073                       (save-current-buffer
10074                         (set-buffer gnus-group-buffer)
10075                         (gnus-activate-group ,group))
10076                       (gnus-summary-goto-article ,cur
10077                                                  gnus-show-all-headers)))
10078         (set-alist 'mime-acting-situation-to-override
10079                    'number num)))))
10080
10081 (mime-add-condition
10082  'action '((type . message)(subtype . rfc822)
10083            (major-mode . gnus-original-article-mode)
10084            (method . gnus-mime-extract-message/rfc822)
10085            (mode . "extract")
10086            ))
10087
10088 (mime-add-condition
10089  'action '((type . message)(subtype . news)
10090            (major-mode . gnus-original-article-mode)
10091            (method . gnus-mime-extract-message/rfc822)
10092            (mode . "extract")
10093            ))
10094
10095 (defun gnus-mime-extract-multipart (entity situation)
10096   (let ((children (mime-entity-children entity))
10097         mime-acting-situation-to-override
10098         f)
10099     (while children
10100       (mime-play-entity (car children)
10101                         (cons (assq 'mode situation)
10102                               mime-acting-situation-to-override))
10103       (setq children (cdr children)))
10104     (if (setq f (cdr (assq 'after-method
10105                            mime-acting-situation-to-override)))
10106         (eval f)
10107       )))
10108
10109 (mime-add-condition
10110  'action '((type . multipart)
10111            (method . gnus-mime-extract-multipart)
10112            (mode . "extract")
10113            )
10114  'with-default)
10115
10116
10117 ;;; @ end
10118 ;;;
10119
10120 (defun gnus-summary-setup-default-charset ()
10121   "Setup newsgroup default charset."
10122   (if (equal gnus-newsgroup-name "nndraft:drafts")
10123       (setq gnus-newsgroup-charset nil)
10124     (let* ((name (and gnus-newsgroup-name
10125                       (gnus-group-real-name gnus-newsgroup-name)))
10126            (ignored-charsets
10127             (or gnus-newsgroup-ephemeral-ignored-charsets
10128                 (append
10129                  (and gnus-newsgroup-name
10130                       (or (gnus-group-find-parameter gnus-newsgroup-name
10131                                                      'ignored-charsets t)
10132                           (let ((alist gnus-group-ignored-charsets-alist)
10133                                 elem (charsets nil))
10134                             (while (setq elem (pop alist))
10135                               (when (and name
10136                                          (string-match (car elem) name))
10137                                 (setq alist nil
10138                                       charsets (cdr elem))))
10139                             charsets)))
10140                  gnus-newsgroup-ignored-charsets))))
10141       (setq gnus-newsgroup-charset
10142             (or gnus-newsgroup-ephemeral-charset
10143                 (and gnus-newsgroup-name
10144                      (or (gnus-group-find-parameter gnus-newsgroup-name 'charset)
10145                          (let ((alist gnus-group-charset-alist)
10146                                elem charset)
10147                            (while (setq elem (pop alist))
10148                              (when (and name
10149                                         (string-match (car elem) name))
10150                                (setq alist nil
10151                                      charset (cadr elem))))
10152                            charset)))
10153                 gnus-default-charset))
10154       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10155            ignored-charsets))))
10156
10157 ;;;
10158 ;;; Mime Commands
10159 ;;;
10160
10161 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10162   "Display the current article buffer fully MIME-buttonized.
10163 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10164 treated as multipart/mixed."
10165   (interactive "P")
10166   (require 'gnus-art)
10167   (let ((gnus-unbuttonized-mime-types nil)
10168         (gnus-mime-display-multipart-as-mixed show-all-parts))
10169     (gnus-summary-show-article)))
10170
10171 (defun gnus-summary-repair-multipart (article)
10172   "Add a Content-Type header to a multipart article without one."
10173   (interactive (list (gnus-summary-article-number)))
10174   (gnus-with-article article
10175     (message-narrow-to-head)
10176     (message-remove-header "Mime-Version")
10177     (goto-char (point-max))
10178     (insert "Mime-Version: 1.0\n")
10179     (widen)
10180     (when (search-forward "\n--" nil t)
10181       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10182         (message-narrow-to-head)
10183         (message-remove-header "Content-Type")
10184         (goto-char (point-max))
10185         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10186                         separator))
10187         (widen))))
10188   (let (gnus-mark-article-hook)
10189     (gnus-summary-select-article t t nil article)))
10190
10191 (defun gnus-summary-toggle-display-buttonized ()
10192   "Toggle the buttonizing of the article buffer."
10193   (interactive)
10194   (require 'gnus-art)
10195   (if (setq gnus-inhibit-mime-unbuttonizing
10196             (not gnus-inhibit-mime-unbuttonizing))
10197       (let ((gnus-unbuttonized-mime-types nil))
10198         (gnus-summary-show-article))
10199     (gnus-summary-show-article)))
10200
10201 ;;;
10202 ;;; Intelli-mouse commmands
10203 ;;;
10204
10205 (defun gnus-wheel-summary-scroll (event)
10206   (interactive "e")
10207   (let ((amount (if (memq 'shift (event-modifiers event))
10208                     (car gnus-wheel-scroll-amount)
10209                   (cdr gnus-wheel-scroll-amount)))
10210         (direction (- (* (static-if (featurep 'xemacs)
10211                              (event-button event)
10212                            (cond ((eq 'mouse-4 (event-basic-type event))
10213                                   4)
10214                                  ((eq 'mouse-5 (event-basic-type event))
10215                                   5)))
10216                          2) 9))
10217         edge)
10218     (gnus-summary-scroll-up (* amount direction))
10219     (when (gnus-eval-in-buffer-window gnus-article-buffer
10220             (save-restriction
10221               (widen)
10222               (and (if (< 0 direction)
10223                        (gnus-article-next-page 0)
10224                      (gnus-article-prev-page 0)
10225                      (bobp))
10226                    (if (setq edge (get-text-property
10227                                    (point-min) 'gnus-wheel-edge))
10228                        (setq edge (* edge direction))
10229                      (setq edge -1))
10230                    (or (plusp edge)
10231                        (let ((buffer-read-only nil)
10232                              (inhibit-read-only t))
10233                          (put-text-property (point-min) (point-max)
10234                                             'gnus-wheel-edge direction)
10235                          nil))
10236                    (or (> edge gnus-wheel-edge-resistance)
10237                        (let ((buffer-read-only nil)
10238                              (inhibit-read-only t))
10239                          (put-text-property (point-min) (point-max)
10240                                             'gnus-wheel-edge
10241                                             (* (1+ edge) direction))
10242                          nil))
10243                    (eq last-command 'gnus-wheel-summary-scroll))))
10244       (gnus-summary-next-article nil nil (minusp direction)))))
10245
10246 (defun gnus-wheel-install ()
10247   "Enable mouse wheel support on summary window."
10248   (when gnus-use-wheel
10249     (let ((keys
10250            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10251       (dolist (key keys)
10252         (define-key gnus-summary-mode-map key
10253           'gnus-wheel-summary-scroll)))))
10254
10255 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10256
10257 ;;;
10258 ;;; Traditional PGP commmands
10259 ;;;
10260
10261 (defun gnus-summary-decrypt-article (&optional force)
10262   "Decrypt the current article in traditional PGP way.
10263 This will have permanent effect only in mail groups.
10264 If FORCE is non-nil, allow editing of articles even in read-only
10265 groups."
10266   (interactive "P")
10267   (gnus-summary-select-article t)
10268   (gnus-eval-in-buffer-window gnus-article-buffer
10269     (save-excursion
10270       (save-restriction
10271         (widen)
10272         (goto-char (point-min))
10273         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10274           (error "Not a traditional PGP message!"))
10275         (let ((armor-start (match-beginning 0)))
10276           (if (and (pgg-decrypt-region armor-start (point-max))
10277                    (or force (not (gnus-group-read-only-p))))
10278               (let ((inhibit-read-only t)
10279                     buffer-read-only)
10280                 (delete-region armor-start
10281                                (progn
10282                                  (re-search-forward "^-+END PGP" nil t)
10283                                  (beginning-of-line 2)
10284                                  (point)))
10285                 (insert-buffer-substring pgg-output-buffer))))))))
10286
10287 (defun gnus-summary-verify-article ()
10288   "Verify the current article in traditional PGP way."
10289   (interactive)
10290   (save-excursion
10291     (set-buffer gnus-original-article-buffer)
10292     (goto-char (point-min))
10293     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10294       (error "Not a traditional PGP message!"))
10295     (re-search-forward "^-+END PGP" nil t)
10296     (beginning-of-line 2)
10297     (call-interactively (function pgg-verify-region))))
10298
10299 ;;;
10300 ;;; Generic summary marking commands
10301 ;;;
10302
10303 (defvar gnus-summary-marking-alist
10304   '((read gnus-del-mark "d")
10305     (unread gnus-unread-mark "u")
10306     (ticked gnus-ticked-mark "!")
10307     (dormant gnus-dormant-mark "?")
10308     (expirable gnus-expirable-mark "e"))
10309   "An alist of names/marks/keystrokes.")
10310
10311 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10312 (defvar gnus-summary-mark-map)
10313
10314 (defun gnus-summary-make-all-marking-commands ()
10315   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10316   (dolist (elem gnus-summary-marking-alist)
10317     (apply 'gnus-summary-make-marking-command elem)))
10318
10319 (defun gnus-summary-make-marking-command (name mark keystroke)
10320   (let ((map (make-sparse-keymap)))
10321     (define-key gnus-summary-generic-mark-map keystroke map)
10322     (dolist (lway `((next "next" next nil "n")
10323                     (next-unread "next unread" next t "N")
10324                     (prev "previous" prev nil "p")
10325                     (prev-unread "previous unread" prev t "P")
10326                     (nomove "" nil nil ,keystroke)))
10327       (let ((func (gnus-summary-make-marking-command-1
10328                    mark (car lway) lway name)))
10329         (setq func (eval func))
10330         (define-key map (nth 4 lway) func)))))
10331
10332 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10333   `(defun ,(intern
10334             (format "gnus-summary-put-mark-as-%s%s"
10335                     name (if (eq way 'nomove)
10336                              ""
10337                            (concat "-" (symbol-name way)))))
10338      (n)
10339      ,(format
10340        "Mark the current article as %s%s.
10341 If N, the prefix, then repeat N times.
10342 If N is negative, move in reverse order.
10343 The difference between N and the actual number of articles marked is
10344 returned."
10345        name (car (cdr lway)))
10346      (interactive "p")
10347      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10348
10349 (defun gnus-summary-generic-mark (n mark move unread)
10350   "Mark N articles with MARK."
10351   (unless (eq major-mode 'gnus-summary-mode)
10352     (error "This command can only be used in the summary buffer"))
10353   (gnus-summary-show-thread)
10354   (let ((nummove
10355          (cond
10356           ((eq move 'next) 1)
10357           ((eq move 'prev) -1)
10358           (t 0))))
10359     (if (zerop nummove)
10360         (setq n 1)
10361       (when (< n 0)
10362         (setq n (abs n)
10363               nummove (* -1 nummove))))
10364     (while (and (> n 0)
10365                 (gnus-summary-mark-article nil mark)
10366                 (zerop (gnus-summary-next-subject nummove unread t)))
10367       (setq n (1- n)))
10368     (when (/= 0 n)
10369       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10370     (gnus-summary-recenter)
10371     (gnus-summary-position-point)
10372     (gnus-set-mode-line 'summary)
10373     n))
10374
10375 (gnus-summary-make-all-marking-commands)
10376
10377 (gnus-ems-redefine)
10378
10379 (provide 'gnus-sum)
10380
10381 (run-hooks 'gnus-sum-load-hook)
10382
10383 ;;; gnus-sum.el ends here