Importing Pterodactyl Gnus v0.54.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'gnus)
31 (require 'gnus-group)
32 (require 'gnus-spec)
33 (require 'gnus-range)
34 (require 'gnus-int)
35 (require 'gnus-undo)
36 (require 'gnus-util)
37 (require 'mm-decode)
38 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
39
40 (defcustom gnus-kill-summary-on-exit t
41   "*If non-nil, kill the summary buffer when you exit from it.
42 If nil, the summary will become a \"*Dead Summary*\" buffer, and
43 it will be killed sometime later."
44   :group 'gnus-summary-exit
45   :type 'boolean)
46
47 (defcustom gnus-fetch-old-headers nil
48   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
49 If an unread article in the group refers to an older, already read (or
50 just marked as read) article, the old article will not normally be
51 displayed in the Summary buffer.  If this variable is non-nil, Gnus
52 will attempt to grab the headers to the old articles, and thereby
53 build complete threads.  If it has the value `some', only enough
54 headers to connect otherwise loose threads will be displayed.  This
55 variable can also be a number.  In that case, no more than that number
56 of old headers will be fetched.  If it has the value `invisible', all
57 old headers will be fetched, but none will be displayed.
58
59 The server has to support NOV for any of this to work."
60   :group 'gnus-thread
61   :type '(choice (const :tag "off" nil)
62                  (const some)
63                  number
64                  (sexp :menu-tag "other" t)))
65
66 (defcustom gnus-refer-thread-limit 200
67   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
68 If t, fetch all the available old headers."
69   :group 'gnus-thread
70   :type '(choice number
71                  (sexp :menu-tag "other" t)))
72
73 (defcustom gnus-summary-make-false-root 'adopt
74   "*nil means that Gnus won't gather loose threads.
75 If the root of a thread has expired or been read in a previous
76 session, the information necessary to build a complete thread has been
77 lost.  Instead of having many small sub-threads from this original thread
78 scattered all over the summary buffer, Gnus can gather them.
79
80 If non-nil, Gnus will try to gather all loose sub-threads from an
81 original thread into one large thread.
82
83 If this variable is non-nil, it should be one of `none', `adopt',
84 `dummy' or `empty'.
85
86 If this variable is `none', Gnus will not make a false root, but just
87 present the sub-threads after another.
88 If this variable is `dummy', Gnus will create a dummy root that will
89 have all the sub-threads as children.
90 If this variable is `adopt', Gnus will make one of the \"children\"
91 the parent and mark all the step-children as such.
92 If this variable is `empty', the \"children\" are printed with empty
93 subject fields.  (Or rather, they will be printed with a string
94 given by the `gnus-summary-same-subject' variable.)"
95   :group 'gnus-thread
96   :type '(choice (const :tag "off" nil)
97                  (const none)
98                  (const dummy)
99                  (const adopt)
100                  (const empty)))
101
102 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
103   "*A regexp to match subjects to be excluded from loose thread gathering.
104 As loose thread gathering is done on subjects only, that means that
105 there can be many false gatherings performed.  By rooting out certain
106 common subjects, gathering might become saner."
107   :group 'gnus-thread
108   :type 'regexp)
109
110 (defcustom gnus-summary-gather-subject-limit nil
111   "*Maximum length of subject comparisons when gathering loose threads.
112 Use nil to compare full subjects.  Setting this variable to a low
113 number will help gather threads that have been corrupted by
114 newsreaders chopping off subject lines, but it might also mean that
115 unrelated articles that have subject that happen to begin with the
116 same few characters will be incorrectly gathered.
117
118 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
119 comparing subjects."
120   :group 'gnus-thread
121   :type '(choice (const :tag "off" nil)
122                  (const fuzzy)
123                  (sexp :menu-tag "on" t)))
124
125 (defcustom gnus-simplify-subject-functions nil
126   "List of functions taking a string argument that simplify subjects.
127 The functions are applied recursively.
128
129 Useful functions to put in this list include: `gnus-simplify-subject-re',
130 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
131   :group 'gnus-thread
132   :type '(repeat function))
133
134 (defcustom gnus-simplify-ignored-prefixes nil
135   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
136   :group 'gnus-thread
137   :type '(choice (const :tag "off" nil)
138                  regexp))
139
140 (defcustom gnus-build-sparse-threads nil
141   "*If non-nil, fill in the gaps in threads.
142 If `some', only fill in the gaps that are needed to tie loose threads
143 together.  If `more', fill in all leaf nodes that Gnus can find.  If
144 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
145   :group 'gnus-thread
146   :type '(choice (const :tag "off" nil)
147                  (const some)
148                  (const more)
149                  (sexp :menu-tag "all" t)))
150
151 (defcustom gnus-summary-thread-gathering-function
152   'gnus-gather-threads-by-subject
153   "*Function used for gathering loose threads.
154 There are two pre-defined functions: `gnus-gather-threads-by-subject',
155 which only takes Subjects into consideration; and
156 `gnus-gather-threads-by-references', which compared the References
157 headers of the articles to find matches."
158   :group 'gnus-thread
159   :type '(radio (function-item gnus-gather-threads-by-subject)
160                 (function-item gnus-gather-threads-by-references)
161                 (function :tag "other")))
162
163 (defcustom gnus-summary-same-subject ""
164   "*String indicating that the current article has the same subject as the previous.
165 This variable will only be used if the value of
166 `gnus-summary-make-false-root' is `empty'."
167   :group 'gnus-summary-format
168   :type 'string)
169
170 (defcustom gnus-summary-goto-unread t
171   "*If t, marking commands will go to the next unread article.
172 If `never', commands that usually go to the next unread article, will
173 go to the next article, whether it is read or not.
174 If nil, only the marking commands will go to the next (un)read article."
175   :group 'gnus-summary-marks
176   :link '(custom-manual "(gnus)Setting Marks")
177   :type '(choice (const :tag "off" nil)
178                  (const never)
179                  (sexp :menu-tag "on" t)))
180
181 (defcustom gnus-summary-default-score 0
182   "*Default article score level.
183 All scores generated by the score files will be added to this score.
184 If this variable is nil, scoring will be disabled."
185   :group 'gnus-score-default
186   :type '(choice (const :tag "disable")
187                  integer))
188
189 (defcustom gnus-summary-zcore-fuzz 0
190   "*Fuzziness factor for the zcore in the summary buffer.
191 Articles with scores closer than this to `gnus-summary-default-score'
192 will not be marked."
193   :group 'gnus-summary-format
194   :type 'integer)
195
196 (defcustom gnus-simplify-subject-fuzzy-regexp nil
197   "*Strings to be removed when doing fuzzy matches.
198 This can either be a regular expression or list of regular expressions
199 that will be removed from subject strings if fuzzy subject
200 simplification is selected."
201   :group 'gnus-thread
202   :type '(repeat regexp))
203
204 (defcustom gnus-show-threads t
205   "*If non-nil, display threads in summary mode."
206   :group 'gnus-thread
207   :type 'boolean)
208
209 (defcustom gnus-thread-hide-subtree nil
210   "*If non-nil, hide all threads initially.
211 If threads are hidden, you have to run the command
212 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
213 to expose hidden threads."
214   :group 'gnus-thread
215   :type 'boolean)
216
217 (defcustom gnus-thread-hide-killed t
218   "*If non-nil, hide killed threads automatically."
219   :group 'gnus-thread
220   :type 'boolean)
221
222 (defcustom gnus-thread-ignore-subject t
223   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
224 If nil, articles that have different subjects from their parents will
225 start separate threads."
226   :group 'gnus-thread
227   :type 'boolean)
228
229 (defcustom gnus-thread-operation-ignore-subject t
230   "*If non-nil, subjects will be ignored when doing thread commands.
231 This affects commands like `gnus-summary-kill-thread' and
232 `gnus-summary-lower-thread'.
233
234 If this variable is nil, articles in the same thread with different
235 subjects will not be included in the operation in question.  If this
236 variable is `fuzzy', only articles that have subjects that are fuzzily
237 equal will be included."
238   :group 'gnus-thread
239   :type '(choice (const :tag "off" nil)
240                  (const fuzzy)
241                  (sexp :tag "on" t)))
242
243 (defcustom gnus-thread-indent-level 4
244   "*Number that says how much each sub-thread should be indented."
245   :group 'gnus-thread
246   :type 'integer)
247
248 (defcustom gnus-auto-extend-newsgroup t
249   "*If non-nil, extend newsgroup forward and backward when requested."
250   :group 'gnus-summary-choose
251   :type 'boolean)
252
253 (defcustom gnus-auto-select-first t
254   "*If nil, don't select the first unread article when entering a group.
255 If this variable is `best', select the highest-scored unread article
256 in the group.  If t, select the first unread article.
257
258 This variable can also be a function to place point on a likely
259 subject line.  Useful values include `gnus-summary-first-unread-subject', 
260 `gnus-summary-first-unread-article' and 
261 `gnus-summary-best-unread-article'.
262
263 If you want to prevent automatic selection of the first unread article
264 in some newsgroups, set the variable to nil in
265 `gnus-select-group-hook'."
266   :group 'gnus-group-select
267   :type '(choice (const :tag "none" nil)
268                  (const best)
269                  (sexp :menu-tag "first" t)
270                  (function-item gnus-summary-first-unread-subject)
271                  (function-item gnus-summary-first-unread-article)
272                  (function-item gnus-summary-best-unread-article)))
273
274 (defcustom gnus-auto-select-next t
275   "*If non-nil, offer to go to the next group from the end of the previous.
276 If the value is t and the next newsgroup is empty, Gnus will exit
277 summary mode and go back to group mode.  If the value is neither nil
278 nor t, Gnus will select the following unread newsgroup.  In
279 particular, if the value is the symbol `quietly', the next unread
280 newsgroup will be selected without any confirmation, and if it is
281 `almost-quietly', the next group will be selected without any
282 confirmation if you are located on the last article in the group.
283 Finally, if this variable is `slightly-quietly', the `Z n' command
284 will go to the next group without confirmation."
285   :group 'gnus-summary-maneuvering
286   :type '(choice (const :tag "off" nil)
287                  (const quietly)
288                  (const almost-quietly)
289                  (const slightly-quietly)
290                  (sexp :menu-tag "on" t)))
291
292 (defcustom gnus-auto-select-same nil
293   "*If non-nil, select the next article with the same subject.
294 If there are no more articles with the same subject, go to
295 the first unread article."
296   :group 'gnus-summary-maneuvering
297   :type 'boolean)
298
299 (defcustom gnus-summary-check-current nil
300   "*If non-nil, consider the current article when moving.
301 The \"unread\" movement commands will stay on the same line if the
302 current article is unread."
303   :group 'gnus-summary-maneuvering
304   :type 'boolean)
305
306 (defcustom gnus-auto-center-summary t
307   "*If non-nil, always center the current summary buffer.
308 In particular, if `vertical' do only vertical recentering.  If non-nil
309 and non-`vertical', do both horizontal and vertical recentering."
310   :group 'gnus-summary-maneuvering
311   :type '(choice (const :tag "none" nil)
312                  (const vertical)
313                  (integer :tag "height")
314                  (sexp :menu-tag "both" t)))
315
316 (defcustom gnus-show-all-headers nil
317   "*If non-nil, don't hide any headers."
318   :group 'gnus-article-hiding
319   :group 'gnus-article-headers
320   :type 'boolean)
321
322 (defcustom gnus-summary-ignore-duplicates nil
323   "*If non-nil, ignore articles with identical Message-ID headers."
324   :group 'gnus-summary
325   :type 'boolean)
326
327 (defcustom gnus-single-article-buffer t
328   "*If non-nil, display all articles in the same buffer.
329 If nil, each group will get its own article buffer."
330   :group 'gnus-article-various
331   :type 'boolean)
332
333 (defcustom gnus-break-pages t
334   "*If non-nil, do page breaking on articles.
335 The page delimiter is specified by the `gnus-page-delimiter'
336 variable."
337   :group 'gnus-article-various
338   :type 'boolean)
339
340 (defcustom gnus-move-split-methods nil
341   "*Variable used to suggest where articles are to be moved to.
342 It uses the same syntax as the `gnus-split-methods' variable."
343   :group 'gnus-summary-mail
344   :type '(repeat (choice (list :value (fun) function)
345                          (cons :value ("" "") regexp (repeat string))
346                          (sexp :value nil))))
347
348 (defcustom gnus-unread-mark ? 
349   "*Mark used for unread articles."
350   :group 'gnus-summary-marks
351   :type 'character)
352
353 (defcustom gnus-ticked-mark ?!
354   "*Mark used for ticked articles."
355   :group 'gnus-summary-marks
356   :type 'character)
357
358 (defcustom gnus-dormant-mark ??
359   "*Mark used for dormant articles."
360   :group 'gnus-summary-marks
361   :type 'character)
362
363 (defcustom gnus-del-mark ?r
364   "*Mark used for del'd articles."
365   :group 'gnus-summary-marks
366   :type 'character)
367
368 (defcustom gnus-read-mark ?R
369   "*Mark used for read articles."
370   :group 'gnus-summary-marks
371   :type 'character)
372
373 (defcustom gnus-expirable-mark ?E
374   "*Mark used for expirable articles."
375   :group 'gnus-summary-marks
376   :type 'character)
377
378 (defcustom gnus-killed-mark ?K
379   "*Mark used for killed articles."
380   :group 'gnus-summary-marks
381   :type 'character)
382
383 (defcustom gnus-souped-mark ?F
384   "*Mark used for killed articles."
385   :group 'gnus-summary-marks
386   :type 'character)
387
388 (defcustom gnus-kill-file-mark ?X
389   "*Mark used for articles killed by kill files."
390   :group 'gnus-summary-marks
391   :type 'character)
392
393 (defcustom gnus-low-score-mark ?Y
394   "*Mark used for articles with a low score."
395   :group 'gnus-summary-marks
396   :type 'character)
397
398 (defcustom gnus-catchup-mark ?C
399   "*Mark used for articles that are caught up."
400   :group 'gnus-summary-marks
401   :type 'character)
402
403 (defcustom gnus-replied-mark ?A
404   "*Mark used for articles that have been replied to."
405   :group 'gnus-summary-marks
406   :type 'character)
407
408 (defcustom gnus-cached-mark ?*
409   "*Mark used for articles that are in the cache."
410   :group 'gnus-summary-marks
411   :type 'character)
412
413 (defcustom gnus-saved-mark ?S
414   "*Mark used for articles that have been saved to."
415   :group 'gnus-summary-marks
416   :type 'character)
417
418 (defcustom gnus-ancient-mark ?O
419   "*Mark used for ancient articles."
420   :group 'gnus-summary-marks
421   :type 'character)
422
423 (defcustom gnus-sparse-mark ?Q
424   "*Mark used for sparsely reffed articles."
425   :group 'gnus-summary-marks
426   :type 'character)
427
428 (defcustom gnus-canceled-mark ?G
429   "*Mark used for canceled articles."
430   :group 'gnus-summary-marks
431   :type 'character)
432
433 (defcustom gnus-duplicate-mark ?M
434   "*Mark used for duplicate articles."
435   :group 'gnus-summary-marks
436   :type 'character)
437
438 (defcustom gnus-undownloaded-mark ?@
439   "*Mark used for articles that weren't downloaded."
440   :group 'gnus-summary-marks
441   :type 'character)
442
443 (defcustom gnus-downloadable-mark ?%
444   "*Mark used for articles that are to be downloaded."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-unsendable-mark ?=
449   "*Mark used for articles that won't be sent."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-score-over-mark ?+
454   "*Score mark used for articles with high scores."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-score-below-mark ?-
459   "*Score mark used for articles with low scores."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-empty-thread-mark ? 
464   "*There is no thread under the article."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-not-empty-thread-mark ?=
469   "*There is a thread under the article."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-view-pseudo-asynchronously nil
474   "*If non-nil, Gnus will view pseudo-articles asynchronously."
475   :group 'gnus-extract-view
476   :type 'boolean)
477
478 (defcustom gnus-auto-expirable-marks
479   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
480         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
481         gnus-souped-mark gnus-duplicate-mark)
482   "*The list of marks converted into expiration if a group is auto-expirable."
483   :group 'gnus-summary
484   :type '(repeat character))
485
486 (defcustom gnus-inhibit-user-auto-expire t
487   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
488   :group 'gnus-summary
489   :type 'boolean)
490
491 (defcustom gnus-view-pseudos nil
492   "*If `automatic', pseudo-articles will be viewed automatically.
493 If `not-confirm', pseudos will be viewed automatically, and the user
494 will not be asked to confirm the command."
495   :group 'gnus-extract-view
496   :type '(choice (const :tag "off" nil)
497                  (const automatic)
498                  (const not-confirm)))
499
500 (defcustom gnus-view-pseudos-separately t
501   "*If non-nil, one pseudo-article will be created for each file to be viewed.
502 If nil, all files that use the same viewing command will be given as a
503 list of parameters to that command."
504   :group 'gnus-extract-view
505   :type 'boolean)
506
507 (defcustom gnus-insert-pseudo-articles t
508   "*If non-nil, insert pseudo-articles when decoding articles."
509   :group 'gnus-extract-view
510   :type 'boolean)
511
512 (defcustom gnus-summary-dummy-line-format
513   "  %(:                          :%) %S\n"
514   "*The format specification for the dummy roots in the summary buffer.
515 It works along the same lines as a normal formatting string,
516 with some simple extensions.
517
518 %S  The subject"
519   :group 'gnus-threading
520   :type 'string)
521
522 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
523   "*The format specification for the summary mode line.
524 It works along the same lines as a normal formatting string,
525 with some simple extensions:
526
527 %G  Group name
528 %p  Unprefixed group name
529 %A  Current article number
530 %z  Current article score
531 %V  Gnus version
532 %U  Number of unread articles in the group
533 %e  Number of unselected articles in the group
534 %Z  A string with unread/unselected article counts
535 %g  Shortish group name
536 %S  Subject of the current article
537 %u  User-defined spec
538 %s  Current score file name
539 %d  Number of dormant articles
540 %r  Number of articles that have been marked as read in this session
541 %E  Number of articles expunged by the score files"
542   :group 'gnus-summary-format
543   :type 'string)
544
545 (defcustom gnus-summary-mark-below 0
546   "*Mark all articles with a score below this variable as read.
547 This variable is local to each summary buffer and usually set by the
548 score file."
549   :group 'gnus-score-default
550   :type 'integer)
551
552 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
553   "*List of functions used for sorting articles in the summary buffer.
554 This variable is only used when not using a threaded display."
555   :group 'gnus-summary-sort
556   :type '(repeat (choice (function-item gnus-article-sort-by-number)
557                          (function-item gnus-article-sort-by-author)
558                          (function-item gnus-article-sort-by-subject)
559                          (function-item gnus-article-sort-by-date)
560                          (function-item gnus-article-sort-by-score)
561                          (function :tag "other"))))
562
563 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
564   "*List of functions used for sorting threads in the summary buffer.
565 By default, threads are sorted by article number.
566
567 Each function takes two threads and return non-nil if the first thread
568 should be sorted before the other.  If you use more than one function,
569 the primary sort function should be the last.  You should probably
570 always include `gnus-thread-sort-by-number' in the list of sorting
571 functions -- preferably first.
572
573 Ready-made functions include `gnus-thread-sort-by-number',
574 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
575 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
576 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
577   :group 'gnus-summary-sort
578   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
579                          (function-item gnus-thread-sort-by-author)
580                          (function-item gnus-thread-sort-by-subject)
581                          (function-item gnus-thread-sort-by-date)
582                          (function-item gnus-thread-sort-by-score)
583                          (function-item gnus-thread-sort-by-total-score)
584                          (function :tag "other"))))
585
586 (defcustom gnus-thread-score-function '+
587   "*Function used for calculating the total score of a thread.
588
589 The function is called with the scores of the article and each
590 subthread and should then return the score of the thread.
591
592 Some functions you can use are `+', `max', or `min'."
593   :group 'gnus-summary-sort
594   :type 'function)
595
596 (defcustom gnus-summary-expunge-below nil
597   "All articles that have a score less than this variable will be expunged.
598 This variable is local to the summary buffers."
599   :group 'gnus-score-default
600   :type '(choice (const :tag "off" nil)
601                  integer))
602
603 (defcustom gnus-thread-expunge-below nil
604   "All threads that have a total score less than this variable will be expunged.
605 See `gnus-thread-score-function' for en explanation of what a
606 \"thread score\" is.
607
608 This variable is local to the summary buffers."
609   :group 'gnus-treading
610   :group 'gnus-score-default
611   :type '(choice (const :tag "off" nil)
612                  integer))
613
614 (defcustom gnus-summary-mode-hook nil
615   "*A hook for Gnus summary mode.
616 This hook is run before any variables are set in the summary buffer."
617   :group 'gnus-summary-various
618   :type 'hook)
619
620 (defcustom gnus-summary-menu-hook nil
621   "*Hook run after the creation of the summary mode menu."
622   :group 'gnus-summary-visual
623   :type 'hook)
624
625 (defcustom gnus-summary-exit-hook nil
626   "*A hook called on exit from the summary buffer.
627 It will be called with point in the group buffer."
628   :group 'gnus-summary-exit
629   :type 'hook)
630
631 (defcustom gnus-summary-prepare-hook nil
632   "*A hook called after the summary buffer has been generated.
633 If you want to modify the summary buffer, you can use this hook."
634   :group 'gnus-summary-various
635   :type 'hook)
636
637 (defcustom gnus-summary-prepared-hook nil
638   "*A hook called as the last thing after the summary buffer has been generated."
639   :group 'gnus-summary-various
640   :type 'hook)
641
642 (defcustom gnus-summary-generate-hook nil
643   "*A hook run just before generating the summary buffer.
644 This hook is commonly used to customize threading variables and the
645 like."
646   :group 'gnus-summary-various
647   :type 'hook)
648
649 (defcustom gnus-select-group-hook nil
650   "*A hook called when a newsgroup is selected.
651
652 If you'd like to simplify subjects like the
653 `gnus-summary-next-same-subject' command does, you can use the
654 following hook:
655
656  (setq gnus-select-group-hook
657       (list
658         (lambda ()
659           (mapcar (lambda (header)
660                      (mail-header-set-subject
661                       header
662                       (gnus-simplify-subject
663                        (mail-header-subject header) 're-only)))
664                   gnus-newsgroup-headers))))"
665   :group 'gnus-group-select
666   :type 'hook)
667
668 (defcustom gnus-select-article-hook nil
669   "*A hook called when an article is selected."
670   :group 'gnus-summary-choose
671   :type 'hook)
672
673 (defcustom gnus-visual-mark-article-hook
674   (list 'gnus-highlight-selected-summary)
675   "*Hook run after selecting an article in the summary buffer.
676 It is meant to be used for highlighting the article in some way.  It
677 is not run if `gnus-visual' is nil."
678   :group 'gnus-summary-visual
679   :type 'hook)
680
681 (defcustom gnus-parse-headers-hook nil
682   "*A hook called before parsing the headers."
683   :group 'gnus-various
684   :type 'hook)
685
686 (defcustom gnus-exit-group-hook nil
687   "*A hook called when exiting (not quitting) summary mode."
688   :group 'gnus-various
689   :type 'hook)
690
691 (defcustom gnus-summary-update-hook
692   (list 'gnus-summary-highlight-line)
693   "*A hook called when a summary line is changed.
694 The hook will not be called if `gnus-visual' is nil.
695
696 The default function `gnus-summary-highlight-line' will
697 highlight the line according to the `gnus-summary-highlight'
698 variable."
699   :group 'gnus-summary-visual
700   :type 'hook)
701
702 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
703   "*A hook called when an article is selected for the first time.
704 The hook is intended to mark an article as read (or unread)
705 automatically when it is selected."
706   :group 'gnus-summary-choose
707   :type 'hook)
708
709 (defcustom gnus-group-no-more-groups-hook nil
710   "*A hook run when returning to group mode having no more (unread) groups."
711   :group 'gnus-group-select
712   :type 'hook)
713
714 (defcustom gnus-ps-print-hook nil
715   "*A hook run before ps-printing something from Gnus."
716   :group 'gnus-summary
717   :type 'hook)
718
719 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
720   "Face used for highlighting the current article in the summary buffer."
721   :group 'gnus-summary-visual
722   :type 'face)
723
724 (defcustom gnus-summary-highlight
725   '(((= mark gnus-canceled-mark)
726      . gnus-summary-cancelled-face)
727     ((and (> score default)
728           (or (= mark gnus-dormant-mark)
729               (= mark gnus-ticked-mark)))
730      . gnus-summary-high-ticked-face)
731     ((and (< score default)
732           (or (= mark gnus-dormant-mark)
733               (= mark gnus-ticked-mark)))
734      . gnus-summary-low-ticked-face)
735     ((or (= mark gnus-dormant-mark)
736          (= mark gnus-ticked-mark))
737      . gnus-summary-normal-ticked-face)
738     ((and (> score default) (= mark gnus-ancient-mark))
739      . gnus-summary-high-ancient-face)
740     ((and (< score default) (= mark gnus-ancient-mark))
741      . gnus-summary-low-ancient-face)
742     ((= mark gnus-ancient-mark)
743      . gnus-summary-normal-ancient-face)
744     ((and (> score default) (= mark gnus-unread-mark))
745      . gnus-summary-high-unread-face)
746     ((and (< score default) (= mark gnus-unread-mark))
747      . gnus-summary-low-unread-face)
748     ((= mark gnus-unread-mark)
749      . gnus-summary-normal-unread-face)
750     ((and (> score default) (memq mark (list gnus-downloadable-mark
751                                              gnus-undownloaded-mark)))
752      . gnus-summary-high-unread-face)
753     ((and (< score default) (memq mark (list gnus-downloadable-mark
754                                              gnus-undownloaded-mark)))
755      . gnus-summary-low-unread-face)
756     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
757      . gnus-summary-normal-unread-face)
758     ((> score default)
759      . gnus-summary-high-read-face)
760     ((< score default)
761      . gnus-summary-low-read-face)
762     (t
763      . gnus-summary-normal-read-face))
764   "*Controls the highlighting of summary buffer lines.
765
766 A list of (FORM . FACE) pairs.  When deciding how a a particular
767 summary line should be displayed, each form is evaluated.  The content
768 of the face field after the first true form is used.  You can change
769 how those summary lines are displayed, by editing the face field.
770
771 You can use the following variables in the FORM field.
772
773 score:   The articles score
774 default: The default article score.
775 below:   The score below which articles are automatically marked as read.
776 mark:    The articles mark."
777   :group 'gnus-summary-visual
778   :type '(repeat (cons (sexp :tag "Form" nil)
779                        face)))
780
781 (defcustom gnus-alter-header-function nil
782   "Function called to allow alteration of article header structures.
783 The function is called with one parameter, the article header vector,
784 which it may alter in any way.")
785
786 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
787   "Variable that says which function should be used to decode a string with encoded words.")
788
789 (defcustom gnus-extra-headers nil
790   "*Extra headers to parse."
791   :group 'gnus-summary
792   :type '(repeat symbol))
793
794 (defcustom gnus-ignored-from-addresses
795   (and user-mail-address (regexp-quote user-mail-address))
796   "*Regexp of From headers that may be suppressed in favor of To headers."
797   :group 'gnus-summary
798   :type 'regexp)
799
800 (defcustom gnus-newsgroup-default-charset-alist 
801   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" . cn-big5)
802     ("^cn\\>\\|\\<chinese\\>" . cn-gb-2312)
803     ("^fj\\>\\|^japan\\>" . iso-2022-jp-2)
804     ("^relcom\\>" . koi8-r))
805   "Alist of Regexps (to match group names) and default charsets to be applied."
806   :type '(repeat (cons (regexp :tag "Group")
807                        (symbol :tag "Charset")))
808   :group 'gnus)
809
810 (defcustom gnus-newsgroup-iso-8859-1-forced-regexp 
811   "^tw\\>\\|^hk\\>\\|^cn\\>\\|\\<chinese\\>"
812   "Regexp of newsgroup in which ISO-8859-1 is forced to other charset."
813   :type 'regexp
814   :group 'gnus)
815
816 ;;; Internal variables
817
818 (defvar gnus-article-mime-handles nil)
819 (defvar gnus-article-decoded-p nil)
820 (defvar gnus-scores-exclude-files nil)
821 (defvar gnus-page-broken nil)
822
823 (defvar gnus-original-article nil)
824 (defvar gnus-article-internal-prepare-hook nil)
825 (defvar gnus-newsgroup-process-stack nil)
826
827 (defvar gnus-thread-indent-array nil)
828 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
829
830 ;; Avoid highlighting in kill files.
831 (defvar gnus-summary-inhibit-highlight nil)
832 (defvar gnus-newsgroup-selected-overlay nil)
833 (defvar gnus-inhibit-limiting nil)
834 (defvar gnus-newsgroup-adaptive-score-file nil)
835 (defvar gnus-current-score-file nil)
836 (defvar gnus-current-move-group nil)
837 (defvar gnus-current-copy-group nil)
838 (defvar gnus-current-crosspost-group nil)
839
840 (defvar gnus-newsgroup-dependencies nil)
841 (defvar gnus-newsgroup-adaptive nil)
842 (defvar gnus-summary-display-article-function nil)
843 (defvar gnus-summary-highlight-line-function nil
844   "Function called after highlighting a summary line.")
845
846 (defvar gnus-summary-line-format-alist
847   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
848     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
849     (?s gnus-tmp-subject-or-nil ?s)
850     (?n gnus-tmp-name ?s)
851     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
852         ?s)
853     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
854             gnus-tmp-from) ?s)
855     (?F gnus-tmp-from ?s)
856     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
857     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
858     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
859     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
860     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
861     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
862     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
863     (?L gnus-tmp-lines ?d)
864     (?I gnus-tmp-indentation ?s)
865     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
866     (?R gnus-tmp-replied ?c)
867     (?\[ gnus-tmp-opening-bracket ?c)
868     (?\] gnus-tmp-closing-bracket ?c)
869     (?\> (make-string gnus-tmp-level ? ) ?s)
870     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
871     (?i gnus-tmp-score ?d)
872     (?z gnus-tmp-score-char ?c)
873     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
874     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
875     (?U gnus-tmp-unread ?c)
876     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
877     (?t (gnus-summary-number-of-articles-in-thread
878          (and (boundp 'thread) (car thread)) gnus-tmp-level)
879         ?d)
880     (?e (gnus-summary-number-of-articles-in-thread
881          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
882         ?c)
883     (?u gnus-tmp-user-defined ?s)
884     (?P (gnus-pick-line-number) ?d))
885   "An alist of format specifications that can appear in summary lines,
886 and what variables they correspond with, along with the type of the
887 variable (string, integer, character, etc).")
888
889 (defvar gnus-summary-dummy-line-format-alist
890   `((?S gnus-tmp-subject ?s)
891     (?N gnus-tmp-number ?d)
892     (?u gnus-tmp-user-defined ?s)))
893
894 (defvar gnus-summary-mode-line-format-alist
895   `((?G gnus-tmp-group-name ?s)
896     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
897     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
898     (?A gnus-tmp-article-number ?d)
899     (?Z gnus-tmp-unread-and-unselected ?s)
900     (?V gnus-version ?s)
901     (?U gnus-tmp-unread-and-unticked ?d)
902     (?S gnus-tmp-subject ?s)
903     (?e gnus-tmp-unselected ?d)
904     (?u gnus-tmp-user-defined ?s)
905     (?d (length gnus-newsgroup-dormant) ?d)
906     (?t (length gnus-newsgroup-marked) ?d)
907     (?r (length gnus-newsgroup-reads) ?d)
908     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
909     (?E gnus-newsgroup-expunged-tally ?d)
910     (?s (gnus-current-score-file-nondirectory) ?s)))
911
912 (defvar gnus-last-search-regexp nil
913   "Default regexp for article search command.")
914
915 (defvar gnus-last-shell-command nil
916   "Default shell command on article.")
917
918 (defvar gnus-newsgroup-begin nil)
919 (defvar gnus-newsgroup-end nil)
920 (defvar gnus-newsgroup-last-rmail nil)
921 (defvar gnus-newsgroup-last-mail nil)
922 (defvar gnus-newsgroup-last-folder nil)
923 (defvar gnus-newsgroup-last-file nil)
924 (defvar gnus-newsgroup-auto-expire nil)
925 (defvar gnus-newsgroup-active nil)
926
927 (defvar gnus-newsgroup-data nil)
928 (defvar gnus-newsgroup-data-reverse nil)
929 (defvar gnus-newsgroup-limit nil)
930 (defvar gnus-newsgroup-limits nil)
931
932 (defvar gnus-newsgroup-unreads nil
933   "List of unread articles in the current newsgroup.")
934
935 (defvar gnus-newsgroup-unselected nil
936   "List of unselected unread articles in the current newsgroup.")
937
938 (defvar gnus-newsgroup-reads nil
939   "Alist of read articles and article marks in the current newsgroup.")
940
941 (defvar gnus-newsgroup-expunged-tally nil)
942
943 (defvar gnus-newsgroup-marked nil
944   "List of ticked articles in the current newsgroup (a subset of unread art).")
945
946 (defvar gnus-newsgroup-killed nil
947   "List of ranges of articles that have been through the scoring process.")
948
949 (defvar gnus-newsgroup-cached nil
950   "List of articles that come from the article cache.")
951
952 (defvar gnus-newsgroup-saved nil
953   "List of articles that have been saved.")
954
955 (defvar gnus-newsgroup-kill-headers nil)
956
957 (defvar gnus-newsgroup-replied nil
958   "List of articles that have been replied to in the current newsgroup.")
959
960 (defvar gnus-newsgroup-expirable nil
961   "List of articles in the current newsgroup that can be expired.")
962
963 (defvar gnus-newsgroup-processable nil
964   "List of articles in the current newsgroup that can be processed.")
965
966 (defvar gnus-newsgroup-downloadable nil
967   "List of articles in the current newsgroup that can be processed.")
968
969 (defvar gnus-newsgroup-undownloaded nil
970   "List of articles in the current newsgroup that haven't been downloaded..")
971
972 (defvar gnus-newsgroup-unsendable nil
973   "List of articles in the current newsgroup that won't be sent.")
974
975 (defvar gnus-newsgroup-bookmarks nil
976   "List of articles in the current newsgroup that have bookmarks.")
977
978 (defvar gnus-newsgroup-dormant nil
979   "List of dormant articles in the current newsgroup.")
980
981 (defvar gnus-newsgroup-scored nil
982   "List of scored articles in the current newsgroup.")
983
984 (defvar gnus-newsgroup-headers nil
985   "List of article headers in the current newsgroup.")
986
987 (defvar gnus-newsgroup-threads nil)
988
989 (defvar gnus-newsgroup-prepared nil
990   "Whether the current group has been prepared properly.")
991
992 (defvar gnus-newsgroup-ancient nil
993   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
994
995 (defvar gnus-newsgroup-sparse nil)
996
997 (defvar gnus-current-article nil)
998 (defvar gnus-article-current nil)
999 (defvar gnus-current-headers nil)
1000 (defvar gnus-have-all-headers nil)
1001 (defvar gnus-last-article nil)
1002 (defvar gnus-newsgroup-history nil)
1003
1004 (defvar gnus-newsgroup-default-charset nil)
1005 (defvar gnus-newsgroup-iso-8859-1-forced nil)
1006
1007 (defconst gnus-summary-local-variables
1008   '(gnus-newsgroup-name
1009     gnus-newsgroup-begin gnus-newsgroup-end
1010     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1011     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1012     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1013     gnus-newsgroup-unselected gnus-newsgroup-marked
1014     gnus-newsgroup-reads gnus-newsgroup-saved
1015     gnus-newsgroup-replied gnus-newsgroup-expirable
1016     gnus-newsgroup-processable gnus-newsgroup-killed
1017     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1018     gnus-newsgroup-unsendable
1019     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1020     gnus-newsgroup-headers gnus-newsgroup-threads
1021     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1022     gnus-current-article gnus-current-headers gnus-have-all-headers
1023     gnus-last-article gnus-article-internal-prepare-hook
1024     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1025     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1026     gnus-thread-expunge-below
1027     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1028     (gnus-summary-mark-below . global)
1029     gnus-newsgroup-active gnus-scores-exclude-files
1030     gnus-newsgroup-history gnus-newsgroup-ancient
1031     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1032     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1033     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1034     (gnus-newsgroup-expunged-tally . 0)
1035     gnus-cache-removable-articles gnus-newsgroup-cached
1036     gnus-newsgroup-data gnus-newsgroup-data-reverse
1037     gnus-newsgroup-limit gnus-newsgroup-limits
1038     gnus-newsgroup-default-charset gnus-newsgroup-iso-8859-1-forced)
1039   "Variables that are buffer-local to the summary buffers.")
1040
1041 ;; Byte-compiler warning.
1042 (defvar gnus-article-mode-map)
1043
1044 ;; MIME stuff.
1045
1046 (defvar gnus-decode-encoded-word-methods
1047   '(mail-decode-encoded-word-string)
1048   "List of methods used to decode encoded words.
1049
1050 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
1051 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1052 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1053 whose names match REGEXP.
1054
1055 For example: 
1056 ((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1057  mail-decode-encoded-word-string 
1058  (\"chinese\" . rfc1843-decode-string))
1059 ")
1060
1061 (defvar gnus-decode-encoded-word-methods-cache nil)
1062
1063 (defun gnus-multi-decode-encoded-word-string (string)
1064   "Apply the functions from `gnus-encoded-word-methods' that match."
1065   (unless (and gnus-decode-encoded-word-methods-cache
1066                (eq gnus-newsgroup-name 
1067                    (car gnus-decode-encoded-word-methods-cache)))
1068     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1069     (mapc '(lambda (x) 
1070              (if (symbolp x)
1071                  (nconc gnus-decode-encoded-word-methods-cache (list x))
1072                (if (and gnus-newsgroup-name 
1073                         (string-match (car x) gnus-newsgroup-name))
1074                    (nconc gnus-decode-encoded-word-methods-cache 
1075                           (list (cdr x))))))
1076           gnus-decode-encoded-word-methods))
1077   (let ((xlist gnus-decode-encoded-word-methods-cache))
1078     (pop xlist)
1079     (while xlist
1080       (setq string (funcall (pop xlist) string))))
1081   string)
1082
1083 ;; Subject simplification.
1084
1085 (defun gnus-simplify-whitespace (str)
1086   "Remove excessive whitespace."
1087   (let ((mystr str))
1088     ;; Multiple spaces.
1089     (while (string-match "[ \t][ \t]+" mystr)
1090       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1091                           " "
1092                           (substring mystr (match-end 0)))))
1093     ;; Leading spaces.
1094     (when (string-match "^[ \t]+" mystr)
1095       (setq mystr (substring mystr (match-end 0))))
1096     ;; Trailing spaces.
1097     (when (string-match "[ \t]+$" mystr)
1098       (setq mystr (substring mystr 0 (match-beginning 0))))
1099     mystr))
1100
1101 (defsubst gnus-simplify-subject-re (subject)
1102   "Remove \"Re:\" from subject lines."
1103   (if (string-match "^[Rr][Ee]: *" subject)
1104       (substring subject (match-end 0))
1105     subject))
1106
1107 (defun gnus-simplify-subject (subject &optional re-only)
1108   "Remove `Re:' and words in parentheses.
1109 If RE-ONLY is non-nil, strip leading `Re:'s only."
1110   (let ((case-fold-search t))           ;Ignore case.
1111     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1112     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1113       (setq subject (substring subject (match-end 0))))
1114     ;; Remove uninteresting prefixes.
1115     (when (and (not re-only)
1116                gnus-simplify-ignored-prefixes
1117                (string-match gnus-simplify-ignored-prefixes subject))
1118       (setq subject (substring subject (match-end 0))))
1119     ;; Remove words in parentheses from end.
1120     (unless re-only
1121       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1122         (setq subject (substring subject 0 (match-beginning 0)))))
1123     ;; Return subject string.
1124     subject))
1125
1126 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1127 ;; all whitespace.
1128 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1129   (goto-char (point-min))
1130   (while (re-search-forward regexp nil t)
1131       (replace-match (or newtext ""))))
1132
1133 (defun gnus-simplify-buffer-fuzzy ()
1134   "Simplify string in the buffer fuzzily.
1135 The string in the accessible portion of the current buffer is simplified.
1136 It is assumed to be a single-line subject.
1137 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1138 matter is removed.  Additional things can be deleted by setting
1139 gnus-simplify-subject-fuzzy-regexp."
1140   (let ((case-fold-search t)
1141         (modified-tick))
1142     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1143
1144     (while (not (eq modified-tick (buffer-modified-tick)))
1145       (setq modified-tick (buffer-modified-tick))
1146       (cond
1147        ((listp gnus-simplify-subject-fuzzy-regexp)
1148         (mapcar 'gnus-simplify-buffer-fuzzy-step
1149                 gnus-simplify-subject-fuzzy-regexp))
1150        (gnus-simplify-subject-fuzzy-regexp
1151         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1152       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1153       (gnus-simplify-buffer-fuzzy-step
1154        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1155       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1156
1157     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1158     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1159     (gnus-simplify-buffer-fuzzy-step " $")
1160     (gnus-simplify-buffer-fuzzy-step "^ +")))
1161
1162 (defun gnus-simplify-subject-fuzzy (subject)
1163   "Simplify a subject string fuzzily.
1164 See `gnus-simplify-buffer-fuzzy' for details."
1165   (save-excursion
1166     (gnus-set-work-buffer)
1167     (let ((case-fold-search t))
1168       ;; Remove uninteresting prefixes.
1169       (when (and gnus-simplify-ignored-prefixes
1170                  (string-match gnus-simplify-ignored-prefixes subject))
1171         (setq subject (substring subject (match-end 0))))
1172       (insert subject)
1173       (inline (gnus-simplify-buffer-fuzzy))
1174       (buffer-string))))
1175
1176 (defsubst gnus-simplify-subject-fully (subject)
1177   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1178   (cond
1179    (gnus-simplify-subject-functions
1180     (gnus-map-function gnus-simplify-subject-functions subject))
1181    ((null gnus-summary-gather-subject-limit)
1182     (gnus-simplify-subject-re subject))
1183    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1184     (gnus-simplify-subject-fuzzy subject))
1185    ((numberp gnus-summary-gather-subject-limit)
1186     (gnus-limit-string (gnus-simplify-subject-re subject)
1187                        gnus-summary-gather-subject-limit))
1188    (t
1189     subject)))
1190
1191 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1192   "Check whether two subjects are equal.
1193 If optional argument simple-first is t, first argument is already
1194 simplified."
1195   (cond
1196    ((null simple-first)
1197     (equal (gnus-simplify-subject-fully s1)
1198            (gnus-simplify-subject-fully s2)))
1199    (t
1200     (equal s1
1201            (gnus-simplify-subject-fully s2)))))
1202
1203 (defun gnus-summary-bubble-group ()
1204   "Increase the score of the current group.
1205 This is a handy function to add to `gnus-summary-exit-hook' to
1206 increase the score of each group you read."
1207   (gnus-group-add-score gnus-newsgroup-name))
1208
1209 \f
1210 ;;;
1211 ;;; Gnus summary mode
1212 ;;;
1213
1214 (put 'gnus-summary-mode 'mode-class 'special)
1215
1216 (when t
1217   ;; Non-orthogonal keys
1218
1219   (gnus-define-keys gnus-summary-mode-map
1220     " " gnus-summary-next-page
1221     "\177" gnus-summary-prev-page
1222     [delete] gnus-summary-prev-page
1223     [backspace] gnus-summary-prev-page
1224     "\r" gnus-summary-scroll-up
1225     "\M-\r" gnus-summary-scroll-down
1226     "n" gnus-summary-next-unread-article
1227     "p" gnus-summary-prev-unread-article
1228     "N" gnus-summary-next-article
1229     "P" gnus-summary-prev-article
1230     "\M-\C-n" gnus-summary-next-same-subject
1231     "\M-\C-p" gnus-summary-prev-same-subject
1232     "\M-n" gnus-summary-next-unread-subject
1233     "\M-p" gnus-summary-prev-unread-subject
1234     "." gnus-summary-first-unread-article
1235     "," gnus-summary-best-unread-article
1236     "\M-s" gnus-summary-search-article-forward
1237     "\M-r" gnus-summary-search-article-backward
1238     "<" gnus-summary-beginning-of-article
1239     ">" gnus-summary-end-of-article
1240     "j" gnus-summary-goto-article
1241     "^" gnus-summary-refer-parent-article
1242     "\M-^" gnus-summary-refer-article
1243     "u" gnus-summary-tick-article-forward
1244     "!" gnus-summary-tick-article-forward
1245     "U" gnus-summary-tick-article-backward
1246     "d" gnus-summary-mark-as-read-forward
1247     "D" gnus-summary-mark-as-read-backward
1248     "E" gnus-summary-mark-as-expirable
1249     "\M-u" gnus-summary-clear-mark-forward
1250     "\M-U" gnus-summary-clear-mark-backward
1251     "k" gnus-summary-kill-same-subject-and-select
1252     "\C-k" gnus-summary-kill-same-subject
1253     "\M-\C-k" gnus-summary-kill-thread
1254     "\M-\C-l" gnus-summary-lower-thread
1255     "e" gnus-summary-edit-article
1256     "#" gnus-summary-mark-as-processable
1257     "\M-#" gnus-summary-unmark-as-processable
1258     "\M-\C-t" gnus-summary-toggle-threads
1259     "\M-\C-s" gnus-summary-show-thread
1260     "\M-\C-h" gnus-summary-hide-thread
1261     "\M-\C-f" gnus-summary-next-thread
1262     "\M-\C-b" gnus-summary-prev-thread
1263     "\M-\C-u" gnus-summary-up-thread
1264     "\M-\C-d" gnus-summary-down-thread
1265     "&" gnus-summary-execute-command
1266     "c" gnus-summary-catchup-and-exit
1267     "\C-w" gnus-summary-mark-region-as-read
1268     "\C-t" gnus-summary-toggle-truncation
1269     "?" gnus-summary-mark-as-dormant
1270     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1271     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1272     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1273     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1274     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1275     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1276     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1277     "=" gnus-summary-expand-window
1278     "\C-x\C-s" gnus-summary-reselect-current-group
1279     "\M-g" gnus-summary-rescan-group
1280     "w" gnus-summary-stop-page-breaking
1281     "\C-c\C-r" gnus-summary-caesar-message
1282     "f" gnus-summary-followup
1283     "F" gnus-summary-followup-with-original
1284     "C" gnus-summary-cancel-article
1285     "r" gnus-summary-reply
1286     "R" gnus-summary-reply-with-original
1287     "\C-c\C-f" gnus-summary-mail-forward
1288     "o" gnus-summary-save-article
1289     "\C-o" gnus-summary-save-article-mail
1290     "|" gnus-summary-pipe-output
1291     "\M-k" gnus-summary-edit-local-kill
1292     "\M-K" gnus-summary-edit-global-kill
1293     ;; "V" gnus-version
1294     "\C-c\C-d" gnus-summary-describe-group
1295     "q" gnus-summary-exit
1296     "Q" gnus-summary-exit-no-update
1297     "\C-c\C-i" gnus-info-find-node
1298     gnus-mouse-2 gnus-mouse-pick-article
1299     "m" gnus-summary-mail-other-window
1300     "a" gnus-summary-post-news
1301     "x" gnus-summary-limit-to-unread
1302     "s" gnus-summary-isearch-article
1303     "t" gnus-article-hide-headers
1304     "g" gnus-summary-show-article
1305     "l" gnus-summary-goto-last-article
1306     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1307     "\C-d" gnus-summary-enter-digest-group
1308     "\M-\C-d" gnus-summary-read-document
1309     "\M-\C-e" gnus-summary-edit-parameters
1310     "\M-\C-g" gnus-summary-customize-parameters
1311     "\C-c\C-b" gnus-bug
1312     "*" gnus-cache-enter-article
1313     "\M-*" gnus-cache-remove-article
1314     "\M-&" gnus-summary-universal-argument
1315     "\C-l" gnus-recenter
1316     "I" gnus-summary-increase-score
1317     "L" gnus-summary-lower-score
1318     "\M-i" gnus-symbolic-argument
1319     "h" gnus-summary-select-article-buffer
1320     "b" gnus-article-view-part
1321     
1322     "V" gnus-summary-score-map
1323     "X" gnus-uu-extract-map
1324     "S" gnus-summary-send-map)
1325
1326   ;; Sort of orthogonal keymap
1327   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1328     "t" gnus-summary-tick-article-forward
1329     "!" gnus-summary-tick-article-forward
1330     "d" gnus-summary-mark-as-read-forward
1331     "r" gnus-summary-mark-as-read-forward
1332     "c" gnus-summary-clear-mark-forward
1333     " " gnus-summary-clear-mark-forward
1334     "e" gnus-summary-mark-as-expirable
1335     "x" gnus-summary-mark-as-expirable
1336     "?" gnus-summary-mark-as-dormant
1337     "b" gnus-summary-set-bookmark
1338     "B" gnus-summary-remove-bookmark
1339     "#" gnus-summary-mark-as-processable
1340     "\M-#" gnus-summary-unmark-as-processable
1341     "S" gnus-summary-limit-include-expunged
1342     "C" gnus-summary-catchup
1343     "H" gnus-summary-catchup-to-here
1344     "\C-c" gnus-summary-catchup-all
1345     "k" gnus-summary-kill-same-subject-and-select
1346     "K" gnus-summary-kill-same-subject
1347     "P" gnus-uu-mark-map)
1348
1349   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1350     "c" gnus-summary-clear-above
1351     "u" gnus-summary-tick-above
1352     "m" gnus-summary-mark-above
1353     "k" gnus-summary-kill-below)
1354
1355   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1356     "/" gnus-summary-limit-to-subject
1357     "n" gnus-summary-limit-to-articles
1358     "w" gnus-summary-pop-limit
1359     "s" gnus-summary-limit-to-subject
1360     "a" gnus-summary-limit-to-author
1361     "u" gnus-summary-limit-to-unread
1362     "m" gnus-summary-limit-to-marks
1363     "v" gnus-summary-limit-to-score
1364     "*" gnus-summary-limit-include-cached
1365     "D" gnus-summary-limit-include-dormant
1366     "T" gnus-summary-limit-include-thread
1367     "d" gnus-summary-limit-exclude-dormant
1368     "t" gnus-summary-limit-to-age
1369     "E" gnus-summary-limit-include-expunged
1370     "c" gnus-summary-limit-exclude-childless-dormant
1371     "C" gnus-summary-limit-mark-excluded-as-read)
1372
1373   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1374     "n" gnus-summary-next-unread-article
1375     "p" gnus-summary-prev-unread-article
1376     "N" gnus-summary-next-article
1377     "P" gnus-summary-prev-article
1378     "\C-n" gnus-summary-next-same-subject
1379     "\C-p" gnus-summary-prev-same-subject
1380     "\M-n" gnus-summary-next-unread-subject
1381     "\M-p" gnus-summary-prev-unread-subject
1382     "f" gnus-summary-first-unread-article
1383     "b" gnus-summary-best-unread-article
1384     "j" gnus-summary-goto-article
1385     "g" gnus-summary-goto-subject
1386     "l" gnus-summary-goto-last-article
1387     "o" gnus-summary-pop-article)
1388
1389   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1390     "k" gnus-summary-kill-thread
1391     "l" gnus-summary-lower-thread
1392     "i" gnus-summary-raise-thread
1393     "T" gnus-summary-toggle-threads
1394     "t" gnus-summary-rethread-current
1395     "^" gnus-summary-reparent-thread
1396     "s" gnus-summary-show-thread
1397     "S" gnus-summary-show-all-threads
1398     "h" gnus-summary-hide-thread
1399     "H" gnus-summary-hide-all-threads
1400     "n" gnus-summary-next-thread
1401     "p" gnus-summary-prev-thread
1402     "u" gnus-summary-up-thread
1403     "o" gnus-summary-top-thread
1404     "d" gnus-summary-down-thread
1405     "#" gnus-uu-mark-thread
1406     "\M-#" gnus-uu-unmark-thread)
1407
1408   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1409     "g" gnus-summary-prepare
1410     "c" gnus-summary-insert-cached-articles)
1411
1412   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1413     "c" gnus-summary-catchup-and-exit
1414     "C" gnus-summary-catchup-all-and-exit
1415     "E" gnus-summary-exit-no-update
1416     "Q" gnus-summary-exit
1417     "Z" gnus-summary-exit
1418     "n" gnus-summary-catchup-and-goto-next-group
1419     "R" gnus-summary-reselect-current-group
1420     "G" gnus-summary-rescan-group
1421     "N" gnus-summary-next-group
1422     "s" gnus-summary-save-newsrc
1423     "P" gnus-summary-prev-group)
1424
1425   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1426     " " gnus-summary-next-page
1427     "n" gnus-summary-next-page
1428     "\177" gnus-summary-prev-page
1429     [delete] gnus-summary-prev-page
1430     "p" gnus-summary-prev-page
1431     "\r" gnus-summary-scroll-up
1432     "\M-\r" gnus-summary-scroll-down
1433     "<" gnus-summary-beginning-of-article
1434     ">" gnus-summary-end-of-article
1435     "b" gnus-summary-beginning-of-article
1436     "e" gnus-summary-end-of-article
1437     "^" gnus-summary-refer-parent-article
1438     "r" gnus-summary-refer-parent-article
1439     "R" gnus-summary-refer-references
1440     "T" gnus-summary-refer-thread
1441     "g" gnus-summary-show-article
1442     "s" gnus-summary-isearch-article
1443     "P" gnus-summary-print-article)
1444
1445   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1446     "b" gnus-article-add-buttons
1447     "B" gnus-article-add-buttons-to-head
1448     "o" gnus-article-treat-overstrike
1449     "e" gnus-article-emphasize
1450     "w" gnus-article-fill-cited-article
1451     "c" gnus-article-remove-cr
1452     "q" gnus-article-de-quoted-unreadable
1453     "f" gnus-article-display-x-face
1454     "l" gnus-summary-stop-page-breaking
1455     "r" gnus-summary-caesar-message
1456     "t" gnus-article-hide-headers
1457     "v" gnus-summary-verbose-headers
1458     "h" gnus-article-treat-html
1459     "d" gnus-article-treat-dumbquotes)
1460
1461   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1462     "a" gnus-article-hide
1463     "h" gnus-article-hide-headers
1464     "b" gnus-article-hide-boring-headers
1465     "s" gnus-article-hide-signature
1466     "c" gnus-article-hide-citation
1467     "C" gnus-article-hide-citation-in-followups
1468     "p" gnus-article-hide-pgp
1469     "P" gnus-article-hide-pem
1470     "\C-c" gnus-article-hide-citation-maybe)
1471
1472   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1473     "a" gnus-article-highlight
1474     "h" gnus-article-highlight-headers
1475     "c" gnus-article-highlight-citation
1476     "s" gnus-article-highlight-signature)
1477
1478   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1479     "w" gnus-article-decode-mime-words
1480     "c" gnus-article-decode-charset
1481     "v" gnus-mime-view-all-parts
1482     "b" gnus-article-view-part)
1483
1484   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1485     "z" gnus-article-date-ut
1486     "u" gnus-article-date-ut
1487     "l" gnus-article-date-local
1488     "e" gnus-article-date-lapsed
1489     "o" gnus-article-date-original
1490     "i" gnus-article-date-iso8601
1491     "s" gnus-article-date-user)
1492
1493   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1494     "t" gnus-article-remove-trailing-blank-lines
1495     "l" gnus-article-strip-leading-blank-lines
1496     "m" gnus-article-strip-multiple-blank-lines
1497     "a" gnus-article-strip-blank-lines
1498     "A" gnus-article-strip-all-blank-lines
1499     "s" gnus-article-strip-leading-space)
1500
1501   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1502     "v" gnus-version
1503     "f" gnus-summary-fetch-faq
1504     "d" gnus-summary-describe-group
1505     "h" gnus-summary-describe-briefly
1506     "i" gnus-info-find-node)
1507
1508   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1509     "e" gnus-summary-expire-articles
1510     "\M-\C-e" gnus-summary-expire-articles-now
1511     "\177" gnus-summary-delete-article
1512     [delete] gnus-summary-delete-article
1513     "m" gnus-summary-move-article
1514     "r" gnus-summary-respool-article
1515     "w" gnus-summary-edit-article
1516     "c" gnus-summary-copy-article
1517     "B" gnus-summary-crosspost-article
1518     "q" gnus-summary-respool-query
1519     "t" gnus-summary-respool-trace
1520     "i" gnus-summary-import-article
1521     "p" gnus-summary-article-posted-p)
1522
1523   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1524     "o" gnus-summary-save-article
1525     "m" gnus-summary-save-article-mail
1526     "F" gnus-summary-write-article-file
1527     "r" gnus-summary-save-article-rmail
1528     "f" gnus-summary-save-article-file
1529     "b" gnus-summary-save-article-body-file
1530     "h" gnus-summary-save-article-folder
1531     "v" gnus-summary-save-article-vm
1532     "p" gnus-summary-pipe-output
1533     "s" gnus-soup-add-article)
1534
1535   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1536     "b" gnus-summary-display-buttonized
1537     "v" gnus-article-view-part
1538     "o" gnus-article-save-part
1539     "c" gnus-article-copy-part
1540     "e" gnus-article-externalize-part
1541     "|" gnus-article-pipe-part)
1542   )
1543
1544 (defun gnus-summary-make-menu-bar ()
1545   (gnus-turn-off-edit-menu 'summary)
1546
1547   (unless (boundp 'gnus-summary-misc-menu)
1548
1549     (easy-menu-define
1550      gnus-summary-kill-menu gnus-summary-mode-map ""
1551      (cons
1552       "Score"
1553       (nconc
1554        (list
1555         ["Enter score..." gnus-summary-score-entry t]
1556         ["Customize" gnus-score-customize t])
1557        (gnus-make-score-map 'increase)
1558        (gnus-make-score-map 'lower)
1559        '(("Mark"
1560           ["Kill below" gnus-summary-kill-below t]
1561           ["Mark above" gnus-summary-mark-above t]
1562           ["Tick above" gnus-summary-tick-above t]
1563           ["Clear above" gnus-summary-clear-above t])
1564          ["Current score" gnus-summary-current-score t]
1565          ["Set score" gnus-summary-set-score t]
1566          ["Switch current score file..." gnus-score-change-score-file t]
1567          ["Set mark below..." gnus-score-set-mark-below t]
1568          ["Set expunge below..." gnus-score-set-expunge-below t]
1569          ["Edit current score file" gnus-score-edit-current-scores t]
1570          ["Edit score file" gnus-score-edit-file t]
1571          ["Trace score" gnus-score-find-trace t]
1572          ["Find words" gnus-score-find-favourite-words t]
1573          ["Rescore buffer" gnus-summary-rescore t]
1574          ["Increase score..." gnus-summary-increase-score t]
1575          ["Lower score..." gnus-summary-lower-score t]))))
1576
1577     ;; Define both the Article menu in the summary buffer and the equivalent
1578     ;; Commands menu in the article buffer here for consistency.
1579     (let ((innards
1580            '(("Hide"
1581               ["All" gnus-article-hide t]
1582               ["Headers" gnus-article-hide-headers t]
1583               ["Signature" gnus-article-hide-signature t]
1584               ["Citation" gnus-article-hide-citation t]
1585               ["PGP" gnus-article-hide-pgp t]
1586               ["Boring headers" gnus-article-hide-boring-headers t])
1587              ("Highlight"
1588               ["All" gnus-article-highlight t]
1589               ["Headers" gnus-article-highlight-headers t]
1590               ["Signature" gnus-article-highlight-signature t]
1591               ["Citation" gnus-article-highlight-citation t])
1592              ("MIME"
1593               ["Words" gnus-article-decode-mime-words t]
1594               ["Charset" gnus-article-decode-charset t]
1595               ["QP" gnus-article-de-quoted-unreadable t]
1596               ["View all" gnus-mime-view-all-parts t])
1597              ("Date"
1598               ["Local" gnus-article-date-local t]
1599               ["ISO8601" gnus-article-date-iso8601 t]
1600               ["UT" gnus-article-date-ut t]
1601               ["Original" gnus-article-date-original t]
1602               ["Lapsed" gnus-article-date-lapsed t]
1603               ["User-defined" gnus-article-date-user t])
1604              ("Washing"
1605               ("Remove Blanks"
1606                ["Leading" gnus-article-strip-leading-blank-lines t]
1607                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1608                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1609                ["All of the above" gnus-article-strip-blank-lines t]
1610                ["All" gnus-article-strip-all-blank-lines t]
1611                ["Leading space" gnus-article-strip-leading-space t])
1612               ["Overstrike" gnus-article-treat-overstrike t]
1613               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1614               ["Emphasis" gnus-article-emphasize t]
1615               ["Word wrap" gnus-article-fill-cited-article t]
1616               ["CR" gnus-article-remove-cr t]
1617               ["Show X-Face" gnus-article-display-x-face t]
1618               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1619               ["UnHTMLize" gnus-article-treat-html t]
1620               ["Rot 13" gnus-summary-caesar-message t]
1621               ["Unix pipe" gnus-summary-pipe-message t]
1622               ["Add buttons" gnus-article-add-buttons t]
1623               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1624               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1625               ["Verbose header" gnus-summary-verbose-headers t]
1626               ["Toggle header" gnus-summary-toggle-header t])
1627              ("Output"
1628               ["Save in default format" gnus-summary-save-article t]
1629               ["Save in file" gnus-summary-save-article-file t]
1630               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1631               ["Save in MH folder" gnus-summary-save-article-folder t]
1632               ["Save in VM folder" gnus-summary-save-article-vm t]
1633               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1634               ["Save body in file" gnus-summary-save-article-body-file t]
1635               ["Pipe through a filter" gnus-summary-pipe-output t]
1636               ["Add to SOUP packet" gnus-soup-add-article t]
1637               ["Print" gnus-summary-print-article t])
1638              ("Backend"
1639               ["Respool article..." gnus-summary-respool-article t]
1640               ["Move article..." gnus-summary-move-article
1641                (gnus-check-backend-function
1642                 'request-move-article gnus-newsgroup-name)]
1643               ["Copy article..." gnus-summary-copy-article t]
1644               ["Crosspost article..." gnus-summary-crosspost-article
1645                (gnus-check-backend-function
1646                 'request-replace-article gnus-newsgroup-name)]
1647               ["Import file..." gnus-summary-import-article t]
1648               ["Check if posted" gnus-summary-article-posted-p t]
1649               ["Edit article" gnus-summary-edit-article
1650                (not (gnus-group-read-only-p))]
1651               ["Delete article" gnus-summary-delete-article
1652                (gnus-check-backend-function
1653                 'request-expire-articles gnus-newsgroup-name)]
1654               ["Query respool" gnus-summary-respool-query t]
1655               ["Trace respool" gnus-summary-respool-trace t]
1656               ["Delete expirable articles" gnus-summary-expire-articles-now
1657                (gnus-check-backend-function
1658                 'request-expire-articles gnus-newsgroup-name)])
1659              ("Extract"
1660               ["Uudecode" gnus-uu-decode-uu t]
1661               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1662               ["Unshar" gnus-uu-decode-unshar t]
1663               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1664               ["Save" gnus-uu-decode-save t]
1665               ["Binhex" gnus-uu-decode-binhex t]
1666               ["Postscript" gnus-uu-decode-postscript t])
1667              ("Cache"
1668               ["Enter article" gnus-cache-enter-article t]
1669               ["Remove article" gnus-cache-remove-article t])
1670              ["Select article buffer" gnus-summary-select-article-buffer t]
1671              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1672              ["Isearch article..." gnus-summary-isearch-article t]
1673              ["Beginning of the article" gnus-summary-beginning-of-article t]
1674              ["End of the article" gnus-summary-end-of-article t]
1675              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1676              ["Fetch referenced articles" gnus-summary-refer-references t]
1677              ["Fetch current thread" gnus-summary-refer-thread t]
1678              ["Fetch article with id..." gnus-summary-refer-article t]
1679              ["Redisplay" gnus-summary-show-article t])))
1680       (easy-menu-define
1681        gnus-summary-article-menu gnus-summary-mode-map ""
1682        (cons "Article" innards))
1683
1684       (easy-menu-define
1685        gnus-article-commands-menu gnus-article-mode-map ""
1686        (cons "Commands" innards)))
1687
1688     (easy-menu-define
1689      gnus-summary-thread-menu gnus-summary-mode-map ""
1690      '("Threads"
1691        ["Toggle threading" gnus-summary-toggle-threads t]
1692        ["Hide threads" gnus-summary-hide-all-threads t]
1693        ["Show threads" gnus-summary-show-all-threads t]
1694        ["Hide thread" gnus-summary-hide-thread t]
1695        ["Show thread" gnus-summary-show-thread t]
1696        ["Go to next thread" gnus-summary-next-thread t]
1697        ["Go to previous thread" gnus-summary-prev-thread t]
1698        ["Go down thread" gnus-summary-down-thread t]
1699        ["Go up thread" gnus-summary-up-thread t]
1700        ["Top of thread" gnus-summary-top-thread t]
1701        ["Mark thread as read" gnus-summary-kill-thread t]
1702        ["Lower thread score" gnus-summary-lower-thread t]
1703        ["Raise thread score" gnus-summary-raise-thread t]
1704        ["Rethread current" gnus-summary-rethread-current t]
1705        ))
1706
1707     (easy-menu-define
1708      gnus-summary-post-menu gnus-summary-mode-map ""
1709      '("Post"
1710        ["Post an article" gnus-summary-post-news t]
1711        ["Followup" gnus-summary-followup t]
1712        ["Followup and yank" gnus-summary-followup-with-original t]
1713        ["Supersede article" gnus-summary-supersede-article t]
1714        ["Cancel article" gnus-summary-cancel-article t]
1715        ["Reply" gnus-summary-reply t]
1716        ["Reply and yank" gnus-summary-reply-with-original t]
1717        ["Wide reply" gnus-summary-wide-reply t]
1718        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
1719        ["Mail forward" gnus-summary-mail-forward t]
1720        ["Post forward" gnus-summary-post-forward t]
1721        ["Digest and mail" gnus-uu-digest-mail-forward t]
1722        ["Digest and post" gnus-uu-digest-post-forward t]
1723        ["Resend message" gnus-summary-resend-message t]
1724        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1725        ["Send a mail" gnus-summary-mail-other-window t]
1726        ["Uuencode and post" gnus-uu-post-news t]
1727        ["Followup via news" gnus-summary-followup-to-mail t]
1728        ["Followup via news and yank"
1729         gnus-summary-followup-to-mail-with-original t]
1730        ;;("Draft"
1731        ;;["Send" gnus-summary-send-draft t]
1732        ;;["Send bounced" gnus-resend-bounced-mail t])
1733        ))
1734
1735     (easy-menu-define
1736      gnus-summary-misc-menu gnus-summary-mode-map ""
1737      '("Misc"
1738        ("Mark Read"
1739         ["Mark as read" gnus-summary-mark-as-read-forward t]
1740         ["Mark same subject and select"
1741          gnus-summary-kill-same-subject-and-select t]
1742         ["Mark same subject" gnus-summary-kill-same-subject t]
1743         ["Catchup" gnus-summary-catchup t]
1744         ["Catchup all" gnus-summary-catchup-all t]
1745         ["Catchup to here" gnus-summary-catchup-to-here t]
1746         ["Catchup region" gnus-summary-mark-region-as-read t]
1747         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1748        ("Mark Various"
1749         ["Tick" gnus-summary-tick-article-forward t]
1750         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1751         ["Remove marks" gnus-summary-clear-mark-forward t]
1752         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1753         ["Set bookmark" gnus-summary-set-bookmark t]
1754         ["Remove bookmark" gnus-summary-remove-bookmark t])
1755        ("Mark Limit"
1756         ["Marks..." gnus-summary-limit-to-marks t]
1757         ["Subject..." gnus-summary-limit-to-subject t]
1758         ["Author..." gnus-summary-limit-to-author t]
1759         ["Age..." gnus-summary-limit-to-age t]
1760         ["Score" gnus-summary-limit-to-score t]
1761         ["Unread" gnus-summary-limit-to-unread t]
1762         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1763         ["Articles" gnus-summary-limit-to-articles t]
1764         ["Pop limit" gnus-summary-pop-limit t]
1765         ["Show dormant" gnus-summary-limit-include-dormant t]
1766         ["Hide childless dormant"
1767          gnus-summary-limit-exclude-childless-dormant t]
1768         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1769         ["Show expunged" gnus-summary-show-all-expunged t])
1770        ("Process Mark"
1771         ["Set mark" gnus-summary-mark-as-processable t]
1772         ["Remove mark" gnus-summary-unmark-as-processable t]
1773         ["Remove all marks" gnus-summary-unmark-all-processable t]
1774         ["Mark above" gnus-uu-mark-over t]
1775         ["Mark series" gnus-uu-mark-series t]
1776         ["Mark region" gnus-uu-mark-region t]
1777         ["Unmark region" gnus-uu-unmark-region t]
1778         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1779         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1780         ["Mark all" gnus-uu-mark-all t]
1781         ["Mark buffer" gnus-uu-mark-buffer t]
1782         ["Mark sparse" gnus-uu-mark-sparse t]
1783         ["Mark thread" gnus-uu-mark-thread t]
1784         ["Unmark thread" gnus-uu-unmark-thread t]
1785         ("Process Mark Sets"
1786          ["Kill" gnus-summary-kill-process-mark t]
1787          ["Yank" gnus-summary-yank-process-mark
1788           gnus-newsgroup-process-stack]
1789          ["Save" gnus-summary-save-process-mark t]))
1790        ("Scroll article"
1791         ["Page forward" gnus-summary-next-page t]
1792         ["Page backward" gnus-summary-prev-page t]
1793         ["Line forward" gnus-summary-scroll-up t])
1794        ("Move"
1795         ["Next unread article" gnus-summary-next-unread-article t]
1796         ["Previous unread article" gnus-summary-prev-unread-article t]
1797         ["Next article" gnus-summary-next-article t]
1798         ["Previous article" gnus-summary-prev-article t]
1799         ["Next unread subject" gnus-summary-next-unread-subject t]
1800         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1801         ["Next article same subject" gnus-summary-next-same-subject t]
1802         ["Previous article same subject" gnus-summary-prev-same-subject t]
1803         ["First unread article" gnus-summary-first-unread-article t]
1804         ["Best unread article" gnus-summary-best-unread-article t]
1805         ["Go to subject number..." gnus-summary-goto-subject t]
1806         ["Go to article number..." gnus-summary-goto-article t]
1807         ["Go to the last article" gnus-summary-goto-last-article t]
1808         ["Pop article off history" gnus-summary-pop-article t])
1809        ("Sort"
1810         ["Sort by number" gnus-summary-sort-by-number t]
1811         ["Sort by author" gnus-summary-sort-by-author t]
1812         ["Sort by subject" gnus-summary-sort-by-subject t]
1813         ["Sort by date" gnus-summary-sort-by-date t]
1814         ["Sort by score" gnus-summary-sort-by-score t]
1815         ["Sort by lines" gnus-summary-sort-by-lines t])
1816        ("Help"
1817         ["Fetch group FAQ" gnus-summary-fetch-faq t]
1818         ["Describe group" gnus-summary-describe-group t]
1819         ["Read manual" gnus-info-find-node t])
1820        ("Modes"
1821         ["Pick and read" gnus-pick-mode t]
1822         ["Binary" gnus-binary-mode t])
1823        ("Regeneration"
1824         ["Regenerate" gnus-summary-prepare t]
1825         ["Insert cached articles" gnus-summary-insert-cached-articles t]
1826         ["Toggle threading" gnus-summary-toggle-threads t])
1827        ["Filter articles..." gnus-summary-execute-command t]
1828        ["Run command on subjects..." gnus-summary-universal-argument t]
1829        ["Search articles forward..." gnus-summary-search-article-forward t]
1830        ["Search articles backward..." gnus-summary-search-article-backward t]
1831        ["Toggle line truncation" gnus-summary-toggle-truncation t]
1832        ["Expand window" gnus-summary-expand-window t]
1833        ["Expire expirable articles" gnus-summary-expire-articles
1834         (gnus-check-backend-function
1835          'request-expire-articles gnus-newsgroup-name)]
1836        ["Edit local kill file" gnus-summary-edit-local-kill t]
1837        ["Edit main kill file" gnus-summary-edit-global-kill t]
1838        ["Edit group parameters" gnus-summary-edit-parameters t]
1839        ["Customize group parameters" gnus-summary-customize-parameters t]
1840        ["Send a bug report" gnus-bug t]
1841        ("Exit"
1842         ["Catchup and exit" gnus-summary-catchup-and-exit t]
1843         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
1844         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
1845         ["Exit group" gnus-summary-exit t]
1846         ["Exit group without updating" gnus-summary-exit-no-update t]
1847         ["Exit and goto next group" gnus-summary-next-group t]
1848         ["Exit and goto prev group" gnus-summary-prev-group t]
1849         ["Reselect group" gnus-summary-reselect-current-group t]
1850         ["Rescan group" gnus-summary-rescan-group t]
1851         ["Update dribble" gnus-summary-save-newsrc t])))
1852
1853     (gnus-run-hooks 'gnus-summary-menu-hook)))
1854
1855 (defun gnus-score-set-default (var value)
1856   "A version of set that updates the GNU Emacs menu-bar."
1857   (set var value)
1858   ;; It is the message that forces the active status to be updated.
1859   (message ""))
1860
1861 (defun gnus-make-score-map (type)
1862   "Make a summary score map of type TYPE."
1863   (if t
1864       nil
1865     (let ((headers '(("author" "from" string)
1866                      ("subject" "subject" string)
1867                      ("article body" "body" string)
1868                      ("article head" "head" string)
1869                      ("xref" "xref" string)
1870                      ("extra header" "extra" string)
1871                      ("lines" "lines" number)
1872                      ("followups to author" "followup" string)))
1873           (types '((number ("less than" <)
1874                            ("greater than" >)
1875                            ("equal" =))
1876                    (string ("substring" s)
1877                            ("exact string" e)
1878                            ("fuzzy string" f)
1879                            ("regexp" r))))
1880           (perms '(("temporary" (current-time-string))
1881                    ("permanent" nil)
1882                    ("immediate" now)))
1883           header)
1884       (list
1885        (apply
1886         'nconc
1887         (list
1888          (if (eq type 'lower)
1889              "Lower score"
1890            "Increase score"))
1891         (let (outh)
1892           (while headers
1893             (setq header (car headers))
1894             (setq outh
1895                   (cons
1896                    (apply
1897                     'nconc
1898                     (list (car header))
1899                     (let ((ts (cdr (assoc (nth 2 header) types)))
1900                           outt)
1901                       (while ts
1902                         (setq outt
1903                               (cons
1904                                (apply
1905                                 'nconc
1906                                 (list (caar ts))
1907                                 (let ((ps perms)
1908                                       outp)
1909                                   (while ps
1910                                     (setq outp
1911                                           (cons
1912                                            (vector
1913                                             (caar ps)
1914                                             (list
1915                                              'gnus-summary-score-entry
1916                                              (nth 1 header)
1917                                              (if (or (string= (nth 1 header)
1918                                                               "head")
1919                                                      (string= (nth 1 header)
1920                                                               "body"))
1921                                                  ""
1922                                                (list 'gnus-summary-header
1923                                                      (nth 1 header)))
1924                                              (list 'quote (nth 1 (car ts)))
1925                                              (list 'gnus-score-default nil)
1926                                              (nth 1 (car ps))
1927                                              t)
1928                                             t)
1929                                            outp))
1930                                     (setq ps (cdr ps)))
1931                                   (list (nreverse outp))))
1932                                outt))
1933                         (setq ts (cdr ts)))
1934                       (list (nreverse outt))))
1935                    outh))
1936             (setq headers (cdr headers)))
1937           (list (nreverse outh))))))))
1938
1939 \f
1940
1941 (defun gnus-summary-mode (&optional group)
1942   "Major mode for reading articles.
1943
1944 All normal editing commands are switched off.
1945 \\<gnus-summary-mode-map>
1946 Each line in this buffer represents one article.  To read an
1947 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
1948 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
1949 respectively.
1950
1951 You can also post articles and send mail from this buffer.  To
1952 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
1953 of an article, type `\\[gnus-summary-reply]'.
1954
1955 There are approx. one gazillion commands you can execute in this
1956 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
1957
1958 The following commands are available:
1959
1960 \\{gnus-summary-mode-map}"
1961   (interactive)
1962   (when (gnus-visual-p 'summary-menu 'menu)
1963     (gnus-summary-make-menu-bar))
1964   (kill-all-local-variables)
1965   (gnus-summary-make-local-variables)
1966   (gnus-make-thread-indent-array)
1967   (gnus-simplify-mode-line)
1968   (setq major-mode 'gnus-summary-mode)
1969   (setq mode-name "Summary")
1970   (make-local-variable 'minor-mode-alist)
1971   (use-local-map gnus-summary-mode-map)
1972   (buffer-disable-undo)
1973   (setq buffer-read-only t)             ;Disable modification
1974   (setq truncate-lines t)
1975   (setq selective-display t)
1976   (setq selective-display-ellipses t)   ;Display `...'
1977   (gnus-summary-set-display-table)
1978   (gnus-set-default-directory)
1979   (setq gnus-newsgroup-name group)
1980   (make-local-variable 'gnus-summary-line-format)
1981   (make-local-variable 'gnus-summary-line-format-spec)
1982   (make-local-variable 'gnus-summary-dummy-line-format)
1983   (make-local-variable 'gnus-summary-dummy-line-format-spec)
1984   (make-local-variable 'gnus-summary-mark-positions)
1985   (make-local-hook 'post-command-hook)
1986   (add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
1987   (make-local-hook 'pre-command-hook)
1988   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
1989   (gnus-run-hooks 'gnus-summary-mode-hook)
1990   (mm-enable-multibyte)
1991   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
1992   (gnus-update-summary-mark-positions))
1993
1994 (defun gnus-summary-make-local-variables ()
1995   "Make all the local summary buffer variables."
1996   (let ((locals gnus-summary-local-variables)
1997         global local)
1998     (while (setq local (pop locals))
1999       (if (consp local)
2000           (progn
2001             (if (eq (cdr local) 'global)
2002                 ;; Copy the global value of the variable.
2003                 (setq global (symbol-value (car local)))
2004               ;; Use the value from the list.
2005               (setq global (eval (cdr local))))
2006             (make-local-variable (car local))
2007             (set (car local) global))
2008         ;; Simple nil-valued local variable.
2009         (make-local-variable local)
2010         (set local nil)))))
2011
2012 (defun gnus-summary-clear-local-variables ()
2013   (let ((locals gnus-summary-local-variables))
2014     (while locals
2015       (if (consp (car locals))
2016           (and (vectorp (caar locals))
2017                (set (caar locals) nil))
2018         (and (vectorp (car locals))
2019              (set (car locals) nil)))
2020       (setq locals (cdr locals)))))
2021
2022 ;; Summary data functions.
2023
2024 (defmacro gnus-data-number (data)
2025   `(car ,data))
2026
2027 (defmacro gnus-data-set-number (data number)
2028   `(setcar ,data ,number))
2029
2030 (defmacro gnus-data-mark (data)
2031   `(nth 1 ,data))
2032
2033 (defmacro gnus-data-set-mark (data mark)
2034   `(setcar (nthcdr 1 ,data) ,mark))
2035
2036 (defmacro gnus-data-pos (data)
2037   `(nth 2 ,data))
2038
2039 (defmacro gnus-data-set-pos (data pos)
2040   `(setcar (nthcdr 2 ,data) ,pos))
2041
2042 (defmacro gnus-data-header (data)
2043   `(nth 3 ,data))
2044
2045 (defmacro gnus-data-set-header (data header)
2046   `(setf (nth 3 ,data) ,header))
2047
2048 (defmacro gnus-data-level (data)
2049   `(nth 4 ,data))
2050
2051 (defmacro gnus-data-unread-p (data)
2052   `(= (nth 1 ,data) gnus-unread-mark))
2053
2054 (defmacro gnus-data-read-p (data)
2055   `(/= (nth 1 ,data) gnus-unread-mark))
2056
2057 (defmacro gnus-data-pseudo-p (data)
2058   `(consp (nth 3 ,data)))
2059
2060 (defmacro gnus-data-find (number)
2061   `(assq ,number gnus-newsgroup-data))
2062
2063 (defmacro gnus-data-find-list (number &optional data)
2064   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2065      (memq (assq ,number bdata)
2066            bdata)))
2067
2068 (defmacro gnus-data-make (number mark pos header level)
2069   `(list ,number ,mark ,pos ,header ,level))
2070
2071 (defun gnus-data-enter (after-article number mark pos header level offset)
2072   (let ((data (gnus-data-find-list after-article)))
2073     (unless data
2074       (error "No such article: %d" after-article))
2075     (setcdr data (cons (gnus-data-make number mark pos header level)
2076                        (cdr data)))
2077     (setq gnus-newsgroup-data-reverse nil)
2078     (gnus-data-update-list (cddr data) offset)))
2079
2080 (defun gnus-data-enter-list (after-article list &optional offset)
2081   (when list
2082     (let ((data (and after-article (gnus-data-find-list after-article)))
2083           (ilist list))
2084       (if (not (or data
2085                    after-article))
2086           (let ((odata gnus-newsgroup-data))
2087             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2088             (when offset
2089               (gnus-data-update-list odata offset)))
2090         ;; Find the last element in the list to be spliced into the main
2091         ;; list.
2092         (while (cdr list)
2093           (setq list (cdr list)))
2094         (if (not data)
2095             (progn
2096               (setcdr list gnus-newsgroup-data)
2097               (setq gnus-newsgroup-data ilist)
2098               (when offset
2099                 (gnus-data-update-list (cdr list) offset)))
2100           (setcdr list (cdr data))
2101           (setcdr data ilist)
2102           (when offset
2103             (gnus-data-update-list (cdr list) offset))))
2104       (setq gnus-newsgroup-data-reverse nil))))
2105
2106 (defun gnus-data-remove (article &optional offset)
2107   (let ((data gnus-newsgroup-data))
2108     (if (= (gnus-data-number (car data)) article)
2109         (progn
2110           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2111                 gnus-newsgroup-data-reverse nil)
2112           (when offset
2113             (gnus-data-update-list gnus-newsgroup-data offset)))
2114       (while (cdr data)
2115         (when (= (gnus-data-number (cadr data)) article)
2116           (setcdr data (cddr data))
2117           (when offset
2118             (gnus-data-update-list (cdr data) offset))
2119           (setq data nil
2120                 gnus-newsgroup-data-reverse nil))
2121         (setq data (cdr data))))))
2122
2123 (defmacro gnus-data-list (backward)
2124   `(if ,backward
2125        (or gnus-newsgroup-data-reverse
2126            (setq gnus-newsgroup-data-reverse
2127                  (reverse gnus-newsgroup-data)))
2128      gnus-newsgroup-data))
2129
2130 (defun gnus-data-update-list (data offset)
2131   "Add OFFSET to the POS of all data entries in DATA."
2132   (setq gnus-newsgroup-data-reverse nil)
2133   (while data
2134     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2135     (setq data (cdr data))))
2136
2137 (defun gnus-summary-article-pseudo-p (article)
2138   "Say whether this article is a pseudo article or not."
2139   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2140
2141 (defmacro gnus-summary-article-sparse-p (article)
2142   "Say whether this article is a sparse article or not."
2143   `(memq ,article gnus-newsgroup-sparse))
2144
2145 (defmacro gnus-summary-article-ancient-p (article)
2146   "Say whether this article is a sparse article or not."
2147   `(memq ,article gnus-newsgroup-ancient))
2148
2149 (defun gnus-article-parent-p (number)
2150   "Say whether this article is a parent or not."
2151   (let ((data (gnus-data-find-list number)))
2152     (and (cdr data)                     ; There has to be an article after...
2153          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2154             (gnus-data-level (nth 1 data))))))
2155
2156 (defun gnus-article-children (number)
2157   "Return a list of all children to NUMBER."
2158   (let* ((data (gnus-data-find-list number))
2159          (level (gnus-data-level (car data)))
2160          children)
2161     (setq data (cdr data))
2162     (while (and data
2163                 (= (gnus-data-level (car data)) (1+ level)))
2164       (push (gnus-data-number (car data)) children)
2165       (setq data (cdr data)))
2166     children))
2167
2168 (defmacro gnus-summary-skip-intangible ()
2169   "If the current article is intangible, then jump to a different article."
2170   '(let ((to (get-text-property (point) 'gnus-intangible)))
2171      (and to (gnus-summary-goto-subject to))))
2172
2173 (defmacro gnus-summary-article-intangible-p ()
2174   "Say whether this article is intangible or not."
2175   '(get-text-property (point) 'gnus-intangible))
2176
2177 (defun gnus-article-read-p (article)
2178   "Say whether ARTICLE is read or not."
2179   (not (or (memq article gnus-newsgroup-marked)
2180            (memq article gnus-newsgroup-unreads)
2181            (memq article gnus-newsgroup-unselected)
2182            (memq article gnus-newsgroup-dormant))))
2183
2184 ;; Some summary mode macros.
2185
2186 (defmacro gnus-summary-article-number ()
2187   "The article number of the article on the current line.
2188 If there isn's an article number here, then we return the current
2189 article number."
2190   '(progn
2191      (gnus-summary-skip-intangible)
2192      (or (get-text-property (point) 'gnus-number)
2193          (gnus-summary-last-subject))))
2194
2195 (defmacro gnus-summary-article-header (&optional number)
2196   "Return the header of article NUMBER."
2197   `(gnus-data-header (gnus-data-find
2198                       ,(or number '(gnus-summary-article-number)))))
2199
2200 (defmacro gnus-summary-thread-level (&optional number)
2201   "Return the level of thread that starts with article NUMBER."
2202   `(if (and (eq gnus-summary-make-false-root 'dummy)
2203             (get-text-property (point) 'gnus-intangible))
2204        0
2205      (gnus-data-level (gnus-data-find
2206                        ,(or number '(gnus-summary-article-number))))))
2207
2208 (defmacro gnus-summary-article-mark (&optional number)
2209   "Return the mark of article NUMBER."
2210   `(gnus-data-mark (gnus-data-find
2211                     ,(or number '(gnus-summary-article-number)))))
2212
2213 (defmacro gnus-summary-article-pos (&optional number)
2214   "Return the position of the line of article NUMBER."
2215   `(gnus-data-pos (gnus-data-find
2216                    ,(or number '(gnus-summary-article-number)))))
2217
2218 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2219 (defmacro gnus-summary-article-subject (&optional number)
2220   "Return current subject string or nil if nothing."
2221   `(let ((headers
2222           ,(if number
2223                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2224              '(gnus-data-header (assq (gnus-summary-article-number)
2225                                       gnus-newsgroup-data)))))
2226      (and headers
2227           (vectorp headers)
2228           (mail-header-subject headers))))
2229
2230 (defmacro gnus-summary-article-score (&optional number)
2231   "Return current article score."
2232   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2233                   gnus-newsgroup-scored))
2234        gnus-summary-default-score 0))
2235
2236 (defun gnus-summary-article-children (&optional number)
2237   "Return a list of article numbers that are children of article NUMBER."
2238   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2239          (level (gnus-data-level (car data)))
2240          l children)
2241     (while (and (setq data (cdr data))
2242                 (> (setq l (gnus-data-level (car data))) level))
2243       (and (= (1+ level) l)
2244            (push (gnus-data-number (car data))
2245                  children)))
2246     (nreverse children)))
2247
2248 (defun gnus-summary-article-parent (&optional number)
2249   "Return the article number of the parent of article NUMBER."
2250   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2251                                     (gnus-data-list t)))
2252          (level (gnus-data-level (car data))))
2253     (if (zerop level)
2254         ()                              ; This is a root.
2255       ;; We search until we find an article with a level less than
2256       ;; this one.  That function has to be the parent.
2257       (while (and (setq data (cdr data))
2258                   (not (< (gnus-data-level (car data)) level))))
2259       (and data (gnus-data-number (car data))))))
2260
2261 (defun gnus-unread-mark-p (mark)
2262   "Say whether MARK is the unread mark."
2263   (= mark gnus-unread-mark))
2264
2265 (defun gnus-read-mark-p (mark)
2266   "Say whether MARK is one of the marks that mark as read.
2267 This is all marks except unread, ticked, dormant, and expirable."
2268   (not (or (= mark gnus-unread-mark)
2269            (= mark gnus-ticked-mark)
2270            (= mark gnus-dormant-mark)
2271            (= mark gnus-expirable-mark))))
2272
2273 (defmacro gnus-article-mark (number)
2274   "Return the MARK of article NUMBER.
2275 This macro should only be used when computing the mark the \"first\"
2276 time; i.e., when generating the summary lines.  After that,
2277 `gnus-summary-article-mark' should be used to examine the
2278 marks of articles."
2279   `(cond
2280     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2281     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2282     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2283     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2284     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2285     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2286     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2287     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2288            gnus-ancient-mark))))
2289
2290 ;; Saving hidden threads.
2291
2292 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2293 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2294
2295 (defmacro gnus-save-hidden-threads (&rest forms)
2296   "Save hidden threads, eval FORMS, and restore the hidden threads."
2297   (let ((config (make-symbol "config")))
2298     `(let ((,config (gnus-hidden-threads-configuration)))
2299        (unwind-protect
2300            (save-excursion
2301              ,@forms)
2302          (gnus-restore-hidden-threads-configuration ,config)))))
2303
2304 (defun gnus-data-compute-positions ()
2305   "Compute the positions of all articles."
2306   (setq gnus-newsgroup-data-reverse nil)
2307   (let ((data gnus-newsgroup-data))
2308     (save-excursion
2309       (gnus-save-hidden-threads
2310         (gnus-summary-show-all-threads)
2311         (goto-char (point-min))
2312         (while data
2313           (while (get-text-property (point) 'gnus-intangible)
2314             (forward-line 1))
2315           (gnus-data-set-pos (car data) (+ (point) 3))
2316           (setq data (cdr data))
2317           (forward-line 1))))))
2318
2319 (defun gnus-hidden-threads-configuration ()
2320   "Return the current hidden threads configuration."
2321   (save-excursion
2322     (let (config)
2323       (goto-char (point-min))
2324       (while (search-forward "\r" nil t)
2325         (push (1- (point)) config))
2326       config)))
2327
2328 (defun gnus-restore-hidden-threads-configuration (config)
2329   "Restore hidden threads configuration from CONFIG."
2330   (let (point buffer-read-only)
2331     (while (setq point (pop config))
2332       (when (and (< point (point-max))
2333                  (goto-char point)
2334                  (eq (char-after) ?\n))
2335         (subst-char-in-region point (1+ point) ?\n ?\r)))))
2336
2337 ;; Various summary mode internalish functions.
2338
2339 (defun gnus-mouse-pick-article (e)
2340   (interactive "e")
2341   (mouse-set-point e)
2342   (gnus-summary-next-page nil t))
2343
2344 (defun gnus-summary-set-display-table ()
2345   ;; Change the display table.  Odd characters have a tendency to mess
2346   ;; up nicely formatted displays - we make all possible glyphs
2347   ;; display only a single character.
2348
2349   ;; We start from the standard display table, if any.
2350   (let ((table (or (copy-sequence standard-display-table)
2351                    (make-display-table)))
2352         (i 32))
2353     ;; Nix out all the control chars...
2354     (while (>= (setq i (1- i)) 0)
2355       (aset table i [??]))
2356     ;; ... but not newline and cr, of course.  (cr is necessary for the
2357     ;; selective display).
2358     (aset table ?\n nil)
2359     (aset table ?\r nil)
2360     ;; We keep TAB as well.
2361     (aset table ?\t nil)
2362     ;; We nix out any glyphs over 126 that are not set already.
2363     (let ((i 256))
2364       (while (>= (setq i (1- i)) 127)
2365         ;; Only modify if the entry is nil.
2366         (unless (aref table i)
2367           (aset table i [??]))))
2368     (setq buffer-display-table table)))
2369
2370 (defun gnus-summary-setup-buffer (group)
2371   "Initialize summary buffer."
2372   (let ((buffer (concat "*Summary " group "*")))
2373     (if (get-buffer buffer)
2374         (progn
2375           (set-buffer buffer)
2376           (setq gnus-summary-buffer (current-buffer))
2377           (not gnus-newsgroup-prepared))
2378       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2379       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2380       (gnus-summary-mode group)
2381       (when gnus-carpal
2382         (gnus-carpal-setup-buffer 'summary))
2383       (unless gnus-single-article-buffer
2384         (make-local-variable 'gnus-article-buffer)
2385         (make-local-variable 'gnus-article-current)
2386         (make-local-variable 'gnus-original-article-buffer))
2387       (setq gnus-newsgroup-name group)
2388       t)))
2389
2390 (defun gnus-set-global-variables ()
2391   ;; Set the global equivalents of the summary buffer-local variables
2392   ;; to the latest values they had.  These reflect the summary buffer
2393   ;; that was in action when the last article was fetched.
2394   (when (eq major-mode 'gnus-summary-mode)
2395     (setq gnus-summary-buffer (current-buffer))
2396     (let ((name gnus-newsgroup-name)
2397           (marked gnus-newsgroup-marked)
2398           (unread gnus-newsgroup-unreads)
2399           (headers gnus-current-headers)
2400           (data gnus-newsgroup-data)
2401           (summary gnus-summary-buffer)
2402           (article-buffer gnus-article-buffer)
2403           (original gnus-original-article-buffer)
2404           (gac gnus-article-current)
2405           (reffed gnus-reffed-article-number)
2406           (score-file gnus-current-score-file)
2407           (default-charset gnus-newsgroup-default-charset)
2408           (iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2409       (save-excursion
2410         (set-buffer gnus-group-buffer)
2411         (setq gnus-newsgroup-name name
2412               gnus-newsgroup-marked marked
2413               gnus-newsgroup-unreads unread
2414               gnus-current-headers headers
2415               gnus-newsgroup-data data
2416               gnus-article-current gac
2417               gnus-summary-buffer summary
2418               gnus-article-buffer article-buffer
2419               gnus-original-article-buffer original
2420               gnus-reffed-article-number reffed
2421               gnus-current-score-file score-file
2422               gnus-newsgroup-default-charset default-charset
2423               gnus-newsgroup-iso-8859-1-forced iso-8859-1-forced)
2424         ;; The article buffer also has local variables.
2425         (when (gnus-buffer-live-p gnus-article-buffer)
2426           (set-buffer gnus-article-buffer)
2427           (setq gnus-summary-buffer summary))))))
2428
2429 (defun gnus-summary-article-unread-p (article)
2430   "Say whether ARTICLE is unread or not."
2431   (memq article gnus-newsgroup-unreads))
2432
2433 (defun gnus-summary-first-article-p (&optional article)
2434   "Return whether ARTICLE is the first article in the buffer."
2435   (if (not (setq article (or article (gnus-summary-article-number))))
2436       nil
2437     (eq article (caar gnus-newsgroup-data))))
2438
2439 (defun gnus-summary-last-article-p (&optional article)
2440   "Return whether ARTICLE is the last article in the buffer."
2441   (if (not (setq article (or article (gnus-summary-article-number))))
2442       t                                 ; All non-existent numbers are the last article.  :-)
2443     (not (cdr (gnus-data-find-list article)))))
2444
2445 (defun gnus-make-thread-indent-array ()
2446   (let ((n 200))
2447     (unless (and gnus-thread-indent-array
2448                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2449       (setq gnus-thread-indent-array (make-vector 201 "")
2450             gnus-thread-indent-array-level gnus-thread-indent-level)
2451       (while (>= n 0)
2452         (aset gnus-thread-indent-array n
2453               (make-string (* n gnus-thread-indent-level) ? ))
2454         (setq n (1- n))))))
2455
2456 (defun gnus-update-summary-mark-positions ()
2457   "Compute where the summary marks are to go."
2458   (save-excursion
2459     (when (gnus-buffer-exists-p gnus-summary-buffer)
2460       (set-buffer gnus-summary-buffer))
2461     (let ((gnus-replied-mark 129)
2462           (gnus-score-below-mark 130)
2463           (gnus-score-over-mark 130)
2464           (gnus-download-mark 131)
2465           (spec gnus-summary-line-format-spec)
2466           gnus-visual pos)
2467       (save-excursion
2468         (gnus-set-work-buffer)
2469         (let ((gnus-summary-line-format-spec spec)
2470               (gnus-newsgroup-downloadable '((0 . t))))
2471           (gnus-summary-insert-line
2472            [0 "" "" "" "" "" 0 0 "" nil]  0 nil 128 t nil "" nil 1)
2473           (goto-char (point-min))
2474           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2475                                              (- (point) 2)))))
2476           (goto-char (point-min))
2477           (push (cons 'replied (and (search-forward "\201" nil t)
2478                                     (- (point) 2)))
2479                 pos)
2480           (goto-char (point-min))
2481           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2482                 pos)
2483           (goto-char (point-min))
2484           (push (cons 'download
2485                       (and (search-forward "\203" nil t) (- (point) 2)))
2486                 pos)))
2487       (setq gnus-summary-mark-positions pos))))
2488
2489 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2490   "Insert a dummy root in the summary buffer."
2491   (beginning-of-line)
2492   (gnus-add-text-properties
2493    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2494    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2495
2496 (defun gnus-summary-from-or-to-or-newsgroups (header)
2497   (let ((to (cdr (assq 'To (mail-header-extra header))))
2498         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2499         (rfc2047-default-charset gnus-newsgroup-default-charset)
2500         (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2501     (cond
2502      ((and to
2503            gnus-ignored-from-addresses
2504            (string-match gnus-ignored-from-addresses
2505                          (mail-header-from header)))
2506       (concat "-> "
2507               (or (car (funcall gnus-extract-address-components
2508                                 (funcall
2509                                  gnus-decode-encoded-word-function to)))
2510                   (funcall gnus-decode-encoded-word-function to))))
2511      ((and newsgroups
2512            gnus-ignored-from-addresses
2513            (string-match gnus-ignored-from-addresses
2514                          (mail-header-from header)))
2515       (concat "=> " newsgroups))
2516      (t
2517       (or (car (funcall gnus-extract-address-components
2518                         (mail-header-from header)))
2519           (mail-header-from header))))))
2520
2521 (defun gnus-summary-insert-line (gnus-tmp-header
2522                                  gnus-tmp-level gnus-tmp-current
2523                                  gnus-tmp-unread gnus-tmp-replied
2524                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2525                                  &optional gnus-tmp-dummy gnus-tmp-score
2526                                  gnus-tmp-process)
2527   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2528          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2529          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2530          (gnus-tmp-score-char
2531           (if (or (null gnus-summary-default-score)
2532                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2533                       gnus-summary-zcore-fuzz))
2534               ? 
2535             (if (< gnus-tmp-score gnus-summary-default-score)
2536                 gnus-score-below-mark gnus-score-over-mark)))
2537          (gnus-tmp-replied
2538           (cond (gnus-tmp-process gnus-process-mark)
2539                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2540                  gnus-cached-mark)
2541                 (gnus-tmp-replied gnus-replied-mark)
2542                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2543                  gnus-saved-mark)
2544                 (t gnus-unread-mark)))
2545          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2546          (gnus-tmp-name
2547           (cond
2548            ((string-match "<[^>]+> *$" gnus-tmp-from)
2549             (let ((beg (match-beginning 0)))
2550               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2551                        (substring gnus-tmp-from (1+ (match-beginning 0))
2552                                   (1- (match-end 0))))
2553                   (substring gnus-tmp-from 0 beg))))
2554            ((string-match "(.+)" gnus-tmp-from)
2555             (substring gnus-tmp-from
2556                        (1+ (match-beginning 0)) (1- (match-end 0))))
2557            (t gnus-tmp-from)))
2558          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2559          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2560          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2561          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2562          (buffer-read-only nil))
2563     (when (string= gnus-tmp-name "")
2564       (setq gnus-tmp-name gnus-tmp-from))
2565     (unless (numberp gnus-tmp-lines)
2566       (setq gnus-tmp-lines 0))
2567     (gnus-put-text-property
2568      (point)
2569      (progn (eval gnus-summary-line-format-spec) (point))
2570      'gnus-number gnus-tmp-number)
2571     (when (gnus-visual-p 'summary-highlight 'highlight)
2572       (forward-line -1)
2573       (gnus-run-hooks 'gnus-summary-update-hook)
2574       (forward-line 1))))
2575
2576 (defun gnus-summary-update-line (&optional dont-update)
2577   ;; Update summary line after change.
2578   (when (and gnus-summary-default-score
2579              (not gnus-summary-inhibit-highlight))
2580     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2581            (article (gnus-summary-article-number))
2582            (score (gnus-summary-article-score article)))
2583       (unless dont-update
2584         (if (and gnus-summary-mark-below
2585                  (< (gnus-summary-article-score)
2586                     gnus-summary-mark-below))
2587             ;; This article has a low score, so we mark it as read.
2588             (when (memq article gnus-newsgroup-unreads)
2589               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2590           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2591             ;; This article was previously marked as read on account
2592             ;; of a low score, but now it has risen, so we mark it as
2593             ;; unread.
2594             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2595         (gnus-summary-update-mark
2596          (if (or (null gnus-summary-default-score)
2597                  (<= (abs (- score gnus-summary-default-score))
2598                      gnus-summary-zcore-fuzz))
2599              ? 
2600            (if (< score gnus-summary-default-score)
2601                gnus-score-below-mark gnus-score-over-mark))
2602          'score))
2603       ;; Do visual highlighting.
2604       (when (gnus-visual-p 'summary-highlight 'highlight)
2605         (gnus-run-hooks 'gnus-summary-update-hook)))))
2606
2607 (defvar gnus-tmp-new-adopts nil)
2608
2609 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2610   "Return the number of articles in THREAD.
2611 This may be 0 in some cases -- if none of the articles in
2612 the thread are to be displayed."
2613   (let* ((number
2614           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2615           (cond
2616            ((not (listp thread))
2617             1)
2618            ((and (consp thread) (cdr thread))
2619             (apply
2620              '+ 1 (mapcar
2621                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2622            ((null thread)
2623             1)
2624            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2625             1)
2626            (t 0))))
2627     (when (and level (zerop level) gnus-tmp-new-adopts)
2628       (incf number
2629             (apply '+ (mapcar
2630                        'gnus-summary-number-of-articles-in-thread
2631                        gnus-tmp-new-adopts))))
2632     (if char
2633         (if (> number 1) gnus-not-empty-thread-mark
2634           gnus-empty-thread-mark)
2635       number)))
2636
2637 (defun gnus-summary-set-local-parameters (group)
2638   "Go through the local params of GROUP and set all variable specs in that list."
2639   (let ((params (gnus-group-find-parameter group))
2640         elem)
2641     (while params
2642       (setq elem (car params)
2643             params (cdr params))
2644       (and (consp elem)                 ; Has to be a cons.
2645            (consp (cdr elem))           ; The cdr has to be a list.
2646            (symbolp (car elem))         ; Has to be a symbol in there.
2647            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2648            (ignore-errors               ; So we set it.
2649              (make-local-variable (car elem))
2650              (set (car elem) (eval (nth 1 elem))))))))
2651
2652 (defun gnus-summary-read-group (group &optional show-all no-article
2653                                       kill-buffer no-display backward
2654                                       select-articles)
2655   "Start reading news in newsgroup GROUP.
2656 If SHOW-ALL is non-nil, already read articles are also listed.
2657 If NO-ARTICLE is non-nil, no article is selected initially.
2658 If NO-DISPLAY, don't generate a summary buffer."
2659   (let (result)
2660     (while (and group
2661                 (null (setq result
2662                             (let ((gnus-auto-select-next nil))
2663                               (or (gnus-summary-read-group-1
2664                                    group show-all no-article
2665                                    kill-buffer no-display
2666                                    select-articles)
2667                                   (setq show-all nil
2668                                         select-articles nil)))))
2669                 (eq gnus-auto-select-next 'quietly))
2670       (set-buffer gnus-group-buffer)
2671       ;; The entry function called above goes to the next
2672       ;; group automatically, so we go two groups back
2673       ;; if we are searching for the previous group.
2674       (when backward
2675         (gnus-group-prev-unread-group 2))
2676       (if (not (equal group (gnus-group-group-name)))
2677           (setq group (gnus-group-group-name))
2678         (setq group nil)))
2679     result))
2680
2681 (defun gnus-summary-read-group-1 (group show-all no-article
2682                                         kill-buffer no-display
2683                                         &optional select-articles)
2684   ;; Killed foreign groups can't be entered.
2685   (when (and (not (gnus-group-native-p group))
2686              (not (gnus-gethash group gnus-newsrc-hashtb)))
2687     (error "Dead non-native groups can't be entered"))
2688   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2689   (let* ((new-group (gnus-summary-setup-buffer group))
2690          (quit-config (gnus-group-quit-config group))
2691          (did-select (and new-group (gnus-select-newsgroup
2692                                      group show-all select-articles))))
2693     (cond
2694      ;; This summary buffer exists already, so we just select it.
2695      ((not new-group)
2696       (gnus-set-global-variables)
2697       (when kill-buffer
2698         (gnus-kill-or-deaden-summary kill-buffer))
2699       (gnus-configure-windows 'summary 'force)
2700       (gnus-set-mode-line 'summary)
2701       (gnus-summary-position-point)
2702       (message "")
2703       t)
2704      ;; We couldn't select this group.
2705      ((null did-select)
2706       (when (and (eq major-mode 'gnus-summary-mode)
2707                  (not (equal (current-buffer) kill-buffer)))
2708         (kill-buffer (current-buffer))
2709         (if (not quit-config)
2710             (progn
2711               ;; Update the info -- marks might need to be removed,
2712               ;; for instance.
2713               (gnus-summary-update-info)
2714               (set-buffer gnus-group-buffer)
2715               (gnus-group-jump-to-group group)
2716               (gnus-group-next-unread-group 1))
2717           (gnus-handle-ephemeral-exit quit-config)))
2718       (gnus-message 3 "Can't select group")
2719       nil)
2720      ;; The user did a `C-g' while prompting for number of articles,
2721      ;; so we exit this group.
2722      ((eq did-select 'quit)
2723       (and (eq major-mode 'gnus-summary-mode)
2724            (not (equal (current-buffer) kill-buffer))
2725            (kill-buffer (current-buffer)))
2726       (when kill-buffer
2727         (gnus-kill-or-deaden-summary kill-buffer))
2728       (if (not quit-config)
2729           (progn
2730             (set-buffer gnus-group-buffer)
2731             (gnus-group-jump-to-group group)
2732             (gnus-group-next-unread-group 1)
2733             (gnus-configure-windows 'group 'force))
2734         (gnus-handle-ephemeral-exit quit-config))
2735       ;; Finally signal the quit.
2736       (signal 'quit nil))
2737      ;; The group was successfully selected.
2738      (t
2739       (gnus-set-global-variables)
2740       ;; Save the active value in effect when the group was entered.
2741       (setq gnus-newsgroup-active
2742             (gnus-copy-sequence
2743              (gnus-active gnus-newsgroup-name)))
2744       ;; You can change the summary buffer in some way with this hook.
2745       (gnus-run-hooks 'gnus-select-group-hook)
2746       ;; Set any local variables in the group parameters.
2747       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2748       (gnus-update-format-specifications
2749        nil 'summary 'summary-mode 'summary-dummy)
2750       ;; Do score processing.
2751       (when gnus-use-scoring
2752         (gnus-possibly-score-headers))
2753       ;; Check whether to fill in the gaps in the threads.
2754       (when gnus-build-sparse-threads
2755         (gnus-build-sparse-threads))
2756       ;; Find the initial limit.
2757       (if gnus-show-threads
2758           (if show-all
2759               (let ((gnus-newsgroup-dormant nil))
2760                 (gnus-summary-initial-limit show-all))
2761             (gnus-summary-initial-limit show-all))
2762         (setq gnus-newsgroup-limit
2763               (mapcar
2764                (lambda (header) (mail-header-number header))
2765                gnus-newsgroup-headers)))
2766       ;; Generate the summary buffer.
2767       (unless no-display
2768         (gnus-summary-prepare))
2769       (when gnus-use-trees
2770         (gnus-tree-open group)
2771         (setq gnus-summary-highlight-line-function
2772               'gnus-tree-highlight-article))
2773       ;; If the summary buffer is empty, but there are some low-scored
2774       ;; articles or some excluded dormants, we include these in the
2775       ;; buffer.
2776       (when (and (zerop (buffer-size))
2777                  (not no-display))
2778         (cond (gnus-newsgroup-dormant
2779                (gnus-summary-limit-include-dormant))
2780               ((and gnus-newsgroup-scored show-all)
2781                (gnus-summary-limit-include-expunged t))))
2782       ;; Function `gnus-apply-kill-file' must be called in this hook.
2783       (gnus-run-hooks 'gnus-apply-kill-hook)
2784       (if (and (zerop (buffer-size))
2785                (not no-display))
2786           (progn
2787             ;; This newsgroup is empty.
2788             (gnus-summary-catchup-and-exit nil t)
2789             (gnus-message 6 "No unread news")
2790             (when kill-buffer
2791               (gnus-kill-or-deaden-summary kill-buffer))
2792             ;; Return nil from this function.
2793             nil)
2794         ;; Hide conversation thread subtrees.  We cannot do this in
2795         ;; gnus-summary-prepare-hook since kill processing may not
2796         ;; work with hidden articles.
2797         (and gnus-show-threads
2798              gnus-thread-hide-subtree
2799              (gnus-summary-hide-all-threads))
2800         (when kill-buffer
2801           (gnus-kill-or-deaden-summary kill-buffer))
2802         ;; Show first unread article if requested.
2803         (if (and (not no-article)
2804                  (not no-display)
2805                  gnus-newsgroup-unreads
2806                  gnus-auto-select-first)
2807             (progn
2808               (gnus-configure-windows 'summary)
2809               (cond
2810                ((eq gnus-auto-select-first 'best)
2811                 (gnus-summary-best-unread-article))
2812                ((eq gnus-auto-select-first t)
2813                 (gnus-summary-first-unread-article))
2814                ((gnus-functionp gnus-auto-select-first)
2815                 (funcall gnus-auto-select-first))))
2816           ;; Don't select any articles, just move point to the first
2817           ;; article in the group.
2818           (goto-char (point-min))
2819           (gnus-summary-position-point)
2820           (gnus-configure-windows 'summary 'force)
2821           (gnus-set-mode-line 'summary))
2822         (when (get-buffer-window gnus-group-buffer t)
2823           ;; Gotta use windows, because recenter does weird stuff if
2824           ;; the current buffer ain't the displayed window.
2825           (let ((owin (selected-window)))
2826             (select-window (get-buffer-window gnus-group-buffer t))
2827             (when (gnus-group-goto-group group)
2828               (recenter))
2829             (select-window owin)))
2830         ;; Mark this buffer as "prepared".
2831         (setq gnus-newsgroup-prepared t)
2832         (gnus-run-hooks 'gnus-summary-prepared-hook)
2833         t)))))
2834
2835 (defun gnus-summary-prepare ()
2836   "Generate the summary buffer."
2837   (interactive)
2838   (let ((buffer-read-only nil))
2839     (erase-buffer)
2840     (setq gnus-newsgroup-data nil
2841           gnus-newsgroup-data-reverse nil)
2842     (gnus-run-hooks 'gnus-summary-generate-hook)
2843     ;; Generate the buffer, either with threads or without.
2844     (when gnus-newsgroup-headers
2845       (gnus-summary-prepare-threads
2846        (if gnus-show-threads
2847            (gnus-sort-gathered-threads
2848             (funcall gnus-summary-thread-gathering-function
2849                      (gnus-sort-threads
2850                       (gnus-cut-threads (gnus-make-threads)))))
2851          ;; Unthreaded display.
2852          (gnus-sort-articles gnus-newsgroup-headers))))
2853     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
2854     ;; Call hooks for modifying summary buffer.
2855     (goto-char (point-min))
2856     (gnus-run-hooks 'gnus-summary-prepare-hook)))
2857
2858 (defsubst gnus-general-simplify-subject (subject)
2859   "Simply subject by the same rules as gnus-gather-threads-by-subject."
2860   (setq subject
2861         (cond
2862          ;; Truncate the subject.
2863          (gnus-simplify-subject-functions
2864           (gnus-map-function gnus-simplify-subject-functions subject))
2865          ((numberp gnus-summary-gather-subject-limit)
2866           (setq subject (gnus-simplify-subject-re subject))
2867           (if (> (length subject) gnus-summary-gather-subject-limit)
2868               (substring subject 0 gnus-summary-gather-subject-limit)
2869             subject))
2870          ;; Fuzzily simplify it.
2871          ((eq 'fuzzy gnus-summary-gather-subject-limit)
2872           (gnus-simplify-subject-fuzzy subject))
2873          ;; Just remove the leading "Re:".
2874          (t
2875           (gnus-simplify-subject-re subject))))
2876
2877   (if (and gnus-summary-gather-exclude-subject
2878            (string-match gnus-summary-gather-exclude-subject subject))
2879       nil                               ; This article shouldn't be gathered
2880     subject))
2881
2882 (defun gnus-summary-simplify-subject-query ()
2883   "Query where the respool algorithm would put this article."
2884   (interactive)
2885   (gnus-summary-select-article)
2886   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
2887
2888 (defun gnus-gather-threads-by-subject (threads)
2889   "Gather threads by looking at Subject headers."
2890   (if (not gnus-summary-make-false-root)
2891       threads
2892     (let ((hashtb (gnus-make-hashtable 1024))
2893           (prev threads)
2894           (result threads)
2895           subject hthread whole-subject)
2896       (while threads
2897         (setq subject (gnus-general-simplify-subject
2898                        (setq whole-subject (mail-header-subject
2899                                             (caar threads)))))
2900         (when subject
2901           (if (setq hthread (gnus-gethash subject hashtb))
2902               (progn
2903                 ;; We enter a dummy root into the thread, if we
2904                 ;; haven't done that already.
2905                 (unless (stringp (caar hthread))
2906                   (setcar hthread (list whole-subject (car hthread))))
2907                 ;; We add this new gathered thread to this gathered
2908                 ;; thread.
2909                 (setcdr (car hthread)
2910                         (nconc (cdar hthread) (list (car threads))))
2911                 ;; Remove it from the list of threads.
2912                 (setcdr prev (cdr threads))
2913                 (setq threads prev))
2914             ;; Enter this thread into the hash table.
2915             (gnus-sethash subject threads hashtb)))
2916         (setq prev threads)
2917         (setq threads (cdr threads)))
2918       result)))
2919
2920 (defun gnus-gather-threads-by-references (threads)
2921   "Gather threads by looking at References headers."
2922   (let ((idhashtb (gnus-make-hashtable 1024))
2923         (thhashtb (gnus-make-hashtable 1024))
2924         (prev threads)
2925         (result threads)
2926         ids references id gthread gid entered ref)
2927     (while threads
2928       (when (setq references (mail-header-references (caar threads)))
2929         (setq id (mail-header-id (caar threads))
2930               ids (gnus-split-references references)
2931               entered nil)
2932         (while (setq ref (pop ids))
2933           (setq ids (delete ref ids))
2934           (if (not (setq gid (gnus-gethash ref idhashtb)))
2935               (progn
2936                 (gnus-sethash ref id idhashtb)
2937                 (gnus-sethash id threads thhashtb))
2938             (setq gthread (gnus-gethash gid thhashtb))
2939             (unless entered
2940               ;; We enter a dummy root into the thread, if we
2941               ;; haven't done that already.
2942               (unless (stringp (caar gthread))
2943                 (setcar gthread (list (mail-header-subject (caar gthread))
2944                                       (car gthread))))
2945               ;; We add this new gathered thread to this gathered
2946               ;; thread.
2947               (setcdr (car gthread)
2948                       (nconc (cdar gthread) (list (car threads)))))
2949             ;; Add it into the thread hash table.
2950             (gnus-sethash id gthread thhashtb)
2951             (setq entered t)
2952             ;; Remove it from the list of threads.
2953             (setcdr prev (cdr threads))
2954             (setq threads prev))))
2955       (setq prev threads)
2956       (setq threads (cdr threads)))
2957     result))
2958
2959 (defun gnus-sort-gathered-threads (threads)
2960   "Sort subtreads inside each gathered thread by article number."
2961   (let ((result threads))
2962     (while threads
2963       (when (stringp (caar threads))
2964         (setcdr (car threads)
2965                 (sort (cdar threads) 'gnus-thread-sort-by-number)))
2966       (setq threads (cdr threads)))
2967     result))
2968
2969 (defun gnus-thread-loop-p (root thread)
2970   "Say whether ROOT is in THREAD."
2971   (let ((stack (list thread))
2972         (infloop 0)
2973         th)
2974     (while (setq thread (pop stack))
2975       (setq th (cdr thread))
2976       (while (and th
2977                   (not (eq (caar th) root)))
2978         (pop th))
2979       (if th
2980           ;; We have found a loop.
2981           (let (ref-dep)
2982             (setcdr thread (delq (car th) (cdr thread)))
2983             (if (boundp (setq ref-dep (intern "none"
2984                                               gnus-newsgroup-dependencies)))
2985                 (setcdr (symbol-value ref-dep)
2986                         (nconc (cdr (symbol-value ref-dep))
2987                                (list (car th))))
2988               (set ref-dep (list nil (car th))))
2989             (setq infloop 1
2990                   stack nil))
2991         ;; Push all the subthreads onto the stack.
2992         (push (cdr thread) stack)))
2993     infloop))
2994
2995 (defun gnus-make-threads ()
2996   "Go through the dependency hashtb and find the roots.  Return all threads."
2997   (let (threads)
2998     (while (catch 'infloop
2999              (mapatoms
3000               (lambda (refs)
3001                 ;; Deal with self-referencing References loops.
3002                 (when (and (car (symbol-value refs))
3003                            (not (zerop
3004                                  (apply
3005                                   '+
3006                                   (mapcar
3007                                    (lambda (thread)
3008                                      (gnus-thread-loop-p
3009                                       (car (symbol-value refs)) thread))
3010                                    (cdr (symbol-value refs)))))))
3011                   (setq threads nil)
3012                   (throw 'infloop t))
3013                 (unless (car (symbol-value refs))
3014                   ;; These threads do not refer back to any other articles,
3015                   ;; so they're roots.
3016                   (setq threads (append (cdr (symbol-value refs)) threads))))
3017               gnus-newsgroup-dependencies)))
3018     threads))
3019
3020 ;; Build the thread tree.
3021 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3022   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3023
3024 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3025 if it was already present.
3026
3027 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3028 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3029 Message-IDs will be renamed be renamed to a unique Message-ID before
3030 being entered.
3031
3032 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3033   (let* ((id (mail-header-id header))
3034          (id-dep (and id (intern id dependencies)))
3035          ref ref-dep ref-header)
3036     ;; Enter this `header' in the `dependencies' table.
3037     (cond
3038      ((not id-dep)
3039       (setq header nil))
3040      ;; The first two cases do the normal part: enter a new `header'
3041      ;; in the `dependencies' table.
3042      ((not (boundp id-dep))
3043       (set id-dep (list header)))
3044      ((null (car (symbol-value id-dep)))
3045       (setcar (symbol-value id-dep) header))
3046
3047      ;; From here the `header' was already present in the
3048      ;; `dependencies' table.
3049      (force-new
3050       ;; Overrides an existing entry;
3051       ;; just set the header part of the entry.
3052       (setcar (symbol-value id-dep) header))
3053
3054      ;; Renames the existing `header' to a unique Message-ID.
3055      ((not gnus-summary-ignore-duplicates)
3056       ;; An article with this Message-ID has already been seen.
3057       ;; We rename the Message-ID.
3058       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3059            (list header))
3060       (mail-header-set-id header id))
3061
3062      ;; The last case ignores an existing entry, except it adds any
3063      ;; additional Xrefs (in case the two articles came from different
3064      ;; servers.
3065      ;; Also sets `header' to `nil' meaning that the `dependencies'
3066      ;; table was *not* modified.
3067      (t
3068       (mail-header-set-xref
3069        (car (symbol-value id-dep))
3070        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3071                    "")
3072                (or (mail-header-xref header) "")))
3073       (setq header nil)))
3074
3075     (when header
3076       ;; First check if that we are not creating a References loop.
3077       (setq ref (gnus-parent-id (mail-header-references header)))
3078       (while (and ref
3079                   (setq ref-dep (intern-soft ref dependencies))
3080                   (boundp ref-dep)
3081                   (setq ref-header (car (symbol-value ref-dep))))
3082         (if (string= id ref)
3083             ;; Yuk!  This is a reference loop.  Make the article be a
3084             ;; root article.
3085             (progn
3086               (mail-header-set-references (car (symbol-value id-dep)) "none")
3087               (setq ref nil))
3088           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3089       (setq ref (gnus-parent-id (mail-header-references header)))
3090       (setq ref-dep (intern (or ref "none") dependencies))
3091       (if (boundp ref-dep)
3092           (setcdr (symbol-value ref-dep)
3093                   (nconc (cdr (symbol-value ref-dep))
3094                          (list (symbol-value id-dep))))
3095         (set ref-dep (list nil (symbol-value id-dep)))))
3096     header))
3097
3098 (defun gnus-build-sparse-threads ()
3099   (let ((headers gnus-newsgroup-headers)
3100         (gnus-summary-ignore-duplicates t)
3101         header references generation relations
3102         subject child end new-child date)
3103     ;; First we create an alist of generations/relations, where
3104     ;; generations is how much we trust the relation, and the relation
3105     ;; is parent/child.
3106     (gnus-message 7 "Making sparse threads...")
3107     (save-excursion
3108       (nnheader-set-temp-buffer " *gnus sparse threads*")
3109       (while (setq header (pop headers))
3110         (when (and (setq references (mail-header-references header))
3111                    (not (string= references "")))
3112           (insert references)
3113           (setq child (mail-header-id header)
3114                 subject (mail-header-subject header)
3115                 date (mail-header-date header)
3116                 generation 0)
3117           (while (search-backward ">" nil t)
3118             (setq end (1+ (point)))
3119             (when (search-backward "<" nil t)
3120               (setq new-child (buffer-substring (point) end))
3121               (push (list (incf generation)
3122                           child (setq child new-child)
3123                           subject date)
3124                     relations)))
3125           (when child
3126             (push (list (1+ generation) child nil subject) relations))
3127           (erase-buffer)))
3128       (kill-buffer (current-buffer)))
3129     ;; Sort over trustworthiness.
3130     (mapcar
3131      (lambda (relation)
3132        (when (gnus-dependencies-add-header
3133               (make-full-mail-header
3134                gnus-reffed-article-number
3135                (nth 3 relation) "" (or (nth 4 relation) "")
3136                (nth 1 relation)
3137                (or (nth 2 relation) "") 0 0 "")
3138               gnus-newsgroup-dependencies nil)
3139          (push gnus-reffed-article-number gnus-newsgroup-limit)
3140          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3141          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3142                gnus-newsgroup-reads)
3143          (decf gnus-reffed-article-number)))
3144      (sort relations 'car-less-than-car))
3145     (gnus-message 7 "Making sparse threads...done")))
3146
3147 (defun gnus-build-old-threads ()
3148   ;; Look at all the articles that refer back to old articles, and
3149   ;; fetch the headers for the articles that aren't there.  This will
3150   ;; build complete threads - if the roots haven't been expired by the
3151   ;; server, that is.
3152   (let (id heads)
3153     (mapatoms
3154      (lambda (refs)
3155        (when (not (car (symbol-value refs)))
3156          (setq heads (cdr (symbol-value refs)))
3157          (while heads
3158            (if (memq (mail-header-number (caar heads))
3159                      gnus-newsgroup-dormant)
3160                (setq heads (cdr heads))
3161              (setq id (symbol-name refs))
3162              (while (and (setq id (gnus-build-get-header id))
3163                          (not (car (gnus-id-to-thread id)))))
3164              (setq heads nil)))))
3165      gnus-newsgroup-dependencies)))
3166
3167 (defmacro gnus-nov-read-integer ()
3168   '(prog1
3169        (if (eq (char-after) ?\t)
3170            0
3171          (let ((num (ignore-errors (read buffer))))
3172            (if (numberp num) num 0)))
3173      (unless (eobp)
3174        (search-forward "\t" eol 'move))))
3175
3176 (defmacro gnus-nov-skip-field ()
3177   '(search-forward "\t" eol 'move))
3178
3179 (defmacro gnus-nov-field ()
3180   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
3181
3182 (defmacro gnus-nov-parse-extra ()
3183   '(let (out string)
3184      (while (not (memq (char-after) '(?\n nil)))
3185        (setq string (gnus-nov-field))
3186        (when (string-match "^\\([^ :]+\\): " string)
3187          (push (cons (intern (match-string 1 string))
3188                      (substring string (match-end 0)))
3189                out)))
3190      out))
3191
3192 ;; This function has to be called with point after the article number
3193 ;; on the beginning of the line.
3194 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3195   (let ((eol (gnus-point-at-eol))
3196         (buffer (current-buffer))
3197         header)
3198
3199     ;; overview: [num subject from date id refs chars lines misc]
3200     (unwind-protect
3201         (progn
3202           (narrow-to-region (point) eol)
3203           (unless (eobp)
3204             (forward-char))
3205
3206           (setq header
3207                 (make-full-mail-header
3208                  number                 ; number
3209                  (funcall gnus-decode-encoded-word-function
3210                           (gnus-nov-field)) ; subject
3211                  (funcall gnus-decode-encoded-word-function
3212                           (gnus-nov-field)) ; from
3213                  (gnus-nov-field)       ; date
3214                  (or (gnus-nov-field)
3215                      (nnheader-generate-fake-message-id)) ; id
3216                  (gnus-nov-field)       ; refs
3217                  (gnus-nov-read-integer) ; chars
3218                  (gnus-nov-read-integer) ; lines
3219                  (unless (eq (char-after) ?\n)
3220                    (gnus-nov-field))    ; misc
3221                  (gnus-nov-parse-extra)))) ; extra
3222
3223       (widen))
3224
3225     (when gnus-alter-header-function
3226       (funcall gnus-alter-header-function header))
3227     (gnus-dependencies-add-header header dependencies force-new)))
3228
3229 (defun gnus-build-get-header (id)
3230   ;; Look through the buffer of NOV lines and find the header to
3231   ;; ID.  Enter this line into the dependencies hash table, and return
3232   ;; the id of the parent article (if any).
3233   (let ((deps gnus-newsgroup-dependencies)
3234         found header)
3235     (prog1
3236         (save-excursion
3237           (set-buffer nntp-server-buffer)
3238           (let ((case-fold-search nil))
3239             (goto-char (point-min))
3240             (while (and (not found)
3241                         (search-forward id nil t))
3242               (beginning-of-line)
3243               (setq found (looking-at
3244                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3245                                    (regexp-quote id))))
3246               (or found (beginning-of-line 2)))
3247             (when found
3248               (beginning-of-line)
3249               (and
3250                (setq header (gnus-nov-parse-line
3251                              (read (current-buffer)) deps))
3252                (gnus-parent-id (mail-header-references header))))))
3253       (when header
3254         (let ((number (mail-header-number header)))
3255           (push number gnus-newsgroup-limit)
3256           (push header gnus-newsgroup-headers)
3257           (if (memq number gnus-newsgroup-unselected)
3258               (progn
3259                 (push number gnus-newsgroup-unreads)
3260                 (setq gnus-newsgroup-unselected
3261                       (delq number gnus-newsgroup-unselected)))
3262             (push number gnus-newsgroup-ancient)))))))
3263
3264 (defun gnus-build-all-threads ()
3265   "Read all the headers."
3266   (let ((gnus-summary-ignore-duplicates t)
3267         (dependencies gnus-newsgroup-dependencies)
3268         header article)
3269     (save-excursion
3270       (set-buffer nntp-server-buffer)
3271       (let ((case-fold-search nil))
3272         (goto-char (point-min))
3273         (while (not (eobp))
3274           (ignore-errors
3275             (setq article (read (current-buffer))
3276                   header (gnus-nov-parse-line
3277                           article dependencies)))
3278           (when header
3279             (save-excursion
3280               (set-buffer gnus-summary-buffer)
3281               (push header gnus-newsgroup-headers)
3282               (if (memq (setq article (mail-header-number header))
3283                         gnus-newsgroup-unselected)
3284                   (progn
3285                     (push article gnus-newsgroup-unreads)
3286                     (setq gnus-newsgroup-unselected
3287                           (delq article gnus-newsgroup-unselected)))
3288                 (push article gnus-newsgroup-ancient)))
3289             (forward-line 1)))))))
3290
3291 (defun gnus-summary-update-article-line (article header)
3292   "Update the line for ARTICLE using HEADERS."
3293   (let* ((id (mail-header-id header))
3294          (thread (gnus-id-to-thread id)))
3295     (unless thread
3296       (error "Article in no thread"))
3297     ;; Update the thread.
3298     (setcar thread header)
3299     (gnus-summary-goto-subject article)
3300     (let* ((datal (gnus-data-find-list article))
3301            (data (car datal))
3302            (length (when (cdr datal)
3303                      (- (gnus-data-pos data)
3304                         (gnus-data-pos (cadr datal)))))
3305            (buffer-read-only nil)
3306            (level (gnus-summary-thread-level)))
3307       (gnus-delete-line)
3308       (gnus-summary-insert-line
3309        header level nil (gnus-article-mark article)
3310        (memq article gnus-newsgroup-replied)
3311        (memq article gnus-newsgroup-expirable)
3312        ;; Only insert the Subject string when it's different
3313        ;; from the previous Subject string.
3314        (if (gnus-subject-equal
3315             (condition-case ()
3316                 (mail-header-subject
3317                  (gnus-data-header
3318                   (cadr
3319                    (gnus-data-find-list
3320                     article
3321                     (gnus-data-list t)))))
3322               ;; Error on the side of excessive subjects.
3323               (error ""))
3324             (mail-header-subject header))
3325            ""
3326          (mail-header-subject header))
3327        nil (cdr (assq article gnus-newsgroup-scored))
3328        (memq article gnus-newsgroup-processable))
3329       (when length
3330         (gnus-data-update-list
3331          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3332
3333 (defun gnus-summary-update-article (article &optional iheader)
3334   "Update ARTICLE in the summary buffer."
3335   (set-buffer gnus-summary-buffer)
3336   (let* ((header (gnus-summary-article-header article))
3337          (id (mail-header-id header))
3338          (data (gnus-data-find article))
3339          (thread (gnus-id-to-thread id))
3340          (references (mail-header-references header))
3341          (parent
3342           (gnus-id-to-thread
3343            (or (gnus-parent-id
3344                 (when (and references
3345                            (not (equal "" references)))
3346                   references))
3347                "none")))
3348          (buffer-read-only nil)
3349          (old (car thread)))
3350     (when thread
3351       (unless iheader
3352         (setcar thread nil)
3353         (when parent
3354           (delq thread parent)))
3355       (if (gnus-summary-insert-subject id header)
3356           ;; Set the (possibly) new article number in the data structure.
3357           (gnus-data-set-number data (gnus-id-to-article id))
3358         (setcar thread old)
3359         nil))))
3360
3361 (defun gnus-rebuild-thread (id &optional line)
3362   "Rebuild the thread containing ID.
3363 If LINE, insert the rebuilt thread starting on line LINE."
3364   (let ((buffer-read-only nil)
3365         old-pos current thread data)
3366     (if (not gnus-show-threads)
3367         (setq thread (list (car (gnus-id-to-thread id))))
3368       ;; Get the thread this article is part of.
3369       (setq thread (gnus-remove-thread id)))
3370     (setq old-pos (gnus-point-at-bol))
3371     (setq current (save-excursion
3372                     (and (zerop (forward-line -1))
3373                          (gnus-summary-article-number))))
3374     ;; If this is a gathered thread, we have to go some re-gathering.
3375     (when (stringp (car thread))
3376       (let ((subject (car thread))
3377             roots thr)
3378         (setq thread (cdr thread))
3379         (while thread
3380           (unless (memq (setq thr (gnus-id-to-thread
3381                                    (gnus-root-id
3382                                     (mail-header-id (caar thread)))))
3383                         roots)
3384             (push thr roots))
3385           (setq thread (cdr thread)))
3386         ;; We now have all (unique) roots.
3387         (if (= (length roots) 1)
3388             ;; All the loose roots are now one solid root.
3389             (setq thread (car roots))
3390           (setq thread (cons subject (gnus-sort-threads roots))))))
3391     (let (threads)
3392       ;; We then insert this thread into the summary buffer.
3393       (when line
3394         (goto-char (point-min))
3395         (forward-line (1- line)))
3396       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3397         (if gnus-show-threads
3398             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3399           (gnus-summary-prepare-unthreaded thread))
3400         (setq data (nreverse gnus-newsgroup-data))
3401         (setq threads gnus-newsgroup-threads))
3402       ;; We splice the new data into the data structure.
3403       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3404       ;;!!! then we want to insert at the beginning of the buffer.
3405       ;;!!! That happens to be true with Gnus now, but that may
3406       ;;!!! change in the future.  Perhaps.
3407       (gnus-data-enter-list
3408        (if line nil current) data (- (point) old-pos))
3409       (setq gnus-newsgroup-threads
3410             (nconc threads gnus-newsgroup-threads))
3411       (gnus-data-compute-positions))))
3412
3413 (defun gnus-number-to-header (number)
3414   "Return the header for article NUMBER."
3415   (let ((headers gnus-newsgroup-headers))
3416     (while (and headers
3417                 (not (= number (mail-header-number (car headers)))))
3418       (pop headers))
3419     (when headers
3420       (car headers))))
3421
3422 (defun gnus-parent-headers (in-headers &optional generation)
3423   "Return the headers of the GENERATIONeth parent of HEADERS."
3424   (unless generation
3425     (setq generation 1))
3426   (let ((parent t)
3427         (headers in-headers)
3428         references)
3429     (while (and parent
3430                 (not (zerop generation))
3431                 (setq references (mail-header-references headers)))
3432       (setq headers (if (and references
3433                              (setq parent (gnus-parent-id references)))
3434                         (car (gnus-id-to-thread parent))
3435                       nil))
3436       (decf generation))
3437     (and (not (eq headers in-headers))
3438          headers)))
3439
3440 (defun gnus-id-to-thread (id)
3441   "Return the (sub-)thread where ID appears."
3442   (gnus-gethash id gnus-newsgroup-dependencies))
3443
3444 (defun gnus-id-to-article (id)
3445   "Return the article number of ID."
3446   (let ((thread (gnus-id-to-thread id)))
3447     (when (and thread
3448                (car thread))
3449       (mail-header-number (car thread)))))
3450
3451 (defun gnus-id-to-header (id)
3452   "Return the article headers of ID."
3453   (car (gnus-id-to-thread id)))
3454
3455 (defun gnus-article-displayed-root-p (article)
3456   "Say whether ARTICLE is a root(ish) article."
3457   (let ((level (gnus-summary-thread-level article))
3458         (refs (mail-header-references  (gnus-summary-article-header article)))
3459         particle)
3460     (cond
3461      ((null level) nil)
3462      ((zerop level) t)
3463      ((null refs) t)
3464      ((null (gnus-parent-id refs)) t)
3465      ((and (= 1 level)
3466            (null (setq particle (gnus-id-to-article
3467                                  (gnus-parent-id refs))))
3468            (null (gnus-summary-thread-level particle)))))))
3469
3470 (defun gnus-root-id (id)
3471   "Return the id of the root of the thread where ID appears."
3472   (let (last-id prev)
3473     (while (and id (setq prev (car (gnus-id-to-thread id))))
3474       (setq last-id id
3475             id (gnus-parent-id (mail-header-references prev))))
3476     last-id))
3477
3478 (defun gnus-articles-in-thread (thread)
3479   "Return the list of articles in THREAD."
3480   (cons (mail-header-number (car thread))
3481         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3482
3483 (defun gnus-remove-thread (id &optional dont-remove)
3484   "Remove the thread that has ID in it."
3485   (let (headers thread last-id)
3486     ;; First go up in this thread until we find the root.
3487     (setq last-id (gnus-root-id id)
3488           headers (message-flatten-list (gnus-id-to-thread last-id)))
3489     ;; We have now found the real root of this thread.  It might have
3490     ;; been gathered into some loose thread, so we have to search
3491     ;; through the threads to find the thread we wanted.
3492     (let ((threads gnus-newsgroup-threads)
3493           sub)
3494       (while threads
3495         (setq sub (car threads))
3496         (if (stringp (car sub))
3497             ;; This is a gathered thread, so we look at the roots
3498             ;; below it to find whether this article is in this
3499             ;; gathered root.
3500             (progn
3501               (setq sub (cdr sub))
3502               (while sub
3503                 (when (member (caar sub) headers)
3504                   (setq thread (car threads)
3505                         threads nil
3506                         sub nil))
3507                 (setq sub (cdr sub))))
3508           ;; It's an ordinary thread, so we check it.
3509           (when (eq (car sub) (car headers))
3510             (setq thread sub
3511                   threads nil)))
3512         (setq threads (cdr threads)))
3513       ;; If this article is in no thread, then it's a root.
3514       (if thread
3515           (unless dont-remove
3516             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3517         (setq thread (gnus-id-to-thread last-id)))
3518       (when thread
3519         (prog1
3520             thread                      ; We return this thread.
3521           (unless dont-remove
3522             (if (stringp (car thread))
3523                 (progn
3524                   ;; If we use dummy roots, then we have to remove the
3525                   ;; dummy root as well.
3526                   (when (eq gnus-summary-make-false-root 'dummy)
3527                     ;; We go to the dummy root by going to
3528                     ;; the first sub-"thread", and then one line up.
3529                     (gnus-summary-goto-article
3530                      (mail-header-number (caadr thread)))
3531                     (forward-line -1)
3532                     (gnus-delete-line)
3533                     (gnus-data-compute-positions))
3534                   (setq thread (cdr thread))
3535                   (while thread
3536                     (gnus-remove-thread-1 (car thread))
3537                     (setq thread (cdr thread))))
3538               (gnus-summary-show-all-threads)
3539               (gnus-remove-thread-1 thread))))))))
3540
3541 (defun gnus-remove-thread-1 (thread)
3542   "Remove the thread THREAD recursively."
3543   (let ((number (mail-header-number (pop thread)))
3544         d)
3545     (setq thread (reverse thread))
3546     (while thread
3547       (gnus-remove-thread-1 (pop thread)))
3548     (when (setq d (gnus-data-find number))
3549       (goto-char (gnus-data-pos d))
3550       (gnus-data-remove
3551        number
3552        (- (gnus-point-at-bol)
3553           (prog1
3554               (1+ (gnus-point-at-eol))
3555             (gnus-delete-line)))))))
3556
3557 (defun gnus-sort-threads (threads)
3558   "Sort THREADS."
3559   (if (not gnus-thread-sort-functions)
3560       threads
3561     (gnus-message 8 "Sorting threads...")
3562     (prog1
3563         (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
3564       (gnus-message 8 "Sorting threads...done"))))
3565
3566 (defun gnus-sort-articles (articles)
3567   "Sort ARTICLES."
3568   (when gnus-article-sort-functions
3569     (gnus-message 7 "Sorting articles...")
3570     (prog1
3571         (setq gnus-newsgroup-headers
3572               (sort articles (gnus-make-sort-function
3573                               gnus-article-sort-functions)))
3574       (gnus-message 7 "Sorting articles...done"))))
3575
3576 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3577 (defmacro gnus-thread-header (thread)
3578   ;; Return header of first article in THREAD.
3579   ;; Note that THREAD must never, ever be anything else than a variable -
3580   ;; using some other form will lead to serious barfage.
3581   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3582   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3583   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
3584         (vector thread) 2))
3585
3586 (defsubst gnus-article-sort-by-number (h1 h2)
3587   "Sort articles by article number."
3588   (< (mail-header-number h1)
3589      (mail-header-number h2)))
3590
3591 (defun gnus-thread-sort-by-number (h1 h2)
3592   "Sort threads by root article number."
3593   (gnus-article-sort-by-number
3594    (gnus-thread-header h1) (gnus-thread-header h2)))
3595
3596 (defsubst gnus-article-sort-by-lines (h1 h2)
3597   "Sort articles by article Lines header."
3598   (< (mail-header-lines h1)
3599      (mail-header-lines h2)))
3600
3601 (defun gnus-thread-sort-by-lines (h1 h2)
3602   "Sort threads by root article Lines header."
3603   (gnus-article-sort-by-lines
3604    (gnus-thread-header h1) (gnus-thread-header h2)))
3605
3606 (defsubst gnus-article-sort-by-author (h1 h2)
3607   "Sort articles by root author."
3608   (string-lessp
3609    (let ((extract (funcall
3610                    gnus-extract-address-components
3611                    (mail-header-from h1))))
3612      (or (car extract) (cadr extract) ""))
3613    (let ((extract (funcall
3614                    gnus-extract-address-components
3615                    (mail-header-from h2))))
3616      (or (car extract) (cadr extract) ""))))
3617
3618 (defun gnus-thread-sort-by-author (h1 h2)
3619   "Sort threads by root author."
3620   (gnus-article-sort-by-author
3621    (gnus-thread-header h1)  (gnus-thread-header h2)))
3622
3623 (defsubst gnus-article-sort-by-subject (h1 h2)
3624   "Sort articles by root subject."
3625   (string-lessp
3626    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3627    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3628
3629 (defun gnus-thread-sort-by-subject (h1 h2)
3630   "Sort threads by root subject."
3631   (gnus-article-sort-by-subject
3632    (gnus-thread-header h1) (gnus-thread-header h2)))
3633
3634 (defsubst gnus-article-sort-by-date (h1 h2)
3635   "Sort articles by root article date."
3636   (time-less-p
3637    (gnus-date-get-time (mail-header-date h1))
3638    (gnus-date-get-time (mail-header-date h2))))
3639
3640 (defun gnus-thread-sort-by-date (h1 h2)
3641   "Sort threads by root article date."
3642   (gnus-article-sort-by-date
3643    (gnus-thread-header h1) (gnus-thread-header h2)))
3644
3645 (defsubst gnus-article-sort-by-score (h1 h2)
3646   "Sort articles by root article score.
3647 Unscored articles will be counted as having a score of zero."
3648   (> (or (cdr (assq (mail-header-number h1)
3649                     gnus-newsgroup-scored))
3650          gnus-summary-default-score 0)
3651      (or (cdr (assq (mail-header-number h2)
3652                     gnus-newsgroup-scored))
3653          gnus-summary-default-score 0)))
3654
3655 (defun gnus-thread-sort-by-score (h1 h2)
3656   "Sort threads by root article score."
3657   (gnus-article-sort-by-score
3658    (gnus-thread-header h1) (gnus-thread-header h2)))
3659
3660 (defun gnus-thread-sort-by-total-score (h1 h2)
3661   "Sort threads by the sum of all scores in the thread.
3662 Unscored articles will be counted as having a score of zero."
3663   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3664
3665 (defun gnus-thread-total-score (thread)
3666   ;;  This function find the total score of THREAD.
3667   (cond ((null thread)
3668          0)
3669         ((consp thread)
3670          (if (stringp (car thread))
3671              (apply gnus-thread-score-function 0
3672                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3673            (gnus-thread-total-score-1 thread)))
3674         (t
3675          (gnus-thread-total-score-1 (list thread)))))
3676
3677 (defun gnus-thread-total-score-1 (root)
3678   ;; This function find the total score of the thread below ROOT.
3679   (setq root (car root))
3680   (apply gnus-thread-score-function
3681          (or (append
3682               (mapcar 'gnus-thread-total-score
3683                       (cdr (gnus-id-to-thread (mail-header-id root))))
3684               (when (> (mail-header-number root) 0)
3685                 (list (or (cdr (assq (mail-header-number root)
3686                                      gnus-newsgroup-scored))
3687                           gnus-summary-default-score 0))))
3688              (list gnus-summary-default-score)
3689              '(0))))
3690
3691 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3692 (defvar gnus-tmp-prev-subject nil)
3693 (defvar gnus-tmp-false-parent nil)
3694 (defvar gnus-tmp-root-expunged nil)
3695 (defvar gnus-tmp-dummy-line nil)
3696
3697 (defvar gnus-tmp-header)
3698 (defun gnus-extra-header (type &optional header)
3699   "Return the extra header of TYPE."
3700   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3701       ""))
3702
3703 (defun gnus-summary-prepare-threads (threads)
3704   "Prepare summary buffer from THREADS and indentation LEVEL.
3705 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3706 or a straight list of headers."
3707   (gnus-message 7 "Generating summary...")
3708
3709   (setq gnus-newsgroup-threads threads)
3710   (beginning-of-line)
3711
3712   (let ((gnus-tmp-level 0)
3713         (default-score (or gnus-summary-default-score 0))
3714         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3715         thread number subject stack state gnus-tmp-gathered beg-match
3716         new-roots gnus-tmp-new-adopts thread-end
3717         gnus-tmp-header gnus-tmp-unread
3718         gnus-tmp-replied gnus-tmp-subject-or-nil
3719         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3720         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3721         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3722
3723     (setq gnus-tmp-prev-subject nil)
3724
3725     (if (vectorp (car threads))
3726         ;; If this is a straight (sic) list of headers, then a
3727         ;; threaded summary display isn't required, so we just create
3728         ;; an unthreaded one.
3729         (gnus-summary-prepare-unthreaded threads)
3730
3731       ;; Do the threaded display.
3732
3733       (while (or threads stack gnus-tmp-new-adopts new-roots)
3734
3735         (if (and (= gnus-tmp-level 0)
3736                  (or (not stack)
3737                      (= (caar stack) 0))
3738                  (not gnus-tmp-false-parent)
3739                  (or gnus-tmp-new-adopts new-roots))
3740             (if gnus-tmp-new-adopts
3741                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3742                       thread (list (car gnus-tmp-new-adopts))
3743                       gnus-tmp-header (caar thread)
3744                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3745               (when new-roots
3746                 (setq thread (list (car new-roots))
3747                       gnus-tmp-header (caar thread)
3748                       new-roots (cdr new-roots))))
3749
3750           (if threads
3751               ;; If there are some threads, we do them before the
3752               ;; threads on the stack.
3753               (setq thread threads
3754                     gnus-tmp-header (caar thread))
3755             ;; There were no current threads, so we pop something off
3756             ;; the stack.
3757             (setq state (car stack)
3758                   gnus-tmp-level (car state)
3759                   thread (cdr state)
3760                   stack (cdr stack)
3761                   gnus-tmp-header (caar thread))))
3762
3763         (setq gnus-tmp-false-parent nil)
3764         (setq gnus-tmp-root-expunged nil)
3765         (setq thread-end nil)
3766
3767         (if (stringp gnus-tmp-header)
3768             ;; The header is a dummy root.
3769             (cond
3770              ((eq gnus-summary-make-false-root 'adopt)
3771               ;; We let the first article adopt the rest.
3772               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3773                                                (cddar thread)))
3774               (setq gnus-tmp-gathered
3775                     (nconc (mapcar
3776                             (lambda (h) (mail-header-number (car h)))
3777                             (cddar thread))
3778                            gnus-tmp-gathered))
3779               (setq thread (cons (list (caar thread)
3780                                        (cadar thread))
3781                                  (cdr thread)))
3782               (setq gnus-tmp-level -1
3783                     gnus-tmp-false-parent t))
3784              ((eq gnus-summary-make-false-root 'empty)
3785               ;; We print adopted articles with empty subject fields.
3786               (setq gnus-tmp-gathered
3787                     (nconc (mapcar
3788                             (lambda (h) (mail-header-number (car h)))
3789                             (cddar thread))
3790                            gnus-tmp-gathered))
3791               (setq gnus-tmp-level -1))
3792              ((eq gnus-summary-make-false-root 'dummy)
3793               ;; We remember that we probably want to output a dummy
3794               ;; root.
3795               (setq gnus-tmp-dummy-line gnus-tmp-header)
3796               (setq gnus-tmp-prev-subject gnus-tmp-header))
3797              (t
3798               ;; We do not make a root for the gathered
3799               ;; sub-threads at all.
3800               (setq gnus-tmp-level -1)))
3801
3802           (setq number (mail-header-number gnus-tmp-header)
3803                 subject (mail-header-subject gnus-tmp-header))
3804
3805           (cond
3806            ;; If the thread has changed subject, we might want to make
3807            ;; this subthread into a root.
3808            ((and (null gnus-thread-ignore-subject)
3809                  (not (zerop gnus-tmp-level))
3810                  gnus-tmp-prev-subject
3811                  (not (inline
3812                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
3813             (setq new-roots (nconc new-roots (list (car thread)))
3814                   thread-end t
3815                   gnus-tmp-header nil))
3816            ;; If the article lies outside the current limit,
3817            ;; then we do not display it.
3818            ((not (memq number gnus-newsgroup-limit))
3819             (setq gnus-tmp-gathered
3820                   (nconc (mapcar
3821                           (lambda (h) (mail-header-number (car h)))
3822                           (cdar thread))
3823                          gnus-tmp-gathered))
3824             (setq gnus-tmp-new-adopts (if (cdar thread)
3825                                           (append gnus-tmp-new-adopts
3826                                                   (cdar thread))
3827                                         gnus-tmp-new-adopts)
3828                   thread-end t
3829                   gnus-tmp-header nil)
3830             (when (zerop gnus-tmp-level)
3831               (setq gnus-tmp-root-expunged t)))
3832            ;; Perhaps this article is to be marked as read?
3833            ((and gnus-summary-mark-below
3834                  (< (or (cdr (assq number gnus-newsgroup-scored))
3835                         default-score)
3836                     gnus-summary-mark-below)
3837                  ;; Don't touch sparse articles.
3838                  (not (gnus-summary-article-sparse-p number))
3839                  (not (gnus-summary-article-ancient-p number)))
3840             (setq gnus-newsgroup-unreads
3841                   (delq number gnus-newsgroup-unreads))
3842             (if gnus-newsgroup-auto-expire
3843                 (push number gnus-newsgroup-expirable)
3844               (push (cons number gnus-low-score-mark)
3845                     gnus-newsgroup-reads))))
3846
3847           (when gnus-tmp-header
3848             ;; We may have an old dummy line to output before this
3849             ;; article.
3850             (when (and gnus-tmp-dummy-line
3851                        (gnus-subject-equal
3852                         gnus-tmp-dummy-line
3853                         (mail-header-subject gnus-tmp-header)))
3854               (gnus-summary-insert-dummy-line
3855                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
3856               (setq gnus-tmp-dummy-line nil))
3857
3858             ;; Compute the mark.
3859             (setq gnus-tmp-unread (gnus-article-mark number))
3860
3861             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
3862                                   gnus-tmp-header gnus-tmp-level)
3863                   gnus-newsgroup-data)
3864
3865             ;; Actually insert the line.
3866             (setq
3867              gnus-tmp-subject-or-nil
3868              (cond
3869               ((and gnus-thread-ignore-subject
3870                     gnus-tmp-prev-subject
3871                     (not (inline (gnus-subject-equal
3872                                   gnus-tmp-prev-subject subject))))
3873                subject)
3874               ((zerop gnus-tmp-level)
3875                (if (and (eq gnus-summary-make-false-root 'empty)
3876                         (memq number gnus-tmp-gathered)
3877                         gnus-tmp-prev-subject
3878                         (inline (gnus-subject-equal
3879                                  gnus-tmp-prev-subject subject)))
3880                    gnus-summary-same-subject
3881                  subject))
3882               (t gnus-summary-same-subject)))
3883             (if (and (eq gnus-summary-make-false-root 'adopt)
3884                      (= gnus-tmp-level 1)
3885                      (memq number gnus-tmp-gathered))
3886                 (setq gnus-tmp-opening-bracket ?\<
3887                       gnus-tmp-closing-bracket ?\>)
3888               (setq gnus-tmp-opening-bracket ?\[
3889                     gnus-tmp-closing-bracket ?\]))
3890             (setq
3891              gnus-tmp-indentation
3892              (aref gnus-thread-indent-array gnus-tmp-level)
3893              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
3894              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
3895                                 gnus-summary-default-score 0)
3896              gnus-tmp-score-char
3897              (if (or (null gnus-summary-default-score)
3898                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3899                          gnus-summary-zcore-fuzz))
3900                  ? 
3901                (if (< gnus-tmp-score gnus-summary-default-score)
3902                    gnus-score-below-mark gnus-score-over-mark))
3903              gnus-tmp-replied
3904              (cond ((memq number gnus-newsgroup-processable)
3905                     gnus-process-mark)
3906                    ((memq number gnus-newsgroup-cached)
3907                     gnus-cached-mark)
3908                    ((memq number gnus-newsgroup-replied)
3909                     gnus-replied-mark)
3910                    ((memq number gnus-newsgroup-saved)
3911                     gnus-saved-mark)
3912                    (t gnus-unread-mark))
3913              gnus-tmp-from (mail-header-from gnus-tmp-header)
3914              gnus-tmp-name
3915              (cond
3916               ((string-match "<[^>]+> *$" gnus-tmp-from)
3917                (setq beg-match (match-beginning 0))
3918                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
3919                         (substring gnus-tmp-from (1+ (match-beginning 0))
3920                                    (1- (match-end 0))))
3921                    (substring gnus-tmp-from 0 beg-match)))
3922               ((string-match "(.+)" gnus-tmp-from)
3923                (substring gnus-tmp-from
3924                           (1+ (match-beginning 0)) (1- (match-end 0))))
3925               (t gnus-tmp-from)))
3926             (when (string= gnus-tmp-name "")
3927               (setq gnus-tmp-name gnus-tmp-from))
3928             (unless (numberp gnus-tmp-lines)
3929               (setq gnus-tmp-lines 0))
3930             (gnus-put-text-property
3931              (point)
3932              (progn (eval gnus-summary-line-format-spec) (point))
3933              'gnus-number number)
3934             (when gnus-visual-p
3935               (forward-line -1)
3936               (gnus-run-hooks 'gnus-summary-update-hook)
3937               (forward-line 1))
3938
3939             (setq gnus-tmp-prev-subject subject)))
3940
3941         (when (nth 1 thread)
3942           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
3943         (incf gnus-tmp-level)
3944         (setq threads (if thread-end nil (cdar thread)))
3945         (unless threads
3946           (setq gnus-tmp-level 0)))))
3947   (gnus-message 7 "Generating summary...done"))
3948
3949 (defun gnus-summary-prepare-unthreaded (headers)
3950   "Generate an unthreaded summary buffer based on HEADERS."
3951   (let (header number mark)
3952
3953     (beginning-of-line)
3954
3955     (while headers
3956       ;; We may have to root out some bad articles...
3957       (when (memq (setq number (mail-header-number
3958                                 (setq header (pop headers))))
3959                   gnus-newsgroup-limit)
3960         ;; Mark article as read when it has a low score.
3961         (when (and gnus-summary-mark-below
3962                    (< (or (cdr (assq number gnus-newsgroup-scored))
3963                           gnus-summary-default-score 0)
3964                       gnus-summary-mark-below)
3965                    (not (gnus-summary-article-ancient-p number)))
3966           (setq gnus-newsgroup-unreads
3967                 (delq number gnus-newsgroup-unreads))
3968           (if gnus-newsgroup-auto-expire
3969               (push number gnus-newsgroup-expirable)
3970             (push (cons number gnus-low-score-mark)
3971                   gnus-newsgroup-reads)))
3972
3973         (setq mark (gnus-article-mark number))
3974         (push (gnus-data-make number mark (1+ (point)) header 0)
3975               gnus-newsgroup-data)
3976         (gnus-summary-insert-line
3977          header 0 number
3978          mark (memq number gnus-newsgroup-replied)
3979          (memq number gnus-newsgroup-expirable)
3980          (mail-header-subject header) nil
3981          (cdr (assq number gnus-newsgroup-scored))
3982          (memq number gnus-newsgroup-processable))))))
3983
3984 (defun gnus-select-newsgroup (group &optional read-all select-articles)
3985   "Select newsgroup GROUP.
3986 If READ-ALL is non-nil, all articles in the group are selected.
3987 If SELECT-ARTICLES, only select those articles from GROUP."
3988   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
3989          ;;!!! Dirty hack; should be removed.
3990          (gnus-summary-ignore-duplicates
3991           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
3992               t
3993             gnus-summary-ignore-duplicates))
3994          (info (nth 2 entry))
3995          articles fetched-articles cached)
3996
3997     (unless (gnus-check-server
3998              (setq gnus-current-select-method
3999                    (gnus-find-method-for-group group)))
4000       (error "Couldn't open server"))
4001
4002     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4003         (gnus-activate-group group)     ; Or we can activate it...
4004         (progn                          ; Or we bug out.
4005           (when (equal major-mode 'gnus-summary-mode)
4006             (kill-buffer (current-buffer)))
4007           (error "Couldn't request group %s: %s"
4008                  group (gnus-status-message group))))
4009
4010     (unless (gnus-request-group group t)
4011       (when (equal major-mode 'gnus-summary-mode)
4012         (kill-buffer (current-buffer)))
4013       (error "Couldn't request group %s: %s"
4014              group (gnus-status-message group)))
4015
4016     (setq gnus-newsgroup-name group)
4017     (setq gnus-newsgroup-unselected nil)
4018     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4019     (gnus-newsgroup-setup-default-charset)
4020
4021     ;; Adjust and set lists of article marks.
4022     (when info
4023       (gnus-adjust-marked-articles info))
4024
4025     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4026     (when (gnus-virtual-group-p group)
4027       (setq cached gnus-newsgroup-cached))
4028
4029     (setq gnus-newsgroup-unreads
4030           (gnus-set-difference
4031            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4032            gnus-newsgroup-dormant))
4033
4034     (setq gnus-newsgroup-processable nil)
4035
4036     (gnus-update-read-articles group gnus-newsgroup-unreads)
4037
4038     (if (setq articles select-articles)
4039         (setq gnus-newsgroup-unselected
4040               (gnus-sorted-intersection
4041                gnus-newsgroup-unreads
4042                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4043       (setq articles (gnus-articles-to-read group read-all)))
4044
4045     (cond
4046      ((null articles)
4047       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4048       'quit)
4049      ((eq articles 0) nil)
4050      (t
4051       ;; Init the dependencies hash table.
4052       (setq gnus-newsgroup-dependencies
4053             (gnus-make-hashtable (length articles)))
4054       (gnus-set-global-variables)
4055       ;; Retrieve the headers and read them in.
4056       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4057       (setq gnus-newsgroup-headers
4058             (if (eq 'nov
4059                     (setq gnus-headers-retrieved-by
4060                           (gnus-retrieve-headers
4061                            articles gnus-newsgroup-name
4062                            ;; We might want to fetch old headers, but
4063                            ;; not if there is only 1 article.
4064                            (and (or (and
4065                                      (not (eq gnus-fetch-old-headers 'some))
4066                                      (not (numberp gnus-fetch-old-headers)))
4067                                     (> (length articles) 1))
4068                                 gnus-fetch-old-headers))))
4069                 (gnus-get-newsgroup-headers-xover
4070                  articles nil nil gnus-newsgroup-name t)
4071               (gnus-get-newsgroup-headers)))
4072       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4073
4074       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4075       (when cached
4076         (setq gnus-newsgroup-cached cached))
4077
4078       ;; Suppress duplicates?
4079       (when gnus-suppress-duplicates
4080         (gnus-dup-suppress-articles))
4081
4082       ;; Set the initial limit.
4083       (setq gnus-newsgroup-limit (copy-sequence articles))
4084       ;; Remove canceled articles from the list of unread articles.
4085       (setq gnus-newsgroup-unreads
4086             (gnus-set-sorted-intersection
4087              gnus-newsgroup-unreads
4088              (setq fetched-articles
4089                    (mapcar (lambda (headers) (mail-header-number headers))
4090                            gnus-newsgroup-headers))))
4091       ;; Removed marked articles that do not exist.
4092       (gnus-update-missing-marks
4093        (gnus-sorted-complement fetched-articles articles))
4094       ;; We might want to build some more threads first.
4095       (when (and gnus-fetch-old-headers
4096                  (eq gnus-headers-retrieved-by 'nov))
4097         (if (eq gnus-fetch-old-headers 'invisible)
4098             (gnus-build-all-threads)
4099           (gnus-build-old-threads)))
4100       ;; Let the Gnus agent mark articles as read.
4101       (when gnus-agent
4102         (gnus-agent-get-undownloaded-list))
4103       ;; Check whether auto-expire is to be done in this group.
4104       (setq gnus-newsgroup-auto-expire
4105             (gnus-group-auto-expirable-p group))
4106       ;; Set up the article buffer now, if necessary.
4107       (unless gnus-single-article-buffer
4108         (gnus-article-setup-buffer))
4109       ;; First and last article in this newsgroup.
4110       (when gnus-newsgroup-headers
4111         (setq gnus-newsgroup-begin
4112               (mail-header-number (car gnus-newsgroup-headers))
4113               gnus-newsgroup-end
4114               (mail-header-number
4115                (gnus-last-element gnus-newsgroup-headers))))
4116       ;; GROUP is successfully selected.
4117       (or gnus-newsgroup-headers t)))))
4118
4119 (defun gnus-articles-to-read (group &optional read-all)
4120   ;; Find out what articles the user wants to read.
4121   (let* ((articles
4122           ;; Select all articles if `read-all' is non-nil, or if there
4123           ;; are no unread articles.
4124           (if (or read-all
4125                   (and (zerop (length gnus-newsgroup-marked))
4126                        (zerop (length gnus-newsgroup-unreads)))
4127                   (eq (gnus-group-find-parameter group 'display)
4128                       'all))
4129               (gnus-uncompress-range (gnus-active group))
4130             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4131                           (copy-sequence gnus-newsgroup-unreads))
4132                   '<)))
4133          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4134          (scored (length scored-list))
4135          (number (length articles))
4136          (marked (+ (length gnus-newsgroup-marked)
4137                     (length gnus-newsgroup-dormant)))
4138          (select
4139           (cond
4140            ((numberp read-all)
4141             read-all)
4142            (t
4143             (condition-case ()
4144                 (cond
4145                  ((and (or (<= scored marked) (= scored number))
4146                        (numberp gnus-large-newsgroup)
4147                        (> number gnus-large-newsgroup))
4148                   (let ((input
4149                          (read-string
4150                           (format
4151                            "How many articles from %s (default %d): "
4152                            (gnus-limit-string gnus-newsgroup-name 35)
4153                            number))))
4154                     (if (string-match "^[ \t]*$" input) number input)))
4155                  ((and (> scored marked) (< scored number)
4156                        (> (- scored number) 20))
4157                   (let ((input
4158                          (read-string
4159                           (format "%s %s (%d scored, %d total): "
4160                                   "How many articles from"
4161                                   group scored number))))
4162                     (if (string-match "^[ \t]*$" input)
4163                         number input)))
4164                  (t number))
4165               (quit nil))))))
4166     (setq select (if (stringp select) (string-to-number select) select))
4167     (if (or (null select) (zerop select))
4168         select
4169       (if (and (not (zerop scored)) (<= (abs select) scored))
4170           (progn
4171             (setq articles (sort scored-list '<))
4172             (setq number (length articles)))
4173         (setq articles (copy-sequence articles)))
4174
4175       (when (< (abs select) number)
4176         (if (< select 0)
4177             ;; Select the N oldest articles.
4178             (setcdr (nthcdr (1- (abs select)) articles) nil)
4179           ;; Select the N most recent articles.
4180           (setq articles (nthcdr (- number select) articles))))
4181       (setq gnus-newsgroup-unselected
4182             (gnus-sorted-intersection
4183              gnus-newsgroup-unreads
4184              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4185       articles)))
4186
4187 (defun gnus-killed-articles (killed articles)
4188   (let (out)
4189     (while articles
4190       (when (inline (gnus-member-of-range (car articles) killed))
4191         (push (car articles) out))
4192       (setq articles (cdr articles)))
4193     out))
4194
4195 (defun gnus-uncompress-marks (marks)
4196   "Uncompress the mark ranges in MARKS."
4197   (let ((uncompressed '(score bookmark))
4198         out)
4199     (while marks
4200       (if (memq (caar marks) uncompressed)
4201           (push (car marks) out)
4202         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4203       (setq marks (cdr marks)))
4204     out))
4205
4206 (defun gnus-adjust-marked-articles (info)
4207   "Set all article lists and remove all marks that are no longer legal."
4208   (let* ((marked-lists (gnus-info-marks info))
4209          (active (gnus-active (gnus-info-group info)))
4210          (min (car active))
4211          (max (cdr active))
4212          (types gnus-article-mark-lists)
4213          (uncompressed '(score bookmark killed))
4214          marks var articles article mark)
4215
4216     (while marked-lists
4217       (setq marks (pop marked-lists))
4218       (set (setq var (intern (format "gnus-newsgroup-%s"
4219                                      (car (rassq (setq mark (car marks))
4220                                                  types)))))
4221            (if (memq (car marks) uncompressed) (cdr marks)
4222              (gnus-uncompress-range (cdr marks))))
4223
4224       (setq articles (symbol-value var))
4225
4226       ;; All articles have to be subsets of the active articles.
4227       (cond
4228        ;; Adjust "simple" lists.
4229        ((memq mark '(tick dormant expire reply save))
4230         (while articles
4231           (when (or (< (setq article (pop articles)) min) (> article max))
4232             (set var (delq article (symbol-value var))))))
4233        ;; Adjust assocs.
4234        ((memq mark uncompressed)
4235         (when (not (listp (cdr (symbol-value var))))
4236           (set var (list (symbol-value var))))
4237         (when (not (listp (cdr articles)))
4238           (setq articles (list articles)))
4239         (while articles
4240           (when (or (not (consp (setq article (pop articles))))
4241                     (< (car article) min)
4242                     (> (car article) max))
4243             (set var (delq article (symbol-value var))))))))))
4244
4245 (defun gnus-update-missing-marks (missing)
4246   "Go through the list of MISSING articles and remove them from the mark lists."
4247   (when missing
4248     (let ((types gnus-article-mark-lists)
4249           var m)
4250       ;; Go through all types.
4251       (while types
4252         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4253         (when (symbol-value var)
4254           ;; This list has articles.  So we delete all missing articles
4255           ;; from it.
4256           (setq m missing)
4257           (while m
4258             (set var (delq (pop m) (symbol-value var)))))))))
4259
4260 (defun gnus-update-marks ()
4261   "Enter the various lists of marked articles into the newsgroup info list."
4262   (let ((types gnus-article-mark-lists)
4263         (info (gnus-get-info gnus-newsgroup-name))
4264         (uncompressed '(score bookmark killed))
4265         type list newmarked symbol delta-marks)
4266     (when info
4267       ;; Add all marks lists that are non-nil to the list of marks lists.
4268       (while (setq type (pop types))
4269         (when (setq list (symbol-value
4270                           (setq symbol
4271                                 (intern (format "gnus-newsgroup-%s"
4272                                                 (car type))))))
4273
4274           ;; Get rid of the entries of the articles that have the
4275           ;; default score.
4276           (when (and (eq (cdr type) 'score)
4277                      gnus-save-score
4278                      list)
4279             (let* ((arts list)
4280                    (prev (cons nil list))
4281                    (all prev))
4282               (while arts
4283                 (if (or (not (consp (car arts)))
4284                         (= (cdar arts) gnus-summary-default-score))
4285                     (setcdr prev (cdr arts))
4286                   (setq prev arts))
4287                 (setq arts (cdr arts)))
4288               (setq list (cdr all))))
4289
4290           (push (cons (cdr type)
4291                       (if (memq (cdr type) uncompressed) list
4292                         (gnus-compress-sequence
4293                          (set symbol (sort list '<)) t)))
4294                 newmarked)))
4295
4296       ;; Enter these new marks into the info of the group.
4297       (if (nthcdr 3 info)
4298           (setcar (nthcdr 3 info) newmarked)
4299         ;; Add the marks lists to the end of the info.
4300         (when newmarked
4301           (setcdr (nthcdr 2 info) (list newmarked))))
4302
4303       ;; Cut off the end of the info if there's nothing else there.
4304       (let ((i 5))
4305         (while (and (> i 2)
4306                     (not (nth i info)))
4307           (when (nthcdr (decf i) info)
4308             (setcdr (nthcdr i info) nil)))))))
4309
4310 (defun gnus-set-mode-line (where)
4311   "This function sets the mode line of the article or summary buffers.
4312 If WHERE is `summary', the summary mode line format will be used."
4313   ;; Is this mode line one we keep updated?
4314   (when (and (memq where gnus-updated-mode-lines)
4315              (symbol-value
4316               (intern (format "gnus-%s-mode-line-format-spec" where))))
4317     (let (mode-string)
4318       (save-excursion
4319         ;; We evaluate this in the summary buffer since these
4320         ;; variables are buffer-local to that buffer.
4321         (set-buffer gnus-summary-buffer)
4322         ;; We bind all these variables that are used in the `eval' form
4323         ;; below.
4324         (let* ((mformat (symbol-value
4325                          (intern
4326                           (format "gnus-%s-mode-line-format-spec" where))))
4327                (gnus-tmp-group-name gnus-newsgroup-name)
4328                (gnus-tmp-article-number (or gnus-current-article 0))
4329                (gnus-tmp-unread gnus-newsgroup-unreads)
4330                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4331                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4332                (gnus-tmp-unread-and-unselected
4333                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4334                             (zerop gnus-tmp-unselected))
4335                        "")
4336                       ((zerop gnus-tmp-unselected)
4337                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4338                       (t (format "{%d(+%d) more}"
4339                                  gnus-tmp-unread-and-unticked
4340                                  gnus-tmp-unselected))))
4341                (gnus-tmp-subject
4342                 (if (and gnus-current-headers
4343                          (vectorp gnus-current-headers))
4344                     (gnus-mode-string-quote
4345                      (mail-header-subject gnus-current-headers))
4346                   ""))
4347                bufname-length max-len
4348                gnus-tmp-header);; passed as argument to any user-format-funcs
4349           (setq mode-string (eval mformat))
4350           (setq bufname-length (if (string-match "%b" mode-string)
4351                                    (- (length
4352                                        (buffer-name
4353                                         (if (eq where 'summary)
4354                                             nil
4355                                           (get-buffer gnus-article-buffer))))
4356                                       2)
4357                                  0))
4358           (setq max-len (max 4 (if gnus-mode-non-string-length
4359                                    (- (window-width)
4360                                       gnus-mode-non-string-length
4361                                       bufname-length)
4362                                  (length mode-string))))
4363           ;; We might have to chop a bit of the string off...
4364           (when (> (length mode-string) max-len)
4365             (setq mode-string
4366                   (concat (truncate-string-to-width mode-string (- max-len 3))
4367                           "...")))
4368           ;; Pad the mode string a bit.
4369           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4370       ;; Update the mode line.
4371       (setq mode-line-buffer-identification
4372             (gnus-mode-line-buffer-identification (list mode-string)))
4373       (set-buffer-modified-p t))))
4374
4375 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4376   "Go through the HEADERS list and add all Xrefs to a hash table.
4377 The resulting hash table is returned, or nil if no Xrefs were found."
4378   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4379          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4380          (xref-hashtb (gnus-make-hashtable))
4381          start group entry number xrefs header)
4382     (while headers
4383       (setq header (pop headers))
4384       (when (and (setq xrefs (mail-header-xref header))
4385                  (not (memq (setq number (mail-header-number header))
4386                             unreads)))
4387         (setq start 0)
4388         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4389           (setq start (match-end 0))
4390           (setq group (if prefix
4391                           (concat prefix (substring xrefs (match-beginning 1)
4392                                                     (match-end 1)))
4393                         (substring xrefs (match-beginning 1) (match-end 1))))
4394           (setq number
4395                 (string-to-int (substring xrefs (match-beginning 2)
4396                                           (match-end 2))))
4397           (if (setq entry (gnus-gethash group xref-hashtb))
4398               (setcdr entry (cons number (cdr entry)))
4399             (gnus-sethash group (cons number nil) xref-hashtb)))))
4400     (and start xref-hashtb)))
4401
4402 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4403   "Look through all the headers and mark the Xrefs as read."
4404   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4405         name entry info xref-hashtb idlist method nth4)
4406     (save-excursion
4407       (set-buffer gnus-group-buffer)
4408       (when (setq xref-hashtb
4409                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4410         (mapatoms
4411          (lambda (group)
4412            (unless (string= from-newsgroup (setq name (symbol-name group)))
4413              (setq idlist (symbol-value group))
4414              ;; Dead groups are not updated.
4415              (and (prog1
4416                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4417                             info (nth 2 entry))
4418                     (when (stringp (setq nth4 (gnus-info-method info)))
4419                       (setq nth4 (gnus-server-to-method nth4))))
4420                   ;; Only do the xrefs if the group has the same
4421                   ;; select method as the group we have just read.
4422                   (or (gnus-methods-equal-p
4423                        nth4 (gnus-find-method-for-group from-newsgroup))
4424                       virtual
4425                       (equal nth4 (setq method (gnus-find-method-for-group
4426                                                 from-newsgroup)))
4427                       (and (equal (car nth4) (car method))
4428                            (equal (nth 1 nth4) (nth 1 method))))
4429                   gnus-use-cross-reference
4430                   (or (not (eq gnus-use-cross-reference t))
4431                       virtual
4432                       ;; Only do cross-references on subscribed
4433                       ;; groups, if that is what is wanted.
4434                       (<= (gnus-info-level info) gnus-level-subscribed))
4435                   (gnus-group-make-articles-read name idlist))))
4436          xref-hashtb)))))
4437
4438 (defun gnus-compute-read-articles (group articles)
4439   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4440          (info (nth 2 entry))
4441          (active (gnus-active group))
4442          ninfo)
4443     (when entry
4444       ;; First peel off all illegal article numbers.
4445       (when active
4446         (let ((ids articles)
4447               id first)
4448           (while (setq id (pop ids))
4449             (when (and first (> id (cdr active)))
4450               ;; We'll end up in this situation in one particular
4451               ;; obscure situation.  If you re-scan a group and get
4452               ;; a new article that is cross-posted to a different
4453               ;; group that has not been re-scanned, you might get
4454               ;; crossposted article that has a higher number than
4455               ;; Gnus believes possible.  So we re-activate this
4456               ;; group as well.  This might mean doing the
4457               ;; crossposting thingy will *increase* the number
4458               ;; of articles in some groups.  Tsk, tsk.
4459               (setq active (or (gnus-activate-group group) active)))
4460             (when (or (> id (cdr active))
4461                       (< id (car active)))
4462               (setq articles (delq id articles))))))
4463       ;; If the read list is nil, we init it.
4464       (if (and active
4465                (null (gnus-info-read info))
4466                (> (car active) 1))
4467           (setq ninfo (cons 1 (1- (car active))))
4468         (setq ninfo (gnus-info-read info)))
4469       ;; Then we add the read articles to the range.
4470       (gnus-add-to-range
4471        ninfo (setq articles (sort articles '<))))))
4472
4473 (defun gnus-group-make-articles-read (group articles)
4474   "Update the info of GROUP to say that ARTICLES are read."
4475   (let* ((num 0)
4476          (entry (gnus-gethash group gnus-newsrc-hashtb))
4477          (info (nth 2 entry))
4478          (active (gnus-active group))
4479          range)
4480     (when entry
4481       (setq range (gnus-compute-read-articles group articles))
4482       (save-excursion
4483         (set-buffer gnus-group-buffer)
4484         (gnus-undo-register
4485           `(progn
4486              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4487              (gnus-info-set-read ',info ',(gnus-info-read info))
4488              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4489              (gnus-group-update-group ,group t))))
4490       ;; Add the read articles to the range.
4491       (gnus-info-set-read info range)
4492       ;; Then we have to re-compute how many unread
4493       ;; articles there are in this group.
4494       (when active
4495         (cond
4496          ((not range)
4497           (setq num (- (1+ (cdr active)) (car active))))
4498          ((not (listp (cdr range)))
4499           (setq num (- (cdr active) (- (1+ (cdr range))
4500                                        (car range)))))
4501          (t
4502           (while range
4503             (if (numberp (car range))
4504                 (setq num (1+ num))
4505               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4506             (setq range (cdr range)))
4507           (setq num (- (cdr active) num))))
4508         ;; Update the number of unread articles.
4509         (setcar entry num)
4510         ;; Update the group buffer.
4511         (gnus-group-update-group group t)))))
4512
4513 (defun gnus-methods-equal-p (m1 m2)
4514   (let ((m1 (or m1 gnus-select-method))
4515         (m2 (or m2 gnus-select-method)))
4516     (or (equal m1 m2)
4517         (and (eq (car m1) (car m2))
4518              (or (not (memq 'address (assoc (symbol-name (car m1))
4519                                             gnus-valid-select-methods)))
4520                  (equal (nth 1 m1) (nth 1 m2)))))))
4521
4522 (defvar gnus-newsgroup-none-id 0)
4523
4524 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4525   (let ((cur nntp-server-buffer)
4526         (dependencies
4527          (or dependencies
4528              (save-excursion (set-buffer gnus-summary-buffer)
4529                              gnus-newsgroup-dependencies)))
4530         headers id end ref
4531         (rfc2047-default-charset gnus-newsgroup-default-charset)
4532         (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
4533     (save-excursion
4534       (set-buffer nntp-server-buffer)
4535       ;; Translate all TAB characters into SPACE characters.
4536       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4537       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4538       (gnus-run-hooks 'gnus-parse-headers-hook)
4539       (let ((case-fold-search t)
4540             in-reply-to header p lines chars)
4541         (goto-char (point-min))
4542         ;; Search to the beginning of the next header.  Error messages
4543         ;; do not begin with 2 or 3.
4544         (while (re-search-forward "^[23][0-9]+ " nil t)
4545           (setq id nil
4546                 ref nil)
4547           ;; This implementation of this function, with nine
4548           ;; search-forwards instead of the one re-search-forward and
4549           ;; a case (which basically was the old function) is actually
4550           ;; about twice as fast, even though it looks messier.  You
4551           ;; can't have everything, I guess.  Speed and elegance
4552           ;; doesn't always go hand in hand.
4553           (setq
4554            header
4555            (vector
4556             ;; Number.
4557             (prog1
4558                 (read cur)
4559               (end-of-line)
4560               (setq p (point))
4561               (narrow-to-region (point)
4562                                 (or (and (search-forward "\n.\n" nil t)
4563                                          (- (point) 2))
4564                                     (point))))
4565             ;; Subject.
4566             (progn
4567               (goto-char p)
4568               (if (search-forward "\nsubject: " nil t)
4569                   (funcall gnus-decode-encoded-word-function
4570                            (nnheader-header-value))
4571                 "(none)"))
4572             ;; From.
4573             (progn
4574               (goto-char p)
4575               (if (search-forward "\nfrom: " nil t)
4576                   (funcall gnus-decode-encoded-word-function
4577                            (nnheader-header-value))
4578                 "(nobody)"))
4579             ;; Date.
4580             (progn
4581               (goto-char p)
4582               (if (search-forward "\ndate: " nil t)
4583                   (nnheader-header-value) ""))
4584             ;; Message-ID.
4585             (progn
4586               (goto-char p)
4587               (setq id (if (re-search-forward
4588                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4589                            ;; We do it this way to make sure the Message-ID
4590                            ;; is (somewhat) syntactically valid.
4591                            (buffer-substring (match-beginning 1)
4592                                              (match-end 1))
4593                          ;; If there was no message-id, we just fake one
4594                          ;; to make subsequent routines simpler.
4595                          (nnheader-generate-fake-message-id))))
4596             ;; References.
4597             (progn
4598               (goto-char p)
4599               (if (search-forward "\nreferences: " nil t)
4600                   (progn
4601                     (setq end (point))
4602                     (prog1
4603                         (nnheader-header-value)
4604                       (setq ref
4605                             (buffer-substring
4606                              (progn
4607                                (end-of-line)
4608                                (search-backward ">" end t)
4609                                (1+ (point)))
4610                              (progn
4611                                (search-backward "<" end t)
4612                                (point))))))
4613                 ;; Get the references from the in-reply-to header if there
4614                 ;; were no references and the in-reply-to header looks
4615                 ;; promising.
4616                 (if (and (search-forward "\nin-reply-to: " nil t)
4617                          (setq in-reply-to (nnheader-header-value))
4618                          (string-match "<[^>]+>" in-reply-to))
4619                     (let (ref2)
4620                       (setq ref (substring in-reply-to (match-beginning 0)
4621                                            (match-end 0)))
4622                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4623                         (setq ref2 (substring in-reply-to (match-beginning 0)
4624                                               (match-end 0)))
4625                         (when (> (length ref2) (length ref))
4626                           (setq ref ref2)))
4627                       ref)
4628                   (setq ref nil))))
4629             ;; Chars.
4630             (progn
4631               (goto-char p)
4632               (if (search-forward "\nchars: " nil t)
4633                   (if (numberp (setq chars (ignore-errors (read cur))))
4634                       chars 0)
4635                 0))
4636             ;; Lines.
4637             (progn
4638               (goto-char p)
4639               (if (search-forward "\nlines: " nil t)
4640                   (if (numberp (setq lines (ignore-errors (read cur))))
4641                       lines 0)
4642                 0))
4643             ;; Xref.
4644             (progn
4645               (goto-char p)
4646               (and (search-forward "\nxref: " nil t)
4647                    (nnheader-header-value)))
4648             ;; Extra.
4649             (when gnus-extra-headers
4650               (let ((extra gnus-extra-headers)
4651                     out)
4652                 (while extra
4653                   (goto-char p)
4654                   (when (search-forward
4655                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4656                     (push (cons (car extra) (nnheader-header-value))
4657                           out))
4658                   (pop extra))
4659                 out))))
4660           (when (equal id ref)
4661             (setq ref nil))
4662
4663           (when gnus-alter-header-function
4664             (funcall gnus-alter-header-function header)
4665             (setq id (mail-header-id header)
4666                   ref (gnus-parent-id (mail-header-references header))))
4667
4668           (when (setq header
4669                       (gnus-dependencies-add-header
4670                        header dependencies force-new))
4671             (push header headers))
4672           (goto-char (point-max))
4673           (widen))
4674         (nreverse headers)))))
4675
4676 ;; Goes through the xover lines and returns a list of vectors
4677 (defun gnus-get-newsgroup-headers-xover (sequence &optional
4678                                                   force-new dependencies
4679                                                   group also-fetch-heads)
4680   "Parse the news overview data in the server buffer, and return a
4681 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4682   ;; Get the Xref when the users reads the articles since most/some
4683   ;; NNTP servers do not include Xrefs when using XOVER.
4684   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4685   (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
4686         (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
4687         (cur nntp-server-buffer)
4688         (dependencies (or dependencies gnus-newsgroup-dependencies))
4689         number headers header)
4690     (save-excursion
4691       (set-buffer nntp-server-buffer)
4692       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4693       ;; Allow the user to mangle the headers before parsing them.
4694       (gnus-run-hooks 'gnus-parse-headers-hook)
4695       (goto-char (point-min))
4696       (while (not (eobp))
4697         (condition-case ()
4698             (while (and sequence (not (eobp)))
4699               (setq number (read cur))
4700               (while (and sequence
4701                           (< (car sequence) number))
4702                 (setq sequence (cdr sequence)))
4703               (and sequence
4704                    (eq number (car sequence))
4705                    (progn
4706                      (setq sequence (cdr sequence))
4707                      (setq header (inline
4708                                     (gnus-nov-parse-line
4709                                      number dependencies force-new))))
4710                    (push header headers))
4711               (forward-line 1))
4712           (error
4713            (gnus-error 4 "Strange nov line (%d)"
4714                        (count-lines (point-min) (point)))))
4715         (forward-line 1))
4716       ;; A common bug in inn is that if you have posted an article and
4717       ;; then retrieves the active file, it will answer correctly --
4718       ;; the new article is included.  However, a NOV entry for the
4719       ;; article may not have been generated yet, so this may fail.
4720       ;; We work around this problem by retrieving the last few
4721       ;; headers using HEAD.
4722       (if (or (not also-fetch-heads)
4723               (not sequence))
4724           ;; We (probably) got all the headers.
4725           (nreverse headers)
4726         (let ((gnus-nov-is-evil t))
4727           (nconc
4728            (nreverse headers)
4729            (when (gnus-retrieve-headers sequence group)
4730              (gnus-get-newsgroup-headers))))))))
4731
4732 (defun gnus-article-get-xrefs ()
4733   "Fill in the Xref value in `gnus-current-headers', if necessary.
4734 This is meant to be called in `gnus-article-internal-prepare-hook'."
4735   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4736                                  gnus-current-headers)))
4737     (or (not gnus-use-cross-reference)
4738         (not headers)
4739         (and (mail-header-xref headers)
4740              (not (string= (mail-header-xref headers) "")))
4741         (let ((case-fold-search t)
4742               xref)
4743           (save-restriction
4744             (nnheader-narrow-to-headers)
4745             (goto-char (point-min))
4746             (when (or (and (eq (downcase (char-after)) ?x)
4747                            (looking-at "Xref:"))
4748                       (search-forward "\nXref:" nil t))
4749               (goto-char (1+ (match-end 0)))
4750               (setq xref (buffer-substring (point)
4751                                            (progn (end-of-line) (point))))
4752               (mail-header-set-xref headers xref)))))))
4753
4754 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4755   "Find article ID and insert the summary line for that article.
4756 OLD-HEADER can either be a header or a line number to insert
4757 the subject line on."
4758   (let* ((line (and (numberp old-header) old-header))
4759          (old-header (and (vectorp old-header) old-header))
4760          (header (cond ((and old-header use-old-header)
4761                         old-header)
4762                        ((and (numberp id)
4763                              (gnus-number-to-header id))
4764                         (gnus-number-to-header id))
4765                        (t
4766                         (gnus-read-header id))))
4767          (number (and (numberp id) id))
4768          d)
4769     (when header
4770       ;; Rebuild the thread that this article is part of and go to the
4771       ;; article we have fetched.
4772       (when (and (not gnus-show-threads)
4773                  old-header)
4774         (when (and number
4775                    (setq d (gnus-data-find (mail-header-number old-header))))
4776           (goto-char (gnus-data-pos d))
4777           (gnus-data-remove
4778            number
4779            (- (gnus-point-at-bol)
4780               (prog1
4781                   (1+ (gnus-point-at-eol))
4782                 (gnus-delete-line))))))
4783       (when old-header
4784         (mail-header-set-number header (mail-header-number old-header)))
4785       (setq gnus-newsgroup-sparse
4786             (delq (setq number (mail-header-number header))
4787                   gnus-newsgroup-sparse))
4788       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4789       (push number gnus-newsgroup-limit)
4790       (gnus-rebuild-thread (mail-header-id header) line)
4791       (gnus-summary-goto-subject number nil t))
4792     (when (and (numberp number)
4793                (> number 0))
4794       ;; We have to update the boundaries even if we can't fetch the
4795       ;; article if ID is a number -- so that the next `P' or `N'
4796       ;; command will fetch the previous (or next) article even
4797       ;; if the one we tried to fetch this time has been canceled.
4798       (when (> number gnus-newsgroup-end)
4799         (setq gnus-newsgroup-end number))
4800       (when (< number gnus-newsgroup-begin)
4801         (setq gnus-newsgroup-begin number))
4802       (setq gnus-newsgroup-unselected
4803             (delq number gnus-newsgroup-unselected)))
4804     ;; Report back a success?
4805     (and header (mail-header-number header))))
4806
4807 ;;; Process/prefix in the summary buffer
4808
4809 (defun gnus-summary-work-articles (n)
4810   "Return a list of articles to be worked upon.
4811 The prefix argument, the list of process marked articles, and the
4812 current article will be taken into consideration."
4813   (save-excursion
4814     (set-buffer gnus-summary-buffer)
4815     (cond
4816      (n
4817       ;; A numerical prefix has been given.
4818       (setq n (prefix-numeric-value n))
4819       (let ((backward (< n 0))
4820             (n (abs (prefix-numeric-value n)))
4821             articles article)
4822         (save-excursion
4823           (while
4824               (and (> n 0)
4825                    (push (setq article (gnus-summary-article-number))
4826                          articles)
4827                    (if backward
4828                        (gnus-summary-find-prev nil article)
4829                      (gnus-summary-find-next nil article)))
4830             (decf n)))
4831         (nreverse articles)))
4832      ((and (gnus-region-active-p) (mark))
4833       (message "region active")
4834       ;; Work on the region between point and mark.
4835       (let ((max (max (point) (mark)))
4836             articles article)
4837         (save-excursion
4838           (goto-char (min (min (point) (mark))))
4839           (while
4840               (and
4841                (push (setq article (gnus-summary-article-number)) articles)
4842                (gnus-summary-find-next nil article)
4843                (< (point) max)))
4844           (nreverse articles))))
4845      (gnus-newsgroup-processable
4846       ;; There are process-marked articles present.
4847       ;; Save current state.
4848       (gnus-summary-save-process-mark)
4849       ;; Return the list.
4850       (reverse gnus-newsgroup-processable))
4851      (t
4852       ;; Just return the current article.
4853       (list (gnus-summary-article-number))))))
4854
4855 (defmacro gnus-summary-iterate (arg &rest forms)
4856   "Iterate over the process/prefixed articles and do FORMS.
4857 ARG is the interactive prefix given to the command.  FORMS will be
4858 executed with point over the summary line of the articles."
4859   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
4860     `(let ((,articles (gnus-summary-work-articles ,arg)))
4861        (while ,articles
4862          (gnus-summary-goto-subject (car ,articles))
4863          ,@forms))))
4864
4865 (put 'gnus-summary-iterate 'lisp-indent-function 1)
4866 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
4867
4868 (defun gnus-summary-save-process-mark ()
4869   "Push the current set of process marked articles on the stack."
4870   (interactive)
4871   (push (copy-sequence gnus-newsgroup-processable)
4872         gnus-newsgroup-process-stack))
4873
4874 (defun gnus-summary-kill-process-mark ()
4875   "Push the current set of process marked articles on the stack and unmark."
4876   (interactive)
4877   (gnus-summary-save-process-mark)
4878   (gnus-summary-unmark-all-processable))
4879
4880 (defun gnus-summary-yank-process-mark ()
4881   "Pop the last process mark state off the stack and restore it."
4882   (interactive)
4883   (unless gnus-newsgroup-process-stack
4884     (error "Empty mark stack"))
4885   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4886
4887 (defun gnus-summary-process-mark-set (set)
4888   "Make SET into the current process marked articles."
4889   (gnus-summary-unmark-all-processable)
4890   (while set
4891     (gnus-summary-set-process-mark (pop set))))
4892
4893 ;;; Searching and stuff
4894
4895 (defun gnus-summary-search-group (&optional backward use-level)
4896   "Search for next unread newsgroup.
4897 If optional argument BACKWARD is non-nil, search backward instead."
4898   (save-excursion
4899     (set-buffer gnus-group-buffer)
4900     (when (gnus-group-search-forward
4901            backward nil (if use-level (gnus-group-group-level) nil))
4902       (gnus-group-group-name))))
4903
4904 (defun gnus-summary-best-group (&optional exclude-group)
4905   "Find the name of the best unread group.
4906 If EXCLUDE-GROUP, do not go to this group."
4907   (save-excursion
4908     (set-buffer gnus-group-buffer)
4909     (save-excursion
4910       (gnus-group-best-unread-group exclude-group))))
4911
4912 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
4913   (if backward (gnus-summary-find-prev)
4914     (let* ((dummy (gnus-summary-article-intangible-p))
4915            (article (or article (gnus-summary-article-number)))
4916            (arts (gnus-data-find-list article))
4917            result)
4918       (when (and (not dummy)
4919                  (or (not gnus-summary-check-current)
4920                      (not unread)
4921                      (not (gnus-data-unread-p (car arts)))))
4922         (setq arts (cdr arts)))
4923       (when (setq result
4924                   (if unread
4925                       (progn
4926                         (while arts
4927                           (when (or (and undownloaded
4928                                          (eq gnus-undownloaded-mark
4929                                              (gnus-data-mark (car arts))))
4930                                     (gnus-data-unread-p (car arts)))
4931                             (setq result (car arts)
4932                                   arts nil))
4933                           (setq arts (cdr arts)))
4934                         result)
4935                     (car arts)))
4936         (goto-char (gnus-data-pos result))
4937         (gnus-data-number result)))))
4938
4939 (defun gnus-summary-find-prev (&optional unread article)
4940   (let* ((eobp (eobp))
4941          (article (or article (gnus-summary-article-number)))
4942          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
4943          result)
4944     (when (and (not eobp)
4945                (or (not gnus-summary-check-current)
4946                    (not unread)
4947                    (not (gnus-data-unread-p (car arts)))))
4948       (setq arts (cdr arts)))
4949     (when (setq result
4950                 (if unread
4951                     (progn
4952                       (while arts
4953                         (when (gnus-data-unread-p (car arts))
4954                           (setq result (car arts)
4955                                 arts nil))
4956                         (setq arts (cdr arts)))
4957                       result)
4958                   (car arts)))
4959       (goto-char (gnus-data-pos result))
4960       (gnus-data-number result))))
4961
4962 (defun gnus-summary-find-subject (subject &optional unread backward article)
4963   (let* ((simp-subject (gnus-simplify-subject-fully subject))
4964          (article (or article (gnus-summary-article-number)))
4965          (articles (gnus-data-list backward))
4966          (arts (gnus-data-find-list article articles))
4967          result)
4968     (when (or (not gnus-summary-check-current)
4969               (not unread)
4970               (not (gnus-data-unread-p (car arts))))
4971       (setq arts (cdr arts)))
4972     (while arts
4973       (and (or (not unread)
4974                (gnus-data-unread-p (car arts)))
4975            (vectorp (gnus-data-header (car arts)))
4976            (gnus-subject-equal
4977             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
4978            (setq result (car arts)
4979                  arts nil))
4980       (setq arts (cdr arts)))
4981     (and result
4982          (goto-char (gnus-data-pos result))
4983          (gnus-data-number result))))
4984
4985 (defun gnus-summary-search-forward (&optional unread subject backward)
4986   "Search forward for an article.
4987 If UNREAD, look for unread articles.  If SUBJECT, look for
4988 articles with that subject.  If BACKWARD, search backward instead."
4989   (cond (subject (gnus-summary-find-subject subject unread backward))
4990         (backward (gnus-summary-find-prev unread))
4991         (t (gnus-summary-find-next unread))))
4992
4993 (defun gnus-recenter (&optional n)
4994   "Center point in window and redisplay frame.
4995 Also do horizontal recentering."
4996   (interactive "P")
4997   (when (and gnus-auto-center-summary
4998              (not (eq gnus-auto-center-summary 'vertical)))
4999     (gnus-horizontal-recenter))
5000   (recenter n))
5001
5002 (defun gnus-summary-recenter ()
5003   "Center point in the summary window.
5004 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5005 displayed, no centering will be performed."
5006   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5007   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5008   (let* ((top (cond ((< (window-height) 4) 0)
5009                     ((< (window-height) 7) 1)
5010                     (t (if (numberp gnus-auto-center-summary)
5011                            gnus-auto-center-summary
5012                          2))))
5013          (height (1- (window-height)))
5014          (bottom (save-excursion (goto-char (point-max))
5015                                  (forward-line (- height))
5016                                  (point)))
5017          (window (get-buffer-window (current-buffer))))
5018     ;; The user has to want it.
5019     (when gnus-auto-center-summary
5020       (when (get-buffer-window gnus-article-buffer)
5021         ;; Only do recentering when the article buffer is displayed,
5022         ;; Set the window start to either `bottom', which is the biggest
5023         ;; possible valid number, or the second line from the top,
5024         ;; whichever is the least.
5025         (set-window-start
5026          window (min bottom (save-excursion
5027                               (forward-line (- top)) (point)))))
5028       ;; Do horizontal recentering while we're at it.
5029       (when (and (get-buffer-window (current-buffer) t)
5030                  (not (eq gnus-auto-center-summary 'vertical)))
5031         (let ((selected (selected-window)))
5032           (select-window (get-buffer-window (current-buffer) t))
5033           (gnus-summary-position-point)
5034           (gnus-horizontal-recenter)
5035           (select-window selected))))))
5036
5037 (defun gnus-summary-jump-to-group (newsgroup)
5038   "Move point to NEWSGROUP in group mode buffer."
5039   ;; Keep update point of group mode buffer if visible.
5040   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5041       (save-window-excursion
5042         ;; Take care of tree window mode.
5043         (when (get-buffer-window gnus-group-buffer)
5044           (pop-to-buffer gnus-group-buffer))
5045         (gnus-group-jump-to-group newsgroup))
5046     (save-excursion
5047       ;; Take care of tree window mode.
5048       (if (get-buffer-window gnus-group-buffer)
5049           (pop-to-buffer gnus-group-buffer)
5050         (set-buffer gnus-group-buffer))
5051       (gnus-group-jump-to-group newsgroup))))
5052
5053 ;; This function returns a list of article numbers based on the
5054 ;; difference between the ranges of read articles in this group and
5055 ;; the range of active articles.
5056 (defun gnus-list-of-unread-articles (group)
5057   (let* ((read (gnus-info-read (gnus-get-info group)))
5058          (active (or (gnus-active group) (gnus-activate-group group)))
5059          (last (cdr active))
5060          first nlast unread)
5061     ;; If none are read, then all are unread.
5062     (if (not read)
5063         (setq first (car active))
5064       ;; If the range of read articles is a single range, then the
5065       ;; first unread article is the article after the last read
5066       ;; article.  Sounds logical, doesn't it?
5067       (if (not (listp (cdr read)))
5068           (setq first (max (car active) (1+ (cdr read))))
5069         ;; `read' is a list of ranges.
5070         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5071                                   (caar read)))
5072                   1)
5073           (setq first (car active)))
5074         (while read
5075           (when first
5076             (while (< first nlast)
5077               (push first unread)
5078               (setq first (1+ first))))
5079           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5080           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5081           (setq read (cdr read)))))
5082     ;; And add the last unread articles.
5083     (while (<= first last)
5084       (push first unread)
5085       (setq first (1+ first)))
5086     ;; Return the list of unread articles.
5087     (delq 0 (nreverse unread))))
5088
5089 (defun gnus-list-of-read-articles (group)
5090   "Return a list of unread, unticked and non-dormant articles."
5091   (let* ((info (gnus-get-info group))
5092          (marked (gnus-info-marks info))
5093          (active (gnus-active group)))
5094     (and info active
5095          (gnus-set-difference
5096           (gnus-sorted-complement
5097            (gnus-uncompress-range active)
5098            (gnus-list-of-unread-articles group))
5099           (append
5100            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5101            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5102
5103 ;; Various summary commands
5104
5105 (defun gnus-summary-select-article-buffer ()
5106   "Reconfigure windows to show article buffer."
5107   (interactive)
5108   (if (not (gnus-buffer-live-p gnus-article-buffer))
5109       (error "There is no article buffer for this summary buffer")
5110     (gnus-configure-windows 'article)
5111     (select-window (get-buffer-window gnus-article-buffer))))
5112
5113 (defun gnus-summary-universal-argument (arg)
5114   "Perform any operation on all articles that are process/prefixed."
5115   (interactive "P")
5116   (let ((articles (gnus-summary-work-articles arg))
5117         func article)
5118     (if (eq
5119          (setq
5120           func
5121           (key-binding
5122            (read-key-sequence
5123             (substitute-command-keys
5124              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
5125              ))))
5126          'undefined)
5127         (gnus-error 1 "Undefined key")
5128       (save-excursion
5129         (while articles
5130           (gnus-summary-goto-subject (setq article (pop articles)))
5131           (let (gnus-newsgroup-processable)
5132             (command-execute func))
5133           (gnus-summary-remove-process-mark article)))))
5134   (gnus-summary-position-point))
5135
5136 (defun gnus-summary-toggle-truncation (&optional arg)
5137   "Toggle truncation of summary lines.
5138 With arg, turn line truncation on iff arg is positive."
5139   (interactive "P")
5140   (setq truncate-lines
5141         (if (null arg) (not truncate-lines)
5142           (> (prefix-numeric-value arg) 0)))
5143   (redraw-display))
5144
5145 (defun gnus-summary-reselect-current-group (&optional all rescan)
5146   "Exit and then reselect the current newsgroup.
5147 The prefix argument ALL means to select all articles."
5148   (interactive "P")
5149   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5150     (error "Ephemeral groups can't be reselected"))
5151   (let ((current-subject (gnus-summary-article-number))
5152         (group gnus-newsgroup-name))
5153     (setq gnus-newsgroup-begin nil)
5154     (gnus-summary-exit)
5155     ;; We have to adjust the point of group mode buffer because
5156     ;; point was moved to the next unread newsgroup by exiting.
5157     (gnus-summary-jump-to-group group)
5158     (when rescan
5159       (save-excursion
5160         (gnus-group-get-new-news-this-group 1)))
5161     (gnus-group-read-group all t)
5162     (gnus-summary-goto-subject current-subject nil t)))
5163
5164 (defun gnus-summary-rescan-group (&optional all)
5165   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5166   (interactive "P")
5167   (gnus-summary-reselect-current-group all t))
5168
5169 (defun gnus-summary-update-info (&optional non-destructive)
5170   (save-excursion
5171     (let ((group gnus-newsgroup-name))
5172       (when group
5173         (when gnus-newsgroup-kill-headers
5174           (setq gnus-newsgroup-killed
5175                 (gnus-compress-sequence
5176                  (nconc
5177                   (gnus-set-sorted-intersection
5178                    (gnus-uncompress-range gnus-newsgroup-killed)
5179                    (setq gnus-newsgroup-unselected
5180                          (sort gnus-newsgroup-unselected '<)))
5181                   (setq gnus-newsgroup-unreads
5182                         (sort gnus-newsgroup-unreads '<)))
5183                  t)))
5184         (unless (listp (cdr gnus-newsgroup-killed))
5185           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5186         (let ((headers gnus-newsgroup-headers))
5187           ;; Set the new ranges of read articles.
5188           (save-excursion
5189             (set-buffer gnus-group-buffer)
5190             (gnus-undo-force-boundary))
5191           (gnus-update-read-articles
5192            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5193           ;; Set the current article marks.
5194           (let ((gnus-newsgroup-scored
5195                  (if (and (not gnus-save-score)
5196                           (not non-destructive))
5197                      nil
5198                    gnus-newsgroup-scored)))
5199             (save-excursion
5200               (gnus-update-marks)))
5201           ;; Do the cross-ref thing.
5202           (when gnus-use-cross-reference
5203             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5204           ;; Do not switch windows but change the buffer to work.
5205           (set-buffer gnus-group-buffer)
5206           (unless (gnus-ephemeral-group-p group)
5207             (gnus-group-update-group group)))))))
5208
5209 (defun gnus-summary-save-newsrc (&optional force)
5210   "Save the current number of read/marked articles in the dribble buffer.
5211 The dribble buffer will then be saved.
5212 If FORCE (the prefix), also save the .newsrc file(s)."
5213   (interactive "P")
5214   (gnus-summary-update-info t)
5215   (if force
5216       (gnus-save-newsrc-file)
5217     (gnus-dribble-save)))
5218
5219 (defun gnus-summary-exit (&optional temporary)
5220   "Exit reading current newsgroup, and then return to group selection mode.
5221 gnus-exit-group-hook is called with no arguments if that value is non-nil."
5222   (interactive)
5223   (gnus-set-global-variables)
5224   (gnus-kill-save-kill-buffer)
5225   (gnus-async-halt-prefetch)
5226   (let* ((group gnus-newsgroup-name)
5227          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5228          (mode major-mode)
5229          (group-point nil)
5230          (buf (current-buffer)))
5231     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5232     ;; If we have several article buffers, we kill them at exit.
5233     (unless gnus-single-article-buffer
5234       (gnus-kill-buffer gnus-original-article-buffer)
5235       (setq gnus-article-current nil))
5236     (when gnus-use-cache
5237       (gnus-cache-possibly-remove-articles)
5238       (gnus-cache-save-buffers))
5239     (gnus-async-prefetch-remove-group group)
5240     (when gnus-suppress-duplicates
5241       (gnus-dup-enter-articles))
5242     (when gnus-use-trees
5243       (gnus-tree-close group))
5244     ;; Remove entries for this group.
5245     (nnmail-purge-split-history (gnus-group-real-name group))
5246     ;; Make all changes in this group permanent.
5247     (unless quit-config
5248       (gnus-run-hooks 'gnus-exit-group-hook)
5249       (gnus-summary-update-info)
5250       ;; Do adaptive scoring, and possibly save score files.
5251       (when gnus-newsgroup-adaptive
5252         (gnus-score-adaptive))
5253       (when gnus-use-scoring
5254         (gnus-score-save)))
5255     (gnus-close-group group)
5256     ;; Make sure where we were, and go to next newsgroup.
5257     (set-buffer gnus-group-buffer)
5258     (unless quit-config
5259       (gnus-group-jump-to-group group))
5260     (gnus-run-hooks 'gnus-summary-exit-hook)
5261     (unless (or quit-config
5262                 ;; If this group has disappeared from the summary
5263                 ;; buffer, don't skip forwards.
5264                 (not (string= group (gnus-group-group-name))))
5265       (gnus-group-next-unread-group 1))
5266     (setq group-point (point))
5267     (if temporary
5268         nil                             ;Nothing to do.
5269       (when (gnus-buffer-live-p gnus-article-buffer)
5270         (save-excursion
5271           (set-buffer gnus-article-buffer)
5272           (mm-destroy-parts gnus-article-mime-handles)))
5273       ;; If we have several article buffers, we kill them at exit.
5274       (unless gnus-single-article-buffer
5275         (gnus-kill-buffer gnus-article-buffer)
5276         (gnus-kill-buffer gnus-original-article-buffer)
5277         (setq gnus-article-current nil))
5278       (set-buffer buf)
5279       (if (not gnus-kill-summary-on-exit)
5280           (gnus-deaden-summary)
5281         ;; We set all buffer-local variables to nil.  It is unclear why
5282         ;; this is needed, but if we don't, buffer-local variables are
5283         ;; not garbage-collected, it seems.  This would the lead to en
5284         ;; ever-growing Emacs.
5285         (gnus-summary-clear-local-variables)
5286         (when (get-buffer gnus-article-buffer)
5287           (bury-buffer gnus-article-buffer))
5288         ;; We clear the global counterparts of the buffer-local
5289         ;; variables as well, just to be on the safe side.
5290         (set-buffer gnus-group-buffer)
5291         (gnus-summary-clear-local-variables)
5292         ;; Return to group mode buffer.
5293         (when (eq mode 'gnus-summary-mode)
5294           (gnus-kill-buffer buf)))
5295       (setq gnus-current-select-method gnus-select-method)
5296       (pop-to-buffer gnus-group-buffer)
5297       (if (not quit-config)
5298           (progn
5299             (goto-char group-point)
5300             (gnus-configure-windows 'group 'force))
5301         (gnus-handle-ephemeral-exit quit-config))
5302       ;; Clear the current group name.
5303       (unless quit-config
5304         (setq gnus-newsgroup-name nil)))))
5305
5306 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5307 (defun gnus-summary-exit-no-update (&optional no-questions)
5308   "Quit reading current newsgroup without updating read article info."
5309   (interactive)
5310   (let* ((group gnus-newsgroup-name)
5311          (quit-config (gnus-group-quit-config group)))
5312     (when (or no-questions
5313               gnus-expert-user
5314               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5315       (gnus-async-halt-prefetch)
5316       (gnus-run-hooks (delq 'gnus-summary-expire-articles 
5317                             (copy-list gnus-summary-prepare-exit-hook)))
5318       (when (gnus-buffer-live-p gnus-article-buffer)
5319         (save-excursion
5320           (set-buffer gnus-article-buffer)
5321           (mm-destroy-parts gnus-article-mime-handles)))
5322       ;; If we have several article buffers, we kill them at exit.
5323       (unless gnus-single-article-buffer
5324         (gnus-kill-buffer gnus-article-buffer)
5325         (gnus-kill-buffer gnus-original-article-buffer)
5326         (setq gnus-article-current nil))
5327       (if (not gnus-kill-summary-on-exit)
5328           (gnus-deaden-summary)
5329         (gnus-close-group group)
5330         (gnus-summary-clear-local-variables)
5331         (set-buffer gnus-group-buffer)
5332         (gnus-summary-clear-local-variables)
5333         (when (get-buffer gnus-summary-buffer)
5334           (kill-buffer gnus-summary-buffer)))
5335       (unless gnus-single-article-buffer
5336         (setq gnus-article-current nil))
5337       (when gnus-use-trees
5338         (gnus-tree-close group))
5339       (gnus-async-prefetch-remove-group group)
5340       (when (get-buffer gnus-article-buffer)
5341         (bury-buffer gnus-article-buffer))
5342       ;; Return to the group buffer.
5343       (gnus-configure-windows 'group 'force)
5344       ;; Clear the current group name.
5345       (setq gnus-newsgroup-name nil)
5346       (when (equal (gnus-group-group-name) group)
5347         (gnus-group-next-unread-group 1))
5348       (when quit-config
5349         (gnus-handle-ephemeral-exit quit-config)))))
5350
5351 (defun gnus-handle-ephemeral-exit (quit-config)
5352   "Handle movement when leaving an ephemeral group.
5353 The state which existed when entering the ephemeral is reset."
5354   (if (not (buffer-name (car quit-config)))
5355       (gnus-configure-windows 'group 'force)
5356     (set-buffer (car quit-config))
5357     (cond ((eq major-mode 'gnus-summary-mode)
5358            (gnus-set-global-variables))
5359           ((eq major-mode 'gnus-article-mode)
5360            (save-excursion
5361              ;; The `gnus-summary-buffer' variable may point
5362              ;; to the old summary buffer when using a single
5363              ;; article buffer.
5364              (unless (gnus-buffer-live-p gnus-summary-buffer)
5365                (set-buffer gnus-group-buffer))
5366              (set-buffer gnus-summary-buffer)
5367              (gnus-set-global-variables))))
5368     (if (or (eq (cdr quit-config) 'article)
5369             (eq (cdr quit-config) 'pick))
5370         (progn
5371           ;; The current article may be from the ephemeral group
5372           ;; thus it is best that we reload this article
5373           (gnus-summary-show-article)
5374           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5375               (gnus-configure-windows 'pick 'force)
5376             (gnus-configure-windows (cdr quit-config) 'force)))
5377       (gnus-configure-windows (cdr quit-config) 'force))
5378     (when (eq major-mode 'gnus-summary-mode)
5379       (gnus-summary-next-subject 1 nil t)
5380       (gnus-summary-recenter)
5381       (gnus-summary-position-point))))
5382
5383 ;;; Dead summaries.
5384
5385 (defvar gnus-dead-summary-mode-map nil)
5386
5387 (unless gnus-dead-summary-mode-map
5388   (setq gnus-dead-summary-mode-map (make-keymap))
5389   (suppress-keymap gnus-dead-summary-mode-map)
5390   (substitute-key-definition
5391    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5392   (let ((keys '("\C-d" "\r" "\177" [delete])))
5393     (while keys
5394       (define-key gnus-dead-summary-mode-map
5395         (pop keys) 'gnus-summary-wake-up-the-dead))))
5396
5397 (defvar gnus-dead-summary-mode nil
5398   "Minor mode for Gnus summary buffers.")
5399
5400 (defun gnus-dead-summary-mode (&optional arg)
5401   "Minor mode for Gnus summary buffers."
5402   (interactive "P")
5403   (when (eq major-mode 'gnus-summary-mode)
5404     (make-local-variable 'gnus-dead-summary-mode)
5405     (setq gnus-dead-summary-mode
5406           (if (null arg) (not gnus-dead-summary-mode)
5407             (> (prefix-numeric-value arg) 0)))
5408     (when gnus-dead-summary-mode
5409       (gnus-add-minor-mode
5410        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5411
5412 (defun gnus-deaden-summary ()
5413   "Make the current summary buffer into a dead summary buffer."
5414   ;; Kill any previous dead summary buffer.
5415   (when (and gnus-dead-summary
5416              (buffer-name gnus-dead-summary))
5417     (save-excursion
5418       (set-buffer gnus-dead-summary)
5419       (when gnus-dead-summary-mode
5420         (kill-buffer (current-buffer)))))
5421   ;; Make this the current dead summary.
5422   (setq gnus-dead-summary (current-buffer))
5423   (gnus-dead-summary-mode 1)
5424   (let ((name (buffer-name)))
5425     (when (string-match "Summary" name)
5426       (rename-buffer
5427        (concat (substring name 0 (match-beginning 0)) "Dead "
5428                (substring name (match-beginning 0)))
5429        t))))
5430
5431 (defun gnus-kill-or-deaden-summary (buffer)
5432   "Kill or deaden the summary BUFFER."
5433   (save-excursion
5434     (when (and (buffer-name buffer)
5435                (not gnus-single-article-buffer))
5436       (save-excursion
5437         (set-buffer buffer)
5438         (gnus-kill-buffer gnus-article-buffer)
5439         (gnus-kill-buffer gnus-original-article-buffer)))
5440     (cond (gnus-kill-summary-on-exit
5441            (when (and gnus-use-trees
5442                       (gnus-buffer-exists-p buffer))
5443              (save-excursion
5444                (set-buffer buffer)
5445                (gnus-tree-close gnus-newsgroup-name)))
5446            (gnus-kill-buffer buffer))
5447           ((gnus-buffer-exists-p buffer)
5448            (save-excursion
5449              (set-buffer buffer)
5450              (gnus-deaden-summary))))))
5451
5452 (defun gnus-summary-wake-up-the-dead (&rest args)
5453   "Wake up the dead summary buffer."
5454   (interactive)
5455   (gnus-dead-summary-mode -1)
5456   (let ((name (buffer-name)))
5457     (when (string-match "Dead " name)
5458       (rename-buffer
5459        (concat (substring name 0 (match-beginning 0))
5460                (substring name (match-end 0)))
5461        t)))
5462   (gnus-message 3 "This dead summary is now alive again"))
5463
5464 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5465 (defun gnus-summary-fetch-faq (&optional faq-dir)
5466   "Fetch the FAQ for the current group.
5467 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5468 in."
5469   (interactive
5470    (list
5471     (when current-prefix-arg
5472       (completing-read
5473        "Faq dir: " (and (listp gnus-group-faq-directory)
5474                         (mapcar (lambda (file) (list file))
5475                                 gnus-group-faq-directory))))))
5476   (let (gnus-faq-buffer)
5477     (when (setq gnus-faq-buffer
5478                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5479       (gnus-configure-windows 'summary-faq))))
5480
5481 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5482 (defun gnus-summary-describe-group (&optional force)
5483   "Describe the current newsgroup."
5484   (interactive "P")
5485   (gnus-group-describe-group force gnus-newsgroup-name))
5486
5487 (defun gnus-summary-describe-briefly ()
5488   "Describe summary mode commands briefly."
5489   (interactive)
5490   (gnus-message 6
5491                 (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")))
5492
5493 ;; Walking around group mode buffer from summary mode.
5494
5495 (defun gnus-summary-next-group (&optional no-article target-group backward)
5496   "Exit current newsgroup and then select next unread newsgroup.
5497 If prefix argument NO-ARTICLE is non-nil, no article is selected
5498 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5499 previous group instead."
5500   (interactive "P")
5501   ;; Stop pre-fetching.
5502   (gnus-async-halt-prefetch)
5503   (let ((current-group gnus-newsgroup-name)
5504         (current-buffer (current-buffer))
5505         entered)
5506     ;; First we semi-exit this group to update Xrefs and all variables.
5507     ;; We can't do a real exit, because the window conf must remain
5508     ;; the same in case the user is prompted for info, and we don't
5509     ;; want the window conf to change before that...
5510     (gnus-summary-exit t)
5511     (while (not entered)
5512       ;; Then we find what group we are supposed to enter.
5513       (set-buffer gnus-group-buffer)
5514       (gnus-group-jump-to-group current-group)
5515       (setq target-group
5516             (or target-group
5517                 (if (eq gnus-keep-same-level 'best)
5518                     (gnus-summary-best-group gnus-newsgroup-name)
5519                   (gnus-summary-search-group backward gnus-keep-same-level))))
5520       (if (not target-group)
5521           ;; There are no further groups, so we return to the group
5522           ;; buffer.
5523           (progn
5524             (gnus-message 5 "Returning to the group buffer")
5525             (setq entered t)
5526             (when (gnus-buffer-live-p current-buffer)
5527               (set-buffer current-buffer)
5528               (gnus-summary-exit))
5529             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5530         ;; We try to enter the target group.
5531         (gnus-group-jump-to-group target-group)
5532         (let ((unreads (gnus-group-group-unread)))
5533           (if (and (or (eq t unreads)
5534                        (and unreads (not (zerop unreads))))
5535                    (gnus-summary-read-group
5536                     target-group nil no-article
5537                     (and (buffer-name current-buffer) current-buffer)
5538                     nil backward))
5539               (setq entered t)
5540             (setq current-group target-group
5541                   target-group nil)))))))
5542
5543 (defun gnus-summary-prev-group (&optional no-article)
5544   "Exit current newsgroup and then select previous unread newsgroup.
5545 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5546   (interactive "P")
5547   (gnus-summary-next-group no-article nil t))
5548
5549 ;; Walking around summary lines.
5550
5551 (defun gnus-summary-first-subject (&optional unread undownloaded)
5552   "Go to the first unread subject.
5553 If UNREAD is non-nil, go to the first unread article.
5554 Returns the article selected or nil if there are no unread articles."
5555   (interactive "P")
5556   (prog1
5557       (cond
5558        ;; Empty summary.
5559        ((null gnus-newsgroup-data)
5560         (gnus-message 3 "No articles in the group")
5561         nil)
5562        ;; Pick the first article.
5563        ((not unread)
5564         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5565         (gnus-data-number (car gnus-newsgroup-data)))
5566        ;; No unread articles.
5567        ((null gnus-newsgroup-unreads)
5568         (gnus-message 3 "No more unread articles")
5569         nil)
5570        ;; Find the first unread article.
5571        (t
5572         (let ((data gnus-newsgroup-data))
5573           (while (and data
5574                       (and (not (and undownloaded
5575                                      (eq gnus-undownloaded-mark
5576                                          (gnus-data-mark (car data)))))
5577                            (not (gnus-data-unread-p (car data)))))
5578             (setq data (cdr data)))
5579           (when data
5580             (goto-char (gnus-data-pos (car data)))
5581             (gnus-data-number (car data))))))
5582     (gnus-summary-position-point)))
5583
5584 (defun gnus-summary-next-subject (n &optional unread dont-display)
5585   "Go to next N'th summary line.
5586 If N is negative, go to the previous N'th subject line.
5587 If UNREAD is non-nil, only unread articles are selected.
5588 The difference between N and the actual number of steps taken is
5589 returned."
5590   (interactive "p")
5591   (let ((backward (< n 0))
5592         (n (abs n)))
5593     (while (and (> n 0)
5594                 (if backward
5595                     (gnus-summary-find-prev unread)
5596                   (gnus-summary-find-next unread)))
5597       (gnus-summary-show-thread)
5598       (setq n (1- n)))
5599     (when (/= 0 n)
5600       (gnus-message 7 "No more%s articles"
5601                     (if unread " unread" "")))
5602     (unless dont-display
5603       (gnus-summary-recenter)
5604       (gnus-summary-position-point))
5605     n))
5606
5607 (defun gnus-summary-next-unread-subject (n)
5608   "Go to next N'th unread summary line."
5609   (interactive "p")
5610   (gnus-summary-next-subject n t))
5611
5612 (defun gnus-summary-prev-subject (n &optional unread)
5613   "Go to previous N'th summary line.
5614 If optional argument UNREAD is non-nil, only unread article is selected."
5615   (interactive "p")
5616   (gnus-summary-next-subject (- n) unread))
5617
5618 (defun gnus-summary-prev-unread-subject (n)
5619   "Go to previous N'th unread summary line."
5620   (interactive "p")
5621   (gnus-summary-next-subject (- n) t))
5622
5623 (defun gnus-summary-goto-subject (article &optional force silent)
5624   "Go the subject line of ARTICLE.
5625 If FORCE, also allow jumping to articles not currently shown."
5626   (interactive "nArticle number: ")
5627   (let ((b (point))
5628         (data (gnus-data-find article)))
5629     ;; We read in the article if we have to.
5630     (and (not data)
5631          force
5632          (gnus-summary-insert-subject
5633           article
5634           (if (or (numberp force) (vectorp force)) force)
5635           t)
5636          (setq data (gnus-data-find article)))
5637     (goto-char b)
5638     (if (not data)
5639         (progn
5640           (unless silent
5641             (gnus-message 3 "Can't find article %d" article))
5642           nil)
5643       (goto-char (gnus-data-pos data))
5644       (gnus-summary-position-point)
5645       article)))
5646
5647 ;; Walking around summary lines with displaying articles.
5648
5649 (defun gnus-summary-expand-window (&optional arg)
5650   "Make the summary buffer take up the entire Emacs frame.
5651 Given a prefix, will force an `article' buffer configuration."
5652   (interactive "P")
5653   (if arg
5654       (gnus-configure-windows 'article 'force)
5655     (gnus-configure-windows 'summary 'force)))
5656
5657 (defun gnus-summary-display-article (article &optional all-header)
5658   "Display ARTICLE in article buffer."
5659   (gnus-set-global-variables)
5660   (if (null article)
5661       nil
5662     (prog1
5663         (if gnus-summary-display-article-function
5664             (funcall gnus-summary-display-article-function article all-header)
5665           (gnus-article-prepare article all-header))
5666       (gnus-run-hooks 'gnus-select-article-hook)
5667       (when (and gnus-current-article
5668                  (not (zerop gnus-current-article)))
5669         (gnus-summary-goto-subject gnus-current-article))
5670       (gnus-summary-recenter)
5671       (when (and gnus-use-trees gnus-show-threads)
5672         (gnus-possibly-generate-tree article)
5673         (gnus-highlight-selected-tree article))
5674       ;; Successfully display article.
5675       (gnus-article-set-window-start
5676        (cdr (assq article gnus-newsgroup-bookmarks))))))
5677
5678 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5679   "Select the current article.
5680 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5681 non-nil, the article will be re-fetched even if it already present in
5682 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5683 be displayed."
5684   ;; Make sure we are in the summary buffer to work around bbdb bug.
5685   (unless (eq major-mode 'gnus-summary-mode)
5686     (set-buffer gnus-summary-buffer))
5687   (let ((article (or article (gnus-summary-article-number)))
5688         (all-headers (not (not all-headers))) ;Must be T or NIL.
5689         gnus-summary-display-article-function
5690         did)
5691     (and (not pseudo)
5692          (gnus-summary-article-pseudo-p article)
5693          (error "This is a pseudo-article"))
5694     (prog1
5695         (save-excursion
5696           (set-buffer gnus-summary-buffer)
5697           (if (or (and gnus-single-article-buffer
5698                        (or (null gnus-current-article)
5699                            (null gnus-article-current)
5700                            (null (get-buffer gnus-article-buffer))
5701                            (not (eq article (cdr gnus-article-current)))
5702                            (not (equal (car gnus-article-current)
5703                                        gnus-newsgroup-name))))
5704                   (and (not gnus-single-article-buffer)
5705                        (or (null gnus-current-article)
5706                            (not (eq gnus-current-article article))))
5707                   force)
5708               ;; The requested article is different from the current article.
5709               (prog1
5710                   (gnus-summary-display-article article all-headers)
5711                 (setq did article))
5712             (when (or all-headers gnus-show-all-headers)
5713               (gnus-article-show-all-headers))
5714             'old))
5715       (when did
5716         (gnus-article-set-window-start
5717          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5718
5719 (defun gnus-summary-set-current-mark (&optional current-mark)
5720   "Obsolete function."
5721   nil)
5722
5723 (defun gnus-summary-next-article (&optional unread subject backward push)
5724   "Select the next article.
5725 If UNREAD, only unread articles are selected.
5726 If SUBJECT, only articles with SUBJECT are selected.
5727 If BACKWARD, the previous article is selected instead of the next."
5728   (interactive "P")
5729   (cond
5730    ;; Is there such an article?
5731    ((and (gnus-summary-search-forward unread subject backward)
5732          (or (gnus-summary-display-article (gnus-summary-article-number))
5733              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5734     (gnus-summary-position-point))
5735    ;; If not, we try the first unread, if that is wanted.
5736    ((and subject
5737          gnus-auto-select-same
5738          (gnus-summary-first-unread-article))
5739     (gnus-summary-position-point)
5740     (gnus-message 6 "Wrapped"))
5741    ;; Try to get next/previous article not displayed in this group.
5742    ((and gnus-auto-extend-newsgroup
5743          (not unread) (not subject))
5744     (gnus-summary-goto-article
5745      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5746      nil (count-lines (point-min) (point))))
5747    ;; Go to next/previous group.
5748    (t
5749     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5750       (gnus-summary-jump-to-group gnus-newsgroup-name))
5751     (let ((cmd last-command-char)
5752           (point
5753            (save-excursion
5754              (set-buffer gnus-group-buffer)
5755              (point)))
5756           (group
5757            (if (eq gnus-keep-same-level 'best)
5758                (gnus-summary-best-group gnus-newsgroup-name)
5759              (gnus-summary-search-group backward gnus-keep-same-level))))
5760       ;; For some reason, the group window gets selected.  We change
5761       ;; it back.
5762       (select-window (get-buffer-window (current-buffer)))
5763       ;; Select next unread newsgroup automagically.
5764       (cond
5765        ((or (not gnus-auto-select-next)
5766             (not cmd))
5767         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5768        ((or (eq gnus-auto-select-next 'quietly)
5769             (and (eq gnus-auto-select-next 'slightly-quietly)
5770                  push)
5771             (and (eq gnus-auto-select-next 'almost-quietly)
5772                  (gnus-summary-last-article-p)))
5773         ;; Select quietly.
5774         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5775             (gnus-summary-exit)
5776           (gnus-message 7 "No more%s articles (%s)..."
5777                         (if unread " unread" "")
5778                         (if group (concat "selecting " group)
5779                           "exiting"))
5780           (gnus-summary-next-group nil group backward)))
5781        (t
5782         (when (gnus-key-press-event-p last-input-event)
5783           (gnus-summary-walk-group-buffer
5784            gnus-newsgroup-name cmd unread backward point))))))))
5785
5786 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5787   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5788                       (?\C-p (gnus-group-prev-unread-group 1))))
5789         (cursor-in-echo-area t)
5790         keve key group ended)
5791     (save-excursion
5792       (set-buffer gnus-group-buffer)
5793       (goto-char start)
5794       (setq group
5795             (if (eq gnus-keep-same-level 'best)
5796                 (gnus-summary-best-group gnus-newsgroup-name)
5797               (gnus-summary-search-group backward gnus-keep-same-level))))
5798     (while (not ended)
5799       (gnus-message
5800        5 "No more%s articles%s" (if unread " unread" "")
5801        (if (and group
5802                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5803            (format " (Type %s for %s [%s])"
5804                    (single-key-description cmd) group
5805                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5806          (format " (Type %s to exit %s)"
5807                  (single-key-description cmd)
5808                  gnus-newsgroup-name)))
5809       ;; Confirm auto selection.
5810       (setq key (car (setq keve (gnus-read-event-char))))
5811       (setq ended t)
5812       (cond
5813        ((assq key keystrokes)
5814         (let ((obuf (current-buffer)))
5815           (switch-to-buffer gnus-group-buffer)
5816           (when group
5817             (gnus-group-jump-to-group group))
5818           (eval (cadr (assq key keystrokes)))
5819           (setq group (gnus-group-group-name))
5820           (switch-to-buffer obuf))
5821         (setq ended nil))
5822        ((equal key cmd)
5823         (if (or (not group)
5824                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5825             (gnus-summary-exit)
5826           (gnus-summary-next-group nil group backward)))
5827        (t
5828         (push (cdr keve) unread-command-events))))))
5829
5830 (defun gnus-summary-next-unread-article ()
5831   "Select unread article after current one."
5832   (interactive)
5833   (gnus-summary-next-article
5834    (or (not (eq gnus-summary-goto-unread 'never))
5835        (gnus-summary-last-article-p (gnus-summary-article-number)))
5836    (and gnus-auto-select-same
5837         (gnus-summary-article-subject))))
5838
5839 (defun gnus-summary-prev-article (&optional unread subject)
5840   "Select the article after the current one.
5841 If UNREAD is non-nil, only unread articles are selected."
5842   (interactive "P")
5843   (gnus-summary-next-article unread subject t))
5844
5845 (defun gnus-summary-prev-unread-article ()
5846   "Select unread article before current one."
5847   (interactive)
5848   (gnus-summary-prev-article
5849    (or (not (eq gnus-summary-goto-unread 'never))
5850        (gnus-summary-first-article-p (gnus-summary-article-number)))
5851    (and gnus-auto-select-same
5852         (gnus-summary-article-subject))))
5853
5854 (defun gnus-summary-next-page (&optional lines circular)
5855   "Show next page of the selected article.
5856 If at the end of the current article, select the next article.
5857 LINES says how many lines should be scrolled up.
5858
5859 If CIRCULAR is non-nil, go to the start of the article instead of
5860 selecting the next article when reaching the end of the current
5861 article."
5862   (interactive "P")
5863   (setq gnus-summary-buffer (current-buffer))
5864   (gnus-set-global-variables)
5865   (let ((article (gnus-summary-article-number))
5866         (article-window (get-buffer-window gnus-article-buffer t))
5867         endp)
5868     ;; If the buffer is empty, we have no article.
5869     (unless article
5870       (error "No article to select"))
5871     (gnus-configure-windows 'article)
5872     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5873         (if (and (eq gnus-summary-goto-unread 'never)
5874                  (not (gnus-summary-last-article-p article)))
5875             (gnus-summary-next-article)
5876           (gnus-summary-next-unread-article))
5877       (if (or (null gnus-current-article)
5878               (null gnus-article-current)
5879               (/= article (cdr gnus-article-current))
5880               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5881           ;; Selected subject is different from current article's.
5882           (gnus-summary-display-article article)
5883         (when article-window
5884           (gnus-eval-in-buffer-window gnus-article-buffer
5885             (setq endp (gnus-article-next-page lines)))
5886           (when endp
5887             (cond (circular
5888                    (gnus-summary-beginning-of-article))
5889                   (lines
5890                    (gnus-message 3 "End of message"))
5891                   ((null lines)
5892                    (if (and (eq gnus-summary-goto-unread 'never)
5893                             (not (gnus-summary-last-article-p article)))
5894                        (gnus-summary-next-article)
5895                      (gnus-summary-next-unread-article))))))))
5896     (gnus-summary-recenter)
5897     (gnus-summary-position-point)))
5898
5899 (defun gnus-summary-prev-page (&optional lines move)
5900   "Show previous page of selected article.
5901 Argument LINES specifies lines to be scrolled down.
5902 If MOVE, move to the previous unread article if point is at
5903 the beginning of the buffer."
5904   (interactive "P")
5905   (let ((article (gnus-summary-article-number))
5906         (article-window (get-buffer-window gnus-article-buffer t))
5907         endp)
5908     (gnus-configure-windows 'article)
5909     (if (or (null gnus-current-article)
5910             (null gnus-article-current)
5911             (/= article (cdr gnus-article-current))
5912             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5913         ;; Selected subject is different from current article's.
5914         (gnus-summary-display-article article)
5915       (gnus-summary-recenter)
5916       (when article-window
5917         (gnus-eval-in-buffer-window gnus-article-buffer
5918           (setq endp (gnus-article-prev-page lines)))
5919         (when (and move endp)
5920           (cond (lines
5921                  (gnus-message 3 "Beginning of message"))
5922                 ((null lines)
5923                  (if (and (eq gnus-summary-goto-unread 'never)
5924                           (not (gnus-summary-first-article-p article)))
5925                      (gnus-summary-prev-article)
5926                    (gnus-summary-prev-unread-article))))))))
5927   (gnus-summary-position-point))
5928
5929 (defun gnus-summary-prev-page-or-article (&optional lines)
5930   "Show previous page of selected article.
5931 Argument LINES specifies lines to be scrolled down.
5932 If at the beginning of the article, go to the next article."
5933   (interactive "P")
5934   (gnus-summary-prev-page lines t))
5935
5936 (defun gnus-summary-scroll-up (lines)
5937   "Scroll up (or down) one line current article.
5938 Argument LINES specifies lines to be scrolled up (or down if negative)."
5939   (interactive "p")
5940   (gnus-configure-windows 'article)
5941   (gnus-summary-show-thread)
5942   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
5943     (gnus-eval-in-buffer-window gnus-article-buffer
5944       (cond ((> lines 0)
5945              (when (gnus-article-next-page lines)
5946                (gnus-message 3 "End of message")))
5947             ((< lines 0)
5948              (gnus-article-prev-page (- lines))))))
5949   (gnus-summary-recenter)
5950   (gnus-summary-position-point))
5951
5952 (defun gnus-summary-scroll-down (lines)
5953   "Scroll down (or up) one line current article.
5954 Argument LINES specifies lines to be scrolled down (or up if negative)."
5955   (interactive "p")
5956   (gnus-summary-scroll-up (- lines)))
5957
5958 (defun gnus-summary-next-same-subject ()
5959   "Select next article which has the same subject as current one."
5960   (interactive)
5961   (gnus-summary-next-article nil (gnus-summary-article-subject)))
5962
5963 (defun gnus-summary-prev-same-subject ()
5964   "Select previous article which has the same subject as current one."
5965   (interactive)
5966   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
5967
5968 (defun gnus-summary-next-unread-same-subject ()
5969   "Select next unread article which has the same subject as current one."
5970   (interactive)
5971   (gnus-summary-next-article t (gnus-summary-article-subject)))
5972
5973 (defun gnus-summary-prev-unread-same-subject ()
5974   "Select previous unread article which has the same subject as current one."
5975   (interactive)
5976   (gnus-summary-prev-article t (gnus-summary-article-subject)))
5977
5978 (defun gnus-summary-first-unread-article ()
5979   "Select the first unread article.
5980 Return nil if there are no unread articles."
5981   (interactive)
5982   (prog1
5983       (when (gnus-summary-first-subject t)
5984         (gnus-summary-show-thread)
5985         (gnus-summary-first-subject t)
5986         (gnus-summary-display-article (gnus-summary-article-number)))
5987     (gnus-summary-position-point)))
5988
5989 (defun gnus-summary-first-unread-subject ()
5990   "Place the point on the subject line of the first unread article.
5991 Return nil if there are no unread articles."
5992   (interactive)
5993   (prog1
5994       (when (gnus-summary-first-subject t)
5995         (gnus-summary-show-thread)
5996         (gnus-summary-first-subject t))
5997     (gnus-summary-position-point)))
5998
5999 (defun gnus-summary-first-article ()
6000   "Select the first article.
6001 Return nil if there are no articles."
6002   (interactive)
6003   (prog1
6004       (when (gnus-summary-first-subject)
6005         (gnus-summary-show-thread)
6006         (gnus-summary-first-subject)
6007         (gnus-summary-display-article (gnus-summary-article-number)))
6008     (gnus-summary-position-point)))
6009
6010 (defun gnus-summary-best-unread-article ()
6011   "Select the unread article with the highest score."
6012   (interactive)
6013   (let ((best -1000000)
6014         (data gnus-newsgroup-data)
6015         article score)
6016     (while data
6017       (and (gnus-data-unread-p (car data))
6018            (> (setq score
6019                     (gnus-summary-article-score (gnus-data-number (car data))))
6020               best)
6021            (setq best score
6022                  article (gnus-data-number (car data))))
6023       (setq data (cdr data)))
6024     (prog1
6025         (if article
6026             (gnus-summary-goto-article article)
6027           (error "No unread articles"))
6028       (gnus-summary-position-point))))
6029
6030 (defun gnus-summary-last-subject ()
6031   "Go to the last displayed subject line in the group."
6032   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6033     (when article
6034       (gnus-summary-goto-subject article))))
6035
6036 (defun gnus-summary-goto-article (article &optional all-headers force)
6037   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6038 If ALL-HEADERS is non-nil, no header lines are hidden.
6039 If FORCE, go to the article even if it isn't displayed.  If FORCE
6040 is a number, it is the line the article is to be displayed on."
6041   (interactive
6042    (list
6043     (completing-read
6044      "Article number or Message-ID: "
6045      (mapcar (lambda (number) (list (int-to-string number)))
6046              gnus-newsgroup-limit))
6047     current-prefix-arg
6048     t))
6049   (prog1
6050       (if (and (stringp article)
6051                (string-match "@" article))
6052           (gnus-summary-refer-article article)
6053         (when (stringp article)
6054           (setq article (string-to-number article)))
6055         (if (gnus-summary-goto-subject article force)
6056             (gnus-summary-display-article article all-headers)
6057           (gnus-message 4 "Couldn't go to article %s" article) nil))
6058     (gnus-summary-position-point)))
6059
6060 (defun gnus-summary-goto-last-article ()
6061   "Go to the previously read article."
6062   (interactive)
6063   (prog1
6064       (when gnus-last-article
6065         (gnus-summary-goto-article gnus-last-article nil t))
6066     (gnus-summary-position-point)))
6067
6068 (defun gnus-summary-pop-article (number)
6069   "Pop one article off the history and go to the previous.
6070 NUMBER articles will be popped off."
6071   (interactive "p")
6072   (let (to)
6073     (setq gnus-newsgroup-history
6074           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6075     (if to
6076         (gnus-summary-goto-article (car to) nil t)
6077       (error "Article history empty")))
6078   (gnus-summary-position-point))
6079
6080 ;; Summary commands and functions for limiting the summary buffer.
6081
6082 (defun gnus-summary-limit-to-articles (n)
6083   "Limit the summary buffer to the next N articles.
6084 If not given a prefix, use the process marked articles instead."
6085   (interactive "P")
6086   (prog1
6087       (let ((articles (gnus-summary-work-articles n)))
6088         (setq gnus-newsgroup-processable nil)
6089         (gnus-summary-limit articles))
6090     (gnus-summary-position-point)))
6091
6092 (defun gnus-summary-pop-limit (&optional total)
6093   "Restore the previous limit.
6094 If given a prefix, remove all limits."
6095   (interactive "P")
6096   (when total
6097     (setq gnus-newsgroup-limits
6098           (list (mapcar (lambda (h) (mail-header-number h))
6099                         gnus-newsgroup-headers))))
6100   (unless gnus-newsgroup-limits
6101     (error "No limit to pop"))
6102   (prog1
6103       (gnus-summary-limit nil 'pop)
6104     (gnus-summary-position-point)))
6105
6106 (defun gnus-summary-limit-to-subject (subject &optional header)
6107   "Limit the summary buffer to articles that have subjects that match a regexp."
6108   (interactive "sLimit to subject (regexp): ")
6109   (unless header
6110     (setq header "subject"))
6111   (when (not (equal "" subject))
6112     (prog1
6113         (let ((articles (gnus-summary-find-matching
6114                          (or header "subject") subject 'all)))
6115           (unless articles
6116             (error "Found no matches for \"%s\"" subject))
6117           (gnus-summary-limit articles))
6118       (gnus-summary-position-point))))
6119
6120 (defun gnus-summary-limit-to-author (from)
6121   "Limit the summary buffer to articles that have authors that match a regexp."
6122   (interactive "sLimit to author (regexp): ")
6123   (gnus-summary-limit-to-subject from "from"))
6124
6125 (defun gnus-summary-limit-to-age (age &optional younger-p)
6126   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6127 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6128 articles that are younger than AGE days."
6129   (interactive "nTime in days: \nP")
6130   (prog1
6131       (let ((data gnus-newsgroup-data)
6132             (cutoff (days-to-time age))
6133             articles d date is-younger)
6134         (while (setq d (pop data))
6135           (when (and (vectorp (gnus-data-header d))
6136                      (setq date (mail-header-date (gnus-data-header d))))
6137             (setq is-younger (time-less-p
6138                               (time-since (date-to-time date))
6139                               cutoff))
6140             (when (if younger-p
6141                       is-younger
6142                     (not is-younger))
6143               (push (gnus-data-number d) articles))))
6144         (gnus-summary-limit (nreverse articles)))
6145     (gnus-summary-position-point)))
6146
6147 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6148 (make-obsolete
6149  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6150
6151 (defun gnus-summary-limit-to-unread (&optional all)
6152   "Limit the summary buffer to articles that are not marked as read.
6153 If ALL is non-nil, limit strictly to unread articles."
6154   (interactive "P")
6155   (if all
6156       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6157     (gnus-summary-limit-to-marks
6158      ;; Concat all the marks that say that an article is read and have
6159      ;; those removed.
6160      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6161            gnus-killed-mark gnus-kill-file-mark
6162            gnus-low-score-mark gnus-expirable-mark
6163            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6164            gnus-duplicate-mark gnus-souped-mark)
6165      'reverse)))
6166
6167 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6168 (make-obsolete 'gnus-summary-delete-marked-with
6169                'gnus-summary-limit-exlude-marks)
6170
6171 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6172   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6173 If REVERSE, limit the summary buffer to articles that are marked
6174 with MARKS.  MARKS can either be a string of marks or a list of marks.
6175 Returns how many articles were removed."
6176   (interactive "sMarks: ")
6177   (gnus-summary-limit-to-marks marks t))
6178
6179 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6180   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6181 If REVERSE (the prefix), limit the summary buffer to articles that are
6182 not marked with MARKS.  MARKS can either be a string of marks or a
6183 list of marks.
6184 Returns how many articles were removed."
6185   (interactive "sMarks: \nP")
6186   (prog1
6187       (let ((data gnus-newsgroup-data)
6188             (marks (if (listp marks) marks
6189                      (append marks nil))) ; Transform to list.
6190             articles)
6191         (while data
6192           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6193                   (memq (gnus-data-mark (car data)) marks))
6194             (push (gnus-data-number (car data)) articles))
6195           (setq data (cdr data)))
6196         (gnus-summary-limit articles))
6197     (gnus-summary-position-point)))
6198
6199 (defun gnus-summary-limit-to-score (&optional score)
6200   "Limit to articles with score at or above SCORE."
6201   (interactive "P")
6202   (setq score (if score
6203                   (prefix-numeric-value score)
6204                 (or gnus-summary-default-score 0)))
6205   (let ((data gnus-newsgroup-data)
6206         articles)
6207     (while data
6208       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6209                 score)
6210         (push (gnus-data-number (car data)) articles))
6211       (setq data (cdr data)))
6212     (prog1
6213         (gnus-summary-limit articles)
6214       (gnus-summary-position-point))))
6215
6216 (defun gnus-summary-limit-include-thread (id)
6217   "Display all the hidden articles that in the current thread."
6218   (interactive (list (mail-header-id (gnus-summary-article-header))))
6219   (let ((articles (gnus-articles-in-thread
6220                    (gnus-id-to-thread (gnus-root-id id)))))
6221     (prog1
6222         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6223       (gnus-summary-position-point))))
6224
6225 (defun gnus-summary-limit-include-dormant ()
6226   "Display all the hidden articles that are marked as dormant.
6227 Note that this command only works on a subset of the articles currently
6228 fetched for this group."
6229   (interactive)
6230   (unless gnus-newsgroup-dormant
6231     (error "There are no dormant articles in this group"))
6232   (prog1
6233       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6234     (gnus-summary-position-point)))
6235
6236 (defun gnus-summary-limit-exclude-dormant ()
6237   "Hide all dormant articles."
6238   (interactive)
6239   (prog1
6240       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6241     (gnus-summary-position-point)))
6242
6243 (defun gnus-summary-limit-exclude-childless-dormant ()
6244   "Hide all dormant articles that have no children."
6245   (interactive)
6246   (let ((data (gnus-data-list t))
6247         articles d children)
6248     ;; Find all articles that are either not dormant or have
6249     ;; children.
6250     (while (setq d (pop data))
6251       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6252                 (and (setq children
6253                            (gnus-article-children (gnus-data-number d)))
6254                      (let (found)
6255                        (while children
6256                          (when (memq (car children) articles)
6257                            (setq children nil
6258                                  found t))
6259                          (pop children))
6260                        found)))
6261         (push (gnus-data-number d) articles)))
6262     ;; Do the limiting.
6263     (prog1
6264         (gnus-summary-limit articles)
6265       (gnus-summary-position-point))))
6266
6267 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6268   "Mark all unread excluded articles as read.
6269 If ALL, mark even excluded ticked and dormants as read."
6270   (interactive "P")
6271   (let ((articles (gnus-sorted-complement
6272                    (sort
6273                     (mapcar (lambda (h) (mail-header-number h))
6274                             gnus-newsgroup-headers)
6275                     '<)
6276                    (sort gnus-newsgroup-limit '<)))
6277         article)
6278     (setq gnus-newsgroup-unreads
6279           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6280     (if all
6281         (setq gnus-newsgroup-dormant nil
6282               gnus-newsgroup-marked nil
6283               gnus-newsgroup-reads
6284               (nconc
6285                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6286                gnus-newsgroup-reads))
6287       (while (setq article (pop articles))
6288         (unless (or (memq article gnus-newsgroup-dormant)
6289                     (memq article gnus-newsgroup-marked))
6290           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6291
6292 (defun gnus-summary-limit (articles &optional pop)
6293   (if pop
6294       ;; We pop the previous limit off the stack and use that.
6295       (setq articles (car gnus-newsgroup-limits)
6296             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6297     ;; We use the new limit, so we push the old limit on the stack.
6298     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6299   ;; Set the limit.
6300   (setq gnus-newsgroup-limit articles)
6301   (let ((total (length gnus-newsgroup-data))
6302         (data (gnus-data-find-list (gnus-summary-article-number)))
6303         (gnus-summary-mark-below nil)   ; Inhibit this.
6304         found)
6305     ;; This will do all the work of generating the new summary buffer
6306     ;; according to the new limit.
6307     (gnus-summary-prepare)
6308     ;; Hide any threads, possibly.
6309     (and gnus-show-threads
6310          gnus-thread-hide-subtree
6311          (gnus-summary-hide-all-threads))
6312     ;; Try to return to the article you were at, or one in the
6313     ;; neighborhood.
6314     (when data
6315       ;; We try to find some article after the current one.
6316       (while data
6317         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6318           (setq data nil
6319                 found t))
6320         (setq data (cdr data))))
6321     (unless found
6322       ;; If there is no data, that means that we were after the last
6323       ;; article.  The same goes when we can't find any articles
6324       ;; after the current one.
6325       (goto-char (point-max))
6326       (gnus-summary-find-prev))
6327     (gnus-set-mode-line 'summary)
6328     ;; We return how many articles were removed from the summary
6329     ;; buffer as a result of the new limit.
6330     (- total (length gnus-newsgroup-data))))
6331
6332 (defsubst gnus-invisible-cut-children (threads)
6333   (let ((num 0))
6334     (while threads
6335       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6336         (incf num))
6337       (pop threads))
6338     (< num 2)))
6339
6340 (defsubst gnus-cut-thread (thread)
6341   "Go forwards in the thread until we find an article that we want to display."
6342   (when (or (eq gnus-fetch-old-headers 'some)
6343             (eq gnus-fetch-old-headers 'invisible)
6344             (eq gnus-build-sparse-threads 'some)
6345             (eq gnus-build-sparse-threads 'more))
6346     ;; Deal with old-fetched headers and sparse threads.
6347     (while (and
6348             thread
6349             (or
6350              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6351              (gnus-summary-article-ancient-p
6352               (mail-header-number (car thread))))
6353             (if (or (<= (length (cdr thread)) 1)
6354                     (eq gnus-fetch-old-headers 'invisible))
6355                 (setq gnus-newsgroup-limit
6356                       (delq (mail-header-number (car thread))
6357                             gnus-newsgroup-limit)
6358                       thread (cadr thread))
6359               (when (gnus-invisible-cut-children (cdr thread))
6360                 (let ((th (cdr thread)))
6361                   (while th
6362                     (if (memq (mail-header-number (caar th))
6363                               gnus-newsgroup-limit)
6364                         (setq thread (car th)
6365                               th nil)
6366                       (setq th (cdr th))))))))))
6367   thread)
6368
6369 (defun gnus-cut-threads (threads)
6370   "Cut off all uninteresting articles from the beginning of threads."
6371   (when (or (eq gnus-fetch-old-headers 'some)
6372             (eq gnus-fetch-old-headers 'invisible)
6373             (eq gnus-build-sparse-threads 'some)
6374             (eq gnus-build-sparse-threads 'more))
6375     (let ((th threads))
6376       (while th
6377         (setcar th (gnus-cut-thread (car th)))
6378         (setq th (cdr th)))))
6379   ;; Remove nixed out threads.
6380   (delq nil threads))
6381
6382 (defun gnus-summary-initial-limit (&optional show-if-empty)
6383   "Figure out what the initial limit is supposed to be on group entry.
6384 This entails weeding out unwanted dormants, low-scored articles,
6385 fetch-old-headers verbiage, and so on."
6386   ;; Most groups have nothing to remove.
6387   (if (or gnus-inhibit-limiting
6388           (and (null gnus-newsgroup-dormant)
6389                (not (eq gnus-fetch-old-headers 'some))
6390                (not (eq gnus-fetch-old-headers 'invisible))
6391                (null gnus-summary-expunge-below)
6392                (not (eq gnus-build-sparse-threads 'some))
6393                (not (eq gnus-build-sparse-threads 'more))
6394                (null gnus-thread-expunge-below)
6395                (not gnus-use-nocem)))
6396       ()                                ; Do nothing.
6397     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6398     (setq gnus-newsgroup-limit nil)
6399     (mapatoms
6400      (lambda (node)
6401        (unless (car (symbol-value node))
6402          ;; These threads have no parents -- they are roots.
6403          (let ((nodes (cdr (symbol-value node)))
6404                thread)
6405            (while nodes
6406              (if (and gnus-thread-expunge-below
6407                       (< (gnus-thread-total-score (car nodes))
6408                          gnus-thread-expunge-below))
6409                  (gnus-expunge-thread (pop nodes))
6410                (setq thread (pop nodes))
6411                (gnus-summary-limit-children thread))))))
6412      gnus-newsgroup-dependencies)
6413     ;; If this limitation resulted in an empty group, we might
6414     ;; pop the previous limit and use it instead.
6415     (when (and (not gnus-newsgroup-limit)
6416                show-if-empty)
6417       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6418     gnus-newsgroup-limit))
6419
6420 (defun gnus-summary-limit-children (thread)
6421   "Return 1 if this subthread is visible and 0 if it is not."
6422   ;; First we get the number of visible children to this thread.  This
6423   ;; is done by recursing down the thread using this function, so this
6424   ;; will really go down to a leaf article first, before slowly
6425   ;; working its way up towards the root.
6426   (when thread
6427     (let ((children
6428            (if (cdr thread)
6429                (apply '+ (mapcar 'gnus-summary-limit-children
6430                                  (cdr thread)))
6431              0))
6432           (number (mail-header-number (car thread)))
6433           score)
6434       (if (and
6435            (not (memq number gnus-newsgroup-marked))
6436            (or
6437             ;; If this article is dormant and has absolutely no visible
6438             ;; children, then this article isn't visible.
6439             (and (memq number gnus-newsgroup-dormant)
6440                  (zerop children))
6441             ;; If this is "fetch-old-headered" and there is no
6442             ;; visible children, then we don't want this article.
6443             (and (eq gnus-fetch-old-headers 'some)
6444                  (gnus-summary-article-ancient-p number)
6445                  (zerop children))
6446             ;; If this is "fetch-old-headered" and `invisible', then
6447             ;; we don't want this article.
6448             (and (eq gnus-fetch-old-headers 'invisible)
6449                  (gnus-summary-article-ancient-p number))
6450             ;; If this is a sparsely inserted article with no children,
6451             ;; we don't want it.
6452             (and (eq gnus-build-sparse-threads 'some)
6453                  (gnus-summary-article-sparse-p number)
6454                  (zerop children))
6455             ;; If we use expunging, and this article is really
6456             ;; low-scored, then we don't want this article.
6457             (when (and gnus-summary-expunge-below
6458                        (< (setq score
6459                                 (or (cdr (assq number gnus-newsgroup-scored))
6460                                     gnus-summary-default-score))
6461                           gnus-summary-expunge-below))
6462               ;; We increase the expunge-tally here, but that has
6463               ;; nothing to do with the limits, really.
6464               (incf gnus-newsgroup-expunged-tally)
6465               ;; We also mark as read here, if that's wanted.
6466               (when (and gnus-summary-mark-below
6467                          (< score gnus-summary-mark-below))
6468                 (setq gnus-newsgroup-unreads
6469                       (delq number gnus-newsgroup-unreads))
6470                 (if gnus-newsgroup-auto-expire
6471                     (push number gnus-newsgroup-expirable)
6472                   (push (cons number gnus-low-score-mark)
6473                         gnus-newsgroup-reads)))
6474               t)
6475             ;; Check NoCeM things.
6476             (if (and gnus-use-nocem
6477                      (gnus-nocem-unwanted-article-p
6478                       (mail-header-id (car thread))))
6479                 (progn
6480                   (setq gnus-newsgroup-unreads
6481                         (delq number gnus-newsgroup-unreads))
6482                   t))))
6483           ;; Nope, invisible article.
6484           0
6485         ;; Ok, this article is to be visible, so we add it to the limit
6486         ;; and return 1.
6487         (push number gnus-newsgroup-limit)
6488         1))))
6489
6490 (defun gnus-expunge-thread (thread)
6491   "Mark all articles in THREAD as read."
6492   (let* ((number (mail-header-number (car thread))))
6493     (incf gnus-newsgroup-expunged-tally)
6494     ;; We also mark as read here, if that's wanted.
6495     (setq gnus-newsgroup-unreads
6496           (delq number gnus-newsgroup-unreads))
6497     (if gnus-newsgroup-auto-expire
6498         (push number gnus-newsgroup-expirable)
6499       (push (cons number gnus-low-score-mark)
6500             gnus-newsgroup-reads)))
6501   ;; Go recursively through all subthreads.
6502   (mapcar 'gnus-expunge-thread (cdr thread)))
6503
6504 ;; Summary article oriented commands
6505
6506 (defun gnus-summary-refer-parent-article (n)
6507   "Refer parent article N times.
6508 If N is negative, go to ancestor -N instead.
6509 The difference between N and the number of articles fetched is returned."
6510   (interactive "p")
6511   (let ((skip 1)
6512         error header ref)
6513     (when (not (natnump n))
6514       (setq skip (abs n)
6515             n 1))
6516     (while (and (> n 0)
6517                 (not error))
6518       (setq header (gnus-summary-article-header))
6519       (if (and (eq (mail-header-number header)
6520                    (cdr gnus-article-current))
6521                (equal gnus-newsgroup-name
6522                       (car gnus-article-current)))
6523           ;; If we try to find the parent of the currently
6524           ;; displayed article, then we take a look at the actual
6525           ;; References header, since this is slightly more
6526           ;; reliable than the References field we got from the
6527           ;; server.
6528           (save-excursion
6529             (set-buffer gnus-original-article-buffer)
6530             (nnheader-narrow-to-headers)
6531             (unless (setq ref (message-fetch-field "references"))
6532               (setq ref (message-fetch-field "in-reply-to")))
6533             (widen))
6534         (setq ref
6535               ;; It's not the current article, so we take a bet on
6536               ;; the value we got from the server.
6537               (mail-header-references header)))
6538       (if (and ref
6539                (not (equal ref "")))
6540           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6541             (gnus-message 1 "Couldn't find parent"))
6542         (gnus-message 1 "No references in article %d"
6543                       (gnus-summary-article-number))
6544         (setq error t))
6545       (decf n))
6546     (gnus-summary-position-point)
6547     n))
6548
6549 (defun gnus-summary-refer-references ()
6550   "Fetch all articles mentioned in the References header.
6551 Return the number of articles fetched."
6552   (interactive)
6553   (let ((ref (mail-header-references (gnus-summary-article-header)))
6554         (current (gnus-summary-article-number))
6555         (n 0))
6556     (if (or (not ref)
6557             (equal ref ""))
6558         (error "No References in the current article")
6559       ;; For each Message-ID in the References header...
6560       (while (string-match "<[^>]*>" ref)
6561         (incf n)
6562         ;; ... fetch that article.
6563         (gnus-summary-refer-article
6564          (prog1 (match-string 0 ref)
6565            (setq ref (substring ref (match-end 0))))))
6566       (gnus-summary-goto-subject current)
6567       (gnus-summary-position-point)
6568       n)))
6569
6570 (defun gnus-summary-refer-thread (&optional limit)
6571   "Fetch all articles in the current thread.
6572 If LIMIT (the numerical prefix), fetch that many old headers instead
6573 of what's specified by the `gnus-refer-thread-limit' variable."
6574   (interactive "P")
6575   (let ((id (mail-header-id (gnus-summary-article-header)))
6576         (limit (if limit (prefix-numeric-value limit)
6577                  gnus-refer-thread-limit)))
6578     ;; We want to fetch LIMIT *old* headers, but we also have to
6579     ;; re-fetch all the headers in the current buffer, because many of
6580     ;; them may be undisplayed.  So we adjust LIMIT.
6581     (when (numberp limit)
6582       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6583     (unless (eq gnus-fetch-old-headers 'invisible)
6584       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6585       ;; Retrieve the headers and read them in.
6586       (if (eq (gnus-retrieve-headers
6587                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6588               'nov)
6589           (gnus-build-all-threads)
6590         (error "Can't fetch thread from backends that don't support NOV"))
6591       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6592     (gnus-summary-limit-include-thread id)))
6593
6594 (defun gnus-summary-refer-article (message-id &optional arg)
6595   "Fetch an article specified by MESSAGE-ID.
6596 If ARG (the prefix), fetch the article using `gnus-refer-article-method'
6597 or `gnus-select-method', no matter what backend the article comes from."
6598   (interactive "sMessage-ID: \nP")
6599   (when (and (stringp message-id)
6600              (not (zerop (length message-id))))
6601     ;; Construct the correct Message-ID if necessary.
6602     ;; Suggested by tale@pawl.rpi.edu.
6603     (unless (string-match "^<" message-id)
6604       (setq message-id (concat "<" message-id)))
6605     (unless (string-match ">$" message-id)
6606       (setq message-id (concat message-id ">")))
6607     (let* ((header (gnus-id-to-header message-id))
6608            (sparse (and header
6609                         (gnus-summary-article-sparse-p
6610                          (mail-header-number header))
6611                         (memq (mail-header-number header)
6612                               gnus-newsgroup-limit))))
6613       (cond
6614        ;; If the article is present in the buffer we just go to it.
6615        ((and header
6616              (or (not (gnus-summary-article-sparse-p
6617                        (mail-header-number header)))
6618                  sparse))
6619         (prog1
6620             (gnus-summary-goto-article
6621              (mail-header-number header) nil t)
6622           (when sparse
6623             (gnus-summary-update-article (mail-header-number header)))))
6624        (t
6625         ;; We fetch the article
6626         (let ((gnus-override-method
6627                (cond ((gnus-news-group-p gnus-newsgroup-name)
6628                       gnus-refer-article-method)
6629                      (arg
6630                       (or gnus-refer-article-method gnus-select-method))
6631                      (t nil)))
6632               number)
6633           ;; Start the special refer-article method, if necessary.
6634           (when (and gnus-refer-article-method
6635                      (gnus-news-group-p gnus-newsgroup-name))
6636             (gnus-check-server gnus-refer-article-method))
6637           ;; Fetch the header, and display the article.
6638           (if (setq number (gnus-summary-insert-subject message-id))
6639               (gnus-summary-select-article nil nil nil number)
6640             (gnus-message 3 "Couldn't fetch article %s" message-id))))))))
6641
6642 (defun gnus-summary-edit-parameters ()
6643   "Edit the group parameters of the current group."
6644   (interactive)
6645   (gnus-group-edit-group gnus-newsgroup-name 'params))
6646
6647 (defun gnus-summary-customize-parameters ()
6648   "Customize the group parameters of the current group."
6649   (interactive)
6650   (gnus-group-customize gnus-newsgroup-name))
6651
6652 (defun gnus-summary-enter-digest-group (&optional force)
6653   "Enter an nndoc group based on the current article.
6654 If FORCE, force a digest interpretation.  If not, try
6655 to guess what the document format is."
6656   (interactive "P")
6657   (let ((conf gnus-current-window-configuration))
6658     (save-excursion
6659       (gnus-summary-select-article))
6660     (setq gnus-current-window-configuration conf)
6661     (let* ((name (format "%s-%d"
6662                          (gnus-group-prefixed-name
6663                           gnus-newsgroup-name (list 'nndoc ""))
6664                          (save-excursion
6665                            (set-buffer gnus-summary-buffer)
6666                            gnus-current-article)))
6667            (ogroup gnus-newsgroup-name)
6668            (params (append (gnus-info-params (gnus-get-info ogroup))
6669                            (list (cons 'to-group ogroup))
6670                            (list (cons 'save-article-group ogroup))))
6671            (case-fold-search t)
6672            (buf (current-buffer))
6673            dig)
6674       (save-excursion
6675         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6676         (insert-buffer-substring gnus-original-article-buffer)
6677         ;; Remove lines that may lead nndoc to misinterpret the
6678         ;; document type.
6679         (narrow-to-region
6680          (goto-char (point-min))
6681          (or (search-forward "\n\n" nil t) (point)))
6682         (goto-char (point-min))
6683         (delete-matching-lines "^\\(Path\\):\\|^From ")
6684         (widen))
6685       (unwind-protect
6686           (if (gnus-group-read-ephemeral-group
6687                name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6688                             (nndoc-article-type
6689                              ,(if force 'digest 'guess))) t)
6690               ;; Make all postings to this group go to the parent group.
6691               (nconc (gnus-info-params (gnus-get-info name))
6692                      params)
6693             ;; Couldn't select this doc group.
6694             (switch-to-buffer buf)
6695             (gnus-set-global-variables)
6696             (gnus-configure-windows 'summary)
6697             (gnus-message 3 "Article couldn't be entered?"))
6698         (kill-buffer dig)))))
6699
6700 (defun gnus-summary-read-document (n)
6701   "Open a new group based on the current article(s).
6702 This will allow you to read digests and other similar
6703 documents as newsgroups.
6704 Obeys the standard process/prefix convention."
6705   (interactive "P")
6706   (let* ((articles (gnus-summary-work-articles n))
6707          (ogroup gnus-newsgroup-name)
6708          (params (append (gnus-info-params (gnus-get-info ogroup))
6709                          (list (cons 'to-group ogroup))))
6710          article group egroup groups vgroup)
6711     (while (setq article (pop articles))
6712       (setq group (format "%s-%d" gnus-newsgroup-name article))
6713       (gnus-summary-remove-process-mark article)
6714       (when (gnus-summary-display-article article)
6715         (save-excursion
6716           (with-temp-buffer
6717             (insert-buffer-substring gnus-original-article-buffer)
6718             ;; Remove some headers that may lead nndoc to make
6719             ;; the wrong guess.
6720             (message-narrow-to-head)
6721             (goto-char (point-min))
6722             (delete-matching-lines "^\\(Path\\):\\|^From ")
6723             (widen)
6724             (if (setq egroup
6725                       (gnus-group-read-ephemeral-group
6726                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6727                                      (nndoc-article-type guess))
6728                        t nil t))
6729                 (progn
6730                   ;; Make all postings to this group go to the parent group.
6731                   (nconc (gnus-info-params (gnus-get-info egroup))
6732                          params)
6733                   (push egroup groups))
6734               ;; Couldn't select this doc group.
6735               (gnus-error 3 "Article couldn't be entered"))))))
6736     ;; Now we have selected all the documents.
6737     (cond
6738      ((not groups)
6739       (error "None of the articles could be interpreted as documents"))
6740      ((gnus-group-read-ephemeral-group
6741        (setq vgroup (format
6742                      "nnvirtual:%s-%s" gnus-newsgroup-name
6743                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6744        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6745        t
6746        (cons (current-buffer) 'summary)))
6747      (t
6748       (error "Couldn't select virtual nndoc group")))))
6749
6750 (defun gnus-summary-isearch-article (&optional regexp-p)
6751   "Do incremental search forward on the current article.
6752 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6753   (interactive "P")
6754   (gnus-summary-select-article)
6755   (gnus-configure-windows 'article)
6756   (gnus-eval-in-buffer-window gnus-article-buffer
6757     (save-restriction
6758       (widen)
6759       (isearch-forward regexp-p))))
6760
6761 (defun gnus-summary-search-article-forward (regexp &optional backward)
6762   "Search for an article containing REGEXP forward.
6763 If BACKWARD, search backward instead."
6764   (interactive
6765    (list (read-string
6766           (format "Search article %s (regexp%s): "
6767                   (if current-prefix-arg "backward" "forward")
6768                   (if gnus-last-search-regexp
6769                       (concat ", default " gnus-last-search-regexp)
6770                     "")))
6771          current-prefix-arg))
6772   (if (string-equal regexp "")
6773       (setq regexp (or gnus-last-search-regexp ""))
6774     (setq gnus-last-search-regexp regexp))
6775   (if (gnus-summary-search-article regexp backward)
6776       (gnus-summary-show-thread)
6777     (error "Search failed: \"%s\"" regexp)))
6778
6779 (defun gnus-summary-search-article-backward (regexp)
6780   "Search for an article containing REGEXP backward."
6781   (interactive
6782    (list (read-string
6783           (format "Search article backward (regexp%s): "
6784                   (if gnus-last-search-regexp
6785                       (concat ", default " gnus-last-search-regexp)
6786                     "")))))
6787   (gnus-summary-search-article-forward regexp 'backward))
6788
6789 (defun gnus-summary-search-article (regexp &optional backward)
6790   "Search for an article containing REGEXP.
6791 Optional argument BACKWARD means do search for backward.
6792 `gnus-select-article-hook' is not called during the search."
6793   ;; We have to require this here to make sure that the following
6794   ;; dynamic binding isn't shadowed by autoloading.
6795   (require 'gnus-async)
6796   (require 'gnus-art)
6797   (let ((gnus-select-article-hook nil)  ;Disable hook.
6798         (gnus-article-display-hook nil)
6799         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
6800         (gnus-use-article-prefetch nil)
6801         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
6802         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
6803         (sum (current-buffer))
6804         (gnus-display-mime-function nil)
6805         (found nil)
6806         point)
6807     (gnus-save-hidden-threads
6808       (gnus-summary-select-article)
6809       (set-buffer gnus-article-buffer)
6810       (when backward
6811         (forward-line -1))
6812       (while (not found)
6813         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
6814         (if (if backward
6815                 (re-search-backward regexp nil t)
6816               (re-search-forward regexp nil t))
6817             ;; We found the regexp.
6818             (progn
6819               (setq found 'found)
6820               (beginning-of-line)
6821               (set-window-start
6822                (get-buffer-window (current-buffer))
6823                (point))
6824               (forward-line 1)
6825               (set-buffer sum)
6826               (setq point (point)))
6827           ;; We didn't find it, so we go to the next article.
6828           (set-buffer sum)
6829           (setq found 'not)
6830           (while (eq found 'not)
6831             (if (not (if backward (gnus-summary-find-prev)
6832                        (gnus-summary-find-next)))
6833                 ;; No more articles.
6834                 (setq found t)
6835               ;; Select the next article and adjust point.
6836               (unless (gnus-summary-article-sparse-p
6837                        (gnus-summary-article-number))
6838                 (setq found nil)
6839                 (gnus-summary-select-article)
6840                 (set-buffer gnus-article-buffer)
6841                 (widen)
6842                 (goto-char (if backward (point-max) (point-min))))))))
6843       (gnus-message 7 ""))
6844     ;; Return whether we found the regexp.
6845     (when (eq found 'found)
6846       (goto-char point)
6847       (gnus-summary-show-thread)
6848       (gnus-summary-goto-subject gnus-current-article)
6849       (gnus-summary-position-point)
6850       t)))
6851
6852 (defun gnus-summary-find-matching (header regexp &optional backward unread
6853                                           not-case-fold)
6854   "Return a list of all articles that match REGEXP on HEADER.
6855 The search stars on the current article and goes forwards unless
6856 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
6857 If UNREAD is non-nil, only unread articles will
6858 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
6859 in the comparisons."
6860   (let ((data (if (eq backward 'all) gnus-newsgroup-data
6861                 (gnus-data-find-list
6862                  (gnus-summary-article-number) (gnus-data-list backward))))
6863         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
6864         (case-fold-search (not not-case-fold))
6865         articles d)
6866     (unless (fboundp (intern (concat "mail-header-" header)))
6867       (error "%s is not a valid header" header))
6868     (while data
6869       (setq d (car data))
6870       (and (or (not unread)             ; We want all articles...
6871                (gnus-data-unread-p d))  ; Or just unreads.
6872            (vectorp (gnus-data-header d)) ; It's not a pseudo.
6873            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
6874            (push (gnus-data-number d) articles)) ; Success!
6875       (setq data (cdr data)))
6876     (nreverse articles)))
6877
6878 (defun gnus-summary-execute-command (header regexp command &optional backward)
6879   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
6880 If HEADER is an empty string (or nil), the match is done on the entire
6881 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
6882   (interactive
6883    (list (let ((completion-ignore-case t))
6884            (completing-read
6885             "Header name: "
6886             (mapcar (lambda (string) (list string))
6887                     '("Number" "Subject" "From" "Lines" "Date"
6888                       "Message-ID" "Xref" "References" "Body"))
6889             nil 'require-match))
6890          (read-string "Regexp: ")
6891          (read-key-sequence "Command: ")
6892          current-prefix-arg))
6893   (when (equal header "Body")
6894     (setq header ""))
6895   ;; Hidden thread subtrees must be searched as well.
6896   (gnus-summary-show-all-threads)
6897   ;; We don't want to change current point nor window configuration.
6898   (save-excursion
6899     (save-window-excursion
6900       (gnus-message 6 "Executing %s..." (key-description command))
6901       ;; We'd like to execute COMMAND interactively so as to give arguments.
6902       (gnus-execute header regexp
6903                     `(call-interactively ',(key-binding command))
6904                     backward)
6905       (gnus-message 6 "Executing %s...done" (key-description command)))))
6906
6907 (defun gnus-summary-beginning-of-article ()
6908   "Scroll the article back to the beginning."
6909   (interactive)
6910   (gnus-summary-select-article)
6911   (gnus-configure-windows 'article)
6912   (gnus-eval-in-buffer-window gnus-article-buffer
6913     (widen)
6914     (goto-char (point-min))
6915     (when gnus-page-broken
6916       (gnus-narrow-to-page))))
6917
6918 (defun gnus-summary-end-of-article ()
6919   "Scroll to the end of the article."
6920   (interactive)
6921   (gnus-summary-select-article)
6922   (gnus-configure-windows 'article)
6923   (gnus-eval-in-buffer-window gnus-article-buffer
6924     (widen)
6925     (goto-char (point-max))
6926     (recenter -3)
6927     (when gnus-page-broken
6928       (gnus-narrow-to-page))))
6929
6930 (defun gnus-summary-print-article (&optional filename n)
6931   "Generate and print a PostScript image of the N next (mail) articles.
6932
6933 If N is negative, print the N previous articles.  If N is nil and articles
6934 have been marked with the process mark, print these instead.
6935
6936 If the optional second argument FILENAME is nil, send the image to the
6937 printer.  If FILENAME is a string, save the PostScript image in a file with
6938 that name.  If FILENAME is a number, prompt the user for the name of the file
6939 to save in."
6940   (interactive (list (ps-print-preprint current-prefix-arg)
6941                      current-prefix-arg))
6942   (dolist (article (gnus-summary-work-articles n))
6943     (gnus-summary-select-article nil nil 'pseudo article)
6944     (gnus-eval-in-buffer-window gnus-article-buffer
6945       (let ((buffer (generate-new-buffer " *print*")))
6946         (unwind-protect
6947             (progn
6948               (copy-to-buffer buffer (point-min) (point-max))
6949               (set-buffer buffer)
6950               (gnus-article-delete-invisible-text)
6951               (let ((ps-left-header
6952                      (list
6953                       (concat "("
6954                               (mail-header-subject gnus-current-headers) ")")
6955                       (concat "("
6956                               (mail-header-from gnus-current-headers) ")")))
6957                     (ps-right-header
6958                      (list
6959                       "/pagenumberstring load"
6960                       (concat "("
6961                               (mail-header-date gnus-current-headers) ")"))))
6962                 (gnus-run-hooks 'gnus-ps-print-hook)
6963                 (save-excursion
6964                   (ps-print-buffer-with-faces filename))))
6965           (kill-buffer buffer))))))
6966
6967 (defun gnus-summary-show-article (&optional arg)
6968   "Force re-fetching of the current article.
6969 If ARG (the prefix) is non-nil, show the raw article without any
6970 article massaging functions being run."
6971   (interactive "P")
6972   (if (not arg)
6973       ;; Select the article the normal way.
6974       (gnus-summary-select-article nil 'force)
6975     ;; We have to require this here to make sure that the following
6976     ;; dynamic binding isn't shadowed by autoloading.
6977     (require 'gnus-async)
6978     (require 'gnus-art)
6979     ;; Bind the article treatment functions to nil.
6980     (let ((gnus-have-all-headers t)
6981           gnus-article-display-hook
6982           gnus-article-prepare-hook
6983           gnus-article-decode-hook
6984           gnus-display-mime-function
6985           gnus-break-pages
6986           gnus-visual)
6987       (gnus-summary-select-article nil 'force)))
6988   (gnus-summary-goto-subject gnus-current-article)
6989   (gnus-summary-position-point))
6990
6991 (defun gnus-summary-verbose-headers (&optional arg)
6992   "Toggle permanent full header display.
6993 If ARG is a positive number, turn header display on.
6994 If ARG is a negative number, turn header display off."
6995   (interactive "P")
6996   (setq gnus-show-all-headers
6997         (cond ((or (not (numberp arg))
6998                    (zerop arg))
6999                (not gnus-show-all-headers))
7000               ((natnump arg)
7001                t)))
7002   (gnus-summary-show-article))
7003
7004 (defun gnus-summary-toggle-header (&optional arg)
7005   "Show the headers if they are hidden, or hide them if they are shown.
7006 If ARG is a positive number, show the entire header.
7007 If ARG is a negative number, hide the unwanted header lines."
7008   (interactive "P")
7009   (save-excursion
7010     (set-buffer gnus-article-buffer)
7011     (let* ((buffer-read-only nil)
7012            (inhibit-point-motion-hooks t)
7013            (hidden (text-property-any
7014                     (goto-char (point-min)) (search-forward "\n\n")
7015                     'invisible t))
7016            e)
7017       (goto-char (point-min))
7018       (when (search-forward "\n\n" nil t)
7019         (delete-region (point-min) (1- (point))))
7020       (goto-char (point-min))
7021       (save-excursion
7022         (set-buffer gnus-original-article-buffer)
7023         (goto-char (point-min))
7024         (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7025       (insert-buffer-substring gnus-original-article-buffer 1 e)
7026       (let ((article-inhibit-hiding t))
7027         (gnus-run-hooks 'gnus-article-display-hook))
7028       (when (or (not hidden) (and (numberp arg) (< arg 0)))
7029         (gnus-article-hide-headers)))))
7030
7031 (defun gnus-summary-show-all-headers ()
7032   "Make all header lines visible."
7033   (interactive)
7034   (gnus-article-show-all-headers))
7035
7036 (defun gnus-summary-caesar-message (&optional arg)
7037   "Caesar rotate the current article by 13.
7038 The numerical prefix specifies how many places to rotate each letter
7039 forward."
7040   (interactive "P")
7041   (gnus-summary-select-article)
7042   (let ((mail-header-separator ""))
7043     (gnus-eval-in-buffer-window gnus-article-buffer
7044       (save-restriction
7045         (widen)
7046         (let ((start (window-start))
7047               buffer-read-only)
7048           (message-caesar-buffer-body arg)
7049           (set-window-start (get-buffer-window (current-buffer)) start))))))
7050
7051 (defun gnus-summary-stop-page-breaking ()
7052   "Stop page breaking in the current article."
7053   (interactive)
7054   (gnus-summary-select-article)
7055   (gnus-eval-in-buffer-window gnus-article-buffer
7056     (widen)
7057     (when (gnus-visual-p 'page-marker)
7058       (let ((buffer-read-only nil))
7059         (gnus-remove-text-with-property 'gnus-prev)
7060         (gnus-remove-text-with-property 'gnus-next))
7061       (setq gnus-page-broken nil))))
7062
7063 (defun gnus-summary-move-article (&optional n to-newsgroup
7064                                             select-method action)
7065   "Move the current article to a different newsgroup.
7066 If N is a positive number, move the N next articles.
7067 If N is a negative number, move the N previous articles.
7068 If N is nil and any articles have been marked with the process mark,
7069 move those articles instead.
7070 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7071 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7072 re-spool using this method.
7073
7074 For this function to work, both the current newsgroup and the
7075 newsgroup that you want to move to have to support the `request-move'
7076 and `request-accept' functions."
7077   (interactive "P")
7078   (unless action
7079     (setq action 'move))
7080   ;; Disable marking as read.
7081   (let (gnus-mark-article-hook)
7082     (save-window-excursion
7083       (gnus-summary-select-article)))
7084   ;; Check whether the source group supports the required functions.
7085   (cond ((and (eq action 'move)
7086               (not (gnus-check-backend-function
7087                     'request-move-article gnus-newsgroup-name)))
7088          (error "The current group does not support article moving"))
7089         ((and (eq action 'crosspost)
7090               (not (gnus-check-backend-function
7091                     'request-replace-article gnus-newsgroup-name)))
7092          (error "The current group does not support article editing")))
7093   (let ((articles (gnus-summary-work-articles n))
7094         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
7095         (names '((move "Move" "Moving")
7096                  (copy "Copy" "Copying")
7097                  (crosspost "Crosspost" "Crossposting")))
7098         (copy-buf (save-excursion
7099                     (nnheader-set-temp-buffer " *copy article*")))
7100         art-group to-method new-xref article to-groups)
7101     (unless (assq action names)
7102       (error "Unknown action %s" action))
7103     ;; Read the newsgroup name.
7104     (when (and (not to-newsgroup)
7105                (not select-method))
7106       (setq to-newsgroup
7107             (gnus-read-move-group-name
7108              (cadr (assq action names))
7109              (symbol-value (intern (format "gnus-current-%s-group" action)))
7110              articles prefix))
7111       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7112     (setq to-method (or select-method
7113                         (gnus-group-name-to-method to-newsgroup)))
7114     ;; Check the method we are to move this article to...
7115     (unless (gnus-check-backend-function
7116              'request-accept-article (car to-method))
7117       (error "%s does not support article copying" (car to-method)))
7118     (unless (gnus-check-server to-method)
7119       (error "Can't open server %s" (car to-method)))
7120     (gnus-message 6 "%s to %s: %s..."
7121                   (caddr (assq action names))
7122                   (or (car select-method) to-newsgroup) articles)
7123     (while articles
7124       (setq article (pop articles))
7125       (setq
7126        art-group
7127        (cond
7128         ;; Move the article.
7129         ((eq action 'move)
7130          ;; Remove this article from future suppression.
7131          (gnus-dup-unsuppress-article article)
7132          (gnus-request-move-article
7133           article                       ; Article to move
7134           gnus-newsgroup-name           ; From newsgroup
7135           (nth 1 (gnus-find-method-for-group
7136                   gnus-newsgroup-name)) ; Server
7137           (list 'gnus-request-accept-article
7138                 to-newsgroup (list 'quote select-method)
7139                 (not articles) t)               ; Accept form
7140           (not articles)))              ; Only save nov last time
7141         ;; Copy the article.
7142         ((eq action 'copy)
7143          (save-excursion
7144            (set-buffer copy-buf)
7145            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7146              (gnus-request-accept-article
7147               to-newsgroup select-method (not articles) t))))
7148         ;; Crosspost the article.
7149         ((eq action 'crosspost)
7150          (let ((xref (message-tokenize-header
7151                       (mail-header-xref (gnus-summary-article-header article))
7152                       " ")))
7153            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7154                                   ":" article))
7155            (unless xref
7156              (setq xref (list (system-name))))
7157            (setq new-xref
7158                  (concat
7159                   (mapconcat 'identity
7160                              (delete "Xref:" (delete new-xref xref))
7161                              " ")
7162                   " " new-xref))
7163            (save-excursion
7164              (set-buffer copy-buf)
7165              ;; First put the article in the destination group.
7166              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7167              (when (consp (setq art-group
7168                                 (gnus-request-accept-article
7169                                  to-newsgroup select-method (not articles))))
7170                (setq new-xref (concat new-xref " " (car art-group)
7171                                       ":" (cdr art-group)))
7172                ;; Now we have the new Xrefs header, so we insert
7173                ;; it and replace the new article.
7174                (nnheader-replace-header "Xref" new-xref)
7175                (gnus-request-replace-article
7176                 (cdr art-group) to-newsgroup (current-buffer))
7177                art-group))))))
7178       (cond
7179        ((not art-group)
7180         (gnus-message 1 "Couldn't %s article %s"
7181                       (cadr (assq action names)) article))
7182        ((and (eq art-group 'junk)
7183              (eq action 'move))
7184         (gnus-summary-mark-article article gnus-canceled-mark)
7185         (gnus-message 4 "Deleted article %s" article))
7186        (t
7187         (let* ((pto-group (gnus-group-prefixed-name
7188                            (car art-group) to-method))
7189                (entry
7190                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7191                (info (nth 2 entry))
7192                (to-group (gnus-info-group info)))
7193           ;; Update the group that has been moved to.
7194           (when (and info
7195                      (memq action '(move copy)))
7196             (unless (member to-group to-groups)
7197               (push to-group to-groups))
7198
7199             (unless (memq article gnus-newsgroup-unreads)
7200               (gnus-info-set-read
7201                info (gnus-add-to-range (gnus-info-read info)
7202                                        (list (cdr art-group)))))
7203
7204             ;; Copy any marks over to the new group.
7205             (let ((marks gnus-article-mark-lists)
7206                   (to-article (cdr art-group)))
7207
7208               ;; See whether the article is to be put in the cache.
7209               (when gnus-use-cache
7210                 (gnus-cache-possibly-enter-article
7211                  to-group to-article
7212                  (let ((header (copy-sequence
7213                                 (gnus-summary-article-header article))))
7214                    (mail-header-set-number header to-article)
7215                    header)
7216                  (memq article gnus-newsgroup-marked)
7217                  (memq article gnus-newsgroup-dormant)
7218                  (memq article gnus-newsgroup-unreads)))
7219
7220               (when (and (equal to-group gnus-newsgroup-name)
7221                          (not (memq article gnus-newsgroup-unreads)))
7222                 ;; Mark this article as read in this group.
7223                 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7224                 (setcdr (gnus-active to-group) to-article)
7225                 (setcdr gnus-newsgroup-active to-article))
7226
7227               (while marks
7228                 (when (memq article (symbol-value
7229                                      (intern (format "gnus-newsgroup-%s"
7230                                                      (caar marks)))))
7231                   ;; If the other group is the same as this group,
7232                   ;; then we have to add the mark to the list.
7233                   (when (equal to-group gnus-newsgroup-name)
7234                     (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7235                          (cons to-article
7236                                (symbol-value
7237                                 (intern (format "gnus-newsgroup-%s"
7238                                                 (caar marks)))))))
7239                   ;; Copy the marks to other group.
7240                   (gnus-add-marked-articles
7241                    to-group (cdar marks) (list to-article) info))
7242                 (setq marks (cdr marks)))
7243
7244               (gnus-dribble-enter
7245                (concat "(gnus-group-set-info '"
7246                        (gnus-prin1-to-string (gnus-get-info to-group))
7247                        ")"))))
7248
7249           ;; Update the Xref header in this article to point to
7250           ;; the new crossposted article we have just created.
7251           (when (eq action 'crosspost)
7252             (save-excursion
7253               (set-buffer copy-buf)
7254               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7255               (nnheader-replace-header "Xref" new-xref)
7256               (gnus-request-replace-article
7257                article gnus-newsgroup-name (current-buffer)))))
7258
7259         ;;;!!!Why is this necessary?
7260         (set-buffer gnus-summary-buffer)
7261
7262         (gnus-summary-goto-subject article)
7263         (when (eq action 'move)
7264           (gnus-summary-mark-article article gnus-canceled-mark))))
7265       (gnus-summary-remove-process-mark article))
7266     ;; Re-activate all groups that have been moved to.
7267     (while to-groups
7268       (save-excursion
7269         (set-buffer gnus-group-buffer)
7270         (when (gnus-group-goto-group (car to-groups) t)
7271           (gnus-group-get-new-news-this-group 1 t))
7272         (pop to-groups)))
7273
7274     (gnus-kill-buffer copy-buf)
7275     (gnus-summary-position-point)
7276     (gnus-set-mode-line 'summary)))
7277
7278 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7279   "Move the current article to a different newsgroup.
7280 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7281 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7282 re-spool using this method."
7283   (interactive "P")
7284   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7285
7286 (defun gnus-summary-crosspost-article (&optional n)
7287   "Crosspost the current article to some other group."
7288   (interactive "P")
7289   (gnus-summary-move-article n nil nil 'crosspost))
7290
7291 (defcustom gnus-summary-respool-default-method nil
7292   "Default method for respooling an article.
7293 If nil, use to the current newsgroup method."
7294   :type '(choice (gnus-select-method :value (nnml ""))
7295                  (const nil))
7296   :group 'gnus-summary-mail)
7297
7298 (defun gnus-summary-respool-article (&optional n method)
7299   "Respool the current article.
7300 The article will be squeezed through the mail spooling process again,
7301 which means that it will be put in some mail newsgroup or other
7302 depending on `nnmail-split-methods'.
7303 If N is a positive number, respool the N next articles.
7304 If N is a negative number, respool the N previous articles.
7305 If N is nil and any articles have been marked with the process mark,
7306 respool those articles instead.
7307
7308 Respooling can be done both from mail groups and \"real\" newsgroups.
7309 In the former case, the articles in question will be moved from the
7310 current group into whatever groups they are destined to.  In the
7311 latter case, they will be copied into the relevant groups."
7312   (interactive
7313    (list current-prefix-arg
7314          (let* ((methods (gnus-methods-using 'respool))
7315                 (methname
7316                  (symbol-name (or gnus-summary-respool-default-method
7317                                   (car (gnus-find-method-for-group
7318                                         gnus-newsgroup-name)))))
7319                 (method
7320                  (gnus-completing-read
7321                   methname "What backend do you want to use when respooling?"
7322                   methods nil t nil 'gnus-mail-method-history))
7323                 ms)
7324            (cond
7325             ((zerop (length (setq ms (gnus-servers-using-backend
7326                                       (intern method)))))
7327              (list (intern method) ""))
7328             ((= 1 (length ms))
7329              (car ms))
7330             (t
7331              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7332                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7333                            ms-alist))))))))
7334   (unless method
7335     (error "No method given for respooling"))
7336   (if (assoc (symbol-name
7337               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7338              (gnus-methods-using 'respool))
7339       (gnus-summary-move-article n nil method)
7340     (gnus-summary-copy-article n nil method)))
7341
7342 (defun gnus-summary-import-article (file)
7343   "Import an arbitrary file into a mail newsgroup."
7344   (interactive "fImport file: ")
7345   (let ((group gnus-newsgroup-name)
7346         (now (current-time))
7347         atts lines)
7348     (unless (gnus-check-backend-function 'request-accept-article group)
7349       (error "%s does not support article importing" group))
7350     (or (file-readable-p file)
7351         (not (file-regular-p file))
7352         (error "Can't read %s" file))
7353     (save-excursion
7354       (set-buffer (gnus-get-buffer-create " *import file*"))
7355       (erase-buffer)
7356       (insert-file-contents file)
7357       (goto-char (point-min))
7358       (unless (nnheader-article-p)
7359         ;; This doesn't look like an article, so we fudge some headers.
7360         (setq atts (file-attributes file)
7361               lines (count-lines (point-min) (point-max)))
7362         (insert "From: " (read-string "From: ") "\n"
7363                 "Subject: " (read-string "Subject: ") "\n"
7364                 "Date: " (message-make-date (nth 5 atts))
7365                 "\n"
7366                 "Message-ID: " (message-make-message-id) "\n"
7367                 "Lines: " (int-to-string lines) "\n"
7368                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7369       (gnus-request-accept-article group nil t)
7370       (kill-buffer (current-buffer)))))
7371
7372 (defun gnus-summary-article-posted-p ()
7373   "Say whether the current (mail) article is available from `gnus-select-method' as well.
7374 This will be the case if the article has both been mailed and posted."
7375   (interactive)
7376   (let ((id (mail-header-references (gnus-summary-article-header)))
7377         (gnus-override-method
7378          (or gnus-refer-article-method gnus-select-method)))
7379     (if (gnus-request-head id "")
7380         (gnus-message 2 "The current message was found on %s"
7381                       gnus-override-method)
7382       (gnus-message 2 "The current message couldn't be found on %s"
7383                     gnus-override-method)
7384       nil)))
7385
7386 (defun gnus-summary-expire-articles (&optional now)
7387   "Expire all articles that are marked as expirable in the current group."
7388   (interactive)
7389   (when (gnus-check-backend-function
7390          'request-expire-articles gnus-newsgroup-name)
7391     ;; This backend supports expiry.
7392     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7393            (expirable (if total
7394                           (progn
7395                             ;; We need to update the info for
7396                             ;; this group for `gnus-list-of-read-articles'
7397                             ;; to give us the right answer.
7398                             (gnus-run-hooks 'gnus-exit-group-hook)
7399                             (gnus-summary-update-info)
7400                             (gnus-list-of-read-articles gnus-newsgroup-name))
7401                         (setq gnus-newsgroup-expirable
7402                               (sort gnus-newsgroup-expirable '<))))
7403            (expiry-wait (if now 'immediate
7404                           (gnus-group-find-parameter
7405                            gnus-newsgroup-name 'expiry-wait)))
7406            es)
7407       (when expirable
7408         ;; There are expirable articles in this group, so we run them
7409         ;; through the expiry process.
7410         (gnus-message 6 "Expiring articles...")
7411         ;; The list of articles that weren't expired is returned.
7412         (save-excursion
7413           (if expiry-wait
7414               (let ((nnmail-expiry-wait-function nil)
7415                     (nnmail-expiry-wait expiry-wait))
7416                 (setq es (gnus-request-expire-articles
7417                           expirable gnus-newsgroup-name)))
7418             (setq es (gnus-request-expire-articles
7419                       expirable gnus-newsgroup-name))))
7420         (unless total
7421           (setq gnus-newsgroup-expirable es))
7422         ;; We go through the old list of expirable, and mark all
7423         ;; really expired articles as nonexistent.
7424         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
7425           (let ((gnus-use-cache nil))
7426             (while expirable
7427               (unless (memq (car expirable) es)
7428                 (when (gnus-data-find (car expirable))
7429                   (gnus-summary-mark-article
7430                    (car expirable) gnus-canceled-mark)))
7431               (setq expirable (cdr expirable)))))
7432         (gnus-message 6 "Expiring articles...done")))))
7433
7434 (defun gnus-summary-expire-articles-now ()
7435   "Expunge all expirable articles in the current group.
7436 This means that *all* articles that are marked as expirable will be
7437 deleted forever, right now."
7438   (interactive)
7439   (or gnus-expert-user
7440       (gnus-yes-or-no-p
7441        "Are you really, really, really sure you want to delete all these messages? ")
7442       (error "Phew!"))
7443   (gnus-summary-expire-articles t))
7444
7445 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7446 (defun gnus-summary-delete-article (&optional n)
7447   "Delete the N next (mail) articles.
7448 This command actually deletes articles.  This is not a marking
7449 command.  The article will disappear forever from your life, never to
7450 return.
7451 If N is negative, delete backwards.
7452 If N is nil and articles have been marked with the process mark,
7453 delete these instead."
7454   (interactive "P")
7455   (unless (gnus-check-backend-function 'request-expire-articles
7456                                        gnus-newsgroup-name)
7457     (error "The current newsgroup does not support article deletion"))
7458   ;; Compute the list of articles to delete.
7459   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
7460         not-deleted)
7461     (if (and gnus-novice-user
7462              (not (gnus-yes-or-no-p
7463                    (format "Do you really want to delete %s forever? "
7464                            (if (> (length articles) 1)
7465                                (format "these %s articles" (length articles))
7466                              "this article")))))
7467         ()
7468       ;; Delete the articles.
7469       (setq not-deleted (gnus-request-expire-articles
7470                          articles gnus-newsgroup-name 'force))
7471       (while articles
7472         (gnus-summary-remove-process-mark (car articles))
7473         ;; The backend might not have been able to delete the article
7474         ;; after all.
7475         (unless (memq (car articles) not-deleted)
7476           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7477         (setq articles (cdr articles)))
7478       (when not-deleted
7479         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7480     (gnus-summary-position-point)
7481     (gnus-set-mode-line 'summary)
7482     not-deleted))
7483
7484 (defun gnus-summary-edit-article (&optional force)
7485   "Edit the current article.
7486 This will have permanent effect only in mail groups.
7487 If FORCE is non-nil, allow editing of articles even in read-only
7488 groups."
7489   (interactive "P")
7490   (save-excursion
7491     (set-buffer gnus-summary-buffer)
7492     (gnus-set-global-variables)
7493     (when (and (not force)
7494                (gnus-group-read-only-p))
7495       (error "The current newsgroup does not support article editing"))
7496     ;; Select article if needed.
7497     (unless (eq (gnus-summary-article-number)
7498                 gnus-current-article)
7499       (gnus-summary-select-article t))
7500     (gnus-article-date-original)
7501     (gnus-article-edit-article
7502      `(lambda (no-highlight)
7503         (gnus-summary-edit-article-done
7504          ,(or (mail-header-references gnus-current-headers) "")
7505          ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))
7506
7507 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7508
7509 (defun gnus-summary-edit-article-done (&optional references read-only buffer
7510                                                  no-highlight)
7511   "Make edits to the current article permanent."
7512   (interactive)
7513   ;; Replace the article.
7514   (let ((buf (current-buffer)))
7515     (with-temp-buffer
7516       (insert-buffer buf)
7517       (if (and (not read-only)
7518                (not (gnus-request-replace-article
7519                      (cdr gnus-article-current) (car gnus-article-current)
7520                      (current-buffer)
7521                      (not gnus-article-decoded-p))))
7522           (error "Couldn't replace article")
7523         ;; Update the summary buffer.
7524         (if (and references
7525                  (equal (message-tokenize-header references " ")
7526                         (message-tokenize-header
7527                          (or (message-fetch-field "references") "") " ")))
7528             ;; We only have to update this line.
7529             (save-excursion
7530               (save-restriction
7531                 (message-narrow-to-head)
7532                 (let ((head (buffer-string))
7533                       header)
7534                   (with-temp-buffer
7535                     (insert (format "211 %d Article retrieved.\n"
7536                                     (cdr gnus-article-current)))
7537                     (insert head)
7538                     (insert ".\n")
7539                     (let ((nntp-server-buffer (current-buffer)))
7540                       (setq header (car (gnus-get-newsgroup-headers
7541                                          (save-excursion
7542                                            (set-buffer gnus-summary-buffer)
7543                                            gnus-newsgroup-dependencies)
7544                                          t))))
7545                     (save-excursion
7546                       (set-buffer gnus-summary-buffer)
7547                       (gnus-data-set-header
7548                        (gnus-data-find (cdr gnus-article-current))
7549                        header)
7550                       (gnus-summary-update-article-line
7551                        (cdr gnus-article-current) header))))))
7552           ;; Update threads.
7553           (set-buffer (or buffer gnus-summary-buffer))
7554           (gnus-summary-update-article (cdr gnus-article-current)))
7555         ;; Prettify the article buffer again.
7556         (unless no-highlight
7557           (save-excursion
7558             (set-buffer gnus-article-buffer)
7559             (gnus-run-hooks 'gnus-article-display-hook)
7560             (set-buffer gnus-original-article-buffer)
7561             (gnus-request-article
7562              (cdr gnus-article-current)
7563              (car gnus-article-current) (current-buffer))))
7564         ;; Prettify the summary buffer line.
7565         (when (gnus-visual-p 'summary-highlight 'highlight)
7566           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
7567
7568 (defun gnus-summary-edit-wash (key)
7569   "Perform editing command KEY in the article buffer."
7570   (interactive
7571    (list
7572     (progn
7573       (message "%s" (concat (this-command-keys) "- "))
7574       (read-char))))
7575   (message "")
7576   (gnus-summary-edit-article)
7577   (execute-kbd-macro (concat (this-command-keys) key))
7578   (gnus-article-edit-done))
7579
7580 ;;; Respooling
7581
7582 (defun gnus-summary-respool-query (&optional silent trace)
7583   "Query where the respool algorithm would put this article."
7584   (interactive)
7585   (let (gnus-mark-article-hook)
7586     (gnus-summary-select-article)
7587     (save-excursion
7588       (set-buffer gnus-original-article-buffer)
7589       (save-restriction
7590         (message-narrow-to-head)
7591         (let ((groups (nnmail-article-group 'identity trace)))
7592           (unless silent
7593             (if groups
7594                 (message "This message would go to %s"
7595                          (mapconcat 'car groups ", "))
7596               (message "This message would go to no groups"))
7597             groups))))))
7598
7599 (defun gnus-summary-respool-trace ()
7600   "Trace where the respool algorithm would put this article.
7601 Display a buffer showing all fancy splitting patterns which matched."
7602   (interactive)
7603   (gnus-summary-respool-query nil t))
7604
7605 ;; Summary marking commands.
7606
7607 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7608   "Mark articles which has the same subject as read, and then select the next.
7609 If UNMARK is positive, remove any kind of mark.
7610 If UNMARK is negative, tick articles."
7611   (interactive "P")
7612   (when unmark
7613     (setq unmark (prefix-numeric-value unmark)))
7614   (let ((count
7615          (gnus-summary-mark-same-subject
7616           (gnus-summary-article-subject) unmark)))
7617     ;; Select next unread article.  If auto-select-same mode, should
7618     ;; select the first unread article.
7619     (gnus-summary-next-article t (and gnus-auto-select-same
7620                                       (gnus-summary-article-subject)))
7621     (gnus-message 7 "%d article%s marked as %s"
7622                   count (if (= count 1) " is" "s are")
7623                   (if unmark "unread" "read"))))
7624
7625 (defun gnus-summary-kill-same-subject (&optional unmark)
7626   "Mark articles which has the same subject as read.
7627 If UNMARK is positive, remove any kind of mark.
7628 If UNMARK is negative, tick articles."
7629   (interactive "P")
7630   (when unmark
7631     (setq unmark (prefix-numeric-value unmark)))
7632   (let ((count
7633          (gnus-summary-mark-same-subject
7634           (gnus-summary-article-subject) unmark)))
7635     ;; If marked as read, go to next unread subject.
7636     (when (null unmark)
7637       ;; Go to next unread subject.
7638       (gnus-summary-next-subject 1 t))
7639     (gnus-message 7 "%d articles are marked as %s"
7640                   count (if unmark "unread" "read"))))
7641
7642 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7643   "Mark articles with same SUBJECT as read, and return marked number.
7644 If optional argument UNMARK is positive, remove any kinds of marks.
7645 If optional argument UNMARK is negative, mark articles as unread instead."
7646   (let ((count 1))
7647     (save-excursion
7648       (cond
7649        ((null unmark)                   ; Mark as read.
7650         (while (and
7651                 (progn
7652                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7653                   (gnus-summary-show-thread) t)
7654                 (gnus-summary-find-subject subject))
7655           (setq count (1+ count))))
7656        ((> unmark 0)                    ; Tick.
7657         (while (and
7658                 (progn
7659                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7660                   (gnus-summary-show-thread) t)
7661                 (gnus-summary-find-subject subject))
7662           (setq count (1+ count))))
7663        (t                               ; Mark as unread.
7664         (while (and
7665                 (progn
7666                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7667                   (gnus-summary-show-thread) t)
7668                 (gnus-summary-find-subject subject))
7669           (setq count (1+ count)))))
7670       (gnus-set-mode-line 'summary)
7671       ;; Return the number of marked articles.
7672       count)))
7673
7674 (defun gnus-summary-mark-as-processable (n &optional unmark)
7675   "Set the process mark on the next N articles.
7676 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7677 the process mark instead.  The difference between N and the actual
7678 number of articles marked is returned."
7679   (interactive "p")
7680   (let ((backward (< n 0))
7681         (n (abs n)))
7682     (while (and
7683             (> n 0)
7684             (if unmark
7685                 (gnus-summary-remove-process-mark
7686                  (gnus-summary-article-number))
7687               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7688             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7689       (setq n (1- n)))
7690     (when (/= 0 n)
7691       (gnus-message 7 "No more articles"))
7692     (gnus-summary-recenter)
7693     (gnus-summary-position-point)
7694     n))
7695
7696 (defun gnus-summary-unmark-as-processable (n)
7697   "Remove the process mark from the next N articles.
7698 If N is negative, unmark backward instead.  The difference between N and
7699 the actual number of articles unmarked is returned."
7700   (interactive "p")
7701   (gnus-summary-mark-as-processable n t))
7702
7703 (defun gnus-summary-unmark-all-processable ()
7704   "Remove the process mark from all articles."
7705   (interactive)
7706   (save-excursion
7707     (while gnus-newsgroup-processable
7708       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7709   (gnus-summary-position-point))
7710
7711 (defun gnus-summary-mark-as-expirable (n)
7712   "Mark N articles forward as expirable.
7713 If N is negative, mark backward instead.  The difference between N and
7714 the actual number of articles marked is returned."
7715   (interactive "p")
7716   (gnus-summary-mark-forward n gnus-expirable-mark))
7717
7718 (defun gnus-summary-mark-article-as-replied (article)
7719   "Mark ARTICLE replied and update the summary line."
7720   (push article gnus-newsgroup-replied)
7721   (let ((buffer-read-only nil))
7722     (when (gnus-summary-goto-subject article nil t)
7723       (gnus-summary-update-secondary-mark article))))
7724
7725 (defun gnus-summary-set-bookmark (article)
7726   "Set a bookmark in current article."
7727   (interactive (list (gnus-summary-article-number)))
7728   (when (or (not (get-buffer gnus-article-buffer))
7729             (not gnus-current-article)
7730             (not gnus-article-current)
7731             (not (equal gnus-newsgroup-name (car gnus-article-current))))
7732     (error "No current article selected"))
7733   ;; Remove old bookmark, if one exists.
7734   (let ((old (assq article gnus-newsgroup-bookmarks)))
7735     (when old
7736       (setq gnus-newsgroup-bookmarks
7737             (delq old gnus-newsgroup-bookmarks))))
7738   ;; Set the new bookmark, which is on the form
7739   ;; (article-number . line-number-in-body).
7740   (push
7741    (cons article
7742          (save-excursion
7743            (set-buffer gnus-article-buffer)
7744            (count-lines
7745             (min (point)
7746                  (save-excursion
7747                    (goto-char (point-min))
7748                    (search-forward "\n\n" nil t)
7749                    (point)))
7750             (point))))
7751    gnus-newsgroup-bookmarks)
7752   (gnus-message 6 "A bookmark has been added to the current article."))
7753
7754 (defun gnus-summary-remove-bookmark (article)
7755   "Remove the bookmark from the current article."
7756   (interactive (list (gnus-summary-article-number)))
7757   ;; Remove old bookmark, if one exists.
7758   (let ((old (assq article gnus-newsgroup-bookmarks)))
7759     (if old
7760         (progn
7761           (setq gnus-newsgroup-bookmarks
7762                 (delq old gnus-newsgroup-bookmarks))
7763           (gnus-message 6 "Removed bookmark."))
7764       (gnus-message 6 "No bookmark in current article."))))
7765
7766 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7767 (defun gnus-summary-mark-as-dormant (n)
7768   "Mark N articles forward as dormant.
7769 If N is negative, mark backward instead.  The difference between N and
7770 the actual number of articles marked is returned."
7771   (interactive "p")
7772   (gnus-summary-mark-forward n gnus-dormant-mark))
7773
7774 (defun gnus-summary-set-process-mark (article)
7775   "Set the process mark on ARTICLE and update the summary line."
7776   (setq gnus-newsgroup-processable
7777         (cons article
7778               (delq article gnus-newsgroup-processable)))
7779   (when (gnus-summary-goto-subject article)
7780     (gnus-summary-show-thread)
7781     (gnus-summary-goto-subject article)
7782     (gnus-summary-update-secondary-mark article)))
7783
7784 (defun gnus-summary-remove-process-mark (article)
7785   "Remove the process mark from ARTICLE and update the summary line."
7786   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
7787   (when (gnus-summary-goto-subject article)
7788     (gnus-summary-show-thread)
7789     (gnus-summary-goto-subject article)
7790     (gnus-summary-update-secondary-mark article)))
7791
7792 (defun gnus-summary-set-saved-mark (article)
7793   "Set the process mark on ARTICLE and update the summary line."
7794   (push article gnus-newsgroup-saved)
7795   (when (gnus-summary-goto-subject article)
7796     (gnus-summary-update-secondary-mark article)))
7797
7798 (defun gnus-summary-mark-forward (n &optional mark no-expire)
7799   "Mark N articles as read forwards.
7800 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
7801 The difference between N and the actual number of articles marked is
7802 returned."
7803   (interactive "p")
7804   (gnus-summary-show-thread)
7805   (let ((backward (< n 0))
7806         (gnus-summary-goto-unread
7807          (and gnus-summary-goto-unread
7808               (not (eq gnus-summary-goto-unread 'never))
7809               (not (memq mark (list gnus-unread-mark
7810                                     gnus-ticked-mark gnus-dormant-mark)))))
7811         (n (abs n))
7812         (mark (or mark gnus-del-mark)))
7813     (while (and (> n 0)
7814                 (gnus-summary-mark-article nil mark no-expire)
7815                 (zerop (gnus-summary-next-subject
7816                         (if backward -1 1)
7817                         (and gnus-summary-goto-unread
7818                              (not (eq gnus-summary-goto-unread 'never)))
7819                         t)))
7820       (setq n (1- n)))
7821     (when (/= 0 n)
7822       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
7823     (gnus-summary-recenter)
7824     (gnus-summary-position-point)
7825     (gnus-set-mode-line 'summary)
7826     n))
7827
7828 (defun gnus-summary-mark-article-as-read (mark)
7829   "Mark the current article quickly as read with MARK."
7830   (let ((article (gnus-summary-article-number)))
7831     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7832     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7833     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7834     (push (cons article mark) gnus-newsgroup-reads)
7835     ;; Possibly remove from cache, if that is used.
7836     (when gnus-use-cache
7837       (gnus-cache-enter-remove-article article))
7838     ;; Allow the backend to change the mark.
7839     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7840     ;; Check for auto-expiry.
7841     (when (and gnus-newsgroup-auto-expire
7842                (memq mark gnus-auto-expirable-marks))
7843       (setq mark gnus-expirable-mark)
7844       ;; Let the backend know about the mark change.
7845       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7846       (push article gnus-newsgroup-expirable))
7847     ;; Set the mark in the buffer.
7848     (gnus-summary-update-mark mark 'unread)
7849     t))
7850
7851 (defun gnus-summary-mark-article-as-unread (mark)
7852   "Mark the current article quickly as unread with MARK."
7853   (let* ((article (gnus-summary-article-number))
7854          (old-mark (gnus-summary-article-mark article)))
7855     ;; Allow the backend to change the mark.
7856     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7857     (if (eq mark old-mark)
7858         t
7859       (if (<= article 0)
7860           (progn
7861             (gnus-error 1 "Can't mark negative article numbers")
7862             nil)
7863         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7864         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7865         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
7866         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
7867         (cond ((= mark gnus-ticked-mark)
7868                (push article gnus-newsgroup-marked))
7869               ((= mark gnus-dormant-mark)
7870                (push article gnus-newsgroup-dormant))
7871               (t
7872                (push article gnus-newsgroup-unreads)))
7873         (gnus-pull article gnus-newsgroup-reads)
7874
7875         ;; See whether the article is to be put in the cache.
7876         (and gnus-use-cache
7877              (vectorp (gnus-summary-article-header article))
7878              (save-excursion
7879                (gnus-cache-possibly-enter-article
7880                 gnus-newsgroup-name article
7881                 (gnus-summary-article-header article)
7882                 (= mark gnus-ticked-mark)
7883                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7884
7885         ;; Fix the mark.
7886         (gnus-summary-update-mark mark 'unread)
7887         t))))
7888
7889 (defun gnus-summary-mark-article (&optional article mark no-expire)
7890   "Mark ARTICLE with MARK.  MARK can be any character.
7891 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
7892 `??' (dormant) and `?E' (expirable).
7893 If MARK is nil, then the default character `?r' is used.
7894 If ARTICLE is nil, then the article on the current line will be
7895 marked."
7896   ;; The mark might be a string.
7897   (when (stringp mark)
7898     (setq mark (aref mark 0)))
7899   ;; If no mark is given, then we check auto-expiring.
7900   (when (null mark)
7901     (setq mark gnus-del-mark))
7902   (when (and (not no-expire)
7903              gnus-newsgroup-auto-expire
7904              (memq mark gnus-auto-expirable-marks))
7905     (setq mark gnus-expirable-mark))
7906   (let ((article (or article (gnus-summary-article-number)))
7907         (old-mark (gnus-summary-article-mark article)))
7908     ;; Allow the backend to change the mark.
7909     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7910     (if (eq mark old-mark)
7911         t
7912       (unless article
7913         (error "No article on current line"))
7914       (if (not (if (or (= mark gnus-unread-mark)
7915                        (= mark gnus-ticked-mark)
7916                        (= mark gnus-dormant-mark))
7917                    (gnus-mark-article-as-unread article mark)
7918                  (gnus-mark-article-as-read article mark)))
7919           t
7920         ;; See whether the article is to be put in the cache.
7921         (and gnus-use-cache
7922              (not (= mark gnus-canceled-mark))
7923              (vectorp (gnus-summary-article-header article))
7924              (save-excursion
7925                (gnus-cache-possibly-enter-article
7926                 gnus-newsgroup-name article
7927                 (gnus-summary-article-header article)
7928                 (= mark gnus-ticked-mark)
7929                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7930
7931         (when (gnus-summary-goto-subject article nil t)
7932           (let ((buffer-read-only nil))
7933             (gnus-summary-show-thread)
7934             ;; Fix the mark.
7935             (gnus-summary-update-mark mark 'unread)
7936             t))))))
7937
7938 (defun gnus-summary-update-secondary-mark (article)
7939   "Update the secondary (read, process, cache) mark."
7940   (gnus-summary-update-mark
7941    (cond ((memq article gnus-newsgroup-processable)
7942           gnus-process-mark)
7943          ((memq article gnus-newsgroup-cached)
7944           gnus-cached-mark)
7945          ((memq article gnus-newsgroup-replied)
7946           gnus-replied-mark)
7947          ((memq article gnus-newsgroup-saved)
7948           gnus-saved-mark)
7949          (t gnus-unread-mark))
7950    'replied)
7951   (when (gnus-visual-p 'summary-highlight 'highlight)
7952     (gnus-run-hooks 'gnus-summary-update-hook))
7953   t)
7954
7955 (defun gnus-summary-update-mark (mark type)
7956   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
7957         (buffer-read-only nil))
7958     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
7959     (when forward
7960       (when (looking-at "\r")
7961         (incf forward))
7962       (when (<= (+ forward (point)) (point-max))
7963         ;; Go to the right position on the line.
7964         (goto-char (+ forward (point)))
7965         ;; Replace the old mark with the new mark.
7966         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
7967         ;; Optionally update the marks by some user rule.
7968         (when (eq type 'unread)
7969           (gnus-data-set-mark
7970            (gnus-data-find (gnus-summary-article-number)) mark)
7971           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
7972
7973 (defun gnus-mark-article-as-read (article &optional mark)
7974   "Enter ARTICLE in the pertinent lists and remove it from others."
7975   ;; Make the article expirable.
7976   (let ((mark (or mark gnus-del-mark)))
7977     (if (= mark gnus-expirable-mark)
7978         (push article gnus-newsgroup-expirable)
7979       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
7980     ;; Remove from unread and marked lists.
7981     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7982     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7983     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7984     (push (cons article mark) gnus-newsgroup-reads)
7985     ;; Possibly remove from cache, if that is used.
7986     (when gnus-use-cache
7987       (gnus-cache-enter-remove-article article))
7988     t))
7989
7990 (defun gnus-mark-article-as-unread (article &optional mark)
7991   "Enter ARTICLE in the pertinent lists and remove it from others."
7992   (let ((mark (or mark gnus-ticked-mark)))
7993     (if (<= article 0)
7994         (progn
7995           (gnus-error 1 "Can't mark negative article numbers")
7996           nil)
7997       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
7998             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
7999             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8000             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8001
8002       ;; Unsuppress duplicates?
8003       (when gnus-suppress-duplicates
8004         (gnus-dup-unsuppress-article article))
8005
8006       (cond ((= mark gnus-ticked-mark)
8007              (push article gnus-newsgroup-marked))
8008             ((= mark gnus-dormant-mark)
8009              (push article gnus-newsgroup-dormant))
8010             (t
8011              (push article gnus-newsgroup-unreads)))
8012       (gnus-pull article gnus-newsgroup-reads)
8013       t)))
8014
8015 (defalias 'gnus-summary-mark-as-unread-forward
8016   'gnus-summary-tick-article-forward)
8017 (make-obsolete 'gnus-summary-mark-as-unread-forward
8018                'gnus-summary-tick-article-forward)
8019 (defun gnus-summary-tick-article-forward (n)
8020   "Tick N articles forwards.
8021 If N is negative, tick backwards instead.
8022 The difference between N and the number of articles ticked is returned."
8023   (interactive "p")
8024   (gnus-summary-mark-forward n gnus-ticked-mark))
8025
8026 (defalias 'gnus-summary-mark-as-unread-backward
8027   'gnus-summary-tick-article-backward)
8028 (make-obsolete 'gnus-summary-mark-as-unread-backward
8029                'gnus-summary-tick-article-backward)
8030 (defun gnus-summary-tick-article-backward (n)
8031   "Tick N articles backwards.
8032 The difference between N and the number of articles ticked is returned."
8033   (interactive "p")
8034   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8035
8036 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8037 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8038 (defun gnus-summary-tick-article (&optional article clear-mark)
8039   "Mark current article as unread.
8040 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8041 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8042   (interactive)
8043   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8044                                        gnus-ticked-mark)))
8045
8046 (defun gnus-summary-mark-as-read-forward (n)
8047   "Mark N articles as read forwards.
8048 If N is negative, mark backwards instead.
8049 The difference between N and the actual number of articles marked is
8050 returned."
8051   (interactive "p")
8052   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8053
8054 (defun gnus-summary-mark-as-read-backward (n)
8055   "Mark the N articles as read backwards.
8056 The difference between N and the actual number of articles marked is
8057 returned."
8058   (interactive "p")
8059   (gnus-summary-mark-forward (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8060
8061 (defun gnus-summary-mark-as-read (&optional article mark)
8062   "Mark current article as read.
8063 ARTICLE specifies the article to be marked as read.
8064 MARK specifies a string to be inserted at the beginning of the line."
8065   (gnus-summary-mark-article article mark))
8066
8067 (defun gnus-summary-clear-mark-forward (n)
8068   "Clear marks from N articles forward.
8069 If N is negative, clear backward instead.
8070 The difference between N and the number of marks cleared is returned."
8071   (interactive "p")
8072   (gnus-summary-mark-forward n gnus-unread-mark))
8073
8074 (defun gnus-summary-clear-mark-backward (n)
8075   "Clear marks from N articles backward.
8076 The difference between N and the number of marks cleared is returned."
8077   (interactive "p")
8078   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8079
8080 (defun gnus-summary-mark-unread-as-read ()
8081   "Intended to be used by `gnus-summary-mark-article-hook'."
8082   (when (memq gnus-current-article gnus-newsgroup-unreads)
8083     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8084
8085 (defun gnus-summary-mark-read-and-unread-as-read ()
8086   "Intended to be used by `gnus-summary-mark-article-hook'."
8087   (let ((mark (gnus-summary-article-mark)))
8088     (when (or (gnus-unread-mark-p mark)
8089               (gnus-read-mark-p mark))
8090       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8091
8092 (defun gnus-summary-mark-region-as-read (point mark all)
8093   "Mark all unread articles between point and mark as read.
8094 If given a prefix, mark all articles between point and mark as read,
8095 even ticked and dormant ones."
8096   (interactive "r\nP")
8097   (save-excursion
8098     (let (article)
8099       (goto-char point)
8100       (beginning-of-line)
8101       (while (and
8102               (< (point) mark)
8103               (progn
8104                 (when (or all
8105                           (memq (setq article (gnus-summary-article-number))
8106                                 gnus-newsgroup-unreads))
8107                   (gnus-summary-mark-article article gnus-del-mark))
8108                 t)
8109               (gnus-summary-find-next))))))
8110
8111 (defun gnus-summary-mark-below (score mark)
8112   "Mark articles with score less than SCORE with MARK."
8113   (interactive "P\ncMark: ")
8114   (setq score (if score
8115                   (prefix-numeric-value score)
8116                 (or gnus-summary-default-score 0)))
8117   (save-excursion
8118     (set-buffer gnus-summary-buffer)
8119     (goto-char (point-min))
8120     (while
8121         (progn
8122           (and (< (gnus-summary-article-score) score)
8123                (gnus-summary-mark-article nil mark))
8124           (gnus-summary-find-next)))))
8125
8126 (defun gnus-summary-kill-below (&optional score)
8127   "Mark articles with score below SCORE as read."
8128   (interactive "P")
8129   (gnus-summary-mark-below score gnus-killed-mark))
8130
8131 (defun gnus-summary-clear-above (&optional score)
8132   "Clear all marks from articles with score above SCORE."
8133   (interactive "P")
8134   (gnus-summary-mark-above score gnus-unread-mark))
8135
8136 (defun gnus-summary-tick-above (&optional score)
8137   "Tick all articles with score above SCORE."
8138   (interactive "P")
8139   (gnus-summary-mark-above score gnus-ticked-mark))
8140
8141 (defun gnus-summary-mark-above (score mark)
8142   "Mark articles with score over SCORE with MARK."
8143   (interactive "P\ncMark: ")
8144   (setq score (if score
8145                   (prefix-numeric-value score)
8146                 (or gnus-summary-default-score 0)))
8147   (save-excursion
8148     (set-buffer gnus-summary-buffer)
8149     (goto-char (point-min))
8150     (while (and (progn
8151                   (when (> (gnus-summary-article-score) score)
8152                     (gnus-summary-mark-article nil mark))
8153                   t)
8154                 (gnus-summary-find-next)))))
8155
8156 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8157 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8158 (defun gnus-summary-limit-include-expunged (&optional no-error)
8159   "Display all the hidden articles that were expunged for low scores."
8160   (interactive)
8161   (let ((buffer-read-only nil))
8162     (let ((scored gnus-newsgroup-scored)
8163           headers h)
8164       (while scored
8165         (unless (gnus-summary-goto-subject (caar scored))
8166           (and (setq h (gnus-summary-article-header (caar scored)))
8167                (< (cdar scored) gnus-summary-expunge-below)
8168                (push h headers)))
8169         (setq scored (cdr scored)))
8170       (if (not headers)
8171           (when (not no-error)
8172             (error "No expunged articles hidden"))
8173         (goto-char (point-min))
8174         (gnus-summary-prepare-unthreaded (nreverse headers))
8175         (goto-char (point-min))
8176         (gnus-summary-position-point)
8177         t))))
8178
8179 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8180   "Mark all unread articles in this newsgroup as read.
8181 If prefix argument ALL is non-nil, ticked and dormant articles will
8182 also be marked as read.
8183 If QUIETLY is non-nil, no questions will be asked.
8184 If TO-HERE is non-nil, it should be a point in the buffer.  All
8185 articles before this point will be marked as read.
8186 Note that this function will only catch up the unread article
8187 in the current summary buffer limitation.
8188 The number of articles marked as read is returned."
8189   (interactive "P")
8190   (prog1
8191       (save-excursion
8192         (when (or quietly
8193                   (not gnus-interactive-catchup) ;Without confirmation?
8194                   gnus-expert-user
8195                   (gnus-y-or-n-p
8196                    (if all
8197                        "Mark absolutely all articles as read? "
8198                      "Mark all unread articles as read? ")))
8199           (if (and not-mark
8200                    (not gnus-newsgroup-adaptive)
8201                    (not gnus-newsgroup-auto-expire)
8202                    (not gnus-suppress-duplicates)
8203                    (or (not gnus-use-cache)
8204                        (eq gnus-use-cache 'passive)))
8205               (progn
8206                 (when all
8207                   (setq gnus-newsgroup-marked nil
8208                         gnus-newsgroup-dormant nil))
8209                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8210             ;; We actually mark all articles as canceled, which we
8211             ;; have to do when using auto-expiry or adaptive scoring.
8212             (gnus-summary-show-all-threads)
8213             (when (gnus-summary-first-subject (not all) t)
8214               (while (and
8215                       (if to-here (< (point) to-here) t)
8216                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8217                       (gnus-summary-find-next (not all) nil nil t))))
8218             (gnus-set-mode-line 'summary))
8219           t))
8220     (gnus-summary-position-point)))
8221
8222 (defun gnus-summary-catchup-to-here (&optional all)
8223   "Mark all unticked articles before the current one as read.
8224 If ALL is non-nil, also mark ticked and dormant articles as read."
8225   (interactive "P")
8226   (save-excursion
8227     (gnus-save-hidden-threads
8228       (let ((beg (point)))
8229         ;; We check that there are unread articles.
8230         (when (or all (gnus-summary-find-prev))
8231           (gnus-summary-catchup all t beg)))))
8232   (gnus-summary-position-point))
8233
8234 (defun gnus-summary-catchup-all (&optional quietly)
8235   "Mark all articles in this newsgroup as read."
8236   (interactive "P")
8237   (gnus-summary-catchup t quietly))
8238
8239 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8240   "Mark all articles not marked as unread in this newsgroup as read, then exit.
8241 If prefix argument ALL is non-nil, all articles are marked as read."
8242   (interactive "P")
8243   (when (gnus-summary-catchup all quietly nil 'fast)
8244     ;; Select next newsgroup or exit.
8245     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8246              (eq gnus-auto-select-next 'quietly))
8247         (gnus-summary-next-group nil)
8248       (gnus-summary-exit))))
8249
8250 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8251   "Mark all articles in this newsgroup as read, and then exit."
8252   (interactive "P")
8253   (gnus-summary-catchup-and-exit t quietly))
8254
8255 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
8256 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8257   "Mark all articles in this group as read and select the next group.
8258 If given a prefix, mark all articles, unread as well as ticked, as
8259 read."
8260   (interactive "P")
8261   (save-excursion
8262     (gnus-summary-catchup all))
8263   (gnus-summary-next-article t nil nil t))
8264
8265 ;; Thread-based commands.
8266
8267 (defun gnus-summary-articles-in-thread (&optional article)
8268   "Return a list of all articles in the current thread.
8269 If ARTICLE is non-nil, return all articles in the thread that starts
8270 with that article."
8271   (let* ((article (or article (gnus-summary-article-number)))
8272          (data (gnus-data-find-list article))
8273          (top-level (gnus-data-level (car data)))
8274          (top-subject
8275           (cond ((null gnus-thread-operation-ignore-subject)
8276                  (gnus-simplify-subject-re
8277                   (mail-header-subject (gnus-data-header (car data)))))
8278                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8279                  (gnus-simplify-subject-fuzzy
8280                   (mail-header-subject (gnus-data-header (car data)))))
8281                 (t nil)))
8282          (end-point (save-excursion
8283                       (if (gnus-summary-go-to-next-thread)
8284                           (point) (point-max))))
8285          articles)
8286     (while (and data
8287                 (< (gnus-data-pos (car data)) end-point))
8288       (when (or (not top-subject)
8289                 (string= top-subject
8290                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8291                              (gnus-simplify-subject-fuzzy
8292                               (mail-header-subject
8293                                (gnus-data-header (car data))))
8294                            (gnus-simplify-subject-re
8295                             (mail-header-subject
8296                              (gnus-data-header (car data)))))))
8297         (push (gnus-data-number (car data)) articles))
8298       (unless (and (setq data (cdr data))
8299                    (> (gnus-data-level (car data)) top-level))
8300         (setq data nil)))
8301     ;; Return the list of articles.
8302     (nreverse articles)))
8303
8304 (defun gnus-summary-rethread-current ()
8305   "Rethread the thread the current article is part of."
8306   (interactive)
8307   (let* ((gnus-show-threads t)
8308          (article (gnus-summary-article-number))
8309          (id (mail-header-id (gnus-summary-article-header)))
8310          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8311     (unless id
8312       (error "No article on the current line"))
8313     (gnus-rebuild-thread id)
8314     (gnus-summary-goto-subject article)))
8315
8316 (defun gnus-summary-reparent-thread ()
8317   "Make the current article child of the marked (or previous) article.
8318
8319 Note that the re-threading will only work if `gnus-thread-ignore-subject'
8320 is non-nil or the Subject: of both articles are the same."
8321   (interactive)
8322   (unless (not (gnus-group-read-only-p))
8323     (error "The current newsgroup does not support article editing"))
8324   (unless (<= (length gnus-newsgroup-processable) 1)
8325     (error "No more than one article may be marked"))
8326   (save-window-excursion
8327     (let ((gnus-article-buffer " *reparent*")
8328           (current-article (gnus-summary-article-number))
8329           ;; First grab the marked article, otherwise one line up.
8330           (parent-article (if (not (null gnus-newsgroup-processable))
8331                               (car gnus-newsgroup-processable)
8332                             (save-excursion
8333                               (if (eq (forward-line -1) 0)
8334                                   (gnus-summary-article-number)
8335                                 (error "Beginning of summary buffer"))))))
8336       (unless (not (eq current-article parent-article))
8337         (error "An article may not be self-referential"))
8338       (let ((message-id (mail-header-id
8339                          (gnus-summary-article-header parent-article))))
8340         (unless (and message-id (not (equal message-id "")))
8341           (error "No message-id in desired parent"))
8342         ;; We don't want the article to be marked as read.
8343         (let (gnus-mark-article-hook)
8344           (gnus-summary-select-article t t nil current-article))
8345         (set-buffer gnus-original-article-buffer)
8346         (let ((buf (format "%s" (buffer-string))))
8347           (with-temp-buffer
8348             (insert buf)
8349             (goto-char (point-min))
8350             (if (re-search-forward "^References: " nil t)
8351                 (progn
8352                   (re-search-forward "^[^ \t]" nil t)
8353                   (forward-line -1)
8354                   (end-of-line)
8355                   (insert " " message-id))
8356               (insert "References: " message-id "\n"))
8357             (unless (gnus-request-replace-article
8358                      current-article (car gnus-article-current)
8359                      (current-buffer))
8360               (error "Couldn't replace article"))))
8361         (set-buffer gnus-summary-buffer)
8362         (gnus-summary-unmark-all-processable)
8363         (gnus-summary-update-article current-article)
8364         (gnus-summary-rethread-current)
8365         (gnus-message 3 "Article %d is now the child of article %d"
8366                       current-article parent-article)))))
8367
8368 (defun gnus-summary-toggle-threads (&optional arg)
8369   "Toggle showing conversation threads.
8370 If ARG is positive number, turn showing conversation threads on."
8371   (interactive "P")
8372   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8373     (setq gnus-show-threads
8374           (if (null arg) (not gnus-show-threads)
8375             (> (prefix-numeric-value arg) 0)))
8376     (gnus-summary-prepare)
8377     (gnus-summary-goto-subject current)
8378     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8379     (gnus-summary-position-point)))
8380
8381 (defun gnus-summary-show-all-threads ()
8382   "Show all threads."
8383   (interactive)
8384   (save-excursion
8385     (let ((buffer-read-only nil))
8386       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8387   (gnus-summary-position-point))
8388
8389 (defun gnus-summary-show-thread ()
8390   "Show thread subtrees.
8391 Returns nil if no thread was there to be shown."
8392   (interactive)
8393   (let ((buffer-read-only nil)
8394         (orig (point))
8395         ;; first goto end then to beg, to have point at beg after let
8396         (end (progn (end-of-line) (point)))
8397         (beg (progn (beginning-of-line) (point))))
8398     (prog1
8399         ;; Any hidden lines here?
8400         (search-forward "\r" end t)
8401       (subst-char-in-region beg end ?\^M ?\n t)
8402       (goto-char orig)
8403       (gnus-summary-position-point))))
8404
8405 (defun gnus-summary-hide-all-threads ()
8406   "Hide all thread subtrees."
8407   (interactive)
8408   (save-excursion
8409     (goto-char (point-min))
8410     (gnus-summary-hide-thread)
8411     (while (zerop (gnus-summary-next-thread 1 t))
8412       (gnus-summary-hide-thread)))
8413   (gnus-summary-position-point))
8414
8415 (defun gnus-summary-hide-thread ()
8416   "Hide thread subtrees.
8417 Returns nil if no threads were there to be hidden."
8418   (interactive)
8419   (let ((buffer-read-only nil)
8420         (start (point))
8421         (article (gnus-summary-article-number)))
8422     (goto-char start)
8423     ;; Go forward until either the buffer ends or the subthread
8424     ;; ends.
8425     (when (and (not (eobp))
8426                (or (zerop (gnus-summary-next-thread 1 t))
8427                    (goto-char (point-max))))
8428       (prog1
8429           (if (and (> (point) start)
8430                    (search-backward "\n" start t))
8431               (progn
8432                 (subst-char-in-region start (point) ?\n ?\^M)
8433                 (gnus-summary-goto-subject article))
8434             (goto-char start)
8435             nil)
8436         ;;(gnus-summary-position-point)
8437         ))))
8438
8439 (defun gnus-summary-go-to-next-thread (&optional previous)
8440   "Go to the same level (or less) next thread.
8441 If PREVIOUS is non-nil, go to previous thread instead.
8442 Return the article number moved to, or nil if moving was impossible."
8443   (let ((level (gnus-summary-thread-level))
8444         (way (if previous -1 1))
8445         (beg (point)))
8446     (forward-line way)
8447     (while (and (not (eobp))
8448                 (< level (gnus-summary-thread-level)))
8449       (forward-line way))
8450     (if (eobp)
8451         (progn
8452           (goto-char beg)
8453           nil)
8454       (setq beg (point))
8455       (prog1
8456           (gnus-summary-article-number)
8457         (goto-char beg)))))
8458
8459 (defun gnus-summary-next-thread (n &optional silent)
8460   "Go to the same level next N'th thread.
8461 If N is negative, search backward instead.
8462 Returns the difference between N and the number of skips actually
8463 done.
8464
8465 If SILENT, don't output messages."
8466   (interactive "p")
8467   (let ((backward (< n 0))
8468         (n (abs n)))
8469     (while (and (> n 0)
8470                 (gnus-summary-go-to-next-thread backward))
8471       (decf n))
8472     (unless silent
8473       (gnus-summary-position-point))
8474     (when (and (not silent) (/= 0 n))
8475       (gnus-message 7 "No more threads"))
8476     n))
8477
8478 (defun gnus-summary-prev-thread (n)
8479   "Go to the same level previous N'th thread.
8480 Returns the difference between N and the number of skips actually
8481 done."
8482   (interactive "p")
8483   (gnus-summary-next-thread (- n)))
8484
8485 (defun gnus-summary-go-down-thread ()
8486   "Go down one level in the current thread."
8487   (let ((children (gnus-summary-article-children)))
8488     (when children
8489       (gnus-summary-goto-subject (car children)))))
8490
8491 (defun gnus-summary-go-up-thread ()
8492   "Go up one level in the current thread."
8493   (let ((parent (gnus-summary-article-parent)))
8494     (when parent
8495       (gnus-summary-goto-subject parent))))
8496
8497 (defun gnus-summary-down-thread (n)
8498   "Go down thread N steps.
8499 If N is negative, go up instead.
8500 Returns the difference between N and how many steps down that were
8501 taken."
8502   (interactive "p")
8503   (let ((up (< n 0))
8504         (n (abs n)))
8505     (while (and (> n 0)
8506                 (if up (gnus-summary-go-up-thread)
8507                   (gnus-summary-go-down-thread)))
8508       (setq n (1- n)))
8509     (gnus-summary-position-point)
8510     (when (/= 0 n)
8511       (gnus-message 7 "Can't go further"))
8512     n))
8513
8514 (defun gnus-summary-up-thread (n)
8515   "Go up thread N steps.
8516 If N is negative, go up instead.
8517 Returns the difference between N and how many steps down that were
8518 taken."
8519   (interactive "p")
8520   (gnus-summary-down-thread (- n)))
8521
8522 (defun gnus-summary-top-thread ()
8523   "Go to the top of the thread."
8524   (interactive)
8525   (while (gnus-summary-go-up-thread))
8526   (gnus-summary-article-number))
8527
8528 (defun gnus-summary-kill-thread (&optional unmark)
8529   "Mark articles under current thread as read.
8530 If the prefix argument is positive, remove any kinds of marks.
8531 If the prefix argument is negative, tick articles instead."
8532   (interactive "P")
8533   (when unmark
8534     (setq unmark (prefix-numeric-value unmark)))
8535   (let ((articles (gnus-summary-articles-in-thread)))
8536     (save-excursion
8537       ;; Expand the thread.
8538       (gnus-summary-show-thread)
8539       ;; Mark all the articles.
8540       (while articles
8541         (gnus-summary-goto-subject (car articles))
8542         (cond ((null unmark)
8543                (gnus-summary-mark-article-as-read gnus-killed-mark))
8544               ((> unmark 0)
8545                (gnus-summary-mark-article-as-unread gnus-unread-mark))
8546               (t
8547                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8548         (setq articles (cdr articles))))
8549     ;; Hide killed subtrees.
8550     (and (null unmark)
8551          gnus-thread-hide-killed
8552          (gnus-summary-hide-thread))
8553     ;; If marked as read, go to next unread subject.
8554     (when (null unmark)
8555       ;; Go to next unread subject.
8556       (gnus-summary-next-subject 1 t)))
8557   (gnus-set-mode-line 'summary))
8558
8559 ;; Summary sorting commands
8560
8561 (defun gnus-summary-sort-by-number (&optional reverse)
8562   "Sort the summary buffer by article number.
8563 Argument REVERSE means reverse order."
8564   (interactive "P")
8565   (gnus-summary-sort 'number reverse))
8566
8567 (defun gnus-summary-sort-by-author (&optional reverse)
8568   "Sort the summary buffer by author name alphabetically.
8569 If case-fold-search is non-nil, case of letters is ignored.
8570 Argument REVERSE means reverse order."
8571   (interactive "P")
8572   (gnus-summary-sort 'author reverse))
8573
8574 (defun gnus-summary-sort-by-subject (&optional reverse)
8575   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
8576 If case-fold-search is non-nil, case of letters is ignored.
8577 Argument REVERSE means reverse order."
8578   (interactive "P")
8579   (gnus-summary-sort 'subject reverse))
8580
8581 (defun gnus-summary-sort-by-date (&optional reverse)
8582   "Sort the summary buffer by date.
8583 Argument REVERSE means reverse order."
8584   (interactive "P")
8585   (gnus-summary-sort 'date reverse))
8586
8587 (defun gnus-summary-sort-by-score (&optional reverse)
8588   "Sort the summary buffer by score.
8589 Argument REVERSE means reverse order."
8590   (interactive "P")
8591   (gnus-summary-sort 'score reverse))
8592
8593 (defun gnus-summary-sort-by-lines (&optional reverse)
8594   "Sort the summary buffer by article length.
8595 Argument REVERSE means reverse order."
8596   (interactive "P")
8597   (gnus-summary-sort 'lines reverse))
8598
8599 (defun gnus-summary-sort (predicate reverse)
8600   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8601   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8602          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8603          (gnus-thread-sort-functions
8604           (if (not reverse)
8605               thread
8606             `(lambda (t1 t2)
8607                (,thread t2 t1))))
8608          (gnus-article-sort-functions
8609           (if (not reverse)
8610               article
8611             `(lambda (t1 t2)
8612                (,article t2 t1))))
8613          (buffer-read-only)
8614          (gnus-summary-prepare-hook nil))
8615     ;; We do the sorting by regenerating the threads.
8616     (gnus-summary-prepare)
8617     ;; Hide subthreads if needed.
8618     (when (and gnus-show-threads gnus-thread-hide-subtree)
8619       (gnus-summary-hide-all-threads))))
8620
8621 ;; Summary saving commands.
8622
8623 (defun gnus-summary-save-article (&optional n not-saved)
8624   "Save the current article using the default saver function.
8625 If N is a positive number, save the N next articles.
8626 If N is a negative number, save the N previous articles.
8627 If N is nil and any articles have been marked with the process mark,
8628 save those articles instead.
8629 The variable `gnus-default-article-saver' specifies the saver function."
8630   (interactive "P")
8631   (let* ((articles (gnus-summary-work-articles n))
8632          (save-buffer (save-excursion
8633                         (nnheader-set-temp-buffer " *Gnus Save*")))
8634          (num (length articles))
8635          header article file)
8636     (while articles
8637       (setq header (gnus-summary-article-header
8638                     (setq article (pop articles))))
8639       (if (not (vectorp header))
8640           ;; This is a pseudo-article.
8641           (if (assq 'name header)
8642               (gnus-copy-file (cdr (assq 'name header)))
8643             (gnus-message 1 "Article %d is unsaveable" article))
8644         ;; This is a real article.
8645         (save-window-excursion
8646           (gnus-summary-select-article t nil nil article))
8647         (save-excursion
8648           (set-buffer save-buffer)
8649           (erase-buffer)
8650           (insert-buffer-substring gnus-original-article-buffer))
8651         (setq file (gnus-article-save save-buffer file num))
8652         (gnus-summary-remove-process-mark article)
8653         (unless not-saved
8654           (gnus-summary-set-saved-mark article))))
8655     (gnus-kill-buffer save-buffer)
8656     (gnus-summary-position-point)
8657     (gnus-set-mode-line 'summary)
8658     n))
8659
8660 (defun gnus-summary-pipe-output (&optional arg)
8661   "Pipe the current article to a subprocess.
8662 If N is a positive number, pipe the N next articles.
8663 If N is a negative number, pipe the N previous articles.
8664 If N is nil and any articles have been marked with the process mark,
8665 pipe those articles instead."
8666   (interactive "P")
8667   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8668     (gnus-summary-save-article arg t))
8669   (gnus-configure-windows 'pipe))
8670
8671 (defun gnus-summary-save-article-mail (&optional arg)
8672   "Append the current article to an mail file.
8673 If N is a positive number, save the N next articles.
8674 If N is a negative number, save the N previous articles.
8675 If N is nil and any articles have been marked with the process mark,
8676 save those articles instead."
8677   (interactive "P")
8678   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8679     (gnus-summary-save-article arg)))
8680
8681 (defun gnus-summary-save-article-rmail (&optional arg)
8682   "Append the current article to an rmail file.
8683 If N is a positive number, save the N next articles.
8684 If N is a negative number, save the N previous articles.
8685 If N is nil and any articles have been marked with the process mark,
8686 save those articles instead."
8687   (interactive "P")
8688   (let ((gnus-default-article-saver 'rmail-output-to-rmail-file))
8689     (gnus-summary-save-article arg)))
8690
8691 (defun gnus-summary-save-article-file (&optional arg)
8692   "Append the current article to a file.
8693 If N is a positive number, save the N next articles.
8694 If N is a negative number, save the N previous articles.
8695 If N is nil and any articles have been marked with the process mark,
8696 save those articles instead."
8697   (interactive "P")
8698   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8699     (gnus-summary-save-article arg)))
8700
8701 (defun gnus-summary-write-article-file (&optional arg)
8702   "Write the current article to a file, deleting the previous file.
8703 If N is a positive number, save the N next articles.
8704 If N is a negative number, save the N previous articles.
8705 If N is nil and any articles have been marked with the process mark,
8706 save those articles instead."
8707   (interactive "P")
8708   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8709     (gnus-summary-save-article arg)))
8710
8711 (defun gnus-summary-save-article-body-file (&optional arg)
8712   "Append the current article body to a file.
8713 If N is a positive number, save the N next articles.
8714 If N is a negative number, save the N previous articles.
8715 If N is nil and any articles have been marked with the process mark,
8716 save those articles instead."
8717   (interactive "P")
8718   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8719     (gnus-summary-save-article arg)))
8720
8721 (defun gnus-summary-pipe-message (program)
8722   "Pipe the current article through PROGRAM."
8723   (interactive "sProgram: ")
8724   (gnus-summary-select-article)
8725   (let ((mail-header-separator ""))
8726     (gnus-eval-in-buffer-window gnus-article-buffer
8727       (save-restriction
8728         (widen)
8729         (let ((start (window-start))
8730               buffer-read-only)
8731           (message-pipe-buffer-body program)
8732           (set-window-start (get-buffer-window (current-buffer)) start))))))
8733
8734 (defun gnus-get-split-value (methods)
8735   "Return a value based on the split METHODS."
8736   (let (split-name method result match)
8737     (when methods
8738       (save-excursion
8739         (set-buffer gnus-original-article-buffer)
8740         (save-restriction
8741           (nnheader-narrow-to-headers)
8742           (while methods
8743             (goto-char (point-min))
8744             (setq method (pop methods))
8745             (setq match (car method))
8746             (when (cond
8747                    ((stringp match)
8748                     ;; Regular expression.
8749                     (ignore-errors
8750                       (re-search-forward match nil t)))
8751                    ((gnus-functionp match)
8752                     ;; Function.
8753                     (save-restriction
8754                       (widen)
8755                       (setq result (funcall match gnus-newsgroup-name))))
8756                    ((consp match)
8757                     ;; Form.
8758                     (save-restriction
8759                       (widen)
8760                       (setq result (eval match)))))
8761               (setq split-name (append (cdr method) split-name))
8762               (cond ((stringp result)
8763                      (push (expand-file-name
8764                             result gnus-article-save-directory)
8765                            split-name))
8766                     ((consp result)
8767                      (setq split-name (append result split-name)))))))))
8768     split-name))
8769
8770 (defun gnus-valid-move-group-p (group)
8771   (and (boundp group)
8772        (symbol-name group)
8773        (symbol-value group)
8774        (memq 'respool
8775              (assoc (symbol-name
8776                      (car (gnus-find-method-for-group
8777                            (symbol-name group))))
8778                     gnus-valid-select-methods))))
8779
8780 (defun gnus-read-move-group-name (prompt default articles prefix)
8781   "Read a group name."
8782   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
8783          (minibuffer-confirm-incomplete nil) ; XEmacs
8784          (prom
8785           (format "%s %s to:"
8786                   prompt
8787                   (if (> (length articles) 1)
8788                       (format "these %d articles" (length articles))
8789                     "this article")))
8790          (to-newsgroup
8791           (cond
8792            ((null split-name)
8793             (gnus-completing-read default prom
8794                                   gnus-active-hashtb
8795                                   'gnus-valid-move-group-p
8796                                   nil prefix
8797                                   'gnus-group-history))
8798            ((= 1 (length split-name))
8799             (gnus-completing-read (car split-name) prom
8800                                   gnus-active-hashtb
8801                                   'gnus-valid-move-group-p
8802                                   nil nil
8803                                   'gnus-group-history))
8804            (t
8805             (gnus-completing-read nil prom
8806                                   (mapcar (lambda (el) (list el))
8807                                           (nreverse split-name))
8808                                   nil nil nil
8809                                   'gnus-group-history)))))
8810     (when to-newsgroup
8811       (if (or (string= to-newsgroup "")
8812               (string= to-newsgroup prefix))
8813           (setq to-newsgroup default))
8814       (unless to-newsgroup
8815         (error "No group name entered"))
8816       (or (gnus-active to-newsgroup)
8817           (gnus-activate-group to-newsgroup)
8818           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
8819                                      to-newsgroup))
8820               (or (and (gnus-request-create-group
8821                         to-newsgroup (gnus-group-name-to-method to-newsgroup))
8822                        (gnus-activate-group to-newsgroup nil nil
8823                                             (gnus-group-name-to-method
8824                                              to-newsgroup)))
8825                   (error "Couldn't create group %s" to-newsgroup)))
8826           (error "No such group: %s" to-newsgroup)))
8827     to-newsgroup))
8828
8829 ;; Summary extract commands
8830
8831 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
8832   (let ((buffer-read-only nil)
8833         (article (gnus-summary-article-number))
8834         after-article b e)
8835     (unless (gnus-summary-goto-subject article)
8836       (error "No such article: %d" article))
8837     (gnus-summary-position-point)
8838     ;; If all commands are to be bunched up on one line, we collect
8839     ;; them here.
8840     (unless gnus-view-pseudos-separately
8841       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
8842             files action)
8843         (while ps
8844           (setq action (cdr (assq 'action (car ps))))
8845           (setq files (list (cdr (assq 'name (car ps)))))
8846           (while (and ps (cdr ps)
8847                       (string= (or action "1")
8848                                (or (cdr (assq 'action (cadr ps))) "2")))
8849             (push (cdr (assq 'name (cadr ps))) files)
8850             (setcdr ps (cddr ps)))
8851           (when files
8852             (when (not (string-match "%s" action))
8853               (push " " files))
8854             (push " " files)
8855             (when (assq 'execute (car ps))
8856               (setcdr (assq 'execute (car ps))
8857                       (funcall (if (string-match "%s" action)
8858                                    'format 'concat)
8859                                action
8860                                (mapconcat
8861                                 (lambda (f)
8862                                   (if (equal f " ")
8863                                       f
8864                                     (mm-quote-arg f)))
8865                                 files " ")))))
8866           (setq ps (cdr ps)))))
8867     (if (and gnus-view-pseudos (not not-view))
8868         (while pslist
8869           (when (assq 'execute (car pslist))
8870             (gnus-execute-command (cdr (assq 'execute (car pslist)))
8871                                   (eq gnus-view-pseudos 'not-confirm)))
8872           (setq pslist (cdr pslist)))
8873       (save-excursion
8874         (while pslist
8875           (setq after-article (or (cdr (assq 'article (car pslist)))
8876                                   (gnus-summary-article-number)))
8877           (gnus-summary-goto-subject after-article)
8878           (forward-line 1)
8879           (setq b (point))
8880           (insert "    " (file-name-nondirectory
8881                           (cdr (assq 'name (car pslist))))
8882                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
8883           (setq e (point))
8884           (forward-line -1)             ; back to `b'
8885           (gnus-add-text-properties
8886            b (1- e) (list 'gnus-number gnus-reffed-article-number
8887                           gnus-mouse-face-prop gnus-mouse-face))
8888           (gnus-data-enter
8889            after-article gnus-reffed-article-number
8890            gnus-unread-mark b (car pslist) 0 (- e b))
8891           (push gnus-reffed-article-number gnus-newsgroup-unreads)
8892           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
8893           (setq pslist (cdr pslist)))))))
8894
8895 (defun gnus-pseudos< (p1 p2)
8896   (let ((c1 (cdr (assq 'action p1)))
8897         (c2 (cdr (assq 'action p2))))
8898     (and c1 c2 (string< c1 c2))))
8899
8900 (defun gnus-request-pseudo-article (props)
8901   (cond ((assq 'execute props)
8902          (gnus-execute-command (cdr (assq 'execute props)))))
8903   (let ((gnus-current-article (gnus-summary-article-number)))
8904     (gnus-run-hooks 'gnus-mark-article-hook)))
8905
8906 (defun gnus-execute-command (command &optional automatic)
8907   (save-excursion
8908     (gnus-article-setup-buffer)
8909     (set-buffer gnus-article-buffer)
8910     (setq buffer-read-only nil)
8911     (let ((command (if automatic command
8912                      (read-string "Command: " (cons command 0)))))
8913       (erase-buffer)
8914       (insert "$ " command "\n\n")
8915       (if gnus-view-pseudo-asynchronously
8916           (start-process "gnus-execute" (current-buffer) shell-file-name
8917                          shell-command-switch command)
8918         (call-process shell-file-name nil t nil
8919                       shell-command-switch command)))))
8920
8921 ;; Summary kill commands.
8922
8923 (defun gnus-summary-edit-global-kill (article)
8924   "Edit the \"global\" kill file."
8925   (interactive (list (gnus-summary-article-number)))
8926   (gnus-group-edit-global-kill article))
8927
8928 (defun gnus-summary-edit-local-kill ()
8929   "Edit a local kill file applied to the current newsgroup."
8930   (interactive)
8931   (setq gnus-current-headers (gnus-summary-article-header))
8932   (gnus-group-edit-local-kill
8933    (gnus-summary-article-number) gnus-newsgroup-name))
8934
8935 ;;; Header reading.
8936
8937 (defun gnus-read-header (id &optional header)
8938   "Read the headers of article ID and enter them into the Gnus system."
8939   (let ((group gnus-newsgroup-name)
8940         (gnus-override-method
8941          (and (gnus-news-group-p gnus-newsgroup-name)
8942               gnus-refer-article-method))
8943         where)
8944     ;; First we check to see whether the header in question is already
8945     ;; fetched.
8946     (if (stringp id)
8947         ;; This is a Message-ID.
8948         (setq header (or header (gnus-id-to-header id)))
8949       ;; This is an article number.
8950       (setq header (or header (gnus-summary-article-header id))))
8951     (if (and header
8952              (not (gnus-summary-article-sparse-p (mail-header-number header))))
8953         ;; We have found the header.
8954         header
8955       ;; If this is a sparse article, we have to nix out its
8956       ;; previous entry in the thread hashtb.
8957       (when (and header
8958                  (gnus-summary-article-sparse-p (mail-header-number header)))
8959         (let* ((parent (gnus-parent-id (mail-header-references header)))
8960                (thread (and parent (gnus-id-to-thread parent))))
8961           (when thread
8962             (delq (assq header thread) thread))))
8963       ;; We have to really fetch the header to this article.
8964       (save-excursion
8965         (set-buffer nntp-server-buffer)
8966         (when (setq where (gnus-request-head id group))
8967           (nnheader-fold-continuation-lines)
8968           (goto-char (point-max))
8969           (insert ".\n")
8970           (goto-char (point-min))
8971           (insert "211 ")
8972           (princ (cond
8973                   ((numberp id) id)
8974                   ((cdr where) (cdr where))
8975                   (header (mail-header-number header))
8976                   (t gnus-reffed-article-number))
8977                  (current-buffer))
8978           (insert " Article retrieved.\n"))
8979         (if (or (not where)
8980                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
8981             ()                          ; Malformed head.
8982           (unless (gnus-summary-article-sparse-p (mail-header-number header))
8983             (when (and (stringp id)
8984                        (not (string= (gnus-group-real-name group)
8985                                      (car where))))
8986               ;; If we fetched by Message-ID and the article came
8987               ;; from a different group, we fudge some bogus article
8988               ;; numbers for this article.
8989               (mail-header-set-number header gnus-reffed-article-number))
8990             (save-excursion
8991               (set-buffer gnus-summary-buffer)
8992               (decf gnus-reffed-article-number)
8993               (gnus-remove-header (mail-header-number header))
8994               (push header gnus-newsgroup-headers)
8995               (setq gnus-current-headers header)
8996               (push (mail-header-number header) gnus-newsgroup-limit)))
8997           header)))))
8998
8999 (defun gnus-remove-header (number)
9000   "Remove header NUMBER from `gnus-newsgroup-headers'."
9001   (if (and gnus-newsgroup-headers
9002            (= number (mail-header-number (car gnus-newsgroup-headers))))
9003       (pop gnus-newsgroup-headers)
9004     (let ((headers gnus-newsgroup-headers))
9005       (while (and (cdr headers)
9006                   (not (= number (mail-header-number (cadr headers)))))
9007         (pop headers))
9008       (when (cdr headers)
9009         (setcdr headers (cddr headers))))))
9010
9011 ;;;
9012 ;;; summary highlights
9013 ;;;
9014
9015 (defun gnus-highlight-selected-summary ()
9016   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9017   ;; Highlight selected article in summary buffer
9018   (when gnus-summary-selected-face
9019     (save-excursion
9020       (let* ((beg (progn (beginning-of-line) (point)))
9021              (end (progn (end-of-line) (point)))
9022              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9023              (from (if (get-text-property beg gnus-mouse-face-prop)
9024                        beg
9025                      (or (next-single-property-change
9026                           beg gnus-mouse-face-prop nil end)
9027                          beg)))
9028              (to
9029               (if (= from end)
9030                   (- from 2)
9031                 (or (next-single-property-change
9032                      from gnus-mouse-face-prop nil end)
9033                     end))))
9034         ;; If no mouse-face prop on line we will have to = from = end,
9035         ;; so we highlight the entire line instead.
9036         (when (= (+ to 2) from)
9037           (setq from beg)
9038           (setq to end))
9039         (if gnus-newsgroup-selected-overlay
9040             ;; Move old overlay.
9041             (gnus-move-overlay
9042              gnus-newsgroup-selected-overlay from to (current-buffer))
9043           ;; Create new overlay.
9044           (gnus-overlay-put
9045            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9046            'face gnus-summary-selected-face))))))
9047
9048 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9049 (defun gnus-summary-highlight-line ()
9050   "Highlight current line according to `gnus-summary-highlight'."
9051   (let* ((list gnus-summary-highlight)
9052          (p (point))
9053          (end (progn (end-of-line) (point)))
9054          ;; now find out where the line starts and leave point there.
9055          (beg (progn (beginning-of-line) (point)))
9056          (article (gnus-summary-article-number))
9057          (score (or (cdr (assq (or article gnus-current-article)
9058                                gnus-newsgroup-scored))
9059                     gnus-summary-default-score 0))
9060          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9061          (inhibit-read-only t))
9062     ;; Eval the cars of the lists until we find a match.
9063     (let ((default gnus-summary-default-score))
9064       (while (and list
9065                   (not (eval (caar list))))
9066         (setq list (cdr list))))
9067     (let ((face (cdar list)))
9068       (unless (eq face (get-text-property beg 'face))
9069         (gnus-put-text-property-excluding-characters-with-faces
9070          beg end 'face
9071          (setq face (if (boundp face) (symbol-value face) face)))
9072         (when gnus-summary-highlight-line-function
9073           (funcall gnus-summary-highlight-line-function article face))))
9074     (goto-char p)))
9075
9076 (defun gnus-update-read-articles (group unread &optional compute)
9077   "Update the list of read articles in GROUP."
9078   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9079          (entry (gnus-gethash group gnus-newsrc-hashtb))
9080          (info (nth 2 entry))
9081          (prev 1)
9082          (unread (sort (copy-sequence unread) '<))
9083          read)
9084     (if (or (not info) (not active))
9085         ;; There is no info on this group if it was, in fact,
9086         ;; killed.  Gnus stores no information on killed groups, so
9087         ;; there's nothing to be done.
9088         ;; One could store the information somewhere temporarily,
9089         ;; perhaps...  Hmmm...
9090         ()
9091       ;; Remove any negative articles numbers.
9092       (while (and unread (< (car unread) 0))
9093         (setq unread (cdr unread)))
9094       ;; Remove any expired article numbers
9095       (while (and unread (< (car unread) (car active)))
9096         (setq unread (cdr unread)))
9097       ;; Compute the ranges of read articles by looking at the list of
9098       ;; unread articles.
9099       (while unread
9100         (when (/= (car unread) prev)
9101           (push (if (= prev (1- (car unread))) prev
9102                   (cons prev (1- (car unread))))
9103                 read))
9104         (setq prev (1+ (car unread)))
9105         (setq unread (cdr unread)))
9106       (when (<= prev (cdr active))
9107         (push (cons prev (cdr active)) read))
9108       (setq read (if (> (length read) 1) (nreverse read) read))
9109       (if compute
9110           read
9111         (save-excursion
9112           (set-buffer gnus-group-buffer)
9113           (gnus-undo-register
9114             `(progn
9115                (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9116                (gnus-info-set-read ',info ',(gnus-info-read info))
9117                (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
9118                (gnus-group-update-group ,group t))))
9119         ;; Enter this list into the group info.
9120         (gnus-info-set-read info read)
9121         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9122         (gnus-get-unread-articles-in-group info (gnus-active group))
9123         t))))
9124
9125 (defun gnus-offer-save-summaries ()
9126   "Offer to save all active summary buffers."
9127   (save-excursion
9128     (let ((buflist (buffer-list))
9129           buffers bufname)
9130       ;; Go through all buffers and find all summaries.
9131       (while buflist
9132         (and (setq bufname (buffer-name (car buflist)))
9133              (string-match "Summary" bufname)
9134              (save-excursion
9135                (set-buffer bufname)
9136                ;; We check that this is, indeed, a summary buffer.
9137                (and (eq major-mode 'gnus-summary-mode)
9138                     ;; Also make sure this isn't bogus.
9139                     gnus-newsgroup-prepared
9140                     ;; Also make sure that this isn't a dead summary buffer.
9141                     (not gnus-dead-summary-mode)))
9142              (push bufname buffers))
9143         (setq buflist (cdr buflist)))
9144       ;; Go through all these summary buffers and offer to save them.
9145       (when buffers
9146         (map-y-or-n-p
9147          "Update summary buffer %s? "
9148          (lambda (buf)
9149            (switch-to-buffer buf)
9150            (gnus-summary-exit))
9151          buffers)))))
9152
9153 (defun gnus-newsgroup-setup-default-charset ()
9154   "Setup newsgroup default charset."
9155   (let ((name (and gnus-newsgroup-name 
9156                    (string-match "[^:]+$" gnus-newsgroup-name)
9157                    (match-string 0 gnus-newsgroup-name))))
9158     (setq gnus-newsgroup-default-charset
9159           (or (and gnus-newsgroup-name
9160                    (or (gnus-group-find-parameter 
9161                         gnus-newsgroup-name 'charset)
9162                        (let ((alist gnus-newsgroup-default-charset-alist) 
9163                              elem (charset nil))
9164                          (while alist
9165                            (if (and name
9166                                     (string-match 
9167                                      (car (setq elem (pop alist)))
9168                                      name))
9169                                (setq alist nil
9170                                      charset (cdr elem))))
9171                          charset)))
9172               rfc2047-default-charset))
9173     (setq gnus-newsgroup-iso-8859-1-forced 
9174           (and gnus-newsgroup-name
9175                (or (gnus-group-find-parameter
9176                     gnus-newsgroup-name 'iso-8859-1-forced)
9177                    (and name
9178                         (string-match  gnus-newsgroup-iso-8859-1-forced-regexp 
9179                                        name))))))
9180   (if (stringp gnus-newsgroup-default-charset)
9181       (setq gnus-newsgroup-default-charset
9182             (intern (downcase gnus-newsgroup-default-charset))))
9183   (setq gnus-newsgroup-iso-8859-1-forced
9184         (if (stringp gnus-newsgroup-iso-8859-1-forced)
9185             (intern (downcase gnus-newsgroup-iso-8859-1-forced))
9186           (and gnus-newsgroup-iso-8859-1-forced
9187                gnus-newsgroup-default-charset))))
9188   
9189 ;;;
9190 ;;; MIME Commands
9191 ;;;
9192
9193 (defun gnus-summary-display-buttonized (&optional arg)
9194   "Display the current buffer fully MIME-buttonized."
9195   (interactive "P")
9196   (require 'gnus-art)
9197   (let ((gnus-unbuttonized-mime-types nil))
9198     (gnus-summary-show-article arg)))
9199     
9200 (gnus-ems-redefine)
9201
9202 (provide 'gnus-sum)
9203
9204 (run-hooks 'gnus-sum-load-hook)
9205
9206 ;;; gnus-sum.el ends here