* gnus-fun.el (gnus-convert-pbm-to-x-face-command): Doc fix.
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 (require 'nnoo)
40
41 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
42 (autoload 'gnus-cache-write-active "gnus-cache")
43 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
44 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
45 (autoload 'mm-uu-dissect "mm-uu")
46
47 (defcustom gnus-kill-summary-on-exit t
48   "*If non-nil, kill the summary buffer when you exit from it.
49 If nil, the summary will become a \"*Dead Summary*\" buffer, and
50 it will be killed sometime later."
51   :group 'gnus-summary-exit
52   :type 'boolean)
53
54 (defcustom gnus-fetch-old-headers nil
55   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
56 If an unread article in the group refers to an older, already read (or
57 just marked as read) article, the old article will not normally be
58 displayed in the Summary buffer.  If this variable is non-nil, Gnus
59 will attempt to grab the headers to the old articles, and thereby
60 build complete threads.  If it has the value `some', only enough
61 headers to connect otherwise loose threads will be displayed.  This
62 variable can also be a number.  In that case, no more than that number
63 of old headers will be fetched.  If it has the value `invisible', all
64 old headers will be fetched, but none will be displayed.
65
66 The server has to support NOV for any of this to work."
67   :group 'gnus-thread
68   :type '(choice (const :tag "off" nil)
69                  (const some)
70                  number
71                  (sexp :menu-tag "other" t)))
72
73 (defcustom gnus-refer-thread-limit 200
74   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
75 If t, fetch all the available old headers."
76   :group 'gnus-thread
77   :type '(choice number
78                  (sexp :menu-tag "other" t)))
79
80 (defcustom gnus-summary-make-false-root 'adopt
81   "*nil means that Gnus won't gather loose threads.
82 If the root of a thread has expired or been read in a previous
83 session, the information necessary to build a complete thread has been
84 lost.  Instead of having many small sub-threads from this original thread
85 scattered all over the summary buffer, Gnus can gather them.
86
87 If non-nil, Gnus will try to gather all loose sub-threads from an
88 original thread into one large thread.
89
90 If this variable is non-nil, it should be one of `none', `adopt',
91 `dummy' or `empty'.
92
93 If this variable is `none', Gnus will not make a false root, but just
94 present the sub-threads after another.
95 If this variable is `dummy', Gnus will create a dummy root that will
96 have all the sub-threads as children.
97 If this variable is `adopt', Gnus will make one of the \"children\"
98 the parent and mark all the step-children as such.
99 If this variable is `empty', the \"children\" are printed with empty
100 subject fields.  (Or rather, they will be printed with a string
101 given by the `gnus-summary-same-subject' variable.)"
102   :group 'gnus-thread
103   :type '(choice (const :tag "off" nil)
104                  (const none)
105                  (const dummy)
106                  (const adopt)
107                  (const empty)))
108
109 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
110   "*A regexp to match subjects to be excluded from loose thread gathering.
111 As loose thread gathering is done on subjects only, that means that
112 there can be many false gatherings performed.  By rooting out certain
113 common subjects, gathering might become saner."
114   :group 'gnus-thread
115   :type 'regexp)
116
117 (defcustom gnus-summary-gather-subject-limit nil
118   "*Maximum length of subject comparisons when gathering loose threads.
119 Use nil to compare full subjects.  Setting this variable to a low
120 number will help gather threads that have been corrupted by
121 newsreaders chopping off subject lines, but it might also mean that
122 unrelated articles that have subject that happen to begin with the
123 same few characters will be incorrectly gathered.
124
125 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
126 comparing subjects."
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const fuzzy)
130                  (sexp :menu-tag "on" t)))
131
132 (defcustom gnus-simplify-subject-functions nil
133   "List of functions taking a string argument that simplify subjects.
134 The functions are applied recursively.
135
136 Useful functions to put in this list include: `gnus-simplify-subject-re',
137 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
138   :group 'gnus-thread
139   :type '(repeat function))
140
141 (defcustom gnus-simplify-ignored-prefixes nil
142   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
143   :group 'gnus-thread
144   :type '(choice (const :tag "off" nil)
145                  regexp))
146
147 (defcustom gnus-build-sparse-threads nil
148   "*If non-nil, fill in the gaps in threads.
149 If `some', only fill in the gaps that are needed to tie loose threads
150 together.  If `more', fill in all leaf nodes that Gnus can find.  If
151 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
152   :group 'gnus-thread
153   :type '(choice (const :tag "off" nil)
154                  (const some)
155                  (const more)
156                  (sexp :menu-tag "all" t)))
157
158 (defcustom gnus-summary-thread-gathering-function
159   'gnus-gather-threads-by-subject
160   "*Function used for gathering loose threads.
161 There are two pre-defined functions: `gnus-gather-threads-by-subject',
162 which only takes Subjects into consideration; and
163 `gnus-gather-threads-by-references', which compared the References
164 headers of the articles to find matches."
165   :group 'gnus-thread
166   :type '(radio (function-item gnus-gather-threads-by-subject)
167                 (function-item gnus-gather-threads-by-references)
168                 (function :tag "other")))
169
170 (defcustom gnus-summary-same-subject ""
171   "*String indicating that the current article has the same subject as the previous.
172 This variable will only be used if the value of
173 `gnus-summary-make-false-root' is `empty'."
174   :group 'gnus-summary-format
175   :type 'string)
176
177 (defcustom gnus-summary-goto-unread t
178   "*If t, many commands will go to the next unread article.
179 This applies to marking commands as well as other commands that
180 \"naturally\" select the next article, like, for instance, `SPC' at
181 the end of an article.
182
183 If nil, the marking commands do NOT go to the next unread article
184 (they go to the next article instead).  If `never', commands that
185 usually go to the next unread article, will go to the next article,
186 whether it is read or not."
187   :group 'gnus-summary-marks
188   :link '(custom-manual "(gnus)Setting Marks")
189   :type '(choice (const :tag "off" nil)
190                  (const never)
191                  (sexp :menu-tag "on" t)))
192
193 (defcustom gnus-summary-default-score 0
194   "*Default article score level.
195 All scores generated by the score files will be added to this score.
196 If this variable is nil, scoring will be disabled."
197   :group 'gnus-score-default
198   :type '(choice (const :tag "disable")
199                  integer))
200
201 (defcustom gnus-summary-default-high-score 0
202   "*Default threshold for a high scored article.
203 An article will be highlighted as high scored if its score is greater
204 than this score."
205   :group 'gnus-score-default
206   :type 'integer)
207
208 (defcustom gnus-summary-default-low-score 0
209   "*Default threshold for a low scored article.
210 An article will be highlighted as low scored if its score is smaller
211 than this score."
212   :group 'gnus-score-default
213   :type 'integer)
214
215 (defcustom gnus-summary-zcore-fuzz 0
216   "*Fuzziness factor for the zcore in the summary buffer.
217 Articles with scores closer than this to `gnus-summary-default-score'
218 will not be marked."
219   :group 'gnus-summary-format
220   :type 'integer)
221
222 (defcustom gnus-simplify-subject-fuzzy-regexp nil
223   "*Strings to be removed when doing fuzzy matches.
224 This can either be a regular expression or list of regular expressions
225 that will be removed from subject strings if fuzzy subject
226 simplification is selected."
227   :group 'gnus-thread
228   :type '(repeat regexp))
229
230 (defcustom gnus-show-threads t
231   "*If non-nil, display threads in summary mode."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-hide-subtree nil
236   "*If non-nil, hide all threads initially.
237 This can be a predicate specifier which says which threads to hide.
238 If threads are hidden, you have to run the command
239 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
240 to expose hidden threads."
241   :group 'gnus-thread
242   :type 'boolean)
243
244 (defcustom gnus-thread-hide-killed t
245   "*If non-nil, hide killed threads automatically."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-ignore-subject t
250   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
251 If nil, articles that have different subjects from their parents will
252 start separate threads."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-operation-ignore-subject t
257   "*If non-nil, subjects will be ignored when doing thread commands.
258 This affects commands like `gnus-summary-kill-thread' and
259 `gnus-summary-lower-thread'.
260
261 If this variable is nil, articles in the same thread with different
262 subjects will not be included in the operation in question.  If this
263 variable is `fuzzy', only articles that have subjects that are fuzzily
264 equal will be included."
265   :group 'gnus-thread
266   :type '(choice (const :tag "off" nil)
267                  (const fuzzy)
268                  (sexp :tag "on" t)))
269
270 (defcustom gnus-thread-indent-level 4
271   "*Number that says how much each sub-thread should be indented."
272   :group 'gnus-thread
273   :type 'integer)
274
275 (defcustom gnus-auto-extend-newsgroup t
276   "*If non-nil, extend newsgroup forward and backward when requested."
277   :group 'gnus-summary-choose
278   :type 'boolean)
279
280 (defcustom gnus-auto-select-first t
281   "*If non-nil, select the article under point.
282 Which article this is is controlled by the `gnus-auto-select-subject'
283 variable.
284
285 If you want to prevent automatic selection of articles in some
286 newsgroups, set the variable to nil in `gnus-select-group-hook'."
287   :group 'gnus-group-select
288   :type '(choice (const :tag "none" nil)
289                  (sexp :menu-tag "first" t)))
290
291 (defcustom gnus-auto-select-subject 'unread
292   "*Says what subject to place under point when entering a group.
293
294 This variable can either be the symbols `first' (place point on the
295 first subject), `unread' (place point on the subject line of the first
296 unread article), `best' (place point on the subject line of the
297 higest-scored article), `unseen' (place point on the subject line of
298 the first unseen article), or a function to be called to place point on
299 some subject line.."
300   :group 'gnus-group-select
301   :type '(choice (const best)
302                  (const unread)
303                  (const first)
304                  (const unseen)))
305
306 (defcustom gnus-auto-select-next t
307   "*If non-nil, offer to go to the next group from the end of the previous.
308 If the value is t and the next newsgroup is empty, Gnus will exit
309 summary mode and go back to group mode.  If the value is neither nil
310 nor t, Gnus will select the following unread newsgroup.  In
311 particular, if the value is the symbol `quietly', the next unread
312 newsgroup will be selected without any confirmation, and if it is
313 `almost-quietly', the next group will be selected without any
314 confirmation if you are located on the last article in the group.
315 Finally, if this variable is `slightly-quietly', the `Z n' command
316 will go to the next group without confirmation."
317   :group 'gnus-summary-maneuvering
318   :type '(choice (const :tag "off" nil)
319                  (const quietly)
320                  (const almost-quietly)
321                  (const slightly-quietly)
322                  (sexp :menu-tag "on" t)))
323
324 (defcustom gnus-auto-select-same nil
325   "*If non-nil, select the next article with the same subject.
326 If there are no more articles with the same subject, go to
327 the first unread article."
328   :group 'gnus-summary-maneuvering
329   :type 'boolean)
330
331 (defcustom gnus-summary-check-current nil
332   "*If non-nil, consider the current article when moving.
333 The \"unread\" movement commands will stay on the same line if the
334 current article is unread."
335   :group 'gnus-summary-maneuvering
336   :type 'boolean)
337
338 (defcustom gnus-auto-center-summary t
339   "*If non-nil, always center the current summary buffer.
340 In particular, if `vertical' do only vertical recentering.  If non-nil
341 and non-`vertical', do both horizontal and vertical recentering."
342   :group 'gnus-summary-maneuvering
343   :type '(choice (const :tag "none" nil)
344                  (const vertical)
345                  (integer :tag "height")
346                  (sexp :menu-tag "both" t)))
347
348 (defcustom gnus-show-all-headers nil
349   "*If non-nil, don't hide any headers."
350   :group 'gnus-article-hiding
351   :group 'gnus-article-headers
352   :type 'boolean)
353
354 (defcustom gnus-summary-ignore-duplicates nil
355   "*If non-nil, ignore articles with identical Message-ID headers."
356   :group 'gnus-summary
357   :type 'boolean)
358
359 (defcustom gnus-single-article-buffer t
360   "*If non-nil, display all articles in the same buffer.
361 If nil, each group will get its own article buffer."
362   :group 'gnus-article-various
363   :type 'boolean)
364
365 (defcustom gnus-break-pages t
366   "*If non-nil, do page breaking on articles.
367 The page delimiter is specified by the `gnus-page-delimiter'
368 variable."
369   :group 'gnus-article-various
370   :type 'boolean)
371
372 (defcustom gnus-move-split-methods nil
373   "*Variable used to suggest where articles are to be moved to.
374 It uses the same syntax as the `gnus-split-methods' variable.
375 However, whereas `gnus-split-methods' specifies file names as targets,
376 this variable specifies group names."
377   :group 'gnus-summary-mail
378   :type '(repeat (choice (list :value (fun) function)
379                          (cons :value ("" "") regexp (repeat string))
380                          (sexp :value nil))))
381
382 (defcustom gnus-unread-mark ?           ;Whitespace
383   "*Mark used for unread articles."
384   :group 'gnus-summary-marks
385   :type 'character)
386
387 (defcustom gnus-ticked-mark ?!
388   "*Mark used for ticked articles."
389   :group 'gnus-summary-marks
390   :type 'character)
391
392 (defcustom gnus-dormant-mark ??
393   "*Mark used for dormant articles."
394   :group 'gnus-summary-marks
395   :type 'character)
396
397 (defcustom gnus-del-mark ?r
398   "*Mark used for del'd articles."
399   :group 'gnus-summary-marks
400   :type 'character)
401
402 (defcustom gnus-read-mark ?R
403   "*Mark used for read articles."
404   :group 'gnus-summary-marks
405   :type 'character)
406
407 (defcustom gnus-expirable-mark ?E
408   "*Mark used for expirable articles."
409   :group 'gnus-summary-marks
410   :type 'character)
411
412 (defcustom gnus-killed-mark ?K
413   "*Mark used for killed articles."
414   :group 'gnus-summary-marks
415   :type 'character)
416
417 (defcustom gnus-souped-mark ?F
418   "*Mark used for souped articles."
419   :group 'gnus-summary-marks
420   :type 'character)
421
422 (defcustom gnus-kill-file-mark ?X
423   "*Mark used for articles killed by kill files."
424   :group 'gnus-summary-marks
425   :type 'character)
426
427 (defcustom gnus-low-score-mark ?Y
428   "*Mark used for articles with a low score."
429   :group 'gnus-summary-marks
430   :type 'character)
431
432 (defcustom gnus-catchup-mark ?C
433   "*Mark used for articles that are caught up."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-replied-mark ?A
438   "*Mark used for articles that have been replied to."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-forwarded-mark ?F
443   "*Mark used for articles that have been forwarded."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-recent-mark ?N
448   "*Mark used for articles that are recent."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-cached-mark ?*
453   "*Mark used for articles that are in the cache."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-saved-mark ?S
458   "*Mark used for articles that have been saved."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-unseen-mark ?.
463   "*Mark used for articles that haven't been seen."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-no-mark ?               ;Whitespace
468   "*Mark used for articles that have no other secondary mark."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-ancient-mark ?O
473   "*Mark used for ancient articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-sparse-mark ?Q
478   "*Mark used for sparsely reffed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-canceled-mark ?G
483   "*Mark used for canceled articles."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-duplicate-mark ?M
488   "*Mark used for duplicate articles."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-undownloaded-mark ?@
493   "*Mark used for articles that weren't downloaded."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-downloadable-mark ?%
498   "*Mark used for articles that are to be downloaded."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-unsendable-mark ?=
503   "*Mark used for articles that won't be sent."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-score-over-mark ?+
508   "*Score mark used for articles with high scores."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-score-below-mark ?-
513   "*Score mark used for articles with low scores."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-empty-thread-mark ?     ;Whitespace
518   "*There is no thread under the article."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-not-empty-thread-mark ?=
523   "*There is a thread under the article."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-view-pseudo-asynchronously nil
528   "*If non-nil, Gnus will view pseudo-articles asynchronously."
529   :group 'gnus-extract-view
530   :type 'boolean)
531
532 (defcustom gnus-auto-expirable-marks
533   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
534         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
535         gnus-souped-mark gnus-duplicate-mark)
536   "*The list of marks converted into expiration if a group is auto-expirable."
537   :version "21.1"
538   :group 'gnus-summary
539   :type '(repeat character))
540
541 (defcustom gnus-inhibit-user-auto-expire t
542   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
543   :version "21.1"
544   :group 'gnus-summary
545   :type 'boolean)
546
547 (defcustom gnus-view-pseudos nil
548   "*If `automatic', pseudo-articles will be viewed automatically.
549 If `not-confirm', pseudos will be viewed automatically, and the user
550 will not be asked to confirm the command."
551   :group 'gnus-extract-view
552   :type '(choice (const :tag "off" nil)
553                  (const automatic)
554                  (const not-confirm)))
555
556 (defcustom gnus-view-pseudos-separately t
557   "*If non-nil, one pseudo-article will be created for each file to be viewed.
558 If nil, all files that use the same viewing command will be given as a
559 list of parameters to that command."
560   :group 'gnus-extract-view
561   :type 'boolean)
562
563 (defcustom gnus-insert-pseudo-articles t
564   "*If non-nil, insert pseudo-articles when decoding articles."
565   :group 'gnus-extract-view
566   :type 'boolean)
567
568 (defcustom gnus-summary-dummy-line-format
569   "  %(:                          :%) %S\n"
570   "*The format specification for the dummy roots in the summary buffer.
571 It works along the same lines as a normal formatting string,
572 with some simple extensions.
573
574 %S  The subject
575
576 General format specifiers can also be used.  See
577 (gnus)Formatting Variables."
578   :group 'gnus-threading
579   :type 'string)
580
581 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
582   "*The format specification for the summary mode line.
583 It works along the same lines as a normal formatting string,
584 with some simple extensions:
585
586 %G  Group name
587 %p  Unprefixed group name
588 %A  Current article number
589 %z  Current article score
590 %V  Gnus version
591 %U  Number of unread articles in the group
592 %e  Number of unselected articles in the group
593 %Z  A string with unread/unselected article counts
594 %g  Shortish group name
595 %S  Subject of the current article
596 %u  User-defined spec
597 %s  Current score file name
598 %d  Number of dormant articles
599 %r  Number of articles that have been marked as read in this session
600 %E  Number of articles expunged by the score files"
601   :group 'gnus-summary-format
602   :type 'string)
603
604 (defcustom gnus-list-identifiers nil
605   "Regexp that matches list identifiers to be removed from subject.
606 This can also be a list of regexps."
607   :version "21.1"
608   :group 'gnus-summary-format
609   :group 'gnus-article-hiding
610   :type '(choice (const :tag "none" nil)
611                  (regexp :value ".*")
612                  (repeat :value (".*") regexp)))
613
614 (defcustom gnus-summary-mark-below 0
615   "*Mark all articles with a score below this variable as read.
616 This variable is local to each summary buffer and usually set by the
617 score file."
618   :group 'gnus-score-default
619   :type 'integer)
620
621 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
622   "*List of functions used for sorting articles in the summary buffer.
623
624 Each function takes two articles and returns non-nil if the first
625 article should be sorted before the other.  If you use more than one
626 function, the primary sort function should be the last.  You should
627 probably always include `gnus-article-sort-by-number' in the list of
628 sorting functions -- preferably first.  Also note that sorting by date
629 is often much slower than sorting by number, and the sorting order is
630 very similar.  (Sorting by date means sorting by the time the message
631 was sent, sorting by number means sorting by arrival time.)
632
633 Ready-made functions include `gnus-article-sort-by-number',
634 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
635 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
636
637 When threading is turned on, the variable `gnus-thread-sort-functions'
638 controls how articles are sorted."
639   :group 'gnus-summary-sort
640   :type '(repeat (choice (function-item gnus-article-sort-by-number)
641                          (function-item gnus-article-sort-by-author)
642                          (function-item gnus-article-sort-by-subject)
643                          (function-item gnus-article-sort-by-date)
644                          (function-item gnus-article-sort-by-score)
645                          (function :tag "other"))))
646
647 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
648   "*List of functions used for sorting threads in the summary buffer.
649 By default, threads are sorted by article number.
650
651 Each function takes two threads and returns non-nil if the first
652 thread should be sorted before the other.  If you use more than one
653 function, the primary sort function should be the last.  You should
654 probably always include `gnus-thread-sort-by-number' in the list of
655 sorting functions -- preferably first.  Also note that sorting by date
656 is often much slower than sorting by number, and the sorting order is
657 very similar.  (Sorting by date means sorting by the time the message
658 was sent, sorting by number means sorting by arrival time.)
659
660 Ready-made functions include `gnus-thread-sort-by-number',
661 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
662 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
663 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
664
665 When threading is turned off, the variable
666 `gnus-article-sort-functions' controls how articles are sorted."
667   :group 'gnus-summary-sort
668   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
669                          (function-item gnus-thread-sort-by-author)
670                          (function-item gnus-thread-sort-by-subject)
671                          (function-item gnus-thread-sort-by-date)
672                          (function-item gnus-thread-sort-by-score)
673                          (function-item gnus-thread-sort-by-total-score)
674                          (function :tag "other"))))
675
676 (defcustom gnus-thread-score-function '+
677   "*Function used for calculating the total score of a thread.
678
679 The function is called with the scores of the article and each
680 subthread and should then return the score of the thread.
681
682 Some functions you can use are `+', `max', or `min'."
683   :group 'gnus-summary-sort
684   :type 'function)
685
686 (defcustom gnus-summary-expunge-below nil
687   "All articles that have a score less than this variable will be expunged.
688 This variable is local to the summary buffers."
689   :group 'gnus-score-default
690   :type '(choice (const :tag "off" nil)
691                  integer))
692
693 (defcustom gnus-thread-expunge-below nil
694   "All threads that have a total score less than this variable will be expunged.
695 See `gnus-thread-score-function' for en explanation of what a
696 \"thread score\" is.
697
698 This variable is local to the summary buffers."
699   :group 'gnus-threading
700   :group 'gnus-score-default
701   :type '(choice (const :tag "off" nil)
702                  integer))
703
704 (defcustom gnus-summary-mode-hook nil
705   "*A hook for Gnus summary mode.
706 This hook is run before any variables are set in the summary buffer."
707   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
708   :group 'gnus-summary-various
709   :type 'hook)
710
711 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
712 (when (featurep 'xemacs)
713   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
714   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
715   (add-hook 'gnus-summary-mode-hook
716             'gnus-xmas-switch-horizontal-scrollbar-off))
717
718 (defcustom gnus-summary-menu-hook nil
719   "*Hook run after the creation of the summary mode menu."
720   :group 'gnus-summary-visual
721   :type 'hook)
722
723 (defcustom gnus-summary-exit-hook nil
724   "*A hook called on exit from the summary buffer.
725 It will be called with point in the group buffer."
726   :group 'gnus-summary-exit
727   :type 'hook)
728
729 (defcustom gnus-summary-prepare-hook nil
730   "*A hook called after the summary buffer has been generated.
731 If you want to modify the summary buffer, you can use this hook."
732   :group 'gnus-summary-various
733   :type 'hook)
734
735 (defcustom gnus-summary-prepared-hook nil
736   "*A hook called as the last thing after the summary buffer has been generated."
737   :group 'gnus-summary-various
738   :type 'hook)
739
740 (defcustom gnus-summary-generate-hook nil
741   "*A hook run just before generating the summary buffer.
742 This hook is commonly used to customize threading variables and the
743 like."
744   :group 'gnus-summary-various
745   :type 'hook)
746
747 (defcustom gnus-select-group-hook nil
748   "*A hook called when a newsgroup is selected.
749
750 If you'd like to simplify subjects like the
751 `gnus-summary-next-same-subject' command does, you can use the
752 following hook:
753
754  (setq gnus-select-group-hook
755       (list
756         (lambda ()
757           (mapcar (lambda (header)
758                      (mail-header-set-subject
759                       header
760                       (gnus-simplify-subject
761                        (mail-header-subject header) 're-only)))
762                   gnus-newsgroup-headers))))"
763   :group 'gnus-group-select
764   :type 'hook)
765
766 (defcustom gnus-select-article-hook nil
767   "*A hook called when an article is selected."
768   :group 'gnus-summary-choose
769   :type 'hook)
770
771 (defcustom gnus-visual-mark-article-hook
772   (list 'gnus-highlight-selected-summary)
773   "*Hook run after selecting an article in the summary buffer.
774 It is meant to be used for highlighting the article in some way.  It
775 is not run if `gnus-visual' is nil."
776   :group 'gnus-summary-visual
777   :type 'hook)
778
779 (defcustom gnus-parse-headers-hook nil
780   "*A hook called before parsing the headers."
781   :group 'gnus-various
782   :type 'hook)
783
784 (defcustom gnus-exit-group-hook nil
785   "*A hook called when exiting summary mode.
786 This hook is not called from the non-updating exit commands like `Q'."
787   :group 'gnus-various
788   :type 'hook)
789
790 (defcustom gnus-summary-update-hook
791   (list 'gnus-summary-highlight-line)
792   "*A hook called when a summary line is changed.
793 The hook will not be called if `gnus-visual' is nil.
794
795 The default function `gnus-summary-highlight-line' will
796 highlight the line according to the `gnus-summary-highlight'
797 variable."
798   :group 'gnus-summary-visual
799   :type 'hook)
800
801 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
802   "*A hook called when an article is selected for the first time.
803 The hook is intended to mark an article as read (or unread)
804 automatically when it is selected."
805   :group 'gnus-summary-choose
806   :type 'hook)
807
808 (defcustom gnus-group-no-more-groups-hook nil
809   "*A hook run when returning to group mode having no more (unread) groups."
810   :group 'gnus-group-select
811   :type 'hook)
812
813 (defcustom gnus-ps-print-hook nil
814   "*A hook run before ps-printing something from Gnus."
815   :group 'gnus-summary
816   :type 'hook)
817
818 (defcustom gnus-summary-display-arrow
819   (and (fboundp 'display-graphic-p)
820        (display-graphic-p))
821   "*If non-nil, display an arrow highlighting the current article."
822   :version "21.1"
823   :group 'gnus-summary
824   :type 'boolean)
825
826 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
827   "Face used for highlighting the current article in the summary buffer."
828   :group 'gnus-summary-visual
829   :type 'face)
830
831 (defcustom gnus-summary-highlight
832   '(((= mark gnus-canceled-mark)
833      . gnus-summary-cancelled-face)
834     ((and (> score default-high)
835           (or (= mark gnus-dormant-mark)
836               (= mark gnus-ticked-mark)))
837      . gnus-summary-high-ticked-face)
838     ((and (< score default-low)
839           (or (= mark gnus-dormant-mark)
840               (= mark gnus-ticked-mark)))
841      . gnus-summary-low-ticked-face)
842     ((or (= mark gnus-dormant-mark)
843          (= mark gnus-ticked-mark))
844      . gnus-summary-normal-ticked-face)
845     ((and (> score default-high) (= mark gnus-ancient-mark))
846      . gnus-summary-high-ancient-face)
847     ((and (< score default-low) (= mark gnus-ancient-mark))
848      . gnus-summary-low-ancient-face)
849     ((= mark gnus-ancient-mark)
850      . gnus-summary-normal-ancient-face)
851     ((and (> score default-high) (= mark gnus-unread-mark))
852      . gnus-summary-high-unread-face)
853     ((and (< score default-low) (= mark gnus-unread-mark))
854      . gnus-summary-low-unread-face)
855     ((= mark gnus-unread-mark)
856      . gnus-summary-normal-unread-face)
857     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
858                                                   gnus-undownloaded-mark)))
859      . gnus-summary-high-unread-face)
860     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
861                                                  gnus-undownloaded-mark)))
862      . gnus-summary-low-unread-face)
863     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
864           (memq article gnus-newsgroup-unreads))
865      . gnus-summary-normal-unread-face)
866     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
867      . gnus-summary-normal-read-face)
868     ((> score default-high)
869      . gnus-summary-high-read-face)
870     ((< score default-low)
871      . gnus-summary-low-read-face)
872     (t
873      . gnus-summary-normal-read-face))
874   "*Controls the highlighting of summary buffer lines.
875
876 A list of (FORM . FACE) pairs.  When deciding how a a particular
877 summary line should be displayed, each form is evaluated.  The content
878 of the face field after the first true form is used.  You can change
879 how those summary lines are displayed, by editing the face field.
880
881 You can use the following variables in the FORM field.
882
883 score:        The article's score
884 default:      The default article score.
885 default-high: The default score for high scored articles.
886 default-low:  The default score for low scored articles.
887 below:        The score below which articles are automatically marked as read.
888 mark:         The articles mark."
889   :group 'gnus-summary-visual
890   :type '(repeat (cons (sexp :tag "Form" nil)
891                        face)))
892
893 (defcustom gnus-alter-header-function nil
894   "Function called to allow alteration of article header structures.
895 The function is called with one parameter, the article header vector,
896 which it may alter in any way.")
897
898 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
899   "Variable that says which function should be used to decode a string with encoded words.")
900
901 (defcustom gnus-extra-headers '(To Newsgroups)
902   "*Extra headers to parse."
903   :version "21.1"
904   :group 'gnus-summary
905   :type '(repeat symbol))
906
907 (defcustom gnus-ignored-from-addresses
908   (and user-mail-address (regexp-quote user-mail-address))
909   "*Regexp of From headers that may be suppressed in favor of To headers."
910   :version "21.1"
911   :group 'gnus-summary
912   :type 'regexp)
913
914 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
915   "List of charsets that should be ignored.
916 When these charsets are used in the \"charset\" parameter, the
917 default charset will be used instead."
918   :version "21.1"
919   :type '(repeat symbol)
920   :group 'gnus-charset)
921
922 (gnus-define-group-parameter
923  ignored-charsets
924  :type list
925  :function-document
926  "Return the ignored charsets of GROUP."
927  :variable gnus-group-ignored-charsets-alist
928  :variable-default
929  '(("alt\\.chinese\\.text" iso-8859-1))
930  :variable-document
931  "Alist of regexps (to match group names) and charsets that should be ignored.
932 When these charsets are used in the \"charset\" parameter, the
933 default charset will be used instead."
934  :variable-group gnus-charset
935  :variable-type '(repeat (cons (regexp :tag "Group")
936                                (repeat symbol)))
937  :parameter-type '(choice :tag "Ignored charsets"
938                           :value nil
939                           (repeat (symbol)))
940  :parameter-document       "\
941 List of charsets that should be ignored.
942
943 When these charsets are used in the \"charset\" parameter, the
944 default charset will be used instead.")
945
946 (defcustom gnus-group-highlight-words-alist nil
947   "Alist of group regexps and highlight regexps.
948 This variable uses the same syntax as `gnus-emphasis-alist'."
949   :version "21.1"
950   :type '(repeat (cons (regexp :tag "Group")
951                        (repeat (list (regexp :tag "Highlight regexp")
952                                      (number :tag "Group for entire word" 0)
953                                      (number :tag "Group for displayed part" 0)
954                                      (symbol :tag "Face"
955                                              gnus-emphasis-highlight-words)))))
956   :group 'gnus-summary-visual)
957
958 (defcustom gnus-summary-show-article-charset-alist
959   nil
960   "Alist of number and charset.
961 The article will be shown with the charset corresponding to the
962 numbered argument.
963 For example: ((1 . cn-gb-2312) (2 . big5))."
964   :version "21.1"
965   :type '(repeat (cons (number :tag "Argument" 1)
966                        (symbol :tag "Charset")))
967   :group 'gnus-charset)
968
969 (defcustom gnus-preserve-marks t
970   "Whether marks are preserved when moving, copying and respooling messages."
971   :version "21.1"
972   :type 'boolean
973   :group 'gnus-summary-marks)
974
975 (defcustom gnus-alter-articles-to-read-function nil
976   "Function to be called to alter the list of articles to be selected."
977   :type '(choice (const nil) function)
978   :group 'gnus-summary)
979
980 (defcustom gnus-orphan-score nil
981   "*All orphans get this score added.  Set in the score file."
982   :group 'gnus-score-default
983   :type '(choice (const nil)
984                  integer))
985
986 (defcustom gnus-summary-save-parts-default-mime "image/.*"
987   "*A regexp to match MIME parts when saving multiple parts of a message
988 with gnus-summary-save-parts (X m). This regexp will be used by default
989 when prompting the user for which type of files to save."
990   :group 'gnus-summary
991   :type 'regexp)
992
993
994 (defcustom gnus-summary-save-parts-default-mime "image/.*"
995   "*A regexp to match MIME parts when saving multiple parts of a message
996 with gnus-summary-save-parts (X m). This regexp will be used by default
997 when prompting the user for which type of files to save."
998   :group 'gnus-summary
999   :type 'regexp)
1000
1001 (defcustom gnus-read-all-available-headers nil
1002   "Whether Gnus should parse all headers made available to it.
1003 This is mostly relevant for slow backends where the user may
1004 wish to widen the summary buffer to include all headers
1005 that were fetched.  Say, for nnultimate groups."
1006   :group 'gnus-summary
1007   :type '(choice boolean regexp))
1008
1009 (defcustom gnus-summary-muttprint-program "muttprint"
1010   "Command (and optional arguments) used to run Muttprint."
1011   :group 'gnus-summary
1012   :type 'string)
1013
1014 ;;; Internal variables
1015
1016 (defvar gnus-summary-display-cache nil)
1017 (defvar gnus-article-mime-handles nil)
1018 (defvar gnus-article-decoded-p nil)
1019 (defvar gnus-article-charset nil)
1020 (defvar gnus-article-ignored-charsets nil)
1021 (defvar gnus-scores-exclude-files nil)
1022 (defvar gnus-page-broken nil)
1023 (defvar gnus-inhibit-mime-unbuttonizing nil)
1024
1025 (defvar gnus-original-article nil)
1026 (defvar gnus-article-internal-prepare-hook nil)
1027 (defvar gnus-newsgroup-process-stack nil)
1028
1029 (defvar gnus-thread-indent-array nil)
1030 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1031 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1032   "Function called to sort the articles within a thread after it has been gathered together.")
1033
1034 (defvar gnus-summary-save-parts-type-history nil)
1035 (defvar gnus-summary-save-parts-last-directory nil)
1036
1037 (defvar gnus-summary-save-parts-type-history nil)
1038 (defvar gnus-summary-save-parts-last-directory nil)
1039
1040 ;; Avoid highlighting in kill files.
1041 (defvar gnus-summary-inhibit-highlight nil)
1042 (defvar gnus-newsgroup-selected-overlay nil)
1043 (defvar gnus-inhibit-limiting nil)
1044 (defvar gnus-newsgroup-adaptive-score-file nil)
1045 (defvar gnus-current-score-file nil)
1046 (defvar gnus-current-move-group nil)
1047 (defvar gnus-current-copy-group nil)
1048 (defvar gnus-current-crosspost-group nil)
1049 (defvar gnus-newsgroup-display nil)
1050
1051 (defvar gnus-newsgroup-dependencies nil)
1052 (defvar gnus-newsgroup-adaptive nil)
1053 (defvar gnus-summary-display-article-function nil)
1054 (defvar gnus-summary-highlight-line-function nil
1055   "Function called after highlighting a summary line.")
1056
1057 (defvar gnus-summary-line-format-alist
1058   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1059     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1060     (?s gnus-tmp-subject-or-nil ?s)
1061     (?n gnus-tmp-name ?s)
1062     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1063         ?s)
1064     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1065             gnus-tmp-from) ?s)
1066     (?F gnus-tmp-from ?s)
1067     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1068     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1069     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1070     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1071     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1072     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1073     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1074     (?L gnus-tmp-lines ?s)
1075     (?I gnus-tmp-indentation ?s)
1076     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1077     (?R gnus-tmp-replied ?c)
1078     (?\[ gnus-tmp-opening-bracket ?c)
1079     (?\] gnus-tmp-closing-bracket ?c)
1080     (?\> (make-string gnus-tmp-level ? ) ?s)
1081     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1082     (?i gnus-tmp-score ?d)
1083     (?z gnus-tmp-score-char ?c)
1084     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1085     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1086     (?U gnus-tmp-unread ?c)
1087     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1088         ?s)
1089     (?t (gnus-summary-number-of-articles-in-thread
1090          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1091         ?d)
1092     (?e (gnus-summary-number-of-articles-in-thread
1093          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1094         ?c)
1095     (?u gnus-tmp-user-defined ?s)
1096     (?P (gnus-pick-line-number) ?d)
1097     (?B gnus-tmp-thread-tree-header-string ?s)
1098     (user-date (gnus-user-date
1099                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1100   "An alist of format specifications that can appear in summary lines.
1101 These are paired with what variables they correspond with, along with
1102 the type of the variable (string, integer, character, etc).")
1103
1104 (defvar gnus-summary-dummy-line-format-alist
1105   `((?S gnus-tmp-subject ?s)
1106     (?N gnus-tmp-number ?d)
1107     (?u gnus-tmp-user-defined ?s)))
1108
1109 (defvar gnus-summary-mode-line-format-alist
1110   `((?G gnus-tmp-group-name ?s)
1111     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1112     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1113     (?A gnus-tmp-article-number ?d)
1114     (?Z gnus-tmp-unread-and-unselected ?s)
1115     (?V gnus-version ?s)
1116     (?U gnus-tmp-unread-and-unticked ?d)
1117     (?S gnus-tmp-subject ?s)
1118     (?e gnus-tmp-unselected ?d)
1119     (?u gnus-tmp-user-defined ?s)
1120     (?d (length gnus-newsgroup-dormant) ?d)
1121     (?t (length gnus-newsgroup-marked) ?d)
1122     (?r (length gnus-newsgroup-reads) ?d)
1123     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1124     (?E gnus-newsgroup-expunged-tally ?d)
1125     (?s (gnus-current-score-file-nondirectory) ?s)))
1126
1127 (defvar gnus-last-search-regexp nil
1128   "Default regexp for article search command.")
1129
1130 (defvar gnus-last-shell-command nil
1131   "Default shell command on article.")
1132
1133 (defvar gnus-newsgroup-begin nil)
1134 (defvar gnus-newsgroup-end nil)
1135 (defvar gnus-newsgroup-last-rmail nil)
1136 (defvar gnus-newsgroup-last-mail nil)
1137 (defvar gnus-newsgroup-last-folder nil)
1138 (defvar gnus-newsgroup-last-file nil)
1139 (defvar gnus-newsgroup-auto-expire nil)
1140 (defvar gnus-newsgroup-active nil)
1141
1142 (defvar gnus-newsgroup-data nil)
1143 (defvar gnus-newsgroup-data-reverse nil)
1144 (defvar gnus-newsgroup-limit nil)
1145 (defvar gnus-newsgroup-limits nil)
1146
1147 (defvar gnus-newsgroup-unreads nil
1148   "List of unread articles in the current newsgroup.")
1149
1150 (defvar gnus-newsgroup-unselected nil
1151   "List of unselected unread articles in the current newsgroup.")
1152
1153 (defvar gnus-newsgroup-reads nil
1154   "Alist of read articles and article marks in the current newsgroup.")
1155
1156 (defvar gnus-newsgroup-expunged-tally nil)
1157
1158 (defvar gnus-newsgroup-marked nil
1159   "List of ticked articles in the current newsgroup (a subset of unread art).")
1160
1161 (defvar gnus-newsgroup-killed nil
1162   "List of ranges of articles that have been through the scoring process.")
1163
1164 (defvar gnus-newsgroup-cached nil
1165   "List of articles that come from the article cache.")
1166
1167 (defvar gnus-newsgroup-saved nil
1168   "List of articles that have been saved.")
1169
1170 (defvar gnus-newsgroup-kill-headers nil)
1171
1172 (defvar gnus-newsgroup-replied nil
1173   "List of articles that have been replied to in the current newsgroup.")
1174
1175 (defvar gnus-newsgroup-forwarded nil
1176   "List of articles that have been forwarded in the current newsgroup.")
1177
1178 (defvar gnus-newsgroup-recent nil
1179   "List of articles that have are recent in the current newsgroup.")
1180
1181 (defvar gnus-newsgroup-expirable nil
1182   "List of articles in the current newsgroup that can be expired.")
1183
1184 (defvar gnus-newsgroup-processable nil
1185   "List of articles in the current newsgroup that can be processed.")
1186
1187 (defvar gnus-newsgroup-downloadable nil
1188   "List of articles in the current newsgroup that can be processed.")
1189
1190 (defvar gnus-newsgroup-undownloaded nil
1191   "List of articles in the current newsgroup that haven't been downloaded..")
1192
1193 (defvar gnus-newsgroup-unsendable nil
1194   "List of articles in the current newsgroup that won't be sent.")
1195
1196 (defvar gnus-newsgroup-bookmarks nil
1197   "List of articles in the current newsgroup that have bookmarks.")
1198
1199 (defvar gnus-newsgroup-dormant nil
1200   "List of dormant articles in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-unseen nil
1203   "List of unseen articles in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-seen nil
1206   "Range of seen articles in the current newsgroup.")
1207
1208 (defvar gnus-newsgroup-articles nil
1209   "List of articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-scored nil
1212   "List of scored articles in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-headers nil
1215   "List of article headers in the current newsgroup.")
1216
1217 (defvar gnus-newsgroup-threads nil)
1218
1219 (defvar gnus-newsgroup-prepared nil
1220   "Whether the current group has been prepared properly.")
1221
1222 (defvar gnus-newsgroup-ancient nil
1223   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1224
1225 (defvar gnus-newsgroup-sparse nil)
1226
1227 (defvar gnus-current-article nil)
1228 (defvar gnus-article-current nil)
1229 (defvar gnus-current-headers nil)
1230 (defvar gnus-have-all-headers nil)
1231 (defvar gnus-last-article nil)
1232 (defvar gnus-newsgroup-history nil)
1233 (defvar gnus-newsgroup-charset nil)
1234 (defvar gnus-newsgroup-ephemeral-charset nil)
1235 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1236
1237 (defvar gnus-article-before-search nil)
1238
1239 (defconst gnus-summary-local-variables
1240   '(gnus-newsgroup-name
1241     gnus-newsgroup-begin gnus-newsgroup-end
1242     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1243     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1244     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1245     gnus-newsgroup-unselected gnus-newsgroup-marked
1246     gnus-newsgroup-reads gnus-newsgroup-saved
1247     gnus-newsgroup-replied gnus-newsgroup-forwarded
1248     gnus-newsgroup-recent
1249     gnus-newsgroup-expirable
1250     gnus-newsgroup-processable gnus-newsgroup-killed
1251     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1252     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1253     gnus-newsgroup-seen gnus-newsgroup-articles
1254     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1255     gnus-newsgroup-headers gnus-newsgroup-threads
1256     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1257     gnus-current-article gnus-current-headers gnus-have-all-headers
1258     gnus-last-article gnus-article-internal-prepare-hook
1259     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1260     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1261     gnus-thread-expunge-below
1262     gnus-score-alist gnus-current-score-file
1263     (gnus-summary-expunge-below . global)
1264     (gnus-summary-mark-below . global)
1265     (gnus-orphan-score . global)
1266     gnus-newsgroup-active gnus-scores-exclude-files
1267     gnus-newsgroup-history gnus-newsgroup-ancient
1268     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1269     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1270     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1271     (gnus-newsgroup-expunged-tally . 0)
1272     gnus-cache-removable-articles gnus-newsgroup-cached
1273     gnus-newsgroup-data gnus-newsgroup-data-reverse
1274     gnus-newsgroup-limit gnus-newsgroup-limits
1275     gnus-newsgroup-charset gnus-newsgroup-display)
1276   "Variables that are buffer-local to the summary buffers.")
1277
1278 (defvar gnus-newsgroup-variables nil
1279   "A list of variables that have separate values in different newsgroups.
1280 A list of newsgroup (summary buffer) local variables, or cons of
1281 variables and their default values (when the default values are not
1282 nil), that should be made global while the summary buffer is active.
1283 These variables can be used to set variables in the group parameters
1284 while still allowing them to affect operations done in other
1285 buffers. For example:
1286
1287 \(setq gnus-newsgroup-variables
1288      '(message-use-followup-to
1289        (gnus-visible-headers .
1290          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1291 ")
1292
1293 ;; Byte-compiler warning.
1294 (eval-when-compile (defvar gnus-article-mode-map))
1295
1296 ;; MIME stuff.
1297
1298 (defvar gnus-decode-encoded-word-methods
1299   '(mail-decode-encoded-word-string)
1300   "List of methods used to decode encoded words.
1301
1302 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1303 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1304 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1305 whose names match REGEXP.
1306
1307 For example:
1308 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1309  mail-decode-encoded-word-string
1310  (\"chinese\" . rfc1843-decode-string))")
1311
1312 (defvar gnus-decode-encoded-word-methods-cache nil)
1313
1314 (defun gnus-multi-decode-encoded-word-string (string)
1315   "Apply the functions from `gnus-encoded-word-methods' that match."
1316   (unless (and gnus-decode-encoded-word-methods-cache
1317                (eq gnus-newsgroup-name
1318                    (car gnus-decode-encoded-word-methods-cache)))
1319     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1320     (mapcar (lambda (x)
1321               (if (symbolp x)
1322                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1323                 (if (and gnus-newsgroup-name
1324                          (string-match (car x) gnus-newsgroup-name))
1325                     (nconc gnus-decode-encoded-word-methods-cache
1326                            (list (cdr x))))))
1327             gnus-decode-encoded-word-methods))
1328   (let ((xlist gnus-decode-encoded-word-methods-cache))
1329     (pop xlist)
1330     (while xlist
1331       (setq string (funcall (pop xlist) string))))
1332   string)
1333
1334 ;; Subject simplification.
1335
1336 (defun gnus-simplify-whitespace (str)
1337   "Remove excessive whitespace from STR."
1338   (let ((mystr str))
1339     ;; Multiple spaces.
1340     (while (string-match "[ \t][ \t]+" mystr)
1341       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1342                           " "
1343                           (substring mystr (match-end 0)))))
1344     ;; Leading spaces.
1345     (when (string-match "^[ \t]+" mystr)
1346       (setq mystr (substring mystr (match-end 0))))
1347     ;; Trailing spaces.
1348     (when (string-match "[ \t]+$" mystr)
1349       (setq mystr (substring mystr 0 (match-beginning 0))))
1350     mystr))
1351
1352 (defsubst gnus-simplify-subject-re (subject)
1353   "Remove \"Re:\" from subject lines."
1354   (if (string-match message-subject-re-regexp subject)
1355       (substring subject (match-end 0))
1356     subject))
1357
1358 (defun gnus-simplify-subject (subject &optional re-only)
1359   "Remove `Re:' and words in parentheses.
1360 If RE-ONLY is non-nil, strip leading `Re:'s only."
1361   (let ((case-fold-search t))           ;Ignore case.
1362     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1363     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1364       (setq subject (substring subject (match-end 0))))
1365     ;; Remove uninteresting prefixes.
1366     (when (and (not re-only)
1367                gnus-simplify-ignored-prefixes
1368                (string-match gnus-simplify-ignored-prefixes subject))
1369       (setq subject (substring subject (match-end 0))))
1370     ;; Remove words in parentheses from end.
1371     (unless re-only
1372       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1373         (setq subject (substring subject 0 (match-beginning 0)))))
1374     ;; Return subject string.
1375     subject))
1376
1377 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1378 ;; all whitespace.
1379 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1380   (goto-char (point-min))
1381   (while (re-search-forward regexp nil t)
1382     (replace-match (or newtext ""))))
1383
1384 (defun gnus-simplify-buffer-fuzzy ()
1385   "Simplify string in the buffer fuzzily.
1386 The string in the accessible portion of the current buffer is simplified.
1387 It is assumed to be a single-line subject.
1388 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1389 matter is removed.  Additional things can be deleted by setting
1390 `gnus-simplify-subject-fuzzy-regexp'."
1391   (let ((case-fold-search t)
1392         (modified-tick))
1393     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1394
1395     (while (not (eq modified-tick (buffer-modified-tick)))
1396       (setq modified-tick (buffer-modified-tick))
1397       (cond
1398        ((listp gnus-simplify-subject-fuzzy-regexp)
1399         (mapcar 'gnus-simplify-buffer-fuzzy-step
1400                 gnus-simplify-subject-fuzzy-regexp))
1401        (gnus-simplify-subject-fuzzy-regexp
1402         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1403       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1404       (gnus-simplify-buffer-fuzzy-step
1405        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1406       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1407
1408     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1409     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1410     (gnus-simplify-buffer-fuzzy-step " $")
1411     (gnus-simplify-buffer-fuzzy-step "^ +")))
1412
1413 (defun gnus-simplify-subject-fuzzy (subject)
1414   "Simplify a subject string fuzzily.
1415 See `gnus-simplify-buffer-fuzzy' for details."
1416   (save-excursion
1417     (gnus-set-work-buffer)
1418     (let ((case-fold-search t))
1419       ;; Remove uninteresting prefixes.
1420       (when (and gnus-simplify-ignored-prefixes
1421                  (string-match gnus-simplify-ignored-prefixes subject))
1422         (setq subject (substring subject (match-end 0))))
1423       (insert subject)
1424       (inline (gnus-simplify-buffer-fuzzy))
1425       (buffer-string))))
1426
1427 (defsubst gnus-simplify-subject-fully (subject)
1428   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1429   (cond
1430    (gnus-simplify-subject-functions
1431     (gnus-map-function gnus-simplify-subject-functions subject))
1432    ((null gnus-summary-gather-subject-limit)
1433     (gnus-simplify-subject-re subject))
1434    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1435     (gnus-simplify-subject-fuzzy subject))
1436    ((numberp gnus-summary-gather-subject-limit)
1437     (gnus-limit-string (gnus-simplify-subject-re subject)
1438                        gnus-summary-gather-subject-limit))
1439    (t
1440     subject)))
1441
1442 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1443   "Check whether two subjects are equal.
1444 If optional argument simple-first is t, first argument is already
1445 simplified."
1446   (cond
1447    ((null simple-first)
1448     (equal (gnus-simplify-subject-fully s1)
1449            (gnus-simplify-subject-fully s2)))
1450    (t
1451     (equal s1
1452            (gnus-simplify-subject-fully s2)))))
1453
1454 (defun gnus-summary-bubble-group ()
1455   "Increase the score of the current group.
1456 This is a handy function to add to `gnus-summary-exit-hook' to
1457 increase the score of each group you read."
1458   (gnus-group-add-score gnus-newsgroup-name))
1459
1460 \f
1461 ;;;
1462 ;;; Gnus summary mode
1463 ;;;
1464
1465 (put 'gnus-summary-mode 'mode-class 'special)
1466
1467 (defvar gnus-article-commands-menu)
1468
1469 (when t
1470   ;; Non-orthogonal keys
1471
1472   (gnus-define-keys gnus-summary-mode-map
1473     " " gnus-summary-next-page
1474     "\177" gnus-summary-prev-page
1475     [delete] gnus-summary-prev-page
1476     [backspace] gnus-summary-prev-page
1477     "\r" gnus-summary-scroll-up
1478     "\M-\r" gnus-summary-scroll-down
1479     "n" gnus-summary-next-unread-article
1480     "p" gnus-summary-prev-unread-article
1481     "N" gnus-summary-next-article
1482     "P" gnus-summary-prev-article
1483     "\M-\C-n" gnus-summary-next-same-subject
1484     "\M-\C-p" gnus-summary-prev-same-subject
1485     "\M-n" gnus-summary-next-unread-subject
1486     "\M-p" gnus-summary-prev-unread-subject
1487     "." gnus-summary-first-unread-article
1488     "," gnus-summary-best-unread-article
1489     "\M-s" gnus-summary-search-article-forward
1490     "\M-r" gnus-summary-search-article-backward
1491     "<" gnus-summary-beginning-of-article
1492     ">" gnus-summary-end-of-article
1493     "j" gnus-summary-goto-article
1494     "^" gnus-summary-refer-parent-article
1495     "\M-^" gnus-summary-refer-article
1496     "u" gnus-summary-tick-article-forward
1497     "!" gnus-summary-tick-article-forward
1498     "U" gnus-summary-tick-article-backward
1499     "d" gnus-summary-mark-as-read-forward
1500     "D" gnus-summary-mark-as-read-backward
1501     "E" gnus-summary-mark-as-expirable
1502     "\M-u" gnus-summary-clear-mark-forward
1503     "\M-U" gnus-summary-clear-mark-backward
1504     "k" gnus-summary-kill-same-subject-and-select
1505     "\C-k" gnus-summary-kill-same-subject
1506     "\M-\C-k" gnus-summary-kill-thread
1507     "\M-\C-l" gnus-summary-lower-thread
1508     "e" gnus-summary-edit-article
1509     "#" gnus-summary-mark-as-processable
1510     "\M-#" gnus-summary-unmark-as-processable
1511     "\M-\C-t" gnus-summary-toggle-threads
1512     "\M-\C-s" gnus-summary-show-thread
1513     "\M-\C-h" gnus-summary-hide-thread
1514     "\M-\C-f" gnus-summary-next-thread
1515     "\M-\C-b" gnus-summary-prev-thread
1516     [(meta down)] gnus-summary-next-thread
1517     [(meta up)] gnus-summary-prev-thread
1518     "\M-\C-u" gnus-summary-up-thread
1519     "\M-\C-d" gnus-summary-down-thread
1520     "&" gnus-summary-execute-command
1521     "c" gnus-summary-catchup-and-exit
1522     "\C-w" gnus-summary-mark-region-as-read
1523     "\C-t" gnus-summary-toggle-truncation
1524     "?" gnus-summary-mark-as-dormant
1525     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1526     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1527     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1528     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1529     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1530     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1531     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1532     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1533     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1534     "=" gnus-summary-expand-window
1535     "\C-x\C-s" gnus-summary-reselect-current-group
1536     "\M-g" gnus-summary-rescan-group
1537     "w" gnus-summary-stop-page-breaking
1538     "\C-c\C-r" gnus-summary-caesar-message
1539     "f" gnus-summary-followup
1540     "F" gnus-summary-followup-with-original
1541     "C" gnus-summary-cancel-article
1542     "r" gnus-summary-reply
1543     "R" gnus-summary-reply-with-original
1544     "\C-c\C-f" gnus-summary-mail-forward
1545     "o" gnus-summary-save-article
1546     "\C-o" gnus-summary-save-article-mail
1547     "|" gnus-summary-pipe-output
1548     "\M-k" gnus-summary-edit-local-kill
1549     "\M-K" gnus-summary-edit-global-kill
1550     ;; "V" gnus-version
1551     "\C-c\C-d" gnus-summary-describe-group
1552     "q" gnus-summary-exit
1553     "Q" gnus-summary-exit-no-update
1554     "\C-c\C-i" gnus-info-find-node
1555     gnus-mouse-2 gnus-mouse-pick-article
1556     "m" gnus-summary-mail-other-window
1557     "a" gnus-summary-post-news
1558     "i" gnus-summary-news-other-window
1559     "x" gnus-summary-limit-to-unread
1560     "s" gnus-summary-isearch-article
1561     "t" gnus-summary-toggle-header
1562     "g" gnus-summary-show-article
1563     "l" gnus-summary-goto-last-article
1564     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1565     "\C-d" gnus-summary-enter-digest-group
1566     "\M-\C-d" gnus-summary-read-document
1567     "\M-\C-e" gnus-summary-edit-parameters
1568     "\M-\C-a" gnus-summary-customize-parameters
1569     "\C-c\C-b" gnus-bug
1570     "*" gnus-cache-enter-article
1571     "\M-*" gnus-cache-remove-article
1572     "\M-&" gnus-summary-universal-argument
1573     "\C-l" gnus-recenter
1574     "I" gnus-summary-increase-score
1575     "L" gnus-summary-lower-score
1576     "\M-i" gnus-symbolic-argument
1577     "h" gnus-summary-select-article-buffer
1578
1579     "b" gnus-article-view-part
1580     "\M-t" gnus-summary-toggle-display-buttonized
1581
1582     "V" gnus-summary-score-map
1583     "X" gnus-uu-extract-map
1584     "S" gnus-summary-send-map)
1585
1586   ;; Sort of orthogonal keymap
1587   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1588     "t" gnus-summary-tick-article-forward
1589     "!" gnus-summary-tick-article-forward
1590     "d" gnus-summary-mark-as-read-forward
1591     "r" gnus-summary-mark-as-read-forward
1592     "c" gnus-summary-clear-mark-forward
1593     " " gnus-summary-clear-mark-forward
1594     "e" gnus-summary-mark-as-expirable
1595     "x" gnus-summary-mark-as-expirable
1596     "?" gnus-summary-mark-as-dormant
1597     "b" gnus-summary-set-bookmark
1598     "B" gnus-summary-remove-bookmark
1599     "#" gnus-summary-mark-as-processable
1600     "\M-#" gnus-summary-unmark-as-processable
1601     "S" gnus-summary-limit-include-expunged
1602     "C" gnus-summary-catchup
1603     "H" gnus-summary-catchup-to-here
1604     "h" gnus-summary-catchup-from-here
1605     "\C-c" gnus-summary-catchup-all
1606     "k" gnus-summary-kill-same-subject-and-select
1607     "K" gnus-summary-kill-same-subject
1608     "P" gnus-uu-mark-map)
1609
1610   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1611     "c" gnus-summary-clear-above
1612     "u" gnus-summary-tick-above
1613     "m" gnus-summary-mark-above
1614     "k" gnus-summary-kill-below)
1615
1616   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1617     "/" gnus-summary-limit-to-subject
1618     "n" gnus-summary-limit-to-articles
1619     "w" gnus-summary-pop-limit
1620     "s" gnus-summary-limit-to-subject
1621     "a" gnus-summary-limit-to-author
1622     "u" gnus-summary-limit-to-unread
1623     "m" gnus-summary-limit-to-marks
1624     "M" gnus-summary-limit-exclude-marks
1625     "v" gnus-summary-limit-to-score
1626     "*" gnus-summary-limit-include-cached
1627     "D" gnus-summary-limit-include-dormant
1628     "T" gnus-summary-limit-include-thread
1629     "d" gnus-summary-limit-exclude-dormant
1630     "t" gnus-summary-limit-to-age
1631     "x" gnus-summary-limit-to-extra
1632     "p" gnus-summary-limit-to-display-predicate
1633     "E" gnus-summary-limit-include-expunged
1634     "c" gnus-summary-limit-exclude-childless-dormant
1635     "C" gnus-summary-limit-mark-excluded-as-read
1636     "o" gnus-summary-insert-old-articles
1637     "N" gnus-summary-insert-new-articles)
1638
1639   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1640     "n" gnus-summary-next-unread-article
1641     "p" gnus-summary-prev-unread-article
1642     "N" gnus-summary-next-article
1643     "P" gnus-summary-prev-article
1644     "\C-n" gnus-summary-next-same-subject
1645     "\C-p" gnus-summary-prev-same-subject
1646     "\M-n" gnus-summary-next-unread-subject
1647     "\M-p" gnus-summary-prev-unread-subject
1648     "f" gnus-summary-first-unread-article
1649     "b" gnus-summary-best-unread-article
1650     "j" gnus-summary-goto-article
1651     "g" gnus-summary-goto-subject
1652     "l" gnus-summary-goto-last-article
1653     "o" gnus-summary-pop-article)
1654
1655   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1656     "k" gnus-summary-kill-thread
1657     "l" gnus-summary-lower-thread
1658     "i" gnus-summary-raise-thread
1659     "T" gnus-summary-toggle-threads
1660     "t" gnus-summary-rethread-current
1661     "^" gnus-summary-reparent-thread
1662     "s" gnus-summary-show-thread
1663     "S" gnus-summary-show-all-threads
1664     "h" gnus-summary-hide-thread
1665     "H" gnus-summary-hide-all-threads
1666     "n" gnus-summary-next-thread
1667     "p" gnus-summary-prev-thread
1668     "u" gnus-summary-up-thread
1669     "o" gnus-summary-top-thread
1670     "d" gnus-summary-down-thread
1671     "#" gnus-uu-mark-thread
1672     "\M-#" gnus-uu-unmark-thread)
1673
1674   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1675     "g" gnus-summary-prepare
1676     "c" gnus-summary-insert-cached-articles)
1677
1678   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1679     "c" gnus-summary-catchup-and-exit
1680     "C" gnus-summary-catchup-all-and-exit
1681     "E" gnus-summary-exit-no-update
1682     "Q" gnus-summary-exit
1683     "Z" gnus-summary-exit
1684     "n" gnus-summary-catchup-and-goto-next-group
1685     "R" gnus-summary-reselect-current-group
1686     "G" gnus-summary-rescan-group
1687     "N" gnus-summary-next-group
1688     "s" gnus-summary-save-newsrc
1689     "P" gnus-summary-prev-group)
1690
1691   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1692     " " gnus-summary-next-page
1693     "n" gnus-summary-next-page
1694     "\177" gnus-summary-prev-page
1695     [delete] gnus-summary-prev-page
1696     "p" gnus-summary-prev-page
1697     "\r" gnus-summary-scroll-up
1698     "\M-\r" gnus-summary-scroll-down
1699     "<" gnus-summary-beginning-of-article
1700     ">" gnus-summary-end-of-article
1701     "b" gnus-summary-beginning-of-article
1702     "e" gnus-summary-end-of-article
1703     "^" gnus-summary-refer-parent-article
1704     "r" gnus-summary-refer-parent-article
1705     "D" gnus-summary-enter-digest-group
1706     "R" gnus-summary-refer-references
1707     "T" gnus-summary-refer-thread
1708     "g" gnus-summary-show-article
1709     "s" gnus-summary-isearch-article
1710     "P" gnus-summary-print-article
1711     "M" gnus-mailing-list-insinuate
1712     "t" gnus-article-babel)
1713
1714   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1715     "b" gnus-article-add-buttons
1716     "B" gnus-article-add-buttons-to-head
1717     "o" gnus-article-treat-overstrike
1718     "e" gnus-article-emphasize
1719     "w" gnus-article-fill-cited-article
1720     "Q" gnus-article-fill-long-lines
1721     "C" gnus-article-capitalize-sentences
1722     "c" gnus-article-remove-cr
1723     "q" gnus-article-de-quoted-unreadable
1724     "6" gnus-article-de-base64-unreadable
1725     "Z" gnus-article-decode-HZ
1726     "h" gnus-article-wash-html
1727     "s" gnus-summary-force-verify-and-decrypt
1728     "f" gnus-article-display-x-face
1729     "l" gnus-summary-stop-page-breaking
1730     "r" gnus-summary-caesar-message
1731     "t" gnus-summary-toggle-header
1732     "g" gnus-treat-smiley
1733     "v" gnus-summary-verbose-headers
1734     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1735     "p" gnus-article-verify-x-pgp-sig
1736     "d" gnus-article-treat-dumbquotes)
1737
1738   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1739     "a" gnus-article-hide
1740     "h" gnus-article-hide-headers
1741     "b" gnus-article-hide-boring-headers
1742     "s" gnus-article-hide-signature
1743     "c" gnus-article-hide-citation
1744     "C" gnus-article-hide-citation-in-followups
1745     "l" gnus-article-hide-list-identifiers
1746     "p" gnus-article-hide-pgp
1747     "B" gnus-article-strip-banner
1748     "P" gnus-article-hide-pem
1749     "\C-c" gnus-article-hide-citation-maybe)
1750
1751   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1752     "a" gnus-article-highlight
1753     "h" gnus-article-highlight-headers
1754     "c" gnus-article-highlight-citation
1755     "s" gnus-article-highlight-signature)
1756
1757   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1758     "f" gnus-article-treat-fold-headers
1759     "u" gnus-article-treat-unfold-headers
1760     "n" gnus-article-treat-fold-newsgroups)
1761
1762   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1763     "x" gnus-article-display-x-face
1764     "s" gnus-treat-smiley
1765     "D" gnus-article-remove-images
1766     "f" gnus-treat-from-picon
1767     "m" gnus-treat-mail-picon
1768     "n" gnus-treat-newsgroups-picon)
1769
1770   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1771     "w" gnus-article-decode-mime-words
1772     "c" gnus-article-decode-charset
1773     "v" gnus-mime-view-all-parts
1774     "b" gnus-article-view-part)
1775
1776   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1777     "z" gnus-article-date-ut
1778     "u" gnus-article-date-ut
1779     "l" gnus-article-date-local
1780     "p" gnus-article-date-english
1781     "e" gnus-article-date-lapsed
1782     "o" gnus-article-date-original
1783     "i" gnus-article-date-iso8601
1784     "s" gnus-article-date-user)
1785
1786   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1787     "t" gnus-article-remove-trailing-blank-lines
1788     "l" gnus-article-strip-leading-blank-lines
1789     "m" gnus-article-strip-multiple-blank-lines
1790     "a" gnus-article-strip-blank-lines
1791     "A" gnus-article-strip-all-blank-lines
1792     "s" gnus-article-strip-leading-space
1793     "e" gnus-article-strip-trailing-space
1794     "w" gnus-article-remove-leading-whitespace)
1795
1796   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1797     "v" gnus-version
1798     "f" gnus-summary-fetch-faq
1799     "d" gnus-summary-describe-group
1800     "h" gnus-summary-describe-briefly
1801     "i" gnus-info-find-node)
1802
1803   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1804     "e" gnus-summary-expire-articles
1805     "\M-\C-e" gnus-summary-expire-articles-now
1806     "\177" gnus-summary-delete-article
1807     [delete] gnus-summary-delete-article
1808     [backspace] gnus-summary-delete-article
1809     "m" gnus-summary-move-article
1810     "r" gnus-summary-respool-article
1811     "w" gnus-summary-edit-article
1812     "c" gnus-summary-copy-article
1813     "B" gnus-summary-crosspost-article
1814     "q" gnus-summary-respool-query
1815     "t" gnus-summary-respool-trace
1816     "i" gnus-summary-import-article
1817     "I" gnus-summary-create-article
1818     "p" gnus-summary-article-posted-p)
1819
1820   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1821     "o" gnus-summary-save-article
1822     "m" gnus-summary-save-article-mail
1823     "F" gnus-summary-write-article-file
1824     "r" gnus-summary-save-article-rmail
1825     "f" gnus-summary-save-article-file
1826     "b" gnus-summary-save-article-body-file
1827     "h" gnus-summary-save-article-folder
1828     "v" gnus-summary-save-article-vm
1829     "p" gnus-summary-pipe-output
1830     "P" gnus-summary-muttprint
1831     "s" gnus-soup-add-article)
1832
1833   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1834     "b" gnus-summary-display-buttonized
1835     "m" gnus-summary-repair-multipart
1836     "v" gnus-article-view-part
1837     "o" gnus-article-save-part
1838     "c" gnus-article-copy-part
1839     "C" gnus-article-view-part-as-charset
1840     "e" gnus-article-externalize-part
1841     "E" gnus-article-encrypt-body
1842     "i" gnus-article-inline-part
1843     "|" gnus-article-pipe-part))
1844
1845 (defvar gnus-article-post-menu nil)
1846
1847 (defun gnus-summary-make-menu-bar ()
1848   (gnus-turn-off-edit-menu 'summary)
1849
1850   (unless (boundp 'gnus-summary-misc-menu)
1851
1852     (easy-menu-define
1853       gnus-summary-kill-menu gnus-summary-mode-map ""
1854       (cons
1855        "Score"
1856        (nconc
1857         (list
1858          ["Customize" gnus-score-customize t])
1859         (gnus-make-score-map 'increase)
1860         (gnus-make-score-map 'lower)
1861         '(("Mark"
1862            ["Kill below" gnus-summary-kill-below t]
1863            ["Mark above" gnus-summary-mark-above t]
1864            ["Tick above" gnus-summary-tick-above t]
1865            ["Clear above" gnus-summary-clear-above t])
1866           ["Current score" gnus-summary-current-score t]
1867           ["Set score" gnus-summary-set-score t]
1868           ["Switch current score file..." gnus-score-change-score-file t]
1869           ["Set mark below..." gnus-score-set-mark-below t]
1870           ["Set expunge below..." gnus-score-set-expunge-below t]
1871           ["Edit current score file" gnus-score-edit-current-scores t]
1872           ["Edit score file" gnus-score-edit-file t]
1873           ["Trace score" gnus-score-find-trace t]
1874           ["Find words" gnus-score-find-favourite-words t]
1875           ["Rescore buffer" gnus-summary-rescore t]
1876           ["Increase score..." gnus-summary-increase-score t]
1877           ["Lower score..." gnus-summary-lower-score t]))))
1878
1879     ;; Define both the Article menu in the summary buffer and the
1880     ;; equivalent Commands menu in the article buffer here for
1881     ;; consistency.
1882     (let ((innards
1883            `(("Hide"
1884               ["All" gnus-article-hide t]
1885               ["Headers" gnus-article-hide-headers t]
1886               ["Signature" gnus-article-hide-signature t]
1887               ["Citation" gnus-article-hide-citation t]
1888               ["List identifiers" gnus-article-hide-list-identifiers t]
1889               ["PGP" gnus-article-hide-pgp t]
1890               ["Banner" gnus-article-strip-banner t]
1891               ["Boring headers" gnus-article-hide-boring-headers t])
1892              ("Highlight"
1893               ["All" gnus-article-highlight t]
1894               ["Headers" gnus-article-highlight-headers t]
1895               ["Signature" gnus-article-highlight-signature t]
1896               ["Citation" gnus-article-highlight-citation t])
1897              ("MIME"
1898               ["Words" gnus-article-decode-mime-words t]
1899               ["Charset" gnus-article-decode-charset t]
1900               ["QP" gnus-article-de-quoted-unreadable t]
1901               ["Base64" gnus-article-de-base64-unreadable t]
1902               ["View all" gnus-mime-view-all-parts t]
1903               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1904               ["Encrypt body" gnus-article-encrypt-body t])
1905              ("Date"
1906               ["Local" gnus-article-date-local t]
1907               ["ISO8601" gnus-article-date-iso8601 t]
1908               ["UT" gnus-article-date-ut t]
1909               ["Original" gnus-article-date-original t]
1910               ["Lapsed" gnus-article-date-lapsed t]
1911               ["User-defined" gnus-article-date-user t])
1912              ("Display"
1913               ["Remove images" gnus-article-remove-images t]
1914               ["Toggle smiley" gnus-treat-smiley t]
1915               ["Show X-Face" gnus-article-display-x-face t]
1916               ["Show picons in From" gnus-treat-from-picon t]
1917               ["Show picons in mail headers" gnus-treat-mail-picon t]
1918               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1919              ("Washing"
1920               ("Remove Blanks"
1921                ["Leading" gnus-article-strip-leading-blank-lines t]
1922                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1923                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1924                ["All of the above" gnus-article-strip-blank-lines t]
1925                ["All" gnus-article-strip-all-blank-lines t]
1926                ["Leading space" gnus-article-strip-leading-space t]
1927                ["Trailing space" gnus-article-strip-trailing-space t]
1928                ["Leading space in headers"
1929                 gnus-article-remove-leading-whitespace t])
1930               ["Overstrike" gnus-article-treat-overstrike t]
1931               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1932               ["Emphasis" gnus-article-emphasize t]
1933               ["Word wrap" gnus-article-fill-cited-article t]
1934               ["Fill long lines" gnus-article-fill-long-lines t]
1935               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1936               ["CR" gnus-article-remove-cr t]
1937               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1938               ["Base64" gnus-article-de-base64-unreadable t]
1939               ["Rot 13" gnus-summary-caesar-message
1940                ,@(if (featurep 'xemacs) '(t)
1941                    '(:help "\"Caesar rotate\" article by 13"))]
1942               ["Unix pipe" gnus-summary-pipe-message t]
1943               ["Add buttons" gnus-article-add-buttons t]
1944               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1945               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1946               ["Verbose header" gnus-summary-verbose-headers t]
1947               ["Toggle header" gnus-summary-toggle-header t]
1948               ["Unfold headers" gnus-article-treat-unfold-headers t]
1949               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
1950               ["Html" gnus-article-wash-html t]
1951               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1952               ["HZ" gnus-article-decode-HZ t])
1953              ("Output"
1954               ["Save in default format" gnus-summary-save-article
1955                ,@(if (featurep 'xemacs) '(t)
1956                    '(:help "Save article using default method"))]
1957               ["Save in file" gnus-summary-save-article-file
1958                ,@(if (featurep 'xemacs) '(t)
1959                    '(:help "Save article in file"))]
1960               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1961               ["Save in MH folder" gnus-summary-save-article-folder t]
1962               ["Save in VM folder" gnus-summary-save-article-vm t]
1963               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1964               ["Save body in file" gnus-summary-save-article-body-file t]
1965               ["Pipe through a filter" gnus-summary-pipe-output t]
1966               ["Add to SOUP packet" gnus-soup-add-article t]
1967               ["Print with Muttprint" gnus-summary-muttprint t]
1968               ["Print" gnus-summary-print-article t])
1969              ("Backend"
1970               ["Respool article..." gnus-summary-respool-article t]
1971               ["Move article..." gnus-summary-move-article
1972                (gnus-check-backend-function
1973                 'request-move-article gnus-newsgroup-name)]
1974               ["Copy article..." gnus-summary-copy-article t]
1975               ["Crosspost article..." gnus-summary-crosspost-article
1976                (gnus-check-backend-function
1977                 'request-replace-article gnus-newsgroup-name)]
1978               ["Import file..." gnus-summary-import-article t]
1979               ["Create article..." gnus-summary-create-article t]
1980               ["Check if posted" gnus-summary-article-posted-p t]
1981               ["Edit article" gnus-summary-edit-article
1982                (not (gnus-group-read-only-p))]
1983               ["Delete article" gnus-summary-delete-article
1984                (gnus-check-backend-function
1985                 'request-expire-articles gnus-newsgroup-name)]
1986               ["Query respool" gnus-summary-respool-query t]
1987               ["Trace respool" gnus-summary-respool-trace t]
1988               ["Delete expirable articles" gnus-summary-expire-articles-now
1989                (gnus-check-backend-function
1990                 'request-expire-articles gnus-newsgroup-name)])
1991              ("Extract"
1992               ["Uudecode" gnus-uu-decode-uu
1993                ,@(if (featurep 'xemacs) '(t)
1994                    '(:help "Decode uuencoded article(s)"))]
1995               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1996               ["Unshar" gnus-uu-decode-unshar t]
1997               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1998               ["Save" gnus-uu-decode-save t]
1999               ["Binhex" gnus-uu-decode-binhex t]
2000               ["Postscript" gnus-uu-decode-postscript t])
2001              ("Cache"
2002               ["Enter article" gnus-cache-enter-article t]
2003               ["Remove article" gnus-cache-remove-article t])
2004              ["Translate" gnus-article-babel t]
2005              ["Select article buffer" gnus-summary-select-article-buffer t]
2006              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2007              ["Isearch article..." gnus-summary-isearch-article t]
2008              ["Beginning of the article" gnus-summary-beginning-of-article t]
2009              ["End of the article" gnus-summary-end-of-article t]
2010              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2011              ["Fetch referenced articles" gnus-summary-refer-references t]
2012              ["Fetch current thread" gnus-summary-refer-thread t]
2013              ["Fetch article with id..." gnus-summary-refer-article t]
2014              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2015              ["Redisplay" gnus-summary-show-article t]
2016              ["Raw article" gnus-summary-show-raw-article t])))
2017       (easy-menu-define
2018         gnus-summary-article-menu gnus-summary-mode-map ""
2019         (cons "Article" innards))
2020
2021       (if (not (keymapp gnus-summary-article-menu))
2022           (easy-menu-define
2023             gnus-article-commands-menu gnus-article-mode-map ""
2024             (cons "Commands" innards))
2025         ;; in Emacs, don't share menu.
2026         (setq gnus-article-commands-menu
2027               (copy-keymap gnus-summary-article-menu))
2028         (define-key gnus-article-mode-map [menu-bar commands]
2029           (cons "Commands" gnus-article-commands-menu))))
2030
2031     (easy-menu-define
2032       gnus-summary-thread-menu gnus-summary-mode-map ""
2033       '("Threads"
2034         ["Toggle threading" gnus-summary-toggle-threads t]
2035         ["Hide threads" gnus-summary-hide-all-threads t]
2036         ["Show threads" gnus-summary-show-all-threads t]
2037         ["Hide thread" gnus-summary-hide-thread t]
2038         ["Show thread" gnus-summary-show-thread t]
2039         ["Go to next thread" gnus-summary-next-thread t]
2040         ["Go to previous thread" gnus-summary-prev-thread t]
2041         ["Go down thread" gnus-summary-down-thread t]
2042         ["Go up thread" gnus-summary-up-thread t]
2043         ["Top of thread" gnus-summary-top-thread t]
2044         ["Mark thread as read" gnus-summary-kill-thread t]
2045         ["Lower thread score" gnus-summary-lower-thread t]
2046         ["Raise thread score" gnus-summary-raise-thread t]
2047         ["Rethread current" gnus-summary-rethread-current t]))
2048
2049     (easy-menu-define
2050       gnus-summary-post-menu gnus-summary-mode-map ""
2051       `("Post"
2052         ["Send a message (mail or news)" gnus-summary-post-news
2053          ,@(if (featurep 'xemacs) '(t)
2054              '(:help "Post an article"))]
2055         ["Followup" gnus-summary-followup
2056          ,@(if (featurep 'xemacs) '(t)
2057              '(:help "Post followup to this article"))]
2058         ["Followup and yank" gnus-summary-followup-with-original
2059          ,@(if (featurep 'xemacs) '(t)
2060              '(:help "Post followup to this article, quoting its contents"))]
2061         ["Supersede article" gnus-summary-supersede-article t]
2062         ["Cancel article" gnus-summary-cancel-article
2063          ,@(if (featurep 'xemacs) '(t)
2064              '(:help "Cancel an article you posted"))]
2065         ["Reply" gnus-summary-reply t]
2066         ["Reply and yank" gnus-summary-reply-with-original t]
2067         ["Wide reply" gnus-summary-wide-reply t]
2068         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2069          ,@(if (featurep 'xemacs) '(t)
2070              '(:help "Mail a reply, quoting this article"))]
2071         ["Mail forward" gnus-summary-mail-forward t]
2072         ["Post forward" gnus-summary-post-forward t]
2073         ["Digest and mail" gnus-uu-digest-mail-forward t]
2074         ["Digest and post" gnus-uu-digest-post-forward t]
2075         ["Resend message" gnus-summary-resend-message t]
2076         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2077         ["Send a mail" gnus-summary-mail-other-window t]
2078         ["Create a local message" gnus-summary-news-other-window t]
2079         ["Uuencode and post" gnus-uu-post-news
2080          ,@(if (featurep 'xemacs) '(t)
2081              '(:help "Post a uuencoded article"))]
2082         ["Followup via news" gnus-summary-followup-to-mail t]
2083         ["Followup via news and yank"
2084          gnus-summary-followup-to-mail-with-original t]
2085         ;;("Draft"
2086         ;;["Send" gnus-summary-send-draft t]
2087         ;;["Send bounced" gnus-resend-bounced-mail t])
2088         ))
2089
2090     (cond
2091      ((not (keymapp gnus-summary-post-menu))
2092       (setq gnus-article-post-menu gnus-summary-post-menu))
2093      ((not gnus-article-post-menu)
2094       ;; Don't share post menu.
2095       (setq gnus-article-post-menu
2096             (copy-keymap gnus-summary-post-menu))))
2097     (define-key gnus-article-mode-map [menu-bar post]
2098       (cons "Post" gnus-article-post-menu))
2099
2100     (easy-menu-define
2101       gnus-summary-misc-menu gnus-summary-mode-map ""
2102       `("Gnus"
2103         ("Mark Read"
2104          ["Mark as read" gnus-summary-mark-as-read-forward t]
2105          ["Mark same subject and select"
2106           gnus-summary-kill-same-subject-and-select t]
2107          ["Mark same subject" gnus-summary-kill-same-subject t]
2108          ["Catchup" gnus-summary-catchup
2109           ,@(if (featurep 'xemacs) '(t)
2110               '(:help "Mark unread articles in this group as read"))]
2111          ["Catchup all" gnus-summary-catchup-all t]
2112          ["Catchup to here" gnus-summary-catchup-to-here t]
2113          ["Catchup from here" gnus-summary-catchup-from-here t]
2114          ["Catchup region" gnus-summary-mark-region-as-read t]
2115          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2116         ("Mark Various"
2117          ["Tick" gnus-summary-tick-article-forward t]
2118          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2119          ["Remove marks" gnus-summary-clear-mark-forward t]
2120          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2121          ["Set bookmark" gnus-summary-set-bookmark t]
2122          ["Remove bookmark" gnus-summary-remove-bookmark t])
2123         ("Limit to"
2124          ["Marks..." gnus-summary-limit-to-marks t]
2125          ["Subject..." gnus-summary-limit-to-subject t]
2126          ["Author..." gnus-summary-limit-to-author t]
2127          ["Age..." gnus-summary-limit-to-age t]
2128          ["Extra..." gnus-summary-limit-to-extra t]
2129          ["Score" gnus-summary-limit-to-score t]
2130          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2131          ["Unread" gnus-summary-limit-to-unread t]
2132          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2133          ["Articles" gnus-summary-limit-to-articles t]
2134          ["Pop limit" gnus-summary-pop-limit t]
2135          ["Show dormant" gnus-summary-limit-include-dormant t]
2136          ["Hide childless dormant"
2137           gnus-summary-limit-exclude-childless-dormant t]
2138          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2139          ["Hide marked" gnus-summary-limit-exclude-marks t]
2140          ["Show expunged" gnus-summary-limit-include-expunged t])
2141         ("Process Mark"
2142          ["Set mark" gnus-summary-mark-as-processable t]
2143          ["Remove mark" gnus-summary-unmark-as-processable t]
2144          ["Remove all marks" gnus-summary-unmark-all-processable t]
2145          ["Mark above" gnus-uu-mark-over t]
2146          ["Mark series" gnus-uu-mark-series t]
2147          ["Mark region" gnus-uu-mark-region t]
2148          ["Unmark region" gnus-uu-unmark-region t]
2149          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2150          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2151          ["Mark all" gnus-uu-mark-all t]
2152          ["Mark buffer" gnus-uu-mark-buffer t]
2153          ["Mark sparse" gnus-uu-mark-sparse t]
2154          ["Mark thread" gnus-uu-mark-thread t]
2155          ["Unmark thread" gnus-uu-unmark-thread t]
2156          ("Process Mark Sets"
2157           ["Kill" gnus-summary-kill-process-mark t]
2158           ["Yank" gnus-summary-yank-process-mark
2159            gnus-newsgroup-process-stack]
2160           ["Save" gnus-summary-save-process-mark t]))
2161         ("Scroll article"
2162          ["Page forward" gnus-summary-next-page
2163           ,@(if (featurep 'xemacs) '(t)
2164               '(:help "Show next page of article"))]
2165          ["Page backward" gnus-summary-prev-page
2166           ,@(if (featurep 'xemacs) '(t)
2167               '(:help "Show previous page of article"))]
2168          ["Line forward" gnus-summary-scroll-up t])
2169         ("Move"
2170          ["Next unread article" gnus-summary-next-unread-article t]
2171          ["Previous unread article" gnus-summary-prev-unread-article t]
2172          ["Next article" gnus-summary-next-article t]
2173          ["Previous article" gnus-summary-prev-article t]
2174          ["Next unread subject" gnus-summary-next-unread-subject t]
2175          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2176          ["Next article same subject" gnus-summary-next-same-subject t]
2177          ["Previous article same subject" gnus-summary-prev-same-subject t]
2178          ["First unread article" gnus-summary-first-unread-article t]
2179          ["Best unread article" gnus-summary-best-unread-article t]
2180          ["Go to subject number..." gnus-summary-goto-subject t]
2181          ["Go to article number..." gnus-summary-goto-article t]
2182          ["Go to the last article" gnus-summary-goto-last-article t]
2183          ["Pop article off history" gnus-summary-pop-article t])
2184         ("Sort"
2185          ["Sort by number" gnus-summary-sort-by-number t]
2186          ["Sort by author" gnus-summary-sort-by-author t]
2187          ["Sort by subject" gnus-summary-sort-by-subject t]
2188          ["Sort by date" gnus-summary-sort-by-date t]
2189          ["Sort by score" gnus-summary-sort-by-score t]
2190          ["Sort by lines" gnus-summary-sort-by-lines t]
2191          ["Sort by characters" gnus-summary-sort-by-chars t]
2192          ["Original sort" gnus-summary-sort-by-original t])
2193         ("Help"
2194          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2195          ["Describe group" gnus-summary-describe-group t]
2196          ["Read manual" gnus-info-find-node t])
2197         ("Modes"
2198          ["Pick and read" gnus-pick-mode t]
2199          ["Binary" gnus-binary-mode t])
2200         ("Regeneration"
2201          ["Regenerate" gnus-summary-prepare t]
2202          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2203          ["Toggle threading" gnus-summary-toggle-threads t])
2204         ["See old articles" gnus-summary-insert-old-articles t]
2205         ["See new articles" gnus-summary-insert-new-articles t]
2206         ["Filter articles..." gnus-summary-execute-command t]
2207         ["Run command on subjects..." gnus-summary-universal-argument t]
2208         ["Search articles forward..." gnus-summary-search-article-forward t]
2209         ["Search articles backward..." gnus-summary-search-article-backward t]
2210         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2211         ["Expand window" gnus-summary-expand-window t]
2212         ["Expire expirable articles" gnus-summary-expire-articles
2213          (gnus-check-backend-function
2214           'request-expire-articles gnus-newsgroup-name)]
2215         ["Edit local kill file" gnus-summary-edit-local-kill t]
2216         ["Edit main kill file" gnus-summary-edit-global-kill t]
2217         ["Edit group parameters" gnus-summary-edit-parameters t]
2218         ["Customize group parameters" gnus-summary-customize-parameters t]
2219         ["Send a bug report" gnus-bug t]
2220         ("Exit"
2221          ["Catchup and exit" gnus-summary-catchup-and-exit
2222           ,@(if (featurep 'xemacs) '(t)
2223               '(:help "Mark unread articles in this group as read, then exit"))]
2224          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2225          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2226          ["Exit group" gnus-summary-exit
2227           ,@(if (featurep 'xemacs) '(t)
2228               '(:help "Exit current group, return to group selection mode"))]
2229          ["Exit group without updating" gnus-summary-exit-no-update t]
2230          ["Exit and goto next group" gnus-summary-next-group t]
2231          ["Exit and goto prev group" gnus-summary-prev-group t]
2232          ["Reselect group" gnus-summary-reselect-current-group t]
2233          ["Rescan group" gnus-summary-rescan-group t]
2234          ["Update dribble" gnus-summary-save-newsrc t])))
2235
2236     (gnus-run-hooks 'gnus-summary-menu-hook)))
2237
2238 (defvar gnus-summary-tool-bar-map nil)
2239
2240 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2241 (defun gnus-summary-make-tool-bar ()
2242   (if (and (fboundp 'tool-bar-add-item-from-menu)
2243            (default-value 'tool-bar-mode)
2244            (not gnus-summary-tool-bar-map))
2245       (setq gnus-summary-tool-bar-map
2246             (let ((tool-bar-map (make-sparse-keymap))
2247                   (load-path (mm-image-load-path)))
2248               (tool-bar-add-item-from-menu
2249                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2250               (tool-bar-add-item-from-menu
2251                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2252               (tool-bar-add-item-from-menu
2253                'gnus-summary-post-news "post" gnus-summary-mode-map)
2254               (tool-bar-add-item-from-menu
2255                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2256               (tool-bar-add-item-from-menu
2257                'gnus-summary-followup "followup" gnus-summary-mode-map)
2258               (tool-bar-add-item-from-menu
2259                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2260               (tool-bar-add-item-from-menu
2261                'gnus-summary-reply "reply" gnus-summary-mode-map)
2262               (tool-bar-add-item-from-menu
2263                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2264               (tool-bar-add-item-from-menu
2265                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2266               (tool-bar-add-item-from-menu
2267                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2268               (tool-bar-add-item-from-menu
2269                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2270               (tool-bar-add-item-from-menu
2271                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2272               (tool-bar-add-item-from-menu
2273                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2274               (tool-bar-add-item-from-menu
2275                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2276               (tool-bar-add-item-from-menu
2277                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2278               tool-bar-map)))
2279   (if gnus-summary-tool-bar-map
2280       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2281
2282 (defun gnus-score-set-default (var value)
2283   "A version of set that updates the GNU Emacs menu-bar."
2284   (set var value)
2285   ;; It is the message that forces the active status to be updated.
2286   (message ""))
2287
2288 (defun gnus-make-score-map (type)
2289   "Make a summary score map of type TYPE."
2290   (if t
2291       nil
2292     (let ((headers '(("author" "from" string)
2293                      ("subject" "subject" string)
2294                      ("article body" "body" string)
2295                      ("article head" "head" string)
2296                      ("xref" "xref" string)
2297                      ("extra header" "extra" string)
2298                      ("lines" "lines" number)
2299                      ("followups to author" "followup" string)))
2300           (types '((number ("less than" <)
2301                            ("greater than" >)
2302                            ("equal" =))
2303                    (string ("substring" s)
2304                            ("exact string" e)
2305                            ("fuzzy string" f)
2306                            ("regexp" r))))
2307           (perms '(("temporary" (current-time-string))
2308                    ("permanent" nil)
2309                    ("immediate" now)))
2310           header)
2311       (list
2312        (apply
2313         'nconc
2314         (list
2315          (if (eq type 'lower)
2316              "Lower score"
2317            "Increase score"))
2318         (let (outh)
2319           (while headers
2320             (setq header (car headers))
2321             (setq outh
2322                   (cons
2323                    (apply
2324                     'nconc
2325                     (list (car header))
2326                     (let ((ts (cdr (assoc (nth 2 header) types)))
2327                           outt)
2328                       (while ts
2329                         (setq outt
2330                               (cons
2331                                (apply
2332                                 'nconc
2333                                 (list (caar ts))
2334                                 (let ((ps perms)
2335                                       outp)
2336                                   (while ps
2337                                     (setq outp
2338                                           (cons
2339                                            (vector
2340                                             (caar ps)
2341                                             (list
2342                                              'gnus-summary-score-entry
2343                                              (nth 1 header)
2344                                              (if (or (string= (nth 1 header)
2345                                                               "head")
2346                                                      (string= (nth 1 header)
2347                                                               "body"))
2348                                                  ""
2349                                                (list 'gnus-summary-header
2350                                                      (nth 1 header)))
2351                                              (list 'quote (nth 1 (car ts)))
2352                                              (list 'gnus-score-delta-default
2353                                                    nil)
2354                                              (nth 1 (car ps))
2355                                              t)
2356                                             t)
2357                                            outp))
2358                                     (setq ps (cdr ps)))
2359                                   (list (nreverse outp))))
2360                                outt))
2361                         (setq ts (cdr ts)))
2362                       (list (nreverse outt))))
2363                    outh))
2364             (setq headers (cdr headers)))
2365           (list (nreverse outh))))))))
2366
2367 \f
2368
2369 (defun gnus-summary-mode (&optional group)
2370   "Major mode for reading articles.
2371
2372 All normal editing commands are switched off.
2373 \\<gnus-summary-mode-map>
2374 Each line in this buffer represents one article.  To read an
2375 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2376 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2377 respectively.
2378
2379 You can also post articles and send mail from this buffer.  To
2380 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2381 of an article, type `\\[gnus-summary-reply]'.
2382
2383 There are approx. one gazillion commands you can execute in this
2384 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2385
2386 The following commands are available:
2387
2388 \\{gnus-summary-mode-map}"
2389   (interactive)
2390   (kill-all-local-variables)
2391   (when (gnus-visual-p 'summary-menu 'menu)
2392     (gnus-summary-make-menu-bar)
2393     (gnus-summary-make-tool-bar))
2394   (gnus-summary-make-local-variables)
2395   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2396     (gnus-summary-make-local-variables))
2397   (gnus-make-thread-indent-array)
2398   (gnus-simplify-mode-line)
2399   (setq major-mode 'gnus-summary-mode)
2400   (setq mode-name "Summary")
2401   (make-local-variable 'minor-mode-alist)
2402   (use-local-map gnus-summary-mode-map)
2403   (buffer-disable-undo)
2404   (setq buffer-read-only t)             ;Disable modification
2405   (setq truncate-lines t)
2406   (setq selective-display t)
2407   (setq selective-display-ellipses t)   ;Display `...'
2408   (gnus-summary-set-display-table)
2409   (gnus-set-default-directory)
2410   (setq gnus-newsgroup-name group)
2411   (make-local-variable 'gnus-summary-line-format)
2412   (make-local-variable 'gnus-summary-line-format-spec)
2413   (make-local-variable 'gnus-summary-dummy-line-format)
2414   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2415   (make-local-variable 'gnus-summary-mark-positions)
2416   (make-local-hook 'pre-command-hook)
2417   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2418   (gnus-run-hooks 'gnus-summary-mode-hook)
2419   (turn-on-gnus-mailing-list-mode)
2420   (mm-enable-multibyte-mule4)
2421   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2422   (gnus-update-summary-mark-positions))
2423
2424 (defun gnus-summary-make-local-variables ()
2425   "Make all the local summary buffer variables."
2426   (let (global)
2427     (dolist (local gnus-summary-local-variables)
2428       (if (consp local)
2429           (progn
2430             (if (eq (cdr local) 'global)
2431                 ;; Copy the global value of the variable.
2432                 (setq global (symbol-value (car local)))
2433               ;; Use the value from the list.
2434               (setq global (eval (cdr local))))
2435             (set (make-local-variable (car local)) global))
2436         ;; Simple nil-valued local variable.
2437         (set (make-local-variable local) nil)))))
2438
2439 (defun gnus-summary-clear-local-variables ()
2440   (let ((locals gnus-summary-local-variables))
2441     (while locals
2442       (if (consp (car locals))
2443           (and (vectorp (caar locals))
2444                (set (caar locals) nil))
2445         (and (vectorp (car locals))
2446              (set (car locals) nil)))
2447       (setq locals (cdr locals)))))
2448
2449 ;; Summary data functions.
2450
2451 (defmacro gnus-data-number (data)
2452   `(car ,data))
2453
2454 (defmacro gnus-data-set-number (data number)
2455   `(setcar ,data ,number))
2456
2457 (defmacro gnus-data-mark (data)
2458   `(nth 1 ,data))
2459
2460 (defmacro gnus-data-set-mark (data mark)
2461   `(setcar (nthcdr 1 ,data) ,mark))
2462
2463 (defmacro gnus-data-pos (data)
2464   `(nth 2 ,data))
2465
2466 (defmacro gnus-data-set-pos (data pos)
2467   `(setcar (nthcdr 2 ,data) ,pos))
2468
2469 (defmacro gnus-data-header (data)
2470   `(nth 3 ,data))
2471
2472 (defmacro gnus-data-set-header (data header)
2473   `(setf (nth 3 ,data) ,header))
2474
2475 (defmacro gnus-data-level (data)
2476   `(nth 4 ,data))
2477
2478 (defmacro gnus-data-unread-p (data)
2479   `(= (nth 1 ,data) gnus-unread-mark))
2480
2481 (defmacro gnus-data-read-p (data)
2482   `(/= (nth 1 ,data) gnus-unread-mark))
2483
2484 (defmacro gnus-data-pseudo-p (data)
2485   `(consp (nth 3 ,data)))
2486
2487 (defmacro gnus-data-find (number)
2488   `(assq ,number gnus-newsgroup-data))
2489
2490 (defmacro gnus-data-find-list (number &optional data)
2491   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2492      (memq (assq ,number bdata)
2493            bdata)))
2494
2495 (defmacro gnus-data-make (number mark pos header level)
2496   `(list ,number ,mark ,pos ,header ,level))
2497
2498 (defun gnus-data-enter (after-article number mark pos header level offset)
2499   (let ((data (gnus-data-find-list after-article)))
2500     (unless data
2501       (error "No such article: %d" after-article))
2502     (setcdr data (cons (gnus-data-make number mark pos header level)
2503                        (cdr data)))
2504     (setq gnus-newsgroup-data-reverse nil)
2505     (gnus-data-update-list (cddr data) offset)))
2506
2507 (defun gnus-data-enter-list (after-article list &optional offset)
2508   (when list
2509     (let ((data (and after-article (gnus-data-find-list after-article)))
2510           (ilist list))
2511       (if (not (or data
2512                    after-article))
2513           (let ((odata gnus-newsgroup-data))
2514             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2515             (when offset
2516               (gnus-data-update-list odata offset)))
2517       ;; Find the last element in the list to be spliced into the main
2518         ;; list.
2519         (while (cdr list)
2520           (setq list (cdr list)))
2521         (if (not data)
2522             (progn
2523               (setcdr list gnus-newsgroup-data)
2524               (setq gnus-newsgroup-data ilist)
2525               (when offset
2526                 (gnus-data-update-list (cdr list) offset)))
2527           (setcdr list (cdr data))
2528           (setcdr data ilist)
2529           (when offset
2530             (gnus-data-update-list (cdr list) offset))))
2531       (setq gnus-newsgroup-data-reverse nil))))
2532
2533 (defun gnus-data-remove (article &optional offset)
2534   (let ((data gnus-newsgroup-data))
2535     (if (= (gnus-data-number (car data)) article)
2536         (progn
2537           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2538                 gnus-newsgroup-data-reverse nil)
2539           (when offset
2540             (gnus-data-update-list gnus-newsgroup-data offset)))
2541       (while (cdr data)
2542         (when (= (gnus-data-number (cadr data)) article)
2543           (setcdr data (cddr data))
2544           (when offset
2545             (gnus-data-update-list (cdr data) offset))
2546           (setq data nil
2547                 gnus-newsgroup-data-reverse nil))
2548         (setq data (cdr data))))))
2549
2550 (defmacro gnus-data-list (backward)
2551   `(if ,backward
2552        (or gnus-newsgroup-data-reverse
2553            (setq gnus-newsgroup-data-reverse
2554                  (reverse gnus-newsgroup-data)))
2555      gnus-newsgroup-data))
2556
2557 (defun gnus-data-update-list (data offset)
2558   "Add OFFSET to the POS of all data entries in DATA."
2559   (setq gnus-newsgroup-data-reverse nil)
2560   (while data
2561     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2562     (setq data (cdr data))))
2563
2564 (defun gnus-summary-article-pseudo-p (article)
2565   "Say whether this article is a pseudo article or not."
2566   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2567
2568 (defmacro gnus-summary-article-sparse-p (article)
2569   "Say whether this article is a sparse article or not."
2570   `(memq ,article gnus-newsgroup-sparse))
2571
2572 (defmacro gnus-summary-article-ancient-p (article)
2573   "Say whether this article is a sparse article or not."
2574   `(memq ,article gnus-newsgroup-ancient))
2575
2576 (defun gnus-article-parent-p (number)
2577   "Say whether this article is a parent or not."
2578   (let ((data (gnus-data-find-list number)))
2579     (and (cdr data)              ; There has to be an article after...
2580          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2581             (gnus-data-level (nth 1 data))))))
2582
2583 (defun gnus-article-children (number)
2584   "Return a list of all children to NUMBER."
2585   (let* ((data (gnus-data-find-list number))
2586          (level (gnus-data-level (car data)))
2587          children)
2588     (setq data (cdr data))
2589     (while (and data
2590                 (= (gnus-data-level (car data)) (1+ level)))
2591       (push (gnus-data-number (car data)) children)
2592       (setq data (cdr data)))
2593     children))
2594
2595 (defmacro gnus-summary-skip-intangible ()
2596   "If the current article is intangible, then jump to a different article."
2597   '(let ((to (get-text-property (point) 'gnus-intangible)))
2598      (and to (gnus-summary-goto-subject to))))
2599
2600 (defmacro gnus-summary-article-intangible-p ()
2601   "Say whether this article is intangible or not."
2602   '(get-text-property (point) 'gnus-intangible))
2603
2604 (defun gnus-article-read-p (article)
2605   "Say whether ARTICLE is read or not."
2606   (not (or (memq article gnus-newsgroup-marked)
2607            (memq article gnus-newsgroup-unreads)
2608            (memq article gnus-newsgroup-unselected)
2609            (memq article gnus-newsgroup-dormant))))
2610
2611 ;; Some summary mode macros.
2612
2613 (defmacro gnus-summary-article-number ()
2614   "The article number of the article on the current line.
2615 If there isn's an article number here, then we return the current
2616 article number."
2617   '(progn
2618      (gnus-summary-skip-intangible)
2619      (or (get-text-property (point) 'gnus-number)
2620          (gnus-summary-last-subject))))
2621
2622 (defmacro gnus-summary-article-header (&optional number)
2623   "Return the header of article NUMBER."
2624   `(gnus-data-header (gnus-data-find
2625                       ,(or number '(gnus-summary-article-number)))))
2626
2627 (defmacro gnus-summary-thread-level (&optional number)
2628   "Return the level of thread that starts with article NUMBER."
2629   `(if (and (eq gnus-summary-make-false-root 'dummy)
2630             (get-text-property (point) 'gnus-intangible))
2631        0
2632      (gnus-data-level (gnus-data-find
2633                        ,(or number '(gnus-summary-article-number))))))
2634
2635 (defmacro gnus-summary-article-mark (&optional number)
2636   "Return the mark of article NUMBER."
2637   `(gnus-data-mark (gnus-data-find
2638                     ,(or number '(gnus-summary-article-number)))))
2639
2640 (defmacro gnus-summary-article-pos (&optional number)
2641   "Return the position of the line of article NUMBER."
2642   `(gnus-data-pos (gnus-data-find
2643                    ,(or number '(gnus-summary-article-number)))))
2644
2645 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2646 (defmacro gnus-summary-article-subject (&optional number)
2647   "Return current subject string or nil if nothing."
2648   `(let ((headers
2649           ,(if number
2650                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2651              '(gnus-data-header (assq (gnus-summary-article-number)
2652                                       gnus-newsgroup-data)))))
2653      (and headers
2654           (vectorp headers)
2655           (mail-header-subject headers))))
2656
2657 (defmacro gnus-summary-article-score (&optional number)
2658   "Return current article score."
2659   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2660                   gnus-newsgroup-scored))
2661        gnus-summary-default-score 0))
2662
2663 (defun gnus-summary-article-children (&optional number)
2664   "Return a list of article numbers that are children of article NUMBER."
2665   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2666          (level (gnus-data-level (car data)))
2667          l children)
2668     (while (and (setq data (cdr data))
2669                 (> (setq l (gnus-data-level (car data))) level))
2670       (and (= (1+ level) l)
2671            (push (gnus-data-number (car data))
2672                  children)))
2673     (nreverse children)))
2674
2675 (defun gnus-summary-article-parent (&optional number)
2676   "Return the article number of the parent of article NUMBER."
2677   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2678                                     (gnus-data-list t)))
2679          (level (gnus-data-level (car data))))
2680     (if (zerop level)
2681         ()                              ; This is a root.
2682       ;; We search until we find an article with a level less than
2683       ;; this one.  That function has to be the parent.
2684       (while (and (setq data (cdr data))
2685                   (not (< (gnus-data-level (car data)) level))))
2686       (and data (gnus-data-number (car data))))))
2687
2688 (defun gnus-unread-mark-p (mark)
2689   "Say whether MARK is the unread mark."
2690   (= mark gnus-unread-mark))
2691
2692 (defun gnus-read-mark-p (mark)
2693   "Say whether MARK is one of the marks that mark as read.
2694 This is all marks except unread, ticked, dormant, and expirable."
2695   (not (or (= mark gnus-unread-mark)
2696            (= mark gnus-ticked-mark)
2697            (= mark gnus-dormant-mark)
2698            (= mark gnus-expirable-mark))))
2699
2700 (defmacro gnus-article-mark (number)
2701   "Return the MARK of article NUMBER.
2702 This macro should only be used when computing the mark the \"first\"
2703 time; i.e., when generating the summary lines.  After that,
2704 `gnus-summary-article-mark' should be used to examine the
2705 marks of articles."
2706   `(cond
2707     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2708     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2709     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2710     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2711     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2712     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2713     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2714     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2715            gnus-ancient-mark))))
2716
2717 ;; Saving hidden threads.
2718
2719 (defmacro gnus-save-hidden-threads (&rest forms)
2720   "Save hidden threads, eval FORMS, and restore the hidden threads."
2721   (let ((config (make-symbol "config")))
2722     `(let ((,config (gnus-hidden-threads-configuration)))
2723        (unwind-protect
2724            (save-excursion
2725              ,@forms)
2726          (gnus-restore-hidden-threads-configuration ,config)))))
2727 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2728 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2729
2730 (defun gnus-data-compute-positions ()
2731   "Compute the positions of all articles."
2732   (setq gnus-newsgroup-data-reverse nil)
2733   (let ((data gnus-newsgroup-data))
2734     (save-excursion
2735       (gnus-save-hidden-threads
2736         (gnus-summary-show-all-threads)
2737         (goto-char (point-min))
2738         (while data
2739           (while (get-text-property (point) 'gnus-intangible)
2740             (forward-line 1))
2741           (gnus-data-set-pos (car data) (+ (point) 3))
2742           (setq data (cdr data))
2743           (forward-line 1))))))
2744
2745 (defun gnus-hidden-threads-configuration ()
2746   "Return the current hidden threads configuration."
2747   (save-excursion
2748     (let (config)
2749       (goto-char (point-min))
2750       (while (search-forward "\r" nil t)
2751         (push (1- (point)) config))
2752       config)))
2753
2754 (defun gnus-restore-hidden-threads-configuration (config)
2755   "Restore hidden threads configuration from CONFIG."
2756   (save-excursion
2757     (let (point buffer-read-only)
2758       (while (setq point (pop config))
2759         (when (and (< point (point-max))
2760                    (goto-char point)
2761                    (eq (char-after) ?\n))
2762           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2763
2764 ;; Various summary mode internalish functions.
2765
2766 (defun gnus-mouse-pick-article (e)
2767   (interactive "e")
2768   (mouse-set-point e)
2769   (gnus-summary-next-page nil t))
2770
2771 (defun gnus-summary-set-display-table ()
2772   "Change the display table.
2773 Odd characters have a tendency to mess
2774 up nicely formatted displays - we make all possible glyphs
2775 display only a single character."
2776
2777   ;; We start from the standard display table, if any.
2778   (let ((table (or (copy-sequence standard-display-table)
2779                    (make-display-table)))
2780         (i 32))
2781     ;; Nix out all the control chars...
2782     (while (>= (setq i (1- i)) 0)
2783       (aset table i [??]))
2784    ;; ... but not newline and cr, of course.  (cr is necessary for the
2785     ;; selective display).
2786     (aset table ?\n nil)
2787     (aset table ?\r nil)
2788     ;; We keep TAB as well.
2789     (aset table ?\t nil)
2790     ;; We nix out any glyphs over 126 that are not set already.
2791     (let ((i 256))
2792       (while (>= (setq i (1- i)) 127)
2793         ;; Only modify if the entry is nil.
2794         (unless (aref table i)
2795           (aset table i [??]))))
2796     (setq buffer-display-table table)))
2797
2798 (defun gnus-summary-set-article-display-arrow (pos)
2799   "Update the overlay arrow to point to line at position POS."
2800   (when (and gnus-summary-display-arrow
2801              (boundp 'overlay-arrow-position)
2802              (boundp 'overlay-arrow-string))
2803     (save-excursion
2804       (goto-char pos)
2805       (beginning-of-line)
2806       (unless overlay-arrow-position
2807         (setq overlay-arrow-position (make-marker)))
2808       (setq overlay-arrow-string "=>"
2809             overlay-arrow-position (set-marker overlay-arrow-position
2810                                                (point)
2811                                                (current-buffer))))))
2812
2813 (defun gnus-summary-buffer-name (group)
2814   "Return the summary buffer name of GROUP."
2815   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2816
2817 (defun gnus-summary-setup-buffer (group)
2818   "Initialize summary buffer."
2819   (let ((buffer (gnus-summary-buffer-name group)))
2820     (if (get-buffer buffer)
2821         (progn
2822           (set-buffer buffer)
2823           (setq gnus-summary-buffer (current-buffer))
2824           (not gnus-newsgroup-prepared))
2825       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2826       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2827       (gnus-summary-mode group)
2828       (when gnus-carpal
2829         (gnus-carpal-setup-buffer 'summary))
2830       (unless gnus-single-article-buffer
2831         (make-local-variable 'gnus-article-buffer)
2832         (make-local-variable 'gnus-article-current)
2833         (make-local-variable 'gnus-original-article-buffer))
2834       (setq gnus-newsgroup-name group)
2835       ;; Set any local variables in the group parameters.
2836       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2837       t)))
2838
2839 (defun gnus-set-global-variables ()
2840   "Set the global equivalents of the buffer-local variables.
2841 They are set to the latest values they had.  These reflect the summary
2842 buffer that was in action when the last article was fetched."
2843   (when (eq major-mode 'gnus-summary-mode)
2844     (setq gnus-summary-buffer (current-buffer))
2845     (let ((name gnus-newsgroup-name)
2846           (marked gnus-newsgroup-marked)
2847           (unread gnus-newsgroup-unreads)
2848           (headers gnus-current-headers)
2849           (data gnus-newsgroup-data)
2850           (summary gnus-summary-buffer)
2851           (article-buffer gnus-article-buffer)
2852           (original gnus-original-article-buffer)
2853           (gac gnus-article-current)
2854           (reffed gnus-reffed-article-number)
2855           (score-file gnus-current-score-file)
2856           (default-charset gnus-newsgroup-charset)
2857           vlist)
2858       (let ((locals gnus-newsgroup-variables))
2859         (while locals
2860           (if (consp (car locals))
2861               (push (eval (caar locals)) vlist)
2862             (push (eval (car locals)) vlist))
2863           (setq locals (cdr locals)))
2864         (setq vlist (nreverse vlist)))
2865       (save-excursion
2866         (set-buffer gnus-group-buffer)
2867         (setq gnus-newsgroup-name name
2868               gnus-newsgroup-marked marked
2869               gnus-newsgroup-unreads unread
2870               gnus-current-headers headers
2871               gnus-newsgroup-data data
2872               gnus-article-current gac
2873               gnus-summary-buffer summary
2874               gnus-article-buffer article-buffer
2875               gnus-original-article-buffer original
2876               gnus-reffed-article-number reffed
2877               gnus-current-score-file score-file
2878               gnus-newsgroup-charset default-charset)
2879         (let ((locals gnus-newsgroup-variables))
2880           (while locals
2881             (if (consp (car locals))
2882                 (set (caar locals) (pop vlist))
2883               (set (car locals) (pop vlist)))
2884             (setq locals (cdr locals))))
2885         ;; The article buffer also has local variables.
2886         (when (gnus-buffer-live-p gnus-article-buffer)
2887           (set-buffer gnus-article-buffer)
2888           (setq gnus-summary-buffer summary))))))
2889
2890 (defun gnus-summary-article-unread-p (article)
2891   "Say whether ARTICLE is unread or not."
2892   (memq article gnus-newsgroup-unreads))
2893
2894 (defun gnus-summary-first-article-p (&optional article)
2895   "Return whether ARTICLE is the first article in the buffer."
2896   (if (not (setq article (or article (gnus-summary-article-number))))
2897       nil
2898     (eq article (caar gnus-newsgroup-data))))
2899
2900 (defun gnus-summary-last-article-p (&optional article)
2901   "Return whether ARTICLE is the last article in the buffer."
2902   (if (not (setq article (or article (gnus-summary-article-number))))
2903       ;; All non-existent numbers are the last article.  :-)
2904       t
2905     (not (cdr (gnus-data-find-list article)))))
2906
2907 (defun gnus-make-thread-indent-array ()
2908   (let ((n 200))
2909     (unless (and gnus-thread-indent-array
2910                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2911       (setq gnus-thread-indent-array (make-vector 201 "")
2912             gnus-thread-indent-array-level gnus-thread-indent-level)
2913       (while (>= n 0)
2914         (aset gnus-thread-indent-array n
2915               (make-string (* n gnus-thread-indent-level) ? ))
2916         (setq n (1- n))))))
2917
2918 (defun gnus-update-summary-mark-positions ()
2919   "Compute where the summary marks are to go."
2920   (save-excursion
2921     (when (gnus-buffer-exists-p gnus-summary-buffer)
2922       (set-buffer gnus-summary-buffer))
2923     (let ((gnus-replied-mark 129)
2924           (gnus-score-below-mark 130)
2925           (gnus-score-over-mark 130)
2926           (gnus-download-mark 131)
2927           (spec gnus-summary-line-format-spec)
2928           gnus-visual pos)
2929       (save-excursion
2930         (gnus-set-work-buffer)
2931         (let ((gnus-summary-line-format-spec spec)
2932               (gnus-newsgroup-downloadable '((0 . t))))
2933           (gnus-summary-insert-line
2934            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
2935            0 nil 128 t nil "" nil 1)
2936           (goto-char (point-min))
2937           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2938                                              (- (point) 2)))))
2939           (goto-char (point-min))
2940           (push (cons 'replied (and (search-forward "\201" nil t)
2941                                     (- (point) 2)))
2942                 pos)
2943           (goto-char (point-min))
2944           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2945                 pos)
2946           (goto-char (point-min))
2947           (push (cons 'download
2948                       (and (search-forward "\203" nil t) (- (point) 2)))
2949                 pos)))
2950       (setq gnus-summary-mark-positions pos))))
2951
2952 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2953   "Insert a dummy root in the summary buffer."
2954   (beginning-of-line)
2955   (gnus-add-text-properties
2956    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2957    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2958
2959 (defun gnus-summary-extract-address-component (from)
2960   (or (car (funcall gnus-extract-address-components from))
2961       from))
2962
2963 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2964   (let ((mail-parse-charset gnus-newsgroup-charset)
2965         ; Is it really necessary to do this next part for each summary line?
2966         ; Luckily, doesn't seem to slow things down much.
2967         (mail-parse-ignored-charsets
2968          (save-excursion (set-buffer gnus-summary-buffer)
2969                          gnus-newsgroup-ignored-charsets)))
2970     (or
2971      (and gnus-ignored-from-addresses
2972           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2973           (let ((extra-headers (mail-header-extra header))
2974                 to
2975                 newsgroups)
2976             (cond
2977              ((setq to (cdr (assq 'To extra-headers)))
2978               (concat "-> "
2979                       (gnus-summary-extract-address-component
2980                        (funcall gnus-decode-encoded-word-function to))))
2981              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2982               (concat "=> " newsgroups)))))
2983      (gnus-summary-extract-address-component gnus-tmp-from))))
2984
2985 (defun gnus-summary-insert-line (gnus-tmp-header
2986                                  gnus-tmp-level gnus-tmp-current
2987                                  gnus-tmp-unread gnus-tmp-replied
2988                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2989                                  &optional gnus-tmp-dummy gnus-tmp-score
2990                                  gnus-tmp-process)
2991   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2992          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2993          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2994          (gnus-tmp-score-char
2995           (if (or (null gnus-summary-default-score)
2996                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2997                       gnus-summary-zcore-fuzz))
2998               ?                         ;Whitespace
2999             (if (< gnus-tmp-score gnus-summary-default-score)
3000                 gnus-score-below-mark gnus-score-over-mark)))
3001          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3002          (gnus-tmp-replied
3003           (cond (gnus-tmp-process gnus-process-mark)
3004                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3005                  gnus-cached-mark)
3006                 (gnus-tmp-replied gnus-replied-mark)
3007                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3008                  gnus-forwarded-mark)
3009                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3010                  gnus-saved-mark)
3011                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3012                  gnus-recent-mark)
3013                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3014                  gnus-unseen-mark)
3015                 (t gnus-no-mark)))
3016          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3017          (gnus-tmp-name
3018           (cond
3019            ((string-match "<[^>]+> *$" gnus-tmp-from)
3020             (let ((beg (match-beginning 0)))
3021               (or (and (string-match "^\".+\"" gnus-tmp-from)
3022                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3023                   (substring gnus-tmp-from 0 beg))))
3024            ((string-match "(.+)" gnus-tmp-from)
3025             (substring gnus-tmp-from
3026                        (1+ (match-beginning 0)) (1- (match-end 0))))
3027            (t gnus-tmp-from)))
3028          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3029          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3030          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3031          (buffer-read-only nil))
3032     (when (string= gnus-tmp-name "")
3033       (setq gnus-tmp-name gnus-tmp-from))
3034     (unless (numberp gnus-tmp-lines)
3035       (setq gnus-tmp-lines -1))
3036     (if (= gnus-tmp-lines -1)
3037         (setq gnus-tmp-lines "?")
3038       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3039     (gnus-put-text-property
3040      (point)
3041      (progn (eval gnus-summary-line-format-spec) (point))
3042      'gnus-number gnus-tmp-number)
3043     (when (gnus-visual-p 'summary-highlight 'highlight)
3044       (forward-line -1)
3045       (gnus-run-hooks 'gnus-summary-update-hook)
3046       (forward-line 1))))
3047
3048 (defun gnus-summary-update-line (&optional dont-update)
3049   "Update summary line after change."
3050   (when (and gnus-summary-default-score
3051              (not gnus-summary-inhibit-highlight))
3052     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3053            (article (gnus-summary-article-number))
3054            (score (gnus-summary-article-score article)))
3055       (unless dont-update
3056         (if (and gnus-summary-mark-below
3057                  (< (gnus-summary-article-score)
3058                     gnus-summary-mark-below))
3059             ;; This article has a low score, so we mark it as read.
3060             (when (memq article gnus-newsgroup-unreads)
3061               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3062           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3063             ;; This article was previously marked as read on account
3064             ;; of a low score, but now it has risen, so we mark it as
3065             ;; unread.
3066             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3067         (gnus-summary-update-mark
3068          (if (or (null gnus-summary-default-score)
3069                  (<= (abs (- score gnus-summary-default-score))
3070                      gnus-summary-zcore-fuzz))
3071              ?                          ;Whitespace
3072            (if (< score gnus-summary-default-score)
3073                gnus-score-below-mark gnus-score-over-mark))
3074          'score))
3075       ;; Do visual highlighting.
3076       (when (gnus-visual-p 'summary-highlight 'highlight)
3077         (gnus-run-hooks 'gnus-summary-update-hook)))))
3078
3079 (defvar gnus-tmp-new-adopts nil)
3080
3081 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3082   "Return the number of articles in THREAD.
3083 This may be 0 in some cases -- if none of the articles in
3084 the thread are to be displayed."
3085   (let* ((number
3086          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3087           (cond
3088            ((not (listp thread))
3089             1)
3090            ((and (consp thread) (cdr thread))
3091             (apply
3092              '+ 1 (mapcar
3093                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3094            ((null thread)
3095             1)
3096            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3097             1)
3098            (t 0))))
3099     (when (and level (zerop level) gnus-tmp-new-adopts)
3100       (incf number
3101             (apply '+ (mapcar
3102                        'gnus-summary-number-of-articles-in-thread
3103                        gnus-tmp-new-adopts))))
3104     (if char
3105         (if (> number 1) gnus-not-empty-thread-mark
3106           gnus-empty-thread-mark)
3107       number)))
3108
3109 (defun gnus-summary-set-local-parameters (group)
3110   "Go through the local params of GROUP and set all variable specs in that list."
3111   (let ((params (gnus-group-find-parameter group))
3112         (vars '(quit-config))           ; Ignore quit-config.
3113         elem)
3114     (while params
3115       (setq elem (car params)
3116             params (cdr params))
3117       (and (consp elem)                 ; Has to be a cons.
3118            (consp (cdr elem))           ; The cdr has to be a list.
3119            (symbolp (car elem))         ; Has to be a symbol in there.
3120            (not (memq (car elem) vars))
3121            (ignore-errors               ; So we set it.
3122              (push (car elem) vars)
3123              (make-local-variable (car elem))
3124              (set (car elem) (eval (nth 1 elem))))))))
3125
3126 (defun gnus-summary-read-group (group &optional show-all no-article
3127                                       kill-buffer no-display backward
3128                                       select-articles)
3129   "Start reading news in newsgroup GROUP.
3130 If SHOW-ALL is non-nil, already read articles are also listed.
3131 If NO-ARTICLE is non-nil, no article is selected initially.
3132 If NO-DISPLAY, don't generate a summary buffer."
3133   (let (result)
3134     (while (and group
3135                 (null (setq result
3136                             (let ((gnus-auto-select-next nil))
3137                               (or (gnus-summary-read-group-1
3138                                    group show-all no-article
3139                                    kill-buffer no-display
3140                                    select-articles)
3141                                   (setq show-all nil
3142                                         select-articles nil)))))
3143                 (eq gnus-auto-select-next 'quietly))
3144       (set-buffer gnus-group-buffer)
3145       ;; The entry function called above goes to the next
3146       ;; group automatically, so we go two groups back
3147       ;; if we are searching for the previous group.
3148       (when backward
3149         (gnus-group-prev-unread-group 2))
3150       (if (not (equal group (gnus-group-group-name)))
3151           (setq group (gnus-group-group-name))
3152         (setq group nil)))
3153     result))
3154
3155 (defun gnus-summary-read-group-1 (group show-all no-article
3156                                         kill-buffer no-display
3157                                         &optional select-articles)
3158   ;; Killed foreign groups can't be entered.
3159   ;;  (when (and (not (gnus-group-native-p group))
3160   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3161   ;;    (error "Dead non-native groups can't be entered"))
3162   (gnus-message 5 "Retrieving newsgroup: %s..."
3163                 (gnus-group-decoded-name group))
3164   (let* ((new-group (gnus-summary-setup-buffer group))
3165          (quit-config (gnus-group-quit-config group))
3166          (did-select (and new-group (gnus-select-newsgroup
3167                                      group show-all select-articles))))
3168     (cond
3169      ;; This summary buffer exists already, so we just select it.
3170      ((not new-group)
3171       (gnus-set-global-variables)
3172       (when kill-buffer
3173         (gnus-kill-or-deaden-summary kill-buffer))
3174       (gnus-configure-windows 'summary 'force)
3175       (gnus-set-mode-line 'summary)
3176       (gnus-summary-position-point)
3177       (message "")
3178       t)
3179      ;; We couldn't select this group.
3180      ((null did-select)
3181       (when (and (eq major-mode 'gnus-summary-mode)
3182                  (not (equal (current-buffer) kill-buffer)))
3183         (kill-buffer (current-buffer))
3184         (if (not quit-config)
3185             (progn
3186               ;; Update the info -- marks might need to be removed,
3187               ;; for instance.
3188               (gnus-summary-update-info)
3189               (set-buffer gnus-group-buffer)
3190               (gnus-group-jump-to-group group)
3191               (gnus-group-next-unread-group 1))
3192           (gnus-handle-ephemeral-exit quit-config)))
3193       (let ((grpinfo (gnus-get-info group)))
3194         (if (null (gnus-info-read grpinfo))
3195             (gnus-message 3 "Group %s contains no messages"
3196                           (gnus-group-decoded-name group))
3197           (gnus-message 3 "Can't select group")))
3198       nil)
3199      ;; The user did a `C-g' while prompting for number of articles,
3200      ;; so we exit this group.
3201      ((eq did-select 'quit)
3202       (and (eq major-mode 'gnus-summary-mode)
3203            (not (equal (current-buffer) kill-buffer))
3204            (kill-buffer (current-buffer)))
3205       (when kill-buffer
3206         (gnus-kill-or-deaden-summary kill-buffer))
3207       (if (not quit-config)
3208           (progn
3209             (set-buffer gnus-group-buffer)
3210             (gnus-group-jump-to-group group)
3211             (gnus-group-next-unread-group 1)
3212             (gnus-configure-windows 'group 'force))
3213         (gnus-handle-ephemeral-exit quit-config))
3214       ;; Finally signal the quit.
3215       (signal 'quit nil))
3216      ;; The group was successfully selected.
3217      (t
3218       (gnus-set-global-variables)
3219       ;; Save the active value in effect when the group was entered.
3220       (setq gnus-newsgroup-active
3221             (gnus-copy-sequence
3222              (gnus-active gnus-newsgroup-name)))
3223       ;; You can change the summary buffer in some way with this hook.
3224       (gnus-run-hooks 'gnus-select-group-hook)
3225       (gnus-update-format-specifications
3226        nil 'summary 'summary-mode 'summary-dummy)
3227       (gnus-update-summary-mark-positions)
3228       ;; Do score processing.
3229       (when gnus-use-scoring
3230         (gnus-possibly-score-headers))
3231       ;; Check whether to fill in the gaps in the threads.
3232       (when gnus-build-sparse-threads
3233         (gnus-build-sparse-threads))
3234       ;; Find the initial limit.
3235       (if gnus-show-threads
3236           (if show-all
3237               (let ((gnus-newsgroup-dormant nil))
3238                 (gnus-summary-initial-limit show-all))
3239             (gnus-summary-initial-limit show-all))
3240         ;; When untreaded, all articles are always shown.
3241         (setq gnus-newsgroup-limit
3242               (mapcar
3243                (lambda (header) (mail-header-number header))
3244                gnus-newsgroup-headers)))
3245       ;; Generate the summary buffer.
3246       (unless no-display
3247         (gnus-summary-prepare))
3248       (when gnus-use-trees
3249         (gnus-tree-open group)
3250         (setq gnus-summary-highlight-line-function
3251               'gnus-tree-highlight-article))
3252       ;; If the summary buffer is empty, but there are some low-scored
3253       ;; articles or some excluded dormants, we include these in the
3254       ;; buffer.
3255       (when (and (zerop (buffer-size))
3256                  (not no-display))
3257         (cond (gnus-newsgroup-dormant
3258                (gnus-summary-limit-include-dormant))
3259               ((and gnus-newsgroup-scored show-all)
3260                (gnus-summary-limit-include-expunged t))))
3261       ;; Function `gnus-apply-kill-file' must be called in this hook.
3262       (gnus-run-hooks 'gnus-apply-kill-hook)
3263       (if (and (zerop (buffer-size))
3264                (not no-display))
3265           (progn
3266             ;; This newsgroup is empty.
3267             (gnus-summary-catchup-and-exit nil t)
3268             (gnus-message 6 "No unread news")
3269             (when kill-buffer
3270               (gnus-kill-or-deaden-summary kill-buffer))
3271             ;; Return nil from this function.
3272             nil)
3273         ;; Hide conversation thread subtrees.  We cannot do this in
3274         ;; gnus-summary-prepare-hook since kill processing may not
3275         ;; work with hidden articles.
3276         (gnus-summary-maybe-hide-threads)
3277         (when kill-buffer
3278           (gnus-kill-or-deaden-summary kill-buffer))
3279         (gnus-summary-auto-select-subject)
3280         ;; Show first unread article if requested.
3281         (if (and (not no-article)
3282                  (not no-display)
3283                  gnus-newsgroup-unreads
3284                  gnus-auto-select-first)
3285             (progn
3286               (gnus-configure-windows 'summary)
3287               (gnus-summary-goto-article (gnus-summary-article-number)))
3288           ;; Don't select any articles.
3289           (gnus-summary-position-point)
3290           (gnus-configure-windows 'summary 'force)
3291           (gnus-set-mode-line 'summary))
3292         (when (get-buffer-window gnus-group-buffer t)
3293           ;; Gotta use windows, because recenter does weird stuff if
3294           ;; the current buffer ain't the displayed window.
3295           (let ((owin (selected-window)))
3296             (select-window (get-buffer-window gnus-group-buffer t))
3297             (when (gnus-group-goto-group group)
3298               (recenter))
3299             (select-window owin)))
3300         ;; Mark this buffer as "prepared".
3301         (setq gnus-newsgroup-prepared t)
3302         (gnus-run-hooks 'gnus-summary-prepared-hook)
3303         t)))))
3304
3305 (defun gnus-summary-auto-select-subject ()
3306   "Select the subject line on initial group entry."
3307   (goto-char (point-min))
3308   (cond
3309    ((eq gnus-auto-select-subject 'best)
3310     (gnus-summary-best-unread-subject))
3311    ((eq gnus-auto-select-subject 'unread)
3312     (gnus-summary-first-unread-subject))
3313    ((eq gnus-auto-select-subject 'unseen)
3314     (gnus-summary-first-unseen-subject))
3315    ((eq gnus-auto-select-subject 'first)
3316     ;; Do nothing.
3317     )
3318    ((gnus-functionp gnus-auto-select-subject)
3319     (funcall gnus-auto-select-subject))))
3320
3321 (defun gnus-summary-prepare ()
3322   "Generate the summary buffer."
3323   (interactive)
3324   (let ((buffer-read-only nil))
3325     (erase-buffer)
3326     (setq gnus-newsgroup-data nil
3327           gnus-newsgroup-data-reverse nil)
3328     (gnus-run-hooks 'gnus-summary-generate-hook)
3329     ;; Generate the buffer, either with threads or without.
3330     (when gnus-newsgroup-headers
3331       (gnus-summary-prepare-threads
3332        (if gnus-show-threads
3333            (gnus-sort-gathered-threads
3334             (funcall gnus-summary-thread-gathering-function
3335                      (gnus-sort-threads
3336                       (gnus-cut-threads (gnus-make-threads)))))
3337          ;; Unthreaded display.
3338          (gnus-sort-articles gnus-newsgroup-headers))))
3339     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3340     ;; Call hooks for modifying summary buffer.
3341     (goto-char (point-min))
3342     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3343
3344 (defsubst gnus-general-simplify-subject (subject)
3345   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3346   (setq subject
3347         (cond
3348          ;; Truncate the subject.
3349          (gnus-simplify-subject-functions
3350           (gnus-map-function gnus-simplify-subject-functions subject))
3351          ((numberp gnus-summary-gather-subject-limit)
3352           (setq subject (gnus-simplify-subject-re subject))
3353           (if (> (length subject) gnus-summary-gather-subject-limit)
3354               (substring subject 0 gnus-summary-gather-subject-limit)
3355             subject))
3356          ;; Fuzzily simplify it.
3357          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3358           (gnus-simplify-subject-fuzzy subject))
3359          ;; Just remove the leading "Re:".
3360          (t
3361           (gnus-simplify-subject-re subject))))
3362
3363   (if (and gnus-summary-gather-exclude-subject
3364            (string-match gnus-summary-gather-exclude-subject subject))
3365       nil                         ; This article shouldn't be gathered
3366     subject))
3367
3368 (defun gnus-summary-simplify-subject-query ()
3369   "Query where the respool algorithm would put this article."
3370   (interactive)
3371   (gnus-summary-select-article)
3372   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3373
3374 (defun gnus-gather-threads-by-subject (threads)
3375   "Gather threads by looking at Subject headers."
3376   (if (not gnus-summary-make-false-root)
3377       threads
3378     (let ((hashtb (gnus-make-hashtable 1024))
3379           (prev threads)
3380           (result threads)
3381           subject hthread whole-subject)
3382       (while threads
3383         (setq subject (gnus-general-simplify-subject
3384                        (setq whole-subject (mail-header-subject
3385                                             (caar threads)))))
3386         (when subject
3387           (if (setq hthread (gnus-gethash subject hashtb))
3388               (progn
3389                 ;; We enter a dummy root into the thread, if we
3390                 ;; haven't done that already.
3391                 (unless (stringp (caar hthread))
3392                   (setcar hthread (list whole-subject (car hthread))))
3393                 ;; We add this new gathered thread to this gathered
3394                 ;; thread.
3395                 (setcdr (car hthread)
3396                         (nconc (cdar hthread) (list (car threads))))
3397                 ;; Remove it from the list of threads.
3398                 (setcdr prev (cdr threads))
3399                 (setq threads prev))
3400             ;; Enter this thread into the hash table.
3401             (gnus-sethash subject threads hashtb)))
3402         (setq prev threads)
3403         (setq threads (cdr threads)))
3404       result)))
3405
3406 (defun gnus-gather-threads-by-references (threads)
3407   "Gather threads by looking at References headers."
3408   (let ((idhashtb (gnus-make-hashtable 1024))
3409         (thhashtb (gnus-make-hashtable 1024))
3410         (prev threads)
3411         (result threads)
3412         ids references id gthread gid entered ref)
3413     (while threads
3414       (when (setq references (mail-header-references (caar threads)))
3415         (setq id (mail-header-id (caar threads))
3416               ids (gnus-split-references references)
3417               entered nil)
3418         (while (setq ref (pop ids))
3419           (setq ids (delete ref ids))
3420           (if (not (setq gid (gnus-gethash ref idhashtb)))
3421               (progn
3422                 (gnus-sethash ref id idhashtb)
3423                 (gnus-sethash id threads thhashtb))
3424             (setq gthread (gnus-gethash gid thhashtb))
3425             (unless entered
3426               ;; We enter a dummy root into the thread, if we
3427               ;; haven't done that already.
3428               (unless (stringp (caar gthread))
3429                 (setcar gthread (list (mail-header-subject (caar gthread))
3430                                       (car gthread))))
3431               ;; We add this new gathered thread to this gathered
3432               ;; thread.
3433               (setcdr (car gthread)
3434                       (nconc (cdar gthread) (list (car threads)))))
3435             ;; Add it into the thread hash table.
3436             (gnus-sethash id gthread thhashtb)
3437             (setq entered t)
3438             ;; Remove it from the list of threads.
3439             (setcdr prev (cdr threads))
3440             (setq threads prev))))
3441       (setq prev threads)
3442       (setq threads (cdr threads)))
3443     result))
3444
3445 (defun gnus-sort-gathered-threads (threads)
3446   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3447   (let ((result threads))
3448     (while threads
3449       (when (stringp (caar threads))
3450         (setcdr (car threads)
3451                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3452       (setq threads (cdr threads)))
3453     result))
3454
3455 (defun gnus-thread-loop-p (root thread)
3456   "Say whether ROOT is in THREAD."
3457   (let ((stack (list thread))
3458         (infloop 0)
3459         th)
3460     (while (setq thread (pop stack))
3461       (setq th (cdr thread))
3462       (while (and th
3463                   (not (eq (caar th) root)))
3464         (pop th))
3465       (if th
3466           ;; We have found a loop.
3467           (let (ref-dep)
3468             (setcdr thread (delq (car th) (cdr thread)))
3469             (if (boundp (setq ref-dep (intern "none"
3470                                               gnus-newsgroup-dependencies)))
3471                 (setcdr (symbol-value ref-dep)
3472                         (nconc (cdr (symbol-value ref-dep))
3473                                (list (car th))))
3474               (set ref-dep (list nil (car th))))
3475             (setq infloop 1
3476                   stack nil))
3477         ;; Push all the subthreads onto the stack.
3478         (push (cdr thread) stack)))
3479     infloop))
3480
3481 (defun gnus-make-threads ()
3482   "Go through the dependency hashtb and find the roots.  Return all threads."
3483   (let (threads)
3484     (while (catch 'infloop
3485              (mapatoms
3486               (lambda (refs)
3487                 ;; Deal with self-referencing References loops.
3488                 (when (and (car (symbol-value refs))
3489                            (not (zerop
3490                                  (apply
3491                                   '+
3492                                   (mapcar
3493                                    (lambda (thread)
3494                                      (gnus-thread-loop-p
3495                                       (car (symbol-value refs)) thread))
3496                                    (cdr (symbol-value refs)))))))
3497                   (setq threads nil)
3498                   (throw 'infloop t))
3499                 (unless (car (symbol-value refs))
3500              ;; These threads do not refer back to any other articles,
3501                   ;; so they're roots.
3502                   (setq threads (append (cdr (symbol-value refs)) threads))))
3503               gnus-newsgroup-dependencies)))
3504     threads))
3505
3506 ;; Build the thread tree.
3507 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3508   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3509
3510 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3511 if it was already present.
3512
3513 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3514 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3515 Message-IDs will be renamed be renamed to a unique Message-ID before
3516 being entered.
3517
3518 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3519   (let* ((id (mail-header-id header))
3520          (id-dep (and id (intern id dependencies)))
3521          ref ref-dep ref-header)
3522     ;; Enter this `header' in the `dependencies' table.
3523     (cond
3524      ((not id-dep)
3525       (setq header nil))
3526      ;; The first two cases do the normal part: enter a new `header'
3527      ;; in the `dependencies' table.
3528      ((not (boundp id-dep))
3529       (set id-dep (list header)))
3530      ((null (car (symbol-value id-dep)))
3531       (setcar (symbol-value id-dep) header))
3532
3533      ;; From here the `header' was already present in the
3534      ;; `dependencies' table.
3535      (force-new
3536       ;; Overrides an existing entry;
3537       ;; just set the header part of the entry.
3538       (setcar (symbol-value id-dep) header))
3539
3540      ;; Renames the existing `header' to a unique Message-ID.
3541      ((not gnus-summary-ignore-duplicates)
3542       ;; An article with this Message-ID has already been seen.
3543       ;; We rename the Message-ID.
3544       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3545            (list header))
3546       (mail-header-set-id header id))
3547
3548      ;; The last case ignores an existing entry, except it adds any
3549      ;; additional Xrefs (in case the two articles came from different
3550      ;; servers.
3551      ;; Also sets `header' to `nil' meaning that the `dependencies'
3552      ;; table was *not* modified.
3553      (t
3554       (mail-header-set-xref
3555        (car (symbol-value id-dep))
3556        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3557                    "")
3558                (or (mail-header-xref header) "")))
3559       (setq header nil)))
3560
3561     (when header
3562       ;; First check if that we are not creating a References loop.
3563       (setq ref (gnus-parent-id (mail-header-references header)))
3564       (while (and ref
3565                   (setq ref-dep (intern-soft ref dependencies))
3566                   (boundp ref-dep)
3567                   (setq ref-header (car (symbol-value ref-dep))))
3568         (if (string= id ref)
3569             ;; Yuk!  This is a reference loop.  Make the article be a
3570             ;; root article.
3571             (progn
3572               (mail-header-set-references (car (symbol-value id-dep)) "none")
3573               (setq ref nil))
3574           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3575       (setq ref (gnus-parent-id (mail-header-references header)))
3576       (setq ref-dep (intern (or ref "none") dependencies))
3577       (if (boundp ref-dep)
3578           (setcdr (symbol-value ref-dep)
3579                   (nconc (cdr (symbol-value ref-dep))
3580                          (list (symbol-value id-dep))))
3581         (set ref-dep (list nil (symbol-value id-dep)))))
3582     header))
3583
3584 (defun gnus-build-sparse-threads ()
3585   (let ((headers gnus-newsgroup-headers)
3586         (mail-parse-charset gnus-newsgroup-charset)
3587         (gnus-summary-ignore-duplicates t)
3588         header references generation relations
3589         subject child end new-child date)
3590     ;; First we create an alist of generations/relations, where
3591     ;; generations is how much we trust the relation, and the relation
3592     ;; is parent/child.
3593     (gnus-message 7 "Making sparse threads...")
3594     (save-excursion
3595       (nnheader-set-temp-buffer " *gnus sparse threads*")
3596       (while (setq header (pop headers))
3597         (when (and (setq references (mail-header-references header))
3598                    (not (string= references "")))
3599           (insert references)
3600           (setq child (mail-header-id header)
3601                 subject (mail-header-subject header)
3602                 date (mail-header-date header)
3603                 generation 0)
3604           (while (search-backward ">" nil t)
3605             (setq end (1+ (point)))
3606             (when (search-backward "<" nil t)
3607               (setq new-child (buffer-substring (point) end))
3608               (push (list (incf generation)
3609                           child (setq child new-child)
3610                           subject date)
3611                     relations)))
3612           (when child
3613             (push (list (1+ generation) child nil subject) relations))
3614           (erase-buffer)))
3615       (kill-buffer (current-buffer)))
3616     ;; Sort over trustworthiness.
3617     (mapcar
3618      (lambda (relation)
3619        (when (gnus-dependencies-add-header
3620               (make-full-mail-header
3621                gnus-reffed-article-number
3622                (nth 3 relation) "" (or (nth 4 relation) "")
3623                (nth 1 relation)
3624                (or (nth 2 relation) "") 0 0 "")
3625               gnus-newsgroup-dependencies nil)
3626          (push gnus-reffed-article-number gnus-newsgroup-limit)
3627          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3628          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3629                gnus-newsgroup-reads)
3630          (decf gnus-reffed-article-number)))
3631      (sort relations 'car-less-than-car))
3632     (gnus-message 7 "Making sparse threads...done")))
3633
3634 (defun gnus-build-old-threads ()
3635   ;; Look at all the articles that refer back to old articles, and
3636   ;; fetch the headers for the articles that aren't there.  This will
3637   ;; build complete threads - if the roots haven't been expired by the
3638   ;; server, that is.
3639   (let ((mail-parse-charset gnus-newsgroup-charset)
3640         id heads)
3641     (mapatoms
3642      (lambda (refs)
3643        (when (not (car (symbol-value refs)))
3644          (setq heads (cdr (symbol-value refs)))
3645          (while heads
3646            (if (memq (mail-header-number (caar heads))
3647                      gnus-newsgroup-dormant)
3648                (setq heads (cdr heads))
3649              (setq id (symbol-name refs))
3650              (while (and (setq id (gnus-build-get-header id))
3651                          (not (car (gnus-id-to-thread id)))))
3652              (setq heads nil)))))
3653      gnus-newsgroup-dependencies)))
3654
3655 ;; This function has to be called with point after the article number
3656 ;; on the beginning of the line.
3657 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3658   (let ((eol (gnus-point-at-eol))
3659         (buffer (current-buffer))
3660         header)
3661
3662     ;; overview: [num subject from date id refs chars lines misc]
3663     (unwind-protect
3664         (progn
3665           (narrow-to-region (point) eol)
3666           (unless (eobp)
3667             (forward-char))
3668
3669           (setq header
3670                 (make-full-mail-header
3671                  number                 ; number
3672                  (funcall gnus-decode-encoded-word-function
3673                           (nnheader-nov-field)) ; subject
3674                  (funcall gnus-decode-encoded-word-function
3675                           (nnheader-nov-field)) ; from
3676                  (nnheader-nov-field)   ; date
3677                  (nnheader-nov-read-message-id) ; id
3678                  (nnheader-nov-field)   ; refs
3679                  (nnheader-nov-read-integer) ; chars
3680                  (nnheader-nov-read-integer) ; lines
3681                  (unless (eobp)
3682                    (if (looking-at "Xref: ")
3683                        (goto-char (match-end 0)))
3684                    (nnheader-nov-field)) ; Xref
3685                  (nnheader-nov-parse-extra)))) ; extra
3686
3687       (widen))
3688
3689     (when gnus-alter-header-function
3690       (funcall gnus-alter-header-function header))
3691     (gnus-dependencies-add-header header dependencies force-new)))
3692
3693 (defun gnus-build-get-header (id)
3694   "Look through the buffer of NOV lines and find the header to ID.
3695 Enter this line into the dependencies hash table, and return
3696 the id of the parent article (if any)."
3697   (let ((deps gnus-newsgroup-dependencies)
3698         found header)
3699     (prog1
3700         (save-excursion
3701           (set-buffer nntp-server-buffer)
3702           (let ((case-fold-search nil))
3703             (goto-char (point-min))
3704             (while (and (not found)
3705                         (search-forward id nil t))
3706               (beginning-of-line)
3707               (setq found (looking-at
3708                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3709                                    (regexp-quote id))))
3710               (or found (beginning-of-line 2)))
3711             (when found
3712               (beginning-of-line)
3713               (and
3714                (setq header (gnus-nov-parse-line
3715                              (read (current-buffer)) deps))
3716                (gnus-parent-id (mail-header-references header))))))
3717       (when header
3718         (let ((number (mail-header-number header)))
3719           (push number gnus-newsgroup-limit)
3720           (push header gnus-newsgroup-headers)
3721           (if (memq number gnus-newsgroup-unselected)
3722               (progn
3723                 (push number gnus-newsgroup-unreads)
3724                 (setq gnus-newsgroup-unselected
3725                       (delq number gnus-newsgroup-unselected)))
3726             (push number gnus-newsgroup-ancient)))))))
3727
3728 (defun gnus-build-all-threads ()
3729   "Read all the headers."
3730   (let ((gnus-summary-ignore-duplicates t)
3731         (mail-parse-charset gnus-newsgroup-charset)
3732         (dependencies gnus-newsgroup-dependencies)
3733         header article)
3734     (save-excursion
3735       (set-buffer nntp-server-buffer)
3736       (let ((case-fold-search nil))
3737         (goto-char (point-min))
3738         (while (not (eobp))
3739           (ignore-errors
3740             (setq article (read (current-buffer))
3741                   header (gnus-nov-parse-line article dependencies)))
3742           (when header
3743             (save-excursion
3744               (set-buffer gnus-summary-buffer)
3745               (push header gnus-newsgroup-headers)
3746               (if (memq (setq article (mail-header-number header))
3747                         gnus-newsgroup-unselected)
3748                   (progn
3749                     (push article gnus-newsgroup-unreads)
3750                     (setq gnus-newsgroup-unselected
3751                           (delq article gnus-newsgroup-unselected)))
3752                 (push article gnus-newsgroup-ancient)))
3753             (forward-line 1)))))))
3754
3755 (defun gnus-summary-update-article-line (article header)
3756   "Update the line for ARTICLE using HEADERS."
3757   (let* ((id (mail-header-id header))
3758          (thread (gnus-id-to-thread id)))
3759     (unless thread
3760       (error "Article in no thread"))
3761     ;; Update the thread.
3762     (setcar thread header)
3763     (gnus-summary-goto-subject article)
3764     (let* ((datal (gnus-data-find-list article))
3765            (data (car datal))
3766            (length (when (cdr datal)
3767                      (- (gnus-data-pos data)
3768                         (gnus-data-pos (cadr datal)))))
3769            (buffer-read-only nil)
3770            (level (gnus-summary-thread-level)))
3771       (gnus-delete-line)
3772       (gnus-summary-insert-line
3773        header level nil (gnus-article-mark article)
3774        (memq article gnus-newsgroup-replied)
3775        (memq article gnus-newsgroup-expirable)
3776        ;; Only insert the Subject string when it's different
3777        ;; from the previous Subject string.
3778        (if (and
3779             gnus-show-threads
3780             (gnus-subject-equal
3781              (condition-case ()
3782                  (mail-header-subject
3783                   (gnus-data-header
3784                    (cadr
3785                     (gnus-data-find-list
3786                      article
3787                      (gnus-data-list t)))))
3788                ;; Error on the side of excessive subjects.
3789                (error ""))
3790              (mail-header-subject header)))
3791            ""
3792          (mail-header-subject header))
3793        nil (cdr (assq article gnus-newsgroup-scored))
3794        (memq article gnus-newsgroup-processable))
3795       (when length
3796         (gnus-data-update-list
3797          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3798
3799 (defun gnus-summary-update-article (article &optional iheader)
3800   "Update ARTICLE in the summary buffer."
3801   (set-buffer gnus-summary-buffer)
3802   (let* ((header (gnus-summary-article-header article))
3803          (id (mail-header-id header))
3804          (data (gnus-data-find article))
3805          (thread (gnus-id-to-thread id))
3806          (references (mail-header-references header))
3807          (parent
3808           (gnus-id-to-thread
3809            (or (gnus-parent-id
3810                 (when (and references
3811                            (not (equal "" references)))
3812                   references))
3813                "none")))
3814          (buffer-read-only nil)
3815          (old (car thread)))
3816     (when thread
3817       (unless iheader
3818         (setcar thread nil)
3819         (when parent
3820           (delq thread parent)))
3821       (if (gnus-summary-insert-subject id header)
3822        ;; Set the (possibly) new article number in the data structure.
3823           (gnus-data-set-number data (gnus-id-to-article id))
3824         (setcar thread old)
3825         nil))))
3826
3827 (defun gnus-rebuild-thread (id &optional line)
3828   "Rebuild the thread containing ID.
3829 If LINE, insert the rebuilt thread starting on line LINE."
3830   (let ((buffer-read-only nil)
3831         old-pos current thread data)
3832     (if (not gnus-show-threads)
3833         (setq thread (list (car (gnus-id-to-thread id))))
3834       ;; Get the thread this article is part of.
3835       (setq thread (gnus-remove-thread id)))
3836     (setq old-pos (gnus-point-at-bol))
3837     (setq current (save-excursion
3838                     (and (re-search-backward "[\r\n]" nil t)
3839                          (gnus-summary-article-number))))
3840     ;; If this is a gathered thread, we have to go some re-gathering.
3841     (when (stringp (car thread))
3842       (let ((subject (car thread))
3843             roots thr)
3844         (setq thread (cdr thread))
3845         (while thread
3846           (unless (memq (setq thr (gnus-id-to-thread
3847                                    (gnus-root-id
3848                                     (mail-header-id (caar thread)))))
3849                         roots)
3850             (push thr roots))
3851           (setq thread (cdr thread)))
3852         ;; We now have all (unique) roots.
3853         (if (= (length roots) 1)
3854             ;; All the loose roots are now one solid root.
3855             (setq thread (car roots))
3856           (setq thread (cons subject (gnus-sort-threads roots))))))
3857     (let (threads)
3858       ;; We then insert this thread into the summary buffer.
3859       (when line
3860         (goto-char (point-min))
3861         (forward-line (1- line)))
3862       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3863         (if gnus-show-threads
3864             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3865           (gnus-summary-prepare-unthreaded thread))
3866         (setq data (nreverse gnus-newsgroup-data))
3867         (setq threads gnus-newsgroup-threads))
3868       ;; We splice the new data into the data structure.
3869       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3870       ;;!!! then we want to insert at the beginning of the buffer.
3871       ;;!!! That happens to be true with Gnus now, but that may
3872       ;;!!! change in the future.  Perhaps.
3873       (gnus-data-enter-list
3874        (if line nil current) data (- (point) old-pos))
3875       (setq gnus-newsgroup-threads
3876             (nconc threads gnus-newsgroup-threads))
3877       (gnus-data-compute-positions))))
3878
3879 (defun gnus-number-to-header (number)
3880   "Return the header for article NUMBER."
3881   (let ((headers gnus-newsgroup-headers))
3882     (while (and headers
3883                 (not (= number (mail-header-number (car headers)))))
3884       (pop headers))
3885     (when headers
3886       (car headers))))
3887
3888 (defun gnus-parent-headers (in-headers &optional generation)
3889   "Return the headers of the GENERATIONeth parent of HEADERS."
3890   (unless generation
3891     (setq generation 1))
3892   (let ((parent t)
3893         (headers in-headers)
3894         references)
3895     (while (and parent
3896                 (not (zerop generation))
3897                 (setq references (mail-header-references headers)))
3898       (setq headers (if (and references
3899                              (setq parent (gnus-parent-id references)))
3900                         (car (gnus-id-to-thread parent))
3901                       nil))
3902       (decf generation))
3903     (and (not (eq headers in-headers))
3904          headers)))
3905
3906 (defun gnus-id-to-thread (id)
3907   "Return the (sub-)thread where ID appears."
3908   (gnus-gethash id gnus-newsgroup-dependencies))
3909
3910 (defun gnus-id-to-article (id)
3911   "Return the article number of ID."
3912   (let ((thread (gnus-id-to-thread id)))
3913     (when (and thread
3914                (car thread))
3915       (mail-header-number (car thread)))))
3916
3917 (defun gnus-id-to-header (id)
3918   "Return the article headers of ID."
3919   (car (gnus-id-to-thread id)))
3920
3921 (defun gnus-article-displayed-root-p (article)
3922   "Say whether ARTICLE is a root(ish) article."
3923   (let ((level (gnus-summary-thread-level article))
3924         (refs (mail-header-references  (gnus-summary-article-header article)))
3925         particle)
3926     (cond
3927      ((null level) nil)
3928      ((zerop level) t)
3929      ((null refs) t)
3930      ((null (gnus-parent-id refs)) t)
3931      ((and (= 1 level)
3932            (null (setq particle (gnus-id-to-article
3933                                  (gnus-parent-id refs))))
3934            (null (gnus-summary-thread-level particle)))))))
3935
3936 (defun gnus-root-id (id)
3937   "Return the id of the root of the thread where ID appears."
3938   (let (last-id prev)
3939     (while (and id (setq prev (car (gnus-id-to-thread id))))
3940       (setq last-id id
3941             id (gnus-parent-id (mail-header-references prev))))
3942     last-id))
3943
3944 (defun gnus-articles-in-thread (thread)
3945   "Return the list of articles in THREAD."
3946   (cons (mail-header-number (car thread))
3947         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3948
3949 (defun gnus-remove-thread (id &optional dont-remove)
3950   "Remove the thread that has ID in it."
3951   (let (headers thread last-id)
3952     ;; First go up in this thread until we find the root.
3953     (setq last-id (gnus-root-id id)
3954           headers (message-flatten-list (gnus-id-to-thread last-id)))
3955     ;; We have now found the real root of this thread.  It might have
3956     ;; been gathered into some loose thread, so we have to search
3957     ;; through the threads to find the thread we wanted.
3958     (let ((threads gnus-newsgroup-threads)
3959           sub)
3960       (while threads
3961         (setq sub (car threads))
3962         (if (stringp (car sub))
3963             ;; This is a gathered thread, so we look at the roots
3964             ;; below it to find whether this article is in this
3965             ;; gathered root.
3966             (progn
3967               (setq sub (cdr sub))
3968               (while sub
3969                 (when (member (caar sub) headers)
3970                   (setq thread (car threads)
3971                         threads nil
3972                         sub nil))
3973                 (setq sub (cdr sub))))
3974           ;; It's an ordinary thread, so we check it.
3975           (when (eq (car sub) (car headers))
3976             (setq thread sub
3977                   threads nil)))
3978         (setq threads (cdr threads)))
3979       ;; If this article is in no thread, then it's a root.
3980       (if thread
3981           (unless dont-remove
3982             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3983         (setq thread (gnus-id-to-thread last-id)))
3984       (when thread
3985         (prog1
3986             thread                      ; We return this thread.
3987           (unless dont-remove
3988             (if (stringp (car thread))
3989                 (progn
3990                   ;; If we use dummy roots, then we have to remove the
3991                   ;; dummy root as well.
3992                   (when (eq gnus-summary-make-false-root 'dummy)
3993                     ;; We go to the dummy root by going to
3994                     ;; the first sub-"thread", and then one line up.
3995                     (gnus-summary-goto-article
3996                      (mail-header-number (caadr thread)))
3997                     (forward-line -1)
3998                     (gnus-delete-line)
3999                     (gnus-data-compute-positions))
4000                   (setq thread (cdr thread))
4001                   (while thread
4002                     (gnus-remove-thread-1 (car thread))
4003                     (setq thread (cdr thread))))
4004               (gnus-remove-thread-1 thread))))))))
4005
4006 (defun gnus-remove-thread-1 (thread)
4007   "Remove the thread THREAD recursively."
4008   (let ((number (mail-header-number (pop thread)))
4009         d)
4010     (setq thread (reverse thread))
4011     (while thread
4012       (gnus-remove-thread-1 (pop thread)))
4013     (when (setq d (gnus-data-find number))
4014       (goto-char (gnus-data-pos d))
4015       (gnus-summary-show-thread)
4016       (gnus-data-remove
4017        number
4018        (- (gnus-point-at-bol)
4019           (prog1
4020               (1+ (gnus-point-at-eol))
4021             (gnus-delete-line)))))))
4022
4023 (defun gnus-sort-threads-1 (threads func)
4024   (sort (mapcar (lambda (thread)
4025                   (cons (car thread)
4026                         (and (cdr thread)
4027                              (gnus-sort-threads-1 (cdr thread) func))))
4028                 threads) func))
4029
4030 (defun gnus-sort-threads (threads)
4031   "Sort THREADS."
4032   (if (not gnus-thread-sort-functions)
4033       threads
4034     (gnus-message 8 "Sorting threads...")
4035     (prog1
4036         (gnus-sort-threads-1
4037          threads
4038          (gnus-make-sort-function gnus-thread-sort-functions))
4039       (gnus-message 8 "Sorting threads...done"))))
4040
4041 (defun gnus-sort-articles (articles)
4042   "Sort ARTICLES."
4043   (when gnus-article-sort-functions
4044     (gnus-message 7 "Sorting articles...")
4045     (prog1
4046         (setq gnus-newsgroup-headers
4047               (sort articles (gnus-make-sort-function
4048                               gnus-article-sort-functions)))
4049       (gnus-message 7 "Sorting articles...done"))))
4050
4051 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4052 (defmacro gnus-thread-header (thread)
4053   "Return header of first article in THREAD.
4054 Note that THREAD must never, ever be anything else than a variable -
4055 using some other form will lead to serious barfage."
4056   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4057   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4058   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4059         (vector thread) 2))
4060
4061 (defsubst gnus-article-sort-by-number (h1 h2)
4062   "Sort articles by article number."
4063   (< (mail-header-number h1)
4064      (mail-header-number h2)))
4065
4066 (defun gnus-thread-sort-by-number (h1 h2)
4067   "Sort threads by root article number."
4068   (gnus-article-sort-by-number
4069    (gnus-thread-header h1) (gnus-thread-header h2)))
4070
4071 (defsubst gnus-article-sort-by-lines (h1 h2)
4072   "Sort articles by article Lines header."
4073   (< (mail-header-lines h1)
4074      (mail-header-lines h2)))
4075
4076 (defun gnus-thread-sort-by-lines (h1 h2)
4077   "Sort threads by root article Lines header."
4078   (gnus-article-sort-by-lines
4079    (gnus-thread-header h1) (gnus-thread-header h2)))
4080
4081 (defsubst gnus-article-sort-by-chars (h1 h2)
4082   "Sort articles by octet length."
4083   (< (mail-header-chars h1)
4084      (mail-header-chars h2)))
4085
4086 (defun gnus-thread-sort-by-chars (h1 h2)
4087   "Sort threads by root article octet length."
4088   (gnus-article-sort-by-chars
4089    (gnus-thread-header h1) (gnus-thread-header h2)))
4090
4091 (defsubst gnus-article-sort-by-author (h1 h2)
4092   "Sort articles by root author."
4093   (string-lessp
4094    (let ((extract (funcall
4095                    gnus-extract-address-components
4096                    (mail-header-from h1))))
4097      (or (car extract) (cadr extract) ""))
4098    (let ((extract (funcall
4099                    gnus-extract-address-components
4100                    (mail-header-from h2))))
4101      (or (car extract) (cadr extract) ""))))
4102
4103 (defun gnus-thread-sort-by-author (h1 h2)
4104   "Sort threads by root author."
4105   (gnus-article-sort-by-author
4106    (gnus-thread-header h1)  (gnus-thread-header h2)))
4107
4108 (defsubst gnus-article-sort-by-subject (h1 h2)
4109   "Sort articles by root subject."
4110   (string-lessp
4111    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4112    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4113
4114 (defun gnus-thread-sort-by-subject (h1 h2)
4115   "Sort threads by root subject."
4116   (gnus-article-sort-by-subject
4117    (gnus-thread-header h1) (gnus-thread-header h2)))
4118
4119 (defsubst gnus-article-sort-by-date (h1 h2)
4120   "Sort articles by root article date."
4121   (time-less-p
4122    (gnus-date-get-time (mail-header-date h1))
4123    (gnus-date-get-time (mail-header-date h2))))
4124
4125 (defun gnus-thread-sort-by-date (h1 h2)
4126   "Sort threads by root article date."
4127   (gnus-article-sort-by-date
4128    (gnus-thread-header h1) (gnus-thread-header h2)))
4129
4130 (defsubst gnus-article-sort-by-score (h1 h2)
4131   "Sort articles by root article score.
4132 Unscored articles will be counted as having a score of zero."
4133   (> (or (cdr (assq (mail-header-number h1)
4134                     gnus-newsgroup-scored))
4135          gnus-summary-default-score 0)
4136      (or (cdr (assq (mail-header-number h2)
4137                     gnus-newsgroup-scored))
4138          gnus-summary-default-score 0)))
4139
4140 (defun gnus-thread-sort-by-score (h1 h2)
4141   "Sort threads by root article score."
4142   (gnus-article-sort-by-score
4143    (gnus-thread-header h1) (gnus-thread-header h2)))
4144
4145 (defun gnus-thread-sort-by-total-score (h1 h2)
4146   "Sort threads by the sum of all scores in the thread.
4147 Unscored articles will be counted as having a score of zero."
4148   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4149
4150 (defun gnus-thread-total-score (thread)
4151   ;; This function find the total score of THREAD.
4152   (cond ((null thread)
4153          0)
4154         ((consp thread)
4155          (if (stringp (car thread))
4156              (apply gnus-thread-score-function 0
4157                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4158            (gnus-thread-total-score-1 thread)))
4159         (t
4160          (gnus-thread-total-score-1 (list thread)))))
4161
4162 (defun gnus-thread-total-score-1 (root)
4163   ;; This function find the total score of the thread below ROOT.
4164   (setq root (car root))
4165   (apply gnus-thread-score-function
4166          (or (append
4167               (mapcar 'gnus-thread-total-score
4168                       (cdr (gnus-id-to-thread (mail-header-id root))))
4169               (when (> (mail-header-number root) 0)
4170                 (list (or (cdr (assq (mail-header-number root)
4171                                      gnus-newsgroup-scored))
4172                           gnus-summary-default-score 0))))
4173              (list gnus-summary-default-score)
4174              '(0))))
4175
4176 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4177 (defvar gnus-tmp-prev-subject nil)
4178 (defvar gnus-tmp-false-parent nil)
4179 (defvar gnus-tmp-root-expunged nil)
4180 (defvar gnus-tmp-dummy-line nil)
4181
4182 (eval-when-compile (defvar gnus-tmp-header))
4183 (defun gnus-extra-header (type &optional header)
4184   "Return the extra header of TYPE."
4185   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4186       ""))
4187
4188 (defvar gnus-tmp-thread-tree-header-string "")
4189
4190 (defvar gnus-sum-thread-tree-root "> "
4191   "With %B spec, used for the root of a thread.
4192 If nil, use subject instead.")
4193 (defvar gnus-sum-thread-tree-single-indent ""
4194   "With %B spec, used for a thread with just one message.
4195 If nil, use subject instead.")
4196 (defvar gnus-sum-thread-tree-vertical "| "
4197   "With %B spec, used for drawing a vertical line.")
4198 (defvar gnus-sum-thread-tree-indent "  "
4199   "With %B spec, used for indenting.")
4200 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4201   "With %B spec, used for a leaf with brothers.")
4202 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4203   "With %B spec, used for a leaf without brothers.")
4204
4205 (defun gnus-summary-prepare-threads (threads)
4206   "Prepare summary buffer from THREADS and indentation LEVEL.
4207 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4208 or a straight list of headers."
4209   (gnus-message 7 "Generating summary...")
4210
4211   (setq gnus-newsgroup-threads threads)
4212   (beginning-of-line)
4213
4214   (let ((gnus-tmp-level 0)
4215         (default-score (or gnus-summary-default-score 0))
4216         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4217         thread number subject stack state gnus-tmp-gathered beg-match
4218         new-roots gnus-tmp-new-adopts thread-end
4219         gnus-tmp-header gnus-tmp-unread
4220         gnus-tmp-replied gnus-tmp-subject-or-nil
4221         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4222         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4223         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4224         tree-stack)
4225
4226     (setq gnus-tmp-prev-subject nil)
4227
4228     (if (vectorp (car threads))
4229         ;; If this is a straight (sic) list of headers, then a
4230         ;; threaded summary display isn't required, so we just create
4231         ;; an unthreaded one.
4232         (gnus-summary-prepare-unthreaded threads)
4233
4234       ;; Do the threaded display.
4235
4236       (while (or threads stack gnus-tmp-new-adopts new-roots)
4237
4238         (if (and (= gnus-tmp-level 0)
4239                  (or (not stack)
4240                      (= (caar stack) 0))
4241                  (not gnus-tmp-false-parent)
4242                  (or gnus-tmp-new-adopts new-roots))
4243             (if gnus-tmp-new-adopts
4244                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4245                       thread (list (car gnus-tmp-new-adopts))
4246                       gnus-tmp-header (caar thread)
4247                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4248               (when new-roots
4249                 (setq thread (list (car new-roots))
4250                       gnus-tmp-header (caar thread)
4251                       new-roots (cdr new-roots))))
4252
4253           (if threads
4254               ;; If there are some threads, we do them before the
4255               ;; threads on the stack.
4256               (setq thread threads
4257                     gnus-tmp-header (caar thread))
4258             ;; There were no current threads, so we pop something off
4259             ;; the stack.
4260             (setq state (car stack)
4261                   gnus-tmp-level (car state)
4262                   tree-stack (cadr state)
4263                   thread (caddr state)
4264                   stack (cdr stack)
4265                   gnus-tmp-header (caar thread))))
4266
4267         (setq gnus-tmp-false-parent nil)
4268         (setq gnus-tmp-root-expunged nil)
4269         (setq thread-end nil)
4270
4271         (if (stringp gnus-tmp-header)
4272             ;; The header is a dummy root.
4273             (cond
4274              ((eq gnus-summary-make-false-root 'adopt)
4275               ;; We let the first article adopt the rest.
4276               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4277                                                (cddar thread)))
4278               (setq gnus-tmp-gathered
4279                     (nconc (mapcar
4280                             (lambda (h) (mail-header-number (car h)))
4281                             (cddar thread))
4282                            gnus-tmp-gathered))
4283               (setq thread (cons (list (caar thread)
4284                                        (cadar thread))
4285                                  (cdr thread)))
4286               (setq gnus-tmp-level -1
4287                     gnus-tmp-false-parent t))
4288              ((eq gnus-summary-make-false-root 'empty)
4289               ;; We print adopted articles with empty subject fields.
4290               (setq gnus-tmp-gathered
4291                     (nconc (mapcar
4292                             (lambda (h) (mail-header-number (car h)))
4293                             (cddar thread))
4294                            gnus-tmp-gathered))
4295               (setq gnus-tmp-level -1))
4296              ((eq gnus-summary-make-false-root 'dummy)
4297               ;; We remember that we probably want to output a dummy
4298               ;; root.
4299               (setq gnus-tmp-dummy-line gnus-tmp-header)
4300               (setq gnus-tmp-prev-subject gnus-tmp-header))
4301              (t
4302               ;; We do not make a root for the gathered
4303               ;; sub-threads at all.
4304               (setq gnus-tmp-level -1)))
4305
4306           (setq number (mail-header-number gnus-tmp-header)
4307                 subject (mail-header-subject gnus-tmp-header))
4308
4309           (cond
4310            ;; If the thread has changed subject, we might want to make
4311            ;; this subthread into a root.
4312            ((and (null gnus-thread-ignore-subject)
4313                  (not (zerop gnus-tmp-level))
4314                  gnus-tmp-prev-subject
4315                  (not (inline
4316                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4317             (setq new-roots (nconc new-roots (list (car thread)))
4318                   thread-end t
4319                   gnus-tmp-header nil))
4320            ;; If the article lies outside the current limit,
4321            ;; then we do not display it.
4322            ((not (memq number gnus-newsgroup-limit))
4323             (setq gnus-tmp-gathered
4324                   (nconc (mapcar
4325                           (lambda (h) (mail-header-number (car h)))
4326                           (cdar thread))
4327                          gnus-tmp-gathered))
4328             (setq gnus-tmp-new-adopts (if (cdar thread)
4329                                           (append gnus-tmp-new-adopts
4330                                                   (cdar thread))
4331                                         gnus-tmp-new-adopts)
4332                   thread-end t
4333                   gnus-tmp-header nil)
4334             (when (zerop gnus-tmp-level)
4335               (setq gnus-tmp-root-expunged t)))
4336            ;; Perhaps this article is to be marked as read?
4337            ((and gnus-summary-mark-below
4338                  (< (or (cdr (assq number gnus-newsgroup-scored))
4339                         default-score)
4340                     gnus-summary-mark-below)
4341                  ;; Don't touch sparse articles.
4342                  (not (gnus-summary-article-sparse-p number))
4343                  (not (gnus-summary-article-ancient-p number)))
4344             (setq gnus-newsgroup-unreads
4345                   (delq number gnus-newsgroup-unreads))
4346             (if gnus-newsgroup-auto-expire
4347                 (push number gnus-newsgroup-expirable)
4348               (push (cons number gnus-low-score-mark)
4349                     gnus-newsgroup-reads))))
4350
4351           (when gnus-tmp-header
4352             ;; We may have an old dummy line to output before this
4353             ;; article.
4354             (when (and gnus-tmp-dummy-line
4355                        (gnus-subject-equal
4356                         gnus-tmp-dummy-line
4357                         (mail-header-subject gnus-tmp-header)))
4358               (gnus-summary-insert-dummy-line
4359                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4360               (setq gnus-tmp-dummy-line nil))
4361
4362             ;; Compute the mark.
4363             (setq gnus-tmp-unread (gnus-article-mark number))
4364
4365             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4366                                   gnus-tmp-header gnus-tmp-level)
4367                   gnus-newsgroup-data)
4368
4369             ;; Actually insert the line.
4370             (setq
4371              gnus-tmp-subject-or-nil
4372              (cond
4373               ((and gnus-thread-ignore-subject
4374                     gnus-tmp-prev-subject
4375                     (not (inline (gnus-subject-equal
4376                                   gnus-tmp-prev-subject subject))))
4377                subject)
4378               ((zerop gnus-tmp-level)
4379                (if (and (eq gnus-summary-make-false-root 'empty)
4380                         (memq number gnus-tmp-gathered)
4381                         gnus-tmp-prev-subject
4382                         (inline (gnus-subject-equal
4383                                  gnus-tmp-prev-subject subject)))
4384                    gnus-summary-same-subject
4385                  subject))
4386               (t gnus-summary-same-subject)))
4387             (if (and (eq gnus-summary-make-false-root 'adopt)
4388                      (= gnus-tmp-level 1)
4389                      (memq number gnus-tmp-gathered))
4390                 (setq gnus-tmp-opening-bracket ?\<
4391                       gnus-tmp-closing-bracket ?\>)
4392               (setq gnus-tmp-opening-bracket ?\[
4393                     gnus-tmp-closing-bracket ?\]))
4394             (setq
4395              gnus-tmp-indentation
4396              (aref gnus-thread-indent-array gnus-tmp-level)
4397              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4398              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4399                                 gnus-summary-default-score 0)
4400              gnus-tmp-score-char
4401              (if (or (null gnus-summary-default-score)
4402                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4403                          gnus-summary-zcore-fuzz))
4404                  ?                      ;Whitespace
4405                (if (< gnus-tmp-score gnus-summary-default-score)
4406                    gnus-score-below-mark gnus-score-over-mark))
4407              gnus-tmp-replied
4408              (cond ((memq number gnus-newsgroup-processable)
4409                     gnus-process-mark)
4410                    ((memq number gnus-newsgroup-cached)
4411                     gnus-cached-mark)
4412                    ((memq number gnus-newsgroup-replied)
4413                     gnus-replied-mark)
4414                    ((memq number gnus-newsgroup-forwarded)
4415                     gnus-forwarded-mark)
4416                    ((memq number gnus-newsgroup-saved)
4417                     gnus-saved-mark)
4418                    ((memq number gnus-newsgroup-recent)
4419                     gnus-recent-mark)
4420                    ((memq number gnus-newsgroup-unseen)
4421                     gnus-unseen-mark)
4422                    (t gnus-no-mark))
4423              gnus-tmp-from (mail-header-from gnus-tmp-header)
4424              gnus-tmp-name
4425              (cond
4426               ((string-match "<[^>]+> *$" gnus-tmp-from)
4427                (setq beg-match (match-beginning 0))
4428                (or (and (string-match "^\".+\"" gnus-tmp-from)
4429                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4430                    (substring gnus-tmp-from 0 beg-match)))
4431               ((string-match "(.+)" gnus-tmp-from)
4432                (substring gnus-tmp-from
4433                           (1+ (match-beginning 0)) (1- (match-end 0))))
4434               (t gnus-tmp-from))
4435              gnus-tmp-thread-tree-header-string
4436              (cond
4437               ((not gnus-show-threads) "")
4438               ((zerop gnus-tmp-level)
4439                (if (cdar thread)
4440                    (or gnus-sum-thread-tree-root subject)
4441                  (or gnus-sum-thread-tree-single-indent subject)))
4442               (t
4443                (concat (apply 'concat
4444                               (mapcar (lambda (item)
4445                                         (if (= item 1)
4446                                             gnus-sum-thread-tree-vertical
4447                                           gnus-sum-thread-tree-indent))
4448                                       (cdr (reverse tree-stack))))
4449                        (if (nth 1 thread)
4450                            gnus-sum-thread-tree-leaf-with-other
4451                          gnus-sum-thread-tree-single-leaf)))))
4452             (when (string= gnus-tmp-name "")
4453               (setq gnus-tmp-name gnus-tmp-from))
4454             (unless (numberp gnus-tmp-lines)
4455               (setq gnus-tmp-lines -1))
4456             (if (= gnus-tmp-lines -1)
4457                 (setq gnus-tmp-lines "?")
4458               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4459             (gnus-put-text-property
4460              (point)
4461              (progn (eval gnus-summary-line-format-spec) (point))
4462              'gnus-number number)
4463             (when gnus-visual-p
4464               (forward-line -1)
4465               (gnus-run-hooks 'gnus-summary-update-hook)
4466               (forward-line 1))
4467
4468             (setq gnus-tmp-prev-subject subject)))
4469
4470         (when (nth 1 thread)
4471           (push (list (max 0 gnus-tmp-level)
4472                       (copy-list tree-stack)
4473                       (nthcdr 1 thread))
4474                 stack))
4475         (push (if (nth 1 thread) 1 0) tree-stack)
4476         (incf gnus-tmp-level)
4477         (setq threads (if thread-end nil (cdar thread)))
4478         (unless threads
4479           (setq gnus-tmp-level 0)))))
4480   (gnus-message 7 "Generating summary...done"))
4481
4482 (defun gnus-summary-prepare-unthreaded (headers)
4483   "Generate an unthreaded summary buffer based on HEADERS."
4484   (let (header number mark)
4485
4486     (beginning-of-line)
4487
4488     (while headers
4489       ;; We may have to root out some bad articles...
4490       (when (memq (setq number (mail-header-number
4491                                 (setq header (pop headers))))
4492                   gnus-newsgroup-limit)
4493         ;; Mark article as read when it has a low score.
4494         (when (and gnus-summary-mark-below
4495                    (< (or (cdr (assq number gnus-newsgroup-scored))
4496                           gnus-summary-default-score 0)
4497                       gnus-summary-mark-below)
4498                    (not (gnus-summary-article-ancient-p number)))
4499           (setq gnus-newsgroup-unreads
4500                 (delq number gnus-newsgroup-unreads))
4501           (if gnus-newsgroup-auto-expire
4502               (push number gnus-newsgroup-expirable)
4503             (push (cons number gnus-low-score-mark)
4504                   gnus-newsgroup-reads)))
4505
4506         (setq mark (gnus-article-mark number))
4507         (push (gnus-data-make number mark (1+ (point)) header 0)
4508               gnus-newsgroup-data)
4509         (gnus-summary-insert-line
4510          header 0 number
4511          mark (memq number gnus-newsgroup-replied)
4512          (memq number gnus-newsgroup-expirable)
4513          (mail-header-subject header) nil
4514          (cdr (assq number gnus-newsgroup-scored))
4515          (memq number gnus-newsgroup-processable))))))
4516
4517 (defun gnus-summary-remove-list-identifiers ()
4518   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4519   (let ((regexp (if (consp gnus-list-identifiers)
4520                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4521                   gnus-list-identifiers))
4522         changed subject)
4523     (when regexp
4524       (dolist (header gnus-newsgroup-headers)
4525         (setq subject (mail-header-subject header)
4526               changed nil)
4527         (while (string-match
4528                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4529                 subject)
4530           (setq subject
4531                 (concat (substring subject 0 (match-beginning 2))
4532                         (substring subject (match-end 0)))
4533                 changed t))
4534         (when (and changed
4535                    (string-match
4536                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4537           (setq subject
4538                 (concat (substring subject 0 (match-beginning 1))
4539                         (substring subject (match-end 1)))))
4540         (when changed
4541           (mail-header-set-subject header subject))))))
4542
4543 (defun gnus-fetch-headers (articles)
4544   "Fetch headers of ARTICLES."
4545   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4546     (gnus-message 5 "Fetching headers for %s..." name)
4547     (prog1
4548         (if (eq 'nov
4549                 (setq gnus-headers-retrieved-by
4550                       (gnus-retrieve-headers
4551                        articles gnus-newsgroup-name
4552                        ;; We might want to fetch old headers, but
4553                        ;; not if there is only 1 article.
4554                        (and (or (and
4555                                  (not (eq gnus-fetch-old-headers 'some))
4556                                  (not (numberp gnus-fetch-old-headers)))
4557                                 (> (length articles) 1))
4558                             gnus-fetch-old-headers))))
4559             (gnus-get-newsgroup-headers-xover
4560              articles nil nil gnus-newsgroup-name t)
4561           (gnus-get-newsgroup-headers))
4562       (gnus-message 5 "Fetching headers for %s...done" name))))
4563
4564 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4565   "Select newsgroup GROUP.
4566 If READ-ALL is non-nil, all articles in the group are selected.
4567 If SELECT-ARTICLES, only select those articles from GROUP."
4568   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4569          ;;!!! Dirty hack; should be removed.
4570          (gnus-summary-ignore-duplicates
4571           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4572               t
4573             gnus-summary-ignore-duplicates))
4574          (info (nth 2 entry))
4575          articles fetched-articles cached)
4576
4577     (unless (gnus-check-server
4578              (set (make-local-variable 'gnus-current-select-method)
4579                   (gnus-find-method-for-group group)))
4580       (error "Couldn't open server"))
4581
4582     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4583         (gnus-activate-group group)     ; Or we can activate it...
4584         (progn                          ; Or we bug out.
4585           (when (equal major-mode 'gnus-summary-mode)
4586             (kill-buffer (current-buffer)))
4587           (error "Couldn't activate group %s: %s"
4588                  group (gnus-status-message group))))
4589
4590     (unless (gnus-request-group group t)
4591       (when (equal major-mode 'gnus-summary-mode)
4592         (kill-buffer (current-buffer)))
4593       (error "Couldn't request group %s: %s"
4594              group (gnus-status-message group)))
4595
4596     (setq gnus-newsgroup-name group
4597           gnus-newsgroup-unselected nil
4598           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4599
4600     (let ((display (gnus-group-find-parameter group 'display)))
4601       (setq gnus-newsgroup-display
4602             (cond
4603              ((not (zerop (or (car-safe read-all) 0)))
4604               ;; The user entered the group with C-u SPC/RET, let's show
4605               ;; all articles.
4606               'gnus-not-ignore)
4607              ((eq display 'all)
4608               'gnus-not-ignore)
4609              ((arrayp display)
4610               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4611              ((numberp display)
4612               ;; The following is probably the "correct" solution, but
4613               ;; it makes Gnus fetch all headers and then limit the
4614               ;; articles (which is slow), so instead we hack the
4615               ;; select-articles parameter instead. -- Simon Josefsson
4616               ;; <jas@kth.se>
4617               ;;
4618               ;; (gnus-byte-compile
4619               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4620               ;;                         display)))))
4621               (setq select-articles
4622                     (gnus-uncompress-range
4623                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4624                              (if (> tmp 0)
4625                                  tmp
4626                                1))
4627                            (cdr (gnus-active group)))))
4628               nil)
4629              (t
4630               nil))))
4631
4632     (gnus-summary-setup-default-charset)
4633
4634     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4635     (when (gnus-virtual-group-p group)
4636       (setq cached gnus-newsgroup-cached))
4637
4638     (setq gnus-newsgroup-unreads
4639           (gnus-set-difference
4640            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4641            gnus-newsgroup-dormant))
4642
4643     (setq gnus-newsgroup-processable nil)
4644
4645     (gnus-update-read-articles group gnus-newsgroup-unreads)
4646
4647     ;; Adjust and set lists of article marks.
4648     (when info
4649       (gnus-adjust-marked-articles info))
4650
4651     (if (setq articles select-articles)
4652         (setq gnus-newsgroup-unselected
4653               (gnus-sorted-intersection
4654                gnus-newsgroup-unreads
4655                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4656       (setq articles (gnus-articles-to-read group read-all)))
4657
4658     (cond
4659      ((null articles)
4660       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4661       'quit)
4662      ((eq articles 0) nil)
4663      (t
4664       ;; Init the dependencies hash table.
4665       (setq gnus-newsgroup-dependencies
4666             (gnus-make-hashtable (length articles)))
4667       (gnus-set-global-variables)
4668       ;; Retrieve the headers and read them in.
4669       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4670
4671       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4672       (when cached
4673         (setq gnus-newsgroup-cached cached))
4674
4675       ;; Suppress duplicates?
4676       (when gnus-suppress-duplicates
4677         (gnus-dup-suppress-articles))
4678
4679       ;; Set the initial limit.
4680       (setq gnus-newsgroup-limit (copy-sequence articles))
4681       ;; Remove canceled articles from the list of unread articles.
4682       (setq fetched-articles
4683             (mapcar (lambda (headers) (mail-header-number headers))
4684                     gnus-newsgroup-headers))
4685       (setq gnus-newsgroup-articles fetched-articles)
4686       (setq gnus-newsgroup-unreads
4687             (gnus-set-sorted-intersection
4688              gnus-newsgroup-unreads fetched-articles))
4689
4690       ;; The `seen' marks are treated specially.
4691       (if (not gnus-newsgroup-seen)
4692           (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4693         (dolist (article gnus-newsgroup-articles)
4694           (unless (gnus-member-of-range article gnus-newsgroup-seen)
4695             (push article gnus-newsgroup-unseen)))
4696         (setq gnus-newsgroup-unseen (nreverse gnus-newsgroup-unseen)))
4697
4698       ;; Removed marked articles that do not exist.
4699       (gnus-update-missing-marks
4700        (gnus-sorted-complement fetched-articles articles))
4701       ;; We might want to build some more threads first.
4702       (when (and gnus-fetch-old-headers
4703                  (eq gnus-headers-retrieved-by 'nov))
4704         (if (eq gnus-fetch-old-headers 'invisible)
4705             (gnus-build-all-threads)
4706           (gnus-build-old-threads)))
4707       ;; Let the Gnus agent mark articles as read.
4708       (when gnus-agent
4709         (gnus-agent-get-undownloaded-list))
4710       ;; Remove list identifiers from subject
4711       (when gnus-list-identifiers
4712         (gnus-summary-remove-list-identifiers))
4713       ;; Check whether auto-expire is to be done in this group.
4714       (setq gnus-newsgroup-auto-expire
4715             (gnus-group-auto-expirable-p group))
4716       ;; Set up the article buffer now, if necessary.
4717       (unless gnus-single-article-buffer
4718         (gnus-article-setup-buffer))
4719       ;; First and last article in this newsgroup.
4720       (when gnus-newsgroup-headers
4721         (setq gnus-newsgroup-begin
4722               (mail-header-number (car gnus-newsgroup-headers))
4723               gnus-newsgroup-end
4724               (mail-header-number
4725                (gnus-last-element gnus-newsgroup-headers))))
4726       ;; GROUP is successfully selected.
4727       (or gnus-newsgroup-headers t)))))
4728
4729 (defun gnus-summary-display-make-predicate (display)
4730   (require 'gnus-agent)
4731   (when (= (length display) 1)
4732     (setq display (car display)))
4733   (unless gnus-summary-display-cache
4734     (dolist (elem (append (list (cons 'read 'read)
4735                                 (cons 'unseen 'unseen))
4736                           gnus-article-mark-lists))
4737       (push (cons (cdr elem)
4738                   (gnus-byte-compile
4739                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4740             gnus-summary-display-cache)))
4741   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4742     (gnus-get-predicate display)))
4743
4744 ;; Uses the dynamically bound `number' variable.
4745 (defvar number)
4746 (defun gnus-article-marked-p (type &optional article)
4747   (let ((article (or article number)))
4748     (cond
4749      ((eq type 'tick)
4750       (memq article gnus-newsgroup-marked))
4751      ((eq type 'unsend)
4752       (memq article gnus-newsgroup-unsendable))
4753      ((eq type 'undownload)
4754       (memq article gnus-newsgroup-undownloaded))
4755      ((eq type 'download)
4756       (memq article gnus-newsgroup-downloadable))
4757      ((eq type 'unread)
4758       (memq article gnus-newsgroup-unreads))
4759      ((eq type 'read)
4760       (memq article gnus-newsgroup-reads))
4761      ((eq type 'dormant)
4762       (memq article gnus-newsgroup-dormant) )
4763      ((eq type 'expire)
4764       (memq article gnus-newsgroup-expirable))
4765      ((eq type 'reply)
4766       (memq article gnus-newsgroup-replied))
4767      ((eq type 'killed)
4768       (memq article gnus-newsgroup-killed))
4769      ((eq type 'bookmark)
4770       (assq article gnus-newsgroup-bookmarks))
4771      ((eq type 'score)
4772       (assq article gnus-newsgroup-scored))
4773      ((eq type 'save)
4774       (memq article gnus-newsgroup-saved))
4775      ((eq type 'cache)
4776       (memq article gnus-newsgroup-cached))
4777      ((eq type 'forward)
4778       (memq article gnus-newsgroup-forwarded))
4779      ((eq type 'seen)
4780       (not (memq article gnus-newsgroup-unseen)))
4781      ((eq type 'recent)
4782       (memq article gnus-newsgroup-recent))
4783      (t t))))
4784
4785 (defun gnus-articles-to-read (group &optional read-all)
4786   "Find out what articles the user wants to read."
4787   (let* ((articles
4788           ;; Select all articles if `read-all' is non-nil, or if there
4789           ;; are no unread articles.
4790           (if (or read-all
4791                   (and (zerop (length gnus-newsgroup-marked))
4792                        (zerop (length gnus-newsgroup-unreads)))
4793                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4794               ;; We want to select the headers for all the articles in
4795               ;; the group, so we select either all the active
4796               ;; articles in the group, or (if that's nil), the
4797               ;; articles in the cache.
4798               (or
4799                (gnus-uncompress-range (gnus-active group))
4800                (gnus-cache-articles-in-group group))
4801             ;; Select only the "normal" subset of articles.
4802             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4803                           (copy-sequence gnus-newsgroup-unreads))
4804                   '<)))
4805          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4806          (scored (length scored-list))
4807          (number (length articles))
4808          (marked (+ (length gnus-newsgroup-marked)
4809                     (length gnus-newsgroup-dormant)))
4810          (select
4811           (cond
4812            ((numberp read-all)
4813             read-all)
4814            (t
4815             (condition-case ()
4816                 (cond
4817                  ((and (or (<= scored marked) (= scored number))
4818                        (numberp gnus-large-newsgroup)
4819                        (> number gnus-large-newsgroup))
4820                   (let ((input
4821                          (read-string
4822                           (format
4823                            "How many articles from %s (default %d): "
4824                            (gnus-limit-string
4825                             (gnus-group-decoded-name gnus-newsgroup-name)
4826                             35)
4827                            number))))
4828                     (if (string-match "^[ \t]*$" input) number input)))
4829                  ((and (> scored marked) (< scored number)
4830                        (> (- scored number) 20))
4831                   (let ((input
4832                          (read-string
4833                           (format "%s %s (%d scored, %d total): "
4834                                   "How many articles from"
4835                                   (gnus-group-decoded-name group)
4836                                   scored number))))
4837                     (if (string-match "^[ \t]*$" input)
4838                         number input)))
4839                  (t number))
4840               (quit
4841                (message "Quit getting the articles to read")
4842                nil))))))
4843     (setq select (if (stringp select) (string-to-number select) select))
4844     (if (or (null select) (zerop select))
4845         select
4846       (if (and (not (zerop scored)) (<= (abs select) scored))
4847           (progn
4848             (setq articles (sort scored-list '<))
4849             (setq number (length articles)))
4850         (setq articles (copy-sequence articles)))
4851
4852       (when (< (abs select) number)
4853         (if (< select 0)
4854             ;; Select the N oldest articles.
4855             (setcdr (nthcdr (1- (abs select)) articles) nil)
4856           ;; Select the N most recent articles.
4857           (setq articles (nthcdr (- number select) articles))))
4858       (setq gnus-newsgroup-unselected
4859             (gnus-sorted-intersection
4860              gnus-newsgroup-unreads
4861              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4862       (when gnus-alter-articles-to-read-function
4863         (setq gnus-newsgroup-unreads
4864               (sort
4865                (funcall gnus-alter-articles-to-read-function
4866                         gnus-newsgroup-name gnus-newsgroup-unreads)
4867                '<)))
4868       articles)))
4869
4870 (defun gnus-killed-articles (killed articles)
4871   (let (out)
4872     (while articles
4873       (when (inline (gnus-member-of-range (car articles) killed))
4874         (push (car articles) out))
4875       (setq articles (cdr articles)))
4876     out))
4877
4878 (defun gnus-uncompress-marks (marks)
4879   "Uncompress the mark ranges in MARKS."
4880   (let ((uncompressed '(score bookmark))
4881         out)
4882     (while marks
4883       (if (memq (caar marks) uncompressed)
4884           (push (car marks) out)
4885         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4886       (setq marks (cdr marks)))
4887     out))
4888
4889 (defun gnus-article-mark-to-type (mark)
4890   "Return the type of MARK."
4891   (or (cadr (assq mark gnus-article-special-mark-lists))
4892       'list))
4893
4894 (defun gnus-article-unpropagatable-p (mark)
4895   "Return whether MARK should be propagated to backend."
4896   (memq mark gnus-article-unpropagated-mark-lists))
4897
4898 (defun gnus-adjust-marked-articles (info)
4899   "Set all article lists and remove all marks that are no longer valid."
4900   (let* ((marked-lists (gnus-info-marks info))
4901          (active (gnus-active (gnus-info-group info)))
4902          (min (car active))
4903          (max (cdr active))
4904          (types gnus-article-mark-lists)
4905          marks var articles article mark mark-type)
4906
4907     (dolist (marks marked-lists)
4908       (setq mark (car marks)
4909             mark-type (gnus-article-mark-to-type mark)
4910             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4911
4912       ;; We set the variable according to the type of the marks list,
4913       ;; and then adjust the marks to a subset of the active articles.
4914       (cond
4915        ;; Adjust "simple" lists.
4916        ((eq mark-type 'list)
4917         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4918         (when (memq mark '(tick dormant expire reply save))
4919           (while articles
4920             (when (or (< (setq article (pop articles)) min) (> article max))
4921               (set var (delq article (symbol-value var)))))))
4922        ;; Adjust assocs.
4923        ((eq mark-type 'tuple)
4924         (set var (setq articles (cdr marks)))
4925         (when (not (listp (cdr (symbol-value var))))
4926           (set var (list (symbol-value var))))
4927         (when (not (listp (cdr articles)))
4928           (setq articles (list articles)))
4929         (while articles
4930           (when (or (not (consp (setq article (pop articles))))
4931                     (< (car article) min)
4932                     (> (car article) max))
4933             (set var (delq article (symbol-value var))))))
4934        ;; Adjust ranges (sloppily).
4935        ((eq mark-type 'range)
4936         (cond
4937          ((eq mark 'seen)
4938           (setq articles (cdr marks))
4939           (while (and articles
4940                       (or (and (consp (car articles))
4941                                (> min (cdar articles)))
4942                           (and (numberp (car articles))
4943                                (> min (car articles)))))
4944             (pop articles))
4945           (set var articles))))))))
4946
4947 (defun gnus-update-missing-marks (missing)
4948   "Go through the list of MISSING articles and remove them from the mark lists."
4949   (when missing
4950     (let (var m)
4951       ;; Go through all types.
4952       (dolist (elem gnus-article-mark-lists)
4953         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4954           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4955           (when (symbol-value var)
4956             ;; This list has articles.  So we delete all missing
4957             ;; articles from it.
4958             (setq m missing)
4959             (while m
4960               (set var (delq (pop m) (symbol-value var))))))))))
4961
4962 (defun gnus-update-marks ()
4963   "Enter the various lists of marked articles into the newsgroup info list."
4964   (let ((types gnus-article-mark-lists)
4965         (info (gnus-get-info gnus-newsgroup-name))
4966         type list newmarked symbol delta-marks)
4967     (when info
4968       ;; Add all marks lists to the list of marks lists.
4969       (while (setq type (pop types))
4970         (setq list (symbol-value
4971                     (setq symbol
4972                           (intern (format "gnus-newsgroup-%s" (car type))))))
4973
4974         (when list
4975           ;; Get rid of the entries of the articles that have the
4976           ;; default score.
4977           (when (and (eq (cdr type) 'score)
4978                      gnus-save-score
4979                      list)
4980             (let* ((arts list)
4981                    (prev (cons nil list))
4982                    (all prev))
4983               (while arts
4984                 (if (or (not (consp (car arts)))
4985                         (= (cdar arts) gnus-summary-default-score))
4986                     (setcdr prev (cdr arts))
4987                   (setq prev arts))
4988                 (setq arts (cdr arts)))
4989               (setq list (cdr all)))))
4990
4991         (when (eq (cdr type) 'seen)
4992           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
4993
4994         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4995           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4996
4997         (when (and (gnus-check-backend-function
4998                     'request-set-mark gnus-newsgroup-name)
4999                    (not (gnus-article-unpropagatable-p (cdr type))))
5000           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5001                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5002                  (add (gnus-remove-from-range
5003                        (gnus-copy-sequence list) old)))
5004             (when add
5005               (push (list add 'add (list (cdr type))) delta-marks))
5006             (when del
5007               (push (list del 'del (list (cdr type))) delta-marks))))
5008
5009         (when list
5010           (push (cons (cdr type) list) newmarked)))
5011
5012       (when delta-marks
5013         (unless (gnus-check-group gnus-newsgroup-name)
5014           (error "Can't open server for %s" gnus-newsgroup-name))
5015         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5016
5017       ;; Enter these new marks into the info of the group.
5018       (if (nthcdr 3 info)
5019           (setcar (nthcdr 3 info) newmarked)
5020         ;; Add the marks lists to the end of the info.
5021         (when newmarked
5022           (setcdr (nthcdr 2 info) (list newmarked))))
5023
5024       ;; Cut off the end of the info if there's nothing else there.
5025       (let ((i 5))
5026         (while (and (> i 2)
5027                     (not (nth i info)))
5028           (when (nthcdr (decf i) info)
5029             (setcdr (nthcdr i info) nil)))))))
5030
5031 (defun gnus-set-mode-line (where)
5032   "Set the mode line of the article or summary buffers.
5033 If WHERE is `summary', the summary mode line format will be used."
5034   ;; Is this mode line one we keep updated?
5035   (when (and (memq where gnus-updated-mode-lines)
5036              (symbol-value
5037               (intern (format "gnus-%s-mode-line-format-spec" where))))
5038     (let (mode-string)
5039       (save-excursion
5040         ;; We evaluate this in the summary buffer since these
5041         ;; variables are buffer-local to that buffer.
5042         (set-buffer gnus-summary-buffer)
5043        ;; We bind all these variables that are used in the `eval' form
5044         ;; below.
5045         (let* ((mformat (symbol-value
5046                          (intern
5047                           (format "gnus-%s-mode-line-format-spec" where))))
5048                (gnus-tmp-group-name (gnus-group-decoded-name
5049                                      gnus-newsgroup-name))
5050                (gnus-tmp-article-number (or gnus-current-article 0))
5051                (gnus-tmp-unread gnus-newsgroup-unreads)
5052                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5053                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5054                (gnus-tmp-unread-and-unselected
5055                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5056                             (zerop gnus-tmp-unselected))
5057                        "")
5058                       ((zerop gnus-tmp-unselected)
5059                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5060                       (t (format "{%d(+%d) more}"
5061                                  gnus-tmp-unread-and-unticked
5062                                  gnus-tmp-unselected))))
5063                (gnus-tmp-subject
5064                 (if (and gnus-current-headers
5065                          (vectorp gnus-current-headers))
5066                     (gnus-mode-string-quote
5067                      (mail-header-subject gnus-current-headers))
5068                   ""))
5069                bufname-length max-len
5070                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5071           (setq mode-string (eval mformat))
5072           (setq bufname-length (if (string-match "%b" mode-string)
5073                                    (- (length
5074                                        (buffer-name
5075                                         (if (eq where 'summary)
5076                                             nil
5077                                           (get-buffer gnus-article-buffer))))
5078                                       2)
5079                                  0))
5080           (setq max-len (max 4 (if gnus-mode-non-string-length
5081                                    (- (window-width)
5082                                       gnus-mode-non-string-length
5083                                       bufname-length)
5084                                  (length mode-string))))
5085           ;; We might have to chop a bit of the string off...
5086           (when (> (length mode-string) max-len)
5087             (setq mode-string
5088                   (concat (truncate-string-to-width mode-string (- max-len 3))
5089                           "...")))
5090           ;; Pad the mode string a bit.
5091           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5092       ;; Update the mode line.
5093       (setq mode-line-buffer-identification
5094             (gnus-mode-line-buffer-identification (list mode-string)))
5095       (set-buffer-modified-p t))))
5096
5097 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5098   "Go through the HEADERS list and add all Xrefs to a hash table.
5099 The resulting hash table is returned, or nil if no Xrefs were found."
5100   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5101          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5102          (xref-hashtb (gnus-make-hashtable))
5103          start group entry number xrefs header)
5104     (while headers
5105       (setq header (pop headers))
5106       (when (and (setq xrefs (mail-header-xref header))
5107                  (not (memq (setq number (mail-header-number header))
5108                             unreads)))
5109         (setq start 0)
5110         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5111           (setq start (match-end 0))
5112           (setq group (if prefix
5113                           (concat prefix (substring xrefs (match-beginning 1)
5114                                                     (match-end 1)))
5115                         (substring xrefs (match-beginning 1) (match-end 1))))
5116           (setq number
5117                 (string-to-int (substring xrefs (match-beginning 2)
5118                                           (match-end 2))))
5119           (if (setq entry (gnus-gethash group xref-hashtb))
5120               (setcdr entry (cons number (cdr entry)))
5121             (gnus-sethash group (cons number nil) xref-hashtb)))))
5122     (and start xref-hashtb)))
5123
5124 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5125   "Look through all the headers and mark the Xrefs as read."
5126   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5127         name entry info xref-hashtb idlist method nth4)
5128     (save-excursion
5129       (set-buffer gnus-group-buffer)
5130       (when (setq xref-hashtb
5131                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5132         (mapatoms
5133          (lambda (group)
5134            (unless (string= from-newsgroup (setq name (symbol-name group)))
5135              (setq idlist (symbol-value group))
5136              ;; Dead groups are not updated.
5137              (and (prog1
5138                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5139                             info (nth 2 entry))
5140                     (when (stringp (setq nth4 (gnus-info-method info)))
5141                       (setq nth4 (gnus-server-to-method nth4))))
5142                   ;; Only do the xrefs if the group has the same
5143                   ;; select method as the group we have just read.
5144                   (or (gnus-methods-equal-p
5145                        nth4 (gnus-find-method-for-group from-newsgroup))
5146                       virtual
5147                       (equal nth4 (setq method (gnus-find-method-for-group
5148                                                 from-newsgroup)))
5149                       (and (equal (car nth4) (car method))
5150                            (equal (nth 1 nth4) (nth 1 method))))
5151                   gnus-use-cross-reference
5152                   (or (not (eq gnus-use-cross-reference t))
5153                       virtual
5154                       ;; Only do cross-references on subscribed
5155                       ;; groups, if that is what is wanted.
5156                       (<= (gnus-info-level info) gnus-level-subscribed))
5157                   (gnus-group-make-articles-read name idlist))))
5158          xref-hashtb)))))
5159
5160 (defun gnus-compute-read-articles (group articles)
5161   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5162          (info (nth 2 entry))
5163          (active (gnus-active group))
5164          ninfo)
5165     (when entry
5166       ;; First peel off all invalid article numbers.
5167       (when active
5168         (let ((ids articles)
5169               id first)
5170           (while (setq id (pop ids))
5171             (when (and first (> id (cdr active)))
5172               ;; We'll end up in this situation in one particular
5173               ;; obscure situation.  If you re-scan a group and get
5174               ;; a new article that is cross-posted to a different
5175               ;; group that has not been re-scanned, you might get
5176               ;; crossposted article that has a higher number than
5177               ;; Gnus believes possible.  So we re-activate this
5178               ;; group as well.  This might mean doing the
5179               ;; crossposting thingy will *increase* the number
5180               ;; of articles in some groups.  Tsk, tsk.
5181               (setq active (or (gnus-activate-group group) active)))
5182             (when (or (> id (cdr active))
5183                       (< id (car active)))
5184               (setq articles (delq id articles))))))
5185       ;; If the read list is nil, we init it.
5186       (if (and active
5187                (null (gnus-info-read info))
5188                (> (car active) 1))
5189           (setq ninfo (cons 1 (1- (car active))))
5190         (setq ninfo (gnus-info-read info)))
5191       ;; Then we add the read articles to the range.
5192       (gnus-add-to-range
5193        ninfo (setq articles (sort articles '<))))))
5194
5195 (defun gnus-group-make-articles-read (group articles)
5196   "Update the info of GROUP to say that ARTICLES are read."
5197   (let* ((num 0)
5198          (entry (gnus-gethash group gnus-newsrc-hashtb))
5199          (info (nth 2 entry))
5200          (active (gnus-active group))
5201          range)
5202     (when entry
5203       (setq range (gnus-compute-read-articles group articles))
5204       (save-excursion
5205         (set-buffer gnus-group-buffer)
5206         (gnus-undo-register
5207           `(progn
5208              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5209              (gnus-info-set-read ',info ',(gnus-info-read info))
5210              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5211              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5212              (gnus-group-update-group ,group t))))
5213       ;; Add the read articles to the range.
5214       (gnus-info-set-read info range)
5215       (gnus-request-set-mark group (list (list range 'add '(read))))
5216       ;; Then we have to re-compute how many unread
5217       ;; articles there are in this group.
5218       (when active
5219         (cond
5220          ((not range)
5221           (setq num (- (1+ (cdr active)) (car active))))
5222          ((not (listp (cdr range)))
5223           (setq num (- (cdr active) (- (1+ (cdr range))
5224                                        (car range)))))
5225          (t
5226           (while range
5227             (if (numberp (car range))
5228                 (setq num (1+ num))
5229               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5230             (setq range (cdr range)))
5231           (setq num (- (cdr active) num))))
5232         ;; Update the number of unread articles.
5233         (setcar entry num)
5234         ;; Update the group buffer.
5235         (gnus-group-update-group group t)))))
5236
5237 (defvar gnus-newsgroup-none-id 0)
5238
5239 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5240   (let ((cur nntp-server-buffer)
5241         (dependencies
5242          (or dependencies
5243              (save-excursion (set-buffer gnus-summary-buffer)
5244                              gnus-newsgroup-dependencies)))
5245         headers id end ref
5246         (mail-parse-charset gnus-newsgroup-charset)
5247         (mail-parse-ignored-charsets
5248          (save-excursion (condition-case nil
5249                              (set-buffer gnus-summary-buffer)
5250                            (error))
5251                          gnus-newsgroup-ignored-charsets)))
5252     (save-excursion
5253       (set-buffer nntp-server-buffer)
5254       ;; Translate all TAB characters into SPACE characters.
5255       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5256       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5257       (gnus-run-hooks 'gnus-parse-headers-hook)
5258       (let ((case-fold-search t)
5259             in-reply-to header p lines chars)
5260         (goto-char (point-min))
5261         ;; Search to the beginning of the next header.  Error messages
5262         ;; do not begin with 2 or 3.
5263         (while (re-search-forward "^[23][0-9]+ " nil t)
5264           (setq id nil
5265                 ref nil)
5266           ;; This implementation of this function, with nine
5267           ;; search-forwards instead of the one re-search-forward and
5268           ;; a case (which basically was the old function) is actually
5269           ;; about twice as fast, even though it looks messier.  You
5270           ;; can't have everything, I guess.  Speed and elegance
5271           ;; doesn't always go hand in hand.
5272           (setq
5273            header
5274            (vector
5275             ;; Number.
5276             (prog1
5277                 (read cur)
5278               (end-of-line)
5279               (setq p (point))
5280               (narrow-to-region (point)
5281                                 (or (and (search-forward "\n.\n" nil t)
5282                                          (- (point) 2))
5283                                     (point))))
5284             ;; Subject.
5285             (progn
5286               (goto-char p)
5287               (if (search-forward "\nsubject:" nil t)
5288                   (funcall gnus-decode-encoded-word-function
5289                            (nnheader-header-value))
5290                 "(none)"))
5291             ;; From.
5292             (progn
5293               (goto-char p)
5294               (if (search-forward "\nfrom:" nil t)
5295                   (funcall gnus-decode-encoded-word-function
5296                            (nnheader-header-value))
5297                 "(nobody)"))
5298             ;; Date.
5299             (progn
5300               (goto-char p)
5301               (if (search-forward "\ndate:" nil t)
5302                   (nnheader-header-value) ""))
5303             ;; Message-ID.
5304             (progn
5305               (goto-char p)
5306               (setq id (if (re-search-forward
5307                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5308                            ;; We do it this way to make sure the Message-ID
5309                            ;; is (somewhat) syntactically valid.
5310                            (buffer-substring (match-beginning 1)
5311                                              (match-end 1))
5312                          ;; If there was no message-id, we just fake one
5313                          ;; to make subsequent routines simpler.
5314                          (nnheader-generate-fake-message-id))))
5315             ;; References.
5316             (progn
5317               (goto-char p)
5318               (if (search-forward "\nreferences:" nil t)
5319                   (progn
5320                     (setq end (point))
5321                     (prog1
5322                         (nnheader-header-value)
5323                       (setq ref
5324                             (buffer-substring
5325                              (progn
5326                                (end-of-line)
5327                                (search-backward ">" end t)
5328                                (1+ (point)))
5329                              (progn
5330                                (search-backward "<" end t)
5331                                (point))))))
5332                 ;; Get the references from the in-reply-to header if there
5333                 ;; were no references and the in-reply-to header looks
5334                 ;; promising.
5335                 (if (and (search-forward "\nin-reply-to:" nil t)
5336                          (setq in-reply-to (nnheader-header-value))
5337                          (string-match "<[^>]+>" in-reply-to))
5338                     (let (ref2)
5339                       (setq ref (substring in-reply-to (match-beginning 0)
5340                                            (match-end 0)))
5341                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5342                         (setq ref2 (substring in-reply-to (match-beginning 0)
5343                                               (match-end 0)))
5344                         (when (> (length ref2) (length ref))
5345                           (setq ref ref2)))
5346                       ref)
5347                   (setq ref nil))))
5348             ;; Chars.
5349             (progn
5350               (goto-char p)
5351               (if (search-forward "\nchars: " nil t)
5352                   (if (numberp (setq chars (ignore-errors (read cur))))
5353                       chars -1)
5354                 -1))
5355             ;; Lines.
5356             (progn
5357               (goto-char p)
5358               (if (search-forward "\nlines: " nil t)
5359                   (if (numberp (setq lines (ignore-errors (read cur))))
5360                       lines -1)
5361                 -1))
5362             ;; Xref.
5363             (progn
5364               (goto-char p)
5365               (and (search-forward "\nxref:" nil t)
5366                    (nnheader-header-value)))
5367             ;; Extra.
5368             (when gnus-extra-headers
5369               (let ((extra gnus-extra-headers)
5370                     out)
5371                 (while extra
5372                   (goto-char p)
5373                   (when (search-forward
5374                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5375                     (push (cons (car extra) (nnheader-header-value))
5376                           out))
5377                   (pop extra))
5378                 out))))
5379           (when (equal id ref)
5380             (setq ref nil))
5381
5382           (when gnus-alter-header-function
5383             (funcall gnus-alter-header-function header)
5384             (setq id (mail-header-id header)
5385                   ref (gnus-parent-id (mail-header-references header))))
5386
5387           (when (setq header
5388                       (gnus-dependencies-add-header
5389                        header dependencies force-new))
5390             (push header headers))
5391           (goto-char (point-max))
5392           (widen))
5393         (nreverse headers)))))
5394
5395 ;; Goes through the xover lines and returns a list of vectors
5396 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5397                                                   force-new dependencies
5398                                                   group also-fetch-heads)
5399   "Parse the news overview data in the server buffer.
5400 Return a list of headers that match SEQUENCE (see
5401 `nntp-retrieve-headers')."
5402   ;; Get the Xref when the users reads the articles since most/some
5403   ;; NNTP servers do not include Xrefs when using XOVER.
5404   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5405   (let ((mail-parse-charset gnus-newsgroup-charset)
5406         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5407         (cur nntp-server-buffer)
5408         (dependencies (or dependencies gnus-newsgroup-dependencies))
5409         (allp (cond
5410                ((eq gnus-read-all-available-headers t)
5411                 t)
5412                ((stringp gnus-read-all-available-headers)
5413                 (string-match gnus-read-all-available-headers group))
5414                (t
5415                 nil)))
5416         number headers header)
5417     (save-excursion
5418       (set-buffer nntp-server-buffer)
5419       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5420       ;; Allow the user to mangle the headers before parsing them.
5421       (gnus-run-hooks 'gnus-parse-headers-hook)
5422       (goto-char (point-min))
5423       (while (not (eobp))
5424         (condition-case ()
5425             (while (and (or sequence allp)
5426                         (not (eobp)))
5427               (setq number (read cur))
5428               (when (not allp)
5429                 (while (and sequence
5430                             (< (car sequence) number))
5431                   (setq sequence (cdr sequence))))
5432               (when (and (or allp
5433                              (and sequence
5434                                   (eq number (car sequence))))
5435                          (progn
5436                            (setq sequence (cdr sequence))
5437                            (setq header (inline
5438                                           (gnus-nov-parse-line
5439                                            number dependencies force-new)))))
5440                 (push header headers))
5441               (forward-line 1))
5442           (error
5443            (gnus-error 4 "Strange nov line (%d)"
5444                        (count-lines (point-min) (point)))))
5445         (forward-line 1))
5446       ;; A common bug in inn is that if you have posted an article and
5447       ;; then retrieves the active file, it will answer correctly --
5448       ;; the new article is included.  However, a NOV entry for the
5449       ;; article may not have been generated yet, so this may fail.
5450       ;; We work around this problem by retrieving the last few
5451       ;; headers using HEAD.
5452       (if (or (not also-fetch-heads)
5453               (not sequence))
5454           ;; We (probably) got all the headers.
5455           (nreverse headers)
5456         (let ((gnus-nov-is-evil t))
5457           (nconc
5458            (nreverse headers)
5459            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5460              (gnus-get-newsgroup-headers))))))))
5461
5462 (defun gnus-article-get-xrefs ()
5463   "Fill in the Xref value in `gnus-current-headers', if necessary.
5464 This is meant to be called in `gnus-article-internal-prepare-hook'."
5465   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5466                                  gnus-current-headers)))
5467     (or (not gnus-use-cross-reference)
5468         (not headers)
5469         (and (mail-header-xref headers)
5470              (not (string= (mail-header-xref headers) "")))
5471         (let ((case-fold-search t)
5472               xref)
5473           (save-restriction
5474             (nnheader-narrow-to-headers)
5475             (goto-char (point-min))
5476             (when (or (and (not (eobp))
5477                            (eq (downcase (char-after)) ?x)
5478                            (looking-at "Xref:"))
5479                       (search-forward "\nXref:" nil t))
5480               (goto-char (1+ (match-end 0)))
5481               (setq xref (buffer-substring (point)
5482                                            (progn (end-of-line) (point))))
5483               (mail-header-set-xref headers xref)))))))
5484
5485 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5486   "Find article ID and insert the summary line for that article.
5487 OLD-HEADER can either be a header or a line number to insert
5488 the subject line on."
5489   (let* ((line (and (numberp old-header) old-header))
5490          (old-header (and (vectorp old-header) old-header))
5491          (header (cond ((and old-header use-old-header)
5492                         old-header)
5493                        ((and (numberp id)
5494                              (gnus-number-to-header id))
5495                         (gnus-number-to-header id))
5496                        (t
5497                         (gnus-read-header id))))
5498          (number (and (numberp id) id))
5499          d)
5500     (when header
5501       ;; Rebuild the thread that this article is part of and go to the
5502       ;; article we have fetched.
5503       (when (and (not gnus-show-threads)
5504                  old-header)
5505         (when (and number
5506                    (setq d (gnus-data-find (mail-header-number old-header))))
5507           (goto-char (gnus-data-pos d))
5508           (gnus-data-remove
5509            number
5510            (- (gnus-point-at-bol)
5511               (prog1
5512                   (1+ (gnus-point-at-eol))
5513                 (gnus-delete-line))))))
5514       (when old-header
5515         (mail-header-set-number header (mail-header-number old-header)))
5516       (setq gnus-newsgroup-sparse
5517             (delq (setq number (mail-header-number header))
5518                   gnus-newsgroup-sparse))
5519       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5520       (push number gnus-newsgroup-limit)
5521       (gnus-rebuild-thread (mail-header-id header) line)
5522       (gnus-summary-goto-subject number nil t))
5523     (when (and (numberp number)
5524                (> number 0))
5525       ;; We have to update the boundaries even if we can't fetch the
5526       ;; article if ID is a number -- so that the next `P' or `N'
5527       ;; command will fetch the previous (or next) article even
5528       ;; if the one we tried to fetch this time has been canceled.
5529       (when (> number gnus-newsgroup-end)
5530         (setq gnus-newsgroup-end number))
5531       (when (< number gnus-newsgroup-begin)
5532         (setq gnus-newsgroup-begin number))
5533       (setq gnus-newsgroup-unselected
5534             (delq number gnus-newsgroup-unselected)))
5535     ;; Report back a success?
5536     (and header (mail-header-number header))))
5537
5538 ;;; Process/prefix in the summary buffer
5539
5540 (defun gnus-summary-work-articles (n)
5541   "Return a list of articles to be worked upon.
5542 The prefix argument, the list of process marked articles, and the
5543 current article will be taken into consideration."
5544   (save-excursion
5545     (set-buffer gnus-summary-buffer)
5546     (cond
5547      (n
5548       ;; A numerical prefix has been given.
5549       (setq n (prefix-numeric-value n))
5550       (let ((backward (< n 0))
5551             (n (abs (prefix-numeric-value n)))
5552             articles article)
5553         (save-excursion
5554           (while
5555               (and (> n 0)
5556                    (push (setq article (gnus-summary-article-number))
5557                          articles)
5558                    (if backward
5559                        (gnus-summary-find-prev nil article)
5560                      (gnus-summary-find-next nil article)))
5561             (decf n)))
5562         (nreverse articles)))
5563      ((and (gnus-region-active-p) (mark))
5564       (message "region active")
5565       ;; Work on the region between point and mark.
5566       (let ((max (max (point) (mark)))
5567             articles article)
5568         (save-excursion
5569           (goto-char (min (min (point) (mark))))
5570           (while
5571               (and
5572                (push (setq article (gnus-summary-article-number)) articles)
5573                (gnus-summary-find-next nil article)
5574                (< (point) max)))
5575           (nreverse articles))))
5576      (gnus-newsgroup-processable
5577       ;; There are process-marked articles present.
5578       ;; Save current state.
5579       (gnus-summary-save-process-mark)
5580       ;; Return the list.
5581       (reverse gnus-newsgroup-processable))
5582      (t
5583       ;; Just return the current article.
5584       (list (gnus-summary-article-number))))))
5585
5586 (defmacro gnus-summary-iterate (arg &rest forms)
5587   "Iterate over the process/prefixed articles and do FORMS.
5588 ARG is the interactive prefix given to the command.  FORMS will be
5589 executed with point over the summary line of the articles."
5590   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5591     `(let ((,articles (gnus-summary-work-articles ,arg)))
5592        (while ,articles
5593          (gnus-summary-goto-subject (car ,articles))
5594          ,@forms
5595          (pop ,articles)))))
5596
5597 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5598 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5599
5600 (defun gnus-summary-save-process-mark ()
5601   "Push the current set of process marked articles on the stack."
5602   (interactive)
5603   (push (copy-sequence gnus-newsgroup-processable)
5604         gnus-newsgroup-process-stack))
5605
5606 (defun gnus-summary-kill-process-mark ()
5607   "Push the current set of process marked articles on the stack and unmark."
5608   (interactive)
5609   (gnus-summary-save-process-mark)
5610   (gnus-summary-unmark-all-processable))
5611
5612 (defun gnus-summary-yank-process-mark ()
5613   "Pop the last process mark state off the stack and restore it."
5614   (interactive)
5615   (unless gnus-newsgroup-process-stack
5616     (error "Empty mark stack"))
5617   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5618
5619 (defun gnus-summary-process-mark-set (set)
5620   "Make SET into the current process marked articles."
5621   (gnus-summary-unmark-all-processable)
5622   (while set
5623     (gnus-summary-set-process-mark (pop set))))
5624
5625 ;;; Searching and stuff
5626
5627 (defun gnus-summary-search-group (&optional backward use-level)
5628   "Search for next unread newsgroup.
5629 If optional argument BACKWARD is non-nil, search backward instead."
5630   (save-excursion
5631     (set-buffer gnus-group-buffer)
5632     (when (gnus-group-search-forward
5633            backward nil (if use-level (gnus-group-group-level) nil))
5634       (gnus-group-group-name))))
5635
5636 (defun gnus-summary-best-group (&optional exclude-group)
5637   "Find the name of the best unread group.
5638 If EXCLUDE-GROUP, do not go to this group."
5639   (save-excursion
5640     (set-buffer gnus-group-buffer)
5641     (save-excursion
5642       (gnus-group-best-unread-group exclude-group))))
5643
5644 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5645   (if backward (gnus-summary-find-prev)
5646     (let* ((dummy (gnus-summary-article-intangible-p))
5647            (article (or article (gnus-summary-article-number)))
5648            (arts (gnus-data-find-list article))
5649            result)
5650       (when (and (not dummy)
5651                  (or (not gnus-summary-check-current)
5652                      (not unread)
5653                      (not (gnus-data-unread-p (car arts)))))
5654         (setq arts (cdr arts)))
5655       (when (setq result
5656                   (if unread
5657                       (progn
5658                         (while arts
5659                           (when (or (and undownloaded
5660                                          (eq gnus-undownloaded-mark
5661                                              (gnus-data-mark (car arts))))
5662                                     (gnus-data-unread-p (car arts)))
5663                             (setq result (car arts)
5664                                   arts nil))
5665                           (setq arts (cdr arts)))
5666                         result)
5667                     (car arts)))
5668         (goto-char (gnus-data-pos result))
5669         (gnus-data-number result)))))
5670
5671 (defun gnus-summary-find-prev (&optional unread article)
5672   (let* ((eobp (eobp))
5673          (article (or article (gnus-summary-article-number)))
5674          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5675          result)
5676     (when (and (not eobp)
5677                (or (not gnus-summary-check-current)
5678                    (not unread)
5679                    (not (gnus-data-unread-p (car arts)))))
5680       (setq arts (cdr arts)))
5681     (when (setq result
5682                 (if unread
5683                     (progn
5684                       (while arts
5685                         (when (gnus-data-unread-p (car arts))
5686                           (setq result (car arts)
5687                                 arts nil))
5688                         (setq arts (cdr arts)))
5689                       result)
5690                   (car arts)))
5691       (goto-char (gnus-data-pos result))
5692       (gnus-data-number result))))
5693
5694 (defun gnus-summary-find-subject (subject &optional unread backward article)
5695   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5696          (article (or article (gnus-summary-article-number)))
5697          (articles (gnus-data-list backward))
5698          (arts (gnus-data-find-list article articles))
5699          result)
5700     (when (or (not gnus-summary-check-current)
5701               (not unread)
5702               (not (gnus-data-unread-p (car arts))))
5703       (setq arts (cdr arts)))
5704     (while arts
5705       (and (or (not unread)
5706                (gnus-data-unread-p (car arts)))
5707            (vectorp (gnus-data-header (car arts)))
5708            (gnus-subject-equal
5709             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5710            (setq result (car arts)
5711                  arts nil))
5712       (setq arts (cdr arts)))
5713     (and result
5714          (goto-char (gnus-data-pos result))
5715          (gnus-data-number result))))
5716
5717 (defun gnus-summary-search-forward (&optional unread subject backward)
5718   "Search forward for an article.
5719 If UNREAD, look for unread articles.  If SUBJECT, look for
5720 articles with that subject.  If BACKWARD, search backward instead."
5721   (cond (subject (gnus-summary-find-subject subject unread backward))
5722         (backward (gnus-summary-find-prev unread))
5723         (t (gnus-summary-find-next unread))))
5724
5725 (defun gnus-recenter (&optional n)
5726   "Center point in window and redisplay frame.
5727 Also do horizontal recentering."
5728   (interactive "P")
5729   (when (and gnus-auto-center-summary
5730              (not (eq gnus-auto-center-summary 'vertical)))
5731     (gnus-horizontal-recenter))
5732   (recenter n))
5733
5734 (defun gnus-summary-recenter ()
5735   "Center point in the summary window.
5736 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5737 displayed, no centering will be performed."
5738   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5739 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5740   (interactive)
5741   (let* ((top (cond ((< (window-height) 4) 0)
5742                     ((< (window-height) 7) 1)
5743                     (t (if (numberp gnus-auto-center-summary)
5744                            gnus-auto-center-summary
5745                          2))))
5746          (height (1- (window-height)))
5747          (bottom (save-excursion (goto-char (point-max))
5748                                  (forward-line (- height))
5749                                  (point)))
5750          (window (get-buffer-window (current-buffer))))
5751     ;; The user has to want it.
5752     (when gnus-auto-center-summary
5753       (when (get-buffer-window gnus-article-buffer)
5754         ;; Only do recentering when the article buffer is displayed,
5755       ;; Set the window start to either `bottom', which is the biggest
5756         ;; possible valid number, or the second line from the top,
5757         ;; whichever is the least.
5758         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5759           (if (> bottom top-pos)
5760               ;; Keep the second line from the top visible
5761               (set-window-start window top-pos t)
5762             ;; Try to keep the bottom line visible; if it's partially
5763             ;; obscured, either scroll one more line to make it fully
5764             ;; visible, or revert to using TOP-POS.
5765             (save-excursion
5766               (goto-char (point-max))
5767               (forward-line -1)
5768               (let ((last-line-start (point)))
5769                 (goto-char bottom)
5770                 (set-window-start window (point) t)
5771                 (when (not (pos-visible-in-window-p last-line-start window))
5772                   (forward-line 1)
5773                   (set-window-start window (min (point) top-pos) t)))))))
5774       ;; Do horizontal recentering while we're at it.
5775       (when (and (get-buffer-window (current-buffer) t)
5776                  (not (eq gnus-auto-center-summary 'vertical)))
5777         (let ((selected (selected-window)))
5778           (select-window (get-buffer-window (current-buffer) t))
5779           (gnus-summary-position-point)
5780           (gnus-horizontal-recenter)
5781           (select-window selected))))))
5782
5783 (defun gnus-summary-jump-to-group (newsgroup)
5784   "Move point to NEWSGROUP in group mode buffer."
5785   ;; Keep update point of group mode buffer if visible.
5786   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5787       (save-window-excursion
5788         ;; Take care of tree window mode.
5789         (when (get-buffer-window gnus-group-buffer)
5790           (pop-to-buffer gnus-group-buffer))
5791         (gnus-group-jump-to-group newsgroup))
5792     (save-excursion
5793       ;; Take care of tree window mode.
5794       (if (get-buffer-window gnus-group-buffer)
5795           (pop-to-buffer gnus-group-buffer)
5796         (set-buffer gnus-group-buffer))
5797       (gnus-group-jump-to-group newsgroup))))
5798
5799 ;; This function returns a list of article numbers based on the
5800 ;; difference between the ranges of read articles in this group and
5801 ;; the range of active articles.
5802 (defun gnus-list-of-unread-articles (group)
5803   (let* ((read (gnus-info-read (gnus-get-info group)))
5804          (active (or (gnus-active group) (gnus-activate-group group)))
5805          (last (cdr active))
5806          first nlast unread)
5807     ;; If none are read, then all are unread.
5808     (if (not read)
5809         (setq first (car active))
5810       ;; If the range of read articles is a single range, then the
5811       ;; first unread article is the article after the last read
5812       ;; article.  Sounds logical, doesn't it?
5813       (if (and (not (listp (cdr read)))
5814                (or (< (car read) (car active))
5815                    (progn (setq read (list read))
5816                           nil)))
5817           (setq first (max (car active) (1+ (cdr read))))
5818         ;; `read' is a list of ranges.
5819         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5820                                   (caar read)))
5821                   1)
5822           (setq first (car active)))
5823         (while read
5824           (when first
5825             (while (< first nlast)
5826               (push first unread)
5827               (setq first (1+ first))))
5828           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5829           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5830           (setq read (cdr read)))))
5831     ;; And add the last unread articles.
5832     (while (<= first last)
5833       (push first unread)
5834       (setq first (1+ first)))
5835     ;; Return the list of unread articles.
5836     (delq 0 (nreverse unread))))
5837
5838 (defun gnus-list-of-read-articles (group)
5839   "Return a list of unread, unticked and non-dormant articles."
5840   (let* ((info (gnus-get-info group))
5841          (marked (gnus-info-marks info))
5842          (active (gnus-active group)))
5843     (and info active
5844          (gnus-set-difference
5845           (gnus-sorted-complement
5846            (gnus-uncompress-range active)
5847            (gnus-list-of-unread-articles group))
5848           (append
5849            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5850            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5851
5852 ;; Various summary commands
5853
5854 (defun gnus-summary-select-article-buffer ()
5855   "Reconfigure windows to show article buffer."
5856   (interactive)
5857   (if (not (gnus-buffer-live-p gnus-article-buffer))
5858       (error "There is no article buffer for this summary buffer")
5859     (gnus-configure-windows 'article)
5860     (select-window (get-buffer-window gnus-article-buffer))))
5861
5862 (defun gnus-summary-universal-argument (arg)
5863   "Perform any operation on all articles that are process/prefixed."
5864   (interactive "P")
5865   (let ((articles (gnus-summary-work-articles arg))
5866         func article)
5867     (if (eq
5868          (setq
5869           func
5870           (key-binding
5871            (read-key-sequence
5872             (substitute-command-keys
5873              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5874          'undefined)
5875         (gnus-error 1 "Undefined key")
5876       (save-excursion
5877         (while articles
5878           (gnus-summary-goto-subject (setq article (pop articles)))
5879           (let (gnus-newsgroup-processable)
5880             (command-execute func))
5881           (gnus-summary-remove-process-mark article)))))
5882   (gnus-summary-position-point))
5883
5884 (defun gnus-summary-toggle-truncation (&optional arg)
5885   "Toggle truncation of summary lines.
5886 With arg, turn line truncation on iff arg is positive."
5887   (interactive "P")
5888   (setq truncate-lines
5889         (if (null arg) (not truncate-lines)
5890           (> (prefix-numeric-value arg) 0)))
5891   (redraw-display))
5892
5893 (defun gnus-summary-reselect-current-group (&optional all rescan)
5894   "Exit and then reselect the current newsgroup.
5895 The prefix argument ALL means to select all articles."
5896   (interactive "P")
5897   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5898     (error "Ephemeral groups can't be reselected"))
5899   (let ((current-subject (gnus-summary-article-number))
5900         (group gnus-newsgroup-name))
5901     (setq gnus-newsgroup-begin nil)
5902     (gnus-summary-exit)
5903     ;; We have to adjust the point of group mode buffer because
5904     ;; point was moved to the next unread newsgroup by exiting.
5905     (gnus-summary-jump-to-group group)
5906     (when rescan
5907       (save-excursion
5908         (gnus-group-get-new-news-this-group 1)))
5909     (gnus-group-read-group all t)
5910     (gnus-summary-goto-subject current-subject nil t)))
5911
5912 (defun gnus-summary-rescan-group (&optional all)
5913   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5914   (interactive "P")
5915   (gnus-summary-reselect-current-group all t))
5916
5917 (defun gnus-summary-update-info (&optional non-destructive)
5918   (save-excursion
5919     (let ((group gnus-newsgroup-name))
5920       (when group
5921         (when gnus-newsgroup-kill-headers
5922           (setq gnus-newsgroup-killed
5923                 (gnus-compress-sequence
5924                  (nconc
5925                   (gnus-set-sorted-intersection
5926                    (gnus-uncompress-range gnus-newsgroup-killed)
5927                    (setq gnus-newsgroup-unselected
5928                          (sort gnus-newsgroup-unselected '<)))
5929                   (setq gnus-newsgroup-unreads
5930                         (sort gnus-newsgroup-unreads '<)))
5931                  t)))
5932         (unless (listp (cdr gnus-newsgroup-killed))
5933           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5934         (let ((headers gnus-newsgroup-headers))
5935           ;; Set the new ranges of read articles.
5936           (save-excursion
5937             (set-buffer gnus-group-buffer)
5938             (gnus-undo-force-boundary))
5939           (gnus-update-read-articles
5940            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5941           ;; Set the current article marks.
5942           (let ((gnus-newsgroup-scored
5943                  (if (and (not gnus-save-score)
5944                           (not non-destructive))
5945                      nil
5946                    gnus-newsgroup-scored)))
5947             (save-excursion
5948               (gnus-update-marks)))
5949           ;; Do the cross-ref thing.
5950           (when gnus-use-cross-reference
5951             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5952           ;; Do not switch windows but change the buffer to work.
5953           (set-buffer gnus-group-buffer)
5954           (unless (gnus-ephemeral-group-p group)
5955             (gnus-group-update-group group)))))))
5956
5957 (defun gnus-summary-save-newsrc (&optional force)
5958   "Save the current number of read/marked articles in the dribble buffer.
5959 The dribble buffer will then be saved.
5960 If FORCE (the prefix), also save the .newsrc file(s)."
5961   (interactive "P")
5962   (gnus-summary-update-info t)
5963   (if force
5964       (gnus-save-newsrc-file)
5965     (gnus-dribble-save)))
5966
5967 (defun gnus-summary-exit (&optional temporary)
5968   "Exit reading current newsgroup, and then return to group selection mode.
5969 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5970   (interactive)
5971   (gnus-set-global-variables)
5972   (when (gnus-buffer-live-p gnus-article-buffer)
5973     (save-excursion
5974       (set-buffer gnus-article-buffer)
5975       (mm-destroy-parts gnus-article-mime-handles)
5976       ;; Set it to nil for safety reason.
5977       (setq gnus-article-mime-handle-alist nil)
5978       (setq gnus-article-mime-handles nil)))
5979   (gnus-kill-save-kill-buffer)
5980   (gnus-async-halt-prefetch)
5981   (let* ((group gnus-newsgroup-name)
5982          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5983          (mode major-mode)
5984          (group-point nil)
5985          (buf (current-buffer)))
5986     (unless quit-config
5987       ;; Do adaptive scoring, and possibly save score files.
5988       (when gnus-newsgroup-adaptive
5989         (gnus-score-adaptive))
5990       (when gnus-use-scoring
5991         (gnus-score-save)))
5992     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5993     ;; If we have several article buffers, we kill them at exit.
5994     (unless gnus-single-article-buffer
5995       (gnus-kill-buffer gnus-original-article-buffer)
5996       (setq gnus-article-current nil))
5997     (when gnus-use-cache
5998       (gnus-cache-possibly-remove-articles)
5999       (gnus-cache-save-buffers))
6000     (gnus-async-prefetch-remove-group group)
6001     (when gnus-suppress-duplicates
6002       (gnus-dup-enter-articles))
6003     (when gnus-use-trees
6004       (gnus-tree-close group))
6005     (when gnus-use-cache
6006       (gnus-cache-write-active))
6007     ;; Remove entries for this group.
6008     (nnmail-purge-split-history (gnus-group-real-name group))
6009     ;; Make all changes in this group permanent.
6010     (unless quit-config
6011       (gnus-run-hooks 'gnus-exit-group-hook)
6012       (gnus-summary-update-info))
6013     (gnus-close-group group)
6014     ;; Make sure where we were, and go to next newsgroup.
6015     (set-buffer gnus-group-buffer)
6016     (unless quit-config
6017       (gnus-group-jump-to-group group))
6018     (gnus-run-hooks 'gnus-summary-exit-hook)
6019     (unless (or quit-config
6020                 ;; If this group has disappeared from the summary
6021                 ;; buffer, don't skip forwards.
6022                 (not (string= group (gnus-group-group-name))))
6023       (gnus-group-next-unread-group 1))
6024     (setq group-point (point))
6025     (if temporary
6026         nil                             ;Nothing to do.
6027       ;; If we have several article buffers, we kill them at exit.
6028       (unless gnus-single-article-buffer
6029         (gnus-kill-buffer gnus-article-buffer)
6030         (gnus-kill-buffer gnus-original-article-buffer)
6031         (setq gnus-article-current nil))
6032       (set-buffer buf)
6033       (if (not gnus-kill-summary-on-exit)
6034           (progn
6035             (gnus-deaden-summary)
6036             (setq mode nil))
6037        ;; We set all buffer-local variables to nil.  It is unclear why
6038         ;; this is needed, but if we don't, buffer-local variables are
6039         ;; not garbage-collected, it seems.  This would the lead to en
6040         ;; ever-growing Emacs.
6041         (gnus-summary-clear-local-variables)
6042         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6043           (gnus-summary-clear-local-variables))
6044         (when (get-buffer gnus-article-buffer)
6045           (bury-buffer gnus-article-buffer))
6046         ;; We clear the global counterparts of the buffer-local
6047         ;; variables as well, just to be on the safe side.
6048         (set-buffer gnus-group-buffer)
6049         (gnus-summary-clear-local-variables)
6050         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6051           (gnus-summary-clear-local-variables)))
6052       (setq gnus-current-select-method gnus-select-method)
6053       (pop-to-buffer gnus-group-buffer)
6054       (if (not quit-config)
6055           (progn
6056             (goto-char group-point)
6057             (gnus-configure-windows 'group 'force))
6058         (gnus-handle-ephemeral-exit quit-config))
6059       ;; Return to group mode buffer.
6060       (when (eq mode 'gnus-summary-mode)
6061         (gnus-kill-buffer buf))
6062       ;; Clear the current group name.
6063       (unless quit-config
6064         (setq gnus-newsgroup-name nil)))))
6065
6066 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6067 (defun gnus-summary-exit-no-update (&optional no-questions)
6068   "Quit reading current newsgroup without updating read article info."
6069   (interactive)
6070   (let* ((group gnus-newsgroup-name)
6071          (quit-config (gnus-group-quit-config group)))
6072     (when (or no-questions
6073               gnus-expert-user
6074               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6075       (gnus-async-halt-prefetch)
6076       (mapcar 'funcall
6077               (delq 'gnus-summary-expire-articles
6078                     (copy-sequence gnus-summary-prepare-exit-hook)))
6079       (when (gnus-buffer-live-p gnus-article-buffer)
6080         (save-excursion
6081           (set-buffer gnus-article-buffer)
6082           (mm-destroy-parts gnus-article-mime-handles)
6083           ;; Set it to nil for safety reason.
6084           (setq gnus-article-mime-handle-alist nil)
6085           (setq gnus-article-mime-handles nil)))
6086       ;; If we have several article buffers, we kill them at exit.
6087       (unless gnus-single-article-buffer
6088         (gnus-kill-buffer gnus-article-buffer)
6089         (gnus-kill-buffer gnus-original-article-buffer)
6090         (setq gnus-article-current nil))
6091       (if (not gnus-kill-summary-on-exit)
6092           (gnus-deaden-summary)
6093         (gnus-close-group group)
6094         (gnus-summary-clear-local-variables)
6095         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6096           (gnus-summary-clear-local-variables))
6097         (set-buffer gnus-group-buffer)
6098         (gnus-summary-clear-local-variables)
6099         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6100           (gnus-summary-clear-local-variables))
6101         (when (get-buffer gnus-summary-buffer)
6102           (kill-buffer gnus-summary-buffer)))
6103       (unless gnus-single-article-buffer
6104         (setq gnus-article-current nil))
6105       (when gnus-use-trees
6106         (gnus-tree-close group))
6107       (gnus-async-prefetch-remove-group group)
6108       (when (get-buffer gnus-article-buffer)
6109         (bury-buffer gnus-article-buffer))
6110       ;; Return to the group buffer.
6111       (gnus-configure-windows 'group 'force)
6112       ;; Clear the current group name.
6113       (setq gnus-newsgroup-name nil)
6114       (when (equal (gnus-group-group-name) group)
6115         (gnus-group-next-unread-group 1))
6116       (when quit-config
6117         (gnus-handle-ephemeral-exit quit-config)))))
6118
6119 (defun gnus-handle-ephemeral-exit (quit-config)
6120   "Handle movement when leaving an ephemeral group.
6121 The state which existed when entering the ephemeral is reset."
6122   (if (not (buffer-name (car quit-config)))
6123       (gnus-configure-windows 'group 'force)
6124     (set-buffer (car quit-config))
6125     (cond ((eq major-mode 'gnus-summary-mode)
6126            (gnus-set-global-variables))
6127           ((eq major-mode 'gnus-article-mode)
6128            (save-excursion
6129              ;; The `gnus-summary-buffer' variable may point
6130              ;; to the old summary buffer when using a single
6131              ;; article buffer.
6132              (unless (gnus-buffer-live-p gnus-summary-buffer)
6133                (set-buffer gnus-group-buffer))
6134              (set-buffer gnus-summary-buffer)
6135              (gnus-set-global-variables))))
6136     (if (or (eq (cdr quit-config) 'article)
6137             (eq (cdr quit-config) 'pick))
6138         (progn
6139           ;; The current article may be from the ephemeral group
6140           ;; thus it is best that we reload this article
6141           (gnus-summary-show-article)
6142           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6143               (gnus-configure-windows 'pick 'force)
6144             (gnus-configure-windows (cdr quit-config) 'force)))
6145       (gnus-configure-windows (cdr quit-config) 'force))
6146     (when (eq major-mode 'gnus-summary-mode)
6147       (gnus-summary-next-subject 1 nil t)
6148       (gnus-summary-recenter)
6149       (gnus-summary-position-point))))
6150
6151 ;;; Dead summaries.
6152
6153 (defvar gnus-dead-summary-mode-map nil)
6154
6155 (unless gnus-dead-summary-mode-map
6156   (setq gnus-dead-summary-mode-map (make-keymap))
6157   (suppress-keymap gnus-dead-summary-mode-map)
6158   (substitute-key-definition
6159    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6160   (dolist (key '("\C-d" "\r" "\177" [delete]))
6161     (define-key gnus-dead-summary-mode-map
6162       key 'gnus-summary-wake-up-the-dead))
6163   (dolist (key '("q" "Q"))
6164     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6165
6166 (defvar gnus-dead-summary-mode nil
6167   "Minor mode for Gnus summary buffers.")
6168
6169 (defun gnus-dead-summary-mode (&optional arg)
6170   "Minor mode for Gnus summary buffers."
6171   (interactive "P")
6172   (when (eq major-mode 'gnus-summary-mode)
6173     (make-local-variable 'gnus-dead-summary-mode)
6174     (setq gnus-dead-summary-mode
6175           (if (null arg) (not gnus-dead-summary-mode)
6176             (> (prefix-numeric-value arg) 0)))
6177     (when gnus-dead-summary-mode
6178       (gnus-add-minor-mode
6179        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6180
6181 (defun gnus-deaden-summary ()
6182   "Make the current summary buffer into a dead summary buffer."
6183   ;; Kill any previous dead summary buffer.
6184   (when (and gnus-dead-summary
6185              (buffer-name gnus-dead-summary))
6186     (save-excursion
6187       (set-buffer gnus-dead-summary)
6188       (when gnus-dead-summary-mode
6189         (kill-buffer (current-buffer)))))
6190   ;; Make this the current dead summary.
6191   (setq gnus-dead-summary (current-buffer))
6192   (gnus-dead-summary-mode 1)
6193   (let ((name (buffer-name)))
6194     (when (string-match "Summary" name)
6195       (rename-buffer
6196        (concat (substring name 0 (match-beginning 0)) "Dead "
6197                (substring name (match-beginning 0)))
6198        t)
6199       (bury-buffer))))
6200
6201 (defun gnus-kill-or-deaden-summary (buffer)
6202   "Kill or deaden the summary BUFFER."
6203   (save-excursion
6204     (when (and (buffer-name buffer)
6205                (not gnus-single-article-buffer))
6206       (save-excursion
6207         (set-buffer buffer)
6208         (gnus-kill-buffer gnus-article-buffer)
6209         (gnus-kill-buffer gnus-original-article-buffer)))
6210     (cond (gnus-kill-summary-on-exit
6211            (when (and gnus-use-trees
6212                       (gnus-buffer-exists-p buffer))
6213              (save-excursion
6214                (set-buffer buffer)
6215                (gnus-tree-close gnus-newsgroup-name)))
6216            (gnus-kill-buffer buffer))
6217           ((gnus-buffer-exists-p buffer)
6218            (save-excursion
6219              (set-buffer buffer)
6220              (gnus-deaden-summary))))))
6221
6222 (defun gnus-summary-wake-up-the-dead (&rest args)
6223   "Wake up the dead summary buffer."
6224   (interactive)
6225   (gnus-dead-summary-mode -1)
6226   (let ((name (buffer-name)))
6227     (when (string-match "Dead " name)
6228       (rename-buffer
6229        (concat (substring name 0 (match-beginning 0))
6230                (substring name (match-end 0)))
6231        t)))
6232   (gnus-message 3 "This dead summary is now alive again"))
6233
6234 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6235 (defun gnus-summary-fetch-faq (&optional faq-dir)
6236   "Fetch the FAQ for the current group.
6237 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6238 in."
6239   (interactive
6240    (list
6241     (when current-prefix-arg
6242       (completing-read
6243        "Faq dir: " (and (listp gnus-group-faq-directory)
6244                         (mapcar (lambda (file) (list file))
6245                                 gnus-group-faq-directory))))))
6246   (let (gnus-faq-buffer)
6247     (when (setq gnus-faq-buffer
6248                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6249       (gnus-configure-windows 'summary-faq))))
6250
6251 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6252 (defun gnus-summary-describe-group (&optional force)
6253   "Describe the current newsgroup."
6254   (interactive "P")
6255   (gnus-group-describe-group force gnus-newsgroup-name))
6256
6257 (defun gnus-summary-describe-briefly ()
6258   "Describe summary mode commands briefly."
6259   (interactive)
6260   (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")))
6261
6262 ;; Walking around group mode buffer from summary mode.
6263
6264 (defun gnus-summary-next-group (&optional no-article target-group backward)
6265   "Exit current newsgroup and then select next unread newsgroup.
6266 If prefix argument NO-ARTICLE is non-nil, no article is selected
6267 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6268 previous group instead."
6269   (interactive "P")
6270   ;; Stop pre-fetching.
6271   (gnus-async-halt-prefetch)
6272   (let ((current-group gnus-newsgroup-name)
6273         (current-buffer (current-buffer))
6274         entered)
6275    ;; First we semi-exit this group to update Xrefs and all variables.
6276     ;; We can't do a real exit, because the window conf must remain
6277     ;; the same in case the user is prompted for info, and we don't
6278     ;; want the window conf to change before that...
6279     (gnus-summary-exit t)
6280     (while (not entered)
6281       ;; Then we find what group we are supposed to enter.
6282       (set-buffer gnus-group-buffer)
6283       (gnus-group-jump-to-group current-group)
6284       (setq target-group
6285             (or target-group
6286                 (if (eq gnus-keep-same-level 'best)
6287                     (gnus-summary-best-group gnus-newsgroup-name)
6288                   (gnus-summary-search-group backward gnus-keep-same-level))))
6289       (if (not target-group)
6290           ;; There are no further groups, so we return to the group
6291           ;; buffer.
6292           (progn
6293             (gnus-message 5 "Returning to the group buffer")
6294             (setq entered t)
6295             (when (gnus-buffer-live-p current-buffer)
6296               (set-buffer current-buffer)
6297               (gnus-summary-exit))
6298             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6299         ;; We try to enter the target group.
6300         (gnus-group-jump-to-group target-group)
6301         (let ((unreads (gnus-group-group-unread)))
6302           (if (and (or (eq t unreads)
6303                        (and unreads (not (zerop unreads))))
6304                    (gnus-summary-read-group
6305                     target-group nil no-article
6306                     (and (buffer-name current-buffer) current-buffer)
6307                     nil backward))
6308               (setq entered t)
6309             (setq current-group target-group
6310                   target-group nil)))))))
6311
6312 (defun gnus-summary-prev-group (&optional no-article)
6313   "Exit current newsgroup and then select previous unread newsgroup.
6314 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6315   (interactive "P")
6316   (gnus-summary-next-group no-article nil t))
6317
6318 ;; Walking around summary lines.
6319
6320 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6321   "Go to the first unread subject.
6322 If UNREAD is non-nil, go to the first unread article.
6323 Returns the article selected or nil if there are no unread articles."
6324   (interactive "P")
6325   (prog1
6326       (cond
6327        ;; Empty summary.
6328        ((null gnus-newsgroup-data)
6329         (gnus-message 3 "No articles in the group")
6330         nil)
6331        ;; Pick the first article.
6332        ((not unread)
6333         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6334         (gnus-data-number (car gnus-newsgroup-data)))
6335        ;; No unread articles.
6336        ((null gnus-newsgroup-unreads)
6337         (gnus-message 3 "No more unread articles")
6338         nil)
6339        ;; Find the first unread article.
6340        (t
6341         (let ((data gnus-newsgroup-data))
6342           (while (and data
6343                       (and (not (and undownloaded
6344                                      (eq gnus-undownloaded-mark
6345                                          (gnus-data-mark (car data)))))
6346                            (if unseen
6347                                (or (not (memq
6348                                          (gnus-data-number (car data))
6349                                          gnus-newsgroup-unseen))
6350                                    (not (gnus-data-unread-p (car data))))
6351                              (not (gnus-data-unread-p (car data))))))
6352             (setq data (cdr data)))
6353           (when data
6354             (goto-char (gnus-data-pos (car data)))
6355             (gnus-data-number (car data))))))
6356     (gnus-summary-position-point)))
6357
6358 (defun gnus-summary-next-subject (n &optional unread dont-display)
6359   "Go to next N'th summary line.
6360 If N is negative, go to the previous N'th subject line.
6361 If UNREAD is non-nil, only unread articles are selected.
6362 The difference between N and the actual number of steps taken is
6363 returned."
6364   (interactive "p")
6365   (let ((backward (< n 0))
6366         (n (abs n)))
6367     (while (and (> n 0)
6368                 (if backward
6369                     (gnus-summary-find-prev unread)
6370                   (gnus-summary-find-next unread)))
6371       (unless (zerop (setq n (1- n)))
6372         (gnus-summary-show-thread)))
6373     (when (/= 0 n)
6374       (gnus-message 7 "No more%s articles"
6375                     (if unread " unread" "")))
6376     (unless dont-display
6377       (gnus-summary-recenter)
6378       (gnus-summary-position-point))
6379     n))
6380
6381 (defun gnus-summary-next-unread-subject (n)
6382   "Go to next N'th unread summary line."
6383   (interactive "p")
6384   (gnus-summary-next-subject n t))
6385
6386 (defun gnus-summary-prev-subject (n &optional unread)
6387   "Go to previous N'th summary line.
6388 If optional argument UNREAD is non-nil, only unread article is selected."
6389   (interactive "p")
6390   (gnus-summary-next-subject (- n) unread))
6391
6392 (defun gnus-summary-prev-unread-subject (n)
6393   "Go to previous N'th unread summary line."
6394   (interactive "p")
6395   (gnus-summary-next-subject (- n) t))
6396
6397 (defun gnus-summary-goto-subject (article &optional force silent)
6398   "Go the subject line of ARTICLE.
6399 If FORCE, also allow jumping to articles not currently shown."
6400   (interactive "nArticle number: ")
6401   (let ((b (point))
6402         (data (gnus-data-find article)))
6403     ;; We read in the article if we have to.
6404     (and (not data)
6405          force
6406          (gnus-summary-insert-subject
6407           article
6408           (if (or (numberp force) (vectorp force)) force)
6409           t)
6410          (setq data (gnus-data-find article)))
6411     (goto-char b)
6412     (if (not data)
6413         (progn
6414           (unless silent
6415             (gnus-message 3 "Can't find article %d" article))
6416           nil)
6417       (let ((pt (gnus-data-pos data)))
6418         (goto-char pt)
6419         (gnus-summary-set-article-display-arrow pt))
6420       (gnus-summary-position-point)
6421       article)))
6422
6423 ;; Walking around summary lines with displaying articles.
6424
6425 (defun gnus-summary-expand-window (&optional arg)
6426   "Make the summary buffer take up the entire Emacs frame.
6427 Given a prefix, will force an `article' buffer configuration."
6428   (interactive "P")
6429   (if arg
6430       (gnus-configure-windows 'article 'force)
6431     (gnus-configure-windows 'summary 'force)))
6432
6433 (defun gnus-summary-display-article (article &optional all-header)
6434   "Display ARTICLE in article buffer."
6435   (when (gnus-buffer-live-p gnus-article-buffer)
6436     (with-current-buffer gnus-article-buffer
6437       (mm-enable-multibyte-mule4)))
6438   (gnus-set-global-variables)
6439   (when (gnus-buffer-live-p gnus-article-buffer)
6440     (with-current-buffer gnus-article-buffer
6441       (setq gnus-article-charset gnus-newsgroup-charset)
6442       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6443       (mm-enable-multibyte-mule4)))
6444   (if (null article)
6445       nil
6446     (prog1
6447         (if gnus-summary-display-article-function
6448             (funcall gnus-summary-display-article-function article all-header)
6449           (gnus-article-prepare article all-header))
6450       (gnus-run-hooks 'gnus-select-article-hook)
6451       (when (and gnus-current-article
6452                  (not (zerop gnus-current-article)))
6453         (gnus-summary-goto-subject gnus-current-article))
6454       (gnus-summary-recenter)
6455       (when (and gnus-use-trees gnus-show-threads)
6456         (gnus-possibly-generate-tree article)
6457         (gnus-highlight-selected-tree article))
6458       ;; Successfully display article.
6459       (gnus-article-set-window-start
6460        (cdr (assq article gnus-newsgroup-bookmarks))))))
6461
6462 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6463   "Select the current article.
6464 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6465 non-nil, the article will be re-fetched even if it already present in
6466 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6467 be displayed."
6468   ;; Make sure we are in the summary buffer to work around bbdb bug.
6469   (unless (eq major-mode 'gnus-summary-mode)
6470     (set-buffer gnus-summary-buffer))
6471   (let ((article (or article (gnus-summary-article-number)))
6472         (all-headers (not (not all-headers))) ;Must be t or nil.
6473         gnus-summary-display-article-function)
6474     (and (not pseudo)
6475          (gnus-summary-article-pseudo-p article)
6476          (error "This is a pseudo-article"))
6477     (save-excursion
6478       (set-buffer gnus-summary-buffer)
6479       (if (or (and gnus-single-article-buffer
6480                    (or (null gnus-current-article)
6481                        (null gnus-article-current)
6482                        (null (get-buffer gnus-article-buffer))
6483                        (not (eq article (cdr gnus-article-current)))
6484                        (not (equal (car gnus-article-current)
6485                                    gnus-newsgroup-name))))
6486               (and (not gnus-single-article-buffer)
6487                    (or (null gnus-current-article)
6488                        (not (eq gnus-current-article article))))
6489               force)
6490        ;; The requested article is different from the current article.
6491           (progn
6492             (gnus-summary-display-article article all-headers)
6493             (when (gnus-buffer-live-p gnus-article-buffer)
6494               (with-current-buffer gnus-article-buffer
6495                 (if (not gnus-article-decoded-p) ;; a local variable
6496                     (mm-disable-multibyte-mule4))))
6497             (when (or all-headers gnus-show-all-headers)
6498               (gnus-article-show-all-headers))
6499             (gnus-article-set-window-start
6500              (cdr (assq article gnus-newsgroup-bookmarks)))
6501             article)
6502         (when (or all-headers gnus-show-all-headers)
6503           (gnus-article-show-all-headers))
6504         'old))))
6505
6506 (defun gnus-summary-force-verify-and-decrypt ()
6507   (interactive)
6508   (let ((mm-verify-option 'known)
6509         (mm-decrypt-option 'known))
6510     (gnus-summary-select-article nil 'force)))
6511
6512 (defun gnus-summary-set-current-mark (&optional current-mark)
6513   "Obsolete function."
6514   nil)
6515
6516 (defun gnus-summary-next-article (&optional unread subject backward push)
6517   "Select the next article.
6518 If UNREAD, only unread articles are selected.
6519 If SUBJECT, only articles with SUBJECT are selected.
6520 If BACKWARD, the previous article is selected instead of the next."
6521   (interactive "P")
6522   (cond
6523    ;; Is there such an article?
6524    ((and (gnus-summary-search-forward unread subject backward)
6525          (or (gnus-summary-display-article (gnus-summary-article-number))
6526              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6527     (gnus-summary-position-point))
6528    ;; If not, we try the first unread, if that is wanted.
6529    ((and subject
6530          gnus-auto-select-same
6531          (gnus-summary-first-unread-article))
6532     (gnus-summary-position-point)
6533     (gnus-message 6 "Wrapped"))
6534    ;; Try to get next/previous article not displayed in this group.
6535    ((and gnus-auto-extend-newsgroup
6536          (not unread) (not subject))
6537     (gnus-summary-goto-article
6538      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6539      nil (count-lines (point-min) (point))))
6540    ;; Go to next/previous group.
6541    (t
6542     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6543       (gnus-summary-jump-to-group gnus-newsgroup-name))
6544     (let ((cmd last-command-char)
6545           (point
6546            (save-excursion
6547              (set-buffer gnus-group-buffer)
6548              (point)))
6549           (group
6550            (if (eq gnus-keep-same-level 'best)
6551                (gnus-summary-best-group gnus-newsgroup-name)
6552              (gnus-summary-search-group backward gnus-keep-same-level))))
6553       ;; For some reason, the group window gets selected.  We change
6554       ;; it back.
6555       (select-window (get-buffer-window (current-buffer)))
6556       ;; Select next unread newsgroup automagically.
6557       (cond
6558        ((or (not gnus-auto-select-next)
6559             (not cmd))
6560         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6561        ((or (eq gnus-auto-select-next 'quietly)
6562             (and (eq gnus-auto-select-next 'slightly-quietly)
6563                  push)
6564             (and (eq gnus-auto-select-next 'almost-quietly)
6565                  (gnus-summary-last-article-p)))
6566         ;; Select quietly.
6567         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6568             (gnus-summary-exit)
6569           (gnus-message 7 "No more%s articles (%s)..."
6570                         (if unread " unread" "")
6571                         (if group (concat "selecting " group)
6572                           "exiting"))
6573           (gnus-summary-next-group nil group backward)))
6574        (t
6575         (when (gnus-key-press-event-p last-input-event)
6576           (gnus-summary-walk-group-buffer
6577            gnus-newsgroup-name cmd unread backward point))))))))
6578
6579 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6580   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6581                       (?\C-p (gnus-group-prev-unread-group 1))))
6582         (cursor-in-echo-area t)
6583         keve key group ended)
6584     (save-excursion
6585       (set-buffer gnus-group-buffer)
6586       (goto-char start)
6587       (setq group
6588             (if (eq gnus-keep-same-level 'best)
6589                 (gnus-summary-best-group gnus-newsgroup-name)
6590               (gnus-summary-search-group backward gnus-keep-same-level))))
6591     (while (not ended)
6592       (gnus-message
6593        5 "No more%s articles%s" (if unread " unread" "")
6594        (if (and group
6595                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6596            (format " (Type %s for %s [%s])"
6597                    (single-key-description cmd) group
6598                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6599          (format " (Type %s to exit %s)"
6600                  (single-key-description cmd)
6601                  gnus-newsgroup-name)))
6602       ;; Confirm auto selection.
6603       (setq key (car (setq keve (gnus-read-event-char))))
6604       (setq ended t)
6605       (cond
6606        ((assq key keystrokes)
6607         (let ((obuf (current-buffer)))
6608           (switch-to-buffer gnus-group-buffer)
6609           (when group
6610             (gnus-group-jump-to-group group))
6611           (eval (cadr (assq key keystrokes)))
6612           (setq group (gnus-group-group-name))
6613           (switch-to-buffer obuf))
6614         (setq ended nil))
6615        ((equal key cmd)
6616         (if (or (not group)
6617                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6618             (gnus-summary-exit)
6619           (gnus-summary-next-group nil group backward)))
6620        (t
6621         (push (cdr keve) unread-command-events))))))
6622
6623 (defun gnus-summary-next-unread-article ()
6624   "Select unread article after current one."
6625   (interactive)
6626   (gnus-summary-next-article
6627    (or (not (eq gnus-summary-goto-unread 'never))
6628        (gnus-summary-last-article-p (gnus-summary-article-number)))
6629    (and gnus-auto-select-same
6630         (gnus-summary-article-subject))))
6631
6632 (defun gnus-summary-prev-article (&optional unread subject)
6633   "Select the article after the current one.
6634 If UNREAD is non-nil, only unread articles are selected."
6635   (interactive "P")
6636   (gnus-summary-next-article unread subject t))
6637
6638 (defun gnus-summary-prev-unread-article ()
6639   "Select unread article before current one."
6640   (interactive)
6641   (gnus-summary-prev-article
6642    (or (not (eq gnus-summary-goto-unread 'never))
6643        (gnus-summary-first-article-p (gnus-summary-article-number)))
6644    (and gnus-auto-select-same
6645         (gnus-summary-article-subject))))
6646
6647 (defun gnus-summary-next-page (&optional lines circular)
6648   "Show next page of the selected article.
6649 If at the end of the current article, select the next article.
6650 LINES says how many lines should be scrolled up.
6651
6652 If CIRCULAR is non-nil, go to the start of the article instead of
6653 selecting the next article when reaching the end of the current
6654 article."
6655   (interactive "P")
6656   (setq gnus-summary-buffer (current-buffer))
6657   (gnus-set-global-variables)
6658   (let ((article (gnus-summary-article-number))
6659         (article-window (get-buffer-window gnus-article-buffer t))
6660         endp)
6661     ;; If the buffer is empty, we have no article.
6662     (unless article
6663       (error "No article to select"))
6664     (gnus-configure-windows 'article)
6665     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6666         (if (and (eq gnus-summary-goto-unread 'never)
6667                  (not (gnus-summary-last-article-p article)))
6668             (gnus-summary-next-article)
6669           (gnus-summary-next-unread-article))
6670       (if (or (null gnus-current-article)
6671               (null gnus-article-current)
6672               (/= article (cdr gnus-article-current))
6673               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6674           ;; Selected subject is different from current article's.
6675           (gnus-summary-display-article article)
6676         (when article-window
6677           (gnus-eval-in-buffer-window gnus-article-buffer
6678             (setq endp (gnus-article-next-page lines)))
6679           (when endp
6680             (cond (circular
6681                    (gnus-summary-beginning-of-article))
6682                   (lines
6683                    (gnus-message 3 "End of message"))
6684                   ((null lines)
6685                    (if (and (eq gnus-summary-goto-unread 'never)
6686                             (not (gnus-summary-last-article-p article)))
6687                        (gnus-summary-next-article)
6688                      (gnus-summary-next-unread-article))))))))
6689     (gnus-summary-recenter)
6690     (gnus-summary-position-point)))
6691
6692 (defun gnus-summary-prev-page (&optional lines move)
6693   "Show previous page of selected article.
6694 Argument LINES specifies lines to be scrolled down.
6695 If MOVE, move to the previous unread article if point is at
6696 the beginning of the buffer."
6697   (interactive "P")
6698   (let ((article (gnus-summary-article-number))
6699         (article-window (get-buffer-window gnus-article-buffer t))
6700         endp)
6701     (gnus-configure-windows 'article)
6702     (if (or (null gnus-current-article)
6703             (null gnus-article-current)
6704             (/= article (cdr gnus-article-current))
6705             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6706         ;; Selected subject is different from current article's.
6707         (gnus-summary-display-article article)
6708       (gnus-summary-recenter)
6709       (when article-window
6710         (gnus-eval-in-buffer-window gnus-article-buffer
6711           (setq endp (gnus-article-prev-page lines)))
6712         (when (and move endp)
6713           (cond (lines
6714                  (gnus-message 3 "Beginning of message"))
6715                 ((null lines)
6716                  (if (and (eq gnus-summary-goto-unread 'never)
6717                           (not (gnus-summary-first-article-p article)))
6718                      (gnus-summary-prev-article)
6719                    (gnus-summary-prev-unread-article))))))))
6720   (gnus-summary-position-point))
6721
6722 (defun gnus-summary-prev-page-or-article (&optional lines)
6723   "Show previous page of selected article.
6724 Argument LINES specifies lines to be scrolled down.
6725 If at the beginning of the article, go to the next article."
6726   (interactive "P")
6727   (gnus-summary-prev-page lines t))
6728
6729 (defun gnus-summary-scroll-up (lines)
6730   "Scroll up (or down) one line current article.
6731 Argument LINES specifies lines to be scrolled up (or down if negative)."
6732   (interactive "p")
6733   (gnus-configure-windows 'article)
6734   (gnus-summary-show-thread)
6735   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6736     (gnus-eval-in-buffer-window gnus-article-buffer
6737       (cond ((> lines 0)
6738              (when (gnus-article-next-page lines)
6739                (gnus-message 3 "End of message")))
6740             ((< lines 0)
6741              (gnus-article-prev-page (- lines))))))
6742   (gnus-summary-recenter)
6743   (gnus-summary-position-point))
6744
6745 (defun gnus-summary-scroll-down (lines)
6746   "Scroll down (or up) one line current article.
6747 Argument LINES specifies lines to be scrolled down (or up if negative)."
6748   (interactive "p")
6749   (gnus-summary-scroll-up (- lines)))
6750
6751 (defun gnus-summary-next-same-subject ()
6752   "Select next article which has the same subject as current one."
6753   (interactive)
6754   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6755
6756 (defun gnus-summary-prev-same-subject ()
6757   "Select previous article which has the same subject as current one."
6758   (interactive)
6759   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6760
6761 (defun gnus-summary-next-unread-same-subject ()
6762   "Select next unread article which has the same subject as current one."
6763   (interactive)
6764   (gnus-summary-next-article t (gnus-summary-article-subject)))
6765
6766 (defun gnus-summary-prev-unread-same-subject ()
6767   "Select previous unread article which has the same subject as current one."
6768   (interactive)
6769   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6770
6771 (defun gnus-summary-first-unread-article ()
6772   "Select 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-display-article (gnus-summary-article-number)))
6780     (gnus-summary-position-point)))
6781
6782 (defun gnus-summary-first-unread-subject ()
6783   "Place the point on the subject line of the first unread article.
6784 Return nil if there are no unread articles."
6785   (interactive)
6786   (prog1
6787       (when (gnus-summary-first-subject t)
6788         (gnus-summary-show-thread)
6789         (gnus-summary-first-subject t))
6790     (gnus-summary-position-point)))
6791
6792 (defun gnus-summary-first-unseen-subject ()
6793   "Place the point on the subject line of the first unseen article.
6794 Return nil if there are no unseen articles."
6795   (interactive)
6796   (prog1
6797       (when (gnus-summary-first-subject t t t)
6798         (gnus-summary-show-thread)
6799         (gnus-summary-first-subject t t t))
6800     (gnus-summary-position-point)))
6801
6802 (defun gnus-summary-first-article ()
6803   "Select the first article.
6804 Return nil if there are no articles."
6805   (interactive)
6806   (prog1
6807       (when (gnus-summary-first-subject)
6808         (gnus-summary-show-thread)
6809         (gnus-summary-first-subject)
6810         (gnus-summary-display-article (gnus-summary-article-number)))
6811     (gnus-summary-position-point)))
6812
6813 (defun gnus-summary-best-unread-article (&optional arg)
6814   "Select the unread article with the highest score.
6815 If given a prefix argument, select the next unread article that has a
6816 score higher than the default score."
6817   (interactive "P")
6818   (let ((article (if arg
6819                      (gnus-summary-better-unread-subject)
6820                    (gnus-summary-best-unread-subject))))
6821     (if article
6822         (gnus-summary-goto-article article)
6823       (error "No unread articles"))))
6824
6825 (defun gnus-summary-best-unread-subject ()
6826   "Select the unread subject with the highest score."
6827   (interactive)
6828   (let ((best -1000000)
6829         (data gnus-newsgroup-data)
6830         article score)
6831     (while data
6832       (and (gnus-data-unread-p (car data))
6833            (> (setq score
6834                     (gnus-summary-article-score (gnus-data-number (car data))))
6835               best)
6836            (setq best score
6837                  article (gnus-data-number (car data))))
6838       (setq data (cdr data)))
6839     (when article
6840       (gnus-summary-goto-subject article))
6841     (gnus-summary-position-point)
6842     article))
6843
6844 (defun gnus-summary-better-unread-subject ()
6845   "Select the first unread subject that has a score over the default score."
6846   (interactive)
6847   (let ((data gnus-newsgroup-data)
6848         article score)
6849     (while (and (setq article (gnus-data-number (car data)))
6850                 (or (gnus-data-read-p (car data))
6851                     (not (> (gnus-summary-article-score article)
6852                             gnus-summary-default-score))))
6853       (setq data (cdr data)))
6854     (when article
6855       (gnus-summary-goto-subject article))
6856     (gnus-summary-position-point)
6857     article))
6858
6859 (defun gnus-summary-last-subject ()
6860   "Go to the last displayed subject line in the group."
6861   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6862     (when article
6863       (gnus-summary-goto-subject article))))
6864
6865 (defun gnus-summary-goto-article (article &optional all-headers force)
6866   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6867 If ALL-HEADERS is non-nil, no header lines are hidden.
6868 If FORCE, go to the article even if it isn't displayed.  If FORCE
6869 is a number, it is the line the article is to be displayed on."
6870   (interactive
6871    (list
6872     (completing-read
6873      "Article number or Message-ID: "
6874      (mapcar (lambda (number) (list (int-to-string number)))
6875              gnus-newsgroup-limit))
6876     current-prefix-arg
6877     t))
6878   (prog1
6879       (if (and (stringp article)
6880                (string-match "@" article))
6881           (gnus-summary-refer-article article)
6882         (when (stringp article)
6883           (setq article (string-to-number article)))
6884         (if (gnus-summary-goto-subject article force)
6885             (gnus-summary-display-article article all-headers)
6886           (gnus-message 4 "Couldn't go to article %s" article) nil))
6887     (gnus-summary-position-point)))
6888
6889 (defun gnus-summary-goto-last-article ()
6890   "Go to the previously read article."
6891   (interactive)
6892   (prog1
6893       (when gnus-last-article
6894         (gnus-summary-goto-article gnus-last-article nil t))
6895     (gnus-summary-position-point)))
6896
6897 (defun gnus-summary-pop-article (number)
6898   "Pop one article off the history and go to the previous.
6899 NUMBER articles will be popped off."
6900   (interactive "p")
6901   (let (to)
6902     (setq gnus-newsgroup-history
6903           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6904     (if to
6905         (gnus-summary-goto-article (car to) nil t)
6906       (error "Article history empty")))
6907   (gnus-summary-position-point))
6908
6909 ;; Summary commands and functions for limiting the summary buffer.
6910
6911 (defun gnus-summary-limit-to-articles (n)
6912   "Limit the summary buffer to the next N articles.
6913 If not given a prefix, use the process marked articles instead."
6914   (interactive "P")
6915   (prog1
6916       (let ((articles (gnus-summary-work-articles n)))
6917         (setq gnus-newsgroup-processable nil)
6918         (gnus-summary-limit articles))
6919     (gnus-summary-position-point)))
6920
6921 (defun gnus-summary-pop-limit (&optional total)
6922   "Restore the previous limit.
6923 If given a prefix, remove all limits."
6924   (interactive "P")
6925   (when total
6926     (setq gnus-newsgroup-limits
6927           (list (mapcar (lambda (h) (mail-header-number h))
6928                         gnus-newsgroup-headers))))
6929   (unless gnus-newsgroup-limits
6930     (error "No limit to pop"))
6931   (prog1
6932       (gnus-summary-limit nil 'pop)
6933     (gnus-summary-position-point)))
6934
6935 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6936   "Limit the summary buffer to articles that have subjects that match a regexp.
6937 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6938   (interactive
6939    (list (read-string (if current-prefix-arg
6940                           "Exclude subject (regexp): "
6941                         "Limit to subject (regexp): "))
6942          nil current-prefix-arg))
6943   (unless header
6944     (setq header "subject"))
6945   (when (not (equal "" subject))
6946     (prog1
6947         (let ((articles (gnus-summary-find-matching
6948                          (or header "subject") subject 'all nil nil
6949                          not-matching)))
6950           (unless articles
6951             (error "Found no matches for \"%s\"" subject))
6952           (gnus-summary-limit articles))
6953       (gnus-summary-position-point))))
6954
6955 (defun gnus-summary-limit-to-author (from &optional not-matching)
6956   "Limit the summary buffer to articles that have authors that match a regexp.
6957 If NOT-MATCHING, excluding articles that have authors that match a regexp."
6958   (interactive
6959    (list (read-string (if current-prefix-arg
6960                           "Exclude author (regexp): "
6961                         "Limit to author (regexp): "))
6962          current-prefix-arg))
6963   (gnus-summary-limit-to-subject from "from" not-matching))
6964
6965 (defun gnus-summary-limit-to-age (age &optional younger-p)
6966   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6967 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6968 articles that are younger than AGE days."
6969   (interactive
6970    (let ((younger current-prefix-arg)
6971          (days-got nil)
6972          days)
6973      (while (not days-got)
6974        (setq days (if younger
6975                       (read-string "Limit to articles within (in days): ")
6976                     (read-string "Limit to articles older than (in days): ")))
6977        (when (> (length days) 0)
6978          (setq days (read days)))
6979        (if (numberp days)
6980            (progn 
6981              (setq days-got t)
6982              (if (< days 0)
6983                  (progn 
6984                    (setq younger (not younger))
6985                    (setq days (* days -1)))))
6986          (message "Please enter a number.")
6987          (sleep-for 1)))
6988      (list days younger)))
6989   (prog1
6990       (let ((data gnus-newsgroup-data)
6991             (cutoff (days-to-time age))
6992             articles d date is-younger)
6993         (while (setq d (pop data))
6994           (when (and (vectorp (gnus-data-header d))
6995                      (setq date (mail-header-date (gnus-data-header d))))
6996             (setq is-younger (time-less-p
6997                               (time-since (condition-case ()
6998                                               (date-to-time date)
6999                                             (error '(0 0))))
7000                               cutoff))
7001             (when (if younger-p
7002                       is-younger
7003                     (not is-younger))
7004               (push (gnus-data-number d) articles))))
7005         (gnus-summary-limit (nreverse articles)))
7006     (gnus-summary-position-point)))
7007
7008 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7009   "Limit the summary buffer to articles that match an 'extra' header."
7010   (interactive
7011    (let ((header
7012           (intern
7013            (gnus-completing-read
7014             (symbol-name (car gnus-extra-headers))
7015             (if current-prefix-arg
7016                 "Exclude extra header:"
7017               "Limit extra header:")
7018             (mapcar (lambda (x)
7019                       (cons (symbol-name x) x))
7020                     gnus-extra-headers)
7021             nil
7022             t))))
7023      (list header
7024            (read-string (format "%s header %s (regexp): "
7025                                 (if current-prefix-arg "Exclude" "Limit to")
7026                                 header))
7027            current-prefix-arg)))
7028   (when (not (equal "" regexp))
7029     (prog1
7030         (let ((articles (gnus-summary-find-matching
7031                          (cons 'extra header) regexp 'all nil nil
7032                          not-matching)))
7033           (unless articles
7034             (error "Found no matches for \"%s\"" regexp))
7035           (gnus-summary-limit articles))
7036       (gnus-summary-position-point))))
7037
7038 (defun gnus-summary-limit-to-display-predicate ()
7039   "Limit the summary buffer to the predicated in the `display' group parameter."
7040   (interactive)
7041   (unless gnus-newsgroup-display
7042     (error "There is no `display' group parameter"))
7043   (let (articles)
7044     (dolist (number gnus-newsgroup-articles)
7045       (when (funcall gnus-newsgroup-display)
7046         (push number articles)))
7047     (gnus-summary-limit articles))
7048   (gnus-summary-position-point))
7049
7050 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7051 (make-obsolete
7052  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7053
7054 (defun gnus-summary-limit-to-unread (&optional all)
7055   "Limit the summary buffer to articles that are not marked as read.
7056 If ALL is non-nil, limit strictly to unread articles."
7057   (interactive "P")
7058   (if all
7059       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7060     (gnus-summary-limit-to-marks
7061      ;; Concat all the marks that say that an article is read and have
7062      ;; those removed.
7063      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7064            gnus-killed-mark gnus-kill-file-mark
7065            gnus-low-score-mark gnus-expirable-mark
7066            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7067            gnus-duplicate-mark gnus-souped-mark)
7068      'reverse)))
7069
7070 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7071 (make-obsolete 'gnus-summary-delete-marked-with
7072                'gnus-summary-limit-exlude-marks)
7073
7074 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7075   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7076 If REVERSE, limit the summary buffer to articles that are marked
7077 with MARKS.  MARKS can either be a string of marks or a list of marks.
7078 Returns how many articles were removed."
7079   (interactive "sMarks: ")
7080   (gnus-summary-limit-to-marks marks t))
7081
7082 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7083   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7084 If REVERSE (the prefix), limit the summary buffer to articles that are
7085 not marked with MARKS.  MARKS can either be a string of marks or a
7086 list of marks.
7087 Returns how many articles were removed."
7088   (interactive "sMarks: \nP")
7089   (prog1
7090       (let ((data gnus-newsgroup-data)
7091             (marks (if (listp marks) marks
7092                      (append marks nil))) ; Transform to list.
7093             articles)
7094         (while data
7095           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7096                   (memq (gnus-data-mark (car data)) marks))
7097             (push (gnus-data-number (car data)) articles))
7098           (setq data (cdr data)))
7099         (gnus-summary-limit articles))
7100     (gnus-summary-position-point)))
7101
7102 (defun gnus-summary-limit-to-score (score)
7103   "Limit to articles with score at or above SCORE."
7104   (interactive "NLimit to articles with score of at least: ")
7105   (let ((data gnus-newsgroup-data)
7106         articles)
7107     (while data
7108       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7109                 score)
7110         (push (gnus-data-number (car data)) articles))
7111       (setq data (cdr data)))
7112     (prog1
7113         (gnus-summary-limit articles)
7114       (gnus-summary-position-point))))
7115
7116 (defun gnus-summary-limit-include-thread (id)
7117   "Display all the hidden articles that is in the thread with ID in it.
7118 When called interactively, ID is the Message-ID of the current
7119 article."
7120   (interactive (list (mail-header-id (gnus-summary-article-header))))
7121   (let ((articles (gnus-articles-in-thread
7122                    (gnus-id-to-thread (gnus-root-id id)))))
7123     (prog1
7124         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7125       (gnus-summary-limit-include-matching-articles
7126        "subject"
7127        (regexp-quote (gnus-simplify-subject-re
7128                       (mail-header-subject (gnus-id-to-header id)))))
7129       (gnus-summary-position-point))))
7130
7131 (defun gnus-summary-limit-include-matching-articles (header regexp)
7132   "Display all the hidden articles that have HEADERs that match REGEXP."
7133   (interactive (list (read-string "Match on header: ")
7134                      (read-string "Regexp: ")))
7135   (let ((articles (gnus-find-matching-articles header regexp)))
7136     (prog1
7137         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7138       (gnus-summary-position-point))))
7139
7140 (defun gnus-summary-limit-include-dormant ()
7141   "Display all the hidden articles that are marked as dormant.
7142 Note that this command only works on a subset of the articles currently
7143 fetched for this group."
7144   (interactive)
7145   (unless gnus-newsgroup-dormant
7146     (error "There are no dormant articles in this group"))
7147   (prog1
7148       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7149     (gnus-summary-position-point)))
7150
7151 (defun gnus-summary-limit-exclude-dormant ()
7152   "Hide all dormant articles."
7153   (interactive)
7154   (prog1
7155       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7156     (gnus-summary-position-point)))
7157
7158 (defun gnus-summary-limit-exclude-childless-dormant ()
7159   "Hide all dormant articles that have no children."
7160   (interactive)
7161   (let ((data (gnus-data-list t))
7162         articles d children)
7163     ;; Find all articles that are either not dormant or have
7164     ;; children.
7165     (while (setq d (pop data))
7166       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7167                 (and (setq children
7168                            (gnus-article-children (gnus-data-number d)))
7169                      (let (found)
7170                        (while children
7171                          (when (memq (car children) articles)
7172                            (setq children nil
7173                                  found t))
7174                          (pop children))
7175                        found)))
7176         (push (gnus-data-number d) articles)))
7177     ;; Do the limiting.
7178     (prog1
7179         (gnus-summary-limit articles)
7180       (gnus-summary-position-point))))
7181
7182 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7183   "Mark all unread excluded articles as read.
7184 If ALL, mark even excluded ticked and dormants as read."
7185   (interactive "P")
7186   (let ((articles (gnus-sorted-complement
7187                    (sort
7188                     (mapcar (lambda (h) (mail-header-number h))
7189                             gnus-newsgroup-headers)
7190                     '<)
7191                    (sort gnus-newsgroup-limit '<)))
7192         article)
7193     (setq gnus-newsgroup-unreads
7194           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7195     (if all
7196         (setq gnus-newsgroup-dormant nil
7197               gnus-newsgroup-marked nil
7198               gnus-newsgroup-reads
7199               (nconc
7200                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7201                gnus-newsgroup-reads))
7202       (while (setq article (pop articles))
7203         (unless (or (memq article gnus-newsgroup-dormant)
7204                     (memq article gnus-newsgroup-marked))
7205           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7206
7207 (defun gnus-summary-limit (articles &optional pop)
7208   (if pop
7209       ;; We pop the previous limit off the stack and use that.
7210       (setq articles (car gnus-newsgroup-limits)
7211             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7212     ;; We use the new limit, so we push the old limit on the stack.
7213     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7214   ;; Set the limit.
7215   (setq gnus-newsgroup-limit articles)
7216   (let ((total (length gnus-newsgroup-data))
7217         (data (gnus-data-find-list (gnus-summary-article-number)))
7218         (gnus-summary-mark-below nil)   ; Inhibit this.
7219         found)
7220     ;; This will do all the work of generating the new summary buffer
7221     ;; according to the new limit.
7222     (gnus-summary-prepare)
7223     ;; Hide any threads, possibly.
7224     (gnus-summary-maybe-hide-threads)
7225     ;; Try to return to the article you were at, or one in the
7226     ;; neighborhood.
7227     (when data
7228       ;; We try to find some article after the current one.
7229       (while data
7230         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7231           (setq data nil
7232                 found t))
7233         (setq data (cdr data))))
7234     (unless found
7235       ;; If there is no data, that means that we were after the last
7236       ;; article.  The same goes when we can't find any articles
7237       ;; after the current one.
7238       (goto-char (point-max))
7239       (gnus-summary-find-prev))
7240     (gnus-set-mode-line 'summary)
7241     ;; We return how many articles were removed from the summary
7242     ;; buffer as a result of the new limit.
7243     (- total (length gnus-newsgroup-data))))
7244
7245 (defsubst gnus-invisible-cut-children (threads)
7246   (let ((num 0))
7247     (while threads
7248       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7249         (incf num))
7250       (pop threads))
7251     (< num 2)))
7252
7253 (defsubst gnus-cut-thread (thread)
7254   "Go forwards in the thread until we find an article that we want to display."
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     ;; Deal with old-fetched headers and sparse threads.
7261     (while (and
7262             thread
7263             (or
7264              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7265              (gnus-summary-article-ancient-p
7266               (mail-header-number (car thread))))
7267             (if (or (<= (length (cdr thread)) 1)
7268                     (eq gnus-fetch-old-headers 'invisible))
7269                 (setq gnus-newsgroup-limit
7270                       (delq (mail-header-number (car thread))
7271                             gnus-newsgroup-limit)
7272                       thread (cadr thread))
7273               (when (gnus-invisible-cut-children (cdr thread))
7274                 (let ((th (cdr thread)))
7275                   (while th
7276                     (if (memq (mail-header-number (caar th))
7277                               gnus-newsgroup-limit)
7278                         (setq thread (car th)
7279                               th nil)
7280                       (setq th (cdr th))))))))))
7281   thread)
7282
7283 (defun gnus-cut-threads (threads)
7284   "Cut off all uninteresting articles from the beginning of threads."
7285   (when (or (eq gnus-fetch-old-headers 'some)
7286             (eq gnus-fetch-old-headers 'invisible)
7287             (numberp gnus-fetch-old-headers)
7288             (eq gnus-build-sparse-threads 'some)
7289             (eq gnus-build-sparse-threads 'more))
7290     (let ((th threads))
7291       (while th
7292         (setcar th (gnus-cut-thread (car th)))
7293         (setq th (cdr th)))))
7294   ;; Remove nixed out threads.
7295   (delq nil threads))
7296
7297 (defun gnus-summary-initial-limit (&optional show-if-empty)
7298   "Figure out what the initial limit is supposed to be on group entry.
7299 This entails weeding out unwanted dormants, low-scored articles,
7300 fetch-old-headers verbiage, and so on."
7301   ;; Most groups have nothing to remove.
7302   (if (or gnus-inhibit-limiting
7303           (and (null gnus-newsgroup-dormant)
7304                (eq gnus-newsgroup-display 'gnus-not-ignore)
7305                (not (eq gnus-fetch-old-headers 'some))
7306                (not (numberp gnus-fetch-old-headers))
7307                (not (eq gnus-fetch-old-headers 'invisible))
7308                (null gnus-summary-expunge-below)
7309                (not (eq gnus-build-sparse-threads 'some))
7310                (not (eq gnus-build-sparse-threads 'more))
7311                (null gnus-thread-expunge-below)
7312                (not gnus-use-nocem)))
7313       ()                                ; Do nothing.
7314     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7315     (setq gnus-newsgroup-limit nil)
7316     (mapatoms
7317      (lambda (node)
7318        (unless (car (symbol-value node))
7319          ;; These threads have no parents -- they are roots.
7320          (let ((nodes (cdr (symbol-value node)))
7321                thread)
7322            (while nodes
7323              (if (and gnus-thread-expunge-below
7324                       (< (gnus-thread-total-score (car nodes))
7325                          gnus-thread-expunge-below))
7326                  (gnus-expunge-thread (pop nodes))
7327                (setq thread (pop nodes))
7328                (gnus-summary-limit-children thread))))))
7329      gnus-newsgroup-dependencies)
7330     ;; If this limitation resulted in an empty group, we might
7331     ;; pop the previous limit and use it instead.
7332     (when (and (not gnus-newsgroup-limit)
7333                show-if-empty)
7334       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7335     gnus-newsgroup-limit))
7336
7337 (defun gnus-summary-limit-children (thread)
7338   "Return 1 if this subthread is visible and 0 if it is not."
7339   ;; First we get the number of visible children to this thread.  This
7340   ;; is done by recursing down the thread using this function, so this
7341   ;; will really go down to a leaf article first, before slowly
7342   ;; working its way up towards the root.
7343   (when thread
7344     (let ((children
7345            (if (cdr thread)
7346                (apply '+ (mapcar 'gnus-summary-limit-children
7347                                  (cdr thread)))
7348              0))
7349           (number (mail-header-number (car thread)))
7350           score)
7351       (if (and
7352            (not (memq number gnus-newsgroup-marked))
7353            (or
7354             ;; If this article is dormant and has absolutely no visible
7355             ;; children, then this article isn't visible.
7356             (and (memq number gnus-newsgroup-dormant)
7357                  (zerop children))
7358             ;; If this is "fetch-old-headered" and there is no
7359             ;; visible children, then we don't want this article.
7360             (and (or (eq gnus-fetch-old-headers 'some)
7361                      (numberp gnus-fetch-old-headers))
7362                  (gnus-summary-article-ancient-p number)
7363                  (zerop children))
7364             ;; If this is "fetch-old-headered" and `invisible', then
7365             ;; we don't want this article.
7366             (and (eq gnus-fetch-old-headers 'invisible)
7367                  (gnus-summary-article-ancient-p number))
7368             ;; If this is a sparsely inserted article with no children,
7369             ;; we don't want it.
7370             (and (eq gnus-build-sparse-threads 'some)
7371                  (gnus-summary-article-sparse-p number)
7372                  (zerop children))
7373             ;; If we use expunging, and this article is really
7374             ;; low-scored, then we don't want this article.
7375             (when (and gnus-summary-expunge-below
7376                        (< (setq score
7377                                 (or (cdr (assq number gnus-newsgroup-scored))
7378                                     gnus-summary-default-score))
7379                           gnus-summary-expunge-below))
7380               ;; We increase the expunge-tally here, but that has
7381               ;; nothing to do with the limits, really.
7382               (incf gnus-newsgroup-expunged-tally)
7383               ;; We also mark as read here, if that's wanted.
7384               (when (and gnus-summary-mark-below
7385                          (< score gnus-summary-mark-below))
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               t)
7393             ;; Do the `display' group parameter.
7394             (and gnus-newsgroup-display
7395                  (not (funcall gnus-newsgroup-display)))
7396             ;; Check NoCeM things.
7397             (if (and gnus-use-nocem
7398                      (gnus-nocem-unwanted-article-p
7399                       (mail-header-id (car thread))))
7400                 (progn
7401                   (setq gnus-newsgroup-unreads
7402                         (delq number gnus-newsgroup-unreads))
7403                   t))))
7404           ;; Nope, invisible article.
7405           0
7406         ;; Ok, this article is to be visible, so we add it to the limit
7407         ;; and return 1.
7408         (push number gnus-newsgroup-limit)
7409         1))))
7410
7411 (defun gnus-expunge-thread (thread)
7412   "Mark all articles in THREAD as read."
7413   (let* ((number (mail-header-number (car thread))))
7414     (incf gnus-newsgroup-expunged-tally)
7415     ;; We also mark as read here, if that's wanted.
7416     (setq gnus-newsgroup-unreads
7417           (delq number gnus-newsgroup-unreads))
7418     (if gnus-newsgroup-auto-expire
7419         (push number gnus-newsgroup-expirable)
7420       (push (cons number gnus-low-score-mark)
7421             gnus-newsgroup-reads)))
7422   ;; Go recursively through all subthreads.
7423   (mapcar 'gnus-expunge-thread (cdr thread)))
7424
7425 ;; Summary article oriented commands
7426
7427 (defun gnus-summary-refer-parent-article (n)
7428   "Refer parent article N times.
7429 If N is negative, go to ancestor -N instead.
7430 The difference between N and the number of articles fetched is returned."
7431   (interactive "p")
7432   (let ((skip 1)
7433         error header ref)
7434     (when (not (natnump n))
7435       (setq skip (abs n)
7436             n 1))
7437     (while (and (> n 0)
7438                 (not error))
7439       (setq header (gnus-summary-article-header))
7440       (if (and (eq (mail-header-number header)
7441                    (cdr gnus-article-current))
7442                (equal gnus-newsgroup-name
7443                       (car gnus-article-current)))
7444           ;; If we try to find the parent of the currently
7445           ;; displayed article, then we take a look at the actual
7446           ;; References header, since this is slightly more
7447           ;; reliable than the References field we got from the
7448           ;; server.
7449           (save-excursion
7450             (set-buffer gnus-original-article-buffer)
7451             (nnheader-narrow-to-headers)
7452             (unless (setq ref (message-fetch-field "references"))
7453               (setq ref (message-fetch-field "in-reply-to")))
7454             (widen))
7455         (setq ref
7456               ;; It's not the current article, so we take a bet on
7457               ;; the value we got from the server.
7458               (mail-header-references header)))
7459       (if (and ref
7460                (not (equal ref "")))
7461           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7462             (gnus-message 1 "Couldn't find parent"))
7463         (gnus-message 1 "No references in article %d"
7464                       (gnus-summary-article-number))
7465         (setq error t))
7466       (decf n))
7467     (gnus-summary-position-point)
7468     n))
7469
7470 (defun gnus-summary-refer-references ()
7471   "Fetch all articles mentioned in the References header.
7472 Return the number of articles fetched."
7473   (interactive)
7474   (let ((ref (mail-header-references (gnus-summary-article-header)))
7475         (current (gnus-summary-article-number))
7476         (n 0))
7477     (if (or (not ref)
7478             (equal ref ""))
7479         (error "No References in the current article")
7480       ;; For each Message-ID in the References header...
7481       (while (string-match "<[^>]*>" ref)
7482         (incf n)
7483         ;; ... fetch that article.
7484         (gnus-summary-refer-article
7485          (prog1 (match-string 0 ref)
7486            (setq ref (substring ref (match-end 0))))))
7487       (gnus-summary-goto-subject current)
7488       (gnus-summary-position-point)
7489       n)))
7490
7491 (defun gnus-summary-refer-thread (&optional limit)
7492   "Fetch all articles in the current thread.
7493 If LIMIT (the numerical prefix), fetch that many old headers instead
7494 of what's specified by the `gnus-refer-thread-limit' variable."
7495   (interactive "P")
7496   (let ((id (mail-header-id (gnus-summary-article-header)))
7497         (limit (if limit (prefix-numeric-value limit)
7498                  gnus-refer-thread-limit)))
7499     ;; We want to fetch LIMIT *old* headers, but we also have to
7500     ;; re-fetch all the headers in the current buffer, because many of
7501     ;; them may be undisplayed.  So we adjust LIMIT.
7502     (when (numberp limit)
7503       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7504     (unless (eq gnus-fetch-old-headers 'invisible)
7505       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7506       ;; Retrieve the headers and read them in.
7507       (if (eq (gnus-retrieve-headers
7508                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7509               'nov)
7510           (gnus-build-all-threads)
7511         (error "Can't fetch thread from backends that don't support NOV"))
7512       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7513     (gnus-summary-limit-include-thread id)))
7514
7515 (defun gnus-summary-refer-article (message-id)
7516   "Fetch an article specified by MESSAGE-ID."
7517   (interactive "sMessage-ID: ")
7518   (when (and (stringp message-id)
7519              (not (zerop (length message-id))))
7520     ;; Construct the correct Message-ID if necessary.
7521     ;; Suggested by tale@pawl.rpi.edu.
7522     (unless (string-match "^<" message-id)
7523       (setq message-id (concat "<" message-id)))
7524     (unless (string-match ">$" message-id)
7525       (setq message-id (concat message-id ">")))
7526     (let* ((header (gnus-id-to-header message-id))
7527            (sparse (and header
7528                         (gnus-summary-article-sparse-p
7529                          (mail-header-number header))
7530                         (memq (mail-header-number header)
7531                               gnus-newsgroup-limit)))
7532            number)
7533       (cond
7534        ;; If the article is present in the buffer we just go to it.
7535        ((and header
7536              (or (not (gnus-summary-article-sparse-p
7537                        (mail-header-number header)))
7538                  sparse))
7539         (prog1
7540             (gnus-summary-goto-article
7541              (mail-header-number header) nil t)
7542           (when sparse
7543             (gnus-summary-update-article (mail-header-number header)))))
7544        (t
7545         ;; We fetch the article.
7546         (catch 'found
7547           (dolist (gnus-override-method (gnus-refer-article-methods))
7548             (gnus-check-server gnus-override-method)
7549             ;; Fetch the header, and display the article.
7550             (when (setq number (gnus-summary-insert-subject message-id))
7551               (gnus-summary-select-article nil nil nil number)
7552               (throw 'found t)))
7553           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7554
7555 (defun gnus-refer-article-methods ()
7556   "Return a list of referrable methods."
7557   (cond
7558    ;; No method, so we default to current and native.
7559    ((null gnus-refer-article-method)
7560     (list gnus-current-select-method gnus-select-method))
7561    ;; Current.
7562    ((eq 'current gnus-refer-article-method)
7563     (list gnus-current-select-method))
7564    ;; List of select methods.
7565    ((not (and (symbolp (car gnus-refer-article-method))
7566               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7567     (let (out)
7568       (dolist (method gnus-refer-article-method)
7569         (push (if (eq 'current method)
7570                   gnus-current-select-method
7571                 method)
7572               out))
7573       (nreverse out)))
7574    ;; One single select method.
7575    (t
7576     (list gnus-refer-article-method))))
7577
7578 (defun gnus-summary-edit-parameters ()
7579   "Edit the group parameters of the current group."
7580   (interactive)
7581   (gnus-group-edit-group gnus-newsgroup-name 'params))
7582
7583 (defun gnus-summary-customize-parameters ()
7584   "Customize the group parameters of the current group."
7585   (interactive)
7586   (gnus-group-customize gnus-newsgroup-name))
7587
7588 (defun gnus-summary-enter-digest-group (&optional force)
7589   "Enter an nndoc group based on the current article.
7590 If FORCE, force a digest interpretation.  If not, try
7591 to guess what the document format is."
7592   (interactive "P")
7593   (let ((conf gnus-current-window-configuration))
7594     (save-excursion
7595       (gnus-summary-select-article))
7596     (setq gnus-current-window-configuration conf)
7597     (let* ((name (format "%s-%d"
7598                          (gnus-group-prefixed-name
7599                           gnus-newsgroup-name (list 'nndoc ""))
7600                          (save-excursion
7601                            (set-buffer gnus-summary-buffer)
7602                            gnus-current-article)))
7603            (ogroup gnus-newsgroup-name)
7604            (params (append (gnus-info-params (gnus-get-info ogroup))
7605                            (list (cons 'to-group ogroup))
7606                            (list (cons 'save-article-group ogroup))))
7607            (case-fold-search t)
7608            (buf (current-buffer))
7609            dig to-address)
7610       (save-excursion
7611         (set-buffer gnus-original-article-buffer)
7612         ;; Have the digest group inherit the main mail address of
7613         ;; the parent article.
7614         (when (setq to-address (or (message-fetch-field "reply-to")
7615                                    (message-fetch-field "from")))
7616           (setq params (append
7617                         (list (cons 'to-address
7618                                     (funcall gnus-decode-encoded-word-function
7619                                              to-address))))))
7620         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7621         (insert-buffer-substring gnus-original-article-buffer)
7622         ;; Remove lines that may lead nndoc to misinterpret the
7623         ;; document type.
7624         (narrow-to-region
7625          (goto-char (point-min))
7626          (or (search-forward "\n\n" nil t) (point)))
7627         (goto-char (point-min))
7628         (delete-matching-lines "^Path:\\|^From ")
7629         (widen))
7630       (unwind-protect
7631           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7632                     (gnus-newsgroup-ephemeral-ignored-charsets
7633                      gnus-newsgroup-ignored-charsets))
7634                 (gnus-group-read-ephemeral-group
7635                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7636                               (nndoc-article-type
7637                                ,(if force 'mbox 'guess))) t))
7638             ;; Make all postings to this group go to the parent group.
7639               (nconc (gnus-info-params (gnus-get-info name))
7640                      params)
7641             ;; Couldn't select this doc group.
7642             (switch-to-buffer buf)
7643             (gnus-set-global-variables)
7644             (gnus-configure-windows 'summary)
7645             (gnus-message 3 "Article couldn't be entered?"))
7646         (kill-buffer dig)))))
7647
7648 (defun gnus-summary-read-document (n)
7649   "Open a new group based on the current article(s).
7650 This will allow you to read digests and other similar
7651 documents as newsgroups.
7652 Obeys the standard process/prefix convention."
7653   (interactive "P")
7654   (let* ((articles (gnus-summary-work-articles n))
7655          (ogroup gnus-newsgroup-name)
7656          (params (append (gnus-info-params (gnus-get-info ogroup))
7657                          (list (cons 'to-group ogroup))))
7658          article group egroup groups vgroup)
7659     (while (setq article (pop articles))
7660       (setq group (format "%s-%d" gnus-newsgroup-name article))
7661       (gnus-summary-remove-process-mark article)
7662       (when (gnus-summary-display-article article)
7663         (save-excursion
7664           (with-temp-buffer
7665             (insert-buffer-substring gnus-original-article-buffer)
7666             ;; Remove some headers that may lead nndoc to make
7667             ;; the wrong guess.
7668             (message-narrow-to-head)
7669             (goto-char (point-min))
7670             (delete-matching-lines "^\\(Path\\):\\|^From ")
7671             (widen)
7672             (if (setq egroup
7673                       (gnus-group-read-ephemeral-group
7674                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7675                                      (nndoc-article-type guess))
7676                        t nil t))
7677                 (progn
7678             ;; Make all postings to this group go to the parent group.
7679                   (nconc (gnus-info-params (gnus-get-info egroup))
7680                          params)
7681                   (push egroup groups))
7682               ;; Couldn't select this doc group.
7683               (gnus-error 3 "Article couldn't be entered"))))))
7684     ;; Now we have selected all the documents.
7685     (cond
7686      ((not groups)
7687       (error "None of the articles could be interpreted as documents"))
7688      ((gnus-group-read-ephemeral-group
7689        (setq vgroup (format
7690                      "nnvirtual:%s-%s" gnus-newsgroup-name
7691                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7692        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7693        t
7694        (cons (current-buffer) 'summary)))
7695      (t
7696       (error "Couldn't select virtual nndoc group")))))
7697
7698 (defun gnus-summary-isearch-article (&optional regexp-p)
7699   "Do incremental search forward on the current article.
7700 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7701   (interactive "P")
7702   (gnus-summary-select-article)
7703   (gnus-configure-windows 'article)
7704   (gnus-eval-in-buffer-window gnus-article-buffer
7705     (save-restriction
7706       (widen)
7707       (isearch-forward regexp-p))))
7708
7709 (defun gnus-summary-search-article-forward (regexp &optional backward)
7710   "Search for an article containing REGEXP forward.
7711 If BACKWARD, search backward instead."
7712   (interactive
7713    (list (read-string
7714           (format "Search article %s (regexp%s): "
7715                   (if current-prefix-arg "backward" "forward")
7716                   (if gnus-last-search-regexp
7717                       (concat ", default " gnus-last-search-regexp)
7718                     "")))
7719          current-prefix-arg))
7720   (if (string-equal regexp "")
7721       (setq regexp (or gnus-last-search-regexp ""))
7722     (setq gnus-last-search-regexp regexp)
7723     (setq gnus-article-before-search gnus-current-article))
7724   ;; Intentionally set gnus-last-article.
7725   (setq gnus-last-article gnus-article-before-search)
7726   (let ((gnus-last-article gnus-last-article))
7727     (if (gnus-summary-search-article regexp backward)
7728         (gnus-summary-show-thread)
7729       (error "Search failed: \"%s\"" regexp))))
7730
7731 (defun gnus-summary-search-article-backward (regexp)
7732   "Search for an article containing REGEXP backward."
7733   (interactive
7734    (list (read-string
7735           (format "Search article backward (regexp%s): "
7736                   (if gnus-last-search-regexp
7737                       (concat ", default " gnus-last-search-regexp)
7738                     "")))))
7739   (gnus-summary-search-article-forward regexp 'backward))
7740
7741 (defun gnus-summary-search-article (regexp &optional backward)
7742   "Search for an article containing REGEXP.
7743 Optional argument BACKWARD means do search for backward.
7744 `gnus-select-article-hook' is not called during the search."
7745   ;; We have to require this here to make sure that the following
7746   ;; dynamic binding isn't shadowed by autoloading.
7747   (require 'gnus-async)
7748   (require 'gnus-art)
7749   (let ((gnus-select-article-hook nil)  ;Disable hook.
7750         (gnus-article-prepare-hook nil)
7751         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7752         (gnus-use-article-prefetch nil)
7753         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7754         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7755         (sum (current-buffer))
7756         (gnus-display-mime-function nil)
7757         (found nil)
7758         point)
7759     (gnus-save-hidden-threads
7760       (gnus-summary-select-article)
7761       (set-buffer gnus-article-buffer)
7762       (goto-char (window-point (get-buffer-window (current-buffer))))
7763       (when backward
7764         (forward-line -1))
7765       (while (not found)
7766         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7767         (if (if backward
7768                 (re-search-backward regexp nil t)
7769               (re-search-forward regexp nil t))
7770             ;; We found the regexp.
7771             (progn
7772               (setq found 'found)
7773               (beginning-of-line)
7774               (set-window-start
7775                (get-buffer-window (current-buffer))
7776                (point))
7777               (forward-line 1)
7778               (set-window-point
7779                (get-buffer-window (current-buffer))
7780                (point))
7781               (set-buffer sum)
7782               (setq point (point)))
7783           ;; We didn't find it, so we go to the next article.
7784           (set-buffer sum)
7785           (setq found 'not)
7786           (while (eq found 'not)
7787             (if (not (if backward (gnus-summary-find-prev)
7788                        (gnus-summary-find-next)))
7789                 ;; No more articles.
7790                 (setq found t)
7791               ;; Select the next article and adjust point.
7792               (unless (gnus-summary-article-sparse-p
7793                        (gnus-summary-article-number))
7794                 (setq found nil)
7795                 (gnus-summary-select-article)
7796                 (set-buffer gnus-article-buffer)
7797                 (widen)
7798                 (goto-char (if backward (point-max) (point-min))))))))
7799       (gnus-message 7 ""))
7800     ;; Return whether we found the regexp.
7801     (when (eq found 'found)
7802       (goto-char point)
7803       (gnus-summary-show-thread)
7804       (gnus-summary-goto-subject gnus-current-article)
7805       (gnus-summary-position-point)
7806       t)))
7807
7808 (defun gnus-find-matching-articles (header regexp)
7809   "Return a list of all articles that match REGEXP on HEADER.
7810 This search includes all articles in the current group that Gnus has
7811 fetched headers for, whether they are displayed or not."
7812   (let ((articles nil)
7813         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7814         (case-fold-search t))
7815     (dolist (header gnus-newsgroup-headers)
7816       (when (string-match regexp (funcall func header))
7817         (push (mail-header-number header) articles)))
7818     (nreverse articles)))
7819
7820 (defun gnus-summary-find-matching (header regexp &optional backward unread
7821                                           not-case-fold not-matching)
7822   "Return a list of all articles that match REGEXP on HEADER.
7823 The search stars on the current article and goes forwards unless
7824 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7825 If UNREAD is non-nil, only unread articles will
7826 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7827 in the comparisons. If NOT-MATCHING, return a list of all articles that
7828 not match REGEXP on HEADER."
7829   (let ((case-fold-search (not not-case-fold))
7830         articles d func)
7831     (if (consp header)
7832         (if (eq (car header) 'extra)
7833             (setq func
7834                   `(lambda (h)
7835                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7836                          "")))
7837           (error "%s is an invalid header" header))
7838       (unless (fboundp (intern (concat "mail-header-" header)))
7839         (error "%s is not a valid header" header))
7840       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7841     (dolist (d (if (eq backward 'all)
7842                    gnus-newsgroup-data
7843                  (gnus-data-find-list
7844                   (gnus-summary-article-number)
7845                   (gnus-data-list backward))))
7846       (when (and (or (not unread)       ; We want all articles...
7847                      (gnus-data-unread-p d)) ; Or just unreads.
7848                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7849                  (if not-matching
7850                      (not (string-match
7851                            regexp
7852                            (funcall func (gnus-data-header d))))
7853                    (string-match regexp
7854                                  (funcall func (gnus-data-header d)))))
7855         (push (gnus-data-number d) articles))) ; Success!
7856     (nreverse articles)))
7857
7858 (defun gnus-summary-execute-command (header regexp command &optional backward)
7859   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7860 If HEADER is an empty string (or nil), the match is done on the entire
7861 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7862   (interactive
7863    (list (let ((completion-ignore-case t))
7864            (completing-read
7865             "Header name: "
7866             (mapcar (lambda (header) (list (format "%s" header)))
7867                     (append
7868                      '("Number" "Subject" "From" "Lines" "Date"
7869                        "Message-ID" "Xref" "References" "Body")
7870                      gnus-extra-headers))
7871             nil 'require-match))
7872          (read-string "Regexp: ")
7873          (read-key-sequence "Command: ")
7874          current-prefix-arg))
7875   (when (equal header "Body")
7876     (setq header ""))
7877   ;; Hidden thread subtrees must be searched as well.
7878   (gnus-summary-show-all-threads)
7879   ;; We don't want to change current point nor window configuration.
7880   (save-excursion
7881     (save-window-excursion
7882       (gnus-message 6 "Executing %s..." (key-description command))
7883 ;; We'd like to execute COMMAND interactively so as to give arguments.
7884       (gnus-execute header regexp
7885                     `(call-interactively ',(key-binding command))
7886                     backward)
7887       (gnus-message 6 "Executing %s...done" (key-description command)))))
7888
7889 (defun gnus-summary-beginning-of-article ()
7890   "Scroll the article back to the beginning."
7891   (interactive)
7892   (gnus-summary-select-article)
7893   (gnus-configure-windows 'article)
7894   (gnus-eval-in-buffer-window gnus-article-buffer
7895     (widen)
7896     (goto-char (point-min))
7897     (when gnus-page-broken
7898       (gnus-narrow-to-page))))
7899
7900 (defun gnus-summary-end-of-article ()
7901   "Scroll to the end of the article."
7902   (interactive)
7903   (gnus-summary-select-article)
7904   (gnus-configure-windows 'article)
7905   (gnus-eval-in-buffer-window gnus-article-buffer
7906     (widen)
7907     (goto-char (point-max))
7908     (recenter -3)
7909     (when gnus-page-broken
7910       (gnus-narrow-to-page))))
7911
7912 (defun gnus-summary-print-truncate-and-quote (string &optional len)
7913   "Truncate to LEN and quote all \"(\"'s in STRING."
7914   (gnus-replace-in-string (if (and len (> (length string) len))
7915                               (substring string 0 len)
7916                             string)
7917                           "[()]" "\\\\\\&"))
7918
7919 (defun gnus-summary-print-article (&optional filename n)
7920   "Generate and print a PostScript image of the N next (mail) articles.
7921
7922 If N is negative, print the N previous articles.  If N is nil and articles
7923 have been marked with the process mark, print these instead.
7924
7925 If the optional first argument FILENAME is nil, send the image to the
7926 printer.  If FILENAME is a string, save the PostScript image in a file with
7927 that name.  If FILENAME is a number, prompt the user for the name of the file
7928 to save in."
7929   (interactive (list (ps-print-preprint current-prefix-arg)))
7930   (dolist (article (gnus-summary-work-articles n))
7931     (gnus-summary-select-article nil nil 'pseudo article)
7932     (gnus-eval-in-buffer-window gnus-article-buffer
7933       (gnus-print-buffer))
7934     (gnus-summary-remove-process-mark article))
7935   (ps-despool filename))
7936
7937 (defun gnus-print-buffer ()
7938   (let ((buffer (generate-new-buffer " *print*")))
7939     (unwind-protect
7940         (progn
7941           (copy-to-buffer buffer (point-min) (point-max))
7942           (set-buffer buffer)
7943           (gnus-article-delete-invisible-text)
7944           (when (gnus-visual-p 'article-highlight 'highlight)
7945             ;; Copy-to-buffer doesn't copy overlay.  So redo
7946             ;; highlight.
7947             (let ((gnus-article-buffer buffer))
7948               (gnus-article-highlight-citation t)
7949               (gnus-article-highlight-signature)))
7950           (let ((ps-left-header
7951                  (list
7952                   (concat "("
7953                           (gnus-summary-print-truncate-and-quote
7954                            (mail-header-subject gnus-current-headers)
7955                            66) ")")
7956                   (concat "("
7957                           (gnus-summary-print-truncate-and-quote
7958                            (mail-header-from gnus-current-headers)
7959                            45) ")")))
7960                 (ps-right-header
7961                  (list
7962                   "/pagenumberstring load"
7963                   (concat "("
7964                           (mail-header-date gnus-current-headers) ")"))))
7965             (gnus-run-hooks 'gnus-ps-print-hook)
7966             (save-excursion
7967               (if window-system
7968                   (ps-spool-buffer-with-faces)
7969                 (ps-spool-buffer)))))
7970       (kill-buffer buffer))))
7971
7972 (defun gnus-summary-show-article (&optional arg)
7973   "Force redisplaying of the current article.
7974 If ARG (the prefix) is a number, show the article with the charset
7975 defined in `gnus-summary-show-article-charset-alist', or the charset
7976 input.
7977 If ARG (the prefix) is non-nil and not a number, show the raw article
7978 without any article massaging functions being run.  Normally, the key strokes 
7979 are `C-u g'."
7980   (interactive "P")
7981   (cond
7982    ((numberp arg)
7983     (gnus-summary-show-article t)
7984     (let ((gnus-newsgroup-charset
7985            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7986                (mm-read-coding-system
7987                 "View as charset: "
7988                 (save-excursion
7989                   (set-buffer gnus-article-buffer)
7990                   (let ((coding-systems
7991                          (detect-coding-region (point) (point-max))))
7992                     (or (car-safe coding-systems)
7993                         coding-systems))))))
7994           (gnus-newsgroup-ignored-charsets 'gnus-all))
7995       (gnus-summary-select-article nil 'force)
7996       (let ((deps gnus-newsgroup-dependencies)
7997             head header lines)
7998         (save-excursion
7999           (set-buffer gnus-original-article-buffer)
8000           (save-restriction
8001             (message-narrow-to-head)
8002             (setq head (buffer-string))
8003             (goto-char (point-min))
8004             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8005               (goto-char (point-max))
8006               (widen)
8007               (setq lines (1- (count-lines (point) (point-max))))))
8008           (with-temp-buffer
8009             (insert (format "211 %d Article retrieved.\n"
8010                             (cdr gnus-article-current)))
8011             (insert head)
8012             (if lines (insert (format "Lines: %d\n" lines)))
8013             (insert ".\n")
8014             (let ((nntp-server-buffer (current-buffer)))
8015               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8016         (gnus-data-set-header
8017          (gnus-data-find (cdr gnus-article-current))
8018          header)
8019         (gnus-summary-update-article-line
8020          (cdr gnus-article-current) header)
8021         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8022           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8023    ((not arg)
8024     ;; Select the article the normal way.
8025     (gnus-summary-select-article nil 'force))
8026    (t
8027     ;; We have to require this here to make sure that the following
8028     ;; dynamic binding isn't shadowed by autoloading.
8029     (require 'gnus-async)
8030     (require 'gnus-art)
8031     ;; Bind the article treatment functions to nil.
8032     (let ((gnus-have-all-headers t)
8033           gnus-article-prepare-hook
8034           gnus-article-decode-hook
8035           gnus-display-mime-function
8036           gnus-break-pages)
8037       ;; Destroy any MIME parts.
8038       (when (gnus-buffer-live-p gnus-article-buffer)
8039         (save-excursion
8040           (set-buffer gnus-article-buffer)
8041           (mm-destroy-parts gnus-article-mime-handles)
8042           ;; Set it to nil for safety reason.
8043           (setq gnus-article-mime-handle-alist nil)
8044           (setq gnus-article-mime-handles nil)))
8045       (gnus-summary-select-article nil 'force))))
8046   (gnus-summary-goto-subject gnus-current-article)
8047   (gnus-summary-position-point))
8048
8049 (defun gnus-summary-show-raw-article ()
8050   "Show the raw article without any article massaging functions being run."
8051   (interactive)
8052   (gnus-summary-show-article t))
8053
8054 (defun gnus-summary-verbose-headers (&optional arg)
8055   "Toggle permanent full header display.
8056 If ARG is a positive number, turn header display on.
8057 If ARG is a negative number, turn header display off."
8058   (interactive "P")
8059   (setq gnus-show-all-headers
8060         (cond ((or (not (numberp arg))
8061                    (zerop arg))
8062                (not gnus-show-all-headers))
8063               ((natnump arg)
8064                t)))
8065   (gnus-summary-show-article))
8066
8067 (defun gnus-summary-toggle-header (&optional arg)
8068   "Show the headers if they are hidden, or hide them if they are shown.
8069 If ARG is a positive number, show the entire header.
8070 If ARG is a negative number, hide the unwanted header lines."
8071   (interactive "P")
8072   (save-excursion
8073     (set-buffer gnus-article-buffer)
8074     (save-restriction
8075       (let* ((buffer-read-only nil)
8076              (inhibit-point-motion-hooks t)
8077              hidden e)
8078         (setq hidden
8079               (if (numberp arg)
8080                   (>= arg 0)
8081                 (save-restriction
8082                   (article-narrow-to-head)
8083                   (gnus-article-hidden-text-p 'headers))))
8084         (goto-char (point-min))
8085         (when (search-forward "\n\n" nil t)
8086           (delete-region (point-min) (1- (point))))
8087         (goto-char (point-min))
8088         (save-excursion
8089           (set-buffer gnus-original-article-buffer)
8090           (goto-char (point-min))
8091           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8092         (insert-buffer-substring gnus-original-article-buffer 1 e)
8093         (save-restriction
8094           (narrow-to-region (point-min) (point))
8095           (article-decode-encoded-words)
8096           (if  hidden
8097               (let ((gnus-treat-hide-headers nil)
8098                     (gnus-treat-hide-boring-headers nil))
8099                 (gnus-delete-wash-type 'headers)
8100                 (gnus-treat-article 'head))
8101             (gnus-treat-article 'head)))
8102         (gnus-set-mode-line 'article)))))
8103
8104 (defun gnus-summary-show-all-headers ()
8105   "Make all header lines visible."
8106   (interactive)
8107   (gnus-summary-toggle-header 1))
8108
8109 (defun gnus-summary-caesar-message (&optional arg)
8110   "Caesar rotate the current article by 13.
8111 The numerical prefix specifies how many places to rotate each letter
8112 forward."
8113   (interactive "P")
8114   (gnus-summary-select-article)
8115   (let ((mail-header-separator ""))
8116     (gnus-eval-in-buffer-window gnus-article-buffer
8117       (save-restriction
8118         (widen)
8119         (let ((start (window-start))
8120               buffer-read-only)
8121           (message-caesar-buffer-body arg)
8122           (set-window-start (get-buffer-window (current-buffer)) start))))))
8123
8124 (defun gnus-summary-stop-page-breaking ()
8125   "Stop page breaking in the current article."
8126   (interactive)
8127   (gnus-summary-select-article)
8128   (gnus-eval-in-buffer-window gnus-article-buffer
8129     (widen)
8130     (when (gnus-visual-p 'page-marker)
8131       (let ((buffer-read-only nil))
8132         (gnus-remove-text-with-property 'gnus-prev)
8133         (gnus-remove-text-with-property 'gnus-next))
8134       (setq gnus-page-broken nil))))
8135
8136 (defun gnus-summary-move-article (&optional n to-newsgroup
8137                                             select-method action)
8138   "Move the current article to a different newsgroup.
8139 If N is a positive number, move the N next articles.
8140 If N is a negative number, move the N previous articles.
8141 If N is nil and any articles have been marked with the process mark,
8142 move those articles instead.
8143 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8144 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8145 re-spool using this method.
8146
8147 For this function to work, both the current newsgroup and the
8148 newsgroup that you want to move to have to support the `request-move'
8149 and `request-accept' functions.
8150
8151 ACTION can be either `move' (the default), `crosspost' or `copy'."
8152   (interactive "P")
8153   (unless action
8154     (setq action 'move))
8155   ;; Check whether the source group supports the required functions.
8156   (cond ((and (eq action 'move)
8157               (not (gnus-check-backend-function
8158                     'request-move-article gnus-newsgroup-name)))
8159          (error "The current group does not support article moving"))
8160         ((and (eq action 'crosspost)
8161               (not (gnus-check-backend-function
8162                     'request-replace-article gnus-newsgroup-name)))
8163          (error "The current group does not support article editing")))
8164   (let ((articles (gnus-summary-work-articles n))
8165         (prefix (if (gnus-check-backend-function
8166                      'request-move-article gnus-newsgroup-name)
8167                     (gnus-group-real-prefix gnus-newsgroup-name)
8168                   ""))
8169         (names '((move "Move" "Moving")
8170                  (copy "Copy" "Copying")
8171                  (crosspost "Crosspost" "Crossposting")))
8172         (copy-buf (save-excursion
8173                     (nnheader-set-temp-buffer " *copy article*")))
8174         art-group to-method new-xref article to-groups)
8175     (unless (assq action names)
8176       (error "Unknown action %s" action))
8177     ;; We have to select an article to give
8178     ;; `gnus-read-move-group-name' an opportunity to suggest an
8179     ;; appropriate default.
8180     (unless (gnus-buffer-live-p gnus-original-article-buffer)
8181       (gnus-summary-select-article nil nil nil (car articles)))
8182     ;; Read the newsgroup name.
8183     (when (and (not to-newsgroup)
8184                (not select-method))
8185       (setq to-newsgroup
8186             (gnus-read-move-group-name
8187              (cadr (assq action names))
8188              (symbol-value (intern (format "gnus-current-%s-group" action)))
8189              articles prefix))
8190       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8191     (setq to-method (or select-method
8192                         (gnus-server-to-method
8193                          (gnus-group-method to-newsgroup))))
8194     ;; Check the method we are to move this article to...
8195     (unless (gnus-check-backend-function
8196              'request-accept-article (car to-method))
8197       (error "%s does not support article copying" (car to-method)))
8198     (unless (gnus-check-server to-method)
8199       (error "Can't open server %s" (car to-method)))
8200     (gnus-message 6 "%s to %s: %s..."
8201                   (caddr (assq action names))
8202                   (or (car select-method) to-newsgroup) articles)
8203     (while articles
8204       (setq article (pop articles))
8205       (setq
8206        art-group
8207        (cond
8208         ;; Move the article.
8209         ((eq action 'move)
8210          ;; Remove this article from future suppression.
8211          (gnus-dup-unsuppress-article article)
8212          (gnus-request-move-article
8213           article                       ; Article to move
8214           gnus-newsgroup-name           ; From newsgroup
8215           (nth 1 (gnus-find-method-for-group
8216                   gnus-newsgroup-name)) ; Server
8217           (list 'gnus-request-accept-article
8218                 to-newsgroup (list 'quote select-method)
8219                 (not articles) t)       ; Accept form
8220           (not articles)))              ; Only save nov last time
8221         ;; Copy the article.
8222         ((eq action 'copy)
8223          (save-excursion
8224            (set-buffer copy-buf)
8225            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8226              (gnus-request-accept-article
8227               to-newsgroup select-method (not articles) t))))
8228         ;; Crosspost the article.
8229         ((eq action 'crosspost)
8230          (let ((xref (message-tokenize-header
8231                       (mail-header-xref (gnus-summary-article-header article))
8232                       " ")))
8233            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8234                                   ":" (number-to-string article)))
8235            (unless xref
8236              (setq xref (list (system-name))))
8237            (setq new-xref
8238                  (concat
8239                   (mapconcat 'identity
8240                              (delete "Xref:" (delete new-xref xref))
8241                              " ")
8242                   " " new-xref))
8243            (save-excursion
8244              (set-buffer copy-buf)
8245              ;; First put the article in the destination group.
8246              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8247              (when (consp (setq art-group
8248                                 (gnus-request-accept-article
8249                                  to-newsgroup select-method (not articles))))
8250                (setq new-xref (concat new-xref " " (car art-group)
8251                                       ":"
8252                                       (number-to-string (cdr art-group))))
8253                ;; Now we have the new Xrefs header, so we insert
8254                ;; it and replace the new article.
8255                (nnheader-replace-header "Xref" new-xref)
8256                (gnus-request-replace-article
8257                 (cdr art-group) to-newsgroup (current-buffer))
8258                art-group))))))
8259       (cond
8260        ((not art-group)
8261         (gnus-message 1 "Couldn't %s article %s: %s"
8262                       (cadr (assq action names)) article
8263                       (nnheader-get-report (car to-method))))
8264        ((eq art-group 'junk)
8265         (when (eq action 'move)
8266           (gnus-summary-mark-article article gnus-canceled-mark)
8267           (gnus-message 4 "Deleted article %s" article)))
8268        (t
8269         (let* ((pto-group (gnus-group-prefixed-name
8270                            (car art-group) to-method))
8271                (entry
8272                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8273                (info (nth 2 entry))
8274                (to-group (gnus-info-group info))
8275                to-marks)
8276           ;; Update the group that has been moved to.
8277           (when (and info
8278                      (memq action '(move copy)))
8279             (unless (member to-group to-groups)
8280               (push to-group to-groups))
8281
8282             (unless (memq article gnus-newsgroup-unreads)
8283               (push 'read to-marks)
8284               (gnus-info-set-read
8285                info (gnus-add-to-range (gnus-info-read info)
8286                                        (list (cdr art-group)))))
8287
8288             ;; See whether the article is to be put in the cache.
8289             (let ((marks gnus-article-mark-lists)
8290                   (to-article (cdr art-group)))
8291
8292               ;; Enter the article into the cache in the new group,
8293               ;; if that is required.
8294               (when gnus-use-cache
8295                 (gnus-cache-possibly-enter-article
8296                  to-group to-article
8297                  (memq article gnus-newsgroup-marked)
8298                  (memq article gnus-newsgroup-dormant)
8299                  (memq article gnus-newsgroup-unreads)))
8300
8301               (when gnus-preserve-marks
8302                 ;; Copy any marks over to the new group.
8303                 (when (and (equal to-group gnus-newsgroup-name)
8304                            (not (memq article gnus-newsgroup-unreads)))
8305                   ;; Mark this article as read in this group.
8306                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8307                   (setcdr (gnus-active to-group) to-article)
8308                   (setcdr gnus-newsgroup-active to-article))
8309
8310                 (while marks
8311                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8312                     (when (memq article (symbol-value
8313                                          (intern (format "gnus-newsgroup-%s"
8314                                                          (caar marks)))))
8315                       (push (cdar marks) to-marks)
8316                       ;; If the other group is the same as this group,
8317                       ;; then we have to add the mark to the list.
8318                       (when (equal to-group gnus-newsgroup-name)
8319                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8320                              (cons to-article
8321                                    (symbol-value
8322                                     (intern (format "gnus-newsgroup-%s"
8323                                                     (caar marks)))))))
8324                       ;; Copy the marks to other group.
8325                       (gnus-add-marked-articles
8326                        to-group (cdar marks) (list to-article) info)))
8327                   (setq marks (cdr marks)))
8328
8329                 (gnus-request-set-mark to-group (list (list (list to-article)
8330                                                             'add
8331                                                             to-marks))))
8332
8333               (gnus-dribble-enter
8334                (concat "(gnus-group-set-info '"
8335                        (gnus-prin1-to-string (gnus-get-info to-group))
8336                        ")"))))
8337
8338           ;; Update the Xref header in this article to point to
8339           ;; the new crossposted article we have just created.
8340           (when (eq action 'crosspost)
8341             (save-excursion
8342               (set-buffer copy-buf)
8343               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8344               (nnheader-replace-header "Xref" new-xref)
8345               (gnus-request-replace-article
8346                article gnus-newsgroup-name (current-buffer)))))
8347
8348         ;;;!!!Why is this necessary?
8349         (set-buffer gnus-summary-buffer)
8350
8351         (gnus-summary-goto-subject article)
8352         (when (eq action 'move)
8353           (gnus-summary-mark-article article gnus-canceled-mark))))
8354       (gnus-summary-remove-process-mark article))
8355     ;; Re-activate all groups that have been moved to.
8356     (save-excursion
8357       (set-buffer gnus-group-buffer)
8358       (let ((gnus-group-marked to-groups))
8359         (gnus-group-get-new-news-this-group nil t)))
8360
8361     (gnus-kill-buffer copy-buf)
8362     (gnus-summary-position-point)
8363     (gnus-set-mode-line 'summary)))
8364
8365 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8366   "Move the current article to a different newsgroup.
8367 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8368 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8369 re-spool using this method."
8370   (interactive "P")
8371   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8372
8373 (defun gnus-summary-crosspost-article (&optional n)
8374   "Crosspost the current article to some other group."
8375   (interactive "P")
8376   (gnus-summary-move-article n nil nil 'crosspost))
8377
8378 (defcustom gnus-summary-respool-default-method nil
8379   "Default method type for respooling an article.
8380 If nil, use to the current newsgroup method."
8381   :type 'symbol
8382   :group 'gnus-summary-mail)
8383
8384 (defun gnus-summary-respool-article (&optional n method)
8385   "Respool the current article.
8386 The article will be squeezed through the mail spooling process again,
8387 which means that it will be put in some mail newsgroup or other
8388 depending on `nnmail-split-methods'.
8389 If N is a positive number, respool the N next articles.
8390 If N is a negative number, respool the N previous articles.
8391 If N is nil and any articles have been marked with the process mark,
8392 respool those articles instead.
8393
8394 Respooling can be done both from mail groups and \"real\" newsgroups.
8395 In the former case, the articles in question will be moved from the
8396 current group into whatever groups they are destined to.  In the
8397 latter case, they will be copied into the relevant groups."
8398   (interactive
8399    (list current-prefix-arg
8400          (let* ((methods (gnus-methods-using 'respool))
8401                 (methname
8402                  (symbol-name (or gnus-summary-respool-default-method
8403                                   (car (gnus-find-method-for-group
8404                                         gnus-newsgroup-name)))))
8405                 (method
8406                  (gnus-completing-read
8407                   methname "What backend do you want to use when respooling?"
8408                   methods nil t nil 'gnus-mail-method-history))
8409                 ms)
8410            (cond
8411             ((zerop (length (setq ms (gnus-servers-using-backend
8412                                       (intern method)))))
8413              (list (intern method) ""))
8414             ((= 1 (length ms))
8415              (car ms))
8416             (t
8417              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8418                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8419                            ms-alist))))))))
8420   (unless method
8421     (error "No method given for respooling"))
8422   (if (assoc (symbol-name
8423               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8424              (gnus-methods-using 'respool))
8425       (gnus-summary-move-article n nil method)
8426     (gnus-summary-copy-article n nil method)))
8427
8428 (defun gnus-summary-import-article (file &optional edit)
8429   "Import an arbitrary file into a mail newsgroup."
8430   (interactive "fImport file: \nP")
8431   (let ((group gnus-newsgroup-name)
8432         (now (current-time))
8433         atts lines group-art)
8434     (unless (gnus-check-backend-function 'request-accept-article group)
8435       (error "%s does not support article importing" group))
8436     (or (file-readable-p file)
8437         (not (file-regular-p file))
8438         (error "Can't read %s" file))
8439     (save-excursion
8440       (set-buffer (gnus-get-buffer-create " *import file*"))
8441       (erase-buffer)
8442       (nnheader-insert-file-contents file)
8443       (goto-char (point-min))
8444       (if (nnheader-article-p)
8445           (save-restriction
8446             (goto-char (point-min))
8447             (search-forward "\n\n" nil t)
8448             (narrow-to-region (point-min) (1- (point)))
8449             (goto-char (point-min))
8450             (unless (re-search-forward "^date:" nil t)
8451               (goto-char (point-max))
8452               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8453        ;; This doesn't look like an article, so we fudge some headers.
8454         (setq atts (file-attributes file)
8455               lines (count-lines (point-min) (point-max)))
8456         (insert "From: " (read-string "From: ") "\n"
8457                 "Subject: " (read-string "Subject: ") "\n"
8458                 "Date: " (message-make-date (nth 5 atts)) "\n"
8459                 "Message-ID: " (message-make-message-id) "\n"
8460                 "Lines: " (int-to-string lines) "\n"
8461                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8462       (setq group-art (gnus-request-accept-article group nil t))
8463       (kill-buffer (current-buffer)))
8464     (setq gnus-newsgroup-active (gnus-activate-group group))
8465     (forward-line 1)
8466     (gnus-summary-goto-article (cdr group-art) nil t)
8467     (when edit
8468       (gnus-summary-edit-article))))
8469
8470 (defun gnus-summary-create-article ()
8471   "Create an article in a mail newsgroup."
8472   (interactive)
8473   (let ((group gnus-newsgroup-name)
8474         (now (current-time))
8475         group-art)
8476     (unless (gnus-check-backend-function 'request-accept-article group)
8477       (error "%s does not support article importing" group))
8478     (save-excursion
8479       (set-buffer (gnus-get-buffer-create " *import file*"))
8480       (erase-buffer)
8481       (goto-char (point-min))
8482       ;; This doesn't look like an article, so we fudge some headers.
8483       (insert "From: " (read-string "From: ") "\n"
8484               "Subject: " (read-string "Subject: ") "\n"
8485               "Date: " (message-make-date now) "\n"
8486               "Message-ID: " (message-make-message-id) "\n")
8487       (setq group-art (gnus-request-accept-article group nil t))
8488       (kill-buffer (current-buffer)))
8489     (setq gnus-newsgroup-active (gnus-activate-group group))
8490     (forward-line 1)
8491     (gnus-summary-goto-article (cdr group-art) nil t)
8492     (gnus-summary-edit-article)))
8493
8494 (defun gnus-summary-article-posted-p ()
8495   "Say whether the current (mail) article is available from news as well.
8496 This will be the case if the article has both been mailed and posted."
8497   (interactive)
8498   (let ((id (mail-header-references (gnus-summary-article-header)))
8499         (gnus-override-method (car (gnus-refer-article-methods))))
8500     (if (gnus-request-head id "")
8501         (gnus-message 2 "The current message was found on %s"
8502                       gnus-override-method)
8503       (gnus-message 2 "The current message couldn't be found on %s"
8504                     gnus-override-method)
8505       nil)))
8506
8507 (defun gnus-summary-expire-articles (&optional now)
8508   "Expire all articles that are marked as expirable in the current group."
8509   (interactive)
8510   (when (gnus-check-backend-function
8511          'request-expire-articles gnus-newsgroup-name)
8512     ;; This backend supports expiry.
8513     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8514            (expirable (if total
8515                           (progn
8516                             ;; We need to update the info for
8517                             ;; this group for `gnus-list-of-read-articles'
8518                             ;; to give us the right answer.
8519                             (gnus-run-hooks 'gnus-exit-group-hook)
8520                             (gnus-summary-update-info)
8521                             (gnus-list-of-read-articles gnus-newsgroup-name))
8522                         (setq gnus-newsgroup-expirable
8523                               (sort gnus-newsgroup-expirable '<))))
8524            (expiry-wait (if now 'immediate
8525                           (gnus-group-find-parameter
8526                            gnus-newsgroup-name 'expiry-wait)))
8527            (nnmail-expiry-target
8528             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8529                 nnmail-expiry-target))
8530            es)
8531       (when expirable
8532         ;; There are expirable articles in this group, so we run them
8533         ;; through the expiry process.
8534         (gnus-message 6 "Expiring articles...")
8535         (unless (gnus-check-group gnus-newsgroup-name)
8536           (error "Can't open server for %s" gnus-newsgroup-name))
8537         ;; The list of articles that weren't expired is returned.
8538         (save-excursion
8539           (if expiry-wait
8540               (let ((nnmail-expiry-wait-function nil)
8541                     (nnmail-expiry-wait expiry-wait))
8542                 (setq es (gnus-request-expire-articles
8543                           expirable gnus-newsgroup-name)))
8544             (setq es (gnus-request-expire-articles
8545                       expirable gnus-newsgroup-name)))
8546           (unless total
8547             (setq gnus-newsgroup-expirable es))
8548           ;; We go through the old list of expirable, and mark all
8549           ;; really expired articles as nonexistent.
8550           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8551             (let ((gnus-use-cache nil))
8552               (while expirable
8553                 (unless (memq (car expirable) es)
8554                   (when (gnus-data-find (car expirable))
8555                     (gnus-summary-mark-article
8556                      (car expirable) gnus-canceled-mark)))
8557                 (setq expirable (cdr expirable))))))
8558         (gnus-message 6 "Expiring articles...done")))))
8559
8560 (defun gnus-summary-expire-articles-now ()
8561   "Expunge all expirable articles in the current group.
8562 This means that *all* articles that are marked as expirable will be
8563 deleted forever, right now."
8564   (interactive)
8565   (or gnus-expert-user
8566       (gnus-yes-or-no-p
8567        "Are you really, really, really sure you want to delete all these messages? ")
8568       (error "Phew!"))
8569   (gnus-summary-expire-articles t))
8570
8571 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8572 (defun gnus-summary-delete-article (&optional n)
8573   "Delete the N next (mail) articles.
8574 This command actually deletes articles.  This is not a marking
8575 command.  The article will disappear forever from your life, never to
8576 return.
8577 If N is negative, delete backwards.
8578 If N is nil and articles have been marked with the process mark,
8579 delete these instead."
8580   (interactive "P")
8581   (unless (gnus-check-backend-function 'request-expire-articles
8582                                        gnus-newsgroup-name)
8583     (error "The current newsgroup does not support article deletion"))
8584   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8585     (error "Couldn't open server"))
8586   ;; Compute the list of articles to delete.
8587   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8588         not-deleted)
8589     (if (and gnus-novice-user
8590              (not (gnus-yes-or-no-p
8591                    (format "Do you really want to delete %s forever? "
8592                            (if (> (length articles) 1)
8593                                (format "these %s articles" (length articles))
8594                              "this article")))))
8595         ()
8596       ;; Delete the articles.
8597       (setq not-deleted (gnus-request-expire-articles
8598                          articles gnus-newsgroup-name 'force))
8599       (while articles
8600         (gnus-summary-remove-process-mark (car articles))
8601         ;; The backend might not have been able to delete the article
8602         ;; after all.
8603         (unless (memq (car articles) not-deleted)
8604           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8605         (setq articles (cdr articles)))
8606       (when not-deleted
8607         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8608     (gnus-summary-position-point)
8609     (gnus-set-mode-line 'summary)
8610     not-deleted))
8611
8612 (defun gnus-summary-edit-article (&optional arg)
8613   "Edit the current article.
8614 This will have permanent effect only in mail groups.
8615 If ARG is nil, edit the decoded articles.
8616 If ARG is 1, edit the raw articles.
8617 If ARG is 2, edit the raw articles even in read-only groups.
8618 If ARG is 3, edit the articles with the current handles.
8619 Otherwise, allow editing of articles even in read-only
8620 groups."
8621   (interactive "P")
8622   (let (force raw current-handles)
8623     (cond
8624      ((null arg))
8625      ((eq arg 1) (setq raw t))
8626      ((eq arg 2) (setq raw t
8627                        force t))
8628      ((eq arg 3) (setq current-handles
8629                        (and (gnus-buffer-live-p gnus-article-buffer)
8630                             (with-current-buffer gnus-article-buffer
8631                               (prog1
8632                                   gnus-article-mime-handles
8633                                 (setq gnus-article-mime-handles nil))))))
8634      (t (setq force t)))
8635     (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8636         (error "Can't edit the raw article in group nndraft:drafts"))
8637     (save-excursion
8638       (set-buffer gnus-summary-buffer)
8639       (let ((mail-parse-charset gnus-newsgroup-charset)
8640             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8641         (gnus-set-global-variables)
8642         (when (and (not force)
8643                    (gnus-group-read-only-p))
8644           (error "The current newsgroup does not support article editing"))
8645         (gnus-summary-show-article t)
8646         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8647           (with-current-buffer gnus-article-buffer
8648             (mm-enable-multibyte-mule4)))
8649         (if (equal gnus-newsgroup-name "nndraft:drafts")
8650             (setq raw t))
8651         (gnus-article-edit-article
8652          (if raw 'ignore
8653            `(lambda ()
8654               (let ((mbl mml-buffer-list))
8655                 (setq mml-buffer-list nil)
8656                 (mime-to-mml ,'current-handles)
8657                 (let ((mbl1 mml-buffer-list))
8658                   (setq mml-buffer-list mbl)
8659                   (set (make-local-variable 'mml-buffer-list) mbl1))
8660                 (make-local-hook 'kill-buffer-hook)
8661                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8662          `(lambda (no-highlight)
8663             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8664                   (message-options message-options)
8665                   (message-options-set-recipient)
8666                   (mail-parse-ignored-charsets
8667                    ',gnus-newsgroup-ignored-charsets))
8668               ,(if (not raw) '(progn
8669                                 (mml-to-mime)
8670                                 (mml-destroy-buffers)
8671                                 (remove-hook 'kill-buffer-hook
8672                                              'mml-destroy-buffers t)
8673                                 (kill-local-variable 'mml-buffer-list)))
8674               (gnus-summary-edit-article-done
8675                ,(or (mail-header-references gnus-current-headers) "")
8676                ,(gnus-group-read-only-p)
8677                ,gnus-summary-buffer no-highlight))))))))
8678
8679 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8680
8681 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8682                                                  no-highlight)
8683   "Make edits to the current article permanent."
8684   (interactive)
8685   (save-excursion
8686    ;; The buffer restriction contains the entire article if it exists.
8687     (when (article-goto-body)
8688       (let ((lines (count-lines (point) (point-max)))
8689             (length (- (point-max) (point)))
8690             (case-fold-search t)
8691             (body (copy-marker (point))))
8692         (goto-char (point-min))
8693         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8694           (delete-region (match-beginning 1) (match-end 1))
8695           (insert (number-to-string length)))
8696         (goto-char (point-min))
8697         (when (re-search-forward
8698                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8699           (delete-region (match-beginning 1) (match-end 1))
8700           (insert (number-to-string length)))
8701         (goto-char (point-min))
8702         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8703           (delete-region (match-beginning 1) (match-end 1))
8704           (insert (number-to-string lines))))))
8705   ;; Replace the article.
8706   (let ((buf (current-buffer)))
8707     (with-temp-buffer
8708       (insert-buffer-substring buf)
8709
8710       (if (and (not read-only)
8711                (not (gnus-request-replace-article
8712                      (cdr gnus-article-current) (car gnus-article-current)
8713                      (current-buffer) t)))
8714           (error "Couldn't replace article")
8715         ;; Update the summary buffer.
8716         (if (and references
8717                  (equal (message-tokenize-header references " ")
8718                         (message-tokenize-header
8719                          (or (message-fetch-field "references") "") " ")))
8720             ;; We only have to update this line.
8721             (save-excursion
8722               (save-restriction
8723                 (message-narrow-to-head)
8724                 (let ((head (buffer-string))
8725                       header)
8726                   (with-temp-buffer
8727                     (insert (format "211 %d Article retrieved.\n"
8728                                     (cdr gnus-article-current)))
8729                     (insert head)
8730                     (insert ".\n")
8731                     (let ((nntp-server-buffer (current-buffer)))
8732                       (setq header (car (gnus-get-newsgroup-headers
8733                                          (save-excursion
8734                                            (set-buffer gnus-summary-buffer)
8735                                            gnus-newsgroup-dependencies)
8736                                          t))))
8737                     (save-excursion
8738                       (set-buffer gnus-summary-buffer)
8739                       (gnus-data-set-header
8740                        (gnus-data-find (cdr gnus-article-current))
8741                        header)
8742                       (gnus-summary-update-article-line
8743                        (cdr gnus-article-current) header)
8744                       (if (gnus-summary-goto-subject
8745                            (cdr gnus-article-current) nil t)
8746                           (gnus-summary-update-secondary-mark
8747                            (cdr gnus-article-current))))))))
8748           ;; Update threads.
8749           (set-buffer (or buffer gnus-summary-buffer))
8750           (gnus-summary-update-article (cdr gnus-article-current))
8751           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8752               (gnus-summary-update-secondary-mark
8753                (cdr gnus-article-current))))
8754         ;; Prettify the article buffer again.
8755         (unless no-highlight
8756           (save-excursion
8757             (set-buffer gnus-article-buffer)
8758             ;;;!!! Fix this -- article should be rehighlighted.
8759             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8760             (set-buffer gnus-original-article-buffer)
8761             (gnus-request-article
8762              (cdr gnus-article-current)
8763              (car gnus-article-current) (current-buffer))))
8764         ;; Prettify the summary buffer line.
8765         (when (gnus-visual-p 'summary-highlight 'highlight)
8766           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8767
8768 (defun gnus-summary-edit-wash (key)
8769   "Perform editing command KEY in the article buffer."
8770   (interactive
8771    (list
8772     (progn
8773       (message "%s" (concat (this-command-keys) "- "))
8774       (read-char))))
8775   (message "")
8776   (gnus-summary-edit-article)
8777   (execute-kbd-macro (concat (this-command-keys) key))
8778   (gnus-article-edit-done))
8779
8780 ;;; Respooling
8781
8782 (defun gnus-summary-respool-query (&optional silent trace)
8783   "Query where the respool algorithm would put this article."
8784   (interactive)
8785   (let (gnus-mark-article-hook)
8786     (gnus-summary-select-article)
8787     (save-excursion
8788       (set-buffer gnus-original-article-buffer)
8789       (save-restriction
8790         (message-narrow-to-head)
8791         (let ((groups (nnmail-article-group 'identity trace)))
8792           (unless silent
8793             (if groups
8794                 (message "This message would go to %s"
8795                          (mapconcat 'car groups ", "))
8796               (message "This message would go to no groups"))
8797             groups))))))
8798
8799 (defun gnus-summary-respool-trace ()
8800   "Trace where the respool algorithm would put this article.
8801 Display a buffer showing all fancy splitting patterns which matched."
8802   (interactive)
8803   (gnus-summary-respool-query nil t))
8804
8805 ;; Summary marking commands.
8806
8807 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8808   "Mark articles which has the same subject as read, and then select the next.
8809 If UNMARK is positive, remove any kind of mark.
8810 If UNMARK is negative, tick articles."
8811   (interactive "P")
8812   (when unmark
8813     (setq unmark (prefix-numeric-value unmark)))
8814   (let ((count
8815          (gnus-summary-mark-same-subject
8816           (gnus-summary-article-subject) unmark)))
8817     ;; Select next unread article.  If auto-select-same mode, should
8818     ;; select the first unread article.
8819     (gnus-summary-next-article t (and gnus-auto-select-same
8820                                       (gnus-summary-article-subject)))
8821     (gnus-message 7 "%d article%s marked as %s"
8822                   count (if (= count 1) " is" "s are")
8823                   (if unmark "unread" "read"))))
8824
8825 (defun gnus-summary-kill-same-subject (&optional unmark)
8826   "Mark articles which has the same subject as read.
8827 If UNMARK is positive, remove any kind of mark.
8828 If UNMARK is negative, tick articles."
8829   (interactive "P")
8830   (when unmark
8831     (setq unmark (prefix-numeric-value unmark)))
8832   (let ((count
8833          (gnus-summary-mark-same-subject
8834           (gnus-summary-article-subject) unmark)))
8835     ;; If marked as read, go to next unread subject.
8836     (when (null unmark)
8837       ;; Go to next unread subject.
8838       (gnus-summary-next-subject 1 t))
8839     (gnus-message 7 "%d articles are marked as %s"
8840                   count (if unmark "unread" "read"))))
8841
8842 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8843   "Mark articles with same SUBJECT as read, and return marked number.
8844 If optional argument UNMARK is positive, remove any kinds of marks.
8845 If optional argument UNMARK is negative, mark articles as unread instead."
8846   (let ((count 1))
8847     (save-excursion
8848       (cond
8849        ((null unmark)                   ; Mark as read.
8850         (while (and
8851                 (progn
8852                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8853                   (gnus-summary-show-thread) t)
8854                 (gnus-summary-find-subject subject))
8855           (setq count (1+ count))))
8856        ((> unmark 0)                    ; Tick.
8857         (while (and
8858                 (progn
8859                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8860                   (gnus-summary-show-thread) t)
8861                 (gnus-summary-find-subject subject))
8862           (setq count (1+ count))))
8863        (t                               ; Mark as unread.
8864         (while (and
8865                 (progn
8866                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8867                   (gnus-summary-show-thread) t)
8868                 (gnus-summary-find-subject subject))
8869           (setq count (1+ count)))))
8870       (gnus-set-mode-line 'summary)
8871       ;; Return the number of marked articles.
8872       count)))
8873
8874 (defun gnus-summary-mark-as-processable (n &optional unmark)
8875   "Set the process mark on the next N articles.
8876 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8877 the process mark instead.  The difference between N and the actual
8878 number of articles marked is returned."
8879   (interactive "P")
8880   (if (and (null n) (gnus-region-active-p))
8881       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8882     (setq n (prefix-numeric-value n))
8883     (let ((backward (< n 0))
8884           (n (abs n)))
8885       (while (and
8886               (> n 0)
8887               (if unmark
8888                   (gnus-summary-remove-process-mark
8889                    (gnus-summary-article-number))
8890                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8891               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8892         (setq n (1- n)))
8893       (when (/= 0 n)
8894         (gnus-message 7 "No more articles"))
8895       (gnus-summary-recenter)
8896       (gnus-summary-position-point)
8897       n)))
8898
8899 (defun gnus-summary-unmark-as-processable (n)
8900   "Remove the process mark from the next N articles.
8901 If N is negative, unmark backward instead.  The difference between N and
8902 the actual number of articles unmarked is returned."
8903   (interactive "P")
8904   (gnus-summary-mark-as-processable n t))
8905
8906 (defun gnus-summary-unmark-all-processable ()
8907   "Remove the process mark from all articles."
8908   (interactive)
8909   (save-excursion
8910     (while gnus-newsgroup-processable
8911       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8912   (gnus-summary-position-point))
8913
8914 (defun gnus-summary-add-mark (article type)
8915   "Mark ARTICLE with a mark of TYPE."
8916   (let ((vtype (car (assq type gnus-article-mark-lists)))
8917         var)
8918     (if (not vtype)
8919         (error "No such mark type: %s" type)
8920       (setq var (intern (format "gnus-newsgroup-%s" type)))
8921       (set var (cons article (symbol-value var)))
8922       (if (memq type '(processable cached replied forwarded recent saved))
8923           (gnus-summary-update-secondary-mark article)
8924         ;;; !!! This is bogus.  We should find out what primary
8925         ;;; !!! mark we want to set.
8926         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8927
8928 (defun gnus-summary-mark-as-expirable (n)
8929   "Mark N articles forward as expirable.
8930 If N is negative, mark backward instead.  The difference between N and
8931 the actual number of articles marked is returned."
8932   (interactive "p")
8933   (gnus-summary-mark-forward n gnus-expirable-mark))
8934
8935 (defun gnus-summary-mark-article-as-replied (article)
8936   "Mark ARTICLE as replied to and update the summary line.
8937 ARTICLE can also be a list of articles."
8938   (interactive (list (gnus-summary-article-number)))
8939   (let ((articles (if (listp article) article (list article))))
8940     (dolist (article articles)
8941       (push article gnus-newsgroup-replied)
8942       (let ((buffer-read-only nil))
8943         (when (gnus-summary-goto-subject article nil t)
8944           (gnus-summary-update-secondary-mark article))))))
8945
8946 (defun gnus-summary-mark-article-as-forwarded (article)
8947   "Mark ARTICLE as forwarded and update the summary line.
8948 ARTICLE can also be a list of articles."
8949   (let ((articles (if (listp article) article (list article))))
8950     (dolist (article articles)
8951       (push article gnus-newsgroup-forwarded)
8952       (let ((buffer-read-only nil))
8953         (when (gnus-summary-goto-subject article nil t)
8954           (gnus-summary-update-secondary-mark article))))))
8955
8956 (defun gnus-summary-set-bookmark (article)
8957   "Set a bookmark in current article."
8958   (interactive (list (gnus-summary-article-number)))
8959   (when (or (not (get-buffer gnus-article-buffer))
8960             (not gnus-current-article)
8961             (not gnus-article-current)
8962             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8963     (error "No current article selected"))
8964   ;; Remove old bookmark, if one exists.
8965   (let ((old (assq article gnus-newsgroup-bookmarks)))
8966     (when old
8967       (setq gnus-newsgroup-bookmarks
8968             (delq old gnus-newsgroup-bookmarks))))
8969   ;; Set the new bookmark, which is on the form
8970   ;; (article-number . line-number-in-body).
8971   (push
8972    (cons article
8973          (save-excursion
8974            (set-buffer gnus-article-buffer)
8975            (count-lines
8976             (min (point)
8977                  (save-excursion
8978                    (goto-char (point-min))
8979                    (search-forward "\n\n" nil t)
8980                    (point)))
8981             (point))))
8982    gnus-newsgroup-bookmarks)
8983   (gnus-message 6 "A bookmark has been added to the current article."))
8984
8985 (defun gnus-summary-remove-bookmark (article)
8986   "Remove the bookmark from the current article."
8987   (interactive (list (gnus-summary-article-number)))
8988   ;; Remove old bookmark, if one exists.
8989   (let ((old (assq article gnus-newsgroup-bookmarks)))
8990     (if old
8991         (progn
8992           (setq gnus-newsgroup-bookmarks
8993                 (delq old gnus-newsgroup-bookmarks))
8994           (gnus-message 6 "Removed bookmark."))
8995       (gnus-message 6 "No bookmark in current article."))))
8996
8997 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8998 (defun gnus-summary-mark-as-dormant (n)
8999   "Mark N articles forward as dormant.
9000 If N is negative, mark backward instead.  The difference between N and
9001 the actual number of articles marked is returned."
9002   (interactive "p")
9003   (gnus-summary-mark-forward n gnus-dormant-mark))
9004
9005 (defun gnus-summary-set-process-mark (article)
9006   "Set the process mark on ARTICLE and update the summary line."
9007   (setq gnus-newsgroup-processable
9008         (cons article
9009               (delq article gnus-newsgroup-processable)))
9010   (when (gnus-summary-goto-subject article)
9011     (gnus-summary-show-thread)
9012     (gnus-summary-goto-subject article)
9013     (gnus-summary-update-secondary-mark article)))
9014
9015 (defun gnus-summary-remove-process-mark (article)
9016   "Remove the process mark from ARTICLE and update the summary line."
9017   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9018   (when (gnus-summary-goto-subject article)
9019     (gnus-summary-show-thread)
9020     (gnus-summary-goto-subject article)
9021     (gnus-summary-update-secondary-mark article)))
9022
9023 (defun gnus-summary-set-saved-mark (article)
9024   "Set the process mark on ARTICLE and update the summary line."
9025   (push article gnus-newsgroup-saved)
9026   (when (gnus-summary-goto-subject article)
9027     (gnus-summary-update-secondary-mark article)))
9028
9029 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9030   "Mark N articles as read forwards.
9031 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9032 The difference between N and the actual number of articles marked is
9033 returned.
9034 Iff NO-EXPIRE, auto-expiry will be inhibited."
9035   (interactive "p")
9036   (gnus-summary-show-thread)
9037   (let ((backward (< n 0))
9038         (gnus-summary-goto-unread
9039          (and gnus-summary-goto-unread
9040               (not (eq gnus-summary-goto-unread 'never))
9041               (not (memq mark (list gnus-unread-mark
9042                                     gnus-ticked-mark gnus-dormant-mark)))))
9043         (n (abs n))
9044         (mark (or mark gnus-del-mark)))
9045     (while (and (> n 0)
9046                 (gnus-summary-mark-article nil mark no-expire)
9047                 (zerop (gnus-summary-next-subject
9048                         (if backward -1 1)
9049                         (and gnus-summary-goto-unread
9050                              (not (eq gnus-summary-goto-unread 'never)))
9051                         t)))
9052       (setq n (1- n)))
9053     (when (/= 0 n)
9054       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9055     (gnus-summary-recenter)
9056     (gnus-summary-position-point)
9057     (gnus-set-mode-line 'summary)
9058     n))
9059
9060 (defun gnus-summary-mark-article-as-read (mark)
9061   "Mark the current article quickly as read with MARK."
9062   (let ((article (gnus-summary-article-number)))
9063     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9064     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9065     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9066     (push (cons article mark) gnus-newsgroup-reads)
9067     ;; Possibly remove from cache, if that is used.
9068     (when gnus-use-cache
9069       (gnus-cache-enter-remove-article article))
9070     ;; Allow the backend to change the mark.
9071     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9072     ;; Check for auto-expiry.
9073     (when (and gnus-newsgroup-auto-expire
9074                (memq mark gnus-auto-expirable-marks))
9075       (setq mark gnus-expirable-mark)
9076       ;; Let the backend know about the mark change.
9077       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9078       (push article gnus-newsgroup-expirable))
9079     ;; Set the mark in the buffer.
9080     (gnus-summary-update-mark mark 'unread)
9081     t))
9082
9083 (defun gnus-summary-mark-article-as-unread (mark)
9084   "Mark the current article quickly as unread with MARK."
9085   (let* ((article (gnus-summary-article-number))
9086          (old-mark (gnus-summary-article-mark article)))
9087     ;; Allow the backend to change the mark.
9088     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9089     (if (eq mark old-mark)
9090         t
9091       (if (<= article 0)
9092           (progn
9093             (gnus-error 1 "Can't mark negative article numbers")
9094             nil)
9095         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9096         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9097         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9098         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9099         (cond ((= mark gnus-ticked-mark)
9100                (push article gnus-newsgroup-marked))
9101               ((= mark gnus-dormant-mark)
9102                (push article gnus-newsgroup-dormant))
9103               (t
9104                (push article gnus-newsgroup-unreads)))
9105         (gnus-pull article gnus-newsgroup-reads)
9106
9107         ;; See whether the article is to be put in the cache.
9108         (and gnus-use-cache
9109              (vectorp (gnus-summary-article-header article))
9110              (save-excursion
9111                (gnus-cache-possibly-enter-article
9112                 gnus-newsgroup-name article
9113                 (= mark gnus-ticked-mark)
9114                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9115
9116         ;; Fix the mark.
9117         (gnus-summary-update-mark mark 'unread)
9118         t))))
9119
9120 (defun gnus-summary-mark-article (&optional article mark no-expire)
9121   "Mark ARTICLE with MARK.  MARK can be any character.
9122 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9123 `??' (dormant) and `?E' (expirable).
9124 If MARK is nil, then the default character `?r' is used.
9125 If ARTICLE is nil, then the article on the current line will be
9126 marked.
9127 Iff NO-EXPIRE, auto-expiry will be inhibited."
9128   ;; The mark might be a string.
9129   (when (stringp mark)
9130     (setq mark (aref mark 0)))
9131   ;; If no mark is given, then we check auto-expiring.
9132   (when (null mark)
9133     (setq mark gnus-del-mark))
9134   (when (and (not no-expire)
9135              gnus-newsgroup-auto-expire
9136              (memq mark gnus-auto-expirable-marks))
9137     (setq mark gnus-expirable-mark))
9138   (let ((article (or article (gnus-summary-article-number)))
9139         (old-mark (gnus-summary-article-mark article)))
9140     ;; Allow the backend to change the mark.
9141     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9142     (if (eq mark old-mark)
9143         t
9144       (unless article
9145         (error "No article on current line"))
9146       (if (not (if (or (= mark gnus-unread-mark)
9147                        (= mark gnus-ticked-mark)
9148                        (= mark gnus-dormant-mark))
9149                    (gnus-mark-article-as-unread article mark)
9150                  (gnus-mark-article-as-read article mark)))
9151           t
9152         ;; See whether the article is to be put in the cache.
9153         (and gnus-use-cache
9154              (not (= mark gnus-canceled-mark))
9155              (vectorp (gnus-summary-article-header article))
9156              (save-excursion
9157                (gnus-cache-possibly-enter-article
9158                 gnus-newsgroup-name article
9159                 (= mark gnus-ticked-mark)
9160                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9161
9162         (when (gnus-summary-goto-subject article nil t)
9163           (let ((buffer-read-only nil))
9164             (gnus-summary-show-thread)
9165             ;; Fix the mark.
9166             (gnus-summary-update-mark mark 'unread)
9167             t))))))
9168
9169 (defun gnus-summary-update-secondary-mark (article)
9170   "Update the secondary (read, process, cache) mark."
9171   (gnus-summary-update-mark
9172    (cond ((memq article gnus-newsgroup-processable)
9173           gnus-process-mark)
9174          ((memq article gnus-newsgroup-cached)
9175           gnus-cached-mark)
9176          ((memq article gnus-newsgroup-replied)
9177           gnus-replied-mark)
9178          ((memq article gnus-newsgroup-forwarded)
9179           gnus-forwarded-mark)
9180          ((memq article gnus-newsgroup-saved)
9181           gnus-saved-mark)
9182          ((memq article gnus-newsgroup-recent)
9183           gnus-recent-mark)
9184          ((memq article gnus-newsgroup-unseen)
9185           gnus-unseen-mark)
9186          (t gnus-no-mark))
9187    'replied)
9188   (when (gnus-visual-p 'summary-highlight 'highlight)
9189     (gnus-run-hooks 'gnus-summary-update-hook))
9190   t)
9191
9192 (defun gnus-summary-update-mark (mark type)
9193   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9194         (buffer-read-only nil))
9195     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9196     (when forward
9197       (when (looking-at "\r")
9198         (incf forward))
9199       (when (<= (+ forward (point)) (point-max))
9200         ;; Go to the right position on the line.
9201         (goto-char (+ forward (point)))
9202         ;; Replace the old mark with the new mark.
9203         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9204         ;; Optionally update the marks by some user rule.
9205         (when (eq type 'unread)
9206           (gnus-data-set-mark
9207            (gnus-data-find (gnus-summary-article-number)) mark)
9208           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9209
9210 (defun gnus-mark-article-as-read (article &optional mark)
9211   "Enter ARTICLE in the pertinent lists and remove it from others."
9212   ;; Make the article expirable.
9213   (let ((mark (or mark gnus-del-mark)))
9214     (if (= mark gnus-expirable-mark)
9215         (push article gnus-newsgroup-expirable)
9216       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9217     ;; Remove from unread and marked lists.
9218     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9219     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9220     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9221     (push (cons article mark) gnus-newsgroup-reads)
9222     ;; Possibly remove from cache, if that is used.
9223     (when gnus-use-cache
9224       (gnus-cache-enter-remove-article article))
9225     t))
9226
9227 (defun gnus-mark-article-as-unread (article &optional mark)
9228   "Enter ARTICLE in the pertinent lists and remove it from others."
9229   (let ((mark (or mark gnus-ticked-mark)))
9230     (if (<= article 0)
9231         (progn
9232           (gnus-error 1 "Can't mark negative article numbers")
9233           nil)
9234       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9235             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9236             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9237             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9238
9239       ;; Unsuppress duplicates?
9240       (when gnus-suppress-duplicates
9241         (gnus-dup-unsuppress-article article))
9242
9243       (cond ((= mark gnus-ticked-mark)
9244              (push article gnus-newsgroup-marked))
9245             ((= mark gnus-dormant-mark)
9246              (push article gnus-newsgroup-dormant))
9247             (t
9248              (push article gnus-newsgroup-unreads)))
9249       (gnus-pull article gnus-newsgroup-reads)
9250       t)))
9251
9252 (defalias 'gnus-summary-mark-as-unread-forward
9253   'gnus-summary-tick-article-forward)
9254 (make-obsolete 'gnus-summary-mark-as-unread-forward
9255                'gnus-summary-tick-article-forward)
9256 (defun gnus-summary-tick-article-forward (n)
9257   "Tick N articles forwards.
9258 If N is negative, tick backwards instead.
9259 The difference between N and the number of articles ticked is returned."
9260   (interactive "p")
9261   (gnus-summary-mark-forward n gnus-ticked-mark))
9262
9263 (defalias 'gnus-summary-mark-as-unread-backward
9264   'gnus-summary-tick-article-backward)
9265 (make-obsolete 'gnus-summary-mark-as-unread-backward
9266                'gnus-summary-tick-article-backward)
9267 (defun gnus-summary-tick-article-backward (n)
9268   "Tick N articles backwards.
9269 The difference between N and the number of articles ticked is returned."
9270   (interactive "p")
9271   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9272
9273 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9274 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9275 (defun gnus-summary-tick-article (&optional article clear-mark)
9276   "Mark current article as unread.
9277 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9278 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9279   (interactive)
9280   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9281                                        gnus-ticked-mark)))
9282
9283 (defun gnus-summary-mark-as-read-forward (n)
9284   "Mark N articles as read forwards.
9285 If N is negative, mark backwards instead.
9286 The difference between N and the actual number of articles marked is
9287 returned."
9288   (interactive "p")
9289   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9290
9291 (defun gnus-summary-mark-as-read-backward (n)
9292   "Mark the N articles as read backwards.
9293 The difference between N and the actual number of articles marked is
9294 returned."
9295   (interactive "p")
9296   (gnus-summary-mark-forward
9297    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9298
9299 (defun gnus-summary-mark-as-read (&optional article mark)
9300   "Mark current article as read.
9301 ARTICLE specifies the article to be marked as read.
9302 MARK specifies a string to be inserted at the beginning of the line."
9303   (gnus-summary-mark-article article mark))
9304
9305 (defun gnus-summary-clear-mark-forward (n)
9306   "Clear marks from N articles forward.
9307 If N is negative, clear backward instead.
9308 The difference between N and the number of marks cleared is returned."
9309   (interactive "p")
9310   (gnus-summary-mark-forward n gnus-unread-mark))
9311
9312 (defun gnus-summary-clear-mark-backward (n)
9313   "Clear marks from N articles backward.
9314 The difference between N and the number of marks cleared is returned."
9315   (interactive "p")
9316   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9317
9318 (defun gnus-summary-mark-unread-as-read ()
9319   "Intended to be used by `gnus-summary-mark-article-hook'."
9320   (when (memq gnus-current-article gnus-newsgroup-unreads)
9321     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9322
9323 (defun gnus-summary-mark-read-and-unread-as-read ()
9324   "Intended to be used by `gnus-summary-mark-article-hook'."
9325   (let ((mark (gnus-summary-article-mark)))
9326     (when (or (gnus-unread-mark-p mark)
9327               (gnus-read-mark-p mark))
9328       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9329
9330 (defun gnus-summary-mark-unread-as-ticked ()
9331   "Intended to be used by `gnus-summary-mark-article-hook'."
9332   (when (memq gnus-current-article gnus-newsgroup-unreads)
9333     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9334
9335 (defun gnus-summary-mark-region-as-read (point mark all)
9336   "Mark all unread articles between point and mark as read.
9337 If given a prefix, mark all articles between point and mark as read,
9338 even ticked and dormant ones."
9339   (interactive "r\nP")
9340   (save-excursion
9341     (let (article)
9342       (goto-char point)
9343       (beginning-of-line)
9344       (while (and
9345               (< (point) mark)
9346               (progn
9347                 (when (or all
9348                           (memq (setq article (gnus-summary-article-number))
9349                                 gnus-newsgroup-unreads))
9350                   (gnus-summary-mark-article article gnus-del-mark))
9351                 t)
9352               (gnus-summary-find-next))))))
9353
9354 (defun gnus-summary-mark-below (score mark)
9355   "Mark articles with score less than SCORE with MARK."
9356   (interactive "P\ncMark: ")
9357   (setq score (if score
9358                   (prefix-numeric-value score)
9359                 (or gnus-summary-default-score 0)))
9360   (save-excursion
9361     (set-buffer gnus-summary-buffer)
9362     (goto-char (point-min))
9363     (while
9364         (progn
9365           (and (< (gnus-summary-article-score) score)
9366                (gnus-summary-mark-article nil mark))
9367           (gnus-summary-find-next)))))
9368
9369 (defun gnus-summary-kill-below (&optional score)
9370   "Mark articles with score below SCORE as read."
9371   (interactive "P")
9372   (gnus-summary-mark-below score gnus-killed-mark))
9373
9374 (defun gnus-summary-clear-above (&optional score)
9375   "Clear all marks from articles with score above SCORE."
9376   (interactive "P")
9377   (gnus-summary-mark-above score gnus-unread-mark))
9378
9379 (defun gnus-summary-tick-above (&optional score)
9380   "Tick all articles with score above SCORE."
9381   (interactive "P")
9382   (gnus-summary-mark-above score gnus-ticked-mark))
9383
9384 (defun gnus-summary-mark-above (score mark)
9385   "Mark articles with score over SCORE with MARK."
9386   (interactive "P\ncMark: ")
9387   (setq score (if score
9388                   (prefix-numeric-value score)
9389                 (or gnus-summary-default-score 0)))
9390   (save-excursion
9391     (set-buffer gnus-summary-buffer)
9392     (goto-char (point-min))
9393     (while (and (progn
9394                   (when (> (gnus-summary-article-score) score)
9395                     (gnus-summary-mark-article nil mark))
9396                   t)
9397                 (gnus-summary-find-next)))))
9398
9399 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9400 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9401 (defun gnus-summary-limit-include-expunged (&optional no-error)
9402   "Display all the hidden articles that were expunged for low scores."
9403   (interactive)
9404   (let ((buffer-read-only nil))
9405     (let ((scored gnus-newsgroup-scored)
9406           headers h)
9407       (while scored
9408         (unless (gnus-summary-article-header (caar scored))
9409           (and (setq h (gnus-number-to-header (caar scored)))
9410                (< (cdar scored) gnus-summary-expunge-below)
9411                (push h headers)))
9412         (setq scored (cdr scored)))
9413       (if (not headers)
9414           (when (not no-error)
9415             (error "No expunged articles hidden"))
9416         (goto-char (point-min))
9417         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9418         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9419         (mapcar (lambda (x) (push (mail-header-number x)
9420                                   gnus-newsgroup-limit))
9421                 headers)
9422         (gnus-summary-prepare-unthreaded (nreverse headers))
9423         (goto-char (point-min))
9424         (gnus-summary-position-point)
9425         t))))
9426
9427 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9428   "Mark all unread articles in this newsgroup as read.
9429 If prefix argument ALL is non-nil, ticked and dormant articles will
9430 also be marked as read.
9431 If QUIETLY is non-nil, no questions will be asked.
9432 If TO-HERE is non-nil, it should be a point in the buffer.  All
9433 articles before (after, if REVERSE is set) this point will be marked as read.
9434 Note that this function will only catch up the unread article
9435 in the current summary buffer limitation.
9436 The number of articles marked as read is returned."
9437   (interactive "P")
9438   (prog1
9439       (save-excursion
9440         (when (or quietly
9441                   (not gnus-interactive-catchup) ;Without confirmation?
9442                   gnus-expert-user
9443                   (gnus-y-or-n-p
9444                    (if all
9445                        "Mark absolutely all articles as read? "
9446                      "Mark all unread articles as read? ")))
9447           (if (and not-mark
9448                    (not gnus-newsgroup-adaptive)
9449                    (not gnus-newsgroup-auto-expire)
9450                    (not gnus-suppress-duplicates)
9451                    (or (not gnus-use-cache)
9452                        (eq gnus-use-cache 'passive)))
9453               (progn
9454                 (when all
9455                   (setq gnus-newsgroup-marked nil
9456                         gnus-newsgroup-dormant nil))
9457                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9458             ;; We actually mark all articles as canceled, which we
9459             ;; have to do when using auto-expiry or adaptive scoring.
9460             (gnus-summary-show-all-threads)
9461             (if (and to-here reverse)
9462                 (progn
9463                   (goto-char to-here)
9464                   (while (and
9465                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9466                           (gnus-summary-find-next (not all) nil nil t))))
9467               (when (gnus-summary-first-subject (not all) t)
9468                 (while (and
9469                         (if to-here (< (point) to-here) t)
9470                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9471                         (gnus-summary-find-next (not all) nil nil t)))))
9472             (gnus-set-mode-line 'summary))
9473           t))
9474     (gnus-summary-position-point)))
9475
9476 (defun gnus-summary-catchup-to-here (&optional all)
9477   "Mark all unticked articles before the current one as read.
9478 If ALL is non-nil, also mark ticked and dormant articles as read."
9479   (interactive "P")
9480   (save-excursion
9481     (gnus-save-hidden-threads
9482       (let ((beg (point)))
9483         ;; We check that there are unread articles.
9484         (when (or all (gnus-summary-find-prev))
9485           (gnus-summary-catchup all t beg)))))
9486   (gnus-summary-position-point))
9487
9488 (defun gnus-summary-catchup-from-here (&optional all)
9489   "Mark all unticked articles after the current one as read.
9490 If ALL is non-nil, also mark ticked and dormant articles as read."
9491   (interactive "P")
9492   (save-excursion
9493     (gnus-save-hidden-threads
9494       (let ((beg (point)))
9495         ;; We check that there are unread articles.
9496         (when (or all (gnus-summary-find-next))
9497           (gnus-summary-catchup all t beg nil t)))))
9498
9499   (gnus-summary-position-point))
9500 (defun gnus-summary-catchup-all (&optional quietly)
9501   "Mark all articles in this newsgroup as read."
9502   (interactive "P")
9503   (gnus-summary-catchup t quietly))
9504
9505 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9506   "Mark all unread articles in this group as read, then exit.
9507 If prefix argument ALL is non-nil, all articles are marked as read.
9508 If QUIETLY is non-nil, no questions will be asked."
9509   (interactive "P")
9510   (when (gnus-summary-catchup all quietly nil 'fast)
9511     ;; Select next newsgroup or exit.
9512     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9513              (eq gnus-auto-select-next 'quietly))
9514         (gnus-summary-next-group nil)
9515       (gnus-summary-exit))))
9516
9517 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9518   "Mark all articles in this newsgroup as read, and then exit."
9519   (interactive "P")
9520   (gnus-summary-catchup-and-exit t quietly))
9521
9522 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9523   "Mark all articles in this group as read and select the next group.
9524 If given a prefix, mark all articles, unread as well as ticked, as
9525 read."
9526   (interactive "P")
9527   (save-excursion
9528     (gnus-summary-catchup all))
9529   (gnus-summary-next-group))
9530
9531 ;;;
9532 ;;; with article
9533 ;;;
9534
9535 (defmacro gnus-with-article (article &rest forms)
9536   "Select ARTICLE and perform FORMS in the original article buffer.
9537 Then replace the article with the result."
9538   `(progn
9539      ;; We don't want the article to be marked as read.
9540      (let (gnus-mark-article-hook)
9541        (gnus-summary-select-article t t nil ,article))
9542      (set-buffer gnus-original-article-buffer)
9543      ,@forms
9544      (if (not (gnus-check-backend-function
9545                'request-replace-article (car gnus-article-current)))
9546          (gnus-message 5 "Read-only group; not replacing")
9547        (unless (gnus-request-replace-article
9548                 ,article (car gnus-article-current)
9549                 (current-buffer) t)
9550          (error "Couldn't replace article")))
9551      ;; The cache and backlog have to be flushed somewhat.
9552      (when gnus-keep-backlog
9553        (gnus-backlog-remove-article
9554         (car gnus-article-current) (cdr gnus-article-current)))
9555      (when gnus-use-cache
9556        (gnus-cache-update-article
9557         (car gnus-article-current) (cdr gnus-article-current)))))
9558
9559 (put 'gnus-with-article 'lisp-indent-function 1)
9560 (put 'gnus-with-article 'edebug-form-spec '(form body))
9561
9562 ;; Thread-based commands.
9563
9564 (defun gnus-summary-articles-in-thread (&optional article)
9565   "Return a list of all articles in the current thread.
9566 If ARTICLE is non-nil, return all articles in the thread that starts
9567 with that article."
9568   (let* ((article (or article (gnus-summary-article-number)))
9569          (data (gnus-data-find-list article))
9570          (top-level (gnus-data-level (car data)))
9571          (top-subject
9572           (cond ((null gnus-thread-operation-ignore-subject)
9573                  (gnus-simplify-subject-re
9574                   (mail-header-subject (gnus-data-header (car data)))))
9575                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9576                  (gnus-simplify-subject-fuzzy
9577                   (mail-header-subject (gnus-data-header (car data)))))
9578                 (t nil)))
9579          (end-point (save-excursion
9580                       (if (gnus-summary-go-to-next-thread)
9581                           (point) (point-max))))
9582          articles)
9583     (while (and data
9584                 (< (gnus-data-pos (car data)) end-point))
9585       (when (or (not top-subject)
9586                 (string= top-subject
9587                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9588                              (gnus-simplify-subject-fuzzy
9589                               (mail-header-subject
9590                                (gnus-data-header (car data))))
9591                            (gnus-simplify-subject-re
9592                             (mail-header-subject
9593                              (gnus-data-header (car data)))))))
9594         (push (gnus-data-number (car data)) articles))
9595       (unless (and (setq data (cdr data))
9596                    (> (gnus-data-level (car data)) top-level))
9597         (setq data nil)))
9598     ;; Return the list of articles.
9599     (nreverse articles)))
9600
9601 (defun gnus-summary-rethread-current ()
9602   "Rethread the thread the current article is part of."
9603   (interactive)
9604   (let* ((gnus-show-threads t)
9605          (article (gnus-summary-article-number))
9606          (id (mail-header-id (gnus-summary-article-header)))
9607          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9608     (unless id
9609       (error "No article on the current line"))
9610     (gnus-rebuild-thread id)
9611     (gnus-summary-goto-subject article)))
9612
9613 (defun gnus-summary-reparent-thread ()
9614   "Make the current article child of the marked (or previous) article.
9615
9616 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9617 is non-nil or the Subject: of both articles are the same."
9618   (interactive)
9619   (unless (not (gnus-group-read-only-p))
9620     (error "The current newsgroup does not support article editing"))
9621   (unless (<= (length gnus-newsgroup-processable) 1)
9622     (error "No more than one article may be marked"))
9623   (save-window-excursion
9624     (let ((gnus-article-buffer " *reparent*")
9625           (current-article (gnus-summary-article-number))
9626           ;; First grab the marked article, otherwise one line up.
9627           (parent-article (if (not (null gnus-newsgroup-processable))
9628                               (car gnus-newsgroup-processable)
9629                             (save-excursion
9630                               (if (eq (forward-line -1) 0)
9631                                   (gnus-summary-article-number)
9632                                 (error "Beginning of summary buffer"))))))
9633       (unless (not (eq current-article parent-article))
9634         (error "An article may not be self-referential"))
9635       (let ((message-id (mail-header-id
9636                          (gnus-summary-article-header parent-article))))
9637         (unless (and message-id (not (equal message-id "")))
9638           (error "No message-id in desired parent"))
9639         (gnus-with-article current-article
9640           (save-restriction
9641             (goto-char (point-min))
9642             (message-narrow-to-head)
9643             (if (re-search-forward "^References: " nil t)
9644                 (progn
9645                   (re-search-forward "^[^ \t]" nil t)
9646                   (forward-line -1)
9647                   (end-of-line)
9648                   (insert " " message-id))
9649               (insert "References: " message-id "\n"))))
9650         (set-buffer gnus-summary-buffer)
9651         (gnus-summary-unmark-all-processable)
9652         (gnus-summary-update-article current-article)
9653         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9654             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9655         (gnus-summary-rethread-current)
9656         (gnus-message 3 "Article %d is now the child of article %d"
9657                       current-article parent-article)))))
9658
9659 (defun gnus-summary-toggle-threads (&optional arg)
9660   "Toggle showing conversation threads.
9661 If ARG is positive number, turn showing conversation threads on."
9662   (interactive "P")
9663   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9664     (setq gnus-show-threads
9665           (if (null arg) (not gnus-show-threads)
9666             (> (prefix-numeric-value arg) 0)))
9667     (gnus-summary-prepare)
9668     (gnus-summary-goto-subject current)
9669     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9670     (gnus-summary-position-point)))
9671
9672 (defun gnus-summary-show-all-threads ()
9673   "Show all threads."
9674   (interactive)
9675   (save-excursion
9676     (let ((buffer-read-only nil))
9677       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9678   (gnus-summary-position-point))
9679
9680 (defun gnus-summary-show-thread ()
9681   "Show thread subtrees.
9682 Returns nil if no thread was there to be shown."
9683   (interactive)
9684   (let ((buffer-read-only nil)
9685         (orig (point))
9686         ;; first goto end then to beg, to have point at beg after let
9687         (end (progn (end-of-line) (point)))
9688         (beg (progn (beginning-of-line) (point))))
9689     (prog1
9690         ;; Any hidden lines here?
9691         (search-forward "\r" end t)
9692       (subst-char-in-region beg end ?\^M ?\n t)
9693       (goto-char orig)
9694       (gnus-summary-position-point))))
9695
9696 (defun gnus-summary-maybe-hide-threads ()
9697   "If requested, hide the threads that should be hidden."
9698   (when (and gnus-show-threads
9699              gnus-thread-hide-subtree)
9700     (gnus-summary-hide-all-threads
9701      (if (or (consp gnus-thread-hide-subtree)
9702              (gnus-functionp gnus-thread-hide-subtree))
9703          (gnus-make-predicate gnus-thread-hide-subtree)
9704        nil))))
9705
9706 ;;; Hiding predicates.
9707
9708 (defun gnus-article-unread-p (header)
9709   (memq (mail-header-number header) gnus-newsgroup-unreads))
9710
9711 (defun gnus-article-unseen-p (header)
9712   (memq (mail-header-number header) gnus-newsgroup-unseen))
9713
9714 (defun gnus-map-articles (predicate articles)
9715   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
9716   (apply 'gnus-or (mapcar predicate
9717                           (mapcar 'gnus-summary-article-header articles))))
9718
9719 (defun gnus-summary-hide-all-threads (&optional predicate)
9720   "Hide all thread subtrees.
9721 If PREDICATE is supplied, threads that satisfy this predicate
9722 will not be hidden."
9723   (interactive)
9724   (save-excursion
9725     (goto-char (point-min))
9726     (let ((end nil))
9727       (while (not end)
9728         (when (or (not predicate)
9729                   (gnus-map-articles
9730                    predicate (gnus-summary-article-children)))
9731             (gnus-summary-hide-thread))
9732         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
9733   (gnus-summary-position-point))
9734
9735 (defun gnus-summary-hide-thread ()
9736   "Hide thread subtrees.
9737 If PREDICATE is supplied, threads that satisfy this predicate
9738 will not be hidden.
9739 Returns nil if no threads were there to be hidden."
9740   (interactive)
9741   (let ((buffer-read-only nil)
9742         (start (point))
9743         (article (gnus-summary-article-number)))
9744     (goto-char start)
9745     ;; Go forward until either the buffer ends or the subthread
9746     ;; ends.
9747     (when (and (not (eobp))
9748                (or (zerop (gnus-summary-next-thread 1 t))
9749                    (goto-char (point-max))))
9750       (prog1
9751           (if (and (> (point) start)
9752                    (search-backward "\n" start t))
9753               (progn
9754                 (subst-char-in-region start (point) ?\n ?\^M)
9755                 (gnus-summary-goto-subject article))
9756             (goto-char start)
9757             nil)))))
9758
9759 (defun gnus-summary-go-to-next-thread (&optional previous)
9760   "Go to the same level (or less) next thread.
9761 If PREVIOUS is non-nil, go to previous thread instead.
9762 Return the article number moved to, or nil if moving was impossible."
9763   (let ((level (gnus-summary-thread-level))
9764         (way (if previous -1 1))
9765         (beg (point)))
9766     (forward-line way)
9767     (while (and (not (eobp))
9768                 (< level (gnus-summary-thread-level)))
9769       (forward-line way))
9770     (if (eobp)
9771         (progn
9772           (goto-char beg)
9773           nil)
9774       (setq beg (point))
9775       (prog1
9776           (gnus-summary-article-number)
9777         (goto-char beg)))))
9778
9779 (defun gnus-summary-next-thread (n &optional silent)
9780   "Go to the same level next N'th thread.
9781 If N is negative, search backward instead.
9782 Returns the difference between N and the number of skips actually
9783 done.
9784
9785 If SILENT, don't output messages."
9786   (interactive "p")
9787   (let ((backward (< n 0))
9788         (n (abs n)))
9789     (while (and (> n 0)
9790                 (gnus-summary-go-to-next-thread backward))
9791       (decf n))
9792     (unless silent
9793       (gnus-summary-position-point))
9794     (when (and (not silent) (/= 0 n))
9795       (gnus-message 7 "No more threads"))
9796     n))
9797
9798 (defun gnus-summary-prev-thread (n)
9799   "Go to the same level previous N'th thread.
9800 Returns the difference between N and the number of skips actually
9801 done."
9802   (interactive "p")
9803   (gnus-summary-next-thread (- n)))
9804
9805 (defun gnus-summary-go-down-thread ()
9806   "Go down one level in the current thread."
9807   (let ((children (gnus-summary-article-children)))
9808     (when children
9809       (gnus-summary-goto-subject (car children)))))
9810
9811 (defun gnus-summary-go-up-thread ()
9812   "Go up one level in the current thread."
9813   (let ((parent (gnus-summary-article-parent)))
9814     (when parent
9815       (gnus-summary-goto-subject parent))))
9816
9817 (defun gnus-summary-down-thread (n)
9818   "Go down thread N steps.
9819 If N is negative, go up instead.
9820 Returns the difference between N and how many steps down that were
9821 taken."
9822   (interactive "p")
9823   (let ((up (< n 0))
9824         (n (abs n)))
9825     (while (and (> n 0)
9826                 (if up (gnus-summary-go-up-thread)
9827                   (gnus-summary-go-down-thread)))
9828       (setq n (1- n)))
9829     (gnus-summary-position-point)
9830     (when (/= 0 n)
9831       (gnus-message 7 "Can't go further"))
9832     n))
9833
9834 (defun gnus-summary-up-thread (n)
9835   "Go up thread N steps.
9836 If N is negative, go down instead.
9837 Returns the difference between N and how many steps down that were
9838 taken."
9839   (interactive "p")
9840   (gnus-summary-down-thread (- n)))
9841
9842 (defun gnus-summary-top-thread ()
9843   "Go to the top of the thread."
9844   (interactive)
9845   (while (gnus-summary-go-up-thread))
9846   (gnus-summary-article-number))
9847
9848 (defun gnus-summary-kill-thread (&optional unmark)
9849   "Mark articles under current thread as read.
9850 If the prefix argument is positive, remove any kinds of marks.
9851 If the prefix argument is negative, tick articles instead."
9852   (interactive "P")
9853   (when unmark
9854     (setq unmark (prefix-numeric-value unmark)))
9855   (let ((articles (gnus-summary-articles-in-thread)))
9856     (save-excursion
9857       ;; Expand the thread.
9858       (gnus-summary-show-thread)
9859       ;; Mark all the articles.
9860       (while articles
9861         (gnus-summary-goto-subject (car articles))
9862         (cond ((null unmark)
9863                (gnus-summary-mark-article-as-read gnus-killed-mark))
9864               ((> unmark 0)
9865                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9866               (t
9867                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9868         (setq articles (cdr articles))))
9869     ;; Hide killed subtrees.
9870     (and (null unmark)
9871          gnus-thread-hide-killed
9872          (gnus-summary-hide-thread))
9873     ;; If marked as read, go to next unread subject.
9874     (when (null unmark)
9875       ;; Go to next unread subject.
9876       (gnus-summary-next-subject 1 t)))
9877   (gnus-set-mode-line 'summary))
9878
9879 ;; Summary sorting commands
9880
9881 (defun gnus-summary-sort-by-number (&optional reverse)
9882   "Sort the summary buffer by article number.
9883 Argument REVERSE means reverse order."
9884   (interactive "P")
9885   (gnus-summary-sort 'number reverse))
9886
9887 (defun gnus-summary-sort-by-author (&optional reverse)
9888   "Sort the summary buffer by author name alphabetically.
9889 If `case-fold-search' is non-nil, case of letters is ignored.
9890 Argument REVERSE means reverse order."
9891   (interactive "P")
9892   (gnus-summary-sort 'author reverse))
9893
9894 (defun gnus-summary-sort-by-subject (&optional reverse)
9895   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9896 If `case-fold-search' is non-nil, case of letters is ignored.
9897 Argument REVERSE means reverse order."
9898   (interactive "P")
9899   (gnus-summary-sort 'subject reverse))
9900
9901 (defun gnus-summary-sort-by-date (&optional reverse)
9902   "Sort the summary buffer by date.
9903 Argument REVERSE means reverse order."
9904   (interactive "P")
9905   (gnus-summary-sort 'date reverse))
9906
9907 (defun gnus-summary-sort-by-score (&optional reverse)
9908   "Sort the summary buffer by score.
9909 Argument REVERSE means reverse order."
9910   (interactive "P")
9911   (gnus-summary-sort 'score reverse))
9912
9913 (defun gnus-summary-sort-by-lines (&optional reverse)
9914   "Sort the summary buffer by the number of lines.
9915 Argument REVERSE means reverse order."
9916   (interactive "P")
9917   (gnus-summary-sort 'lines reverse))
9918
9919 (defun gnus-summary-sort-by-chars (&optional reverse)
9920   "Sort the summary buffer by article length.
9921 Argument REVERSE means reverse order."
9922   (interactive "P")
9923   (gnus-summary-sort 'chars reverse))
9924
9925 (defun gnus-summary-sort-by-original (&optional reverse)
9926   "Sort the summary buffer using the default sorting method.
9927 Argument REVERSE means reverse order."
9928   (interactive "P")
9929   (let* ((buffer-read-only)
9930          (gnus-summary-prepare-hook nil))
9931     ;; We do the sorting by regenerating the threads.
9932     (gnus-summary-prepare)
9933     ;; Hide subthreads if needed.
9934     (gnus-summary-maybe-hide-threads)))
9935
9936 (defun gnus-summary-sort (predicate reverse)
9937   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9938   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9939          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9940          (gnus-thread-sort-functions
9941           (if (not reverse)
9942               thread
9943             `(lambda (t1 t2)
9944                (,thread t2 t1))))
9945          (gnus-sort-gathered-threads-function
9946           gnus-thread-sort-functions)
9947          (gnus-article-sort-functions
9948           (if (not reverse)
9949               article
9950             `(lambda (t1 t2)
9951                (,article t2 t1))))
9952          (buffer-read-only)
9953          (gnus-summary-prepare-hook nil))
9954     ;; We do the sorting by regenerating the threads.
9955     (gnus-summary-prepare)
9956     ;; Hide subthreads if needed.
9957     (gnus-summary-maybe-hide-threads)))
9958
9959 ;; Summary saving commands.
9960
9961 (defun gnus-summary-save-article (&optional n not-saved)
9962   "Save the current article using the default saver function.
9963 If N is a positive number, save the N next articles.
9964 If N is a negative number, save the N previous articles.
9965 If N is nil and any articles have been marked with the process mark,
9966 save those articles instead.
9967 The variable `gnus-default-article-saver' specifies the saver function."
9968   (interactive "P")
9969   (let* ((articles (gnus-summary-work-articles n))
9970          (save-buffer (save-excursion
9971                         (nnheader-set-temp-buffer " *Gnus Save*")))
9972          (num (length articles))
9973          header file)
9974     (dolist (article articles)
9975       (setq header (gnus-summary-article-header article))
9976       (if (not (vectorp header))
9977           ;; This is a pseudo-article.
9978           (if (assq 'name header)
9979               (gnus-copy-file (cdr (assq 'name header)))
9980             (gnus-message 1 "Article %d is unsaveable" article))
9981         ;; This is a real article.
9982         (save-window-excursion
9983           (let ((gnus-display-mime-function nil)
9984                 (gnus-article-prepare-hook nil))
9985             (gnus-summary-select-article t nil nil article)))
9986         (save-excursion
9987           (set-buffer save-buffer)
9988           (erase-buffer)
9989           (insert-buffer-substring gnus-original-article-buffer))
9990         (setq file (gnus-article-save save-buffer file num))
9991         (gnus-summary-remove-process-mark article)
9992         (unless not-saved
9993           (gnus-summary-set-saved-mark article))))
9994     (gnus-kill-buffer save-buffer)
9995     (gnus-summary-position-point)
9996     (gnus-set-mode-line 'summary)
9997     n))
9998
9999 (defun gnus-summary-pipe-output (&optional arg)
10000   "Pipe the current article to a subprocess.
10001 If N is a positive number, pipe the N next articles.
10002 If N is a negative number, pipe the N previous articles.
10003 If N is nil and any articles have been marked with the process mark,
10004 pipe those articles instead."
10005   (interactive "P")
10006   (require 'gnus-art)
10007   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10008     (gnus-summary-save-article arg t))
10009   (let ((buffer (get-buffer "*Shell Command Output*")))
10010     (if (and buffer
10011              (with-current-buffer buffer (> (point-max) (point-min))))
10012         (gnus-configure-windows 'pipe))))
10013
10014 (defun gnus-summary-save-article-mail (&optional arg)
10015   "Append the current article to an mail file.
10016 If N is a positive number, save the N next articles.
10017 If N is a negative number, save the N previous articles.
10018 If N is nil and any articles have been marked with the process mark,
10019 save those articles instead."
10020   (interactive "P")
10021   (require 'gnus-art)
10022   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10023     (gnus-summary-save-article arg)))
10024
10025 (defun gnus-summary-save-article-rmail (&optional arg)
10026   "Append the current article to an rmail file.
10027 If N is a positive number, save the N next articles.
10028 If N is a negative number, save the N previous articles.
10029 If N is nil and any articles have been marked with the process mark,
10030 save those articles instead."
10031   (interactive "P")
10032   (require 'gnus-art)
10033   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10034     (gnus-summary-save-article arg)))
10035
10036 (defun gnus-summary-save-article-file (&optional arg)
10037   "Append the current article to a file.
10038 If N is a positive number, save the N next articles.
10039 If N is a negative number, save the N previous articles.
10040 If N is nil and any articles have been marked with the process mark,
10041 save those articles instead."
10042   (interactive "P")
10043   (require 'gnus-art)
10044   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10045     (gnus-summary-save-article arg)))
10046
10047 (defun gnus-summary-write-article-file (&optional arg)
10048   "Write the current article to a file, deleting the previous file.
10049 If N is a positive number, save the N next articles.
10050 If N is a negative number, save the N previous articles.
10051 If N is nil and any articles have been marked with the process mark,
10052 save those articles instead."
10053   (interactive "P")
10054   (require 'gnus-art)
10055   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10056     (gnus-summary-save-article arg)))
10057
10058 (defun gnus-summary-save-article-body-file (&optional arg)
10059   "Append the current article body to a file.
10060 If N is a positive number, save the N next articles.
10061 If N is a negative number, save the N previous articles.
10062 If N is nil and any articles have been marked with the process mark,
10063 save those articles instead."
10064   (interactive "P")
10065   (require 'gnus-art)
10066   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10067     (gnus-summary-save-article arg)))
10068
10069 (defun gnus-summary-muttprint (&optional arg)
10070   "Print the current article using Muttprint.
10071 If N is a positive number, save the N next articles.
10072 If N is a negative number, save the N previous articles.
10073 If N is nil and any articles have been marked with the process mark,
10074 save those articles instead."
10075   (interactive "P")
10076   (require 'gnus-art)
10077   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10078     (gnus-summary-save-article arg t)))
10079
10080 (defun gnus-summary-pipe-message (program)
10081   "Pipe the current article through PROGRAM."
10082   (interactive "sProgram: ")
10083   (gnus-summary-select-article)
10084   (let ((mail-header-separator ""))
10085     (gnus-eval-in-buffer-window gnus-article-buffer
10086       (save-restriction
10087         (widen)
10088         (let ((start (window-start))
10089               buffer-read-only)
10090           (message-pipe-buffer-body program)
10091           (set-window-start (get-buffer-window (current-buffer)) start))))))
10092
10093 (defun gnus-get-split-value (methods)
10094   "Return a value based on the split METHODS."
10095   (let (split-name method result match)
10096     (when methods
10097       (save-excursion
10098         (set-buffer gnus-original-article-buffer)
10099         (save-restriction
10100           (nnheader-narrow-to-headers)
10101           (while (and methods (not split-name))
10102             (goto-char (point-min))
10103             (setq method (pop methods))
10104             (setq match (car method))
10105             (when (cond
10106                    ((stringp match)
10107                     ;; Regular expression.
10108                     (ignore-errors
10109                       (re-search-forward match nil t)))
10110                    ((gnus-functionp match)
10111                     ;; Function.
10112                     (save-restriction
10113                       (widen)
10114                       (setq result (funcall match gnus-newsgroup-name))))
10115                    ((consp match)
10116                     ;; Form.
10117                     (save-restriction
10118                       (widen)
10119                       (setq result (eval match)))))
10120               (setq split-name (cdr method))
10121               (cond ((stringp result)
10122                      (push (expand-file-name
10123                             result gnus-article-save-directory)
10124                            split-name))
10125                     ((consp result)
10126                      (setq split-name (append result split-name)))))))))
10127     (nreverse split-name)))
10128
10129 (defun gnus-valid-move-group-p (group)
10130   (and (boundp group)
10131        (symbol-name group)
10132        (symbol-value group)
10133        (gnus-get-function (gnus-find-method-for-group
10134                            (symbol-name group)) 'request-accept-article t)))
10135
10136 (defun gnus-read-move-group-name (prompt default articles prefix)
10137   "Read a group name."
10138   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10139          (minibuffer-confirm-incomplete nil) ; XEmacs
10140          (prom
10141           (format "%s %s to:"
10142                   prompt
10143                   (if (> (length articles) 1)
10144                       (format "these %d articles" (length articles))
10145                     "this article")))
10146          (to-newsgroup
10147           (cond
10148            ((null split-name)
10149             (gnus-completing-read default prom
10150                                   gnus-active-hashtb
10151                                   'gnus-valid-move-group-p
10152                                   nil prefix
10153                                   'gnus-group-history))
10154            ((= 1 (length split-name))
10155             (gnus-completing-read (car split-name) prom
10156                                   gnus-active-hashtb
10157                                   'gnus-valid-move-group-p
10158                                   nil nil
10159                                   'gnus-group-history))
10160            (t
10161             (gnus-completing-read nil prom
10162                                   (mapcar (lambda (el) (list el))
10163                                           (nreverse split-name))
10164                                   nil nil nil
10165                                   'gnus-group-history))))
10166          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10167     (when to-newsgroup
10168       (if (or (string= to-newsgroup "")
10169               (string= to-newsgroup prefix))
10170           (setq to-newsgroup default))
10171       (unless to-newsgroup
10172         (error "No group name entered"))
10173       (or (gnus-active to-newsgroup)
10174           (gnus-activate-group to-newsgroup nil nil to-method)
10175           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10176                                      to-newsgroup))
10177               (or (and (gnus-request-create-group to-newsgroup to-method)
10178                        (gnus-activate-group
10179                         to-newsgroup nil nil to-method)
10180                        (gnus-subscribe-group to-newsgroup))
10181                   (error "Couldn't create group %s" to-newsgroup)))
10182           (error "No such group: %s" to-newsgroup)))
10183     to-newsgroup))
10184
10185 (defun gnus-summary-save-parts (type dir n &optional reverse)
10186   "Save parts matching TYPE to DIR.
10187 If REVERSE, save parts that do not match TYPE."
10188   (interactive
10189    (list (read-string "Save parts of type: "
10190                       (or (car gnus-summary-save-parts-type-history)
10191                           gnus-summary-save-parts-default-mime)
10192                       'gnus-summary-save-parts-type-history)
10193          (setq gnus-summary-save-parts-last-directory
10194                (read-file-name "Save to directory: "
10195                                gnus-summary-save-parts-last-directory
10196                                nil t))
10197          current-prefix-arg))
10198   (gnus-summary-iterate n
10199     (let ((gnus-display-mime-function nil)
10200           (gnus-inhibit-treatment t))
10201       (gnus-summary-select-article))
10202     (save-excursion
10203       (set-buffer gnus-article-buffer)
10204       (let ((handles (or gnus-article-mime-handles
10205                          (mm-dissect-buffer) (mm-uu-dissect))))
10206         (when handles
10207           (gnus-summary-save-parts-1 type dir handles reverse)
10208           (unless gnus-article-mime-handles ;; Don't destroy this case.
10209             (mm-destroy-parts handles)))))))
10210
10211 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10212   (if (stringp (car handle))
10213       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10214               (cdr handle))
10215     (when (if reverse
10216               (not (string-match type (mm-handle-media-type handle)))
10217             (string-match type (mm-handle-media-type handle)))
10218       (let ((file (expand-file-name
10219                    (file-name-nondirectory
10220                     (or
10221                      (mail-content-type-get
10222                       (mm-handle-disposition handle) 'filename)
10223                      (concat gnus-newsgroup-name
10224                              "." (number-to-string
10225                                   (cdr gnus-article-current)))))
10226                    dir)))
10227         (unless (file-exists-p file)
10228           (mm-save-part-to-file handle file))))))
10229
10230 ;; Summary extract commands
10231
10232 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10233   (let ((buffer-read-only nil)
10234         (article (gnus-summary-article-number))
10235         after-article b e)
10236     (unless (gnus-summary-goto-subject article)
10237       (error "No such article: %d" article))
10238     (gnus-summary-position-point)
10239     ;; If all commands are to be bunched up on one line, we collect
10240     ;; them here.
10241     (unless gnus-view-pseudos-separately
10242       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10243             files action)
10244         (while ps
10245           (setq action (cdr (assq 'action (car ps))))
10246           (setq files (list (cdr (assq 'name (car ps)))))
10247           (while (and ps (cdr ps)
10248                       (string= (or action "1")
10249                                (or (cdr (assq 'action (cadr ps))) "2")))
10250             (push (cdr (assq 'name (cadr ps))) files)
10251             (setcdr ps (cddr ps)))
10252           (when files
10253             (when (not (string-match "%s" action))
10254               (push " " files))
10255             (push " " files)
10256             (when (assq 'execute (car ps))
10257               (setcdr (assq 'execute (car ps))
10258                       (funcall (if (string-match "%s" action)
10259                                    'format 'concat)
10260                                action
10261                                (mapconcat
10262                                 (lambda (f)
10263                                   (if (equal f " ")
10264                                       f
10265                                     (mm-quote-arg f)))
10266                                 files " ")))))
10267           (setq ps (cdr ps)))))
10268     (if (and gnus-view-pseudos (not not-view))
10269         (while pslist
10270           (when (assq 'execute (car pslist))
10271             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10272                                   (eq gnus-view-pseudos 'not-confirm)))
10273           (setq pslist (cdr pslist)))
10274       (save-excursion
10275         (while pslist
10276           (setq after-article (or (cdr (assq 'article (car pslist)))
10277                                   (gnus-summary-article-number)))
10278           (gnus-summary-goto-subject after-article)
10279           (forward-line 1)
10280           (setq b (point))
10281           (insert "    " (file-name-nondirectory
10282                           (cdr (assq 'name (car pslist))))
10283                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10284           (setq e (point))
10285           (forward-line -1)             ; back to `b'
10286           (gnus-add-text-properties
10287            b (1- e) (list 'gnus-number gnus-reffed-article-number
10288                           gnus-mouse-face-prop gnus-mouse-face))
10289           (gnus-data-enter
10290            after-article gnus-reffed-article-number
10291            gnus-unread-mark b (car pslist) 0 (- e b))
10292           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10293           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10294           (setq pslist (cdr pslist)))))))
10295
10296 (defun gnus-pseudos< (p1 p2)
10297   (let ((c1 (cdr (assq 'action p1)))
10298         (c2 (cdr (assq 'action p2))))
10299     (and c1 c2 (string< c1 c2))))
10300
10301 (defun gnus-request-pseudo-article (props)
10302   (cond ((assq 'execute props)
10303          (gnus-execute-command (cdr (assq 'execute props)))))
10304   (let ((gnus-current-article (gnus-summary-article-number)))
10305     (gnus-run-hooks 'gnus-mark-article-hook)))
10306
10307 (defun gnus-execute-command (command &optional automatic)
10308   (save-excursion
10309     (gnus-article-setup-buffer)
10310     (set-buffer gnus-article-buffer)
10311     (setq buffer-read-only nil)
10312     (let ((command (if automatic command
10313                      (read-string "Command: " (cons command 0)))))
10314       (erase-buffer)
10315       (insert "$ " command "\n\n")
10316       (if gnus-view-pseudo-asynchronously
10317           (start-process "gnus-execute" (current-buffer) shell-file-name
10318                          shell-command-switch command)
10319         (call-process shell-file-name nil t nil
10320                       shell-command-switch command)))))
10321
10322 ;; Summary kill commands.
10323
10324 (defun gnus-summary-edit-global-kill (article)
10325   "Edit the \"global\" kill file."
10326   (interactive (list (gnus-summary-article-number)))
10327   (gnus-group-edit-global-kill article))
10328
10329 (defun gnus-summary-edit-local-kill ()
10330   "Edit a local kill file applied to the current newsgroup."
10331   (interactive)
10332   (setq gnus-current-headers (gnus-summary-article-header))
10333   (gnus-group-edit-local-kill
10334    (gnus-summary-article-number) gnus-newsgroup-name))
10335
10336 ;;; Header reading.
10337
10338 (defun gnus-read-header (id &optional header)
10339   "Read the headers of article ID and enter them into the Gnus system."
10340   (let ((group gnus-newsgroup-name)
10341         (gnus-override-method
10342          (or
10343           gnus-override-method
10344           (and (gnus-news-group-p gnus-newsgroup-name)
10345                (car (gnus-refer-article-methods)))))
10346         where)
10347     ;; First we check to see whether the header in question is already
10348     ;; fetched.
10349     (if (stringp id)
10350         ;; This is a Message-ID.
10351         (setq header (or header (gnus-id-to-header id)))
10352       ;; This is an article number.
10353       (setq header (or header (gnus-summary-article-header id))))
10354     (if (and header
10355              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10356         ;; We have found the header.
10357         header
10358       ;; If this is a sparse article, we have to nix out its
10359       ;; previous entry in the thread hashtb.
10360       (when (and header
10361                  (gnus-summary-article-sparse-p (mail-header-number header)))
10362         (let* ((parent (gnus-parent-id (mail-header-references header)))
10363                (thread (and parent (gnus-id-to-thread parent))))
10364           (when thread
10365             (delq (assq header thread) thread))))
10366       ;; We have to really fetch the header to this article.
10367       (save-excursion
10368         (set-buffer nntp-server-buffer)
10369         (when (setq where (gnus-request-head id group))
10370           (nnheader-fold-continuation-lines)
10371           (goto-char (point-max))
10372           (insert ".\n")
10373           (goto-char (point-min))
10374           (insert "211 ")
10375           (princ (cond
10376                   ((numberp id) id)
10377                   ((cdr where) (cdr where))
10378                   (header (mail-header-number header))
10379                   (t gnus-reffed-article-number))
10380                  (current-buffer))
10381           (insert " Article retrieved.\n"))
10382         (if (or (not where)
10383                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10384             ()                          ; Malformed head.
10385           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10386             (when (and (stringp id)
10387                        (not (string= (gnus-group-real-name group)
10388                                      (car where))))
10389               ;; If we fetched by Message-ID and the article came
10390               ;; from a different group, we fudge some bogus article
10391               ;; numbers for this article.
10392               (mail-header-set-number header gnus-reffed-article-number))
10393             (save-excursion
10394               (set-buffer gnus-summary-buffer)
10395               (decf gnus-reffed-article-number)
10396               (gnus-remove-header (mail-header-number header))
10397               (push header gnus-newsgroup-headers)
10398               (setq gnus-current-headers header)
10399               (push (mail-header-number header) gnus-newsgroup-limit)))
10400           header)))))
10401
10402 (defun gnus-remove-header (number)
10403   "Remove header NUMBER from `gnus-newsgroup-headers'."
10404   (if (and gnus-newsgroup-headers
10405            (= number (mail-header-number (car gnus-newsgroup-headers))))
10406       (pop gnus-newsgroup-headers)
10407     (let ((headers gnus-newsgroup-headers))
10408       (while (and (cdr headers)
10409                   (not (= number (mail-header-number (cadr headers)))))
10410         (pop headers))
10411       (when (cdr headers)
10412         (setcdr headers (cddr headers))))))
10413
10414 ;;;
10415 ;;; summary highlights
10416 ;;;
10417
10418 (defun gnus-highlight-selected-summary ()
10419   "Highlight selected article in summary buffer."
10420   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10421   (when gnus-summary-selected-face
10422     (save-excursion
10423       (let* ((beg (progn (beginning-of-line) (point)))
10424              (end (progn (end-of-line) (point)))
10425              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10426              (from (if (get-text-property beg gnus-mouse-face-prop)
10427                        beg
10428                      (or (next-single-property-change
10429                           beg gnus-mouse-face-prop nil end)
10430                          beg)))
10431              (to
10432               (if (= from end)
10433                   (- from 2)
10434                 (or (next-single-property-change
10435                      from gnus-mouse-face-prop nil end)
10436                     end))))
10437         ;; If no mouse-face prop on line we will have to = from = end,
10438         ;; so we highlight the entire line instead.
10439         (when (= (+ to 2) from)
10440           (setq from beg)
10441           (setq to end))
10442         (if gnus-newsgroup-selected-overlay
10443             ;; Move old overlay.
10444             (gnus-move-overlay
10445              gnus-newsgroup-selected-overlay from to (current-buffer))
10446           ;; Create new overlay.
10447           (gnus-overlay-put
10448            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10449            'face gnus-summary-selected-face))))))
10450
10451 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10452 (defun gnus-summary-highlight-line ()
10453   "Highlight current line according to `gnus-summary-highlight'."
10454   (let* ((list gnus-summary-highlight)
10455          (p (point))
10456          (end (progn (end-of-line) (point)))
10457          ;; now find out where the line starts and leave point there.
10458          (beg (progn (beginning-of-line) (point)))
10459          (article (gnus-summary-article-number))
10460          (score (or (cdr (assq (or article gnus-current-article)
10461                                gnus-newsgroup-scored))
10462                     gnus-summary-default-score 0))
10463          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10464          (inhibit-read-only t))
10465     ;; Eval the cars of the lists until we find a match.
10466     (let ((default gnus-summary-default-score)
10467           (default-high gnus-summary-default-high-score)
10468           (default-low gnus-summary-default-low-score))
10469       (while (and list
10470                   (not (eval (caar list))))
10471         (setq list (cdr list))))
10472     (let ((face (cdar list)))
10473       (unless (eq face (get-text-property beg 'face))
10474         (gnus-put-text-property-excluding-characters-with-faces
10475          beg end 'face
10476          (setq face (if (boundp face) (symbol-value face) face)))
10477         (when gnus-summary-highlight-line-function
10478           (funcall gnus-summary-highlight-line-function article face))))
10479     (goto-char p)))
10480
10481 (defun gnus-update-read-articles (group unread &optional compute)
10482   "Update the list of read articles in GROUP."
10483   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10484          (entry (gnus-gethash group gnus-newsrc-hashtb))
10485          (info (nth 2 entry))
10486          (prev 1)
10487          (unread (sort (copy-sequence unread) '<))
10488          read)
10489     (if (or (not info) (not active))
10490         ;; There is no info on this group if it was, in fact,
10491         ;; killed.  Gnus stores no information on killed groups, so
10492         ;; there's nothing to be done.
10493         ;; One could store the information somewhere temporarily,
10494         ;; perhaps...  Hmmm...
10495         ()
10496       ;; Remove any negative articles numbers.
10497       (while (and unread (< (car unread) 0))
10498         (setq unread (cdr unread)))
10499       ;; Remove any expired article numbers
10500       (while (and unread (< (car unread) (car active)))
10501         (setq unread (cdr unread)))
10502       ;; Compute the ranges of read articles by looking at the list of
10503       ;; unread articles.
10504       (while unread
10505         (when (/= (car unread) prev)
10506           (push (if (= prev (1- (car unread))) prev
10507                   (cons prev (1- (car unread))))
10508                 read))
10509         (setq prev (1+ (car unread)))
10510         (setq unread (cdr unread)))
10511       (when (<= prev (cdr active))
10512         (push (cons prev (cdr active)) read))
10513       (setq read (if (> (length read) 1) (nreverse read) read))
10514       (if compute
10515           read
10516         (save-excursion
10517           (let (setmarkundo)
10518             ;; Propagate the read marks to the backend.
10519             (when (gnus-check-backend-function 'request-set-mark group)
10520               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10521                     (add (gnus-remove-from-range read (gnus-info-read info))))
10522                 (when (or add del)
10523                   (unless (gnus-check-group group)
10524                     (error "Can't open server for %s" group))
10525                   (gnus-request-set-mark
10526                    group (delq nil (list (if add (list add 'add '(read)))
10527                                          (if del (list del 'del '(read))))))
10528                   (setq setmarkundo
10529                         `(gnus-request-set-mark
10530                           ,group
10531                           ',(delq nil (list
10532                                        (if del (list del 'add '(read)))
10533                                        (if add (list add 'del '(read))))))))))
10534             (set-buffer gnus-group-buffer)
10535             (gnus-undo-register
10536               `(progn
10537                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10538                  (gnus-info-set-read ',info ',(gnus-info-read info))
10539                  (gnus-get-unread-articles-in-group ',info
10540                                                     (gnus-active ,group))
10541                  (gnus-group-update-group ,group t)
10542                  ,setmarkundo))))
10543         ;; Enter this list into the group info.
10544         (gnus-info-set-read info read)
10545         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10546         (gnus-get-unread-articles-in-group info (gnus-active group))
10547         t))))
10548
10549 (defun gnus-offer-save-summaries ()
10550   "Offer to save all active summary buffers."
10551   (let (buffers)
10552     ;; Go through all buffers and find all summaries.
10553     (dolist (buffer (buffer-list))
10554       (when (and (setq buffer (buffer-name buffer))
10555                  (string-match "Summary" buffer)
10556                  (save-excursion
10557                    (set-buffer buffer)
10558                    ;; We check that this is, indeed, a summary buffer.
10559                    (and (eq major-mode 'gnus-summary-mode)
10560                         ;; Also make sure this isn't bogus.
10561                         gnus-newsgroup-prepared
10562                         ;; Also make sure that this isn't a
10563                         ;; dead summary buffer.
10564                         (not gnus-dead-summary-mode))))
10565         (push buffer buffers)))
10566     ;; Go through all these summary buffers and offer to save them.
10567     (when buffers
10568       (save-excursion
10569         (map-y-or-n-p
10570          "Update summary buffer %s? "
10571          (lambda (buf)
10572            (switch-to-buffer buf)
10573            (gnus-summary-exit))
10574          buffers)))))
10575
10576 (defun gnus-summary-setup-default-charset ()
10577   "Setup newsgroup default charset."
10578   (if (equal gnus-newsgroup-name "nndraft:drafts")
10579       (setq gnus-newsgroup-charset nil)
10580     (let* ((ignored-charsets
10581             (or gnus-newsgroup-ephemeral-ignored-charsets
10582                 (append
10583                  (and gnus-newsgroup-name
10584                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10585                  gnus-newsgroup-ignored-charsets))))
10586       (setq gnus-newsgroup-charset
10587             (or gnus-newsgroup-ephemeral-charset
10588                 (and gnus-newsgroup-name
10589                      (gnus-parameter-charset gnus-newsgroup-name))
10590                 gnus-default-charset))
10591       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10592            ignored-charsets))))
10593
10594 ;;;
10595 ;;; Mime Commands
10596 ;;;
10597
10598 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10599   "Display the current article buffer fully MIME-buttonized.
10600 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10601 treated as multipart/mixed."
10602   (interactive "P")
10603   (require 'gnus-art)
10604   (let ((gnus-unbuttonized-mime-types nil)
10605         (gnus-mime-display-multipart-as-mixed show-all-parts))
10606     (gnus-summary-show-article)))
10607
10608 (defun gnus-summary-repair-multipart (article)
10609   "Add a Content-Type header to a multipart article without one."
10610   (interactive (list (gnus-summary-article-number)))
10611   (gnus-with-article article
10612     (message-narrow-to-head)
10613     (message-remove-header "Mime-Version")
10614     (goto-char (point-max))
10615     (insert "Mime-Version: 1.0\n")
10616     (widen)
10617     (when (search-forward "\n--" nil t)
10618       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10619         (message-narrow-to-head)
10620         (message-remove-header "Content-Type")
10621         (goto-char (point-max))
10622         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10623                         separator))
10624         (widen))))
10625   (let (gnus-mark-article-hook)
10626     (gnus-summary-select-article t t nil article)))
10627
10628 (defun gnus-summary-toggle-display-buttonized ()
10629   "Toggle the buttonizing of the article buffer."
10630   (interactive)
10631   (require 'gnus-art)
10632   (if (setq gnus-inhibit-mime-unbuttonizing
10633             (not gnus-inhibit-mime-unbuttonizing))
10634       (let ((gnus-unbuttonized-mime-types nil))
10635         (gnus-summary-show-article))
10636     (gnus-summary-show-article)))
10637
10638 ;;;
10639 ;;; Generic summary marking commands
10640 ;;;
10641
10642 (defvar gnus-summary-marking-alist
10643   '((read gnus-del-mark "d")
10644     (unread gnus-unread-mark "u")
10645     (ticked gnus-ticked-mark "!")
10646     (dormant gnus-dormant-mark "?")
10647     (expirable gnus-expirable-mark "e"))
10648   "An alist of names/marks/keystrokes.")
10649
10650 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10651 (defvar gnus-summary-mark-map)
10652
10653 (defun gnus-summary-make-all-marking-commands ()
10654   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10655   (dolist (elem gnus-summary-marking-alist)
10656     (apply 'gnus-summary-make-marking-command elem)))
10657
10658 (defun gnus-summary-make-marking-command (name mark keystroke)
10659   (let ((map (make-sparse-keymap)))
10660     (define-key gnus-summary-generic-mark-map keystroke map)
10661     (dolist (lway `((next "next" next nil "n")
10662                     (next-unread "next unread" next t "N")
10663                     (prev "previous" prev nil "p")
10664                     (prev-unread "previous unread" prev t "P")
10665                     (nomove "" nil nil ,keystroke)))
10666       (let ((func (gnus-summary-make-marking-command-1
10667                    mark (car lway) lway name)))
10668         (setq func (eval func))
10669         (define-key map (nth 4 lway) func)))))
10670
10671 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10672   `(defun ,(intern
10673             (format "gnus-summary-put-mark-as-%s%s"
10674                     name (if (eq way 'nomove)
10675                              ""
10676                            (concat "-" (symbol-name way)))))
10677      (n)
10678      ,(format
10679        "Mark the current article as %s%s.
10680 If N, the prefix, then repeat N times.
10681 If N is negative, move in reverse order.
10682 The difference between N and the actual number of articles marked is
10683 returned."
10684        name (cadr lway))
10685      (interactive "p")
10686      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10687
10688 (defun gnus-summary-generic-mark (n mark move unread)
10689   "Mark N articles with MARK."
10690   (unless (eq major-mode 'gnus-summary-mode)
10691     (error "This command can only be used in the summary buffer"))
10692   (gnus-summary-show-thread)
10693   (let ((nummove
10694          (cond
10695           ((eq move 'next) 1)
10696           ((eq move 'prev) -1)
10697           (t 0))))
10698     (if (zerop nummove)
10699         (setq n 1)
10700       (when (< n 0)
10701         (setq n (abs n)
10702               nummove (* -1 nummove))))
10703     (while (and (> n 0)
10704                 (gnus-summary-mark-article nil mark)
10705                 (zerop (gnus-summary-next-subject nummove unread t)))
10706       (setq n (1- n)))
10707     (when (/= 0 n)
10708       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10709     (gnus-summary-recenter)
10710     (gnus-summary-position-point)
10711     (gnus-set-mode-line 'summary)
10712     n))
10713
10714 (defun gnus-summary-insert-articles (articles)
10715   (when (setq articles
10716               (gnus-set-difference articles
10717                                    (mapcar (lambda (h) (mail-header-number h))
10718                                            gnus-newsgroup-headers)))
10719     (setq gnus-newsgroup-headers
10720           (merge 'list
10721                  gnus-newsgroup-headers
10722                  (gnus-fetch-headers articles)
10723                  'gnus-article-sort-by-number))
10724     ;; Suppress duplicates?
10725     (when gnus-suppress-duplicates
10726       (gnus-dup-suppress-articles))
10727
10728     ;; We might want to build some more threads first.
10729     (when (and gnus-fetch-old-headers
10730                (eq gnus-headers-retrieved-by 'nov))
10731       (if (eq gnus-fetch-old-headers 'invisible)
10732           (gnus-build-all-threads)
10733         (gnus-build-old-threads)))
10734     ;; Let the Gnus agent mark articles as read.
10735     (when gnus-agent
10736       (gnus-agent-get-undownloaded-list))
10737     ;; Remove list identifiers from subject
10738     (when gnus-list-identifiers
10739       (gnus-summary-remove-list-identifiers))
10740     ;; First and last article in this newsgroup.
10741     (when gnus-newsgroup-headers
10742       (setq gnus-newsgroup-begin
10743             (mail-header-number (car gnus-newsgroup-headers))
10744             gnus-newsgroup-end
10745             (mail-header-number
10746              (gnus-last-element gnus-newsgroup-headers))))
10747     (when gnus-use-scoring
10748       (gnus-possibly-score-headers))))
10749
10750 (defun gnus-summary-insert-old-articles (&optional all)
10751   "Insert all old articles in this group.
10752 If ALL is non-nil, already read articles become readable.
10753 If ALL is a number, fetch this number of articles."
10754   (interactive "P")
10755   (prog1
10756       (let ((old (mapcar 'car gnus-newsgroup-data))
10757             (i (car gnus-newsgroup-active))
10758             older len)
10759         (while (<= i (cdr gnus-newsgroup-active))
10760           (or (memq i old) (push i older))
10761           (incf i))
10762         (setq len (length older))
10763         (cond
10764          ((null older) nil)
10765          ((numberp all)
10766           (if (< all len)
10767               (setq older (subseq older 0 all))))
10768          (all nil)
10769          (t
10770           (if (and (numberp gnus-large-newsgroup)
10771                    (> len gnus-large-newsgroup))
10772               (let ((input
10773                      (read-string
10774                       (format
10775                        "How many articles from %s (default %d): "
10776                        (gnus-limit-string
10777                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10778                        len))))
10779                 (unless (string-match "^[ \t]*$" input)
10780                   (setq all (string-to-number input))
10781                   (if (< all len)
10782                       (setq older (subseq older 0 all))))))))
10783         (if (not older)
10784             (message "No old news.")
10785           (gnus-summary-insert-articles older)
10786           (gnus-summary-limit (gnus-union older old))))
10787     (gnus-summary-position-point)))
10788
10789 (defun gnus-summary-insert-new-articles ()
10790   "Insert all new articles in this group."
10791   (interactive)
10792   (prog1
10793       (let ((old (mapcar 'car gnus-newsgroup-data))
10794             (old-active gnus-newsgroup-active)
10795             (nnmail-fetched-sources (list t))
10796             i new)
10797         (setq gnus-newsgroup-active
10798               (gnus-activate-group gnus-newsgroup-name 'scan))
10799         (setq i (1+ (cdr old-active)))
10800         (while (<= i (cdr gnus-newsgroup-active))
10801           (push i new)
10802           (incf i))
10803         (if (not new)
10804             (message "No gnus is bad news.")
10805           (setq new (nreverse new))
10806           (gnus-summary-insert-articles new)
10807           (setq gnus-newsgroup-unreads
10808                 (append gnus-newsgroup-unreads new))
10809           (gnus-summary-limit (gnus-union old new))))
10810     (gnus-summary-position-point)))
10811
10812 (gnus-summary-make-all-marking-commands)
10813
10814 (gnus-ems-redefine)
10815
10816 (provide 'gnus-sum)
10817
10818 (run-hooks 'gnus-sum-load-hook)
10819
10820 ;;; gnus-sum.el ends here