* gnus-sum.el (t): New `W D' map.
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; 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 ;; Recursive :-(.
40 ;; (require 'gnus-art)
41 (require 'nnoo)
42 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
43 (autoload 'gnus-cache-write-active "gnus-cache")
44 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
45 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
46 (autoload 'mm-uu-dissect "mm-uu")
47
48 (defcustom gnus-kill-summary-on-exit t
49   "*If non-nil, kill the summary buffer when you exit from it.
50 If nil, the summary will become a \"*Dead Summary*\" buffer, and
51 it will be killed sometime later."
52   :group 'gnus-summary-exit
53   :type 'boolean)
54
55 (defcustom gnus-fetch-old-headers nil
56   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
57 If an unread article in the group refers to an older, already read (or
58 just marked as read) article, the old article will not normally be
59 displayed in the Summary buffer.  If this variable is non-nil, Gnus
60 will attempt to grab the headers to the old articles, and thereby
61 build complete threads.  If it has the value `some', only enough
62 headers to connect otherwise loose threads will be displayed.  This
63 variable can also be a number.  In that case, no more than that number
64 of old headers will be fetched.  If it has the value `invisible', all
65 old headers will be fetched, but none will be displayed.
66
67 The server has to support NOV for any of this to work."
68   :group 'gnus-thread
69   :type '(choice (const :tag "off" nil)
70                  (const some)
71                  number
72                  (sexp :menu-tag "other" t)))
73
74 (defcustom gnus-refer-thread-limit 200
75   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
76 If t, fetch all the available old headers."
77   :group 'gnus-thread
78   :type '(choice number
79                  (sexp :menu-tag "other" t)))
80
81 (defcustom gnus-summary-make-false-root 'adopt
82   "*nil means that Gnus won't gather loose threads.
83 If the root of a thread has expired or been read in a previous
84 session, the information necessary to build a complete thread has been
85 lost.  Instead of having many small sub-threads from this original thread
86 scattered all over the summary buffer, Gnus can gather them.
87
88 If non-nil, Gnus will try to gather all loose sub-threads from an
89 original thread into one large thread.
90
91 If this variable is non-nil, it should be one of `none', `adopt',
92 `dummy' or `empty'.
93
94 If this variable is `none', Gnus will not make a false root, but just
95 present the sub-threads after another.
96 If this variable is `dummy', Gnus will create a dummy root that will
97 have all the sub-threads as children.
98 If this variable is `adopt', Gnus will make one of the \"children\"
99 the parent and mark all the step-children as such.
100 If this variable is `empty', the \"children\" are printed with empty
101 subject fields.  (Or rather, they will be printed with a string
102 given by the `gnus-summary-same-subject' variable.)"
103   :group 'gnus-thread
104   :type '(choice (const :tag "off" nil)
105                  (const none)
106                  (const dummy)
107                  (const adopt)
108                  (const empty)))
109
110 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
111   "*A regexp to match subjects to be excluded from loose thread gathering.
112 As loose thread gathering is done on subjects only, that means that
113 there can be many false gatherings performed.  By rooting out certain
114 common subjects, gathering might become saner."
115   :group 'gnus-thread
116   :type 'regexp)
117
118 (defcustom gnus-summary-gather-subject-limit nil
119   "*Maximum length of subject comparisons when gathering loose threads.
120 Use nil to compare full subjects.  Setting this variable to a low
121 number will help gather threads that have been corrupted by
122 newsreaders chopping off subject lines, but it might also mean that
123 unrelated articles that have subject that happen to begin with the
124 same few characters will be incorrectly gathered.
125
126 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
127 comparing subjects."
128   :group 'gnus-thread
129   :type '(choice (const :tag "off" nil)
130                  (const fuzzy)
131                  (sexp :menu-tag "on" t)))
132
133 (defcustom gnus-simplify-subject-functions nil
134   "List of functions taking a string argument that simplify subjects.
135 The functions are applied recursively.
136
137 Useful functions to put in this list include: `gnus-simplify-subject-re',
138 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
139   :group 'gnus-thread
140   :type '(repeat function))
141
142 (defcustom gnus-simplify-ignored-prefixes nil
143   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  regexp))
147
148 (defcustom gnus-build-sparse-threads nil
149   "*If non-nil, fill in the gaps in threads.
150 If `some', only fill in the gaps that are needed to tie loose threads
151 together.  If `more', fill in all leaf nodes that Gnus can find.  If
152 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const some)
156                  (const more)
157                  (sexp :menu-tag "all" t)))
158
159 (defcustom gnus-summary-thread-gathering-function
160   'gnus-gather-threads-by-subject
161   "*Function used for gathering loose threads.
162 There are two pre-defined functions: `gnus-gather-threads-by-subject',
163 which only takes Subjects into consideration; and
164 `gnus-gather-threads-by-references', which compared the References
165 headers of the articles to find matches."
166   :group 'gnus-thread
167   :type '(radio (function-item gnus-gather-threads-by-subject)
168                 (function-item gnus-gather-threads-by-references)
169                 (function :tag "other")))
170
171 (defcustom gnus-summary-same-subject ""
172   "*String indicating that the current article has the same subject as the previous.
173 This variable will only be used if the value of
174 `gnus-summary-make-false-root' is `empty'."
175   :group 'gnus-summary-format
176   :type 'string)
177
178 (defcustom gnus-summary-goto-unread t
179   "*If t, many commands will go to the next unread article.
180 This applies to marking commands as well as other commands that
181 \"naturally\" select the next article, like, for instance, `SPC' at
182 the end of an article.
183
184 If nil, the marking commands do NOT go to the next unread article
185 (they go to the next article instead).  If `never', commands that
186 usually go to the next unread article, will go to the next article,
187 whether it is read or not."
188   :group 'gnus-summary-marks
189   :link '(custom-manual "(gnus)Setting Marks")
190   :type '(choice (const :tag "off" nil)
191                  (const never)
192                  (sexp :menu-tag "on" t)))
193
194 (defcustom gnus-summary-default-score 0
195   "*Default article score level.
196 All scores generated by the score files will be added to this score.
197 If this variable is nil, scoring will be disabled."
198   :group 'gnus-score-default
199   :type '(choice (const :tag "disable")
200                  integer))
201
202 (defcustom gnus-summary-default-high-score 0
203   "*Default threshold for a high scored article.
204 An article will be highlighted as high scored if its score is greater
205 than this score."
206   :group 'gnus-score-default
207   :type 'integer)
208
209 (defcustom gnus-summary-default-low-score 0
210   "*Default threshold for a low scored article.
211 An article will be highlighted as low scored if its score is smaller
212 than this score."
213   :group 'gnus-score-default
214   :type 'integer)
215
216 (defcustom gnus-summary-zcore-fuzz 0
217   "*Fuzziness factor for the zcore in the summary buffer.
218 Articles with scores closer than this to `gnus-summary-default-score'
219 will not be marked."
220   :group 'gnus-summary-format
221   :type 'integer)
222
223 (defcustom gnus-simplify-subject-fuzzy-regexp nil
224   "*Strings to be removed when doing fuzzy matches.
225 This can either be a regular expression or list of regular expressions
226 that will be removed from subject strings if fuzzy subject
227 simplification is selected."
228   :group 'gnus-thread
229   :type '(repeat regexp))
230
231 (defcustom gnus-show-threads t
232   "*If non-nil, display threads in summary mode."
233   :group 'gnus-thread
234   :type 'boolean)
235
236 (defcustom gnus-thread-hide-subtree nil
237   "*If non-nil, hide all threads initially.
238 If threads are hidden, you have to run the command
239 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
240 to expose hidden threads."
241   :group 'gnus-thread
242   :type 'boolean)
243
244 (defcustom gnus-thread-hide-killed t
245   "*If non-nil, hide killed threads automatically."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-ignore-subject t
250   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
251 If nil, articles that have different subjects from their parents will
252 start separate threads."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-operation-ignore-subject t
257   "*If non-nil, subjects will be ignored when doing thread commands.
258 This affects commands like `gnus-summary-kill-thread' and
259 `gnus-summary-lower-thread'.
260
261 If this variable is nil, articles in the same thread with different
262 subjects will not be included in the operation in question.  If this
263 variable is `fuzzy', only articles that have subjects that are fuzzily
264 equal will be included."
265   :group 'gnus-thread
266   :type '(choice (const :tag "off" nil)
267                  (const fuzzy)
268                  (sexp :tag "on" t)))
269
270 (defcustom gnus-thread-indent-level 4
271   "*Number that says how much each sub-thread should be indented."
272   :group 'gnus-thread
273   :type 'integer)
274
275 (defcustom gnus-auto-extend-newsgroup t
276   "*If non-nil, extend newsgroup forward and backward when requested."
277   :group 'gnus-summary-choose
278   :type 'boolean)
279
280 (defcustom gnus-auto-select-first t
281   "*If non-nil, select the article under point.
282 Which article this is is controlled by the `gnus-auto-select-subject'
283 variable.
284
285 If you want to prevent automatic selection of articles in some
286 newsgroups, set the variable to nil in `gnus-select-group-hook'."
287   :group 'gnus-group-select
288   :type '(choice (const :tag "none" nil)
289                  (sexp :menu-tag "first" t)))
290
291 (defcustom gnus-auto-select-subject 'unread
292   "*Says what subject to place under point when entering a group.
293
294 This variable can either be the symbols `first' (place point on the
295 first subject), `unread' (place point on the subject line of the first
296 unread article), `best' (place point on the subject line of the
297 higest-scored article), `unseen' (place point on the subject line of
298 the first unseen article), or a function to be called to place point on
299 some subject line.."
300   :group 'gnus-group-select
301   :type '(choice (const best)
302                  (const unread)
303                  (const first)
304                  (const unseen)))
305
306 (defcustom gnus-auto-select-next t
307   "*If non-nil, offer to go to the next group from the end of the previous.
308 If the value is t and the next newsgroup is empty, Gnus will exit
309 summary mode and go back to group mode.  If the value is neither nil
310 nor t, Gnus will select the following unread newsgroup.  In
311 particular, if the value is the symbol `quietly', the next unread
312 newsgroup will be selected without any confirmation, and if it is
313 `almost-quietly', the next group will be selected without any
314 confirmation if you are located on the last article in the group.
315 Finally, if this variable is `slightly-quietly', the `Z n' command
316 will go to the next group without confirmation."
317   :group 'gnus-summary-maneuvering
318   :type '(choice (const :tag "off" nil)
319                  (const quietly)
320                  (const almost-quietly)
321                  (const slightly-quietly)
322                  (sexp :menu-tag "on" t)))
323
324 (defcustom gnus-auto-select-same nil
325   "*If non-nil, select the next article with the same subject.
326 If there are no more articles with the same subject, go to
327 the first unread article."
328   :group 'gnus-summary-maneuvering
329   :type 'boolean)
330
331 (defcustom gnus-summary-check-current nil
332   "*If non-nil, consider the current article when moving.
333 The \"unread\" movement commands will stay on the same line if the
334 current article is unread."
335   :group 'gnus-summary-maneuvering
336   :type 'boolean)
337
338 (defcustom gnus-auto-center-summary t
339   "*If non-nil, always center the current summary buffer.
340 In particular, if `vertical' do only vertical recentering.  If non-nil
341 and non-`vertical', do both horizontal and vertical recentering."
342   :group 'gnus-summary-maneuvering
343   :type '(choice (const :tag "none" nil)
344                  (const vertical)
345                  (integer :tag "height")
346                  (sexp :menu-tag "both" t)))
347
348 (defcustom gnus-show-all-headers nil
349   "*If non-nil, don't hide any headers."
350   :group 'gnus-article-hiding
351   :group 'gnus-article-headers
352   :type 'boolean)
353
354 (defcustom gnus-summary-ignore-duplicates nil
355   "*If non-nil, ignore articles with identical Message-ID headers."
356   :group 'gnus-summary
357   :type 'boolean)
358
359 (defcustom gnus-single-article-buffer t
360   "*If non-nil, display all articles in the same buffer.
361 If nil, each group will get its own article buffer."
362   :group 'gnus-article-various
363   :type 'boolean)
364
365 (defcustom gnus-break-pages t
366   "*If non-nil, do page breaking on articles.
367 The page delimiter is specified by the `gnus-page-delimiter'
368 variable."
369   :group 'gnus-article-various
370   :type 'boolean)
371
372 (defcustom gnus-move-split-methods nil
373   "*Variable used to suggest where articles are to be moved to.
374 It uses the same syntax as the `gnus-split-methods' variable.
375 However, whereas `gnus-split-methods' specifies file names as targets,
376 this variable specifies group names."
377   :group 'gnus-summary-mail
378   :type '(repeat (choice (list :value (fun) function)
379                          (cons :value ("" "") regexp (repeat string))
380                          (sexp :value nil))))
381
382 (defcustom gnus-unread-mark ?           ;Whitespace
383   "*Mark used for unread articles."
384   :group 'gnus-summary-marks
385   :type 'character)
386
387 (defcustom gnus-ticked-mark ?!
388   "*Mark used for ticked articles."
389   :group 'gnus-summary-marks
390   :type 'character)
391
392 (defcustom gnus-dormant-mark ??
393   "*Mark used for dormant articles."
394   :group 'gnus-summary-marks
395   :type 'character)
396
397 (defcustom gnus-del-mark ?r
398   "*Mark used for del'd articles."
399   :group 'gnus-summary-marks
400   :type 'character)
401
402 (defcustom gnus-read-mark ?R
403   "*Mark used for read articles."
404   :group 'gnus-summary-marks
405   :type 'character)
406
407 (defcustom gnus-expirable-mark ?E
408   "*Mark used for expirable articles."
409   :group 'gnus-summary-marks
410   :type 'character)
411
412 (defcustom gnus-killed-mark ?K
413   "*Mark used for killed articles."
414   :group 'gnus-summary-marks
415   :type 'character)
416
417 (defcustom gnus-souped-mark ?F
418   "*Mark used for souped articles."
419   :group 'gnus-summary-marks
420   :type 'character)
421
422 (defcustom gnus-kill-file-mark ?X
423   "*Mark used for articles killed by kill files."
424   :group 'gnus-summary-marks
425   :type 'character)
426
427 (defcustom gnus-low-score-mark ?Y
428   "*Mark used for articles with a low score."
429   :group 'gnus-summary-marks
430   :type 'character)
431
432 (defcustom gnus-catchup-mark ?C
433   "*Mark used for articles that are caught up."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-replied-mark ?A
438   "*Mark used for articles that have been replied to."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-forwarded-mark ?F
443   "*Mark used for articles that have been forwarded."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-recent-mark ?N
448   "*Mark used for articles that are recent."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-cached-mark ?*
453   "*Mark used for articles that are in the cache."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-saved-mark ?S
458   "*Mark used for articles that have been saved."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-unseen-mark ?.
463   "*Mark used for articles that haven't been seen."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-no-mark ?               ;Whitespace
468   "*Mark used for articles that have no other secondary mark."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-ancient-mark ?O
473   "*Mark used for ancient articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-sparse-mark ?Q
478   "*Mark used for sparsely reffed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-canceled-mark ?G
483   "*Mark used for canceled articles."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-duplicate-mark ?M
488   "*Mark used for duplicate articles."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-undownloaded-mark ?@
493   "*Mark used for articles that weren't downloaded."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-downloadable-mark ?%
498   "*Mark used for articles that are to be downloaded."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-unsendable-mark ?=
503   "*Mark used for articles that won't be sent."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-score-over-mark ?+
508   "*Score mark used for articles with high scores."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-score-below-mark ?-
513   "*Score mark used for articles with low scores."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-empty-thread-mark ?     ;Whitespace
518   "*There is no thread under the article."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-not-empty-thread-mark ?=
523   "*There is a thread under the article."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-view-pseudo-asynchronously nil
528   "*If non-nil, Gnus will view pseudo-articles asynchronously."
529   :group 'gnus-extract-view
530   :type 'boolean)
531
532 (defcustom gnus-auto-expirable-marks
533   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
534         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
535         gnus-souped-mark gnus-duplicate-mark)
536   "*The list of marks converted into expiration if a group is auto-expirable."
537   :version "21.1"
538   :group 'gnus-summary
539   :type '(repeat character))
540
541 (defcustom gnus-inhibit-user-auto-expire t
542   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
543   :version "21.1"
544   :group 'gnus-summary
545   :type 'boolean)
546
547 (defcustom gnus-view-pseudos nil
548   "*If `automatic', pseudo-articles will be viewed automatically.
549 If `not-confirm', pseudos will be viewed automatically, and the user
550 will not be asked to confirm the command."
551   :group 'gnus-extract-view
552   :type '(choice (const :tag "off" nil)
553                  (const automatic)
554                  (const not-confirm)))
555
556 (defcustom gnus-view-pseudos-separately t
557   "*If non-nil, one pseudo-article will be created for each file to be viewed.
558 If nil, all files that use the same viewing command will be given as a
559 list of parameters to that command."
560   :group 'gnus-extract-view
561   :type 'boolean)
562
563 (defcustom gnus-insert-pseudo-articles t
564   "*If non-nil, insert pseudo-articles when decoding articles."
565   :group 'gnus-extract-view
566   :type 'boolean)
567
568 (defcustom gnus-summary-dummy-line-format
569   "  %(:                          :%) %S\n"
570   "*The format specification for the dummy roots in the summary buffer.
571 It works along the same lines as a normal formatting string,
572 with some simple extensions.
573
574 %S  The subject"
575   :group 'gnus-threading
576   :type 'string)
577
578 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
579   "*The format specification for the summary mode line.
580 It works along the same lines as a normal formatting string,
581 with some simple extensions:
582
583 %G  Group name
584 %p  Unprefixed group name
585 %A  Current article number
586 %z  Current article score
587 %V  Gnus version
588 %U  Number of unread articles in the group
589 %e  Number of unselected articles in the group
590 %Z  A string with unread/unselected article counts
591 %g  Shortish group name
592 %S  Subject of the current article
593 %u  User-defined spec
594 %s  Current score file name
595 %d  Number of dormant articles
596 %r  Number of articles that have been marked as read in this session
597 %E  Number of articles expunged by the score files"
598   :group 'gnus-summary-format
599   :type 'string)
600
601 (defcustom gnus-list-identifiers nil
602   "Regexp that matches list identifiers to be removed from subject.
603 This can also be a list of regexps."
604   :version "21.1"
605   :group 'gnus-summary-format
606   :group 'gnus-article-hiding
607   :type '(choice (const :tag "none" nil)
608                  (regexp :value ".*")
609                  (repeat :value (".*") regexp)))
610
611 (defcustom gnus-summary-mark-below 0
612   "*Mark all articles with a score below this variable as read.
613 This variable is local to each summary buffer and usually set by the
614 score file."
615   :group 'gnus-score-default
616   :type 'integer)
617
618 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
619   "*List of functions used for sorting articles in the summary buffer.
620
621 Each function takes two articles and returns non-nil if the first
622 article should be sorted before the other.  If you use more than one
623 function, the primary sort function should be the last.  You should
624 probably always include `gnus-article-sort-by-number' in the list of
625 sorting functions -- preferably first.  Also note that sorting by date
626 is often much slower than sorting by number, and the sorting order is
627 very similar.  (Sorting by date means sorting by the time the message
628 was sent, sorting by number means sorting by arrival time.)
629
630 Ready-made functions include `gnus-article-sort-by-number',
631 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
632 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
633
634 When threading is turned on, the variable `gnus-thread-sort-functions'
635 controls how articles are sorted."
636   :group 'gnus-summary-sort
637   :type '(repeat (choice (function-item gnus-article-sort-by-number)
638                          (function-item gnus-article-sort-by-author)
639                          (function-item gnus-article-sort-by-subject)
640                          (function-item gnus-article-sort-by-date)
641                          (function-item gnus-article-sort-by-score)
642                          (function :tag "other"))))
643
644 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
645   "*List of functions used for sorting threads in the summary buffer.
646 By default, threads are sorted by article number.
647
648 Each function takes two threads and returns non-nil if the first
649 thread should be sorted before the other.  If you use more than one
650 function, the primary sort function should be the last.  You should
651 probably always include `gnus-thread-sort-by-number' in the list of
652 sorting functions -- preferably first.  Also note that sorting by date
653 is often much slower than sorting by number, and the sorting order is
654 very similar.  (Sorting by date means sorting by the time the message
655 was sent, sorting by number means sorting by arrival time.)
656
657 Ready-made functions include `gnus-thread-sort-by-number',
658 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
659 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
660 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
661
662 When threading is turned off, the variable
663 `gnus-article-sort-functions' controls how articles are sorted."
664   :group 'gnus-summary-sort
665   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
666                          (function-item gnus-thread-sort-by-author)
667                          (function-item gnus-thread-sort-by-subject)
668                          (function-item gnus-thread-sort-by-date)
669                          (function-item gnus-thread-sort-by-score)
670                          (function-item gnus-thread-sort-by-total-score)
671                          (function :tag "other"))))
672
673 (defcustom gnus-thread-score-function '+
674   "*Function used for calculating the total score of a thread.
675
676 The function is called with the scores of the article and each
677 subthread and should then return the score of the thread.
678
679 Some functions you can use are `+', `max', or `min'."
680   :group 'gnus-summary-sort
681   :type 'function)
682
683 (defcustom gnus-summary-expunge-below nil
684   "All articles that have a score less than this variable will be expunged.
685 This variable is local to the summary buffers."
686   :group 'gnus-score-default
687   :type '(choice (const :tag "off" nil)
688                  integer))
689
690 (defcustom gnus-thread-expunge-below nil
691   "All threads that have a total score less than this variable will be expunged.
692 See `gnus-thread-score-function' for en explanation of what a
693 \"thread score\" is.
694
695 This variable is local to the summary buffers."
696   :group 'gnus-threading
697   :group 'gnus-score-default
698   :type '(choice (const :tag "off" nil)
699                  integer))
700
701 (defcustom gnus-summary-mode-hook nil
702   "*A hook for Gnus summary mode.
703 This hook is run before any variables are set in the summary buffer."
704   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
705   :group 'gnus-summary-various
706   :type 'hook)
707
708 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
709 (when (featurep 'xemacs)
710   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
711   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
712   (add-hook 'gnus-summary-mode-hook
713             'gnus-xmas-switch-horizontal-scrollbar-off))
714
715 (defcustom gnus-summary-menu-hook nil
716   "*Hook run after the creation of the summary mode menu."
717   :group 'gnus-summary-visual
718   :type 'hook)
719
720 (defcustom gnus-summary-exit-hook nil
721   "*A hook called on exit from the summary buffer.
722 It will be called with point in the group buffer."
723   :group 'gnus-summary-exit
724   :type 'hook)
725
726 (defcustom gnus-summary-prepare-hook nil
727   "*A hook called after the summary buffer has been generated.
728 If you want to modify the summary buffer, you can use this hook."
729   :group 'gnus-summary-various
730   :type 'hook)
731
732 (defcustom gnus-summary-prepared-hook nil
733   "*A hook called as the last thing after the summary buffer has been generated."
734   :group 'gnus-summary-various
735   :type 'hook)
736
737 (defcustom gnus-summary-generate-hook nil
738   "*A hook run just before generating the summary buffer.
739 This hook is commonly used to customize threading variables and the
740 like."
741   :group 'gnus-summary-various
742   :type 'hook)
743
744 (defcustom gnus-select-group-hook nil
745   "*A hook called when a newsgroup is selected.
746
747 If you'd like to simplify subjects like the
748 `gnus-summary-next-same-subject' command does, you can use the
749 following hook:
750
751  (setq gnus-select-group-hook
752       (list
753         (lambda ()
754           (mapcar (lambda (header)
755                      (mail-header-set-subject
756                       header
757                       (gnus-simplify-subject
758                        (mail-header-subject header) 're-only)))
759                   gnus-newsgroup-headers))))"
760   :group 'gnus-group-select
761   :type 'hook)
762
763 (defcustom gnus-select-article-hook nil
764   "*A hook called when an article is selected."
765   :group 'gnus-summary-choose
766   :type 'hook)
767
768 (defcustom gnus-visual-mark-article-hook
769   (list 'gnus-highlight-selected-summary)
770   "*Hook run after selecting an article in the summary buffer.
771 It is meant to be used for highlighting the article in some way.  It
772 is not run if `gnus-visual' is nil."
773   :group 'gnus-summary-visual
774   :type 'hook)
775
776 (defcustom gnus-parse-headers-hook nil
777   "*A hook called before parsing the headers."
778   :group 'gnus-various
779   :type 'hook)
780
781 (defcustom gnus-exit-group-hook nil
782   "*A hook called when exiting summary mode.
783 This hook is not called from the non-updating exit commands like `Q'."
784   :group 'gnus-various
785   :type 'hook)
786
787 (defcustom gnus-summary-update-hook
788   (list 'gnus-summary-highlight-line)
789   "*A hook called when a summary line is changed.
790 The hook will not be called if `gnus-visual' is nil.
791
792 The default function `gnus-summary-highlight-line' will
793 highlight the line according to the `gnus-summary-highlight'
794 variable."
795   :group 'gnus-summary-visual
796   :type 'hook)
797
798 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
799   "*A hook called when an article is selected for the first time.
800 The hook is intended to mark an article as read (or unread)
801 automatically when it is selected."
802   :group 'gnus-summary-choose
803   :type 'hook)
804
805 (defcustom gnus-group-no-more-groups-hook nil
806   "*A hook run when returning to group mode having no more (unread) groups."
807   :group 'gnus-group-select
808   :type 'hook)
809
810 (defcustom gnus-ps-print-hook nil
811   "*A hook run before ps-printing something from Gnus."
812   :group 'gnus-summary
813   :type 'hook)
814
815 (defcustom gnus-summary-display-arrow
816   (and (fboundp 'display-graphic-p)
817        (display-graphic-p))
818   "*If non-nil, display an arrow highlighting the current article."
819   :version "21.1"
820   :group 'gnus-summary
821   :type 'boolean)
822
823 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
824   "Face used for highlighting the current article in the summary buffer."
825   :group 'gnus-summary-visual
826   :type 'face)
827
828 (defcustom gnus-summary-highlight
829   '(((= mark gnus-canceled-mark)
830      . gnus-summary-cancelled-face)
831     ((and (> score default-high)
832           (or (= mark gnus-dormant-mark)
833               (= mark gnus-ticked-mark)))
834      . gnus-summary-high-ticked-face)
835     ((and (< score default-low)
836           (or (= mark gnus-dormant-mark)
837               (= mark gnus-ticked-mark)))
838      . gnus-summary-low-ticked-face)
839     ((or (= mark gnus-dormant-mark)
840          (= mark gnus-ticked-mark))
841      . gnus-summary-normal-ticked-face)
842     ((and (> score default-high) (= mark gnus-ancient-mark))
843      . gnus-summary-high-ancient-face)
844     ((and (< score default-low) (= mark gnus-ancient-mark))
845      . gnus-summary-low-ancient-face)
846     ((= mark gnus-ancient-mark)
847      . gnus-summary-normal-ancient-face)
848     ((and (> score default-high) (= mark gnus-unread-mark))
849      . gnus-summary-high-unread-face)
850     ((and (< score default-low) (= mark gnus-unread-mark))
851      . gnus-summary-low-unread-face)
852     ((= mark gnus-unread-mark)
853      . gnus-summary-normal-unread-face)
854     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
855                                                   gnus-undownloaded-mark)))
856      . gnus-summary-high-unread-face)
857     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
858                                                  gnus-undownloaded-mark)))
859      . gnus-summary-low-unread-face)
860     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
861           (memq article gnus-newsgroup-unreads))
862      . gnus-summary-normal-unread-face)
863     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
864      . gnus-summary-normal-read-face)
865     ((> score default-high)
866      . gnus-summary-high-read-face)
867     ((< score default-low)
868      . gnus-summary-low-read-face)
869     (t
870      . gnus-summary-normal-read-face))
871   "*Controls the highlighting of summary buffer lines.
872
873 A list of (FORM . FACE) pairs.  When deciding how a a particular
874 summary line should be displayed, each form is evaluated.  The content
875 of the face field after the first true form is used.  You can change
876 how those summary lines are displayed, by editing the face field.
877
878 You can use the following variables in the FORM field.
879
880 score:        The article's score
881 default:      The default article score.
882 default-high: The default score for high scored articles.
883 default-low:  The default score for low scored articles.
884 below:        The score below which articles are automatically marked as read.
885 mark:         The articles mark."
886   :group 'gnus-summary-visual
887   :type '(repeat (cons (sexp :tag "Form" nil)
888                        face)))
889
890 (defcustom gnus-alter-header-function nil
891   "Function called to allow alteration of article header structures.
892 The function is called with one parameter, the article header vector,
893 which it may alter in any way.")
894
895 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
896   "Variable that says which function should be used to decode a string with encoded words.")
897
898 (defcustom gnus-extra-headers nil
899   "*Extra headers to parse."
900   :version "21.1"
901   :group 'gnus-summary
902   :type '(repeat symbol))
903
904 (defcustom gnus-ignored-from-addresses
905   (and user-mail-address (regexp-quote user-mail-address))
906   "*Regexp of From headers that may be suppressed in favor of To headers."
907   :version "21.1"
908   :group 'gnus-summary
909   :type 'regexp)
910
911 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
912   "List of charsets that should be ignored.
913 When these charsets are used in the \"charset\" parameter, the
914 default charset will be used instead."
915   :version "21.1"
916   :type '(repeat symbol)
917   :group 'gnus-charset)
918
919 (gnus-define-group-parameter
920  ignored-charsets
921  :type list
922  :function-document
923  "Return the ignored charsets of GROUP."
924  :variable gnus-group-ignored-charsets-alist
925  :variable-default
926  '(("alt\\.chinese\\.text" iso-8859-1))
927  :variable-document
928  "Alist of regexps (to match group names) and charsets that should be ignored.
929 When these charsets are used in the \"charset\" parameter, the
930 default charset will be used instead."
931  :variable-group gnus-charset
932  :variable-type '(repeat (cons (regexp :tag "Group")
933                                (repeat symbol)))
934  :parameter-type '(choice :tag "Ignored charsets"
935                           :value nil
936                           (repeat (symbol)))
937  :parameter-document       "\
938 List of charsets that should be ignored.
939
940 When these charsets are used in the \"charset\" parameter, the
941 default charset will be used instead.")
942
943 (defcustom gnus-group-highlight-words-alist nil
944   "Alist of group regexps and highlight regexps.
945 This variable uses the same syntax as `gnus-emphasis-alist'."
946   :version "21.1"
947   :type '(repeat (cons (regexp :tag "Group")
948                        (repeat (list (regexp :tag "Highlight regexp")
949                                      (number :tag "Group for entire word" 0)
950                                      (number :tag "Group for displayed part" 0)
951                                      (symbol :tag "Face"
952                                              gnus-emphasis-highlight-words)))))
953   :group 'gnus-summary-visual)
954
955 (defcustom gnus-summary-show-article-charset-alist
956   nil
957   "Alist of number and charset.
958 The article will be shown with the charset corresponding to the
959 numbered argument.
960 For example: ((1 . cn-gb-2312) (2 . big5))."
961   :version "21.1"
962   :type '(repeat (cons (number :tag "Argument" 1)
963                        (symbol :tag "Charset")))
964   :group 'gnus-charset)
965
966 (defcustom gnus-preserve-marks t
967   "Whether marks are preserved when moving, copying and respooling messages."
968   :version "21.1"
969   :type 'boolean
970   :group 'gnus-summary-marks)
971
972 (defcustom gnus-alter-articles-to-read-function nil
973   "Function to be called to alter the list of articles to be selected."
974   :type '(choice (const nil) function)
975   :group 'gnus-summary)
976
977 (defcustom gnus-orphan-score nil
978   "*All orphans get this score added.  Set in the score file."
979   :group 'gnus-score-default
980   :type '(choice (const nil)
981                  integer))
982
983 (defcustom gnus-summary-save-parts-default-mime "image/.*"
984   "*A regexp to match MIME parts when saving multiple parts of a message
985 with gnus-summary-save-parts (X m). This regexp will be used by default
986 when prompting the user for which type of files to save."
987   :group 'gnus-summary
988   :type 'regexp)
989
990
991 (defcustom gnus-summary-save-parts-default-mime "image/.*"
992   "*A regexp to match MIME parts when saving multiple parts of a message
993 with gnus-summary-save-parts (X m). This regexp will be used by default
994 when prompting the user for which type of files to save."
995   :group 'gnus-summary
996   :type 'regexp)
997
998 (defcustom gnus-read-all-available-headers nil
999   "Whether Gnus should parse all headers made available to it.
1000 This is mostly relevant for slow backends where the user may
1001 wish to widen the summary buffer to include all headers
1002 that were fetched.  Say, for nnultimate groups."
1003   :group 'gnus-summary
1004   :type '(choice boolean regexp))
1005
1006 (defcustom gnus-summary-muttprint-program "muttprint"
1007   "Command (and optional arguments) used to run Muttprint."
1008   :group 'gnus-summary
1009   :type 'string)
1010
1011 ;;; Internal variables
1012
1013 (defvar gnus-summary-display-cache nil)
1014 (defvar gnus-article-mime-handles nil)
1015 (defvar gnus-article-decoded-p nil)
1016 (defvar gnus-article-charset nil)
1017 (defvar gnus-article-ignored-charsets nil)
1018 (defvar gnus-scores-exclude-files nil)
1019 (defvar gnus-page-broken nil)
1020 (defvar gnus-inhibit-mime-unbuttonizing nil)
1021
1022 (defvar gnus-original-article nil)
1023 (defvar gnus-article-internal-prepare-hook nil)
1024 (defvar gnus-newsgroup-process-stack nil)
1025
1026 (defvar gnus-thread-indent-array nil)
1027 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1028 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1029   "Function called to sort the articles within a thread after it has been gathered together.")
1030
1031 (defvar gnus-summary-save-parts-type-history nil)
1032 (defvar gnus-summary-save-parts-last-directory nil)
1033
1034 (defvar gnus-summary-save-parts-type-history nil)
1035 (defvar gnus-summary-save-parts-last-directory nil)
1036
1037 ;; Avoid highlighting in kill files.
1038 (defvar gnus-summary-inhibit-highlight nil)
1039 (defvar gnus-newsgroup-selected-overlay nil)
1040 (defvar gnus-inhibit-limiting nil)
1041 (defvar gnus-newsgroup-adaptive-score-file nil)
1042 (defvar gnus-current-score-file nil)
1043 (defvar gnus-current-move-group nil)
1044 (defvar gnus-current-copy-group nil)
1045 (defvar gnus-current-crosspost-group nil)
1046 (defvar gnus-newsgroup-display nil)
1047
1048 (defvar gnus-newsgroup-dependencies nil)
1049 (defvar gnus-newsgroup-adaptive nil)
1050 (defvar gnus-summary-display-article-function nil)
1051 (defvar gnus-summary-highlight-line-function nil
1052   "Function called after highlighting a summary line.")
1053
1054 (defvar gnus-summary-line-format-alist
1055   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1056     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1057     (?s gnus-tmp-subject-or-nil ?s)
1058     (?n gnus-tmp-name ?s)
1059     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1060         ?s)
1061     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1062             gnus-tmp-from) ?s)
1063     (?F gnus-tmp-from ?s)
1064     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1065     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1066     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1067     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1068     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1069     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1070     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1071     (?L gnus-tmp-lines ?s)
1072     (?I gnus-tmp-indentation ?s)
1073     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1074     (?R gnus-tmp-replied ?c)
1075     (?\[ gnus-tmp-opening-bracket ?c)
1076     (?\] gnus-tmp-closing-bracket ?c)
1077     (?\> (make-string gnus-tmp-level ? ) ?s)
1078     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1079     (?i gnus-tmp-score ?d)
1080     (?z gnus-tmp-score-char ?c)
1081     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1082     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1083     (?U gnus-tmp-unread ?c)
1084     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1085         ?s)
1086     (?t (gnus-summary-number-of-articles-in-thread
1087          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1088         ?d)
1089     (?e (gnus-summary-number-of-articles-in-thread
1090          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1091         ?c)
1092     (?u gnus-tmp-user-defined ?s)
1093     (?P (gnus-pick-line-number) ?d)
1094     (?B gnus-tmp-thread-tree-header-string ?s)
1095     (user-date (gnus-user-date
1096                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1097   "An alist of format specifications that can appear in summary lines.
1098 These are paired with what variables they correspond with, along with
1099 the type of the variable (string, integer, character, etc).")
1100
1101 (defvar gnus-summary-dummy-line-format-alist
1102   `((?S gnus-tmp-subject ?s)
1103     (?N gnus-tmp-number ?d)
1104     (?u gnus-tmp-user-defined ?s)))
1105
1106 (defvar gnus-summary-mode-line-format-alist
1107   `((?G gnus-tmp-group-name ?s)
1108     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1109     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1110     (?A gnus-tmp-article-number ?d)
1111     (?Z gnus-tmp-unread-and-unselected ?s)
1112     (?V gnus-version ?s)
1113     (?U gnus-tmp-unread-and-unticked ?d)
1114     (?S gnus-tmp-subject ?s)
1115     (?e gnus-tmp-unselected ?d)
1116     (?u gnus-tmp-user-defined ?s)
1117     (?d (length gnus-newsgroup-dormant) ?d)
1118     (?t (length gnus-newsgroup-marked) ?d)
1119     (?r (length gnus-newsgroup-reads) ?d)
1120     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1121     (?E gnus-newsgroup-expunged-tally ?d)
1122     (?s (gnus-current-score-file-nondirectory) ?s)))
1123
1124 (defvar gnus-last-search-regexp nil
1125   "Default regexp for article search command.")
1126
1127 (defvar gnus-last-shell-command nil
1128   "Default shell command on article.")
1129
1130 (defvar gnus-newsgroup-begin nil)
1131 (defvar gnus-newsgroup-end nil)
1132 (defvar gnus-newsgroup-last-rmail nil)
1133 (defvar gnus-newsgroup-last-mail nil)
1134 (defvar gnus-newsgroup-last-folder nil)
1135 (defvar gnus-newsgroup-last-file nil)
1136 (defvar gnus-newsgroup-auto-expire nil)
1137 (defvar gnus-newsgroup-active nil)
1138
1139 (defvar gnus-newsgroup-data nil)
1140 (defvar gnus-newsgroup-data-reverse nil)
1141 (defvar gnus-newsgroup-limit nil)
1142 (defvar gnus-newsgroup-limits nil)
1143
1144 (defvar gnus-newsgroup-unreads nil
1145   "List of unread articles in the current newsgroup.")
1146
1147 (defvar gnus-newsgroup-unselected nil
1148   "List of unselected unread articles in the current newsgroup.")
1149
1150 (defvar gnus-newsgroup-reads nil
1151   "Alist of read articles and article marks in the current newsgroup.")
1152
1153 (defvar gnus-newsgroup-expunged-tally nil)
1154
1155 (defvar gnus-newsgroup-marked nil
1156   "List of ticked articles in the current newsgroup (a subset of unread art).")
1157
1158 (defvar gnus-newsgroup-killed nil
1159   "List of ranges of articles that have been through the scoring process.")
1160
1161 (defvar gnus-newsgroup-cached nil
1162   "List of articles that come from the article cache.")
1163
1164 (defvar gnus-newsgroup-saved nil
1165   "List of articles that have been saved.")
1166
1167 (defvar gnus-newsgroup-kill-headers nil)
1168
1169 (defvar gnus-newsgroup-replied nil
1170   "List of articles that have been replied to in the current newsgroup.")
1171
1172 (defvar gnus-newsgroup-forwarded nil
1173   "List of articles that have been forwarded in the current newsgroup.")
1174
1175 (defvar gnus-newsgroup-recent nil
1176   "List of articles that have are recent in the current newsgroup.")
1177
1178 (defvar gnus-newsgroup-expirable nil
1179   "List of articles in the current newsgroup that can be expired.")
1180
1181 (defvar gnus-newsgroup-processable nil
1182   "List of articles in the current newsgroup that can be processed.")
1183
1184 (defvar gnus-newsgroup-downloadable nil
1185   "List of articles in the current newsgroup that can be processed.")
1186
1187 (defvar gnus-newsgroup-undownloaded nil
1188   "List of articles in the current newsgroup that haven't been downloaded..")
1189
1190 (defvar gnus-newsgroup-unsendable nil
1191   "List of articles in the current newsgroup that won't be sent.")
1192
1193 (defvar gnus-newsgroup-bookmarks nil
1194   "List of articles in the current newsgroup that have bookmarks.")
1195
1196 (defvar gnus-newsgroup-dormant nil
1197   "List of dormant articles in the current newsgroup.")
1198
1199 (defvar gnus-newsgroup-unseen nil
1200   "List of unseen articles in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-seen nil
1203   "Range of seen articles in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-articles nil
1206   "List of articles in the current newsgroup.")
1207
1208 (defvar gnus-newsgroup-scored nil
1209   "List of scored articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-headers nil
1212   "List of article headers in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-threads nil)
1215
1216 (defvar gnus-newsgroup-prepared nil
1217   "Whether the current group has been prepared properly.")
1218
1219 (defvar gnus-newsgroup-ancient nil
1220   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-sparse nil)
1223
1224 (defvar gnus-current-article nil)
1225 (defvar gnus-article-current nil)
1226 (defvar gnus-current-headers nil)
1227 (defvar gnus-have-all-headers nil)
1228 (defvar gnus-last-article nil)
1229 (defvar gnus-newsgroup-history nil)
1230 (defvar gnus-newsgroup-charset nil)
1231 (defvar gnus-newsgroup-ephemeral-charset nil)
1232 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1233
1234 (defvar gnus-article-before-search nil)
1235
1236 (defconst gnus-summary-local-variables
1237   '(gnus-newsgroup-name
1238     gnus-newsgroup-begin gnus-newsgroup-end
1239     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1240     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1241     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1242     gnus-newsgroup-unselected gnus-newsgroup-marked
1243     gnus-newsgroup-reads gnus-newsgroup-saved
1244     gnus-newsgroup-replied gnus-newsgroup-forwarded
1245     gnus-newsgroup-recent
1246     gnus-newsgroup-expirable
1247     gnus-newsgroup-processable gnus-newsgroup-killed
1248     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1249     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1250     gnus-newsgroup-seen gnus-newsgroup-articles
1251     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1252     gnus-newsgroup-headers gnus-newsgroup-threads
1253     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1254     gnus-current-article gnus-current-headers gnus-have-all-headers
1255     gnus-last-article gnus-article-internal-prepare-hook
1256     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1257     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1258     gnus-thread-expunge-below
1259     gnus-score-alist gnus-current-score-file
1260     (gnus-summary-expunge-below . global)
1261     (gnus-summary-mark-below . global)
1262     (gnus-orphan-score . global)
1263     gnus-newsgroup-active gnus-scores-exclude-files
1264     gnus-newsgroup-history gnus-newsgroup-ancient
1265     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1266     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1267     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1268     (gnus-newsgroup-expunged-tally . 0)
1269     gnus-cache-removable-articles gnus-newsgroup-cached
1270     gnus-newsgroup-data gnus-newsgroup-data-reverse
1271     gnus-newsgroup-limit gnus-newsgroup-limits
1272     gnus-newsgroup-charset gnus-newsgroup-display)
1273   "Variables that are buffer-local to the summary buffers.")
1274
1275 (defvar gnus-newsgroup-variables nil
1276   "A list of variables that have separate values in different newsgroups.
1277 A list of newsgroup (summary buffer) local variables, or cons of
1278 variables and their default values (when the default values are not
1279 nil), that should be made global while the summary buffer is active.
1280 These variables can be used to set variables in the group parameters
1281 while still allowing them to affect operations done in other
1282 buffers. For example:
1283
1284 \(setq gnus-newsgroup-variables
1285      '(message-use-followup-to
1286        (gnus-visible-headers .
1287          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1288 ")
1289
1290 ;; Byte-compiler warning.
1291 (eval-when-compile (defvar gnus-article-mode-map))
1292
1293 ;; MIME stuff.
1294
1295 (defvar gnus-decode-encoded-word-methods
1296   '(mail-decode-encoded-word-string)
1297   "List of methods used to decode encoded words.
1298
1299 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1300 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1301 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1302 whose names match REGEXP.
1303
1304 For example:
1305 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1306  mail-decode-encoded-word-string
1307  (\"chinese\" . rfc1843-decode-string))")
1308
1309 (defvar gnus-decode-encoded-word-methods-cache nil)
1310
1311 (defun gnus-multi-decode-encoded-word-string (string)
1312   "Apply the functions from `gnus-encoded-word-methods' that match."
1313   (unless (and gnus-decode-encoded-word-methods-cache
1314                (eq gnus-newsgroup-name
1315                    (car gnus-decode-encoded-word-methods-cache)))
1316     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1317     (mapcar (lambda (x)
1318               (if (symbolp x)
1319                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1320                 (if (and gnus-newsgroup-name
1321                          (string-match (car x) gnus-newsgroup-name))
1322                     (nconc gnus-decode-encoded-word-methods-cache
1323                            (list (cdr x))))))
1324             gnus-decode-encoded-word-methods))
1325   (let ((xlist gnus-decode-encoded-word-methods-cache))
1326     (pop xlist)
1327     (while xlist
1328       (setq string (funcall (pop xlist) string))))
1329   string)
1330
1331 ;; Subject simplification.
1332
1333 (defun gnus-simplify-whitespace (str)
1334   "Remove excessive whitespace from STR."
1335   (let ((mystr str))
1336     ;; Multiple spaces.
1337     (while (string-match "[ \t][ \t]+" mystr)
1338       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1339                           " "
1340                           (substring mystr (match-end 0)))))
1341     ;; Leading spaces.
1342     (when (string-match "^[ \t]+" mystr)
1343       (setq mystr (substring mystr (match-end 0))))
1344     ;; Trailing spaces.
1345     (when (string-match "[ \t]+$" mystr)
1346       (setq mystr (substring mystr 0 (match-beginning 0))))
1347     mystr))
1348
1349 (defsubst gnus-simplify-subject-re (subject)
1350   "Remove \"Re:\" from subject lines."
1351   (if (string-match message-subject-re-regexp subject)
1352       (substring subject (match-end 0))
1353     subject))
1354
1355 (defun gnus-simplify-subject (subject &optional re-only)
1356   "Remove `Re:' and words in parentheses.
1357 If RE-ONLY is non-nil, strip leading `Re:'s only."
1358   (let ((case-fold-search t))           ;Ignore case.
1359     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1360     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1361       (setq subject (substring subject (match-end 0))))
1362     ;; Remove uninteresting prefixes.
1363     (when (and (not re-only)
1364                gnus-simplify-ignored-prefixes
1365                (string-match gnus-simplify-ignored-prefixes subject))
1366       (setq subject (substring subject (match-end 0))))
1367     ;; Remove words in parentheses from end.
1368     (unless re-only
1369       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1370         (setq subject (substring subject 0 (match-beginning 0)))))
1371     ;; Return subject string.
1372     subject))
1373
1374 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1375 ;; all whitespace.
1376 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1377   (goto-char (point-min))
1378   (while (re-search-forward regexp nil t)
1379     (replace-match (or newtext ""))))
1380
1381 (defun gnus-simplify-buffer-fuzzy ()
1382   "Simplify string in the buffer fuzzily.
1383 The string in the accessible portion of the current buffer is simplified.
1384 It is assumed to be a single-line subject.
1385 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1386 matter is removed.  Additional things can be deleted by setting
1387 `gnus-simplify-subject-fuzzy-regexp'."
1388   (let ((case-fold-search t)
1389         (modified-tick))
1390     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1391
1392     (while (not (eq modified-tick (buffer-modified-tick)))
1393       (setq modified-tick (buffer-modified-tick))
1394       (cond
1395        ((listp gnus-simplify-subject-fuzzy-regexp)
1396         (mapcar 'gnus-simplify-buffer-fuzzy-step
1397                 gnus-simplify-subject-fuzzy-regexp))
1398        (gnus-simplify-subject-fuzzy-regexp
1399         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1400       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1401       (gnus-simplify-buffer-fuzzy-step
1402        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1403       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1404
1405     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1406     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1407     (gnus-simplify-buffer-fuzzy-step " $")
1408     (gnus-simplify-buffer-fuzzy-step "^ +")))
1409
1410 (defun gnus-simplify-subject-fuzzy (subject)
1411   "Simplify a subject string fuzzily.
1412 See `gnus-simplify-buffer-fuzzy' for details."
1413   (save-excursion
1414     (gnus-set-work-buffer)
1415     (let ((case-fold-search t))
1416       ;; Remove uninteresting prefixes.
1417       (when (and gnus-simplify-ignored-prefixes
1418                  (string-match gnus-simplify-ignored-prefixes subject))
1419         (setq subject (substring subject (match-end 0))))
1420       (insert subject)
1421       (inline (gnus-simplify-buffer-fuzzy))
1422       (buffer-string))))
1423
1424 (defsubst gnus-simplify-subject-fully (subject)
1425   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1426   (cond
1427    (gnus-simplify-subject-functions
1428     (gnus-map-function gnus-simplify-subject-functions subject))
1429    ((null gnus-summary-gather-subject-limit)
1430     (gnus-simplify-subject-re subject))
1431    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1432     (gnus-simplify-subject-fuzzy subject))
1433    ((numberp gnus-summary-gather-subject-limit)
1434     (gnus-limit-string (gnus-simplify-subject-re subject)
1435                        gnus-summary-gather-subject-limit))
1436    (t
1437     subject)))
1438
1439 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1440   "Check whether two subjects are equal.
1441 If optional argument simple-first is t, first argument is already
1442 simplified."
1443   (cond
1444    ((null simple-first)
1445     (equal (gnus-simplify-subject-fully s1)
1446            (gnus-simplify-subject-fully s2)))
1447    (t
1448     (equal s1
1449            (gnus-simplify-subject-fully s2)))))
1450
1451 (defun gnus-summary-bubble-group ()
1452   "Increase the score of the current group.
1453 This is a handy function to add to `gnus-summary-exit-hook' to
1454 increase the score of each group you read."
1455   (gnus-group-add-score gnus-newsgroup-name))
1456
1457 \f
1458 ;;;
1459 ;;; Gnus summary mode
1460 ;;;
1461
1462 (put 'gnus-summary-mode 'mode-class 'special)
1463
1464 (defvar gnus-article-commands-menu)
1465
1466 (when t
1467   ;; Non-orthogonal keys
1468
1469   (gnus-define-keys gnus-summary-mode-map
1470     " " gnus-summary-next-page
1471     "\177" gnus-summary-prev-page
1472     [delete] gnus-summary-prev-page
1473     [backspace] gnus-summary-prev-page
1474     "\r" gnus-summary-scroll-up
1475     "\M-\r" gnus-summary-scroll-down
1476     "n" gnus-summary-next-unread-article
1477     "p" gnus-summary-prev-unread-article
1478     "N" gnus-summary-next-article
1479     "P" gnus-summary-prev-article
1480     "\M-\C-n" gnus-summary-next-same-subject
1481     "\M-\C-p" gnus-summary-prev-same-subject
1482     "\M-n" gnus-summary-next-unread-subject
1483     "\M-p" gnus-summary-prev-unread-subject
1484     "." gnus-summary-first-unread-article
1485     "," gnus-summary-best-unread-article
1486     "\M-s" gnus-summary-search-article-forward
1487     "\M-r" gnus-summary-search-article-backward
1488     "<" gnus-summary-beginning-of-article
1489     ">" gnus-summary-end-of-article
1490     "j" gnus-summary-goto-article
1491     "^" gnus-summary-refer-parent-article
1492     "\M-^" gnus-summary-refer-article
1493     "u" gnus-summary-tick-article-forward
1494     "!" gnus-summary-tick-article-forward
1495     "U" gnus-summary-tick-article-backward
1496     "d" gnus-summary-mark-as-read-forward
1497     "D" gnus-summary-mark-as-read-backward
1498     "E" gnus-summary-mark-as-expirable
1499     "\M-u" gnus-summary-clear-mark-forward
1500     "\M-U" gnus-summary-clear-mark-backward
1501     "k" gnus-summary-kill-same-subject-and-select
1502     "\C-k" gnus-summary-kill-same-subject
1503     "\M-\C-k" gnus-summary-kill-thread
1504     "\M-\C-l" gnus-summary-lower-thread
1505     "e" gnus-summary-edit-article
1506     "#" gnus-summary-mark-as-processable
1507     "\M-#" gnus-summary-unmark-as-processable
1508     "\M-\C-t" gnus-summary-toggle-threads
1509     "\M-\C-s" gnus-summary-show-thread
1510     "\M-\C-h" gnus-summary-hide-thread
1511     "\M-\C-f" gnus-summary-next-thread
1512     "\M-\C-b" gnus-summary-prev-thread
1513     [(meta down)] gnus-summary-next-thread
1514     [(meta up)] gnus-summary-prev-thread
1515     "\M-\C-u" gnus-summary-up-thread
1516     "\M-\C-d" gnus-summary-down-thread
1517     "&" gnus-summary-execute-command
1518     "c" gnus-summary-catchup-and-exit
1519     "\C-w" gnus-summary-mark-region-as-read
1520     "\C-t" gnus-summary-toggle-truncation
1521     "?" gnus-summary-mark-as-dormant
1522     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1523     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1524     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1525     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1526     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1527     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1528     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1529     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1530     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1531     "=" gnus-summary-expand-window
1532     "\C-x\C-s" gnus-summary-reselect-current-group
1533     "\M-g" gnus-summary-rescan-group
1534     "w" gnus-summary-stop-page-breaking
1535     "\C-c\C-r" gnus-summary-caesar-message
1536     "f" gnus-summary-followup
1537     "F" gnus-summary-followup-with-original
1538     "C" gnus-summary-cancel-article
1539     "r" gnus-summary-reply
1540     "R" gnus-summary-reply-with-original
1541     "\C-c\C-f" gnus-summary-mail-forward
1542     "o" gnus-summary-save-article
1543     "\C-o" gnus-summary-save-article-mail
1544     "|" gnus-summary-pipe-output
1545     "\M-k" gnus-summary-edit-local-kill
1546     "\M-K" gnus-summary-edit-global-kill
1547     ;; "V" gnus-version
1548     "\C-c\C-d" gnus-summary-describe-group
1549     "q" gnus-summary-exit
1550     "Q" gnus-summary-exit-no-update
1551     "\C-c\C-i" gnus-info-find-node
1552     gnus-mouse-2 gnus-mouse-pick-article
1553     "m" gnus-summary-mail-other-window
1554     "a" gnus-summary-post-news
1555     "i" gnus-summary-news-other-window
1556     "x" gnus-summary-limit-to-unread
1557     "s" gnus-summary-isearch-article
1558     "t" gnus-summary-toggle-header
1559     "g" gnus-summary-show-article
1560     "l" gnus-summary-goto-last-article
1561     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1562     "\C-d" gnus-summary-enter-digest-group
1563     "\M-\C-d" gnus-summary-read-document
1564     "\M-\C-e" gnus-summary-edit-parameters
1565     "\M-\C-a" gnus-summary-customize-parameters
1566     "\C-c\C-b" gnus-bug
1567     "*" gnus-cache-enter-article
1568     "\M-*" gnus-cache-remove-article
1569     "\M-&" gnus-summary-universal-argument
1570     "\C-l" gnus-recenter
1571     "I" gnus-summary-increase-score
1572     "L" gnus-summary-lower-score
1573     "\M-i" gnus-symbolic-argument
1574     "h" gnus-summary-select-article-buffer
1575
1576     "b" gnus-article-view-part
1577     "\M-t" gnus-summary-toggle-display-buttonized
1578
1579     "V" gnus-summary-score-map
1580     "X" gnus-uu-extract-map
1581     "S" gnus-summary-send-map)
1582
1583   ;; Sort of orthogonal keymap
1584   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1585     "t" gnus-summary-tick-article-forward
1586     "!" gnus-summary-tick-article-forward
1587     "d" gnus-summary-mark-as-read-forward
1588     "r" gnus-summary-mark-as-read-forward
1589     "c" gnus-summary-clear-mark-forward
1590     " " gnus-summary-clear-mark-forward
1591     "e" gnus-summary-mark-as-expirable
1592     "x" gnus-summary-mark-as-expirable
1593     "?" gnus-summary-mark-as-dormant
1594     "b" gnus-summary-set-bookmark
1595     "B" gnus-summary-remove-bookmark
1596     "#" gnus-summary-mark-as-processable
1597     "\M-#" gnus-summary-unmark-as-processable
1598     "S" gnus-summary-limit-include-expunged
1599     "C" gnus-summary-catchup
1600     "H" gnus-summary-catchup-to-here
1601     "h" gnus-summary-catchup-from-here
1602     "\C-c" gnus-summary-catchup-all
1603     "k" gnus-summary-kill-same-subject-and-select
1604     "K" gnus-summary-kill-same-subject
1605     "P" gnus-uu-mark-map)
1606
1607   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1608     "c" gnus-summary-clear-above
1609     "u" gnus-summary-tick-above
1610     "m" gnus-summary-mark-above
1611     "k" gnus-summary-kill-below)
1612
1613   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1614     "/" gnus-summary-limit-to-subject
1615     "n" gnus-summary-limit-to-articles
1616     "w" gnus-summary-pop-limit
1617     "s" gnus-summary-limit-to-subject
1618     "a" gnus-summary-limit-to-author
1619     "u" gnus-summary-limit-to-unread
1620     "m" gnus-summary-limit-to-marks
1621     "M" gnus-summary-limit-exclude-marks
1622     "v" gnus-summary-limit-to-score
1623     "*" gnus-summary-limit-include-cached
1624     "D" gnus-summary-limit-include-dormant
1625     "T" gnus-summary-limit-include-thread
1626     "d" gnus-summary-limit-exclude-dormant
1627     "t" gnus-summary-limit-to-age
1628     "x" gnus-summary-limit-to-extra
1629     "p" gnus-summary-limit-to-display-predicate
1630     "E" gnus-summary-limit-include-expunged
1631     "c" gnus-summary-limit-exclude-childless-dormant
1632     "C" gnus-summary-limit-mark-excluded-as-read
1633     "o" gnus-summary-insert-old-articles
1634     "N" gnus-summary-insert-new-articles)
1635
1636   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1637     "n" gnus-summary-next-unread-article
1638     "p" gnus-summary-prev-unread-article
1639     "N" gnus-summary-next-article
1640     "P" gnus-summary-prev-article
1641     "\C-n" gnus-summary-next-same-subject
1642     "\C-p" gnus-summary-prev-same-subject
1643     "\M-n" gnus-summary-next-unread-subject
1644     "\M-p" gnus-summary-prev-unread-subject
1645     "f" gnus-summary-first-unread-article
1646     "b" gnus-summary-best-unread-article
1647     "j" gnus-summary-goto-article
1648     "g" gnus-summary-goto-subject
1649     "l" gnus-summary-goto-last-article
1650     "o" gnus-summary-pop-article)
1651
1652   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1653     "k" gnus-summary-kill-thread
1654     "l" gnus-summary-lower-thread
1655     "i" gnus-summary-raise-thread
1656     "T" gnus-summary-toggle-threads
1657     "t" gnus-summary-rethread-current
1658     "^" gnus-summary-reparent-thread
1659     "s" gnus-summary-show-thread
1660     "S" gnus-summary-show-all-threads
1661     "h" gnus-summary-hide-thread
1662     "H" gnus-summary-hide-all-threads
1663     "n" gnus-summary-next-thread
1664     "p" gnus-summary-prev-thread
1665     "u" gnus-summary-up-thread
1666     "o" gnus-summary-top-thread
1667     "d" gnus-summary-down-thread
1668     "#" gnus-uu-mark-thread
1669     "\M-#" gnus-uu-unmark-thread)
1670
1671   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1672     "g" gnus-summary-prepare
1673     "c" gnus-summary-insert-cached-articles)
1674
1675   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1676     "c" gnus-summary-catchup-and-exit
1677     "C" gnus-summary-catchup-all-and-exit
1678     "E" gnus-summary-exit-no-update
1679     "Q" gnus-summary-exit
1680     "Z" gnus-summary-exit
1681     "n" gnus-summary-catchup-and-goto-next-group
1682     "R" gnus-summary-reselect-current-group
1683     "G" gnus-summary-rescan-group
1684     "N" gnus-summary-next-group
1685     "s" gnus-summary-save-newsrc
1686     "P" gnus-summary-prev-group)
1687
1688   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1689     " " gnus-summary-next-page
1690     "n" gnus-summary-next-page
1691     "\177" gnus-summary-prev-page
1692     [delete] gnus-summary-prev-page
1693     "p" gnus-summary-prev-page
1694     "\r" gnus-summary-scroll-up
1695     "\M-\r" gnus-summary-scroll-down
1696     "<" gnus-summary-beginning-of-article
1697     ">" gnus-summary-end-of-article
1698     "b" gnus-summary-beginning-of-article
1699     "e" gnus-summary-end-of-article
1700     "^" gnus-summary-refer-parent-article
1701     "r" gnus-summary-refer-parent-article
1702     "D" gnus-summary-enter-digest-group
1703     "R" gnus-summary-refer-references
1704     "T" gnus-summary-refer-thread
1705     "g" gnus-summary-show-article
1706     "s" gnus-summary-isearch-article
1707     "P" gnus-summary-print-article
1708     "M" gnus-mailing-list-insinuate
1709     "t" gnus-article-babel)
1710
1711   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1712     "b" gnus-article-add-buttons
1713     "B" gnus-article-add-buttons-to-head
1714     "o" gnus-article-treat-overstrike
1715     "e" gnus-article-emphasize
1716     "w" gnus-article-fill-cited-article
1717     "Q" gnus-article-fill-long-lines
1718     "C" gnus-article-capitalize-sentences
1719     "c" gnus-article-remove-cr
1720     "q" gnus-article-de-quoted-unreadable
1721     "6" gnus-article-de-base64-unreadable
1722     "Z" gnus-article-decode-HZ
1723     "h" gnus-article-wash-html
1724     "s" gnus-summary-force-verify-and-decrypt
1725     "f" gnus-article-display-x-face
1726     "l" gnus-summary-stop-page-breaking
1727     "r" gnus-summary-caesar-message
1728     "t" gnus-summary-toggle-header
1729     "g" gnus-summary-toggle-smiley
1730     "u" gnus-article-treat-unfold-headers
1731     "n" gnus-article-treat-fold-newsgroups
1732     "v" gnus-summary-verbose-headers
1733     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1734     "p" gnus-article-verify-x-pgp-sig
1735     "d" gnus-article-treat-dumbquotes)
1736
1737   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1738     "a" gnus-article-hide
1739     "h" gnus-article-hide-headers
1740     "b" gnus-article-hide-boring-headers
1741     "s" gnus-article-hide-signature
1742     "c" gnus-article-hide-citation
1743     "C" gnus-article-hide-citation-in-followups
1744     "l" gnus-article-hide-list-identifiers
1745     "p" gnus-article-hide-pgp
1746     "B" gnus-article-strip-banner
1747     "P" gnus-article-hide-pem
1748     "\C-c" gnus-article-hide-citation-maybe)
1749
1750   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1751     "a" gnus-article-highlight
1752     "h" gnus-article-highlight-headers
1753     "c" gnus-article-highlight-citation
1754     "s" gnus-article-highlight-signature)
1755
1756   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1757     "x" gnus-article-display-x-face
1758     "s" gnus-summary-toggle-smiley
1759     "f" gnus-treat-from-picon
1760     "m" gnus-treat-mail-picon
1761     "n" gnus-treat-newsgroups-picon)
1762
1763   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1764     "w" gnus-article-decode-mime-words
1765     "c" gnus-article-decode-charset
1766     "v" gnus-mime-view-all-parts
1767     "b" gnus-article-view-part)
1768
1769   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1770     "z" gnus-article-date-ut
1771     "u" gnus-article-date-ut
1772     "l" gnus-article-date-local
1773     "p" gnus-article-date-english
1774     "e" gnus-article-date-lapsed
1775     "o" gnus-article-date-original
1776     "i" gnus-article-date-iso8601
1777     "s" gnus-article-date-user)
1778
1779   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1780     "t" gnus-article-remove-trailing-blank-lines
1781     "l" gnus-article-strip-leading-blank-lines
1782     "m" gnus-article-strip-multiple-blank-lines
1783     "a" gnus-article-strip-blank-lines
1784     "A" gnus-article-strip-all-blank-lines
1785     "s" gnus-article-strip-leading-space
1786     "e" gnus-article-strip-trailing-space
1787     "w" gnus-article-remove-leading-whitespace)
1788
1789   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1790     "v" gnus-version
1791     "f" gnus-summary-fetch-faq
1792     "d" gnus-summary-describe-group
1793     "h" gnus-summary-describe-briefly
1794     "i" gnus-info-find-node)
1795
1796   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1797     "e" gnus-summary-expire-articles
1798     "\M-\C-e" gnus-summary-expire-articles-now
1799     "\177" gnus-summary-delete-article
1800     [delete] gnus-summary-delete-article
1801     [backspace] gnus-summary-delete-article
1802     "m" gnus-summary-move-article
1803     "r" gnus-summary-respool-article
1804     "w" gnus-summary-edit-article
1805     "c" gnus-summary-copy-article
1806     "B" gnus-summary-crosspost-article
1807     "q" gnus-summary-respool-query
1808     "t" gnus-summary-respool-trace
1809     "i" gnus-summary-import-article
1810     "I" gnus-summary-create-article
1811     "p" gnus-summary-article-posted-p)
1812
1813   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1814     "o" gnus-summary-save-article
1815     "m" gnus-summary-save-article-mail
1816     "F" gnus-summary-write-article-file
1817     "r" gnus-summary-save-article-rmail
1818     "f" gnus-summary-save-article-file
1819     "b" gnus-summary-save-article-body-file
1820     "h" gnus-summary-save-article-folder
1821     "v" gnus-summary-save-article-vm
1822     "p" gnus-summary-pipe-output
1823     "P" gnus-summary-muttprint
1824     "s" gnus-soup-add-article)
1825
1826   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1827     "b" gnus-summary-display-buttonized
1828     "m" gnus-summary-repair-multipart
1829     "v" gnus-article-view-part
1830     "o" gnus-article-save-part
1831     "c" gnus-article-copy-part
1832     "C" gnus-article-view-part-as-charset
1833     "e" gnus-article-externalize-part
1834     "E" gnus-article-encrypt-body
1835     "i" gnus-article-inline-part
1836     "|" gnus-article-pipe-part))
1837
1838 (defvar gnus-article-post-menu nil)
1839
1840 (defun gnus-summary-make-menu-bar ()
1841   (gnus-turn-off-edit-menu 'summary)
1842
1843   (unless (boundp 'gnus-summary-misc-menu)
1844
1845     (easy-menu-define
1846       gnus-summary-kill-menu gnus-summary-mode-map ""
1847       (cons
1848        "Score"
1849        (nconc
1850         (list
1851          ["Customize" gnus-score-customize t])
1852         (gnus-make-score-map 'increase)
1853         (gnus-make-score-map 'lower)
1854         '(("Mark"
1855            ["Kill below" gnus-summary-kill-below t]
1856            ["Mark above" gnus-summary-mark-above t]
1857            ["Tick above" gnus-summary-tick-above t]
1858            ["Clear above" gnus-summary-clear-above t])
1859           ["Current score" gnus-summary-current-score t]
1860           ["Set score" gnus-summary-set-score t]
1861           ["Switch current score file..." gnus-score-change-score-file t]
1862           ["Set mark below..." gnus-score-set-mark-below t]
1863           ["Set expunge below..." gnus-score-set-expunge-below t]
1864           ["Edit current score file" gnus-score-edit-current-scores t]
1865           ["Edit score file" gnus-score-edit-file t]
1866           ["Trace score" gnus-score-find-trace t]
1867           ["Find words" gnus-score-find-favourite-words t]
1868           ["Rescore buffer" gnus-summary-rescore t]
1869           ["Increase score..." gnus-summary-increase-score t]
1870           ["Lower score..." gnus-summary-lower-score t]))))
1871
1872     ;; Define both the Article menu in the summary buffer and the
1873     ;; equivalent Commands menu in the article buffer here for
1874     ;; consistency.
1875     (let ((innards
1876            `(("Hide"
1877               ["All" gnus-article-hide t]
1878               ["Headers" gnus-article-hide-headers t]
1879               ["Signature" gnus-article-hide-signature t]
1880               ["Citation" gnus-article-hide-citation t]
1881               ["List identifiers" gnus-article-hide-list-identifiers t]
1882               ["PGP" gnus-article-hide-pgp t]
1883               ["Banner" gnus-article-strip-banner t]
1884               ["Boring headers" gnus-article-hide-boring-headers t])
1885              ("Highlight"
1886               ["All" gnus-article-highlight t]
1887               ["Headers" gnus-article-highlight-headers t]
1888               ["Signature" gnus-article-highlight-signature t]
1889               ["Citation" gnus-article-highlight-citation t])
1890              ("MIME"
1891               ["Words" gnus-article-decode-mime-words t]
1892               ["Charset" gnus-article-decode-charset t]
1893               ["QP" gnus-article-de-quoted-unreadable t]
1894               ["Base64" gnus-article-de-base64-unreadable t]
1895               ["View all" gnus-mime-view-all-parts t]
1896               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1897               ["Encrypt body" gnus-article-encrypt-body t])
1898              ("Date"
1899               ["Local" gnus-article-date-local t]
1900               ["ISO8601" gnus-article-date-iso8601 t]
1901               ["UT" gnus-article-date-ut t]
1902               ["Original" gnus-article-date-original t]
1903               ["Lapsed" gnus-article-date-lapsed t]
1904               ["User-defined" gnus-article-date-user t])
1905              ("Display"
1906               ["Toggle smiley" gnus-summary-toggle-smiley t]
1907               ["Show X-Face" gnus-article-display-x-face t]
1908               ["Show picons in From" gnus-treat-from-picon t]
1909               ["Show picons in mail headers" gnus-treat-mail-picon t]
1910               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1911              ("Washing"
1912               ("Remove Blanks"
1913                ["Leading" gnus-article-strip-leading-blank-lines t]
1914                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1915                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1916                ["All of the above" gnus-article-strip-blank-lines t]
1917                ["All" gnus-article-strip-all-blank-lines t]
1918                ["Leading space" gnus-article-strip-leading-space t]
1919                ["Trailing space" gnus-article-strip-trailing-space t]
1920                ["Leading space in headers"
1921                 gnus-article-remove-leading-whitespace t])
1922               ["Overstrike" gnus-article-treat-overstrike t]
1923               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1924               ["Emphasis" gnus-article-emphasize t]
1925               ["Word wrap" gnus-article-fill-cited-article t]
1926               ["Fill long lines" gnus-article-fill-long-lines t]
1927               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1928               ["CR" gnus-article-remove-cr t]
1929               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1930               ["Base64" gnus-article-de-base64-unreadable t]
1931               ["Rot 13" gnus-summary-caesar-message
1932                ,@(if (featurep 'xemacs) '(t)
1933                    '(:help "\"Caesar rotate\" article by 13"))]
1934               ["Unix pipe" gnus-summary-pipe-message t]
1935               ["Add buttons" gnus-article-add-buttons t]
1936               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1937               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1938               ["Verbose header" gnus-summary-verbose-headers t]
1939               ["Toggle header" gnus-summary-toggle-header t]
1940               ["Unfold headers" gnus-article-treat-unfold-headers t]
1941               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1942               ["Html" gnus-article-wash-html t]
1943               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1944               ["HZ" gnus-article-decode-HZ t])
1945              ("Output"
1946               ["Save in default format" gnus-summary-save-article
1947                ,@(if (featurep 'xemacs) '(t)
1948                    '(:help "Save article using default method"))]
1949               ["Save in file" gnus-summary-save-article-file
1950                ,@(if (featurep 'xemacs) '(t)
1951                    '(:help "Save article in file"))]
1952               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1953               ["Save in MH folder" gnus-summary-save-article-folder t]
1954               ["Save in VM folder" gnus-summary-save-article-vm t]
1955               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1956               ["Save body in file" gnus-summary-save-article-body-file t]
1957               ["Pipe through a filter" gnus-summary-pipe-output t]
1958               ["Add to SOUP packet" gnus-soup-add-article t]
1959               ["Print with Muttprint" gnus-summary-muttprint t]
1960               ["Print" gnus-summary-print-article t])
1961              ("Backend"
1962               ["Respool article..." gnus-summary-respool-article t]
1963               ["Move article..." gnus-summary-move-article
1964                (gnus-check-backend-function
1965                 'request-move-article gnus-newsgroup-name)]
1966               ["Copy article..." gnus-summary-copy-article t]
1967               ["Crosspost article..." gnus-summary-crosspost-article
1968                (gnus-check-backend-function
1969                 'request-replace-article gnus-newsgroup-name)]
1970               ["Import file..." gnus-summary-import-article t]
1971               ["Create article..." gnus-summary-create-article t]
1972               ["Check if posted" gnus-summary-article-posted-p t]
1973               ["Edit article" gnus-summary-edit-article
1974                (not (gnus-group-read-only-p))]
1975               ["Delete article" gnus-summary-delete-article
1976                (gnus-check-backend-function
1977                 'request-expire-articles gnus-newsgroup-name)]
1978               ["Query respool" gnus-summary-respool-query t]
1979               ["Trace respool" gnus-summary-respool-trace t]
1980               ["Delete expirable articles" gnus-summary-expire-articles-now
1981                (gnus-check-backend-function
1982                 'request-expire-articles gnus-newsgroup-name)])
1983              ("Extract"
1984               ["Uudecode" gnus-uu-decode-uu
1985                ,@(if (featurep 'xemacs) '(t)
1986                    '(:help "Decode uuencoded article(s)"))]
1987               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1988               ["Unshar" gnus-uu-decode-unshar t]
1989               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1990               ["Save" gnus-uu-decode-save t]
1991               ["Binhex" gnus-uu-decode-binhex t]
1992               ["Postscript" gnus-uu-decode-postscript t])
1993              ("Cache"
1994               ["Enter article" gnus-cache-enter-article t]
1995               ["Remove article" gnus-cache-remove-article t])
1996              ["Translate" gnus-article-babel t]
1997              ["Select article buffer" gnus-summary-select-article-buffer t]
1998              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1999              ["Isearch article..." gnus-summary-isearch-article t]
2000              ["Beginning of the article" gnus-summary-beginning-of-article t]
2001              ["End of the article" gnus-summary-end-of-article t]
2002              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2003              ["Fetch referenced articles" gnus-summary-refer-references t]
2004              ["Fetch current thread" gnus-summary-refer-thread t]
2005              ["Fetch article with id..." gnus-summary-refer-article t]
2006              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2007              ["Redisplay" gnus-summary-show-article t]
2008              ["Raw article" gnus-summary-show-raw-article t])))
2009       (easy-menu-define
2010         gnus-summary-article-menu gnus-summary-mode-map ""
2011         (cons "Article" innards))
2012
2013       (if (not (keymapp gnus-summary-article-menu))
2014           (easy-menu-define
2015             gnus-article-commands-menu gnus-article-mode-map ""
2016             (cons "Commands" innards))
2017         ;; in Emacs, don't share menu.
2018         (setq gnus-article-commands-menu
2019               (copy-keymap gnus-summary-article-menu))
2020         (define-key gnus-article-mode-map [menu-bar commands]
2021           (cons "Commands" gnus-article-commands-menu))))
2022
2023     (easy-menu-define
2024       gnus-summary-thread-menu gnus-summary-mode-map ""
2025       '("Threads"
2026         ["Toggle threading" gnus-summary-toggle-threads t]
2027         ["Hide threads" gnus-summary-hide-all-threads t]
2028         ["Show threads" gnus-summary-show-all-threads t]
2029         ["Hide thread" gnus-summary-hide-thread t]
2030         ["Show thread" gnus-summary-show-thread t]
2031         ["Go to next thread" gnus-summary-next-thread t]
2032         ["Go to previous thread" gnus-summary-prev-thread t]
2033         ["Go down thread" gnus-summary-down-thread t]
2034         ["Go up thread" gnus-summary-up-thread t]
2035         ["Top of thread" gnus-summary-top-thread t]
2036         ["Mark thread as read" gnus-summary-kill-thread t]
2037         ["Lower thread score" gnus-summary-lower-thread t]
2038         ["Raise thread score" gnus-summary-raise-thread t]
2039         ["Rethread current" gnus-summary-rethread-current t]))
2040
2041     (easy-menu-define
2042       gnus-summary-post-menu gnus-summary-mode-map ""
2043       `("Post"
2044         ["Send a message (mail or news)" gnus-summary-post-news
2045          ,@(if (featurep 'xemacs) '(t)
2046              '(:help "Post an article"))]
2047         ["Followup" gnus-summary-followup
2048          ,@(if (featurep 'xemacs) '(t)
2049              '(:help "Post followup to this article"))]
2050         ["Followup and yank" gnus-summary-followup-with-original
2051          ,@(if (featurep 'xemacs) '(t)
2052              '(:help "Post followup to this article, quoting its contents"))]
2053         ["Supersede article" gnus-summary-supersede-article t]
2054         ["Cancel article" gnus-summary-cancel-article
2055          ,@(if (featurep 'xemacs) '(t)
2056              '(:help "Cancel an article you posted"))]
2057         ["Reply" gnus-summary-reply t]
2058         ["Reply and yank" gnus-summary-reply-with-original t]
2059         ["Wide reply" gnus-summary-wide-reply t]
2060         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2061          ,@(if (featurep 'xemacs) '(t)
2062              '(:help "Mail a reply, quoting this article"))]
2063         ["Mail forward" gnus-summary-mail-forward t]
2064         ["Post forward" gnus-summary-post-forward t]
2065         ["Digest and mail" gnus-uu-digest-mail-forward t]
2066         ["Digest and post" gnus-uu-digest-post-forward t]
2067         ["Resend message" gnus-summary-resend-message t]
2068         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2069         ["Send a mail" gnus-summary-mail-other-window t]
2070         ["Create a local message" gnus-summary-news-other-window t]
2071         ["Uuencode and post" gnus-uu-post-news
2072          ,@(if (featurep 'xemacs) '(t)
2073              '(:help "Post a uuencoded article"))]
2074         ["Followup via news" gnus-summary-followup-to-mail t]
2075         ["Followup via news and yank"
2076          gnus-summary-followup-to-mail-with-original t]
2077         ;;("Draft"
2078         ;;["Send" gnus-summary-send-draft t]
2079         ;;["Send bounced" gnus-resend-bounced-mail t])
2080         ))
2081
2082     (cond
2083      ((not (keymapp gnus-summary-post-menu))
2084       (setq gnus-article-post-menu gnus-summary-post-menu))
2085      ((not gnus-article-post-menu)
2086       ;; Don't share post menu.
2087       (setq gnus-article-post-menu
2088             (copy-keymap gnus-summary-post-menu))))
2089     (define-key gnus-article-mode-map [menu-bar post]
2090       (cons "Post" gnus-article-post-menu))
2091
2092     (easy-menu-define
2093       gnus-summary-misc-menu gnus-summary-mode-map ""
2094       `("Gnus"
2095         ("Mark Read"
2096          ["Mark as read" gnus-summary-mark-as-read-forward t]
2097          ["Mark same subject and select"
2098           gnus-summary-kill-same-subject-and-select t]
2099          ["Mark same subject" gnus-summary-kill-same-subject t]
2100          ["Catchup" gnus-summary-catchup
2101           ,@(if (featurep 'xemacs) '(t)
2102               '(:help "Mark unread articles in this group as read"))]
2103          ["Catchup all" gnus-summary-catchup-all t]
2104          ["Catchup to here" gnus-summary-catchup-to-here t]
2105          ["Catchup from here" gnus-summary-catchup-from-here t]
2106          ["Catchup region" gnus-summary-mark-region-as-read t]
2107          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2108         ("Mark Various"
2109          ["Tick" gnus-summary-tick-article-forward t]
2110          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2111          ["Remove marks" gnus-summary-clear-mark-forward t]
2112          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2113          ["Set bookmark" gnus-summary-set-bookmark t]
2114          ["Remove bookmark" gnus-summary-remove-bookmark t])
2115         ("Limit to"
2116          ["Marks..." gnus-summary-limit-to-marks t]
2117          ["Subject..." gnus-summary-limit-to-subject t]
2118          ["Author..." gnus-summary-limit-to-author t]
2119          ["Age..." gnus-summary-limit-to-age t]
2120          ["Extra..." gnus-summary-limit-to-extra t]
2121          ["Score" gnus-summary-limit-to-score t]
2122          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2123          ["Unread" gnus-summary-limit-to-unread t]
2124          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2125          ["Articles" gnus-summary-limit-to-articles t]
2126          ["Pop limit" gnus-summary-pop-limit t]
2127          ["Show dormant" gnus-summary-limit-include-dormant t]
2128          ["Hide childless dormant"
2129           gnus-summary-limit-exclude-childless-dormant t]
2130          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2131          ["Hide marked" gnus-summary-limit-exclude-marks t]
2132          ["Show expunged" gnus-summary-limit-include-expunged t])
2133         ("Process Mark"
2134          ["Set mark" gnus-summary-mark-as-processable t]
2135          ["Remove mark" gnus-summary-unmark-as-processable t]
2136          ["Remove all marks" gnus-summary-unmark-all-processable t]
2137          ["Mark above" gnus-uu-mark-over t]
2138          ["Mark series" gnus-uu-mark-series t]
2139          ["Mark region" gnus-uu-mark-region t]
2140          ["Unmark region" gnus-uu-unmark-region t]
2141          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2142          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2143          ["Mark all" gnus-uu-mark-all t]
2144          ["Mark buffer" gnus-uu-mark-buffer t]
2145          ["Mark sparse" gnus-uu-mark-sparse t]
2146          ["Mark thread" gnus-uu-mark-thread t]
2147          ["Unmark thread" gnus-uu-unmark-thread t]
2148          ("Process Mark Sets"
2149           ["Kill" gnus-summary-kill-process-mark t]
2150           ["Yank" gnus-summary-yank-process-mark
2151            gnus-newsgroup-process-stack]
2152           ["Save" gnus-summary-save-process-mark t]))
2153         ("Scroll article"
2154          ["Page forward" gnus-summary-next-page
2155           ,@(if (featurep 'xemacs) '(t)
2156               '(:help "Show next page of article"))]
2157          ["Page backward" gnus-summary-prev-page
2158           ,@(if (featurep 'xemacs) '(t)
2159               '(:help "Show previous page of article"))]
2160          ["Line forward" gnus-summary-scroll-up t])
2161         ("Move"
2162          ["Next unread article" gnus-summary-next-unread-article t]
2163          ["Previous unread article" gnus-summary-prev-unread-article t]
2164          ["Next article" gnus-summary-next-article t]
2165          ["Previous article" gnus-summary-prev-article t]
2166          ["Next unread subject" gnus-summary-next-unread-subject t]
2167          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2168          ["Next article same subject" gnus-summary-next-same-subject t]
2169          ["Previous article same subject" gnus-summary-prev-same-subject t]
2170          ["First unread article" gnus-summary-first-unread-article t]
2171          ["Best unread article" gnus-summary-best-unread-article t]
2172          ["Go to subject number..." gnus-summary-goto-subject t]
2173          ["Go to article number..." gnus-summary-goto-article t]
2174          ["Go to the last article" gnus-summary-goto-last-article t]
2175          ["Pop article off history" gnus-summary-pop-article t])
2176         ("Sort"
2177          ["Sort by number" gnus-summary-sort-by-number t]
2178          ["Sort by author" gnus-summary-sort-by-author t]
2179          ["Sort by subject" gnus-summary-sort-by-subject t]
2180          ["Sort by date" gnus-summary-sort-by-date t]
2181          ["Sort by score" gnus-summary-sort-by-score t]
2182          ["Sort by lines" gnus-summary-sort-by-lines t]
2183          ["Sort by characters" gnus-summary-sort-by-chars t]
2184          ["Original sort" gnus-summary-sort-by-original t])
2185         ("Help"
2186          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2187          ["Describe group" gnus-summary-describe-group t]
2188          ["Read manual" gnus-info-find-node t])
2189         ("Modes"
2190          ["Pick and read" gnus-pick-mode t]
2191          ["Binary" gnus-binary-mode t])
2192         ("Regeneration"
2193          ["Regenerate" gnus-summary-prepare t]
2194          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2195          ["Toggle threading" gnus-summary-toggle-threads t])
2196         ["See old articles" gnus-summary-insert-old-articles t]
2197         ["See new articles" gnus-summary-insert-new-articles t]
2198         ["Filter articles..." gnus-summary-execute-command t]
2199         ["Run command on subjects..." gnus-summary-universal-argument t]
2200         ["Search articles forward..." gnus-summary-search-article-forward t]
2201         ["Search articles backward..." gnus-summary-search-article-backward t]
2202         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2203         ["Expand window" gnus-summary-expand-window t]
2204         ["Expire expirable articles" gnus-summary-expire-articles
2205          (gnus-check-backend-function
2206           'request-expire-articles gnus-newsgroup-name)]
2207         ["Edit local kill file" gnus-summary-edit-local-kill t]
2208         ["Edit main kill file" gnus-summary-edit-global-kill t]
2209         ["Edit group parameters" gnus-summary-edit-parameters t]
2210         ["Customize group parameters" gnus-summary-customize-parameters t]
2211         ["Send a bug report" gnus-bug t]
2212         ("Exit"
2213          ["Catchup and exit" gnus-summary-catchup-and-exit
2214           ,@(if (featurep 'xemacs) '(t)
2215               '(:help "Mark unread articles in this group as read, then exit"))]
2216          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2217          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2218          ["Exit group" gnus-summary-exit
2219           ,@(if (featurep 'xemacs) '(t)
2220               '(:help "Exit current group, return to group selection mode"))]
2221          ["Exit group without updating" gnus-summary-exit-no-update t]
2222          ["Exit and goto next group" gnus-summary-next-group t]
2223          ["Exit and goto prev group" gnus-summary-prev-group t]
2224          ["Reselect group" gnus-summary-reselect-current-group t]
2225          ["Rescan group" gnus-summary-rescan-group t]
2226          ["Update dribble" gnus-summary-save-newsrc t])))
2227
2228     (gnus-run-hooks 'gnus-summary-menu-hook)))
2229
2230 (defvar gnus-summary-tool-bar-map nil)
2231
2232 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2233 (defun gnus-summary-make-tool-bar ()
2234   (if (and (fboundp 'tool-bar-add-item-from-menu)
2235            (default-value 'tool-bar-mode)
2236            (not gnus-summary-tool-bar-map))
2237       (setq gnus-summary-tool-bar-map
2238             (let ((tool-bar-map (make-sparse-keymap))
2239                   (load-path (mm-image-load-path)))
2240               (tool-bar-add-item-from-menu
2241                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2242               (tool-bar-add-item-from-menu
2243                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2244               (tool-bar-add-item-from-menu
2245                'gnus-summary-post-news "post" gnus-summary-mode-map)
2246               (tool-bar-add-item-from-menu
2247                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2248               (tool-bar-add-item-from-menu
2249                'gnus-summary-followup "followup" gnus-summary-mode-map)
2250               (tool-bar-add-item-from-menu
2251                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2252               (tool-bar-add-item-from-menu
2253                'gnus-summary-reply "reply" gnus-summary-mode-map)
2254               (tool-bar-add-item-from-menu
2255                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2256               (tool-bar-add-item-from-menu
2257                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2258               (tool-bar-add-item-from-menu
2259                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2260               (tool-bar-add-item-from-menu
2261                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2262               (tool-bar-add-item-from-menu
2263                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2264               (tool-bar-add-item-from-menu
2265                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2266               (tool-bar-add-item-from-menu
2267                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2268               (tool-bar-add-item-from-menu
2269                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2270               tool-bar-map)))
2271   (if gnus-summary-tool-bar-map
2272       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2273
2274 (defun gnus-score-set-default (var value)
2275   "A version of set that updates the GNU Emacs menu-bar."
2276   (set var value)
2277   ;; It is the message that forces the active status to be updated.
2278   (message ""))
2279
2280 (defun gnus-make-score-map (type)
2281   "Make a summary score map of type TYPE."
2282   (if t
2283       nil
2284     (let ((headers '(("author" "from" string)
2285                      ("subject" "subject" string)
2286                      ("article body" "body" string)
2287                      ("article head" "head" string)
2288                      ("xref" "xref" string)
2289                      ("extra header" "extra" string)
2290                      ("lines" "lines" number)
2291                      ("followups to author" "followup" string)))
2292           (types '((number ("less than" <)
2293                            ("greater than" >)
2294                            ("equal" =))
2295                    (string ("substring" s)
2296                            ("exact string" e)
2297                            ("fuzzy string" f)
2298                            ("regexp" r))))
2299           (perms '(("temporary" (current-time-string))
2300                    ("permanent" nil)
2301                    ("immediate" now)))
2302           header)
2303       (list
2304        (apply
2305         'nconc
2306         (list
2307          (if (eq type 'lower)
2308              "Lower score"
2309            "Increase score"))
2310         (let (outh)
2311           (while headers
2312             (setq header (car headers))
2313             (setq outh
2314                   (cons
2315                    (apply
2316                     'nconc
2317                     (list (car header))
2318                     (let ((ts (cdr (assoc (nth 2 header) types)))
2319                           outt)
2320                       (while ts
2321                         (setq outt
2322                               (cons
2323                                (apply
2324                                 'nconc
2325                                 (list (caar ts))
2326                                 (let ((ps perms)
2327                                       outp)
2328                                   (while ps
2329                                     (setq outp
2330                                           (cons
2331                                            (vector
2332                                             (caar ps)
2333                                             (list
2334                                              'gnus-summary-score-entry
2335                                              (nth 1 header)
2336                                              (if (or (string= (nth 1 header)
2337                                                               "head")
2338                                                      (string= (nth 1 header)
2339                                                               "body"))
2340                                                  ""
2341                                                (list 'gnus-summary-header
2342                                                      (nth 1 header)))
2343                                              (list 'quote (nth 1 (car ts)))
2344                                              (list 'gnus-score-delta-default
2345                                                    nil)
2346                                              (nth 1 (car ps))
2347                                              t)
2348                                             t)
2349                                            outp))
2350                                     (setq ps (cdr ps)))
2351                                   (list (nreverse outp))))
2352                                outt))
2353                         (setq ts (cdr ts)))
2354                       (list (nreverse outt))))
2355                    outh))
2356             (setq headers (cdr headers)))
2357           (list (nreverse outh))))))))
2358
2359 \f
2360
2361 (defun gnus-summary-mode (&optional group)
2362   "Major mode for reading articles.
2363
2364 All normal editing commands are switched off.
2365 \\<gnus-summary-mode-map>
2366 Each line in this buffer represents one article.  To read an
2367 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2368 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2369 respectively.
2370
2371 You can also post articles and send mail from this buffer.  To
2372 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2373 of an article, type `\\[gnus-summary-reply]'.
2374
2375 There are approx. one gazillion commands you can execute in this
2376 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2377
2378 The following commands are available:
2379
2380 \\{gnus-summary-mode-map}"
2381   (interactive)
2382   (kill-all-local-variables)
2383   (when (gnus-visual-p 'summary-menu 'menu)
2384     (gnus-summary-make-menu-bar)
2385     (gnus-summary-make-tool-bar))
2386   (gnus-summary-make-local-variables)
2387   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2388     (gnus-summary-make-local-variables))
2389   (gnus-make-thread-indent-array)
2390   (gnus-simplify-mode-line)
2391   (setq major-mode 'gnus-summary-mode)
2392   (setq mode-name "Summary")
2393   (make-local-variable 'minor-mode-alist)
2394   (use-local-map gnus-summary-mode-map)
2395   (buffer-disable-undo)
2396   (setq buffer-read-only t)             ;Disable modification
2397   (setq truncate-lines t)
2398   (setq selective-display t)
2399   (setq selective-display-ellipses t)   ;Display `...'
2400   (gnus-summary-set-display-table)
2401   (gnus-set-default-directory)
2402   (setq gnus-newsgroup-name group)
2403   (make-local-variable 'gnus-summary-line-format)
2404   (make-local-variable 'gnus-summary-line-format-spec)
2405   (make-local-variable 'gnus-summary-dummy-line-format)
2406   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2407   (make-local-variable 'gnus-summary-mark-positions)
2408   (make-local-hook 'pre-command-hook)
2409   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2410   (gnus-run-hooks 'gnus-summary-mode-hook)
2411   (turn-on-gnus-mailing-list-mode)
2412   (mm-enable-multibyte-mule4)
2413   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2414   (gnus-update-summary-mark-positions))
2415
2416 (defun gnus-summary-make-local-variables ()
2417   "Make all the local summary buffer variables."
2418   (let (global)
2419     (dolist (local gnus-summary-local-variables)
2420       (if (consp local)
2421           (progn
2422             (if (eq (cdr local) 'global)
2423                 ;; Copy the global value of the variable.
2424                 (setq global (symbol-value (car local)))
2425               ;; Use the value from the list.
2426               (setq global (eval (cdr local))))
2427             (set (make-local-variable (car local)) global))
2428         ;; Simple nil-valued local variable.
2429         (set (make-local-variable local) nil)))))
2430
2431 (defun gnus-summary-clear-local-variables ()
2432   (let ((locals gnus-summary-local-variables))
2433     (while locals
2434       (if (consp (car locals))
2435           (and (vectorp (caar locals))
2436                (set (caar locals) nil))
2437         (and (vectorp (car locals))
2438              (set (car locals) nil)))
2439       (setq locals (cdr locals)))))
2440
2441 ;; Summary data functions.
2442
2443 (defmacro gnus-data-number (data)
2444   `(car ,data))
2445
2446 (defmacro gnus-data-set-number (data number)
2447   `(setcar ,data ,number))
2448
2449 (defmacro gnus-data-mark (data)
2450   `(nth 1 ,data))
2451
2452 (defmacro gnus-data-set-mark (data mark)
2453   `(setcar (nthcdr 1 ,data) ,mark))
2454
2455 (defmacro gnus-data-pos (data)
2456   `(nth 2 ,data))
2457
2458 (defmacro gnus-data-set-pos (data pos)
2459   `(setcar (nthcdr 2 ,data) ,pos))
2460
2461 (defmacro gnus-data-header (data)
2462   `(nth 3 ,data))
2463
2464 (defmacro gnus-data-set-header (data header)
2465   `(setf (nth 3 ,data) ,header))
2466
2467 (defmacro gnus-data-level (data)
2468   `(nth 4 ,data))
2469
2470 (defmacro gnus-data-unread-p (data)
2471   `(= (nth 1 ,data) gnus-unread-mark))
2472
2473 (defmacro gnus-data-read-p (data)
2474   `(/= (nth 1 ,data) gnus-unread-mark))
2475
2476 (defmacro gnus-data-pseudo-p (data)
2477   `(consp (nth 3 ,data)))
2478
2479 (defmacro gnus-data-find (number)
2480   `(assq ,number gnus-newsgroup-data))
2481
2482 (defmacro gnus-data-find-list (number &optional data)
2483   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2484      (memq (assq ,number bdata)
2485            bdata)))
2486
2487 (defmacro gnus-data-make (number mark pos header level)
2488   `(list ,number ,mark ,pos ,header ,level))
2489
2490 (defun gnus-data-enter (after-article number mark pos header level offset)
2491   (let ((data (gnus-data-find-list after-article)))
2492     (unless data
2493       (error "No such article: %d" after-article))
2494     (setcdr data (cons (gnus-data-make number mark pos header level)
2495                        (cdr data)))
2496     (setq gnus-newsgroup-data-reverse nil)
2497     (gnus-data-update-list (cddr data) offset)))
2498
2499 (defun gnus-data-enter-list (after-article list &optional offset)
2500   (when list
2501     (let ((data (and after-article (gnus-data-find-list after-article)))
2502           (ilist list))
2503       (if (not (or data
2504                    after-article))
2505           (let ((odata gnus-newsgroup-data))
2506             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2507             (when offset
2508               (gnus-data-update-list odata offset)))
2509       ;; Find the last element in the list to be spliced into the main
2510         ;; list.
2511         (while (cdr list)
2512           (setq list (cdr list)))
2513         (if (not data)
2514             (progn
2515               (setcdr list gnus-newsgroup-data)
2516               (setq gnus-newsgroup-data ilist)
2517               (when offset
2518                 (gnus-data-update-list (cdr list) offset)))
2519           (setcdr list (cdr data))
2520           (setcdr data ilist)
2521           (when offset
2522             (gnus-data-update-list (cdr list) offset))))
2523       (setq gnus-newsgroup-data-reverse nil))))
2524
2525 (defun gnus-data-remove (article &optional offset)
2526   (let ((data gnus-newsgroup-data))
2527     (if (= (gnus-data-number (car data)) article)
2528         (progn
2529           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2530                 gnus-newsgroup-data-reverse nil)
2531           (when offset
2532             (gnus-data-update-list gnus-newsgroup-data offset)))
2533       (while (cdr data)
2534         (when (= (gnus-data-number (cadr data)) article)
2535           (setcdr data (cddr data))
2536           (when offset
2537             (gnus-data-update-list (cdr data) offset))
2538           (setq data nil
2539                 gnus-newsgroup-data-reverse nil))
2540         (setq data (cdr data))))))
2541
2542 (defmacro gnus-data-list (backward)
2543   `(if ,backward
2544        (or gnus-newsgroup-data-reverse
2545            (setq gnus-newsgroup-data-reverse
2546                  (reverse gnus-newsgroup-data)))
2547      gnus-newsgroup-data))
2548
2549 (defun gnus-data-update-list (data offset)
2550   "Add OFFSET to the POS of all data entries in DATA."
2551   (setq gnus-newsgroup-data-reverse nil)
2552   (while data
2553     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2554     (setq data (cdr data))))
2555
2556 (defun gnus-summary-article-pseudo-p (article)
2557   "Say whether this article is a pseudo article or not."
2558   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2559
2560 (defmacro gnus-summary-article-sparse-p (article)
2561   "Say whether this article is a sparse article or not."
2562   `(memq ,article gnus-newsgroup-sparse))
2563
2564 (defmacro gnus-summary-article-ancient-p (article)
2565   "Say whether this article is a sparse article or not."
2566   `(memq ,article gnus-newsgroup-ancient))
2567
2568 (defun gnus-article-parent-p (number)
2569   "Say whether this article is a parent or not."
2570   (let ((data (gnus-data-find-list number)))
2571     (and (cdr data)              ; There has to be an article after...
2572          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2573             (gnus-data-level (nth 1 data))))))
2574
2575 (defun gnus-article-children (number)
2576   "Return a list of all children to NUMBER."
2577   (let* ((data (gnus-data-find-list number))
2578          (level (gnus-data-level (car data)))
2579          children)
2580     (setq data (cdr data))
2581     (while (and data
2582                 (= (gnus-data-level (car data)) (1+ level)))
2583       (push (gnus-data-number (car data)) children)
2584       (setq data (cdr data)))
2585     children))
2586
2587 (defmacro gnus-summary-skip-intangible ()
2588   "If the current article is intangible, then jump to a different article."
2589   '(let ((to (get-text-property (point) 'gnus-intangible)))
2590      (and to (gnus-summary-goto-subject to))))
2591
2592 (defmacro gnus-summary-article-intangible-p ()
2593   "Say whether this article is intangible or not."
2594   '(get-text-property (point) 'gnus-intangible))
2595
2596 (defun gnus-article-read-p (article)
2597   "Say whether ARTICLE is read or not."
2598   (not (or (memq article gnus-newsgroup-marked)
2599            (memq article gnus-newsgroup-unreads)
2600            (memq article gnus-newsgroup-unselected)
2601            (memq article gnus-newsgroup-dormant))))
2602
2603 ;; Some summary mode macros.
2604
2605 (defmacro gnus-summary-article-number ()
2606   "The article number of the article on the current line.
2607 If there isn's an article number here, then we return the current
2608 article number."
2609   '(progn
2610      (gnus-summary-skip-intangible)
2611      (or (get-text-property (point) 'gnus-number)
2612          (gnus-summary-last-subject))))
2613
2614 (defmacro gnus-summary-article-header (&optional number)
2615   "Return the header of article NUMBER."
2616   `(gnus-data-header (gnus-data-find
2617                       ,(or number '(gnus-summary-article-number)))))
2618
2619 (defmacro gnus-summary-thread-level (&optional number)
2620   "Return the level of thread that starts with article NUMBER."
2621   `(if (and (eq gnus-summary-make-false-root 'dummy)
2622             (get-text-property (point) 'gnus-intangible))
2623        0
2624      (gnus-data-level (gnus-data-find
2625                        ,(or number '(gnus-summary-article-number))))))
2626
2627 (defmacro gnus-summary-article-mark (&optional number)
2628   "Return the mark of article NUMBER."
2629   `(gnus-data-mark (gnus-data-find
2630                     ,(or number '(gnus-summary-article-number)))))
2631
2632 (defmacro gnus-summary-article-pos (&optional number)
2633   "Return the position of the line of article NUMBER."
2634   `(gnus-data-pos (gnus-data-find
2635                    ,(or number '(gnus-summary-article-number)))))
2636
2637 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2638 (defmacro gnus-summary-article-subject (&optional number)
2639   "Return current subject string or nil if nothing."
2640   `(let ((headers
2641           ,(if number
2642                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2643              '(gnus-data-header (assq (gnus-summary-article-number)
2644                                       gnus-newsgroup-data)))))
2645      (and headers
2646           (vectorp headers)
2647           (mail-header-subject headers))))
2648
2649 (defmacro gnus-summary-article-score (&optional number)
2650   "Return current article score."
2651   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2652                   gnus-newsgroup-scored))
2653        gnus-summary-default-score 0))
2654
2655 (defun gnus-summary-article-children (&optional number)
2656   "Return a list of article numbers that are children of article NUMBER."
2657   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2658          (level (gnus-data-level (car data)))
2659          l children)
2660     (while (and (setq data (cdr data))
2661                 (> (setq l (gnus-data-level (car data))) level))
2662       (and (= (1+ level) l)
2663            (push (gnus-data-number (car data))
2664                  children)))
2665     (nreverse children)))
2666
2667 (defun gnus-summary-article-parent (&optional number)
2668   "Return the article number of the parent of article NUMBER."
2669   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2670                                     (gnus-data-list t)))
2671          (level (gnus-data-level (car data))))
2672     (if (zerop level)
2673         ()                              ; This is a root.
2674       ;; We search until we find an article with a level less than
2675       ;; this one.  That function has to be the parent.
2676       (while (and (setq data (cdr data))
2677                   (not (< (gnus-data-level (car data)) level))))
2678       (and data (gnus-data-number (car data))))))
2679
2680 (defun gnus-unread-mark-p (mark)
2681   "Say whether MARK is the unread mark."
2682   (= mark gnus-unread-mark))
2683
2684 (defun gnus-read-mark-p (mark)
2685   "Say whether MARK is one of the marks that mark as read.
2686 This is all marks except unread, ticked, dormant, and expirable."
2687   (not (or (= mark gnus-unread-mark)
2688            (= mark gnus-ticked-mark)
2689            (= mark gnus-dormant-mark)
2690            (= mark gnus-expirable-mark))))
2691
2692 (defmacro gnus-article-mark (number)
2693   "Return the MARK of article NUMBER.
2694 This macro should only be used when computing the mark the \"first\"
2695 time; i.e., when generating the summary lines.  After that,
2696 `gnus-summary-article-mark' should be used to examine the
2697 marks of articles."
2698   `(cond
2699     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2700     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2701     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2702     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2703     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2704     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2705     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2706     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2707            gnus-ancient-mark))))
2708
2709 ;; Saving hidden threads.
2710
2711 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2712 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2713
2714 (defmacro gnus-save-hidden-threads (&rest forms)
2715   "Save hidden threads, eval FORMS, and restore the hidden threads."
2716   (let ((config (make-symbol "config")))
2717     `(let ((,config (gnus-hidden-threads-configuration)))
2718        (unwind-protect
2719            (save-excursion
2720              ,@forms)
2721          (gnus-restore-hidden-threads-configuration ,config)))))
2722
2723 (defun gnus-data-compute-positions ()
2724   "Compute the positions of all articles."
2725   (setq gnus-newsgroup-data-reverse nil)
2726   (let ((data gnus-newsgroup-data))
2727     (save-excursion
2728       (gnus-save-hidden-threads
2729         (gnus-summary-show-all-threads)
2730         (goto-char (point-min))
2731         (while data
2732           (while (get-text-property (point) 'gnus-intangible)
2733             (forward-line 1))
2734           (gnus-data-set-pos (car data) (+ (point) 3))
2735           (setq data (cdr data))
2736           (forward-line 1))))))
2737
2738 (defun gnus-hidden-threads-configuration ()
2739   "Return the current hidden threads configuration."
2740   (save-excursion
2741     (let (config)
2742       (goto-char (point-min))
2743       (while (search-forward "\r" nil t)
2744         (push (1- (point)) config))
2745       config)))
2746
2747 (defun gnus-restore-hidden-threads-configuration (config)
2748   "Restore hidden threads configuration from CONFIG."
2749   (save-excursion
2750     (let (point buffer-read-only)
2751       (while (setq point (pop config))
2752         (when (and (< point (point-max))
2753                    (goto-char point)
2754                    (eq (char-after) ?\n))
2755           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2756
2757 ;; Various summary mode internalish functions.
2758
2759 (defun gnus-mouse-pick-article (e)
2760   (interactive "e")
2761   (mouse-set-point e)
2762   (gnus-summary-next-page nil t))
2763
2764 (defun gnus-summary-set-display-table ()
2765   "Change the display table.
2766 Odd characters have a tendency to mess
2767 up nicely formatted displays - we make all possible glyphs
2768 display only a single character."
2769
2770   ;; We start from the standard display table, if any.
2771   (let ((table (or (copy-sequence standard-display-table)
2772                    (make-display-table)))
2773         (i 32))
2774     ;; Nix out all the control chars...
2775     (while (>= (setq i (1- i)) 0)
2776       (aset table i [??]))
2777    ;; ... but not newline and cr, of course.  (cr is necessary for the
2778     ;; selective display).
2779     (aset table ?\n nil)
2780     (aset table ?\r nil)
2781     ;; We keep TAB as well.
2782     (aset table ?\t nil)
2783     ;; We nix out any glyphs over 126 that are not set already.
2784     (let ((i 256))
2785       (while (>= (setq i (1- i)) 127)
2786         ;; Only modify if the entry is nil.
2787         (unless (aref table i)
2788           (aset table i [??]))))
2789     (setq buffer-display-table table)))
2790
2791 (defun gnus-summary-set-article-display-arrow (pos)
2792   "Update the overlay arrow to point to line at position POS."
2793   (when (and gnus-summary-display-arrow
2794              (boundp 'overlay-arrow-position)
2795              (boundp 'overlay-arrow-string))
2796     (save-excursion
2797       (goto-char pos)
2798       (beginning-of-line)
2799       (unless overlay-arrow-position
2800         (setq overlay-arrow-position (make-marker)))
2801       (setq overlay-arrow-string "=>"
2802             overlay-arrow-position (set-marker overlay-arrow-position
2803                                                (point)
2804                                                (current-buffer))))))
2805
2806 (defun gnus-summary-buffer-name (group)
2807   "Return the summary buffer name of GROUP."
2808   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2809
2810 (defun gnus-summary-setup-buffer (group)
2811   "Initialize summary buffer."
2812   (let ((buffer (gnus-summary-buffer-name group)))
2813     (if (get-buffer buffer)
2814         (progn
2815           (set-buffer buffer)
2816           (setq gnus-summary-buffer (current-buffer))
2817           (not gnus-newsgroup-prepared))
2818       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2819       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2820       (gnus-summary-mode group)
2821       (when gnus-carpal
2822         (gnus-carpal-setup-buffer 'summary))
2823       (unless gnus-single-article-buffer
2824         (make-local-variable 'gnus-article-buffer)
2825         (make-local-variable 'gnus-article-current)
2826         (make-local-variable 'gnus-original-article-buffer))
2827       (setq gnus-newsgroup-name group)
2828       ;; Set any local variables in the group parameters.
2829       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2830       t)))
2831
2832 (defun gnus-set-global-variables ()
2833   "Set the global equivalents of the buffer-local variables.
2834 They are set to the latest values they had.  These reflect the summary
2835 buffer that was in action when the last article was fetched."
2836   (when (eq major-mode 'gnus-summary-mode)
2837     (setq gnus-summary-buffer (current-buffer))
2838     (let ((name gnus-newsgroup-name)
2839           (marked gnus-newsgroup-marked)
2840           (unread gnus-newsgroup-unreads)
2841           (headers gnus-current-headers)
2842           (data gnus-newsgroup-data)
2843           (summary gnus-summary-buffer)
2844           (article-buffer gnus-article-buffer)
2845           (original gnus-original-article-buffer)
2846           (gac gnus-article-current)
2847           (reffed gnus-reffed-article-number)
2848           (score-file gnus-current-score-file)
2849           (default-charset gnus-newsgroup-charset)
2850           vlist)
2851       (let ((locals gnus-newsgroup-variables))
2852         (while locals
2853           (if (consp (car locals))
2854               (push (eval (caar locals)) vlist)
2855             (push (eval (car locals)) vlist))
2856           (setq locals (cdr locals)))
2857         (setq vlist (nreverse vlist)))
2858       (save-excursion
2859         (set-buffer gnus-group-buffer)
2860         (setq gnus-newsgroup-name name
2861               gnus-newsgroup-marked marked
2862               gnus-newsgroup-unreads unread
2863               gnus-current-headers headers
2864               gnus-newsgroup-data data
2865               gnus-article-current gac
2866               gnus-summary-buffer summary
2867               gnus-article-buffer article-buffer
2868               gnus-original-article-buffer original
2869               gnus-reffed-article-number reffed
2870               gnus-current-score-file score-file
2871               gnus-newsgroup-charset default-charset)
2872         (let ((locals gnus-newsgroup-variables))
2873           (while locals
2874             (if (consp (car locals))
2875                 (set (caar locals) (pop vlist))
2876               (set (car locals) (pop vlist)))
2877             (setq locals (cdr locals))))
2878         ;; The article buffer also has local variables.
2879         (when (gnus-buffer-live-p gnus-article-buffer)
2880           (set-buffer gnus-article-buffer)
2881           (setq gnus-summary-buffer summary))))))
2882
2883 (defun gnus-summary-article-unread-p (article)
2884   "Say whether ARTICLE is unread or not."
2885   (memq article gnus-newsgroup-unreads))
2886
2887 (defun gnus-summary-first-article-p (&optional article)
2888   "Return whether ARTICLE is the first article in the buffer."
2889   (if (not (setq article (or article (gnus-summary-article-number))))
2890       nil
2891     (eq article (caar gnus-newsgroup-data))))
2892
2893 (defun gnus-summary-last-article-p (&optional article)
2894   "Return whether ARTICLE is the last article in the buffer."
2895   (if (not (setq article (or article (gnus-summary-article-number))))
2896       ;; All non-existent numbers are the last article.  :-)
2897       t
2898     (not (cdr (gnus-data-find-list article)))))
2899
2900 (defun gnus-make-thread-indent-array ()
2901   (let ((n 200))
2902     (unless (and gnus-thread-indent-array
2903                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2904       (setq gnus-thread-indent-array (make-vector 201 "")
2905             gnus-thread-indent-array-level gnus-thread-indent-level)
2906       (while (>= n 0)
2907         (aset gnus-thread-indent-array n
2908               (make-string (* n gnus-thread-indent-level) ? ))
2909         (setq n (1- n))))))
2910
2911 (defun gnus-update-summary-mark-positions ()
2912   "Compute where the summary marks are to go."
2913   (save-excursion
2914     (when (gnus-buffer-exists-p gnus-summary-buffer)
2915       (set-buffer gnus-summary-buffer))
2916     (let ((gnus-replied-mark 129)
2917           (gnus-score-below-mark 130)
2918           (gnus-score-over-mark 130)
2919           (gnus-download-mark 131)
2920           (spec gnus-summary-line-format-spec)
2921           gnus-visual pos)
2922       (save-excursion
2923         (gnus-set-work-buffer)
2924         (let ((gnus-summary-line-format-spec spec)
2925               (gnus-newsgroup-downloadable '((0 . t))))
2926           (gnus-summary-insert-line
2927            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2928            0 nil 128 t nil "" nil 1)
2929           (goto-char (point-min))
2930           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2931                                              (- (point) 2)))))
2932           (goto-char (point-min))
2933           (push (cons 'replied (and (search-forward "\201" nil t)
2934                                     (- (point) 2)))
2935                 pos)
2936           (goto-char (point-min))
2937           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2938                 pos)
2939           (goto-char (point-min))
2940           (push (cons 'download
2941                       (and (search-forward "\203" nil t) (- (point) 2)))
2942                 pos)))
2943       (setq gnus-summary-mark-positions pos))))
2944
2945 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2946   "Insert a dummy root in the summary buffer."
2947   (beginning-of-line)
2948   (gnus-add-text-properties
2949    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2950    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2951
2952 (defun gnus-summary-extract-address-component (from)
2953   (or (car (funcall gnus-extract-address-components from))
2954       from))
2955
2956 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2957   (let ((mail-parse-charset gnus-newsgroup-charset)
2958         ; Is it really necessary to do this next part for each summary line?
2959         ; Luckily, doesn't seem to slow things down much.
2960         (mail-parse-ignored-charsets
2961          (save-excursion (set-buffer gnus-summary-buffer)
2962                          gnus-newsgroup-ignored-charsets)))
2963     (or
2964      (and gnus-ignored-from-addresses
2965           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2966           (let ((extra-headers (mail-header-extra header))
2967                 to
2968                 newsgroups)
2969             (cond
2970              ((setq to (cdr (assq 'To extra-headers)))
2971               (concat "-> "
2972                       (gnus-summary-extract-address-component
2973                        (funcall gnus-decode-encoded-word-function to))))
2974              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2975               (concat "=> " newsgroups)))))
2976      (gnus-summary-extract-address-component gnus-tmp-from))))
2977
2978 (defun gnus-summary-insert-line (gnus-tmp-header
2979                                  gnus-tmp-level gnus-tmp-current
2980                                  gnus-tmp-unread gnus-tmp-replied
2981                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2982                                  &optional gnus-tmp-dummy gnus-tmp-score
2983                                  gnus-tmp-process)
2984   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2985          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2986          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2987          (gnus-tmp-score-char
2988           (if (or (null gnus-summary-default-score)
2989                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2990                       gnus-summary-zcore-fuzz))
2991               ?                         ;Whitespace
2992             (if (< gnus-tmp-score gnus-summary-default-score)
2993                 gnus-score-below-mark gnus-score-over-mark)))
2994          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2995          (gnus-tmp-replied
2996           (cond (gnus-tmp-process gnus-process-mark)
2997                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2998                  gnus-cached-mark)
2999                 (gnus-tmp-replied gnus-replied-mark)
3000                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3001                  gnus-forwarded-mark)
3002                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3003                  gnus-saved-mark)
3004                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3005                  gnus-recent-mark)
3006                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3007                  gnus-unseen-mark)
3008                 (t gnus-no-mark)))
3009          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3010          (gnus-tmp-name
3011           (cond
3012            ((string-match "<[^>]+> *$" gnus-tmp-from)
3013             (let ((beg (match-beginning 0)))
3014               (or (and (string-match "^\".+\"" gnus-tmp-from)
3015                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3016                   (substring gnus-tmp-from 0 beg))))
3017            ((string-match "(.+)" gnus-tmp-from)
3018             (substring gnus-tmp-from
3019                        (1+ (match-beginning 0)) (1- (match-end 0))))
3020            (t gnus-tmp-from)))
3021          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3022          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3023          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3024          (buffer-read-only nil))
3025     (when (string= gnus-tmp-name "")
3026       (setq gnus-tmp-name gnus-tmp-from))
3027     (unless (numberp gnus-tmp-lines)
3028       (setq gnus-tmp-lines -1))
3029     (if (= gnus-tmp-lines -1)
3030         (setq gnus-tmp-lines "?")
3031       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3032     (gnus-put-text-property
3033      (point)
3034      (progn (eval gnus-summary-line-format-spec) (point))
3035      'gnus-number gnus-tmp-number)
3036     (when (gnus-visual-p 'summary-highlight 'highlight)
3037       (forward-line -1)
3038       (gnus-run-hooks 'gnus-summary-update-hook)
3039       (forward-line 1))))
3040
3041 (defun gnus-summary-update-line (&optional dont-update)
3042   "Update summary line after change."
3043   (when (and gnus-summary-default-score
3044              (not gnus-summary-inhibit-highlight))
3045     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3046            (article (gnus-summary-article-number))
3047            (score (gnus-summary-article-score article)))
3048       (unless dont-update
3049         (if (and gnus-summary-mark-below
3050                  (< (gnus-summary-article-score)
3051                     gnus-summary-mark-below))
3052             ;; This article has a low score, so we mark it as read.
3053             (when (memq article gnus-newsgroup-unreads)
3054               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3055           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3056             ;; This article was previously marked as read on account
3057             ;; of a low score, but now it has risen, so we mark it as
3058             ;; unread.
3059             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3060         (gnus-summary-update-mark
3061          (if (or (null gnus-summary-default-score)
3062                  (<= (abs (- score gnus-summary-default-score))
3063                      gnus-summary-zcore-fuzz))
3064              ?                          ;Whitespace
3065            (if (< score gnus-summary-default-score)
3066                gnus-score-below-mark gnus-score-over-mark))
3067          'score))
3068       ;; Do visual highlighting.
3069       (when (gnus-visual-p 'summary-highlight 'highlight)
3070         (gnus-run-hooks 'gnus-summary-update-hook)))))
3071
3072 (defvar gnus-tmp-new-adopts nil)
3073
3074 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3075   "Return the number of articles in THREAD.
3076 This may be 0 in some cases -- if none of the articles in
3077 the thread are to be displayed."
3078   (let* ((number
3079          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3080           (cond
3081            ((not (listp thread))
3082             1)
3083            ((and (consp thread) (cdr thread))
3084             (apply
3085              '+ 1 (mapcar
3086                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3087            ((null thread)
3088             1)
3089            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3090             1)
3091            (t 0))))
3092     (when (and level (zerop level) gnus-tmp-new-adopts)
3093       (incf number
3094             (apply '+ (mapcar
3095                        'gnus-summary-number-of-articles-in-thread
3096                        gnus-tmp-new-adopts))))
3097     (if char
3098         (if (> number 1) gnus-not-empty-thread-mark
3099           gnus-empty-thread-mark)
3100       number)))
3101
3102 (defun gnus-summary-set-local-parameters (group)
3103   "Go through the local params of GROUP and set all variable specs in that list."
3104   (let ((params (gnus-group-find-parameter group))
3105         (vars '(quit-config))           ; Ignore quit-config.
3106         elem)
3107     (while params
3108       (setq elem (car params)
3109             params (cdr params))
3110       (and (consp elem)                 ; Has to be a cons.
3111            (consp (cdr elem))           ; The cdr has to be a list.
3112            (symbolp (car elem))         ; Has to be a symbol in there.
3113            (not (memq (car elem) vars))
3114            (ignore-errors               ; So we set it.
3115              (push (car elem) vars)
3116              (make-local-variable (car elem))
3117              (set (car elem) (eval (nth 1 elem))))))))
3118
3119 (defun gnus-summary-read-group (group &optional show-all no-article
3120                                       kill-buffer no-display backward
3121                                       select-articles)
3122   "Start reading news in newsgroup GROUP.
3123 If SHOW-ALL is non-nil, already read articles are also listed.
3124 If NO-ARTICLE is non-nil, no article is selected initially.
3125 If NO-DISPLAY, don't generate a summary buffer."
3126   (let (result)
3127     (while (and group
3128                 (null (setq result
3129                             (let ((gnus-auto-select-next nil))
3130                               (or (gnus-summary-read-group-1
3131                                    group show-all no-article
3132                                    kill-buffer no-display
3133                                    select-articles)
3134                                   (setq show-all nil
3135                                         select-articles nil)))))
3136                 (eq gnus-auto-select-next 'quietly))
3137       (set-buffer gnus-group-buffer)
3138       ;; The entry function called above goes to the next
3139       ;; group automatically, so we go two groups back
3140       ;; if we are searching for the previous group.
3141       (when backward
3142         (gnus-group-prev-unread-group 2))
3143       (if (not (equal group (gnus-group-group-name)))
3144           (setq group (gnus-group-group-name))
3145         (setq group nil)))
3146     result))
3147
3148 (defun gnus-summary-read-group-1 (group show-all no-article
3149                                         kill-buffer no-display
3150                                         &optional select-articles)
3151   ;; Killed foreign groups can't be entered.
3152   ;;  (when (and (not (gnus-group-native-p group))
3153   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3154   ;;    (error "Dead non-native groups can't be entered"))
3155   (gnus-message 5 "Retrieving newsgroup: %s..."
3156                 (gnus-group-decoded-name group))
3157   (let* ((new-group (gnus-summary-setup-buffer group))
3158          (quit-config (gnus-group-quit-config group))
3159          (did-select (and new-group (gnus-select-newsgroup
3160                                      group show-all select-articles))))
3161     (cond
3162      ;; This summary buffer exists already, so we just select it.
3163      ((not new-group)
3164       (gnus-set-global-variables)
3165       (when kill-buffer
3166         (gnus-kill-or-deaden-summary kill-buffer))
3167       (gnus-configure-windows 'summary 'force)
3168       (gnus-set-mode-line 'summary)
3169       (gnus-summary-position-point)
3170       (message "")
3171       t)
3172      ;; We couldn't select this group.
3173      ((null did-select)
3174       (when (and (eq major-mode 'gnus-summary-mode)
3175                  (not (equal (current-buffer) kill-buffer)))
3176         (kill-buffer (current-buffer))
3177         (if (not quit-config)
3178             (progn
3179               ;; Update the info -- marks might need to be removed,
3180               ;; for instance.
3181               (gnus-summary-update-info)
3182               (set-buffer gnus-group-buffer)
3183               (gnus-group-jump-to-group group)
3184               (gnus-group-next-unread-group 1))
3185           (gnus-handle-ephemeral-exit quit-config)))
3186       (let ((grpinfo (gnus-get-info group)))
3187         (if (null (gnus-info-read grpinfo))
3188             (gnus-message 3 "Group %s contains no messages"
3189                           (gnus-group-decoded-name group))
3190           (gnus-message 3 "Can't select group")))
3191       nil)
3192      ;; The user did a `C-g' while prompting for number of articles,
3193      ;; so we exit this group.
3194      ((eq did-select 'quit)
3195       (and (eq major-mode 'gnus-summary-mode)
3196            (not (equal (current-buffer) kill-buffer))
3197            (kill-buffer (current-buffer)))
3198       (when kill-buffer
3199         (gnus-kill-or-deaden-summary kill-buffer))
3200       (if (not quit-config)
3201           (progn
3202             (set-buffer gnus-group-buffer)
3203             (gnus-group-jump-to-group group)
3204             (gnus-group-next-unread-group 1)
3205             (gnus-configure-windows 'group 'force))
3206         (gnus-handle-ephemeral-exit quit-config))
3207       ;; Finally signal the quit.
3208       (signal 'quit nil))
3209      ;; The group was successfully selected.
3210      (t
3211       (gnus-set-global-variables)
3212       ;; Save the active value in effect when the group was entered.
3213       (setq gnus-newsgroup-active
3214             (gnus-copy-sequence
3215              (gnus-active gnus-newsgroup-name)))
3216       ;; You can change the summary buffer in some way with this hook.
3217       (gnus-run-hooks 'gnus-select-group-hook)
3218       (gnus-update-format-specifications
3219        nil 'summary 'summary-mode 'summary-dummy)
3220       (gnus-update-summary-mark-positions)
3221       ;; Do score processing.
3222       (when gnus-use-scoring
3223         (gnus-possibly-score-headers))
3224       ;; Check whether to fill in the gaps in the threads.
3225       (when gnus-build-sparse-threads
3226         (gnus-build-sparse-threads))
3227       ;; Find the initial limit.
3228       (if gnus-show-threads
3229           (if show-all
3230               (let ((gnus-newsgroup-dormant nil))
3231                 (gnus-summary-initial-limit show-all))
3232             (gnus-summary-initial-limit show-all))
3233         ;; When untreaded, all articles are always shown.
3234         (setq gnus-newsgroup-limit
3235               (mapcar
3236                (lambda (header) (mail-header-number header))
3237                gnus-newsgroup-headers)))
3238       ;; Generate the summary buffer.
3239       (unless no-display
3240         (gnus-summary-prepare))
3241       (when gnus-use-trees
3242         (gnus-tree-open group)
3243         (setq gnus-summary-highlight-line-function
3244               'gnus-tree-highlight-article))
3245       ;; If the summary buffer is empty, but there are some low-scored
3246       ;; articles or some excluded dormants, we include these in the
3247       ;; buffer.
3248       (when (and (zerop (buffer-size))
3249                  (not no-display))
3250         (cond (gnus-newsgroup-dormant
3251                (gnus-summary-limit-include-dormant))
3252               ((and gnus-newsgroup-scored show-all)
3253                (gnus-summary-limit-include-expunged t))))
3254       ;; Function `gnus-apply-kill-file' must be called in this hook.
3255       (gnus-run-hooks 'gnus-apply-kill-hook)
3256       (if (and (zerop (buffer-size))
3257                (not no-display))
3258           (progn
3259             ;; This newsgroup is empty.
3260             (gnus-summary-catchup-and-exit nil t)
3261             (gnus-message 6 "No unread news")
3262             (when kill-buffer
3263               (gnus-kill-or-deaden-summary kill-buffer))
3264             ;; Return nil from this function.
3265             nil)
3266         ;; Hide conversation thread subtrees.  We cannot do this in
3267         ;; gnus-summary-prepare-hook since kill processing may not
3268         ;; work with hidden articles.
3269         (and gnus-show-threads
3270              gnus-thread-hide-subtree
3271              (gnus-summary-hide-all-threads))
3272         (when kill-buffer
3273           (gnus-kill-or-deaden-summary kill-buffer))
3274         (gnus-summary-auto-select-subject)
3275         ;; Show first unread article if requested.
3276         (if (and (not no-article)
3277                  (not no-display)
3278                  gnus-newsgroup-unreads
3279                  gnus-auto-select-first)
3280             (progn
3281               (gnus-configure-windows 'summary)
3282               (gnus-summary-goto-article (gnus-summary-article-number)))
3283           ;; Don't select any articles.
3284           (gnus-summary-position-point)
3285           (gnus-configure-windows 'summary 'force)
3286           (gnus-set-mode-line 'summary))
3287         (when (get-buffer-window gnus-group-buffer t)
3288           ;; Gotta use windows, because recenter does weird stuff if
3289           ;; the current buffer ain't the displayed window.
3290           (let ((owin (selected-window)))
3291             (select-window (get-buffer-window gnus-group-buffer t))
3292             (when (gnus-group-goto-group group)
3293               (recenter))
3294             (select-window owin)))
3295         ;; Mark this buffer as "prepared".
3296         (setq gnus-newsgroup-prepared t)
3297         (gnus-run-hooks 'gnus-summary-prepared-hook)
3298         t)))))
3299
3300 (defun gnus-summary-auto-select-subject ()
3301   "Select the subject line on initial group entry."
3302   (goto-char (point-min))
3303   (cond
3304    ((eq gnus-auto-select-subject 'best)
3305     (gnus-summary-best-unread-subject))
3306    ((eq gnus-auto-select-subject 'unread)
3307     (gnus-summary-first-unread-subject))
3308    ((eq gnus-auto-select-subject 'unseen)
3309     (gnus-summary-first-unseen-subject))
3310    ((eq gnus-auto-select-subject 'first)
3311     ;; Do nothing.
3312     )
3313    ((gnus-functionp gnus-auto-select-subject)
3314     (funcall gnus-auto-select-subject))))
3315
3316 (defun gnus-summary-prepare ()
3317   "Generate the summary buffer."
3318   (interactive)
3319   (let ((buffer-read-only nil))
3320     (erase-buffer)
3321     (setq gnus-newsgroup-data nil
3322           gnus-newsgroup-data-reverse nil)
3323     (gnus-run-hooks 'gnus-summary-generate-hook)
3324     ;; Generate the buffer, either with threads or without.
3325     (when gnus-newsgroup-headers
3326       (gnus-summary-prepare-threads
3327        (if gnus-show-threads
3328            (gnus-sort-gathered-threads
3329             (funcall gnus-summary-thread-gathering-function
3330                      (gnus-sort-threads
3331                       (gnus-cut-threads (gnus-make-threads)))))
3332          ;; Unthreaded display.
3333          (gnus-sort-articles gnus-newsgroup-headers))))
3334     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3335     ;; Call hooks for modifying summary buffer.
3336     (goto-char (point-min))
3337     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3338
3339 (defsubst gnus-general-simplify-subject (subject)
3340   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3341   (setq subject
3342         (cond
3343          ;; Truncate the subject.
3344          (gnus-simplify-subject-functions
3345           (gnus-map-function gnus-simplify-subject-functions subject))
3346          ((numberp gnus-summary-gather-subject-limit)
3347           (setq subject (gnus-simplify-subject-re subject))
3348           (if (> (length subject) gnus-summary-gather-subject-limit)
3349               (substring subject 0 gnus-summary-gather-subject-limit)
3350             subject))
3351          ;; Fuzzily simplify it.
3352          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3353           (gnus-simplify-subject-fuzzy subject))
3354          ;; Just remove the leading "Re:".
3355          (t
3356           (gnus-simplify-subject-re subject))))
3357
3358   (if (and gnus-summary-gather-exclude-subject
3359            (string-match gnus-summary-gather-exclude-subject subject))
3360       nil                         ; This article shouldn't be gathered
3361     subject))
3362
3363 (defun gnus-summary-simplify-subject-query ()
3364   "Query where the respool algorithm would put this article."
3365   (interactive)
3366   (gnus-summary-select-article)
3367   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3368
3369 (defun gnus-gather-threads-by-subject (threads)
3370   "Gather threads by looking at Subject headers."
3371   (if (not gnus-summary-make-false-root)
3372       threads
3373     (let ((hashtb (gnus-make-hashtable 1024))
3374           (prev threads)
3375           (result threads)
3376           subject hthread whole-subject)
3377       (while threads
3378         (setq subject (gnus-general-simplify-subject
3379                        (setq whole-subject (mail-header-subject
3380                                             (caar threads)))))
3381         (when subject
3382           (if (setq hthread (gnus-gethash subject hashtb))
3383               (progn
3384                 ;; We enter a dummy root into the thread, if we
3385                 ;; haven't done that already.
3386                 (unless (stringp (caar hthread))
3387                   (setcar hthread (list whole-subject (car hthread))))
3388                 ;; We add this new gathered thread to this gathered
3389                 ;; thread.
3390                 (setcdr (car hthread)
3391                         (nconc (cdar hthread) (list (car threads))))
3392                 ;; Remove it from the list of threads.
3393                 (setcdr prev (cdr threads))
3394                 (setq threads prev))
3395             ;; Enter this thread into the hash table.
3396             (gnus-sethash subject threads hashtb)))
3397         (setq prev threads)
3398         (setq threads (cdr threads)))
3399       result)))
3400
3401 (defun gnus-gather-threads-by-references (threads)
3402   "Gather threads by looking at References headers."
3403   (let ((idhashtb (gnus-make-hashtable 1024))
3404         (thhashtb (gnus-make-hashtable 1024))
3405         (prev threads)
3406         (result threads)
3407         ids references id gthread gid entered ref)
3408     (while threads
3409       (when (setq references (mail-header-references (caar threads)))
3410         (setq id (mail-header-id (caar threads))
3411               ids (gnus-split-references references)
3412               entered nil)
3413         (while (setq ref (pop ids))
3414           (setq ids (delete ref ids))
3415           (if (not (setq gid (gnus-gethash ref idhashtb)))
3416               (progn
3417                 (gnus-sethash ref id idhashtb)
3418                 (gnus-sethash id threads thhashtb))
3419             (setq gthread (gnus-gethash gid thhashtb))
3420             (unless entered
3421               ;; We enter a dummy root into the thread, if we
3422               ;; haven't done that already.
3423               (unless (stringp (caar gthread))
3424                 (setcar gthread (list (mail-header-subject (caar gthread))
3425                                       (car gthread))))
3426               ;; We add this new gathered thread to this gathered
3427               ;; thread.
3428               (setcdr (car gthread)
3429                       (nconc (cdar gthread) (list (car threads)))))
3430             ;; Add it into the thread hash table.
3431             (gnus-sethash id gthread thhashtb)
3432             (setq entered t)
3433             ;; Remove it from the list of threads.
3434             (setcdr prev (cdr threads))
3435             (setq threads prev))))
3436       (setq prev threads)
3437       (setq threads (cdr threads)))
3438     result))
3439
3440 (defun gnus-sort-gathered-threads (threads)
3441   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3442   (let ((result threads))
3443     (while threads
3444       (when (stringp (caar threads))
3445         (setcdr (car threads)
3446                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3447       (setq threads (cdr threads)))
3448     result))
3449
3450 (defun gnus-thread-loop-p (root thread)
3451   "Say whether ROOT is in THREAD."
3452   (let ((stack (list thread))
3453         (infloop 0)
3454         th)
3455     (while (setq thread (pop stack))
3456       (setq th (cdr thread))
3457       (while (and th
3458                   (not (eq (caar th) root)))
3459         (pop th))
3460       (if th
3461           ;; We have found a loop.
3462           (let (ref-dep)
3463             (setcdr thread (delq (car th) (cdr thread)))
3464             (if (boundp (setq ref-dep (intern "none"
3465                                               gnus-newsgroup-dependencies)))
3466                 (setcdr (symbol-value ref-dep)
3467                         (nconc (cdr (symbol-value ref-dep))
3468                                (list (car th))))
3469               (set ref-dep (list nil (car th))))
3470             (setq infloop 1
3471                   stack nil))
3472         ;; Push all the subthreads onto the stack.
3473         (push (cdr thread) stack)))
3474     infloop))
3475
3476 (defun gnus-make-threads ()
3477   "Go through the dependency hashtb and find the roots.  Return all threads."
3478   (let (threads)
3479     (while (catch 'infloop
3480              (mapatoms
3481               (lambda (refs)
3482                 ;; Deal with self-referencing References loops.
3483                 (when (and (car (symbol-value refs))
3484                            (not (zerop
3485                                  (apply
3486                                   '+
3487                                   (mapcar
3488                                    (lambda (thread)
3489                                      (gnus-thread-loop-p
3490                                       (car (symbol-value refs)) thread))
3491                                    (cdr (symbol-value refs)))))))
3492                   (setq threads nil)
3493                   (throw 'infloop t))
3494                 (unless (car (symbol-value refs))
3495              ;; These threads do not refer back to any other articles,
3496                   ;; so they're roots.
3497                   (setq threads (append (cdr (symbol-value refs)) threads))))
3498               gnus-newsgroup-dependencies)))
3499     threads))
3500
3501 ;; Build the thread tree.
3502 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3503   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3504
3505 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3506 if it was already present.
3507
3508 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3509 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3510 Message-IDs will be renamed be renamed to a unique Message-ID before
3511 being entered.
3512
3513 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3514   (let* ((id (mail-header-id header))
3515          (id-dep (and id (intern id dependencies)))
3516          ref ref-dep ref-header)
3517     ;; Enter this `header' in the `dependencies' table.
3518     (cond
3519      ((not id-dep)
3520       (setq header nil))
3521      ;; The first two cases do the normal part: enter a new `header'
3522      ;; in the `dependencies' table.
3523      ((not (boundp id-dep))
3524       (set id-dep (list header)))
3525      ((null (car (symbol-value id-dep)))
3526       (setcar (symbol-value id-dep) header))
3527
3528      ;; From here the `header' was already present in the
3529      ;; `dependencies' table.
3530      (force-new
3531       ;; Overrides an existing entry;
3532       ;; just set the header part of the entry.
3533       (setcar (symbol-value id-dep) header))
3534
3535      ;; Renames the existing `header' to a unique Message-ID.
3536      ((not gnus-summary-ignore-duplicates)
3537       ;; An article with this Message-ID has already been seen.
3538       ;; We rename the Message-ID.
3539       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3540            (list header))
3541       (mail-header-set-id header id))
3542
3543      ;; The last case ignores an existing entry, except it adds any
3544      ;; additional Xrefs (in case the two articles came from different
3545      ;; servers.
3546      ;; Also sets `header' to `nil' meaning that the `dependencies'
3547      ;; table was *not* modified.
3548      (t
3549       (mail-header-set-xref
3550        (car (symbol-value id-dep))
3551        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3552                    "")
3553                (or (mail-header-xref header) "")))
3554       (setq header nil)))
3555
3556     (when header
3557       ;; First check if that we are not creating a References loop.
3558       (setq ref (gnus-parent-id (mail-header-references header)))
3559       (while (and ref
3560                   (setq ref-dep (intern-soft ref dependencies))
3561                   (boundp ref-dep)
3562                   (setq ref-header (car (symbol-value ref-dep))))
3563         (if (string= id ref)
3564             ;; Yuk!  This is a reference loop.  Make the article be a
3565             ;; root article.
3566             (progn
3567               (mail-header-set-references (car (symbol-value id-dep)) "none")
3568               (setq ref nil))
3569           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3570       (setq ref (gnus-parent-id (mail-header-references header)))
3571       (setq ref-dep (intern (or ref "none") dependencies))
3572       (if (boundp ref-dep)
3573           (setcdr (symbol-value ref-dep)
3574                   (nconc (cdr (symbol-value ref-dep))
3575                          (list (symbol-value id-dep))))
3576         (set ref-dep (list nil (symbol-value id-dep)))))
3577     header))
3578
3579 (defun gnus-build-sparse-threads ()
3580   (let ((headers gnus-newsgroup-headers)
3581         (mail-parse-charset gnus-newsgroup-charset)
3582         (gnus-summary-ignore-duplicates t)
3583         header references generation relations
3584         subject child end new-child date)
3585     ;; First we create an alist of generations/relations, where
3586     ;; generations is how much we trust the relation, and the relation
3587     ;; is parent/child.
3588     (gnus-message 7 "Making sparse threads...")
3589     (save-excursion
3590       (nnheader-set-temp-buffer " *gnus sparse threads*")
3591       (while (setq header (pop headers))
3592         (when (and (setq references (mail-header-references header))
3593                    (not (string= references "")))
3594           (insert references)
3595           (setq child (mail-header-id header)
3596                 subject (mail-header-subject header)
3597                 date (mail-header-date header)
3598                 generation 0)
3599           (while (search-backward ">" nil t)
3600             (setq end (1+ (point)))
3601             (when (search-backward "<" nil t)
3602               (setq new-child (buffer-substring (point) end))
3603               (push (list (incf generation)
3604                           child (setq child new-child)
3605                           subject date)
3606                     relations)))
3607           (when child
3608             (push (list (1+ generation) child nil subject) relations))
3609           (erase-buffer)))
3610       (kill-buffer (current-buffer)))
3611     ;; Sort over trustworthiness.
3612     (mapcar
3613      (lambda (relation)
3614        (when (gnus-dependencies-add-header
3615               (make-full-mail-header
3616                gnus-reffed-article-number
3617                (nth 3 relation) "" (or (nth 4 relation) "")
3618                (nth 1 relation)
3619                (or (nth 2 relation) "") 0 0 "")
3620               gnus-newsgroup-dependencies nil)
3621          (push gnus-reffed-article-number gnus-newsgroup-limit)
3622          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3623          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3624                gnus-newsgroup-reads)
3625          (decf gnus-reffed-article-number)))
3626      (sort relations 'car-less-than-car))
3627     (gnus-message 7 "Making sparse threads...done")))
3628
3629 (defun gnus-build-old-threads ()
3630   ;; Look at all the articles that refer back to old articles, and
3631   ;; fetch the headers for the articles that aren't there.  This will
3632   ;; build complete threads - if the roots haven't been expired by the
3633   ;; server, that is.
3634   (let ((mail-parse-charset gnus-newsgroup-charset)
3635         id heads)
3636     (mapatoms
3637      (lambda (refs)
3638        (when (not (car (symbol-value refs)))
3639          (setq heads (cdr (symbol-value refs)))
3640          (while heads
3641            (if (memq (mail-header-number (caar heads))
3642                      gnus-newsgroup-dormant)
3643                (setq heads (cdr heads))
3644              (setq id (symbol-name refs))
3645              (while (and (setq id (gnus-build-get-header id))
3646                          (not (car (gnus-id-to-thread id)))))
3647              (setq heads nil)))))
3648      gnus-newsgroup-dependencies)))
3649
3650 ;; This function has to be called with point after the article number
3651 ;; on the beginning of the line.
3652 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3653   (let ((eol (gnus-point-at-eol))
3654         (buffer (current-buffer))
3655         header)
3656
3657     ;; overview: [num subject from date id refs chars lines misc]
3658     (unwind-protect
3659         (progn
3660           (narrow-to-region (point) eol)
3661           (unless (eobp)
3662             (forward-char))
3663
3664           (setq header
3665                 (make-full-mail-header
3666                  number                 ; number
3667                  (funcall gnus-decode-encoded-word-function
3668                           (nnheader-nov-field)) ; subject
3669                  (funcall gnus-decode-encoded-word-function
3670                           (nnheader-nov-field)) ; from
3671                  (nnheader-nov-field)   ; date
3672                  (nnheader-nov-read-message-id) ; id
3673                  (nnheader-nov-field)   ; refs
3674                  (nnheader-nov-read-integer) ; chars
3675                  (nnheader-nov-read-integer) ; lines
3676                  (unless (eobp)
3677                    (if (looking-at "Xref: ")
3678                        (goto-char (match-end 0)))
3679                    (nnheader-nov-field)) ; Xref
3680                  (nnheader-nov-parse-extra)))) ; extra
3681
3682       (widen))
3683
3684     (when gnus-alter-header-function
3685       (funcall gnus-alter-header-function header))
3686     (gnus-dependencies-add-header header dependencies force-new)))
3687
3688 (defun gnus-build-get-header (id)
3689   "Look through the buffer of NOV lines and find the header to ID.
3690 Enter this line into the dependencies hash table, and return
3691 the id of the parent article (if any)."
3692   (let ((deps gnus-newsgroup-dependencies)
3693         found header)
3694     (prog1
3695         (save-excursion
3696           (set-buffer nntp-server-buffer)
3697           (let ((case-fold-search nil))
3698             (goto-char (point-min))
3699             (while (and (not found)
3700                         (search-forward id nil t))
3701               (beginning-of-line)
3702               (setq found (looking-at
3703                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3704                                    (regexp-quote id))))
3705               (or found (beginning-of-line 2)))
3706             (when found
3707               (beginning-of-line)
3708               (and
3709                (setq header (gnus-nov-parse-line
3710                              (read (current-buffer)) deps))
3711                (gnus-parent-id (mail-header-references header))))))
3712       (when header
3713         (let ((number (mail-header-number header)))
3714           (push number gnus-newsgroup-limit)
3715           (push header gnus-newsgroup-headers)
3716           (if (memq number gnus-newsgroup-unselected)
3717               (progn
3718                 (push number gnus-newsgroup-unreads)
3719                 (setq gnus-newsgroup-unselected
3720                       (delq number gnus-newsgroup-unselected)))
3721             (push number gnus-newsgroup-ancient)))))))
3722
3723 (defun gnus-build-all-threads ()
3724   "Read all the headers."
3725   (let ((gnus-summary-ignore-duplicates t)
3726         (mail-parse-charset gnus-newsgroup-charset)
3727         (dependencies gnus-newsgroup-dependencies)
3728         header article)
3729     (save-excursion
3730       (set-buffer nntp-server-buffer)
3731       (let ((case-fold-search nil))
3732         (goto-char (point-min))
3733         (while (not (eobp))
3734           (ignore-errors
3735             (setq article (read (current-buffer))
3736                   header (gnus-nov-parse-line article dependencies)))
3737           (when header
3738             (save-excursion
3739               (set-buffer gnus-summary-buffer)
3740               (push header gnus-newsgroup-headers)
3741               (if (memq (setq article (mail-header-number header))
3742                         gnus-newsgroup-unselected)
3743                   (progn
3744                     (push article gnus-newsgroup-unreads)
3745                     (setq gnus-newsgroup-unselected
3746                           (delq article gnus-newsgroup-unselected)))
3747                 (push article gnus-newsgroup-ancient)))
3748             (forward-line 1)))))))
3749
3750 (defun gnus-summary-update-article-line (article header)
3751   "Update the line for ARTICLE using HEADERS."
3752   (let* ((id (mail-header-id header))
3753          (thread (gnus-id-to-thread id)))
3754     (unless thread
3755       (error "Article in no thread"))
3756     ;; Update the thread.
3757     (setcar thread header)
3758     (gnus-summary-goto-subject article)
3759     (let* ((datal (gnus-data-find-list article))
3760            (data (car datal))
3761            (length (when (cdr datal)
3762                      (- (gnus-data-pos data)
3763                         (gnus-data-pos (cadr datal)))))
3764            (buffer-read-only nil)
3765            (level (gnus-summary-thread-level)))
3766       (gnus-delete-line)
3767       (gnus-summary-insert-line
3768        header level nil (gnus-article-mark article)
3769        (memq article gnus-newsgroup-replied)
3770        (memq article gnus-newsgroup-expirable)
3771        ;; Only insert the Subject string when it's different
3772        ;; from the previous Subject string.
3773        (if (and
3774             gnus-show-threads
3775             (gnus-subject-equal
3776              (condition-case ()
3777                  (mail-header-subject
3778                   (gnus-data-header
3779                    (cadr
3780                     (gnus-data-find-list
3781                      article
3782                      (gnus-data-list t)))))
3783                ;; Error on the side of excessive subjects.
3784                (error ""))
3785              (mail-header-subject header)))
3786            ""
3787          (mail-header-subject header))
3788        nil (cdr (assq article gnus-newsgroup-scored))
3789        (memq article gnus-newsgroup-processable))
3790       (when length
3791         (gnus-data-update-list
3792          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3793
3794 (defun gnus-summary-update-article (article &optional iheader)
3795   "Update ARTICLE in the summary buffer."
3796   (set-buffer gnus-summary-buffer)
3797   (let* ((header (gnus-summary-article-header article))
3798          (id (mail-header-id header))
3799          (data (gnus-data-find article))
3800          (thread (gnus-id-to-thread id))
3801          (references (mail-header-references header))
3802          (parent
3803           (gnus-id-to-thread
3804            (or (gnus-parent-id
3805                 (when (and references
3806                            (not (equal "" references)))
3807                   references))
3808                "none")))
3809          (buffer-read-only nil)
3810          (old (car thread)))
3811     (when thread
3812       (unless iheader
3813         (setcar thread nil)
3814         (when parent
3815           (delq thread parent)))
3816       (if (gnus-summary-insert-subject id header)
3817        ;; Set the (possibly) new article number in the data structure.
3818           (gnus-data-set-number data (gnus-id-to-article id))
3819         (setcar thread old)
3820         nil))))
3821
3822 (defun gnus-rebuild-thread (id &optional line)
3823   "Rebuild the thread containing ID.
3824 If LINE, insert the rebuilt thread starting on line LINE."
3825   (let ((buffer-read-only nil)
3826         old-pos current thread data)
3827     (if (not gnus-show-threads)
3828         (setq thread (list (car (gnus-id-to-thread id))))
3829       ;; Get the thread this article is part of.
3830       (setq thread (gnus-remove-thread id)))
3831     (setq old-pos (gnus-point-at-bol))
3832     (setq current (save-excursion
3833                     (and (re-search-backward "[\r\n]" nil t)
3834                          (gnus-summary-article-number))))
3835     ;; If this is a gathered thread, we have to go some re-gathering.
3836     (when (stringp (car thread))
3837       (let ((subject (car thread))
3838             roots thr)
3839         (setq thread (cdr thread))
3840         (while thread
3841           (unless (memq (setq thr (gnus-id-to-thread
3842                                    (gnus-root-id
3843                                     (mail-header-id (caar thread)))))
3844                         roots)
3845             (push thr roots))
3846           (setq thread (cdr thread)))
3847         ;; We now have all (unique) roots.
3848         (if (= (length roots) 1)
3849             ;; All the loose roots are now one solid root.
3850             (setq thread (car roots))
3851           (setq thread (cons subject (gnus-sort-threads roots))))))
3852     (let (threads)
3853       ;; We then insert this thread into the summary buffer.
3854       (when line
3855         (goto-char (point-min))
3856         (forward-line (1- line)))
3857       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3858         (if gnus-show-threads
3859             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3860           (gnus-summary-prepare-unthreaded thread))
3861         (setq data (nreverse gnus-newsgroup-data))
3862         (setq threads gnus-newsgroup-threads))
3863       ;; We splice the new data into the data structure.
3864       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3865       ;;!!! then we want to insert at the beginning of the buffer.
3866       ;;!!! That happens to be true with Gnus now, but that may
3867       ;;!!! change in the future.  Perhaps.
3868       (gnus-data-enter-list
3869        (if line nil current) data (- (point) old-pos))
3870       (setq gnus-newsgroup-threads
3871             (nconc threads gnus-newsgroup-threads))
3872       (gnus-data-compute-positions))))
3873
3874 (defun gnus-number-to-header (number)
3875   "Return the header for article NUMBER."
3876   (let ((headers gnus-newsgroup-headers))
3877     (while (and headers
3878                 (not (= number (mail-header-number (car headers)))))
3879       (pop headers))
3880     (when headers
3881       (car headers))))
3882
3883 (defun gnus-parent-headers (in-headers &optional generation)
3884   "Return the headers of the GENERATIONeth parent of HEADERS."
3885   (unless generation
3886     (setq generation 1))
3887   (let ((parent t)
3888         (headers in-headers)
3889         references)
3890     (while (and parent
3891                 (not (zerop generation))
3892                 (setq references (mail-header-references headers)))
3893       (setq headers (if (and references
3894                              (setq parent (gnus-parent-id references)))
3895                         (car (gnus-id-to-thread parent))
3896                       nil))
3897       (decf generation))
3898     (and (not (eq headers in-headers))
3899          headers)))
3900
3901 (defun gnus-id-to-thread (id)
3902   "Return the (sub-)thread where ID appears."
3903   (gnus-gethash id gnus-newsgroup-dependencies))
3904
3905 (defun gnus-id-to-article (id)
3906   "Return the article number of ID."
3907   (let ((thread (gnus-id-to-thread id)))
3908     (when (and thread
3909                (car thread))
3910       (mail-header-number (car thread)))))
3911
3912 (defun gnus-id-to-header (id)
3913   "Return the article headers of ID."
3914   (car (gnus-id-to-thread id)))
3915
3916 (defun gnus-article-displayed-root-p (article)
3917   "Say whether ARTICLE is a root(ish) article."
3918   (let ((level (gnus-summary-thread-level article))
3919         (refs (mail-header-references  (gnus-summary-article-header article)))
3920         particle)
3921     (cond
3922      ((null level) nil)
3923      ((zerop level) t)
3924      ((null refs) t)
3925      ((null (gnus-parent-id refs)) t)
3926      ((and (= 1 level)
3927            (null (setq particle (gnus-id-to-article
3928                                  (gnus-parent-id refs))))
3929            (null (gnus-summary-thread-level particle)))))))
3930
3931 (defun gnus-root-id (id)
3932   "Return the id of the root of the thread where ID appears."
3933   (let (last-id prev)
3934     (while (and id (setq prev (car (gnus-id-to-thread id))))
3935       (setq last-id id
3936             id (gnus-parent-id (mail-header-references prev))))
3937     last-id))
3938
3939 (defun gnus-articles-in-thread (thread)
3940   "Return the list of articles in THREAD."
3941   (cons (mail-header-number (car thread))
3942         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3943
3944 (defun gnus-remove-thread (id &optional dont-remove)
3945   "Remove the thread that has ID in it."
3946   (let (headers thread last-id)
3947     ;; First go up in this thread until we find the root.
3948     (setq last-id (gnus-root-id id)
3949           headers (message-flatten-list (gnus-id-to-thread last-id)))
3950     ;; We have now found the real root of this thread.  It might have
3951     ;; been gathered into some loose thread, so we have to search
3952     ;; through the threads to find the thread we wanted.
3953     (let ((threads gnus-newsgroup-threads)
3954           sub)
3955       (while threads
3956         (setq sub (car threads))
3957         (if (stringp (car sub))
3958             ;; This is a gathered thread, so we look at the roots
3959             ;; below it to find whether this article is in this
3960             ;; gathered root.
3961             (progn
3962               (setq sub (cdr sub))
3963               (while sub
3964                 (when (member (caar sub) headers)
3965                   (setq thread (car threads)
3966                         threads nil
3967                         sub nil))
3968                 (setq sub (cdr sub))))
3969           ;; It's an ordinary thread, so we check it.
3970           (when (eq (car sub) (car headers))
3971             (setq thread sub
3972                   threads nil)))
3973         (setq threads (cdr threads)))
3974       ;; If this article is in no thread, then it's a root.
3975       (if thread
3976           (unless dont-remove
3977             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3978         (setq thread (gnus-id-to-thread last-id)))
3979       (when thread
3980         (prog1
3981             thread                      ; We return this thread.
3982           (unless dont-remove
3983             (if (stringp (car thread))
3984                 (progn
3985                   ;; If we use dummy roots, then we have to remove the
3986                   ;; dummy root as well.
3987                   (when (eq gnus-summary-make-false-root 'dummy)
3988                     ;; We go to the dummy root by going to
3989                     ;; the first sub-"thread", and then one line up.
3990                     (gnus-summary-goto-article
3991                      (mail-header-number (caadr thread)))
3992                     (forward-line -1)
3993                     (gnus-delete-line)
3994                     (gnus-data-compute-positions))
3995                   (setq thread (cdr thread))
3996                   (while thread
3997                     (gnus-remove-thread-1 (car thread))
3998                     (setq thread (cdr thread))))
3999               (gnus-remove-thread-1 thread))))))))
4000
4001 (defun gnus-remove-thread-1 (thread)
4002   "Remove the thread THREAD recursively."
4003   (let ((number (mail-header-number (pop thread)))
4004         d)
4005     (setq thread (reverse thread))
4006     (while thread
4007       (gnus-remove-thread-1 (pop thread)))
4008     (when (setq d (gnus-data-find number))
4009       (goto-char (gnus-data-pos d))
4010       (gnus-summary-show-thread)
4011       (gnus-data-remove
4012        number
4013        (- (gnus-point-at-bol)
4014           (prog1
4015               (1+ (gnus-point-at-eol))
4016             (gnus-delete-line)))))))
4017
4018 (defun gnus-sort-threads-1 (threads func)
4019   (sort (mapcar (lambda (thread)
4020                   (cons (car thread)
4021                         (and (cdr thread)
4022                              (gnus-sort-threads-1 (cdr thread) func))))
4023                 threads) func))
4024
4025 (defun gnus-sort-threads (threads)
4026   "Sort THREADS."
4027   (if (not gnus-thread-sort-functions)
4028       threads
4029     (gnus-message 8 "Sorting threads...")
4030     (prog1
4031         (gnus-sort-threads-1
4032          threads
4033          (gnus-make-sort-function gnus-thread-sort-functions))
4034       (gnus-message 8 "Sorting threads...done"))))
4035
4036 (defun gnus-sort-articles (articles)
4037   "Sort ARTICLES."
4038   (when gnus-article-sort-functions
4039     (gnus-message 7 "Sorting articles...")
4040     (prog1
4041         (setq gnus-newsgroup-headers
4042               (sort articles (gnus-make-sort-function
4043                               gnus-article-sort-functions)))
4044       (gnus-message 7 "Sorting articles...done"))))
4045
4046 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4047 (defmacro gnus-thread-header (thread)
4048   "Return header of first article in THREAD.
4049 Note that THREAD must never, ever be anything else than a variable -
4050 using some other form will lead to serious barfage."
4051   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4052   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4053   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4054         (vector thread) 2))
4055
4056 (defsubst gnus-article-sort-by-number (h1 h2)
4057   "Sort articles by article number."
4058   (< (mail-header-number h1)
4059      (mail-header-number h2)))
4060
4061 (defun gnus-thread-sort-by-number (h1 h2)
4062   "Sort threads by root article number."
4063   (gnus-article-sort-by-number
4064    (gnus-thread-header h1) (gnus-thread-header h2)))
4065
4066 (defsubst gnus-article-sort-by-lines (h1 h2)
4067   "Sort articles by article Lines header."
4068   (< (mail-header-lines h1)
4069      (mail-header-lines h2)))
4070
4071 (defun gnus-thread-sort-by-lines (h1 h2)
4072   "Sort threads by root article Lines header."
4073   (gnus-article-sort-by-lines
4074    (gnus-thread-header h1) (gnus-thread-header h2)))
4075
4076 (defsubst gnus-article-sort-by-chars (h1 h2)
4077   "Sort articles by octet length."
4078   (< (mail-header-chars h1)
4079      (mail-header-chars h2)))
4080
4081 (defun gnus-thread-sort-by-chars (h1 h2)
4082   "Sort threads by root article octet length."
4083   (gnus-article-sort-by-chars
4084    (gnus-thread-header h1) (gnus-thread-header h2)))
4085
4086 (defsubst gnus-article-sort-by-author (h1 h2)
4087   "Sort articles by root author."
4088   (string-lessp
4089    (let ((extract (funcall
4090                    gnus-extract-address-components
4091                    (mail-header-from h1))))
4092      (or (car extract) (cadr extract) ""))
4093    (let ((extract (funcall
4094                    gnus-extract-address-components
4095                    (mail-header-from h2))))
4096      (or (car extract) (cadr extract) ""))))
4097
4098 (defun gnus-thread-sort-by-author (h1 h2)
4099   "Sort threads by root author."
4100   (gnus-article-sort-by-author
4101    (gnus-thread-header h1)  (gnus-thread-header h2)))
4102
4103 (defsubst gnus-article-sort-by-subject (h1 h2)
4104   "Sort articles by root subject."
4105   (string-lessp
4106    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4107    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4108
4109 (defun gnus-thread-sort-by-subject (h1 h2)
4110   "Sort threads by root subject."
4111   (gnus-article-sort-by-subject
4112    (gnus-thread-header h1) (gnus-thread-header h2)))
4113
4114 (defsubst gnus-article-sort-by-date (h1 h2)
4115   "Sort articles by root article date."
4116   (time-less-p
4117    (gnus-date-get-time (mail-header-date h1))
4118    (gnus-date-get-time (mail-header-date h2))))
4119
4120 (defun gnus-thread-sort-by-date (h1 h2)
4121   "Sort threads by root article date."
4122   (gnus-article-sort-by-date
4123    (gnus-thread-header h1) (gnus-thread-header h2)))
4124
4125 (defsubst gnus-article-sort-by-score (h1 h2)
4126   "Sort articles by root article score.
4127 Unscored articles will be counted as having a score of zero."
4128   (> (or (cdr (assq (mail-header-number h1)
4129                     gnus-newsgroup-scored))
4130          gnus-summary-default-score 0)
4131      (or (cdr (assq (mail-header-number h2)
4132                     gnus-newsgroup-scored))
4133          gnus-summary-default-score 0)))
4134
4135 (defun gnus-thread-sort-by-score (h1 h2)
4136   "Sort threads by root article score."
4137   (gnus-article-sort-by-score
4138    (gnus-thread-header h1) (gnus-thread-header h2)))
4139
4140 (defun gnus-thread-sort-by-total-score (h1 h2)
4141   "Sort threads by the sum of all scores in the thread.
4142 Unscored articles will be counted as having a score of zero."
4143   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4144
4145 (defun gnus-thread-total-score (thread)
4146   ;; This function find the total score of THREAD.
4147   (cond ((null thread)
4148          0)
4149         ((consp thread)
4150          (if (stringp (car thread))
4151              (apply gnus-thread-score-function 0
4152                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4153            (gnus-thread-total-score-1 thread)))
4154         (t
4155          (gnus-thread-total-score-1 (list thread)))))
4156
4157 (defun gnus-thread-total-score-1 (root)
4158   ;; This function find the total score of the thread below ROOT.
4159   (setq root (car root))
4160   (apply gnus-thread-score-function
4161          (or (append
4162               (mapcar 'gnus-thread-total-score
4163                       (cdr (gnus-id-to-thread (mail-header-id root))))
4164               (when (> (mail-header-number root) 0)
4165                 (list (or (cdr (assq (mail-header-number root)
4166                                      gnus-newsgroup-scored))
4167                           gnus-summary-default-score 0))))
4168              (list gnus-summary-default-score)
4169              '(0))))
4170
4171 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4172 (defvar gnus-tmp-prev-subject nil)
4173 (defvar gnus-tmp-false-parent nil)
4174 (defvar gnus-tmp-root-expunged nil)
4175 (defvar gnus-tmp-dummy-line nil)
4176
4177 (eval-when-compile (defvar gnus-tmp-header))
4178 (defun gnus-extra-header (type &optional header)
4179   "Return the extra header of TYPE."
4180   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4181       ""))
4182
4183 (defvar gnus-tmp-thread-tree-header-string "")
4184
4185 (defvar gnus-sum-thread-tree-root "> "
4186   "With %B spec, used for the root of a thread.
4187 If nil, use subject instead.")
4188 (defvar gnus-sum-thread-tree-single-indent ""
4189   "With %B spec, used for a thread with just one message.
4190 If nil, use subject instead.")
4191 (defvar gnus-sum-thread-tree-vertical "| "
4192   "With %B spec, used for drawing a vertical line.")
4193 (defvar gnus-sum-thread-tree-indent "  "
4194   "With %B spec, used for indenting.")
4195 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4196   "With %B spec, used for a leaf with brothers.")
4197 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4198   "With %B spec, used for a leaf without brothers.")
4199
4200 (defun gnus-summary-prepare-threads (threads)
4201   "Prepare summary buffer from THREADS and indentation LEVEL.
4202 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4203 or a straight list of headers."
4204   (gnus-message 7 "Generating summary...")
4205
4206   (setq gnus-newsgroup-threads threads)
4207   (beginning-of-line)
4208
4209   (let ((gnus-tmp-level 0)
4210         (default-score (or gnus-summary-default-score 0))
4211         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4212         thread number subject stack state gnus-tmp-gathered beg-match
4213         new-roots gnus-tmp-new-adopts thread-end
4214         gnus-tmp-header gnus-tmp-unread
4215         gnus-tmp-replied gnus-tmp-subject-or-nil
4216         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4217         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4218         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4219         tree-stack)
4220
4221     (setq gnus-tmp-prev-subject nil)
4222
4223     (if (vectorp (car threads))
4224         ;; If this is a straight (sic) list of headers, then a
4225         ;; threaded summary display isn't required, so we just create
4226         ;; an unthreaded one.
4227         (gnus-summary-prepare-unthreaded threads)
4228
4229       ;; Do the threaded display.
4230
4231       (while (or threads stack gnus-tmp-new-adopts new-roots)
4232
4233         (if (and (= gnus-tmp-level 0)
4234                  (or (not stack)
4235                      (= (caar stack) 0))
4236                  (not gnus-tmp-false-parent)
4237                  (or gnus-tmp-new-adopts new-roots))
4238             (if gnus-tmp-new-adopts
4239                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4240                       thread (list (car gnus-tmp-new-adopts))
4241                       gnus-tmp-header (caar thread)
4242                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4243               (when new-roots
4244                 (setq thread (list (car new-roots))
4245                       gnus-tmp-header (caar thread)
4246                       new-roots (cdr new-roots))))
4247
4248           (if threads
4249               ;; If there are some threads, we do them before the
4250               ;; threads on the stack.
4251               (setq thread threads
4252                     gnus-tmp-header (caar thread))
4253             ;; There were no current threads, so we pop something off
4254             ;; the stack.
4255             (setq state (car stack)
4256                   gnus-tmp-level (car state)
4257                   tree-stack (cadr state)
4258                   thread (caddr state)
4259                   stack (cdr stack)
4260                   gnus-tmp-header (caar thread))))
4261
4262         (setq gnus-tmp-false-parent nil)
4263         (setq gnus-tmp-root-expunged nil)
4264         (setq thread-end nil)
4265
4266         (if (stringp gnus-tmp-header)
4267             ;; The header is a dummy root.
4268             (cond
4269              ((eq gnus-summary-make-false-root 'adopt)
4270               ;; We let the first article adopt the rest.
4271               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4272                                                (cddar thread)))
4273               (setq gnus-tmp-gathered
4274                     (nconc (mapcar
4275                             (lambda (h) (mail-header-number (car h)))
4276                             (cddar thread))
4277                            gnus-tmp-gathered))
4278               (setq thread (cons (list (caar thread)
4279                                        (cadar thread))
4280                                  (cdr thread)))
4281               (setq gnus-tmp-level -1
4282                     gnus-tmp-false-parent t))
4283              ((eq gnus-summary-make-false-root 'empty)
4284               ;; We print adopted articles with empty subject fields.
4285               (setq gnus-tmp-gathered
4286                     (nconc (mapcar
4287                             (lambda (h) (mail-header-number (car h)))
4288                             (cddar thread))
4289                            gnus-tmp-gathered))
4290               (setq gnus-tmp-level -1))
4291              ((eq gnus-summary-make-false-root 'dummy)
4292               ;; We remember that we probably want to output a dummy
4293               ;; root.
4294               (setq gnus-tmp-dummy-line gnus-tmp-header)
4295               (setq gnus-tmp-prev-subject gnus-tmp-header))
4296              (t
4297               ;; We do not make a root for the gathered
4298               ;; sub-threads at all.
4299               (setq gnus-tmp-level -1)))
4300
4301           (setq number (mail-header-number gnus-tmp-header)
4302                 subject (mail-header-subject gnus-tmp-header))
4303
4304           (cond
4305            ;; If the thread has changed subject, we might want to make
4306            ;; this subthread into a root.
4307            ((and (null gnus-thread-ignore-subject)
4308                  (not (zerop gnus-tmp-level))
4309                  gnus-tmp-prev-subject
4310                  (not (inline
4311                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4312             (setq new-roots (nconc new-roots (list (car thread)))
4313                   thread-end t
4314                   gnus-tmp-header nil))
4315            ;; If the article lies outside the current limit,
4316            ;; then we do not display it.
4317            ((not (memq number gnus-newsgroup-limit))
4318             (setq gnus-tmp-gathered
4319                   (nconc (mapcar
4320                           (lambda (h) (mail-header-number (car h)))
4321                           (cdar thread))
4322                          gnus-tmp-gathered))
4323             (setq gnus-tmp-new-adopts (if (cdar thread)
4324                                           (append gnus-tmp-new-adopts
4325                                                   (cdar thread))
4326                                         gnus-tmp-new-adopts)
4327                   thread-end t
4328                   gnus-tmp-header nil)
4329             (when (zerop gnus-tmp-level)
4330               (setq gnus-tmp-root-expunged t)))
4331            ;; Perhaps this article is to be marked as read?
4332            ((and gnus-summary-mark-below
4333                  (< (or (cdr (assq number gnus-newsgroup-scored))
4334                         default-score)
4335                     gnus-summary-mark-below)
4336                  ;; Don't touch sparse articles.
4337                  (not (gnus-summary-article-sparse-p number))
4338                  (not (gnus-summary-article-ancient-p number)))
4339             (setq gnus-newsgroup-unreads
4340                   (delq number gnus-newsgroup-unreads))
4341             (if gnus-newsgroup-auto-expire
4342                 (push number gnus-newsgroup-expirable)
4343               (push (cons number gnus-low-score-mark)
4344                     gnus-newsgroup-reads))))
4345
4346           (when gnus-tmp-header
4347             ;; We may have an old dummy line to output before this
4348             ;; article.
4349             (when (and gnus-tmp-dummy-line
4350                        (gnus-subject-equal
4351                         gnus-tmp-dummy-line
4352                         (mail-header-subject gnus-tmp-header)))
4353               (gnus-summary-insert-dummy-line
4354                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4355               (setq gnus-tmp-dummy-line nil))
4356
4357             ;; Compute the mark.
4358             (setq gnus-tmp-unread (gnus-article-mark number))
4359
4360             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4361                                   gnus-tmp-header gnus-tmp-level)
4362                   gnus-newsgroup-data)
4363
4364             ;; Actually insert the line.
4365             (setq
4366              gnus-tmp-subject-or-nil
4367              (cond
4368               ((and gnus-thread-ignore-subject
4369                     gnus-tmp-prev-subject
4370                     (not (inline (gnus-subject-equal
4371                                   gnus-tmp-prev-subject subject))))
4372                subject)
4373               ((zerop gnus-tmp-level)
4374                (if (and (eq gnus-summary-make-false-root 'empty)
4375                         (memq number gnus-tmp-gathered)
4376                         gnus-tmp-prev-subject
4377                         (inline (gnus-subject-equal
4378                                  gnus-tmp-prev-subject subject)))
4379                    gnus-summary-same-subject
4380                  subject))
4381               (t gnus-summary-same-subject)))
4382             (if (and (eq gnus-summary-make-false-root 'adopt)
4383                      (= gnus-tmp-level 1)
4384                      (memq number gnus-tmp-gathered))
4385                 (setq gnus-tmp-opening-bracket ?\<
4386                       gnus-tmp-closing-bracket ?\>)
4387               (setq gnus-tmp-opening-bracket ?\[
4388                     gnus-tmp-closing-bracket ?\]))
4389             (setq
4390              gnus-tmp-indentation
4391              (aref gnus-thread-indent-array gnus-tmp-level)
4392              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4393              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4394                                 gnus-summary-default-score 0)
4395              gnus-tmp-score-char
4396              (if (or (null gnus-summary-default-score)
4397                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4398                          gnus-summary-zcore-fuzz))
4399                  ?                      ;Whitespace
4400                (if (< gnus-tmp-score gnus-summary-default-score)
4401                    gnus-score-below-mark gnus-score-over-mark))
4402              gnus-tmp-replied
4403              (cond ((memq number gnus-newsgroup-processable)
4404                     gnus-process-mark)
4405                    ((memq number gnus-newsgroup-cached)
4406                     gnus-cached-mark)
4407                    ((memq number gnus-newsgroup-replied)
4408                     gnus-replied-mark)
4409                    ((memq number gnus-newsgroup-forwarded)
4410                     gnus-forwarded-mark)
4411                    ((memq number gnus-newsgroup-saved)
4412                     gnus-saved-mark)
4413                    ((memq number gnus-newsgroup-recent)
4414                     gnus-recent-mark)
4415                    ((memq number gnus-newsgroup-unseen)
4416                     gnus-unseen-mark)
4417                    (t gnus-no-mark))
4418              gnus-tmp-from (mail-header-from gnus-tmp-header)
4419              gnus-tmp-name
4420              (cond
4421               ((string-match "<[^>]+> *$" gnus-tmp-from)
4422                (setq beg-match (match-beginning 0))
4423                (or (and (string-match "^\".+\"" gnus-tmp-from)
4424                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4425                    (substring gnus-tmp-from 0 beg-match)))
4426               ((string-match "(.+)" gnus-tmp-from)
4427                (substring gnus-tmp-from
4428                           (1+ (match-beginning 0)) (1- (match-end 0))))
4429               (t gnus-tmp-from))
4430              gnus-tmp-thread-tree-header-string
4431              (cond
4432               ((not gnus-show-threads) "")
4433               ((zerop gnus-tmp-level)
4434                (if (cdar thread)
4435                    (or gnus-sum-thread-tree-root subject)
4436                  (or gnus-sum-thread-tree-single-indent subject)))
4437               (t
4438                (concat (apply 'concat
4439                               (mapcar (lambda (item)
4440                                         (if (= item 1)
4441                                             gnus-sum-thread-tree-vertical
4442                                           gnus-sum-thread-tree-indent))
4443                                       (cdr (reverse tree-stack))))
4444                        (if (nth 1 thread)
4445                            gnus-sum-thread-tree-leaf-with-other
4446                          gnus-sum-thread-tree-single-leaf)))))
4447             (when (string= gnus-tmp-name "")
4448               (setq gnus-tmp-name gnus-tmp-from))
4449             (unless (numberp gnus-tmp-lines)
4450               (setq gnus-tmp-lines -1))
4451             (if (= gnus-tmp-lines -1)
4452                 (setq gnus-tmp-lines "?")
4453               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4454             (gnus-put-text-property
4455              (point)
4456              (progn (eval gnus-summary-line-format-spec) (point))
4457              'gnus-number number)
4458             (when gnus-visual-p
4459               (forward-line -1)
4460               (gnus-run-hooks 'gnus-summary-update-hook)
4461               (forward-line 1))
4462
4463             (setq gnus-tmp-prev-subject subject)))
4464
4465         (when (nth 1 thread)
4466           (push (list (max 0 gnus-tmp-level)
4467                       (copy-list tree-stack)
4468                       (nthcdr 1 thread))
4469                 stack))
4470         (push (if (nth 1 thread) 1 0) tree-stack)
4471         (incf gnus-tmp-level)
4472         (setq threads (if thread-end nil (cdar thread)))
4473         (unless threads
4474           (setq gnus-tmp-level 0)))))
4475   (gnus-message 7 "Generating summary...done"))
4476
4477 (defun gnus-summary-prepare-unthreaded (headers)
4478   "Generate an unthreaded summary buffer based on HEADERS."
4479   (let (header number mark)
4480
4481     (beginning-of-line)
4482
4483     (while headers
4484       ;; We may have to root out some bad articles...
4485       (when (memq (setq number (mail-header-number
4486                                 (setq header (pop headers))))
4487                   gnus-newsgroup-limit)
4488         ;; Mark article as read when it has a low score.
4489         (when (and gnus-summary-mark-below
4490                    (< (or (cdr (assq number gnus-newsgroup-scored))
4491                           gnus-summary-default-score 0)
4492                       gnus-summary-mark-below)
4493                    (not (gnus-summary-article-ancient-p number)))
4494           (setq gnus-newsgroup-unreads
4495                 (delq number gnus-newsgroup-unreads))
4496           (if gnus-newsgroup-auto-expire
4497               (push number gnus-newsgroup-expirable)
4498             (push (cons number gnus-low-score-mark)
4499                   gnus-newsgroup-reads)))
4500
4501         (setq mark (gnus-article-mark number))
4502         (push (gnus-data-make number mark (1+ (point)) header 0)
4503               gnus-newsgroup-data)
4504         (gnus-summary-insert-line
4505          header 0 number
4506          mark (memq number gnus-newsgroup-replied)
4507          (memq number gnus-newsgroup-expirable)
4508          (mail-header-subject header) nil
4509          (cdr (assq number gnus-newsgroup-scored))
4510          (memq number gnus-newsgroup-processable))))))
4511
4512 (defun gnus-summary-remove-list-identifiers ()
4513   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4514   (let ((regexp (if (consp gnus-list-identifiers)
4515                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4516                   gnus-list-identifiers))
4517         changed subject)
4518     (when regexp
4519       (dolist (header gnus-newsgroup-headers)
4520         (setq subject (mail-header-subject header)
4521               changed nil)
4522         (while (string-match
4523                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4524                 subject)
4525           (setq subject
4526                 (concat (substring subject 0 (match-beginning 2))
4527                         (substring subject (match-end 0)))
4528                 changed t))
4529         (when (and changed
4530                    (string-match
4531                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4532           (setq subject
4533                 (concat (substring subject 0 (match-beginning 1))
4534                         (substring subject (match-end 1)))))
4535         (when changed
4536           (mail-header-set-subject header subject))))))
4537
4538 (defun gnus-fetch-headers (articles)
4539   "Fetch headers of ARTICLES."
4540   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4541     (gnus-message 5 "Fetching headers for %s..." name)
4542     (prog1
4543         (if (eq 'nov
4544                 (setq gnus-headers-retrieved-by
4545                       (gnus-retrieve-headers
4546                        articles gnus-newsgroup-name
4547                        ;; We might want to fetch old headers, but
4548                        ;; not if there is only 1 article.
4549                        (and (or (and
4550                                  (not (eq gnus-fetch-old-headers 'some))
4551                                  (not (numberp gnus-fetch-old-headers)))
4552                                 (> (length articles) 1))
4553                             gnus-fetch-old-headers))))
4554             (gnus-get-newsgroup-headers-xover
4555              articles nil nil gnus-newsgroup-name t)
4556           (gnus-get-newsgroup-headers))
4557       (gnus-message 5 "Fetching headers for %s...done" name))))
4558
4559 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4560   "Select newsgroup GROUP.
4561 If READ-ALL is non-nil, all articles in the group are selected.
4562 If SELECT-ARTICLES, only select those articles from GROUP."
4563   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4564          ;;!!! Dirty hack; should be removed.
4565          (gnus-summary-ignore-duplicates
4566           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4567               t
4568             gnus-summary-ignore-duplicates))
4569          (info (nth 2 entry))
4570          articles fetched-articles cached)
4571
4572     (unless (gnus-check-server
4573              (set (make-local-variable 'gnus-current-select-method)
4574                   (gnus-find-method-for-group group)))
4575       (error "Couldn't open server"))
4576
4577     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4578         (gnus-activate-group group)     ; Or we can activate it...
4579         (progn                          ; Or we bug out.
4580           (when (equal major-mode 'gnus-summary-mode)
4581             (kill-buffer (current-buffer)))
4582           (error "Couldn't activate group %s: %s"
4583                  group (gnus-status-message group))))
4584
4585     (unless (gnus-request-group group t)
4586       (when (equal major-mode 'gnus-summary-mode)
4587         (kill-buffer (current-buffer)))
4588       (error "Couldn't request group %s: %s"
4589              group (gnus-status-message group)))
4590
4591     (setq gnus-newsgroup-name group
4592           gnus-newsgroup-unselected nil
4593           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4594
4595     (let ((display (gnus-group-find-parameter group 'display)))
4596       (setq gnus-newsgroup-display
4597             (cond
4598              ((not (zerop (or (car-safe read-all) 0)))
4599               ;; The user entered the group with C-u SPC/RET, let's show
4600               ;; all articles.
4601               'gnus-not-ignore)
4602              ((eq display 'all)
4603               'gnus-not-ignore)
4604              ((arrayp display)
4605               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4606              ((numberp display)
4607               ;; The following is probably the "correct" solution, but
4608               ;; it makes Gnus fetch all headers and then limit the
4609               ;; articles (which is slow), so instead we hack the
4610               ;; select-articles parameter instead. -- Simon Josefsson
4611               ;; <jas@kth.se>
4612               ;;
4613               ;; (gnus-byte-compile
4614               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4615               ;;                         display)))))
4616               (setq select-articles
4617                     (gnus-uncompress-range
4618                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4619                              (if (> tmp 0)
4620                                  tmp
4621                                1))
4622                            (cdr (gnus-active group)))))
4623               nil)
4624              (t
4625               nil))))
4626
4627     (gnus-summary-setup-default-charset)
4628
4629     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4630     (when (gnus-virtual-group-p group)
4631       (setq cached gnus-newsgroup-cached))
4632
4633     (setq gnus-newsgroup-unreads
4634           (gnus-set-difference
4635            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4636            gnus-newsgroup-dormant))
4637
4638     (setq gnus-newsgroup-processable nil)
4639
4640     (gnus-update-read-articles group gnus-newsgroup-unreads)
4641
4642     ;; Adjust and set lists of article marks.
4643     (when info
4644       (gnus-adjust-marked-articles info))
4645
4646     (if (setq articles select-articles)
4647         (setq gnus-newsgroup-unselected
4648               (gnus-sorted-intersection
4649                gnus-newsgroup-unreads
4650                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4651       (setq articles (gnus-articles-to-read group read-all)))
4652
4653     (cond
4654      ((null articles)
4655       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4656       'quit)
4657      ((eq articles 0) nil)
4658      (t
4659       ;; Init the dependencies hash table.
4660       (setq gnus-newsgroup-dependencies
4661             (gnus-make-hashtable (length articles)))
4662       (gnus-set-global-variables)
4663       ;; Retrieve the headers and read them in.
4664       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4665
4666       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4667       (when cached
4668         (setq gnus-newsgroup-cached cached))
4669
4670       ;; Suppress duplicates?
4671       (when gnus-suppress-duplicates
4672         (gnus-dup-suppress-articles))
4673
4674       ;; Set the initial limit.
4675       (setq gnus-newsgroup-limit (copy-sequence articles))
4676       ;; Remove canceled articles from the list of unread articles.
4677       (setq fetched-articles
4678             (mapcar (lambda (headers) (mail-header-number headers))
4679                     gnus-newsgroup-headers))
4680       (setq gnus-newsgroup-articles fetched-articles)
4681       (setq gnus-newsgroup-unreads
4682             (gnus-set-sorted-intersection
4683              gnus-newsgroup-unreads fetched-articles))
4684
4685       ;; The `seen' marks are treated specially.
4686       (if (not gnus-newsgroup-seen)
4687           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4688         (dolist (article gnus-newsgroup-articles)
4689           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4690             (push article gnus-newsgroup-unseen)))
4691         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4692
4693       ;; Removed marked articles that do not exist.
4694       (gnus-update-missing-marks
4695        (gnus-sorted-complement fetched-articles articles))
4696       ;; We might want to build some more threads first.
4697       (when (and gnus-fetch-old-headers
4698                  (eq gnus-headers-retrieved-by 'nov))
4699         (if (eq gnus-fetch-old-headers 'invisible)
4700             (gnus-build-all-threads)
4701           (gnus-build-old-threads)))
4702       ;; Let the Gnus agent mark articles as read.
4703       (when gnus-agent
4704         (gnus-agent-get-undownloaded-list))
4705       ;; Remove list identifiers from subject
4706       (when gnus-list-identifiers
4707         (gnus-summary-remove-list-identifiers))
4708       ;; Check whether auto-expire is to be done in this group.
4709       (setq gnus-newsgroup-auto-expire
4710             (gnus-group-auto-expirable-p group))
4711       ;; Set up the article buffer now, if necessary.
4712       (unless gnus-single-article-buffer
4713         (gnus-article-setup-buffer))
4714       ;; First and last article in this newsgroup.
4715       (when gnus-newsgroup-headers
4716         (setq gnus-newsgroup-begin
4717               (mail-header-number (car gnus-newsgroup-headers))
4718               gnus-newsgroup-end
4719               (mail-header-number
4720                (gnus-last-element gnus-newsgroup-headers))))
4721       ;; GROUP is successfully selected.
4722       (or gnus-newsgroup-headers t)))))
4723
4724 (defun gnus-summary-display-make-predicate (display)
4725   (require 'gnus-agent)
4726   (when (= (length display) 1)
4727     (setq display (car display)))
4728   (unless gnus-summary-display-cache
4729     (dolist (elem (append (list (cons 'read 'read)
4730                                 (cons 'unseen 'unseen))
4731                           gnus-article-mark-lists))
4732       (push (cons (cdr elem)
4733                   (gnus-byte-compile
4734                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4735             gnus-summary-display-cache)))
4736   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4737     (gnus-get-predicate display)))
4738
4739 ;; Uses the dynamically bound `number' variable.
4740 (defvar number)
4741 (defun gnus-article-marked-p (type &optional article)
4742   (let ((article (or article number)))
4743     (cond
4744      ((eq type 'tick)
4745       (memq article gnus-newsgroup-marked))
4746      ((eq type 'unsend)
4747       (memq article gnus-newsgroup-unsendable))
4748      ((eq type 'undownload)
4749       (memq article gnus-newsgroup-undownloaded))
4750      ((eq type 'download)
4751       (memq article gnus-newsgroup-downloadable))
4752      ((eq type 'unread)
4753       (memq article gnus-newsgroup-unreads))
4754      ((eq type 'read)
4755       (memq article gnus-newsgroup-reads))
4756      ((eq type 'dormant)
4757       (memq article gnus-newsgroup-dormant) )
4758      ((eq type 'expire)
4759       (memq article gnus-newsgroup-expirable))
4760      ((eq type 'reply)
4761       (memq article gnus-newsgroup-replied))
4762      ((eq type 'killed)
4763       (memq article gnus-newsgroup-killed))
4764      ((eq type 'bookmark)
4765       (assq article gnus-newsgroup-bookmarks))
4766      ((eq type 'score)
4767       (assq article gnus-newsgroup-scored))
4768      ((eq type 'save)
4769       (memq article gnus-newsgroup-saved))
4770      ((eq type 'cache)
4771       (memq article gnus-newsgroup-cached))
4772      ((eq type 'forward)
4773       (memq article gnus-newsgroup-forwarded))
4774      ((eq type 'seen)
4775       (not (memq article gnus-newsgroup-unseen)))
4776      ((eq type 'recent)
4777       (memq article gnus-newsgroup-recent))
4778      (t t))))
4779
4780 (defun gnus-articles-to-read (group &optional read-all)
4781   "Find out what articles the user wants to read."
4782   (let* ((articles
4783           ;; Select all articles if `read-all' is non-nil, or if there
4784           ;; are no unread articles.
4785           (if (or read-all
4786                   (and (zerop (length gnus-newsgroup-marked))
4787                        (zerop (length gnus-newsgroup-unreads)))
4788                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4789               ;; We want to select the headers for all the articles in
4790               ;; the group, so we select either all the active
4791               ;; articles in the group, or (if that's nil), the
4792               ;; articles in the cache.
4793               (or
4794                (gnus-uncompress-range (gnus-active group))
4795                (gnus-cache-articles-in-group group))
4796             ;; Select only the "normal" subset of articles.
4797             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4798                           (copy-sequence gnus-newsgroup-unreads))
4799                   '<)))
4800          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4801          (scored (length scored-list))
4802          (number (length articles))
4803          (marked (+ (length gnus-newsgroup-marked)
4804                     (length gnus-newsgroup-dormant)))
4805          (select
4806           (cond
4807            ((numberp read-all)
4808             read-all)
4809            (t
4810             (condition-case ()
4811                 (cond
4812                  ((and (or (<= scored marked) (= scored number))
4813                        (numberp gnus-large-newsgroup)
4814                        (> number gnus-large-newsgroup))
4815                   (let ((input
4816                          (read-string
4817                           (format
4818                            "How many articles from %s (default %d): "
4819                            (gnus-limit-string
4820                             (gnus-group-decoded-name gnus-newsgroup-name)
4821                             35)
4822                            number))))
4823                     (if (string-match "^[ \t]*$" input) number input)))
4824                  ((and (> scored marked) (< scored number)
4825                        (> (- scored number) 20))
4826                   (let ((input
4827                          (read-string
4828                           (format "%s %s (%d scored, %d total): "
4829                                   "How many articles from"
4830                                   (gnus-group-decoded-name group)
4831                                   scored number))))
4832                     (if (string-match "^[ \t]*$" input)
4833                         number input)))
4834                  (t number))
4835               (quit
4836                (message "Quit getting the articles to read")
4837                nil))))))
4838     (setq select (if (stringp select) (string-to-number select) select))
4839     (if (or (null select) (zerop select))
4840         select
4841       (if (and (not (zerop scored)) (<= (abs select) scored))
4842           (progn
4843             (setq articles (sort scored-list '<))
4844             (setq number (length articles)))
4845         (setq articles (copy-sequence articles)))
4846
4847       (when (< (abs select) number)
4848         (if (< select 0)
4849             ;; Select the N oldest articles.
4850             (setcdr (nthcdr (1- (abs select)) articles) nil)
4851           ;; Select the N most recent articles.
4852           (setq articles (nthcdr (- number select) articles))))
4853       (setq gnus-newsgroup-unselected
4854             (gnus-sorted-intersection
4855              gnus-newsgroup-unreads
4856              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4857       (when gnus-alter-articles-to-read-function
4858         (setq gnus-newsgroup-unreads
4859               (sort
4860                (funcall gnus-alter-articles-to-read-function
4861                         gnus-newsgroup-name gnus-newsgroup-unreads)
4862                '<)))
4863       articles)))
4864
4865 (defun gnus-killed-articles (killed articles)
4866   (let (out)
4867     (while articles
4868       (when (inline (gnus-member-of-range (car articles) killed))
4869         (push (car articles) out))
4870       (setq articles (cdr articles)))
4871     out))
4872
4873 (defun gnus-uncompress-marks (marks)
4874   "Uncompress the mark ranges in MARKS."
4875   (let ((uncompressed '(score bookmark))
4876         out)
4877     (while marks
4878       (if (memq (caar marks) uncompressed)
4879           (push (car marks) out)
4880         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4881       (setq marks (cdr marks)))
4882     out))
4883
4884 (defun gnus-article-mark-to-type (mark)
4885   "Return the type of MARK."
4886   (or (cadr (assq mark gnus-article-special-mark-lists))
4887       'list))
4888
4889 (defun gnus-article-unpropagatable-p (mark)
4890   "Return whether MARK should be propagated to backend."
4891   (memq mark gnus-article-unpropagated-mark-lists))
4892
4893 (defun gnus-adjust-marked-articles (info)
4894   "Set all article lists and remove all marks that are no longer valid."
4895   (let* ((marked-lists (gnus-info-marks info))
4896          (active (gnus-active (gnus-info-group info)))
4897          (min (car active))
4898          (max (cdr active))
4899          (types gnus-article-mark-lists)
4900          marks var articles article mark mark-type)
4901
4902     (dolist (marks marked-lists)
4903       (setq mark (car marks)
4904             mark-type (gnus-article-mark-to-type mark)
4905             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4906
4907       ;; We set the variable according to the type of the marks list,
4908       ;; and then adjust the marks to a subset of the active articles.
4909       (cond
4910        ;; Adjust "simple" lists.
4911        ((eq mark-type 'list)
4912         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4913         (when (memq mark '(tick dormant expire reply save))
4914           (while articles
4915             (when (or (< (setq article (pop articles)) min) (> article max))
4916               (set var (delq article (symbol-value var)))))))
4917        ;; Adjust assocs.
4918        ((eq mark-type 'tuple)
4919         (set var (setq articles (cdr marks)))
4920         (when (not (listp (cdr (symbol-value var))))
4921           (set var (list (symbol-value var))))
4922         (when (not (listp (cdr articles)))
4923           (setq articles (list articles)))
4924         (while articles
4925           (when (or (not (consp (setq article (pop articles))))
4926                     (< (car article) min)
4927                     (> (car article) max))
4928             (set var (delq article (symbol-value var))))))
4929        ;; Adjust ranges (sloppily).
4930        ((eq mark-type 'range)
4931         (cond
4932          ((eq mark 'seen)
4933           (setq articles (cdr marks))
4934           (while (and articles
4935                       (or (and (consp (car articles))
4936                                (> min (cdar articles)))
4937                           (and (numberp (car articles))
4938                                (> min (car articles)))))
4939             (pop articles))
4940           (set var articles))))))))
4941
4942 (defun gnus-update-missing-marks (missing)
4943   "Go through the list of MISSING articles and remove them from the mark lists."
4944   (when missing
4945     (let (var m)
4946       ;; Go through all types.
4947       (dolist (elem gnus-article-mark-lists)
4948         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4949           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4950           (when (symbol-value var)
4951             ;; This list has articles.  So we delete all missing
4952             ;; articles from it.
4953             (setq m missing)
4954             (while m
4955               (set var (delq (pop m) (symbol-value var))))))))))
4956
4957 (defun gnus-update-marks ()
4958   "Enter the various lists of marked articles into the newsgroup info list."
4959   (let ((types gnus-article-mark-lists)
4960         (info (gnus-get-info gnus-newsgroup-name))
4961         type list newmarked symbol delta-marks)
4962     (when info
4963       ;; Add all marks lists to the list of marks lists.
4964       (while (setq type (pop types))
4965         (setq list (symbol-value
4966                     (setq symbol
4967                           (intern (format "gnus-newsgroup-%s" (car type))))))
4968
4969         (when list
4970           ;; Get rid of the entries of the articles that have the
4971           ;; default score.
4972           (when (and (eq (cdr type) 'score)
4973                      gnus-save-score
4974                      list)
4975             (let* ((arts list)
4976                    (prev (cons nil list))
4977                    (all prev))
4978               (while arts
4979                 (if (or (not (consp (car arts)))
4980                         (= (cdar arts) gnus-summary-default-score))
4981                     (setcdr prev (cdr arts))
4982                   (setq prev arts))
4983                 (setq arts (cdr arts)))
4984               (setq list (cdr all)))))
4985
4986         (when (eq (cdr type) 'seen)
4987           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
4988
4989         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4990           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4991
4992         (when (and (gnus-check-backend-function
4993                     'request-set-mark gnus-newsgroup-name)
4994                    (not (gnus-article-unpropagatable-p (cdr type))))
4995           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4996                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4997                  (add (gnus-remove-from-range
4998                        (gnus-copy-sequence list) old)))
4999             (when add
5000               (push (list add 'add (list (cdr type))) delta-marks))
5001             (when del
5002               (push (list del 'del (list (cdr type))) delta-marks))))
5003
5004         (when list
5005           (push (cons (cdr type) list) newmarked)))
5006
5007       (when delta-marks
5008         (unless (gnus-check-group gnus-newsgroup-name)
5009           (error "Can't open server for %s" gnus-newsgroup-name))
5010         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5011
5012       ;; Enter these new marks into the info of the group.
5013       (if (nthcdr 3 info)
5014           (setcar (nthcdr 3 info) newmarked)
5015         ;; Add the marks lists to the end of the info.
5016         (when newmarked
5017           (setcdr (nthcdr 2 info) (list newmarked))))
5018
5019       ;; Cut off the end of the info if there's nothing else there.
5020       (let ((i 5))
5021         (while (and (> i 2)
5022                     (not (nth i info)))
5023           (when (nthcdr (decf i) info)
5024             (setcdr (nthcdr i info) nil)))))))
5025
5026 (defun gnus-set-mode-line (where)
5027   "Set the mode line of the article or summary buffers.
5028 If WHERE is `summary', the summary mode line format will be used."
5029   ;; Is this mode line one we keep updated?
5030   (when (and (memq where gnus-updated-mode-lines)
5031              (symbol-value
5032               (intern (format "gnus-%s-mode-line-format-spec" where))))
5033     (let (mode-string)
5034       (save-excursion
5035         ;; We evaluate this in the summary buffer since these
5036         ;; variables are buffer-local to that buffer.
5037         (set-buffer gnus-summary-buffer)
5038        ;; We bind all these variables that are used in the `eval' form
5039         ;; below.
5040         (let* ((mformat (symbol-value
5041                          (intern
5042                           (format "gnus-%s-mode-line-format-spec" where))))
5043                (gnus-tmp-group-name (gnus-group-decoded-name
5044                                      gnus-newsgroup-name))
5045                (gnus-tmp-article-number (or gnus-current-article 0))
5046                (gnus-tmp-unread gnus-newsgroup-unreads)
5047                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5048                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5049                (gnus-tmp-unread-and-unselected
5050                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5051                             (zerop gnus-tmp-unselected))
5052                        "")
5053                       ((zerop gnus-tmp-unselected)
5054                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5055                       (t (format "{%d(+%d) more}"
5056                                  gnus-tmp-unread-and-unticked
5057                                  gnus-tmp-unselected))))
5058                (gnus-tmp-subject
5059                 (if (and gnus-current-headers
5060                          (vectorp gnus-current-headers))
5061                     (gnus-mode-string-quote
5062                      (mail-header-subject gnus-current-headers))
5063                   ""))
5064                bufname-length max-len
5065                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5066           (setq mode-string (eval mformat))
5067           (setq bufname-length (if (string-match "%b" mode-string)
5068                                    (- (length
5069                                        (buffer-name
5070                                         (if (eq where 'summary)
5071                                             nil
5072                                           (get-buffer gnus-article-buffer))))
5073                                       2)
5074                                  0))
5075           (setq max-len (max 4 (if gnus-mode-non-string-length
5076                                    (- (window-width)
5077                                       gnus-mode-non-string-length
5078                                       bufname-length)
5079                                  (length mode-string))))
5080           ;; We might have to chop a bit of the string off...
5081           (when (> (length mode-string) max-len)
5082             (setq mode-string
5083                   (concat (truncate-string-to-width mode-string (- max-len 3))
5084                           "...")))
5085           ;; Pad the mode string a bit.
5086           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5087       ;; Update the mode line.
5088       (setq mode-line-buffer-identification
5089             (gnus-mode-line-buffer-identification (list mode-string)))
5090       (set-buffer-modified-p t))))
5091
5092 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5093   "Go through the HEADERS list and add all Xrefs to a hash table.
5094 The resulting hash table is returned, or nil if no Xrefs were found."
5095   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5096          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5097          (xref-hashtb (gnus-make-hashtable))
5098          start group entry number xrefs header)
5099     (while headers
5100       (setq header (pop headers))
5101       (when (and (setq xrefs (mail-header-xref header))
5102                  (not (memq (setq number (mail-header-number header))
5103                             unreads)))
5104         (setq start 0)
5105         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5106           (setq start (match-end 0))
5107           (setq group (if prefix
5108                           (concat prefix (substring xrefs (match-beginning 1)
5109                                                     (match-end 1)))
5110                         (substring xrefs (match-beginning 1) (match-end 1))))
5111           (setq number
5112                 (string-to-int (substring xrefs (match-beginning 2)
5113                                           (match-end 2))))
5114           (if (setq entry (gnus-gethash group xref-hashtb))
5115               (setcdr entry (cons number (cdr entry)))
5116             (gnus-sethash group (cons number nil) xref-hashtb)))))
5117     (and start xref-hashtb)))
5118
5119 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5120   "Look through all the headers and mark the Xrefs as read."
5121   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5122         name entry info xref-hashtb idlist method nth4)
5123     (save-excursion
5124       (set-buffer gnus-group-buffer)
5125       (when (setq xref-hashtb
5126                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5127         (mapatoms
5128          (lambda (group)
5129            (unless (string= from-newsgroup (setq name (symbol-name group)))
5130              (setq idlist (symbol-value group))
5131              ;; Dead groups are not updated.
5132              (and (prog1
5133                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5134                             info (nth 2 entry))
5135                     (when (stringp (setq nth4 (gnus-info-method info)))
5136                       (setq nth4 (gnus-server-to-method nth4))))
5137                   ;; Only do the xrefs if the group has the same
5138                   ;; select method as the group we have just read.
5139                   (or (gnus-methods-equal-p
5140                        nth4 (gnus-find-method-for-group from-newsgroup))
5141                       virtual
5142                       (equal nth4 (setq method (gnus-find-method-for-group
5143                                                 from-newsgroup)))
5144                       (and (equal (car nth4) (car method))
5145                            (equal (nth 1 nth4) (nth 1 method))))
5146                   gnus-use-cross-reference
5147                   (or (not (eq gnus-use-cross-reference t))
5148                       virtual
5149                       ;; Only do cross-references on subscribed
5150                       ;; groups, if that is what is wanted.
5151                       (<= (gnus-info-level info) gnus-level-subscribed))
5152                   (gnus-group-make-articles-read name idlist))))
5153          xref-hashtb)))))
5154
5155 (defun gnus-compute-read-articles (group articles)
5156   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5157          (info (nth 2 entry))
5158          (active (gnus-active group))
5159          ninfo)
5160     (when entry
5161       ;; First peel off all invalid article numbers.
5162       (when active
5163         (let ((ids articles)
5164               id first)
5165           (while (setq id (pop ids))
5166             (when (and first (> id (cdr active)))
5167               ;; We'll end up in this situation in one particular
5168               ;; obscure situation.  If you re-scan a group and get
5169               ;; a new article that is cross-posted to a different
5170               ;; group that has not been re-scanned, you might get
5171               ;; crossposted article that has a higher number than
5172               ;; Gnus believes possible.  So we re-activate this
5173               ;; group as well.  This might mean doing the
5174               ;; crossposting thingy will *increase* the number
5175               ;; of articles in some groups.  Tsk, tsk.
5176               (setq active (or (gnus-activate-group group) active)))
5177             (when (or (> id (cdr active))
5178                       (< id (car active)))
5179               (setq articles (delq id articles))))))
5180       ;; If the read list is nil, we init it.
5181       (if (and active
5182                (null (gnus-info-read info))
5183                (> (car active) 1))
5184           (setq ninfo (cons 1 (1- (car active))))
5185         (setq ninfo (gnus-info-read info)))
5186       ;; Then we add the read articles to the range.
5187       (gnus-add-to-range
5188        ninfo (setq articles (sort articles '<))))))
5189
5190 (defun gnus-group-make-articles-read (group articles)
5191   "Update the info of GROUP to say that ARTICLES are read."
5192   (let* ((num 0)
5193          (entry (gnus-gethash group gnus-newsrc-hashtb))
5194          (info (nth 2 entry))
5195          (active (gnus-active group))
5196          range)
5197     (when entry
5198       (setq range (gnus-compute-read-articles group articles))
5199       (save-excursion
5200         (set-buffer gnus-group-buffer)
5201         (gnus-undo-register
5202           `(progn
5203              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5204              (gnus-info-set-read ',info ',(gnus-info-read info))
5205              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5206              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5207              (gnus-group-update-group ,group t))))
5208       ;; Add the read articles to the range.
5209       (gnus-info-set-read info range)
5210       (gnus-request-set-mark group (list (list range 'add '(read))))
5211       ;; Then we have to re-compute how many unread
5212       ;; articles there are in this group.
5213       (when active
5214         (cond
5215          ((not range)
5216           (setq num (- (1+ (cdr active)) (car active))))
5217          ((not (listp (cdr range)))
5218           (setq num (- (cdr active) (- (1+ (cdr range))
5219                                        (car range)))))
5220          (t
5221           (while range
5222             (if (numberp (car range))
5223                 (setq num (1+ num))
5224               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5225             (setq range (cdr range)))
5226           (setq num (- (cdr active) num))))
5227         ;; Update the number of unread articles.
5228         (setcar entry num)
5229         ;; Update the group buffer.
5230         (gnus-group-update-group group t)))))
5231
5232 (defvar gnus-newsgroup-none-id 0)
5233
5234 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5235   (let ((cur nntp-server-buffer)
5236         (dependencies
5237          (or dependencies
5238              (save-excursion (set-buffer gnus-summary-buffer)
5239                              gnus-newsgroup-dependencies)))
5240         headers id end ref
5241         (mail-parse-charset gnus-newsgroup-charset)
5242         (mail-parse-ignored-charsets
5243          (save-excursion (condition-case nil
5244                              (set-buffer gnus-summary-buffer)
5245                            (error))
5246                          gnus-newsgroup-ignored-charsets)))
5247     (save-excursion
5248       (set-buffer nntp-server-buffer)
5249       ;; Translate all TAB characters into SPACE characters.
5250       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5251       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5252       (gnus-run-hooks 'gnus-parse-headers-hook)
5253       (let ((case-fold-search t)
5254             in-reply-to header p lines chars)
5255         (goto-char (point-min))
5256         ;; Search to the beginning of the next header.  Error messages
5257         ;; do not begin with 2 or 3.
5258         (while (re-search-forward "^[23][0-9]+ " nil t)
5259           (setq id nil
5260                 ref nil)
5261           ;; This implementation of this function, with nine
5262           ;; search-forwards instead of the one re-search-forward and
5263           ;; a case (which basically was the old function) is actually
5264           ;; about twice as fast, even though it looks messier.  You
5265           ;; can't have everything, I guess.  Speed and elegance
5266           ;; doesn't always go hand in hand.
5267           (setq
5268            header
5269            (vector
5270             ;; Number.
5271             (prog1
5272                 (read cur)
5273               (end-of-line)
5274               (setq p (point))
5275               (narrow-to-region (point)
5276                                 (or (and (search-forward "\n.\n" nil t)
5277                                          (- (point) 2))
5278                                     (point))))
5279             ;; Subject.
5280             (progn
5281               (goto-char p)
5282               (if (search-forward "\nsubject:" nil t)
5283                   (funcall gnus-decode-encoded-word-function
5284                            (nnheader-header-value))
5285                 "(none)"))
5286             ;; From.
5287             (progn
5288               (goto-char p)
5289               (if (search-forward "\nfrom:" nil t)
5290                   (funcall gnus-decode-encoded-word-function
5291                            (nnheader-header-value))
5292                 "(nobody)"))
5293             ;; Date.
5294             (progn
5295               (goto-char p)
5296               (if (search-forward "\ndate:" nil t)
5297                   (nnheader-header-value) ""))
5298             ;; Message-ID.
5299             (progn
5300               (goto-char p)
5301               (setq id (if (re-search-forward
5302                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5303                            ;; We do it this way to make sure the Message-ID
5304                            ;; is (somewhat) syntactically valid.
5305                            (buffer-substring (match-beginning 1)
5306                                              (match-end 1))
5307                          ;; If there was no message-id, we just fake one
5308                          ;; to make subsequent routines simpler.
5309                          (nnheader-generate-fake-message-id))))
5310             ;; References.
5311             (progn
5312               (goto-char p)
5313               (if (search-forward "\nreferences:" nil t)
5314                   (progn
5315                     (setq end (point))
5316                     (prog1
5317                         (nnheader-header-value)
5318                       (setq ref
5319                             (buffer-substring
5320                              (progn
5321                                (end-of-line)
5322                                (search-backward ">" end t)
5323                                (1+ (point)))
5324                              (progn
5325                                (search-backward "<" end t)
5326                                (point))))))
5327                 ;; Get the references from the in-reply-to header if there
5328                 ;; were no references and the in-reply-to header looks
5329                 ;; promising.
5330                 (if (and (search-forward "\nin-reply-to:" nil t)
5331                          (setq in-reply-to (nnheader-header-value))
5332                          (string-match "<[^>]+>" in-reply-to))
5333                     (let (ref2)
5334                       (setq ref (substring in-reply-to (match-beginning 0)
5335                                            (match-end 0)))
5336                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5337                         (setq ref2 (substring in-reply-to (match-beginning 0)
5338                                               (match-end 0)))
5339                         (when (> (length ref2) (length ref))
5340                           (setq ref ref2)))
5341                       ref)
5342                   (setq ref nil))))
5343             ;; Chars.
5344             (progn
5345               (goto-char p)
5346               (if (search-forward "\nchars: " nil t)
5347                   (if (numberp (setq chars (ignore-errors (read cur))))
5348                       chars -1)
5349                 -1))
5350             ;; Lines.
5351             (progn
5352               (goto-char p)
5353               (if (search-forward "\nlines: " nil t)
5354                   (if (numberp (setq lines (ignore-errors (read cur))))
5355                       lines -1)
5356                 -1))
5357             ;; Xref.
5358             (progn
5359               (goto-char p)
5360               (and (search-forward "\nxref:" nil t)
5361                    (nnheader-header-value)))
5362             ;; Extra.
5363             (when gnus-extra-headers
5364               (let ((extra gnus-extra-headers)
5365                     out)
5366                 (while extra
5367                   (goto-char p)
5368                   (when (search-forward
5369                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5370                     (push (cons (car extra) (nnheader-header-value))
5371                           out))
5372                   (pop extra))
5373                 out))))
5374           (when (equal id ref)
5375             (setq ref nil))
5376
5377           (when gnus-alter-header-function
5378             (funcall gnus-alter-header-function header)
5379             (setq id (mail-header-id header)
5380                   ref (gnus-parent-id (mail-header-references header))))
5381
5382           (when (setq header
5383                       (gnus-dependencies-add-header
5384                        header dependencies force-new))
5385             (push header headers))
5386           (goto-char (point-max))
5387           (widen))
5388         (nreverse headers)))))
5389
5390 ;; Goes through the xover lines and returns a list of vectors
5391 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5392                                                   force-new dependencies
5393                                                   group also-fetch-heads)
5394   "Parse the news overview data in the server buffer.
5395 Return a list of headers that match SEQUENCE (see
5396 `nntp-retrieve-headers')."
5397   ;; Get the Xref when the users reads the articles since most/some
5398   ;; NNTP servers do not include Xrefs when using XOVER.
5399   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5400   (let ((mail-parse-charset gnus-newsgroup-charset)
5401         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5402         (cur nntp-server-buffer)
5403         (dependencies (or dependencies gnus-newsgroup-dependencies))
5404         (allp (cond
5405                ((eq gnus-read-all-available-headers t)
5406                 t)
5407                ((stringp gnus-read-all-available-headers)
5408                 (string-match gnus-read-all-available-headers group))
5409                (t
5410                 nil)))
5411         number headers header)
5412     (save-excursion
5413       (set-buffer nntp-server-buffer)
5414       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5415       ;; Allow the user to mangle the headers before parsing them.
5416       (gnus-run-hooks 'gnus-parse-headers-hook)
5417       (goto-char (point-min))
5418       (while (not (eobp))
5419         (condition-case ()
5420             (while (and (or sequence allp)
5421                         (not (eobp)))
5422               (setq number (read cur))
5423               (when (not allp)
5424                 (while (and sequence
5425                             (< (car sequence) number))
5426                   (setq sequence (cdr sequence))))
5427               (when (and (or allp
5428                              (and sequence
5429                                   (eq number (car sequence))))
5430                          (progn
5431                            (setq sequence (cdr sequence))
5432                            (setq header (inline
5433                                           (gnus-nov-parse-line
5434                                            number dependencies force-new)))))
5435                 (push header headers))
5436               (forward-line 1))
5437           (error
5438            (gnus-error 4 "Strange nov line (%d)"
5439                        (count-lines (point-min) (point)))))
5440         (forward-line 1))
5441       ;; A common bug in inn is that if you have posted an article and
5442       ;; then retrieves the active file, it will answer correctly --
5443       ;; the new article is included.  However, a NOV entry for the
5444       ;; article may not have been generated yet, so this may fail.
5445       ;; We work around this problem by retrieving the last few
5446       ;; headers using HEAD.
5447       (if (or (not also-fetch-heads)
5448               (not sequence))
5449           ;; We (probably) got all the headers.
5450           (nreverse headers)
5451         (let ((gnus-nov-is-evil t))
5452           (nconc
5453            (nreverse headers)
5454            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5455              (gnus-get-newsgroup-headers))))))))
5456
5457 (defun gnus-article-get-xrefs ()
5458   "Fill in the Xref value in `gnus-current-headers', if necessary.
5459 This is meant to be called in `gnus-article-internal-prepare-hook'."
5460   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5461                                  gnus-current-headers)))
5462     (or (not gnus-use-cross-reference)
5463         (not headers)
5464         (and (mail-header-xref headers)
5465              (not (string= (mail-header-xref headers) "")))
5466         (let ((case-fold-search t)
5467               xref)
5468           (save-restriction
5469             (nnheader-narrow-to-headers)
5470             (goto-char (point-min))
5471             (when (or (and (not (eobp))
5472                            (eq (downcase (char-after)) ?x)
5473                            (looking-at "Xref:"))
5474                       (search-forward "\nXref:" nil t))
5475               (goto-char (1+ (match-end 0)))
5476               (setq xref (buffer-substring (point)
5477                                            (progn (end-of-line) (point))))
5478               (mail-header-set-xref headers xref)))))))
5479
5480 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5481   "Find article ID and insert the summary line for that article.
5482 OLD-HEADER can either be a header or a line number to insert
5483 the subject line on."
5484   (let* ((line (and (numberp old-header) old-header))
5485          (old-header (and (vectorp old-header) old-header))
5486          (header (cond ((and old-header use-old-header)
5487                         old-header)
5488                        ((and (numberp id)
5489                              (gnus-number-to-header id))
5490                         (gnus-number-to-header id))
5491                        (t
5492                         (gnus-read-header id))))
5493          (number (and (numberp id) id))
5494          d)
5495     (when header
5496       ;; Rebuild the thread that this article is part of and go to the
5497       ;; article we have fetched.
5498       (when (and (not gnus-show-threads)
5499                  old-header)
5500         (when (and number
5501                    (setq d (gnus-data-find (mail-header-number old-header))))
5502           (goto-char (gnus-data-pos d))
5503           (gnus-data-remove
5504            number
5505            (- (gnus-point-at-bol)
5506               (prog1
5507                   (1+ (gnus-point-at-eol))
5508                 (gnus-delete-line))))))
5509       (when old-header
5510         (mail-header-set-number header (mail-header-number old-header)))
5511       (setq gnus-newsgroup-sparse
5512             (delq (setq number (mail-header-number header))
5513                   gnus-newsgroup-sparse))
5514       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5515       (push number gnus-newsgroup-limit)
5516       (gnus-rebuild-thread (mail-header-id header) line)
5517       (gnus-summary-goto-subject number nil t))
5518     (when (and (numberp number)
5519                (> number 0))
5520       ;; We have to update the boundaries even if we can't fetch the
5521       ;; article if ID is a number -- so that the next `P' or `N'
5522       ;; command will fetch the previous (or next) article even
5523       ;; if the one we tried to fetch this time has been canceled.
5524       (when (> number gnus-newsgroup-end)
5525         (setq gnus-newsgroup-end number))
5526       (when (< number gnus-newsgroup-begin)
5527         (setq gnus-newsgroup-begin number))
5528       (setq gnus-newsgroup-unselected
5529             (delq number gnus-newsgroup-unselected)))
5530     ;; Report back a success?
5531     (and header (mail-header-number header))))
5532
5533 ;;; Process/prefix in the summary buffer
5534
5535 (defun gnus-summary-work-articles (n)
5536   "Return a list of articles to be worked upon.
5537 The prefix argument, the list of process marked articles, and the
5538 current article will be taken into consideration."
5539   (save-excursion
5540     (set-buffer gnus-summary-buffer)
5541     (cond
5542      (n
5543       ;; A numerical prefix has been given.
5544       (setq n (prefix-numeric-value n))
5545       (let ((backward (< n 0))
5546             (n (abs (prefix-numeric-value n)))
5547             articles article)
5548         (save-excursion
5549           (while
5550               (and (> n 0)
5551                    (push (setq article (gnus-summary-article-number))
5552                          articles)
5553                    (if backward
5554                        (gnus-summary-find-prev nil article)
5555                      (gnus-summary-find-next nil article)))
5556             (decf n)))
5557         (nreverse articles)))
5558      ((and (gnus-region-active-p) (mark))
5559       (message "region active")
5560       ;; Work on the region between point and mark.
5561       (let ((max (max (point) (mark)))
5562             articles article)
5563         (save-excursion
5564           (goto-char (min (min (point) (mark))))
5565           (while
5566               (and
5567                (push (setq article (gnus-summary-article-number)) articles)
5568                (gnus-summary-find-next nil article)
5569                (< (point) max)))
5570           (nreverse articles))))
5571      (gnus-newsgroup-processable
5572       ;; There are process-marked articles present.
5573       ;; Save current state.
5574       (gnus-summary-save-process-mark)
5575       ;; Return the list.
5576       (reverse gnus-newsgroup-processable))
5577      (t
5578       ;; Just return the current article.
5579       (list (gnus-summary-article-number))))))
5580
5581 (defmacro gnus-summary-iterate (arg &rest forms)
5582   "Iterate over the process/prefixed articles and do FORMS.
5583 ARG is the interactive prefix given to the command.  FORMS will be
5584 executed with point over the summary line of the articles."
5585   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5586     `(let ((,articles (gnus-summary-work-articles ,arg)))
5587        (while ,articles
5588          (gnus-summary-goto-subject (car ,articles))
5589          ,@forms
5590          (pop ,articles)))))
5591
5592 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5593 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5594
5595 (defun gnus-summary-save-process-mark ()
5596   "Push the current set of process marked articles on the stack."
5597   (interactive)
5598   (push (copy-sequence gnus-newsgroup-processable)
5599         gnus-newsgroup-process-stack))
5600
5601 (defun gnus-summary-kill-process-mark ()
5602   "Push the current set of process marked articles on the stack and unmark."
5603   (interactive)
5604   (gnus-summary-save-process-mark)
5605   (gnus-summary-unmark-all-processable))
5606
5607 (defun gnus-summary-yank-process-mark ()
5608   "Pop the last process mark state off the stack and restore it."
5609   (interactive)
5610   (unless gnus-newsgroup-process-stack
5611     (error "Empty mark stack"))
5612   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5613
5614 (defun gnus-summary-process-mark-set (set)
5615   "Make SET into the current process marked articles."
5616   (gnus-summary-unmark-all-processable)
5617   (while set
5618     (gnus-summary-set-process-mark (pop set))))
5619
5620 ;;; Searching and stuff
5621
5622 (defun gnus-summary-search-group (&optional backward use-level)
5623   "Search for next unread newsgroup.
5624 If optional argument BACKWARD is non-nil, search backward instead."
5625   (save-excursion
5626     (set-buffer gnus-group-buffer)
5627     (when (gnus-group-search-forward
5628            backward nil (if use-level (gnus-group-group-level) nil))
5629       (gnus-group-group-name))))
5630
5631 (defun gnus-summary-best-group (&optional exclude-group)
5632   "Find the name of the best unread group.
5633 If EXCLUDE-GROUP, do not go to this group."
5634   (save-excursion
5635     (set-buffer gnus-group-buffer)
5636     (save-excursion
5637       (gnus-group-best-unread-group exclude-group))))
5638
5639 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5640   (if backward (gnus-summary-find-prev)
5641     (let* ((dummy (gnus-summary-article-intangible-p))
5642            (article (or article (gnus-summary-article-number)))
5643            (arts (gnus-data-find-list article))
5644            result)
5645       (when (and (not dummy)
5646                  (or (not gnus-summary-check-current)
5647                      (not unread)
5648                      (not (gnus-data-unread-p (car arts)))))
5649         (setq arts (cdr arts)))
5650       (when (setq result
5651                   (if unread
5652                       (progn
5653                         (while arts
5654                           (when (or (and undownloaded
5655                                          (eq gnus-undownloaded-mark
5656                                              (gnus-data-mark (car arts))))
5657                                     (gnus-data-unread-p (car arts)))
5658                             (setq result (car arts)
5659                                   arts nil))
5660                           (setq arts (cdr arts)))
5661                         result)
5662                     (car arts)))
5663         (goto-char (gnus-data-pos result))
5664         (gnus-data-number result)))))
5665
5666 (defun gnus-summary-find-prev (&optional unread article)
5667   (let* ((eobp (eobp))
5668          (article (or article (gnus-summary-article-number)))
5669          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5670          result)
5671     (when (and (not eobp)
5672                (or (not gnus-summary-check-current)
5673                    (not unread)
5674                    (not (gnus-data-unread-p (car arts)))))
5675       (setq arts (cdr arts)))
5676     (when (setq result
5677                 (if unread
5678                     (progn
5679                       (while arts
5680                         (when (gnus-data-unread-p (car arts))
5681                           (setq result (car arts)
5682                                 arts nil))
5683                         (setq arts (cdr arts)))
5684                       result)
5685                   (car arts)))
5686       (goto-char (gnus-data-pos result))
5687       (gnus-data-number result))))
5688
5689 (defun gnus-summary-find-subject (subject &optional unread backward article)
5690   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5691          (article (or article (gnus-summary-article-number)))
5692          (articles (gnus-data-list backward))
5693          (arts (gnus-data-find-list article articles))
5694          result)
5695     (when (or (not gnus-summary-check-current)
5696               (not unread)
5697               (not (gnus-data-unread-p (car arts))))
5698       (setq arts (cdr arts)))
5699     (while arts
5700       (and (or (not unread)
5701                (gnus-data-unread-p (car arts)))
5702            (vectorp (gnus-data-header (car arts)))
5703            (gnus-subject-equal
5704             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5705            (setq result (car arts)
5706                  arts nil))
5707       (setq arts (cdr arts)))
5708     (and result
5709          (goto-char (gnus-data-pos result))
5710          (gnus-data-number result))))
5711
5712 (defun gnus-summary-search-forward (&optional unread subject backward)
5713   "Search forward for an article.
5714 If UNREAD, look for unread articles.  If SUBJECT, look for
5715 articles with that subject.  If BACKWARD, search backward instead."
5716   (cond (subject (gnus-summary-find-subject subject unread backward))
5717         (backward (gnus-summary-find-prev unread))
5718         (t (gnus-summary-find-next unread))))
5719
5720 (defun gnus-recenter (&optional n)
5721   "Center point in window and redisplay frame.
5722 Also do horizontal recentering."
5723   (interactive "P")
5724   (when (and gnus-auto-center-summary
5725              (not (eq gnus-auto-center-summary 'vertical)))
5726     (gnus-horizontal-recenter))
5727   (recenter n))
5728
5729 (defun gnus-summary-recenter ()
5730   "Center point in the summary window.
5731 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5732 displayed, no centering will be performed."
5733   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5734 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5735   (interactive)
5736   (let* ((top (cond ((< (window-height) 4) 0)
5737                     ((< (window-height) 7) 1)
5738                     (t (if (numberp gnus-auto-center-summary)
5739                            gnus-auto-center-summary
5740                          2))))
5741          (height (1- (window-height)))
5742          (bottom (save-excursion (goto-char (point-max))
5743                                  (forward-line (- height))
5744                                  (point)))
5745          (window (get-buffer-window (current-buffer))))
5746     ;; The user has to want it.
5747     (when gnus-auto-center-summary
5748       (when (get-buffer-window gnus-article-buffer)
5749         ;; Only do recentering when the article buffer is displayed,
5750       ;; Set the window start to either `bottom', which is the biggest
5751         ;; possible valid number, or the second line from the top,
5752         ;; whichever is the least.
5753         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5754           (if (> bottom top-pos)
5755               ;; Keep the second line from the top visible
5756               (set-window-start window top-pos t)
5757             ;; Try to keep the bottom line visible; if it's partially
5758             ;; obscured, either scroll one more line to make it fully
5759             ;; visible, or revert to using TOP-POS.
5760             (save-excursion
5761               (goto-char (point-max))
5762               (forward-line -1)
5763               (let ((last-line-start (point)))
5764                 (goto-char bottom)
5765                 (set-window-start window (point) t)
5766                 (when (not (pos-visible-in-window-p last-line-start window))
5767                   (forward-line 1)
5768                   (set-window-start window (min (point) top-pos) t)))))))
5769       ;; Do horizontal recentering while we're at it.
5770       (when (and (get-buffer-window (current-buffer) t)
5771                  (not (eq gnus-auto-center-summary 'vertical)))
5772         (let ((selected (selected-window)))
5773           (select-window (get-buffer-window (current-buffer) t))
5774           (gnus-summary-position-point)
5775           (gnus-horizontal-recenter)
5776           (select-window selected))))))
5777
5778 (defun gnus-summary-jump-to-group (newsgroup)
5779   "Move point to NEWSGROUP in group mode buffer."
5780   ;; Keep update point of group mode buffer if visible.
5781   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5782       (save-window-excursion
5783         ;; Take care of tree window mode.
5784         (when (get-buffer-window gnus-group-buffer)
5785           (pop-to-buffer gnus-group-buffer))
5786         (gnus-group-jump-to-group newsgroup))
5787     (save-excursion
5788       ;; Take care of tree window mode.
5789       (if (get-buffer-window gnus-group-buffer)
5790           (pop-to-buffer gnus-group-buffer)
5791         (set-buffer gnus-group-buffer))
5792       (gnus-group-jump-to-group newsgroup))))
5793
5794 ;; This function returns a list of article numbers based on the
5795 ;; difference between the ranges of read articles in this group and
5796 ;; the range of active articles.
5797 (defun gnus-list-of-unread-articles (group)
5798   (let* ((read (gnus-info-read (gnus-get-info group)))
5799          (active (or (gnus-active group) (gnus-activate-group group)))
5800          (last (cdr active))
5801          first nlast unread)
5802     ;; If none are read, then all are unread.
5803     (if (not read)
5804         (setq first (car active))
5805       ;; If the range of read articles is a single range, then the
5806       ;; first unread article is the article after the last read
5807       ;; article.  Sounds logical, doesn't it?
5808       (if (and (not (listp (cdr read)))
5809                (or (< (car read) (car active))
5810                    (progn (setq read (list read))
5811                           nil)))
5812           (setq first (max (car active) (1+ (cdr read))))
5813         ;; `read' is a list of ranges.
5814         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5815                                   (caar read)))
5816                   1)
5817           (setq first (car active)))
5818         (while read
5819           (when first
5820             (while (< first nlast)
5821               (push first unread)
5822               (setq first (1+ first))))
5823           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5824           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5825           (setq read (cdr read)))))
5826     ;; And add the last unread articles.
5827     (while (<= first last)
5828       (push first unread)
5829       (setq first (1+ first)))
5830     ;; Return the list of unread articles.
5831     (delq 0 (nreverse unread))))
5832
5833 (defun gnus-list-of-read-articles (group)
5834   "Return a list of unread, unticked and non-dormant articles."
5835   (let* ((info (gnus-get-info group))
5836          (marked (gnus-info-marks info))
5837          (active (gnus-active group)))
5838     (and info active
5839          (gnus-set-difference
5840           (gnus-sorted-complement
5841            (gnus-uncompress-range active)
5842            (gnus-list-of-unread-articles group))
5843           (append
5844            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5845            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5846
5847 ;; Various summary commands
5848
5849 (defun gnus-summary-select-article-buffer ()
5850   "Reconfigure windows to show article buffer."
5851   (interactive)
5852   (if (not (gnus-buffer-live-p gnus-article-buffer))
5853       (error "There is no article buffer for this summary buffer")
5854     (gnus-configure-windows 'article)
5855     (select-window (get-buffer-window gnus-article-buffer))))
5856
5857 (defun gnus-summary-universal-argument (arg)
5858   "Perform any operation on all articles that are process/prefixed."
5859   (interactive "P")
5860   (let ((articles (gnus-summary-work-articles arg))
5861         func article)
5862     (if (eq
5863          (setq
5864           func
5865           (key-binding
5866            (read-key-sequence
5867             (substitute-command-keys
5868              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5869          'undefined)
5870         (gnus-error 1 "Undefined key")
5871       (save-excursion
5872         (while articles
5873           (gnus-summary-goto-subject (setq article (pop articles)))
5874           (let (gnus-newsgroup-processable)
5875             (command-execute func))
5876           (gnus-summary-remove-process-mark article)))))
5877   (gnus-summary-position-point))
5878
5879 (defun gnus-summary-toggle-truncation (&optional arg)
5880   "Toggle truncation of summary lines.
5881 With arg, turn line truncation on iff arg is positive."
5882   (interactive "P")
5883   (setq truncate-lines
5884         (if (null arg) (not truncate-lines)
5885           (> (prefix-numeric-value arg) 0)))
5886   (redraw-display))
5887
5888 (defun gnus-summary-reselect-current-group (&optional all rescan)
5889   "Exit and then reselect the current newsgroup.
5890 The prefix argument ALL means to select all articles."
5891   (interactive "P")
5892   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5893     (error "Ephemeral groups can't be reselected"))
5894   (let ((current-subject (gnus-summary-article-number))
5895         (group gnus-newsgroup-name))
5896     (setq gnus-newsgroup-begin nil)
5897     (gnus-summary-exit)
5898     ;; We have to adjust the point of group mode buffer because
5899     ;; point was moved to the next unread newsgroup by exiting.
5900     (gnus-summary-jump-to-group group)
5901     (when rescan
5902       (save-excursion
5903         (gnus-group-get-new-news-this-group 1)))
5904     (gnus-group-read-group all t)
5905     (gnus-summary-goto-subject current-subject nil t)))
5906
5907 (defun gnus-summary-rescan-group (&optional all)
5908   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5909   (interactive "P")
5910   (gnus-summary-reselect-current-group all t))
5911
5912 (defun gnus-summary-update-info (&optional non-destructive)
5913   (save-excursion
5914     (let ((group gnus-newsgroup-name))
5915       (when group
5916         (when gnus-newsgroup-kill-headers
5917           (setq gnus-newsgroup-killed
5918                 (gnus-compress-sequence
5919                  (nconc
5920                   (gnus-set-sorted-intersection
5921                    (gnus-uncompress-range gnus-newsgroup-killed)
5922                    (setq gnus-newsgroup-unselected
5923                          (sort gnus-newsgroup-unselected '<)))
5924                   (setq gnus-newsgroup-unreads
5925                         (sort gnus-newsgroup-unreads '<)))
5926                  t)))
5927         (unless (listp (cdr gnus-newsgroup-killed))
5928           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5929         (let ((headers gnus-newsgroup-headers))
5930           ;; Set the new ranges of read articles.
5931           (save-excursion
5932             (set-buffer gnus-group-buffer)
5933             (gnus-undo-force-boundary))
5934           (gnus-update-read-articles
5935            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5936           ;; Set the current article marks.
5937           (let ((gnus-newsgroup-scored
5938                  (if (and (not gnus-save-score)
5939                           (not non-destructive))
5940                      nil
5941                    gnus-newsgroup-scored)))
5942             (save-excursion
5943               (gnus-update-marks)))
5944           ;; Do the cross-ref thing.
5945           (when gnus-use-cross-reference
5946             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5947           ;; Do not switch windows but change the buffer to work.
5948           (set-buffer gnus-group-buffer)
5949           (unless (gnus-ephemeral-group-p group)
5950             (gnus-group-update-group group)))))))
5951
5952 (defun gnus-summary-save-newsrc (&optional force)
5953   "Save the current number of read/marked articles in the dribble buffer.
5954 The dribble buffer will then be saved.
5955 If FORCE (the prefix), also save the .newsrc file(s)."
5956   (interactive "P")
5957   (gnus-summary-update-info t)
5958   (if force
5959       (gnus-save-newsrc-file)
5960     (gnus-dribble-save)))
5961
5962 (defun gnus-summary-exit (&optional temporary)
5963   "Exit reading current newsgroup, and then return to group selection mode.
5964 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5965   (interactive)
5966   (gnus-set-global-variables)
5967   (when (gnus-buffer-live-p gnus-article-buffer)
5968     (save-excursion
5969       (set-buffer gnus-article-buffer)
5970       (mm-destroy-parts gnus-article-mime-handles)
5971       ;; Set it to nil for safety reason.
5972       (setq gnus-article-mime-handle-alist nil)
5973       (setq gnus-article-mime-handles nil)))
5974   (gnus-kill-save-kill-buffer)
5975   (gnus-async-halt-prefetch)
5976   (let* ((group gnus-newsgroup-name)
5977          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5978          (mode major-mode)
5979          (group-point nil)
5980          (buf (current-buffer)))
5981     (unless quit-config
5982       ;; Do adaptive scoring, and possibly save score files.
5983       (when gnus-newsgroup-adaptive
5984         (gnus-score-adaptive))
5985       (when gnus-use-scoring
5986         (gnus-score-save)))
5987     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5988     ;; If we have several article buffers, we kill them at exit.
5989     (unless gnus-single-article-buffer
5990       (gnus-kill-buffer gnus-original-article-buffer)
5991       (setq gnus-article-current nil))
5992     (when gnus-use-cache
5993       (gnus-cache-possibly-remove-articles)
5994       (gnus-cache-save-buffers))
5995     (gnus-async-prefetch-remove-group group)
5996     (when gnus-suppress-duplicates
5997       (gnus-dup-enter-articles))
5998     (when gnus-use-trees
5999       (gnus-tree-close group))
6000     (when gnus-use-cache
6001       (gnus-cache-write-active))
6002     ;; Remove entries for this group.
6003     (nnmail-purge-split-history (gnus-group-real-name group))
6004     ;; Make all changes in this group permanent.
6005     (unless quit-config
6006       (gnus-run-hooks 'gnus-exit-group-hook)
6007       (gnus-summary-update-info))
6008     (gnus-close-group group)
6009     ;; Make sure where we were, and go to next newsgroup.
6010     (set-buffer gnus-group-buffer)
6011     (unless quit-config
6012       (gnus-group-jump-to-group group))
6013     (gnus-run-hooks 'gnus-summary-exit-hook)
6014     (unless (or quit-config
6015                 ;; If this group has disappeared from the summary
6016                 ;; buffer, don't skip forwards.
6017                 (not (string= group (gnus-group-group-name))))
6018       (gnus-group-next-unread-group 1))
6019     (setq group-point (point))
6020     (if temporary
6021         nil                             ;Nothing to do.
6022       ;; If we have several article buffers, we kill them at exit.
6023       (unless gnus-single-article-buffer
6024         (gnus-kill-buffer gnus-article-buffer)
6025         (gnus-kill-buffer gnus-original-article-buffer)
6026         (setq gnus-article-current nil))
6027       (set-buffer buf)
6028       (if (not gnus-kill-summary-on-exit)
6029           (progn
6030             (gnus-deaden-summary)
6031             (setq mode nil))
6032        ;; We set all buffer-local variables to nil.  It is unclear why
6033         ;; this is needed, but if we don't, buffer-local variables are
6034         ;; not garbage-collected, it seems.  This would the lead to en
6035         ;; ever-growing Emacs.
6036         (gnus-summary-clear-local-variables)
6037         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6038           (gnus-summary-clear-local-variables))
6039         (when (get-buffer gnus-article-buffer)
6040           (bury-buffer gnus-article-buffer))
6041         ;; We clear the global counterparts of the buffer-local
6042         ;; variables as well, just to be on the safe side.
6043         (set-buffer gnus-group-buffer)
6044         (gnus-summary-clear-local-variables)
6045         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6046           (gnus-summary-clear-local-variables)))
6047       (setq gnus-current-select-method gnus-select-method)
6048       (pop-to-buffer gnus-group-buffer)
6049       (if (not quit-config)
6050           (progn
6051             (goto-char group-point)
6052             (gnus-configure-windows 'group 'force))
6053         (gnus-handle-ephemeral-exit quit-config))
6054       ;; Return to group mode buffer.
6055       (when (eq mode 'gnus-summary-mode)
6056         (gnus-kill-buffer buf))
6057       ;; Clear the current group name.
6058       (unless quit-config
6059         (setq gnus-newsgroup-name nil)))))
6060
6061 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6062 (defun gnus-summary-exit-no-update (&optional no-questions)
6063   "Quit reading current newsgroup without updating read article info."
6064   (interactive)
6065   (let* ((group gnus-newsgroup-name)
6066          (quit-config (gnus-group-quit-config group)))
6067     (when (or no-questions
6068               gnus-expert-user
6069               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6070       (gnus-async-halt-prefetch)
6071       (mapcar 'funcall
6072               (delq 'gnus-summary-expire-articles
6073                     (copy-sequence gnus-summary-prepare-exit-hook)))
6074       (when (gnus-buffer-live-p gnus-article-buffer)
6075         (save-excursion
6076           (set-buffer gnus-article-buffer)
6077           (mm-destroy-parts gnus-article-mime-handles)
6078           ;; Set it to nil for safety reason.
6079           (setq gnus-article-mime-handle-alist nil)
6080           (setq gnus-article-mime-handles nil)))
6081       ;; If we have several article buffers, we kill them at exit.
6082       (unless gnus-single-article-buffer
6083         (gnus-kill-buffer gnus-article-buffer)
6084         (gnus-kill-buffer gnus-original-article-buffer)
6085         (setq gnus-article-current nil))
6086       (if (not gnus-kill-summary-on-exit)
6087           (gnus-deaden-summary)
6088         (gnus-close-group group)
6089         (gnus-summary-clear-local-variables)
6090         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6091           (gnus-summary-clear-local-variables))
6092         (set-buffer gnus-group-buffer)
6093         (gnus-summary-clear-local-variables)
6094         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6095           (gnus-summary-clear-local-variables))
6096         (when (get-buffer gnus-summary-buffer)
6097           (kill-buffer gnus-summary-buffer)))
6098       (unless gnus-single-article-buffer
6099         (setq gnus-article-current nil))
6100       (when gnus-use-trees
6101         (gnus-tree-close group))
6102       (gnus-async-prefetch-remove-group group)
6103       (when (get-buffer gnus-article-buffer)
6104         (bury-buffer gnus-article-buffer))
6105       ;; Return to the group buffer.
6106       (gnus-configure-windows 'group 'force)
6107       ;; Clear the current group name.
6108       (setq gnus-newsgroup-name nil)
6109       (when (equal (gnus-group-group-name) group)
6110         (gnus-group-next-unread-group 1))
6111       (when quit-config
6112         (gnus-handle-ephemeral-exit quit-config)))))
6113
6114 (defun gnus-handle-ephemeral-exit (quit-config)
6115   "Handle movement when leaving an ephemeral group.
6116 The state which existed when entering the ephemeral is reset."
6117   (if (not (buffer-name (car quit-config)))
6118       (gnus-configure-windows 'group 'force)
6119     (set-buffer (car quit-config))
6120     (cond ((eq major-mode 'gnus-summary-mode)
6121            (gnus-set-global-variables))
6122           ((eq major-mode 'gnus-article-mode)
6123            (save-excursion
6124              ;; The `gnus-summary-buffer' variable may point
6125              ;; to the old summary buffer when using a single
6126              ;; article buffer.
6127              (unless (gnus-buffer-live-p gnus-summary-buffer)
6128                (set-buffer gnus-group-buffer))
6129              (set-buffer gnus-summary-buffer)
6130              (gnus-set-global-variables))))
6131     (if (or (eq (cdr quit-config) 'article)
6132             (eq (cdr quit-config) 'pick))
6133         (progn
6134           ;; The current article may be from the ephemeral group
6135           ;; thus it is best that we reload this article
6136           (gnus-summary-show-article)
6137           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6138               (gnus-configure-windows 'pick 'force)
6139             (gnus-configure-windows (cdr quit-config) 'force)))
6140       (gnus-configure-windows (cdr quit-config) 'force))
6141     (when (eq major-mode 'gnus-summary-mode)
6142       (gnus-summary-next-subject 1 nil t)
6143       (gnus-summary-recenter)
6144       (gnus-summary-position-point))))
6145
6146 ;;; Dead summaries.
6147
6148 (defvar gnus-dead-summary-mode-map nil)
6149
6150 (unless gnus-dead-summary-mode-map
6151   (setq gnus-dead-summary-mode-map (make-keymap))
6152   (suppress-keymap gnus-dead-summary-mode-map)
6153   (substitute-key-definition
6154    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6155   (let ((keys '("\C-d" "\r" "\177" [delete])))
6156     (while keys
6157       (define-key gnus-dead-summary-mode-map
6158         (pop keys) 'gnus-summary-wake-up-the-dead))))
6159
6160 (defvar gnus-dead-summary-mode nil
6161   "Minor mode for Gnus summary buffers.")
6162
6163 (defun gnus-dead-summary-mode (&optional arg)
6164   "Minor mode for Gnus summary buffers."
6165   (interactive "P")
6166   (when (eq major-mode 'gnus-summary-mode)
6167     (make-local-variable 'gnus-dead-summary-mode)
6168     (setq gnus-dead-summary-mode
6169           (if (null arg) (not gnus-dead-summary-mode)
6170             (> (prefix-numeric-value arg) 0)))
6171     (when gnus-dead-summary-mode
6172       (gnus-add-minor-mode
6173        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6174
6175 (defun gnus-deaden-summary ()
6176   "Make the current summary buffer into a dead summary buffer."
6177   ;; Kill any previous dead summary buffer.
6178   (when (and gnus-dead-summary
6179              (buffer-name gnus-dead-summary))
6180     (save-excursion
6181       (set-buffer gnus-dead-summary)
6182       (when gnus-dead-summary-mode
6183         (kill-buffer (current-buffer)))))
6184   ;; Make this the current dead summary.
6185   (setq gnus-dead-summary (current-buffer))
6186   (gnus-dead-summary-mode 1)
6187   (let ((name (buffer-name)))
6188     (when (string-match "Summary" name)
6189       (rename-buffer
6190        (concat (substring name 0 (match-beginning 0)) "Dead "
6191                (substring name (match-beginning 0)))
6192        t)
6193       (bury-buffer))))
6194
6195 (defun gnus-kill-or-deaden-summary (buffer)
6196   "Kill or deaden the summary BUFFER."
6197   (save-excursion
6198     (when (and (buffer-name buffer)
6199                (not gnus-single-article-buffer))
6200       (save-excursion
6201         (set-buffer buffer)
6202         (gnus-kill-buffer gnus-article-buffer)
6203         (gnus-kill-buffer gnus-original-article-buffer)))
6204     (cond (gnus-kill-summary-on-exit
6205            (when (and gnus-use-trees
6206                       (gnus-buffer-exists-p buffer))
6207              (save-excursion
6208                (set-buffer buffer)
6209                (gnus-tree-close gnus-newsgroup-name)))
6210            (gnus-kill-buffer buffer))
6211           ((gnus-buffer-exists-p buffer)
6212            (save-excursion
6213              (set-buffer buffer)
6214              (gnus-deaden-summary))))))
6215
6216 (defun gnus-summary-wake-up-the-dead (&rest args)
6217   "Wake up the dead summary buffer."
6218   (interactive)
6219   (gnus-dead-summary-mode -1)
6220   (let ((name (buffer-name)))
6221     (when (string-match "Dead " name)
6222       (rename-buffer
6223        (concat (substring name 0 (match-beginning 0))
6224                (substring name (match-end 0)))
6225        t)))
6226   (gnus-message 3 "This dead summary is now alive again"))
6227
6228 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6229 (defun gnus-summary-fetch-faq (&optional faq-dir)
6230   "Fetch the FAQ for the current group.
6231 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6232 in."
6233   (interactive
6234    (list
6235     (when current-prefix-arg
6236       (completing-read
6237        "Faq dir: " (and (listp gnus-group-faq-directory)
6238                         (mapcar (lambda (file) (list file))
6239                                 gnus-group-faq-directory))))))
6240   (let (gnus-faq-buffer)
6241     (when (setq gnus-faq-buffer
6242                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6243       (gnus-configure-windows 'summary-faq))))
6244
6245 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6246 (defun gnus-summary-describe-group (&optional force)
6247   "Describe the current newsgroup."
6248   (interactive "P")
6249   (gnus-group-describe-group force gnus-newsgroup-name))
6250
6251 (defun gnus-summary-describe-briefly ()
6252   "Describe summary mode commands briefly."
6253   (interactive)
6254   (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")))
6255
6256 ;; Walking around group mode buffer from summary mode.
6257
6258 (defun gnus-summary-next-group (&optional no-article target-group backward)
6259   "Exit current newsgroup and then select next unread newsgroup.
6260 If prefix argument NO-ARTICLE is non-nil, no article is selected
6261 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6262 previous group instead."
6263   (interactive "P")
6264   ;; Stop pre-fetching.
6265   (gnus-async-halt-prefetch)
6266   (let ((current-group gnus-newsgroup-name)
6267         (current-buffer (current-buffer))
6268         entered)
6269    ;; First we semi-exit this group to update Xrefs and all variables.
6270     ;; We can't do a real exit, because the window conf must remain
6271     ;; the same in case the user is prompted for info, and we don't
6272     ;; want the window conf to change before that...
6273     (gnus-summary-exit t)
6274     (while (not entered)
6275       ;; Then we find what group we are supposed to enter.
6276       (set-buffer gnus-group-buffer)
6277       (gnus-group-jump-to-group current-group)
6278       (setq target-group
6279             (or target-group
6280                 (if (eq gnus-keep-same-level 'best)
6281                     (gnus-summary-best-group gnus-newsgroup-name)
6282                   (gnus-summary-search-group backward gnus-keep-same-level))))
6283       (if (not target-group)
6284           ;; There are no further groups, so we return to the group
6285           ;; buffer.
6286           (progn
6287             (gnus-message 5 "Returning to the group buffer")
6288             (setq entered t)
6289             (when (gnus-buffer-live-p current-buffer)
6290               (set-buffer current-buffer)
6291               (gnus-summary-exit))
6292             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6293         ;; We try to enter the target group.
6294         (gnus-group-jump-to-group target-group)
6295         (let ((unreads (gnus-group-group-unread)))
6296           (if (and (or (eq t unreads)
6297                        (and unreads (not (zerop unreads))))
6298                    (gnus-summary-read-group
6299                     target-group nil no-article
6300                     (and (buffer-name current-buffer) current-buffer)
6301                     nil backward))
6302               (setq entered t)
6303             (setq current-group target-group
6304                   target-group nil)))))))
6305
6306 (defun gnus-summary-prev-group (&optional no-article)
6307   "Exit current newsgroup and then select previous unread newsgroup.
6308 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6309   (interactive "P")
6310   (gnus-summary-next-group no-article nil t))
6311
6312 ;; Walking around summary lines.
6313
6314 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6315   "Go to the first unread subject.
6316 If UNREAD is non-nil, go to the first unread article.
6317 Returns the article selected or nil if there are no unread articles."
6318   (interactive "P")
6319   (prog1
6320       (cond
6321        ;; Empty summary.
6322        ((null gnus-newsgroup-data)
6323         (gnus-message 3 "No articles in the group")
6324         nil)
6325        ;; Pick the first article.
6326        ((not unread)
6327         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6328         (gnus-data-number (car gnus-newsgroup-data)))
6329        ;; No unread articles.
6330        ((null gnus-newsgroup-unreads)
6331         (gnus-message 3 "No more unread articles")
6332         nil)
6333        ;; Find the first unread article.
6334        (t
6335         (let ((data gnus-newsgroup-data))
6336           (while (and data
6337                       (and (not (and undownloaded
6338                                      (eq gnus-undownloaded-mark
6339                                          (gnus-data-mark (car data)))))
6340                            (not (and unseen
6341                                      (memq (car data) gnus-newsgroup-unseen)))
6342                            (not (gnus-data-unread-p (car data)))))
6343             (setq data (cdr data)))
6344           (when data
6345             (goto-char (gnus-data-pos (car data)))
6346             (gnus-data-number (car data))))))
6347     (gnus-summary-position-point)))
6348
6349 (defun gnus-summary-next-subject (n &optional unread dont-display)
6350   "Go to next N'th summary line.
6351 If N is negative, go to the previous N'th subject line.
6352 If UNREAD is non-nil, only unread articles are selected.
6353 The difference between N and the actual number of steps taken is
6354 returned."
6355   (interactive "p")
6356   (let ((backward (< n 0))
6357         (n (abs n)))
6358     (while (and (> n 0)
6359                 (if backward
6360                     (gnus-summary-find-prev unread)
6361                   (gnus-summary-find-next unread)))
6362       (unless (zerop (setq n (1- n)))
6363         (gnus-summary-show-thread)))
6364     (when (/= 0 n)
6365       (gnus-message 7 "No more%s articles"
6366                     (if unread " unread" "")))
6367     (unless dont-display
6368       (gnus-summary-recenter)
6369       (gnus-summary-position-point))
6370     n))
6371
6372 (defun gnus-summary-next-unread-subject (n)
6373   "Go to next N'th unread summary line."
6374   (interactive "p")
6375   (gnus-summary-next-subject n t))
6376
6377 (defun gnus-summary-prev-subject (n &optional unread)
6378   "Go to previous N'th summary line.
6379 If optional argument UNREAD is non-nil, only unread article is selected."
6380   (interactive "p")
6381   (gnus-summary-next-subject (- n) unread))
6382
6383 (defun gnus-summary-prev-unread-subject (n)
6384   "Go to previous N'th unread summary line."
6385   (interactive "p")
6386   (gnus-summary-next-subject (- n) t))
6387
6388 (defun gnus-summary-goto-subject (article &optional force silent)
6389   "Go the subject line of ARTICLE.
6390 If FORCE, also allow jumping to articles not currently shown."
6391   (interactive "nArticle number: ")
6392   (let ((b (point))
6393         (data (gnus-data-find article)))
6394     ;; We read in the article if we have to.
6395     (and (not data)
6396          force
6397          (gnus-summary-insert-subject
6398           article
6399           (if (or (numberp force) (vectorp force)) force)
6400           t)
6401          (setq data (gnus-data-find article)))
6402     (goto-char b)
6403     (if (not data)
6404         (progn
6405           (unless silent
6406             (gnus-message 3 "Can't find article %d" article))
6407           nil)
6408       (let ((pt (gnus-data-pos data)))
6409         (goto-char pt)
6410         (gnus-summary-set-article-display-arrow pt))
6411       (gnus-summary-position-point)
6412       article)))
6413
6414 ;; Walking around summary lines with displaying articles.
6415
6416 (defun gnus-summary-expand-window (&optional arg)
6417   "Make the summary buffer take up the entire Emacs frame.
6418 Given a prefix, will force an `article' buffer configuration."
6419   (interactive "P")
6420   (if arg
6421       (gnus-configure-windows 'article 'force)
6422     (gnus-configure-windows 'summary 'force)))
6423
6424 (defun gnus-summary-display-article (article &optional all-header)
6425   "Display ARTICLE in article buffer."
6426   (when (gnus-buffer-live-p gnus-article-buffer)
6427     (with-current-buffer gnus-article-buffer
6428       (mm-enable-multibyte-mule4)))
6429   (gnus-set-global-variables)
6430   (when (gnus-buffer-live-p gnus-article-buffer)
6431     (with-current-buffer gnus-article-buffer
6432       (setq gnus-article-charset gnus-newsgroup-charset)
6433       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6434       (mm-enable-multibyte-mule4)))
6435   (if (null article)
6436       nil
6437     (prog1
6438         (if gnus-summary-display-article-function
6439             (funcall gnus-summary-display-article-function article all-header)
6440           (gnus-article-prepare article all-header))
6441       (gnus-run-hooks 'gnus-select-article-hook)
6442       (when (and gnus-current-article
6443                  (not (zerop gnus-current-article)))
6444         (gnus-summary-goto-subject gnus-current-article))
6445       (gnus-summary-recenter)
6446       (when (and gnus-use-trees gnus-show-threads)
6447         (gnus-possibly-generate-tree article)
6448         (gnus-highlight-selected-tree article))
6449       ;; Successfully display article.
6450       (gnus-article-set-window-start
6451        (cdr (assq article gnus-newsgroup-bookmarks))))))
6452
6453 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6454   "Select the current article.
6455 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6456 non-nil, the article will be re-fetched even if it already present in
6457 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6458 be displayed."
6459   ;; Make sure we are in the summary buffer to work around bbdb bug.
6460   (unless (eq major-mode 'gnus-summary-mode)
6461     (set-buffer gnus-summary-buffer))
6462   (let ((article (or article (gnus-summary-article-number)))
6463         (all-headers (not (not all-headers))) ;Must be t or nil.
6464         gnus-summary-display-article-function)
6465     (and (not pseudo)
6466          (gnus-summary-article-pseudo-p article)
6467          (error "This is a pseudo-article"))
6468     (save-excursion
6469       (set-buffer gnus-summary-buffer)
6470       (if (or (and gnus-single-article-buffer
6471                    (or (null gnus-current-article)
6472                        (null gnus-article-current)
6473                        (null (get-buffer gnus-article-buffer))
6474                        (not (eq article (cdr gnus-article-current)))
6475                        (not (equal (car gnus-article-current)
6476                                    gnus-newsgroup-name))))
6477               (and (not gnus-single-article-buffer)
6478                    (or (null gnus-current-article)
6479                        (not (eq gnus-current-article article))))
6480               force)
6481        ;; The requested article is different from the current article.
6482           (progn
6483             (gnus-summary-display-article article all-headers)
6484             (when (gnus-buffer-live-p gnus-article-buffer)
6485               (with-current-buffer gnus-article-buffer
6486                 (if (not gnus-article-decoded-p) ;; a local variable
6487                     (mm-disable-multibyte-mule4))))
6488             (when (or all-headers gnus-show-all-headers)
6489               (gnus-article-show-all-headers))
6490             (gnus-article-set-window-start
6491              (cdr (assq article gnus-newsgroup-bookmarks)))
6492             article)
6493         (when (or all-headers gnus-show-all-headers)
6494           (gnus-article-show-all-headers))
6495         'old))))
6496
6497 (defun gnus-summary-force-verify-and-decrypt ()
6498   (interactive)
6499   (let ((mm-verify-option 'known)
6500         (mm-decrypt-option 'known))
6501     (gnus-summary-select-article nil 'force)))
6502
6503 (defun gnus-summary-set-current-mark (&optional current-mark)
6504   "Obsolete function."
6505   nil)
6506
6507 (defun gnus-summary-next-article (&optional unread subject backward push)
6508   "Select the next article.
6509 If UNREAD, only unread articles are selected.
6510 If SUBJECT, only articles with SUBJECT are selected.
6511 If BACKWARD, the previous article is selected instead of the next."
6512   (interactive "P")
6513   (cond
6514    ;; Is there such an article?
6515    ((and (gnus-summary-search-forward unread subject backward)
6516          (or (gnus-summary-display-article (gnus-summary-article-number))
6517              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6518     (gnus-summary-position-point))
6519    ;; If not, we try the first unread, if that is wanted.
6520    ((and subject
6521          gnus-auto-select-same
6522          (gnus-summary-first-unread-article))
6523     (gnus-summary-position-point)
6524     (gnus-message 6 "Wrapped"))
6525    ;; Try to get next/previous article not displayed in this group.
6526    ((and gnus-auto-extend-newsgroup
6527          (not unread) (not subject))
6528     (gnus-summary-goto-article
6529      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6530      nil (count-lines (point-min) (point))))
6531    ;; Go to next/previous group.
6532    (t
6533     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6534       (gnus-summary-jump-to-group gnus-newsgroup-name))
6535     (let ((cmd last-command-char)
6536           (point
6537            (save-excursion
6538              (set-buffer gnus-group-buffer)
6539              (point)))
6540           (group
6541            (if (eq gnus-keep-same-level 'best)
6542                (gnus-summary-best-group gnus-newsgroup-name)
6543              (gnus-summary-search-group backward gnus-keep-same-level))))
6544       ;; For some reason, the group window gets selected.  We change
6545       ;; it back.
6546       (select-window (get-buffer-window (current-buffer)))
6547       ;; Select next unread newsgroup automagically.
6548       (cond
6549        ((or (not gnus-auto-select-next)
6550             (not cmd))
6551         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6552        ((or (eq gnus-auto-select-next 'quietly)
6553             (and (eq gnus-auto-select-next 'slightly-quietly)
6554                  push)
6555             (and (eq gnus-auto-select-next 'almost-quietly)
6556                  (gnus-summary-last-article-p)))
6557         ;; Select quietly.
6558         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6559             (gnus-summary-exit)
6560           (gnus-message 7 "No more%s articles (%s)..."
6561                         (if unread " unread" "")
6562                         (if group (concat "selecting " group)
6563                           "exiting"))
6564           (gnus-summary-next-group nil group backward)))
6565        (t
6566         (when (gnus-key-press-event-p last-input-event)
6567           (gnus-summary-walk-group-buffer
6568            gnus-newsgroup-name cmd unread backward point))))))))
6569
6570 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6571   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6572                       (?\C-p (gnus-group-prev-unread-group 1))))
6573         (cursor-in-echo-area t)
6574         keve key group ended)
6575     (save-excursion
6576       (set-buffer gnus-group-buffer)
6577       (goto-char start)
6578       (setq group
6579             (if (eq gnus-keep-same-level 'best)
6580                 (gnus-summary-best-group gnus-newsgroup-name)
6581               (gnus-summary-search-group backward gnus-keep-same-level))))
6582     (while (not ended)
6583       (gnus-message
6584        5 "No more%s articles%s" (if unread " unread" "")
6585        (if (and group
6586                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6587            (format " (Type %s for %s [%s])"
6588                    (single-key-description cmd) group
6589                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6590          (format " (Type %s to exit %s)"
6591                  (single-key-description cmd)
6592                  gnus-newsgroup-name)))
6593       ;; Confirm auto selection.
6594       (setq key (car (setq keve (gnus-read-event-char))))
6595       (setq ended t)
6596       (cond
6597        ((assq key keystrokes)
6598         (let ((obuf (current-buffer)))
6599           (switch-to-buffer gnus-group-buffer)
6600           (when group
6601             (gnus-group-jump-to-group group))
6602           (eval (cadr (assq key keystrokes)))
6603           (setq group (gnus-group-group-name))
6604           (switch-to-buffer obuf))
6605         (setq ended nil))
6606        ((equal key cmd)
6607         (if (or (not group)
6608                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6609             (gnus-summary-exit)
6610           (gnus-summary-next-group nil group backward)))
6611        (t
6612         (push (cdr keve) unread-command-events))))))
6613
6614 (defun gnus-summary-next-unread-article ()
6615   "Select unread article after current one."
6616   (interactive)
6617   (gnus-summary-next-article
6618    (or (not (eq gnus-summary-goto-unread 'never))
6619        (gnus-summary-last-article-p (gnus-summary-article-number)))
6620    (and gnus-auto-select-same
6621         (gnus-summary-article-subject))))
6622
6623 (defun gnus-summary-prev-article (&optional unread subject)
6624   "Select the article after the current one.
6625 If UNREAD is non-nil, only unread articles are selected."
6626   (interactive "P")
6627   (gnus-summary-next-article unread subject t))
6628
6629 (defun gnus-summary-prev-unread-article ()
6630   "Select unread article before current one."
6631   (interactive)
6632   (gnus-summary-prev-article
6633    (or (not (eq gnus-summary-goto-unread 'never))
6634        (gnus-summary-first-article-p (gnus-summary-article-number)))
6635    (and gnus-auto-select-same
6636         (gnus-summary-article-subject))))
6637
6638 (defun gnus-summary-next-page (&optional lines circular)
6639   "Show next page of the selected article.
6640 If at the end of the current article, select the next article.
6641 LINES says how many lines should be scrolled up.
6642
6643 If CIRCULAR is non-nil, go to the start of the article instead of
6644 selecting the next article when reaching the end of the current
6645 article."
6646   (interactive "P")
6647   (setq gnus-summary-buffer (current-buffer))
6648   (gnus-set-global-variables)
6649   (let ((article (gnus-summary-article-number))
6650         (article-window (get-buffer-window gnus-article-buffer t))
6651         endp)
6652     ;; If the buffer is empty, we have no article.
6653     (unless article
6654       (error "No article to select"))
6655     (gnus-configure-windows 'article)
6656     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6657         (if (and (eq gnus-summary-goto-unread 'never)
6658                  (not (gnus-summary-last-article-p article)))
6659             (gnus-summary-next-article)
6660           (gnus-summary-next-unread-article))
6661       (if (or (null gnus-current-article)
6662               (null gnus-article-current)
6663               (/= article (cdr gnus-article-current))
6664               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6665           ;; Selected subject is different from current article's.
6666           (gnus-summary-display-article article)
6667         (when article-window
6668           (gnus-eval-in-buffer-window gnus-article-buffer
6669             (setq endp (gnus-article-next-page lines)))
6670           (when endp
6671             (cond (circular
6672                    (gnus-summary-beginning-of-article))
6673                   (lines
6674                    (gnus-message 3 "End of message"))
6675                   ((null lines)
6676                    (if (and (eq gnus-summary-goto-unread 'never)
6677                             (not (gnus-summary-last-article-p article)))
6678                        (gnus-summary-next-article)
6679                      (gnus-summary-next-unread-article))))))))
6680     (gnus-summary-recenter)
6681     (gnus-summary-position-point)))
6682
6683 (defun gnus-summary-prev-page (&optional lines move)
6684   "Show previous page of selected article.
6685 Argument LINES specifies lines to be scrolled down.
6686 If MOVE, move to the previous unread article if point is at
6687 the beginning of the buffer."
6688   (interactive "P")
6689   (let ((article (gnus-summary-article-number))
6690         (article-window (get-buffer-window gnus-article-buffer t))
6691         endp)
6692     (gnus-configure-windows 'article)
6693     (if (or (null gnus-current-article)
6694             (null gnus-article-current)
6695             (/= article (cdr gnus-article-current))
6696             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6697         ;; Selected subject is different from current article's.
6698         (gnus-summary-display-article article)
6699       (gnus-summary-recenter)
6700       (when article-window
6701         (gnus-eval-in-buffer-window gnus-article-buffer
6702           (setq endp (gnus-article-prev-page lines)))
6703         (when (and move endp)
6704           (cond (lines
6705                  (gnus-message 3 "Beginning of message"))
6706                 ((null lines)
6707                  (if (and (eq gnus-summary-goto-unread 'never)
6708                           (not (gnus-summary-first-article-p article)))
6709                      (gnus-summary-prev-article)
6710                    (gnus-summary-prev-unread-article))))))))
6711   (gnus-summary-position-point))
6712
6713 (defun gnus-summary-prev-page-or-article (&optional lines)
6714   "Show previous page of selected article.
6715 Argument LINES specifies lines to be scrolled down.
6716 If at the beginning of the article, go to the next article."
6717   (interactive "P")
6718   (gnus-summary-prev-page lines t))
6719
6720 (defun gnus-summary-scroll-up (lines)
6721   "Scroll up (or down) one line current article.
6722 Argument LINES specifies lines to be scrolled up (or down if negative)."
6723   (interactive "p")
6724   (gnus-configure-windows 'article)
6725   (gnus-summary-show-thread)
6726   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6727     (gnus-eval-in-buffer-window gnus-article-buffer
6728       (cond ((> lines 0)
6729              (when (gnus-article-next-page lines)
6730                (gnus-message 3 "End of message")))
6731             ((< lines 0)
6732              (gnus-article-prev-page (- lines))))))
6733   (gnus-summary-recenter)
6734   (gnus-summary-position-point))
6735
6736 (defun gnus-summary-scroll-down (lines)
6737   "Scroll down (or up) one line current article.
6738 Argument LINES specifies lines to be scrolled down (or up if negative)."
6739   (interactive "p")
6740   (gnus-summary-scroll-up (- lines)))
6741
6742 (defun gnus-summary-next-same-subject ()
6743   "Select next article which has the same subject as current one."
6744   (interactive)
6745   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6746
6747 (defun gnus-summary-prev-same-subject ()
6748   "Select previous article which has the same subject as current one."
6749   (interactive)
6750   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6751
6752 (defun gnus-summary-next-unread-same-subject ()
6753   "Select next unread article which has the same subject as current one."
6754   (interactive)
6755   (gnus-summary-next-article t (gnus-summary-article-subject)))
6756
6757 (defun gnus-summary-prev-unread-same-subject ()
6758   "Select previous unread article which has the same subject as current one."
6759   (interactive)
6760   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6761
6762 (defun gnus-summary-first-unread-article ()
6763   "Select the first unread article.
6764 Return nil if there are no unread articles."
6765   (interactive)
6766   (prog1
6767       (when (gnus-summary-first-subject t)
6768         (gnus-summary-show-thread)
6769         (gnus-summary-first-subject t)
6770         (gnus-summary-display-article (gnus-summary-article-number)))
6771     (gnus-summary-position-point)))
6772
6773 (defun gnus-summary-first-unread-subject ()
6774   "Place the point on the subject line of the first unread article.
6775 Return nil if there are no unread articles."
6776   (interactive)
6777   (prog1
6778       (when (gnus-summary-first-subject t)
6779         (gnus-summary-show-thread)
6780         (gnus-summary-first-subject t))
6781     (gnus-summary-position-point)))
6782
6783 (defun gnus-summary-first-unseen-subject ()
6784   "Place the point on the subject line of the first unseen article.
6785 Return nil if there are no unseen articles."
6786   (interactive)
6787   (prog1
6788       (when (gnus-summary-first-subject t t t)
6789         (gnus-summary-show-thread)
6790         (gnus-summary-first-subject t t t))
6791     (gnus-summary-position-point)))
6792
6793 (defun gnus-summary-first-article ()
6794   "Select the first article.
6795 Return nil if there are no articles."
6796   (interactive)
6797   (prog1
6798       (when (gnus-summary-first-subject)
6799         (gnus-summary-show-thread)
6800         (gnus-summary-first-subject)
6801         (gnus-summary-display-article (gnus-summary-article-number)))
6802     (gnus-summary-position-point)))
6803
6804 (defun gnus-summary-best-unread-article ()
6805   "Select the unread article with the highest score."
6806   (interactive)
6807   (let ((article (gnus-summary-best-unread-subject)))
6808     (if article
6809         (gnus-summary-goto-article article)
6810       (error "No unread articles"))))
6811
6812 (defun gnus-summary-best-unread-subject ()
6813   "Select the unread subject with the highest score."
6814   (interactive)
6815   (let ((best -1000000)
6816         (data gnus-newsgroup-data)
6817         article score)
6818     (while data
6819       (and (gnus-data-unread-p (car data))
6820            (> (setq score
6821                     (gnus-summary-article-score (gnus-data-number (car data))))
6822               best)
6823            (setq best score
6824                  article (gnus-data-number (car data))))
6825       (setq data (cdr data)))
6826     (gnus-summary-position-point)
6827     article))
6828
6829 (defun gnus-summary-last-subject ()
6830   "Go to the last displayed subject line in the group."
6831   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6832     (when article
6833       (gnus-summary-goto-subject article))))
6834
6835 (defun gnus-summary-goto-article (article &optional all-headers force)
6836   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6837 If ALL-HEADERS is non-nil, no header lines are hidden.
6838 If FORCE, go to the article even if it isn't displayed.  If FORCE
6839 is a number, it is the line the article is to be displayed on."
6840   (interactive
6841    (list
6842     (completing-read
6843      "Article number or Message-ID: "
6844      (mapcar (lambda (number) (list (int-to-string number)))
6845              gnus-newsgroup-limit))
6846     current-prefix-arg
6847     t))
6848   (prog1
6849       (if (and (stringp article)
6850                (string-match "@" article))
6851           (gnus-summary-refer-article article)
6852         (when (stringp article)
6853           (setq article (string-to-number article)))
6854         (if (gnus-summary-goto-subject article force)
6855             (gnus-summary-display-article article all-headers)
6856           (gnus-message 4 "Couldn't go to article %s" article) nil))
6857     (gnus-summary-position-point)))
6858
6859 (defun gnus-summary-goto-last-article ()
6860   "Go to the previously read article."
6861   (interactive)
6862   (prog1
6863       (when gnus-last-article
6864         (gnus-summary-goto-article gnus-last-article nil t))
6865     (gnus-summary-position-point)))
6866
6867 (defun gnus-summary-pop-article (number)
6868   "Pop one article off the history and go to the previous.
6869 NUMBER articles will be popped off."
6870   (interactive "p")
6871   (let (to)
6872     (setq gnus-newsgroup-history
6873           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6874     (if to
6875         (gnus-summary-goto-article (car to) nil t)
6876       (error "Article history empty")))
6877   (gnus-summary-position-point))
6878
6879 ;; Summary commands and functions for limiting the summary buffer.
6880
6881 (defun gnus-summary-limit-to-articles (n)
6882   "Limit the summary buffer to the next N articles.
6883 If not given a prefix, use the process marked articles instead."
6884   (interactive "P")
6885   (prog1
6886       (let ((articles (gnus-summary-work-articles n)))
6887         (setq gnus-newsgroup-processable nil)
6888         (gnus-summary-limit articles))
6889     (gnus-summary-position-point)))
6890
6891 (defun gnus-summary-pop-limit (&optional total)
6892   "Restore the previous limit.
6893 If given a prefix, remove all limits."
6894   (interactive "P")
6895   (when total
6896     (setq gnus-newsgroup-limits
6897           (list (mapcar (lambda (h) (mail-header-number h))
6898                         gnus-newsgroup-headers))))
6899   (unless gnus-newsgroup-limits
6900     (error "No limit to pop"))
6901   (prog1
6902       (gnus-summary-limit nil 'pop)
6903     (gnus-summary-position-point)))
6904
6905 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6906   "Limit the summary buffer to articles that have subjects that match a regexp.
6907 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6908   (interactive
6909    (list (read-string (if current-prefix-arg
6910                           "Exclude subject (regexp): "
6911                         "Limit to subject (regexp): "))
6912          nil current-prefix-arg))
6913   (unless header
6914     (setq header "subject"))
6915   (when (not (equal "" subject))
6916     (prog1
6917         (let ((articles (gnus-summary-find-matching
6918                          (or header "subject") subject 'all nil nil
6919                          not-matching)))
6920           (unless articles
6921             (error "Found no matches for \"%s\"" subject))
6922           (gnus-summary-limit articles))
6923       (gnus-summary-position-point))))
6924
6925 (defun gnus-summary-limit-to-author (from &optional not-matching)
6926   "Limit the summary buffer to articles that have authors that match a regexp.
6927 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6928   (interactive
6929    (list (read-string (if current-prefix-arg
6930                           "Exclude author (regexp): "
6931                         "Limit to author (regexp): "))
6932          current-prefix-arg))
6933   (gnus-summary-limit-to-subject from "from" not-matching))
6934
6935 (defun gnus-summary-limit-to-age (age &optional younger-p)
6936   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6937 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6938 articles that are younger than AGE days."
6939   (interactive
6940    (let ((younger current-prefix-arg)
6941          (days-got nil)
6942          days)
6943      (while (not days-got)
6944        (setq days (if younger
6945                       (read-string "Limit to articles within (in days): ")
6946                     (read-string "Limit to articles older than (in days): ")))
6947        (when (> (length days) 0)
6948          (setq days (read days)))
6949        (if (numberp days)
6950            (progn 
6951              (setq days-got t)
6952              (if (< days 0)
6953                  (progn 
6954                    (setq younger (not younger))
6955                    (setq days (* days -1)))))
6956          (message "Please enter a number.")
6957          (sleep-for 1)))
6958      (list days younger)))
6959   (prog1
6960       (let ((data gnus-newsgroup-data)
6961             (cutoff (days-to-time age))
6962             articles d date is-younger)
6963         (while (setq d (pop data))
6964           (when (and (vectorp (gnus-data-header d))
6965                      (setq date (mail-header-date (gnus-data-header d))))
6966             (setq is-younger (time-less-p
6967                               (time-since (condition-case ()
6968                                               (date-to-time date)
6969                                             (error '(0 0))))
6970                               cutoff))
6971             (when (if younger-p
6972                       is-younger
6973                     (not is-younger))
6974               (push (gnus-data-number d) articles))))
6975         (gnus-summary-limit (nreverse articles)))
6976     (gnus-summary-position-point)))
6977
6978 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
6979   "Limit the summary buffer to articles that match an 'extra' header."
6980   (interactive
6981    (let ((header
6982           (intern
6983            (gnus-completing-read
6984             (symbol-name (car gnus-extra-headers))
6985             (if current-prefix-arg
6986                 "Exclude extra header:"
6987               "Limit extra header:")
6988             (mapcar (lambda (x)
6989                       (cons (symbol-name x) x))
6990                     gnus-extra-headers)
6991             nil
6992             t))))
6993      (list header
6994            (read-string (format "%s header %s (regexp): "
6995                                 (if current-prefix-arg "Exclude" "Limit to")
6996                                 header))
6997            current-prefix-arg)))
6998   (when (not (equal "" regexp))
6999     (prog1
7000         (let ((articles (gnus-summary-find-matching
7001                          (cons 'extra header) regexp 'all nil nil
7002                          not-matching)))
7003           (unless articles
7004             (error "Found no matches for \"%s\"" regexp))
7005           (gnus-summary-limit articles))
7006       (gnus-summary-position-point))))
7007
7008 (defun gnus-summary-limit-to-display-predicate ()
7009   "Limit the summary buffer to the predicated in the `display' group parameter."
7010   (interactive)
7011   (unless gnus-newsgroup-display
7012     (error "There is no `display' group parameter"))
7013   (let (articles)
7014     (dolist (number gnus-newsgroup-articles)
7015       (when (funcall gnus-newsgroup-display)
7016         (push number articles)))
7017     (gnus-summary-limit articles))
7018   (gnus-summary-position-point))
7019
7020 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7021 (make-obsolete
7022  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7023
7024 (defun gnus-summary-limit-to-unread (&optional all)
7025   "Limit the summary buffer to articles that are not marked as read.
7026 If ALL is non-nil, limit strictly to unread articles."
7027   (interactive "P")
7028   (if all
7029       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7030     (gnus-summary-limit-to-marks
7031      ;; Concat all the marks that say that an article is read and have
7032      ;; those removed.
7033      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7034            gnus-killed-mark gnus-kill-file-mark
7035            gnus-low-score-mark gnus-expirable-mark
7036            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7037            gnus-duplicate-mark gnus-souped-mark)
7038      'reverse)))
7039
7040 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7041 (make-obsolete 'gnus-summary-delete-marked-with
7042                'gnus-summary-limit-exlude-marks)
7043
7044 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7045   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7046 If REVERSE, limit the summary buffer to articles that are marked
7047 with MARKS.  MARKS can either be a string of marks or a list of marks.
7048 Returns how many articles were removed."
7049   (interactive "sMarks: ")
7050   (gnus-summary-limit-to-marks marks t))
7051
7052 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7053   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7054 If REVERSE (the prefix), limit the summary buffer to articles that are
7055 not marked with MARKS.  MARKS can either be a string of marks or a
7056 list of marks.
7057 Returns how many articles were removed."
7058   (interactive "sMarks: \nP")
7059   (prog1
7060       (let ((data gnus-newsgroup-data)
7061             (marks (if (listp marks) marks
7062                      (append marks nil))) ; Transform to list.
7063             articles)
7064         (while data
7065           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7066                   (memq (gnus-data-mark (car data)) marks))
7067             (push (gnus-data-number (car data)) articles))
7068           (setq data (cdr data)))
7069         (gnus-summary-limit articles))
7070     (gnus-summary-position-point)))
7071
7072 (defun gnus-summary-limit-to-score (score)
7073   "Limit to articles with score at or above SCORE."
7074   (interactive "NLimit to articles with score of at least: ")
7075   (let ((data gnus-newsgroup-data)
7076         articles)
7077     (while data
7078       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7079                 score)
7080         (push (gnus-data-number (car data)) articles))
7081       (setq data (cdr data)))
7082     (prog1
7083         (gnus-summary-limit articles)
7084       (gnus-summary-position-point))))
7085
7086 (defun gnus-summary-limit-include-thread (id)
7087   "Display all the hidden articles that is in the thread with ID in it.
7088 When called interactively, ID is the Message-ID of the current
7089 article."
7090   (interactive (list (mail-header-id (gnus-summary-article-header))))
7091   (let ((articles (gnus-articles-in-thread
7092                    (gnus-id-to-thread (gnus-root-id id)))))
7093     (prog1
7094         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7095       (gnus-summary-limit-include-matching-articles
7096        "subject"
7097        (regexp-quote (gnus-simplify-subject-re
7098                       (mail-header-subject (gnus-id-to-header id)))))
7099       (gnus-summary-position-point))))
7100
7101 (defun gnus-summary-limit-include-matching-articles (header regexp)
7102   "Display all the hidden articles that have HEADERs that match REGEXP."
7103   (interactive (list (read-string "Match on header: ")
7104                      (read-string "Regexp: ")))
7105   (let ((articles (gnus-find-matching-articles header regexp)))
7106     (prog1
7107         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7108       (gnus-summary-position-point))))
7109
7110 (defun gnus-summary-limit-include-dormant ()
7111   "Display all the hidden articles that are marked as dormant.
7112 Note that this command only works on a subset of the articles currently
7113 fetched for this group."
7114   (interactive)
7115   (unless gnus-newsgroup-dormant
7116     (error "There are no dormant articles in this group"))
7117   (prog1
7118       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7119     (gnus-summary-position-point)))
7120
7121 (defun gnus-summary-limit-exclude-dormant ()
7122   "Hide all dormant articles."
7123   (interactive)
7124   (prog1
7125       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7126     (gnus-summary-position-point)))
7127
7128 (defun gnus-summary-limit-exclude-childless-dormant ()
7129   "Hide all dormant articles that have no children."
7130   (interactive)
7131   (let ((data (gnus-data-list t))
7132         articles d children)
7133     ;; Find all articles that are either not dormant or have
7134     ;; children.
7135     (while (setq d (pop data))
7136       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7137                 (and (setq children
7138                            (gnus-article-children (gnus-data-number d)))
7139                      (let (found)
7140                        (while children
7141                          (when (memq (car children) articles)
7142                            (setq children nil
7143                                  found t))
7144                          (pop children))
7145                        found)))
7146         (push (gnus-data-number d) articles)))
7147     ;; Do the limiting.
7148     (prog1
7149         (gnus-summary-limit articles)
7150       (gnus-summary-position-point))))
7151
7152 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7153   "Mark all unread excluded articles as read.
7154 If ALL, mark even excluded ticked and dormants as read."
7155   (interactive "P")
7156   (let ((articles (gnus-sorted-complement
7157                    (sort
7158                     (mapcar (lambda (h) (mail-header-number h))
7159                             gnus-newsgroup-headers)
7160                     '<)
7161                    (sort gnus-newsgroup-limit '<)))
7162         article)
7163     (setq gnus-newsgroup-unreads
7164           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7165     (if all
7166         (setq gnus-newsgroup-dormant nil
7167               gnus-newsgroup-marked nil
7168               gnus-newsgroup-reads
7169               (nconc
7170                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7171                gnus-newsgroup-reads))
7172       (while (setq article (pop articles))
7173         (unless (or (memq article gnus-newsgroup-dormant)
7174                     (memq article gnus-newsgroup-marked))
7175           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7176
7177 (defun gnus-summary-limit (articles &optional pop)
7178   (if pop
7179       ;; We pop the previous limit off the stack and use that.
7180       (setq articles (car gnus-newsgroup-limits)
7181             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7182     ;; We use the new limit, so we push the old limit on the stack.
7183     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7184   ;; Set the limit.
7185   (setq gnus-newsgroup-limit articles)
7186   (let ((total (length gnus-newsgroup-data))
7187         (data (gnus-data-find-list (gnus-summary-article-number)))
7188         (gnus-summary-mark-below nil)   ; Inhibit this.
7189         found)
7190     ;; This will do all the work of generating the new summary buffer
7191     ;; according to the new limit.
7192     (gnus-summary-prepare)
7193     ;; Hide any threads, possibly.
7194     (and gnus-show-threads
7195          gnus-thread-hide-subtree
7196          (gnus-summary-hide-all-threads))
7197     ;; Try to return to the article you were at, or one in the
7198     ;; neighborhood.
7199     (when data
7200       ;; We try to find some article after the current one.
7201       (while data
7202         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7203           (setq data nil
7204                 found t))
7205         (setq data (cdr data))))
7206     (unless found
7207       ;; If there is no data, that means that we were after the last
7208       ;; article.  The same goes when we can't find any articles
7209       ;; after the current one.
7210       (goto-char (point-max))
7211       (gnus-summary-find-prev))
7212     (gnus-set-mode-line 'summary)
7213     ;; We return how many articles were removed from the summary
7214     ;; buffer as a result of the new limit.
7215     (- total (length gnus-newsgroup-data))))
7216
7217 (defsubst gnus-invisible-cut-children (threads)
7218   (let ((num 0))
7219     (while threads
7220       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7221         (incf num))
7222       (pop threads))
7223     (< num 2)))
7224
7225 (defsubst gnus-cut-thread (thread)
7226   "Go forwards in the thread until we find an article that we want to display."
7227   (when (or (eq gnus-fetch-old-headers 'some)
7228             (eq gnus-fetch-old-headers 'invisible)
7229             (numberp gnus-fetch-old-headers)
7230             (eq gnus-build-sparse-threads 'some)
7231             (eq gnus-build-sparse-threads 'more))
7232     ;; Deal with old-fetched headers and sparse threads.
7233     (while (and
7234             thread
7235             (or
7236              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7237              (gnus-summary-article-ancient-p
7238               (mail-header-number (car thread))))
7239             (if (or (<= (length (cdr thread)) 1)
7240                     (eq gnus-fetch-old-headers 'invisible))
7241                 (setq gnus-newsgroup-limit
7242                       (delq (mail-header-number (car thread))
7243                             gnus-newsgroup-limit)
7244                       thread (cadr thread))
7245               (when (gnus-invisible-cut-children (cdr thread))
7246                 (let ((th (cdr thread)))
7247                   (while th
7248                     (if (memq (mail-header-number (caar th))
7249                               gnus-newsgroup-limit)
7250                         (setq thread (car th)
7251                               th nil)
7252                       (setq th (cdr th))))))))))
7253   thread)
7254
7255 (defun gnus-cut-threads (threads)
7256   "Cut off all uninteresting articles from the beginning of threads."
7257   (when (or (eq gnus-fetch-old-headers 'some)
7258             (eq gnus-fetch-old-headers 'invisible)
7259             (numberp gnus-fetch-old-headers)
7260             (eq gnus-build-sparse-threads 'some)
7261             (eq gnus-build-sparse-threads 'more))
7262     (let ((th threads))
7263       (while th
7264         (setcar th (gnus-cut-thread (car th)))
7265         (setq th (cdr th)))))
7266   ;; Remove nixed out threads.
7267   (delq nil threads))
7268
7269 (defun gnus-summary-initial-limit (&optional show-if-empty)
7270   "Figure out what the initial limit is supposed to be on group entry.
7271 This entails weeding out unwanted dormants, low-scored articles,
7272 fetch-old-headers verbiage, and so on."
7273   ;; Most groups have nothing to remove.
7274   (if (or gnus-inhibit-limiting
7275           (and (null gnus-newsgroup-dormant)
7276                (eq gnus-newsgroup-display 'gnus-not-ignore)
7277                (not (eq gnus-fetch-old-headers 'some))
7278                (not (numberp gnus-fetch-old-headers))
7279                (not (eq gnus-fetch-old-headers 'invisible))
7280                (null gnus-summary-expunge-below)
7281                (not (eq gnus-build-sparse-threads 'some))
7282                (not (eq gnus-build-sparse-threads 'more))
7283                (null gnus-thread-expunge-below)
7284                (not gnus-use-nocem)))
7285       ()                                ; Do nothing.
7286     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7287     (setq gnus-newsgroup-limit nil)
7288     (mapatoms
7289      (lambda (node)
7290        (unless (car (symbol-value node))
7291          ;; These threads have no parents -- they are roots.
7292          (let ((nodes (cdr (symbol-value node)))
7293                thread)
7294            (while nodes
7295              (if (and gnus-thread-expunge-below
7296                       (< (gnus-thread-total-score (car nodes))
7297                          gnus-thread-expunge-below))
7298                  (gnus-expunge-thread (pop nodes))
7299                (setq thread (pop nodes))
7300                (gnus-summary-limit-children thread))))))
7301      gnus-newsgroup-dependencies)
7302     ;; If this limitation resulted in an empty group, we might
7303     ;; pop the previous limit and use it instead.
7304     (when (and (not gnus-newsgroup-limit)
7305                show-if-empty)
7306       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7307     gnus-newsgroup-limit))
7308
7309 (defun gnus-summary-limit-children (thread)
7310   "Return 1 if this subthread is visible and 0 if it is not."
7311   ;; First we get the number of visible children to this thread.  This
7312   ;; is done by recursing down the thread using this function, so this
7313   ;; will really go down to a leaf article first, before slowly
7314   ;; working its way up towards the root.
7315   (when thread
7316     (let ((children
7317            (if (cdr thread)
7318                (apply '+ (mapcar 'gnus-summary-limit-children
7319                                  (cdr thread)))
7320              0))
7321           (number (mail-header-number (car thread)))
7322           score)
7323       (if (and
7324            (not (memq number gnus-newsgroup-marked))
7325            (or
7326             ;; If this article is dormant and has absolutely no visible
7327             ;; children, then this article isn't visible.
7328             (and (memq number gnus-newsgroup-dormant)
7329                  (zerop children))
7330             ;; If this is "fetch-old-headered" and there is no
7331             ;; visible children, then we don't want this article.
7332             (and (or (eq gnus-fetch-old-headers 'some)
7333                      (numberp gnus-fetch-old-headers))
7334                  (gnus-summary-article-ancient-p number)
7335                  (zerop children))
7336             ;; If this is "fetch-old-headered" and `invisible', then
7337             ;; we don't want this article.
7338             (and (eq gnus-fetch-old-headers 'invisible)
7339                  (gnus-summary-article-ancient-p number))
7340             ;; If this is a sparsely inserted article with no children,
7341             ;; we don't want it.
7342             (and (eq gnus-build-sparse-threads 'some)
7343                  (gnus-summary-article-sparse-p number)
7344                  (zerop children))
7345             ;; If we use expunging, and this article is really
7346             ;; low-scored, then we don't want this article.
7347             (when (and gnus-summary-expunge-below
7348                        (< (setq score
7349                                 (or (cdr (assq number gnus-newsgroup-scored))
7350                                     gnus-summary-default-score))
7351                           gnus-summary-expunge-below))
7352               ;; We increase the expunge-tally here, but that has
7353               ;; nothing to do with the limits, really.
7354               (incf gnus-newsgroup-expunged-tally)
7355               ;; We also mark as read here, if that's wanted.
7356               (when (and gnus-summary-mark-below
7357                          (< score gnus-summary-mark-below))
7358                 (setq gnus-newsgroup-unreads
7359                       (delq number gnus-newsgroup-unreads))
7360                 (if gnus-newsgroup-auto-expire
7361                     (push number gnus-newsgroup-expirable)
7362                   (push (cons number gnus-low-score-mark)
7363                         gnus-newsgroup-reads)))
7364               t)
7365             ;; Do the `display' group parameter.
7366             (and gnus-newsgroup-display
7367                  (not (funcall gnus-newsgroup-display)))
7368             ;; Check NoCeM things.
7369             (if (and gnus-use-nocem
7370                      (gnus-nocem-unwanted-article-p
7371                       (mail-header-id (car thread))))
7372                 (progn
7373                   (setq gnus-newsgroup-unreads
7374                         (delq number gnus-newsgroup-unreads))
7375                   t))))
7376           ;; Nope, invisible article.
7377           0
7378         ;; Ok, this article is to be visible, so we add it to the limit
7379         ;; and return 1.
7380         (push number gnus-newsgroup-limit)
7381         1))))
7382
7383 (defun gnus-expunge-thread (thread)
7384   "Mark all articles in THREAD as read."
7385   (let* ((number (mail-header-number (car thread))))
7386     (incf gnus-newsgroup-expunged-tally)
7387     ;; We also mark as read here, if that's wanted.
7388     (setq gnus-newsgroup-unreads
7389           (delq number gnus-newsgroup-unreads))
7390     (if gnus-newsgroup-auto-expire
7391         (push number gnus-newsgroup-expirable)
7392       (push (cons number gnus-low-score-mark)
7393             gnus-newsgroup-reads)))
7394   ;; Go recursively through all subthreads.
7395   (mapcar 'gnus-expunge-thread (cdr thread)))
7396
7397 ;; Summary article oriented commands
7398
7399 (defun gnus-summary-refer-parent-article (n)
7400   "Refer parent article N times.
7401 If N is negative, go to ancestor -N instead.
7402 The difference between N and the number of articles fetched is returned."
7403   (interactive "p")
7404   (let ((skip 1)
7405         error header ref)
7406     (when (not (natnump n))
7407       (setq skip (abs n)
7408             n 1))
7409     (while (and (> n 0)
7410                 (not error))
7411       (setq header (gnus-summary-article-header))
7412       (if (and (eq (mail-header-number header)
7413                    (cdr gnus-article-current))
7414                (equal gnus-newsgroup-name
7415                       (car gnus-article-current)))
7416           ;; If we try to find the parent of the currently
7417           ;; displayed article, then we take a look at the actual
7418           ;; References header, since this is slightly more
7419           ;; reliable than the References field we got from the
7420           ;; server.
7421           (save-excursion
7422             (set-buffer gnus-original-article-buffer)
7423             (nnheader-narrow-to-headers)
7424             (unless (setq ref (message-fetch-field "references"))
7425               (setq ref (message-fetch-field "in-reply-to")))
7426             (widen))
7427         (setq ref
7428               ;; It's not the current article, so we take a bet on
7429               ;; the value we got from the server.
7430               (mail-header-references header)))
7431       (if (and ref
7432                (not (equal ref "")))
7433           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7434             (gnus-message 1 "Couldn't find parent"))
7435         (gnus-message 1 "No references in article %d"
7436                       (gnus-summary-article-number))
7437         (setq error t))
7438       (decf n))
7439     (gnus-summary-position-point)
7440     n))
7441
7442 (defun gnus-summary-refer-references ()
7443   "Fetch all articles mentioned in the References header.
7444 Return the number of articles fetched."
7445   (interactive)
7446   (let ((ref (mail-header-references (gnus-summary-article-header)))
7447         (current (gnus-summary-article-number))
7448         (n 0))
7449     (if (or (not ref)
7450             (equal ref ""))
7451         (error "No References in the current article")
7452       ;; For each Message-ID in the References header...
7453       (while (string-match "<[^>]*>" ref)
7454         (incf n)
7455         ;; ... fetch that article.
7456         (gnus-summary-refer-article
7457          (prog1 (match-string 0 ref)
7458            (setq ref (substring ref (match-end 0))))))
7459       (gnus-summary-goto-subject current)
7460       (gnus-summary-position-point)
7461       n)))
7462
7463 (defun gnus-summary-refer-thread (&optional limit)
7464   "Fetch all articles in the current thread.
7465 If LIMIT (the numerical prefix), fetch that many old headers instead
7466 of what's specified by the `gnus-refer-thread-limit' variable."
7467   (interactive "P")
7468   (let ((id (mail-header-id (gnus-summary-article-header)))
7469         (limit (if limit (prefix-numeric-value limit)
7470                  gnus-refer-thread-limit)))
7471     ;; We want to fetch LIMIT *old* headers, but we also have to
7472     ;; re-fetch all the headers in the current buffer, because many of
7473     ;; them may be undisplayed.  So we adjust LIMIT.
7474     (when (numberp limit)
7475       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7476     (unless (eq gnus-fetch-old-headers 'invisible)
7477       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7478       ;; Retrieve the headers and read them in.
7479       (if (eq (gnus-retrieve-headers
7480                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7481               'nov)
7482           (gnus-build-all-threads)
7483         (error "Can't fetch thread from backends that don't support NOV"))
7484       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7485     (gnus-summary-limit-include-thread id)))
7486
7487 (defun gnus-summary-refer-article (message-id)
7488   "Fetch an article specified by MESSAGE-ID."
7489   (interactive "sMessage-ID: ")
7490   (when (and (stringp message-id)
7491              (not (zerop (length message-id))))
7492     ;; Construct the correct Message-ID if necessary.
7493     ;; Suggested by tale@pawl.rpi.edu.
7494     (unless (string-match "^<" message-id)
7495       (setq message-id (concat "<" message-id)))
7496     (unless (string-match ">$" message-id)
7497       (setq message-id (concat message-id ">")))
7498     (let* ((header (gnus-id-to-header message-id))
7499            (sparse (and header
7500                         (gnus-summary-article-sparse-p
7501                          (mail-header-number header))
7502                         (memq (mail-header-number header)
7503                               gnus-newsgroup-limit)))
7504            number)
7505       (cond
7506        ;; If the article is present in the buffer we just go to it.
7507        ((and header
7508              (or (not (gnus-summary-article-sparse-p
7509                        (mail-header-number header)))
7510                  sparse))
7511         (prog1
7512             (gnus-summary-goto-article
7513              (mail-header-number header) nil t)
7514           (when sparse
7515             (gnus-summary-update-article (mail-header-number header)))))
7516        (t
7517         ;; We fetch the article.
7518         (catch 'found
7519           (dolist (gnus-override-method (gnus-refer-article-methods))
7520             (gnus-check-server gnus-override-method)
7521             ;; Fetch the header, and display the article.
7522             (when (setq number (gnus-summary-insert-subject message-id))
7523               (gnus-summary-select-article nil nil nil number)
7524               (throw 'found t)))
7525           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7526
7527 (defun gnus-refer-article-methods ()
7528   "Return a list of referrable methods."
7529   (cond
7530    ;; No method, so we default to current and native.
7531    ((null gnus-refer-article-method)
7532     (list gnus-current-select-method gnus-select-method))
7533    ;; Current.
7534    ((eq 'current gnus-refer-article-method)
7535     (list gnus-current-select-method))
7536    ;; List of select methods.
7537    ((not (and (symbolp (car gnus-refer-article-method))
7538               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7539     (let (out)
7540       (dolist (method gnus-refer-article-method)
7541         (push (if (eq 'current method)
7542                   gnus-current-select-method
7543                 method)
7544               out))
7545       (nreverse out)))
7546    ;; One single select method.
7547    (t
7548     (list gnus-refer-article-method))))
7549
7550 (defun gnus-summary-edit-parameters ()
7551   "Edit the group parameters of the current group."
7552   (interactive)
7553   (gnus-group-edit-group gnus-newsgroup-name 'params))
7554
7555 (defun gnus-summary-customize-parameters ()
7556   "Customize the group parameters of the current group."
7557   (interactive)
7558   (gnus-group-customize gnus-newsgroup-name))
7559
7560 (defun gnus-summary-enter-digest-group (&optional force)
7561   "Enter an nndoc group based on the current article.
7562 If FORCE, force a digest interpretation.  If not, try
7563 to guess what the document format is."
7564   (interactive "P")
7565   (let ((conf gnus-current-window-configuration))
7566     (save-excursion
7567       (gnus-summary-select-article))
7568     (setq gnus-current-window-configuration conf)
7569     (let* ((name (format "%s-%d"
7570                          (gnus-group-prefixed-name
7571                           gnus-newsgroup-name (list 'nndoc ""))
7572                          (save-excursion
7573                            (set-buffer gnus-summary-buffer)
7574                            gnus-current-article)))
7575            (ogroup gnus-newsgroup-name)
7576            (params (append (gnus-info-params (gnus-get-info ogroup))
7577                            (list (cons 'to-group ogroup))
7578                            (list (cons 'save-article-group ogroup))))
7579            (case-fold-search t)
7580            (buf (current-buffer))
7581            dig to-address)
7582       (save-excursion
7583         (set-buffer gnus-original-article-buffer)
7584         ;; Have the digest group inherit the main mail address of
7585         ;; the parent article.
7586         (when (setq to-address (or (message-fetch-field "reply-to")
7587                                    (message-fetch-field "from")))
7588           (setq params (append
7589                         (list (cons 'to-address
7590                                     (funcall gnus-decode-encoded-word-function
7591                                              to-address))))))
7592         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7593         (insert-buffer-substring gnus-original-article-buffer)
7594         ;; Remove lines that may lead nndoc to misinterpret the
7595         ;; document type.
7596         (narrow-to-region
7597          (goto-char (point-min))
7598          (or (search-forward "\n\n" nil t) (point)))
7599         (goto-char (point-min))
7600         (delete-matching-lines "^Path:\\|^From ")
7601         (widen))
7602       (unwind-protect
7603           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7604                     (gnus-newsgroup-ephemeral-ignored-charsets
7605                      gnus-newsgroup-ignored-charsets))
7606                 (gnus-group-read-ephemeral-group
7607                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7608                               (nndoc-article-type
7609                                ,(if force 'mbox 'guess))) t))
7610             ;; Make all postings to this group go to the parent group.
7611               (nconc (gnus-info-params (gnus-get-info name))
7612                      params)
7613             ;; Couldn't select this doc group.
7614             (switch-to-buffer buf)
7615             (gnus-set-global-variables)
7616             (gnus-configure-windows 'summary)
7617             (gnus-message 3 "Article couldn't be entered?"))
7618         (kill-buffer dig)))))
7619
7620 (defun gnus-summary-read-document (n)
7621   "Open a new group based on the current article(s).
7622 This will allow you to read digests and other similar
7623 documents as newsgroups.
7624 Obeys the standard process/prefix convention."
7625   (interactive "P")
7626   (let* ((articles (gnus-summary-work-articles n))
7627          (ogroup gnus-newsgroup-name)
7628          (params (append (gnus-info-params (gnus-get-info ogroup))
7629                          (list (cons 'to-group ogroup))))
7630          article group egroup groups vgroup)
7631     (while (setq article (pop articles))
7632       (setq group (format "%s-%d" gnus-newsgroup-name article))
7633       (gnus-summary-remove-process-mark article)
7634       (when (gnus-summary-display-article article)
7635         (save-excursion
7636           (with-temp-buffer
7637             (insert-buffer-substring gnus-original-article-buffer)
7638             ;; Remove some headers that may lead nndoc to make
7639             ;; the wrong guess.
7640             (message-narrow-to-head)
7641             (goto-char (point-min))
7642             (delete-matching-lines "^\\(Path\\):\\|^From ")
7643             (widen)
7644             (if (setq egroup
7645                       (gnus-group-read-ephemeral-group
7646                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7647                                      (nndoc-article-type guess))
7648                        t nil t))
7649                 (progn
7650             ;; Make all postings to this group go to the parent group.
7651                   (nconc (gnus-info-params (gnus-get-info egroup))
7652                          params)
7653                   (push egroup groups))
7654               ;; Couldn't select this doc group.
7655               (gnus-error 3 "Article couldn't be entered"))))))
7656     ;; Now we have selected all the documents.
7657     (cond
7658      ((not groups)
7659       (error "None of the articles could be interpreted as documents"))
7660      ((gnus-group-read-ephemeral-group
7661        (setq vgroup (format
7662                      "nnvirtual:%s-%s" gnus-newsgroup-name
7663                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7664        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7665        t
7666        (cons (current-buffer) 'summary)))
7667      (t
7668       (error "Couldn't select virtual nndoc group")))))
7669
7670 (defun gnus-summary-isearch-article (&optional regexp-p)
7671   "Do incremental search forward on the current article.
7672 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7673   (interactive "P")
7674   (gnus-summary-select-article)
7675   (gnus-configure-windows 'article)
7676   (gnus-eval-in-buffer-window gnus-article-buffer
7677     (save-restriction
7678       (widen)
7679       (isearch-forward regexp-p))))
7680
7681 (defun gnus-summary-search-article-forward (regexp &optional backward)
7682   "Search for an article containing REGEXP forward.
7683 If BACKWARD, search backward instead."
7684   (interactive
7685    (list (read-string
7686           (format "Search article %s (regexp%s): "
7687                   (if current-prefix-arg "backward" "forward")
7688                   (if gnus-last-search-regexp
7689                       (concat ", default " gnus-last-search-regexp)
7690                     "")))
7691          current-prefix-arg))
7692   (if (string-equal regexp "")
7693       (setq regexp (or gnus-last-search-regexp ""))
7694     (setq gnus-last-search-regexp regexp)
7695     (setq gnus-article-before-search gnus-current-article))
7696   ;; Intentionally set gnus-last-article.
7697   (setq gnus-last-article gnus-article-before-search)
7698   (let ((gnus-last-article gnus-last-article))
7699     (if (gnus-summary-search-article regexp backward)
7700         (gnus-summary-show-thread)
7701       (error "Search failed: \"%s\"" regexp))))
7702
7703 (defun gnus-summary-search-article-backward (regexp)
7704   "Search for an article containing REGEXP backward."
7705   (interactive
7706    (list (read-string
7707           (format "Search article backward (regexp%s): "
7708                   (if gnus-last-search-regexp
7709                       (concat ", default " gnus-last-search-regexp)
7710                     "")))))
7711   (gnus-summary-search-article-forward regexp 'backward))
7712
7713 (defun gnus-summary-search-article (regexp &optional backward)
7714   "Search for an article containing REGEXP.
7715 Optional argument BACKWARD means do search for backward.
7716 `gnus-select-article-hook' is not called during the search."
7717   ;; We have to require this here to make sure that the following
7718   ;; dynamic binding isn't shadowed by autoloading.
7719   (require 'gnus-async)
7720   (require 'gnus-art)
7721   (let ((gnus-select-article-hook nil)  ;Disable hook.
7722         (gnus-article-prepare-hook nil)
7723         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7724         (gnus-use-article-prefetch nil)
7725         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7726         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7727         (sum (current-buffer))
7728         (gnus-display-mime-function nil)
7729         (found nil)
7730         point)
7731     (gnus-save-hidden-threads
7732       (gnus-summary-select-article)
7733       (set-buffer gnus-article-buffer)
7734       (goto-char (window-point (get-buffer-window (current-buffer))))
7735       (when backward
7736         (forward-line -1))
7737       (while (not found)
7738         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7739         (if (if backward
7740                 (re-search-backward regexp nil t)
7741               (re-search-forward regexp nil t))
7742             ;; We found the regexp.
7743             (progn
7744               (setq found 'found)
7745               (beginning-of-line)
7746               (set-window-start
7747                (get-buffer-window (current-buffer))
7748                (point))
7749               (forward-line 1)
7750               (set-window-point
7751                (get-buffer-window (current-buffer))
7752                (point))
7753               (set-buffer sum)
7754               (setq point (point)))
7755           ;; We didn't find it, so we go to the next article.
7756           (set-buffer sum)
7757           (setq found 'not)
7758           (while (eq found 'not)
7759             (if (not (if backward (gnus-summary-find-prev)
7760                        (gnus-summary-find-next)))
7761                 ;; No more articles.
7762                 (setq found t)
7763               ;; Select the next article and adjust point.
7764               (unless (gnus-summary-article-sparse-p
7765                        (gnus-summary-article-number))
7766                 (setq found nil)
7767                 (gnus-summary-select-article)
7768                 (set-buffer gnus-article-buffer)
7769                 (widen)
7770                 (goto-char (if backward (point-max) (point-min))))))))
7771       (gnus-message 7 ""))
7772     ;; Return whether we found the regexp.
7773     (when (eq found 'found)
7774       (goto-char point)
7775       (gnus-summary-show-thread)
7776       (gnus-summary-goto-subject gnus-current-article)
7777       (gnus-summary-position-point)
7778       t)))
7779
7780 (defun gnus-find-matching-articles (header regexp)
7781   "Return a list of all articles that match REGEXP on HEADER.
7782 This search includes all articles in the current group that Gnus has
7783 fetched headers for, whether they are displayed or not."
7784   (let ((articles nil)
7785         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7786         (case-fold-search t))
7787     (dolist (header gnus-newsgroup-headers)
7788       (when (string-match regexp (funcall func header))
7789         (push (mail-header-number header) articles)))
7790     (nreverse articles)))
7791
7792 (defun gnus-summary-find-matching (header regexp &optional backward unread
7793                                           not-case-fold not-matching)
7794   "Return a list of all articles that match REGEXP on HEADER.
7795 The search stars on the current article and goes forwards unless
7796 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7797 If UNREAD is non-nil, only unread articles will
7798 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7799 in the comparisons. If NOT-MATCHING, return a list of all articles that
7800 not match REGEXP on HEADER."
7801   (let ((case-fold-search (not not-case-fold))
7802         articles d func)
7803     (if (consp header)
7804         (if (eq (car header) 'extra)
7805             (setq func
7806                   `(lambda (h)
7807                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7808                          "")))
7809           (error "%s is an invalid header" header))
7810       (unless (fboundp (intern (concat "mail-header-" header)))
7811         (error "%s is not a valid header" header))
7812       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7813     (dolist (d (if (eq backward 'all)
7814                    gnus-newsgroup-data
7815                  (gnus-data-find-list
7816                   (gnus-summary-article-number)
7817                   (gnus-data-list backward))))
7818       (when (and (or (not unread)       ; We want all articles...
7819                      (gnus-data-unread-p d)) ; Or just unreads.
7820                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7821                  (if not-matching
7822                      (not (string-match
7823                            regexp
7824                            (funcall func (gnus-data-header d))))
7825                    (string-match regexp
7826                                  (funcall func (gnus-data-header d)))))
7827         (push (gnus-data-number d) articles))) ; Success!
7828     (nreverse articles)))
7829
7830 (defun gnus-summary-execute-command (header regexp command &optional backward)
7831   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7832 If HEADER is an empty string (or nil), the match is done on the entire
7833 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7834   (interactive
7835    (list (let ((completion-ignore-case t))
7836            (completing-read
7837             "Header name: "
7838             (mapcar (lambda (header) (list (format "%s" header)))
7839                     (append
7840                      '("Number" "Subject" "From" "Lines" "Date"
7841                        "Message-ID" "Xref" "References" "Body")
7842                      gnus-extra-headers))
7843             nil 'require-match))
7844          (read-string "Regexp: ")
7845          (read-key-sequence "Command: ")
7846          current-prefix-arg))
7847   (when (equal header "Body")
7848     (setq header ""))
7849   ;; Hidden thread subtrees must be searched as well.
7850   (gnus-summary-show-all-threads)
7851   ;; We don't want to change current point nor window configuration.
7852   (save-excursion
7853     (save-window-excursion
7854       (gnus-message 6 "Executing %s..." (key-description command))
7855 ;; We'd like to execute COMMAND interactively so as to give arguments.
7856       (gnus-execute header regexp
7857                     `(call-interactively ',(key-binding command))
7858                     backward)
7859       (gnus-message 6 "Executing %s...done" (key-description command)))))
7860
7861 (defun gnus-summary-beginning-of-article ()
7862   "Scroll the article back to the beginning."
7863   (interactive)
7864   (gnus-summary-select-article)
7865   (gnus-configure-windows 'article)
7866   (gnus-eval-in-buffer-window gnus-article-buffer
7867     (widen)
7868     (goto-char (point-min))
7869     (when gnus-page-broken
7870       (gnus-narrow-to-page))))
7871
7872 (defun gnus-summary-end-of-article ()
7873   "Scroll to the end of the article."
7874   (interactive)
7875   (gnus-summary-select-article)
7876   (gnus-configure-windows 'article)
7877   (gnus-eval-in-buffer-window gnus-article-buffer
7878     (widen)
7879     (goto-char (point-max))
7880     (recenter -3)
7881     (when gnus-page-broken
7882       (gnus-narrow-to-page))))
7883
7884 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7885   "Truncate to LEN and quote all \"(\"'s in STRING."
7886   (gnus-replace-in-string (if (and len (> (length string) len))
7887                               (substring string 0 len)
7888                             string)
7889                           "[()]" "\\\\\\&"))
7890
7891 (defun gnus-summary-print-article (&optional filename n)
7892   "Generate and print a PostScript image of the N next (mail) articles.
7893
7894 If N is negative, print the N previous articles.  If N is nil and articles
7895 have been marked with the process mark, print these instead.
7896
7897 If the optional first argument FILENAME is nil, send the image to the
7898 printer.  If FILENAME is a string, save the PostScript image in a file with
7899 that name.  If FILENAME is a number, prompt the user for the name of the file
7900 to save in."
7901   (interactive (list (ps-print-preprint current-prefix-arg)))
7902   (dolist (article (gnus-summary-work-articles n))
7903     (gnus-summary-select-article nil nil 'pseudo article)
7904     (gnus-eval-in-buffer-window gnus-article-buffer
7905       (let ((buffer (generate-new-buffer " *print*")))
7906         (unwind-protect
7907             (progn
7908               (copy-to-buffer buffer (point-min) (point-max))
7909               (set-buffer buffer)
7910               (gnus-article-delete-invisible-text)
7911               (when (gnus-visual-p 'article-highlight 'highlight)
7912                 ;; Copy-to-buffer doesn't copy overlay.  So redo
7913                 ;; highlight.
7914                 (let ((gnus-article-buffer buffer))
7915                   (gnus-article-highlight-citation t)
7916                   (gnus-article-highlight-signature)))
7917               (let ((ps-left-header
7918                      (list
7919                       (concat "("
7920                               (gnus-summary-print-truncate-and-quote
7921                                (mail-header-subject gnus-current-headers)
7922                                66) ")")
7923                       (concat "("
7924                               (gnus-summary-print-truncate-and-quote
7925                                (mail-header-from gnus-current-headers)
7926                                45) ")")))
7927                     (ps-right-header
7928                      (list
7929                       "/pagenumberstring load"
7930                       (concat "("
7931                               (mail-header-date gnus-current-headers) ")"))))
7932                 (gnus-run-hooks 'gnus-ps-print-hook)
7933                 (save-excursion
7934                   (if window-system
7935                       (ps-spool-buffer-with-faces)
7936                     (ps-spool-buffer)))))
7937           (kill-buffer buffer))))
7938     (gnus-summary-remove-process-mark article))
7939   (ps-despool filename))
7940
7941 (defun gnus-summary-show-article (&optional arg)
7942   "Force redisplaying of the current article.
7943 If ARG (the prefix) is a number, show the article with the charset
7944 defined in `gnus-summary-show-article-charset-alist', or the charset
7945 input.
7946 If ARG (the prefix) is non-nil and not a number, show the raw article
7947 without any article massaging functions being run.  Normally, the key strokes 
7948 are `C-u g'."
7949   (interactive "P")
7950   (cond
7951    ((numberp arg)
7952     (gnus-summary-show-article t)
7953     (let ((gnus-newsgroup-charset
7954            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7955                (mm-read-coding-system
7956                 "View as charset: "
7957                 (save-excursion
7958                   (set-buffer gnus-article-buffer)
7959                   (let ((coding-systems
7960                          (detect-coding-region (point) (point-max))))
7961                     (or (car-safe coding-systems)
7962                         coding-systems))))))
7963           (gnus-newsgroup-ignored-charsets 'gnus-all))
7964       (gnus-summary-select-article nil 'force)
7965       (let ((deps gnus-newsgroup-dependencies)
7966             head header lines)
7967         (save-excursion
7968           (set-buffer gnus-original-article-buffer)
7969           (save-restriction
7970             (message-narrow-to-head)
7971             (setq head (buffer-string))
7972             (goto-char (point-min))
7973             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
7974               (goto-char (point-max))
7975               (widen)
7976               (setq lines (1- (count-lines (point) (point-max))))))
7977           (with-temp-buffer
7978             (insert (format "211 %d Article retrieved.\n"
7979                             (cdr gnus-article-current)))
7980             (insert head)
7981             (if lines (insert (format "Lines: %d\n" lines)))
7982             (insert ".\n")
7983             (let ((nntp-server-buffer (current-buffer)))
7984               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7985         (gnus-data-set-header
7986          (gnus-data-find (cdr gnus-article-current))
7987          header)
7988         (gnus-summary-update-article-line
7989          (cdr gnus-article-current) header)
7990         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
7991           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
7992    ((not arg)
7993     ;; Select the article the normal way.
7994     (gnus-summary-select-article nil 'force))
7995    (t
7996     ;; We have to require this here to make sure that the following
7997     ;; dynamic binding isn't shadowed by autoloading.
7998     (require 'gnus-async)
7999     (require 'gnus-art)
8000     ;; Bind the article treatment functions to nil.
8001     (let ((gnus-have-all-headers t)
8002           gnus-article-prepare-hook
8003           gnus-article-decode-hook
8004           gnus-display-mime-function
8005           gnus-break-pages)
8006       ;; Destroy any MIME parts.
8007       (when (gnus-buffer-live-p gnus-article-buffer)
8008         (save-excursion
8009           (set-buffer gnus-article-buffer)
8010           (mm-destroy-parts gnus-article-mime-handles)
8011           ;; Set it to nil for safety reason.
8012           (setq gnus-article-mime-handle-alist nil)
8013           (setq gnus-article-mime-handles nil)))
8014       (gnus-summary-select-article nil 'force))))
8015   (gnus-summary-goto-subject gnus-current-article)
8016   (gnus-summary-position-point))
8017
8018 (defun gnus-summary-show-raw-article ()
8019   "Show the raw article without any article massaging functions being run."
8020   (interactive)
8021   (gnus-summary-show-article t))
8022
8023 (defun gnus-summary-verbose-headers (&optional arg)
8024   "Toggle permanent full header display.
8025 If ARG is a positive number, turn header display on.
8026 If ARG is a negative number, turn header display off."
8027   (interactive "P")
8028   (setq gnus-show-all-headers
8029         (cond ((or (not (numberp arg))
8030                    (zerop arg))
8031                (not gnus-show-all-headers))
8032               ((natnump arg)
8033                t)))
8034   (gnus-summary-show-article))
8035
8036 (defun gnus-summary-toggle-header (&optional arg)
8037   "Show the headers if they are hidden, or hide them if they are shown.
8038 If ARG is a positive number, show the entire header.
8039 If ARG is a negative number, hide the unwanted header lines."
8040   (interactive "P")
8041   (save-excursion
8042     (set-buffer gnus-article-buffer)
8043     (save-restriction
8044       (let* ((buffer-read-only nil)
8045              (inhibit-point-motion-hooks t)
8046              hidden e)
8047         (setq hidden
8048               (if (numberp arg)
8049                   (>= arg 0)
8050                 (save-restriction
8051                   (article-narrow-to-head)
8052                   (gnus-article-hidden-text-p 'headers))))
8053         (goto-char (point-min))
8054         (when (search-forward "\n\n" nil t)
8055           (delete-region (point-min) (1- (point))))
8056         (goto-char (point-min))
8057         (save-excursion
8058           (set-buffer gnus-original-article-buffer)
8059           (goto-char (point-min))
8060           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8061         (insert-buffer-substring gnus-original-article-buffer 1 e)
8062         (save-restriction
8063           (narrow-to-region (point-min) (point))
8064           (article-decode-encoded-words)
8065           (if  hidden
8066               (let ((gnus-treat-hide-headers nil)
8067                     (gnus-treat-hide-boring-headers nil))
8068                 (setq gnus-article-wash-types
8069                       (delq 'headers gnus-article-wash-types))
8070                 (gnus-treat-article 'head))
8071             (gnus-treat-article 'head)))
8072         (gnus-set-mode-line 'article)))))
8073
8074 (defun gnus-summary-show-all-headers ()
8075   "Make all header lines visible."
8076   (interactive)
8077   (gnus-summary-toggle-header 1))
8078
8079 (defun gnus-summary-caesar-message (&optional arg)
8080   "Caesar rotate the current article by 13.
8081 The numerical prefix specifies how many places to rotate each letter
8082 forward."
8083   (interactive "P")
8084   (gnus-summary-select-article)
8085   (let ((mail-header-separator ""))
8086     (gnus-eval-in-buffer-window gnus-article-buffer
8087       (save-restriction
8088         (widen)
8089         (let ((start (window-start))
8090               buffer-read-only)
8091           (message-caesar-buffer-body arg)
8092           (set-window-start (get-buffer-window (current-buffer)) start))))))
8093
8094 (defun gnus-summary-stop-page-breaking ()
8095   "Stop page breaking in the current article."
8096   (interactive)
8097   (gnus-summary-select-article)
8098   (gnus-eval-in-buffer-window gnus-article-buffer
8099     (widen)
8100     (when (gnus-visual-p 'page-marker)
8101       (let ((buffer-read-only nil))
8102         (gnus-remove-text-with-property 'gnus-prev)
8103         (gnus-remove-text-with-property 'gnus-next))
8104       (setq gnus-page-broken nil))))
8105
8106 (defun gnus-summary-move-article (&optional n to-newsgroup
8107                                             select-method action)
8108   "Move the current article to a different newsgroup.
8109 If N is a positive number, move the N next articles.
8110 If N is a negative number, move the N previous articles.
8111 If N is nil and any articles have been marked with the process mark,
8112 move those articles instead.
8113 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8114 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8115 re-spool using this method.
8116
8117 For this function to work, both the current newsgroup and the
8118 newsgroup that you want to move to have to support the `request-move'
8119 and `request-accept' functions.
8120
8121 ACTION can be either `move' (the default), `crosspost' or `copy'."
8122   (interactive "P")
8123   (unless action
8124     (setq action 'move))
8125   ;; Check whether the source group supports the required functions.
8126   (cond ((and (eq action 'move)
8127               (not (gnus-check-backend-function
8128                     'request-move-article gnus-newsgroup-name)))
8129          (error "The current group does not support article moving"))
8130         ((and (eq action 'crosspost)
8131               (not (gnus-check-backend-function
8132                     'request-replace-article gnus-newsgroup-name)))
8133          (error "The current group does not support article editing")))
8134   (let ((articles (gnus-summary-work-articles n))
8135         (prefix (if (gnus-check-backend-function
8136                      'request-move-article gnus-newsgroup-name)
8137                     (gnus-group-real-prefix gnus-newsgroup-name)
8138                   ""))
8139         (names '((move "Move" "Moving")
8140                  (copy "Copy" "Copying")
8141                  (crosspost "Crosspost" "Crossposting")))
8142         (copy-buf (save-excursion
8143                     (nnheader-set-temp-buffer " *copy article*")))
8144         art-group to-method new-xref article to-groups)
8145     (unless (assq action names)
8146       (error "Unknown action %s" action))
8147     ;; We have to select an article to give
8148     ;; `gnus-read-move-group-name' an opportunity to suggest an
8149     ;; appropriate default.
8150     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8151       (gnus-summary-select-article nil nil nil (car articles)))
8152     ;; Read the newsgroup name.
8153     (when (and (not to-newsgroup)
8154                (not select-method))
8155       (setq to-newsgroup
8156             (gnus-read-move-group-name
8157              (cadr (assq action names))
8158              (symbol-value (intern (format "gnus-current-%s-group" action)))
8159              articles prefix))
8160       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8161     (setq to-method (or select-method
8162                         (gnus-server-to-method
8163                          (gnus-group-method to-newsgroup))))
8164     ;; Check the method we are to move this article to...
8165     (unless (gnus-check-backend-function
8166              'request-accept-article (car to-method))
8167       (error "%s does not support article copying" (car to-method)))
8168     (unless (gnus-check-server to-method)
8169       (error "Can't open server %s" (car to-method)))
8170     (gnus-message 6 "%s to %s: %s..."
8171                   (caddr (assq action names))
8172                   (or (car select-method) to-newsgroup) articles)
8173     (while articles
8174       (setq article (pop articles))
8175       (setq
8176        art-group
8177        (cond
8178         ;; Move the article.
8179         ((eq action 'move)
8180          ;; Remove this article from future suppression.
8181          (gnus-dup-unsuppress-article article)
8182          (gnus-request-move-article
8183           article                       ; Article to move
8184           gnus-newsgroup-name           ; From newsgroup
8185           (nth 1 (gnus-find-method-for-group
8186                   gnus-newsgroup-name)) ; Server
8187           (list 'gnus-request-accept-article
8188                 to-newsgroup (list 'quote select-method)
8189                 (not articles) t)       ; Accept form
8190           (not articles)))              ; Only save nov last time
8191         ;; Copy the article.
8192         ((eq action 'copy)
8193          (save-excursion
8194            (set-buffer copy-buf)
8195            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8196              (gnus-request-accept-article
8197               to-newsgroup select-method (not articles) t))))
8198         ;; Crosspost the article.
8199         ((eq action 'crosspost)
8200          (let ((xref (message-tokenize-header
8201                       (mail-header-xref (gnus-summary-article-header article))
8202                       " ")))
8203            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8204                                   ":" (number-to-string article)))
8205            (unless xref
8206              (setq xref (list (system-name))))
8207            (setq new-xref
8208                  (concat
8209                   (mapconcat 'identity
8210                              (delete "Xref:" (delete new-xref xref))
8211                              " ")
8212                   " " new-xref))
8213            (save-excursion
8214              (set-buffer copy-buf)
8215              ;; First put the article in the destination group.
8216              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8217              (when (consp (setq art-group
8218                                 (gnus-request-accept-article
8219                                  to-newsgroup select-method (not articles))))
8220                (setq new-xref (concat new-xref " " (car art-group)
8221                                       ":"
8222                                       (number-to-string (cdr art-group))))
8223                ;; Now we have the new Xrefs header, so we insert
8224                ;; it and replace the new article.
8225                (nnheader-replace-header "Xref" new-xref)
8226                (gnus-request-replace-article
8227                 (cdr art-group) to-newsgroup (current-buffer))
8228                art-group))))))
8229       (cond
8230        ((not art-group)
8231         (gnus-message 1 "Couldn't %s article %s: %s"
8232                       (cadr (assq action names)) article
8233                       (nnheader-get-report (car to-method))))
8234        ((eq art-group 'junk)
8235         (when (eq action 'move)
8236           (gnus-summary-mark-article article gnus-canceled-mark)
8237           (gnus-message 4 "Deleted article %s" article)))
8238        (t
8239         (let* ((pto-group (gnus-group-prefixed-name
8240                            (car art-group) to-method))
8241                (entry
8242                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8243                (info (nth 2 entry))
8244                (to-group (gnus-info-group info))
8245                to-marks)
8246           ;; Update the group that has been moved to.
8247           (when (and info
8248                      (memq action '(move copy)))
8249             (unless (member to-group to-groups)
8250               (push to-group to-groups))
8251
8252             (unless (memq article gnus-newsgroup-unreads)
8253               (push 'read to-marks)
8254               (gnus-info-set-read
8255                info (gnus-add-to-range (gnus-info-read info)
8256                                        (list (cdr art-group)))))
8257
8258             ;; See whether the article is to be put in the cache.
8259             (let ((marks gnus-article-mark-lists)
8260                   (to-article (cdr art-group)))
8261
8262               ;; Enter the article into the cache in the new group,
8263               ;; if that is required.
8264               (when gnus-use-cache
8265                 (gnus-cache-possibly-enter-article
8266                  to-group to-article
8267                  (memq article gnus-newsgroup-marked)
8268                  (memq article gnus-newsgroup-dormant)
8269                  (memq article gnus-newsgroup-unreads)))
8270
8271               (when gnus-preserve-marks
8272                 ;; Copy any marks over to the new group.
8273                 (when (and (equal to-group gnus-newsgroup-name)
8274                            (not (memq article gnus-newsgroup-unreads)))
8275                   ;; Mark this article as read in this group.
8276                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8277                   (setcdr (gnus-active to-group) to-article)
8278                   (setcdr gnus-newsgroup-active to-article))
8279
8280                 (while marks
8281                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8282                     (when (memq article (symbol-value
8283                                          (intern (format "gnus-newsgroup-%s"
8284                                                          (caar marks)))))
8285                       (push (cdar marks) to-marks)
8286                       ;; If the other group is the same as this group,
8287                       ;; then we have to add the mark to the list.
8288                       (when (equal to-group gnus-newsgroup-name)
8289                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8290                              (cons to-article
8291                                    (symbol-value
8292                                     (intern (format "gnus-newsgroup-%s"
8293                                                     (caar marks)))))))
8294                       ;; Copy the marks to other group.
8295                       (gnus-add-marked-articles
8296                        to-group (cdar marks) (list to-article) info)))
8297                   (setq marks (cdr marks)))
8298
8299                 (gnus-request-set-mark to-group (list (list (list to-article)
8300                                                             'add
8301                                                             to-marks))))
8302
8303               (gnus-dribble-enter
8304                (concat "(gnus-group-set-info '"
8305                        (gnus-prin1-to-string (gnus-get-info to-group))
8306                        ")"))))
8307
8308           ;; Update the Xref header in this article to point to
8309           ;; the new crossposted article we have just created.
8310           (when (eq action 'crosspost)
8311             (save-excursion
8312               (set-buffer copy-buf)
8313               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8314               (nnheader-replace-header "Xref" new-xref)
8315               (gnus-request-replace-article
8316                article gnus-newsgroup-name (current-buffer)))))
8317
8318         ;;;!!!Why is this necessary?
8319         (set-buffer gnus-summary-buffer)
8320
8321         (gnus-summary-goto-subject article)
8322         (when (eq action 'move)
8323           (gnus-summary-mark-article article gnus-canceled-mark))))
8324       (gnus-summary-remove-process-mark article))
8325     ;; Re-activate all groups that have been moved to.
8326     (save-excursion
8327       (set-buffer gnus-group-buffer)
8328       (let ((gnus-group-marked to-groups))
8329         (gnus-group-get-new-news-this-group nil t)))
8330
8331     (gnus-kill-buffer copy-buf)
8332     (gnus-summary-position-point)
8333     (gnus-set-mode-line 'summary)))
8334
8335 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8336   "Move the current article to a different newsgroup.
8337 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8338 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8339 re-spool using this method."
8340   (interactive "P")
8341   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8342
8343 (defun gnus-summary-crosspost-article (&optional n)
8344   "Crosspost the current article to some other group."
8345   (interactive "P")
8346   (gnus-summary-move-article n nil nil 'crosspost))
8347
8348 (defcustom gnus-summary-respool-default-method nil
8349   "Default method type for respooling an article.
8350 If nil, use to the current newsgroup method."
8351   :type 'symbol
8352   :group 'gnus-summary-mail)
8353
8354 (defun gnus-summary-respool-article (&optional n method)
8355   "Respool the current article.
8356 The article will be squeezed through the mail spooling process again,
8357 which means that it will be put in some mail newsgroup or other
8358 depending on `nnmail-split-methods'.
8359 If N is a positive number, respool the N next articles.
8360 If N is a negative number, respool the N previous articles.
8361 If N is nil and any articles have been marked with the process mark,
8362 respool those articles instead.
8363
8364 Respooling can be done both from mail groups and \"real\" newsgroups.
8365 In the former case, the articles in question will be moved from the
8366 current group into whatever groups they are destined to.  In the
8367 latter case, they will be copied into the relevant groups."
8368   (interactive
8369    (list current-prefix-arg
8370          (let* ((methods (gnus-methods-using 'respool))
8371                 (methname
8372                  (symbol-name (or gnus-summary-respool-default-method
8373                                   (car (gnus-find-method-for-group
8374                                         gnus-newsgroup-name)))))
8375                 (method
8376                  (gnus-completing-read
8377                   methname "What backend do you want to use when respooling?"
8378                   methods nil t nil 'gnus-mail-method-history))
8379                 ms)
8380            (cond
8381             ((zerop (length (setq ms (gnus-servers-using-backend
8382                                       (intern method)))))
8383              (list (intern method) ""))
8384             ((= 1 (length ms))
8385              (car ms))
8386             (t
8387              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8388                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8389                            ms-alist))))))))
8390   (unless method
8391     (error "No method given for respooling"))
8392   (if (assoc (symbol-name
8393               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8394              (gnus-methods-using 'respool))
8395       (gnus-summary-move-article n nil method)
8396     (gnus-summary-copy-article n nil method)))
8397
8398 (defun gnus-summary-import-article (file &optional edit)
8399   "Import an arbitrary file into a mail newsgroup."
8400   (interactive "fImport file: \nP")
8401   (let ((group gnus-newsgroup-name)
8402         (now (current-time))
8403         atts lines group-art)
8404     (unless (gnus-check-backend-function 'request-accept-article group)
8405       (error "%s does not support article importing" group))
8406     (or (file-readable-p file)
8407         (not (file-regular-p file))
8408         (error "Can't read %s" file))
8409     (save-excursion
8410       (set-buffer (gnus-get-buffer-create " *import file*"))
8411       (erase-buffer)
8412       (nnheader-insert-file-contents file)
8413       (goto-char (point-min))
8414       (if (nnheader-article-p)
8415           (save-restriction
8416             (goto-char (point-min))
8417             (search-forward "\n\n" nil t)
8418             (narrow-to-region (point-min) (1- (point)))
8419             (goto-char (point-min))
8420             (unless (re-search-forward "^date:" nil t)
8421               (goto-char (point-max))
8422               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8423        ;; This doesn't look like an article, so we fudge some headers.
8424         (setq atts (file-attributes file)
8425               lines (count-lines (point-min) (point-max)))
8426         (insert "From: " (read-string "From: ") "\n"
8427                 "Subject: " (read-string "Subject: ") "\n"
8428                 "Date: " (message-make-date (nth 5 atts)) "\n"
8429                 "Message-ID: " (message-make-message-id) "\n"
8430                 "Lines: " (int-to-string lines) "\n"
8431                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8432       (setq group-art (gnus-request-accept-article group nil t))
8433       (kill-buffer (current-buffer)))
8434     (setq gnus-newsgroup-active (gnus-activate-group group))
8435     (forward-line 1)
8436     (gnus-summary-goto-article (cdr group-art) nil t)
8437     (when edit
8438       (gnus-summary-edit-article))))
8439
8440 (defun gnus-summary-create-article ()
8441   "Create an article in a mail newsgroup."
8442   (interactive)
8443   (let ((group gnus-newsgroup-name)
8444         (now (current-time))
8445         group-art)
8446     (unless (gnus-check-backend-function 'request-accept-article group)
8447       (error "%s does not support article importing" group))
8448     (save-excursion
8449       (set-buffer (gnus-get-buffer-create " *import file*"))
8450       (erase-buffer)
8451       (goto-char (point-min))
8452       ;; This doesn't look like an article, so we fudge some headers.
8453       (insert "From: " (read-string "From: ") "\n"
8454               "Subject: " (read-string "Subject: ") "\n"
8455               "Date: " (message-make-date now) "\n"
8456               "Message-ID: " (message-make-message-id) "\n")
8457       (setq group-art (gnus-request-accept-article group nil t))
8458       (kill-buffer (current-buffer)))
8459     (setq gnus-newsgroup-active (gnus-activate-group group))
8460     (forward-line 1)
8461     (gnus-summary-goto-article (cdr group-art) nil t)
8462     (gnus-summary-edit-article)))
8463
8464 (defun gnus-summary-article-posted-p ()
8465   "Say whether the current (mail) article is available from news as well.
8466 This will be the case if the article has both been mailed and posted."
8467   (interactive)
8468   (let ((id (mail-header-references (gnus-summary-article-header)))
8469         (gnus-override-method (car (gnus-refer-article-methods))))
8470     (if (gnus-request-head id "")
8471         (gnus-message 2 "The current message was found on %s"
8472                       gnus-override-method)
8473       (gnus-message 2 "The current message couldn't be found on %s"
8474                     gnus-override-method)
8475       nil)))
8476
8477 (defun gnus-summary-expire-articles (&optional now)
8478   "Expire all articles that are marked as expirable in the current group."
8479   (interactive)
8480   (when (gnus-check-backend-function
8481          'request-expire-articles gnus-newsgroup-name)
8482     ;; This backend supports expiry.
8483     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8484            (expirable (if total
8485                           (progn
8486                             ;; We need to update the info for
8487                             ;; this group for `gnus-list-of-read-articles'
8488                             ;; to give us the right answer.
8489                             (gnus-run-hooks 'gnus-exit-group-hook)
8490                             (gnus-summary-update-info)
8491                             (gnus-list-of-read-articles gnus-newsgroup-name))
8492                         (setq gnus-newsgroup-expirable
8493                               (sort gnus-newsgroup-expirable '<))))
8494            (expiry-wait (if now 'immediate
8495                           (gnus-group-find-parameter
8496                            gnus-newsgroup-name 'expiry-wait)))
8497            (nnmail-expiry-target
8498             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8499                 nnmail-expiry-target))
8500            es)
8501       (when expirable
8502         ;; There are expirable articles in this group, so we run them
8503         ;; through the expiry process.
8504         (gnus-message 6 "Expiring articles...")
8505         (unless (gnus-check-group gnus-newsgroup-name)
8506           (error "Can't open server for %s" gnus-newsgroup-name))
8507         ;; The list of articles that weren't expired is returned.
8508         (save-excursion
8509           (if expiry-wait
8510               (let ((nnmail-expiry-wait-function nil)
8511                     (nnmail-expiry-wait expiry-wait))
8512                 (setq es (gnus-request-expire-articles
8513                           expirable gnus-newsgroup-name)))
8514             (setq es (gnus-request-expire-articles
8515                       expirable gnus-newsgroup-name)))
8516           (unless total
8517             (setq gnus-newsgroup-expirable es))
8518           ;; We go through the old list of expirable, and mark all
8519           ;; really expired articles as nonexistent.
8520           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8521             (let ((gnus-use-cache nil))
8522               (while expirable
8523                 (unless (memq (car expirable) es)
8524                   (when (gnus-data-find (car expirable))
8525                     (gnus-summary-mark-article
8526                      (car expirable) gnus-canceled-mark)))
8527                 (setq expirable (cdr expirable))))))
8528         (gnus-message 6 "Expiring articles...done")))))
8529
8530 (defun gnus-summary-expire-articles-now ()
8531   "Expunge all expirable articles in the current group.
8532 This means that *all* articles that are marked as expirable will be
8533 deleted forever, right now."
8534   (interactive)
8535   (or gnus-expert-user
8536       (gnus-yes-or-no-p
8537        "Are you really, really, really sure you want to delete all these messages? ")
8538       (error "Phew!"))
8539   (gnus-summary-expire-articles t))
8540
8541 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8542 (defun gnus-summary-delete-article (&optional n)
8543   "Delete the N next (mail) articles.
8544 This command actually deletes articles.  This is not a marking
8545 command.  The article will disappear forever from your life, never to
8546 return.
8547 If N is negative, delete backwards.
8548 If N is nil and articles have been marked with the process mark,
8549 delete these instead."
8550   (interactive "P")
8551   (unless (gnus-check-backend-function 'request-expire-articles
8552                                        gnus-newsgroup-name)
8553     (error "The current newsgroup does not support article deletion"))
8554   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8555     (error "Couldn't open server"))
8556   ;; Compute the list of articles to delete.
8557   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8558         not-deleted)
8559     (if (and gnus-novice-user
8560              (not (gnus-yes-or-no-p
8561                    (format "Do you really want to delete %s forever? "
8562                            (if (> (length articles) 1)
8563                                (format "these %s articles" (length articles))
8564                              "this article")))))
8565         ()
8566       ;; Delete the articles.
8567       (setq not-deleted (gnus-request-expire-articles
8568                          articles gnus-newsgroup-name 'force))
8569       (while articles
8570         (gnus-summary-remove-process-mark (car articles))
8571         ;; The backend might not have been able to delete the article
8572         ;; after all.
8573         (unless (memq (car articles) not-deleted)
8574           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8575         (setq articles (cdr articles)))
8576       (when not-deleted
8577         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8578     (gnus-summary-position-point)
8579     (gnus-set-mode-line 'summary)
8580     not-deleted))
8581
8582 (defun gnus-summary-edit-article (&optional arg)
8583   "Edit the current article.
8584 This will have permanent effect only in mail groups.
8585 If ARG is nil, edit the decoded articles.
8586 If ARG is 1, edit the raw articles.
8587 If ARG is 2, edit the raw articles even in read-only groups.
8588 If ARG is 3, edit the articles with the current handles.
8589 Otherwise, allow editing of articles even in read-only
8590 groups."
8591   (interactive "P")
8592   (let (force raw current-handles)
8593     (cond
8594      ((null arg))
8595      ((eq arg 1) (setq raw t))
8596      ((eq arg 2) (setq raw t
8597                        force t))
8598      ((eq arg 3) (setq current-handles
8599                        (and (gnus-buffer-live-p gnus-article-buffer)
8600                             (with-current-buffer gnus-article-buffer
8601                               (prog1
8602                                   gnus-article-mime-handles
8603                                 (setq gnus-article-mime-handles nil))))))
8604      (t (setq force t)))
8605     (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8606         (error "Can't edit the raw article in group nndraft:drafts"))
8607     (save-excursion
8608       (set-buffer gnus-summary-buffer)
8609       (let ((mail-parse-charset gnus-newsgroup-charset)
8610             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8611         (gnus-set-global-variables)
8612         (when (and (not force)
8613                    (gnus-group-read-only-p))
8614           (error "The current newsgroup does not support article editing"))
8615         (gnus-summary-show-article t)
8616         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8617           (with-current-buffer gnus-article-buffer
8618             (mm-enable-multibyte-mule4)))
8619         (if (equal gnus-newsgroup-name "nndraft:drafts")
8620             (setq raw t))
8621         (gnus-article-edit-article
8622          (if raw 'ignore
8623            `(lambda ()
8624               (let ((mbl mml-buffer-list))
8625                 (setq mml-buffer-list nil)
8626                 (mime-to-mml ,'current-handles)
8627                 (let ((mbl1 mml-buffer-list))
8628                   (setq mml-buffer-list mbl)
8629                   (set (make-local-variable 'mml-buffer-list) mbl1))
8630                 (make-local-hook 'kill-buffer-hook)
8631                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8632          `(lambda (no-highlight)
8633             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8634                   (message-options message-options)
8635                   (message-options-set-recipient)
8636                   (mail-parse-ignored-charsets
8637                    ',gnus-newsgroup-ignored-charsets))
8638               ,(if (not raw) '(progn
8639                                 (mml-to-mime)
8640                                 (mml-destroy-buffers)
8641                                 (remove-hook 'kill-buffer-hook
8642                                              'mml-destroy-buffers t)
8643                                 (kill-local-variable 'mml-buffer-list)))
8644               (gnus-summary-edit-article-done
8645                ,(or (mail-header-references gnus-current-headers) "")
8646                ,(gnus-group-read-only-p)
8647                ,gnus-summary-buffer no-highlight))))))))
8648
8649 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8650
8651 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8652                                                  no-highlight)
8653   "Make edits to the current article permanent."
8654   (interactive)
8655   (save-excursion
8656    ;; The buffer restriction contains the entire article if it exists.
8657     (when (article-goto-body)
8658       (let ((lines (count-lines (point) (point-max)))
8659             (length (- (point-max) (point)))
8660             (case-fold-search t)
8661             (body (copy-marker (point))))
8662         (goto-char (point-min))
8663         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8664           (delete-region (match-beginning 1) (match-end 1))
8665           (insert (number-to-string length)))
8666         (goto-char (point-min))
8667         (when (re-search-forward
8668                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8669           (delete-region (match-beginning 1) (match-end 1))
8670           (insert (number-to-string length)))
8671         (goto-char (point-min))
8672         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8673           (delete-region (match-beginning 1) (match-end 1))
8674           (insert (number-to-string lines))))))
8675   ;; Replace the article.
8676   (let ((buf (current-buffer)))
8677     (with-temp-buffer
8678       (insert-buffer-substring buf)
8679
8680       (if (and (not read-only)
8681                (not (gnus-request-replace-article
8682                      (cdr gnus-article-current) (car gnus-article-current)
8683                      (current-buffer) t)))
8684           (error "Couldn't replace article")
8685         ;; Update the summary buffer.
8686         (if (and references
8687                  (equal (message-tokenize-header references " ")
8688                         (message-tokenize-header
8689                          (or (message-fetch-field "references") "") " ")))
8690             ;; We only have to update this line.
8691             (save-excursion
8692               (save-restriction
8693                 (message-narrow-to-head)
8694                 (let ((head (buffer-string))
8695                       header)
8696                   (with-temp-buffer
8697                     (insert (format "211 %d Article retrieved.\n"
8698                                     (cdr gnus-article-current)))
8699                     (insert head)
8700                     (insert ".\n")
8701                     (let ((nntp-server-buffer (current-buffer)))
8702                       (setq header (car (gnus-get-newsgroup-headers
8703                                          (save-excursion
8704                                            (set-buffer gnus-summary-buffer)
8705                                            gnus-newsgroup-dependencies)
8706                                          t))))
8707                     (save-excursion
8708                       (set-buffer gnus-summary-buffer)
8709                       (gnus-data-set-header
8710                        (gnus-data-find (cdr gnus-article-current))
8711                        header)
8712                       (gnus-summary-update-article-line
8713                        (cdr gnus-article-current) header)
8714                       (if (gnus-summary-goto-subject
8715                            (cdr gnus-article-current) nil t)
8716                           (gnus-summary-update-secondary-mark
8717                            (cdr gnus-article-current))))))))
8718           ;; Update threads.
8719           (set-buffer (or buffer gnus-summary-buffer))
8720           (gnus-summary-update-article (cdr gnus-article-current))
8721           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8722               (gnus-summary-update-secondary-mark
8723                (cdr gnus-article-current))))
8724         ;; Prettify the article buffer again.
8725         (unless no-highlight
8726           (save-excursion
8727             (set-buffer gnus-article-buffer)
8728             ;;;!!! Fix this -- article should be rehighlighted.
8729             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8730             (set-buffer gnus-original-article-buffer)
8731             (gnus-request-article
8732              (cdr gnus-article-current)
8733              (car gnus-article-current) (current-buffer))))
8734         ;; Prettify the summary buffer line.
8735         (when (gnus-visual-p 'summary-highlight 'highlight)
8736           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8737
8738 (defun gnus-summary-edit-wash (key)
8739   "Perform editing command KEY in the article buffer."
8740   (interactive
8741    (list
8742     (progn
8743       (message "%s" (concat (this-command-keys) "- "))
8744       (read-char))))
8745   (message "")
8746   (gnus-summary-edit-article)
8747   (execute-kbd-macro (concat (this-command-keys) key))
8748   (gnus-article-edit-done))
8749
8750
8751 (defun gnus-summary-toggle-smiley (&optional arg)
8752   "Toggle the display of smilies as small graphical icons."
8753   (interactive "P")
8754   (save-excursion
8755     (set-buffer gnus-article-buffer)
8756     (gnus-smiley-display arg)))
8757
8758 ;;; Respooling
8759
8760 (defun gnus-summary-respool-query (&optional silent trace)
8761   "Query where the respool algorithm would put this article."
8762   (interactive)
8763   (let (gnus-mark-article-hook)
8764     (gnus-summary-select-article)
8765     (save-excursion
8766       (set-buffer gnus-original-article-buffer)
8767       (save-restriction
8768         (message-narrow-to-head)
8769         (let ((groups (nnmail-article-group 'identity trace)))
8770           (unless silent
8771             (if groups
8772                 (message "This message would go to %s"
8773                          (mapconcat 'car groups ", "))
8774               (message "This message would go to no groups"))
8775             groups))))))
8776
8777 (defun gnus-summary-respool-trace ()
8778   "Trace where the respool algorithm would put this article.
8779 Display a buffer showing all fancy splitting patterns which matched."
8780   (interactive)
8781   (gnus-summary-respool-query nil t))
8782
8783 ;; Summary marking commands.
8784
8785 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8786   "Mark articles which has the same subject as read, and then select the next.
8787 If UNMARK is positive, remove any kind of mark.
8788 If UNMARK is negative, tick articles."
8789   (interactive "P")
8790   (when unmark
8791     (setq unmark (prefix-numeric-value unmark)))
8792   (let ((count
8793          (gnus-summary-mark-same-subject
8794           (gnus-summary-article-subject) unmark)))
8795     ;; Select next unread article.  If auto-select-same mode, should
8796     ;; select the first unread article.
8797     (gnus-summary-next-article t (and gnus-auto-select-same
8798                                       (gnus-summary-article-subject)))
8799     (gnus-message 7 "%d article%s marked as %s"
8800                   count (if (= count 1) " is" "s are")
8801                   (if unmark "unread" "read"))))
8802
8803 (defun gnus-summary-kill-same-subject (&optional unmark)
8804   "Mark articles which has the same subject as read.
8805 If UNMARK is positive, remove any kind of mark.
8806 If UNMARK is negative, tick articles."
8807   (interactive "P")
8808   (when unmark
8809     (setq unmark (prefix-numeric-value unmark)))
8810   (let ((count
8811          (gnus-summary-mark-same-subject
8812           (gnus-summary-article-subject) unmark)))
8813     ;; If marked as read, go to next unread subject.
8814     (when (null unmark)
8815       ;; Go to next unread subject.
8816       (gnus-summary-next-subject 1 t))
8817     (gnus-message 7 "%d articles are marked as %s"
8818                   count (if unmark "unread" "read"))))
8819
8820 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8821   "Mark articles with same SUBJECT as read, and return marked number.
8822 If optional argument UNMARK is positive, remove any kinds of marks.
8823 If optional argument UNMARK is negative, mark articles as unread instead."
8824   (let ((count 1))
8825     (save-excursion
8826       (cond
8827        ((null unmark)                   ; Mark as read.
8828         (while (and
8829                 (progn
8830                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8831                   (gnus-summary-show-thread) t)
8832                 (gnus-summary-find-subject subject))
8833           (setq count (1+ count))))
8834        ((> unmark 0)                    ; Tick.
8835         (while (and
8836                 (progn
8837                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8838                   (gnus-summary-show-thread) t)
8839                 (gnus-summary-find-subject subject))
8840           (setq count (1+ count))))
8841        (t                               ; Mark as unread.
8842         (while (and
8843                 (progn
8844                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8845                   (gnus-summary-show-thread) t)
8846                 (gnus-summary-find-subject subject))
8847           (setq count (1+ count)))))
8848       (gnus-set-mode-line 'summary)
8849       ;; Return the number of marked articles.
8850       count)))
8851
8852 (defun gnus-summary-mark-as-processable (n &optional unmark)
8853   "Set the process mark on the next N articles.
8854 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8855 the process mark instead.  The difference between N and the actual
8856 number of articles marked is returned."
8857   (interactive "P")
8858   (if (and (null n) (gnus-region-active-p))
8859       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8860     (setq n (prefix-numeric-value n))
8861     (let ((backward (< n 0))
8862           (n (abs n)))
8863       (while (and
8864               (> n 0)
8865               (if unmark
8866                   (gnus-summary-remove-process-mark
8867                    (gnus-summary-article-number))
8868                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8869               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8870         (setq n (1- n)))
8871       (when (/= 0 n)
8872         (gnus-message 7 "No more articles"))
8873       (gnus-summary-recenter)
8874       (gnus-summary-position-point)
8875       n)))
8876
8877 (defun gnus-summary-unmark-as-processable (n)
8878   "Remove the process mark from the next N articles.
8879 If N is negative, unmark backward instead.  The difference between N and
8880 the actual number of articles unmarked is returned."
8881   (interactive "P")
8882   (gnus-summary-mark-as-processable n t))
8883
8884 (defun gnus-summary-unmark-all-processable ()
8885   "Remove the process mark from all articles."
8886   (interactive)
8887   (save-excursion
8888     (while gnus-newsgroup-processable
8889       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8890   (gnus-summary-position-point))
8891
8892 (defun gnus-summary-add-mark (article type)
8893   "Mark ARTICLE with a mark of TYPE."
8894   (let ((vtype (car (assq type gnus-article-mark-lists)))
8895         var)
8896     (if (not vtype)
8897         (error "No such mark type: %s" type)
8898       (setq var (intern (format "gnus-newsgroup-%s" type)))
8899       (set var (cons article (symbol-value var)))
8900       (if (memq type '(processable cached replied forwarded recent saved))
8901           (gnus-summary-update-secondary-mark article)
8902         ;;; !!! This is bogus.  We should find out what primary
8903         ;;; !!! mark we want to set.
8904         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8905
8906 (defun gnus-summary-mark-as-expirable (n)
8907   "Mark N articles forward as expirable.
8908 If N is negative, mark backward instead.  The difference between N and
8909 the actual number of articles marked is returned."
8910   (interactive "p")
8911   (gnus-summary-mark-forward n gnus-expirable-mark))
8912
8913 (defun gnus-summary-mark-article-as-replied (article)
8914   "Mark ARTICLE as replied to and update the summary line.
8915 ARTICLE can also be a list of articles."
8916   (interactive (list (gnus-summary-article-number)))
8917   (let ((articles (if (listp article) article (list article))))
8918     (dolist (article articles)
8919       (push article gnus-newsgroup-replied)
8920       (let ((buffer-read-only nil))
8921         (when (gnus-summary-goto-subject article nil t)
8922           (gnus-summary-update-secondary-mark article))))))
8923
8924 (defun gnus-summary-mark-article-as-forwarded (article)
8925   "Mark ARTICLE as forwarded and update the summary line.
8926 ARTICLE can also be a list of articles."
8927   (let ((articles (if (listp article) article (list article))))
8928     (dolist (article articles)
8929       (push article gnus-newsgroup-forwarded)
8930       (let ((buffer-read-only nil))
8931         (when (gnus-summary-goto-subject article nil t)
8932           (gnus-summary-update-secondary-mark article))))))
8933
8934 (defun gnus-summary-set-bookmark (article)
8935   "Set a bookmark in current article."
8936   (interactive (list (gnus-summary-article-number)))
8937   (when (or (not (get-buffer gnus-article-buffer))
8938             (not gnus-current-article)
8939             (not gnus-article-current)
8940             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8941     (error "No current article selected"))
8942   ;; Remove old bookmark, if one exists.
8943   (let ((old (assq article gnus-newsgroup-bookmarks)))
8944     (when old
8945       (setq gnus-newsgroup-bookmarks
8946             (delq old gnus-newsgroup-bookmarks))))
8947   ;; Set the new bookmark, which is on the form
8948   ;; (article-number . line-number-in-body).
8949   (push
8950    (cons article
8951          (save-excursion
8952            (set-buffer gnus-article-buffer)
8953            (count-lines
8954             (min (point)
8955                  (save-excursion
8956                    (goto-char (point-min))
8957                    (search-forward "\n\n" nil t)
8958                    (point)))
8959             (point))))
8960    gnus-newsgroup-bookmarks)
8961   (gnus-message 6 "A bookmark has been added to the current article."))
8962
8963 (defun gnus-summary-remove-bookmark (article)
8964   "Remove the bookmark from the current article."
8965   (interactive (list (gnus-summary-article-number)))
8966   ;; Remove old bookmark, if one exists.
8967   (let ((old (assq article gnus-newsgroup-bookmarks)))
8968     (if old
8969         (progn
8970           (setq gnus-newsgroup-bookmarks
8971                 (delq old gnus-newsgroup-bookmarks))
8972           (gnus-message 6 "Removed bookmark."))
8973       (gnus-message 6 "No bookmark in current article."))))
8974
8975 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8976 (defun gnus-summary-mark-as-dormant (n)
8977   "Mark N articles forward as dormant.
8978 If N is negative, mark backward instead.  The difference between N and
8979 the actual number of articles marked is returned."
8980   (interactive "p")
8981   (gnus-summary-mark-forward n gnus-dormant-mark))
8982
8983 (defun gnus-summary-set-process-mark (article)
8984   "Set the process mark on ARTICLE and update the summary line."
8985   (setq gnus-newsgroup-processable
8986         (cons article
8987               (delq article gnus-newsgroup-processable)))
8988   (when (gnus-summary-goto-subject article)
8989     (gnus-summary-show-thread)
8990     (gnus-summary-goto-subject article)
8991     (gnus-summary-update-secondary-mark article)))
8992
8993 (defun gnus-summary-remove-process-mark (article)
8994   "Remove the process mark from ARTICLE and update the summary line."
8995   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8996   (when (gnus-summary-goto-subject article)
8997     (gnus-summary-show-thread)
8998     (gnus-summary-goto-subject article)
8999     (gnus-summary-update-secondary-mark article)))
9000
9001 (defun gnus-summary-set-saved-mark (article)
9002   "Set the process mark on ARTICLE and update the summary line."
9003   (push article gnus-newsgroup-saved)
9004   (when (gnus-summary-goto-subject article)
9005     (gnus-summary-update-secondary-mark article)))
9006
9007 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9008   "Mark N articles as read forwards.
9009 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9010 The difference between N and the actual number of articles marked is
9011 returned.
9012 Iff NO-EXPIRE, auto-expiry will be inhibited."
9013   (interactive "p")
9014   (gnus-summary-show-thread)
9015   (let ((backward (< n 0))
9016         (gnus-summary-goto-unread
9017          (and gnus-summary-goto-unread
9018               (not (eq gnus-summary-goto-unread 'never))
9019               (not (memq mark (list gnus-unread-mark
9020                                     gnus-ticked-mark gnus-dormant-mark)))))
9021         (n (abs n))
9022         (mark (or mark gnus-del-mark)))
9023     (while (and (> n 0)
9024                 (gnus-summary-mark-article nil mark no-expire)
9025                 (zerop (gnus-summary-next-subject
9026                         (if backward -1 1)
9027                         (and gnus-summary-goto-unread
9028                              (not (eq gnus-summary-goto-unread 'never)))
9029                         t)))
9030       (setq n (1- n)))
9031     (when (/= 0 n)
9032       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9033     (gnus-summary-recenter)
9034     (gnus-summary-position-point)
9035     (gnus-set-mode-line 'summary)
9036     n))
9037
9038 (defun gnus-summary-mark-article-as-read (mark)
9039   "Mark the current article quickly as read with MARK."
9040   (let ((article (gnus-summary-article-number)))
9041     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9042     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9043     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9044     (push (cons article mark) gnus-newsgroup-reads)
9045     ;; Possibly remove from cache, if that is used.
9046     (when gnus-use-cache
9047       (gnus-cache-enter-remove-article article))
9048     ;; Allow the backend to change the mark.
9049     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9050     ;; Check for auto-expiry.
9051     (when (and gnus-newsgroup-auto-expire
9052                (memq mark gnus-auto-expirable-marks))
9053       (setq mark gnus-expirable-mark)
9054       ;; Let the backend know about the mark change.
9055       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9056       (push article gnus-newsgroup-expirable))
9057     ;; Set the mark in the buffer.
9058     (gnus-summary-update-mark mark 'unread)
9059     t))
9060
9061 (defun gnus-summary-mark-article-as-unread (mark)
9062   "Mark the current article quickly as unread with MARK."
9063   (let* ((article (gnus-summary-article-number))
9064          (old-mark (gnus-summary-article-mark article)))
9065     ;; Allow the backend to change the mark.
9066     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9067     (if (eq mark old-mark)
9068         t
9069       (if (<= article 0)
9070           (progn
9071             (gnus-error 1 "Can't mark negative article numbers")
9072             nil)
9073         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9074         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9075         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9076         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9077         (cond ((= mark gnus-ticked-mark)
9078                (push article gnus-newsgroup-marked))
9079               ((= mark gnus-dormant-mark)
9080                (push article gnus-newsgroup-dormant))
9081               (t
9082                (push article gnus-newsgroup-unreads)))
9083         (gnus-pull article gnus-newsgroup-reads)
9084
9085         ;; See whether the article is to be put in the cache.
9086         (and gnus-use-cache
9087              (vectorp (gnus-summary-article-header article))
9088              (save-excursion
9089                (gnus-cache-possibly-enter-article
9090                 gnus-newsgroup-name article
9091                 (= mark gnus-ticked-mark)
9092                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9093
9094         ;; Fix the mark.
9095         (gnus-summary-update-mark mark 'unread)
9096         t))))
9097
9098 (defun gnus-summary-mark-article (&optional article mark no-expire)
9099   "Mark ARTICLE with MARK.  MARK can be any character.
9100 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9101 `??' (dormant) and `?E' (expirable).
9102 If MARK is nil, then the default character `?r' is used.
9103 If ARTICLE is nil, then the article on the current line will be
9104 marked.
9105 Iff NO-EXPIRE, auto-expiry will be inhibited."
9106   ;; The mark might be a string.
9107   (when (stringp mark)
9108     (setq mark (aref mark 0)))
9109   ;; If no mark is given, then we check auto-expiring.
9110   (when (null mark)
9111     (setq mark gnus-del-mark))
9112   (when (and (not no-expire)
9113              gnus-newsgroup-auto-expire
9114              (memq mark gnus-auto-expirable-marks))
9115     (setq mark gnus-expirable-mark))
9116   (let ((article (or article (gnus-summary-article-number)))
9117         (old-mark (gnus-summary-article-mark article)))
9118     ;; Allow the backend to change the mark.
9119     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9120     (if (eq mark old-mark)
9121         t
9122       (unless article
9123         (error "No article on current line"))
9124       (if (not (if (or (= mark gnus-unread-mark)
9125                        (= mark gnus-ticked-mark)
9126                        (= mark gnus-dormant-mark))
9127                    (gnus-mark-article-as-unread article mark)
9128                  (gnus-mark-article-as-read article mark)))
9129           t
9130         ;; See whether the article is to be put in the cache.
9131         (and gnus-use-cache
9132              (not (= mark gnus-canceled-mark))
9133              (vectorp (gnus-summary-article-header article))
9134              (save-excursion
9135                (gnus-cache-possibly-enter-article
9136                 gnus-newsgroup-name article
9137                 (= mark gnus-ticked-mark)
9138                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9139
9140         (when (gnus-summary-goto-subject article nil t)
9141           (let ((buffer-read-only nil))
9142             (gnus-summary-show-thread)
9143             ;; Fix the mark.
9144             (gnus-summary-update-mark mark 'unread)
9145             t))))))
9146
9147 (defun gnus-summary-update-secondary-mark (article)
9148   "Update the secondary (read, process, cache) mark."
9149   (gnus-summary-update-mark
9150    (cond ((memq article gnus-newsgroup-processable)
9151           gnus-process-mark)
9152          ((memq article gnus-newsgroup-cached)
9153           gnus-cached-mark)
9154          ((memq article gnus-newsgroup-replied)
9155           gnus-replied-mark)
9156          ((memq article gnus-newsgroup-forwarded)
9157           gnus-forwarded-mark)
9158          ((memq article gnus-newsgroup-saved)
9159           gnus-saved-mark)
9160          ((memq article gnus-newsgroup-recent)
9161           gnus-recent-mark)
9162          ((memq article gnus-newsgroup-unseen)
9163           gnus-unseen-mark)
9164          (t gnus-no-mark))
9165    'replied)
9166   (when (gnus-visual-p 'summary-highlight 'highlight)
9167     (gnus-run-hooks 'gnus-summary-update-hook))
9168   t)
9169
9170 (defun gnus-summary-update-mark (mark type)
9171   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9172         (buffer-read-only nil))
9173     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9174     (when forward
9175       (when (looking-at "\r")
9176         (incf forward))
9177       (when (<= (+ forward (point)) (point-max))
9178         ;; Go to the right position on the line.
9179         (goto-char (+ forward (point)))
9180         ;; Replace the old mark with the new mark.
9181         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9182         ;; Optionally update the marks by some user rule.
9183         (when (eq type 'unread)
9184           (gnus-data-set-mark
9185            (gnus-data-find (gnus-summary-article-number)) mark)
9186           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9187
9188 (defun gnus-mark-article-as-read (article &optional mark)
9189   "Enter ARTICLE in the pertinent lists and remove it from others."
9190   ;; Make the article expirable.
9191   (let ((mark (or mark gnus-del-mark)))
9192     (if (= mark gnus-expirable-mark)
9193         (push article gnus-newsgroup-expirable)
9194       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9195     ;; Remove from unread and marked lists.
9196     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9197     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9198     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9199     (push (cons article mark) gnus-newsgroup-reads)
9200     ;; Possibly remove from cache, if that is used.
9201     (when gnus-use-cache
9202       (gnus-cache-enter-remove-article article))
9203     t))
9204
9205 (defun gnus-mark-article-as-unread (article &optional mark)
9206   "Enter ARTICLE in the pertinent lists and remove it from others."
9207   (let ((mark (or mark gnus-ticked-mark)))
9208     (if (<= article 0)
9209         (progn
9210           (gnus-error 1 "Can't mark negative article numbers")
9211           nil)
9212       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9213             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9214             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9215             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9216
9217       ;; Unsuppress duplicates?
9218       (when gnus-suppress-duplicates
9219         (gnus-dup-unsuppress-article article))
9220
9221       (cond ((= mark gnus-ticked-mark)
9222              (push article gnus-newsgroup-marked))
9223             ((= mark gnus-dormant-mark)
9224              (push article gnus-newsgroup-dormant))
9225             (t
9226              (push article gnus-newsgroup-unreads)))
9227       (gnus-pull article gnus-newsgroup-reads)
9228       t)))
9229
9230 (defalias 'gnus-summary-mark-as-unread-forward
9231   'gnus-summary-tick-article-forward)
9232 (make-obsolete 'gnus-summary-mark-as-unread-forward
9233                'gnus-summary-tick-article-forward)
9234 (defun gnus-summary-tick-article-forward (n)
9235   "Tick N articles forwards.
9236 If N is negative, tick backwards instead.
9237 The difference between N and the number of articles ticked is returned."
9238   (interactive "p")
9239   (gnus-summary-mark-forward n gnus-ticked-mark))
9240
9241 (defalias 'gnus-summary-mark-as-unread-backward
9242   'gnus-summary-tick-article-backward)
9243 (make-obsolete 'gnus-summary-mark-as-unread-backward
9244                'gnus-summary-tick-article-backward)
9245 (defun gnus-summary-tick-article-backward (n)
9246   "Tick N articles backwards.
9247 The difference between N and the number of articles ticked is returned."
9248   (interactive "p")
9249   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9250
9251 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9252 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9253 (defun gnus-summary-tick-article (&optional article clear-mark)
9254   "Mark current article as unread.
9255 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9256 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9257   (interactive)
9258   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9259                                        gnus-ticked-mark)))
9260
9261 (defun gnus-summary-mark-as-read-forward (n)
9262   "Mark N articles as read forwards.
9263 If N is negative, mark backwards instead.
9264 The difference between N and the actual number of articles marked is
9265 returned."
9266   (interactive "p")
9267   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9268
9269 (defun gnus-summary-mark-as-read-backward (n)
9270   "Mark the N articles as read backwards.
9271 The difference between N and the actual number of articles marked is
9272 returned."
9273   (interactive "p")
9274   (gnus-summary-mark-forward
9275    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9276
9277 (defun gnus-summary-mark-as-read (&optional article mark)
9278   "Mark current article as read.
9279 ARTICLE specifies the article to be marked as read.
9280 MARK specifies a string to be inserted at the beginning of the line."
9281   (gnus-summary-mark-article article mark))
9282
9283 (defun gnus-summary-clear-mark-forward (n)
9284   "Clear marks from N articles forward.
9285 If N is negative, clear backward instead.
9286 The difference between N and the number of marks cleared is returned."
9287   (interactive "p")
9288   (gnus-summary-mark-forward n gnus-unread-mark))
9289
9290 (defun gnus-summary-clear-mark-backward (n)
9291   "Clear marks from N articles backward.
9292 The difference between N and the number of marks cleared is returned."
9293   (interactive "p")
9294   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9295
9296 (defun gnus-summary-mark-unread-as-read ()
9297   "Intended to be used by `gnus-summary-mark-article-hook'."
9298   (when (memq gnus-current-article gnus-newsgroup-unreads)
9299     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9300
9301 (defun gnus-summary-mark-read-and-unread-as-read ()
9302   "Intended to be used by `gnus-summary-mark-article-hook'."
9303   (let ((mark (gnus-summary-article-mark)))
9304     (when (or (gnus-unread-mark-p mark)
9305               (gnus-read-mark-p mark))
9306       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9307
9308 (defun gnus-summary-mark-unread-as-ticked ()
9309   "Intended to be used by `gnus-summary-mark-article-hook'."
9310   (when (memq gnus-current-article gnus-newsgroup-unreads)
9311     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9312
9313 (defun gnus-summary-mark-region-as-read (point mark all)
9314   "Mark all unread articles between point and mark as read.
9315 If given a prefix, mark all articles between point and mark as read,
9316 even ticked and dormant ones."
9317   (interactive "r\nP")
9318   (save-excursion
9319     (let (article)
9320       (goto-char point)
9321       (beginning-of-line)
9322       (while (and
9323               (< (point) mark)
9324               (progn
9325                 (when (or all
9326                           (memq (setq article (gnus-summary-article-number))
9327                                 gnus-newsgroup-unreads))
9328                   (gnus-summary-mark-article article gnus-del-mark))
9329                 t)
9330               (gnus-summary-find-next))))))
9331
9332 (defun gnus-summary-mark-below (score mark)
9333   "Mark articles with score less than SCORE with MARK."
9334   (interactive "P\ncMark: ")
9335   (setq score (if score
9336                   (prefix-numeric-value score)
9337                 (or gnus-summary-default-score 0)))
9338   (save-excursion
9339     (set-buffer gnus-summary-buffer)
9340     (goto-char (point-min))
9341     (while
9342         (progn
9343           (and (< (gnus-summary-article-score) score)
9344                (gnus-summary-mark-article nil mark))
9345           (gnus-summary-find-next)))))
9346
9347 (defun gnus-summary-kill-below (&optional score)
9348   "Mark articles with score below SCORE as read."
9349   (interactive "P")
9350   (gnus-summary-mark-below score gnus-killed-mark))
9351
9352 (defun gnus-summary-clear-above (&optional score)
9353   "Clear all marks from articles with score above SCORE."
9354   (interactive "P")
9355   (gnus-summary-mark-above score gnus-unread-mark))
9356
9357 (defun gnus-summary-tick-above (&optional score)
9358   "Tick all articles with score above SCORE."
9359   (interactive "P")
9360   (gnus-summary-mark-above score gnus-ticked-mark))
9361
9362 (defun gnus-summary-mark-above (score mark)
9363   "Mark articles with score over SCORE with MARK."
9364   (interactive "P\ncMark: ")
9365   (setq score (if score
9366                   (prefix-numeric-value score)
9367                 (or gnus-summary-default-score 0)))
9368   (save-excursion
9369     (set-buffer gnus-summary-buffer)
9370     (goto-char (point-min))
9371     (while (and (progn
9372                   (when (> (gnus-summary-article-score) score)
9373                     (gnus-summary-mark-article nil mark))
9374                   t)
9375                 (gnus-summary-find-next)))))
9376
9377 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9378 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9379 (defun gnus-summary-limit-include-expunged (&optional no-error)
9380   "Display all the hidden articles that were expunged for low scores."
9381   (interactive)
9382   (let ((buffer-read-only nil))
9383     (let ((scored gnus-newsgroup-scored)
9384           headers h)
9385       (while scored
9386         (unless (gnus-summary-article-header (caar scored))
9387           (and (setq h (gnus-number-to-header (caar scored)))
9388                (< (cdar scored) gnus-summary-expunge-below)
9389                (push h headers)))
9390         (setq scored (cdr scored)))
9391       (if (not headers)
9392           (when (not no-error)
9393             (error "No expunged articles hidden"))
9394         (goto-char (point-min))
9395         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9396         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9397         (mapcar (lambda (x) (push (mail-header-number x)
9398                                   gnus-newsgroup-limit))
9399                 headers)
9400         (gnus-summary-prepare-unthreaded (nreverse headers))
9401         (goto-char (point-min))
9402         (gnus-summary-position-point)
9403         t))))
9404
9405 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9406   "Mark all unread articles in this newsgroup as read.
9407 If prefix argument ALL is non-nil, ticked and dormant articles will
9408 also be marked as read.
9409 If QUIETLY is non-nil, no questions will be asked.
9410 If TO-HERE is non-nil, it should be a point in the buffer.  All
9411 articles before (after, if REVERSE is set) this point will be marked as read.
9412 Note that this function will only catch up the unread article
9413 in the current summary buffer limitation.
9414 The number of articles marked as read is returned."
9415   (interactive "P")
9416   (prog1
9417       (save-excursion
9418         (when (or quietly
9419                   (not gnus-interactive-catchup) ;Without confirmation?
9420                   gnus-expert-user
9421                   (gnus-y-or-n-p
9422                    (if all
9423                        "Mark absolutely all articles as read? "
9424                      "Mark all unread articles as read? ")))
9425           (if (and not-mark
9426                    (not gnus-newsgroup-adaptive)
9427                    (not gnus-newsgroup-auto-expire)
9428                    (not gnus-suppress-duplicates)
9429                    (or (not gnus-use-cache)
9430                        (eq gnus-use-cache 'passive)))
9431               (progn
9432                 (when all
9433                   (setq gnus-newsgroup-marked nil
9434                         gnus-newsgroup-dormant nil))
9435                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9436             ;; We actually mark all articles as canceled, which we
9437             ;; have to do when using auto-expiry or adaptive scoring.
9438             (gnus-summary-show-all-threads)
9439             (if (and to-here reverse)
9440                 (progn
9441                   (goto-char to-here)
9442                   (while (and
9443                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9444                           (gnus-summary-find-next (not all) nil nil t))))
9445               (when (gnus-summary-first-subject (not all) t)
9446                 (while (and
9447                         (if to-here (< (point) to-here) t)
9448                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9449                         (gnus-summary-find-next (not all) nil nil t)))))
9450             (gnus-set-mode-line 'summary))
9451           t))
9452     (gnus-summary-position-point)))
9453
9454 (defun gnus-summary-catchup-to-here (&optional all)
9455   "Mark all unticked articles before the current one as read.
9456 If ALL is non-nil, also mark ticked and dormant articles as read."
9457   (interactive "P")
9458   (save-excursion
9459     (gnus-save-hidden-threads
9460       (let ((beg (point)))
9461         ;; We check that there are unread articles.
9462         (when (or all (gnus-summary-find-prev))
9463           (gnus-summary-catchup all t beg)))))
9464   (gnus-summary-position-point))
9465
9466 (defun gnus-summary-catchup-from-here (&optional all)
9467   "Mark all unticked articles after the current one as read.
9468 If ALL is non-nil, also mark ticked and dormant articles as read."
9469   (interactive "P")
9470   (save-excursion
9471     (gnus-save-hidden-threads
9472       (let ((beg (point)))
9473         ;; We check that there are unread articles.
9474         (when (or all (gnus-summary-find-next))
9475           (gnus-summary-catchup all t beg nil t)))))
9476
9477   (gnus-summary-position-point))
9478 (defun gnus-summary-catchup-all (&optional quietly)
9479   "Mark all articles in this newsgroup as read."
9480   (interactive "P")
9481   (gnus-summary-catchup t quietly))
9482
9483 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9484   "Mark all unread articles in this group as read, then exit.
9485 If prefix argument ALL is non-nil, all articles are marked as read.
9486 If QUIETLY is non-nil, no questions will be asked."
9487   (interactive "P")
9488   (when (gnus-summary-catchup all quietly nil 'fast)
9489     ;; Select next newsgroup or exit.
9490     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9491              (eq gnus-auto-select-next 'quietly))
9492         (gnus-summary-next-group nil)
9493       (gnus-summary-exit))))
9494
9495 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9496   "Mark all articles in this newsgroup as read, and then exit."
9497   (interactive "P")
9498   (gnus-summary-catchup-and-exit t quietly))
9499
9500 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9501   "Mark all articles in this group as read and select the next group.
9502 If given a prefix, mark all articles, unread as well as ticked, as
9503 read."
9504   (interactive "P")
9505   (save-excursion
9506     (gnus-summary-catchup all))
9507   (gnus-summary-next-group))
9508
9509 ;;;
9510 ;;; with article
9511 ;;;
9512
9513 (defmacro gnus-with-article (article &rest forms)
9514   "Select ARTICLE and perform FORMS in the original article buffer.
9515 Then replace the article with the result."
9516   `(progn
9517      ;; We don't want the article to be marked as read.
9518      (let (gnus-mark-article-hook)
9519        (gnus-summary-select-article t t nil ,article))
9520      (set-buffer gnus-original-article-buffer)
9521      ,@forms
9522      (if (not (gnus-check-backend-function
9523                'request-replace-article (car gnus-article-current)))
9524          (gnus-message 5 "Read-only group; not replacing")
9525        (unless (gnus-request-replace-article
9526                 ,article (car gnus-article-current)
9527                 (current-buffer) t)
9528          (error "Couldn't replace article")))
9529      ;; The cache and backlog have to be flushed somewhat.
9530      (when gnus-keep-backlog
9531        (gnus-backlog-remove-article
9532         (car gnus-article-current) (cdr gnus-article-current)))
9533      (when gnus-use-cache
9534        (gnus-cache-update-article
9535         (car gnus-article-current) (cdr gnus-article-current)))))
9536
9537 (put 'gnus-with-article 'lisp-indent-function 1)
9538 (put 'gnus-with-article 'edebug-form-spec '(form body))
9539
9540 ;; Thread-based commands.
9541
9542 (defun gnus-summary-articles-in-thread (&optional article)
9543   "Return a list of all articles in the current thread.
9544 If ARTICLE is non-nil, return all articles in the thread that starts
9545 with that article."
9546   (let* ((article (or article (gnus-summary-article-number)))
9547          (data (gnus-data-find-list article))
9548          (top-level (gnus-data-level (car data)))
9549          (top-subject
9550           (cond ((null gnus-thread-operation-ignore-subject)
9551                  (gnus-simplify-subject-re
9552                   (mail-header-subject (gnus-data-header (car data)))))
9553                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9554                  (gnus-simplify-subject-fuzzy
9555                   (mail-header-subject (gnus-data-header (car data)))))
9556                 (t nil)))
9557          (end-point (save-excursion
9558                       (if (gnus-summary-go-to-next-thread)
9559                           (point) (point-max))))
9560          articles)
9561     (while (and data
9562                 (< (gnus-data-pos (car data)) end-point))
9563       (when (or (not top-subject)
9564                 (string= top-subject
9565                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9566                              (gnus-simplify-subject-fuzzy
9567                               (mail-header-subject
9568                                (gnus-data-header (car data))))
9569                            (gnus-simplify-subject-re
9570                             (mail-header-subject
9571                              (gnus-data-header (car data)))))))
9572         (push (gnus-data-number (car data)) articles))
9573       (unless (and (setq data (cdr data))
9574                    (> (gnus-data-level (car data)) top-level))
9575         (setq data nil)))
9576     ;; Return the list of articles.
9577     (nreverse articles)))
9578
9579 (defun gnus-summary-rethread-current ()
9580   "Rethread the thread the current article is part of."
9581   (interactive)
9582   (let* ((gnus-show-threads t)
9583          (article (gnus-summary-article-number))
9584          (id (mail-header-id (gnus-summary-article-header)))
9585          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9586     (unless id
9587       (error "No article on the current line"))
9588     (gnus-rebuild-thread id)
9589     (gnus-summary-goto-subject article)))
9590
9591 (defun gnus-summary-reparent-thread ()
9592   "Make the current article child of the marked (or previous) article.
9593
9594 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9595 is non-nil or the Subject: of both articles are the same."
9596   (interactive)
9597   (unless (not (gnus-group-read-only-p))
9598     (error "The current newsgroup does not support article editing"))
9599   (unless (<= (length gnus-newsgroup-processable) 1)
9600     (error "No more than one article may be marked"))
9601   (save-window-excursion
9602     (let ((gnus-article-buffer " *reparent*")
9603           (current-article (gnus-summary-article-number))
9604           ;; First grab the marked article, otherwise one line up.
9605           (parent-article (if (not (null gnus-newsgroup-processable))
9606                               (car gnus-newsgroup-processable)
9607                             (save-excursion
9608                               (if (eq (forward-line -1) 0)
9609                                   (gnus-summary-article-number)
9610                                 (error "Beginning of summary buffer"))))))
9611       (unless (not (eq current-article parent-article))
9612         (error "An article may not be self-referential"))
9613       (let ((message-id (mail-header-id
9614                          (gnus-summary-article-header parent-article))))
9615         (unless (and message-id (not (equal message-id "")))
9616           (error "No message-id in desired parent"))
9617         (gnus-with-article current-article
9618           (save-restriction
9619             (goto-char (point-min))
9620             (message-narrow-to-head)
9621             (if (re-search-forward "^References: " nil t)
9622                 (progn
9623                   (re-search-forward "^[^ \t]" nil t)
9624                   (forward-line -1)
9625                   (end-of-line)
9626                   (insert " " message-id))
9627               (insert "References: " message-id "\n"))))
9628         (set-buffer gnus-summary-buffer)
9629         (gnus-summary-unmark-all-processable)
9630         (gnus-summary-update-article current-article)
9631         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9632             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9633         (gnus-summary-rethread-current)
9634         (gnus-message 3 "Article %d is now the child of article %d"
9635                       current-article parent-article)))))
9636
9637 (defun gnus-summary-toggle-threads (&optional arg)
9638   "Toggle showing conversation threads.
9639 If ARG is positive number, turn showing conversation threads on."
9640   (interactive "P")
9641   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9642     (setq gnus-show-threads
9643           (if (null arg) (not gnus-show-threads)
9644             (> (prefix-numeric-value arg) 0)))
9645     (gnus-summary-prepare)
9646     (gnus-summary-goto-subject current)
9647     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9648     (gnus-summary-position-point)))
9649
9650 (defun gnus-summary-show-all-threads ()
9651   "Show all threads."
9652   (interactive)
9653   (save-excursion
9654     (let ((buffer-read-only nil))
9655       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9656   (gnus-summary-position-point))
9657
9658 (defun gnus-summary-show-thread ()
9659   "Show thread subtrees.
9660 Returns nil if no thread was there to be shown."
9661   (interactive)
9662   (let ((buffer-read-only nil)
9663         (orig (point))
9664         ;; first goto end then to beg, to have point at beg after let
9665         (end (progn (end-of-line) (point)))
9666         (beg (progn (beginning-of-line) (point))))
9667     (prog1
9668         ;; Any hidden lines here?
9669         (search-forward "\r" end t)
9670       (subst-char-in-region beg end ?\^M ?\n t)
9671       (goto-char orig)
9672       (gnus-summary-position-point))))
9673
9674 (defun gnus-summary-hide-all-threads ()
9675   "Hide all thread subtrees."
9676   (interactive)
9677   (save-excursion
9678     (goto-char (point-min))
9679     (gnus-summary-hide-thread)
9680     (while (zerop (gnus-summary-next-thread 1 t))
9681       (gnus-summary-hide-thread)))
9682   (gnus-summary-position-point))
9683
9684 (defun gnus-summary-hide-thread ()
9685   "Hide thread subtrees.
9686 Returns nil if no threads were there to be hidden."
9687   (interactive)
9688   (let ((buffer-read-only nil)
9689         (start (point))
9690         (article (gnus-summary-article-number)))
9691     (goto-char start)
9692     ;; Go forward until either the buffer ends or the subthread
9693     ;; ends.
9694     (when (and (not (eobp))
9695                (or (zerop (gnus-summary-next-thread 1 t))
9696                    (goto-char (point-max))))
9697       (prog1
9698           (if (and (> (point) start)
9699                    (search-backward "\n" start t))
9700               (progn
9701                 (subst-char-in-region start (point) ?\n ?\^M)
9702                 (gnus-summary-goto-subject article))
9703             (goto-char start)
9704             nil)))))
9705
9706 (defun gnus-summary-go-to-next-thread (&optional previous)
9707   "Go to the same level (or less) next thread.
9708 If PREVIOUS is non-nil, go to previous thread instead.
9709 Return the article number moved to, or nil if moving was impossible."
9710   (let ((level (gnus-summary-thread-level))
9711         (way (if previous -1 1))
9712         (beg (point)))
9713     (forward-line way)
9714     (while (and (not (eobp))
9715                 (< level (gnus-summary-thread-level)))
9716       (forward-line way))
9717     (if (eobp)
9718         (progn
9719           (goto-char beg)
9720           nil)
9721       (setq beg (point))
9722       (prog1
9723           (gnus-summary-article-number)
9724         (goto-char beg)))))
9725
9726 (defun gnus-summary-next-thread (n &optional silent)
9727   "Go to the same level next N'th thread.
9728 If N is negative, search backward instead.
9729 Returns the difference between N and the number of skips actually
9730 done.
9731
9732 If SILENT, don't output messages."
9733   (interactive "p")
9734   (let ((backward (< n 0))
9735         (n (abs n)))
9736     (while (and (> n 0)
9737                 (gnus-summary-go-to-next-thread backward))
9738       (decf n))
9739     (unless silent
9740       (gnus-summary-position-point))
9741     (when (and (not silent) (/= 0 n))
9742       (gnus-message 7 "No more threads"))
9743     n))
9744
9745 (defun gnus-summary-prev-thread (n)
9746   "Go to the same level previous N'th thread.
9747 Returns the difference between N and the number of skips actually
9748 done."
9749   (interactive "p")
9750   (gnus-summary-next-thread (- n)))
9751
9752 (defun gnus-summary-go-down-thread ()
9753   "Go down one level in the current thread."
9754   (let ((children (gnus-summary-article-children)))
9755     (when children
9756       (gnus-summary-goto-subject (car children)))))
9757
9758 (defun gnus-summary-go-up-thread ()
9759   "Go up one level in the current thread."
9760   (let ((parent (gnus-summary-article-parent)))
9761     (when parent
9762       (gnus-summary-goto-subject parent))))
9763
9764 (defun gnus-summary-down-thread (n)
9765   "Go down thread N steps.
9766 If N is negative, go up instead.
9767 Returns the difference between N and how many steps down that were
9768 taken."
9769   (interactive "p")
9770   (let ((up (< n 0))
9771         (n (abs n)))
9772     (while (and (> n 0)
9773                 (if up (gnus-summary-go-up-thread)
9774                   (gnus-summary-go-down-thread)))
9775       (setq n (1- n)))
9776     (gnus-summary-position-point)
9777     (when (/= 0 n)
9778       (gnus-message 7 "Can't go further"))
9779     n))
9780
9781 (defun gnus-summary-up-thread (n)
9782   "Go up thread N steps.
9783 If N is negative, go down instead.
9784 Returns the difference between N and how many steps down that were
9785 taken."
9786   (interactive "p")
9787   (gnus-summary-down-thread (- n)))
9788
9789 (defun gnus-summary-top-thread ()
9790   "Go to the top of the thread."
9791   (interactive)
9792   (while (gnus-summary-go-up-thread))
9793   (gnus-summary-article-number))
9794
9795 (defun gnus-summary-kill-thread (&optional unmark)
9796   "Mark articles under current thread as read.
9797 If the prefix argument is positive, remove any kinds of marks.
9798 If the prefix argument is negative, tick articles instead."
9799   (interactive "P")
9800   (when unmark
9801     (setq unmark (prefix-numeric-value unmark)))
9802   (let ((articles (gnus-summary-articles-in-thread)))
9803     (save-excursion
9804       ;; Expand the thread.
9805       (gnus-summary-show-thread)
9806       ;; Mark all the articles.
9807       (while articles
9808         (gnus-summary-goto-subject (car articles))
9809         (cond ((null unmark)
9810                (gnus-summary-mark-article-as-read gnus-killed-mark))
9811               ((> unmark 0)
9812                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9813               (t
9814                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9815         (setq articles (cdr articles))))
9816     ;; Hide killed subtrees.
9817     (and (null unmark)
9818          gnus-thread-hide-killed
9819          (gnus-summary-hide-thread))
9820     ;; If marked as read, go to next unread subject.
9821     (when (null unmark)
9822       ;; Go to next unread subject.
9823       (gnus-summary-next-subject 1 t)))
9824   (gnus-set-mode-line 'summary))
9825
9826 ;; Summary sorting commands
9827
9828 (defun gnus-summary-sort-by-number (&optional reverse)
9829   "Sort the summary buffer by article number.
9830 Argument REVERSE means reverse order."
9831   (interactive "P")
9832   (gnus-summary-sort 'number reverse))
9833
9834 (defun gnus-summary-sort-by-author (&optional reverse)
9835   "Sort the summary buffer by author name alphabetically.
9836 If `case-fold-search' is non-nil, case of letters is ignored.
9837 Argument REVERSE means reverse order."
9838   (interactive "P")
9839   (gnus-summary-sort 'author reverse))
9840
9841 (defun gnus-summary-sort-by-subject (&optional reverse)
9842   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9843 If `case-fold-search' is non-nil, case of letters is ignored.
9844 Argument REVERSE means reverse order."
9845   (interactive "P")
9846   (gnus-summary-sort 'subject reverse))
9847
9848 (defun gnus-summary-sort-by-date (&optional reverse)
9849   "Sort the summary buffer by date.
9850 Argument REVERSE means reverse order."
9851   (interactive "P")
9852   (gnus-summary-sort 'date reverse))
9853
9854 (defun gnus-summary-sort-by-score (&optional reverse)
9855   "Sort the summary buffer by score.
9856 Argument REVERSE means reverse order."
9857   (interactive "P")
9858   (gnus-summary-sort 'score reverse))
9859
9860 (defun gnus-summary-sort-by-lines (&optional reverse)
9861   "Sort the summary buffer by the number of lines.
9862 Argument REVERSE means reverse order."
9863   (interactive "P")
9864   (gnus-summary-sort 'lines reverse))
9865
9866 (defun gnus-summary-sort-by-chars (&optional reverse)
9867   "Sort the summary buffer by article length.
9868 Argument REVERSE means reverse order."
9869   (interactive "P")
9870   (gnus-summary-sort 'chars reverse))
9871
9872 (defun gnus-summary-sort-by-original (&optional reverse)
9873   "Sort the summary buffer using the default sorting method.
9874 Argument REVERSE means reverse order."
9875   (interactive "P")
9876   (let* ((buffer-read-only)
9877          (gnus-summary-prepare-hook nil))
9878     ;; We do the sorting by regenerating the threads.
9879     (gnus-summary-prepare)
9880     ;; Hide subthreads if needed.
9881     (when (and gnus-show-threads gnus-thread-hide-subtree)
9882       (gnus-summary-hide-all-threads))))
9883
9884 (defun gnus-summary-sort (predicate reverse)
9885   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9886   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9887          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9888          (gnus-thread-sort-functions
9889           (if (not reverse)
9890               thread
9891             `(lambda (t1 t2)
9892                (,thread t2 t1))))
9893          (gnus-sort-gathered-threads-function
9894           gnus-thread-sort-functions)
9895          (gnus-article-sort-functions
9896           (if (not reverse)
9897               article
9898             `(lambda (t1 t2)
9899                (,article t2 t1))))
9900          (buffer-read-only)
9901          (gnus-summary-prepare-hook nil))
9902     ;; We do the sorting by regenerating the threads.
9903     (gnus-summary-prepare)
9904     ;; Hide subthreads if needed.
9905     (when (and gnus-show-threads gnus-thread-hide-subtree)
9906       (gnus-summary-hide-all-threads))))
9907
9908 ;; Summary saving commands.
9909
9910 (defun gnus-summary-save-article (&optional n not-saved)
9911   "Save the current article using the default saver function.
9912 If N is a positive number, save the N next articles.
9913 If N is a negative number, save the N previous articles.
9914 If N is nil and any articles have been marked with the process mark,
9915 save those articles instead.
9916 The variable `gnus-default-article-saver' specifies the saver function."
9917   (interactive "P")
9918   (let* ((articles (gnus-summary-work-articles n))
9919          (save-buffer (save-excursion
9920                         (nnheader-set-temp-buffer " *Gnus Save*")))
9921          (num (length articles))
9922          header file)
9923     (dolist (article articles)
9924       (setq header (gnus-summary-article-header article))
9925       (if (not (vectorp header))
9926           ;; This is a pseudo-article.
9927           (if (assq 'name header)
9928               (gnus-copy-file (cdr (assq 'name header)))
9929             (gnus-message 1 "Article %d is unsaveable" article))
9930         ;; This is a real article.
9931         (save-window-excursion
9932           (let ((gnus-display-mime-function nil)
9933                 (gnus-article-prepare-hook nil))
9934             (gnus-summary-select-article t nil nil article)))
9935         (save-excursion
9936           (set-buffer save-buffer)
9937           (erase-buffer)
9938           (insert-buffer-substring gnus-original-article-buffer))
9939         (setq file (gnus-article-save save-buffer file num))
9940         (gnus-summary-remove-process-mark article)
9941         (unless not-saved
9942           (gnus-summary-set-saved-mark article))))
9943     (gnus-kill-buffer save-buffer)
9944     (gnus-summary-position-point)
9945     (gnus-set-mode-line 'summary)
9946     n))
9947
9948 (defun gnus-summary-pipe-output (&optional arg)
9949   "Pipe the current article to a subprocess.
9950 If N is a positive number, pipe the N next articles.
9951 If N is a negative number, pipe the N previous articles.
9952 If N is nil and any articles have been marked with the process mark,
9953 pipe those articles instead."
9954   (interactive "P")
9955   (require 'gnus-art)
9956   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9957     (gnus-summary-save-article arg t))
9958   (let ((buffer (get-buffer "*Shell Command Output*")))
9959     (if (and buffer
9960              (with-current-buffer buffer (> (point-max) (point-min))))
9961         (gnus-configure-windows 'pipe))))
9962
9963 (defun gnus-summary-save-article-mail (&optional arg)
9964   "Append the current article to an mail file.
9965 If N is a positive number, save the N next articles.
9966 If N is a negative number, save the N previous articles.
9967 If N is nil and any articles have been marked with the process mark,
9968 save those articles instead."
9969   (interactive "P")
9970   (require 'gnus-art)
9971   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9972     (gnus-summary-save-article arg)))
9973
9974 (defun gnus-summary-save-article-rmail (&optional arg)
9975   "Append the current article to an rmail file.
9976 If N is a positive number, save the N next articles.
9977 If N is a negative number, save the N previous articles.
9978 If N is nil and any articles have been marked with the process mark,
9979 save those articles instead."
9980   (interactive "P")
9981   (require 'gnus-art)
9982   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9983     (gnus-summary-save-article arg)))
9984
9985 (defun gnus-summary-save-article-file (&optional arg)
9986   "Append the current article to a file.
9987 If N is a positive number, save the N next articles.
9988 If N is a negative number, save the N previous articles.
9989 If N is nil and any articles have been marked with the process mark,
9990 save those articles instead."
9991   (interactive "P")
9992   (require 'gnus-art)
9993   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9994     (gnus-summary-save-article arg)))
9995
9996 (defun gnus-summary-write-article-file (&optional arg)
9997   "Write the current article to a file, deleting the previous file.
9998 If N is a positive number, save the N next articles.
9999 If N is a negative number, save the N previous articles.
10000 If N is nil and any articles have been marked with the process mark,
10001 save those articles instead."
10002   (interactive "P")
10003   (require 'gnus-art)
10004   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10005     (gnus-summary-save-article arg)))
10006
10007 (defun gnus-summary-save-article-body-file (&optional arg)
10008   "Append the current article body to a file.
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   (interactive "P")
10014   (require 'gnus-art)
10015   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10016     (gnus-summary-save-article arg)))
10017
10018 (defun gnus-summary-muttprint (&optional arg)
10019   "Print the current article using Muttprint.
10020 If N is a positive number, save the N next articles.
10021 If N is a negative number, save the N previous articles.
10022 If N is nil and any articles have been marked with the process mark,
10023 save those articles instead."
10024   (interactive "P")
10025   (require 'gnus-art)
10026   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10027     (gnus-summary-save-article arg t)))
10028
10029 (defun gnus-summary-pipe-message (program)
10030   "Pipe the current article through PROGRAM."
10031   (interactive "sProgram: ")
10032   (gnus-summary-select-article)
10033   (let ((mail-header-separator ""))
10034     (gnus-eval-in-buffer-window gnus-article-buffer
10035       (save-restriction
10036         (widen)
10037         (let ((start (window-start))
10038               buffer-read-only)
10039           (message-pipe-buffer-body program)
10040           (set-window-start (get-buffer-window (current-buffer)) start))))))
10041
10042 (defun gnus-get-split-value (methods)
10043   "Return a value based on the split METHODS."
10044   (let (split-name method result match)
10045     (when methods
10046       (save-excursion
10047         (set-buffer gnus-original-article-buffer)
10048         (save-restriction
10049           (nnheader-narrow-to-headers)
10050           (while (and methods (not split-name))
10051             (goto-char (point-min))
10052             (setq method (pop methods))
10053             (setq match (car method))
10054             (when (cond
10055                    ((stringp match)
10056                     ;; Regular expression.
10057                     (ignore-errors
10058                       (re-search-forward match nil t)))
10059                    ((gnus-functionp match)
10060                     ;; Function.
10061                     (save-restriction
10062                       (widen)
10063                       (setq result (funcall match gnus-newsgroup-name))))
10064                    ((consp match)
10065                     ;; Form.
10066                     (save-restriction
10067                       (widen)
10068                       (setq result (eval match)))))
10069               (setq split-name (cdr method))
10070               (cond ((stringp result)
10071                      (push (expand-file-name
10072                             result gnus-article-save-directory)
10073                            split-name))
10074                     ((consp result)
10075                      (setq split-name (append result split-name)))))))))
10076     (nreverse split-name)))
10077
10078 (defun gnus-valid-move-group-p (group)
10079   (and (boundp group)
10080        (symbol-name group)
10081        (symbol-value group)
10082        (gnus-get-function (gnus-find-method-for-group
10083                            (symbol-name group)) 'request-accept-article t)))
10084
10085 (defun gnus-read-move-group-name (prompt default articles prefix)
10086   "Read a group name."
10087   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10088          (minibuffer-confirm-incomplete nil) ; XEmacs
10089          (prom
10090           (format "%s %s to:"
10091                   prompt
10092                   (if (> (length articles) 1)
10093                       (format "these %d articles" (length articles))
10094                     "this article")))
10095          (to-newsgroup
10096           (cond
10097            ((null split-name)
10098             (gnus-completing-read default prom
10099                                   gnus-active-hashtb
10100                                   'gnus-valid-move-group-p
10101                                   nil prefix
10102                                   'gnus-group-history))
10103            ((= 1 (length split-name))
10104             (gnus-completing-read (car split-name) prom
10105                                   gnus-active-hashtb
10106                                   'gnus-valid-move-group-p
10107                                   nil nil
10108                                   'gnus-group-history))
10109            (t
10110             (gnus-completing-read nil prom
10111                                   (mapcar (lambda (el) (list el))
10112                                           (nreverse split-name))
10113                                   nil nil nil
10114                                   'gnus-group-history))))
10115          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10116     (when to-newsgroup
10117       (if (or (string= to-newsgroup "")
10118               (string= to-newsgroup prefix))
10119           (setq to-newsgroup default))
10120       (unless to-newsgroup
10121         (error "No group name entered"))
10122       (or (gnus-active to-newsgroup)
10123           (gnus-activate-group to-newsgroup nil nil to-method)
10124           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10125                                      to-newsgroup))
10126               (or (and (gnus-request-create-group to-newsgroup to-method)
10127                        (gnus-activate-group
10128                         to-newsgroup nil nil to-method)
10129                        (gnus-subscribe-group to-newsgroup))
10130                   (error "Couldn't create group %s" to-newsgroup)))
10131           (error "No such group: %s" to-newsgroup)))
10132     to-newsgroup))
10133
10134 (defun gnus-summary-save-parts (type dir n &optional reverse)
10135   "Save parts matching TYPE to DIR.
10136 If REVERSE, save parts that do not match TYPE."
10137   (interactive
10138    (list (read-string "Save parts of type: "
10139                       (or (car gnus-summary-save-parts-type-history)
10140                           gnus-summary-save-parts-default-mime)
10141                       'gnus-summary-save-parts-type-history)
10142          (setq gnus-summary-save-parts-last-directory
10143                (read-file-name "Save to directory: "
10144                                gnus-summary-save-parts-last-directory
10145                                nil t))
10146          current-prefix-arg))
10147   (gnus-summary-iterate n
10148     (let ((gnus-display-mime-function nil)
10149           (gnus-inhibit-treatment t))
10150       (gnus-summary-select-article))
10151     (save-excursion
10152       (set-buffer gnus-article-buffer)
10153       (let ((handles (or gnus-article-mime-handles
10154                          (mm-dissect-buffer) (mm-uu-dissect))))
10155         (when handles
10156           (gnus-summary-save-parts-1 type dir handles reverse)
10157           (unless gnus-article-mime-handles ;; Don't destroy this case.
10158             (mm-destroy-parts handles)))))))
10159
10160 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10161   (if (stringp (car handle))
10162       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10163               (cdr handle))
10164     (when (if reverse
10165               (not (string-match type (mm-handle-media-type handle)))
10166             (string-match type (mm-handle-media-type handle)))
10167       (let ((file (expand-file-name
10168                    (file-name-nondirectory
10169                     (or
10170                      (mail-content-type-get
10171                       (mm-handle-disposition handle) 'filename)
10172                      (concat gnus-newsgroup-name
10173                              "." (number-to-string
10174                                   (cdr gnus-article-current)))))
10175                    dir)))
10176         (unless (file-exists-p file)
10177           (mm-save-part-to-file handle file))))))
10178
10179 ;; Summary extract commands
10180
10181 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10182   (let ((buffer-read-only nil)
10183         (article (gnus-summary-article-number))
10184         after-article b e)
10185     (unless (gnus-summary-goto-subject article)
10186       (error "No such article: %d" article))
10187     (gnus-summary-position-point)
10188     ;; If all commands are to be bunched up on one line, we collect
10189     ;; them here.
10190     (unless gnus-view-pseudos-separately
10191       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10192             files action)
10193         (while ps
10194           (setq action (cdr (assq 'action (car ps))))
10195           (setq files (list (cdr (assq 'name (car ps)))))
10196           (while (and ps (cdr ps)
10197                       (string= (or action "1")
10198                                (or (cdr (assq 'action (cadr ps))) "2")))
10199             (push (cdr (assq 'name (cadr ps))) files)
10200             (setcdr ps (cddr ps)))
10201           (when files
10202             (when (not (string-match "%s" action))
10203               (push " " files))
10204             (push " " files)
10205             (when (assq 'execute (car ps))
10206               (setcdr (assq 'execute (car ps))
10207                       (funcall (if (string-match "%s" action)
10208                                    'format 'concat)
10209                                action
10210                                (mapconcat
10211                                 (lambda (f)
10212                                   (if (equal f " ")
10213                                       f
10214                                     (mm-quote-arg f)))
10215                                 files " ")))))
10216           (setq ps (cdr ps)))))
10217     (if (and gnus-view-pseudos (not not-view))
10218         (while pslist
10219           (when (assq 'execute (car pslist))
10220             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10221                                   (eq gnus-view-pseudos 'not-confirm)))
10222           (setq pslist (cdr pslist)))
10223       (save-excursion
10224         (while pslist
10225           (setq after-article (or (cdr (assq 'article (car pslist)))
10226                                   (gnus-summary-article-number)))
10227           (gnus-summary-goto-subject after-article)
10228           (forward-line 1)
10229           (setq b (point))
10230           (insert "    " (file-name-nondirectory
10231                           (cdr (assq 'name (car pslist))))
10232                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10233           (setq e (point))
10234           (forward-line -1)             ; back to `b'
10235           (gnus-add-text-properties
10236            b (1- e) (list 'gnus-number gnus-reffed-article-number
10237                           gnus-mouse-face-prop gnus-mouse-face))
10238           (gnus-data-enter
10239            after-article gnus-reffed-article-number
10240            gnus-unread-mark b (car pslist) 0 (- e b))
10241           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10242           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10243           (setq pslist (cdr pslist)))))))
10244
10245 (defun gnus-pseudos< (p1 p2)
10246   (let ((c1 (cdr (assq 'action p1)))
10247         (c2 (cdr (assq 'action p2))))
10248     (and c1 c2 (string< c1 c2))))
10249
10250 (defun gnus-request-pseudo-article (props)
10251   (cond ((assq 'execute props)
10252          (gnus-execute-command (cdr (assq 'execute props)))))
10253   (let ((gnus-current-article (gnus-summary-article-number)))
10254     (gnus-run-hooks 'gnus-mark-article-hook)))
10255
10256 (defun gnus-execute-command (command &optional automatic)
10257   (save-excursion
10258     (gnus-article-setup-buffer)
10259     (set-buffer gnus-article-buffer)
10260     (setq buffer-read-only nil)
10261     (let ((command (if automatic command
10262                      (read-string "Command: " (cons command 0)))))
10263       (erase-buffer)
10264       (insert "$ " command "\n\n")
10265       (if gnus-view-pseudo-asynchronously
10266           (start-process "gnus-execute" (current-buffer) shell-file-name
10267                          shell-command-switch command)
10268         (call-process shell-file-name nil t nil
10269                       shell-command-switch command)))))
10270
10271 ;; Summary kill commands.
10272
10273 (defun gnus-summary-edit-global-kill (article)
10274   "Edit the \"global\" kill file."
10275   (interactive (list (gnus-summary-article-number)))
10276   (gnus-group-edit-global-kill article))
10277
10278 (defun gnus-summary-edit-local-kill ()
10279   "Edit a local kill file applied to the current newsgroup."
10280   (interactive)
10281   (setq gnus-current-headers (gnus-summary-article-header))
10282   (gnus-group-edit-local-kill
10283    (gnus-summary-article-number) gnus-newsgroup-name))
10284
10285 ;;; Header reading.
10286
10287 (defun gnus-read-header (id &optional header)
10288   "Read the headers of article ID and enter them into the Gnus system."
10289   (let ((group gnus-newsgroup-name)
10290         (gnus-override-method
10291          (or
10292           gnus-override-method
10293           (and (gnus-news-group-p gnus-newsgroup-name)
10294                (car (gnus-refer-article-methods)))))
10295         where)
10296     ;; First we check to see whether the header in question is already
10297     ;; fetched.
10298     (if (stringp id)
10299         ;; This is a Message-ID.
10300         (setq header (or header (gnus-id-to-header id)))
10301       ;; This is an article number.
10302       (setq header (or header (gnus-summary-article-header id))))
10303     (if (and header
10304              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10305         ;; We have found the header.
10306         header
10307       ;; If this is a sparse article, we have to nix out its
10308       ;; previous entry in the thread hashtb.
10309       (when (and header
10310                  (gnus-summary-article-sparse-p (mail-header-number header)))
10311         (let* ((parent (gnus-parent-id (mail-header-references header)))
10312                (thread (and parent (gnus-id-to-thread parent))))
10313           (when thread
10314             (delq (assq header thread) thread))))
10315       ;; We have to really fetch the header to this article.
10316       (save-excursion
10317         (set-buffer nntp-server-buffer)
10318         (when (setq where (gnus-request-head id group))
10319           (nnheader-fold-continuation-lines)
10320           (goto-char (point-max))
10321           (insert ".\n")
10322           (goto-char (point-min))
10323           (insert "211 ")
10324           (princ (cond
10325                   ((numberp id) id)
10326                   ((cdr where) (cdr where))
10327                   (header (mail-header-number header))
10328                   (t gnus-reffed-article-number))
10329                  (current-buffer))
10330           (insert " Article retrieved.\n"))
10331         (if (or (not where)
10332                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10333             ()                          ; Malformed head.
10334           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10335             (when (and (stringp id)
10336                        (not (string= (gnus-group-real-name group)
10337                                      (car where))))
10338               ;; If we fetched by Message-ID and the article came
10339               ;; from a different group, we fudge some bogus article
10340               ;; numbers for this article.
10341               (mail-header-set-number header gnus-reffed-article-number))
10342             (save-excursion
10343               (set-buffer gnus-summary-buffer)
10344               (decf gnus-reffed-article-number)
10345               (gnus-remove-header (mail-header-number header))
10346               (push header gnus-newsgroup-headers)
10347               (setq gnus-current-headers header)
10348               (push (mail-header-number header) gnus-newsgroup-limit)))
10349           header)))))
10350
10351 (defun gnus-remove-header (number)
10352   "Remove header NUMBER from `gnus-newsgroup-headers'."
10353   (if (and gnus-newsgroup-headers
10354            (= number (mail-header-number (car gnus-newsgroup-headers))))
10355       (pop gnus-newsgroup-headers)
10356     (let ((headers gnus-newsgroup-headers))
10357       (while (and (cdr headers)
10358                   (not (= number (mail-header-number (cadr headers)))))
10359         (pop headers))
10360       (when (cdr headers)
10361         (setcdr headers (cddr headers))))))
10362
10363 ;;;
10364 ;;; summary highlights
10365 ;;;
10366
10367 (defun gnus-highlight-selected-summary ()
10368   "Highlight selected article in summary buffer."
10369   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10370   (when gnus-summary-selected-face
10371     (save-excursion
10372       (let* ((beg (progn (beginning-of-line) (point)))
10373              (end (progn (end-of-line) (point)))
10374              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10375              (from (if (get-text-property beg gnus-mouse-face-prop)
10376                        beg
10377                      (or (next-single-property-change
10378                           beg gnus-mouse-face-prop nil end)
10379                          beg)))
10380              (to
10381               (if (= from end)
10382                   (- from 2)
10383                 (or (next-single-property-change
10384                      from gnus-mouse-face-prop nil end)
10385                     end))))
10386         ;; If no mouse-face prop on line we will have to = from = end,
10387         ;; so we highlight the entire line instead.
10388         (when (= (+ to 2) from)
10389           (setq from beg)
10390           (setq to end))
10391         (if gnus-newsgroup-selected-overlay
10392             ;; Move old overlay.
10393             (gnus-move-overlay
10394              gnus-newsgroup-selected-overlay from to (current-buffer))
10395           ;; Create new overlay.
10396           (gnus-overlay-put
10397            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10398            'face gnus-summary-selected-face))))))
10399
10400 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10401 (defun gnus-summary-highlight-line ()
10402   "Highlight current line according to `gnus-summary-highlight'."
10403   (let* ((list gnus-summary-highlight)
10404          (p (point))
10405          (end (progn (end-of-line) (point)))
10406          ;; now find out where the line starts and leave point there.
10407          (beg (progn (beginning-of-line) (point)))
10408          (article (gnus-summary-article-number))
10409          (score (or (cdr (assq (or article gnus-current-article)
10410                                gnus-newsgroup-scored))
10411                     gnus-summary-default-score 0))
10412          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10413          (inhibit-read-only t))
10414     ;; Eval the cars of the lists until we find a match.
10415     (let ((default gnus-summary-default-score)
10416           (default-high gnus-summary-default-high-score)
10417           (default-low gnus-summary-default-low-score))
10418       (while (and list
10419                   (not (eval (caar list))))
10420         (setq list (cdr list))))
10421     (let ((face (cdar list)))
10422       (unless (eq face (get-text-property beg 'face))
10423         (gnus-put-text-property-excluding-characters-with-faces
10424          beg end 'face
10425          (setq face (if (boundp face) (symbol-value face) face)))
10426         (when gnus-summary-highlight-line-function
10427           (funcall gnus-summary-highlight-line-function article face))))
10428     (goto-char p)))
10429
10430 (defun gnus-update-read-articles (group unread &optional compute)
10431   "Update the list of read articles in GROUP."
10432   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10433          (entry (gnus-gethash group gnus-newsrc-hashtb))
10434          (info (nth 2 entry))
10435          (prev 1)
10436          (unread (sort (copy-sequence unread) '<))
10437          read)
10438     (if (or (not info) (not active))
10439         ;; There is no info on this group if it was, in fact,
10440         ;; killed.  Gnus stores no information on killed groups, so
10441         ;; there's nothing to be done.
10442         ;; One could store the information somewhere temporarily,
10443         ;; perhaps...  Hmmm...
10444         ()
10445       ;; Remove any negative articles numbers.
10446       (while (and unread (< (car unread) 0))
10447         (setq unread (cdr unread)))
10448       ;; Remove any expired article numbers
10449       (while (and unread (< (car unread) (car active)))
10450         (setq unread (cdr unread)))
10451       ;; Compute the ranges of read articles by looking at the list of
10452       ;; unread articles.
10453       (while unread
10454         (when (/= (car unread) prev)
10455           (push (if (= prev (1- (car unread))) prev
10456                   (cons prev (1- (car unread))))
10457                 read))
10458         (setq prev (1+ (car unread)))
10459         (setq unread (cdr unread)))
10460       (when (<= prev (cdr active))
10461         (push (cons prev (cdr active)) read))
10462       (setq read (if (> (length read) 1) (nreverse read) read))
10463       (if compute
10464           read
10465         (save-excursion
10466           (let (setmarkundo)
10467             ;; Propagate the read marks to the backend.
10468             (when (gnus-check-backend-function 'request-set-mark group)
10469               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10470                     (add (gnus-remove-from-range read (gnus-info-read info))))
10471                 (when (or add del)
10472                   (unless (gnus-check-group group)
10473                     (error "Can't open server for %s" group))
10474                   (gnus-request-set-mark
10475                    group (delq nil (list (if add (list add 'add '(read)))
10476                                          (if del (list del 'del '(read))))))
10477                   (setq setmarkundo
10478                         `(gnus-request-set-mark
10479                           ,group
10480                           ',(delq nil (list
10481                                        (if del (list del 'add '(read)))
10482                                        (if add (list add 'del '(read))))))))))
10483             (set-buffer gnus-group-buffer)
10484             (gnus-undo-register
10485               `(progn
10486                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10487                  (gnus-info-set-read ',info ',(gnus-info-read info))
10488                  (gnus-get-unread-articles-in-group ',info
10489                                                     (gnus-active ,group))
10490                  (gnus-group-update-group ,group t)
10491                  ,setmarkundo))))
10492         ;; Enter this list into the group info.
10493         (gnus-info-set-read info read)
10494         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10495         (gnus-get-unread-articles-in-group info (gnus-active group))
10496         t))))
10497
10498 (defun gnus-offer-save-summaries ()
10499   "Offer to save all active summary buffers."
10500   (let (buffers)
10501     ;; Go through all buffers and find all summaries.
10502     (dolist (buffer (buffer-list))
10503       (when (and (setq buffer (buffer-name buffer))
10504                  (string-match "Summary" buffer)
10505                  (save-excursion
10506                    (set-buffer buffer)
10507                    ;; We check that this is, indeed, a summary buffer.
10508                    (and (eq major-mode 'gnus-summary-mode)
10509                         ;; Also make sure this isn't bogus.
10510                         gnus-newsgroup-prepared
10511                         ;; Also make sure that this isn't a
10512                         ;; dead summary buffer.
10513                         (not gnus-dead-summary-mode))))
10514         (push buffer buffers)))
10515     ;; Go through all these summary buffers and offer to save them.
10516     (when buffers
10517       (save-excursion
10518         (map-y-or-n-p
10519          "Update summary buffer %s? "
10520          (lambda (buf)
10521            (switch-to-buffer buf)
10522            (gnus-summary-exit))
10523          buffers)))))
10524
10525 (defun gnus-summary-setup-default-charset ()
10526   "Setup newsgroup default charset."
10527   (if (equal gnus-newsgroup-name "nndraft:drafts")
10528       (setq gnus-newsgroup-charset nil)
10529     (let* ((ignored-charsets
10530             (or gnus-newsgroup-ephemeral-ignored-charsets
10531                 (append
10532                  (and gnus-newsgroup-name
10533                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10534                  gnus-newsgroup-ignored-charsets))))
10535       (setq gnus-newsgroup-charset
10536             (or gnus-newsgroup-ephemeral-charset
10537                 (and gnus-newsgroup-name
10538                      (gnus-parameter-charset gnus-newsgroup-name))
10539                 gnus-default-charset))
10540       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10541            ignored-charsets))))
10542
10543 ;;;
10544 ;;; Mime Commands
10545 ;;;
10546
10547 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10548   "Display the current article buffer fully MIME-buttonized.
10549 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10550 treated as multipart/mixed."
10551   (interactive "P")
10552   (require 'gnus-art)
10553   (let ((gnus-unbuttonized-mime-types nil)
10554         (gnus-mime-display-multipart-as-mixed show-all-parts))
10555     (gnus-summary-show-article)))
10556
10557 (defun gnus-summary-repair-multipart (article)
10558   "Add a Content-Type header to a multipart article without one."
10559   (interactive (list (gnus-summary-article-number)))
10560   (gnus-with-article article
10561     (message-narrow-to-head)
10562     (message-remove-header "Mime-Version")
10563     (goto-char (point-max))
10564     (insert "Mime-Version: 1.0\n")
10565     (widen)
10566     (when (search-forward "\n--" nil t)
10567       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10568         (message-narrow-to-head)
10569         (message-remove-header "Content-Type")
10570         (goto-char (point-max))
10571         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10572                         separator))
10573         (widen))))
10574   (let (gnus-mark-article-hook)
10575     (gnus-summary-select-article t t nil article)))
10576
10577 (defun gnus-summary-toggle-display-buttonized ()
10578   "Toggle the buttonizing of the article buffer."
10579   (interactive)
10580   (require 'gnus-art)
10581   (if (setq gnus-inhibit-mime-unbuttonizing
10582             (not gnus-inhibit-mime-unbuttonizing))
10583       (let ((gnus-unbuttonized-mime-types nil))
10584         (gnus-summary-show-article))
10585     (gnus-summary-show-article)))
10586
10587 ;;;
10588 ;;; Generic summary marking commands
10589 ;;;
10590
10591 (defvar gnus-summary-marking-alist
10592   '((read gnus-del-mark "d")
10593     (unread gnus-unread-mark "u")
10594     (ticked gnus-ticked-mark "!")
10595     (dormant gnus-dormant-mark "?")
10596     (expirable gnus-expirable-mark "e"))
10597   "An alist of names/marks/keystrokes.")
10598
10599 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10600 (defvar gnus-summary-mark-map)
10601
10602 (defun gnus-summary-make-all-marking-commands ()
10603   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10604   (dolist (elem gnus-summary-marking-alist)
10605     (apply 'gnus-summary-make-marking-command elem)))
10606
10607 (defun gnus-summary-make-marking-command (name mark keystroke)
10608   (let ((map (make-sparse-keymap)))
10609     (define-key gnus-summary-generic-mark-map keystroke map)
10610     (dolist (lway `((next "next" next nil "n")
10611                     (next-unread "next unread" next t "N")
10612                     (prev "previous" prev nil "p")
10613                     (prev-unread "previous unread" prev t "P")
10614                     (nomove "" nil nil ,keystroke)))
10615       (let ((func (gnus-summary-make-marking-command-1
10616                    mark (car lway) lway name)))
10617         (setq func (eval func))
10618         (define-key map (nth 4 lway) func)))))
10619
10620 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10621   `(defun ,(intern
10622             (format "gnus-summary-put-mark-as-%s%s"
10623                     name (if (eq way 'nomove)
10624                              ""
10625                            (concat "-" (symbol-name way)))))
10626      (n)
10627      ,(format
10628        "Mark the current article as %s%s.
10629 If N, the prefix, then repeat N times.
10630 If N is negative, move in reverse order.
10631 The difference between N and the actual number of articles marked is
10632 returned."
10633        name (cadr lway))
10634      (interactive "p")
10635      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10636
10637 (defun gnus-summary-generic-mark (n mark move unread)
10638   "Mark N articles with MARK."
10639   (unless (eq major-mode 'gnus-summary-mode)
10640     (error "This command can only be used in the summary buffer"))
10641   (gnus-summary-show-thread)
10642   (let ((nummove
10643          (cond
10644           ((eq move 'next) 1)
10645           ((eq move 'prev) -1)
10646           (t 0))))
10647     (if (zerop nummove)
10648         (setq n 1)
10649       (when (< n 0)
10650         (setq n (abs n)
10651               nummove (* -1 nummove))))
10652     (while (and (> n 0)
10653                 (gnus-summary-mark-article nil mark)
10654                 (zerop (gnus-summary-next-subject nummove unread t)))
10655       (setq n (1- n)))
10656     (when (/= 0 n)
10657       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10658     (gnus-summary-recenter)
10659     (gnus-summary-position-point)
10660     (gnus-set-mode-line 'summary)
10661     n))
10662
10663 (defun gnus-summary-insert-articles (articles)
10664   (when (setq articles
10665               (gnus-set-difference articles
10666                                    (mapcar (lambda (h) (mail-header-number h))
10667                                            gnus-newsgroup-headers)))
10668     (setq gnus-newsgroup-headers
10669           (merge 'list
10670                  gnus-newsgroup-headers
10671                  (gnus-fetch-headers articles)
10672                  'gnus-article-sort-by-number))
10673     ;; Suppress duplicates?
10674     (when gnus-suppress-duplicates
10675       (gnus-dup-suppress-articles))
10676
10677     ;; We might want to build some more threads first.
10678     (when (and gnus-fetch-old-headers
10679                (eq gnus-headers-retrieved-by 'nov))
10680       (if (eq gnus-fetch-old-headers 'invisible)
10681           (gnus-build-all-threads)
10682         (gnus-build-old-threads)))
10683     ;; Let the Gnus agent mark articles as read.
10684     (when gnus-agent
10685       (gnus-agent-get-undownloaded-list))
10686     ;; Remove list identifiers from subject
10687     (when gnus-list-identifiers
10688       (gnus-summary-remove-list-identifiers))
10689     ;; First and last article in this newsgroup.
10690     (when gnus-newsgroup-headers
10691       (setq gnus-newsgroup-begin
10692             (mail-header-number (car gnus-newsgroup-headers))
10693             gnus-newsgroup-end
10694             (mail-header-number
10695              (gnus-last-element gnus-newsgroup-headers))))
10696     (when gnus-use-scoring
10697       (gnus-possibly-score-headers))))
10698
10699 (defun gnus-summary-insert-old-articles (&optional all)
10700   "Insert all old articles in this group.
10701 If ALL is non-nil, already read articles become readable.
10702 If ALL is a number, fetch this number of articles."
10703   (interactive "P")
10704   (prog1
10705       (let ((old (mapcar 'car gnus-newsgroup-data))
10706             (i (car gnus-newsgroup-active))
10707             older len)
10708         (while (<= i (cdr gnus-newsgroup-active))
10709           (or (memq i old) (push i older))
10710           (incf i))
10711         (setq len (length older))
10712         (cond
10713          ((null older) nil)
10714          ((numberp all)
10715           (if (< all len)
10716               (setq older (subseq older 0 all))))
10717          (all nil)
10718          (t
10719           (if (and (numberp gnus-large-newsgroup)
10720                    (> len gnus-large-newsgroup))
10721               (let ((input
10722                      (read-string
10723                       (format
10724                        "How many articles from %s (default %d): "
10725                        (gnus-limit-string
10726                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10727                        len))))
10728                 (unless (string-match "^[ \t]*$" input)
10729                   (setq all (string-to-number input))
10730                   (if (< all len)
10731                       (setq older (subseq older 0 all))))))))
10732         (if (not older)
10733             (message "No old news.")
10734           (gnus-summary-insert-articles older)
10735           (gnus-summary-limit (gnus-union older old))))
10736     (gnus-summary-position-point)))
10737
10738 (defun gnus-summary-insert-new-articles ()
10739   "Insert all new articles in this group."
10740   (interactive)
10741   (prog1
10742       (let ((old (mapcar 'car gnus-newsgroup-data))
10743             (old-active gnus-newsgroup-active)
10744             (nnmail-fetched-sources (list t))
10745             i new)
10746         (setq gnus-newsgroup-active
10747               (gnus-activate-group gnus-newsgroup-name 'scan))
10748         (setq i (1+ (cdr old-active)))
10749         (while (<= i (cdr gnus-newsgroup-active))
10750           (push i new)
10751           (incf i))
10752         (if (not new)
10753             (message "No gnus is bad news.")
10754           (setq new (nreverse new))
10755           (gnus-summary-insert-articles new)
10756           (setq gnus-newsgroup-unreads
10757                 (append gnus-newsgroup-unreads new))
10758           (gnus-summary-limit (gnus-union old new))))
10759     (gnus-summary-position-point)))
10760
10761 (gnus-summary-make-all-marking-commands)
10762
10763 (gnus-ems-redefine)
10764
10765 (provide 'gnus-sum)
10766
10767 (run-hooks 'gnus-sum-load-hook)
10768
10769 ;;; gnus-sum.el ends here