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