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