(gnus-wheel-summary-scroll): Use `event-basic-type' instead of `event-button'
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (require 'cl))
31
32 (require 'gnus)
33 (require 'gnus-group)
34 (require 'gnus-spec)
35 (require 'gnus-range)
36 (require 'gnus-int)
37 (require 'gnus-undo)
38 (require 'gnus-util)
39 (require 'mime-view)
40
41 (eval-when-compile
42   (require 'mime-play)
43   (require 'static))
44
45 (eval-and-compile
46   (autoload 'gnus-cache-articles-in-group "gnus-cache"))
47
48 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
49 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
50
51 (defcustom gnus-kill-summary-on-exit t
52   "*If non-nil, kill the summary buffer when you exit from it.
53 If nil, the summary will become a \"*Dead Summary*\" buffer, and
54 it will be killed sometime later."
55   :group 'gnus-summary-exit
56   :type 'boolean)
57
58 (defcustom gnus-fetch-old-headers nil
59   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
60 If an unread article in the group refers to an older, already read (or
61 just marked as read) article, the old article will not normally be
62 displayed in the Summary buffer.  If this variable is non-nil, Gnus
63 will attempt to grab the headers to the old articles, and thereby
64 build complete threads.  If it has the value `some', only enough
65 headers to connect otherwise loose threads will be displayed.  This
66 variable can also be a number.  In that case, no more than that number
67 of old headers will be fetched.  If it has the value `invisible', all
68 old headers will be fetched, but none will be displayed.
69
70 The server has to support NOV for any of this to work."
71   :group 'gnus-thread
72   :type '(choice (const :tag "off" nil)
73                  (const some)
74                  number
75                  (sexp :menu-tag "other" t)))
76
77 (defcustom gnus-refer-thread-limit 200
78   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
79 If t, fetch all the available old headers."
80   :group 'gnus-thread
81   :type '(choice number
82                  (sexp :menu-tag "other" t)))
83
84 (defcustom gnus-summary-make-false-root 'adopt
85   "*nil means that Gnus won't gather loose threads.
86 If the root of a thread has expired or been read in a previous
87 session, the information necessary to build a complete thread has been
88 lost.  Instead of having many small sub-threads from this original thread
89 scattered all over the summary buffer, Gnus can gather them.
90
91 If non-nil, Gnus will try to gather all loose sub-threads from an
92 original thread into one large thread.
93
94 If this variable is non-nil, it should be one of `none', `adopt',
95 `dummy' or `empty'.
96
97 If this variable is `none', Gnus will not make a false root, but just
98 present the sub-threads after another.
99 If this variable is `dummy', Gnus will create a dummy root that will
100 have all the sub-threads as children.
101 If this variable is `adopt', Gnus will make one of the \"children\"
102 the parent and mark all the step-children as such.
103 If this variable is `empty', the \"children\" are printed with empty
104 subject fields.  (Or rather, they will be printed with a string
105 given by the `gnus-summary-same-subject' variable.)"
106   :group 'gnus-thread
107   :type '(choice (const :tag "off" nil)
108                  (const none)
109                  (const dummy)
110                  (const adopt)
111                  (const empty)))
112
113 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
114   "*A regexp to match subjects to be excluded from loose thread gathering.
115 As loose thread gathering is done on subjects only, that means that
116 there can be many false gatherings performed.  By rooting out certain
117 common subjects, gathering might become saner."
118   :group 'gnus-thread
119   :type 'regexp)
120
121 (defcustom gnus-summary-gather-subject-limit nil
122   "*Maximum length of subject comparisons when gathering loose threads.
123 Use nil to compare full subjects.  Setting this variable to a low
124 number will help gather threads that have been corrupted by
125 newsreaders chopping off subject lines, but it might also mean that
126 unrelated articles that have subject that happen to begin with the
127 same few characters will be incorrectly gathered.
128
129 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
130 comparing subjects."
131   :group 'gnus-thread
132   :type '(choice (const :tag "off" nil)
133                  (const fuzzy)
134                  (sexp :menu-tag "on" t)))
135
136 (defcustom gnus-simplify-subject-functions nil
137   "List of functions taking a string argument that simplify subjects.
138 The functions are applied recursively.
139
140 Useful functions to put in this list include: `gnus-simplify-subject-re',
141 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
142   :group 'gnus-thread
143   :type '(repeat function))
144
145 (defcustom gnus-simplify-ignored-prefixes nil
146   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
147   :group 'gnus-thread
148   :type '(choice (const :tag "off" nil)
149                  regexp))
150
151 (defcustom gnus-build-sparse-threads nil
152   "*If non-nil, fill in the gaps in threads.
153 If `some', only fill in the gaps that are needed to tie loose threads
154 together.  If `more', fill in all leaf nodes that Gnus can find.  If
155 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
156   :group 'gnus-thread
157   :type '(choice (const :tag "off" nil)
158                  (const some)
159                  (const more)
160                  (sexp :menu-tag "all" t)))
161
162 (defcustom gnus-summary-thread-gathering-function
163   'gnus-gather-threads-by-subject
164   "*Function used for gathering loose threads.
165 There are two pre-defined functions: `gnus-gather-threads-by-subject',
166 which only takes Subjects into consideration; and
167 `gnus-gather-threads-by-references', which compared the References
168 headers of the articles to find matches."
169   :group 'gnus-thread
170   :type '(radio (function-item gnus-gather-threads-by-subject)
171                 (function-item gnus-gather-threads-by-references)
172                 (function :tag "other")))
173
174 (defcustom gnus-summary-same-subject ""
175   "*String indicating that the current article has the same subject as the previous.
176 This variable will only be used if the value of
177 `gnus-summary-make-false-root' is `empty'."
178   :group 'gnus-summary-format
179   :type 'string)
180
181 (defcustom gnus-summary-goto-unread t
182   "*If t, marking commands will go to the next unread article.
183 If `never', commands that usually go to the next unread article, will
184 go to the next article, whether it is read or not.
185 If nil, only the marking commands will go to the next (un)read article."
186   :group 'gnus-summary-marks
187   :link '(custom-manual "(gnus)Setting Marks")
188   :type '(choice (const :tag "off" nil)
189                  (const never)
190                  (sexp :menu-tag "on" t)))
191
192 (defcustom gnus-summary-default-score 0
193   "*Default article score level.
194 All scores generated by the score files will be added to this score.
195 If this variable is nil, scoring will be disabled."
196   :group 'gnus-score-default
197   :type '(choice (const :tag "disable")
198                  integer))
199
200 (defcustom gnus-summary-zcore-fuzz 0
201   "*Fuzziness factor for the zcore in the summary buffer.
202 Articles with scores closer than this to `gnus-summary-default-score'
203 will not be marked."
204   :group 'gnus-summary-format
205   :type 'integer)
206
207 (defcustom gnus-simplify-subject-fuzzy-regexp nil
208   "*Strings to be removed when doing fuzzy matches.
209 This can either be a regular expression or list of regular expressions
210 that will be removed from subject strings if fuzzy subject
211 simplification is selected."
212   :group 'gnus-thread
213   :type '(repeat regexp))
214
215 (defcustom gnus-show-threads t
216   "*If non-nil, display threads in summary mode."
217   :group 'gnus-thread
218   :type 'boolean)
219
220 (defcustom gnus-thread-hide-subtree nil
221   "*If non-nil, hide all threads initially.
222 If threads are hidden, you have to run the command
223 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
224 to expose hidden threads."
225   :group 'gnus-thread
226   :type 'boolean)
227
228 (defcustom gnus-thread-hide-killed t
229   "*If non-nil, hide killed threads automatically."
230   :group 'gnus-thread
231   :type 'boolean)
232
233 (defcustom gnus-thread-ignore-subject t
234   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
235 If nil, articles that have different subjects from their parents will
236 start separate threads."
237   :group 'gnus-thread
238   :type 'boolean)
239
240 (defcustom gnus-thread-operation-ignore-subject t
241   "*If non-nil, subjects will be ignored when doing thread commands.
242 This affects commands like `gnus-summary-kill-thread' and
243 `gnus-summary-lower-thread'.
244
245 If this variable is nil, articles in the same thread with different
246 subjects will not be included in the operation in question.  If this
247 variable is `fuzzy', only articles that have subjects that are fuzzily
248 equal will be included."
249   :group 'gnus-thread
250   :type '(choice (const :tag "off" nil)
251                  (const fuzzy)
252                  (sexp :tag "on" t)))
253
254 (defcustom gnus-thread-indent-level 4
255   "*Number that says how much each sub-thread should be indented."
256   :group 'gnus-thread
257   :type 'integer)
258
259 (defcustom gnus-auto-extend-newsgroup t
260   "*If non-nil, extend newsgroup forward and backward when requested."
261   :group 'gnus-summary-choose
262   :type 'boolean)
263
264 (defcustom gnus-auto-select-first t
265   "*If nil, don't select the first unread article when entering a group.
266 If this variable is `best', select the highest-scored unread article
267 in the group.  If t, select the first unread article.
268
269 This variable can also be a function to place point on a likely
270 subject line.  Useful values include `gnus-summary-first-unread-subject',
271 `gnus-summary-first-unread-article' and
272 `gnus-summary-best-unread-article'.
273
274 If you want to prevent automatic selection of the first unread article
275 in some newsgroups, set the variable to nil in
276 `gnus-select-group-hook'."
277   :group 'gnus-group-select
278   :type '(choice (const :tag "none" nil)
279                  (const best)
280                  (sexp :menu-tag "first" t)
281                  (function-item gnus-summary-first-unread-subject)
282                  (function-item gnus-summary-first-unread-article)
283                  (function-item gnus-summary-best-unread-article)))
284
285 (defcustom gnus-dont-select-after-jump-to-other-group nil
286   "If non-nil, don't select the first unread article after entering the
287 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
288 it is depend on the value of `gnus-auto-select-first' whether to select
289 or not."
290   :group 'gnus-group-select
291   :type 'boolean)
292
293 (defcustom gnus-auto-select-next t
294   "*If non-nil, offer to go to the next group from the end of the previous.
295 If the value is t and the next newsgroup is empty, Gnus will exit
296 summary mode and go back to group mode.  If the value is neither nil
297 nor t, Gnus will select the following unread newsgroup.  In
298 particular, if the value is the symbol `quietly', the next unread
299 newsgroup will be selected without any confirmation, and if it is
300 `almost-quietly', the next group will be selected without any
301 confirmation if you are located on the last article in the group.
302 Finally, if this variable is `slightly-quietly', the `Z n' command
303 will go to the next group without confirmation."
304   :group 'gnus-summary-maneuvering
305   :type '(choice (const :tag "off" nil)
306                  (const quietly)
307                  (const almost-quietly)
308                  (const slightly-quietly)
309                  (sexp :menu-tag "on" t)))
310
311 (defcustom gnus-auto-select-same nil
312   "*If non-nil, select the next article with the same subject.
313 If there are no more articles with the same subject, go to
314 the first unread article."
315   :group 'gnus-summary-maneuvering
316   :type 'boolean)
317
318 (defcustom gnus-summary-check-current nil
319   "*If non-nil, consider the current article when moving.
320 The \"unread\" movement commands will stay on the same line if the
321 current article is unread."
322   :group 'gnus-summary-maneuvering
323   :type 'boolean)
324
325 (defcustom gnus-auto-center-summary t
326   "*If non-nil, always center the current summary buffer.
327 In particular, if `vertical' do only vertical recentering.  If non-nil
328 and non-`vertical', do both horizontal and vertical recentering."
329   :group 'gnus-summary-maneuvering
330   :type '(choice (const :tag "none" nil)
331                  (const vertical)
332                  (integer :tag "height")
333                  (sexp :menu-tag "both" t)))
334
335 (defcustom gnus-show-all-headers nil
336   "*If non-nil, don't hide any headers."
337   :group 'gnus-article-hiding
338   :group 'gnus-article-headers
339   :type 'boolean)
340
341 (defcustom gnus-summary-ignore-duplicates nil
342   "*If non-nil, ignore articles with identical Message-ID headers."
343   :group 'gnus-summary
344   :type 'boolean)
345
346 (defcustom gnus-single-article-buffer t
347   "*If non-nil, display all articles in the same buffer.
348 If nil, each group will get its own article buffer."
349   :group 'gnus-article-various
350   :type 'boolean)
351
352 (defcustom gnus-break-pages t
353   "*If non-nil, do page breaking on articles.
354 The page delimiter is specified by the `gnus-page-delimiter'
355 variable."
356   :group 'gnus-article-various
357   :type 'boolean)
358
359 (defcustom gnus-show-mime t
360   "*If non-nil, do mime processing of articles.
361 The articles will simply be fed to the function given by
362 `gnus-article-display-method-for-mime'."
363   :group 'gnus-article-mime
364   :type 'boolean)
365
366 (defcustom gnus-move-split-methods nil
367   "*Variable used to suggest where articles are to be moved to.
368 It uses the same syntax as the `gnus-split-methods' variable."
369   :group 'gnus-summary-mail
370   :type '(repeat (choice (list :value (fun) function)
371                          (cons :value ("" "") regexp (repeat string))
372                          (sexp :value nil))))
373
374 (defcustom gnus-unread-mark ? ;Whitespace
375   "*Mark used for unread articles."
376   :group 'gnus-summary-marks
377   :type 'character)
378
379 (defcustom gnus-ticked-mark ?!
380   "*Mark used for ticked articles."
381   :group 'gnus-summary-marks
382   :type 'character)
383
384 (defcustom gnus-dormant-mark ??
385   "*Mark used for dormant articles."
386   :group 'gnus-summary-marks
387   :type 'character)
388
389 (defcustom gnus-del-mark ?r
390   "*Mark used for del'd articles."
391   :group 'gnus-summary-marks
392   :type 'character)
393
394 (defcustom gnus-read-mark ?R
395   "*Mark used for read articles."
396   :group 'gnus-summary-marks
397   :type 'character)
398
399 (defcustom gnus-expirable-mark ?E
400   "*Mark used for expirable articles."
401   :group 'gnus-summary-marks
402   :type 'character)
403
404 (defcustom gnus-killed-mark ?K
405   "*Mark used for killed articles."
406   :group 'gnus-summary-marks
407   :type 'character)
408
409 (defcustom gnus-souped-mark ?F
410   "*Mark used for killed articles."
411   :group 'gnus-summary-marks
412   :type 'character)
413
414 (defcustom gnus-kill-file-mark ?X
415   "*Mark used for articles killed by kill files."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-low-score-mark ?Y
420   "*Mark used for articles with a low score."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-catchup-mark ?C
425   "*Mark used for articles that are caught up."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-replied-mark ?A
430   "*Mark used for articles that have been replied to."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-cached-mark ?*
435   "*Mark used for articles that are in the cache."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-saved-mark ?S
440   "*Mark used for articles that have been saved to."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-ancient-mark ?O
445   "*Mark used for ancient articles."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-sparse-mark ?Q
450   "*Mark used for sparsely reffed articles."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-canceled-mark ?G
455   "*Mark used for canceled articles."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-duplicate-mark ?M
460   "*Mark used for duplicate articles."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-undownloaded-mark ?@
465   "*Mark used for articles that weren't downloaded."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-downloadable-mark ?%
470   "*Mark used for articles that are to be downloaded."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-unsendable-mark ?=
475   "*Mark used for articles that won't be sent."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-score-over-mark ?+
480   "*Score mark used for articles with high scores."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-score-below-mark ?-
485   "*Score mark used for articles with low scores."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-empty-thread-mark ? ;Whitespace
490   "*There is no thread under the article."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-not-empty-thread-mark ?=
495   "*There is a thread under the article."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-view-pseudo-asynchronously nil
500   "*If non-nil, Gnus will view pseudo-articles asynchronously."
501   :group 'gnus-extract-view
502   :type 'boolean)
503
504 (defcustom gnus-auto-expirable-marks
505   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
506         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
507         gnus-souped-mark gnus-duplicate-mark)
508   "*The list of marks converted into expiration if a group is auto-expirable."
509   :group 'gnus-summary
510   :type '(repeat character))
511
512 (defcustom gnus-inhibit-user-auto-expire t
513   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
514   :group 'gnus-summary
515   :type 'boolean)
516
517 (defcustom gnus-view-pseudos nil
518   "*If `automatic', pseudo-articles will be viewed automatically.
519 If `not-confirm', pseudos will be viewed automatically, and the user
520 will not be asked to confirm the command."
521   :group 'gnus-extract-view
522   :type '(choice (const :tag "off" nil)
523                  (const automatic)
524                  (const not-confirm)))
525
526 (defcustom gnus-view-pseudos-separately t
527   "*If non-nil, one pseudo-article will be created for each file to be viewed.
528 If nil, all files that use the same viewing command will be given as a
529 list of parameters to that command."
530   :group 'gnus-extract-view
531   :type 'boolean)
532
533 (defcustom gnus-insert-pseudo-articles t
534   "*If non-nil, insert pseudo-articles when decoding articles."
535   :group 'gnus-extract-view
536   :type 'boolean)
537
538 (defcustom gnus-summary-dummy-line-format
539   "  %(:                          :%) %S\n"
540   "*The format specification for the dummy roots in the summary buffer.
541 It works along the same lines as a normal formatting string,
542 with some simple extensions.
543
544 %S  The subject"
545   :group 'gnus-threading
546   :type 'string)
547
548 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
549   "*The format specification for the summary mode line.
550 It works along the same lines as a normal formatting string,
551 with some simple extensions:
552
553 %G  Group name
554 %p  Unprefixed group name
555 %A  Current article number
556 %z  Current article score
557 %V  Gnus version
558 %U  Number of unread articles in the group
559 %e  Number of unselected articles in the group
560 %Z  A string with unread/unselected article counts
561 %g  Shortish group name
562 %S  Subject of the current article
563 %u  User-defined spec
564 %s  Current score file name
565 %d  Number of dormant articles
566 %r  Number of articles that have been marked as read in this session
567 %E  Number of articles expunged by the score files"
568   :group 'gnus-summary-format
569   :type 'string)
570
571 (defcustom gnus-summary-mark-below 0
572   "*Mark all articles with a score below this variable as read.
573 This variable is local to each summary buffer and usually set by the
574 score file."
575   :group 'gnus-score-default
576   :type 'integer)
577
578 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
579   "*List of functions used for sorting articles in the summary buffer.
580 This variable is only used when not using a threaded display."
581   :group 'gnus-summary-sort
582   :type '(repeat (choice (function-item gnus-article-sort-by-number)
583                          (function-item gnus-article-sort-by-author)
584                          (function-item gnus-article-sort-by-subject)
585                          (function-item gnus-article-sort-by-date)
586                          (function-item gnus-article-sort-by-score)
587                          (function :tag "other"))))
588
589 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
590   "*List of functions used for sorting threads in the summary buffer.
591 By default, threads are sorted by article number.
592
593 Each function takes two threads and return non-nil if the first thread
594 should be sorted before the other.  If you use more than one function,
595 the primary sort function should be the last.  You should probably
596 always include `gnus-thread-sort-by-number' in the list of sorting
597 functions -- preferably first.
598
599 Ready-made functions include `gnus-thread-sort-by-number',
600 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
601 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
602 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
603   :group 'gnus-summary-sort
604   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
605                          (function-item gnus-thread-sort-by-author)
606                          (function-item gnus-thread-sort-by-subject)
607                          (function-item gnus-thread-sort-by-date)
608                          (function-item gnus-thread-sort-by-score)
609                          (function-item gnus-thread-sort-by-total-score)
610                          (function :tag "other"))))
611
612 (defcustom gnus-thread-score-function '+
613   "*Function used for calculating the total score of a thread.
614
615 The function is called with the scores of the article and each
616 subthread and should then return the score of the thread.
617
618 Some functions you can use are `+', `max', or `min'."
619   :group 'gnus-summary-sort
620   :type 'function)
621
622 (defcustom gnus-summary-expunge-below nil
623   "All articles that have a score less than this variable will be expunged.
624 This variable is local to the summary buffers."
625   :group 'gnus-score-default
626   :type '(choice (const :tag "off" nil)
627                  integer))
628
629 (defcustom gnus-thread-expunge-below nil
630   "All threads that have a total score less than this variable will be expunged.
631 See `gnus-thread-score-function' for en explanation of what a
632 \"thread score\" is.
633
634 This variable is local to the summary buffers."
635   :group 'gnus-threading
636   :group 'gnus-score-default
637   :type '(choice (const :tag "off" nil)
638                  integer))
639
640 (defcustom gnus-summary-mode-hook nil
641   "*A hook for Gnus summary mode.
642 This hook is run before any variables are set in the summary buffer."
643   :group 'gnus-summary-various
644   :type 'hook)
645
646 (defcustom gnus-summary-menu-hook nil
647   "*Hook run after the creation of the summary mode menu."
648   :group 'gnus-summary-visual
649   :type 'hook)
650
651 (defcustom gnus-summary-exit-hook nil
652   "*A hook called on exit from the summary buffer.
653 It will be called with point in the group buffer."
654   :group 'gnus-summary-exit
655   :type 'hook)
656
657 (defcustom gnus-summary-prepare-hook nil
658   "*A hook called after the summary buffer has been generated.
659 If you want to modify the summary buffer, you can use this hook."
660   :group 'gnus-summary-various
661   :type 'hook)
662
663 (defcustom gnus-summary-prepared-hook nil
664   "*A hook called as the last thing after the summary buffer has been generated."
665   :group 'gnus-summary-various
666   :type 'hook)
667
668 (defcustom gnus-summary-generate-hook nil
669   "*A hook run just before generating the summary buffer.
670 This hook is commonly used to customize threading variables and the
671 like."
672   :group 'gnus-summary-various
673   :type 'hook)
674
675 (defcustom gnus-select-group-hook nil
676   "*A hook called when a newsgroup is selected.
677
678 If you'd like to simplify subjects like the
679 `gnus-summary-next-same-subject' command does, you can use the
680 following hook:
681
682  (setq gnus-select-group-hook
683       (list
684         (lambda ()
685           (mapcar (lambda (header)
686                      (mail-header-set-subject
687                       header
688                       (gnus-simplify-subject
689                        (mail-header-subject header) 're-only)))
690                   gnus-newsgroup-headers))))"
691   :group 'gnus-group-select
692   :type 'hook)
693
694 (defcustom gnus-select-article-hook nil
695   "*A hook called when an article is selected."
696   :group 'gnus-summary-choose
697   :type 'hook)
698
699 (defcustom gnus-visual-mark-article-hook
700   (list 'gnus-highlight-selected-summary)
701   "*Hook run after selecting an article in the summary buffer.
702 It is meant to be used for highlighting the article in some way.  It
703 is not run if `gnus-visual' is nil."
704   :group 'gnus-summary-visual
705   :type 'hook)
706
707 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
708   "*A hook called before parsing the headers."
709   :group 'gnus-various
710   :type 'hook)
711
712 (defcustom gnus-exit-group-hook nil
713   "*A hook called when exiting (not quitting) summary mode."
714   :group 'gnus-various
715   :type 'hook)
716
717 (defcustom gnus-summary-update-hook
718   (list 'gnus-summary-highlight-line)
719   "*A hook called when a summary line is changed.
720 The hook will not be called if `gnus-visual' is nil.
721
722 The default function `gnus-summary-highlight-line' will
723 highlight the line according to the `gnus-summary-highlight'
724 variable."
725   :group 'gnus-summary-visual
726   :type 'hook)
727
728 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
729   "*A hook called when an article is selected for the first time.
730 The hook is intended to mark an article as read (or unread)
731 automatically when it is selected."
732   :group 'gnus-summary-choose
733   :type 'hook)
734
735 (defcustom gnus-group-no-more-groups-hook nil
736   "*A hook run when returning to group mode having no more (unread) groups."
737   :group 'gnus-group-select
738   :type 'hook)
739
740 (defcustom gnus-ps-print-hook nil
741   "*A hook run before ps-printing something from Gnus."
742   :group 'gnus-summary
743   :type 'hook)
744
745 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
746   "Face used for highlighting the current article in the summary buffer."
747   :group 'gnus-summary-visual
748   :type 'face)
749
750 (defcustom gnus-summary-highlight
751   '(((= mark gnus-canceled-mark)
752      . gnus-summary-cancelled-face)
753     ((and (> score default)
754           (or (= mark gnus-dormant-mark)
755               (= mark gnus-ticked-mark)))
756      . gnus-summary-high-ticked-face)
757     ((and (< score default)
758           (or (= mark gnus-dormant-mark)
759               (= mark gnus-ticked-mark)))
760      . gnus-summary-low-ticked-face)
761     ((or (= mark gnus-dormant-mark)
762          (= mark gnus-ticked-mark))
763      . gnus-summary-normal-ticked-face)
764     ((and (> score default) (= mark gnus-ancient-mark))
765      . gnus-summary-high-ancient-face)
766     ((and (< score default) (= mark gnus-ancient-mark))
767      . gnus-summary-low-ancient-face)
768     ((= mark gnus-ancient-mark)
769      . gnus-summary-normal-ancient-face)
770     ((and (> score default) (= mark gnus-unread-mark))
771      . gnus-summary-high-unread-face)
772     ((and (< score default) (= mark gnus-unread-mark))
773      . gnus-summary-low-unread-face)
774     ((= mark gnus-unread-mark)
775      . gnus-summary-normal-unread-face)
776     ((and (> score default) (memq mark (list gnus-downloadable-mark
777                                              gnus-undownloaded-mark)))
778      . gnus-summary-high-unread-face)
779     ((and (< score default) (memq mark (list gnus-downloadable-mark
780                                              gnus-undownloaded-mark)))
781      . gnus-summary-low-unread-face)
782     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
783      . gnus-summary-normal-unread-face)
784     ((> score default)
785      . gnus-summary-high-read-face)
786     ((< score default)
787      . gnus-summary-low-read-face)
788     (t
789      . gnus-summary-normal-read-face))
790   "*Controls the highlighting of summary buffer lines.
791
792 A list of (FORM . FACE) pairs.  When deciding how a a particular
793 summary line should be displayed, each form is evaluated.  The content
794 of the face field after the first true form is used.  You can change
795 how those summary lines are displayed, by editing the face field.
796
797 You can use the following variables in the FORM field.
798
799 score:   The articles score
800 default: The default article score.
801 below:   The score below which articles are automatically marked as read.
802 mark:    The articles mark."
803   :group 'gnus-summary-visual
804   :type '(repeat (cons (sexp :tag "Form" nil)
805                        face)))
806
807 (defcustom gnus-alter-header-function nil
808   "Function called to allow alteration of article header structures.
809 The function is called with one parameter, the article header vector,
810 which it may alter in any way.")
811
812 (defvar gnus-decode-encoded-word-function
813   (mime-find-field-decoder 'From 'nov)
814   "Variable that says which function should be used to decode a string with encoded words.")
815
816 (defcustom gnus-extra-headers nil
817   "*Extra headers to parse."
818   :group 'gnus-summary
819   :type '(repeat symbol))
820
821 (defcustom gnus-ignored-from-addresses
822   (and user-mail-address (regexp-quote user-mail-address))
823   "*Regexp of From headers that may be suppressed in favor of To headers."
824   :group 'gnus-summary
825   :type 'regexp)
826
827 (defcustom gnus-group-charset-alist
828   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
829     ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
830     ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
831     ("^relcom\\>" koi8-r)
832     ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
833     ("^israel\\>" iso-8859-1)
834     ("^han\\>" euc-kr)
835     ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
836     (".*" iso-8859-1))
837   "Alist of regexps (to match group names) and default charsets to be used when reading."
838   :type '(repeat (list (regexp :tag "Group")
839                        (symbol :tag "Charset")))
840   :group 'gnus-charset)
841
842 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit)
843   "List of charsets that should be ignored.
844 When these charsets are used in the \"charset\" parameter, the
845 default charset will be used instead."
846   :type '(repeat symbol)
847   :group 'gnus-charset)
848
849 (defcustom gnus-group-ignored-charsets-alist 
850   '(("alt\\.chinese\\.text" iso-8859-1))
851   "Alist of regexps (to match group names) and charsets that should be ignored.
852 When these charsets are used in the \"charset\" parameter, the
853 default charset will be used instead."
854   :type '(repeat (cons (regexp :tag "Group")
855                        (repeat symbol)))
856   :group 'gnus-charset)
857
858 (defcustom gnus-group-highlight-words-alist nil
859   "Alist of group regexps and highlight regexps.
860 This variable uses the same syntax as `gnus-emphasis-alist'."
861   :type '(repeat (cons (regexp :tag "Group")
862                        (repeat (list (regexp :tag "Highlight regexp")
863                                      (number :tag "Group for entire word" 0)
864                                      (number :tag "Group for displayed part" 0)
865                                      (symbol :tag "Face" 
866                                              gnus-emphasis-highlight-words)))))
867   :group 'gnus-summary-visual)
868
869 (defcustom gnus-use-wheel nil
870   "Use Intelli-mouse on summary movement"
871   :type 'boolean
872   :group 'gnus-summary-maneuvering)
873
874 (defcustom gnus-wheel-scroll-amount '(5 . 1)
875   "Amount to scroll messages by spinning the mouse wheel.
876 This is actually a cons cell, where the first item is the amount to scroll
877 on a normal wheel event, and the second is the amount to scroll when the
878 wheel is moved with the shift key depressed."
879   :type '(cons (integer :tag "Shift") integer)
880   :group 'gnus-summary-maneuvering)
881
882 (defcustom gnus-wheel-edge-resistance 2
883   "How hard it should be to change the current article
884 by moving the mouse over the edge of the article window."
885   :type 'integer
886   :group 'gnus-summary-maneuvering)
887
888 ;;; Internal variables
889
890 (defvar gnus-scores-exclude-files nil)
891 (defvar gnus-page-broken nil)
892 (defvar gnus-inhibit-mime-unbuttonizing nil)
893
894 (defvar gnus-original-article nil)
895 (defvar gnus-article-internal-prepare-hook nil)
896 (defvar gnus-newsgroup-process-stack nil)
897
898 (defvar gnus-thread-indent-array nil)
899 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
900
901 ;; Avoid highlighting in kill files.
902 (defvar gnus-summary-inhibit-highlight nil)
903 (defvar gnus-newsgroup-selected-overlay nil)
904 (defvar gnus-inhibit-limiting nil)
905 (defvar gnus-newsgroup-adaptive-score-file nil)
906 (defvar gnus-current-score-file nil)
907 (defvar gnus-current-move-group nil)
908 (defvar gnus-current-copy-group nil)
909 (defvar gnus-current-crosspost-group nil)
910
911 (defvar gnus-newsgroup-dependencies nil)
912 (defvar gnus-newsgroup-adaptive nil)
913 (defvar gnus-summary-display-article-function nil)
914 (defvar gnus-summary-highlight-line-function nil
915   "Function called after highlighting a summary line.")
916
917 (defvar gnus-summary-line-format-alist
918   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
919     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
920     (?s gnus-tmp-subject-or-nil ?s)
921     (?n gnus-tmp-name ?s)
922     (?A (std11-address-string
923          (car (mime-read-field 'From gnus-tmp-header))) ?s)
924     (?a (or (std11-full-name-string
925              (car (mime-read-field 'From gnus-tmp-header)))
926             gnus-tmp-from) ?s)
927     (?F gnus-tmp-from ?s)
928     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
929     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
930     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
931     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
932     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
933     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
934     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
935     (?L gnus-tmp-lines ?d)
936     (?I gnus-tmp-indentation ?s)
937     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
938     (?R gnus-tmp-replied ?c)
939     (?\[ gnus-tmp-opening-bracket ?c)
940     (?\] gnus-tmp-closing-bracket ?c)
941     (?\> (make-string gnus-tmp-level ? ) ?s)
942     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
943     (?i gnus-tmp-score ?d)
944     (?z gnus-tmp-score-char ?c)
945     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
946     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
947     (?U gnus-tmp-unread ?c)
948     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
949     (?t (gnus-summary-number-of-articles-in-thread
950          (and (boundp 'thread) (car thread)) gnus-tmp-level)
951         ?d)
952     (?e (gnus-summary-number-of-articles-in-thread
953          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
954         ?c)
955     (?u gnus-tmp-user-defined ?s)
956     (?P (gnus-pick-line-number) ?d))
957   "An alist of format specifications that can appear in summary lines,
958 and what variables they correspond with, along with the type of the
959 variable (string, integer, character, etc).")
960
961 (defvar gnus-summary-dummy-line-format-alist
962   `((?S gnus-tmp-subject ?s)
963     (?N gnus-tmp-number ?d)
964     (?u gnus-tmp-user-defined ?s)))
965
966 (defvar gnus-summary-mode-line-format-alist
967   `((?G gnus-tmp-group-name ?s)
968     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
969     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
970     (?A gnus-tmp-article-number ?d)
971     (?Z gnus-tmp-unread-and-unselected ?s)
972     (?V gnus-version ?s)
973     (?U gnus-tmp-unread-and-unticked ?d)
974     (?S gnus-tmp-subject ?s)
975     (?e gnus-tmp-unselected ?d)
976     (?u gnus-tmp-user-defined ?s)
977     (?d (length gnus-newsgroup-dormant) ?d)
978     (?t (length gnus-newsgroup-marked) ?d)
979     (?r (length gnus-newsgroup-reads) ?d)
980     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
981     (?E gnus-newsgroup-expunged-tally ?d)
982     (?s (gnus-current-score-file-nondirectory) ?s)))
983
984 (defvar gnus-last-search-regexp nil
985   "Default regexp for article search command.")
986
987 (defvar gnus-last-shell-command nil
988   "Default shell command on article.")
989
990 (defvar gnus-newsgroup-begin nil)
991 (defvar gnus-newsgroup-end nil)
992 (defvar gnus-newsgroup-last-rmail nil)
993 (defvar gnus-newsgroup-last-mail nil)
994 (defvar gnus-newsgroup-last-folder nil)
995 (defvar gnus-newsgroup-last-file nil)
996 (defvar gnus-newsgroup-auto-expire nil)
997 (defvar gnus-newsgroup-active nil)
998
999 (defvar gnus-newsgroup-data nil)
1000 (defvar gnus-newsgroup-data-reverse nil)
1001 (defvar gnus-newsgroup-limit nil)
1002 (defvar gnus-newsgroup-limits nil)
1003
1004 (defvar gnus-newsgroup-unreads nil
1005   "List of unread articles in the current newsgroup.")
1006
1007 (defvar gnus-newsgroup-unselected nil
1008   "List of unselected unread articles in the current newsgroup.")
1009
1010 (defvar gnus-newsgroup-reads nil
1011   "Alist of read articles and article marks in the current newsgroup.")
1012
1013 (defvar gnus-newsgroup-expunged-tally nil)
1014
1015 (defvar gnus-newsgroup-marked nil
1016   "List of ticked articles in the current newsgroup (a subset of unread art).")
1017
1018 (defvar gnus-newsgroup-killed nil
1019   "List of ranges of articles that have been through the scoring process.")
1020
1021 (defvar gnus-newsgroup-cached nil
1022   "List of articles that come from the article cache.")
1023
1024 (defvar gnus-newsgroup-saved nil
1025   "List of articles that have been saved.")
1026
1027 (defvar gnus-newsgroup-kill-headers nil)
1028
1029 (defvar gnus-newsgroup-replied nil
1030   "List of articles that have been replied to in the current newsgroup.")
1031
1032 (defvar gnus-newsgroup-expirable nil
1033   "List of articles in the current newsgroup that can be expired.")
1034
1035 (defvar gnus-newsgroup-processable nil
1036   "List of articles in the current newsgroup that can be processed.")
1037
1038 (defvar gnus-newsgroup-downloadable nil
1039   "List of articles in the current newsgroup that can be processed.")
1040
1041 (defvar gnus-newsgroup-undownloaded nil
1042   "List of articles in the current newsgroup that haven't been downloaded..")
1043
1044 (defvar gnus-newsgroup-unsendable nil
1045   "List of articles in the current newsgroup that won't be sent.")
1046
1047 (defvar gnus-newsgroup-bookmarks nil
1048   "List of articles in the current newsgroup that have bookmarks.")
1049
1050 (defvar gnus-newsgroup-dormant nil
1051   "List of dormant articles in the current newsgroup.")
1052
1053 (defvar gnus-newsgroup-scored nil
1054   "List of scored articles in the current newsgroup.")
1055
1056 (defvar gnus-newsgroup-headers nil
1057   "List of article headers in the current newsgroup.")
1058
1059 (defvar gnus-newsgroup-threads nil)
1060
1061 (defvar gnus-newsgroup-prepared nil
1062   "Whether the current group has been prepared properly.")
1063
1064 (defvar gnus-newsgroup-ancient nil
1065   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1066
1067 (defvar gnus-newsgroup-sparse nil)
1068
1069 (defvar gnus-current-article nil)
1070 (defvar gnus-article-current nil)
1071 (defvar gnus-current-headers nil)
1072 (defvar gnus-have-all-headers nil)
1073 (defvar gnus-last-article nil)
1074 (defvar gnus-newsgroup-history nil)
1075 (defvar gnus-newsgroup-charset nil)
1076 (defvar gnus-newsgroup-ephemeral-charset nil)
1077 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1078
1079 (defconst gnus-summary-local-variables
1080   '(gnus-newsgroup-name
1081     gnus-newsgroup-begin gnus-newsgroup-end
1082     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1083     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1084     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1085     gnus-newsgroup-unselected gnus-newsgroup-marked
1086     gnus-newsgroup-reads gnus-newsgroup-saved
1087     gnus-newsgroup-replied gnus-newsgroup-expirable
1088     gnus-newsgroup-processable gnus-newsgroup-killed
1089     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1090     gnus-newsgroup-unsendable
1091     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1092     gnus-newsgroup-headers gnus-newsgroup-threads
1093     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1094     gnus-current-article gnus-current-headers gnus-have-all-headers
1095     gnus-last-article gnus-article-internal-prepare-hook
1096     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1097     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1098     gnus-thread-expunge-below
1099     gnus-score-alist gnus-current-score-file
1100     (gnus-summary-expunge-below . global)
1101     (gnus-summary-mark-below . global)
1102     gnus-newsgroup-active gnus-scores-exclude-files
1103     gnus-newsgroup-history gnus-newsgroup-ancient
1104     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1105     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1106     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1107     (gnus-newsgroup-expunged-tally . 0)
1108     gnus-cache-removable-articles gnus-newsgroup-cached
1109     gnus-newsgroup-data gnus-newsgroup-data-reverse
1110     gnus-newsgroup-limit gnus-newsgroup-limits
1111     gnus-newsgroup-charset)
1112   "Variables that are buffer-local to the summary buffers.")
1113
1114 ;; Byte-compiler warning.
1115 (defvar gnus-article-mode-map)
1116
1117 ;; Subject simplification.
1118
1119 (defun gnus-simplify-whitespace (str)
1120   "Remove excessive whitespace."
1121   (let ((mystr str))
1122     ;; Multiple spaces.
1123     (while (string-match "[ \t][ \t]+" mystr)
1124       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1125                           " "
1126                           (substring mystr (match-end 0)))))
1127     ;; Leading spaces.
1128     (when (string-match "^[ \t]+" mystr)
1129       (setq mystr (substring mystr (match-end 0))))
1130     ;; Trailing spaces.
1131     (when (string-match "[ \t]+$" mystr)
1132       (setq mystr (substring mystr 0 (match-beginning 0))))
1133     mystr))
1134
1135 (defsubst gnus-simplify-subject-re (subject)
1136   "Remove \"Re:\" from subject lines."
1137   (if (string-match "^[Rr][Ee]: *" subject)
1138       (substring subject (match-end 0))
1139     subject))
1140
1141 (defun gnus-simplify-subject (subject &optional re-only)
1142   "Remove `Re:' and words in parentheses.
1143 If RE-ONLY is non-nil, strip leading `Re:'s only."
1144   (let ((case-fold-search t))           ;Ignore case.
1145     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1146     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1147       (setq subject (substring subject (match-end 0))))
1148     ;; Remove uninteresting prefixes.
1149     (when (and (not re-only)
1150                gnus-simplify-ignored-prefixes
1151                (string-match gnus-simplify-ignored-prefixes subject))
1152       (setq subject (substring subject (match-end 0))))
1153     ;; Remove words in parentheses from end.
1154     (unless re-only
1155       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1156         (setq subject (substring subject 0 (match-beginning 0)))))
1157     ;; Return subject string.
1158     subject))
1159
1160 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1161 ;; all whitespace.
1162 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1163   (goto-char (point-min))
1164   (while (re-search-forward regexp nil t)
1165       (replace-match (or newtext ""))))
1166
1167 (defun gnus-simplify-buffer-fuzzy ()
1168   "Simplify string in the buffer fuzzily.
1169 The string in the accessible portion of the current buffer is simplified.
1170 It is assumed to be a single-line subject.
1171 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1172 matter is removed.  Additional things can be deleted by setting
1173 gnus-simplify-subject-fuzzy-regexp."
1174   (let ((case-fold-search t)
1175         (modified-tick))
1176     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1177
1178     (while (not (eq modified-tick (buffer-modified-tick)))
1179       (setq modified-tick (buffer-modified-tick))
1180       (cond
1181        ((listp gnus-simplify-subject-fuzzy-regexp)
1182         (mapcar 'gnus-simplify-buffer-fuzzy-step
1183                 gnus-simplify-subject-fuzzy-regexp))
1184        (gnus-simplify-subject-fuzzy-regexp
1185         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1186       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1187       (gnus-simplify-buffer-fuzzy-step
1188        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1189       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1190
1191     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1192     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1193     (gnus-simplify-buffer-fuzzy-step " $")
1194     (gnus-simplify-buffer-fuzzy-step "^ +")))
1195
1196 (defun gnus-simplify-subject-fuzzy (subject)
1197   "Simplify a subject string fuzzily.
1198 See `gnus-simplify-buffer-fuzzy' for details."
1199   (save-excursion
1200     (gnus-set-work-buffer)
1201     (let ((case-fold-search t))
1202       ;; Remove uninteresting prefixes.
1203       (when (and gnus-simplify-ignored-prefixes
1204                  (string-match gnus-simplify-ignored-prefixes subject))
1205         (setq subject (substring subject (match-end 0))))
1206       (insert subject)
1207       (inline (gnus-simplify-buffer-fuzzy))
1208       (buffer-string))))
1209
1210 (defsubst gnus-simplify-subject-fully (subject)
1211   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1212   (cond
1213    (gnus-simplify-subject-functions
1214     (gnus-map-function gnus-simplify-subject-functions subject))
1215    ((null gnus-summary-gather-subject-limit)
1216     (gnus-simplify-subject-re subject))
1217    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1218     (gnus-simplify-subject-fuzzy subject))
1219    ((numberp gnus-summary-gather-subject-limit)
1220     (gnus-limit-string (gnus-simplify-subject-re subject)
1221                        gnus-summary-gather-subject-limit))
1222    (t
1223     subject)))
1224
1225 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1226   "Check whether two subjects are equal.
1227 If optional argument simple-first is t, first argument is already
1228 simplified."
1229   (cond
1230    ((null simple-first)
1231     (equal (gnus-simplify-subject-fully s1)
1232            (gnus-simplify-subject-fully s2)))
1233    (t
1234     (equal s1
1235            (gnus-simplify-subject-fully s2)))))
1236
1237 (defun gnus-summary-bubble-group ()
1238   "Increase the score of the current group.
1239 This is a handy function to add to `gnus-summary-exit-hook' to
1240 increase the score of each group you read."
1241   (gnus-group-add-score gnus-newsgroup-name))
1242
1243 \f
1244 ;;;
1245 ;;; Gnus summary mode
1246 ;;;
1247
1248 (put 'gnus-summary-mode 'mode-class 'special)
1249
1250 (when t
1251   ;; Non-orthogonal keys
1252
1253   (gnus-define-keys gnus-summary-mode-map
1254     " " gnus-summary-next-page
1255     "\177" gnus-summary-prev-page
1256     [delete] gnus-summary-prev-page
1257     [backspace] gnus-summary-prev-page
1258     "\r" gnus-summary-scroll-up
1259     "\M-\r" gnus-summary-scroll-down
1260     "n" gnus-summary-next-unread-article
1261     "p" gnus-summary-prev-unread-article
1262     "N" gnus-summary-next-article
1263     "P" gnus-summary-prev-article
1264     "\M-\C-n" gnus-summary-next-same-subject
1265     "\M-\C-p" gnus-summary-prev-same-subject
1266     "\M-n" gnus-summary-next-unread-subject
1267     "\M-p" gnus-summary-prev-unread-subject
1268     "." gnus-summary-first-unread-article
1269     "," gnus-summary-best-unread-article
1270     "\M-s" gnus-summary-search-article-forward
1271     "\M-r" gnus-summary-search-article-backward
1272     "<" gnus-summary-beginning-of-article
1273     ">" gnus-summary-end-of-article
1274     "j" gnus-summary-goto-article
1275     "^" gnus-summary-refer-parent-article
1276     "\M-^" gnus-summary-refer-article
1277     "u" gnus-summary-tick-article-forward
1278     "!" gnus-summary-tick-article-forward
1279     "U" gnus-summary-tick-article-backward
1280     "d" gnus-summary-mark-as-read-forward
1281     "D" gnus-summary-mark-as-read-backward
1282     "E" gnus-summary-mark-as-expirable
1283     "\M-u" gnus-summary-clear-mark-forward
1284     "\M-U" gnus-summary-clear-mark-backward
1285     "k" gnus-summary-kill-same-subject-and-select
1286     "\C-k" gnus-summary-kill-same-subject
1287     "\M-\C-k" gnus-summary-kill-thread
1288     "\M-\C-l" gnus-summary-lower-thread
1289     "e" gnus-summary-edit-article
1290     "#" gnus-summary-mark-as-processable
1291     "\M-#" gnus-summary-unmark-as-processable
1292     "\M-\C-t" gnus-summary-toggle-threads
1293     "\M-\C-s" gnus-summary-show-thread
1294     "\M-\C-h" gnus-summary-hide-thread
1295     "\M-\C-f" gnus-summary-next-thread
1296     "\M-\C-b" gnus-summary-prev-thread
1297     "\M-\C-u" gnus-summary-up-thread
1298     "\M-\C-d" gnus-summary-down-thread
1299     "&" gnus-summary-execute-command
1300     "c" gnus-summary-catchup-and-exit
1301     "\C-w" gnus-summary-mark-region-as-read
1302     "\C-t" gnus-summary-toggle-truncation
1303     "?" gnus-summary-mark-as-dormant
1304     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1305     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1306     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1307     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1308     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1309     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1310     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1311     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1312     "=" gnus-summary-expand-window
1313     "\C-x\C-s" gnus-summary-reselect-current-group
1314     "\M-g" gnus-summary-rescan-group
1315     "w" gnus-summary-stop-page-breaking
1316     "\C-c\C-r" gnus-summary-caesar-message
1317     "\M-t" gnus-summary-toggle-mime
1318     "f" gnus-summary-followup
1319     "F" gnus-summary-followup-with-original
1320     "C" gnus-summary-cancel-article
1321     "r" gnus-summary-reply
1322     "R" gnus-summary-reply-with-original
1323     "\C-c\C-f" gnus-summary-mail-forward
1324     "o" gnus-summary-save-article
1325     "\C-o" gnus-summary-save-article-mail
1326     "|" gnus-summary-pipe-output
1327     "\M-k" gnus-summary-edit-local-kill
1328     "\M-K" gnus-summary-edit-global-kill
1329     ;; "V" gnus-version
1330     "\C-c\C-d" gnus-summary-describe-group
1331     "q" gnus-summary-exit
1332     "Q" gnus-summary-exit-no-update
1333     "\C-c\C-i" gnus-info-find-node
1334     gnus-mouse-2 gnus-mouse-pick-article
1335     "m" gnus-summary-mail-other-window
1336     "a" gnus-summary-post-news
1337     "x" gnus-summary-limit-to-unread
1338     "s" gnus-summary-isearch-article
1339     "t" gnus-article-toggle-headers
1340     "g" gnus-summary-show-article
1341     "l" gnus-summary-goto-last-article
1342     "v" gnus-summary-preview-mime-message
1343     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1344     "\C-d" gnus-summary-enter-digest-group
1345     "\M-\C-d" gnus-summary-read-document
1346     "\M-\C-e" gnus-summary-edit-parameters
1347     "\M-\C-g" gnus-summary-customize-parameters
1348     "\C-c\C-b" gnus-bug
1349     "*" gnus-cache-enter-article
1350     "\M-*" gnus-cache-remove-article
1351     "\M-&" gnus-summary-universal-argument
1352     "\C-l" gnus-recenter
1353     "I" gnus-summary-increase-score
1354     "L" gnus-summary-lower-score
1355     "\M-i" gnus-symbolic-argument
1356     "h" gnus-summary-select-article-buffer
1357
1358     "V" gnus-summary-score-map
1359     "X" gnus-uu-extract-map
1360     "S" gnus-summary-send-map)
1361
1362   ;; Sort of orthogonal keymap
1363   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1364     "t" gnus-summary-tick-article-forward
1365     "!" gnus-summary-tick-article-forward
1366     "d" gnus-summary-mark-as-read-forward
1367     "r" gnus-summary-mark-as-read-forward
1368     "c" gnus-summary-clear-mark-forward
1369     " " gnus-summary-clear-mark-forward
1370     "e" gnus-summary-mark-as-expirable
1371     "x" gnus-summary-mark-as-expirable
1372     "?" gnus-summary-mark-as-dormant
1373     "b" gnus-summary-set-bookmark
1374     "B" gnus-summary-remove-bookmark
1375     "#" gnus-summary-mark-as-processable
1376     "\M-#" gnus-summary-unmark-as-processable
1377     "S" gnus-summary-limit-include-expunged
1378     "C" gnus-summary-catchup
1379     "H" gnus-summary-catchup-to-here
1380     "\C-c" gnus-summary-catchup-all
1381     "k" gnus-summary-kill-same-subject-and-select
1382     "K" gnus-summary-kill-same-subject
1383     "P" gnus-uu-mark-map)
1384
1385   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1386     "c" gnus-summary-clear-above
1387     "u" gnus-summary-tick-above
1388     "m" gnus-summary-mark-above
1389     "k" gnus-summary-kill-below)
1390
1391   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1392     "/" gnus-summary-limit-to-subject
1393     "n" gnus-summary-limit-to-articles
1394     "w" gnus-summary-pop-limit
1395     "s" gnus-summary-limit-to-subject
1396     "a" gnus-summary-limit-to-author
1397     "u" gnus-summary-limit-to-unread
1398     "m" gnus-summary-limit-to-marks
1399     "M" gnus-summary-limit-exclude-marks
1400     "v" gnus-summary-limit-to-score
1401     "*" gnus-summary-limit-include-cached
1402     "D" gnus-summary-limit-include-dormant
1403     "T" gnus-summary-limit-include-thread
1404     "d" gnus-summary-limit-exclude-dormant
1405     "t" gnus-summary-limit-to-age
1406     "x" gnus-summary-limit-to-extra 
1407     "E" gnus-summary-limit-include-expunged
1408     "c" gnus-summary-limit-exclude-childless-dormant
1409     "C" gnus-summary-limit-mark-excluded-as-read)
1410
1411   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1412     "n" gnus-summary-next-unread-article
1413     "p" gnus-summary-prev-unread-article
1414     "N" gnus-summary-next-article
1415     "P" gnus-summary-prev-article
1416     "\C-n" gnus-summary-next-same-subject
1417     "\C-p" gnus-summary-prev-same-subject
1418     "\M-n" gnus-summary-next-unread-subject
1419     "\M-p" gnus-summary-prev-unread-subject
1420     "f" gnus-summary-first-unread-article
1421     "b" gnus-summary-best-unread-article
1422     "j" gnus-summary-goto-article
1423     "g" gnus-summary-goto-subject
1424     "l" gnus-summary-goto-last-article
1425     "o" gnus-summary-pop-article)
1426
1427   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1428     "k" gnus-summary-kill-thread
1429     "l" gnus-summary-lower-thread
1430     "i" gnus-summary-raise-thread
1431     "T" gnus-summary-toggle-threads
1432     "t" gnus-summary-rethread-current
1433     "^" gnus-summary-reparent-thread
1434     "s" gnus-summary-show-thread
1435     "S" gnus-summary-show-all-threads
1436     "h" gnus-summary-hide-thread
1437     "H" gnus-summary-hide-all-threads
1438     "n" gnus-summary-next-thread
1439     "p" gnus-summary-prev-thread
1440     "u" gnus-summary-up-thread
1441     "o" gnus-summary-top-thread
1442     "d" gnus-summary-down-thread
1443     "#" gnus-uu-mark-thread
1444     "\M-#" gnus-uu-unmark-thread)
1445
1446   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1447     "g" gnus-summary-prepare
1448     "c" gnus-summary-insert-cached-articles)
1449
1450   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1451     "c" gnus-summary-catchup-and-exit
1452     "C" gnus-summary-catchup-all-and-exit
1453     "E" gnus-summary-exit-no-update
1454     "J" gnus-summary-jump-to-other-group
1455     "Q" gnus-summary-exit
1456     "Z" gnus-summary-exit
1457     "n" gnus-summary-catchup-and-goto-next-group
1458     "R" gnus-summary-reselect-current-group
1459     "G" gnus-summary-rescan-group
1460     "N" gnus-summary-next-group
1461     "s" gnus-summary-save-newsrc
1462     "P" gnus-summary-prev-group)
1463
1464   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1465     " " gnus-summary-next-page
1466     "n" gnus-summary-next-page
1467     "\177" gnus-summary-prev-page
1468     [delete] gnus-summary-prev-page
1469     "p" gnus-summary-prev-page
1470     "\r" gnus-summary-scroll-up
1471     "\M-\r" gnus-summary-scroll-down
1472     "<" gnus-summary-beginning-of-article
1473     ">" gnus-summary-end-of-article
1474     "b" gnus-summary-beginning-of-article
1475     "e" gnus-summary-end-of-article
1476     "^" gnus-summary-refer-parent-article
1477     "r" gnus-summary-refer-parent-article
1478     "D" gnus-summary-enter-digest-group
1479     "R" gnus-summary-refer-references
1480     "T" gnus-summary-refer-thread
1481     "g" gnus-summary-show-article
1482     "s" gnus-summary-isearch-article
1483     "P" gnus-summary-print-article
1484     "t" gnus-article-babel)
1485
1486   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1487     "b" gnus-article-add-buttons
1488     "B" gnus-article-add-buttons-to-head
1489     "o" gnus-article-treat-overstrike
1490     "e" gnus-article-emphasize
1491     "w" gnus-article-fill-cited-article
1492     "Q" gnus-article-fill-long-lines
1493     "C" gnus-article-capitalize-sentences
1494     "c" gnus-article-remove-cr
1495     "f" gnus-article-display-x-face
1496     "l" gnus-summary-stop-page-breaking
1497     "r" gnus-summary-caesar-message
1498     "t" gnus-article-toggle-headers
1499     "v" gnus-summary-verbose-headers
1500     "m" gnus-summary-toggle-mime
1501     "H" gnus-article-strip-headers-in-body
1502     "d" gnus-article-treat-dumbquotes)
1503
1504   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1505     "a" gnus-article-hide
1506     "h" gnus-article-toggle-headers
1507     "b" gnus-article-hide-boring-headers
1508     "s" gnus-article-hide-signature
1509     "c" gnus-article-hide-citation
1510     "C" gnus-article-hide-citation-in-followups
1511     "p" gnus-article-hide-pgp
1512     "B" gnus-article-strip-banner
1513     "P" gnus-article-hide-pem
1514     "\C-c" gnus-article-hide-citation-maybe)
1515
1516   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1517     "a" gnus-article-highlight
1518     "h" gnus-article-highlight-headers
1519     "c" gnus-article-highlight-citation
1520     "s" gnus-article-highlight-signature)
1521
1522   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1523     "z" gnus-article-date-ut
1524     "u" gnus-article-date-ut
1525     "l" gnus-article-date-local
1526     "e" gnus-article-date-lapsed
1527     "o" gnus-article-date-original
1528     "i" gnus-article-date-iso8601
1529     "s" gnus-article-date-user)
1530
1531   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1532     "t" gnus-article-remove-trailing-blank-lines
1533     "l" gnus-article-strip-leading-blank-lines
1534     "m" gnus-article-strip-multiple-blank-lines
1535     "a" gnus-article-strip-blank-lines
1536     "A" gnus-article-strip-all-blank-lines
1537     "s" gnus-article-strip-leading-space
1538     "e" gnus-article-strip-trailing-space)
1539
1540   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1541     "v" gnus-version
1542     "f" gnus-summary-fetch-faq
1543     "d" gnus-summary-describe-group
1544     "h" gnus-summary-describe-briefly
1545     "i" gnus-info-find-node)
1546
1547   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1548     "e" gnus-summary-expire-articles
1549     "\M-\C-e" gnus-summary-expire-articles-now
1550     "\177" gnus-summary-delete-article
1551     [delete] gnus-summary-delete-article
1552     [backspace] gnus-summary-delete-article
1553     "m" gnus-summary-move-article
1554     "r" gnus-summary-respool-article
1555     "w" gnus-summary-edit-article
1556     "c" gnus-summary-copy-article
1557     "B" gnus-summary-crosspost-article
1558     "q" gnus-summary-respool-query
1559     "t" gnus-summary-respool-trace
1560     "i" gnus-summary-import-article
1561     "p" gnus-summary-article-posted-p)
1562
1563   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1564     "o" gnus-summary-save-article
1565     "m" gnus-summary-save-article-mail
1566     "F" gnus-summary-write-article-file
1567     "r" gnus-summary-save-article-rmail
1568     "f" gnus-summary-save-article-file
1569     "b" gnus-summary-save-article-body-file
1570     "h" gnus-summary-save-article-folder
1571     "v" gnus-summary-save-article-vm
1572     "p" gnus-summary-pipe-output
1573     "s" gnus-soup-add-article)
1574
1575   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1576     "b" gnus-summary-display-buttonized
1577     "m" gnus-summary-repair-multipart
1578     "v" gnus-article-view-part
1579     "o" gnus-article-save-part
1580     "c" gnus-article-copy-part
1581     "e" gnus-article-externalize-part
1582     "i" gnus-article-inline-part
1583     "|" gnus-article-pipe-part)
1584   )
1585
1586 (defun gnus-summary-make-menu-bar ()
1587   (gnus-turn-off-edit-menu 'summary)
1588
1589   (unless (boundp 'gnus-summary-misc-menu)
1590
1591     (easy-menu-define
1592      gnus-summary-kill-menu gnus-summary-mode-map ""
1593      (cons
1594       "Score"
1595       (nconc
1596        (list
1597         ["Enter score..." gnus-summary-score-entry t]
1598         ["Customize" gnus-score-customize t])
1599        (gnus-make-score-map 'increase)
1600        (gnus-make-score-map 'lower)
1601        '(("Mark"
1602           ["Kill below" gnus-summary-kill-below t]
1603           ["Mark above" gnus-summary-mark-above t]
1604           ["Tick above" gnus-summary-tick-above t]
1605           ["Clear above" gnus-summary-clear-above t])
1606          ["Current score" gnus-summary-current-score t]
1607          ["Set score" gnus-summary-set-score t]
1608          ["Switch current score file..." gnus-score-change-score-file t]
1609          ["Set mark below..." gnus-score-set-mark-below t]
1610          ["Set expunge below..." gnus-score-set-expunge-below t]
1611          ["Edit current score file" gnus-score-edit-current-scores t]
1612          ["Edit score file" gnus-score-edit-file t]
1613          ["Trace score" gnus-score-find-trace t]
1614          ["Find words" gnus-score-find-favourite-words t]
1615          ["Rescore buffer" gnus-summary-rescore t]
1616          ["Increase score..." gnus-summary-increase-score t]
1617          ["Lower score..." gnus-summary-lower-score t]))))
1618
1619     ;; Define both the Article menu in the summary buffer and the equivalent
1620     ;; Commands menu in the article buffer here for consistency.
1621     (let ((innards
1622            '(("Hide"
1623               ["All" gnus-article-hide t]
1624               ["Headers" gnus-article-toggle-headers t]
1625               ["Signature" gnus-article-hide-signature t]
1626               ["Citation" gnus-article-hide-citation t]
1627               ["PGP" gnus-article-hide-pgp t]
1628               ["Banner" gnus-article-strip-banner t]
1629               ["Boring headers" gnus-article-hide-boring-headers t])
1630              ("Highlight"
1631               ["All" gnus-article-highlight t]
1632               ["Headers" gnus-article-highlight-headers t]
1633               ["Signature" gnus-article-highlight-signature t]
1634               ["Citation" gnus-article-highlight-citation t])
1635              ("Date"
1636               ["Local" gnus-article-date-local t]
1637               ["ISO8601" gnus-article-date-iso8601 t]
1638               ["UT" gnus-article-date-ut t]
1639               ["Original" gnus-article-date-original t]
1640               ["Lapsed" gnus-article-date-lapsed t]
1641               ["User-defined" gnus-article-date-user t])
1642              ("Washing"
1643               ("Remove Blanks"
1644                ["Leading" gnus-article-strip-leading-blank-lines t]
1645                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1646                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1647                ["All of the above" gnus-article-strip-blank-lines t]
1648                ["All" gnus-article-strip-all-blank-lines t]
1649                ["Leading space" gnus-article-strip-leading-space t]
1650                ["Trailing space" gnus-article-strip-trailing-space t])
1651               ["Overstrike" gnus-article-treat-overstrike t]
1652               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1653               ["Emphasis" gnus-article-emphasize t]
1654               ["Word wrap" gnus-article-fill-cited-article t]
1655               ["Fill long lines" gnus-article-fill-long-lines t]
1656               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1657               ["CR" gnus-article-remove-cr t]
1658               ["Show X-Face" gnus-article-display-x-face t]
1659               ["Rot 13" gnus-summary-caesar-message t]
1660               ["Unix pipe" gnus-summary-pipe-message t]
1661               ["Add buttons" gnus-article-add-buttons t]
1662               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1663               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1664               ["Toggle MIME" gnus-summary-toggle-mime t]
1665               ["Verbose header" gnus-summary-verbose-headers t]
1666               ["Toggle header" gnus-summary-toggle-header t])
1667              ("Output"
1668               ["Save in default format" gnus-summary-save-article t]
1669               ["Save in file" gnus-summary-save-article-file t]
1670               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1671               ["Save in MH folder" gnus-summary-save-article-folder t]
1672               ["Save in VM folder" gnus-summary-save-article-vm t]
1673               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1674               ["Save body in file" gnus-summary-save-article-body-file t]
1675               ["Pipe through a filter" gnus-summary-pipe-output t]
1676               ["Add to SOUP packet" gnus-soup-add-article t]
1677               ["Print" gnus-summary-print-article t])
1678              ("Backend"
1679               ["Respool article..." gnus-summary-respool-article t]
1680               ["Move article..." gnus-summary-move-article
1681                (gnus-check-backend-function
1682                 'request-move-article gnus-newsgroup-name)]
1683               ["Copy article..." gnus-summary-copy-article t]
1684               ["Crosspost article..." gnus-summary-crosspost-article
1685                (gnus-check-backend-function
1686                 'request-replace-article gnus-newsgroup-name)]
1687               ["Import file..." gnus-summary-import-article t]
1688               ["Check if posted" gnus-summary-article-posted-p t]
1689               ["Edit article" gnus-summary-edit-article
1690                (not (gnus-group-read-only-p))]
1691               ["Delete article" gnus-summary-delete-article
1692                (gnus-check-backend-function
1693                 'request-expire-articles gnus-newsgroup-name)]
1694               ["Query respool" gnus-summary-respool-query t]
1695               ["Trace respool" gnus-summary-respool-trace t]
1696               ["Delete expirable articles" gnus-summary-expire-articles-now
1697                (gnus-check-backend-function
1698                 'request-expire-articles gnus-newsgroup-name)])
1699              ("Extract"
1700               ["Uudecode" gnus-uu-decode-uu t]
1701               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1702               ["Unshar" gnus-uu-decode-unshar t]
1703               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1704               ["Save" gnus-uu-decode-save t]
1705               ["Binhex" gnus-uu-decode-binhex t]
1706               ["Postscript" gnus-uu-decode-postscript t])
1707              ("Cache"
1708               ["Enter article" gnus-cache-enter-article t]
1709               ["Remove article" gnus-cache-remove-article t])
1710              ["Translate" gnus-article-babel t]
1711              ["Select article buffer" gnus-summary-select-article-buffer t]
1712              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1713              ["Isearch article..." gnus-summary-isearch-article t]
1714              ["Beginning of the article" gnus-summary-beginning-of-article t]
1715              ["End of the article" gnus-summary-end-of-article t]
1716              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1717              ["Fetch referenced articles" gnus-summary-refer-references t]
1718              ["Fetch current thread" gnus-summary-refer-thread t]
1719              ["Fetch article with id..." gnus-summary-refer-article t]
1720              ["Redisplay" gnus-summary-show-article t])))
1721       (easy-menu-define
1722        gnus-summary-article-menu gnus-summary-mode-map ""
1723        (cons "Article" innards))
1724
1725       (easy-menu-define
1726        gnus-article-commands-menu gnus-article-mode-map ""
1727        (cons "Commands" innards)))
1728
1729     (easy-menu-define
1730      gnus-summary-thread-menu gnus-summary-mode-map ""
1731      '("Threads"
1732        ["Toggle threading" gnus-summary-toggle-threads t]
1733        ["Hide threads" gnus-summary-hide-all-threads t]
1734        ["Show threads" gnus-summary-show-all-threads t]
1735        ["Hide thread" gnus-summary-hide-thread t]
1736        ["Show thread" gnus-summary-show-thread t]
1737        ["Go to next thread" gnus-summary-next-thread t]
1738        ["Go to previous thread" gnus-summary-prev-thread t]
1739        ["Go down thread" gnus-summary-down-thread t]
1740        ["Go up thread" gnus-summary-up-thread t]
1741        ["Top of thread" gnus-summary-top-thread t]
1742        ["Mark thread as read" gnus-summary-kill-thread t]
1743        ["Lower thread score" gnus-summary-lower-thread t]
1744        ["Raise thread score" gnus-summary-raise-thread t]
1745        ["Rethread current" gnus-summary-rethread-current t]
1746        ))
1747
1748     (easy-menu-define
1749      gnus-summary-post-menu gnus-summary-mode-map ""
1750      '("Post"
1751        ["Post an article" gnus-summary-post-news t]
1752        ["Followup" gnus-summary-followup t]
1753        ["Followup and yank" gnus-summary-followup-with-original t]
1754        ["Supersede article" gnus-summary-supersede-article t]
1755        ["Cancel article" gnus-summary-cancel-article t]
1756        ["Reply" gnus-summary-reply t]
1757        ["Reply and yank" gnus-summary-reply-with-original t]
1758        ["Wide reply" gnus-summary-wide-reply t]
1759        ["Wide reply and yank" gnus-summary-wide-reply-with-original t]
1760        ["Mail forward" gnus-summary-mail-forward t]
1761        ["Post forward" gnus-summary-post-forward t]
1762        ["Digest and mail" gnus-summary-mail-digest t]
1763        ["Digest and post" gnus-summary-post-digest t]
1764        ["Resend message" gnus-summary-resend-message t]
1765        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1766        ["Send a mail" gnus-summary-mail-other-window t]
1767        ["Uuencode and post" gnus-uu-post-news t]
1768        ["Followup via news" gnus-summary-followup-to-mail t]
1769        ["Followup via news and yank"
1770         gnus-summary-followup-to-mail-with-original t]
1771        ;;("Draft"
1772        ;;["Send" gnus-summary-send-draft t]
1773        ;;["Send bounced" gnus-resend-bounced-mail t])
1774        ))
1775
1776     (easy-menu-define
1777      gnus-summary-misc-menu gnus-summary-mode-map ""
1778      '("Misc"
1779        ("Mark Read"
1780         ["Mark as read" gnus-summary-mark-as-read-forward t]
1781         ["Mark same subject and select"
1782          gnus-summary-kill-same-subject-and-select t]
1783         ["Mark same subject" gnus-summary-kill-same-subject t]
1784         ["Catchup" gnus-summary-catchup t]
1785         ["Catchup all" gnus-summary-catchup-all t]
1786         ["Catchup to here" gnus-summary-catchup-to-here t]
1787         ["Catchup region" gnus-summary-mark-region-as-read t]
1788         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1789        ("Mark Various"
1790         ["Tick" gnus-summary-tick-article-forward t]
1791         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1792         ["Remove marks" gnus-summary-clear-mark-forward t]
1793         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1794         ["Set bookmark" gnus-summary-set-bookmark t]
1795         ["Remove bookmark" gnus-summary-remove-bookmark t])
1796        ("Mark Limit"
1797         ["Marks..." gnus-summary-limit-to-marks t]
1798         ["Subject..." gnus-summary-limit-to-subject t]
1799         ["Author..." gnus-summary-limit-to-author t]
1800         ["Age..." gnus-summary-limit-to-age t]
1801         ["Extra..." gnus-summary-limit-to-extra t]
1802         ["Score" gnus-summary-limit-to-score t]
1803         ["Unread" gnus-summary-limit-to-unread t]
1804         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1805         ["Articles" gnus-summary-limit-to-articles t]
1806         ["Pop limit" gnus-summary-pop-limit t]
1807         ["Show dormant" gnus-summary-limit-include-dormant t]
1808         ["Hide childless dormant"
1809          gnus-summary-limit-exclude-childless-dormant t]
1810         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1811         ["Hide marked" gnus-summary-limit-exclude-marks t]
1812         ["Show expunged" gnus-summary-show-all-expunged t])
1813        ("Process Mark"
1814         ["Set mark" gnus-summary-mark-as-processable t]
1815         ["Remove mark" gnus-summary-unmark-as-processable t]
1816         ["Remove all marks" gnus-summary-unmark-all-processable t]
1817         ["Mark above" gnus-uu-mark-over t]
1818         ["Mark series" gnus-uu-mark-series t]
1819         ["Mark region" gnus-uu-mark-region t]
1820         ["Unmark region" gnus-uu-unmark-region t]
1821         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1822         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1823         ["Mark all" gnus-uu-mark-all t]
1824         ["Mark buffer" gnus-uu-mark-buffer t]
1825         ["Mark sparse" gnus-uu-mark-sparse t]
1826         ["Mark thread" gnus-uu-mark-thread t]
1827         ["Unmark thread" gnus-uu-unmark-thread t]
1828         ("Process Mark Sets"
1829          ["Kill" gnus-summary-kill-process-mark t]
1830          ["Yank" gnus-summary-yank-process-mark
1831           gnus-newsgroup-process-stack]
1832          ["Save" gnus-summary-save-process-mark t]))
1833        ("Scroll article"
1834         ["Page forward" gnus-summary-next-page t]
1835         ["Page backward" gnus-summary-prev-page t]
1836         ["Line forward" gnus-summary-scroll-up t])
1837        ("Move"
1838         ["Next unread article" gnus-summary-next-unread-article t]
1839         ["Previous unread article" gnus-summary-prev-unread-article t]
1840         ["Next article" gnus-summary-next-article t]
1841         ["Previous article" gnus-summary-prev-article t]
1842         ["Next unread subject" gnus-summary-next-unread-subject t]
1843         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1844         ["Next article same subject" gnus-summary-next-same-subject t]
1845         ["Previous article same subject" gnus-summary-prev-same-subject t]
1846         ["First unread article" gnus-summary-first-unread-article t]
1847         ["Best unread article" gnus-summary-best-unread-article t]
1848         ["Go to subject number..." gnus-summary-goto-subject t]
1849         ["Go to article number..." gnus-summary-goto-article t]
1850         ["Go to the last article" gnus-summary-goto-last-article t]
1851         ["Pop article off history" gnus-summary-pop-article t])
1852        ("Sort"
1853         ["Sort by number" gnus-summary-sort-by-number t]
1854         ["Sort by author" gnus-summary-sort-by-author t]
1855         ["Sort by subject" gnus-summary-sort-by-subject t]
1856         ["Sort by date" gnus-summary-sort-by-date t]
1857         ["Sort by score" gnus-summary-sort-by-score t]
1858         ["Sort by lines" gnus-summary-sort-by-lines t]
1859         ["Sort by characters" gnus-summary-sort-by-chars t])
1860        ("Help"
1861         ["Fetch group FAQ" gnus-summary-fetch-faq t]
1862         ["Describe group" gnus-summary-describe-group t]
1863         ["Read manual" gnus-info-find-node t])
1864        ("Modes"
1865         ["Pick and read" gnus-pick-mode t]
1866         ["Binary" gnus-binary-mode t])
1867        ("Regeneration"
1868         ["Regenerate" gnus-summary-prepare t]
1869         ["Insert cached articles" gnus-summary-insert-cached-articles t]
1870         ["Toggle threading" gnus-summary-toggle-threads t])
1871        ["Filter articles..." gnus-summary-execute-command t]
1872        ["Run command on subjects..." gnus-summary-universal-argument t]
1873        ["Search articles forward..." gnus-summary-search-article-forward t]
1874        ["Search articles backward..." gnus-summary-search-article-backward t]
1875        ["Toggle line truncation" gnus-summary-toggle-truncation t]
1876        ["Expand window" gnus-summary-expand-window t]
1877        ["Expire expirable articles" gnus-summary-expire-articles
1878         (gnus-check-backend-function
1879          'request-expire-articles gnus-newsgroup-name)]
1880        ["Edit local kill file" gnus-summary-edit-local-kill t]
1881        ["Edit main kill file" gnus-summary-edit-global-kill t]
1882        ["Edit group parameters" gnus-summary-edit-parameters t]
1883        ["Customize group parameters" gnus-summary-customize-parameters t]
1884        ["Send a bug report" gnus-bug t]
1885        ("Exit"
1886         ["Catchup and exit" gnus-summary-catchup-and-exit t]
1887         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
1888         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
1889         ["Exit group" gnus-summary-exit t]
1890         ["Exit group without updating" gnus-summary-exit-no-update t]
1891         ["Exit and goto next group" gnus-summary-next-group t]
1892         ["Exit and goto prev group" gnus-summary-prev-group t]
1893         ["Reselect group" gnus-summary-reselect-current-group t]
1894         ["Rescan group" gnus-summary-rescan-group t]
1895         ["Update dribble" gnus-summary-save-newsrc t])))
1896
1897     (gnus-run-hooks 'gnus-summary-menu-hook)))
1898
1899 (defun gnus-score-set-default (var value)
1900   "A version of set that updates the GNU Emacs menu-bar."
1901   (set var value)
1902   ;; It is the message that forces the active status to be updated.
1903   (message ""))
1904
1905 (defun gnus-make-score-map (type)
1906   "Make a summary score map of type TYPE."
1907   (if t
1908       nil
1909     (let ((headers '(("author" "from" string)
1910                      ("subject" "subject" string)
1911                      ("article body" "body" string)
1912                      ("article head" "head" string)
1913                      ("xref" "xref" string)
1914                      ("extra header" "extra" string)
1915                      ("lines" "lines" number)
1916                      ("followups to author" "followup" string)))
1917           (types '((number ("less than" <)
1918                            ("greater than" >)
1919                            ("equal" =))
1920                    (string ("substring" s)
1921                            ("exact string" e)
1922                            ("fuzzy string" f)
1923                            ("regexp" r))))
1924           (perms '(("temporary" (current-time-string))
1925                    ("permanent" nil)
1926                    ("immediate" now)))
1927           header)
1928       (list
1929        (apply
1930         'nconc
1931         (list
1932          (if (eq type 'lower)
1933              "Lower score"
1934            "Increase score"))
1935         (let (outh)
1936           (while headers
1937             (setq header (car headers))
1938             (setq outh
1939                   (cons
1940                    (apply
1941                     'nconc
1942                     (list (car header))
1943                     (let ((ts (cdr (assoc (nth 2 header) types)))
1944                           outt)
1945                       (while ts
1946                         (setq outt
1947                               (cons
1948                                (apply
1949                                 'nconc
1950                                 (list (caar ts))
1951                                 (let ((ps perms)
1952                                       outp)
1953                                   (while ps
1954                                     (setq outp
1955                                           (cons
1956                                            (vector
1957                                             (caar ps)
1958                                             (list
1959                                              'gnus-summary-score-entry
1960                                              (nth 1 header)
1961                                              (if (or (string= (nth 1 header)
1962                                                               "head")
1963                                                      (string= (nth 1 header)
1964                                                               "body"))
1965                                                  ""
1966                                                (list 'gnus-summary-header
1967                                                      (nth 1 header)))
1968                                              (list 'quote (nth 1 (car ts)))
1969                                              (list 'gnus-score-default nil)
1970                                              (nth 1 (car ps))
1971                                              t)
1972                                             t)
1973                                            outp))
1974                                     (setq ps (cdr ps)))
1975                                   (list (nreverse outp))))
1976                                outt))
1977                         (setq ts (cdr ts)))
1978                       (list (nreverse outt))))
1979                    outh))
1980             (setq headers (cdr headers)))
1981           (list (nreverse outh))))))))
1982
1983 \f
1984
1985 (defun gnus-summary-mode (&optional group)
1986   "Major mode for reading articles.
1987
1988 All normal editing commands are switched off.
1989 \\<gnus-summary-mode-map>
1990 Each line in this buffer represents one article.  To read an
1991 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
1992 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
1993 respectively.
1994
1995 You can also post articles and send mail from this buffer.  To
1996 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
1997 of an article, type `\\[gnus-summary-reply]'.
1998
1999 There are approx. one gazillion commands you can execute in this
2000 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2001
2002 The following commands are available:
2003
2004 \\{gnus-summary-mode-map}"
2005   (interactive)
2006   (when (gnus-visual-p 'summary-menu 'menu)
2007     (gnus-summary-make-menu-bar))
2008   (kill-all-local-variables)
2009   (gnus-summary-make-local-variables)
2010   (gnus-make-thread-indent-array)
2011   (gnus-simplify-mode-line)
2012   (setq major-mode 'gnus-summary-mode)
2013   (setq mode-name "Summary")
2014   (make-local-variable 'minor-mode-alist)
2015   (use-local-map gnus-summary-mode-map)
2016   (buffer-disable-undo)
2017   (setq buffer-read-only t)             ;Disable modification
2018   (setq truncate-lines t)
2019   (setq selective-display t)
2020   (setq selective-display-ellipses t)   ;Display `...'
2021   (gnus-summary-set-display-table)
2022   (gnus-set-default-directory)
2023   (setq gnus-newsgroup-name group)
2024   (make-local-variable 'gnus-summary-line-format)
2025   (make-local-variable 'gnus-summary-line-format-spec)
2026   (make-local-variable 'gnus-summary-dummy-line-format)
2027   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2028   (make-local-variable 'gnus-summary-mark-positions)
2029   (make-local-hook 'pre-command-hook)
2030   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2031   (gnus-run-hooks 'gnus-summary-mode-hook)
2032   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2033   (gnus-update-summary-mark-positions))
2034
2035 (defun gnus-summary-make-local-variables ()
2036   "Make all the local summary buffer variables."
2037   (let (global)
2038     (dolist (local gnus-summary-local-variables)
2039       (if (consp local)
2040           (progn
2041             (if (eq (cdr local) 'global)
2042                 ;; Copy the global value of the variable.
2043                 (setq global (symbol-value (car local)))
2044               ;; Use the value from the list.
2045               (setq global (eval (cdr local))))
2046             (set (make-local-variable (car local)) global))
2047         ;; Simple nil-valued local variable.
2048         (set (make-local-variable local) nil)))))
2049
2050 (defun gnus-summary-clear-local-variables ()
2051   (let ((locals gnus-summary-local-variables))
2052     (while locals
2053       (if (consp (car locals))
2054           (and (vectorp (caar locals))
2055                (set (caar locals) nil))
2056         (and (vectorp (car locals))
2057              (set (car locals) nil)))
2058       (setq locals (cdr locals)))))
2059
2060 ;; Summary data functions.
2061
2062 (defmacro gnus-data-number (data)
2063   `(car ,data))
2064
2065 (defmacro gnus-data-set-number (data number)
2066   `(setcar ,data ,number))
2067
2068 (defmacro gnus-data-mark (data)
2069   `(nth 1 ,data))
2070
2071 (defmacro gnus-data-set-mark (data mark)
2072   `(setcar (nthcdr 1 ,data) ,mark))
2073
2074 (defmacro gnus-data-pos (data)
2075   `(nth 2 ,data))
2076
2077 (defmacro gnus-data-set-pos (data pos)
2078   `(setcar (nthcdr 2 ,data) ,pos))
2079
2080 (defmacro gnus-data-header (data)
2081   `(nth 3 ,data))
2082
2083 (defmacro gnus-data-set-header (data header)
2084   `(setf (nth 3 ,data) ,header))
2085
2086 (defmacro gnus-data-level (data)
2087   `(nth 4 ,data))
2088
2089 (defmacro gnus-data-unread-p (data)
2090   `(= (nth 1 ,data) gnus-unread-mark))
2091
2092 (defmacro gnus-data-read-p (data)
2093   `(/= (nth 1 ,data) gnus-unread-mark))
2094
2095 (defmacro gnus-data-pseudo-p (data)
2096   `(consp (nth 3 ,data)))
2097
2098 (defmacro gnus-data-find (number)
2099   `(assq ,number gnus-newsgroup-data))
2100
2101 (defmacro gnus-data-find-list (number &optional data)
2102   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2103      (memq (assq ,number bdata)
2104            bdata)))
2105
2106 (defmacro gnus-data-make (number mark pos header level)
2107   `(list ,number ,mark ,pos ,header ,level))
2108
2109 (defun gnus-data-enter (after-article number mark pos header level offset)
2110   (let ((data (gnus-data-find-list after-article)))
2111     (unless data
2112       (error "No such article: %d" after-article))
2113     (setcdr data (cons (gnus-data-make number mark pos header level)
2114                        (cdr data)))
2115     (setq gnus-newsgroup-data-reverse nil)
2116     (gnus-data-update-list (cddr data) offset)))
2117
2118 (defun gnus-data-enter-list (after-article list &optional offset)
2119   (when list
2120     (let ((data (and after-article (gnus-data-find-list after-article)))
2121           (ilist list))
2122       (if (not (or data
2123                    after-article))
2124           (let ((odata gnus-newsgroup-data))
2125             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2126             (when offset
2127               (gnus-data-update-list odata offset)))
2128         ;; Find the last element in the list to be spliced into the main
2129         ;; list.
2130         (while (cdr list)
2131           (setq list (cdr list)))
2132         (if (not data)
2133             (progn
2134               (setcdr list gnus-newsgroup-data)
2135               (setq gnus-newsgroup-data ilist)
2136               (when offset
2137                 (gnus-data-update-list (cdr list) offset)))
2138           (setcdr list (cdr data))
2139           (setcdr data ilist)
2140           (when offset
2141             (gnus-data-update-list (cdr list) offset))))
2142       (setq gnus-newsgroup-data-reverse nil))))
2143
2144 (defun gnus-data-remove (article &optional offset)
2145   (let ((data gnus-newsgroup-data))
2146     (if (= (gnus-data-number (car data)) article)
2147         (progn
2148           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2149                 gnus-newsgroup-data-reverse nil)
2150           (when offset
2151             (gnus-data-update-list gnus-newsgroup-data offset)))
2152       (while (cdr data)
2153         (when (= (gnus-data-number (cadr data)) article)
2154           (setcdr data (cddr data))
2155           (when offset
2156             (gnus-data-update-list (cdr data) offset))
2157           (setq data nil
2158                 gnus-newsgroup-data-reverse nil))
2159         (setq data (cdr data))))))
2160
2161 (defmacro gnus-data-list (backward)
2162   `(if ,backward
2163        (or gnus-newsgroup-data-reverse
2164            (setq gnus-newsgroup-data-reverse
2165                  (reverse gnus-newsgroup-data)))
2166      gnus-newsgroup-data))
2167
2168 (defun gnus-data-update-list (data offset)
2169   "Add OFFSET to the POS of all data entries in DATA."
2170   (setq gnus-newsgroup-data-reverse nil)
2171   (while data
2172     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2173     (setq data (cdr data))))
2174
2175 (defun gnus-summary-article-pseudo-p (article)
2176   "Say whether this article is a pseudo article or not."
2177   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2178
2179 (defmacro gnus-summary-article-sparse-p (article)
2180   "Say whether this article is a sparse article or not."
2181   `(memq ,article gnus-newsgroup-sparse))
2182
2183 (defmacro gnus-summary-article-ancient-p (article)
2184   "Say whether this article is a sparse article or not."
2185   `(memq ,article gnus-newsgroup-ancient))
2186
2187 (defun gnus-article-parent-p (number)
2188   "Say whether this article is a parent or not."
2189   (let ((data (gnus-data-find-list number)))
2190     (and (cdr data)                     ; There has to be an article after...
2191          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2192             (gnus-data-level (nth 1 data))))))
2193
2194 (defun gnus-article-children (number)
2195   "Return a list of all children to NUMBER."
2196   (let* ((data (gnus-data-find-list number))
2197          (level (gnus-data-level (car data)))
2198          children)
2199     (setq data (cdr data))
2200     (while (and data
2201                 (= (gnus-data-level (car data)) (1+ level)))
2202       (push (gnus-data-number (car data)) children)
2203       (setq data (cdr data)))
2204     children))
2205
2206 (defmacro gnus-summary-skip-intangible ()
2207   "If the current article is intangible, then jump to a different article."
2208   '(let ((to (get-text-property (point) 'gnus-intangible)))
2209      (and to (gnus-summary-goto-subject to))))
2210
2211 (defmacro gnus-summary-article-intangible-p ()
2212   "Say whether this article is intangible or not."
2213   '(get-text-property (point) 'gnus-intangible))
2214
2215 (defun gnus-article-read-p (article)
2216   "Say whether ARTICLE is read or not."
2217   (not (or (memq article gnus-newsgroup-marked)
2218            (memq article gnus-newsgroup-unreads)
2219            (memq article gnus-newsgroup-unselected)
2220            (memq article gnus-newsgroup-dormant))))
2221
2222 ;; Some summary mode macros.
2223
2224 (defmacro gnus-summary-article-number ()
2225   "The article number of the article on the current line.
2226 If there isn's an article number here, then we return the current
2227 article number."
2228   '(progn
2229      (gnus-summary-skip-intangible)
2230      (or (get-text-property (point) 'gnus-number)
2231          (gnus-summary-last-subject))))
2232
2233 (defmacro gnus-summary-article-header (&optional number)
2234   "Return the header of article NUMBER."
2235   `(gnus-data-header (gnus-data-find
2236                       ,(or number '(gnus-summary-article-number)))))
2237
2238 (defmacro gnus-summary-thread-level (&optional number)
2239   "Return the level of thread that starts with article NUMBER."
2240   `(if (and (eq gnus-summary-make-false-root 'dummy)
2241             (get-text-property (point) 'gnus-intangible))
2242        0
2243      (gnus-data-level (gnus-data-find
2244                        ,(or number '(gnus-summary-article-number))))))
2245
2246 (defmacro gnus-summary-article-mark (&optional number)
2247   "Return the mark of article NUMBER."
2248   `(gnus-data-mark (gnus-data-find
2249                     ,(or number '(gnus-summary-article-number)))))
2250
2251 (defmacro gnus-summary-article-pos (&optional number)
2252   "Return the position of the line of article NUMBER."
2253   `(gnus-data-pos (gnus-data-find
2254                    ,(or number '(gnus-summary-article-number)))))
2255
2256 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2257 (defmacro gnus-summary-article-subject (&optional number)
2258   "Return current subject string or nil if nothing."
2259   `(let ((headers
2260           ,(if number
2261                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2262              '(gnus-data-header (assq (gnus-summary-article-number)
2263                                       gnus-newsgroup-data)))))
2264      (and headers
2265           (vectorp headers)
2266           (mail-header-subject headers))))
2267
2268 (defmacro gnus-summary-article-score (&optional number)
2269   "Return current article score."
2270   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2271                   gnus-newsgroup-scored))
2272        gnus-summary-default-score 0))
2273
2274 (defun gnus-summary-article-children (&optional number)
2275   "Return a list of article numbers that are children of article NUMBER."
2276   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2277          (level (gnus-data-level (car data)))
2278          l children)
2279     (while (and (setq data (cdr data))
2280                 (> (setq l (gnus-data-level (car data))) level))
2281       (and (= (1+ level) l)
2282            (push (gnus-data-number (car data))
2283                  children)))
2284     (nreverse children)))
2285
2286 (defun gnus-summary-article-parent (&optional number)
2287   "Return the article number of the parent of article NUMBER."
2288   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2289                                     (gnus-data-list t)))
2290          (level (gnus-data-level (car data))))
2291     (if (zerop level)
2292         ()                              ; This is a root.
2293       ;; We search until we find an article with a level less than
2294       ;; this one.  That function has to be the parent.
2295       (while (and (setq data (cdr data))
2296                   (not (< (gnus-data-level (car data)) level))))
2297       (and data (gnus-data-number (car data))))))
2298
2299 (defun gnus-unread-mark-p (mark)
2300   "Say whether MARK is the unread mark."
2301   (= mark gnus-unread-mark))
2302
2303 (defun gnus-read-mark-p (mark)
2304   "Say whether MARK is one of the marks that mark as read.
2305 This is all marks except unread, ticked, dormant, and expirable."
2306   (not (or (= mark gnus-unread-mark)
2307            (= mark gnus-ticked-mark)
2308            (= mark gnus-dormant-mark)
2309            (= mark gnus-expirable-mark))))
2310
2311 (defmacro gnus-article-mark (number)
2312   "Return the MARK of article NUMBER.
2313 This macro should only be used when computing the mark the \"first\"
2314 time; i.e., when generating the summary lines.  After that,
2315 `gnus-summary-article-mark' should be used to examine the
2316 marks of articles."
2317   `(cond
2318     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2319     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2320     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2321     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2322     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2323     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2324     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2325     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2326            gnus-ancient-mark))))
2327
2328 ;; Saving hidden threads.
2329
2330 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2331 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2332
2333 (defmacro gnus-save-hidden-threads (&rest forms)
2334   "Save hidden threads, eval FORMS, and restore the hidden threads."
2335   (let ((config (make-symbol "config")))
2336     `(let ((,config (gnus-hidden-threads-configuration)))
2337        (unwind-protect
2338            (save-excursion
2339              ,@forms)
2340          (gnus-restore-hidden-threads-configuration ,config)))))
2341
2342 (defun gnus-data-compute-positions ()
2343   "Compute the positions of all articles."
2344   (setq gnus-newsgroup-data-reverse nil)
2345   (let ((data gnus-newsgroup-data))
2346     (save-excursion
2347       (gnus-save-hidden-threads
2348         (gnus-summary-show-all-threads)
2349         (goto-char (point-min))
2350         (while data
2351           (while (get-text-property (point) 'gnus-intangible)
2352             (forward-line 1))
2353           (gnus-data-set-pos (car data) (+ (point) 3))
2354           (setq data (cdr data))
2355           (forward-line 1))))))
2356
2357 (defun gnus-hidden-threads-configuration ()
2358   "Return the current hidden threads configuration."
2359   (save-excursion
2360     (let (config)
2361       (goto-char (point-min))
2362       (while (search-forward "\r" nil t)
2363         (push (1- (point)) config))
2364       config)))
2365
2366 (defun gnus-restore-hidden-threads-configuration (config)
2367   "Restore hidden threads configuration from CONFIG."
2368   (let (point buffer-read-only)
2369     (while (setq point (pop config))
2370       (when (and (< point (point-max))
2371                  (goto-char point)
2372                  (eq (char-after) ?\n))
2373         (subst-char-in-region point (1+ point) ?\n ?\r)))))
2374
2375 ;; Various summary mode internalish functions.
2376
2377 (defun gnus-mouse-pick-article (e)
2378   (interactive "e")
2379   (mouse-set-point e)
2380   (gnus-summary-next-page nil t))
2381
2382 (defun gnus-summary-set-display-table ()
2383   ;; Change the display table.  Odd characters have a tendency to mess
2384   ;; up nicely formatted displays - we make all possible glyphs
2385   ;; display only a single character.
2386
2387   ;; We start from the standard display table, if any.
2388   (let ((table (or (copy-sequence standard-display-table)
2389                    (make-display-table)))
2390         (i 32))
2391     ;; Nix out all the control chars...
2392     (while (>= (setq i (1- i)) 0)
2393       (aset table i [??]))
2394     ;; ... but not newline and cr, of course.  (cr is necessary for the
2395     ;; selective display).
2396     (aset table ?\n nil)
2397     (aset table ?\r nil)
2398     ;; We keep TAB as well.
2399     (aset table ?\t nil)
2400     ;; We nix out any glyphs over 126 that are not set already.
2401     (let ((i 256))
2402       (while (>= (setq i (1- i)) 127)
2403         ;; Only modify if the entry is nil.
2404         (unless (aref table i)
2405           (aset table i [??]))))
2406     (setq buffer-display-table table)))
2407
2408 (defun gnus-summary-setup-buffer (group)
2409   "Initialize summary buffer."
2410   (let ((buffer (concat "*Summary " group "*")))
2411     (if (get-buffer buffer)
2412         (progn
2413           (set-buffer buffer)
2414           (setq gnus-summary-buffer (current-buffer))
2415           (not gnus-newsgroup-prepared))
2416       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2417       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2418       (gnus-summary-mode group)
2419       (when gnus-carpal
2420         (gnus-carpal-setup-buffer 'summary))
2421       (unless gnus-single-article-buffer
2422         (make-local-variable 'gnus-article-buffer)
2423         (make-local-variable 'gnus-article-current)
2424         (make-local-variable 'gnus-original-article-buffer))
2425       (setq gnus-newsgroup-name group)
2426       t)))
2427
2428 (defun gnus-set-global-variables ()
2429   ;; Set the global equivalents of the summary buffer-local variables
2430   ;; to the latest values they had.  These reflect the summary buffer
2431   ;; that was in action when the last article was fetched.
2432   (when (eq major-mode 'gnus-summary-mode)
2433     (setq gnus-summary-buffer (current-buffer))
2434     (let ((name gnus-newsgroup-name)
2435           (marked gnus-newsgroup-marked)
2436           (unread gnus-newsgroup-unreads)
2437           (headers gnus-current-headers)
2438           (data gnus-newsgroup-data)
2439           (summary gnus-summary-buffer)
2440           (article-buffer gnus-article-buffer)
2441           (original gnus-original-article-buffer)
2442           (gac gnus-article-current)
2443           (reffed gnus-reffed-article-number)
2444           (score-file gnus-current-score-file)
2445           (default-charset gnus-newsgroup-charset))
2446       (save-excursion
2447         (set-buffer gnus-group-buffer)
2448         (setq gnus-newsgroup-name name
2449               gnus-newsgroup-marked marked
2450               gnus-newsgroup-unreads unread
2451               gnus-current-headers headers
2452               gnus-newsgroup-data data
2453               gnus-article-current gac
2454               gnus-summary-buffer summary
2455               gnus-article-buffer article-buffer
2456               gnus-original-article-buffer original
2457               gnus-reffed-article-number reffed
2458               gnus-current-score-file score-file
2459               gnus-newsgroup-charset default-charset)
2460         ;; The article buffer also has local variables.
2461         (when (gnus-buffer-live-p gnus-article-buffer)
2462           (set-buffer gnus-article-buffer)
2463           (setq gnus-summary-buffer summary))))))
2464
2465 (defun gnus-summary-article-unread-p (article)
2466   "Say whether ARTICLE is unread or not."
2467   (memq article gnus-newsgroup-unreads))
2468
2469 (defun gnus-summary-first-article-p (&optional article)
2470   "Return whether ARTICLE is the first article in the buffer."
2471   (if (not (setq article (or article (gnus-summary-article-number))))
2472       nil
2473     (eq article (caar gnus-newsgroup-data))))
2474
2475 (defun gnus-summary-last-article-p (&optional article)
2476   "Return whether ARTICLE is the last article in the buffer."
2477   (if (not (setq article (or article (gnus-summary-article-number))))
2478       ;; All non-existent numbers are the last article.  :-)
2479       t
2480     (not (cdr (gnus-data-find-list article)))))
2481
2482 (defun gnus-make-thread-indent-array ()
2483   (let ((n 200))
2484     (unless (and gnus-thread-indent-array
2485                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2486       (setq gnus-thread-indent-array (make-vector 201 "")
2487             gnus-thread-indent-array-level gnus-thread-indent-level)
2488       (while (>= n 0)
2489         (aset gnus-thread-indent-array n
2490               (make-string (* n gnus-thread-indent-level) ? ))
2491         (setq n (1- n))))))
2492
2493 (defun gnus-update-summary-mark-positions ()
2494   "Compute where the summary marks are to go."
2495   (save-excursion
2496     (when (gnus-buffer-exists-p gnus-summary-buffer)
2497       (set-buffer gnus-summary-buffer))
2498     (let ((gnus-replied-mark 129)
2499           (gnus-score-below-mark 130)
2500           (gnus-score-over-mark 130)
2501           (gnus-download-mark 131)
2502           (spec gnus-summary-line-format-spec)
2503           gnus-visual pos)
2504       (save-excursion
2505         (gnus-set-work-buffer)
2506         (let ((gnus-summary-line-format-spec spec)
2507               (gnus-newsgroup-downloadable '((0 . t))))
2508           (gnus-summary-insert-line
2509            (make-full-mail-header 0 "" "" "" "" "" 0 0 "" nil)
2510            0 nil 128 t nil "" nil 1)
2511           (goto-char (point-min))
2512           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2513                                              (- (point) 2)))))
2514           (goto-char (point-min))
2515           (push (cons 'replied (and (search-forward "\201" nil t)
2516                                     (- (point) 2)))
2517                 pos)
2518           (goto-char (point-min))
2519           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2520                 pos)
2521           (goto-char (point-min))
2522           (push (cons 'download
2523                       (and (search-forward "\203" nil t) (- (point) 2)))
2524                 pos)))
2525       (setq gnus-summary-mark-positions pos))))
2526
2527 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2528   "Insert a dummy root in the summary buffer."
2529   (beginning-of-line)
2530   (gnus-add-text-properties
2531    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2532    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2533
2534 (defun gnus-summary-from-or-to-or-newsgroups (header)
2535   (let ((to (cdr (assq 'To (mail-header-extra header))))
2536         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2537         (default-mime-charset (with-current-buffer gnus-summary-buffer
2538                                 default-mime-charset)))
2539     (cond
2540      ((and to
2541            gnus-ignored-from-addresses
2542            (string-match gnus-ignored-from-addresses
2543                          (mail-header-from header)))
2544       (concat "-> "
2545               (or (car (funcall gnus-extract-address-components
2546                                 (funcall
2547                                  gnus-decode-encoded-word-function to)))
2548                   (funcall gnus-decode-encoded-word-function to))))
2549      ((and newsgroups
2550            gnus-ignored-from-addresses
2551            (string-match gnus-ignored-from-addresses
2552                          (mail-header-from header)))
2553       (concat "=> " newsgroups))
2554      (t
2555       (or (car (funcall gnus-extract-address-components
2556                         (mail-header-from header)))
2557           (mail-header-from header))))))
2558
2559 (defun gnus-summary-insert-line (gnus-tmp-header
2560                                  gnus-tmp-level gnus-tmp-current
2561                                  gnus-tmp-unread gnus-tmp-replied
2562                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2563                                  &optional gnus-tmp-dummy gnus-tmp-score
2564                                  gnus-tmp-process)
2565   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2566          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2567          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2568          (gnus-tmp-score-char
2569           (if (or (null gnus-summary-default-score)
2570                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2571                       gnus-summary-zcore-fuzz))
2572               ? ;Whitespace
2573             (if (< gnus-tmp-score gnus-summary-default-score)
2574                 gnus-score-below-mark gnus-score-over-mark)))
2575          (gnus-tmp-replied
2576           (cond (gnus-tmp-process gnus-process-mark)
2577                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2578                  gnus-cached-mark)
2579                 (gnus-tmp-replied gnus-replied-mark)
2580                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2581                  gnus-saved-mark)
2582                 (t gnus-unread-mark)))
2583          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2584          (gnus-tmp-name
2585           (cond
2586            ((string-match "<[^>]+> *$" gnus-tmp-from)
2587             (let ((beg (match-beginning 0)))
2588               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2589                        (substring gnus-tmp-from (1+ (match-beginning 0))
2590                                   (1- (match-end 0))))
2591                   (substring gnus-tmp-from 0 beg))))
2592            ((string-match "(.+)" gnus-tmp-from)
2593             (substring gnus-tmp-from
2594                        (1+ (match-beginning 0)) (1- (match-end 0))))
2595            (t gnus-tmp-from)))
2596          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2597          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2598          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2599          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2600          (buffer-read-only nil))
2601     (when (string= gnus-tmp-name "")
2602       (setq gnus-tmp-name gnus-tmp-from))
2603     (unless (numberp gnus-tmp-lines)
2604       (setq gnus-tmp-lines 0))
2605     (gnus-put-text-property-excluding-characters-with-faces
2606      (point)
2607      (progn (eval gnus-summary-line-format-spec) (point))
2608      'gnus-number gnus-tmp-number)
2609     (when (gnus-visual-p 'summary-highlight 'highlight)
2610       (forward-line -1)
2611       (gnus-run-hooks 'gnus-summary-update-hook)
2612       (forward-line 1))))
2613
2614 (defun gnus-summary-update-line (&optional dont-update)
2615   ;; Update summary line after change.
2616   (when (and gnus-summary-default-score
2617              (not gnus-summary-inhibit-highlight))
2618     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2619            (article (gnus-summary-article-number))
2620            (score (gnus-summary-article-score article)))
2621       (unless dont-update
2622         (if (and gnus-summary-mark-below
2623                  (< (gnus-summary-article-score)
2624                     gnus-summary-mark-below))
2625             ;; This article has a low score, so we mark it as read.
2626             (when (memq article gnus-newsgroup-unreads)
2627               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2628           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2629             ;; This article was previously marked as read on account
2630             ;; of a low score, but now it has risen, so we mark it as
2631             ;; unread.
2632             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2633         (gnus-summary-update-mark
2634          (if (or (null gnus-summary-default-score)
2635                  (<= (abs (- score gnus-summary-default-score))
2636                      gnus-summary-zcore-fuzz))
2637              ? ;Whitespace
2638            (if (< score gnus-summary-default-score)
2639                gnus-score-below-mark gnus-score-over-mark))
2640          'score))
2641       ;; Do visual highlighting.
2642       (when (gnus-visual-p 'summary-highlight 'highlight)
2643         (gnus-run-hooks 'gnus-summary-update-hook)))))
2644
2645 (defvar gnus-tmp-new-adopts nil)
2646
2647 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2648   "Return the number of articles in THREAD.
2649 This may be 0 in some cases -- if none of the articles in
2650 the thread are to be displayed."
2651   (let* ((number
2652           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2653           (cond
2654            ((not (listp thread))
2655             1)
2656            ((and (consp thread) (cdr thread))
2657             (apply
2658              '+ 1 (mapcar
2659                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2660            ((null thread)
2661             1)
2662            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2663             1)
2664            (t 0))))
2665     (when (and level (zerop level) gnus-tmp-new-adopts)
2666       (incf number
2667             (apply '+ (mapcar
2668                        'gnus-summary-number-of-articles-in-thread
2669                        gnus-tmp-new-adopts))))
2670     (if char
2671         (if (> number 1) gnus-not-empty-thread-mark
2672           gnus-empty-thread-mark)
2673       number)))
2674
2675 (defun gnus-summary-set-local-parameters (group)
2676   "Go through the local params of GROUP and set all variable specs in that list."
2677   (let ((params (gnus-group-find-parameter group))
2678         elem)
2679     (while params
2680       (setq elem (car params)
2681             params (cdr params))
2682       (and (consp elem)                 ; Has to be a cons.
2683            (consp (cdr elem))           ; The cdr has to be a list.
2684            (symbolp (car elem))         ; Has to be a symbol in there.
2685            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2686            (ignore-errors               ; So we set it.
2687              (make-local-variable (car elem))
2688              (set (car elem) (eval (nth 1 elem))))))))
2689
2690 (defun gnus-summary-read-group (group &optional show-all no-article
2691                                       kill-buffer no-display backward
2692                                       select-articles)
2693   "Start reading news in newsgroup GROUP.
2694 If SHOW-ALL is non-nil, already read articles are also listed.
2695 If NO-ARTICLE is non-nil, no article is selected initially.
2696 If NO-DISPLAY, don't generate a summary buffer."
2697   (let (result)
2698     (while (and group
2699                 (null (setq result
2700                             (let ((gnus-auto-select-next nil))
2701                               (or (gnus-summary-read-group-1
2702                                    group show-all no-article
2703                                    kill-buffer no-display
2704                                    select-articles)
2705                                   (setq show-all nil
2706                                         select-articles nil)))))
2707                 (eq gnus-auto-select-next 'quietly))
2708       (set-buffer gnus-group-buffer)
2709       ;; The entry function called above goes to the next
2710       ;; group automatically, so we go two groups back
2711       ;; if we are searching for the previous group.
2712       (when backward
2713         (gnus-group-prev-unread-group 2))
2714       (if (not (equal group (gnus-group-group-name)))
2715           (setq group (gnus-group-group-name))
2716         (setq group nil)))
2717     result))
2718
2719 (defun gnus-summary-jump-to-other-group (group &optional show-all)
2720   "Directly jump to the other GROUP from summary buffer.
2721 If SHOW-ALL is non-nil, already read articles are also listed."
2722   (interactive
2723    (if (eq gnus-summary-buffer (current-buffer))
2724        (list (completing-read
2725               "Group: " gnus-active-hashtb nil t
2726               (when (and gnus-newsgroup-name
2727                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
2728                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
2729               'gnus-group-history)
2730              current-prefix-arg)
2731      (error "%s must be invoked from a gnus summary buffer." this-command)))
2732   (unless (or (zerop (length group))
2733               (and gnus-newsgroup-name
2734                    (string-equal gnus-newsgroup-name group)))
2735     (gnus-summary-exit)
2736     (gnus-summary-read-group group show-all
2737                              gnus-dont-select-after-jump-to-other-group)))
2738
2739 (defun gnus-summary-read-group-1 (group show-all no-article
2740                                         kill-buffer no-display
2741                                         &optional select-articles)
2742   ;; Killed foreign groups can't be entered.
2743   (when (and (not (gnus-group-native-p group))
2744              (not (gnus-gethash group gnus-newsrc-hashtb)))
2745     (error "Dead non-native groups can't be entered"))
2746   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2747   (let* ((new-group (gnus-summary-setup-buffer group))
2748          (quit-config (gnus-group-quit-config group))
2749          (did-select (and new-group (gnus-select-newsgroup
2750                                      group show-all select-articles))))
2751     (cond
2752      ;; This summary buffer exists already, so we just select it.
2753      ((not new-group)
2754       (gnus-set-global-variables)
2755       (when kill-buffer
2756         (gnus-kill-or-deaden-summary kill-buffer))
2757       (gnus-configure-windows 'summary 'force)
2758       (gnus-set-mode-line 'summary)
2759       (gnus-summary-position-point)
2760       (message "")
2761       t)
2762      ;; We couldn't select this group.
2763      ((null did-select)
2764       (when (and (eq major-mode 'gnus-summary-mode)
2765                  (not (equal (current-buffer) kill-buffer)))
2766         (kill-buffer (current-buffer))
2767         (if (not quit-config)
2768             (progn
2769               ;; Update the info -- marks might need to be removed,
2770               ;; for instance.
2771               (gnus-summary-update-info)
2772               (set-buffer gnus-group-buffer)
2773               (gnus-group-jump-to-group group)
2774               (gnus-group-next-unread-group 1))
2775           (gnus-handle-ephemeral-exit quit-config)))
2776       (gnus-message 3 "Can't select group")
2777       nil)
2778      ;; The user did a `C-g' while prompting for number of articles,
2779      ;; so we exit this group.
2780      ((eq did-select 'quit)
2781       (and (eq major-mode 'gnus-summary-mode)
2782            (not (equal (current-buffer) kill-buffer))
2783            (kill-buffer (current-buffer)))
2784       (when kill-buffer
2785         (gnus-kill-or-deaden-summary kill-buffer))
2786       (if (not quit-config)
2787           (progn
2788             (set-buffer gnus-group-buffer)
2789             (gnus-group-jump-to-group group)
2790             (gnus-group-next-unread-group 1)
2791             (gnus-configure-windows 'group 'force))
2792         (gnus-handle-ephemeral-exit quit-config))
2793       ;; Finally signal the quit.
2794       (signal 'quit nil))
2795      ;; The group was successfully selected.
2796      (t
2797       (gnus-set-global-variables)
2798       ;; Save the active value in effect when the group was entered.
2799       (setq gnus-newsgroup-active
2800             (gnus-copy-sequence
2801              (gnus-active gnus-newsgroup-name)))
2802       ;; You can change the summary buffer in some way with this hook.
2803       (gnus-run-hooks 'gnus-select-group-hook)
2804       ;; Set any local variables in the group parameters.
2805       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2806       (gnus-update-format-specifications
2807        nil 'summary 'summary-mode 'summary-dummy)
2808       (gnus-update-summary-mark-positions)
2809       ;; Do score processing.
2810       (when gnus-use-scoring
2811         (gnus-possibly-score-headers))
2812       ;; Check whether to fill in the gaps in the threads.
2813       (when gnus-build-sparse-threads
2814         (gnus-build-sparse-threads))
2815       ;; Find the initial limit.
2816       (if gnus-show-threads
2817           (if show-all
2818               (let ((gnus-newsgroup-dormant nil))
2819                 (gnus-summary-initial-limit show-all))
2820             (gnus-summary-initial-limit show-all))
2821         (setq gnus-newsgroup-limit
2822               (mapcar
2823                (lambda (header) (mail-header-number header))
2824                gnus-newsgroup-headers)))
2825       ;; Generate the summary buffer.
2826       (unless no-display
2827         (gnus-summary-prepare))
2828       (when gnus-use-trees
2829         (gnus-tree-open group)
2830         (setq gnus-summary-highlight-line-function
2831               'gnus-tree-highlight-article))
2832       ;; If the summary buffer is empty, but there are some low-scored
2833       ;; articles or some excluded dormants, we include these in the
2834       ;; buffer.
2835       (when (and (zerop (buffer-size))
2836                  (not no-display))
2837         (cond (gnus-newsgroup-dormant
2838                (gnus-summary-limit-include-dormant))
2839               ((and gnus-newsgroup-scored show-all)
2840                (gnus-summary-limit-include-expunged t))))
2841       ;; Function `gnus-apply-kill-file' must be called in this hook.
2842       (gnus-run-hooks 'gnus-apply-kill-hook)
2843       (if (and (zerop (buffer-size))
2844                (not no-display))
2845           (progn
2846             ;; This newsgroup is empty.
2847             (gnus-summary-catchup-and-exit nil t)
2848             (gnus-message 6 "No unread news")
2849             (when kill-buffer
2850               (gnus-kill-or-deaden-summary kill-buffer))
2851             ;; Return nil from this function.
2852             nil)
2853         ;; Hide conversation thread subtrees.  We cannot do this in
2854         ;; gnus-summary-prepare-hook since kill processing may not
2855         ;; work with hidden articles.
2856         (and gnus-show-threads
2857              gnus-thread-hide-subtree
2858              (gnus-summary-hide-all-threads))
2859         (when kill-buffer
2860           (gnus-kill-or-deaden-summary kill-buffer))
2861         ;; Show first unread article if requested.
2862         (if (and (not no-article)
2863                  (not no-display)
2864                  gnus-newsgroup-unreads
2865                  gnus-auto-select-first)
2866             (progn
2867               (gnus-configure-windows 'summary)
2868               (cond
2869                ((eq gnus-auto-select-first 'best)
2870                 (gnus-summary-best-unread-article))
2871                ((eq gnus-auto-select-first t)
2872                 (gnus-summary-first-unread-article))
2873                ((gnus-functionp gnus-auto-select-first)
2874                 (funcall gnus-auto-select-first))))
2875           ;; Don't select any articles, just move point to the first
2876           ;; article in the group.
2877           (goto-char (point-min))
2878           (gnus-summary-position-point)
2879           (gnus-configure-windows 'summary 'force)
2880           (gnus-set-mode-line 'summary))
2881         (when (get-buffer-window gnus-group-buffer t)
2882           ;; Gotta use windows, because recenter does weird stuff if
2883           ;; the current buffer ain't the displayed window.
2884           (let ((owin (selected-window)))
2885             (select-window (get-buffer-window gnus-group-buffer t))
2886             (when (gnus-group-goto-group group)
2887               (recenter))
2888             (select-window owin)))
2889         ;; Mark this buffer as "prepared".
2890         (setq gnus-newsgroup-prepared t)
2891         (gnus-run-hooks 'gnus-summary-prepared-hook)
2892         t)))))
2893
2894 (defun gnus-summary-prepare ()
2895   "Generate the summary buffer."
2896   (interactive)
2897   (let ((buffer-read-only nil))
2898     (erase-buffer)
2899     (setq gnus-newsgroup-data nil
2900           gnus-newsgroup-data-reverse nil)
2901     (gnus-run-hooks 'gnus-summary-generate-hook)
2902     ;; Generate the buffer, either with threads or without.
2903     (when gnus-newsgroup-headers
2904       (gnus-summary-prepare-threads
2905        (if gnus-show-threads
2906            (gnus-sort-gathered-threads
2907             (funcall gnus-summary-thread-gathering-function
2908                      (gnus-sort-threads
2909                       (gnus-cut-threads (gnus-make-threads)))))
2910          ;; Unthreaded display.
2911          (gnus-sort-articles gnus-newsgroup-headers))))
2912     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
2913     ;; Call hooks for modifying summary buffer.
2914     (goto-char (point-min))
2915     (gnus-run-hooks 'gnus-summary-prepare-hook)))
2916
2917 (defsubst gnus-general-simplify-subject (subject)
2918   "Simply subject by the same rules as gnus-gather-threads-by-subject."
2919   (setq subject
2920         (cond
2921          ;; Truncate the subject.
2922          (gnus-simplify-subject-functions
2923           (gnus-map-function gnus-simplify-subject-functions subject))
2924          ((numberp gnus-summary-gather-subject-limit)
2925           (setq subject (gnus-simplify-subject-re subject))
2926           (if (> (length subject) gnus-summary-gather-subject-limit)
2927               (substring subject 0 gnus-summary-gather-subject-limit)
2928             subject))
2929          ;; Fuzzily simplify it.
2930          ((eq 'fuzzy gnus-summary-gather-subject-limit)
2931           (gnus-simplify-subject-fuzzy subject))
2932          ;; Just remove the leading "Re:".
2933          (t
2934           (gnus-simplify-subject-re subject))))
2935
2936   (if (and gnus-summary-gather-exclude-subject
2937            (string-match gnus-summary-gather-exclude-subject subject))
2938       nil                               ; This article shouldn't be gathered
2939     subject))
2940
2941 (defun gnus-summary-simplify-subject-query ()
2942   "Query where the respool algorithm would put this article."
2943   (interactive)
2944   (gnus-summary-select-article)
2945   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
2946
2947 (defun gnus-gather-threads-by-subject (threads)
2948   "Gather threads by looking at Subject headers."
2949   (if (not gnus-summary-make-false-root)
2950       threads
2951     (let ((hashtb (gnus-make-hashtable 1024))
2952           (prev threads)
2953           (result threads)
2954           subject hthread whole-subject)
2955       (while threads
2956         (setq subject (gnus-general-simplify-subject
2957                        (setq whole-subject (mail-header-subject
2958                                             (caar threads)))))
2959         (when subject
2960           (if (setq hthread (gnus-gethash subject hashtb))
2961               (progn
2962                 ;; We enter a dummy root into the thread, if we
2963                 ;; haven't done that already.
2964                 (unless (stringp (caar hthread))
2965                   (setcar hthread (list whole-subject (car hthread))))
2966                 ;; We add this new gathered thread to this gathered
2967                 ;; thread.
2968                 (setcdr (car hthread)
2969                         (nconc (cdar hthread) (list (car threads))))
2970                 ;; Remove it from the list of threads.
2971                 (setcdr prev (cdr threads))
2972                 (setq threads prev))
2973             ;; Enter this thread into the hash table.
2974             (gnus-sethash subject threads hashtb)))
2975         (setq prev threads)
2976         (setq threads (cdr threads)))
2977       result)))
2978
2979 (defun gnus-gather-threads-by-references (threads)
2980   "Gather threads by looking at References headers."
2981   (let ((idhashtb (gnus-make-hashtable 1024))
2982         (thhashtb (gnus-make-hashtable 1024))
2983         (prev threads)
2984         (result threads)
2985         ids references id gthread gid entered ref)
2986     (while threads
2987       (when (setq references (mail-header-references (caar threads)))
2988         (setq id (mail-header-id (caar threads))
2989               ids (gnus-split-references references)
2990               entered nil)
2991         (while (setq ref (pop ids))
2992           (setq ids (delete ref ids))
2993           (if (not (setq gid (gnus-gethash ref idhashtb)))
2994               (progn
2995                 (gnus-sethash ref id idhashtb)
2996                 (gnus-sethash id threads thhashtb))
2997             (setq gthread (gnus-gethash gid thhashtb))
2998             (unless entered
2999               ;; We enter a dummy root into the thread, if we
3000               ;; haven't done that already.
3001               (unless (stringp (caar gthread))
3002                 (setcar gthread (list (mail-header-subject (caar gthread))
3003                                       (car gthread))))
3004               ;; We add this new gathered thread to this gathered
3005               ;; thread.
3006               (setcdr (car gthread)
3007                       (nconc (cdar gthread) (list (car threads)))))
3008             ;; Add it into the thread hash table.
3009             (gnus-sethash id gthread thhashtb)
3010             (setq entered t)
3011             ;; Remove it from the list of threads.
3012             (setcdr prev (cdr threads))
3013             (setq threads prev))))
3014       (setq prev threads)
3015       (setq threads (cdr threads)))
3016     result))
3017
3018 (defun gnus-sort-gathered-threads (threads)
3019   "Sort subtreads inside each gathered thread by article number."
3020   (let ((result threads))
3021     (while threads
3022       (when (stringp (caar threads))
3023         (setcdr (car threads)
3024                 (sort (cdar threads) 'gnus-thread-sort-by-number)))
3025       (setq threads (cdr threads)))
3026     result))
3027
3028 (defun gnus-thread-loop-p (root thread)
3029   "Say whether ROOT is in THREAD."
3030   (let ((stack (list thread))
3031         (infloop 0)
3032         th)
3033     (while (setq thread (pop stack))
3034       (setq th (cdr thread))
3035       (while (and th
3036                   (not (eq (caar th) root)))
3037         (pop th))
3038       (if th
3039           ;; We have found a loop.
3040           (let (ref-dep)
3041             (setcdr thread (delq (car th) (cdr thread)))
3042             (if (boundp (setq ref-dep (intern "none"
3043                                               gnus-newsgroup-dependencies)))
3044                 (setcdr (symbol-value ref-dep)
3045                         (nconc (cdr (symbol-value ref-dep))
3046                                (list (car th))))
3047               (set ref-dep (list nil (car th))))
3048             (setq infloop 1
3049                   stack nil))
3050         ;; Push all the subthreads onto the stack.
3051         (push (cdr thread) stack)))
3052     infloop))
3053
3054 (defun gnus-make-threads ()
3055   "Go through the dependency hashtb and find the roots.  Return all threads."
3056   (let (threads)
3057     (while (catch 'infloop
3058              (mapatoms
3059               (lambda (refs)
3060                 ;; Deal with self-referencing References loops.
3061                 (when (and (car (symbol-value refs))
3062                            (not (zerop
3063                                  (apply
3064                                   '+
3065                                   (mapcar
3066                                    (lambda (thread)
3067                                      (gnus-thread-loop-p
3068                                       (car (symbol-value refs)) thread))
3069                                    (cdr (symbol-value refs)))))))
3070                   (setq threads nil)
3071                   (throw 'infloop t))
3072                 (unless (car (symbol-value refs))
3073                   ;; These threads do not refer back to any other articles,
3074                   ;; so they're roots.
3075                   (setq threads (append (cdr (symbol-value refs)) threads))))
3076               gnus-newsgroup-dependencies)))
3077     threads))
3078
3079 ;; Build the thread tree.
3080 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3081   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3082
3083 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3084 if it was already present.
3085
3086 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3087 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3088 Message-IDs will be renamed be renamed to a unique Message-ID before
3089 being entered.
3090
3091 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3092   (let* ((id (mail-header-id header))
3093          (id-dep (and id (intern id dependencies)))
3094          ref ref-dep ref-header)
3095     ;; Enter this `header' in the `dependencies' table.
3096     (cond
3097      ((not id-dep)
3098       (setq header nil))
3099      ;; The first two cases do the normal part: enter a new `header'
3100      ;; in the `dependencies' table.
3101      ((not (boundp id-dep))
3102       (set id-dep (list header)))
3103      ((null (car (symbol-value id-dep)))
3104       (setcar (symbol-value id-dep) header))
3105
3106      ;; From here the `header' was already present in the
3107      ;; `dependencies' table.
3108      (force-new
3109       ;; Overrides an existing entry;
3110       ;; just set the header part of the entry.
3111       (setcar (symbol-value id-dep) header))
3112
3113      ;; Renames the existing `header' to a unique Message-ID.
3114      ((not gnus-summary-ignore-duplicates)
3115       ;; An article with this Message-ID has already been seen.
3116       ;; We rename the Message-ID.
3117       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3118            (list header))
3119       (mail-header-set-id header id))
3120
3121      ;; The last case ignores an existing entry, except it adds any
3122      ;; additional Xrefs (in case the two articles came from different
3123      ;; servers.
3124      ;; Also sets `header' to `nil' meaning that the `dependencies'
3125      ;; table was *not* modified.
3126      (t
3127       (mail-header-set-xref
3128        (car (symbol-value id-dep))
3129        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3130                    "")
3131                (or (mail-header-xref header) "")))
3132       (setq header nil)))
3133
3134     (when header
3135       ;; First check if that we are not creating a References loop.
3136       (setq ref (gnus-parent-id (mail-header-references header)))
3137       (while (and ref
3138                   (setq ref-dep (intern-soft ref dependencies))
3139                   (boundp ref-dep)
3140                   (setq ref-header (car (symbol-value ref-dep))))
3141         (if (string= id ref)
3142             ;; Yuk!  This is a reference loop.  Make the article be a
3143             ;; root article.
3144             (progn
3145               (mail-header-set-references (car (symbol-value id-dep)) "none")
3146               (setq ref nil))
3147           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3148       (setq ref (gnus-parent-id (mail-header-references header)))
3149       (setq ref-dep (intern (or ref "none") dependencies))
3150       (if (boundp ref-dep)
3151           (setcdr (symbol-value ref-dep)
3152                   (nconc (cdr (symbol-value ref-dep))
3153                          (list (symbol-value id-dep))))
3154         (set ref-dep (list nil (symbol-value id-dep)))))
3155     header))
3156
3157 (defun gnus-build-sparse-threads ()
3158   (let ((headers gnus-newsgroup-headers)
3159         (gnus-summary-ignore-duplicates t)
3160         header references generation relations
3161         subject child end new-child date)
3162     ;; First we create an alist of generations/relations, where
3163     ;; generations is how much we trust the relation, and the relation
3164     ;; is parent/child.
3165     (gnus-message 7 "Making sparse threads...")
3166     (save-excursion
3167       (nnheader-set-temp-buffer " *gnus sparse threads*")
3168       (while (setq header (pop headers))
3169         (when (and (setq references (mail-header-references header))
3170                    (not (string= references "")))
3171           (insert references)
3172           (setq child (mail-header-id header)
3173                 subject (mail-header-subject header)
3174                 date (mail-header-date header)
3175                 generation 0)
3176           (while (search-backward ">" nil t)
3177             (setq end (1+ (point)))
3178             (when (search-backward "<" nil t)
3179               (setq new-child (buffer-substring (point) end))
3180               (push (list (incf generation)
3181                           child (setq child new-child)
3182                           subject date)
3183                     relations)))
3184           (when child
3185             (push (list (1+ generation) child nil subject) relations))
3186           (erase-buffer)))
3187       (kill-buffer (current-buffer)))
3188     ;; Sort over trustworthiness.
3189     (mapcar
3190      (lambda (relation)
3191        (when (gnus-dependencies-add-header
3192               (make-full-mail-header
3193                gnus-reffed-article-number
3194                (nth 3 relation) "" (or (nth 4 relation) "")
3195                (nth 1 relation)
3196                (or (nth 2 relation) "") 0 0 "")
3197               gnus-newsgroup-dependencies nil)
3198          (push gnus-reffed-article-number gnus-newsgroup-limit)
3199          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3200          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3201                gnus-newsgroup-reads)
3202          (decf gnus-reffed-article-number)))
3203      (sort relations 'car-less-than-car))
3204     (gnus-message 7 "Making sparse threads...done")))
3205
3206 (defun gnus-build-old-threads ()
3207   ;; Look at all the articles that refer back to old articles, and
3208   ;; fetch the headers for the articles that aren't there.  This will
3209   ;; build complete threads - if the roots haven't been expired by the
3210   ;; server, that is.
3211   (let (id heads)
3212     (mapatoms
3213      (lambda (refs)
3214        (when (not (car (symbol-value refs)))
3215          (setq heads (cdr (symbol-value refs)))
3216          (while heads
3217            (if (memq (mail-header-number (caar heads))
3218                      gnus-newsgroup-dormant)
3219                (setq heads (cdr heads))
3220              (setq id (symbol-name refs))
3221              (while (and (setq id (gnus-build-get-header id))
3222                          (not (car (gnus-id-to-thread id)))))
3223              (setq heads nil)))))
3224      gnus-newsgroup-dependencies)))
3225
3226 ;; This function has to be called with point after the article number
3227 ;; on the beginning of the line.
3228 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3229   (let ((eol (gnus-point-at-eol))
3230         (buffer (current-buffer))
3231         header)
3232
3233     ;; overview: [num subject from date id refs chars lines misc]
3234     (unless (eobp)
3235       (forward-char))
3236
3237     (setq header
3238           (make-full-mail-header
3239            number                               ; number
3240            (nnheader-nov-field)                 ; subject
3241            (nnheader-nov-field)                 ; from
3242            (nnheader-nov-field)                 ; date
3243            (nnheader-nov-read-message-id)       ; id
3244            (nnheader-nov-field)                 ; refs
3245            (nnheader-nov-read-integer)          ; chars
3246            (nnheader-nov-read-integer)          ; lines
3247            (unless (eobp)
3248              (nnheader-nov-field))              ; misc
3249            (nnheader-nov-parse-extra)))         ; extra
3250
3251     (when gnus-alter-header-function
3252       (funcall gnus-alter-header-function header))
3253     (gnus-dependencies-add-header header dependencies force-new)))
3254
3255 (defun gnus-build-get-header (id)
3256   ;; Look through the buffer of NOV lines and find the header to
3257   ;; ID.  Enter this line into the dependencies hash table, and return
3258   ;; the id of the parent article (if any).
3259   (let ((deps gnus-newsgroup-dependencies)
3260         found header)
3261     (prog1
3262         (save-excursion
3263           (set-buffer nntp-server-buffer)
3264           (let ((case-fold-search nil))
3265             (goto-char (point-min))
3266             (while (and (not found)
3267                         (search-forward id nil t))
3268               (beginning-of-line)
3269               (setq found (looking-at
3270                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3271                                    (regexp-quote id))))
3272               (or found (beginning-of-line 2)))
3273             (when found
3274               (beginning-of-line)
3275               (and
3276                (setq header (gnus-nov-parse-line
3277                              (read (current-buffer)) deps))
3278                (gnus-parent-id (mail-header-references header))))))
3279       (when header
3280         (let ((number (mail-header-number header)))
3281           (push number gnus-newsgroup-limit)
3282           (push header gnus-newsgroup-headers)
3283           (if (memq number gnus-newsgroup-unselected)
3284               (progn
3285                 (push number gnus-newsgroup-unreads)
3286                 (setq gnus-newsgroup-unselected
3287                       (delq number gnus-newsgroup-unselected)))
3288             (push number gnus-newsgroup-ancient)))))))
3289
3290 (defun gnus-build-all-threads ()
3291   "Read all the headers."
3292   (let ((gnus-summary-ignore-duplicates t)
3293         (dependencies gnus-newsgroup-dependencies)
3294         header article)
3295     (save-excursion
3296       (set-buffer nntp-server-buffer)
3297       (let ((case-fold-search nil))
3298         (goto-char (point-min))
3299         (while (not (eobp))
3300           (ignore-errors
3301             (setq article (read (current-buffer))
3302                   header (gnus-nov-parse-line
3303                           article dependencies)))
3304           (when header
3305             (save-excursion
3306               (set-buffer gnus-summary-buffer)
3307               (push header gnus-newsgroup-headers)
3308               (if (memq (setq article (mail-header-number header))
3309                         gnus-newsgroup-unselected)
3310                   (progn
3311                     (push article gnus-newsgroup-unreads)
3312                     (setq gnus-newsgroup-unselected
3313                           (delq article gnus-newsgroup-unselected)))
3314                 (push article gnus-newsgroup-ancient)))
3315             (forward-line 1)))))))
3316
3317 (defun gnus-summary-update-article-line (article header)
3318   "Update the line for ARTICLE using HEADERS."
3319   (let* ((id (mail-header-id header))
3320          (thread (gnus-id-to-thread id)))
3321     (unless thread
3322       (error "Article in no thread"))
3323     ;; Update the thread.
3324     (setcar thread header)
3325     (gnus-summary-goto-subject article)
3326     (let* ((datal (gnus-data-find-list article))
3327            (data (car datal))
3328            (length (when (cdr datal)
3329                      (- (gnus-data-pos data)
3330                         (gnus-data-pos (cadr datal)))))
3331            (buffer-read-only nil)
3332            (level (gnus-summary-thread-level)))
3333       (gnus-delete-line)
3334       (gnus-summary-insert-line
3335        header level nil (gnus-article-mark article)
3336        (memq article gnus-newsgroup-replied)
3337        (memq article gnus-newsgroup-expirable)
3338        ;; Only insert the Subject string when it's different
3339        ;; from the previous Subject string.
3340        (if (gnus-subject-equal
3341             (condition-case ()
3342                 (mail-header-subject
3343                  (gnus-data-header
3344                   (cadr
3345                    (gnus-data-find-list
3346                     article
3347                     (gnus-data-list t)))))
3348               ;; Error on the side of excessive subjects.
3349               (error ""))
3350             (mail-header-subject header))
3351            ""
3352          (mail-header-subject header))
3353        nil (cdr (assq article gnus-newsgroup-scored))
3354        (memq article gnus-newsgroup-processable))
3355       (when length
3356         (gnus-data-update-list
3357          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3358
3359 (defun gnus-summary-update-article (article &optional iheader)
3360   "Update ARTICLE in the summary buffer."
3361   (set-buffer gnus-summary-buffer)
3362   (let* ((header (gnus-summary-article-header article))
3363          (id (mail-header-id header))
3364          (data (gnus-data-find article))
3365          (thread (gnus-id-to-thread id))
3366          (references (mail-header-references header))
3367          (parent
3368           (gnus-id-to-thread
3369            (or (gnus-parent-id
3370                 (when (and references
3371                            (not (equal "" references)))
3372                   references))
3373                "none")))
3374          (buffer-read-only nil)
3375          (old (car thread)))
3376     (when thread
3377       (unless iheader
3378         (setcar thread nil)
3379         (when parent
3380           (delq thread parent)))
3381       (if (gnus-summary-insert-subject id header)
3382           ;; Set the (possibly) new article number in the data structure.
3383           (gnus-data-set-number data (gnus-id-to-article id))
3384         (setcar thread old)
3385         nil))))
3386
3387 (defun gnus-rebuild-thread (id &optional line)
3388   "Rebuild the thread containing ID.
3389 If LINE, insert the rebuilt thread starting on line LINE."
3390   (let ((buffer-read-only nil)
3391         old-pos current thread data)
3392     (if (not gnus-show-threads)
3393         (setq thread (list (car (gnus-id-to-thread id))))
3394       ;; Get the thread this article is part of.
3395       (setq thread (gnus-remove-thread id)))
3396     (setq old-pos (gnus-point-at-bol))
3397     (setq current (save-excursion
3398                     (and (zerop (forward-line -1))
3399                          (gnus-summary-article-number))))
3400     ;; If this is a gathered thread, we have to go some re-gathering.
3401     (when (stringp (car thread))
3402       (let ((subject (car thread))
3403             roots thr)
3404         (setq thread (cdr thread))
3405         (while thread
3406           (unless (memq (setq thr (gnus-id-to-thread
3407                                    (gnus-root-id
3408                                     (mail-header-id (caar thread)))))
3409                         roots)
3410             (push thr roots))
3411           (setq thread (cdr thread)))
3412         ;; We now have all (unique) roots.
3413         (if (= (length roots) 1)
3414             ;; All the loose roots are now one solid root.
3415             (setq thread (car roots))
3416           (setq thread (cons subject (gnus-sort-threads roots))))))
3417     (let (threads)
3418       ;; We then insert this thread into the summary buffer.
3419       (when line
3420         (goto-char (point-min))
3421         (forward-line (1- line)))
3422       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3423         (if gnus-show-threads
3424             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3425           (gnus-summary-prepare-unthreaded thread))
3426         (setq data (nreverse gnus-newsgroup-data))
3427         (setq threads gnus-newsgroup-threads))
3428       ;; We splice the new data into the data structure.
3429       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3430       ;;!!! then we want to insert at the beginning of the buffer.
3431       ;;!!! That happens to be true with Gnus now, but that may
3432       ;;!!! change in the future.  Perhaps.
3433       (gnus-data-enter-list
3434        (if line nil current) data (- (point) old-pos))
3435       (setq gnus-newsgroup-threads
3436             (nconc threads gnus-newsgroup-threads))
3437       (gnus-data-compute-positions))))
3438
3439 (defun gnus-number-to-header (number)
3440   "Return the header for article NUMBER."
3441   (let ((headers gnus-newsgroup-headers))
3442     (while (and headers
3443                 (not (= number (mail-header-number (car headers)))))
3444       (pop headers))
3445     (when headers
3446       (car headers))))
3447
3448 (defun gnus-parent-headers (in-headers &optional generation)
3449   "Return the headers of the GENERATIONeth parent of HEADERS."
3450   (unless generation
3451     (setq generation 1))
3452   (let ((parent t)
3453         (headers in-headers)
3454         references)
3455     (while (and parent
3456                 (not (zerop generation))
3457                 (setq references (mail-header-references headers)))
3458       (setq headers (if (and references
3459                              (setq parent (gnus-parent-id references)))
3460                         (car (gnus-id-to-thread parent))
3461                       nil))
3462       (decf generation))
3463     (and (not (eq headers in-headers))
3464          headers)))
3465
3466 (defun gnus-id-to-thread (id)
3467   "Return the (sub-)thread where ID appears."
3468   (gnus-gethash id gnus-newsgroup-dependencies))
3469
3470 (defun gnus-id-to-article (id)
3471   "Return the article number of ID."
3472   (let ((thread (gnus-id-to-thread id)))
3473     (when (and thread
3474                (car thread))
3475       (mail-header-number (car thread)))))
3476
3477 (defun gnus-id-to-header (id)
3478   "Return the article headers of ID."
3479   (car (gnus-id-to-thread id)))
3480
3481 (defun gnus-article-displayed-root-p (article)
3482   "Say whether ARTICLE is a root(ish) article."
3483   (let ((level (gnus-summary-thread-level article))
3484         (refs (mail-header-references  (gnus-summary-article-header article)))
3485         particle)
3486     (cond
3487      ((null level) nil)
3488      ((zerop level) t)
3489      ((null refs) t)
3490      ((null (gnus-parent-id refs)) t)
3491      ((and (= 1 level)
3492            (null (setq particle (gnus-id-to-article
3493                                  (gnus-parent-id refs))))
3494            (null (gnus-summary-thread-level particle)))))))
3495
3496 (defun gnus-root-id (id)
3497   "Return the id of the root of the thread where ID appears."
3498   (let (last-id prev)
3499     (while (and id (setq prev (car (gnus-id-to-thread id))))
3500       (setq last-id id
3501             id (gnus-parent-id (mail-header-references prev))))
3502     last-id))
3503
3504 (defun gnus-articles-in-thread (thread)
3505   "Return the list of articles in THREAD."
3506   (cons (mail-header-number (car thread))
3507         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3508
3509 (defun gnus-remove-thread (id &optional dont-remove)
3510   "Remove the thread that has ID in it."
3511   (let (headers thread last-id)
3512     ;; First go up in this thread until we find the root.
3513     (setq last-id (gnus-root-id id)
3514           headers (message-flatten-list (gnus-id-to-thread last-id)))
3515     ;; We have now found the real root of this thread.  It might have
3516     ;; been gathered into some loose thread, so we have to search
3517     ;; through the threads to find the thread we wanted.
3518     (let ((threads gnus-newsgroup-threads)
3519           sub)
3520       (while threads
3521         (setq sub (car threads))
3522         (if (stringp (car sub))
3523             ;; This is a gathered thread, so we look at the roots
3524             ;; below it to find whether this article is in this
3525             ;; gathered root.
3526             (progn
3527               (setq sub (cdr sub))
3528               (while sub
3529                 (when (member (caar sub) headers)
3530                   (setq thread (car threads)
3531                         threads nil
3532                         sub nil))
3533                 (setq sub (cdr sub))))
3534           ;; It's an ordinary thread, so we check it.
3535           (when (eq (car sub) (car headers))
3536             (setq thread sub
3537                   threads nil)))
3538         (setq threads (cdr threads)))
3539       ;; If this article is in no thread, then it's a root.
3540       (if thread
3541           (unless dont-remove
3542             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3543         (setq thread (gnus-id-to-thread last-id)))
3544       (when thread
3545         (prog1
3546             thread                      ; We return this thread.
3547           (unless dont-remove
3548             (if (stringp (car thread))
3549                 (progn
3550                   ;; If we use dummy roots, then we have to remove the
3551                   ;; dummy root as well.
3552                   (when (eq gnus-summary-make-false-root 'dummy)
3553                     ;; We go to the dummy root by going to
3554                     ;; the first sub-"thread", and then one line up.
3555                     (gnus-summary-goto-article
3556                      (mail-header-number (caadr thread)))
3557                     (forward-line -1)
3558                     (gnus-delete-line)
3559                     (gnus-data-compute-positions))
3560                   (setq thread (cdr thread))
3561                   (while thread
3562                     (gnus-remove-thread-1 (car thread))
3563                     (setq thread (cdr thread))))
3564               (gnus-summary-show-all-threads)
3565               (gnus-remove-thread-1 thread))))))))
3566
3567 (defun gnus-remove-thread-1 (thread)
3568   "Remove the thread THREAD recursively."
3569   (let ((number (mail-header-number (pop thread)))
3570         d)
3571     (setq thread (reverse thread))
3572     (while thread
3573       (gnus-remove-thread-1 (pop thread)))
3574     (when (setq d (gnus-data-find number))
3575       (goto-char (gnus-data-pos d))
3576       (gnus-data-remove
3577        number
3578        (- (gnus-point-at-bol)
3579           (prog1
3580               (1+ (gnus-point-at-eol))
3581             (gnus-delete-line)))))))
3582
3583 (defun gnus-sort-threads (threads)
3584   "Sort THREADS."
3585   (if (not gnus-thread-sort-functions)
3586       threads
3587     (gnus-message 8 "Sorting threads...")
3588     (prog1
3589         (sort threads (gnus-make-sort-function gnus-thread-sort-functions))
3590       (gnus-message 8 "Sorting threads...done"))))
3591
3592 (defun gnus-sort-articles (articles)
3593   "Sort ARTICLES."
3594   (when gnus-article-sort-functions
3595     (gnus-message 7 "Sorting articles...")
3596     (prog1
3597         (setq gnus-newsgroup-headers
3598               (sort articles (gnus-make-sort-function
3599                               gnus-article-sort-functions)))
3600       (gnus-message 7 "Sorting articles...done"))))
3601
3602 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3603 (defmacro gnus-thread-header (thread)
3604   ;; Return header of first article in THREAD.
3605   ;; Note that THREAD must never, ever be anything else than a variable -
3606   ;; using some other form will lead to serious barfage.
3607   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3608   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3609   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
3610         (vector thread) 2))
3611
3612 (defsubst gnus-article-sort-by-number (h1 h2)
3613   "Sort articles by article number."
3614   (< (mail-header-number h1)
3615      (mail-header-number h2)))
3616
3617 (defun gnus-thread-sort-by-number (h1 h2)
3618   "Sort threads by root article number."
3619   (gnus-article-sort-by-number
3620    (gnus-thread-header h1) (gnus-thread-header h2)))
3621
3622 (defsubst gnus-article-sort-by-lines (h1 h2)
3623   "Sort articles by article Lines header."
3624   (< (mail-header-lines h1)
3625      (mail-header-lines h2)))
3626
3627 (defun gnus-thread-sort-by-lines (h1 h2)
3628   "Sort threads by root article Lines header."
3629   (gnus-article-sort-by-lines
3630    (gnus-thread-header h1) (gnus-thread-header h2)))
3631
3632 (defsubst gnus-article-sort-by-chars (h1 h2)
3633   "Sort articles by octet length."
3634   (< (mail-header-chars h1)
3635      (mail-header-chars h2)))
3636
3637 (defun gnus-thread-sort-by-chars (h1 h2)
3638   "Sort threads by root article octet length."
3639   (gnus-article-sort-by-chars
3640    (gnus-thread-header h1) (gnus-thread-header h2)))
3641
3642 (defsubst gnus-article-sort-by-author (h1 h2)
3643   "Sort articles by root author."
3644   (string-lessp
3645    (let ((addr (car (mime-read-field 'From h1))))
3646      (or (std11-full-name-string addr)
3647          (std11-address-string addr)
3648          ""))
3649    (let ((addr (car (mime-read-field 'From h2))))
3650      (or (std11-full-name-string addr)
3651          (std11-address-string addr)
3652          ""))
3653    ))
3654
3655 (defun gnus-thread-sort-by-author (h1 h2)
3656   "Sort threads by root author."
3657   (gnus-article-sort-by-author
3658    (gnus-thread-header h1)  (gnus-thread-header h2)))
3659
3660 (defsubst gnus-article-sort-by-subject (h1 h2)
3661   "Sort articles by root subject."
3662   (string-lessp
3663    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3664    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3665
3666 (defun gnus-thread-sort-by-subject (h1 h2)
3667   "Sort threads by root subject."
3668   (gnus-article-sort-by-subject
3669    (gnus-thread-header h1) (gnus-thread-header h2)))
3670
3671 (defsubst gnus-article-sort-by-date (h1 h2)
3672   "Sort articles by root article date."
3673   (time-less-p
3674    (gnus-date-get-time (mail-header-date h1))
3675    (gnus-date-get-time (mail-header-date h2))))
3676
3677 (defun gnus-thread-sort-by-date (h1 h2)
3678   "Sort threads by root article date."
3679   (gnus-article-sort-by-date
3680    (gnus-thread-header h1) (gnus-thread-header h2)))
3681
3682 (defsubst gnus-article-sort-by-score (h1 h2)
3683   "Sort articles by root article score.
3684 Unscored articles will be counted as having a score of zero."
3685   (> (or (cdr (assq (mail-header-number h1)
3686                     gnus-newsgroup-scored))
3687          gnus-summary-default-score 0)
3688      (or (cdr (assq (mail-header-number h2)
3689                     gnus-newsgroup-scored))
3690          gnus-summary-default-score 0)))
3691
3692 (defun gnus-thread-sort-by-score (h1 h2)
3693   "Sort threads by root article score."
3694   (gnus-article-sort-by-score
3695    (gnus-thread-header h1) (gnus-thread-header h2)))
3696
3697 (defun gnus-thread-sort-by-total-score (h1 h2)
3698   "Sort threads by the sum of all scores in the thread.
3699 Unscored articles will be counted as having a score of zero."
3700   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3701
3702 (defun gnus-thread-total-score (thread)
3703   ;; This function find the total score of THREAD.
3704   (cond ((null thread)
3705          0)
3706         ((consp thread)
3707          (if (stringp (car thread))
3708              (apply gnus-thread-score-function 0
3709                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3710            (gnus-thread-total-score-1 thread)))
3711         (t
3712          (gnus-thread-total-score-1 (list thread)))))
3713
3714 (defun gnus-thread-total-score-1 (root)
3715   ;; This function find the total score of the thread below ROOT.
3716   (setq root (car root))
3717   (apply gnus-thread-score-function
3718          (or (append
3719               (mapcar 'gnus-thread-total-score
3720                       (cdr (gnus-id-to-thread (mail-header-id root))))
3721               (when (> (mail-header-number root) 0)
3722                 (list (or (cdr (assq (mail-header-number root)
3723                                      gnus-newsgroup-scored))
3724                           gnus-summary-default-score 0))))
3725              (list gnus-summary-default-score)
3726              '(0))))
3727
3728 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3729 (defvar gnus-tmp-prev-subject nil)
3730 (defvar gnus-tmp-false-parent nil)
3731 (defvar gnus-tmp-root-expunged nil)
3732 (defvar gnus-tmp-dummy-line nil)
3733
3734 (defvar gnus-tmp-header)
3735 (defun gnus-extra-header (type &optional header)
3736   "Return the extra header of TYPE."
3737   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3738       ""))
3739
3740 (defun gnus-summary-prepare-threads (threads)
3741   "Prepare summary buffer from THREADS and indentation LEVEL.
3742 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3743 or a straight list of headers."
3744   (gnus-message 7 "Generating summary...")
3745
3746   (setq gnus-newsgroup-threads threads)
3747   (beginning-of-line)
3748
3749   (let ((gnus-tmp-level 0)
3750         (default-score (or gnus-summary-default-score 0))
3751         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3752         thread number subject stack state gnus-tmp-gathered beg-match
3753         new-roots gnus-tmp-new-adopts thread-end
3754         gnus-tmp-header gnus-tmp-unread
3755         gnus-tmp-replied gnus-tmp-subject-or-nil
3756         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3757         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3758         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3759
3760     (setq gnus-tmp-prev-subject nil)
3761
3762     (if (vectorp (car threads))
3763         ;; If this is a straight (sic) list of headers, then a
3764         ;; threaded summary display isn't required, so we just create
3765         ;; an unthreaded one.
3766         (gnus-summary-prepare-unthreaded threads)
3767
3768       ;; Do the threaded display.
3769
3770       (while (or threads stack gnus-tmp-new-adopts new-roots)
3771
3772         (if (and (= gnus-tmp-level 0)
3773                  (or (not stack)
3774                      (= (caar stack) 0))
3775                  (not gnus-tmp-false-parent)
3776                  (or gnus-tmp-new-adopts new-roots))
3777             (if gnus-tmp-new-adopts
3778                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3779                       thread (list (car gnus-tmp-new-adopts))
3780                       gnus-tmp-header (caar thread)
3781                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3782               (when new-roots
3783                 (setq thread (list (car new-roots))
3784                       gnus-tmp-header (caar thread)
3785                       new-roots (cdr new-roots))))
3786
3787           (if threads
3788               ;; If there are some threads, we do them before the
3789               ;; threads on the stack.
3790               (setq thread threads
3791                     gnus-tmp-header (caar thread))
3792             ;; There were no current threads, so we pop something off
3793             ;; the stack.
3794             (setq state (car stack)
3795                   gnus-tmp-level (car state)
3796                   thread (cdr state)
3797                   stack (cdr stack)
3798                   gnus-tmp-header (caar thread))))
3799
3800         (setq gnus-tmp-false-parent nil)
3801         (setq gnus-tmp-root-expunged nil)
3802         (setq thread-end nil)
3803
3804         (if (stringp gnus-tmp-header)
3805             ;; The header is a dummy root.
3806             (cond
3807              ((eq gnus-summary-make-false-root 'adopt)
3808               ;; We let the first article adopt the rest.
3809               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3810                                                (cddar thread)))
3811               (setq gnus-tmp-gathered
3812                     (nconc (mapcar
3813                             (lambda (h) (mail-header-number (car h)))
3814                             (cddar thread))
3815                            gnus-tmp-gathered))
3816               (setq thread (cons (list (caar thread)
3817                                        (cadar thread))
3818                                  (cdr thread)))
3819               (setq gnus-tmp-level -1
3820                     gnus-tmp-false-parent t))
3821              ((eq gnus-summary-make-false-root 'empty)
3822               ;; We print adopted articles with empty subject fields.
3823               (setq gnus-tmp-gathered
3824                     (nconc (mapcar
3825                             (lambda (h) (mail-header-number (car h)))
3826                             (cddar thread))
3827                            gnus-tmp-gathered))
3828               (setq gnus-tmp-level -1))
3829              ((eq gnus-summary-make-false-root 'dummy)
3830               ;; We remember that we probably want to output a dummy
3831               ;; root.
3832               (setq gnus-tmp-dummy-line gnus-tmp-header)
3833               (setq gnus-tmp-prev-subject gnus-tmp-header))
3834              (t
3835               ;; We do not make a root for the gathered
3836               ;; sub-threads at all.
3837               (setq gnus-tmp-level -1)))
3838
3839           (setq number (mail-header-number gnus-tmp-header)
3840                 subject (mail-header-subject gnus-tmp-header))
3841
3842           (cond
3843            ;; If the thread has changed subject, we might want to make
3844            ;; this subthread into a root.
3845            ((and (null gnus-thread-ignore-subject)
3846                  (not (zerop gnus-tmp-level))
3847                  gnus-tmp-prev-subject
3848                  (not (inline
3849                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
3850             (setq new-roots (nconc new-roots (list (car thread)))
3851                   thread-end t
3852                   gnus-tmp-header nil))
3853            ;; If the article lies outside the current limit,
3854            ;; then we do not display it.
3855            ((not (memq number gnus-newsgroup-limit))
3856             (setq gnus-tmp-gathered
3857                   (nconc (mapcar
3858                           (lambda (h) (mail-header-number (car h)))
3859                           (cdar thread))
3860                          gnus-tmp-gathered))
3861             (setq gnus-tmp-new-adopts (if (cdar thread)
3862                                           (append gnus-tmp-new-adopts
3863                                                   (cdar thread))
3864                                         gnus-tmp-new-adopts)
3865                   thread-end t
3866                   gnus-tmp-header nil)
3867             (when (zerop gnus-tmp-level)
3868               (setq gnus-tmp-root-expunged t)))
3869            ;; Perhaps this article is to be marked as read?
3870            ((and gnus-summary-mark-below
3871                  (< (or (cdr (assq number gnus-newsgroup-scored))
3872                         default-score)
3873                     gnus-summary-mark-below)
3874                  ;; Don't touch sparse articles.
3875                  (not (gnus-summary-article-sparse-p number))
3876                  (not (gnus-summary-article-ancient-p number)))
3877             (setq gnus-newsgroup-unreads
3878                   (delq number gnus-newsgroup-unreads))
3879             (if gnus-newsgroup-auto-expire
3880                 (push number gnus-newsgroup-expirable)
3881               (push (cons number gnus-low-score-mark)
3882                     gnus-newsgroup-reads))))
3883
3884           (when gnus-tmp-header
3885             ;; We may have an old dummy line to output before this
3886             ;; article.
3887             (when (and gnus-tmp-dummy-line
3888                        (gnus-subject-equal
3889                         gnus-tmp-dummy-line
3890                         (mail-header-subject gnus-tmp-header)))
3891               (gnus-summary-insert-dummy-line
3892                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
3893               (setq gnus-tmp-dummy-line nil))
3894
3895             ;; Compute the mark.
3896             (setq gnus-tmp-unread (gnus-article-mark number))
3897
3898             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
3899                                   gnus-tmp-header gnus-tmp-level)
3900                   gnus-newsgroup-data)
3901
3902             ;; Actually insert the line.
3903             (setq
3904              gnus-tmp-subject-or-nil
3905              (cond
3906               ((and gnus-thread-ignore-subject
3907                     gnus-tmp-prev-subject
3908                     (not (inline (gnus-subject-equal
3909                                   gnus-tmp-prev-subject subject))))
3910                subject)
3911               ((zerop gnus-tmp-level)
3912                (if (and (eq gnus-summary-make-false-root 'empty)
3913                         (memq number gnus-tmp-gathered)
3914                         gnus-tmp-prev-subject
3915                         (inline (gnus-subject-equal
3916                                  gnus-tmp-prev-subject subject)))
3917                    gnus-summary-same-subject
3918                  subject))
3919               (t gnus-summary-same-subject)))
3920             (if (and (eq gnus-summary-make-false-root 'adopt)
3921                      (= gnus-tmp-level 1)
3922                      (memq number gnus-tmp-gathered))
3923                 (setq gnus-tmp-opening-bracket ?\<
3924                       gnus-tmp-closing-bracket ?\>)
3925               (setq gnus-tmp-opening-bracket ?\[
3926                     gnus-tmp-closing-bracket ?\]))
3927             (setq
3928              gnus-tmp-indentation
3929              (aref gnus-thread-indent-array gnus-tmp-level)
3930              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
3931              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
3932                                 gnus-summary-default-score 0)
3933              gnus-tmp-score-char
3934              (if (or (null gnus-summary-default-score)
3935                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3936                          gnus-summary-zcore-fuzz))
3937                  ? ;Whitespace
3938                (if (< gnus-tmp-score gnus-summary-default-score)
3939                    gnus-score-below-mark gnus-score-over-mark))
3940              gnus-tmp-replied
3941              (cond ((memq number gnus-newsgroup-processable)
3942                     gnus-process-mark)
3943                    ((memq number gnus-newsgroup-cached)
3944                     gnus-cached-mark)
3945                    ((memq number gnus-newsgroup-replied)
3946                     gnus-replied-mark)
3947                    ((memq number gnus-newsgroup-saved)
3948                     gnus-saved-mark)
3949                    (t gnus-unread-mark))
3950              gnus-tmp-from (mail-header-from gnus-tmp-header)
3951              gnus-tmp-name
3952              (cond
3953               ((string-match "<[^>]+> *$" gnus-tmp-from)
3954                (setq beg-match (match-beginning 0))
3955                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
3956                         (substring gnus-tmp-from (1+ (match-beginning 0))
3957                                    (1- (match-end 0))))
3958                    (substring gnus-tmp-from 0 beg-match)))
3959               ((string-match "(.+)" gnus-tmp-from)
3960                (substring gnus-tmp-from
3961                           (1+ (match-beginning 0)) (1- (match-end 0))))
3962               (t gnus-tmp-from)))
3963             (when (string= gnus-tmp-name "")
3964               (setq gnus-tmp-name gnus-tmp-from))
3965             (unless (numberp gnus-tmp-lines)
3966               (setq gnus-tmp-lines 0))
3967             (gnus-put-text-property
3968              (point)
3969              (progn (eval gnus-summary-line-format-spec) (point))
3970              'gnus-number number)
3971             (when gnus-visual-p
3972               (forward-line -1)
3973               (gnus-run-hooks 'gnus-summary-update-hook)
3974               (forward-line 1))
3975
3976             (setq gnus-tmp-prev-subject subject)))
3977
3978         (when (nth 1 thread)
3979           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
3980         (incf gnus-tmp-level)
3981         (setq threads (if thread-end nil (cdar thread)))
3982         (unless threads
3983           (setq gnus-tmp-level 0)))))
3984   (gnus-message 7 "Generating summary...done"))
3985
3986 (defun gnus-summary-prepare-unthreaded (headers)
3987   "Generate an unthreaded summary buffer based on HEADERS."
3988   (let (header number mark)
3989
3990     (beginning-of-line)
3991
3992     (while headers
3993       ;; We may have to root out some bad articles...
3994       (when (memq (setq number (mail-header-number
3995                                 (setq header (pop headers))))
3996                   gnus-newsgroup-limit)
3997         ;; Mark article as read when it has a low score.
3998         (when (and gnus-summary-mark-below
3999                    (< (or (cdr (assq number gnus-newsgroup-scored))
4000                           gnus-summary-default-score 0)
4001                       gnus-summary-mark-below)
4002                    (not (gnus-summary-article-ancient-p number)))
4003           (setq gnus-newsgroup-unreads
4004                 (delq number gnus-newsgroup-unreads))
4005           (if gnus-newsgroup-auto-expire
4006               (push number gnus-newsgroup-expirable)
4007             (push (cons number gnus-low-score-mark)
4008                   gnus-newsgroup-reads)))
4009
4010         (setq mark (gnus-article-mark number))
4011         (push (gnus-data-make number mark (1+ (point)) header 0)
4012               gnus-newsgroup-data)
4013         (gnus-summary-insert-line
4014          header 0 number
4015          mark (memq number gnus-newsgroup-replied)
4016          (memq number gnus-newsgroup-expirable)
4017          (mail-header-subject header) nil
4018          (cdr (assq number gnus-newsgroup-scored))
4019          (memq number gnus-newsgroup-processable))))))
4020
4021 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4022   "Select newsgroup GROUP.
4023 If READ-ALL is non-nil, all articles in the group are selected.
4024 If SELECT-ARTICLES, only select those articles from GROUP."
4025   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4026          ;;!!! Dirty hack; should be removed.
4027          (gnus-summary-ignore-duplicates
4028           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4029               t
4030             gnus-summary-ignore-duplicates))
4031          (info (nth 2 entry))
4032          articles fetched-articles cached)
4033
4034     (unless (gnus-check-server
4035              (setq gnus-current-select-method
4036                    (gnus-find-method-for-group group)))
4037       (error "Couldn't open server"))
4038
4039     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4040         (gnus-activate-group group)     ; Or we can activate it...
4041         (progn                          ; Or we bug out.
4042           (when (equal major-mode 'gnus-summary-mode)
4043             (kill-buffer (current-buffer)))
4044           (error "Couldn't request group %s: %s"
4045                  group (gnus-status-message group))))
4046
4047     (unless (gnus-request-group group t)
4048       (when (equal major-mode 'gnus-summary-mode)
4049         (kill-buffer (current-buffer)))
4050       (error "Couldn't request group %s: %s"
4051              group (gnus-status-message group)))
4052
4053     (setq gnus-newsgroup-name group)
4054     (setq gnus-newsgroup-unselected nil)
4055     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4056     (gnus-summary-setup-default-charset)
4057
4058     ;; Adjust and set lists of article marks.
4059     (when info
4060       (gnus-adjust-marked-articles info))
4061
4062     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4063     (setq cached
4064           (if (gnus-virtual-group-p group)
4065               gnus-newsgroup-cached
4066             (gnus-cache-articles-in-group group)))
4067
4068     (setq gnus-newsgroup-unreads
4069           (gnus-set-difference
4070            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4071            gnus-newsgroup-dormant))
4072
4073     (setq gnus-newsgroup-processable nil)
4074
4075     (gnus-update-read-articles group gnus-newsgroup-unreads)
4076
4077     (if (setq articles select-articles)
4078         (setq gnus-newsgroup-unselected
4079               (gnus-sorted-intersection
4080                gnus-newsgroup-unreads
4081                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4082       (setq articles (gnus-articles-to-read group read-all)))
4083
4084     (cond
4085      ((null articles)
4086       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4087       'quit)
4088      ((eq articles 0) nil)
4089      (t
4090       ;; Init the dependencies hash table.
4091       (setq gnus-newsgroup-dependencies
4092             (gnus-make-hashtable (length articles)))
4093       (gnus-set-global-variables)
4094       ;; Retrieve the headers and read them in.
4095       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4096       (setq gnus-newsgroup-headers
4097             (gnus-retrieve-parsed-headers
4098              articles gnus-newsgroup-name
4099              ;; We might want to fetch old headers, but
4100              ;; not if there is only 1 article.
4101              (and (or (and (not (eq gnus-fetch-old-headers 'some))
4102                            (not (numberp gnus-fetch-old-headers)))
4103                       (> (length articles) 1))
4104                   gnus-fetch-old-headers)))
4105       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4106
4107       ;; Suppress duplicates?
4108       (when gnus-suppress-duplicates
4109         (gnus-dup-suppress-articles))
4110
4111       ;; Set the initial limit.
4112       (setq gnus-newsgroup-limit (copy-sequence articles))
4113       ;; Remove canceled articles from the list of unread articles.
4114       (setq gnus-newsgroup-unreads
4115             (gnus-set-sorted-intersection
4116              gnus-newsgroup-unreads
4117              (setq fetched-articles
4118                    (mapcar (lambda (headers) (mail-header-number headers))
4119                            gnus-newsgroup-headers))))
4120       ;; Removed marked articles that do not exist.
4121       (gnus-update-missing-marks
4122        (gnus-sorted-complement fetched-articles articles))
4123
4124       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4125       (when cached
4126         (setq gnus-newsgroup-cached cached))
4127
4128       ;; We might want to build some more threads first.
4129       (when (and gnus-fetch-old-headers
4130                  (eq gnus-headers-retrieved-by 'nov))
4131         (if (eq gnus-fetch-old-headers 'invisible)
4132             (gnus-build-all-threads)
4133           (gnus-build-old-threads)))
4134       ;; Let the Gnus agent mark articles as read.
4135       (when gnus-agent
4136         (gnus-agent-get-undownloaded-list))
4137       ;; Check whether auto-expire is to be done in this group.
4138       (setq gnus-newsgroup-auto-expire
4139             (gnus-group-auto-expirable-p group))
4140       ;; Set up the article buffer now, if necessary.
4141       (unless gnus-single-article-buffer
4142         (gnus-article-setup-buffer))
4143       ;; First and last article in this newsgroup.
4144       (when gnus-newsgroup-headers
4145         (setq gnus-newsgroup-begin
4146               (mail-header-number (car gnus-newsgroup-headers))
4147               gnus-newsgroup-end
4148               (mail-header-number
4149                (gnus-last-element gnus-newsgroup-headers))))
4150       ;; GROUP is successfully selected.
4151       (or gnus-newsgroup-headers t)))))
4152
4153 (defun gnus-articles-to-read (group &optional read-all)
4154   ;; Find out what articles the user wants to read.
4155   (let* ((articles
4156           ;; Select all articles if `read-all' is non-nil, or if there
4157           ;; are no unread articles.
4158           (if (or read-all
4159                   (and (zerop (length gnus-newsgroup-marked))
4160                        (zerop (length gnus-newsgroup-unreads)))
4161                   (eq (gnus-group-find-parameter group 'display)
4162                       'all))
4163               (gnus-uncompress-range (gnus-active group))
4164             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4165                           (copy-sequence gnus-newsgroup-unreads))
4166                   '<)))
4167          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4168          (scored (length scored-list))
4169          (number (length articles))
4170          (marked (+ (length gnus-newsgroup-marked)
4171                     (length gnus-newsgroup-dormant)))
4172          (select
4173           (cond
4174            ((numberp read-all)
4175             read-all)
4176            (t
4177             (condition-case ()
4178                 (cond
4179                  ((and (or (<= scored marked) (= scored number))
4180                        (natnump gnus-large-newsgroup)
4181                        (> number gnus-large-newsgroup))
4182                   (let ((input (read-from-minibuffer
4183                                 (format
4184                                  "How many articles from %s (max %d): "
4185                                  (gnus-limit-string gnus-newsgroup-name 35)
4186                                  number)
4187                                 (static-if (< emacs-major-version 20)
4188                                     (number-to-string gnus-large-newsgroup)
4189                                   (cons
4190                                    (number-to-string gnus-large-newsgroup)
4191                                    0)))))
4192                     (if (string-match "^[ \t]*$" input)
4193                         number
4194                       input)))
4195                  ((and (> scored marked) (< scored number)
4196                        (> (- scored number) 20))
4197                   (let ((input
4198                          (read-string
4199                           (format "%s %s (%d scored, %d total): "
4200                                   "How many articles from"
4201                                   group scored number))))
4202                     (if (string-match "^[ \t]*$" input)
4203                         number input)))
4204                  (t number))
4205               (quit nil))))))
4206     (setq select (if (stringp select) (string-to-number select) select))
4207     (if (or (null select) (zerop select))
4208         select
4209       (if (and (not (zerop scored)) (<= (abs select) scored))
4210           (progn
4211             (setq articles (sort scored-list '<))
4212             (setq number (length articles)))
4213         (setq articles (copy-sequence articles)))
4214
4215       (when (< (abs select) number)
4216         (if (< select 0)
4217             ;; Select the N oldest articles.
4218             (setcdr (nthcdr (1- (abs select)) articles) nil)
4219           ;; Select the N most recent articles.
4220           (setq articles (nthcdr (- number select) articles))))
4221       (setq gnus-newsgroup-unselected
4222             (gnus-sorted-intersection
4223              gnus-newsgroup-unreads
4224              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4225       articles)))
4226
4227 (defun gnus-killed-articles (killed articles)
4228   (let (out)
4229     (while articles
4230       (when (inline (gnus-member-of-range (car articles) killed))
4231         (push (car articles) out))
4232       (setq articles (cdr articles)))
4233     out))
4234
4235 (defun gnus-uncompress-marks (marks)
4236   "Uncompress the mark ranges in MARKS."
4237   (let ((uncompressed '(score bookmark))
4238         out)
4239     (while marks
4240       (if (memq (caar marks) uncompressed)
4241           (push (car marks) out)
4242         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4243       (setq marks (cdr marks)))
4244     out))
4245
4246 (defun gnus-adjust-marked-articles (info)
4247   "Set all article lists and remove all marks that are no longer valid."
4248   (let* ((marked-lists (gnus-info-marks info))
4249          (active (gnus-active (gnus-info-group info)))
4250          (min (car active))
4251          (max (cdr active))
4252          (types gnus-article-mark-lists)
4253          (uncompressed '(score bookmark killed))
4254          marks var articles article mark)
4255
4256     (while marked-lists
4257       (setq marks (pop marked-lists))
4258       (set (setq var (intern (format "gnus-newsgroup-%s"
4259                                      (car (rassq (setq mark (car marks))
4260                                                  types)))))
4261            (if (memq (car marks) uncompressed) (cdr marks)
4262              (gnus-uncompress-range (cdr marks))))
4263
4264       (setq articles (symbol-value var))
4265
4266       ;; All articles have to be subsets of the active articles.
4267       (cond
4268        ;; Adjust "simple" lists.
4269        ((memq mark '(tick dormant expire reply save))
4270         (while articles
4271           (when (or (< (setq article (pop articles)) min) (> article max))
4272             (set var (delq article (symbol-value var))))))
4273        ;; Adjust assocs.
4274        ((memq mark uncompressed)
4275         (when (not (listp (cdr (symbol-value var))))
4276           (set var (list (symbol-value var))))
4277         (when (not (listp (cdr articles)))
4278           (setq articles (list articles)))
4279         (while articles
4280           (when (or (not (consp (setq article (pop articles))))
4281                     (< (car article) min)
4282                     (> (car article) max))
4283             (set var (delq article (symbol-value var))))))))))
4284
4285 (defun gnus-update-missing-marks (missing)
4286   "Go through the list of MISSING articles and remove them from the mark lists."
4287   (when missing
4288     (let ((types gnus-article-mark-lists)
4289           var m)
4290       ;; Go through all types.
4291       (while types
4292         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4293         (when (symbol-value var)
4294           ;; This list has articles.  So we delete all missing articles
4295           ;; from it.
4296           (setq m missing)
4297           (while m
4298             (set var (delq (pop m) (symbol-value var)))))))))
4299
4300 (defun gnus-update-marks ()
4301   "Enter the various lists of marked articles into the newsgroup info list."
4302   (let ((types gnus-article-mark-lists)
4303         (info (gnus-get-info gnus-newsgroup-name))
4304         (uncompressed '(score bookmark killed))
4305         type list newmarked symbol delta-marks)
4306     (when info
4307       ;; Add all marks lists to the list of marks lists.
4308       (while (setq type (pop types))
4309         (setq list (symbol-value
4310                           (setq symbol
4311                                 (intern (format "gnus-newsgroup-%s"
4312                                                 (car type))))))
4313
4314         (when list
4315           ;; Get rid of the entries of the articles that have the
4316           ;; default score.
4317           (when (and (eq (cdr type) 'score)
4318                      gnus-save-score
4319                      list)
4320             (let* ((arts list)
4321                    (prev (cons nil list))
4322                    (all prev))
4323               (while arts
4324                 (if (or (not (consp (car arts)))
4325                         (= (cdar arts) gnus-summary-default-score))
4326                     (setcdr prev (cdr arts))
4327                   (setq prev arts))
4328                 (setq arts (cdr arts)))
4329               (setq list (cdr all)))))
4330
4331        (or (memq (cdr type) uncompressed)
4332            (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4333        
4334        (when (gnus-check-backend-function 'request-set-mark
4335                                           gnus-newsgroup-name)
4336          ;; uncompressed:s are not proper flags (they are cons cells)
4337          ;; cache is a internal gnus flag
4338          (unless (memq (cdr type) (cons 'cache uncompressed))
4339            (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4340                   (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4341                   (add (gnus-remove-from-range (gnus-copy-sequence list) old)))
4342              (if add
4343                  (push (list add 'add (list (cdr type))) delta-marks))
4344              (if del
4345                  (push (list del 'del (list (cdr type))) delta-marks)))))
4346           
4347         (when list
4348          (push (cons (cdr type) list) newmarked)))
4349
4350       (when delta-marks
4351         (unless (gnus-check-group gnus-newsgroup-name)
4352           (error "Can't open server for %s" gnus-newsgroup-name))
4353         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4354           
4355       ;; Enter these new marks into the info of the group.
4356       (if (nthcdr 3 info)
4357           (setcar (nthcdr 3 info) newmarked)
4358         ;; Add the marks lists to the end of the info.
4359         (when newmarked
4360           (setcdr (nthcdr 2 info) (list newmarked))))
4361
4362       ;; Cut off the end of the info if there's nothing else there.
4363       (let ((i 5))
4364         (while (and (> i 2)
4365                     (not (nth i info)))
4366           (when (nthcdr (decf i) info)
4367             (setcdr (nthcdr i info) nil)))))))
4368
4369 (defun gnus-set-mode-line (where)
4370   "This function sets the mode line of the article or summary buffers.
4371 If WHERE is `summary', the summary mode line format will be used."
4372   ;; Is this mode line one we keep updated?
4373   (when (and (memq where gnus-updated-mode-lines)
4374              (symbol-value
4375               (intern (format "gnus-%s-mode-line-format-spec" where))))
4376     (let (mode-string)
4377       (save-excursion
4378         ;; We evaluate this in the summary buffer since these
4379         ;; variables are buffer-local to that buffer.
4380         (set-buffer gnus-summary-buffer)
4381         ;; We bind all these variables that are used in the `eval' form
4382         ;; below.
4383         (let* ((mformat (symbol-value
4384                          (intern
4385                           (format "gnus-%s-mode-line-format-spec" where))))
4386                (gnus-tmp-group-name gnus-newsgroup-name)
4387                (gnus-tmp-article-number (or gnus-current-article 0))
4388                (gnus-tmp-unread gnus-newsgroup-unreads)
4389                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4390                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4391                (gnus-tmp-unread-and-unselected
4392                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4393                             (zerop gnus-tmp-unselected))
4394                        "")
4395                       ((zerop gnus-tmp-unselected)
4396                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4397                       (t (format "{%d(+%d) more}"
4398                                  gnus-tmp-unread-and-unticked
4399                                  gnus-tmp-unselected))))
4400                (gnus-tmp-subject
4401                 (if (and gnus-current-headers
4402                          (vectorp gnus-current-headers))
4403                     (gnus-mode-string-quote
4404                      (mail-header-subject gnus-current-headers))
4405                   ""))
4406                bufname-length max-len
4407                gnus-tmp-header);; passed as argument to any user-format-funcs
4408           (setq mode-string (eval mformat))
4409           (setq bufname-length (if (string-match "%b" mode-string)
4410                                    (- (length
4411                                        (buffer-name
4412                                         (if (eq where 'summary)
4413                                             nil
4414                                           (get-buffer gnus-article-buffer))))
4415                                       2)
4416                                  0))
4417           (setq max-len (max 4 (if gnus-mode-non-string-length
4418                                    (- (window-width)
4419                                       gnus-mode-non-string-length
4420                                       bufname-length)
4421                                  (length mode-string))))
4422           ;; We might have to chop a bit of the string off...
4423           (when (> (length mode-string) max-len)
4424             (setq mode-string
4425                   (concat (gnus-truncate-string mode-string (- max-len 3))
4426                           "...")))
4427           ;; Pad the mode string a bit.
4428           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4429       ;; Update the mode line.
4430       (setq mode-line-buffer-identification
4431             (gnus-mode-line-buffer-identification (list mode-string)))
4432       (set-buffer-modified-p t))))
4433
4434 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4435   "Go through the HEADERS list and add all Xrefs to a hash table.
4436 The resulting hash table is returned, or nil if no Xrefs were found."
4437   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4438          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4439          (xref-hashtb (gnus-make-hashtable))
4440          start group entry number xrefs header)
4441     (while headers
4442       (setq header (pop headers))
4443       (when (and (setq xrefs (mail-header-xref header))
4444                  (not (memq (setq number (mail-header-number header))
4445                             unreads)))
4446         (setq start 0)
4447         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4448           (setq start (match-end 0))
4449           (setq group (if prefix
4450                           (concat prefix (substring xrefs (match-beginning 1)
4451                                                     (match-end 1)))
4452                         (substring xrefs (match-beginning 1) (match-end 1))))
4453           (setq number
4454                 (string-to-int (substring xrefs (match-beginning 2)
4455                                           (match-end 2))))
4456           (if (setq entry (gnus-gethash group xref-hashtb))
4457               (setcdr entry (cons number (cdr entry)))
4458             (gnus-sethash group (cons number nil) xref-hashtb)))))
4459     (and start xref-hashtb)))
4460
4461 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4462   "Look through all the headers and mark the Xrefs as read."
4463   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4464         name entry info xref-hashtb idlist method nth4)
4465     (save-excursion
4466       (set-buffer gnus-group-buffer)
4467       (when (setq xref-hashtb
4468                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4469         (mapatoms
4470          (lambda (group)
4471            (unless (string= from-newsgroup (setq name (symbol-name group)))
4472              (setq idlist (symbol-value group))
4473              ;; Dead groups are not updated.
4474              (and (prog1
4475                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4476                             info (nth 2 entry))
4477                     (when (stringp (setq nth4 (gnus-info-method info)))
4478                       (setq nth4 (gnus-server-to-method nth4))))
4479                   ;; Only do the xrefs if the group has the same
4480                   ;; select method as the group we have just read.
4481                   (or (gnus-methods-equal-p
4482                        nth4 (gnus-find-method-for-group from-newsgroup))
4483                       virtual
4484                       (equal nth4 (setq method (gnus-find-method-for-group
4485                                                 from-newsgroup)))
4486                       (and (equal (car nth4) (car method))
4487                            (equal (nth 1 nth4) (nth 1 method))))
4488                   gnus-use-cross-reference
4489                   (or (not (eq gnus-use-cross-reference t))
4490                       virtual
4491                       ;; Only do cross-references on subscribed
4492                       ;; groups, if that is what is wanted.
4493                       (<= (gnus-info-level info) gnus-level-subscribed))
4494                   (gnus-group-make-articles-read name idlist))))
4495          xref-hashtb)))))
4496
4497 (defun gnus-compute-read-articles (group articles)
4498   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4499          (info (nth 2 entry))
4500          (active (gnus-active group))
4501          ninfo)
4502     (when entry
4503       ;; First peel off all invalid article numbers.
4504       (when active
4505         (let ((ids articles)
4506               id first)
4507           (while (setq id (pop ids))
4508             (when (and first (> id (cdr active)))
4509               ;; We'll end up in this situation in one particular
4510               ;; obscure situation.  If you re-scan a group and get
4511               ;; a new article that is cross-posted to a different
4512               ;; group that has not been re-scanned, you might get
4513               ;; crossposted article that has a higher number than
4514               ;; Gnus believes possible.  So we re-activate this
4515               ;; group as well.  This might mean doing the
4516               ;; crossposting thingy will *increase* the number
4517               ;; of articles in some groups.  Tsk, tsk.
4518               (setq active (or (gnus-activate-group group) active)))
4519             (when (or (> id (cdr active))
4520                       (< id (car active)))
4521               (setq articles (delq id articles))))))
4522       ;; If the read list is nil, we init it.
4523       (if (and active
4524                (null (gnus-info-read info))
4525                (> (car active) 1))
4526           (setq ninfo (cons 1 (1- (car active))))
4527         (setq ninfo (gnus-info-read info)))
4528       ;; Then we add the read articles to the range.
4529       (gnus-add-to-range
4530        ninfo (setq articles (sort articles '<))))))
4531
4532 (defun gnus-group-make-articles-read (group articles)
4533   "Update the info of GROUP to say that ARTICLES are read."
4534   (let* ((num 0)
4535          (entry (gnus-gethash group gnus-newsrc-hashtb))
4536          (info (nth 2 entry))
4537          (active (gnus-active group))
4538          range)
4539     (when entry
4540       (setq range (gnus-compute-read-articles group articles))
4541       (save-excursion
4542         (set-buffer gnus-group-buffer)
4543         (gnus-undo-register
4544           `(progn
4545              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4546              (gnus-info-set-read ',info ',(gnus-info-read info))
4547              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4548              (gnus-group-update-group ,group t))))
4549       ;; Add the read articles to the range.
4550       (gnus-info-set-read info range)
4551       ;; Then we have to re-compute how many unread
4552       ;; articles there are in this group.
4553       (when active
4554         (cond
4555          ((not range)
4556           (setq num (- (1+ (cdr active)) (car active))))
4557          ((not (listp (cdr range)))
4558           (setq num (- (cdr active) (- (1+ (cdr range))
4559                                        (car range)))))
4560          (t
4561           (while range
4562             (if (numberp (car range))
4563                 (setq num (1+ num))
4564               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4565             (setq range (cdr range)))
4566           (setq num (- (cdr active) num))))
4567         ;; Update the number of unread articles.
4568         (setcar entry num)
4569         ;; Update the group buffer.
4570         (gnus-group-update-group group t)))))
4571
4572 (defvar gnus-newsgroup-none-id 0)
4573
4574 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4575   (let ((cur nntp-server-buffer)
4576         (dependencies
4577          (or dependencies
4578              (save-excursion (set-buffer gnus-summary-buffer)
4579                              gnus-newsgroup-dependencies)))
4580         headers id end ref
4581         (mail-parse-charset gnus-newsgroup-charset)
4582         (mail-parse-ignored-charsets
4583          (save-excursion (condition-case nil
4584                              (set-buffer gnus-summary-buffer)
4585                            (error))
4586                          gnus-newsgroup-ignored-charsets)))
4587     (save-excursion
4588       (set-buffer nntp-server-buffer)
4589       ;; Translate all TAB characters into SPACE characters.
4590       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4591       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4592       (gnus-run-hooks 'gnus-parse-headers-hook)
4593       (let ((case-fold-search t)
4594             in-reply-to header p lines chars ctype)
4595         (goto-char (point-min))
4596         ;; Search to the beginning of the next header.  Error messages
4597         ;; do not begin with 2 or 3.
4598         (while (re-search-forward "^[23][0-9]+ " nil t)
4599           (setq id nil
4600                 ref nil)
4601           ;; This implementation of this function, with nine
4602           ;; search-forwards instead of the one re-search-forward and
4603           ;; a case (which basically was the old function) is actually
4604           ;; about twice as fast, even though it looks messier.  You
4605           ;; can't have everything, I guess.  Speed and elegance
4606           ;; doesn't always go hand in hand.
4607           (setq
4608            header
4609            (make-full-mail-header
4610             ;; Number.
4611             (prog1
4612                 (read cur)
4613               (end-of-line)
4614               (setq p (point))
4615               (narrow-to-region (point)
4616                                 (or (and (search-forward "\n.\n" nil t)
4617                                          (- (point) 2))
4618                                     (point))))
4619             ;; Subject.
4620             (progn
4621               (goto-char p)
4622               (if (search-forward "\nsubject: " nil t)
4623                   (buffer-substring (match-end 0) (std11-field-end))
4624                 "(none)"))
4625             ;; From.
4626             (progn
4627               (goto-char p)
4628               (if (search-forward "\nfrom: " nil t)
4629                   (buffer-substring (match-end 0) (std11-field-end))
4630                 "(nobody)"))
4631             ;; Date.
4632             (progn
4633               (goto-char p)
4634               (if (search-forward "\ndate: " nil t)
4635                   (buffer-substring (match-end 0) (std11-field-end))
4636                 ""))
4637             ;; Message-ID.
4638             (progn
4639               (goto-char p)
4640               (setq id (if (re-search-forward
4641                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4642                            ;; We do it this way to make sure the Message-ID
4643                            ;; is (somewhat) syntactically valid.
4644                            (buffer-substring (match-beginning 1)
4645                                              (match-end 1))
4646                          ;; If there was no message-id, we just fake one
4647                          ;; to make subsequent routines simpler.
4648                          (nnheader-generate-fake-message-id))))
4649             ;; References.
4650             (progn
4651               (goto-char p)
4652               (if (search-forward "\nreferences: " nil t)
4653                   (progn
4654                     (setq end (point))
4655                     (prog1
4656                         (buffer-substring (match-end 0) (std11-field-end))
4657                       (setq ref
4658                             (buffer-substring
4659                              (progn
4660                                ;; (end-of-line)
4661                                (search-backward ">" end t)
4662                                (1+ (point)))
4663                              (progn
4664                                (search-backward "<" end t)
4665                                (point))))))
4666                 ;; Get the references from the in-reply-to header if there
4667                 ;; were no references and the in-reply-to header looks
4668                 ;; promising.
4669                 (if (and (search-forward "\nin-reply-to: " nil t)
4670                          (setq in-reply-to
4671                                (buffer-substring (match-end 0)
4672                                                  (std11-field-end)))
4673                          (string-match "<[^>]+>" in-reply-to))
4674                     (let (ref2)
4675                       (setq ref (substring in-reply-to (match-beginning 0)
4676                                            (match-end 0)))
4677                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4678                         (setq ref2 (substring in-reply-to (match-beginning 0)
4679                                               (match-end 0)))
4680                         (when (> (length ref2) (length ref))
4681                           (setq ref ref2)))
4682                       ref)
4683                   (setq ref nil))))
4684             ;; Chars.
4685             (progn
4686               (goto-char p)
4687               (if (search-forward "\nchars: " nil t)
4688                   (if (numberp (setq chars (ignore-errors (read cur))))
4689                       chars 0)
4690                 0))
4691             ;; Lines.
4692             (progn
4693               (goto-char p)
4694               (if (search-forward "\nlines: " nil t)
4695                   (if (numberp (setq lines (ignore-errors (read cur))))
4696                       lines 0)
4697                 0))
4698             ;; Xref.
4699             (progn
4700               (goto-char p)
4701               (and (search-forward "\nxref: " nil t)
4702                    (buffer-substring (match-end 0) (std11-field-end))))
4703             ;; Extra.
4704             (when gnus-extra-headers
4705               (let ((extra gnus-extra-headers)
4706                     out)
4707                 (while extra
4708                   (goto-char p)
4709                   (when (search-forward
4710                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4711                     (push (cons (car extra)
4712                                 (buffer-substring (match-end 0)
4713                                                   (std11-field-end)))
4714                           out))
4715                   (pop extra))
4716                 out))))
4717           (goto-char p)
4718           (if (and (search-forward "\ncontent-type: " nil t)
4719                    (setq ctype
4720                          (buffer-substring (match-end 0) (std11-field-end))))
4721               (mime-entity-set-content-type-internal
4722                header (mime-parse-Content-Type ctype)))
4723           (when (equal id ref)
4724             (setq ref nil))
4725
4726           (when gnus-alter-header-function
4727             (funcall gnus-alter-header-function header)
4728             (setq id (mail-header-id header)
4729                   ref (gnus-parent-id (mail-header-references header))))
4730
4731           (when (setq header
4732                       (gnus-dependencies-add-header
4733                        header dependencies force-new))
4734             (push header headers))
4735           (goto-char (point-max))
4736           (widen))
4737         (nreverse headers)))))
4738
4739 ;; Goes through the xover lines and returns a list of vectors
4740 (defun gnus-get-newsgroup-headers-xover (sequence &optional
4741                                                   force-new dependencies
4742                                                   group also-fetch-heads)
4743   "Parse the news overview data in the server buffer, and return a
4744 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
4745   ;; Get the Xref when the users reads the articles since most/some
4746   ;; NNTP servers do not include Xrefs when using XOVER.
4747   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
4748   (let ((mail-parse-charset gnus-newsgroup-charset)
4749         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
4750         (cur nntp-server-buffer)
4751         (dependencies (or dependencies gnus-newsgroup-dependencies))
4752         number headers header)
4753     (save-excursion
4754       (set-buffer nntp-server-buffer)
4755       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4756       ;; Allow the user to mangle the headers before parsing them.
4757       (gnus-run-hooks 'gnus-parse-headers-hook)
4758       (goto-char (point-min))
4759       (while (not (eobp))
4760         (condition-case ()
4761             (while (and sequence (not (eobp)))
4762               (setq number (read cur))
4763               (while (and sequence
4764                           (< (car sequence) number))
4765                 (setq sequence (cdr sequence)))
4766               (and sequence
4767                    (eq number (car sequence))
4768                    (progn
4769                      (setq sequence (cdr sequence))
4770                      (setq header (inline
4771                                     (gnus-nov-parse-line
4772                                      number dependencies force-new))))
4773                    (push header headers))
4774               (forward-line 1))
4775           (error
4776            (gnus-error 4 "Strange nov line (%d)"
4777                        (count-lines (point-min) (point)))))
4778         (forward-line 1))
4779       ;; A common bug in inn is that if you have posted an article and
4780       ;; then retrieves the active file, it will answer correctly --
4781       ;; the new article is included.  However, a NOV entry for the
4782       ;; article may not have been generated yet, so this may fail.
4783       ;; We work around this problem by retrieving the last few
4784       ;; headers using HEAD.
4785       (if (or (not also-fetch-heads)
4786               (not sequence))
4787           ;; We (probably) got all the headers.
4788           (nreverse headers)
4789         (let ((gnus-nov-is-evil t))
4790           (nconc
4791            (nreverse headers)
4792            (gnus-retrieve-parsed-headers sequence group)
4793            ))))))
4794
4795 (defun gnus-article-get-xrefs ()
4796   "Fill in the Xref value in `gnus-current-headers', if necessary.
4797 This is meant to be called in `gnus-article-internal-prepare-hook'."
4798   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4799                                  gnus-current-headers)))
4800     (or (not gnus-use-cross-reference)
4801         (not headers)
4802         (and (mail-header-xref headers)
4803              (not (string= (mail-header-xref headers) "")))
4804         (let ((case-fold-search t)
4805               xref)
4806           (save-restriction
4807             (nnheader-narrow-to-headers)
4808             (goto-char (point-min))
4809             (when (or (and (eq (downcase (char-after)) ?x)
4810                            (looking-at "Xref:"))
4811                       (search-forward "\nXref:" nil t))
4812               (goto-char (1+ (match-end 0)))
4813               (setq xref (buffer-substring (point)
4814                                            (progn (end-of-line) (point))))
4815               (mail-header-set-xref headers xref)))))))
4816
4817 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
4818   "Find article ID and insert the summary line for that article.
4819 OLD-HEADER can either be a header or a line number to insert
4820 the subject line on."
4821   (let* ((line (and (numberp old-header) old-header))
4822          (old-header (and (vectorp old-header) old-header))
4823          (header (cond ((and old-header use-old-header)
4824                         old-header)
4825                        ((and (numberp id)
4826                              (gnus-number-to-header id))
4827                         (gnus-number-to-header id))
4828                        (t
4829                         (gnus-read-header id))))
4830          (number (and (numberp id) id))
4831          d)
4832     (when header
4833       ;; Rebuild the thread that this article is part of and go to the
4834       ;; article we have fetched.
4835       (when (and (not gnus-show-threads)
4836                  old-header)
4837         (when (and number
4838                    (setq d (gnus-data-find (mail-header-number old-header))))
4839           (goto-char (gnus-data-pos d))
4840           (gnus-data-remove
4841            number
4842            (- (gnus-point-at-bol)
4843               (prog1
4844                   (1+ (gnus-point-at-eol))
4845                 (gnus-delete-line))))))
4846       (when old-header
4847         (mail-header-set-number header (mail-header-number old-header)))
4848       (setq gnus-newsgroup-sparse
4849             (delq (setq number (mail-header-number header))
4850                   gnus-newsgroup-sparse))
4851       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
4852       (push number gnus-newsgroup-limit)
4853       (gnus-rebuild-thread (mail-header-id header) line)
4854       (gnus-summary-goto-subject number nil t))
4855     (when (and (numberp number)
4856                (> number 0))
4857       ;; We have to update the boundaries even if we can't fetch the
4858       ;; article if ID is a number -- so that the next `P' or `N'
4859       ;; command will fetch the previous (or next) article even
4860       ;; if the one we tried to fetch this time has been canceled.
4861       (when (> number gnus-newsgroup-end)
4862         (setq gnus-newsgroup-end number))
4863       (when (< number gnus-newsgroup-begin)
4864         (setq gnus-newsgroup-begin number))
4865       (setq gnus-newsgroup-unselected
4866             (delq number gnus-newsgroup-unselected)))
4867     ;; Report back a success?
4868     (and header (mail-header-number header))))
4869
4870 ;;; Process/prefix in the summary buffer
4871
4872 (defun gnus-summary-work-articles (n)
4873   "Return a list of articles to be worked upon.
4874 The prefix argument, the list of process marked articles, and the
4875 current article will be taken into consideration."
4876   (save-excursion
4877     (set-buffer gnus-summary-buffer)
4878     (cond
4879      (n
4880       ;; A numerical prefix has been given.
4881       (setq n (prefix-numeric-value n))
4882       (let ((backward (< n 0))
4883             (n (abs (prefix-numeric-value n)))
4884             articles article)
4885         (save-excursion
4886           (while
4887               (and (> n 0)
4888                    (push (setq article (gnus-summary-article-number))
4889                          articles)
4890                    (if backward
4891                        (gnus-summary-find-prev nil article)
4892                      (gnus-summary-find-next nil article)))
4893             (decf n)))
4894         (nreverse articles)))
4895      ((and (gnus-region-active-p) (mark))
4896       (message "region active")
4897       ;; Work on the region between point and mark.
4898       (let ((max (max (point) (mark)))
4899             articles article)
4900         (save-excursion
4901           (goto-char (min (point) (mark)))
4902           (while
4903               (and
4904                (push (setq article (gnus-summary-article-number)) articles)
4905                (gnus-summary-find-next nil article)
4906                (< (point) max)))
4907           (nreverse articles))))
4908      (gnus-newsgroup-processable
4909       ;; There are process-marked articles present.
4910       ;; Save current state.
4911       (gnus-summary-save-process-mark)
4912       ;; Return the list.
4913       (reverse gnus-newsgroup-processable))
4914      (t
4915       ;; Just return the current article.
4916       (list (gnus-summary-article-number))))))
4917
4918 (defmacro gnus-summary-iterate (arg &rest forms)
4919   "Iterate over the process/prefixed articles and do FORMS.
4920 ARG is the interactive prefix given to the command.  FORMS will be
4921 executed with point over the summary line of the articles."
4922   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
4923     `(let ((,articles (gnus-summary-work-articles ,arg)))
4924        (while ,articles
4925          (gnus-summary-goto-subject (car ,articles))
4926          ,@forms
4927          (pop ,articles)))))
4928
4929 (put 'gnus-summary-iterate 'lisp-indent-function 1)
4930 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
4931
4932 (defun gnus-summary-save-process-mark ()
4933   "Push the current set of process marked articles on the stack."
4934   (interactive)
4935   (push (copy-sequence gnus-newsgroup-processable)
4936         gnus-newsgroup-process-stack))
4937
4938 (defun gnus-summary-kill-process-mark ()
4939   "Push the current set of process marked articles on the stack and unmark."
4940   (interactive)
4941   (gnus-summary-save-process-mark)
4942   (gnus-summary-unmark-all-processable))
4943
4944 (defun gnus-summary-yank-process-mark ()
4945   "Pop the last process mark state off the stack and restore it."
4946   (interactive)
4947   (unless gnus-newsgroup-process-stack
4948     (error "Empty mark stack"))
4949   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
4950
4951 (defun gnus-summary-process-mark-set (set)
4952   "Make SET into the current process marked articles."
4953   (gnus-summary-unmark-all-processable)
4954   (while set
4955     (gnus-summary-set-process-mark (pop set))))
4956
4957 ;;; Searching and stuff
4958
4959 (defun gnus-summary-search-group (&optional backward use-level)
4960   "Search for next unread newsgroup.
4961 If optional argument BACKWARD is non-nil, search backward instead."
4962   (save-excursion
4963     (set-buffer gnus-group-buffer)
4964     (when (gnus-group-search-forward
4965            backward nil (if use-level (gnus-group-group-level) nil))
4966       (gnus-group-group-name))))
4967
4968 (defun gnus-summary-best-group (&optional exclude-group)
4969   "Find the name of the best unread group.
4970 If EXCLUDE-GROUP, do not go to this group."
4971   (save-excursion
4972     (set-buffer gnus-group-buffer)
4973     (save-excursion
4974       (gnus-group-best-unread-group exclude-group))))
4975
4976 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
4977   (if backward (gnus-summary-find-prev)
4978     (let* ((dummy (gnus-summary-article-intangible-p))
4979            (article (or article (gnus-summary-article-number)))
4980            (arts (gnus-data-find-list article))
4981            result)
4982       (when (and (not dummy)
4983                  (or (not gnus-summary-check-current)
4984                      (not unread)
4985                      (not (gnus-data-unread-p (car arts)))))
4986         (setq arts (cdr arts)))
4987       (when (setq result
4988                   (if unread
4989                       (progn
4990                         (while arts
4991                           (when (or (and undownloaded
4992                                          (eq gnus-undownloaded-mark
4993                                              (gnus-data-mark (car arts))))
4994                                     (gnus-data-unread-p (car arts)))
4995                             (setq result (car arts)
4996                                   arts nil))
4997                           (setq arts (cdr arts)))
4998                         result)
4999                     (car arts)))
5000         (goto-char (gnus-data-pos result))
5001         (gnus-data-number result)))))
5002
5003 (defun gnus-summary-find-prev (&optional unread article)
5004   (let* ((eobp (eobp))
5005          (article (or article (gnus-summary-article-number)))
5006          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5007          result)
5008     (when (and (not eobp)
5009                (or (not gnus-summary-check-current)
5010                    (not unread)
5011                    (not (gnus-data-unread-p (car arts)))))
5012       (setq arts (cdr arts)))
5013     (when (setq result
5014                 (if unread
5015                     (progn
5016                       (while arts
5017                         (when (gnus-data-unread-p (car arts))
5018                           (setq result (car arts)
5019                                 arts nil))
5020                         (setq arts (cdr arts)))
5021                       result)
5022                   (car arts)))
5023       (goto-char (gnus-data-pos result))
5024       (gnus-data-number result))))
5025
5026 (defun gnus-summary-find-subject (subject &optional unread backward article)
5027   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5028          (article (or article (gnus-summary-article-number)))
5029          (articles (gnus-data-list backward))
5030          (arts (gnus-data-find-list article articles))
5031          result)
5032     (when (or (not gnus-summary-check-current)
5033               (not unread)
5034               (not (gnus-data-unread-p (car arts))))
5035       (setq arts (cdr arts)))
5036     (while arts
5037       (and (or (not unread)
5038                (gnus-data-unread-p (car arts)))
5039            (vectorp (gnus-data-header (car arts)))
5040            (gnus-subject-equal
5041             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5042            (setq result (car arts)
5043                  arts nil))
5044       (setq arts (cdr arts)))
5045     (and result
5046          (goto-char (gnus-data-pos result))
5047          (gnus-data-number result))))
5048
5049 (defun gnus-summary-search-forward (&optional unread subject backward)
5050   "Search forward for an article.
5051 If UNREAD, look for unread articles.  If SUBJECT, look for
5052 articles with that subject.  If BACKWARD, search backward instead."
5053   (cond (subject (gnus-summary-find-subject subject unread backward))
5054         (backward (gnus-summary-find-prev unread))
5055         (t (gnus-summary-find-next unread))))
5056
5057 (defun gnus-recenter (&optional n)
5058   "Center point in window and redisplay frame.
5059 Also do horizontal recentering."
5060   (interactive "P")
5061   (when (and gnus-auto-center-summary
5062              (not (eq gnus-auto-center-summary 'vertical)))
5063     (gnus-horizontal-recenter))
5064   (recenter n))
5065
5066 (defun gnus-summary-recenter ()
5067   "Center point in the summary window.
5068 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5069 displayed, no centering will be performed."
5070   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5071   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5072   (let* ((top (cond ((< (window-height) 4) 0)
5073                     ((< (window-height) 7) 1)
5074                     (t (if (numberp gnus-auto-center-summary)
5075                            gnus-auto-center-summary
5076                          2))))
5077          (height (1- (window-height)))
5078          (bottom (save-excursion (goto-char (point-max))
5079                                  (forward-line (- height))
5080                                  (point)))
5081          (window (get-buffer-window (current-buffer))))
5082     ;; The user has to want it.
5083     (when gnus-auto-center-summary
5084       (when (get-buffer-window gnus-article-buffer)
5085         ;; Only do recentering when the article buffer is displayed,
5086         ;; Set the window start to either `bottom', which is the biggest
5087         ;; possible valid number, or the second line from the top,
5088         ;; whichever is the least.
5089         (set-window-start
5090          window (min bottom (save-excursion
5091                               (forward-line (- top)) (point)))))
5092       ;; Do horizontal recentering while we're at it.
5093       (when (and (get-buffer-window (current-buffer) t)
5094                  (not (eq gnus-auto-center-summary 'vertical)))
5095         (let ((selected (selected-window)))
5096           (select-window (get-buffer-window (current-buffer) t))
5097           (gnus-summary-position-point)
5098           (gnus-horizontal-recenter)
5099           (select-window selected))))))
5100
5101 (defun gnus-summary-jump-to-group (newsgroup)
5102   "Move point to NEWSGROUP in group mode buffer."
5103   ;; Keep update point of group mode buffer if visible.
5104   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5105       (save-window-excursion
5106         ;; Take care of tree window mode.
5107         (when (get-buffer-window gnus-group-buffer)
5108           (pop-to-buffer gnus-group-buffer))
5109         (gnus-group-jump-to-group newsgroup))
5110     (save-excursion
5111       ;; Take care of tree window mode.
5112       (if (get-buffer-window gnus-group-buffer)
5113           (pop-to-buffer gnus-group-buffer)
5114         (set-buffer gnus-group-buffer))
5115       (gnus-group-jump-to-group newsgroup))))
5116
5117 ;; This function returns a list of article numbers based on the
5118 ;; difference between the ranges of read articles in this group and
5119 ;; the range of active articles.
5120 (defun gnus-list-of-unread-articles (group)
5121   (let* ((read (gnus-info-read (gnus-get-info group)))
5122          (active (or (gnus-active group) (gnus-activate-group group)))
5123          (last (cdr active))
5124          first nlast unread)
5125     ;; If none are read, then all are unread.
5126     (if (not read)
5127         (setq first (car active))
5128       ;; If the range of read articles is a single range, then the
5129       ;; first unread article is the article after the last read
5130       ;; article.  Sounds logical, doesn't it?
5131       (if (not (listp (cdr read)))
5132           (setq first (max (car active) (1+ (cdr read))))
5133         ;; `read' is a list of ranges.
5134         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5135                                   (caar read)))
5136                   1)
5137           (setq first (car active)))
5138         (while read
5139           (when first
5140             (while (< first nlast)
5141               (push first unread)
5142               (setq first (1+ first))))
5143           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5144           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5145           (setq read (cdr read)))))
5146     ;; And add the last unread articles.
5147     (while (<= first last)
5148       (push first unread)
5149       (setq first (1+ first)))
5150     ;; Return the list of unread articles.
5151     (delq 0 (nreverse unread))))
5152
5153 (defun gnus-list-of-read-articles (group)
5154   "Return a list of unread, unticked and non-dormant articles."
5155   (let* ((info (gnus-get-info group))
5156          (marked (gnus-info-marks info))
5157          (active (gnus-active group)))
5158     (and info active
5159          (gnus-set-difference
5160           (gnus-sorted-complement
5161            (gnus-uncompress-range active)
5162            (gnus-list-of-unread-articles group))
5163           (append
5164            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5165            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5166
5167 ;; Various summary commands
5168
5169 (defun gnus-summary-select-article-buffer ()
5170   "Reconfigure windows to show article buffer."
5171   (interactive)
5172   (if (not (gnus-buffer-live-p gnus-article-buffer))
5173       (error "There is no article buffer for this summary buffer")
5174     (gnus-configure-windows 'article)
5175     (select-window (get-buffer-window gnus-article-buffer))))
5176
5177 (defun gnus-summary-universal-argument (arg)
5178   "Perform any operation on all articles that are process/prefixed."
5179   (interactive "P")
5180   (let ((articles (gnus-summary-work-articles arg))
5181         func article)
5182     (if (eq
5183          (setq
5184           func
5185           (key-binding
5186            (read-key-sequence
5187             (substitute-command-keys
5188              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
5189              ))))
5190          'undefined)
5191         (gnus-error 1 "Undefined key")
5192       (save-excursion
5193         (while articles
5194           (gnus-summary-goto-subject (setq article (pop articles)))
5195           (let (gnus-newsgroup-processable)
5196             (command-execute func))
5197           (gnus-summary-remove-process-mark article)))))
5198   (gnus-summary-position-point))
5199
5200 (defun gnus-summary-toggle-truncation (&optional arg)
5201   "Toggle truncation of summary lines.
5202 With arg, turn line truncation on iff arg is positive."
5203   (interactive "P")
5204   (setq truncate-lines
5205         (if (null arg) (not truncate-lines)
5206           (> (prefix-numeric-value arg) 0)))
5207   (redraw-display))
5208
5209 (defun gnus-summary-reselect-current-group (&optional all rescan)
5210   "Rescan the current newsgroup, exit and then reselect it.
5211 The prefix argument ALL means to select all articles."
5212   (interactive "P")
5213   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5214     (error "Ephemeral groups can't be reselected"))
5215   (let ((current-subject (gnus-summary-article-number))
5216         (group gnus-newsgroup-name))
5217     (save-excursion
5218       (set-buffer gnus-group-buffer)
5219       ;; We have to adjust the point of group mode buffer because
5220       ;; point was moved to the next unread newsgroup by exiting.
5221       (gnus-summary-jump-to-group group)
5222       (when rescan
5223         (save-excursion
5224           (gnus-group-get-new-news-this-group 1))))
5225     (setq gnus-newsgroup-begin nil)
5226     (gnus-summary-exit)
5227     (gnus-group-read-group all t group)
5228     (gnus-summary-goto-subject current-subject nil t)))
5229
5230 (defun gnus-summary-rescan-group (&optional all)
5231   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5232   (interactive "P")
5233   (gnus-summary-reselect-current-group all t))
5234
5235 (defun gnus-summary-update-info (&optional non-destructive)
5236   (save-excursion
5237     (let ((group gnus-newsgroup-name))
5238       (when group
5239         (when gnus-newsgroup-kill-headers
5240           (setq gnus-newsgroup-killed
5241                 (gnus-compress-sequence
5242                  (nconc
5243                   (gnus-set-sorted-intersection
5244                    (gnus-uncompress-range gnus-newsgroup-killed)
5245                    (setq gnus-newsgroup-unselected
5246                          (sort gnus-newsgroup-unselected '<)))
5247                   (setq gnus-newsgroup-unreads
5248                         (sort gnus-newsgroup-unreads '<)))
5249                  t)))
5250         (unless (listp (cdr gnus-newsgroup-killed))
5251           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5252         (let ((headers gnus-newsgroup-headers))
5253           ;; Set the new ranges of read articles.
5254           (save-excursion
5255             (set-buffer gnus-group-buffer)
5256             (gnus-undo-force-boundary))
5257           (gnus-update-read-articles
5258            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5259           ;; Set the current article marks.
5260           (let ((gnus-newsgroup-scored
5261                  (if (and (not gnus-save-score)
5262                           (not non-destructive))
5263                      nil
5264                    gnus-newsgroup-scored)))
5265             (save-excursion
5266               (gnus-update-marks)))
5267           ;; Do the cross-ref thing.
5268           (when gnus-use-cross-reference
5269             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5270           ;; Do not switch windows but change the buffer to work.
5271           (set-buffer gnus-group-buffer)
5272           (unless (gnus-ephemeral-group-p group)
5273             (gnus-group-update-group group)))))))
5274
5275 (defun gnus-summary-save-newsrc (&optional force)
5276   "Save the current number of read/marked articles in the dribble buffer.
5277 The dribble buffer will then be saved.
5278 If FORCE (the prefix), also save the .newsrc file(s)."
5279   (interactive "P")
5280   (gnus-summary-update-info t)
5281   (if force
5282       (gnus-save-newsrc-file)
5283     (gnus-dribble-save)))
5284
5285 (defun gnus-summary-exit (&optional temporary)
5286   "Exit reading current newsgroup, and then return to group selection mode.
5287 gnus-exit-group-hook is called with no arguments if that value is non-nil."
5288   (interactive)
5289   (gnus-set-global-variables)
5290   (gnus-kill-save-kill-buffer)
5291   (gnus-async-halt-prefetch)
5292   (let* ((group gnus-newsgroup-name)
5293          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5294          (mode major-mode)
5295          (group-point nil)
5296          (buf (current-buffer)))
5297     (unless quit-config
5298       ;; Do adaptive scoring, and possibly save score files.
5299       (when gnus-newsgroup-adaptive
5300         (gnus-score-adaptive))
5301       (when gnus-use-scoring
5302         (gnus-score-save)))
5303     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5304     ;; If we have several article buffers, we kill them at exit.
5305     (unless gnus-single-article-buffer
5306       (gnus-kill-buffer gnus-original-article-buffer)
5307       (setq gnus-article-current nil))
5308     (when gnus-use-cache
5309       (gnus-cache-possibly-remove-articles)
5310       (gnus-cache-save-buffers))
5311     (gnus-async-prefetch-remove-group group)
5312     (when gnus-suppress-duplicates
5313       (gnus-dup-enter-articles))
5314     (when gnus-use-trees
5315       (gnus-tree-close group))
5316     ;; Remove entries for this group.
5317     (nnmail-purge-split-history (gnus-group-real-name group))
5318     ;; Make all changes in this group permanent.
5319     (unless quit-config
5320       (gnus-run-hooks 'gnus-exit-group-hook)
5321       (gnus-summary-update-info))
5322     (gnus-close-group group)
5323     ;; Make sure where we were, and go to next newsgroup.
5324     (set-buffer gnus-group-buffer)
5325     (unless quit-config
5326       (gnus-group-jump-to-group group))
5327     (gnus-run-hooks 'gnus-summary-exit-hook)
5328     (unless (or quit-config
5329                 ;; If this group has disappeared from the summary
5330                 ;; buffer, don't skip forwards.
5331                 (not (string= group (gnus-group-group-name))))
5332       (gnus-group-next-unread-group 1))
5333     (setq group-point (point))
5334     (if temporary
5335         nil                             ;Nothing to do.
5336       ;; If we have several article buffers, we kill them at exit.
5337       (unless gnus-single-article-buffer
5338         (gnus-kill-buffer gnus-article-buffer)
5339         (gnus-kill-buffer gnus-original-article-buffer)
5340         (setq gnus-article-current nil))
5341       (set-buffer buf)
5342       (if (not gnus-kill-summary-on-exit)
5343           (gnus-deaden-summary)
5344         ;; We set all buffer-local variables to nil.  It is unclear why
5345         ;; this is needed, but if we don't, buffer-local variables are
5346         ;; not garbage-collected, it seems.  This would the lead to en
5347         ;; ever-growing Emacs.
5348         (gnus-summary-clear-local-variables)
5349         (when (get-buffer gnus-article-buffer)
5350           (bury-buffer gnus-article-buffer))
5351         ;; We clear the global counterparts of the buffer-local
5352         ;; variables as well, just to be on the safe side.
5353         (set-buffer gnus-group-buffer)
5354         (gnus-summary-clear-local-variables)
5355         ;; Return to group mode buffer.
5356         (when (eq mode 'gnus-summary-mode)
5357           (gnus-kill-buffer buf)))
5358       (setq gnus-current-select-method gnus-select-method)
5359       (pop-to-buffer gnus-group-buffer)
5360       (if (not quit-config)
5361           (progn
5362             (goto-char group-point)
5363             (gnus-configure-windows 'group 'force))
5364         (gnus-handle-ephemeral-exit quit-config))
5365       ;; Clear the current group name.
5366       (unless quit-config
5367         (setq gnus-newsgroup-name nil)))))
5368
5369 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5370 (defun gnus-summary-exit-no-update (&optional no-questions)
5371   "Quit reading current newsgroup without updating read article info."
5372   (interactive)
5373   (let* ((group gnus-newsgroup-name)
5374          (quit-config (gnus-group-quit-config group)))
5375     (when (or no-questions
5376               gnus-expert-user
5377               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5378       (gnus-async-halt-prefetch)
5379       (mapcar 'funcall
5380               (delq 'gnus-summary-expire-articles
5381                     (copy-list gnus-summary-prepare-exit-hook)))
5382       ;; If we have several article buffers, we kill them at exit.
5383       (unless gnus-single-article-buffer
5384         (gnus-kill-buffer gnus-article-buffer)
5385         (gnus-kill-buffer gnus-original-article-buffer)
5386         (setq gnus-article-current nil))
5387       (if (not gnus-kill-summary-on-exit)
5388           (gnus-deaden-summary)
5389         (gnus-close-group group)
5390         (gnus-summary-clear-local-variables)
5391         (set-buffer gnus-group-buffer)
5392         (gnus-summary-clear-local-variables)
5393         (when (get-buffer gnus-summary-buffer)
5394           (kill-buffer gnus-summary-buffer)))
5395       (unless gnus-single-article-buffer
5396         (setq gnus-article-current nil))
5397       (when gnus-use-trees
5398         (gnus-tree-close group))
5399       (gnus-async-prefetch-remove-group group)
5400       (when (get-buffer gnus-article-buffer)
5401         (bury-buffer gnus-article-buffer))
5402       ;; Return to the group buffer.
5403       (gnus-configure-windows 'group 'force)
5404       ;; Clear the current group name.
5405       (setq gnus-newsgroup-name nil)
5406       (when (equal (gnus-group-group-name) group)
5407         (gnus-group-next-unread-group 1))
5408       (when quit-config
5409         (gnus-handle-ephemeral-exit quit-config)))))
5410
5411 (defun gnus-handle-ephemeral-exit (quit-config)
5412   "Handle movement when leaving an ephemeral group.
5413 The state which existed when entering the ephemeral is reset."
5414   (if (not (buffer-name (car quit-config)))
5415       (gnus-configure-windows 'group 'force)
5416     (set-buffer (car quit-config))
5417     (cond ((eq major-mode 'gnus-summary-mode)
5418            (gnus-set-global-variables))
5419           ((eq major-mode 'gnus-article-mode)
5420            (save-excursion
5421              ;; The `gnus-summary-buffer' variable may point
5422              ;; to the old summary buffer when using a single
5423              ;; article buffer.
5424              (unless (gnus-buffer-live-p gnus-summary-buffer)
5425                (set-buffer gnus-group-buffer))
5426              (set-buffer gnus-summary-buffer)
5427              (gnus-set-global-variables))))
5428     (if (or (eq (cdr quit-config) 'article)
5429             (eq (cdr quit-config) 'pick))
5430         (progn
5431           ;; The current article may be from the ephemeral group
5432           ;; thus it is best that we reload this article
5433           (gnus-summary-show-article)
5434           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5435               (gnus-configure-windows 'pick 'force)
5436             (gnus-configure-windows (cdr quit-config) 'force)))
5437       (gnus-configure-windows (cdr quit-config) 'force))
5438     (when (eq major-mode 'gnus-summary-mode)
5439       (gnus-summary-next-subject 1 nil t)
5440       (gnus-summary-recenter)
5441       (gnus-summary-position-point))))
5442
5443 (defun gnus-summary-preview-mime-message ()
5444   "MIME decode and play this message."
5445   (interactive)
5446   (let ((gnus-break-pages nil)
5447         (gnus-show-mime t))
5448     (gnus-summary-select-article gnus-show-all-headers t))
5449   (select-window (get-buffer-window gnus-article-buffer)))
5450
5451 ;;; Dead summaries.
5452
5453 (defvar gnus-dead-summary-mode-map nil)
5454
5455 (unless gnus-dead-summary-mode-map
5456   (setq gnus-dead-summary-mode-map (make-keymap))
5457   (suppress-keymap gnus-dead-summary-mode-map)
5458   (substitute-key-definition
5459    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5460   (let ((keys '("\C-d" "\r" "\177" [delete])))
5461     (while keys
5462       (define-key gnus-dead-summary-mode-map
5463         (pop keys) 'gnus-summary-wake-up-the-dead))))
5464
5465 (defvar gnus-dead-summary-mode nil
5466   "Minor mode for Gnus summary buffers.")
5467
5468 (defun gnus-dead-summary-mode (&optional arg)
5469   "Minor mode for Gnus summary buffers."
5470   (interactive "P")
5471   (when (eq major-mode 'gnus-summary-mode)
5472     (make-local-variable 'gnus-dead-summary-mode)
5473     (setq gnus-dead-summary-mode
5474           (if (null arg) (not gnus-dead-summary-mode)
5475             (> (prefix-numeric-value arg) 0)))
5476     (when gnus-dead-summary-mode
5477       (gnus-add-minor-mode
5478        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5479
5480 (defun gnus-deaden-summary ()
5481   "Make the current summary buffer into a dead summary buffer."
5482   ;; Kill any previous dead summary buffer.
5483   (when (and gnus-dead-summary
5484              (buffer-name gnus-dead-summary))
5485     (save-excursion
5486       (set-buffer gnus-dead-summary)
5487       (when gnus-dead-summary-mode
5488         (kill-buffer (current-buffer)))))
5489   ;; Make this the current dead summary.
5490   (setq gnus-dead-summary (current-buffer))
5491   (gnus-dead-summary-mode 1)
5492   (let ((name (buffer-name)))
5493     (when (string-match "Summary" name)
5494       (rename-buffer
5495        (concat (substring name 0 (match-beginning 0)) "Dead "
5496                (substring name (match-beginning 0)))
5497        t))))
5498
5499 (defun gnus-kill-or-deaden-summary (buffer)
5500   "Kill or deaden the summary BUFFER."
5501   (save-excursion
5502     (when (and (buffer-name buffer)
5503                (not gnus-single-article-buffer))
5504       (save-excursion
5505         (set-buffer buffer)
5506         (gnus-kill-buffer gnus-article-buffer)
5507         (gnus-kill-buffer gnus-original-article-buffer)))
5508     (cond (gnus-kill-summary-on-exit
5509            (when (and gnus-use-trees
5510                       (gnus-buffer-exists-p buffer))
5511              (save-excursion
5512                (set-buffer buffer)
5513                (gnus-tree-close gnus-newsgroup-name)))
5514            (gnus-kill-buffer buffer))
5515           ((gnus-buffer-exists-p buffer)
5516            (save-excursion
5517              (set-buffer buffer)
5518              (gnus-deaden-summary))))))
5519
5520 (defun gnus-summary-wake-up-the-dead (&rest args)
5521   "Wake up the dead summary buffer."
5522   (interactive)
5523   (gnus-dead-summary-mode -1)
5524   (let ((name (buffer-name)))
5525     (when (string-match "Dead " name)
5526       (rename-buffer
5527        (concat (substring name 0 (match-beginning 0))
5528                (substring name (match-end 0)))
5529        t)))
5530   (gnus-message 3 "This dead summary is now alive again"))
5531
5532 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5533 (defun gnus-summary-fetch-faq (&optional faq-dir)
5534   "Fetch the FAQ for the current group.
5535 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5536 in."
5537   (interactive
5538    (list
5539     (when current-prefix-arg
5540       (completing-read
5541        "Faq dir: " (and (listp gnus-group-faq-directory)
5542                         (mapcar (lambda (file) (list file))
5543                                 gnus-group-faq-directory))))))
5544   (let (gnus-faq-buffer)
5545     (when (setq gnus-faq-buffer
5546                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5547       (gnus-configure-windows 'summary-faq))))
5548
5549 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5550 (defun gnus-summary-describe-group (&optional force)
5551   "Describe the current newsgroup."
5552   (interactive "P")
5553   (gnus-group-describe-group force gnus-newsgroup-name))
5554
5555 (defun gnus-summary-describe-briefly ()
5556   "Describe summary mode commands briefly."
5557   (interactive)
5558   (gnus-message 6 (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")))
5559
5560 ;; Walking around group mode buffer from summary mode.
5561
5562 (defun gnus-summary-next-group (&optional no-article target-group backward)
5563   "Exit current newsgroup and then select next unread newsgroup.
5564 If prefix argument NO-ARTICLE is non-nil, no article is selected
5565 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5566 previous group instead."
5567   (interactive "P")
5568   ;; Stop pre-fetching.
5569   (gnus-async-halt-prefetch)
5570   (let ((current-group gnus-newsgroup-name)
5571         (current-buffer (current-buffer))
5572         entered)
5573     ;; First we semi-exit this group to update Xrefs and all variables.
5574     ;; We can't do a real exit, because the window conf must remain
5575     ;; the same in case the user is prompted for info, and we don't
5576     ;; want the window conf to change before that...
5577     (gnus-summary-exit t)
5578     (while (not entered)
5579       ;; Then we find what group we are supposed to enter.
5580       (set-buffer gnus-group-buffer)
5581       (gnus-group-jump-to-group current-group)
5582       (setq target-group
5583             (or target-group
5584                 (if (eq gnus-keep-same-level 'best)
5585                     (gnus-summary-best-group gnus-newsgroup-name)
5586                   (gnus-summary-search-group backward gnus-keep-same-level))))
5587       (if (not target-group)
5588           ;; There are no further groups, so we return to the group
5589           ;; buffer.
5590           (progn
5591             (gnus-message 5 "Returning to the group buffer")
5592             (setq entered t)
5593             (when (gnus-buffer-live-p current-buffer)
5594               (set-buffer current-buffer)
5595               (gnus-summary-exit))
5596             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5597         ;; We try to enter the target group.
5598         (gnus-group-jump-to-group target-group)
5599         (let ((unreads (gnus-group-group-unread)))
5600           (if (and (or (eq t unreads)
5601                        (and unreads (not (zerop unreads))))
5602                    (gnus-summary-read-group
5603                     target-group nil no-article
5604                     (and (buffer-name current-buffer) current-buffer)
5605                     nil backward))
5606               (setq entered t)
5607             (setq current-group target-group
5608                   target-group nil)))))))
5609
5610 (defun gnus-summary-prev-group (&optional no-article)
5611   "Exit current newsgroup and then select previous unread newsgroup.
5612 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5613   (interactive "P")
5614   (gnus-summary-next-group no-article nil t))
5615
5616 ;; Walking around summary lines.
5617
5618 (defun gnus-summary-first-subject (&optional unread undownloaded)
5619   "Go to the first unread subject.
5620 If UNREAD is non-nil, go to the first unread article.
5621 Returns the article selected or nil if there are no unread articles."
5622   (interactive "P")
5623   (prog1
5624       (cond
5625        ;; Empty summary.
5626        ((null gnus-newsgroup-data)
5627         (gnus-message 3 "No articles in the group")
5628         nil)
5629        ;; Pick the first article.
5630        ((not unread)
5631         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5632         (gnus-data-number (car gnus-newsgroup-data)))
5633        ;; No unread articles.
5634        ((null gnus-newsgroup-unreads)
5635         (gnus-message 3 "No more unread articles")
5636         nil)
5637        ;; Find the first unread article.
5638        (t
5639         (let ((data gnus-newsgroup-data))
5640           (while (and data
5641                       (and (not (and undownloaded
5642                                      (eq gnus-undownloaded-mark
5643                                          (gnus-data-mark (car data)))))
5644                            (not (gnus-data-unread-p (car data)))))
5645             (setq data (cdr data)))
5646           (when data
5647             (goto-char (gnus-data-pos (car data)))
5648             (gnus-data-number (car data))))))
5649     (gnus-summary-position-point)))
5650
5651 (defun gnus-summary-next-subject (n &optional unread dont-display)
5652   "Go to next N'th summary line.
5653 If N is negative, go to the previous N'th subject line.
5654 If UNREAD is non-nil, only unread articles are selected.
5655 The difference between N and the actual number of steps taken is
5656 returned."
5657   (interactive "p")
5658   (let ((backward (< n 0))
5659         (n (abs n)))
5660     (while (and (> n 0)
5661                 (if backward
5662                     (gnus-summary-find-prev unread)
5663                   (gnus-summary-find-next unread)))
5664       (gnus-summary-show-thread)
5665       (setq n (1- n)))
5666     (when (/= 0 n)
5667       (gnus-message 7 "No more%s articles"
5668                     (if unread " unread" "")))
5669     (unless dont-display
5670       (gnus-summary-recenter)
5671       (gnus-summary-position-point))
5672     n))
5673
5674 (defun gnus-summary-next-unread-subject (n)
5675   "Go to next N'th unread summary line."
5676   (interactive "p")
5677   (gnus-summary-next-subject n t))
5678
5679 (defun gnus-summary-prev-subject (n &optional unread)
5680   "Go to previous N'th summary line.
5681 If optional argument UNREAD is non-nil, only unread article is selected."
5682   (interactive "p")
5683   (gnus-summary-next-subject (- n) unread))
5684
5685 (defun gnus-summary-prev-unread-subject (n)
5686   "Go to previous N'th unread summary line."
5687   (interactive "p")
5688   (gnus-summary-next-subject (- n) t))
5689
5690 (defun gnus-summary-goto-subject (article &optional force silent)
5691   "Go the subject line of ARTICLE.
5692 If FORCE, also allow jumping to articles not currently shown."
5693   (interactive "nArticle number: ")
5694   (let ((b (point))
5695         (data (gnus-data-find article)))
5696     ;; We read in the article if we have to.
5697     (and (not data)
5698          force
5699          (gnus-summary-insert-subject
5700           article
5701           (if (or (numberp force) (vectorp force)) force)
5702           t)
5703          (setq data (gnus-data-find article)))
5704     (goto-char b)
5705     (if (not data)
5706         (progn
5707           (unless silent
5708             (gnus-message 3 "Can't find article %d" article))
5709           nil)
5710       (goto-char (gnus-data-pos data))
5711       (gnus-summary-position-point)
5712       article)))
5713
5714 ;; Walking around summary lines with displaying articles.
5715
5716 (defun gnus-summary-expand-window (&optional arg)
5717   "Make the summary buffer take up the entire Emacs frame.
5718 Given a prefix, will force an `article' buffer configuration."
5719   (interactive "P")
5720   (if arg
5721       (gnus-configure-windows 'article 'force)
5722     (gnus-configure-windows 'summary 'force)))
5723
5724 (defun gnus-summary-display-article (article &optional all-header)
5725   "Display ARTICLE in article buffer."
5726   (gnus-set-global-variables)
5727   (if (null article)
5728       nil
5729     (prog1
5730         (if gnus-summary-display-article-function
5731             (funcall gnus-summary-display-article-function article all-header)
5732           (gnus-article-prepare article all-header))
5733       (gnus-run-hooks 'gnus-select-article-hook)
5734       (when (and gnus-current-article
5735                  (not (zerop gnus-current-article)))
5736         (gnus-summary-goto-subject gnus-current-article))
5737       (gnus-summary-recenter)
5738       (when (and gnus-use-trees gnus-show-threads)
5739         (gnus-possibly-generate-tree article)
5740         (gnus-highlight-selected-tree article))
5741       ;; Successfully display article.
5742       (gnus-article-set-window-start
5743        (cdr (assq article gnus-newsgroup-bookmarks))))))
5744
5745 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
5746   "Select the current article.
5747 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
5748 non-nil, the article will be re-fetched even if it already present in
5749 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
5750 be displayed."
5751   ;; Make sure we are in the summary buffer to work around bbdb bug.
5752   (unless (eq major-mode 'gnus-summary-mode)
5753     (set-buffer gnus-summary-buffer))
5754   (let ((article (or article (gnus-summary-article-number)))
5755         (all-headers (not (not all-headers))) ;Must be T or NIL.
5756         gnus-summary-display-article-function
5757         did)
5758     (and (not pseudo)
5759          (gnus-summary-article-pseudo-p article)
5760          (error "This is a pseudo-article"))
5761     (prog1
5762         (save-excursion
5763           (set-buffer gnus-summary-buffer)
5764           (if (or (and gnus-single-article-buffer
5765                        (or (null gnus-current-article)
5766                            (null gnus-article-current)
5767                            (null (get-buffer gnus-article-buffer))
5768                            (not (eq article (cdr gnus-article-current)))
5769                            (not (equal (car gnus-article-current)
5770                                        gnus-newsgroup-name))))
5771                   (and (not gnus-single-article-buffer)
5772                        (or (null gnus-current-article)
5773                            (not (eq gnus-current-article article))))
5774                   force)
5775               ;; The requested article is different from the current article.
5776               (prog1
5777                   (gnus-summary-display-article article all-headers)
5778                 (setq did article)
5779                 (when (or all-headers gnus-show-all-headers)
5780                   (gnus-article-show-all-headers)))
5781             (when (or all-headers gnus-show-all-headers)
5782               (gnus-article-show-all-headers))
5783             'old))
5784       (when did
5785         (gnus-article-set-window-start
5786          (cdr (assq article gnus-newsgroup-bookmarks)))))))
5787
5788 (defun gnus-summary-set-current-mark (&optional current-mark)
5789   "Obsolete function."
5790   nil)
5791
5792 (defun gnus-summary-next-article (&optional unread subject backward push)
5793   "Select the next article.
5794 If UNREAD, only unread articles are selected.
5795 If SUBJECT, only articles with SUBJECT are selected.
5796 If BACKWARD, the previous article is selected instead of the next."
5797   (interactive "P")
5798   (cond
5799    ;; Is there such an article?
5800    ((and (gnus-summary-search-forward unread subject backward)
5801          (or (gnus-summary-display-article (gnus-summary-article-number))
5802              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5803     (gnus-summary-position-point))
5804    ;; If not, we try the first unread, if that is wanted.
5805    ((and subject
5806          gnus-auto-select-same
5807          (gnus-summary-first-unread-article))
5808     (gnus-summary-position-point)
5809     (gnus-message 6 "Wrapped"))
5810    ;; Try to get next/previous article not displayed in this group.
5811    ((and gnus-auto-extend-newsgroup
5812          (not unread) (not subject))
5813     (gnus-summary-goto-article
5814      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
5815      nil (count-lines (point-min) (point))))
5816    ;; Go to next/previous group.
5817    (t
5818     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
5819       (gnus-summary-jump-to-group gnus-newsgroup-name))
5820     (let ((cmd last-command-char)
5821           (point
5822            (save-excursion
5823              (set-buffer gnus-group-buffer)
5824              (point)))
5825           (group
5826            (if (eq gnus-keep-same-level 'best)
5827                (gnus-summary-best-group gnus-newsgroup-name)
5828              (gnus-summary-search-group backward gnus-keep-same-level))))
5829       ;; For some reason, the group window gets selected.  We change
5830       ;; it back.
5831       (select-window (get-buffer-window (current-buffer)))
5832       ;; Select next unread newsgroup automagically.
5833       (cond
5834        ((or (not gnus-auto-select-next)
5835             (not cmd))
5836         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
5837        ((or (eq gnus-auto-select-next 'quietly)
5838             (and (eq gnus-auto-select-next 'slightly-quietly)
5839                  push)
5840             (and (eq gnus-auto-select-next 'almost-quietly)
5841                  (gnus-summary-last-article-p)))
5842         ;; Select quietly.
5843         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
5844             (gnus-summary-exit)
5845           (gnus-message 7 "No more%s articles (%s)..."
5846                         (if unread " unread" "")
5847                         (if group (concat "selecting " group)
5848                           "exiting"))
5849           (gnus-summary-next-group nil group backward)))
5850        (t
5851         (when (gnus-key-press-event-p last-input-event)
5852           (gnus-summary-walk-group-buffer
5853            gnus-newsgroup-name cmd unread backward point))))))))
5854
5855 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
5856   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
5857                       (?\C-p (gnus-group-prev-unread-group 1))))
5858         (cursor-in-echo-area t)
5859         keve key group ended)
5860     (save-excursion
5861       (set-buffer gnus-group-buffer)
5862       (goto-char start)
5863       (setq group
5864             (if (eq gnus-keep-same-level 'best)
5865                 (gnus-summary-best-group gnus-newsgroup-name)
5866               (gnus-summary-search-group backward gnus-keep-same-level))))
5867     (while (not ended)
5868       (gnus-message
5869        5 "No more%s articles%s" (if unread " unread" "")
5870        (if (and group
5871                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
5872            (format " (Type %s for %s [%s])"
5873                    (single-key-description cmd) group
5874                    (car (gnus-gethash group gnus-newsrc-hashtb)))
5875          (format " (Type %s to exit %s)"
5876                  (single-key-description cmd)
5877                  gnus-newsgroup-name)))
5878       ;; Confirm auto selection.
5879       (setq key (car (setq keve (gnus-read-event-char))))
5880       (setq ended t)
5881       (cond
5882        ((assq key keystrokes)
5883         (let ((obuf (current-buffer)))
5884           (switch-to-buffer gnus-group-buffer)
5885           (when group
5886             (gnus-group-jump-to-group group))
5887           (eval (cadr (assq key keystrokes)))
5888           (setq group (gnus-group-group-name))
5889           (switch-to-buffer obuf))
5890         (setq ended nil))
5891        ((equal key cmd)
5892         (if (or (not group)
5893                 (gnus-ephemeral-group-p gnus-newsgroup-name))
5894             (gnus-summary-exit)
5895           (gnus-summary-next-group nil group backward)))
5896        (t
5897         (push (cdr keve) unread-command-events))))))
5898
5899 (defun gnus-summary-next-unread-article ()
5900   "Select unread article after current one."
5901   (interactive)
5902   (gnus-summary-next-article
5903    (or (not (eq gnus-summary-goto-unread 'never))
5904        (gnus-summary-last-article-p (gnus-summary-article-number)))
5905    (and gnus-auto-select-same
5906         (gnus-summary-article-subject))))
5907
5908 (defun gnus-summary-prev-article (&optional unread subject)
5909   "Select the article after the current one.
5910 If UNREAD is non-nil, only unread articles are selected."
5911   (interactive "P")
5912   (gnus-summary-next-article unread subject t))
5913
5914 (defun gnus-summary-prev-unread-article ()
5915   "Select unread article before current one."
5916   (interactive)
5917   (gnus-summary-prev-article
5918    (or (not (eq gnus-summary-goto-unread 'never))
5919        (gnus-summary-first-article-p (gnus-summary-article-number)))
5920    (and gnus-auto-select-same
5921         (gnus-summary-article-subject))))
5922
5923 (defun gnus-summary-next-page (&optional lines circular)
5924   "Show next page of the selected article.
5925 If at the end of the current article, select the next article.
5926 LINES says how many lines should be scrolled up.
5927
5928 If CIRCULAR is non-nil, go to the start of the article instead of
5929 selecting the next article when reaching the end of the current
5930 article."
5931   (interactive "P")
5932   (setq gnus-summary-buffer (current-buffer))
5933   (gnus-set-global-variables)
5934   (let ((article (gnus-summary-article-number))
5935         (article-window (get-buffer-window gnus-article-buffer t))
5936         endp)
5937     ;; If the buffer is empty, we have no article.
5938     (unless article
5939       (error "No article to select"))
5940     (gnus-configure-windows 'article)
5941     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
5942         (if (and (eq gnus-summary-goto-unread 'never)
5943                  (not (gnus-summary-last-article-p article)))
5944             (gnus-summary-next-article)
5945           (gnus-summary-next-unread-article))
5946       (if (or (null gnus-current-article)
5947               (null gnus-article-current)
5948               (/= article (cdr gnus-article-current))
5949               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5950           ;; Selected subject is different from current article's.
5951           (gnus-summary-display-article article)
5952         (when article-window
5953           (gnus-eval-in-buffer-window gnus-article-buffer
5954             (setq endp (gnus-article-next-page lines)))
5955           (when endp
5956             (cond (circular
5957                    (gnus-summary-beginning-of-article))
5958                   (lines
5959                    (gnus-message 3 "End of message"))
5960                   ((null lines)
5961                    (if (and (eq gnus-summary-goto-unread 'never)
5962                             (not (gnus-summary-last-article-p article)))
5963                        (gnus-summary-next-article)
5964                      (gnus-summary-next-unread-article))))))))
5965     (gnus-summary-recenter)
5966     (gnus-summary-position-point)))
5967
5968 (defun gnus-summary-prev-page (&optional lines move)
5969   "Show previous page of selected article.
5970 Argument LINES specifies lines to be scrolled down.
5971 If MOVE, move to the previous unread article if point is at
5972 the beginning of the buffer."
5973   (interactive "P")
5974   (let ((article (gnus-summary-article-number))
5975         (article-window (get-buffer-window gnus-article-buffer t))
5976         endp)
5977     (gnus-configure-windows 'article)
5978     (if (or (null gnus-current-article)
5979             (null gnus-article-current)
5980             (/= article (cdr gnus-article-current))
5981             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
5982         ;; Selected subject is different from current article's.
5983         (gnus-summary-display-article article)
5984       (gnus-summary-recenter)
5985       (when article-window
5986         (gnus-eval-in-buffer-window gnus-article-buffer
5987           (setq endp (gnus-article-prev-page lines)))
5988         (when (and move endp)
5989           (cond (lines
5990                  (gnus-message 3 "Beginning of message"))
5991                 ((null lines)
5992                  (if (and (eq gnus-summary-goto-unread 'never)
5993                           (not (gnus-summary-first-article-p article)))
5994                      (gnus-summary-prev-article)
5995                    (gnus-summary-prev-unread-article))))))))
5996   (gnus-summary-position-point))
5997
5998 (defun gnus-summary-prev-page-or-article (&optional lines)
5999   "Show previous page of selected article.
6000 Argument LINES specifies lines to be scrolled down.
6001 If at the beginning of the article, go to the next article."
6002   (interactive "P")
6003   (gnus-summary-prev-page lines t))
6004
6005 (defun gnus-summary-scroll-up (lines)
6006   "Scroll up (or down) one line current article.
6007 Argument LINES specifies lines to be scrolled up (or down if negative)."
6008   (interactive "p")
6009   (gnus-configure-windows 'article)
6010   (gnus-summary-show-thread)
6011   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6012     (gnus-eval-in-buffer-window gnus-article-buffer
6013       (cond ((> lines 0)
6014              (when (gnus-article-next-page lines)
6015                (gnus-message 3 "End of message")))
6016             ((< lines 0)
6017              (gnus-article-prev-page (- lines))))))
6018   (gnus-summary-recenter)
6019   (gnus-summary-position-point))
6020
6021 (defun gnus-summary-scroll-down (lines)
6022   "Scroll down (or up) one line current article.
6023 Argument LINES specifies lines to be scrolled down (or up if negative)."
6024   (interactive "p")
6025   (gnus-summary-scroll-up (- lines)))
6026
6027 (defun gnus-summary-next-same-subject ()
6028   "Select next article which has the same subject as current one."
6029   (interactive)
6030   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6031
6032 (defun gnus-summary-prev-same-subject ()
6033   "Select previous article which has the same subject as current one."
6034   (interactive)
6035   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6036
6037 (defun gnus-summary-next-unread-same-subject ()
6038   "Select next unread article which has the same subject as current one."
6039   (interactive)
6040   (gnus-summary-next-article t (gnus-summary-article-subject)))
6041
6042 (defun gnus-summary-prev-unread-same-subject ()
6043   "Select previous unread article which has the same subject as current one."
6044   (interactive)
6045   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6046
6047 (defun gnus-summary-first-unread-article ()
6048   "Select the first unread article.
6049 Return nil if there are no unread articles."
6050   (interactive)
6051   (prog1
6052       (when (gnus-summary-first-subject t)
6053         (gnus-summary-show-thread)
6054         (gnus-summary-first-subject t)
6055         (gnus-summary-display-article (gnus-summary-article-number)))
6056     (gnus-summary-position-point)))
6057
6058 (defun gnus-summary-first-unread-subject ()
6059   "Place the point on the subject line of the first unread article.
6060 Return nil if there are no unread articles."
6061   (interactive)
6062   (prog1
6063       (when (gnus-summary-first-subject t)
6064         (gnus-summary-show-thread)
6065         (gnus-summary-first-subject t))
6066     (gnus-summary-position-point)))
6067
6068 (defun gnus-summary-first-article ()
6069   "Select the first article.
6070 Return nil if there are no articles."
6071   (interactive)
6072   (prog1
6073       (when (gnus-summary-first-subject)
6074         (gnus-summary-show-thread)
6075         (gnus-summary-first-subject)
6076         (gnus-summary-display-article (gnus-summary-article-number)))
6077     (gnus-summary-position-point)))
6078
6079 (defun gnus-summary-best-unread-article ()
6080   "Select the unread article with the highest score."
6081   (interactive)
6082   (let ((best -1000000)
6083         (data gnus-newsgroup-data)
6084         article score)
6085     (while data
6086       (and (gnus-data-unread-p (car data))
6087            (> (setq score
6088                     (gnus-summary-article-score (gnus-data-number (car data))))
6089               best)
6090            (setq best score
6091                  article (gnus-data-number (car data))))
6092       (setq data (cdr data)))
6093     (prog1
6094         (if article
6095             (gnus-summary-goto-article article)
6096           (error "No unread articles"))
6097       (gnus-summary-position-point))))
6098
6099 (defun gnus-summary-last-subject ()
6100   "Go to the last displayed subject line in the group."
6101   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6102     (when article
6103       (gnus-summary-goto-subject article))))
6104
6105 (defun gnus-summary-goto-article (article &optional all-headers force)
6106   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6107 If ALL-HEADERS is non-nil, no header lines are hidden.
6108 If FORCE, go to the article even if it isn't displayed.  If FORCE
6109 is a number, it is the line the article is to be displayed on."
6110   (interactive
6111    (list
6112     (completing-read
6113      "Article number or Message-ID: "
6114      (mapcar (lambda (number) (list (int-to-string number)))
6115              gnus-newsgroup-limit))
6116     current-prefix-arg
6117     t))
6118   (prog1
6119       (if (and (stringp article)
6120                (string-match "@" article))
6121           (gnus-summary-refer-article article)
6122         (when (stringp article)
6123           (setq article (string-to-number article)))
6124         (if (gnus-summary-goto-subject article force)
6125             (gnus-summary-display-article article all-headers)
6126           (gnus-message 4 "Couldn't go to article %s" article) nil))
6127     (gnus-summary-position-point)))
6128
6129 (defun gnus-summary-goto-last-article ()
6130   "Go to the previously read article."
6131   (interactive)
6132   (prog1
6133       (when gnus-last-article
6134         (gnus-summary-goto-article gnus-last-article nil t))
6135     (gnus-summary-position-point)))
6136
6137 (defun gnus-summary-pop-article (number)
6138   "Pop one article off the history and go to the previous.
6139 NUMBER articles will be popped off."
6140   (interactive "p")
6141   (let (to)
6142     (setq gnus-newsgroup-history
6143           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6144     (if to
6145         (gnus-summary-goto-article (car to) nil t)
6146       (error "Article history empty")))
6147   (gnus-summary-position-point))
6148
6149 ;; Summary commands and functions for limiting the summary buffer.
6150
6151 (defun gnus-summary-limit-to-articles (n)
6152   "Limit the summary buffer to the next N articles.
6153 If not given a prefix, use the process marked articles instead."
6154   (interactive "P")
6155   (prog1
6156       (let ((articles (gnus-summary-work-articles n)))
6157         (setq gnus-newsgroup-processable nil)
6158         (gnus-summary-limit articles))
6159     (gnus-summary-position-point)))
6160
6161 (defun gnus-summary-pop-limit (&optional total)
6162   "Restore the previous limit.
6163 If given a prefix, remove all limits."
6164   (interactive "P")
6165   (when total
6166     (setq gnus-newsgroup-limits
6167           (list (mapcar (lambda (h) (mail-header-number h))
6168                         gnus-newsgroup-headers))))
6169   (unless gnus-newsgroup-limits
6170     (error "No limit to pop"))
6171   (prog1
6172       (gnus-summary-limit nil 'pop)
6173     (gnus-summary-position-point)))
6174
6175 (defun gnus-summary-limit-to-subject (subject &optional header)
6176   "Limit the summary buffer to articles that have subjects that match a regexp."
6177   (interactive "sLimit to subject (regexp): ")
6178   (unless header
6179     (setq header "subject"))
6180   (when (not (equal "" subject))
6181     (prog1
6182         (let ((articles (gnus-summary-find-matching
6183                          (or header "subject") subject 'all)))
6184           (unless articles
6185             (error "Found no matches for \"%s\"" subject))
6186           (gnus-summary-limit articles))
6187       (gnus-summary-position-point))))
6188
6189 (defun gnus-summary-limit-to-author (from)
6190   "Limit the summary buffer to articles that have authors that match a regexp."
6191   (interactive "sLimit to author (regexp): ")
6192   (gnus-summary-limit-to-subject from "from"))
6193
6194 (defun gnus-summary-limit-to-age (age &optional younger-p)
6195   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6196 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6197 articles that are younger than AGE days."
6198   (interactive "nLimit to articles older than (in days): \nP")
6199   (prog1
6200       (let ((data gnus-newsgroup-data)
6201             (cutoff (days-to-time age))
6202             articles d date is-younger)
6203         (while (setq d (pop data))
6204           (when (and (vectorp (gnus-data-header d))
6205                      (setq date (mail-header-date (gnus-data-header d))))
6206             (setq is-younger (time-less-p
6207                               (time-since (date-to-time date))
6208                               cutoff))
6209             (when (if younger-p
6210                       is-younger
6211                     (not is-younger))
6212               (push (gnus-data-number d) articles))))
6213         (gnus-summary-limit (nreverse articles)))
6214     (gnus-summary-position-point)))
6215
6216 (defun gnus-summary-limit-to-extra (header regexp)
6217   "Limit the summary buffer to articles that match an 'extra' header."
6218   (interactive
6219    (let ((header
6220           (intern
6221            (gnus-completing-read
6222             (symbol-name (car gnus-extra-headers))      
6223             "Limit extra header:"       
6224             (mapcar (lambda (x) 
6225                       (cons (symbol-name x) x))
6226                     gnus-extra-headers)
6227             nil                 
6228             t))))
6229      (list header
6230            (read-string (format "Limit to header %s (regexp): " header)))))
6231   (when (not (equal "" regexp))
6232     (prog1
6233         (let ((articles (gnus-summary-find-matching
6234                          (cons 'extra header) regexp 'all)))
6235           (unless articles
6236             (error "Found no matches for \"%s\"" regexp))
6237           (gnus-summary-limit articles))
6238       (gnus-summary-position-point))))
6239
6240 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6241 (make-obsolete
6242  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6243
6244 (defun gnus-summary-limit-to-unread (&optional all)
6245   "Limit the summary buffer to articles that are not marked as read.
6246 If ALL is non-nil, limit strictly to unread articles."
6247   (interactive "P")
6248   (if all
6249       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6250     (gnus-summary-limit-to-marks
6251      ;; Concat all the marks that say that an article is read and have
6252      ;; those removed.
6253      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6254            gnus-killed-mark gnus-kill-file-mark
6255            gnus-low-score-mark gnus-expirable-mark
6256            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6257            gnus-duplicate-mark gnus-souped-mark)
6258      'reverse)))
6259
6260 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6261 (make-obsolete 'gnus-summary-delete-marked-with
6262                'gnus-summary-limit-exlude-marks)
6263
6264 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6265   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6266 If REVERSE, limit the summary buffer to articles that are marked
6267 with MARKS.  MARKS can either be a string of marks or a list of marks.
6268 Returns how many articles were removed."
6269   (interactive "sMarks: ")
6270   (gnus-summary-limit-to-marks marks t))
6271
6272 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6273   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6274 If REVERSE (the prefix), limit the summary buffer to articles that are
6275 not marked with MARKS.  MARKS can either be a string of marks or a
6276 list of marks.
6277 Returns how many articles were removed."
6278   (interactive "sMarks: \nP")
6279   (prog1
6280       (let ((data gnus-newsgroup-data)
6281             (marks (if (listp marks) marks
6282                      (append marks nil))) ; Transform to list.
6283             articles)
6284         (while data
6285           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6286                   (memq (gnus-data-mark (car data)) marks))
6287             (push (gnus-data-number (car data)) articles))
6288           (setq data (cdr data)))
6289         (gnus-summary-limit articles))
6290     (gnus-summary-position-point)))
6291
6292 (defun gnus-summary-limit-to-score (&optional score)
6293   "Limit to articles with score at or above SCORE."
6294   (interactive "P")
6295   (setq score (if score
6296                   (prefix-numeric-value score)
6297                 (or gnus-summary-default-score 0)))
6298   (let ((data gnus-newsgroup-data)
6299         articles)
6300     (while data
6301       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6302                 score)
6303         (push (gnus-data-number (car data)) articles))
6304       (setq data (cdr data)))
6305     (prog1
6306         (gnus-summary-limit articles)
6307       (gnus-summary-position-point))))
6308
6309 (defun gnus-summary-limit-include-thread (id)
6310   "Display all the hidden articles that in the current thread."
6311   (interactive (list (mail-header-id (gnus-summary-article-header))))
6312   (let ((articles (gnus-articles-in-thread
6313                    (gnus-id-to-thread (gnus-root-id id)))))
6314     (prog1
6315         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6316       (gnus-summary-position-point))))
6317
6318 (defun gnus-summary-limit-include-dormant ()
6319   "Display all the hidden articles that are marked as dormant.
6320 Note that this command only works on a subset of the articles currently
6321 fetched for this group."
6322   (interactive)
6323   (unless gnus-newsgroup-dormant
6324     (error "There are no dormant articles in this group"))
6325   (prog1
6326       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6327     (gnus-summary-position-point)))
6328
6329 (defun gnus-summary-limit-exclude-dormant ()
6330   "Hide all dormant articles."
6331   (interactive)
6332   (prog1
6333       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6334     (gnus-summary-position-point)))
6335
6336 (defun gnus-summary-limit-exclude-childless-dormant ()
6337   "Hide all dormant articles that have no children."
6338   (interactive)
6339   (let ((data (gnus-data-list t))
6340         articles d children)
6341     ;; Find all articles that are either not dormant or have
6342     ;; children.
6343     (while (setq d (pop data))
6344       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6345                 (and (setq children
6346                            (gnus-article-children (gnus-data-number d)))
6347                      (let (found)
6348                        (while children
6349                          (when (memq (car children) articles)
6350                            (setq children nil
6351                                  found t))
6352                          (pop children))
6353                        found)))
6354         (push (gnus-data-number d) articles)))
6355     ;; Do the limiting.
6356     (prog1
6357         (gnus-summary-limit articles)
6358       (gnus-summary-position-point))))
6359
6360 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6361   "Mark all unread excluded articles as read.
6362 If ALL, mark even excluded ticked and dormants as read."
6363   (interactive "P")
6364   (let ((articles (gnus-sorted-complement
6365                    (sort
6366                     (mapcar (lambda (h) (mail-header-number h))
6367                             gnus-newsgroup-headers)
6368                     '<)
6369                    (sort gnus-newsgroup-limit '<)))
6370         article)
6371     (setq gnus-newsgroup-unreads
6372           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6373     (if all
6374         (setq gnus-newsgroup-dormant nil
6375               gnus-newsgroup-marked nil
6376               gnus-newsgroup-reads
6377               (nconc
6378                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6379                gnus-newsgroup-reads))
6380       (while (setq article (pop articles))
6381         (unless (or (memq article gnus-newsgroup-dormant)
6382                     (memq article gnus-newsgroup-marked))
6383           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6384
6385 (defun gnus-summary-limit (articles &optional pop)
6386   (if pop
6387       ;; We pop the previous limit off the stack and use that.
6388       (setq articles (car gnus-newsgroup-limits)
6389             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6390     ;; We use the new limit, so we push the old limit on the stack.
6391     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6392   ;; Set the limit.
6393   (setq gnus-newsgroup-limit articles)
6394   (let ((total (length gnus-newsgroup-data))
6395         (data (gnus-data-find-list (gnus-summary-article-number)))
6396         (gnus-summary-mark-below nil)   ; Inhibit this.
6397         found)
6398     ;; This will do all the work of generating the new summary buffer
6399     ;; according to the new limit.
6400     (gnus-summary-prepare)
6401     ;; Hide any threads, possibly.
6402     (and gnus-show-threads
6403          gnus-thread-hide-subtree
6404          (gnus-summary-hide-all-threads))
6405     ;; Try to return to the article you were at, or one in the
6406     ;; neighborhood.
6407     (when data
6408       ;; We try to find some article after the current one.
6409       (while data
6410         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6411           (setq data nil
6412                 found t))
6413         (setq data (cdr data))))
6414     (unless found
6415       ;; If there is no data, that means that we were after the last
6416       ;; article.  The same goes when we can't find any articles
6417       ;; after the current one.
6418       (goto-char (point-max))
6419       (gnus-summary-find-prev))
6420     (gnus-set-mode-line 'summary)
6421     ;; We return how many articles were removed from the summary
6422     ;; buffer as a result of the new limit.
6423     (- total (length gnus-newsgroup-data))))
6424
6425 (defsubst gnus-invisible-cut-children (threads)
6426   (let ((num 0))
6427     (while threads
6428       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6429         (incf num))
6430       (pop threads))
6431     (< num 2)))
6432
6433 (defsubst gnus-cut-thread (thread)
6434   "Go forwards in the thread until we find an article that we want to display."
6435   (when (or (eq gnus-fetch-old-headers 'some)
6436             (eq gnus-fetch-old-headers 'invisible)
6437             (eq gnus-build-sparse-threads 'some)
6438             (eq gnus-build-sparse-threads 'more))
6439     ;; Deal with old-fetched headers and sparse threads.
6440     (while (and
6441             thread
6442             (or
6443              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6444              (gnus-summary-article-ancient-p
6445               (mail-header-number (car thread))))
6446             (if (or (<= (length (cdr thread)) 1)
6447                     (eq gnus-fetch-old-headers 'invisible))
6448                 (setq gnus-newsgroup-limit
6449                       (delq (mail-header-number (car thread))
6450                             gnus-newsgroup-limit)
6451                       thread (cadr thread))
6452               (when (gnus-invisible-cut-children (cdr thread))
6453                 (let ((th (cdr thread)))
6454                   (while th
6455                     (if (memq (mail-header-number (caar th))
6456                               gnus-newsgroup-limit)
6457                         (setq thread (car th)
6458                               th nil)
6459                       (setq th (cdr th))))))))))
6460   thread)
6461
6462 (defun gnus-cut-threads (threads)
6463   "Cut off all uninteresting articles from the beginning of threads."
6464   (when (or (eq gnus-fetch-old-headers 'some)
6465             (eq gnus-fetch-old-headers 'invisible)
6466             (eq gnus-build-sparse-threads 'some)
6467             (eq gnus-build-sparse-threads 'more))
6468     (let ((th threads))
6469       (while th
6470         (setcar th (gnus-cut-thread (car th)))
6471         (setq th (cdr th)))))
6472   ;; Remove nixed out threads.
6473   (delq nil threads))
6474
6475 (defun gnus-summary-initial-limit (&optional show-if-empty)
6476   "Figure out what the initial limit is supposed to be on group entry.
6477 This entails weeding out unwanted dormants, low-scored articles,
6478 fetch-old-headers verbiage, and so on."
6479   ;; Most groups have nothing to remove.
6480   (if (or gnus-inhibit-limiting
6481           (and (null gnus-newsgroup-dormant)
6482                (not (eq gnus-fetch-old-headers 'some))
6483                (not (eq gnus-fetch-old-headers 'invisible))
6484                (null gnus-summary-expunge-below)
6485                (not (eq gnus-build-sparse-threads 'some))
6486                (not (eq gnus-build-sparse-threads 'more))
6487                (null gnus-thread-expunge-below)
6488                (not gnus-use-nocem)))
6489       ()                                ; Do nothing.
6490     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6491     (setq gnus-newsgroup-limit nil)
6492     (mapatoms
6493      (lambda (node)
6494        (unless (car (symbol-value node))
6495          ;; These threads have no parents -- they are roots.
6496          (let ((nodes (cdr (symbol-value node)))
6497                thread)
6498            (while nodes
6499              (if (and gnus-thread-expunge-below
6500                       (< (gnus-thread-total-score (car nodes))
6501                          gnus-thread-expunge-below))
6502                  (gnus-expunge-thread (pop nodes))
6503                (setq thread (pop nodes))
6504                (gnus-summary-limit-children thread))))))
6505      gnus-newsgroup-dependencies)
6506     ;; If this limitation resulted in an empty group, we might
6507     ;; pop the previous limit and use it instead.
6508     (when (and (not gnus-newsgroup-limit)
6509                show-if-empty)
6510       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6511     gnus-newsgroup-limit))
6512
6513 (defun gnus-summary-limit-children (thread)
6514   "Return 1 if this subthread is visible and 0 if it is not."
6515   ;; First we get the number of visible children to this thread.  This
6516   ;; is done by recursing down the thread using this function, so this
6517   ;; will really go down to a leaf article first, before slowly
6518   ;; working its way up towards the root.
6519   (when thread
6520     (let ((children
6521            (if (cdr thread)
6522                (apply '+ (mapcar 'gnus-summary-limit-children
6523                                  (cdr thread)))
6524              0))
6525           (number (mail-header-number (car thread)))
6526           score)
6527       (if (and
6528            (not (memq number gnus-newsgroup-marked))
6529            (or
6530             ;; If this article is dormant and has absolutely no visible
6531             ;; children, then this article isn't visible.
6532             (and (memq number gnus-newsgroup-dormant)
6533                  (zerop children))
6534             ;; If this is "fetch-old-headered" and there is no
6535             ;; visible children, then we don't want this article.
6536             (and (eq gnus-fetch-old-headers 'some)
6537                  (gnus-summary-article-ancient-p number)
6538                  (zerop children))
6539             ;; If this is "fetch-old-headered" and `invisible', then
6540             ;; we don't want this article.
6541             (and (eq gnus-fetch-old-headers 'invisible)
6542                  (gnus-summary-article-ancient-p number))
6543             ;; If this is a sparsely inserted article with no children,
6544             ;; we don't want it.
6545             (and (eq gnus-build-sparse-threads 'some)
6546                  (gnus-summary-article-sparse-p number)
6547                  (zerop children))
6548             ;; If we use expunging, and this article is really
6549             ;; low-scored, then we don't want this article.
6550             (when (and gnus-summary-expunge-below
6551                        (< (setq score
6552                                 (or (cdr (assq number gnus-newsgroup-scored))
6553                                     gnus-summary-default-score))
6554                           gnus-summary-expunge-below))
6555               ;; We increase the expunge-tally here, but that has
6556               ;; nothing to do with the limits, really.
6557               (incf gnus-newsgroup-expunged-tally)
6558               ;; We also mark as read here, if that's wanted.
6559               (when (and gnus-summary-mark-below
6560                          (< score gnus-summary-mark-below))
6561                 (setq gnus-newsgroup-unreads
6562                       (delq number gnus-newsgroup-unreads))
6563                 (if gnus-newsgroup-auto-expire
6564                     (push number gnus-newsgroup-expirable)
6565                   (push (cons number gnus-low-score-mark)
6566                         gnus-newsgroup-reads)))
6567               t)
6568             ;; Check NoCeM things.
6569             (if (and gnus-use-nocem
6570                      (gnus-nocem-unwanted-article-p
6571                       (mail-header-id (car thread))))
6572                 (progn
6573                   (setq gnus-newsgroup-unreads
6574                         (delq number gnus-newsgroup-unreads))
6575                   t))))
6576           ;; Nope, invisible article.
6577           0
6578         ;; Ok, this article is to be visible, so we add it to the limit
6579         ;; and return 1.
6580         (push number gnus-newsgroup-limit)
6581         1))))
6582
6583 (defun gnus-expunge-thread (thread)
6584   "Mark all articles in THREAD as read."
6585   (let* ((number (mail-header-number (car thread))))
6586     (incf gnus-newsgroup-expunged-tally)
6587     ;; We also mark as read here, if that's wanted.
6588     (setq gnus-newsgroup-unreads
6589           (delq number gnus-newsgroup-unreads))
6590     (if gnus-newsgroup-auto-expire
6591         (push number gnus-newsgroup-expirable)
6592       (push (cons number gnus-low-score-mark)
6593             gnus-newsgroup-reads)))
6594   ;; Go recursively through all subthreads.
6595   (mapcar 'gnus-expunge-thread (cdr thread)))
6596
6597 ;; Summary article oriented commands
6598
6599 (defun gnus-summary-refer-parent-article (n)
6600   "Refer parent article N times.
6601 If N is negative, go to ancestor -N instead.
6602 The difference between N and the number of articles fetched is returned."
6603   (interactive "p")
6604   (let ((skip 1)
6605         error header ref)
6606     (when (not (natnump n))
6607       (setq skip (abs n)
6608             n 1))
6609     (while (and (> n 0)
6610                 (not error))
6611       (setq header (gnus-summary-article-header))
6612       (if (and (eq (mail-header-number header)
6613                    (cdr gnus-article-current))
6614                (equal gnus-newsgroup-name
6615                       (car gnus-article-current)))
6616           ;; If we try to find the parent of the currently
6617           ;; displayed article, then we take a look at the actual
6618           ;; References header, since this is slightly more
6619           ;; reliable than the References field we got from the
6620           ;; server.
6621           (save-excursion
6622             (set-buffer gnus-original-article-buffer)
6623             (nnheader-narrow-to-headers)
6624             (unless (setq ref (message-fetch-field "references"))
6625               (setq ref (message-fetch-field "in-reply-to")))
6626             (widen))
6627         (setq ref
6628               ;; It's not the current article, so we take a bet on
6629               ;; the value we got from the server.
6630               (mail-header-references header)))
6631       (if (and ref
6632                (not (equal ref "")))
6633           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6634             (gnus-message 1 "Couldn't find parent"))
6635         (gnus-message 1 "No references in article %d"
6636                       (gnus-summary-article-number))
6637         (setq error t))
6638       (decf n))
6639     (gnus-summary-position-point)
6640     n))
6641
6642 (defun gnus-summary-refer-references ()
6643   "Fetch all articles mentioned in the References header.
6644 Return the number of articles fetched."
6645   (interactive)
6646   (let ((ref (mail-header-references (gnus-summary-article-header)))
6647         (current (gnus-summary-article-number))
6648         (n 0))
6649     (if (or (not ref)
6650             (equal ref ""))
6651         (error "No References in the current article")
6652       ;; For each Message-ID in the References header...
6653       (while (string-match "<[^>]*>" ref)
6654         (incf n)
6655         ;; ... fetch that article.
6656         (gnus-summary-refer-article
6657          (prog1 (match-string 0 ref)
6658            (setq ref (substring ref (match-end 0))))))
6659       (gnus-summary-goto-subject current)
6660       (gnus-summary-position-point)
6661       n)))
6662
6663 (defun gnus-summary-refer-thread (&optional limit)
6664   "Fetch all articles in the current thread.
6665 If LIMIT (the numerical prefix), fetch that many old headers instead
6666 of what's specified by the `gnus-refer-thread-limit' variable."
6667   (interactive "P")
6668   (let ((id (mail-header-id (gnus-summary-article-header)))
6669         (limit (if limit (prefix-numeric-value limit)
6670                  gnus-refer-thread-limit)))
6671     ;; We want to fetch LIMIT *old* headers, but we also have to
6672     ;; re-fetch all the headers in the current buffer, because many of
6673     ;; them may be undisplayed.  So we adjust LIMIT.
6674     (when (numberp limit)
6675       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6676     (unless (eq gnus-fetch-old-headers 'invisible)
6677       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6678       ;; Retrieve the headers and read them in.
6679       (if (eq (gnus-retrieve-headers
6680                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6681               'nov)
6682           (gnus-build-all-threads)
6683         (error "Can't fetch thread from backends that don't support NOV"))
6684       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6685     (gnus-summary-limit-include-thread id)))
6686
6687 (defun gnus-summary-refer-article (message-id &optional arg)
6688   "Fetch an article specified by MESSAGE-ID.
6689 If ARG (the prefix), fetch the article using `gnus-refer-article-method'
6690 or `gnus-select-method', no matter what backend the article comes from."
6691   (interactive "sMessage-ID: \nP")
6692   (when (and (stringp message-id)
6693              (not (zerop (length message-id))))
6694     ;; Construct the correct Message-ID if necessary.
6695     ;; Suggested by tale@pawl.rpi.edu.
6696     (unless (string-match "^<" message-id)
6697       (setq message-id (concat "<" message-id)))
6698     (unless (string-match ">$" message-id)
6699       (setq message-id (concat message-id ">")))
6700     (let* ((header (gnus-id-to-header message-id))
6701            (sparse (and header
6702                         (gnus-summary-article-sparse-p
6703                          (mail-header-number header))
6704                         (memq (mail-header-number header)
6705                               gnus-newsgroup-limit))))
6706       (cond
6707        ;; If the article is present in the buffer we just go to it.
6708        ((and header
6709              (or (not (gnus-summary-article-sparse-p
6710                        (mail-header-number header)))
6711                  sparse))
6712         (prog1
6713             (gnus-summary-goto-article
6714              (mail-header-number header) nil t)
6715           (when sparse
6716             (gnus-summary-update-article (mail-header-number header)))))
6717        (t
6718         ;; We fetch the article
6719         (let ((gnus-override-method
6720                (cond ((gnus-news-group-p gnus-newsgroup-name)
6721                       gnus-refer-article-method)
6722                      (arg
6723                       (or gnus-refer-article-method gnus-select-method))
6724                      (t nil)))
6725               number)
6726           ;; Start the special refer-article method, if necessary.
6727           (when (and gnus-refer-article-method
6728                      (gnus-news-group-p gnus-newsgroup-name))
6729             (gnus-check-server gnus-refer-article-method))
6730           ;; Fetch the header, and display the article.
6731           (if (setq number (gnus-summary-insert-subject message-id))
6732               (gnus-summary-select-article nil nil nil number)
6733             (gnus-message 3 "Couldn't fetch article %s" message-id))))))))
6734
6735 (defun gnus-summary-edit-parameters ()
6736   "Edit the group parameters of the current group."
6737   (interactive)
6738   (gnus-group-edit-group gnus-newsgroup-name 'params))
6739
6740 (defun gnus-summary-customize-parameters ()
6741   "Customize the group parameters of the current group."
6742   (interactive)
6743   (gnus-group-customize gnus-newsgroup-name))
6744
6745 (defun gnus-summary-enter-digest-group (&optional force)
6746   "Enter an nndoc group based on the current article.
6747 If FORCE, force a digest interpretation.  If not, try
6748 to guess what the document format is."
6749   (interactive "P")
6750   (let ((conf gnus-current-window-configuration))
6751     (save-excursion
6752       (gnus-summary-select-article))
6753     (setq gnus-current-window-configuration conf)
6754     (let* ((name (format "%s-%d"
6755                          (gnus-group-prefixed-name
6756                           gnus-newsgroup-name (list 'nndoc ""))
6757                          (save-excursion
6758                            (set-buffer gnus-summary-buffer)
6759                            gnus-current-article)))
6760            (ogroup gnus-newsgroup-name)
6761            (params (append (gnus-info-params (gnus-get-info ogroup))
6762                            (list (cons 'to-group ogroup))
6763                            (list (cons 'save-article-group ogroup))))
6764            (case-fold-search t)
6765            (buf (current-buffer))
6766            dig)
6767       (save-excursion
6768         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
6769         (insert-buffer-substring gnus-original-article-buffer)
6770         ;; Remove lines that may lead nndoc to misinterpret the
6771         ;; document type.
6772         (narrow-to-region
6773          (goto-char (point-min))
6774          (or (search-forward "\n\n" nil t) (point)))
6775         (goto-char (point-min))
6776         (delete-matching-lines "^Path:\\|^From ")
6777         (widen))
6778       (unwind-protect
6779           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
6780                     (gnus-newsgroup-ephemeral-ignored-charsets
6781                      gnus-newsgroup-ignored-charsets))
6782                 (gnus-group-read-ephemeral-group
6783                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
6784                               (nndoc-article-type
6785                                ,(if force 'digest 'guess))) t))
6786               ;; Make all postings to this group go to the parent group.
6787               (nconc (gnus-info-params (gnus-get-info name))
6788                      params)
6789             ;; Couldn't select this doc group.
6790             (switch-to-buffer buf)
6791             (gnus-set-global-variables)
6792             (gnus-configure-windows 'summary)
6793             (gnus-message 3 "Article couldn't be entered?"))
6794         (kill-buffer dig)))))
6795
6796 (defun gnus-summary-read-document (n)
6797   "Open a new group based on the current article(s).
6798 This will allow you to read digests and other similar
6799 documents as newsgroups.
6800 Obeys the standard process/prefix convention."
6801   (interactive "P")
6802   (let* ((articles (gnus-summary-work-articles n))
6803          (ogroup gnus-newsgroup-name)
6804          (params (append (gnus-info-params (gnus-get-info ogroup))
6805                          (list (cons 'to-group ogroup))))
6806          article group egroup groups vgroup)
6807     (while (setq article (pop articles))
6808       (setq group (format "%s-%d" gnus-newsgroup-name article))
6809       (gnus-summary-remove-process-mark article)
6810       (when (gnus-summary-display-article article)
6811         (save-excursion
6812           (with-temp-buffer
6813             (insert-buffer-substring gnus-original-article-buffer)
6814             ;; Remove some headers that may lead nndoc to make
6815             ;; the wrong guess.
6816             (message-narrow-to-head)
6817             (goto-char (point-min))
6818             (delete-matching-lines "^\\(Path\\):\\|^From ")
6819             (widen)
6820             (if (setq egroup
6821                       (gnus-group-read-ephemeral-group
6822                        group `(nndoc ,group (nndoc-address ,(current-buffer))
6823                                      (nndoc-article-type guess))
6824                        t nil t))
6825                 (progn
6826                   ;; Make all postings to this group go to the parent group.
6827                   (nconc (gnus-info-params (gnus-get-info egroup))
6828                          params)
6829                   (push egroup groups))
6830               ;; Couldn't select this doc group.
6831               (gnus-error 3 "Article couldn't be entered"))))))
6832     ;; Now we have selected all the documents.
6833     (cond
6834      ((not groups)
6835       (error "None of the articles could be interpreted as documents"))
6836      ((gnus-group-read-ephemeral-group
6837        (setq vgroup (format
6838                      "nnvirtual:%s-%s" gnus-newsgroup-name
6839                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
6840        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
6841        t
6842        (cons (current-buffer) 'summary)))
6843      (t
6844       (error "Couldn't select virtual nndoc group")))))
6845
6846 (defun gnus-summary-isearch-article (&optional regexp-p)
6847   "Do incremental search forward on the current article.
6848 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
6849   (interactive "P")
6850   (gnus-summary-select-article)
6851   (gnus-configure-windows 'article)
6852   (gnus-eval-in-buffer-window gnus-article-buffer
6853     (save-restriction
6854       (widen)
6855       (isearch-forward regexp-p))))
6856
6857 (defun gnus-summary-search-article-forward (regexp &optional backward)
6858   "Search for an article containing REGEXP forward.
6859 If BACKWARD, search backward instead."
6860   (interactive
6861    (list (read-string
6862           (format "Search article %s (regexp%s): "
6863                   (if current-prefix-arg "backward" "forward")
6864                   (if gnus-last-search-regexp
6865                       (concat ", default " gnus-last-search-regexp)
6866                     "")))
6867          current-prefix-arg))
6868   (if (string-equal regexp "")
6869       (setq regexp (or gnus-last-search-regexp ""))
6870     (setq gnus-last-search-regexp regexp))
6871   (if (gnus-summary-search-article regexp backward)
6872       (gnus-summary-show-thread)
6873     (error "Search failed: \"%s\"" regexp)))
6874
6875 (defun gnus-summary-search-article-backward (regexp)
6876   "Search for an article containing REGEXP backward."
6877   (interactive
6878    (list (read-string
6879           (format "Search article backward (regexp%s): "
6880                   (if gnus-last-search-regexp
6881                       (concat ", default " gnus-last-search-regexp)
6882                     "")))))
6883   (gnus-summary-search-article-forward regexp 'backward))
6884
6885 (defun gnus-summary-search-article (regexp &optional backward)
6886   "Search for an article containing REGEXP.
6887 Optional argument BACKWARD means do search for backward.
6888 `gnus-select-article-hook' is not called during the search."
6889   ;; We have to require this here to make sure that the following
6890   ;; dynamic binding isn't shadowed by autoloading.
6891   (require 'gnus-async)
6892   (require 'gnus-art)
6893   (let ((gnus-select-article-hook nil)  ;Disable hook.
6894         (gnus-article-display-hook nil)
6895         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
6896         (gnus-use-article-prefetch nil)
6897         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
6898         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
6899         (sum (current-buffer))
6900         (found nil)
6901         point)
6902     (gnus-save-hidden-threads
6903       (gnus-summary-select-article)
6904       (set-buffer gnus-article-buffer)
6905       (when backward
6906         (forward-line -1))
6907       (while (not found)
6908         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
6909         (if (if backward
6910                 (re-search-backward regexp nil t)
6911               (re-search-forward regexp nil t))
6912             ;; We found the regexp.
6913             (progn
6914               (setq found 'found)
6915               (beginning-of-line)
6916               (set-window-start
6917                (get-buffer-window (current-buffer))
6918                (point))
6919               (forward-line 1)
6920               (set-buffer sum)
6921               (setq point (point)))
6922           ;; We didn't find it, so we go to the next article.
6923           (set-buffer sum)
6924           (setq found 'not)
6925           (while (eq found 'not)
6926             (if (not (if backward (gnus-summary-find-prev)
6927                        (gnus-summary-find-next)))
6928                 ;; No more articles.
6929                 (setq found t)
6930               ;; Select the next article and adjust point.
6931               (unless (gnus-summary-article-sparse-p
6932                        (gnus-summary-article-number))
6933                 (setq found nil)
6934                 (gnus-summary-select-article)
6935                 (set-buffer gnus-article-buffer)
6936                 (widen)
6937                 (goto-char (if backward (point-max) (point-min))))))))
6938       (gnus-message 7 ""))
6939     ;; Return whether we found the regexp.
6940     (when (eq found 'found)
6941       (goto-char point)
6942       (gnus-summary-show-thread)
6943       (gnus-summary-goto-subject gnus-current-article)
6944       (gnus-summary-position-point)
6945       t)))
6946
6947 (defun gnus-summary-find-matching (header regexp &optional backward unread
6948                                           not-case-fold)
6949   "Return a list of all articles that match REGEXP on HEADER.
6950 The search stars on the current article and goes forwards unless
6951 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
6952 If UNREAD is non-nil, only unread articles will
6953 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
6954 in the comparisons."
6955   (let ((data (if (eq backward 'all) gnus-newsgroup-data
6956                 (gnus-data-find-list
6957                  (gnus-summary-article-number) (gnus-data-list backward))))
6958         (case-fold-search (not not-case-fold))
6959         articles d func)
6960     (if (consp header)
6961         (if (eq (car header) 'extra)
6962             (setq func
6963                   `(lambda (h)
6964                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
6965                          "")))
6966           (error "%s is an invalid header" header))
6967       (unless (fboundp (intern (concat "mail-header-" header)))
6968         (error "%s is not a valid header" header))
6969       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
6970     (while data
6971       (setq d (car data))
6972       (and (or (not unread)             ; We want all articles...
6973                (gnus-data-unread-p d))  ; Or just unreads.
6974            (vectorp (gnus-data-header d)) ; It's not a pseudo.
6975            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
6976            (push (gnus-data-number d) articles)) ; Success!
6977       (setq data (cdr data)))
6978     (nreverse articles)))
6979
6980 (defun gnus-summary-execute-command (header regexp command &optional backward)
6981   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
6982 If HEADER is an empty string (or nil), the match is done on the entire
6983 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
6984   (interactive
6985    (list (let ((completion-ignore-case t))
6986            (completing-read
6987             "Header name: "
6988             (mapcar (lambda (string) (list string))
6989                     '("Number" "Subject" "From" "Lines" "Date"
6990                       "Message-ID" "Xref" "References" "Body"))
6991             nil 'require-match))
6992          (read-string "Regexp: ")
6993          (read-key-sequence "Command: ")
6994          current-prefix-arg))
6995   (when (equal header "Body")
6996     (setq header ""))
6997   ;; Hidden thread subtrees must be searched as well.
6998   (gnus-summary-show-all-threads)
6999   ;; We don't want to change current point nor window configuration.
7000   (save-excursion
7001     (save-window-excursion
7002       (gnus-message 6 "Executing %s..." (key-description command))
7003       ;; We'd like to execute COMMAND interactively so as to give arguments.
7004       (gnus-execute header regexp
7005                     `(call-interactively ',(key-binding command))
7006                     backward)
7007       (gnus-message 6 "Executing %s...done" (key-description command)))))
7008
7009 (defun gnus-summary-beginning-of-article ()
7010   "Scroll the article back to the beginning."
7011   (interactive)
7012   (gnus-summary-select-article)
7013   (gnus-configure-windows 'article)
7014   (gnus-eval-in-buffer-window gnus-article-buffer
7015     (widen)
7016     (goto-char (point-min))
7017     (when gnus-page-broken
7018       (gnus-narrow-to-page))))
7019
7020 (defun gnus-summary-end-of-article ()
7021   "Scroll to the end of the article."
7022   (interactive)
7023   (gnus-summary-select-article)
7024   (gnus-configure-windows 'article)
7025   (gnus-eval-in-buffer-window gnus-article-buffer
7026     (widen)
7027     (goto-char (point-max))
7028     (recenter -3)
7029     (when gnus-page-broken
7030       (gnus-narrow-to-page))))
7031
7032 (defun gnus-summary-print-article (&optional filename n)
7033   "Generate and print a PostScript image of the N next (mail) articles.
7034
7035 If N is negative, print the N previous articles.  If N is nil and articles
7036 have been marked with the process mark, print these instead.
7037
7038 If the optional first argument FILENAME is nil, send the image to the
7039 printer.  If FILENAME is a string, save the PostScript image in a file with
7040 that name.  If FILENAME is a number, prompt the user for the name of the file
7041 to save in."
7042   (interactive (list (ps-print-preprint current-prefix-arg)
7043                      current-prefix-arg))
7044   (dolist (article (gnus-summary-work-articles n))
7045     (gnus-summary-select-article nil nil 'pseudo article)
7046     (gnus-eval-in-buffer-window gnus-article-buffer
7047       (let ((buffer (generate-new-buffer " *print*")))
7048         (unwind-protect
7049             (progn
7050               (copy-to-buffer buffer (point-min) (point-max))
7051               (set-buffer buffer)
7052               (gnus-article-delete-invisible-text)
7053               (let ((ps-left-header
7054                      (list
7055                       (concat "("
7056                               (mail-header-subject gnus-current-headers) ")")
7057                       (concat "("
7058                               (mail-header-from gnus-current-headers) ")")))
7059                     (ps-right-header
7060                      (list
7061                       "/pagenumberstring load"
7062                       (concat "("
7063                               (mail-header-date gnus-current-headers) ")"))))
7064                 (gnus-run-hooks 'gnus-ps-print-hook)
7065                 (save-excursion
7066                   (ps-print-buffer-with-faces filename))))
7067           (kill-buffer buffer))))))
7068
7069 (defun gnus-summary-show-article (&optional arg)
7070   "Force re-fetching of the current article.
7071 If ARG (the prefix) is non-nil, show the raw article without any
7072 article massaging functions being run."
7073   (interactive "P")
7074   (if (not arg)
7075       ;; Select the article the normal way.
7076       (gnus-summary-select-article nil 'force)
7077     ;; We have to require this here to make sure that the following
7078     ;; dynamic binding isn't shadowed by autoloading.
7079     (require 'gnus-async)
7080     (require 'gnus-art)
7081     ;; Bind the article treatment functions to nil.
7082     (let ((gnus-have-all-headers t)
7083           gnus-article-display-hook
7084           gnus-article-prepare-hook
7085           gnus-article-decode-hook
7086           gnus-break-pages
7087           gnus-show-mime
7088           gnus-visual)
7089       (gnus-summary-select-article nil 'force)))
7090   (gnus-summary-goto-subject gnus-current-article)
7091   (gnus-summary-position-point))
7092
7093 (defun gnus-summary-verbose-headers (&optional arg)
7094   "Toggle permanent full header display.
7095 If ARG is a positive number, turn header display on.
7096 If ARG is a negative number, turn header display off."
7097   (interactive "P")
7098   (setq gnus-show-all-headers
7099         (cond ((or (not (numberp arg))
7100                    (zerop arg))
7101                (not gnus-show-all-headers))
7102               ((natnump arg)
7103                t)))
7104   (gnus-summary-show-article))
7105
7106 (defun gnus-summary-toggle-header (&optional arg)
7107   "Show the headers if they are hidden, or hide them if they are shown.
7108 If ARG is a positive number, show the entire header.
7109 If ARG is a negative number, hide the unwanted header lines."
7110   (interactive "P")
7111   (save-excursion
7112     (set-buffer gnus-article-buffer)
7113     (save-restriction
7114       (let* ((buffer-read-only nil)
7115              (inhibit-point-motion-hooks t)
7116              hidden e)
7117         (save-restriction 
7118           (article-narrow-to-head)
7119           (setq hidden (gnus-article-hidden-text-p 'headers)))
7120         (goto-char (point-min))
7121         (when (search-forward "\n\n" nil t)
7122           (delete-region (point-min) (1- (point))))
7123         (goto-char (point-min))
7124         (save-excursion
7125           (set-buffer gnus-original-article-buffer)
7126           (goto-char (point-min))
7127           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7128         (insert-buffer-substring gnus-original-article-buffer 1 e)
7129         (save-restriction
7130           (narrow-to-region (point-min) (point))
7131           (article-decode-encoded-words)
7132           (if (or hidden
7133                   (and (numberp arg) (< arg 0)))
7134               (let ((gnus-treat-hide-headers nil)
7135                     (gnus-treat-hide-boring-headers nil))
7136                 (gnus-treat-article 'head))
7137             (gnus-treat-article 'head)))))))
7138
7139 (defun gnus-summary-show-all-headers ()
7140   "Make all header lines visible."
7141   (interactive)
7142   (gnus-article-show-all-headers))
7143
7144 (defun gnus-summary-toggle-mime (&optional arg)
7145   "Toggle MIME processing.
7146 If ARG is a positive number, turn MIME processing on."
7147   (interactive "P")
7148   (setq gnus-show-mime
7149         (if (null arg)
7150             (not gnus-show-mime)
7151           (> (prefix-numeric-value arg) 0)))
7152   (gnus-summary-select-article t 'force))
7153
7154 (defun gnus-summary-caesar-message (&optional arg)
7155   "Caesar rotate the current article by 13.
7156 The numerical prefix specifies how many places to rotate each letter
7157 forward."
7158   (interactive "P")
7159   (gnus-summary-select-article)
7160   (let ((mail-header-separator ""))
7161     (gnus-eval-in-buffer-window gnus-article-buffer
7162       (save-restriction
7163         (widen)
7164         (let ((start (window-start))
7165               buffer-read-only)
7166           (message-caesar-buffer-body arg)
7167           (set-window-start (get-buffer-window (current-buffer)) start))))))
7168
7169 (defun gnus-summary-stop-page-breaking ()
7170   "Stop page breaking in the current article."
7171   (interactive)
7172   (gnus-summary-select-article)
7173   (gnus-eval-in-buffer-window gnus-article-buffer
7174     (widen)
7175     (when (gnus-visual-p 'page-marker)
7176       (let ((buffer-read-only nil))
7177         (gnus-remove-text-with-property 'gnus-prev)
7178         (gnus-remove-text-with-property 'gnus-next))
7179       (setq gnus-page-broken nil))))
7180
7181 (defun gnus-summary-move-article (&optional n to-newsgroup
7182                                             select-method action)
7183   "Move the current article to a different newsgroup.
7184 If N is a positive number, move the N next articles.
7185 If N is a negative number, move the N previous articles.
7186 If N is nil and any articles have been marked with the process mark,
7187 move those articles instead.
7188 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7189 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7190 re-spool using this method.
7191
7192 For this function to work, both the current newsgroup and the
7193 newsgroup that you want to move to have to support the `request-move'
7194 and `request-accept' functions."
7195   (interactive "P")
7196   (unless action
7197     (setq action 'move))
7198   ;; Disable marking as read.
7199   (let (gnus-mark-article-hook)
7200     (save-window-excursion
7201       (gnus-summary-select-article)))
7202   ;; Check whether the source group supports the required functions.
7203   (cond ((and (eq action 'move)
7204               (not (gnus-check-backend-function
7205                     'request-move-article gnus-newsgroup-name)))
7206          (error "The current group does not support article moving"))
7207         ((and (eq action 'crosspost)
7208               (not (gnus-check-backend-function
7209                     'request-replace-article gnus-newsgroup-name)))
7210          (error "The current group does not support article editing")))
7211   (let ((articles (gnus-summary-work-articles n))
7212         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
7213         (names '((move "Move" "Moving")
7214                  (copy "Copy" "Copying")
7215                  (crosspost "Crosspost" "Crossposting")))
7216         (copy-buf (save-excursion
7217                     (nnheader-set-temp-buffer " *copy article*")))
7218         (default-marks gnus-article-mark-lists)
7219         (no-expire-marks (delete '(expirable . expire)
7220                                  (copy-sequence gnus-article-mark-lists)))
7221         art-group to-method new-xref article to-groups)
7222     (unless (assq action names)
7223       (error "Unknown action %s" action))
7224     ;; Read the newsgroup name.
7225     (when (and (not to-newsgroup)
7226                (not select-method))
7227       (setq to-newsgroup
7228             (gnus-read-move-group-name
7229              (cadr (assq action names))
7230              (symbol-value (intern (format "gnus-current-%s-group" action)))
7231              articles prefix))
7232       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7233     (setq to-method (or select-method
7234                         (gnus-group-name-to-method to-newsgroup)))
7235     ;; Check the method we are to move this article to...
7236     (unless (gnus-check-backend-function
7237              'request-accept-article (car to-method))
7238       (error "%s does not support article copying" (car to-method)))
7239     (unless (gnus-check-server to-method)
7240       (error "Can't open server %s" (car to-method)))
7241     (gnus-message 6 "%s to %s: %s..."
7242                   (caddr (assq action names))
7243                   (or (car select-method) to-newsgroup) articles)
7244     (while articles
7245       (setq article (pop articles))
7246       (setq
7247        art-group
7248        (cond
7249         ;; Move the article.
7250         ((eq action 'move)
7251          ;; Remove this article from future suppression.
7252          (gnus-dup-unsuppress-article article)
7253          (gnus-request-move-article
7254           article                       ; Article to move
7255           gnus-newsgroup-name           ; From newsgroup
7256           (nth 1 (gnus-find-method-for-group
7257                   gnus-newsgroup-name)) ; Server
7258           (list 'gnus-request-accept-article
7259                 to-newsgroup (list 'quote select-method)
7260                 (not articles) t)               ; Accept form
7261           (not articles)))              ; Only save nov last time
7262         ;; Copy the article.
7263         ((eq action 'copy)
7264          (save-excursion
7265            (set-buffer copy-buf)
7266            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7267              (gnus-request-accept-article
7268               to-newsgroup select-method (not articles) t))))
7269         ;; Crosspost the article.
7270         ((eq action 'crosspost)
7271          (let ((xref (message-tokenize-header
7272                       (mail-header-xref (gnus-summary-article-header article))
7273                       " ")))
7274            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7275                                   ":" article))
7276            (unless xref
7277              (setq xref (list (system-name))))
7278            (setq new-xref
7279                  (concat
7280                   (mapconcat 'identity
7281                              (delete "Xref:" (delete new-xref xref))
7282                              " ")
7283                   " " new-xref))
7284            (save-excursion
7285              (set-buffer copy-buf)
7286              ;; First put the article in the destination group.
7287              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7288              (when (consp (setq art-group
7289                                 (gnus-request-accept-article
7290                                  to-newsgroup select-method (not articles))))
7291                (setq new-xref (concat new-xref " " (car art-group)
7292                                       ":" (cdr art-group)))
7293                ;; Now we have the new Xrefs header, so we insert
7294                ;; it and replace the new article.
7295                (nnheader-replace-header "Xref" new-xref)
7296                (gnus-request-replace-article
7297                 (cdr art-group) to-newsgroup (current-buffer))
7298                art-group))))))
7299       (cond
7300        ((not art-group)
7301         (gnus-message 1 "Couldn't %s article %s"
7302                       (cadr (assq action names)) article))
7303        ((and (eq art-group 'junk)
7304              (eq action 'move))
7305         (gnus-summary-mark-article article gnus-canceled-mark)
7306         (gnus-message 4 "Deleted article %s" article))
7307        (t
7308         (let* ((pto-group (gnus-group-prefixed-name
7309                            (car art-group) to-method))
7310                (entry
7311                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7312                (info (nth 2 entry))
7313                (to-group (gnus-info-group info))
7314                to-marks)
7315           ;; Update the group that has been moved to.
7316           (when (and info
7317                      (memq action '(move copy)))
7318             (unless (member to-group to-groups)
7319               (push to-group to-groups))
7320
7321             (unless (memq article gnus-newsgroup-unreads)
7322               (push 'read to-marks)
7323               (gnus-info-set-read
7324                info (gnus-add-to-range (gnus-info-read info)
7325                                        (list (cdr art-group)))))
7326
7327             ;; Copy any marks over to the new group.
7328             (let ((marks (if (gnus-group-auto-expirable-p to-group)
7329                              default-marks
7330                            no-expire-marks))
7331                   (to-article (cdr art-group)))
7332
7333               ;; See whether the article is to be put in the cache.
7334               (when gnus-use-cache
7335                 (gnus-cache-possibly-enter-article
7336                  to-group to-article
7337                  (let ((header (copy-sequence
7338                                 (gnus-summary-article-header article))))
7339                    (mail-header-set-number header to-article)
7340                    header)
7341                  (memq article gnus-newsgroup-marked)
7342                  (memq article gnus-newsgroup-dormant)
7343                  (memq article gnus-newsgroup-unreads)))
7344
7345               (when (and (equal to-group gnus-newsgroup-name)
7346                          (not (memq article gnus-newsgroup-unreads)))
7347                 ;; Mark this article as read in this group.
7348                 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7349                 (setcdr (gnus-active to-group) to-article)
7350                 (setcdr gnus-newsgroup-active to-article))
7351
7352               (while marks
7353                 (when (memq article (symbol-value
7354                                      (intern (format "gnus-newsgroup-%s"
7355                                                      (caar marks)))))
7356                   (push (cdar marks) to-marks)
7357                   ;; If the other group is the same as this group,
7358                   ;; then we have to add the mark to the list.
7359                   (when (equal to-group gnus-newsgroup-name)
7360                     (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7361                          (cons to-article
7362                                (symbol-value
7363                                 (intern (format "gnus-newsgroup-%s"
7364                                                 (caar marks)))))))
7365                   ;; Copy the marks to other group.
7366                   (gnus-add-marked-articles
7367                    to-group (cdar marks) (list to-article) info))
7368                 (setq marks (cdr marks)))
7369
7370               (gnus-request-set-mark to-group (list (list (list to-article)
7371                                                           'set
7372                                                           to-marks)))
7373
7374               (gnus-dribble-enter
7375                (concat "(gnus-group-set-info '"
7376                        (gnus-prin1-to-string (gnus-get-info to-group))
7377                        ")"))))
7378
7379           ;; Update the Xref header in this article to point to
7380           ;; the new crossposted article we have just created.
7381           (when (eq action 'crosspost)
7382             (save-excursion
7383               (set-buffer copy-buf)
7384               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7385               (nnheader-replace-header "Xref" new-xref)
7386               (gnus-request-replace-article
7387                article gnus-newsgroup-name (current-buffer)))))
7388
7389         ;;;!!!Why is this necessary?
7390         (set-buffer gnus-summary-buffer)
7391
7392         (gnus-summary-goto-subject article)
7393         (when (eq action 'move)
7394           (gnus-summary-mark-article article gnus-canceled-mark))))
7395       (gnus-summary-remove-process-mark article))
7396     ;; Re-activate all groups that have been moved to.
7397     (while to-groups
7398       (save-excursion
7399         (set-buffer gnus-group-buffer)
7400         (when (gnus-group-goto-group (car to-groups) t)
7401           (gnus-group-get-new-news-this-group 1 t))
7402         (pop to-groups)))
7403
7404     (gnus-kill-buffer copy-buf)
7405     (gnus-summary-position-point)
7406     (gnus-set-mode-line 'summary)))
7407
7408 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7409   "Move the current article to a different newsgroup.
7410 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7411 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7412 re-spool using this method."
7413   (interactive "P")
7414   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7415
7416 (defun gnus-summary-crosspost-article (&optional n)
7417   "Crosspost the current article to some other group."
7418   (interactive "P")
7419   (gnus-summary-move-article n nil nil 'crosspost))
7420
7421 (defcustom gnus-summary-respool-default-method nil
7422   "Default method for respooling an article.
7423 If nil, use to the current newsgroup method."
7424   :type '(choice (gnus-select-method :value (nnml ""))
7425                  (const nil))
7426   :group 'gnus-summary-mail)
7427
7428 (defun gnus-summary-respool-article (&optional n method)
7429   "Respool the current article.
7430 The article will be squeezed through the mail spooling process again,
7431 which means that it will be put in some mail newsgroup or other
7432 depending on `nnmail-split-methods'.
7433 If N is a positive number, respool the N next articles.
7434 If N is a negative number, respool the N previous articles.
7435 If N is nil and any articles have been marked with the process mark,
7436 respool those articles instead.
7437
7438 Respooling can be done both from mail groups and \"real\" newsgroups.
7439 In the former case, the articles in question will be moved from the
7440 current group into whatever groups they are destined to.  In the
7441 latter case, they will be copied into the relevant groups."
7442   (interactive
7443    (list current-prefix-arg
7444          (let* ((methods (gnus-methods-using 'respool))
7445                 (methname
7446                  (symbol-name (or gnus-summary-respool-default-method
7447                                   (car (gnus-find-method-for-group
7448                                         gnus-newsgroup-name)))))
7449                 (method
7450                  (gnus-completing-read
7451                   methname "What backend do you want to use when respooling?"
7452                   methods nil t nil 'gnus-mail-method-history))
7453                 ms)
7454            (cond
7455             ((zerop (length (setq ms (gnus-servers-using-backend
7456                                       (intern method)))))
7457              (list (intern method) ""))
7458             ((= 1 (length ms))
7459              (car ms))
7460             (t
7461              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7462                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7463                            ms-alist))))))))
7464   (unless method
7465     (error "No method given for respooling"))
7466   (if (assoc (symbol-name
7467               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7468              (gnus-methods-using 'respool))
7469       (gnus-summary-move-article n nil method)
7470     (gnus-summary-copy-article n nil method)))
7471
7472 (defun gnus-summary-import-article (file)
7473   "Import an arbitrary file into a mail newsgroup."
7474   (interactive "fImport file: ")
7475   (let ((group gnus-newsgroup-name)
7476         (now (current-time))
7477         atts lines)
7478     (unless (gnus-check-backend-function 'request-accept-article group)
7479       (error "%s does not support article importing" group))
7480     (or (file-readable-p file)
7481         (not (file-regular-p file))
7482         (error "Can't read %s" file))
7483     (save-excursion
7484       (set-buffer (gnus-get-buffer-create " *import file*"))
7485       (erase-buffer)
7486       (nnheader-insert-file-contents file)
7487       (goto-char (point-min))
7488       (unless (nnheader-article-p)
7489         ;; This doesn't look like an article, so we fudge some headers.
7490         (setq atts (file-attributes file)
7491               lines (count-lines (point-min) (point-max)))
7492         (insert "From: " (read-string "From: ") "\n"
7493                 "Subject: " (read-string "Subject: ") "\n"
7494                 "Date: " (message-make-date (nth 5 atts))
7495                 "\n"
7496                 "Message-ID: " (message-make-message-id) "\n"
7497                 "Lines: " (int-to-string lines) "\n"
7498                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7499       (gnus-request-accept-article group nil t)
7500       (kill-buffer (current-buffer)))))
7501
7502 (defun gnus-summary-article-posted-p ()
7503   "Say whether the current (mail) article is available from `gnus-select-method' as well.
7504 This will be the case if the article has both been mailed and posted."
7505   (interactive)
7506   (let ((id (mail-header-references (gnus-summary-article-header)))
7507         (gnus-override-method
7508          (or gnus-refer-article-method gnus-select-method)))
7509     (if (gnus-request-head id "")
7510         (gnus-message 2 "The current message was found on %s"
7511                       gnus-override-method)
7512       (gnus-message 2 "The current message couldn't be found on %s"
7513                     gnus-override-method)
7514       nil)))
7515
7516 (defun gnus-summary-expire-articles (&optional now)
7517   "Expire all articles that are marked as expirable in the current group."
7518   (interactive)
7519   (when (gnus-check-backend-function
7520          'request-expire-articles gnus-newsgroup-name)
7521     ;; This backend supports expiry.
7522     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7523            (expirable (if total
7524                           (progn
7525                             ;; We need to update the info for
7526                             ;; this group for `gnus-list-of-read-articles'
7527                             ;; to give us the right answer.
7528                             (gnus-run-hooks 'gnus-exit-group-hook)
7529                             (gnus-summary-update-info)
7530                             (gnus-list-of-read-articles gnus-newsgroup-name))
7531                         (setq gnus-newsgroup-expirable
7532                               (sort gnus-newsgroup-expirable '<))))
7533            (expiry-wait (if now 'immediate
7534                           (gnus-group-find-parameter
7535                            gnus-newsgroup-name 'expiry-wait)))
7536            es)
7537       (when expirable
7538         ;; There are expirable articles in this group, so we run them
7539         ;; through the expiry process.
7540         (gnus-message 6 "Expiring articles...")
7541         (unless (gnus-check-group gnus-newsgroup-name)
7542           (error "Can't open server for %s" gnus-newsgroup-name))
7543         ;; The list of articles that weren't expired is returned.
7544         (save-excursion
7545           (if expiry-wait
7546               (let ((nnmail-expiry-wait-function nil)
7547                     (nnmail-expiry-wait expiry-wait))
7548                 (setq es (gnus-request-expire-articles
7549                           expirable gnus-newsgroup-name)))
7550             (setq es (gnus-request-expire-articles
7551                       expirable gnus-newsgroup-name))))
7552         (unless total
7553           (setq gnus-newsgroup-expirable es))
7554         ;; We go through the old list of expirable, and mark all
7555         ;; really expired articles as nonexistent.
7556         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
7557           (let ((gnus-use-cache nil))
7558             (while expirable
7559               (unless (memq (car expirable) es)
7560                 (when (gnus-data-find (car expirable))
7561                   (gnus-summary-mark-article
7562                    (car expirable) gnus-canceled-mark)))
7563               (setq expirable (cdr expirable)))))
7564         (gnus-message 6 "Expiring articles...done")))))
7565
7566 (defun gnus-summary-expire-articles-now ()
7567   "Expunge all expirable articles in the current group.
7568 This means that *all* articles that are marked as expirable will be
7569 deleted forever, right now."
7570   (interactive)
7571   (or gnus-expert-user
7572       (gnus-yes-or-no-p
7573        "Are you really, really, really sure you want to delete all these messages? ")
7574       (error "Phew!"))
7575   (gnus-summary-expire-articles t))
7576
7577 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7578 (defun gnus-summary-delete-article (&optional n)
7579   "Delete the N next (mail) articles.
7580 This command actually deletes articles.  This is not a marking
7581 command.  The article will disappear forever from your life, never to
7582 return.
7583 If N is negative, delete backwards.
7584 If N is nil and articles have been marked with the process mark,
7585 delete these instead."
7586   (interactive "P")
7587   (unless (gnus-check-backend-function 'request-expire-articles
7588                                        gnus-newsgroup-name)
7589     (error "The current newsgroup does not support article deletion"))
7590   ;; Compute the list of articles to delete.
7591   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
7592         not-deleted)
7593     (if (and gnus-novice-user
7594              (not (gnus-yes-or-no-p
7595                    (format "Do you really want to delete %s forever? "
7596                            (if (> (length articles) 1)
7597                                (format "these %s articles" (length articles))
7598                              "this article")))))
7599         ()
7600       ;; Delete the articles.
7601       (setq not-deleted (gnus-request-expire-articles
7602                          articles gnus-newsgroup-name 'force))
7603       (while articles
7604         (gnus-summary-remove-process-mark (car articles))
7605         ;; The backend might not have been able to delete the article
7606         ;; after all.
7607         (unless (memq (car articles) not-deleted)
7608           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7609         (setq articles (cdr articles)))
7610       (when not-deleted
7611         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7612     (gnus-summary-position-point)
7613     (gnus-set-mode-line 'summary)
7614     not-deleted))
7615
7616 (defun gnus-summary-edit-article (&optional force)
7617   "Edit the current article.
7618 This will have permanent effect only in mail groups.
7619 If FORCE is non-nil, allow editing of articles even in read-only
7620 groups."
7621   (interactive "P")
7622   (save-excursion
7623     (set-buffer gnus-summary-buffer)
7624     (let ((mail-parse-charset gnus-newsgroup-charset)
7625           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
7626       (gnus-set-global-variables)
7627       (when (and (not force)
7628                  (gnus-group-read-only-p))
7629         (error "The current newsgroup does not support article editing"))
7630       (gnus-summary-show-article t)
7631       (gnus-article-edit-article
7632        'ignore
7633        `(lambda (no-highlight)
7634           (let ((mail-parse-charset ',gnus-newsgroup-charset)
7635                 (mail-parse-ignored-charsets
7636                  ',gnus-newsgroup-ignored-charsets))
7637             (gnus-summary-edit-article-done
7638              ,(or (mail-header-references gnus-current-headers) "")
7639              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
7640
7641 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7642
7643 (defun gnus-summary-edit-article-done (&optional references read-only buffer
7644                                                  no-highlight)
7645   "Make edits to the current article permanent."
7646   (interactive)
7647   ;; Replace the article.
7648   (let ((buf (current-buffer)))
7649     (with-temp-buffer
7650       (insert-buffer-substring buf)
7651       (if (and (not read-only)
7652                (not (gnus-request-replace-article
7653                      (cdr gnus-article-current) (car gnus-article-current)
7654                      (current-buffer) t)))
7655           (error "Couldn't replace article")
7656         ;; Update the summary buffer.
7657         (if (and references
7658                  (equal (message-tokenize-header references " ")
7659                         (message-tokenize-header
7660                          (or (message-fetch-field "references") "") " ")))
7661             ;; We only have to update this line.
7662             (save-excursion
7663               (save-restriction
7664                 (message-narrow-to-head)
7665                 (let ((head (buffer-string))
7666                       header)
7667                   (with-temp-buffer
7668                     (insert (format "211 %d Article retrieved.\n"
7669                                     (cdr gnus-article-current)))
7670                     (insert head)
7671                     (insert ".\n")
7672                     (let ((nntp-server-buffer (current-buffer)))
7673                       (setq header (car (gnus-get-newsgroup-headers
7674                                          (save-excursion
7675                                            (set-buffer gnus-summary-buffer)
7676                                            gnus-newsgroup-dependencies)
7677                                          t))))
7678                     (save-excursion
7679                       (set-buffer gnus-summary-buffer)
7680                       (gnus-data-set-header
7681                        (gnus-data-find (cdr gnus-article-current))
7682                        header)
7683                       (gnus-summary-update-article-line
7684                        (cdr gnus-article-current) header))))))
7685           ;; Update threads.
7686           (set-buffer (or buffer gnus-summary-buffer))
7687           (gnus-summary-update-article (cdr gnus-article-current)))
7688         ;; Prettify the article buffer again.
7689         (unless no-highlight
7690           (save-excursion
7691             (set-buffer gnus-article-buffer)
7692             ;;;!!! Fix this -- article should be rehighlighted.
7693             ;;;(gnus-run-hooks 'gnus-article-display-hook)
7694             (set-buffer gnus-original-article-buffer)
7695             (gnus-request-article
7696              (cdr gnus-article-current)
7697              (car gnus-article-current) (current-buffer))))
7698         ;; Prettify the summary buffer line.
7699         (when (gnus-visual-p 'summary-highlight 'highlight)
7700           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
7701
7702 (defun gnus-summary-edit-wash (key)
7703   "Perform editing command KEY in the article buffer."
7704   (interactive
7705    (list
7706     (progn
7707       (message "%s" (concat (this-command-keys) "- "))
7708       (read-char))))
7709   (message "")
7710   (gnus-summary-edit-article)
7711   (execute-kbd-macro (concat (this-command-keys) key))
7712   (gnus-article-edit-done))
7713
7714 ;;; Respooling
7715
7716 (defun gnus-summary-respool-query (&optional silent trace)
7717   "Query where the respool algorithm would put this article."
7718   (interactive)
7719   (let (gnus-mark-article-hook)
7720     (gnus-summary-select-article)
7721     (save-excursion
7722       (set-buffer gnus-original-article-buffer)
7723       (save-restriction
7724         (message-narrow-to-head)
7725         (let ((groups (nnmail-article-group 'identity trace)))
7726           (unless silent
7727             (if groups
7728                 (message "This message would go to %s"
7729                          (mapconcat 'car groups ", "))
7730               (message "This message would go to no groups"))
7731             groups))))))
7732
7733 (defun gnus-summary-respool-trace ()
7734   "Trace where the respool algorithm would put this article.
7735 Display a buffer showing all fancy splitting patterns which matched."
7736   (interactive)
7737   (gnus-summary-respool-query nil t))
7738
7739 ;; Summary marking commands.
7740
7741 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
7742   "Mark articles which has the same subject as read, and then select the next.
7743 If UNMARK is positive, remove any kind of mark.
7744 If UNMARK is negative, tick articles."
7745   (interactive "P")
7746   (when unmark
7747     (setq unmark (prefix-numeric-value unmark)))
7748   (let ((count
7749          (gnus-summary-mark-same-subject
7750           (gnus-summary-article-subject) unmark)))
7751     ;; Select next unread article.  If auto-select-same mode, should
7752     ;; select the first unread article.
7753     (gnus-summary-next-article t (and gnus-auto-select-same
7754                                       (gnus-summary-article-subject)))
7755     (gnus-message 7 "%d article%s marked as %s"
7756                   count (if (= count 1) " is" "s are")
7757                   (if unmark "unread" "read"))))
7758
7759 (defun gnus-summary-kill-same-subject (&optional unmark)
7760   "Mark articles which has the same subject as read.
7761 If UNMARK is positive, remove any kind of mark.
7762 If UNMARK is negative, tick articles."
7763   (interactive "P")
7764   (when unmark
7765     (setq unmark (prefix-numeric-value unmark)))
7766   (let ((count
7767          (gnus-summary-mark-same-subject
7768           (gnus-summary-article-subject) unmark)))
7769     ;; If marked as read, go to next unread subject.
7770     (when (null unmark)
7771       ;; Go to next unread subject.
7772       (gnus-summary-next-subject 1 t))
7773     (gnus-message 7 "%d articles are marked as %s"
7774                   count (if unmark "unread" "read"))))
7775
7776 (defun gnus-summary-mark-same-subject (subject &optional unmark)
7777   "Mark articles with same SUBJECT as read, and return marked number.
7778 If optional argument UNMARK is positive, remove any kinds of marks.
7779 If optional argument UNMARK is negative, mark articles as unread instead."
7780   (let ((count 1))
7781     (save-excursion
7782       (cond
7783        ((null unmark)                   ; Mark as read.
7784         (while (and
7785                 (progn
7786                   (gnus-summary-mark-article-as-read gnus-killed-mark)
7787                   (gnus-summary-show-thread) t)
7788                 (gnus-summary-find-subject subject))
7789           (setq count (1+ count))))
7790        ((> unmark 0)                    ; Tick.
7791         (while (and
7792                 (progn
7793                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
7794                   (gnus-summary-show-thread) t)
7795                 (gnus-summary-find-subject subject))
7796           (setq count (1+ count))))
7797        (t                               ; Mark as unread.
7798         (while (and
7799                 (progn
7800                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
7801                   (gnus-summary-show-thread) t)
7802                 (gnus-summary-find-subject subject))
7803           (setq count (1+ count)))))
7804       (gnus-set-mode-line 'summary)
7805       ;; Return the number of marked articles.
7806       count)))
7807
7808 (defun gnus-summary-mark-as-processable (n &optional unmark)
7809   "Set the process mark on the next N articles.
7810 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
7811 the process mark instead.  The difference between N and the actual
7812 number of articles marked is returned."
7813   (interactive "p")
7814   (let ((backward (< n 0))
7815         (n (abs n)))
7816     (while (and
7817             (> n 0)
7818             (if unmark
7819                 (gnus-summary-remove-process-mark
7820                  (gnus-summary-article-number))
7821               (gnus-summary-set-process-mark (gnus-summary-article-number)))
7822             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
7823       (setq n (1- n)))
7824     (when (/= 0 n)
7825       (gnus-message 7 "No more articles"))
7826     (gnus-summary-recenter)
7827     (gnus-summary-position-point)
7828     n))
7829
7830 (defun gnus-summary-unmark-as-processable (n)
7831   "Remove the process mark from the next N articles.
7832 If N is negative, unmark backward instead.  The difference between N and
7833 the actual number of articles unmarked is returned."
7834   (interactive "p")
7835   (gnus-summary-mark-as-processable n t))
7836
7837 (defun gnus-summary-unmark-all-processable ()
7838   "Remove the process mark from all articles."
7839   (interactive)
7840   (save-excursion
7841     (while gnus-newsgroup-processable
7842       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
7843   (gnus-summary-position-point))
7844
7845 (defun gnus-summary-mark-as-expirable (n)
7846   "Mark N articles forward as expirable.
7847 If N is negative, mark backward instead.  The difference between N and
7848 the actual number of articles marked is returned."
7849   (interactive "p")
7850   (gnus-summary-mark-forward n gnus-expirable-mark))
7851
7852 (defun gnus-summary-mark-article-as-replied (article)
7853   "Mark ARTICLE replied and update the summary line."
7854   (push article gnus-newsgroup-replied)
7855   (let ((buffer-read-only nil))
7856     (when (gnus-summary-goto-subject article nil t)
7857       (gnus-summary-update-secondary-mark article))))
7858
7859 (defun gnus-summary-set-bookmark (article)
7860   "Set a bookmark in current article."
7861   (interactive (list (gnus-summary-article-number)))
7862   (when (or (not (get-buffer gnus-article-buffer))
7863             (not gnus-current-article)
7864             (not gnus-article-current)
7865             (not (equal gnus-newsgroup-name (car gnus-article-current))))
7866     (error "No current article selected"))
7867   ;; Remove old bookmark, if one exists.
7868   (let ((old (assq article gnus-newsgroup-bookmarks)))
7869     (when old
7870       (setq gnus-newsgroup-bookmarks
7871             (delq old gnus-newsgroup-bookmarks))))
7872   ;; Set the new bookmark, which is on the form
7873   ;; (article-number . line-number-in-body).
7874   (push
7875    (cons article
7876          (save-excursion
7877            (set-buffer gnus-article-buffer)
7878            (count-lines
7879             (min (point)
7880                  (save-excursion
7881                    (goto-char (point-min))
7882                    (search-forward "\n\n" nil t)
7883                    (point)))
7884             (point))))
7885    gnus-newsgroup-bookmarks)
7886   (gnus-message 6 "A bookmark has been added to the current article."))
7887
7888 (defun gnus-summary-remove-bookmark (article)
7889   "Remove the bookmark from the current article."
7890   (interactive (list (gnus-summary-article-number)))
7891   ;; Remove old bookmark, if one exists.
7892   (let ((old (assq article gnus-newsgroup-bookmarks)))
7893     (if old
7894         (progn
7895           (setq gnus-newsgroup-bookmarks
7896                 (delq old gnus-newsgroup-bookmarks))
7897           (gnus-message 6 "Removed bookmark."))
7898       (gnus-message 6 "No bookmark in current article."))))
7899
7900 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
7901 (defun gnus-summary-mark-as-dormant (n)
7902   "Mark N articles forward as dormant.
7903 If N is negative, mark backward instead.  The difference between N and
7904 the actual number of articles marked is returned."
7905   (interactive "p")
7906   (gnus-summary-mark-forward n gnus-dormant-mark))
7907
7908 (defun gnus-summary-set-process-mark (article)
7909   "Set the process mark on ARTICLE and update the summary line."
7910   (setq gnus-newsgroup-processable
7911         (cons article
7912               (delq article gnus-newsgroup-processable)))
7913   (when (gnus-summary-goto-subject article)
7914     (gnus-summary-show-thread)
7915     (gnus-summary-goto-subject article)
7916     (gnus-summary-update-secondary-mark article)))
7917
7918 (defun gnus-summary-remove-process-mark (article)
7919   "Remove the process mark from ARTICLE and update the summary line."
7920   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
7921   (when (gnus-summary-goto-subject article)
7922     (gnus-summary-show-thread)
7923     (gnus-summary-goto-subject article)
7924     (gnus-summary-update-secondary-mark article)))
7925
7926 (defun gnus-summary-set-saved-mark (article)
7927   "Set the process mark on ARTICLE and update the summary line."
7928   (push article gnus-newsgroup-saved)
7929   (when (gnus-summary-goto-subject article)
7930     (gnus-summary-update-secondary-mark article)))
7931
7932 (defun gnus-summary-mark-forward (n &optional mark no-expire)
7933   "Mark N articles as read forwards.
7934 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
7935 The difference between N and the actual number of articles marked is
7936 returned."
7937   (interactive "p")
7938   (gnus-summary-show-thread)
7939   (let ((backward (< n 0))
7940         (gnus-summary-goto-unread
7941          (and gnus-summary-goto-unread
7942               (not (eq gnus-summary-goto-unread 'never))
7943               (not (memq mark (list gnus-unread-mark
7944                                     gnus-ticked-mark gnus-dormant-mark)))))
7945         (n (abs n))
7946         (mark (or mark gnus-del-mark)))
7947     (while (and (> n 0)
7948                 (gnus-summary-mark-article nil mark no-expire)
7949                 (zerop (gnus-summary-next-subject
7950                         (if backward -1 1)
7951                         (and gnus-summary-goto-unread
7952                              (not (eq gnus-summary-goto-unread 'never)))
7953                         t)))
7954       (setq n (1- n)))
7955     (when (/= 0 n)
7956       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
7957     (gnus-summary-recenter)
7958     (gnus-summary-position-point)
7959     (gnus-set-mode-line 'summary)
7960     n))
7961
7962 (defun gnus-summary-mark-article-as-read (mark)
7963   "Mark the current article quickly as read with MARK."
7964   (let ((article (gnus-summary-article-number)))
7965     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
7966     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7967     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7968     (push (cons article mark) gnus-newsgroup-reads)
7969     ;; Possibly remove from cache, if that is used.
7970     (when gnus-use-cache
7971       (gnus-cache-enter-remove-article article))
7972     ;; Allow the backend to change the mark.
7973     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7974     ;; Check for auto-expiry.
7975     (when (and gnus-newsgroup-auto-expire
7976                (memq mark gnus-auto-expirable-marks))
7977       (setq mark gnus-expirable-mark)
7978       ;; Let the backend know about the mark change.
7979       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7980       (push article gnus-newsgroup-expirable))
7981     ;; Set the mark in the buffer.
7982     (gnus-summary-update-mark mark 'unread)
7983     t))
7984
7985 (defun gnus-summary-mark-article-as-unread (mark)
7986   "Mark the current article quickly as unread with MARK."
7987   (let* ((article (gnus-summary-article-number))
7988          (old-mark (gnus-summary-article-mark article)))
7989     ;; Allow the backend to change the mark.
7990     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
7991     (if (eq mark old-mark)
7992         t
7993       (if (<= article 0)
7994           (progn
7995             (gnus-error 1 "Can't mark negative article numbers")
7996             nil)
7997         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
7998         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
7999         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8000         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8001         (cond ((= mark gnus-ticked-mark)
8002                (push article gnus-newsgroup-marked))
8003               ((= mark gnus-dormant-mark)
8004                (push article gnus-newsgroup-dormant))
8005               (t
8006                (push article gnus-newsgroup-unreads)))
8007         (gnus-pull article gnus-newsgroup-reads)
8008
8009         ;; See whether the article is to be put in the cache.
8010         (and gnus-use-cache
8011              (vectorp (gnus-summary-article-header article))
8012              (save-excursion
8013                (gnus-cache-possibly-enter-article
8014                 gnus-newsgroup-name article
8015                 (gnus-summary-article-header article)
8016                 (= mark gnus-ticked-mark)
8017                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8018
8019         ;; Fix the mark.
8020         (gnus-summary-update-mark mark 'unread)
8021         t))))
8022
8023 (defun gnus-summary-mark-article (&optional article mark no-expire)
8024   "Mark ARTICLE with MARK.  MARK can be any character.
8025 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8026 `??' (dormant) and `?E' (expirable).
8027 If MARK is nil, then the default character `?r' is used.
8028 If ARTICLE is nil, then the article on the current line will be
8029 marked."
8030   ;; The mark might be a string.
8031   (when (stringp mark)
8032     (setq mark (aref mark 0)))
8033   ;; If no mark is given, then we check auto-expiring.
8034   (when (null mark)
8035     (setq mark gnus-del-mark))
8036   (when (and (not no-expire)
8037              gnus-newsgroup-auto-expire
8038              (memq mark gnus-auto-expirable-marks))
8039     (setq mark gnus-expirable-mark))
8040   (let ((article (or article (gnus-summary-article-number)))
8041         (old-mark (gnus-summary-article-mark article)))
8042     ;; Allow the backend to change the mark.
8043     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8044     (if (eq mark old-mark)
8045         t
8046       (unless article
8047         (error "No article on current line"))
8048       (if (not (if (or (= mark gnus-unread-mark)
8049                        (= mark gnus-ticked-mark)
8050                        (= mark gnus-dormant-mark))
8051                    (gnus-mark-article-as-unread article mark)
8052                  (gnus-mark-article-as-read article mark)))
8053           t
8054         ;; See whether the article is to be put in the cache.
8055         (and gnus-use-cache
8056              (not (= mark gnus-canceled-mark))
8057              (vectorp (gnus-summary-article-header article))
8058              (save-excursion
8059                (gnus-cache-possibly-enter-article
8060                 gnus-newsgroup-name article
8061                 (gnus-summary-article-header article)
8062                 (= mark gnus-ticked-mark)
8063                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8064
8065         (when (gnus-summary-goto-subject article nil t)
8066           (let ((buffer-read-only nil))
8067             (gnus-summary-show-thread)
8068             ;; Fix the mark.
8069             (gnus-summary-update-mark mark 'unread)
8070             t))))))
8071
8072 (defun gnus-summary-update-secondary-mark (article)
8073   "Update the secondary (read, process, cache) mark."
8074   (gnus-summary-update-mark
8075    (cond ((memq article gnus-newsgroup-processable)
8076           gnus-process-mark)
8077          ((memq article gnus-newsgroup-cached)
8078           gnus-cached-mark)
8079          ((memq article gnus-newsgroup-replied)
8080           gnus-replied-mark)
8081          ((memq article gnus-newsgroup-saved)
8082           gnus-saved-mark)
8083          (t gnus-unread-mark))
8084    'replied)
8085   (when (gnus-visual-p 'summary-highlight 'highlight)
8086     (gnus-run-hooks 'gnus-summary-update-hook))
8087   t)
8088
8089 (defun gnus-summary-update-mark (mark type)
8090   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8091         (buffer-read-only nil))
8092     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8093     (when forward
8094       (when (looking-at "\r")
8095         (incf forward))
8096       (when (<= (+ forward (point)) (point-max))
8097         ;; Go to the right position on the line.
8098         (goto-char (+ forward (point)))
8099         ;; Replace the old mark with the new mark.
8100         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8101         ;; Optionally update the marks by some user rule.
8102         (when (eq type 'unread)
8103           (gnus-data-set-mark
8104            (gnus-data-find (gnus-summary-article-number)) mark)
8105           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
8106
8107 (defun gnus-mark-article-as-read (article &optional mark)
8108   "Enter ARTICLE in the pertinent lists and remove it from others."
8109   ;; Make the article expirable.
8110   (let ((mark (or mark gnus-del-mark)))
8111     (if (= mark gnus-expirable-mark)
8112         (push article gnus-newsgroup-expirable)
8113       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8114     ;; Remove from unread and marked lists.
8115     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8116     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8117     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8118     (push (cons article mark) gnus-newsgroup-reads)
8119     ;; Possibly remove from cache, if that is used.
8120     (when gnus-use-cache
8121       (gnus-cache-enter-remove-article article))
8122     t))
8123
8124 (defun gnus-mark-article-as-unread (article &optional mark)
8125   "Enter ARTICLE in the pertinent lists and remove it from others."
8126   (let ((mark (or mark gnus-ticked-mark)))
8127     (if (<= article 0)
8128         (progn
8129           (gnus-error 1 "Can't mark negative article numbers")
8130           nil)
8131       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8132             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8133             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8134             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8135
8136       ;; Unsuppress duplicates?
8137       (when gnus-suppress-duplicates
8138         (gnus-dup-unsuppress-article article))
8139
8140       (cond ((= mark gnus-ticked-mark)
8141              (push article gnus-newsgroup-marked))
8142             ((= mark gnus-dormant-mark)
8143              (push article gnus-newsgroup-dormant))
8144             (t
8145              (push article gnus-newsgroup-unreads)))
8146       (gnus-pull article gnus-newsgroup-reads)
8147       t)))
8148
8149 (defalias 'gnus-summary-mark-as-unread-forward
8150   'gnus-summary-tick-article-forward)
8151 (make-obsolete 'gnus-summary-mark-as-unread-forward
8152                'gnus-summary-tick-article-forward)
8153 (defun gnus-summary-tick-article-forward (n)
8154   "Tick N articles forwards.
8155 If N is negative, tick backwards instead.
8156 The difference between N and the number of articles ticked is returned."
8157   (interactive "p")
8158   (gnus-summary-mark-forward n gnus-ticked-mark))
8159
8160 (defalias 'gnus-summary-mark-as-unread-backward
8161   'gnus-summary-tick-article-backward)
8162 (make-obsolete 'gnus-summary-mark-as-unread-backward
8163                'gnus-summary-tick-article-backward)
8164 (defun gnus-summary-tick-article-backward (n)
8165   "Tick N articles backwards.
8166 The difference between N and the number of articles ticked is returned."
8167   (interactive "p")
8168   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8169
8170 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8171 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8172 (defun gnus-summary-tick-article (&optional article clear-mark)
8173   "Mark current article as unread.
8174 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8175 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8176   (interactive)
8177   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8178                                        gnus-ticked-mark)))
8179
8180 (defun gnus-summary-mark-as-read-forward (n)
8181   "Mark N articles as read forwards.
8182 If N is negative, mark backwards instead.
8183 The difference between N and the actual number of articles marked is
8184 returned."
8185   (interactive "p")
8186   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8187
8188 (defun gnus-summary-mark-as-read-backward (n)
8189   "Mark the N articles as read backwards.
8190 The difference between N and the actual number of articles marked is
8191 returned."
8192   (interactive "p")
8193   (gnus-summary-mark-forward
8194    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8195
8196 (defun gnus-summary-mark-as-read (&optional article mark)
8197   "Mark current article as read.
8198 ARTICLE specifies the article to be marked as read.
8199 MARK specifies a string to be inserted at the beginning of the line."
8200   (gnus-summary-mark-article article mark))
8201
8202 (defun gnus-summary-clear-mark-forward (n)
8203   "Clear marks from N articles forward.
8204 If N is negative, clear backward instead.
8205 The difference between N and the number of marks cleared is returned."
8206   (interactive "p")
8207   (gnus-summary-mark-forward n gnus-unread-mark))
8208
8209 (defun gnus-summary-clear-mark-backward (n)
8210   "Clear marks from N articles backward.
8211 The difference between N and the number of marks cleared is returned."
8212   (interactive "p")
8213   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8214
8215 (defun gnus-summary-mark-unread-as-read ()
8216   "Intended to be used by `gnus-summary-mark-article-hook'."
8217   (when (memq gnus-current-article gnus-newsgroup-unreads)
8218     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8219
8220 (defun gnus-summary-mark-read-and-unread-as-read ()
8221   "Intended to be used by `gnus-summary-mark-article-hook'."
8222   (let ((mark (gnus-summary-article-mark)))
8223     (when (or (gnus-unread-mark-p mark)
8224               (gnus-read-mark-p mark))
8225       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8226
8227 (defun gnus-summary-mark-region-as-read (point mark all)
8228   "Mark all unread articles between point and mark as read.
8229 If given a prefix, mark all articles between point and mark as read,
8230 even ticked and dormant ones."
8231   (interactive "r\nP")
8232   (save-excursion
8233     (let (article)
8234       (goto-char point)
8235       (beginning-of-line)
8236       (while (and
8237               (< (point) mark)
8238               (progn
8239                 (when (or all
8240                           (memq (setq article (gnus-summary-article-number))
8241                                 gnus-newsgroup-unreads))
8242                   (gnus-summary-mark-article article gnus-del-mark))
8243                 t)
8244               (gnus-summary-find-next))))))
8245
8246 (defun gnus-summary-mark-below (score mark)
8247   "Mark articles with score less than SCORE with MARK."
8248   (interactive "P\ncMark: ")
8249   (setq score (if score
8250                   (prefix-numeric-value score)
8251                 (or gnus-summary-default-score 0)))
8252   (save-excursion
8253     (set-buffer gnus-summary-buffer)
8254     (goto-char (point-min))
8255     (while
8256         (progn
8257           (and (< (gnus-summary-article-score) score)
8258                (gnus-summary-mark-article nil mark))
8259           (gnus-summary-find-next)))))
8260
8261 (defun gnus-summary-kill-below (&optional score)
8262   "Mark articles with score below SCORE as read."
8263   (interactive "P")
8264   (gnus-summary-mark-below score gnus-killed-mark))
8265
8266 (defun gnus-summary-clear-above (&optional score)
8267   "Clear all marks from articles with score above SCORE."
8268   (interactive "P")
8269   (gnus-summary-mark-above score gnus-unread-mark))
8270
8271 (defun gnus-summary-tick-above (&optional score)
8272   "Tick all articles with score above SCORE."
8273   (interactive "P")
8274   (gnus-summary-mark-above score gnus-ticked-mark))
8275
8276 (defun gnus-summary-mark-above (score mark)
8277   "Mark articles with score over SCORE with MARK."
8278   (interactive "P\ncMark: ")
8279   (setq score (if score
8280                   (prefix-numeric-value score)
8281                 (or gnus-summary-default-score 0)))
8282   (save-excursion
8283     (set-buffer gnus-summary-buffer)
8284     (goto-char (point-min))
8285     (while (and (progn
8286                   (when (> (gnus-summary-article-score) score)
8287                     (gnus-summary-mark-article nil mark))
8288                   t)
8289                 (gnus-summary-find-next)))))
8290
8291 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8292 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8293 (defun gnus-summary-limit-include-expunged (&optional no-error)
8294   "Display all the hidden articles that were expunged for low scores."
8295   (interactive)
8296   (let ((buffer-read-only nil))
8297     (let ((scored gnus-newsgroup-scored)
8298           headers h)
8299       (while scored
8300         (unless (gnus-summary-goto-subject (caar scored))
8301           (and (setq h (gnus-summary-article-header (caar scored)))
8302                (< (cdar scored) gnus-summary-expunge-below)
8303                (push h headers)))
8304         (setq scored (cdr scored)))
8305       (if (not headers)
8306           (when (not no-error)
8307             (error "No expunged articles hidden"))
8308         (goto-char (point-min))
8309         (gnus-summary-prepare-unthreaded (nreverse headers))
8310         (goto-char (point-min))
8311         (gnus-summary-position-point)
8312         t))))
8313
8314 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8315   "Mark all unread articles in this newsgroup as read.
8316 If prefix argument ALL is non-nil, ticked and dormant articles will
8317 also be marked as read.
8318 If QUIETLY is non-nil, no questions will be asked.
8319 If TO-HERE is non-nil, it should be a point in the buffer.  All
8320 articles before this point will be marked as read.
8321 Note that this function will only catch up the unread article
8322 in the current summary buffer limitation.
8323 The number of articles marked as read is returned."
8324   (interactive "P")
8325   (prog1
8326       (save-excursion
8327         (when (or quietly
8328                   (not gnus-interactive-catchup) ;Without confirmation?
8329                   gnus-expert-user
8330                   (gnus-y-or-n-p
8331                    (if all
8332                        "Mark absolutely all articles as read? "
8333                      "Mark all unread articles as read? ")))
8334           (if (and not-mark
8335                    (not gnus-newsgroup-adaptive)
8336                    (not gnus-newsgroup-auto-expire)
8337                    (not gnus-suppress-duplicates)
8338                    (or (not gnus-use-cache)
8339                        (eq gnus-use-cache 'passive)))
8340               (progn
8341                 (when all
8342                   (setq gnus-newsgroup-marked nil
8343                         gnus-newsgroup-dormant nil))
8344                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8345             ;; We actually mark all articles as canceled, which we
8346             ;; have to do when using auto-expiry or adaptive scoring.
8347             (gnus-summary-show-all-threads)
8348             (when (gnus-summary-first-subject (not all) t)
8349               (while (and
8350                       (if to-here (< (point) to-here) t)
8351                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8352                       (gnus-summary-find-next (not all) nil nil t))))
8353             (gnus-set-mode-line 'summary))
8354           t))
8355     (gnus-summary-position-point)))
8356
8357 (defun gnus-summary-catchup-to-here (&optional all)
8358   "Mark all unticked articles before the current one as read.
8359 If ALL is non-nil, also mark ticked and dormant articles as read."
8360   (interactive "P")
8361   (save-excursion
8362     (gnus-save-hidden-threads
8363       (let ((beg (point)))
8364         ;; We check that there are unread articles.
8365         (when (or all (gnus-summary-find-prev))
8366           (gnus-summary-catchup all t beg)))))
8367   (gnus-summary-position-point))
8368
8369 (defun gnus-summary-catchup-all (&optional quietly)
8370   "Mark all articles in this newsgroup as read."
8371   (interactive "P")
8372   (gnus-summary-catchup t quietly))
8373
8374 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8375   "Mark all unread articles in this group as read, then exit.
8376 If prefix argument ALL is non-nil, all articles are marked as read."
8377   (interactive "P")
8378   (when (gnus-summary-catchup all quietly nil 'fast)
8379     ;; Select next newsgroup or exit.
8380     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8381              (eq gnus-auto-select-next 'quietly))
8382         (gnus-summary-next-group nil)
8383       (gnus-summary-exit))))
8384
8385 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8386   "Mark all articles in this newsgroup as read, and then exit."
8387   (interactive "P")
8388   (gnus-summary-catchup-and-exit t quietly))
8389
8390 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
8391 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8392   "Mark all articles in this group as read and select the next group.
8393 If given a prefix, mark all articles, unread as well as ticked, as
8394 read."
8395   (interactive "P")
8396   (save-excursion
8397     (gnus-summary-catchup all))
8398   (gnus-summary-next-article t nil nil t))
8399
8400 ;; Thread-based commands.
8401
8402 (defun gnus-summary-articles-in-thread (&optional article)
8403   "Return a list of all articles in the current thread.
8404 If ARTICLE is non-nil, return all articles in the thread that starts
8405 with that article."
8406   (let* ((article (or article (gnus-summary-article-number)))
8407          (data (gnus-data-find-list article))
8408          (top-level (gnus-data-level (car data)))
8409          (top-subject
8410           (cond ((null gnus-thread-operation-ignore-subject)
8411                  (gnus-simplify-subject-re
8412                   (mail-header-subject (gnus-data-header (car data)))))
8413                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8414                  (gnus-simplify-subject-fuzzy
8415                   (mail-header-subject (gnus-data-header (car data)))))
8416                 (t nil)))
8417          (end-point (save-excursion
8418                       (if (gnus-summary-go-to-next-thread)
8419                           (point) (point-max))))
8420          articles)
8421     (while (and data
8422                 (< (gnus-data-pos (car data)) end-point))
8423       (when (or (not top-subject)
8424                 (string= top-subject
8425                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8426                              (gnus-simplify-subject-fuzzy
8427                               (mail-header-subject
8428                                (gnus-data-header (car data))))
8429                            (gnus-simplify-subject-re
8430                             (mail-header-subject
8431                              (gnus-data-header (car data)))))))
8432         (push (gnus-data-number (car data)) articles))
8433       (unless (and (setq data (cdr data))
8434                    (> (gnus-data-level (car data)) top-level))
8435         (setq data nil)))
8436     ;; Return the list of articles.
8437     (nreverse articles)))
8438
8439 (defun gnus-summary-rethread-current ()
8440   "Rethread the thread the current article is part of."
8441   (interactive)
8442   (let* ((gnus-show-threads t)
8443          (article (gnus-summary-article-number))
8444          (id (mail-header-id (gnus-summary-article-header)))
8445          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8446     (unless id
8447       (error "No article on the current line"))
8448     (gnus-rebuild-thread id)
8449     (gnus-summary-goto-subject article)))
8450
8451 (defun gnus-summary-reparent-thread ()
8452   "Make the current article child of the marked (or previous) article.
8453
8454 Note that the re-threading will only work if `gnus-thread-ignore-subject'
8455 is non-nil or the Subject: of both articles are the same."
8456   (interactive)
8457   (unless (not (gnus-group-read-only-p))
8458     (error "The current newsgroup does not support article editing"))
8459   (unless (<= (length gnus-newsgroup-processable) 1)
8460     (error "No more than one article may be marked"))
8461   (save-window-excursion
8462     (let ((gnus-article-buffer " *reparent*")
8463           (current-article (gnus-summary-article-number))
8464           ;; First grab the marked article, otherwise one line up.
8465           (parent-article (if (not (null gnus-newsgroup-processable))
8466                               (car gnus-newsgroup-processable)
8467                             (save-excursion
8468                               (if (eq (forward-line -1) 0)
8469                                   (gnus-summary-article-number)
8470                                 (error "Beginning of summary buffer"))))))
8471       (unless (not (eq current-article parent-article))
8472         (error "An article may not be self-referential"))
8473       (let ((message-id (mail-header-id
8474                          (gnus-summary-article-header parent-article))))
8475         (unless (and message-id (not (equal message-id "")))
8476           (error "No message-id in desired parent"))
8477         (gnus-with-article current-article
8478           (goto-char (point-min))
8479           (if (re-search-forward "^References: " nil t)
8480               (progn
8481                 (re-search-forward "^[^ \t]" nil t)
8482                 (forward-line -1)
8483                 (end-of-line)
8484                 (insert " " message-id))
8485             (insert "References: " message-id "\n")))
8486         (set-buffer gnus-summary-buffer)
8487         (gnus-summary-unmark-all-processable)
8488         (gnus-summary-update-article current-article)
8489         (gnus-summary-rethread-current)
8490         (gnus-message 3 "Article %d is now the child of article %d"
8491                       current-article parent-article)))))
8492
8493 (defun gnus-summary-toggle-threads (&optional arg)
8494   "Toggle showing conversation threads.
8495 If ARG is positive number, turn showing conversation threads on."
8496   (interactive "P")
8497   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8498     (setq gnus-show-threads
8499           (if (null arg) (not gnus-show-threads)
8500             (> (prefix-numeric-value arg) 0)))
8501     (gnus-summary-prepare)
8502     (gnus-summary-goto-subject current)
8503     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8504     (gnus-summary-position-point)))
8505
8506 (defun gnus-summary-show-all-threads ()
8507   "Show all threads."
8508   (interactive)
8509   (save-excursion
8510     (let ((buffer-read-only nil))
8511       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8512   (gnus-summary-position-point))
8513
8514 (defun gnus-summary-show-thread ()
8515   "Show thread subtrees.
8516 Returns nil if no thread was there to be shown."
8517   (interactive)
8518   (let ((buffer-read-only nil)
8519         (orig (point))
8520         ;; first goto end then to beg, to have point at beg after let
8521         (end (progn (end-of-line) (point)))
8522         (beg (progn (beginning-of-line) (point))))
8523     (prog1
8524         ;; Any hidden lines here?
8525         (search-forward "\r" end t)
8526       (subst-char-in-region beg end ?\^M ?\n t)
8527       (goto-char orig)
8528       (gnus-summary-position-point))))
8529
8530 (defun gnus-summary-hide-all-threads ()
8531   "Hide all thread subtrees."
8532   (interactive)
8533   (save-excursion
8534     (goto-char (point-min))
8535     (gnus-summary-hide-thread)
8536     (while (zerop (gnus-summary-next-thread 1 t))
8537       (gnus-summary-hide-thread)))
8538   (gnus-summary-position-point))
8539
8540 (defun gnus-summary-hide-thread ()
8541   "Hide thread subtrees.
8542 Returns nil if no threads were there to be hidden."
8543   (interactive)
8544   (let ((buffer-read-only nil)
8545         (start (point))
8546         (article (gnus-summary-article-number)))
8547     (goto-char start)
8548     ;; Go forward until either the buffer ends or the subthread
8549     ;; ends.
8550     (when (and (not (eobp))
8551                (or (zerop (gnus-summary-next-thread 1 t))
8552                    (goto-char (point-max))))
8553       (prog1
8554           (if (and (> (point) start)
8555                    (search-backward "\n" start t))
8556               (progn
8557                 (subst-char-in-region start (point) ?\n ?\^M)
8558                 (gnus-summary-goto-subject article))
8559             (goto-char start)
8560             nil)
8561         ;;(gnus-summary-position-point)
8562         ))))
8563
8564 (defun gnus-summary-go-to-next-thread (&optional previous)
8565   "Go to the same level (or less) next thread.
8566 If PREVIOUS is non-nil, go to previous thread instead.
8567 Return the article number moved to, or nil if moving was impossible."
8568   (let ((level (gnus-summary-thread-level))
8569         (way (if previous -1 1))
8570         (beg (point)))
8571     (forward-line way)
8572     (while (and (not (eobp))
8573                 (< level (gnus-summary-thread-level)))
8574       (forward-line way))
8575     (if (eobp)
8576         (progn
8577           (goto-char beg)
8578           nil)
8579       (setq beg (point))
8580       (prog1
8581           (gnus-summary-article-number)
8582         (goto-char beg)))))
8583
8584 (defun gnus-summary-next-thread (n &optional silent)
8585   "Go to the same level next N'th thread.
8586 If N is negative, search backward instead.
8587 Returns the difference between N and the number of skips actually
8588 done.
8589
8590 If SILENT, don't output messages."
8591   (interactive "p")
8592   (let ((backward (< n 0))
8593         (n (abs n)))
8594     (while (and (> n 0)
8595                 (gnus-summary-go-to-next-thread backward))
8596       (decf n))
8597     (unless silent
8598       (gnus-summary-position-point))
8599     (when (and (not silent) (/= 0 n))
8600       (gnus-message 7 "No more threads"))
8601     n))
8602
8603 (defun gnus-summary-prev-thread (n)
8604   "Go to the same level previous N'th thread.
8605 Returns the difference between N and the number of skips actually
8606 done."
8607   (interactive "p")
8608   (gnus-summary-next-thread (- n)))
8609
8610 (defun gnus-summary-go-down-thread ()
8611   "Go down one level in the current thread."
8612   (let ((children (gnus-summary-article-children)))
8613     (when children
8614       (gnus-summary-goto-subject (car children)))))
8615
8616 (defun gnus-summary-go-up-thread ()
8617   "Go up one level in the current thread."
8618   (let ((parent (gnus-summary-article-parent)))
8619     (when parent
8620       (gnus-summary-goto-subject parent))))
8621
8622 (defun gnus-summary-down-thread (n)
8623   "Go down thread N steps.
8624 If N is negative, go up instead.
8625 Returns the difference between N and how many steps down that were
8626 taken."
8627   (interactive "p")
8628   (let ((up (< n 0))
8629         (n (abs n)))
8630     (while (and (> n 0)
8631                 (if up (gnus-summary-go-up-thread)
8632                   (gnus-summary-go-down-thread)))
8633       (setq n (1- n)))
8634     (gnus-summary-position-point)
8635     (when (/= 0 n)
8636       (gnus-message 7 "Can't go further"))
8637     n))
8638
8639 (defun gnus-summary-up-thread (n)
8640   "Go up thread N steps.
8641 If N is negative, go up instead.
8642 Returns the difference between N and how many steps down that were
8643 taken."
8644   (interactive "p")
8645   (gnus-summary-down-thread (- n)))
8646
8647 (defun gnus-summary-top-thread ()
8648   "Go to the top of the thread."
8649   (interactive)
8650   (while (gnus-summary-go-up-thread))
8651   (gnus-summary-article-number))
8652
8653 (defun gnus-summary-kill-thread (&optional unmark)
8654   "Mark articles under current thread as read.
8655 If the prefix argument is positive, remove any kinds of marks.
8656 If the prefix argument is negative, tick articles instead."
8657   (interactive "P")
8658   (when unmark
8659     (setq unmark (prefix-numeric-value unmark)))
8660   (let ((articles (gnus-summary-articles-in-thread)))
8661     (save-excursion
8662       ;; Expand the thread.
8663       (gnus-summary-show-thread)
8664       ;; Mark all the articles.
8665       (while articles
8666         (gnus-summary-goto-subject (car articles))
8667         (cond ((null unmark)
8668                (gnus-summary-mark-article-as-read gnus-killed-mark))
8669               ((> unmark 0)
8670                (gnus-summary-mark-article-as-unread gnus-unread-mark))
8671               (t
8672                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8673         (setq articles (cdr articles))))
8674     ;; Hide killed subtrees.
8675     (and (null unmark)
8676          gnus-thread-hide-killed
8677          (gnus-summary-hide-thread))
8678     ;; If marked as read, go to next unread subject.
8679     (when (null unmark)
8680       ;; Go to next unread subject.
8681       (gnus-summary-next-subject 1 t)))
8682   (gnus-set-mode-line 'summary))
8683
8684 ;; Summary sorting commands
8685
8686 (defun gnus-summary-sort-by-number (&optional reverse)
8687   "Sort the summary buffer by article number.
8688 Argument REVERSE means reverse order."
8689   (interactive "P")
8690   (gnus-summary-sort 'number reverse))
8691
8692 (defun gnus-summary-sort-by-author (&optional reverse)
8693   "Sort the summary buffer by author name alphabetically.
8694 If case-fold-search is non-nil, case of letters is ignored.
8695 Argument REVERSE means reverse order."
8696   (interactive "P")
8697   (gnus-summary-sort 'author reverse))
8698
8699 (defun gnus-summary-sort-by-subject (&optional reverse)
8700   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
8701 If case-fold-search is non-nil, case of letters is ignored.
8702 Argument REVERSE means reverse order."
8703   (interactive "P")
8704   (gnus-summary-sort 'subject reverse))
8705
8706 (defun gnus-summary-sort-by-date (&optional reverse)
8707   "Sort the summary buffer by date.
8708 Argument REVERSE means reverse order."
8709   (interactive "P")
8710   (gnus-summary-sort 'date reverse))
8711
8712 (defun gnus-summary-sort-by-score (&optional reverse)
8713   "Sort the summary buffer by score.
8714 Argument REVERSE means reverse order."
8715   (interactive "P")
8716   (gnus-summary-sort 'score reverse))
8717
8718 (defun gnus-summary-sort-by-lines (&optional reverse)
8719   "Sort the summary buffer by the number of lines.
8720 Argument REVERSE means reverse order."
8721   (interactive "P")
8722   (gnus-summary-sort 'lines reverse))
8723
8724 (defun gnus-summary-sort-by-chars (&optional reverse)
8725   "Sort the summary buffer by article length.
8726 Argument REVERSE means reverse order."
8727   (interactive "P")
8728   (gnus-summary-sort 'chars reverse))   
8729
8730 (defun gnus-summary-sort (predicate reverse)
8731   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
8732   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
8733          (article (intern (format "gnus-article-sort-by-%s" predicate)))
8734          (gnus-thread-sort-functions
8735           (if (not reverse)
8736               thread
8737             `(lambda (t1 t2)
8738                (,thread t2 t1))))
8739          (gnus-article-sort-functions
8740           (if (not reverse)
8741               article
8742             `(lambda (t1 t2)
8743                (,article t2 t1))))
8744          (buffer-read-only)
8745          (gnus-summary-prepare-hook nil))
8746     ;; We do the sorting by regenerating the threads.
8747     (gnus-summary-prepare)
8748     ;; Hide subthreads if needed.
8749     (when (and gnus-show-threads gnus-thread-hide-subtree)
8750       (gnus-summary-hide-all-threads))))
8751
8752 ;; Summary saving commands.
8753
8754 (defun gnus-summary-save-article (&optional n not-saved)
8755   "Save the current article using the default saver function.
8756 If N is a positive number, save the N next articles.
8757 If N is a negative number, save the N previous articles.
8758 If N is nil and any articles have been marked with the process mark,
8759 save those articles instead.
8760 The variable `gnus-default-article-saver' specifies the saver function."
8761   (interactive "P")
8762   (let* ((articles (gnus-summary-work-articles n))
8763          (save-buffer (save-excursion
8764                         (nnheader-set-temp-buffer " *Gnus Save*")))
8765          (num (length articles))
8766          header file)
8767     (dolist (article articles)
8768       (setq header (gnus-summary-article-header article))
8769       (if (not (vectorp header))
8770           ;; This is a pseudo-article.
8771           (if (assq 'name header)
8772               (gnus-copy-file (cdr (assq 'name header)))
8773             (gnus-message 1 "Article %d is unsaveable" article))
8774         ;; This is a real article.
8775         (save-window-excursion
8776           (gnus-summary-select-article t nil nil article))
8777         (save-excursion
8778           (set-buffer save-buffer)
8779           (erase-buffer)
8780           (insert-buffer-substring gnus-original-article-buffer))
8781         (setq file (gnus-article-save save-buffer file num))
8782         (gnus-summary-remove-process-mark article)
8783         (unless not-saved
8784           (gnus-summary-set-saved-mark article))))
8785     (gnus-kill-buffer save-buffer)
8786     (gnus-summary-position-point)
8787     (gnus-set-mode-line 'summary)
8788     n))
8789
8790 (defun gnus-summary-pipe-output (&optional arg)
8791   "Pipe the current article to a subprocess.
8792 If N is a positive number, pipe the N next articles.
8793 If N is a negative number, pipe the N previous articles.
8794 If N is nil and any articles have been marked with the process mark,
8795 pipe those articles instead."
8796   (interactive "P")
8797   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
8798     (gnus-summary-save-article arg t))
8799   (gnus-configure-windows 'pipe))
8800
8801 (defun gnus-summary-save-article-mail (&optional arg)
8802   "Append the current article to an mail file.
8803 If N is a positive number, save the N next articles.
8804 If N is a negative number, save the N previous articles.
8805 If N is nil and any articles have been marked with the process mark,
8806 save those articles instead."
8807   (interactive "P")
8808   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
8809     (gnus-summary-save-article arg)))
8810
8811 (defun gnus-summary-save-article-rmail (&optional arg)
8812   "Append the current article to an rmail file.
8813 If N is a positive number, save the N next articles.
8814 If N is a negative number, save the N previous articles.
8815 If N is nil and any articles have been marked with the process mark,
8816 save those articles instead."
8817   (interactive "P")
8818   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
8819     (gnus-summary-save-article arg)))
8820
8821 (defun gnus-summary-save-article-file (&optional arg)
8822   "Append the current article to a file.
8823 If N is a positive number, save the N next articles.
8824 If N is a negative number, save the N previous articles.
8825 If N is nil and any articles have been marked with the process mark,
8826 save those articles instead."
8827   (interactive "P")
8828   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
8829     (gnus-summary-save-article arg)))
8830
8831 (defun gnus-summary-write-article-file (&optional arg)
8832   "Write the current article to a file, deleting the previous file.
8833 If N is a positive number, save the N next articles.
8834 If N is a negative number, save the N previous articles.
8835 If N is nil and any articles have been marked with the process mark,
8836 save those articles instead."
8837   (interactive "P")
8838   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
8839     (gnus-summary-save-article arg)))
8840
8841 (defun gnus-summary-save-article-body-file (&optional arg)
8842   "Append the current article body to a file.
8843 If N is a positive number, save the N next articles.
8844 If N is a negative number, save the N previous articles.
8845 If N is nil and any articles have been marked with the process mark,
8846 save those articles instead."
8847   (interactive "P")
8848   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
8849     (gnus-summary-save-article arg)))
8850
8851 (defun gnus-summary-pipe-message (program)
8852   "Pipe the current article through PROGRAM."
8853   (interactive "sProgram: ")
8854   (gnus-summary-select-article)
8855   (let ((mail-header-separator ""))
8856     (gnus-eval-in-buffer-window gnus-article-buffer
8857       (save-restriction
8858         (widen)
8859         (let ((start (window-start))
8860               buffer-read-only)
8861           (message-pipe-buffer-body program)
8862           (set-window-start (get-buffer-window (current-buffer)) start))))))
8863
8864 (defun gnus-get-split-value (methods)
8865   "Return a value based on the split METHODS."
8866   (let (split-name method result match)
8867     (when methods
8868       (save-excursion
8869         (set-buffer gnus-original-article-buffer)
8870         (save-restriction
8871           (nnheader-narrow-to-headers)
8872           (while methods
8873             (goto-char (point-min))
8874             (setq method (pop methods))
8875             (setq match (car method))
8876             (when (cond
8877                    ((stringp match)
8878                     ;; Regular expression.
8879                     (ignore-errors
8880                       (re-search-forward match nil t)))
8881                    ((gnus-functionp match)
8882                     ;; Function.
8883                     (save-restriction
8884                       (widen)
8885                       (setq result (funcall match gnus-newsgroup-name))))
8886                    ((consp match)
8887                     ;; Form.
8888                     (save-restriction
8889                       (widen)
8890                       (setq result (eval match)))))
8891               (setq split-name (append (cdr method) split-name))
8892               (cond ((stringp result)
8893                      (push (expand-file-name
8894                             result gnus-article-save-directory)
8895                            split-name))
8896                     ((consp result)
8897                      (setq split-name (append result split-name)))))))))
8898     (nreverse split-name)))
8899
8900 (defun gnus-valid-move-group-p (group)
8901   (and (boundp group)
8902        (symbol-name group)
8903        (symbol-value group)
8904        (gnus-get-function (gnus-find-method-for-group
8905                            (symbol-name group)) 'request-accept-article t)))
8906
8907 (defun gnus-read-move-group-name (prompt default articles prefix)
8908   "Read a group name."
8909   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
8910          (minibuffer-confirm-incomplete nil) ; XEmacs
8911          (prom
8912           (format "%s %s to:"
8913                   prompt
8914                   (if (> (length articles) 1)
8915                       (format "these %d articles" (length articles))
8916                     "this article")))
8917          (to-newsgroup
8918           (cond
8919            ((null split-name)
8920             (gnus-completing-read default prom
8921                                   gnus-active-hashtb
8922                                   'gnus-valid-move-group-p
8923                                   nil prefix
8924                                   'gnus-group-history))
8925            ((= 1 (length split-name))
8926             (gnus-completing-read (car split-name) prom
8927                                   gnus-active-hashtb
8928                                   'gnus-valid-move-group-p
8929                                   nil nil
8930                                   'gnus-group-history))
8931            (t
8932             (gnus-completing-read nil prom
8933                                   (mapcar (lambda (el) (list el))
8934                                           (nreverse split-name))
8935                                   nil nil nil
8936                                   'gnus-group-history)))))
8937     (when to-newsgroup
8938       (if (or (string= to-newsgroup "")
8939               (string= to-newsgroup prefix))
8940           (setq to-newsgroup default))
8941       (unless to-newsgroup
8942         (error "No group name entered"))
8943       (or (gnus-active to-newsgroup)
8944           (gnus-activate-group to-newsgroup)
8945           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
8946                                      to-newsgroup))
8947               (or (and (gnus-request-create-group
8948                         to-newsgroup (gnus-group-name-to-method to-newsgroup))
8949                        (gnus-activate-group to-newsgroup nil nil
8950                                             (gnus-group-name-to-method
8951                                              to-newsgroup)))
8952                   (error "Couldn't create group %s" to-newsgroup)))
8953           (error "No such group: %s" to-newsgroup)))
8954     to-newsgroup))
8955
8956 (defun gnus-summary-save-parts (type dir n reverse)
8957   "Save parts matching TYPE to DIR.
8958 If REVERSE, save parts that do not match TYPE."
8959   (interactive
8960    (list (read-string "Save parts of type: " "image/.*")
8961          (read-file-name "Save to directory: " t nil t)
8962          current-prefix-arg))
8963   (gnus-summary-iterate n
8964     (let ((gnus-display-mime-function nil)
8965           (gnus-inhibit-treatment t))
8966       (gnus-summary-select-article))
8967     (save-excursion
8968       (set-buffer gnus-article-buffer)
8969       (let ((handles (or (mm-dissect-buffer) (mm-uu-dissect))))
8970         (when handles
8971           (gnus-summary-save-parts-1 type dir handles reverse)
8972           (mm-destroy-parts handles))))))
8973
8974 (defun gnus-summary-save-parts-1 (type dir handle reverse)
8975   (if (stringp (car handle))
8976       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
8977               (cdr handle))
8978     (when (if reverse
8979               (not (string-match type (mm-handle-media-type handle)))
8980             (string-match type (mm-handle-media-type handle)))
8981       (let ((file (expand-file-name
8982                    (file-name-nondirectory
8983                     (or
8984                      (mail-content-type-get
8985                       (mm-handle-disposition handle) 'filename)
8986                      (concat gnus-newsgroup-name "." gnus-current-article)))
8987                    dir)))
8988         (unless (file-exists-p file)
8989           (mm-save-part-to-file handle file))))))
8990
8991 ;; Summary extract commands
8992
8993 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
8994   (let ((buffer-read-only nil)
8995         (article (gnus-summary-article-number))
8996         after-article b e)
8997     (unless (gnus-summary-goto-subject article)
8998       (error "No such article: %d" article))
8999     (gnus-summary-position-point)
9000     ;; If all commands are to be bunched up on one line, we collect
9001     ;; them here.
9002     (unless gnus-view-pseudos-separately
9003       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9004             files action)
9005         (while ps
9006           (setq action (cdr (assq 'action (car ps))))
9007           (setq files (list (cdr (assq 'name (car ps)))))
9008           (while (and ps (cdr ps)
9009                       (string= (or action "1")
9010                                (or (cdr (assq 'action (cadr ps))) "2")))
9011             (push (cdr (assq 'name (cadr ps))) files)
9012             (setcdr ps (cddr ps)))
9013           (when files
9014             (when (not (string-match "%s" action))
9015               (push " " files))
9016             (push " " files)
9017             (when (assq 'execute (car ps))
9018               (setcdr (assq 'execute (car ps))
9019                       (funcall (if (string-match "%s" action)
9020                                    'format 'concat)
9021                                action
9022                                (mapconcat
9023                                 (lambda (f)
9024                                   (if (equal f " ")
9025                                       f
9026                                     (gnus-quote-arg-for-sh-or-csh f)))
9027                                 files " ")))))
9028           (setq ps (cdr ps)))))
9029     (if (and gnus-view-pseudos (not not-view))
9030         (while pslist
9031           (when (assq 'execute (car pslist))
9032             (gnus-execute-command (cdr (assq 'execute (car pslist)))
9033                                   (eq gnus-view-pseudos 'not-confirm)))
9034           (setq pslist (cdr pslist)))
9035       (save-excursion
9036         (while pslist
9037           (setq after-article (or (cdr (assq 'article (car pslist)))
9038                                   (gnus-summary-article-number)))
9039           (gnus-summary-goto-subject after-article)
9040           (forward-line 1)
9041           (setq b (point))
9042           (insert "    " (file-name-nondirectory
9043                           (cdr (assq 'name (car pslist))))
9044                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9045           (setq e (point))
9046           (forward-line -1)             ; back to `b'
9047           (gnus-add-text-properties
9048            b (1- e) (list 'gnus-number gnus-reffed-article-number
9049                           gnus-mouse-face-prop gnus-mouse-face))
9050           (gnus-data-enter
9051            after-article gnus-reffed-article-number
9052            gnus-unread-mark b (car pslist) 0 (- e b))
9053           (push gnus-reffed-article-number gnus-newsgroup-unreads)
9054           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9055           (setq pslist (cdr pslist)))))))
9056
9057 (defun gnus-pseudos< (p1 p2)
9058   (let ((c1 (cdr (assq 'action p1)))
9059         (c2 (cdr (assq 'action p2))))
9060     (and c1 c2 (string< c1 c2))))
9061
9062 (defun gnus-request-pseudo-article (props)
9063   (cond ((assq 'execute props)
9064          (gnus-execute-command (cdr (assq 'execute props)))))
9065   (let ((gnus-current-article (gnus-summary-article-number)))
9066     (gnus-run-hooks 'gnus-mark-article-hook)))
9067
9068 (defun gnus-execute-command (command &optional automatic)
9069   (save-excursion
9070     (gnus-article-setup-buffer)
9071     (set-buffer gnus-article-buffer)
9072     (setq buffer-read-only nil)
9073     (let ((command (if automatic command
9074                      (read-string "Command: " (cons command 0)))))
9075       (erase-buffer)
9076       (insert "$ " command "\n\n")
9077       (if gnus-view-pseudo-asynchronously
9078           (start-process "gnus-execute" (current-buffer) shell-file-name
9079                          shell-command-switch command)
9080         (call-process shell-file-name nil t nil
9081                       shell-command-switch command)))))
9082
9083 ;; Summary kill commands.
9084
9085 (defun gnus-summary-edit-global-kill (article)
9086   "Edit the \"global\" kill file."
9087   (interactive (list (gnus-summary-article-number)))
9088   (gnus-group-edit-global-kill article))
9089
9090 (defun gnus-summary-edit-local-kill ()
9091   "Edit a local kill file applied to the current newsgroup."
9092   (interactive)
9093   (setq gnus-current-headers (gnus-summary-article-header))
9094   (gnus-group-edit-local-kill
9095    (gnus-summary-article-number) gnus-newsgroup-name))
9096
9097 ;;; Header reading.
9098
9099 (defun gnus-read-header (id &optional header)
9100   "Read the headers of article ID and enter them into the Gnus system."
9101   (let ((group gnus-newsgroup-name)
9102         (gnus-override-method
9103          (and (gnus-news-group-p gnus-newsgroup-name)
9104               gnus-refer-article-method))
9105         where)
9106     ;; First we check to see whether the header in question is already
9107     ;; fetched.
9108     (if (stringp id)
9109         ;; This is a Message-ID.
9110         (setq header (or header (gnus-id-to-header id)))
9111       ;; This is an article number.
9112       (setq header (or header (gnus-summary-article-header id))))
9113     (if (and header
9114              (not (gnus-summary-article-sparse-p (mail-header-number header))))
9115         ;; We have found the header.
9116         header
9117       ;; If this is a sparse article, we have to nix out its
9118       ;; previous entry in the thread hashtb.
9119       (when (and header
9120                  (gnus-summary-article-sparse-p (mail-header-number header)))
9121         (let* ((parent (gnus-parent-id (mail-header-references header)))
9122                (thread (and parent (gnus-id-to-thread parent))))
9123           (when thread
9124             (delq (assq header thread) thread))))
9125       ;; We have to really fetch the header to this article.
9126       (save-excursion
9127         (set-buffer nntp-server-buffer)
9128         (when (setq where (gnus-request-head id group))
9129           (nnheader-fold-continuation-lines)
9130           (goto-char (point-max))
9131           (insert ".\n")
9132           (goto-char (point-min))
9133           (insert "211 ")
9134           (princ (cond
9135                   ((numberp id) id)
9136                   ((cdr where) (cdr where))
9137                   (header (mail-header-number header))
9138                   (t gnus-reffed-article-number))
9139                  (current-buffer))
9140           (insert " Article retrieved.\n"))
9141         (if (or (not where)
9142                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9143             ()                          ; Malformed head.
9144           (unless (gnus-summary-article-sparse-p (mail-header-number header))
9145             (when (and (stringp id)
9146                        (not (string= (gnus-group-real-name group)
9147                                      (car where))))
9148               ;; If we fetched by Message-ID and the article came
9149               ;; from a different group, we fudge some bogus article
9150               ;; numbers for this article.
9151               (mail-header-set-number header gnus-reffed-article-number))
9152             (save-excursion
9153               (set-buffer gnus-summary-buffer)
9154               (decf gnus-reffed-article-number)
9155               (gnus-remove-header (mail-header-number header))
9156               (push header gnus-newsgroup-headers)
9157               (setq gnus-current-headers header)
9158               (push (mail-header-number header) gnus-newsgroup-limit)))
9159           header)))))
9160
9161 (defun gnus-remove-header (number)
9162   "Remove header NUMBER from `gnus-newsgroup-headers'."
9163   (if (and gnus-newsgroup-headers
9164            (= number (mail-header-number (car gnus-newsgroup-headers))))
9165       (pop gnus-newsgroup-headers)
9166     (let ((headers gnus-newsgroup-headers))
9167       (while (and (cdr headers)
9168                   (not (= number (mail-header-number (cadr headers)))))
9169         (pop headers))
9170       (when (cdr headers)
9171         (setcdr headers (cddr headers))))))
9172
9173 ;;;
9174 ;;; summary highlights
9175 ;;;
9176
9177 (defun gnus-highlight-selected-summary ()
9178   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9179   ;; Highlight selected article in summary buffer
9180   (when gnus-summary-selected-face
9181     (save-excursion
9182       (let* ((beg (progn (beginning-of-line) (point)))
9183              (end (progn (end-of-line) (point)))
9184              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9185              (from (if (get-text-property beg gnus-mouse-face-prop)
9186                        beg
9187                      (or (next-single-property-change
9188                           beg gnus-mouse-face-prop nil end)
9189                          beg)))
9190              (to
9191               (if (= from end)
9192                   (- from 2)
9193                 (or (next-single-property-change
9194                      from gnus-mouse-face-prop nil end)
9195                     end))))
9196         ;; If no mouse-face prop on line we will have to = from = end,
9197         ;; so we highlight the entire line instead.
9198         (when (= (+ to 2) from)
9199           (setq from beg)
9200           (setq to end))
9201         (if gnus-newsgroup-selected-overlay
9202             ;; Move old overlay.
9203             (gnus-move-overlay
9204              gnus-newsgroup-selected-overlay from to (current-buffer))
9205           ;; Create new overlay.
9206           (gnus-overlay-put
9207            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9208            'face gnus-summary-selected-face))))))
9209
9210 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9211 (defun gnus-summary-highlight-line ()
9212   "Highlight current line according to `gnus-summary-highlight'."
9213   (let* ((list gnus-summary-highlight)
9214          (p (point))
9215          (end (progn (end-of-line) (point)))
9216          ;; now find out where the line starts and leave point there.
9217          (beg (progn (beginning-of-line) (point)))
9218          (article (gnus-summary-article-number))
9219          (score (or (cdr (assq (or article gnus-current-article)
9220                                gnus-newsgroup-scored))
9221                     gnus-summary-default-score 0))
9222          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9223          (inhibit-read-only t))
9224     ;; Eval the cars of the lists until we find a match.
9225     (let ((default gnus-summary-default-score))
9226       (while (and list
9227                   (not (eval (caar list))))
9228         (setq list (cdr list))))
9229     (let ((face (cdar list)))
9230       (unless (eq face (get-text-property beg 'face))
9231         (gnus-put-text-property-excluding-characters-with-faces
9232          beg end 'face
9233          (setq face (if (boundp face) (symbol-value face) face)))
9234         (when gnus-summary-highlight-line-function
9235           (funcall gnus-summary-highlight-line-function article face))))
9236     (goto-char p)))
9237
9238 (defun gnus-update-read-articles (group unread &optional compute)
9239   "Update the list of read articles in GROUP."
9240   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9241          (entry (gnus-gethash group gnus-newsrc-hashtb))
9242          (info (nth 2 entry))
9243          (prev 1)
9244          (unread (sort (copy-sequence unread) '<))
9245          read)
9246     (if (or (not info) (not active))
9247         ;; There is no info on this group if it was, in fact,
9248         ;; killed.  Gnus stores no information on killed groups, so
9249         ;; there's nothing to be done.
9250         ;; One could store the information somewhere temporarily,
9251         ;; perhaps...  Hmmm...
9252         ()
9253       ;; Remove any negative articles numbers.
9254       (while (and unread (< (car unread) 0))
9255         (setq unread (cdr unread)))
9256       ;; Remove any expired article numbers
9257       (while (and unread (< (car unread) (car active)))
9258         (setq unread (cdr unread)))
9259       ;; Compute the ranges of read articles by looking at the list of
9260       ;; unread articles.
9261       (while unread
9262         (when (/= (car unread) prev)
9263           (push (if (= prev (1- (car unread))) prev
9264                   (cons prev (1- (car unread))))
9265                 read))
9266         (setq prev (1+ (car unread)))
9267         (setq unread (cdr unread)))
9268       (when (<= prev (cdr active))
9269         (push (cons prev (cdr active)) read))
9270       (setq read (if (> (length read) 1) (nreverse read) read))
9271       (if compute
9272           read
9273         (save-excursion
9274           (set-buffer gnus-group-buffer)
9275           (gnus-undo-register
9276             `(progn
9277                (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9278                (gnus-info-set-read ',info ',(gnus-info-read info))
9279                (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
9280                (gnus-group-update-group ,group t))))
9281        ;; Propagate the read marks to the backend.
9282        (if (gnus-check-backend-function 'request-set-mark group)
9283            (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9284                  (add (gnus-remove-from-range read (gnus-info-read info))))
9285              (when (or add del)
9286                (unless (gnus-check-group group)
9287                  (error "Can't open server for %s" group))
9288                (gnus-request-set-mark
9289                 group (delq nil (list (if add (list add 'add '(read)))
9290                                       (if del (list del 'del '(read)))))))))
9291         ;; Enter this list into the group info.
9292         (gnus-info-set-read info read)
9293         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9294         (gnus-get-unread-articles-in-group info (gnus-active group))
9295         t))))
9296
9297 (defun gnus-offer-save-summaries ()
9298   "Offer to save all active summary buffers."
9299   (save-excursion
9300     (let ((buflist (buffer-list))
9301           buffers bufname)
9302       ;; Go through all buffers and find all summaries.
9303       (while buflist
9304         (and (setq bufname (buffer-name (car buflist)))
9305              (string-match "Summary" bufname)
9306              (save-excursion
9307                (set-buffer bufname)
9308                ;; We check that this is, indeed, a summary buffer.
9309                (and (eq major-mode 'gnus-summary-mode)
9310                     ;; Also make sure this isn't bogus.
9311                     gnus-newsgroup-prepared
9312                     ;; Also make sure that this isn't a dead summary buffer.
9313                     (not gnus-dead-summary-mode)))
9314              (push bufname buffers))
9315         (setq buflist (cdr buflist)))
9316       ;; Go through all these summary buffers and offer to save them.
9317       (when buffers
9318         (map-y-or-n-p
9319          "Update summary buffer %s? "
9320          (lambda (buf)
9321            (switch-to-buffer buf)
9322            (gnus-summary-exit))
9323          buffers)))))
9324
9325
9326 ;;; @ for mime-partial
9327 ;;;
9328
9329 (defun gnus-request-partial-message ()
9330   (save-excursion
9331     (let ((number (gnus-summary-article-number))
9332           (group gnus-newsgroup-name)
9333           (mother gnus-article-buffer))
9334       (set-buffer (get-buffer-create " *Partial Article*"))
9335       (erase-buffer)
9336       (setq mime-preview-buffer mother)
9337       (gnus-request-article-this-buffer number group)
9338       (mime-parse-buffer)
9339       )))
9340
9341 (autoload 'mime-combine-message/partial-pieces-automatically
9342   "mime-partial"
9343   "Internal method to combine message/partial messages automatically.")
9344
9345 (mime-add-condition
9346  'action '((type . message)(subtype . partial)
9347            (major-mode . gnus-original-article-mode)
9348            (method . mime-combine-message/partial-pieces-automatically)
9349            (summary-buffer-exp . gnus-summary-buffer)
9350            (request-partial-message-method . gnus-request-partial-message)
9351            ))
9352
9353
9354 ;;; @ for message/rfc822
9355 ;;;
9356
9357 (defun gnus-mime-extract-message/rfc822 (entity situation)
9358   (let (group article num cwin swin cur)
9359     (with-current-buffer (mime-entity-buffer entity)
9360       (save-restriction
9361         (narrow-to-region (mime-entity-body-start entity)
9362                           (mime-entity-body-end entity))
9363         (setq group (or (cdr (assq 'group situation))
9364                         (completing-read "Group: "
9365                                          gnus-active-hashtb
9366                                          nil
9367                                          (gnus-read-active-file-p)
9368                                          gnus-newsgroup-name))
9369               article (gnus-request-accept-article group)
9370               )
9371         ))
9372     (when (and (consp article)
9373                (numberp (setq article (cdr article))))
9374       (setq num (1+ (or (cdr (assq 'number situation)) 0))
9375             cwin (get-buffer-window (current-buffer) t)
9376             )
9377       (save-window-excursion
9378         (if (setq swin (get-buffer-window gnus-summary-buffer t))
9379             (select-window swin)
9380           (set-buffer gnus-summary-buffer)
9381           )
9382         (setq cur gnus-current-article)
9383         (forward-line num)
9384         (let (gnus-show-threads)
9385           (gnus-summary-goto-subject article t)
9386           )
9387         (gnus-summary-clear-mark-forward 1)
9388         (gnus-summary-goto-subject cur)
9389         )
9390       (when (and cwin (window-frame cwin))
9391         (select-frame (window-frame cwin))
9392         )
9393       (when (boundp 'mime-acting-situation-to-override)
9394         (set-alist 'mime-acting-situation-to-override
9395                    'group
9396                    group)
9397         (set-alist 'mime-acting-situation-to-override
9398                    'after-method
9399                    `(progn
9400                       (save-current-buffer
9401                         (set-buffer gnus-group-buffer)
9402                         (gnus-activate-group ,group)
9403                         )
9404                       (gnus-summary-goto-article ,cur
9405                                                  gnus-show-all-headers)
9406                       ))
9407         (set-alist 'mime-acting-situation-to-override
9408                    'number num)
9409         )
9410       )))
9411
9412 (mime-add-condition
9413  'action '((type . message)(subtype . rfc822)
9414            (major-mode . gnus-original-article-mode)
9415            (method . gnus-mime-extract-message/rfc822)
9416            (mode . "extract")
9417            ))
9418
9419 (mime-add-condition
9420  'action '((type . message)(subtype . news)
9421            (major-mode . gnus-original-article-mode)
9422            (method . gnus-mime-extract-message/rfc822)
9423            (mode . "extract")
9424            ))
9425
9426 (defun gnus-mime-extract-multipart (entity situation)
9427   (let ((children (mime-entity-children entity))
9428         mime-acting-situation-to-override
9429         f)
9430     (while children
9431       (mime-play-entity (car children)
9432                         (cons (assq 'mode situation)
9433                               mime-acting-situation-to-override))
9434       (setq children (cdr children)))
9435     (if (setq f (cdr (assq 'after-method
9436                            mime-acting-situation-to-override)))
9437         (eval f)
9438       )))  
9439
9440 (mime-add-condition
9441  'action '((type . multipart)
9442            (method . gnus-mime-extract-multipart)
9443            (mode . "extract")
9444            )
9445  'with-default)
9446
9447
9448 ;;; @ end
9449 ;;;
9450
9451 (defun gnus-summary-setup-default-charset ()
9452   "Setup newsgroup default charset."
9453   (if (equal gnus-newsgroup-name "nndraft:drafts")
9454       (setq gnus-newsgroup-charset nil)
9455   (let* ((name (and gnus-newsgroup-name
9456                    (gnus-group-real-name gnus-newsgroup-name)))
9457          (ignored-charsets 
9458           (or gnus-newsgroup-ephemeral-ignored-charsets
9459               (append
9460                (and gnus-newsgroup-name
9461                     (or (gnus-group-find-parameter gnus-newsgroup-name
9462                                                    'ignored-charsets t)
9463                         (let ((alist gnus-group-ignored-charsets-alist)
9464                            elem (charsets nil))
9465                           (while (setq elem (pop alist))
9466                             (when (and name
9467                                        (string-match (car elem) name))
9468                               (setq alist nil
9469                                     charsets (cdr elem))))
9470                           charsets))))
9471               gnus-newsgroup-ignored-charsets)))
9472     (setq gnus-newsgroup-charset
9473           (or gnus-newsgroup-ephemeral-charset
9474               (and gnus-newsgroup-name
9475                    (or (gnus-group-find-parameter gnus-newsgroup-name
9476                                                   'charset)
9477                        (let ((alist gnus-group-charset-alist)
9478                              elem (charset nil))
9479                          (while (setq elem (pop alist))
9480                            (when (and name
9481                                       (string-match (car elem) name))
9482                              (setq alist nil
9483                                    charset (cadr elem))))
9484                          charset)))
9485               gnus-default-charset))
9486     (set (make-local-variable 'gnus-newsgroup-ignored-charsets) 
9487          ignored-charsets))))
9488
9489 ;;;
9490 ;;; Mime Commands
9491 ;;;
9492
9493 (defun gnus-summary-display-buttonized (&optional show-all-parts)
9494   "Display the current article buffer fully MIME-buttonized.
9495 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
9496 treated as multipart/mixed."
9497   (interactive "P")
9498   (require 'gnus-art)
9499   (let ((gnus-unbuttonized-mime-types nil)
9500         (gnus-mime-display-multipart-as-mixed show-all-parts))
9501     (gnus-summary-show-article)))
9502
9503 (defun gnus-summary-repair-multipart (article)
9504   "Add a Content-Type header to a multipart article without one."
9505   (interactive (list (gnus-summary-article-number)))
9506   (gnus-with-article article
9507     (message-narrow-to-head)
9508     (goto-char (point-max))
9509     (widen)
9510     (when (search-forward "\n--" nil t)
9511       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
9512         (message-narrow-to-head)
9513         (message-remove-header "Mime-Version")
9514         (message-remove-header "Content-Type")
9515         (goto-char (point-max))
9516         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
9517                         separator))
9518         (insert "Mime-Version: 1.0\n")
9519         (widen))))
9520   (let (gnus-mark-article-hook)
9521     (gnus-summary-select-article t t nil article)))
9522
9523 (defun gnus-summary-toggle-display-buttonized ()
9524   "Toggle the buttonizing of the article buffer."
9525   (interactive)
9526   (require 'gnus-art)
9527   (if (setq gnus-inhibit-mime-unbuttonizing
9528             (not gnus-inhibit-mime-unbuttonizing))
9529       (let ((gnus-unbuttonized-mime-types nil))
9530         (gnus-summary-show-article))
9531     (gnus-summary-show-article)))
9532
9533 ;;;
9534 ;;; Intelli-mouse commmands
9535 ;;;
9536
9537 (defun gnus-wheel-summary-scroll (event)
9538   (interactive "e")
9539   (let ((amount (if (memq 'shift (event-modifiers event))
9540                     (car gnus-wheel-scroll-amount)
9541                   (cdr gnus-wheel-scroll-amount)))
9542         (direction (- (* (static-if (featurep 'xemacs)
9543                              (event-button event)
9544                            (cond ((eq 'mouse-4 (event-basic-type event))
9545                                   4)
9546                                  ((eq 'mouse-5 (event-basic-type event))
9547                                   5)))
9548                          2) 9))
9549         edge)
9550     (gnus-summary-scroll-up (* amount direction))
9551     (when (gnus-eval-in-buffer-window gnus-article-buffer
9552             (save-restriction
9553               (widen)
9554               (and (if (< 0 direction)
9555                        (gnus-article-next-page 0)
9556                      (gnus-article-prev-page 0)
9557                      (bobp))
9558                    (if (setq edge (get-text-property
9559                                    (point-min) 'gnus-wheel-edge))
9560                        (setq edge (* edge direction))
9561                      (setq edge -1))
9562                    (or (plusp edge)
9563                        (progn
9564                          (put-text-property (point-min) (point-max)
9565                                             'gnus-wheel-edge direction)
9566                          nil))
9567                    (or (> edge gnus-wheel-edge-resistance)
9568                        (progn
9569                          (put-text-property (point-min) (point-max)
9570                                             'gnus-wheel-edge
9571                                             (* (1+ edge) direction))
9572                          nil))
9573                    (eq last-command 'gnus-wheel-summary-scroll))
9574               ))
9575       (gnus-summary-next-article nil nil (minusp direction)))
9576     ))
9577
9578 (defun gnus-wheel-install ()
9579   "Enable mouse wheel support on summary window."
9580   (when gnus-use-wheel
9581     (let ((keys 
9582            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
9583       (dolist (key keys)
9584         (define-key gnus-summary-mode-map key
9585           'gnus-wheel-summary-scroll)))))
9586
9587 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
9588
9589 ;;;
9590 ;;; with article
9591 ;;;
9592
9593 (defmacro gnus-with-article (article &rest forms)
9594   "Select ARTICLE and perform FORMS in the original article buffer.
9595 Then replace the article with the result."
9596   `(progn
9597      ;; We don't want the article to be marked as read.
9598      (let (gnus-mark-article-hook)
9599        (gnus-summary-select-article t t nil ,article))
9600      (set-buffer gnus-original-article-buffer)
9601      ,@forms
9602      (if (not (gnus-check-backend-function
9603                'request-replace-article (car gnus-article-current)))
9604          (gnus-message 5 "Read-only group; not replacing")
9605        (unless (gnus-request-replace-article
9606                 ,article (car gnus-article-current)
9607                 (current-buffer) t)
9608          (error "Couldn't replace article")))
9609      ;; The cache and backlog have to be flushed somewhat.
9610      (when gnus-keep-backlog
9611        (gnus-backlog-remove-article
9612         (car gnus-article-current) (cdr gnus-article-current)))
9613      (when gnus-use-cache
9614        (gnus-cache-update-article
9615         (car gnus-article-current) (cdr gnus-article-current)))))
9616
9617 (put 'gnus-with-article 'lisp-indent-function 1)
9618 (put 'gnus-with-article 'edebug-form-spec '(form body))
9619
9620 ;;;
9621 ;;; Generic summary marking commands
9622 ;;;
9623
9624 (defvar gnus-summary-marking-alist
9625   '((read gnus-del-mark "d")
9626     (unread gnus-unread-mark "u")
9627     (ticked gnus-ticked-mark "!")
9628     (dormant gnus-dormant-mark "?")
9629     (expirable gnus-expirable-mark "e"))
9630   "An alist of names/marks/keystrokes.")
9631
9632 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
9633 (defvar gnus-summary-mark-map)
9634
9635 (defun gnus-summary-make-all-marking-commands ()
9636   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
9637   (dolist (elem gnus-summary-marking-alist)
9638     (apply 'gnus-summary-make-marking-command elem)))
9639
9640 (defun gnus-summary-make-marking-command (name mark keystroke)
9641   (let ((map (make-sparse-keymap)))
9642     (define-key gnus-summary-generic-mark-map keystroke map)
9643     (dolist (lway `((next "next" next nil "n")
9644                     (next-unread "next unread" next t "N")
9645                     (prev "previous" prev nil "p")
9646                     (prev-unread "previous unread" prev t "P")
9647                     (nomove "" nil nil ,keystroke)))
9648       (let ((func (gnus-summary-make-marking-command-1
9649                    mark (car lway) lway name)))
9650         (setq func (eval func))
9651         (define-key map (nth 4 lway) func)))))
9652       
9653 (defun gnus-summary-make-marking-command-1 (mark way lway name)      
9654   `(defun ,(intern
9655             (format "gnus-summary-put-mark-as-%s%s"
9656                     name (if (eq way 'nomove)
9657                              ""
9658                            (concat "-" (symbol-name way)))))
9659      (n)
9660      ,(format
9661        "Mark the current article as %s%s.
9662 If N, the prefix, then repeat N times.
9663 If N is negative, move in reverse order.
9664 The difference between N and the actual number of articles marked is
9665 returned."
9666        name (cadr lway))
9667      (interactive "p")
9668      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
9669     
9670 (defun gnus-summary-generic-mark (n mark move unread)
9671   "Mark N articles with MARK."
9672   (unless (eq major-mode 'gnus-summary-mode)
9673     (error "This command can only be used in the summary buffer"))
9674   (gnus-summary-show-thread)
9675   (let ((nummove
9676          (cond
9677           ((eq move 'next) 1)
9678           ((eq move 'prev) -1)
9679           (t 0))))
9680     (if (zerop nummove)
9681         (setq n 1)
9682       (when (< n 0)
9683         (setq n (abs n)
9684               nummove (* -1 nummove))))
9685     (while (and (> n 0)
9686                 (gnus-summary-mark-article nil mark)
9687                 (zerop (gnus-summary-next-subject nummove unread t)))
9688       (setq n (1- n)))
9689     (when (/= 0 n)
9690       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9691     (gnus-summary-recenter)
9692     (gnus-summary-position-point)
9693     (gnus-set-mode-line 'summary)
9694     n))
9695
9696 (gnus-summary-make-all-marking-commands)
9697
9698 (gnus-ems-redefine)
9699
9700 (provide 'gnus-sum)
9701
9702 (run-hooks 'gnus-sum-load-hook)
9703
9704 ;;; gnus-sum.el ends here