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