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