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