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