* gnus-sum.el (gnus-summary-maybe-hide-threads): Use predicate
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 (require 'nnoo)
40
41 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
42 (autoload 'gnus-cache-write-active "gnus-cache")
43 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
44 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
45 (autoload 'mm-uu-dissect "mm-uu")
46
47 (defcustom gnus-kill-summary-on-exit t
48   "*If non-nil, kill the summary buffer when you exit from it.
49 If nil, the summary will become a \"*Dead Summary*\" buffer, and
50 it will be killed sometime later."
51   :group 'gnus-summary-exit
52   :type 'boolean)
53
54 (defcustom gnus-fetch-old-headers nil
55   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
56 If an unread article in the group refers to an older, already read (or
57 just marked as read) article, the old article will not normally be
58 displayed in the Summary buffer.  If this variable is non-nil, Gnus
59 will attempt to grab the headers to the old articles, and thereby
60 build complete threads.  If it has the value `some', only enough
61 headers to connect otherwise loose threads will be displayed.  This
62 variable can also be a number.  In that case, no more than that number
63 of old headers will be fetched.  If it has the value `invisible', all
64 old headers will be fetched, but none will be displayed.
65
66 The server has to support NOV for any of this to work."
67   :group 'gnus-thread
68   :type '(choice (const :tag "off" nil)
69                  (const some)
70                  number
71                  (sexp :menu-tag "other" t)))
72
73 (defcustom gnus-refer-thread-limit 200
74   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
75 If t, fetch all the available old headers."
76   :group 'gnus-thread
77   :type '(choice number
78                  (sexp :menu-tag "other" t)))
79
80 (defcustom gnus-summary-make-false-root 'adopt
81   "*nil means that Gnus won't gather loose threads.
82 If the root of a thread has expired or been read in a previous
83 session, the information necessary to build a complete thread has been
84 lost.  Instead of having many small sub-threads from this original thread
85 scattered all over the summary buffer, Gnus can gather them.
86
87 If non-nil, Gnus will try to gather all loose sub-threads from an
88 original thread into one large thread.
89
90 If this variable is non-nil, it should be one of `none', `adopt',
91 `dummy' or `empty'.
92
93 If this variable is `none', Gnus will not make a false root, but just
94 present the sub-threads after another.
95 If this variable is `dummy', Gnus will create a dummy root that will
96 have all the sub-threads as children.
97 If this variable is `adopt', Gnus will make one of the \"children\"
98 the parent and mark all the step-children as such.
99 If this variable is `empty', the \"children\" are printed with empty
100 subject fields.  (Or rather, they will be printed with a string
101 given by the `gnus-summary-same-subject' variable.)"
102   :group 'gnus-thread
103   :type '(choice (const :tag "off" nil)
104                  (const none)
105                  (const dummy)
106                  (const adopt)
107                  (const empty)))
108
109 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
110   "*A regexp to match subjects to be excluded from loose thread gathering.
111 As loose thread gathering is done on subjects only, that means that
112 there can be many false gatherings performed.  By rooting out certain
113 common subjects, gathering might become saner."
114   :group 'gnus-thread
115   :type 'regexp)
116
117 (defcustom gnus-summary-gather-subject-limit nil
118   "*Maximum length of subject comparisons when gathering loose threads.
119 Use nil to compare full subjects.  Setting this variable to a low
120 number will help gather threads that have been corrupted by
121 newsreaders chopping off subject lines, but it might also mean that
122 unrelated articles that have subject that happen to begin with the
123 same few characters will be incorrectly gathered.
124
125 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
126 comparing subjects."
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const fuzzy)
130                  (sexp :menu-tag "on" t)))
131
132 (defcustom gnus-simplify-subject-functions nil
133   "List of functions taking a string argument that simplify subjects.
134 The functions are applied recursively.
135
136 Useful functions to put in this list include: `gnus-simplify-subject-re',
137 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
138   :group 'gnus-thread
139   :type '(repeat function))
140
141 (defcustom gnus-simplify-ignored-prefixes nil
142   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
143   :group 'gnus-thread
144   :type '(choice (const :tag "off" nil)
145                  regexp))
146
147 (defcustom gnus-build-sparse-threads nil
148   "*If non-nil, fill in the gaps in threads.
149 If `some', only fill in the gaps that are needed to tie loose threads
150 together.  If `more', fill in all leaf nodes that Gnus can find.  If
151 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
152   :group 'gnus-thread
153   :type '(choice (const :tag "off" nil)
154                  (const some)
155                  (const more)
156                  (sexp :menu-tag "all" t)))
157
158 (defcustom gnus-summary-thread-gathering-function
159   'gnus-gather-threads-by-subject
160   "*Function used for gathering loose threads.
161 There are two pre-defined functions: `gnus-gather-threads-by-subject',
162 which only takes Subjects into consideration; and
163 `gnus-gather-threads-by-references', which compared the References
164 headers of the articles to find matches."
165   :group 'gnus-thread
166   :type '(radio (function-item gnus-gather-threads-by-subject)
167                 (function-item gnus-gather-threads-by-references)
168                 (function :tag "other")))
169
170 (defcustom gnus-summary-same-subject ""
171   "*String indicating that the current article has the same subject as the previous.
172 This variable will only be used if the value of
173 `gnus-summary-make-false-root' is `empty'."
174   :group 'gnus-summary-format
175   :type 'string)
176
177 (defcustom gnus-summary-goto-unread t
178   "*If t, many commands will go to the next unread article.
179 This applies to marking commands as well as other commands that
180 \"naturally\" select the next article, like, for instance, `SPC' at
181 the end of an article.
182
183 If nil, the marking commands do NOT go to the next unread article
184 (they go to the next article instead).  If `never', commands that
185 usually go to the next unread article, will go to the next article,
186 whether it is read or not."
187   :group 'gnus-summary-marks
188   :link '(custom-manual "(gnus)Setting Marks")
189   :type '(choice (const :tag "off" nil)
190                  (const never)
191                  (sexp :menu-tag "on" t)))
192
193 (defcustom gnus-summary-default-score 0
194   "*Default article score level.
195 All scores generated by the score files will be added to this score.
196 If this variable is nil, scoring will be disabled."
197   :group 'gnus-score-default
198   :type '(choice (const :tag "disable")
199                  integer))
200
201 (defcustom gnus-summary-default-high-score 0
202   "*Default threshold for a high scored article.
203 An article will be highlighted as high scored if its score is greater
204 than this score."
205   :group 'gnus-score-default
206   :type 'integer)
207
208 (defcustom gnus-summary-default-low-score 0
209   "*Default threshold for a low scored article.
210 An article will be highlighted as low scored if its score is smaller
211 than this score."
212   :group 'gnus-score-default
213   :type '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 This can be a predicate specifier which says which threads to hide.
238 If threads are hidden, you have to run the command
239 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
240 to expose hidden threads."
241   :group 'gnus-thread
242   :type 'boolean)
243
244 (defcustom gnus-thread-hide-killed t
245   "*If non-nil, hide killed threads automatically."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-ignore-subject t
250   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
251 If nil, articles that have different subjects from their parents will
252 start separate threads."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-operation-ignore-subject t
257   "*If non-nil, subjects will be ignored when doing thread commands.
258 This affects commands like `gnus-summary-kill-thread' and
259 `gnus-summary-lower-thread'.
260
261 If this variable is nil, articles in the same thread with different
262 subjects will not be included in the operation in question.  If this
263 variable is `fuzzy', only articles that have subjects that are fuzzily
264 equal will be included."
265   :group 'gnus-thread
266   :type '(choice (const :tag "off" nil)
267                  (const fuzzy)
268                  (sexp :tag "on" t)))
269
270 (defcustom gnus-thread-indent-level 4
271   "*Number that says how much each sub-thread should be indented."
272   :group 'gnus-thread
273   :type 'integer)
274
275 (defcustom gnus-auto-extend-newsgroup t
276   "*If non-nil, extend newsgroup forward and backward when requested."
277   :group 'gnus-summary-choose
278   :type 'boolean)
279
280 (defcustom gnus-auto-select-first t
281   "*If non-nil, select the article under point.
282 Which article this is is controlled by the `gnus-auto-select-subject'
283 variable.
284
285 If you want to prevent automatic selection of articles in some
286 newsgroups, set the variable to nil in `gnus-select-group-hook'."
287   :group 'gnus-group-select
288   :type '(choice (const :tag "none" nil)
289                  (sexp :menu-tag "first" t)))
290
291 (defcustom gnus-auto-select-subject 'unread
292   "*Says what subject to place under point when entering a group.
293
294 This variable can either be the symbols `first' (place point on the
295 first subject), `unread' (place point on the subject line of the first
296 unread article), `best' (place point on the subject line of the
297 higest-scored article), `unseen' (place point on the subject line of
298 the first unseen article), or a function to be called to place point on
299 some subject line.."
300   :group 'gnus-group-select
301   :type '(choice (const best)
302                  (const unread)
303                  (const first)
304                  (const unseen)))
305
306 (defcustom gnus-auto-select-next t
307   "*If non-nil, offer to go to the next group from the end of the previous.
308 If the value is t and the next newsgroup is empty, Gnus will exit
309 summary mode and go back to group mode.  If the value is neither nil
310 nor t, Gnus will select the following unread newsgroup.  In
311 particular, if the value is the symbol `quietly', the next unread
312 newsgroup will be selected without any confirmation, and if it is
313 `almost-quietly', the next group will be selected without any
314 confirmation if you are located on the last article in the group.
315 Finally, if this variable is `slightly-quietly', the `Z n' command
316 will go to the next group without confirmation."
317   :group 'gnus-summary-maneuvering
318   :type '(choice (const :tag "off" nil)
319                  (const quietly)
320                  (const almost-quietly)
321                  (const slightly-quietly)
322                  (sexp :menu-tag "on" t)))
323
324 (defcustom gnus-auto-select-same nil
325   "*If non-nil, select the next article with the same subject.
326 If there are no more articles with the same subject, go to
327 the first unread article."
328   :group 'gnus-summary-maneuvering
329   :type 'boolean)
330
331 (defcustom gnus-summary-check-current nil
332   "*If non-nil, consider the current article when moving.
333 The \"unread\" movement commands will stay on the same line if the
334 current article is unread."
335   :group 'gnus-summary-maneuvering
336   :type 'boolean)
337
338 (defcustom gnus-auto-center-summary t
339   "*If non-nil, always center the current summary buffer.
340 In particular, if `vertical' do only vertical recentering.  If non-nil
341 and non-`vertical', do both horizontal and vertical recentering."
342   :group 'gnus-summary-maneuvering
343   :type '(choice (const :tag "none" nil)
344                  (const vertical)
345                  (integer :tag "height")
346                  (sexp :menu-tag "both" t)))
347
348 (defcustom gnus-show-all-headers nil
349   "*If non-nil, don't hide any headers."
350   :group 'gnus-article-hiding
351   :group 'gnus-article-headers
352   :type 'boolean)
353
354 (defcustom gnus-summary-ignore-duplicates nil
355   "*If non-nil, ignore articles with identical Message-ID headers."
356   :group 'gnus-summary
357   :type 'boolean)
358
359 (defcustom gnus-single-article-buffer t
360   "*If non-nil, display all articles in the same buffer.
361 If nil, each group will get its own article buffer."
362   :group 'gnus-article-various
363   :type 'boolean)
364
365 (defcustom gnus-break-pages t
366   "*If non-nil, do page breaking on articles.
367 The page delimiter is specified by the `gnus-page-delimiter'
368 variable."
369   :group 'gnus-article-various
370   :type 'boolean)
371
372 (defcustom gnus-move-split-methods nil
373   "*Variable used to suggest where articles are to be moved to.
374 It uses the same syntax as the `gnus-split-methods' variable.
375 However, whereas `gnus-split-methods' specifies file names as targets,
376 this variable specifies group names."
377   :group 'gnus-summary-mail
378   :type '(repeat (choice (list :value (fun) function)
379                          (cons :value ("" "") regexp (repeat string))
380                          (sexp :value nil))))
381
382 (defcustom gnus-unread-mark ?           ;Whitespace
383   "*Mark used for unread articles."
384   :group 'gnus-summary-marks
385   :type 'character)
386
387 (defcustom gnus-ticked-mark ?!
388   "*Mark used for ticked articles."
389   :group 'gnus-summary-marks
390   :type 'character)
391
392 (defcustom gnus-dormant-mark ??
393   "*Mark used for dormant articles."
394   :group 'gnus-summary-marks
395   :type 'character)
396
397 (defcustom gnus-del-mark ?r
398   "*Mark used for del'd articles."
399   :group 'gnus-summary-marks
400   :type 'character)
401
402 (defcustom gnus-read-mark ?R
403   "*Mark used for read articles."
404   :group 'gnus-summary-marks
405   :type 'character)
406
407 (defcustom gnus-expirable-mark ?E
408   "*Mark used for expirable articles."
409   :group 'gnus-summary-marks
410   :type 'character)
411
412 (defcustom gnus-killed-mark ?K
413   "*Mark used for killed articles."
414   :group 'gnus-summary-marks
415   :type 'character)
416
417 (defcustom gnus-souped-mark ?F
418   "*Mark used for souped articles."
419   :group 'gnus-summary-marks
420   :type 'character)
421
422 (defcustom gnus-kill-file-mark ?X
423   "*Mark used for articles killed by kill files."
424   :group 'gnus-summary-marks
425   :type 'character)
426
427 (defcustom gnus-low-score-mark ?Y
428   "*Mark used for articles with a low score."
429   :group 'gnus-summary-marks
430   :type 'character)
431
432 (defcustom gnus-catchup-mark ?C
433   "*Mark used for articles that are caught up."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-replied-mark ?A
438   "*Mark used for articles that have been replied to."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-forwarded-mark ?F
443   "*Mark used for articles that have been forwarded."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-recent-mark ?N
448   "*Mark used for articles that are recent."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-cached-mark ?*
453   "*Mark used for articles that are in the cache."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-saved-mark ?S
458   "*Mark used for articles that have been saved."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-unseen-mark ?.
463   "*Mark used for articles that haven't been seen."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-no-mark ?               ;Whitespace
468   "*Mark used for articles that have no other secondary mark."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-ancient-mark ?O
473   "*Mark used for ancient articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-sparse-mark ?Q
478   "*Mark used for sparsely reffed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-canceled-mark ?G
483   "*Mark used for canceled articles."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-duplicate-mark ?M
488   "*Mark used for duplicate articles."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-undownloaded-mark ?@
493   "*Mark used for articles that weren't downloaded."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-downloadable-mark ?%
498   "*Mark used for articles that are to be downloaded."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-unsendable-mark ?=
503   "*Mark used for articles that won't be sent."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-score-over-mark ?+
508   "*Score mark used for articles with high scores."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-score-below-mark ?-
513   "*Score mark used for articles with low scores."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-empty-thread-mark ?     ;Whitespace
518   "*There is no thread under the article."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-not-empty-thread-mark ?=
523   "*There is a thread under the article."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-view-pseudo-asynchronously nil
528   "*If non-nil, Gnus will view pseudo-articles asynchronously."
529   :group 'gnus-extract-view
530   :type 'boolean)
531
532 (defcustom gnus-auto-expirable-marks
533   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
534         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
535         gnus-souped-mark gnus-duplicate-mark)
536   "*The list of marks converted into expiration if a group is auto-expirable."
537   :version "21.1"
538   :group 'gnus-summary
539   :type '(repeat character))
540
541 (defcustom gnus-inhibit-user-auto-expire t
542   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
543   :version "21.1"
544   :group 'gnus-summary
545   :type 'boolean)
546
547 (defcustom gnus-view-pseudos nil
548   "*If `automatic', pseudo-articles will be viewed automatically.
549 If `not-confirm', pseudos will be viewed automatically, and the user
550 will not be asked to confirm the command."
551   :group 'gnus-extract-view
552   :type '(choice (const :tag "off" nil)
553                  (const automatic)
554                  (const not-confirm)))
555
556 (defcustom gnus-view-pseudos-separately t
557   "*If non-nil, one pseudo-article will be created for each file to be viewed.
558 If nil, all files that use the same viewing command will be given as a
559 list of parameters to that command."
560   :group 'gnus-extract-view
561   :type 'boolean)
562
563 (defcustom gnus-insert-pseudo-articles t
564   "*If non-nil, insert pseudo-articles when decoding articles."
565   :group 'gnus-extract-view
566   :type 'boolean)
567
568 (defcustom gnus-summary-dummy-line-format
569   "  %(:                          :%) %S\n"
570   "*The format specification for the dummy roots in the summary buffer.
571 It works along the same lines as a normal formatting string,
572 with some simple extensions.
573
574 %S  The subject"
575   :group 'gnus-threading
576   :type 'string)
577
578 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
579   "*The format specification for the summary mode line.
580 It works along the same lines as a normal formatting string,
581 with some simple extensions:
582
583 %G  Group name
584 %p  Unprefixed group name
585 %A  Current article number
586 %z  Current article score
587 %V  Gnus version
588 %U  Number of unread articles in the group
589 %e  Number of unselected articles in the group
590 %Z  A string with unread/unselected article counts
591 %g  Shortish group name
592 %S  Subject of the current article
593 %u  User-defined spec
594 %s  Current score file name
595 %d  Number of dormant articles
596 %r  Number of articles that have been marked as read in this session
597 %E  Number of articles expunged by the score files"
598   :group 'gnus-summary-format
599   :type 'string)
600
601 (defcustom gnus-list-identifiers nil
602   "Regexp that matches list identifiers to be removed from subject.
603 This can also be a list of regexps."
604   :version "21.1"
605   :group 'gnus-summary-format
606   :group 'gnus-article-hiding
607   :type '(choice (const :tag "none" nil)
608                  (regexp :value ".*")
609                  (repeat :value (".*") regexp)))
610
611 (defcustom gnus-summary-mark-below 0
612   "*Mark all articles with a score below this variable as read.
613 This variable is local to each summary buffer and usually set by the
614 score file."
615   :group 'gnus-score-default
616   :type 'integer)
617
618 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
619   "*List of functions used for sorting articles in the summary buffer.
620
621 Each function takes two articles and returns non-nil if the first
622 article should be sorted before the other.  If you use more than one
623 function, the primary sort function should be the last.  You should
624 probably always include `gnus-article-sort-by-number' in the list of
625 sorting functions -- preferably first.  Also note that sorting by date
626 is often much slower than sorting by number, and the sorting order is
627 very similar.  (Sorting by date means sorting by the time the message
628 was sent, sorting by number means sorting by arrival time.)
629
630 Ready-made functions include `gnus-article-sort-by-number',
631 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
632 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
633
634 When threading is turned on, the variable `gnus-thread-sort-functions'
635 controls how articles are sorted."
636   :group 'gnus-summary-sort
637   :type '(repeat (choice (function-item gnus-article-sort-by-number)
638                          (function-item gnus-article-sort-by-author)
639                          (function-item gnus-article-sort-by-subject)
640                          (function-item gnus-article-sort-by-date)
641                          (function-item gnus-article-sort-by-score)
642                          (function :tag "other"))))
643
644 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
645   "*List of functions used for sorting threads in the summary buffer.
646 By default, threads are sorted by article number.
647
648 Each function takes two threads and returns non-nil if the first
649 thread should be sorted before the other.  If you use more than one
650 function, the primary sort function should be the last.  You should
651 probably always include `gnus-thread-sort-by-number' in the list of
652 sorting functions -- preferably first.  Also note that sorting by date
653 is often much slower than sorting by number, and the sorting order is
654 very similar.  (Sorting by date means sorting by the time the message
655 was sent, sorting by number means sorting by arrival time.)
656
657 Ready-made functions include `gnus-thread-sort-by-number',
658 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
659 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
660 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
661
662 When threading is turned off, the variable
663 `gnus-article-sort-functions' controls how articles are sorted."
664   :group 'gnus-summary-sort
665   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
666                          (function-item gnus-thread-sort-by-author)
667                          (function-item gnus-thread-sort-by-subject)
668                          (function-item gnus-thread-sort-by-date)
669                          (function-item gnus-thread-sort-by-score)
670                          (function-item gnus-thread-sort-by-total-score)
671                          (function :tag "other"))))
672
673 (defcustom gnus-thread-score-function '+
674   "*Function used for calculating the total score of a thread.
675
676 The function is called with the scores of the article and each
677 subthread and should then return the score of the thread.
678
679 Some functions you can use are `+', `max', or `min'."
680   :group 'gnus-summary-sort
681   :type 'function)
682
683 (defcustom gnus-summary-expunge-below nil
684   "All articles that have a score less than this variable will be expunged.
685 This variable is local to the summary buffers."
686   :group 'gnus-score-default
687   :type '(choice (const :tag "off" nil)
688                  integer))
689
690 (defcustom gnus-thread-expunge-below nil
691   "All threads that have a total score less than this variable will be expunged.
692 See `gnus-thread-score-function' for en explanation of what a
693 \"thread score\" is.
694
695 This variable is local to the summary buffers."
696   :group 'gnus-threading
697   :group 'gnus-score-default
698   :type '(choice (const :tag "off" nil)
699                  integer))
700
701 (defcustom gnus-summary-mode-hook nil
702   "*A hook for Gnus summary mode.
703 This hook is run before any variables are set in the summary buffer."
704   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
705   :group 'gnus-summary-various
706   :type 'hook)
707
708 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
709 (when (featurep 'xemacs)
710   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
711   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
712   (add-hook 'gnus-summary-mode-hook
713             'gnus-xmas-switch-horizontal-scrollbar-off))
714
715 (defcustom gnus-summary-menu-hook nil
716   "*Hook run after the creation of the summary mode menu."
717   :group 'gnus-summary-visual
718   :type 'hook)
719
720 (defcustom gnus-summary-exit-hook nil
721   "*A hook called on exit from the summary buffer.
722 It will be called with point in the group buffer."
723   :group 'gnus-summary-exit
724   :type 'hook)
725
726 (defcustom gnus-summary-prepare-hook nil
727   "*A hook called after the summary buffer has been generated.
728 If you want to modify the summary buffer, you can use this hook."
729   :group 'gnus-summary-various
730   :type 'hook)
731
732 (defcustom gnus-summary-prepared-hook nil
733   "*A hook called as the last thing after the summary buffer has been generated."
734   :group 'gnus-summary-various
735   :type 'hook)
736
737 (defcustom gnus-summary-generate-hook nil
738   "*A hook run just before generating the summary buffer.
739 This hook is commonly used to customize threading variables and the
740 like."
741   :group 'gnus-summary-various
742   :type 'hook)
743
744 (defcustom gnus-select-group-hook nil
745   "*A hook called when a newsgroup is selected.
746
747 If you'd like to simplify subjects like the
748 `gnus-summary-next-same-subject' command does, you can use the
749 following hook:
750
751  (setq gnus-select-group-hook
752       (list
753         (lambda ()
754           (mapcar (lambda (header)
755                      (mail-header-set-subject
756                       header
757                       (gnus-simplify-subject
758                        (mail-header-subject header) 're-only)))
759                   gnus-newsgroup-headers))))"
760   :group 'gnus-group-select
761   :type 'hook)
762
763 (defcustom gnus-select-article-hook nil
764   "*A hook called when an article is selected."
765   :group 'gnus-summary-choose
766   :type 'hook)
767
768 (defcustom gnus-visual-mark-article-hook
769   (list 'gnus-highlight-selected-summary)
770   "*Hook run after selecting an article in the summary buffer.
771 It is meant to be used for highlighting the article in some way.  It
772 is not run if `gnus-visual' is nil."
773   :group 'gnus-summary-visual
774   :type 'hook)
775
776 (defcustom gnus-parse-headers-hook nil
777   "*A hook called before parsing the headers."
778   :group 'gnus-various
779   :type 'hook)
780
781 (defcustom gnus-exit-group-hook nil
782   "*A hook called when exiting summary mode.
783 This hook is not called from the non-updating exit commands like `Q'."
784   :group 'gnus-various
785   :type 'hook)
786
787 (defcustom gnus-summary-update-hook
788   (list 'gnus-summary-highlight-line)
789   "*A hook called when a summary line is changed.
790 The hook will not be called if `gnus-visual' is nil.
791
792 The default function `gnus-summary-highlight-line' will
793 highlight the line according to the `gnus-summary-highlight'
794 variable."
795   :group 'gnus-summary-visual
796   :type 'hook)
797
798 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
799   "*A hook called when an article is selected for the first time.
800 The hook is intended to mark an article as read (or unread)
801 automatically when it is selected."
802   :group 'gnus-summary-choose
803   :type 'hook)
804
805 (defcustom gnus-group-no-more-groups-hook nil
806   "*A hook run when returning to group mode having no more (unread) groups."
807   :group 'gnus-group-select
808   :type 'hook)
809
810 (defcustom gnus-ps-print-hook nil
811   "*A hook run before ps-printing something from Gnus."
812   :group 'gnus-summary
813   :type 'hook)
814
815 (defcustom gnus-summary-display-arrow
816   (and (fboundp 'display-graphic-p)
817        (display-graphic-p))
818   "*If non-nil, display an arrow highlighting the current article."
819   :version "21.1"
820   :group 'gnus-summary
821   :type 'boolean)
822
823 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
824   "Face used for highlighting the current article in the summary buffer."
825   :group 'gnus-summary-visual
826   :type 'face)
827
828 (defcustom gnus-summary-highlight
829   '(((= mark gnus-canceled-mark)
830      . gnus-summary-cancelled-face)
831     ((and (> score default-high)
832           (or (= mark gnus-dormant-mark)
833               (= mark gnus-ticked-mark)))
834      . gnus-summary-high-ticked-face)
835     ((and (< score default-low)
836           (or (= mark gnus-dormant-mark)
837               (= mark gnus-ticked-mark)))
838      . gnus-summary-low-ticked-face)
839     ((or (= mark gnus-dormant-mark)
840          (= mark gnus-ticked-mark))
841      . gnus-summary-normal-ticked-face)
842     ((and (> score default-high) (= mark gnus-ancient-mark))
843      . gnus-summary-high-ancient-face)
844     ((and (< score default-low) (= mark gnus-ancient-mark))
845      . gnus-summary-low-ancient-face)
846     ((= mark gnus-ancient-mark)
847      . gnus-summary-normal-ancient-face)
848     ((and (> score default-high) (= mark gnus-unread-mark))
849      . gnus-summary-high-unread-face)
850     ((and (< score default-low) (= mark gnus-unread-mark))
851      . gnus-summary-low-unread-face)
852     ((= mark gnus-unread-mark)
853      . gnus-summary-normal-unread-face)
854     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
855                                                   gnus-undownloaded-mark)))
856      . gnus-summary-high-unread-face)
857     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
858                                                  gnus-undownloaded-mark)))
859      . gnus-summary-low-unread-face)
860     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
861           (memq article gnus-newsgroup-unreads))
862      . gnus-summary-normal-unread-face)
863     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
864      . gnus-summary-normal-read-face)
865     ((> score default-high)
866      . gnus-summary-high-read-face)
867     ((< score default-low)
868      . gnus-summary-low-read-face)
869     (t
870      . gnus-summary-normal-read-face))
871   "*Controls the highlighting of summary buffer lines.
872
873 A list of (FORM . FACE) pairs.  When deciding how a a particular
874 summary line should be displayed, each form is evaluated.  The content
875 of the face field after the first true form is used.  You can change
876 how those summary lines are displayed, by editing the face field.
877
878 You can use the following variables in the FORM field.
879
880 score:        The article's score
881 default:      The default article score.
882 default-high: The default score for high scored articles.
883 default-low:  The default score for low scored articles.
884 below:        The score below which articles are automatically marked as read.
885 mark:         The articles mark."
886   :group 'gnus-summary-visual
887   :type '(repeat (cons (sexp :tag "Form" nil)
888                        face)))
889
890 (defcustom gnus-alter-header-function nil
891   "Function called to allow alteration of article header structures.
892 The function is called with one parameter, the article header vector,
893 which it may alter in any way.")
894
895 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
896   "Variable that says which function should be used to decode a string with encoded words.")
897
898 (defcustom gnus-extra-headers nil
899   "*Extra headers to parse."
900   :version "21.1"
901   :group 'gnus-summary
902   :type '(repeat symbol))
903
904 (defcustom gnus-ignored-from-addresses
905   (and user-mail-address (regexp-quote user-mail-address))
906   "*Regexp of From headers that may be suppressed in favor of To headers."
907   :version "21.1"
908   :group 'gnus-summary
909   :type 'regexp)
910
911 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
912   "List of charsets that should be ignored.
913 When these charsets are used in the \"charset\" parameter, the
914 default charset will be used instead."
915   :version "21.1"
916   :type '(repeat symbol)
917   :group 'gnus-charset)
918
919 (gnus-define-group-parameter
920  ignored-charsets
921  :type list
922  :function-document
923  "Return the ignored charsets of GROUP."
924  :variable gnus-group-ignored-charsets-alist
925  :variable-default
926  '(("alt\\.chinese\\.text" iso-8859-1))
927  :variable-document
928  "Alist of regexps (to match group names) and charsets that should be ignored.
929 When these charsets are used in the \"charset\" parameter, the
930 default charset will be used instead."
931  :variable-group gnus-charset
932  :variable-type '(repeat (cons (regexp :tag "Group")
933                                (repeat symbol)))
934  :parameter-type '(choice :tag "Ignored charsets"
935                           :value nil
936                           (repeat (symbol)))
937  :parameter-document       "\
938 List of charsets that should be ignored.
939
940 When these charsets are used in the \"charset\" parameter, the
941 default charset will be used instead.")
942
943 (defcustom gnus-group-highlight-words-alist nil
944   "Alist of group regexps and highlight regexps.
945 This variable uses the same syntax as `gnus-emphasis-alist'."
946   :version "21.1"
947   :type '(repeat (cons (regexp :tag "Group")
948                        (repeat (list (regexp :tag "Highlight regexp")
949                                      (number :tag "Group for entire word" 0)
950                                      (number :tag "Group for displayed part" 0)
951                                      (symbol :tag "Face"
952                                              gnus-emphasis-highlight-words)))))
953   :group 'gnus-summary-visual)
954
955 (defcustom gnus-summary-show-article-charset-alist
956   nil
957   "Alist of number and charset.
958 The article will be shown with the charset corresponding to the
959 numbered argument.
960 For example: ((1 . cn-gb-2312) (2 . big5))."
961   :version "21.1"
962   :type '(repeat (cons (number :tag "Argument" 1)
963                        (symbol :tag "Charset")))
964   :group 'gnus-charset)
965
966 (defcustom gnus-preserve-marks t
967   "Whether marks are preserved when moving, copying and respooling messages."
968   :version "21.1"
969   :type 'boolean
970   :group 'gnus-summary-marks)
971
972 (defcustom gnus-alter-articles-to-read-function nil
973   "Function to be called to alter the list of articles to be selected."
974   :type '(choice (const nil) function)
975   :group 'gnus-summary)
976
977 (defcustom gnus-orphan-score nil
978   "*All orphans get this score added.  Set in the score file."
979   :group 'gnus-score-default
980   :type '(choice (const nil)
981                  integer))
982
983 (defcustom gnus-summary-save-parts-default-mime "image/.*"
984   "*A regexp to match MIME parts when saving multiple parts of a message
985 with gnus-summary-save-parts (X m). This regexp will be used by default
986 when prompting the user for which type of files to save."
987   :group 'gnus-summary
988   :type 'regexp)
989
990
991 (defcustom gnus-summary-save-parts-default-mime "image/.*"
992   "*A regexp to match MIME parts when saving multiple parts of a message
993 with gnus-summary-save-parts (X m). This regexp will be used by default
994 when prompting the user for which type of files to save."
995   :group 'gnus-summary
996   :type 'regexp)
997
998 (defcustom gnus-read-all-available-headers nil
999   "Whether Gnus should parse all headers made available to it.
1000 This is mostly relevant for slow backends where the user may
1001 wish to widen the summary buffer to include all headers
1002 that were fetched.  Say, for nnultimate groups."
1003   :group 'gnus-summary
1004   :type '(choice boolean regexp))
1005
1006 (defcustom gnus-summary-muttprint-program "muttprint"
1007   "Command (and optional arguments) used to run Muttprint."
1008   :group 'gnus-summary
1009   :type 'string)
1010
1011 ;;; Internal variables
1012
1013 (defvar gnus-summary-display-cache nil)
1014 (defvar gnus-article-mime-handles nil)
1015 (defvar gnus-article-decoded-p nil)
1016 (defvar gnus-article-charset nil)
1017 (defvar gnus-article-ignored-charsets nil)
1018 (defvar gnus-scores-exclude-files nil)
1019 (defvar gnus-page-broken nil)
1020 (defvar gnus-inhibit-mime-unbuttonizing nil)
1021
1022 (defvar gnus-original-article nil)
1023 (defvar gnus-article-internal-prepare-hook nil)
1024 (defvar gnus-newsgroup-process-stack nil)
1025
1026 (defvar gnus-thread-indent-array nil)
1027 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1028 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1029   "Function called to sort the articles within a thread after it has been gathered together.")
1030
1031 (defvar gnus-summary-save-parts-type-history nil)
1032 (defvar gnus-summary-save-parts-last-directory nil)
1033
1034 (defvar gnus-summary-save-parts-type-history nil)
1035 (defvar gnus-summary-save-parts-last-directory nil)
1036
1037 ;; Avoid highlighting in kill files.
1038 (defvar gnus-summary-inhibit-highlight nil)
1039 (defvar gnus-newsgroup-selected-overlay nil)
1040 (defvar gnus-inhibit-limiting nil)
1041 (defvar gnus-newsgroup-adaptive-score-file nil)
1042 (defvar gnus-current-score-file nil)
1043 (defvar gnus-current-move-group nil)
1044 (defvar gnus-current-copy-group nil)
1045 (defvar gnus-current-crosspost-group nil)
1046 (defvar gnus-newsgroup-display nil)
1047
1048 (defvar gnus-newsgroup-dependencies nil)
1049 (defvar gnus-newsgroup-adaptive nil)
1050 (defvar gnus-summary-display-article-function nil)
1051 (defvar gnus-summary-highlight-line-function nil
1052   "Function called after highlighting a summary line.")
1053
1054 (defvar gnus-summary-line-format-alist
1055   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1056     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1057     (?s gnus-tmp-subject-or-nil ?s)
1058     (?n gnus-tmp-name ?s)
1059     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1060         ?s)
1061     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1062             gnus-tmp-from) ?s)
1063     (?F gnus-tmp-from ?s)
1064     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1065     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1066     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1067     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1068     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1069     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1070     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1071     (?L gnus-tmp-lines ?s)
1072     (?I gnus-tmp-indentation ?s)
1073     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1074     (?R gnus-tmp-replied ?c)
1075     (?\[ gnus-tmp-opening-bracket ?c)
1076     (?\] gnus-tmp-closing-bracket ?c)
1077     (?\> (make-string gnus-tmp-level ? ) ?s)
1078     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1079     (?i gnus-tmp-score ?d)
1080     (?z gnus-tmp-score-char ?c)
1081     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1082     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1083     (?U gnus-tmp-unread ?c)
1084     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1085         ?s)
1086     (?t (gnus-summary-number-of-articles-in-thread
1087          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1088         ?d)
1089     (?e (gnus-summary-number-of-articles-in-thread
1090          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1091         ?c)
1092     (?u gnus-tmp-user-defined ?s)
1093     (?P (gnus-pick-line-number) ?d)
1094     (?B gnus-tmp-thread-tree-header-string ?s)
1095     (user-date (gnus-user-date
1096                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1097   "An alist of format specifications that can appear in summary lines.
1098 These are paired with what variables they correspond with, along with
1099 the type of the variable (string, integer, character, etc).")
1100
1101 (defvar gnus-summary-dummy-line-format-alist
1102   `((?S gnus-tmp-subject ?s)
1103     (?N gnus-tmp-number ?d)
1104     (?u gnus-tmp-user-defined ?s)))
1105
1106 (defvar gnus-summary-mode-line-format-alist
1107   `((?G gnus-tmp-group-name ?s)
1108     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1109     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1110     (?A gnus-tmp-article-number ?d)
1111     (?Z gnus-tmp-unread-and-unselected ?s)
1112     (?V gnus-version ?s)
1113     (?U gnus-tmp-unread-and-unticked ?d)
1114     (?S gnus-tmp-subject ?s)
1115     (?e gnus-tmp-unselected ?d)
1116     (?u gnus-tmp-user-defined ?s)
1117     (?d (length gnus-newsgroup-dormant) ?d)
1118     (?t (length gnus-newsgroup-marked) ?d)
1119     (?r (length gnus-newsgroup-reads) ?d)
1120     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1121     (?E gnus-newsgroup-expunged-tally ?d)
1122     (?s (gnus-current-score-file-nondirectory) ?s)))
1123
1124 (defvar gnus-last-search-regexp nil
1125   "Default regexp for article search command.")
1126
1127 (defvar gnus-last-shell-command nil
1128   "Default shell command on article.")
1129
1130 (defvar gnus-newsgroup-begin nil)
1131 (defvar gnus-newsgroup-end nil)
1132 (defvar gnus-newsgroup-last-rmail nil)
1133 (defvar gnus-newsgroup-last-mail nil)
1134 (defvar gnus-newsgroup-last-folder nil)
1135 (defvar gnus-newsgroup-last-file nil)
1136 (defvar gnus-newsgroup-auto-expire nil)
1137 (defvar gnus-newsgroup-active nil)
1138
1139 (defvar gnus-newsgroup-data nil)
1140 (defvar gnus-newsgroup-data-reverse nil)
1141 (defvar gnus-newsgroup-limit nil)
1142 (defvar gnus-newsgroup-limits nil)
1143
1144 (defvar gnus-newsgroup-unreads nil
1145   "List of unread articles in the current newsgroup.")
1146
1147 (defvar gnus-newsgroup-unselected nil
1148   "List of unselected unread articles in the current newsgroup.")
1149
1150 (defvar gnus-newsgroup-reads nil
1151   "Alist of read articles and article marks in the current newsgroup.")
1152
1153 (defvar gnus-newsgroup-expunged-tally nil)
1154
1155 (defvar gnus-newsgroup-marked nil
1156   "List of ticked articles in the current newsgroup (a subset of unread art).")
1157
1158 (defvar gnus-newsgroup-killed nil
1159   "List of ranges of articles that have been through the scoring process.")
1160
1161 (defvar gnus-newsgroup-cached nil
1162   "List of articles that come from the article cache.")
1163
1164 (defvar gnus-newsgroup-saved nil
1165   "List of articles that have been saved.")
1166
1167 (defvar gnus-newsgroup-kill-headers nil)
1168
1169 (defvar gnus-newsgroup-replied nil
1170   "List of articles that have been replied to in the current newsgroup.")
1171
1172 (defvar gnus-newsgroup-forwarded nil
1173   "List of articles that have been forwarded in the current newsgroup.")
1174
1175 (defvar gnus-newsgroup-recent nil
1176   "List of articles that have are recent in the current newsgroup.")
1177
1178 (defvar gnus-newsgroup-expirable nil
1179   "List of articles in the current newsgroup that can be expired.")
1180
1181 (defvar gnus-newsgroup-processable nil
1182   "List of articles in the current newsgroup that can be processed.")
1183
1184 (defvar gnus-newsgroup-downloadable nil
1185   "List of articles in the current newsgroup that can be processed.")
1186
1187 (defvar gnus-newsgroup-undownloaded nil
1188   "List of articles in the current newsgroup that haven't been downloaded..")
1189
1190 (defvar gnus-newsgroup-unsendable nil
1191   "List of articles in the current newsgroup that won't be sent.")
1192
1193 (defvar gnus-newsgroup-bookmarks nil
1194   "List of articles in the current newsgroup that have bookmarks.")
1195
1196 (defvar gnus-newsgroup-dormant nil
1197   "List of dormant articles in the current newsgroup.")
1198
1199 (defvar gnus-newsgroup-unseen nil
1200   "List of unseen articles in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-seen nil
1203   "Range of seen articles in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-articles nil
1206   "List of articles in the current newsgroup.")
1207
1208 (defvar gnus-newsgroup-scored nil
1209   "List of scored articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-headers nil
1212   "List of article headers in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-threads nil)
1215
1216 (defvar gnus-newsgroup-prepared nil
1217   "Whether the current group has been prepared properly.")
1218
1219 (defvar gnus-newsgroup-ancient nil
1220   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-sparse nil)
1223
1224 (defvar gnus-current-article nil)
1225 (defvar gnus-article-current nil)
1226 (defvar gnus-current-headers nil)
1227 (defvar gnus-have-all-headers nil)
1228 (defvar gnus-last-article nil)
1229 (defvar gnus-newsgroup-history nil)
1230 (defvar gnus-newsgroup-charset nil)
1231 (defvar gnus-newsgroup-ephemeral-charset nil)
1232 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1233
1234 (defvar gnus-article-before-search nil)
1235
1236 (defconst gnus-summary-local-variables
1237   '(gnus-newsgroup-name
1238     gnus-newsgroup-begin gnus-newsgroup-end
1239     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1240     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1241     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1242     gnus-newsgroup-unselected gnus-newsgroup-marked
1243     gnus-newsgroup-reads gnus-newsgroup-saved
1244     gnus-newsgroup-replied gnus-newsgroup-forwarded
1245     gnus-newsgroup-recent
1246     gnus-newsgroup-expirable
1247     gnus-newsgroup-processable gnus-newsgroup-killed
1248     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1249     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1250     gnus-newsgroup-seen gnus-newsgroup-articles
1251     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1252     gnus-newsgroup-headers gnus-newsgroup-threads
1253     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1254     gnus-current-article gnus-current-headers gnus-have-all-headers
1255     gnus-last-article gnus-article-internal-prepare-hook
1256     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1257     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1258     gnus-thread-expunge-below
1259     gnus-score-alist gnus-current-score-file
1260     (gnus-summary-expunge-below . global)
1261     (gnus-summary-mark-below . global)
1262     (gnus-orphan-score . global)
1263     gnus-newsgroup-active gnus-scores-exclude-files
1264     gnus-newsgroup-history gnus-newsgroup-ancient
1265     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1266     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1267     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1268     (gnus-newsgroup-expunged-tally . 0)
1269     gnus-cache-removable-articles gnus-newsgroup-cached
1270     gnus-newsgroup-data gnus-newsgroup-data-reverse
1271     gnus-newsgroup-limit gnus-newsgroup-limits
1272     gnus-newsgroup-charset gnus-newsgroup-display)
1273   "Variables that are buffer-local to the summary buffers.")
1274
1275 (defvar gnus-newsgroup-variables nil
1276   "A list of variables that have separate values in different newsgroups.
1277 A list of newsgroup (summary buffer) local variables, or cons of
1278 variables and their default values (when the default values are not
1279 nil), that should be made global while the summary buffer is active.
1280 These variables can be used to set variables in the group parameters
1281 while still allowing them to affect operations done in other
1282 buffers. For example:
1283
1284 \(setq gnus-newsgroup-variables
1285      '(message-use-followup-to
1286        (gnus-visible-headers .
1287          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1288 ")
1289
1290 ;; Byte-compiler warning.
1291 (eval-when-compile (defvar gnus-article-mode-map))
1292
1293 ;; MIME stuff.
1294
1295 (defvar gnus-decode-encoded-word-methods
1296   '(mail-decode-encoded-word-string)
1297   "List of methods used to decode encoded words.
1298
1299 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1300 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1301 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1302 whose names match REGEXP.
1303
1304 For example:
1305 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1306  mail-decode-encoded-word-string
1307  (\"chinese\" . rfc1843-decode-string))")
1308
1309 (defvar gnus-decode-encoded-word-methods-cache nil)
1310
1311 (defun gnus-multi-decode-encoded-word-string (string)
1312   "Apply the functions from `gnus-encoded-word-methods' that match."
1313   (unless (and gnus-decode-encoded-word-methods-cache
1314                (eq gnus-newsgroup-name
1315                    (car gnus-decode-encoded-word-methods-cache)))
1316     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1317     (mapcar (lambda (x)
1318               (if (symbolp x)
1319                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1320                 (if (and gnus-newsgroup-name
1321                          (string-match (car x) gnus-newsgroup-name))
1322                     (nconc gnus-decode-encoded-word-methods-cache
1323                            (list (cdr x))))))
1324             gnus-decode-encoded-word-methods))
1325   (let ((xlist gnus-decode-encoded-word-methods-cache))
1326     (pop xlist)
1327     (while xlist
1328       (setq string (funcall (pop xlist) string))))
1329   string)
1330
1331 ;; Subject simplification.
1332
1333 (defun gnus-simplify-whitespace (str)
1334   "Remove excessive whitespace from STR."
1335   (let ((mystr str))
1336     ;; Multiple spaces.
1337     (while (string-match "[ \t][ \t]+" mystr)
1338       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1339                           " "
1340                           (substring mystr (match-end 0)))))
1341     ;; Leading spaces.
1342     (when (string-match "^[ \t]+" mystr)
1343       (setq mystr (substring mystr (match-end 0))))
1344     ;; Trailing spaces.
1345     (when (string-match "[ \t]+$" mystr)
1346       (setq mystr (substring mystr 0 (match-beginning 0))))
1347     mystr))
1348
1349 (defsubst gnus-simplify-subject-re (subject)
1350   "Remove \"Re:\" from subject lines."
1351   (if (string-match message-subject-re-regexp subject)
1352       (substring subject (match-end 0))
1353     subject))
1354
1355 (defun gnus-simplify-subject (subject &optional re-only)
1356   "Remove `Re:' and words in parentheses.
1357 If RE-ONLY is non-nil, strip leading `Re:'s only."
1358   (let ((case-fold-search t))           ;Ignore case.
1359     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1360     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1361       (setq subject (substring subject (match-end 0))))
1362     ;; Remove uninteresting prefixes.
1363     (when (and (not re-only)
1364                gnus-simplify-ignored-prefixes
1365                (string-match gnus-simplify-ignored-prefixes subject))
1366       (setq subject (substring subject (match-end 0))))
1367     ;; Remove words in parentheses from end.
1368     (unless re-only
1369       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1370         (setq subject (substring subject 0 (match-beginning 0)))))
1371     ;; Return subject string.
1372     subject))
1373
1374 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1375 ;; all whitespace.
1376 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1377   (goto-char (point-min))
1378   (while (re-search-forward regexp nil t)
1379     (replace-match (or newtext ""))))
1380
1381 (defun gnus-simplify-buffer-fuzzy ()
1382   "Simplify string in the buffer fuzzily.
1383 The string in the accessible portion of the current buffer is simplified.
1384 It is assumed to be a single-line subject.
1385 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1386 matter is removed.  Additional things can be deleted by setting
1387 `gnus-simplify-subject-fuzzy-regexp'."
1388   (let ((case-fold-search t)
1389         (modified-tick))
1390     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1391
1392     (while (not (eq modified-tick (buffer-modified-tick)))
1393       (setq modified-tick (buffer-modified-tick))
1394       (cond
1395        ((listp gnus-simplify-subject-fuzzy-regexp)
1396         (mapcar 'gnus-simplify-buffer-fuzzy-step
1397                 gnus-simplify-subject-fuzzy-regexp))
1398        (gnus-simplify-subject-fuzzy-regexp
1399         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1400       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1401       (gnus-simplify-buffer-fuzzy-step
1402        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1403       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1404
1405     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1406     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1407     (gnus-simplify-buffer-fuzzy-step " $")
1408     (gnus-simplify-buffer-fuzzy-step "^ +")))
1409
1410 (defun gnus-simplify-subject-fuzzy (subject)
1411   "Simplify a subject string fuzzily.
1412 See `gnus-simplify-buffer-fuzzy' for details."
1413   (save-excursion
1414     (gnus-set-work-buffer)
1415     (let ((case-fold-search t))
1416       ;; Remove uninteresting prefixes.
1417       (when (and gnus-simplify-ignored-prefixes
1418                  (string-match gnus-simplify-ignored-prefixes subject))
1419         (setq subject (substring subject (match-end 0))))
1420       (insert subject)
1421       (inline (gnus-simplify-buffer-fuzzy))
1422       (buffer-string))))
1423
1424 (defsubst gnus-simplify-subject-fully (subject)
1425   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1426   (cond
1427    (gnus-simplify-subject-functions
1428     (gnus-map-function gnus-simplify-subject-functions subject))
1429    ((null gnus-summary-gather-subject-limit)
1430     (gnus-simplify-subject-re subject))
1431    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1432     (gnus-simplify-subject-fuzzy subject))
1433    ((numberp gnus-summary-gather-subject-limit)
1434     (gnus-limit-string (gnus-simplify-subject-re subject)
1435                        gnus-summary-gather-subject-limit))
1436    (t
1437     subject)))
1438
1439 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1440   "Check whether two subjects are equal.
1441 If optional argument simple-first is t, first argument is already
1442 simplified."
1443   (cond
1444    ((null simple-first)
1445     (equal (gnus-simplify-subject-fully s1)
1446            (gnus-simplify-subject-fully s2)))
1447    (t
1448     (equal s1
1449            (gnus-simplify-subject-fully s2)))))
1450
1451 (defun gnus-summary-bubble-group ()
1452   "Increase the score of the current group.
1453 This is a handy function to add to `gnus-summary-exit-hook' to
1454 increase the score of each group you read."
1455   (gnus-group-add-score gnus-newsgroup-name))
1456
1457 \f
1458 ;;;
1459 ;;; Gnus summary mode
1460 ;;;
1461
1462 (put 'gnus-summary-mode 'mode-class 'special)
1463
1464 (defvar gnus-article-commands-menu)
1465
1466 (when t
1467   ;; Non-orthogonal keys
1468
1469   (gnus-define-keys gnus-summary-mode-map
1470     " " gnus-summary-next-page
1471     "\177" gnus-summary-prev-page
1472     [delete] gnus-summary-prev-page
1473     [backspace] gnus-summary-prev-page
1474     "\r" gnus-summary-scroll-up
1475     "\M-\r" gnus-summary-scroll-down
1476     "n" gnus-summary-next-unread-article
1477     "p" gnus-summary-prev-unread-article
1478     "N" gnus-summary-next-article
1479     "P" gnus-summary-prev-article
1480     "\M-\C-n" gnus-summary-next-same-subject
1481     "\M-\C-p" gnus-summary-prev-same-subject
1482     "\M-n" gnus-summary-next-unread-subject
1483     "\M-p" gnus-summary-prev-unread-subject
1484     "." gnus-summary-first-unread-article
1485     "," gnus-summary-best-unread-article
1486     "\M-s" gnus-summary-search-article-forward
1487     "\M-r" gnus-summary-search-article-backward
1488     "<" gnus-summary-beginning-of-article
1489     ">" gnus-summary-end-of-article
1490     "j" gnus-summary-goto-article
1491     "^" gnus-summary-refer-parent-article
1492     "\M-^" gnus-summary-refer-article
1493     "u" gnus-summary-tick-article-forward
1494     "!" gnus-summary-tick-article-forward
1495     "U" gnus-summary-tick-article-backward
1496     "d" gnus-summary-mark-as-read-forward
1497     "D" gnus-summary-mark-as-read-backward
1498     "E" gnus-summary-mark-as-expirable
1499     "\M-u" gnus-summary-clear-mark-forward
1500     "\M-U" gnus-summary-clear-mark-backward
1501     "k" gnus-summary-kill-same-subject-and-select
1502     "\C-k" gnus-summary-kill-same-subject
1503     "\M-\C-k" gnus-summary-kill-thread
1504     "\M-\C-l" gnus-summary-lower-thread
1505     "e" gnus-summary-edit-article
1506     "#" gnus-summary-mark-as-processable
1507     "\M-#" gnus-summary-unmark-as-processable
1508     "\M-\C-t" gnus-summary-toggle-threads
1509     "\M-\C-s" gnus-summary-show-thread
1510     "\M-\C-h" gnus-summary-hide-thread
1511     "\M-\C-f" gnus-summary-next-thread
1512     "\M-\C-b" gnus-summary-prev-thread
1513     [(meta down)] gnus-summary-next-thread
1514     [(meta up)] gnus-summary-prev-thread
1515     "\M-\C-u" gnus-summary-up-thread
1516     "\M-\C-d" gnus-summary-down-thread
1517     "&" gnus-summary-execute-command
1518     "c" gnus-summary-catchup-and-exit
1519     "\C-w" gnus-summary-mark-region-as-read
1520     "\C-t" gnus-summary-toggle-truncation
1521     "?" gnus-summary-mark-as-dormant
1522     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1523     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1524     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1525     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1526     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1527     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1528     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1529     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1530     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1531     "=" gnus-summary-expand-window
1532     "\C-x\C-s" gnus-summary-reselect-current-group
1533     "\M-g" gnus-summary-rescan-group
1534     "w" gnus-summary-stop-page-breaking
1535     "\C-c\C-r" gnus-summary-caesar-message
1536     "f" gnus-summary-followup
1537     "F" gnus-summary-followup-with-original
1538     "C" gnus-summary-cancel-article
1539     "r" gnus-summary-reply
1540     "R" gnus-summary-reply-with-original
1541     "\C-c\C-f" gnus-summary-mail-forward
1542     "o" gnus-summary-save-article
1543     "\C-o" gnus-summary-save-article-mail
1544     "|" gnus-summary-pipe-output
1545     "\M-k" gnus-summary-edit-local-kill
1546     "\M-K" gnus-summary-edit-global-kill
1547     ;; "V" gnus-version
1548     "\C-c\C-d" gnus-summary-describe-group
1549     "q" gnus-summary-exit
1550     "Q" gnus-summary-exit-no-update
1551     "\C-c\C-i" gnus-info-find-node
1552     gnus-mouse-2 gnus-mouse-pick-article
1553     "m" gnus-summary-mail-other-window
1554     "a" gnus-summary-post-news
1555     "i" gnus-summary-news-other-window
1556     "x" gnus-summary-limit-to-unread
1557     "s" gnus-summary-isearch-article
1558     "t" gnus-summary-toggle-header
1559     "g" gnus-summary-show-article
1560     "l" gnus-summary-goto-last-article
1561     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1562     "\C-d" gnus-summary-enter-digest-group
1563     "\M-\C-d" gnus-summary-read-document
1564     "\M-\C-e" gnus-summary-edit-parameters
1565     "\M-\C-a" gnus-summary-customize-parameters
1566     "\C-c\C-b" gnus-bug
1567     "*" gnus-cache-enter-article
1568     "\M-*" gnus-cache-remove-article
1569     "\M-&" gnus-summary-universal-argument
1570     "\C-l" gnus-recenter
1571     "I" gnus-summary-increase-score
1572     "L" gnus-summary-lower-score
1573     "\M-i" gnus-symbolic-argument
1574     "h" gnus-summary-select-article-buffer
1575
1576     "b" gnus-article-view-part
1577     "\M-t" gnus-summary-toggle-display-buttonized
1578
1579     "V" gnus-summary-score-map
1580     "X" gnus-uu-extract-map
1581     "S" gnus-summary-send-map)
1582
1583   ;; Sort of orthogonal keymap
1584   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1585     "t" gnus-summary-tick-article-forward
1586     "!" gnus-summary-tick-article-forward
1587     "d" gnus-summary-mark-as-read-forward
1588     "r" gnus-summary-mark-as-read-forward
1589     "c" gnus-summary-clear-mark-forward
1590     " " gnus-summary-clear-mark-forward
1591     "e" gnus-summary-mark-as-expirable
1592     "x" gnus-summary-mark-as-expirable
1593     "?" gnus-summary-mark-as-dormant
1594     "b" gnus-summary-set-bookmark
1595     "B" gnus-summary-remove-bookmark
1596     "#" gnus-summary-mark-as-processable
1597     "\M-#" gnus-summary-unmark-as-processable
1598     "S" gnus-summary-limit-include-expunged
1599     "C" gnus-summary-catchup
1600     "H" gnus-summary-catchup-to-here
1601     "h" gnus-summary-catchup-from-here
1602     "\C-c" gnus-summary-catchup-all
1603     "k" gnus-summary-kill-same-subject-and-select
1604     "K" gnus-summary-kill-same-subject
1605     "P" gnus-uu-mark-map)
1606
1607   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1608     "c" gnus-summary-clear-above
1609     "u" gnus-summary-tick-above
1610     "m" gnus-summary-mark-above
1611     "k" gnus-summary-kill-below)
1612
1613   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1614     "/" gnus-summary-limit-to-subject
1615     "n" gnus-summary-limit-to-articles
1616     "w" gnus-summary-pop-limit
1617     "s" gnus-summary-limit-to-subject
1618     "a" gnus-summary-limit-to-author
1619     "u" gnus-summary-limit-to-unread
1620     "m" gnus-summary-limit-to-marks
1621     "M" gnus-summary-limit-exclude-marks
1622     "v" gnus-summary-limit-to-score
1623     "*" gnus-summary-limit-include-cached
1624     "D" gnus-summary-limit-include-dormant
1625     "T" gnus-summary-limit-include-thread
1626     "d" gnus-summary-limit-exclude-dormant
1627     "t" gnus-summary-limit-to-age
1628     "x" gnus-summary-limit-to-extra
1629     "p" gnus-summary-limit-to-display-predicate
1630     "E" gnus-summary-limit-include-expunged
1631     "c" gnus-summary-limit-exclude-childless-dormant
1632     "C" gnus-summary-limit-mark-excluded-as-read
1633     "o" gnus-summary-insert-old-articles
1634     "N" gnus-summary-insert-new-articles)
1635
1636   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1637     "n" gnus-summary-next-unread-article
1638     "p" gnus-summary-prev-unread-article
1639     "N" gnus-summary-next-article
1640     "P" gnus-summary-prev-article
1641     "\C-n" gnus-summary-next-same-subject
1642     "\C-p" gnus-summary-prev-same-subject
1643     "\M-n" gnus-summary-next-unread-subject
1644     "\M-p" gnus-summary-prev-unread-subject
1645     "f" gnus-summary-first-unread-article
1646     "b" gnus-summary-best-unread-article
1647     "j" gnus-summary-goto-article
1648     "g" gnus-summary-goto-subject
1649     "l" gnus-summary-goto-last-article
1650     "o" gnus-summary-pop-article)
1651
1652   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1653     "k" gnus-summary-kill-thread
1654     "l" gnus-summary-lower-thread
1655     "i" gnus-summary-raise-thread
1656     "T" gnus-summary-toggle-threads
1657     "t" gnus-summary-rethread-current
1658     "^" gnus-summary-reparent-thread
1659     "s" gnus-summary-show-thread
1660     "S" gnus-summary-show-all-threads
1661     "h" gnus-summary-hide-thread
1662     "H" gnus-summary-hide-all-threads
1663     "n" gnus-summary-next-thread
1664     "p" gnus-summary-prev-thread
1665     "u" gnus-summary-up-thread
1666     "o" gnus-summary-top-thread
1667     "d" gnus-summary-down-thread
1668     "#" gnus-uu-mark-thread
1669     "\M-#" gnus-uu-unmark-thread)
1670
1671   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1672     "g" gnus-summary-prepare
1673     "c" gnus-summary-insert-cached-articles)
1674
1675   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1676     "c" gnus-summary-catchup-and-exit
1677     "C" gnus-summary-catchup-all-and-exit
1678     "E" gnus-summary-exit-no-update
1679     "Q" gnus-summary-exit
1680     "Z" gnus-summary-exit
1681     "n" gnus-summary-catchup-and-goto-next-group
1682     "R" gnus-summary-reselect-current-group
1683     "G" gnus-summary-rescan-group
1684     "N" gnus-summary-next-group
1685     "s" gnus-summary-save-newsrc
1686     "P" gnus-summary-prev-group)
1687
1688   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1689     " " gnus-summary-next-page
1690     "n" gnus-summary-next-page
1691     "\177" gnus-summary-prev-page
1692     [delete] gnus-summary-prev-page
1693     "p" gnus-summary-prev-page
1694     "\r" gnus-summary-scroll-up
1695     "\M-\r" gnus-summary-scroll-down
1696     "<" gnus-summary-beginning-of-article
1697     ">" gnus-summary-end-of-article
1698     "b" gnus-summary-beginning-of-article
1699     "e" gnus-summary-end-of-article
1700     "^" gnus-summary-refer-parent-article
1701     "r" gnus-summary-refer-parent-article
1702     "D" gnus-summary-enter-digest-group
1703     "R" gnus-summary-refer-references
1704     "T" gnus-summary-refer-thread
1705     "g" gnus-summary-show-article
1706     "s" gnus-summary-isearch-article
1707     "P" gnus-summary-print-article
1708     "M" gnus-mailing-list-insinuate
1709     "t" gnus-article-babel)
1710
1711   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1712     "b" gnus-article-add-buttons
1713     "B" gnus-article-add-buttons-to-head
1714     "o" gnus-article-treat-overstrike
1715     "e" gnus-article-emphasize
1716     "w" gnus-article-fill-cited-article
1717     "Q" gnus-article-fill-long-lines
1718     "C" gnus-article-capitalize-sentences
1719     "c" gnus-article-remove-cr
1720     "q" gnus-article-de-quoted-unreadable
1721     "6" gnus-article-de-base64-unreadable
1722     "Z" gnus-article-decode-HZ
1723     "h" gnus-article-wash-html
1724     "s" gnus-summary-force-verify-and-decrypt
1725     "f" gnus-article-display-x-face
1726     "l" gnus-summary-stop-page-breaking
1727     "r" gnus-summary-caesar-message
1728     "t" gnus-summary-toggle-header
1729     "g" gnus-treat-smiley
1730     "v" gnus-summary-verbose-headers
1731     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1732     "p" gnus-article-verify-x-pgp-sig
1733     "d" gnus-article-treat-dumbquotes)
1734
1735   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1736     "a" gnus-article-hide
1737     "h" gnus-article-hide-headers
1738     "b" gnus-article-hide-boring-headers
1739     "s" gnus-article-hide-signature
1740     "c" gnus-article-hide-citation
1741     "C" gnus-article-hide-citation-in-followups
1742     "l" gnus-article-hide-list-identifiers
1743     "p" gnus-article-hide-pgp
1744     "B" gnus-article-strip-banner
1745     "P" gnus-article-hide-pem
1746     "\C-c" gnus-article-hide-citation-maybe)
1747
1748   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1749     "a" gnus-article-highlight
1750     "h" gnus-article-highlight-headers
1751     "c" gnus-article-highlight-citation
1752     "s" gnus-article-highlight-signature)
1753
1754   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1755     "f" gnus-article-treat-fold-headers
1756     "u" gnus-article-treat-unfold-headers
1757     "n" gnus-article-treat-fold-newsgroups)
1758
1759   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1760     "x" gnus-article-display-x-face
1761     "s" gnus-treat-smiley
1762     "D" gnus-article-remove-images
1763     "f" gnus-treat-from-picon
1764     "m" gnus-treat-mail-picon
1765     "n" gnus-treat-newsgroups-picon)
1766
1767   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1768     "w" gnus-article-decode-mime-words
1769     "c" gnus-article-decode-charset
1770     "v" gnus-mime-view-all-parts
1771     "b" gnus-article-view-part)
1772
1773   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1774     "z" gnus-article-date-ut
1775     "u" gnus-article-date-ut
1776     "l" gnus-article-date-local
1777     "p" gnus-article-date-english
1778     "e" gnus-article-date-lapsed
1779     "o" gnus-article-date-original
1780     "i" gnus-article-date-iso8601
1781     "s" gnus-article-date-user)
1782
1783   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1784     "t" gnus-article-remove-trailing-blank-lines
1785     "l" gnus-article-strip-leading-blank-lines
1786     "m" gnus-article-strip-multiple-blank-lines
1787     "a" gnus-article-strip-blank-lines
1788     "A" gnus-article-strip-all-blank-lines
1789     "s" gnus-article-strip-leading-space
1790     "e" gnus-article-strip-trailing-space
1791     "w" gnus-article-remove-leading-whitespace)
1792
1793   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1794     "v" gnus-version
1795     "f" gnus-summary-fetch-faq
1796     "d" gnus-summary-describe-group
1797     "h" gnus-summary-describe-briefly
1798     "i" gnus-info-find-node)
1799
1800   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1801     "e" gnus-summary-expire-articles
1802     "\M-\C-e" gnus-summary-expire-articles-now
1803     "\177" gnus-summary-delete-article
1804     [delete] gnus-summary-delete-article
1805     [backspace] gnus-summary-delete-article
1806     "m" gnus-summary-move-article
1807     "r" gnus-summary-respool-article
1808     "w" gnus-summary-edit-article
1809     "c" gnus-summary-copy-article
1810     "B" gnus-summary-crosspost-article
1811     "q" gnus-summary-respool-query
1812     "t" gnus-summary-respool-trace
1813     "i" gnus-summary-import-article
1814     "I" gnus-summary-create-article
1815     "p" gnus-summary-article-posted-p)
1816
1817   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1818     "o" gnus-summary-save-article
1819     "m" gnus-summary-save-article-mail
1820     "F" gnus-summary-write-article-file
1821     "r" gnus-summary-save-article-rmail
1822     "f" gnus-summary-save-article-file
1823     "b" gnus-summary-save-article-body-file
1824     "h" gnus-summary-save-article-folder
1825     "v" gnus-summary-save-article-vm
1826     "p" gnus-summary-pipe-output
1827     "P" gnus-summary-muttprint
1828     "s" gnus-soup-add-article)
1829
1830   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1831     "b" gnus-summary-display-buttonized
1832     "m" gnus-summary-repair-multipart
1833     "v" gnus-article-view-part
1834     "o" gnus-article-save-part
1835     "c" gnus-article-copy-part
1836     "C" gnus-article-view-part-as-charset
1837     "e" gnus-article-externalize-part
1838     "E" gnus-article-encrypt-body
1839     "i" gnus-article-inline-part
1840     "|" gnus-article-pipe-part))
1841
1842 (defvar gnus-article-post-menu nil)
1843
1844 (defun gnus-summary-make-menu-bar ()
1845   (gnus-turn-off-edit-menu 'summary)
1846
1847   (unless (boundp 'gnus-summary-misc-menu)
1848
1849     (easy-menu-define
1850       gnus-summary-kill-menu gnus-summary-mode-map ""
1851       (cons
1852        "Score"
1853        (nconc
1854         (list
1855          ["Customize" gnus-score-customize t])
1856         (gnus-make-score-map 'increase)
1857         (gnus-make-score-map 'lower)
1858         '(("Mark"
1859            ["Kill below" gnus-summary-kill-below t]
1860            ["Mark above" gnus-summary-mark-above t]
1861            ["Tick above" gnus-summary-tick-above t]
1862            ["Clear above" gnus-summary-clear-above t])
1863           ["Current score" gnus-summary-current-score t]
1864           ["Set score" gnus-summary-set-score t]
1865           ["Switch current score file..." gnus-score-change-score-file t]
1866           ["Set mark below..." gnus-score-set-mark-below t]
1867           ["Set expunge below..." gnus-score-set-expunge-below t]
1868           ["Edit current score file" gnus-score-edit-current-scores t]
1869           ["Edit score file" gnus-score-edit-file t]
1870           ["Trace score" gnus-score-find-trace t]
1871           ["Find words" gnus-score-find-favourite-words t]
1872           ["Rescore buffer" gnus-summary-rescore t]
1873           ["Increase score..." gnus-summary-increase-score t]
1874           ["Lower score..." gnus-summary-lower-score t]))))
1875
1876     ;; Define both the Article menu in the summary buffer and the
1877     ;; equivalent Commands menu in the article buffer here for
1878     ;; consistency.
1879     (let ((innards
1880            `(("Hide"
1881               ["All" gnus-article-hide t]
1882               ["Headers" gnus-article-hide-headers t]
1883               ["Signature" gnus-article-hide-signature t]
1884               ["Citation" gnus-article-hide-citation t]
1885               ["List identifiers" gnus-article-hide-list-identifiers t]
1886               ["PGP" gnus-article-hide-pgp t]
1887               ["Banner" gnus-article-strip-banner t]
1888               ["Boring headers" gnus-article-hide-boring-headers t])
1889              ("Highlight"
1890               ["All" gnus-article-highlight t]
1891               ["Headers" gnus-article-highlight-headers t]
1892               ["Signature" gnus-article-highlight-signature t]
1893               ["Citation" gnus-article-highlight-citation t])
1894              ("MIME"
1895               ["Words" gnus-article-decode-mime-words t]
1896               ["Charset" gnus-article-decode-charset t]
1897               ["QP" gnus-article-de-quoted-unreadable t]
1898               ["Base64" gnus-article-de-base64-unreadable t]
1899               ["View all" gnus-mime-view-all-parts t]
1900               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1901               ["Encrypt body" gnus-article-encrypt-body t])
1902              ("Date"
1903               ["Local" gnus-article-date-local t]
1904               ["ISO8601" gnus-article-date-iso8601 t]
1905               ["UT" gnus-article-date-ut t]
1906               ["Original" gnus-article-date-original t]
1907               ["Lapsed" gnus-article-date-lapsed t]
1908               ["User-defined" gnus-article-date-user t])
1909              ("Display"
1910               ["Remove images" gnus-article-remove-images t]
1911               ["Toggle smiley" gnus-treat-smiley t]
1912               ["Show X-Face" gnus-article-display-x-face t]
1913               ["Show picons in From" gnus-treat-from-picon t]
1914               ["Show picons in mail headers" gnus-treat-mail-picon t]
1915               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1916              ("Washing"
1917               ("Remove Blanks"
1918                ["Leading" gnus-article-strip-leading-blank-lines t]
1919                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1920                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1921                ["All of the above" gnus-article-strip-blank-lines t]
1922                ["All" gnus-article-strip-all-blank-lines t]
1923                ["Leading space" gnus-article-strip-leading-space t]
1924                ["Trailing space" gnus-article-strip-trailing-space t]
1925                ["Leading space in headers"
1926                 gnus-article-remove-leading-whitespace t])
1927               ["Overstrike" gnus-article-treat-overstrike t]
1928               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1929               ["Emphasis" gnus-article-emphasize t]
1930               ["Word wrap" gnus-article-fill-cited-article t]
1931               ["Fill long lines" gnus-article-fill-long-lines t]
1932               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1933               ["CR" gnus-article-remove-cr t]
1934               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1935               ["Base64" gnus-article-de-base64-unreadable t]
1936               ["Rot 13" gnus-summary-caesar-message
1937                ,@(if (featurep 'xemacs) '(t)
1938                    '(:help "\"Caesar rotate\" article by 13"))]
1939               ["Unix pipe" gnus-summary-pipe-message t]
1940               ["Add buttons" gnus-article-add-buttons t]
1941               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1942               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1943               ["Verbose header" gnus-summary-verbose-headers t]
1944               ["Toggle header" gnus-summary-toggle-header t]
1945               ["Unfold headers" gnus-article-treat-unfold-headers t]
1946               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1947               ["Html" gnus-article-wash-html t]
1948               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1949               ["HZ" gnus-article-decode-HZ t])
1950              ("Output"
1951               ["Save in default format" gnus-summary-save-article
1952                ,@(if (featurep 'xemacs) '(t)
1953                    '(:help "Save article using default method"))]
1954               ["Save in file" gnus-summary-save-article-file
1955                ,@(if (featurep 'xemacs) '(t)
1956                    '(:help "Save article in file"))]
1957               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1958               ["Save in MH folder" gnus-summary-save-article-folder t]
1959               ["Save in VM folder" gnus-summary-save-article-vm t]
1960               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1961               ["Save body in file" gnus-summary-save-article-body-file t]
1962               ["Pipe through a filter" gnus-summary-pipe-output t]
1963               ["Add to SOUP packet" gnus-soup-add-article t]
1964               ["Print with Muttprint" gnus-summary-muttprint t]
1965               ["Print" gnus-summary-print-article t])
1966              ("Backend"
1967               ["Respool article..." gnus-summary-respool-article t]
1968               ["Move article..." gnus-summary-move-article
1969                (gnus-check-backend-function
1970                 'request-move-article gnus-newsgroup-name)]
1971               ["Copy article..." gnus-summary-copy-article t]
1972               ["Crosspost article..." gnus-summary-crosspost-article
1973                (gnus-check-backend-function
1974                 'request-replace-article gnus-newsgroup-name)]
1975               ["Import file..." gnus-summary-import-article t]
1976               ["Create article..." gnus-summary-create-article t]
1977               ["Check if posted" gnus-summary-article-posted-p t]
1978               ["Edit article" gnus-summary-edit-article
1979                (not (gnus-group-read-only-p))]
1980               ["Delete article" gnus-summary-delete-article
1981                (gnus-check-backend-function
1982                 'request-expire-articles gnus-newsgroup-name)]
1983               ["Query respool" gnus-summary-respool-query t]
1984               ["Trace respool" gnus-summary-respool-trace t]
1985               ["Delete expirable articles" gnus-summary-expire-articles-now
1986                (gnus-check-backend-function
1987                 'request-expire-articles gnus-newsgroup-name)])
1988              ("Extract"
1989               ["Uudecode" gnus-uu-decode-uu
1990                ,@(if (featurep 'xemacs) '(t)
1991                    '(:help "Decode uuencoded article(s)"))]
1992               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1993               ["Unshar" gnus-uu-decode-unshar t]
1994               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1995               ["Save" gnus-uu-decode-save t]
1996               ["Binhex" gnus-uu-decode-binhex t]
1997               ["Postscript" gnus-uu-decode-postscript t])
1998              ("Cache"
1999               ["Enter article" gnus-cache-enter-article t]
2000               ["Remove article" gnus-cache-remove-article t])
2001              ["Translate" gnus-article-babel t]
2002              ["Select article buffer" gnus-summary-select-article-buffer t]
2003              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2004              ["Isearch article..." gnus-summary-isearch-article t]
2005              ["Beginning of the article" gnus-summary-beginning-of-article t]
2006              ["End of the article" gnus-summary-end-of-article t]
2007              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2008              ["Fetch referenced articles" gnus-summary-refer-references t]
2009              ["Fetch current thread" gnus-summary-refer-thread t]
2010              ["Fetch article with id..." gnus-summary-refer-article t]
2011              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2012              ["Redisplay" gnus-summary-show-article t]
2013              ["Raw article" gnus-summary-show-raw-article t])))
2014       (easy-menu-define
2015         gnus-summary-article-menu gnus-summary-mode-map ""
2016         (cons "Article" innards))
2017
2018       (if (not (keymapp gnus-summary-article-menu))
2019           (easy-menu-define
2020             gnus-article-commands-menu gnus-article-mode-map ""
2021             (cons "Commands" innards))
2022         ;; in Emacs, don't share menu.
2023         (setq gnus-article-commands-menu
2024               (copy-keymap gnus-summary-article-menu))
2025         (define-key gnus-article-mode-map [menu-bar commands]
2026           (cons "Commands" gnus-article-commands-menu))))
2027
2028     (easy-menu-define
2029       gnus-summary-thread-menu gnus-summary-mode-map ""
2030       '("Threads"
2031         ["Toggle threading" gnus-summary-toggle-threads t]
2032         ["Hide threads" gnus-summary-hide-all-threads t]
2033         ["Show threads" gnus-summary-show-all-threads t]
2034         ["Hide thread" gnus-summary-hide-thread t]
2035         ["Show thread" gnus-summary-show-thread t]
2036         ["Go to next thread" gnus-summary-next-thread t]
2037         ["Go to previous thread" gnus-summary-prev-thread t]
2038         ["Go down thread" gnus-summary-down-thread t]
2039         ["Go up thread" gnus-summary-up-thread t]
2040         ["Top of thread" gnus-summary-top-thread t]
2041         ["Mark thread as read" gnus-summary-kill-thread t]
2042         ["Lower thread score" gnus-summary-lower-thread t]
2043         ["Raise thread score" gnus-summary-raise-thread t]
2044         ["Rethread current" gnus-summary-rethread-current t]))
2045
2046     (easy-menu-define
2047       gnus-summary-post-menu gnus-summary-mode-map ""
2048       `("Post"
2049         ["Send a message (mail or news)" gnus-summary-post-news
2050          ,@(if (featurep 'xemacs) '(t)
2051              '(:help "Post an article"))]
2052         ["Followup" gnus-summary-followup
2053          ,@(if (featurep 'xemacs) '(t)
2054              '(:help "Post followup to this article"))]
2055         ["Followup and yank" gnus-summary-followup-with-original
2056          ,@(if (featurep 'xemacs) '(t)
2057              '(:help "Post followup to this article, quoting its contents"))]
2058         ["Supersede article" gnus-summary-supersede-article t]
2059         ["Cancel article" gnus-summary-cancel-article
2060          ,@(if (featurep 'xemacs) '(t)
2061              '(:help "Cancel an article you posted"))]
2062         ["Reply" gnus-summary-reply t]
2063         ["Reply and yank" gnus-summary-reply-with-original t]
2064         ["Wide reply" gnus-summary-wide-reply t]
2065         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2066          ,@(if (featurep 'xemacs) '(t)
2067              '(:help "Mail a reply, quoting this article"))]
2068         ["Mail forward" gnus-summary-mail-forward t]
2069         ["Post forward" gnus-summary-post-forward t]
2070         ["Digest and mail" gnus-uu-digest-mail-forward t]
2071         ["Digest and post" gnus-uu-digest-post-forward t]
2072         ["Resend message" gnus-summary-resend-message t]
2073         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2074         ["Send a mail" gnus-summary-mail-other-window t]
2075         ["Create a local message" gnus-summary-news-other-window t]
2076         ["Uuencode and post" gnus-uu-post-news
2077          ,@(if (featurep 'xemacs) '(t)
2078              '(:help "Post a uuencoded article"))]
2079         ["Followup via news" gnus-summary-followup-to-mail t]
2080         ["Followup via news and yank"
2081          gnus-summary-followup-to-mail-with-original t]
2082         ;;("Draft"
2083         ;;["Send" gnus-summary-send-draft t]
2084         ;;["Send bounced" gnus-resend-bounced-mail t])
2085         ))
2086
2087     (cond
2088      ((not (keymapp gnus-summary-post-menu))
2089       (setq gnus-article-post-menu gnus-summary-post-menu))
2090      ((not gnus-article-post-menu)
2091       ;; Don't share post menu.
2092       (setq gnus-article-post-menu
2093             (copy-keymap gnus-summary-post-menu))))
2094     (define-key gnus-article-mode-map [menu-bar post]
2095       (cons "Post" gnus-article-post-menu))
2096
2097     (easy-menu-define
2098       gnus-summary-misc-menu gnus-summary-mode-map ""
2099       `("Gnus"
2100         ("Mark Read"
2101          ["Mark as read" gnus-summary-mark-as-read-forward t]
2102          ["Mark same subject and select"
2103           gnus-summary-kill-same-subject-and-select t]
2104          ["Mark same subject" gnus-summary-kill-same-subject t]
2105          ["Catchup" gnus-summary-catchup
2106           ,@(if (featurep 'xemacs) '(t)
2107               '(:help "Mark unread articles in this group as read"))]
2108          ["Catchup all" gnus-summary-catchup-all t]
2109          ["Catchup to here" gnus-summary-catchup-to-here t]
2110          ["Catchup from here" gnus-summary-catchup-from-here t]
2111          ["Catchup region" gnus-summary-mark-region-as-read t]
2112          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2113         ("Mark Various"
2114          ["Tick" gnus-summary-tick-article-forward t]
2115          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2116          ["Remove marks" gnus-summary-clear-mark-forward t]
2117          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2118          ["Set bookmark" gnus-summary-set-bookmark t]
2119          ["Remove bookmark" gnus-summary-remove-bookmark t])
2120         ("Limit to"
2121          ["Marks..." gnus-summary-limit-to-marks t]
2122          ["Subject..." gnus-summary-limit-to-subject t]
2123          ["Author..." gnus-summary-limit-to-author t]
2124          ["Age..." gnus-summary-limit-to-age t]
2125          ["Extra..." gnus-summary-limit-to-extra t]
2126          ["Score" gnus-summary-limit-to-score t]
2127          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2128          ["Unread" gnus-summary-limit-to-unread t]
2129          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2130          ["Articles" gnus-summary-limit-to-articles t]
2131          ["Pop limit" gnus-summary-pop-limit t]
2132          ["Show dormant" gnus-summary-limit-include-dormant t]
2133          ["Hide childless dormant"
2134           gnus-summary-limit-exclude-childless-dormant t]
2135          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2136          ["Hide marked" gnus-summary-limit-exclude-marks t]
2137          ["Show expunged" gnus-summary-limit-include-expunged t])
2138         ("Process Mark"
2139          ["Set mark" gnus-summary-mark-as-processable t]
2140          ["Remove mark" gnus-summary-unmark-as-processable t]
2141          ["Remove all marks" gnus-summary-unmark-all-processable t]
2142          ["Mark above" gnus-uu-mark-over t]
2143          ["Mark series" gnus-uu-mark-series t]
2144          ["Mark region" gnus-uu-mark-region t]
2145          ["Unmark region" gnus-uu-unmark-region t]
2146          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2147          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2148          ["Mark all" gnus-uu-mark-all t]
2149          ["Mark buffer" gnus-uu-mark-buffer t]
2150          ["Mark sparse" gnus-uu-mark-sparse t]
2151          ["Mark thread" gnus-uu-mark-thread t]
2152          ["Unmark thread" gnus-uu-unmark-thread t]
2153          ("Process Mark Sets"
2154           ["Kill" gnus-summary-kill-process-mark t]
2155           ["Yank" gnus-summary-yank-process-mark
2156            gnus-newsgroup-process-stack]
2157           ["Save" gnus-summary-save-process-mark t]))
2158         ("Scroll article"
2159          ["Page forward" gnus-summary-next-page
2160           ,@(if (featurep 'xemacs) '(t)
2161               '(:help "Show next page of article"))]
2162          ["Page backward" gnus-summary-prev-page
2163           ,@(if (featurep 'xemacs) '(t)
2164               '(:help "Show previous page of article"))]
2165          ["Line forward" gnus-summary-scroll-up t])
2166         ("Move"
2167          ["Next unread article" gnus-summary-next-unread-article t]
2168          ["Previous unread article" gnus-summary-prev-unread-article t]
2169          ["Next article" gnus-summary-next-article t]
2170          ["Previous article" gnus-summary-prev-article t]
2171          ["Next unread subject" gnus-summary-next-unread-subject t]
2172          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2173          ["Next article same subject" gnus-summary-next-same-subject t]
2174          ["Previous article same subject" gnus-summary-prev-same-subject t]
2175          ["First unread article" gnus-summary-first-unread-article t]
2176          ["Best unread article" gnus-summary-best-unread-article t]
2177          ["Go to subject number..." gnus-summary-goto-subject t]
2178          ["Go to article number..." gnus-summary-goto-article t]
2179          ["Go to the last article" gnus-summary-goto-last-article t]
2180          ["Pop article off history" gnus-summary-pop-article t])
2181         ("Sort"
2182          ["Sort by number" gnus-summary-sort-by-number t]
2183          ["Sort by author" gnus-summary-sort-by-author t]
2184          ["Sort by subject" gnus-summary-sort-by-subject t]
2185          ["Sort by date" gnus-summary-sort-by-date t]
2186          ["Sort by score" gnus-summary-sort-by-score t]
2187          ["Sort by lines" gnus-summary-sort-by-lines t]
2188          ["Sort by characters" gnus-summary-sort-by-chars t]
2189          ["Original sort" gnus-summary-sort-by-original t])
2190         ("Help"
2191          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2192          ["Describe group" gnus-summary-describe-group t]
2193          ["Read manual" gnus-info-find-node t])
2194         ("Modes"
2195          ["Pick and read" gnus-pick-mode t]
2196          ["Binary" gnus-binary-mode t])
2197         ("Regeneration"
2198          ["Regenerate" gnus-summary-prepare t]
2199          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2200          ["Toggle threading" gnus-summary-toggle-threads t])
2201         ["See old articles" gnus-summary-insert-old-articles t]
2202         ["See new articles" gnus-summary-insert-new-articles t]
2203         ["Filter articles..." gnus-summary-execute-command t]
2204         ["Run command on subjects..." gnus-summary-universal-argument t]
2205         ["Search articles forward..." gnus-summary-search-article-forward t]
2206         ["Search articles backward..." gnus-summary-search-article-backward t]
2207         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2208         ["Expand window" gnus-summary-expand-window t]
2209         ["Expire expirable articles" gnus-summary-expire-articles
2210          (gnus-check-backend-function
2211           'request-expire-articles gnus-newsgroup-name)]
2212         ["Edit local kill file" gnus-summary-edit-local-kill t]
2213         ["Edit main kill file" gnus-summary-edit-global-kill t]
2214         ["Edit group parameters" gnus-summary-edit-parameters t]
2215         ["Customize group parameters" gnus-summary-customize-parameters t]
2216         ["Send a bug report" gnus-bug t]
2217         ("Exit"
2218          ["Catchup and exit" gnus-summary-catchup-and-exit
2219           ,@(if (featurep 'xemacs) '(t)
2220               '(:help "Mark unread articles in this group as read, then exit"))]
2221          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2222          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2223          ["Exit group" gnus-summary-exit
2224           ,@(if (featurep 'xemacs) '(t)
2225               '(:help "Exit current group, return to group selection mode"))]
2226          ["Exit group without updating" gnus-summary-exit-no-update t]
2227          ["Exit and goto next group" gnus-summary-next-group t]
2228          ["Exit and goto prev group" gnus-summary-prev-group t]
2229          ["Reselect group" gnus-summary-reselect-current-group t]
2230          ["Rescan group" gnus-summary-rescan-group t]
2231          ["Update dribble" gnus-summary-save-newsrc t])))
2232
2233     (gnus-run-hooks 'gnus-summary-menu-hook)))
2234
2235 (defvar gnus-summary-tool-bar-map nil)
2236
2237 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2238 (defun gnus-summary-make-tool-bar ()
2239   (if (and (fboundp 'tool-bar-add-item-from-menu)
2240            (default-value 'tool-bar-mode)
2241            (not gnus-summary-tool-bar-map))
2242       (setq gnus-summary-tool-bar-map
2243             (let ((tool-bar-map (make-sparse-keymap))
2244                   (load-path (mm-image-load-path)))
2245               (tool-bar-add-item-from-menu
2246                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2247               (tool-bar-add-item-from-menu
2248                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2249               (tool-bar-add-item-from-menu
2250                'gnus-summary-post-news "post" gnus-summary-mode-map)
2251               (tool-bar-add-item-from-menu
2252                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2253               (tool-bar-add-item-from-menu
2254                'gnus-summary-followup "followup" gnus-summary-mode-map)
2255               (tool-bar-add-item-from-menu
2256                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2257               (tool-bar-add-item-from-menu
2258                'gnus-summary-reply "reply" gnus-summary-mode-map)
2259               (tool-bar-add-item-from-menu
2260                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2261               (tool-bar-add-item-from-menu
2262                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2263               (tool-bar-add-item-from-menu
2264                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2265               (tool-bar-add-item-from-menu
2266                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2267               (tool-bar-add-item-from-menu
2268                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2269               (tool-bar-add-item-from-menu
2270                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2271               (tool-bar-add-item-from-menu
2272                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2273               (tool-bar-add-item-from-menu
2274                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2275               tool-bar-map)))
2276   (if gnus-summary-tool-bar-map
2277       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2278
2279 (defun gnus-score-set-default (var value)
2280   "A version of set that updates the GNU Emacs menu-bar."
2281   (set var value)
2282   ;; It is the message that forces the active status to be updated.
2283   (message ""))
2284
2285 (defun gnus-make-score-map (type)
2286   "Make a summary score map of type TYPE."
2287   (if t
2288       nil
2289     (let ((headers '(("author" "from" string)
2290                      ("subject" "subject" string)
2291                      ("article body" "body" string)
2292                      ("article head" "head" string)
2293                      ("xref" "xref" string)
2294                      ("extra header" "extra" string)
2295                      ("lines" "lines" number)
2296                      ("followups to author" "followup" string)))
2297           (types '((number ("less than" <)
2298                            ("greater than" >)
2299                            ("equal" =))
2300                    (string ("substring" s)
2301                            ("exact string" e)
2302                            ("fuzzy string" f)
2303                            ("regexp" r))))
2304           (perms '(("temporary" (current-time-string))
2305                    ("permanent" nil)
2306                    ("immediate" now)))
2307           header)
2308       (list
2309        (apply
2310         'nconc
2311         (list
2312          (if (eq type 'lower)
2313              "Lower score"
2314            "Increase score"))
2315         (let (outh)
2316           (while headers
2317             (setq header (car headers))
2318             (setq outh
2319                   (cons
2320                    (apply
2321                     'nconc
2322                     (list (car header))
2323                     (let ((ts (cdr (assoc (nth 2 header) types)))
2324                           outt)
2325                       (while ts
2326                         (setq outt
2327                               (cons
2328                                (apply
2329                                 'nconc
2330                                 (list (caar ts))
2331                                 (let ((ps perms)
2332                                       outp)
2333                                   (while ps
2334                                     (setq outp
2335                                           (cons
2336                                            (vector
2337                                             (caar ps)
2338                                             (list
2339                                              'gnus-summary-score-entry
2340                                              (nth 1 header)
2341                                              (if (or (string= (nth 1 header)
2342                                                               "head")
2343                                                      (string= (nth 1 header)
2344                                                               "body"))
2345                                                  ""
2346                                                (list 'gnus-summary-header
2347                                                      (nth 1 header)))
2348                                              (list 'quote (nth 1 (car ts)))
2349                                              (list 'gnus-score-delta-default
2350                                                    nil)
2351                                              (nth 1 (car ps))
2352                                              t)
2353                                             t)
2354                                            outp))
2355                                     (setq ps (cdr ps)))
2356                                   (list (nreverse outp))))
2357                                outt))
2358                         (setq ts (cdr ts)))
2359                       (list (nreverse outt))))
2360                    outh))
2361             (setq headers (cdr headers)))
2362           (list (nreverse outh))))))))
2363
2364 \f
2365
2366 (defun gnus-summary-mode (&optional group)
2367   "Major mode for reading articles.
2368
2369 All normal editing commands are switched off.
2370 \\<gnus-summary-mode-map>
2371 Each line in this buffer represents one article.  To read an
2372 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2373 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2374 respectively.
2375
2376 You can also post articles and send mail from this buffer.  To
2377 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2378 of an article, type `\\[gnus-summary-reply]'.
2379
2380 There are approx. one gazillion commands you can execute in this
2381 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2382
2383 The following commands are available:
2384
2385 \\{gnus-summary-mode-map}"
2386   (interactive)
2387   (kill-all-local-variables)
2388   (when (gnus-visual-p 'summary-menu 'menu)
2389     (gnus-summary-make-menu-bar)
2390     (gnus-summary-make-tool-bar))
2391   (gnus-summary-make-local-variables)
2392   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2393     (gnus-summary-make-local-variables))
2394   (gnus-make-thread-indent-array)
2395   (gnus-simplify-mode-line)
2396   (setq major-mode 'gnus-summary-mode)
2397   (setq mode-name "Summary")
2398   (make-local-variable 'minor-mode-alist)
2399   (use-local-map gnus-summary-mode-map)
2400   (buffer-disable-undo)
2401   (setq buffer-read-only t)             ;Disable modification
2402   (setq truncate-lines t)
2403   (setq selective-display t)
2404   (setq selective-display-ellipses t)   ;Display `...'
2405   (gnus-summary-set-display-table)
2406   (gnus-set-default-directory)
2407   (setq gnus-newsgroup-name group)
2408   (make-local-variable 'gnus-summary-line-format)
2409   (make-local-variable 'gnus-summary-line-format-spec)
2410   (make-local-variable 'gnus-summary-dummy-line-format)
2411   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2412   (make-local-variable 'gnus-summary-mark-positions)
2413   (make-local-hook 'pre-command-hook)
2414   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2415   (gnus-run-hooks 'gnus-summary-mode-hook)
2416   (turn-on-gnus-mailing-list-mode)
2417   (mm-enable-multibyte-mule4)
2418   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2419   (gnus-update-summary-mark-positions))
2420
2421 (defun gnus-summary-make-local-variables ()
2422   "Make all the local summary buffer variables."
2423   (let (global)
2424     (dolist (local gnus-summary-local-variables)
2425       (if (consp local)
2426           (progn
2427             (if (eq (cdr local) 'global)
2428                 ;; Copy the global value of the variable.
2429                 (setq global (symbol-value (car local)))
2430               ;; Use the value from the list.
2431               (setq global (eval (cdr local))))
2432             (set (make-local-variable (car local)) global))
2433         ;; Simple nil-valued local variable.
2434         (set (make-local-variable local) nil)))))
2435
2436 (defun gnus-summary-clear-local-variables ()
2437   (let ((locals gnus-summary-local-variables))
2438     (while locals
2439       (if (consp (car locals))
2440           (and (vectorp (caar locals))
2441                (set (caar locals) nil))
2442         (and (vectorp (car locals))
2443              (set (car locals) nil)))
2444       (setq locals (cdr locals)))))
2445
2446 ;; Summary data functions.
2447
2448 (defmacro gnus-data-number (data)
2449   `(car ,data))
2450
2451 (defmacro gnus-data-set-number (data number)
2452   `(setcar ,data ,number))
2453
2454 (defmacro gnus-data-mark (data)
2455   `(nth 1 ,data))
2456
2457 (defmacro gnus-data-set-mark (data mark)
2458   `(setcar (nthcdr 1 ,data) ,mark))
2459
2460 (defmacro gnus-data-pos (data)
2461   `(nth 2 ,data))
2462
2463 (defmacro gnus-data-set-pos (data pos)
2464   `(setcar (nthcdr 2 ,data) ,pos))
2465
2466 (defmacro gnus-data-header (data)
2467   `(nth 3 ,data))
2468
2469 (defmacro gnus-data-set-header (data header)
2470   `(setf (nth 3 ,data) ,header))
2471
2472 (defmacro gnus-data-level (data)
2473   `(nth 4 ,data))
2474
2475 (defmacro gnus-data-unread-p (data)
2476   `(= (nth 1 ,data) gnus-unread-mark))
2477
2478 (defmacro gnus-data-read-p (data)
2479   `(/= (nth 1 ,data) gnus-unread-mark))
2480
2481 (defmacro gnus-data-pseudo-p (data)
2482   `(consp (nth 3 ,data)))
2483
2484 (defmacro gnus-data-find (number)
2485   `(assq ,number gnus-newsgroup-data))
2486
2487 (defmacro gnus-data-find-list (number &optional data)
2488   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2489      (memq (assq ,number bdata)
2490            bdata)))
2491
2492 (defmacro gnus-data-make (number mark pos header level)
2493   `(list ,number ,mark ,pos ,header ,level))
2494
2495 (defun gnus-data-enter (after-article number mark pos header level offset)
2496   (let ((data (gnus-data-find-list after-article)))
2497     (unless data
2498       (error "No such article: %d" after-article))
2499     (setcdr data (cons (gnus-data-make number mark pos header level)
2500                        (cdr data)))
2501     (setq gnus-newsgroup-data-reverse nil)
2502     (gnus-data-update-list (cddr data) offset)))
2503
2504 (defun gnus-data-enter-list (after-article list &optional offset)
2505   (when list
2506     (let ((data (and after-article (gnus-data-find-list after-article)))
2507           (ilist list))
2508       (if (not (or data
2509                    after-article))
2510           (let ((odata gnus-newsgroup-data))
2511             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2512             (when offset
2513               (gnus-data-update-list odata offset)))
2514       ;; Find the last element in the list to be spliced into the main
2515         ;; list.
2516         (while (cdr list)
2517           (setq list (cdr list)))
2518         (if (not data)
2519             (progn
2520               (setcdr list gnus-newsgroup-data)
2521               (setq gnus-newsgroup-data ilist)
2522               (when offset
2523                 (gnus-data-update-list (cdr list) offset)))
2524           (setcdr list (cdr data))
2525           (setcdr data ilist)
2526           (when offset
2527             (gnus-data-update-list (cdr list) offset))))
2528       (setq gnus-newsgroup-data-reverse nil))))
2529
2530 (defun gnus-data-remove (article &optional offset)
2531   (let ((data gnus-newsgroup-data))
2532     (if (= (gnus-data-number (car data)) article)
2533         (progn
2534           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2535                 gnus-newsgroup-data-reverse nil)
2536           (when offset
2537             (gnus-data-update-list gnus-newsgroup-data offset)))
2538       (while (cdr data)
2539         (when (= (gnus-data-number (cadr data)) article)
2540           (setcdr data (cddr data))
2541           (when offset
2542             (gnus-data-update-list (cdr data) offset))
2543           (setq data nil
2544                 gnus-newsgroup-data-reverse nil))
2545         (setq data (cdr data))))))
2546
2547 (defmacro gnus-data-list (backward)
2548   `(if ,backward
2549        (or gnus-newsgroup-data-reverse
2550            (setq gnus-newsgroup-data-reverse
2551                  (reverse gnus-newsgroup-data)))
2552      gnus-newsgroup-data))
2553
2554 (defun gnus-data-update-list (data offset)
2555   "Add OFFSET to the POS of all data entries in DATA."
2556   (setq gnus-newsgroup-data-reverse nil)
2557   (while data
2558     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2559     (setq data (cdr data))))
2560
2561 (defun gnus-summary-article-pseudo-p (article)
2562   "Say whether this article is a pseudo article or not."
2563   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2564
2565 (defmacro gnus-summary-article-sparse-p (article)
2566   "Say whether this article is a sparse article or not."
2567   `(memq ,article gnus-newsgroup-sparse))
2568
2569 (defmacro gnus-summary-article-ancient-p (article)
2570   "Say whether this article is a sparse article or not."
2571   `(memq ,article gnus-newsgroup-ancient))
2572
2573 (defun gnus-article-parent-p (number)
2574   "Say whether this article is a parent or not."
2575   (let ((data (gnus-data-find-list number)))
2576     (and (cdr data)              ; There has to be an article after...
2577          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2578             (gnus-data-level (nth 1 data))))))
2579
2580 (defun gnus-article-children (number)
2581   "Return a list of all children to NUMBER."
2582   (let* ((data (gnus-data-find-list number))
2583          (level (gnus-data-level (car data)))
2584          children)
2585     (setq data (cdr data))
2586     (while (and data
2587                 (= (gnus-data-level (car data)) (1+ level)))
2588       (push (gnus-data-number (car data)) children)
2589       (setq data (cdr data)))
2590     children))
2591
2592 (defmacro gnus-summary-skip-intangible ()
2593   "If the current article is intangible, then jump to a different article."
2594   '(let ((to (get-text-property (point) 'gnus-intangible)))
2595      (and to (gnus-summary-goto-subject to))))
2596
2597 (defmacro gnus-summary-article-intangible-p ()
2598   "Say whether this article is intangible or not."
2599   '(get-text-property (point) 'gnus-intangible))
2600
2601 (defun gnus-article-read-p (article)
2602   "Say whether ARTICLE is read or not."
2603   (not (or (memq article gnus-newsgroup-marked)
2604            (memq article gnus-newsgroup-unreads)
2605            (memq article gnus-newsgroup-unselected)
2606            (memq article gnus-newsgroup-dormant))))
2607
2608 ;; Some summary mode macros.
2609
2610 (defmacro gnus-summary-article-number ()
2611   "The article number of the article on the current line.
2612 If there isn's an article number here, then we return the current
2613 article number."
2614   '(progn
2615      (gnus-summary-skip-intangible)
2616      (or (get-text-property (point) 'gnus-number)
2617          (gnus-summary-last-subject))))
2618
2619 (defmacro gnus-summary-article-header (&optional number)
2620   "Return the header of article NUMBER."
2621   `(gnus-data-header (gnus-data-find
2622                       ,(or number '(gnus-summary-article-number)))))
2623
2624 (defmacro gnus-summary-thread-level (&optional number)
2625   "Return the level of thread that starts with article NUMBER."
2626   `(if (and (eq gnus-summary-make-false-root 'dummy)
2627             (get-text-property (point) 'gnus-intangible))
2628        0
2629      (gnus-data-level (gnus-data-find
2630                        ,(or number '(gnus-summary-article-number))))))
2631
2632 (defmacro gnus-summary-article-mark (&optional number)
2633   "Return the mark of article NUMBER."
2634   `(gnus-data-mark (gnus-data-find
2635                     ,(or number '(gnus-summary-article-number)))))
2636
2637 (defmacro gnus-summary-article-pos (&optional number)
2638   "Return the position of the line of article NUMBER."
2639   `(gnus-data-pos (gnus-data-find
2640                    ,(or number '(gnus-summary-article-number)))))
2641
2642 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2643 (defmacro gnus-summary-article-subject (&optional number)
2644   "Return current subject string or nil if nothing."
2645   `(let ((headers
2646           ,(if number
2647                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2648              '(gnus-data-header (assq (gnus-summary-article-number)
2649                                       gnus-newsgroup-data)))))
2650      (and headers
2651           (vectorp headers)
2652           (mail-header-subject headers))))
2653
2654 (defmacro gnus-summary-article-score (&optional number)
2655   "Return current article score."
2656   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2657                   gnus-newsgroup-scored))
2658        gnus-summary-default-score 0))
2659
2660 (defun gnus-summary-article-children (&optional number)
2661   "Return a list of article numbers that are children of article NUMBER."
2662   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2663          (level (gnus-data-level (car data)))
2664          l children)
2665     (while (and (setq data (cdr data))
2666                 (> (setq l (gnus-data-level (car data))) level))
2667       (and (= (1+ level) l)
2668            (push (gnus-data-number (car data))
2669                  children)))
2670     (nreverse children)))
2671
2672 (defun gnus-summary-article-parent (&optional number)
2673   "Return the article number of the parent of article NUMBER."
2674   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2675                                     (gnus-data-list t)))
2676          (level (gnus-data-level (car data))))
2677     (if (zerop level)
2678         ()                              ; This is a root.
2679       ;; We search until we find an article with a level less than
2680       ;; this one.  That function has to be the parent.
2681       (while (and (setq data (cdr data))
2682                   (not (< (gnus-data-level (car data)) level))))
2683       (and data (gnus-data-number (car data))))))
2684
2685 (defun gnus-unread-mark-p (mark)
2686   "Say whether MARK is the unread mark."
2687   (= mark gnus-unread-mark))
2688
2689 (defun gnus-read-mark-p (mark)
2690   "Say whether MARK is one of the marks that mark as read.
2691 This is all marks except unread, ticked, dormant, and expirable."
2692   (not (or (= mark gnus-unread-mark)
2693            (= mark gnus-ticked-mark)
2694            (= mark gnus-dormant-mark)
2695            (= mark gnus-expirable-mark))))
2696
2697 (defmacro gnus-article-mark (number)
2698   "Return the MARK of article NUMBER.
2699 This macro should only be used when computing the mark the \"first\"
2700 time; i.e., when generating the summary lines.  After that,
2701 `gnus-summary-article-mark' should be used to examine the
2702 marks of articles."
2703   `(cond
2704     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2705     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2706     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2707     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2708     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2709     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2710     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2711     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2712            gnus-ancient-mark))))
2713
2714 ;; Saving hidden threads.
2715
2716 (defmacro gnus-save-hidden-threads (&rest forms)
2717   "Save hidden threads, eval FORMS, and restore the hidden threads."
2718   (let ((config (make-symbol "config")))
2719     `(let ((,config (gnus-hidden-threads-configuration)))
2720        (unwind-protect
2721            (save-excursion
2722              ,@forms)
2723          (gnus-restore-hidden-threads-configuration ,config)))))
2724 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2725 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2726
2727 (defun gnus-data-compute-positions ()
2728   "Compute the positions of all articles."
2729   (setq gnus-newsgroup-data-reverse nil)
2730   (let ((data gnus-newsgroup-data))
2731     (save-excursion
2732       (gnus-save-hidden-threads
2733         (gnus-summary-show-all-threads)
2734         (goto-char (point-min))
2735         (while data
2736           (while (get-text-property (point) 'gnus-intangible)
2737             (forward-line 1))
2738           (gnus-data-set-pos (car data) (+ (point) 3))
2739           (setq data (cdr data))
2740           (forward-line 1))))))
2741
2742 (defun gnus-hidden-threads-configuration ()
2743   "Return the current hidden threads configuration."
2744   (save-excursion
2745     (let (config)
2746       (goto-char (point-min))
2747       (while (search-forward "\r" nil t)
2748         (push (1- (point)) config))
2749       config)))
2750
2751 (defun gnus-restore-hidden-threads-configuration (config)
2752   "Restore hidden threads configuration from CONFIG."
2753   (save-excursion
2754     (let (point buffer-read-only)
2755       (while (setq point (pop config))
2756         (when (and (< point (point-max))
2757                    (goto-char point)
2758                    (eq (char-after) ?\n))
2759           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2760
2761 ;; Various summary mode internalish functions.
2762
2763 (defun gnus-mouse-pick-article (e)
2764   (interactive "e")
2765   (mouse-set-point e)
2766   (gnus-summary-next-page nil t))
2767
2768 (defun gnus-summary-set-display-table ()
2769   "Change the display table.
2770 Odd characters have a tendency to mess
2771 up nicely formatted displays - we make all possible glyphs
2772 display only a single character."
2773
2774   ;; We start from the standard display table, if any.
2775   (let ((table (or (copy-sequence standard-display-table)
2776                    (make-display-table)))
2777         (i 32))
2778     ;; Nix out all the control chars...
2779     (while (>= (setq i (1- i)) 0)
2780       (aset table i [??]))
2781    ;; ... but not newline and cr, of course.  (cr is necessary for the
2782     ;; selective display).
2783     (aset table ?\n nil)
2784     (aset table ?\r nil)
2785     ;; We keep TAB as well.
2786     (aset table ?\t nil)
2787     ;; We nix out any glyphs over 126 that are not set already.
2788     (let ((i 256))
2789       (while (>= (setq i (1- i)) 127)
2790         ;; Only modify if the entry is nil.
2791         (unless (aref table i)
2792           (aset table i [??]))))
2793     (setq buffer-display-table table)))
2794
2795 (defun gnus-summary-set-article-display-arrow (pos)
2796   "Update the overlay arrow to point to line at position POS."
2797   (when (and gnus-summary-display-arrow
2798              (boundp 'overlay-arrow-position)
2799              (boundp 'overlay-arrow-string))
2800     (save-excursion
2801       (goto-char pos)
2802       (beginning-of-line)
2803       (unless overlay-arrow-position
2804         (setq overlay-arrow-position (make-marker)))
2805       (setq overlay-arrow-string "=>"
2806             overlay-arrow-position (set-marker overlay-arrow-position
2807                                                (point)
2808                                                (current-buffer))))))
2809
2810 (defun gnus-summary-buffer-name (group)
2811   "Return the summary buffer name of GROUP."
2812   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2813
2814 (defun gnus-summary-setup-buffer (group)
2815   "Initialize summary buffer."
2816   (let ((buffer (gnus-summary-buffer-name group)))
2817     (if (get-buffer buffer)
2818         (progn
2819           (set-buffer buffer)
2820           (setq gnus-summary-buffer (current-buffer))
2821           (not gnus-newsgroup-prepared))
2822       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2823       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2824       (gnus-summary-mode group)
2825       (when gnus-carpal
2826         (gnus-carpal-setup-buffer 'summary))
2827       (unless gnus-single-article-buffer
2828         (make-local-variable 'gnus-article-buffer)
2829         (make-local-variable 'gnus-article-current)
2830         (make-local-variable 'gnus-original-article-buffer))
2831       (setq gnus-newsgroup-name group)
2832       ;; Set any local variables in the group parameters.
2833       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2834       t)))
2835
2836 (defun gnus-set-global-variables ()
2837   "Set the global equivalents of the buffer-local variables.
2838 They are set to the latest values they had.  These reflect the summary
2839 buffer that was in action when the last article was fetched."
2840   (when (eq major-mode 'gnus-summary-mode)
2841     (setq gnus-summary-buffer (current-buffer))
2842     (let ((name gnus-newsgroup-name)
2843           (marked gnus-newsgroup-marked)
2844           (unread gnus-newsgroup-unreads)
2845           (headers gnus-current-headers)
2846           (data gnus-newsgroup-data)
2847           (summary gnus-summary-buffer)
2848           (article-buffer gnus-article-buffer)
2849           (original gnus-original-article-buffer)
2850           (gac gnus-article-current)
2851           (reffed gnus-reffed-article-number)
2852           (score-file gnus-current-score-file)
2853           (default-charset gnus-newsgroup-charset)
2854           vlist)
2855       (let ((locals gnus-newsgroup-variables))
2856         (while locals
2857           (if (consp (car locals))
2858               (push (eval (caar locals)) vlist)
2859             (push (eval (car locals)) vlist))
2860           (setq locals (cdr locals)))
2861         (setq vlist (nreverse vlist)))
2862       (save-excursion
2863         (set-buffer gnus-group-buffer)
2864         (setq gnus-newsgroup-name name
2865               gnus-newsgroup-marked marked
2866               gnus-newsgroup-unreads unread
2867               gnus-current-headers headers
2868               gnus-newsgroup-data data
2869               gnus-article-current gac
2870               gnus-summary-buffer summary
2871               gnus-article-buffer article-buffer
2872               gnus-original-article-buffer original
2873               gnus-reffed-article-number reffed
2874               gnus-current-score-file score-file
2875               gnus-newsgroup-charset default-charset)
2876         (let ((locals gnus-newsgroup-variables))
2877           (while locals
2878             (if (consp (car locals))
2879                 (set (caar locals) (pop vlist))
2880               (set (car locals) (pop vlist)))
2881             (setq locals (cdr locals))))
2882         ;; The article buffer also has local variables.
2883         (when (gnus-buffer-live-p gnus-article-buffer)
2884           (set-buffer gnus-article-buffer)
2885           (setq gnus-summary-buffer summary))))))
2886
2887 (defun gnus-summary-article-unread-p (article)
2888   "Say whether ARTICLE is unread or not."
2889   (memq article gnus-newsgroup-unreads))
2890
2891 (defun gnus-summary-first-article-p (&optional article)
2892   "Return whether ARTICLE is the first article in the buffer."
2893   (if (not (setq article (or article (gnus-summary-article-number))))
2894       nil
2895     (eq article (caar gnus-newsgroup-data))))
2896
2897 (defun gnus-summary-last-article-p (&optional article)
2898   "Return whether ARTICLE is the last article in the buffer."
2899   (if (not (setq article (or article (gnus-summary-article-number))))
2900       ;; All non-existent numbers are the last article.  :-)
2901       t
2902     (not (cdr (gnus-data-find-list article)))))
2903
2904 (defun gnus-make-thread-indent-array ()
2905   (let ((n 200))
2906     (unless (and gnus-thread-indent-array
2907                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2908       (setq gnus-thread-indent-array (make-vector 201 "")
2909             gnus-thread-indent-array-level gnus-thread-indent-level)
2910       (while (>= n 0)
2911         (aset gnus-thread-indent-array n
2912               (make-string (* n gnus-thread-indent-level) ? ))
2913         (setq n (1- n))))))
2914
2915 (defun gnus-update-summary-mark-positions ()
2916   "Compute where the summary marks are to go."
2917   (save-excursion
2918     (when (gnus-buffer-exists-p gnus-summary-buffer)
2919       (set-buffer gnus-summary-buffer))
2920     (let ((gnus-replied-mark 129)
2921           (gnus-score-below-mark 130)
2922           (gnus-score-over-mark 130)
2923           (gnus-download-mark 131)
2924           (spec gnus-summary-line-format-spec)
2925           gnus-visual pos)
2926       (save-excursion
2927         (gnus-set-work-buffer)
2928         (let ((gnus-summary-line-format-spec spec)
2929               (gnus-newsgroup-downloadable '((0 . t))))
2930           (gnus-summary-insert-line
2931            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2932            0 nil 128 t nil "" nil 1)
2933           (goto-char (point-min))
2934           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2935                                              (- (point) 2)))))
2936           (goto-char (point-min))
2937           (push (cons 'replied (and (search-forward "\201" nil t)
2938                                     (- (point) 2)))
2939                 pos)
2940           (goto-char (point-min))
2941           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2942                 pos)
2943           (goto-char (point-min))
2944           (push (cons 'download
2945                       (and (search-forward "\203" nil t) (- (point) 2)))
2946                 pos)))
2947       (setq gnus-summary-mark-positions pos))))
2948
2949 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2950   "Insert a dummy root in the summary buffer."
2951   (beginning-of-line)
2952   (gnus-add-text-properties
2953    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2954    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2955
2956 (defun gnus-summary-extract-address-component (from)
2957   (or (car (funcall gnus-extract-address-components from))
2958       from))
2959
2960 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2961   (let ((mail-parse-charset gnus-newsgroup-charset)
2962         ; Is it really necessary to do this next part for each summary line?
2963         ; Luckily, doesn't seem to slow things down much.
2964         (mail-parse-ignored-charsets
2965          (save-excursion (set-buffer gnus-summary-buffer)
2966                          gnus-newsgroup-ignored-charsets)))
2967     (or
2968      (and gnus-ignored-from-addresses
2969           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2970           (let ((extra-headers (mail-header-extra header))
2971                 to
2972                 newsgroups)
2973             (cond
2974              ((setq to (cdr (assq 'To extra-headers)))
2975               (concat "-> "
2976                       (gnus-summary-extract-address-component
2977                        (funcall gnus-decode-encoded-word-function to))))
2978              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2979               (concat "=> " newsgroups)))))
2980      (gnus-summary-extract-address-component gnus-tmp-from))))
2981
2982 (defun gnus-summary-insert-line (gnus-tmp-header
2983                                  gnus-tmp-level gnus-tmp-current
2984                                  gnus-tmp-unread gnus-tmp-replied
2985                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2986                                  &optional gnus-tmp-dummy gnus-tmp-score
2987                                  gnus-tmp-process)
2988   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2989          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2990          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2991          (gnus-tmp-score-char
2992           (if (or (null gnus-summary-default-score)
2993                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2994                       gnus-summary-zcore-fuzz))
2995               ?                         ;Whitespace
2996             (if (< gnus-tmp-score gnus-summary-default-score)
2997                 gnus-score-below-mark gnus-score-over-mark)))
2998          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2999          (gnus-tmp-replied
3000           (cond (gnus-tmp-process gnus-process-mark)
3001                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3002                  gnus-cached-mark)
3003                 (gnus-tmp-replied gnus-replied-mark)
3004                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3005                  gnus-forwarded-mark)
3006                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3007                  gnus-saved-mark)
3008                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3009                  gnus-recent-mark)
3010                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3011                  gnus-unseen-mark)
3012                 (t gnus-no-mark)))
3013          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3014          (gnus-tmp-name
3015           (cond
3016            ((string-match "<[^>]+> *$" gnus-tmp-from)
3017             (let ((beg (match-beginning 0)))
3018               (or (and (string-match "^\".+\"" gnus-tmp-from)
3019                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3020                   (substring gnus-tmp-from 0 beg))))
3021            ((string-match "(.+)" gnus-tmp-from)
3022             (substring gnus-tmp-from
3023                        (1+ (match-beginning 0)) (1- (match-end 0))))
3024            (t gnus-tmp-from)))
3025          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3026          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3027          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3028          (buffer-read-only nil))
3029     (when (string= gnus-tmp-name "")
3030       (setq gnus-tmp-name gnus-tmp-from))
3031     (unless (numberp gnus-tmp-lines)
3032       (setq gnus-tmp-lines -1))
3033     (if (= gnus-tmp-lines -1)
3034         (setq gnus-tmp-lines "?")
3035       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3036     (gnus-put-text-property
3037      (point)
3038      (progn (eval gnus-summary-line-format-spec) (point))
3039      'gnus-number gnus-tmp-number)
3040     (when (gnus-visual-p 'summary-highlight 'highlight)
3041       (forward-line -1)
3042       (gnus-run-hooks 'gnus-summary-update-hook)
3043       (forward-line 1))))
3044
3045 (defun gnus-summary-update-line (&optional dont-update)
3046   "Update summary line after change."
3047   (when (and gnus-summary-default-score
3048              (not gnus-summary-inhibit-highlight))
3049     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3050            (article (gnus-summary-article-number))
3051            (score (gnus-summary-article-score article)))
3052       (unless dont-update
3053         (if (and gnus-summary-mark-below
3054                  (< (gnus-summary-article-score)
3055                     gnus-summary-mark-below))
3056             ;; This article has a low score, so we mark it as read.
3057             (when (memq article gnus-newsgroup-unreads)
3058               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3059           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3060             ;; This article was previously marked as read on account
3061             ;; of a low score, but now it has risen, so we mark it as
3062             ;; unread.
3063             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3064         (gnus-summary-update-mark
3065          (if (or (null gnus-summary-default-score)
3066                  (<= (abs (- score gnus-summary-default-score))
3067                      gnus-summary-zcore-fuzz))
3068              ?                          ;Whitespace
3069            (if (< score gnus-summary-default-score)
3070                gnus-score-below-mark gnus-score-over-mark))
3071          'score))
3072       ;; Do visual highlighting.
3073       (when (gnus-visual-p 'summary-highlight 'highlight)
3074         (gnus-run-hooks 'gnus-summary-update-hook)))))
3075
3076 (defvar gnus-tmp-new-adopts nil)
3077
3078 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3079   "Return the number of articles in THREAD.
3080 This may be 0 in some cases -- if none of the articles in
3081 the thread are to be displayed."
3082   (let* ((number
3083          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3084           (cond
3085            ((not (listp thread))
3086             1)
3087            ((and (consp thread) (cdr thread))
3088             (apply
3089              '+ 1 (mapcar
3090                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3091            ((null thread)
3092             1)
3093            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3094             1)
3095            (t 0))))
3096     (when (and level (zerop level) gnus-tmp-new-adopts)
3097       (incf number
3098             (apply '+ (mapcar
3099                        'gnus-summary-number-of-articles-in-thread
3100                        gnus-tmp-new-adopts))))
3101     (if char
3102         (if (> number 1) gnus-not-empty-thread-mark
3103           gnus-empty-thread-mark)
3104       number)))
3105
3106 (defun gnus-summary-set-local-parameters (group)
3107   "Go through the local params of GROUP and set all variable specs in that list."
3108   (let ((params (gnus-group-find-parameter group))
3109         (vars '(quit-config))           ; Ignore quit-config.
3110         elem)
3111     (while params
3112       (setq elem (car params)
3113             params (cdr params))
3114       (and (consp elem)                 ; Has to be a cons.
3115            (consp (cdr elem))           ; The cdr has to be a list.
3116            (symbolp (car elem))         ; Has to be a symbol in there.
3117            (not (memq (car elem) vars))
3118            (ignore-errors               ; So we set it.
3119              (push (car elem) vars)
3120              (make-local-variable (car elem))
3121              (set (car elem) (eval (nth 1 elem))))))))
3122
3123 (defun gnus-summary-read-group (group &optional show-all no-article
3124                                       kill-buffer no-display backward
3125                                       select-articles)
3126   "Start reading news in newsgroup GROUP.
3127 If SHOW-ALL is non-nil, already read articles are also listed.
3128 If NO-ARTICLE is non-nil, no article is selected initially.
3129 If NO-DISPLAY, don't generate a summary buffer."
3130   (let (result)
3131     (while (and group
3132                 (null (setq result
3133                             (let ((gnus-auto-select-next nil))
3134                               (or (gnus-summary-read-group-1
3135                                    group show-all no-article
3136                                    kill-buffer no-display
3137                                    select-articles)
3138                                   (setq show-all nil
3139                                         select-articles nil)))))
3140                 (eq gnus-auto-select-next 'quietly))
3141       (set-buffer gnus-group-buffer)
3142       ;; The entry function called above goes to the next
3143       ;; group automatically, so we go two groups back
3144       ;; if we are searching for the previous group.
3145       (when backward
3146         (gnus-group-prev-unread-group 2))
3147       (if (not (equal group (gnus-group-group-name)))
3148           (setq group (gnus-group-group-name))
3149         (setq group nil)))
3150     result))
3151
3152 (defun gnus-summary-read-group-1 (group show-all no-article
3153                                         kill-buffer no-display
3154                                         &optional select-articles)
3155   ;; Killed foreign groups can't be entered.
3156   ;;  (when (and (not (gnus-group-native-p group))
3157   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3158   ;;    (error "Dead non-native groups can't be entered"))
3159   (gnus-message 5 "Retrieving newsgroup: %s..."
3160                 (gnus-group-decoded-name group))
3161   (let* ((new-group (gnus-summary-setup-buffer group))
3162          (quit-config (gnus-group-quit-config group))
3163          (did-select (and new-group (gnus-select-newsgroup
3164                                      group show-all select-articles))))
3165     (cond
3166      ;; This summary buffer exists already, so we just select it.
3167      ((not new-group)
3168       (gnus-set-global-variables)
3169       (when kill-buffer
3170         (gnus-kill-or-deaden-summary kill-buffer))
3171       (gnus-configure-windows 'summary 'force)
3172       (gnus-set-mode-line 'summary)
3173       (gnus-summary-position-point)
3174       (message "")
3175       t)
3176      ;; We couldn't select this group.
3177      ((null did-select)
3178       (when (and (eq major-mode 'gnus-summary-mode)
3179                  (not (equal (current-buffer) kill-buffer)))
3180         (kill-buffer (current-buffer))
3181         (if (not quit-config)
3182             (progn
3183               ;; Update the info -- marks might need to be removed,
3184               ;; for instance.
3185               (gnus-summary-update-info)
3186               (set-buffer gnus-group-buffer)
3187               (gnus-group-jump-to-group group)
3188               (gnus-group-next-unread-group 1))
3189           (gnus-handle-ephemeral-exit quit-config)))
3190       (let ((grpinfo (gnus-get-info group)))
3191         (if (null (gnus-info-read grpinfo))
3192             (gnus-message 3 "Group %s contains no messages"
3193                           (gnus-group-decoded-name group))
3194           (gnus-message 3 "Can't select group")))
3195       nil)
3196      ;; The user did a `C-g' while prompting for number of articles,
3197      ;; so we exit this group.
3198      ((eq did-select 'quit)
3199       (and (eq major-mode 'gnus-summary-mode)
3200            (not (equal (current-buffer) kill-buffer))
3201            (kill-buffer (current-buffer)))
3202       (when kill-buffer
3203         (gnus-kill-or-deaden-summary kill-buffer))
3204       (if (not quit-config)
3205           (progn
3206             (set-buffer gnus-group-buffer)
3207             (gnus-group-jump-to-group group)
3208             (gnus-group-next-unread-group 1)
3209             (gnus-configure-windows 'group 'force))
3210         (gnus-handle-ephemeral-exit quit-config))
3211       ;; Finally signal the quit.
3212       (signal 'quit nil))
3213      ;; The group was successfully selected.
3214      (t
3215       (gnus-set-global-variables)
3216       ;; Save the active value in effect when the group was entered.
3217       (setq gnus-newsgroup-active
3218             (gnus-copy-sequence
3219              (gnus-active gnus-newsgroup-name)))
3220       ;; You can change the summary buffer in some way with this hook.
3221       (gnus-run-hooks 'gnus-select-group-hook)
3222       (gnus-update-format-specifications
3223        nil 'summary 'summary-mode 'summary-dummy)
3224       (gnus-update-summary-mark-positions)
3225       ;; Do score processing.
3226       (when gnus-use-scoring
3227         (gnus-possibly-score-headers))
3228       ;; Check whether to fill in the gaps in the threads.
3229       (when gnus-build-sparse-threads
3230         (gnus-build-sparse-threads))
3231       ;; Find the initial limit.
3232       (if gnus-show-threads
3233           (if show-all
3234               (let ((gnus-newsgroup-dormant nil))
3235                 (gnus-summary-initial-limit show-all))
3236             (gnus-summary-initial-limit show-all))
3237         ;; When untreaded, all articles are always shown.
3238         (setq gnus-newsgroup-limit
3239               (mapcar
3240                (lambda (header) (mail-header-number header))
3241                gnus-newsgroup-headers)))
3242       ;; Generate the summary buffer.
3243       (unless no-display
3244         (gnus-summary-prepare))
3245       (when gnus-use-trees
3246         (gnus-tree-open group)
3247         (setq gnus-summary-highlight-line-function
3248               'gnus-tree-highlight-article))
3249       ;; If the summary buffer is empty, but there are some low-scored
3250       ;; articles or some excluded dormants, we include these in the
3251       ;; buffer.
3252       (when (and (zerop (buffer-size))
3253                  (not no-display))
3254         (cond (gnus-newsgroup-dormant
3255                (gnus-summary-limit-include-dormant))
3256               ((and gnus-newsgroup-scored show-all)
3257                (gnus-summary-limit-include-expunged t))))
3258       ;; Function `gnus-apply-kill-file' must be called in this hook.
3259       (gnus-run-hooks 'gnus-apply-kill-hook)
3260       (if (and (zerop (buffer-size))
3261                (not no-display))
3262           (progn
3263             ;; This newsgroup is empty.
3264             (gnus-summary-catchup-and-exit nil t)
3265             (gnus-message 6 "No unread news")
3266             (when kill-buffer
3267               (gnus-kill-or-deaden-summary kill-buffer))
3268             ;; Return nil from this function.
3269             nil)
3270         ;; Hide conversation thread subtrees.  We cannot do this in
3271         ;; gnus-summary-prepare-hook since kill processing may not
3272         ;; work with hidden articles.
3273         (gnus-summary-maybe-hide-threads)
3274         (when kill-buffer
3275           (gnus-kill-or-deaden-summary kill-buffer))
3276         (gnus-summary-auto-select-subject)
3277         ;; Show first unread article if requested.
3278         (if (and (not no-article)
3279                  (not no-display)
3280                  gnus-newsgroup-unreads
3281                  gnus-auto-select-first)
3282             (progn
3283               (gnus-configure-windows 'summary)
3284               (gnus-summary-goto-article (gnus-summary-article-number)))
3285           ;; Don't select any articles.
3286           (gnus-summary-position-point)
3287           (gnus-configure-windows 'summary 'force)
3288           (gnus-set-mode-line 'summary))
3289         (when (get-buffer-window gnus-group-buffer t)
3290           ;; Gotta use windows, because recenter does weird stuff if
3291           ;; the current buffer ain't the displayed window.
3292           (let ((owin (selected-window)))
3293             (select-window (get-buffer-window gnus-group-buffer t))
3294             (when (gnus-group-goto-group group)
3295               (recenter))
3296             (select-window owin)))
3297         ;; Mark this buffer as "prepared".
3298         (setq gnus-newsgroup-prepared t)
3299         (gnus-run-hooks 'gnus-summary-prepared-hook)
3300         t)))))
3301
3302 (defun gnus-summary-auto-select-subject ()
3303   "Select the subject line on initial group entry."
3304   (goto-char (point-min))
3305   (cond
3306    ((eq gnus-auto-select-subject 'best)
3307     (gnus-summary-best-unread-subject))
3308    ((eq gnus-auto-select-subject 'unread)
3309     (gnus-summary-first-unread-subject))
3310    ((eq gnus-auto-select-subject 'unseen)
3311     (gnus-summary-first-unseen-subject))
3312    ((eq gnus-auto-select-subject 'first)
3313     ;; Do nothing.
3314     )
3315    ((gnus-functionp gnus-auto-select-subject)
3316     (funcall gnus-auto-select-subject))))
3317
3318 (defun gnus-summary-prepare ()
3319   "Generate the summary buffer."
3320   (interactive)
3321   (let ((buffer-read-only nil))
3322     (erase-buffer)
3323     (setq gnus-newsgroup-data nil
3324           gnus-newsgroup-data-reverse nil)
3325     (gnus-run-hooks 'gnus-summary-generate-hook)
3326     ;; Generate the buffer, either with threads or without.
3327     (when gnus-newsgroup-headers
3328       (gnus-summary-prepare-threads
3329        (if gnus-show-threads
3330            (gnus-sort-gathered-threads
3331             (funcall gnus-summary-thread-gathering-function
3332                      (gnus-sort-threads
3333                       (gnus-cut-threads (gnus-make-threads)))))
3334          ;; Unthreaded display.
3335          (gnus-sort-articles gnus-newsgroup-headers))))
3336     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3337     ;; Call hooks for modifying summary buffer.
3338     (goto-char (point-min))
3339     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3340
3341 (defsubst gnus-general-simplify-subject (subject)
3342   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3343   (setq subject
3344         (cond
3345          ;; Truncate the subject.
3346          (gnus-simplify-subject-functions
3347           (gnus-map-function gnus-simplify-subject-functions subject))
3348          ((numberp gnus-summary-gather-subject-limit)
3349           (setq subject (gnus-simplify-subject-re subject))
3350           (if (> (length subject) gnus-summary-gather-subject-limit)
3351               (substring subject 0 gnus-summary-gather-subject-limit)
3352             subject))
3353          ;; Fuzzily simplify it.
3354          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3355           (gnus-simplify-subject-fuzzy subject))
3356          ;; Just remove the leading "Re:".
3357          (t
3358           (gnus-simplify-subject-re subject))))
3359
3360   (if (and gnus-summary-gather-exclude-subject
3361            (string-match gnus-summary-gather-exclude-subject subject))
3362       nil                         ; This article shouldn't be gathered
3363     subject))
3364
3365 (defun gnus-summary-simplify-subject-query ()
3366   "Query where the respool algorithm would put this article."
3367   (interactive)
3368   (gnus-summary-select-article)
3369   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3370
3371 (defun gnus-gather-threads-by-subject (threads)
3372   "Gather threads by looking at Subject headers."
3373   (if (not gnus-summary-make-false-root)
3374       threads
3375     (let ((hashtb (gnus-make-hashtable 1024))
3376           (prev threads)
3377           (result threads)
3378           subject hthread whole-subject)
3379       (while threads
3380         (setq subject (gnus-general-simplify-subject
3381                        (setq whole-subject (mail-header-subject
3382                                             (caar threads)))))
3383         (when subject
3384           (if (setq hthread (gnus-gethash subject hashtb))
3385               (progn
3386                 ;; We enter a dummy root into the thread, if we
3387                 ;; haven't done that already.
3388                 (unless (stringp (caar hthread))
3389                   (setcar hthread (list whole-subject (car hthread))))
3390                 ;; We add this new gathered thread to this gathered
3391                 ;; thread.
3392                 (setcdr (car hthread)
3393                         (nconc (cdar hthread) (list (car threads))))
3394                 ;; Remove it from the list of threads.
3395                 (setcdr prev (cdr threads))
3396                 (setq threads prev))
3397             ;; Enter this thread into the hash table.
3398             (gnus-sethash subject threads hashtb)))
3399         (setq prev threads)
3400         (setq threads (cdr threads)))
3401       result)))
3402
3403 (defun gnus-gather-threads-by-references (threads)
3404   "Gather threads by looking at References headers."
3405   (let ((idhashtb (gnus-make-hashtable 1024))
3406         (thhashtb (gnus-make-hashtable 1024))
3407         (prev threads)
3408         (result threads)
3409         ids references id gthread gid entered ref)
3410     (while threads
3411       (when (setq references (mail-header-references (caar threads)))
3412         (setq id (mail-header-id (caar threads))
3413               ids (gnus-split-references references)
3414               entered nil)
3415         (while (setq ref (pop ids))
3416           (setq ids (delete ref ids))
3417           (if (not (setq gid (gnus-gethash ref idhashtb)))
3418               (progn
3419                 (gnus-sethash ref id idhashtb)
3420                 (gnus-sethash id threads thhashtb))
3421             (setq gthread (gnus-gethash gid thhashtb))
3422             (unless entered
3423               ;; We enter a dummy root into the thread, if we
3424               ;; haven't done that already.
3425               (unless (stringp (caar gthread))
3426                 (setcar gthread (list (mail-header-subject (caar gthread))
3427                                       (car gthread))))
3428               ;; We add this new gathered thread to this gathered
3429               ;; thread.
3430               (setcdr (car gthread)
3431                       (nconc (cdar gthread) (list (car threads)))))
3432             ;; Add it into the thread hash table.
3433             (gnus-sethash id gthread thhashtb)
3434             (setq entered t)
3435             ;; Remove it from the list of threads.
3436             (setcdr prev (cdr threads))
3437             (setq threads prev))))
3438       (setq prev threads)
3439       (setq threads (cdr threads)))
3440     result))
3441
3442 (defun gnus-sort-gathered-threads (threads)
3443   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3444   (let ((result threads))
3445     (while threads
3446       (when (stringp (caar threads))
3447         (setcdr (car threads)
3448                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3449       (setq threads (cdr threads)))
3450     result))
3451
3452 (defun gnus-thread-loop-p (root thread)
3453   "Say whether ROOT is in THREAD."
3454   (let ((stack (list thread))
3455         (infloop 0)
3456         th)
3457     (while (setq thread (pop stack))
3458       (setq th (cdr thread))
3459       (while (and th
3460                   (not (eq (caar th) root)))
3461         (pop th))
3462       (if th
3463           ;; We have found a loop.
3464           (let (ref-dep)
3465             (setcdr thread (delq (car th) (cdr thread)))
3466             (if (boundp (setq ref-dep (intern "none"
3467                                               gnus-newsgroup-dependencies)))
3468                 (setcdr (symbol-value ref-dep)
3469                         (nconc (cdr (symbol-value ref-dep))
3470                                (list (car th))))
3471               (set ref-dep (list nil (car th))))
3472             (setq infloop 1
3473                   stack nil))
3474         ;; Push all the subthreads onto the stack.
3475         (push (cdr thread) stack)))
3476     infloop))
3477
3478 (defun gnus-make-threads ()
3479   "Go through the dependency hashtb and find the roots.  Return all threads."
3480   (let (threads)
3481     (while (catch 'infloop
3482              (mapatoms
3483               (lambda (refs)
3484                 ;; Deal with self-referencing References loops.
3485                 (when (and (car (symbol-value refs))
3486                            (not (zerop
3487                                  (apply
3488                                   '+
3489                                   (mapcar
3490                                    (lambda (thread)
3491                                      (gnus-thread-loop-p
3492                                       (car (symbol-value refs)) thread))
3493                                    (cdr (symbol-value refs)))))))
3494                   (setq threads nil)
3495                   (throw 'infloop t))
3496                 (unless (car (symbol-value refs))
3497              ;; These threads do not refer back to any other articles,
3498                   ;; so they're roots.
3499                   (setq threads (append (cdr (symbol-value refs)) threads))))
3500               gnus-newsgroup-dependencies)))
3501     threads))
3502
3503 ;; Build the thread tree.
3504 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3505   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3506
3507 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3508 if it was already present.
3509
3510 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3511 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3512 Message-IDs will be renamed be renamed to a unique Message-ID before
3513 being entered.
3514
3515 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3516   (let* ((id (mail-header-id header))
3517          (id-dep (and id (intern id dependencies)))
3518          ref ref-dep ref-header)
3519     ;; Enter this `header' in the `dependencies' table.
3520     (cond
3521      ((not id-dep)
3522       (setq header nil))
3523      ;; The first two cases do the normal part: enter a new `header'
3524      ;; in the `dependencies' table.
3525      ((not (boundp id-dep))
3526       (set id-dep (list header)))
3527      ((null (car (symbol-value id-dep)))
3528       (setcar (symbol-value id-dep) header))
3529
3530      ;; From here the `header' was already present in the
3531      ;; `dependencies' table.
3532      (force-new
3533       ;; Overrides an existing entry;
3534       ;; just set the header part of the entry.
3535       (setcar (symbol-value id-dep) header))
3536
3537      ;; Renames the existing `header' to a unique Message-ID.
3538      ((not gnus-summary-ignore-duplicates)
3539       ;; An article with this Message-ID has already been seen.
3540       ;; We rename the Message-ID.
3541       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3542            (list header))
3543       (mail-header-set-id header id))
3544
3545      ;; The last case ignores an existing entry, except it adds any
3546      ;; additional Xrefs (in case the two articles came from different
3547      ;; servers.
3548      ;; Also sets `header' to `nil' meaning that the `dependencies'
3549      ;; table was *not* modified.
3550      (t
3551       (mail-header-set-xref
3552        (car (symbol-value id-dep))
3553        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3554                    "")
3555                (or (mail-header-xref header) "")))
3556       (setq header nil)))
3557
3558     (when header
3559       ;; First check if that we are not creating a References loop.
3560       (setq ref (gnus-parent-id (mail-header-references header)))
3561       (while (and ref
3562                   (setq ref-dep (intern-soft ref dependencies))
3563                   (boundp ref-dep)
3564                   (setq ref-header (car (symbol-value ref-dep))))
3565         (if (string= id ref)
3566             ;; Yuk!  This is a reference loop.  Make the article be a
3567             ;; root article.
3568             (progn
3569               (mail-header-set-references (car (symbol-value id-dep)) "none")
3570               (setq ref nil))
3571           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3572       (setq ref (gnus-parent-id (mail-header-references header)))
3573       (setq ref-dep (intern (or ref "none") dependencies))
3574       (if (boundp ref-dep)
3575           (setcdr (symbol-value ref-dep)
3576                   (nconc (cdr (symbol-value ref-dep))
3577                          (list (symbol-value id-dep))))
3578         (set ref-dep (list nil (symbol-value id-dep)))))
3579     header))
3580
3581 (defun gnus-build-sparse-threads ()
3582   (let ((headers gnus-newsgroup-headers)
3583         (mail-parse-charset gnus-newsgroup-charset)
3584         (gnus-summary-ignore-duplicates t)
3585         header references generation relations
3586         subject child end new-child date)
3587     ;; First we create an alist of generations/relations, where
3588     ;; generations is how much we trust the relation, and the relation
3589     ;; is parent/child.
3590     (gnus-message 7 "Making sparse threads...")
3591     (save-excursion
3592       (nnheader-set-temp-buffer " *gnus sparse threads*")
3593       (while (setq header (pop headers))
3594         (when (and (setq references (mail-header-references header))
3595                    (not (string= references "")))
3596           (insert references)
3597           (setq child (mail-header-id header)
3598                 subject (mail-header-subject header)
3599                 date (mail-header-date header)
3600                 generation 0)
3601           (while (search-backward ">" nil t)
3602             (setq end (1+ (point)))
3603             (when (search-backward "<" nil t)
3604               (setq new-child (buffer-substring (point) end))
3605               (push (list (incf generation)
3606                           child (setq child new-child)
3607                           subject date)
3608                     relations)))
3609           (when child
3610             (push (list (1+ generation) child nil subject) relations))
3611           (erase-buffer)))
3612       (kill-buffer (current-buffer)))
3613     ;; Sort over trustworthiness.
3614     (mapcar
3615      (lambda (relation)
3616        (when (gnus-dependencies-add-header
3617               (make-full-mail-header
3618                gnus-reffed-article-number
3619                (nth 3 relation) "" (or (nth 4 relation) "")
3620                (nth 1 relation)
3621                (or (nth 2 relation) "") 0 0 "")
3622               gnus-newsgroup-dependencies nil)
3623          (push gnus-reffed-article-number gnus-newsgroup-limit)
3624          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3625          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3626                gnus-newsgroup-reads)
3627          (decf gnus-reffed-article-number)))
3628      (sort relations 'car-less-than-car))
3629     (gnus-message 7 "Making sparse threads...done")))
3630
3631 (defun gnus-build-old-threads ()
3632   ;; Look at all the articles that refer back to old articles, and
3633   ;; fetch the headers for the articles that aren't there.  This will
3634   ;; build complete threads - if the roots haven't been expired by the
3635   ;; server, that is.
3636   (let ((mail-parse-charset gnus-newsgroup-charset)
3637         id heads)
3638     (mapatoms
3639      (lambda (refs)
3640        (when (not (car (symbol-value refs)))
3641          (setq heads (cdr (symbol-value refs)))
3642          (while heads
3643            (if (memq (mail-header-number (caar heads))
3644                      gnus-newsgroup-dormant)
3645                (setq heads (cdr heads))
3646              (setq id (symbol-name refs))
3647              (while (and (setq id (gnus-build-get-header id))
3648                          (not (car (gnus-id-to-thread id)))))
3649              (setq heads nil)))))
3650      gnus-newsgroup-dependencies)))
3651
3652 ;; This function has to be called with point after the article number
3653 ;; on the beginning of the line.
3654 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3655   (let ((eol (gnus-point-at-eol))
3656         (buffer (current-buffer))
3657         header)
3658
3659     ;; overview: [num subject from date id refs chars lines misc]
3660     (unwind-protect
3661         (progn
3662           (narrow-to-region (point) eol)
3663           (unless (eobp)
3664             (forward-char))
3665
3666           (setq header
3667                 (make-full-mail-header
3668                  number                 ; number
3669                  (funcall gnus-decode-encoded-word-function
3670                           (nnheader-nov-field)) ; subject
3671                  (funcall gnus-decode-encoded-word-function
3672                           (nnheader-nov-field)) ; from
3673                  (nnheader-nov-field)   ; date
3674                  (nnheader-nov-read-message-id) ; id
3675                  (nnheader-nov-field)   ; refs
3676                  (nnheader-nov-read-integer) ; chars
3677                  (nnheader-nov-read-integer) ; lines
3678                  (unless (eobp)
3679                    (if (looking-at "Xref: ")
3680                        (goto-char (match-end 0)))
3681                    (nnheader-nov-field)) ; Xref
3682                  (nnheader-nov-parse-extra)))) ; extra
3683
3684       (widen))
3685
3686     (when gnus-alter-header-function
3687       (funcall gnus-alter-header-function header))
3688     (gnus-dependencies-add-header header dependencies force-new)))
3689
3690 (defun gnus-build-get-header (id)
3691   "Look through the buffer of NOV lines and find the header to ID.
3692 Enter this line into the dependencies hash table, and return
3693 the id of the parent article (if any)."
3694   (let ((deps gnus-newsgroup-dependencies)
3695         found header)
3696     (prog1
3697         (save-excursion
3698           (set-buffer nntp-server-buffer)
3699           (let ((case-fold-search nil))
3700             (goto-char (point-min))
3701             (while (and (not found)
3702                         (search-forward id nil t))
3703               (beginning-of-line)
3704               (setq found (looking-at
3705                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3706                                    (regexp-quote id))))
3707               (or found (beginning-of-line 2)))
3708             (when found
3709               (beginning-of-line)
3710               (and
3711                (setq header (gnus-nov-parse-line
3712                              (read (current-buffer)) deps))
3713                (gnus-parent-id (mail-header-references header))))))
3714       (when header
3715         (let ((number (mail-header-number header)))
3716           (push number gnus-newsgroup-limit)
3717           (push header gnus-newsgroup-headers)
3718           (if (memq number gnus-newsgroup-unselected)
3719               (progn
3720                 (push number gnus-newsgroup-unreads)
3721                 (setq gnus-newsgroup-unselected
3722                       (delq number gnus-newsgroup-unselected)))
3723             (push number gnus-newsgroup-ancient)))))))
3724
3725 (defun gnus-build-all-threads ()
3726   "Read all the headers."
3727   (let ((gnus-summary-ignore-duplicates t)
3728         (mail-parse-charset gnus-newsgroup-charset)
3729         (dependencies gnus-newsgroup-dependencies)
3730         header article)
3731     (save-excursion
3732       (set-buffer nntp-server-buffer)
3733       (let ((case-fold-search nil))
3734         (goto-char (point-min))
3735         (while (not (eobp))
3736           (ignore-errors
3737             (setq article (read (current-buffer))
3738                   header (gnus-nov-parse-line article dependencies)))
3739           (when header
3740             (save-excursion
3741               (set-buffer gnus-summary-buffer)
3742               (push header gnus-newsgroup-headers)
3743               (if (memq (setq article (mail-header-number header))
3744                         gnus-newsgroup-unselected)
3745                   (progn
3746                     (push article gnus-newsgroup-unreads)
3747                     (setq gnus-newsgroup-unselected
3748                           (delq article gnus-newsgroup-unselected)))
3749                 (push article gnus-newsgroup-ancient)))
3750             (forward-line 1)))))))
3751
3752 (defun gnus-summary-update-article-line (article header)
3753   "Update the line for ARTICLE using HEADERS."
3754   (let* ((id (mail-header-id header))
3755          (thread (gnus-id-to-thread id)))
3756     (unless thread
3757       (error "Article in no thread"))
3758     ;; Update the thread.
3759     (setcar thread header)
3760     (gnus-summary-goto-subject article)
3761     (let* ((datal (gnus-data-find-list article))
3762            (data (car datal))
3763            (length (when (cdr datal)
3764                      (- (gnus-data-pos data)
3765                         (gnus-data-pos (cadr datal)))))
3766            (buffer-read-only nil)
3767            (level (gnus-summary-thread-level)))
3768       (gnus-delete-line)
3769       (gnus-summary-insert-line
3770        header level nil (gnus-article-mark article)
3771        (memq article gnus-newsgroup-replied)
3772        (memq article gnus-newsgroup-expirable)
3773        ;; Only insert the Subject string when it's different
3774        ;; from the previous Subject string.
3775        (if (and
3776             gnus-show-threads
3777             (gnus-subject-equal
3778              (condition-case ()
3779                  (mail-header-subject
3780                   (gnus-data-header
3781                    (cadr
3782                     (gnus-data-find-list
3783                      article
3784                      (gnus-data-list t)))))
3785                ;; Error on the side of excessive subjects.
3786                (error ""))
3787              (mail-header-subject header)))
3788            ""
3789          (mail-header-subject header))
3790        nil (cdr (assq article gnus-newsgroup-scored))
3791        (memq article gnus-newsgroup-processable))
3792       (when length
3793         (gnus-data-update-list
3794          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3795
3796 (defun gnus-summary-update-article (article &optional iheader)
3797   "Update ARTICLE in the summary buffer."
3798   (set-buffer gnus-summary-buffer)
3799   (let* ((header (gnus-summary-article-header article))
3800          (id (mail-header-id header))
3801          (data (gnus-data-find article))
3802          (thread (gnus-id-to-thread id))
3803          (references (mail-header-references header))
3804          (parent
3805           (gnus-id-to-thread
3806            (or (gnus-parent-id
3807                 (when (and references
3808                            (not (equal "" references)))
3809                   references))
3810                "none")))
3811          (buffer-read-only nil)
3812          (old (car thread)))
3813     (when thread
3814       (unless iheader
3815         (setcar thread nil)
3816         (when parent
3817           (delq thread parent)))
3818       (if (gnus-summary-insert-subject id header)
3819        ;; Set the (possibly) new article number in the data structure.
3820           (gnus-data-set-number data (gnus-id-to-article id))
3821         (setcar thread old)
3822         nil))))
3823
3824 (defun gnus-rebuild-thread (id &optional line)
3825   "Rebuild the thread containing ID.
3826 If LINE, insert the rebuilt thread starting on line LINE."
3827   (let ((buffer-read-only nil)
3828         old-pos current thread data)
3829     (if (not gnus-show-threads)
3830         (setq thread (list (car (gnus-id-to-thread id))))
3831       ;; Get the thread this article is part of.
3832       (setq thread (gnus-remove-thread id)))
3833     (setq old-pos (gnus-point-at-bol))
3834     (setq current (save-excursion
3835                     (and (re-search-backward "[\r\n]" nil t)
3836                          (gnus-summary-article-number))))
3837     ;; If this is a gathered thread, we have to go some re-gathering.
3838     (when (stringp (car thread))
3839       (let ((subject (car thread))
3840             roots thr)
3841         (setq thread (cdr thread))
3842         (while thread
3843           (unless (memq (setq thr (gnus-id-to-thread
3844                                    (gnus-root-id
3845                                     (mail-header-id (caar thread)))))
3846                         roots)
3847             (push thr roots))
3848           (setq thread (cdr thread)))
3849         ;; We now have all (unique) roots.
3850         (if (= (length roots) 1)
3851             ;; All the loose roots are now one solid root.
3852             (setq thread (car roots))
3853           (setq thread (cons subject (gnus-sort-threads roots))))))
3854     (let (threads)
3855       ;; We then insert this thread into the summary buffer.
3856       (when line
3857         (goto-char (point-min))
3858         (forward-line (1- line)))
3859       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3860         (if gnus-show-threads
3861             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3862           (gnus-summary-prepare-unthreaded thread))
3863         (setq data (nreverse gnus-newsgroup-data))
3864         (setq threads gnus-newsgroup-threads))
3865       ;; We splice the new data into the data structure.
3866       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3867       ;;!!! then we want to insert at the beginning of the buffer.
3868       ;;!!! That happens to be true with Gnus now, but that may
3869       ;;!!! change in the future.  Perhaps.
3870       (gnus-data-enter-list
3871        (if line nil current) data (- (point) old-pos))
3872       (setq gnus-newsgroup-threads
3873             (nconc threads gnus-newsgroup-threads))
3874       (gnus-data-compute-positions))))
3875
3876 (defun gnus-number-to-header (number)
3877   "Return the header for article NUMBER."
3878   (let ((headers gnus-newsgroup-headers))
3879     (while (and headers
3880                 (not (= number (mail-header-number (car headers)))))
3881       (pop headers))
3882     (when headers
3883       (car headers))))
3884
3885 (defun gnus-parent-headers (in-headers &optional generation)
3886   "Return the headers of the GENERATIONeth parent of HEADERS."
3887   (unless generation
3888     (setq generation 1))
3889   (let ((parent t)
3890         (headers in-headers)
3891         references)
3892     (while (and parent
3893                 (not (zerop generation))
3894                 (setq references (mail-header-references headers)))
3895       (setq headers (if (and references
3896                              (setq parent (gnus-parent-id references)))
3897                         (car (gnus-id-to-thread parent))
3898                       nil))
3899       (decf generation))
3900     (and (not (eq headers in-headers))
3901          headers)))
3902
3903 (defun gnus-id-to-thread (id)
3904   "Return the (sub-)thread where ID appears."
3905   (gnus-gethash id gnus-newsgroup-dependencies))
3906
3907 (defun gnus-id-to-article (id)
3908   "Return the article number of ID."
3909   (let ((thread (gnus-id-to-thread id)))
3910     (when (and thread
3911                (car thread))
3912       (mail-header-number (car thread)))))
3913
3914 (defun gnus-id-to-header (id)
3915   "Return the article headers of ID."
3916   (car (gnus-id-to-thread id)))
3917
3918 (defun gnus-article-displayed-root-p (article)
3919   "Say whether ARTICLE is a root(ish) article."
3920   (let ((level (gnus-summary-thread-level article))
3921         (refs (mail-header-references  (gnus-summary-article-header article)))
3922         particle)
3923     (cond
3924      ((null level) nil)
3925      ((zerop level) t)
3926      ((null refs) t)
3927      ((null (gnus-parent-id refs)) t)
3928      ((and (= 1 level)
3929            (null (setq particle (gnus-id-to-article
3930                                  (gnus-parent-id refs))))
3931            (null (gnus-summary-thread-level particle)))))))
3932
3933 (defun gnus-root-id (id)
3934   "Return the id of the root of the thread where ID appears."
3935   (let (last-id prev)
3936     (while (and id (setq prev (car (gnus-id-to-thread id))))
3937       (setq last-id id
3938             id (gnus-parent-id (mail-header-references prev))))
3939     last-id))
3940
3941 (defun gnus-articles-in-thread (thread)
3942   "Return the list of articles in THREAD."
3943   (cons (mail-header-number (car thread))
3944         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3945
3946 (defun gnus-remove-thread (id &optional dont-remove)
3947   "Remove the thread that has ID in it."
3948   (let (headers thread last-id)
3949     ;; First go up in this thread until we find the root.
3950     (setq last-id (gnus-root-id id)
3951           headers (message-flatten-list (gnus-id-to-thread last-id)))
3952     ;; We have now found the real root of this thread.  It might have
3953     ;; been gathered into some loose thread, so we have to search
3954     ;; through the threads to find the thread we wanted.
3955     (let ((threads gnus-newsgroup-threads)
3956           sub)
3957       (while threads
3958         (setq sub (car threads))
3959         (if (stringp (car sub))
3960             ;; This is a gathered thread, so we look at the roots
3961             ;; below it to find whether this article is in this
3962             ;; gathered root.
3963             (progn
3964               (setq sub (cdr sub))
3965               (while sub
3966                 (when (member (caar sub) headers)
3967                   (setq thread (car threads)
3968                         threads nil
3969                         sub nil))
3970                 (setq sub (cdr sub))))
3971           ;; It's an ordinary thread, so we check it.
3972           (when (eq (car sub) (car headers))
3973             (setq thread sub
3974                   threads nil)))
3975         (setq threads (cdr threads)))
3976       ;; If this article is in no thread, then it's a root.
3977       (if thread
3978           (unless dont-remove
3979             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3980         (setq thread (gnus-id-to-thread last-id)))
3981       (when thread
3982         (prog1
3983             thread                      ; We return this thread.
3984           (unless dont-remove
3985             (if (stringp (car thread))
3986                 (progn
3987                   ;; If we use dummy roots, then we have to remove the
3988                   ;; dummy root as well.
3989                   (when (eq gnus-summary-make-false-root 'dummy)
3990                     ;; We go to the dummy root by going to
3991                     ;; the first sub-"thread", and then one line up.
3992                     (gnus-summary-goto-article
3993                      (mail-header-number (caadr thread)))
3994                     (forward-line -1)
3995                     (gnus-delete-line)
3996                     (gnus-data-compute-positions))
3997                   (setq thread (cdr thread))
3998                   (while thread
3999                     (gnus-remove-thread-1 (car thread))
4000                     (setq thread (cdr thread))))
4001               (gnus-remove-thread-1 thread))))))))
4002
4003 (defun gnus-remove-thread-1 (thread)
4004   "Remove the thread THREAD recursively."
4005   (let ((number (mail-header-number (pop thread)))
4006         d)
4007     (setq thread (reverse thread))
4008     (while thread
4009       (gnus-remove-thread-1 (pop thread)))
4010     (when (setq d (gnus-data-find number))
4011       (goto-char (gnus-data-pos d))
4012       (gnus-summary-show-thread)
4013       (gnus-data-remove
4014        number
4015        (- (gnus-point-at-bol)
4016           (prog1
4017               (1+ (gnus-point-at-eol))
4018             (gnus-delete-line)))))))
4019
4020 (defun gnus-sort-threads-1 (threads func)
4021   (sort (mapcar (lambda (thread)
4022                   (cons (car thread)
4023                         (and (cdr thread)
4024                              (gnus-sort-threads-1 (cdr thread) func))))
4025                 threads) func))
4026
4027 (defun gnus-sort-threads (threads)
4028   "Sort THREADS."
4029   (if (not gnus-thread-sort-functions)
4030       threads
4031     (gnus-message 8 "Sorting threads...")
4032     (prog1
4033         (gnus-sort-threads-1
4034          threads
4035          (gnus-make-sort-function gnus-thread-sort-functions))
4036       (gnus-message 8 "Sorting threads...done"))))
4037
4038 (defun gnus-sort-articles (articles)
4039   "Sort ARTICLES."
4040   (when gnus-article-sort-functions
4041     (gnus-message 7 "Sorting articles...")
4042     (prog1
4043         (setq gnus-newsgroup-headers
4044               (sort articles (gnus-make-sort-function
4045                               gnus-article-sort-functions)))
4046       (gnus-message 7 "Sorting articles...done"))))
4047
4048 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4049 (defmacro gnus-thread-header (thread)
4050   "Return header of first article in THREAD.
4051 Note that THREAD must never, ever be anything else than a variable -
4052 using some other form will lead to serious barfage."
4053   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4054   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4055   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4056         (vector thread) 2))
4057
4058 (defsubst gnus-article-sort-by-number (h1 h2)
4059   "Sort articles by article number."
4060   (< (mail-header-number h1)
4061      (mail-header-number h2)))
4062
4063 (defun gnus-thread-sort-by-number (h1 h2)
4064   "Sort threads by root article number."
4065   (gnus-article-sort-by-number
4066    (gnus-thread-header h1) (gnus-thread-header h2)))
4067
4068 (defsubst gnus-article-sort-by-lines (h1 h2)
4069   "Sort articles by article Lines header."
4070   (< (mail-header-lines h1)
4071      (mail-header-lines h2)))
4072
4073 (defun gnus-thread-sort-by-lines (h1 h2)
4074   "Sort threads by root article Lines header."
4075   (gnus-article-sort-by-lines
4076    (gnus-thread-header h1) (gnus-thread-header h2)))
4077
4078 (defsubst gnus-article-sort-by-chars (h1 h2)
4079   "Sort articles by octet length."
4080   (< (mail-header-chars h1)
4081      (mail-header-chars h2)))
4082
4083 (defun gnus-thread-sort-by-chars (h1 h2)
4084   "Sort threads by root article octet length."
4085   (gnus-article-sort-by-chars
4086    (gnus-thread-header h1) (gnus-thread-header h2)))
4087
4088 (defsubst gnus-article-sort-by-author (h1 h2)
4089   "Sort articles by root author."
4090   (string-lessp
4091    (let ((extract (funcall
4092                    gnus-extract-address-components
4093                    (mail-header-from h1))))
4094      (or (car extract) (cadr extract) ""))
4095    (let ((extract (funcall
4096                    gnus-extract-address-components
4097                    (mail-header-from h2))))
4098      (or (car extract) (cadr extract) ""))))
4099
4100 (defun gnus-thread-sort-by-author (h1 h2)
4101   "Sort threads by root author."
4102   (gnus-article-sort-by-author
4103    (gnus-thread-header h1)  (gnus-thread-header h2)))
4104
4105 (defsubst gnus-article-sort-by-subject (h1 h2)
4106   "Sort articles by root subject."
4107   (string-lessp
4108    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4109    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4110
4111 (defun gnus-thread-sort-by-subject (h1 h2)
4112   "Sort threads by root subject."
4113   (gnus-article-sort-by-subject
4114    (gnus-thread-header h1) (gnus-thread-header h2)))
4115
4116 (defsubst gnus-article-sort-by-date (h1 h2)
4117   "Sort articles by root article date."
4118   (time-less-p
4119    (gnus-date-get-time (mail-header-date h1))
4120    (gnus-date-get-time (mail-header-date h2))))
4121
4122 (defun gnus-thread-sort-by-date (h1 h2)
4123   "Sort threads by root article date."
4124   (gnus-article-sort-by-date
4125    (gnus-thread-header h1) (gnus-thread-header h2)))
4126
4127 (defsubst gnus-article-sort-by-score (h1 h2)
4128   "Sort articles by root article score.
4129 Unscored articles will be counted as having a score of zero."
4130   (> (or (cdr (assq (mail-header-number h1)
4131                     gnus-newsgroup-scored))
4132          gnus-summary-default-score 0)
4133      (or (cdr (assq (mail-header-number h2)
4134                     gnus-newsgroup-scored))
4135          gnus-summary-default-score 0)))
4136
4137 (defun gnus-thread-sort-by-score (h1 h2)
4138   "Sort threads by root article score."
4139   (gnus-article-sort-by-score
4140    (gnus-thread-header h1) (gnus-thread-header h2)))
4141
4142 (defun gnus-thread-sort-by-total-score (h1 h2)
4143   "Sort threads by the sum of all scores in the thread.
4144 Unscored articles will be counted as having a score of zero."
4145   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4146
4147 (defun gnus-thread-total-score (thread)
4148   ;; This function find the total score of THREAD.
4149   (cond ((null thread)
4150          0)
4151         ((consp thread)
4152          (if (stringp (car thread))
4153              (apply gnus-thread-score-function 0
4154                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4155            (gnus-thread-total-score-1 thread)))
4156         (t
4157          (gnus-thread-total-score-1 (list thread)))))
4158
4159 (defun gnus-thread-total-score-1 (root)
4160   ;; This function find the total score of the thread below ROOT.
4161   (setq root (car root))
4162   (apply gnus-thread-score-function
4163          (or (append
4164               (mapcar 'gnus-thread-total-score
4165                       (cdr (gnus-id-to-thread (mail-header-id root))))
4166               (when (> (mail-header-number root) 0)
4167                 (list (or (cdr (assq (mail-header-number root)
4168                                      gnus-newsgroup-scored))
4169                           gnus-summary-default-score 0))))
4170              (list gnus-summary-default-score)
4171              '(0))))
4172
4173 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4174 (defvar gnus-tmp-prev-subject nil)
4175 (defvar gnus-tmp-false-parent nil)
4176 (defvar gnus-tmp-root-expunged nil)
4177 (defvar gnus-tmp-dummy-line nil)
4178
4179 (eval-when-compile (defvar gnus-tmp-header))
4180 (defun gnus-extra-header (type &optional header)
4181   "Return the extra header of TYPE."
4182   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4183       ""))
4184
4185 (defvar gnus-tmp-thread-tree-header-string "")
4186
4187 (defvar gnus-sum-thread-tree-root "> "
4188   "With %B spec, used for the root of a thread.
4189 If nil, use subject instead.")
4190 (defvar gnus-sum-thread-tree-single-indent ""
4191   "With %B spec, used for a thread with just one message.
4192 If nil, use subject instead.")
4193 (defvar gnus-sum-thread-tree-vertical "| "
4194   "With %B spec, used for drawing a vertical line.")
4195 (defvar gnus-sum-thread-tree-indent "  "
4196   "With %B spec, used for indenting.")
4197 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4198   "With %B spec, used for a leaf with brothers.")
4199 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4200   "With %B spec, used for a leaf without brothers.")
4201
4202 (defun gnus-summary-prepare-threads (threads)
4203   "Prepare summary buffer from THREADS and indentation LEVEL.
4204 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4205 or a straight list of headers."
4206   (gnus-message 7 "Generating summary...")
4207
4208   (setq gnus-newsgroup-threads threads)
4209   (beginning-of-line)
4210
4211   (let ((gnus-tmp-level 0)
4212         (default-score (or gnus-summary-default-score 0))
4213         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4214         thread number subject stack state gnus-tmp-gathered beg-match
4215         new-roots gnus-tmp-new-adopts thread-end
4216         gnus-tmp-header gnus-tmp-unread
4217         gnus-tmp-replied gnus-tmp-subject-or-nil
4218         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4219         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4220         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4221         tree-stack)
4222
4223     (setq gnus-tmp-prev-subject nil)
4224
4225     (if (vectorp (car threads))
4226         ;; If this is a straight (sic) list of headers, then a
4227         ;; threaded summary display isn't required, so we just create
4228         ;; an unthreaded one.
4229         (gnus-summary-prepare-unthreaded threads)
4230
4231       ;; Do the threaded display.
4232
4233       (while (or threads stack gnus-tmp-new-adopts new-roots)
4234
4235         (if (and (= gnus-tmp-level 0)
4236                  (or (not stack)
4237                      (= (caar stack) 0))
4238                  (not gnus-tmp-false-parent)
4239                  (or gnus-tmp-new-adopts new-roots))
4240             (if gnus-tmp-new-adopts
4241                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4242                       thread (list (car gnus-tmp-new-adopts))
4243                       gnus-tmp-header (caar thread)
4244                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4245               (when new-roots
4246                 (setq thread (list (car new-roots))
4247                       gnus-tmp-header (caar thread)
4248                       new-roots (cdr new-roots))))
4249
4250           (if threads
4251               ;; If there are some threads, we do them before the
4252               ;; threads on the stack.
4253               (setq thread threads
4254                     gnus-tmp-header (caar thread))
4255             ;; There were no current threads, so we pop something off
4256             ;; the stack.
4257             (setq state (car stack)
4258                   gnus-tmp-level (car state)
4259                   tree-stack (cadr state)
4260                   thread (caddr state)
4261                   stack (cdr stack)
4262                   gnus-tmp-header (caar thread))))
4263
4264         (setq gnus-tmp-false-parent nil)
4265         (setq gnus-tmp-root-expunged nil)
4266         (setq thread-end nil)
4267
4268         (if (stringp gnus-tmp-header)
4269             ;; The header is a dummy root.
4270             (cond
4271              ((eq gnus-summary-make-false-root 'adopt)
4272               ;; We let the first article adopt the rest.
4273               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4274                                                (cddar thread)))
4275               (setq gnus-tmp-gathered
4276                     (nconc (mapcar
4277                             (lambda (h) (mail-header-number (car h)))
4278                             (cddar thread))
4279                            gnus-tmp-gathered))
4280               (setq thread (cons (list (caar thread)
4281                                        (cadar thread))
4282                                  (cdr thread)))
4283               (setq gnus-tmp-level -1
4284                     gnus-tmp-false-parent t))
4285              ((eq gnus-summary-make-false-root 'empty)
4286               ;; We print adopted articles with empty subject fields.
4287               (setq gnus-tmp-gathered
4288                     (nconc (mapcar
4289                             (lambda (h) (mail-header-number (car h)))
4290                             (cddar thread))
4291                            gnus-tmp-gathered))
4292               (setq gnus-tmp-level -1))
4293              ((eq gnus-summary-make-false-root 'dummy)
4294               ;; We remember that we probably want to output a dummy
4295               ;; root.
4296               (setq gnus-tmp-dummy-line gnus-tmp-header)
4297               (setq gnus-tmp-prev-subject gnus-tmp-header))
4298              (t
4299               ;; We do not make a root for the gathered
4300               ;; sub-threads at all.
4301               (setq gnus-tmp-level -1)))
4302
4303           (setq number (mail-header-number gnus-tmp-header)
4304                 subject (mail-header-subject gnus-tmp-header))
4305
4306           (cond
4307            ;; If the thread has changed subject, we might want to make
4308            ;; this subthread into a root.
4309            ((and (null gnus-thread-ignore-subject)
4310                  (not (zerop gnus-tmp-level))
4311                  gnus-tmp-prev-subject
4312                  (not (inline
4313                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4314             (setq new-roots (nconc new-roots (list (car thread)))
4315                   thread-end t
4316                   gnus-tmp-header nil))
4317            ;; If the article lies outside the current limit,
4318            ;; then we do not display it.
4319            ((not (memq number gnus-newsgroup-limit))
4320             (setq gnus-tmp-gathered
4321                   (nconc (mapcar
4322                           (lambda (h) (mail-header-number (car h)))
4323                           (cdar thread))
4324                          gnus-tmp-gathered))
4325             (setq gnus-tmp-new-adopts (if (cdar thread)
4326                                           (append gnus-tmp-new-adopts
4327                                                   (cdar thread))
4328                                         gnus-tmp-new-adopts)
4329                   thread-end t
4330                   gnus-tmp-header nil)
4331             (when (zerop gnus-tmp-level)
4332               (setq gnus-tmp-root-expunged t)))
4333            ;; Perhaps this article is to be marked as read?
4334            ((and gnus-summary-mark-below
4335                  (< (or (cdr (assq number gnus-newsgroup-scored))
4336                         default-score)
4337                     gnus-summary-mark-below)
4338                  ;; Don't touch sparse articles.
4339                  (not (gnus-summary-article-sparse-p number))
4340                  (not (gnus-summary-article-ancient-p number)))
4341             (setq gnus-newsgroup-unreads
4342                   (delq number gnus-newsgroup-unreads))
4343             (if gnus-newsgroup-auto-expire
4344                 (push number gnus-newsgroup-expirable)
4345               (push (cons number gnus-low-score-mark)
4346                     gnus-newsgroup-reads))))
4347
4348           (when gnus-tmp-header
4349             ;; We may have an old dummy line to output before this
4350             ;; article.
4351             (when (and gnus-tmp-dummy-line
4352                        (gnus-subject-equal
4353                         gnus-tmp-dummy-line
4354                         (mail-header-subject gnus-tmp-header)))
4355               (gnus-summary-insert-dummy-line
4356                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4357               (setq gnus-tmp-dummy-line nil))
4358
4359             ;; Compute the mark.
4360             (setq gnus-tmp-unread (gnus-article-mark number))
4361
4362             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4363                                   gnus-tmp-header gnus-tmp-level)
4364                   gnus-newsgroup-data)
4365
4366             ;; Actually insert the line.
4367             (setq
4368              gnus-tmp-subject-or-nil
4369              (cond
4370               ((and gnus-thread-ignore-subject
4371                     gnus-tmp-prev-subject
4372                     (not (inline (gnus-subject-equal
4373                                   gnus-tmp-prev-subject subject))))
4374                subject)
4375               ((zerop gnus-tmp-level)
4376                (if (and (eq gnus-summary-make-false-root 'empty)
4377                         (memq number gnus-tmp-gathered)
4378                         gnus-tmp-prev-subject
4379                         (inline (gnus-subject-equal
4380                                  gnus-tmp-prev-subject subject)))
4381                    gnus-summary-same-subject
4382                  subject))
4383               (t gnus-summary-same-subject)))
4384             (if (and (eq gnus-summary-make-false-root 'adopt)
4385                      (= gnus-tmp-level 1)
4386                      (memq number gnus-tmp-gathered))
4387                 (setq gnus-tmp-opening-bracket ?\<
4388                       gnus-tmp-closing-bracket ?\>)
4389               (setq gnus-tmp-opening-bracket ?\[
4390                     gnus-tmp-closing-bracket ?\]))
4391             (setq
4392              gnus-tmp-indentation
4393              (aref gnus-thread-indent-array gnus-tmp-level)
4394              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4395              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4396                                 gnus-summary-default-score 0)
4397              gnus-tmp-score-char
4398              (if (or (null gnus-summary-default-score)
4399                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4400                          gnus-summary-zcore-fuzz))
4401                  ?                      ;Whitespace
4402                (if (< gnus-tmp-score gnus-summary-default-score)
4403                    gnus-score-below-mark gnus-score-over-mark))
4404              gnus-tmp-replied
4405              (cond ((memq number gnus-newsgroup-processable)
4406                     gnus-process-mark)
4407                    ((memq number gnus-newsgroup-cached)
4408                     gnus-cached-mark)
4409                    ((memq number gnus-newsgroup-replied)
4410                     gnus-replied-mark)
4411                    ((memq number gnus-newsgroup-forwarded)
4412                     gnus-forwarded-mark)
4413                    ((memq number gnus-newsgroup-saved)
4414                     gnus-saved-mark)
4415                    ((memq number gnus-newsgroup-recent)
4416                     gnus-recent-mark)
4417                    ((memq number gnus-newsgroup-unseen)
4418                     gnus-unseen-mark)
4419                    (t gnus-no-mark))
4420              gnus-tmp-from (mail-header-from gnus-tmp-header)
4421              gnus-tmp-name
4422              (cond
4423               ((string-match "<[^>]+> *$" gnus-tmp-from)
4424                (setq beg-match (match-beginning 0))
4425                (or (and (string-match "^\".+\"" gnus-tmp-from)
4426                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4427                    (substring gnus-tmp-from 0 beg-match)))
4428               ((string-match "(.+)" gnus-tmp-from)
4429                (substring gnus-tmp-from
4430                           (1+ (match-beginning 0)) (1- (match-end 0))))
4431               (t gnus-tmp-from))
4432              gnus-tmp-thread-tree-header-string
4433              (cond
4434               ((not gnus-show-threads) "")
4435               ((zerop gnus-tmp-level)
4436                (if (cdar thread)
4437                    (or gnus-sum-thread-tree-root subject)
4438                  (or gnus-sum-thread-tree-single-indent subject)))
4439               (t
4440                (concat (apply 'concat
4441                               (mapcar (lambda (item)
4442                                         (if (= item 1)
4443                                             gnus-sum-thread-tree-vertical
4444                                           gnus-sum-thread-tree-indent))
4445                                       (cdr (reverse tree-stack))))
4446                        (if (nth 1 thread)
4447                            gnus-sum-thread-tree-leaf-with-other
4448                          gnus-sum-thread-tree-single-leaf)))))
4449             (when (string= gnus-tmp-name "")
4450               (setq gnus-tmp-name gnus-tmp-from))
4451             (unless (numberp gnus-tmp-lines)
4452               (setq gnus-tmp-lines -1))
4453             (if (= gnus-tmp-lines -1)
4454                 (setq gnus-tmp-lines "?")
4455               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4456             (gnus-put-text-property
4457              (point)
4458              (progn (eval gnus-summary-line-format-spec) (point))
4459              'gnus-number number)
4460             (when gnus-visual-p
4461               (forward-line -1)
4462               (gnus-run-hooks 'gnus-summary-update-hook)
4463               (forward-line 1))
4464
4465             (setq gnus-tmp-prev-subject subject)))
4466
4467         (when (nth 1 thread)
4468           (push (list (max 0 gnus-tmp-level)
4469                       (copy-list tree-stack)
4470                       (nthcdr 1 thread))
4471                 stack))
4472         (push (if (nth 1 thread) 1 0) tree-stack)
4473         (incf gnus-tmp-level)
4474         (setq threads (if thread-end nil (cdar thread)))
4475         (unless threads
4476           (setq gnus-tmp-level 0)))))
4477   (gnus-message 7 "Generating summary...done"))
4478
4479 (defun gnus-summary-prepare-unthreaded (headers)
4480   "Generate an unthreaded summary buffer based on HEADERS."
4481   (let (header number mark)
4482
4483     (beginning-of-line)
4484
4485     (while headers
4486       ;; We may have to root out some bad articles...
4487       (when (memq (setq number (mail-header-number
4488                                 (setq header (pop headers))))
4489                   gnus-newsgroup-limit)
4490         ;; Mark article as read when it has a low score.
4491         (when (and gnus-summary-mark-below
4492                    (< (or (cdr (assq number gnus-newsgroup-scored))
4493                           gnus-summary-default-score 0)
4494                       gnus-summary-mark-below)
4495                    (not (gnus-summary-article-ancient-p number)))
4496           (setq gnus-newsgroup-unreads
4497                 (delq number gnus-newsgroup-unreads))
4498           (if gnus-newsgroup-auto-expire
4499               (push number gnus-newsgroup-expirable)
4500             (push (cons number gnus-low-score-mark)
4501                   gnus-newsgroup-reads)))
4502
4503         (setq mark (gnus-article-mark number))
4504         (push (gnus-data-make number mark (1+ (point)) header 0)
4505               gnus-newsgroup-data)
4506         (gnus-summary-insert-line
4507          header 0 number
4508          mark (memq number gnus-newsgroup-replied)
4509          (memq number gnus-newsgroup-expirable)
4510          (mail-header-subject header) nil
4511          (cdr (assq number gnus-newsgroup-scored))
4512          (memq number gnus-newsgroup-processable))))))
4513
4514 (defun gnus-summary-remove-list-identifiers ()
4515   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4516   (let ((regexp (if (consp gnus-list-identifiers)
4517                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4518                   gnus-list-identifiers))
4519         changed subject)
4520     (when regexp
4521       (dolist (header gnus-newsgroup-headers)
4522         (setq subject (mail-header-subject header)
4523               changed nil)
4524         (while (string-match
4525                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4526                 subject)
4527           (setq subject
4528                 (concat (substring subject 0 (match-beginning 2))
4529                         (substring subject (match-end 0)))
4530                 changed t))
4531         (when (and changed
4532                    (string-match
4533                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4534           (setq subject
4535                 (concat (substring subject 0 (match-beginning 1))
4536                         (substring subject (match-end 1)))))
4537         (when changed
4538           (mail-header-set-subject header subject))))))
4539
4540 (defun gnus-fetch-headers (articles)
4541   "Fetch headers of ARTICLES."
4542   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4543     (gnus-message 5 "Fetching headers for %s..." name)
4544     (prog1
4545         (if (eq 'nov
4546                 (setq gnus-headers-retrieved-by
4547                       (gnus-retrieve-headers
4548                        articles gnus-newsgroup-name
4549                        ;; We might want to fetch old headers, but
4550                        ;; not if there is only 1 article.
4551                        (and (or (and
4552                                  (not (eq gnus-fetch-old-headers 'some))
4553                                  (not (numberp gnus-fetch-old-headers)))
4554                                 (> (length articles) 1))
4555                             gnus-fetch-old-headers))))
4556             (gnus-get-newsgroup-headers-xover
4557              articles nil nil gnus-newsgroup-name t)
4558           (gnus-get-newsgroup-headers))
4559       (gnus-message 5 "Fetching headers for %s...done" name))))
4560
4561 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4562   "Select newsgroup GROUP.
4563 If READ-ALL is non-nil, all articles in the group are selected.
4564 If SELECT-ARTICLES, only select those articles from GROUP."
4565   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4566          ;;!!! Dirty hack; should be removed.
4567          (gnus-summary-ignore-duplicates
4568           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4569               t
4570             gnus-summary-ignore-duplicates))
4571          (info (nth 2 entry))
4572          articles fetched-articles cached)
4573
4574     (unless (gnus-check-server
4575              (set (make-local-variable 'gnus-current-select-method)
4576                   (gnus-find-method-for-group group)))
4577       (error "Couldn't open server"))
4578
4579     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4580         (gnus-activate-group group)     ; Or we can activate it...
4581         (progn                          ; Or we bug out.
4582           (when (equal major-mode 'gnus-summary-mode)
4583             (kill-buffer (current-buffer)))
4584           (error "Couldn't activate group %s: %s"
4585                  group (gnus-status-message group))))
4586
4587     (unless (gnus-request-group group t)
4588       (when (equal major-mode 'gnus-summary-mode)
4589         (kill-buffer (current-buffer)))
4590       (error "Couldn't request group %s: %s"
4591              group (gnus-status-message group)))
4592
4593     (setq gnus-newsgroup-name group
4594           gnus-newsgroup-unselected nil
4595           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4596
4597     (let ((display (gnus-group-find-parameter group 'display)))
4598       (setq gnus-newsgroup-display
4599             (cond
4600              ((not (zerop (or (car-safe read-all) 0)))
4601               ;; The user entered the group with C-u SPC/RET, let's show
4602               ;; all articles.
4603               'gnus-not-ignore)
4604              ((eq display 'all)
4605               'gnus-not-ignore)
4606              ((arrayp display)
4607               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4608              ((numberp display)
4609               ;; The following is probably the "correct" solution, but
4610               ;; it makes Gnus fetch all headers and then limit the
4611               ;; articles (which is slow), so instead we hack the
4612               ;; select-articles parameter instead. -- Simon Josefsson
4613               ;; <jas@kth.se>
4614               ;;
4615               ;; (gnus-byte-compile
4616               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4617               ;;                         display)))))
4618               (setq select-articles
4619                     (gnus-uncompress-range
4620                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4621                              (if (> tmp 0)
4622                                  tmp
4623                                1))
4624                            (cdr (gnus-active group)))))
4625               nil)
4626              (t
4627               nil))))
4628
4629     (gnus-summary-setup-default-charset)
4630
4631     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4632     (when (gnus-virtual-group-p group)
4633       (setq cached gnus-newsgroup-cached))
4634
4635     (setq gnus-newsgroup-unreads
4636           (gnus-set-difference
4637            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4638            gnus-newsgroup-dormant))
4639
4640     (setq gnus-newsgroup-processable nil)
4641
4642     (gnus-update-read-articles group gnus-newsgroup-unreads)
4643
4644     ;; Adjust and set lists of article marks.
4645     (when info
4646       (gnus-adjust-marked-articles info))
4647
4648     (if (setq articles select-articles)
4649         (setq gnus-newsgroup-unselected
4650               (gnus-sorted-intersection
4651                gnus-newsgroup-unreads
4652                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4653       (setq articles (gnus-articles-to-read group read-all)))
4654
4655     (cond
4656      ((null articles)
4657       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4658       'quit)
4659      ((eq articles 0) nil)
4660      (t
4661       ;; Init the dependencies hash table.
4662       (setq gnus-newsgroup-dependencies
4663             (gnus-make-hashtable (length articles)))
4664       (gnus-set-global-variables)
4665       ;; Retrieve the headers and read them in.
4666       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4667
4668       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4669       (when cached
4670         (setq gnus-newsgroup-cached cached))
4671
4672       ;; Suppress duplicates?
4673       (when gnus-suppress-duplicates
4674         (gnus-dup-suppress-articles))
4675
4676       ;; Set the initial limit.
4677       (setq gnus-newsgroup-limit (copy-sequence articles))
4678       ;; Remove canceled articles from the list of unread articles.
4679       (setq fetched-articles
4680             (mapcar (lambda (headers) (mail-header-number headers))
4681                     gnus-newsgroup-headers))
4682       (setq gnus-newsgroup-articles fetched-articles)
4683       (setq gnus-newsgroup-unreads
4684             (gnus-set-sorted-intersection
4685              gnus-newsgroup-unreads fetched-articles))
4686
4687       ;; The `seen' marks are treated specially.
4688       (if (not gnus-newsgroup-seen)
4689           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4690         (dolist (article gnus-newsgroup-articles)
4691           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4692             (push article gnus-newsgroup-unseen)))
4693         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4694
4695       ;; Removed marked articles that do not exist.
4696       (gnus-update-missing-marks
4697        (gnus-sorted-complement fetched-articles articles))
4698       ;; We might want to build some more threads first.
4699       (when (and gnus-fetch-old-headers
4700                  (eq gnus-headers-retrieved-by 'nov))
4701         (if (eq gnus-fetch-old-headers 'invisible)
4702             (gnus-build-all-threads)
4703           (gnus-build-old-threads)))
4704       ;; Let the Gnus agent mark articles as read.
4705       (when gnus-agent
4706         (gnus-agent-get-undownloaded-list))
4707       ;; Remove list identifiers from subject
4708       (when gnus-list-identifiers
4709         (gnus-summary-remove-list-identifiers))
4710       ;; Check whether auto-expire is to be done in this group.
4711       (setq gnus-newsgroup-auto-expire
4712             (gnus-group-auto-expirable-p group))
4713       ;; Set up the article buffer now, if necessary.
4714       (unless gnus-single-article-buffer
4715         (gnus-article-setup-buffer))
4716       ;; First and last article in this newsgroup.
4717       (when gnus-newsgroup-headers
4718         (setq gnus-newsgroup-begin
4719               (mail-header-number (car gnus-newsgroup-headers))
4720               gnus-newsgroup-end
4721               (mail-header-number
4722                (gnus-last-element gnus-newsgroup-headers))))
4723       ;; GROUP is successfully selected.
4724       (or gnus-newsgroup-headers t)))))
4725
4726 (defun gnus-summary-display-make-predicate (display)
4727   (require 'gnus-agent)
4728   (when (= (length display) 1)
4729     (setq display (car display)))
4730   (unless gnus-summary-display-cache
4731     (dolist (elem (append (list (cons 'read 'read)
4732                                 (cons 'unseen 'unseen))
4733                           gnus-article-mark-lists))
4734       (push (cons (cdr elem)
4735                   (gnus-byte-compile
4736                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4737             gnus-summary-display-cache)))
4738   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4739     (gnus-get-predicate display)))
4740
4741 ;; Uses the dynamically bound `number' variable.
4742 (defvar number)
4743 (defun gnus-article-marked-p (type &optional article)
4744   (let ((article (or article number)))
4745     (cond
4746      ((eq type 'tick)
4747       (memq article gnus-newsgroup-marked))
4748      ((eq type 'unsend)
4749       (memq article gnus-newsgroup-unsendable))
4750      ((eq type 'undownload)
4751       (memq article gnus-newsgroup-undownloaded))
4752      ((eq type 'download)
4753       (memq article gnus-newsgroup-downloadable))
4754      ((eq type 'unread)
4755       (memq article gnus-newsgroup-unreads))
4756      ((eq type 'read)
4757       (memq article gnus-newsgroup-reads))
4758      ((eq type 'dormant)
4759       (memq article gnus-newsgroup-dormant) )
4760      ((eq type 'expire)
4761       (memq article gnus-newsgroup-expirable))
4762      ((eq type 'reply)
4763       (memq article gnus-newsgroup-replied))
4764      ((eq type 'killed)
4765       (memq article gnus-newsgroup-killed))
4766      ((eq type 'bookmark)
4767       (assq article gnus-newsgroup-bookmarks))
4768      ((eq type 'score)
4769       (assq article gnus-newsgroup-scored))
4770      ((eq type 'save)
4771       (memq article gnus-newsgroup-saved))
4772      ((eq type 'cache)
4773       (memq article gnus-newsgroup-cached))
4774      ((eq type 'forward)
4775       (memq article gnus-newsgroup-forwarded))
4776      ((eq type 'seen)
4777       (not (memq article gnus-newsgroup-unseen)))
4778      ((eq type 'recent)
4779       (memq article gnus-newsgroup-recent))
4780      (t t))))
4781
4782 (defun gnus-articles-to-read (group &optional read-all)
4783   "Find out what articles the user wants to read."
4784   (let* ((articles
4785           ;; Select all articles if `read-all' is non-nil, or if there
4786           ;; are no unread articles.
4787           (if (or read-all
4788                   (and (zerop (length gnus-newsgroup-marked))
4789                        (zerop (length gnus-newsgroup-unreads)))
4790                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4791               ;; We want to select the headers for all the articles in
4792               ;; the group, so we select either all the active
4793               ;; articles in the group, or (if that's nil), the
4794               ;; articles in the cache.
4795               (or
4796                (gnus-uncompress-range (gnus-active group))
4797                (gnus-cache-articles-in-group group))
4798             ;; Select only the "normal" subset of articles.
4799             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4800                           (copy-sequence gnus-newsgroup-unreads))
4801                   '<)))
4802          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4803          (scored (length scored-list))
4804          (number (length articles))
4805          (marked (+ (length gnus-newsgroup-marked)
4806                     (length gnus-newsgroup-dormant)))
4807          (select
4808           (cond
4809            ((numberp read-all)
4810             read-all)
4811            (t
4812             (condition-case ()
4813                 (cond
4814                  ((and (or (<= scored marked) (= scored number))
4815                        (numberp gnus-large-newsgroup)
4816                        (> number gnus-large-newsgroup))
4817                   (let ((input
4818                          (read-string
4819                           (format
4820                            "How many articles from %s (default %d): "
4821                            (gnus-limit-string
4822                             (gnus-group-decoded-name gnus-newsgroup-name)
4823                             35)
4824                            number))))
4825                     (if (string-match "^[ \t]*$" input) number input)))
4826                  ((and (> scored marked) (< scored number)
4827                        (> (- scored number) 20))
4828                   (let ((input
4829                          (read-string
4830                           (format "%s %s (%d scored, %d total): "
4831                                   "How many articles from"
4832                                   (gnus-group-decoded-name group)
4833                                   scored number))))
4834                     (if (string-match "^[ \t]*$" input)
4835                         number input)))
4836                  (t number))
4837               (quit
4838                (message "Quit getting the articles to read")
4839                nil))))))
4840     (setq select (if (stringp select) (string-to-number select) select))
4841     (if (or (null select) (zerop select))
4842         select
4843       (if (and (not (zerop scored)) (<= (abs select) scored))
4844           (progn
4845             (setq articles (sort scored-list '<))
4846             (setq number (length articles)))
4847         (setq articles (copy-sequence articles)))
4848
4849       (when (< (abs select) number)
4850         (if (< select 0)
4851             ;; Select the N oldest articles.
4852             (setcdr (nthcdr (1- (abs select)) articles) nil)
4853           ;; Select the N most recent articles.
4854           (setq articles (nthcdr (- number select) articles))))
4855       (setq gnus-newsgroup-unselected
4856             (gnus-sorted-intersection
4857              gnus-newsgroup-unreads
4858              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4859       (when gnus-alter-articles-to-read-function
4860         (setq gnus-newsgroup-unreads
4861               (sort
4862                (funcall gnus-alter-articles-to-read-function
4863                         gnus-newsgroup-name gnus-newsgroup-unreads)
4864                '<)))
4865       articles)))
4866
4867 (defun gnus-killed-articles (killed articles)
4868   (let (out)
4869     (while articles
4870       (when (inline (gnus-member-of-range (car articles) killed))
4871         (push (car articles) out))
4872       (setq articles (cdr articles)))
4873     out))
4874
4875 (defun gnus-uncompress-marks (marks)
4876   "Uncompress the mark ranges in MARKS."
4877   (let ((uncompressed '(score bookmark))
4878         out)
4879     (while marks
4880       (if (memq (caar marks) uncompressed)
4881           (push (car marks) out)
4882         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4883       (setq marks (cdr marks)))
4884     out))
4885
4886 (defun gnus-article-mark-to-type (mark)
4887   "Return the type of MARK."
4888   (or (cadr (assq mark gnus-article-special-mark-lists))
4889       'list))
4890
4891 (defun gnus-article-unpropagatable-p (mark)
4892   "Return whether MARK should be propagated to backend."
4893   (memq mark gnus-article-unpropagated-mark-lists))
4894
4895 (defun gnus-adjust-marked-articles (info)
4896   "Set all article lists and remove all marks that are no longer valid."
4897   (let* ((marked-lists (gnus-info-marks info))
4898          (active (gnus-active (gnus-info-group info)))
4899          (min (car active))
4900          (max (cdr active))
4901          (types gnus-article-mark-lists)
4902          marks var articles article mark mark-type)
4903
4904     (dolist (marks marked-lists)
4905       (setq mark (car marks)
4906             mark-type (gnus-article-mark-to-type mark)
4907             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4908
4909       ;; We set the variable according to the type of the marks list,
4910       ;; and then adjust the marks to a subset of the active articles.
4911       (cond
4912        ;; Adjust "simple" lists.
4913        ((eq mark-type 'list)
4914         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4915         (when (memq mark '(tick dormant expire reply save))
4916           (while articles
4917             (when (or (< (setq article (pop articles)) min) (> article max))
4918               (set var (delq article (symbol-value var)))))))
4919        ;; Adjust assocs.
4920        ((eq mark-type 'tuple)
4921         (set var (setq articles (cdr marks)))
4922         (when (not (listp (cdr (symbol-value var))))
4923           (set var (list (symbol-value var))))
4924         (when (not (listp (cdr articles)))
4925           (setq articles (list articles)))
4926         (while articles
4927           (when (or (not (consp (setq article (pop articles))))
4928                     (< (car article) min)
4929                     (> (car article) max))
4930             (set var (delq article (symbol-value var))))))
4931        ;; Adjust ranges (sloppily).
4932        ((eq mark-type 'range)
4933         (cond
4934          ((eq mark 'seen)
4935           (setq articles (cdr marks))
4936           (while (and articles
4937                       (or (and (consp (car articles))
4938                                (> min (cdar articles)))
4939                           (and (numberp (car articles))
4940                                (> min (car articles)))))
4941             (pop articles))
4942           (set var articles))))))))
4943
4944 (defun gnus-update-missing-marks (missing)
4945   "Go through the list of MISSING articles and remove them from the mark lists."
4946   (when missing
4947     (let (var m)
4948       ;; Go through all types.
4949       (dolist (elem gnus-article-mark-lists)
4950         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4951           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4952           (when (symbol-value var)
4953             ;; This list has articles.  So we delete all missing
4954             ;; articles from it.
4955             (setq m missing)
4956             (while m
4957               (set var (delq (pop m) (symbol-value var))))))))))
4958
4959 (defun gnus-update-marks ()
4960   "Enter the various lists of marked articles into the newsgroup info list."
4961   (let ((types gnus-article-mark-lists)
4962         (info (gnus-get-info gnus-newsgroup-name))
4963         type list newmarked symbol delta-marks)
4964     (when info
4965       ;; Add all marks lists to the list of marks lists.
4966       (while (setq type (pop types))
4967         (setq list (symbol-value
4968                     (setq symbol
4969                           (intern (format "gnus-newsgroup-%s" (car type))))))
4970
4971         (when list
4972           ;; Get rid of the entries of the articles that have the
4973           ;; default score.
4974           (when (and (eq (cdr type) 'score)
4975                      gnus-save-score
4976                      list)
4977             (let* ((arts list)
4978                    (prev (cons nil list))
4979                    (all prev))
4980               (while arts
4981                 (if (or (not (consp (car arts)))
4982                         (= (cdar arts) gnus-summary-default-score))
4983                     (setcdr prev (cdr arts))
4984                   (setq prev arts))
4985                 (setq arts (cdr arts)))
4986               (setq list (cdr all)))))
4987
4988         (when (eq (cdr type) 'seen)
4989           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
4990
4991         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4992           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4993
4994         (when (and (gnus-check-backend-function
4995                     'request-set-mark gnus-newsgroup-name)
4996                    (not (gnus-article-unpropagatable-p (cdr type))))
4997           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4998                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4999                  (add (gnus-remove-from-range
5000                        (gnus-copy-sequence list) old)))
5001             (when add
5002               (push (list add 'add (list (cdr type))) delta-marks))
5003             (when del
5004               (push (list del 'del (list (cdr type))) delta-marks))))
5005
5006         (when list
5007           (push (cons (cdr type) list) newmarked)))
5008
5009       (when delta-marks
5010         (unless (gnus-check-group gnus-newsgroup-name)
5011           (error "Can't open server for %s" gnus-newsgroup-name))
5012         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5013
5014       ;; Enter these new marks into the info of the group.
5015       (if (nthcdr 3 info)
5016           (setcar (nthcdr 3 info) newmarked)
5017         ;; Add the marks lists to the end of the info.
5018         (when newmarked
5019           (setcdr (nthcdr 2 info) (list newmarked))))
5020
5021       ;; Cut off the end of the info if there's nothing else there.
5022       (let ((i 5))
5023         (while (and (> i 2)
5024                     (not (nth i info)))
5025           (when (nthcdr (decf i) info)
5026             (setcdr (nthcdr i info) nil)))))))
5027
5028 (defun gnus-set-mode-line (where)
5029   "Set the mode line of the article or summary buffers.
5030 If WHERE is `summary', the summary mode line format will be used."
5031   ;; Is this mode line one we keep updated?
5032   (when (and (memq where gnus-updated-mode-lines)
5033              (symbol-value
5034               (intern (format "gnus-%s-mode-line-format-spec" where))))
5035     (let (mode-string)
5036       (save-excursion
5037         ;; We evaluate this in the summary buffer since these
5038         ;; variables are buffer-local to that buffer.
5039         (set-buffer gnus-summary-buffer)
5040        ;; We bind all these variables that are used in the `eval' form
5041         ;; below.
5042         (let* ((mformat (symbol-value
5043                          (intern
5044                           (format "gnus-%s-mode-line-format-spec" where))))
5045                (gnus-tmp-group-name (gnus-group-decoded-name
5046                                      gnus-newsgroup-name))
5047                (gnus-tmp-article-number (or gnus-current-article 0))
5048                (gnus-tmp-unread gnus-newsgroup-unreads)
5049                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5050                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5051                (gnus-tmp-unread-and-unselected
5052                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5053                             (zerop gnus-tmp-unselected))
5054                        "")
5055                       ((zerop gnus-tmp-unselected)
5056                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5057                       (t (format "{%d(+%d) more}"
5058                                  gnus-tmp-unread-and-unticked
5059                                  gnus-tmp-unselected))))
5060                (gnus-tmp-subject
5061                 (if (and gnus-current-headers
5062                          (vectorp gnus-current-headers))
5063                     (gnus-mode-string-quote
5064                      (mail-header-subject gnus-current-headers))
5065                   ""))
5066                bufname-length max-len
5067                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5068           (setq mode-string (eval mformat))
5069           (setq bufname-length (if (string-match "%b" mode-string)
5070                                    (- (length
5071                                        (buffer-name
5072                                         (if (eq where 'summary)
5073                                             nil
5074                                           (get-buffer gnus-article-buffer))))
5075                                       2)
5076                                  0))
5077           (setq max-len (max 4 (if gnus-mode-non-string-length
5078                                    (- (window-width)
5079                                       gnus-mode-non-string-length
5080                                       bufname-length)
5081                                  (length mode-string))))
5082           ;; We might have to chop a bit of the string off...
5083           (when (> (length mode-string) max-len)
5084             (setq mode-string
5085                   (concat (truncate-string-to-width mode-string (- max-len 3))
5086                           "...")))
5087           ;; Pad the mode string a bit.
5088           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5089       ;; Update the mode line.
5090       (setq mode-line-buffer-identification
5091             (gnus-mode-line-buffer-identification (list mode-string)))
5092       (set-buffer-modified-p t))))
5093
5094 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5095   "Go through the HEADERS list and add all Xrefs to a hash table.
5096 The resulting hash table is returned, or nil if no Xrefs were found."
5097   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5098          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5099          (xref-hashtb (gnus-make-hashtable))
5100          start group entry number xrefs header)
5101     (while headers
5102       (setq header (pop headers))
5103       (when (and (setq xrefs (mail-header-xref header))
5104                  (not (memq (setq number (mail-header-number header))
5105                             unreads)))
5106         (setq start 0)
5107         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5108           (setq start (match-end 0))
5109           (setq group (if prefix
5110                           (concat prefix (substring xrefs (match-beginning 1)
5111                                                     (match-end 1)))
5112                         (substring xrefs (match-beginning 1) (match-end 1))))
5113           (setq number
5114                 (string-to-int (substring xrefs (match-beginning 2)
5115                                           (match-end 2))))
5116           (if (setq entry (gnus-gethash group xref-hashtb))
5117               (setcdr entry (cons number (cdr entry)))
5118             (gnus-sethash group (cons number nil) xref-hashtb)))))
5119     (and start xref-hashtb)))
5120
5121 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5122   "Look through all the headers and mark the Xrefs as read."
5123   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5124         name entry info xref-hashtb idlist method nth4)
5125     (save-excursion
5126       (set-buffer gnus-group-buffer)
5127       (when (setq xref-hashtb
5128                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5129         (mapatoms
5130          (lambda (group)
5131            (unless (string= from-newsgroup (setq name (symbol-name group)))
5132              (setq idlist (symbol-value group))
5133              ;; Dead groups are not updated.
5134              (and (prog1
5135                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5136                             info (nth 2 entry))
5137                     (when (stringp (setq nth4 (gnus-info-method info)))
5138                       (setq nth4 (gnus-server-to-method nth4))))
5139                   ;; Only do the xrefs if the group has the same
5140                   ;; select method as the group we have just read.
5141                   (or (gnus-methods-equal-p
5142                        nth4 (gnus-find-method-for-group from-newsgroup))
5143                       virtual
5144                       (equal nth4 (setq method (gnus-find-method-for-group
5145                                                 from-newsgroup)))
5146                       (and (equal (car nth4) (car method))
5147                            (equal (nth 1 nth4) (nth 1 method))))
5148                   gnus-use-cross-reference
5149                   (or (not (eq gnus-use-cross-reference t))
5150                       virtual
5151                       ;; Only do cross-references on subscribed
5152                       ;; groups, if that is what is wanted.
5153                       (<= (gnus-info-level info) gnus-level-subscribed))
5154                   (gnus-group-make-articles-read name idlist))))
5155          xref-hashtb)))))
5156
5157 (defun gnus-compute-read-articles (group articles)
5158   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5159          (info (nth 2 entry))
5160          (active (gnus-active group))
5161          ninfo)
5162     (when entry
5163       ;; First peel off all invalid article numbers.
5164       (when active
5165         (let ((ids articles)
5166               id first)
5167           (while (setq id (pop ids))
5168             (when (and first (> id (cdr active)))
5169               ;; We'll end up in this situation in one particular
5170               ;; obscure situation.  If you re-scan a group and get
5171               ;; a new article that is cross-posted to a different
5172               ;; group that has not been re-scanned, you might get
5173               ;; crossposted article that has a higher number than
5174               ;; Gnus believes possible.  So we re-activate this
5175               ;; group as well.  This might mean doing the
5176               ;; crossposting thingy will *increase* the number
5177               ;; of articles in some groups.  Tsk, tsk.
5178               (setq active (or (gnus-activate-group group) active)))
5179             (when (or (> id (cdr active))
5180                       (< id (car active)))
5181               (setq articles (delq id articles))))))
5182       ;; If the read list is nil, we init it.
5183       (if (and active
5184                (null (gnus-info-read info))
5185                (> (car active) 1))
5186           (setq ninfo (cons 1 (1- (car active))))
5187         (setq ninfo (gnus-info-read info)))
5188       ;; Then we add the read articles to the range.
5189       (gnus-add-to-range
5190        ninfo (setq articles (sort articles '<))))))
5191
5192 (defun gnus-group-make-articles-read (group articles)
5193   "Update the info of GROUP to say that ARTICLES are read."
5194   (let* ((num 0)
5195          (entry (gnus-gethash group gnus-newsrc-hashtb))
5196          (info (nth 2 entry))
5197          (active (gnus-active group))
5198          range)
5199     (when entry
5200       (setq range (gnus-compute-read-articles group articles))
5201       (save-excursion
5202         (set-buffer gnus-group-buffer)
5203         (gnus-undo-register
5204           `(progn
5205              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5206              (gnus-info-set-read ',info ',(gnus-info-read info))
5207              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5208              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5209              (gnus-group-update-group ,group t))))
5210       ;; Add the read articles to the range.
5211       (gnus-info-set-read info range)
5212       (gnus-request-set-mark group (list (list range 'add '(read))))
5213       ;; Then we have to re-compute how many unread
5214       ;; articles there are in this group.
5215       (when active
5216         (cond
5217          ((not range)
5218           (setq num (- (1+ (cdr active)) (car active))))
5219          ((not (listp (cdr range)))
5220           (setq num (- (cdr active) (- (1+ (cdr range))
5221                                        (car range)))))
5222          (t
5223           (while range
5224             (if (numberp (car range))
5225                 (setq num (1+ num))
5226               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5227             (setq range (cdr range)))
5228           (setq num (- (cdr active) num))))
5229         ;; Update the number of unread articles.
5230         (setcar entry num)
5231         ;; Update the group buffer.
5232         (gnus-group-update-group group t)))))
5233
5234 (defvar gnus-newsgroup-none-id 0)
5235
5236 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5237   (let ((cur nntp-server-buffer)
5238         (dependencies
5239          (or dependencies
5240              (save-excursion (set-buffer gnus-summary-buffer)
5241                              gnus-newsgroup-dependencies)))
5242         headers id end ref
5243         (mail-parse-charset gnus-newsgroup-charset)
5244         (mail-parse-ignored-charsets
5245          (save-excursion (condition-case nil
5246                              (set-buffer gnus-summary-buffer)
5247                            (error))
5248                          gnus-newsgroup-ignored-charsets)))
5249     (save-excursion
5250       (set-buffer nntp-server-buffer)
5251       ;; Translate all TAB characters into SPACE characters.
5252       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5253       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5254       (gnus-run-hooks 'gnus-parse-headers-hook)
5255       (let ((case-fold-search t)
5256             in-reply-to header p lines chars)
5257         (goto-char (point-min))
5258         ;; Search to the beginning of the next header.  Error messages
5259         ;; do not begin with 2 or 3.
5260         (while (re-search-forward "^[23][0-9]+ " nil t)
5261           (setq id nil
5262                 ref nil)
5263           ;; This implementation of this function, with nine
5264           ;; search-forwards instead of the one re-search-forward and
5265           ;; a case (which basically was the old function) is actually
5266           ;; about twice as fast, even though it looks messier.  You
5267           ;; can't have everything, I guess.  Speed and elegance
5268           ;; doesn't always go hand in hand.
5269           (setq
5270            header
5271            (vector
5272             ;; Number.
5273             (prog1
5274                 (read cur)
5275               (end-of-line)
5276               (setq p (point))
5277               (narrow-to-region (point)
5278                                 (or (and (search-forward "\n.\n" nil t)
5279                                          (- (point) 2))
5280                                     (point))))
5281             ;; Subject.
5282             (progn
5283               (goto-char p)
5284               (if (search-forward "\nsubject:" nil t)
5285                   (funcall gnus-decode-encoded-word-function
5286                            (nnheader-header-value))
5287                 "(none)"))
5288             ;; From.
5289             (progn
5290               (goto-char p)
5291               (if (search-forward "\nfrom:" nil t)
5292                   (funcall gnus-decode-encoded-word-function
5293                            (nnheader-header-value))
5294                 "(nobody)"))
5295             ;; Date.
5296             (progn
5297               (goto-char p)
5298               (if (search-forward "\ndate:" nil t)
5299                   (nnheader-header-value) ""))
5300             ;; Message-ID.
5301             (progn
5302               (goto-char p)
5303               (setq id (if (re-search-forward
5304                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5305                            ;; We do it this way to make sure the Message-ID
5306                            ;; is (somewhat) syntactically valid.
5307                            (buffer-substring (match-beginning 1)
5308                                              (match-end 1))
5309                          ;; If there was no message-id, we just fake one
5310                          ;; to make subsequent routines simpler.
5311                          (nnheader-generate-fake-message-id))))
5312             ;; References.
5313             (progn
5314               (goto-char p)
5315               (if (search-forward "\nreferences:" nil t)
5316                   (progn
5317                     (setq end (point))
5318                     (prog1
5319                         (nnheader-header-value)
5320                       (setq ref
5321                             (buffer-substring
5322                              (progn
5323                                (end-of-line)
5324                                (search-backward ">" end t)
5325                                (1+ (point)))
5326                              (progn
5327                                (search-backward "<" end t)
5328                                (point))))))
5329                 ;; Get the references from the in-reply-to header if there
5330                 ;; were no references and the in-reply-to header looks
5331                 ;; promising.
5332                 (if (and (search-forward "\nin-reply-to:" nil t)
5333                          (setq in-reply-to (nnheader-header-value))
5334                          (string-match "<[^>]+>" in-reply-to))
5335                     (let (ref2)
5336                       (setq ref (substring in-reply-to (match-beginning 0)
5337                                            (match-end 0)))
5338                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5339                         (setq ref2 (substring in-reply-to (match-beginning 0)
5340                                               (match-end 0)))
5341                         (when (> (length ref2) (length ref))
5342                           (setq ref ref2)))
5343                       ref)
5344                   (setq ref nil))))
5345             ;; Chars.
5346             (progn
5347               (goto-char p)
5348               (if (search-forward "\nchars: " nil t)
5349                   (if (numberp (setq chars (ignore-errors (read cur))))
5350                       chars -1)
5351                 -1))
5352             ;; Lines.
5353             (progn
5354               (goto-char p)
5355               (if (search-forward "\nlines: " nil t)
5356                   (if (numberp (setq lines (ignore-errors (read cur))))
5357                       lines -1)
5358                 -1))
5359             ;; Xref.
5360             (progn
5361               (goto-char p)
5362               (and (search-forward "\nxref:" nil t)
5363                    (nnheader-header-value)))
5364             ;; Extra.
5365             (when gnus-extra-headers
5366               (let ((extra gnus-extra-headers)
5367                     out)
5368                 (while extra
5369                   (goto-char p)
5370                   (when (search-forward
5371                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5372                     (push (cons (car extra) (nnheader-header-value))
5373                           out))
5374                   (pop extra))
5375                 out))))
5376           (when (equal id ref)
5377             (setq ref nil))
5378
5379           (when gnus-alter-header-function
5380             (funcall gnus-alter-header-function header)
5381             (setq id (mail-header-id header)
5382                   ref (gnus-parent-id (mail-header-references header))))
5383
5384           (when (setq header
5385                       (gnus-dependencies-add-header
5386                        header dependencies force-new))
5387             (push header headers))
5388           (goto-char (point-max))
5389           (widen))
5390         (nreverse headers)))))
5391
5392 ;; Goes through the xover lines and returns a list of vectors
5393 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5394                                                   force-new dependencies
5395                                                   group also-fetch-heads)
5396   "Parse the news overview data in the server buffer.
5397 Return a list of headers that match SEQUENCE (see
5398 `nntp-retrieve-headers')."
5399   ;; Get the Xref when the users reads the articles since most/some
5400   ;; NNTP servers do not include Xrefs when using XOVER.
5401   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5402   (let ((mail-parse-charset gnus-newsgroup-charset)
5403         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5404         (cur nntp-server-buffer)
5405         (dependencies (or dependencies gnus-newsgroup-dependencies))
5406         (allp (cond
5407                ((eq gnus-read-all-available-headers t)
5408                 t)
5409                ((stringp gnus-read-all-available-headers)
5410                 (string-match gnus-read-all-available-headers group))
5411                (t
5412                 nil)))
5413         number headers header)
5414     (save-excursion
5415       (set-buffer nntp-server-buffer)
5416       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5417       ;; Allow the user to mangle the headers before parsing them.
5418       (gnus-run-hooks 'gnus-parse-headers-hook)
5419       (goto-char (point-min))
5420       (while (not (eobp))
5421         (condition-case ()
5422             (while (and (or sequence allp)
5423                         (not (eobp)))
5424               (setq number (read cur))
5425               (when (not allp)
5426                 (while (and sequence
5427                             (< (car sequence) number))
5428                   (setq sequence (cdr sequence))))
5429               (when (and (or allp
5430                              (and sequence
5431                                   (eq number (car sequence))))
5432                          (progn
5433                            (setq sequence (cdr sequence))
5434                            (setq header (inline
5435                                           (gnus-nov-parse-line
5436                                            number dependencies force-new)))))
5437                 (push header headers))
5438               (forward-line 1))
5439           (error
5440            (gnus-error 4 "Strange nov line (%d)"
5441                        (count-lines (point-min) (point)))))
5442         (forward-line 1))
5443       ;; A common bug in inn is that if you have posted an article and
5444       ;; then retrieves the active file, it will answer correctly --
5445       ;; the new article is included.  However, a NOV entry for the
5446       ;; article may not have been generated yet, so this may fail.
5447       ;; We work around this problem by retrieving the last few
5448       ;; headers using HEAD.
5449       (if (or (not also-fetch-heads)
5450               (not sequence))
5451           ;; We (probably) got all the headers.
5452           (nreverse headers)
5453         (let ((gnus-nov-is-evil t))
5454           (nconc
5455            (nreverse headers)
5456            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5457              (gnus-get-newsgroup-headers))))))))
5458
5459 (defun gnus-article-get-xrefs ()
5460   "Fill in the Xref value in `gnus-current-headers', if necessary.
5461 This is meant to be called in `gnus-article-internal-prepare-hook'."
5462   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5463                                  gnus-current-headers)))
5464     (or (not gnus-use-cross-reference)
5465         (not headers)
5466         (and (mail-header-xref headers)
5467              (not (string= (mail-header-xref headers) "")))
5468         (let ((case-fold-search t)
5469               xref)
5470           (save-restriction
5471             (nnheader-narrow-to-headers)
5472             (goto-char (point-min))
5473             (when (or (and (not (eobp))
5474                            (eq (downcase (char-after)) ?x)
5475                            (looking-at "Xref:"))
5476                       (search-forward "\nXref:" nil t))
5477               (goto-char (1+ (match-end 0)))
5478               (setq xref (buffer-substring (point)
5479                                            (progn (end-of-line) (point))))
5480               (mail-header-set-xref headers xref)))))))
5481
5482 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5483   "Find article ID and insert the summary line for that article.
5484 OLD-HEADER can either be a header or a line number to insert
5485 the subject line on."
5486   (let* ((line (and (numberp old-header) old-header))
5487          (old-header (and (vectorp old-header) old-header))
5488          (header (cond ((and old-header use-old-header)
5489                         old-header)
5490                        ((and (numberp id)
5491                              (gnus-number-to-header id))
5492                         (gnus-number-to-header id))
5493                        (t
5494                         (gnus-read-header id))))
5495          (number (and (numberp id) id))
5496          d)
5497     (when header
5498       ;; Rebuild the thread that this article is part of and go to the
5499       ;; article we have fetched.
5500       (when (and (not gnus-show-threads)
5501                  old-header)
5502         (when (and number
5503                    (setq d (gnus-data-find (mail-header-number old-header))))
5504           (goto-char (gnus-data-pos d))
5505           (gnus-data-remove
5506            number
5507            (- (gnus-point-at-bol)
5508               (prog1
5509                   (1+ (gnus-point-at-eol))
5510                 (gnus-delete-line))))))
5511       (when old-header
5512         (mail-header-set-number header (mail-header-number old-header)))
5513       (setq gnus-newsgroup-sparse
5514             (delq (setq number (mail-header-number header))
5515                   gnus-newsgroup-sparse))
5516       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5517       (push number gnus-newsgroup-limit)
5518       (gnus-rebuild-thread (mail-header-id header) line)
5519       (gnus-summary-goto-subject number nil t))
5520     (when (and (numberp number)
5521                (> number 0))
5522       ;; We have to update the boundaries even if we can't fetch the
5523       ;; article if ID is a number -- so that the next `P' or `N'
5524       ;; command will fetch the previous (or next) article even
5525       ;; if the one we tried to fetch this time has been canceled.
5526       (when (> number gnus-newsgroup-end)
5527         (setq gnus-newsgroup-end number))
5528       (when (< number gnus-newsgroup-begin)
5529         (setq gnus-newsgroup-begin number))
5530       (setq gnus-newsgroup-unselected
5531             (delq number gnus-newsgroup-unselected)))
5532     ;; Report back a success?
5533     (and header (mail-header-number header))))
5534
5535 ;;; Process/prefix in the summary buffer
5536
5537 (defun gnus-summary-work-articles (n)
5538   "Return a list of articles to be worked upon.
5539 The prefix argument, the list of process marked articles, and the
5540 current article will be taken into consideration."
5541   (save-excursion
5542     (set-buffer gnus-summary-buffer)
5543     (cond
5544      (n
5545       ;; A numerical prefix has been given.
5546       (setq n (prefix-numeric-value n))
5547       (let ((backward (< n 0))
5548             (n (abs (prefix-numeric-value n)))
5549             articles article)
5550         (save-excursion
5551           (while
5552               (and (> n 0)
5553                    (push (setq article (gnus-summary-article-number))
5554                          articles)
5555                    (if backward
5556                        (gnus-summary-find-prev nil article)
5557                      (gnus-summary-find-next nil article)))
5558             (decf n)))
5559         (nreverse articles)))
5560      ((and (gnus-region-active-p) (mark))
5561       (message "region active")
5562       ;; Work on the region between point and mark.
5563       (let ((max (max (point) (mark)))
5564             articles article)
5565         (save-excursion
5566           (goto-char (min (min (point) (mark))))
5567           (while
5568               (and
5569                (push (setq article (gnus-summary-article-number)) articles)
5570                (gnus-summary-find-next nil article)
5571                (< (point) max)))
5572           (nreverse articles))))
5573      (gnus-newsgroup-processable
5574       ;; There are process-marked articles present.
5575       ;; Save current state.
5576       (gnus-summary-save-process-mark)
5577       ;; Return the list.
5578       (reverse gnus-newsgroup-processable))
5579      (t
5580       ;; Just return the current article.
5581       (list (gnus-summary-article-number))))))
5582
5583 (defmacro gnus-summary-iterate (arg &rest forms)
5584   "Iterate over the process/prefixed articles and do FORMS.
5585 ARG is the interactive prefix given to the command.  FORMS will be
5586 executed with point over the summary line of the articles."
5587   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5588     `(let ((,articles (gnus-summary-work-articles ,arg)))
5589        (while ,articles
5590          (gnus-summary-goto-subject (car ,articles))
5591          ,@forms
5592          (pop ,articles)))))
5593
5594 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5595 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5596
5597 (defun gnus-summary-save-process-mark ()
5598   "Push the current set of process marked articles on the stack."
5599   (interactive)
5600   (push (copy-sequence gnus-newsgroup-processable)
5601         gnus-newsgroup-process-stack))
5602
5603 (defun gnus-summary-kill-process-mark ()
5604   "Push the current set of process marked articles on the stack and unmark."
5605   (interactive)
5606   (gnus-summary-save-process-mark)
5607   (gnus-summary-unmark-all-processable))
5608
5609 (defun gnus-summary-yank-process-mark ()
5610   "Pop the last process mark state off the stack and restore it."
5611   (interactive)
5612   (unless gnus-newsgroup-process-stack
5613     (error "Empty mark stack"))
5614   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5615
5616 (defun gnus-summary-process-mark-set (set)
5617   "Make SET into the current process marked articles."
5618   (gnus-summary-unmark-all-processable)
5619   (while set
5620     (gnus-summary-set-process-mark (pop set))))
5621
5622 ;;; Searching and stuff
5623
5624 (defun gnus-summary-search-group (&optional backward use-level)
5625   "Search for next unread newsgroup.
5626 If optional argument BACKWARD is non-nil, search backward instead."
5627   (save-excursion
5628     (set-buffer gnus-group-buffer)
5629     (when (gnus-group-search-forward
5630            backward nil (if use-level (gnus-group-group-level) nil))
5631       (gnus-group-group-name))))
5632
5633 (defun gnus-summary-best-group (&optional exclude-group)
5634   "Find the name of the best unread group.
5635 If EXCLUDE-GROUP, do not go to this group."
5636   (save-excursion
5637     (set-buffer gnus-group-buffer)
5638     (save-excursion
5639       (gnus-group-best-unread-group exclude-group))))
5640
5641 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5642   (if backward (gnus-summary-find-prev)
5643     (let* ((dummy (gnus-summary-article-intangible-p))
5644            (article (or article (gnus-summary-article-number)))
5645            (arts (gnus-data-find-list article))
5646            result)
5647       (when (and (not dummy)
5648                  (or (not gnus-summary-check-current)
5649                      (not unread)
5650                      (not (gnus-data-unread-p (car arts)))))
5651         (setq arts (cdr arts)))
5652       (when (setq result
5653                   (if unread
5654                       (progn
5655                         (while arts
5656                           (when (or (and undownloaded
5657                                          (eq gnus-undownloaded-mark
5658                                              (gnus-data-mark (car arts))))
5659                                     (gnus-data-unread-p (car arts)))
5660                             (setq result (car arts)
5661                                   arts nil))
5662                           (setq arts (cdr arts)))
5663                         result)
5664                     (car arts)))
5665         (goto-char (gnus-data-pos result))
5666         (gnus-data-number result)))))
5667
5668 (defun gnus-summary-find-prev (&optional unread article)
5669   (let* ((eobp (eobp))
5670          (article (or article (gnus-summary-article-number)))
5671          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5672          result)
5673     (when (and (not eobp)
5674                (or (not gnus-summary-check-current)
5675                    (not unread)
5676                    (not (gnus-data-unread-p (car arts)))))
5677       (setq arts (cdr arts)))
5678     (when (setq result
5679                 (if unread
5680                     (progn
5681                       (while arts
5682                         (when (gnus-data-unread-p (car arts))
5683                           (setq result (car arts)
5684                                 arts nil))
5685                         (setq arts (cdr arts)))
5686                       result)
5687                   (car arts)))
5688       (goto-char (gnus-data-pos result))
5689       (gnus-data-number result))))
5690
5691 (defun gnus-summary-find-subject (subject &optional unread backward article)
5692   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5693          (article (or article (gnus-summary-article-number)))
5694          (articles (gnus-data-list backward))
5695          (arts (gnus-data-find-list article articles))
5696          result)
5697     (when (or (not gnus-summary-check-current)
5698               (not unread)
5699               (not (gnus-data-unread-p (car arts))))
5700       (setq arts (cdr arts)))
5701     (while arts
5702       (and (or (not unread)
5703                (gnus-data-unread-p (car arts)))
5704            (vectorp (gnus-data-header (car arts)))
5705            (gnus-subject-equal
5706             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5707            (setq result (car arts)
5708                  arts nil))
5709       (setq arts (cdr arts)))
5710     (and result
5711          (goto-char (gnus-data-pos result))
5712          (gnus-data-number result))))
5713
5714 (defun gnus-summary-search-forward (&optional unread subject backward)
5715   "Search forward for an article.
5716 If UNREAD, look for unread articles.  If SUBJECT, look for
5717 articles with that subject.  If BACKWARD, search backward instead."
5718   (cond (subject (gnus-summary-find-subject subject unread backward))
5719         (backward (gnus-summary-find-prev unread))
5720         (t (gnus-summary-find-next unread))))
5721
5722 (defun gnus-recenter (&optional n)
5723   "Center point in window and redisplay frame.
5724 Also do horizontal recentering."
5725   (interactive "P")
5726   (when (and gnus-auto-center-summary
5727              (not (eq gnus-auto-center-summary 'vertical)))
5728     (gnus-horizontal-recenter))
5729   (recenter n))
5730
5731 (defun gnus-summary-recenter ()
5732   "Center point in the summary window.
5733 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5734 displayed, no centering will be performed."
5735   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5736 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5737   (interactive)
5738   (let* ((top (cond ((< (window-height) 4) 0)
5739                     ((< (window-height) 7) 1)
5740                     (t (if (numberp gnus-auto-center-summary)
5741                            gnus-auto-center-summary
5742                          2))))
5743          (height (1- (window-height)))
5744          (bottom (save-excursion (goto-char (point-max))
5745                                  (forward-line (- height))
5746                                  (point)))
5747          (window (get-buffer-window (current-buffer))))
5748     ;; The user has to want it.
5749     (when gnus-auto-center-summary
5750       (when (get-buffer-window gnus-article-buffer)
5751         ;; Only do recentering when the article buffer is displayed,
5752       ;; Set the window start to either `bottom', which is the biggest
5753         ;; possible valid number, or the second line from the top,
5754         ;; whichever is the least.
5755         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5756           (if (> bottom top-pos)
5757               ;; Keep the second line from the top visible
5758               (set-window-start window top-pos t)
5759             ;; Try to keep the bottom line visible; if it's partially
5760             ;; obscured, either scroll one more line to make it fully
5761             ;; visible, or revert to using TOP-POS.
5762             (save-excursion
5763               (goto-char (point-max))
5764               (forward-line -1)
5765               (let ((last-line-start (point)))
5766                 (goto-char bottom)
5767                 (set-window-start window (point) t)
5768                 (when (not (pos-visible-in-window-p last-line-start window))
5769                   (forward-line 1)
5770                   (set-window-start window (min (point) top-pos) t)))))))
5771       ;; Do horizontal recentering while we're at it.
5772       (when (and (get-buffer-window (current-buffer) t)
5773                  (not (eq gnus-auto-center-summary 'vertical)))
5774         (let ((selected (selected-window)))
5775           (select-window (get-buffer-window (current-buffer) t))
5776           (gnus-summary-position-point)
5777           (gnus-horizontal-recenter)
5778           (select-window selected))))))
5779
5780 (defun gnus-summary-jump-to-group (newsgroup)
5781   "Move point to NEWSGROUP in group mode buffer."
5782   ;; Keep update point of group mode buffer if visible.
5783   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5784       (save-window-excursion
5785         ;; Take care of tree window mode.
5786         (when (get-buffer-window gnus-group-buffer)
5787           (pop-to-buffer gnus-group-buffer))
5788         (gnus-group-jump-to-group newsgroup))
5789     (save-excursion
5790       ;; Take care of tree window mode.
5791       (if (get-buffer-window gnus-group-buffer)
5792           (pop-to-buffer gnus-group-buffer)
5793         (set-buffer gnus-group-buffer))
5794       (gnus-group-jump-to-group newsgroup))))
5795
5796 ;; This function returns a list of article numbers based on the
5797 ;; difference between the ranges of read articles in this group and
5798 ;; the range of active articles.
5799 (defun gnus-list-of-unread-articles (group)
5800   (let* ((read (gnus-info-read (gnus-get-info group)))
5801          (active (or (gnus-active group) (gnus-activate-group group)))
5802          (last (cdr active))
5803          first nlast unread)
5804     ;; If none are read, then all are unread.
5805     (if (not read)
5806         (setq first (car active))
5807       ;; If the range of read articles is a single range, then the
5808       ;; first unread article is the article after the last read
5809       ;; article.  Sounds logical, doesn't it?
5810       (if (and (not (listp (cdr read)))
5811                (or (< (car read) (car active))
5812                    (progn (setq read (list read))
5813                           nil)))
5814           (setq first (max (car active) (1+ (cdr read))))
5815         ;; `read' is a list of ranges.
5816         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5817                                   (caar read)))
5818                   1)
5819           (setq first (car active)))
5820         (while read
5821           (when first
5822             (while (< first nlast)
5823               (push first unread)
5824               (setq first (1+ first))))
5825           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5826           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5827           (setq read (cdr read)))))
5828     ;; And add the last unread articles.
5829     (while (<= first last)
5830       (push first unread)
5831       (setq first (1+ first)))
5832     ;; Return the list of unread articles.
5833     (delq 0 (nreverse unread))))
5834
5835 (defun gnus-list-of-read-articles (group)
5836   "Return a list of unread, unticked and non-dormant articles."
5837   (let* ((info (gnus-get-info group))
5838          (marked (gnus-info-marks info))
5839          (active (gnus-active group)))
5840     (and info active
5841          (gnus-set-difference
5842           (gnus-sorted-complement
5843            (gnus-uncompress-range active)
5844            (gnus-list-of-unread-articles group))
5845           (append
5846            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5847            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5848
5849 ;; Various summary commands
5850
5851 (defun gnus-summary-select-article-buffer ()
5852   "Reconfigure windows to show article buffer."
5853   (interactive)
5854   (if (not (gnus-buffer-live-p gnus-article-buffer))
5855       (error "There is no article buffer for this summary buffer")
5856     (gnus-configure-windows 'article)
5857     (select-window (get-buffer-window gnus-article-buffer))))
5858
5859 (defun gnus-summary-universal-argument (arg)
5860   "Perform any operation on all articles that are process/prefixed."
5861   (interactive "P")
5862   (let ((articles (gnus-summary-work-articles arg))
5863         func article)
5864     (if (eq
5865          (setq
5866           func
5867           (key-binding
5868            (read-key-sequence
5869             (substitute-command-keys
5870              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5871          'undefined)
5872         (gnus-error 1 "Undefined key")
5873       (save-excursion
5874         (while articles
5875           (gnus-summary-goto-subject (setq article (pop articles)))
5876           (let (gnus-newsgroup-processable)
5877             (command-execute func))
5878           (gnus-summary-remove-process-mark article)))))
5879   (gnus-summary-position-point))
5880
5881 (defun gnus-summary-toggle-truncation (&optional arg)
5882   "Toggle truncation of summary lines.
5883 With arg, turn line truncation on iff arg is positive."
5884   (interactive "P")
5885   (setq truncate-lines
5886         (if (null arg) (not truncate-lines)
5887           (> (prefix-numeric-value arg) 0)))
5888   (redraw-display))
5889
5890 (defun gnus-summary-reselect-current-group (&optional all rescan)
5891   "Exit and then reselect the current newsgroup.
5892 The prefix argument ALL means to select all articles."
5893   (interactive "P")
5894   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5895     (error "Ephemeral groups can't be reselected"))
5896   (let ((current-subject (gnus-summary-article-number))
5897         (group gnus-newsgroup-name))
5898     (setq gnus-newsgroup-begin nil)
5899     (gnus-summary-exit)
5900     ;; We have to adjust the point of group mode buffer because
5901     ;; point was moved to the next unread newsgroup by exiting.
5902     (gnus-summary-jump-to-group group)
5903     (when rescan
5904       (save-excursion
5905         (gnus-group-get-new-news-this-group 1)))
5906     (gnus-group-read-group all t)
5907     (gnus-summary-goto-subject current-subject nil t)))
5908
5909 (defun gnus-summary-rescan-group (&optional all)
5910   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5911   (interactive "P")
5912   (gnus-summary-reselect-current-group all t))
5913
5914 (defun gnus-summary-update-info (&optional non-destructive)
5915   (save-excursion
5916     (let ((group gnus-newsgroup-name))
5917       (when group
5918         (when gnus-newsgroup-kill-headers
5919           (setq gnus-newsgroup-killed
5920                 (gnus-compress-sequence
5921                  (nconc
5922                   (gnus-set-sorted-intersection
5923                    (gnus-uncompress-range gnus-newsgroup-killed)
5924                    (setq gnus-newsgroup-unselected
5925                          (sort gnus-newsgroup-unselected '<)))
5926                   (setq gnus-newsgroup-unreads
5927                         (sort gnus-newsgroup-unreads '<)))
5928                  t)))
5929         (unless (listp (cdr gnus-newsgroup-killed))
5930           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5931         (let ((headers gnus-newsgroup-headers))
5932           ;; Set the new ranges of read articles.
5933           (save-excursion
5934             (set-buffer gnus-group-buffer)
5935             (gnus-undo-force-boundary))
5936           (gnus-update-read-articles
5937            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5938           ;; Set the current article marks.
5939           (let ((gnus-newsgroup-scored
5940                  (if (and (not gnus-save-score)
5941                           (not non-destructive))
5942                      nil
5943                    gnus-newsgroup-scored)))
5944             (save-excursion
5945               (gnus-update-marks)))
5946           ;; Do the cross-ref thing.
5947           (when gnus-use-cross-reference
5948             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5949           ;; Do not switch windows but change the buffer to work.
5950           (set-buffer gnus-group-buffer)
5951           (unless (gnus-ephemeral-group-p group)
5952             (gnus-group-update-group group)))))))
5953
5954 (defun gnus-summary-save-newsrc (&optional force)
5955   "Save the current number of read/marked articles in the dribble buffer.
5956 The dribble buffer will then be saved.
5957 If FORCE (the prefix), also save the .newsrc file(s)."
5958   (interactive "P")
5959   (gnus-summary-update-info t)
5960   (if force
5961       (gnus-save-newsrc-file)
5962     (gnus-dribble-save)))
5963
5964 (defun gnus-summary-exit (&optional temporary)
5965   "Exit reading current newsgroup, and then return to group selection mode.
5966 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5967   (interactive)
5968   (gnus-set-global-variables)
5969   (when (gnus-buffer-live-p gnus-article-buffer)
5970     (save-excursion
5971       (set-buffer gnus-article-buffer)
5972       (mm-destroy-parts gnus-article-mime-handles)
5973       ;; Set it to nil for safety reason.
5974       (setq gnus-article-mime-handle-alist nil)
5975       (setq gnus-article-mime-handles nil)))
5976   (gnus-kill-save-kill-buffer)
5977   (gnus-async-halt-prefetch)
5978   (let* ((group gnus-newsgroup-name)
5979          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5980          (mode major-mode)
5981          (group-point nil)
5982          (buf (current-buffer)))
5983     (unless quit-config
5984       ;; Do adaptive scoring, and possibly save score files.
5985       (when gnus-newsgroup-adaptive
5986         (gnus-score-adaptive))
5987       (when gnus-use-scoring
5988         (gnus-score-save)))
5989     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5990     ;; If we have several article buffers, we kill them at exit.
5991     (unless gnus-single-article-buffer
5992       (gnus-kill-buffer gnus-original-article-buffer)
5993       (setq gnus-article-current nil))
5994     (when gnus-use-cache
5995       (gnus-cache-possibly-remove-articles)
5996       (gnus-cache-save-buffers))
5997     (gnus-async-prefetch-remove-group group)
5998     (when gnus-suppress-duplicates
5999       (gnus-dup-enter-articles))
6000     (when gnus-use-trees
6001       (gnus-tree-close group))
6002     (when gnus-use-cache
6003       (gnus-cache-write-active))
6004     ;; Remove entries for this group.
6005     (nnmail-purge-split-history (gnus-group-real-name group))
6006     ;; Make all changes in this group permanent.
6007     (unless quit-config
6008       (gnus-run-hooks 'gnus-exit-group-hook)
6009       (gnus-summary-update-info))
6010     (gnus-close-group group)
6011     ;; Make sure where we were, and go to next newsgroup.
6012     (set-buffer gnus-group-buffer)
6013     (unless quit-config
6014       (gnus-group-jump-to-group group))
6015     (gnus-run-hooks 'gnus-summary-exit-hook)
6016     (unless (or quit-config
6017                 ;; If this group has disappeared from the summary
6018                 ;; buffer, don't skip forwards.
6019                 (not (string= group (gnus-group-group-name))))
6020       (gnus-group-next-unread-group 1))
6021     (setq group-point (point))
6022     (if temporary
6023         nil                             ;Nothing to do.
6024       ;; If we have several article buffers, we kill them at exit.
6025       (unless gnus-single-article-buffer
6026         (gnus-kill-buffer gnus-article-buffer)
6027         (gnus-kill-buffer gnus-original-article-buffer)
6028         (setq gnus-article-current nil))
6029       (set-buffer buf)
6030       (if (not gnus-kill-summary-on-exit)
6031           (progn
6032             (gnus-deaden-summary)
6033             (setq mode nil))
6034        ;; We set all buffer-local variables to nil.  It is unclear why
6035         ;; this is needed, but if we don't, buffer-local variables are
6036         ;; not garbage-collected, it seems.  This would the lead to en
6037         ;; ever-growing Emacs.
6038         (gnus-summary-clear-local-variables)
6039         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6040           (gnus-summary-clear-local-variables))
6041         (when (get-buffer gnus-article-buffer)
6042           (bury-buffer gnus-article-buffer))
6043         ;; We clear the global counterparts of the buffer-local
6044         ;; variables as well, just to be on the safe side.
6045         (set-buffer gnus-group-buffer)
6046         (gnus-summary-clear-local-variables)
6047         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6048           (gnus-summary-clear-local-variables)))
6049       (setq gnus-current-select-method gnus-select-method)
6050       (pop-to-buffer gnus-group-buffer)
6051       (if (not quit-config)
6052           (progn
6053             (goto-char group-point)
6054             (gnus-configure-windows 'group 'force))
6055         (gnus-handle-ephemeral-exit quit-config))
6056       ;; Return to group mode buffer.
6057       (when (eq mode 'gnus-summary-mode)
6058         (gnus-kill-buffer buf))
6059       ;; Clear the current group name.
6060       (unless quit-config
6061         (setq gnus-newsgroup-name nil)))))
6062
6063 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6064 (defun gnus-summary-exit-no-update (&optional no-questions)
6065   "Quit reading current newsgroup without updating read article info."
6066   (interactive)
6067   (let* ((group gnus-newsgroup-name)
6068          (quit-config (gnus-group-quit-config group)))
6069     (when (or no-questions
6070               gnus-expert-user
6071               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6072       (gnus-async-halt-prefetch)
6073       (mapcar 'funcall
6074               (delq 'gnus-summary-expire-articles
6075                     (copy-sequence gnus-summary-prepare-exit-hook)))
6076       (when (gnus-buffer-live-p gnus-article-buffer)
6077         (save-excursion
6078           (set-buffer gnus-article-buffer)
6079           (mm-destroy-parts gnus-article-mime-handles)
6080           ;; Set it to nil for safety reason.
6081           (setq gnus-article-mime-handle-alist nil)
6082           (setq gnus-article-mime-handles nil)))
6083       ;; If we have several article buffers, we kill them at exit.
6084       (unless gnus-single-article-buffer
6085         (gnus-kill-buffer gnus-article-buffer)
6086         (gnus-kill-buffer gnus-original-article-buffer)
6087         (setq gnus-article-current nil))
6088       (if (not gnus-kill-summary-on-exit)
6089           (gnus-deaden-summary)
6090         (gnus-close-group group)
6091         (gnus-summary-clear-local-variables)
6092         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6093           (gnus-summary-clear-local-variables))
6094         (set-buffer gnus-group-buffer)
6095         (gnus-summary-clear-local-variables)
6096         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6097           (gnus-summary-clear-local-variables))
6098         (when (get-buffer gnus-summary-buffer)
6099           (kill-buffer gnus-summary-buffer)))
6100       (unless gnus-single-article-buffer
6101         (setq gnus-article-current nil))
6102       (when gnus-use-trees
6103         (gnus-tree-close group))
6104       (gnus-async-prefetch-remove-group group)
6105       (when (get-buffer gnus-article-buffer)
6106         (bury-buffer gnus-article-buffer))
6107       ;; Return to the group buffer.
6108       (gnus-configure-windows 'group 'force)
6109       ;; Clear the current group name.
6110       (setq gnus-newsgroup-name nil)
6111       (when (equal (gnus-group-group-name) group)
6112         (gnus-group-next-unread-group 1))
6113       (when quit-config
6114         (gnus-handle-ephemeral-exit quit-config)))))
6115
6116 (defun gnus-handle-ephemeral-exit (quit-config)
6117   "Handle movement when leaving an ephemeral group.
6118 The state which existed when entering the ephemeral is reset."
6119   (if (not (buffer-name (car quit-config)))
6120       (gnus-configure-windows 'group 'force)
6121     (set-buffer (car quit-config))
6122     (cond ((eq major-mode 'gnus-summary-mode)
6123            (gnus-set-global-variables))
6124           ((eq major-mode 'gnus-article-mode)
6125            (save-excursion
6126              ;; The `gnus-summary-buffer' variable may point
6127              ;; to the old summary buffer when using a single
6128              ;; article buffer.
6129              (unless (gnus-buffer-live-p gnus-summary-buffer)
6130                (set-buffer gnus-group-buffer))
6131              (set-buffer gnus-summary-buffer)
6132              (gnus-set-global-variables))))
6133     (if (or (eq (cdr quit-config) 'article)
6134             (eq (cdr quit-config) 'pick))
6135         (progn
6136           ;; The current article may be from the ephemeral group
6137           ;; thus it is best that we reload this article
6138           (gnus-summary-show-article)
6139           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6140               (gnus-configure-windows 'pick 'force)
6141             (gnus-configure-windows (cdr quit-config) 'force)))
6142       (gnus-configure-windows (cdr quit-config) 'force))
6143     (when (eq major-mode 'gnus-summary-mode)
6144       (gnus-summary-next-subject 1 nil t)
6145       (gnus-summary-recenter)
6146       (gnus-summary-position-point))))
6147
6148 ;;; Dead summaries.
6149
6150 (defvar gnus-dead-summary-mode-map nil)
6151
6152 (unless gnus-dead-summary-mode-map
6153   (setq gnus-dead-summary-mode-map (make-keymap))
6154   (suppress-keymap gnus-dead-summary-mode-map)
6155   (substitute-key-definition
6156    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6157   (dolist (key '("\C-d" "\r" "\177" [delete]))
6158     (define-key gnus-dead-summary-mode-map
6159       key 'gnus-summary-wake-up-the-dead))
6160   (dolist (key '("q" "Q"))
6161     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6162
6163 (defvar gnus-dead-summary-mode nil
6164   "Minor mode for Gnus summary buffers.")
6165
6166 (defun gnus-dead-summary-mode (&optional arg)
6167   "Minor mode for Gnus summary buffers."
6168   (interactive "P")
6169   (when (eq major-mode 'gnus-summary-mode)
6170     (make-local-variable 'gnus-dead-summary-mode)
6171     (setq gnus-dead-summary-mode
6172           (if (null arg) (not gnus-dead-summary-mode)
6173             (> (prefix-numeric-value arg) 0)))
6174     (when gnus-dead-summary-mode
6175       (gnus-add-minor-mode
6176        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6177
6178 (defun gnus-deaden-summary ()
6179   "Make the current summary buffer into a dead summary buffer."
6180   ;; Kill any previous dead summary buffer.
6181   (when (and gnus-dead-summary
6182              (buffer-name gnus-dead-summary))
6183     (save-excursion
6184       (set-buffer gnus-dead-summary)
6185       (when gnus-dead-summary-mode
6186         (kill-buffer (current-buffer)))))
6187   ;; Make this the current dead summary.
6188   (setq gnus-dead-summary (current-buffer))
6189   (gnus-dead-summary-mode 1)
6190   (let ((name (buffer-name)))
6191     (when (string-match "Summary" name)
6192       (rename-buffer
6193        (concat (substring name 0 (match-beginning 0)) "Dead "
6194                (substring name (match-beginning 0)))
6195        t)
6196       (bury-buffer))))
6197
6198 (defun gnus-kill-or-deaden-summary (buffer)
6199   "Kill or deaden the summary BUFFER."
6200   (save-excursion
6201     (when (and (buffer-name buffer)
6202                (not gnus-single-article-buffer))
6203       (save-excursion
6204         (set-buffer buffer)
6205         (gnus-kill-buffer gnus-article-buffer)
6206         (gnus-kill-buffer gnus-original-article-buffer)))
6207     (cond (gnus-kill-summary-on-exit
6208            (when (and gnus-use-trees
6209                       (gnus-buffer-exists-p buffer))
6210              (save-excursion
6211                (set-buffer buffer)
6212                (gnus-tree-close gnus-newsgroup-name)))
6213            (gnus-kill-buffer buffer))
6214           ((gnus-buffer-exists-p buffer)
6215            (save-excursion
6216              (set-buffer buffer)
6217              (gnus-deaden-summary))))))
6218
6219 (defun gnus-summary-wake-up-the-dead (&rest args)
6220   "Wake up the dead summary buffer."
6221   (interactive)
6222   (gnus-dead-summary-mode -1)
6223   (let ((name (buffer-name)))
6224     (when (string-match "Dead " name)
6225       (rename-buffer
6226        (concat (substring name 0 (match-beginning 0))
6227                (substring name (match-end 0)))
6228        t)))
6229   (gnus-message 3 "This dead summary is now alive again"))
6230
6231 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6232 (defun gnus-summary-fetch-faq (&optional faq-dir)
6233   "Fetch the FAQ for the current group.
6234 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6235 in."
6236   (interactive
6237    (list
6238     (when current-prefix-arg
6239       (completing-read
6240        "Faq dir: " (and (listp gnus-group-faq-directory)
6241                         (mapcar (lambda (file) (list file))
6242                                 gnus-group-faq-directory))))))
6243   (let (gnus-faq-buffer)
6244     (when (setq gnus-faq-buffer
6245                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6246       (gnus-configure-windows 'summary-faq))))
6247
6248 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6249 (defun gnus-summary-describe-group (&optional force)
6250   "Describe the current newsgroup."
6251   (interactive "P")
6252   (gnus-group-describe-group force gnus-newsgroup-name))
6253
6254 (defun gnus-summary-describe-briefly ()
6255   "Describe summary mode commands briefly."
6256   (interactive)
6257   (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")))
6258
6259 ;; Walking around group mode buffer from summary mode.
6260
6261 (defun gnus-summary-next-group (&optional no-article target-group backward)
6262   "Exit current newsgroup and then select next unread newsgroup.
6263 If prefix argument NO-ARTICLE is non-nil, no article is selected
6264 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6265 previous group instead."
6266   (interactive "P")
6267   ;; Stop pre-fetching.
6268   (gnus-async-halt-prefetch)
6269   (let ((current-group gnus-newsgroup-name)
6270         (current-buffer (current-buffer))
6271         entered)
6272    ;; First we semi-exit this group to update Xrefs and all variables.
6273     ;; We can't do a real exit, because the window conf must remain
6274     ;; the same in case the user is prompted for info, and we don't
6275     ;; want the window conf to change before that...
6276     (gnus-summary-exit t)
6277     (while (not entered)
6278       ;; Then we find what group we are supposed to enter.
6279       (set-buffer gnus-group-buffer)
6280       (gnus-group-jump-to-group current-group)
6281       (setq target-group
6282             (or target-group
6283                 (if (eq gnus-keep-same-level 'best)
6284                     (gnus-summary-best-group gnus-newsgroup-name)
6285                   (gnus-summary-search-group backward gnus-keep-same-level))))
6286       (if (not target-group)
6287           ;; There are no further groups, so we return to the group
6288           ;; buffer.
6289           (progn
6290             (gnus-message 5 "Returning to the group buffer")
6291             (setq entered t)
6292             (when (gnus-buffer-live-p current-buffer)
6293               (set-buffer current-buffer)
6294               (gnus-summary-exit))
6295             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6296         ;; We try to enter the target group.
6297         (gnus-group-jump-to-group target-group)
6298         (let ((unreads (gnus-group-group-unread)))
6299           (if (and (or (eq t unreads)
6300                        (and unreads (not (zerop unreads))))
6301                    (gnus-summary-read-group
6302                     target-group nil no-article
6303                     (and (buffer-name current-buffer) current-buffer)
6304                     nil backward))
6305               (setq entered t)
6306             (setq current-group target-group
6307                   target-group nil)))))))
6308
6309 (defun gnus-summary-prev-group (&optional no-article)
6310   "Exit current newsgroup and then select previous unread newsgroup.
6311 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6312   (interactive "P")
6313   (gnus-summary-next-group no-article nil t))
6314
6315 ;; Walking around summary lines.
6316
6317 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6318   "Go to the first unread subject.
6319 If UNREAD is non-nil, go to the first unread article.
6320 Returns the article selected or nil if there are no unread articles."
6321   (interactive "P")
6322   (prog1
6323       (cond
6324        ;; Empty summary.
6325        ((null gnus-newsgroup-data)
6326         (gnus-message 3 "No articles in the group")
6327         nil)
6328        ;; Pick the first article.
6329        ((not unread)
6330         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6331         (gnus-data-number (car gnus-newsgroup-data)))
6332        ;; No unread articles.
6333        ((null gnus-newsgroup-unreads)
6334         (gnus-message 3 "No more unread articles")
6335         nil)
6336        ;; Find the first unread article.
6337        (t
6338         (let ((data gnus-newsgroup-data))
6339           (while (and data
6340                       (and (not (and undownloaded
6341                                      (eq gnus-undownloaded-mark
6342                                          (gnus-data-mark (car data)))))
6343                            (not (and unseen
6344                                      (memq (car data) gnus-newsgroup-unseen)))
6345                            (not (gnus-data-unread-p (car data)))))
6346             (setq data (cdr data)))
6347           (when data
6348             (goto-char (gnus-data-pos (car data)))
6349             (gnus-data-number (car data))))))
6350     (gnus-summary-position-point)))
6351
6352 (defun gnus-summary-next-subject (n &optional unread dont-display)
6353   "Go to next N'th summary line.
6354 If N is negative, go to the previous N'th subject line.
6355 If UNREAD is non-nil, only unread articles are selected.
6356 The difference between N and the actual number of steps taken is
6357 returned."
6358   (interactive "p")
6359   (let ((backward (< n 0))
6360         (n (abs n)))
6361     (while (and (> n 0)
6362                 (if backward
6363                     (gnus-summary-find-prev unread)
6364                   (gnus-summary-find-next unread)))
6365       (unless (zerop (setq n (1- n)))
6366         (gnus-summary-show-thread)))
6367     (when (/= 0 n)
6368       (gnus-message 7 "No more%s articles"
6369                     (if unread " unread" "")))
6370     (unless dont-display
6371       (gnus-summary-recenter)
6372       (gnus-summary-position-point))
6373     n))
6374
6375 (defun gnus-summary-next-unread-subject (n)
6376   "Go to next N'th unread summary line."
6377   (interactive "p")
6378   (gnus-summary-next-subject n t))
6379
6380 (defun gnus-summary-prev-subject (n &optional unread)
6381   "Go to previous N'th summary line.
6382 If optional argument UNREAD is non-nil, only unread article is selected."
6383   (interactive "p")
6384   (gnus-summary-next-subject (- n) unread))
6385
6386 (defun gnus-summary-prev-unread-subject (n)
6387   "Go to previous N'th unread summary line."
6388   (interactive "p")
6389   (gnus-summary-next-subject (- n) t))
6390
6391 (defun gnus-summary-goto-subject (article &optional force silent)
6392   "Go the subject line of ARTICLE.
6393 If FORCE, also allow jumping to articles not currently shown."
6394   (interactive "nArticle number: ")
6395   (let ((b (point))
6396         (data (gnus-data-find article)))
6397     ;; We read in the article if we have to.
6398     (and (not data)
6399          force
6400          (gnus-summary-insert-subject
6401           article
6402           (if (or (numberp force) (vectorp force)) force)
6403           t)
6404          (setq data (gnus-data-find article)))
6405     (goto-char b)
6406     (if (not data)
6407         (progn
6408           (unless silent
6409             (gnus-message 3 "Can't find article %d" article))
6410           nil)
6411       (let ((pt (gnus-data-pos data)))
6412         (goto-char pt)
6413         (gnus-summary-set-article-display-arrow pt))
6414       (gnus-summary-position-point)
6415       article)))
6416
6417 ;; Walking around summary lines with displaying articles.
6418
6419 (defun gnus-summary-expand-window (&optional arg)
6420   "Make the summary buffer take up the entire Emacs frame.
6421 Given a prefix, will force an `article' buffer configuration."
6422   (interactive "P")
6423   (if arg
6424       (gnus-configure-windows 'article 'force)
6425     (gnus-configure-windows 'summary 'force)))
6426
6427 (defun gnus-summary-display-article (article &optional all-header)
6428   "Display ARTICLE in article buffer."
6429   (when (gnus-buffer-live-p gnus-article-buffer)
6430     (with-current-buffer gnus-article-buffer
6431       (mm-enable-multibyte-mule4)))
6432   (gnus-set-global-variables)
6433   (when (gnus-buffer-live-p gnus-article-buffer)
6434     (with-current-buffer gnus-article-buffer
6435       (setq gnus-article-charset gnus-newsgroup-charset)
6436       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6437       (mm-enable-multibyte-mule4)))
6438   (if (null article)
6439       nil
6440     (prog1
6441         (if gnus-summary-display-article-function
6442             (funcall gnus-summary-display-article-function article all-header)
6443           (gnus-article-prepare article all-header))
6444       (gnus-run-hooks 'gnus-select-article-hook)
6445       (when (and gnus-current-article
6446                  (not (zerop gnus-current-article)))
6447         (gnus-summary-goto-subject gnus-current-article))
6448       (gnus-summary-recenter)
6449       (when (and gnus-use-trees gnus-show-threads)
6450         (gnus-possibly-generate-tree article)
6451         (gnus-highlight-selected-tree article))
6452       ;; Successfully display article.
6453       (gnus-article-set-window-start
6454        (cdr (assq article gnus-newsgroup-bookmarks))))))
6455
6456 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6457   "Select the current article.
6458 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6459 non-nil, the article will be re-fetched even if it already present in
6460 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6461 be displayed."
6462   ;; Make sure we are in the summary buffer to work around bbdb bug.
6463   (unless (eq major-mode 'gnus-summary-mode)
6464     (set-buffer gnus-summary-buffer))
6465   (let ((article (or article (gnus-summary-article-number)))
6466         (all-headers (not (not all-headers))) ;Must be t or nil.
6467         gnus-summary-display-article-function)
6468     (and (not pseudo)
6469          (gnus-summary-article-pseudo-p article)
6470          (error "This is a pseudo-article"))
6471     (save-excursion
6472       (set-buffer gnus-summary-buffer)
6473       (if (or (and gnus-single-article-buffer
6474                    (or (null gnus-current-article)
6475                        (null gnus-article-current)
6476                        (null (get-buffer gnus-article-buffer))
6477                        (not (eq article (cdr gnus-article-current)))
6478                        (not (equal (car gnus-article-current)
6479                                    gnus-newsgroup-name))))
6480               (and (not gnus-single-article-buffer)
6481                    (or (null gnus-current-article)
6482                        (not (eq gnus-current-article article))))
6483               force)
6484        ;; The requested article is different from the current article.
6485           (progn
6486             (gnus-summary-display-article article all-headers)
6487             (when (gnus-buffer-live-p gnus-article-buffer)
6488               (with-current-buffer gnus-article-buffer
6489                 (if (not gnus-article-decoded-p) ;; a local variable
6490                     (mm-disable-multibyte-mule4))))
6491             (when (or all-headers gnus-show-all-headers)
6492               (gnus-article-show-all-headers))
6493             (gnus-article-set-window-start
6494              (cdr (assq article gnus-newsgroup-bookmarks)))
6495             article)
6496         (when (or all-headers gnus-show-all-headers)
6497           (gnus-article-show-all-headers))
6498         'old))))
6499
6500 (defun gnus-summary-force-verify-and-decrypt ()
6501   (interactive)
6502   (let ((mm-verify-option 'known)
6503         (mm-decrypt-option 'known))
6504     (gnus-summary-select-article nil 'force)))
6505
6506 (defun gnus-summary-set-current-mark (&optional current-mark)
6507   "Obsolete function."
6508   nil)
6509
6510 (defun gnus-summary-next-article (&optional unread subject backward push)
6511   "Select the next article.
6512 If UNREAD, only unread articles are selected.
6513 If SUBJECT, only articles with SUBJECT are selected.
6514 If BACKWARD, the previous article is selected instead of the next."
6515   (interactive "P")
6516   (cond
6517    ;; Is there such an article?
6518    ((and (gnus-summary-search-forward unread subject backward)
6519          (or (gnus-summary-display-article (gnus-summary-article-number))
6520              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6521     (gnus-summary-position-point))
6522    ;; If not, we try the first unread, if that is wanted.
6523    ((and subject
6524          gnus-auto-select-same
6525          (gnus-summary-first-unread-article))
6526     (gnus-summary-position-point)
6527     (gnus-message 6 "Wrapped"))
6528    ;; Try to get next/previous article not displayed in this group.
6529    ((and gnus-auto-extend-newsgroup
6530          (not unread) (not subject))
6531     (gnus-summary-goto-article
6532      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6533      nil (count-lines (point-min) (point))))
6534    ;; Go to next/previous group.
6535    (t
6536     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6537       (gnus-summary-jump-to-group gnus-newsgroup-name))
6538     (let ((cmd last-command-char)
6539           (point
6540            (save-excursion
6541              (set-buffer gnus-group-buffer)
6542              (point)))
6543           (group
6544            (if (eq gnus-keep-same-level 'best)
6545                (gnus-summary-best-group gnus-newsgroup-name)
6546              (gnus-summary-search-group backward gnus-keep-same-level))))
6547       ;; For some reason, the group window gets selected.  We change
6548       ;; it back.
6549       (select-window (get-buffer-window (current-buffer)))
6550       ;; Select next unread newsgroup automagically.
6551       (cond
6552        ((or (not gnus-auto-select-next)
6553             (not cmd))
6554         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6555        ((or (eq gnus-auto-select-next 'quietly)
6556             (and (eq gnus-auto-select-next 'slightly-quietly)
6557                  push)
6558             (and (eq gnus-auto-select-next 'almost-quietly)
6559                  (gnus-summary-last-article-p)))
6560         ;; Select quietly.
6561         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6562             (gnus-summary-exit)
6563           (gnus-message 7 "No more%s articles (%s)..."
6564                         (if unread " unread" "")
6565                         (if group (concat "selecting " group)
6566                           "exiting"))
6567           (gnus-summary-next-group nil group backward)))
6568        (t
6569         (when (gnus-key-press-event-p last-input-event)
6570           (gnus-summary-walk-group-buffer
6571            gnus-newsgroup-name cmd unread backward point))))))))
6572
6573 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6574   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6575                       (?\C-p (gnus-group-prev-unread-group 1))))
6576         (cursor-in-echo-area t)
6577         keve key group ended)
6578     (save-excursion
6579       (set-buffer gnus-group-buffer)
6580       (goto-char start)
6581       (setq group
6582             (if (eq gnus-keep-same-level 'best)
6583                 (gnus-summary-best-group gnus-newsgroup-name)
6584               (gnus-summary-search-group backward gnus-keep-same-level))))
6585     (while (not ended)
6586       (gnus-message
6587        5 "No more%s articles%s" (if unread " unread" "")
6588        (if (and group
6589                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6590            (format " (Type %s for %s [%s])"
6591                    (single-key-description cmd) group
6592                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6593          (format " (Type %s to exit %s)"
6594                  (single-key-description cmd)
6595                  gnus-newsgroup-name)))
6596       ;; Confirm auto selection.
6597       (setq key (car (setq keve (gnus-read-event-char))))
6598       (setq ended t)
6599       (cond
6600        ((assq key keystrokes)
6601         (let ((obuf (current-buffer)))
6602           (switch-to-buffer gnus-group-buffer)
6603           (when group
6604             (gnus-group-jump-to-group group))
6605           (eval (cadr (assq key keystrokes)))
6606           (setq group (gnus-group-group-name))
6607           (switch-to-buffer obuf))
6608         (setq ended nil))
6609        ((equal key cmd)
6610         (if (or (not group)
6611                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6612             (gnus-summary-exit)
6613           (gnus-summary-next-group nil group backward)))
6614        (t
6615         (push (cdr keve) unread-command-events))))))
6616
6617 (defun gnus-summary-next-unread-article ()
6618   "Select unread article after current one."
6619   (interactive)
6620   (gnus-summary-next-article
6621    (or (not (eq gnus-summary-goto-unread 'never))
6622        (gnus-summary-last-article-p (gnus-summary-article-number)))
6623    (and gnus-auto-select-same
6624         (gnus-summary-article-subject))))
6625
6626 (defun gnus-summary-prev-article (&optional unread subject)
6627   "Select the article after the current one.
6628 If UNREAD is non-nil, only unread articles are selected."
6629   (interactive "P")
6630   (gnus-summary-next-article unread subject t))
6631
6632 (defun gnus-summary-prev-unread-article ()
6633   "Select unread article before current one."
6634   (interactive)
6635   (gnus-summary-prev-article
6636    (or (not (eq gnus-summary-goto-unread 'never))
6637        (gnus-summary-first-article-p (gnus-summary-article-number)))
6638    (and gnus-auto-select-same
6639         (gnus-summary-article-subject))))
6640
6641 (defun gnus-summary-next-page (&optional lines circular)
6642   "Show next page of the selected article.
6643 If at the end of the current article, select the next article.
6644 LINES says how many lines should be scrolled up.
6645
6646 If CIRCULAR is non-nil, go to the start of the article instead of
6647 selecting the next article when reaching the end of the current
6648 article."
6649   (interactive "P")
6650   (setq gnus-summary-buffer (current-buffer))
6651   (gnus-set-global-variables)
6652   (let ((article (gnus-summary-article-number))
6653         (article-window (get-buffer-window gnus-article-buffer t))
6654         endp)
6655     ;; If the buffer is empty, we have no article.
6656     (unless article
6657       (error "No article to select"))
6658     (gnus-configure-windows 'article)
6659     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6660         (if (and (eq gnus-summary-goto-unread 'never)
6661                  (not (gnus-summary-last-article-p article)))
6662             (gnus-summary-next-article)
6663           (gnus-summary-next-unread-article))
6664       (if (or (null gnus-current-article)
6665               (null gnus-article-current)
6666               (/= article (cdr gnus-article-current))
6667               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6668           ;; Selected subject is different from current article's.
6669           (gnus-summary-display-article article)
6670         (when article-window
6671           (gnus-eval-in-buffer-window gnus-article-buffer
6672             (setq endp (gnus-article-next-page lines)))
6673           (when endp
6674             (cond (circular
6675                    (gnus-summary-beginning-of-article))
6676                   (lines
6677                    (gnus-message 3 "End of message"))
6678                   ((null lines)
6679                    (if (and (eq gnus-summary-goto-unread 'never)
6680                             (not (gnus-summary-last-article-p article)))
6681                        (gnus-summary-next-article)
6682                      (gnus-summary-next-unread-article))))))))
6683     (gnus-summary-recenter)
6684     (gnus-summary-position-point)))
6685
6686 (defun gnus-summary-prev-page (&optional lines move)
6687   "Show previous page of selected article.
6688 Argument LINES specifies lines to be scrolled down.
6689 If MOVE, move to the previous unread article if point is at
6690 the beginning of the buffer."
6691   (interactive "P")
6692   (let ((article (gnus-summary-article-number))
6693         (article-window (get-buffer-window gnus-article-buffer t))
6694         endp)
6695     (gnus-configure-windows 'article)
6696     (if (or (null gnus-current-article)
6697             (null gnus-article-current)
6698             (/= article (cdr gnus-article-current))
6699             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6700         ;; Selected subject is different from current article's.
6701         (gnus-summary-display-article article)
6702       (gnus-summary-recenter)
6703       (when article-window
6704         (gnus-eval-in-buffer-window gnus-article-buffer
6705           (setq endp (gnus-article-prev-page lines)))
6706         (when (and move endp)
6707           (cond (lines
6708                  (gnus-message 3 "Beginning of message"))
6709                 ((null lines)
6710                  (if (and (eq gnus-summary-goto-unread 'never)
6711                           (not (gnus-summary-first-article-p article)))
6712                      (gnus-summary-prev-article)
6713                    (gnus-summary-prev-unread-article))))))))
6714   (gnus-summary-position-point))
6715
6716 (defun gnus-summary-prev-page-or-article (&optional lines)
6717   "Show previous page of selected article.
6718 Argument LINES specifies lines to be scrolled down.
6719 If at the beginning of the article, go to the next article."
6720   (interactive "P")
6721   (gnus-summary-prev-page lines t))
6722
6723 (defun gnus-summary-scroll-up (lines)
6724   "Scroll up (or down) one line current article.
6725 Argument LINES specifies lines to be scrolled up (or down if negative)."
6726   (interactive "p")
6727   (gnus-configure-windows 'article)
6728   (gnus-summary-show-thread)
6729   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6730     (gnus-eval-in-buffer-window gnus-article-buffer
6731       (cond ((> lines 0)
6732              (when (gnus-article-next-page lines)
6733                (gnus-message 3 "End of message")))
6734             ((< lines 0)
6735              (gnus-article-prev-page (- lines))))))
6736   (gnus-summary-recenter)
6737   (gnus-summary-position-point))
6738
6739 (defun gnus-summary-scroll-down (lines)
6740   "Scroll down (or up) one line current article.
6741 Argument LINES specifies lines to be scrolled down (or up if negative)."
6742   (interactive "p")
6743   (gnus-summary-scroll-up (- lines)))
6744
6745 (defun gnus-summary-next-same-subject ()
6746   "Select next article which has the same subject as current one."
6747   (interactive)
6748   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6749
6750 (defun gnus-summary-prev-same-subject ()
6751   "Select previous article which has the same subject as current one."
6752   (interactive)
6753   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6754
6755 (defun gnus-summary-next-unread-same-subject ()
6756   "Select next unread article which has the same subject as current one."
6757   (interactive)
6758   (gnus-summary-next-article t (gnus-summary-article-subject)))
6759
6760 (defun gnus-summary-prev-unread-same-subject ()
6761   "Select previous unread article which has the same subject as current one."
6762   (interactive)
6763   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6764
6765 (defun gnus-summary-first-unread-article ()
6766   "Select the first unread article.
6767 Return nil if there are no unread articles."
6768   (interactive)
6769   (prog1
6770       (when (gnus-summary-first-subject t)
6771         (gnus-summary-show-thread)
6772         (gnus-summary-first-subject t)
6773         (gnus-summary-display-article (gnus-summary-article-number)))
6774     (gnus-summary-position-point)))
6775
6776 (defun gnus-summary-first-unread-subject ()
6777   "Place the point on the subject line of the first unread article.
6778 Return nil if there are no unread articles."
6779   (interactive)
6780   (prog1
6781       (when (gnus-summary-first-subject t)
6782         (gnus-summary-show-thread)
6783         (gnus-summary-first-subject t))
6784     (gnus-summary-position-point)))
6785
6786 (defun gnus-summary-first-unseen-subject ()
6787   "Place the point on the subject line of the first unseen article.
6788 Return nil if there are no unseen articles."
6789   (interactive)
6790   (prog1
6791       (when (gnus-summary-first-subject t t t)
6792         (gnus-summary-show-thread)
6793         (gnus-summary-first-subject t t t))
6794     (gnus-summary-position-point)))
6795
6796 (defun gnus-summary-first-article ()
6797   "Select the first article.
6798 Return nil if there are no articles."
6799   (interactive)
6800   (prog1
6801       (when (gnus-summary-first-subject)
6802         (gnus-summary-show-thread)
6803         (gnus-summary-first-subject)
6804         (gnus-summary-display-article (gnus-summary-article-number)))
6805     (gnus-summary-position-point)))
6806
6807 (defun gnus-summary-best-unread-article (&optional arg)
6808   "Select the unread article with the highest score.
6809 If given a prefix argument, select the next unread article that has a
6810 score higher than the default score."
6811   (interactive "P")
6812   (let ((article (if arg
6813                      (gnus-summary-better-unread-subject)
6814                    (gnus-summary-best-unread-subject))))
6815     (if article
6816         (gnus-summary-goto-article article)
6817       (error "No unread articles"))))
6818
6819 (defun gnus-summary-best-unread-subject ()
6820   "Select the unread subject with the highest score."
6821   (interactive)
6822   (let ((best -1000000)
6823         (data gnus-newsgroup-data)
6824         article score)
6825     (while data
6826       (and (gnus-data-unread-p (car data))
6827            (> (setq score
6828                     (gnus-summary-article-score (gnus-data-number (car data))))
6829               best)
6830            (setq best score
6831                  article (gnus-data-number (car data))))
6832       (setq data (cdr data)))
6833     (when article
6834       (gnus-summary-goto-subject article))
6835     (gnus-summary-position-point)
6836     article))
6837
6838 (defun gnus-summary-better-unread-subject ()
6839   "Select the first unread subject that has a score over the default score."
6840   (interactive)
6841   (let ((data gnus-newsgroup-data)
6842         article score)
6843     (while (and (setq article (gnus-data-number (car data)))
6844                 (or (gnus-data-read-p (car data))
6845                     (not (> (gnus-summary-article-score article)
6846                             gnus-summary-default-score))))
6847       (setq data (cdr data)))
6848     (when article
6849       (gnus-summary-goto-subject article))
6850     (gnus-summary-position-point)
6851     article))
6852
6853 (defun gnus-summary-last-subject ()
6854   "Go to the last displayed subject line in the group."
6855   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6856     (when article
6857       (gnus-summary-goto-subject article))))
6858
6859 (defun gnus-summary-goto-article (article &optional all-headers force)
6860   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6861 If ALL-HEADERS is non-nil, no header lines are hidden.
6862 If FORCE, go to the article even if it isn't displayed.  If FORCE
6863 is a number, it is the line the article is to be displayed on."
6864   (interactive
6865    (list
6866     (completing-read
6867      "Article number or Message-ID: "
6868      (mapcar (lambda (number) (list (int-to-string number)))
6869              gnus-newsgroup-limit))
6870     current-prefix-arg
6871     t))
6872   (prog1
6873       (if (and (stringp article)
6874                (string-match "@" article))
6875           (gnus-summary-refer-article article)
6876         (when (stringp article)
6877           (setq article (string-to-number article)))
6878         (if (gnus-summary-goto-subject article force)
6879             (gnus-summary-display-article article all-headers)
6880           (gnus-message 4 "Couldn't go to article %s" article) nil))
6881     (gnus-summary-position-point)))
6882
6883 (defun gnus-summary-goto-last-article ()
6884   "Go to the previously read article."
6885   (interactive)
6886   (prog1
6887       (when gnus-last-article
6888         (gnus-summary-goto-article gnus-last-article nil t))
6889     (gnus-summary-position-point)))
6890
6891 (defun gnus-summary-pop-article (number)
6892   "Pop one article off the history and go to the previous.
6893 NUMBER articles will be popped off."
6894   (interactive "p")
6895   (let (to)
6896     (setq gnus-newsgroup-history
6897           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6898     (if to
6899         (gnus-summary-goto-article (car to) nil t)
6900       (error "Article history empty")))
6901   (gnus-summary-position-point))
6902
6903 ;; Summary commands and functions for limiting the summary buffer.
6904
6905 (defun gnus-summary-limit-to-articles (n)
6906   "Limit the summary buffer to the next N articles.
6907 If not given a prefix, use the process marked articles instead."
6908   (interactive "P")
6909   (prog1
6910       (let ((articles (gnus-summary-work-articles n)))
6911         (setq gnus-newsgroup-processable nil)
6912         (gnus-summary-limit articles))
6913     (gnus-summary-position-point)))
6914
6915 (defun gnus-summary-pop-limit (&optional total)
6916   "Restore the previous limit.
6917 If given a prefix, remove all limits."
6918   (interactive "P")
6919   (when total
6920     (setq gnus-newsgroup-limits
6921           (list (mapcar (lambda (h) (mail-header-number h))
6922                         gnus-newsgroup-headers))))
6923   (unless gnus-newsgroup-limits
6924     (error "No limit to pop"))
6925   (prog1
6926       (gnus-summary-limit nil 'pop)
6927     (gnus-summary-position-point)))
6928
6929 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6930   "Limit the summary buffer to articles that have subjects that match a regexp.
6931 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6932   (interactive
6933    (list (read-string (if current-prefix-arg
6934                           "Exclude subject (regexp): "
6935                         "Limit to subject (regexp): "))
6936          nil current-prefix-arg))
6937   (unless header
6938     (setq header "subject"))
6939   (when (not (equal "" subject))
6940     (prog1
6941         (let ((articles (gnus-summary-find-matching
6942                          (or header "subject") subject 'all nil nil
6943                          not-matching)))
6944           (unless articles
6945             (error "Found no matches for \"%s\"" subject))
6946           (gnus-summary-limit articles))
6947       (gnus-summary-position-point))))
6948
6949 (defun gnus-summary-limit-to-author (from &optional not-matching)
6950   "Limit the summary buffer to articles that have authors that match a regexp.
6951 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6952   (interactive
6953    (list (read-string (if current-prefix-arg
6954                           "Exclude author (regexp): "
6955                         "Limit to author (regexp): "))
6956          current-prefix-arg))
6957   (gnus-summary-limit-to-subject from "from" not-matching))
6958
6959 (defun gnus-summary-limit-to-age (age &optional younger-p)
6960   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6961 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6962 articles that are younger than AGE days."
6963   (interactive
6964    (let ((younger current-prefix-arg)
6965          (days-got nil)
6966          days)
6967      (while (not days-got)
6968        (setq days (if younger
6969                       (read-string "Limit to articles within (in days): ")
6970                     (read-string "Limit to articles older than (in days): ")))
6971        (when (> (length days) 0)
6972          (setq days (read days)))
6973        (if (numberp days)
6974            (progn 
6975              (setq days-got t)
6976              (if (< days 0)
6977                  (progn 
6978                    (setq younger (not younger))
6979                    (setq days (* days -1)))))
6980          (message "Please enter a number.")
6981          (sleep-for 1)))
6982      (list days younger)))
6983   (prog1
6984       (let ((data gnus-newsgroup-data)
6985             (cutoff (days-to-time age))
6986             articles d date is-younger)
6987         (while (setq d (pop data))
6988           (when (and (vectorp (gnus-data-header d))
6989                      (setq date (mail-header-date (gnus-data-header d))))
6990             (setq is-younger (time-less-p
6991                               (time-since (condition-case ()
6992                                               (date-to-time date)
6993                                             (error '(0 0))))
6994                               cutoff))
6995             (when (if younger-p
6996                       is-younger
6997                     (not is-younger))
6998               (push (gnus-data-number d) articles))))
6999         (gnus-summary-limit (nreverse articles)))
7000     (gnus-summary-position-point)))
7001
7002 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7003   "Limit the summary buffer to articles that match an 'extra' header."
7004   (interactive
7005    (let ((header
7006           (intern
7007            (gnus-completing-read
7008             (symbol-name (car gnus-extra-headers))
7009             (if current-prefix-arg
7010                 "Exclude extra header:"
7011               "Limit extra header:")
7012             (mapcar (lambda (x)
7013                       (cons (symbol-name x) x))
7014                     gnus-extra-headers)
7015             nil
7016             t))))
7017      (list header
7018            (read-string (format "%s header %s (regexp): "
7019                                 (if current-prefix-arg "Exclude" "Limit to")
7020                                 header))
7021            current-prefix-arg)))
7022   (when (not (equal "" regexp))
7023     (prog1
7024         (let ((articles (gnus-summary-find-matching
7025                          (cons 'extra header) regexp 'all nil nil
7026                          not-matching)))
7027           (unless articles
7028             (error "Found no matches for \"%s\"" regexp))
7029           (gnus-summary-limit articles))
7030       (gnus-summary-position-point))))
7031
7032 (defun gnus-summary-limit-to-display-predicate ()
7033   "Limit the summary buffer to the predicated in the `display' group parameter."
7034   (interactive)
7035   (unless gnus-newsgroup-display
7036     (error "There is no `display' group parameter"))
7037   (let (articles)
7038     (dolist (number gnus-newsgroup-articles)
7039       (when (funcall gnus-newsgroup-display)
7040         (push number articles)))
7041     (gnus-summary-limit articles))
7042   (gnus-summary-position-point))
7043
7044 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7045 (make-obsolete
7046  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7047
7048 (defun gnus-summary-limit-to-unread (&optional all)
7049   "Limit the summary buffer to articles that are not marked as read.
7050 If ALL is non-nil, limit strictly to unread articles."
7051   (interactive "P")
7052   (if all
7053       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7054     (gnus-summary-limit-to-marks
7055      ;; Concat all the marks that say that an article is read and have
7056      ;; those removed.
7057      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7058            gnus-killed-mark gnus-kill-file-mark
7059            gnus-low-score-mark gnus-expirable-mark
7060            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7061            gnus-duplicate-mark gnus-souped-mark)
7062      'reverse)))
7063
7064 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7065 (make-obsolete 'gnus-summary-delete-marked-with
7066                'gnus-summary-limit-exlude-marks)
7067
7068 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7069   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7070 If REVERSE, limit the summary buffer to articles that are marked
7071 with MARKS.  MARKS can either be a string of marks or a list of marks.
7072 Returns how many articles were removed."
7073   (interactive "sMarks: ")
7074   (gnus-summary-limit-to-marks marks t))
7075
7076 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7077   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7078 If REVERSE (the prefix), limit the summary buffer to articles that are
7079 not marked with MARKS.  MARKS can either be a string of marks or a
7080 list of marks.
7081 Returns how many articles were removed."
7082   (interactive "sMarks: \nP")
7083   (prog1
7084       (let ((data gnus-newsgroup-data)
7085             (marks (if (listp marks) marks
7086                      (append marks nil))) ; Transform to list.
7087             articles)
7088         (while data
7089           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7090                   (memq (gnus-data-mark (car data)) marks))
7091             (push (gnus-data-number (car data)) articles))
7092           (setq data (cdr data)))
7093         (gnus-summary-limit articles))
7094     (gnus-summary-position-point)))
7095
7096 (defun gnus-summary-limit-to-score (score)
7097   "Limit to articles with score at or above SCORE."
7098   (interactive "NLimit to articles with score of at least: ")
7099   (let ((data gnus-newsgroup-data)
7100         articles)
7101     (while data
7102       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7103                 score)
7104         (push (gnus-data-number (car data)) articles))
7105       (setq data (cdr data)))
7106     (prog1
7107         (gnus-summary-limit articles)
7108       (gnus-summary-position-point))))
7109
7110 (defun gnus-summary-limit-include-thread (id)
7111   "Display all the hidden articles that is in the thread with ID in it.
7112 When called interactively, ID is the Message-ID of the current
7113 article."
7114   (interactive (list (mail-header-id (gnus-summary-article-header))))
7115   (let ((articles (gnus-articles-in-thread
7116                    (gnus-id-to-thread (gnus-root-id id)))))
7117     (prog1
7118         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7119       (gnus-summary-limit-include-matching-articles
7120        "subject"
7121        (regexp-quote (gnus-simplify-subject-re
7122                       (mail-header-subject (gnus-id-to-header id)))))
7123       (gnus-summary-position-point))))
7124
7125 (defun gnus-summary-limit-include-matching-articles (header regexp)
7126   "Display all the hidden articles that have HEADERs that match REGEXP."
7127   (interactive (list (read-string "Match on header: ")
7128                      (read-string "Regexp: ")))
7129   (let ((articles (gnus-find-matching-articles header regexp)))
7130     (prog1
7131         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7132       (gnus-summary-position-point))))
7133
7134 (defun gnus-summary-limit-include-dormant ()
7135   "Display all the hidden articles that are marked as dormant.
7136 Note that this command only works on a subset of the articles currently
7137 fetched for this group."
7138   (interactive)
7139   (unless gnus-newsgroup-dormant
7140     (error "There are no dormant articles in this group"))
7141   (prog1
7142       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7143     (gnus-summary-position-point)))
7144
7145 (defun gnus-summary-limit-exclude-dormant ()
7146   "Hide all dormant articles."
7147   (interactive)
7148   (prog1
7149       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7150     (gnus-summary-position-point)))
7151
7152 (defun gnus-summary-limit-exclude-childless-dormant ()
7153   "Hide all dormant articles that have no children."
7154   (interactive)
7155   (let ((data (gnus-data-list t))
7156         articles d children)
7157     ;; Find all articles that are either not dormant or have
7158     ;; children.
7159     (while (setq d (pop data))
7160       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7161                 (and (setq children
7162                            (gnus-article-children (gnus-data-number d)))
7163                      (let (found)
7164                        (while children
7165                          (when (memq (car children) articles)
7166                            (setq children nil
7167                                  found t))
7168                          (pop children))
7169                        found)))
7170         (push (gnus-data-number d) articles)))
7171     ;; Do the limiting.
7172     (prog1
7173         (gnus-summary-limit articles)
7174       (gnus-summary-position-point))))
7175
7176 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7177   "Mark all unread excluded articles as read.
7178 If ALL, mark even excluded ticked and dormants as read."
7179   (interactive "P")
7180   (let ((articles (gnus-sorted-complement
7181                    (sort
7182                     (mapcar (lambda (h) (mail-header-number h))
7183                             gnus-newsgroup-headers)
7184                     '<)
7185                    (sort gnus-newsgroup-limit '<)))
7186         article)
7187     (setq gnus-newsgroup-unreads
7188           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7189     (if all
7190         (setq gnus-newsgroup-dormant nil
7191               gnus-newsgroup-marked nil
7192               gnus-newsgroup-reads
7193               (nconc
7194                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7195                gnus-newsgroup-reads))
7196       (while (setq article (pop articles))
7197         (unless (or (memq article gnus-newsgroup-dormant)
7198                     (memq article gnus-newsgroup-marked))
7199           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7200
7201 (defun gnus-summary-limit (articles &optional pop)
7202   (if pop
7203       ;; We pop the previous limit off the stack and use that.
7204       (setq articles (car gnus-newsgroup-limits)
7205             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7206     ;; We use the new limit, so we push the old limit on the stack.
7207     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7208   ;; Set the limit.
7209   (setq gnus-newsgroup-limit articles)
7210   (let ((total (length gnus-newsgroup-data))
7211         (data (gnus-data-find-list (gnus-summary-article-number)))
7212         (gnus-summary-mark-below nil)   ; Inhibit this.
7213         found)
7214     ;; This will do all the work of generating the new summary buffer
7215     ;; according to the new limit.
7216     (gnus-summary-prepare)
7217     ;; Hide any threads, possibly.
7218     (gnus-summary-maybe-hide-threads)
7219     ;; Try to return to the article you were at, or one in the
7220     ;; neighborhood.
7221     (when data
7222       ;; We try to find some article after the current one.
7223       (while data
7224         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7225           (setq data nil
7226                 found t))
7227         (setq data (cdr data))))
7228     (unless found
7229       ;; If there is no data, that means that we were after the last
7230       ;; article.  The same goes when we can't find any articles
7231       ;; after the current one.
7232       (goto-char (point-max))
7233       (gnus-summary-find-prev))
7234     (gnus-set-mode-line 'summary)
7235     ;; We return how many articles were removed from the summary
7236     ;; buffer as a result of the new limit.
7237     (- total (length gnus-newsgroup-data))))
7238
7239 (defsubst gnus-invisible-cut-children (threads)
7240   (let ((num 0))
7241     (while threads
7242       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7243         (incf num))
7244       (pop threads))
7245     (< num 2)))
7246
7247 (defsubst gnus-cut-thread (thread)
7248   "Go forwards in the thread until we find an article that we want to display."
7249   (when (or (eq gnus-fetch-old-headers 'some)
7250             (eq gnus-fetch-old-headers 'invisible)
7251             (numberp gnus-fetch-old-headers)
7252             (eq gnus-build-sparse-threads 'some)
7253             (eq gnus-build-sparse-threads 'more))
7254     ;; Deal with old-fetched headers and sparse threads.
7255     (while (and
7256             thread
7257             (or
7258              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7259              (gnus-summary-article-ancient-p
7260               (mail-header-number (car thread))))
7261             (if (or (<= (length (cdr thread)) 1)
7262                     (eq gnus-fetch-old-headers 'invisible))
7263                 (setq gnus-newsgroup-limit
7264                       (delq (mail-header-number (car thread))
7265                             gnus-newsgroup-limit)
7266                       thread (cadr thread))
7267               (when (gnus-invisible-cut-children (cdr thread))
7268                 (let ((th (cdr thread)))
7269                   (while th
7270                     (if (memq (mail-header-number (caar th))
7271                               gnus-newsgroup-limit)
7272                         (setq thread (car th)
7273                               th nil)
7274                       (setq th (cdr th))))))))))
7275   thread)
7276
7277 (defun gnus-cut-threads (threads)
7278   "Cut off all uninteresting articles from the beginning of threads."
7279   (when (or (eq gnus-fetch-old-headers 'some)
7280             (eq gnus-fetch-old-headers 'invisible)
7281             (numberp gnus-fetch-old-headers)
7282             (eq gnus-build-sparse-threads 'some)
7283             (eq gnus-build-sparse-threads 'more))
7284     (let ((th threads))
7285       (while th
7286         (setcar th (gnus-cut-thread (car th)))
7287         (setq th (cdr th)))))
7288   ;; Remove nixed out threads.
7289   (delq nil threads))
7290
7291 (defun gnus-summary-initial-limit (&optional show-if-empty)
7292   "Figure out what the initial limit is supposed to be on group entry.
7293 This entails weeding out unwanted dormants, low-scored articles,
7294 fetch-old-headers verbiage, and so on."
7295   ;; Most groups have nothing to remove.
7296   (if (or gnus-inhibit-limiting
7297           (and (null gnus-newsgroup-dormant)
7298                (eq gnus-newsgroup-display 'gnus-not-ignore)
7299                (not (eq gnus-fetch-old-headers 'some))
7300                (not (numberp gnus-fetch-old-headers))
7301                (not (eq gnus-fetch-old-headers 'invisible))
7302                (null gnus-summary-expunge-below)
7303                (not (eq gnus-build-sparse-threads 'some))
7304                (not (eq gnus-build-sparse-threads 'more))
7305                (null gnus-thread-expunge-below)
7306                (not gnus-use-nocem)))
7307       ()                                ; Do nothing.
7308     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7309     (setq gnus-newsgroup-limit nil)
7310     (mapatoms
7311      (lambda (node)
7312        (unless (car (symbol-value node))
7313          ;; These threads have no parents -- they are roots.
7314          (let ((nodes (cdr (symbol-value node)))
7315                thread)
7316            (while nodes
7317              (if (and gnus-thread-expunge-below
7318                       (< (gnus-thread-total-score (car nodes))
7319                          gnus-thread-expunge-below))
7320                  (gnus-expunge-thread (pop nodes))
7321                (setq thread (pop nodes))
7322                (gnus-summary-limit-children thread))))))
7323      gnus-newsgroup-dependencies)
7324     ;; If this limitation resulted in an empty group, we might
7325     ;; pop the previous limit and use it instead.
7326     (when (and (not gnus-newsgroup-limit)
7327                show-if-empty)
7328       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7329     gnus-newsgroup-limit))
7330
7331 (defun gnus-summary-limit-children (thread)
7332   "Return 1 if this subthread is visible and 0 if it is not."
7333   ;; First we get the number of visible children to this thread.  This
7334   ;; is done by recursing down the thread using this function, so this
7335   ;; will really go down to a leaf article first, before slowly
7336   ;; working its way up towards the root.
7337   (when thread
7338     (let ((children
7339            (if (cdr thread)
7340                (apply '+ (mapcar 'gnus-summary-limit-children
7341                                  (cdr thread)))
7342              0))
7343           (number (mail-header-number (car thread)))
7344           score)
7345       (if (and
7346            (not (memq number gnus-newsgroup-marked))
7347            (or
7348             ;; If this article is dormant and has absolutely no visible
7349             ;; children, then this article isn't visible.
7350             (and (memq number gnus-newsgroup-dormant)
7351                  (zerop children))
7352             ;; If this is "fetch-old-headered" and there is no
7353             ;; visible children, then we don't want this article.
7354             (and (or (eq gnus-fetch-old-headers 'some)
7355                      (numberp gnus-fetch-old-headers))
7356                  (gnus-summary-article-ancient-p number)
7357                  (zerop children))
7358             ;; If this is "fetch-old-headered" and `invisible', then
7359             ;; we don't want this article.
7360             (and (eq gnus-fetch-old-headers 'invisible)
7361                  (gnus-summary-article-ancient-p number))
7362             ;; If this is a sparsely inserted article with no children,
7363             ;; we don't want it.
7364             (and (eq gnus-build-sparse-threads 'some)
7365                  (gnus-summary-article-sparse-p number)
7366                  (zerop children))
7367             ;; If we use expunging, and this article is really
7368             ;; low-scored, then we don't want this article.
7369             (when (and gnus-summary-expunge-below
7370                        (< (setq score
7371                                 (or (cdr (assq number gnus-newsgroup-scored))
7372                                     gnus-summary-default-score))
7373                           gnus-summary-expunge-below))
7374               ;; We increase the expunge-tally here, but that has
7375               ;; nothing to do with the limits, really.
7376               (incf gnus-newsgroup-expunged-tally)
7377               ;; We also mark as read here, if that's wanted.
7378               (when (and gnus-summary-mark-below
7379                          (< score gnus-summary-mark-below))
7380                 (setq gnus-newsgroup-unreads
7381                       (delq number gnus-newsgroup-unreads))
7382                 (if gnus-newsgroup-auto-expire
7383                     (push number gnus-newsgroup-expirable)
7384                   (push (cons number gnus-low-score-mark)
7385                         gnus-newsgroup-reads)))
7386               t)
7387             ;; Do the `display' group parameter.
7388             (and gnus-newsgroup-display
7389                  (not (funcall gnus-newsgroup-display)))
7390             ;; Check NoCeM things.
7391             (if (and gnus-use-nocem
7392                      (gnus-nocem-unwanted-article-p
7393                       (mail-header-id (car thread))))
7394                 (progn
7395                   (setq gnus-newsgroup-unreads
7396                         (delq number gnus-newsgroup-unreads))
7397                   t))))
7398           ;; Nope, invisible article.
7399           0
7400         ;; Ok, this article is to be visible, so we add it to the limit
7401         ;; and return 1.
7402         (push number gnus-newsgroup-limit)
7403         1))))
7404
7405 (defun gnus-expunge-thread (thread)
7406   "Mark all articles in THREAD as read."
7407   (let* ((number (mail-header-number (car thread))))
7408     (incf gnus-newsgroup-expunged-tally)
7409     ;; We also mark as read here, if that's wanted.
7410     (setq gnus-newsgroup-unreads
7411           (delq number gnus-newsgroup-unreads))
7412     (if gnus-newsgroup-auto-expire
7413         (push number gnus-newsgroup-expirable)
7414       (push (cons number gnus-low-score-mark)
7415             gnus-newsgroup-reads)))
7416   ;; Go recursively through all subthreads.
7417   (mapcar 'gnus-expunge-thread (cdr thread)))
7418
7419 ;; Summary article oriented commands
7420
7421 (defun gnus-summary-refer-parent-article (n)
7422   "Refer parent article N times.
7423 If N is negative, go to ancestor -N instead.
7424 The difference between N and the number of articles fetched is returned."
7425   (interactive "p")
7426   (let ((skip 1)
7427         error header ref)
7428     (when (not (natnump n))
7429       (setq skip (abs n)
7430             n 1))
7431     (while (and (> n 0)
7432                 (not error))
7433       (setq header (gnus-summary-article-header))
7434       (if (and (eq (mail-header-number header)
7435                    (cdr gnus-article-current))
7436                (equal gnus-newsgroup-name
7437                       (car gnus-article-current)))
7438           ;; If we try to find the parent of the currently
7439           ;; displayed article, then we take a look at the actual
7440           ;; References header, since this is slightly more
7441           ;; reliable than the References field we got from the
7442           ;; server.
7443           (save-excursion
7444             (set-buffer gnus-original-article-buffer)
7445             (nnheader-narrow-to-headers)
7446             (unless (setq ref (message-fetch-field "references"))
7447               (setq ref (message-fetch-field "in-reply-to")))
7448             (widen))
7449         (setq ref
7450               ;; It's not the current article, so we take a bet on
7451               ;; the value we got from the server.
7452               (mail-header-references header)))
7453       (if (and ref
7454                (not (equal ref "")))
7455           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7456             (gnus-message 1 "Couldn't find parent"))
7457         (gnus-message 1 "No references in article %d"
7458                       (gnus-summary-article-number))
7459         (setq error t))
7460       (decf n))
7461     (gnus-summary-position-point)
7462     n))
7463
7464 (defun gnus-summary-refer-references ()
7465   "Fetch all articles mentioned in the References header.
7466 Return the number of articles fetched."
7467   (interactive)
7468   (let ((ref (mail-header-references (gnus-summary-article-header)))
7469         (current (gnus-summary-article-number))
7470         (n 0))
7471     (if (or (not ref)
7472             (equal ref ""))
7473         (error "No References in the current article")
7474       ;; For each Message-ID in the References header...
7475       (while (string-match "<[^>]*>" ref)
7476         (incf n)
7477         ;; ... fetch that article.
7478         (gnus-summary-refer-article
7479          (prog1 (match-string 0 ref)
7480            (setq ref (substring ref (match-end 0))))))
7481       (gnus-summary-goto-subject current)
7482       (gnus-summary-position-point)
7483       n)))
7484
7485 (defun gnus-summary-refer-thread (&optional limit)
7486   "Fetch all articles in the current thread.
7487 If LIMIT (the numerical prefix), fetch that many old headers instead
7488 of what's specified by the `gnus-refer-thread-limit' variable."
7489   (interactive "P")
7490   (let ((id (mail-header-id (gnus-summary-article-header)))
7491         (limit (if limit (prefix-numeric-value limit)
7492                  gnus-refer-thread-limit)))
7493     ;; We want to fetch LIMIT *old* headers, but we also have to
7494     ;; re-fetch all the headers in the current buffer, because many of
7495     ;; them may be undisplayed.  So we adjust LIMIT.
7496     (when (numberp limit)
7497       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7498     (unless (eq gnus-fetch-old-headers 'invisible)
7499       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7500       ;; Retrieve the headers and read them in.
7501       (if (eq (gnus-retrieve-headers
7502                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7503               'nov)
7504           (gnus-build-all-threads)
7505         (error "Can't fetch thread from backends that don't support NOV"))
7506       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7507     (gnus-summary-limit-include-thread id)))
7508
7509 (defun gnus-summary-refer-article (message-id)
7510   "Fetch an article specified by MESSAGE-ID."
7511   (interactive "sMessage-ID: ")
7512   (when (and (stringp message-id)
7513              (not (zerop (length message-id))))
7514     ;; Construct the correct Message-ID if necessary.
7515     ;; Suggested by tale@pawl.rpi.edu.
7516     (unless (string-match "^<" message-id)
7517       (setq message-id (concat "<" message-id)))
7518     (unless (string-match ">$" message-id)
7519       (setq message-id (concat message-id ">")))
7520     (let* ((header (gnus-id-to-header message-id))
7521            (sparse (and header
7522                         (gnus-summary-article-sparse-p
7523                          (mail-header-number header))
7524                         (memq (mail-header-number header)
7525                               gnus-newsgroup-limit)))
7526            number)
7527       (cond
7528        ;; If the article is present in the buffer we just go to it.
7529        ((and header
7530              (or (not (gnus-summary-article-sparse-p
7531                        (mail-header-number header)))
7532                  sparse))
7533         (prog1
7534             (gnus-summary-goto-article
7535              (mail-header-number header) nil t)
7536           (when sparse
7537             (gnus-summary-update-article (mail-header-number header)))))
7538        (t
7539         ;; We fetch the article.
7540         (catch 'found
7541           (dolist (gnus-override-method (gnus-refer-article-methods))
7542             (gnus-check-server gnus-override-method)
7543             ;; Fetch the header, and display the article.
7544             (when (setq number (gnus-summary-insert-subject message-id))
7545               (gnus-summary-select-article nil nil nil number)
7546               (throw 'found t)))
7547           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7548
7549 (defun gnus-refer-article-methods ()
7550   "Return a list of referrable methods."
7551   (cond
7552    ;; No method, so we default to current and native.
7553    ((null gnus-refer-article-method)
7554     (list gnus-current-select-method gnus-select-method))
7555    ;; Current.
7556    ((eq 'current gnus-refer-article-method)
7557     (list gnus-current-select-method))
7558    ;; List of select methods.
7559    ((not (and (symbolp (car gnus-refer-article-method))
7560               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7561     (let (out)
7562       (dolist (method gnus-refer-article-method)
7563         (push (if (eq 'current method)
7564                   gnus-current-select-method
7565                 method)
7566               out))
7567       (nreverse out)))
7568    ;; One single select method.
7569    (t
7570     (list gnus-refer-article-method))))
7571
7572 (defun gnus-summary-edit-parameters ()
7573   "Edit the group parameters of the current group."
7574   (interactive)
7575   (gnus-group-edit-group gnus-newsgroup-name 'params))
7576
7577 (defun gnus-summary-customize-parameters ()
7578   "Customize the group parameters of the current group."
7579   (interactive)
7580   (gnus-group-customize gnus-newsgroup-name))
7581
7582 (defun gnus-summary-enter-digest-group (&optional force)
7583   "Enter an nndoc group based on the current article.
7584 If FORCE, force a digest interpretation.  If not, try
7585 to guess what the document format is."
7586   (interactive "P")
7587   (let ((conf gnus-current-window-configuration))
7588     (save-excursion
7589       (gnus-summary-select-article))
7590     (setq gnus-current-window-configuration conf)
7591     (let* ((name (format "%s-%d"
7592                          (gnus-group-prefixed-name
7593                           gnus-newsgroup-name (list 'nndoc ""))
7594                          (save-excursion
7595                            (set-buffer gnus-summary-buffer)
7596                            gnus-current-article)))
7597            (ogroup gnus-newsgroup-name)
7598            (params (append (gnus-info-params (gnus-get-info ogroup))
7599                            (list (cons 'to-group ogroup))
7600                            (list (cons 'save-article-group ogroup))))
7601            (case-fold-search t)
7602            (buf (current-buffer))
7603            dig to-address)
7604       (save-excursion
7605         (set-buffer gnus-original-article-buffer)
7606         ;; Have the digest group inherit the main mail address of
7607         ;; the parent article.
7608         (when (setq to-address (or (message-fetch-field "reply-to")
7609                                    (message-fetch-field "from")))
7610           (setq params (append
7611                         (list (cons 'to-address
7612                                     (funcall gnus-decode-encoded-word-function
7613                                              to-address))))))
7614         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7615         (insert-buffer-substring gnus-original-article-buffer)
7616         ;; Remove lines that may lead nndoc to misinterpret the
7617         ;; document type.
7618         (narrow-to-region
7619          (goto-char (point-min))
7620          (or (search-forward "\n\n" nil t) (point)))
7621         (goto-char (point-min))
7622         (delete-matching-lines "^Path:\\|^From ")
7623         (widen))
7624       (unwind-protect
7625           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7626                     (gnus-newsgroup-ephemeral-ignored-charsets
7627                      gnus-newsgroup-ignored-charsets))
7628                 (gnus-group-read-ephemeral-group
7629                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7630                               (nndoc-article-type
7631                                ,(if force 'mbox 'guess))) t))
7632             ;; Make all postings to this group go to the parent group.
7633               (nconc (gnus-info-params (gnus-get-info name))
7634                      params)
7635             ;; Couldn't select this doc group.
7636             (switch-to-buffer buf)
7637             (gnus-set-global-variables)
7638             (gnus-configure-windows 'summary)
7639             (gnus-message 3 "Article couldn't be entered?"))
7640         (kill-buffer dig)))))
7641
7642 (defun gnus-summary-read-document (n)
7643   "Open a new group based on the current article(s).
7644 This will allow you to read digests and other similar
7645 documents as newsgroups.
7646 Obeys the standard process/prefix convention."
7647   (interactive "P")
7648   (let* ((articles (gnus-summary-work-articles n))
7649          (ogroup gnus-newsgroup-name)
7650          (params (append (gnus-info-params (gnus-get-info ogroup))
7651                          (list (cons 'to-group ogroup))))
7652          article group egroup groups vgroup)
7653     (while (setq article (pop articles))
7654       (setq group (format "%s-%d" gnus-newsgroup-name article))
7655       (gnus-summary-remove-process-mark article)
7656       (when (gnus-summary-display-article article)
7657         (save-excursion
7658           (with-temp-buffer
7659             (insert-buffer-substring gnus-original-article-buffer)
7660             ;; Remove some headers that may lead nndoc to make
7661             ;; the wrong guess.
7662             (message-narrow-to-head)
7663             (goto-char (point-min))
7664             (delete-matching-lines "^\\(Path\\):\\|^From ")
7665             (widen)
7666             (if (setq egroup
7667                       (gnus-group-read-ephemeral-group
7668                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7669                                      (nndoc-article-type guess))
7670                        t nil t))
7671                 (progn
7672             ;; Make all postings to this group go to the parent group.
7673                   (nconc (gnus-info-params (gnus-get-info egroup))
7674                          params)
7675                   (push egroup groups))
7676               ;; Couldn't select this doc group.
7677               (gnus-error 3 "Article couldn't be entered"))))))
7678     ;; Now we have selected all the documents.
7679     (cond
7680      ((not groups)
7681       (error "None of the articles could be interpreted as documents"))
7682      ((gnus-group-read-ephemeral-group
7683        (setq vgroup (format
7684                      "nnvirtual:%s-%s" gnus-newsgroup-name
7685                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7686        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7687        t
7688        (cons (current-buffer) 'summary)))
7689      (t
7690       (error "Couldn't select virtual nndoc group")))))
7691
7692 (defun gnus-summary-isearch-article (&optional regexp-p)
7693   "Do incremental search forward on the current article.
7694 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7695   (interactive "P")
7696   (gnus-summary-select-article)
7697   (gnus-configure-windows 'article)
7698   (gnus-eval-in-buffer-window gnus-article-buffer
7699     (save-restriction
7700       (widen)
7701       (isearch-forward regexp-p))))
7702
7703 (defun gnus-summary-search-article-forward (regexp &optional backward)
7704   "Search for an article containing REGEXP forward.
7705 If BACKWARD, search backward instead."
7706   (interactive
7707    (list (read-string
7708           (format "Search article %s (regexp%s): "
7709                   (if current-prefix-arg "backward" "forward")
7710                   (if gnus-last-search-regexp
7711                       (concat ", default " gnus-last-search-regexp)
7712                     "")))
7713          current-prefix-arg))
7714   (if (string-equal regexp "")
7715       (setq regexp (or gnus-last-search-regexp ""))
7716     (setq gnus-last-search-regexp regexp)
7717     (setq gnus-article-before-search gnus-current-article))
7718   ;; Intentionally set gnus-last-article.
7719   (setq gnus-last-article gnus-article-before-search)
7720   (let ((gnus-last-article gnus-last-article))
7721     (if (gnus-summary-search-article regexp backward)
7722         (gnus-summary-show-thread)
7723       (error "Search failed: \"%s\"" regexp))))
7724
7725 (defun gnus-summary-search-article-backward (regexp)
7726   "Search for an article containing REGEXP backward."
7727   (interactive
7728    (list (read-string
7729           (format "Search article backward (regexp%s): "
7730                   (if gnus-last-search-regexp
7731                       (concat ", default " gnus-last-search-regexp)
7732                     "")))))
7733   (gnus-summary-search-article-forward regexp 'backward))
7734
7735 (defun gnus-summary-search-article (regexp &optional backward)
7736   "Search for an article containing REGEXP.
7737 Optional argument BACKWARD means do search for backward.
7738 `gnus-select-article-hook' is not called during the search."
7739   ;; We have to require this here to make sure that the following
7740   ;; dynamic binding isn't shadowed by autoloading.
7741   (require 'gnus-async)
7742   (require 'gnus-art)
7743   (let ((gnus-select-article-hook nil)  ;Disable hook.
7744         (gnus-article-prepare-hook nil)
7745         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7746         (gnus-use-article-prefetch nil)
7747         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7748         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7749         (sum (current-buffer))
7750         (gnus-display-mime-function nil)
7751         (found nil)
7752         point)
7753     (gnus-save-hidden-threads
7754       (gnus-summary-select-article)
7755       (set-buffer gnus-article-buffer)
7756       (goto-char (window-point (get-buffer-window (current-buffer))))
7757       (when backward
7758         (forward-line -1))
7759       (while (not found)
7760         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7761         (if (if backward
7762                 (re-search-backward regexp nil t)
7763               (re-search-forward regexp nil t))
7764             ;; We found the regexp.
7765             (progn
7766               (setq found 'found)
7767               (beginning-of-line)
7768               (set-window-start
7769                (get-buffer-window (current-buffer))
7770                (point))
7771               (forward-line 1)
7772               (set-window-point
7773                (get-buffer-window (current-buffer))
7774                (point))
7775               (set-buffer sum)
7776               (setq point (point)))
7777           ;; We didn't find it, so we go to the next article.
7778           (set-buffer sum)
7779           (setq found 'not)
7780           (while (eq found 'not)
7781             (if (not (if backward (gnus-summary-find-prev)
7782                        (gnus-summary-find-next)))
7783                 ;; No more articles.
7784                 (setq found t)
7785               ;; Select the next article and adjust point.
7786               (unless (gnus-summary-article-sparse-p
7787                        (gnus-summary-article-number))
7788                 (setq found nil)
7789                 (gnus-summary-select-article)
7790                 (set-buffer gnus-article-buffer)
7791                 (widen)
7792                 (goto-char (if backward (point-max) (point-min))))))))
7793       (gnus-message 7 ""))
7794     ;; Return whether we found the regexp.
7795     (when (eq found 'found)
7796       (goto-char point)
7797       (gnus-summary-show-thread)
7798       (gnus-summary-goto-subject gnus-current-article)
7799       (gnus-summary-position-point)
7800       t)))
7801
7802 (defun gnus-find-matching-articles (header regexp)
7803   "Return a list of all articles that match REGEXP on HEADER.
7804 This search includes all articles in the current group that Gnus has
7805 fetched headers for, whether they are displayed or not."
7806   (let ((articles nil)
7807         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7808         (case-fold-search t))
7809     (dolist (header gnus-newsgroup-headers)
7810       (when (string-match regexp (funcall func header))
7811         (push (mail-header-number header) articles)))
7812     (nreverse articles)))
7813
7814 (defun gnus-summary-find-matching (header regexp &optional backward unread
7815                                           not-case-fold not-matching)
7816   "Return a list of all articles that match REGEXP on HEADER.
7817 The search stars on the current article and goes forwards unless
7818 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7819 If UNREAD is non-nil, only unread articles will
7820 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7821 in the comparisons. If NOT-MATCHING, return a list of all articles that
7822 not match REGEXP on HEADER."
7823   (let ((case-fold-search (not not-case-fold))
7824         articles d func)
7825     (if (consp header)
7826         (if (eq (car header) 'extra)
7827             (setq func
7828                   `(lambda (h)
7829                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7830                          "")))
7831           (error "%s is an invalid header" header))
7832       (unless (fboundp (intern (concat "mail-header-" header)))
7833         (error "%s is not a valid header" header))
7834       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7835     (dolist (d (if (eq backward 'all)
7836                    gnus-newsgroup-data
7837                  (gnus-data-find-list
7838                   (gnus-summary-article-number)
7839                   (gnus-data-list backward))))
7840       (when (and (or (not unread)       ; We want all articles...
7841                      (gnus-data-unread-p d)) ; Or just unreads.
7842                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7843                  (if not-matching
7844                      (not (string-match
7845                            regexp
7846                            (funcall func (gnus-data-header d))))
7847                    (string-match regexp
7848                                  (funcall func (gnus-data-header d)))))
7849         (push (gnus-data-number d) articles))) ; Success!
7850     (nreverse articles)))
7851
7852 (defun gnus-summary-execute-command (header regexp command &optional backward)
7853   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7854 If HEADER is an empty string (or nil), the match is done on the entire
7855 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7856   (interactive
7857    (list (let ((completion-ignore-case t))
7858            (completing-read
7859             "Header name: "
7860             (mapcar (lambda (header) (list (format "%s" header)))
7861                     (append
7862                      '("Number" "Subject" "From" "Lines" "Date"
7863                        "Message-ID" "Xref" "References" "Body")
7864                      gnus-extra-headers))
7865             nil 'require-match))
7866          (read-string "Regexp: ")
7867          (read-key-sequence "Command: ")
7868          current-prefix-arg))
7869   (when (equal header "Body")
7870     (setq header ""))
7871   ;; Hidden thread subtrees must be searched as well.
7872   (gnus-summary-show-all-threads)
7873   ;; We don't want to change current point nor window configuration.
7874   (save-excursion
7875     (save-window-excursion
7876       (gnus-message 6 "Executing %s..." (key-description command))
7877 ;; We'd like to execute COMMAND interactively so as to give arguments.
7878       (gnus-execute header regexp
7879                     `(call-interactively ',(key-binding command))
7880                     backward)
7881       (gnus-message 6 "Executing %s...done" (key-description command)))))
7882
7883 (defun gnus-summary-beginning-of-article ()
7884   "Scroll the article back to the beginning."
7885   (interactive)
7886   (gnus-summary-select-article)
7887   (gnus-configure-windows 'article)
7888   (gnus-eval-in-buffer-window gnus-article-buffer
7889     (widen)
7890     (goto-char (point-min))
7891     (when gnus-page-broken
7892       (gnus-narrow-to-page))))
7893
7894 (defun gnus-summary-end-of-article ()
7895   "Scroll to the end of the article."
7896   (interactive)
7897   (gnus-summary-select-article)
7898   (gnus-configure-windows 'article)
7899   (gnus-eval-in-buffer-window gnus-article-buffer
7900     (widen)
7901     (goto-char (point-max))
7902     (recenter -3)
7903     (when gnus-page-broken
7904       (gnus-narrow-to-page))))
7905
7906 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7907   "Truncate to LEN and quote all \"(\"'s in STRING."
7908   (gnus-replace-in-string (if (and len (> (length string) len))
7909                               (substring string 0 len)
7910                             string)
7911                           "[()]" "\\\\\\&"))
7912
7913 (defun gnus-summary-print-article (&optional filename n)
7914   "Generate and print a PostScript image of the N next (mail) articles.
7915
7916 If N is negative, print the N previous articles.  If N is nil and articles
7917 have been marked with the process mark, print these instead.
7918
7919 If the optional first argument FILENAME is nil, send the image to the
7920 printer.  If FILENAME is a string, save the PostScript image in a file with
7921 that name.  If FILENAME is a number, prompt the user for the name of the file
7922 to save in."
7923   (interactive (list (ps-print-preprint current-prefix-arg)))
7924   (dolist (article (gnus-summary-work-articles n))
7925     (gnus-summary-select-article nil nil 'pseudo article)
7926     (gnus-eval-in-buffer-window gnus-article-buffer
7927       (gnus-print-buffer))
7928     (gnus-summary-remove-process-mark article))
7929   (ps-despool filename))
7930
7931 (defun gnus-print-buffer ()
7932   (let ((buffer (generate-new-buffer " *print*")))
7933     (unwind-protect
7934         (progn
7935           (copy-to-buffer buffer (point-min) (point-max))
7936           (set-buffer buffer)
7937           (gnus-article-delete-invisible-text)
7938           (when (gnus-visual-p 'article-highlight 'highlight)
7939             ;; Copy-to-buffer doesn't copy overlay.  So redo
7940             ;; highlight.
7941             (let ((gnus-article-buffer buffer))
7942               (gnus-article-highlight-citation t)
7943               (gnus-article-highlight-signature)))
7944           (let ((ps-left-header
7945                  (list
7946                   (concat "("
7947                           (gnus-summary-print-truncate-and-quote
7948                            (mail-header-subject gnus-current-headers)
7949                            66) ")")
7950                   (concat "("
7951                           (gnus-summary-print-truncate-and-quote
7952                            (mail-header-from gnus-current-headers)
7953                            45) ")")))
7954                 (ps-right-header
7955                  (list
7956                   "/pagenumberstring load"
7957                   (concat "("
7958                           (mail-header-date gnus-current-headers) ")"))))
7959             (gnus-run-hooks 'gnus-ps-print-hook)
7960             (save-excursion
7961               (if window-system
7962                   (ps-spool-buffer-with-faces)
7963                 (ps-spool-buffer)))))
7964       (kill-buffer buffer))))
7965
7966 (defun gnus-summary-show-article (&optional arg)
7967   "Force redisplaying of the current article.
7968 If ARG (the prefix) is a number, show the article with the charset
7969 defined in `gnus-summary-show-article-charset-alist', or the charset
7970 input.
7971 If ARG (the prefix) is non-nil and not a number, show the raw article
7972 without any article massaging functions being run.  Normally, the key strokes 
7973 are `C-u g'."
7974   (interactive "P")
7975   (cond
7976    ((numberp arg)
7977     (gnus-summary-show-article t)
7978     (let ((gnus-newsgroup-charset
7979            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7980                (mm-read-coding-system
7981                 "View as charset: "
7982                 (save-excursion
7983                   (set-buffer gnus-article-buffer)
7984                   (let ((coding-systems
7985                          (detect-coding-region (point) (point-max))))
7986                     (or (car-safe coding-systems)
7987                         coding-systems))))))
7988           (gnus-newsgroup-ignored-charsets 'gnus-all))
7989       (gnus-summary-select-article nil 'force)
7990       (let ((deps gnus-newsgroup-dependencies)
7991             head header lines)
7992         (save-excursion
7993           (set-buffer gnus-original-article-buffer)
7994           (save-restriction
7995             (message-narrow-to-head)
7996             (setq head (buffer-string))
7997             (goto-char (point-min))
7998             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
7999               (goto-char (point-max))
8000               (widen)
8001               (setq lines (1- (count-lines (point) (point-max))))))
8002           (with-temp-buffer
8003             (insert (format "211 %d Article retrieved.\n"
8004                             (cdr gnus-article-current)))
8005             (insert head)
8006             (if lines (insert (format "Lines: %d\n" lines)))
8007             (insert ".\n")
8008             (let ((nntp-server-buffer (current-buffer)))
8009               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8010         (gnus-data-set-header
8011          (gnus-data-find (cdr gnus-article-current))
8012          header)
8013         (gnus-summary-update-article-line
8014          (cdr gnus-article-current) header)
8015         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8016           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8017    ((not arg)
8018     ;; Select the article the normal way.
8019     (gnus-summary-select-article nil 'force))
8020    (t
8021     ;; We have to require this here to make sure that the following
8022     ;; dynamic binding isn't shadowed by autoloading.
8023     (require 'gnus-async)
8024     (require 'gnus-art)
8025     ;; Bind the article treatment functions to nil.
8026     (let ((gnus-have-all-headers t)
8027           gnus-article-prepare-hook
8028           gnus-article-decode-hook
8029           gnus-display-mime-function
8030           gnus-break-pages)
8031       ;; Destroy any MIME parts.
8032       (when (gnus-buffer-live-p gnus-article-buffer)
8033         (save-excursion
8034           (set-buffer gnus-article-buffer)
8035           (mm-destroy-parts gnus-article-mime-handles)
8036           ;; Set it to nil for safety reason.
8037           (setq gnus-article-mime-handle-alist nil)
8038           (setq gnus-article-mime-handles nil)))
8039       (gnus-summary-select-article nil 'force))))
8040   (gnus-summary-goto-subject gnus-current-article)
8041   (gnus-summary-position-point))
8042
8043 (defun gnus-summary-show-raw-article ()
8044   "Show the raw article without any article massaging functions being run."
8045   (interactive)
8046   (gnus-summary-show-article t))
8047
8048 (defun gnus-summary-verbose-headers (&optional arg)
8049   "Toggle permanent full header display.
8050 If ARG is a positive number, turn header display on.
8051 If ARG is a negative number, turn header display off."
8052   (interactive "P")
8053   (setq gnus-show-all-headers
8054         (cond ((or (not (numberp arg))
8055                    (zerop arg))
8056                (not gnus-show-all-headers))
8057               ((natnump arg)
8058                t)))
8059   (gnus-summary-show-article))
8060
8061 (defun gnus-summary-toggle-header (&optional arg)
8062   "Show the headers if they are hidden, or hide them if they are shown.
8063 If ARG is a positive number, show the entire header.
8064 If ARG is a negative number, hide the unwanted header lines."
8065   (interactive "P")
8066   (save-excursion
8067     (set-buffer gnus-article-buffer)
8068     (save-restriction
8069       (let* ((buffer-read-only nil)
8070              (inhibit-point-motion-hooks t)
8071              hidden e)
8072         (setq hidden
8073               (if (numberp arg)
8074                   (>= arg 0)
8075                 (save-restriction
8076                   (article-narrow-to-head)
8077                   (gnus-article-hidden-text-p 'headers))))
8078         (goto-char (point-min))
8079         (when (search-forward "\n\n" nil t)
8080           (delete-region (point-min) (1- (point))))
8081         (goto-char (point-min))
8082         (save-excursion
8083           (set-buffer gnus-original-article-buffer)
8084           (goto-char (point-min))
8085           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8086         (insert-buffer-substring gnus-original-article-buffer 1 e)
8087         (save-restriction
8088           (narrow-to-region (point-min) (point))
8089           (article-decode-encoded-words)
8090           (if  hidden
8091               (let ((gnus-treat-hide-headers nil)
8092                     (gnus-treat-hide-boring-headers nil))
8093                 (gnus-delete-wash-type 'headers)
8094                 (gnus-treat-article 'head))
8095             (gnus-treat-article 'head)))
8096         (gnus-set-mode-line 'article)))))
8097
8098 (defun gnus-summary-show-all-headers ()
8099   "Make all header lines visible."
8100   (interactive)
8101   (gnus-summary-toggle-header 1))
8102
8103 (defun gnus-summary-caesar-message (&optional arg)
8104   "Caesar rotate the current article by 13.
8105 The numerical prefix specifies how many places to rotate each letter
8106 forward."
8107   (interactive "P")
8108   (gnus-summary-select-article)
8109   (let ((mail-header-separator ""))
8110     (gnus-eval-in-buffer-window gnus-article-buffer
8111       (save-restriction
8112         (widen)
8113         (let ((start (window-start))
8114               buffer-read-only)
8115           (message-caesar-buffer-body arg)
8116           (set-window-start (get-buffer-window (current-buffer)) start))))))
8117
8118 (defun gnus-summary-stop-page-breaking ()
8119   "Stop page breaking in the current article."
8120   (interactive)
8121   (gnus-summary-select-article)
8122   (gnus-eval-in-buffer-window gnus-article-buffer
8123     (widen)
8124     (when (gnus-visual-p 'page-marker)
8125       (let ((buffer-read-only nil))
8126         (gnus-remove-text-with-property 'gnus-prev)
8127         (gnus-remove-text-with-property 'gnus-next))
8128       (setq gnus-page-broken nil))))
8129
8130 (defun gnus-summary-move-article (&optional n to-newsgroup
8131                                             select-method action)
8132   "Move the current article to a different newsgroup.
8133 If N is a positive number, move the N next articles.
8134 If N is a negative number, move the N previous articles.
8135 If N is nil and any articles have been marked with the process mark,
8136 move those articles instead.
8137 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8138 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8139 re-spool using this method.
8140
8141 For this function to work, both the current newsgroup and the
8142 newsgroup that you want to move to have to support the `request-move'
8143 and `request-accept' functions.
8144
8145 ACTION can be either `move' (the default), `crosspost' or `copy'."
8146   (interactive "P")
8147   (unless action
8148     (setq action 'move))
8149   ;; Check whether the source group supports the required functions.
8150   (cond ((and (eq action 'move)
8151               (not (gnus-check-backend-function
8152                     'request-move-article gnus-newsgroup-name)))
8153          (error "The current group does not support article moving"))
8154         ((and (eq action 'crosspost)
8155               (not (gnus-check-backend-function
8156                     'request-replace-article gnus-newsgroup-name)))
8157          (error "The current group does not support article editing")))
8158   (let ((articles (gnus-summary-work-articles n))
8159         (prefix (if (gnus-check-backend-function
8160                      'request-move-article gnus-newsgroup-name)
8161                     (gnus-group-real-prefix gnus-newsgroup-name)
8162                   ""))
8163         (names '((move "Move" "Moving")
8164                  (copy "Copy" "Copying")
8165                  (crosspost "Crosspost" "Crossposting")))
8166         (copy-buf (save-excursion
8167                     (nnheader-set-temp-buffer " *copy article*")))
8168         art-group to-method new-xref article to-groups)
8169     (unless (assq action names)
8170       (error "Unknown action %s" action))
8171     ;; We have to select an article to give
8172     ;; `gnus-read-move-group-name' an opportunity to suggest an
8173     ;; appropriate default.
8174     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8175       (gnus-summary-select-article nil nil nil (car articles)))
8176     ;; Read the newsgroup name.
8177     (when (and (not to-newsgroup)
8178                (not select-method))
8179       (setq to-newsgroup
8180             (gnus-read-move-group-name
8181              (cadr (assq action names))
8182              (symbol-value (intern (format "gnus-current-%s-group" action)))
8183              articles prefix))
8184       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8185     (setq to-method (or select-method
8186                         (gnus-server-to-method
8187                          (gnus-group-method to-newsgroup))))
8188     ;; Check the method we are to move this article to...
8189     (unless (gnus-check-backend-function
8190              'request-accept-article (car to-method))
8191       (error "%s does not support article copying" (car to-method)))
8192     (unless (gnus-check-server to-method)
8193       (error "Can't open server %s" (car to-method)))
8194     (gnus-message 6 "%s to %s: %s..."
8195                   (caddr (assq action names))
8196                   (or (car select-method) to-newsgroup) articles)
8197     (while articles
8198       (setq article (pop articles))
8199       (setq
8200        art-group
8201        (cond
8202         ;; Move the article.
8203         ((eq action 'move)
8204          ;; Remove this article from future suppression.
8205          (gnus-dup-unsuppress-article article)
8206          (gnus-request-move-article
8207           article                       ; Article to move
8208           gnus-newsgroup-name           ; From newsgroup
8209           (nth 1 (gnus-find-method-for-group
8210                   gnus-newsgroup-name)) ; Server
8211           (list 'gnus-request-accept-article
8212                 to-newsgroup (list 'quote select-method)
8213                 (not articles) t)       ; Accept form
8214           (not articles)))              ; Only save nov last time
8215         ;; Copy the article.
8216         ((eq action 'copy)
8217          (save-excursion
8218            (set-buffer copy-buf)
8219            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8220              (gnus-request-accept-article
8221               to-newsgroup select-method (not articles) t))))
8222         ;; Crosspost the article.
8223         ((eq action 'crosspost)
8224          (let ((xref (message-tokenize-header
8225                       (mail-header-xref (gnus-summary-article-header article))
8226                       " ")))
8227            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8228                                   ":" (number-to-string article)))
8229            (unless xref
8230              (setq xref (list (system-name))))
8231            (setq new-xref
8232                  (concat
8233                   (mapconcat 'identity
8234                              (delete "Xref:" (delete new-xref xref))
8235                              " ")
8236                   " " new-xref))
8237            (save-excursion
8238              (set-buffer copy-buf)
8239              ;; First put the article in the destination group.
8240              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8241              (when (consp (setq art-group
8242                                 (gnus-request-accept-article
8243                                  to-newsgroup select-method (not articles))))
8244                (setq new-xref (concat new-xref " " (car art-group)
8245                                       ":"
8246                                       (number-to-string (cdr art-group))))
8247                ;; Now we have the new Xrefs header, so we insert
8248                ;; it and replace the new article.
8249                (nnheader-replace-header "Xref" new-xref)
8250                (gnus-request-replace-article
8251                 (cdr art-group) to-newsgroup (current-buffer))
8252                art-group))))))
8253       (cond
8254        ((not art-group)
8255         (gnus-message 1 "Couldn't %s article %s: %s"
8256                       (cadr (assq action names)) article
8257                       (nnheader-get-report (car to-method))))
8258        ((eq art-group 'junk)
8259         (when (eq action 'move)
8260           (gnus-summary-mark-article article gnus-canceled-mark)
8261           (gnus-message 4 "Deleted article %s" article)))
8262        (t
8263         (let* ((pto-group (gnus-group-prefixed-name
8264                            (car art-group) to-method))
8265                (entry
8266                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8267                (info (nth 2 entry))
8268                (to-group (gnus-info-group info))
8269                to-marks)
8270           ;; Update the group that has been moved to.
8271           (when (and info
8272                      (memq action '(move copy)))
8273             (unless (member to-group to-groups)
8274               (push to-group to-groups))
8275
8276             (unless (memq article gnus-newsgroup-unreads)
8277               (push 'read to-marks)
8278               (gnus-info-set-read
8279                info (gnus-add-to-range (gnus-info-read info)
8280                                        (list (cdr art-group)))))
8281
8282             ;; See whether the article is to be put in the cache.
8283             (let ((marks gnus-article-mark-lists)
8284                   (to-article (cdr art-group)))
8285
8286               ;; Enter the article into the cache in the new group,
8287               ;; if that is required.
8288               (when gnus-use-cache
8289                 (gnus-cache-possibly-enter-article
8290                  to-group to-article
8291                  (memq article gnus-newsgroup-marked)
8292                  (memq article gnus-newsgroup-dormant)
8293                  (memq article gnus-newsgroup-unreads)))
8294
8295               (when gnus-preserve-marks
8296                 ;; Copy any marks over to the new group.
8297                 (when (and (equal to-group gnus-newsgroup-name)
8298                            (not (memq article gnus-newsgroup-unreads)))
8299                   ;; Mark this article as read in this group.
8300                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8301                   (setcdr (gnus-active to-group) to-article)
8302                   (setcdr gnus-newsgroup-active to-article))
8303
8304                 (while marks
8305                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8306                     (when (memq article (symbol-value
8307                                          (intern (format "gnus-newsgroup-%s"
8308                                                          (caar marks)))))
8309                       (push (cdar marks) to-marks)
8310                       ;; If the other group is the same as this group,
8311                       ;; then we have to add the mark to the list.
8312                       (when (equal to-group gnus-newsgroup-name)
8313                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8314                              (cons to-article
8315                                    (symbol-value
8316                                     (intern (format "gnus-newsgroup-%s"
8317                                                     (caar marks)))))))
8318                       ;; Copy the marks to other group.
8319                       (gnus-add-marked-articles
8320                        to-group (cdar marks) (list to-article) info)))
8321                   (setq marks (cdr marks)))
8322
8323                 (gnus-request-set-mark to-group (list (list (list to-article)
8324                                                             'add
8325                                                             to-marks))))
8326
8327               (gnus-dribble-enter
8328                (concat "(gnus-group-set-info '"
8329                        (gnus-prin1-to-string (gnus-get-info to-group))
8330                        ")"))))
8331
8332           ;; Update the Xref header in this article to point to
8333           ;; the new crossposted article we have just created.
8334           (when (eq action 'crosspost)
8335             (save-excursion
8336               (set-buffer copy-buf)
8337               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8338               (nnheader-replace-header "Xref" new-xref)
8339               (gnus-request-replace-article
8340                article gnus-newsgroup-name (current-buffer)))))
8341
8342         ;;;!!!Why is this necessary?
8343         (set-buffer gnus-summary-buffer)
8344
8345         (gnus-summary-goto-subject article)
8346         (when (eq action 'move)
8347           (gnus-summary-mark-article article gnus-canceled-mark))))
8348       (gnus-summary-remove-process-mark article))
8349     ;; Re-activate all groups that have been moved to.
8350     (save-excursion
8351       (set-buffer gnus-group-buffer)
8352       (let ((gnus-group-marked to-groups))
8353         (gnus-group-get-new-news-this-group nil t)))
8354
8355     (gnus-kill-buffer copy-buf)
8356     (gnus-summary-position-point)
8357     (gnus-set-mode-line 'summary)))
8358
8359 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8360   "Move the current article to a different newsgroup.
8361 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8362 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8363 re-spool using this method."
8364   (interactive "P")
8365   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8366
8367 (defun gnus-summary-crosspost-article (&optional n)
8368   "Crosspost the current article to some other group."
8369   (interactive "P")
8370   (gnus-summary-move-article n nil nil 'crosspost))
8371
8372 (defcustom gnus-summary-respool-default-method nil
8373   "Default method type for respooling an article.
8374 If nil, use to the current newsgroup method."
8375   :type 'symbol
8376   :group 'gnus-summary-mail)
8377
8378 (defun gnus-summary-respool-article (&optional n method)
8379   "Respool the current article.
8380 The article will be squeezed through the mail spooling process again,
8381 which means that it will be put in some mail newsgroup or other
8382 depending on `nnmail-split-methods'.
8383 If N is a positive number, respool the N next articles.
8384 If N is a negative number, respool the N previous articles.
8385 If N is nil and any articles have been marked with the process mark,
8386 respool those articles instead.
8387
8388 Respooling can be done both from mail groups and \"real\" newsgroups.
8389 In the former case, the articles in question will be moved from the
8390 current group into whatever groups they are destined to.  In the
8391 latter case, they will be copied into the relevant groups."
8392   (interactive
8393    (list current-prefix-arg
8394          (let* ((methods (gnus-methods-using 'respool))
8395                 (methname
8396                  (symbol-name (or gnus-summary-respool-default-method
8397                                   (car (gnus-find-method-for-group
8398                                         gnus-newsgroup-name)))))
8399                 (method
8400                  (gnus-completing-read
8401                   methname "What backend do you want to use when respooling?"
8402                   methods nil t nil 'gnus-mail-method-history))
8403                 ms)
8404            (cond
8405             ((zerop (length (setq ms (gnus-servers-using-backend
8406                                       (intern method)))))
8407              (list (intern method) ""))
8408             ((= 1 (length ms))
8409              (car ms))
8410             (t
8411              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8412                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8413                            ms-alist))))))))
8414   (unless method
8415     (error "No method given for respooling"))
8416   (if (assoc (symbol-name
8417               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8418              (gnus-methods-using 'respool))
8419       (gnus-summary-move-article n nil method)
8420     (gnus-summary-copy-article n nil method)))
8421
8422 (defun gnus-summary-import-article (file &optional edit)
8423   "Import an arbitrary file into a mail newsgroup."
8424   (interactive "fImport file: \nP")
8425   (let ((group gnus-newsgroup-name)
8426         (now (current-time))
8427         atts lines group-art)
8428     (unless (gnus-check-backend-function 'request-accept-article group)
8429       (error "%s does not support article importing" group))
8430     (or (file-readable-p file)
8431         (not (file-regular-p file))
8432         (error "Can't read %s" file))
8433     (save-excursion
8434       (set-buffer (gnus-get-buffer-create " *import file*"))
8435       (erase-buffer)
8436       (nnheader-insert-file-contents file)
8437       (goto-char (point-min))
8438       (if (nnheader-article-p)
8439           (save-restriction
8440             (goto-char (point-min))
8441             (search-forward "\n\n" nil t)
8442             (narrow-to-region (point-min) (1- (point)))
8443             (goto-char (point-min))
8444             (unless (re-search-forward "^date:" nil t)
8445               (goto-char (point-max))
8446               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8447        ;; This doesn't look like an article, so we fudge some headers.
8448         (setq atts (file-attributes file)
8449               lines (count-lines (point-min) (point-max)))
8450         (insert "From: " (read-string "From: ") "\n"
8451                 "Subject: " (read-string "Subject: ") "\n"
8452                 "Date: " (message-make-date (nth 5 atts)) "\n"
8453                 "Message-ID: " (message-make-message-id) "\n"
8454                 "Lines: " (int-to-string lines) "\n"
8455                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8456       (setq group-art (gnus-request-accept-article group nil t))
8457       (kill-buffer (current-buffer)))
8458     (setq gnus-newsgroup-active (gnus-activate-group group))
8459     (forward-line 1)
8460     (gnus-summary-goto-article (cdr group-art) nil t)
8461     (when edit
8462       (gnus-summary-edit-article))))
8463
8464 (defun gnus-summary-create-article ()
8465   "Create an article in a mail newsgroup."
8466   (interactive)
8467   (let ((group gnus-newsgroup-name)
8468         (now (current-time))
8469         group-art)
8470     (unless (gnus-check-backend-function 'request-accept-article group)
8471       (error "%s does not support article importing" group))
8472     (save-excursion
8473       (set-buffer (gnus-get-buffer-create " *import file*"))
8474       (erase-buffer)
8475       (goto-char (point-min))
8476       ;; This doesn't look like an article, so we fudge some headers.
8477       (insert "From: " (read-string "From: ") "\n"
8478               "Subject: " (read-string "Subject: ") "\n"
8479               "Date: " (message-make-date now) "\n"
8480               "Message-ID: " (message-make-message-id) "\n")
8481       (setq group-art (gnus-request-accept-article group nil t))
8482       (kill-buffer (current-buffer)))
8483     (setq gnus-newsgroup-active (gnus-activate-group group))
8484     (forward-line 1)
8485     (gnus-summary-goto-article (cdr group-art) nil t)
8486     (gnus-summary-edit-article)))
8487
8488 (defun gnus-summary-article-posted-p ()
8489   "Say whether the current (mail) article is available from news as well.
8490 This will be the case if the article has both been mailed and posted."
8491   (interactive)
8492   (let ((id (mail-header-references (gnus-summary-article-header)))
8493         (gnus-override-method (car (gnus-refer-article-methods))))
8494     (if (gnus-request-head id "")
8495         (gnus-message 2 "The current message was found on %s"
8496                       gnus-override-method)
8497       (gnus-message 2 "The current message couldn't be found on %s"
8498                     gnus-override-method)
8499       nil)))
8500
8501 (defun gnus-summary-expire-articles (&optional now)
8502   "Expire all articles that are marked as expirable in the current group."
8503   (interactive)
8504   (when (gnus-check-backend-function
8505          'request-expire-articles gnus-newsgroup-name)
8506     ;; This backend supports expiry.
8507     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8508            (expirable (if total
8509                           (progn
8510                             ;; We need to update the info for
8511                             ;; this group for `gnus-list-of-read-articles'
8512                             ;; to give us the right answer.
8513                             (gnus-run-hooks 'gnus-exit-group-hook)
8514                             (gnus-summary-update-info)
8515                             (gnus-list-of-read-articles gnus-newsgroup-name))
8516                         (setq gnus-newsgroup-expirable
8517                               (sort gnus-newsgroup-expirable '<))))
8518            (expiry-wait (if now 'immediate
8519                           (gnus-group-find-parameter
8520                            gnus-newsgroup-name 'expiry-wait)))
8521            (nnmail-expiry-target
8522             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8523                 nnmail-expiry-target))
8524            es)
8525       (when expirable
8526         ;; There are expirable articles in this group, so we run them
8527         ;; through the expiry process.
8528         (gnus-message 6 "Expiring articles...")
8529         (unless (gnus-check-group gnus-newsgroup-name)
8530           (error "Can't open server for %s" gnus-newsgroup-name))
8531         ;; The list of articles that weren't expired is returned.
8532         (save-excursion
8533           (if expiry-wait
8534               (let ((nnmail-expiry-wait-function nil)
8535                     (nnmail-expiry-wait expiry-wait))
8536                 (setq es (gnus-request-expire-articles
8537                           expirable gnus-newsgroup-name)))
8538             (setq es (gnus-request-expire-articles
8539                       expirable gnus-newsgroup-name)))
8540           (unless total
8541             (setq gnus-newsgroup-expirable es))
8542           ;; We go through the old list of expirable, and mark all
8543           ;; really expired articles as nonexistent.
8544           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8545             (let ((gnus-use-cache nil))
8546               (while expirable
8547                 (unless (memq (car expirable) es)
8548                   (when (gnus-data-find (car expirable))
8549                     (gnus-summary-mark-article
8550                      (car expirable) gnus-canceled-mark)))
8551                 (setq expirable (cdr expirable))))))
8552         (gnus-message 6 "Expiring articles...done")))))
8553
8554 (defun gnus-summary-expire-articles-now ()
8555   "Expunge all expirable articles in the current group.
8556 This means that *all* articles that are marked as expirable will be
8557 deleted forever, right now."
8558   (interactive)
8559   (or gnus-expert-user
8560       (gnus-yes-or-no-p
8561        "Are you really, really, really sure you want to delete all these messages? ")
8562       (error "Phew!"))
8563   (gnus-summary-expire-articles t))
8564
8565 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8566 (defun gnus-summary-delete-article (&optional n)
8567   "Delete the N next (mail) articles.
8568 This command actually deletes articles.  This is not a marking
8569 command.  The article will disappear forever from your life, never to
8570 return.
8571 If N is negative, delete backwards.
8572 If N is nil and articles have been marked with the process mark,
8573 delete these instead."
8574   (interactive "P")
8575   (unless (gnus-check-backend-function 'request-expire-articles
8576                                        gnus-newsgroup-name)
8577     (error "The current newsgroup does not support article deletion"))
8578   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8579     (error "Couldn't open server"))
8580   ;; Compute the list of articles to delete.
8581   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8582         not-deleted)
8583     (if (and gnus-novice-user
8584              (not (gnus-yes-or-no-p
8585                    (format "Do you really want to delete %s forever? "
8586                            (if (> (length articles) 1)
8587                                (format "these %s articles" (length articles))
8588                              "this article")))))
8589         ()
8590       ;; Delete the articles.
8591       (setq not-deleted (gnus-request-expire-articles
8592                          articles gnus-newsgroup-name 'force))
8593       (while articles
8594         (gnus-summary-remove-process-mark (car articles))
8595         ;; The backend might not have been able to delete the article
8596         ;; after all.
8597         (unless (memq (car articles) not-deleted)
8598           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8599         (setq articles (cdr articles)))
8600       (when not-deleted
8601         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8602     (gnus-summary-position-point)
8603     (gnus-set-mode-line 'summary)
8604     not-deleted))
8605
8606 (defun gnus-summary-edit-article (&optional arg)
8607   "Edit the current article.
8608 This will have permanent effect only in mail groups.
8609 If ARG is nil, edit the decoded articles.
8610 If ARG is 1, edit the raw articles.
8611 If ARG is 2, edit the raw articles even in read-only groups.
8612 If ARG is 3, edit the articles with the current handles.
8613 Otherwise, allow editing of articles even in read-only
8614 groups."
8615   (interactive "P")
8616   (let (force raw current-handles)
8617     (cond
8618      ((null arg))
8619      ((eq arg 1) (setq raw t))
8620      ((eq arg 2) (setq raw t
8621                        force t))
8622      ((eq arg 3) (setq current-handles
8623                        (and (gnus-buffer-live-p gnus-article-buffer)
8624                             (with-current-buffer gnus-article-buffer
8625                               (prog1
8626                                   gnus-article-mime-handles
8627                                 (setq gnus-article-mime-handles nil))))))
8628      (t (setq force t)))
8629     (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8630         (error "Can't edit the raw article in group nndraft:drafts"))
8631     (save-excursion
8632       (set-buffer gnus-summary-buffer)
8633       (let ((mail-parse-charset gnus-newsgroup-charset)
8634             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8635         (gnus-set-global-variables)
8636         (when (and (not force)
8637                    (gnus-group-read-only-p))
8638           (error "The current newsgroup does not support article editing"))
8639         (gnus-summary-show-article t)
8640         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8641           (with-current-buffer gnus-article-buffer
8642             (mm-enable-multibyte-mule4)))
8643         (if (equal gnus-newsgroup-name "nndraft:drafts")
8644             (setq raw t))
8645         (gnus-article-edit-article
8646          (if raw 'ignore
8647            `(lambda ()
8648               (let ((mbl mml-buffer-list))
8649                 (setq mml-buffer-list nil)
8650                 (mime-to-mml ,'current-handles)
8651                 (let ((mbl1 mml-buffer-list))
8652                   (setq mml-buffer-list mbl)
8653                   (set (make-local-variable 'mml-buffer-list) mbl1))
8654                 (make-local-hook 'kill-buffer-hook)
8655                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8656          `(lambda (no-highlight)
8657             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8658                   (message-options message-options)
8659                   (message-options-set-recipient)
8660                   (mail-parse-ignored-charsets
8661                    ',gnus-newsgroup-ignored-charsets))
8662               ,(if (not raw) '(progn
8663                                 (mml-to-mime)
8664                                 (mml-destroy-buffers)
8665                                 (remove-hook 'kill-buffer-hook
8666                                              'mml-destroy-buffers t)
8667                                 (kill-local-variable 'mml-buffer-list)))
8668               (gnus-summary-edit-article-done
8669                ,(or (mail-header-references gnus-current-headers) "")
8670                ,(gnus-group-read-only-p)
8671                ,gnus-summary-buffer no-highlight))))))))
8672
8673 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8674
8675 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8676                                                  no-highlight)
8677   "Make edits to the current article permanent."
8678   (interactive)
8679   (save-excursion
8680    ;; The buffer restriction contains the entire article if it exists.
8681     (when (article-goto-body)
8682       (let ((lines (count-lines (point) (point-max)))
8683             (length (- (point-max) (point)))
8684             (case-fold-search t)
8685             (body (copy-marker (point))))
8686         (goto-char (point-min))
8687         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8688           (delete-region (match-beginning 1) (match-end 1))
8689           (insert (number-to-string length)))
8690         (goto-char (point-min))
8691         (when (re-search-forward
8692                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8693           (delete-region (match-beginning 1) (match-end 1))
8694           (insert (number-to-string length)))
8695         (goto-char (point-min))
8696         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8697           (delete-region (match-beginning 1) (match-end 1))
8698           (insert (number-to-string lines))))))
8699   ;; Replace the article.
8700   (let ((buf (current-buffer)))
8701     (with-temp-buffer
8702       (insert-buffer-substring buf)
8703
8704       (if (and (not read-only)
8705                (not (gnus-request-replace-article
8706                      (cdr gnus-article-current) (car gnus-article-current)
8707                      (current-buffer) t)))
8708           (error "Couldn't replace article")
8709         ;; Update the summary buffer.
8710         (if (and references
8711                  (equal (message-tokenize-header references " ")
8712                         (message-tokenize-header
8713                          (or (message-fetch-field "references") "") " ")))
8714             ;; We only have to update this line.
8715             (save-excursion
8716               (save-restriction
8717                 (message-narrow-to-head)
8718                 (let ((head (buffer-string))
8719                       header)
8720                   (with-temp-buffer
8721                     (insert (format "211 %d Article retrieved.\n"
8722                                     (cdr gnus-article-current)))
8723                     (insert head)
8724                     (insert ".\n")
8725                     (let ((nntp-server-buffer (current-buffer)))
8726                       (setq header (car (gnus-get-newsgroup-headers
8727                                          (save-excursion
8728                                            (set-buffer gnus-summary-buffer)
8729                                            gnus-newsgroup-dependencies)
8730                                          t))))
8731                     (save-excursion
8732                       (set-buffer gnus-summary-buffer)
8733                       (gnus-data-set-header
8734                        (gnus-data-find (cdr gnus-article-current))
8735                        header)
8736                       (gnus-summary-update-article-line
8737                        (cdr gnus-article-current) header)
8738                       (if (gnus-summary-goto-subject
8739                            (cdr gnus-article-current) nil t)
8740                           (gnus-summary-update-secondary-mark
8741                            (cdr gnus-article-current))))))))
8742           ;; Update threads.
8743           (set-buffer (or buffer gnus-summary-buffer))
8744           (gnus-summary-update-article (cdr gnus-article-current))
8745           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8746               (gnus-summary-update-secondary-mark
8747                (cdr gnus-article-current))))
8748         ;; Prettify the article buffer again.
8749         (unless no-highlight
8750           (save-excursion
8751             (set-buffer gnus-article-buffer)
8752             ;;;!!! Fix this -- article should be rehighlighted.
8753             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8754             (set-buffer gnus-original-article-buffer)
8755             (gnus-request-article
8756              (cdr gnus-article-current)
8757              (car gnus-article-current) (current-buffer))))
8758         ;; Prettify the summary buffer line.
8759         (when (gnus-visual-p 'summary-highlight 'highlight)
8760           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8761
8762 (defun gnus-summary-edit-wash (key)
8763   "Perform editing command KEY in the article buffer."
8764   (interactive
8765    (list
8766     (progn
8767       (message "%s" (concat (this-command-keys) "- "))
8768       (read-char))))
8769   (message "")
8770   (gnus-summary-edit-article)
8771   (execute-kbd-macro (concat (this-command-keys) key))
8772   (gnus-article-edit-done))
8773
8774 ;;; Respooling
8775
8776 (defun gnus-summary-respool-query (&optional silent trace)
8777   "Query where the respool algorithm would put this article."
8778   (interactive)
8779   (let (gnus-mark-article-hook)
8780     (gnus-summary-select-article)
8781     (save-excursion
8782       (set-buffer gnus-original-article-buffer)
8783       (save-restriction
8784         (message-narrow-to-head)
8785         (let ((groups (nnmail-article-group 'identity trace)))
8786           (unless silent
8787             (if groups
8788                 (message "This message would go to %s"
8789                          (mapconcat 'car groups ", "))
8790               (message "This message would go to no groups"))
8791             groups))))))
8792
8793 (defun gnus-summary-respool-trace ()
8794   "Trace where the respool algorithm would put this article.
8795 Display a buffer showing all fancy splitting patterns which matched."
8796   (interactive)
8797   (gnus-summary-respool-query nil t))
8798
8799 ;; Summary marking commands.
8800
8801 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8802   "Mark articles which has the same subject as read, and then select the next.
8803 If UNMARK is positive, remove any kind of mark.
8804 If UNMARK is negative, tick articles."
8805   (interactive "P")
8806   (when unmark
8807     (setq unmark (prefix-numeric-value unmark)))
8808   (let ((count
8809          (gnus-summary-mark-same-subject
8810           (gnus-summary-article-subject) unmark)))
8811     ;; Select next unread article.  If auto-select-same mode, should
8812     ;; select the first unread article.
8813     (gnus-summary-next-article t (and gnus-auto-select-same
8814                                       (gnus-summary-article-subject)))
8815     (gnus-message 7 "%d article%s marked as %s"
8816                   count (if (= count 1) " is" "s are")
8817                   (if unmark "unread" "read"))))
8818
8819 (defun gnus-summary-kill-same-subject (&optional unmark)
8820   "Mark articles which has the same subject as read.
8821 If UNMARK is positive, remove any kind of mark.
8822 If UNMARK is negative, tick articles."
8823   (interactive "P")
8824   (when unmark
8825     (setq unmark (prefix-numeric-value unmark)))
8826   (let ((count
8827          (gnus-summary-mark-same-subject
8828           (gnus-summary-article-subject) unmark)))
8829     ;; If marked as read, go to next unread subject.
8830     (when (null unmark)
8831       ;; Go to next unread subject.
8832       (gnus-summary-next-subject 1 t))
8833     (gnus-message 7 "%d articles are marked as %s"
8834                   count (if unmark "unread" "read"))))
8835
8836 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8837   "Mark articles with same SUBJECT as read, and return marked number.
8838 If optional argument UNMARK is positive, remove any kinds of marks.
8839 If optional argument UNMARK is negative, mark articles as unread instead."
8840   (let ((count 1))
8841     (save-excursion
8842       (cond
8843        ((null unmark)                   ; Mark as read.
8844         (while (and
8845                 (progn
8846                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8847                   (gnus-summary-show-thread) t)
8848                 (gnus-summary-find-subject subject))
8849           (setq count (1+ count))))
8850        ((> unmark 0)                    ; Tick.
8851         (while (and
8852                 (progn
8853                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8854                   (gnus-summary-show-thread) t)
8855                 (gnus-summary-find-subject subject))
8856           (setq count (1+ count))))
8857        (t                               ; Mark as unread.
8858         (while (and
8859                 (progn
8860                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8861                   (gnus-summary-show-thread) t)
8862                 (gnus-summary-find-subject subject))
8863           (setq count (1+ count)))))
8864       (gnus-set-mode-line 'summary)
8865       ;; Return the number of marked articles.
8866       count)))
8867
8868 (defun gnus-summary-mark-as-processable (n &optional unmark)
8869   "Set the process mark on the next N articles.
8870 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8871 the process mark instead.  The difference between N and the actual
8872 number of articles marked is returned."
8873   (interactive "P")
8874   (if (and (null n) (gnus-region-active-p))
8875       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8876     (setq n (prefix-numeric-value n))
8877     (let ((backward (< n 0))
8878           (n (abs n)))
8879       (while (and
8880               (> n 0)
8881               (if unmark
8882                   (gnus-summary-remove-process-mark
8883                    (gnus-summary-article-number))
8884                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8885               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8886         (setq n (1- n)))
8887       (when (/= 0 n)
8888         (gnus-message 7 "No more articles"))
8889       (gnus-summary-recenter)
8890       (gnus-summary-position-point)
8891       n)))
8892
8893 (defun gnus-summary-unmark-as-processable (n)
8894   "Remove the process mark from the next N articles.
8895 If N is negative, unmark backward instead.  The difference between N and
8896 the actual number of articles unmarked is returned."
8897   (interactive "P")
8898   (gnus-summary-mark-as-processable n t))
8899
8900 (defun gnus-summary-unmark-all-processable ()
8901   "Remove the process mark from all articles."
8902   (interactive)
8903   (save-excursion
8904     (while gnus-newsgroup-processable
8905       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8906   (gnus-summary-position-point))
8907
8908 (defun gnus-summary-add-mark (article type)
8909   "Mark ARTICLE with a mark of TYPE."
8910   (let ((vtype (car (assq type gnus-article-mark-lists)))
8911         var)
8912     (if (not vtype)
8913         (error "No such mark type: %s" type)
8914       (setq var (intern (format "gnus-newsgroup-%s" type)))
8915       (set var (cons article (symbol-value var)))
8916       (if (memq type '(processable cached replied forwarded recent saved))
8917           (gnus-summary-update-secondary-mark article)
8918         ;;; !!! This is bogus.  We should find out what primary
8919         ;;; !!! mark we want to set.
8920         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8921
8922 (defun gnus-summary-mark-as-expirable (n)
8923   "Mark N articles forward as expirable.
8924 If N is negative, mark backward instead.  The difference between N and
8925 the actual number of articles marked is returned."
8926   (interactive "p")
8927   (gnus-summary-mark-forward n gnus-expirable-mark))
8928
8929 (defun gnus-summary-mark-article-as-replied (article)
8930   "Mark ARTICLE as replied to and update the summary line.
8931 ARTICLE can also be a list of articles."
8932   (interactive (list (gnus-summary-article-number)))
8933   (let ((articles (if (listp article) article (list article))))
8934     (dolist (article articles)
8935       (push article gnus-newsgroup-replied)
8936       (let ((buffer-read-only nil))
8937         (when (gnus-summary-goto-subject article nil t)
8938           (gnus-summary-update-secondary-mark article))))))
8939
8940 (defun gnus-summary-mark-article-as-forwarded (article)
8941   "Mark ARTICLE as forwarded and update the summary line.
8942 ARTICLE can also be a list of articles."
8943   (let ((articles (if (listp article) article (list article))))
8944     (dolist (article articles)
8945       (push article gnus-newsgroup-forwarded)
8946       (let ((buffer-read-only nil))
8947         (when (gnus-summary-goto-subject article nil t)
8948           (gnus-summary-update-secondary-mark article))))))
8949
8950 (defun gnus-summary-set-bookmark (article)
8951   "Set a bookmark in current article."
8952   (interactive (list (gnus-summary-article-number)))
8953   (when (or (not (get-buffer gnus-article-buffer))
8954             (not gnus-current-article)
8955             (not gnus-article-current)
8956             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8957     (error "No current article selected"))
8958   ;; Remove old bookmark, if one exists.
8959   (let ((old (assq article gnus-newsgroup-bookmarks)))
8960     (when old
8961       (setq gnus-newsgroup-bookmarks
8962             (delq old gnus-newsgroup-bookmarks))))
8963   ;; Set the new bookmark, which is on the form
8964   ;; (article-number . line-number-in-body).
8965   (push
8966    (cons article
8967          (save-excursion
8968            (set-buffer gnus-article-buffer)
8969            (count-lines
8970             (min (point)
8971                  (save-excursion
8972                    (goto-char (point-min))
8973                    (search-forward "\n\n" nil t)
8974                    (point)))
8975             (point))))
8976    gnus-newsgroup-bookmarks)
8977   (gnus-message 6 "A bookmark has been added to the current article."))
8978
8979 (defun gnus-summary-remove-bookmark (article)
8980   "Remove the bookmark from the current article."
8981   (interactive (list (gnus-summary-article-number)))
8982   ;; Remove old bookmark, if one exists.
8983   (let ((old (assq article gnus-newsgroup-bookmarks)))
8984     (if old
8985         (progn
8986           (setq gnus-newsgroup-bookmarks
8987                 (delq old gnus-newsgroup-bookmarks))
8988           (gnus-message 6 "Removed bookmark."))
8989       (gnus-message 6 "No bookmark in current article."))))
8990
8991 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8992 (defun gnus-summary-mark-as-dormant (n)
8993   "Mark N articles forward as dormant.
8994 If N is negative, mark backward instead.  The difference between N and
8995 the actual number of articles marked is returned."
8996   (interactive "p")
8997   (gnus-summary-mark-forward n gnus-dormant-mark))
8998
8999 (defun gnus-summary-set-process-mark (article)
9000   "Set the process mark on ARTICLE and update the summary line."
9001   (setq gnus-newsgroup-processable
9002         (cons article
9003               (delq article gnus-newsgroup-processable)))
9004   (when (gnus-summary-goto-subject article)
9005     (gnus-summary-show-thread)
9006     (gnus-summary-goto-subject article)
9007     (gnus-summary-update-secondary-mark article)))
9008
9009 (defun gnus-summary-remove-process-mark (article)
9010   "Remove the process mark from ARTICLE and update the summary line."
9011   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9012   (when (gnus-summary-goto-subject article)
9013     (gnus-summary-show-thread)
9014     (gnus-summary-goto-subject article)
9015     (gnus-summary-update-secondary-mark article)))
9016
9017 (defun gnus-summary-set-saved-mark (article)
9018   "Set the process mark on ARTICLE and update the summary line."
9019   (push article gnus-newsgroup-saved)
9020   (when (gnus-summary-goto-subject article)
9021     (gnus-summary-update-secondary-mark article)))
9022
9023 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9024   "Mark N articles as read forwards.
9025 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9026 The difference between N and the actual number of articles marked is
9027 returned.
9028 Iff NO-EXPIRE, auto-expiry will be inhibited."
9029   (interactive "p")
9030   (gnus-summary-show-thread)
9031   (let ((backward (< n 0))
9032         (gnus-summary-goto-unread
9033          (and gnus-summary-goto-unread
9034               (not (eq gnus-summary-goto-unread 'never))
9035               (not (memq mark (list gnus-unread-mark
9036                                     gnus-ticked-mark gnus-dormant-mark)))))
9037         (n (abs n))
9038         (mark (or mark gnus-del-mark)))
9039     (while (and (> n 0)
9040                 (gnus-summary-mark-article nil mark no-expire)
9041                 (zerop (gnus-summary-next-subject
9042                         (if backward -1 1)
9043                         (and gnus-summary-goto-unread
9044                              (not (eq gnus-summary-goto-unread 'never)))
9045                         t)))
9046       (setq n (1- n)))
9047     (when (/= 0 n)
9048       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9049     (gnus-summary-recenter)
9050     (gnus-summary-position-point)
9051     (gnus-set-mode-line 'summary)
9052     n))
9053
9054 (defun gnus-summary-mark-article-as-read (mark)
9055   "Mark the current article quickly as read with MARK."
9056   (let ((article (gnus-summary-article-number)))
9057     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9058     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9059     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9060     (push (cons article mark) gnus-newsgroup-reads)
9061     ;; Possibly remove from cache, if that is used.
9062     (when gnus-use-cache
9063       (gnus-cache-enter-remove-article article))
9064     ;; Allow the backend to change the mark.
9065     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9066     ;; Check for auto-expiry.
9067     (when (and gnus-newsgroup-auto-expire
9068                (memq mark gnus-auto-expirable-marks))
9069       (setq mark gnus-expirable-mark)
9070       ;; Let the backend know about the mark change.
9071       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9072       (push article gnus-newsgroup-expirable))
9073     ;; Set the mark in the buffer.
9074     (gnus-summary-update-mark mark 'unread)
9075     t))
9076
9077 (defun gnus-summary-mark-article-as-unread (mark)
9078   "Mark the current article quickly as unread with MARK."
9079   (let* ((article (gnus-summary-article-number))
9080          (old-mark (gnus-summary-article-mark article)))
9081     ;; Allow the backend to change the mark.
9082     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9083     (if (eq mark old-mark)
9084         t
9085       (if (<= article 0)
9086           (progn
9087             (gnus-error 1 "Can't mark negative article numbers")
9088             nil)
9089         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9090         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9091         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9092         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9093         (cond ((= mark gnus-ticked-mark)
9094                (push article gnus-newsgroup-marked))
9095               ((= mark gnus-dormant-mark)
9096                (push article gnus-newsgroup-dormant))
9097               (t
9098                (push article gnus-newsgroup-unreads)))
9099         (gnus-pull article gnus-newsgroup-reads)
9100
9101         ;; See whether the article is to be put in the cache.
9102         (and gnus-use-cache
9103              (vectorp (gnus-summary-article-header article))
9104              (save-excursion
9105                (gnus-cache-possibly-enter-article
9106                 gnus-newsgroup-name article
9107                 (= mark gnus-ticked-mark)
9108                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9109
9110         ;; Fix the mark.
9111         (gnus-summary-update-mark mark 'unread)
9112         t))))
9113
9114 (defun gnus-summary-mark-article (&optional article mark no-expire)
9115   "Mark ARTICLE with MARK.  MARK can be any character.
9116 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9117 `??' (dormant) and `?E' (expirable).
9118 If MARK is nil, then the default character `?r' is used.
9119 If ARTICLE is nil, then the article on the current line will be
9120 marked.
9121 Iff NO-EXPIRE, auto-expiry will be inhibited."
9122   ;; The mark might be a string.
9123   (when (stringp mark)
9124     (setq mark (aref mark 0)))
9125   ;; If no mark is given, then we check auto-expiring.
9126   (when (null mark)
9127     (setq mark gnus-del-mark))
9128   (when (and (not no-expire)
9129              gnus-newsgroup-auto-expire
9130              (memq mark gnus-auto-expirable-marks))
9131     (setq mark gnus-expirable-mark))
9132   (let ((article (or article (gnus-summary-article-number)))
9133         (old-mark (gnus-summary-article-mark article)))
9134     ;; Allow the backend to change the mark.
9135     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9136     (if (eq mark old-mark)
9137         t
9138       (unless article
9139         (error "No article on current line"))
9140       (if (not (if (or (= mark gnus-unread-mark)
9141                        (= mark gnus-ticked-mark)
9142                        (= mark gnus-dormant-mark))
9143                    (gnus-mark-article-as-unread article mark)
9144                  (gnus-mark-article-as-read article mark)))
9145           t
9146         ;; See whether the article is to be put in the cache.
9147         (and gnus-use-cache
9148              (not (= mark gnus-canceled-mark))
9149              (vectorp (gnus-summary-article-header article))
9150              (save-excursion
9151                (gnus-cache-possibly-enter-article
9152                 gnus-newsgroup-name article
9153                 (= mark gnus-ticked-mark)
9154                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9155
9156         (when (gnus-summary-goto-subject article nil t)
9157           (let ((buffer-read-only nil))
9158             (gnus-summary-show-thread)
9159             ;; Fix the mark.
9160             (gnus-summary-update-mark mark 'unread)
9161             t))))))
9162
9163 (defun gnus-summary-update-secondary-mark (article)
9164   "Update the secondary (read, process, cache) mark."
9165   (gnus-summary-update-mark
9166    (cond ((memq article gnus-newsgroup-processable)
9167           gnus-process-mark)
9168          ((memq article gnus-newsgroup-cached)
9169           gnus-cached-mark)
9170          ((memq article gnus-newsgroup-replied)
9171           gnus-replied-mark)
9172          ((memq article gnus-newsgroup-forwarded)
9173           gnus-forwarded-mark)
9174          ((memq article gnus-newsgroup-saved)
9175           gnus-saved-mark)
9176          ((memq article gnus-newsgroup-recent)
9177           gnus-recent-mark)
9178          ((memq article gnus-newsgroup-unseen)
9179           gnus-unseen-mark)
9180          (t gnus-no-mark))
9181    'replied)
9182   (when (gnus-visual-p 'summary-highlight 'highlight)
9183     (gnus-run-hooks 'gnus-summary-update-hook))
9184   t)
9185
9186 (defun gnus-summary-update-mark (mark type)
9187   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9188         (buffer-read-only nil))
9189     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9190     (when forward
9191       (when (looking-at "\r")
9192         (incf forward))
9193       (when (<= (+ forward (point)) (point-max))
9194         ;; Go to the right position on the line.
9195         (goto-char (+ forward (point)))
9196         ;; Replace the old mark with the new mark.
9197         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9198         ;; Optionally update the marks by some user rule.
9199         (when (eq type 'unread)
9200           (gnus-data-set-mark
9201            (gnus-data-find (gnus-summary-article-number)) mark)
9202           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9203
9204 (defun gnus-mark-article-as-read (article &optional mark)
9205   "Enter ARTICLE in the pertinent lists and remove it from others."
9206   ;; Make the article expirable.
9207   (let ((mark (or mark gnus-del-mark)))
9208     (if (= mark gnus-expirable-mark)
9209         (push article gnus-newsgroup-expirable)
9210       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9211     ;; Remove from unread and marked lists.
9212     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9213     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9214     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9215     (push (cons article mark) gnus-newsgroup-reads)
9216     ;; Possibly remove from cache, if that is used.
9217     (when gnus-use-cache
9218       (gnus-cache-enter-remove-article article))
9219     t))
9220
9221 (defun gnus-mark-article-as-unread (article &optional mark)
9222   "Enter ARTICLE in the pertinent lists and remove it from others."
9223   (let ((mark (or mark gnus-ticked-mark)))
9224     (if (<= article 0)
9225         (progn
9226           (gnus-error 1 "Can't mark negative article numbers")
9227           nil)
9228       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9229             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9230             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9231             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9232
9233       ;; Unsuppress duplicates?
9234       (when gnus-suppress-duplicates
9235         (gnus-dup-unsuppress-article article))
9236
9237       (cond ((= mark gnus-ticked-mark)
9238              (push article gnus-newsgroup-marked))
9239             ((= mark gnus-dormant-mark)
9240              (push article gnus-newsgroup-dormant))
9241             (t
9242              (push article gnus-newsgroup-unreads)))
9243       (gnus-pull article gnus-newsgroup-reads)
9244       t)))
9245
9246 (defalias 'gnus-summary-mark-as-unread-forward
9247   'gnus-summary-tick-article-forward)
9248 (make-obsolete 'gnus-summary-mark-as-unread-forward
9249                'gnus-summary-tick-article-forward)
9250 (defun gnus-summary-tick-article-forward (n)
9251   "Tick N articles forwards.
9252 If N is negative, tick backwards instead.
9253 The difference between N and the number of articles ticked is returned."
9254   (interactive "p")
9255   (gnus-summary-mark-forward n gnus-ticked-mark))
9256
9257 (defalias 'gnus-summary-mark-as-unread-backward
9258   'gnus-summary-tick-article-backward)
9259 (make-obsolete 'gnus-summary-mark-as-unread-backward
9260                'gnus-summary-tick-article-backward)
9261 (defun gnus-summary-tick-article-backward (n)
9262   "Tick N articles backwards.
9263 The difference between N and the number of articles ticked is returned."
9264   (interactive "p")
9265   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9266
9267 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9268 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9269 (defun gnus-summary-tick-article (&optional article clear-mark)
9270   "Mark current article as unread.
9271 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9272 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9273   (interactive)
9274   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9275                                        gnus-ticked-mark)))
9276
9277 (defun gnus-summary-mark-as-read-forward (n)
9278   "Mark N articles as read forwards.
9279 If N is negative, mark backwards instead.
9280 The difference between N and the actual number of articles marked is
9281 returned."
9282   (interactive "p")
9283   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9284
9285 (defun gnus-summary-mark-as-read-backward (n)
9286   "Mark the N articles as read backwards.
9287 The difference between N and the actual number of articles marked is
9288 returned."
9289   (interactive "p")
9290   (gnus-summary-mark-forward
9291    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9292
9293 (defun gnus-summary-mark-as-read (&optional article mark)
9294   "Mark current article as read.
9295 ARTICLE specifies the article to be marked as read.
9296 MARK specifies a string to be inserted at the beginning of the line."
9297   (gnus-summary-mark-article article mark))
9298
9299 (defun gnus-summary-clear-mark-forward (n)
9300   "Clear marks from N articles forward.
9301 If N is negative, clear backward instead.
9302 The difference between N and the number of marks cleared is returned."
9303   (interactive "p")
9304   (gnus-summary-mark-forward n gnus-unread-mark))
9305
9306 (defun gnus-summary-clear-mark-backward (n)
9307   "Clear marks from N articles backward.
9308 The difference between N and the number of marks cleared is returned."
9309   (interactive "p")
9310   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9311
9312 (defun gnus-summary-mark-unread-as-read ()
9313   "Intended to be used by `gnus-summary-mark-article-hook'."
9314   (when (memq gnus-current-article gnus-newsgroup-unreads)
9315     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9316
9317 (defun gnus-summary-mark-read-and-unread-as-read ()
9318   "Intended to be used by `gnus-summary-mark-article-hook'."
9319   (let ((mark (gnus-summary-article-mark)))
9320     (when (or (gnus-unread-mark-p mark)
9321               (gnus-read-mark-p mark))
9322       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9323
9324 (defun gnus-summary-mark-unread-as-ticked ()
9325   "Intended to be used by `gnus-summary-mark-article-hook'."
9326   (when (memq gnus-current-article gnus-newsgroup-unreads)
9327     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9328
9329 (defun gnus-summary-mark-region-as-read (point mark all)
9330   "Mark all unread articles between point and mark as read.
9331 If given a prefix, mark all articles between point and mark as read,
9332 even ticked and dormant ones."
9333   (interactive "r\nP")
9334   (save-excursion
9335     (let (article)
9336       (goto-char point)
9337       (beginning-of-line)
9338       (while (and
9339               (< (point) mark)
9340               (progn
9341                 (when (or all
9342                           (memq (setq article (gnus-summary-article-number))
9343                                 gnus-newsgroup-unreads))
9344                   (gnus-summary-mark-article article gnus-del-mark))
9345                 t)
9346               (gnus-summary-find-next))))))
9347
9348 (defun gnus-summary-mark-below (score mark)
9349   "Mark articles with score less than SCORE with MARK."
9350   (interactive "P\ncMark: ")
9351   (setq score (if score
9352                   (prefix-numeric-value score)
9353                 (or gnus-summary-default-score 0)))
9354   (save-excursion
9355     (set-buffer gnus-summary-buffer)
9356     (goto-char (point-min))
9357     (while
9358         (progn
9359           (and (< (gnus-summary-article-score) score)
9360                (gnus-summary-mark-article nil mark))
9361           (gnus-summary-find-next)))))
9362
9363 (defun gnus-summary-kill-below (&optional score)
9364   "Mark articles with score below SCORE as read."
9365   (interactive "P")
9366   (gnus-summary-mark-below score gnus-killed-mark))
9367
9368 (defun gnus-summary-clear-above (&optional score)
9369   "Clear all marks from articles with score above SCORE."
9370   (interactive "P")
9371   (gnus-summary-mark-above score gnus-unread-mark))
9372
9373 (defun gnus-summary-tick-above (&optional score)
9374   "Tick all articles with score above SCORE."
9375   (interactive "P")
9376   (gnus-summary-mark-above score gnus-ticked-mark))
9377
9378 (defun gnus-summary-mark-above (score mark)
9379   "Mark articles with score over SCORE with MARK."
9380   (interactive "P\ncMark: ")
9381   (setq score (if score
9382                   (prefix-numeric-value score)
9383                 (or gnus-summary-default-score 0)))
9384   (save-excursion
9385     (set-buffer gnus-summary-buffer)
9386     (goto-char (point-min))
9387     (while (and (progn
9388                   (when (> (gnus-summary-article-score) score)
9389                     (gnus-summary-mark-article nil mark))
9390                   t)
9391                 (gnus-summary-find-next)))))
9392
9393 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9394 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9395 (defun gnus-summary-limit-include-expunged (&optional no-error)
9396   "Display all the hidden articles that were expunged for low scores."
9397   (interactive)
9398   (let ((buffer-read-only nil))
9399     (let ((scored gnus-newsgroup-scored)
9400           headers h)
9401       (while scored
9402         (unless (gnus-summary-article-header (caar scored))
9403           (and (setq h (gnus-number-to-header (caar scored)))
9404                (< (cdar scored) gnus-summary-expunge-below)
9405                (push h headers)))
9406         (setq scored (cdr scored)))
9407       (if (not headers)
9408           (when (not no-error)
9409             (error "No expunged articles hidden"))
9410         (goto-char (point-min))
9411         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9412         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9413         (mapcar (lambda (x) (push (mail-header-number x)
9414                                   gnus-newsgroup-limit))
9415                 headers)
9416         (gnus-summary-prepare-unthreaded (nreverse headers))
9417         (goto-char (point-min))
9418         (gnus-summary-position-point)
9419         t))))
9420
9421 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9422   "Mark all unread articles in this newsgroup as read.
9423 If prefix argument ALL is non-nil, ticked and dormant articles will
9424 also be marked as read.
9425 If QUIETLY is non-nil, no questions will be asked.
9426 If TO-HERE is non-nil, it should be a point in the buffer.  All
9427 articles before (after, if REVERSE is set) this point will be marked as read.
9428 Note that this function will only catch up the unread article
9429 in the current summary buffer limitation.
9430 The number of articles marked as read is returned."
9431   (interactive "P")
9432   (prog1
9433       (save-excursion
9434         (when (or quietly
9435                   (not gnus-interactive-catchup) ;Without confirmation?
9436                   gnus-expert-user
9437                   (gnus-y-or-n-p
9438                    (if all
9439                        "Mark absolutely all articles as read? "
9440                      "Mark all unread articles as read? ")))
9441           (if (and not-mark
9442                    (not gnus-newsgroup-adaptive)
9443                    (not gnus-newsgroup-auto-expire)
9444                    (not gnus-suppress-duplicates)
9445                    (or (not gnus-use-cache)
9446                        (eq gnus-use-cache 'passive)))
9447               (progn
9448                 (when all
9449                   (setq gnus-newsgroup-marked nil
9450                         gnus-newsgroup-dormant nil))
9451                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9452             ;; We actually mark all articles as canceled, which we
9453             ;; have to do when using auto-expiry or adaptive scoring.
9454             (gnus-summary-show-all-threads)
9455             (if (and to-here reverse)
9456                 (progn
9457                   (goto-char to-here)
9458                   (while (and
9459                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9460                           (gnus-summary-find-next (not all) nil nil t))))
9461               (when (gnus-summary-first-subject (not all) t)
9462                 (while (and
9463                         (if to-here (< (point) to-here) t)
9464                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9465                         (gnus-summary-find-next (not all) nil nil t)))))
9466             (gnus-set-mode-line 'summary))
9467           t))
9468     (gnus-summary-position-point)))
9469
9470 (defun gnus-summary-catchup-to-here (&optional all)
9471   "Mark all unticked articles before the current one as read.
9472 If ALL is non-nil, also mark ticked and dormant articles as read."
9473   (interactive "P")
9474   (save-excursion
9475     (gnus-save-hidden-threads
9476       (let ((beg (point)))
9477         ;; We check that there are unread articles.
9478         (when (or all (gnus-summary-find-prev))
9479           (gnus-summary-catchup all t beg)))))
9480   (gnus-summary-position-point))
9481
9482 (defun gnus-summary-catchup-from-here (&optional all)
9483   "Mark all unticked articles after the current one as read.
9484 If ALL is non-nil, also mark ticked and dormant articles as read."
9485   (interactive "P")
9486   (save-excursion
9487     (gnus-save-hidden-threads
9488       (let ((beg (point)))
9489         ;; We check that there are unread articles.
9490         (when (or all (gnus-summary-find-next))
9491           (gnus-summary-catchup all t beg nil t)))))
9492
9493   (gnus-summary-position-point))
9494 (defun gnus-summary-catchup-all (&optional quietly)
9495   "Mark all articles in this newsgroup as read."
9496   (interactive "P")
9497   (gnus-summary-catchup t quietly))
9498
9499 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9500   "Mark all unread articles in this group as read, then exit.
9501 If prefix argument ALL is non-nil, all articles are marked as read.
9502 If QUIETLY is non-nil, no questions will be asked."
9503   (interactive "P")
9504   (when (gnus-summary-catchup all quietly nil 'fast)
9505     ;; Select next newsgroup or exit.
9506     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9507              (eq gnus-auto-select-next 'quietly))
9508         (gnus-summary-next-group nil)
9509       (gnus-summary-exit))))
9510
9511 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9512   "Mark all articles in this newsgroup as read, and then exit."
9513   (interactive "P")
9514   (gnus-summary-catchup-and-exit t quietly))
9515
9516 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9517   "Mark all articles in this group as read and select the next group.
9518 If given a prefix, mark all articles, unread as well as ticked, as
9519 read."
9520   (interactive "P")
9521   (save-excursion
9522     (gnus-summary-catchup all))
9523   (gnus-summary-next-group))
9524
9525 ;;;
9526 ;;; with article
9527 ;;;
9528
9529 (defmacro gnus-with-article (article &rest forms)
9530   "Select ARTICLE and perform FORMS in the original article buffer.
9531 Then replace the article with the result."
9532   `(progn
9533      ;; We don't want the article to be marked as read.
9534      (let (gnus-mark-article-hook)
9535        (gnus-summary-select-article t t nil ,article))
9536      (set-buffer gnus-original-article-buffer)
9537      ,@forms
9538      (if (not (gnus-check-backend-function
9539                'request-replace-article (car gnus-article-current)))
9540          (gnus-message 5 "Read-only group; not replacing")
9541        (unless (gnus-request-replace-article
9542                 ,article (car gnus-article-current)
9543                 (current-buffer) t)
9544          (error "Couldn't replace article")))
9545      ;; The cache and backlog have to be flushed somewhat.
9546      (when gnus-keep-backlog
9547        (gnus-backlog-remove-article
9548         (car gnus-article-current) (cdr gnus-article-current)))
9549      (when gnus-use-cache
9550        (gnus-cache-update-article
9551         (car gnus-article-current) (cdr gnus-article-current)))))
9552
9553 (put 'gnus-with-article 'lisp-indent-function 1)
9554 (put 'gnus-with-article 'edebug-form-spec '(form body))
9555
9556 ;; Thread-based commands.
9557
9558 (defun gnus-summary-articles-in-thread (&optional article)
9559   "Return a list of all articles in the current thread.
9560 If ARTICLE is non-nil, return all articles in the thread that starts
9561 with that article."
9562   (let* ((article (or article (gnus-summary-article-number)))
9563          (data (gnus-data-find-list article))
9564          (top-level (gnus-data-level (car data)))
9565          (top-subject
9566           (cond ((null gnus-thread-operation-ignore-subject)
9567                  (gnus-simplify-subject-re
9568                   (mail-header-subject (gnus-data-header (car data)))))
9569                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9570                  (gnus-simplify-subject-fuzzy
9571                   (mail-header-subject (gnus-data-header (car data)))))
9572                 (t nil)))
9573          (end-point (save-excursion
9574                       (if (gnus-summary-go-to-next-thread)
9575                           (point) (point-max))))
9576          articles)
9577     (while (and data
9578                 (< (gnus-data-pos (car data)) end-point))
9579       (when (or (not top-subject)
9580                 (string= top-subject
9581                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9582                              (gnus-simplify-subject-fuzzy
9583                               (mail-header-subject
9584                                (gnus-data-header (car data))))
9585                            (gnus-simplify-subject-re
9586                             (mail-header-subject
9587                              (gnus-data-header (car data)))))))
9588         (push (gnus-data-number (car data)) articles))
9589       (unless (and (setq data (cdr data))
9590                    (> (gnus-data-level (car data)) top-level))
9591         (setq data nil)))
9592     ;; Return the list of articles.
9593     (nreverse articles)))
9594
9595 (defun gnus-summary-rethread-current ()
9596   "Rethread the thread the current article is part of."
9597   (interactive)
9598   (let* ((gnus-show-threads t)
9599          (article (gnus-summary-article-number))
9600          (id (mail-header-id (gnus-summary-article-header)))
9601          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9602     (unless id
9603       (error "No article on the current line"))
9604     (gnus-rebuild-thread id)
9605     (gnus-summary-goto-subject article)))
9606
9607 (defun gnus-summary-reparent-thread ()
9608   "Make the current article child of the marked (or previous) article.
9609
9610 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9611 is non-nil or the Subject: of both articles are the same."
9612   (interactive)
9613   (unless (not (gnus-group-read-only-p))
9614     (error "The current newsgroup does not support article editing"))
9615   (unless (<= (length gnus-newsgroup-processable) 1)
9616     (error "No more than one article may be marked"))
9617   (save-window-excursion
9618     (let ((gnus-article-buffer " *reparent*")
9619           (current-article (gnus-summary-article-number))
9620           ;; First grab the marked article, otherwise one line up.
9621           (parent-article (if (not (null gnus-newsgroup-processable))
9622                               (car gnus-newsgroup-processable)
9623                             (save-excursion
9624                               (if (eq (forward-line -1) 0)
9625                                   (gnus-summary-article-number)
9626                                 (error "Beginning of summary buffer"))))))
9627       (unless (not (eq current-article parent-article))
9628         (error "An article may not be self-referential"))
9629       (let ((message-id (mail-header-id
9630                          (gnus-summary-article-header parent-article))))
9631         (unless (and message-id (not (equal message-id "")))
9632           (error "No message-id in desired parent"))
9633         (gnus-with-article current-article
9634           (save-restriction
9635             (goto-char (point-min))
9636             (message-narrow-to-head)
9637             (if (re-search-forward "^References: " nil t)
9638                 (progn
9639                   (re-search-forward "^[^ \t]" nil t)
9640                   (forward-line -1)
9641                   (end-of-line)
9642                   (insert " " message-id))
9643               (insert "References: " message-id "\n"))))
9644         (set-buffer gnus-summary-buffer)
9645         (gnus-summary-unmark-all-processable)
9646         (gnus-summary-update-article current-article)
9647         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9648             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9649         (gnus-summary-rethread-current)
9650         (gnus-message 3 "Article %d is now the child of article %d"
9651                       current-article parent-article)))))
9652
9653 (defun gnus-summary-toggle-threads (&optional arg)
9654   "Toggle showing conversation threads.
9655 If ARG is positive number, turn showing conversation threads on."
9656   (interactive "P")
9657   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9658     (setq gnus-show-threads
9659           (if (null arg) (not gnus-show-threads)
9660             (> (prefix-numeric-value arg) 0)))
9661     (gnus-summary-prepare)
9662     (gnus-summary-goto-subject current)
9663     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9664     (gnus-summary-position-point)))
9665
9666 (defun gnus-summary-show-all-threads ()
9667   "Show all threads."
9668   (interactive)
9669   (save-excursion
9670     (let ((buffer-read-only nil))
9671       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9672   (gnus-summary-position-point))
9673
9674 (defun gnus-summary-show-thread ()
9675   "Show thread subtrees.
9676 Returns nil if no thread was there to be shown."
9677   (interactive)
9678   (let ((buffer-read-only nil)
9679         (orig (point))
9680         ;; first goto end then to beg, to have point at beg after let
9681         (end (progn (end-of-line) (point)))
9682         (beg (progn (beginning-of-line) (point))))
9683     (prog1
9684         ;; Any hidden lines here?
9685         (search-forward "\r" end t)
9686       (subst-char-in-region beg end ?\^M ?\n t)
9687       (goto-char orig)
9688       (gnus-summary-position-point))))
9689
9690 (defun gnus-summary-maybe-hide-threads ()
9691   "If requested, hide the threads that should be hidden."
9692   (when (and gnus-show-threads
9693              gnus-thread-hide-subtree)
9694     (gnus-summary-hide-all-threads
9695      (if (or (consp gnus-thread-hide-subtree)
9696              (gnus-functionp gnus-thread-hide-subtree))
9697          (gnus-make-predicate gnus-thread-hide-subtree)
9698        nil))))
9699
9700 ;;; Hiding predicates.
9701
9702 (defun gnus-article-unread-p (header)
9703   (memq (mail-header-number header) gnus-newsgroup-unreads))
9704
9705 (defun gnus-article-unseen-p (header)
9706   (memq (mail-header-number header) gnus-newsgroup-unseen))
9707
9708 (defun gnus-map-articles (predicate articles)
9709   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
9710   (apply 'gnus-or (mapcar predicate
9711                           (mapcar 'gnus-summary-article-header articles))))
9712
9713 (defun gnus-summary-hide-all-threads (&optional predicate)
9714   "Hide all thread subtrees.
9715 If PREDICATE is supplied, threads that satisfy this predicate
9716 will not be hidden."
9717   (interactive)
9718   (save-excursion
9719     (goto-char (point-min))
9720     (let ((end nil))
9721       (while (not end)
9722         (when (or (not predicate)
9723                   (gnus-map-articles
9724                    predicate (gnus-summary-article-children)))
9725             (gnus-summary-hide-thread))
9726         (setq end (zerop (gnus-summary-next-thread 1 t))))))
9727   (gnus-summary-position-point))
9728
9729 (defun gnus-summary-hide-thread ()
9730   "Hide thread subtrees.
9731 If PREDICATE is supplied, threads that satisfy this predicate
9732 will not be hidden.
9733 Returns nil if no threads were there to be hidden."
9734   (interactive)
9735   (let ((buffer-read-only nil)
9736         (start (point))
9737         (article (gnus-summary-article-number)))
9738     (goto-char start)
9739     ;; Go forward until either the buffer ends or the subthread
9740     ;; ends.
9741     (when (and (not (eobp))
9742                (or (zerop (gnus-summary-next-thread 1 t))
9743                    (goto-char (point-max))))
9744       (prog1
9745           (if (and (> (point) start)
9746                    (search-backward "\n" start t))
9747               (progn
9748                 (subst-char-in-region start (point) ?\n ?\^M)
9749                 (gnus-summary-goto-subject article))
9750             (goto-char start)
9751             nil)))))
9752
9753 (defun gnus-summary-go-to-next-thread (&optional previous)
9754   "Go to the same level (or less) next thread.
9755 If PREVIOUS is non-nil, go to previous thread instead.
9756 Return the article number moved to, or nil if moving was impossible."
9757   (let ((level (gnus-summary-thread-level))
9758         (way (if previous -1 1))
9759         (beg (point)))
9760     (forward-line way)
9761     (while (and (not (eobp))
9762                 (< level (gnus-summary-thread-level)))
9763       (forward-line way))
9764     (if (eobp)
9765         (progn
9766           (goto-char beg)
9767           nil)
9768       (setq beg (point))
9769       (prog1
9770           (gnus-summary-article-number)
9771         (goto-char beg)))))
9772
9773 (defun gnus-summary-next-thread (n &optional silent)
9774   "Go to the same level next N'th thread.
9775 If N is negative, search backward instead.
9776 Returns the difference between N and the number of skips actually
9777 done.
9778
9779 If SILENT, don't output messages."
9780   (interactive "p")
9781   (let ((backward (< n 0))
9782         (n (abs n)))
9783     (while (and (> n 0)
9784                 (gnus-summary-go-to-next-thread backward))
9785       (decf n))
9786     (unless silent
9787       (gnus-summary-position-point))
9788     (when (and (not silent) (/= 0 n))
9789       (gnus-message 7 "No more threads"))
9790     n))
9791
9792 (defun gnus-summary-prev-thread (n)
9793   "Go to the same level previous N'th thread.
9794 Returns the difference between N and the number of skips actually
9795 done."
9796   (interactive "p")
9797   (gnus-summary-next-thread (- n)))
9798
9799 (defun gnus-summary-go-down-thread ()
9800   "Go down one level in the current thread."
9801   (let ((children (gnus-summary-article-children)))
9802     (when children
9803       (gnus-summary-goto-subject (car children)))))
9804
9805 (defun gnus-summary-go-up-thread ()
9806   "Go up one level in the current thread."
9807   (let ((parent (gnus-summary-article-parent)))
9808     (when parent
9809       (gnus-summary-goto-subject parent))))
9810
9811 (defun gnus-summary-down-thread (n)
9812   "Go down thread N steps.
9813 If N is negative, go up instead.
9814 Returns the difference between N and how many steps down that were
9815 taken."
9816   (interactive "p")
9817   (let ((up (< n 0))
9818         (n (abs n)))
9819     (while (and (> n 0)
9820                 (if up (gnus-summary-go-up-thread)
9821                   (gnus-summary-go-down-thread)))
9822       (setq n (1- n)))
9823     (gnus-summary-position-point)
9824     (when (/= 0 n)
9825       (gnus-message 7 "Can't go further"))
9826     n))
9827
9828 (defun gnus-summary-up-thread (n)
9829   "Go up thread N steps.
9830 If N is negative, go down instead.
9831 Returns the difference between N and how many steps down that were
9832 taken."
9833   (interactive "p")
9834   (gnus-summary-down-thread (- n)))
9835
9836 (defun gnus-summary-top-thread ()
9837   "Go to the top of the thread."
9838   (interactive)
9839   (while (gnus-summary-go-up-thread))
9840   (gnus-summary-article-number))
9841
9842 (defun gnus-summary-kill-thread (&optional unmark)
9843   "Mark articles under current thread as read.
9844 If the prefix argument is positive, remove any kinds of marks.
9845 If the prefix argument is negative, tick articles instead."
9846   (interactive "P")
9847   (when unmark
9848     (setq unmark (prefix-numeric-value unmark)))
9849   (let ((articles (gnus-summary-articles-in-thread)))
9850     (save-excursion
9851       ;; Expand the thread.
9852       (gnus-summary-show-thread)
9853       ;; Mark all the articles.
9854       (while articles
9855         (gnus-summary-goto-subject (car articles))
9856         (cond ((null unmark)
9857                (gnus-summary-mark-article-as-read gnus-killed-mark))
9858               ((> unmark 0)
9859                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9860               (t
9861                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9862         (setq articles (cdr articles))))
9863     ;; Hide killed subtrees.
9864     (and (null unmark)
9865          gnus-thread-hide-killed
9866          (gnus-summary-hide-thread))
9867     ;; If marked as read, go to next unread subject.
9868     (when (null unmark)
9869       ;; Go to next unread subject.
9870       (gnus-summary-next-subject 1 t)))
9871   (gnus-set-mode-line 'summary))
9872
9873 ;; Summary sorting commands
9874
9875 (defun gnus-summary-sort-by-number (&optional reverse)
9876   "Sort the summary buffer by article number.
9877 Argument REVERSE means reverse order."
9878   (interactive "P")
9879   (gnus-summary-sort 'number reverse))
9880
9881 (defun gnus-summary-sort-by-author (&optional reverse)
9882   "Sort the summary buffer by author name alphabetically.
9883 If `case-fold-search' is non-nil, case of letters is ignored.
9884 Argument REVERSE means reverse order."
9885   (interactive "P")
9886   (gnus-summary-sort 'author reverse))
9887
9888 (defun gnus-summary-sort-by-subject (&optional reverse)
9889   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9890 If `case-fold-search' is non-nil, case of letters is ignored.
9891 Argument REVERSE means reverse order."
9892   (interactive "P")
9893   (gnus-summary-sort 'subject reverse))
9894
9895 (defun gnus-summary-sort-by-date (&optional reverse)
9896   "Sort the summary buffer by date.
9897 Argument REVERSE means reverse order."
9898   (interactive "P")
9899   (gnus-summary-sort 'date reverse))
9900
9901 (defun gnus-summary-sort-by-score (&optional reverse)
9902   "Sort the summary buffer by score.
9903 Argument REVERSE means reverse order."
9904   (interactive "P")
9905   (gnus-summary-sort 'score reverse))
9906
9907 (defun gnus-summary-sort-by-lines (&optional reverse)
9908   "Sort the summary buffer by the number of lines.
9909 Argument REVERSE means reverse order."
9910   (interactive "P")
9911   (gnus-summary-sort 'lines reverse))
9912
9913 (defun gnus-summary-sort-by-chars (&optional reverse)
9914   "Sort the summary buffer by article length.
9915 Argument REVERSE means reverse order."
9916   (interactive "P")
9917   (gnus-summary-sort 'chars reverse))
9918
9919 (defun gnus-summary-sort-by-original (&optional reverse)
9920   "Sort the summary buffer using the default sorting method.
9921 Argument REVERSE means reverse order."
9922   (interactive "P")
9923   (let* ((buffer-read-only)
9924          (gnus-summary-prepare-hook nil))
9925     ;; We do the sorting by regenerating the threads.
9926     (gnus-summary-prepare)
9927     ;; Hide subthreads if needed.
9928     (gnus-summary-maybe-hide-threads)))
9929
9930 (defun gnus-summary-sort (predicate reverse)
9931   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9932   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9933          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9934          (gnus-thread-sort-functions
9935           (if (not reverse)
9936               thread
9937             `(lambda (t1 t2)
9938                (,thread t2 t1))))
9939          (gnus-sort-gathered-threads-function
9940           gnus-thread-sort-functions)
9941          (gnus-article-sort-functions
9942           (if (not reverse)
9943               article
9944             `(lambda (t1 t2)
9945                (,article t2 t1))))
9946          (buffer-read-only)
9947          (gnus-summary-prepare-hook nil))
9948     ;; We do the sorting by regenerating the threads.
9949     (gnus-summary-prepare)
9950     ;; Hide subthreads if needed.
9951     (gnus-summary-maybe-hide-threads)))
9952
9953 ;; Summary saving commands.
9954
9955 (defun gnus-summary-save-article (&optional n not-saved)
9956   "Save the current article using the default saver function.
9957 If N is a positive number, save the N next articles.
9958 If N is a negative number, save the N previous articles.
9959 If N is nil and any articles have been marked with the process mark,
9960 save those articles instead.
9961 The variable `gnus-default-article-saver' specifies the saver function."
9962   (interactive "P")
9963   (let* ((articles (gnus-summary-work-articles n))
9964          (save-buffer (save-excursion
9965                         (nnheader-set-temp-buffer " *Gnus Save*")))
9966          (num (length articles))
9967          header file)
9968     (dolist (article articles)
9969       (setq header (gnus-summary-article-header article))
9970       (if (not (vectorp header))
9971           ;; This is a pseudo-article.
9972           (if (assq 'name header)
9973               (gnus-copy-file (cdr (assq 'name header)))
9974             (gnus-message 1 "Article %d is unsaveable" article))
9975         ;; This is a real article.
9976         (save-window-excursion
9977           (let ((gnus-display-mime-function nil)
9978                 (gnus-article-prepare-hook nil))
9979             (gnus-summary-select-article t nil nil article)))
9980         (save-excursion
9981           (set-buffer save-buffer)
9982           (erase-buffer)
9983           (insert-buffer-substring gnus-original-article-buffer))
9984         (setq file (gnus-article-save save-buffer file num))
9985         (gnus-summary-remove-process-mark article)
9986         (unless not-saved
9987           (gnus-summary-set-saved-mark article))))
9988     (gnus-kill-buffer save-buffer)
9989     (gnus-summary-position-point)
9990     (gnus-set-mode-line 'summary)
9991     n))
9992
9993 (defun gnus-summary-pipe-output (&optional arg)
9994   "Pipe the current article to a subprocess.
9995 If N is a positive number, pipe the N next articles.
9996 If N is a negative number, pipe the N previous articles.
9997 If N is nil and any articles have been marked with the process mark,
9998 pipe those articles instead."
9999   (interactive "P")
10000   (require 'gnus-art)
10001   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10002     (gnus-summary-save-article arg t))
10003   (let ((buffer (get-buffer "*Shell Command Output*")))
10004     (if (and buffer
10005              (with-current-buffer buffer (> (point-max) (point-min))))
10006         (gnus-configure-windows 'pipe))))
10007
10008 (defun gnus-summary-save-article-mail (&optional arg)
10009   "Append the current article to an mail file.
10010 If N is a positive number, save the N next articles.
10011 If N is a negative number, save the N previous articles.
10012 If N is nil and any articles have been marked with the process mark,
10013 save those articles instead."
10014   (interactive "P")
10015   (require 'gnus-art)
10016   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10017     (gnus-summary-save-article arg)))
10018
10019 (defun gnus-summary-save-article-rmail (&optional arg)
10020   "Append the current article to an rmail file.
10021 If N is a positive number, save the N next articles.
10022 If N is a negative number, save the N previous articles.
10023 If N is nil and any articles have been marked with the process mark,
10024 save those articles instead."
10025   (interactive "P")
10026   (require 'gnus-art)
10027   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10028     (gnus-summary-save-article arg)))
10029
10030 (defun gnus-summary-save-article-file (&optional arg)
10031   "Append the current article to a file.
10032 If N is a positive number, save the N next articles.
10033 If N is a negative number, save the N previous articles.
10034 If N is nil and any articles have been marked with the process mark,
10035 save those articles instead."
10036   (interactive "P")
10037   (require 'gnus-art)
10038   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10039     (gnus-summary-save-article arg)))
10040
10041 (defun gnus-summary-write-article-file (&optional arg)
10042   "Write the current article to a file, deleting the previous file.
10043 If N is a positive number, save the N next articles.
10044 If N is a negative number, save the N previous articles.
10045 If N is nil and any articles have been marked with the process mark,
10046 save those articles instead."
10047   (interactive "P")
10048   (require 'gnus-art)
10049   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10050     (gnus-summary-save-article arg)))
10051
10052 (defun gnus-summary-save-article-body-file (&optional arg)
10053   "Append the current article body to a file.
10054 If N is a positive number, save the N next articles.
10055 If N is a negative number, save the N previous articles.
10056 If N is nil and any articles have been marked with the process mark,
10057 save those articles instead."
10058   (interactive "P")
10059   (require 'gnus-art)
10060   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10061     (gnus-summary-save-article arg)))
10062
10063 (defun gnus-summary-muttprint (&optional arg)
10064   "Print the current article using Muttprint.
10065 If N is a positive number, save the N next articles.
10066 If N is a negative number, save the N previous articles.
10067 If N is nil and any articles have been marked with the process mark,
10068 save those articles instead."
10069   (interactive "P")
10070   (require 'gnus-art)
10071   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10072     (gnus-summary-save-article arg t)))
10073
10074 (defun gnus-summary-pipe-message (program)
10075   "Pipe the current article through PROGRAM."
10076   (interactive "sProgram: ")
10077   (gnus-summary-select-article)
10078   (let ((mail-header-separator ""))
10079     (gnus-eval-in-buffer-window gnus-article-buffer
10080       (save-restriction
10081         (widen)
10082         (let ((start (window-start))
10083               buffer-read-only)
10084           (message-pipe-buffer-body program)
10085           (set-window-start (get-buffer-window (current-buffer)) start))))))
10086
10087 (defun gnus-get-split-value (methods)
10088   "Return a value based on the split METHODS."
10089   (let (split-name method result match)
10090     (when methods
10091       (save-excursion
10092         (set-buffer gnus-original-article-buffer)
10093         (save-restriction
10094           (nnheader-narrow-to-headers)
10095           (while (and methods (not split-name))
10096             (goto-char (point-min))
10097             (setq method (pop methods))
10098             (setq match (car method))
10099             (when (cond
10100                    ((stringp match)
10101                     ;; Regular expression.
10102                     (ignore-errors
10103                       (re-search-forward match nil t)))
10104                    ((gnus-functionp match)
10105                     ;; Function.
10106                     (save-restriction
10107                       (widen)
10108                       (setq result (funcall match gnus-newsgroup-name))))
10109                    ((consp match)
10110                     ;; Form.
10111                     (save-restriction
10112                       (widen)
10113                       (setq result (eval match)))))
10114               (setq split-name (cdr method))
10115               (cond ((stringp result)
10116                      (push (expand-file-name
10117                             result gnus-article-save-directory)
10118                            split-name))
10119                     ((consp result)
10120                      (setq split-name (append result split-name)))))))))
10121     (nreverse split-name)))
10122
10123 (defun gnus-valid-move-group-p (group)
10124   (and (boundp group)
10125        (symbol-name group)
10126        (symbol-value group)
10127        (gnus-get-function (gnus-find-method-for-group
10128                            (symbol-name group)) 'request-accept-article t)))
10129
10130 (defun gnus-read-move-group-name (prompt default articles prefix)
10131   "Read a group name."
10132   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10133          (minibuffer-confirm-incomplete nil) ; XEmacs
10134          (prom
10135           (format "%s %s to:"
10136                   prompt
10137                   (if (> (length articles) 1)
10138                       (format "these %d articles" (length articles))
10139                     "this article")))
10140          (to-newsgroup
10141           (cond
10142            ((null split-name)
10143             (gnus-completing-read default prom
10144                                   gnus-active-hashtb
10145                                   'gnus-valid-move-group-p
10146                                   nil prefix
10147                                   'gnus-group-history))
10148            ((= 1 (length split-name))
10149             (gnus-completing-read (car split-name) prom
10150                                   gnus-active-hashtb
10151                                   'gnus-valid-move-group-p
10152                                   nil nil
10153                                   'gnus-group-history))
10154            (t
10155             (gnus-completing-read nil prom
10156                                   (mapcar (lambda (el) (list el))
10157                                           (nreverse split-name))
10158                                   nil nil nil
10159                                   'gnus-group-history))))
10160          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10161     (when to-newsgroup
10162       (if (or (string= to-newsgroup "")
10163               (string= to-newsgroup prefix))
10164           (setq to-newsgroup default))
10165       (unless to-newsgroup
10166         (error "No group name entered"))
10167       (or (gnus-active to-newsgroup)
10168           (gnus-activate-group to-newsgroup nil nil to-method)
10169           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10170                                      to-newsgroup))
10171               (or (and (gnus-request-create-group to-newsgroup to-method)
10172                        (gnus-activate-group
10173                         to-newsgroup nil nil to-method)
10174                        (gnus-subscribe-group to-newsgroup))
10175                   (error "Couldn't create group %s" to-newsgroup)))
10176           (error "No such group: %s" to-newsgroup)))
10177     to-newsgroup))
10178
10179 (defun gnus-summary-save-parts (type dir n &optional reverse)
10180   "Save parts matching TYPE to DIR.
10181 If REVERSE, save parts that do not match TYPE."
10182   (interactive
10183    (list (read-string "Save parts of type: "
10184                       (or (car gnus-summary-save-parts-type-history)
10185                           gnus-summary-save-parts-default-mime)
10186                       'gnus-summary-save-parts-type-history)
10187          (setq gnus-summary-save-parts-last-directory
10188                (read-file-name "Save to directory: "
10189                                gnus-summary-save-parts-last-directory
10190                                nil t))
10191          current-prefix-arg))
10192   (gnus-summary-iterate n
10193     (let ((gnus-display-mime-function nil)
10194           (gnus-inhibit-treatment t))
10195       (gnus-summary-select-article))
10196     (save-excursion
10197       (set-buffer gnus-article-buffer)
10198       (let ((handles (or gnus-article-mime-handles
10199                          (mm-dissect-buffer) (mm-uu-dissect))))
10200         (when handles
10201           (gnus-summary-save-parts-1 type dir handles reverse)
10202           (unless gnus-article-mime-handles ;; Don't destroy this case.
10203             (mm-destroy-parts handles)))))))
10204
10205 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10206   (if (stringp (car handle))
10207       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10208               (cdr handle))
10209     (when (if reverse
10210               (not (string-match type (mm-handle-media-type handle)))
10211             (string-match type (mm-handle-media-type handle)))
10212       (let ((file (expand-file-name
10213                    (file-name-nondirectory
10214                     (or
10215                      (mail-content-type-get
10216                       (mm-handle-disposition handle) 'filename)
10217                      (concat gnus-newsgroup-name
10218                              "." (number-to-string
10219                                   (cdr gnus-article-current)))))
10220                    dir)))
10221         (unless (file-exists-p file)
10222           (mm-save-part-to-file handle file))))))
10223
10224 ;; Summary extract commands
10225
10226 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10227   (let ((buffer-read-only nil)
10228         (article (gnus-summary-article-number))
10229         after-article b e)
10230     (unless (gnus-summary-goto-subject article)
10231       (error "No such article: %d" article))
10232     (gnus-summary-position-point)
10233     ;; If all commands are to be bunched up on one line, we collect
10234     ;; them here.
10235     (unless gnus-view-pseudos-separately
10236       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10237             files action)
10238         (while ps
10239           (setq action (cdr (assq 'action (car ps))))
10240           (setq files (list (cdr (assq 'name (car ps)))))
10241           (while (and ps (cdr ps)
10242                       (string= (or action "1")
10243                                (or (cdr (assq 'action (cadr ps))) "2")))
10244             (push (cdr (assq 'name (cadr ps))) files)
10245             (setcdr ps (cddr ps)))
10246           (when files
10247             (when (not (string-match "%s" action))
10248               (push " " files))
10249             (push " " files)
10250             (when (assq 'execute (car ps))
10251               (setcdr (assq 'execute (car ps))
10252                       (funcall (if (string-match "%s" action)
10253                                    'format 'concat)
10254                                action
10255                                (mapconcat
10256                                 (lambda (f)
10257                                   (if (equal f " ")
10258                                       f
10259                                     (mm-quote-arg f)))
10260                                 files " ")))))
10261           (setq ps (cdr ps)))))
10262     (if (and gnus-view-pseudos (not not-view))
10263         (while pslist
10264           (when (assq 'execute (car pslist))
10265             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10266                                   (eq gnus-view-pseudos 'not-confirm)))
10267           (setq pslist (cdr pslist)))
10268       (save-excursion
10269         (while pslist
10270           (setq after-article (or (cdr (assq 'article (car pslist)))
10271                                   (gnus-summary-article-number)))
10272           (gnus-summary-goto-subject after-article)
10273           (forward-line 1)
10274           (setq b (point))
10275           (insert "    " (file-name-nondirectory
10276                           (cdr (assq 'name (car pslist))))
10277                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10278           (setq e (point))
10279           (forward-line -1)             ; back to `b'
10280           (gnus-add-text-properties
10281            b (1- e) (list 'gnus-number gnus-reffed-article-number
10282                           gnus-mouse-face-prop gnus-mouse-face))
10283           (gnus-data-enter
10284            after-article gnus-reffed-article-number
10285            gnus-unread-mark b (car pslist) 0 (- e b))
10286           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10287           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10288           (setq pslist (cdr pslist)))))))
10289
10290 (defun gnus-pseudos< (p1 p2)
10291   (let ((c1 (cdr (assq 'action p1)))
10292         (c2 (cdr (assq 'action p2))))
10293     (and c1 c2 (string< c1 c2))))
10294
10295 (defun gnus-request-pseudo-article (props)
10296   (cond ((assq 'execute props)
10297          (gnus-execute-command (cdr (assq 'execute props)))))
10298   (let ((gnus-current-article (gnus-summary-article-number)))
10299     (gnus-run-hooks 'gnus-mark-article-hook)))
10300
10301 (defun gnus-execute-command (command &optional automatic)
10302   (save-excursion
10303     (gnus-article-setup-buffer)
10304     (set-buffer gnus-article-buffer)
10305     (setq buffer-read-only nil)
10306     (let ((command (if automatic command
10307                      (read-string "Command: " (cons command 0)))))
10308       (erase-buffer)
10309       (insert "$ " command "\n\n")
10310       (if gnus-view-pseudo-asynchronously
10311           (start-process "gnus-execute" (current-buffer) shell-file-name
10312                          shell-command-switch command)
10313         (call-process shell-file-name nil t nil
10314                       shell-command-switch command)))))
10315
10316 ;; Summary kill commands.
10317
10318 (defun gnus-summary-edit-global-kill (article)
10319   "Edit the \"global\" kill file."
10320   (interactive (list (gnus-summary-article-number)))
10321   (gnus-group-edit-global-kill article))
10322
10323 (defun gnus-summary-edit-local-kill ()
10324   "Edit a local kill file applied to the current newsgroup."
10325   (interactive)
10326   (setq gnus-current-headers (gnus-summary-article-header))
10327   (gnus-group-edit-local-kill
10328    (gnus-summary-article-number) gnus-newsgroup-name))
10329
10330 ;;; Header reading.
10331
10332 (defun gnus-read-header (id &optional header)
10333   "Read the headers of article ID and enter them into the Gnus system."
10334   (let ((group gnus-newsgroup-name)
10335         (gnus-override-method
10336          (or
10337           gnus-override-method
10338           (and (gnus-news-group-p gnus-newsgroup-name)
10339                (car (gnus-refer-article-methods)))))
10340         where)
10341     ;; First we check to see whether the header in question is already
10342     ;; fetched.
10343     (if (stringp id)
10344         ;; This is a Message-ID.
10345         (setq header (or header (gnus-id-to-header id)))
10346       ;; This is an article number.
10347       (setq header (or header (gnus-summary-article-header id))))
10348     (if (and header
10349              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10350         ;; We have found the header.
10351         header
10352       ;; If this is a sparse article, we have to nix out its
10353       ;; previous entry in the thread hashtb.
10354       (when (and header
10355                  (gnus-summary-article-sparse-p (mail-header-number header)))
10356         (let* ((parent (gnus-parent-id (mail-header-references header)))
10357                (thread (and parent (gnus-id-to-thread parent))))
10358           (when thread
10359             (delq (assq header thread) thread))))
10360       ;; We have to really fetch the header to this article.
10361       (save-excursion
10362         (set-buffer nntp-server-buffer)
10363         (when (setq where (gnus-request-head id group))
10364           (nnheader-fold-continuation-lines)
10365           (goto-char (point-max))
10366           (insert ".\n")
10367           (goto-char (point-min))
10368           (insert "211 ")
10369           (princ (cond
10370                   ((numberp id) id)
10371                   ((cdr where) (cdr where))
10372                   (header (mail-header-number header))
10373                   (t gnus-reffed-article-number))
10374                  (current-buffer))
10375           (insert " Article retrieved.\n"))
10376         (if (or (not where)
10377                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10378             ()                          ; Malformed head.
10379           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10380             (when (and (stringp id)
10381                        (not (string= (gnus-group-real-name group)
10382                                      (car where))))
10383               ;; If we fetched by Message-ID and the article came
10384               ;; from a different group, we fudge some bogus article
10385               ;; numbers for this article.
10386               (mail-header-set-number header gnus-reffed-article-number))
10387             (save-excursion
10388               (set-buffer gnus-summary-buffer)
10389               (decf gnus-reffed-article-number)
10390               (gnus-remove-header (mail-header-number header))
10391               (push header gnus-newsgroup-headers)
10392               (setq gnus-current-headers header)
10393               (push (mail-header-number header) gnus-newsgroup-limit)))
10394           header)))))
10395
10396 (defun gnus-remove-header (number)
10397   "Remove header NUMBER from `gnus-newsgroup-headers'."
10398   (if (and gnus-newsgroup-headers
10399            (= number (mail-header-number (car gnus-newsgroup-headers))))
10400       (pop gnus-newsgroup-headers)
10401     (let ((headers gnus-newsgroup-headers))
10402       (while (and (cdr headers)
10403                   (not (= number (mail-header-number (cadr headers)))))
10404         (pop headers))
10405       (when (cdr headers)
10406         (setcdr headers (cddr headers))))))
10407
10408 ;;;
10409 ;;; summary highlights
10410 ;;;
10411
10412 (defun gnus-highlight-selected-summary ()
10413   "Highlight selected article in summary buffer."
10414   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10415   (when gnus-summary-selected-face
10416     (save-excursion
10417       (let* ((beg (progn (beginning-of-line) (point)))
10418              (end (progn (end-of-line) (point)))
10419              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10420              (from (if (get-text-property beg gnus-mouse-face-prop)
10421                        beg
10422                      (or (next-single-property-change
10423                           beg gnus-mouse-face-prop nil end)
10424                          beg)))
10425              (to
10426               (if (= from end)
10427                   (- from 2)
10428                 (or (next-single-property-change
10429                      from gnus-mouse-face-prop nil end)
10430                     end))))
10431         ;; If no mouse-face prop on line we will have to = from = end,
10432         ;; so we highlight the entire line instead.
10433         (when (= (+ to 2) from)
10434           (setq from beg)
10435           (setq to end))
10436         (if gnus-newsgroup-selected-overlay
10437             ;; Move old overlay.
10438             (gnus-move-overlay
10439              gnus-newsgroup-selected-overlay from to (current-buffer))
10440           ;; Create new overlay.
10441           (gnus-overlay-put
10442            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10443            'face gnus-summary-selected-face))))))
10444
10445 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10446 (defun gnus-summary-highlight-line ()
10447   "Highlight current line according to `gnus-summary-highlight'."
10448   (let* ((list gnus-summary-highlight)
10449          (p (point))
10450          (end (progn (end-of-line) (point)))
10451          ;; now find out where the line starts and leave point there.
10452          (beg (progn (beginning-of-line) (point)))
10453          (article (gnus-summary-article-number))
10454          (score (or (cdr (assq (or article gnus-current-article)
10455                                gnus-newsgroup-scored))
10456                     gnus-summary-default-score 0))
10457          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10458          (inhibit-read-only t))
10459     ;; Eval the cars of the lists until we find a match.
10460     (let ((default gnus-summary-default-score)
10461           (default-high gnus-summary-default-high-score)
10462           (default-low gnus-summary-default-low-score))
10463       (while (and list
10464                   (not (eval (caar list))))
10465         (setq list (cdr list))))
10466     (let ((face (cdar list)))
10467       (unless (eq face (get-text-property beg 'face))
10468         (gnus-put-text-property-excluding-characters-with-faces
10469          beg end 'face
10470          (setq face (if (boundp face) (symbol-value face) face)))
10471         (when gnus-summary-highlight-line-function
10472           (funcall gnus-summary-highlight-line-function article face))))
10473     (goto-char p)))
10474
10475 (defun gnus-update-read-articles (group unread &optional compute)
10476   "Update the list of read articles in GROUP."
10477   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10478          (entry (gnus-gethash group gnus-newsrc-hashtb))
10479          (info (nth 2 entry))
10480          (prev 1)
10481          (unread (sort (copy-sequence unread) '<))
10482          read)
10483     (if (or (not info) (not active))
10484         ;; There is no info on this group if it was, in fact,
10485         ;; killed.  Gnus stores no information on killed groups, so
10486         ;; there's nothing to be done.
10487         ;; One could store the information somewhere temporarily,
10488         ;; perhaps...  Hmmm...
10489         ()
10490       ;; Remove any negative articles numbers.
10491       (while (and unread (< (car unread) 0))
10492         (setq unread (cdr unread)))
10493       ;; Remove any expired article numbers
10494       (while (and unread (< (car unread) (car active)))
10495         (setq unread (cdr unread)))
10496       ;; Compute the ranges of read articles by looking at the list of
10497       ;; unread articles.
10498       (while unread
10499         (when (/= (car unread) prev)
10500           (push (if (= prev (1- (car unread))) prev
10501                   (cons prev (1- (car unread))))
10502                 read))
10503         (setq prev (1+ (car unread)))
10504         (setq unread (cdr unread)))
10505       (when (<= prev (cdr active))
10506         (push (cons prev (cdr active)) read))
10507       (setq read (if (> (length read) 1) (nreverse read) read))
10508       (if compute
10509           read
10510         (save-excursion
10511           (let (setmarkundo)
10512             ;; Propagate the read marks to the backend.
10513             (when (gnus-check-backend-function 'request-set-mark group)
10514               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10515                     (add (gnus-remove-from-range read (gnus-info-read info))))
10516                 (when (or add del)
10517                   (unless (gnus-check-group group)
10518                     (error "Can't open server for %s" group))
10519                   (gnus-request-set-mark
10520                    group (delq nil (list (if add (list add 'add '(read)))
10521                                          (if del (list del 'del '(read))))))
10522                   (setq setmarkundo
10523                         `(gnus-request-set-mark
10524                           ,group
10525                           ',(delq nil (list
10526                                        (if del (list del 'add '(read)))
10527                                        (if add (list add 'del '(read))))))))))
10528             (set-buffer gnus-group-buffer)
10529             (gnus-undo-register
10530               `(progn
10531                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10532                  (gnus-info-set-read ',info ',(gnus-info-read info))
10533                  (gnus-get-unread-articles-in-group ',info
10534                                                     (gnus-active ,group))
10535                  (gnus-group-update-group ,group t)
10536                  ,setmarkundo))))
10537         ;; Enter this list into the group info.
10538         (gnus-info-set-read info read)
10539         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10540         (gnus-get-unread-articles-in-group info (gnus-active group))
10541         t))))
10542
10543 (defun gnus-offer-save-summaries ()
10544   "Offer to save all active summary buffers."
10545   (let (buffers)
10546     ;; Go through all buffers and find all summaries.
10547     (dolist (buffer (buffer-list))
10548       (when (and (setq buffer (buffer-name buffer))
10549                  (string-match "Summary" buffer)
10550                  (save-excursion
10551                    (set-buffer buffer)
10552                    ;; We check that this is, indeed, a summary buffer.
10553                    (and (eq major-mode 'gnus-summary-mode)
10554                         ;; Also make sure this isn't bogus.
10555                         gnus-newsgroup-prepared
10556                         ;; Also make sure that this isn't a
10557                         ;; dead summary buffer.
10558                         (not gnus-dead-summary-mode))))
10559         (push buffer buffers)))
10560     ;; Go through all these summary buffers and offer to save them.
10561     (when buffers
10562       (save-excursion
10563         (map-y-or-n-p
10564          "Update summary buffer %s? "
10565          (lambda (buf)
10566            (switch-to-buffer buf)
10567            (gnus-summary-exit))
10568          buffers)))))
10569
10570 (defun gnus-summary-setup-default-charset ()
10571   "Setup newsgroup default charset."
10572   (if (equal gnus-newsgroup-name "nndraft:drafts")
10573       (setq gnus-newsgroup-charset nil)
10574     (let* ((ignored-charsets
10575             (or gnus-newsgroup-ephemeral-ignored-charsets
10576                 (append
10577                  (and gnus-newsgroup-name
10578                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10579                  gnus-newsgroup-ignored-charsets))))
10580       (setq gnus-newsgroup-charset
10581             (or gnus-newsgroup-ephemeral-charset
10582                 (and gnus-newsgroup-name
10583                      (gnus-parameter-charset gnus-newsgroup-name))
10584                 gnus-default-charset))
10585       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10586            ignored-charsets))))
10587
10588 ;;;
10589 ;;; Mime Commands
10590 ;;;
10591
10592 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10593   "Display the current article buffer fully MIME-buttonized.
10594 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10595 treated as multipart/mixed."
10596   (interactive "P")
10597   (require 'gnus-art)
10598   (let ((gnus-unbuttonized-mime-types nil)
10599         (gnus-mime-display-multipart-as-mixed show-all-parts))
10600     (gnus-summary-show-article)))
10601
10602 (defun gnus-summary-repair-multipart (article)
10603   "Add a Content-Type header to a multipart article without one."
10604   (interactive (list (gnus-summary-article-number)))
10605   (gnus-with-article article
10606     (message-narrow-to-head)
10607     (message-remove-header "Mime-Version")
10608     (goto-char (point-max))
10609     (insert "Mime-Version: 1.0\n")
10610     (widen)
10611     (when (search-forward "\n--" nil t)
10612       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10613         (message-narrow-to-head)
10614         (message-remove-header "Content-Type")
10615         (goto-char (point-max))
10616         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10617                         separator))
10618         (widen))))
10619   (let (gnus-mark-article-hook)
10620     (gnus-summary-select-article t t nil article)))
10621
10622 (defun gnus-summary-toggle-display-buttonized ()
10623   "Toggle the buttonizing of the article buffer."
10624   (interactive)
10625   (require 'gnus-art)
10626   (if (setq gnus-inhibit-mime-unbuttonizing
10627             (not gnus-inhibit-mime-unbuttonizing))
10628       (let ((gnus-unbuttonized-mime-types nil))
10629         (gnus-summary-show-article))
10630     (gnus-summary-show-article)))
10631
10632 ;;;
10633 ;;; Generic summary marking commands
10634 ;;;
10635
10636 (defvar gnus-summary-marking-alist
10637   '((read gnus-del-mark "d")
10638     (unread gnus-unread-mark "u")
10639     (ticked gnus-ticked-mark "!")
10640     (dormant gnus-dormant-mark "?")
10641     (expirable gnus-expirable-mark "e"))
10642   "An alist of names/marks/keystrokes.")
10643
10644 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10645 (defvar gnus-summary-mark-map)
10646
10647 (defun gnus-summary-make-all-marking-commands ()
10648   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10649   (dolist (elem gnus-summary-marking-alist)
10650     (apply 'gnus-summary-make-marking-command elem)))
10651
10652 (defun gnus-summary-make-marking-command (name mark keystroke)
10653   (let ((map (make-sparse-keymap)))
10654     (define-key gnus-summary-generic-mark-map keystroke map)
10655     (dolist (lway `((next "next" next nil "n")
10656                     (next-unread "next unread" next t "N")
10657                     (prev "previous" prev nil "p")
10658                     (prev-unread "previous unread" prev t "P")
10659                     (nomove "" nil nil ,keystroke)))
10660       (let ((func (gnus-summary-make-marking-command-1
10661                    mark (car lway) lway name)))
10662         (setq func (eval func))
10663         (define-key map (nth 4 lway) func)))))
10664
10665 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10666   `(defun ,(intern
10667             (format "gnus-summary-put-mark-as-%s%s"
10668                     name (if (eq way 'nomove)
10669                              ""
10670                            (concat "-" (symbol-name way)))))
10671      (n)
10672      ,(format
10673        "Mark the current article as %s%s.
10674 If N, the prefix, then repeat N times.
10675 If N is negative, move in reverse order.
10676 The difference between N and the actual number of articles marked is
10677 returned."
10678        name (cadr lway))
10679      (interactive "p")
10680      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10681
10682 (defun gnus-summary-generic-mark (n mark move unread)
10683   "Mark N articles with MARK."
10684   (unless (eq major-mode 'gnus-summary-mode)
10685     (error "This command can only be used in the summary buffer"))
10686   (gnus-summary-show-thread)
10687   (let ((nummove
10688          (cond
10689           ((eq move 'next) 1)
10690           ((eq move 'prev) -1)
10691           (t 0))))
10692     (if (zerop nummove)
10693         (setq n 1)
10694       (when (< n 0)
10695         (setq n (abs n)
10696               nummove (* -1 nummove))))
10697     (while (and (> n 0)
10698                 (gnus-summary-mark-article nil mark)
10699                 (zerop (gnus-summary-next-subject nummove unread t)))
10700       (setq n (1- n)))
10701     (when (/= 0 n)
10702       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10703     (gnus-summary-recenter)
10704     (gnus-summary-position-point)
10705     (gnus-set-mode-line 'summary)
10706     n))
10707
10708 (defun gnus-summary-insert-articles (articles)
10709   (when (setq articles
10710               (gnus-set-difference articles
10711                                    (mapcar (lambda (h) (mail-header-number h))
10712                                            gnus-newsgroup-headers)))
10713     (setq gnus-newsgroup-headers
10714           (merge 'list
10715                  gnus-newsgroup-headers
10716                  (gnus-fetch-headers articles)
10717                  'gnus-article-sort-by-number))
10718     ;; Suppress duplicates?
10719     (when gnus-suppress-duplicates
10720       (gnus-dup-suppress-articles))
10721
10722     ;; We might want to build some more threads first.
10723     (when (and gnus-fetch-old-headers
10724                (eq gnus-headers-retrieved-by 'nov))
10725       (if (eq gnus-fetch-old-headers 'invisible)
10726           (gnus-build-all-threads)
10727         (gnus-build-old-threads)))
10728     ;; Let the Gnus agent mark articles as read.
10729     (when gnus-agent
10730       (gnus-agent-get-undownloaded-list))
10731     ;; Remove list identifiers from subject
10732     (when gnus-list-identifiers
10733       (gnus-summary-remove-list-identifiers))
10734     ;; First and last article in this newsgroup.
10735     (when gnus-newsgroup-headers
10736       (setq gnus-newsgroup-begin
10737             (mail-header-number (car gnus-newsgroup-headers))
10738             gnus-newsgroup-end
10739             (mail-header-number
10740              (gnus-last-element gnus-newsgroup-headers))))
10741     (when gnus-use-scoring
10742       (gnus-possibly-score-headers))))
10743
10744 (defun gnus-summary-insert-old-articles (&optional all)
10745   "Insert all old articles in this group.
10746 If ALL is non-nil, already read articles become readable.
10747 If ALL is a number, fetch this number of articles."
10748   (interactive "P")
10749   (prog1
10750       (let ((old (mapcar 'car gnus-newsgroup-data))
10751             (i (car gnus-newsgroup-active))
10752             older len)
10753         (while (<= i (cdr gnus-newsgroup-active))
10754           (or (memq i old) (push i older))
10755           (incf i))
10756         (setq len (length older))
10757         (cond
10758          ((null older) nil)
10759          ((numberp all)
10760           (if (< all len)
10761               (setq older (subseq older 0 all))))
10762          (all nil)
10763          (t
10764           (if (and (numberp gnus-large-newsgroup)
10765                    (> len gnus-large-newsgroup))
10766               (let ((input
10767                      (read-string
10768                       (format
10769                        "How many articles from %s (default %d): "
10770                        (gnus-limit-string
10771                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10772                        len))))
10773                 (unless (string-match "^[ \t]*$" input)
10774                   (setq all (string-to-number input))
10775                   (if (< all len)
10776                       (setq older (subseq older 0 all))))))))
10777         (if (not older)
10778             (message "No old news.")
10779           (gnus-summary-insert-articles older)
10780           (gnus-summary-limit (gnus-union older old))))
10781     (gnus-summary-position-point)))
10782
10783 (defun gnus-summary-insert-new-articles ()
10784   "Insert all new articles in this group."
10785   (interactive)
10786   (prog1
10787       (let ((old (mapcar 'car gnus-newsgroup-data))
10788             (old-active gnus-newsgroup-active)
10789             (nnmail-fetched-sources (list t))
10790             i new)
10791         (setq gnus-newsgroup-active
10792               (gnus-activate-group gnus-newsgroup-name 'scan))
10793         (setq i (1+ (cdr old-active)))
10794         (while (<= i (cdr gnus-newsgroup-active))
10795           (push i new)
10796           (incf i))
10797         (if (not new)
10798             (message "No gnus is bad news.")
10799           (setq new (nreverse new))
10800           (gnus-summary-insert-articles new)
10801           (setq gnus-newsgroup-unreads
10802                 (append gnus-newsgroup-unreads new))
10803           (gnus-summary-limit (gnus-union old new))))
10804     (gnus-summary-position-point)))
10805
10806 (gnus-summary-make-all-marking-commands)
10807
10808 (gnus-ems-redefine)
10809
10810 (provide 'gnus-sum)
10811
10812 (run-hooks 'gnus-sum-load-hook)
10813
10814 ;;; gnus-sum.el ends here