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