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