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