* gnus-art.el (article-display-x-face): Insert From:.
[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
576 General format specifiers can also be used.  
577 See (gnus)Formatting Variables."
578   :link '(custom-manual "(gnus)Formatting Variables")
579   :group 'gnus-threading
580   :type 'string)
581
582 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
583   "*The format specification for the summary mode line.
584 It works along the same lines as a normal formatting string,
585 with some simple extensions:
586
587 %G  Group name
588 %p  Unprefixed group name
589 %A  Current article number
590 %z  Current article score
591 %V  Gnus version
592 %U  Number of unread articles in the group
593 %e  Number of unselected articles in the group
594 %Z  A string with unread/unselected article counts
595 %g  Shortish group name
596 %S  Subject of the current article
597 %u  User-defined spec
598 %s  Current score file name
599 %d  Number of dormant articles
600 %r  Number of articles that have been marked as read in this session
601 %E  Number of articles expunged by the score files"
602   :group 'gnus-summary-format
603   :type 'string)
604
605 (defcustom gnus-list-identifiers nil
606   "Regexp that matches list identifiers to be removed from subject.
607 This can also be a list of regexps."
608   :version "21.1"
609   :group 'gnus-summary-format
610   :group 'gnus-article-hiding
611   :type '(choice (const :tag "none" nil)
612                  (regexp :value ".*")
613                  (repeat :value (".*") regexp)))
614
615 (defcustom gnus-summary-mark-below 0
616   "*Mark all articles with a score below this variable as read.
617 This variable is local to each summary buffer and usually set by the
618 score file."
619   :group 'gnus-score-default
620   :type 'integer)
621
622 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
623   "*List of functions used for sorting articles in the summary buffer.
624
625 Each function takes two articles and returns non-nil if the first
626 article should be sorted before the other.  If you use more than one
627 function, the primary sort function should be the last.  You should
628 probably always include `gnus-article-sort-by-number' in the list of
629 sorting functions -- preferably first.  Also note that sorting by date
630 is often much slower than sorting by number, and the sorting order is
631 very similar.  (Sorting by date means sorting by the time the message
632 was sent, sorting by number means sorting by arrival time.)
633
634 Ready-made functions include `gnus-article-sort-by-number',
635 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
636 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
637
638 When threading is turned on, the variable `gnus-thread-sort-functions'
639 controls how articles are sorted."
640   :group 'gnus-summary-sort
641   :type '(repeat (choice (function-item gnus-article-sort-by-number)
642                          (function-item gnus-article-sort-by-author)
643                          (function-item gnus-article-sort-by-subject)
644                          (function-item gnus-article-sort-by-date)
645                          (function-item gnus-article-sort-by-score)
646                          (function :tag "other"))))
647
648 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
649   "*List of functions used for sorting threads in the summary buffer.
650 By default, threads are sorted by article number.
651
652 Each function takes two threads and returns non-nil if the first
653 thread should be sorted before the other.  If you use more than one
654 function, the primary sort function should be the last.  You should
655 probably always include `gnus-thread-sort-by-number' in the list of
656 sorting functions -- preferably first.  Also note that sorting by date
657 is often much slower than sorting by number, and the sorting order is
658 very similar.  (Sorting by date means sorting by the time the message
659 was sent, sorting by number means sorting by arrival time.)
660
661 Ready-made functions include `gnus-thread-sort-by-number',
662 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
663 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
664 `gnus-thread-sort-by-most-recent-number',
665 `gnus-thread-sort-by-most-recent-date', and
666 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
667
668 When threading is turned off, the variable
669 `gnus-article-sort-functions' controls how articles are sorted."
670   :group 'gnus-summary-sort
671   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
672                          (function-item gnus-thread-sort-by-author)
673                          (function-item gnus-thread-sort-by-subject)
674                          (function-item gnus-thread-sort-by-date)
675                          (function-item gnus-thread-sort-by-score)
676                          (function-item gnus-thread-sort-by-total-score)
677                          (function :tag "other"))))
678
679 (defcustom gnus-thread-score-function '+
680   "*Function used for calculating the total score of a thread.
681
682 The function is called with the scores of the article and each
683 subthread and should then return the score of the thread.
684
685 Some functions you can use are `+', `max', or `min'."
686   :group 'gnus-summary-sort
687   :type 'function)
688
689 (defcustom gnus-summary-expunge-below nil
690   "All articles that have a score less than this variable will be expunged.
691 This variable is local to the summary buffers."
692   :group 'gnus-score-default
693   :type '(choice (const :tag "off" nil)
694                  integer))
695
696 (defcustom gnus-thread-expunge-below nil
697   "All threads that have a total score less than this variable will be expunged.
698 See `gnus-thread-score-function' for en explanation of what a
699 \"thread score\" is.
700
701 This variable is local to the summary buffers."
702   :group 'gnus-threading
703   :group 'gnus-score-default
704   :type '(choice (const :tag "off" nil)
705                  integer))
706
707 (defcustom gnus-summary-mode-hook nil
708   "*A hook for Gnus summary mode.
709 This hook is run before any variables are set in the summary buffer."
710   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
711   :group 'gnus-summary-various
712   :type 'hook)
713
714 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
715 (when (featurep 'xemacs)
716   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
717   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
718   (add-hook 'gnus-summary-mode-hook
719             'gnus-xmas-switch-horizontal-scrollbar-off))
720
721 (defcustom gnus-summary-menu-hook nil
722   "*Hook run after the creation of the summary mode menu."
723   :group 'gnus-summary-visual
724   :type 'hook)
725
726 (defcustom gnus-summary-exit-hook nil
727   "*A hook called on exit from the summary buffer.
728 It will be called with point in the group buffer."
729   :group 'gnus-summary-exit
730   :type 'hook)
731
732 (defcustom gnus-summary-prepare-hook nil
733   "*A hook called after the summary buffer has been generated.
734 If you want to modify the summary buffer, you can use this hook."
735   :group 'gnus-summary-various
736   :type 'hook)
737
738 (defcustom gnus-summary-prepared-hook nil
739   "*A hook called as the last thing after the summary buffer has been generated."
740   :group 'gnus-summary-various
741   :type 'hook)
742
743 (defcustom gnus-summary-generate-hook nil
744   "*A hook run just before generating the summary buffer.
745 This hook is commonly used to customize threading variables and the
746 like."
747   :group 'gnus-summary-various
748   :type 'hook)
749
750 (defcustom gnus-select-group-hook nil
751   "*A hook called when a newsgroup is selected.
752
753 If you'd like to simplify subjects like the
754 `gnus-summary-next-same-subject' command does, you can use the
755 following hook:
756
757  (add-hook gnus-select-group-hook
758            (lambda ()
759              (mapcar (lambda (header)
760                        (mail-header-set-subject
761                         header
762                         (gnus-simplify-subject
763                          (mail-header-subject header) 're-only)))
764                      gnus-newsgroup-headers)))"
765   :group 'gnus-group-select
766   :type 'hook)
767
768 (defcustom gnus-select-article-hook nil
769   "*A hook called when an article is selected."
770   :group 'gnus-summary-choose
771   :type 'hook)
772
773 (defcustom gnus-visual-mark-article-hook
774   (list 'gnus-highlight-selected-summary)
775   "*Hook run after selecting an article in the summary buffer.
776 It is meant to be used for highlighting the article in some way.  It
777 is not run if `gnus-visual' is nil."
778   :group 'gnus-summary-visual
779   :type 'hook)
780
781 (defcustom gnus-parse-headers-hook nil
782   "*A hook called before parsing the headers."
783   :group 'gnus-various
784   :type 'hook)
785
786 (defcustom gnus-exit-group-hook nil
787   "*A hook called when exiting summary mode.
788 This hook is not called from the non-updating exit commands like `Q'."
789   :group 'gnus-various
790   :type 'hook)
791
792 (defcustom gnus-summary-update-hook
793   (list 'gnus-summary-highlight-line)
794   "*A hook called when a summary line is changed.
795 The hook will not be called if `gnus-visual' is nil.
796
797 The default function `gnus-summary-highlight-line' will
798 highlight the line according to the `gnus-summary-highlight'
799 variable."
800   :group 'gnus-summary-visual
801   :type 'hook)
802
803 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
804   "*A hook called when an article is selected for the first time.
805 The hook is intended to mark an article as read (or unread)
806 automatically when it is selected."
807   :group 'gnus-summary-choose
808   :type 'hook)
809
810 (defcustom gnus-group-no-more-groups-hook nil
811   "*A hook run when returning to group mode having no more (unread) groups."
812   :group 'gnus-group-select
813   :type 'hook)
814
815 (defcustom gnus-ps-print-hook nil
816   "*A hook run before ps-printing something from Gnus."
817   :group 'gnus-summary
818   :type 'hook)
819
820 (defcustom gnus-summary-display-arrow
821   (and (fboundp 'display-graphic-p)
822        (display-graphic-p))
823   "*If non-nil, display an arrow highlighting the current article."
824   :version "21.1"
825   :group 'gnus-summary
826   :type 'boolean)
827
828 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
829   "Face used for highlighting the current article in the summary buffer."
830   :group 'gnus-summary-visual
831   :type 'face)
832
833 (defcustom gnus-summary-highlight
834   '(((= mark gnus-canceled-mark)
835      . gnus-summary-cancelled-face)
836     ((and (> score default-high)
837           (or (= mark gnus-dormant-mark)
838               (= mark gnus-ticked-mark)))
839      . gnus-summary-high-ticked-face)
840     ((and (< score default-low)
841           (or (= mark gnus-dormant-mark)
842               (= mark gnus-ticked-mark)))
843      . gnus-summary-low-ticked-face)
844     ((or (= mark gnus-dormant-mark)
845          (= mark gnus-ticked-mark))
846      . gnus-summary-normal-ticked-face)
847     ((and (> score default-high) (= mark gnus-ancient-mark))
848      . gnus-summary-high-ancient-face)
849     ((and (< score default-low) (= mark gnus-ancient-mark))
850      . gnus-summary-low-ancient-face)
851     ((= mark gnus-ancient-mark)
852      . gnus-summary-normal-ancient-face)
853     ((and (> score default-high) (= mark gnus-unread-mark))
854      . gnus-summary-high-unread-face)
855     ((and (< score default-low) (= mark gnus-unread-mark))
856      . gnus-summary-low-unread-face)
857     ((= mark gnus-unread-mark)
858      . gnus-summary-normal-unread-face)
859     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
860                                                   gnus-undownloaded-mark)))
861      . gnus-summary-high-unread-face)
862     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
863                                                  gnus-undownloaded-mark)))
864      . gnus-summary-low-unread-face)
865     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
866           (memq article gnus-newsgroup-unreads))
867      . gnus-summary-normal-unread-face)
868     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
869      . gnus-summary-normal-read-face)
870     ((> score default-high)
871      . gnus-summary-high-read-face)
872     ((< score default-low)
873      . gnus-summary-low-read-face)
874     (t
875      . gnus-summary-normal-read-face))
876   "*Controls the highlighting of summary buffer lines.
877
878 A list of (FORM . FACE) pairs.  When deciding how a a particular
879 summary line should be displayed, each form is evaluated.  The content
880 of the face field after the first true form is used.  You can change
881 how those summary lines are displayed, by editing the face field.
882
883 You can use the following variables in the FORM field.
884
885 score:        The article's score
886 default:      The default article score.
887 default-high: The default score for high scored articles.
888 default-low:  The default score for low scored articles.
889 below:        The score below which articles are automatically marked as read.
890 mark:         The articles mark."
891   :group 'gnus-summary-visual
892   :type '(repeat (cons (sexp :tag "Form" nil)
893                        face)))
894
895 (defcustom gnus-alter-header-function nil
896   "Function called to allow alteration of article header structures.
897 The function is called with one parameter, the article header vector,
898 which it may alter in any way.")
899
900 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
901   "Variable that says which function should be used to decode a string with encoded words.")
902
903 (defcustom gnus-extra-headers '(To Newsgroups)
904   "*Extra headers to parse."
905   :version "21.1"
906   :group 'gnus-summary
907   :type '(repeat symbol))
908
909 (defcustom gnus-ignored-from-addresses
910   (and user-mail-address (regexp-quote user-mail-address))
911   "*Regexp of From headers that may be suppressed in favor of To headers."
912   :version "21.1"
913   :group 'gnus-summary
914   :type 'regexp)
915
916 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
917   "List of charsets that should be ignored.
918 When these charsets are used in the \"charset\" parameter, the
919 default charset will be used instead."
920   :version "21.1"
921   :type '(repeat symbol)
922   :group 'gnus-charset)
923
924 (gnus-define-group-parameter
925  ignored-charsets
926  :type list
927  :function-document
928  "Return the ignored charsets of GROUP."
929  :variable gnus-group-ignored-charsets-alist
930  :variable-default
931  '(("alt\\.chinese\\.text" iso-8859-1))
932  :variable-document
933  "Alist of regexps (to match group names) and charsets that should be ignored.
934 When these charsets are used in the \"charset\" parameter, the
935 default charset will be used instead."
936  :variable-group gnus-charset
937  :variable-type '(repeat (cons (regexp :tag "Group")
938                                (repeat symbol)))
939  :parameter-type '(choice :tag "Ignored charsets"
940                           :value nil
941                           (repeat (symbol)))
942  :parameter-document       "\
943 List of charsets that should be ignored.
944
945 When these charsets are used in the \"charset\" parameter, the
946 default charset will be used instead.")
947
948 (defcustom gnus-group-highlight-words-alist nil
949   "Alist of group regexps and highlight regexps.
950 This variable uses the same syntax as `gnus-emphasis-alist'."
951   :version "21.1"
952   :type '(repeat (cons (regexp :tag "Group")
953                        (repeat (list (regexp :tag "Highlight regexp")
954                                      (number :tag "Group for entire word" 0)
955                                      (number :tag "Group for displayed part" 0)
956                                      (symbol :tag "Face"
957                                              gnus-emphasis-highlight-words)))))
958   :group 'gnus-summary-visual)
959
960 (defcustom gnus-summary-show-article-charset-alist
961   nil
962   "Alist of number and charset.
963 The article will be shown with the charset corresponding to the
964 numbered argument.
965 For example: ((1 . cn-gb-2312) (2 . big5))."
966   :version "21.1"
967   :type '(repeat (cons (number :tag "Argument" 1)
968                        (symbol :tag "Charset")))
969   :group 'gnus-charset)
970
971 (defcustom gnus-preserve-marks t
972   "Whether marks are preserved when moving, copying and respooling messages."
973   :version "21.1"
974   :type 'boolean
975   :group 'gnus-summary-marks)
976
977 (defcustom gnus-alter-articles-to-read-function nil
978   "Function to be called to alter the list of articles to be selected."
979   :type '(choice (const nil) function)
980   :group 'gnus-summary)
981
982 (defcustom gnus-orphan-score nil
983   "*All orphans get this score added.  Set in the score file."
984   :group 'gnus-score-default
985   :type '(choice (const nil)
986                  integer))
987
988 (defcustom gnus-summary-save-parts-default-mime "image/.*"
989   "*A regexp to match MIME parts when saving multiple parts of a message
990 with gnus-summary-save-parts (X m). This regexp will be used by default
991 when prompting the user for which type of files to save."
992   :group 'gnus-summary
993   :type 'regexp)
994
995
996 (defcustom gnus-summary-save-parts-default-mime "image/.*"
997   "*A regexp to match MIME parts when saving multiple parts of a message
998 with gnus-summary-save-parts (X m). This regexp will be used by default
999 when prompting the user for which type of files to save."
1000   :group 'gnus-summary
1001   :type 'regexp)
1002
1003 (defcustom gnus-read-all-available-headers nil
1004   "Whether Gnus should parse all headers made available to it.
1005 This is mostly relevant for slow backends where the user may
1006 wish to widen the summary buffer to include all headers
1007 that were fetched.  Say, for nnultimate groups."
1008   :group 'gnus-summary
1009   :type '(choice boolean regexp))
1010
1011 (defcustom gnus-summary-muttprint-program "muttprint"
1012   "Command (and optional arguments) used to run Muttprint."
1013   :group 'gnus-summary
1014   :type 'string)
1015
1016 ;;; Internal variables
1017
1018 (defvar gnus-summary-display-cache nil)
1019 (defvar gnus-article-mime-handles nil)
1020 (defvar gnus-article-decoded-p nil)
1021 (defvar gnus-article-charset nil)
1022 (defvar gnus-article-ignored-charsets nil)
1023 (defvar gnus-scores-exclude-files nil)
1024 (defvar gnus-page-broken nil)
1025 (defvar gnus-inhibit-mime-unbuttonizing nil)
1026
1027 (defvar gnus-original-article nil)
1028 (defvar gnus-article-internal-prepare-hook nil)
1029 (defvar gnus-newsgroup-process-stack nil)
1030
1031 (defvar gnus-thread-indent-array nil)
1032 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1033 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1034   "Function called to sort the articles within a thread after it has been gathered together.")
1035
1036 (defvar gnus-summary-save-parts-type-history nil)
1037 (defvar gnus-summary-save-parts-last-directory nil)
1038
1039 (defvar gnus-summary-save-parts-type-history nil)
1040 (defvar gnus-summary-save-parts-last-directory nil)
1041
1042 ;; Avoid highlighting in kill files.
1043 (defvar gnus-summary-inhibit-highlight nil)
1044 (defvar gnus-newsgroup-selected-overlay nil)
1045 (defvar gnus-inhibit-limiting nil)
1046 (defvar gnus-newsgroup-adaptive-score-file nil)
1047 (defvar gnus-current-score-file nil)
1048 (defvar gnus-current-move-group nil)
1049 (defvar gnus-current-copy-group nil)
1050 (defvar gnus-current-crosspost-group nil)
1051 (defvar gnus-newsgroup-display nil)
1052
1053 (defvar gnus-newsgroup-dependencies nil)
1054 (defvar gnus-newsgroup-adaptive nil)
1055 (defvar gnus-summary-display-article-function nil)
1056 (defvar gnus-summary-highlight-line-function nil
1057   "Function called after highlighting a summary line.")
1058
1059 (defvar gnus-summary-line-format-alist
1060   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1061     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1062     (?s gnus-tmp-subject-or-nil ?s)
1063     (?n gnus-tmp-name ?s)
1064     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1065         ?s)
1066     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1067             gnus-tmp-from) ?s)
1068     (?F gnus-tmp-from ?s)
1069     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1070     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1071     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1072     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1073     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1074     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1075     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1076     (?L gnus-tmp-lines ?s)
1077     (?I gnus-tmp-indentation ?s)
1078     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1079     (?R gnus-tmp-replied ?c)
1080     (?\[ gnus-tmp-opening-bracket ?c)
1081     (?\] gnus-tmp-closing-bracket ?c)
1082     (?\> (make-string gnus-tmp-level ? ) ?s)
1083     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1084     (?i gnus-tmp-score ?d)
1085     (?z gnus-tmp-score-char ?c)
1086     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1087     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1088     (?U gnus-tmp-unread ?c)
1089     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1090         ?s)
1091     (?t (gnus-summary-number-of-articles-in-thread
1092          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1093         ?d)
1094     (?e (gnus-summary-number-of-articles-in-thread
1095          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1096         ?c)
1097     (?u gnus-tmp-user-defined ?s)
1098     (?P (gnus-pick-line-number) ?d)
1099     (?B gnus-tmp-thread-tree-header-string ?s)
1100     (user-date (gnus-user-date
1101                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1102   "An alist of format specifications that can appear in summary lines.
1103 These are paired with what variables they correspond with, along with
1104 the type of the variable (string, integer, character, etc).")
1105
1106 (defvar gnus-summary-dummy-line-format-alist
1107   `((?S gnus-tmp-subject ?s)
1108     (?N gnus-tmp-number ?d)
1109     (?u gnus-tmp-user-defined ?s)))
1110
1111 (defvar gnus-summary-mode-line-format-alist
1112   `((?G gnus-tmp-group-name ?s)
1113     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1114     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1115     (?A gnus-tmp-article-number ?d)
1116     (?Z gnus-tmp-unread-and-unselected ?s)
1117     (?V gnus-version ?s)
1118     (?U gnus-tmp-unread-and-unticked ?d)
1119     (?S gnus-tmp-subject ?s)
1120     (?e gnus-tmp-unselected ?d)
1121     (?u gnus-tmp-user-defined ?s)
1122     (?d (length gnus-newsgroup-dormant) ?d)
1123     (?t (length gnus-newsgroup-marked) ?d)
1124     (?r (length gnus-newsgroup-reads) ?d)
1125     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1126     (?E gnus-newsgroup-expunged-tally ?d)
1127     (?s (gnus-current-score-file-nondirectory) ?s)))
1128
1129 (defvar gnus-last-search-regexp nil
1130   "Default regexp for article search command.")
1131
1132 (defvar gnus-last-shell-command nil
1133   "Default shell command on article.")
1134
1135 (defvar gnus-newsgroup-begin nil)
1136 (defvar gnus-newsgroup-end nil)
1137 (defvar gnus-newsgroup-last-rmail nil)
1138 (defvar gnus-newsgroup-last-mail nil)
1139 (defvar gnus-newsgroup-last-folder nil)
1140 (defvar gnus-newsgroup-last-file nil)
1141 (defvar gnus-newsgroup-auto-expire nil)
1142 (defvar gnus-newsgroup-active nil)
1143
1144 (defvar gnus-newsgroup-data nil)
1145 (defvar gnus-newsgroup-data-reverse nil)
1146 (defvar gnus-newsgroup-limit nil)
1147 (defvar gnus-newsgroup-limits nil)
1148
1149 (defvar gnus-newsgroup-unreads nil
1150   "List of unread articles in the current newsgroup.")
1151
1152 (defvar gnus-newsgroup-unselected nil
1153   "List of unselected unread articles in the current newsgroup.")
1154
1155 (defvar gnus-newsgroup-reads nil
1156   "Alist of read articles and article marks in the current newsgroup.")
1157
1158 (defvar gnus-newsgroup-expunged-tally nil)
1159
1160 (defvar gnus-newsgroup-marked nil
1161   "List of ticked articles in the current newsgroup (a subset of unread art).")
1162
1163 (defvar gnus-newsgroup-killed nil
1164   "List of ranges of articles that have been through the scoring process.")
1165
1166 (defvar gnus-newsgroup-cached nil
1167   "List of articles that come from the article cache.")
1168
1169 (defvar gnus-newsgroup-saved nil
1170   "List of articles that have been saved.")
1171
1172 (defvar gnus-newsgroup-kill-headers nil)
1173
1174 (defvar gnus-newsgroup-replied nil
1175   "List of articles that have been replied to in the current newsgroup.")
1176
1177 (defvar gnus-newsgroup-forwarded nil
1178   "List of articles that have been forwarded in the current newsgroup.")
1179
1180 (defvar gnus-newsgroup-recent nil
1181   "List of articles that have are recent in the current newsgroup.")
1182
1183 (defvar gnus-newsgroup-expirable nil
1184   "List of articles in the current newsgroup that can be expired.")
1185
1186 (defvar gnus-newsgroup-processable nil
1187   "List of articles in the current newsgroup that can be processed.")
1188
1189 (defvar gnus-newsgroup-downloadable nil
1190   "List of articles in the current newsgroup that can be processed.")
1191
1192 (defvar gnus-newsgroup-undownloaded nil
1193   "List of articles in the current newsgroup that haven't been downloaded..")
1194
1195 (defvar gnus-newsgroup-unsendable nil
1196   "List of articles in the current newsgroup that won't be sent.")
1197
1198 (defvar gnus-newsgroup-bookmarks nil
1199   "List of articles in the current newsgroup that have bookmarks.")
1200
1201 (defvar gnus-newsgroup-dormant nil
1202   "List of dormant articles in the current newsgroup.")
1203
1204 (defvar gnus-newsgroup-unseen nil
1205   "List of unseen articles in the current newsgroup.")
1206
1207 (defvar gnus-newsgroup-seen nil
1208   "Range of seen articles in the current newsgroup.")
1209
1210 (defvar gnus-newsgroup-articles nil
1211   "List of articles in the current newsgroup.")
1212
1213 (defvar gnus-newsgroup-scored nil
1214   "List of scored articles in the current newsgroup.")
1215
1216 (defvar gnus-newsgroup-headers nil
1217   "List of article headers in the current newsgroup.")
1218
1219 (defvar gnus-newsgroup-threads nil)
1220
1221 (defvar gnus-newsgroup-prepared nil
1222   "Whether the current group has been prepared properly.")
1223
1224 (defvar gnus-newsgroup-ancient nil
1225   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1226
1227 (defvar gnus-newsgroup-sparse nil)
1228
1229 (defvar gnus-current-article nil)
1230 (defvar gnus-article-current nil)
1231 (defvar gnus-current-headers nil)
1232 (defvar gnus-have-all-headers nil)
1233 (defvar gnus-last-article nil)
1234 (defvar gnus-newsgroup-history nil)
1235 (defvar gnus-newsgroup-charset nil)
1236 (defvar gnus-newsgroup-ephemeral-charset nil)
1237 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1238
1239 (defvar gnus-article-before-search nil)
1240
1241 (defconst gnus-summary-local-variables
1242   '(gnus-newsgroup-name
1243     gnus-newsgroup-begin gnus-newsgroup-end
1244     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1245     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1246     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1247     gnus-newsgroup-unselected gnus-newsgroup-marked
1248     gnus-newsgroup-reads gnus-newsgroup-saved
1249     gnus-newsgroup-replied gnus-newsgroup-forwarded
1250     gnus-newsgroup-recent
1251     gnus-newsgroup-expirable
1252     gnus-newsgroup-processable gnus-newsgroup-killed
1253     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1254     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1255     gnus-newsgroup-seen gnus-newsgroup-articles
1256     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1257     gnus-newsgroup-headers gnus-newsgroup-threads
1258     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1259     gnus-current-article gnus-current-headers gnus-have-all-headers
1260     gnus-last-article gnus-article-internal-prepare-hook
1261     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1262     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1263     gnus-thread-expunge-below
1264     gnus-score-alist gnus-current-score-file
1265     (gnus-summary-expunge-below . global)
1266     (gnus-summary-mark-below . global)
1267     (gnus-orphan-score . global)
1268     gnus-newsgroup-active gnus-scores-exclude-files
1269     gnus-newsgroup-history gnus-newsgroup-ancient
1270     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1271     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1272     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1273     (gnus-newsgroup-expunged-tally . 0)
1274     gnus-cache-removable-articles gnus-newsgroup-cached
1275     gnus-newsgroup-data gnus-newsgroup-data-reverse
1276     gnus-newsgroup-limit gnus-newsgroup-limits
1277     gnus-newsgroup-charset gnus-newsgroup-display)
1278   "Variables that are buffer-local to the summary buffers.")
1279
1280 (defvar gnus-newsgroup-variables nil
1281   "A list of variables that have separate values in different newsgroups.
1282 A list of newsgroup (summary buffer) local variables, or cons of
1283 variables and their default values (when the default values are not
1284 nil), that should be made global while the summary buffer is active.
1285 These variables can be used to set variables in the group parameters
1286 while still allowing them to affect operations done in other
1287 buffers. For example:
1288
1289 \(setq gnus-newsgroup-variables
1290      '(message-use-followup-to
1291        (gnus-visible-headers .
1292          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1293 ")
1294
1295 ;; Byte-compiler warning.
1296 (eval-when-compile (defvar gnus-article-mode-map))
1297
1298 ;; MIME stuff.
1299
1300 (defvar gnus-decode-encoded-word-methods
1301   '(mail-decode-encoded-word-string)
1302   "List of methods used to decode encoded words.
1303
1304 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1305 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1306 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1307 whose names match REGEXP.
1308
1309 For example:
1310 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1311  mail-decode-encoded-word-string
1312  (\"chinese\" . rfc1843-decode-string))")
1313
1314 (defvar gnus-decode-encoded-word-methods-cache nil)
1315
1316 (defun gnus-multi-decode-encoded-word-string (string)
1317   "Apply the functions from `gnus-encoded-word-methods' that match."
1318   (unless (and gnus-decode-encoded-word-methods-cache
1319                (eq gnus-newsgroup-name
1320                    (car gnus-decode-encoded-word-methods-cache)))
1321     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1322     (mapcar (lambda (x)
1323               (if (symbolp x)
1324                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1325                 (if (and gnus-newsgroup-name
1326                          (string-match (car x) gnus-newsgroup-name))
1327                     (nconc gnus-decode-encoded-word-methods-cache
1328                            (list (cdr x))))))
1329             gnus-decode-encoded-word-methods))
1330   (let ((xlist gnus-decode-encoded-word-methods-cache))
1331     (pop xlist)
1332     (while xlist
1333       (setq string (funcall (pop xlist) string))))
1334   string)
1335
1336 ;; Subject simplification.
1337
1338 (defun gnus-simplify-whitespace (str)
1339   "Remove excessive whitespace from STR."
1340   (let ((mystr str))
1341     ;; Multiple spaces.
1342     (while (string-match "[ \t][ \t]+" mystr)
1343       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1344                           " "
1345                           (substring mystr (match-end 0)))))
1346     ;; Leading spaces.
1347     (when (string-match "^[ \t]+" mystr)
1348       (setq mystr (substring mystr (match-end 0))))
1349     ;; Trailing spaces.
1350     (when (string-match "[ \t]+$" mystr)
1351       (setq mystr (substring mystr 0 (match-beginning 0))))
1352     mystr))
1353
1354 (defsubst gnus-simplify-subject-re (subject)
1355   "Remove \"Re:\" from subject lines."
1356   (if (string-match message-subject-re-regexp subject)
1357       (substring subject (match-end 0))
1358     subject))
1359
1360 (defun gnus-simplify-subject (subject &optional re-only)
1361   "Remove `Re:' and words in parentheses.
1362 If RE-ONLY is non-nil, strip leading `Re:'s only."
1363   (let ((case-fold-search t))           ;Ignore case.
1364     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1365     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1366       (setq subject (substring subject (match-end 0))))
1367     ;; Remove uninteresting prefixes.
1368     (when (and (not re-only)
1369                gnus-simplify-ignored-prefixes
1370                (string-match gnus-simplify-ignored-prefixes subject))
1371       (setq subject (substring subject (match-end 0))))
1372     ;; Remove words in parentheses from end.
1373     (unless re-only
1374       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1375         (setq subject (substring subject 0 (match-beginning 0)))))
1376     ;; Return subject string.
1377     subject))
1378
1379 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1380 ;; all whitespace.
1381 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1382   (goto-char (point-min))
1383   (while (re-search-forward regexp nil t)
1384     (replace-match (or newtext ""))))
1385
1386 (defun gnus-simplify-buffer-fuzzy ()
1387   "Simplify string in the buffer fuzzily.
1388 The string in the accessible portion of the current buffer is simplified.
1389 It is assumed to be a single-line subject.
1390 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1391 matter is removed.  Additional things can be deleted by setting
1392 `gnus-simplify-subject-fuzzy-regexp'."
1393   (let ((case-fold-search t)
1394         (modified-tick))
1395     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1396
1397     (while (not (eq modified-tick (buffer-modified-tick)))
1398       (setq modified-tick (buffer-modified-tick))
1399       (cond
1400        ((listp gnus-simplify-subject-fuzzy-regexp)
1401         (mapcar 'gnus-simplify-buffer-fuzzy-step
1402                 gnus-simplify-subject-fuzzy-regexp))
1403        (gnus-simplify-subject-fuzzy-regexp
1404         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1405       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1406       (gnus-simplify-buffer-fuzzy-step
1407        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1408       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1409
1410     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1411     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1412     (gnus-simplify-buffer-fuzzy-step " $")
1413     (gnus-simplify-buffer-fuzzy-step "^ +")))
1414
1415 (defun gnus-simplify-subject-fuzzy (subject)
1416   "Simplify a subject string fuzzily.
1417 See `gnus-simplify-buffer-fuzzy' for details."
1418   (save-excursion
1419     (gnus-set-work-buffer)
1420     (let ((case-fold-search t))
1421       ;; Remove uninteresting prefixes.
1422       (when (and gnus-simplify-ignored-prefixes
1423                  (string-match gnus-simplify-ignored-prefixes subject))
1424         (setq subject (substring subject (match-end 0))))
1425       (insert subject)
1426       (inline (gnus-simplify-buffer-fuzzy))
1427       (buffer-string))))
1428
1429 (defsubst gnus-simplify-subject-fully (subject)
1430   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1431   (cond
1432    (gnus-simplify-subject-functions
1433     (gnus-map-function gnus-simplify-subject-functions subject))
1434    ((null gnus-summary-gather-subject-limit)
1435     (gnus-simplify-subject-re subject))
1436    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1437     (gnus-simplify-subject-fuzzy subject))
1438    ((numberp gnus-summary-gather-subject-limit)
1439     (gnus-limit-string (gnus-simplify-subject-re subject)
1440                        gnus-summary-gather-subject-limit))
1441    (t
1442     subject)))
1443
1444 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1445   "Check whether two subjects are equal.
1446 If optional argument simple-first is t, first argument is already
1447 simplified."
1448   (cond
1449    ((null simple-first)
1450     (equal (gnus-simplify-subject-fully s1)
1451            (gnus-simplify-subject-fully s2)))
1452    (t
1453     (equal s1
1454            (gnus-simplify-subject-fully s2)))))
1455
1456 (defun gnus-summary-bubble-group ()
1457   "Increase the score of the current group.
1458 This is a handy function to add to `gnus-summary-exit-hook' to
1459 increase the score of each group you read."
1460   (gnus-group-add-score gnus-newsgroup-name))
1461
1462 \f
1463 ;;;
1464 ;;; Gnus summary mode
1465 ;;;
1466
1467 (put 'gnus-summary-mode 'mode-class 'special)
1468
1469 (defvar gnus-article-commands-menu)
1470
1471 (when t
1472   ;; Non-orthogonal keys
1473
1474   (gnus-define-keys gnus-summary-mode-map
1475     " " gnus-summary-next-page
1476     "\177" gnus-summary-prev-page
1477     [delete] gnus-summary-prev-page
1478     [backspace] gnus-summary-prev-page
1479     "\r" gnus-summary-scroll-up
1480     "\M-\r" gnus-summary-scroll-down
1481     "n" gnus-summary-next-unread-article
1482     "p" gnus-summary-prev-unread-article
1483     "N" gnus-summary-next-article
1484     "P" gnus-summary-prev-article
1485     "\M-\C-n" gnus-summary-next-same-subject
1486     "\M-\C-p" gnus-summary-prev-same-subject
1487     "\M-n" gnus-summary-next-unread-subject
1488     "\M-p" gnus-summary-prev-unread-subject
1489     "." gnus-summary-first-unread-article
1490     "," gnus-summary-best-unread-article
1491     "\M-s" gnus-summary-search-article-forward
1492     "\M-r" gnus-summary-search-article-backward
1493     "<" gnus-summary-beginning-of-article
1494     ">" gnus-summary-end-of-article
1495     "j" gnus-summary-goto-article
1496     "^" gnus-summary-refer-parent-article
1497     "\M-^" gnus-summary-refer-article
1498     "u" gnus-summary-tick-article-forward
1499     "!" gnus-summary-tick-article-forward
1500     "U" gnus-summary-tick-article-backward
1501     "d" gnus-summary-mark-as-read-forward
1502     "D" gnus-summary-mark-as-read-backward
1503     "E" gnus-summary-mark-as-expirable
1504     "\M-u" gnus-summary-clear-mark-forward
1505     "\M-U" gnus-summary-clear-mark-backward
1506     "k" gnus-summary-kill-same-subject-and-select
1507     "\C-k" gnus-summary-kill-same-subject
1508     "\M-\C-k" gnus-summary-kill-thread
1509     "\M-\C-l" gnus-summary-lower-thread
1510     "e" gnus-summary-edit-article
1511     "#" gnus-summary-mark-as-processable
1512     "\M-#" gnus-summary-unmark-as-processable
1513     "\M-\C-t" gnus-summary-toggle-threads
1514     "\M-\C-s" gnus-summary-show-thread
1515     "\M-\C-h" gnus-summary-hide-thread
1516     "\M-\C-f" gnus-summary-next-thread
1517     "\M-\C-b" gnus-summary-prev-thread
1518     [(meta down)] gnus-summary-next-thread
1519     [(meta up)] gnus-summary-prev-thread
1520     "\M-\C-u" gnus-summary-up-thread
1521     "\M-\C-d" gnus-summary-down-thread
1522     "&" gnus-summary-execute-command
1523     "c" gnus-summary-catchup-and-exit
1524     "\C-w" gnus-summary-mark-region-as-read
1525     "\C-t" gnus-summary-toggle-truncation
1526     "?" gnus-summary-mark-as-dormant
1527     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1528     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1529     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1530     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1531     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1532     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1533     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1534     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1535     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1536     "=" gnus-summary-expand-window
1537     "\C-x\C-s" gnus-summary-reselect-current-group
1538     "\M-g" gnus-summary-rescan-group
1539     "w" gnus-summary-stop-page-breaking
1540     "\C-c\C-r" gnus-summary-caesar-message
1541     "f" gnus-summary-followup
1542     "F" gnus-summary-followup-with-original
1543     "C" gnus-summary-cancel-article
1544     "r" gnus-summary-reply
1545     "R" gnus-summary-reply-with-original
1546     "\C-c\C-f" gnus-summary-mail-forward
1547     "o" gnus-summary-save-article
1548     "\C-o" gnus-summary-save-article-mail
1549     "|" gnus-summary-pipe-output
1550     "\M-k" gnus-summary-edit-local-kill
1551     "\M-K" gnus-summary-edit-global-kill
1552     ;; "V" gnus-version
1553     "\C-c\C-d" gnus-summary-describe-group
1554     "q" gnus-summary-exit
1555     "Q" gnus-summary-exit-no-update
1556     "\C-c\C-i" gnus-info-find-node
1557     gnus-mouse-2 gnus-mouse-pick-article
1558     "m" gnus-summary-mail-other-window
1559     "a" gnus-summary-post-news
1560     "i" gnus-summary-news-other-window
1561     "x" gnus-summary-limit-to-unread
1562     "s" gnus-summary-isearch-article
1563     "t" gnus-summary-toggle-header
1564     "g" gnus-summary-show-article
1565     "l" gnus-summary-goto-last-article
1566     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1567     "\C-d" gnus-summary-enter-digest-group
1568     "\M-\C-d" gnus-summary-read-document
1569     "\M-\C-e" gnus-summary-edit-parameters
1570     "\M-\C-a" gnus-summary-customize-parameters
1571     "\C-c\C-b" gnus-bug
1572     "*" gnus-cache-enter-article
1573     "\M-*" gnus-cache-remove-article
1574     "\M-&" gnus-summary-universal-argument
1575     "\C-l" gnus-recenter
1576     "I" gnus-summary-increase-score
1577     "L" gnus-summary-lower-score
1578     "\M-i" gnus-symbolic-argument
1579     "h" gnus-summary-select-article-buffer
1580
1581     "b" gnus-article-view-part
1582     "\M-t" gnus-summary-toggle-display-buttonized
1583
1584     "V" gnus-summary-score-map
1585     "X" gnus-uu-extract-map
1586     "S" gnus-summary-send-map)
1587
1588   ;; Sort of orthogonal keymap
1589   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1590     "t" gnus-summary-tick-article-forward
1591     "!" gnus-summary-tick-article-forward
1592     "d" gnus-summary-mark-as-read-forward
1593     "r" gnus-summary-mark-as-read-forward
1594     "c" gnus-summary-clear-mark-forward
1595     " " gnus-summary-clear-mark-forward
1596     "e" gnus-summary-mark-as-expirable
1597     "x" gnus-summary-mark-as-expirable
1598     "?" gnus-summary-mark-as-dormant
1599     "b" gnus-summary-set-bookmark
1600     "B" gnus-summary-remove-bookmark
1601     "#" gnus-summary-mark-as-processable
1602     "\M-#" gnus-summary-unmark-as-processable
1603     "S" gnus-summary-limit-include-expunged
1604     "C" gnus-summary-catchup
1605     "H" gnus-summary-catchup-to-here
1606     "h" gnus-summary-catchup-from-here
1607     "\C-c" gnus-summary-catchup-all
1608     "k" gnus-summary-kill-same-subject-and-select
1609     "K" gnus-summary-kill-same-subject
1610     "P" gnus-uu-mark-map)
1611
1612   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1613     "c" gnus-summary-clear-above
1614     "u" gnus-summary-tick-above
1615     "m" gnus-summary-mark-above
1616     "k" gnus-summary-kill-below)
1617
1618   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1619     "/" gnus-summary-limit-to-subject
1620     "n" gnus-summary-limit-to-articles
1621     "w" gnus-summary-pop-limit
1622     "s" gnus-summary-limit-to-subject
1623     "a" gnus-summary-limit-to-author
1624     "u" gnus-summary-limit-to-unread
1625     "m" gnus-summary-limit-to-marks
1626     "M" gnus-summary-limit-exclude-marks
1627     "v" gnus-summary-limit-to-score
1628     "*" gnus-summary-limit-include-cached
1629     "D" gnus-summary-limit-include-dormant
1630     "T" gnus-summary-limit-include-thread
1631     "d" gnus-summary-limit-exclude-dormant
1632     "t" gnus-summary-limit-to-age
1633     "x" gnus-summary-limit-to-extra
1634     "p" gnus-summary-limit-to-display-predicate
1635     "E" gnus-summary-limit-include-expunged
1636     "c" gnus-summary-limit-exclude-childless-dormant
1637     "C" gnus-summary-limit-mark-excluded-as-read
1638     "o" gnus-summary-insert-old-articles
1639     "N" gnus-summary-insert-new-articles)
1640
1641   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1642     "n" gnus-summary-next-unread-article
1643     "p" gnus-summary-prev-unread-article
1644     "N" gnus-summary-next-article
1645     "P" gnus-summary-prev-article
1646     "\C-n" gnus-summary-next-same-subject
1647     "\C-p" gnus-summary-prev-same-subject
1648     "\M-n" gnus-summary-next-unread-subject
1649     "\M-p" gnus-summary-prev-unread-subject
1650     "f" gnus-summary-first-unread-article
1651     "b" gnus-summary-best-unread-article
1652     "j" gnus-summary-goto-article
1653     "g" gnus-summary-goto-subject
1654     "l" gnus-summary-goto-last-article
1655     "o" gnus-summary-pop-article)
1656
1657   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1658     "k" gnus-summary-kill-thread
1659     "l" gnus-summary-lower-thread
1660     "i" gnus-summary-raise-thread
1661     "T" gnus-summary-toggle-threads
1662     "t" gnus-summary-rethread-current
1663     "^" gnus-summary-reparent-thread
1664     "s" gnus-summary-show-thread
1665     "S" gnus-summary-show-all-threads
1666     "h" gnus-summary-hide-thread
1667     "H" gnus-summary-hide-all-threads
1668     "n" gnus-summary-next-thread
1669     "p" gnus-summary-prev-thread
1670     "u" gnus-summary-up-thread
1671     "o" gnus-summary-top-thread
1672     "d" gnus-summary-down-thread
1673     "#" gnus-uu-mark-thread
1674     "\M-#" gnus-uu-unmark-thread)
1675
1676   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1677     "g" gnus-summary-prepare
1678     "c" gnus-summary-insert-cached-articles)
1679
1680   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1681     "c" gnus-summary-catchup-and-exit
1682     "C" gnus-summary-catchup-all-and-exit
1683     "E" gnus-summary-exit-no-update
1684     "Q" gnus-summary-exit
1685     "Z" gnus-summary-exit
1686     "n" gnus-summary-catchup-and-goto-next-group
1687     "R" gnus-summary-reselect-current-group
1688     "G" gnus-summary-rescan-group
1689     "N" gnus-summary-next-group
1690     "s" gnus-summary-save-newsrc
1691     "P" gnus-summary-prev-group)
1692
1693   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1694     " " gnus-summary-next-page
1695     "n" gnus-summary-next-page
1696     "\177" gnus-summary-prev-page
1697     [delete] gnus-summary-prev-page
1698     "p" gnus-summary-prev-page
1699     "\r" gnus-summary-scroll-up
1700     "\M-\r" gnus-summary-scroll-down
1701     "<" gnus-summary-beginning-of-article
1702     ">" gnus-summary-end-of-article
1703     "b" gnus-summary-beginning-of-article
1704     "e" gnus-summary-end-of-article
1705     "^" gnus-summary-refer-parent-article
1706     "r" gnus-summary-refer-parent-article
1707     "D" gnus-summary-enter-digest-group
1708     "R" gnus-summary-refer-references
1709     "T" gnus-summary-refer-thread
1710     "g" gnus-summary-show-article
1711     "s" gnus-summary-isearch-article
1712     "P" gnus-summary-print-article
1713     "M" gnus-mailing-list-insinuate
1714     "t" gnus-article-babel)
1715
1716   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1717     "b" gnus-article-add-buttons
1718     "B" gnus-article-add-buttons-to-head
1719     "o" gnus-article-treat-overstrike
1720     "e" gnus-article-emphasize
1721     "w" gnus-article-fill-cited-article
1722     "Q" gnus-article-fill-long-lines
1723     "C" gnus-article-capitalize-sentences
1724     "c" gnus-article-remove-cr
1725     "q" gnus-article-de-quoted-unreadable
1726     "6" gnus-article-de-base64-unreadable
1727     "Z" gnus-article-decode-HZ
1728     "h" gnus-article-wash-html
1729     "s" gnus-summary-force-verify-and-decrypt
1730     "f" gnus-article-display-x-face
1731     "l" gnus-summary-stop-page-breaking
1732     "r" gnus-summary-caesar-message
1733     "t" gnus-summary-toggle-header
1734     "g" gnus-treat-smiley
1735     "v" gnus-summary-verbose-headers
1736     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1737     "p" gnus-article-verify-x-pgp-sig
1738     "d" gnus-article-treat-dumbquotes)
1739
1740   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1741     "a" gnus-article-hide
1742     "h" gnus-article-hide-headers
1743     "b" gnus-article-hide-boring-headers
1744     "s" gnus-article-hide-signature
1745     "c" gnus-article-hide-citation
1746     "C" gnus-article-hide-citation-in-followups
1747     "l" gnus-article-hide-list-identifiers
1748     "p" gnus-article-hide-pgp
1749     "B" gnus-article-strip-banner
1750     "P" gnus-article-hide-pem
1751     "\C-c" gnus-article-hide-citation-maybe)
1752
1753   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1754     "a" gnus-article-highlight
1755     "h" gnus-article-highlight-headers
1756     "c" gnus-article-highlight-citation
1757     "s" gnus-article-highlight-signature)
1758
1759   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1760     "f" gnus-article-treat-fold-headers
1761     "u" gnus-article-treat-unfold-headers
1762     "n" gnus-article-treat-fold-newsgroups)
1763
1764   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1765     "x" gnus-article-display-x-face
1766     "s" gnus-treat-smiley
1767     "D" gnus-article-remove-images
1768     "f" gnus-treat-from-picon
1769     "m" gnus-treat-mail-picon
1770     "n" gnus-treat-newsgroups-picon)
1771
1772   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1773     "w" gnus-article-decode-mime-words
1774     "c" gnus-article-decode-charset
1775     "v" gnus-mime-view-all-parts
1776     "b" gnus-article-view-part)
1777
1778   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1779     "z" gnus-article-date-ut
1780     "u" gnus-article-date-ut
1781     "l" gnus-article-date-local
1782     "p" gnus-article-date-english
1783     "e" gnus-article-date-lapsed
1784     "o" gnus-article-date-original
1785     "i" gnus-article-date-iso8601
1786     "s" gnus-article-date-user)
1787
1788   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1789     "t" gnus-article-remove-trailing-blank-lines
1790     "l" gnus-article-strip-leading-blank-lines
1791     "m" gnus-article-strip-multiple-blank-lines
1792     "a" gnus-article-strip-blank-lines
1793     "A" gnus-article-strip-all-blank-lines
1794     "s" gnus-article-strip-leading-space
1795     "e" gnus-article-strip-trailing-space
1796     "w" gnus-article-remove-leading-whitespace)
1797
1798   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1799     "v" gnus-version
1800     "f" gnus-summary-fetch-faq
1801     "d" gnus-summary-describe-group
1802     "h" gnus-summary-describe-briefly
1803     "i" gnus-info-find-node)
1804
1805   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1806     "e" gnus-summary-expire-articles
1807     "\M-\C-e" gnus-summary-expire-articles-now
1808     "\177" gnus-summary-delete-article
1809     [delete] gnus-summary-delete-article
1810     [backspace] gnus-summary-delete-article
1811     "m" gnus-summary-move-article
1812     "r" gnus-summary-respool-article
1813     "w" gnus-summary-edit-article
1814     "c" gnus-summary-copy-article
1815     "B" gnus-summary-crosspost-article
1816     "q" gnus-summary-respool-query
1817     "t" gnus-summary-respool-trace
1818     "i" gnus-summary-import-article
1819     "I" gnus-summary-create-article
1820     "p" gnus-summary-article-posted-p)
1821
1822   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1823     "o" gnus-summary-save-article
1824     "m" gnus-summary-save-article-mail
1825     "F" gnus-summary-write-article-file
1826     "r" gnus-summary-save-article-rmail
1827     "f" gnus-summary-save-article-file
1828     "b" gnus-summary-save-article-body-file
1829     "h" gnus-summary-save-article-folder
1830     "v" gnus-summary-save-article-vm
1831     "p" gnus-summary-pipe-output
1832     "P" gnus-summary-muttprint
1833     "s" gnus-soup-add-article)
1834
1835   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1836     "b" gnus-summary-display-buttonized
1837     "m" gnus-summary-repair-multipart
1838     "v" gnus-article-view-part
1839     "o" gnus-article-save-part
1840     "c" gnus-article-copy-part
1841     "C" gnus-article-view-part-as-charset
1842     "e" gnus-article-externalize-part
1843     "E" gnus-article-encrypt-body
1844     "i" gnus-article-inline-part
1845     "|" gnus-article-pipe-part))
1846
1847 (defvar gnus-article-post-menu nil)
1848
1849 (defun gnus-summary-make-menu-bar ()
1850   (gnus-turn-off-edit-menu 'summary)
1851
1852   (unless (boundp 'gnus-summary-misc-menu)
1853
1854     (easy-menu-define
1855       gnus-summary-kill-menu gnus-summary-mode-map ""
1856       (cons
1857        "Score"
1858        (nconc
1859         (list
1860          ["Customize" gnus-score-customize t])
1861         (gnus-make-score-map 'increase)
1862         (gnus-make-score-map 'lower)
1863         '(("Mark"
1864            ["Kill below" gnus-summary-kill-below t]
1865            ["Mark above" gnus-summary-mark-above t]
1866            ["Tick above" gnus-summary-tick-above t]
1867            ["Clear above" gnus-summary-clear-above t])
1868           ["Current score" gnus-summary-current-score t]
1869           ["Set score" gnus-summary-set-score t]
1870           ["Switch current score file..." gnus-score-change-score-file t]
1871           ["Set mark below..." gnus-score-set-mark-below t]
1872           ["Set expunge below..." gnus-score-set-expunge-below t]
1873           ["Edit current score file" gnus-score-edit-current-scores t]
1874           ["Edit score file" gnus-score-edit-file t]
1875           ["Trace score" gnus-score-find-trace t]
1876           ["Find words" gnus-score-find-favourite-words t]
1877           ["Rescore buffer" gnus-summary-rescore t]
1878           ["Increase score..." gnus-summary-increase-score t]
1879           ["Lower score..." gnus-summary-lower-score t]))))
1880
1881     ;; Define both the Article menu in the summary buffer and the
1882     ;; equivalent Commands menu in the article buffer here for
1883     ;; consistency.
1884     (let ((innards
1885            `(("Hide"
1886               ["All" gnus-article-hide t]
1887               ["Headers" gnus-article-hide-headers t]
1888               ["Signature" gnus-article-hide-signature t]
1889               ["Citation" gnus-article-hide-citation t]
1890               ["List identifiers" gnus-article-hide-list-identifiers t]
1891               ["PGP" gnus-article-hide-pgp t]
1892               ["Banner" gnus-article-strip-banner t]
1893               ["Boring headers" gnus-article-hide-boring-headers t])
1894              ("Highlight"
1895               ["All" gnus-article-highlight t]
1896               ["Headers" gnus-article-highlight-headers t]
1897               ["Signature" gnus-article-highlight-signature t]
1898               ["Citation" gnus-article-highlight-citation t])
1899              ("MIME"
1900               ["Words" gnus-article-decode-mime-words t]
1901               ["Charset" gnus-article-decode-charset t]
1902               ["QP" gnus-article-de-quoted-unreadable t]
1903               ["Base64" gnus-article-de-base64-unreadable t]
1904               ["View all" gnus-mime-view-all-parts t]
1905               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1906               ["Encrypt body" gnus-article-encrypt-body t])
1907              ("Date"
1908               ["Local" gnus-article-date-local t]
1909               ["ISO8601" gnus-article-date-iso8601 t]
1910               ["UT" gnus-article-date-ut t]
1911               ["Original" gnus-article-date-original t]
1912               ["Lapsed" gnus-article-date-lapsed t]
1913               ["User-defined" gnus-article-date-user t])
1914              ("Display"
1915               ["Remove images" gnus-article-remove-images t]
1916               ["Toggle smiley" gnus-treat-smiley t]
1917               ["Show X-Face" gnus-article-display-x-face t]
1918               ["Show picons in From" gnus-treat-from-picon t]
1919               ["Show picons in mail headers" gnus-treat-mail-picon t]
1920               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1921              ("Washing"
1922               ("Remove Blanks"
1923                ["Leading" gnus-article-strip-leading-blank-lines t]
1924                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1925                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1926                ["All of the above" gnus-article-strip-blank-lines t]
1927                ["All" gnus-article-strip-all-blank-lines t]
1928                ["Leading space" gnus-article-strip-leading-space t]
1929                ["Trailing space" gnus-article-strip-trailing-space t]
1930                ["Leading space in headers"
1931                 gnus-article-remove-leading-whitespace t])
1932               ["Overstrike" gnus-article-treat-overstrike t]
1933               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1934               ["Emphasis" gnus-article-emphasize t]
1935               ["Word wrap" gnus-article-fill-cited-article t]
1936               ["Fill long lines" gnus-article-fill-long-lines t]
1937               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1938               ["CR" gnus-article-remove-cr t]
1939               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1940               ["Base64" gnus-article-de-base64-unreadable t]
1941               ["Rot 13" gnus-summary-caesar-message
1942                ,@(if (featurep 'xemacs) '(t)
1943                    '(:help "\"Caesar rotate\" article by 13"))]
1944               ["Unix pipe" gnus-summary-pipe-message t]
1945               ["Add buttons" gnus-article-add-buttons t]
1946               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1947               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1948               ["Verbose header" gnus-summary-verbose-headers t]
1949               ["Toggle header" gnus-summary-toggle-header t]
1950               ["Unfold headers" gnus-article-treat-unfold-headers t]
1951               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1952               ["Html" gnus-article-wash-html t]
1953               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1954               ["HZ" gnus-article-decode-HZ t])
1955              ("Output"
1956               ["Save in default format" gnus-summary-save-article
1957                ,@(if (featurep 'xemacs) '(t)
1958                    '(:help "Save article using default method"))]
1959               ["Save in file" gnus-summary-save-article-file
1960                ,@(if (featurep 'xemacs) '(t)
1961                    '(:help "Save article in file"))]
1962               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1963               ["Save in MH folder" gnus-summary-save-article-folder t]
1964               ["Save in VM folder" gnus-summary-save-article-vm t]
1965               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1966               ["Save body in file" gnus-summary-save-article-body-file t]
1967               ["Pipe through a filter" gnus-summary-pipe-output t]
1968               ["Add to SOUP packet" gnus-soup-add-article t]
1969               ["Print with Muttprint" gnus-summary-muttprint t]
1970               ["Print" gnus-summary-print-article t])
1971              ("Backend"
1972               ["Respool article..." gnus-summary-respool-article t]
1973               ["Move article..." gnus-summary-move-article
1974                (gnus-check-backend-function
1975                 'request-move-article gnus-newsgroup-name)]
1976               ["Copy article..." gnus-summary-copy-article t]
1977               ["Crosspost article..." gnus-summary-crosspost-article
1978                (gnus-check-backend-function
1979                 'request-replace-article gnus-newsgroup-name)]
1980               ["Import file..." gnus-summary-import-article t]
1981               ["Create article..." gnus-summary-create-article t]
1982               ["Check if posted" gnus-summary-article-posted-p t]
1983               ["Edit article" gnus-summary-edit-article
1984                (not (gnus-group-read-only-p))]
1985               ["Delete article" gnus-summary-delete-article
1986                (gnus-check-backend-function
1987                 'request-expire-articles gnus-newsgroup-name)]
1988               ["Query respool" gnus-summary-respool-query t]
1989               ["Trace respool" gnus-summary-respool-trace t]
1990               ["Delete expirable articles" gnus-summary-expire-articles-now
1991                (gnus-check-backend-function
1992                 'request-expire-articles gnus-newsgroup-name)])
1993              ("Extract"
1994               ["Uudecode" gnus-uu-decode-uu
1995                ,@(if (featurep 'xemacs) '(t)
1996                    '(:help "Decode uuencoded article(s)"))]
1997               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1998               ["Unshar" gnus-uu-decode-unshar t]
1999               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2000               ["Save" gnus-uu-decode-save t]
2001               ["Binhex" gnus-uu-decode-binhex t]
2002               ["Postscript" gnus-uu-decode-postscript t])
2003              ("Cache"
2004               ["Enter article" gnus-cache-enter-article t]
2005               ["Remove article" gnus-cache-remove-article t])
2006              ["Translate" gnus-article-babel t]
2007              ["Select article buffer" gnus-summary-select-article-buffer t]
2008              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2009              ["Isearch article..." gnus-summary-isearch-article t]
2010              ["Beginning of the article" gnus-summary-beginning-of-article t]
2011              ["End of the article" gnus-summary-end-of-article t]
2012              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2013              ["Fetch referenced articles" gnus-summary-refer-references t]
2014              ["Fetch current thread" gnus-summary-refer-thread t]
2015              ["Fetch article with id..." gnus-summary-refer-article t]
2016              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2017              ["Redisplay" gnus-summary-show-article t]
2018              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2019       (easy-menu-define
2020         gnus-summary-article-menu gnus-summary-mode-map ""
2021         (cons "Article" innards))
2022
2023       (if (not (keymapp gnus-summary-article-menu))
2024           (easy-menu-define
2025             gnus-article-commands-menu gnus-article-mode-map ""
2026             (cons "Commands" innards))
2027         ;; in Emacs, don't share menu.
2028         (setq gnus-article-commands-menu
2029               (copy-keymap gnus-summary-article-menu))
2030         (define-key gnus-article-mode-map [menu-bar commands]
2031           (cons "Commands" gnus-article-commands-menu))))
2032
2033     (easy-menu-define
2034       gnus-summary-thread-menu gnus-summary-mode-map ""
2035       '("Threads"
2036         ["Toggle threading" gnus-summary-toggle-threads t]
2037         ["Hide threads" gnus-summary-hide-all-threads t]
2038         ["Show threads" gnus-summary-show-all-threads t]
2039         ["Hide thread" gnus-summary-hide-thread t]
2040         ["Show thread" gnus-summary-show-thread t]
2041         ["Go to next thread" gnus-summary-next-thread t]
2042         ["Go to previous thread" gnus-summary-prev-thread t]
2043         ["Go down thread" gnus-summary-down-thread t]
2044         ["Go up thread" gnus-summary-up-thread t]
2045         ["Top of thread" gnus-summary-top-thread t]
2046         ["Mark thread as read" gnus-summary-kill-thread t]
2047         ["Lower thread score" gnus-summary-lower-thread t]
2048         ["Raise thread score" gnus-summary-raise-thread t]
2049         ["Rethread current" gnus-summary-rethread-current t]))
2050
2051     (easy-menu-define
2052       gnus-summary-post-menu gnus-summary-mode-map ""
2053       `("Post"
2054         ["Send a message (mail or news)" gnus-summary-post-news
2055          ,@(if (featurep 'xemacs) '(t)
2056              '(:help "Post an article"))]
2057         ["Followup" gnus-summary-followup
2058          ,@(if (featurep 'xemacs) '(t)
2059              '(:help "Post followup to this article"))]
2060         ["Followup and yank" gnus-summary-followup-with-original
2061          ,@(if (featurep 'xemacs) '(t)
2062              '(:help "Post followup to this article, quoting its contents"))]
2063         ["Supersede article" gnus-summary-supersede-article t]
2064         ["Cancel article" gnus-summary-cancel-article
2065          ,@(if (featurep 'xemacs) '(t)
2066              '(:help "Cancel an article you posted"))]
2067         ["Reply" gnus-summary-reply t]
2068         ["Reply and yank" gnus-summary-reply-with-original t]
2069         ["Wide reply" gnus-summary-wide-reply t]
2070         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2071          ,@(if (featurep 'xemacs) '(t)
2072              '(:help "Mail a reply, quoting this article"))]
2073         ["Very wide reply" gnus-summary-very-wide-reply t]
2074         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2075         ,@(if (featurep 'xemacs) '(t)
2076             '(:help "Mail a very wide reply, quoting this article"))]
2077         ["Mail forward" gnus-summary-mail-forward t]
2078         ["Post forward" gnus-summary-post-forward t]
2079         ["Digest and mail" gnus-uu-digest-mail-forward t]
2080         ["Digest and post" gnus-uu-digest-post-forward t]
2081         ["Resend message" gnus-summary-resend-message t]
2082         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2083         ["Send a mail" gnus-summary-mail-other-window t]
2084         ["Create a local message" gnus-summary-news-other-window t]
2085         ["Uuencode and post" gnus-uu-post-news
2086          ,@(if (featurep 'xemacs) '(t)
2087              '(:help "Post a uuencoded article"))]
2088         ["Followup via news" gnus-summary-followup-to-mail t]
2089         ["Followup via news and yank"
2090          gnus-summary-followup-to-mail-with-original t]
2091         ;;("Draft"
2092         ;;["Send" gnus-summary-send-draft t]
2093         ;;["Send bounced" gnus-resend-bounced-mail t])
2094         ))
2095
2096     (cond
2097      ((not (keymapp gnus-summary-post-menu))
2098       (setq gnus-article-post-menu gnus-summary-post-menu))
2099      ((not gnus-article-post-menu)
2100       ;; Don't share post menu.
2101       (setq gnus-article-post-menu
2102             (copy-keymap gnus-summary-post-menu))))
2103     (define-key gnus-article-mode-map [menu-bar post]
2104       (cons "Post" gnus-article-post-menu))
2105
2106     (easy-menu-define
2107       gnus-summary-misc-menu gnus-summary-mode-map ""
2108       `("Gnus"
2109         ("Mark Read"
2110          ["Mark as read" gnus-summary-mark-as-read-forward t]
2111          ["Mark same subject and select"
2112           gnus-summary-kill-same-subject-and-select t]
2113          ["Mark same subject" gnus-summary-kill-same-subject t]
2114          ["Catchup" gnus-summary-catchup
2115           ,@(if (featurep 'xemacs) '(t)
2116               '(:help "Mark unread articles in this group as read"))]
2117          ["Catchup all" gnus-summary-catchup-all t]
2118          ["Catchup to here" gnus-summary-catchup-to-here t]
2119          ["Catchup from here" gnus-summary-catchup-from-here t]
2120          ["Catchup region" gnus-summary-mark-region-as-read t]
2121          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2122         ("Mark Various"
2123          ["Tick" gnus-summary-tick-article-forward t]
2124          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2125          ["Remove marks" gnus-summary-clear-mark-forward t]
2126          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2127          ["Set bookmark" gnus-summary-set-bookmark t]
2128          ["Remove bookmark" gnus-summary-remove-bookmark t])
2129         ("Limit to"
2130          ["Marks..." gnus-summary-limit-to-marks t]
2131          ["Subject..." gnus-summary-limit-to-subject t]
2132          ["Author..." gnus-summary-limit-to-author t]
2133          ["Age..." gnus-summary-limit-to-age t]
2134          ["Extra..." gnus-summary-limit-to-extra t]
2135          ["Score" gnus-summary-limit-to-score t]
2136          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2137          ["Unread" gnus-summary-limit-to-unread t]
2138          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2139          ["Articles" gnus-summary-limit-to-articles t]
2140          ["Pop limit" gnus-summary-pop-limit t]
2141          ["Show dormant" gnus-summary-limit-include-dormant t]
2142          ["Hide childless dormant"
2143           gnus-summary-limit-exclude-childless-dormant t]
2144          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2145          ["Hide marked" gnus-summary-limit-exclude-marks t]
2146          ["Show expunged" gnus-summary-limit-include-expunged t])
2147         ("Process Mark"
2148          ["Set mark" gnus-summary-mark-as-processable t]
2149          ["Remove mark" gnus-summary-unmark-as-processable t]
2150          ["Remove all marks" gnus-summary-unmark-all-processable t]
2151          ["Mark above" gnus-uu-mark-over t]
2152          ["Mark series" gnus-uu-mark-series t]
2153          ["Mark region" gnus-uu-mark-region t]
2154          ["Unmark region" gnus-uu-unmark-region t]
2155          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2156          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2157          ["Mark all" gnus-uu-mark-all t]
2158          ["Mark buffer" gnus-uu-mark-buffer t]
2159          ["Mark sparse" gnus-uu-mark-sparse t]
2160          ["Mark thread" gnus-uu-mark-thread t]
2161          ["Unmark thread" gnus-uu-unmark-thread t]
2162          ("Process Mark Sets"
2163           ["Kill" gnus-summary-kill-process-mark t]
2164           ["Yank" gnus-summary-yank-process-mark
2165            gnus-newsgroup-process-stack]
2166           ["Save" gnus-summary-save-process-mark t]))
2167         ("Scroll article"
2168          ["Page forward" gnus-summary-next-page
2169           ,@(if (featurep 'xemacs) '(t)
2170               '(:help "Show next page of article"))]
2171          ["Page backward" gnus-summary-prev-page
2172           ,@(if (featurep 'xemacs) '(t)
2173               '(:help "Show previous page of article"))]
2174          ["Line forward" gnus-summary-scroll-up t])
2175         ("Move"
2176          ["Next unread article" gnus-summary-next-unread-article t]
2177          ["Previous unread article" gnus-summary-prev-unread-article t]
2178          ["Next article" gnus-summary-next-article t]
2179          ["Previous article" gnus-summary-prev-article t]
2180          ["Next unread subject" gnus-summary-next-unread-subject t]
2181          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2182          ["Next article same subject" gnus-summary-next-same-subject t]
2183          ["Previous article same subject" gnus-summary-prev-same-subject t]
2184          ["First unread article" gnus-summary-first-unread-article t]
2185          ["Best unread article" gnus-summary-best-unread-article t]
2186          ["Go to subject number..." gnus-summary-goto-subject t]
2187          ["Go to article number..." gnus-summary-goto-article t]
2188          ["Go to the last article" gnus-summary-goto-last-article t]
2189          ["Pop article off history" gnus-summary-pop-article t])
2190         ("Sort"
2191          ["Sort by number" gnus-summary-sort-by-number t]
2192          ["Sort by author" gnus-summary-sort-by-author t]
2193          ["Sort by subject" gnus-summary-sort-by-subject t]
2194          ["Sort by date" gnus-summary-sort-by-date t]
2195          ["Sort by score" gnus-summary-sort-by-score t]
2196          ["Sort by lines" gnus-summary-sort-by-lines t]
2197          ["Sort by characters" gnus-summary-sort-by-chars t]
2198          ["Original sort" gnus-summary-sort-by-original t])
2199         ("Help"
2200          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2201          ["Describe group" gnus-summary-describe-group t]
2202          ["Read manual" gnus-info-find-node t])
2203         ("Modes"
2204          ["Pick and read" gnus-pick-mode t]
2205          ["Binary" gnus-binary-mode t])
2206         ("Regeneration"
2207          ["Regenerate" gnus-summary-prepare t]
2208          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2209          ["Toggle threading" gnus-summary-toggle-threads t])
2210         ["See old articles" gnus-summary-insert-old-articles t]
2211         ["See new articles" gnus-summary-insert-new-articles t]
2212         ["Filter articles..." gnus-summary-execute-command t]
2213         ["Run command on subjects..." gnus-summary-universal-argument t]
2214         ["Search articles forward..." gnus-summary-search-article-forward t]
2215         ["Search articles backward..." gnus-summary-search-article-backward t]
2216         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2217         ["Expand window" gnus-summary-expand-window t]
2218         ["Expire expirable articles" gnus-summary-expire-articles
2219          (gnus-check-backend-function
2220           'request-expire-articles gnus-newsgroup-name)]
2221         ["Edit local kill file" gnus-summary-edit-local-kill t]
2222         ["Edit main kill file" gnus-summary-edit-global-kill t]
2223         ["Edit group parameters" gnus-summary-edit-parameters t]
2224         ["Customize group parameters" gnus-summary-customize-parameters t]
2225         ["Send a bug report" gnus-bug t]
2226         ("Exit"
2227          ["Catchup and exit" gnus-summary-catchup-and-exit
2228           ,@(if (featurep 'xemacs) '(t)
2229               '(:help "Mark unread articles in this group as read, then exit"))]
2230          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2231          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2232          ["Exit group" gnus-summary-exit
2233           ,@(if (featurep 'xemacs) '(t)
2234               '(:help "Exit current group, return to group selection mode"))]
2235          ["Exit group without updating" gnus-summary-exit-no-update t]
2236          ["Exit and goto next group" gnus-summary-next-group t]
2237          ["Exit and goto prev group" gnus-summary-prev-group t]
2238          ["Reselect group" gnus-summary-reselect-current-group t]
2239          ["Rescan group" gnus-summary-rescan-group t]
2240          ["Update dribble" gnus-summary-save-newsrc t])))
2241
2242     (gnus-run-hooks 'gnus-summary-menu-hook)))
2243
2244 (defvar gnus-summary-tool-bar-map nil)
2245
2246 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2247 (defun gnus-summary-make-tool-bar ()
2248   (if (and (fboundp 'tool-bar-add-item-from-menu)
2249            (default-value 'tool-bar-mode)
2250            (not gnus-summary-tool-bar-map))
2251       (setq gnus-summary-tool-bar-map
2252             (let ((tool-bar-map (make-sparse-keymap))
2253                   (load-path (mm-image-load-path)))
2254               (tool-bar-add-item-from-menu
2255                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2256               (tool-bar-add-item-from-menu
2257                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2258               (tool-bar-add-item-from-menu
2259                'gnus-summary-post-news "post" gnus-summary-mode-map)
2260               (tool-bar-add-item-from-menu
2261                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2262               (tool-bar-add-item-from-menu
2263                'gnus-summary-followup "followup" gnus-summary-mode-map)
2264               (tool-bar-add-item-from-menu
2265                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2266               (tool-bar-add-item-from-menu
2267                'gnus-summary-reply "reply" gnus-summary-mode-map)
2268               (tool-bar-add-item-from-menu
2269                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2270               (tool-bar-add-item-from-menu
2271                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2272               (tool-bar-add-item-from-menu
2273                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2274               (tool-bar-add-item-from-menu
2275                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2276               (tool-bar-add-item-from-menu
2277                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2278               (tool-bar-add-item-from-menu
2279                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2280               (tool-bar-add-item-from-menu
2281                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2282               (tool-bar-add-item-from-menu
2283                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2284               tool-bar-map)))
2285   (if gnus-summary-tool-bar-map
2286       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2287
2288 (defun gnus-score-set-default (var value)
2289   "A version of set that updates the GNU Emacs menu-bar."
2290   (set var value)
2291   ;; It is the message that forces the active status to be updated.
2292   (message ""))
2293
2294 (defun gnus-make-score-map (type)
2295   "Make a summary score map of type TYPE."
2296   (if t
2297       nil
2298     (let ((headers '(("author" "from" string)
2299                      ("subject" "subject" string)
2300                      ("article body" "body" string)
2301                      ("article head" "head" string)
2302                      ("xref" "xref" string)
2303                      ("extra header" "extra" string)
2304                      ("lines" "lines" number)
2305                      ("followups to author" "followup" string)))
2306           (types '((number ("less than" <)
2307                            ("greater than" >)
2308                            ("equal" =))
2309                    (string ("substring" s)
2310                            ("exact string" e)
2311                            ("fuzzy string" f)
2312                            ("regexp" r))))
2313           (perms '(("temporary" (current-time-string))
2314                    ("permanent" nil)
2315                    ("immediate" now)))
2316           header)
2317       (list
2318        (apply
2319         'nconc
2320         (list
2321          (if (eq type 'lower)
2322              "Lower score"
2323            "Increase score"))
2324         (let (outh)
2325           (while headers
2326             (setq header (car headers))
2327             (setq outh
2328                   (cons
2329                    (apply
2330                     'nconc
2331                     (list (car header))
2332                     (let ((ts (cdr (assoc (nth 2 header) types)))
2333                           outt)
2334                       (while ts
2335                         (setq outt
2336                               (cons
2337                                (apply
2338                                 'nconc
2339                                 (list (caar ts))
2340                                 (let ((ps perms)
2341                                       outp)
2342                                   (while ps
2343                                     (setq outp
2344                                           (cons
2345                                            (vector
2346                                             (caar ps)
2347                                             (list
2348                                              'gnus-summary-score-entry
2349                                              (nth 1 header)
2350                                              (if (or (string= (nth 1 header)
2351                                                               "head")
2352                                                      (string= (nth 1 header)
2353                                                               "body"))
2354                                                  ""
2355                                                (list 'gnus-summary-header
2356                                                      (nth 1 header)))
2357                                              (list 'quote (nth 1 (car ts)))
2358                                              (list 'gnus-score-delta-default
2359                                                    nil)
2360                                              (nth 1 (car ps))
2361                                              t)
2362                                             t)
2363                                            outp))
2364                                     (setq ps (cdr ps)))
2365                                   (list (nreverse outp))))
2366                                outt))
2367                         (setq ts (cdr ts)))
2368                       (list (nreverse outt))))
2369                    outh))
2370             (setq headers (cdr headers)))
2371           (list (nreverse outh))))))))
2372
2373 \f
2374
2375 (defun gnus-summary-mode (&optional group)
2376   "Major mode for reading articles.
2377
2378 All normal editing commands are switched off.
2379 \\<gnus-summary-mode-map>
2380 Each line in this buffer represents one article.  To read an
2381 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2382 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2383 respectively.
2384
2385 You can also post articles and send mail from this buffer.  To
2386 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2387 of an article, type `\\[gnus-summary-reply]'.
2388
2389 There are approx. one gazillion commands you can execute in this
2390 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2391
2392 The following commands are available:
2393
2394 \\{gnus-summary-mode-map}"
2395   (interactive)
2396   (kill-all-local-variables)
2397   (when (gnus-visual-p 'summary-menu 'menu)
2398     (gnus-summary-make-menu-bar)
2399     (gnus-summary-make-tool-bar))
2400   (gnus-summary-make-local-variables)
2401   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2402     (gnus-summary-make-local-variables))
2403   (gnus-make-thread-indent-array)
2404   (gnus-simplify-mode-line)
2405   (setq major-mode 'gnus-summary-mode)
2406   (setq mode-name "Summary")
2407   (make-local-variable 'minor-mode-alist)
2408   (use-local-map gnus-summary-mode-map)
2409   (buffer-disable-undo)
2410   (setq buffer-read-only t)             ;Disable modification
2411   (setq truncate-lines t)
2412   (setq selective-display t)
2413   (setq selective-display-ellipses t)   ;Display `...'
2414   (gnus-summary-set-display-table)
2415   (gnus-set-default-directory)
2416   (setq gnus-newsgroup-name group)
2417   (make-local-variable 'gnus-summary-line-format)
2418   (make-local-variable 'gnus-summary-line-format-spec)
2419   (make-local-variable 'gnus-summary-dummy-line-format)
2420   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2421   (make-local-variable 'gnus-summary-mark-positions)
2422   (make-local-hook 'pre-command-hook)
2423   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2424   (gnus-run-hooks 'gnus-summary-mode-hook)
2425   (turn-on-gnus-mailing-list-mode)
2426   (mm-enable-multibyte)
2427   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2428   (gnus-update-summary-mark-positions))
2429
2430 (defun gnus-summary-make-local-variables ()
2431   "Make all the local summary buffer variables."
2432   (let (global)
2433     (dolist (local gnus-summary-local-variables)
2434       (if (consp local)
2435           (progn
2436             (if (eq (cdr local) 'global)
2437                 ;; Copy the global value of the variable.
2438                 (setq global (symbol-value (car local)))
2439               ;; Use the value from the list.
2440               (setq global (eval (cdr local))))
2441             (set (make-local-variable (car local)) global))
2442         ;; Simple nil-valued local variable.
2443         (set (make-local-variable local) nil)))))
2444
2445 (defun gnus-summary-clear-local-variables ()
2446   (let ((locals gnus-summary-local-variables))
2447     (while locals
2448       (if (consp (car locals))
2449           (and (vectorp (caar locals))
2450                (set (caar locals) nil))
2451         (and (vectorp (car locals))
2452              (set (car locals) nil)))
2453       (setq locals (cdr locals)))))
2454
2455 ;; Summary data functions.
2456
2457 (defmacro gnus-data-number (data)
2458   `(car ,data))
2459
2460 (defmacro gnus-data-set-number (data number)
2461   `(setcar ,data ,number))
2462
2463 (defmacro gnus-data-mark (data)
2464   `(nth 1 ,data))
2465
2466 (defmacro gnus-data-set-mark (data mark)
2467   `(setcar (nthcdr 1 ,data) ,mark))
2468
2469 (defmacro gnus-data-pos (data)
2470   `(nth 2 ,data))
2471
2472 (defmacro gnus-data-set-pos (data pos)
2473   `(setcar (nthcdr 2 ,data) ,pos))
2474
2475 (defmacro gnus-data-header (data)
2476   `(nth 3 ,data))
2477
2478 (defmacro gnus-data-set-header (data header)
2479   `(setf (nth 3 ,data) ,header))
2480
2481 (defmacro gnus-data-level (data)
2482   `(nth 4 ,data))
2483
2484 (defmacro gnus-data-unread-p (data)
2485   `(= (nth 1 ,data) gnus-unread-mark))
2486
2487 (defmacro gnus-data-read-p (data)
2488   `(/= (nth 1 ,data) gnus-unread-mark))
2489
2490 (defmacro gnus-data-pseudo-p (data)
2491   `(consp (nth 3 ,data)))
2492
2493 (defmacro gnus-data-find (number)
2494   `(assq ,number gnus-newsgroup-data))
2495
2496 (defmacro gnus-data-find-list (number &optional data)
2497   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2498      (memq (assq ,number bdata)
2499            bdata)))
2500
2501 (defmacro gnus-data-make (number mark pos header level)
2502   `(list ,number ,mark ,pos ,header ,level))
2503
2504 (defun gnus-data-enter (after-article number mark pos header level offset)
2505   (let ((data (gnus-data-find-list after-article)))
2506     (unless data
2507       (error "No such article: %d" after-article))
2508     (setcdr data (cons (gnus-data-make number mark pos header level)
2509                        (cdr data)))
2510     (setq gnus-newsgroup-data-reverse nil)
2511     (gnus-data-update-list (cddr data) offset)))
2512
2513 (defun gnus-data-enter-list (after-article list &optional offset)
2514   (when list
2515     (let ((data (and after-article (gnus-data-find-list after-article)))
2516           (ilist list))
2517       (if (not (or data
2518                    after-article))
2519           (let ((odata gnus-newsgroup-data))
2520             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2521             (when offset
2522               (gnus-data-update-list odata offset)))
2523       ;; Find the last element in the list to be spliced into the main
2524         ;; list.
2525         (while (cdr list)
2526           (setq list (cdr list)))
2527         (if (not data)
2528             (progn
2529               (setcdr list gnus-newsgroup-data)
2530               (setq gnus-newsgroup-data ilist)
2531               (when offset
2532                 (gnus-data-update-list (cdr list) offset)))
2533           (setcdr list (cdr data))
2534           (setcdr data ilist)
2535           (when offset
2536             (gnus-data-update-list (cdr list) offset))))
2537       (setq gnus-newsgroup-data-reverse nil))))
2538
2539 (defun gnus-data-remove (article &optional offset)
2540   (let ((data gnus-newsgroup-data))
2541     (if (= (gnus-data-number (car data)) article)
2542         (progn
2543           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2544                 gnus-newsgroup-data-reverse nil)
2545           (when offset
2546             (gnus-data-update-list gnus-newsgroup-data offset)))
2547       (while (cdr data)
2548         (when (= (gnus-data-number (cadr data)) article)
2549           (setcdr data (cddr data))
2550           (when offset
2551             (gnus-data-update-list (cdr data) offset))
2552           (setq data nil
2553                 gnus-newsgroup-data-reverse nil))
2554         (setq data (cdr data))))))
2555
2556 (defmacro gnus-data-list (backward)
2557   `(if ,backward
2558        (or gnus-newsgroup-data-reverse
2559            (setq gnus-newsgroup-data-reverse
2560                  (reverse gnus-newsgroup-data)))
2561      gnus-newsgroup-data))
2562
2563 (defun gnus-data-update-list (data offset)
2564   "Add OFFSET to the POS of all data entries in DATA."
2565   (setq gnus-newsgroup-data-reverse nil)
2566   (while data
2567     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2568     (setq data (cdr data))))
2569
2570 (defun gnus-summary-article-pseudo-p (article)
2571   "Say whether this article is a pseudo article or not."
2572   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2573
2574 (defmacro gnus-summary-article-sparse-p (article)
2575   "Say whether this article is a sparse article or not."
2576   `(memq ,article gnus-newsgroup-sparse))
2577
2578 (defmacro gnus-summary-article-ancient-p (article)
2579   "Say whether this article is a sparse article or not."
2580   `(memq ,article gnus-newsgroup-ancient))
2581
2582 (defun gnus-article-parent-p (number)
2583   "Say whether this article is a parent or not."
2584   (let ((data (gnus-data-find-list number)))
2585     (and (cdr data)              ; There has to be an article after...
2586          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2587             (gnus-data-level (nth 1 data))))))
2588
2589 (defun gnus-article-children (number)
2590   "Return a list of all children to NUMBER."
2591   (let* ((data (gnus-data-find-list number))
2592          (level (gnus-data-level (car data)))
2593          children)
2594     (setq data (cdr data))
2595     (while (and data
2596                 (= (gnus-data-level (car data)) (1+ level)))
2597       (push (gnus-data-number (car data)) children)
2598       (setq data (cdr data)))
2599     children))
2600
2601 (defmacro gnus-summary-skip-intangible ()
2602   "If the current article is intangible, then jump to a different article."
2603   '(let ((to (get-text-property (point) 'gnus-intangible)))
2604      (and to (gnus-summary-goto-subject to))))
2605
2606 (defmacro gnus-summary-article-intangible-p ()
2607   "Say whether this article is intangible or not."
2608   '(get-text-property (point) 'gnus-intangible))
2609
2610 (defun gnus-article-read-p (article)
2611   "Say whether ARTICLE is read or not."
2612   (not (or (memq article gnus-newsgroup-marked)
2613            (memq article gnus-newsgroup-unreads)
2614            (memq article gnus-newsgroup-unselected)
2615            (memq article gnus-newsgroup-dormant))))
2616
2617 ;; Some summary mode macros.
2618
2619 (defmacro gnus-summary-article-number ()
2620   "The article number of the article on the current line.
2621 If there isn's an article number here, then we return the current
2622 article number."
2623   '(progn
2624      (gnus-summary-skip-intangible)
2625      (or (get-text-property (point) 'gnus-number)
2626          (gnus-summary-last-subject))))
2627
2628 (defmacro gnus-summary-article-header (&optional number)
2629   "Return the header of article NUMBER."
2630   `(gnus-data-header (gnus-data-find
2631                       ,(or number '(gnus-summary-article-number)))))
2632
2633 (defmacro gnus-summary-thread-level (&optional number)
2634   "Return the level of thread that starts with article NUMBER."
2635   `(if (and (eq gnus-summary-make-false-root 'dummy)
2636             (get-text-property (point) 'gnus-intangible))
2637        0
2638      (gnus-data-level (gnus-data-find
2639                        ,(or number '(gnus-summary-article-number))))))
2640
2641 (defmacro gnus-summary-article-mark (&optional number)
2642   "Return the mark of article NUMBER."
2643   `(gnus-data-mark (gnus-data-find
2644                     ,(or number '(gnus-summary-article-number)))))
2645
2646 (defmacro gnus-summary-article-pos (&optional number)
2647   "Return the position of the line of article NUMBER."
2648   `(gnus-data-pos (gnus-data-find
2649                    ,(or number '(gnus-summary-article-number)))))
2650
2651 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2652 (defmacro gnus-summary-article-subject (&optional number)
2653   "Return current subject string or nil if nothing."
2654   `(let ((headers
2655           ,(if number
2656                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2657              '(gnus-data-header (assq (gnus-summary-article-number)
2658                                       gnus-newsgroup-data)))))
2659      (and headers
2660           (vectorp headers)
2661           (mail-header-subject headers))))
2662
2663 (defmacro gnus-summary-article-score (&optional number)
2664   "Return current article score."
2665   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2666                   gnus-newsgroup-scored))
2667        gnus-summary-default-score 0))
2668
2669 (defun gnus-summary-article-children (&optional number)
2670   "Return a list of article numbers that are children of article NUMBER."
2671   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2672          (level (gnus-data-level (car data)))
2673          l children)
2674     (while (and (setq data (cdr data))
2675                 (> (setq l (gnus-data-level (car data))) level))
2676       (and (= (1+ level) l)
2677            (push (gnus-data-number (car data))
2678                  children)))
2679     (nreverse children)))
2680
2681 (defun gnus-summary-article-parent (&optional number)
2682   "Return the article number of the parent of article NUMBER."
2683   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2684                                     (gnus-data-list t)))
2685          (level (gnus-data-level (car data))))
2686     (if (zerop level)
2687         ()                              ; This is a root.
2688       ;; We search until we find an article with a level less than
2689       ;; this one.  That function has to be the parent.
2690       (while (and (setq data (cdr data))
2691                   (not (< (gnus-data-level (car data)) level))))
2692       (and data (gnus-data-number (car data))))))
2693
2694 (defun gnus-unread-mark-p (mark)
2695   "Say whether MARK is the unread mark."
2696   (= mark gnus-unread-mark))
2697
2698 (defun gnus-read-mark-p (mark)
2699   "Say whether MARK is one of the marks that mark as read.
2700 This is all marks except unread, ticked, dormant, and expirable."
2701   (not (or (= mark gnus-unread-mark)
2702            (= mark gnus-ticked-mark)
2703            (= mark gnus-dormant-mark)
2704            (= mark gnus-expirable-mark))))
2705
2706 (defmacro gnus-article-mark (number)
2707   "Return the MARK of article NUMBER.
2708 This macro should only be used when computing the mark the \"first\"
2709 time; i.e., when generating the summary lines.  After that,
2710 `gnus-summary-article-mark' should be used to examine the
2711 marks of articles."
2712   `(cond
2713     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2714     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2715     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2716     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2717     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2718     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2719     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2720     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2721            gnus-ancient-mark))))
2722
2723 ;; Saving hidden threads.
2724
2725 (defmacro gnus-save-hidden-threads (&rest forms)
2726   "Save hidden threads, eval FORMS, and restore the hidden threads."
2727   (let ((config (make-symbol "config")))
2728     `(let ((,config (gnus-hidden-threads-configuration)))
2729        (unwind-protect
2730            (save-excursion
2731              ,@forms)
2732          (gnus-restore-hidden-threads-configuration ,config)))))
2733 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2734 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2735
2736 (defun gnus-data-compute-positions ()
2737   "Compute the positions of all articles."
2738   (setq gnus-newsgroup-data-reverse nil)
2739   (let ((data gnus-newsgroup-data))
2740     (save-excursion
2741       (gnus-save-hidden-threads
2742         (gnus-summary-show-all-threads)
2743         (goto-char (point-min))
2744         (while data
2745           (while (get-text-property (point) 'gnus-intangible)
2746             (forward-line 1))
2747           (gnus-data-set-pos (car data) (+ (point) 3))
2748           (setq data (cdr data))
2749           (forward-line 1))))))
2750
2751 (defun gnus-hidden-threads-configuration ()
2752   "Return the current hidden threads configuration."
2753   (save-excursion
2754     (let (config)
2755       (goto-char (point-min))
2756       (while (search-forward "\r" nil t)
2757         (push (1- (point)) config))
2758       config)))
2759
2760 (defun gnus-restore-hidden-threads-configuration (config)
2761   "Restore hidden threads configuration from CONFIG."
2762   (save-excursion
2763     (let (point buffer-read-only)
2764       (while (setq point (pop config))
2765         (when (and (< point (point-max))
2766                    (goto-char point)
2767                    (eq (char-after) ?\n))
2768           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2769
2770 ;; Various summary mode internalish functions.
2771
2772 (defun gnus-mouse-pick-article (e)
2773   (interactive "e")
2774   (mouse-set-point e)
2775   (gnus-summary-next-page nil t))
2776
2777 (defun gnus-summary-set-display-table ()
2778   "Change the display table.
2779 Odd characters have a tendency to mess
2780 up nicely formatted displays - we make all possible glyphs
2781 display only a single character."
2782
2783   ;; We start from the standard display table, if any.
2784   (let ((table (or (copy-sequence standard-display-table)
2785                    (make-display-table)))
2786         (i 32))
2787     ;; Nix out all the control chars...
2788     (while (>= (setq i (1- i)) 0)
2789       (aset table i [??]))
2790    ;; ... but not newline and cr, of course.  (cr is necessary for the
2791     ;; selective display).
2792     (aset table ?\n nil)
2793     (aset table ?\r nil)
2794     ;; We keep TAB as well.
2795     (aset table ?\t nil)
2796     ;; We nix out any glyphs over 126 that are not set already.
2797     (let ((i 256))
2798       (while (>= (setq i (1- i)) 127)
2799         ;; Only modify if the entry is nil.
2800         (unless (aref table i)
2801           (aset table i [??]))))
2802     (setq buffer-display-table table)))
2803
2804 (defun gnus-summary-set-article-display-arrow (pos)
2805   "Update the overlay arrow to point to line at position POS."
2806   (when (and gnus-summary-display-arrow
2807              (boundp 'overlay-arrow-position)
2808              (boundp 'overlay-arrow-string))
2809     (save-excursion
2810       (goto-char pos)
2811       (beginning-of-line)
2812       (unless overlay-arrow-position
2813         (setq overlay-arrow-position (make-marker)))
2814       (setq overlay-arrow-string "=>"
2815             overlay-arrow-position (set-marker overlay-arrow-position
2816                                                (point)
2817                                                (current-buffer))))))
2818
2819 (defun gnus-summary-buffer-name (group)
2820   "Return the summary buffer name of GROUP."
2821   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2822
2823 (defun gnus-summary-setup-buffer (group)
2824   "Initialize summary buffer."
2825   (let ((buffer (gnus-summary-buffer-name group)))
2826     (if (get-buffer buffer)
2827         (progn
2828           (set-buffer buffer)
2829           (setq gnus-summary-buffer (current-buffer))
2830           (not gnus-newsgroup-prepared))
2831       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2832       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2833       (gnus-summary-mode group)
2834       (when gnus-carpal
2835         (gnus-carpal-setup-buffer 'summary))
2836       (unless gnus-single-article-buffer
2837         (make-local-variable 'gnus-article-buffer)
2838         (make-local-variable 'gnus-article-current)
2839         (make-local-variable 'gnus-original-article-buffer))
2840       (setq gnus-newsgroup-name group)
2841       ;; Set any local variables in the group parameters.
2842       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2843       t)))
2844
2845 (defun gnus-set-global-variables ()
2846   "Set the global equivalents of the buffer-local variables.
2847 They are set to the latest values they had.  These reflect the summary
2848 buffer that was in action when the last article was fetched."
2849   (when (eq major-mode 'gnus-summary-mode)
2850     (setq gnus-summary-buffer (current-buffer))
2851     (let ((name gnus-newsgroup-name)
2852           (marked gnus-newsgroup-marked)
2853           (unread gnus-newsgroup-unreads)
2854           (headers gnus-current-headers)
2855           (data gnus-newsgroup-data)
2856           (summary gnus-summary-buffer)
2857           (article-buffer gnus-article-buffer)
2858           (original gnus-original-article-buffer)
2859           (gac gnus-article-current)
2860           (reffed gnus-reffed-article-number)
2861           (score-file gnus-current-score-file)
2862           (default-charset gnus-newsgroup-charset)
2863           vlist)
2864       (let ((locals gnus-newsgroup-variables))
2865         (while locals
2866           (if (consp (car locals))
2867               (push (eval (caar locals)) vlist)
2868             (push (eval (car locals)) vlist))
2869           (setq locals (cdr locals)))
2870         (setq vlist (nreverse vlist)))
2871       (save-excursion
2872         (set-buffer gnus-group-buffer)
2873         (setq gnus-newsgroup-name name
2874               gnus-newsgroup-marked marked
2875               gnus-newsgroup-unreads unread
2876               gnus-current-headers headers
2877               gnus-newsgroup-data data
2878               gnus-article-current gac
2879               gnus-summary-buffer summary
2880               gnus-article-buffer article-buffer
2881               gnus-original-article-buffer original
2882               gnus-reffed-article-number reffed
2883               gnus-current-score-file score-file
2884               gnus-newsgroup-charset default-charset)
2885         (let ((locals gnus-newsgroup-variables))
2886           (while locals
2887             (if (consp (car locals))
2888                 (set (caar locals) (pop vlist))
2889               (set (car locals) (pop vlist)))
2890             (setq locals (cdr locals))))
2891         ;; The article buffer also has local variables.
2892         (when (gnus-buffer-live-p gnus-article-buffer)
2893           (set-buffer gnus-article-buffer)
2894           (setq gnus-summary-buffer summary))))))
2895
2896 (defun gnus-summary-article-unread-p (article)
2897   "Say whether ARTICLE is unread or not."
2898   (memq article gnus-newsgroup-unreads))
2899
2900 (defun gnus-summary-first-article-p (&optional article)
2901   "Return whether ARTICLE is the first article in the buffer."
2902   (if (not (setq article (or article (gnus-summary-article-number))))
2903       nil
2904     (eq article (caar gnus-newsgroup-data))))
2905
2906 (defun gnus-summary-last-article-p (&optional article)
2907   "Return whether ARTICLE is the last article in the buffer."
2908   (if (not (setq article (or article (gnus-summary-article-number))))
2909       ;; All non-existent numbers are the last article.  :-)
2910       t
2911     (not (cdr (gnus-data-find-list article)))))
2912
2913 (defun gnus-make-thread-indent-array ()
2914   (let ((n 200))
2915     (unless (and gnus-thread-indent-array
2916                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2917       (setq gnus-thread-indent-array (make-vector 201 "")
2918             gnus-thread-indent-array-level gnus-thread-indent-level)
2919       (while (>= n 0)
2920         (aset gnus-thread-indent-array n
2921               (make-string (* n gnus-thread-indent-level) ? ))
2922         (setq n (1- n))))))
2923
2924 (defun gnus-update-summary-mark-positions ()
2925   "Compute where the summary marks are to go."
2926   (save-excursion
2927     (when (gnus-buffer-exists-p gnus-summary-buffer)
2928       (set-buffer gnus-summary-buffer))
2929     (let ((gnus-replied-mark 129)
2930           (gnus-score-below-mark 130)
2931           (gnus-score-over-mark 130)
2932           (gnus-download-mark 131)
2933           (spec gnus-summary-line-format-spec)
2934           gnus-visual pos)
2935       (save-excursion
2936         (gnus-set-work-buffer)
2937         (let ((gnus-summary-line-format-spec spec)
2938               (gnus-newsgroup-downloadable '((0 . t))))
2939           (gnus-summary-insert-line
2940            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2941            0 nil 128 t nil "" nil 1)
2942           (goto-char (point-min))
2943           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2944                                              (- (point) 2)))))
2945           (goto-char (point-min))
2946           (push (cons 'replied (and (search-forward "\201" nil t)
2947                                     (- (point) 2)))
2948                 pos)
2949           (goto-char (point-min))
2950           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2951                 pos)
2952           (goto-char (point-min))
2953           (push (cons 'download
2954                       (and (search-forward "\203" nil t) (- (point) 2)))
2955                 pos)))
2956       (setq gnus-summary-mark-positions pos))))
2957
2958 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2959   "Insert a dummy root in the summary buffer."
2960   (beginning-of-line)
2961   (gnus-add-text-properties
2962    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2963    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2964
2965 (defun gnus-summary-extract-address-component (from)
2966   (or (car (funcall gnus-extract-address-components from))
2967       from))
2968
2969 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2970   (let ((mail-parse-charset gnus-newsgroup-charset)
2971         ; Is it really necessary to do this next part for each summary line?
2972         ; Luckily, doesn't seem to slow things down much.
2973         (mail-parse-ignored-charsets
2974          (save-excursion (set-buffer gnus-summary-buffer)
2975                          gnus-newsgroup-ignored-charsets)))
2976     (or
2977      (and gnus-ignored-from-addresses
2978           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2979           (let ((extra-headers (mail-header-extra header))
2980                 to
2981                 newsgroups)
2982             (cond
2983              ((setq to (cdr (assq 'To extra-headers)))
2984               (concat "-> "
2985                       (gnus-summary-extract-address-component
2986                        (funcall gnus-decode-encoded-word-function to))))
2987              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2988               (concat "=> " newsgroups)))))
2989      (gnus-summary-extract-address-component gnus-tmp-from))))
2990
2991 (defun gnus-summary-insert-line (gnus-tmp-header
2992                                  gnus-tmp-level gnus-tmp-current
2993                                  gnus-tmp-unread gnus-tmp-replied
2994                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2995                                  &optional gnus-tmp-dummy gnus-tmp-score
2996                                  gnus-tmp-process)
2997   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2998          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2999          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3000          (gnus-tmp-score-char
3001           (if (or (null gnus-summary-default-score)
3002                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3003                       gnus-summary-zcore-fuzz))
3004               ?                         ;Whitespace
3005             (if (< gnus-tmp-score gnus-summary-default-score)
3006                 gnus-score-below-mark gnus-score-over-mark)))
3007          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3008          (gnus-tmp-replied
3009           (cond (gnus-tmp-process gnus-process-mark)
3010                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3011                  gnus-cached-mark)
3012                 (gnus-tmp-replied gnus-replied-mark)
3013                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3014                  gnus-forwarded-mark)
3015                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3016                  gnus-saved-mark)
3017                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3018                  gnus-recent-mark)
3019                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3020                  gnus-unseen-mark)
3021                 (t gnus-no-mark)))
3022          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3023          (gnus-tmp-name
3024           (cond
3025            ((string-match "<[^>]+> *$" gnus-tmp-from)
3026             (let ((beg (match-beginning 0)))
3027               (or (and (string-match "^\".+\"" gnus-tmp-from)
3028                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3029                   (substring gnus-tmp-from 0 beg))))
3030            ((string-match "(.+)" gnus-tmp-from)
3031             (substring gnus-tmp-from
3032                        (1+ (match-beginning 0)) (1- (match-end 0))))
3033            (t gnus-tmp-from)))
3034          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3035          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3036          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3037          (buffer-read-only nil))
3038     (when (string= gnus-tmp-name "")
3039       (setq gnus-tmp-name gnus-tmp-from))
3040     (unless (numberp gnus-tmp-lines)
3041       (setq gnus-tmp-lines -1))
3042     (if (= gnus-tmp-lines -1)
3043         (setq gnus-tmp-lines "?")
3044       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3045     (gnus-put-text-property
3046      (point)
3047      (progn (eval gnus-summary-line-format-spec) (point))
3048      'gnus-number gnus-tmp-number)
3049     (when (gnus-visual-p 'summary-highlight 'highlight)
3050       (forward-line -1)
3051       (gnus-run-hooks 'gnus-summary-update-hook)
3052       (forward-line 1))))
3053
3054 (defun gnus-summary-update-line (&optional dont-update)
3055   "Update summary line after change."
3056   (when (and gnus-summary-default-score
3057              (not gnus-summary-inhibit-highlight))
3058     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3059            (article (gnus-summary-article-number))
3060            (score (gnus-summary-article-score article)))
3061       (unless dont-update
3062         (if (and gnus-summary-mark-below
3063                  (< (gnus-summary-article-score)
3064                     gnus-summary-mark-below))
3065             ;; This article has a low score, so we mark it as read.
3066             (when (memq article gnus-newsgroup-unreads)
3067               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3068           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3069             ;; This article was previously marked as read on account
3070             ;; of a low score, but now it has risen, so we mark it as
3071             ;; unread.
3072             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3073         (gnus-summary-update-mark
3074          (if (or (null gnus-summary-default-score)
3075                  (<= (abs (- score gnus-summary-default-score))
3076                      gnus-summary-zcore-fuzz))
3077              ?                          ;Whitespace
3078            (if (< score gnus-summary-default-score)
3079                gnus-score-below-mark gnus-score-over-mark))
3080          'score))
3081       ;; Do visual highlighting.
3082       (when (gnus-visual-p 'summary-highlight 'highlight)
3083         (gnus-run-hooks 'gnus-summary-update-hook)))))
3084
3085 (defvar gnus-tmp-new-adopts nil)
3086
3087 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3088   "Return the number of articles in THREAD.
3089 This may be 0 in some cases -- if none of the articles in
3090 the thread are to be displayed."
3091   (let* ((number
3092          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3093           (cond
3094            ((not (listp thread))
3095             1)
3096            ((and (consp thread) (cdr thread))
3097             (apply
3098              '+ 1 (mapcar
3099                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3100            ((null thread)
3101             1)
3102            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3103             1)
3104            (t 0))))
3105     (when (and level (zerop level) gnus-tmp-new-adopts)
3106       (incf number
3107             (apply '+ (mapcar
3108                        'gnus-summary-number-of-articles-in-thread
3109                        gnus-tmp-new-adopts))))
3110     (if char
3111         (if (> number 1) gnus-not-empty-thread-mark
3112           gnus-empty-thread-mark)
3113       number)))
3114
3115 (defun gnus-summary-set-local-parameters (group)
3116   "Go through the local params of GROUP and set all variable specs in that list."
3117   (let ((params (gnus-group-find-parameter group))
3118         (vars '(quit-config))           ; Ignore quit-config.
3119         elem)
3120     (while params
3121       (setq elem (car params)
3122             params (cdr params))
3123       (and (consp elem)                 ; Has to be a cons.
3124            (consp (cdr elem))           ; The cdr has to be a list.
3125            (symbolp (car elem))         ; Has to be a symbol in there.
3126            (not (memq (car elem) vars))
3127            (ignore-errors               ; So we set it.
3128              (push (car elem) vars)
3129              (make-local-variable (car elem))
3130              (set (car elem) (eval (nth 1 elem))))))))
3131
3132 (defun gnus-summary-read-group (group &optional show-all no-article
3133                                       kill-buffer no-display backward
3134                                       select-articles)
3135   "Start reading news in newsgroup GROUP.
3136 If SHOW-ALL is non-nil, already read articles are also listed.
3137 If NO-ARTICLE is non-nil, no article is selected initially.
3138 If NO-DISPLAY, don't generate a summary buffer."
3139   (let (result)
3140     (while (and group
3141                 (null (setq result
3142                             (let ((gnus-auto-select-next nil))
3143                               (or (gnus-summary-read-group-1
3144                                    group show-all no-article
3145                                    kill-buffer no-display
3146                                    select-articles)
3147                                   (setq show-all nil
3148                                         select-articles nil)))))
3149                 (eq gnus-auto-select-next 'quietly))
3150       (set-buffer gnus-group-buffer)
3151       ;; The entry function called above goes to the next
3152       ;; group automatically, so we go two groups back
3153       ;; if we are searching for the previous group.
3154       (when backward
3155         (gnus-group-prev-unread-group 2))
3156       (if (not (equal group (gnus-group-group-name)))
3157           (setq group (gnus-group-group-name))
3158         (setq group nil)))
3159     result))
3160
3161 (defun gnus-summary-read-group-1 (group show-all no-article
3162                                         kill-buffer no-display
3163                                         &optional select-articles)
3164   ;; Killed foreign groups can't be entered.
3165   ;;  (when (and (not (gnus-group-native-p group))
3166   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3167   ;;    (error "Dead non-native groups can't be entered"))
3168   (gnus-message 5 "Retrieving newsgroup: %s..."
3169                 (gnus-group-decoded-name group))
3170   (let* ((new-group (gnus-summary-setup-buffer group))
3171          (quit-config (gnus-group-quit-config group))
3172          (did-select (and new-group (gnus-select-newsgroup
3173                                      group show-all select-articles))))
3174     (cond
3175      ;; This summary buffer exists already, so we just select it.
3176      ((not new-group)
3177       (gnus-set-global-variables)
3178       (when kill-buffer
3179         (gnus-kill-or-deaden-summary kill-buffer))
3180       (gnus-configure-windows 'summary 'force)
3181       (gnus-set-mode-line 'summary)
3182       (gnus-summary-position-point)
3183       (message "")
3184       t)
3185      ;; We couldn't select this group.
3186      ((null did-select)
3187       (when (and (eq major-mode 'gnus-summary-mode)
3188                  (not (equal (current-buffer) kill-buffer)))
3189         (kill-buffer (current-buffer))
3190         (if (not quit-config)
3191             (progn
3192               ;; Update the info -- marks might need to be removed,
3193               ;; for instance.
3194               (gnus-summary-update-info)
3195               (set-buffer gnus-group-buffer)
3196               (gnus-group-jump-to-group group)
3197               (gnus-group-next-unread-group 1))
3198           (gnus-handle-ephemeral-exit quit-config)))
3199       (let ((grpinfo (gnus-get-info group)))
3200         (if (null (gnus-info-read grpinfo))
3201             (gnus-message 3 "Group %s contains no messages"
3202                           (gnus-group-decoded-name group))
3203           (gnus-message 3 "Can't select group")))
3204       nil)
3205      ;; The user did a `C-g' while prompting for number of articles,
3206      ;; so we exit this group.
3207      ((eq did-select 'quit)
3208       (and (eq major-mode 'gnus-summary-mode)
3209            (not (equal (current-buffer) kill-buffer))
3210            (kill-buffer (current-buffer)))
3211       (when kill-buffer
3212         (gnus-kill-or-deaden-summary kill-buffer))
3213       (if (not quit-config)
3214           (progn
3215             (set-buffer gnus-group-buffer)
3216             (gnus-group-jump-to-group group)
3217             (gnus-group-next-unread-group 1)
3218             (gnus-configure-windows 'group 'force))
3219         (gnus-handle-ephemeral-exit quit-config))
3220       ;; Finally signal the quit.
3221       (signal 'quit nil))
3222      ;; The group was successfully selected.
3223      (t
3224       (gnus-set-global-variables)
3225       ;; Save the active value in effect when the group was entered.
3226       (setq gnus-newsgroup-active
3227             (gnus-copy-sequence
3228              (gnus-active gnus-newsgroup-name)))
3229       ;; You can change the summary buffer in some way with this hook.
3230       (gnus-run-hooks 'gnus-select-group-hook)
3231       (gnus-update-format-specifications
3232        nil 'summary 'summary-mode 'summary-dummy)
3233       (gnus-update-summary-mark-positions)
3234       ;; Do score processing.
3235       (when gnus-use-scoring
3236         (gnus-possibly-score-headers))
3237       ;; Check whether to fill in the gaps in the threads.
3238       (when gnus-build-sparse-threads
3239         (gnus-build-sparse-threads))
3240       ;; Find the initial limit.
3241       (if gnus-show-threads
3242           (if show-all
3243               (let ((gnus-newsgroup-dormant nil))
3244                 (gnus-summary-initial-limit show-all))
3245             (gnus-summary-initial-limit show-all))
3246         ;; When untreaded, all articles are always shown.
3247         (setq gnus-newsgroup-limit
3248               (mapcar
3249                (lambda (header) (mail-header-number header))
3250                gnus-newsgroup-headers)))
3251       ;; Generate the summary buffer.
3252       (unless no-display
3253         (gnus-summary-prepare))
3254       (when gnus-use-trees
3255         (gnus-tree-open group)
3256         (setq gnus-summary-highlight-line-function
3257               'gnus-tree-highlight-article))
3258       ;; If the summary buffer is empty, but there are some low-scored
3259       ;; articles or some excluded dormants, we include these in the
3260       ;; buffer.
3261       (when (and (zerop (buffer-size))
3262                  (not no-display))
3263         (cond (gnus-newsgroup-dormant
3264                (gnus-summary-limit-include-dormant))
3265               ((and gnus-newsgroup-scored show-all)
3266                (gnus-summary-limit-include-expunged t))))
3267       ;; Function `gnus-apply-kill-file' must be called in this hook.
3268       (gnus-run-hooks 'gnus-apply-kill-hook)
3269       (if (and (zerop (buffer-size))
3270                (not no-display))
3271           (progn
3272             ;; This newsgroup is empty.
3273             (gnus-summary-catchup-and-exit nil t)
3274             (gnus-message 6 "No unread news")
3275             (when kill-buffer
3276               (gnus-kill-or-deaden-summary kill-buffer))
3277             ;; Return nil from this function.
3278             nil)
3279         ;; Hide conversation thread subtrees.  We cannot do this in
3280         ;; gnus-summary-prepare-hook since kill processing may not
3281         ;; work with hidden articles.
3282         (gnus-summary-maybe-hide-threads)
3283         (when kill-buffer
3284           (gnus-kill-or-deaden-summary kill-buffer))
3285         (gnus-summary-auto-select-subject)
3286         ;; Show first unread article if requested.
3287         (if (and (not no-article)
3288                  (not no-display)
3289                  gnus-newsgroup-unreads
3290                  gnus-auto-select-first)
3291             (progn
3292               (gnus-configure-windows 'summary)
3293               (let ((art (gnus-summary-article-number)))
3294                 (unless (memq art gnus-newsgroup-undownloaded)
3295                   (gnus-summary-goto-article art))))
3296           ;; Don't select any articles.
3297           (gnus-summary-position-point)
3298           (gnus-configure-windows 'summary 'force)
3299           (gnus-set-mode-line 'summary))
3300         (when (get-buffer-window gnus-group-buffer t)
3301           ;; Gotta use windows, because recenter does weird stuff if
3302           ;; the current buffer ain't the displayed window.
3303           (let ((owin (selected-window)))
3304             (select-window (get-buffer-window gnus-group-buffer t))
3305             (when (gnus-group-goto-group group)
3306               (recenter))
3307             (select-window owin)))
3308         ;; Mark this buffer as "prepared".
3309         (setq gnus-newsgroup-prepared t)
3310         (gnus-run-hooks 'gnus-summary-prepared-hook)
3311         t)))))
3312
3313 (defun gnus-summary-auto-select-subject ()
3314   "Select the subject line on initial group entry."
3315   (goto-char (point-min))
3316   (cond
3317    ((eq gnus-auto-select-subject 'best)
3318     (gnus-summary-best-unread-subject))
3319    ((eq gnus-auto-select-subject 'unread)
3320     (gnus-summary-first-unread-subject))
3321    ((eq gnus-auto-select-subject 'unseen)
3322     (gnus-summary-first-unseen-subject))
3323    ((eq gnus-auto-select-subject 'first)
3324     ;; Do nothing.
3325     )
3326    ((gnus-functionp gnus-auto-select-subject)
3327     (funcall gnus-auto-select-subject))))
3328
3329 (defun gnus-summary-prepare ()
3330   "Generate the summary buffer."
3331   (interactive)
3332   (let ((buffer-read-only nil))
3333     (erase-buffer)
3334     (setq gnus-newsgroup-data nil
3335           gnus-newsgroup-data-reverse nil)
3336     (gnus-run-hooks 'gnus-summary-generate-hook)
3337     ;; Generate the buffer, either with threads or without.
3338     (when gnus-newsgroup-headers
3339       (gnus-summary-prepare-threads
3340        (if gnus-show-threads
3341            (gnus-sort-gathered-threads
3342             (funcall gnus-summary-thread-gathering-function
3343                      (gnus-sort-threads
3344                       (gnus-cut-threads (gnus-make-threads)))))
3345          ;; Unthreaded display.
3346          (gnus-sort-articles gnus-newsgroup-headers))))
3347     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3348     ;; Call hooks for modifying summary buffer.
3349     (goto-char (point-min))
3350     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3351
3352 (defsubst gnus-general-simplify-subject (subject)
3353   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3354   (setq subject
3355         (cond
3356          ;; Truncate the subject.
3357          (gnus-simplify-subject-functions
3358           (gnus-map-function gnus-simplify-subject-functions subject))
3359          ((numberp gnus-summary-gather-subject-limit)
3360           (setq subject (gnus-simplify-subject-re subject))
3361           (if (> (length subject) gnus-summary-gather-subject-limit)
3362               (substring subject 0 gnus-summary-gather-subject-limit)
3363             subject))
3364          ;; Fuzzily simplify it.
3365          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3366           (gnus-simplify-subject-fuzzy subject))
3367          ;; Just remove the leading "Re:".
3368          (t
3369           (gnus-simplify-subject-re subject))))
3370
3371   (if (and gnus-summary-gather-exclude-subject
3372            (string-match gnus-summary-gather-exclude-subject subject))
3373       nil                         ; This article shouldn't be gathered
3374     subject))
3375
3376 (defun gnus-summary-simplify-subject-query ()
3377   "Query where the respool algorithm would put this article."
3378   (interactive)
3379   (gnus-summary-select-article)
3380   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3381
3382 (defun gnus-gather-threads-by-subject (threads)
3383   "Gather threads by looking at Subject headers."
3384   (if (not gnus-summary-make-false-root)
3385       threads
3386     (let ((hashtb (gnus-make-hashtable 1024))
3387           (prev threads)
3388           (result threads)
3389           subject hthread whole-subject)
3390       (while threads
3391         (setq subject (gnus-general-simplify-subject
3392                        (setq whole-subject (mail-header-subject
3393                                             (caar threads)))))
3394         (when subject
3395           (if (setq hthread (gnus-gethash subject hashtb))
3396               (progn
3397                 ;; We enter a dummy root into the thread, if we
3398                 ;; haven't done that already.
3399                 (unless (stringp (caar hthread))
3400                   (setcar hthread (list whole-subject (car hthread))))
3401                 ;; We add this new gathered thread to this gathered
3402                 ;; thread.
3403                 (setcdr (car hthread)
3404                         (nconc (cdar hthread) (list (car threads))))
3405                 ;; Remove it from the list of threads.
3406                 (setcdr prev (cdr threads))
3407                 (setq threads prev))
3408             ;; Enter this thread into the hash table.
3409             (gnus-sethash subject threads hashtb)))
3410         (setq prev threads)
3411         (setq threads (cdr threads)))
3412       result)))
3413
3414 (defun gnus-gather-threads-by-references (threads)
3415   "Gather threads by looking at References headers."
3416   (let ((idhashtb (gnus-make-hashtable 1024))
3417         (thhashtb (gnus-make-hashtable 1024))
3418         (prev threads)
3419         (result threads)
3420         ids references id gthread gid entered ref)
3421     (while threads
3422       (when (setq references (mail-header-references (caar threads)))
3423         (setq id (mail-header-id (caar threads))
3424               ids (gnus-split-references references)
3425               entered nil)
3426         (while (setq ref (pop ids))
3427           (setq ids (delete ref ids))
3428           (if (not (setq gid (gnus-gethash ref idhashtb)))
3429               (progn
3430                 (gnus-sethash ref id idhashtb)
3431                 (gnus-sethash id threads thhashtb))
3432             (setq gthread (gnus-gethash gid thhashtb))
3433             (unless entered
3434               ;; We enter a dummy root into the thread, if we
3435               ;; haven't done that already.
3436               (unless (stringp (caar gthread))
3437                 (setcar gthread (list (mail-header-subject (caar gthread))
3438                                       (car gthread))))
3439               ;; We add this new gathered thread to this gathered
3440               ;; thread.
3441               (setcdr (car gthread)
3442                       (nconc (cdar gthread) (list (car threads)))))
3443             ;; Add it into the thread hash table.
3444             (gnus-sethash id gthread thhashtb)
3445             (setq entered t)
3446             ;; Remove it from the list of threads.
3447             (setcdr prev (cdr threads))
3448             (setq threads prev))))
3449       (setq prev threads)
3450       (setq threads (cdr threads)))
3451     result))
3452
3453 (defun gnus-sort-gathered-threads (threads)
3454   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3455   (let ((result threads))
3456     (while threads
3457       (when (stringp (caar threads))
3458         (setcdr (car threads)
3459                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3460       (setq threads (cdr threads)))
3461     result))
3462
3463 (defun gnus-thread-loop-p (root thread)
3464   "Say whether ROOT is in THREAD."
3465   (let ((stack (list thread))
3466         (infloop 0)
3467         th)
3468     (while (setq thread (pop stack))
3469       (setq th (cdr thread))
3470       (while (and th
3471                   (not (eq (caar th) root)))
3472         (pop th))
3473       (if th
3474           ;; We have found a loop.
3475           (let (ref-dep)
3476             (setcdr thread (delq (car th) (cdr thread)))
3477             (if (boundp (setq ref-dep (intern "none"
3478                                               gnus-newsgroup-dependencies)))
3479                 (setcdr (symbol-value ref-dep)
3480                         (nconc (cdr (symbol-value ref-dep))
3481                                (list (car th))))
3482               (set ref-dep (list nil (car th))))
3483             (setq infloop 1
3484                   stack nil))
3485         ;; Push all the subthreads onto the stack.
3486         (push (cdr thread) stack)))
3487     infloop))
3488
3489 (defun gnus-make-threads ()
3490   "Go through the dependency hashtb and find the roots.  Return all threads."
3491   (let (threads)
3492     (while (catch 'infloop
3493              (mapatoms
3494               (lambda (refs)
3495                 ;; Deal with self-referencing References loops.
3496                 (when (and (car (symbol-value refs))
3497                            (not (zerop
3498                                  (apply
3499                                   '+
3500                                   (mapcar
3501                                    (lambda (thread)
3502                                      (gnus-thread-loop-p
3503                                       (car (symbol-value refs)) thread))
3504                                    (cdr (symbol-value refs)))))))
3505                   (setq threads nil)
3506                   (throw 'infloop t))
3507                 (unless (car (symbol-value refs))
3508              ;; These threads do not refer back to any other articles,
3509                   ;; so they're roots.
3510                   (setq threads (append (cdr (symbol-value refs)) threads))))
3511               gnus-newsgroup-dependencies)))
3512     threads))
3513
3514 ;; Build the thread tree.
3515 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3516   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3517
3518 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3519 if it was already present.
3520
3521 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3522 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3523 Message-IDs will be renamed be renamed to a unique Message-ID before
3524 being entered.
3525
3526 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3527   (let* ((id (mail-header-id header))
3528          (id-dep (and id (intern id dependencies)))
3529          ref ref-dep ref-header)
3530     ;; Enter this `header' in the `dependencies' table.
3531     (cond
3532      ((not id-dep)
3533       (setq header nil))
3534      ;; The first two cases do the normal part: enter a new `header'
3535      ;; in the `dependencies' table.
3536      ((not (boundp id-dep))
3537       (set id-dep (list header)))
3538      ((null (car (symbol-value id-dep)))
3539       (setcar (symbol-value id-dep) header))
3540
3541      ;; From here the `header' was already present in the
3542      ;; `dependencies' table.
3543      (force-new
3544       ;; Overrides an existing entry;
3545       ;; just set the header part of the entry.
3546       (setcar (symbol-value id-dep) header))
3547
3548      ;; Renames the existing `header' to a unique Message-ID.
3549      ((not gnus-summary-ignore-duplicates)
3550       ;; An article with this Message-ID has already been seen.
3551       ;; We rename the Message-ID.
3552       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3553            (list header))
3554       (mail-header-set-id header id))
3555
3556      ;; The last case ignores an existing entry, except it adds any
3557      ;; additional Xrefs (in case the two articles came from different
3558      ;; servers.
3559      ;; Also sets `header' to `nil' meaning that the `dependencies'
3560      ;; table was *not* modified.
3561      (t
3562       (mail-header-set-xref
3563        (car (symbol-value id-dep))
3564        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3565                    "")
3566                (or (mail-header-xref header) "")))
3567       (setq header nil)))
3568
3569     (when header
3570       ;; First check if that we are not creating a References loop.
3571       (setq ref (gnus-parent-id (mail-header-references header)))
3572       (while (and ref
3573                   (setq ref-dep (intern-soft ref dependencies))
3574                   (boundp ref-dep)
3575                   (setq ref-header (car (symbol-value ref-dep))))
3576         (if (string= id ref)
3577             ;; Yuk!  This is a reference loop.  Make the article be a
3578             ;; root article.
3579             (progn
3580               (mail-header-set-references (car (symbol-value id-dep)) "none")
3581               (setq ref nil))
3582           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3583       (setq ref (gnus-parent-id (mail-header-references header)))
3584       (setq ref-dep (intern (or ref "none") dependencies))
3585       (if (boundp ref-dep)
3586           (setcdr (symbol-value ref-dep)
3587                   (nconc (cdr (symbol-value ref-dep))
3588                          (list (symbol-value id-dep))))
3589         (set ref-dep (list nil (symbol-value id-dep)))))
3590     header))
3591
3592 (defun gnus-build-sparse-threads ()
3593   (let ((headers gnus-newsgroup-headers)
3594         (mail-parse-charset gnus-newsgroup-charset)
3595         (gnus-summary-ignore-duplicates t)
3596         header references generation relations
3597         subject child end new-child date)
3598     ;; First we create an alist of generations/relations, where
3599     ;; generations is how much we trust the relation, and the relation
3600     ;; is parent/child.
3601     (gnus-message 7 "Making sparse threads...")
3602     (save-excursion
3603       (nnheader-set-temp-buffer " *gnus sparse threads*")
3604       (while (setq header (pop headers))
3605         (when (and (setq references (mail-header-references header))
3606                    (not (string= references "")))
3607           (insert references)
3608           (setq child (mail-header-id header)
3609                 subject (mail-header-subject header)
3610                 date (mail-header-date header)
3611                 generation 0)
3612           (while (search-backward ">" nil t)
3613             (setq end (1+ (point)))
3614             (when (search-backward "<" nil t)
3615               (setq new-child (buffer-substring (point) end))
3616               (push (list (incf generation)
3617                           child (setq child new-child)
3618                           subject date)
3619                     relations)))
3620           (when child
3621             (push (list (1+ generation) child nil subject) relations))
3622           (erase-buffer)))
3623       (kill-buffer (current-buffer)))
3624     ;; Sort over trustworthiness.
3625     (mapcar
3626      (lambda (relation)
3627        (when (gnus-dependencies-add-header
3628               (make-full-mail-header
3629                gnus-reffed-article-number
3630                (nth 3 relation) "" (or (nth 4 relation) "")
3631                (nth 1 relation)
3632                (or (nth 2 relation) "") 0 0 "")
3633               gnus-newsgroup-dependencies nil)
3634          (push gnus-reffed-article-number gnus-newsgroup-limit)
3635          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3636          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3637                gnus-newsgroup-reads)
3638          (decf gnus-reffed-article-number)))
3639      (sort relations 'car-less-than-car))
3640     (gnus-message 7 "Making sparse threads...done")))
3641
3642 (defun gnus-build-old-threads ()
3643   ;; Look at all the articles that refer back to old articles, and
3644   ;; fetch the headers for the articles that aren't there.  This will
3645   ;; build complete threads - if the roots haven't been expired by the
3646   ;; server, that is.
3647   (let ((mail-parse-charset gnus-newsgroup-charset)
3648         id heads)
3649     (mapatoms
3650      (lambda (refs)
3651        (when (not (car (symbol-value refs)))
3652          (setq heads (cdr (symbol-value refs)))
3653          (while heads
3654            (if (memq (mail-header-number (caar heads))
3655                      gnus-newsgroup-dormant)
3656                (setq heads (cdr heads))
3657              (setq id (symbol-name refs))
3658              (while (and (setq id (gnus-build-get-header id))
3659                          (not (car (gnus-id-to-thread id)))))
3660              (setq heads nil)))))
3661      gnus-newsgroup-dependencies)))
3662
3663 ;; This function has to be called with point after the article number
3664 ;; on the beginning of the line.
3665 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3666   (let ((eol (gnus-point-at-eol))
3667         (buffer (current-buffer))
3668         header)
3669
3670     ;; overview: [num subject from date id refs chars lines misc]
3671     (unwind-protect
3672         (progn
3673           (narrow-to-region (point) eol)
3674           (unless (eobp)
3675             (forward-char))
3676
3677           (setq header
3678                 (make-full-mail-header
3679                  number                 ; number
3680                  (funcall gnus-decode-encoded-word-function
3681                           (nnheader-nov-field)) ; subject
3682                  (funcall gnus-decode-encoded-word-function
3683                           (nnheader-nov-field)) ; from
3684                  (nnheader-nov-field)   ; date
3685                  (nnheader-nov-read-message-id) ; id
3686                  (nnheader-nov-field)   ; refs
3687                  (nnheader-nov-read-integer) ; chars
3688                  (nnheader-nov-read-integer) ; lines
3689                  (unless (eobp)
3690                    (if (looking-at "Xref: ")
3691                        (goto-char (match-end 0)))
3692                    (nnheader-nov-field)) ; Xref
3693                  (nnheader-nov-parse-extra)))) ; extra
3694
3695       (widen))
3696
3697     (when gnus-alter-header-function
3698       (funcall gnus-alter-header-function header))
3699     (gnus-dependencies-add-header header dependencies force-new)))
3700
3701 (defun gnus-build-get-header (id)
3702   "Look through the buffer of NOV lines and find the header to ID.
3703 Enter this line into the dependencies hash table, and return
3704 the id of the parent article (if any)."
3705   (let ((deps gnus-newsgroup-dependencies)
3706         found header)
3707     (prog1
3708         (save-excursion
3709           (set-buffer nntp-server-buffer)
3710           (let ((case-fold-search nil))
3711             (goto-char (point-min))
3712             (while (and (not found)
3713                         (search-forward id nil t))
3714               (beginning-of-line)
3715               (setq found (looking-at
3716                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3717                                    (regexp-quote id))))
3718               (or found (beginning-of-line 2)))
3719             (when found
3720               (beginning-of-line)
3721               (and
3722                (setq header (gnus-nov-parse-line
3723                              (read (current-buffer)) deps))
3724                (gnus-parent-id (mail-header-references header))))))
3725       (when header
3726         (let ((number (mail-header-number header)))
3727           (push number gnus-newsgroup-limit)
3728           (push header gnus-newsgroup-headers)
3729           (if (memq number gnus-newsgroup-unselected)
3730               (progn
3731                 (push number gnus-newsgroup-unreads)
3732                 (setq gnus-newsgroup-unselected
3733                       (delq number gnus-newsgroup-unselected)))
3734             (push number gnus-newsgroup-ancient)))))))
3735
3736 (defun gnus-build-all-threads ()
3737   "Read all the headers."
3738   (let ((gnus-summary-ignore-duplicates t)
3739         (mail-parse-charset gnus-newsgroup-charset)
3740         (dependencies gnus-newsgroup-dependencies)
3741         header article)
3742     (save-excursion
3743       (set-buffer nntp-server-buffer)
3744       (let ((case-fold-search nil))
3745         (goto-char (point-min))
3746         (while (not (eobp))
3747           (ignore-errors
3748             (setq article (read (current-buffer))
3749                   header (gnus-nov-parse-line article dependencies)))
3750           (when header
3751             (save-excursion
3752               (set-buffer gnus-summary-buffer)
3753               (push header gnus-newsgroup-headers)
3754               (if (memq (setq article (mail-header-number header))
3755                         gnus-newsgroup-unselected)
3756                   (progn
3757                     (push article gnus-newsgroup-unreads)
3758                     (setq gnus-newsgroup-unselected
3759                           (delq article gnus-newsgroup-unselected)))
3760                 (push article gnus-newsgroup-ancient)))
3761             (forward-line 1)))))))
3762
3763 (defun gnus-summary-update-article-line (article header)
3764   "Update the line for ARTICLE using HEADERS."
3765   (let* ((id (mail-header-id header))
3766          (thread (gnus-id-to-thread id)))
3767     (unless thread
3768       (error "Article in no thread"))
3769     ;; Update the thread.
3770     (setcar thread header)
3771     (gnus-summary-goto-subject article)
3772     (let* ((datal (gnus-data-find-list article))
3773            (data (car datal))
3774            (length (when (cdr datal)
3775                      (- (gnus-data-pos data)
3776                         (gnus-data-pos (cadr datal)))))
3777            (buffer-read-only nil)
3778            (level (gnus-summary-thread-level)))
3779       (gnus-delete-line)
3780       (gnus-summary-insert-line
3781        header level nil (gnus-article-mark article)
3782        (memq article gnus-newsgroup-replied)
3783        (memq article gnus-newsgroup-expirable)
3784        ;; Only insert the Subject string when it's different
3785        ;; from the previous Subject string.
3786        (if (and
3787             gnus-show-threads
3788             (gnus-subject-equal
3789              (condition-case ()
3790                  (mail-header-subject
3791                   (gnus-data-header
3792                    (cadr
3793                     (gnus-data-find-list
3794                      article
3795                      (gnus-data-list t)))))
3796                ;; Error on the side of excessive subjects.
3797                (error ""))
3798              (mail-header-subject header)))
3799            ""
3800          (mail-header-subject header))
3801        nil (cdr (assq article gnus-newsgroup-scored))
3802        (memq article gnus-newsgroup-processable))
3803       (when length
3804         (gnus-data-update-list
3805          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3806
3807 (defun gnus-summary-update-article (article &optional iheader)
3808   "Update ARTICLE in the summary buffer."
3809   (set-buffer gnus-summary-buffer)
3810   (let* ((header (gnus-summary-article-header article))
3811          (id (mail-header-id header))
3812          (data (gnus-data-find article))
3813          (thread (gnus-id-to-thread id))
3814          (references (mail-header-references header))
3815          (parent
3816           (gnus-id-to-thread
3817            (or (gnus-parent-id
3818                 (when (and references
3819                            (not (equal "" references)))
3820                   references))
3821                "none")))
3822          (buffer-read-only nil)
3823          (old (car thread)))
3824     (when thread
3825       (unless iheader
3826         (setcar thread nil)
3827         (when parent
3828           (delq thread parent)))
3829       (if (gnus-summary-insert-subject id header)
3830        ;; Set the (possibly) new article number in the data structure.
3831           (gnus-data-set-number data (gnus-id-to-article id))
3832         (setcar thread old)
3833         nil))))
3834
3835 (defun gnus-rebuild-thread (id &optional line)
3836   "Rebuild the thread containing ID.
3837 If LINE, insert the rebuilt thread starting on line LINE."
3838   (let ((buffer-read-only nil)
3839         old-pos current thread data)
3840     (if (not gnus-show-threads)
3841         (setq thread (list (car (gnus-id-to-thread id))))
3842       ;; Get the thread this article is part of.
3843       (setq thread (gnus-remove-thread id)))
3844     (setq old-pos (gnus-point-at-bol))
3845     (setq current (save-excursion
3846                     (and (re-search-backward "[\r\n]" nil t)
3847                          (gnus-summary-article-number))))
3848     ;; If this is a gathered thread, we have to go some re-gathering.
3849     (when (stringp (car thread))
3850       (let ((subject (car thread))
3851             roots thr)
3852         (setq thread (cdr thread))
3853         (while thread
3854           (unless (memq (setq thr (gnus-id-to-thread
3855                                    (gnus-root-id
3856                                     (mail-header-id (caar thread)))))
3857                         roots)
3858             (push thr roots))
3859           (setq thread (cdr thread)))
3860         ;; We now have all (unique) roots.
3861         (if (= (length roots) 1)
3862             ;; All the loose roots are now one solid root.
3863             (setq thread (car roots))
3864           (setq thread (cons subject (gnus-sort-threads roots))))))
3865     (let (threads)
3866       ;; We then insert this thread into the summary buffer.
3867       (when line
3868         (goto-char (point-min))
3869         (forward-line (1- line)))
3870       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3871         (if gnus-show-threads
3872             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3873           (gnus-summary-prepare-unthreaded thread))
3874         (setq data (nreverse gnus-newsgroup-data))
3875         (setq threads gnus-newsgroup-threads))
3876       ;; We splice the new data into the data structure.
3877       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3878       ;;!!! then we want to insert at the beginning of the buffer.
3879       ;;!!! That happens to be true with Gnus now, but that may
3880       ;;!!! change in the future.  Perhaps.
3881       (gnus-data-enter-list
3882        (if line nil current) data (- (point) old-pos))
3883       (setq gnus-newsgroup-threads
3884             (nconc threads gnus-newsgroup-threads))
3885       (gnus-data-compute-positions))))
3886
3887 (defun gnus-number-to-header (number)
3888   "Return the header for article NUMBER."
3889   (let ((headers gnus-newsgroup-headers))
3890     (while (and headers
3891                 (not (= number (mail-header-number (car headers)))))
3892       (pop headers))
3893     (when headers
3894       (car headers))))
3895
3896 (defun gnus-parent-headers (in-headers &optional generation)
3897   "Return the headers of the GENERATIONeth parent of HEADERS."
3898   (unless generation
3899     (setq generation 1))
3900   (let ((parent t)
3901         (headers in-headers)
3902         references)
3903     (while (and parent
3904                 (not (zerop generation))
3905                 (setq references (mail-header-references headers)))
3906       (setq headers (if (and references
3907                              (setq parent (gnus-parent-id references)))
3908                         (car (gnus-id-to-thread parent))
3909                       nil))
3910       (decf generation))
3911     (and (not (eq headers in-headers))
3912          headers)))
3913
3914 (defun gnus-id-to-thread (id)
3915   "Return the (sub-)thread where ID appears."
3916   (gnus-gethash id gnus-newsgroup-dependencies))
3917
3918 (defun gnus-id-to-article (id)
3919   "Return the article number of ID."
3920   (let ((thread (gnus-id-to-thread id)))
3921     (when (and thread
3922                (car thread))
3923       (mail-header-number (car thread)))))
3924
3925 (defun gnus-id-to-header (id)
3926   "Return the article headers of ID."
3927   (car (gnus-id-to-thread id)))
3928
3929 (defun gnus-article-displayed-root-p (article)
3930   "Say whether ARTICLE is a root(ish) article."
3931   (let ((level (gnus-summary-thread-level article))
3932         (refs (mail-header-references  (gnus-summary-article-header article)))
3933         particle)
3934     (cond
3935      ((null level) nil)
3936      ((zerop level) t)
3937      ((null refs) t)
3938      ((null (gnus-parent-id refs)) t)
3939      ((and (= 1 level)
3940            (null (setq particle (gnus-id-to-article
3941                                  (gnus-parent-id refs))))
3942            (null (gnus-summary-thread-level particle)))))))
3943
3944 (defun gnus-root-id (id)
3945   "Return the id of the root of the thread where ID appears."
3946   (let (last-id prev)
3947     (while (and id (setq prev (car (gnus-id-to-thread id))))
3948       (setq last-id id
3949             id (gnus-parent-id (mail-header-references prev))))
3950     last-id))
3951
3952 (defun gnus-articles-in-thread (thread)
3953   "Return the list of articles in THREAD."
3954   (cons (mail-header-number (car thread))
3955         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3956
3957 (defun gnus-remove-thread (id &optional dont-remove)
3958   "Remove the thread that has ID in it."
3959   (let (headers thread last-id)
3960     ;; First go up in this thread until we find the root.
3961     (setq last-id (gnus-root-id id)
3962           headers (message-flatten-list (gnus-id-to-thread last-id)))
3963     ;; We have now found the real root of this thread.  It might have
3964     ;; been gathered into some loose thread, so we have to search
3965     ;; through the threads to find the thread we wanted.
3966     (let ((threads gnus-newsgroup-threads)
3967           sub)
3968       (while threads
3969         (setq sub (car threads))
3970         (if (stringp (car sub))
3971             ;; This is a gathered thread, so we look at the roots
3972             ;; below it to find whether this article is in this
3973             ;; gathered root.
3974             (progn
3975               (setq sub (cdr sub))
3976               (while sub
3977                 (when (member (caar sub) headers)
3978                   (setq thread (car threads)
3979                         threads nil
3980                         sub nil))
3981                 (setq sub (cdr sub))))
3982           ;; It's an ordinary thread, so we check it.
3983           (when (eq (car sub) (car headers))
3984             (setq thread sub
3985                   threads nil)))
3986         (setq threads (cdr threads)))
3987       ;; If this article is in no thread, then it's a root.
3988       (if thread
3989           (unless dont-remove
3990             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3991         (setq thread (gnus-id-to-thread last-id)))
3992       (when thread
3993         (prog1
3994             thread                      ; We return this thread.
3995           (unless dont-remove
3996             (if (stringp (car thread))
3997                 (progn
3998                   ;; If we use dummy roots, then we have to remove the
3999                   ;; dummy root as well.
4000                   (when (eq gnus-summary-make-false-root 'dummy)
4001                     ;; We go to the dummy root by going to
4002                     ;; the first sub-"thread", and then one line up.
4003                     (gnus-summary-goto-article
4004                      (mail-header-number (caadr thread)))
4005                     (forward-line -1)
4006                     (gnus-delete-line)
4007                     (gnus-data-compute-positions))
4008                   (setq thread (cdr thread))
4009                   (while thread
4010                     (gnus-remove-thread-1 (car thread))
4011                     (setq thread (cdr thread))))
4012               (gnus-remove-thread-1 thread))))))))
4013
4014 (defun gnus-remove-thread-1 (thread)
4015   "Remove the thread THREAD recursively."
4016   (let ((number (mail-header-number (pop thread)))
4017         d)
4018     (setq thread (reverse thread))
4019     (while thread
4020       (gnus-remove-thread-1 (pop thread)))
4021     (when (setq d (gnus-data-find number))
4022       (goto-char (gnus-data-pos d))
4023       (gnus-summary-show-thread)
4024       (gnus-data-remove
4025        number
4026        (- (gnus-point-at-bol)
4027           (prog1
4028               (1+ (gnus-point-at-eol))
4029             (gnus-delete-line)))))))
4030
4031 (defun gnus-sort-threads-1 (threads func)
4032   (sort (mapcar (lambda (thread)
4033                   (cons (car thread)
4034                         (and (cdr thread)
4035                              (gnus-sort-threads-1 (cdr thread) func))))
4036                 threads) func))
4037
4038 (defun gnus-sort-threads (threads)
4039   "Sort THREADS."
4040   (if (not gnus-thread-sort-functions)
4041       threads
4042     (gnus-message 8 "Sorting threads...")
4043     (prog1
4044         (gnus-sort-threads-1
4045          threads
4046          (gnus-make-sort-function gnus-thread-sort-functions))
4047       (gnus-message 8 "Sorting threads...done"))))
4048
4049 (defun gnus-sort-articles (articles)
4050   "Sort ARTICLES."
4051   (when gnus-article-sort-functions
4052     (gnus-message 7 "Sorting articles...")
4053     (prog1
4054         (setq gnus-newsgroup-headers
4055               (sort articles (gnus-make-sort-function
4056                               gnus-article-sort-functions)))
4057       (gnus-message 7 "Sorting articles...done"))))
4058
4059 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4060 (defmacro gnus-thread-header (thread)
4061   "Return header of first article in THREAD.
4062 Note that THREAD must never, ever be anything else than a variable -
4063 using some other form will lead to serious barfage."
4064   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4065   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4066   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4067         (vector thread) 2))
4068
4069 (defsubst gnus-article-sort-by-number (h1 h2)
4070   "Sort articles by article number."
4071   (< (mail-header-number h1)
4072      (mail-header-number h2)))
4073
4074 (defun gnus-thread-sort-by-number (h1 h2)
4075   "Sort threads by root article number."
4076   (gnus-article-sort-by-number
4077    (gnus-thread-header h1) (gnus-thread-header h2)))
4078
4079 (defsubst gnus-article-sort-by-lines (h1 h2)
4080   "Sort articles by article Lines header."
4081   (< (mail-header-lines h1)
4082      (mail-header-lines h2)))
4083
4084 (defun gnus-thread-sort-by-lines (h1 h2)
4085   "Sort threads by root article Lines header."
4086   (gnus-article-sort-by-lines
4087    (gnus-thread-header h1) (gnus-thread-header h2)))
4088
4089 (defsubst gnus-article-sort-by-chars (h1 h2)
4090   "Sort articles by octet length."
4091   (< (mail-header-chars h1)
4092      (mail-header-chars h2)))
4093
4094 (defun gnus-thread-sort-by-chars (h1 h2)
4095   "Sort threads by root article octet length."
4096   (gnus-article-sort-by-chars
4097    (gnus-thread-header h1) (gnus-thread-header h2)))
4098
4099 (defsubst gnus-article-sort-by-author (h1 h2)
4100   "Sort articles by root author."
4101   (string-lessp
4102    (let ((extract (funcall
4103                    gnus-extract-address-components
4104                    (mail-header-from h1))))
4105      (or (car extract) (cadr extract) ""))
4106    (let ((extract (funcall
4107                    gnus-extract-address-components
4108                    (mail-header-from h2))))
4109      (or (car extract) (cadr extract) ""))))
4110
4111 (defun gnus-thread-sort-by-author (h1 h2)
4112   "Sort threads by root author."
4113   (gnus-article-sort-by-author
4114    (gnus-thread-header h1)  (gnus-thread-header h2)))
4115
4116 (defsubst gnus-article-sort-by-subject (h1 h2)
4117   "Sort articles by root subject."
4118   (string-lessp
4119    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4120    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4121
4122 (defun gnus-thread-sort-by-subject (h1 h2)
4123   "Sort threads by root subject."
4124   (gnus-article-sort-by-subject
4125    (gnus-thread-header h1) (gnus-thread-header h2)))
4126
4127 (defsubst gnus-article-sort-by-date (h1 h2)
4128   "Sort articles by root article date."
4129   (time-less-p
4130    (gnus-date-get-time (mail-header-date h1))
4131    (gnus-date-get-time (mail-header-date h2))))
4132
4133 (defun gnus-thread-sort-by-date (h1 h2)
4134   "Sort threads by root article date."
4135   (gnus-article-sort-by-date
4136    (gnus-thread-header h1) (gnus-thread-header h2)))
4137
4138 (defsubst gnus-article-sort-by-score (h1 h2)
4139   "Sort articles by root article score.
4140 Unscored articles will be counted as having a score of zero."
4141   (> (or (cdr (assq (mail-header-number h1)
4142                     gnus-newsgroup-scored))
4143          gnus-summary-default-score 0)
4144      (or (cdr (assq (mail-header-number h2)
4145                     gnus-newsgroup-scored))
4146          gnus-summary-default-score 0)))
4147
4148 (defun gnus-thread-sort-by-score (h1 h2)
4149   "Sort threads by root article score."
4150   (gnus-article-sort-by-score
4151    (gnus-thread-header h1) (gnus-thread-header h2)))
4152
4153 (defun gnus-thread-sort-by-total-score (h1 h2)
4154   "Sort threads by the sum of all scores in the thread.
4155 Unscored articles will be counted as having a score of zero."
4156   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4157
4158 (defun gnus-thread-total-score (thread)
4159   ;; This function find the total score of THREAD.
4160   (cond
4161    ((null thread)
4162     0)
4163    ((consp thread)
4164     (if (stringp (car thread))
4165         (apply gnus-thread-score-function 0
4166                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4167       (gnus-thread-total-score-1 thread)))
4168    (t
4169     (gnus-thread-total-score-1 (list thread)))))
4170
4171 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4172   "Sort threads such that the thread with the most recently arrived article comes first."
4173   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4174
4175 (defun gnus-thread-highest-number (thread)
4176   "Return the highest article number in THREAD."
4177   (apply 'max (mapcar (lambda (header)
4178                         (mail-header-number header))
4179                       (message-flatten-list thread))))
4180
4181 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4182   "Sort threads such that the thread with the most recently dated article comes first."
4183   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4184
4185 (defun gnus-thread-latest-date (thread)
4186   "Return the highest article date in THREAD."
4187   (let ((previous-time 0))
4188     (apply 'max (mapcar
4189                  (lambda (header)
4190                    (setq previous-time
4191                          (time-to-seconds
4192                           (mail-header-parse-date
4193                            (condition-case ()
4194                                (mail-header-date header)
4195                              (error previous-time))))))
4196                  (sort
4197                   (message-flatten-list thread)
4198                   (lambda (h1 h2)
4199                     (< (mail-header-number h1)
4200                        (mail-header-number h2))))))))
4201
4202 (defun gnus-thread-total-score-1 (root)
4203   ;; This function find the total score of the thread below ROOT.
4204   (setq root (car root))
4205   (apply gnus-thread-score-function
4206          (or (append
4207               (mapcar 'gnus-thread-total-score
4208                       (cdr (gnus-id-to-thread (mail-header-id root))))
4209               (when (> (mail-header-number root) 0)
4210                 (list (or (cdr (assq (mail-header-number root)
4211                                      gnus-newsgroup-scored))
4212                           gnus-summary-default-score 0))))
4213              (list gnus-summary-default-score)
4214              '(0))))
4215
4216 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4217 (defvar gnus-tmp-prev-subject nil)
4218 (defvar gnus-tmp-false-parent nil)
4219 (defvar gnus-tmp-root-expunged nil)
4220 (defvar gnus-tmp-dummy-line nil)
4221
4222 (eval-when-compile (defvar gnus-tmp-header))
4223 (defun gnus-extra-header (type &optional header)
4224   "Return the extra header of TYPE."
4225   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4226       ""))
4227
4228 (defvar gnus-tmp-thread-tree-header-string "")
4229
4230 (defvar gnus-sum-thread-tree-root "> "
4231   "With %B spec, used for the root of a thread.
4232 If nil, use subject instead.")
4233 (defvar gnus-sum-thread-tree-single-indent ""
4234   "With %B spec, used for a thread with just one message.
4235 If nil, use subject instead.")
4236 (defvar gnus-sum-thread-tree-vertical "| "
4237   "With %B spec, used for drawing a vertical line.")
4238 (defvar gnus-sum-thread-tree-indent "  "
4239   "With %B spec, used for indenting.")
4240 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4241   "With %B spec, used for a leaf with brothers.")
4242 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4243   "With %B spec, used for a leaf without brothers.")
4244
4245 (defun gnus-summary-prepare-threads (threads)
4246   "Prepare summary buffer from THREADS and indentation LEVEL.
4247 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4248 or a straight list of headers."
4249   (gnus-message 7 "Generating summary...")
4250
4251   (setq gnus-newsgroup-threads threads)
4252   (beginning-of-line)
4253
4254   (let ((gnus-tmp-level 0)
4255         (default-score (or gnus-summary-default-score 0))
4256         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4257         thread number subject stack state gnus-tmp-gathered beg-match
4258         new-roots gnus-tmp-new-adopts thread-end
4259         gnus-tmp-header gnus-tmp-unread
4260         gnus-tmp-replied gnus-tmp-subject-or-nil
4261         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4262         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4263         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4264         tree-stack)
4265
4266     (setq gnus-tmp-prev-subject nil)
4267
4268     (if (vectorp (car threads))
4269         ;; If this is a straight (sic) list of headers, then a
4270         ;; threaded summary display isn't required, so we just create
4271         ;; an unthreaded one.
4272         (gnus-summary-prepare-unthreaded threads)
4273
4274       ;; Do the threaded display.
4275
4276       (while (or threads stack gnus-tmp-new-adopts new-roots)
4277
4278         (if (and (= gnus-tmp-level 0)
4279                  (or (not stack)
4280                      (= (caar stack) 0))
4281                  (not gnus-tmp-false-parent)
4282                  (or gnus-tmp-new-adopts new-roots))
4283             (if gnus-tmp-new-adopts
4284                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4285                       thread (list (car gnus-tmp-new-adopts))
4286                       gnus-tmp-header (caar thread)
4287                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4288               (when new-roots
4289                 (setq thread (list (car new-roots))
4290                       gnus-tmp-header (caar thread)
4291                       new-roots (cdr new-roots))))
4292
4293           (if threads
4294               ;; If there are some threads, we do them before the
4295               ;; threads on the stack.
4296               (setq thread threads
4297                     gnus-tmp-header (caar thread))
4298             ;; There were no current threads, so we pop something off
4299             ;; the stack.
4300             (setq state (car stack)
4301                   gnus-tmp-level (car state)
4302                   tree-stack (cadr state)
4303                   thread (caddr state)
4304                   stack (cdr stack)
4305                   gnus-tmp-header (caar thread))))
4306
4307         (setq gnus-tmp-false-parent nil)
4308         (setq gnus-tmp-root-expunged nil)
4309         (setq thread-end nil)
4310
4311         (if (stringp gnus-tmp-header)
4312             ;; The header is a dummy root.
4313             (cond
4314              ((eq gnus-summary-make-false-root 'adopt)
4315               ;; We let the first article adopt the rest.
4316               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4317                                                (cddar thread)))
4318               (setq gnus-tmp-gathered
4319                     (nconc (mapcar
4320                             (lambda (h) (mail-header-number (car h)))
4321                             (cddar thread))
4322                            gnus-tmp-gathered))
4323               (setq thread (cons (list (caar thread)
4324                                        (cadar thread))
4325                                  (cdr thread)))
4326               (setq gnus-tmp-level -1
4327                     gnus-tmp-false-parent t))
4328              ((eq gnus-summary-make-false-root 'empty)
4329               ;; We print adopted articles with empty subject fields.
4330               (setq gnus-tmp-gathered
4331                     (nconc (mapcar
4332                             (lambda (h) (mail-header-number (car h)))
4333                             (cddar thread))
4334                            gnus-tmp-gathered))
4335               (setq gnus-tmp-level -1))
4336              ((eq gnus-summary-make-false-root 'dummy)
4337               ;; We remember that we probably want to output a dummy
4338               ;; root.
4339               (setq gnus-tmp-dummy-line gnus-tmp-header)
4340               (setq gnus-tmp-prev-subject gnus-tmp-header))
4341              (t
4342               ;; We do not make a root for the gathered
4343               ;; sub-threads at all.
4344               (setq gnus-tmp-level -1)))
4345
4346           (setq number (mail-header-number gnus-tmp-header)
4347                 subject (mail-header-subject gnus-tmp-header))
4348
4349           (cond
4350            ;; If the thread has changed subject, we might want to make
4351            ;; this subthread into a root.
4352            ((and (null gnus-thread-ignore-subject)
4353                  (not (zerop gnus-tmp-level))
4354                  gnus-tmp-prev-subject
4355                  (not (inline
4356                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4357             (setq new-roots (nconc new-roots (list (car thread)))
4358                   thread-end t
4359                   gnus-tmp-header nil))
4360            ;; If the article lies outside the current limit,
4361            ;; then we do not display it.
4362            ((not (memq number gnus-newsgroup-limit))
4363             (setq gnus-tmp-gathered
4364                   (nconc (mapcar
4365                           (lambda (h) (mail-header-number (car h)))
4366                           (cdar thread))
4367                          gnus-tmp-gathered))
4368             (setq gnus-tmp-new-adopts (if (cdar thread)
4369                                           (append gnus-tmp-new-adopts
4370                                                   (cdar thread))
4371                                         gnus-tmp-new-adopts)
4372                   thread-end t
4373                   gnus-tmp-header nil)
4374             (when (zerop gnus-tmp-level)
4375               (setq gnus-tmp-root-expunged t)))
4376            ;; Perhaps this article is to be marked as read?
4377            ((and gnus-summary-mark-below
4378                  (< (or (cdr (assq number gnus-newsgroup-scored))
4379                         default-score)
4380                     gnus-summary-mark-below)
4381                  ;; Don't touch sparse articles.
4382                  (not (gnus-summary-article-sparse-p number))
4383                  (not (gnus-summary-article-ancient-p number)))
4384             (setq gnus-newsgroup-unreads
4385                   (delq number gnus-newsgroup-unreads))
4386             (if gnus-newsgroup-auto-expire
4387                 (push number gnus-newsgroup-expirable)
4388               (push (cons number gnus-low-score-mark)
4389                     gnus-newsgroup-reads))))
4390
4391           (when gnus-tmp-header
4392             ;; We may have an old dummy line to output before this
4393             ;; article.
4394             (when (and gnus-tmp-dummy-line
4395                        (gnus-subject-equal
4396                         gnus-tmp-dummy-line
4397                         (mail-header-subject gnus-tmp-header)))
4398               (gnus-summary-insert-dummy-line
4399                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4400               (setq gnus-tmp-dummy-line nil))
4401
4402             ;; Compute the mark.
4403             (setq gnus-tmp-unread (gnus-article-mark number))
4404
4405             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4406                                   gnus-tmp-header gnus-tmp-level)
4407                   gnus-newsgroup-data)
4408
4409             ;; Actually insert the line.
4410             (setq
4411              gnus-tmp-subject-or-nil
4412              (cond
4413               ((and gnus-thread-ignore-subject
4414                     gnus-tmp-prev-subject
4415                     (not (inline (gnus-subject-equal
4416                                   gnus-tmp-prev-subject subject))))
4417                subject)
4418               ((zerop gnus-tmp-level)
4419                (if (and (eq gnus-summary-make-false-root 'empty)
4420                         (memq number gnus-tmp-gathered)
4421                         gnus-tmp-prev-subject
4422                         (inline (gnus-subject-equal
4423                                  gnus-tmp-prev-subject subject)))
4424                    gnus-summary-same-subject
4425                  subject))
4426               (t gnus-summary-same-subject)))
4427             (if (and (eq gnus-summary-make-false-root 'adopt)
4428                      (= gnus-tmp-level 1)
4429                      (memq number gnus-tmp-gathered))
4430                 (setq gnus-tmp-opening-bracket ?\<
4431                       gnus-tmp-closing-bracket ?\>)
4432               (setq gnus-tmp-opening-bracket ?\[
4433                     gnus-tmp-closing-bracket ?\]))
4434             (setq
4435              gnus-tmp-indentation
4436              (aref gnus-thread-indent-array gnus-tmp-level)
4437              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4438              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4439                                 gnus-summary-default-score 0)
4440              gnus-tmp-score-char
4441              (if (or (null gnus-summary-default-score)
4442                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4443                          gnus-summary-zcore-fuzz))
4444                  ?                      ;Whitespace
4445                (if (< gnus-tmp-score gnus-summary-default-score)
4446                    gnus-score-below-mark gnus-score-over-mark))
4447              gnus-tmp-replied
4448              (cond ((memq number gnus-newsgroup-processable)
4449                     gnus-process-mark)
4450                    ((memq number gnus-newsgroup-cached)
4451                     gnus-cached-mark)
4452                    ((memq number gnus-newsgroup-replied)
4453                     gnus-replied-mark)
4454                    ((memq number gnus-newsgroup-forwarded)
4455                     gnus-forwarded-mark)
4456                    ((memq number gnus-newsgroup-saved)
4457                     gnus-saved-mark)
4458                    ((memq number gnus-newsgroup-recent)
4459                     gnus-recent-mark)
4460                    ((memq number gnus-newsgroup-unseen)
4461                     gnus-unseen-mark)
4462                    (t gnus-no-mark))
4463              gnus-tmp-from (mail-header-from gnus-tmp-header)
4464              gnus-tmp-name
4465              (cond
4466               ((string-match "<[^>]+> *$" gnus-tmp-from)
4467                (setq beg-match (match-beginning 0))
4468                (or (and (string-match "^\".+\"" gnus-tmp-from)
4469                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4470                    (substring gnus-tmp-from 0 beg-match)))
4471               ((string-match "(.+)" gnus-tmp-from)
4472                (substring gnus-tmp-from
4473                           (1+ (match-beginning 0)) (1- (match-end 0))))
4474               (t gnus-tmp-from))
4475              gnus-tmp-thread-tree-header-string
4476              (cond
4477               ((not gnus-show-threads) "")
4478               ((zerop gnus-tmp-level)
4479                (if (cdar thread)
4480                    (or gnus-sum-thread-tree-root subject)
4481                  (or gnus-sum-thread-tree-single-indent subject)))
4482               (t
4483                (concat (apply 'concat
4484                               (mapcar (lambda (item)
4485                                         (if (= item 1)
4486                                             gnus-sum-thread-tree-vertical
4487                                           gnus-sum-thread-tree-indent))
4488                                       (cdr (reverse tree-stack))))
4489                        (if (nth 1 thread)
4490                            gnus-sum-thread-tree-leaf-with-other
4491                          gnus-sum-thread-tree-single-leaf)))))
4492             (when (string= gnus-tmp-name "")
4493               (setq gnus-tmp-name gnus-tmp-from))
4494             (unless (numberp gnus-tmp-lines)
4495               (setq gnus-tmp-lines -1))
4496             (if (= gnus-tmp-lines -1)
4497                 (setq gnus-tmp-lines "?")
4498               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4499             (gnus-put-text-property
4500              (point)
4501              (progn (eval gnus-summary-line-format-spec) (point))
4502              'gnus-number number)
4503             (when gnus-visual-p
4504               (forward-line -1)
4505               (gnus-run-hooks 'gnus-summary-update-hook)
4506               (forward-line 1))
4507
4508             (setq gnus-tmp-prev-subject subject)))
4509
4510         (when (nth 1 thread)
4511           (push (list (max 0 gnus-tmp-level)
4512                       (copy-list tree-stack)
4513                       (nthcdr 1 thread))
4514                 stack))
4515         (push (if (nth 1 thread) 1 0) tree-stack)
4516         (incf gnus-tmp-level)
4517         (setq threads (if thread-end nil (cdar thread)))
4518         (unless threads
4519           (setq gnus-tmp-level 0)))))
4520   (gnus-message 7 "Generating summary...done"))
4521
4522 (defun gnus-summary-prepare-unthreaded (headers)
4523   "Generate an unthreaded summary buffer based on HEADERS."
4524   (let (header number mark)
4525
4526     (beginning-of-line)
4527
4528     (while headers
4529       ;; We may have to root out some bad articles...
4530       (when (memq (setq number (mail-header-number
4531                                 (setq header (pop headers))))
4532                   gnus-newsgroup-limit)
4533         ;; Mark article as read when it has a low score.
4534         (when (and gnus-summary-mark-below
4535                    (< (or (cdr (assq number gnus-newsgroup-scored))
4536                           gnus-summary-default-score 0)
4537                       gnus-summary-mark-below)
4538                    (not (gnus-summary-article-ancient-p number)))
4539           (setq gnus-newsgroup-unreads
4540                 (delq number gnus-newsgroup-unreads))
4541           (if gnus-newsgroup-auto-expire
4542               (push number gnus-newsgroup-expirable)
4543             (push (cons number gnus-low-score-mark)
4544                   gnus-newsgroup-reads)))
4545
4546         (setq mark (gnus-article-mark number))
4547         (push (gnus-data-make number mark (1+ (point)) header 0)
4548               gnus-newsgroup-data)
4549         (gnus-summary-insert-line
4550          header 0 number
4551          mark (memq number gnus-newsgroup-replied)
4552          (memq number gnus-newsgroup-expirable)
4553          (mail-header-subject header) nil
4554          (cdr (assq number gnus-newsgroup-scored))
4555          (memq number gnus-newsgroup-processable))))))
4556
4557 (defun gnus-summary-remove-list-identifiers ()
4558   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4559   (let ((regexp (if (consp gnus-list-identifiers)
4560                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4561                   gnus-list-identifiers))
4562         changed subject)
4563     (when regexp
4564       (dolist (header gnus-newsgroup-headers)
4565         (setq subject (mail-header-subject header)
4566               changed nil)
4567         (while (string-match
4568                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4569                 subject)
4570           (setq subject
4571                 (concat (substring subject 0 (match-beginning 2))
4572                         (substring subject (match-end 0)))
4573                 changed t))
4574         (when (and changed
4575                    (string-match
4576                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4577           (setq subject
4578                 (concat (substring subject 0 (match-beginning 1))
4579                         (substring subject (match-end 1)))))
4580         (when changed
4581           (mail-header-set-subject header subject))))))
4582
4583 (defun gnus-fetch-headers (articles)
4584   "Fetch headers of ARTICLES."
4585   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4586     (gnus-message 5 "Fetching headers for %s..." name)
4587     (prog1
4588         (if (eq 'nov
4589                 (setq gnus-headers-retrieved-by
4590                       (gnus-retrieve-headers
4591                        articles gnus-newsgroup-name
4592                        ;; We might want to fetch old headers, but
4593                        ;; not if there is only 1 article.
4594                        (and (or (and
4595                                  (not (eq gnus-fetch-old-headers 'some))
4596                                  (not (numberp gnus-fetch-old-headers)))
4597                                 (> (length articles) 1))
4598                             gnus-fetch-old-headers))))
4599             (gnus-get-newsgroup-headers-xover
4600              articles nil nil gnus-newsgroup-name t)
4601           (gnus-get-newsgroup-headers))
4602       (gnus-message 5 "Fetching headers for %s...done" name))))
4603
4604 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4605   "Select newsgroup GROUP.
4606 If READ-ALL is non-nil, all articles in the group are selected.
4607 If SELECT-ARTICLES, only select those articles from GROUP."
4608   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4609          ;;!!! Dirty hack; should be removed.
4610          (gnus-summary-ignore-duplicates
4611           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4612               t
4613             gnus-summary-ignore-duplicates))
4614          (info (nth 2 entry))
4615          articles fetched-articles cached)
4616
4617     (unless (gnus-check-server
4618              (set (make-local-variable 'gnus-current-select-method)
4619                   (gnus-find-method-for-group group)))
4620       (error "Couldn't open server"))
4621
4622     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4623         (gnus-activate-group group)     ; Or we can activate it...
4624         (progn                          ; Or we bug out.
4625           (when (equal major-mode 'gnus-summary-mode)
4626             (kill-buffer (current-buffer)))
4627           (error "Couldn't activate group %s: %s"
4628                  group (gnus-status-message group))))
4629
4630     (unless (gnus-request-group group t)
4631       (when (equal major-mode 'gnus-summary-mode)
4632         (kill-buffer (current-buffer)))
4633       (error "Couldn't request group %s: %s"
4634              group (gnus-status-message group)))
4635
4636     (setq gnus-newsgroup-name group
4637           gnus-newsgroup-unselected nil
4638           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4639
4640     (let ((display (gnus-group-find-parameter group 'display)))
4641       (setq gnus-newsgroup-display
4642             (cond
4643              ((not (zerop (or (car-safe read-all) 0)))
4644               ;; The user entered the group with C-u SPC/RET, let's show
4645               ;; all articles.
4646               'gnus-not-ignore)
4647              ((eq display 'all)
4648               'gnus-not-ignore)
4649              ((arrayp display)
4650               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4651              ((numberp display)
4652               ;; The following is probably the "correct" solution, but
4653               ;; it makes Gnus fetch all headers and then limit the
4654               ;; articles (which is slow), so instead we hack the
4655               ;; select-articles parameter instead. -- Simon Josefsson
4656               ;; <jas@kth.se>
4657               ;;
4658               ;; (gnus-byte-compile
4659               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4660               ;;                         display)))))
4661               (setq select-articles
4662                     (gnus-uncompress-range
4663                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4664                              (if (> tmp 0)
4665                                  tmp
4666                                1))
4667                            (cdr (gnus-active group)))))
4668               nil)
4669              (t
4670               nil))))
4671
4672     (gnus-summary-setup-default-charset)
4673
4674     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4675     (when (gnus-virtual-group-p group)
4676       (setq cached gnus-newsgroup-cached))
4677
4678     (setq gnus-newsgroup-unreads
4679           (gnus-set-difference
4680            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4681            gnus-newsgroup-dormant))
4682
4683     (setq gnus-newsgroup-processable nil)
4684
4685     (gnus-update-read-articles group gnus-newsgroup-unreads)
4686
4687     ;; Adjust and set lists of article marks.
4688     (when info
4689       (gnus-adjust-marked-articles info))
4690
4691     (if (setq articles select-articles)
4692         (setq gnus-newsgroup-unselected
4693               (gnus-sorted-intersection
4694                gnus-newsgroup-unreads
4695                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4696       (setq articles (gnus-articles-to-read group read-all)))
4697
4698     (cond
4699      ((null articles)
4700       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4701       'quit)
4702      ((eq articles 0) nil)
4703      (t
4704       ;; Init the dependencies hash table.
4705       (setq gnus-newsgroup-dependencies
4706             (gnus-make-hashtable (length articles)))
4707       (gnus-set-global-variables)
4708       ;; Retrieve the headers and read them in.
4709       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4710
4711       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4712       (when cached
4713         (setq gnus-newsgroup-cached cached))
4714
4715       ;; Suppress duplicates?
4716       (when gnus-suppress-duplicates
4717         (gnus-dup-suppress-articles))
4718
4719       ;; Set the initial limit.
4720       (setq gnus-newsgroup-limit (copy-sequence articles))
4721       ;; Remove canceled articles from the list of unread articles.
4722       (setq fetched-articles
4723             (mapcar (lambda (headers) (mail-header-number headers))
4724                     gnus-newsgroup-headers))
4725       (setq gnus-newsgroup-articles fetched-articles)
4726       (setq gnus-newsgroup-unreads
4727             (gnus-set-sorted-intersection
4728              gnus-newsgroup-unreads fetched-articles))
4729
4730       ;; The `seen' marks are treated specially.
4731       (if (not gnus-newsgroup-seen)
4732           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4733         (dolist (article gnus-newsgroup-articles)
4734           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4735             (push article gnus-newsgroup-unseen)))
4736         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4737
4738       ;; Removed marked articles that do not exist.
4739       (gnus-update-missing-marks
4740        (gnus-sorted-complement fetched-articles articles))
4741       ;; We might want to build some more threads first.
4742       (when (and gnus-fetch-old-headers
4743                  (eq gnus-headers-retrieved-by 'nov))
4744         (if (eq gnus-fetch-old-headers 'invisible)
4745             (gnus-build-all-threads)
4746           (gnus-build-old-threads)))
4747       ;; Let the Gnus agent mark articles as read.
4748       (when gnus-agent
4749         (gnus-agent-get-undownloaded-list))
4750       ;; Remove list identifiers from subject
4751       (when gnus-list-identifiers
4752         (gnus-summary-remove-list-identifiers))
4753       ;; Check whether auto-expire is to be done in this group.
4754       (setq gnus-newsgroup-auto-expire
4755             (gnus-group-auto-expirable-p group))
4756       ;; Set up the article buffer now, if necessary.
4757       (unless gnus-single-article-buffer
4758         (gnus-article-setup-buffer))
4759       ;; First and last article in this newsgroup.
4760       (when gnus-newsgroup-headers
4761         (setq gnus-newsgroup-begin
4762               (mail-header-number (car gnus-newsgroup-headers))
4763               gnus-newsgroup-end
4764               (mail-header-number
4765                (gnus-last-element gnus-newsgroup-headers))))
4766       ;; GROUP is successfully selected.
4767       (or gnus-newsgroup-headers t)))))
4768
4769 (defun gnus-summary-display-make-predicate (display)
4770   (require 'gnus-agent)
4771   (when (= (length display) 1)
4772     (setq display (car display)))
4773   (unless gnus-summary-display-cache
4774     (dolist (elem (append (list (cons 'read 'read)
4775                                 (cons 'unseen 'unseen))
4776                           gnus-article-mark-lists))
4777       (push (cons (cdr elem)
4778                   (gnus-byte-compile
4779                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4780             gnus-summary-display-cache)))
4781   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4782     (gnus-get-predicate display)))
4783
4784 ;; Uses the dynamically bound `number' variable.
4785 (defvar number)
4786 (defun gnus-article-marked-p (type &optional article)
4787   (let ((article (or article number)))
4788     (cond
4789      ((eq type 'tick)
4790       (memq article gnus-newsgroup-marked))
4791      ((eq type 'unsend)
4792       (memq article gnus-newsgroup-unsendable))
4793      ((eq type 'undownload)
4794       (memq article gnus-newsgroup-undownloaded))
4795      ((eq type 'download)
4796       (memq article gnus-newsgroup-downloadable))
4797      ((eq type 'unread)
4798       (memq article gnus-newsgroup-unreads))
4799      ((eq type 'read)
4800       (memq article gnus-newsgroup-reads))
4801      ((eq type 'dormant)
4802       (memq article gnus-newsgroup-dormant) )
4803      ((eq type 'expire)
4804       (memq article gnus-newsgroup-expirable))
4805      ((eq type 'reply)
4806       (memq article gnus-newsgroup-replied))
4807      ((eq type 'killed)
4808       (memq article gnus-newsgroup-killed))
4809      ((eq type 'bookmark)
4810       (assq article gnus-newsgroup-bookmarks))
4811      ((eq type 'score)
4812       (assq article gnus-newsgroup-scored))
4813      ((eq type 'save)
4814       (memq article gnus-newsgroup-saved))
4815      ((eq type 'cache)
4816       (memq article gnus-newsgroup-cached))
4817      ((eq type 'forward)
4818       (memq article gnus-newsgroup-forwarded))
4819      ((eq type 'seen)
4820       (not (memq article gnus-newsgroup-unseen)))
4821      ((eq type 'recent)
4822       (memq article gnus-newsgroup-recent))
4823      (t t))))
4824
4825 (defun gnus-articles-to-read (group &optional read-all)
4826   "Find out what articles the user wants to read."
4827   (let* ((articles
4828           ;; Select all articles if `read-all' is non-nil, or if there
4829           ;; are no unread articles.
4830           (if (or read-all
4831                   (and (zerop (length gnus-newsgroup-marked))
4832                        (zerop (length gnus-newsgroup-unreads)))
4833                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4834               ;; We want to select the headers for all the articles in
4835               ;; the group, so we select either all the active
4836               ;; articles in the group, or (if that's nil), the
4837               ;; articles in the cache.
4838               (or
4839                (gnus-uncompress-range (gnus-active group))
4840                (gnus-cache-articles-in-group group))
4841             ;; Select only the "normal" subset of articles.
4842             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4843                           (copy-sequence gnus-newsgroup-unreads))
4844                   '<)))
4845          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4846          (scored (length scored-list))
4847          (number (length articles))
4848          (marked (+ (length gnus-newsgroup-marked)
4849                     (length gnus-newsgroup-dormant)))
4850          (select
4851           (cond
4852            ((numberp read-all)
4853             read-all)
4854            (t
4855             (condition-case ()
4856                 (cond
4857                  ((and (or (<= scored marked) (= scored number))
4858                        (numberp gnus-large-newsgroup)
4859                        (> number gnus-large-newsgroup))
4860                   (let ((input
4861                          (read-string
4862                           (format
4863                            "How many articles from %s (default %d): "
4864                            (gnus-limit-string
4865                             (gnus-group-decoded-name gnus-newsgroup-name)
4866                             35)
4867                            number))))
4868                     (if (string-match "^[ \t]*$" input) number input)))
4869                  ((and (> scored marked) (< scored number)
4870                        (> (- scored number) 20))
4871                   (let ((input
4872                          (read-string
4873                           (format "%s %s (%d scored, %d total): "
4874                                   "How many articles from"
4875                                   (gnus-group-decoded-name group)
4876                                   scored number))))
4877                     (if (string-match "^[ \t]*$" input)
4878                         number input)))
4879                  (t number))
4880               (quit
4881                (message "Quit getting the articles to read")
4882                nil))))))
4883     (setq select (if (stringp select) (string-to-number select) select))
4884     (if (or (null select) (zerop select))
4885         select
4886       (if (and (not (zerop scored)) (<= (abs select) scored))
4887           (progn
4888             (setq articles (sort scored-list '<))
4889             (setq number (length articles)))
4890         (setq articles (copy-sequence articles)))
4891
4892       (when (< (abs select) number)
4893         (if (< select 0)
4894             ;; Select the N oldest articles.
4895             (setcdr (nthcdr (1- (abs select)) articles) nil)
4896           ;; Select the N most recent articles.
4897           (setq articles (nthcdr (- number select) articles))))
4898       (setq gnus-newsgroup-unselected
4899             (gnus-sorted-intersection
4900              gnus-newsgroup-unreads
4901              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4902       (when gnus-alter-articles-to-read-function
4903         (setq gnus-newsgroup-unreads
4904               (sort
4905                (funcall gnus-alter-articles-to-read-function
4906                         gnus-newsgroup-name gnus-newsgroup-unreads)
4907                '<)))
4908       articles)))
4909
4910 (defun gnus-killed-articles (killed articles)
4911   (let (out)
4912     (while articles
4913       (when (inline (gnus-member-of-range (car articles) killed))
4914         (push (car articles) out))
4915       (setq articles (cdr articles)))
4916     out))
4917
4918 (defun gnus-uncompress-marks (marks)
4919   "Uncompress the mark ranges in MARKS."
4920   (let ((uncompressed '(score bookmark))
4921         out)
4922     (while marks
4923       (if (memq (caar marks) uncompressed)
4924           (push (car marks) out)
4925         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4926       (setq marks (cdr marks)))
4927     out))
4928
4929 (defun gnus-article-mark-to-type (mark)
4930   "Return the type of MARK."
4931   (or (cadr (assq mark gnus-article-special-mark-lists))
4932       'list))
4933
4934 (defun gnus-article-unpropagatable-p (mark)
4935   "Return whether MARK should be propagated to backend."
4936   (memq mark gnus-article-unpropagated-mark-lists))
4937
4938 (defun gnus-adjust-marked-articles (info)
4939   "Set all article lists and remove all marks that are no longer valid."
4940   (let* ((marked-lists (gnus-info-marks info))
4941          (active (gnus-active (gnus-info-group info)))
4942          (min (car active))
4943          (max (cdr active))
4944          (types gnus-article-mark-lists)
4945          marks var articles article mark mark-type)
4946
4947     (dolist (marks marked-lists)
4948       (setq mark (car marks)
4949             mark-type (gnus-article-mark-to-type mark)
4950             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4951
4952       ;; We set the variable according to the type of the marks list,
4953       ;; and then adjust the marks to a subset of the active articles.
4954       (cond
4955        ;; Adjust "simple" lists.
4956        ((eq mark-type 'list)
4957         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4958         (when (memq mark '(tick dormant expire reply save))
4959           (while articles
4960             (when (or (< (setq article (pop articles)) min) (> article max))
4961               (set var (delq article (symbol-value var)))))))
4962        ;; Adjust assocs.
4963        ((eq mark-type 'tuple)
4964         (set var (setq articles (cdr marks)))
4965         (when (not (listp (cdr (symbol-value var))))
4966           (set var (list (symbol-value var))))
4967         (when (not (listp (cdr articles)))
4968           (setq articles (list articles)))
4969         (while articles
4970           (when (or (not (consp (setq article (pop articles))))
4971                     (< (car article) min)
4972                     (> (car article) max))
4973             (set var (delq article (symbol-value var))))))
4974        ;; Adjust ranges (sloppily).
4975        ((eq mark-type 'range)
4976         (cond
4977          ((eq mark 'seen)
4978           (setq articles (cdr marks))
4979           (while (and articles
4980                       (or (and (consp (car articles))
4981                                (> min (cdar articles)))
4982                           (and (numberp (car articles))
4983                                (> min (car articles)))))
4984             (pop articles))
4985           (set var articles))))))))
4986
4987 (defun gnus-update-missing-marks (missing)
4988   "Go through the list of MISSING articles and remove them from the mark lists."
4989   (when missing
4990     (let (var m)
4991       ;; Go through all types.
4992       (dolist (elem gnus-article-mark-lists)
4993         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4994           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4995           (when (symbol-value var)
4996             ;; This list has articles.  So we delete all missing
4997             ;; articles from it.
4998             (setq m missing)
4999             (while m
5000               (set var (delq (pop m) (symbol-value var))))))))))
5001
5002 (defun gnus-update-marks ()
5003   "Enter the various lists of marked articles into the newsgroup info list."
5004   (let ((types gnus-article-mark-lists)
5005         (info (gnus-get-info gnus-newsgroup-name))
5006         type list newmarked symbol delta-marks)
5007     (when info
5008       ;; Add all marks lists to the list of marks lists.
5009       (while (setq type (pop types))
5010         (setq list (symbol-value
5011                     (setq symbol
5012                           (intern (format "gnus-newsgroup-%s" (car type))))))
5013
5014         (when list
5015           ;; Get rid of the entries of the articles that have the
5016           ;; default score.
5017           (when (and (eq (cdr type) 'score)
5018                      gnus-save-score
5019                      list)
5020             (let* ((arts list)
5021                    (prev (cons nil list))
5022                    (all prev))
5023               (while arts
5024                 (if (or (not (consp (car arts)))
5025                         (= (cdar arts) gnus-summary-default-score))
5026                     (setcdr prev (cdr arts))
5027                   (setq prev arts))
5028                 (setq arts (cdr arts)))
5029               (setq list (cdr all)))))
5030
5031         (when (eq (cdr type) 'seen)
5032           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5033
5034         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5035           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5036
5037         (when (and (gnus-check-backend-function
5038                     'request-set-mark gnus-newsgroup-name)
5039                    (not (gnus-article-unpropagatable-p (cdr type))))
5040           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5041                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5042                  (add (gnus-remove-from-range
5043                        (gnus-copy-sequence list) old)))
5044             (when add
5045               (push (list add 'add (list (cdr type))) delta-marks))
5046             (when del
5047               (push (list del 'del (list (cdr type))) delta-marks))))
5048
5049         (when list
5050           (push (cons (cdr type) list) newmarked)))
5051
5052       (when delta-marks
5053         (unless (gnus-check-group gnus-newsgroup-name)
5054           (error "Can't open server for %s" gnus-newsgroup-name))
5055         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5056
5057       ;; Enter these new marks into the info of the group.
5058       (if (nthcdr 3 info)
5059           (setcar (nthcdr 3 info) newmarked)
5060         ;; Add the marks lists to the end of the info.
5061         (when newmarked
5062           (setcdr (nthcdr 2 info) (list newmarked))))
5063
5064       ;; Cut off the end of the info if there's nothing else there.
5065       (let ((i 5))
5066         (while (and (> i 2)
5067                     (not (nth i info)))
5068           (when (nthcdr (decf i) info)
5069             (setcdr (nthcdr i info) nil)))))))
5070
5071 (defun gnus-set-mode-line (where)
5072   "Set the mode line of the article or summary buffers.
5073 If WHERE is `summary', the summary mode line format will be used."
5074   ;; Is this mode line one we keep updated?
5075   (when (and (memq where gnus-updated-mode-lines)
5076              (symbol-value
5077               (intern (format "gnus-%s-mode-line-format-spec" where))))
5078     (let (mode-string)
5079       (save-excursion
5080         ;; We evaluate this in the summary buffer since these
5081         ;; variables are buffer-local to that buffer.
5082         (set-buffer gnus-summary-buffer)
5083        ;; We bind all these variables that are used in the `eval' form
5084         ;; below.
5085         (let* ((mformat (symbol-value
5086                          (intern
5087                           (format "gnus-%s-mode-line-format-spec" where))))
5088                (gnus-tmp-group-name (gnus-group-decoded-name
5089                                      gnus-newsgroup-name))
5090                (gnus-tmp-article-number (or gnus-current-article 0))
5091                (gnus-tmp-unread gnus-newsgroup-unreads)
5092                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5093                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5094                (gnus-tmp-unread-and-unselected
5095                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5096                             (zerop gnus-tmp-unselected))
5097                        "")
5098                       ((zerop gnus-tmp-unselected)
5099                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5100                       (t (format "{%d(+%d) more}"
5101                                  gnus-tmp-unread-and-unticked
5102                                  gnus-tmp-unselected))))
5103                (gnus-tmp-subject
5104                 (if (and gnus-current-headers
5105                          (vectorp gnus-current-headers))
5106                     (gnus-mode-string-quote
5107                      (mail-header-subject gnus-current-headers))
5108                   ""))
5109                bufname-length max-len
5110                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5111           (setq mode-string (eval mformat))
5112           (setq bufname-length (if (string-match "%b" mode-string)
5113                                    (- (length
5114                                        (buffer-name
5115                                         (if (eq where 'summary)
5116                                             nil
5117                                           (get-buffer gnus-article-buffer))))
5118                                       2)
5119                                  0))
5120           (setq max-len (max 4 (if gnus-mode-non-string-length
5121                                    (- (window-width)
5122                                       gnus-mode-non-string-length
5123                                       bufname-length)
5124                                  (length mode-string))))
5125           ;; We might have to chop a bit of the string off...
5126           (when (> (length mode-string) max-len)
5127             (setq mode-string
5128                   (concat (truncate-string-to-width mode-string (- max-len 3))
5129                           "...")))
5130           ;; Pad the mode string a bit.
5131           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5132       ;; Update the mode line.
5133       (setq mode-line-buffer-identification
5134             (gnus-mode-line-buffer-identification (list mode-string)))
5135       (set-buffer-modified-p t))))
5136
5137 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5138   "Go through the HEADERS list and add all Xrefs to a hash table.
5139 The resulting hash table is returned, or nil if no Xrefs were found."
5140   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5141          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5142          (xref-hashtb (gnus-make-hashtable))
5143          start group entry number xrefs header)
5144     (while headers
5145       (setq header (pop headers))
5146       (when (and (setq xrefs (mail-header-xref header))
5147                  (not (memq (setq number (mail-header-number header))
5148                             unreads)))
5149         (setq start 0)
5150         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5151           (setq start (match-end 0))
5152           (setq group (if prefix
5153                           (concat prefix (substring xrefs (match-beginning 1)
5154                                                     (match-end 1)))
5155                         (substring xrefs (match-beginning 1) (match-end 1))))
5156           (setq number
5157                 (string-to-int (substring xrefs (match-beginning 2)
5158                                           (match-end 2))))
5159           (if (setq entry (gnus-gethash group xref-hashtb))
5160               (setcdr entry (cons number (cdr entry)))
5161             (gnus-sethash group (cons number nil) xref-hashtb)))))
5162     (and start xref-hashtb)))
5163
5164 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5165   "Look through all the headers and mark the Xrefs as read."
5166   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5167         name entry info xref-hashtb idlist method nth4)
5168     (save-excursion
5169       (set-buffer gnus-group-buffer)
5170       (when (setq xref-hashtb
5171                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5172         (mapatoms
5173          (lambda (group)
5174            (unless (string= from-newsgroup (setq name (symbol-name group)))
5175              (setq idlist (symbol-value group))
5176              ;; Dead groups are not updated.
5177              (and (prog1
5178                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5179                             info (nth 2 entry))
5180                     (when (stringp (setq nth4 (gnus-info-method info)))
5181                       (setq nth4 (gnus-server-to-method nth4))))
5182                   ;; Only do the xrefs if the group has the same
5183                   ;; select method as the group we have just read.
5184                   (or (gnus-methods-equal-p
5185                        nth4 (gnus-find-method-for-group from-newsgroup))
5186                       virtual
5187                       (equal nth4 (setq method (gnus-find-method-for-group
5188                                                 from-newsgroup)))
5189                       (and (equal (car nth4) (car method))
5190                            (equal (nth 1 nth4) (nth 1 method))))
5191                   gnus-use-cross-reference
5192                   (or (not (eq gnus-use-cross-reference t))
5193                       virtual
5194                       ;; Only do cross-references on subscribed
5195                       ;; groups, if that is what is wanted.
5196                       (<= (gnus-info-level info) gnus-level-subscribed))
5197                   (gnus-group-make-articles-read name idlist))))
5198          xref-hashtb)))))
5199
5200 (defun gnus-compute-read-articles (group articles)
5201   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5202          (info (nth 2 entry))
5203          (active (gnus-active group))
5204          ninfo)
5205     (when entry
5206       ;; First peel off all invalid article numbers.
5207       (when active
5208         (let ((ids articles)
5209               id first)
5210           (while (setq id (pop ids))
5211             (when (and first (> id (cdr active)))
5212               ;; We'll end up in this situation in one particular
5213               ;; obscure situation.  If you re-scan a group and get
5214               ;; a new article that is cross-posted to a different
5215               ;; group that has not been re-scanned, you might get
5216               ;; crossposted article that has a higher number than
5217               ;; Gnus believes possible.  So we re-activate this
5218               ;; group as well.  This might mean doing the
5219               ;; crossposting thingy will *increase* the number
5220               ;; of articles in some groups.  Tsk, tsk.
5221               (setq active (or (gnus-activate-group group) active)))
5222             (when (or (> id (cdr active))
5223                       (< id (car active)))
5224               (setq articles (delq id articles))))))
5225       ;; If the read list is nil, we init it.
5226       (if (and active
5227                (null (gnus-info-read info))
5228                (> (car active) 1))
5229           (setq ninfo (cons 1 (1- (car active))))
5230         (setq ninfo (gnus-info-read info)))
5231       ;; Then we add the read articles to the range.
5232       (gnus-add-to-range
5233        ninfo (setq articles (sort articles '<))))))
5234
5235 (defun gnus-group-make-articles-read (group articles)
5236   "Update the info of GROUP to say that ARTICLES are read."
5237   (let* ((num 0)
5238          (entry (gnus-gethash group gnus-newsrc-hashtb))
5239          (info (nth 2 entry))
5240          (active (gnus-active group))
5241          range)
5242     (when entry
5243       (setq range (gnus-compute-read-articles group articles))
5244       (save-excursion
5245         (set-buffer gnus-group-buffer)
5246         (gnus-undo-register
5247           `(progn
5248              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5249              (gnus-info-set-read ',info ',(gnus-info-read info))
5250              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5251              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5252              (gnus-group-update-group ,group t))))
5253       ;; Add the read articles to the range.
5254       (gnus-info-set-read info range)
5255       (gnus-request-set-mark group (list (list range 'add '(read))))
5256       ;; Then we have to re-compute how many unread
5257       ;; articles there are in this group.
5258       (when active
5259         (cond
5260          ((not range)
5261           (setq num (- (1+ (cdr active)) (car active))))
5262          ((not (listp (cdr range)))
5263           (setq num (- (cdr active) (- (1+ (cdr range))
5264                                        (car range)))))
5265          (t
5266           (while range
5267             (if (numberp (car range))
5268                 (setq num (1+ num))
5269               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5270             (setq range (cdr range)))
5271           (setq num (- (cdr active) num))))
5272         ;; Update the number of unread articles.
5273         (setcar entry num)
5274         ;; Update the group buffer.
5275         (gnus-group-update-group group t)))))
5276
5277 (defvar gnus-newsgroup-none-id 0)
5278
5279 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5280   (let ((cur nntp-server-buffer)
5281         (dependencies
5282          (or dependencies
5283              (save-excursion (set-buffer gnus-summary-buffer)
5284                              gnus-newsgroup-dependencies)))
5285         headers id end ref
5286         (mail-parse-charset gnus-newsgroup-charset)
5287         (mail-parse-ignored-charsets
5288          (save-excursion (condition-case nil
5289                              (set-buffer gnus-summary-buffer)
5290                            (error))
5291                          gnus-newsgroup-ignored-charsets)))
5292     (save-excursion
5293       (set-buffer nntp-server-buffer)
5294       ;; Translate all TAB characters into SPACE characters.
5295       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5296       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5297       (gnus-run-hooks 'gnus-parse-headers-hook)
5298       (let ((case-fold-search t)
5299             in-reply-to header p lines chars)
5300         (goto-char (point-min))
5301         ;; Search to the beginning of the next header.  Error messages
5302         ;; do not begin with 2 or 3.
5303         (while (re-search-forward "^[23][0-9]+ " nil t)
5304           (setq id nil
5305                 ref nil)
5306           ;; This implementation of this function, with nine
5307           ;; search-forwards instead of the one re-search-forward and
5308           ;; a case (which basically was the old function) is actually
5309           ;; about twice as fast, even though it looks messier.  You
5310           ;; can't have everything, I guess.  Speed and elegance
5311           ;; doesn't always go hand in hand.
5312           (setq
5313            header
5314            (vector
5315             ;; Number.
5316             (prog1
5317                 (read cur)
5318               (end-of-line)
5319               (setq p (point))
5320               (narrow-to-region (point)
5321                                 (or (and (search-forward "\n.\n" nil t)
5322                                          (- (point) 2))
5323                                     (point))))
5324             ;; Subject.
5325             (progn
5326               (goto-char p)
5327               (if (search-forward "\nsubject:" nil t)
5328                   (funcall gnus-decode-encoded-word-function
5329                            (nnheader-header-value))
5330                 "(none)"))
5331             ;; From.
5332             (progn
5333               (goto-char p)
5334               (if (search-forward "\nfrom:" nil t)
5335                   (funcall gnus-decode-encoded-word-function
5336                            (nnheader-header-value))
5337                 "(nobody)"))
5338             ;; Date.
5339             (progn
5340               (goto-char p)
5341               (if (search-forward "\ndate:" nil t)
5342                   (nnheader-header-value) ""))
5343             ;; Message-ID.
5344             (progn
5345               (goto-char p)
5346               (setq id (if (re-search-forward
5347                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5348                            ;; We do it this way to make sure the Message-ID
5349                            ;; is (somewhat) syntactically valid.
5350                            (buffer-substring (match-beginning 1)
5351                                              (match-end 1))
5352                          ;; If there was no message-id, we just fake one
5353                          ;; to make subsequent routines simpler.
5354                          (nnheader-generate-fake-message-id))))
5355             ;; References.
5356             (progn
5357               (goto-char p)
5358               (if (search-forward "\nreferences:" nil t)
5359                   (progn
5360                     (setq end (point))
5361                     (prog1
5362                         (nnheader-header-value)
5363                       (setq ref
5364                             (buffer-substring
5365                              (progn
5366                                (end-of-line)
5367                                (search-backward ">" end t)
5368                                (1+ (point)))
5369                              (progn
5370                                (search-backward "<" end t)
5371                                (point))))))
5372                 ;; Get the references from the in-reply-to header if there
5373                 ;; were no references and the in-reply-to header looks
5374                 ;; promising.
5375                 (if (and (search-forward "\nin-reply-to:" nil t)
5376                          (setq in-reply-to (nnheader-header-value))
5377                          (string-match "<[^>]+>" in-reply-to))
5378                     (let (ref2)
5379                       (setq ref (substring in-reply-to (match-beginning 0)
5380                                            (match-end 0)))
5381                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5382                         (setq ref2 (substring in-reply-to (match-beginning 0)
5383                                               (match-end 0)))
5384                         (when (> (length ref2) (length ref))
5385                           (setq ref ref2)))
5386                       ref)
5387                   (setq ref nil))))
5388             ;; Chars.
5389             (progn
5390               (goto-char p)
5391               (if (search-forward "\nchars: " nil t)
5392                   (if (numberp (setq chars (ignore-errors (read cur))))
5393                       chars -1)
5394                 -1))
5395             ;; Lines.
5396             (progn
5397               (goto-char p)
5398               (if (search-forward "\nlines: " nil t)
5399                   (if (numberp (setq lines (ignore-errors (read cur))))
5400                       lines -1)
5401                 -1))
5402             ;; Xref.
5403             (progn
5404               (goto-char p)
5405               (and (search-forward "\nxref:" nil t)
5406                    (nnheader-header-value)))
5407             ;; Extra.
5408             (when gnus-extra-headers
5409               (let ((extra gnus-extra-headers)
5410                     out)
5411                 (while extra
5412                   (goto-char p)
5413                   (when (search-forward
5414                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5415                     (push (cons (car extra) (nnheader-header-value))
5416                           out))
5417                   (pop extra))
5418                 out))))
5419           (when (equal id ref)
5420             (setq ref nil))
5421
5422           (when gnus-alter-header-function
5423             (funcall gnus-alter-header-function header)
5424             (setq id (mail-header-id header)
5425                   ref (gnus-parent-id (mail-header-references header))))
5426
5427           (when (setq header
5428                       (gnus-dependencies-add-header
5429                        header dependencies force-new))
5430             (push header headers))
5431           (goto-char (point-max))
5432           (widen))
5433         (nreverse headers)))))
5434
5435 ;; Goes through the xover lines and returns a list of vectors
5436 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5437                                                   force-new dependencies
5438                                                   group also-fetch-heads)
5439   "Parse the news overview data in the server buffer.
5440 Return a list of headers that match SEQUENCE (see
5441 `nntp-retrieve-headers')."
5442   ;; Get the Xref when the users reads the articles since most/some
5443   ;; NNTP servers do not include Xrefs when using XOVER.
5444   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5445   (let ((mail-parse-charset gnus-newsgroup-charset)
5446         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5447         (cur nntp-server-buffer)
5448         (dependencies (or dependencies gnus-newsgroup-dependencies))
5449         (allp (cond
5450                ((eq gnus-read-all-available-headers t)
5451                 t)
5452                ((stringp gnus-read-all-available-headers)
5453                 (string-match gnus-read-all-available-headers group))
5454                (t
5455                 nil)))
5456         number headers header)
5457     (save-excursion
5458       (set-buffer nntp-server-buffer)
5459       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5460       ;; Allow the user to mangle the headers before parsing them.
5461       (gnus-run-hooks 'gnus-parse-headers-hook)
5462       (goto-char (point-min))
5463       (while (not (eobp))
5464         (condition-case ()
5465             (while (and (or sequence allp)
5466                         (not (eobp)))
5467               (setq number (read cur))
5468               (when (not allp)
5469                 (while (and sequence
5470                             (< (car sequence) number))
5471                   (setq sequence (cdr sequence))))
5472               (when (and (or allp
5473                              (and sequence
5474                                   (eq number (car sequence))))
5475                          (progn
5476                            (setq sequence (cdr sequence))
5477                            (setq header (inline
5478                                           (gnus-nov-parse-line
5479                                            number dependencies force-new)))))
5480                 (push header headers))
5481               (forward-line 1))
5482           (error
5483            (gnus-error 4 "Strange nov line (%d)"
5484                        (count-lines (point-min) (point)))))
5485         (forward-line 1))
5486       ;; A common bug in inn is that if you have posted an article and
5487       ;; then retrieves the active file, it will answer correctly --
5488       ;; the new article is included.  However, a NOV entry for the
5489       ;; article may not have been generated yet, so this may fail.
5490       ;; We work around this problem by retrieving the last few
5491       ;; headers using HEAD.
5492       (if (or (not also-fetch-heads)
5493               (not sequence))
5494           ;; We (probably) got all the headers.
5495           (nreverse headers)
5496         (let ((gnus-nov-is-evil t))
5497           (nconc
5498            (nreverse headers)
5499            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5500              (gnus-get-newsgroup-headers))))))))
5501
5502 (defun gnus-article-get-xrefs ()
5503   "Fill in the Xref value in `gnus-current-headers', if necessary.
5504 This is meant to be called in `gnus-article-internal-prepare-hook'."
5505   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5506                                  gnus-current-headers)))
5507     (or (not gnus-use-cross-reference)
5508         (not headers)
5509         (and (mail-header-xref headers)
5510              (not (string= (mail-header-xref headers) "")))
5511         (let ((case-fold-search t)
5512               xref)
5513           (save-restriction
5514             (nnheader-narrow-to-headers)
5515             (goto-char (point-min))
5516             (when (or (and (not (eobp))
5517                            (eq (downcase (char-after)) ?x)
5518                            (looking-at "Xref:"))
5519                       (search-forward "\nXref:" nil t))
5520               (goto-char (1+ (match-end 0)))
5521               (setq xref (buffer-substring (point)
5522                                            (progn (end-of-line) (point))))
5523               (mail-header-set-xref headers xref)))))))
5524
5525 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5526   "Find article ID and insert the summary line for that article.
5527 OLD-HEADER can either be a header or a line number to insert
5528 the subject line on."
5529   (let* ((line (and (numberp old-header) old-header))
5530          (old-header (and (vectorp old-header) old-header))
5531          (header (cond ((and old-header use-old-header)
5532                         old-header)
5533                        ((and (numberp id)
5534                              (gnus-number-to-header id))
5535                         (gnus-number-to-header id))
5536                        (t
5537                         (gnus-read-header id))))
5538          (number (and (numberp id) id))
5539          d)
5540     (when header
5541       ;; Rebuild the thread that this article is part of and go to the
5542       ;; article we have fetched.
5543       (when (and (not gnus-show-threads)
5544                  old-header)
5545         (when (and number
5546                    (setq d (gnus-data-find (mail-header-number old-header))))
5547           (goto-char (gnus-data-pos d))
5548           (gnus-data-remove
5549            number
5550            (- (gnus-point-at-bol)
5551               (prog1
5552                   (1+ (gnus-point-at-eol))
5553                 (gnus-delete-line))))))
5554       (when old-header
5555         (mail-header-set-number header (mail-header-number old-header)))
5556       (setq gnus-newsgroup-sparse
5557             (delq (setq number (mail-header-number header))
5558                   gnus-newsgroup-sparse))
5559       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5560       (push number gnus-newsgroup-limit)
5561       (gnus-rebuild-thread (mail-header-id header) line)
5562       (gnus-summary-goto-subject number nil t))
5563     (when (and (numberp number)
5564                (> number 0))
5565       ;; We have to update the boundaries even if we can't fetch the
5566       ;; article if ID is a number -- so that the next `P' or `N'
5567       ;; command will fetch the previous (or next) article even
5568       ;; if the one we tried to fetch this time has been canceled.
5569       (when (> number gnus-newsgroup-end)
5570         (setq gnus-newsgroup-end number))
5571       (when (< number gnus-newsgroup-begin)
5572         (setq gnus-newsgroup-begin number))
5573       (setq gnus-newsgroup-unselected
5574             (delq number gnus-newsgroup-unselected)))
5575     ;; Report back a success?
5576     (and header (mail-header-number header))))
5577
5578 ;;; Process/prefix in the summary buffer
5579
5580 (defun gnus-summary-work-articles (n)
5581   "Return a list of articles to be worked upon.
5582 The prefix argument, the list of process marked articles, and the
5583 current article will be taken into consideration."
5584   (save-excursion
5585     (set-buffer gnus-summary-buffer)
5586     (cond
5587      (n
5588       ;; A numerical prefix has been given.
5589       (setq n (prefix-numeric-value n))
5590       (let ((backward (< n 0))
5591             (n (abs (prefix-numeric-value n)))
5592             articles article)
5593         (save-excursion
5594           (while
5595               (and (> n 0)
5596                    (push (setq article (gnus-summary-article-number))
5597                          articles)
5598                    (if backward
5599                        (gnus-summary-find-prev nil article)
5600                      (gnus-summary-find-next nil article)))
5601             (decf n)))
5602         (nreverse articles)))
5603      ((and (gnus-region-active-p) (mark))
5604       (message "region active")
5605       ;; Work on the region between point and mark.
5606       (let ((max (max (point) (mark)))
5607             articles article)
5608         (save-excursion
5609           (goto-char (min (min (point) (mark))))
5610           (while
5611               (and
5612                (push (setq article (gnus-summary-article-number)) articles)
5613                (gnus-summary-find-next nil article)
5614                (< (point) max)))
5615           (nreverse articles))))
5616      (gnus-newsgroup-processable
5617       ;; There are process-marked articles present.
5618       ;; Save current state.
5619       (gnus-summary-save-process-mark)
5620       ;; Return the list.
5621       (reverse gnus-newsgroup-processable))
5622      (t
5623       ;; Just return the current article.
5624       (list (gnus-summary-article-number))))))
5625
5626 (defmacro gnus-summary-iterate (arg &rest forms)
5627   "Iterate over the process/prefixed articles and do FORMS.
5628 ARG is the interactive prefix given to the command.  FORMS will be
5629 executed with point over the summary line of the articles."
5630   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5631     `(let ((,articles (gnus-summary-work-articles ,arg)))
5632        (while ,articles
5633          (gnus-summary-goto-subject (car ,articles))
5634          ,@forms
5635          (pop ,articles)))))
5636
5637 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5638 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5639
5640 (defun gnus-summary-save-process-mark ()
5641   "Push the current set of process marked articles on the stack."
5642   (interactive)
5643   (push (copy-sequence gnus-newsgroup-processable)
5644         gnus-newsgroup-process-stack))
5645
5646 (defun gnus-summary-kill-process-mark ()
5647   "Push the current set of process marked articles on the stack and unmark."
5648   (interactive)
5649   (gnus-summary-save-process-mark)
5650   (gnus-summary-unmark-all-processable))
5651
5652 (defun gnus-summary-yank-process-mark ()
5653   "Pop the last process mark state off the stack and restore it."
5654   (interactive)
5655   (unless gnus-newsgroup-process-stack
5656     (error "Empty mark stack"))
5657   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5658
5659 (defun gnus-summary-process-mark-set (set)
5660   "Make SET into the current process marked articles."
5661   (gnus-summary-unmark-all-processable)
5662   (while set
5663     (gnus-summary-set-process-mark (pop set))))
5664
5665 ;;; Searching and stuff
5666
5667 (defun gnus-summary-search-group (&optional backward use-level)
5668   "Search for next unread newsgroup.
5669 If optional argument BACKWARD is non-nil, search backward instead."
5670   (save-excursion
5671     (set-buffer gnus-group-buffer)
5672     (when (gnus-group-search-forward
5673            backward nil (if use-level (gnus-group-group-level) nil))
5674       (gnus-group-group-name))))
5675
5676 (defun gnus-summary-best-group (&optional exclude-group)
5677   "Find the name of the best unread group.
5678 If EXCLUDE-GROUP, do not go to this group."
5679   (save-excursion
5680     (set-buffer gnus-group-buffer)
5681     (save-excursion
5682       (gnus-group-best-unread-group exclude-group))))
5683
5684 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5685   (if backward (gnus-summary-find-prev)
5686     (let* ((dummy (gnus-summary-article-intangible-p))
5687            (article (or article (gnus-summary-article-number)))
5688            (arts (gnus-data-find-list article))
5689            result)
5690       (when (and (not dummy)
5691                  (or (not gnus-summary-check-current)
5692                      (not unread)
5693                      (not (gnus-data-unread-p (car arts)))))
5694         (setq arts (cdr arts)))
5695       (when (setq result
5696                   (if unread
5697                       (progn
5698                         (while arts
5699                           (when (or (and undownloaded
5700                                          (eq gnus-undownloaded-mark
5701                                              (gnus-data-mark (car arts))))
5702                                     (gnus-data-unread-p (car arts)))
5703                             (setq result (car arts)
5704                                   arts nil))
5705                           (setq arts (cdr arts)))
5706                         result)
5707                     (car arts)))
5708         (goto-char (gnus-data-pos result))
5709         (gnus-data-number result)))))
5710
5711 (defun gnus-summary-find-prev (&optional unread article)
5712   (let* ((eobp (eobp))
5713          (article (or article (gnus-summary-article-number)))
5714          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5715          result)
5716     (when (and (not eobp)
5717                (or (not gnus-summary-check-current)
5718                    (not unread)
5719                    (not (gnus-data-unread-p (car arts)))))
5720       (setq arts (cdr arts)))
5721     (when (setq result
5722                 (if unread
5723                     (progn
5724                       (while arts
5725                         (when (gnus-data-unread-p (car arts))
5726                           (setq result (car arts)
5727                                 arts nil))
5728                         (setq arts (cdr arts)))
5729                       result)
5730                   (car arts)))
5731       (goto-char (gnus-data-pos result))
5732       (gnus-data-number result))))
5733
5734 (defun gnus-summary-find-subject (subject &optional unread backward article)
5735   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5736          (article (or article (gnus-summary-article-number)))
5737          (articles (gnus-data-list backward))
5738          (arts (gnus-data-find-list article articles))
5739          result)
5740     (when (or (not gnus-summary-check-current)
5741               (not unread)
5742               (not (gnus-data-unread-p (car arts))))
5743       (setq arts (cdr arts)))
5744     (while arts
5745       (and (or (not unread)
5746                (gnus-data-unread-p (car arts)))
5747            (vectorp (gnus-data-header (car arts)))
5748            (gnus-subject-equal
5749             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5750            (setq result (car arts)
5751                  arts nil))
5752       (setq arts (cdr arts)))
5753     (and result
5754          (goto-char (gnus-data-pos result))
5755          (gnus-data-number result))))
5756
5757 (defun gnus-summary-search-forward (&optional unread subject backward)
5758   "Search forward for an article.
5759 If UNREAD, look for unread articles.  If SUBJECT, look for
5760 articles with that subject.  If BACKWARD, search backward instead."
5761   (cond (subject (gnus-summary-find-subject subject unread backward))
5762         (backward (gnus-summary-find-prev unread))
5763         (t (gnus-summary-find-next unread))))
5764
5765 (defun gnus-recenter (&optional n)
5766   "Center point in window and redisplay frame.
5767 Also do horizontal recentering."
5768   (interactive "P")
5769   (when (and gnus-auto-center-summary
5770              (not (eq gnus-auto-center-summary 'vertical)))
5771     (gnus-horizontal-recenter))
5772   (recenter n))
5773
5774 (defun gnus-summary-recenter ()
5775   "Center point in the summary window.
5776 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5777 displayed, no centering will be performed."
5778   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5779 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5780   (interactive)
5781   (let* ((top (cond ((< (window-height) 4) 0)
5782                     ((< (window-height) 7) 1)
5783                     (t (if (numberp gnus-auto-center-summary)
5784                            gnus-auto-center-summary
5785                          2))))
5786          (height (1- (window-height)))
5787          (bottom (save-excursion (goto-char (point-max))
5788                                  (forward-line (- height))
5789                                  (point)))
5790          (window (get-buffer-window (current-buffer))))
5791     ;; The user has to want it.
5792     (when gnus-auto-center-summary
5793       (when (get-buffer-window gnus-article-buffer)
5794         ;; Only do recentering when the article buffer is displayed,
5795       ;; Set the window start to either `bottom', which is the biggest
5796         ;; possible valid number, or the second line from the top,
5797         ;; whichever is the least.
5798         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5799           (if (> bottom top-pos)
5800               ;; Keep the second line from the top visible
5801               (set-window-start window top-pos t)
5802             ;; Try to keep the bottom line visible; if it's partially
5803             ;; obscured, either scroll one more line to make it fully
5804             ;; visible, or revert to using TOP-POS.
5805             (save-excursion
5806               (goto-char (point-max))
5807               (forward-line -1)
5808               (let ((last-line-start (point)))
5809                 (goto-char bottom)
5810                 (set-window-start window (point) t)
5811                 (when (not (pos-visible-in-window-p last-line-start window))
5812                   (forward-line 1)
5813                   (set-window-start window (min (point) top-pos) t)))))))
5814       ;; Do horizontal recentering while we're at it.
5815       (when (and (get-buffer-window (current-buffer) t)
5816                  (not (eq gnus-auto-center-summary 'vertical)))
5817         (let ((selected (selected-window)))
5818           (select-window (get-buffer-window (current-buffer) t))
5819           (gnus-summary-position-point)
5820           (gnus-horizontal-recenter)
5821           (select-window selected))))))
5822
5823 (defun gnus-summary-jump-to-group (newsgroup)
5824   "Move point to NEWSGROUP in group mode buffer."
5825   ;; Keep update point of group mode buffer if visible.
5826   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5827       (save-window-excursion
5828         ;; Take care of tree window mode.
5829         (when (get-buffer-window gnus-group-buffer)
5830           (pop-to-buffer gnus-group-buffer))
5831         (gnus-group-jump-to-group newsgroup))
5832     (save-excursion
5833       ;; Take care of tree window mode.
5834       (if (get-buffer-window gnus-group-buffer)
5835           (pop-to-buffer gnus-group-buffer)
5836         (set-buffer gnus-group-buffer))
5837       (gnus-group-jump-to-group newsgroup))))
5838
5839 ;; This function returns a list of article numbers based on the
5840 ;; difference between the ranges of read articles in this group and
5841 ;; the range of active articles.
5842 (defun gnus-list-of-unread-articles (group)
5843   (let* ((read (gnus-info-read (gnus-get-info group)))
5844          (active (or (gnus-active group) (gnus-activate-group group)))
5845          (last (cdr active))
5846          first nlast unread)
5847     ;; If none are read, then all are unread.
5848     (if (not read)
5849         (setq first (car active))
5850       ;; If the range of read articles is a single range, then the
5851       ;; first unread article is the article after the last read
5852       ;; article.  Sounds logical, doesn't it?
5853       (if (and (not (listp (cdr read)))
5854                (or (< (car read) (car active))
5855                    (progn (setq read (list read))
5856                           nil)))
5857           (setq first (max (car active) (1+ (cdr read))))
5858         ;; `read' is a list of ranges.
5859         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5860                                   (caar read)))
5861                   1)
5862           (setq first (car active)))
5863         (while read
5864           (when first
5865             (while (< first nlast)
5866               (push first unread)
5867               (setq first (1+ first))))
5868           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5869           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5870           (setq read (cdr read)))))
5871     ;; And add the last unread articles.
5872     (while (<= first last)
5873       (push first unread)
5874       (setq first (1+ first)))
5875     ;; Return the list of unread articles.
5876     (delq 0 (nreverse unread))))
5877
5878 (defun gnus-list-of-read-articles (group)
5879   "Return a list of unread, unticked and non-dormant articles."
5880   (let* ((info (gnus-get-info group))
5881          (marked (gnus-info-marks info))
5882          (active (gnus-active group)))
5883     (and info active
5884          (gnus-set-difference
5885           (gnus-sorted-complement
5886            (gnus-uncompress-range active)
5887            (gnus-list-of-unread-articles group))
5888           (append
5889            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5890            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5891
5892 ;; Various summary commands
5893
5894 (defun gnus-summary-select-article-buffer ()
5895   "Reconfigure windows to show article buffer."
5896   (interactive)
5897   (if (not (gnus-buffer-live-p gnus-article-buffer))
5898       (error "There is no article buffer for this summary buffer")
5899     (gnus-configure-windows 'article)
5900     (select-window (get-buffer-window gnus-article-buffer))))
5901
5902 (defun gnus-summary-universal-argument (arg)
5903   "Perform any operation on all articles that are process/prefixed."
5904   (interactive "P")
5905   (let ((articles (gnus-summary-work-articles arg))
5906         func article)
5907     (if (eq
5908          (setq
5909           func
5910           (key-binding
5911            (read-key-sequence
5912             (substitute-command-keys
5913              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5914          'undefined)
5915         (gnus-error 1 "Undefined key")
5916       (save-excursion
5917         (while articles
5918           (gnus-summary-goto-subject (setq article (pop articles)))
5919           (let (gnus-newsgroup-processable)
5920             (command-execute func))
5921           (gnus-summary-remove-process-mark article)))))
5922   (gnus-summary-position-point))
5923
5924 (defun gnus-summary-toggle-truncation (&optional arg)
5925   "Toggle truncation of summary lines.
5926 With arg, turn line truncation on iff arg is positive."
5927   (interactive "P")
5928   (setq truncate-lines
5929         (if (null arg) (not truncate-lines)
5930           (> (prefix-numeric-value arg) 0)))
5931   (redraw-display))
5932
5933 (defun gnus-summary-reselect-current-group (&optional all rescan)
5934   "Exit and then reselect the current newsgroup.
5935 The prefix argument ALL means to select all articles."
5936   (interactive "P")
5937   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5938     (error "Ephemeral groups can't be reselected"))
5939   (let ((current-subject (gnus-summary-article-number))
5940         (group gnus-newsgroup-name))
5941     (setq gnus-newsgroup-begin nil)
5942     (gnus-summary-exit)
5943     ;; We have to adjust the point of group mode buffer because
5944     ;; point was moved to the next unread newsgroup by exiting.
5945     (gnus-summary-jump-to-group group)
5946     (when rescan
5947       (save-excursion
5948         (gnus-group-get-new-news-this-group 1)))
5949     (gnus-group-read-group all t)
5950     (gnus-summary-goto-subject current-subject nil t)))
5951
5952 (defun gnus-summary-rescan-group (&optional all)
5953   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5954   (interactive "P")
5955   (gnus-summary-reselect-current-group all t))
5956
5957 (defun gnus-summary-update-info (&optional non-destructive)
5958   (save-excursion
5959     (let ((group gnus-newsgroup-name))
5960       (when group
5961         (when gnus-newsgroup-kill-headers
5962           (setq gnus-newsgroup-killed
5963                 (gnus-compress-sequence
5964                  (nconc
5965                   (gnus-set-sorted-intersection
5966                    (gnus-uncompress-range gnus-newsgroup-killed)
5967                    (setq gnus-newsgroup-unselected
5968                          (sort gnus-newsgroup-unselected '<)))
5969                   (setq gnus-newsgroup-unreads
5970                         (sort gnus-newsgroup-unreads '<)))
5971                  t)))
5972         (unless (listp (cdr gnus-newsgroup-killed))
5973           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5974         (let ((headers gnus-newsgroup-headers))
5975           ;; Set the new ranges of read articles.
5976           (save-excursion
5977             (set-buffer gnus-group-buffer)
5978             (gnus-undo-force-boundary))
5979           (gnus-update-read-articles
5980            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5981           ;; Set the current article marks.
5982           (let ((gnus-newsgroup-scored
5983                  (if (and (not gnus-save-score)
5984                           (not non-destructive))
5985                      nil
5986                    gnus-newsgroup-scored)))
5987             (save-excursion
5988               (gnus-update-marks)))
5989           ;; Do the cross-ref thing.
5990           (when gnus-use-cross-reference
5991             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5992           ;; Do not switch windows but change the buffer to work.
5993           (set-buffer gnus-group-buffer)
5994           (unless (gnus-ephemeral-group-p group)
5995             (gnus-group-update-group group)))))))
5996
5997 (defun gnus-summary-save-newsrc (&optional force)
5998   "Save the current number of read/marked articles in the dribble buffer.
5999 The dribble buffer will then be saved.
6000 If FORCE (the prefix), also save the .newsrc file(s)."
6001   (interactive "P")
6002   (gnus-summary-update-info t)
6003   (if force
6004       (gnus-save-newsrc-file)
6005     (gnus-dribble-save)))
6006
6007 (defun gnus-summary-exit (&optional temporary)
6008   "Exit reading current newsgroup, and then return to group selection mode.
6009 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6010   (interactive)
6011   (gnus-set-global-variables)
6012   (when (gnus-buffer-live-p gnus-article-buffer)
6013     (save-excursion
6014       (set-buffer gnus-article-buffer)
6015       (mm-destroy-parts gnus-article-mime-handles)
6016       ;; Set it to nil for safety reason.
6017       (setq gnus-article-mime-handle-alist nil)
6018       (setq gnus-article-mime-handles nil)))
6019   (gnus-kill-save-kill-buffer)
6020   (gnus-async-halt-prefetch)
6021   (let* ((group gnus-newsgroup-name)
6022          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6023          (mode major-mode)
6024          (group-point nil)
6025          (buf (current-buffer)))
6026     (unless quit-config
6027       ;; Do adaptive scoring, and possibly save score files.
6028       (when gnus-newsgroup-adaptive
6029         (gnus-score-adaptive))
6030       (when gnus-use-scoring
6031         (gnus-score-save)))
6032     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6033     ;; If we have several article buffers, we kill them at exit.
6034     (unless gnus-single-article-buffer
6035       (gnus-kill-buffer gnus-original-article-buffer)
6036       (setq gnus-article-current nil))
6037     (when gnus-use-cache
6038       (gnus-cache-possibly-remove-articles)
6039       (gnus-cache-save-buffers))
6040     (gnus-async-prefetch-remove-group group)
6041     (when gnus-suppress-duplicates
6042       (gnus-dup-enter-articles))
6043     (when gnus-use-trees
6044       (gnus-tree-close group))
6045     (when gnus-use-cache
6046       (gnus-cache-write-active))
6047     ;; Remove entries for this group.
6048     (nnmail-purge-split-history (gnus-group-real-name group))
6049     ;; Make all changes in this group permanent.
6050     (unless quit-config
6051       (gnus-run-hooks 'gnus-exit-group-hook)
6052       (gnus-summary-update-info))
6053     (gnus-close-group group)
6054     ;; Make sure where we were, and go to next newsgroup.
6055     (set-buffer gnus-group-buffer)
6056     (unless quit-config
6057       (gnus-group-jump-to-group group))
6058     (gnus-run-hooks 'gnus-summary-exit-hook)
6059     (unless (or quit-config
6060                 ;; If this group has disappeared from the summary
6061                 ;; buffer, don't skip forwards.
6062                 (not (string= group (gnus-group-group-name))))
6063       (gnus-group-next-unread-group 1))
6064     (setq group-point (point))
6065     (if temporary
6066         nil                             ;Nothing to do.
6067       ;; If we have several article buffers, we kill them at exit.
6068       (unless gnus-single-article-buffer
6069         (gnus-kill-buffer gnus-article-buffer)
6070         (gnus-kill-buffer gnus-original-article-buffer)
6071         (setq gnus-article-current nil))
6072       (set-buffer buf)
6073       (if (not gnus-kill-summary-on-exit)
6074           (progn
6075             (gnus-deaden-summary)
6076             (setq mode nil))
6077        ;; We set all buffer-local variables to nil.  It is unclear why
6078         ;; this is needed, but if we don't, buffer-local variables are
6079         ;; not garbage-collected, it seems.  This would the lead to en
6080         ;; ever-growing Emacs.
6081         (gnus-summary-clear-local-variables)
6082         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6083           (gnus-summary-clear-local-variables))
6084         (when (get-buffer gnus-article-buffer)
6085           (bury-buffer gnus-article-buffer))
6086         ;; We clear the global counterparts of the buffer-local
6087         ;; variables as well, just to be on the safe side.
6088         (set-buffer gnus-group-buffer)
6089         (gnus-summary-clear-local-variables)
6090         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6091           (gnus-summary-clear-local-variables)))
6092       (setq gnus-current-select-method gnus-select-method)
6093       (pop-to-buffer gnus-group-buffer)
6094       (if (not quit-config)
6095           (progn
6096             (goto-char group-point)
6097             (gnus-configure-windows 'group 'force))
6098         (gnus-handle-ephemeral-exit quit-config))
6099       ;; Return to group mode buffer.
6100       (when (eq mode 'gnus-summary-mode)
6101         (gnus-kill-buffer buf))
6102       ;; Clear the current group name.
6103       (unless quit-config
6104         (setq gnus-newsgroup-name nil)))))
6105
6106 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6107 (defun gnus-summary-exit-no-update (&optional no-questions)
6108   "Quit reading current newsgroup without updating read article info."
6109   (interactive)
6110   (let* ((group gnus-newsgroup-name)
6111          (quit-config (gnus-group-quit-config group)))
6112     (when (or no-questions
6113               gnus-expert-user
6114               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6115       (gnus-async-halt-prefetch)
6116       (mapcar 'funcall
6117               (delq 'gnus-summary-expire-articles
6118                     (copy-sequence gnus-summary-prepare-exit-hook)))
6119       (when (gnus-buffer-live-p gnus-article-buffer)
6120         (save-excursion
6121           (set-buffer gnus-article-buffer)
6122           (mm-destroy-parts gnus-article-mime-handles)
6123           ;; Set it to nil for safety reason.
6124           (setq gnus-article-mime-handle-alist nil)
6125           (setq gnus-article-mime-handles nil)))
6126       ;; If we have several article buffers, we kill them at exit.
6127       (unless gnus-single-article-buffer
6128         (gnus-kill-buffer gnus-article-buffer)
6129         (gnus-kill-buffer gnus-original-article-buffer)
6130         (setq gnus-article-current nil))
6131       (if (not gnus-kill-summary-on-exit)
6132           (gnus-deaden-summary)
6133         (gnus-close-group group)
6134         (gnus-summary-clear-local-variables)
6135         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6136           (gnus-summary-clear-local-variables))
6137         (set-buffer gnus-group-buffer)
6138         (gnus-summary-clear-local-variables)
6139         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6140           (gnus-summary-clear-local-variables))
6141         (when (get-buffer gnus-summary-buffer)
6142           (kill-buffer gnus-summary-buffer)))
6143       (unless gnus-single-article-buffer
6144         (setq gnus-article-current nil))
6145       (when gnus-use-trees
6146         (gnus-tree-close group))
6147       (gnus-async-prefetch-remove-group group)
6148       (when (get-buffer gnus-article-buffer)
6149         (bury-buffer gnus-article-buffer))
6150       ;; Return to the group buffer.
6151       (gnus-configure-windows 'group 'force)
6152       ;; Clear the current group name.
6153       (setq gnus-newsgroup-name nil)
6154       (when (equal (gnus-group-group-name) group)
6155         (gnus-group-next-unread-group 1))
6156       (when quit-config
6157         (gnus-handle-ephemeral-exit quit-config)))))
6158
6159 (defun gnus-handle-ephemeral-exit (quit-config)
6160   "Handle movement when leaving an ephemeral group.
6161 The state which existed when entering the ephemeral is reset."
6162   (if (not (buffer-name (car quit-config)))
6163       (gnus-configure-windows 'group 'force)
6164     (set-buffer (car quit-config))
6165     (cond ((eq major-mode 'gnus-summary-mode)
6166            (gnus-set-global-variables))
6167           ((eq major-mode 'gnus-article-mode)
6168            (save-excursion
6169              ;; The `gnus-summary-buffer' variable may point
6170              ;; to the old summary buffer when using a single
6171              ;; article buffer.
6172              (unless (gnus-buffer-live-p gnus-summary-buffer)
6173                (set-buffer gnus-group-buffer))
6174              (set-buffer gnus-summary-buffer)
6175              (gnus-set-global-variables))))
6176     (if (or (eq (cdr quit-config) 'article)
6177             (eq (cdr quit-config) 'pick))
6178         (progn
6179           ;; The current article may be from the ephemeral group
6180           ;; thus it is best that we reload this article
6181           (gnus-summary-show-article)
6182           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6183               (gnus-configure-windows 'pick 'force)
6184             (gnus-configure-windows (cdr quit-config) 'force)))
6185       (gnus-configure-windows (cdr quit-config) 'force))
6186     (when (eq major-mode 'gnus-summary-mode)
6187       (gnus-summary-next-subject 1 nil t)
6188       (gnus-summary-recenter)
6189       (gnus-summary-position-point))))
6190
6191 ;;; Dead summaries.
6192
6193 (defvar gnus-dead-summary-mode-map nil)
6194
6195 (unless gnus-dead-summary-mode-map
6196   (setq gnus-dead-summary-mode-map (make-keymap))
6197   (suppress-keymap gnus-dead-summary-mode-map)
6198   (substitute-key-definition
6199    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6200   (dolist (key '("\C-d" "\r" "\177" [delete]))
6201     (define-key gnus-dead-summary-mode-map
6202       key 'gnus-summary-wake-up-the-dead))
6203   (dolist (key '("q" "Q"))
6204     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6205
6206 (defvar gnus-dead-summary-mode nil
6207   "Minor mode for Gnus summary buffers.")
6208
6209 (defun gnus-dead-summary-mode (&optional arg)
6210   "Minor mode for Gnus summary buffers."
6211   (interactive "P")
6212   (when (eq major-mode 'gnus-summary-mode)
6213     (make-local-variable 'gnus-dead-summary-mode)
6214     (setq gnus-dead-summary-mode
6215           (if (null arg) (not gnus-dead-summary-mode)
6216             (> (prefix-numeric-value arg) 0)))
6217     (when gnus-dead-summary-mode
6218       (gnus-add-minor-mode
6219        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6220
6221 (defun gnus-deaden-summary ()
6222   "Make the current summary buffer into a dead summary buffer."
6223   ;; Kill any previous dead summary buffer.
6224   (when (and gnus-dead-summary
6225              (buffer-name gnus-dead-summary))
6226     (save-excursion
6227       (set-buffer gnus-dead-summary)
6228       (when gnus-dead-summary-mode
6229         (kill-buffer (current-buffer)))))
6230   ;; Make this the current dead summary.
6231   (setq gnus-dead-summary (current-buffer))
6232   (gnus-dead-summary-mode 1)
6233   (let ((name (buffer-name)))
6234     (when (string-match "Summary" name)
6235       (rename-buffer
6236        (concat (substring name 0 (match-beginning 0)) "Dead "
6237                (substring name (match-beginning 0)))
6238        t)
6239       (bury-buffer))))
6240
6241 (defun gnus-kill-or-deaden-summary (buffer)
6242   "Kill or deaden the summary BUFFER."
6243   (save-excursion
6244     (when (and (buffer-name buffer)
6245                (not gnus-single-article-buffer))
6246       (save-excursion
6247         (set-buffer buffer)
6248         (gnus-kill-buffer gnus-article-buffer)
6249         (gnus-kill-buffer gnus-original-article-buffer)))
6250     (cond (gnus-kill-summary-on-exit
6251            (when (and gnus-use-trees
6252                       (gnus-buffer-exists-p buffer))
6253              (save-excursion
6254                (set-buffer buffer)
6255                (gnus-tree-close gnus-newsgroup-name)))
6256            (gnus-kill-buffer buffer))
6257           ((gnus-buffer-exists-p buffer)
6258            (save-excursion
6259              (set-buffer buffer)
6260              (gnus-deaden-summary))))))
6261
6262 (defun gnus-summary-wake-up-the-dead (&rest args)
6263   "Wake up the dead summary buffer."
6264   (interactive)
6265   (gnus-dead-summary-mode -1)
6266   (let ((name (buffer-name)))
6267     (when (string-match "Dead " name)
6268       (rename-buffer
6269        (concat (substring name 0 (match-beginning 0))
6270                (substring name (match-end 0)))
6271        t)))
6272   (gnus-message 3 "This dead summary is now alive again"))
6273
6274 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6275 (defun gnus-summary-fetch-faq (&optional faq-dir)
6276   "Fetch the FAQ for the current group.
6277 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6278 in."
6279   (interactive
6280    (list
6281     (when current-prefix-arg
6282       (completing-read
6283        "Faq dir: " (and (listp gnus-group-faq-directory)
6284                         (mapcar (lambda (file) (list file))
6285                                 gnus-group-faq-directory))))))
6286   (let (gnus-faq-buffer)
6287     (when (setq gnus-faq-buffer
6288                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6289       (gnus-configure-windows 'summary-faq))))
6290
6291 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6292 (defun gnus-summary-describe-group (&optional force)
6293   "Describe the current newsgroup."
6294   (interactive "P")
6295   (gnus-group-describe-group force gnus-newsgroup-name))
6296
6297 (defun gnus-summary-describe-briefly ()
6298   "Describe summary mode commands briefly."
6299   (interactive)
6300   (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")))
6301
6302 ;; Walking around group mode buffer from summary mode.
6303
6304 (defun gnus-summary-next-group (&optional no-article target-group backward)
6305   "Exit current newsgroup and then select next unread newsgroup.
6306 If prefix argument NO-ARTICLE is non-nil, no article is selected
6307 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6308 previous group instead."
6309   (interactive "P")
6310   ;; Stop pre-fetching.
6311   (gnus-async-halt-prefetch)
6312   (let ((current-group gnus-newsgroup-name)
6313         (current-buffer (current-buffer))
6314         entered)
6315    ;; First we semi-exit this group to update Xrefs and all variables.
6316     ;; We can't do a real exit, because the window conf must remain
6317     ;; the same in case the user is prompted for info, and we don't
6318     ;; want the window conf to change before that...
6319     (gnus-summary-exit t)
6320     (while (not entered)
6321       ;; Then we find what group we are supposed to enter.
6322       (set-buffer gnus-group-buffer)
6323       (gnus-group-jump-to-group current-group)
6324       (setq target-group
6325             (or target-group
6326                 (if (eq gnus-keep-same-level 'best)
6327                     (gnus-summary-best-group gnus-newsgroup-name)
6328                   (gnus-summary-search-group backward gnus-keep-same-level))))
6329       (if (not target-group)
6330           ;; There are no further groups, so we return to the group
6331           ;; buffer.
6332           (progn
6333             (gnus-message 5 "Returning to the group buffer")
6334             (setq entered t)
6335             (when (gnus-buffer-live-p current-buffer)
6336               (set-buffer current-buffer)
6337               (gnus-summary-exit))
6338             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6339         ;; We try to enter the target group.
6340         (gnus-group-jump-to-group target-group)
6341         (let ((unreads (gnus-group-group-unread)))
6342           (if (and (or (eq t unreads)
6343                        (and unreads (not (zerop unreads))))
6344                    (gnus-summary-read-group
6345                     target-group nil no-article
6346                     (and (buffer-name current-buffer) current-buffer)
6347                     nil backward))
6348               (setq entered t)
6349             (setq current-group target-group
6350                   target-group nil)))))))
6351
6352 (defun gnus-summary-prev-group (&optional no-article)
6353   "Exit current newsgroup and then select previous unread newsgroup.
6354 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6355   (interactive "P")
6356   (gnus-summary-next-group no-article nil t))
6357
6358 ;; Walking around summary lines.
6359
6360 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6361   "Go to the first unread subject.
6362 If UNREAD is non-nil, go to the first unread article.
6363 Returns the article selected or nil if there are no unread articles."
6364   (interactive "P")
6365   (prog1
6366       (cond
6367        ;; Empty summary.
6368        ((null gnus-newsgroup-data)
6369         (gnus-message 3 "No articles in the group")
6370         nil)
6371        ;; Pick the first article.
6372        ((not unread)
6373         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6374         (gnus-data-number (car gnus-newsgroup-data)))
6375        ;; No unread articles.
6376        ((null gnus-newsgroup-unreads)
6377         (gnus-message 3 "No more unread articles")
6378         nil)
6379        ;; Find the first unread article.
6380        (t
6381         (let ((data gnus-newsgroup-data))
6382           (while (and data
6383                       (and (not (and undownloaded
6384                                      (eq gnus-undownloaded-mark
6385                                          (gnus-data-mark (car data)))))
6386                            (if unseen
6387                                (or (not (memq
6388                                          (gnus-data-number (car data))
6389                                          gnus-newsgroup-unseen))
6390                                    (not (gnus-data-unread-p (car data))))
6391                              (not (gnus-data-unread-p (car data))))))
6392             (setq data (cdr data)))
6393           (when data
6394             (goto-char (gnus-data-pos (car data)))
6395             (gnus-data-number (car data))))))
6396     (gnus-summary-position-point)))
6397
6398 (defun gnus-summary-next-subject (n &optional unread dont-display)
6399   "Go to next N'th summary line.
6400 If N is negative, go to the previous N'th subject line.
6401 If UNREAD is non-nil, only unread articles are selected.
6402 The difference between N and the actual number of steps taken is
6403 returned."
6404   (interactive "p")
6405   (let ((backward (< n 0))
6406         (n (abs n)))
6407     (while (and (> n 0)
6408                 (if backward
6409                     (gnus-summary-find-prev unread)
6410                   (gnus-summary-find-next unread)))
6411       (unless (zerop (setq n (1- n)))
6412         (gnus-summary-show-thread)))
6413     (when (/= 0 n)
6414       (gnus-message 7 "No more%s articles"
6415                     (if unread " unread" "")))
6416     (unless dont-display
6417       (gnus-summary-recenter)
6418       (gnus-summary-position-point))
6419     n))
6420
6421 (defun gnus-summary-next-unread-subject (n)
6422   "Go to next N'th unread summary line."
6423   (interactive "p")
6424   (gnus-summary-next-subject n t))
6425
6426 (defun gnus-summary-prev-subject (n &optional unread)
6427   "Go to previous N'th summary line.
6428 If optional argument UNREAD is non-nil, only unread article is selected."
6429   (interactive "p")
6430   (gnus-summary-next-subject (- n) unread))
6431
6432 (defun gnus-summary-prev-unread-subject (n)
6433   "Go to previous N'th unread summary line."
6434   (interactive "p")
6435   (gnus-summary-next-subject (- n) t))
6436
6437 (defun gnus-summary-goto-subject (article &optional force silent)
6438   "Go the subject line of ARTICLE.
6439 If FORCE, also allow jumping to articles not currently shown."
6440   (interactive "nArticle number: ")
6441   (let ((b (point))
6442         (data (gnus-data-find article)))
6443     ;; We read in the article if we have to.
6444     (and (not data)
6445          force
6446          (gnus-summary-insert-subject
6447           article
6448           (if (or (numberp force) (vectorp force)) force)
6449           t)
6450          (setq data (gnus-data-find article)))
6451     (goto-char b)
6452     (if (not data)
6453         (progn
6454           (unless silent
6455             (gnus-message 3 "Can't find article %d" article))
6456           nil)
6457       (let ((pt (gnus-data-pos data)))
6458         (goto-char pt)
6459         (gnus-summary-set-article-display-arrow pt))
6460       (gnus-summary-position-point)
6461       article)))
6462
6463 ;; Walking around summary lines with displaying articles.
6464
6465 (defun gnus-summary-expand-window (&optional arg)
6466   "Make the summary buffer take up the entire Emacs frame.
6467 Given a prefix, will force an `article' buffer configuration."
6468   (interactive "P")
6469   (if arg
6470       (gnus-configure-windows 'article 'force)
6471     (gnus-configure-windows 'summary 'force)))
6472
6473 (defun gnus-summary-display-article (article &optional all-header)
6474   "Display ARTICLE in article buffer."
6475   (when (gnus-buffer-live-p gnus-article-buffer)
6476     (with-current-buffer gnus-article-buffer
6477       (mm-enable-multibyte)))
6478   (gnus-set-global-variables)
6479   (when (gnus-buffer-live-p gnus-article-buffer)
6480     (with-current-buffer gnus-article-buffer
6481       (setq gnus-article-charset gnus-newsgroup-charset)
6482       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6483       (mm-enable-multibyte)))
6484   (if (null article)
6485       nil
6486     (prog1
6487         (if gnus-summary-display-article-function
6488             (funcall gnus-summary-display-article-function article all-header)
6489           (gnus-article-prepare article all-header))
6490       (gnus-run-hooks 'gnus-select-article-hook)
6491       (when (and gnus-current-article
6492                  (not (zerop gnus-current-article)))
6493         (gnus-summary-goto-subject gnus-current-article))
6494       (gnus-summary-recenter)
6495       (when (and gnus-use-trees gnus-show-threads)
6496         (gnus-possibly-generate-tree article)
6497         (gnus-highlight-selected-tree article))
6498       ;; Successfully display article.
6499       (gnus-article-set-window-start
6500        (cdr (assq article gnus-newsgroup-bookmarks))))))
6501
6502 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6503   "Select the current article.
6504 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6505 non-nil, the article will be re-fetched even if it already present in
6506 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6507 be displayed."
6508   ;; Make sure we are in the summary buffer to work around bbdb bug.
6509   (unless (eq major-mode 'gnus-summary-mode)
6510     (set-buffer gnus-summary-buffer))
6511   (let ((article (or article (gnus-summary-article-number)))
6512         (all-headers (not (not all-headers))) ;Must be t or nil.
6513         gnus-summary-display-article-function)
6514     (and (not pseudo)
6515          (gnus-summary-article-pseudo-p article)
6516          (error "This is a pseudo-article"))
6517     (save-excursion
6518       (set-buffer gnus-summary-buffer)
6519       (if (or (and gnus-single-article-buffer
6520                    (or (null gnus-current-article)
6521                        (null gnus-article-current)
6522                        (null (get-buffer gnus-article-buffer))
6523                        (not (eq article (cdr gnus-article-current)))
6524                        (not (equal (car gnus-article-current)
6525                                    gnus-newsgroup-name))))
6526               (and (not gnus-single-article-buffer)
6527                    (or (null gnus-current-article)
6528                        (not (eq gnus-current-article article))))
6529               force)
6530        ;; The requested article is different from the current article.
6531           (progn
6532             (gnus-summary-display-article article all-headers)
6533             (when (gnus-buffer-live-p gnus-article-buffer)
6534               (with-current-buffer gnus-article-buffer
6535                 (if (not gnus-article-decoded-p) ;; a local variable
6536                     (mm-disable-multibyte))))
6537             (when (or all-headers gnus-show-all-headers)
6538               (gnus-article-show-all-headers))
6539             (gnus-article-set-window-start
6540              (cdr (assq article gnus-newsgroup-bookmarks)))
6541             article)
6542         (when (or all-headers gnus-show-all-headers)
6543           (gnus-article-show-all-headers))
6544         'old))))
6545
6546 (defun gnus-summary-force-verify-and-decrypt ()
6547   (interactive)
6548   (let ((mm-verify-option 'known)
6549         (mm-decrypt-option 'known))
6550     (gnus-summary-select-article nil 'force)))
6551
6552 (defun gnus-summary-set-current-mark (&optional current-mark)
6553   "Obsolete function."
6554   nil)
6555
6556 (defun gnus-summary-next-article (&optional unread subject backward push)
6557   "Select the next article.
6558 If UNREAD, only unread articles are selected.
6559 If SUBJECT, only articles with SUBJECT are selected.
6560 If BACKWARD, the previous article is selected instead of the next."
6561   (interactive "P")
6562   (cond
6563    ;; Is there such an article?
6564    ((and (gnus-summary-search-forward unread subject backward)
6565          (or (gnus-summary-display-article (gnus-summary-article-number))
6566              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6567     (gnus-summary-position-point))
6568    ;; If not, we try the first unread, if that is wanted.
6569    ((and subject
6570          gnus-auto-select-same
6571          (gnus-summary-first-unread-article))
6572     (gnus-summary-position-point)
6573     (gnus-message 6 "Wrapped"))
6574    ;; Try to get next/previous article not displayed in this group.
6575    ((and gnus-auto-extend-newsgroup
6576          (not unread) (not subject))
6577     (gnus-summary-goto-article
6578      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6579      nil (count-lines (point-min) (point))))
6580    ;; Go to next/previous group.
6581    (t
6582     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6583       (gnus-summary-jump-to-group gnus-newsgroup-name))
6584     (let ((cmd last-command-char)
6585           (point
6586            (save-excursion
6587              (set-buffer gnus-group-buffer)
6588              (point)))
6589           (group
6590            (if (eq gnus-keep-same-level 'best)
6591                (gnus-summary-best-group gnus-newsgroup-name)
6592              (gnus-summary-search-group backward gnus-keep-same-level))))
6593       ;; For some reason, the group window gets selected.  We change
6594       ;; it back.
6595       (select-window (get-buffer-window (current-buffer)))
6596       ;; Select next unread newsgroup automagically.
6597       (cond
6598        ((or (not gnus-auto-select-next)
6599             (not cmd))
6600         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6601        ((or (eq gnus-auto-select-next 'quietly)
6602             (and (eq gnus-auto-select-next 'slightly-quietly)
6603                  push)
6604             (and (eq gnus-auto-select-next 'almost-quietly)
6605                  (gnus-summary-last-article-p)))
6606         ;; Select quietly.
6607         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6608             (gnus-summary-exit)
6609           (gnus-message 7 "No more%s articles (%s)..."
6610                         (if unread " unread" "")
6611                         (if group (concat "selecting " group)
6612                           "exiting"))
6613           (gnus-summary-next-group nil group backward)))
6614        (t
6615         (when (gnus-key-press-event-p last-input-event)
6616           (gnus-summary-walk-group-buffer
6617            gnus-newsgroup-name cmd unread backward point))))))))
6618
6619 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6620   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6621                       (?\C-p (gnus-group-prev-unread-group 1))))
6622         (cursor-in-echo-area t)
6623         keve key group ended)
6624     (save-excursion
6625       (set-buffer gnus-group-buffer)
6626       (goto-char start)
6627       (setq group
6628             (if (eq gnus-keep-same-level 'best)
6629                 (gnus-summary-best-group gnus-newsgroup-name)
6630               (gnus-summary-search-group backward gnus-keep-same-level))))
6631     (while (not ended)
6632       (gnus-message
6633        5 "No more%s articles%s" (if unread " unread" "")
6634        (if (and group
6635                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6636            (format " (Type %s for %s [%s])"
6637                    (single-key-description cmd) group
6638                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6639          (format " (Type %s to exit %s)"
6640                  (single-key-description cmd)
6641                  gnus-newsgroup-name)))
6642       ;; Confirm auto selection.
6643       (setq key (car (setq keve (gnus-read-event-char))))
6644       (setq ended t)
6645       (cond
6646        ((assq key keystrokes)
6647         (let ((obuf (current-buffer)))
6648           (switch-to-buffer gnus-group-buffer)
6649           (when group
6650             (gnus-group-jump-to-group group))
6651           (eval (cadr (assq key keystrokes)))
6652           (setq group (gnus-group-group-name))
6653           (switch-to-buffer obuf))
6654         (setq ended nil))
6655        ((equal key cmd)
6656         (if (or (not group)
6657                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6658             (gnus-summary-exit)
6659           (gnus-summary-next-group nil group backward)))
6660        (t
6661         (push (cdr keve) unread-command-events))))))
6662
6663 (defun gnus-summary-next-unread-article ()
6664   "Select unread article after current one."
6665   (interactive)
6666   (gnus-summary-next-article
6667    (or (not (eq gnus-summary-goto-unread 'never))
6668        (gnus-summary-last-article-p (gnus-summary-article-number)))
6669    (and gnus-auto-select-same
6670         (gnus-summary-article-subject))))
6671
6672 (defun gnus-summary-prev-article (&optional unread subject)
6673   "Select the article after the current one.
6674 If UNREAD is non-nil, only unread articles are selected."
6675   (interactive "P")
6676   (gnus-summary-next-article unread subject t))
6677
6678 (defun gnus-summary-prev-unread-article ()
6679   "Select unread article before current one."
6680   (interactive)
6681   (gnus-summary-prev-article
6682    (or (not (eq gnus-summary-goto-unread 'never))
6683        (gnus-summary-first-article-p (gnus-summary-article-number)))
6684    (and gnus-auto-select-same
6685         (gnus-summary-article-subject))))
6686
6687 (defun gnus-summary-next-page (&optional lines circular)
6688   "Show next page of the selected article.
6689 If at the end of the current article, select the next article.
6690 LINES says how many lines should be scrolled up.
6691
6692 If CIRCULAR is non-nil, go to the start of the article instead of
6693 selecting the next article when reaching the end of the current
6694 article."
6695   (interactive "P")
6696   (setq gnus-summary-buffer (current-buffer))
6697   (gnus-set-global-variables)
6698   (let ((article (gnus-summary-article-number))
6699         (article-window (get-buffer-window gnus-article-buffer t))
6700         endp)
6701     ;; If the buffer is empty, we have no article.
6702     (unless article
6703       (error "No article to select"))
6704     (gnus-configure-windows 'article)
6705     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6706         (if (and (eq gnus-summary-goto-unread 'never)
6707                  (not (gnus-summary-last-article-p article)))
6708             (gnus-summary-next-article)
6709           (gnus-summary-next-unread-article))
6710       (if (or (null gnus-current-article)
6711               (null gnus-article-current)
6712               (/= article (cdr gnus-article-current))
6713               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6714           ;; Selected subject is different from current article's.
6715           (gnus-summary-display-article article)
6716         (when article-window
6717           (gnus-eval-in-buffer-window gnus-article-buffer
6718             (setq endp (gnus-article-next-page lines)))
6719           (when endp
6720             (cond (circular
6721                    (gnus-summary-beginning-of-article))
6722                   (lines
6723                    (gnus-message 3 "End of message"))
6724                   ((null lines)
6725                    (if (and (eq gnus-summary-goto-unread 'never)
6726                             (not (gnus-summary-last-article-p article)))
6727                        (gnus-summary-next-article)
6728                      (gnus-summary-next-unread-article))))))))
6729     (gnus-summary-recenter)
6730     (gnus-summary-position-point)))
6731
6732 (defun gnus-summary-prev-page (&optional lines move)
6733   "Show previous page of selected article.
6734 Argument LINES specifies lines to be scrolled down.
6735 If MOVE, move to the previous unread article if point is at
6736 the beginning of the buffer."
6737   (interactive "P")
6738   (let ((article (gnus-summary-article-number))
6739         (article-window (get-buffer-window gnus-article-buffer t))
6740         endp)
6741     (gnus-configure-windows 'article)
6742     (if (or (null gnus-current-article)
6743             (null gnus-article-current)
6744             (/= article (cdr gnus-article-current))
6745             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6746         ;; Selected subject is different from current article's.
6747         (gnus-summary-display-article article)
6748       (gnus-summary-recenter)
6749       (when article-window
6750         (gnus-eval-in-buffer-window gnus-article-buffer
6751           (setq endp (gnus-article-prev-page lines)))
6752         (when (and move endp)
6753           (cond (lines
6754                  (gnus-message 3 "Beginning of message"))
6755                 ((null lines)
6756                  (if (and (eq gnus-summary-goto-unread 'never)
6757                           (not (gnus-summary-first-article-p article)))
6758                      (gnus-summary-prev-article)
6759                    (gnus-summary-prev-unread-article))))))))
6760   (gnus-summary-position-point))
6761
6762 (defun gnus-summary-prev-page-or-article (&optional lines)
6763   "Show previous page of selected article.
6764 Argument LINES specifies lines to be scrolled down.
6765 If at the beginning of the article, go to the next article."
6766   (interactive "P")
6767   (gnus-summary-prev-page lines t))
6768
6769 (defun gnus-summary-scroll-up (lines)
6770   "Scroll up (or down) one line current article.
6771 Argument LINES specifies lines to be scrolled up (or down if negative)."
6772   (interactive "p")
6773   (gnus-configure-windows 'article)
6774   (gnus-summary-show-thread)
6775   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6776     (gnus-eval-in-buffer-window gnus-article-buffer
6777       (cond ((> lines 0)
6778              (when (gnus-article-next-page lines)
6779                (gnus-message 3 "End of message")))
6780             ((< lines 0)
6781              (gnus-article-prev-page (- lines))))))
6782   (gnus-summary-recenter)
6783   (gnus-summary-position-point))
6784
6785 (defun gnus-summary-scroll-down (lines)
6786   "Scroll down (or up) one line current article.
6787 Argument LINES specifies lines to be scrolled down (or up if negative)."
6788   (interactive "p")
6789   (gnus-summary-scroll-up (- lines)))
6790
6791 (defun gnus-summary-next-same-subject ()
6792   "Select next article which has the same subject as current one."
6793   (interactive)
6794   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6795
6796 (defun gnus-summary-prev-same-subject ()
6797   "Select previous article which has the same subject as current one."
6798   (interactive)
6799   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6800
6801 (defun gnus-summary-next-unread-same-subject ()
6802   "Select next unread article which has the same subject as current one."
6803   (interactive)
6804   (gnus-summary-next-article t (gnus-summary-article-subject)))
6805
6806 (defun gnus-summary-prev-unread-same-subject ()
6807   "Select previous unread article which has the same subject as current one."
6808   (interactive)
6809   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6810
6811 (defun gnus-summary-first-unread-article ()
6812   "Select the first unread article.
6813 Return nil if there are no unread articles."
6814   (interactive)
6815   (prog1
6816       (when (gnus-summary-first-subject t)
6817         (gnus-summary-show-thread)
6818         (gnus-summary-first-subject t)
6819         (gnus-summary-display-article (gnus-summary-article-number)))
6820     (gnus-summary-position-point)))
6821
6822 (defun gnus-summary-first-unread-subject ()
6823   "Place the point on the subject line of the first unread article.
6824 Return nil if there are no unread articles."
6825   (interactive)
6826   (prog1
6827       (when (gnus-summary-first-subject t)
6828         (gnus-summary-show-thread)
6829         (gnus-summary-first-subject t))
6830     (gnus-summary-position-point)))
6831
6832 (defun gnus-summary-first-unseen-subject ()
6833   "Place the point on the subject line of the first unseen article.
6834 Return nil if there are no unseen articles."
6835   (interactive)
6836   (prog1
6837       (when (gnus-summary-first-subject t t t)
6838         (gnus-summary-show-thread)
6839         (gnus-summary-first-subject t t t))
6840     (gnus-summary-position-point)))
6841
6842 (defun gnus-summary-first-article ()
6843   "Select the first article.
6844 Return nil if there are no articles."
6845   (interactive)
6846   (prog1
6847       (when (gnus-summary-first-subject)
6848         (gnus-summary-show-thread)
6849         (gnus-summary-first-subject)
6850         (gnus-summary-display-article (gnus-summary-article-number)))
6851     (gnus-summary-position-point)))
6852
6853 (defun gnus-summary-best-unread-article (&optional arg)
6854   "Select the unread article with the highest score.
6855 If given a prefix argument, select the next unread article that has a
6856 score higher than the default score."
6857   (interactive "P")
6858   (let ((article (if arg
6859                      (gnus-summary-better-unread-subject)
6860                    (gnus-summary-best-unread-subject))))
6861     (if article
6862         (gnus-summary-goto-article article)
6863       (error "No unread articles"))))
6864
6865 (defun gnus-summary-best-unread-subject ()
6866   "Select the unread subject with the highest score."
6867   (interactive)
6868   (let ((best -1000000)
6869         (data gnus-newsgroup-data)
6870         article score)
6871     (while data
6872       (and (gnus-data-unread-p (car data))
6873            (> (setq score
6874                     (gnus-summary-article-score (gnus-data-number (car data))))
6875               best)
6876            (setq best score
6877                  article (gnus-data-number (car data))))
6878       (setq data (cdr data)))
6879     (when article
6880       (gnus-summary-goto-subject article))
6881     (gnus-summary-position-point)
6882     article))
6883
6884 (defun gnus-summary-better-unread-subject ()
6885   "Select the first unread subject that has a score over the default score."
6886   (interactive)
6887   (let ((data gnus-newsgroup-data)
6888         article score)
6889     (while (and (setq article (gnus-data-number (car data)))
6890                 (or (gnus-data-read-p (car data))
6891                     (not (> (gnus-summary-article-score article)
6892                             gnus-summary-default-score))))
6893       (setq data (cdr data)))
6894     (when article
6895       (gnus-summary-goto-subject article))
6896     (gnus-summary-position-point)
6897     article))
6898
6899 (defun gnus-summary-last-subject ()
6900   "Go to the last displayed subject line in the group."
6901   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6902     (when article
6903       (gnus-summary-goto-subject article))))
6904
6905 (defun gnus-summary-goto-article (article &optional all-headers force)
6906   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6907 If ALL-HEADERS is non-nil, no header lines are hidden.
6908 If FORCE, go to the article even if it isn't displayed.  If FORCE
6909 is a number, it is the line the article is to be displayed on."
6910   (interactive
6911    (list
6912     (completing-read
6913      "Article number or Message-ID: "
6914      (mapcar (lambda (number) (list (int-to-string number)))
6915              gnus-newsgroup-limit))
6916     current-prefix-arg
6917     t))
6918   (prog1
6919       (if (and (stringp article)
6920                (string-match "@" article))
6921           (gnus-summary-refer-article article)
6922         (when (stringp article)
6923           (setq article (string-to-number article)))
6924         (if (gnus-summary-goto-subject article force)
6925             (gnus-summary-display-article article all-headers)
6926           (gnus-message 4 "Couldn't go to article %s" article) nil))
6927     (gnus-summary-position-point)))
6928
6929 (defun gnus-summary-goto-last-article ()
6930   "Go to the previously read article."
6931   (interactive)
6932   (prog1
6933       (when gnus-last-article
6934         (gnus-summary-goto-article gnus-last-article nil t))
6935     (gnus-summary-position-point)))
6936
6937 (defun gnus-summary-pop-article (number)
6938   "Pop one article off the history and go to the previous.
6939 NUMBER articles will be popped off."
6940   (interactive "p")
6941   (let (to)
6942     (setq gnus-newsgroup-history
6943           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6944     (if to
6945         (gnus-summary-goto-article (car to) nil t)
6946       (error "Article history empty")))
6947   (gnus-summary-position-point))
6948
6949 ;; Summary commands and functions for limiting the summary buffer.
6950
6951 (defun gnus-summary-limit-to-articles (n)
6952   "Limit the summary buffer to the next N articles.
6953 If not given a prefix, use the process marked articles instead."
6954   (interactive "P")
6955   (prog1
6956       (let ((articles (gnus-summary-work-articles n)))
6957         (setq gnus-newsgroup-processable nil)
6958         (gnus-summary-limit articles))
6959     (gnus-summary-position-point)))
6960
6961 (defun gnus-summary-pop-limit (&optional total)
6962   "Restore the previous limit.
6963 If given a prefix, remove all limits."
6964   (interactive "P")
6965   (when total
6966     (setq gnus-newsgroup-limits
6967           (list (mapcar (lambda (h) (mail-header-number h))
6968                         gnus-newsgroup-headers))))
6969   (unless gnus-newsgroup-limits
6970     (error "No limit to pop"))
6971   (prog1
6972       (gnus-summary-limit nil 'pop)
6973     (gnus-summary-position-point)))
6974
6975 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6976   "Limit the summary buffer to articles that have subjects that match a regexp.
6977 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6978   (interactive
6979    (list (read-string (if current-prefix-arg
6980                           "Exclude subject (regexp): "
6981                         "Limit to subject (regexp): "))
6982          nil current-prefix-arg))
6983   (unless header
6984     (setq header "subject"))
6985   (when (not (equal "" subject))
6986     (prog1
6987         (let ((articles (gnus-summary-find-matching
6988                          (or header "subject") subject 'all nil nil
6989                          not-matching)))
6990           (unless articles
6991             (error "Found no matches for \"%s\"" subject))
6992           (gnus-summary-limit articles))
6993       (gnus-summary-position-point))))
6994
6995 (defun gnus-summary-limit-to-author (from &optional not-matching)
6996   "Limit the summary buffer to articles that have authors that match a regexp.
6997 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6998   (interactive
6999    (list (read-string (if current-prefix-arg
7000                           "Exclude author (regexp): "
7001                         "Limit to author (regexp): "))
7002          current-prefix-arg))
7003   (gnus-summary-limit-to-subject from "from" not-matching))
7004
7005 (defun gnus-summary-limit-to-age (age &optional younger-p)
7006   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7007 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7008 articles that are younger than AGE days."
7009   (interactive
7010    (let ((younger current-prefix-arg)
7011          (days-got nil)
7012          days)
7013      (while (not days-got)
7014        (setq days (if younger
7015                       (read-string "Limit to articles within (in days): ")
7016                     (read-string "Limit to articles older than (in days): ")))
7017        (when (> (length days) 0)
7018          (setq days (read days)))
7019        (if (numberp days)
7020            (progn 
7021              (setq days-got t)
7022              (if (< days 0)
7023                  (progn 
7024                    (setq younger (not younger))
7025                    (setq days (* days -1)))))
7026          (message "Please enter a number.")
7027          (sleep-for 1)))
7028      (list days younger)))
7029   (prog1
7030       (let ((data gnus-newsgroup-data)
7031             (cutoff (days-to-time age))
7032             articles d date is-younger)
7033         (while (setq d (pop data))
7034           (when (and (vectorp (gnus-data-header d))
7035                      (setq date (mail-header-date (gnus-data-header d))))
7036             (setq is-younger (time-less-p
7037                               (time-since (condition-case ()
7038                                               (date-to-time date)
7039                                             (error '(0 0))))
7040                               cutoff))
7041             (when (if younger-p
7042                       is-younger
7043                     (not is-younger))
7044               (push (gnus-data-number d) articles))))
7045         (gnus-summary-limit (nreverse articles)))
7046     (gnus-summary-position-point)))
7047
7048 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7049   "Limit the summary buffer to articles that match an 'extra' header."
7050   (interactive
7051    (let ((header
7052           (intern
7053            (gnus-completing-read
7054             (symbol-name (car gnus-extra-headers))
7055             (if current-prefix-arg
7056                 "Exclude extra header:"
7057               "Limit extra header:")
7058             (mapcar (lambda (x)
7059                       (cons (symbol-name x) x))
7060                     gnus-extra-headers)
7061             nil
7062             t))))
7063      (list header
7064            (read-string (format "%s header %s (regexp): "
7065                                 (if current-prefix-arg "Exclude" "Limit to")
7066                                 header))
7067            current-prefix-arg)))
7068   (when (not (equal "" regexp))
7069     (prog1
7070         (let ((articles (gnus-summary-find-matching
7071                          (cons 'extra header) regexp 'all nil nil
7072                          not-matching)))
7073           (unless articles
7074             (error "Found no matches for \"%s\"" regexp))
7075           (gnus-summary-limit articles))
7076       (gnus-summary-position-point))))
7077
7078 (defun gnus-summary-limit-to-display-predicate ()
7079   "Limit the summary buffer to the predicated in the `display' group parameter."
7080   (interactive)
7081   (unless gnus-newsgroup-display
7082     (error "There is no `display' group parameter"))
7083   (let (articles)
7084     (dolist (number gnus-newsgroup-articles)
7085       (when (funcall gnus-newsgroup-display)
7086         (push number articles)))
7087     (gnus-summary-limit articles))
7088   (gnus-summary-position-point))
7089
7090 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7091 (make-obsolete
7092  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7093
7094 (defun gnus-summary-limit-to-unread (&optional all)
7095   "Limit the summary buffer to articles that are not marked as read.
7096 If ALL is non-nil, limit strictly to unread articles."
7097   (interactive "P")
7098   (if all
7099       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7100     (gnus-summary-limit-to-marks
7101      ;; Concat all the marks that say that an article is read and have
7102      ;; those removed.
7103      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7104            gnus-killed-mark gnus-kill-file-mark
7105            gnus-low-score-mark gnus-expirable-mark
7106            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7107            gnus-duplicate-mark gnus-souped-mark)
7108      'reverse)))
7109
7110 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7111 (make-obsolete 'gnus-summary-delete-marked-with
7112                'gnus-summary-limit-exlude-marks)
7113
7114 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7115   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7116 If REVERSE, limit the summary buffer to articles that are marked
7117 with MARKS.  MARKS can either be a string of marks or a list of marks.
7118 Returns how many articles were removed."
7119   (interactive "sMarks: ")
7120   (gnus-summary-limit-to-marks marks t))
7121
7122 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7123   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7124 If REVERSE (the prefix), limit the summary buffer to articles that are
7125 not marked with MARKS.  MARKS can either be a string of marks or a
7126 list of marks.
7127 Returns how many articles were removed."
7128   (interactive "sMarks: \nP")
7129   (prog1
7130       (let ((data gnus-newsgroup-data)
7131             (marks (if (listp marks) marks
7132                      (append marks nil))) ; Transform to list.
7133             articles)
7134         (while data
7135           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7136                   (memq (gnus-data-mark (car data)) marks))
7137             (push (gnus-data-number (car data)) articles))
7138           (setq data (cdr data)))
7139         (gnus-summary-limit articles))
7140     (gnus-summary-position-point)))
7141
7142 (defun gnus-summary-limit-to-score (score)
7143   "Limit to articles with score at or above SCORE."
7144   (interactive "NLimit to articles with score of at least: ")
7145   (let ((data gnus-newsgroup-data)
7146         articles)
7147     (while data
7148       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7149                 score)
7150         (push (gnus-data-number (car data)) articles))
7151       (setq data (cdr data)))
7152     (prog1
7153         (gnus-summary-limit articles)
7154       (gnus-summary-position-point))))
7155
7156 (defun gnus-summary-limit-include-thread (id)
7157   "Display all the hidden articles that is in the thread with ID in it.
7158 When called interactively, ID is the Message-ID of the current
7159 article."
7160   (interactive (list (mail-header-id (gnus-summary-article-header))))
7161   (let ((articles (gnus-articles-in-thread
7162                    (gnus-id-to-thread (gnus-root-id id)))))
7163     (prog1
7164         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7165       (gnus-summary-limit-include-matching-articles
7166        "subject"
7167        (regexp-quote (gnus-simplify-subject-re
7168                       (mail-header-subject (gnus-id-to-header id)))))
7169       (gnus-summary-position-point))))
7170
7171 (defun gnus-summary-limit-include-matching-articles (header regexp)
7172   "Display all the hidden articles that have HEADERs that match REGEXP."
7173   (interactive (list (read-string "Match on header: ")
7174                      (read-string "Regexp: ")))
7175   (let ((articles (gnus-find-matching-articles header regexp)))
7176     (prog1
7177         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7178       (gnus-summary-position-point))))
7179
7180 (defun gnus-summary-limit-include-dormant ()
7181   "Display all the hidden articles that are marked as dormant.
7182 Note that this command only works on a subset of the articles currently
7183 fetched for this group."
7184   (interactive)
7185   (unless gnus-newsgroup-dormant
7186     (error "There are no dormant articles in this group"))
7187   (prog1
7188       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7189     (gnus-summary-position-point)))
7190
7191 (defun gnus-summary-limit-exclude-dormant ()
7192   "Hide all dormant articles."
7193   (interactive)
7194   (prog1
7195       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7196     (gnus-summary-position-point)))
7197
7198 (defun gnus-summary-limit-exclude-childless-dormant ()
7199   "Hide all dormant articles that have no children."
7200   (interactive)
7201   (let ((data (gnus-data-list t))
7202         articles d children)
7203     ;; Find all articles that are either not dormant or have
7204     ;; children.
7205     (while (setq d (pop data))
7206       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7207                 (and (setq children
7208                            (gnus-article-children (gnus-data-number d)))
7209                      (let (found)
7210                        (while children
7211                          (when (memq (car children) articles)
7212                            (setq children nil
7213                                  found t))
7214                          (pop children))
7215                        found)))
7216         (push (gnus-data-number d) articles)))
7217     ;; Do the limiting.
7218     (prog1
7219         (gnus-summary-limit articles)
7220       (gnus-summary-position-point))))
7221
7222 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7223   "Mark all unread excluded articles as read.
7224 If ALL, mark even excluded ticked and dormants as read."
7225   (interactive "P")
7226   (let ((articles (gnus-sorted-complement
7227                    (sort
7228                     (mapcar (lambda (h) (mail-header-number h))
7229                             gnus-newsgroup-headers)
7230                     '<)
7231                    (sort gnus-newsgroup-limit '<)))
7232         article)
7233     (setq gnus-newsgroup-unreads
7234           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7235     (if all
7236         (setq gnus-newsgroup-dormant nil
7237               gnus-newsgroup-marked nil
7238               gnus-newsgroup-reads
7239               (nconc
7240                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7241                gnus-newsgroup-reads))
7242       (while (setq article (pop articles))
7243         (unless (or (memq article gnus-newsgroup-dormant)
7244                     (memq article gnus-newsgroup-marked))
7245           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7246
7247 (defun gnus-summary-limit (articles &optional pop)
7248   (if pop
7249       ;; We pop the previous limit off the stack and use that.
7250       (setq articles (car gnus-newsgroup-limits)
7251             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7252     ;; We use the new limit, so we push the old limit on the stack.
7253     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7254   ;; Set the limit.
7255   (setq gnus-newsgroup-limit articles)
7256   (let ((total (length gnus-newsgroup-data))
7257         (data (gnus-data-find-list (gnus-summary-article-number)))
7258         (gnus-summary-mark-below nil)   ; Inhibit this.
7259         found)
7260     ;; This will do all the work of generating the new summary buffer
7261     ;; according to the new limit.
7262     (gnus-summary-prepare)
7263     ;; Hide any threads, possibly.
7264     (gnus-summary-maybe-hide-threads)
7265     ;; Try to return to the article you were at, or one in the
7266     ;; neighborhood.
7267     (when data
7268       ;; We try to find some article after the current one.
7269       (while data
7270         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7271           (setq data nil
7272                 found t))
7273         (setq data (cdr data))))
7274     (unless found
7275       ;; If there is no data, that means that we were after the last
7276       ;; article.  The same goes when we can't find any articles
7277       ;; after the current one.
7278       (goto-char (point-max))
7279       (gnus-summary-find-prev))
7280     (gnus-set-mode-line 'summary)
7281     ;; We return how many articles were removed from the summary
7282     ;; buffer as a result of the new limit.
7283     (- total (length gnus-newsgroup-data))))
7284
7285 (defsubst gnus-invisible-cut-children (threads)
7286   (let ((num 0))
7287     (while threads
7288       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7289         (incf num))
7290       (pop threads))
7291     (< num 2)))
7292
7293 (defsubst gnus-cut-thread (thread)
7294   "Go forwards in the thread until we find an article that we want to display."
7295   (when (or (eq gnus-fetch-old-headers 'some)
7296             (eq gnus-fetch-old-headers 'invisible)
7297             (numberp gnus-fetch-old-headers)
7298             (eq gnus-build-sparse-threads 'some)
7299             (eq gnus-build-sparse-threads 'more))
7300     ;; Deal with old-fetched headers and sparse threads.
7301     (while (and
7302             thread
7303             (or
7304              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7305              (gnus-summary-article-ancient-p
7306               (mail-header-number (car thread))))
7307             (if (or (<= (length (cdr thread)) 1)
7308                     (eq gnus-fetch-old-headers 'invisible))
7309                 (setq gnus-newsgroup-limit
7310                       (delq (mail-header-number (car thread))
7311                             gnus-newsgroup-limit)
7312                       thread (cadr thread))
7313               (when (gnus-invisible-cut-children (cdr thread))
7314                 (let ((th (cdr thread)))
7315                   (while th
7316                     (if (memq (mail-header-number (caar th))
7317                               gnus-newsgroup-limit)
7318                         (setq thread (car th)
7319                               th nil)
7320                       (setq th (cdr th))))))))))
7321   thread)
7322
7323 (defun gnus-cut-threads (threads)
7324   "Cut off all uninteresting articles from the beginning of threads."
7325   (when (or (eq gnus-fetch-old-headers 'some)
7326             (eq gnus-fetch-old-headers 'invisible)
7327             (numberp gnus-fetch-old-headers)
7328             (eq gnus-build-sparse-threads 'some)
7329             (eq gnus-build-sparse-threads 'more))
7330     (let ((th threads))
7331       (while th
7332         (setcar th (gnus-cut-thread (car th)))
7333         (setq th (cdr th)))))
7334   ;; Remove nixed out threads.
7335   (delq nil threads))
7336
7337 (defun gnus-summary-initial-limit (&optional show-if-empty)
7338   "Figure out what the initial limit is supposed to be on group entry.
7339 This entails weeding out unwanted dormants, low-scored articles,
7340 fetch-old-headers verbiage, and so on."
7341   ;; Most groups have nothing to remove.
7342   (if (or gnus-inhibit-limiting
7343           (and (null gnus-newsgroup-dormant)
7344                (eq gnus-newsgroup-display 'gnus-not-ignore)
7345                (not (eq gnus-fetch-old-headers 'some))
7346                (not (numberp gnus-fetch-old-headers))
7347                (not (eq gnus-fetch-old-headers 'invisible))
7348                (null gnus-summary-expunge-below)
7349                (not (eq gnus-build-sparse-threads 'some))
7350                (not (eq gnus-build-sparse-threads 'more))
7351                (null gnus-thread-expunge-below)
7352                (not gnus-use-nocem)))
7353       ()                                ; Do nothing.
7354     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7355     (setq gnus-newsgroup-limit nil)
7356     (mapatoms
7357      (lambda (node)
7358        (unless (car (symbol-value node))
7359          ;; These threads have no parents -- they are roots.
7360          (let ((nodes (cdr (symbol-value node)))
7361                thread)
7362            (while nodes
7363              (if (and gnus-thread-expunge-below
7364                       (< (gnus-thread-total-score (car nodes))
7365                          gnus-thread-expunge-below))
7366                  (gnus-expunge-thread (pop nodes))
7367                (setq thread (pop nodes))
7368                (gnus-summary-limit-children thread))))))
7369      gnus-newsgroup-dependencies)
7370     ;; If this limitation resulted in an empty group, we might
7371     ;; pop the previous limit and use it instead.
7372     (when (and (not gnus-newsgroup-limit)
7373                show-if-empty)
7374       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7375     gnus-newsgroup-limit))
7376
7377 (defun gnus-summary-limit-children (thread)
7378   "Return 1 if this subthread is visible and 0 if it is not."
7379   ;; First we get the number of visible children to this thread.  This
7380   ;; is done by recursing down the thread using this function, so this
7381   ;; will really go down to a leaf article first, before slowly
7382   ;; working its way up towards the root.
7383   (when thread
7384     (let ((children
7385            (if (cdr thread)
7386                (apply '+ (mapcar 'gnus-summary-limit-children
7387                                  (cdr thread)))
7388              0))
7389           (number (mail-header-number (car thread)))
7390           score)
7391       (if (and
7392            (not (memq number gnus-newsgroup-marked))
7393            (or
7394             ;; If this article is dormant and has absolutely no visible
7395             ;; children, then this article isn't visible.
7396             (and (memq number gnus-newsgroup-dormant)
7397                  (zerop children))
7398             ;; If this is "fetch-old-headered" and there is no
7399             ;; visible children, then we don't want this article.
7400             (and (or (eq gnus-fetch-old-headers 'some)
7401                      (numberp gnus-fetch-old-headers))
7402                  (gnus-summary-article-ancient-p number)
7403                  (zerop children))
7404             ;; If this is "fetch-old-headered" and `invisible', then
7405             ;; we don't want this article.
7406             (and (eq gnus-fetch-old-headers 'invisible)
7407                  (gnus-summary-article-ancient-p number))
7408             ;; If this is a sparsely inserted article with no children,
7409             ;; we don't want it.
7410             (and (eq gnus-build-sparse-threads 'some)
7411                  (gnus-summary-article-sparse-p number)
7412                  (zerop children))
7413             ;; If we use expunging, and this article is really
7414             ;; low-scored, then we don't want this article.
7415             (when (and gnus-summary-expunge-below
7416                        (< (setq score
7417                                 (or (cdr (assq number gnus-newsgroup-scored))
7418                                     gnus-summary-default-score))
7419                           gnus-summary-expunge-below))
7420               ;; We increase the expunge-tally here, but that has
7421               ;; nothing to do with the limits, really.
7422               (incf gnus-newsgroup-expunged-tally)
7423               ;; We also mark as read here, if that's wanted.
7424               (when (and gnus-summary-mark-below
7425                          (< score gnus-summary-mark-below))
7426                 (setq gnus-newsgroup-unreads
7427                       (delq number gnus-newsgroup-unreads))
7428                 (if gnus-newsgroup-auto-expire
7429                     (push number gnus-newsgroup-expirable)
7430                   (push (cons number gnus-low-score-mark)
7431                         gnus-newsgroup-reads)))
7432               t)
7433             ;; Do the `display' group parameter.
7434             (and gnus-newsgroup-display
7435                  (not (funcall gnus-newsgroup-display)))
7436             ;; Check NoCeM things.
7437             (if (and gnus-use-nocem
7438                      (gnus-nocem-unwanted-article-p
7439                       (mail-header-id (car thread))))
7440                 (progn
7441                   (setq gnus-newsgroup-unreads
7442                         (delq number gnus-newsgroup-unreads))
7443                   t))))
7444           ;; Nope, invisible article.
7445           0
7446         ;; Ok, this article is to be visible, so we add it to the limit
7447         ;; and return 1.
7448         (push number gnus-newsgroup-limit)
7449         1))))
7450
7451 (defun gnus-expunge-thread (thread)
7452   "Mark all articles in THREAD as read."
7453   (let* ((number (mail-header-number (car thread))))
7454     (incf gnus-newsgroup-expunged-tally)
7455     ;; We also mark as read here, if that's wanted.
7456     (setq gnus-newsgroup-unreads
7457           (delq number gnus-newsgroup-unreads))
7458     (if gnus-newsgroup-auto-expire
7459         (push number gnus-newsgroup-expirable)
7460       (push (cons number gnus-low-score-mark)
7461             gnus-newsgroup-reads)))
7462   ;; Go recursively through all subthreads.
7463   (mapcar 'gnus-expunge-thread (cdr thread)))
7464
7465 ;; Summary article oriented commands
7466
7467 (defun gnus-summary-refer-parent-article (n)
7468   "Refer parent article N times.
7469 If N is negative, go to ancestor -N instead.
7470 The difference between N and the number of articles fetched is returned."
7471   (interactive "p")
7472   (let ((skip 1)
7473         error header ref)
7474     (when (not (natnump n))
7475       (setq skip (abs n)
7476             n 1))
7477     (while (and (> n 0)
7478                 (not error))
7479       (setq header (gnus-summary-article-header))
7480       (if (and (eq (mail-header-number header)
7481                    (cdr gnus-article-current))
7482                (equal gnus-newsgroup-name
7483                       (car gnus-article-current)))
7484           ;; If we try to find the parent of the currently
7485           ;; displayed article, then we take a look at the actual
7486           ;; References header, since this is slightly more
7487           ;; reliable than the References field we got from the
7488           ;; server.
7489           (save-excursion
7490             (set-buffer gnus-original-article-buffer)
7491             (nnheader-narrow-to-headers)
7492             (unless (setq ref (message-fetch-field "references"))
7493               (setq ref (message-fetch-field "in-reply-to")))
7494             (widen))
7495         (setq ref
7496               ;; It's not the current article, so we take a bet on
7497               ;; the value we got from the server.
7498               (mail-header-references header)))
7499       (if (and ref
7500                (not (equal ref "")))
7501           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7502             (gnus-message 1 "Couldn't find parent"))
7503         (gnus-message 1 "No references in article %d"
7504                       (gnus-summary-article-number))
7505         (setq error t))
7506       (decf n))
7507     (gnus-summary-position-point)
7508     n))
7509
7510 (defun gnus-summary-refer-references ()
7511   "Fetch all articles mentioned in the References header.
7512 Return the number of articles fetched."
7513   (interactive)
7514   (let ((ref (mail-header-references (gnus-summary-article-header)))
7515         (current (gnus-summary-article-number))
7516         (n 0))
7517     (if (or (not ref)
7518             (equal ref ""))
7519         (error "No References in the current article")
7520       ;; For each Message-ID in the References header...
7521       (while (string-match "<[^>]*>" ref)
7522         (incf n)
7523         ;; ... fetch that article.
7524         (gnus-summary-refer-article
7525          (prog1 (match-string 0 ref)
7526            (setq ref (substring ref (match-end 0))))))
7527       (gnus-summary-goto-subject current)
7528       (gnus-summary-position-point)
7529       n)))
7530
7531 (defun gnus-summary-refer-thread (&optional limit)
7532   "Fetch all articles in the current thread.
7533 If LIMIT (the numerical prefix), fetch that many old headers instead
7534 of what's specified by the `gnus-refer-thread-limit' variable."
7535   (interactive "P")
7536   (let ((id (mail-header-id (gnus-summary-article-header)))
7537         (limit (if limit (prefix-numeric-value limit)
7538                  gnus-refer-thread-limit)))
7539     ;; We want to fetch LIMIT *old* headers, but we also have to
7540     ;; re-fetch all the headers in the current buffer, because many of
7541     ;; them may be undisplayed.  So we adjust LIMIT.
7542     (when (numberp limit)
7543       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7544     (unless (eq gnus-fetch-old-headers 'invisible)
7545       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7546       ;; Retrieve the headers and read them in.
7547       (if (eq (gnus-retrieve-headers
7548                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7549               'nov)
7550           (gnus-build-all-threads)
7551         (error "Can't fetch thread from backends that don't support NOV"))
7552       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7553     (gnus-summary-limit-include-thread id)))
7554
7555 (defun gnus-summary-refer-article (message-id)
7556   "Fetch an article specified by MESSAGE-ID."
7557   (interactive "sMessage-ID: ")
7558   (when (and (stringp message-id)
7559              (not (zerop (length message-id))))
7560     ;; Construct the correct Message-ID if necessary.
7561     ;; Suggested by tale@pawl.rpi.edu.
7562     (unless (string-match "^<" message-id)
7563       (setq message-id (concat "<" message-id)))
7564     (unless (string-match ">$" message-id)
7565       (setq message-id (concat message-id ">")))
7566     (let* ((header (gnus-id-to-header message-id))
7567            (sparse (and header
7568                         (gnus-summary-article-sparse-p
7569                          (mail-header-number header))
7570                         (memq (mail-header-number header)
7571                               gnus-newsgroup-limit)))
7572            number)
7573       (cond
7574        ;; If the article is present in the buffer we just go to it.
7575        ((and header
7576              (or (not (gnus-summary-article-sparse-p
7577                        (mail-header-number header)))
7578                  sparse))
7579         (prog1
7580             (gnus-summary-goto-article
7581              (mail-header-number header) nil t)
7582           (when sparse
7583             (gnus-summary-update-article (mail-header-number header)))))
7584        (t
7585         ;; We fetch the article.
7586         (catch 'found
7587           (dolist (gnus-override-method (gnus-refer-article-methods))
7588             (gnus-check-server gnus-override-method)
7589             ;; Fetch the header, and display the article.
7590             (when (setq number (gnus-summary-insert-subject message-id))
7591               (gnus-summary-select-article nil nil nil number)
7592               (throw 'found t)))
7593           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7594
7595 (defun gnus-refer-article-methods ()
7596   "Return a list of referrable methods."
7597   (cond
7598    ;; No method, so we default to current and native.
7599    ((null gnus-refer-article-method)
7600     (list gnus-current-select-method gnus-select-method))
7601    ;; Current.
7602    ((eq 'current gnus-refer-article-method)
7603     (list gnus-current-select-method))
7604    ;; List of select methods.
7605    ((not (and (symbolp (car gnus-refer-article-method))
7606               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7607     (let (out)
7608       (dolist (method gnus-refer-article-method)
7609         (push (if (eq 'current method)
7610                   gnus-current-select-method
7611                 method)
7612               out))
7613       (nreverse out)))
7614    ;; One single select method.
7615    (t
7616     (list gnus-refer-article-method))))
7617
7618 (defun gnus-summary-edit-parameters ()
7619   "Edit the group parameters of the current group."
7620   (interactive)
7621   (gnus-group-edit-group gnus-newsgroup-name 'params))
7622
7623 (defun gnus-summary-customize-parameters ()
7624   "Customize the group parameters of the current group."
7625   (interactive)
7626   (gnus-group-customize gnus-newsgroup-name))
7627
7628 (defun gnus-summary-enter-digest-group (&optional force)
7629   "Enter an nndoc group based on the current article.
7630 If FORCE, force a digest interpretation.  If not, try
7631 to guess what the document format is."
7632   (interactive "P")
7633   (let ((conf gnus-current-window-configuration))
7634     (save-excursion
7635       (gnus-summary-select-article))
7636     (setq gnus-current-window-configuration conf)
7637     (let* ((name (format "%s-%d"
7638                          (gnus-group-prefixed-name
7639                           gnus-newsgroup-name (list 'nndoc ""))
7640                          (save-excursion
7641                            (set-buffer gnus-summary-buffer)
7642                            gnus-current-article)))
7643            (ogroup gnus-newsgroup-name)
7644            (params (append (gnus-info-params (gnus-get-info ogroup))
7645                            (list (cons 'to-group ogroup))
7646                            (list (cons 'save-article-group ogroup))))
7647            (case-fold-search t)
7648            (buf (current-buffer))
7649            dig to-address)
7650       (save-excursion
7651         (set-buffer gnus-original-article-buffer)
7652         ;; Have the digest group inherit the main mail address of
7653         ;; the parent article.
7654         (when (setq to-address (or (message-fetch-field "reply-to")
7655                                    (message-fetch-field "from")))
7656           (setq params (append
7657                         (list (cons 'to-address
7658                                     (funcall gnus-decode-encoded-word-function
7659                                              to-address))))))
7660         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7661         (insert-buffer-substring gnus-original-article-buffer)
7662         ;; Remove lines that may lead nndoc to misinterpret the
7663         ;; document type.
7664         (narrow-to-region
7665          (goto-char (point-min))
7666          (or (search-forward "\n\n" nil t) (point)))
7667         (goto-char (point-min))
7668         (delete-matching-lines "^Path:\\|^From ")
7669         (widen))
7670       (unwind-protect
7671           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7672                     (gnus-newsgroup-ephemeral-ignored-charsets
7673                      gnus-newsgroup-ignored-charsets))
7674                 (gnus-group-read-ephemeral-group
7675                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7676                               (nndoc-article-type
7677                                ,(if force 'mbox 'guess)))
7678                  t nil nil nil
7679                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7680                                                         "ADAPT")))))
7681               ;; Make all postings to this group go to the parent group.
7682               (nconc (gnus-info-params (gnus-get-info name))
7683                      params)
7684             ;; Couldn't select this doc group.
7685             (switch-to-buffer buf)
7686             (gnus-set-global-variables)
7687             (gnus-configure-windows 'summary)
7688             (gnus-message 3 "Article couldn't be entered?"))
7689         (kill-buffer dig)))))
7690
7691 (defun gnus-summary-read-document (n)
7692   "Open a new group based on the current article(s).
7693 This will allow you to read digests and other similar
7694 documents as newsgroups.
7695 Obeys the standard process/prefix convention."
7696   (interactive "P")
7697   (let* ((articles (gnus-summary-work-articles n))
7698          (ogroup gnus-newsgroup-name)
7699          (params (append (gnus-info-params (gnus-get-info ogroup))
7700                          (list (cons 'to-group ogroup))))
7701          article group egroup groups vgroup)
7702     (while (setq article (pop articles))
7703       (setq group (format "%s-%d" gnus-newsgroup-name article))
7704       (gnus-summary-remove-process-mark article)
7705       (when (gnus-summary-display-article article)
7706         (save-excursion
7707           (with-temp-buffer
7708             (insert-buffer-substring gnus-original-article-buffer)
7709             ;; Remove some headers that may lead nndoc to make
7710             ;; the wrong guess.
7711             (message-narrow-to-head)
7712             (goto-char (point-min))
7713             (delete-matching-lines "^\\(Path\\):\\|^From ")
7714             (widen)
7715             (if (setq egroup
7716                       (gnus-group-read-ephemeral-group
7717                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7718                                      (nndoc-article-type guess))
7719                        t nil t))
7720                 (progn
7721             ;; Make all postings to this group go to the parent group.
7722                   (nconc (gnus-info-params (gnus-get-info egroup))
7723                          params)
7724                   (push egroup groups))
7725               ;; Couldn't select this doc group.
7726               (gnus-error 3 "Article couldn't be entered"))))))
7727     ;; Now we have selected all the documents.
7728     (cond
7729      ((not groups)
7730       (error "None of the articles could be interpreted as documents"))
7731      ((gnus-group-read-ephemeral-group
7732        (setq vgroup (format
7733                      "nnvirtual:%s-%s" gnus-newsgroup-name
7734                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7735        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7736        t
7737        (cons (current-buffer) 'summary)))
7738      (t
7739       (error "Couldn't select virtual nndoc group")))))
7740
7741 (defun gnus-summary-isearch-article (&optional regexp-p)
7742   "Do incremental search forward on the current article.
7743 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7744   (interactive "P")
7745   (gnus-summary-select-article)
7746   (gnus-configure-windows 'article)
7747   (gnus-eval-in-buffer-window gnus-article-buffer
7748     (save-restriction
7749       (widen)
7750       (isearch-forward regexp-p))))
7751
7752 (defun gnus-summary-search-article-forward (regexp &optional backward)
7753   "Search for an article containing REGEXP forward.
7754 If BACKWARD, search backward instead."
7755   (interactive
7756    (list (read-string
7757           (format "Search article %s (regexp%s): "
7758                   (if current-prefix-arg "backward" "forward")
7759                   (if gnus-last-search-regexp
7760                       (concat ", default " gnus-last-search-regexp)
7761                     "")))
7762          current-prefix-arg))
7763   (if (string-equal regexp "")
7764       (setq regexp (or gnus-last-search-regexp ""))
7765     (setq gnus-last-search-regexp regexp)
7766     (setq gnus-article-before-search gnus-current-article))
7767   ;; Intentionally set gnus-last-article.
7768   (setq gnus-last-article gnus-article-before-search)
7769   (let ((gnus-last-article gnus-last-article))
7770     (if (gnus-summary-search-article regexp backward)
7771         (gnus-summary-show-thread)
7772       (error "Search failed: \"%s\"" regexp))))
7773
7774 (defun gnus-summary-search-article-backward (regexp)
7775   "Search for an article containing REGEXP backward."
7776   (interactive
7777    (list (read-string
7778           (format "Search article backward (regexp%s): "
7779                   (if gnus-last-search-regexp
7780                       (concat ", default " gnus-last-search-regexp)
7781                     "")))))
7782   (gnus-summary-search-article-forward regexp 'backward))
7783
7784 (defun gnus-summary-search-article (regexp &optional backward)
7785   "Search for an article containing REGEXP.
7786 Optional argument BACKWARD means do search for backward.
7787 `gnus-select-article-hook' is not called during the search."
7788   ;; We have to require this here to make sure that the following
7789   ;; dynamic binding isn't shadowed by autoloading.
7790   (require 'gnus-async)
7791   (require 'gnus-art)
7792   (let ((gnus-select-article-hook nil)  ;Disable hook.
7793         (gnus-article-prepare-hook nil)
7794         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7795         (gnus-use-article-prefetch nil)
7796         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7797         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7798         (sum (current-buffer))
7799         (gnus-display-mime-function nil)
7800         (found nil)
7801         point)
7802     (gnus-save-hidden-threads
7803       (gnus-summary-select-article)
7804       (set-buffer gnus-article-buffer)
7805       (goto-char (window-point (get-buffer-window (current-buffer))))
7806       (when backward
7807         (forward-line -1))
7808       (while (not found)
7809         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7810         (if (if backward
7811                 (re-search-backward regexp nil t)
7812               (re-search-forward regexp nil t))
7813             ;; We found the regexp.
7814             (progn
7815               (setq found 'found)
7816               (beginning-of-line)
7817               (set-window-start
7818                (get-buffer-window (current-buffer))
7819                (point))
7820               (forward-line 1)
7821               (set-window-point
7822                (get-buffer-window (current-buffer))
7823                (point))
7824               (set-buffer sum)
7825               (setq point (point)))
7826           ;; We didn't find it, so we go to the next article.
7827           (set-buffer sum)
7828           (setq found 'not)
7829           (while (eq found 'not)
7830             (if (not (if backward (gnus-summary-find-prev)
7831                        (gnus-summary-find-next)))
7832                 ;; No more articles.
7833                 (setq found t)
7834               ;; Select the next article and adjust point.
7835               (unless (gnus-summary-article-sparse-p
7836                        (gnus-summary-article-number))
7837                 (setq found nil)
7838                 (gnus-summary-select-article)
7839                 (set-buffer gnus-article-buffer)
7840                 (widen)
7841                 (goto-char (if backward (point-max) (point-min))))))))
7842       (gnus-message 7 ""))
7843     ;; Return whether we found the regexp.
7844     (when (eq found 'found)
7845       (goto-char point)
7846       (gnus-summary-show-thread)
7847       (gnus-summary-goto-subject gnus-current-article)
7848       (gnus-summary-position-point)
7849       t)))
7850
7851 (defun gnus-find-matching-articles (header regexp)
7852   "Return a list of all articles that match REGEXP on HEADER.
7853 This search includes all articles in the current group that Gnus has
7854 fetched headers for, whether they are displayed or not."
7855   (let ((articles nil)
7856         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7857         (case-fold-search t))
7858     (dolist (header gnus-newsgroup-headers)
7859       (when (string-match regexp (funcall func header))
7860         (push (mail-header-number header) articles)))
7861     (nreverse articles)))
7862
7863 (defun gnus-summary-find-matching (header regexp &optional backward unread
7864                                           not-case-fold not-matching)
7865   "Return a list of all articles that match REGEXP on HEADER.
7866 The search stars on the current article and goes forwards unless
7867 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7868 If UNREAD is non-nil, only unread articles will
7869 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7870 in the comparisons. If NOT-MATCHING, return a list of all articles that
7871 not match REGEXP on HEADER."
7872   (let ((case-fold-search (not not-case-fold))
7873         articles d func)
7874     (if (consp header)
7875         (if (eq (car header) 'extra)
7876             (setq func
7877                   `(lambda (h)
7878                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7879                          "")))
7880           (error "%s is an invalid header" header))
7881       (unless (fboundp (intern (concat "mail-header-" header)))
7882         (error "%s is not a valid header" header))
7883       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7884     (dolist (d (if (eq backward 'all)
7885                    gnus-newsgroup-data
7886                  (gnus-data-find-list
7887                   (gnus-summary-article-number)
7888                   (gnus-data-list backward))))
7889       (when (and (or (not unread)       ; We want all articles...
7890                      (gnus-data-unread-p d)) ; Or just unreads.
7891                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7892                  (if not-matching
7893                      (not (string-match
7894                            regexp
7895                            (funcall func (gnus-data-header d))))
7896                    (string-match regexp
7897                                  (funcall func (gnus-data-header d)))))
7898         (push (gnus-data-number d) articles))) ; Success!
7899     (nreverse articles)))
7900
7901 (defun gnus-summary-execute-command (header regexp command &optional backward)
7902   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7903 If HEADER is an empty string (or nil), the match is done on the entire
7904 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7905   (interactive
7906    (list (let ((completion-ignore-case t))
7907            (completing-read
7908             "Header name: "
7909             (mapcar (lambda (header) (list (format "%s" header)))
7910                     (append
7911                      '("Number" "Subject" "From" "Lines" "Date"
7912                        "Message-ID" "Xref" "References" "Body")
7913                      gnus-extra-headers))
7914             nil 'require-match))
7915          (read-string "Regexp: ")
7916          (read-key-sequence "Command: ")
7917          current-prefix-arg))
7918   (when (equal header "Body")
7919     (setq header ""))
7920   ;; Hidden thread subtrees must be searched as well.
7921   (gnus-summary-show-all-threads)
7922   ;; We don't want to change current point nor window configuration.
7923   (save-excursion
7924     (save-window-excursion
7925       (gnus-message 6 "Executing %s..." (key-description command))
7926 ;; We'd like to execute COMMAND interactively so as to give arguments.
7927       (gnus-execute header regexp
7928                     `(call-interactively ',(key-binding command))
7929                     backward)
7930       (gnus-message 6 "Executing %s...done" (key-description command)))))
7931
7932 (defun gnus-summary-beginning-of-article ()
7933   "Scroll the article back to the beginning."
7934   (interactive)
7935   (gnus-summary-select-article)
7936   (gnus-configure-windows 'article)
7937   (gnus-eval-in-buffer-window gnus-article-buffer
7938     (widen)
7939     (goto-char (point-min))
7940     (when gnus-page-broken
7941       (gnus-narrow-to-page))))
7942
7943 (defun gnus-summary-end-of-article ()
7944   "Scroll to the end of the article."
7945   (interactive)
7946   (gnus-summary-select-article)
7947   (gnus-configure-windows 'article)
7948   (gnus-eval-in-buffer-window gnus-article-buffer
7949     (widen)
7950     (goto-char (point-max))
7951     (recenter -3)
7952     (when gnus-page-broken
7953       (gnus-narrow-to-page))))
7954
7955 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7956   "Truncate to LEN and quote all \"(\"'s in STRING."
7957   (gnus-replace-in-string (if (and len (> (length string) len))
7958                               (substring string 0 len)
7959                             string)
7960                           "[()]" "\\\\\\&"))
7961
7962 (defun gnus-summary-print-article (&optional filename n)
7963   "Generate and print a PostScript image of the N next (mail) articles.
7964
7965 If N is negative, print the N previous articles.  If N is nil and articles
7966 have been marked with the process mark, print these instead.
7967
7968 If the optional first argument FILENAME is nil, send the image to the
7969 printer.  If FILENAME is a string, save the PostScript image in a file with
7970 that name.  If FILENAME is a number, prompt the user for the name of the file
7971 to save in."
7972   (interactive (list (ps-print-preprint current-prefix-arg)))
7973   (dolist (article (gnus-summary-work-articles n))
7974     (gnus-summary-select-article nil nil 'pseudo article)
7975     (gnus-eval-in-buffer-window gnus-article-buffer
7976       (gnus-print-buffer))
7977     (gnus-summary-remove-process-mark article))
7978   (ps-despool filename))
7979
7980 (defun gnus-print-buffer ()
7981   (let ((buffer (generate-new-buffer " *print*")))
7982     (unwind-protect
7983         (progn
7984           (copy-to-buffer buffer (point-min) (point-max))
7985           (set-buffer buffer)
7986           (gnus-article-delete-invisible-text)
7987           (when (gnus-visual-p 'article-highlight 'highlight)
7988             ;; Copy-to-buffer doesn't copy overlay.  So redo
7989             ;; highlight.
7990             (let ((gnus-article-buffer buffer))
7991               (gnus-article-highlight-citation t)
7992               (gnus-article-highlight-signature)))
7993           (let ((ps-left-header
7994                  (list
7995                   (concat "("
7996                           (gnus-summary-print-truncate-and-quote
7997                            (mail-header-subject gnus-current-headers)
7998                            66) ")")
7999                   (concat "("
8000                           (gnus-summary-print-truncate-and-quote
8001                            (mail-header-from gnus-current-headers)
8002                            45) ")")))
8003                 (ps-right-header
8004                  (list
8005                   "/pagenumberstring load"
8006                   (concat "("
8007                           (mail-header-date gnus-current-headers) ")"))))
8008             (gnus-run-hooks 'gnus-ps-print-hook)
8009             (save-excursion
8010               (if window-system
8011                   (ps-spool-buffer-with-faces)
8012                 (ps-spool-buffer)))))
8013       (kill-buffer buffer))))
8014
8015 (defun gnus-summary-show-article (&optional arg)
8016   "Force redisplaying of the current article.
8017 If ARG (the prefix) is a number, show the article with the charset
8018 defined in `gnus-summary-show-article-charset-alist', or the charset
8019 input.
8020 If ARG (the prefix) is non-nil and not a number, show the raw article
8021 without any article massaging functions being run.  Normally, the key strokes 
8022 are `C-u g'."
8023   (interactive "P")
8024   (cond
8025    ((numberp arg)
8026     (gnus-summary-show-article t)
8027     (let ((gnus-newsgroup-charset
8028            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8029                (mm-read-coding-system
8030                 "View as charset: " ;; actually it is coding system.
8031                 (save-excursion
8032                   (set-buffer gnus-article-buffer)
8033                   (mm-detect-coding-region (point) (point-max))))))
8034           (gnus-newsgroup-ignored-charsets 'gnus-all))
8035       (gnus-summary-select-article nil 'force)
8036       (let ((deps gnus-newsgroup-dependencies)
8037             head header lines)
8038         (save-excursion
8039           (set-buffer gnus-original-article-buffer)
8040           (save-restriction
8041             (message-narrow-to-head)
8042             (setq head (buffer-string))
8043             (goto-char (point-min))
8044             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8045               (goto-char (point-max))
8046               (widen)
8047               (setq lines (1- (count-lines (point) (point-max))))))
8048           (with-temp-buffer
8049             (insert (format "211 %d Article retrieved.\n"
8050                             (cdr gnus-article-current)))
8051             (insert head)
8052             (if lines (insert (format "Lines: %d\n" lines)))
8053             (insert ".\n")
8054             (let ((nntp-server-buffer (current-buffer)))
8055               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8056         (gnus-data-set-header
8057          (gnus-data-find (cdr gnus-article-current))
8058          header)
8059         (gnus-summary-update-article-line
8060          (cdr gnus-article-current) header)
8061         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8062           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8063    ((not arg)
8064     ;; Select the article the normal way.
8065     (gnus-summary-select-article nil 'force))
8066    (t
8067     ;; We have to require this here to make sure that the following
8068     ;; dynamic binding isn't shadowed by autoloading.
8069     (require 'gnus-async)
8070     (require 'gnus-art)
8071     ;; Bind the article treatment functions to nil.
8072     (let ((gnus-have-all-headers t)
8073           gnus-article-prepare-hook
8074           gnus-article-decode-hook
8075           gnus-display-mime-function
8076           gnus-break-pages)
8077       ;; Destroy any MIME parts.
8078       (when (gnus-buffer-live-p gnus-article-buffer)
8079         (save-excursion
8080           (set-buffer gnus-article-buffer)
8081           (mm-destroy-parts gnus-article-mime-handles)
8082           ;; Set it to nil for safety reason.
8083           (setq gnus-article-mime-handle-alist nil)
8084           (setq gnus-article-mime-handles nil)))
8085       (gnus-summary-select-article nil 'force))))
8086   (gnus-summary-goto-subject gnus-current-article)
8087   (gnus-summary-position-point))
8088
8089 (defun gnus-summary-show-raw-article ()
8090   "Show the raw article without any article massaging functions being run."
8091   (interactive)
8092   (gnus-summary-show-article t))
8093
8094 (defun gnus-summary-verbose-headers (&optional arg)
8095   "Toggle permanent full header display.
8096 If ARG is a positive number, turn header display on.
8097 If ARG is a negative number, turn header display off."
8098   (interactive "P")
8099   (setq gnus-show-all-headers
8100         (cond ((or (not (numberp arg))
8101                    (zerop arg))
8102                (not gnus-show-all-headers))
8103               ((natnump arg)
8104                t)))
8105   (gnus-summary-show-article))
8106
8107 (defun gnus-summary-toggle-header (&optional arg)
8108   "Show the headers if they are hidden, or hide them if they are shown.
8109 If ARG is a positive number, show the entire header.
8110 If ARG is a negative number, hide the unwanted header lines."
8111   (interactive "P")
8112   (save-excursion
8113     (set-buffer gnus-article-buffer)
8114     (save-restriction
8115       (let* ((buffer-read-only nil)
8116              (inhibit-point-motion-hooks t)
8117              hidden e)
8118         (setq hidden
8119               (if (numberp arg)
8120                   (>= arg 0)
8121                 (save-restriction
8122                   (article-narrow-to-head)
8123                   (gnus-article-hidden-text-p 'headers))))
8124         (goto-char (point-min))
8125         (when (search-forward "\n\n" nil t)
8126           (delete-region (point-min) (1- (point))))
8127         (goto-char (point-min))
8128         (save-excursion
8129           (set-buffer gnus-original-article-buffer)
8130           (goto-char (point-min))
8131           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8132         (insert-buffer-substring gnus-original-article-buffer 1 e)
8133         (save-restriction
8134           (narrow-to-region (point-min) (point))
8135           (article-decode-encoded-words)
8136           (if  hidden
8137               (let ((gnus-treat-hide-headers nil)
8138                     (gnus-treat-hide-boring-headers nil))
8139                 (gnus-delete-wash-type 'headers)
8140                 (gnus-treat-article 'head))
8141             (gnus-treat-article 'head)))
8142         (gnus-set-mode-line 'article)))))
8143
8144 (defun gnus-summary-show-all-headers ()
8145   "Make all header lines visible."
8146   (interactive)
8147   (gnus-summary-toggle-header 1))
8148
8149 (defun gnus-summary-caesar-message (&optional arg)
8150   "Caesar rotate the current article by 13.
8151 The numerical prefix specifies how many places to rotate each letter
8152 forward."
8153   (interactive "P")
8154   (gnus-summary-select-article)
8155   (let ((mail-header-separator ""))
8156     (gnus-eval-in-buffer-window gnus-article-buffer
8157       (save-restriction
8158         (widen)
8159         (let ((start (window-start))
8160               buffer-read-only)
8161           (message-caesar-buffer-body arg)
8162           (set-window-start (get-buffer-window (current-buffer)) start))))))
8163
8164 (defun gnus-summary-stop-page-breaking ()
8165   "Stop page breaking in the current article."
8166   (interactive)
8167   (gnus-summary-select-article)
8168   (gnus-eval-in-buffer-window gnus-article-buffer
8169     (widen)
8170     (when (gnus-visual-p 'page-marker)
8171       (let ((buffer-read-only nil))
8172         (gnus-remove-text-with-property 'gnus-prev)
8173         (gnus-remove-text-with-property 'gnus-next))
8174       (setq gnus-page-broken nil))))
8175
8176 (defun gnus-summary-move-article (&optional n to-newsgroup
8177                                             select-method action)
8178   "Move the current article to a different newsgroup.
8179 If N is a positive number, move the N next articles.
8180 If N is a negative number, move the N previous articles.
8181 If N is nil and any articles have been marked with the process mark,
8182 move those articles instead.
8183 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8184 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8185 re-spool using this method.
8186
8187 For this function to work, both the current newsgroup and the
8188 newsgroup that you want to move to have to support the `request-move'
8189 and `request-accept' functions.
8190
8191 ACTION can be either `move' (the default), `crosspost' or `copy'."
8192   (interactive "P")
8193   (unless action
8194     (setq action 'move))
8195   ;; Check whether the source group supports the required functions.
8196   (cond ((and (eq action 'move)
8197               (not (gnus-check-backend-function
8198                     'request-move-article gnus-newsgroup-name)))
8199          (error "The current group does not support article moving"))
8200         ((and (eq action 'crosspost)
8201               (not (gnus-check-backend-function
8202                     'request-replace-article gnus-newsgroup-name)))
8203          (error "The current group does not support article editing")))
8204   (let ((articles (gnus-summary-work-articles n))
8205         (prefix (if (gnus-check-backend-function
8206                      'request-move-article gnus-newsgroup-name)
8207                     (gnus-group-real-prefix gnus-newsgroup-name)
8208                   ""))
8209         (names '((move "Move" "Moving")
8210                  (copy "Copy" "Copying")
8211                  (crosspost "Crosspost" "Crossposting")))
8212         (copy-buf (save-excursion
8213                     (nnheader-set-temp-buffer " *copy article*")))
8214         art-group to-method new-xref article to-groups)
8215     (unless (assq action names)
8216       (error "Unknown action %s" action))
8217     ;; We have to select an article to give
8218     ;; `gnus-read-move-group-name' an opportunity to suggest an
8219     ;; appropriate default.
8220     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8221       (let ((gnus-display-mime-function nil)
8222             (gnus-article-prepare-hook nil))
8223         (gnus-summary-select-article nil nil nil (car articles))))
8224     ;; Read the newsgroup name.
8225     (when (and (not to-newsgroup)
8226                (not select-method))
8227       (setq to-newsgroup
8228             (gnus-read-move-group-name
8229              (cadr (assq action names))
8230              (symbol-value (intern (format "gnus-current-%s-group" action)))
8231              articles prefix))
8232       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8233     (setq to-method (or select-method
8234                         (gnus-server-to-method
8235                          (gnus-group-method to-newsgroup))))
8236     ;; Check the method we are to move this article to...
8237     (unless (gnus-check-backend-function
8238              'request-accept-article (car to-method))
8239       (error "%s does not support article copying" (car to-method)))
8240     (unless (gnus-check-server to-method)
8241       (error "Can't open server %s" (car to-method)))
8242     (gnus-message 6 "%s to %s: %s..."
8243                   (caddr (assq action names))
8244                   (or (car select-method) to-newsgroup) articles)
8245     (while articles
8246       (setq article (pop articles))
8247       (setq
8248        art-group
8249        (cond
8250         ;; Move the article.
8251         ((eq action 'move)
8252          ;; Remove this article from future suppression.
8253          (gnus-dup-unsuppress-article article)
8254          (gnus-request-move-article
8255           article                       ; Article to move
8256           gnus-newsgroup-name           ; From newsgroup
8257           (nth 1 (gnus-find-method-for-group
8258                   gnus-newsgroup-name)) ; Server
8259           (list 'gnus-request-accept-article
8260                 to-newsgroup (list 'quote select-method)
8261                 (not articles) t)       ; Accept form
8262           (not articles)))              ; Only save nov last time
8263         ;; Copy the article.
8264         ((eq action 'copy)
8265          (save-excursion
8266            (set-buffer copy-buf)
8267            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8268              (gnus-request-accept-article
8269               to-newsgroup select-method (not articles) t))))
8270         ;; Crosspost the article.
8271         ((eq action 'crosspost)
8272          (let ((xref (message-tokenize-header
8273                       (mail-header-xref (gnus-summary-article-header article))
8274                       " ")))
8275            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8276                                   ":" (number-to-string article)))
8277            (unless xref
8278              (setq xref (list (system-name))))
8279            (setq new-xref
8280                  (concat
8281                   (mapconcat 'identity
8282                              (delete "Xref:" (delete new-xref xref))
8283                              " ")
8284                   " " new-xref))
8285            (save-excursion
8286              (set-buffer copy-buf)
8287              ;; First put the article in the destination group.
8288              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8289              (when (consp (setq art-group
8290                                 (gnus-request-accept-article
8291                                  to-newsgroup select-method (not articles))))
8292                (setq new-xref (concat new-xref " " (car art-group)
8293                                       ":"
8294                                       (number-to-string (cdr art-group))))
8295                ;; Now we have the new Xrefs header, so we insert
8296                ;; it and replace the new article.
8297                (nnheader-replace-header "Xref" new-xref)
8298                (gnus-request-replace-article
8299                 (cdr art-group) to-newsgroup (current-buffer))
8300                art-group))))))
8301       (cond
8302        ((not art-group)
8303         (gnus-message 1 "Couldn't %s article %s: %s"
8304                       (cadr (assq action names)) article
8305                       (nnheader-get-report (car to-method))))
8306        ((eq art-group 'junk)
8307         (when (eq action 'move)
8308           (gnus-summary-mark-article article gnus-canceled-mark)
8309           (gnus-message 4 "Deleted article %s" article)))
8310        (t
8311         (let* ((pto-group (gnus-group-prefixed-name
8312                            (car art-group) to-method))
8313                (entry
8314                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8315                (info (nth 2 entry))
8316                (to-group (gnus-info-group info))
8317                to-marks)
8318           ;; Update the group that has been moved to.
8319           (when (and info
8320                      (memq action '(move copy)))
8321             (unless (member to-group to-groups)
8322               (push to-group to-groups))
8323
8324             (unless (memq article gnus-newsgroup-unreads)
8325               (push 'read to-marks)
8326               (gnus-info-set-read
8327                info (gnus-add-to-range (gnus-info-read info)
8328                                        (list (cdr art-group)))))
8329
8330             ;; See whether the article is to be put in the cache.
8331             (let ((marks gnus-article-mark-lists)
8332                   (to-article (cdr art-group)))
8333
8334               ;; Enter the article into the cache in the new group,
8335               ;; if that is required.
8336               (when gnus-use-cache
8337                 (gnus-cache-possibly-enter-article
8338                  to-group to-article
8339                  (memq article gnus-newsgroup-marked)
8340                  (memq article gnus-newsgroup-dormant)
8341                  (memq article gnus-newsgroup-unreads)))
8342
8343               (when gnus-preserve-marks
8344                 ;; Copy any marks over to the new group.
8345                 (when (and (equal to-group gnus-newsgroup-name)
8346                            (not (memq article gnus-newsgroup-unreads)))
8347                   ;; Mark this article as read in this group.
8348                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8349                   (setcdr (gnus-active to-group) to-article)
8350                   (setcdr gnus-newsgroup-active to-article))
8351
8352                 (while marks
8353                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8354                     (when (memq article (symbol-value
8355                                          (intern (format "gnus-newsgroup-%s"
8356                                                          (caar marks)))))
8357                       (push (cdar marks) to-marks)
8358                       ;; If the other group is the same as this group,
8359                       ;; then we have to add the mark to the list.
8360                       (when (equal to-group gnus-newsgroup-name)
8361                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8362                              (cons to-article
8363                                    (symbol-value
8364                                     (intern (format "gnus-newsgroup-%s"
8365                                                     (caar marks)))))))
8366                       ;; Copy the marks to other group.
8367                       (gnus-add-marked-articles
8368                        to-group (cdar marks) (list to-article) info)))
8369                   (setq marks (cdr marks)))
8370
8371                 (gnus-request-set-mark to-group (list (list (list to-article)
8372                                                             'add
8373                                                             to-marks))))
8374
8375               (gnus-dribble-enter
8376                (concat "(gnus-group-set-info '"
8377                        (gnus-prin1-to-string (gnus-get-info to-group))
8378                        ")"))))
8379
8380           ;; Update the Xref header in this article to point to
8381           ;; the new crossposted article we have just created.
8382           (when (eq action 'crosspost)
8383             (save-excursion
8384               (set-buffer copy-buf)
8385               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8386               (nnheader-replace-header "Xref" new-xref)
8387               (gnus-request-replace-article
8388                article gnus-newsgroup-name (current-buffer)))))
8389
8390         ;;;!!!Why is this necessary?
8391         (set-buffer gnus-summary-buffer)
8392
8393         (gnus-summary-goto-subject article)
8394         (when (eq action 'move)
8395           (gnus-summary-mark-article article gnus-canceled-mark))))
8396       (gnus-summary-remove-process-mark article))
8397     ;; Re-activate all groups that have been moved to.
8398     (save-excursion
8399       (set-buffer gnus-group-buffer)
8400       (let ((gnus-group-marked to-groups))
8401         (gnus-group-get-new-news-this-group nil t)))
8402
8403     (gnus-kill-buffer copy-buf)
8404     (gnus-summary-position-point)
8405     (gnus-set-mode-line 'summary)))
8406
8407 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8408   "Move the current article to a different newsgroup.
8409 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8410 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8411 re-spool using this method."
8412   (interactive "P")
8413   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8414
8415 (defun gnus-summary-crosspost-article (&optional n)
8416   "Crosspost the current article to some other group."
8417   (interactive "P")
8418   (gnus-summary-move-article n nil nil 'crosspost))
8419
8420 (defcustom gnus-summary-respool-default-method nil
8421   "Default method type for respooling an article.
8422 If nil, use to the current newsgroup method."
8423   :type 'symbol
8424   :group 'gnus-summary-mail)
8425
8426 (defun gnus-summary-respool-article (&optional n method)
8427   "Respool the current article.
8428 The article will be squeezed through the mail spooling process again,
8429 which means that it will be put in some mail newsgroup or other
8430 depending on `nnmail-split-methods'.
8431 If N is a positive number, respool the N next articles.
8432 If N is a negative number, respool the N previous articles.
8433 If N is nil and any articles have been marked with the process mark,
8434 respool those articles instead.
8435
8436 Respooling can be done both from mail groups and \"real\" newsgroups.
8437 In the former case, the articles in question will be moved from the
8438 current group into whatever groups they are destined to.  In the
8439 latter case, they will be copied into the relevant groups."
8440   (interactive
8441    (list current-prefix-arg
8442          (let* ((methods (gnus-methods-using 'respool))
8443                 (methname
8444                  (symbol-name (or gnus-summary-respool-default-method
8445                                   (car (gnus-find-method-for-group
8446                                         gnus-newsgroup-name)))))
8447                 (method
8448                  (gnus-completing-read
8449                   methname "What backend do you want to use when respooling?"
8450                   methods nil t nil 'gnus-mail-method-history))
8451                 ms)
8452            (cond
8453             ((zerop (length (setq ms (gnus-servers-using-backend
8454                                       (intern method)))))
8455              (list (intern method) ""))
8456             ((= 1 (length ms))
8457              (car ms))
8458             (t
8459              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8460                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8461                            ms-alist))))))))
8462   (unless method
8463     (error "No method given for respooling"))
8464   (if (assoc (symbol-name
8465               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8466              (gnus-methods-using 'respool))
8467       (gnus-summary-move-article n nil method)
8468     (gnus-summary-copy-article n nil method)))
8469
8470 (defun gnus-summary-import-article (file &optional edit)
8471   "Import an arbitrary file into a mail newsgroup."
8472   (interactive "fImport file: \nP")
8473   (let ((group gnus-newsgroup-name)
8474         (now (current-time))
8475         atts lines group-art)
8476     (unless (gnus-check-backend-function 'request-accept-article group)
8477       (error "%s does not support article importing" group))
8478     (or (file-readable-p file)
8479         (not (file-regular-p file))
8480         (error "Can't read %s" file))
8481     (save-excursion
8482       (set-buffer (gnus-get-buffer-create " *import file*"))
8483       (erase-buffer)
8484       (nnheader-insert-file-contents file)
8485       (goto-char (point-min))
8486       (if (nnheader-article-p)
8487           (save-restriction
8488             (goto-char (point-min))
8489             (search-forward "\n\n" nil t)
8490             (narrow-to-region (point-min) (1- (point)))
8491             (goto-char (point-min))
8492             (unless (re-search-forward "^date:" nil t)
8493               (goto-char (point-max))
8494               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8495        ;; This doesn't look like an article, so we fudge some headers.
8496         (setq atts (file-attributes file)
8497               lines (count-lines (point-min) (point-max)))
8498         (insert "From: " (read-string "From: ") "\n"
8499                 "Subject: " (read-string "Subject: ") "\n"
8500                 "Date: " (message-make-date (nth 5 atts)) "\n"
8501                 "Message-ID: " (message-make-message-id) "\n"
8502                 "Lines: " (int-to-string lines) "\n"
8503                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8504       (setq group-art (gnus-request-accept-article group nil t))
8505       (kill-buffer (current-buffer)))
8506     (setq gnus-newsgroup-active (gnus-activate-group group))
8507     (forward-line 1)
8508     (gnus-summary-goto-article (cdr group-art) nil t)
8509     (when edit
8510       (gnus-summary-edit-article))))
8511
8512 (defun gnus-summary-create-article ()
8513   "Create an article in a mail newsgroup."
8514   (interactive)
8515   (let ((group gnus-newsgroup-name)
8516         (now (current-time))
8517         group-art)
8518     (unless (gnus-check-backend-function 'request-accept-article group)
8519       (error "%s does not support article importing" group))
8520     (save-excursion
8521       (set-buffer (gnus-get-buffer-create " *import file*"))
8522       (erase-buffer)
8523       (goto-char (point-min))
8524       ;; This doesn't look like an article, so we fudge some headers.
8525       (insert "From: " (read-string "From: ") "\n"
8526               "Subject: " (read-string "Subject: ") "\n"
8527               "Date: " (message-make-date now) "\n"
8528               "Message-ID: " (message-make-message-id) "\n")
8529       (setq group-art (gnus-request-accept-article group nil t))
8530       (kill-buffer (current-buffer)))
8531     (setq gnus-newsgroup-active (gnus-activate-group group))
8532     (forward-line 1)
8533     (gnus-summary-goto-article (cdr group-art) nil t)
8534     (gnus-summary-edit-article)))
8535
8536 (defun gnus-summary-article-posted-p ()
8537   "Say whether the current (mail) article is available from news as well.
8538 This will be the case if the article has both been mailed and posted."
8539   (interactive)
8540   (let ((id (mail-header-references (gnus-summary-article-header)))
8541         (gnus-override-method (car (gnus-refer-article-methods))))
8542     (if (gnus-request-head id "")
8543         (gnus-message 2 "The current message was found on %s"
8544                       gnus-override-method)
8545       (gnus-message 2 "The current message couldn't be found on %s"
8546                     gnus-override-method)
8547       nil)))
8548
8549 (defun gnus-summary-expire-articles (&optional now)
8550   "Expire all articles that are marked as expirable in the current group."
8551   (interactive)
8552   (when (gnus-check-backend-function
8553          'request-expire-articles gnus-newsgroup-name)
8554     ;; This backend supports expiry.
8555     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8556            (expirable (if total
8557                           (progn
8558                             ;; We need to update the info for
8559                             ;; this group for `gnus-list-of-read-articles'
8560                             ;; to give us the right answer.
8561                             (gnus-run-hooks 'gnus-exit-group-hook)
8562                             (gnus-summary-update-info)
8563                             (gnus-list-of-read-articles gnus-newsgroup-name))
8564                         (setq gnus-newsgroup-expirable
8565                               (sort gnus-newsgroup-expirable '<))))
8566            (expiry-wait (if now 'immediate
8567                           (gnus-group-find-parameter
8568                            gnus-newsgroup-name 'expiry-wait)))
8569            (nnmail-expiry-target
8570             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8571                 nnmail-expiry-target))
8572            es)
8573       (when expirable
8574         ;; There are expirable articles in this group, so we run them
8575         ;; through the expiry process.
8576         (gnus-message 6 "Expiring articles...")
8577         (unless (gnus-check-group gnus-newsgroup-name)
8578           (error "Can't open server for %s" gnus-newsgroup-name))
8579         ;; The list of articles that weren't expired is returned.
8580         (save-excursion
8581           (if expiry-wait
8582               (let ((nnmail-expiry-wait-function nil)
8583                     (nnmail-expiry-wait expiry-wait))
8584                 (setq es (gnus-request-expire-articles
8585                           expirable gnus-newsgroup-name)))
8586             (setq es (gnus-request-expire-articles
8587                       expirable gnus-newsgroup-name)))
8588           (unless total
8589             (setq gnus-newsgroup-expirable es))
8590           ;; We go through the old list of expirable, and mark all
8591           ;; really expired articles as nonexistent.
8592           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8593             (let ((gnus-use-cache nil))
8594               (while expirable
8595                 (unless (memq (car expirable) es)
8596                   (when (gnus-data-find (car expirable))
8597                     (gnus-summary-mark-article
8598                      (car expirable) gnus-canceled-mark)))
8599                 (setq expirable (cdr expirable))))))
8600         (gnus-message 6 "Expiring articles...done")))))
8601
8602 (defun gnus-summary-expire-articles-now ()
8603   "Expunge all expirable articles in the current group.
8604 This means that *all* articles that are marked as expirable will be
8605 deleted forever, right now."
8606   (interactive)
8607   (or gnus-expert-user
8608       (gnus-yes-or-no-p
8609        "Are you really, really, really sure you want to delete all these messages? ")
8610       (error "Phew!"))
8611   (gnus-summary-expire-articles t))
8612
8613 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8614 (defun gnus-summary-delete-article (&optional n)
8615   "Delete the N next (mail) articles.
8616 This command actually deletes articles.  This is not a marking
8617 command.  The article will disappear forever from your life, never to
8618 return.
8619 If N is negative, delete backwards.
8620 If N is nil and articles have been marked with the process mark,
8621 delete these instead."
8622   (interactive "P")
8623   (unless (gnus-check-backend-function 'request-expire-articles
8624                                        gnus-newsgroup-name)
8625     (error "The current newsgroup does not support article deletion"))
8626   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8627     (error "Couldn't open server"))
8628   ;; Compute the list of articles to delete.
8629   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8630         not-deleted)
8631     (if (and gnus-novice-user
8632              (not (gnus-yes-or-no-p
8633                    (format "Do you really want to delete %s forever? "
8634                            (if (> (length articles) 1)
8635                                (format "these %s articles" (length articles))
8636                              "this article")))))
8637         ()
8638       ;; Delete the articles.
8639       (setq not-deleted (gnus-request-expire-articles
8640                          articles gnus-newsgroup-name 'force))
8641       (while articles
8642         (gnus-summary-remove-process-mark (car articles))
8643         ;; The backend might not have been able to delete the article
8644         ;; after all.
8645         (unless (memq (car articles) not-deleted)
8646           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8647         (setq articles (cdr articles)))
8648       (when not-deleted
8649         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8650     (gnus-summary-position-point)
8651     (gnus-set-mode-line 'summary)
8652     not-deleted))
8653
8654 (defun gnus-summary-edit-article (&optional arg)
8655   "Edit the current article.
8656 This will have permanent effect only in mail groups.
8657 If ARG is nil, edit the decoded articles.
8658 If ARG is 1, edit the raw articles.
8659 If ARG is 2, edit the raw articles even in read-only groups.
8660 If ARG is 3, edit the articles with the current handles.
8661 Otherwise, allow editing of articles even in read-only
8662 groups."
8663   (interactive "P")
8664   (let (force raw current-handles)
8665     (cond
8666      ((null arg))
8667      ((eq arg 1)
8668       (setq raw t))
8669      ((eq arg 2)
8670       (setq raw t
8671             force t))
8672      ((eq arg 3)
8673       (setq current-handles
8674             (and (gnus-buffer-live-p gnus-article-buffer)
8675                  (with-current-buffer gnus-article-buffer
8676                    (prog1
8677                        gnus-article-mime-handles
8678                      (setq gnus-article-mime-handles nil))))))
8679      (t
8680       (setq force t)))
8681     (when (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8682       (error "Can't edit the raw article in group nndraft:drafts"))
8683     (save-excursion
8684       (set-buffer gnus-summary-buffer)
8685       (let ((mail-parse-charset gnus-newsgroup-charset)
8686             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8687         (gnus-set-global-variables)
8688         (when (and (not force)
8689                    (gnus-group-read-only-p))
8690           (error "The current newsgroup does not support article editing"))
8691         (gnus-summary-show-article t)
8692         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8693           (with-current-buffer gnus-article-buffer
8694             (mm-enable-multibyte)))
8695         (if (equal gnus-newsgroup-name "nndraft:drafts")
8696             (setq raw t))
8697         (gnus-article-edit-article
8698          (if raw 'ignore
8699            `(lambda ()
8700               (let ((mbl mml-buffer-list))
8701                 (setq mml-buffer-list nil)
8702                 (mime-to-mml ,'current-handles)
8703                 (let ((mbl1 mml-buffer-list))
8704                   (setq mml-buffer-list mbl)
8705                   (set (make-local-variable 'mml-buffer-list) mbl1))
8706                 (make-local-hook 'kill-buffer-hook)
8707                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8708          `(lambda (no-highlight)
8709             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8710                   (message-options message-options)
8711                   (message-options-set-recipient)
8712                   (mail-parse-ignored-charsets
8713                    ',gnus-newsgroup-ignored-charsets))
8714               ,(if (not raw) '(progn
8715                                 (mml-to-mime)
8716                                 (mml-destroy-buffers)
8717                                 (remove-hook 'kill-buffer-hook
8718                                              'mml-destroy-buffers t)
8719                                 (kill-local-variable 'mml-buffer-list)))
8720               (gnus-summary-edit-article-done
8721                ,(or (mail-header-references gnus-current-headers) "")
8722                ,(gnus-group-read-only-p)
8723                ,gnus-summary-buffer no-highlight))))))))
8724
8725 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8726
8727 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8728                                                  no-highlight)
8729   "Make edits to the current article permanent."
8730   (interactive)
8731   (save-excursion
8732    ;; The buffer restriction contains the entire article if it exists.
8733     (when (article-goto-body)
8734       (let ((lines (count-lines (point) (point-max)))
8735             (length (- (point-max) (point)))
8736             (case-fold-search t)
8737             (body (copy-marker (point))))
8738         (goto-char (point-min))
8739         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8740           (delete-region (match-beginning 1) (match-end 1))
8741           (insert (number-to-string length)))
8742         (goto-char (point-min))
8743         (when (re-search-forward
8744                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8745           (delete-region (match-beginning 1) (match-end 1))
8746           (insert (number-to-string length)))
8747         (goto-char (point-min))
8748         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8749           (delete-region (match-beginning 1) (match-end 1))
8750           (insert (number-to-string lines))))))
8751   ;; Replace the article.
8752   (let ((buf (current-buffer)))
8753     (with-temp-buffer
8754       (insert-buffer-substring buf)
8755
8756       (if (and (not read-only)
8757                (not (gnus-request-replace-article
8758                      (cdr gnus-article-current) (car gnus-article-current)
8759                      (current-buffer) t)))
8760           (error "Couldn't replace article")
8761         ;; Update the summary buffer.
8762         (if (and references
8763                  (equal (message-tokenize-header references " ")
8764                         (message-tokenize-header
8765                          (or (message-fetch-field "references") "") " ")))
8766             ;; We only have to update this line.
8767             (save-excursion
8768               (save-restriction
8769                 (message-narrow-to-head)
8770                 (let ((head (buffer-string))
8771                       header)
8772                   (with-temp-buffer
8773                     (insert (format "211 %d Article retrieved.\n"
8774                                     (cdr gnus-article-current)))
8775                     (insert head)
8776                     (insert ".\n")
8777                     (let ((nntp-server-buffer (current-buffer)))
8778                       (setq header (car (gnus-get-newsgroup-headers
8779                                          (save-excursion
8780                                            (set-buffer gnus-summary-buffer)
8781                                            gnus-newsgroup-dependencies)
8782                                          t))))
8783                     (save-excursion
8784                       (set-buffer gnus-summary-buffer)
8785                       (gnus-data-set-header
8786                        (gnus-data-find (cdr gnus-article-current))
8787                        header)
8788                       (gnus-summary-update-article-line
8789                        (cdr gnus-article-current) header)
8790                       (if (gnus-summary-goto-subject
8791                            (cdr gnus-article-current) nil t)
8792                           (gnus-summary-update-secondary-mark
8793                            (cdr gnus-article-current))))))))
8794           ;; Update threads.
8795           (set-buffer (or buffer gnus-summary-buffer))
8796           (gnus-summary-update-article (cdr gnus-article-current))
8797           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8798               (gnus-summary-update-secondary-mark
8799                (cdr gnus-article-current))))
8800         ;; Prettify the article buffer again.
8801         (unless no-highlight
8802           (save-excursion
8803             (set-buffer gnus-article-buffer)
8804             ;;;!!! Fix this -- article should be rehighlighted.
8805             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8806             (set-buffer gnus-original-article-buffer)
8807             (gnus-request-article
8808              (cdr gnus-article-current)
8809              (car gnus-article-current) (current-buffer))))
8810         ;; Prettify the summary buffer line.
8811         (when (gnus-visual-p 'summary-highlight 'highlight)
8812           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8813
8814 (defun gnus-summary-edit-wash (key)
8815   "Perform editing command KEY in the article buffer."
8816   (interactive
8817    (list
8818     (progn
8819       (message "%s" (concat (this-command-keys) "- "))
8820       (read-char))))
8821   (message "")
8822   (gnus-summary-edit-article)
8823   (execute-kbd-macro (concat (this-command-keys) key))
8824   (gnus-article-edit-done))
8825
8826 ;;; Respooling
8827
8828 (defun gnus-summary-respool-query (&optional silent trace)
8829   "Query where the respool algorithm would put this article."
8830   (interactive)
8831   (let (gnus-mark-article-hook)
8832     (gnus-summary-select-article)
8833     (save-excursion
8834       (set-buffer gnus-original-article-buffer)
8835       (save-restriction
8836         (message-narrow-to-head)
8837         (let ((groups (nnmail-article-group 'identity trace)))
8838           (unless silent
8839             (if groups
8840                 (message "This message would go to %s"
8841                          (mapconcat 'car groups ", "))
8842               (message "This message would go to no groups"))
8843             groups))))))
8844
8845 (defun gnus-summary-respool-trace ()
8846   "Trace where the respool algorithm would put this article.
8847 Display a buffer showing all fancy splitting patterns which matched."
8848   (interactive)
8849   (gnus-summary-respool-query nil t))
8850
8851 ;; Summary marking commands.
8852
8853 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8854   "Mark articles which has the same subject as read, and then select the next.
8855 If UNMARK is positive, remove any kind of mark.
8856 If UNMARK is negative, tick articles."
8857   (interactive "P")
8858   (when unmark
8859     (setq unmark (prefix-numeric-value unmark)))
8860   (let ((count
8861          (gnus-summary-mark-same-subject
8862           (gnus-summary-article-subject) unmark)))
8863     ;; Select next unread article.  If auto-select-same mode, should
8864     ;; select the first unread article.
8865     (gnus-summary-next-article t (and gnus-auto-select-same
8866                                       (gnus-summary-article-subject)))
8867     (gnus-message 7 "%d article%s marked as %s"
8868                   count (if (= count 1) " is" "s are")
8869                   (if unmark "unread" "read"))))
8870
8871 (defun gnus-summary-kill-same-subject (&optional unmark)
8872   "Mark articles which has the same subject as read.
8873 If UNMARK is positive, remove any kind of mark.
8874 If UNMARK is negative, tick articles."
8875   (interactive "P")
8876   (when unmark
8877     (setq unmark (prefix-numeric-value unmark)))
8878   (let ((count
8879          (gnus-summary-mark-same-subject
8880           (gnus-summary-article-subject) unmark)))
8881     ;; If marked as read, go to next unread subject.
8882     (when (null unmark)
8883       ;; Go to next unread subject.
8884       (gnus-summary-next-subject 1 t))
8885     (gnus-message 7 "%d articles are marked as %s"
8886                   count (if unmark "unread" "read"))))
8887
8888 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8889   "Mark articles with same SUBJECT as read, and return marked number.
8890 If optional argument UNMARK is positive, remove any kinds of marks.
8891 If optional argument UNMARK is negative, mark articles as unread instead."
8892   (let ((count 1))
8893     (save-excursion
8894       (cond
8895        ((null unmark)                   ; Mark as read.
8896         (while (and
8897                 (progn
8898                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8899                   (gnus-summary-show-thread) t)
8900                 (gnus-summary-find-subject subject))
8901           (setq count (1+ count))))
8902        ((> unmark 0)                    ; Tick.
8903         (while (and
8904                 (progn
8905                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8906                   (gnus-summary-show-thread) t)
8907                 (gnus-summary-find-subject subject))
8908           (setq count (1+ count))))
8909        (t                               ; Mark as unread.
8910         (while (and
8911                 (progn
8912                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8913                   (gnus-summary-show-thread) t)
8914                 (gnus-summary-find-subject subject))
8915           (setq count (1+ count)))))
8916       (gnus-set-mode-line 'summary)
8917       ;; Return the number of marked articles.
8918       count)))
8919
8920 (defun gnus-summary-mark-as-processable (n &optional unmark)
8921   "Set the process mark on the next N articles.
8922 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8923 the process mark instead.  The difference between N and the actual
8924 number of articles marked is returned."
8925   (interactive "P")
8926   (if (and (null n) (gnus-region-active-p))
8927       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8928     (setq n (prefix-numeric-value n))
8929     (let ((backward (< n 0))
8930           (n (abs n)))
8931       (while (and
8932               (> n 0)
8933               (if unmark
8934                   (gnus-summary-remove-process-mark
8935                    (gnus-summary-article-number))
8936                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8937               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8938         (setq n (1- n)))
8939       (when (/= 0 n)
8940         (gnus-message 7 "No more articles"))
8941       (gnus-summary-recenter)
8942       (gnus-summary-position-point)
8943       n)))
8944
8945 (defun gnus-summary-unmark-as-processable (n)
8946   "Remove the process mark from the next N articles.
8947 If N is negative, unmark backward instead.  The difference between N and
8948 the actual number of articles unmarked is returned."
8949   (interactive "P")
8950   (gnus-summary-mark-as-processable n t))
8951
8952 (defun gnus-summary-unmark-all-processable ()
8953   "Remove the process mark from all articles."
8954   (interactive)
8955   (save-excursion
8956     (while gnus-newsgroup-processable
8957       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8958   (gnus-summary-position-point))
8959
8960 (defun gnus-summary-add-mark (article type)
8961   "Mark ARTICLE with a mark of TYPE."
8962   (let ((vtype (car (assq type gnus-article-mark-lists)))
8963         var)
8964     (if (not vtype)
8965         (error "No such mark type: %s" type)
8966       (setq var (intern (format "gnus-newsgroup-%s" type)))
8967       (set var (cons article (symbol-value var)))
8968       (if (memq type '(processable cached replied forwarded recent saved))
8969           (gnus-summary-update-secondary-mark article)
8970         ;;; !!! This is bogus.  We should find out what primary
8971         ;;; !!! mark we want to set.
8972         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8973
8974 (defun gnus-summary-mark-as-expirable (n)
8975   "Mark N articles forward as expirable.
8976 If N is negative, mark backward instead.  The difference between N and
8977 the actual number of articles marked is returned."
8978   (interactive "p")
8979   (gnus-summary-mark-forward n gnus-expirable-mark))
8980
8981 (defun gnus-summary-mark-article-as-replied (article)
8982   "Mark ARTICLE as replied to and update the summary line.
8983 ARTICLE can also be a list of articles."
8984   (interactive (list (gnus-summary-article-number)))
8985   (let ((articles (if (listp article) article (list article))))
8986     (dolist (article articles)
8987       (push article gnus-newsgroup-replied)
8988       (let ((buffer-read-only nil))
8989         (when (gnus-summary-goto-subject article nil t)
8990           (gnus-summary-update-secondary-mark article))))))
8991
8992 (defun gnus-summary-mark-article-as-forwarded (article)
8993   "Mark ARTICLE as forwarded and update the summary line.
8994 ARTICLE can also be a list of articles."
8995   (let ((articles (if (listp article) article (list article))))
8996     (dolist (article articles)
8997       (push article gnus-newsgroup-forwarded)
8998       (let ((buffer-read-only nil))
8999         (when (gnus-summary-goto-subject article nil t)
9000           (gnus-summary-update-secondary-mark article))))))
9001
9002 (defun gnus-summary-set-bookmark (article)
9003   "Set a bookmark in current article."
9004   (interactive (list (gnus-summary-article-number)))
9005   (when (or (not (get-buffer gnus-article-buffer))
9006             (not gnus-current-article)
9007             (not gnus-article-current)
9008             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9009     (error "No current article selected"))
9010   ;; Remove old bookmark, if one exists.
9011   (let ((old (assq article gnus-newsgroup-bookmarks)))
9012     (when old
9013       (setq gnus-newsgroup-bookmarks
9014             (delq old gnus-newsgroup-bookmarks))))
9015   ;; Set the new bookmark, which is on the form
9016   ;; (article-number . line-number-in-body).
9017   (push
9018    (cons article
9019          (save-excursion
9020            (set-buffer gnus-article-buffer)
9021            (count-lines
9022             (min (point)
9023                  (save-excursion
9024                    (goto-char (point-min))
9025                    (search-forward "\n\n" nil t)
9026                    (point)))
9027             (point))))
9028    gnus-newsgroup-bookmarks)
9029   (gnus-message 6 "A bookmark has been added to the current article."))
9030
9031 (defun gnus-summary-remove-bookmark (article)
9032   "Remove the bookmark from the current article."
9033   (interactive (list (gnus-summary-article-number)))
9034   ;; Remove old bookmark, if one exists.
9035   (let ((old (assq article gnus-newsgroup-bookmarks)))
9036     (if old
9037         (progn
9038           (setq gnus-newsgroup-bookmarks
9039                 (delq old gnus-newsgroup-bookmarks))
9040           (gnus-message 6 "Removed bookmark."))
9041       (gnus-message 6 "No bookmark in current article."))))
9042
9043 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9044 (defun gnus-summary-mark-as-dormant (n)
9045   "Mark N articles forward as dormant.
9046 If N is negative, mark backward instead.  The difference between N and
9047 the actual number of articles marked is returned."
9048   (interactive "p")
9049   (gnus-summary-mark-forward n gnus-dormant-mark))
9050
9051 (defun gnus-summary-set-process-mark (article)
9052   "Set the process mark on ARTICLE and update the summary line."
9053   (setq gnus-newsgroup-processable
9054         (cons article
9055               (delq article gnus-newsgroup-processable)))
9056   (when (gnus-summary-goto-subject article)
9057     (gnus-summary-show-thread)
9058     (gnus-summary-goto-subject article)
9059     (gnus-summary-update-secondary-mark article)))
9060
9061 (defun gnus-summary-remove-process-mark (article)
9062   "Remove the process mark from ARTICLE and update the summary line."
9063   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9064   (when (gnus-summary-goto-subject article)
9065     (gnus-summary-show-thread)
9066     (gnus-summary-goto-subject article)
9067     (gnus-summary-update-secondary-mark article)))
9068
9069 (defun gnus-summary-set-saved-mark (article)
9070   "Set the process mark on ARTICLE and update the summary line."
9071   (push article gnus-newsgroup-saved)
9072   (when (gnus-summary-goto-subject article)
9073     (gnus-summary-update-secondary-mark article)))
9074
9075 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9076   "Mark N articles as read forwards.
9077 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9078 The difference between N and the actual number of articles marked is
9079 returned.
9080 Iff NO-EXPIRE, auto-expiry will be inhibited."
9081   (interactive "p")
9082   (gnus-summary-show-thread)
9083   (let ((backward (< n 0))
9084         (gnus-summary-goto-unread
9085          (and gnus-summary-goto-unread
9086               (not (eq gnus-summary-goto-unread 'never))
9087               (not (memq mark (list gnus-unread-mark
9088                                     gnus-ticked-mark gnus-dormant-mark)))))
9089         (n (abs n))
9090         (mark (or mark gnus-del-mark)))
9091     (while (and (> n 0)
9092                 (gnus-summary-mark-article nil mark no-expire)
9093                 (zerop (gnus-summary-next-subject
9094                         (if backward -1 1)
9095                         (and gnus-summary-goto-unread
9096                              (not (eq gnus-summary-goto-unread 'never)))
9097                         t)))
9098       (setq n (1- n)))
9099     (when (/= 0 n)
9100       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9101     (gnus-summary-recenter)
9102     (gnus-summary-position-point)
9103     (gnus-set-mode-line 'summary)
9104     n))
9105
9106 (defun gnus-summary-mark-article-as-read (mark)
9107   "Mark the current article quickly as read with MARK."
9108   (let ((article (gnus-summary-article-number)))
9109     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9110     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9111     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9112     (push (cons article mark) gnus-newsgroup-reads)
9113     ;; Possibly remove from cache, if that is used.
9114     (when gnus-use-cache
9115       (gnus-cache-enter-remove-article article))
9116     ;; Allow the backend to change the mark.
9117     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9118     ;; Check for auto-expiry.
9119     (when (and gnus-newsgroup-auto-expire
9120                (memq mark gnus-auto-expirable-marks))
9121       (setq mark gnus-expirable-mark)
9122       ;; Let the backend know about the mark change.
9123       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9124       (push article gnus-newsgroup-expirable))
9125     ;; Set the mark in the buffer.
9126     (gnus-summary-update-mark mark 'unread)
9127     t))
9128
9129 (defun gnus-summary-mark-article-as-unread (mark)
9130   "Mark the current article quickly as unread with MARK."
9131   (let* ((article (gnus-summary-article-number))
9132          (old-mark (gnus-summary-article-mark article)))
9133     ;; Allow the backend to change the mark.
9134     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9135     (if (eq mark old-mark)
9136         t
9137       (if (<= article 0)
9138           (progn
9139             (gnus-error 1 "Can't mark negative article numbers")
9140             nil)
9141         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9142         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9143         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9144         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9145         (cond ((= mark gnus-ticked-mark)
9146                (push article gnus-newsgroup-marked))
9147               ((= mark gnus-dormant-mark)
9148                (push article gnus-newsgroup-dormant))
9149               (t
9150                (push article gnus-newsgroup-unreads)))
9151         (gnus-pull article gnus-newsgroup-reads)
9152
9153         ;; See whether the article is to be put in the cache.
9154         (and gnus-use-cache
9155              (vectorp (gnus-summary-article-header article))
9156              (save-excursion
9157                (gnus-cache-possibly-enter-article
9158                 gnus-newsgroup-name article
9159                 (= mark gnus-ticked-mark)
9160                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9161
9162         ;; Fix the mark.
9163         (gnus-summary-update-mark mark 'unread)
9164         t))))
9165
9166 (defun gnus-summary-mark-article (&optional article mark no-expire)
9167   "Mark ARTICLE with MARK.  MARK can be any character.
9168 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9169 `??' (dormant) and `?E' (expirable).
9170 If MARK is nil, then the default character `?r' is used.
9171 If ARTICLE is nil, then the article on the current line will be
9172 marked.
9173 Iff NO-EXPIRE, auto-expiry will be inhibited."
9174   ;; The mark might be a string.
9175   (when (stringp mark)
9176     (setq mark (aref mark 0)))
9177   ;; If no mark is given, then we check auto-expiring.
9178   (when (null mark)
9179     (setq mark gnus-del-mark))
9180   (when (and (not no-expire)
9181              gnus-newsgroup-auto-expire
9182              (memq mark gnus-auto-expirable-marks))
9183     (setq mark gnus-expirable-mark))
9184   (let ((article (or article (gnus-summary-article-number)))
9185         (old-mark (gnus-summary-article-mark article)))
9186     ;; Allow the backend to change the mark.
9187     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9188     (if (eq mark old-mark)
9189         t
9190       (unless article
9191         (error "No article on current line"))
9192       (if (not (if (or (= mark gnus-unread-mark)
9193                        (= mark gnus-ticked-mark)
9194                        (= mark gnus-dormant-mark))
9195                    (gnus-mark-article-as-unread article mark)
9196                  (gnus-mark-article-as-read article mark)))
9197           t
9198         ;; See whether the article is to be put in the cache.
9199         (and gnus-use-cache
9200              (not (= mark gnus-canceled-mark))
9201              (vectorp (gnus-summary-article-header article))
9202              (save-excursion
9203                (gnus-cache-possibly-enter-article
9204                 gnus-newsgroup-name article
9205                 (= mark gnus-ticked-mark)
9206                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9207
9208         (when (gnus-summary-goto-subject article nil t)
9209           (let ((buffer-read-only nil))
9210             (gnus-summary-show-thread)
9211             ;; Fix the mark.
9212             (gnus-summary-update-mark mark 'unread)
9213             t))))))
9214
9215 (defun gnus-summary-update-secondary-mark (article)
9216   "Update the secondary (read, process, cache) mark."
9217   (gnus-summary-update-mark
9218    (cond ((memq article gnus-newsgroup-processable)
9219           gnus-process-mark)
9220          ((memq article gnus-newsgroup-cached)
9221           gnus-cached-mark)
9222          ((memq article gnus-newsgroup-replied)
9223           gnus-replied-mark)
9224          ((memq article gnus-newsgroup-forwarded)
9225           gnus-forwarded-mark)
9226          ((memq article gnus-newsgroup-saved)
9227           gnus-saved-mark)
9228          ((memq article gnus-newsgroup-recent)
9229           gnus-recent-mark)
9230          ((memq article gnus-newsgroup-unseen)
9231           gnus-unseen-mark)
9232          (t gnus-no-mark))
9233    'replied)
9234   (when (gnus-visual-p 'summary-highlight 'highlight)
9235     (gnus-run-hooks 'gnus-summary-update-hook))
9236   t)
9237
9238 (defun gnus-summary-update-mark (mark type)
9239   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9240         (buffer-read-only nil))
9241     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9242     (when forward
9243       (when (looking-at "\r")
9244         (incf forward))
9245       (when (<= (+ forward (point)) (point-max))
9246         ;; Go to the right position on the line.
9247         (goto-char (+ forward (point)))
9248         ;; Replace the old mark with the new mark.
9249         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9250         ;; Optionally update the marks by some user rule.
9251         (when (eq type 'unread)
9252           (gnus-data-set-mark
9253            (gnus-data-find (gnus-summary-article-number)) mark)
9254           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9255
9256 (defun gnus-mark-article-as-read (article &optional mark)
9257   "Enter ARTICLE in the pertinent lists and remove it from others."
9258   ;; Make the article expirable.
9259   (let ((mark (or mark gnus-del-mark)))
9260     (if (= mark gnus-expirable-mark)
9261         (push article gnus-newsgroup-expirable)
9262       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9263     ;; Remove from unread and marked lists.
9264     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9265     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9266     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9267     (push (cons article mark) gnus-newsgroup-reads)
9268     ;; Possibly remove from cache, if that is used.
9269     (when gnus-use-cache
9270       (gnus-cache-enter-remove-article article))
9271     t))
9272
9273 (defun gnus-mark-article-as-unread (article &optional mark)
9274   "Enter ARTICLE in the pertinent lists and remove it from others."
9275   (let ((mark (or mark gnus-ticked-mark)))
9276     (if (<= article 0)
9277         (progn
9278           (gnus-error 1 "Can't mark negative article numbers")
9279           nil)
9280       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9281             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9282             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9283             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9284
9285       ;; Unsuppress duplicates?
9286       (when gnus-suppress-duplicates
9287         (gnus-dup-unsuppress-article article))
9288
9289       (cond ((= mark gnus-ticked-mark)
9290              (push article gnus-newsgroup-marked))
9291             ((= mark gnus-dormant-mark)
9292              (push article gnus-newsgroup-dormant))
9293             (t
9294              (push article gnus-newsgroup-unreads)))
9295       (gnus-pull article gnus-newsgroup-reads)
9296       t)))
9297
9298 (defalias 'gnus-summary-mark-as-unread-forward
9299   'gnus-summary-tick-article-forward)
9300 (make-obsolete 'gnus-summary-mark-as-unread-forward
9301                'gnus-summary-tick-article-forward)
9302 (defun gnus-summary-tick-article-forward (n)
9303   "Tick N articles forwards.
9304 If N is negative, tick backwards instead.
9305 The difference between N and the number of articles ticked is returned."
9306   (interactive "p")
9307   (gnus-summary-mark-forward n gnus-ticked-mark))
9308
9309 (defalias 'gnus-summary-mark-as-unread-backward
9310   'gnus-summary-tick-article-backward)
9311 (make-obsolete 'gnus-summary-mark-as-unread-backward
9312                'gnus-summary-tick-article-backward)
9313 (defun gnus-summary-tick-article-backward (n)
9314   "Tick N articles backwards.
9315 The difference between N and the number of articles ticked is returned."
9316   (interactive "p")
9317   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9318
9319 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9320 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9321 (defun gnus-summary-tick-article (&optional article clear-mark)
9322   "Mark current article as unread.
9323 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9324 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9325   (interactive)
9326   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9327                                        gnus-ticked-mark)))
9328
9329 (defun gnus-summary-mark-as-read-forward (n)
9330   "Mark N articles as read forwards.
9331 If N is negative, mark backwards instead.
9332 The difference between N and the actual number of articles marked is
9333 returned."
9334   (interactive "p")
9335   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9336
9337 (defun gnus-summary-mark-as-read-backward (n)
9338   "Mark the N articles as read backwards.
9339 The difference between N and the actual number of articles marked is
9340 returned."
9341   (interactive "p")
9342   (gnus-summary-mark-forward
9343    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9344
9345 (defun gnus-summary-mark-as-read (&optional article mark)
9346   "Mark current article as read.
9347 ARTICLE specifies the article to be marked as read.
9348 MARK specifies a string to be inserted at the beginning of the line."
9349   (gnus-summary-mark-article article mark))
9350
9351 (defun gnus-summary-clear-mark-forward (n)
9352   "Clear marks from N articles forward.
9353 If N is negative, clear backward instead.
9354 The difference between N and the number of marks cleared is returned."
9355   (interactive "p")
9356   (gnus-summary-mark-forward n gnus-unread-mark))
9357
9358 (defun gnus-summary-clear-mark-backward (n)
9359   "Clear marks from N articles backward.
9360 The difference between N and the number of marks cleared is returned."
9361   (interactive "p")
9362   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9363
9364 (defun gnus-summary-mark-unread-as-read ()
9365   "Intended to be used by `gnus-summary-mark-article-hook'."
9366   (when (memq gnus-current-article gnus-newsgroup-unreads)
9367     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9368
9369 (defun gnus-summary-mark-read-and-unread-as-read ()
9370   "Intended to be used by `gnus-summary-mark-article-hook'."
9371   (let ((mark (gnus-summary-article-mark)))
9372     (when (or (gnus-unread-mark-p mark)
9373               (gnus-read-mark-p mark))
9374       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9375
9376 (defun gnus-summary-mark-unread-as-ticked ()
9377   "Intended to be used by `gnus-summary-mark-article-hook'."
9378   (when (memq gnus-current-article gnus-newsgroup-unreads)
9379     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9380
9381 (defun gnus-summary-mark-region-as-read (point mark all)
9382   "Mark all unread articles between point and mark as read.
9383 If given a prefix, mark all articles between point and mark as read,
9384 even ticked and dormant ones."
9385   (interactive "r\nP")
9386   (save-excursion
9387     (let (article)
9388       (goto-char point)
9389       (beginning-of-line)
9390       (while (and
9391               (< (point) mark)
9392               (progn
9393                 (when (or all
9394                           (memq (setq article (gnus-summary-article-number))
9395                                 gnus-newsgroup-unreads))
9396                   (gnus-summary-mark-article article gnus-del-mark))
9397                 t)
9398               (gnus-summary-find-next))))))
9399
9400 (defun gnus-summary-mark-below (score mark)
9401   "Mark articles with score less than SCORE with MARK."
9402   (interactive "P\ncMark: ")
9403   (setq score (if score
9404                   (prefix-numeric-value score)
9405                 (or gnus-summary-default-score 0)))
9406   (save-excursion
9407     (set-buffer gnus-summary-buffer)
9408     (goto-char (point-min))
9409     (while
9410         (progn
9411           (and (< (gnus-summary-article-score) score)
9412                (gnus-summary-mark-article nil mark))
9413           (gnus-summary-find-next)))))
9414
9415 (defun gnus-summary-kill-below (&optional score)
9416   "Mark articles with score below SCORE as read."
9417   (interactive "P")
9418   (gnus-summary-mark-below score gnus-killed-mark))
9419
9420 (defun gnus-summary-clear-above (&optional score)
9421   "Clear all marks from articles with score above SCORE."
9422   (interactive "P")
9423   (gnus-summary-mark-above score gnus-unread-mark))
9424
9425 (defun gnus-summary-tick-above (&optional score)
9426   "Tick all articles with score above SCORE."
9427   (interactive "P")
9428   (gnus-summary-mark-above score gnus-ticked-mark))
9429
9430 (defun gnus-summary-mark-above (score mark)
9431   "Mark articles with score over SCORE with MARK."
9432   (interactive "P\ncMark: ")
9433   (setq score (if score
9434                   (prefix-numeric-value score)
9435                 (or gnus-summary-default-score 0)))
9436   (save-excursion
9437     (set-buffer gnus-summary-buffer)
9438     (goto-char (point-min))
9439     (while (and (progn
9440                   (when (> (gnus-summary-article-score) score)
9441                     (gnus-summary-mark-article nil mark))
9442                   t)
9443                 (gnus-summary-find-next)))))
9444
9445 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9446 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9447 (defun gnus-summary-limit-include-expunged (&optional no-error)
9448   "Display all the hidden articles that were expunged for low scores."
9449   (interactive)
9450   (let ((buffer-read-only nil))
9451     (let ((scored gnus-newsgroup-scored)
9452           headers h)
9453       (while scored
9454         (unless (gnus-summary-article-header (caar scored))
9455           (and (setq h (gnus-number-to-header (caar scored)))
9456                (< (cdar scored) gnus-summary-expunge-below)
9457                (push h headers)))
9458         (setq scored (cdr scored)))
9459       (if (not headers)
9460           (when (not no-error)
9461             (error "No expunged articles hidden"))
9462         (goto-char (point-min))
9463         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9464         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9465         (mapcar (lambda (x) (push (mail-header-number x)
9466                                   gnus-newsgroup-limit))
9467                 headers)
9468         (gnus-summary-prepare-unthreaded (nreverse headers))
9469         (goto-char (point-min))
9470         (gnus-summary-position-point)
9471         t))))
9472
9473 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9474   "Mark all unread articles in this newsgroup as read.
9475 If prefix argument ALL is non-nil, ticked and dormant articles will
9476 also be marked as read.
9477 If QUIETLY is non-nil, no questions will be asked.
9478 If TO-HERE is non-nil, it should be a point in the buffer.  All
9479 articles before (after, if REVERSE is set) this point will be marked as read.
9480 Note that this function will only catch up the unread article
9481 in the current summary buffer limitation.
9482 The number of articles marked as read is returned."
9483   (interactive "P")
9484   (prog1
9485       (save-excursion
9486         (when (or quietly
9487                   (not gnus-interactive-catchup) ;Without confirmation?
9488                   gnus-expert-user
9489                   (gnus-y-or-n-p
9490                    (if all
9491                        "Mark absolutely all articles as read? "
9492                      "Mark all unread articles as read? ")))
9493           (if (and not-mark
9494                    (not gnus-newsgroup-adaptive)
9495                    (not gnus-newsgroup-auto-expire)
9496                    (not gnus-suppress-duplicates)
9497                    (or (not gnus-use-cache)
9498                        (eq gnus-use-cache 'passive)))
9499               (progn
9500                 (when all
9501                   (setq gnus-newsgroup-marked nil
9502                         gnus-newsgroup-dormant nil))
9503                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9504             ;; We actually mark all articles as canceled, which we
9505             ;; have to do when using auto-expiry or adaptive scoring.
9506             (gnus-summary-show-all-threads)
9507             (if (and to-here reverse)
9508                 (progn
9509                   (goto-char to-here)
9510                   (while (and
9511                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9512                           (gnus-summary-find-next (not all) nil nil t))))
9513               (when (gnus-summary-first-subject (not all) t)
9514                 (while (and
9515                         (if to-here (< (point) to-here) t)
9516                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9517                         (gnus-summary-find-next (not all) nil nil t)))))
9518             (gnus-set-mode-line 'summary))
9519           t))
9520     (gnus-summary-position-point)))
9521
9522 (defun gnus-summary-catchup-to-here (&optional all)
9523   "Mark all unticked articles before the current one as read.
9524 If ALL is non-nil, also mark ticked and dormant articles as read."
9525   (interactive "P")
9526   (save-excursion
9527     (gnus-save-hidden-threads
9528       (let ((beg (point)))
9529         ;; We check that there are unread articles.
9530         (when (or all (gnus-summary-find-prev))
9531           (gnus-summary-catchup all t beg)))))
9532   (gnus-summary-position-point))
9533
9534 (defun gnus-summary-catchup-from-here (&optional all)
9535   "Mark all unticked articles after the current one as read.
9536 If ALL is non-nil, also mark ticked and dormant articles as read."
9537   (interactive "P")
9538   (save-excursion
9539     (gnus-save-hidden-threads
9540       (let ((beg (point)))
9541         ;; We check that there are unread articles.
9542         (when (or all (gnus-summary-find-next))
9543           (gnus-summary-catchup all t beg nil t)))))
9544
9545   (gnus-summary-position-point))
9546 (defun gnus-summary-catchup-all (&optional quietly)
9547   "Mark all articles in this newsgroup as read."
9548   (interactive "P")
9549   (gnus-summary-catchup t quietly))
9550
9551 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9552   "Mark all unread articles in this group as read, then exit.
9553 If prefix argument ALL is non-nil, all articles are marked as read.
9554 If QUIETLY is non-nil, no questions will be asked."
9555   (interactive "P")
9556   (when (gnus-summary-catchup all quietly nil 'fast)
9557     ;; Select next newsgroup or exit.
9558     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9559              (eq gnus-auto-select-next 'quietly))
9560         (gnus-summary-next-group nil)
9561       (gnus-summary-exit))))
9562
9563 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9564   "Mark all articles in this newsgroup as read, and then exit."
9565   (interactive "P")
9566   (gnus-summary-catchup-and-exit t quietly))
9567
9568 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9569   "Mark all articles in this group as read and select the next group.
9570 If given a prefix, mark all articles, unread as well as ticked, as
9571 read."
9572   (interactive "P")
9573   (save-excursion
9574     (gnus-summary-catchup all))
9575   (gnus-summary-next-group))
9576
9577 ;;;
9578 ;;; with article
9579 ;;;
9580
9581 (defmacro gnus-with-article (article &rest forms)
9582   "Select ARTICLE and perform FORMS in the original article buffer.
9583 Then replace the article with the result."
9584   `(progn
9585      ;; We don't want the article to be marked as read.
9586      (let (gnus-mark-article-hook)
9587        (gnus-summary-select-article t t nil ,article))
9588      (set-buffer gnus-original-article-buffer)
9589      ,@forms
9590      (if (not (gnus-check-backend-function
9591                'request-replace-article (car gnus-article-current)))
9592          (gnus-message 5 "Read-only group; not replacing")
9593        (unless (gnus-request-replace-article
9594                 ,article (car gnus-article-current)
9595                 (current-buffer) t)
9596          (error "Couldn't replace article")))
9597      ;; The cache and backlog have to be flushed somewhat.
9598      (when gnus-keep-backlog
9599        (gnus-backlog-remove-article
9600         (car gnus-article-current) (cdr gnus-article-current)))
9601      (when gnus-use-cache
9602        (gnus-cache-update-article
9603         (car gnus-article-current) (cdr gnus-article-current)))))
9604
9605 (put 'gnus-with-article 'lisp-indent-function 1)
9606 (put 'gnus-with-article 'edebug-form-spec '(form body))
9607
9608 ;; Thread-based commands.
9609
9610 (defun gnus-summary-articles-in-thread (&optional article)
9611   "Return a list of all articles in the current thread.
9612 If ARTICLE is non-nil, return all articles in the thread that starts
9613 with that article."
9614   (let* ((article (or article (gnus-summary-article-number)))
9615          (data (gnus-data-find-list article))
9616          (top-level (gnus-data-level (car data)))
9617          (top-subject
9618           (cond ((null gnus-thread-operation-ignore-subject)
9619                  (gnus-simplify-subject-re
9620                   (mail-header-subject (gnus-data-header (car data)))))
9621                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9622                  (gnus-simplify-subject-fuzzy
9623                   (mail-header-subject (gnus-data-header (car data)))))
9624                 (t nil)))
9625          (end-point (save-excursion
9626                       (if (gnus-summary-go-to-next-thread)
9627                           (point) (point-max))))
9628          articles)
9629     (while (and data
9630                 (< (gnus-data-pos (car data)) end-point))
9631       (when (or (not top-subject)
9632                 (string= top-subject
9633                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9634                              (gnus-simplify-subject-fuzzy
9635                               (mail-header-subject
9636                                (gnus-data-header (car data))))
9637                            (gnus-simplify-subject-re
9638                             (mail-header-subject
9639                              (gnus-data-header (car data)))))))
9640         (push (gnus-data-number (car data)) articles))
9641       (unless (and (setq data (cdr data))
9642                    (> (gnus-data-level (car data)) top-level))
9643         (setq data nil)))
9644     ;; Return the list of articles.
9645     (nreverse articles)))
9646
9647 (defun gnus-summary-rethread-current ()
9648   "Rethread the thread the current article is part of."
9649   (interactive)
9650   (let* ((gnus-show-threads t)
9651          (article (gnus-summary-article-number))
9652          (id (mail-header-id (gnus-summary-article-header)))
9653          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9654     (unless id
9655       (error "No article on the current line"))
9656     (gnus-rebuild-thread id)
9657     (gnus-summary-goto-subject article)))
9658
9659 (defun gnus-summary-reparent-thread ()
9660   "Make the current article child of the marked (or previous) article.
9661
9662 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9663 is non-nil or the Subject: of both articles are the same."
9664   (interactive)
9665   (unless (not (gnus-group-read-only-p))
9666     (error "The current newsgroup does not support article editing"))
9667   (unless (<= (length gnus-newsgroup-processable) 1)
9668     (error "No more than one article may be marked"))
9669   (save-window-excursion
9670     (let ((gnus-article-buffer " *reparent*")
9671           (current-article (gnus-summary-article-number))
9672           ;; First grab the marked article, otherwise one line up.
9673           (parent-article (if (not (null gnus-newsgroup-processable))
9674                               (car gnus-newsgroup-processable)
9675                             (save-excursion
9676                               (if (eq (forward-line -1) 0)
9677                                   (gnus-summary-article-number)
9678                                 (error "Beginning of summary buffer"))))))
9679       (unless (not (eq current-article parent-article))
9680         (error "An article may not be self-referential"))
9681       (let ((message-id (mail-header-id
9682                          (gnus-summary-article-header parent-article))))
9683         (unless (and message-id (not (equal message-id "")))
9684           (error "No message-id in desired parent"))
9685         (gnus-with-article current-article
9686           (save-restriction
9687             (goto-char (point-min))
9688             (message-narrow-to-head)
9689             (if (re-search-forward "^References: " nil t)
9690                 (progn
9691                   (re-search-forward "^[^ \t]" nil t)
9692                   (forward-line -1)
9693                   (end-of-line)
9694                   (insert " " message-id))
9695               (insert "References: " message-id "\n"))))
9696         (set-buffer gnus-summary-buffer)
9697         (gnus-summary-unmark-all-processable)
9698         (gnus-summary-update-article current-article)
9699         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9700             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9701         (gnus-summary-rethread-current)
9702         (gnus-message 3 "Article %d is now the child of article %d"
9703                       current-article parent-article)))))
9704
9705 (defun gnus-summary-toggle-threads (&optional arg)
9706   "Toggle showing conversation threads.
9707 If ARG is positive number, turn showing conversation threads on."
9708   (interactive "P")
9709   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9710     (setq gnus-show-threads
9711           (if (null arg) (not gnus-show-threads)
9712             (> (prefix-numeric-value arg) 0)))
9713     (gnus-summary-prepare)
9714     (gnus-summary-goto-subject current)
9715     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9716     (gnus-summary-position-point)))
9717
9718 (defun gnus-summary-show-all-threads ()
9719   "Show all threads."
9720   (interactive)
9721   (save-excursion
9722     (let ((buffer-read-only nil))
9723       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9724   (gnus-summary-position-point))
9725
9726 (defun gnus-summary-show-thread ()
9727   "Show thread subtrees.
9728 Returns nil if no thread was there to be shown."
9729   (interactive)
9730   (let ((buffer-read-only nil)
9731         (orig (point))
9732         ;; first goto end then to beg, to have point at beg after let
9733         (end (progn (end-of-line) (point)))
9734         (beg (progn (beginning-of-line) (point))))
9735     (prog1
9736         ;; Any hidden lines here?
9737         (search-forward "\r" end t)
9738       (subst-char-in-region beg end ?\^M ?\n t)
9739       (goto-char orig)
9740       (gnus-summary-position-point))))
9741
9742 (defun gnus-summary-maybe-hide-threads ()
9743   "If requested, hide the threads that should be hidden."
9744   (when (and gnus-show-threads
9745              gnus-thread-hide-subtree)
9746     (gnus-summary-hide-all-threads
9747      (if (or (consp gnus-thread-hide-subtree)
9748              (gnus-functionp gnus-thread-hide-subtree))
9749          (gnus-make-predicate gnus-thread-hide-subtree)
9750        nil))))
9751
9752 ;;; Hiding predicates.
9753
9754 (defun gnus-article-unread-p (header)
9755   (memq (mail-header-number header) gnus-newsgroup-unreads))
9756
9757 (defun gnus-article-unseen-p (header)
9758   (memq (mail-header-number header) gnus-newsgroup-unseen))
9759
9760 (defun gnus-map-articles (predicate articles)
9761   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
9762   (apply 'gnus-or (mapcar predicate
9763                           (mapcar 'gnus-summary-article-header articles))))
9764
9765 (defun gnus-summary-hide-all-threads (&optional predicate)
9766   "Hide all thread subtrees.
9767 If PREDICATE is supplied, threads that satisfy this predicate
9768 will not be hidden."
9769   (interactive)
9770   (save-excursion
9771     (goto-char (point-min))
9772     (let ((end nil))
9773       (while (not end)
9774         (when (or (not predicate)
9775                   (gnus-map-articles
9776                    predicate (gnus-summary-article-children)))
9777             (gnus-summary-hide-thread))
9778         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
9779   (gnus-summary-position-point))
9780
9781 (defun gnus-summary-hide-thread ()
9782   "Hide thread subtrees.
9783 If PREDICATE is supplied, threads that satisfy this predicate
9784 will not be hidden.
9785 Returns nil if no threads were there to be hidden."
9786   (interactive)
9787   (let ((buffer-read-only nil)
9788         (start (point))
9789         (article (gnus-summary-article-number)))
9790     (goto-char start)
9791     ;; Go forward until either the buffer ends or the subthread
9792     ;; ends.
9793     (when (and (not (eobp))
9794                (or (zerop (gnus-summary-next-thread 1 t))
9795                    (goto-char (point-max))))
9796       (prog1
9797           (if (and (> (point) start)
9798                    (search-backward "\n" start t))
9799               (progn
9800                 (subst-char-in-region start (point) ?\n ?\^M)
9801                 (gnus-summary-goto-subject article))
9802             (goto-char start)
9803             nil)))))
9804
9805 (defun gnus-summary-go-to-next-thread (&optional previous)
9806   "Go to the same level (or less) next thread.
9807 If PREVIOUS is non-nil, go to previous thread instead.
9808 Return the article number moved to, or nil if moving was impossible."
9809   (let ((level (gnus-summary-thread-level))
9810         (way (if previous -1 1))
9811         (beg (point)))
9812     (forward-line way)
9813     (while (and (not (eobp))
9814                 (< level (gnus-summary-thread-level)))
9815       (forward-line way))
9816     (if (eobp)
9817         (progn
9818           (goto-char beg)
9819           nil)
9820       (setq beg (point))
9821       (prog1
9822           (gnus-summary-article-number)
9823         (goto-char beg)))))
9824
9825 (defun gnus-summary-next-thread (n &optional silent)
9826   "Go to the same level next N'th thread.
9827 If N is negative, search backward instead.
9828 Returns the difference between N and the number of skips actually
9829 done.
9830
9831 If SILENT, don't output messages."
9832   (interactive "p")
9833   (let ((backward (< n 0))
9834         (n (abs n)))
9835     (while (and (> n 0)
9836                 (gnus-summary-go-to-next-thread backward))
9837       (decf n))
9838     (unless silent
9839       (gnus-summary-position-point))
9840     (when (and (not silent) (/= 0 n))
9841       (gnus-message 7 "No more threads"))
9842     n))
9843
9844 (defun gnus-summary-prev-thread (n)
9845   "Go to the same level previous N'th thread.
9846 Returns the difference between N and the number of skips actually
9847 done."
9848   (interactive "p")
9849   (gnus-summary-next-thread (- n)))
9850
9851 (defun gnus-summary-go-down-thread ()
9852   "Go down one level in the current thread."
9853   (let ((children (gnus-summary-article-children)))
9854     (when children
9855       (gnus-summary-goto-subject (car children)))))
9856
9857 (defun gnus-summary-go-up-thread ()
9858   "Go up one level in the current thread."
9859   (let ((parent (gnus-summary-article-parent)))
9860     (when parent
9861       (gnus-summary-goto-subject parent))))
9862
9863 (defun gnus-summary-down-thread (n)
9864   "Go down thread N steps.
9865 If N is negative, go up instead.
9866 Returns the difference between N and how many steps down that were
9867 taken."
9868   (interactive "p")
9869   (let ((up (< n 0))
9870         (n (abs n)))
9871     (while (and (> n 0)
9872                 (if up (gnus-summary-go-up-thread)
9873                   (gnus-summary-go-down-thread)))
9874       (setq n (1- n)))
9875     (gnus-summary-position-point)
9876     (when (/= 0 n)
9877       (gnus-message 7 "Can't go further"))
9878     n))
9879
9880 (defun gnus-summary-up-thread (n)
9881   "Go up thread N steps.
9882 If N is negative, go down instead.
9883 Returns the difference between N and how many steps down that were
9884 taken."
9885   (interactive "p")
9886   (gnus-summary-down-thread (- n)))
9887
9888 (defun gnus-summary-top-thread ()
9889   "Go to the top of the thread."
9890   (interactive)
9891   (while (gnus-summary-go-up-thread))
9892   (gnus-summary-article-number))
9893
9894 (defun gnus-summary-kill-thread (&optional unmark)
9895   "Mark articles under current thread as read.
9896 If the prefix argument is positive, remove any kinds of marks.
9897 If the prefix argument is negative, tick articles instead."
9898   (interactive "P")
9899   (when unmark
9900     (setq unmark (prefix-numeric-value unmark)))
9901   (let ((articles (gnus-summary-articles-in-thread)))
9902     (save-excursion
9903       ;; Expand the thread.
9904       (gnus-summary-show-thread)
9905       ;; Mark all the articles.
9906       (while articles
9907         (gnus-summary-goto-subject (car articles))
9908         (cond ((null unmark)
9909                (gnus-summary-mark-article-as-read gnus-killed-mark))
9910               ((> unmark 0)
9911                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9912               (t
9913                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9914         (setq articles (cdr articles))))
9915     ;; Hide killed subtrees.
9916     (and (null unmark)
9917          gnus-thread-hide-killed
9918          (gnus-summary-hide-thread))
9919     ;; If marked as read, go to next unread subject.
9920     (when (null unmark)
9921       ;; Go to next unread subject.
9922       (gnus-summary-next-subject 1 t)))
9923   (gnus-set-mode-line 'summary))
9924
9925 ;; Summary sorting commands
9926
9927 (defun gnus-summary-sort-by-number (&optional reverse)
9928   "Sort the summary buffer by article number.
9929 Argument REVERSE means reverse order."
9930   (interactive "P")
9931   (gnus-summary-sort 'number reverse))
9932
9933 (defun gnus-summary-sort-by-author (&optional reverse)
9934   "Sort the summary buffer by author name alphabetically.
9935 If `case-fold-search' is non-nil, case of letters is ignored.
9936 Argument REVERSE means reverse order."
9937   (interactive "P")
9938   (gnus-summary-sort 'author reverse))
9939
9940 (defun gnus-summary-sort-by-subject (&optional reverse)
9941   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9942 If `case-fold-search' is non-nil, case of letters is ignored.
9943 Argument REVERSE means reverse order."
9944   (interactive "P")
9945   (gnus-summary-sort 'subject reverse))
9946
9947 (defun gnus-summary-sort-by-date (&optional reverse)
9948   "Sort the summary buffer by date.
9949 Argument REVERSE means reverse order."
9950   (interactive "P")
9951   (gnus-summary-sort 'date reverse))
9952
9953 (defun gnus-summary-sort-by-score (&optional reverse)
9954   "Sort the summary buffer by score.
9955 Argument REVERSE means reverse order."
9956   (interactive "P")
9957   (gnus-summary-sort 'score reverse))
9958
9959 (defun gnus-summary-sort-by-lines (&optional reverse)
9960   "Sort the summary buffer by the number of lines.
9961 Argument REVERSE means reverse order."
9962   (interactive "P")
9963   (gnus-summary-sort 'lines reverse))
9964
9965 (defun gnus-summary-sort-by-chars (&optional reverse)
9966   "Sort the summary buffer by article length.
9967 Argument REVERSE means reverse order."
9968   (interactive "P")
9969   (gnus-summary-sort 'chars reverse))
9970
9971 (defun gnus-summary-sort-by-original (&optional reverse)
9972   "Sort the summary buffer using the default sorting method.
9973 Argument REVERSE means reverse order."
9974   (interactive "P")
9975   (let* ((buffer-read-only)
9976          (gnus-summary-prepare-hook nil))
9977     ;; We do the sorting by regenerating the threads.
9978     (gnus-summary-prepare)
9979     ;; Hide subthreads if needed.
9980     (gnus-summary-maybe-hide-threads)))
9981
9982 (defun gnus-summary-sort (predicate reverse)
9983   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9984   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9985          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9986          (gnus-thread-sort-functions
9987           (if (not reverse)
9988               thread
9989             `(lambda (t1 t2)
9990                (,thread t2 t1))))
9991          (gnus-sort-gathered-threads-function
9992           gnus-thread-sort-functions)
9993          (gnus-article-sort-functions
9994           (if (not reverse)
9995               article
9996             `(lambda (t1 t2)
9997                (,article t2 t1))))
9998          (buffer-read-only)
9999          (gnus-summary-prepare-hook nil))
10000     ;; We do the sorting by regenerating the threads.
10001     (gnus-summary-prepare)
10002     ;; Hide subthreads if needed.
10003     (gnus-summary-maybe-hide-threads)))
10004
10005 ;; Summary saving commands.
10006
10007 (defun gnus-summary-save-article (&optional n not-saved)
10008   "Save the current article using the default saver function.
10009 If N is a positive number, save the N next articles.
10010 If N is a negative number, save the N previous articles.
10011 If N is nil and any articles have been marked with the process mark,
10012 save those articles instead.
10013 The variable `gnus-default-article-saver' specifies the saver function."
10014   (interactive "P")
10015   (let* ((articles (gnus-summary-work-articles n))
10016          (save-buffer (save-excursion
10017                         (nnheader-set-temp-buffer " *Gnus Save*")))
10018          (num (length articles))
10019          header file)
10020     (dolist (article articles)
10021       (setq header (gnus-summary-article-header article))
10022       (if (not (vectorp header))
10023           ;; This is a pseudo-article.
10024           (if (assq 'name header)
10025               (gnus-copy-file (cdr (assq 'name header)))
10026             (gnus-message 1 "Article %d is unsaveable" article))
10027         ;; This is a real article.
10028         (save-window-excursion
10029           (let ((gnus-display-mime-function nil)
10030                 (gnus-article-prepare-hook nil))
10031             (gnus-summary-select-article t nil nil article)))
10032         (save-excursion
10033           (set-buffer save-buffer)
10034           (erase-buffer)
10035           (insert-buffer-substring gnus-original-article-buffer))
10036         (setq file (gnus-article-save save-buffer file num))
10037         (gnus-summary-remove-process-mark article)
10038         (unless not-saved
10039           (gnus-summary-set-saved-mark article))))
10040     (gnus-kill-buffer save-buffer)
10041     (gnus-summary-position-point)
10042     (gnus-set-mode-line 'summary)
10043     n))
10044
10045 (defun gnus-summary-pipe-output (&optional arg)
10046   "Pipe the current article to a subprocess.
10047 If N is a positive number, pipe the N next articles.
10048 If N is a negative number, pipe the N previous articles.
10049 If N is nil and any articles have been marked with the process mark,
10050 pipe those articles instead."
10051   (interactive "P")
10052   (require 'gnus-art)
10053   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10054     (gnus-summary-save-article arg t))
10055   (let ((buffer (get-buffer "*Shell Command Output*")))
10056     (if (and buffer
10057              (with-current-buffer buffer (> (point-max) (point-min))))
10058         (gnus-configure-windows 'pipe))))
10059
10060 (defun gnus-summary-save-article-mail (&optional arg)
10061   "Append the current article to an mail file.
10062 If N is a positive number, save the N next articles.
10063 If N is a negative number, save the N previous articles.
10064 If N is nil and any articles have been marked with the process mark,
10065 save those articles instead."
10066   (interactive "P")
10067   (require 'gnus-art)
10068   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10069     (gnus-summary-save-article arg)))
10070
10071 (defun gnus-summary-save-article-rmail (&optional arg)
10072   "Append the current article to an rmail file.
10073 If N is a positive number, save the N next articles.
10074 If N is a negative number, save the N previous articles.
10075 If N is nil and any articles have been marked with the process mark,
10076 save those articles instead."
10077   (interactive "P")
10078   (require 'gnus-art)
10079   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10080     (gnus-summary-save-article arg)))
10081
10082 (defun gnus-summary-save-article-file (&optional arg)
10083   "Append the current article to a file.
10084 If N is a positive number, save the N next articles.
10085 If N is a negative number, save the N previous articles.
10086 If N is nil and any articles have been marked with the process mark,
10087 save those articles instead."
10088   (interactive "P")
10089   (require 'gnus-art)
10090   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10091     (gnus-summary-save-article arg)))
10092
10093 (defun gnus-summary-write-article-file (&optional arg)
10094   "Write the current article to a file, deleting the previous file.
10095 If N is a positive number, save the N next articles.
10096 If N is a negative number, save the N previous articles.
10097 If N is nil and any articles have been marked with the process mark,
10098 save those articles instead."
10099   (interactive "P")
10100   (require 'gnus-art)
10101   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10102     (gnus-summary-save-article arg)))
10103
10104 (defun gnus-summary-save-article-body-file (&optional arg)
10105   "Append the current article body to a file.
10106 If N is a positive number, save the N next articles.
10107 If N is a negative number, save the N previous articles.
10108 If N is nil and any articles have been marked with the process mark,
10109 save those articles instead."
10110   (interactive "P")
10111   (require 'gnus-art)
10112   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10113     (gnus-summary-save-article arg)))
10114
10115 (defun gnus-summary-muttprint (&optional arg)
10116   "Print the current article using Muttprint.
10117 If N is a positive number, save the N next articles.
10118 If N is a negative number, save the N previous articles.
10119 If N is nil and any articles have been marked with the process mark,
10120 save those articles instead."
10121   (interactive "P")
10122   (require 'gnus-art)
10123   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10124     (gnus-summary-save-article arg t)))
10125
10126 (defun gnus-summary-pipe-message (program)
10127   "Pipe the current article through PROGRAM."
10128   (interactive "sProgram: ")
10129   (gnus-summary-select-article)
10130   (let ((mail-header-separator ""))
10131     (gnus-eval-in-buffer-window gnus-article-buffer
10132       (save-restriction
10133         (widen)
10134         (let ((start (window-start))
10135               buffer-read-only)
10136           (message-pipe-buffer-body program)
10137           (set-window-start (get-buffer-window (current-buffer)) start))))))
10138
10139 (defun gnus-get-split-value (methods)
10140   "Return a value based on the split METHODS."
10141   (let (split-name method result match)
10142     (when methods
10143       (save-excursion
10144         (set-buffer gnus-original-article-buffer)
10145         (save-restriction
10146           (nnheader-narrow-to-headers)
10147           (while (and methods (not split-name))
10148             (goto-char (point-min))
10149             (setq method (pop methods))
10150             (setq match (car method))
10151             (when (cond
10152                    ((stringp match)
10153                     ;; Regular expression.
10154                     (ignore-errors
10155                       (re-search-forward match nil t)))
10156                    ((gnus-functionp match)
10157                     ;; Function.
10158                     (save-restriction
10159                       (widen)
10160                       (setq result (funcall match gnus-newsgroup-name))))
10161                    ((consp match)
10162                     ;; Form.
10163                     (save-restriction
10164                       (widen)
10165                       (setq result (eval match)))))
10166               (setq split-name (cdr method))
10167               (cond ((stringp result)
10168                      (push (expand-file-name
10169                             result gnus-article-save-directory)
10170                            split-name))
10171                     ((consp result)
10172                      (setq split-name (append result split-name)))))))))
10173     (nreverse split-name)))
10174
10175 (defun gnus-valid-move-group-p (group)
10176   (and (boundp group)
10177        (symbol-name group)
10178        (symbol-value group)
10179        (gnus-get-function (gnus-find-method-for-group
10180                            (symbol-name group)) 'request-accept-article t)))
10181
10182 (defun gnus-read-move-group-name (prompt default articles prefix)
10183   "Read a group name."
10184   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10185          (minibuffer-confirm-incomplete nil) ; XEmacs
10186          (prom
10187           (format "%s %s to:"
10188                   prompt
10189                   (if (> (length articles) 1)
10190                       (format "these %d articles" (length articles))
10191                     "this article")))
10192          (to-newsgroup
10193           (cond
10194            ((null split-name)
10195             (gnus-completing-read default prom
10196                                   gnus-active-hashtb
10197                                   'gnus-valid-move-group-p
10198                                   nil prefix
10199                                   'gnus-group-history))
10200            ((= 1 (length split-name))
10201             (gnus-completing-read (car split-name) prom
10202                                   gnus-active-hashtb
10203                                   'gnus-valid-move-group-p
10204                                   nil nil
10205                                   'gnus-group-history))
10206            (t
10207             (gnus-completing-read nil prom
10208                                   (mapcar (lambda (el) (list el))
10209                                           (nreverse split-name))
10210                                   nil nil nil
10211                                   'gnus-group-history))))
10212          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10213     (when to-newsgroup
10214       (if (or (string= to-newsgroup "")
10215               (string= to-newsgroup prefix))
10216           (setq to-newsgroup default))
10217       (unless to-newsgroup
10218         (error "No group name entered"))
10219       (or (gnus-active to-newsgroup)
10220           (gnus-activate-group to-newsgroup nil nil to-method)
10221           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10222                                      to-newsgroup))
10223               (or (and (gnus-request-create-group to-newsgroup to-method)
10224                        (gnus-activate-group
10225                         to-newsgroup nil nil to-method)
10226                        (gnus-subscribe-group to-newsgroup))
10227                   (error "Couldn't create group %s" to-newsgroup)))
10228           (error "No such group: %s" to-newsgroup)))
10229     to-newsgroup))
10230
10231 (defun gnus-summary-save-parts (type dir n &optional reverse)
10232   "Save parts matching TYPE to DIR.
10233 If REVERSE, save parts that do not match TYPE."
10234   (interactive
10235    (list (read-string "Save parts of type: "
10236                       (or (car gnus-summary-save-parts-type-history)
10237                           gnus-summary-save-parts-default-mime)
10238                       'gnus-summary-save-parts-type-history)
10239          (setq gnus-summary-save-parts-last-directory
10240                (read-file-name "Save to directory: "
10241                                gnus-summary-save-parts-last-directory
10242                                nil t))
10243          current-prefix-arg))
10244   (gnus-summary-iterate n
10245     (let ((gnus-display-mime-function nil)
10246           (gnus-inhibit-treatment t))
10247       (gnus-summary-select-article))
10248     (save-excursion
10249       (set-buffer gnus-article-buffer)
10250       (let ((handles (or gnus-article-mime-handles
10251                          (mm-dissect-buffer) (mm-uu-dissect))))
10252         (when handles
10253           (gnus-summary-save-parts-1 type dir handles reverse)
10254           (unless gnus-article-mime-handles ;; Don't destroy this case.
10255             (mm-destroy-parts handles)))))))
10256
10257 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10258   (if (stringp (car handle))
10259       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10260               (cdr handle))
10261     (when (if reverse
10262               (not (string-match type (mm-handle-media-type handle)))
10263             (string-match type (mm-handle-media-type handle)))
10264       (let ((file (expand-file-name
10265                    (file-name-nondirectory
10266                     (or
10267                      (mail-content-type-get
10268                       (mm-handle-disposition handle) 'filename)
10269                      (concat gnus-newsgroup-name
10270                              "." (number-to-string
10271                                   (cdr gnus-article-current)))))
10272                    dir)))
10273         (unless (file-exists-p file)
10274           (mm-save-part-to-file handle file))))))
10275
10276 ;; Summary extract commands
10277
10278 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10279   (let ((buffer-read-only nil)
10280         (article (gnus-summary-article-number))
10281         after-article b e)
10282     (unless (gnus-summary-goto-subject article)
10283       (error "No such article: %d" article))
10284     (gnus-summary-position-point)
10285     ;; If all commands are to be bunched up on one line, we collect
10286     ;; them here.
10287     (unless gnus-view-pseudos-separately
10288       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10289             files action)
10290         (while ps
10291           (setq action (cdr (assq 'action (car ps))))
10292           (setq files (list (cdr (assq 'name (car ps)))))
10293           (while (and ps (cdr ps)
10294                       (string= (or action "1")
10295                                (or (cdr (assq 'action (cadr ps))) "2")))
10296             (push (cdr (assq 'name (cadr ps))) files)
10297             (setcdr ps (cddr ps)))
10298           (when files
10299             (when (not (string-match "%s" action))
10300               (push " " files))
10301             (push " " files)
10302             (when (assq 'execute (car ps))
10303               (setcdr (assq 'execute (car ps))
10304                       (funcall (if (string-match "%s" action)
10305                                    'format 'concat)
10306                                action
10307                                (mapconcat
10308                                 (lambda (f)
10309                                   (if (equal f " ")
10310                                       f
10311                                     (mm-quote-arg f)))
10312                                 files " ")))))
10313           (setq ps (cdr ps)))))
10314     (if (and gnus-view-pseudos (not not-view))
10315         (while pslist
10316           (when (assq 'execute (car pslist))
10317             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10318                                   (eq gnus-view-pseudos 'not-confirm)))
10319           (setq pslist (cdr pslist)))
10320       (save-excursion
10321         (while pslist
10322           (setq after-article (or (cdr (assq 'article (car pslist)))
10323                                   (gnus-summary-article-number)))
10324           (gnus-summary-goto-subject after-article)
10325           (forward-line 1)
10326           (setq b (point))
10327           (insert "    " (file-name-nondirectory
10328                           (cdr (assq 'name (car pslist))))
10329                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10330           (setq e (point))
10331           (forward-line -1)             ; back to `b'
10332           (gnus-add-text-properties
10333            b (1- e) (list 'gnus-number gnus-reffed-article-number
10334                           gnus-mouse-face-prop gnus-mouse-face))
10335           (gnus-data-enter
10336            after-article gnus-reffed-article-number
10337            gnus-unread-mark b (car pslist) 0 (- e b))
10338           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10339           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10340           (setq pslist (cdr pslist)))))))
10341
10342 (defun gnus-pseudos< (p1 p2)
10343   (let ((c1 (cdr (assq 'action p1)))
10344         (c2 (cdr (assq 'action p2))))
10345     (and c1 c2 (string< c1 c2))))
10346
10347 (defun gnus-request-pseudo-article (props)
10348   (cond ((assq 'execute props)
10349          (gnus-execute-command (cdr (assq 'execute props)))))
10350   (let ((gnus-current-article (gnus-summary-article-number)))
10351     (gnus-run-hooks 'gnus-mark-article-hook)))
10352
10353 (defun gnus-execute-command (command &optional automatic)
10354   (save-excursion
10355     (gnus-article-setup-buffer)
10356     (set-buffer gnus-article-buffer)
10357     (setq buffer-read-only nil)
10358     (let ((command (if automatic command
10359                      (read-string "Command: " (cons command 0)))))
10360       (erase-buffer)
10361       (insert "$ " command "\n\n")
10362       (if gnus-view-pseudo-asynchronously
10363           (start-process "gnus-execute" (current-buffer) shell-file-name
10364                          shell-command-switch command)
10365         (call-process shell-file-name nil t nil
10366                       shell-command-switch command)))))
10367
10368 ;; Summary kill commands.
10369
10370 (defun gnus-summary-edit-global-kill (article)
10371   "Edit the \"global\" kill file."
10372   (interactive (list (gnus-summary-article-number)))
10373   (gnus-group-edit-global-kill article))
10374
10375 (defun gnus-summary-edit-local-kill ()
10376   "Edit a local kill file applied to the current newsgroup."
10377   (interactive)
10378   (setq gnus-current-headers (gnus-summary-article-header))
10379   (gnus-group-edit-local-kill
10380    (gnus-summary-article-number) gnus-newsgroup-name))
10381
10382 ;;; Header reading.
10383
10384 (defun gnus-read-header (id &optional header)
10385   "Read the headers of article ID and enter them into the Gnus system."
10386   (let ((group gnus-newsgroup-name)
10387         (gnus-override-method
10388          (or
10389           gnus-override-method
10390           (and (gnus-news-group-p gnus-newsgroup-name)
10391                (car (gnus-refer-article-methods)))))
10392         where)
10393     ;; First we check to see whether the header in question is already
10394     ;; fetched.
10395     (if (stringp id)
10396         ;; This is a Message-ID.
10397         (setq header (or header (gnus-id-to-header id)))
10398       ;; This is an article number.
10399       (setq header (or header (gnus-summary-article-header id))))
10400     (if (and header
10401              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10402         ;; We have found the header.
10403         header
10404       ;; If this is a sparse article, we have to nix out its
10405       ;; previous entry in the thread hashtb.
10406       (when (and header
10407                  (gnus-summary-article-sparse-p (mail-header-number header)))
10408         (let* ((parent (gnus-parent-id (mail-header-references header)))
10409                (thread (and parent (gnus-id-to-thread parent))))
10410           (when thread
10411             (delq (assq header thread) thread))))
10412       ;; We have to really fetch the header to this article.
10413       (save-excursion
10414         (set-buffer nntp-server-buffer)
10415         (when (setq where (gnus-request-head id group))
10416           (nnheader-fold-continuation-lines)
10417           (goto-char (point-max))
10418           (insert ".\n")
10419           (goto-char (point-min))
10420           (insert "211 ")
10421           (princ (cond
10422                   ((numberp id) id)
10423                   ((cdr where) (cdr where))
10424                   (header (mail-header-number header))
10425                   (t gnus-reffed-article-number))
10426                  (current-buffer))
10427           (insert " Article retrieved.\n"))
10428         (if (or (not where)
10429                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10430             ()                          ; Malformed head.
10431           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10432             (when (and (stringp id)
10433                        (not (string= (gnus-group-real-name group)
10434                                      (car where))))
10435               ;; If we fetched by Message-ID and the article came
10436               ;; from a different group, we fudge some bogus article
10437               ;; numbers for this article.
10438               (mail-header-set-number header gnus-reffed-article-number))
10439             (save-excursion
10440               (set-buffer gnus-summary-buffer)
10441               (decf gnus-reffed-article-number)
10442               (gnus-remove-header (mail-header-number header))
10443               (push header gnus-newsgroup-headers)
10444               (setq gnus-current-headers header)
10445               (push (mail-header-number header) gnus-newsgroup-limit)))
10446           header)))))
10447
10448 (defun gnus-remove-header (number)
10449   "Remove header NUMBER from `gnus-newsgroup-headers'."
10450   (if (and gnus-newsgroup-headers
10451            (= number (mail-header-number (car gnus-newsgroup-headers))))
10452       (pop gnus-newsgroup-headers)
10453     (let ((headers gnus-newsgroup-headers))
10454       (while (and (cdr headers)
10455                   (not (= number (mail-header-number (cadr headers)))))
10456         (pop headers))
10457       (when (cdr headers)
10458         (setcdr headers (cddr headers))))))
10459
10460 ;;;
10461 ;;; summary highlights
10462 ;;;
10463
10464 (defun gnus-highlight-selected-summary ()
10465   "Highlight selected article in summary buffer."
10466   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10467   (when gnus-summary-selected-face
10468     (save-excursion
10469       (let* ((beg (progn (beginning-of-line) (point)))
10470              (end (progn (end-of-line) (point)))
10471              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10472              (from (if (get-text-property beg gnus-mouse-face-prop)
10473                        beg
10474                      (or (next-single-property-change
10475                           beg gnus-mouse-face-prop nil end)
10476                          beg)))
10477              (to
10478               (if (= from end)
10479                   (- from 2)
10480                 (or (next-single-property-change
10481                      from gnus-mouse-face-prop nil end)
10482                     end))))
10483         ;; If no mouse-face prop on line we will have to = from = end,
10484         ;; so we highlight the entire line instead.
10485         (when (= (+ to 2) from)
10486           (setq from beg)
10487           (setq to end))
10488         (if gnus-newsgroup-selected-overlay
10489             ;; Move old overlay.
10490             (gnus-move-overlay
10491              gnus-newsgroup-selected-overlay from to (current-buffer))
10492           ;; Create new overlay.
10493           (gnus-overlay-put
10494            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10495            'face gnus-summary-selected-face))))))
10496
10497 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10498 (defun gnus-summary-highlight-line ()
10499   "Highlight current line according to `gnus-summary-highlight'."
10500   (let* ((list gnus-summary-highlight)
10501          (p (point))
10502          (end (progn (end-of-line) (point)))
10503          ;; now find out where the line starts and leave point there.
10504          (beg (progn (beginning-of-line) (point)))
10505          (article (gnus-summary-article-number))
10506          (score (or (cdr (assq (or article gnus-current-article)
10507                                gnus-newsgroup-scored))
10508                     gnus-summary-default-score 0))
10509          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10510          (inhibit-read-only t))
10511     ;; Eval the cars of the lists until we find a match.
10512     (let ((default gnus-summary-default-score)
10513           (default-high gnus-summary-default-high-score)
10514           (default-low gnus-summary-default-low-score))
10515       (while (and list
10516                   (not (eval (caar list))))
10517         (setq list (cdr list))))
10518     (let ((face (cdar list)))
10519       (unless (eq face (get-text-property beg 'face))
10520         (gnus-put-text-property-excluding-characters-with-faces
10521          beg end 'face
10522          (setq face (if (boundp face) (symbol-value face) face)))
10523         (when gnus-summary-highlight-line-function
10524           (funcall gnus-summary-highlight-line-function article face))))
10525     (goto-char p)))
10526
10527 (defun gnus-update-read-articles (group unread &optional compute)
10528   "Update the list of read articles in GROUP."
10529   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10530          (entry (gnus-gethash group gnus-newsrc-hashtb))
10531          (info (nth 2 entry))
10532          (prev 1)
10533          (unread (sort (copy-sequence unread) '<))
10534          read)
10535     (if (or (not info) (not active))
10536         ;; There is no info on this group if it was, in fact,
10537         ;; killed.  Gnus stores no information on killed groups, so
10538         ;; there's nothing to be done.
10539         ;; One could store the information somewhere temporarily,
10540         ;; perhaps...  Hmmm...
10541         ()
10542       ;; Remove any negative articles numbers.
10543       (while (and unread (< (car unread) 0))
10544         (setq unread (cdr unread)))
10545       ;; Remove any expired article numbers
10546       (while (and unread (< (car unread) (car active)))
10547         (setq unread (cdr unread)))
10548       ;; Compute the ranges of read articles by looking at the list of
10549       ;; unread articles.
10550       (while unread
10551         (when (/= (car unread) prev)
10552           (push (if (= prev (1- (car unread))) prev
10553                   (cons prev (1- (car unread))))
10554                 read))
10555         (setq prev (1+ (car unread)))
10556         (setq unread (cdr unread)))
10557       (when (<= prev (cdr active))
10558         (push (cons prev (cdr active)) read))
10559       (setq read (if (> (length read) 1) (nreverse read) read))
10560       (if compute
10561           read
10562         (save-excursion
10563           (let (setmarkundo)
10564             ;; Propagate the read marks to the backend.
10565             (when (gnus-check-backend-function 'request-set-mark group)
10566               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10567                     (add (gnus-remove-from-range read (gnus-info-read info))))
10568                 (when (or add del)
10569                   (unless (gnus-check-group group)
10570                     (error "Can't open server for %s" group))
10571                   (gnus-request-set-mark
10572                    group (delq nil (list (if add (list add 'add '(read)))
10573                                          (if del (list del 'del '(read))))))
10574                   (setq setmarkundo
10575                         `(gnus-request-set-mark
10576                           ,group
10577                           ',(delq nil (list
10578                                        (if del (list del 'add '(read)))
10579                                        (if add (list add 'del '(read))))))))))
10580             (set-buffer gnus-group-buffer)
10581             (gnus-undo-register
10582               `(progn
10583                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10584                  (gnus-info-set-read ',info ',(gnus-info-read info))
10585                  (gnus-get-unread-articles-in-group ',info
10586                                                     (gnus-active ,group))
10587                  (gnus-group-update-group ,group t)
10588                  ,setmarkundo))))
10589         ;; Enter this list into the group info.
10590         (gnus-info-set-read info read)
10591         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10592         (gnus-get-unread-articles-in-group info (gnus-active group))
10593         t))))
10594
10595 (defun gnus-offer-save-summaries ()
10596   "Offer to save all active summary buffers."
10597   (let (buffers)
10598     ;; Go through all buffers and find all summaries.
10599     (dolist (buffer (buffer-list))
10600       (when (and (setq buffer (buffer-name buffer))
10601                  (string-match "Summary" buffer)
10602                  (save-excursion
10603                    (set-buffer buffer)
10604                    ;; We check that this is, indeed, a summary buffer.
10605                    (and (eq major-mode 'gnus-summary-mode)
10606                         ;; Also make sure this isn't bogus.
10607                         gnus-newsgroup-prepared
10608                         ;; Also make sure that this isn't a
10609                         ;; dead summary buffer.
10610                         (not gnus-dead-summary-mode))))
10611         (push buffer buffers)))
10612     ;; Go through all these summary buffers and offer to save them.
10613     (when buffers
10614       (save-excursion
10615         (map-y-or-n-p
10616          "Update summary buffer %s? "
10617          (lambda (buf)
10618            (switch-to-buffer buf)
10619            (gnus-summary-exit))
10620          buffers)))))
10621
10622 (defun gnus-summary-setup-default-charset ()
10623   "Setup newsgroup default charset."
10624   (if (equal gnus-newsgroup-name "nndraft:drafts")
10625       (setq gnus-newsgroup-charset nil)
10626     (let* ((ignored-charsets
10627             (or gnus-newsgroup-ephemeral-ignored-charsets
10628                 (append
10629                  (and gnus-newsgroup-name
10630                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10631                  gnus-newsgroup-ignored-charsets))))
10632       (setq gnus-newsgroup-charset
10633             (or gnus-newsgroup-ephemeral-charset
10634                 (and gnus-newsgroup-name
10635                      (gnus-parameter-charset gnus-newsgroup-name))
10636                 gnus-default-charset))
10637       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10638            ignored-charsets))))
10639
10640 ;;;
10641 ;;; Mime Commands
10642 ;;;
10643
10644 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10645   "Display the current article buffer fully MIME-buttonized.
10646 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10647 treated as multipart/mixed."
10648   (interactive "P")
10649   (require 'gnus-art)
10650   (let ((gnus-unbuttonized-mime-types nil)
10651         (gnus-mime-display-multipart-as-mixed show-all-parts))
10652     (gnus-summary-show-article)))
10653
10654 (defun gnus-summary-repair-multipart (article)
10655   "Add a Content-Type header to a multipart article without one."
10656   (interactive (list (gnus-summary-article-number)))
10657   (gnus-with-article article
10658     (message-narrow-to-head)
10659     (message-remove-header "Mime-Version")
10660     (goto-char (point-max))
10661     (insert "Mime-Version: 1.0\n")
10662     (widen)
10663     (when (search-forward "\n--" nil t)
10664       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10665         (message-narrow-to-head)
10666         (message-remove-header "Content-Type")
10667         (goto-char (point-max))
10668         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10669                         separator))
10670         (widen))))
10671   (let (gnus-mark-article-hook)
10672     (gnus-summary-select-article t t nil article)))
10673
10674 (defun gnus-summary-toggle-display-buttonized ()
10675   "Toggle the buttonizing of the article buffer."
10676   (interactive)
10677   (require 'gnus-art)
10678   (if (setq gnus-inhibit-mime-unbuttonizing
10679             (not gnus-inhibit-mime-unbuttonizing))
10680       (let ((gnus-unbuttonized-mime-types nil))
10681         (gnus-summary-show-article))
10682     (gnus-summary-show-article)))
10683
10684 ;;;
10685 ;;; Generic summary marking commands
10686 ;;;
10687
10688 (defvar gnus-summary-marking-alist
10689   '((read gnus-del-mark "d")
10690     (unread gnus-unread-mark "u")
10691     (ticked gnus-ticked-mark "!")
10692     (dormant gnus-dormant-mark "?")
10693     (expirable gnus-expirable-mark "e"))
10694   "An alist of names/marks/keystrokes.")
10695
10696 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10697 (defvar gnus-summary-mark-map)
10698
10699 (defun gnus-summary-make-all-marking-commands ()
10700   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10701   (dolist (elem gnus-summary-marking-alist)
10702     (apply 'gnus-summary-make-marking-command elem)))
10703
10704 (defun gnus-summary-make-marking-command (name mark keystroke)
10705   (let ((map (make-sparse-keymap)))
10706     (define-key gnus-summary-generic-mark-map keystroke map)
10707     (dolist (lway `((next "next" next nil "n")
10708                     (next-unread "next unread" next t "N")
10709                     (prev "previous" prev nil "p")
10710                     (prev-unread "previous unread" prev t "P")
10711                     (nomove "" nil nil ,keystroke)))
10712       (let ((func (gnus-summary-make-marking-command-1
10713                    mark (car lway) lway name)))
10714         (setq func (eval func))
10715         (define-key map (nth 4 lway) func)))))
10716
10717 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10718   `(defun ,(intern
10719             (format "gnus-summary-put-mark-as-%s%s"
10720                     name (if (eq way 'nomove)
10721                              ""
10722                            (concat "-" (symbol-name way)))))
10723      (n)
10724      ,(format
10725        "Mark the current article as %s%s.
10726 If N, the prefix, then repeat N times.
10727 If N is negative, move in reverse order.
10728 The difference between N and the actual number of articles marked is
10729 returned."
10730        name (cadr lway))
10731      (interactive "p")
10732      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10733
10734 (defun gnus-summary-generic-mark (n mark move unread)
10735   "Mark N articles with MARK."
10736   (unless (eq major-mode 'gnus-summary-mode)
10737     (error "This command can only be used in the summary buffer"))
10738   (gnus-summary-show-thread)
10739   (let ((nummove
10740          (cond
10741           ((eq move 'next) 1)
10742           ((eq move 'prev) -1)
10743           (t 0))))
10744     (if (zerop nummove)
10745         (setq n 1)
10746       (when (< n 0)
10747         (setq n (abs n)
10748               nummove (* -1 nummove))))
10749     (while (and (> n 0)
10750                 (gnus-summary-mark-article nil mark)
10751                 (zerop (gnus-summary-next-subject nummove unread t)))
10752       (setq n (1- n)))
10753     (when (/= 0 n)
10754       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10755     (gnus-summary-recenter)
10756     (gnus-summary-position-point)
10757     (gnus-set-mode-line 'summary)
10758     n))
10759
10760 (defun gnus-summary-insert-articles (articles)
10761   (when (setq articles
10762               (gnus-set-difference articles
10763                                    (mapcar (lambda (h) (mail-header-number h))
10764                                            gnus-newsgroup-headers)))
10765     (setq gnus-newsgroup-headers
10766           (merge 'list
10767                  gnus-newsgroup-headers
10768                  (gnus-fetch-headers articles)
10769                  'gnus-article-sort-by-number))
10770     ;; Suppress duplicates?
10771     (when gnus-suppress-duplicates
10772       (gnus-dup-suppress-articles))
10773
10774     ;; We might want to build some more threads first.
10775     (when (and gnus-fetch-old-headers
10776                (eq gnus-headers-retrieved-by 'nov))
10777       (if (eq gnus-fetch-old-headers 'invisible)
10778           (gnus-build-all-threads)
10779         (gnus-build-old-threads)))
10780     ;; Let the Gnus agent mark articles as read.
10781     (when gnus-agent
10782       (gnus-agent-get-undownloaded-list))
10783     ;; Remove list identifiers from subject
10784     (when gnus-list-identifiers
10785       (gnus-summary-remove-list-identifiers))
10786     ;; First and last article in this newsgroup.
10787     (when gnus-newsgroup-headers
10788       (setq gnus-newsgroup-begin
10789             (mail-header-number (car gnus-newsgroup-headers))
10790             gnus-newsgroup-end
10791             (mail-header-number
10792              (gnus-last-element gnus-newsgroup-headers))))
10793     (when gnus-use-scoring
10794       (gnus-possibly-score-headers))))
10795
10796 (defun gnus-summary-insert-old-articles (&optional all)
10797   "Insert all old articles in this group.
10798 If ALL is non-nil, already read articles become readable.
10799 If ALL is a number, fetch this number of articles."
10800   (interactive "P")
10801   (prog1
10802       (let ((old (mapcar 'car gnus-newsgroup-data))
10803             (i (car gnus-newsgroup-active))
10804             older len)
10805         (while (<= i (cdr gnus-newsgroup-active))
10806           (or (memq i old) (push i older))
10807           (incf i))
10808         (setq len (length older))
10809         (cond
10810          ((null older) nil)
10811          ((numberp all)
10812           (if (< all len)
10813               (setq older (subseq older 0 all))))
10814          (all nil)
10815          (t
10816           (if (and (numberp gnus-large-newsgroup)
10817                    (> len gnus-large-newsgroup))
10818               (let ((input
10819                      (read-string
10820                       (format
10821                        "How many articles from %s (default %d): "
10822                        (gnus-limit-string
10823                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10824                        len))))
10825                 (unless (string-match "^[ \t]*$" input)
10826                   (setq all (string-to-number input))
10827                   (if (< all len)
10828                       (setq older (subseq older 0 all))))))))
10829         (if (not older)
10830             (message "No old news.")
10831           (let ((gnus-fetch-old-headers t))
10832             (gnus-summary-insert-articles older))
10833           (gnus-summary-limit (gnus-union older old))))
10834     (gnus-summary-position-point)))
10835
10836 (defun gnus-summary-insert-new-articles ()
10837   "Insert all new articles in this group."
10838   (interactive)
10839   (prog1
10840       (let ((old (mapcar 'car gnus-newsgroup-data))
10841             (old-active gnus-newsgroup-active)
10842             (nnmail-fetched-sources (list t))
10843             i new)
10844         (setq gnus-newsgroup-active
10845               (gnus-activate-group gnus-newsgroup-name 'scan))
10846         (setq i (1+ (cdr old-active)))
10847         (while (<= i (cdr gnus-newsgroup-active))
10848           (push i new)
10849           (incf i))
10850         (if (not new)
10851             (message "No gnus is bad news.")
10852           (setq new (nreverse new))
10853           (gnus-summary-insert-articles new)
10854           (setq gnus-newsgroup-unreads
10855                 (append gnus-newsgroup-unreads new))
10856           (gnus-summary-limit (gnus-union old new))))
10857     (gnus-summary-position-point)))
10858
10859 (gnus-summary-make-all-marking-commands)
10860
10861 (gnus-ems-redefine)
10862
10863 (provide 'gnus-sum)
10864
10865 (run-hooks 'gnus-sum-load-hook)
10866
10867 ;;; gnus-sum.el ends here