*** 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 t)
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-limit-string gnus-newsgroup-name 35)
3800                            number))))
3801                     (if (string-match "^[ \t]*$" input) number input)))
3802                  ((and (> scored marked) (< scored number)
3803                        (> (- scored number) 20))
3804                   (let ((input
3805                          (read-string
3806                           (format "%s %s (%d scored, %d total): "
3807                                   "How many articles from"
3808                                   group scored number))))
3809                     (if (string-match "^[ \t]*$" input)
3810                         number input)))
3811                  (t number))
3812               (quit nil))))))
3813     (setq select (if (stringp select) (string-to-number select) select))
3814     (if (or (null select) (zerop select))
3815         select
3816       (if (and (not (zerop scored)) (<= (abs select) scored))
3817           (progn
3818             (setq articles (sort scored-list '<))
3819             (setq number (length articles)))
3820         (setq articles (copy-sequence articles)))
3821
3822       (when (< (abs select) number)
3823         (if (< select 0)
3824             ;; Select the N oldest articles.
3825             (setcdr (nthcdr (1- (abs select)) articles) nil)
3826           ;; Select the N most recent articles.
3827           (setq articles (nthcdr (- number select) articles))))
3828       (setq gnus-newsgroup-unselected
3829             (gnus-sorted-intersection
3830              gnus-newsgroup-unreads
3831              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
3832       articles)))
3833
3834 (defun gnus-killed-articles (killed articles)
3835   (let (out)
3836     (while articles
3837       (when (inline (gnus-member-of-range (car articles) killed))
3838         (push (car articles) out))
3839       (setq articles (cdr articles)))
3840     out))
3841
3842 (defun gnus-uncompress-marks (marks)
3843   "Uncompress the mark ranges in MARKS."
3844   (let ((uncompressed '(score bookmark))
3845         out)
3846     (while marks
3847       (if (memq (caar marks) uncompressed)
3848           (push (car marks) out)
3849         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
3850       (setq marks (cdr marks)))
3851     out))
3852
3853 (defun gnus-adjust-marked-articles (info)
3854   "Set all article lists and remove all marks that are no longer legal."
3855   (let* ((marked-lists (gnus-info-marks info))
3856          (active (gnus-active (gnus-info-group info)))
3857          (min (car active))
3858          (max (cdr active))
3859          (types gnus-article-mark-lists)
3860          (uncompressed '(score bookmark killed))
3861          marks var articles article mark)
3862
3863     (while marked-lists
3864       (setq marks (pop marked-lists))
3865       (set (setq var (intern (format "gnus-newsgroup-%s"
3866                                      (car (rassq (setq mark (car marks))
3867                                                  types)))))
3868            (if (memq (car marks) uncompressed) (cdr marks)
3869              (gnus-uncompress-range (cdr marks))))
3870
3871       (setq articles (symbol-value var))
3872
3873       ;; All articles have to be subsets of the active articles.
3874       (cond
3875        ;; Adjust "simple" lists.
3876        ((memq mark '(tick dormant expirable reply save))
3877         (while articles
3878           (when (or (< (setq article (pop articles)) min) (> article max))
3879             (set var (delq article (symbol-value var))))))
3880        ;; Adjust assocs.
3881        ((memq mark uncompressed)
3882         (while articles
3883           (when (or (not (consp (setq article (pop articles))))
3884                     (< (car article) min)
3885                     (> (car article) max))
3886             (set var (delq article (symbol-value var))))))))))
3887
3888 (defun gnus-update-missing-marks (missing)
3889   "Go through the list of MISSING articles and remove them mark lists."
3890   (when missing
3891     (let ((types gnus-article-mark-lists)
3892           var m)
3893       ;; Go through all types.
3894       (while types
3895         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
3896         (when (symbol-value var)
3897           ;; This list has articles.  So we delete all missing articles
3898           ;; from it.
3899           (setq m missing)
3900           (while m
3901             (set var (delq (pop m) (symbol-value var)))))))))
3902
3903 (defun gnus-update-marks ()
3904   "Enter the various lists of marked articles into the newsgroup info list."
3905   (let ((types gnus-article-mark-lists)
3906         (info (gnus-get-info gnus-newsgroup-name))
3907         (uncompressed '(score bookmark killed))
3908         type list newmarked symbol)
3909     (when info
3910       ;; Add all marks lists that are non-nil to the list of marks lists.
3911       (while types
3912         (setq type (pop types))
3913         (when (setq list (symbol-value
3914                           (setq symbol
3915                                 (intern (format "gnus-newsgroup-%s"
3916                                                 (car type))))))
3917           (push (cons (cdr type)
3918                       (if (memq (cdr type) uncompressed) list
3919                         (gnus-compress-sequence 
3920                          (set symbol (sort list '<)) t)))
3921                 newmarked)))
3922
3923       ;; Enter these new marks into the info of the group.
3924       (if (nthcdr 3 info)
3925           (setcar (nthcdr 3 info) newmarked)
3926         ;; Add the marks lists to the end of the info.
3927         (when newmarked
3928           (setcdr (nthcdr 2 info) (list newmarked))))
3929
3930       ;; Cut off the end of the info if there's nothing else there.
3931       (let ((i 5))
3932         (while (and (> i 2)
3933                     (not (nth i info)))
3934           (when (nthcdr (decf i) info)
3935             (setcdr (nthcdr i info) nil)))))))
3936
3937 (defun gnus-set-mode-line (where)
3938   "This function sets the mode line of the article or summary buffers.
3939 If WHERE is `summary', the summary mode line format will be used."
3940   ;; Is this mode line one we keep updated?
3941   (when (memq where gnus-updated-mode-lines)
3942     (let (mode-string)
3943       (save-excursion
3944         ;; We evaluate this in the summary buffer since these
3945         ;; variables are buffer-local to that buffer.
3946         (set-buffer gnus-summary-buffer)
3947         ;; We bind all these variables that are used in the `eval' form
3948         ;; below.
3949         (let* ((mformat (symbol-value
3950                          (intern
3951                           (format "gnus-%s-mode-line-format-spec" where))))
3952                (gnus-tmp-group-name gnus-newsgroup-name)
3953                (gnus-tmp-article-number (or gnus-current-article 0))
3954                (gnus-tmp-unread gnus-newsgroup-unreads)
3955                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
3956                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
3957                (gnus-tmp-unread-and-unselected
3958                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
3959                             (zerop gnus-tmp-unselected))
3960                        "")
3961                       ((zerop gnus-tmp-unselected)
3962                        (format "{%d more}" gnus-tmp-unread-and-unticked))
3963                       (t (format "{%d(+%d) more}"
3964                                  gnus-tmp-unread-and-unticked
3965                                  gnus-tmp-unselected))))
3966                (gnus-tmp-subject
3967                 (if (and gnus-current-headers
3968                          (vectorp gnus-current-headers))
3969                     (gnus-mode-string-quote
3970                      (mail-header-subject gnus-current-headers))
3971                   ""))
3972                max-len
3973                gnus-tmp-header);; passed as argument to any user-format-funcs
3974           (setq mode-string (eval mformat))
3975           (setq max-len (max 4 (if gnus-mode-non-string-length
3976                                    (- (window-width)
3977                                       gnus-mode-non-string-length)
3978                                  (length mode-string))))
3979           ;; We might have to chop a bit of the string off...
3980           (when (> (length mode-string) max-len)
3981             (setq mode-string
3982                   (concat (gnus-truncate-string mode-string (- max-len 3))
3983                           "...")))
3984           ;; Pad the mode string a bit.
3985           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
3986       ;; Update the mode line.
3987       (setq mode-line-buffer-identification 
3988             (gnus-mode-line-buffer-identification
3989              (list mode-string)))
3990       (set-buffer-modified-p t))))
3991
3992 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
3993   "Go through the HEADERS list and add all Xrefs to a hash table.
3994 The resulting hash table is returned, or nil if no Xrefs were found."
3995   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
3996          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
3997          (xref-hashtb (gnus-make-hashtable))
3998          start group entry number xrefs header)
3999     (while headers
4000       (setq header (pop headers))
4001       (when (and (setq xrefs (mail-header-xref header))
4002                  (not (memq (setq number (mail-header-number header))
4003                             unreads)))
4004         (setq start 0)
4005         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4006           (setq start (match-end 0))
4007           (setq group (if prefix
4008                           (concat prefix (substring xrefs (match-beginning 1)
4009                                                     (match-end 1)))
4010                         (substring xrefs (match-beginning 1) (match-end 1))))
4011           (setq number
4012                 (string-to-int (substring xrefs (match-beginning 2)
4013                                           (match-end 2))))
4014           (if (setq entry (gnus-gethash group xref-hashtb))
4015               (setcdr entry (cons number (cdr entry)))
4016             (gnus-sethash group (cons number nil) xref-hashtb)))))
4017     (and start xref-hashtb)))
4018
4019 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4020   "Look through all the headers and mark the Xrefs as read."
4021   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4022         name entry info xref-hashtb idlist method nth4)
4023     (save-excursion
4024       (set-buffer gnus-group-buffer)
4025       (when (setq xref-hashtb
4026                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4027         (mapatoms
4028          (lambda (group)
4029            (unless (string= from-newsgroup (setq name (symbol-name group)))
4030              (setq idlist (symbol-value group))
4031              ;; Dead groups are not updated.
4032              (and (prog1
4033                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4034                             info (nth 2 entry))
4035                     (when (stringp (setq nth4 (gnus-info-method info)))
4036                       (setq nth4 (gnus-server-to-method nth4))))
4037                   ;; Only do the xrefs if the group has the same
4038                   ;; select method as the group we have just read.
4039                   (or (gnus-methods-equal-p
4040                        nth4 (gnus-find-method-for-group from-newsgroup))
4041                       virtual
4042                       (equal nth4 (setq method (gnus-find-method-for-group
4043                                                 from-newsgroup)))
4044                       (and (equal (car nth4) (car method))
4045                            (equal (nth 1 nth4) (nth 1 method))))
4046                   gnus-use-cross-reference
4047                   (or (not (eq gnus-use-cross-reference t))
4048                       virtual
4049                       ;; Only do cross-references on subscribed
4050                       ;; groups, if that is what is wanted.
4051                       (<= (gnus-info-level info) gnus-level-subscribed))
4052                   (gnus-group-make-articles-read name idlist))))
4053          xref-hashtb)))))
4054
4055 (defun gnus-group-make-articles-read (group articles)
4056   "Update the info of GROUP to say that only ARTICLES are unread."
4057   (let* ((num 0)
4058          (entry (gnus-gethash group gnus-newsrc-hashtb))
4059          (info (nth 2 entry))
4060          (active (gnus-active group))
4061          range)
4062     ;; First peel off all illegal article numbers.
4063     (when active
4064       (let ((ids articles)
4065             id first)
4066         (while (setq id (pop ids))
4067           (when (and first (> id (cdr active)))
4068             ;; We'll end up in this situation in one particular
4069             ;; obscure situation.  If you re-scan a group and get
4070             ;; a new article that is cross-posted to a different
4071             ;; group that has not been re-scanned, you might get
4072             ;; crossposted article that has a higher number than
4073             ;; Gnus believes possible.  So we re-activate this
4074             ;; group as well.  This might mean doing the
4075             ;; crossposting thingy will *increase* the number
4076             ;; of articles in some groups.  Tsk, tsk.
4077             (setq active (or (gnus-activate-group group) active)))
4078           (when (or (> id (cdr active))
4079                     (< id (car active)))
4080             (setq articles (delq id articles))))))
4081     (save-excursion
4082       (set-buffer gnus-group-buffer)
4083       (gnus-undo-register
4084         `(progn
4085            (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4086            (gnus-info-set-read ',info ',(gnus-info-read info))
4087            (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4088            (gnus-group-update-group ,group t))))
4089     ;; If the read list is nil, we init it.
4090     (and active
4091          (null (gnus-info-read info))
4092          (> (car active) 1)
4093          (gnus-info-set-read info (cons 1 (1- (car active)))))
4094     ;; Then we add the read articles to the range.
4095     (gnus-info-set-read
4096      info
4097      (setq range
4098            (gnus-add-to-range
4099             (gnus-info-read info) (setq articles (sort articles '<)))))
4100     ;; Then we have to re-compute how many unread
4101     ;; articles there are in this group.
4102     (when active
4103       (cond
4104        ((not range)
4105         (setq num (- (1+ (cdr active)) (car active))))
4106        ((not (listp (cdr range)))
4107         (setq num (- (cdr active) (- (1+ (cdr range))
4108                                      (car range)))))
4109        (t
4110         (while range
4111           (if (numberp (car range))
4112               (setq num (1+ num))
4113             (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4114           (setq range (cdr range)))
4115         (setq num (- (cdr active) num))))
4116       ;; Update the number of unread articles.
4117       (setcar entry num)
4118       ;; Update the group buffer.
4119       (gnus-group-update-group group t))))
4120
4121 (defun gnus-methods-equal-p (m1 m2)
4122   (let ((m1 (or m1 gnus-select-method))
4123         (m2 (or m2 gnus-select-method)))
4124     (or (equal m1 m2)
4125         (and (eq (car m1) (car m2))
4126              (or (not (memq 'address (assoc (symbol-name (car m1))
4127                                             gnus-valid-select-methods)))
4128                  (equal (nth 1 m1) (nth 1 m2)))))))
4129
4130 (defvar gnus-newsgroup-none-id 0)
4131
4132 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4133   (let ((cur nntp-server-buffer)
4134         (dependencies
4135          (or dependencies
4136              (save-excursion (set-buffer gnus-summary-buffer)
4137                              gnus-newsgroup-dependencies)))
4138         headers id id-dep ref-dep end ref)
4139     (save-excursion
4140       (set-buffer nntp-server-buffer)
4141       ;; Translate all TAB characters into SPACE characters.
4142       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4143       (run-hooks 'gnus-parse-headers-hook)
4144       (let ((case-fold-search t)
4145             in-reply-to header p lines)
4146         (goto-char (point-min))
4147         ;; Search to the beginning of the next header.  Error messages
4148         ;; do not begin with 2 or 3.
4149         (while (re-search-forward "^[23][0-9]+ " nil t)
4150           (setq id nil
4151                 ref nil)
4152           ;; This implementation of this function, with nine
4153           ;; search-forwards instead of the one re-search-forward and
4154           ;; a case (which basically was the old function) is actually
4155           ;; about twice as fast, even though it looks messier.  You
4156           ;; can't have everything, I guess.  Speed and elegance
4157           ;; doesn't always go hand in hand.
4158           (setq
4159            header
4160            (vector
4161             ;; Number.
4162             (prog1
4163                 (read cur)
4164               (end-of-line)
4165               (setq p (point))
4166               (narrow-to-region (point)
4167                                 (or (and (search-forward "\n.\n" nil t)
4168                                          (- (point) 2))
4169                                     (point))))
4170             ;; Subject.
4171             (progn
4172               (goto-char p)
4173               (if (search-forward "\nsubject: " nil t)
4174                   (nnheader-header-value) "(none)"))
4175             ;; From.
4176             (progn
4177               (goto-char p)
4178               (if (search-forward "\nfrom: " nil t)
4179                   (nnheader-header-value) "(nobody)"))
4180             ;; Date.
4181             (progn
4182               (goto-char p)
4183               (if (search-forward "\ndate: " nil t)
4184                   (nnheader-header-value) ""))
4185             ;; Message-ID.
4186             (progn
4187               (goto-char p)
4188               (setq id (if (search-forward "\nmessage-id: " nil t)
4189                            (nnheader-header-value)
4190                          ;; If there was no message-id, we just fake one
4191                          ;; to make subsequent routines simpler.
4192                          (nnheader-generate-fake-message-id))))
4193             ;; References.
4194             (progn
4195               (goto-char p)
4196               (if (search-forward "\nreferences: " nil t)
4197                   (progn
4198                     (setq end (point))
4199                     (prog1
4200                         (nnheader-header-value)
4201                       (setq ref
4202                             (buffer-substring
4203                              (progn
4204                                (end-of-line)
4205                                (search-backward ">" end t)
4206                                (1+ (point)))
4207                              (progn
4208                                (search-backward "<" end t)
4209                                (point))))))
4210                 ;; Get the references from the in-reply-to header if there
4211                 ;; were no references and the in-reply-to header looks
4212                 ;; promising.
4213                 (if (and (search-forward "\nin-reply-to: " nil t)
4214                          (setq in-reply-to (nnheader-header-value))
4215                          (string-match "<[^>]+>" in-reply-to))
4216                     (setq ref (substring in-reply-to (match-beginning 0)
4217                                          (match-end 0)))
4218                   (setq ref nil))))
4219             ;; Chars.
4220             0
4221             ;; Lines.
4222             (progn
4223               (goto-char p)
4224               (if (search-forward "\nlines: " nil t)
4225                   (if (numberp (setq lines (read cur)))
4226                       lines 0)
4227                 0))
4228             ;; Xref.
4229             (progn
4230               (goto-char p)
4231               (and (search-forward "\nxref: " nil t)
4232                    (nnheader-header-value)))))
4233           (when (equal id ref)
4234             (setq ref nil))
4235           ;; We do the threading while we read the headers.  The
4236           ;; message-id and the last reference are both entered into
4237           ;; the same hash table.  Some tippy-toeing around has to be
4238           ;; done in case an article has arrived before the article
4239           ;; which it refers to.
4240           (if (boundp (setq id-dep (intern id dependencies)))
4241               (if (and (car (symbol-value id-dep))
4242                        (not force-new))
4243                   ;; An article with this Message-ID has already
4244                   ;; been seen, so we ignore this one, except we add
4245                   ;; any additional Xrefs (in case the two articles
4246                   ;; came from different servers).
4247                   (progn
4248                     (mail-header-set-xref
4249                      (car (symbol-value id-dep))
4250                      (concat (or (mail-header-xref
4251                                   (car (symbol-value id-dep)))
4252                                  "")
4253                              (or (mail-header-xref header) "")))
4254                     (setq header nil))
4255                 (setcar (symbol-value id-dep) header))
4256             (set id-dep (list header)))
4257           (when  header
4258             (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
4259                 (setcdr (symbol-value ref-dep)
4260                         (nconc (cdr (symbol-value ref-dep))
4261                                (list (symbol-value id-dep))))
4262               (set ref-dep (list nil (symbol-value id-dep))))
4263             (push header headers))
4264           (goto-char (point-max))
4265           (widen))
4266         (nreverse headers)))))
4267
4268 ;; The following macros and functions were written by Felix Lee
4269 ;; <flee@cse.psu.edu>.
4270
4271 (defmacro gnus-nov-read-integer ()
4272   '(prog1
4273        (if (= (following-char) ?\t)
4274            0
4275          (let ((num (ignore-errors (read buffer))))
4276            (if (numberp num) num 0)))
4277      (unless (eobp)
4278        (forward-char 1))))
4279
4280 (defmacro gnus-nov-skip-field ()
4281   '(search-forward "\t" eol 'move))
4282
4283 (defmacro gnus-nov-field ()
4284   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
4285
4286 ;; (defvar gnus-nov-none-counter 0)
4287
4288 ;; This function has to be called with point after the article number
4289 ;; on the beginning of the line.
4290 (defun gnus-nov-parse-line (number dependencies &optional force-new)
4291   (let ((eol (gnus-point-at-eol))
4292         (buffer (current-buffer))
4293         header ref id id-dep ref-dep)
4294
4295     ;; overview: [num subject from date id refs chars lines misc]
4296     (unwind-protect
4297         (progn
4298           (narrow-to-region (point) eol)
4299           (unless (eobp)
4300             (forward-char))
4301
4302           (setq header
4303                 (vector
4304                  number                 ; number
4305                  (gnus-nov-field)       ; subject
4306                  (gnus-nov-field)       ; from
4307                  (gnus-nov-field)       ; date
4308                  (setq id (or (gnus-nov-field)
4309                               (nnheader-generate-fake-message-id))) ; id
4310                  (progn
4311                    (let ((beg (point)))
4312                      (search-forward "\t" eol)
4313                      (if (search-backward ">" beg t)
4314                          (setq ref
4315                                (buffer-substring
4316                                 (1+ (point))
4317                                 (search-backward "<" beg t)))
4318                        (setq ref nil))
4319                      (goto-char beg))
4320                    (gnus-nov-field))    ; refs
4321                  (gnus-nov-read-integer) ; chars
4322                  (gnus-nov-read-integer) ; lines
4323                  (if (= (following-char) ?\n)
4324                      nil
4325                    (gnus-nov-field))    ; misc
4326                  )))
4327
4328       (widen))
4329
4330     ;; We build the thread tree.
4331     (when (equal id ref)
4332       ;; This article refers back to itself.  Naughty, naughty.
4333       (setq ref nil))
4334     (if (boundp (setq id-dep (intern id dependencies)))
4335         (if (and (car (symbol-value id-dep))
4336                  (not force-new))
4337             ;; An article with this Message-ID has already been seen,
4338             ;; so we ignore this one, except we add any additional
4339             ;; Xrefs (in case the two articles came from different
4340             ;; servers.
4341             (progn
4342               (mail-header-set-xref
4343                (car (symbol-value id-dep))
4344                (concat (or (mail-header-xref
4345                             (car (symbol-value id-dep)))
4346                            "")
4347                        (or (mail-header-xref header) "")))
4348               (setq header nil))
4349           (setcar (symbol-value id-dep) header))
4350       (set id-dep (list header)))
4351     (when header
4352       (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
4353           (setcdr (symbol-value ref-dep)
4354                   (nconc (cdr (symbol-value ref-dep))
4355                          (list (symbol-value id-dep))))
4356         (set ref-dep (list nil (symbol-value id-dep)))))
4357     header))
4358
4359 ;; Goes through the xover lines and returns a list of vectors
4360 (defun gnus-get-newsgroup-headers-xover (sequence &optional 
4361                                                   force-new dependencies
4362                                                   group also-fetch-heads)
4363   "Parse the news overview data in the server buffer, and return a
4364 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4365   ;; Get the Xref when the users reads the articles since most/some
4366   ;; NNTP servers do not include Xrefs when using XOVER.
4367   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4368   (let ((cur nntp-server-buffer)
4369         (dependencies (or dependencies gnus-newsgroup-dependencies))
4370         number headers header)
4371     (save-excursion
4372       (set-buffer nntp-server-buffer)
4373       ;; Allow the user to mangle the headers before parsing them.
4374       (run-hooks 'gnus-parse-headers-hook)
4375       (goto-char (point-min))
4376       (while (not (eobp))
4377         (condition-case ()
4378             (while (and sequence (not (eobp)))
4379               (setq number (read cur))
4380               (while (and sequence
4381                           (< (car sequence) number))
4382                 (setq sequence (cdr sequence)))
4383               (and sequence
4384                    (eq number (car sequence))
4385                    (progn
4386                      (setq sequence (cdr sequence))
4387                      (setq header (inline
4388                                     (gnus-nov-parse-line
4389                                      number dependencies force-new))))
4390                    (push header headers))
4391               (forward-line 1))
4392           (error
4393            (gnus-error 4 "Strange nov line (%d)"
4394                        (count-lines (point-min) (point)))))
4395         (forward-line 1))
4396       ;; A common bug in inn is that if you have posted an article and
4397       ;; then retrieves the active file, it will answer correctly --
4398       ;; the new article is included.  However, a NOV entry for the
4399       ;; article may not have been generated yet, so this may fail.
4400       ;; We work around this problem by retrieving the last few
4401       ;; headers using HEAD.
4402       (when also-fetch-heads
4403         (if (not sequence)
4404             (nreverse headers)
4405           (let ((gnus-nov-is-evil t)
4406                 (nntp-nov-is-evil t))
4407             (nconc
4408              (nreverse headers)
4409              (when (gnus-retrieve-headers sequence group)
4410                (gnus-get-newsgroup-headers)))))))))
4411
4412 (defun gnus-article-get-xrefs ()
4413   "Fill in the Xref value in `gnus-current-headers', if necessary.
4414 This is meant to be called in `gnus-article-internal-prepare-hook'."
4415   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4416                                  gnus-current-headers)))
4417     (or (not gnus-use-cross-reference)
4418         (not headers)
4419         (and (mail-header-xref headers)
4420              (not (string= (mail-header-xref headers) "")))
4421         (let ((case-fold-search t)
4422               xref)
4423           (save-restriction
4424             (nnheader-narrow-to-headers)
4425             (goto-char (point-min))
4426             (when (or (and (eq (downcase (following-char)) ?x)
4427                            (looking-at "Xref:"))
4428                       (search-forward "\nXref:" nil t))
4429               (goto-char (1+ (match-end 0)))
4430               (setq xref (buffer-substring (point)
4431                                            (progn (end-of-line) (point))))
4432               (mail-header-set-xref headers xref)))))))
4433
4434 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4435   "Find article ID and insert the summary line for that article."
4436   (let ((header (if (and old-header use-old-header)
4437                     old-header (gnus-read-header id)))
4438         (number (and (numberp id) id))
4439         pos d)
4440     (when header
4441       ;; Rebuild the thread that this article is part of and go to the
4442       ;; article we have fetched.
4443       (when (and (not gnus-show-threads)
4444                  old-header)
4445         (when (setq d (gnus-data-find (mail-header-number old-header)))
4446           (goto-char (gnus-data-pos d))
4447           (gnus-data-remove 
4448            number
4449            (- (gnus-point-at-bol)
4450               (prog1
4451                   (1+ (gnus-point-at-eol))
4452                 (gnus-delete-line))))))
4453       (when old-header
4454         (mail-header-set-number header (mail-header-number old-header)))
4455       (setq gnus-newsgroup-sparse
4456             (delq (setq number (mail-header-number header))
4457                   gnus-newsgroup-sparse))
4458       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4459       (gnus-rebuild-thread (mail-header-id header))
4460       (gnus-summary-goto-subject number nil t))
4461     (when (and (numberp number)
4462                (> number 0))
4463       ;; We have to update the boundaries even if we can't fetch the
4464       ;; article if ID is a number -- so that the next `P' or `N'
4465       ;; command will fetch the previous (or next) article even
4466       ;; if the one we tried to fetch this time has been canceled.
4467       (when (> number gnus-newsgroup-end)
4468         (setq gnus-newsgroup-end number))
4469       (when (< number gnus-newsgroup-begin)
4470         (setq gnus-newsgroup-begin number))
4471       (setq gnus-newsgroup-unselected
4472             (delq number gnus-newsgroup-unselected)))
4473     ;; Report back a success?
4474     (and header (mail-header-number header))))
4475
4476 ;;; Process/prefix in the summary buffer
4477
4478 (defun gnus-summary-work-articles (n)
4479   "Return a list of articles to be worked upon.  The prefix argument,
4480 the list of process marked articles, and the current article will be
4481 taken into consideration."
4482   (cond
4483    (n
4484     ;; A numerical prefix has been given.
4485     (setq n (prefix-numeric-value n))
4486     (let ((backward (< n 0))
4487           (n (abs (prefix-numeric-value n)))
4488           articles article)
4489       (save-excursion
4490         (while
4491             (and (> n 0)
4492                  (push (setq article (gnus-summary-article-number))
4493                        articles)
4494                  (if backward
4495                      (gnus-summary-find-prev nil article)
4496                    (gnus-summary-find-next nil article)))
4497           (decf n)))
4498       (nreverse articles)))
4499    ((and (boundp 'transient-mark-mode)
4500          transient-mark-mode
4501          (boundp 'mark-active)
4502          mark-active)
4503     ;; Work on the region between point and mark.
4504     (let ((max (max (point) (mark)))
4505           articles article)
4506       (save-excursion
4507         (goto-char (min (point) (mark)))
4508         (while
4509             (and
4510              (push (setq article (gnus-summary-article-number)) articles)
4511              (gnus-summary-find-next nil article)
4512              (< (point) max)))
4513         (nreverse articles))))
4514    (gnus-newsgroup-processable
4515     ;; There are process-marked articles present.
4516     ;; Save current state.
4517     (gnus-summary-save-process-mark)
4518     ;; Return the list.
4519     (reverse gnus-newsgroup-processable))
4520    (t
4521     ;; Just return the current article.
4522     (list (gnus-summary-article-number)))))
4523
4524 (defun gnus-summary-save-process-mark ()
4525   "Push the current set of process marked articles on the stack."
4526   (interactive)
4527   (push (copy-sequence gnus-newsgroup-processable)
4528         gnus-newsgroup-process-stack))
4529
4530 (defun gnus-summary-kill-process-mark ()
4531   "Push the current set of process marked articles on the stack and unmark."
4532   (interactive)
4533   (gnus-summary-save-process-mark)
4534   (gnus-summary-unmark-all-processable))
4535
4536 (defun gnus-summary-yank-process-mark ()
4537   "Pop the last process mark state off the stack and restore it."
4538   (interactive)
4539   (unless gnus-newsgroup-process-stack
4540     (error "Empty mark stack"))
4541   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4542
4543 (defun gnus-summary-process-mark-set (set)
4544   "Make SET into the current process marked articles."
4545   (gnus-summary-unmark-all-processable)
4546   (while set
4547     (gnus-summary-set-process-mark (pop set))))
4548
4549 ;;; Searching and stuff
4550
4551 (defun gnus-summary-search-group (&optional backward use-level)
4552   "Search for next unread newsgroup.
4553 If optional argument BACKWARD is non-nil, search backward instead."
4554   (save-excursion
4555     (set-buffer gnus-group-buffer)
4556     (when (gnus-group-search-forward
4557            backward nil (if use-level (gnus-group-group-level) nil))
4558       (gnus-group-group-name))))
4559
4560 (defun gnus-summary-best-group (&optional exclude-group)
4561   "Find the name of the best unread group.
4562 If EXCLUDE-GROUP, do not go to this group."
4563   (save-excursion
4564     (set-buffer gnus-group-buffer)
4565     (save-excursion
4566       (gnus-group-best-unread-group exclude-group))))
4567
4568 (defun gnus-summary-find-next (&optional unread article backward)
4569   (if backward (gnus-summary-find-prev)
4570     (let* ((dummy (gnus-summary-article-intangible-p))
4571            (article (or article (gnus-summary-article-number)))
4572            (arts (gnus-data-find-list article))
4573            result)
4574       (when (and (not dummy)
4575                  (or (not gnus-summary-check-current)
4576                      (not unread)
4577                      (not (gnus-data-unread-p (car arts)))))
4578         (setq arts (cdr arts)))
4579       (when (setq result
4580                   (if unread
4581                       (progn
4582                         (while arts
4583                           (when (gnus-data-unread-p (car arts))
4584                             (setq result (car arts)
4585                                   arts nil))
4586                           (setq arts (cdr arts)))
4587                         result)
4588                     (car arts)))
4589         (goto-char (gnus-data-pos result))
4590         (gnus-data-number result)))))
4591
4592 (defun gnus-summary-find-prev (&optional unread article)
4593   (let* ((eobp (eobp))
4594          (article (or article (gnus-summary-article-number)))
4595          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
4596          result)
4597     (when (and (not eobp)
4598                (or (not gnus-summary-check-current)
4599                    (not unread)
4600                    (not (gnus-data-unread-p (car arts)))))
4601       (setq arts (cdr arts)))
4602     (when (setq result
4603                 (if unread
4604                     (progn
4605                       (while arts
4606                         (when (gnus-data-unread-p (car arts))
4607                           (setq result (car arts)
4608                                 arts nil))
4609                         (setq arts (cdr arts)))
4610                       result)
4611                   (car arts)))
4612       (goto-char (gnus-data-pos result))
4613       (gnus-data-number result))))
4614
4615 (defun gnus-summary-find-subject (subject &optional unread backward article)
4616   (let* ((simp-subject (gnus-simplify-subject-fully subject))
4617          (article (or article (gnus-summary-article-number)))
4618          (articles (gnus-data-list backward))
4619          (arts (gnus-data-find-list article articles))
4620          result)
4621     (when (or (not gnus-summary-check-current)
4622               (not unread)
4623               (not (gnus-data-unread-p (car arts))))
4624       (setq arts (cdr arts)))
4625     (while arts
4626       (and (or (not unread)
4627                (gnus-data-unread-p (car arts)))
4628            (vectorp (gnus-data-header (car arts)))
4629            (gnus-subject-equal
4630             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
4631            (setq result (car arts)
4632                  arts nil))
4633       (setq arts (cdr arts)))
4634     (and result
4635          (goto-char (gnus-data-pos result))
4636          (gnus-data-number result))))
4637
4638 (defun gnus-summary-search-forward (&optional unread subject backward)
4639   "Search forward for an article.
4640 If UNREAD, look for unread articles.  If SUBJECT, look for
4641 articles with that subject.  If BACKWARD, search backward instead."
4642   (cond (subject (gnus-summary-find-subject subject unread backward))
4643         (backward (gnus-summary-find-prev unread))
4644         (t (gnus-summary-find-next unread))))
4645
4646 (defun gnus-recenter (&optional n)
4647   "Center point in window and redisplay frame.
4648 Also do horizontal recentering."
4649   (interactive "P")
4650   (when (and gnus-auto-center-summary
4651              (not (eq gnus-auto-center-summary 'vertical)))
4652     (gnus-horizontal-recenter))
4653   (recenter n))
4654
4655 (defun gnus-summary-recenter ()
4656   "Center point in the summary window.
4657 If `gnus-auto-center-summary' is nil, or the article buffer isn't
4658 displayed, no centering will be performed."
4659   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
4660   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
4661   (let* ((top (cond ((< (window-height) 4) 0)
4662                     ((< (window-height) 7) 1)
4663                     (t 2)))
4664          (height (1- (window-height)))
4665          (bottom (save-excursion (goto-char (point-max))
4666                                  (forward-line (- height))
4667                                  (point)))
4668          (window (get-buffer-window (current-buffer))))
4669     ;; The user has to want it.
4670     (when gnus-auto-center-summary
4671       (when (get-buffer-window gnus-article-buffer)
4672         ;; Only do recentering when the article buffer is displayed,
4673         ;; Set the window start to either `bottom', which is the biggest
4674         ;; possible valid number, or the second line from the top,
4675         ;; whichever is the least.
4676         (set-window-start
4677          window (min bottom (save-excursion 
4678                               (forward-line (- top)) (point)))))
4679       ;; Do horizontal recentering while we're at it.
4680       (when (and (get-buffer-window (current-buffer) t)
4681                  (not (eq gnus-auto-center-summary 'vertical)))
4682         (let ((selected (selected-window)))
4683           (select-window (get-buffer-window (current-buffer) t))
4684           (gnus-summary-position-point)
4685           (gnus-horizontal-recenter)
4686           (select-window selected))))))
4687
4688 (defun gnus-summary-jump-to-group (newsgroup)
4689   "Move point to NEWSGROUP in group mode buffer."
4690   ;; Keep update point of group mode buffer if visible.
4691   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
4692       (save-window-excursion
4693         ;; Take care of tree window mode.
4694         (when (get-buffer-window gnus-group-buffer)
4695           (pop-to-buffer gnus-group-buffer))
4696         (gnus-group-jump-to-group newsgroup))
4697     (save-excursion
4698       ;; Take care of tree window mode.
4699       (if (get-buffer-window gnus-group-buffer)
4700           (pop-to-buffer gnus-group-buffer)
4701         (set-buffer gnus-group-buffer))
4702       (gnus-group-jump-to-group newsgroup))))
4703
4704 ;; This function returns a list of article numbers based on the
4705 ;; difference between the ranges of read articles in this group and
4706 ;; the range of active articles.
4707 (defun gnus-list-of-unread-articles (group)
4708   (let* ((read (gnus-info-read (gnus-get-info group)))
4709          (active (or (gnus-active group) (gnus-activate-group group)))
4710          (last (cdr active))
4711          first nlast unread)
4712     ;; If none are read, then all are unread.
4713     (if (not read)
4714         (setq first (car active))
4715       ;; If the range of read articles is a single range, then the
4716       ;; first unread article is the article after the last read
4717       ;; article.  Sounds logical, doesn't it?
4718       (if (not (listp (cdr read)))
4719           (setq first (1+ (cdr read)))
4720         ;; `read' is a list of ranges.
4721         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
4722                                   (caar read)))
4723                   1)
4724           (setq first 1))
4725         (while read
4726           (when first
4727             (while (< first nlast)
4728               (push first unread)
4729               (setq first (1+ first))))
4730           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
4731           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
4732           (setq read (cdr read)))))
4733     ;; And add the last unread articles.
4734     (while (<= first last)
4735       (push first unread)
4736       (setq first (1+ first)))
4737     ;; Return the list of unread articles.
4738     (nreverse unread)))
4739
4740 (defun gnus-list-of-read-articles (group)
4741   "Return a list of unread, unticked and non-dormant articles."
4742   (let* ((info (gnus-get-info group))
4743          (marked (gnus-info-marks info))
4744          (active (gnus-active group)))
4745     (and info active
4746          (gnus-set-difference
4747           (gnus-sorted-complement
4748            (gnus-uncompress-range active)
4749            (gnus-list-of-unread-articles group))
4750           (append
4751            (gnus-uncompress-range (cdr (assq 'dormant marked)))
4752            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
4753
4754 ;; Various summary commands
4755
4756 (defun gnus-summary-universal-argument (arg)
4757   "Perform any operation on all articles that are process/prefixed."
4758   (interactive "P")
4759   (gnus-set-global-variables)
4760   (let ((articles (gnus-summary-work-articles arg))
4761         func article)
4762     (if (eq
4763          (setq
4764           func
4765           (key-binding
4766            (read-key-sequence
4767             (substitute-command-keys
4768              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
4769              ))))
4770          'undefined)
4771         (gnus-error 1 "Undefined key")
4772       (save-excursion
4773         (while articles
4774           (gnus-summary-goto-subject (setq article (pop articles)))
4775           (let (gnus-newsgroup-processable)
4776             (command-execute func))
4777           (gnus-summary-remove-process-mark article)))))
4778   (gnus-summary-position-point))
4779
4780 (defun gnus-summary-toggle-truncation (&optional arg)
4781   "Toggle truncation of summary lines.
4782 With arg, turn line truncation on iff arg is positive."
4783   (interactive "P")
4784   (setq truncate-lines
4785         (if (null arg) (not truncate-lines)
4786           (> (prefix-numeric-value arg) 0)))
4787   (redraw-display))
4788
4789 (defun gnus-summary-reselect-current-group (&optional all rescan)
4790   "Exit and then reselect the current newsgroup.
4791 The prefix argument ALL means to select all articles."
4792   (interactive "P")
4793   (gnus-set-global-variables)
4794   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
4795     (error "Ephemeral groups can't be reselected"))
4796   (let ((current-subject (gnus-summary-article-number))
4797         (group gnus-newsgroup-name))
4798     (setq gnus-newsgroup-begin nil)
4799     (gnus-summary-exit)
4800     ;; We have to adjust the point of group mode buffer because the
4801     ;; current point was moved to the next unread newsgroup by
4802     ;; exiting.
4803     (gnus-summary-jump-to-group group)
4804     (when rescan
4805       (save-excursion
4806         (gnus-group-get-new-news-this-group 1)))
4807     (gnus-group-read-group all t)
4808     (gnus-summary-goto-subject current-subject nil t)))
4809
4810 (defun gnus-summary-rescan-group (&optional all)
4811   "Exit the newsgroup, ask for new articles, and select the newsgroup."
4812   (interactive "P")
4813   (gnus-summary-reselect-current-group all t))
4814
4815 (defun gnus-summary-update-info (&optional non-destructive)
4816   (save-excursion
4817     (let ((group gnus-newsgroup-name))
4818       (when gnus-newsgroup-kill-headers
4819         (setq gnus-newsgroup-killed
4820               (gnus-compress-sequence
4821                (nconc
4822                 (gnus-set-sorted-intersection
4823                  (gnus-uncompress-range gnus-newsgroup-killed)
4824                  (setq gnus-newsgroup-unselected
4825                        (sort gnus-newsgroup-unselected '<)))
4826                 (setq gnus-newsgroup-unreads
4827                       (sort gnus-newsgroup-unreads '<)))
4828                t)))
4829       (unless (listp (cdr gnus-newsgroup-killed))
4830         (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
4831       (let ((headers gnus-newsgroup-headers))
4832         (when (and (not gnus-save-score)
4833                    (not non-destructive))
4834           (setq gnus-newsgroup-scored nil))
4835         ;; Set the new ranges of read articles.
4836         (gnus-update-read-articles
4837          group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
4838         ;; Set the current article marks.
4839         (gnus-update-marks)
4840         ;; Do the cross-ref thing.
4841         (when gnus-use-cross-reference
4842           (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
4843         ;; Do adaptive scoring, and possibly save score files.
4844         (when gnus-newsgroup-adaptive
4845           (gnus-score-adaptive))
4846         (when gnus-use-scoring
4847           (gnus-score-save))
4848         ;; Do not switch windows but change the buffer to work.
4849         (set-buffer gnus-group-buffer)
4850         (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
4851           (gnus-group-update-group group))))))
4852
4853 (defun gnus-summary-save-newsrc (&optional force)
4854   "Save the current number of read/marked articles in the dribble buffer.
4855 The dribble buffer will then be saved.
4856 If FORCE (the prefix), also save the .newsrc file(s)."
4857   (interactive "P")
4858   (gnus-summary-update-info t)
4859   (if force
4860       (gnus-save-newsrc-file)
4861     (gnus-dribble-save)))
4862
4863 (defun gnus-summary-exit (&optional temporary)
4864   "Exit reading current newsgroup, and then return to group selection mode.
4865 gnus-exit-group-hook is called with no arguments if that value is non-nil."
4866   (interactive)
4867   (gnus-set-global-variables)
4868   (gnus-kill-save-kill-buffer)
4869   (let* ((group gnus-newsgroup-name)
4870          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
4871          (mode major-mode)
4872          (buf (current-buffer)))
4873     (run-hooks 'gnus-summary-prepare-exit-hook)
4874     ;; If we have several article buffers, we kill them at exit.
4875     (unless gnus-single-article-buffer
4876       (gnus-kill-buffer gnus-original-article-buffer)
4877       (setq gnus-article-current nil))
4878     (when gnus-use-cache
4879       (gnus-cache-possibly-remove-articles)
4880       (gnus-cache-save-buffers))
4881     (gnus-async-prefetch-remove-group group)
4882     (when gnus-suppress-duplicates
4883       (gnus-dup-enter-articles))
4884     (when gnus-use-trees
4885       (gnus-tree-close group))
4886     ;; Make all changes in this group permanent.
4887     (unless quit-config
4888       (run-hooks 'gnus-exit-group-hook)
4889       (gnus-summary-update-info))
4890     (gnus-close-group group)
4891     ;; Make sure where I was, and go to next newsgroup.
4892     (set-buffer gnus-group-buffer)
4893     (unless quit-config
4894       (gnus-group-jump-to-group group))
4895     (run-hooks 'gnus-summary-exit-hook)
4896     (unless quit-config
4897       (gnus-group-next-unread-group 1))
4898     (if temporary
4899         nil                             ;Nothing to do.
4900       ;; If we have several article buffers, we kill them at exit.
4901       (unless gnus-single-article-buffer
4902         (gnus-kill-buffer gnus-article-buffer)
4903         (gnus-kill-buffer gnus-original-article-buffer)
4904         (setq gnus-article-current nil))
4905       (set-buffer buf)
4906       (if (not gnus-kill-summary-on-exit)
4907           (gnus-deaden-summary)
4908         ;; We set all buffer-local variables to nil.  It is unclear why
4909         ;; this is needed, but if we don't, buffer-local variables are
4910         ;; not garbage-collected, it seems.  This would the lead to en
4911         ;; ever-growing Emacs.
4912         (gnus-summary-clear-local-variables)
4913         (when (get-buffer gnus-article-buffer)
4914           (bury-buffer gnus-article-buffer))
4915         ;; We clear the global counterparts of the buffer-local
4916         ;; variables as well, just to be on the safe side.
4917         (set-buffer gnus-group-buffer)
4918         (gnus-summary-clear-local-variables)
4919         ;; Return to group mode buffer.
4920         (when (eq mode 'gnus-summary-mode)
4921           (gnus-kill-buffer buf)))
4922       (setq gnus-current-select-method gnus-select-method)
4923       (pop-to-buffer gnus-group-buffer)
4924       ;; Clear the current group name.
4925       (if (not quit-config)
4926           (progn
4927             (gnus-group-jump-to-group group)
4928             (gnus-group-next-unread-group 1)
4929             (gnus-configure-windows 'group 'force))
4930         (gnus-handle-ephemeral-exit quit-config))
4931       (unless quit-config
4932         (setq gnus-newsgroup-name nil)))))
4933
4934 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
4935 (defun gnus-summary-exit-no-update (&optional no-questions)
4936   "Quit reading current newsgroup without updating read article info."
4937   (interactive)
4938   (gnus-set-global-variables)
4939   (let* ((group gnus-newsgroup-name)
4940          (quit-config (gnus-group-quit-config group)))
4941     (when (or no-questions
4942               gnus-expert-user
4943               (gnus-y-or-n-p "Discard changes to this group and exit? "))
4944       ;; If we have several article buffers, we kill them at exit.
4945       (unless gnus-single-article-buffer
4946         (gnus-kill-buffer gnus-article-buffer)
4947         (gnus-kill-buffer gnus-original-article-buffer)
4948         (setq gnus-article-current nil))
4949       (if (not gnus-kill-summary-on-exit)
4950           (gnus-deaden-summary)
4951         (gnus-close-group group)
4952         (gnus-summary-clear-local-variables)
4953         (set-buffer gnus-group-buffer)
4954         (gnus-summary-clear-local-variables)
4955         (when (get-buffer gnus-summary-buffer)
4956           (kill-buffer gnus-summary-buffer)))
4957       (unless gnus-single-article-buffer
4958         (setq gnus-article-current nil))
4959       (when gnus-use-trees
4960         (gnus-tree-close group))
4961       (gnus-async-prefetch-remove-group group)
4962       (when (get-buffer gnus-article-buffer)
4963         (bury-buffer gnus-article-buffer))
4964       ;; Return to the group buffer.
4965       (gnus-configure-windows 'group 'force)
4966       ;; Clear the current group name.
4967       (setq gnus-newsgroup-name nil)
4968       (when (equal (gnus-group-group-name) group)
4969         (gnus-group-next-unread-group 1))
4970       (when quit-config
4971         (gnus-handle-ephemeral-exit quit-config)))))
4972
4973 (defun gnus-handle-ephemeral-exit (quit-config)
4974   "Handle movement when leaving an ephemeral group.  The state
4975 which existed when entering the ephemeral is reset."
4976   (if (not (buffer-name (car quit-config)))
4977       (gnus-configure-windows 'group 'force)
4978     (set-buffer (car quit-config))
4979     (cond ((eq major-mode 'gnus-summary-mode)
4980            (gnus-set-global-variables))
4981           ((eq major-mode 'gnus-article-mode)
4982            (save-excursion
4983              ;; The `gnus-summary-buffer' variable may point
4984              ;; to the old summary buffer when using a single
4985              ;; article buffer.
4986              (unless (gnus-buffer-live-p gnus-summary-buffer)
4987                (set-buffer gnus-group-buffer))
4988              (set-buffer gnus-summary-buffer)
4989              (gnus-set-global-variables))))
4990     (if (or (eq (cdr quit-config) 'article)
4991             (eq (cdr quit-config) 'pick))
4992         (progn
4993           ;; The current article may be from the ephemeral group
4994           ;; thus it is best that we reload this article
4995           (gnus-summary-show-article)
4996           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
4997               (gnus-configure-windows 'pick 'force)
4998             (gnus-configure-windows (cdr quit-config) 'force)))
4999       (gnus-configure-windows (cdr quit-config) 'force))
5000     (when (eq major-mode 'gnus-summary-mode)
5001       (gnus-summary-next-subject 1 nil t)
5002       (gnus-summary-recenter)
5003       (gnus-summary-position-point))))
5004
5005 ;;; Dead summaries.
5006
5007 (defvar gnus-dead-summary-mode-map nil)
5008
5009 (unless gnus-dead-summary-mode-map
5010   (setq gnus-dead-summary-mode-map (make-keymap))
5011   (suppress-keymap gnus-dead-summary-mode-map)
5012   (substitute-key-definition
5013    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5014   (let ((keys '("\C-d" "\r" "\177")))
5015     (while keys
5016       (define-key gnus-dead-summary-mode-map
5017         (pop keys) 'gnus-summary-wake-up-the-dead))))
5018
5019 (defvar gnus-dead-summary-mode nil
5020   "Minor mode for Gnus summary buffers.")
5021
5022 (defun gnus-dead-summary-mode (&optional arg)
5023   "Minor mode for Gnus summary buffers."
5024   (interactive "P")
5025   (when (eq major-mode 'gnus-summary-mode)
5026     (make-local-variable 'gnus-dead-summary-mode)
5027     (setq gnus-dead-summary-mode
5028           (if (null arg) (not gnus-dead-summary-mode)
5029             (> (prefix-numeric-value arg) 0)))
5030     (when gnus-dead-summary-mode
5031       (unless (assq 'gnus-dead-summary-mode minor-mode-alist)
5032         (push '(gnus-dead-summary-mode " Dead") minor-mode-alist))
5033       (unless (assq 'gnus-dead-summary-mode minor-mode-map-alist)
5034         (push (cons 'gnus-dead-summary-mode gnus-dead-summary-mode-map)
5035               minor-mode-map-alist)))))
5036
5037 (defun gnus-deaden-summary ()
5038   "Make the current summary buffer into a dead summary buffer."
5039   ;; Kill any previous dead summary buffer.
5040   (when (and gnus-dead-summary
5041              (buffer-name gnus-dead-summary))
5042     (save-excursion
5043       (set-buffer gnus-dead-summary)
5044       (when gnus-dead-summary-mode
5045         (kill-buffer (current-buffer)))))
5046   ;; Make this the current dead summary.
5047   (setq gnus-dead-summary (current-buffer))
5048   (gnus-dead-summary-mode 1)
5049   (let ((name (buffer-name)))
5050     (when (string-match "Summary" name)
5051       (rename-buffer
5052        (concat (substring name 0 (match-beginning 0)) "Dead "
5053                (substring name (match-beginning 0)))
5054        t))))
5055
5056 (defun gnus-kill-or-deaden-summary (buffer)
5057   "Kill or deaden the summary BUFFER."
5058   (when (and (buffer-name buffer)
5059              (not gnus-single-article-buffer))
5060     (save-excursion
5061       (set-buffer buffer)
5062       (gnus-kill-buffer gnus-article-buffer)
5063       (gnus-kill-buffer gnus-original-article-buffer)))
5064   (cond (gnus-kill-summary-on-exit
5065          (when (and gnus-use-trees
5066                     (and (get-buffer buffer)
5067                          (buffer-name (get-buffer buffer))))
5068            (save-excursion
5069              (set-buffer (get-buffer buffer))
5070              (gnus-tree-close gnus-newsgroup-name)))
5071          (gnus-kill-buffer buffer))
5072         ((and (get-buffer buffer)
5073               (buffer-name (get-buffer buffer)))
5074          (save-excursion
5075            (set-buffer buffer)
5076            (gnus-deaden-summary)))))
5077
5078 (defun gnus-summary-wake-up-the-dead (&rest args)
5079   "Wake up the dead summary buffer."
5080   (interactive)
5081   (gnus-dead-summary-mode -1)
5082   (let ((name (buffer-name)))
5083     (when (string-match "Dead " name)
5084       (rename-buffer
5085        (concat (substring name 0 (match-beginning 0))
5086                (substring name (match-end 0)))
5087        t)))
5088   (gnus-message 3 "This dead summary is now alive again"))
5089
5090 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5091 (defun gnus-summary-fetch-faq (&optional faq-dir)
5092   "Fetch the FAQ for the current group.
5093 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5094 in."
5095   (interactive
5096    (list
5097     (when current-prefix-arg
5098       (completing-read
5099        "Faq dir: " (and (listp gnus-group-faq-directory)
5100                         gnus-group-faq-directory)))))
5101   (let (gnus-faq-buffer)
5102     (when (setq gnus-faq-buffer
5103                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5104       (gnus-configure-windows 'summary-faq))))
5105
5106 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5107 (defun gnus-summary-describe-group (&optional force)
5108   "Describe the current newsgroup."
5109   (interactive "P")
5110   (gnus-group-describe-group force gnus-newsgroup-name))
5111
5112 (defun gnus-summary-describe-briefly ()
5113   "Describe summary mode commands briefly."
5114   (interactive)
5115   (gnus-message 6
5116                 (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")))
5117
5118 ;; Walking around group mode buffer from summary mode.
5119
5120 (defun gnus-summary-next-group (&optional no-article target-group backward)
5121   "Exit current newsgroup and then select next unread newsgroup.
5122 If prefix argument NO-ARTICLE is non-nil, no article is selected
5123 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5124 previous group instead."
5125   (interactive "P")
5126   (gnus-set-global-variables)
5127   ;; Stop pre-fetching.
5128   (gnus-async-halt-prefetch)
5129   (let ((current-group gnus-newsgroup-name)
5130         (current-buffer (current-buffer))
5131         entered)
5132     ;; First we semi-exit this group to update Xrefs and all variables.
5133     ;; We can't do a real exit, because the window conf must remain
5134     ;; the same in case the user is prompted for info, and we don't
5135     ;; want the window conf to change before that...
5136     (gnus-summary-exit t)
5137     (while (not entered)
5138       ;; Then we find what group we are supposed to enter.
5139       (set-buffer gnus-group-buffer)
5140       (gnus-group-jump-to-group current-group)
5141       (setq target-group
5142             (or target-group
5143                 (if (eq gnus-keep-same-level 'best)
5144                     (gnus-summary-best-group gnus-newsgroup-name)
5145                   (gnus-summary-search-group backward gnus-keep-same-level))))
5146       (if (not target-group)
5147           ;; There are no further groups, so we return to the group
5148           ;; buffer.
5149           (progn
5150             (gnus-message 5 "Returning to the group buffer")
5151             (setq entered t)
5152             (set-buffer current-buffer)
5153             (gnus-summary-exit)
5154             (run-hooks 'gnus-group-no-more-groups-hook))
5155         ;; We try to enter the target group.
5156         (gnus-group-jump-to-group target-group)
5157         (let ((unreads (gnus-group-group-unread)))
5158           (if (and (or (eq t unreads)
5159                        (and unreads (not (zerop unreads))))
5160                    (gnus-summary-read-group
5161                     target-group nil no-article current-buffer))
5162               (setq entered t)
5163             (setq current-group target-group
5164                   target-group nil)))))))
5165
5166 (defun gnus-summary-prev-group (&optional no-article)
5167   "Exit current newsgroup and then select previous unread newsgroup.
5168 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5169   (interactive "P")
5170   (gnus-summary-next-group no-article nil t))
5171
5172 ;; Walking around summary lines.
5173
5174 (defun gnus-summary-first-subject (&optional unread)
5175   "Go to the first unread subject.
5176 If UNREAD is non-nil, go to the first unread article.
5177 Returns the article selected or nil if there are no unread articles."
5178   (interactive "P")
5179   (prog1
5180       (cond
5181        ;; Empty summary.
5182        ((null gnus-newsgroup-data)
5183         (gnus-message 3 "No articles in the group")
5184         nil)
5185        ;; Pick the first article.
5186        ((not unread)
5187         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5188         (gnus-data-number (car gnus-newsgroup-data)))
5189        ;; No unread articles.
5190        ((null gnus-newsgroup-unreads)
5191         (gnus-message 3 "No more unread articles")
5192         nil)
5193        ;; Find the first unread article.
5194        (t
5195         (let ((data gnus-newsgroup-data))
5196           (while (and data
5197                       (not (gnus-data-unread-p (car data))))
5198             (setq data (cdr data)))
5199           (when data
5200             (goto-char (gnus-data-pos (car data)))
5201             (gnus-data-number (car data))))))
5202     (gnus-summary-position-point)))
5203
5204 (defun gnus-summary-next-subject (n &optional unread dont-display)
5205   "Go to next N'th summary line.
5206 If N is negative, go to the previous N'th subject line.
5207 If UNREAD is non-nil, only unread articles are selected.
5208 The difference between N and the actual number of steps taken is
5209 returned."
5210   (interactive "p")
5211   (let ((backward (< n 0))
5212         (n (abs n)))
5213     (while (and (> n 0)
5214                 (if backward
5215                     (gnus-summary-find-prev unread)
5216                   (gnus-summary-find-next unread)))
5217       (setq n (1- n)))
5218     (when (/= 0 n)
5219       (gnus-message 7 "No more%s articles"
5220                     (if unread " unread" "")))
5221     (unless dont-display
5222       (gnus-summary-recenter)
5223       (gnus-summary-position-point))
5224     n))
5225
5226 (defun gnus-summary-next-unread-subject (n)
5227   "Go to next N'th unread summary line."
5228   (interactive "p")
5229   (gnus-summary-next-subject n t))
5230
5231 (defun gnus-summary-prev-subject (n &optional unread)
5232   "Go to previous N'th summary line.
5233 If optional argument UNREAD is non-nil, only unread article is selected."
5234   (interactive "p")
5235   (gnus-summary-next-subject (- n) unread))
5236
5237 (defun gnus-summary-prev-unread-subject (n)
5238   "Go to previous N'th unread summary line."
5239   (interactive "p")
5240   (gnus-summary-next-subject (- n) t))
5241
5242 (defun gnus-summary-goto-subject (article &optional force silent)
5243   "Go the subject line of ARTICLE.
5244 If FORCE, also allow jumping to articles not currently shown."
5245   (interactive "nArticle number: ")
5246   (let ((b (point))
5247         (data (gnus-data-find article)))
5248     ;; We read in the article if we have to.
5249     (and (not data)
5250          force
5251          (gnus-summary-insert-subject article (and (vectorp force) force) t)
5252          (setq data (gnus-data-find article)))
5253     (goto-char b)
5254     (if (not data)
5255         (progn
5256           (unless silent
5257             (gnus-message 3 "Can't find article %d" article))
5258           nil)
5259       (goto-char (gnus-data-pos data))
5260       article)))
5261
5262 ;; Walking around summary lines with displaying articles.
5263
5264 (defun gnus-summary-expand-window (&optional arg)
5265   "Make the summary buffer take up the entire Emacs frame.
5266 Given a prefix, will force an `article' buffer configuration."
5267   (interactive "P")
5268   (gnus-set-global-variables)
5269   (if arg
5270       (gnus-configure-windows 'article 'force)
5271     (gnus-configure-windows 'summary 'force)))
5272
5273 (defun gnus-summary-display-article (article &optional all-header)
5274   "Display ARTICLE in article buffer."
5275   (gnus-set-global-variables)
5276   (if (null article)
5277       nil
5278     (prog1
5279         (if gnus-summary-display-article-function
5280             (funcall gnus-summary-display-article-function article all-header)
5281           (gnus-article-prepare article all-header))
5282       (run-hooks 'gnus-select-article-hook)
5283       (when (and gnus-current-article
5284                  (not (zerop gnus-current-article)))
5285         (gnus-summary-goto-subject gnus-current-article))
5286       (gnus-summary-recenter)
5287       (when (and gnus-use-trees gnus-show-threads)
5288         (gnus-possibly-generate-tree article)
5289         (gnus-highlight-selected-tree article))
5290       ;; Successfully display article.
5291       (gnus-article-set-window-start
5292        (cdr (assq article gnus-newsgroup-bookmarks))))))
5293
5294 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5295   "Select the current article.
5296 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5297 non-nil, the article will be re-fetched even if it already present in
5298 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5299 be displayed."
5300   ;; Make sure we are in the summary buffer to work around bbdb bug.
5301   (unless (eq major-mode 'gnus-summary-mode)
5302     (set-buffer gnus-summary-buffer))
5303   (let ((article (or article (gnus-summary-article-number)))
5304         (all-headers (not (not all-headers))) ;Must be T or NIL.
5305         gnus-summary-display-article-function
5306         did)
5307     (and (not pseudo)
5308          (gnus-summary-article-pseudo-p article)
5309          (error "This is a pseudo-article."))
5310     (prog1
5311         (save-excursion
5312           (set-buffer gnus-summary-buffer)
5313           (if (or (and gnus-single-article-buffer
5314                        (or (null gnus-current-article)
5315                            (null gnus-article-current)
5316                            (null (get-buffer gnus-article-buffer))
5317                            (not (eq article (cdr gnus-article-current)))
5318                            (not (equal (car gnus-article-current)
5319                                        gnus-newsgroup-name))))
5320                   (and (not gnus-single-article-buffer)
5321                        (or (null gnus-current-article)
5322                            (not (eq gnus-current-article article))))
5323                   force)
5324               ;; The requested article is different from the current article.
5325               (prog1
5326                   (gnus-summary-display-article article all-headers)
5327                 (setq did article))
5328             (when (or all-headers gnus-show-all-headers)
5329               (gnus-article-show-all-headers))
5330             'old))
5331       (when did
5332         (gnus-article-set-window-start
5333          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5334
5335 (defun gnus-summary-set-current-mark (&optional current-mark)
5336   "Obsolete function."
5337   nil)
5338
5339 (defun gnus-summary-next-article (&optional unread subject backward push)
5340   "Select the next article.
5341 If UNREAD, only unread articles are selected.
5342 If SUBJECT, only articles with SUBJECT are selected.
5343 If BACKWARD, the previous article is selected instead of the next."
5344   (interactive "P")
5345   (gnus-set-global-variables)
5346   (cond
5347    ;; Is there such an article?
5348    ((and (gnus-summary-search-forward unread subject backward)
5349          (or (gnus-summary-display-article (gnus-summary-article-number))
5350              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5351     (gnus-summary-position-point))
5352    ;; If not, we try the first unread, if that is wanted.
5353    ((and subject
5354          gnus-auto-select-same
5355          ;; Make sure that we don't select the current article.
5356          (not (eq (gnus-summary-article-number)
5357                   (save-excursion
5358                     (gnus-summary-first-subject t)
5359                     (gnus-summary-article-number))))
5360          (gnus-summary-first-unread-article))
5361     (gnus-summary-position-point)
5362     (gnus-message 6 "Wrapped"))
5363    ;; Try to get next/previous article not displayed in this group.
5364    ((and gnus-auto-extend-newsgroup
5365          (not unread) (not subject))
5366     (gnus-summary-goto-article
5367      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5368      nil t))
5369    ;; Go to next/previous group.
5370    (t
5371     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5372       (gnus-summary-jump-to-group gnus-newsgroup-name))
5373     (let ((cmd last-command-char)
5374           (group
5375            (if (eq gnus-keep-same-level 'best)
5376                (gnus-summary-best-group gnus-newsgroup-name)
5377              (gnus-summary-search-group backward gnus-keep-same-level))))
5378       ;; For some reason, the group window gets selected.  We change
5379       ;; it back.
5380       (select-window (get-buffer-window (current-buffer)))
5381       ;; Select next unread newsgroup automagically.
5382       (cond
5383        ((or (not gnus-auto-select-next)
5384             (not cmd))
5385         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5386        ((or (eq gnus-auto-select-next 'quietly)
5387             (and (eq gnus-auto-select-next 'slightly-quietly)
5388                  push)
5389             (and (eq gnus-auto-select-next 'almost-quietly)
5390                  (gnus-summary-last-article-p)))
5391         ;; Select quietly.
5392         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5393             (gnus-summary-exit)
5394           (gnus-message 7 "No more%s articles (%s)..."
5395                         (if unread " unread" "")
5396                         (if group (concat "selecting " group)
5397                           "exiting"))
5398           (gnus-summary-next-group nil group backward)))
5399        (t
5400         (when (gnus-key-press-event-p last-input-event)
5401           (gnus-summary-walk-group-buffer
5402            gnus-newsgroup-name cmd unread backward))))))))
5403
5404 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward)
5405   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5406                       (?\C-p (gnus-group-prev-unread-group 1))))
5407         (cursor-in-echo-area t)
5408         keve key group ended)
5409     (save-excursion
5410       (set-buffer gnus-group-buffer)
5411       (gnus-summary-jump-to-group from-group)
5412       (setq group
5413             (if (eq gnus-keep-same-level 'best)
5414                 (gnus-summary-best-group gnus-newsgroup-name)
5415               (gnus-summary-search-group backward gnus-keep-same-level))))
5416     (while (not ended)
5417       (gnus-message
5418        5 "No more%s articles%s" (if unread " unread" "")
5419        (if (and group
5420                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5421            (format " (Type %s for %s [%s])"
5422                    (single-key-description cmd) group
5423                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5424          (format " (Type %s to exit %s)"
5425                  (single-key-description cmd)
5426                  gnus-newsgroup-name)))
5427       ;; Confirm auto selection.
5428       (setq key (car (setq keve (gnus-read-event-char))))
5429       (setq ended t)
5430       (cond
5431        ((assq key keystrokes)
5432         (let ((obuf (current-buffer)))
5433           (switch-to-buffer gnus-group-buffer)
5434           (when group
5435             (gnus-group-jump-to-group group))
5436           (eval (cadr (assq key keystrokes)))
5437           (setq group (gnus-group-group-name))
5438           (switch-to-buffer obuf))
5439         (setq ended nil))
5440        ((equal key cmd)
5441         (if (or (not group)
5442                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5443             (gnus-summary-exit)
5444           (gnus-summary-next-group nil group backward)))
5445        (t
5446         (push (cdr keve) unread-command-events))))))
5447
5448 (defun gnus-summary-next-unread-article ()
5449   "Select unread article after current one."
5450   (interactive)
5451   (gnus-summary-next-article 
5452    (or (not (eq gnus-summary-goto-unread 'never))
5453        (gnus-summary-last-article-p (gnus-summary-article-number)))
5454    (and gnus-auto-select-same
5455         (gnus-summary-article-subject))))
5456
5457 (defun gnus-summary-prev-article (&optional unread subject)
5458   "Select the article after the current one.
5459 If UNREAD is non-nil, only unread articles are selected."
5460   (interactive "P")
5461   (gnus-summary-next-article unread subject t))
5462
5463 (defun gnus-summary-prev-unread-article ()
5464   "Select unread article before current one."
5465   (interactive)
5466   (gnus-summary-prev-article
5467    (or (not (eq gnus-summary-goto-unread 'never))
5468        (gnus-summary-first-article-p (gnus-summary-article-number)))
5469    (and gnus-auto-select-same
5470         (gnus-summary-article-subject))))
5471
5472 (defun gnus-summary-next-page (&optional lines circular)
5473   "Show next page of the selected article.
5474 If at the end of the current article, select the next article.
5475 LINES says how many lines should be scrolled up.
5476
5477 If CIRCULAR is non-nil, go to the start of the article instead of
5478 selecting the next article when reaching the end of the current
5479 article."
5480   (interactive "P")
5481   (setq gnus-summary-buffer (current-buffer))
5482   (gnus-set-global-variables)
5483   (let ((article (gnus-summary-article-number))
5484         (article-window (get-buffer-window gnus-article-buffer))
5485         (endp nil))
5486     (gnus-configure-windows 'article)
5487     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5488         (if (and (eq gnus-summary-goto-unread 'never)
5489                  (not (gnus-summary-last-article-p article)))
5490             (gnus-summary-next-article)
5491           (gnus-summary-next-unread-article))
5492       (if (or (null gnus-current-article)
5493               (null gnus-article-current)
5494               (/= article (cdr gnus-article-current))
5495               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5496           ;; Selected subject is different from current article's.
5497           (gnus-summary-display-article article)
5498         (when article-window
5499           (gnus-eval-in-buffer-window gnus-article-buffer
5500             (setq endp (gnus-article-next-page lines)))
5501           (when endp
5502             (cond (circular
5503                    (gnus-summary-beginning-of-article))
5504                   (lines
5505                    (gnus-message 3 "End of message"))
5506                   ((null lines)
5507                    (if (and (eq gnus-summary-goto-unread 'never)
5508                             (not (gnus-summary-last-article-p article)))
5509                        (gnus-summary-next-article)
5510                      (gnus-summary-next-unread-article))))))))
5511     (gnus-summary-recenter)
5512     (gnus-summary-position-point)))
5513
5514 (defun gnus-summary-prev-page (&optional lines)
5515   "Show previous page of selected article.
5516 Argument LINES specifies lines to be scrolled down."
5517   (interactive "P")
5518   (gnus-set-global-variables)
5519   (let ((article (gnus-summary-article-number)))
5520     (gnus-configure-windows 'article)
5521     (if (or (null gnus-current-article)
5522             (null gnus-article-current)
5523             (/= article (cdr gnus-article-current))
5524             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5525         ;; Selected subject is different from current article's.
5526         (gnus-summary-display-article article)
5527       (gnus-summary-recenter)
5528       (gnus-eval-in-buffer-window gnus-article-buffer
5529         (gnus-article-prev-page lines))))
5530   (gnus-summary-position-point))
5531
5532 (defun gnus-summary-scroll-up (lines)
5533   "Scroll up (or down) one line current article.
5534 Argument LINES specifies lines to be scrolled up (or down if negative)."
5535   (interactive "p")
5536   (gnus-set-global-variables)
5537   (gnus-configure-windows 'article)
5538   (gnus-summary-show-thread)
5539   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
5540     (gnus-eval-in-buffer-window gnus-article-buffer
5541       (cond ((> lines 0)
5542              (when (gnus-article-next-page lines)
5543                (gnus-message 3 "End of message")))
5544             ((< lines 0)
5545              (gnus-article-prev-page (- lines))))))
5546   (gnus-summary-recenter)
5547   (gnus-summary-position-point))
5548
5549 (defun gnus-summary-next-same-subject ()
5550   "Select next article which has the same subject as current one."
5551   (interactive)
5552   (gnus-set-global-variables)
5553   (gnus-summary-next-article nil (gnus-summary-article-subject)))
5554
5555 (defun gnus-summary-prev-same-subject ()
5556   "Select previous article which has the same subject as current one."
5557   (interactive)
5558   (gnus-set-global-variables)
5559   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
5560
5561 (defun gnus-summary-next-unread-same-subject ()
5562   "Select next unread article which has the same subject as current one."
5563   (interactive)
5564   (gnus-set-global-variables)
5565   (gnus-summary-next-article t (gnus-summary-article-subject)))
5566
5567 (defun gnus-summary-prev-unread-same-subject ()
5568   "Select previous unread article which has the same subject as current one."
5569   (interactive)
5570   (gnus-set-global-variables)
5571   (gnus-summary-prev-article t (gnus-summary-article-subject)))
5572
5573 (defun gnus-summary-first-unread-article ()
5574   "Select the first unread article.
5575 Return nil if there are no unread articles."
5576   (interactive)
5577   (gnus-set-global-variables)
5578   (prog1
5579       (when (gnus-summary-first-subject t)
5580         (gnus-summary-show-thread)
5581         (gnus-summary-first-subject t)
5582         (gnus-summary-display-article (gnus-summary-article-number)))
5583     (gnus-summary-position-point)))
5584
5585 (defun gnus-summary-first-article ()
5586   "Select the first article.
5587 Return nil if there are no articles."
5588   (interactive)
5589   (gnus-set-global-variables)
5590   (prog1
5591       (when (gnus-summary-first-subject)
5592       (gnus-summary-show-thread)
5593       (gnus-summary-first-subject)
5594       (gnus-summary-display-article (gnus-summary-article-number)))
5595     (gnus-summary-position-point)))
5596
5597 (defun gnus-summary-best-unread-article ()
5598   "Select the unread article with the highest score."
5599   (interactive)
5600   (gnus-set-global-variables)
5601   (let ((best -1000000)
5602         (data gnus-newsgroup-data)
5603         article score)
5604     (while data
5605       (and (gnus-data-unread-p (car data))
5606            (> (setq score
5607                     (gnus-summary-article-score (gnus-data-number (car data))))
5608               best)
5609            (setq best score
5610                  article (gnus-data-number (car data))))
5611       (setq data (cdr data)))
5612     (prog1
5613         (if article
5614             (gnus-summary-goto-article article)
5615           (error "No unread articles"))
5616       (gnus-summary-position-point))))
5617
5618 (defun gnus-summary-last-subject ()
5619   "Go to the last displayed subject line in the group."
5620   (let ((article (gnus-data-number (car (gnus-data-list t)))))
5621     (when article
5622       (gnus-summary-goto-subject article))))
5623
5624 (defun gnus-summary-goto-article (article &optional all-headers force)
5625   "Fetch ARTICLE and display it if it exists.
5626 If ALL-HEADERS is non-nil, no header lines are hidden."
5627   (interactive
5628    (list
5629     (string-to-int
5630      (completing-read
5631       "Article number: "
5632       (mapcar (lambda (number) (list (int-to-string number)))
5633               gnus-newsgroup-limit)))
5634     current-prefix-arg
5635     t))
5636   (prog1
5637       (if (gnus-summary-goto-subject article force)
5638           (gnus-summary-display-article article all-headers)
5639         (gnus-message 4 "Couldn't go to article %s" article) nil)
5640     (gnus-summary-position-point)))
5641
5642 (defun gnus-summary-goto-last-article ()
5643   "Go to the previously read article."
5644   (interactive)
5645   (prog1
5646       (when gnus-last-article
5647         (gnus-summary-goto-article gnus-last-article))
5648     (gnus-summary-position-point)))
5649
5650 (defun gnus-summary-pop-article (number)
5651   "Pop one article off the history and go to the previous.
5652 NUMBER articles will be popped off."
5653   (interactive "p")
5654   (let (to)
5655     (setq gnus-newsgroup-history
5656           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
5657     (if to
5658         (gnus-summary-goto-article (car to))
5659       (error "Article history empty")))
5660   (gnus-summary-position-point))
5661
5662 ;; Summary commands and functions for limiting the summary buffer.
5663
5664 (defun gnus-summary-limit-to-articles (n)
5665   "Limit the summary buffer to the next N articles.
5666 If not given a prefix, use the process marked articles instead."
5667   (interactive "P")
5668   (gnus-set-global-variables)
5669   (prog1
5670       (let ((articles (gnus-summary-work-articles n)))
5671         (setq gnus-newsgroup-processable nil)
5672         (gnus-summary-limit articles))
5673     (gnus-summary-position-point)))
5674
5675 (defun gnus-summary-pop-limit (&optional total)
5676   "Restore the previous limit.
5677 If given a prefix, remove all limits."
5678   (interactive "P")
5679   (gnus-set-global-variables)
5680   (when total 
5681     (setq gnus-newsgroup-limits
5682           (list (mapcar (lambda (h) (mail-header-number h))
5683                         gnus-newsgroup-headers))))
5684   (unless gnus-newsgroup-limits
5685     (error "No limit to pop"))
5686   (prog1
5687       (gnus-summary-limit nil 'pop)
5688     (gnus-summary-position-point)))
5689
5690 (defun gnus-summary-limit-to-subject (subject &optional header)
5691   "Limit the summary buffer to articles that have subjects that match a regexp."
5692   (interactive "sLimit to subject (regexp): ")
5693   (unless header
5694     (setq header "subject"))
5695   (when (not (equal "" subject))
5696     (prog1
5697         (let ((articles (gnus-summary-find-matching
5698                          (or header "subject") subject 'all)))
5699           (unless articles
5700             (error "Found no matches for \"%s\"" subject))
5701           (gnus-summary-limit articles))
5702       (gnus-summary-position-point))))
5703
5704 (defun gnus-summary-limit-to-author (from)
5705   "Limit the summary buffer to articles that have authors that match a regexp."
5706   (interactive "sLimit to author (regexp): ")
5707   (gnus-summary-limit-to-subject from "from"))
5708
5709 (defun gnus-summary-limit-to-age (age &optional younger-p)
5710   "Limit the summary buffer to articles that are older than (or equal) AGE days. 
5711 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
5712 articles that are younger than AGE days."
5713   (interactive "nTime in days: \nP")
5714   (prog1
5715       (let ((data gnus-newsgroup-data)
5716             (cutoff (nnmail-days-to-time age))
5717             articles d date is-younger)
5718         (while (setq d (pop data))
5719           (when (and (vectorp (gnus-data-header d))
5720                      (setq date (mail-header-date (gnus-data-header d))))
5721             (setq is-younger (nnmail-time-less
5722                               (nnmail-time-since (nnmail-date-to-time date))
5723                               cutoff))
5724             (when (if younger-p is-younger (not is-younger))
5725               (push (gnus-data-number d) articles))))
5726         (gnus-summary-limit (nreverse articles)))
5727     (gnus-summary-position-point)))
5728
5729 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
5730 (make-obsolete
5731  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
5732
5733 (defun gnus-summary-limit-to-unread (&optional all)
5734   "Limit the summary buffer to articles that are not marked as read.
5735 If ALL is non-nil, limit strictly to unread articles."
5736   (interactive "P")
5737   (if all
5738       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
5739     (gnus-summary-limit-to-marks
5740      ;; Concat all the marks that say that an article is read and have
5741      ;; those removed.
5742      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
5743            gnus-killed-mark gnus-kill-file-mark
5744            gnus-low-score-mark gnus-expirable-mark
5745            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
5746            gnus-duplicate-mark)
5747      'reverse)))
5748
5749 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
5750 (make-obsolete 'gnus-summary-delete-marked-with
5751                'gnus-summary-limit-exlude-marks)
5752
5753 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
5754   "Exclude articles that are marked with MARKS (e.g. \"DK\").
5755 If REVERSE, limit the summary buffer to articles that are marked
5756 with MARKS.  MARKS can either be a string of marks or a list of marks.
5757 Returns how many articles were removed."
5758   (interactive "sMarks: ")
5759   (gnus-summary-limit-to-marks marks t))
5760   
5761 (defun gnus-summary-limit-to-marks (marks &optional reverse)
5762   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
5763 If REVERSE (the prefix), limit the summary buffer to articles that are
5764 not marked with MARKS.  MARKS can either be a string of marks or a
5765 list of marks.
5766 Returns how many articles were removed."
5767   (interactive (list (read-string "Marks: ") current-prefix-arg))
5768   (gnus-set-global-variables)
5769   (prog1
5770       (let ((data gnus-newsgroup-data)
5771             (marks (if (listp marks) marks
5772                      (append marks nil))) ; Transform to list.
5773             articles)
5774         (while data
5775           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
5776                   (memq (gnus-data-mark (car data)) marks))
5777             (push (gnus-data-number (car data)) articles))
5778           (setq data (cdr data)))
5779         (gnus-summary-limit articles))
5780     (gnus-summary-position-point)))
5781
5782 (defun gnus-summary-limit-to-score (&optional score)
5783   "Limit to articles with score at or above SCORE."
5784   (interactive "P")
5785   (gnus-set-global-variables)
5786   (setq score (if score
5787                   (prefix-numeric-value score)
5788                 (or gnus-summary-default-score 0)))
5789   (let ((data gnus-newsgroup-data)
5790         articles)
5791     (while data
5792       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
5793                 score)
5794         (push (gnus-data-number (car data)) articles))
5795       (setq data (cdr data)))
5796     (prog1
5797         (gnus-summary-limit articles)
5798       (gnus-summary-position-point))))
5799
5800 (defun gnus-summary-limit-include-dormant ()
5801   "Display all the hidden articles that are marked as dormant."
5802   (interactive)
5803   (gnus-set-global-variables)
5804   (unless gnus-newsgroup-dormant
5805     (error "There are no dormant articles in this group"))
5806   (prog1
5807       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
5808     (gnus-summary-position-point)))
5809
5810 (defun gnus-summary-limit-exclude-dormant ()
5811   "Hide all dormant articles."
5812   (interactive)
5813   (gnus-set-global-variables)
5814   (prog1
5815       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
5816     (gnus-summary-position-point)))
5817
5818 (defun gnus-summary-limit-exclude-childless-dormant ()
5819   "Hide all dormant articles that have no children."
5820   (interactive)
5821   (gnus-set-global-variables)
5822   (let ((data (gnus-data-list t))
5823         articles d children)
5824     ;; Find all articles that are either not dormant or have
5825     ;; children.
5826     (while (setq d (pop data))
5827       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
5828                 (and (setq children 
5829                            (gnus-article-children (gnus-data-number d)))
5830                      (let (found)
5831                        (while children
5832                          (when (memq (car children) articles)
5833                            (setq children nil
5834                                  found t))
5835                          (pop children))
5836                        found)))
5837         (push (gnus-data-number d) articles)))
5838     ;; Do the limiting.
5839     (prog1
5840         (gnus-summary-limit articles)
5841       (gnus-summary-position-point))))
5842
5843 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
5844   "Mark all unread excluded articles as read.
5845 If ALL, mark even excluded ticked and dormants as read."
5846   (interactive "P")
5847   (let ((articles (gnus-sorted-complement
5848                    (sort
5849                     (mapcar (lambda (h) (mail-header-number h))
5850                             gnus-newsgroup-headers)
5851                     '<)
5852                    (sort gnus-newsgroup-limit '<)))
5853         article)
5854     (setq gnus-newsgroup-unreads nil)
5855     (if all
5856         (setq gnus-newsgroup-dormant nil
5857               gnus-newsgroup-marked nil
5858               gnus-newsgroup-reads
5859               (nconc
5860                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
5861                gnus-newsgroup-reads))
5862       (while (setq article (pop articles))
5863         (unless (or (memq article gnus-newsgroup-dormant)
5864                     (memq article gnus-newsgroup-marked))
5865           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
5866
5867 (defun gnus-summary-limit (articles &optional pop)
5868   (if pop
5869       ;; We pop the previous limit off the stack and use that.
5870       (setq articles (car gnus-newsgroup-limits)
5871             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
5872     ;; We use the new limit, so we push the old limit on the stack.
5873     (push gnus-newsgroup-limit gnus-newsgroup-limits))
5874   ;; Set the limit.
5875   (setq gnus-newsgroup-limit articles)
5876   (let ((total (length gnus-newsgroup-data))
5877         (data (gnus-data-find-list (gnus-summary-article-number)))
5878         (gnus-summary-mark-below nil)   ; Inhibit this.
5879         found)
5880     ;; This will do all the work of generating the new summary buffer
5881     ;; according to the new limit.
5882     (gnus-summary-prepare)
5883     ;; Hide any threads, possibly.
5884     (and gnus-show-threads
5885          gnus-thread-hide-subtree
5886          (gnus-summary-hide-all-threads))
5887     ;; Try to return to the article you were at, or one in the
5888     ;; neighborhood.
5889     (when data
5890       ;; We try to find some article after the current one.
5891       (while data
5892         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
5893           (setq data nil
5894                 found t))
5895         (setq data (cdr data))))
5896     (unless found
5897       ;; If there is no data, that means that we were after the last
5898       ;; article.  The same goes when we can't find any articles
5899       ;; after the current one.
5900       (goto-char (point-max))
5901       (gnus-summary-find-prev))
5902     ;; We return how many articles were removed from the summary
5903     ;; buffer as a result of the new limit.
5904     (- total (length gnus-newsgroup-data))))
5905
5906 (defsubst gnus-invisible-cut-children (threads)
5907   (let ((num 0))
5908     (while threads
5909       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
5910         (incf num))
5911       (pop threads))
5912     (< num 2)))
5913
5914 (defsubst gnus-cut-thread (thread)
5915   "Go forwards in the thread until we find an article that we want to display."
5916   (when (or (eq gnus-fetch-old-headers 'some)
5917             (eq gnus-build-sparse-threads 'some)
5918             (eq gnus-build-sparse-threads 'more))
5919     ;; Deal with old-fetched headers and sparse threads.
5920     (while (and
5921             thread
5922             (or
5923              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
5924              (gnus-summary-article-ancient-p
5925               (mail-header-number (car thread))))
5926             (progn
5927               (if (<= (length (cdr thread)) 1)
5928                   (setq thread (cadr thread))
5929                 (when (gnus-invisible-cut-children (cdr thread))
5930                   (let ((th (cdr thread)))
5931                     (while th
5932                       (if (memq (mail-header-number (caar th))
5933                                 gnus-newsgroup-limit)
5934                           (setq thread (car th)
5935                                 th nil)
5936                         (setq th (cdr th)))))))))
5937       ))
5938   thread)
5939
5940 (defun gnus-cut-threads (threads)
5941   "Cut off all uninteresting articles from the beginning of threads."
5942   (when (or (eq gnus-fetch-old-headers 'some)
5943             (eq gnus-build-sparse-threads 'some)
5944             (eq gnus-build-sparse-threads 'more))
5945     (let ((th threads))
5946       (while th
5947         (setcar th (gnus-cut-thread (car th)))
5948         (setq th (cdr th)))))
5949   ;; Remove nixed out threads.
5950   (delq nil threads))
5951
5952 (defun gnus-summary-initial-limit (&optional show-if-empty)
5953   "Figure out what the initial limit is supposed to be on group entry.
5954 This entails weeding out unwanted dormants, low-scored articles,
5955 fetch-old-headers verbiage, and so on."
5956   ;; Most groups have nothing to remove.
5957   (if (or gnus-inhibit-limiting
5958           (and (null gnus-newsgroup-dormant)
5959                (not (eq gnus-fetch-old-headers 'some))
5960                (null gnus-summary-expunge-below)
5961                (not (eq gnus-build-sparse-threads 'some))
5962                (not (eq gnus-build-sparse-threads 'more))
5963                (null gnus-thread-expunge-below)
5964                (not gnus-use-nocem)))
5965       ()                                ; Do nothing.
5966     (push gnus-newsgroup-limit gnus-newsgroup-limits)
5967     (setq gnus-newsgroup-limit nil)
5968     (mapatoms
5969      (lambda (node)
5970        (unless (car (symbol-value node))
5971          ;; These threads have no parents -- they are roots.
5972          (let ((nodes (cdr (symbol-value node)))
5973                thread)
5974            (while nodes
5975              (if (and gnus-thread-expunge-below
5976                       (< (gnus-thread-total-score (car nodes))
5977                          gnus-thread-expunge-below))
5978                  (gnus-expunge-thread (pop nodes))
5979                (setq thread (pop nodes))
5980                (gnus-summary-limit-children thread))))))
5981      gnus-newsgroup-dependencies)
5982     ;; If this limitation resulted in an empty group, we might
5983     ;; pop the previous limit and use it instead.
5984     (when (and (not gnus-newsgroup-limit)
5985                show-if-empty)
5986       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
5987     gnus-newsgroup-limit))
5988
5989 (defun gnus-summary-limit-children (thread)
5990   "Return 1 if this subthread is visible and 0 if it is not."
5991   ;; First we get the number of visible children to this thread.  This
5992   ;; is done by recursing down the thread using this function, so this
5993   ;; will really go down to a leaf article first, before slowly
5994   ;; working its way up towards the root.
5995   (when thread
5996     (let ((children
5997            (if (cdr thread)
5998                (apply '+ (mapcar 'gnus-summary-limit-children
5999                                  (cdr thread)))
6000              0))
6001           (number (mail-header-number (car thread)))
6002           score)
6003       (if (and
6004            (not (memq number gnus-newsgroup-marked))
6005            (or
6006             ;; If this article is dormant and has absolutely no visible
6007             ;; children, then this article isn't visible.
6008             (and (memq number gnus-newsgroup-dormant)
6009                  (zerop children))
6010             ;; If this is "fetch-old-headered" and there is no
6011             ;; visible children, then we don't want this article.
6012             (and (eq gnus-fetch-old-headers 'some)
6013                  (gnus-summary-article-ancient-p number)
6014                  (zerop children))
6015             ;; If this is a sparsely inserted article with no children,
6016             ;; we don't want it.
6017             (and (eq gnus-build-sparse-threads 'some)
6018                  (gnus-summary-article-sparse-p number)
6019                  (zerop children))
6020             ;; If we use expunging, and this article is really
6021             ;; low-scored, then we don't want this article.
6022             (when (and gnus-summary-expunge-below
6023                        (< (setq score
6024                                 (or (cdr (assq number gnus-newsgroup-scored))
6025                                     gnus-summary-default-score))
6026                           gnus-summary-expunge-below))
6027               ;; We increase the expunge-tally here, but that has
6028               ;; nothing to do with the limits, really.
6029               (incf gnus-newsgroup-expunged-tally)
6030               ;; We also mark as read here, if that's wanted.
6031               (when (and gnus-summary-mark-below
6032                          (< score gnus-summary-mark-below))
6033                 (setq gnus-newsgroup-unreads
6034                       (delq number gnus-newsgroup-unreads))
6035                 (if gnus-newsgroup-auto-expire
6036                     (push number gnus-newsgroup-expirable)
6037                   (push (cons number gnus-low-score-mark)
6038                         gnus-newsgroup-reads)))
6039               t)
6040             ;; Check NoCeM things.
6041             (if (and gnus-use-nocem
6042                      (gnus-nocem-unwanted-article-p
6043                       (mail-header-id (car thread))))
6044                 (progn
6045                   (setq gnus-newsgroup-reads 
6046                         (delq number gnus-newsgroup-unreads))
6047                   t))))
6048           ;; Nope, invisible article.
6049           0
6050         ;; Ok, this article is to be visible, so we add it to the limit
6051         ;; and return 1.
6052         (push number gnus-newsgroup-limit)
6053         1))))
6054
6055 (defun gnus-expunge-thread (thread)
6056   "Mark all articles in THREAD as read."
6057   (let* ((number (mail-header-number (car thread))))
6058     (incf gnus-newsgroup-expunged-tally)
6059     ;; We also mark as read here, if that's wanted.
6060     (setq gnus-newsgroup-unreads
6061           (delq number gnus-newsgroup-unreads))
6062     (if gnus-newsgroup-auto-expire
6063         (push number gnus-newsgroup-expirable)
6064       (push (cons number gnus-low-score-mark)
6065             gnus-newsgroup-reads)))
6066   ;; Go recursively through all subthreads.
6067   (mapcar 'gnus-expunge-thread (cdr thread)))
6068
6069 ;; Summary article oriented commands
6070
6071 (defun gnus-summary-refer-parent-article (n)
6072   "Refer parent article N times.
6073 If N is negative, go to ancestor -N instead.
6074 The difference between N and the number of articles fetched is returned."
6075   (interactive "p")
6076   (gnus-set-global-variables)
6077   (let ((skip 1)
6078         error header ref)
6079     (when (not (natnump n))
6080       (setq skip (abs n)
6081             n 1))
6082     (while (and (> n 0)
6083                 (not error))
6084       (setq header (gnus-summary-article-header))
6085       (if (and (eq (mail-header-number header)
6086                    (cdr gnus-article-current))
6087                (equal gnus-newsgroup-name
6088                       (car gnus-article-current)))
6089           ;; If we try to find the parent of the currently
6090           ;; displayed article, then we take a look at the actual
6091           ;; References header, since this is slightly more
6092           ;; reliable than the References field we got from the
6093           ;; server.
6094           (save-excursion
6095             (set-buffer gnus-original-article-buffer)
6096             (nnheader-narrow-to-headers)
6097             (unless (setq ref (message-fetch-field "references"))
6098               (setq ref (message-fetch-field "in-reply-to")))
6099             (widen))
6100         (setq ref
6101               ;; It's not the current article, so we take a bet on
6102               ;; the value we got from the server.
6103               (mail-header-references header)))
6104       (if (and ref
6105                (not (equal ref "")))
6106           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6107             (gnus-message 1 "Couldn't find parent"))
6108         (gnus-message 1 "No references in article %d"
6109                       (gnus-summary-article-number))
6110         (setq error t))
6111       (decf n))
6112     (gnus-summary-position-point)
6113     n))
6114
6115 (defun gnus-summary-refer-references ()
6116   "Fetch all articles mentioned in the References header.
6117 Return how many articles were fetched."
6118   (interactive)
6119   (gnus-set-global-variables)
6120   (let ((ref (mail-header-references (gnus-summary-article-header)))
6121         (current (gnus-summary-article-number))
6122         (n 0))
6123     (if (or (not ref)
6124             (equal ref ""))
6125         (error "No References in the current article")
6126       ;; For each Message-ID in the References header...
6127       (while (string-match "<[^>]*>" ref)
6128         (incf n)
6129         ;; ... fetch that article.
6130         (gnus-summary-refer-article
6131          (prog1 (match-string 0 ref)
6132            (setq ref (substring ref (match-end 0))))))
6133       (gnus-summary-goto-subject current)
6134       (gnus-summary-position-point)
6135       n)))
6136
6137 (defun gnus-summary-refer-article (message-id)
6138   "Fetch an article specified by MESSAGE-ID."
6139   (interactive "sMessage-ID: ")
6140   (when (and (stringp message-id)
6141              (not (zerop (length message-id))))
6142     ;; Construct the correct Message-ID if necessary.
6143     ;; Suggested by tale@pawl.rpi.edu.
6144     (unless (string-match "^<" message-id)
6145       (setq message-id (concat "<" message-id)))
6146     (unless (string-match ">$" message-id)
6147       (setq message-id (concat message-id ">")))
6148     (let* ((header (gnus-id-to-header message-id))
6149            (sparse (and header
6150                         (gnus-summary-article-sparse-p 
6151                          (mail-header-number header)))))
6152       (if header
6153           (prog1
6154               ;; The article is present in the buffer, to we just go to it.
6155               (gnus-summary-goto-article 
6156                (mail-header-number header) nil header)
6157             (when sparse
6158               (gnus-summary-update-article (mail-header-number header))))
6159         ;; We fetch the article
6160         (let ((gnus-override-method 
6161                (and (gnus-news-group-p gnus-newsgroup-name)
6162                     gnus-refer-article-method))
6163               number)
6164           ;; Start the special refer-article method, if necessary.
6165           (when (and gnus-refer-article-method
6166                      (gnus-news-group-p gnus-newsgroup-name))
6167             (gnus-check-server gnus-refer-article-method))
6168           ;; Fetch the header, and display the article.
6169           (if (setq number (gnus-summary-insert-subject message-id))
6170               (gnus-summary-select-article nil nil nil number)
6171             (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
6172
6173 (defun gnus-summary-enter-digest-group (&optional force)
6174   "Enter an nndoc group based on the current article.
6175 If FORCE, force a digest interpretation.  If not, try
6176 to guess what the document format is."
6177   (interactive "P")
6178   (gnus-set-global-variables)
6179   (let ((conf gnus-current-window-configuration))
6180     (save-excursion
6181       (gnus-summary-select-article))
6182     (setq gnus-current-window-configuration conf)
6183     (let* ((name (format "%s-%d"
6184                          (gnus-group-prefixed-name
6185                           gnus-newsgroup-name (list 'nndoc ""))
6186                          (save-excursion
6187                            (set-buffer gnus-summary-buffer)
6188                            gnus-current-article)))
6189            (ogroup gnus-newsgroup-name)
6190            (params (append (gnus-info-params (gnus-get-info ogroup))
6191                            (list (cons 'to-group ogroup))))
6192            (case-fold-search t)
6193            (buf (current-buffer))
6194            dig)
6195       (save-excursion
6196         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6197         (insert-buffer-substring gnus-original-article-buffer)
6198         ;; Remove lines that may lead nndoc to misinterpret the
6199         ;; document type.
6200         (narrow-to-region
6201          (goto-char (point-min))
6202          (or (search-forward "\n\n" nil t) (point)))
6203         (goto-char (point-min))
6204         (delete-matching-lines "^\\(Path\\):\\|^From ")
6205         (widen))
6206       (unwind-protect
6207           (if (gnus-group-read-ephemeral-group
6208                name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6209                             (nndoc-article-type 
6210                              ,(if force 'digest 'guess))) t)
6211               ;; Make all postings to this group go to the parent group.
6212               (nconc (gnus-info-params (gnus-get-info name))
6213                      params)
6214             ;; Couldn't select this doc group.
6215             (switch-to-buffer buf)
6216             (gnus-set-global-variables)
6217             (gnus-configure-windows 'summary)
6218             (gnus-message 3 "Article couldn't be entered?"))
6219         (kill-buffer dig)))))
6220
6221 (defun gnus-summary-read-document (n)
6222   "Open a new group based on the current article(s).
6223 This will allow you to read digests and other similar
6224 documents as newsgroups.
6225 Obeys the standard process/prefix convention."
6226   (interactive "P")
6227   (let* ((articles (gnus-summary-work-articles n))
6228          (ogroup gnus-newsgroup-name)
6229          (params (append (gnus-info-params (gnus-get-info ogroup))
6230                          (list (cons 'to-group ogroup))))
6231          article group egroup groups vgroup)
6232     (while (setq article (pop articles))
6233       (setq group (format "%s-%d" gnus-newsgroup-name article))
6234       (gnus-summary-remove-process-mark article)
6235       (when (gnus-summary-display-article article)
6236         (save-excursion
6237           (nnheader-temp-write nil
6238             (insert-buffer-substring gnus-original-article-buffer)
6239             ;; Remove some headers that may lead nndoc to make
6240             ;; the wrong guess.
6241             (message-narrow-to-head)
6242             (goto-char (point-min))
6243             (delete-matching-lines "^\\(Path\\):\\|^From ")
6244             (widen)
6245             (if (setq egroup
6246                       (gnus-group-read-ephemeral-group
6247                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6248                                      (nndoc-article-type guess))
6249                        t nil t))
6250                 (progn
6251                   ;; Make all postings to this group go to the parent group.
6252                   (nconc (gnus-info-params (gnus-get-info egroup))
6253                          params)
6254                   (push egroup groups))
6255               ;; Couldn't select this doc group.
6256               (gnus-error 3 "Article couldn't be entered"))))))
6257     ;; Now we have selected all the documents.
6258     (cond
6259      ((not groups)
6260       (error "None of the articles could be interpreted as documents"))
6261      ((gnus-group-read-ephemeral-group
6262        (setq vgroup (format
6263                      "nnvirtual:%s-%s" gnus-newsgroup-name
6264                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6265        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6266        t
6267        (cons (current-buffer) 'summary)))
6268      (t
6269       (error "Couldn't select virtual nndoc group")))))
6270       
6271 (defun gnus-summary-isearch-article (&optional regexp-p)
6272   "Do incremental search forward on the current article.
6273 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6274   (interactive "P")
6275   (gnus-set-global-variables)
6276   (gnus-summary-select-article)
6277   (gnus-configure-windows 'article)
6278   (gnus-eval-in-buffer-window gnus-article-buffer
6279     ;;(goto-char (point-min))
6280     (isearch-forward regexp-p)))
6281
6282 (defun gnus-summary-search-article-forward (regexp &optional backward)
6283   "Search for an article containing REGEXP forward.
6284 If BACKWARD, search backward instead."
6285   (interactive
6286    (list (read-string
6287           (format "Search article %s (regexp%s): "
6288                   (if current-prefix-arg "backward" "forward")
6289                   (if gnus-last-search-regexp
6290                       (concat ", default " gnus-last-search-regexp)
6291                     "")))
6292          current-prefix-arg))
6293   (gnus-set-global-variables)
6294   (if (string-equal regexp "")
6295       (setq regexp (or gnus-last-search-regexp ""))
6296     (setq gnus-last-search-regexp regexp))
6297   (if (gnus-summary-search-article regexp backward)
6298       (gnus-summary-show-thread)
6299     (error "Search failed: \"%s\"" regexp)))
6300
6301 (defun gnus-summary-search-article-backward (regexp)
6302   "Search for an article containing REGEXP backward."
6303   (interactive
6304    (list (read-string
6305           (format "Search article backward (regexp%s): "
6306                   (if gnus-last-search-regexp
6307                       (concat ", default " gnus-last-search-regexp)
6308                     "")))))
6309   (gnus-summary-search-article-forward regexp 'backward))
6310
6311 (defun gnus-summary-search-article (regexp &optional backward)
6312   "Search for an article containing REGEXP.
6313 Optional argument BACKWARD means do search for backward.
6314 `gnus-select-article-hook' is not called during the search."
6315   (let ((gnus-select-article-hook nil)  ;Disable hook.
6316         (gnus-article-display-hook nil)
6317         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
6318         (gnus-use-article-prefetch nil)
6319         (sum (current-buffer))
6320         (found nil)
6321         point)
6322     (gnus-save-hidden-threads
6323       (gnus-summary-select-article)
6324       (set-buffer gnus-article-buffer)
6325       (when backward
6326         (forward-line -1))
6327       (while (not found)
6328         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
6329         (if (if backward
6330                 (re-search-backward regexp nil t)
6331               (re-search-forward regexp nil t))
6332             ;; We found the regexp.
6333             (progn
6334               (setq found 'found)
6335               (beginning-of-line)
6336               (set-window-start
6337                (get-buffer-window (current-buffer))
6338                (point))
6339               (forward-line 1)
6340               (set-buffer sum)
6341               (setq point (point)))
6342           ;; We didn't find it, so we go to the next article.
6343           (set-buffer sum)
6344           (setq found 'not)
6345           (while (eq found 'not)
6346             (if (not (if backward (gnus-summary-find-prev)
6347                        (gnus-summary-find-next)))
6348                 ;; No more articles.
6349                 (setq found t)
6350               ;; Select the next article and adjust point.
6351               (unless (gnus-summary-article-sparse-p
6352                        (gnus-summary-article-number))
6353                 (setq found nil)
6354                 (gnus-summary-select-article)
6355                 (set-buffer gnus-article-buffer)
6356                 (widen)
6357                 (goto-char (if backward (point-max) (point-min))))))))
6358       (gnus-message 7 ""))
6359     ;; Return whether we found the regexp.
6360     (when (eq found 'found)
6361       (goto-char point)
6362       (gnus-summary-show-thread)
6363       (gnus-summary-goto-subject gnus-current-article)
6364       (gnus-summary-position-point)
6365       t)))
6366
6367 (defun gnus-summary-find-matching (header regexp &optional backward unread
6368                                           not-case-fold)
6369   "Return a list of all articles that match REGEXP on HEADER.
6370 The search stars on the current article and goes forwards unless
6371 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
6372 If UNREAD is non-nil, only unread articles will
6373 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
6374 in the comparisons."
6375   (let ((data (if (eq backward 'all) gnus-newsgroup-data
6376                 (gnus-data-find-list
6377                  (gnus-summary-article-number) (gnus-data-list backward))))
6378         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
6379         (case-fold-search (not not-case-fold))
6380         articles d)
6381     (unless (fboundp (intern (concat "mail-header-" header)))
6382       (error "%s is not a valid header" header))
6383     (while data
6384       (setq d (car data))
6385       (and (or (not unread)             ; We want all articles...
6386                (gnus-data-unread-p d))  ; Or just unreads.
6387            (vectorp (gnus-data-header d)) ; It's not a pseudo.
6388            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
6389            (push (gnus-data-number d) articles)) ; Success!
6390       (setq data (cdr data)))
6391     (nreverse articles)))
6392
6393 (defun gnus-summary-execute-command (header regexp command &optional backward)
6394   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
6395 If HEADER is an empty string (or nil), the match is done on the entire
6396 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
6397   (interactive
6398    (list (let ((completion-ignore-case t))
6399            (completing-read
6400             "Header name: "
6401             (mapcar (lambda (string) (list string))
6402                     '("Number" "Subject" "From" "Lines" "Date"
6403                       "Message-ID" "Xref" "References" "Body"))
6404             nil 'require-match))
6405          (read-string "Regexp: ")
6406          (read-key-sequence "Command: ")
6407          current-prefix-arg))
6408   (when (equal header "Body")
6409     (setq header ""))
6410   (gnus-set-global-variables)
6411   ;; Hidden thread subtrees must be searched as well.
6412   (gnus-summary-show-all-threads)
6413   ;; We don't want to change current point nor window configuration.
6414   (save-excursion
6415     (save-window-excursion
6416       (gnus-message 6 "Executing %s..." (key-description command))
6417       ;; We'd like to execute COMMAND interactively so as to give arguments.
6418       (gnus-execute header regexp
6419                     `(call-interactively ',(key-binding command))
6420                     backward)
6421       (gnus-message 6 "Executing %s...done" (key-description command)))))
6422
6423 (defun gnus-summary-beginning-of-article ()
6424   "Scroll the article back to the beginning."
6425   (interactive)
6426   (gnus-set-global-variables)
6427   (gnus-summary-select-article)
6428   (gnus-configure-windows 'article)
6429   (gnus-eval-in-buffer-window gnus-article-buffer
6430     (widen)
6431     (goto-char (point-min))
6432     (when gnus-break-pages
6433       (gnus-narrow-to-page))))
6434
6435 (defun gnus-summary-end-of-article ()
6436   "Scroll to the end of the article."
6437   (interactive)
6438   (gnus-set-global-variables)
6439   (gnus-summary-select-article)
6440   (gnus-configure-windows 'article)
6441   (gnus-eval-in-buffer-window gnus-article-buffer
6442     (widen)
6443     (goto-char (point-max))
6444     (recenter -3)
6445     (when gnus-break-pages
6446       (gnus-narrow-to-page))))
6447
6448 (defun gnus-summary-print-article (&optional filename)
6449   "Generate and print a PostScript image of the article buffer.
6450
6451 If the optional argument FILENAME is nil, send the image to the printer.
6452 If FILENAME is a string, save the PostScript image in a file with that
6453 name.  If FILENAME is a number, prompt the user for the name of the file
6454 to save in."
6455   (interactive (list (ps-print-preprint current-prefix-arg)))
6456   (gnus-summary-select-article)
6457   (gnus-eval-in-buffer-window gnus-article-buffer
6458     (let ((buffer (generate-new-buffer " *print*")))
6459       (unwind-protect
6460           (progn
6461             (copy-to-buffer buffer (point-min) (point-max))
6462             (set-buffer buffer)
6463             (gnus-article-delete-invisible-text)
6464             (ps-print-buffer-with-faces filename))
6465         (kill-buffer buffer)))))
6466
6467 (defun gnus-summary-show-article (&optional arg)
6468   "Force re-fetching of the current article.
6469 If ARG (the prefix) is non-nil, show the raw article without any
6470 article massaging functions being run."
6471   (interactive "P")
6472   (gnus-set-global-variables)
6473   (if (not arg)
6474       ;; Select the article the normal way.
6475       (gnus-summary-select-article nil 'force)
6476     ;; Bind the article treatment functions to nil.
6477     (let ((gnus-have-all-headers t)
6478           gnus-article-display-hook
6479           gnus-article-prepare-hook
6480           gnus-break-pages
6481           gnus-visual)
6482       (gnus-summary-select-article nil 'force)))
6483   (gnus-summary-goto-subject gnus-current-article)
6484                                         ;  (gnus-configure-windows 'article)
6485   (gnus-summary-position-point))
6486
6487 (defun gnus-summary-verbose-headers (&optional arg)
6488   "Toggle permanent full header display.
6489 If ARG is a positive number, turn header display on.
6490 If ARG is a negative number, turn header display off."
6491   (interactive "P")
6492   (gnus-set-global-variables)
6493   (setq gnus-show-all-headers
6494         (cond ((or (not (numberp arg))
6495                    (zerop arg))
6496                (not gnus-show-all-headers))
6497               ((natnump arg)
6498                t)))
6499   (gnus-summary-show-article))
6500
6501 (defun gnus-summary-toggle-header (&optional arg)
6502   "Show the headers if they are hidden, or hide them if they are shown.
6503 If ARG is a positive number, show the entire header.
6504 If ARG is a negative number, hide the unwanted header lines."
6505   (interactive "P")
6506   (gnus-set-global-variables)
6507   (save-excursion
6508     (set-buffer gnus-article-buffer)
6509     (let* ((buffer-read-only nil)
6510            (inhibit-point-motion-hooks t)
6511            (hidden (text-property-any
6512                     (goto-char (point-min)) (search-forward "\n\n")
6513                     'invisible t))
6514            e)
6515       (goto-char (point-min))
6516       (when (search-forward "\n\n" nil t)
6517         (delete-region (point-min) (1- (point))))
6518       (goto-char (point-min))
6519       (save-excursion
6520         (set-buffer gnus-original-article-buffer)
6521         (goto-char (point-min))
6522         (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
6523       (insert-buffer-substring gnus-original-article-buffer 1 e)
6524       (let ((article-inhibit-hiding t))
6525         (run-hooks 'gnus-article-display-hook))
6526       (when (or (not hidden) (and (numberp arg) (< arg 0)))
6527         (gnus-article-hide-headers)))))
6528
6529 (defun gnus-summary-show-all-headers ()
6530   "Make all header lines visible."
6531   (interactive)
6532   (gnus-set-global-variables)
6533   (gnus-article-show-all-headers))
6534
6535 (defun gnus-summary-toggle-mime (&optional arg)
6536   "Toggle MIME processing.
6537 If ARG is a positive number, turn MIME processing on."
6538   (interactive "P")
6539   (gnus-set-global-variables)
6540   (setq gnus-show-mime
6541         (if (null arg) (not gnus-show-mime)
6542           (> (prefix-numeric-value arg) 0)))
6543   (gnus-summary-select-article t 'force))
6544
6545 (defun gnus-summary-caesar-message (&optional arg)
6546   "Caesar rotate the current article by 13.
6547 The numerical prefix specifies how many places to rotate each letter
6548 forward."
6549   (interactive "P")
6550   (gnus-set-global-variables)
6551   (gnus-summary-select-article)
6552   (let ((mail-header-separator ""))
6553     (gnus-eval-in-buffer-window gnus-article-buffer
6554       (save-restriction
6555         (widen)
6556         (let ((start (window-start))
6557               buffer-read-only)
6558           (message-caesar-buffer-body arg)
6559           (set-window-start (get-buffer-window (current-buffer)) start))))))
6560
6561 (defun gnus-summary-stop-page-breaking ()
6562   "Stop page breaking in the current article."
6563   (interactive)
6564   (gnus-set-global-variables)
6565   (gnus-summary-select-article)
6566   (gnus-eval-in-buffer-window gnus-article-buffer
6567     (widen)
6568     (when (gnus-visual-p 'page-marker)
6569       (let ((buffer-read-only nil))
6570         (gnus-remove-text-with-property 'gnus-prev)
6571         (gnus-remove-text-with-property 'gnus-next)))))
6572
6573 (defun gnus-summary-move-article (&optional n to-newsgroup 
6574                                             select-method action)
6575   "Move the current article to a different newsgroup.
6576 If N is a positive number, move the N next articles.
6577 If N is a negative number, move the N previous articles.
6578 If N is nil and any articles have been marked with the process mark,
6579 move those articles instead.
6580 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
6581 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
6582 re-spool using this method.
6583
6584 For this function to work, both the current newsgroup and the
6585 newsgroup that you want to move to have to support the `request-move'
6586 and `request-accept' functions."
6587   (interactive "P")
6588   (unless action
6589     (setq action 'move))
6590   (gnus-set-global-variables)
6591   ;; Disable marking as read.
6592   (let (gnus-mark-article-hook)
6593     (save-window-excursion
6594       (gnus-summary-select-article)))
6595   ;; Check whether the source group supports the required functions.
6596   (cond ((and (eq action 'move)
6597               (not (gnus-check-backend-function
6598                     'request-move-article gnus-newsgroup-name)))
6599          (error "The current group does not support article moving"))
6600         ((and (eq action 'crosspost)
6601               (not (gnus-check-backend-function
6602                     'request-replace-article gnus-newsgroup-name)))
6603          (error "The current group does not support article editing")))
6604   (let ((articles (gnus-summary-work-articles n))
6605         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
6606         (names '((move "Move" "Moving")
6607                  (copy "Copy" "Copying")
6608                  (crosspost "Crosspost" "Crossposting")))
6609         (copy-buf (save-excursion
6610                     (nnheader-set-temp-buffer " *copy article*")))
6611         art-group to-method new-xref article to-groups)
6612     (unless (assq action names)
6613       (error "Unknown action %s" action))
6614     ;; Read the newsgroup name.
6615     (when (and (not to-newsgroup)
6616                (not select-method))
6617       (setq to-newsgroup
6618             (gnus-read-move-group-name
6619              (cadr (assq action names))
6620              (symbol-value (intern (format "gnus-current-%s-group" action)))
6621              articles prefix))
6622       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
6623     (setq to-method (or select-method 
6624                         (gnus-group-name-to-method to-newsgroup)))
6625     ;; Check the method we are to move this article to...
6626     (unless (gnus-check-backend-function 
6627              'request-accept-article (car to-method))
6628       (error "%s does not support article copying" (car to-method)))
6629     (unless (gnus-check-server to-method)
6630       (error "Can't open server %s" (car to-method)))
6631     (gnus-message 6 "%s to %s: %s..."
6632                   (caddr (assq action names))
6633                   (or (car select-method) to-newsgroup) articles)
6634     (while articles
6635       (setq article (pop articles))
6636       (setq
6637        art-group
6638        (cond
6639         ;; Move the article.
6640         ((eq action 'move)
6641          (gnus-request-move-article
6642           article                       ; Article to move
6643           gnus-newsgroup-name           ; From newsgroup
6644           (nth 1 (gnus-find-method-for-group
6645                   gnus-newsgroup-name)) ; Server
6646           (list 'gnus-request-accept-article
6647                 to-newsgroup (list 'quote select-method)
6648                 (not articles))         ; Accept form
6649           (not articles)))              ; Only save nov last time
6650         ;; Copy the article.
6651         ((eq action 'copy)
6652          (save-excursion
6653            (set-buffer copy-buf)
6654            (gnus-request-article-this-buffer article gnus-newsgroup-name)
6655            (gnus-request-accept-article
6656             to-newsgroup select-method (not articles))))
6657         ;; Crosspost the article.
6658         ((eq action 'crosspost)
6659          (let ((xref (message-tokenize-header
6660                       (mail-header-xref (gnus-summary-article-header article))
6661                       " ")))
6662            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
6663                                   ":" article))
6664            (unless xref 
6665              (setq xref (list (system-name))))
6666            (setq new-xref
6667                  (concat
6668                   (mapconcat 'identity 
6669                              (delete "Xref:" (delete new-xref xref))
6670                              " ")
6671                   new-xref))
6672            (save-excursion
6673              (set-buffer copy-buf)
6674              (gnus-request-article-this-buffer article gnus-newsgroup-name)
6675              (nnheader-replace-header "xref" new-xref)
6676              (gnus-request-accept-article
6677               to-newsgroup select-method (not articles)))))))
6678       (if (not art-group)
6679           (gnus-message 1 "Couldn't %s article %s"
6680                         (cadr (assq action names)) article)
6681         (let* ((entry
6682                 (or
6683                  (gnus-gethash (car art-group) gnus-newsrc-hashtb)
6684                  (gnus-gethash
6685                   (gnus-group-prefixed-name
6686                    (car art-group)
6687                    (or select-method 
6688                        (gnus-find-method-for-group to-newsgroup)))
6689                   gnus-newsrc-hashtb)))
6690                (info (nth 2 entry))
6691                (to-group (gnus-info-group info)))
6692           ;; Update the group that has been moved to.
6693           (when (and info
6694                      (memq action '(move copy)))
6695             (unless (member to-group to-groups)
6696               (push to-group to-groups))
6697
6698             (unless (memq article gnus-newsgroup-unreads)
6699               (gnus-info-set-read
6700                info (gnus-add-to-range (gnus-info-read info)
6701                                        (list (cdr art-group)))))
6702
6703             ;; Copy any marks over to the new group.
6704             (let ((marks gnus-article-mark-lists)
6705                   (to-article (cdr art-group)))
6706
6707               ;; See whether the article is to be put in the cache.
6708               (when gnus-use-cache
6709                 (gnus-cache-possibly-enter-article
6710                  to-group to-article
6711                  (let ((header (copy-sequence
6712                                 (gnus-summary-article-header article))))
6713                    (mail-header-set-number header to-article)
6714                    header)
6715                  (memq article gnus-newsgroup-marked)
6716                  (memq article gnus-newsgroup-dormant)
6717                  (memq article gnus-newsgroup-unreads)))
6718
6719               (while marks
6720                 (when (memq article (symbol-value
6721                                      (intern (format "gnus-newsgroup-%s"
6722                                                      (caar marks)))))
6723                   ;; If the other group is the same as this group,
6724                   ;; then we have to add the mark to the list.
6725                   (when (equal to-group gnus-newsgroup-name)
6726                     (set (intern (format "gnus-newsgroup-%s" (caar marks)))
6727                          (cons to-article
6728                                (symbol-value
6729                                 (intern (format "gnus-newsgroup-%s"
6730                                                 (caar marks)))))))
6731                   ;; Copy mark to other group.
6732                   (gnus-add-marked-articles
6733                    to-group (cdar marks) (list to-article) info))
6734                 (setq marks (cdr marks)))))
6735
6736           ;; Update the Xref header in this article to point to
6737           ;; the new crossposted article we have just created.
6738           (when (eq action 'crosspost)
6739             (save-excursion
6740               (set-buffer copy-buf)
6741               (gnus-request-article-this-buffer article gnus-newsgroup-name)
6742               (nnheader-replace-header
6743                "xref" (concat new-xref " " (car art-group)
6744                               ":" (cdr art-group)))
6745               (gnus-request-replace-article
6746                article gnus-newsgroup-name (current-buffer)))))
6747
6748         (gnus-summary-goto-subject article)
6749         (when (eq action 'move)
6750           (gnus-summary-mark-article article gnus-canceled-mark)))
6751       (gnus-summary-remove-process-mark article))
6752     ;; Re-activate all groups that have been moved to.
6753     (while to-groups
6754       (gnus-activate-group (pop to-groups)))
6755     
6756     (gnus-kill-buffer copy-buf)
6757     (gnus-summary-position-point)
6758     (gnus-set-mode-line 'summary)))
6759
6760 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
6761   "Move the current article to a different newsgroup.
6762 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
6763 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
6764 re-spool using this method."
6765   (interactive "P")
6766   (gnus-summary-move-article n nil select-method 'copy))
6767
6768 (defun gnus-summary-crosspost-article (&optional n)
6769   "Crosspost the current article to some other group."
6770   (interactive "P")
6771   (gnus-summary-move-article n nil nil 'crosspost))
6772
6773 (defcustom gnus-summary-respool-default-method nil
6774   "Default method for respooling an article.  
6775 If nil, use to the current newsgroup method."
6776   :type 'gnus-select-method-name
6777   :group 'gnus-summary-mail)
6778
6779 (defun gnus-summary-respool-article (&optional n method)
6780   "Respool the current article.
6781 The article will be squeezed through the mail spooling process again,
6782 which means that it will be put in some mail newsgroup or other
6783 depending on `nnmail-split-methods'.
6784 If N is a positive number, respool the N next articles.
6785 If N is a negative number, respool the N previous articles.
6786 If N is nil and any articles have been marked with the process mark,
6787 respool those articles instead.
6788
6789 Respooling can be done both from mail groups and \"real\" newsgroups.
6790 In the former case, the articles in question will be moved from the
6791 current group into whatever groups they are destined to.  In the
6792 latter case, they will be copied into the relevant groups."
6793   (interactive 
6794    (list current-prefix-arg
6795          (let* ((methods (gnus-methods-using 'respool))
6796                 (methname
6797                  (symbol-name (or gnus-summary-respool-default-method
6798                                   (car (gnus-find-method-for-group
6799                                         gnus-newsgroup-name)))))
6800                 (method
6801                  (gnus-completing-read 
6802                   methname "What backend do you want to use when respooling?"
6803                   methods nil t nil 'gnus-mail-method-history))
6804                 ms)
6805            (cond
6806             ((zerop (length (setq ms (gnus-servers-using-backend 
6807                                       (intern method)))))
6808              (list (intern method) ""))
6809             ((= 1 (length ms))
6810              (car ms))
6811             (t
6812              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
6813                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
6814                            ms-alist))))))))
6815   (gnus-set-global-variables)
6816   (unless method
6817     (error "No method given for respooling"))
6818   (if (assoc (symbol-name
6819               (car (gnus-find-method-for-group gnus-newsgroup-name)))
6820              (gnus-methods-using 'respool))
6821       (gnus-summary-move-article n nil method)
6822     (gnus-summary-copy-article n nil method)))
6823
6824 (defun gnus-summary-import-article (file)
6825   "Import a random file into a mail newsgroup."
6826   (interactive "fImport file: ")
6827   (gnus-set-global-variables)
6828   (let ((group gnus-newsgroup-name)
6829         (now (current-time))
6830         atts lines)
6831     (unless (gnus-check-backend-function 'request-accept-article group)
6832       (error "%s does not support article importing" group))
6833     (or (file-readable-p file)
6834         (not (file-regular-p file))
6835         (error "Can't read %s" file))
6836     (save-excursion
6837       (set-buffer (get-buffer-create " *import file*"))
6838       (buffer-disable-undo (current-buffer))
6839       (erase-buffer)
6840       (insert-file-contents file)
6841       (goto-char (point-min))
6842       (unless (nnheader-article-p)
6843         ;; This doesn't look like an article, so we fudge some headers.
6844         (setq atts (file-attributes file)
6845               lines (count-lines (point-min) (point-max)))
6846         (insert "From: " (read-string "From: ") "\n"
6847                 "Subject: " (read-string "Subject: ") "\n"
6848                 "Date: " (timezone-make-date-arpa-standard
6849                           (current-time-string (nth 5 atts))
6850                           (current-time-zone now)
6851                           (current-time-zone now))
6852                 "\n"
6853                 "Message-ID: " (message-make-message-id) "\n"
6854                 "Lines: " (int-to-string lines) "\n"
6855                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
6856       (gnus-request-accept-article group nil t)
6857       (kill-buffer (current-buffer)))))
6858
6859 (defun gnus-summary-article-posted-p ()
6860   "Say whether the current (mail) article is available from `gnus-select-method' as well.
6861 This will be the case if the article has both been mailed and posted."
6862   (interactive)
6863   (let ((id (mail-header-references (gnus-summary-article-header)))
6864         (gnus-override-method
6865          (or gnus-refer-article-method gnus-select-method)))
6866     (if (gnus-request-head id "")
6867         (gnus-message 2 "The current message was found on %s"
6868                       gnus-override-method)
6869       (gnus-message 2 "The current message couldn't be found on %s"
6870                     gnus-override-method)
6871       nil)))
6872
6873 (defun gnus-summary-expire-articles (&optional now)
6874   "Expire all articles that are marked as expirable in the current group."
6875   (interactive)
6876   (gnus-set-global-variables)
6877   (when (gnus-check-backend-function
6878          'request-expire-articles gnus-newsgroup-name)
6879     ;; This backend supports expiry.
6880     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
6881            (expirable (if total
6882                           (progn
6883                             ;; We need to update the info for
6884                             ;; this group for `gnus-list-of-read-articles'
6885                             ;; to give us the right answer.
6886                             (run-hooks 'gnus-exit-group-hook)
6887                             (gnus-summary-update-info)
6888                             (gnus-list-of-read-articles gnus-newsgroup-name))
6889                         (setq gnus-newsgroup-expirable
6890                               (sort gnus-newsgroup-expirable '<))))
6891            (expiry-wait (if now 'immediate
6892                           (gnus-group-find-parameter
6893                            gnus-newsgroup-name 'expiry-wait)))
6894            es)
6895       (when expirable
6896         ;; There are expirable articles in this group, so we run them
6897         ;; through the expiry process.
6898         (gnus-message 6 "Expiring articles...")
6899         ;; The list of articles that weren't expired is returned.
6900         (if expiry-wait
6901             (let ((nnmail-expiry-wait-function nil)
6902                   (nnmail-expiry-wait expiry-wait))
6903               (setq es (gnus-request-expire-articles
6904                         expirable gnus-newsgroup-name)))
6905           (setq es (gnus-request-expire-articles
6906                     expirable gnus-newsgroup-name)))
6907         (unless total
6908           (setq gnus-newsgroup-expirable es))
6909         ;; We go through the old list of expirable, and mark all
6910         ;; really expired articles as nonexistent.
6911         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
6912           (let ((gnus-use-cache nil))
6913             (while expirable
6914               (unless (memq (car expirable) es)
6915                 (when (gnus-data-find (car expirable))
6916                   (gnus-summary-mark-article
6917                    (car expirable) gnus-canceled-mark)))
6918               (setq expirable (cdr expirable)))))
6919         (gnus-message 6 "Expiring articles...done")))))
6920
6921 (defun gnus-summary-expire-articles-now ()
6922   "Expunge all expirable articles in the current group.
6923 This means that *all* articles that are marked as expirable will be
6924 deleted forever, right now."
6925   (interactive)
6926   (gnus-set-global-variables)
6927   (or gnus-expert-user
6928       (gnus-yes-or-no-p
6929        "Are you really, really, really sure you want to delete all these messages? ")
6930       (error "Phew!"))
6931   (gnus-summary-expire-articles t))
6932
6933 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
6934 (defun gnus-summary-delete-article (&optional n)
6935   "Delete the N next (mail) articles.
6936 This command actually deletes articles.  This is not a marking
6937 command.  The article will disappear forever from your life, never to
6938 return.
6939 If N is negative, delete backwards.
6940 If N is nil and articles have been marked with the process mark,
6941 delete these instead."
6942   (interactive "P")
6943   (gnus-set-global-variables)
6944   (unless (gnus-check-backend-function 'request-expire-articles
6945                                        gnus-newsgroup-name)
6946     (error "The current newsgroup does not support article deletion."))
6947   ;; Compute the list of articles to delete.
6948   (let ((articles (gnus-summary-work-articles n))
6949         not-deleted)
6950     (if (and gnus-novice-user
6951              (not (gnus-yes-or-no-p
6952                    (format "Do you really want to delete %s forever? "
6953                            (if (> (length articles) 1)
6954                                (format "these %s articles" (length articles))
6955                              "this article")))))
6956         ()
6957       ;; Delete the articles.
6958       (setq not-deleted (gnus-request-expire-articles
6959                          articles gnus-newsgroup-name 'force))
6960       (while articles
6961         (gnus-summary-remove-process-mark (car articles))
6962         ;; The backend might not have been able to delete the article
6963         ;; after all.
6964         (unless (memq (car articles) not-deleted)
6965           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
6966         (setq articles (cdr articles))))
6967     (gnus-summary-position-point)
6968     (gnus-set-mode-line 'summary)
6969     not-deleted))
6970
6971 (defun gnus-summary-edit-article (&optional force)
6972   "Edit the current article.
6973 This will have permanent effect only in mail groups.
6974 If FORCE is non-nil, allow editing of articles even in read-only
6975 groups." 
6976   (interactive "P")
6977   (save-excursion
6978     (set-buffer gnus-summary-buffer)
6979     (gnus-set-global-variables)
6980     (when (and (not force)
6981                (gnus-group-read-only-p))
6982       (error "The current newsgroup does not support article editing."))
6983     ;; Select article if needed.
6984     (unless (eq (gnus-summary-article-number)
6985                 gnus-current-article)
6986       (gnus-summary-select-article t))
6987     (gnus-article-edit-article
6988      `(lambda ()
6989         (gnus-summary-edit-article-done
6990          ,(or (mail-header-references gnus-current-headers) "")
6991          ,(gnus-group-read-only-p) ,gnus-summary-buffer)))))
6992
6993 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
6994
6995 (defun gnus-summary-edit-article-done (&optional references read-only buffer)
6996   "Make edits to the current article permanent."
6997   (interactive)
6998   ;; Replace the article.
6999   (if (and (not read-only)
7000            (not (gnus-request-replace-article
7001                  (cdr gnus-article-current) (car gnus-article-current)
7002                  (current-buffer))))
7003       (error "Couldn't replace article.")
7004     ;; Update the summary buffer.
7005     (if (and references
7006              (equal (message-tokenize-header references " ")
7007                     (message-tokenize-header
7008                      (or (message-fetch-field "references") "") " ")))
7009         ;; We only have to update this line.
7010         (save-excursion
7011           (save-restriction
7012             (message-narrow-to-head)
7013             (let ((header (nnheader-parse-head t)))
7014               (set-buffer buffer)
7015               (mail-header-set-number header (cdr gnus-article-current))
7016               (gnus-summary-update-article-line
7017                (cdr gnus-article-current) header))))
7018       ;; Update threads.
7019       (set-buffer (or buffer gnus-summary-buffer))
7020       (gnus-summary-update-article (cdr gnus-article-current)))
7021     ;; Prettify the article buffer again.
7022     (save-excursion
7023       (set-buffer gnus-article-buffer)
7024       (run-hooks 'gnus-article-display-hook))
7025     ;; Prettify the summary buffer line.
7026     (when (gnus-visual-p 'summary-highlight 'highlight)
7027       (run-hooks 'gnus-visual-mark-article-hook))))
7028
7029 (defun gnus-summary-edit-wash (key)
7030   "Perform editing command in the article buffer."
7031   (interactive 
7032    (list
7033     (progn
7034       (message "%s" (concat (this-command-keys) "- "))
7035       (read-char))))
7036   (message "")
7037   (gnus-summary-edit-article)
7038   (execute-kbd-macro (concat (this-command-keys) key))
7039   (gnus-article-edit-done))
7040
7041 ;;; Respooling
7042
7043 (defun gnus-summary-respool-query ()
7044   "Query where the respool algorithm would put this article."
7045   (interactive)
7046   (gnus-set-global-variables)
7047   (let (gnus-mark-article-hook)
7048     (gnus-summary-select-article)
7049     (save-excursion
7050       (set-buffer gnus-article-buffer)
7051       (save-restriction
7052         (goto-char (point-min))
7053         (search-forward "\n\n")
7054         (narrow-to-region (point-min) (point))
7055         (message "This message would go to %s"
7056                  (mapconcat 'car (nnmail-article-group 'identity) ", "))))))
7057
7058 ;; Summary marking commands.
7059
7060 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7061   "Mark articles which has the same subject as read, and then select the next.
7062 If UNMARK is positive, remove any kind of mark.
7063 If UNMARK is negative, tick articles."
7064   (interactive "P")
7065   (gnus-set-global-variables)
7066   (when unmark
7067     (setq unmark (prefix-numeric-value unmark)))
7068   (let ((count
7069          (gnus-summary-mark-same-subject
7070           (gnus-summary-article-subject) unmark)))
7071     ;; Select next unread article.  If auto-select-same mode, should
7072     ;; select the first unread article.
7073     (gnus-summary-next-article t (and gnus-auto-select-same
7074                                       (gnus-summary-article-subject)))
7075     (gnus-message 7 "%d article%s marked as %s"
7076                   count (if (= count 1) " is" "s are")
7077                   (if unmark "unread" "read"))))
7078
7079 (defun gnus-summary-kill-same-subject (&optional unmark)
7080   "Mark articles which has the same subject as read.
7081 If UNMARK is positive, remove any kind of mark.
7082 If UNMARK is negative, tick articles."
7083   (interactive "P")
7084   (gnus-set-global-variables)
7085   (when unmark
7086     (setq unmark (prefix-numeric-value unmark)))
7087   (let ((count
7088          (gnus-summary-mark-same-subject
7089           (gnus-summary-article-subject) unmark)))
7090     ;; If marked as read, go to next unread subject.
7091     (when (null unmark)
7092       ;; Go to next unread subject.
7093       (gnus-summary-next-subject 1 t))
7094     (gnus-message 7 "%d articles are marked as %s"
7095                   count (if unmark "unread" "read"))))
7096
7097 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7098   "Mark articles with same SUBJECT as read, and return marked number.
7099 If optional argument UNMARK is positive, remove any kinds of marks.
7100 If optional argument UNMARK is negative, mark articles as unread instead."
7101   (let ((count 1))
7102     (save-excursion
7103       (cond
7104        ((null unmark)                   ; Mark as read.
7105         (while (and
7106                 (progn
7107                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7108                   (gnus-summary-show-thread) t)
7109                 (gnus-summary-find-subject subject))
7110           (setq count (1+ count))))
7111        ((> unmark 0)                    ; Tick.
7112         (while (and
7113                 (progn
7114                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7115                   (gnus-summary-show-thread) t)
7116                 (gnus-summary-find-subject subject))
7117           (setq count (1+ count))))
7118        (t                               ; Mark as unread.
7119         (while (and
7120                 (progn
7121                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7122                   (gnus-summary-show-thread) t)
7123                 (gnus-summary-find-subject subject))
7124           (setq count (1+ count)))))
7125       (gnus-set-mode-line 'summary)
7126       ;; Return the number of marked articles.
7127       count)))
7128
7129 (defun gnus-summary-mark-as-processable (n &optional unmark)
7130   "Set the process mark on the next N articles.
7131 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7132 the process mark instead.  The difference between N and the actual
7133 number of articles marked is returned."
7134   (interactive "p")
7135   (gnus-set-global-variables)
7136   (let ((backward (< n 0))
7137         (n (abs n)))
7138     (while (and
7139             (> n 0)
7140             (if unmark
7141                 (gnus-summary-remove-process-mark
7142                  (gnus-summary-article-number))
7143               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7144             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7145       (setq n (1- n)))
7146     (when (/= 0 n)
7147       (gnus-message 7 "No more articles"))
7148     (gnus-summary-recenter)
7149     (gnus-summary-position-point)
7150     n))
7151
7152 (defun gnus-summary-unmark-as-processable (n)
7153   "Remove the process mark from the next N articles.
7154 If N is negative, mark backward instead.  The difference between N and
7155 the actual number of articles marked is returned."
7156   (interactive "p")
7157   (gnus-set-global-variables)
7158   (gnus-summary-mark-as-processable n t))
7159
7160 (defun gnus-summary-unmark-all-processable ()
7161   "Remove the process mark from all articles."
7162   (interactive)
7163   (gnus-set-global-variables)
7164   (save-excursion
7165     (while gnus-newsgroup-processable
7166       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7167   (gnus-summary-position-point))
7168
7169 (defun gnus-summary-mark-as-expirable (n)
7170   "Mark N articles forward as expirable.
7171 If N is negative, mark backward instead.  The difference between N and
7172 the actual number of articles marked is returned."
7173   (interactive "p")
7174   (gnus-set-global-variables)
7175   (gnus-summary-mark-forward n gnus-expirable-mark))
7176
7177 (defun gnus-summary-mark-article-as-replied (article)
7178   "Mark ARTICLE replied and update the summary line."
7179   (push article gnus-newsgroup-replied)
7180   (let ((buffer-read-only nil))
7181     (when (gnus-summary-goto-subject article)
7182       (gnus-summary-update-secondary-mark article))))
7183
7184 (defun gnus-summary-set-bookmark (article)
7185   "Set a bookmark in current article."
7186   (interactive (list (gnus-summary-article-number)))
7187   (gnus-set-global-variables)
7188   (when (or (not (get-buffer gnus-article-buffer))
7189             (not gnus-current-article)
7190             (not gnus-article-current)
7191             (not (equal gnus-newsgroup-name (car gnus-article-current))))
7192     (error "No current article selected"))
7193   ;; Remove old bookmark, if one exists.
7194   (let ((old (assq article gnus-newsgroup-bookmarks)))
7195     (when old
7196       (setq gnus-newsgroup-bookmarks
7197             (delq old gnus-newsgroup-bookmarks))))
7198   ;; Set the new bookmark, which is on the form
7199   ;; (article-number . line-number-in-body).
7200   (push
7201    (cons article
7202          (save-excursion
7203            (set-buffer gnus-article-buffer)
7204            (count-lines
7205             (min (point)
7206                  (save-excursion
7207                    (goto-char (point-min))
7208                    (search-forward "\n\n" nil t)
7209                    (point)))
7210             (point))))
7211    gnus-newsgroup-bookmarks)
7212   (gnus-message 6 "A bookmark has been added to the current article."))
7213
7214 (defun gnus-summary-remove-bookmark (article)
7215   "Remove the bookmark from the current article."
7216   (interactive (list (gnus-summary-article-number)))
7217   (gnus-set-global-variables)
7218   ;; Remove old bookmark, if one exists.
7219   (let ((old (assq article gnus-newsgroup-bookmarks)))
7220     (if old
7221         (progn
7222           (setq gnus-newsgroup-bookmarks
7223                 (delq old gnus-newsgroup-bookmarks))
7224           (gnus-message 6 "Removed bookmark."))
7225       (gnus-message 6 "No bookmark in current article."))))
7226
7227 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7228 (defun gnus-summary-mark-as-dormant (n)
7229   "Mark N articles forward as dormant.
7230 If N is negative, mark backward instead.  The difference between N and
7231 the actual number of articles marked is returned."
7232   (interactive "p")
7233   (gnus-set-global-variables)
7234   (gnus-summary-mark-forward n gnus-dormant-mark))
7235
7236 (defun gnus-summary-set-process-mark (article)
7237   "Set the process mark on ARTICLE and update the summary line."
7238   (setq gnus-newsgroup-processable
7239         (cons article
7240               (delq article gnus-newsgroup-processable)))
7241   (when (gnus-summary-goto-subject article)
7242     (gnus-summary-show-thread)
7243     (gnus-summary-update-secondary-mark article)))
7244
7245 (defun gnus-summary-remove-process-mark (article)
7246   "Remove the process mark from ARTICLE and update the summary line."
7247   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
7248   (when (gnus-summary-goto-subject article)
7249     (gnus-summary-show-thread)
7250     (gnus-summary-update-secondary-mark article)))
7251
7252 (defun gnus-summary-set-saved-mark (article)
7253   "Set the process mark on ARTICLE and update the summary line."
7254   (push article gnus-newsgroup-saved)
7255   (when (gnus-summary-goto-subject article)
7256     (gnus-summary-update-secondary-mark article)))
7257
7258 (defun gnus-summary-mark-forward (n &optional mark no-expire)
7259   "Mark N articles as read forwards.
7260 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
7261 The difference between N and the actual number of articles marked is
7262 returned."
7263   (interactive "p")
7264   (gnus-set-global-variables)
7265   (let ((backward (< n 0))
7266         (gnus-summary-goto-unread
7267          (and gnus-summary-goto-unread
7268               (not (eq gnus-summary-goto-unread 'never))
7269               (not (memq mark (list gnus-unread-mark
7270                                     gnus-ticked-mark gnus-dormant-mark)))))
7271         (n (abs n))
7272         (mark (or mark gnus-del-mark)))
7273     (while (and (> n 0)
7274                 (gnus-summary-mark-article nil mark no-expire)
7275                 (zerop (gnus-summary-next-subject
7276                         (if backward -1 1)
7277                         (and gnus-summary-goto-unread
7278                              (not (eq gnus-summary-goto-unread 'never)))
7279                         t)))
7280       (setq n (1- n)))
7281     (when (/= 0 n)
7282       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
7283     (gnus-summary-recenter)
7284     (gnus-summary-position-point)
7285     (gnus-set-mode-line 'summary)
7286     n))
7287
7288 (defun gnus-summary-mark-article-as-read (mark)
7289   "Mark the current article quickly as read with MARK."
7290   (let ((article (gnus-summary-article-number)))
7291     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7292     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7293     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7294     (push (cons article mark) gnus-newsgroup-reads)
7295     ;; Possibly remove from cache, if that is used.
7296     (when gnus-use-cache
7297       (gnus-cache-enter-remove-article article))
7298     ;; Allow the backend to change the mark.
7299     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7300     ;; Check for auto-expiry.
7301     (when (and gnus-newsgroup-auto-expire
7302                (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
7303                    (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
7304                    (= mark gnus-ancient-mark)
7305                    (= mark gnus-read-mark) (= mark gnus-souped-mark)
7306                    (= mark gnus-duplicate-mark)))
7307       (setq mark gnus-expirable-mark)
7308       (push article gnus-newsgroup-expirable))
7309     ;; Set the mark in the buffer.
7310     (gnus-summary-update-mark mark 'unread)
7311     t))
7312
7313 (defun gnus-summary-mark-article-as-unread (mark)
7314   "Mark the current article quickly as unread with MARK."
7315   (let ((article (gnus-summary-article-number)))
7316     (if (< article 0)
7317         (gnus-error 1 "Unmarkable article")
7318       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7319       (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7320       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
7321       (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
7322       (cond ((= mark gnus-ticked-mark)
7323              (push article gnus-newsgroup-marked))
7324             ((= mark gnus-dormant-mark)
7325              (push article gnus-newsgroup-dormant))
7326             (t
7327              (push article gnus-newsgroup-unreads)))
7328       (setq gnus-newsgroup-reads
7329             (delq (assq article gnus-newsgroup-reads)
7330                   gnus-newsgroup-reads))
7331
7332       ;; See whether the article is to be put in the cache.
7333       (and gnus-use-cache
7334            (vectorp (gnus-summary-article-header article))
7335            (save-excursion
7336              (gnus-cache-possibly-enter-article
7337               gnus-newsgroup-name article
7338               (gnus-summary-article-header article)
7339               (= mark gnus-ticked-mark)
7340               (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7341
7342       ;; Fix the mark.
7343       (gnus-summary-update-mark mark 'unread))
7344     t))
7345
7346 (defun gnus-summary-mark-article (&optional article mark no-expire)
7347   "Mark ARTICLE with MARK.  MARK can be any character.
7348 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
7349 `??' (dormant) and `?E' (expirable).
7350 If MARK is nil, then the default character `?D' is used.
7351 If ARTICLE is nil, then the article on the current line will be
7352 marked."
7353   ;; The mark might be a string.
7354   (when (stringp mark)
7355     (setq mark (aref mark 0)))
7356   ;; If no mark is given, then we check auto-expiring.
7357   (and (not no-expire)
7358        gnus-newsgroup-auto-expire
7359        (or (not mark)
7360            (and (gnus-characterp mark)
7361                 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
7362                     (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
7363                     (= mark gnus-read-mark) (= mark gnus-souped-mark)
7364                     (= mark gnus-duplicate-mark))))
7365        (setq mark gnus-expirable-mark))
7366   (let* ((mark (or mark gnus-del-mark))
7367          (article (or article (gnus-summary-article-number))))
7368     (unless article
7369       (error "No article on current line"))
7370     (if (or (= mark gnus-unread-mark)
7371             (= mark gnus-ticked-mark)
7372             (= mark gnus-dormant-mark))
7373         (gnus-mark-article-as-unread article mark)
7374       (gnus-mark-article-as-read article mark))
7375
7376     ;; See whether the article is to be put in the cache.
7377     (and gnus-use-cache
7378          (not (= mark gnus-canceled-mark))
7379          (vectorp (gnus-summary-article-header article))
7380          (save-excursion
7381            (gnus-cache-possibly-enter-article
7382             gnus-newsgroup-name article
7383             (gnus-summary-article-header article)
7384             (= mark gnus-ticked-mark)
7385             (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
7386
7387     (when (gnus-summary-goto-subject article nil t)
7388       (let ((buffer-read-only nil))
7389         (gnus-summary-show-thread)
7390         ;; Fix the mark.
7391         (gnus-summary-update-mark mark 'unread)
7392         t))))
7393
7394 (defun gnus-summary-update-secondary-mark (article)
7395   "Update the secondary (read, process, cache) mark."
7396   (gnus-summary-update-mark
7397    (cond ((memq article gnus-newsgroup-processable)
7398           gnus-process-mark)
7399          ((memq article gnus-newsgroup-cached)
7400           gnus-cached-mark)
7401          ((memq article gnus-newsgroup-replied)
7402           gnus-replied-mark)
7403          ((memq article gnus-newsgroup-saved)
7404           gnus-saved-mark)
7405          (t gnus-unread-mark))
7406    'replied)
7407   (when (gnus-visual-p 'summary-highlight 'highlight)
7408     (run-hooks 'gnus-summary-update-hook))
7409   t)
7410
7411 (defun gnus-summary-update-mark (mark type)
7412   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
7413         (buffer-read-only nil))
7414     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
7415     (when (looking-at "\r")
7416       (incf forward))
7417     (when (and forward
7418                (<= (+ forward (point)) (point-max)))
7419       ;; Go to the right position on the line.
7420       (goto-char (+ forward (point)))
7421       ;; Replace the old mark with the new mark.
7422       (subst-char-in-region (point) (1+ (point)) (following-char) mark)
7423       ;; Optionally update the marks by some user rule.
7424       (when (eq type 'unread)
7425         (gnus-data-set-mark
7426          (gnus-data-find (gnus-summary-article-number)) mark)
7427         (gnus-summary-update-line (eq mark gnus-unread-mark))))))
7428
7429 (defun gnus-mark-article-as-read (article &optional mark)
7430   "Enter ARTICLE in the pertinent lists and remove it from others."
7431   ;; Make the article expirable.
7432   (let ((mark (or mark gnus-del-mark)))
7433     (if (= mark gnus-expirable-mark)
7434         (push article gnus-newsgroup-expirable)
7435       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
7436     ;; Remove from unread and marked lists.
7437     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7438     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7439     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7440     (push (cons article mark) gnus-newsgroup-reads)
7441     ;; Possibly remove from cache, if that is used.
7442     (when gnus-use-cache
7443       (gnus-cache-enter-remove-article article))))
7444
7445 (defun gnus-mark-article-as-unread (article &optional mark)
7446   "Enter ARTICLE in the pertinent lists and remove it from others."
7447   (let ((mark (or mark gnus-ticked-mark)))
7448     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
7449           gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
7450           gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
7451           gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7452
7453     ;; Unsuppress duplicates?
7454     (when gnus-suppress-duplicates
7455       (gnus-dup-unsuppress-article article))
7456
7457     (cond ((= mark gnus-ticked-mark)
7458            (push article gnus-newsgroup-marked))
7459           ((= mark gnus-dormant-mark)
7460            (push article gnus-newsgroup-dormant))
7461           (t
7462            (push article gnus-newsgroup-unreads)))
7463     (setq gnus-newsgroup-reads
7464           (delq (assq article gnus-newsgroup-reads)
7465                 gnus-newsgroup-reads))))
7466
7467 (defalias 'gnus-summary-mark-as-unread-forward
7468   'gnus-summary-tick-article-forward)
7469 (make-obsolete 'gnus-summary-mark-as-unread-forward
7470                'gnus-summary-tick-article-forward)
7471 (defun gnus-summary-tick-article-forward (n)
7472   "Tick N articles forwards.
7473 If N is negative, tick backwards instead.
7474 The difference between N and the number of articles ticked is returned."
7475   (interactive "p")
7476   (gnus-summary-mark-forward n gnus-ticked-mark))
7477
7478 (defalias 'gnus-summary-mark-as-unread-backward
7479   'gnus-summary-tick-article-backward)
7480 (make-obsolete 'gnus-summary-mark-as-unread-backward
7481                'gnus-summary-tick-article-backward)
7482 (defun gnus-summary-tick-article-backward (n)
7483   "Tick N articles backwards.
7484 The difference between N and the number of articles ticked is returned."
7485   (interactive "p")
7486   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
7487
7488 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
7489 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
7490 (defun gnus-summary-tick-article (&optional article clear-mark)
7491   "Mark current article as unread.
7492 Optional 1st argument ARTICLE specifies article number to be marked as unread.
7493 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
7494   (interactive)
7495   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
7496                                        gnus-ticked-mark)))
7497
7498 (defun gnus-summary-mark-as-read-forward (n)
7499   "Mark N articles as read forwards.
7500 If N is negative, mark backwards instead.
7501 The difference between N and the actual number of articles marked is
7502 returned."
7503   (interactive "p")
7504   (gnus-summary-mark-forward n gnus-del-mark t))
7505
7506 (defun gnus-summary-mark-as-read-backward (n)
7507   "Mark the N articles as read backwards.
7508 The difference between N and the actual number of articles marked is
7509 returned."
7510   (interactive "p")
7511   (gnus-summary-mark-forward (- n) gnus-del-mark t))
7512
7513 (defun gnus-summary-mark-as-read (&optional article mark)
7514   "Mark current article as read.
7515 ARTICLE specifies the article to be marked as read.
7516 MARK specifies a string to be inserted at the beginning of the line."
7517   (gnus-summary-mark-article article mark))
7518
7519 (defun gnus-summary-clear-mark-forward (n)
7520   "Clear marks from N articles forward.
7521 If N is negative, clear backward instead.
7522 The difference between N and the number of marks cleared is returned."
7523   (interactive "p")
7524   (gnus-summary-mark-forward n gnus-unread-mark))
7525
7526 (defun gnus-summary-clear-mark-backward (n)
7527   "Clear marks from N articles backward.
7528 The difference between N and the number of marks cleared is returned."
7529   (interactive "p")
7530   (gnus-summary-mark-forward (- n) gnus-unread-mark))
7531
7532 (defun gnus-summary-mark-unread-as-read ()
7533   "Intended to be used by `gnus-summary-mark-article-hook'."
7534   (when (memq gnus-current-article gnus-newsgroup-unreads)
7535     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
7536
7537 (defun gnus-summary-mark-read-and-unread-as-read ()
7538   "Intended to be used by `gnus-summary-mark-article-hook'."
7539   (let ((mark (gnus-summary-article-mark)))
7540     (when (or (gnus-unread-mark-p mark)
7541               (gnus-read-mark-p mark))
7542       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
7543
7544 (defun gnus-summary-mark-region-as-read (point mark all)
7545   "Mark all unread articles between point and mark as read.
7546 If given a prefix, mark all articles between point and mark as read,
7547 even ticked and dormant ones."
7548   (interactive "r\nP")
7549   (save-excursion
7550     (let (article)
7551       (goto-char point)
7552       (beginning-of-line)
7553       (while (and
7554               (< (point) mark)
7555               (progn
7556                 (when (or all
7557                           (memq (setq article (gnus-summary-article-number))
7558                                 gnus-newsgroup-unreads))
7559                   (gnus-summary-mark-article article gnus-del-mark))
7560                 t)
7561               (gnus-summary-find-next))))))
7562
7563 (defun gnus-summary-mark-below (score mark)
7564   "Mark articles with score less than SCORE with MARK."
7565   (interactive "P\ncMark: ")
7566   (gnus-set-global-variables)
7567   (setq score (if score
7568                   (prefix-numeric-value score)
7569                 (or gnus-summary-default-score 0)))
7570   (save-excursion
7571     (set-buffer gnus-summary-buffer)
7572     (goto-char (point-min))
7573     (while 
7574         (progn
7575           (and (< (gnus-summary-article-score) score)
7576                (gnus-summary-mark-article nil mark))
7577           (gnus-summary-find-next)))))
7578
7579 (defun gnus-summary-kill-below (&optional score)
7580   "Mark articles with score below SCORE as read."
7581   (interactive "P")
7582   (gnus-set-global-variables)
7583   (gnus-summary-mark-below score gnus-killed-mark))
7584
7585 (defun gnus-summary-clear-above (&optional score)
7586   "Clear all marks from articles with score above SCORE."
7587   (interactive "P")
7588   (gnus-set-global-variables)
7589   (gnus-summary-mark-above score gnus-unread-mark))
7590
7591 (defun gnus-summary-tick-above (&optional score)
7592   "Tick all articles with score above SCORE."
7593   (interactive "P")
7594   (gnus-set-global-variables)
7595   (gnus-summary-mark-above score gnus-ticked-mark))
7596
7597 (defun gnus-summary-mark-above (score mark)
7598   "Mark articles with score over SCORE with MARK."
7599   (interactive "P\ncMark: ")
7600   (gnus-set-global-variables)
7601   (setq score (if score
7602                   (prefix-numeric-value score)
7603                 (or gnus-summary-default-score 0)))
7604   (save-excursion
7605     (set-buffer gnus-summary-buffer)
7606     (goto-char (point-min))
7607     (while (and (progn
7608                   (when (> (gnus-summary-article-score) score)
7609                     (gnus-summary-mark-article nil mark))
7610                   t)
7611                 (gnus-summary-find-next)))))
7612
7613 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7614 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
7615 (defun gnus-summary-limit-include-expunged (&optional no-error)
7616   "Display all the hidden articles that were expunged for low scores."
7617   (interactive)
7618   (gnus-set-global-variables)
7619   (let ((buffer-read-only nil))
7620     (let ((scored gnus-newsgroup-scored)
7621           headers h)
7622       (while scored
7623         (unless (gnus-summary-goto-subject (caar scored))
7624           (and (setq h (gnus-summary-article-header (caar scored)))
7625                (< (cdar scored) gnus-summary-expunge-below)
7626                (push h headers)))
7627         (setq scored (cdr scored)))
7628       (if (not headers)
7629           (when (not no-error)
7630             (error "No expunged articles hidden."))
7631         (goto-char (point-min))
7632         (gnus-summary-prepare-unthreaded (nreverse headers))
7633         (goto-char (point-min))
7634         (gnus-summary-position-point)
7635         t))))
7636
7637 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
7638   "Mark all unread articles in this newsgroup as read.
7639 If prefix argument ALL is non-nil, ticked and dormant articles will 
7640 also be marked as read.
7641 If QUIETLY is non-nil, no questions will be asked.
7642 If TO-HERE is non-nil, it should be a point in the buffer.  All
7643 articles before this point will be marked as read.
7644 Note that this function will only catch up the unread article
7645 in the current summary buffer limitation.
7646 The number of articles marked as read is returned."
7647   (interactive "P")
7648   (gnus-set-global-variables)
7649   (prog1
7650       (save-excursion
7651         (when (or quietly
7652                   (not gnus-interactive-catchup) ;Without confirmation?
7653                   gnus-expert-user
7654                   (gnus-y-or-n-p
7655                    (if all
7656                        "Mark absolutely all articles as read? "
7657                      "Mark all unread articles as read? ")))
7658           (if (and not-mark
7659                    (not gnus-newsgroup-adaptive)
7660                    (not gnus-newsgroup-auto-expire)
7661                    (not gnus-suppress-duplicates))
7662               (progn
7663                 (when all
7664                   (setq gnus-newsgroup-marked nil
7665                         gnus-newsgroup-dormant nil))
7666                 (setq gnus-newsgroup-unreads nil))
7667             ;; We actually mark all articles as canceled, which we
7668             ;; have to do when using auto-expiry or adaptive scoring.
7669             (gnus-summary-show-all-threads)
7670             (when (gnus-summary-first-subject (not all))
7671               (while (and
7672                       (if to-here (< (point) to-here) t)
7673                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
7674                       (gnus-summary-find-next (not all)))))
7675             (gnus-set-mode-line 'summary))
7676           t))
7677     (gnus-summary-position-point)))
7678
7679 (defun gnus-summary-catchup-to-here (&optional all)
7680   "Mark all unticked articles before the current one as read.
7681 If ALL is non-nil, also mark ticked and dormant articles as read."
7682   (interactive "P")
7683   (gnus-set-global-variables)
7684   (save-excursion
7685     (gnus-save-hidden-threads
7686       (let ((beg (point)))
7687         ;; We check that there are unread articles.
7688         (when (or all (gnus-summary-find-prev))
7689           (gnus-summary-catchup all t beg)))))
7690   (gnus-summary-position-point))
7691
7692 (defun gnus-summary-catchup-all (&optional quietly)
7693   "Mark all articles in this newsgroup as read."
7694   (interactive "P")
7695   (gnus-set-global-variables)
7696   (gnus-summary-catchup t quietly))
7697
7698 (defun gnus-summary-catchup-and-exit (&optional all quietly)
7699   "Mark all articles not marked as unread in this newsgroup as read, then exit.
7700 If prefix argument ALL is non-nil, all articles are marked as read."
7701   (interactive "P")
7702   (gnus-set-global-variables)
7703   (when (gnus-summary-catchup all quietly nil 'fast)
7704     ;; Select next newsgroup or exit.
7705     (if (eq gnus-auto-select-next 'quietly)
7706         (gnus-summary-next-group nil)
7707       (gnus-summary-exit))))
7708
7709 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
7710   "Mark all articles in this newsgroup as read, and then exit."
7711   (interactive "P")
7712   (gnus-set-global-variables)
7713   (gnus-summary-catchup-and-exit t quietly))
7714
7715 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
7716 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
7717   "Mark all articles in this group as read and select the next group.
7718 If given a prefix, mark all articles, unread as well as ticked, as
7719 read."
7720   (interactive "P")
7721   (gnus-set-global-variables)
7722   (save-excursion
7723     (gnus-summary-catchup all))
7724   (gnus-summary-next-article t nil nil t))
7725
7726 ;; Thread-based commands.
7727
7728 (defun gnus-summary-articles-in-thread (&optional article)
7729   "Return a list of all articles in the current thread.
7730 If ARTICLE is non-nil, return all articles in the thread that starts
7731 with that article."
7732   (let* ((article (or article (gnus-summary-article-number)))
7733          (data (gnus-data-find-list article))
7734          (top-level (gnus-data-level (car data)))
7735          (top-subject
7736           (cond ((null gnus-thread-operation-ignore-subject)
7737                  (gnus-simplify-subject-re
7738                   (mail-header-subject (gnus-data-header (car data)))))
7739                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
7740                  (gnus-simplify-subject-fuzzy
7741                   (mail-header-subject (gnus-data-header (car data)))))
7742                 (t nil)))
7743          (end-point (save-excursion
7744                       (if (gnus-summary-go-to-next-thread)
7745                           (point) (point-max))))
7746          articles)
7747     (while (and data
7748                 (< (gnus-data-pos (car data)) end-point))
7749       (when (or (not top-subject)
7750                 (string= top-subject
7751                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
7752                              (gnus-simplify-subject-fuzzy
7753                               (mail-header-subject
7754                                (gnus-data-header (car data))))
7755                            (gnus-simplify-subject-re
7756                             (mail-header-subject
7757                              (gnus-data-header (car data)))))))
7758         (push (gnus-data-number (car data)) articles))
7759       (unless (and (setq data (cdr data))
7760                    (> (gnus-data-level (car data)) top-level))
7761         (setq data nil)))
7762     ;; Return the list of articles.
7763     (nreverse articles)))
7764
7765 (defun gnus-summary-rethread-current ()
7766   "Rethread the thread the current article is part of."
7767   (interactive)
7768   (gnus-set-global-variables)
7769   (let* ((gnus-show-threads t)
7770          (article (gnus-summary-article-number))
7771          (id (mail-header-id (gnus-summary-article-header)))
7772          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
7773     (unless id
7774       (error "No article on the current line"))
7775     (gnus-rebuild-thread id)
7776     (gnus-summary-goto-subject article)))
7777
7778 (defun gnus-summary-reparent-thread ()
7779   "Make current article child of the marked (or previous) article.
7780
7781 Note that the re-threading will only work if `gnus-thread-ignore-subject'
7782 is non-nil or the Subject: of both articles are the same."
7783   (interactive)
7784   (unless (not (gnus-group-read-only-p))
7785     (error "The current newsgroup does not support article editing."))
7786   (unless (<= (length gnus-newsgroup-processable) 1)
7787     (error "No more than one article may be marked."))
7788   (save-window-excursion
7789     (let ((gnus-article-buffer " *reparent*")
7790           (current-article (gnus-summary-article-number))
7791                                         ; first grab the marked article, otherwise one line up.
7792           (parent-article (if (not (null gnus-newsgroup-processable))
7793                               (car gnus-newsgroup-processable)
7794                             (save-excursion
7795                               (if (eq (forward-line -1) 0)
7796                                   (gnus-summary-article-number)
7797                                 (error "Beginning of summary buffer."))))))
7798       (unless (not (eq current-article parent-article))
7799         (error "An article may not be self-referential."))
7800       (let ((message-id (mail-header-id 
7801                          (gnus-summary-article-header parent-article))))
7802         (unless (and message-id (not (equal message-id "")))
7803           (error "No message-id in desired parent."))
7804         (gnus-summary-select-article t t nil current-article)
7805         (set-buffer gnus-article-buffer)
7806         (setq buffer-read-only nil)
7807         (let ((buf (format "%s" (buffer-string))))
7808           (erase-buffer)
7809           (insert buf))
7810         (goto-char (point-min))
7811         (if (search-forward-regexp "^References: " nil t)
7812             (insert message-id " " )
7813           (insert "References: " message-id "\n"))
7814         (unless (gnus-request-replace-article current-article
7815                                               (car gnus-article-current)
7816                                               gnus-article-buffer)
7817           (error "Couldn't replace article."))
7818         (set-buffer gnus-summary-buffer)
7819         (gnus-summary-unmark-all-processable)
7820         (gnus-summary-rethread-current)
7821         (gnus-message 3 "Article %d is now the child of article %d."
7822                       current-article parent-article)))))
7823
7824 (defun gnus-summary-toggle-threads (&optional arg)
7825   "Toggle showing conversation threads.
7826 If ARG is positive number, turn showing conversation threads on."
7827   (interactive "P")
7828   (gnus-set-global-variables)
7829   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
7830     (setq gnus-show-threads
7831           (if (null arg) (not gnus-show-threads)
7832             (> (prefix-numeric-value arg) 0)))
7833     (gnus-summary-prepare)
7834     (gnus-summary-goto-subject current)
7835     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
7836     (gnus-summary-position-point)))
7837
7838 (defun gnus-summary-show-all-threads ()
7839   "Show all threads."
7840   (interactive)
7841   (gnus-set-global-variables)
7842   (save-excursion
7843     (let ((buffer-read-only nil))
7844       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
7845   (gnus-summary-position-point))
7846
7847 (defun gnus-summary-show-thread ()
7848   "Show thread subtrees.
7849 Returns nil if no thread was there to be shown."
7850   (interactive)
7851   (gnus-set-global-variables)
7852   (let ((buffer-read-only nil)
7853         (orig (point))
7854         ;; first goto end then to beg, to have point at beg after let
7855         (end (progn (end-of-line) (point)))
7856         (beg (progn (beginning-of-line) (point))))
7857     (prog1
7858         ;; Any hidden lines here?
7859         (search-forward "\r" end t)
7860       (subst-char-in-region beg end ?\^M ?\n t)
7861       (goto-char orig)
7862       (gnus-summary-position-point))))
7863
7864 (defun gnus-summary-hide-all-threads ()
7865   "Hide all thread subtrees."
7866   (interactive)
7867   (gnus-set-global-variables)
7868   (save-excursion
7869     (goto-char (point-min))
7870     (gnus-summary-hide-thread)
7871     (while (zerop (gnus-summary-next-thread 1 t))
7872       (gnus-summary-hide-thread)))
7873   (gnus-summary-position-point))
7874
7875 (defun gnus-summary-hide-thread ()
7876   "Hide thread subtrees.
7877 Returns nil if no threads were there to be hidden."
7878   (interactive)
7879   (gnus-set-global-variables)
7880   (let ((buffer-read-only nil)
7881         (start (point))
7882         (article (gnus-summary-article-number)))
7883     (goto-char start)
7884     ;; Go forward until either the buffer ends or the subthread
7885     ;; ends.
7886     (when (and (not (eobp))
7887                (or (zerop (gnus-summary-next-thread 1 t))
7888                    (goto-char (point-max))))
7889       (prog1
7890           (if (and (> (point) start)
7891                    (search-backward "\n" start t))
7892               (progn
7893                 (subst-char-in-region start (point) ?\n ?\^M)
7894                 (gnus-summary-goto-subject article))
7895             (goto-char start)
7896             nil)
7897         ;;(gnus-summary-position-point)
7898         ))))
7899
7900 (defun gnus-summary-go-to-next-thread (&optional previous)
7901   "Go to the same level (or less) next thread.
7902 If PREVIOUS is non-nil, go to previous thread instead.
7903 Return the article number moved to, or nil if moving was impossible."
7904   (let ((level (gnus-summary-thread-level))
7905         (way (if previous -1 1))
7906         (beg (point)))
7907     (forward-line way)
7908     (while (and (not (eobp))
7909                 (< level (gnus-summary-thread-level)))
7910       (forward-line way))
7911     (if (eobp)
7912         (progn
7913           (goto-char beg)
7914           nil)
7915       (setq beg (point))
7916       (prog1
7917           (gnus-summary-article-number)
7918         (goto-char beg)))))
7919
7920 (defun gnus-summary-next-thread (n &optional silent)
7921   "Go to the same level next N'th thread.
7922 If N is negative, search backward instead.
7923 Returns the difference between N and the number of skips actually
7924 done.
7925
7926 If SILENT, don't output messages."
7927   (interactive "p")
7928   (gnus-set-global-variables)
7929   (let ((backward (< n 0))
7930         (n (abs n)))
7931     (while (and (> n 0)
7932                 (gnus-summary-go-to-next-thread backward))
7933       (decf n))
7934     (unless silent 
7935       (gnus-summary-position-point))
7936     (when (and (not silent) (/= 0 n))
7937       (gnus-message 7 "No more threads"))
7938     n))
7939
7940 (defun gnus-summary-prev-thread (n)
7941   "Go to the same level previous N'th thread.
7942 Returns the difference between N and the number of skips actually
7943 done."
7944   (interactive "p")
7945   (gnus-set-global-variables)
7946   (gnus-summary-next-thread (- n)))
7947
7948 (defun gnus-summary-go-down-thread ()
7949   "Go down one level in the current thread."
7950   (let ((children (gnus-summary-article-children)))
7951     (when children
7952       (gnus-summary-goto-subject (car children)))))
7953
7954 (defun gnus-summary-go-up-thread ()
7955   "Go up one level in the current thread."
7956   (let ((parent (gnus-summary-article-parent)))
7957     (when parent
7958       (gnus-summary-goto-subject parent))))
7959
7960 (defun gnus-summary-down-thread (n)
7961   "Go down thread N steps.
7962 If N is negative, go up instead.
7963 Returns the difference between N and how many steps down that were
7964 taken."
7965   (interactive "p")
7966   (gnus-set-global-variables)
7967   (let ((up (< n 0))
7968         (n (abs n)))
7969     (while (and (> n 0)
7970                 (if up (gnus-summary-go-up-thread)
7971                   (gnus-summary-go-down-thread)))
7972       (setq n (1- n)))
7973     (gnus-summary-position-point)
7974     (when (/= 0 n)
7975       (gnus-message 7 "Can't go further"))
7976     n))
7977
7978 (defun gnus-summary-up-thread (n)
7979   "Go up thread N steps.
7980 If N is negative, go up instead.
7981 Returns the difference between N and how many steps down that were
7982 taken."
7983   (interactive "p")
7984   (gnus-set-global-variables)
7985   (gnus-summary-down-thread (- n)))
7986
7987 (defun gnus-summary-top-thread ()
7988   "Go to the top of the thread."
7989   (interactive)
7990   (gnus-set-global-variables)
7991   (while (gnus-summary-go-up-thread))
7992   (gnus-summary-article-number))
7993
7994 (defun gnus-summary-kill-thread (&optional unmark)
7995   "Mark articles under current thread as read.
7996 If the prefix argument is positive, remove any kinds of marks.
7997 If the prefix argument is negative, tick articles instead."
7998   (interactive "P")
7999   (gnus-set-global-variables)
8000   (when unmark
8001     (setq unmark (prefix-numeric-value unmark)))
8002   (let ((articles (gnus-summary-articles-in-thread)))
8003     (save-excursion
8004       ;; Expand the thread.
8005       (gnus-summary-show-thread)
8006       ;; Mark all the articles.
8007       (while articles
8008         (gnus-summary-goto-subject (car articles))
8009         (cond ((null unmark)
8010                (gnus-summary-mark-article-as-read gnus-killed-mark))
8011               ((> unmark 0)
8012                (gnus-summary-mark-article-as-unread gnus-unread-mark))
8013               (t
8014                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8015         (setq articles (cdr articles))))
8016     ;; Hide killed subtrees.
8017     (and (null unmark)
8018          gnus-thread-hide-killed
8019          (gnus-summary-hide-thread))
8020     ;; If marked as read, go to next unread subject.
8021     (when (null unmark)
8022       ;; Go to next unread subject.
8023       (gnus-summary-next-subject 1 t)))
8024   (gnus-set-mode-line 'summary))
8025
8026 ;; Summary sorting commands
8027
8028 (defun gnus-summary-sort-by-number (&optional reverse)
8029   "Sort the summary buffer by article number.
8030 Argument REVERSE means reverse order."
8031   (interactive "P")
8032   (gnus-summary-sort 'number reverse))
8033
8034 (defun gnus-summary-sort-by-author (&optional reverse)
8035   "Sort the summary buffer by author name alphabetically.
8036 If case-fold-search is non-nil, case of letters is ignored.
8037 Argument REVERSE means reverse order."
8038   (interactive "P")
8039   (gnus-summary-sort 'author reverse))
8040
8041 (defun gnus-summary-sort-by-subject (&optional reverse)
8042   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
8043 If case-fold-search is non-nil, case of letters is ignored.
8044 Argument REVERSE means reverse order."
8045   (interactive "P")
8046   (gnus-summary-sort 'subject reverse))
8047
8048 (defun gnus-summary-sort-by-date (&optional reverse)
8049   "Sort the summary buffer by date.
8050 Argument REVERSE means reverse order."
8051   (interactive "P")
8052   (gnus-summary-sort 'date reverse))
8053
8054 (defun gnus-summary-sort-by-score (&optional reverse)
8055   "Sort the summary buffer by score.
8056 Argument REVERSE means reverse order."
8057   (interactive "P")
8058   (gnus-summary-sort 'score reverse))
8059
8060 (defun gnus-summary-sort-by-lines (&optional reverse)
8061   "Sort the summary buffer by article length.
8062 Argument REVERSE means reverse order."
8063   (interactive "P")
8064   (gnus-summary-sort 'lines reverse))
8065
8066 (defun gnus-summary-sort (predicate reverse)
8067   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8068   (gnus-set-global-variables)
8069   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8070          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8071          (gnus-thread-sort-functions
8072           (list
8073            (if (not reverse)
8074                thread
8075              `(lambda (t1 t2)
8076                 (,thread t2 t1)))))
8077          (gnus-article-sort-functions
8078           (list
8079            (if (not reverse)
8080                article
8081              `(lambda (t1 t2)
8082                 (,article t2 t1)))))
8083          (buffer-read-only)
8084          (gnus-summary-prepare-hook nil))
8085     ;; We do the sorting by regenerating the threads.
8086     (gnus-summary-prepare)
8087     ;; Hide subthreads if needed.
8088     (when (and gnus-show-threads gnus-thread-hide-subtree)
8089       (gnus-summary-hide-all-threads))))
8090
8091 ;; Summary saving commands.
8092
8093 (defun gnus-summary-save-article (&optional n not-saved)
8094   "Save the current article using the default saver function.
8095 If N is a positive number, save the N next articles.
8096 If N is a negative number, save the N previous articles.
8097 If N is nil and any articles have been marked with the process mark,
8098 save those articles instead.
8099 The variable `gnus-default-article-saver' specifies the saver function."
8100   (interactive "P")
8101   (gnus-set-global-variables)
8102   (let* ((articles (gnus-summary-work-articles n))
8103          (save-buffer (save-excursion 
8104                         (nnheader-set-temp-buffer " *Gnus Save*")))
8105          (num (length articles))
8106          header article file)
8107     (while articles
8108       (setq header (gnus-summary-article-header
8109                     (setq article (pop articles))))
8110       (if (not (vectorp header))
8111           ;; This is a pseudo-article.
8112           (if (assq 'name header)
8113               (gnus-copy-file (cdr (assq 'name header)))
8114             (gnus-message 1 "Article %d is unsaveable" article))
8115         ;; This is a real article.
8116         (save-window-excursion
8117           (gnus-summary-select-article t nil nil article))
8118         (save-excursion
8119           (set-buffer save-buffer)
8120           (erase-buffer)
8121           (insert-buffer-substring gnus-original-article-buffer))
8122         (setq file (gnus-article-save save-buffer file num))
8123         (gnus-summary-remove-process-mark article)
8124         (unless not-saved
8125           (gnus-summary-set-saved-mark article))))
8126     (gnus-kill-buffer save-buffer)
8127     (gnus-summary-position-point)
8128     (gnus-set-mode-line 'summary)
8129     n))
8130
8131 (defun gnus-summary-pipe-output (&optional arg)
8132   "Pipe the current article to a subprocess.
8133 If N is a positive number, pipe the N next articles.
8134 If N is a negative number, pipe the N previous articles.
8135 If N is nil and any articles have been marked with the process mark,
8136 pipe those articles instead."
8137   (interactive "P")
8138   (gnus-set-global-variables)
8139   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8140     (gnus-summary-save-article arg t))
8141   (gnus-configure-windows 'pipe))
8142
8143 (defun gnus-summary-save-article-mail (&optional arg)
8144   "Append the current article to an mail file.
8145 If N is a positive number, save the N next articles.
8146 If N is a negative number, save the N previous articles.
8147 If N is nil and any articles have been marked with the process mark,
8148 save those articles instead."
8149   (interactive "P")
8150   (gnus-set-global-variables)
8151   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8152     (gnus-summary-save-article arg)))
8153
8154 (defun gnus-summary-save-article-rmail (&optional arg)
8155   "Append the current article to an rmail file.
8156 If N is a positive number, save the N next articles.
8157 If N is a negative number, save the N previous articles.
8158 If N is nil and any articles have been marked with the process mark,
8159 save those articles instead."
8160   (interactive "P")
8161   (gnus-set-global-variables)
8162   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
8163     (gnus-summary-save-article arg)))
8164
8165 (defun gnus-summary-save-article-file (&optional arg)
8166   "Append the current article to a file.
8167 If N is a positive number, save the N next articles.
8168 If N is a negative number, save the N previous articles.
8169 If N is nil and any articles have been marked with the process mark,
8170 save those articles instead."
8171   (interactive "P")
8172   (gnus-set-global-variables)
8173   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8174     (gnus-summary-save-article arg)))
8175
8176 (defun gnus-summary-write-article-file (&optional arg)
8177   "Write the current article to a file, deleting the previous file.
8178 If N is a positive number, save the N next articles.
8179 If N is a negative number, save the N previous articles.
8180 If N is nil and any articles have been marked with the process mark,
8181 save those articles instead."
8182   (interactive "P")
8183   (gnus-set-global-variables)
8184   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8185     (gnus-summary-save-article arg)))
8186
8187 (defun gnus-summary-save-article-body-file (&optional arg)
8188   "Append the current article body to a file.
8189 If N is a positive number, save the N next articles.
8190 If N is a negative number, save the N previous articles.
8191 If N is nil and any articles have been marked with the process mark,
8192 save those articles instead."
8193   (interactive "P")
8194   (gnus-set-global-variables)
8195   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8196     (gnus-summary-save-article arg)))
8197
8198 (defun gnus-get-split-value (methods)
8199   "Return a value based on the split METHODS."
8200   (let (split-name method result match)
8201     (when methods
8202       (save-excursion
8203         (set-buffer gnus-original-article-buffer)
8204         (save-restriction
8205           (nnheader-narrow-to-headers)
8206           (while methods
8207             (goto-char (point-min))
8208             (setq method (pop methods))
8209             (setq match (car method))
8210             (when (cond
8211                    ((stringp match)
8212                     ;; Regular expression.
8213                     (ignore-errors
8214                       (re-search-forward match nil t)))
8215                    ((gnus-functionp match)
8216                     ;; Function.
8217                     (save-restriction
8218                       (widen)
8219                       (setq result (funcall match gnus-newsgroup-name))))
8220                    ((consp match)
8221                     ;; Form.
8222                     (save-restriction
8223                       (widen)
8224                       (setq result (eval match)))))
8225               (setq split-name (append (cdr method) split-name))
8226               (cond ((stringp result)
8227                      (push (expand-file-name
8228                             result gnus-article-save-directory)
8229                            split-name))
8230                     ((consp result)
8231                      (setq split-name (append result split-name)))))))))
8232     split-name))
8233
8234 (defun gnus-valid-move-group-p (group)
8235   (and (boundp group)
8236        (symbol-name group)
8237        (memq 'respool
8238              (assoc (symbol-name
8239                      (car (gnus-find-method-for-group
8240                            (symbol-name group))))
8241                     gnus-valid-select-methods))))
8242
8243 (defun gnus-read-move-group-name (prompt default articles prefix)
8244   "Read a group name."
8245   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
8246          (minibuffer-confirm-incomplete nil) ; XEmacs
8247          (prom
8248           (format "%s %s to:"
8249                   prompt
8250                   (if (> (length articles) 1)
8251                       (format "these %d articles" (length articles))
8252                     "this article")))
8253          (to-newsgroup
8254           (cond
8255            ((null split-name)
8256             (gnus-completing-read default prom
8257                                   gnus-active-hashtb
8258                                   'gnus-valid-move-group-p
8259                                   nil prefix
8260                                   'gnus-group-history))
8261            ((= 1 (length split-name))
8262             (gnus-completing-read (car split-name) prom
8263                                   gnus-active-hashtb
8264                                   'gnus-valid-move-group-p
8265                                   nil nil
8266                                   'gnus-group-history))
8267            (t
8268             (gnus-completing-read nil prom 
8269                                   (mapcar (lambda (el) (list el))
8270                                           (nreverse split-name))
8271                                   nil nil nil
8272                                   'gnus-group-history)))))
8273     (when to-newsgroup
8274       (if (or (string= to-newsgroup "")
8275               (string= to-newsgroup prefix))
8276           (setq to-newsgroup (or default "")))
8277       (or (gnus-active to-newsgroup)
8278           (gnus-activate-group to-newsgroup)
8279           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
8280                                      to-newsgroup))
8281               (or (and (gnus-request-create-group 
8282                         to-newsgroup (gnus-group-name-to-method to-newsgroup))
8283                        (gnus-activate-group to-newsgroup nil nil
8284                                             (gnus-group-name-to-method
8285                                              to-newsgroup)))
8286                   (error "Couldn't create group %s" to-newsgroup)))
8287           (error "No such group: %s" to-newsgroup)))
8288     to-newsgroup))
8289
8290 ;; Summary extract commands
8291
8292 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
8293   (let ((buffer-read-only nil)
8294         (article (gnus-summary-article-number))
8295         after-article b e)
8296     (unless (gnus-summary-goto-subject article)
8297       (error "No such article: %d" article))
8298     (gnus-summary-position-point)
8299     ;; If all commands are to be bunched up on one line, we collect
8300     ;; them here.
8301     (unless gnus-view-pseudos-separately
8302       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
8303             files action)
8304         (while ps
8305           (setq action (cdr (assq 'action (car ps))))
8306           (setq files (list (cdr (assq 'name (car ps)))))
8307           (while (and ps (cdr ps)
8308                       (string= (or action "1")
8309                                (or (cdr (assq 'action (cadr ps))) "2")))
8310             (push (cdr (assq 'name (cadr ps))) files)
8311             (setcdr ps (cddr ps)))
8312           (when files
8313             (when (not (string-match "%s" action))
8314               (push " " files))
8315             (push " " files)
8316             (when (assq 'execute (car ps))
8317               (setcdr (assq 'execute (car ps))
8318                       (funcall (if (string-match "%s" action)
8319                                    'format 'concat)
8320                                action
8321                                (mapconcat (lambda (f) f) files " ")))))
8322           (setq ps (cdr ps)))))
8323     (if (and gnus-view-pseudos (not not-view))
8324         (while pslist
8325           (when (assq 'execute (car pslist))
8326             (gnus-execute-command (cdr (assq 'execute (car pslist)))
8327                                   (eq gnus-view-pseudos 'not-confirm)))
8328           (setq pslist (cdr pslist)))
8329       (save-excursion
8330         (while pslist
8331           (setq after-article (or (cdr (assq 'article (car pslist)))
8332                                   (gnus-summary-article-number)))
8333           (gnus-summary-goto-subject after-article)
8334           (forward-line 1)
8335           (setq b (point))
8336           (insert "    " (file-name-nondirectory
8337                           (cdr (assq 'name (car pslist))))
8338                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
8339           (setq e (point))
8340           (forward-line -1)             ; back to `b'
8341           (gnus-add-text-properties
8342            b (1- e) (list 'gnus-number gnus-reffed-article-number
8343                           gnus-mouse-face-prop gnus-mouse-face))
8344           (gnus-data-enter
8345            after-article gnus-reffed-article-number
8346            gnus-unread-mark b (car pslist) 0 (- e b))
8347           (push gnus-reffed-article-number gnus-newsgroup-unreads)
8348           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
8349           (setq pslist (cdr pslist)))))))
8350
8351 (defun gnus-pseudos< (p1 p2)
8352   (let ((c1 (cdr (assq 'action p1)))
8353         (c2 (cdr (assq 'action p2))))
8354     (and c1 c2 (string< c1 c2))))
8355
8356 (defun gnus-request-pseudo-article (props)
8357   (cond ((assq 'execute props)
8358          (gnus-execute-command (cdr (assq 'execute props)))))
8359   (let ((gnus-current-article (gnus-summary-article-number)))
8360     (run-hooks 'gnus-mark-article-hook)))
8361
8362 (defun gnus-execute-command (command &optional automatic)
8363   (save-excursion
8364     (gnus-article-setup-buffer)
8365     (set-buffer gnus-article-buffer)
8366     (setq buffer-read-only nil)
8367     (let ((command (if automatic command (read-string "Command: " command)))
8368           ;; Just binding this here doesn't help, because there might
8369           ;; be output from the process after exiting the scope of 
8370           ;; this `let'.
8371           ;; (buffer-read-only nil)
8372           )
8373       (erase-buffer)
8374       (insert "$ " command "\n\n")
8375       (if gnus-view-pseudo-asynchronously
8376           (start-process "gnus-execute" nil shell-file-name
8377                          shell-command-switch command)
8378         (call-process shell-file-name nil t nil
8379                       shell-command-switch command)))))
8380
8381 ;; Summary kill commands.
8382
8383 (defun gnus-summary-edit-global-kill (article)
8384   "Edit the \"global\" kill file."
8385   (interactive (list (gnus-summary-article-number)))
8386   (gnus-set-global-variables)
8387   (gnus-group-edit-global-kill article))
8388
8389 (defun gnus-summary-edit-local-kill ()
8390   "Edit a local kill file applied to the current newsgroup."
8391   (interactive)
8392   (gnus-set-global-variables)
8393   (setq gnus-current-headers (gnus-summary-article-header))
8394   (gnus-set-global-variables)
8395   (gnus-group-edit-local-kill
8396    (gnus-summary-article-number) gnus-newsgroup-name))
8397
8398 ;;; Header reading.
8399
8400 (defun gnus-read-header (id &optional header)
8401   "Read the headers of article ID and enter them into the Gnus system."
8402   (let ((group gnus-newsgroup-name)
8403         (gnus-override-method 
8404          (and (gnus-news-group-p gnus-newsgroup-name)
8405               gnus-refer-article-method))
8406         where)
8407     ;; First we check to see whether the header in question is already
8408     ;; fetched.
8409     (if (stringp id)
8410         ;; This is a Message-ID.
8411         (setq header (or header (gnus-id-to-header id)))
8412       ;; This is an article number.
8413       (setq header (or header (gnus-summary-article-header id))))
8414     (if (and header
8415              (not (gnus-summary-article-sparse-p (mail-header-number header))))
8416         ;; We have found the header.
8417         header
8418       ;; We have to really fetch the header to this article.
8419       (save-excursion
8420         (set-buffer nntp-server-buffer)
8421         (when (setq where (gnus-request-head id group))
8422           (nnheader-fold-continuation-lines)
8423           (goto-char (point-max))
8424           (insert ".\n")
8425           (goto-char (point-min))
8426           (insert "211 ")
8427           (princ (cond
8428                   ((numberp id) id)
8429                   ((cdr where) (cdr where))
8430                   (header (mail-header-number header))
8431                   (t gnus-reffed-article-number))
8432                  (current-buffer))
8433           (insert " Article retrieved.\n"))
8434         (if (not (setq header (car (gnus-get-newsgroup-headers nil t))))
8435             ()                          ; Malformed head.
8436           (unless (gnus-summary-article-sparse-p (mail-header-number header))
8437             (when (and (stringp id)
8438                        (not (string= (gnus-group-real-name group)
8439                                      (car where))))
8440               ;; If we fetched by Message-ID and the article came
8441               ;; from a different group, we fudge some bogus article
8442               ;; numbers for this article.
8443               (mail-header-set-number header gnus-reffed-article-number))
8444             (save-excursion
8445               (set-buffer gnus-summary-buffer)
8446               (decf gnus-reffed-article-number)
8447               (gnus-remove-header (mail-header-number header))
8448               (push header gnus-newsgroup-headers)
8449               (setq gnus-current-headers header)
8450               (push (mail-header-number header) gnus-newsgroup-limit)))
8451           header)))))
8452
8453 (defun gnus-remove-header (number)
8454   "Remove header NUMBER from `gnus-newsgroup-headers'."
8455   (if (and gnus-newsgroup-headers
8456            (= number (mail-header-number (car gnus-newsgroup-headers))))
8457       (pop gnus-newsgroup-headers)
8458     (let ((headers gnus-newsgroup-headers))
8459       (while (and (cdr headers)
8460                   (not (= number (mail-header-number (cadr headers)))))
8461         (pop headers))
8462       (when (cdr headers)
8463         (setcdr headers (cddr headers))))))
8464
8465 ;;;
8466 ;;; summary highlights
8467 ;;;
8468
8469 (defun gnus-highlight-selected-summary ()
8470   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
8471   ;; Highlight selected article in summary buffer
8472   (when gnus-summary-selected-face
8473     (save-excursion
8474       (let* ((beg (progn (beginning-of-line) (point)))
8475              (end (progn (end-of-line) (point)))
8476              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
8477              (from (if (get-text-property beg gnus-mouse-face-prop)
8478                        beg
8479                      (or (next-single-property-change 
8480                           beg gnus-mouse-face-prop nil end)
8481                          beg)))
8482              (to
8483               (if (= from end)
8484                   (- from 2)
8485                 (or (next-single-property-change
8486                      from gnus-mouse-face-prop nil end)
8487                     end))))
8488         ;; If no mouse-face prop on line we will have to = from = end,
8489         ;; so we highlight the entire line instead.
8490         (when (= (+ to 2) from)
8491           (setq from beg)
8492           (setq to end))
8493         (if gnus-newsgroup-selected-overlay
8494             ;; Move old overlay.
8495             (gnus-move-overlay
8496              gnus-newsgroup-selected-overlay from to (current-buffer))
8497           ;; Create new overlay.
8498           (gnus-overlay-put
8499            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
8500            'face gnus-summary-selected-face))))))
8501
8502 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
8503 (defun gnus-summary-highlight-line ()
8504   "Highlight current line according to `gnus-summary-highlight'."
8505   (let* ((list gnus-summary-highlight)
8506          (p (point))
8507          (end (progn (end-of-line) (point)))
8508          ;; now find out where the line starts and leave point there.
8509          (beg (progn (beginning-of-line) (point)))
8510          (article (gnus-summary-article-number))
8511          (score (or (cdr (assq (or article gnus-current-article)
8512                                gnus-newsgroup-scored))
8513                     gnus-summary-default-score 0))
8514          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
8515          (inhibit-read-only t))
8516     ;; Eval the cars of the lists until we find a match.
8517     (let ((default gnus-summary-default-score))
8518       (while (and list
8519                   (not (eval (caar list))))
8520         (setq list (cdr list))))
8521     (let ((face (cdar list)))
8522       (unless (eq face (get-text-property beg 'face))
8523         (gnus-put-text-property 
8524          beg end 'face 
8525          (setq face (if (boundp face) (symbol-value face) face)))
8526         (when gnus-summary-highlight-line-function
8527           (funcall gnus-summary-highlight-line-function article face))))
8528     (goto-char p)))
8529
8530 (defun gnus-update-read-articles (group unread)
8531   "Update the list of read articles in GROUP."
8532   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
8533          (entry (gnus-gethash group gnus-newsrc-hashtb))
8534          (info (nth 2 entry))
8535          (prev 1)
8536          (unread (sort (copy-sequence unread) '<))
8537          read)
8538     (if (or (not info) (not active))
8539         ;; There is no info on this group if it was, in fact,
8540         ;; killed.  Gnus stores no information on killed groups, so
8541         ;; there's nothing to be done.
8542         ;; One could store the information somewhere temporarily,
8543         ;; perhaps...  Hmmm...
8544         ()
8545       ;; Remove any negative articles numbers.
8546       (while (and unread (< (car unread) 0))
8547         (setq unread (cdr unread)))
8548       ;; Remove any expired article numbers
8549       (while (and unread (< (car unread) (car active)))
8550         (setq unread (cdr unread)))
8551       ;; Compute the ranges of read articles by looking at the list of
8552       ;; unread articles.
8553       (while unread
8554         (when (/= (car unread) prev)
8555           (push (if (= prev (1- (car unread))) prev
8556                   (cons prev (1- (car unread))))
8557                 read))
8558         (setq prev (1+ (car unread)))
8559         (setq unread (cdr unread)))
8560       (when (<= prev (cdr active))
8561         (push (cons prev (cdr active)) read))
8562       (save-excursion
8563         (set-buffer gnus-group-buffer)
8564         (gnus-undo-register
8565           `(progn
8566              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
8567              (gnus-info-set-read ',info ',(gnus-info-read info))
8568              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
8569              (gnus-group-update-group ,group t))))
8570       ;; Enter this list into the group info.
8571       (gnus-info-set-read
8572        info (if (> (length read) 1) (nreverse read) read))
8573       ;; Set the number of unread articles in gnus-newsrc-hashtb.
8574       (gnus-get-unread-articles-in-group info (gnus-active group))
8575       t)))
8576
8577 (provide 'gnus-sum)
8578
8579 (run-hooks 'gnus-sum-load-hook)
8580
8581 ;;; gnus-sum.el ends here