* smiley-ems.el (smiley-update-cache): Check for valid types.
[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 (require 'nnoo)
40
41 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
42 (autoload 'gnus-cache-write-active "gnus-cache")
43 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
44 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
45 (autoload 'mm-uu-dissect "mm-uu")
46
47 (defcustom gnus-kill-summary-on-exit t
48   "*If non-nil, kill the summary buffer when you exit from it.
49 If nil, the summary will become a \"*Dead Summary*\" buffer, and
50 it will be killed sometime later."
51   :group 'gnus-summary-exit
52   :type 'boolean)
53
54 (defcustom gnus-fetch-old-headers nil
55   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
56 If an unread article in the group refers to an older, already read (or
57 just marked as read) article, the old article will not normally be
58 displayed in the Summary buffer.  If this variable is non-nil, Gnus
59 will attempt to grab the headers to the old articles, and thereby
60 build complete threads.  If it has the value `some', only enough
61 headers to connect otherwise loose threads will be displayed.  This
62 variable can also be a number.  In that case, no more than that number
63 of old headers will be fetched.  If it has the value `invisible', all
64 old headers will be fetched, but none will be displayed.
65
66 The server has to support NOV for any of this to work."
67   :group 'gnus-thread
68   :type '(choice (const :tag "off" nil)
69                  (const some)
70                  number
71                  (sexp :menu-tag "other" t)))
72
73 (defcustom gnus-refer-thread-limit 200
74   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
75 If t, fetch all the available old headers."
76   :group 'gnus-thread
77   :type '(choice number
78                  (sexp :menu-tag "other" t)))
79
80 (defcustom gnus-summary-make-false-root 'adopt
81   "*nil means that Gnus won't gather loose threads.
82 If the root of a thread has expired or been read in a previous
83 session, the information necessary to build a complete thread has been
84 lost.  Instead of having many small sub-threads from this original thread
85 scattered all over the summary buffer, Gnus can gather them.
86
87 If non-nil, Gnus will try to gather all loose sub-threads from an
88 original thread into one large thread.
89
90 If this variable is non-nil, it should be one of `none', `adopt',
91 `dummy' or `empty'.
92
93 If this variable is `none', Gnus will not make a false root, but just
94 present the sub-threads after another.
95 If this variable is `dummy', Gnus will create a dummy root that will
96 have all the sub-threads as children.
97 If this variable is `adopt', Gnus will make one of the \"children\"
98 the parent and mark all the step-children as such.
99 If this variable is `empty', the \"children\" are printed with empty
100 subject fields.  (Or rather, they will be printed with a string
101 given by the `gnus-summary-same-subject' variable.)"
102   :group 'gnus-thread
103   :type '(choice (const :tag "off" nil)
104                  (const none)
105                  (const dummy)
106                  (const adopt)
107                  (const empty)))
108
109 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
110   "*A regexp to match subjects to be excluded from loose thread gathering.
111 As loose thread gathering is done on subjects only, that means that
112 there can be many false gatherings performed.  By rooting out certain
113 common subjects, gathering might become saner."
114   :group 'gnus-thread
115   :type 'regexp)
116
117 (defcustom gnus-summary-gather-subject-limit nil
118   "*Maximum length of subject comparisons when gathering loose threads.
119 Use nil to compare full subjects.  Setting this variable to a low
120 number will help gather threads that have been corrupted by
121 newsreaders chopping off subject lines, but it might also mean that
122 unrelated articles that have subject that happen to begin with the
123 same few characters will be incorrectly gathered.
124
125 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
126 comparing subjects."
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const fuzzy)
130                  (sexp :menu-tag "on" t)))
131
132 (defcustom gnus-simplify-subject-functions nil
133   "List of functions taking a string argument that simplify subjects.
134 The functions are applied recursively.
135
136 Useful functions to put in this list include: `gnus-simplify-subject-re',
137 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
138   :group 'gnus-thread
139   :type '(repeat function))
140
141 (defcustom gnus-simplify-ignored-prefixes nil
142   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
143   :group 'gnus-thread
144   :type '(choice (const :tag "off" nil)
145                  regexp))
146
147 (defcustom gnus-build-sparse-threads nil
148   "*If non-nil, fill in the gaps in threads.
149 If `some', only fill in the gaps that are needed to tie loose threads
150 together.  If `more', fill in all leaf nodes that Gnus can find.  If
151 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
152   :group 'gnus-thread
153   :type '(choice (const :tag "off" nil)
154                  (const some)
155                  (const more)
156                  (sexp :menu-tag "all" t)))
157
158 (defcustom gnus-summary-thread-gathering-function
159   'gnus-gather-threads-by-subject
160   "*Function used for gathering loose threads.
161 There are two pre-defined functions: `gnus-gather-threads-by-subject',
162 which only takes Subjects into consideration; and
163 `gnus-gather-threads-by-references', which compared the References
164 headers of the articles to find matches."
165   :group 'gnus-thread
166   :type '(radio (function-item gnus-gather-threads-by-subject)
167                 (function-item gnus-gather-threads-by-references)
168                 (function :tag "other")))
169
170 (defcustom gnus-summary-same-subject ""
171   "*String indicating that the current article has the same subject as the previous.
172 This variable will only be used if the value of
173 `gnus-summary-make-false-root' is `empty'."
174   :group 'gnus-summary-format
175   :type 'string)
176
177 (defcustom gnus-summary-goto-unread t
178   "*If t, many commands will go to the next unread article.
179 This applies to marking commands as well as other commands that
180 \"naturally\" select the next article, like, for instance, `SPC' at
181 the end of an article.
182
183 If nil, the marking commands do NOT go to the next unread article
184 (they go to the next article instead).  If `never', commands that
185 usually go to the next unread article, will go to the next article,
186 whether it is read or not."
187   :group 'gnus-summary-marks
188   :link '(custom-manual "(gnus)Setting Marks")
189   :type '(choice (const :tag "off" nil)
190                  (const never)
191                  (sexp :menu-tag "on" t)))
192
193 (defcustom gnus-summary-default-score 0
194   "*Default article score level.
195 All scores generated by the score files will be added to this score.
196 If this variable is nil, scoring will be disabled."
197   :group 'gnus-score-default
198   :type '(choice (const :tag "disable")
199                  integer))
200
201 (defcustom gnus-summary-default-high-score 0
202   "*Default threshold for a high scored article.
203 An article will be highlighted as high scored if its score is greater
204 than this score."
205   :group 'gnus-score-default
206   :type 'integer)
207
208 (defcustom gnus-summary-default-low-score 0
209   "*Default threshold for a low scored article.
210 An article will be highlighted as low scored if its score is smaller
211 than this score."
212   :group 'gnus-score-default
213   :type 'integer)
214
215 (defcustom gnus-summary-zcore-fuzz 0
216   "*Fuzziness factor for the zcore in the summary buffer.
217 Articles with scores closer than this to `gnus-summary-default-score'
218 will not be marked."
219   :group 'gnus-summary-format
220   :type 'integer)
221
222 (defcustom gnus-simplify-subject-fuzzy-regexp nil
223   "*Strings to be removed when doing fuzzy matches.
224 This can either be a regular expression or list of regular expressions
225 that will be removed from subject strings if fuzzy subject
226 simplification is selected."
227   :group 'gnus-thread
228   :type '(repeat regexp))
229
230 (defcustom gnus-show-threads t
231   "*If non-nil, display threads in summary mode."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-hide-subtree nil
236   "*If non-nil, hide all threads initially.
237 If threads are hidden, you have to run the command
238 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
239 to expose hidden threads."
240   :group 'gnus-thread
241   :type 'boolean)
242
243 (defcustom gnus-thread-hide-killed t
244   "*If non-nil, hide killed threads automatically."
245   :group 'gnus-thread
246   :type 'boolean)
247
248 (defcustom gnus-thread-ignore-subject t
249   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
250 If nil, articles that have different subjects from their parents will
251 start separate threads."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-operation-ignore-subject t
256   "*If non-nil, subjects will be ignored when doing thread commands.
257 This affects commands like `gnus-summary-kill-thread' and
258 `gnus-summary-lower-thread'.
259
260 If this variable is nil, articles in the same thread with different
261 subjects will not be included in the operation in question.  If this
262 variable is `fuzzy', only articles that have subjects that are fuzzily
263 equal will be included."
264   :group 'gnus-thread
265   :type '(choice (const :tag "off" nil)
266                  (const fuzzy)
267                  (sexp :tag "on" t)))
268
269 (defcustom gnus-thread-indent-level 4
270   "*Number that says how much each sub-thread should be indented."
271   :group 'gnus-thread
272   :type 'integer)
273
274 (defcustom gnus-auto-extend-newsgroup t
275   "*If non-nil, extend newsgroup forward and backward when requested."
276   :group 'gnus-summary-choose
277   :type 'boolean)
278
279 (defcustom gnus-auto-select-first t
280   "*If non-nil, select the article under point.
281 Which article this is is controlled by the `gnus-auto-select-subject'
282 variable.
283
284 If you want to prevent automatic selection of articles in some
285 newsgroups, set the variable to nil in `gnus-select-group-hook'."
286   :group 'gnus-group-select
287   :type '(choice (const :tag "none" nil)
288                  (sexp :menu-tag "first" t)))
289
290 (defcustom gnus-auto-select-subject 'unread
291   "*Says what subject to place under point when entering a group.
292
293 This variable can either be the symbols `first' (place point on the
294 first subject), `unread' (place point on the subject line of the first
295 unread article), `best' (place point on the subject line of the
296 higest-scored article), `unseen' (place point on the subject line of
297 the first unseen article), or a function to be called to place point on
298 some subject line.."
299   :group 'gnus-group-select
300   :type '(choice (const best)
301                  (const unread)
302                  (const first)
303                  (const unseen)))
304
305 (defcustom gnus-auto-select-next t
306   "*If non-nil, offer to go to the next group from the end of the previous.
307 If the value is t and the next newsgroup is empty, Gnus will exit
308 summary mode and go back to group mode.  If the value is neither nil
309 nor t, Gnus will select the following unread newsgroup.  In
310 particular, if the value is the symbol `quietly', the next unread
311 newsgroup will be selected without any confirmation, and if it is
312 `almost-quietly', the next group will be selected without any
313 confirmation if you are located on the last article in the group.
314 Finally, if this variable is `slightly-quietly', the `Z n' command
315 will go to the next group without confirmation."
316   :group 'gnus-summary-maneuvering
317   :type '(choice (const :tag "off" nil)
318                  (const quietly)
319                  (const almost-quietly)
320                  (const slightly-quietly)
321                  (sexp :menu-tag "on" t)))
322
323 (defcustom gnus-auto-select-same nil
324   "*If non-nil, select the next article with the same subject.
325 If there are no more articles with the same subject, go to
326 the first unread article."
327   :group 'gnus-summary-maneuvering
328   :type 'boolean)
329
330 (defcustom gnus-summary-check-current nil
331   "*If non-nil, consider the current article when moving.
332 The \"unread\" movement commands will stay on the same line if the
333 current article is unread."
334   :group 'gnus-summary-maneuvering
335   :type 'boolean)
336
337 (defcustom gnus-auto-center-summary t
338   "*If non-nil, always center the current summary buffer.
339 In particular, if `vertical' do only vertical recentering.  If non-nil
340 and non-`vertical', do both horizontal and vertical recentering."
341   :group 'gnus-summary-maneuvering
342   :type '(choice (const :tag "none" nil)
343                  (const vertical)
344                  (integer :tag "height")
345                  (sexp :menu-tag "both" t)))
346
347 (defcustom gnus-show-all-headers nil
348   "*If non-nil, don't hide any headers."
349   :group 'gnus-article-hiding
350   :group 'gnus-article-headers
351   :type 'boolean)
352
353 (defcustom gnus-summary-ignore-duplicates nil
354   "*If non-nil, ignore articles with identical Message-ID headers."
355   :group 'gnus-summary
356   :type 'boolean)
357
358 (defcustom gnus-single-article-buffer t
359   "*If non-nil, display all articles in the same buffer.
360 If nil, each group will get its own article buffer."
361   :group 'gnus-article-various
362   :type 'boolean)
363
364 (defcustom gnus-break-pages t
365   "*If non-nil, do page breaking on articles.
366 The page delimiter is specified by the `gnus-page-delimiter'
367 variable."
368   :group 'gnus-article-various
369   :type 'boolean)
370
371 (defcustom gnus-move-split-methods nil
372   "*Variable used to suggest where articles are to be moved to.
373 It uses the same syntax as the `gnus-split-methods' variable.
374 However, whereas `gnus-split-methods' specifies file names as targets,
375 this variable specifies group names."
376   :group 'gnus-summary-mail
377   :type '(repeat (choice (list :value (fun) function)
378                          (cons :value ("" "") regexp (repeat string))
379                          (sexp :value nil))))
380
381 (defcustom gnus-unread-mark ?           ;Whitespace
382   "*Mark used for unread articles."
383   :group 'gnus-summary-marks
384   :type 'character)
385
386 (defcustom gnus-ticked-mark ?!
387   "*Mark used for ticked articles."
388   :group 'gnus-summary-marks
389   :type 'character)
390
391 (defcustom gnus-dormant-mark ??
392   "*Mark used for dormant articles."
393   :group 'gnus-summary-marks
394   :type 'character)
395
396 (defcustom gnus-del-mark ?r
397   "*Mark used for del'd articles."
398   :group 'gnus-summary-marks
399   :type 'character)
400
401 (defcustom gnus-read-mark ?R
402   "*Mark used for read articles."
403   :group 'gnus-summary-marks
404   :type 'character)
405
406 (defcustom gnus-expirable-mark ?E
407   "*Mark used for expirable articles."
408   :group 'gnus-summary-marks
409   :type 'character)
410
411 (defcustom gnus-killed-mark ?K
412   "*Mark used for killed articles."
413   :group 'gnus-summary-marks
414   :type 'character)
415
416 (defcustom gnus-souped-mark ?F
417   "*Mark used for souped articles."
418   :group 'gnus-summary-marks
419   :type 'character)
420
421 (defcustom gnus-kill-file-mark ?X
422   "*Mark used for articles killed by kill files."
423   :group 'gnus-summary-marks
424   :type 'character)
425
426 (defcustom gnus-low-score-mark ?Y
427   "*Mark used for articles with a low score."
428   :group 'gnus-summary-marks
429   :type 'character)
430
431 (defcustom gnus-catchup-mark ?C
432   "*Mark used for articles that are caught up."
433   :group 'gnus-summary-marks
434   :type 'character)
435
436 (defcustom gnus-replied-mark ?A
437   "*Mark used for articles that have been replied to."
438   :group 'gnus-summary-marks
439   :type 'character)
440
441 (defcustom gnus-forwarded-mark ?F
442   "*Mark used for articles that have been forwarded."
443   :group 'gnus-summary-marks
444   :type 'character)
445
446 (defcustom gnus-recent-mark ?N
447   "*Mark used for articles that are recent."
448   :group 'gnus-summary-marks
449   :type 'character)
450
451 (defcustom gnus-cached-mark ?*
452   "*Mark used for articles that are in the cache."
453   :group 'gnus-summary-marks
454   :type 'character)
455
456 (defcustom gnus-saved-mark ?S
457   "*Mark used for articles that have been saved."
458   :group 'gnus-summary-marks
459   :type 'character)
460
461 (defcustom gnus-unseen-mark ?.
462   "*Mark used for articles that haven't been seen."
463   :group 'gnus-summary-marks
464   :type 'character)
465
466 (defcustom gnus-no-mark ?               ;Whitespace
467   "*Mark used for articles that have no other secondary mark."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ancient-mark ?O
472   "*Mark used for ancient articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-sparse-mark ?Q
477   "*Mark used for sparsely reffed articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-canceled-mark ?G
482   "*Mark used for canceled articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-duplicate-mark ?M
487   "*Mark used for duplicate articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-undownloaded-mark ?@
492   "*Mark used for articles that weren't downloaded."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-downloadable-mark ?%
497   "*Mark used for articles that are to be downloaded."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-unsendable-mark ?=
502   "*Mark used for articles that won't be sent."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-score-over-mark ?+
507   "*Score mark used for articles with high scores."
508   :group 'gnus-summary-marks
509   :type 'character)
510
511 (defcustom gnus-score-below-mark ?-
512   "*Score mark used for articles with low scores."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-empty-thread-mark ?     ;Whitespace
517   "*There is no thread under the article."
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-not-empty-thread-mark ?=
522   "*There is a thread under the article."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-view-pseudo-asynchronously nil
527   "*If non-nil, Gnus will view pseudo-articles asynchronously."
528   :group 'gnus-extract-view
529   :type 'boolean)
530
531 (defcustom gnus-auto-expirable-marks
532   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
533         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
534         gnus-souped-mark gnus-duplicate-mark)
535   "*The list of marks converted into expiration if a group is auto-expirable."
536   :version "21.1"
537   :group 'gnus-summary
538   :type '(repeat character))
539
540 (defcustom gnus-inhibit-user-auto-expire t
541   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
542   :version "21.1"
543   :group 'gnus-summary
544   :type 'boolean)
545
546 (defcustom gnus-view-pseudos nil
547   "*If `automatic', pseudo-articles will be viewed automatically.
548 If `not-confirm', pseudos will be viewed automatically, and the user
549 will not be asked to confirm the command."
550   :group 'gnus-extract-view
551   :type '(choice (const :tag "off" nil)
552                  (const automatic)
553                  (const not-confirm)))
554
555 (defcustom gnus-view-pseudos-separately t
556   "*If non-nil, one pseudo-article will be created for each file to be viewed.
557 If nil, all files that use the same viewing command will be given as a
558 list of parameters to that command."
559   :group 'gnus-extract-view
560   :type 'boolean)
561
562 (defcustom gnus-insert-pseudo-articles t
563   "*If non-nil, insert pseudo-articles when decoding articles."
564   :group 'gnus-extract-view
565   :type 'boolean)
566
567 (defcustom gnus-summary-dummy-line-format
568   "  %(:                          :%) %S\n"
569   "*The format specification for the dummy roots in the summary buffer.
570 It works along the same lines as a normal formatting string,
571 with some simple extensions.
572
573 %S  The subject"
574   :group 'gnus-threading
575   :type 'string)
576
577 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
578   "*The format specification for the summary mode line.
579 It works along the same lines as a normal formatting string,
580 with some simple extensions:
581
582 %G  Group name
583 %p  Unprefixed group name
584 %A  Current article number
585 %z  Current article score
586 %V  Gnus version
587 %U  Number of unread articles in the group
588 %e  Number of unselected articles in the group
589 %Z  A string with unread/unselected article counts
590 %g  Shortish group name
591 %S  Subject of the current article
592 %u  User-defined spec
593 %s  Current score file name
594 %d  Number of dormant articles
595 %r  Number of articles that have been marked as read in this session
596 %E  Number of articles expunged by the score files"
597   :group 'gnus-summary-format
598   :type 'string)
599
600 (defcustom gnus-list-identifiers nil
601   "Regexp that matches list identifiers to be removed from subject.
602 This can also be a list of regexps."
603   :version "21.1"
604   :group 'gnus-summary-format
605   :group 'gnus-article-hiding
606   :type '(choice (const :tag "none" nil)
607                  (regexp :value ".*")
608                  (repeat :value (".*") regexp)))
609
610 (defcustom gnus-summary-mark-below 0
611   "*Mark all articles with a score below this variable as read.
612 This variable is local to each summary buffer and usually set by the
613 score file."
614   :group 'gnus-score-default
615   :type 'integer)
616
617 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
618   "*List of functions used for sorting articles in the summary buffer.
619
620 Each function takes two articles and returns non-nil if the first
621 article should be sorted before the other.  If you use more than one
622 function, the primary sort function should be the last.  You should
623 probably always include `gnus-article-sort-by-number' in the list of
624 sorting functions -- preferably first.  Also note that sorting by date
625 is often much slower than sorting by number, and the sorting order is
626 very similar.  (Sorting by date means sorting by the time the message
627 was sent, sorting by number means sorting by arrival time.)
628
629 Ready-made functions include `gnus-article-sort-by-number',
630 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
631 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
632
633 When threading is turned on, the variable `gnus-thread-sort-functions'
634 controls how articles are sorted."
635   :group 'gnus-summary-sort
636   :type '(repeat (choice (function-item gnus-article-sort-by-number)
637                          (function-item gnus-article-sort-by-author)
638                          (function-item gnus-article-sort-by-subject)
639                          (function-item gnus-article-sort-by-date)
640                          (function-item gnus-article-sort-by-score)
641                          (function :tag "other"))))
642
643 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
644   "*List of functions used for sorting threads in the summary buffer.
645 By default, threads are sorted by article number.
646
647 Each function takes two threads and returns non-nil if the first
648 thread should be sorted before the other.  If you use more than one
649 function, the primary sort function should be the last.  You should
650 probably always include `gnus-thread-sort-by-number' in the list of
651 sorting functions -- preferably first.  Also note that sorting by date
652 is often much slower than sorting by number, and the sorting order is
653 very similar.  (Sorting by date means sorting by the time the message
654 was sent, sorting by number means sorting by arrival time.)
655
656 Ready-made functions include `gnus-thread-sort-by-number',
657 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
658 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
659 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
660
661 When threading is turned off, the variable
662 `gnus-article-sort-functions' controls how articles are sorted."
663   :group 'gnus-summary-sort
664   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
665                          (function-item gnus-thread-sort-by-author)
666                          (function-item gnus-thread-sort-by-subject)
667                          (function-item gnus-thread-sort-by-date)
668                          (function-item gnus-thread-sort-by-score)
669                          (function-item gnus-thread-sort-by-total-score)
670                          (function :tag "other"))))
671
672 (defcustom gnus-thread-score-function '+
673   "*Function used for calculating the total score of a thread.
674
675 The function is called with the scores of the article and each
676 subthread and should then return the score of the thread.
677
678 Some functions you can use are `+', `max', or `min'."
679   :group 'gnus-summary-sort
680   :type 'function)
681
682 (defcustom gnus-summary-expunge-below nil
683   "All articles that have a score less than this variable will be expunged.
684 This variable is local to the summary buffers."
685   :group 'gnus-score-default
686   :type '(choice (const :tag "off" nil)
687                  integer))
688
689 (defcustom gnus-thread-expunge-below nil
690   "All threads that have a total score less than this variable will be expunged.
691 See `gnus-thread-score-function' for en explanation of what a
692 \"thread score\" is.
693
694 This variable is local to the summary buffers."
695   :group 'gnus-threading
696   :group 'gnus-score-default
697   :type '(choice (const :tag "off" nil)
698                  integer))
699
700 (defcustom gnus-summary-mode-hook nil
701   "*A hook for Gnus summary mode.
702 This hook is run before any variables are set in the summary buffer."
703   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
704   :group 'gnus-summary-various
705   :type 'hook)
706
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (when (featurep 'xemacs)
709   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
710   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
711   (add-hook 'gnus-summary-mode-hook
712             'gnus-xmas-switch-horizontal-scrollbar-off))
713
714 (defcustom gnus-summary-menu-hook nil
715   "*Hook run after the creation of the summary mode menu."
716   :group 'gnus-summary-visual
717   :type 'hook)
718
719 (defcustom gnus-summary-exit-hook nil
720   "*A hook called on exit from the summary buffer.
721 It will be called with point in the group buffer."
722   :group 'gnus-summary-exit
723   :type 'hook)
724
725 (defcustom gnus-summary-prepare-hook nil
726   "*A hook called after the summary buffer has been generated.
727 If you want to modify the summary buffer, you can use this hook."
728   :group 'gnus-summary-various
729   :type 'hook)
730
731 (defcustom gnus-summary-prepared-hook nil
732   "*A hook called as the last thing after the summary buffer has been generated."
733   :group 'gnus-summary-various
734   :type 'hook)
735
736 (defcustom gnus-summary-generate-hook nil
737   "*A hook run just before generating the summary buffer.
738 This hook is commonly used to customize threading variables and the
739 like."
740   :group 'gnus-summary-various
741   :type 'hook)
742
743 (defcustom gnus-select-group-hook nil
744   "*A hook called when a newsgroup is selected.
745
746 If you'd like to simplify subjects like the
747 `gnus-summary-next-same-subject' command does, you can use the
748 following hook:
749
750  (setq gnus-select-group-hook
751       (list
752         (lambda ()
753           (mapcar (lambda (header)
754                      (mail-header-set-subject
755                       header
756                       (gnus-simplify-subject
757                        (mail-header-subject header) 're-only)))
758                   gnus-newsgroup-headers))))"
759   :group 'gnus-group-select
760   :type 'hook)
761
762 (defcustom gnus-select-article-hook nil
763   "*A hook called when an article is selected."
764   :group 'gnus-summary-choose
765   :type 'hook)
766
767 (defcustom gnus-visual-mark-article-hook
768   (list 'gnus-highlight-selected-summary)
769   "*Hook run after selecting an article in the summary buffer.
770 It is meant to be used for highlighting the article in some way.  It
771 is not run if `gnus-visual' is nil."
772   :group 'gnus-summary-visual
773   :type 'hook)
774
775 (defcustom gnus-parse-headers-hook nil
776   "*A hook called before parsing the headers."
777   :group 'gnus-various
778   :type 'hook)
779
780 (defcustom gnus-exit-group-hook nil
781   "*A hook called when exiting summary mode.
782 This hook is not called from the non-updating exit commands like `Q'."
783   :group 'gnus-various
784   :type 'hook)
785
786 (defcustom gnus-summary-update-hook
787   (list 'gnus-summary-highlight-line)
788   "*A hook called when a summary line is changed.
789 The hook will not be called if `gnus-visual' is nil.
790
791 The default function `gnus-summary-highlight-line' will
792 highlight the line according to the `gnus-summary-highlight'
793 variable."
794   :group 'gnus-summary-visual
795   :type 'hook)
796
797 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
798   "*A hook called when an article is selected for the first time.
799 The hook is intended to mark an article as read (or unread)
800 automatically when it is selected."
801   :group 'gnus-summary-choose
802   :type 'hook)
803
804 (defcustom gnus-group-no-more-groups-hook nil
805   "*A hook run when returning to group mode having no more (unread) groups."
806   :group 'gnus-group-select
807   :type 'hook)
808
809 (defcustom gnus-ps-print-hook nil
810   "*A hook run before ps-printing something from Gnus."
811   :group 'gnus-summary
812   :type 'hook)
813
814 (defcustom gnus-summary-display-arrow
815   (and (fboundp 'display-graphic-p)
816        (display-graphic-p))
817   "*If non-nil, display an arrow highlighting the current article."
818   :version "21.1"
819   :group 'gnus-summary
820   :type 'boolean)
821
822 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
823   "Face used for highlighting the current article in the summary buffer."
824   :group 'gnus-summary-visual
825   :type 'face)
826
827 (defcustom gnus-summary-highlight
828   '(((= mark gnus-canceled-mark)
829      . gnus-summary-cancelled-face)
830     ((and (> score default-high)
831           (or (= mark gnus-dormant-mark)
832               (= mark gnus-ticked-mark)))
833      . gnus-summary-high-ticked-face)
834     ((and (< score default-low)
835           (or (= mark gnus-dormant-mark)
836               (= mark gnus-ticked-mark)))
837      . gnus-summary-low-ticked-face)
838     ((or (= mark gnus-dormant-mark)
839          (= mark gnus-ticked-mark))
840      . gnus-summary-normal-ticked-face)
841     ((and (> score default-high) (= mark gnus-ancient-mark))
842      . gnus-summary-high-ancient-face)
843     ((and (< score default-low) (= mark gnus-ancient-mark))
844      . gnus-summary-low-ancient-face)
845     ((= mark gnus-ancient-mark)
846      . gnus-summary-normal-ancient-face)
847     ((and (> score default-high) (= mark gnus-unread-mark))
848      . gnus-summary-high-unread-face)
849     ((and (< score default-low) (= mark gnus-unread-mark))
850      . gnus-summary-low-unread-face)
851     ((= mark gnus-unread-mark)
852      . gnus-summary-normal-unread-face)
853     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
854                                                   gnus-undownloaded-mark)))
855      . gnus-summary-high-unread-face)
856     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
857                                                  gnus-undownloaded-mark)))
858      . gnus-summary-low-unread-face)
859     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
860           (memq article gnus-newsgroup-unreads))
861      . gnus-summary-normal-unread-face)
862     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
863      . gnus-summary-normal-read-face)
864     ((> score default-high)
865      . gnus-summary-high-read-face)
866     ((< score default-low)
867      . gnus-summary-low-read-face)
868     (t
869      . gnus-summary-normal-read-face))
870   "*Controls the highlighting of summary buffer lines.
871
872 A list of (FORM . FACE) pairs.  When deciding how a a particular
873 summary line should be displayed, each form is evaluated.  The content
874 of the face field after the first true form is used.  You can change
875 how those summary lines are displayed, by editing the face field.
876
877 You can use the following variables in the FORM field.
878
879 score:        The article's score
880 default:      The default article score.
881 default-high: The default score for high scored articles.
882 default-low:  The default score for low scored articles.
883 below:        The score below which articles are automatically marked as read.
884 mark:         The articles mark."
885   :group 'gnus-summary-visual
886   :type '(repeat (cons (sexp :tag "Form" nil)
887                        face)))
888
889 (defcustom gnus-alter-header-function nil
890   "Function called to allow alteration of article header structures.
891 The function is called with one parameter, the article header vector,
892 which it may alter in any way.")
893
894 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
895   "Variable that says which function should be used to decode a string with encoded words.")
896
897 (defcustom gnus-extra-headers nil
898   "*Extra headers to parse."
899   :version "21.1"
900   :group 'gnus-summary
901   :type '(repeat symbol))
902
903 (defcustom gnus-ignored-from-addresses
904   (and user-mail-address (regexp-quote user-mail-address))
905   "*Regexp of From headers that may be suppressed in favor of To headers."
906   :version "21.1"
907   :group 'gnus-summary
908   :type 'regexp)
909
910 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
911   "List of charsets that should be ignored.
912 When these charsets are used in the \"charset\" parameter, the
913 default charset will be used instead."
914   :version "21.1"
915   :type '(repeat symbol)
916   :group 'gnus-charset)
917
918 (gnus-define-group-parameter
919  ignored-charsets
920  :type list
921  :function-document
922  "Return the ignored charsets of GROUP."
923  :variable gnus-group-ignored-charsets-alist
924  :variable-default
925  '(("alt\\.chinese\\.text" iso-8859-1))
926  :variable-document
927  "Alist of regexps (to match group names) and charsets that should be ignored.
928 When these charsets are used in the \"charset\" parameter, the
929 default charset will be used instead."
930  :variable-group gnus-charset
931  :variable-type '(repeat (cons (regexp :tag "Group")
932                                (repeat symbol)))
933  :parameter-type '(choice :tag "Ignored charsets"
934                           :value nil
935                           (repeat (symbol)))
936  :parameter-document       "\
937 List of charsets that should be ignored.
938
939 When these charsets are used in the \"charset\" parameter, the
940 default charset will be used instead.")
941
942 (defcustom gnus-group-highlight-words-alist nil
943   "Alist of group regexps and highlight regexps.
944 This variable uses the same syntax as `gnus-emphasis-alist'."
945   :version "21.1"
946   :type '(repeat (cons (regexp :tag "Group")
947                        (repeat (list (regexp :tag "Highlight regexp")
948                                      (number :tag "Group for entire word" 0)
949                                      (number :tag "Group for displayed part" 0)
950                                      (symbol :tag "Face"
951                                              gnus-emphasis-highlight-words)))))
952   :group 'gnus-summary-visual)
953
954 (defcustom gnus-summary-show-article-charset-alist
955   nil
956   "Alist of number and charset.
957 The article will be shown with the charset corresponding to the
958 numbered argument.
959 For example: ((1 . cn-gb-2312) (2 . big5))."
960   :version "21.1"
961   :type '(repeat (cons (number :tag "Argument" 1)
962                        (symbol :tag "Charset")))
963   :group 'gnus-charset)
964
965 (defcustom gnus-preserve-marks t
966   "Whether marks are preserved when moving, copying and respooling messages."
967   :version "21.1"
968   :type 'boolean
969   :group 'gnus-summary-marks)
970
971 (defcustom gnus-alter-articles-to-read-function nil
972   "Function to be called to alter the list of articles to be selected."
973   :type '(choice (const nil) function)
974   :group 'gnus-summary)
975
976 (defcustom gnus-orphan-score nil
977   "*All orphans get this score added.  Set in the score file."
978   :group 'gnus-score-default
979   :type '(choice (const nil)
980                  integer))
981
982 (defcustom gnus-summary-save-parts-default-mime "image/.*"
983   "*A regexp to match MIME parts when saving multiple parts of a message
984 with gnus-summary-save-parts (X m). This regexp will be used by default
985 when prompting the user for which type of files to save."
986   :group 'gnus-summary
987   :type 'regexp)
988
989
990 (defcustom gnus-summary-save-parts-default-mime "image/.*"
991   "*A regexp to match MIME parts when saving multiple parts of a message
992 with gnus-summary-save-parts (X m). This regexp will be used by default
993 when prompting the user for which type of files to save."
994   :group 'gnus-summary
995   :type 'regexp)
996
997 (defcustom gnus-read-all-available-headers nil
998   "Whether Gnus should parse all headers made available to it.
999 This is mostly relevant for slow backends where the user may
1000 wish to widen the summary buffer to include all headers
1001 that were fetched.  Say, for nnultimate groups."
1002   :group 'gnus-summary
1003   :type '(choice boolean regexp))
1004
1005 (defcustom gnus-summary-muttprint-program "muttprint"
1006   "Command (and optional arguments) used to run Muttprint."
1007   :group 'gnus-summary
1008   :type 'string)
1009
1010 ;;; Internal variables
1011
1012 (defvar gnus-summary-display-cache nil)
1013 (defvar gnus-article-mime-handles nil)
1014 (defvar gnus-article-decoded-p nil)
1015 (defvar gnus-article-charset nil)
1016 (defvar gnus-article-ignored-charsets nil)
1017 (defvar gnus-scores-exclude-files nil)
1018 (defvar gnus-page-broken nil)
1019 (defvar gnus-inhibit-mime-unbuttonizing nil)
1020
1021 (defvar gnus-original-article nil)
1022 (defvar gnus-article-internal-prepare-hook nil)
1023 (defvar gnus-newsgroup-process-stack nil)
1024
1025 (defvar gnus-thread-indent-array nil)
1026 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1027 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1028   "Function called to sort the articles within a thread after it has been gathered together.")
1029
1030 (defvar gnus-summary-save-parts-type-history nil)
1031 (defvar gnus-summary-save-parts-last-directory nil)
1032
1033 (defvar gnus-summary-save-parts-type-history nil)
1034 (defvar gnus-summary-save-parts-last-directory nil)
1035
1036 ;; Avoid highlighting in kill files.
1037 (defvar gnus-summary-inhibit-highlight nil)
1038 (defvar gnus-newsgroup-selected-overlay nil)
1039 (defvar gnus-inhibit-limiting nil)
1040 (defvar gnus-newsgroup-adaptive-score-file nil)
1041 (defvar gnus-current-score-file nil)
1042 (defvar gnus-current-move-group nil)
1043 (defvar gnus-current-copy-group nil)
1044 (defvar gnus-current-crosspost-group nil)
1045 (defvar gnus-newsgroup-display nil)
1046
1047 (defvar gnus-newsgroup-dependencies nil)
1048 (defvar gnus-newsgroup-adaptive nil)
1049 (defvar gnus-summary-display-article-function nil)
1050 (defvar gnus-summary-highlight-line-function nil
1051   "Function called after highlighting a summary line.")
1052
1053 (defvar gnus-summary-line-format-alist
1054   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1055     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1056     (?s gnus-tmp-subject-or-nil ?s)
1057     (?n gnus-tmp-name ?s)
1058     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1059         ?s)
1060     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1061             gnus-tmp-from) ?s)
1062     (?F gnus-tmp-from ?s)
1063     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1064     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1065     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1066     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1067     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1068     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1069     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1070     (?L gnus-tmp-lines ?s)
1071     (?I gnus-tmp-indentation ?s)
1072     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1073     (?R gnus-tmp-replied ?c)
1074     (?\[ gnus-tmp-opening-bracket ?c)
1075     (?\] gnus-tmp-closing-bracket ?c)
1076     (?\> (make-string gnus-tmp-level ? ) ?s)
1077     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1078     (?i gnus-tmp-score ?d)
1079     (?z gnus-tmp-score-char ?c)
1080     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1081     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1082     (?U gnus-tmp-unread ?c)
1083     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1084         ?s)
1085     (?t (gnus-summary-number-of-articles-in-thread
1086          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1087         ?d)
1088     (?e (gnus-summary-number-of-articles-in-thread
1089          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1090         ?c)
1091     (?u gnus-tmp-user-defined ?s)
1092     (?P (gnus-pick-line-number) ?d)
1093     (?B gnus-tmp-thread-tree-header-string ?s)
1094     (user-date (gnus-user-date
1095                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1096   "An alist of format specifications that can appear in summary lines.
1097 These are paired with what variables they correspond with, along with
1098 the type of the variable (string, integer, character, etc).")
1099
1100 (defvar gnus-summary-dummy-line-format-alist
1101   `((?S gnus-tmp-subject ?s)
1102     (?N gnus-tmp-number ?d)
1103     (?u gnus-tmp-user-defined ?s)))
1104
1105 (defvar gnus-summary-mode-line-format-alist
1106   `((?G gnus-tmp-group-name ?s)
1107     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1108     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1109     (?A gnus-tmp-article-number ?d)
1110     (?Z gnus-tmp-unread-and-unselected ?s)
1111     (?V gnus-version ?s)
1112     (?U gnus-tmp-unread-and-unticked ?d)
1113     (?S gnus-tmp-subject ?s)
1114     (?e gnus-tmp-unselected ?d)
1115     (?u gnus-tmp-user-defined ?s)
1116     (?d (length gnus-newsgroup-dormant) ?d)
1117     (?t (length gnus-newsgroup-marked) ?d)
1118     (?r (length gnus-newsgroup-reads) ?d)
1119     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1120     (?E gnus-newsgroup-expunged-tally ?d)
1121     (?s (gnus-current-score-file-nondirectory) ?s)))
1122
1123 (defvar gnus-last-search-regexp nil
1124   "Default regexp for article search command.")
1125
1126 (defvar gnus-last-shell-command nil
1127   "Default shell command on article.")
1128
1129 (defvar gnus-newsgroup-begin nil)
1130 (defvar gnus-newsgroup-end nil)
1131 (defvar gnus-newsgroup-last-rmail nil)
1132 (defvar gnus-newsgroup-last-mail nil)
1133 (defvar gnus-newsgroup-last-folder nil)
1134 (defvar gnus-newsgroup-last-file nil)
1135 (defvar gnus-newsgroup-auto-expire nil)
1136 (defvar gnus-newsgroup-active nil)
1137
1138 (defvar gnus-newsgroup-data nil)
1139 (defvar gnus-newsgroup-data-reverse nil)
1140 (defvar gnus-newsgroup-limit nil)
1141 (defvar gnus-newsgroup-limits nil)
1142
1143 (defvar gnus-newsgroup-unreads nil
1144   "List of unread articles in the current newsgroup.")
1145
1146 (defvar gnus-newsgroup-unselected nil
1147   "List of unselected unread articles in the current newsgroup.")
1148
1149 (defvar gnus-newsgroup-reads nil
1150   "Alist of read articles and article marks in the current newsgroup.")
1151
1152 (defvar gnus-newsgroup-expunged-tally nil)
1153
1154 (defvar gnus-newsgroup-marked nil
1155   "List of ticked articles in the current newsgroup (a subset of unread art).")
1156
1157 (defvar gnus-newsgroup-killed nil
1158   "List of ranges of articles that have been through the scoring process.")
1159
1160 (defvar gnus-newsgroup-cached nil
1161   "List of articles that come from the article cache.")
1162
1163 (defvar gnus-newsgroup-saved nil
1164   "List of articles that have been saved.")
1165
1166 (defvar gnus-newsgroup-kill-headers nil)
1167
1168 (defvar gnus-newsgroup-replied nil
1169   "List of articles that have been replied to in the current newsgroup.")
1170
1171 (defvar gnus-newsgroup-forwarded nil
1172   "List of articles that have been forwarded in the current newsgroup.")
1173
1174 (defvar gnus-newsgroup-recent nil
1175   "List of articles that have are recent in the current newsgroup.")
1176
1177 (defvar gnus-newsgroup-expirable nil
1178   "List of articles in the current newsgroup that can be expired.")
1179
1180 (defvar gnus-newsgroup-processable nil
1181   "List of articles in the current newsgroup that can be processed.")
1182
1183 (defvar gnus-newsgroup-downloadable nil
1184   "List of articles in the current newsgroup that can be processed.")
1185
1186 (defvar gnus-newsgroup-undownloaded nil
1187   "List of articles in the current newsgroup that haven't been downloaded..")
1188
1189 (defvar gnus-newsgroup-unsendable nil
1190   "List of articles in the current newsgroup that won't be sent.")
1191
1192 (defvar gnus-newsgroup-bookmarks nil
1193   "List of articles in the current newsgroup that have bookmarks.")
1194
1195 (defvar gnus-newsgroup-dormant nil
1196   "List of dormant articles in the current newsgroup.")
1197
1198 (defvar gnus-newsgroup-unseen nil
1199   "List of unseen articles in the current newsgroup.")
1200
1201 (defvar gnus-newsgroup-seen nil
1202   "Range of seen articles in the current newsgroup.")
1203
1204 (defvar gnus-newsgroup-articles nil
1205   "List of articles in the current newsgroup.")
1206
1207 (defvar gnus-newsgroup-scored nil
1208   "List of scored articles in the current newsgroup.")
1209
1210 (defvar gnus-newsgroup-headers nil
1211   "List of article headers in the current newsgroup.")
1212
1213 (defvar gnus-newsgroup-threads nil)
1214
1215 (defvar gnus-newsgroup-prepared nil
1216   "Whether the current group has been prepared properly.")
1217
1218 (defvar gnus-newsgroup-ancient nil
1219   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1220
1221 (defvar gnus-newsgroup-sparse nil)
1222
1223 (defvar gnus-current-article nil)
1224 (defvar gnus-article-current nil)
1225 (defvar gnus-current-headers nil)
1226 (defvar gnus-have-all-headers nil)
1227 (defvar gnus-last-article nil)
1228 (defvar gnus-newsgroup-history nil)
1229 (defvar gnus-newsgroup-charset nil)
1230 (defvar gnus-newsgroup-ephemeral-charset nil)
1231 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1232
1233 (defvar gnus-article-before-search nil)
1234
1235 (defconst gnus-summary-local-variables
1236   '(gnus-newsgroup-name
1237     gnus-newsgroup-begin gnus-newsgroup-end
1238     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1239     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1240     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1241     gnus-newsgroup-unselected gnus-newsgroup-marked
1242     gnus-newsgroup-reads gnus-newsgroup-saved
1243     gnus-newsgroup-replied gnus-newsgroup-forwarded
1244     gnus-newsgroup-recent
1245     gnus-newsgroup-expirable
1246     gnus-newsgroup-processable gnus-newsgroup-killed
1247     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1248     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1249     gnus-newsgroup-seen gnus-newsgroup-articles
1250     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1251     gnus-newsgroup-headers gnus-newsgroup-threads
1252     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1253     gnus-current-article gnus-current-headers gnus-have-all-headers
1254     gnus-last-article gnus-article-internal-prepare-hook
1255     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1256     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1257     gnus-thread-expunge-below
1258     gnus-score-alist gnus-current-score-file
1259     (gnus-summary-expunge-below . global)
1260     (gnus-summary-mark-below . global)
1261     (gnus-orphan-score . global)
1262     gnus-newsgroup-active gnus-scores-exclude-files
1263     gnus-newsgroup-history gnus-newsgroup-ancient
1264     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1265     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1266     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1267     (gnus-newsgroup-expunged-tally . 0)
1268     gnus-cache-removable-articles gnus-newsgroup-cached
1269     gnus-newsgroup-data gnus-newsgroup-data-reverse
1270     gnus-newsgroup-limit gnus-newsgroup-limits
1271     gnus-newsgroup-charset gnus-newsgroup-display)
1272   "Variables that are buffer-local to the summary buffers.")
1273
1274 (defvar gnus-newsgroup-variables nil
1275   "A list of variables that have separate values in different newsgroups.
1276 A list of newsgroup (summary buffer) local variables, or cons of
1277 variables and their default values (when the default values are not
1278 nil), that should be made global while the summary buffer is active.
1279 These variables can be used to set variables in the group parameters
1280 while still allowing them to affect operations done in other
1281 buffers. For example:
1282
1283 \(setq gnus-newsgroup-variables
1284      '(message-use-followup-to
1285        (gnus-visible-headers .
1286          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1287 ")
1288
1289 ;; Byte-compiler warning.
1290 (eval-when-compile (defvar gnus-article-mode-map))
1291
1292 ;; MIME stuff.
1293
1294 (defvar gnus-decode-encoded-word-methods
1295   '(mail-decode-encoded-word-string)
1296   "List of methods used to decode encoded words.
1297
1298 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1299 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1300 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1301 whose names match REGEXP.
1302
1303 For example:
1304 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1305  mail-decode-encoded-word-string
1306  (\"chinese\" . rfc1843-decode-string))")
1307
1308 (defvar gnus-decode-encoded-word-methods-cache nil)
1309
1310 (defun gnus-multi-decode-encoded-word-string (string)
1311   "Apply the functions from `gnus-encoded-word-methods' that match."
1312   (unless (and gnus-decode-encoded-word-methods-cache
1313                (eq gnus-newsgroup-name
1314                    (car gnus-decode-encoded-word-methods-cache)))
1315     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1316     (mapcar (lambda (x)
1317               (if (symbolp x)
1318                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1319                 (if (and gnus-newsgroup-name
1320                          (string-match (car x) gnus-newsgroup-name))
1321                     (nconc gnus-decode-encoded-word-methods-cache
1322                            (list (cdr x))))))
1323             gnus-decode-encoded-word-methods))
1324   (let ((xlist gnus-decode-encoded-word-methods-cache))
1325     (pop xlist)
1326     (while xlist
1327       (setq string (funcall (pop xlist) string))))
1328   string)
1329
1330 ;; Subject simplification.
1331
1332 (defun gnus-simplify-whitespace (str)
1333   "Remove excessive whitespace from STR."
1334   (let ((mystr str))
1335     ;; Multiple spaces.
1336     (while (string-match "[ \t][ \t]+" mystr)
1337       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1338                           " "
1339                           (substring mystr (match-end 0)))))
1340     ;; Leading spaces.
1341     (when (string-match "^[ \t]+" mystr)
1342       (setq mystr (substring mystr (match-end 0))))
1343     ;; Trailing spaces.
1344     (when (string-match "[ \t]+$" mystr)
1345       (setq mystr (substring mystr 0 (match-beginning 0))))
1346     mystr))
1347
1348 (defsubst gnus-simplify-subject-re (subject)
1349   "Remove \"Re:\" from subject lines."
1350   (if (string-match message-subject-re-regexp subject)
1351       (substring subject (match-end 0))
1352     subject))
1353
1354 (defun gnus-simplify-subject (subject &optional re-only)
1355   "Remove `Re:' and words in parentheses.
1356 If RE-ONLY is non-nil, strip leading `Re:'s only."
1357   (let ((case-fold-search t))           ;Ignore case.
1358     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1359     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1360       (setq subject (substring subject (match-end 0))))
1361     ;; Remove uninteresting prefixes.
1362     (when (and (not re-only)
1363                gnus-simplify-ignored-prefixes
1364                (string-match gnus-simplify-ignored-prefixes subject))
1365       (setq subject (substring subject (match-end 0))))
1366     ;; Remove words in parentheses from end.
1367     (unless re-only
1368       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1369         (setq subject (substring subject 0 (match-beginning 0)))))
1370     ;; Return subject string.
1371     subject))
1372
1373 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1374 ;; all whitespace.
1375 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1376   (goto-char (point-min))
1377   (while (re-search-forward regexp nil t)
1378     (replace-match (or newtext ""))))
1379
1380 (defun gnus-simplify-buffer-fuzzy ()
1381   "Simplify string in the buffer fuzzily.
1382 The string in the accessible portion of the current buffer is simplified.
1383 It is assumed to be a single-line subject.
1384 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1385 matter is removed.  Additional things can be deleted by setting
1386 `gnus-simplify-subject-fuzzy-regexp'."
1387   (let ((case-fold-search t)
1388         (modified-tick))
1389     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1390
1391     (while (not (eq modified-tick (buffer-modified-tick)))
1392       (setq modified-tick (buffer-modified-tick))
1393       (cond
1394        ((listp gnus-simplify-subject-fuzzy-regexp)
1395         (mapcar 'gnus-simplify-buffer-fuzzy-step
1396                 gnus-simplify-subject-fuzzy-regexp))
1397        (gnus-simplify-subject-fuzzy-regexp
1398         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1399       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1400       (gnus-simplify-buffer-fuzzy-step
1401        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1402       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1403
1404     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1405     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1406     (gnus-simplify-buffer-fuzzy-step " $")
1407     (gnus-simplify-buffer-fuzzy-step "^ +")))
1408
1409 (defun gnus-simplify-subject-fuzzy (subject)
1410   "Simplify a subject string fuzzily.
1411 See `gnus-simplify-buffer-fuzzy' for details."
1412   (save-excursion
1413     (gnus-set-work-buffer)
1414     (let ((case-fold-search t))
1415       ;; Remove uninteresting prefixes.
1416       (when (and gnus-simplify-ignored-prefixes
1417                  (string-match gnus-simplify-ignored-prefixes subject))
1418         (setq subject (substring subject (match-end 0))))
1419       (insert subject)
1420       (inline (gnus-simplify-buffer-fuzzy))
1421       (buffer-string))))
1422
1423 (defsubst gnus-simplify-subject-fully (subject)
1424   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1425   (cond
1426    (gnus-simplify-subject-functions
1427     (gnus-map-function gnus-simplify-subject-functions subject))
1428    ((null gnus-summary-gather-subject-limit)
1429     (gnus-simplify-subject-re subject))
1430    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1431     (gnus-simplify-subject-fuzzy subject))
1432    ((numberp gnus-summary-gather-subject-limit)
1433     (gnus-limit-string (gnus-simplify-subject-re subject)
1434                        gnus-summary-gather-subject-limit))
1435    (t
1436     subject)))
1437
1438 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1439   "Check whether two subjects are equal.
1440 If optional argument simple-first is t, first argument is already
1441 simplified."
1442   (cond
1443    ((null simple-first)
1444     (equal (gnus-simplify-subject-fully s1)
1445            (gnus-simplify-subject-fully s2)))
1446    (t
1447     (equal s1
1448            (gnus-simplify-subject-fully s2)))))
1449
1450 (defun gnus-summary-bubble-group ()
1451   "Increase the score of the current group.
1452 This is a handy function to add to `gnus-summary-exit-hook' to
1453 increase the score of each group you read."
1454   (gnus-group-add-score gnus-newsgroup-name))
1455
1456 \f
1457 ;;;
1458 ;;; Gnus summary mode
1459 ;;;
1460
1461 (put 'gnus-summary-mode 'mode-class 'special)
1462
1463 (defvar gnus-article-commands-menu)
1464
1465 (when t
1466   ;; Non-orthogonal keys
1467
1468   (gnus-define-keys gnus-summary-mode-map
1469     " " gnus-summary-next-page
1470     "\177" gnus-summary-prev-page
1471     [delete] gnus-summary-prev-page
1472     [backspace] gnus-summary-prev-page
1473     "\r" gnus-summary-scroll-up
1474     "\M-\r" gnus-summary-scroll-down
1475     "n" gnus-summary-next-unread-article
1476     "p" gnus-summary-prev-unread-article
1477     "N" gnus-summary-next-article
1478     "P" gnus-summary-prev-article
1479     "\M-\C-n" gnus-summary-next-same-subject
1480     "\M-\C-p" gnus-summary-prev-same-subject
1481     "\M-n" gnus-summary-next-unread-subject
1482     "\M-p" gnus-summary-prev-unread-subject
1483     "." gnus-summary-first-unread-article
1484     "," gnus-summary-best-unread-article
1485     "\M-s" gnus-summary-search-article-forward
1486     "\M-r" gnus-summary-search-article-backward
1487     "<" gnus-summary-beginning-of-article
1488     ">" gnus-summary-end-of-article
1489     "j" gnus-summary-goto-article
1490     "^" gnus-summary-refer-parent-article
1491     "\M-^" gnus-summary-refer-article
1492     "u" gnus-summary-tick-article-forward
1493     "!" gnus-summary-tick-article-forward
1494     "U" gnus-summary-tick-article-backward
1495     "d" gnus-summary-mark-as-read-forward
1496     "D" gnus-summary-mark-as-read-backward
1497     "E" gnus-summary-mark-as-expirable
1498     "\M-u" gnus-summary-clear-mark-forward
1499     "\M-U" gnus-summary-clear-mark-backward
1500     "k" gnus-summary-kill-same-subject-and-select
1501     "\C-k" gnus-summary-kill-same-subject
1502     "\M-\C-k" gnus-summary-kill-thread
1503     "\M-\C-l" gnus-summary-lower-thread
1504     "e" gnus-summary-edit-article
1505     "#" gnus-summary-mark-as-processable
1506     "\M-#" gnus-summary-unmark-as-processable
1507     "\M-\C-t" gnus-summary-toggle-threads
1508     "\M-\C-s" gnus-summary-show-thread
1509     "\M-\C-h" gnus-summary-hide-thread
1510     "\M-\C-f" gnus-summary-next-thread
1511     "\M-\C-b" gnus-summary-prev-thread
1512     [(meta down)] gnus-summary-next-thread
1513     [(meta up)] gnus-summary-prev-thread
1514     "\M-\C-u" gnus-summary-up-thread
1515     "\M-\C-d" gnus-summary-down-thread
1516     "&" gnus-summary-execute-command
1517     "c" gnus-summary-catchup-and-exit
1518     "\C-w" gnus-summary-mark-region-as-read
1519     "\C-t" gnus-summary-toggle-truncation
1520     "?" gnus-summary-mark-as-dormant
1521     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1522     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1523     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1524     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1525     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1526     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1527     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1528     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1529     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1530     "=" gnus-summary-expand-window
1531     "\C-x\C-s" gnus-summary-reselect-current-group
1532     "\M-g" gnus-summary-rescan-group
1533     "w" gnus-summary-stop-page-breaking
1534     "\C-c\C-r" gnus-summary-caesar-message
1535     "f" gnus-summary-followup
1536     "F" gnus-summary-followup-with-original
1537     "C" gnus-summary-cancel-article
1538     "r" gnus-summary-reply
1539     "R" gnus-summary-reply-with-original
1540     "\C-c\C-f" gnus-summary-mail-forward
1541     "o" gnus-summary-save-article
1542     "\C-o" gnus-summary-save-article-mail
1543     "|" gnus-summary-pipe-output
1544     "\M-k" gnus-summary-edit-local-kill
1545     "\M-K" gnus-summary-edit-global-kill
1546     ;; "V" gnus-version
1547     "\C-c\C-d" gnus-summary-describe-group
1548     "q" gnus-summary-exit
1549     "Q" gnus-summary-exit-no-update
1550     "\C-c\C-i" gnus-info-find-node
1551     gnus-mouse-2 gnus-mouse-pick-article
1552     "m" gnus-summary-mail-other-window
1553     "a" gnus-summary-post-news
1554     "i" gnus-summary-news-other-window
1555     "x" gnus-summary-limit-to-unread
1556     "s" gnus-summary-isearch-article
1557     "t" gnus-summary-toggle-header
1558     "g" gnus-summary-show-article
1559     "l" gnus-summary-goto-last-article
1560     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1561     "\C-d" gnus-summary-enter-digest-group
1562     "\M-\C-d" gnus-summary-read-document
1563     "\M-\C-e" gnus-summary-edit-parameters
1564     "\M-\C-a" gnus-summary-customize-parameters
1565     "\C-c\C-b" gnus-bug
1566     "*" gnus-cache-enter-article
1567     "\M-*" gnus-cache-remove-article
1568     "\M-&" gnus-summary-universal-argument
1569     "\C-l" gnus-recenter
1570     "I" gnus-summary-increase-score
1571     "L" gnus-summary-lower-score
1572     "\M-i" gnus-symbolic-argument
1573     "h" gnus-summary-select-article-buffer
1574
1575     "b" gnus-article-view-part
1576     "\M-t" gnus-summary-toggle-display-buttonized
1577
1578     "V" gnus-summary-score-map
1579     "X" gnus-uu-extract-map
1580     "S" gnus-summary-send-map)
1581
1582   ;; Sort of orthogonal keymap
1583   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1584     "t" gnus-summary-tick-article-forward
1585     "!" gnus-summary-tick-article-forward
1586     "d" gnus-summary-mark-as-read-forward
1587     "r" gnus-summary-mark-as-read-forward
1588     "c" gnus-summary-clear-mark-forward
1589     " " gnus-summary-clear-mark-forward
1590     "e" gnus-summary-mark-as-expirable
1591     "x" gnus-summary-mark-as-expirable
1592     "?" gnus-summary-mark-as-dormant
1593     "b" gnus-summary-set-bookmark
1594     "B" gnus-summary-remove-bookmark
1595     "#" gnus-summary-mark-as-processable
1596     "\M-#" gnus-summary-unmark-as-processable
1597     "S" gnus-summary-limit-include-expunged
1598     "C" gnus-summary-catchup
1599     "H" gnus-summary-catchup-to-here
1600     "h" gnus-summary-catchup-from-here
1601     "\C-c" gnus-summary-catchup-all
1602     "k" gnus-summary-kill-same-subject-and-select
1603     "K" gnus-summary-kill-same-subject
1604     "P" gnus-uu-mark-map)
1605
1606   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1607     "c" gnus-summary-clear-above
1608     "u" gnus-summary-tick-above
1609     "m" gnus-summary-mark-above
1610     "k" gnus-summary-kill-below)
1611
1612   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1613     "/" gnus-summary-limit-to-subject
1614     "n" gnus-summary-limit-to-articles
1615     "w" gnus-summary-pop-limit
1616     "s" gnus-summary-limit-to-subject
1617     "a" gnus-summary-limit-to-author
1618     "u" gnus-summary-limit-to-unread
1619     "m" gnus-summary-limit-to-marks
1620     "M" gnus-summary-limit-exclude-marks
1621     "v" gnus-summary-limit-to-score
1622     "*" gnus-summary-limit-include-cached
1623     "D" gnus-summary-limit-include-dormant
1624     "T" gnus-summary-limit-include-thread
1625     "d" gnus-summary-limit-exclude-dormant
1626     "t" gnus-summary-limit-to-age
1627     "x" gnus-summary-limit-to-extra
1628     "p" gnus-summary-limit-to-display-predicate
1629     "E" gnus-summary-limit-include-expunged
1630     "c" gnus-summary-limit-exclude-childless-dormant
1631     "C" gnus-summary-limit-mark-excluded-as-read
1632     "o" gnus-summary-insert-old-articles
1633     "N" gnus-summary-insert-new-articles)
1634
1635   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1636     "n" gnus-summary-next-unread-article
1637     "p" gnus-summary-prev-unread-article
1638     "N" gnus-summary-next-article
1639     "P" gnus-summary-prev-article
1640     "\C-n" gnus-summary-next-same-subject
1641     "\C-p" gnus-summary-prev-same-subject
1642     "\M-n" gnus-summary-next-unread-subject
1643     "\M-p" gnus-summary-prev-unread-subject
1644     "f" gnus-summary-first-unread-article
1645     "b" gnus-summary-best-unread-article
1646     "j" gnus-summary-goto-article
1647     "g" gnus-summary-goto-subject
1648     "l" gnus-summary-goto-last-article
1649     "o" gnus-summary-pop-article)
1650
1651   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1652     "k" gnus-summary-kill-thread
1653     "l" gnus-summary-lower-thread
1654     "i" gnus-summary-raise-thread
1655     "T" gnus-summary-toggle-threads
1656     "t" gnus-summary-rethread-current
1657     "^" gnus-summary-reparent-thread
1658     "s" gnus-summary-show-thread
1659     "S" gnus-summary-show-all-threads
1660     "h" gnus-summary-hide-thread
1661     "H" gnus-summary-hide-all-threads
1662     "n" gnus-summary-next-thread
1663     "p" gnus-summary-prev-thread
1664     "u" gnus-summary-up-thread
1665     "o" gnus-summary-top-thread
1666     "d" gnus-summary-down-thread
1667     "#" gnus-uu-mark-thread
1668     "\M-#" gnus-uu-unmark-thread)
1669
1670   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1671     "g" gnus-summary-prepare
1672     "c" gnus-summary-insert-cached-articles)
1673
1674   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1675     "c" gnus-summary-catchup-and-exit
1676     "C" gnus-summary-catchup-all-and-exit
1677     "E" gnus-summary-exit-no-update
1678     "Q" gnus-summary-exit
1679     "Z" gnus-summary-exit
1680     "n" gnus-summary-catchup-and-goto-next-group
1681     "R" gnus-summary-reselect-current-group
1682     "G" gnus-summary-rescan-group
1683     "N" gnus-summary-next-group
1684     "s" gnus-summary-save-newsrc
1685     "P" gnus-summary-prev-group)
1686
1687   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1688     " " gnus-summary-next-page
1689     "n" gnus-summary-next-page
1690     "\177" gnus-summary-prev-page
1691     [delete] gnus-summary-prev-page
1692     "p" gnus-summary-prev-page
1693     "\r" gnus-summary-scroll-up
1694     "\M-\r" gnus-summary-scroll-down
1695     "<" gnus-summary-beginning-of-article
1696     ">" gnus-summary-end-of-article
1697     "b" gnus-summary-beginning-of-article
1698     "e" gnus-summary-end-of-article
1699     "^" gnus-summary-refer-parent-article
1700     "r" gnus-summary-refer-parent-article
1701     "D" gnus-summary-enter-digest-group
1702     "R" gnus-summary-refer-references
1703     "T" gnus-summary-refer-thread
1704     "g" gnus-summary-show-article
1705     "s" gnus-summary-isearch-article
1706     "P" gnus-summary-print-article
1707     "M" gnus-mailing-list-insinuate
1708     "t" gnus-article-babel)
1709
1710   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1711     "b" gnus-article-add-buttons
1712     "B" gnus-article-add-buttons-to-head
1713     "o" gnus-article-treat-overstrike
1714     "e" gnus-article-emphasize
1715     "w" gnus-article-fill-cited-article
1716     "Q" gnus-article-fill-long-lines
1717     "C" gnus-article-capitalize-sentences
1718     "c" gnus-article-remove-cr
1719     "q" gnus-article-de-quoted-unreadable
1720     "6" gnus-article-de-base64-unreadable
1721     "Z" gnus-article-decode-HZ
1722     "h" gnus-article-wash-html
1723     "s" gnus-summary-force-verify-and-decrypt
1724     "f" gnus-article-display-x-face
1725     "l" gnus-summary-stop-page-breaking
1726     "r" gnus-summary-caesar-message
1727     "t" gnus-summary-toggle-header
1728     "g" gnus-summary-toggle-smiley
1729     "u" gnus-article-treat-unfold-headers
1730     "n" gnus-article-treat-fold-newsgroups
1731     "v" gnus-summary-verbose-headers
1732     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1733     "p" gnus-article-verify-x-pgp-sig
1734     "d" gnus-article-treat-dumbquotes)
1735
1736   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1737     "a" gnus-article-hide
1738     "h" gnus-article-hide-headers
1739     "b" gnus-article-hide-boring-headers
1740     "s" gnus-article-hide-signature
1741     "c" gnus-article-hide-citation
1742     "C" gnus-article-hide-citation-in-followups
1743     "l" gnus-article-hide-list-identifiers
1744     "p" gnus-article-hide-pgp
1745     "B" gnus-article-strip-banner
1746     "P" gnus-article-hide-pem
1747     "\C-c" gnus-article-hide-citation-maybe)
1748
1749   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1750     "a" gnus-article-highlight
1751     "h" gnus-article-highlight-headers
1752     "c" gnus-article-highlight-citation
1753     "s" gnus-article-highlight-signature)
1754
1755   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1756     "x" gnus-article-display-x-face
1757     "s" gnus-summary-toggle-smiley
1758     "f" gnus-treat-from-picon
1759     "m" gnus-treat-mail-picon
1760     "n" gnus-treat-newsgroups-picon)
1761
1762   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1763     "w" gnus-article-decode-mime-words
1764     "c" gnus-article-decode-charset
1765     "v" gnus-mime-view-all-parts
1766     "b" gnus-article-view-part)
1767
1768   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1769     "z" gnus-article-date-ut
1770     "u" gnus-article-date-ut
1771     "l" gnus-article-date-local
1772     "p" gnus-article-date-english
1773     "e" gnus-article-date-lapsed
1774     "o" gnus-article-date-original
1775     "i" gnus-article-date-iso8601
1776     "s" gnus-article-date-user)
1777
1778   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1779     "t" gnus-article-remove-trailing-blank-lines
1780     "l" gnus-article-strip-leading-blank-lines
1781     "m" gnus-article-strip-multiple-blank-lines
1782     "a" gnus-article-strip-blank-lines
1783     "A" gnus-article-strip-all-blank-lines
1784     "s" gnus-article-strip-leading-space
1785     "e" gnus-article-strip-trailing-space
1786     "w" gnus-article-remove-leading-whitespace)
1787
1788   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1789     "v" gnus-version
1790     "f" gnus-summary-fetch-faq
1791     "d" gnus-summary-describe-group
1792     "h" gnus-summary-describe-briefly
1793     "i" gnus-info-find-node)
1794
1795   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1796     "e" gnus-summary-expire-articles
1797     "\M-\C-e" gnus-summary-expire-articles-now
1798     "\177" gnus-summary-delete-article
1799     [delete] gnus-summary-delete-article
1800     [backspace] gnus-summary-delete-article
1801     "m" gnus-summary-move-article
1802     "r" gnus-summary-respool-article
1803     "w" gnus-summary-edit-article
1804     "c" gnus-summary-copy-article
1805     "B" gnus-summary-crosspost-article
1806     "q" gnus-summary-respool-query
1807     "t" gnus-summary-respool-trace
1808     "i" gnus-summary-import-article
1809     "I" gnus-summary-create-article
1810     "p" gnus-summary-article-posted-p)
1811
1812   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1813     "o" gnus-summary-save-article
1814     "m" gnus-summary-save-article-mail
1815     "F" gnus-summary-write-article-file
1816     "r" gnus-summary-save-article-rmail
1817     "f" gnus-summary-save-article-file
1818     "b" gnus-summary-save-article-body-file
1819     "h" gnus-summary-save-article-folder
1820     "v" gnus-summary-save-article-vm
1821     "p" gnus-summary-pipe-output
1822     "P" gnus-summary-muttprint
1823     "s" gnus-soup-add-article)
1824
1825   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1826     "b" gnus-summary-display-buttonized
1827     "m" gnus-summary-repair-multipart
1828     "v" gnus-article-view-part
1829     "o" gnus-article-save-part
1830     "c" gnus-article-copy-part
1831     "C" gnus-article-view-part-as-charset
1832     "e" gnus-article-externalize-part
1833     "E" gnus-article-encrypt-body
1834     "i" gnus-article-inline-part
1835     "|" gnus-article-pipe-part))
1836
1837 (defvar gnus-article-post-menu nil)
1838
1839 (defun gnus-summary-make-menu-bar ()
1840   (gnus-turn-off-edit-menu 'summary)
1841
1842   (unless (boundp 'gnus-summary-misc-menu)
1843
1844     (easy-menu-define
1845       gnus-summary-kill-menu gnus-summary-mode-map ""
1846       (cons
1847        "Score"
1848        (nconc
1849         (list
1850          ["Customize" gnus-score-customize t])
1851         (gnus-make-score-map 'increase)
1852         (gnus-make-score-map 'lower)
1853         '(("Mark"
1854            ["Kill below" gnus-summary-kill-below t]
1855            ["Mark above" gnus-summary-mark-above t]
1856            ["Tick above" gnus-summary-tick-above t]
1857            ["Clear above" gnus-summary-clear-above t])
1858           ["Current score" gnus-summary-current-score t]
1859           ["Set score" gnus-summary-set-score t]
1860           ["Switch current score file..." gnus-score-change-score-file t]
1861           ["Set mark below..." gnus-score-set-mark-below t]
1862           ["Set expunge below..." gnus-score-set-expunge-below t]
1863           ["Edit current score file" gnus-score-edit-current-scores t]
1864           ["Edit score file" gnus-score-edit-file t]
1865           ["Trace score" gnus-score-find-trace t]
1866           ["Find words" gnus-score-find-favourite-words t]
1867           ["Rescore buffer" gnus-summary-rescore t]
1868           ["Increase score..." gnus-summary-increase-score t]
1869           ["Lower score..." gnus-summary-lower-score t]))))
1870
1871     ;; Define both the Article menu in the summary buffer and the
1872     ;; equivalent Commands menu in the article buffer here for
1873     ;; consistency.
1874     (let ((innards
1875            `(("Hide"
1876               ["All" gnus-article-hide t]
1877               ["Headers" gnus-article-hide-headers t]
1878               ["Signature" gnus-article-hide-signature t]
1879               ["Citation" gnus-article-hide-citation t]
1880               ["List identifiers" gnus-article-hide-list-identifiers t]
1881               ["PGP" gnus-article-hide-pgp t]
1882               ["Banner" gnus-article-strip-banner t]
1883               ["Boring headers" gnus-article-hide-boring-headers t])
1884              ("Highlight"
1885               ["All" gnus-article-highlight t]
1886               ["Headers" gnus-article-highlight-headers t]
1887               ["Signature" gnus-article-highlight-signature t]
1888               ["Citation" gnus-article-highlight-citation t])
1889              ("MIME"
1890               ["Words" gnus-article-decode-mime-words t]
1891               ["Charset" gnus-article-decode-charset t]
1892               ["QP" gnus-article-de-quoted-unreadable t]
1893               ["Base64" gnus-article-de-base64-unreadable t]
1894               ["View all" gnus-mime-view-all-parts t]
1895               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1896               ["Encrypt body" gnus-article-encrypt-body t])
1897              ("Date"
1898               ["Local" gnus-article-date-local t]
1899               ["ISO8601" gnus-article-date-iso8601 t]
1900               ["UT" gnus-article-date-ut t]
1901               ["Original" gnus-article-date-original t]
1902               ["Lapsed" gnus-article-date-lapsed t]
1903               ["User-defined" gnus-article-date-user t])
1904              ("Display"
1905               ["Toggle smiley" gnus-summary-toggle-smiley t]
1906               ["Show X-Face" gnus-article-display-x-face t]
1907               ["Show picons in From" gnus-treat-from-picon t]
1908               ["Show picons in mail headers" gnus-treat-mail-picon t]
1909               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1910              ("Washing"
1911               ("Remove Blanks"
1912                ["Leading" gnus-article-strip-leading-blank-lines t]
1913                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1914                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1915                ["All of the above" gnus-article-strip-blank-lines t]
1916                ["All" gnus-article-strip-all-blank-lines t]
1917                ["Leading space" gnus-article-strip-leading-space t]
1918                ["Trailing space" gnus-article-strip-trailing-space t]
1919                ["Leading space in headers"
1920                 gnus-article-remove-leading-whitespace t])
1921               ["Overstrike" gnus-article-treat-overstrike t]
1922               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1923               ["Emphasis" gnus-article-emphasize t]
1924               ["Word wrap" gnus-article-fill-cited-article t]
1925               ["Fill long lines" gnus-article-fill-long-lines t]
1926               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1927               ["CR" gnus-article-remove-cr t]
1928               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1929               ["Base64" gnus-article-de-base64-unreadable t]
1930               ["Rot 13" gnus-summary-caesar-message
1931                ,@(if (featurep 'xemacs) '(t)
1932                    '(:help "\"Caesar rotate\" article by 13"))]
1933               ["Unix pipe" gnus-summary-pipe-message t]
1934               ["Add buttons" gnus-article-add-buttons t]
1935               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1936               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1937               ["Verbose header" gnus-summary-verbose-headers t]
1938               ["Toggle header" gnus-summary-toggle-header t]
1939               ["Unfold headers" gnus-article-treat-unfold-headers t]
1940               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1941               ["Html" gnus-article-wash-html t]
1942               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1943               ["HZ" gnus-article-decode-HZ t])
1944              ("Output"
1945               ["Save in default format" gnus-summary-save-article
1946                ,@(if (featurep 'xemacs) '(t)
1947                    '(:help "Save article using default method"))]
1948               ["Save in file" gnus-summary-save-article-file
1949                ,@(if (featurep 'xemacs) '(t)
1950                    '(:help "Save article in file"))]
1951               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1952               ["Save in MH folder" gnus-summary-save-article-folder t]
1953               ["Save in VM folder" gnus-summary-save-article-vm t]
1954               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1955               ["Save body in file" gnus-summary-save-article-body-file t]
1956               ["Pipe through a filter" gnus-summary-pipe-output t]
1957               ["Add to SOUP packet" gnus-soup-add-article t]
1958               ["Print with Muttprint" gnus-summary-muttprint t]
1959               ["Print" gnus-summary-print-article t])
1960              ("Backend"
1961               ["Respool article..." gnus-summary-respool-article t]
1962               ["Move article..." gnus-summary-move-article
1963                (gnus-check-backend-function
1964                 'request-move-article gnus-newsgroup-name)]
1965               ["Copy article..." gnus-summary-copy-article t]
1966               ["Crosspost article..." gnus-summary-crosspost-article
1967                (gnus-check-backend-function
1968                 'request-replace-article gnus-newsgroup-name)]
1969               ["Import file..." gnus-summary-import-article t]
1970               ["Create article..." gnus-summary-create-article t]
1971               ["Check if posted" gnus-summary-article-posted-p t]
1972               ["Edit article" gnus-summary-edit-article
1973                (not (gnus-group-read-only-p))]
1974               ["Delete article" gnus-summary-delete-article
1975                (gnus-check-backend-function
1976                 'request-expire-articles gnus-newsgroup-name)]
1977               ["Query respool" gnus-summary-respool-query t]
1978               ["Trace respool" gnus-summary-respool-trace t]
1979               ["Delete expirable articles" gnus-summary-expire-articles-now
1980                (gnus-check-backend-function
1981                 'request-expire-articles gnus-newsgroup-name)])
1982              ("Extract"
1983               ["Uudecode" gnus-uu-decode-uu
1984                ,@(if (featurep 'xemacs) '(t)
1985                    '(:help "Decode uuencoded article(s)"))]
1986               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1987               ["Unshar" gnus-uu-decode-unshar t]
1988               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1989               ["Save" gnus-uu-decode-save t]
1990               ["Binhex" gnus-uu-decode-binhex t]
1991               ["Postscript" gnus-uu-decode-postscript t])
1992              ("Cache"
1993               ["Enter article" gnus-cache-enter-article t]
1994               ["Remove article" gnus-cache-remove-article t])
1995              ["Translate" gnus-article-babel t]
1996              ["Select article buffer" gnus-summary-select-article-buffer t]
1997              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1998              ["Isearch article..." gnus-summary-isearch-article t]
1999              ["Beginning of the article" gnus-summary-beginning-of-article t]
2000              ["End of the article" gnus-summary-end-of-article t]
2001              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2002              ["Fetch referenced articles" gnus-summary-refer-references t]
2003              ["Fetch current thread" gnus-summary-refer-thread t]
2004              ["Fetch article with id..." gnus-summary-refer-article t]
2005              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2006              ["Redisplay" gnus-summary-show-article t]
2007              ["Raw article" gnus-summary-show-raw-article t])))
2008       (easy-menu-define
2009         gnus-summary-article-menu gnus-summary-mode-map ""
2010         (cons "Article" innards))
2011
2012       (if (not (keymapp gnus-summary-article-menu))
2013           (easy-menu-define
2014             gnus-article-commands-menu gnus-article-mode-map ""
2015             (cons "Commands" innards))
2016         ;; in Emacs, don't share menu.
2017         (setq gnus-article-commands-menu
2018               (copy-keymap gnus-summary-article-menu))
2019         (define-key gnus-article-mode-map [menu-bar commands]
2020           (cons "Commands" gnus-article-commands-menu))))
2021
2022     (easy-menu-define
2023       gnus-summary-thread-menu gnus-summary-mode-map ""
2024       '("Threads"
2025         ["Toggle threading" gnus-summary-toggle-threads t]
2026         ["Hide threads" gnus-summary-hide-all-threads t]
2027         ["Show threads" gnus-summary-show-all-threads t]
2028         ["Hide thread" gnus-summary-hide-thread t]
2029         ["Show thread" gnus-summary-show-thread t]
2030         ["Go to next thread" gnus-summary-next-thread t]
2031         ["Go to previous thread" gnus-summary-prev-thread t]
2032         ["Go down thread" gnus-summary-down-thread t]
2033         ["Go up thread" gnus-summary-up-thread t]
2034         ["Top of thread" gnus-summary-top-thread t]
2035         ["Mark thread as read" gnus-summary-kill-thread t]
2036         ["Lower thread score" gnus-summary-lower-thread t]
2037         ["Raise thread score" gnus-summary-raise-thread t]
2038         ["Rethread current" gnus-summary-rethread-current t]))
2039
2040     (easy-menu-define
2041       gnus-summary-post-menu gnus-summary-mode-map ""
2042       `("Post"
2043         ["Send a message (mail or news)" gnus-summary-post-news
2044          ,@(if (featurep 'xemacs) '(t)
2045              '(:help "Post an article"))]
2046         ["Followup" gnus-summary-followup
2047          ,@(if (featurep 'xemacs) '(t)
2048              '(:help "Post followup to this article"))]
2049         ["Followup and yank" gnus-summary-followup-with-original
2050          ,@(if (featurep 'xemacs) '(t)
2051              '(:help "Post followup to this article, quoting its contents"))]
2052         ["Supersede article" gnus-summary-supersede-article t]
2053         ["Cancel article" gnus-summary-cancel-article
2054          ,@(if (featurep 'xemacs) '(t)
2055              '(:help "Cancel an article you posted"))]
2056         ["Reply" gnus-summary-reply t]
2057         ["Reply and yank" gnus-summary-reply-with-original t]
2058         ["Wide reply" gnus-summary-wide-reply t]
2059         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2060          ,@(if (featurep 'xemacs) '(t)
2061              '(:help "Mail a reply, quoting this article"))]
2062         ["Mail forward" gnus-summary-mail-forward t]
2063         ["Post forward" gnus-summary-post-forward t]
2064         ["Digest and mail" gnus-uu-digest-mail-forward t]
2065         ["Digest and post" gnus-uu-digest-post-forward t]
2066         ["Resend message" gnus-summary-resend-message t]
2067         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2068         ["Send a mail" gnus-summary-mail-other-window t]
2069         ["Create a local message" gnus-summary-news-other-window t]
2070         ["Uuencode and post" gnus-uu-post-news
2071          ,@(if (featurep 'xemacs) '(t)
2072              '(:help "Post a uuencoded article"))]
2073         ["Followup via news" gnus-summary-followup-to-mail t]
2074         ["Followup via news and yank"
2075          gnus-summary-followup-to-mail-with-original t]
2076         ;;("Draft"
2077         ;;["Send" gnus-summary-send-draft t]
2078         ;;["Send bounced" gnus-resend-bounced-mail t])
2079         ))
2080
2081     (cond
2082      ((not (keymapp gnus-summary-post-menu))
2083       (setq gnus-article-post-menu gnus-summary-post-menu))
2084      ((not gnus-article-post-menu)
2085       ;; Don't share post menu.
2086       (setq gnus-article-post-menu
2087             (copy-keymap gnus-summary-post-menu))))
2088     (define-key gnus-article-mode-map [menu-bar post]
2089       (cons "Post" gnus-article-post-menu))
2090
2091     (easy-menu-define
2092       gnus-summary-misc-menu gnus-summary-mode-map ""
2093       `("Gnus"
2094         ("Mark Read"
2095          ["Mark as read" gnus-summary-mark-as-read-forward t]
2096          ["Mark same subject and select"
2097           gnus-summary-kill-same-subject-and-select t]
2098          ["Mark same subject" gnus-summary-kill-same-subject t]
2099          ["Catchup" gnus-summary-catchup
2100           ,@(if (featurep 'xemacs) '(t)
2101               '(:help "Mark unread articles in this group as read"))]
2102          ["Catchup all" gnus-summary-catchup-all t]
2103          ["Catchup to here" gnus-summary-catchup-to-here t]
2104          ["Catchup from here" gnus-summary-catchup-from-here t]
2105          ["Catchup region" gnus-summary-mark-region-as-read t]
2106          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2107         ("Mark Various"
2108          ["Tick" gnus-summary-tick-article-forward t]
2109          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2110          ["Remove marks" gnus-summary-clear-mark-forward t]
2111          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2112          ["Set bookmark" gnus-summary-set-bookmark t]
2113          ["Remove bookmark" gnus-summary-remove-bookmark t])
2114         ("Limit to"
2115          ["Marks..." gnus-summary-limit-to-marks t]
2116          ["Subject..." gnus-summary-limit-to-subject t]
2117          ["Author..." gnus-summary-limit-to-author t]
2118          ["Age..." gnus-summary-limit-to-age t]
2119          ["Extra..." gnus-summary-limit-to-extra t]
2120          ["Score" gnus-summary-limit-to-score t]
2121          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2122          ["Unread" gnus-summary-limit-to-unread t]
2123          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2124          ["Articles" gnus-summary-limit-to-articles t]
2125          ["Pop limit" gnus-summary-pop-limit t]
2126          ["Show dormant" gnus-summary-limit-include-dormant t]
2127          ["Hide childless dormant"
2128           gnus-summary-limit-exclude-childless-dormant t]
2129          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2130          ["Hide marked" gnus-summary-limit-exclude-marks t]
2131          ["Show expunged" gnus-summary-limit-include-expunged t])
2132         ("Process Mark"
2133          ["Set mark" gnus-summary-mark-as-processable t]
2134          ["Remove mark" gnus-summary-unmark-as-processable t]
2135          ["Remove all marks" gnus-summary-unmark-all-processable t]
2136          ["Mark above" gnus-uu-mark-over t]
2137          ["Mark series" gnus-uu-mark-series t]
2138          ["Mark region" gnus-uu-mark-region t]
2139          ["Unmark region" gnus-uu-unmark-region t]
2140          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2141          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2142          ["Mark all" gnus-uu-mark-all t]
2143          ["Mark buffer" gnus-uu-mark-buffer t]
2144          ["Mark sparse" gnus-uu-mark-sparse t]
2145          ["Mark thread" gnus-uu-mark-thread t]
2146          ["Unmark thread" gnus-uu-unmark-thread t]
2147          ("Process Mark Sets"
2148           ["Kill" gnus-summary-kill-process-mark t]
2149           ["Yank" gnus-summary-yank-process-mark
2150            gnus-newsgroup-process-stack]
2151           ["Save" gnus-summary-save-process-mark t]))
2152         ("Scroll article"
2153          ["Page forward" gnus-summary-next-page
2154           ,@(if (featurep 'xemacs) '(t)
2155               '(:help "Show next page of article"))]
2156          ["Page backward" gnus-summary-prev-page
2157           ,@(if (featurep 'xemacs) '(t)
2158               '(:help "Show previous page of article"))]
2159          ["Line forward" gnus-summary-scroll-up t])
2160         ("Move"
2161          ["Next unread article" gnus-summary-next-unread-article t]
2162          ["Previous unread article" gnus-summary-prev-unread-article t]
2163          ["Next article" gnus-summary-next-article t]
2164          ["Previous article" gnus-summary-prev-article t]
2165          ["Next unread subject" gnus-summary-next-unread-subject t]
2166          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2167          ["Next article same subject" gnus-summary-next-same-subject t]
2168          ["Previous article same subject" gnus-summary-prev-same-subject t]
2169          ["First unread article" gnus-summary-first-unread-article t]
2170          ["Best unread article" gnus-summary-best-unread-article t]
2171          ["Go to subject number..." gnus-summary-goto-subject t]
2172          ["Go to article number..." gnus-summary-goto-article t]
2173          ["Go to the last article" gnus-summary-goto-last-article t]
2174          ["Pop article off history" gnus-summary-pop-article t])
2175         ("Sort"
2176          ["Sort by number" gnus-summary-sort-by-number t]
2177          ["Sort by author" gnus-summary-sort-by-author t]
2178          ["Sort by subject" gnus-summary-sort-by-subject t]
2179          ["Sort by date" gnus-summary-sort-by-date t]
2180          ["Sort by score" gnus-summary-sort-by-score t]
2181          ["Sort by lines" gnus-summary-sort-by-lines t]
2182          ["Sort by characters" gnus-summary-sort-by-chars t]
2183          ["Original sort" gnus-summary-sort-by-original t])
2184         ("Help"
2185          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2186          ["Describe group" gnus-summary-describe-group t]
2187          ["Read manual" gnus-info-find-node t])
2188         ("Modes"
2189          ["Pick and read" gnus-pick-mode t]
2190          ["Binary" gnus-binary-mode t])
2191         ("Regeneration"
2192          ["Regenerate" gnus-summary-prepare t]
2193          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2194          ["Toggle threading" gnus-summary-toggle-threads t])
2195         ["See old articles" gnus-summary-insert-old-articles t]
2196         ["See new articles" gnus-summary-insert-new-articles t]
2197         ["Filter articles..." gnus-summary-execute-command t]
2198         ["Run command on subjects..." gnus-summary-universal-argument t]
2199         ["Search articles forward..." gnus-summary-search-article-forward t]
2200         ["Search articles backward..." gnus-summary-search-article-backward t]
2201         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2202         ["Expand window" gnus-summary-expand-window t]
2203         ["Expire expirable articles" gnus-summary-expire-articles
2204          (gnus-check-backend-function
2205           'request-expire-articles gnus-newsgroup-name)]
2206         ["Edit local kill file" gnus-summary-edit-local-kill t]
2207         ["Edit main kill file" gnus-summary-edit-global-kill t]
2208         ["Edit group parameters" gnus-summary-edit-parameters t]
2209         ["Customize group parameters" gnus-summary-customize-parameters t]
2210         ["Send a bug report" gnus-bug t]
2211         ("Exit"
2212          ["Catchup and exit" gnus-summary-catchup-and-exit
2213           ,@(if (featurep 'xemacs) '(t)
2214               '(:help "Mark unread articles in this group as read, then exit"))]
2215          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2216          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2217          ["Exit group" gnus-summary-exit
2218           ,@(if (featurep 'xemacs) '(t)
2219               '(:help "Exit current group, return to group selection mode"))]
2220          ["Exit group without updating" gnus-summary-exit-no-update t]
2221          ["Exit and goto next group" gnus-summary-next-group t]
2222          ["Exit and goto prev group" gnus-summary-prev-group t]
2223          ["Reselect group" gnus-summary-reselect-current-group t]
2224          ["Rescan group" gnus-summary-rescan-group t]
2225          ["Update dribble" gnus-summary-save-newsrc t])))
2226
2227     (gnus-run-hooks 'gnus-summary-menu-hook)))
2228
2229 (defvar gnus-summary-tool-bar-map nil)
2230
2231 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2232 (defun gnus-summary-make-tool-bar ()
2233   (if (and (fboundp 'tool-bar-add-item-from-menu)
2234            (default-value 'tool-bar-mode)
2235            (not gnus-summary-tool-bar-map))
2236       (setq gnus-summary-tool-bar-map
2237             (let ((tool-bar-map (make-sparse-keymap))
2238                   (load-path (mm-image-load-path)))
2239               (tool-bar-add-item-from-menu
2240                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2241               (tool-bar-add-item-from-menu
2242                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2243               (tool-bar-add-item-from-menu
2244                'gnus-summary-post-news "post" gnus-summary-mode-map)
2245               (tool-bar-add-item-from-menu
2246                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2247               (tool-bar-add-item-from-menu
2248                'gnus-summary-followup "followup" gnus-summary-mode-map)
2249               (tool-bar-add-item-from-menu
2250                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2251               (tool-bar-add-item-from-menu
2252                'gnus-summary-reply "reply" gnus-summary-mode-map)
2253               (tool-bar-add-item-from-menu
2254                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2255               (tool-bar-add-item-from-menu
2256                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2257               (tool-bar-add-item-from-menu
2258                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2259               (tool-bar-add-item-from-menu
2260                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2261               (tool-bar-add-item-from-menu
2262                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2263               (tool-bar-add-item-from-menu
2264                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2265               (tool-bar-add-item-from-menu
2266                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2267               (tool-bar-add-item-from-menu
2268                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2269               tool-bar-map)))
2270   (if gnus-summary-tool-bar-map
2271       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2272
2273 (defun gnus-score-set-default (var value)
2274   "A version of set that updates the GNU Emacs menu-bar."
2275   (set var value)
2276   ;; It is the message that forces the active status to be updated.
2277   (message ""))
2278
2279 (defun gnus-make-score-map (type)
2280   "Make a summary score map of type TYPE."
2281   (if t
2282       nil
2283     (let ((headers '(("author" "from" string)
2284                      ("subject" "subject" string)
2285                      ("article body" "body" string)
2286                      ("article head" "head" string)
2287                      ("xref" "xref" string)
2288                      ("extra header" "extra" string)
2289                      ("lines" "lines" number)
2290                      ("followups to author" "followup" string)))
2291           (types '((number ("less than" <)
2292                            ("greater than" >)
2293                            ("equal" =))
2294                    (string ("substring" s)
2295                            ("exact string" e)
2296                            ("fuzzy string" f)
2297                            ("regexp" r))))
2298           (perms '(("temporary" (current-time-string))
2299                    ("permanent" nil)
2300                    ("immediate" now)))
2301           header)
2302       (list
2303        (apply
2304         'nconc
2305         (list
2306          (if (eq type 'lower)
2307              "Lower score"
2308            "Increase score"))
2309         (let (outh)
2310           (while headers
2311             (setq header (car headers))
2312             (setq outh
2313                   (cons
2314                    (apply
2315                     'nconc
2316                     (list (car header))
2317                     (let ((ts (cdr (assoc (nth 2 header) types)))
2318                           outt)
2319                       (while ts
2320                         (setq outt
2321                               (cons
2322                                (apply
2323                                 'nconc
2324                                 (list (caar ts))
2325                                 (let ((ps perms)
2326                                       outp)
2327                                   (while ps
2328                                     (setq outp
2329                                           (cons
2330                                            (vector
2331                                             (caar ps)
2332                                             (list
2333                                              'gnus-summary-score-entry
2334                                              (nth 1 header)
2335                                              (if (or (string= (nth 1 header)
2336                                                               "head")
2337                                                      (string= (nth 1 header)
2338                                                               "body"))
2339                                                  ""
2340                                                (list 'gnus-summary-header
2341                                                      (nth 1 header)))
2342                                              (list 'quote (nth 1 (car ts)))
2343                                              (list 'gnus-score-delta-default
2344                                                    nil)
2345                                              (nth 1 (car ps))
2346                                              t)
2347                                             t)
2348                                            outp))
2349                                     (setq ps (cdr ps)))
2350                                   (list (nreverse outp))))
2351                                outt))
2352                         (setq ts (cdr ts)))
2353                       (list (nreverse outt))))
2354                    outh))
2355             (setq headers (cdr headers)))
2356           (list (nreverse outh))))))))
2357
2358 \f
2359
2360 (defun gnus-summary-mode (&optional group)
2361   "Major mode for reading articles.
2362
2363 All normal editing commands are switched off.
2364 \\<gnus-summary-mode-map>
2365 Each line in this buffer represents one article.  To read an
2366 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2367 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2368 respectively.
2369
2370 You can also post articles and send mail from this buffer.  To
2371 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2372 of an article, type `\\[gnus-summary-reply]'.
2373
2374 There are approx. one gazillion commands you can execute in this
2375 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2376
2377 The following commands are available:
2378
2379 \\{gnus-summary-mode-map}"
2380   (interactive)
2381   (kill-all-local-variables)
2382   (when (gnus-visual-p 'summary-menu 'menu)
2383     (gnus-summary-make-menu-bar)
2384     (gnus-summary-make-tool-bar))
2385   (gnus-summary-make-local-variables)
2386   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2387     (gnus-summary-make-local-variables))
2388   (gnus-make-thread-indent-array)
2389   (gnus-simplify-mode-line)
2390   (setq major-mode 'gnus-summary-mode)
2391   (setq mode-name "Summary")
2392   (make-local-variable 'minor-mode-alist)
2393   (use-local-map gnus-summary-mode-map)
2394   (buffer-disable-undo)
2395   (setq buffer-read-only t)             ;Disable modification
2396   (setq truncate-lines t)
2397   (setq selective-display t)
2398   (setq selective-display-ellipses t)   ;Display `...'
2399   (gnus-summary-set-display-table)
2400   (gnus-set-default-directory)
2401   (setq gnus-newsgroup-name group)
2402   (make-local-variable 'gnus-summary-line-format)
2403   (make-local-variable 'gnus-summary-line-format-spec)
2404   (make-local-variable 'gnus-summary-dummy-line-format)
2405   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2406   (make-local-variable 'gnus-summary-mark-positions)
2407   (make-local-hook 'pre-command-hook)
2408   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2409   (gnus-run-hooks 'gnus-summary-mode-hook)
2410   (turn-on-gnus-mailing-list-mode)
2411   (mm-enable-multibyte-mule4)
2412   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2413   (gnus-update-summary-mark-positions))
2414
2415 (defun gnus-summary-make-local-variables ()
2416   "Make all the local summary buffer variables."
2417   (let (global)
2418     (dolist (local gnus-summary-local-variables)
2419       (if (consp local)
2420           (progn
2421             (if (eq (cdr local) 'global)
2422                 ;; Copy the global value of the variable.
2423                 (setq global (symbol-value (car local)))
2424               ;; Use the value from the list.
2425               (setq global (eval (cdr local))))
2426             (set (make-local-variable (car local)) global))
2427         ;; Simple nil-valued local variable.
2428         (set (make-local-variable local) nil)))))
2429
2430 (defun gnus-summary-clear-local-variables ()
2431   (let ((locals gnus-summary-local-variables))
2432     (while locals
2433       (if (consp (car locals))
2434           (and (vectorp (caar locals))
2435                (set (caar locals) nil))
2436         (and (vectorp (car locals))
2437              (set (car locals) nil)))
2438       (setq locals (cdr locals)))))
2439
2440 ;; Summary data functions.
2441
2442 (defmacro gnus-data-number (data)
2443   `(car ,data))
2444
2445 (defmacro gnus-data-set-number (data number)
2446   `(setcar ,data ,number))
2447
2448 (defmacro gnus-data-mark (data)
2449   `(nth 1 ,data))
2450
2451 (defmacro gnus-data-set-mark (data mark)
2452   `(setcar (nthcdr 1 ,data) ,mark))
2453
2454 (defmacro gnus-data-pos (data)
2455   `(nth 2 ,data))
2456
2457 (defmacro gnus-data-set-pos (data pos)
2458   `(setcar (nthcdr 2 ,data) ,pos))
2459
2460 (defmacro gnus-data-header (data)
2461   `(nth 3 ,data))
2462
2463 (defmacro gnus-data-set-header (data header)
2464   `(setf (nth 3 ,data) ,header))
2465
2466 (defmacro gnus-data-level (data)
2467   `(nth 4 ,data))
2468
2469 (defmacro gnus-data-unread-p (data)
2470   `(= (nth 1 ,data) gnus-unread-mark))
2471
2472 (defmacro gnus-data-read-p (data)
2473   `(/= (nth 1 ,data) gnus-unread-mark))
2474
2475 (defmacro gnus-data-pseudo-p (data)
2476   `(consp (nth 3 ,data)))
2477
2478 (defmacro gnus-data-find (number)
2479   `(assq ,number gnus-newsgroup-data))
2480
2481 (defmacro gnus-data-find-list (number &optional data)
2482   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2483      (memq (assq ,number bdata)
2484            bdata)))
2485
2486 (defmacro gnus-data-make (number mark pos header level)
2487   `(list ,number ,mark ,pos ,header ,level))
2488
2489 (defun gnus-data-enter (after-article number mark pos header level offset)
2490   (let ((data (gnus-data-find-list after-article)))
2491     (unless data
2492       (error "No such article: %d" after-article))
2493     (setcdr data (cons (gnus-data-make number mark pos header level)
2494                        (cdr data)))
2495     (setq gnus-newsgroup-data-reverse nil)
2496     (gnus-data-update-list (cddr data) offset)))
2497
2498 (defun gnus-data-enter-list (after-article list &optional offset)
2499   (when list
2500     (let ((data (and after-article (gnus-data-find-list after-article)))
2501           (ilist list))
2502       (if (not (or data
2503                    after-article))
2504           (let ((odata gnus-newsgroup-data))
2505             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2506             (when offset
2507               (gnus-data-update-list odata offset)))
2508       ;; Find the last element in the list to be spliced into the main
2509         ;; list.
2510         (while (cdr list)
2511           (setq list (cdr list)))
2512         (if (not data)
2513             (progn
2514               (setcdr list gnus-newsgroup-data)
2515               (setq gnus-newsgroup-data ilist)
2516               (when offset
2517                 (gnus-data-update-list (cdr list) offset)))
2518           (setcdr list (cdr data))
2519           (setcdr data ilist)
2520           (when offset
2521             (gnus-data-update-list (cdr list) offset))))
2522       (setq gnus-newsgroup-data-reverse nil))))
2523
2524 (defun gnus-data-remove (article &optional offset)
2525   (let ((data gnus-newsgroup-data))
2526     (if (= (gnus-data-number (car data)) article)
2527         (progn
2528           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2529                 gnus-newsgroup-data-reverse nil)
2530           (when offset
2531             (gnus-data-update-list gnus-newsgroup-data offset)))
2532       (while (cdr data)
2533         (when (= (gnus-data-number (cadr data)) article)
2534           (setcdr data (cddr data))
2535           (when offset
2536             (gnus-data-update-list (cdr data) offset))
2537           (setq data nil
2538                 gnus-newsgroup-data-reverse nil))
2539         (setq data (cdr data))))))
2540
2541 (defmacro gnus-data-list (backward)
2542   `(if ,backward
2543        (or gnus-newsgroup-data-reverse
2544            (setq gnus-newsgroup-data-reverse
2545                  (reverse gnus-newsgroup-data)))
2546      gnus-newsgroup-data))
2547
2548 (defun gnus-data-update-list (data offset)
2549   "Add OFFSET to the POS of all data entries in DATA."
2550   (setq gnus-newsgroup-data-reverse nil)
2551   (while data
2552     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2553     (setq data (cdr data))))
2554
2555 (defun gnus-summary-article-pseudo-p (article)
2556   "Say whether this article is a pseudo article or not."
2557   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2558
2559 (defmacro gnus-summary-article-sparse-p (article)
2560   "Say whether this article is a sparse article or not."
2561   `(memq ,article gnus-newsgroup-sparse))
2562
2563 (defmacro gnus-summary-article-ancient-p (article)
2564   "Say whether this article is a sparse article or not."
2565   `(memq ,article gnus-newsgroup-ancient))
2566
2567 (defun gnus-article-parent-p (number)
2568   "Say whether this article is a parent or not."
2569   (let ((data (gnus-data-find-list number)))
2570     (and (cdr data)              ; There has to be an article after...
2571          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2572             (gnus-data-level (nth 1 data))))))
2573
2574 (defun gnus-article-children (number)
2575   "Return a list of all children to NUMBER."
2576   (let* ((data (gnus-data-find-list number))
2577          (level (gnus-data-level (car data)))
2578          children)
2579     (setq data (cdr data))
2580     (while (and data
2581                 (= (gnus-data-level (car data)) (1+ level)))
2582       (push (gnus-data-number (car data)) children)
2583       (setq data (cdr data)))
2584     children))
2585
2586 (defmacro gnus-summary-skip-intangible ()
2587   "If the current article is intangible, then jump to a different article."
2588   '(let ((to (get-text-property (point) 'gnus-intangible)))
2589      (and to (gnus-summary-goto-subject to))))
2590
2591 (defmacro gnus-summary-article-intangible-p ()
2592   "Say whether this article is intangible or not."
2593   '(get-text-property (point) 'gnus-intangible))
2594
2595 (defun gnus-article-read-p (article)
2596   "Say whether ARTICLE is read or not."
2597   (not (or (memq article gnus-newsgroup-marked)
2598            (memq article gnus-newsgroup-unreads)
2599            (memq article gnus-newsgroup-unselected)
2600            (memq article gnus-newsgroup-dormant))))
2601
2602 ;; Some summary mode macros.
2603
2604 (defmacro gnus-summary-article-number ()
2605   "The article number of the article on the current line.
2606 If there isn's an article number here, then we return the current
2607 article number."
2608   '(progn
2609      (gnus-summary-skip-intangible)
2610      (or (get-text-property (point) 'gnus-number)
2611          (gnus-summary-last-subject))))
2612
2613 (defmacro gnus-summary-article-header (&optional number)
2614   "Return the header of article NUMBER."
2615   `(gnus-data-header (gnus-data-find
2616                       ,(or number '(gnus-summary-article-number)))))
2617
2618 (defmacro gnus-summary-thread-level (&optional number)
2619   "Return the level of thread that starts with article NUMBER."
2620   `(if (and (eq gnus-summary-make-false-root 'dummy)
2621             (get-text-property (point) 'gnus-intangible))
2622        0
2623      (gnus-data-level (gnus-data-find
2624                        ,(or number '(gnus-summary-article-number))))))
2625
2626 (defmacro gnus-summary-article-mark (&optional number)
2627   "Return the mark of article NUMBER."
2628   `(gnus-data-mark (gnus-data-find
2629                     ,(or number '(gnus-summary-article-number)))))
2630
2631 (defmacro gnus-summary-article-pos (&optional number)
2632   "Return the position of the line of article NUMBER."
2633   `(gnus-data-pos (gnus-data-find
2634                    ,(or number '(gnus-summary-article-number)))))
2635
2636 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2637 (defmacro gnus-summary-article-subject (&optional number)
2638   "Return current subject string or nil if nothing."
2639   `(let ((headers
2640           ,(if number
2641                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2642              '(gnus-data-header (assq (gnus-summary-article-number)
2643                                       gnus-newsgroup-data)))))
2644      (and headers
2645           (vectorp headers)
2646           (mail-header-subject headers))))
2647
2648 (defmacro gnus-summary-article-score (&optional number)
2649   "Return current article score."
2650   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2651                   gnus-newsgroup-scored))
2652        gnus-summary-default-score 0))
2653
2654 (defun gnus-summary-article-children (&optional number)
2655   "Return a list of article numbers that are children of article NUMBER."
2656   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2657          (level (gnus-data-level (car data)))
2658          l children)
2659     (while (and (setq data (cdr data))
2660                 (> (setq l (gnus-data-level (car data))) level))
2661       (and (= (1+ level) l)
2662            (push (gnus-data-number (car data))
2663                  children)))
2664     (nreverse children)))
2665
2666 (defun gnus-summary-article-parent (&optional number)
2667   "Return the article number of the parent of article NUMBER."
2668   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2669                                     (gnus-data-list t)))
2670          (level (gnus-data-level (car data))))
2671     (if (zerop level)
2672         ()                              ; This is a root.
2673       ;; We search until we find an article with a level less than
2674       ;; this one.  That function has to be the parent.
2675       (while (and (setq data (cdr data))
2676                   (not (< (gnus-data-level (car data)) level))))
2677       (and data (gnus-data-number (car data))))))
2678
2679 (defun gnus-unread-mark-p (mark)
2680   "Say whether MARK is the unread mark."
2681   (= mark gnus-unread-mark))
2682
2683 (defun gnus-read-mark-p (mark)
2684   "Say whether MARK is one of the marks that mark as read.
2685 This is all marks except unread, ticked, dormant, and expirable."
2686   (not (or (= mark gnus-unread-mark)
2687            (= mark gnus-ticked-mark)
2688            (= mark gnus-dormant-mark)
2689            (= mark gnus-expirable-mark))))
2690
2691 (defmacro gnus-article-mark (number)
2692   "Return the MARK of article NUMBER.
2693 This macro should only be used when computing the mark the \"first\"
2694 time; i.e., when generating the summary lines.  After that,
2695 `gnus-summary-article-mark' should be used to examine the
2696 marks of articles."
2697   `(cond
2698     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2699     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2700     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2701     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2702     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2703     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2704     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2705     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2706            gnus-ancient-mark))))
2707
2708 ;; Saving hidden threads.
2709
2710 (defmacro gnus-save-hidden-threads (&rest forms)
2711   "Save hidden threads, eval FORMS, and restore the hidden threads."
2712   (let ((config (make-symbol "config")))
2713     `(let ((,config (gnus-hidden-threads-configuration)))
2714        (unwind-protect
2715            (save-excursion
2716              ,@forms)
2717          (gnus-restore-hidden-threads-configuration ,config)))))
2718 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2719 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2720
2721 (defun gnus-data-compute-positions ()
2722   "Compute the positions of all articles."
2723   (setq gnus-newsgroup-data-reverse nil)
2724   (let ((data gnus-newsgroup-data))
2725     (save-excursion
2726       (gnus-save-hidden-threads
2727         (gnus-summary-show-all-threads)
2728         (goto-char (point-min))
2729         (while data
2730           (while (get-text-property (point) 'gnus-intangible)
2731             (forward-line 1))
2732           (gnus-data-set-pos (car data) (+ (point) 3))
2733           (setq data (cdr data))
2734           (forward-line 1))))))
2735
2736 (defun gnus-hidden-threads-configuration ()
2737   "Return the current hidden threads configuration."
2738   (save-excursion
2739     (let (config)
2740       (goto-char (point-min))
2741       (while (search-forward "\r" nil t)
2742         (push (1- (point)) config))
2743       config)))
2744
2745 (defun gnus-restore-hidden-threads-configuration (config)
2746   "Restore hidden threads configuration from CONFIG."
2747   (save-excursion
2748     (let (point buffer-read-only)
2749       (while (setq point (pop config))
2750         (when (and (< point (point-max))
2751                    (goto-char point)
2752                    (eq (char-after) ?\n))
2753           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2754
2755 ;; Various summary mode internalish functions.
2756
2757 (defun gnus-mouse-pick-article (e)
2758   (interactive "e")
2759   (mouse-set-point e)
2760   (gnus-summary-next-page nil t))
2761
2762 (defun gnus-summary-set-display-table ()
2763   "Change the display table.
2764 Odd characters have a tendency to mess
2765 up nicely formatted displays - we make all possible glyphs
2766 display only a single character."
2767
2768   ;; We start from the standard display table, if any.
2769   (let ((table (or (copy-sequence standard-display-table)
2770                    (make-display-table)))
2771         (i 32))
2772     ;; Nix out all the control chars...
2773     (while (>= (setq i (1- i)) 0)
2774       (aset table i [??]))
2775    ;; ... but not newline and cr, of course.  (cr is necessary for the
2776     ;; selective display).
2777     (aset table ?\n nil)
2778     (aset table ?\r nil)
2779     ;; We keep TAB as well.
2780     (aset table ?\t nil)
2781     ;; We nix out any glyphs over 126 that are not set already.
2782     (let ((i 256))
2783       (while (>= (setq i (1- i)) 127)
2784         ;; Only modify if the entry is nil.
2785         (unless (aref table i)
2786           (aset table i [??]))))
2787     (setq buffer-display-table table)))
2788
2789 (defun gnus-summary-set-article-display-arrow (pos)
2790   "Update the overlay arrow to point to line at position POS."
2791   (when (and gnus-summary-display-arrow
2792              (boundp 'overlay-arrow-position)
2793              (boundp 'overlay-arrow-string))
2794     (save-excursion
2795       (goto-char pos)
2796       (beginning-of-line)
2797       (unless overlay-arrow-position
2798         (setq overlay-arrow-position (make-marker)))
2799       (setq overlay-arrow-string "=>"
2800             overlay-arrow-position (set-marker overlay-arrow-position
2801                                                (point)
2802                                                (current-buffer))))))
2803
2804 (defun gnus-summary-buffer-name (group)
2805   "Return the summary buffer name of GROUP."
2806   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2807
2808 (defun gnus-summary-setup-buffer (group)
2809   "Initialize summary buffer."
2810   (let ((buffer (gnus-summary-buffer-name group)))
2811     (if (get-buffer buffer)
2812         (progn
2813           (set-buffer buffer)
2814           (setq gnus-summary-buffer (current-buffer))
2815           (not gnus-newsgroup-prepared))
2816       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2817       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2818       (gnus-summary-mode group)
2819       (when gnus-carpal
2820         (gnus-carpal-setup-buffer 'summary))
2821       (unless gnus-single-article-buffer
2822         (make-local-variable 'gnus-article-buffer)
2823         (make-local-variable 'gnus-article-current)
2824         (make-local-variable 'gnus-original-article-buffer))
2825       (setq gnus-newsgroup-name group)
2826       ;; Set any local variables in the group parameters.
2827       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2828       t)))
2829
2830 (defun gnus-set-global-variables ()
2831   "Set the global equivalents of the buffer-local variables.
2832 They are set to the latest values they had.  These reflect the summary
2833 buffer that was in action when the last article was fetched."
2834   (when (eq major-mode 'gnus-summary-mode)
2835     (setq gnus-summary-buffer (current-buffer))
2836     (let ((name gnus-newsgroup-name)
2837           (marked gnus-newsgroup-marked)
2838           (unread gnus-newsgroup-unreads)
2839           (headers gnus-current-headers)
2840           (data gnus-newsgroup-data)
2841           (summary gnus-summary-buffer)
2842           (article-buffer gnus-article-buffer)
2843           (original gnus-original-article-buffer)
2844           (gac gnus-article-current)
2845           (reffed gnus-reffed-article-number)
2846           (score-file gnus-current-score-file)
2847           (default-charset gnus-newsgroup-charset)
2848           vlist)
2849       (let ((locals gnus-newsgroup-variables))
2850         (while locals
2851           (if (consp (car locals))
2852               (push (eval (caar locals)) vlist)
2853             (push (eval (car locals)) vlist))
2854           (setq locals (cdr locals)))
2855         (setq vlist (nreverse vlist)))
2856       (save-excursion
2857         (set-buffer gnus-group-buffer)
2858         (setq gnus-newsgroup-name name
2859               gnus-newsgroup-marked marked
2860               gnus-newsgroup-unreads unread
2861               gnus-current-headers headers
2862               gnus-newsgroup-data data
2863               gnus-article-current gac
2864               gnus-summary-buffer summary
2865               gnus-article-buffer article-buffer
2866               gnus-original-article-buffer original
2867               gnus-reffed-article-number reffed
2868               gnus-current-score-file score-file
2869               gnus-newsgroup-charset default-charset)
2870         (let ((locals gnus-newsgroup-variables))
2871           (while locals
2872             (if (consp (car locals))
2873                 (set (caar locals) (pop vlist))
2874               (set (car locals) (pop vlist)))
2875             (setq locals (cdr locals))))
2876         ;; The article buffer also has local variables.
2877         (when (gnus-buffer-live-p gnus-article-buffer)
2878           (set-buffer gnus-article-buffer)
2879           (setq gnus-summary-buffer summary))))))
2880
2881 (defun gnus-summary-article-unread-p (article)
2882   "Say whether ARTICLE is unread or not."
2883   (memq article gnus-newsgroup-unreads))
2884
2885 (defun gnus-summary-first-article-p (&optional article)
2886   "Return whether ARTICLE is the first article in the buffer."
2887   (if (not (setq article (or article (gnus-summary-article-number))))
2888       nil
2889     (eq article (caar gnus-newsgroup-data))))
2890
2891 (defun gnus-summary-last-article-p (&optional article)
2892   "Return whether ARTICLE is the last article in the buffer."
2893   (if (not (setq article (or article (gnus-summary-article-number))))
2894       ;; All non-existent numbers are the last article.  :-)
2895       t
2896     (not (cdr (gnus-data-find-list article)))))
2897
2898 (defun gnus-make-thread-indent-array ()
2899   (let ((n 200))
2900     (unless (and gnus-thread-indent-array
2901                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2902       (setq gnus-thread-indent-array (make-vector 201 "")
2903             gnus-thread-indent-array-level gnus-thread-indent-level)
2904       (while (>= n 0)
2905         (aset gnus-thread-indent-array n
2906               (make-string (* n gnus-thread-indent-level) ? ))
2907         (setq n (1- n))))))
2908
2909 (defun gnus-update-summary-mark-positions ()
2910   "Compute where the summary marks are to go."
2911   (save-excursion
2912     (when (gnus-buffer-exists-p gnus-summary-buffer)
2913       (set-buffer gnus-summary-buffer))
2914     (let ((gnus-replied-mark 129)
2915           (gnus-score-below-mark 130)
2916           (gnus-score-over-mark 130)
2917           (gnus-download-mark 131)
2918           (spec gnus-summary-line-format-spec)
2919           gnus-visual pos)
2920       (save-excursion
2921         (gnus-set-work-buffer)
2922         (let ((gnus-summary-line-format-spec spec)
2923               (gnus-newsgroup-downloadable '((0 . t))))
2924           (gnus-summary-insert-line
2925            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2926            0 nil 128 t nil "" nil 1)
2927           (goto-char (point-min))
2928           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2929                                              (- (point) 2)))))
2930           (goto-char (point-min))
2931           (push (cons 'replied (and (search-forward "\201" nil t)
2932                                     (- (point) 2)))
2933                 pos)
2934           (goto-char (point-min))
2935           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2936                 pos)
2937           (goto-char (point-min))
2938           (push (cons 'download
2939                       (and (search-forward "\203" nil t) (- (point) 2)))
2940                 pos)))
2941       (setq gnus-summary-mark-positions pos))))
2942
2943 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2944   "Insert a dummy root in the summary buffer."
2945   (beginning-of-line)
2946   (gnus-add-text-properties
2947    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2948    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2949
2950 (defun gnus-summary-extract-address-component (from)
2951   (or (car (funcall gnus-extract-address-components from))
2952       from))
2953
2954 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2955   (let ((mail-parse-charset gnus-newsgroup-charset)
2956         ; Is it really necessary to do this next part for each summary line?
2957         ; Luckily, doesn't seem to slow things down much.
2958         (mail-parse-ignored-charsets
2959          (save-excursion (set-buffer gnus-summary-buffer)
2960                          gnus-newsgroup-ignored-charsets)))
2961     (or
2962      (and gnus-ignored-from-addresses
2963           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2964           (let ((extra-headers (mail-header-extra header))
2965                 to
2966                 newsgroups)
2967             (cond
2968              ((setq to (cdr (assq 'To extra-headers)))
2969               (concat "-> "
2970                       (gnus-summary-extract-address-component
2971                        (funcall gnus-decode-encoded-word-function to))))
2972              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2973               (concat "=> " newsgroups)))))
2974      (gnus-summary-extract-address-component gnus-tmp-from))))
2975
2976 (defun gnus-summary-insert-line (gnus-tmp-header
2977                                  gnus-tmp-level gnus-tmp-current
2978                                  gnus-tmp-unread gnus-tmp-replied
2979                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2980                                  &optional gnus-tmp-dummy gnus-tmp-score
2981                                  gnus-tmp-process)
2982   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2983          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2984          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2985          (gnus-tmp-score-char
2986           (if (or (null gnus-summary-default-score)
2987                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2988                       gnus-summary-zcore-fuzz))
2989               ?                         ;Whitespace
2990             (if (< gnus-tmp-score gnus-summary-default-score)
2991                 gnus-score-below-mark gnus-score-over-mark)))
2992          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2993          (gnus-tmp-replied
2994           (cond (gnus-tmp-process gnus-process-mark)
2995                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2996                  gnus-cached-mark)
2997                 (gnus-tmp-replied gnus-replied-mark)
2998                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
2999                  gnus-forwarded-mark)
3000                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3001                  gnus-saved-mark)
3002                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3003                  gnus-recent-mark)
3004                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3005                  gnus-unseen-mark)
3006                 (t gnus-no-mark)))
3007          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3008          (gnus-tmp-name
3009           (cond
3010            ((string-match "<[^>]+> *$" gnus-tmp-from)
3011             (let ((beg (match-beginning 0)))
3012               (or (and (string-match "^\".+\"" gnus-tmp-from)
3013                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3014                   (substring gnus-tmp-from 0 beg))))
3015            ((string-match "(.+)" gnus-tmp-from)
3016             (substring gnus-tmp-from
3017                        (1+ (match-beginning 0)) (1- (match-end 0))))
3018            (t gnus-tmp-from)))
3019          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3020          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3021          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3022          (buffer-read-only nil))
3023     (when (string= gnus-tmp-name "")
3024       (setq gnus-tmp-name gnus-tmp-from))
3025     (unless (numberp gnus-tmp-lines)
3026       (setq gnus-tmp-lines -1))
3027     (if (= gnus-tmp-lines -1)
3028         (setq gnus-tmp-lines "?")
3029       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3030     (gnus-put-text-property
3031      (point)
3032      (progn (eval gnus-summary-line-format-spec) (point))
3033      'gnus-number gnus-tmp-number)
3034     (when (gnus-visual-p 'summary-highlight 'highlight)
3035       (forward-line -1)
3036       (gnus-run-hooks 'gnus-summary-update-hook)
3037       (forward-line 1))))
3038
3039 (defun gnus-summary-update-line (&optional dont-update)
3040   "Update summary line after change."
3041   (when (and gnus-summary-default-score
3042              (not gnus-summary-inhibit-highlight))
3043     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3044            (article (gnus-summary-article-number))
3045            (score (gnus-summary-article-score article)))
3046       (unless dont-update
3047         (if (and gnus-summary-mark-below
3048                  (< (gnus-summary-article-score)
3049                     gnus-summary-mark-below))
3050             ;; This article has a low score, so we mark it as read.
3051             (when (memq article gnus-newsgroup-unreads)
3052               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3053           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3054             ;; This article was previously marked as read on account
3055             ;; of a low score, but now it has risen, so we mark it as
3056             ;; unread.
3057             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3058         (gnus-summary-update-mark
3059          (if (or (null gnus-summary-default-score)
3060                  (<= (abs (- score gnus-summary-default-score))
3061                      gnus-summary-zcore-fuzz))
3062              ?                          ;Whitespace
3063            (if (< score gnus-summary-default-score)
3064                gnus-score-below-mark gnus-score-over-mark))
3065          'score))
3066       ;; Do visual highlighting.
3067       (when (gnus-visual-p 'summary-highlight 'highlight)
3068         (gnus-run-hooks 'gnus-summary-update-hook)))))
3069
3070 (defvar gnus-tmp-new-adopts nil)
3071
3072 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3073   "Return the number of articles in THREAD.
3074 This may be 0 in some cases -- if none of the articles in
3075 the thread are to be displayed."
3076   (let* ((number
3077          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3078           (cond
3079            ((not (listp thread))
3080             1)
3081            ((and (consp thread) (cdr thread))
3082             (apply
3083              '+ 1 (mapcar
3084                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3085            ((null thread)
3086             1)
3087            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3088             1)
3089            (t 0))))
3090     (when (and level (zerop level) gnus-tmp-new-adopts)
3091       (incf number
3092             (apply '+ (mapcar
3093                        'gnus-summary-number-of-articles-in-thread
3094                        gnus-tmp-new-adopts))))
3095     (if char
3096         (if (> number 1) gnus-not-empty-thread-mark
3097           gnus-empty-thread-mark)
3098       number)))
3099
3100 (defun gnus-summary-set-local-parameters (group)
3101   "Go through the local params of GROUP and set all variable specs in that list."
3102   (let ((params (gnus-group-find-parameter group))
3103         (vars '(quit-config))           ; Ignore quit-config.
3104         elem)
3105     (while params
3106       (setq elem (car params)
3107             params (cdr params))
3108       (and (consp elem)                 ; Has to be a cons.
3109            (consp (cdr elem))           ; The cdr has to be a list.
3110            (symbolp (car elem))         ; Has to be a symbol in there.
3111            (not (memq (car elem) vars))
3112            (ignore-errors               ; So we set it.
3113              (push (car elem) vars)
3114              (make-local-variable (car elem))
3115              (set (car elem) (eval (nth 1 elem))))))))
3116
3117 (defun gnus-summary-read-group (group &optional show-all no-article
3118                                       kill-buffer no-display backward
3119                                       select-articles)
3120   "Start reading news in newsgroup GROUP.
3121 If SHOW-ALL is non-nil, already read articles are also listed.
3122 If NO-ARTICLE is non-nil, no article is selected initially.
3123 If NO-DISPLAY, don't generate a summary buffer."
3124   (let (result)
3125     (while (and group
3126                 (null (setq result
3127                             (let ((gnus-auto-select-next nil))
3128                               (or (gnus-summary-read-group-1
3129                                    group show-all no-article
3130                                    kill-buffer no-display
3131                                    select-articles)
3132                                   (setq show-all nil
3133                                         select-articles nil)))))
3134                 (eq gnus-auto-select-next 'quietly))
3135       (set-buffer gnus-group-buffer)
3136       ;; The entry function called above goes to the next
3137       ;; group automatically, so we go two groups back
3138       ;; if we are searching for the previous group.
3139       (when backward
3140         (gnus-group-prev-unread-group 2))
3141       (if (not (equal group (gnus-group-group-name)))
3142           (setq group (gnus-group-group-name))
3143         (setq group nil)))
3144     result))
3145
3146 (defun gnus-summary-read-group-1 (group show-all no-article
3147                                         kill-buffer no-display
3148                                         &optional select-articles)
3149   ;; Killed foreign groups can't be entered.
3150   ;;  (when (and (not (gnus-group-native-p group))
3151   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3152   ;;    (error "Dead non-native groups can't be entered"))
3153   (gnus-message 5 "Retrieving newsgroup: %s..."
3154                 (gnus-group-decoded-name group))
3155   (let* ((new-group (gnus-summary-setup-buffer group))
3156          (quit-config (gnus-group-quit-config group))
3157          (did-select (and new-group (gnus-select-newsgroup
3158                                      group show-all select-articles))))
3159     (cond
3160      ;; This summary buffer exists already, so we just select it.
3161      ((not new-group)
3162       (gnus-set-global-variables)
3163       (when kill-buffer
3164         (gnus-kill-or-deaden-summary kill-buffer))
3165       (gnus-configure-windows 'summary 'force)
3166       (gnus-set-mode-line 'summary)
3167       (gnus-summary-position-point)
3168       (message "")
3169       t)
3170      ;; We couldn't select this group.
3171      ((null did-select)
3172       (when (and (eq major-mode 'gnus-summary-mode)
3173                  (not (equal (current-buffer) kill-buffer)))
3174         (kill-buffer (current-buffer))
3175         (if (not quit-config)
3176             (progn
3177               ;; Update the info -- marks might need to be removed,
3178               ;; for instance.
3179               (gnus-summary-update-info)
3180               (set-buffer gnus-group-buffer)
3181               (gnus-group-jump-to-group group)
3182               (gnus-group-next-unread-group 1))
3183           (gnus-handle-ephemeral-exit quit-config)))
3184       (let ((grpinfo (gnus-get-info group)))
3185         (if (null (gnus-info-read grpinfo))
3186             (gnus-message 3 "Group %s contains no messages"
3187                           (gnus-group-decoded-name group))
3188           (gnus-message 3 "Can't select group")))
3189       nil)
3190      ;; The user did a `C-g' while prompting for number of articles,
3191      ;; so we exit this group.
3192      ((eq did-select 'quit)
3193       (and (eq major-mode 'gnus-summary-mode)
3194            (not (equal (current-buffer) kill-buffer))
3195            (kill-buffer (current-buffer)))
3196       (when kill-buffer
3197         (gnus-kill-or-deaden-summary kill-buffer))
3198       (if (not quit-config)
3199           (progn
3200             (set-buffer gnus-group-buffer)
3201             (gnus-group-jump-to-group group)
3202             (gnus-group-next-unread-group 1)
3203             (gnus-configure-windows 'group 'force))
3204         (gnus-handle-ephemeral-exit quit-config))
3205       ;; Finally signal the quit.
3206       (signal 'quit nil))
3207      ;; The group was successfully selected.
3208      (t
3209       (gnus-set-global-variables)
3210       ;; Save the active value in effect when the group was entered.
3211       (setq gnus-newsgroup-active
3212             (gnus-copy-sequence
3213              (gnus-active gnus-newsgroup-name)))
3214       ;; You can change the summary buffer in some way with this hook.
3215       (gnus-run-hooks 'gnus-select-group-hook)
3216       (gnus-update-format-specifications
3217        nil 'summary 'summary-mode 'summary-dummy)
3218       (gnus-update-summary-mark-positions)
3219       ;; Do score processing.
3220       (when gnus-use-scoring
3221         (gnus-possibly-score-headers))
3222       ;; Check whether to fill in the gaps in the threads.
3223       (when gnus-build-sparse-threads
3224         (gnus-build-sparse-threads))
3225       ;; Find the initial limit.
3226       (if gnus-show-threads
3227           (if show-all
3228               (let ((gnus-newsgroup-dormant nil))
3229                 (gnus-summary-initial-limit show-all))
3230             (gnus-summary-initial-limit show-all))
3231         ;; When untreaded, all articles are always shown.
3232         (setq gnus-newsgroup-limit
3233               (mapcar
3234                (lambda (header) (mail-header-number header))
3235                gnus-newsgroup-headers)))
3236       ;; Generate the summary buffer.
3237       (unless no-display
3238         (gnus-summary-prepare))
3239       (when gnus-use-trees
3240         (gnus-tree-open group)
3241         (setq gnus-summary-highlight-line-function
3242               'gnus-tree-highlight-article))
3243       ;; If the summary buffer is empty, but there are some low-scored
3244       ;; articles or some excluded dormants, we include these in the
3245       ;; buffer.
3246       (when (and (zerop (buffer-size))
3247                  (not no-display))
3248         (cond (gnus-newsgroup-dormant
3249                (gnus-summary-limit-include-dormant))
3250               ((and gnus-newsgroup-scored show-all)
3251                (gnus-summary-limit-include-expunged t))))
3252       ;; Function `gnus-apply-kill-file' must be called in this hook.
3253       (gnus-run-hooks 'gnus-apply-kill-hook)
3254       (if (and (zerop (buffer-size))
3255                (not no-display))
3256           (progn
3257             ;; This newsgroup is empty.
3258             (gnus-summary-catchup-and-exit nil t)
3259             (gnus-message 6 "No unread news")
3260             (when kill-buffer
3261               (gnus-kill-or-deaden-summary kill-buffer))
3262             ;; Return nil from this function.
3263             nil)
3264         ;; Hide conversation thread subtrees.  We cannot do this in
3265         ;; gnus-summary-prepare-hook since kill processing may not
3266         ;; work with hidden articles.
3267         (and gnus-show-threads
3268              gnus-thread-hide-subtree
3269              (gnus-summary-hide-all-threads))
3270         (when kill-buffer
3271           (gnus-kill-or-deaden-summary kill-buffer))
3272         (gnus-summary-auto-select-subject)
3273         ;; Show first unread article if requested.
3274         (if (and (not no-article)
3275                  (not no-display)
3276                  gnus-newsgroup-unreads
3277                  gnus-auto-select-first)
3278             (progn
3279               (gnus-configure-windows 'summary)
3280               (gnus-summary-goto-article (gnus-summary-article-number)))
3281           ;; Don't select any articles.
3282           (gnus-summary-position-point)
3283           (gnus-configure-windows 'summary 'force)
3284           (gnus-set-mode-line 'summary))
3285         (when (get-buffer-window gnus-group-buffer t)
3286           ;; Gotta use windows, because recenter does weird stuff if
3287           ;; the current buffer ain't the displayed window.
3288           (let ((owin (selected-window)))
3289             (select-window (get-buffer-window gnus-group-buffer t))
3290             (when (gnus-group-goto-group group)
3291               (recenter))
3292             (select-window owin)))
3293         ;; Mark this buffer as "prepared".
3294         (setq gnus-newsgroup-prepared t)
3295         (gnus-run-hooks 'gnus-summary-prepared-hook)
3296         t)))))
3297
3298 (defun gnus-summary-auto-select-subject ()
3299   "Select the subject line on initial group entry."
3300   (goto-char (point-min))
3301   (cond
3302    ((eq gnus-auto-select-subject 'best)
3303     (gnus-summary-best-unread-subject))
3304    ((eq gnus-auto-select-subject 'unread)
3305     (gnus-summary-first-unread-subject))
3306    ((eq gnus-auto-select-subject 'unseen)
3307     (gnus-summary-first-unseen-subject))
3308    ((eq gnus-auto-select-subject 'first)
3309     ;; Do nothing.
3310     )
3311    ((gnus-functionp gnus-auto-select-subject)
3312     (funcall gnus-auto-select-subject))))
3313
3314 (defun gnus-summary-prepare ()
3315   "Generate the summary buffer."
3316   (interactive)
3317   (let ((buffer-read-only nil))
3318     (erase-buffer)
3319     (setq gnus-newsgroup-data nil
3320           gnus-newsgroup-data-reverse nil)
3321     (gnus-run-hooks 'gnus-summary-generate-hook)
3322     ;; Generate the buffer, either with threads or without.
3323     (when gnus-newsgroup-headers
3324       (gnus-summary-prepare-threads
3325        (if gnus-show-threads
3326            (gnus-sort-gathered-threads
3327             (funcall gnus-summary-thread-gathering-function
3328                      (gnus-sort-threads
3329                       (gnus-cut-threads (gnus-make-threads)))))
3330          ;; Unthreaded display.
3331          (gnus-sort-articles gnus-newsgroup-headers))))
3332     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3333     ;; Call hooks for modifying summary buffer.
3334     (goto-char (point-min))
3335     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3336
3337 (defsubst gnus-general-simplify-subject (subject)
3338   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3339   (setq subject
3340         (cond
3341          ;; Truncate the subject.
3342          (gnus-simplify-subject-functions
3343           (gnus-map-function gnus-simplify-subject-functions subject))
3344          ((numberp gnus-summary-gather-subject-limit)
3345           (setq subject (gnus-simplify-subject-re subject))
3346           (if (> (length subject) gnus-summary-gather-subject-limit)
3347               (substring subject 0 gnus-summary-gather-subject-limit)
3348             subject))
3349          ;; Fuzzily simplify it.
3350          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3351           (gnus-simplify-subject-fuzzy subject))
3352          ;; Just remove the leading "Re:".
3353          (t
3354           (gnus-simplify-subject-re subject))))
3355
3356   (if (and gnus-summary-gather-exclude-subject
3357            (string-match gnus-summary-gather-exclude-subject subject))
3358       nil                         ; This article shouldn't be gathered
3359     subject))
3360
3361 (defun gnus-summary-simplify-subject-query ()
3362   "Query where the respool algorithm would put this article."
3363   (interactive)
3364   (gnus-summary-select-article)
3365   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3366
3367 (defun gnus-gather-threads-by-subject (threads)
3368   "Gather threads by looking at Subject headers."
3369   (if (not gnus-summary-make-false-root)
3370       threads
3371     (let ((hashtb (gnus-make-hashtable 1024))
3372           (prev threads)
3373           (result threads)
3374           subject hthread whole-subject)
3375       (while threads
3376         (setq subject (gnus-general-simplify-subject
3377                        (setq whole-subject (mail-header-subject
3378                                             (caar threads)))))
3379         (when subject
3380           (if (setq hthread (gnus-gethash subject hashtb))
3381               (progn
3382                 ;; We enter a dummy root into the thread, if we
3383                 ;; haven't done that already.
3384                 (unless (stringp (caar hthread))
3385                   (setcar hthread (list whole-subject (car hthread))))
3386                 ;; We add this new gathered thread to this gathered
3387                 ;; thread.
3388                 (setcdr (car hthread)
3389                         (nconc (cdar hthread) (list (car threads))))
3390                 ;; Remove it from the list of threads.
3391                 (setcdr prev (cdr threads))
3392                 (setq threads prev))
3393             ;; Enter this thread into the hash table.
3394             (gnus-sethash subject threads hashtb)))
3395         (setq prev threads)
3396         (setq threads (cdr threads)))
3397       result)))
3398
3399 (defun gnus-gather-threads-by-references (threads)
3400   "Gather threads by looking at References headers."
3401   (let ((idhashtb (gnus-make-hashtable 1024))
3402         (thhashtb (gnus-make-hashtable 1024))
3403         (prev threads)
3404         (result threads)
3405         ids references id gthread gid entered ref)
3406     (while threads
3407       (when (setq references (mail-header-references (caar threads)))
3408         (setq id (mail-header-id (caar threads))
3409               ids (gnus-split-references references)
3410               entered nil)
3411         (while (setq ref (pop ids))
3412           (setq ids (delete ref ids))
3413           (if (not (setq gid (gnus-gethash ref idhashtb)))
3414               (progn
3415                 (gnus-sethash ref id idhashtb)
3416                 (gnus-sethash id threads thhashtb))
3417             (setq gthread (gnus-gethash gid thhashtb))
3418             (unless entered
3419               ;; We enter a dummy root into the thread, if we
3420               ;; haven't done that already.
3421               (unless (stringp (caar gthread))
3422                 (setcar gthread (list (mail-header-subject (caar gthread))
3423                                       (car gthread))))
3424               ;; We add this new gathered thread to this gathered
3425               ;; thread.
3426               (setcdr (car gthread)
3427                       (nconc (cdar gthread) (list (car threads)))))
3428             ;; Add it into the thread hash table.
3429             (gnus-sethash id gthread thhashtb)
3430             (setq entered t)
3431             ;; Remove it from the list of threads.
3432             (setcdr prev (cdr threads))
3433             (setq threads prev))))
3434       (setq prev threads)
3435       (setq threads (cdr threads)))
3436     result))
3437
3438 (defun gnus-sort-gathered-threads (threads)
3439   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3440   (let ((result threads))
3441     (while threads
3442       (when (stringp (caar threads))
3443         (setcdr (car threads)
3444                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3445       (setq threads (cdr threads)))
3446     result))
3447
3448 (defun gnus-thread-loop-p (root thread)
3449   "Say whether ROOT is in THREAD."
3450   (let ((stack (list thread))
3451         (infloop 0)
3452         th)
3453     (while (setq thread (pop stack))
3454       (setq th (cdr thread))
3455       (while (and th
3456                   (not (eq (caar th) root)))
3457         (pop th))
3458       (if th
3459           ;; We have found a loop.
3460           (let (ref-dep)
3461             (setcdr thread (delq (car th) (cdr thread)))
3462             (if (boundp (setq ref-dep (intern "none"
3463                                               gnus-newsgroup-dependencies)))
3464                 (setcdr (symbol-value ref-dep)
3465                         (nconc (cdr (symbol-value ref-dep))
3466                                (list (car th))))
3467               (set ref-dep (list nil (car th))))
3468             (setq infloop 1
3469                   stack nil))
3470         ;; Push all the subthreads onto the stack.
3471         (push (cdr thread) stack)))
3472     infloop))
3473
3474 (defun gnus-make-threads ()
3475   "Go through the dependency hashtb and find the roots.  Return all threads."
3476   (let (threads)
3477     (while (catch 'infloop
3478              (mapatoms
3479               (lambda (refs)
3480                 ;; Deal with self-referencing References loops.
3481                 (when (and (car (symbol-value refs))
3482                            (not (zerop
3483                                  (apply
3484                                   '+
3485                                   (mapcar
3486                                    (lambda (thread)
3487                                      (gnus-thread-loop-p
3488                                       (car (symbol-value refs)) thread))
3489                                    (cdr (symbol-value refs)))))))
3490                   (setq threads nil)
3491                   (throw 'infloop t))
3492                 (unless (car (symbol-value refs))
3493              ;; These threads do not refer back to any other articles,
3494                   ;; so they're roots.
3495                   (setq threads (append (cdr (symbol-value refs)) threads))))
3496               gnus-newsgroup-dependencies)))
3497     threads))
3498
3499 ;; Build the thread tree.
3500 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3501   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3502
3503 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3504 if it was already present.
3505
3506 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3507 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3508 Message-IDs will be renamed be renamed to a unique Message-ID before
3509 being entered.
3510
3511 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3512   (let* ((id (mail-header-id header))
3513          (id-dep (and id (intern id dependencies)))
3514          ref ref-dep ref-header)
3515     ;; Enter this `header' in the `dependencies' table.
3516     (cond
3517      ((not id-dep)
3518       (setq header nil))
3519      ;; The first two cases do the normal part: enter a new `header'
3520      ;; in the `dependencies' table.
3521      ((not (boundp id-dep))
3522       (set id-dep (list header)))
3523      ((null (car (symbol-value id-dep)))
3524       (setcar (symbol-value id-dep) header))
3525
3526      ;; From here the `header' was already present in the
3527      ;; `dependencies' table.
3528      (force-new
3529       ;; Overrides an existing entry;
3530       ;; just set the header part of the entry.
3531       (setcar (symbol-value id-dep) header))
3532
3533      ;; Renames the existing `header' to a unique Message-ID.
3534      ((not gnus-summary-ignore-duplicates)
3535       ;; An article with this Message-ID has already been seen.
3536       ;; We rename the Message-ID.
3537       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3538            (list header))
3539       (mail-header-set-id header id))
3540
3541      ;; The last case ignores an existing entry, except it adds any
3542      ;; additional Xrefs (in case the two articles came from different
3543      ;; servers.
3544      ;; Also sets `header' to `nil' meaning that the `dependencies'
3545      ;; table was *not* modified.
3546      (t
3547       (mail-header-set-xref
3548        (car (symbol-value id-dep))
3549        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3550                    "")
3551                (or (mail-header-xref header) "")))
3552       (setq header nil)))
3553
3554     (when header
3555       ;; First check if that we are not creating a References loop.
3556       (setq ref (gnus-parent-id (mail-header-references header)))
3557       (while (and ref
3558                   (setq ref-dep (intern-soft ref dependencies))
3559                   (boundp ref-dep)
3560                   (setq ref-header (car (symbol-value ref-dep))))
3561         (if (string= id ref)
3562             ;; Yuk!  This is a reference loop.  Make the article be a
3563             ;; root article.
3564             (progn
3565               (mail-header-set-references (car (symbol-value id-dep)) "none")
3566               (setq ref nil))
3567           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3568       (setq ref (gnus-parent-id (mail-header-references header)))
3569       (setq ref-dep (intern (or ref "none") dependencies))
3570       (if (boundp ref-dep)
3571           (setcdr (symbol-value ref-dep)
3572                   (nconc (cdr (symbol-value ref-dep))
3573                          (list (symbol-value id-dep))))
3574         (set ref-dep (list nil (symbol-value id-dep)))))
3575     header))
3576
3577 (defun gnus-build-sparse-threads ()
3578   (let ((headers gnus-newsgroup-headers)
3579         (mail-parse-charset gnus-newsgroup-charset)
3580         (gnus-summary-ignore-duplicates t)
3581         header references generation relations
3582         subject child end new-child date)
3583     ;; First we create an alist of generations/relations, where
3584     ;; generations is how much we trust the relation, and the relation
3585     ;; is parent/child.
3586     (gnus-message 7 "Making sparse threads...")
3587     (save-excursion
3588       (nnheader-set-temp-buffer " *gnus sparse threads*")
3589       (while (setq header (pop headers))
3590         (when (and (setq references (mail-header-references header))
3591                    (not (string= references "")))
3592           (insert references)
3593           (setq child (mail-header-id header)
3594                 subject (mail-header-subject header)
3595                 date (mail-header-date header)
3596                 generation 0)
3597           (while (search-backward ">" nil t)
3598             (setq end (1+ (point)))
3599             (when (search-backward "<" nil t)
3600               (setq new-child (buffer-substring (point) end))
3601               (push (list (incf generation)
3602                           child (setq child new-child)
3603                           subject date)
3604                     relations)))
3605           (when child
3606             (push (list (1+ generation) child nil subject) relations))
3607           (erase-buffer)))
3608       (kill-buffer (current-buffer)))
3609     ;; Sort over trustworthiness.
3610     (mapcar
3611      (lambda (relation)
3612        (when (gnus-dependencies-add-header
3613               (make-full-mail-header
3614                gnus-reffed-article-number
3615                (nth 3 relation) "" (or (nth 4 relation) "")
3616                (nth 1 relation)
3617                (or (nth 2 relation) "") 0 0 "")
3618               gnus-newsgroup-dependencies nil)
3619          (push gnus-reffed-article-number gnus-newsgroup-limit)
3620          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3621          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3622                gnus-newsgroup-reads)
3623          (decf gnus-reffed-article-number)))
3624      (sort relations 'car-less-than-car))
3625     (gnus-message 7 "Making sparse threads...done")))
3626
3627 (defun gnus-build-old-threads ()
3628   ;; Look at all the articles that refer back to old articles, and
3629   ;; fetch the headers for the articles that aren't there.  This will
3630   ;; build complete threads - if the roots haven't been expired by the
3631   ;; server, that is.
3632   (let ((mail-parse-charset gnus-newsgroup-charset)
3633         id heads)
3634     (mapatoms
3635      (lambda (refs)
3636        (when (not (car (symbol-value refs)))
3637          (setq heads (cdr (symbol-value refs)))
3638          (while heads
3639            (if (memq (mail-header-number (caar heads))
3640                      gnus-newsgroup-dormant)
3641                (setq heads (cdr heads))
3642              (setq id (symbol-name refs))
3643              (while (and (setq id (gnus-build-get-header id))
3644                          (not (car (gnus-id-to-thread id)))))
3645              (setq heads nil)))))
3646      gnus-newsgroup-dependencies)))
3647
3648 ;; This function has to be called with point after the article number
3649 ;; on the beginning of the line.
3650 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3651   (let ((eol (gnus-point-at-eol))
3652         (buffer (current-buffer))
3653         header)
3654
3655     ;; overview: [num subject from date id refs chars lines misc]
3656     (unwind-protect
3657         (progn
3658           (narrow-to-region (point) eol)
3659           (unless (eobp)
3660             (forward-char))
3661
3662           (setq header
3663                 (make-full-mail-header
3664                  number                 ; number
3665                  (funcall gnus-decode-encoded-word-function
3666                           (nnheader-nov-field)) ; subject
3667                  (funcall gnus-decode-encoded-word-function
3668                           (nnheader-nov-field)) ; from
3669                  (nnheader-nov-field)   ; date
3670                  (nnheader-nov-read-message-id) ; id
3671                  (nnheader-nov-field)   ; refs
3672                  (nnheader-nov-read-integer) ; chars
3673                  (nnheader-nov-read-integer) ; lines
3674                  (unless (eobp)
3675                    (if (looking-at "Xref: ")
3676                        (goto-char (match-end 0)))
3677                    (nnheader-nov-field)) ; Xref
3678                  (nnheader-nov-parse-extra)))) ; extra
3679
3680       (widen))
3681
3682     (when gnus-alter-header-function
3683       (funcall gnus-alter-header-function header))
3684     (gnus-dependencies-add-header header dependencies force-new)))
3685
3686 (defun gnus-build-get-header (id)
3687   "Look through the buffer of NOV lines and find the header to ID.
3688 Enter this line into the dependencies hash table, and return
3689 the id of the parent article (if any)."
3690   (let ((deps gnus-newsgroup-dependencies)
3691         found header)
3692     (prog1
3693         (save-excursion
3694           (set-buffer nntp-server-buffer)
3695           (let ((case-fold-search nil))
3696             (goto-char (point-min))
3697             (while (and (not found)
3698                         (search-forward id nil t))
3699               (beginning-of-line)
3700               (setq found (looking-at
3701                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3702                                    (regexp-quote id))))
3703               (or found (beginning-of-line 2)))
3704             (when found
3705               (beginning-of-line)
3706               (and
3707                (setq header (gnus-nov-parse-line
3708                              (read (current-buffer)) deps))
3709                (gnus-parent-id (mail-header-references header))))))
3710       (when header
3711         (let ((number (mail-header-number header)))
3712           (push number gnus-newsgroup-limit)
3713           (push header gnus-newsgroup-headers)
3714           (if (memq number gnus-newsgroup-unselected)
3715               (progn
3716                 (push number gnus-newsgroup-unreads)
3717                 (setq gnus-newsgroup-unselected
3718                       (delq number gnus-newsgroup-unselected)))
3719             (push number gnus-newsgroup-ancient)))))))
3720
3721 (defun gnus-build-all-threads ()
3722   "Read all the headers."
3723   (let ((gnus-summary-ignore-duplicates t)
3724         (mail-parse-charset gnus-newsgroup-charset)
3725         (dependencies gnus-newsgroup-dependencies)
3726         header article)
3727     (save-excursion
3728       (set-buffer nntp-server-buffer)
3729       (let ((case-fold-search nil))
3730         (goto-char (point-min))
3731         (while (not (eobp))
3732           (ignore-errors
3733             (setq article (read (current-buffer))
3734                   header (gnus-nov-parse-line article dependencies)))
3735           (when header
3736             (save-excursion
3737               (set-buffer gnus-summary-buffer)
3738               (push header gnus-newsgroup-headers)
3739               (if (memq (setq article (mail-header-number header))
3740                         gnus-newsgroup-unselected)
3741                   (progn
3742                     (push article gnus-newsgroup-unreads)
3743                     (setq gnus-newsgroup-unselected
3744                           (delq article gnus-newsgroup-unselected)))
3745                 (push article gnus-newsgroup-ancient)))
3746             (forward-line 1)))))))
3747
3748 (defun gnus-summary-update-article-line (article header)
3749   "Update the line for ARTICLE using HEADERS."
3750   (let* ((id (mail-header-id header))
3751          (thread (gnus-id-to-thread id)))
3752     (unless thread
3753       (error "Article in no thread"))
3754     ;; Update the thread.
3755     (setcar thread header)
3756     (gnus-summary-goto-subject article)
3757     (let* ((datal (gnus-data-find-list article))
3758            (data (car datal))
3759            (length (when (cdr datal)
3760                      (- (gnus-data-pos data)
3761                         (gnus-data-pos (cadr datal)))))
3762            (buffer-read-only nil)
3763            (level (gnus-summary-thread-level)))
3764       (gnus-delete-line)
3765       (gnus-summary-insert-line
3766        header level nil (gnus-article-mark article)
3767        (memq article gnus-newsgroup-replied)
3768        (memq article gnus-newsgroup-expirable)
3769        ;; Only insert the Subject string when it's different
3770        ;; from the previous Subject string.
3771        (if (and
3772             gnus-show-threads
3773             (gnus-subject-equal
3774              (condition-case ()
3775                  (mail-header-subject
3776                   (gnus-data-header
3777                    (cadr
3778                     (gnus-data-find-list
3779                      article
3780                      (gnus-data-list t)))))
3781                ;; Error on the side of excessive subjects.
3782                (error ""))
3783              (mail-header-subject header)))
3784            ""
3785          (mail-header-subject header))
3786        nil (cdr (assq article gnus-newsgroup-scored))
3787        (memq article gnus-newsgroup-processable))
3788       (when length
3789         (gnus-data-update-list
3790          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3791
3792 (defun gnus-summary-update-article (article &optional iheader)
3793   "Update ARTICLE in the summary buffer."
3794   (set-buffer gnus-summary-buffer)
3795   (let* ((header (gnus-summary-article-header article))
3796          (id (mail-header-id header))
3797          (data (gnus-data-find article))
3798          (thread (gnus-id-to-thread id))
3799          (references (mail-header-references header))
3800          (parent
3801           (gnus-id-to-thread
3802            (or (gnus-parent-id
3803                 (when (and references
3804                            (not (equal "" references)))
3805                   references))
3806                "none")))
3807          (buffer-read-only nil)
3808          (old (car thread)))
3809     (when thread
3810       (unless iheader
3811         (setcar thread nil)
3812         (when parent
3813           (delq thread parent)))
3814       (if (gnus-summary-insert-subject id header)
3815        ;; Set the (possibly) new article number in the data structure.
3816           (gnus-data-set-number data (gnus-id-to-article id))
3817         (setcar thread old)
3818         nil))))
3819
3820 (defun gnus-rebuild-thread (id &optional line)
3821   "Rebuild the thread containing ID.
3822 If LINE, insert the rebuilt thread starting on line LINE."
3823   (let ((buffer-read-only nil)
3824         old-pos current thread data)
3825     (if (not gnus-show-threads)
3826         (setq thread (list (car (gnus-id-to-thread id))))
3827       ;; Get the thread this article is part of.
3828       (setq thread (gnus-remove-thread id)))
3829     (setq old-pos (gnus-point-at-bol))
3830     (setq current (save-excursion
3831                     (and (re-search-backward "[\r\n]" nil t)
3832                          (gnus-summary-article-number))))
3833     ;; If this is a gathered thread, we have to go some re-gathering.
3834     (when (stringp (car thread))
3835       (let ((subject (car thread))
3836             roots thr)
3837         (setq thread (cdr thread))
3838         (while thread
3839           (unless (memq (setq thr (gnus-id-to-thread
3840                                    (gnus-root-id
3841                                     (mail-header-id (caar thread)))))
3842                         roots)
3843             (push thr roots))
3844           (setq thread (cdr thread)))
3845         ;; We now have all (unique) roots.
3846         (if (= (length roots) 1)
3847             ;; All the loose roots are now one solid root.
3848             (setq thread (car roots))
3849           (setq thread (cons subject (gnus-sort-threads roots))))))
3850     (let (threads)
3851       ;; We then insert this thread into the summary buffer.
3852       (when line
3853         (goto-char (point-min))
3854         (forward-line (1- line)))
3855       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3856         (if gnus-show-threads
3857             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3858           (gnus-summary-prepare-unthreaded thread))
3859         (setq data (nreverse gnus-newsgroup-data))
3860         (setq threads gnus-newsgroup-threads))
3861       ;; We splice the new data into the data structure.
3862       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3863       ;;!!! then we want to insert at the beginning of the buffer.
3864       ;;!!! That happens to be true with Gnus now, but that may
3865       ;;!!! change in the future.  Perhaps.
3866       (gnus-data-enter-list
3867        (if line nil current) data (- (point) old-pos))
3868       (setq gnus-newsgroup-threads
3869             (nconc threads gnus-newsgroup-threads))
3870       (gnus-data-compute-positions))))
3871
3872 (defun gnus-number-to-header (number)
3873   "Return the header for article NUMBER."
3874   (let ((headers gnus-newsgroup-headers))
3875     (while (and headers
3876                 (not (= number (mail-header-number (car headers)))))
3877       (pop headers))
3878     (when headers
3879       (car headers))))
3880
3881 (defun gnus-parent-headers (in-headers &optional generation)
3882   "Return the headers of the GENERATIONeth parent of HEADERS."
3883   (unless generation
3884     (setq generation 1))
3885   (let ((parent t)
3886         (headers in-headers)
3887         references)
3888     (while (and parent
3889                 (not (zerop generation))
3890                 (setq references (mail-header-references headers)))
3891       (setq headers (if (and references
3892                              (setq parent (gnus-parent-id references)))
3893                         (car (gnus-id-to-thread parent))
3894                       nil))
3895       (decf generation))
3896     (and (not (eq headers in-headers))
3897          headers)))
3898
3899 (defun gnus-id-to-thread (id)
3900   "Return the (sub-)thread where ID appears."
3901   (gnus-gethash id gnus-newsgroup-dependencies))
3902
3903 (defun gnus-id-to-article (id)
3904   "Return the article number of ID."
3905   (let ((thread (gnus-id-to-thread id)))
3906     (when (and thread
3907                (car thread))
3908       (mail-header-number (car thread)))))
3909
3910 (defun gnus-id-to-header (id)
3911   "Return the article headers of ID."
3912   (car (gnus-id-to-thread id)))
3913
3914 (defun gnus-article-displayed-root-p (article)
3915   "Say whether ARTICLE is a root(ish) article."
3916   (let ((level (gnus-summary-thread-level article))
3917         (refs (mail-header-references  (gnus-summary-article-header article)))
3918         particle)
3919     (cond
3920      ((null level) nil)
3921      ((zerop level) t)
3922      ((null refs) t)
3923      ((null (gnus-parent-id refs)) t)
3924      ((and (= 1 level)
3925            (null (setq particle (gnus-id-to-article
3926                                  (gnus-parent-id refs))))
3927            (null (gnus-summary-thread-level particle)))))))
3928
3929 (defun gnus-root-id (id)
3930   "Return the id of the root of the thread where ID appears."
3931   (let (last-id prev)
3932     (while (and id (setq prev (car (gnus-id-to-thread id))))
3933       (setq last-id id
3934             id (gnus-parent-id (mail-header-references prev))))
3935     last-id))
3936
3937 (defun gnus-articles-in-thread (thread)
3938   "Return the list of articles in THREAD."
3939   (cons (mail-header-number (car thread))
3940         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3941
3942 (defun gnus-remove-thread (id &optional dont-remove)
3943   "Remove the thread that has ID in it."
3944   (let (headers thread last-id)
3945     ;; First go up in this thread until we find the root.
3946     (setq last-id (gnus-root-id id)
3947           headers (message-flatten-list (gnus-id-to-thread last-id)))
3948     ;; We have now found the real root of this thread.  It might have
3949     ;; been gathered into some loose thread, so we have to search
3950     ;; through the threads to find the thread we wanted.
3951     (let ((threads gnus-newsgroup-threads)
3952           sub)
3953       (while threads
3954         (setq sub (car threads))
3955         (if (stringp (car sub))
3956             ;; This is a gathered thread, so we look at the roots
3957             ;; below it to find whether this article is in this
3958             ;; gathered root.
3959             (progn
3960               (setq sub (cdr sub))
3961               (while sub
3962                 (when (member (caar sub) headers)
3963                   (setq thread (car threads)
3964                         threads nil
3965                         sub nil))
3966                 (setq sub (cdr sub))))
3967           ;; It's an ordinary thread, so we check it.
3968           (when (eq (car sub) (car headers))
3969             (setq thread sub
3970                   threads nil)))
3971         (setq threads (cdr threads)))
3972       ;; If this article is in no thread, then it's a root.
3973       (if thread
3974           (unless dont-remove
3975             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3976         (setq thread (gnus-id-to-thread last-id)))
3977       (when thread
3978         (prog1
3979             thread                      ; We return this thread.
3980           (unless dont-remove
3981             (if (stringp (car thread))
3982                 (progn
3983                   ;; If we use dummy roots, then we have to remove the
3984                   ;; dummy root as well.
3985                   (when (eq gnus-summary-make-false-root 'dummy)
3986                     ;; We go to the dummy root by going to
3987                     ;; the first sub-"thread", and then one line up.
3988                     (gnus-summary-goto-article
3989                      (mail-header-number (caadr thread)))
3990                     (forward-line -1)
3991                     (gnus-delete-line)
3992                     (gnus-data-compute-positions))
3993                   (setq thread (cdr thread))
3994                   (while thread
3995                     (gnus-remove-thread-1 (car thread))
3996                     (setq thread (cdr thread))))
3997               (gnus-remove-thread-1 thread))))))))
3998
3999 (defun gnus-remove-thread-1 (thread)
4000   "Remove the thread THREAD recursively."
4001   (let ((number (mail-header-number (pop thread)))
4002         d)
4003     (setq thread (reverse thread))
4004     (while thread
4005       (gnus-remove-thread-1 (pop thread)))
4006     (when (setq d (gnus-data-find number))
4007       (goto-char (gnus-data-pos d))
4008       (gnus-summary-show-thread)
4009       (gnus-data-remove
4010        number
4011        (- (gnus-point-at-bol)
4012           (prog1
4013               (1+ (gnus-point-at-eol))
4014             (gnus-delete-line)))))))
4015
4016 (defun gnus-sort-threads-1 (threads func)
4017   (sort (mapcar (lambda (thread)
4018                   (cons (car thread)
4019                         (and (cdr thread)
4020                              (gnus-sort-threads-1 (cdr thread) func))))
4021                 threads) func))
4022
4023 (defun gnus-sort-threads (threads)
4024   "Sort THREADS."
4025   (if (not gnus-thread-sort-functions)
4026       threads
4027     (gnus-message 8 "Sorting threads...")
4028     (prog1
4029         (gnus-sort-threads-1
4030          threads
4031          (gnus-make-sort-function gnus-thread-sort-functions))
4032       (gnus-message 8 "Sorting threads...done"))))
4033
4034 (defun gnus-sort-articles (articles)
4035   "Sort ARTICLES."
4036   (when gnus-article-sort-functions
4037     (gnus-message 7 "Sorting articles...")
4038     (prog1
4039         (setq gnus-newsgroup-headers
4040               (sort articles (gnus-make-sort-function
4041                               gnus-article-sort-functions)))
4042       (gnus-message 7 "Sorting articles...done"))))
4043
4044 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4045 (defmacro gnus-thread-header (thread)
4046   "Return header of first article in THREAD.
4047 Note that THREAD must never, ever be anything else than a variable -
4048 using some other form will lead to serious barfage."
4049   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4050   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4051   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4052         (vector thread) 2))
4053
4054 (defsubst gnus-article-sort-by-number (h1 h2)
4055   "Sort articles by article number."
4056   (< (mail-header-number h1)
4057      (mail-header-number h2)))
4058
4059 (defun gnus-thread-sort-by-number (h1 h2)
4060   "Sort threads by root article number."
4061   (gnus-article-sort-by-number
4062    (gnus-thread-header h1) (gnus-thread-header h2)))
4063
4064 (defsubst gnus-article-sort-by-lines (h1 h2)
4065   "Sort articles by article Lines header."
4066   (< (mail-header-lines h1)
4067      (mail-header-lines h2)))
4068
4069 (defun gnus-thread-sort-by-lines (h1 h2)
4070   "Sort threads by root article Lines header."
4071   (gnus-article-sort-by-lines
4072    (gnus-thread-header h1) (gnus-thread-header h2)))
4073
4074 (defsubst gnus-article-sort-by-chars (h1 h2)
4075   "Sort articles by octet length."
4076   (< (mail-header-chars h1)
4077      (mail-header-chars h2)))
4078
4079 (defun gnus-thread-sort-by-chars (h1 h2)
4080   "Sort threads by root article octet length."
4081   (gnus-article-sort-by-chars
4082    (gnus-thread-header h1) (gnus-thread-header h2)))
4083
4084 (defsubst gnus-article-sort-by-author (h1 h2)
4085   "Sort articles by root author."
4086   (string-lessp
4087    (let ((extract (funcall
4088                    gnus-extract-address-components
4089                    (mail-header-from h1))))
4090      (or (car extract) (cadr extract) ""))
4091    (let ((extract (funcall
4092                    gnus-extract-address-components
4093                    (mail-header-from h2))))
4094      (or (car extract) (cadr extract) ""))))
4095
4096 (defun gnus-thread-sort-by-author (h1 h2)
4097   "Sort threads by root author."
4098   (gnus-article-sort-by-author
4099    (gnus-thread-header h1)  (gnus-thread-header h2)))
4100
4101 (defsubst gnus-article-sort-by-subject (h1 h2)
4102   "Sort articles by root subject."
4103   (string-lessp
4104    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4105    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4106
4107 (defun gnus-thread-sort-by-subject (h1 h2)
4108   "Sort threads by root subject."
4109   (gnus-article-sort-by-subject
4110    (gnus-thread-header h1) (gnus-thread-header h2)))
4111
4112 (defsubst gnus-article-sort-by-date (h1 h2)
4113   "Sort articles by root article date."
4114   (time-less-p
4115    (gnus-date-get-time (mail-header-date h1))
4116    (gnus-date-get-time (mail-header-date h2))))
4117
4118 (defun gnus-thread-sort-by-date (h1 h2)
4119   "Sort threads by root article date."
4120   (gnus-article-sort-by-date
4121    (gnus-thread-header h1) (gnus-thread-header h2)))
4122
4123 (defsubst gnus-article-sort-by-score (h1 h2)
4124   "Sort articles by root article score.
4125 Unscored articles will be counted as having a score of zero."
4126   (> (or (cdr (assq (mail-header-number h1)
4127                     gnus-newsgroup-scored))
4128          gnus-summary-default-score 0)
4129      (or (cdr (assq (mail-header-number h2)
4130                     gnus-newsgroup-scored))
4131          gnus-summary-default-score 0)))
4132
4133 (defun gnus-thread-sort-by-score (h1 h2)
4134   "Sort threads by root article score."
4135   (gnus-article-sort-by-score
4136    (gnus-thread-header h1) (gnus-thread-header h2)))
4137
4138 (defun gnus-thread-sort-by-total-score (h1 h2)
4139   "Sort threads by the sum of all scores in the thread.
4140 Unscored articles will be counted as having a score of zero."
4141   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4142
4143 (defun gnus-thread-total-score (thread)
4144   ;; This function find the total score of THREAD.
4145   (cond ((null thread)
4146          0)
4147         ((consp thread)
4148          (if (stringp (car thread))
4149              (apply gnus-thread-score-function 0
4150                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4151            (gnus-thread-total-score-1 thread)))
4152         (t
4153          (gnus-thread-total-score-1 (list thread)))))
4154
4155 (defun gnus-thread-total-score-1 (root)
4156   ;; This function find the total score of the thread below ROOT.
4157   (setq root (car root))
4158   (apply gnus-thread-score-function
4159          (or (append
4160               (mapcar 'gnus-thread-total-score
4161                       (cdr (gnus-id-to-thread (mail-header-id root))))
4162               (when (> (mail-header-number root) 0)
4163                 (list (or (cdr (assq (mail-header-number root)
4164                                      gnus-newsgroup-scored))
4165                           gnus-summary-default-score 0))))
4166              (list gnus-summary-default-score)
4167              '(0))))
4168
4169 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4170 (defvar gnus-tmp-prev-subject nil)
4171 (defvar gnus-tmp-false-parent nil)
4172 (defvar gnus-tmp-root-expunged nil)
4173 (defvar gnus-tmp-dummy-line nil)
4174
4175 (eval-when-compile (defvar gnus-tmp-header))
4176 (defun gnus-extra-header (type &optional header)
4177   "Return the extra header of TYPE."
4178   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4179       ""))
4180
4181 (defvar gnus-tmp-thread-tree-header-string "")
4182
4183 (defvar gnus-sum-thread-tree-root "> "
4184   "With %B spec, used for the root of a thread.
4185 If nil, use subject instead.")
4186 (defvar gnus-sum-thread-tree-single-indent ""
4187   "With %B spec, used for a thread with just one message.
4188 If nil, use subject instead.")
4189 (defvar gnus-sum-thread-tree-vertical "| "
4190   "With %B spec, used for drawing a vertical line.")
4191 (defvar gnus-sum-thread-tree-indent "  "
4192   "With %B spec, used for indenting.")
4193 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4194   "With %B spec, used for a leaf with brothers.")
4195 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4196   "With %B spec, used for a leaf without brothers.")
4197
4198 (defun gnus-summary-prepare-threads (threads)
4199   "Prepare summary buffer from THREADS and indentation LEVEL.
4200 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4201 or a straight list of headers."
4202   (gnus-message 7 "Generating summary...")
4203
4204   (setq gnus-newsgroup-threads threads)
4205   (beginning-of-line)
4206
4207   (let ((gnus-tmp-level 0)
4208         (default-score (or gnus-summary-default-score 0))
4209         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4210         thread number subject stack state gnus-tmp-gathered beg-match
4211         new-roots gnus-tmp-new-adopts thread-end
4212         gnus-tmp-header gnus-tmp-unread
4213         gnus-tmp-replied gnus-tmp-subject-or-nil
4214         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4215         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4216         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4217         tree-stack)
4218
4219     (setq gnus-tmp-prev-subject nil)
4220
4221     (if (vectorp (car threads))
4222         ;; If this is a straight (sic) list of headers, then a
4223         ;; threaded summary display isn't required, so we just create
4224         ;; an unthreaded one.
4225         (gnus-summary-prepare-unthreaded threads)
4226
4227       ;; Do the threaded display.
4228
4229       (while (or threads stack gnus-tmp-new-adopts new-roots)
4230
4231         (if (and (= gnus-tmp-level 0)
4232                  (or (not stack)
4233                      (= (caar stack) 0))
4234                  (not gnus-tmp-false-parent)
4235                  (or gnus-tmp-new-adopts new-roots))
4236             (if gnus-tmp-new-adopts
4237                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4238                       thread (list (car gnus-tmp-new-adopts))
4239                       gnus-tmp-header (caar thread)
4240                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4241               (when new-roots
4242                 (setq thread (list (car new-roots))
4243                       gnus-tmp-header (caar thread)
4244                       new-roots (cdr new-roots))))
4245
4246           (if threads
4247               ;; If there are some threads, we do them before the
4248               ;; threads on the stack.
4249               (setq thread threads
4250                     gnus-tmp-header (caar thread))
4251             ;; There were no current threads, so we pop something off
4252             ;; the stack.
4253             (setq state (car stack)
4254                   gnus-tmp-level (car state)
4255                   tree-stack (cadr state)
4256                   thread (caddr state)
4257                   stack (cdr stack)
4258                   gnus-tmp-header (caar thread))))
4259
4260         (setq gnus-tmp-false-parent nil)
4261         (setq gnus-tmp-root-expunged nil)
4262         (setq thread-end nil)
4263
4264         (if (stringp gnus-tmp-header)
4265             ;; The header is a dummy root.
4266             (cond
4267              ((eq gnus-summary-make-false-root 'adopt)
4268               ;; We let the first article adopt the rest.
4269               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4270                                                (cddar thread)))
4271               (setq gnus-tmp-gathered
4272                     (nconc (mapcar
4273                             (lambda (h) (mail-header-number (car h)))
4274                             (cddar thread))
4275                            gnus-tmp-gathered))
4276               (setq thread (cons (list (caar thread)
4277                                        (cadar thread))
4278                                  (cdr thread)))
4279               (setq gnus-tmp-level -1
4280                     gnus-tmp-false-parent t))
4281              ((eq gnus-summary-make-false-root 'empty)
4282               ;; We print adopted articles with empty subject fields.
4283               (setq gnus-tmp-gathered
4284                     (nconc (mapcar
4285                             (lambda (h) (mail-header-number (car h)))
4286                             (cddar thread))
4287                            gnus-tmp-gathered))
4288               (setq gnus-tmp-level -1))
4289              ((eq gnus-summary-make-false-root 'dummy)
4290               ;; We remember that we probably want to output a dummy
4291               ;; root.
4292               (setq gnus-tmp-dummy-line gnus-tmp-header)
4293               (setq gnus-tmp-prev-subject gnus-tmp-header))
4294              (t
4295               ;; We do not make a root for the gathered
4296               ;; sub-threads at all.
4297               (setq gnus-tmp-level -1)))
4298
4299           (setq number (mail-header-number gnus-tmp-header)
4300                 subject (mail-header-subject gnus-tmp-header))
4301
4302           (cond
4303            ;; If the thread has changed subject, we might want to make
4304            ;; this subthread into a root.
4305            ((and (null gnus-thread-ignore-subject)
4306                  (not (zerop gnus-tmp-level))
4307                  gnus-tmp-prev-subject
4308                  (not (inline
4309                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4310             (setq new-roots (nconc new-roots (list (car thread)))
4311                   thread-end t
4312                   gnus-tmp-header nil))
4313            ;; If the article lies outside the current limit,
4314            ;; then we do not display it.
4315            ((not (memq number gnus-newsgroup-limit))
4316             (setq gnus-tmp-gathered
4317                   (nconc (mapcar
4318                           (lambda (h) (mail-header-number (car h)))
4319                           (cdar thread))
4320                          gnus-tmp-gathered))
4321             (setq gnus-tmp-new-adopts (if (cdar thread)
4322                                           (append gnus-tmp-new-adopts
4323                                                   (cdar thread))
4324                                         gnus-tmp-new-adopts)
4325                   thread-end t
4326                   gnus-tmp-header nil)
4327             (when (zerop gnus-tmp-level)
4328               (setq gnus-tmp-root-expunged t)))
4329            ;; Perhaps this article is to be marked as read?
4330            ((and gnus-summary-mark-below
4331                  (< (or (cdr (assq number gnus-newsgroup-scored))
4332                         default-score)
4333                     gnus-summary-mark-below)
4334                  ;; Don't touch sparse articles.
4335                  (not (gnus-summary-article-sparse-p number))
4336                  (not (gnus-summary-article-ancient-p number)))
4337             (setq gnus-newsgroup-unreads
4338                   (delq number gnus-newsgroup-unreads))
4339             (if gnus-newsgroup-auto-expire
4340                 (push number gnus-newsgroup-expirable)
4341               (push (cons number gnus-low-score-mark)
4342                     gnus-newsgroup-reads))))
4343
4344           (when gnus-tmp-header
4345             ;; We may have an old dummy line to output before this
4346             ;; article.
4347             (when (and gnus-tmp-dummy-line
4348                        (gnus-subject-equal
4349                         gnus-tmp-dummy-line
4350                         (mail-header-subject gnus-tmp-header)))
4351               (gnus-summary-insert-dummy-line
4352                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4353               (setq gnus-tmp-dummy-line nil))
4354
4355             ;; Compute the mark.
4356             (setq gnus-tmp-unread (gnus-article-mark number))
4357
4358             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4359                                   gnus-tmp-header gnus-tmp-level)
4360                   gnus-newsgroup-data)
4361
4362             ;; Actually insert the line.
4363             (setq
4364              gnus-tmp-subject-or-nil
4365              (cond
4366               ((and gnus-thread-ignore-subject
4367                     gnus-tmp-prev-subject
4368                     (not (inline (gnus-subject-equal
4369                                   gnus-tmp-prev-subject subject))))
4370                subject)
4371               ((zerop gnus-tmp-level)
4372                (if (and (eq gnus-summary-make-false-root 'empty)
4373                         (memq number gnus-tmp-gathered)
4374                         gnus-tmp-prev-subject
4375                         (inline (gnus-subject-equal
4376                                  gnus-tmp-prev-subject subject)))
4377                    gnus-summary-same-subject
4378                  subject))
4379               (t gnus-summary-same-subject)))
4380             (if (and (eq gnus-summary-make-false-root 'adopt)
4381                      (= gnus-tmp-level 1)
4382                      (memq number gnus-tmp-gathered))
4383                 (setq gnus-tmp-opening-bracket ?\<
4384                       gnus-tmp-closing-bracket ?\>)
4385               (setq gnus-tmp-opening-bracket ?\[
4386                     gnus-tmp-closing-bracket ?\]))
4387             (setq
4388              gnus-tmp-indentation
4389              (aref gnus-thread-indent-array gnus-tmp-level)
4390              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4391              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4392                                 gnus-summary-default-score 0)
4393              gnus-tmp-score-char
4394              (if (or (null gnus-summary-default-score)
4395                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4396                          gnus-summary-zcore-fuzz))
4397                  ?                      ;Whitespace
4398                (if (< gnus-tmp-score gnus-summary-default-score)
4399                    gnus-score-below-mark gnus-score-over-mark))
4400              gnus-tmp-replied
4401              (cond ((memq number gnus-newsgroup-processable)
4402                     gnus-process-mark)
4403                    ((memq number gnus-newsgroup-cached)
4404                     gnus-cached-mark)
4405                    ((memq number gnus-newsgroup-replied)
4406                     gnus-replied-mark)
4407                    ((memq number gnus-newsgroup-forwarded)
4408                     gnus-forwarded-mark)
4409                    ((memq number gnus-newsgroup-saved)
4410                     gnus-saved-mark)
4411                    ((memq number gnus-newsgroup-recent)
4412                     gnus-recent-mark)
4413                    ((memq number gnus-newsgroup-unseen)
4414                     gnus-unseen-mark)
4415                    (t gnus-no-mark))
4416              gnus-tmp-from (mail-header-from gnus-tmp-header)
4417              gnus-tmp-name
4418              (cond
4419               ((string-match "<[^>]+> *$" gnus-tmp-from)
4420                (setq beg-match (match-beginning 0))
4421                (or (and (string-match "^\".+\"" gnus-tmp-from)
4422                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4423                    (substring gnus-tmp-from 0 beg-match)))
4424               ((string-match "(.+)" gnus-tmp-from)
4425                (substring gnus-tmp-from
4426                           (1+ (match-beginning 0)) (1- (match-end 0))))
4427               (t gnus-tmp-from))
4428              gnus-tmp-thread-tree-header-string
4429              (cond
4430               ((not gnus-show-threads) "")
4431               ((zerop gnus-tmp-level)
4432                (if (cdar thread)
4433                    (or gnus-sum-thread-tree-root subject)
4434                  (or gnus-sum-thread-tree-single-indent subject)))
4435               (t
4436                (concat (apply 'concat
4437                               (mapcar (lambda (item)
4438                                         (if (= item 1)
4439                                             gnus-sum-thread-tree-vertical
4440                                           gnus-sum-thread-tree-indent))
4441                                       (cdr (reverse tree-stack))))
4442                        (if (nth 1 thread)
4443                            gnus-sum-thread-tree-leaf-with-other
4444                          gnus-sum-thread-tree-single-leaf)))))
4445             (when (string= gnus-tmp-name "")
4446               (setq gnus-tmp-name gnus-tmp-from))
4447             (unless (numberp gnus-tmp-lines)
4448               (setq gnus-tmp-lines -1))
4449             (if (= gnus-tmp-lines -1)
4450                 (setq gnus-tmp-lines "?")
4451               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4452             (gnus-put-text-property
4453              (point)
4454              (progn (eval gnus-summary-line-format-spec) (point))
4455              'gnus-number number)
4456             (when gnus-visual-p
4457               (forward-line -1)
4458               (gnus-run-hooks 'gnus-summary-update-hook)
4459               (forward-line 1))
4460
4461             (setq gnus-tmp-prev-subject subject)))
4462
4463         (when (nth 1 thread)
4464           (push (list (max 0 gnus-tmp-level)
4465                       (copy-list tree-stack)
4466                       (nthcdr 1 thread))
4467                 stack))
4468         (push (if (nth 1 thread) 1 0) tree-stack)
4469         (incf gnus-tmp-level)
4470         (setq threads (if thread-end nil (cdar thread)))
4471         (unless threads
4472           (setq gnus-tmp-level 0)))))
4473   (gnus-message 7 "Generating summary...done"))
4474
4475 (defun gnus-summary-prepare-unthreaded (headers)
4476   "Generate an unthreaded summary buffer based on HEADERS."
4477   (let (header number mark)
4478
4479     (beginning-of-line)
4480
4481     (while headers
4482       ;; We may have to root out some bad articles...
4483       (when (memq (setq number (mail-header-number
4484                                 (setq header (pop headers))))
4485                   gnus-newsgroup-limit)
4486         ;; Mark article as read when it has a low score.
4487         (when (and gnus-summary-mark-below
4488                    (< (or (cdr (assq number gnus-newsgroup-scored))
4489                           gnus-summary-default-score 0)
4490                       gnus-summary-mark-below)
4491                    (not (gnus-summary-article-ancient-p number)))
4492           (setq gnus-newsgroup-unreads
4493                 (delq number gnus-newsgroup-unreads))
4494           (if gnus-newsgroup-auto-expire
4495               (push number gnus-newsgroup-expirable)
4496             (push (cons number gnus-low-score-mark)
4497                   gnus-newsgroup-reads)))
4498
4499         (setq mark (gnus-article-mark number))
4500         (push (gnus-data-make number mark (1+ (point)) header 0)
4501               gnus-newsgroup-data)
4502         (gnus-summary-insert-line
4503          header 0 number
4504          mark (memq number gnus-newsgroup-replied)
4505          (memq number gnus-newsgroup-expirable)
4506          (mail-header-subject header) nil
4507          (cdr (assq number gnus-newsgroup-scored))
4508          (memq number gnus-newsgroup-processable))))))
4509
4510 (defun gnus-summary-remove-list-identifiers ()
4511   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4512   (let ((regexp (if (consp gnus-list-identifiers)
4513                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4514                   gnus-list-identifiers))
4515         changed subject)
4516     (when regexp
4517       (dolist (header gnus-newsgroup-headers)
4518         (setq subject (mail-header-subject header)
4519               changed nil)
4520         (while (string-match
4521                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4522                 subject)
4523           (setq subject
4524                 (concat (substring subject 0 (match-beginning 2))
4525                         (substring subject (match-end 0)))
4526                 changed t))
4527         (when (and changed
4528                    (string-match
4529                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4530           (setq subject
4531                 (concat (substring subject 0 (match-beginning 1))
4532                         (substring subject (match-end 1)))))
4533         (when changed
4534           (mail-header-set-subject header subject))))))
4535
4536 (defun gnus-fetch-headers (articles)
4537   "Fetch headers of ARTICLES."
4538   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4539     (gnus-message 5 "Fetching headers for %s..." name)
4540     (prog1
4541         (if (eq 'nov
4542                 (setq gnus-headers-retrieved-by
4543                       (gnus-retrieve-headers
4544                        articles gnus-newsgroup-name
4545                        ;; We might want to fetch old headers, but
4546                        ;; not if there is only 1 article.
4547                        (and (or (and
4548                                  (not (eq gnus-fetch-old-headers 'some))
4549                                  (not (numberp gnus-fetch-old-headers)))
4550                                 (> (length articles) 1))
4551                             gnus-fetch-old-headers))))
4552             (gnus-get-newsgroup-headers-xover
4553              articles nil nil gnus-newsgroup-name t)
4554           (gnus-get-newsgroup-headers))
4555       (gnus-message 5 "Fetching headers for %s...done" name))))
4556
4557 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4558   "Select newsgroup GROUP.
4559 If READ-ALL is non-nil, all articles in the group are selected.
4560 If SELECT-ARTICLES, only select those articles from GROUP."
4561   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4562          ;;!!! Dirty hack; should be removed.
4563          (gnus-summary-ignore-duplicates
4564           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4565               t
4566             gnus-summary-ignore-duplicates))
4567          (info (nth 2 entry))
4568          articles fetched-articles cached)
4569
4570     (unless (gnus-check-server
4571              (set (make-local-variable 'gnus-current-select-method)
4572                   (gnus-find-method-for-group group)))
4573       (error "Couldn't open server"))
4574
4575     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4576         (gnus-activate-group group)     ; Or we can activate it...
4577         (progn                          ; Or we bug out.
4578           (when (equal major-mode 'gnus-summary-mode)
4579             (kill-buffer (current-buffer)))
4580           (error "Couldn't activate group %s: %s"
4581                  group (gnus-status-message group))))
4582
4583     (unless (gnus-request-group group t)
4584       (when (equal major-mode 'gnus-summary-mode)
4585         (kill-buffer (current-buffer)))
4586       (error "Couldn't request group %s: %s"
4587              group (gnus-status-message group)))
4588
4589     (setq gnus-newsgroup-name group
4590           gnus-newsgroup-unselected nil
4591           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4592
4593     (let ((display (gnus-group-find-parameter group 'display)))
4594       (setq gnus-newsgroup-display
4595             (cond
4596              ((not (zerop (or (car-safe read-all) 0)))
4597               ;; The user entered the group with C-u SPC/RET, let's show
4598               ;; all articles.
4599               'gnus-not-ignore)
4600              ((eq display 'all)
4601               'gnus-not-ignore)
4602              ((arrayp display)
4603               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4604              ((numberp display)
4605               ;; The following is probably the "correct" solution, but
4606               ;; it makes Gnus fetch all headers and then limit the
4607               ;; articles (which is slow), so instead we hack the
4608               ;; select-articles parameter instead. -- Simon Josefsson
4609               ;; <jas@kth.se>
4610               ;;
4611               ;; (gnus-byte-compile
4612               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4613               ;;                         display)))))
4614               (setq select-articles
4615                     (gnus-uncompress-range
4616                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4617                              (if (> tmp 0)
4618                                  tmp
4619                                1))
4620                            (cdr (gnus-active group)))))
4621               nil)
4622              (t
4623               nil))))
4624
4625     (gnus-summary-setup-default-charset)
4626
4627     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4628     (when (gnus-virtual-group-p group)
4629       (setq cached gnus-newsgroup-cached))
4630
4631     (setq gnus-newsgroup-unreads
4632           (gnus-set-difference
4633            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4634            gnus-newsgroup-dormant))
4635
4636     (setq gnus-newsgroup-processable nil)
4637
4638     (gnus-update-read-articles group gnus-newsgroup-unreads)
4639
4640     ;; Adjust and set lists of article marks.
4641     (when info
4642       (gnus-adjust-marked-articles info))
4643
4644     (if (setq articles select-articles)
4645         (setq gnus-newsgroup-unselected
4646               (gnus-sorted-intersection
4647                gnus-newsgroup-unreads
4648                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4649       (setq articles (gnus-articles-to-read group read-all)))
4650
4651     (cond
4652      ((null articles)
4653       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4654       'quit)
4655      ((eq articles 0) nil)
4656      (t
4657       ;; Init the dependencies hash table.
4658       (setq gnus-newsgroup-dependencies
4659             (gnus-make-hashtable (length articles)))
4660       (gnus-set-global-variables)
4661       ;; Retrieve the headers and read them in.
4662       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4663
4664       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4665       (when cached
4666         (setq gnus-newsgroup-cached cached))
4667
4668       ;; Suppress duplicates?
4669       (when gnus-suppress-duplicates
4670         (gnus-dup-suppress-articles))
4671
4672       ;; Set the initial limit.
4673       (setq gnus-newsgroup-limit (copy-sequence articles))
4674       ;; Remove canceled articles from the list of unread articles.
4675       (setq fetched-articles
4676             (mapcar (lambda (headers) (mail-header-number headers))
4677                     gnus-newsgroup-headers))
4678       (setq gnus-newsgroup-articles fetched-articles)
4679       (setq gnus-newsgroup-unreads
4680             (gnus-set-sorted-intersection
4681              gnus-newsgroup-unreads fetched-articles))
4682
4683       ;; The `seen' marks are treated specially.
4684       (if (not gnus-newsgroup-seen)
4685           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4686         (dolist (article gnus-newsgroup-articles)
4687           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4688             (push article gnus-newsgroup-unseen)))
4689         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4690
4691       ;; Removed marked articles that do not exist.
4692       (gnus-update-missing-marks
4693        (gnus-sorted-complement fetched-articles articles))
4694       ;; We might want to build some more threads first.
4695       (when (and gnus-fetch-old-headers
4696                  (eq gnus-headers-retrieved-by 'nov))
4697         (if (eq gnus-fetch-old-headers 'invisible)
4698             (gnus-build-all-threads)
4699           (gnus-build-old-threads)))
4700       ;; Let the Gnus agent mark articles as read.
4701       (when gnus-agent
4702         (gnus-agent-get-undownloaded-list))
4703       ;; Remove list identifiers from subject
4704       (when gnus-list-identifiers
4705         (gnus-summary-remove-list-identifiers))
4706       ;; Check whether auto-expire is to be done in this group.
4707       (setq gnus-newsgroup-auto-expire
4708             (gnus-group-auto-expirable-p group))
4709       ;; Set up the article buffer now, if necessary.
4710       (unless gnus-single-article-buffer
4711         (gnus-article-setup-buffer))
4712       ;; First and last article in this newsgroup.
4713       (when gnus-newsgroup-headers
4714         (setq gnus-newsgroup-begin
4715               (mail-header-number (car gnus-newsgroup-headers))
4716               gnus-newsgroup-end
4717               (mail-header-number
4718                (gnus-last-element gnus-newsgroup-headers))))
4719       ;; GROUP is successfully selected.
4720       (or gnus-newsgroup-headers t)))))
4721
4722 (defun gnus-summary-display-make-predicate (display)
4723   (require 'gnus-agent)
4724   (when (= (length display) 1)
4725     (setq display (car display)))
4726   (unless gnus-summary-display-cache
4727     (dolist (elem (append (list (cons 'read 'read)
4728                                 (cons 'unseen 'unseen))
4729                           gnus-article-mark-lists))
4730       (push (cons (cdr elem)
4731                   (gnus-byte-compile
4732                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4733             gnus-summary-display-cache)))
4734   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4735     (gnus-get-predicate display)))
4736
4737 ;; Uses the dynamically bound `number' variable.
4738 (defvar number)
4739 (defun gnus-article-marked-p (type &optional article)
4740   (let ((article (or article number)))
4741     (cond
4742      ((eq type 'tick)
4743       (memq article gnus-newsgroup-marked))
4744      ((eq type 'unsend)
4745       (memq article gnus-newsgroup-unsendable))
4746      ((eq type 'undownload)
4747       (memq article gnus-newsgroup-undownloaded))
4748      ((eq type 'download)
4749       (memq article gnus-newsgroup-downloadable))
4750      ((eq type 'unread)
4751       (memq article gnus-newsgroup-unreads))
4752      ((eq type 'read)
4753       (memq article gnus-newsgroup-reads))
4754      ((eq type 'dormant)
4755       (memq article gnus-newsgroup-dormant) )
4756      ((eq type 'expire)
4757       (memq article gnus-newsgroup-expirable))
4758      ((eq type 'reply)
4759       (memq article gnus-newsgroup-replied))
4760      ((eq type 'killed)
4761       (memq article gnus-newsgroup-killed))
4762      ((eq type 'bookmark)
4763       (assq article gnus-newsgroup-bookmarks))
4764      ((eq type 'score)
4765       (assq article gnus-newsgroup-scored))
4766      ((eq type 'save)
4767       (memq article gnus-newsgroup-saved))
4768      ((eq type 'cache)
4769       (memq article gnus-newsgroup-cached))
4770      ((eq type 'forward)
4771       (memq article gnus-newsgroup-forwarded))
4772      ((eq type 'seen)
4773       (not (memq article gnus-newsgroup-unseen)))
4774      ((eq type 'recent)
4775       (memq article gnus-newsgroup-recent))
4776      (t t))))
4777
4778 (defun gnus-articles-to-read (group &optional read-all)
4779   "Find out what articles the user wants to read."
4780   (let* ((articles
4781           ;; Select all articles if `read-all' is non-nil, or if there
4782           ;; are no unread articles.
4783           (if (or read-all
4784                   (and (zerop (length gnus-newsgroup-marked))
4785                        (zerop (length gnus-newsgroup-unreads)))
4786                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4787               ;; We want to select the headers for all the articles in
4788               ;; the group, so we select either all the active
4789               ;; articles in the group, or (if that's nil), the
4790               ;; articles in the cache.
4791               (or
4792                (gnus-uncompress-range (gnus-active group))
4793                (gnus-cache-articles-in-group group))
4794             ;; Select only the "normal" subset of articles.
4795             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4796                           (copy-sequence gnus-newsgroup-unreads))
4797                   '<)))
4798          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4799          (scored (length scored-list))
4800          (number (length articles))
4801          (marked (+ (length gnus-newsgroup-marked)
4802                     (length gnus-newsgroup-dormant)))
4803          (select
4804           (cond
4805            ((numberp read-all)
4806             read-all)
4807            (t
4808             (condition-case ()
4809                 (cond
4810                  ((and (or (<= scored marked) (= scored number))
4811                        (numberp gnus-large-newsgroup)
4812                        (> number gnus-large-newsgroup))
4813                   (let ((input
4814                          (read-string
4815                           (format
4816                            "How many articles from %s (default %d): "
4817                            (gnus-limit-string
4818                             (gnus-group-decoded-name gnus-newsgroup-name)
4819                             35)
4820                            number))))
4821                     (if (string-match "^[ \t]*$" input) number input)))
4822                  ((and (> scored marked) (< scored number)
4823                        (> (- scored number) 20))
4824                   (let ((input
4825                          (read-string
4826                           (format "%s %s (%d scored, %d total): "
4827                                   "How many articles from"
4828                                   (gnus-group-decoded-name group)
4829                                   scored number))))
4830                     (if (string-match "^[ \t]*$" input)
4831                         number input)))
4832                  (t number))
4833               (quit
4834                (message "Quit getting the articles to read")
4835                nil))))))
4836     (setq select (if (stringp select) (string-to-number select) select))
4837     (if (or (null select) (zerop select))
4838         select
4839       (if (and (not (zerop scored)) (<= (abs select) scored))
4840           (progn
4841             (setq articles (sort scored-list '<))
4842             (setq number (length articles)))
4843         (setq articles (copy-sequence articles)))
4844
4845       (when (< (abs select) number)
4846         (if (< select 0)
4847             ;; Select the N oldest articles.
4848             (setcdr (nthcdr (1- (abs select)) articles) nil)
4849           ;; Select the N most recent articles.
4850           (setq articles (nthcdr (- number select) articles))))
4851       (setq gnus-newsgroup-unselected
4852             (gnus-sorted-intersection
4853              gnus-newsgroup-unreads
4854              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4855       (when gnus-alter-articles-to-read-function
4856         (setq gnus-newsgroup-unreads
4857               (sort
4858                (funcall gnus-alter-articles-to-read-function
4859                         gnus-newsgroup-name gnus-newsgroup-unreads)
4860                '<)))
4861       articles)))
4862
4863 (defun gnus-killed-articles (killed articles)
4864   (let (out)
4865     (while articles
4866       (when (inline (gnus-member-of-range (car articles) killed))
4867         (push (car articles) out))
4868       (setq articles (cdr articles)))
4869     out))
4870
4871 (defun gnus-uncompress-marks (marks)
4872   "Uncompress the mark ranges in MARKS."
4873   (let ((uncompressed '(score bookmark))
4874         out)
4875     (while marks
4876       (if (memq (caar marks) uncompressed)
4877           (push (car marks) out)
4878         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4879       (setq marks (cdr marks)))
4880     out))
4881
4882 (defun gnus-article-mark-to-type (mark)
4883   "Return the type of MARK."
4884   (or (cadr (assq mark gnus-article-special-mark-lists))
4885       'list))
4886
4887 (defun gnus-article-unpropagatable-p (mark)
4888   "Return whether MARK should be propagated to backend."
4889   (memq mark gnus-article-unpropagated-mark-lists))
4890
4891 (defun gnus-adjust-marked-articles (info)
4892   "Set all article lists and remove all marks that are no longer valid."
4893   (let* ((marked-lists (gnus-info-marks info))
4894          (active (gnus-active (gnus-info-group info)))
4895          (min (car active))
4896          (max (cdr active))
4897          (types gnus-article-mark-lists)
4898          marks var articles article mark mark-type)
4899
4900     (dolist (marks marked-lists)
4901       (setq mark (car marks)
4902             mark-type (gnus-article-mark-to-type mark)
4903             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4904
4905       ;; We set the variable according to the type of the marks list,
4906       ;; and then adjust the marks to a subset of the active articles.
4907       (cond
4908        ;; Adjust "simple" lists.
4909        ((eq mark-type 'list)
4910         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4911         (when (memq mark '(tick dormant expire reply save))
4912           (while articles
4913             (when (or (< (setq article (pop articles)) min) (> article max))
4914               (set var (delq article (symbol-value var)))))))
4915        ;; Adjust assocs.
4916        ((eq mark-type 'tuple)
4917         (set var (setq articles (cdr marks)))
4918         (when (not (listp (cdr (symbol-value var))))
4919           (set var (list (symbol-value var))))
4920         (when (not (listp (cdr articles)))
4921           (setq articles (list articles)))
4922         (while articles
4923           (when (or (not (consp (setq article (pop articles))))
4924                     (< (car article) min)
4925                     (> (car article) max))
4926             (set var (delq article (symbol-value var))))))
4927        ;; Adjust ranges (sloppily).
4928        ((eq mark-type 'range)
4929         (cond
4930          ((eq mark 'seen)
4931           (setq articles (cdr marks))
4932           (while (and articles
4933                       (or (and (consp (car articles))
4934                                (> min (cdar articles)))
4935                           (and (numberp (car articles))
4936                                (> min (car articles)))))
4937             (pop articles))
4938           (set var articles))))))))
4939
4940 (defun gnus-update-missing-marks (missing)
4941   "Go through the list of MISSING articles and remove them from the mark lists."
4942   (when missing
4943     (let (var m)
4944       ;; Go through all types.
4945       (dolist (elem gnus-article-mark-lists)
4946         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4947           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4948           (when (symbol-value var)
4949             ;; This list has articles.  So we delete all missing
4950             ;; articles from it.
4951             (setq m missing)
4952             (while m
4953               (set var (delq (pop m) (symbol-value var))))))))))
4954
4955 (defun gnus-update-marks ()
4956   "Enter the various lists of marked articles into the newsgroup info list."
4957   (let ((types gnus-article-mark-lists)
4958         (info (gnus-get-info gnus-newsgroup-name))
4959         type list newmarked symbol delta-marks)
4960     (when info
4961       ;; Add all marks lists to the list of marks lists.
4962       (while (setq type (pop types))
4963         (setq list (symbol-value
4964                     (setq symbol
4965                           (intern (format "gnus-newsgroup-%s" (car type))))))
4966
4967         (when list
4968           ;; Get rid of the entries of the articles that have the
4969           ;; default score.
4970           (when (and (eq (cdr type) 'score)
4971                      gnus-save-score
4972                      list)
4973             (let* ((arts list)
4974                    (prev (cons nil list))
4975                    (all prev))
4976               (while arts
4977                 (if (or (not (consp (car arts)))
4978                         (= (cdar arts) gnus-summary-default-score))
4979                     (setcdr prev (cdr arts))
4980                   (setq prev arts))
4981                 (setq arts (cdr arts)))
4982               (setq list (cdr all)))))
4983
4984         (when (eq (cdr type) 'seen)
4985           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
4986
4987         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4988           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4989
4990         (when (and (gnus-check-backend-function
4991                     'request-set-mark gnus-newsgroup-name)
4992                    (not (gnus-article-unpropagatable-p (cdr type))))
4993           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4994                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4995                  (add (gnus-remove-from-range
4996                        (gnus-copy-sequence list) old)))
4997             (when add
4998               (push (list add 'add (list (cdr type))) delta-marks))
4999             (when del
5000               (push (list del 'del (list (cdr type))) delta-marks))))
5001
5002         (when list
5003           (push (cons (cdr type) list) newmarked)))
5004
5005       (when delta-marks
5006         (unless (gnus-check-group gnus-newsgroup-name)
5007           (error "Can't open server for %s" gnus-newsgroup-name))
5008         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5009
5010       ;; Enter these new marks into the info of the group.
5011       (if (nthcdr 3 info)
5012           (setcar (nthcdr 3 info) newmarked)
5013         ;; Add the marks lists to the end of the info.
5014         (when newmarked
5015           (setcdr (nthcdr 2 info) (list newmarked))))
5016
5017       ;; Cut off the end of the info if there's nothing else there.
5018       (let ((i 5))
5019         (while (and (> i 2)
5020                     (not (nth i info)))
5021           (when (nthcdr (decf i) info)
5022             (setcdr (nthcdr i info) nil)))))))
5023
5024 (defun gnus-set-mode-line (where)
5025   "Set the mode line of the article or summary buffers.
5026 If WHERE is `summary', the summary mode line format will be used."
5027   ;; Is this mode line one we keep updated?
5028   (when (and (memq where gnus-updated-mode-lines)
5029              (symbol-value
5030               (intern (format "gnus-%s-mode-line-format-spec" where))))
5031     (let (mode-string)
5032       (save-excursion
5033         ;; We evaluate this in the summary buffer since these
5034         ;; variables are buffer-local to that buffer.
5035         (set-buffer gnus-summary-buffer)
5036        ;; We bind all these variables that are used in the `eval' form
5037         ;; below.
5038         (let* ((mformat (symbol-value
5039                          (intern
5040                           (format "gnus-%s-mode-line-format-spec" where))))
5041                (gnus-tmp-group-name (gnus-group-decoded-name
5042                                      gnus-newsgroup-name))
5043                (gnus-tmp-article-number (or gnus-current-article 0))
5044                (gnus-tmp-unread gnus-newsgroup-unreads)
5045                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5046                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5047                (gnus-tmp-unread-and-unselected
5048                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5049                             (zerop gnus-tmp-unselected))
5050                        "")
5051                       ((zerop gnus-tmp-unselected)
5052                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5053                       (t (format "{%d(+%d) more}"
5054                                  gnus-tmp-unread-and-unticked
5055                                  gnus-tmp-unselected))))
5056                (gnus-tmp-subject
5057                 (if (and gnus-current-headers
5058                          (vectorp gnus-current-headers))
5059                     (gnus-mode-string-quote
5060                      (mail-header-subject gnus-current-headers))
5061                   ""))
5062                bufname-length max-len
5063                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5064           (setq mode-string (eval mformat))
5065           (setq bufname-length (if (string-match "%b" mode-string)
5066                                    (- (length
5067                                        (buffer-name
5068                                         (if (eq where 'summary)
5069                                             nil
5070                                           (get-buffer gnus-article-buffer))))
5071                                       2)
5072                                  0))
5073           (setq max-len (max 4 (if gnus-mode-non-string-length
5074                                    (- (window-width)
5075                                       gnus-mode-non-string-length
5076                                       bufname-length)
5077                                  (length mode-string))))
5078           ;; We might have to chop a bit of the string off...
5079           (when (> (length mode-string) max-len)
5080             (setq mode-string
5081                   (concat (truncate-string-to-width mode-string (- max-len 3))
5082                           "...")))
5083           ;; Pad the mode string a bit.
5084           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5085       ;; Update the mode line.
5086       (setq mode-line-buffer-identification
5087             (gnus-mode-line-buffer-identification (list mode-string)))
5088       (set-buffer-modified-p t))))
5089
5090 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5091   "Go through the HEADERS list and add all Xrefs to a hash table.
5092 The resulting hash table is returned, or nil if no Xrefs were found."
5093   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5094          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5095          (xref-hashtb (gnus-make-hashtable))
5096          start group entry number xrefs header)
5097     (while headers
5098       (setq header (pop headers))
5099       (when (and (setq xrefs (mail-header-xref header))
5100                  (not (memq (setq number (mail-header-number header))
5101                             unreads)))
5102         (setq start 0)
5103         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5104           (setq start (match-end 0))
5105           (setq group (if prefix
5106                           (concat prefix (substring xrefs (match-beginning 1)
5107                                                     (match-end 1)))
5108                         (substring xrefs (match-beginning 1) (match-end 1))))
5109           (setq number
5110                 (string-to-int (substring xrefs (match-beginning 2)
5111                                           (match-end 2))))
5112           (if (setq entry (gnus-gethash group xref-hashtb))
5113               (setcdr entry (cons number (cdr entry)))
5114             (gnus-sethash group (cons number nil) xref-hashtb)))))
5115     (and start xref-hashtb)))
5116
5117 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5118   "Look through all the headers and mark the Xrefs as read."
5119   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5120         name entry info xref-hashtb idlist method nth4)
5121     (save-excursion
5122       (set-buffer gnus-group-buffer)
5123       (when (setq xref-hashtb
5124                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5125         (mapatoms
5126          (lambda (group)
5127            (unless (string= from-newsgroup (setq name (symbol-name group)))
5128              (setq idlist (symbol-value group))
5129              ;; Dead groups are not updated.
5130              (and (prog1
5131                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5132                             info (nth 2 entry))
5133                     (when (stringp (setq nth4 (gnus-info-method info)))
5134                       (setq nth4 (gnus-server-to-method nth4))))
5135                   ;; Only do the xrefs if the group has the same
5136                   ;; select method as the group we have just read.
5137                   (or (gnus-methods-equal-p
5138                        nth4 (gnus-find-method-for-group from-newsgroup))
5139                       virtual
5140                       (equal nth4 (setq method (gnus-find-method-for-group
5141                                                 from-newsgroup)))
5142                       (and (equal (car nth4) (car method))
5143                            (equal (nth 1 nth4) (nth 1 method))))
5144                   gnus-use-cross-reference
5145                   (or (not (eq gnus-use-cross-reference t))
5146                       virtual
5147                       ;; Only do cross-references on subscribed
5148                       ;; groups, if that is what is wanted.
5149                       (<= (gnus-info-level info) gnus-level-subscribed))
5150                   (gnus-group-make-articles-read name idlist))))
5151          xref-hashtb)))))
5152
5153 (defun gnus-compute-read-articles (group articles)
5154   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5155          (info (nth 2 entry))
5156          (active (gnus-active group))
5157          ninfo)
5158     (when entry
5159       ;; First peel off all invalid article numbers.
5160       (when active
5161         (let ((ids articles)
5162               id first)
5163           (while (setq id (pop ids))
5164             (when (and first (> id (cdr active)))
5165               ;; We'll end up in this situation in one particular
5166               ;; obscure situation.  If you re-scan a group and get
5167               ;; a new article that is cross-posted to a different
5168               ;; group that has not been re-scanned, you might get
5169               ;; crossposted article that has a higher number than
5170               ;; Gnus believes possible.  So we re-activate this
5171               ;; group as well.  This might mean doing the
5172               ;; crossposting thingy will *increase* the number
5173               ;; of articles in some groups.  Tsk, tsk.
5174               (setq active (or (gnus-activate-group group) active)))
5175             (when (or (> id (cdr active))
5176                       (< id (car active)))
5177               (setq articles (delq id articles))))))
5178       ;; If the read list is nil, we init it.
5179       (if (and active
5180                (null (gnus-info-read info))
5181                (> (car active) 1))
5182           (setq ninfo (cons 1 (1- (car active))))
5183         (setq ninfo (gnus-info-read info)))
5184       ;; Then we add the read articles to the range.
5185       (gnus-add-to-range
5186        ninfo (setq articles (sort articles '<))))))
5187
5188 (defun gnus-group-make-articles-read (group articles)
5189   "Update the info of GROUP to say that ARTICLES are read."
5190   (let* ((num 0)
5191          (entry (gnus-gethash group gnus-newsrc-hashtb))
5192          (info (nth 2 entry))
5193          (active (gnus-active group))
5194          range)
5195     (when entry
5196       (setq range (gnus-compute-read-articles group articles))
5197       (save-excursion
5198         (set-buffer gnus-group-buffer)
5199         (gnus-undo-register
5200           `(progn
5201              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5202              (gnus-info-set-read ',info ',(gnus-info-read info))
5203              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5204              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5205              (gnus-group-update-group ,group t))))
5206       ;; Add the read articles to the range.
5207       (gnus-info-set-read info range)
5208       (gnus-request-set-mark group (list (list range 'add '(read))))
5209       ;; Then we have to re-compute how many unread
5210       ;; articles there are in this group.
5211       (when active
5212         (cond
5213          ((not range)
5214           (setq num (- (1+ (cdr active)) (car active))))
5215          ((not (listp (cdr range)))
5216           (setq num (- (cdr active) (- (1+ (cdr range))
5217                                        (car range)))))
5218          (t
5219           (while range
5220             (if (numberp (car range))
5221                 (setq num (1+ num))
5222               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5223             (setq range (cdr range)))
5224           (setq num (- (cdr active) num))))
5225         ;; Update the number of unread articles.
5226         (setcar entry num)
5227         ;; Update the group buffer.
5228         (gnus-group-update-group group t)))))
5229
5230 (defvar gnus-newsgroup-none-id 0)
5231
5232 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5233   (let ((cur nntp-server-buffer)
5234         (dependencies
5235          (or dependencies
5236              (save-excursion (set-buffer gnus-summary-buffer)
5237                              gnus-newsgroup-dependencies)))
5238         headers id end ref
5239         (mail-parse-charset gnus-newsgroup-charset)
5240         (mail-parse-ignored-charsets
5241          (save-excursion (condition-case nil
5242                              (set-buffer gnus-summary-buffer)
5243                            (error))
5244                          gnus-newsgroup-ignored-charsets)))
5245     (save-excursion
5246       (set-buffer nntp-server-buffer)
5247       ;; Translate all TAB characters into SPACE characters.
5248       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5249       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5250       (gnus-run-hooks 'gnus-parse-headers-hook)
5251       (let ((case-fold-search t)
5252             in-reply-to header p lines chars)
5253         (goto-char (point-min))
5254         ;; Search to the beginning of the next header.  Error messages
5255         ;; do not begin with 2 or 3.
5256         (while (re-search-forward "^[23][0-9]+ " nil t)
5257           (setq id nil
5258                 ref nil)
5259           ;; This implementation of this function, with nine
5260           ;; search-forwards instead of the one re-search-forward and
5261           ;; a case (which basically was the old function) is actually
5262           ;; about twice as fast, even though it looks messier.  You
5263           ;; can't have everything, I guess.  Speed and elegance
5264           ;; doesn't always go hand in hand.
5265           (setq
5266            header
5267            (vector
5268             ;; Number.
5269             (prog1
5270                 (read cur)
5271               (end-of-line)
5272               (setq p (point))
5273               (narrow-to-region (point)
5274                                 (or (and (search-forward "\n.\n" nil t)
5275                                          (- (point) 2))
5276                                     (point))))
5277             ;; Subject.
5278             (progn
5279               (goto-char p)
5280               (if (search-forward "\nsubject:" nil t)
5281                   (funcall gnus-decode-encoded-word-function
5282                            (nnheader-header-value))
5283                 "(none)"))
5284             ;; From.
5285             (progn
5286               (goto-char p)
5287               (if (search-forward "\nfrom:" nil t)
5288                   (funcall gnus-decode-encoded-word-function
5289                            (nnheader-header-value))
5290                 "(nobody)"))
5291             ;; Date.
5292             (progn
5293               (goto-char p)
5294               (if (search-forward "\ndate:" nil t)
5295                   (nnheader-header-value) ""))
5296             ;; Message-ID.
5297             (progn
5298               (goto-char p)
5299               (setq id (if (re-search-forward
5300                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5301                            ;; We do it this way to make sure the Message-ID
5302                            ;; is (somewhat) syntactically valid.
5303                            (buffer-substring (match-beginning 1)
5304                                              (match-end 1))
5305                          ;; If there was no message-id, we just fake one
5306                          ;; to make subsequent routines simpler.
5307                          (nnheader-generate-fake-message-id))))
5308             ;; References.
5309             (progn
5310               (goto-char p)
5311               (if (search-forward "\nreferences:" nil t)
5312                   (progn
5313                     (setq end (point))
5314                     (prog1
5315                         (nnheader-header-value)
5316                       (setq ref
5317                             (buffer-substring
5318                              (progn
5319                                (end-of-line)
5320                                (search-backward ">" end t)
5321                                (1+ (point)))
5322                              (progn
5323                                (search-backward "<" end t)
5324                                (point))))))
5325                 ;; Get the references from the in-reply-to header if there
5326                 ;; were no references and the in-reply-to header looks
5327                 ;; promising.
5328                 (if (and (search-forward "\nin-reply-to:" nil t)
5329                          (setq in-reply-to (nnheader-header-value))
5330                          (string-match "<[^>]+>" in-reply-to))
5331                     (let (ref2)
5332                       (setq ref (substring in-reply-to (match-beginning 0)
5333                                            (match-end 0)))
5334                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5335                         (setq ref2 (substring in-reply-to (match-beginning 0)
5336                                               (match-end 0)))
5337                         (when (> (length ref2) (length ref))
5338                           (setq ref ref2)))
5339                       ref)
5340                   (setq ref nil))))
5341             ;; Chars.
5342             (progn
5343               (goto-char p)
5344               (if (search-forward "\nchars: " nil t)
5345                   (if (numberp (setq chars (ignore-errors (read cur))))
5346                       chars -1)
5347                 -1))
5348             ;; Lines.
5349             (progn
5350               (goto-char p)
5351               (if (search-forward "\nlines: " nil t)
5352                   (if (numberp (setq lines (ignore-errors (read cur))))
5353                       lines -1)
5354                 -1))
5355             ;; Xref.
5356             (progn
5357               (goto-char p)
5358               (and (search-forward "\nxref:" nil t)
5359                    (nnheader-header-value)))
5360             ;; Extra.
5361             (when gnus-extra-headers
5362               (let ((extra gnus-extra-headers)
5363                     out)
5364                 (while extra
5365                   (goto-char p)
5366                   (when (search-forward
5367                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5368                     (push (cons (car extra) (nnheader-header-value))
5369                           out))
5370                   (pop extra))
5371                 out))))
5372           (when (equal id ref)
5373             (setq ref nil))
5374
5375           (when gnus-alter-header-function
5376             (funcall gnus-alter-header-function header)
5377             (setq id (mail-header-id header)
5378                   ref (gnus-parent-id (mail-header-references header))))
5379
5380           (when (setq header
5381                       (gnus-dependencies-add-header
5382                        header dependencies force-new))
5383             (push header headers))
5384           (goto-char (point-max))
5385           (widen))
5386         (nreverse headers)))))
5387
5388 ;; Goes through the xover lines and returns a list of vectors
5389 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5390                                                   force-new dependencies
5391                                                   group also-fetch-heads)
5392   "Parse the news overview data in the server buffer.
5393 Return a list of headers that match SEQUENCE (see
5394 `nntp-retrieve-headers')."
5395   ;; Get the Xref when the users reads the articles since most/some
5396   ;; NNTP servers do not include Xrefs when using XOVER.
5397   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5398   (let ((mail-parse-charset gnus-newsgroup-charset)
5399         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5400         (cur nntp-server-buffer)
5401         (dependencies (or dependencies gnus-newsgroup-dependencies))
5402         (allp (cond
5403                ((eq gnus-read-all-available-headers t)
5404                 t)
5405                ((stringp gnus-read-all-available-headers)
5406                 (string-match gnus-read-all-available-headers group))
5407                (t
5408                 nil)))
5409         number headers header)
5410     (save-excursion
5411       (set-buffer nntp-server-buffer)
5412       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5413       ;; Allow the user to mangle the headers before parsing them.
5414       (gnus-run-hooks 'gnus-parse-headers-hook)
5415       (goto-char (point-min))
5416       (while (not (eobp))
5417         (condition-case ()
5418             (while (and (or sequence allp)
5419                         (not (eobp)))
5420               (setq number (read cur))
5421               (when (not allp)
5422                 (while (and sequence
5423                             (< (car sequence) number))
5424                   (setq sequence (cdr sequence))))
5425               (when (and (or allp
5426                              (and sequence
5427                                   (eq number (car sequence))))
5428                          (progn
5429                            (setq sequence (cdr sequence))
5430                            (setq header (inline
5431                                           (gnus-nov-parse-line
5432                                            number dependencies force-new)))))
5433                 (push header headers))
5434               (forward-line 1))
5435           (error
5436            (gnus-error 4 "Strange nov line (%d)"
5437                        (count-lines (point-min) (point)))))
5438         (forward-line 1))
5439       ;; A common bug in inn is that if you have posted an article and
5440       ;; then retrieves the active file, it will answer correctly --
5441       ;; the new article is included.  However, a NOV entry for the
5442       ;; article may not have been generated yet, so this may fail.
5443       ;; We work around this problem by retrieving the last few
5444       ;; headers using HEAD.
5445       (if (or (not also-fetch-heads)
5446               (not sequence))
5447           ;; We (probably) got all the headers.
5448           (nreverse headers)
5449         (let ((gnus-nov-is-evil t))
5450           (nconc
5451            (nreverse headers)
5452            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5453              (gnus-get-newsgroup-headers))))))))
5454
5455 (defun gnus-article-get-xrefs ()
5456   "Fill in the Xref value in `gnus-current-headers', if necessary.
5457 This is meant to be called in `gnus-article-internal-prepare-hook'."
5458   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5459                                  gnus-current-headers)))
5460     (or (not gnus-use-cross-reference)
5461         (not headers)
5462         (and (mail-header-xref headers)
5463              (not (string= (mail-header-xref headers) "")))
5464         (let ((case-fold-search t)
5465               xref)
5466           (save-restriction
5467             (nnheader-narrow-to-headers)
5468             (goto-char (point-min))
5469             (when (or (and (not (eobp))
5470                            (eq (downcase (char-after)) ?x)
5471                            (looking-at "Xref:"))
5472                       (search-forward "\nXref:" nil t))
5473               (goto-char (1+ (match-end 0)))
5474               (setq xref (buffer-substring (point)
5475                                            (progn (end-of-line) (point))))
5476               (mail-header-set-xref headers xref)))))))
5477
5478 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5479   "Find article ID and insert the summary line for that article.
5480 OLD-HEADER can either be a header or a line number to insert
5481 the subject line on."
5482   (let* ((line (and (numberp old-header) old-header))
5483          (old-header (and (vectorp old-header) old-header))
5484          (header (cond ((and old-header use-old-header)
5485                         old-header)
5486                        ((and (numberp id)
5487                              (gnus-number-to-header id))
5488                         (gnus-number-to-header id))
5489                        (t
5490                         (gnus-read-header id))))
5491          (number (and (numberp id) id))
5492          d)
5493     (when header
5494       ;; Rebuild the thread that this article is part of and go to the
5495       ;; article we have fetched.
5496       (when (and (not gnus-show-threads)
5497                  old-header)
5498         (when (and number
5499                    (setq d (gnus-data-find (mail-header-number old-header))))
5500           (goto-char (gnus-data-pos d))
5501           (gnus-data-remove
5502            number
5503            (- (gnus-point-at-bol)
5504               (prog1
5505                   (1+ (gnus-point-at-eol))
5506                 (gnus-delete-line))))))
5507       (when old-header
5508         (mail-header-set-number header (mail-header-number old-header)))
5509       (setq gnus-newsgroup-sparse
5510             (delq (setq number (mail-header-number header))
5511                   gnus-newsgroup-sparse))
5512       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5513       (push number gnus-newsgroup-limit)
5514       (gnus-rebuild-thread (mail-header-id header) line)
5515       (gnus-summary-goto-subject number nil t))
5516     (when (and (numberp number)
5517                (> number 0))
5518       ;; We have to update the boundaries even if we can't fetch the
5519       ;; article if ID is a number -- so that the next `P' or `N'
5520       ;; command will fetch the previous (or next) article even
5521       ;; if the one we tried to fetch this time has been canceled.
5522       (when (> number gnus-newsgroup-end)
5523         (setq gnus-newsgroup-end number))
5524       (when (< number gnus-newsgroup-begin)
5525         (setq gnus-newsgroup-begin number))
5526       (setq gnus-newsgroup-unselected
5527             (delq number gnus-newsgroup-unselected)))
5528     ;; Report back a success?
5529     (and header (mail-header-number header))))
5530
5531 ;;; Process/prefix in the summary buffer
5532
5533 (defun gnus-summary-work-articles (n)
5534   "Return a list of articles to be worked upon.
5535 The prefix argument, the list of process marked articles, and the
5536 current article will be taken into consideration."
5537   (save-excursion
5538     (set-buffer gnus-summary-buffer)
5539     (cond
5540      (n
5541       ;; A numerical prefix has been given.
5542       (setq n (prefix-numeric-value n))
5543       (let ((backward (< n 0))
5544             (n (abs (prefix-numeric-value n)))
5545             articles article)
5546         (save-excursion
5547           (while
5548               (and (> n 0)
5549                    (push (setq article (gnus-summary-article-number))
5550                          articles)
5551                    (if backward
5552                        (gnus-summary-find-prev nil article)
5553                      (gnus-summary-find-next nil article)))
5554             (decf n)))
5555         (nreverse articles)))
5556      ((and (gnus-region-active-p) (mark))
5557       (message "region active")
5558       ;; Work on the region between point and mark.
5559       (let ((max (max (point) (mark)))
5560             articles article)
5561         (save-excursion
5562           (goto-char (min (min (point) (mark))))
5563           (while
5564               (and
5565                (push (setq article (gnus-summary-article-number)) articles)
5566                (gnus-summary-find-next nil article)
5567                (< (point) max)))
5568           (nreverse articles))))
5569      (gnus-newsgroup-processable
5570       ;; There are process-marked articles present.
5571       ;; Save current state.
5572       (gnus-summary-save-process-mark)
5573       ;; Return the list.
5574       (reverse gnus-newsgroup-processable))
5575      (t
5576       ;; Just return the current article.
5577       (list (gnus-summary-article-number))))))
5578
5579 (defmacro gnus-summary-iterate (arg &rest forms)
5580   "Iterate over the process/prefixed articles and do FORMS.
5581 ARG is the interactive prefix given to the command.  FORMS will be
5582 executed with point over the summary line of the articles."
5583   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5584     `(let ((,articles (gnus-summary-work-articles ,arg)))
5585        (while ,articles
5586          (gnus-summary-goto-subject (car ,articles))
5587          ,@forms
5588          (pop ,articles)))))
5589
5590 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5591 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5592
5593 (defun gnus-summary-save-process-mark ()
5594   "Push the current set of process marked articles on the stack."
5595   (interactive)
5596   (push (copy-sequence gnus-newsgroup-processable)
5597         gnus-newsgroup-process-stack))
5598
5599 (defun gnus-summary-kill-process-mark ()
5600   "Push the current set of process marked articles on the stack and unmark."
5601   (interactive)
5602   (gnus-summary-save-process-mark)
5603   (gnus-summary-unmark-all-processable))
5604
5605 (defun gnus-summary-yank-process-mark ()
5606   "Pop the last process mark state off the stack and restore it."
5607   (interactive)
5608   (unless gnus-newsgroup-process-stack
5609     (error "Empty mark stack"))
5610   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5611
5612 (defun gnus-summary-process-mark-set (set)
5613   "Make SET into the current process marked articles."
5614   (gnus-summary-unmark-all-processable)
5615   (while set
5616     (gnus-summary-set-process-mark (pop set))))
5617
5618 ;;; Searching and stuff
5619
5620 (defun gnus-summary-search-group (&optional backward use-level)
5621   "Search for next unread newsgroup.
5622 If optional argument BACKWARD is non-nil, search backward instead."
5623   (save-excursion
5624     (set-buffer gnus-group-buffer)
5625     (when (gnus-group-search-forward
5626            backward nil (if use-level (gnus-group-group-level) nil))
5627       (gnus-group-group-name))))
5628
5629 (defun gnus-summary-best-group (&optional exclude-group)
5630   "Find the name of the best unread group.
5631 If EXCLUDE-GROUP, do not go to this group."
5632   (save-excursion
5633     (set-buffer gnus-group-buffer)
5634     (save-excursion
5635       (gnus-group-best-unread-group exclude-group))))
5636
5637 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5638   (if backward (gnus-summary-find-prev)
5639     (let* ((dummy (gnus-summary-article-intangible-p))
5640            (article (or article (gnus-summary-article-number)))
5641            (arts (gnus-data-find-list article))
5642            result)
5643       (when (and (not dummy)
5644                  (or (not gnus-summary-check-current)
5645                      (not unread)
5646                      (not (gnus-data-unread-p (car arts)))))
5647         (setq arts (cdr arts)))
5648       (when (setq result
5649                   (if unread
5650                       (progn
5651                         (while arts
5652                           (when (or (and undownloaded
5653                                          (eq gnus-undownloaded-mark
5654                                              (gnus-data-mark (car arts))))
5655                                     (gnus-data-unread-p (car arts)))
5656                             (setq result (car arts)
5657                                   arts nil))
5658                           (setq arts (cdr arts)))
5659                         result)
5660                     (car arts)))
5661         (goto-char (gnus-data-pos result))
5662         (gnus-data-number result)))))
5663
5664 (defun gnus-summary-find-prev (&optional unread article)
5665   (let* ((eobp (eobp))
5666          (article (or article (gnus-summary-article-number)))
5667          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5668          result)
5669     (when (and (not eobp)
5670                (or (not gnus-summary-check-current)
5671                    (not unread)
5672                    (not (gnus-data-unread-p (car arts)))))
5673       (setq arts (cdr arts)))
5674     (when (setq result
5675                 (if unread
5676                     (progn
5677                       (while arts
5678                         (when (gnus-data-unread-p (car arts))
5679                           (setq result (car arts)
5680                                 arts nil))
5681                         (setq arts (cdr arts)))
5682                       result)
5683                   (car arts)))
5684       (goto-char (gnus-data-pos result))
5685       (gnus-data-number result))))
5686
5687 (defun gnus-summary-find-subject (subject &optional unread backward article)
5688   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5689          (article (or article (gnus-summary-article-number)))
5690          (articles (gnus-data-list backward))
5691          (arts (gnus-data-find-list article articles))
5692          result)
5693     (when (or (not gnus-summary-check-current)
5694               (not unread)
5695               (not (gnus-data-unread-p (car arts))))
5696       (setq arts (cdr arts)))
5697     (while arts
5698       (and (or (not unread)
5699                (gnus-data-unread-p (car arts)))
5700            (vectorp (gnus-data-header (car arts)))
5701            (gnus-subject-equal
5702             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5703            (setq result (car arts)
5704                  arts nil))
5705       (setq arts (cdr arts)))
5706     (and result
5707          (goto-char (gnus-data-pos result))
5708          (gnus-data-number result))))
5709
5710 (defun gnus-summary-search-forward (&optional unread subject backward)
5711   "Search forward for an article.
5712 If UNREAD, look for unread articles.  If SUBJECT, look for
5713 articles with that subject.  If BACKWARD, search backward instead."
5714   (cond (subject (gnus-summary-find-subject subject unread backward))
5715         (backward (gnus-summary-find-prev unread))
5716         (t (gnus-summary-find-next unread))))
5717
5718 (defun gnus-recenter (&optional n)
5719   "Center point in window and redisplay frame.
5720 Also do horizontal recentering."
5721   (interactive "P")
5722   (when (and gnus-auto-center-summary
5723              (not (eq gnus-auto-center-summary 'vertical)))
5724     (gnus-horizontal-recenter))
5725   (recenter n))
5726
5727 (defun gnus-summary-recenter ()
5728   "Center point in the summary window.
5729 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5730 displayed, no centering will be performed."
5731   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5732 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5733   (interactive)
5734   (let* ((top (cond ((< (window-height) 4) 0)
5735                     ((< (window-height) 7) 1)
5736                     (t (if (numberp gnus-auto-center-summary)
5737                            gnus-auto-center-summary
5738                          2))))
5739          (height (1- (window-height)))
5740          (bottom (save-excursion (goto-char (point-max))
5741                                  (forward-line (- height))
5742                                  (point)))
5743          (window (get-buffer-window (current-buffer))))
5744     ;; The user has to want it.
5745     (when gnus-auto-center-summary
5746       (when (get-buffer-window gnus-article-buffer)
5747         ;; Only do recentering when the article buffer is displayed,
5748       ;; Set the window start to either `bottom', which is the biggest
5749         ;; possible valid number, or the second line from the top,
5750         ;; whichever is the least.
5751         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5752           (if (> bottom top-pos)
5753               ;; Keep the second line from the top visible
5754               (set-window-start window top-pos t)
5755             ;; Try to keep the bottom line visible; if it's partially
5756             ;; obscured, either scroll one more line to make it fully
5757             ;; visible, or revert to using TOP-POS.
5758             (save-excursion
5759               (goto-char (point-max))
5760               (forward-line -1)
5761               (let ((last-line-start (point)))
5762                 (goto-char bottom)
5763                 (set-window-start window (point) t)
5764                 (when (not (pos-visible-in-window-p last-line-start window))
5765                   (forward-line 1)
5766                   (set-window-start window (min (point) top-pos) t)))))))
5767       ;; Do horizontal recentering while we're at it.
5768       (when (and (get-buffer-window (current-buffer) t)
5769                  (not (eq gnus-auto-center-summary 'vertical)))
5770         (let ((selected (selected-window)))
5771           (select-window (get-buffer-window (current-buffer) t))
5772           (gnus-summary-position-point)
5773           (gnus-horizontal-recenter)
5774           (select-window selected))))))
5775
5776 (defun gnus-summary-jump-to-group (newsgroup)
5777   "Move point to NEWSGROUP in group mode buffer."
5778   ;; Keep update point of group mode buffer if visible.
5779   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5780       (save-window-excursion
5781         ;; Take care of tree window mode.
5782         (when (get-buffer-window gnus-group-buffer)
5783           (pop-to-buffer gnus-group-buffer))
5784         (gnus-group-jump-to-group newsgroup))
5785     (save-excursion
5786       ;; Take care of tree window mode.
5787       (if (get-buffer-window gnus-group-buffer)
5788           (pop-to-buffer gnus-group-buffer)
5789         (set-buffer gnus-group-buffer))
5790       (gnus-group-jump-to-group newsgroup))))
5791
5792 ;; This function returns a list of article numbers based on the
5793 ;; difference between the ranges of read articles in this group and
5794 ;; the range of active articles.
5795 (defun gnus-list-of-unread-articles (group)
5796   (let* ((read (gnus-info-read (gnus-get-info group)))
5797          (active (or (gnus-active group) (gnus-activate-group group)))
5798          (last (cdr active))
5799          first nlast unread)
5800     ;; If none are read, then all are unread.
5801     (if (not read)
5802         (setq first (car active))
5803       ;; If the range of read articles is a single range, then the
5804       ;; first unread article is the article after the last read
5805       ;; article.  Sounds logical, doesn't it?
5806       (if (and (not (listp (cdr read)))
5807                (or (< (car read) (car active))
5808                    (progn (setq read (list read))
5809                           nil)))
5810           (setq first (max (car active) (1+ (cdr read))))
5811         ;; `read' is a list of ranges.
5812         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5813                                   (caar read)))
5814                   1)
5815           (setq first (car active)))
5816         (while read
5817           (when first
5818             (while (< first nlast)
5819               (push first unread)
5820               (setq first (1+ first))))
5821           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5822           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5823           (setq read (cdr read)))))
5824     ;; And add the last unread articles.
5825     (while (<= first last)
5826       (push first unread)
5827       (setq first (1+ first)))
5828     ;; Return the list of unread articles.
5829     (delq 0 (nreverse unread))))
5830
5831 (defun gnus-list-of-read-articles (group)
5832   "Return a list of unread, unticked and non-dormant articles."
5833   (let* ((info (gnus-get-info group))
5834          (marked (gnus-info-marks info))
5835          (active (gnus-active group)))
5836     (and info active
5837          (gnus-set-difference
5838           (gnus-sorted-complement
5839            (gnus-uncompress-range active)
5840            (gnus-list-of-unread-articles group))
5841           (append
5842            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5843            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5844
5845 ;; Various summary commands
5846
5847 (defun gnus-summary-select-article-buffer ()
5848   "Reconfigure windows to show article buffer."
5849   (interactive)
5850   (if (not (gnus-buffer-live-p gnus-article-buffer))
5851       (error "There is no article buffer for this summary buffer")
5852     (gnus-configure-windows 'article)
5853     (select-window (get-buffer-window gnus-article-buffer))))
5854
5855 (defun gnus-summary-universal-argument (arg)
5856   "Perform any operation on all articles that are process/prefixed."
5857   (interactive "P")
5858   (let ((articles (gnus-summary-work-articles arg))
5859         func article)
5860     (if (eq
5861          (setq
5862           func
5863           (key-binding
5864            (read-key-sequence
5865             (substitute-command-keys
5866              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5867          'undefined)
5868         (gnus-error 1 "Undefined key")
5869       (save-excursion
5870         (while articles
5871           (gnus-summary-goto-subject (setq article (pop articles)))
5872           (let (gnus-newsgroup-processable)
5873             (command-execute func))
5874           (gnus-summary-remove-process-mark article)))))
5875   (gnus-summary-position-point))
5876
5877 (defun gnus-summary-toggle-truncation (&optional arg)
5878   "Toggle truncation of summary lines.
5879 With arg, turn line truncation on iff arg is positive."
5880   (interactive "P")
5881   (setq truncate-lines
5882         (if (null arg) (not truncate-lines)
5883           (> (prefix-numeric-value arg) 0)))
5884   (redraw-display))
5885
5886 (defun gnus-summary-reselect-current-group (&optional all rescan)
5887   "Exit and then reselect the current newsgroup.
5888 The prefix argument ALL means to select all articles."
5889   (interactive "P")
5890   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5891     (error "Ephemeral groups can't be reselected"))
5892   (let ((current-subject (gnus-summary-article-number))
5893         (group gnus-newsgroup-name))
5894     (setq gnus-newsgroup-begin nil)
5895     (gnus-summary-exit)
5896     ;; We have to adjust the point of group mode buffer because
5897     ;; point was moved to the next unread newsgroup by exiting.
5898     (gnus-summary-jump-to-group group)
5899     (when rescan
5900       (save-excursion
5901         (gnus-group-get-new-news-this-group 1)))
5902     (gnus-group-read-group all t)
5903     (gnus-summary-goto-subject current-subject nil t)))
5904
5905 (defun gnus-summary-rescan-group (&optional all)
5906   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5907   (interactive "P")
5908   (gnus-summary-reselect-current-group all t))
5909
5910 (defun gnus-summary-update-info (&optional non-destructive)
5911   (save-excursion
5912     (let ((group gnus-newsgroup-name))
5913       (when group
5914         (when gnus-newsgroup-kill-headers
5915           (setq gnus-newsgroup-killed
5916                 (gnus-compress-sequence
5917                  (nconc
5918                   (gnus-set-sorted-intersection
5919                    (gnus-uncompress-range gnus-newsgroup-killed)
5920                    (setq gnus-newsgroup-unselected
5921                          (sort gnus-newsgroup-unselected '<)))
5922                   (setq gnus-newsgroup-unreads
5923                         (sort gnus-newsgroup-unreads '<)))
5924                  t)))
5925         (unless (listp (cdr gnus-newsgroup-killed))
5926           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5927         (let ((headers gnus-newsgroup-headers))
5928           ;; Set the new ranges of read articles.
5929           (save-excursion
5930             (set-buffer gnus-group-buffer)
5931             (gnus-undo-force-boundary))
5932           (gnus-update-read-articles
5933            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5934           ;; Set the current article marks.
5935           (let ((gnus-newsgroup-scored
5936                  (if (and (not gnus-save-score)
5937                           (not non-destructive))
5938                      nil
5939                    gnus-newsgroup-scored)))
5940             (save-excursion
5941               (gnus-update-marks)))
5942           ;; Do the cross-ref thing.
5943           (when gnus-use-cross-reference
5944             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5945           ;; Do not switch windows but change the buffer to work.
5946           (set-buffer gnus-group-buffer)
5947           (unless (gnus-ephemeral-group-p group)
5948             (gnus-group-update-group group)))))))
5949
5950 (defun gnus-summary-save-newsrc (&optional force)
5951   "Save the current number of read/marked articles in the dribble buffer.
5952 The dribble buffer will then be saved.
5953 If FORCE (the prefix), also save the .newsrc file(s)."
5954   (interactive "P")
5955   (gnus-summary-update-info t)
5956   (if force
5957       (gnus-save-newsrc-file)
5958     (gnus-dribble-save)))
5959
5960 (defun gnus-summary-exit (&optional temporary)
5961   "Exit reading current newsgroup, and then return to group selection mode.
5962 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5963   (interactive)
5964   (gnus-set-global-variables)
5965   (when (gnus-buffer-live-p gnus-article-buffer)
5966     (save-excursion
5967       (set-buffer gnus-article-buffer)
5968       (mm-destroy-parts gnus-article-mime-handles)
5969       ;; Set it to nil for safety reason.
5970       (setq gnus-article-mime-handle-alist nil)
5971       (setq gnus-article-mime-handles nil)))
5972   (gnus-kill-save-kill-buffer)
5973   (gnus-async-halt-prefetch)
5974   (let* ((group gnus-newsgroup-name)
5975          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5976          (mode major-mode)
5977          (group-point nil)
5978          (buf (current-buffer)))
5979     (unless quit-config
5980       ;; Do adaptive scoring, and possibly save score files.
5981       (when gnus-newsgroup-adaptive
5982         (gnus-score-adaptive))
5983       (when gnus-use-scoring
5984         (gnus-score-save)))
5985     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5986     ;; If we have several article buffers, we kill them at exit.
5987     (unless gnus-single-article-buffer
5988       (gnus-kill-buffer gnus-original-article-buffer)
5989       (setq gnus-article-current nil))
5990     (when gnus-use-cache
5991       (gnus-cache-possibly-remove-articles)
5992       (gnus-cache-save-buffers))
5993     (gnus-async-prefetch-remove-group group)
5994     (when gnus-suppress-duplicates
5995       (gnus-dup-enter-articles))
5996     (when gnus-use-trees
5997       (gnus-tree-close group))
5998     (when gnus-use-cache
5999       (gnus-cache-write-active))
6000     ;; Remove entries for this group.
6001     (nnmail-purge-split-history (gnus-group-real-name group))
6002     ;; Make all changes in this group permanent.
6003     (unless quit-config
6004       (gnus-run-hooks 'gnus-exit-group-hook)
6005       (gnus-summary-update-info))
6006     (gnus-close-group group)
6007     ;; Make sure where we were, and go to next newsgroup.
6008     (set-buffer gnus-group-buffer)
6009     (unless quit-config
6010       (gnus-group-jump-to-group group))
6011     (gnus-run-hooks 'gnus-summary-exit-hook)
6012     (unless (or quit-config
6013                 ;; If this group has disappeared from the summary
6014                 ;; buffer, don't skip forwards.
6015                 (not (string= group (gnus-group-group-name))))
6016       (gnus-group-next-unread-group 1))
6017     (setq group-point (point))
6018     (if temporary
6019         nil                             ;Nothing to do.
6020       ;; If we have several article buffers, we kill them at exit.
6021       (unless gnus-single-article-buffer
6022         (gnus-kill-buffer gnus-article-buffer)
6023         (gnus-kill-buffer gnus-original-article-buffer)
6024         (setq gnus-article-current nil))
6025       (set-buffer buf)
6026       (if (not gnus-kill-summary-on-exit)
6027           (progn
6028             (gnus-deaden-summary)
6029             (setq mode nil))
6030        ;; We set all buffer-local variables to nil.  It is unclear why
6031         ;; this is needed, but if we don't, buffer-local variables are
6032         ;; not garbage-collected, it seems.  This would the lead to en
6033         ;; ever-growing Emacs.
6034         (gnus-summary-clear-local-variables)
6035         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6036           (gnus-summary-clear-local-variables))
6037         (when (get-buffer gnus-article-buffer)
6038           (bury-buffer gnus-article-buffer))
6039         ;; We clear the global counterparts of the buffer-local
6040         ;; variables as well, just to be on the safe side.
6041         (set-buffer gnus-group-buffer)
6042         (gnus-summary-clear-local-variables)
6043         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6044           (gnus-summary-clear-local-variables)))
6045       (setq gnus-current-select-method gnus-select-method)
6046       (pop-to-buffer gnus-group-buffer)
6047       (if (not quit-config)
6048           (progn
6049             (goto-char group-point)
6050             (gnus-configure-windows 'group 'force))
6051         (gnus-handle-ephemeral-exit quit-config))
6052       ;; Return to group mode buffer.
6053       (when (eq mode 'gnus-summary-mode)
6054         (gnus-kill-buffer buf))
6055       ;; Clear the current group name.
6056       (unless quit-config
6057         (setq gnus-newsgroup-name nil)))))
6058
6059 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6060 (defun gnus-summary-exit-no-update (&optional no-questions)
6061   "Quit reading current newsgroup without updating read article info."
6062   (interactive)
6063   (let* ((group gnus-newsgroup-name)
6064          (quit-config (gnus-group-quit-config group)))
6065     (when (or no-questions
6066               gnus-expert-user
6067               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6068       (gnus-async-halt-prefetch)
6069       (mapcar 'funcall
6070               (delq 'gnus-summary-expire-articles
6071                     (copy-sequence gnus-summary-prepare-exit-hook)))
6072       (when (gnus-buffer-live-p gnus-article-buffer)
6073         (save-excursion
6074           (set-buffer gnus-article-buffer)
6075           (mm-destroy-parts gnus-article-mime-handles)
6076           ;; Set it to nil for safety reason.
6077           (setq gnus-article-mime-handle-alist nil)
6078           (setq gnus-article-mime-handles nil)))
6079       ;; If we have several article buffers, we kill them at exit.
6080       (unless gnus-single-article-buffer
6081         (gnus-kill-buffer gnus-article-buffer)
6082         (gnus-kill-buffer gnus-original-article-buffer)
6083         (setq gnus-article-current nil))
6084       (if (not gnus-kill-summary-on-exit)
6085           (gnus-deaden-summary)
6086         (gnus-close-group group)
6087         (gnus-summary-clear-local-variables)
6088         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6089           (gnus-summary-clear-local-variables))
6090         (set-buffer gnus-group-buffer)
6091         (gnus-summary-clear-local-variables)
6092         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6093           (gnus-summary-clear-local-variables))
6094         (when (get-buffer gnus-summary-buffer)
6095           (kill-buffer gnus-summary-buffer)))
6096       (unless gnus-single-article-buffer
6097         (setq gnus-article-current nil))
6098       (when gnus-use-trees
6099         (gnus-tree-close group))
6100       (gnus-async-prefetch-remove-group group)
6101       (when (get-buffer gnus-article-buffer)
6102         (bury-buffer gnus-article-buffer))
6103       ;; Return to the group buffer.
6104       (gnus-configure-windows 'group 'force)
6105       ;; Clear the current group name.
6106       (setq gnus-newsgroup-name nil)
6107       (when (equal (gnus-group-group-name) group)
6108         (gnus-group-next-unread-group 1))
6109       (when quit-config
6110         (gnus-handle-ephemeral-exit quit-config)))))
6111
6112 (defun gnus-handle-ephemeral-exit (quit-config)
6113   "Handle movement when leaving an ephemeral group.
6114 The state which existed when entering the ephemeral is reset."
6115   (if (not (buffer-name (car quit-config)))
6116       (gnus-configure-windows 'group 'force)
6117     (set-buffer (car quit-config))
6118     (cond ((eq major-mode 'gnus-summary-mode)
6119            (gnus-set-global-variables))
6120           ((eq major-mode 'gnus-article-mode)
6121            (save-excursion
6122              ;; The `gnus-summary-buffer' variable may point
6123              ;; to the old summary buffer when using a single
6124              ;; article buffer.
6125              (unless (gnus-buffer-live-p gnus-summary-buffer)
6126                (set-buffer gnus-group-buffer))
6127              (set-buffer gnus-summary-buffer)
6128              (gnus-set-global-variables))))
6129     (if (or (eq (cdr quit-config) 'article)
6130             (eq (cdr quit-config) 'pick))
6131         (progn
6132           ;; The current article may be from the ephemeral group
6133           ;; thus it is best that we reload this article
6134           (gnus-summary-show-article)
6135           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6136               (gnus-configure-windows 'pick 'force)
6137             (gnus-configure-windows (cdr quit-config) 'force)))
6138       (gnus-configure-windows (cdr quit-config) 'force))
6139     (when (eq major-mode 'gnus-summary-mode)
6140       (gnus-summary-next-subject 1 nil t)
6141       (gnus-summary-recenter)
6142       (gnus-summary-position-point))))
6143
6144 ;;; Dead summaries.
6145
6146 (defvar gnus-dead-summary-mode-map nil)
6147
6148 (unless gnus-dead-summary-mode-map
6149   (setq gnus-dead-summary-mode-map (make-keymap))
6150   (suppress-keymap gnus-dead-summary-mode-map)
6151   (substitute-key-definition
6152    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6153   (let ((keys '("\C-d" "\r" "\177" [delete])))
6154     (while keys
6155       (define-key gnus-dead-summary-mode-map
6156         (pop keys) 'gnus-summary-wake-up-the-dead))))
6157
6158 (defvar gnus-dead-summary-mode nil
6159   "Minor mode for Gnus summary buffers.")
6160
6161 (defun gnus-dead-summary-mode (&optional arg)
6162   "Minor mode for Gnus summary buffers."
6163   (interactive "P")
6164   (when (eq major-mode 'gnus-summary-mode)
6165     (make-local-variable 'gnus-dead-summary-mode)
6166     (setq gnus-dead-summary-mode
6167           (if (null arg) (not gnus-dead-summary-mode)
6168             (> (prefix-numeric-value arg) 0)))
6169     (when gnus-dead-summary-mode
6170       (gnus-add-minor-mode
6171        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6172
6173 (defun gnus-deaden-summary ()
6174   "Make the current summary buffer into a dead summary buffer."
6175   ;; Kill any previous dead summary buffer.
6176   (when (and gnus-dead-summary
6177              (buffer-name gnus-dead-summary))
6178     (save-excursion
6179       (set-buffer gnus-dead-summary)
6180       (when gnus-dead-summary-mode
6181         (kill-buffer (current-buffer)))))
6182   ;; Make this the current dead summary.
6183   (setq gnus-dead-summary (current-buffer))
6184   (gnus-dead-summary-mode 1)
6185   (let ((name (buffer-name)))
6186     (when (string-match "Summary" name)
6187       (rename-buffer
6188        (concat (substring name 0 (match-beginning 0)) "Dead "
6189                (substring name (match-beginning 0)))
6190        t)
6191       (bury-buffer))))
6192
6193 (defun gnus-kill-or-deaden-summary (buffer)
6194   "Kill or deaden the summary BUFFER."
6195   (save-excursion
6196     (when (and (buffer-name buffer)
6197                (not gnus-single-article-buffer))
6198       (save-excursion
6199         (set-buffer buffer)
6200         (gnus-kill-buffer gnus-article-buffer)
6201         (gnus-kill-buffer gnus-original-article-buffer)))
6202     (cond (gnus-kill-summary-on-exit
6203            (when (and gnus-use-trees
6204                       (gnus-buffer-exists-p buffer))
6205              (save-excursion
6206                (set-buffer buffer)
6207                (gnus-tree-close gnus-newsgroup-name)))
6208            (gnus-kill-buffer buffer))
6209           ((gnus-buffer-exists-p buffer)
6210            (save-excursion
6211              (set-buffer buffer)
6212              (gnus-deaden-summary))))))
6213
6214 (defun gnus-summary-wake-up-the-dead (&rest args)
6215   "Wake up the dead summary buffer."
6216   (interactive)
6217   (gnus-dead-summary-mode -1)
6218   (let ((name (buffer-name)))
6219     (when (string-match "Dead " name)
6220       (rename-buffer
6221        (concat (substring name 0 (match-beginning 0))
6222                (substring name (match-end 0)))
6223        t)))
6224   (gnus-message 3 "This dead summary is now alive again"))
6225
6226 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6227 (defun gnus-summary-fetch-faq (&optional faq-dir)
6228   "Fetch the FAQ for the current group.
6229 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6230 in."
6231   (interactive
6232    (list
6233     (when current-prefix-arg
6234       (completing-read
6235        "Faq dir: " (and (listp gnus-group-faq-directory)
6236                         (mapcar (lambda (file) (list file))
6237                                 gnus-group-faq-directory))))))
6238   (let (gnus-faq-buffer)
6239     (when (setq gnus-faq-buffer
6240                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6241       (gnus-configure-windows 'summary-faq))))
6242
6243 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6244 (defun gnus-summary-describe-group (&optional force)
6245   "Describe the current newsgroup."
6246   (interactive "P")
6247   (gnus-group-describe-group force gnus-newsgroup-name))
6248
6249 (defun gnus-summary-describe-briefly ()
6250   "Describe summary mode commands briefly."
6251   (interactive)
6252   (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")))
6253
6254 ;; Walking around group mode buffer from summary mode.
6255
6256 (defun gnus-summary-next-group (&optional no-article target-group backward)
6257   "Exit current newsgroup and then select next unread newsgroup.
6258 If prefix argument NO-ARTICLE is non-nil, no article is selected
6259 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6260 previous group instead."
6261   (interactive "P")
6262   ;; Stop pre-fetching.
6263   (gnus-async-halt-prefetch)
6264   (let ((current-group gnus-newsgroup-name)
6265         (current-buffer (current-buffer))
6266         entered)
6267    ;; First we semi-exit this group to update Xrefs and all variables.
6268     ;; We can't do a real exit, because the window conf must remain
6269     ;; the same in case the user is prompted for info, and we don't
6270     ;; want the window conf to change before that...
6271     (gnus-summary-exit t)
6272     (while (not entered)
6273       ;; Then we find what group we are supposed to enter.
6274       (set-buffer gnus-group-buffer)
6275       (gnus-group-jump-to-group current-group)
6276       (setq target-group
6277             (or target-group
6278                 (if (eq gnus-keep-same-level 'best)
6279                     (gnus-summary-best-group gnus-newsgroup-name)
6280                   (gnus-summary-search-group backward gnus-keep-same-level))))
6281       (if (not target-group)
6282           ;; There are no further groups, so we return to the group
6283           ;; buffer.
6284           (progn
6285             (gnus-message 5 "Returning to the group buffer")
6286             (setq entered t)
6287             (when (gnus-buffer-live-p current-buffer)
6288               (set-buffer current-buffer)
6289               (gnus-summary-exit))
6290             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6291         ;; We try to enter the target group.
6292         (gnus-group-jump-to-group target-group)
6293         (let ((unreads (gnus-group-group-unread)))
6294           (if (and (or (eq t unreads)
6295                        (and unreads (not (zerop unreads))))
6296                    (gnus-summary-read-group
6297                     target-group nil no-article
6298                     (and (buffer-name current-buffer) current-buffer)
6299                     nil backward))
6300               (setq entered t)
6301             (setq current-group target-group
6302                   target-group nil)))))))
6303
6304 (defun gnus-summary-prev-group (&optional no-article)
6305   "Exit current newsgroup and then select previous unread newsgroup.
6306 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6307   (interactive "P")
6308   (gnus-summary-next-group no-article nil t))
6309
6310 ;; Walking around summary lines.
6311
6312 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6313   "Go to the first unread subject.
6314 If UNREAD is non-nil, go to the first unread article.
6315 Returns the article selected or nil if there are no unread articles."
6316   (interactive "P")
6317   (prog1
6318       (cond
6319        ;; Empty summary.
6320        ((null gnus-newsgroup-data)
6321         (gnus-message 3 "No articles in the group")
6322         nil)
6323        ;; Pick the first article.
6324        ((not unread)
6325         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6326         (gnus-data-number (car gnus-newsgroup-data)))
6327        ;; No unread articles.
6328        ((null gnus-newsgroup-unreads)
6329         (gnus-message 3 "No more unread articles")
6330         nil)
6331        ;; Find the first unread article.
6332        (t
6333         (let ((data gnus-newsgroup-data))
6334           (while (and data
6335                       (and (not (and undownloaded
6336                                      (eq gnus-undownloaded-mark
6337                                          (gnus-data-mark (car data)))))
6338                            (not (and unseen
6339                                      (memq (car data) gnus-newsgroup-unseen)))
6340                            (not (gnus-data-unread-p (car data)))))
6341             (setq data (cdr data)))
6342           (when data
6343             (goto-char (gnus-data-pos (car data)))
6344             (gnus-data-number (car data))))))
6345     (gnus-summary-position-point)))
6346
6347 (defun gnus-summary-next-subject (n &optional unread dont-display)
6348   "Go to next N'th summary line.
6349 If N is negative, go to the previous N'th subject line.
6350 If UNREAD is non-nil, only unread articles are selected.
6351 The difference between N and the actual number of steps taken is
6352 returned."
6353   (interactive "p")
6354   (let ((backward (< n 0))
6355         (n (abs n)))
6356     (while (and (> n 0)
6357                 (if backward
6358                     (gnus-summary-find-prev unread)
6359                   (gnus-summary-find-next unread)))
6360       (unless (zerop (setq n (1- n)))
6361         (gnus-summary-show-thread)))
6362     (when (/= 0 n)
6363       (gnus-message 7 "No more%s articles"
6364                     (if unread " unread" "")))
6365     (unless dont-display
6366       (gnus-summary-recenter)
6367       (gnus-summary-position-point))
6368     n))
6369
6370 (defun gnus-summary-next-unread-subject (n)
6371   "Go to next N'th unread summary line."
6372   (interactive "p")
6373   (gnus-summary-next-subject n t))
6374
6375 (defun gnus-summary-prev-subject (n &optional unread)
6376   "Go to previous N'th summary line.
6377 If optional argument UNREAD is non-nil, only unread article is selected."
6378   (interactive "p")
6379   (gnus-summary-next-subject (- n) unread))
6380
6381 (defun gnus-summary-prev-unread-subject (n)
6382   "Go to previous N'th unread summary line."
6383   (interactive "p")
6384   (gnus-summary-next-subject (- n) t))
6385
6386 (defun gnus-summary-goto-subject (article &optional force silent)
6387   "Go the subject line of ARTICLE.
6388 If FORCE, also allow jumping to articles not currently shown."
6389   (interactive "nArticle number: ")
6390   (let ((b (point))
6391         (data (gnus-data-find article)))
6392     ;; We read in the article if we have to.
6393     (and (not data)
6394          force
6395          (gnus-summary-insert-subject
6396           article
6397           (if (or (numberp force) (vectorp force)) force)
6398           t)
6399          (setq data (gnus-data-find article)))
6400     (goto-char b)
6401     (if (not data)
6402         (progn
6403           (unless silent
6404             (gnus-message 3 "Can't find article %d" article))
6405           nil)
6406       (let ((pt (gnus-data-pos data)))
6407         (goto-char pt)
6408         (gnus-summary-set-article-display-arrow pt))
6409       (gnus-summary-position-point)
6410       article)))
6411
6412 ;; Walking around summary lines with displaying articles.
6413
6414 (defun gnus-summary-expand-window (&optional arg)
6415   "Make the summary buffer take up the entire Emacs frame.
6416 Given a prefix, will force an `article' buffer configuration."
6417   (interactive "P")
6418   (if arg
6419       (gnus-configure-windows 'article 'force)
6420     (gnus-configure-windows 'summary 'force)))
6421
6422 (defun gnus-summary-display-article (article &optional all-header)
6423   "Display ARTICLE in article buffer."
6424   (when (gnus-buffer-live-p gnus-article-buffer)
6425     (with-current-buffer gnus-article-buffer
6426       (mm-enable-multibyte-mule4)))
6427   (gnus-set-global-variables)
6428   (when (gnus-buffer-live-p gnus-article-buffer)
6429     (with-current-buffer gnus-article-buffer
6430       (setq gnus-article-charset gnus-newsgroup-charset)
6431       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6432       (mm-enable-multibyte-mule4)))
6433   (if (null article)
6434       nil
6435     (prog1
6436         (if gnus-summary-display-article-function
6437             (funcall gnus-summary-display-article-function article all-header)
6438           (gnus-article-prepare article all-header))
6439       (gnus-run-hooks 'gnus-select-article-hook)
6440       (when (and gnus-current-article
6441                  (not (zerop gnus-current-article)))
6442         (gnus-summary-goto-subject gnus-current-article))
6443       (gnus-summary-recenter)
6444       (when (and gnus-use-trees gnus-show-threads)
6445         (gnus-possibly-generate-tree article)
6446         (gnus-highlight-selected-tree article))
6447       ;; Successfully display article.
6448       (gnus-article-set-window-start
6449        (cdr (assq article gnus-newsgroup-bookmarks))))))
6450
6451 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6452   "Select the current article.
6453 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6454 non-nil, the article will be re-fetched even if it already present in
6455 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6456 be displayed."
6457   ;; Make sure we are in the summary buffer to work around bbdb bug.
6458   (unless (eq major-mode 'gnus-summary-mode)
6459     (set-buffer gnus-summary-buffer))
6460   (let ((article (or article (gnus-summary-article-number)))
6461         (all-headers (not (not all-headers))) ;Must be t or nil.
6462         gnus-summary-display-article-function)
6463     (and (not pseudo)
6464          (gnus-summary-article-pseudo-p article)
6465          (error "This is a pseudo-article"))
6466     (save-excursion
6467       (set-buffer gnus-summary-buffer)
6468       (if (or (and gnus-single-article-buffer
6469                    (or (null gnus-current-article)
6470                        (null gnus-article-current)
6471                        (null (get-buffer gnus-article-buffer))
6472                        (not (eq article (cdr gnus-article-current)))
6473                        (not (equal (car gnus-article-current)
6474                                    gnus-newsgroup-name))))
6475               (and (not gnus-single-article-buffer)
6476                    (or (null gnus-current-article)
6477                        (not (eq gnus-current-article article))))
6478               force)
6479        ;; The requested article is different from the current article.
6480           (progn
6481             (gnus-summary-display-article article all-headers)
6482             (when (gnus-buffer-live-p gnus-article-buffer)
6483               (with-current-buffer gnus-article-buffer
6484                 (if (not gnus-article-decoded-p) ;; a local variable
6485                     (mm-disable-multibyte-mule4))))
6486             (when (or all-headers gnus-show-all-headers)
6487               (gnus-article-show-all-headers))
6488             (gnus-article-set-window-start
6489              (cdr (assq article gnus-newsgroup-bookmarks)))
6490             article)
6491         (when (or all-headers gnus-show-all-headers)
6492           (gnus-article-show-all-headers))
6493         'old))))
6494
6495 (defun gnus-summary-force-verify-and-decrypt ()
6496   (interactive)
6497   (let ((mm-verify-option 'known)
6498         (mm-decrypt-option 'known))
6499     (gnus-summary-select-article nil 'force)))
6500
6501 (defun gnus-summary-set-current-mark (&optional current-mark)
6502   "Obsolete function."
6503   nil)
6504
6505 (defun gnus-summary-next-article (&optional unread subject backward push)
6506   "Select the next article.
6507 If UNREAD, only unread articles are selected.
6508 If SUBJECT, only articles with SUBJECT are selected.
6509 If BACKWARD, the previous article is selected instead of the next."
6510   (interactive "P")
6511   (cond
6512    ;; Is there such an article?
6513    ((and (gnus-summary-search-forward unread subject backward)
6514          (or (gnus-summary-display-article (gnus-summary-article-number))
6515              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6516     (gnus-summary-position-point))
6517    ;; If not, we try the first unread, if that is wanted.
6518    ((and subject
6519          gnus-auto-select-same
6520          (gnus-summary-first-unread-article))
6521     (gnus-summary-position-point)
6522     (gnus-message 6 "Wrapped"))
6523    ;; Try to get next/previous article not displayed in this group.
6524    ((and gnus-auto-extend-newsgroup
6525          (not unread) (not subject))
6526     (gnus-summary-goto-article
6527      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6528      nil (count-lines (point-min) (point))))
6529    ;; Go to next/previous group.
6530    (t
6531     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6532       (gnus-summary-jump-to-group gnus-newsgroup-name))
6533     (let ((cmd last-command-char)
6534           (point
6535            (save-excursion
6536              (set-buffer gnus-group-buffer)
6537              (point)))
6538           (group
6539            (if (eq gnus-keep-same-level 'best)
6540                (gnus-summary-best-group gnus-newsgroup-name)
6541              (gnus-summary-search-group backward gnus-keep-same-level))))
6542       ;; For some reason, the group window gets selected.  We change
6543       ;; it back.
6544       (select-window (get-buffer-window (current-buffer)))
6545       ;; Select next unread newsgroup automagically.
6546       (cond
6547        ((or (not gnus-auto-select-next)
6548             (not cmd))
6549         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6550        ((or (eq gnus-auto-select-next 'quietly)
6551             (and (eq gnus-auto-select-next 'slightly-quietly)
6552                  push)
6553             (and (eq gnus-auto-select-next 'almost-quietly)
6554                  (gnus-summary-last-article-p)))
6555         ;; Select quietly.
6556         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6557             (gnus-summary-exit)
6558           (gnus-message 7 "No more%s articles (%s)..."
6559                         (if unread " unread" "")
6560                         (if group (concat "selecting " group)
6561                           "exiting"))
6562           (gnus-summary-next-group nil group backward)))
6563        (t
6564         (when (gnus-key-press-event-p last-input-event)
6565           (gnus-summary-walk-group-buffer
6566            gnus-newsgroup-name cmd unread backward point))))))))
6567
6568 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6569   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6570                       (?\C-p (gnus-group-prev-unread-group 1))))
6571         (cursor-in-echo-area t)
6572         keve key group ended)
6573     (save-excursion
6574       (set-buffer gnus-group-buffer)
6575       (goto-char start)
6576       (setq group
6577             (if (eq gnus-keep-same-level 'best)
6578                 (gnus-summary-best-group gnus-newsgroup-name)
6579               (gnus-summary-search-group backward gnus-keep-same-level))))
6580     (while (not ended)
6581       (gnus-message
6582        5 "No more%s articles%s" (if unread " unread" "")
6583        (if (and group
6584                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6585            (format " (Type %s for %s [%s])"
6586                    (single-key-description cmd) group
6587                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6588          (format " (Type %s to exit %s)"
6589                  (single-key-description cmd)
6590                  gnus-newsgroup-name)))
6591       ;; Confirm auto selection.
6592       (setq key (car (setq keve (gnus-read-event-char))))
6593       (setq ended t)
6594       (cond
6595        ((assq key keystrokes)
6596         (let ((obuf (current-buffer)))
6597           (switch-to-buffer gnus-group-buffer)
6598           (when group
6599             (gnus-group-jump-to-group group))
6600           (eval (cadr (assq key keystrokes)))
6601           (setq group (gnus-group-group-name))
6602           (switch-to-buffer obuf))
6603         (setq ended nil))
6604        ((equal key cmd)
6605         (if (or (not group)
6606                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6607             (gnus-summary-exit)
6608           (gnus-summary-next-group nil group backward)))
6609        (t
6610         (push (cdr keve) unread-command-events))))))
6611
6612 (defun gnus-summary-next-unread-article ()
6613   "Select unread article after current one."
6614   (interactive)
6615   (gnus-summary-next-article
6616    (or (not (eq gnus-summary-goto-unread 'never))
6617        (gnus-summary-last-article-p (gnus-summary-article-number)))
6618    (and gnus-auto-select-same
6619         (gnus-summary-article-subject))))
6620
6621 (defun gnus-summary-prev-article (&optional unread subject)
6622   "Select the article after the current one.
6623 If UNREAD is non-nil, only unread articles are selected."
6624   (interactive "P")
6625   (gnus-summary-next-article unread subject t))
6626
6627 (defun gnus-summary-prev-unread-article ()
6628   "Select unread article before current one."
6629   (interactive)
6630   (gnus-summary-prev-article
6631    (or (not (eq gnus-summary-goto-unread 'never))
6632        (gnus-summary-first-article-p (gnus-summary-article-number)))
6633    (and gnus-auto-select-same
6634         (gnus-summary-article-subject))))
6635
6636 (defun gnus-summary-next-page (&optional lines circular)
6637   "Show next page of the selected article.
6638 If at the end of the current article, select the next article.
6639 LINES says how many lines should be scrolled up.
6640
6641 If CIRCULAR is non-nil, go to the start of the article instead of
6642 selecting the next article when reaching the end of the current
6643 article."
6644   (interactive "P")
6645   (setq gnus-summary-buffer (current-buffer))
6646   (gnus-set-global-variables)
6647   (let ((article (gnus-summary-article-number))
6648         (article-window (get-buffer-window gnus-article-buffer t))
6649         endp)
6650     ;; If the buffer is empty, we have no article.
6651     (unless article
6652       (error "No article to select"))
6653     (gnus-configure-windows 'article)
6654     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6655         (if (and (eq gnus-summary-goto-unread 'never)
6656                  (not (gnus-summary-last-article-p article)))
6657             (gnus-summary-next-article)
6658           (gnus-summary-next-unread-article))
6659       (if (or (null gnus-current-article)
6660               (null gnus-article-current)
6661               (/= article (cdr gnus-article-current))
6662               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6663           ;; Selected subject is different from current article's.
6664           (gnus-summary-display-article article)
6665         (when article-window
6666           (gnus-eval-in-buffer-window gnus-article-buffer
6667             (setq endp (gnus-article-next-page lines)))
6668           (when endp
6669             (cond (circular
6670                    (gnus-summary-beginning-of-article))
6671                   (lines
6672                    (gnus-message 3 "End of message"))
6673                   ((null lines)
6674                    (if (and (eq gnus-summary-goto-unread 'never)
6675                             (not (gnus-summary-last-article-p article)))
6676                        (gnus-summary-next-article)
6677                      (gnus-summary-next-unread-article))))))))
6678     (gnus-summary-recenter)
6679     (gnus-summary-position-point)))
6680
6681 (defun gnus-summary-prev-page (&optional lines move)
6682   "Show previous page of selected article.
6683 Argument LINES specifies lines to be scrolled down.
6684 If MOVE, move to the previous unread article if point is at
6685 the beginning of the buffer."
6686   (interactive "P")
6687   (let ((article (gnus-summary-article-number))
6688         (article-window (get-buffer-window gnus-article-buffer t))
6689         endp)
6690     (gnus-configure-windows 'article)
6691     (if (or (null gnus-current-article)
6692             (null gnus-article-current)
6693             (/= article (cdr gnus-article-current))
6694             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6695         ;; Selected subject is different from current article's.
6696         (gnus-summary-display-article article)
6697       (gnus-summary-recenter)
6698       (when article-window
6699         (gnus-eval-in-buffer-window gnus-article-buffer
6700           (setq endp (gnus-article-prev-page lines)))
6701         (when (and move endp)
6702           (cond (lines
6703                  (gnus-message 3 "Beginning of message"))
6704                 ((null lines)
6705                  (if (and (eq gnus-summary-goto-unread 'never)
6706                           (not (gnus-summary-first-article-p article)))
6707                      (gnus-summary-prev-article)
6708                    (gnus-summary-prev-unread-article))))))))
6709   (gnus-summary-position-point))
6710
6711 (defun gnus-summary-prev-page-or-article (&optional lines)
6712   "Show previous page of selected article.
6713 Argument LINES specifies lines to be scrolled down.
6714 If at the beginning of the article, go to the next article."
6715   (interactive "P")
6716   (gnus-summary-prev-page lines t))
6717
6718 (defun gnus-summary-scroll-up (lines)
6719   "Scroll up (or down) one line current article.
6720 Argument LINES specifies lines to be scrolled up (or down if negative)."
6721   (interactive "p")
6722   (gnus-configure-windows 'article)
6723   (gnus-summary-show-thread)
6724   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6725     (gnus-eval-in-buffer-window gnus-article-buffer
6726       (cond ((> lines 0)
6727              (when (gnus-article-next-page lines)
6728                (gnus-message 3 "End of message")))
6729             ((< lines 0)
6730              (gnus-article-prev-page (- lines))))))
6731   (gnus-summary-recenter)
6732   (gnus-summary-position-point))
6733
6734 (defun gnus-summary-scroll-down (lines)
6735   "Scroll down (or up) one line current article.
6736 Argument LINES specifies lines to be scrolled down (or up if negative)."
6737   (interactive "p")
6738   (gnus-summary-scroll-up (- lines)))
6739
6740 (defun gnus-summary-next-same-subject ()
6741   "Select next article which has the same subject as current one."
6742   (interactive)
6743   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6744
6745 (defun gnus-summary-prev-same-subject ()
6746   "Select previous article which has the same subject as current one."
6747   (interactive)
6748   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6749
6750 (defun gnus-summary-next-unread-same-subject ()
6751   "Select next unread article which has the same subject as current one."
6752   (interactive)
6753   (gnus-summary-next-article t (gnus-summary-article-subject)))
6754
6755 (defun gnus-summary-prev-unread-same-subject ()
6756   "Select previous unread article which has the same subject as current one."
6757   (interactive)
6758   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6759
6760 (defun gnus-summary-first-unread-article ()
6761   "Select the first unread article.
6762 Return nil if there are no unread articles."
6763   (interactive)
6764   (prog1
6765       (when (gnus-summary-first-subject t)
6766         (gnus-summary-show-thread)
6767         (gnus-summary-first-subject t)
6768         (gnus-summary-display-article (gnus-summary-article-number)))
6769     (gnus-summary-position-point)))
6770
6771 (defun gnus-summary-first-unread-subject ()
6772   "Place the point on the subject line of the first unread article.
6773 Return nil if there are no unread articles."
6774   (interactive)
6775   (prog1
6776       (when (gnus-summary-first-subject t)
6777         (gnus-summary-show-thread)
6778         (gnus-summary-first-subject t))
6779     (gnus-summary-position-point)))
6780
6781 (defun gnus-summary-first-unseen-subject ()
6782   "Place the point on the subject line of the first unseen article.
6783 Return nil if there are no unseen articles."
6784   (interactive)
6785   (prog1
6786       (when (gnus-summary-first-subject t t t)
6787         (gnus-summary-show-thread)
6788         (gnus-summary-first-subject t t t))
6789     (gnus-summary-position-point)))
6790
6791 (defun gnus-summary-first-article ()
6792   "Select the first article.
6793 Return nil if there are no articles."
6794   (interactive)
6795   (prog1
6796       (when (gnus-summary-first-subject)
6797         (gnus-summary-show-thread)
6798         (gnus-summary-first-subject)
6799         (gnus-summary-display-article (gnus-summary-article-number)))
6800     (gnus-summary-position-point)))
6801
6802 (defun gnus-summary-best-unread-article ()
6803   "Select the unread article with the highest score."
6804   (interactive)
6805   (let ((article (gnus-summary-best-unread-subject)))
6806     (if article
6807         (gnus-summary-goto-article article)
6808       (error "No unread articles"))))
6809
6810 (defun gnus-summary-best-unread-subject ()
6811   "Select the unread subject with the highest score."
6812   (interactive)
6813   (let ((best -1000000)
6814         (data gnus-newsgroup-data)
6815         article score)
6816     (while data
6817       (and (gnus-data-unread-p (car data))
6818            (> (setq score
6819                     (gnus-summary-article-score (gnus-data-number (car data))))
6820               best)
6821            (setq best score
6822                  article (gnus-data-number (car data))))
6823       (setq data (cdr data)))
6824     (gnus-summary-position-point)
6825     article))
6826
6827 (defun gnus-summary-last-subject ()
6828   "Go to the last displayed subject line in the group."
6829   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6830     (when article
6831       (gnus-summary-goto-subject article))))
6832
6833 (defun gnus-summary-goto-article (article &optional all-headers force)
6834   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6835 If ALL-HEADERS is non-nil, no header lines are hidden.
6836 If FORCE, go to the article even if it isn't displayed.  If FORCE
6837 is a number, it is the line the article is to be displayed on."
6838   (interactive
6839    (list
6840     (completing-read
6841      "Article number or Message-ID: "
6842      (mapcar (lambda (number) (list (int-to-string number)))
6843              gnus-newsgroup-limit))
6844     current-prefix-arg
6845     t))
6846   (prog1
6847       (if (and (stringp article)
6848                (string-match "@" article))
6849           (gnus-summary-refer-article article)
6850         (when (stringp article)
6851           (setq article (string-to-number article)))
6852         (if (gnus-summary-goto-subject article force)
6853             (gnus-summary-display-article article all-headers)
6854           (gnus-message 4 "Couldn't go to article %s" article) nil))
6855     (gnus-summary-position-point)))
6856
6857 (defun gnus-summary-goto-last-article ()
6858   "Go to the previously read article."
6859   (interactive)
6860   (prog1
6861       (when gnus-last-article
6862         (gnus-summary-goto-article gnus-last-article nil t))
6863     (gnus-summary-position-point)))
6864
6865 (defun gnus-summary-pop-article (number)
6866   "Pop one article off the history and go to the previous.
6867 NUMBER articles will be popped off."
6868   (interactive "p")
6869   (let (to)
6870     (setq gnus-newsgroup-history
6871           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6872     (if to
6873         (gnus-summary-goto-article (car to) nil t)
6874       (error "Article history empty")))
6875   (gnus-summary-position-point))
6876
6877 ;; Summary commands and functions for limiting the summary buffer.
6878
6879 (defun gnus-summary-limit-to-articles (n)
6880   "Limit the summary buffer to the next N articles.
6881 If not given a prefix, use the process marked articles instead."
6882   (interactive "P")
6883   (prog1
6884       (let ((articles (gnus-summary-work-articles n)))
6885         (setq gnus-newsgroup-processable nil)
6886         (gnus-summary-limit articles))
6887     (gnus-summary-position-point)))
6888
6889 (defun gnus-summary-pop-limit (&optional total)
6890   "Restore the previous limit.
6891 If given a prefix, remove all limits."
6892   (interactive "P")
6893   (when total
6894     (setq gnus-newsgroup-limits
6895           (list (mapcar (lambda (h) (mail-header-number h))
6896                         gnus-newsgroup-headers))))
6897   (unless gnus-newsgroup-limits
6898     (error "No limit to pop"))
6899   (prog1
6900       (gnus-summary-limit nil 'pop)
6901     (gnus-summary-position-point)))
6902
6903 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6904   "Limit the summary buffer to articles that have subjects that match a regexp.
6905 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6906   (interactive
6907    (list (read-string (if current-prefix-arg
6908                           "Exclude subject (regexp): "
6909                         "Limit to subject (regexp): "))
6910          nil current-prefix-arg))
6911   (unless header
6912     (setq header "subject"))
6913   (when (not (equal "" subject))
6914     (prog1
6915         (let ((articles (gnus-summary-find-matching
6916                          (or header "subject") subject 'all nil nil
6917                          not-matching)))
6918           (unless articles
6919             (error "Found no matches for \"%s\"" subject))
6920           (gnus-summary-limit articles))
6921       (gnus-summary-position-point))))
6922
6923 (defun gnus-summary-limit-to-author (from &optional not-matching)
6924   "Limit the summary buffer to articles that have authors that match a regexp.
6925 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6926   (interactive
6927    (list (read-string (if current-prefix-arg
6928                           "Exclude author (regexp): "
6929                         "Limit to author (regexp): "))
6930          current-prefix-arg))
6931   (gnus-summary-limit-to-subject from "from" not-matching))
6932
6933 (defun gnus-summary-limit-to-age (age &optional younger-p)
6934   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6935 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6936 articles that are younger than AGE days."
6937   (interactive
6938    (let ((younger current-prefix-arg)
6939          (days-got nil)
6940          days)
6941      (while (not days-got)
6942        (setq days (if younger
6943                       (read-string "Limit to articles within (in days): ")
6944                     (read-string "Limit to articles older than (in days): ")))
6945        (when (> (length days) 0)
6946          (setq days (read days)))
6947        (if (numberp days)
6948            (progn 
6949              (setq days-got t)
6950              (if (< days 0)
6951                  (progn 
6952                    (setq younger (not younger))
6953                    (setq days (* days -1)))))
6954          (message "Please enter a number.")
6955          (sleep-for 1)))
6956      (list days younger)))
6957   (prog1
6958       (let ((data gnus-newsgroup-data)
6959             (cutoff (days-to-time age))
6960             articles d date is-younger)
6961         (while (setq d (pop data))
6962           (when (and (vectorp (gnus-data-header d))
6963                      (setq date (mail-header-date (gnus-data-header d))))
6964             (setq is-younger (time-less-p
6965                               (time-since (condition-case ()
6966                                               (date-to-time date)
6967                                             (error '(0 0))))
6968                               cutoff))
6969             (when (if younger-p
6970                       is-younger
6971                     (not is-younger))
6972               (push (gnus-data-number d) articles))))
6973         (gnus-summary-limit (nreverse articles)))
6974     (gnus-summary-position-point)))
6975
6976 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
6977   "Limit the summary buffer to articles that match an 'extra' header."
6978   (interactive
6979    (let ((header
6980           (intern
6981            (gnus-completing-read
6982             (symbol-name (car gnus-extra-headers))
6983             (if current-prefix-arg
6984                 "Exclude extra header:"
6985               "Limit extra header:")
6986             (mapcar (lambda (x)
6987                       (cons (symbol-name x) x))
6988                     gnus-extra-headers)
6989             nil
6990             t))))
6991      (list header
6992            (read-string (format "%s header %s (regexp): "
6993                                 (if current-prefix-arg "Exclude" "Limit to")
6994                                 header))
6995            current-prefix-arg)))
6996   (when (not (equal "" regexp))
6997     (prog1
6998         (let ((articles (gnus-summary-find-matching
6999                          (cons 'extra header) regexp 'all nil nil
7000                          not-matching)))
7001           (unless articles
7002             (error "Found no matches for \"%s\"" regexp))
7003           (gnus-summary-limit articles))
7004       (gnus-summary-position-point))))
7005
7006 (defun gnus-summary-limit-to-display-predicate ()
7007   "Limit the summary buffer to the predicated in the `display' group parameter."
7008   (interactive)
7009   (unless gnus-newsgroup-display
7010     (error "There is no `display' group parameter"))
7011   (let (articles)
7012     (dolist (number gnus-newsgroup-articles)
7013       (when (funcall gnus-newsgroup-display)
7014         (push number articles)))
7015     (gnus-summary-limit articles))
7016   (gnus-summary-position-point))
7017
7018 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7019 (make-obsolete
7020  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7021
7022 (defun gnus-summary-limit-to-unread (&optional all)
7023   "Limit the summary buffer to articles that are not marked as read.
7024 If ALL is non-nil, limit strictly to unread articles."
7025   (interactive "P")
7026   (if all
7027       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7028     (gnus-summary-limit-to-marks
7029      ;; Concat all the marks that say that an article is read and have
7030      ;; those removed.
7031      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7032            gnus-killed-mark gnus-kill-file-mark
7033            gnus-low-score-mark gnus-expirable-mark
7034            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7035            gnus-duplicate-mark gnus-souped-mark)
7036      'reverse)))
7037
7038 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7039 (make-obsolete 'gnus-summary-delete-marked-with
7040                'gnus-summary-limit-exlude-marks)
7041
7042 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7043   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7044 If REVERSE, limit the summary buffer to articles that are marked
7045 with MARKS.  MARKS can either be a string of marks or a list of marks.
7046 Returns how many articles were removed."
7047   (interactive "sMarks: ")
7048   (gnus-summary-limit-to-marks marks t))
7049
7050 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7051   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7052 If REVERSE (the prefix), limit the summary buffer to articles that are
7053 not marked with MARKS.  MARKS can either be a string of marks or a
7054 list of marks.
7055 Returns how many articles were removed."
7056   (interactive "sMarks: \nP")
7057   (prog1
7058       (let ((data gnus-newsgroup-data)
7059             (marks (if (listp marks) marks
7060                      (append marks nil))) ; Transform to list.
7061             articles)
7062         (while data
7063           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7064                   (memq (gnus-data-mark (car data)) marks))
7065             (push (gnus-data-number (car data)) articles))
7066           (setq data (cdr data)))
7067         (gnus-summary-limit articles))
7068     (gnus-summary-position-point)))
7069
7070 (defun gnus-summary-limit-to-score (score)
7071   "Limit to articles with score at or above SCORE."
7072   (interactive "NLimit to articles with score of at least: ")
7073   (let ((data gnus-newsgroup-data)
7074         articles)
7075     (while data
7076       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7077                 score)
7078         (push (gnus-data-number (car data)) articles))
7079       (setq data (cdr data)))
7080     (prog1
7081         (gnus-summary-limit articles)
7082       (gnus-summary-position-point))))
7083
7084 (defun gnus-summary-limit-include-thread (id)
7085   "Display all the hidden articles that is in the thread with ID in it.
7086 When called interactively, ID is the Message-ID of the current
7087 article."
7088   (interactive (list (mail-header-id (gnus-summary-article-header))))
7089   (let ((articles (gnus-articles-in-thread
7090                    (gnus-id-to-thread (gnus-root-id id)))))
7091     (prog1
7092         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7093       (gnus-summary-limit-include-matching-articles
7094        "subject"
7095        (regexp-quote (gnus-simplify-subject-re
7096                       (mail-header-subject (gnus-id-to-header id)))))
7097       (gnus-summary-position-point))))
7098
7099 (defun gnus-summary-limit-include-matching-articles (header regexp)
7100   "Display all the hidden articles that have HEADERs that match REGEXP."
7101   (interactive (list (read-string "Match on header: ")
7102                      (read-string "Regexp: ")))
7103   (let ((articles (gnus-find-matching-articles header regexp)))
7104     (prog1
7105         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7106       (gnus-summary-position-point))))
7107
7108 (defun gnus-summary-limit-include-dormant ()
7109   "Display all the hidden articles that are marked as dormant.
7110 Note that this command only works on a subset of the articles currently
7111 fetched for this group."
7112   (interactive)
7113   (unless gnus-newsgroup-dormant
7114     (error "There are no dormant articles in this group"))
7115   (prog1
7116       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7117     (gnus-summary-position-point)))
7118
7119 (defun gnus-summary-limit-exclude-dormant ()
7120   "Hide all dormant articles."
7121   (interactive)
7122   (prog1
7123       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7124     (gnus-summary-position-point)))
7125
7126 (defun gnus-summary-limit-exclude-childless-dormant ()
7127   "Hide all dormant articles that have no children."
7128   (interactive)
7129   (let ((data (gnus-data-list t))
7130         articles d children)
7131     ;; Find all articles that are either not dormant or have
7132     ;; children.
7133     (while (setq d (pop data))
7134       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7135                 (and (setq children
7136                            (gnus-article-children (gnus-data-number d)))
7137                      (let (found)
7138                        (while children
7139                          (when (memq (car children) articles)
7140                            (setq children nil
7141                                  found t))
7142                          (pop children))
7143                        found)))
7144         (push (gnus-data-number d) articles)))
7145     ;; Do the limiting.
7146     (prog1
7147         (gnus-summary-limit articles)
7148       (gnus-summary-position-point))))
7149
7150 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7151   "Mark all unread excluded articles as read.
7152 If ALL, mark even excluded ticked and dormants as read."
7153   (interactive "P")
7154   (let ((articles (gnus-sorted-complement
7155                    (sort
7156                     (mapcar (lambda (h) (mail-header-number h))
7157                             gnus-newsgroup-headers)
7158                     '<)
7159                    (sort gnus-newsgroup-limit '<)))
7160         article)
7161     (setq gnus-newsgroup-unreads
7162           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7163     (if all
7164         (setq gnus-newsgroup-dormant nil
7165               gnus-newsgroup-marked nil
7166               gnus-newsgroup-reads
7167               (nconc
7168                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7169                gnus-newsgroup-reads))
7170       (while (setq article (pop articles))
7171         (unless (or (memq article gnus-newsgroup-dormant)
7172                     (memq article gnus-newsgroup-marked))
7173           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7174
7175 (defun gnus-summary-limit (articles &optional pop)
7176   (if pop
7177       ;; We pop the previous limit off the stack and use that.
7178       (setq articles (car gnus-newsgroup-limits)
7179             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7180     ;; We use the new limit, so we push the old limit on the stack.
7181     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7182   ;; Set the limit.
7183   (setq gnus-newsgroup-limit articles)
7184   (let ((total (length gnus-newsgroup-data))
7185         (data (gnus-data-find-list (gnus-summary-article-number)))
7186         (gnus-summary-mark-below nil)   ; Inhibit this.
7187         found)
7188     ;; This will do all the work of generating the new summary buffer
7189     ;; according to the new limit.
7190     (gnus-summary-prepare)
7191     ;; Hide any threads, possibly.
7192     (and gnus-show-threads
7193          gnus-thread-hide-subtree
7194          (gnus-summary-hide-all-threads))
7195     ;; Try to return to the article you were at, or one in the
7196     ;; neighborhood.
7197     (when data
7198       ;; We try to find some article after the current one.
7199       (while data
7200         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7201           (setq data nil
7202                 found t))
7203         (setq data (cdr data))))
7204     (unless found
7205       ;; If there is no data, that means that we were after the last
7206       ;; article.  The same goes when we can't find any articles
7207       ;; after the current one.
7208       (goto-char (point-max))
7209       (gnus-summary-find-prev))
7210     (gnus-set-mode-line 'summary)
7211     ;; We return how many articles were removed from the summary
7212     ;; buffer as a result of the new limit.
7213     (- total (length gnus-newsgroup-data))))
7214
7215 (defsubst gnus-invisible-cut-children (threads)
7216   (let ((num 0))
7217     (while threads
7218       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7219         (incf num))
7220       (pop threads))
7221     (< num 2)))
7222
7223 (defsubst gnus-cut-thread (thread)
7224   "Go forwards in the thread until we find an article that we want to display."
7225   (when (or (eq gnus-fetch-old-headers 'some)
7226             (eq gnus-fetch-old-headers 'invisible)
7227             (numberp gnus-fetch-old-headers)
7228             (eq gnus-build-sparse-threads 'some)
7229             (eq gnus-build-sparse-threads 'more))
7230     ;; Deal with old-fetched headers and sparse threads.
7231     (while (and
7232             thread
7233             (or
7234              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7235              (gnus-summary-article-ancient-p
7236               (mail-header-number (car thread))))
7237             (if (or (<= (length (cdr thread)) 1)
7238                     (eq gnus-fetch-old-headers 'invisible))
7239                 (setq gnus-newsgroup-limit
7240                       (delq (mail-header-number (car thread))
7241                             gnus-newsgroup-limit)
7242                       thread (cadr thread))
7243               (when (gnus-invisible-cut-children (cdr thread))
7244                 (let ((th (cdr thread)))
7245                   (while th
7246                     (if (memq (mail-header-number (caar th))
7247                               gnus-newsgroup-limit)
7248                         (setq thread (car th)
7249                               th nil)
7250                       (setq th (cdr th))))))))))
7251   thread)
7252
7253 (defun gnus-cut-threads (threads)
7254   "Cut off all uninteresting articles from the beginning of threads."
7255   (when (or (eq gnus-fetch-old-headers 'some)
7256             (eq gnus-fetch-old-headers 'invisible)
7257             (numberp gnus-fetch-old-headers)
7258             (eq gnus-build-sparse-threads 'some)
7259             (eq gnus-build-sparse-threads 'more))
7260     (let ((th threads))
7261       (while th
7262         (setcar th (gnus-cut-thread (car th)))
7263         (setq th (cdr th)))))
7264   ;; Remove nixed out threads.
7265   (delq nil threads))
7266
7267 (defun gnus-summary-initial-limit (&optional show-if-empty)
7268   "Figure out what the initial limit is supposed to be on group entry.
7269 This entails weeding out unwanted dormants, low-scored articles,
7270 fetch-old-headers verbiage, and so on."
7271   ;; Most groups have nothing to remove.
7272   (if (or gnus-inhibit-limiting
7273           (and (null gnus-newsgroup-dormant)
7274                (eq gnus-newsgroup-display 'gnus-not-ignore)
7275                (not (eq gnus-fetch-old-headers 'some))
7276                (not (numberp gnus-fetch-old-headers))
7277                (not (eq gnus-fetch-old-headers 'invisible))
7278                (null gnus-summary-expunge-below)
7279                (not (eq gnus-build-sparse-threads 'some))
7280                (not (eq gnus-build-sparse-threads 'more))
7281                (null gnus-thread-expunge-below)
7282                (not gnus-use-nocem)))
7283       ()                                ; Do nothing.
7284     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7285     (setq gnus-newsgroup-limit nil)
7286     (mapatoms
7287      (lambda (node)
7288        (unless (car (symbol-value node))
7289          ;; These threads have no parents -- they are roots.
7290          (let ((nodes (cdr (symbol-value node)))
7291                thread)
7292            (while nodes
7293              (if (and gnus-thread-expunge-below
7294                       (< (gnus-thread-total-score (car nodes))
7295                          gnus-thread-expunge-below))
7296                  (gnus-expunge-thread (pop nodes))
7297                (setq thread (pop nodes))
7298                (gnus-summary-limit-children thread))))))
7299      gnus-newsgroup-dependencies)
7300     ;; If this limitation resulted in an empty group, we might
7301     ;; pop the previous limit and use it instead.
7302     (when (and (not gnus-newsgroup-limit)
7303                show-if-empty)
7304       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7305     gnus-newsgroup-limit))
7306
7307 (defun gnus-summary-limit-children (thread)
7308   "Return 1 if this subthread is visible and 0 if it is not."
7309   ;; First we get the number of visible children to this thread.  This
7310   ;; is done by recursing down the thread using this function, so this
7311   ;; will really go down to a leaf article first, before slowly
7312   ;; working its way up towards the root.
7313   (when thread
7314     (let ((children
7315            (if (cdr thread)
7316                (apply '+ (mapcar 'gnus-summary-limit-children
7317                                  (cdr thread)))
7318              0))
7319           (number (mail-header-number (car thread)))
7320           score)
7321       (if (and
7322            (not (memq number gnus-newsgroup-marked))
7323            (or
7324             ;; If this article is dormant and has absolutely no visible
7325             ;; children, then this article isn't visible.
7326             (and (memq number gnus-newsgroup-dormant)
7327                  (zerop children))
7328             ;; If this is "fetch-old-headered" and there is no
7329             ;; visible children, then we don't want this article.
7330             (and (or (eq gnus-fetch-old-headers 'some)
7331                      (numberp gnus-fetch-old-headers))
7332                  (gnus-summary-article-ancient-p number)
7333                  (zerop children))
7334             ;; If this is "fetch-old-headered" and `invisible', then
7335             ;; we don't want this article.
7336             (and (eq gnus-fetch-old-headers 'invisible)
7337                  (gnus-summary-article-ancient-p number))
7338             ;; If this is a sparsely inserted article with no children,
7339             ;; we don't want it.
7340             (and (eq gnus-build-sparse-threads 'some)
7341                  (gnus-summary-article-sparse-p number)
7342                  (zerop children))
7343             ;; If we use expunging, and this article is really
7344             ;; low-scored, then we don't want this article.
7345             (when (and gnus-summary-expunge-below
7346                        (< (setq score
7347                                 (or (cdr (assq number gnus-newsgroup-scored))
7348                                     gnus-summary-default-score))
7349                           gnus-summary-expunge-below))
7350               ;; We increase the expunge-tally here, but that has
7351               ;; nothing to do with the limits, really.
7352               (incf gnus-newsgroup-expunged-tally)
7353               ;; We also mark as read here, if that's wanted.
7354               (when (and gnus-summary-mark-below
7355                          (< score gnus-summary-mark-below))
7356                 (setq gnus-newsgroup-unreads
7357                       (delq number gnus-newsgroup-unreads))
7358                 (if gnus-newsgroup-auto-expire
7359                     (push number gnus-newsgroup-expirable)
7360                   (push (cons number gnus-low-score-mark)
7361                         gnus-newsgroup-reads)))
7362               t)
7363             ;; Do the `display' group parameter.
7364             (and gnus-newsgroup-display
7365                  (not (funcall gnus-newsgroup-display)))
7366             ;; Check NoCeM things.
7367             (if (and gnus-use-nocem
7368                      (gnus-nocem-unwanted-article-p
7369                       (mail-header-id (car thread))))
7370                 (progn
7371                   (setq gnus-newsgroup-unreads
7372                         (delq number gnus-newsgroup-unreads))
7373                   t))))
7374           ;; Nope, invisible article.
7375           0
7376         ;; Ok, this article is to be visible, so we add it to the limit
7377         ;; and return 1.
7378         (push number gnus-newsgroup-limit)
7379         1))))
7380
7381 (defun gnus-expunge-thread (thread)
7382   "Mark all articles in THREAD as read."
7383   (let* ((number (mail-header-number (car thread))))
7384     (incf gnus-newsgroup-expunged-tally)
7385     ;; We also mark as read here, if that's wanted.
7386     (setq gnus-newsgroup-unreads
7387           (delq number gnus-newsgroup-unreads))
7388     (if gnus-newsgroup-auto-expire
7389         (push number gnus-newsgroup-expirable)
7390       (push (cons number gnus-low-score-mark)
7391             gnus-newsgroup-reads)))
7392   ;; Go recursively through all subthreads.
7393   (mapcar 'gnus-expunge-thread (cdr thread)))
7394
7395 ;; Summary article oriented commands
7396
7397 (defun gnus-summary-refer-parent-article (n)
7398   "Refer parent article N times.
7399 If N is negative, go to ancestor -N instead.
7400 The difference between N and the number of articles fetched is returned."
7401   (interactive "p")
7402   (let ((skip 1)
7403         error header ref)
7404     (when (not (natnump n))
7405       (setq skip (abs n)
7406             n 1))
7407     (while (and (> n 0)
7408                 (not error))
7409       (setq header (gnus-summary-article-header))
7410       (if (and (eq (mail-header-number header)
7411                    (cdr gnus-article-current))
7412                (equal gnus-newsgroup-name
7413                       (car gnus-article-current)))
7414           ;; If we try to find the parent of the currently
7415           ;; displayed article, then we take a look at the actual
7416           ;; References header, since this is slightly more
7417           ;; reliable than the References field we got from the
7418           ;; server.
7419           (save-excursion
7420             (set-buffer gnus-original-article-buffer)
7421             (nnheader-narrow-to-headers)
7422             (unless (setq ref (message-fetch-field "references"))
7423               (setq ref (message-fetch-field "in-reply-to")))
7424             (widen))
7425         (setq ref
7426               ;; It's not the current article, so we take a bet on
7427               ;; the value we got from the server.
7428               (mail-header-references header)))
7429       (if (and ref
7430                (not (equal ref "")))
7431           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7432             (gnus-message 1 "Couldn't find parent"))
7433         (gnus-message 1 "No references in article %d"
7434                       (gnus-summary-article-number))
7435         (setq error t))
7436       (decf n))
7437     (gnus-summary-position-point)
7438     n))
7439
7440 (defun gnus-summary-refer-references ()
7441   "Fetch all articles mentioned in the References header.
7442 Return the number of articles fetched."
7443   (interactive)
7444   (let ((ref (mail-header-references (gnus-summary-article-header)))
7445         (current (gnus-summary-article-number))
7446         (n 0))
7447     (if (or (not ref)
7448             (equal ref ""))
7449         (error "No References in the current article")
7450       ;; For each Message-ID in the References header...
7451       (while (string-match "<[^>]*>" ref)
7452         (incf n)
7453         ;; ... fetch that article.
7454         (gnus-summary-refer-article
7455          (prog1 (match-string 0 ref)
7456            (setq ref (substring ref (match-end 0))))))
7457       (gnus-summary-goto-subject current)
7458       (gnus-summary-position-point)
7459       n)))
7460
7461 (defun gnus-summary-refer-thread (&optional limit)
7462   "Fetch all articles in the current thread.
7463 If LIMIT (the numerical prefix), fetch that many old headers instead
7464 of what's specified by the `gnus-refer-thread-limit' variable."
7465   (interactive "P")
7466   (let ((id (mail-header-id (gnus-summary-article-header)))
7467         (limit (if limit (prefix-numeric-value limit)
7468                  gnus-refer-thread-limit)))
7469     ;; We want to fetch LIMIT *old* headers, but we also have to
7470     ;; re-fetch all the headers in the current buffer, because many of
7471     ;; them may be undisplayed.  So we adjust LIMIT.
7472     (when (numberp limit)
7473       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7474     (unless (eq gnus-fetch-old-headers 'invisible)
7475       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7476       ;; Retrieve the headers and read them in.
7477       (if (eq (gnus-retrieve-headers
7478                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7479               'nov)
7480           (gnus-build-all-threads)
7481         (error "Can't fetch thread from backends that don't support NOV"))
7482       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7483     (gnus-summary-limit-include-thread id)))
7484
7485 (defun gnus-summary-refer-article (message-id)
7486   "Fetch an article specified by MESSAGE-ID."
7487   (interactive "sMessage-ID: ")
7488   (when (and (stringp message-id)
7489              (not (zerop (length message-id))))
7490     ;; Construct the correct Message-ID if necessary.
7491     ;; Suggested by tale@pawl.rpi.edu.
7492     (unless (string-match "^<" message-id)
7493       (setq message-id (concat "<" message-id)))
7494     (unless (string-match ">$" message-id)
7495       (setq message-id (concat message-id ">")))
7496     (let* ((header (gnus-id-to-header message-id))
7497            (sparse (and header
7498                         (gnus-summary-article-sparse-p
7499                          (mail-header-number header))
7500                         (memq (mail-header-number header)
7501                               gnus-newsgroup-limit)))
7502            number)
7503       (cond
7504        ;; If the article is present in the buffer we just go to it.
7505        ((and header
7506              (or (not (gnus-summary-article-sparse-p
7507                        (mail-header-number header)))
7508                  sparse))
7509         (prog1
7510             (gnus-summary-goto-article
7511              (mail-header-number header) nil t)
7512           (when sparse
7513             (gnus-summary-update-article (mail-header-number header)))))
7514        (t
7515         ;; We fetch the article.
7516         (catch 'found
7517           (dolist (gnus-override-method (gnus-refer-article-methods))
7518             (gnus-check-server gnus-override-method)
7519             ;; Fetch the header, and display the article.
7520             (when (setq number (gnus-summary-insert-subject message-id))
7521               (gnus-summary-select-article nil nil nil number)
7522               (throw 'found t)))
7523           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7524
7525 (defun gnus-refer-article-methods ()
7526   "Return a list of referrable methods."
7527   (cond
7528    ;; No method, so we default to current and native.
7529    ((null gnus-refer-article-method)
7530     (list gnus-current-select-method gnus-select-method))
7531    ;; Current.
7532    ((eq 'current gnus-refer-article-method)
7533     (list gnus-current-select-method))
7534    ;; List of select methods.
7535    ((not (and (symbolp (car gnus-refer-article-method))
7536               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7537     (let (out)
7538       (dolist (method gnus-refer-article-method)
7539         (push (if (eq 'current method)
7540                   gnus-current-select-method
7541                 method)
7542               out))
7543       (nreverse out)))
7544    ;; One single select method.
7545    (t
7546     (list gnus-refer-article-method))))
7547
7548 (defun gnus-summary-edit-parameters ()
7549   "Edit the group parameters of the current group."
7550   (interactive)
7551   (gnus-group-edit-group gnus-newsgroup-name 'params))
7552
7553 (defun gnus-summary-customize-parameters ()
7554   "Customize the group parameters of the current group."
7555   (interactive)
7556   (gnus-group-customize gnus-newsgroup-name))
7557
7558 (defun gnus-summary-enter-digest-group (&optional force)
7559   "Enter an nndoc group based on the current article.
7560 If FORCE, force a digest interpretation.  If not, try
7561 to guess what the document format is."
7562   (interactive "P")
7563   (let ((conf gnus-current-window-configuration))
7564     (save-excursion
7565       (gnus-summary-select-article))
7566     (setq gnus-current-window-configuration conf)
7567     (let* ((name (format "%s-%d"
7568                          (gnus-group-prefixed-name
7569                           gnus-newsgroup-name (list 'nndoc ""))
7570                          (save-excursion
7571                            (set-buffer gnus-summary-buffer)
7572                            gnus-current-article)))
7573            (ogroup gnus-newsgroup-name)
7574            (params (append (gnus-info-params (gnus-get-info ogroup))
7575                            (list (cons 'to-group ogroup))
7576                            (list (cons 'save-article-group ogroup))))
7577            (case-fold-search t)
7578            (buf (current-buffer))
7579            dig to-address)
7580       (save-excursion
7581         (set-buffer gnus-original-article-buffer)
7582         ;; Have the digest group inherit the main mail address of
7583         ;; the parent article.
7584         (when (setq to-address (or (message-fetch-field "reply-to")
7585                                    (message-fetch-field "from")))
7586           (setq params (append
7587                         (list (cons 'to-address
7588                                     (funcall gnus-decode-encoded-word-function
7589                                              to-address))))))
7590         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7591         (insert-buffer-substring gnus-original-article-buffer)
7592         ;; Remove lines that may lead nndoc to misinterpret the
7593         ;; document type.
7594         (narrow-to-region
7595          (goto-char (point-min))
7596          (or (search-forward "\n\n" nil t) (point)))
7597         (goto-char (point-min))
7598         (delete-matching-lines "^Path:\\|^From ")
7599         (widen))
7600       (unwind-protect
7601           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7602                     (gnus-newsgroup-ephemeral-ignored-charsets
7603                      gnus-newsgroup-ignored-charsets))
7604                 (gnus-group-read-ephemeral-group
7605                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7606                               (nndoc-article-type
7607                                ,(if force 'mbox 'guess))) t))
7608             ;; Make all postings to this group go to the parent group.
7609               (nconc (gnus-info-params (gnus-get-info name))
7610                      params)
7611             ;; Couldn't select this doc group.
7612             (switch-to-buffer buf)
7613             (gnus-set-global-variables)
7614             (gnus-configure-windows 'summary)
7615             (gnus-message 3 "Article couldn't be entered?"))
7616         (kill-buffer dig)))))
7617
7618 (defun gnus-summary-read-document (n)
7619   "Open a new group based on the current article(s).
7620 This will allow you to read digests and other similar
7621 documents as newsgroups.
7622 Obeys the standard process/prefix convention."
7623   (interactive "P")
7624   (let* ((articles (gnus-summary-work-articles n))
7625          (ogroup gnus-newsgroup-name)
7626          (params (append (gnus-info-params (gnus-get-info ogroup))
7627                          (list (cons 'to-group ogroup))))
7628          article group egroup groups vgroup)
7629     (while (setq article (pop articles))
7630       (setq group (format "%s-%d" gnus-newsgroup-name article))
7631       (gnus-summary-remove-process-mark article)
7632       (when (gnus-summary-display-article article)
7633         (save-excursion
7634           (with-temp-buffer
7635             (insert-buffer-substring gnus-original-article-buffer)
7636             ;; Remove some headers that may lead nndoc to make
7637             ;; the wrong guess.
7638             (message-narrow-to-head)
7639             (goto-char (point-min))
7640             (delete-matching-lines "^\\(Path\\):\\|^From ")
7641             (widen)
7642             (if (setq egroup
7643                       (gnus-group-read-ephemeral-group
7644                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7645                                      (nndoc-article-type guess))
7646                        t nil t))
7647                 (progn
7648             ;; Make all postings to this group go to the parent group.
7649                   (nconc (gnus-info-params (gnus-get-info egroup))
7650                          params)
7651                   (push egroup groups))
7652               ;; Couldn't select this doc group.
7653               (gnus-error 3 "Article couldn't be entered"))))))
7654     ;; Now we have selected all the documents.
7655     (cond
7656      ((not groups)
7657       (error "None of the articles could be interpreted as documents"))
7658      ((gnus-group-read-ephemeral-group
7659        (setq vgroup (format
7660                      "nnvirtual:%s-%s" gnus-newsgroup-name
7661                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7662        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7663        t
7664        (cons (current-buffer) 'summary)))
7665      (t
7666       (error "Couldn't select virtual nndoc group")))))
7667
7668 (defun gnus-summary-isearch-article (&optional regexp-p)
7669   "Do incremental search forward on the current article.
7670 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7671   (interactive "P")
7672   (gnus-summary-select-article)
7673   (gnus-configure-windows 'article)
7674   (gnus-eval-in-buffer-window gnus-article-buffer
7675     (save-restriction
7676       (widen)
7677       (isearch-forward regexp-p))))
7678
7679 (defun gnus-summary-search-article-forward (regexp &optional backward)
7680   "Search for an article containing REGEXP forward.
7681 If BACKWARD, search backward instead."
7682   (interactive
7683    (list (read-string
7684           (format "Search article %s (regexp%s): "
7685                   (if current-prefix-arg "backward" "forward")
7686                   (if gnus-last-search-regexp
7687                       (concat ", default " gnus-last-search-regexp)
7688                     "")))
7689          current-prefix-arg))
7690   (if (string-equal regexp "")
7691       (setq regexp (or gnus-last-search-regexp ""))
7692     (setq gnus-last-search-regexp regexp)
7693     (setq gnus-article-before-search gnus-current-article))
7694   ;; Intentionally set gnus-last-article.
7695   (setq gnus-last-article gnus-article-before-search)
7696   (let ((gnus-last-article gnus-last-article))
7697     (if (gnus-summary-search-article regexp backward)
7698         (gnus-summary-show-thread)
7699       (error "Search failed: \"%s\"" regexp))))
7700
7701 (defun gnus-summary-search-article-backward (regexp)
7702   "Search for an article containing REGEXP backward."
7703   (interactive
7704    (list (read-string
7705           (format "Search article backward (regexp%s): "
7706                   (if gnus-last-search-regexp
7707                       (concat ", default " gnus-last-search-regexp)
7708                     "")))))
7709   (gnus-summary-search-article-forward regexp 'backward))
7710
7711 (defun gnus-summary-search-article (regexp &optional backward)
7712   "Search for an article containing REGEXP.
7713 Optional argument BACKWARD means do search for backward.
7714 `gnus-select-article-hook' is not called during the search."
7715   ;; We have to require this here to make sure that the following
7716   ;; dynamic binding isn't shadowed by autoloading.
7717   (require 'gnus-async)
7718   (require 'gnus-art)
7719   (let ((gnus-select-article-hook nil)  ;Disable hook.
7720         (gnus-article-prepare-hook nil)
7721         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7722         (gnus-use-article-prefetch nil)
7723         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7724         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7725         (sum (current-buffer))
7726         (gnus-display-mime-function nil)
7727         (found nil)
7728         point)
7729     (gnus-save-hidden-threads
7730       (gnus-summary-select-article)
7731       (set-buffer gnus-article-buffer)
7732       (goto-char (window-point (get-buffer-window (current-buffer))))
7733       (when backward
7734         (forward-line -1))
7735       (while (not found)
7736         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7737         (if (if backward
7738                 (re-search-backward regexp nil t)
7739               (re-search-forward regexp nil t))
7740             ;; We found the regexp.
7741             (progn
7742               (setq found 'found)
7743               (beginning-of-line)
7744               (set-window-start
7745                (get-buffer-window (current-buffer))
7746                (point))
7747               (forward-line 1)
7748               (set-window-point
7749                (get-buffer-window (current-buffer))
7750                (point))
7751               (set-buffer sum)
7752               (setq point (point)))
7753           ;; We didn't find it, so we go to the next article.
7754           (set-buffer sum)
7755           (setq found 'not)
7756           (while (eq found 'not)
7757             (if (not (if backward (gnus-summary-find-prev)
7758                        (gnus-summary-find-next)))
7759                 ;; No more articles.
7760                 (setq found t)
7761               ;; Select the next article and adjust point.
7762               (unless (gnus-summary-article-sparse-p
7763                        (gnus-summary-article-number))
7764                 (setq found nil)
7765                 (gnus-summary-select-article)
7766                 (set-buffer gnus-article-buffer)
7767                 (widen)
7768                 (goto-char (if backward (point-max) (point-min))))))))
7769       (gnus-message 7 ""))
7770     ;; Return whether we found the regexp.
7771     (when (eq found 'found)
7772       (goto-char point)
7773       (gnus-summary-show-thread)
7774       (gnus-summary-goto-subject gnus-current-article)
7775       (gnus-summary-position-point)
7776       t)))
7777
7778 (defun gnus-find-matching-articles (header regexp)
7779   "Return a list of all articles that match REGEXP on HEADER.
7780 This search includes all articles in the current group that Gnus has
7781 fetched headers for, whether they are displayed or not."
7782   (let ((articles nil)
7783         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7784         (case-fold-search t))
7785     (dolist (header gnus-newsgroup-headers)
7786       (when (string-match regexp (funcall func header))
7787         (push (mail-header-number header) articles)))
7788     (nreverse articles)))
7789
7790 (defun gnus-summary-find-matching (header regexp &optional backward unread
7791                                           not-case-fold not-matching)
7792   "Return a list of all articles that match REGEXP on HEADER.
7793 The search stars on the current article and goes forwards unless
7794 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7795 If UNREAD is non-nil, only unread articles will
7796 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7797 in the comparisons. If NOT-MATCHING, return a list of all articles that
7798 not match REGEXP on HEADER."
7799   (let ((case-fold-search (not not-case-fold))
7800         articles d func)
7801     (if (consp header)
7802         (if (eq (car header) 'extra)
7803             (setq func
7804                   `(lambda (h)
7805                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7806                          "")))
7807           (error "%s is an invalid header" header))
7808       (unless (fboundp (intern (concat "mail-header-" header)))
7809         (error "%s is not a valid header" header))
7810       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7811     (dolist (d (if (eq backward 'all)
7812                    gnus-newsgroup-data
7813                  (gnus-data-find-list
7814                   (gnus-summary-article-number)
7815                   (gnus-data-list backward))))
7816       (when (and (or (not unread)       ; We want all articles...
7817                      (gnus-data-unread-p d)) ; Or just unreads.
7818                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7819                  (if not-matching
7820                      (not (string-match
7821                            regexp
7822                            (funcall func (gnus-data-header d))))
7823                    (string-match regexp
7824                                  (funcall func (gnus-data-header d)))))
7825         (push (gnus-data-number d) articles))) ; Success!
7826     (nreverse articles)))
7827
7828 (defun gnus-summary-execute-command (header regexp command &optional backward)
7829   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7830 If HEADER is an empty string (or nil), the match is done on the entire
7831 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7832   (interactive
7833    (list (let ((completion-ignore-case t))
7834            (completing-read
7835             "Header name: "
7836             (mapcar (lambda (header) (list (format "%s" header)))
7837                     (append
7838                      '("Number" "Subject" "From" "Lines" "Date"
7839                        "Message-ID" "Xref" "References" "Body")
7840                      gnus-extra-headers))
7841             nil 'require-match))
7842          (read-string "Regexp: ")
7843          (read-key-sequence "Command: ")
7844          current-prefix-arg))
7845   (when (equal header "Body")
7846     (setq header ""))
7847   ;; Hidden thread subtrees must be searched as well.
7848   (gnus-summary-show-all-threads)
7849   ;; We don't want to change current point nor window configuration.
7850   (save-excursion
7851     (save-window-excursion
7852       (gnus-message 6 "Executing %s..." (key-description command))
7853 ;; We'd like to execute COMMAND interactively so as to give arguments.
7854       (gnus-execute header regexp
7855                     `(call-interactively ',(key-binding command))
7856                     backward)
7857       (gnus-message 6 "Executing %s...done" (key-description command)))))
7858
7859 (defun gnus-summary-beginning-of-article ()
7860   "Scroll the article back to the beginning."
7861   (interactive)
7862   (gnus-summary-select-article)
7863   (gnus-configure-windows 'article)
7864   (gnus-eval-in-buffer-window gnus-article-buffer
7865     (widen)
7866     (goto-char (point-min))
7867     (when gnus-page-broken
7868       (gnus-narrow-to-page))))
7869
7870 (defun gnus-summary-end-of-article ()
7871   "Scroll to the end of the article."
7872   (interactive)
7873   (gnus-summary-select-article)
7874   (gnus-configure-windows 'article)
7875   (gnus-eval-in-buffer-window gnus-article-buffer
7876     (widen)
7877     (goto-char (point-max))
7878     (recenter -3)
7879     (when gnus-page-broken
7880       (gnus-narrow-to-page))))
7881
7882 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7883   "Truncate to LEN and quote all \"(\"'s in STRING."
7884   (gnus-replace-in-string (if (and len (> (length string) len))
7885                               (substring string 0 len)
7886                             string)
7887                           "[()]" "\\\\\\&"))
7888
7889 (defun gnus-summary-print-article (&optional filename n)
7890   "Generate and print a PostScript image of the N next (mail) articles.
7891
7892 If N is negative, print the N previous articles.  If N is nil and articles
7893 have been marked with the process mark, print these instead.
7894
7895 If the optional first argument FILENAME is nil, send the image to the
7896 printer.  If FILENAME is a string, save the PostScript image in a file with
7897 that name.  If FILENAME is a number, prompt the user for the name of the file
7898 to save in."
7899   (interactive (list (ps-print-preprint current-prefix-arg)))
7900   (dolist (article (gnus-summary-work-articles n))
7901     (gnus-summary-select-article nil nil 'pseudo article)
7902     (gnus-eval-in-buffer-window gnus-article-buffer
7903       (gnus-print-buffer))
7904     (gnus-summary-remove-process-mark article))
7905   (ps-despool filename))
7906
7907 (defun gnus-print-buffer ()
7908   (let ((buffer (generate-new-buffer " *print*")))
7909     (unwind-protect
7910         (progn
7911           (copy-to-buffer buffer (point-min) (point-max))
7912           (set-buffer buffer)
7913           (gnus-article-delete-invisible-text)
7914           (when (gnus-visual-p 'article-highlight 'highlight)
7915             ;; Copy-to-buffer doesn't copy overlay.  So redo
7916             ;; highlight.
7917             (let ((gnus-article-buffer buffer))
7918               (gnus-article-highlight-citation t)
7919               (gnus-article-highlight-signature)))
7920           (let ((ps-left-header
7921                  (list
7922                   (concat "("
7923                           (gnus-summary-print-truncate-and-quote
7924                            (mail-header-subject gnus-current-headers)
7925                            66) ")")
7926                   (concat "("
7927                           (gnus-summary-print-truncate-and-quote
7928                            (mail-header-from gnus-current-headers)
7929                            45) ")")))
7930                 (ps-right-header
7931                  (list
7932                   "/pagenumberstring load"
7933                   (concat "("
7934                           (mail-header-date gnus-current-headers) ")"))))
7935             (gnus-run-hooks 'gnus-ps-print-hook)
7936             (save-excursion
7937               (if window-system
7938                   (ps-spool-buffer-with-faces)
7939                 (ps-spool-buffer)))))
7940       (kill-buffer buffer))))
7941
7942 (defun gnus-summary-show-article (&optional arg)
7943   "Force redisplaying of the current article.
7944 If ARG (the prefix) is a number, show the article with the charset
7945 defined in `gnus-summary-show-article-charset-alist', or the charset
7946 input.
7947 If ARG (the prefix) is non-nil and not a number, show the raw article
7948 without any article massaging functions being run.  Normally, the key strokes 
7949 are `C-u g'."
7950   (interactive "P")
7951   (cond
7952    ((numberp arg)
7953     (gnus-summary-show-article t)
7954     (let ((gnus-newsgroup-charset
7955            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7956                (mm-read-coding-system
7957                 "View as charset: "
7958                 (save-excursion
7959                   (set-buffer gnus-article-buffer)
7960                   (let ((coding-systems
7961                          (detect-coding-region (point) (point-max))))
7962                     (or (car-safe coding-systems)
7963                         coding-systems))))))
7964           (gnus-newsgroup-ignored-charsets 'gnus-all))
7965       (gnus-summary-select-article nil 'force)
7966       (let ((deps gnus-newsgroup-dependencies)
7967             head header lines)
7968         (save-excursion
7969           (set-buffer gnus-original-article-buffer)
7970           (save-restriction
7971             (message-narrow-to-head)
7972             (setq head (buffer-string))
7973             (goto-char (point-min))
7974             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
7975               (goto-char (point-max))
7976               (widen)
7977               (setq lines (1- (count-lines (point) (point-max))))))
7978           (with-temp-buffer
7979             (insert (format "211 %d Article retrieved.\n"
7980                             (cdr gnus-article-current)))
7981             (insert head)
7982             (if lines (insert (format "Lines: %d\n" lines)))
7983             (insert ".\n")
7984             (let ((nntp-server-buffer (current-buffer)))
7985               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7986         (gnus-data-set-header
7987          (gnus-data-find (cdr gnus-article-current))
7988          header)
7989         (gnus-summary-update-article-line
7990          (cdr gnus-article-current) header)
7991         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
7992           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
7993    ((not arg)
7994     ;; Select the article the normal way.
7995     (gnus-summary-select-article nil 'force))
7996    (t
7997     ;; We have to require this here to make sure that the following
7998     ;; dynamic binding isn't shadowed by autoloading.
7999     (require 'gnus-async)
8000     (require 'gnus-art)
8001     ;; Bind the article treatment functions to nil.
8002     (let ((gnus-have-all-headers t)
8003           gnus-article-prepare-hook
8004           gnus-article-decode-hook
8005           gnus-display-mime-function
8006           gnus-break-pages)
8007       ;; Destroy any MIME parts.
8008       (when (gnus-buffer-live-p gnus-article-buffer)
8009         (save-excursion
8010           (set-buffer gnus-article-buffer)
8011           (mm-destroy-parts gnus-article-mime-handles)
8012           ;; Set it to nil for safety reason.
8013           (setq gnus-article-mime-handle-alist nil)
8014           (setq gnus-article-mime-handles nil)))
8015       (gnus-summary-select-article nil 'force))))
8016   (gnus-summary-goto-subject gnus-current-article)
8017   (gnus-summary-position-point))
8018
8019 (defun gnus-summary-show-raw-article ()
8020   "Show the raw article without any article massaging functions being run."
8021   (interactive)
8022   (gnus-summary-show-article t))
8023
8024 (defun gnus-summary-verbose-headers (&optional arg)
8025   "Toggle permanent full header display.
8026 If ARG is a positive number, turn header display on.
8027 If ARG is a negative number, turn header display off."
8028   (interactive "P")
8029   (setq gnus-show-all-headers
8030         (cond ((or (not (numberp arg))
8031                    (zerop arg))
8032                (not gnus-show-all-headers))
8033               ((natnump arg)
8034                t)))
8035   (gnus-summary-show-article))
8036
8037 (defun gnus-summary-toggle-header (&optional arg)
8038   "Show the headers if they are hidden, or hide them if they are shown.
8039 If ARG is a positive number, show the entire header.
8040 If ARG is a negative number, hide the unwanted header lines."
8041   (interactive "P")
8042   (save-excursion
8043     (set-buffer gnus-article-buffer)
8044     (save-restriction
8045       (let* ((buffer-read-only nil)
8046              (inhibit-point-motion-hooks t)
8047              hidden e)
8048         (setq hidden
8049               (if (numberp arg)
8050                   (>= arg 0)
8051                 (save-restriction
8052                   (article-narrow-to-head)
8053                   (gnus-article-hidden-text-p 'headers))))
8054         (goto-char (point-min))
8055         (when (search-forward "\n\n" nil t)
8056           (delete-region (point-min) (1- (point))))
8057         (goto-char (point-min))
8058         (save-excursion
8059           (set-buffer gnus-original-article-buffer)
8060           (goto-char (point-min))
8061           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8062         (insert-buffer-substring gnus-original-article-buffer 1 e)
8063         (save-restriction
8064           (narrow-to-region (point-min) (point))
8065           (article-decode-encoded-words)
8066           (if  hidden
8067               (let ((gnus-treat-hide-headers nil)
8068                     (gnus-treat-hide-boring-headers nil))
8069                 (gnus-delete-wash-type 'headers)
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