1da94812209ac6ae7272ec606e99b548a78b9463
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 (require 'nnoo)
40
41 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
42 (autoload 'gnus-cache-write-active "gnus-cache")
43 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
44 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
45 (autoload 'mm-uu-dissect "mm-uu")
46 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
47   "Deuglify broken Outlook (Express) articles and redisplay."
48   t)
49
50 (defcustom gnus-kill-summary-on-exit t
51   "*If non-nil, kill the summary buffer when you exit from it.
52 If nil, the summary will become a \"*Dead Summary*\" buffer, and
53 it will be killed sometime later."
54   :group 'gnus-summary-exit
55   :type 'boolean)
56
57 (defcustom gnus-fetch-old-headers nil
58   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
59 If an unread article in the group refers to an older, already read (or
60 just marked as read) article, the old article will not normally be
61 displayed in the Summary buffer.  If this variable is non-nil, Gnus
62 will attempt to grab the headers to the old articles, and thereby
63 build complete threads.  If it has the value `some', only enough
64 headers to connect otherwise loose threads will be displayed.  This
65 variable can also be a number.  In that case, no more than that number
66 of old headers will be fetched.  If it has the value `invisible', all
67 old headers will be fetched, but none will be displayed.
68
69 The server has to support NOV for any of this to work."
70   :group 'gnus-thread
71   :type '(choice (const :tag "off" nil)
72                  (const some)
73                  number
74                  (sexp :menu-tag "other" t)))
75
76 (defcustom gnus-refer-thread-limit 200
77   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
78 If t, fetch all the available old headers."
79   :group 'gnus-thread
80   :type '(choice number
81                  (sexp :menu-tag "other" t)))
82
83 (defcustom gnus-summary-make-false-root 'adopt
84   "*nil means that Gnus won't gather loose threads.
85 If the root of a thread has expired or been read in a previous
86 session, the information necessary to build a complete thread has been
87 lost.  Instead of having many small sub-threads from this original thread
88 scattered all over the summary buffer, Gnus can gather them.
89
90 If non-nil, Gnus will try to gather all loose sub-threads from an
91 original thread into one large thread.
92
93 If this variable is non-nil, it should be one of `none', `adopt',
94 `dummy' or `empty'.
95
96 If this variable is `none', Gnus will not make a false root, but just
97 present the sub-threads after another.
98 If this variable is `dummy', Gnus will create a dummy root that will
99 have all the sub-threads as children.
100 If this variable is `adopt', Gnus will make one of the \"children\"
101 the parent and mark all the step-children as such.
102 If this variable is `empty', the \"children\" are printed with empty
103 subject fields.  (Or rather, they will be printed with a string
104 given by the `gnus-summary-same-subject' variable.)"
105   :group 'gnus-thread
106   :type '(choice (const :tag "off" nil)
107                  (const none)
108                  (const dummy)
109                  (const adopt)
110                  (const empty)))
111
112 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
113   "*A regexp to match subjects to be excluded from loose thread gathering.
114 As loose thread gathering is done on subjects only, that means that
115 there can be many false gatherings performed.  By rooting out certain
116 common subjects, gathering might become saner."
117   :group 'gnus-thread
118   :type 'regexp)
119
120 (defcustom gnus-summary-gather-subject-limit nil
121   "*Maximum length of subject comparisons when gathering loose threads.
122 Use nil to compare full subjects.  Setting this variable to a low
123 number will help gather threads that have been corrupted by
124 newsreaders chopping off subject lines, but it might also mean that
125 unrelated articles that have subject that happen to begin with the
126 same few characters will be incorrectly gathered.
127
128 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
129 comparing subjects."
130   :group 'gnus-thread
131   :type '(choice (const :tag "off" nil)
132                  (const fuzzy)
133                  (sexp :menu-tag "on" t)))
134
135 (defcustom gnus-simplify-subject-functions nil
136   "List of functions taking a string argument that simplify subjects.
137 The functions are applied recursively.
138
139 Useful functions to put in this list include:
140 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
141 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
142   :group 'gnus-thread
143   :type '(repeat function))
144
145 (defcustom gnus-simplify-ignored-prefixes nil
146   "*Remove matches for this regexp 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, many commands will go to the next unread article.
183 This applies to marking commands as well as other commands that
184 \"naturally\" select the next article, like, for instance, `SPC' at
185 the end of an article.
186
187 If nil, the marking commands do NOT go to the next unread article
188 \(they go to the next article instead).  If `never', commands that
189 usually go to the next unread article, will go to the next article,
190 whether it is read or not."
191   :group 'gnus-summary-marks
192   :link '(custom-manual "(gnus)Setting Marks")
193   :type '(choice (const :tag "off" nil)
194                  (const never)
195                  (sexp :menu-tag "on" t)))
196
197 (defcustom gnus-summary-default-score 0
198   "*Default article score level.
199 All scores generated by the score files will be added to this score.
200 If this variable is nil, scoring will be disabled."
201   :group 'gnus-score-default
202   :type '(choice (const :tag "disable")
203                  integer))
204
205 (defcustom gnus-summary-default-high-score 0
206   "*Default threshold for a high scored article.
207 An article will be highlighted as high scored if its score is greater
208 than this score."
209   :group 'gnus-score-default
210   :type 'integer)
211
212 (defcustom gnus-summary-default-low-score 0
213   "*Default threshold for a low scored article.
214 An article will be highlighted as low scored if its score is smaller
215 than this score."
216   :group 'gnus-score-default
217   :type 'integer)
218
219 (defcustom gnus-summary-zcore-fuzz 0
220   "*Fuzziness factor for the zcore in the summary buffer.
221 Articles with scores closer than this to `gnus-summary-default-score'
222 will not be marked."
223   :group 'gnus-summary-format
224   :type 'integer)
225
226 (defcustom gnus-simplify-subject-fuzzy-regexp nil
227   "*Strings to be removed when doing fuzzy matches.
228 This can either be a regular expression or list of regular expressions
229 that will be removed from subject strings if fuzzy subject
230 simplification is selected."
231   :group 'gnus-thread
232   :type '(repeat regexp))
233
234 (defcustom gnus-show-threads t
235   "*If non-nil, display threads in summary mode."
236   :group 'gnus-thread
237   :type 'boolean)
238
239 (defcustom gnus-thread-hide-subtree nil
240   "*If non-nil, hide all threads initially.
241 This can be a predicate specifier which says which threads to hide.
242 If threads are hidden, you have to run the command
243 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
244 to expose hidden threads."
245   :group 'gnus-thread
246   :type 'boolean)
247
248 (defcustom gnus-thread-hide-killed t
249   "*If non-nil, hide killed threads automatically."
250   :group 'gnus-thread
251   :type 'boolean)
252
253 (defcustom gnus-thread-ignore-subject t
254   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
255 If nil, articles that have different subjects from their parents will
256 start separate threads."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-operation-ignore-subject t
261   "*If non-nil, subjects will be ignored when doing thread commands.
262 This affects commands like `gnus-summary-kill-thread' and
263 `gnus-summary-lower-thread'.
264
265 If this variable is nil, articles in the same thread with different
266 subjects will not be included in the operation in question.  If this
267 variable is `fuzzy', only articles that have subjects that are fuzzily
268 equal will be included."
269   :group 'gnus-thread
270   :type '(choice (const :tag "off" nil)
271                  (const fuzzy)
272                  (sexp :tag "on" t)))
273
274 (defcustom gnus-thread-indent-level 4
275   "*Number that says how much each sub-thread should be indented."
276   :group 'gnus-thread
277   :type 'integer)
278
279 (defcustom gnus-auto-extend-newsgroup t
280   "*If non-nil, extend newsgroup forward and backward when requested."
281   :group 'gnus-summary-choose
282   :type 'boolean)
283
284 (defcustom gnus-auto-select-first t
285   "*If non-nil, select the article under point.
286 Which article this is is controlled by the `gnus-auto-select-subject'
287 variable.
288
289 If you want to prevent automatic selection of articles in some
290 newsgroups, set the variable to nil in `gnus-select-group-hook'."
291   :group 'gnus-group-select
292   :type '(choice (const :tag "none" nil)
293                  (sexp :menu-tag "first" t)))
294
295 (defcustom gnus-auto-select-subject 'unread
296   "*Says what subject to place under point when entering a group.
297
298 This variable can either be the symbols `first' (place point on the
299 first subject), `unread' (place point on the subject line of the first
300 unread article), `best' (place point on the subject line of the
301 higest-scored article), `unseen' (place point on the subject line of
302 the first unseen article), 'unseen-or-unread' (place point on the subject
303 line of the first unseen article or, if all article have been seen, on the
304 subject line of the first unread article), or a function to be called to
305 place point on some subject line."
306   :group 'gnus-group-select
307   :type '(choice (const best)
308                  (const unread)
309                  (const first)
310                  (const unseen)
311                  (const unseen-or-unread)))
312
313 (defcustom gnus-auto-select-next t
314   "*If non-nil, offer to go to the next group from the end of the previous.
315 If the value is t and the next newsgroup is empty, Gnus will exit
316 summary mode and go back to group mode.  If the value is neither nil
317 nor t, Gnus will select the following unread newsgroup.  In
318 particular, if the value is the symbol `quietly', the next unread
319 newsgroup will be selected without any confirmation, and if it is
320 `almost-quietly', the next group will be selected without any
321 confirmation if you are located on the last article in the group.
322 Finally, if this variable is `slightly-quietly', the `Z n' command
323 will go to the next group without confirmation."
324   :group 'gnus-summary-maneuvering
325   :type '(choice (const :tag "off" nil)
326                  (const quietly)
327                  (const almost-quietly)
328                  (const slightly-quietly)
329                  (sexp :menu-tag "on" t)))
330
331 (defcustom gnus-auto-select-same nil
332   "*If non-nil, select the next article with the same subject.
333 If there are no more articles with the same subject, go to
334 the first unread article."
335   :group 'gnus-summary-maneuvering
336   :type 'boolean)
337
338 (defcustom gnus-summary-check-current nil
339   "*If non-nil, consider the current article when moving.
340 The \"unread\" movement commands will stay on the same line if the
341 current article is unread."
342   :group 'gnus-summary-maneuvering
343   :type 'boolean)
344
345 (defcustom gnus-auto-center-summary t
346   "*If non-nil, always center the current summary buffer.
347 In particular, if `vertical' do only vertical recentering.  If non-nil
348 and non-`vertical', do both horizontal and vertical recentering."
349   :group 'gnus-summary-maneuvering
350   :type '(choice (const :tag "none" nil)
351                  (const vertical)
352                  (integer :tag "height")
353                  (sexp :menu-tag "both" t)))
354
355 (defcustom gnus-show-all-headers nil
356   "*If non-nil, don't hide any headers."
357   :group 'gnus-article-hiding
358   :group 'gnus-article-headers
359   :type 'boolean)
360
361 (defcustom gnus-summary-ignore-duplicates nil
362   "*If non-nil, ignore articles with identical Message-ID headers."
363   :group 'gnus-summary
364   :type 'boolean)
365
366 (defcustom gnus-single-article-buffer t
367   "*If non-nil, display all articles in the same buffer.
368 If nil, each group will get its own article buffer."
369   :group 'gnus-article-various
370   :type 'boolean)
371
372 (defcustom gnus-break-pages t
373   "*If non-nil, do page breaking on articles.
374 The page delimiter is specified by the `gnus-page-delimiter'
375 variable."
376   :group 'gnus-article-various
377   :type 'boolean)
378
379 (defcustom gnus-move-split-methods nil
380   "*Variable used to suggest where articles are to be moved to.
381 It uses the same syntax as the `gnus-split-methods' variable.
382 However, whereas `gnus-split-methods' specifies file names as targets,
383 this variable specifies group names."
384   :group 'gnus-summary-mail
385   :type '(repeat (choice (list :value (fun) function)
386                          (cons :value ("" "") regexp (repeat string))
387                          (sexp :value nil))))
388
389 (defcustom gnus-unread-mark ?           ;Whitespace
390   "*Mark used for unread articles."
391   :group 'gnus-summary-marks
392   :type 'character)
393
394 (defcustom gnus-ticked-mark ?!
395   "*Mark used for ticked articles."
396   :group 'gnus-summary-marks
397   :type 'character)
398
399 (defcustom gnus-dormant-mark ??
400   "*Mark used for dormant articles."
401   :group 'gnus-summary-marks
402   :type 'character)
403
404 (defcustom gnus-del-mark ?r
405   "*Mark used for del'd articles."
406   :group 'gnus-summary-marks
407   :type 'character)
408
409 (defcustom gnus-read-mark ?R
410   "*Mark used for read articles."
411   :group 'gnus-summary-marks
412   :type 'character)
413
414 (defcustom gnus-expirable-mark ?E
415   "*Mark used for expirable articles."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-killed-mark ?K
420   "*Mark used for killed articles."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-spam-mark ?H
425   "*Mark used for spam articles."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-souped-mark ?F
430   "*Mark used for souped articles."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-kill-file-mark ?X
435   "*Mark used for articles killed by kill files."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-low-score-mark ?Y
440   "*Mark used for articles with a low score."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-catchup-mark ?C
445   "*Mark used for articles that are caught up."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-replied-mark ?A
450   "*Mark used for articles that have been replied to."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-forwarded-mark ?F
455   "*Mark used for articles that have been forwarded."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-recent-mark ?N
460   "*Mark used for articles that are recent."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-cached-mark ?*
465   "*Mark used for articles that are in the cache."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-saved-mark ?S
470   "*Mark used for articles that have been saved."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-unseen-mark ?.
475   "*Mark used for articles that haven't been seen."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-no-mark ?               ;Whitespace
480   "*Mark used for articles that have no other secondary mark."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-ancient-mark ?O
485   "*Mark used for ancient articles."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-sparse-mark ?Q
490   "*Mark used for sparsely reffed articles."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-canceled-mark ?G
495   "*Mark used for canceled articles."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-duplicate-mark ?M
500   "*Mark used for duplicate articles."
501   :group 'gnus-summary-marks
502   :type 'character)
503
504 (defcustom gnus-undownloaded-mark ?@
505   "*Mark used for articles that weren't downloaded."
506   :group 'gnus-summary-marks
507   :type 'character)
508
509 (defcustom gnus-downloadable-mark ?%
510   "*Mark used for articles that are to be downloaded."
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-unsendable-mark ?=
515   "*Mark used for articles that won't be sent."
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-score-over-mark ?+
520   "*Score mark used for articles with high scores."
521   :group 'gnus-summary-marks
522   :type 'character)
523
524 (defcustom gnus-score-below-mark ?-
525   "*Score mark used for articles with low scores."
526   :group 'gnus-summary-marks
527   :type 'character)
528
529 (defcustom gnus-empty-thread-mark ?     ;Whitespace
530   "*There is no thread under the article."
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-not-empty-thread-mark ?=
535   "*There is a thread under the article."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-view-pseudo-asynchronously nil
540   "*If non-nil, Gnus will view pseudo-articles asynchronously."
541   :group 'gnus-extract-view
542   :type 'boolean)
543
544 (defcustom gnus-auto-expirable-marks
545   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
546         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
547         gnus-souped-mark gnus-duplicate-mark)
548   "*The list of marks converted into expiration if a group is auto-expirable."
549   :version "21.1"
550   :group 'gnus-summary
551   :type '(repeat character))
552
553 (defcustom gnus-inhibit-user-auto-expire t
554   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
555   :version "21.1"
556   :group 'gnus-summary
557   :type 'boolean)
558
559 (defcustom gnus-view-pseudos nil
560   "*If `automatic', pseudo-articles will be viewed automatically.
561 If `not-confirm', pseudos will be viewed automatically, and the user
562 will not be asked to confirm the command."
563   :group 'gnus-extract-view
564   :type '(choice (const :tag "off" nil)
565                  (const automatic)
566                  (const not-confirm)))
567
568 (defcustom gnus-view-pseudos-separately t
569   "*If non-nil, one pseudo-article will be created for each file to be viewed.
570 If nil, all files that use the same viewing command will be given as a
571 list of parameters to that command."
572   :group 'gnus-extract-view
573   :type 'boolean)
574
575 (defcustom gnus-insert-pseudo-articles t
576   "*If non-nil, insert pseudo-articles when decoding articles."
577   :group 'gnus-extract-view
578   :type 'boolean)
579
580 (defcustom gnus-summary-dummy-line-format
581   "  %(:                          :%) %S\n"
582   "*The format specification for the dummy roots in the summary buffer.
583 It works along the same lines as a normal formatting string,
584 with some simple extensions.
585
586 %S  The subject
587
588 General format specifiers can also be used.
589 See `(gnus)Formatting Variables'."
590   :link '(custom-manual "(gnus)Formatting Variables")
591   :group 'gnus-threading
592   :type 'string)
593
594 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
595   "*The format specification for the summary mode line.
596 It works along the same lines as a normal formatting string,
597 with some simple extensions:
598
599 %G  Group name
600 %p  Unprefixed group name
601 %A  Current article number
602 %z  Current article score
603 %V  Gnus version
604 %U  Number of unread articles in the group
605 %e  Number of unselected articles in the group
606 %Z  A string with unread/unselected article counts
607 %g  Shortish group name
608 %S  Subject of the current article
609 %u  User-defined spec
610 %s  Current score file name
611 %d  Number of dormant articles
612 %r  Number of articles that have been marked as read in this session
613 %E  Number of articles expunged by the score files"
614   :group 'gnus-summary-format
615   :type 'string)
616
617 (defcustom gnus-list-identifiers nil
618   "Regexp that matches list identifiers to be removed from subject.
619 This can also be a list of regexps."
620   :version "21.1"
621   :group 'gnus-summary-format
622   :group 'gnus-article-hiding
623   :type '(choice (const :tag "none" nil)
624                  (regexp :value ".*")
625                  (repeat :value (".*") regexp)))
626
627 (defcustom gnus-summary-mark-below 0
628   "*Mark all articles with a score below this variable as read.
629 This variable is local to each summary buffer and usually set by the
630 score file."
631   :group 'gnus-score-default
632   :type 'integer)
633
634 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
635   "*List of functions used for sorting articles in the summary buffer.
636
637 Each function takes two articles and returns non-nil if the first
638 article should be sorted before the other.  If you use more than one
639 function, the primary sort function should be the last.  You should
640 probably always include `gnus-article-sort-by-number' in the list of
641 sorting functions -- preferably first.  Also note that sorting by date
642 is often much slower than sorting by number, and the sorting order is
643 very similar.  (Sorting by date means sorting by the time the message
644 was sent, sorting by number means sorting by arrival time.)
645
646 Ready-made functions include `gnus-article-sort-by-number',
647 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
648 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
649 and `gnus-article-sort-by-score'.
650
651 When threading is turned on, the variable `gnus-thread-sort-functions'
652 controls how articles are sorted."
653   :group 'gnus-summary-sort
654   :type '(repeat (choice (function-item gnus-article-sort-by-number)
655                          (function-item gnus-article-sort-by-author)
656                          (function-item gnus-article-sort-by-subject)
657                          (function-item gnus-article-sort-by-date)
658                          (function-item gnus-article-sort-by-score)
659                          (function-item gnus-article-sort-by-random)
660                          (function :tag "other"))))
661
662 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
663   "*List of functions used for sorting threads in the summary buffer.
664 By default, threads are sorted by article number.
665
666 Each function takes two threads and returns non-nil if the first
667 thread should be sorted before the other.  If you use more than one
668 function, the primary sort function should be the last.  You should
669 probably always include `gnus-thread-sort-by-number' in the list of
670 sorting functions -- preferably first.  Also note that sorting by date
671 is often much slower than sorting by number, and the sorting order is
672 very similar.  (Sorting by date means sorting by the time the message
673 was sent, sorting by number means sorting by arrival time.)
674
675 Ready-made functions include `gnus-thread-sort-by-number',
676 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
677 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
678 `gnus-thread-sort-by-most-recent-number',
679 `gnus-thread-sort-by-most-recent-date',
680 `gnus-thread-sort-by-random', and
681 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
682
683 When threading is turned off, the variable
684 `gnus-article-sort-functions' controls how articles are sorted."
685   :group 'gnus-summary-sort
686   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
687                          (function-item gnus-thread-sort-by-author)
688                          (function-item gnus-thread-sort-by-subject)
689                          (function-item gnus-thread-sort-by-date)
690                          (function-item gnus-thread-sort-by-score)
691                          (function-item gnus-thread-sort-by-total-score)
692                          (function-item gnus-thread-sort-by-random)
693                          (function :tag "other"))))
694
695 (defcustom gnus-thread-score-function '+
696   "*Function used for calculating the total score of a thread.
697
698 The function is called with the scores of the article and each
699 subthread and should then return the score of the thread.
700
701 Some functions you can use are `+', `max', or `min'."
702   :group 'gnus-summary-sort
703   :type 'function)
704
705 (defcustom gnus-summary-expunge-below nil
706   "All articles that have a score less than this variable will be expunged.
707 This variable is local to the summary buffers."
708   :group 'gnus-score-default
709   :type '(choice (const :tag "off" nil)
710                  integer))
711
712 (defcustom gnus-thread-expunge-below nil
713   "All threads that have a total score less than this variable will be expunged.
714 See `gnus-thread-score-function' for en explanation of what a
715 \"thread score\" is.
716
717 This variable is local to the summary buffers."
718   :group 'gnus-threading
719   :group 'gnus-score-default
720   :type '(choice (const :tag "off" nil)
721                  integer))
722
723 (defcustom gnus-summary-mode-hook nil
724   "*A hook for Gnus summary mode.
725 This hook is run before any variables are set in the summary buffer."
726   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
727   :group 'gnus-summary-various
728   :type 'hook)
729
730 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
731 (when (featurep 'xemacs)
732   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
733   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
734   (add-hook 'gnus-summary-mode-hook
735             'gnus-xmas-switch-horizontal-scrollbar-off))
736
737 (defcustom gnus-summary-menu-hook nil
738   "*Hook run after the creation of the summary mode menu."
739   :group 'gnus-summary-visual
740   :type 'hook)
741
742 (defcustom gnus-summary-exit-hook nil
743   "*A hook called on exit from the summary buffer.
744 It will be called with point in the group buffer."
745   :group 'gnus-summary-exit
746   :type 'hook)
747
748 (defcustom gnus-summary-prepare-hook nil
749   "*A hook called after the summary buffer has been generated.
750 If you want to modify the summary buffer, you can use this hook."
751   :group 'gnus-summary-various
752   :type 'hook)
753
754 (defcustom gnus-summary-prepared-hook nil
755   "*A hook called as the last thing after the summary buffer has been generated."
756   :group 'gnus-summary-various
757   :type 'hook)
758
759 (defcustom gnus-summary-generate-hook nil
760   "*A hook run just before generating the summary buffer.
761 This hook is commonly used to customize threading variables and the
762 like."
763   :group 'gnus-summary-various
764   :type 'hook)
765
766 (defcustom gnus-select-group-hook nil
767   "*A hook called when a newsgroup is selected.
768
769 If you'd like to simplify subjects like the
770 `gnus-summary-next-same-subject' command does, you can use the
771 following hook:
772
773  (add-hook gnus-select-group-hook
774            (lambda ()
775              (mapcar (lambda (header)
776                        (mail-header-set-subject
777                         header
778                         (gnus-simplify-subject
779                          (mail-header-subject header) 're-only)))
780                      gnus-newsgroup-headers)))"
781   :group 'gnus-group-select
782   :type 'hook)
783
784 (defcustom gnus-select-article-hook nil
785   "*A hook called when an article is selected."
786   :group 'gnus-summary-choose
787   :type 'hook)
788
789 (defcustom gnus-visual-mark-article-hook
790   (list 'gnus-highlight-selected-summary)
791   "*Hook run after selecting an article in the summary buffer.
792 It is meant to be used for highlighting the article in some way.  It
793 is not run if `gnus-visual' is nil."
794   :group 'gnus-summary-visual
795   :type 'hook)
796
797 (defcustom gnus-parse-headers-hook nil
798   "*A hook called before parsing the headers."
799   :group 'gnus-various
800   :type 'hook)
801
802 (defcustom gnus-exit-group-hook nil
803   "*A hook called when exiting summary mode.
804 This hook is not called from the non-updating exit commands like `Q'."
805   :group 'gnus-various
806   :type 'hook)
807
808 (defcustom gnus-summary-update-hook
809   (list 'gnus-summary-highlight-line)
810   "*A hook called when a summary line is changed.
811 The hook will not be called if `gnus-visual' is nil.
812
813 The default function `gnus-summary-highlight-line' will
814 highlight the line according to the `gnus-summary-highlight'
815 variable."
816   :group 'gnus-summary-visual
817   :type 'hook)
818
819 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
820   "*A hook called when an article is selected for the first time.
821 The hook is intended to mark an article as read (or unread)
822 automatically when it is selected."
823   :group 'gnus-summary-choose
824   :type 'hook)
825
826 (defcustom gnus-group-no-more-groups-hook nil
827   "*A hook run when returning to group mode having no more (unread) groups."
828   :group 'gnus-group-select
829   :type 'hook)
830
831 (defcustom gnus-ps-print-hook nil
832   "*A hook run before ps-printing something from Gnus."
833   :group 'gnus-summary
834   :type 'hook)
835
836 (defcustom gnus-summary-display-arrow
837   (and (fboundp 'display-graphic-p)
838        (display-graphic-p))
839   "*If non-nil, display an arrow highlighting the current article."
840   :version "21.1"
841   :group 'gnus-summary
842   :type 'boolean)
843
844 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
845   "Face used for highlighting the current article in the summary buffer."
846   :group 'gnus-summary-visual
847   :type 'face)
848
849 (defvar gnus-tmp-downloaded nil)
850
851 (defcustom gnus-summary-highlight
852   '(((eq mark gnus-canceled-mark)
853      . gnus-summary-cancelled-face)
854     ((and (> score default-high)
855           (or (eq mark gnus-dormant-mark)
856               (eq mark gnus-ticked-mark)))
857      . gnus-summary-high-ticked-face)
858     ((and (< score default-low)
859           (or (eq mark gnus-dormant-mark)
860               (eq mark gnus-ticked-mark)))
861      . gnus-summary-low-ticked-face)
862     ((or (eq mark gnus-dormant-mark)
863          (eq mark gnus-ticked-mark))
864      . gnus-summary-normal-ticked-face)
865     ((and (> score default-high) (eq mark gnus-ancient-mark))
866      . gnus-summary-high-ancient-face)
867     ((and (< score default-low) (eq mark gnus-ancient-mark))
868      . gnus-summary-low-ancient-face)
869     ((eq mark gnus-ancient-mark)
870      . gnus-summary-normal-ancient-face)
871     (gnus-tmp-downloaded
872      . gnus-agent-downloaded-article-face)
873     ((and (> score default-high) (eq mark gnus-unread-mark))
874      . gnus-summary-high-unread-face)
875     ((and (< score default-low) (eq mark gnus-unread-mark))
876      . gnus-summary-low-unread-face)
877     ((eq mark gnus-unread-mark)
878      . gnus-summary-normal-unread-face)
879     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
880                                                   gnus-undownloaded-mark)))
881      . gnus-summary-high-unread-face)
882     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
883                                                  gnus-undownloaded-mark)))
884      . gnus-summary-low-unread-face)
885     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
886           (memq article gnus-newsgroup-unreads))
887      . gnus-summary-normal-unread-face)
888     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
889      . gnus-summary-normal-read-face)
890     ((> score default-high)
891      . gnus-summary-high-read-face)
892     ((< score default-low)
893      . gnus-summary-low-read-face)
894     (t
895      . gnus-summary-normal-read-face))
896   "*Controls the highlighting of summary buffer lines.
897
898 A list of (FORM . FACE) pairs.  When deciding how a a particular
899 summary line should be displayed, each form is evaluated.  The content
900 of the face field after the first true form is used.  You can change
901 how those summary lines are displayed, by editing the face field.
902
903 You can use the following variables in the FORM field.
904
905 score:        The article's score
906 default:      The default article score.
907 default-high: The default score for high scored articles.
908 default-low:  The default score for low scored articles.
909 below:        The score below which articles are automatically marked as read.
910 mark:         The articles mark."
911   :group 'gnus-summary-visual
912   :type '(repeat (cons (sexp :tag "Form" nil)
913                        face)))
914
915 (defcustom gnus-alter-header-function nil
916   "Function called to allow alteration of article header structures.
917 The function is called with one parameter, the article header vector,
918 which it may alter in any way.")
919
920 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
921   "Variable that says which function should be used to decode a string with encoded words.")
922
923 (defcustom gnus-extra-headers '(To Newsgroups)
924   "*Extra headers to parse."
925   :version "21.1"
926   :group 'gnus-summary
927   :type '(repeat symbol))
928
929 (defcustom gnus-ignored-from-addresses
930   (and user-mail-address (regexp-quote user-mail-address))
931   "*Regexp of From headers that may be suppressed in favor of To headers."
932   :version "21.1"
933   :group 'gnus-summary
934   :type 'regexp)
935
936 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
937   "List of charsets that should be ignored.
938 When these charsets are used in the \"charset\" parameter, the
939 default charset will be used instead."
940   :version "21.1"
941   :type '(repeat symbol)
942   :group 'gnus-charset)
943
944 (gnus-define-group-parameter
945  ignored-charsets
946  :type list
947  :function-document
948  "Return the ignored charsets of GROUP."
949  :variable gnus-group-ignored-charsets-alist
950  :variable-default
951  '(("alt\\.chinese\\.text" iso-8859-1))
952  :variable-document
953  "Alist of regexps (to match group names) and charsets that should be ignored.
954 When these charsets are used in the \"charset\" parameter, the
955 default charset will be used instead."
956  :variable-group gnus-charset
957  :variable-type '(repeat (cons (regexp :tag "Group")
958                                (repeat symbol)))
959  :parameter-type '(choice :tag "Ignored charsets"
960                           :value nil
961                           (repeat (symbol)))
962  :parameter-document       "\
963 List of charsets that should be ignored.
964
965 When these charsets are used in the \"charset\" parameter, the
966 default charset will be used instead.")
967
968 (defcustom gnus-group-highlight-words-alist nil
969   "Alist of group regexps and highlight regexps.
970 This variable uses the same syntax as `gnus-emphasis-alist'."
971   :version "21.1"
972   :type '(repeat (cons (regexp :tag "Group")
973                        (repeat (list (regexp :tag "Highlight regexp")
974                                      (number :tag "Group for entire word" 0)
975                                      (number :tag "Group for displayed part" 0)
976                                      (symbol :tag "Face"
977                                              gnus-emphasis-highlight-words)))))
978   :group 'gnus-summary-visual)
979
980 (defcustom gnus-summary-show-article-charset-alist
981   nil
982   "Alist of number and charset.
983 The article will be shown with the charset corresponding to the
984 numbered argument.
985 For example: ((1 . cn-gb-2312) (2 . big5))."
986   :version "21.1"
987   :type '(repeat (cons (number :tag "Argument" 1)
988                        (symbol :tag "Charset")))
989   :group 'gnus-charset)
990
991 (defcustom gnus-preserve-marks t
992   "Whether marks are preserved when moving, copying and respooling messages."
993   :version "21.1"
994   :type 'boolean
995   :group 'gnus-summary-marks)
996
997 (defcustom gnus-alter-articles-to-read-function nil
998   "Function to be called to alter the list of articles to be selected."
999   :type '(choice (const nil) function)
1000   :group 'gnus-summary)
1001
1002 (defcustom gnus-orphan-score nil
1003   "*All orphans get this score added.  Set in the score file."
1004   :group 'gnus-score-default
1005   :type '(choice (const nil)
1006                  integer))
1007
1008 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1009   "*A regexp to match MIME parts when saving multiple parts of a message
1010 with gnus-summary-save-parts (X m). This regexp will be used by default
1011 when prompting the user for which type of files to save."
1012   :group 'gnus-summary
1013   :type 'regexp)
1014
1015 (defcustom gnus-read-all-available-headers nil
1016   "Whether Gnus should parse all headers made available to it.
1017 This is mostly relevant for slow backends where the user may
1018 wish to widen the summary buffer to include all headers
1019 that were fetched.  Say, for nnultimate groups."
1020   :group 'gnus-summary
1021   :type '(choice boolean regexp))
1022
1023 (defcustom gnus-summary-muttprint-program "muttprint"
1024   "Command (and optional arguments) used to run Muttprint."
1025   :version "21.3"
1026   :group 'gnus-summary
1027   :type 'string)
1028
1029 (defcustom gnus-article-loose-mime nil
1030   "If non-nil, don't require MIME-Version header.
1031 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1032 supply the MIME-Version header or deliberately strip it From the mail.
1033 Set it to non-nil, Gnus will treat some articles as MIME even if
1034 the MIME-Version header is missed."
1035   :version "21.3"
1036   :type 'boolean
1037   :group 'gnus-article)
1038
1039 ;;; Internal variables
1040
1041 (defvar gnus-summary-display-cache nil)
1042 (defvar gnus-article-mime-handles nil)
1043 (defvar gnus-article-decoded-p nil)
1044 (defvar gnus-article-charset nil)
1045 (defvar gnus-article-ignored-charsets nil)
1046 (defvar gnus-scores-exclude-files nil)
1047 (defvar gnus-page-broken nil)
1048
1049 (defvar gnus-original-article nil)
1050 (defvar gnus-article-internal-prepare-hook nil)
1051 (defvar gnus-newsgroup-process-stack nil)
1052
1053 (defvar gnus-thread-indent-array nil)
1054 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1055 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1056   "Function called to sort the articles within a thread after it has been gathered together.")
1057
1058 (defvar gnus-summary-save-parts-type-history nil)
1059 (defvar gnus-summary-save-parts-last-directory nil)
1060
1061 ;; Avoid highlighting in kill files.
1062 (defvar gnus-summary-inhibit-highlight nil)
1063 (defvar gnus-newsgroup-selected-overlay nil)
1064 (defvar gnus-inhibit-limiting nil)
1065 (defvar gnus-newsgroup-adaptive-score-file nil)
1066 (defvar gnus-current-score-file nil)
1067 (defvar gnus-current-move-group nil)
1068 (defvar gnus-current-copy-group nil)
1069 (defvar gnus-current-crosspost-group nil)
1070 (defvar gnus-newsgroup-display nil)
1071
1072 (defvar gnus-newsgroup-dependencies nil)
1073 (defvar gnus-newsgroup-adaptive nil)
1074 (defvar gnus-summary-display-article-function nil)
1075 (defvar gnus-summary-highlight-line-function nil
1076   "Function called after highlighting a summary line.")
1077
1078 (defvar gnus-summary-line-format-alist
1079   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1080     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1081     (?s gnus-tmp-subject-or-nil ?s)
1082     (?n gnus-tmp-name ?s)
1083     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1084         ?s)
1085     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1086             gnus-tmp-from) ?s)
1087     (?F gnus-tmp-from ?s)
1088     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1089     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1090     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1091     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1092     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1093     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1094     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1095     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1096     (?L gnus-tmp-lines ?s)
1097     (?I gnus-tmp-indentation ?s)
1098     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1099     (?R gnus-tmp-replied ?c)
1100     (?\[ gnus-tmp-opening-bracket ?c)
1101     (?\] gnus-tmp-closing-bracket ?c)
1102     (?\> (make-string gnus-tmp-level ? ) ?s)
1103     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1104     (?i gnus-tmp-score ?d)
1105     (?z gnus-tmp-score-char ?c)
1106     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1107     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1108     (?U gnus-tmp-unread ?c)
1109     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1110         ?s)
1111     (?t (gnus-summary-number-of-articles-in-thread
1112          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1113         ?d)
1114     (?e (gnus-summary-number-of-articles-in-thread
1115          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1116         ?c)
1117     (?u gnus-tmp-user-defined ?s)
1118     (?P (gnus-pick-line-number) ?d)
1119     (?B gnus-tmp-thread-tree-header-string ?s)
1120     (user-date (gnus-user-date
1121                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1122   "An alist of format specifications that can appear in summary lines.
1123 These are paired with what variables they correspond with, along with
1124 the type of the variable (string, integer, character, etc).")
1125
1126 (defvar gnus-summary-dummy-line-format-alist
1127   `((?S gnus-tmp-subject ?s)
1128     (?N gnus-tmp-number ?d)
1129     (?u gnus-tmp-user-defined ?s)))
1130
1131 (defvar gnus-summary-mode-line-format-alist
1132   `((?G gnus-tmp-group-name ?s)
1133     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1134     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1135     (?A gnus-tmp-article-number ?d)
1136     (?Z gnus-tmp-unread-and-unselected ?s)
1137     (?V gnus-version ?s)
1138     (?U gnus-tmp-unread-and-unticked ?d)
1139     (?S gnus-tmp-subject ?s)
1140     (?e gnus-tmp-unselected ?d)
1141     (?u gnus-tmp-user-defined ?s)
1142     (?d (length gnus-newsgroup-dormant) ?d)
1143     (?t (length gnus-newsgroup-marked) ?d)
1144     (?h (length gnus-newsgroup-spam-marked) ?d)
1145     (?r (length gnus-newsgroup-reads) ?d)
1146     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1147     (?E gnus-newsgroup-expunged-tally ?d)
1148     (?s (gnus-current-score-file-nondirectory) ?s)))
1149
1150 (defvar gnus-last-search-regexp nil
1151   "Default regexp for article search command.")
1152
1153 (defvar gnus-last-shell-command nil
1154   "Default shell command on article.")
1155
1156 (defvar gnus-newsgroup-begin nil)
1157 (defvar gnus-newsgroup-end nil)
1158 (defvar gnus-newsgroup-last-rmail nil)
1159 (defvar gnus-newsgroup-last-mail nil)
1160 (defvar gnus-newsgroup-last-folder nil)
1161 (defvar gnus-newsgroup-last-file nil)
1162 (defvar gnus-newsgroup-auto-expire nil)
1163 (defvar gnus-newsgroup-active nil)
1164
1165 (defvar gnus-newsgroup-data nil)
1166 (defvar gnus-newsgroup-data-reverse nil)
1167 (defvar gnus-newsgroup-limit nil)
1168 (defvar gnus-newsgroup-limits nil)
1169
1170 (defvar gnus-newsgroup-unreads nil
1171   "Sorted list of unread articles in the current newsgroup.")
1172
1173 (defvar gnus-newsgroup-unselected nil
1174   "Sorted list of unselected unread articles in the current newsgroup.")
1175
1176 (defvar gnus-newsgroup-reads nil
1177   "Alist of read articles and article marks in the current newsgroup.")
1178
1179 (defvar gnus-newsgroup-expunged-tally nil)
1180
1181 (defvar gnus-newsgroup-marked nil
1182   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1183
1184 (defvar gnus-newsgroup-spam-marked nil
1185   "List of ranges of articles that have been marked as spam.")
1186
1187 (defvar gnus-newsgroup-killed nil
1188   "List of ranges of articles that have been through the scoring process.")
1189
1190 (defvar gnus-newsgroup-cached nil
1191   "Sorted list of articles that come from the article cache.")
1192
1193 (defvar gnus-newsgroup-saved nil
1194   "List of articles that have been saved.")
1195
1196 (defvar gnus-newsgroup-kill-headers nil)
1197
1198 (defvar gnus-newsgroup-replied nil
1199   "List of articles that have been replied to in the current newsgroup.")
1200
1201 (defvar gnus-newsgroup-forwarded nil
1202   "List of articles that have been forwarded in the current newsgroup.")
1203
1204 (defvar gnus-newsgroup-recent nil
1205   "List of articles that have are recent in the current newsgroup.")
1206
1207 (defvar gnus-newsgroup-expirable nil
1208   "Sorted list of articles in the current newsgroup that can be expired.")
1209
1210 (defvar gnus-newsgroup-processable nil
1211   "List of articles in the current newsgroup that can be processed.")
1212
1213 (defvar gnus-newsgroup-downloadable nil
1214   "Sorted list of articles in the current newsgroup that can be processed.")
1215
1216 (defvar gnus-newsgroup-undownloaded nil
1217   "List of articles in the current newsgroup that haven't been downloaded..")
1218
1219 (defvar gnus-newsgroup-unsendable nil
1220   "List of articles in the current newsgroup that won't be sent.")
1221
1222 (defvar gnus-newsgroup-bookmarks nil
1223   "List of articles in the current newsgroup that have bookmarks.")
1224
1225 (defvar gnus-newsgroup-dormant nil
1226   "Sorted list of dormant articles in the current newsgroup.")
1227
1228 (defvar gnus-newsgroup-unseen nil
1229   "List of unseen articles in the current newsgroup.")
1230
1231 (defvar gnus-newsgroup-seen nil
1232   "Range of seen articles in the current newsgroup.")
1233
1234 (defvar gnus-newsgroup-articles nil
1235   "List of articles in the current newsgroup.")
1236
1237 (defvar gnus-newsgroup-scored nil
1238   "List of scored articles in the current newsgroup.")
1239
1240 (defvar gnus-newsgroup-headers nil
1241   "List of article headers in the current newsgroup.")
1242
1243 (defvar gnus-newsgroup-threads nil)
1244
1245 (defvar gnus-newsgroup-prepared nil
1246   "Whether the current group has been prepared properly.")
1247
1248 (defvar gnus-newsgroup-ancient nil
1249   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1250
1251 (defvar gnus-newsgroup-sparse nil)
1252
1253 (defvar gnus-current-article nil)
1254 (defvar gnus-article-current nil)
1255 (defvar gnus-current-headers nil)
1256 (defvar gnus-have-all-headers nil)
1257 (defvar gnus-last-article nil)
1258 (defvar gnus-newsgroup-history nil)
1259 (defvar gnus-newsgroup-charset nil)
1260 (defvar gnus-newsgroup-ephemeral-charset nil)
1261 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1262
1263 (defvar gnus-article-before-search nil)
1264
1265 (defconst gnus-summary-local-variables
1266   '(gnus-newsgroup-name
1267     gnus-newsgroup-begin gnus-newsgroup-end
1268     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1269     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1270     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1271     gnus-newsgroup-unselected gnus-newsgroup-marked
1272     gnus-newsgroup-spam-marked
1273     gnus-newsgroup-reads gnus-newsgroup-saved
1274     gnus-newsgroup-replied gnus-newsgroup-forwarded
1275     gnus-newsgroup-recent
1276     gnus-newsgroup-expirable
1277     gnus-newsgroup-processable gnus-newsgroup-killed
1278     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1279     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1280     gnus-newsgroup-seen gnus-newsgroup-articles
1281     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1282     gnus-newsgroup-headers gnus-newsgroup-threads
1283     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1284     gnus-current-article gnus-current-headers gnus-have-all-headers
1285     gnus-last-article gnus-article-internal-prepare-hook
1286     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1287     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1288     gnus-thread-expunge-below
1289     gnus-score-alist gnus-current-score-file
1290     (gnus-summary-expunge-below . global)
1291     (gnus-summary-mark-below . global)
1292     (gnus-orphan-score . global)
1293     gnus-newsgroup-active gnus-scores-exclude-files
1294     gnus-newsgroup-history gnus-newsgroup-ancient
1295     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1296     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1297     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1298     (gnus-newsgroup-expunged-tally . 0)
1299     gnus-cache-removable-articles gnus-newsgroup-cached
1300     gnus-newsgroup-data gnus-newsgroup-data-reverse
1301     gnus-newsgroup-limit gnus-newsgroup-limits
1302     gnus-newsgroup-charset gnus-newsgroup-display)
1303   "Variables that are buffer-local to the summary buffers.")
1304
1305 (defvar gnus-newsgroup-variables nil
1306   "A list of variables that have separate values in different newsgroups.
1307 A list of newsgroup (summary buffer) local variables, or cons of
1308 variables and their default values (when the default values are not
1309 nil), that should be made global while the summary buffer is active.
1310 These variables can be used to set variables in the group parameters
1311 while still allowing them to affect operations done in other
1312 buffers. For example:
1313
1314 \(setq gnus-newsgroup-variables
1315      '(message-use-followup-to
1316        (gnus-visible-headers .
1317          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1318 ")
1319
1320 ;; Byte-compiler warning.
1321 (eval-when-compile (defvar gnus-article-mode-map))
1322
1323 ;; MIME stuff.
1324
1325 (defvar gnus-decode-encoded-word-methods
1326   '(mail-decode-encoded-word-string)
1327   "List of methods used to decode encoded words.
1328
1329 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1330 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1331 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1332 whose names match REGEXP.
1333
1334 For example:
1335 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1336  mail-decode-encoded-word-string
1337  (\"chinese\" . rfc1843-decode-string))")
1338
1339 (defvar gnus-decode-encoded-word-methods-cache nil)
1340
1341 (defun gnus-multi-decode-encoded-word-string (string)
1342   "Apply the functions from `gnus-encoded-word-methods' that match."
1343   (unless (and gnus-decode-encoded-word-methods-cache
1344                (eq gnus-newsgroup-name
1345                    (car gnus-decode-encoded-word-methods-cache)))
1346     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1347     (mapcar (lambda (x)
1348               (if (symbolp x)
1349                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1350                 (if (and gnus-newsgroup-name
1351                          (string-match (car x) gnus-newsgroup-name))
1352                     (nconc gnus-decode-encoded-word-methods-cache
1353                            (list (cdr x))))))
1354             gnus-decode-encoded-word-methods))
1355   (let ((xlist gnus-decode-encoded-word-methods-cache))
1356     (pop xlist)
1357     (while xlist
1358       (setq string (funcall (pop xlist) string))))
1359   string)
1360
1361 ;; Subject simplification.
1362
1363 (defun gnus-simplify-whitespace (str)
1364   "Remove excessive whitespace from STR."
1365   (let ((mystr str))
1366     ;; Multiple spaces.
1367     (while (string-match "[ \t][ \t]+" mystr)
1368       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1369                           " "
1370                           (substring mystr (match-end 0)))))
1371     ;; Leading spaces.
1372     (when (string-match "^[ \t]+" mystr)
1373       (setq mystr (substring mystr (match-end 0))))
1374     ;; Trailing spaces.
1375     (when (string-match "[ \t]+$" mystr)
1376       (setq mystr (substring mystr 0 (match-beginning 0))))
1377     mystr))
1378
1379 (defun gnus-simplify-all-whitespace (str)
1380   "Remove all whitespace from STR."
1381   (let ((mystr str))
1382     (while (string-match "[ \t\n]+" mystr)
1383       (setq mystr (replace-match "" nil nil mystr)))
1384     mystr))
1385
1386 (defsubst gnus-simplify-subject-re (subject)
1387   "Remove \"Re:\" from subject lines."
1388   (if (string-match message-subject-re-regexp subject)
1389       (substring subject (match-end 0))
1390     subject))
1391
1392 (defun gnus-simplify-subject (subject &optional re-only)
1393   "Remove `Re:' and words in parentheses.
1394 If RE-ONLY is non-nil, strip leading `Re:'s only."
1395   (let ((case-fold-search t))           ;Ignore case.
1396     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1397     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1398       (setq subject (substring subject (match-end 0))))
1399     ;; Remove uninteresting prefixes.
1400     (when (and (not re-only)
1401                gnus-simplify-ignored-prefixes
1402                (string-match gnus-simplify-ignored-prefixes subject))
1403       (setq subject (substring subject (match-end 0))))
1404     ;; Remove words in parentheses from end.
1405     (unless re-only
1406       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1407         (setq subject (substring subject 0 (match-beginning 0)))))
1408     ;; Return subject string.
1409     subject))
1410
1411 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1412 ;; all whitespace.
1413 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1414   (goto-char (point-min))
1415   (while (re-search-forward regexp nil t)
1416     (replace-match (or newtext ""))))
1417
1418 (defun gnus-simplify-buffer-fuzzy ()
1419   "Simplify string in the buffer fuzzily.
1420 The string in the accessible portion of the current buffer is simplified.
1421 It is assumed to be a single-line subject.
1422 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1423 matter is removed.  Additional things can be deleted by setting
1424 `gnus-simplify-subject-fuzzy-regexp'."
1425   (let ((case-fold-search t)
1426         (modified-tick))
1427     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1428
1429     (while (not (eq modified-tick (buffer-modified-tick)))
1430       (setq modified-tick (buffer-modified-tick))
1431       (cond
1432        ((listp gnus-simplify-subject-fuzzy-regexp)
1433         (mapcar 'gnus-simplify-buffer-fuzzy-step
1434                 gnus-simplify-subject-fuzzy-regexp))
1435        (gnus-simplify-subject-fuzzy-regexp
1436         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1437       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1438       (gnus-simplify-buffer-fuzzy-step
1439        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1440       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1441
1442     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1443     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1444     (gnus-simplify-buffer-fuzzy-step " $")
1445     (gnus-simplify-buffer-fuzzy-step "^ +")))
1446
1447 (defun gnus-simplify-subject-fuzzy (subject)
1448   "Simplify a subject string fuzzily.
1449 See `gnus-simplify-buffer-fuzzy' for details."
1450   (save-excursion
1451     (gnus-set-work-buffer)
1452     (let ((case-fold-search t))
1453       ;; Remove uninteresting prefixes.
1454       (when (and gnus-simplify-ignored-prefixes
1455                  (string-match gnus-simplify-ignored-prefixes subject))
1456         (setq subject (substring subject (match-end 0))))
1457       (insert subject)
1458       (inline (gnus-simplify-buffer-fuzzy))
1459       (buffer-string))))
1460
1461 (defsubst gnus-simplify-subject-fully (subject)
1462   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1463   (cond
1464    (gnus-simplify-subject-functions
1465     (gnus-map-function gnus-simplify-subject-functions subject))
1466    ((null gnus-summary-gather-subject-limit)
1467     (gnus-simplify-subject-re subject))
1468    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1469     (gnus-simplify-subject-fuzzy subject))
1470    ((numberp gnus-summary-gather-subject-limit)
1471     (gnus-limit-string (gnus-simplify-subject-re subject)
1472                        gnus-summary-gather-subject-limit))
1473    (t
1474     subject)))
1475
1476 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1477   "Check whether two subjects are equal.
1478 If optional argument simple-first is t, first argument is already
1479 simplified."
1480   (cond
1481    ((null simple-first)
1482     (equal (gnus-simplify-subject-fully s1)
1483            (gnus-simplify-subject-fully s2)))
1484    (t
1485     (equal s1
1486            (gnus-simplify-subject-fully s2)))))
1487
1488 (defun gnus-summary-bubble-group ()
1489   "Increase the score of the current group.
1490 This is a handy function to add to `gnus-summary-exit-hook' to
1491 increase the score of each group you read."
1492   (gnus-group-add-score gnus-newsgroup-name))
1493
1494 \f
1495 ;;;
1496 ;;; Gnus summary mode
1497 ;;;
1498
1499 (put 'gnus-summary-mode 'mode-class 'special)
1500
1501 (defvar gnus-article-commands-menu)
1502
1503 (when t
1504   ;; Non-orthogonal keys
1505
1506   (gnus-define-keys gnus-summary-mode-map
1507     " " gnus-summary-next-page
1508     "\177" gnus-summary-prev-page
1509     [delete] gnus-summary-prev-page
1510     [backspace] gnus-summary-prev-page
1511     "\r" gnus-summary-scroll-up
1512     "\M-\r" gnus-summary-scroll-down
1513     "n" gnus-summary-next-unread-article
1514     "p" gnus-summary-prev-unread-article
1515     "N" gnus-summary-next-article
1516     "P" gnus-summary-prev-article
1517     "\M-\C-n" gnus-summary-next-same-subject
1518     "\M-\C-p" gnus-summary-prev-same-subject
1519     "\M-n" gnus-summary-next-unread-subject
1520     "\M-p" gnus-summary-prev-unread-subject
1521     "." gnus-summary-first-unread-article
1522     "," gnus-summary-best-unread-article
1523     "\M-s" gnus-summary-search-article-forward
1524     "\M-r" gnus-summary-search-article-backward
1525     "<" gnus-summary-beginning-of-article
1526     ">" gnus-summary-end-of-article
1527     "j" gnus-summary-goto-article
1528     "^" gnus-summary-refer-parent-article
1529     "\M-^" gnus-summary-refer-article
1530     "u" gnus-summary-tick-article-forward
1531     "!" gnus-summary-tick-article-forward
1532     "U" gnus-summary-tick-article-backward
1533     "d" gnus-summary-mark-as-read-forward
1534     "D" gnus-summary-mark-as-read-backward
1535     "E" gnus-summary-mark-as-expirable
1536     "\M-u" gnus-summary-clear-mark-forward
1537     "\M-U" gnus-summary-clear-mark-backward
1538     "k" gnus-summary-kill-same-subject-and-select
1539     "\C-k" gnus-summary-kill-same-subject
1540     "\M-\C-k" gnus-summary-kill-thread
1541     "\M-\C-l" gnus-summary-lower-thread
1542     "e" gnus-summary-edit-article
1543     "#" gnus-summary-mark-as-processable
1544     "\M-#" gnus-summary-unmark-as-processable
1545     "\M-\C-t" gnus-summary-toggle-threads
1546     "\M-\C-s" gnus-summary-show-thread
1547     "\M-\C-h" gnus-summary-hide-thread
1548     "\M-\C-f" gnus-summary-next-thread
1549     "\M-\C-b" gnus-summary-prev-thread
1550     [(meta down)] gnus-summary-next-thread
1551     [(meta up)] gnus-summary-prev-thread
1552     "\M-\C-u" gnus-summary-up-thread
1553     "\M-\C-d" gnus-summary-down-thread
1554     "&" gnus-summary-execute-command
1555     "c" gnus-summary-catchup-and-exit
1556     "\C-w" gnus-summary-mark-region-as-read
1557     "\C-t" gnus-summary-toggle-truncation
1558     "?" gnus-summary-mark-as-dormant
1559     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1560     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1561     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1562     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1563     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1564     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1565     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1566     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1567     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1568     "\C-c\C-s\C-r" gnus-summary-sort-by-random
1569     "=" gnus-summary-expand-window
1570     "\C-x\C-s" gnus-summary-reselect-current-group
1571     "\M-g" gnus-summary-rescan-group
1572     "w" gnus-summary-stop-page-breaking
1573     "\C-c\C-r" gnus-summary-caesar-message
1574     "f" gnus-summary-followup
1575     "F" gnus-summary-followup-with-original
1576     "C" gnus-summary-cancel-article
1577     "r" gnus-summary-reply
1578     "R" gnus-summary-reply-with-original
1579     "\C-c\C-f" gnus-summary-mail-forward
1580     "o" gnus-summary-save-article
1581     "\C-o" gnus-summary-save-article-mail
1582     "|" gnus-summary-pipe-output
1583     "\M-k" gnus-summary-edit-local-kill
1584     "\M-K" gnus-summary-edit-global-kill
1585     ;; "V" gnus-version
1586     "\C-c\C-d" gnus-summary-describe-group
1587     "q" gnus-summary-exit
1588     "Q" gnus-summary-exit-no-update
1589     "\C-c\C-i" gnus-info-find-node
1590     gnus-mouse-2 gnus-mouse-pick-article
1591     "m" gnus-summary-mail-other-window
1592     "a" gnus-summary-post-news
1593     "i" gnus-summary-news-other-window
1594     "x" gnus-summary-limit-to-unread
1595     "s" gnus-summary-isearch-article
1596     "t" gnus-summary-toggle-header
1597     "g" gnus-summary-show-article
1598     "l" gnus-summary-goto-last-article
1599     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1600     "\C-d" gnus-summary-enter-digest-group
1601     "\M-\C-d" gnus-summary-read-document
1602     "\M-\C-e" gnus-summary-edit-parameters
1603     "\M-\C-a" gnus-summary-customize-parameters
1604     "\C-c\C-b" gnus-bug
1605     "*" gnus-cache-enter-article
1606     "\M-*" gnus-cache-remove-article
1607     "\M-&" gnus-summary-universal-argument
1608     "\C-l" gnus-recenter
1609     "I" gnus-summary-increase-score
1610     "L" gnus-summary-lower-score
1611     "\M-i" gnus-symbolic-argument
1612     "h" gnus-summary-select-article-buffer
1613
1614     "b" gnus-article-view-part
1615     "\M-t" gnus-summary-toggle-display-buttonized
1616
1617     "V" gnus-summary-score-map
1618     "X" gnus-uu-extract-map
1619     "S" gnus-summary-send-map)
1620
1621   ;; Sort of orthogonal keymap
1622   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1623     "t" gnus-summary-tick-article-forward
1624     "!" gnus-summary-tick-article-forward
1625     "d" gnus-summary-mark-as-read-forward
1626     "r" gnus-summary-mark-as-read-forward
1627     "c" gnus-summary-clear-mark-forward
1628     " " gnus-summary-clear-mark-forward
1629     "e" gnus-summary-mark-as-expirable
1630     "x" gnus-summary-mark-as-expirable
1631     "?" gnus-summary-mark-as-dormant
1632     "b" gnus-summary-set-bookmark
1633     "B" gnus-summary-remove-bookmark
1634     "#" gnus-summary-mark-as-processable
1635     "\M-#" gnus-summary-unmark-as-processable
1636     "S" gnus-summary-limit-include-expunged
1637     "C" gnus-summary-catchup
1638     "H" gnus-summary-catchup-to-here
1639     "h" gnus-summary-catchup-from-here
1640     "\C-c" gnus-summary-catchup-all
1641     "k" gnus-summary-kill-same-subject-and-select
1642     "K" gnus-summary-kill-same-subject
1643     "P" gnus-uu-mark-map)
1644
1645   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1646     "c" gnus-summary-clear-above
1647     "u" gnus-summary-tick-above
1648     "m" gnus-summary-mark-above
1649     "k" gnus-summary-kill-below)
1650
1651   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1652     "/" gnus-summary-limit-to-subject
1653     "n" gnus-summary-limit-to-articles
1654     "w" gnus-summary-pop-limit
1655     "s" gnus-summary-limit-to-subject
1656     "a" gnus-summary-limit-to-author
1657     "u" gnus-summary-limit-to-unread
1658     "m" gnus-summary-limit-to-marks
1659     "M" gnus-summary-limit-exclude-marks
1660     "v" gnus-summary-limit-to-score
1661     "*" gnus-summary-limit-include-cached
1662     "D" gnus-summary-limit-include-dormant
1663     "T" gnus-summary-limit-include-thread
1664     "d" gnus-summary-limit-exclude-dormant
1665     "t" gnus-summary-limit-to-age
1666     "." gnus-summary-limit-to-unseen
1667     "x" gnus-summary-limit-to-extra
1668     "p" gnus-summary-limit-to-display-predicate
1669     "E" gnus-summary-limit-include-expunged
1670     "c" gnus-summary-limit-exclude-childless-dormant
1671     "C" gnus-summary-limit-mark-excluded-as-read
1672     "o" gnus-summary-insert-old-articles
1673     "N" gnus-summary-insert-new-articles)
1674
1675   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1676     "n" gnus-summary-next-unread-article
1677     "p" gnus-summary-prev-unread-article
1678     "N" gnus-summary-next-article
1679     "P" gnus-summary-prev-article
1680     "\C-n" gnus-summary-next-same-subject
1681     "\C-p" gnus-summary-prev-same-subject
1682     "\M-n" gnus-summary-next-unread-subject
1683     "\M-p" gnus-summary-prev-unread-subject
1684     "f" gnus-summary-first-unread-article
1685     "b" gnus-summary-best-unread-article
1686     "j" gnus-summary-goto-article
1687     "g" gnus-summary-goto-subject
1688     "l" gnus-summary-goto-last-article
1689     "o" gnus-summary-pop-article)
1690
1691   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1692     "k" gnus-summary-kill-thread
1693     "l" gnus-summary-lower-thread
1694     "i" gnus-summary-raise-thread
1695     "T" gnus-summary-toggle-threads
1696     "t" gnus-summary-rethread-current
1697     "^" gnus-summary-reparent-thread
1698     "s" gnus-summary-show-thread
1699     "S" gnus-summary-show-all-threads
1700     "h" gnus-summary-hide-thread
1701     "H" gnus-summary-hide-all-threads
1702     "n" gnus-summary-next-thread
1703     "p" gnus-summary-prev-thread
1704     "u" gnus-summary-up-thread
1705     "o" gnus-summary-top-thread
1706     "d" gnus-summary-down-thread
1707     "#" gnus-uu-mark-thread
1708     "\M-#" gnus-uu-unmark-thread)
1709
1710   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1711     "g" gnus-summary-prepare
1712     "c" gnus-summary-insert-cached-articles)
1713
1714   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1715     "c" gnus-summary-catchup-and-exit
1716     "C" gnus-summary-catchup-all-and-exit
1717     "E" gnus-summary-exit-no-update
1718     "Q" gnus-summary-exit
1719     "Z" gnus-summary-exit
1720     "n" gnus-summary-catchup-and-goto-next-group
1721     "R" gnus-summary-reselect-current-group
1722     "G" gnus-summary-rescan-group
1723     "N" gnus-summary-next-group
1724     "s" gnus-summary-save-newsrc
1725     "P" gnus-summary-prev-group)
1726
1727   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1728     " " gnus-summary-next-page
1729     "n" gnus-summary-next-page
1730     "\177" gnus-summary-prev-page
1731     [delete] gnus-summary-prev-page
1732     "p" gnus-summary-prev-page
1733     "\r" gnus-summary-scroll-up
1734     "\M-\r" gnus-summary-scroll-down
1735     "<" gnus-summary-beginning-of-article
1736     ">" gnus-summary-end-of-article
1737     "b" gnus-summary-beginning-of-article
1738     "e" gnus-summary-end-of-article
1739     "^" gnus-summary-refer-parent-article
1740     "r" gnus-summary-refer-parent-article
1741     "D" gnus-summary-enter-digest-group
1742     "R" gnus-summary-refer-references
1743     "T" gnus-summary-refer-thread
1744     "g" gnus-summary-show-article
1745     "s" gnus-summary-isearch-article
1746     "P" gnus-summary-print-article
1747     "M" gnus-mailing-list-insinuate
1748     "t" gnus-article-babel)
1749
1750   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1751     "b" gnus-article-add-buttons
1752     "B" gnus-article-add-buttons-to-head
1753     "o" gnus-article-treat-overstrike
1754     "e" gnus-article-emphasize
1755     "w" gnus-article-fill-cited-article
1756     "Q" gnus-article-fill-long-lines
1757     "C" gnus-article-capitalize-sentences
1758     "c" gnus-article-remove-cr
1759     "q" gnus-article-de-quoted-unreadable
1760     "6" gnus-article-de-base64-unreadable
1761     "Z" gnus-article-decode-HZ
1762     "h" gnus-article-wash-html
1763     "u" gnus-article-unsplit-urls
1764     "s" gnus-summary-force-verify-and-decrypt
1765     "f" gnus-article-display-x-face
1766     "l" gnus-summary-stop-page-breaking
1767     "r" gnus-summary-caesar-message
1768     "m" gnus-summary-morse-message
1769     "t" gnus-summary-toggle-header
1770     "g" gnus-treat-smiley
1771     "v" gnus-summary-verbose-headers
1772     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1773     "p" gnus-article-verify-x-pgp-sig
1774     "d" gnus-article-treat-dumbquotes
1775     "k" gnus-article-outlook-deuglify-article)
1776
1777   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1778     "a" gnus-article-hide
1779     "h" gnus-article-hide-headers
1780     "b" gnus-article-hide-boring-headers
1781     "s" gnus-article-hide-signature
1782     "c" gnus-article-hide-citation
1783     "C" gnus-article-hide-citation-in-followups
1784     "l" gnus-article-hide-list-identifiers
1785     "p" gnus-article-hide-pgp
1786     "B" gnus-article-strip-banner
1787     "P" gnus-article-hide-pem
1788     "\C-c" gnus-article-hide-citation-maybe)
1789
1790   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1791     "a" gnus-article-highlight
1792     "h" gnus-article-highlight-headers
1793     "c" gnus-article-highlight-citation
1794     "s" gnus-article-highlight-signature)
1795
1796   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1797     "f" gnus-article-treat-fold-headers
1798     "u" gnus-article-treat-unfold-headers
1799     "n" gnus-article-treat-fold-newsgroups)
1800
1801   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1802     "x" gnus-article-display-x-face
1803     "s" gnus-treat-smiley
1804     "D" gnus-article-remove-images
1805     "f" gnus-treat-from-picon
1806     "m" gnus-treat-mail-picon
1807     "n" gnus-treat-newsgroups-picon)
1808
1809   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1810     "w" gnus-article-decode-mime-words
1811     "c" gnus-article-decode-charset
1812     "v" gnus-mime-view-all-parts
1813     "b" gnus-article-view-part)
1814
1815   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1816     "z" gnus-article-date-ut
1817     "u" gnus-article-date-ut
1818     "l" gnus-article-date-local
1819     "p" gnus-article-date-english
1820     "e" gnus-article-date-lapsed
1821     "o" gnus-article-date-original
1822     "i" gnus-article-date-iso8601
1823     "s" gnus-article-date-user)
1824
1825   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1826     "t" gnus-article-remove-trailing-blank-lines
1827     "l" gnus-article-strip-leading-blank-lines
1828     "m" gnus-article-strip-multiple-blank-lines
1829     "a" gnus-article-strip-blank-lines
1830     "A" gnus-article-strip-all-blank-lines
1831     "s" gnus-article-strip-leading-space
1832     "e" gnus-article-strip-trailing-space
1833     "w" gnus-article-remove-leading-whitespace)
1834
1835   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1836     "v" gnus-version
1837     "f" gnus-summary-fetch-faq
1838     "d" gnus-summary-describe-group
1839     "h" gnus-summary-describe-briefly
1840     "i" gnus-info-find-node
1841     "c" gnus-group-fetch-charter
1842     "C" gnus-group-fetch-control)
1843
1844   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1845     "e" gnus-summary-expire-articles
1846     "\M-\C-e" gnus-summary-expire-articles-now
1847     "\177" gnus-summary-delete-article
1848     [delete] gnus-summary-delete-article
1849     [backspace] gnus-summary-delete-article
1850     "m" gnus-summary-move-article
1851     "r" gnus-summary-respool-article
1852     "w" gnus-summary-edit-article
1853     "c" gnus-summary-copy-article
1854     "B" gnus-summary-crosspost-article
1855     "q" gnus-summary-respool-query
1856     "t" gnus-summary-respool-trace
1857     "i" gnus-summary-import-article
1858     "I" gnus-summary-create-article
1859     "p" gnus-summary-article-posted-p)
1860
1861   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1862     "o" gnus-summary-save-article
1863     "m" gnus-summary-save-article-mail
1864     "F" gnus-summary-write-article-file
1865     "r" gnus-summary-save-article-rmail
1866     "f" gnus-summary-save-article-file
1867     "b" gnus-summary-save-article-body-file
1868     "h" gnus-summary-save-article-folder
1869     "v" gnus-summary-save-article-vm
1870     "p" gnus-summary-pipe-output
1871     "P" gnus-summary-muttprint
1872     "s" gnus-soup-add-article)
1873
1874   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1875     "b" gnus-summary-display-buttonized
1876     "m" gnus-summary-repair-multipart
1877     "v" gnus-article-view-part
1878     "o" gnus-article-save-part
1879     "c" gnus-article-copy-part
1880     "C" gnus-article-view-part-as-charset
1881     "e" gnus-article-view-part-externally
1882     "E" gnus-article-encrypt-body
1883     "i" gnus-article-inline-part
1884     "|" gnus-article-pipe-part)
1885
1886   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1887     "p" gnus-summary-mark-as-processable
1888     "u" gnus-summary-unmark-as-processable
1889     "U" gnus-summary-unmark-all-processable
1890     "v" gnus-uu-mark-over
1891     "s" gnus-uu-mark-series
1892     "r" gnus-uu-mark-region
1893     "g" gnus-uu-unmark-region
1894     "R" gnus-uu-mark-by-regexp
1895     "G" gnus-uu-unmark-by-regexp
1896     "t" gnus-uu-mark-thread
1897     "T" gnus-uu-unmark-thread
1898     "a" gnus-uu-mark-all
1899     "b" gnus-uu-mark-buffer
1900     "S" gnus-uu-mark-sparse
1901     "k" gnus-summary-kill-process-mark
1902     "y" gnus-summary-yank-process-mark
1903     "w" gnus-summary-save-process-mark
1904     "i" gnus-uu-invert-processable)
1905
1906   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1907     ;;"x" gnus-uu-extract-any
1908     "m" gnus-summary-save-parts
1909     "u" gnus-uu-decode-uu
1910     "U" gnus-uu-decode-uu-and-save
1911     "s" gnus-uu-decode-unshar
1912     "S" gnus-uu-decode-unshar-and-save
1913     "o" gnus-uu-decode-save
1914     "O" gnus-uu-decode-save
1915     "b" gnus-uu-decode-binhex
1916     "B" gnus-uu-decode-binhex
1917     "p" gnus-uu-decode-postscript
1918     "P" gnus-uu-decode-postscript-and-save)
1919
1920   (gnus-define-keys
1921       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1922     "u" gnus-uu-decode-uu-view
1923     "U" gnus-uu-decode-uu-and-save-view
1924     "s" gnus-uu-decode-unshar-view
1925     "S" gnus-uu-decode-unshar-and-save-view
1926     "o" gnus-uu-decode-save-view
1927     "O" gnus-uu-decode-save-view
1928     "b" gnus-uu-decode-binhex-view
1929     "B" gnus-uu-decode-binhex-view
1930     "p" gnus-uu-decode-postscript-view
1931     "P" gnus-uu-decode-postscript-and-save-view))
1932
1933 (defvar gnus-article-post-menu nil)
1934
1935 (defconst gnus-summary-menu-maxlen 20)
1936
1937 (defun gnus-summary-menu-split (menu)
1938   ;; If we have lots of elements, divide them into groups of 20
1939   ;; and make a pane (or submenu) for each one.
1940   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1941       (let ((menu menu) sublists next
1942             (i 1))
1943         (while menu
1944           ;; Pull off the next gnus-summary-menu-maxlen elements
1945           ;; and make them the next element of sublist.
1946           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1947           (if next
1948               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1949                       nil))
1950           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1951                                              (aref (car (last menu)) 0)) menu)
1952                                sublists))
1953           (setq i (1+ i))
1954           (setq menu next))
1955         (nreverse sublists))
1956     ;; Few elements--put them all in one pane.
1957     menu))
1958
1959 (defun gnus-summary-make-menu-bar ()
1960   (gnus-turn-off-edit-menu 'summary)
1961
1962   (unless (boundp 'gnus-summary-misc-menu)
1963
1964     (easy-menu-define
1965       gnus-summary-kill-menu gnus-summary-mode-map ""
1966       (cons
1967        "Score"
1968        (nconc
1969         (list
1970          ["Customize" gnus-score-customize t])
1971         (gnus-make-score-map 'increase)
1972         (gnus-make-score-map 'lower)
1973         '(("Mark"
1974            ["Kill below" gnus-summary-kill-below t]
1975            ["Mark above" gnus-summary-mark-above t]
1976            ["Tick above" gnus-summary-tick-above t]
1977            ["Clear above" gnus-summary-clear-above t])
1978           ["Current score" gnus-summary-current-score t]
1979           ["Set score" gnus-summary-set-score t]
1980           ["Switch current score file..." gnus-score-change-score-file t]
1981           ["Set mark below..." gnus-score-set-mark-below t]
1982           ["Set expunge below..." gnus-score-set-expunge-below t]
1983           ["Edit current score file" gnus-score-edit-current-scores t]
1984           ["Edit score file" gnus-score-edit-file t]
1985           ["Trace score" gnus-score-find-trace t]
1986           ["Find words" gnus-score-find-favourite-words t]
1987           ["Rescore buffer" gnus-summary-rescore t]
1988           ["Increase score..." gnus-summary-increase-score t]
1989           ["Lower score..." gnus-summary-lower-score t]))))
1990
1991     ;; Define both the Article menu in the summary buffer and the
1992     ;; equivalent Commands menu in the article buffer here for
1993     ;; consistency.
1994     (let ((innards
1995            `(("Hide"
1996               ["All" gnus-article-hide t]
1997               ["Headers" gnus-article-hide-headers t]
1998               ["Signature" gnus-article-hide-signature t]
1999               ["Citation" gnus-article-hide-citation t]
2000               ["List identifiers" gnus-article-hide-list-identifiers t]
2001               ["PGP" gnus-article-hide-pgp t]
2002               ["Banner" gnus-article-strip-banner t]
2003               ["Boring headers" gnus-article-hide-boring-headers t])
2004              ("Highlight"
2005               ["All" gnus-article-highlight t]
2006               ["Headers" gnus-article-highlight-headers t]
2007               ["Signature" gnus-article-highlight-signature t]
2008               ["Citation" gnus-article-highlight-citation t])
2009              ("MIME"
2010               ["Words" gnus-article-decode-mime-words t]
2011               ["Charset" gnus-article-decode-charset t]
2012               ["QP" gnus-article-de-quoted-unreadable t]
2013               ["Base64" gnus-article-de-base64-unreadable t]
2014               ["View MIME buttons" gnus-summary-display-buttonized t]
2015               ["View all" gnus-mime-view-all-parts t]
2016               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2017               ["Encrypt body" gnus-article-encrypt-body t]
2018               ["Extract all parts" gnus-summary-save-parts t])
2019              ("Date"
2020               ["Local" gnus-article-date-local t]
2021               ["ISO8601" gnus-article-date-iso8601 t]
2022               ["UT" gnus-article-date-ut t]
2023               ["Original" gnus-article-date-original t]
2024               ["Lapsed" gnus-article-date-lapsed t]
2025               ["User-defined" gnus-article-date-user t])
2026              ("Display"
2027               ["Remove images" gnus-article-remove-images t]
2028               ["Toggle smiley" gnus-treat-smiley t]
2029               ["Show X-Face" gnus-article-display-x-face t]
2030               ["Show picons in From" gnus-treat-from-picon t]
2031               ["Show picons in mail headers" gnus-treat-mail-picon t]
2032               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2033               ("View as different encoding"
2034                ,@(gnus-summary-menu-split
2035                   (mapcar
2036                    (lambda (cs)
2037                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2038                      ;; forms for menu commands, we should provide intern'ed
2039                      ;; function symbols.
2040                      (let ((command (intern (format "\
2041 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2042                        (fset command
2043                              `(lambda ()
2044                                 (interactive)
2045                                 (let ((gnus-summary-show-article-charset-alist
2046                                        '((1 . ,cs))))
2047                                   (gnus-summary-show-article 1))))
2048                        `[,(symbol-name cs) ,command t]))
2049                    (sort (if (fboundp 'coding-system-list)
2050                              (coding-system-list)
2051                            (mapcar 'car mm-mime-mule-charset-alist))
2052                          'string<)))))
2053              ("Washing"
2054               ("Remove Blanks"
2055                ["Leading" gnus-article-strip-leading-blank-lines t]
2056                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2057                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2058                ["All of the above" gnus-article-strip-blank-lines t]
2059                ["All" gnus-article-strip-all-blank-lines t]
2060                ["Leading space" gnus-article-strip-leading-space t]
2061                ["Trailing space" gnus-article-strip-trailing-space t]
2062                ["Leading space in headers"
2063                 gnus-article-remove-leading-whitespace t])
2064               ["Overstrike" gnus-article-treat-overstrike t]
2065               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2066               ["Emphasis" gnus-article-emphasize t]
2067               ["Word wrap" gnus-article-fill-cited-article t]
2068               ["Fill long lines" gnus-article-fill-long-lines t]
2069               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2070               ["CR" gnus-article-remove-cr t]
2071               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2072               ["Base64" gnus-article-de-base64-unreadable t]
2073               ["Rot 13" gnus-summary-caesar-message
2074                ,@(if (featurep 'xemacs) '(t)
2075                    '(:help "\"Caesar rotate\" article by 13"))]
2076               ["Morse decode" gnus-summary-morse-message t]
2077               ["Unix pipe..." gnus-summary-pipe-message t]
2078               ["Add buttons" gnus-article-add-buttons t]
2079               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2080               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2081               ["Verbose header" gnus-summary-verbose-headers t]
2082               ["Toggle header" gnus-summary-toggle-header t]
2083               ["Unfold headers" gnus-article-treat-unfold-headers t]
2084               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2085               ["Html" gnus-article-wash-html t]
2086               ["URLs" gnus-article-unsplit-urls t]
2087               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2088               ["HZ" gnus-article-decode-HZ t]
2089               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2090               )
2091              ("Output"
2092               ["Save in default format" gnus-summary-save-article
2093                ,@(if (featurep 'xemacs) '(t)
2094                    '(:help "Save article using default method"))]
2095               ["Save in file" gnus-summary-save-article-file
2096                ,@(if (featurep 'xemacs) '(t)
2097                    '(:help "Save article in file"))]
2098               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2099               ["Save in MH folder" gnus-summary-save-article-folder t]
2100               ["Save in VM folder" gnus-summary-save-article-vm t]
2101               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2102               ["Save body in file" gnus-summary-save-article-body-file t]
2103               ["Pipe through a filter" gnus-summary-pipe-output t]
2104               ["Add to SOUP packet" gnus-soup-add-article t]
2105               ["Print with Muttprint" gnus-summary-muttprint t]
2106               ["Print" gnus-summary-print-article t])
2107              ("Backend"
2108               ["Respool article..." gnus-summary-respool-article t]
2109               ["Move article..." gnus-summary-move-article
2110                (gnus-check-backend-function
2111                 'request-move-article gnus-newsgroup-name)]
2112               ["Copy article..." gnus-summary-copy-article t]
2113               ["Crosspost article..." gnus-summary-crosspost-article
2114                (gnus-check-backend-function
2115                 'request-replace-article gnus-newsgroup-name)]
2116               ["Import file..." gnus-summary-import-article t]
2117               ["Create article..." gnus-summary-create-article t]
2118               ["Check if posted" gnus-summary-article-posted-p t]
2119               ["Edit article" gnus-summary-edit-article
2120                (not (gnus-group-read-only-p))]
2121               ["Delete article" gnus-summary-delete-article
2122                (gnus-check-backend-function
2123                 'request-expire-articles gnus-newsgroup-name)]
2124               ["Query respool" gnus-summary-respool-query t]
2125               ["Trace respool" gnus-summary-respool-trace t]
2126               ["Delete expirable articles" gnus-summary-expire-articles-now
2127                (gnus-check-backend-function
2128                 'request-expire-articles gnus-newsgroup-name)])
2129              ("Extract"
2130               ["Uudecode" gnus-uu-decode-uu
2131                ,@(if (featurep 'xemacs) '(t)
2132                    '(:help "Decode uuencoded article(s)"))]
2133               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2134               ["Unshar" gnus-uu-decode-unshar t]
2135               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2136               ["Save" gnus-uu-decode-save t]
2137               ["Binhex" gnus-uu-decode-binhex t]
2138               ["Postscript" gnus-uu-decode-postscript t]
2139               ["All MIME parts" gnus-summary-save-parts t])
2140              ("Cache"
2141               ["Enter article" gnus-cache-enter-article t]
2142               ["Remove article" gnus-cache-remove-article t])
2143              ["Translate" gnus-article-babel t]
2144              ["Select article buffer" gnus-summary-select-article-buffer t]
2145              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2146              ["Isearch article..." gnus-summary-isearch-article t]
2147              ["Beginning of the article" gnus-summary-beginning-of-article t]
2148              ["End of the article" gnus-summary-end-of-article t]
2149              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2150              ["Fetch referenced articles" gnus-summary-refer-references t]
2151              ["Fetch current thread" gnus-summary-refer-thread t]
2152              ["Fetch article with id..." gnus-summary-refer-article t]
2153              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2154              ["Redisplay" gnus-summary-show-article t]
2155              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2156       (easy-menu-define
2157         gnus-summary-article-menu gnus-summary-mode-map ""
2158         (cons "Article" innards))
2159
2160       (if (not (keymapp gnus-summary-article-menu))
2161           (easy-menu-define
2162             gnus-article-commands-menu gnus-article-mode-map ""
2163             (cons "Commands" innards))
2164         ;; in Emacs, don't share menu.
2165         (setq gnus-article-commands-menu
2166               (copy-keymap gnus-summary-article-menu))
2167         (define-key gnus-article-mode-map [menu-bar commands]
2168           (cons "Commands" gnus-article-commands-menu))))
2169
2170     (easy-menu-define
2171       gnus-summary-thread-menu gnus-summary-mode-map ""
2172       '("Threads"
2173         ["Toggle threading" gnus-summary-toggle-threads t]
2174         ["Hide threads" gnus-summary-hide-all-threads t]
2175         ["Show threads" gnus-summary-show-all-threads t]
2176         ["Hide thread" gnus-summary-hide-thread t]
2177         ["Show thread" gnus-summary-show-thread t]
2178         ["Go to next thread" gnus-summary-next-thread t]
2179         ["Go to previous thread" gnus-summary-prev-thread t]
2180         ["Go down thread" gnus-summary-down-thread t]
2181         ["Go up thread" gnus-summary-up-thread t]
2182         ["Top of thread" gnus-summary-top-thread t]
2183         ["Mark thread as read" gnus-summary-kill-thread t]
2184         ["Lower thread score" gnus-summary-lower-thread t]
2185         ["Raise thread score" gnus-summary-raise-thread t]
2186         ["Rethread current" gnus-summary-rethread-current t]))
2187
2188     (easy-menu-define
2189       gnus-summary-post-menu gnus-summary-mode-map ""
2190       `("Post"
2191         ["Send a message (mail or news)" gnus-summary-post-news
2192          ,@(if (featurep 'xemacs) '(t)
2193              '(:help "Post an article"))]
2194         ["Followup" gnus-summary-followup
2195          ,@(if (featurep 'xemacs) '(t)
2196              '(:help "Post followup to this article"))]
2197         ["Followup and yank" gnus-summary-followup-with-original
2198          ,@(if (featurep 'xemacs) '(t)
2199              '(:help "Post followup to this article, quoting its contents"))]
2200         ["Supersede article" gnus-summary-supersede-article t]
2201         ["Cancel article" gnus-summary-cancel-article
2202          ,@(if (featurep 'xemacs) '(t)
2203              '(:help "Cancel an article you posted"))]
2204         ["Reply" gnus-summary-reply t]
2205         ["Reply and yank" gnus-summary-reply-with-original t]
2206         ["Wide reply" gnus-summary-wide-reply t]
2207         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2208          ,@(if (featurep 'xemacs) '(t)
2209              '(:help "Mail a reply, quoting this article"))]
2210         ["Very wide reply" gnus-summary-very-wide-reply t]
2211         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2212          ,@(if (featurep 'xemacs) '(t)
2213              '(:help "Mail a very wide reply, quoting this article"))]
2214         ["Mail forward" gnus-summary-mail-forward t]
2215         ["Post forward" gnus-summary-post-forward t]
2216         ["Digest and mail" gnus-uu-digest-mail-forward t]
2217         ["Digest and post" gnus-uu-digest-post-forward t]
2218         ["Resend message" gnus-summary-resend-message t]
2219         ["Resend message edit" gnus-summary-resend-message-edit t]
2220         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2221         ["Send a mail" gnus-summary-mail-other-window t]
2222         ["Create a local message" gnus-summary-news-other-window t]
2223         ["Uuencode and post" gnus-uu-post-news
2224          ,@(if (featurep 'xemacs) '(t)
2225              '(:help "Post a uuencoded article"))]
2226         ["Followup via news" gnus-summary-followup-to-mail t]
2227         ["Followup via news and yank"
2228          gnus-summary-followup-to-mail-with-original t]
2229         ;;("Draft"
2230         ;;["Send" gnus-summary-send-draft t]
2231         ;;["Send bounced" gnus-resend-bounced-mail t])
2232         ))
2233
2234     (cond
2235      ((not (keymapp gnus-summary-post-menu))
2236       (setq gnus-article-post-menu gnus-summary-post-menu))
2237      ((not gnus-article-post-menu)
2238       ;; Don't share post menu.
2239       (setq gnus-article-post-menu
2240             (copy-keymap gnus-summary-post-menu))))
2241     (define-key gnus-article-mode-map [menu-bar post]
2242       (cons "Post" gnus-article-post-menu))
2243
2244     (easy-menu-define
2245       gnus-summary-misc-menu gnus-summary-mode-map ""
2246       `("Gnus"
2247         ("Mark Read"
2248          ["Mark as read" gnus-summary-mark-as-read-forward t]
2249          ["Mark same subject and select"
2250           gnus-summary-kill-same-subject-and-select t]
2251          ["Mark same subject" gnus-summary-kill-same-subject t]
2252          ["Catchup" gnus-summary-catchup
2253           ,@(if (featurep 'xemacs) '(t)
2254               '(:help "Mark unread articles in this group as read"))]
2255          ["Catchup all" gnus-summary-catchup-all t]
2256          ["Catchup to here" gnus-summary-catchup-to-here t]
2257          ["Catchup from here" gnus-summary-catchup-from-here t]
2258          ["Catchup region" gnus-summary-mark-region-as-read t]
2259          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2260         ("Mark Various"
2261          ["Tick" gnus-summary-tick-article-forward t]
2262          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2263          ["Remove marks" gnus-summary-clear-mark-forward t]
2264          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2265          ["Set bookmark" gnus-summary-set-bookmark t]
2266          ["Remove bookmark" gnus-summary-remove-bookmark t])
2267         ("Limit to"
2268          ["Marks..." gnus-summary-limit-to-marks t]
2269          ["Subject..." gnus-summary-limit-to-subject t]
2270          ["Author..." gnus-summary-limit-to-author t]
2271          ["Age..." gnus-summary-limit-to-age t]
2272          ["Extra..." gnus-summary-limit-to-extra t]
2273          ["Score..." gnus-summary-limit-to-score t]
2274          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2275          ["Unread" gnus-summary-limit-to-unread t]
2276          ["Unseen" gnus-summary-limit-to-unseen t]
2277          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2278          ["Articles" gnus-summary-limit-to-articles t]
2279          ["Pop limit" gnus-summary-pop-limit t]
2280          ["Show dormant" gnus-summary-limit-include-dormant t]
2281          ["Hide childless dormant"
2282           gnus-summary-limit-exclude-childless-dormant t]
2283          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2284          ["Hide marked" gnus-summary-limit-exclude-marks t]
2285          ["Show expunged" gnus-summary-limit-include-expunged t])
2286         ("Process Mark"
2287          ["Set mark" gnus-summary-mark-as-processable t]
2288          ["Remove mark" gnus-summary-unmark-as-processable t]
2289          ["Remove all marks" gnus-summary-unmark-all-processable t]
2290          ["Mark above" gnus-uu-mark-over t]
2291          ["Mark series" gnus-uu-mark-series t]
2292          ["Mark region" gnus-uu-mark-region t]
2293          ["Unmark region" gnus-uu-unmark-region t]
2294          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2295          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2296          ["Mark all" gnus-uu-mark-all t]
2297          ["Mark buffer" gnus-uu-mark-buffer t]
2298          ["Mark sparse" gnus-uu-mark-sparse t]
2299          ["Mark thread" gnus-uu-mark-thread t]
2300          ["Unmark thread" gnus-uu-unmark-thread t]
2301          ("Process Mark Sets"
2302           ["Kill" gnus-summary-kill-process-mark t]
2303           ["Yank" gnus-summary-yank-process-mark
2304            gnus-newsgroup-process-stack]
2305           ["Save" gnus-summary-save-process-mark t]))
2306         ("Scroll article"
2307          ["Page forward" gnus-summary-next-page
2308           ,@(if (featurep 'xemacs) '(t)
2309               '(:help "Show next page of article"))]
2310          ["Page backward" gnus-summary-prev-page
2311           ,@(if (featurep 'xemacs) '(t)
2312               '(:help "Show previous page of article"))]
2313          ["Line forward" gnus-summary-scroll-up t])
2314         ("Move"
2315          ["Next unread article" gnus-summary-next-unread-article t]
2316          ["Previous unread article" gnus-summary-prev-unread-article t]
2317          ["Next article" gnus-summary-next-article t]
2318          ["Previous article" gnus-summary-prev-article t]
2319          ["Next unread subject" gnus-summary-next-unread-subject t]
2320          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2321          ["Next article same subject" gnus-summary-next-same-subject t]
2322          ["Previous article same subject" gnus-summary-prev-same-subject t]
2323          ["First unread article" gnus-summary-first-unread-article t]
2324          ["Best unread article" gnus-summary-best-unread-article t]
2325          ["Go to subject number..." gnus-summary-goto-subject t]
2326          ["Go to article number..." gnus-summary-goto-article t]
2327          ["Go to the last article" gnus-summary-goto-last-article t]
2328          ["Pop article off history" gnus-summary-pop-article t])
2329         ("Sort"
2330          ["Sort by number" gnus-summary-sort-by-number t]
2331          ["Sort by author" gnus-summary-sort-by-author t]
2332          ["Sort by subject" gnus-summary-sort-by-subject t]
2333          ["Sort by date" gnus-summary-sort-by-date t]
2334          ["Sort by score" gnus-summary-sort-by-score t]
2335          ["Sort by lines" gnus-summary-sort-by-lines t]
2336          ["Sort by characters" gnus-summary-sort-by-chars t]
2337          ["Randomize" gnus-summary-sort-by-random t]
2338          ["Original sort" gnus-summary-sort-by-original t])
2339         ("Help"
2340          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2341          ["Describe group" gnus-summary-describe-group t]
2342          ["Fetch charter" gnus-group-fetch-charter
2343           ,@(if (featurep 'xemacs) nil
2344               '(:help "Display the charter of the current group"))]
2345          ["Fetch control message" gnus-group-fetch-control
2346           ,@(if (featurep 'xemacs) nil
2347               '(:help "Display the archived control message for the current group"))]
2348          ["Read manual" gnus-info-find-node t])
2349         ("Modes"
2350          ["Pick and read" gnus-pick-mode t]
2351          ["Binary" gnus-binary-mode t])
2352         ("Regeneration"
2353          ["Regenerate" gnus-summary-prepare t]
2354          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2355          ["Toggle threading" gnus-summary-toggle-threads t])
2356         ["See old articles" gnus-summary-insert-old-articles t]
2357         ["See new articles" gnus-summary-insert-new-articles t]
2358         ["Filter articles..." gnus-summary-execute-command t]
2359         ["Run command on subjects..." gnus-summary-universal-argument t]
2360         ["Search articles forward..." gnus-summary-search-article-forward t]
2361         ["Search articles backward..." gnus-summary-search-article-backward t]
2362         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2363         ["Expand window" gnus-summary-expand-window t]
2364         ["Expire expirable articles" gnus-summary-expire-articles
2365          (gnus-check-backend-function
2366           'request-expire-articles gnus-newsgroup-name)]
2367         ["Edit local kill file" gnus-summary-edit-local-kill t]
2368         ["Edit main kill file" gnus-summary-edit-global-kill t]
2369         ["Edit group parameters" gnus-summary-edit-parameters t]
2370         ["Customize group parameters" gnus-summary-customize-parameters t]
2371         ["Send a bug report" gnus-bug t]
2372         ("Exit"
2373          ["Catchup and exit" gnus-summary-catchup-and-exit
2374           ,@(if (featurep 'xemacs) '(t)
2375               '(:help "Mark unread articles in this group as read, then exit"))]
2376          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2377          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2378          ["Exit group" gnus-summary-exit
2379           ,@(if (featurep 'xemacs) '(t)
2380               '(:help "Exit current group, return to group selection mode"))]
2381          ["Exit group without updating" gnus-summary-exit-no-update t]
2382          ["Exit and goto next group" gnus-summary-next-group t]
2383          ["Exit and goto prev group" gnus-summary-prev-group t]
2384          ["Reselect group" gnus-summary-reselect-current-group t]
2385          ["Rescan group" gnus-summary-rescan-group t]
2386          ["Update dribble" gnus-summary-save-newsrc t])))
2387
2388     (gnus-run-hooks 'gnus-summary-menu-hook)))
2389
2390 (defvar gnus-summary-tool-bar-map nil)
2391
2392 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2393 (defun gnus-summary-make-tool-bar ()
2394   (if (and (fboundp 'tool-bar-add-item-from-menu)
2395            (default-value 'tool-bar-mode)
2396            (not gnus-summary-tool-bar-map))
2397       (setq gnus-summary-tool-bar-map
2398             (let ((tool-bar-map (make-sparse-keymap))
2399                   (load-path (mm-image-load-path)))
2400               (tool-bar-add-item-from-menu
2401                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2402               (tool-bar-add-item-from-menu
2403                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2404               (tool-bar-add-item-from-menu
2405                'gnus-summary-post-news "post" gnus-summary-mode-map)
2406               (tool-bar-add-item-from-menu
2407                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2408               (tool-bar-add-item-from-menu
2409                'gnus-summary-followup "followup" gnus-summary-mode-map)
2410               (tool-bar-add-item-from-menu
2411                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2412               (tool-bar-add-item-from-menu
2413                'gnus-summary-reply "reply" gnus-summary-mode-map)
2414               (tool-bar-add-item-from-menu
2415                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2416               (tool-bar-add-item-from-menu
2417                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2418               (tool-bar-add-item-from-menu
2419                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2420               (tool-bar-add-item-from-menu
2421                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2422               (tool-bar-add-item-from-menu
2423                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2424               (tool-bar-add-item-from-menu
2425                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2426               (tool-bar-add-item-from-menu
2427                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2428               (tool-bar-add-item-from-menu
2429                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2430               tool-bar-map)))
2431   (if gnus-summary-tool-bar-map
2432       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2433
2434 (defun gnus-score-set-default (var value)
2435   "A version of set that updates the GNU Emacs menu-bar."
2436   (set var value)
2437   ;; It is the message that forces the active status to be updated.
2438   (message ""))
2439
2440 (defun gnus-make-score-map (type)
2441   "Make a summary score map of type TYPE."
2442   (if t
2443       nil
2444     (let ((headers '(("author" "from" string)
2445                      ("subject" "subject" string)
2446                      ("article body" "body" string)
2447                      ("article head" "head" string)
2448                      ("xref" "xref" string)
2449                      ("extra header" "extra" string)
2450                      ("lines" "lines" number)
2451                      ("followups to author" "followup" string)))
2452           (types '((number ("less than" <)
2453                            ("greater than" >)
2454                            ("equal" =))
2455                    (string ("substring" s)
2456                            ("exact string" e)
2457                            ("fuzzy string" f)
2458                            ("regexp" r))))
2459           (perms '(("temporary" (current-time-string))
2460                    ("permanent" nil)
2461                    ("immediate" now)))
2462           header)
2463       (list
2464        (apply
2465         'nconc
2466         (list
2467          (if (eq type 'lower)
2468              "Lower score"
2469            "Increase score"))
2470         (let (outh)
2471           (while headers
2472             (setq header (car headers))
2473             (setq outh
2474                   (cons
2475                    (apply
2476                     'nconc
2477                     (list (car header))
2478                     (let ((ts (cdr (assoc (nth 2 header) types)))
2479                           outt)
2480                       (while ts
2481                         (setq outt
2482                               (cons
2483                                (apply
2484                                 'nconc
2485                                 (list (caar ts))
2486                                 (let ((ps perms)
2487                                       outp)
2488                                   (while ps
2489                                     (setq outp
2490                                           (cons
2491                                            (vector
2492                                             (caar ps)
2493                                             (list
2494                                              'gnus-summary-score-entry
2495                                              (nth 1 header)
2496                                              (if (or (string= (nth 1 header)
2497                                                               "head")
2498                                                      (string= (nth 1 header)
2499                                                               "body"))
2500                                                  ""
2501                                                (list 'gnus-summary-header
2502                                                      (nth 1 header)))
2503                                              (list 'quote (nth 1 (car ts)))
2504                                              (list 'gnus-score-delta-default
2505                                                    nil)
2506                                              (nth 1 (car ps))
2507                                              t)
2508                                             t)
2509                                            outp))
2510                                     (setq ps (cdr ps)))
2511                                   (list (nreverse outp))))
2512                                outt))
2513                         (setq ts (cdr ts)))
2514                       (list (nreverse outt))))
2515                    outh))
2516             (setq headers (cdr headers)))
2517           (list (nreverse outh))))))))
2518
2519 \f
2520
2521 (defun gnus-summary-mode (&optional group)
2522   "Major mode for reading articles.
2523
2524 All normal editing commands are switched off.
2525 \\<gnus-summary-mode-map>
2526 Each line in this buffer represents one article.  To read an
2527 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2528 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2529 respectively.
2530
2531 You can also post articles and send mail from this buffer.  To
2532 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2533 of an article, type `\\[gnus-summary-reply]'.
2534
2535 There are approx. one gazillion commands you can execute in this
2536 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2537
2538 The following commands are available:
2539
2540 \\{gnus-summary-mode-map}"
2541   (interactive)
2542   (kill-all-local-variables)
2543   (when (gnus-visual-p 'summary-menu 'menu)
2544     (gnus-summary-make-menu-bar)
2545     (gnus-summary-make-tool-bar))
2546   (gnus-summary-make-local-variables)
2547   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2548     (gnus-summary-make-local-variables))
2549   (gnus-make-thread-indent-array)
2550   (gnus-simplify-mode-line)
2551   (setq major-mode 'gnus-summary-mode)
2552   (setq mode-name "Summary")
2553   (make-local-variable 'minor-mode-alist)
2554   (use-local-map gnus-summary-mode-map)
2555   (buffer-disable-undo)
2556   (setq buffer-read-only t)             ;Disable modification
2557   (setq truncate-lines t)
2558   (setq selective-display t)
2559   (setq selective-display-ellipses t)   ;Display `...'
2560   (gnus-summary-set-display-table)
2561   (gnus-set-default-directory)
2562   (setq gnus-newsgroup-name group)
2563   (make-local-variable 'gnus-summary-line-format)
2564   (make-local-variable 'gnus-summary-line-format-spec)
2565   (make-local-variable 'gnus-summary-dummy-line-format)
2566   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2567   (make-local-variable 'gnus-summary-mark-positions)
2568   (make-local-hook 'pre-command-hook)
2569   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2570   (gnus-run-hooks 'gnus-summary-mode-hook)
2571   (turn-on-gnus-mailing-list-mode)
2572   (mm-enable-multibyte)
2573   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2574   (gnus-update-summary-mark-positions))
2575
2576 (defun gnus-summary-make-local-variables ()
2577   "Make all the local summary buffer variables."
2578   (let (global)
2579     (dolist (local gnus-summary-local-variables)
2580       (if (consp local)
2581           (progn
2582             (if (eq (cdr local) 'global)
2583                 ;; Copy the global value of the variable.
2584                 (setq global (symbol-value (car local)))
2585               ;; Use the value from the list.
2586               (setq global (eval (cdr local))))
2587             (set (make-local-variable (car local)) global))
2588         ;; Simple nil-valued local variable.
2589         (set (make-local-variable local) nil)))))
2590
2591 (defun gnus-summary-clear-local-variables ()
2592   (let ((locals gnus-summary-local-variables))
2593     (while locals
2594       (if (consp (car locals))
2595           (and (vectorp (caar locals))
2596                (set (caar locals) nil))
2597         (and (vectorp (car locals))
2598              (set (car locals) nil)))
2599       (setq locals (cdr locals)))))
2600
2601 ;; Summary data functions.
2602
2603 (defmacro gnus-data-number (data)
2604   `(car ,data))
2605
2606 (defmacro gnus-data-set-number (data number)
2607   `(setcar ,data ,number))
2608
2609 (defmacro gnus-data-mark (data)
2610   `(nth 1 ,data))
2611
2612 (defmacro gnus-data-set-mark (data mark)
2613   `(setcar (nthcdr 1 ,data) ,mark))
2614
2615 (defmacro gnus-data-pos (data)
2616   `(nth 2 ,data))
2617
2618 (defmacro gnus-data-set-pos (data pos)
2619   `(setcar (nthcdr 2 ,data) ,pos))
2620
2621 (defmacro gnus-data-header (data)
2622   `(nth 3 ,data))
2623
2624 (defmacro gnus-data-set-header (data header)
2625   `(setf (nth 3 ,data) ,header))
2626
2627 (defmacro gnus-data-level (data)
2628   `(nth 4 ,data))
2629
2630 (defmacro gnus-data-unread-p (data)
2631   `(= (nth 1 ,data) gnus-unread-mark))
2632
2633 (defmacro gnus-data-read-p (data)
2634   `(/= (nth 1 ,data) gnus-unread-mark))
2635
2636 (defmacro gnus-data-pseudo-p (data)
2637   `(consp (nth 3 ,data)))
2638
2639 (defmacro gnus-data-find (number)
2640   `(assq ,number gnus-newsgroup-data))
2641
2642 (defmacro gnus-data-find-list (number &optional data)
2643   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2644      (memq (assq ,number bdata)
2645            bdata)))
2646
2647 (defmacro gnus-data-make (number mark pos header level)
2648   `(list ,number ,mark ,pos ,header ,level))
2649
2650 (defun gnus-data-enter (after-article number mark pos header level offset)
2651   (let ((data (gnus-data-find-list after-article)))
2652     (unless data
2653       (error "No such article: %d" after-article))
2654     (setcdr data (cons (gnus-data-make number mark pos header level)
2655                        (cdr data)))
2656     (setq gnus-newsgroup-data-reverse nil)
2657     (gnus-data-update-list (cddr data) offset)))
2658
2659 (defun gnus-data-enter-list (after-article list &optional offset)
2660   (when list
2661     (let ((data (and after-article (gnus-data-find-list after-article)))
2662           (ilist list))
2663       (if (not (or data
2664                    after-article))
2665           (let ((odata gnus-newsgroup-data))
2666             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2667             (when offset
2668               (gnus-data-update-list odata offset)))
2669       ;; Find the last element in the list to be spliced into the main
2670         ;; list.
2671         (while (cdr list)
2672           (setq list (cdr list)))
2673         (if (not data)
2674             (progn
2675               (setcdr list gnus-newsgroup-data)
2676               (setq gnus-newsgroup-data ilist)
2677               (when offset
2678                 (gnus-data-update-list (cdr list) offset)))
2679           (setcdr list (cdr data))
2680           (setcdr data ilist)
2681           (when offset
2682             (gnus-data-update-list (cdr list) offset))))
2683       (setq gnus-newsgroup-data-reverse nil))))
2684
2685 (defun gnus-data-remove (article &optional offset)
2686   (let ((data gnus-newsgroup-data))
2687     (if (= (gnus-data-number (car data)) article)
2688         (progn
2689           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2690                 gnus-newsgroup-data-reverse nil)
2691           (when offset
2692             (gnus-data-update-list gnus-newsgroup-data offset)))
2693       (while (cdr data)
2694         (when (= (gnus-data-number (cadr data)) article)
2695           (setcdr data (cddr data))
2696           (when offset
2697             (gnus-data-update-list (cdr data) offset))
2698           (setq data nil
2699                 gnus-newsgroup-data-reverse nil))
2700         (setq data (cdr data))))))
2701
2702 (defmacro gnus-data-list (backward)
2703   `(if ,backward
2704        (or gnus-newsgroup-data-reverse
2705            (setq gnus-newsgroup-data-reverse
2706                  (reverse gnus-newsgroup-data)))
2707      gnus-newsgroup-data))
2708
2709 (defun gnus-data-update-list (data offset)
2710   "Add OFFSET to the POS of all data entries in DATA."
2711   (setq gnus-newsgroup-data-reverse nil)
2712   (while data
2713     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2714     (setq data (cdr data))))
2715
2716 (defun gnus-summary-article-pseudo-p (article)
2717   "Say whether this article is a pseudo article or not."
2718   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2719
2720 (defmacro gnus-summary-article-sparse-p (article)
2721   "Say whether this article is a sparse article or not."
2722   `(memq ,article gnus-newsgroup-sparse))
2723
2724 (defmacro gnus-summary-article-ancient-p (article)
2725   "Say whether this article is a sparse article or not."
2726   `(memq ,article gnus-newsgroup-ancient))
2727
2728 (defun gnus-article-parent-p (number)
2729   "Say whether this article is a parent or not."
2730   (let ((data (gnus-data-find-list number)))
2731     (and (cdr data)              ; There has to be an article after...
2732          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2733             (gnus-data-level (nth 1 data))))))
2734
2735 (defun gnus-article-children (number)
2736   "Return a list of all children to NUMBER."
2737   (let* ((data (gnus-data-find-list number))
2738          (level (gnus-data-level (car data)))
2739          children)
2740     (setq data (cdr data))
2741     (while (and data
2742                 (= (gnus-data-level (car data)) (1+ level)))
2743       (push (gnus-data-number (car data)) children)
2744       (setq data (cdr data)))
2745     children))
2746
2747 (defmacro gnus-summary-skip-intangible ()
2748   "If the current article is intangible, then jump to a different article."
2749   '(let ((to (get-text-property (point) 'gnus-intangible)))
2750      (and to (gnus-summary-goto-subject to))))
2751
2752 (defmacro gnus-summary-article-intangible-p ()
2753   "Say whether this article is intangible or not."
2754   '(get-text-property (point) 'gnus-intangible))
2755
2756 (defun gnus-article-read-p (article)
2757   "Say whether ARTICLE is read or not."
2758   (not (or (memq article gnus-newsgroup-marked)
2759            (memq article gnus-newsgroup-spam-marked)
2760            (memq article gnus-newsgroup-unreads)
2761            (memq article gnus-newsgroup-unselected)
2762            (memq article gnus-newsgroup-dormant))))
2763
2764 ;; Some summary mode macros.
2765
2766 (defmacro gnus-summary-article-number ()
2767   "The article number of the article on the current line.
2768 If there isn't an article number here, then we return the current
2769 article number."
2770   '(progn
2771      (gnus-summary-skip-intangible)
2772      (or (get-text-property (point) 'gnus-number)
2773          (gnus-summary-last-subject))))
2774
2775 (defmacro gnus-summary-article-header (&optional number)
2776   "Return the header of article NUMBER."
2777   `(gnus-data-header (gnus-data-find
2778                       ,(or number '(gnus-summary-article-number)))))
2779
2780 (defmacro gnus-summary-thread-level (&optional number)
2781   "Return the level of thread that starts with article NUMBER."
2782   `(if (and (eq gnus-summary-make-false-root 'dummy)
2783             (get-text-property (point) 'gnus-intangible))
2784        0
2785      (gnus-data-level (gnus-data-find
2786                        ,(or number '(gnus-summary-article-number))))))
2787
2788 (defmacro gnus-summary-article-mark (&optional number)
2789   "Return the mark of article NUMBER."
2790   `(gnus-data-mark (gnus-data-find
2791                     ,(or number '(gnus-summary-article-number)))))
2792
2793 (defmacro gnus-summary-article-pos (&optional number)
2794   "Return the position of the line of article NUMBER."
2795   `(gnus-data-pos (gnus-data-find
2796                    ,(or number '(gnus-summary-article-number)))))
2797
2798 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2799 (defmacro gnus-summary-article-subject (&optional number)
2800   "Return current subject string or nil if nothing."
2801   `(let ((headers
2802           ,(if number
2803                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2804              '(gnus-data-header (assq (gnus-summary-article-number)
2805                                       gnus-newsgroup-data)))))
2806      (and headers
2807           (vectorp headers)
2808           (mail-header-subject headers))))
2809
2810 (defmacro gnus-summary-article-score (&optional number)
2811   "Return current article score."
2812   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2813                   gnus-newsgroup-scored))
2814        gnus-summary-default-score 0))
2815
2816 (defun gnus-summary-article-children (&optional number)
2817   "Return a list of article numbers that are children of article NUMBER."
2818   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2819          (level (gnus-data-level (car data)))
2820          l children)
2821     (while (and (setq data (cdr data))
2822                 (> (setq l (gnus-data-level (car data))) level))
2823       (and (= (1+ level) l)
2824            (push (gnus-data-number (car data))
2825                  children)))
2826     (nreverse children)))
2827
2828 (defun gnus-summary-article-parent (&optional number)
2829   "Return the article number of the parent of article NUMBER."
2830   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2831                                     (gnus-data-list t)))
2832          (level (gnus-data-level (car data))))
2833     (if (zerop level)
2834         ()                              ; This is a root.
2835       ;; We search until we find an article with a level less than
2836       ;; this one.  That function has to be the parent.
2837       (while (and (setq data (cdr data))
2838                   (not (< (gnus-data-level (car data)) level))))
2839       (and data (gnus-data-number (car data))))))
2840
2841 (defun gnus-unread-mark-p (mark)
2842   "Say whether MARK is the unread mark."
2843   (= mark gnus-unread-mark))
2844
2845 (defun gnus-read-mark-p (mark)
2846   "Say whether MARK is one of the marks that mark as read.
2847 This is all marks except unread, ticked, dormant, and expirable."
2848   (not (or (= mark gnus-unread-mark)
2849            (= mark gnus-ticked-mark)
2850            (= mark gnus-dormant-mark)
2851            (= mark gnus-expirable-mark))))
2852
2853 (defmacro gnus-article-mark (number)
2854   "Return the MARK of article NUMBER.
2855 This macro should only be used when computing the mark the \"first\"
2856 time; i.e., when generating the summary lines.  After that,
2857 `gnus-summary-article-mark' should be used to examine the
2858 marks of articles."
2859   `(cond
2860     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2861 ;;;;    ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2862     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2863     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2864     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2865     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2866     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2867     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2868     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2869            gnus-ancient-mark))))
2870
2871 ;; Saving hidden threads.
2872
2873 (defmacro gnus-save-hidden-threads (&rest forms)
2874   "Save hidden threads, eval FORMS, and restore the hidden threads."
2875   (let ((config (make-symbol "config")))
2876     `(let ((,config (gnus-hidden-threads-configuration)))
2877        (unwind-protect
2878            (save-excursion
2879              ,@forms)
2880          (gnus-restore-hidden-threads-configuration ,config)))))
2881 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2882 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2883
2884 (defun gnus-data-compute-positions ()
2885   "Compute the positions of all articles."
2886   (setq gnus-newsgroup-data-reverse nil)
2887   (let ((data gnus-newsgroup-data))
2888     (save-excursion
2889       (gnus-save-hidden-threads
2890         (gnus-summary-show-all-threads)
2891         (goto-char (point-min))
2892         (while data
2893           (while (get-text-property (point) 'gnus-intangible)
2894             (forward-line 1))
2895           (gnus-data-set-pos (car data) (+ (point) 3))
2896           (setq data (cdr data))
2897           (forward-line 1))))))
2898
2899 (defun gnus-hidden-threads-configuration ()
2900   "Return the current hidden threads configuration."
2901   (save-excursion
2902     (let (config)
2903       (goto-char (point-min))
2904       (while (search-forward "\r" nil t)
2905         (push (1- (point)) config))
2906       config)))
2907
2908 (defun gnus-restore-hidden-threads-configuration (config)
2909   "Restore hidden threads configuration from CONFIG."
2910   (save-excursion
2911     (let (point buffer-read-only)
2912       (while (setq point (pop config))
2913         (when (and (< point (point-max))
2914                    (goto-char point)
2915                    (eq (char-after) ?\n))
2916           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2917
2918 ;; Various summary mode internalish functions.
2919
2920 (defun gnus-mouse-pick-article (e)
2921   (interactive "e")
2922   (mouse-set-point e)
2923   (gnus-summary-next-page nil t))
2924
2925 (defun gnus-summary-set-display-table ()
2926   "Change the display table.
2927 Odd characters have a tendency to mess
2928 up nicely formatted displays - we make all possible glyphs
2929 display only a single character."
2930
2931   ;; We start from the standard display table, if any.
2932   (let ((table (or (copy-sequence standard-display-table)
2933                    (make-display-table)))
2934         (i 32))
2935     ;; Nix out all the control chars...
2936     (while (>= (setq i (1- i)) 0)
2937       (aset table i [??]))
2938    ;; ... but not newline and cr, of course.  (cr is necessary for the
2939     ;; selective display).
2940     (aset table ?\n nil)
2941     (aset table ?\r nil)
2942     ;; We keep TAB as well.
2943     (aset table ?\t nil)
2944     ;; We nix out any glyphs over 126 that are not set already.
2945     (let ((i 256))
2946       (while (>= (setq i (1- i)) 127)
2947         ;; Only modify if the entry is nil.
2948         (unless (aref table i)
2949           (aset table i [??]))))
2950     (setq buffer-display-table table)))
2951
2952 (defun gnus-summary-set-article-display-arrow (pos)
2953   "Update the overlay arrow to point to line at position POS."
2954   (when (and gnus-summary-display-arrow
2955              (boundp 'overlay-arrow-position)
2956              (boundp 'overlay-arrow-string))
2957     (save-excursion
2958       (goto-char pos)
2959       (beginning-of-line)
2960       (unless overlay-arrow-position
2961         (setq overlay-arrow-position (make-marker)))
2962       (setq overlay-arrow-string "=>"
2963             overlay-arrow-position (set-marker overlay-arrow-position
2964                                                (point)
2965                                                (current-buffer))))))
2966
2967 (defun gnus-summary-buffer-name (group)
2968   "Return the summary buffer name of GROUP."
2969   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2970
2971 (defun gnus-summary-setup-buffer (group)
2972   "Initialize summary buffer."
2973   (let ((buffer (gnus-summary-buffer-name group))
2974         (dead-name (concat "*Dead Summary "
2975                            (gnus-group-decoded-name group) "*")))
2976     ;; If a dead summary buffer exists, we kill it.
2977     (when (gnus-buffer-live-p dead-name)
2978       (gnus-kill-buffer dead-name))
2979     (if (get-buffer buffer)
2980         (progn
2981           (set-buffer buffer)
2982           (setq gnus-summary-buffer (current-buffer))
2983           (not gnus-newsgroup-prepared))
2984       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2985       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2986       (gnus-summary-mode group)
2987       (when gnus-carpal
2988         (gnus-carpal-setup-buffer 'summary))
2989       (unless gnus-single-article-buffer
2990         (make-local-variable 'gnus-article-buffer)
2991         (make-local-variable 'gnus-article-current)
2992         (make-local-variable 'gnus-original-article-buffer))
2993       (setq gnus-newsgroup-name group)
2994       ;; Set any local variables in the group parameters.
2995       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2996       t)))
2997
2998 (defun gnus-set-global-variables ()
2999   "Set the global equivalents of the buffer-local variables.
3000 They are set to the latest values they had.  These reflect the summary
3001 buffer that was in action when the last article was fetched."
3002   (when (eq major-mode 'gnus-summary-mode)
3003     (setq gnus-summary-buffer (current-buffer))
3004     (let ((name gnus-newsgroup-name)
3005           (marked gnus-newsgroup-marked)
3006           (spam gnus-newsgroup-spam-marked)
3007           (unread gnus-newsgroup-unreads)
3008           (headers gnus-current-headers)
3009           (data gnus-newsgroup-data)
3010           (summary gnus-summary-buffer)
3011           (article-buffer gnus-article-buffer)
3012           (original gnus-original-article-buffer)
3013           (gac gnus-article-current)
3014           (reffed gnus-reffed-article-number)
3015           (score-file gnus-current-score-file)
3016           (default-charset gnus-newsgroup-charset)
3017           vlist)
3018       (let ((locals gnus-newsgroup-variables))
3019         (while locals
3020           (if (consp (car locals))
3021               (push (eval (caar locals)) vlist)
3022             (push (eval (car locals)) vlist))
3023           (setq locals (cdr locals)))
3024         (setq vlist (nreverse vlist)))
3025       (save-excursion
3026         (set-buffer gnus-group-buffer)
3027         (setq gnus-newsgroup-name name
3028               gnus-newsgroup-marked marked
3029               gnus-newsgroup-spam-marked spam
3030               gnus-newsgroup-unreads unread
3031               gnus-current-headers headers
3032               gnus-newsgroup-data data
3033               gnus-article-current gac
3034               gnus-summary-buffer summary
3035               gnus-article-buffer article-buffer
3036               gnus-original-article-buffer original
3037               gnus-reffed-article-number reffed
3038               gnus-current-score-file score-file
3039               gnus-newsgroup-charset default-charset)
3040         (let ((locals gnus-newsgroup-variables))
3041           (while locals
3042             (if (consp (car locals))
3043                 (set (caar locals) (pop vlist))
3044               (set (car locals) (pop vlist)))
3045             (setq locals (cdr locals))))
3046         ;; The article buffer also has local variables.
3047         (when (gnus-buffer-live-p gnus-article-buffer)
3048           (set-buffer gnus-article-buffer)
3049           (setq gnus-summary-buffer summary))))))
3050
3051 (defun gnus-summary-article-unread-p (article)
3052   "Say whether ARTICLE is unread or not."
3053   (memq article gnus-newsgroup-unreads))
3054
3055 (defun gnus-summary-first-article-p (&optional article)
3056   "Return whether ARTICLE is the first article in the buffer."
3057   (if (not (setq article (or article (gnus-summary-article-number))))
3058       nil
3059     (eq article (caar gnus-newsgroup-data))))
3060
3061 (defun gnus-summary-last-article-p (&optional article)
3062   "Return whether ARTICLE is the last article in the buffer."
3063   (if (not (setq article (or article (gnus-summary-article-number))))
3064       ;; All non-existent numbers are the last article.  :-)
3065       t
3066     (not (cdr (gnus-data-find-list article)))))
3067
3068 (defun gnus-make-thread-indent-array ()
3069   (let ((n 200))
3070     (unless (and gnus-thread-indent-array
3071                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3072       (setq gnus-thread-indent-array (make-vector 201 "")
3073             gnus-thread-indent-array-level gnus-thread-indent-level)
3074       (while (>= n 0)
3075         (aset gnus-thread-indent-array n
3076               (make-string (* n gnus-thread-indent-level) ? ))
3077         (setq n (1- n))))))
3078
3079 (defun gnus-update-summary-mark-positions ()
3080   "Compute where the summary marks are to go."
3081   (save-excursion
3082     (when (gnus-buffer-exists-p gnus-summary-buffer)
3083       (set-buffer gnus-summary-buffer))
3084     (let ((gnus-replied-mark 129)
3085           (gnus-score-below-mark 130)
3086           (gnus-score-over-mark 130)
3087           (gnus-download-mark 131)
3088           (spec gnus-summary-line-format-spec)
3089           gnus-visual pos)
3090       (save-excursion
3091         (gnus-set-work-buffer)
3092         (let ((gnus-summary-line-format-spec spec)
3093               (gnus-newsgroup-downloadable '((0 . t))))
3094           (gnus-summary-insert-line
3095            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
3096            0 nil 128 t nil "" nil 1)
3097           (goto-char (point-min))
3098           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3099                                              (- (point) (point-min) 1)))))
3100           (goto-char (point-min))
3101           (push (cons 'replied (and (search-forward "\201" nil t)
3102                                     (- (point) (point-min) 1)))
3103                 pos)
3104           (goto-char (point-min))
3105           (push (cons 'score (and (search-forward "\202" nil t)
3106                                   (- (point) (point-min) 1)))
3107                 pos)
3108           (goto-char (point-min))
3109           (push (cons 'download
3110                       (and (search-forward "\203" nil t)
3111                            (- (point) (point-min) 1)))
3112                 pos)))
3113       (setq gnus-summary-mark-positions pos))))
3114
3115 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3116   "Insert a dummy root in the summary buffer."
3117   (beginning-of-line)
3118   (gnus-add-text-properties
3119    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3120    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3121
3122 (defun gnus-summary-extract-address-component (from)
3123   (or (car (funcall gnus-extract-address-components from))
3124       from))
3125
3126 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3127   (let ((mail-parse-charset gnus-newsgroup-charset)
3128         ; Is it really necessary to do this next part for each summary line?
3129         ; Luckily, doesn't seem to slow things down much.
3130         (mail-parse-ignored-charsets
3131          (save-excursion (set-buffer gnus-summary-buffer)
3132                          gnus-newsgroup-ignored-charsets)))
3133     (or
3134      (and gnus-ignored-from-addresses
3135           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3136           (let ((extra-headers (mail-header-extra header))
3137                 to
3138                 newsgroups)
3139             (cond
3140              ((setq to (cdr (assq 'To extra-headers)))
3141               (concat "-> "
3142                       (inline
3143                         (gnus-summary-extract-address-component
3144                          (funcall gnus-decode-encoded-word-function to)))))
3145              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3146               (concat "=> " newsgroups)))))
3147      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3148
3149 (defun gnus-summary-insert-line (gnus-tmp-header
3150                                  gnus-tmp-level gnus-tmp-current
3151                                  gnus-tmp-unread gnus-tmp-replied
3152                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3153                                  &optional gnus-tmp-dummy gnus-tmp-score
3154                                  gnus-tmp-process)
3155   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3156          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3157          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3158          (gnus-tmp-score-char
3159           (if (or (null gnus-summary-default-score)
3160                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3161                       gnus-summary-zcore-fuzz))
3162               ?                         ;Whitespace
3163             (if (< gnus-tmp-score gnus-summary-default-score)
3164                 gnus-score-below-mark gnus-score-over-mark)))
3165          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3166          (gnus-tmp-replied
3167           (cond (gnus-tmp-process gnus-process-mark)
3168                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3169                  gnus-cached-mark)
3170                 (gnus-tmp-replied gnus-replied-mark)
3171                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3172                  gnus-forwarded-mark)
3173                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3174                  gnus-saved-mark)
3175                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3176                  gnus-recent-mark)
3177                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3178                  gnus-unseen-mark)
3179                 (t gnus-no-mark)))
3180          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3181          (gnus-tmp-name
3182           (cond
3183            ((string-match "<[^>]+> *$" gnus-tmp-from)
3184             (let ((beg (match-beginning 0)))
3185               (or (and (string-match "^\".+\"" gnus-tmp-from)
3186                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3187                   (substring gnus-tmp-from 0 beg))))
3188            ((string-match "(.+)" gnus-tmp-from)
3189             (substring gnus-tmp-from
3190                        (1+ (match-beginning 0)) (1- (match-end 0))))
3191            (t gnus-tmp-from)))
3192          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3193          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3194          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3195          (buffer-read-only nil))
3196     (when (string= gnus-tmp-name "")
3197       (setq gnus-tmp-name gnus-tmp-from))
3198     (unless (numberp gnus-tmp-lines)
3199       (setq gnus-tmp-lines -1))
3200     (if (= gnus-tmp-lines -1)
3201         (setq gnus-tmp-lines "?")
3202       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3203     (gnus-put-text-property
3204      (point)
3205      (progn (eval gnus-summary-line-format-spec) (point))
3206      'gnus-number gnus-tmp-number)
3207     (when (gnus-visual-p 'summary-highlight 'highlight)
3208       (forward-line -1)
3209       (gnus-run-hooks 'gnus-summary-update-hook)
3210       (forward-line 1))))
3211
3212 (defun gnus-summary-update-line (&optional dont-update)
3213   "Update summary line after change."
3214   (when (and gnus-summary-default-score
3215              (not gnus-summary-inhibit-highlight))
3216     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3217            (article (gnus-summary-article-number))
3218            (score (gnus-summary-article-score article)))
3219       (unless dont-update
3220         (if (and gnus-summary-mark-below
3221                  (< (gnus-summary-article-score)
3222                     gnus-summary-mark-below))
3223             ;; This article has a low score, so we mark it as read.
3224             (when (memq article gnus-newsgroup-unreads)
3225               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3226           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3227             ;; This article was previously marked as read on account
3228             ;; of a low score, but now it has risen, so we mark it as
3229             ;; unread.
3230             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3231         (gnus-summary-update-mark
3232          (if (or (null gnus-summary-default-score)
3233                  (<= (abs (- score gnus-summary-default-score))
3234                      gnus-summary-zcore-fuzz))
3235              ?                          ;Whitespace
3236            (if (< score gnus-summary-default-score)
3237                gnus-score-below-mark gnus-score-over-mark))
3238          'score))
3239       ;; Do visual highlighting.
3240       (when (gnus-visual-p 'summary-highlight 'highlight)
3241         (gnus-run-hooks 'gnus-summary-update-hook)))))
3242
3243 (defvar gnus-tmp-new-adopts nil)
3244
3245 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3246   "Return the number of articles in THREAD.
3247 This may be 0 in some cases -- if none of the articles in
3248 the thread are to be displayed."
3249   (let* ((number
3250          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3251           (cond
3252            ((not (listp thread))
3253             1)
3254            ((and (consp thread) (cdr thread))
3255             (apply
3256              '+ 1 (mapcar
3257                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3258            ((null thread)
3259             1)
3260            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3261             1)
3262            (t 0))))
3263     (when (and level (zerop level) gnus-tmp-new-adopts)
3264       (incf number
3265             (apply '+ (mapcar
3266                        'gnus-summary-number-of-articles-in-thread
3267                        gnus-tmp-new-adopts))))
3268     (if char
3269         (if (> number 1) gnus-not-empty-thread-mark
3270           gnus-empty-thread-mark)
3271       number)))
3272
3273 (defsubst gnus-summary-line-message-size (head)
3274   "Return pretty-printed version of message size.
3275 This function is intended to be used in
3276 `gnus-summary-line-format-alist', which see."
3277   (let ((c (or (mail-header-chars head) -1)))
3278     (cond ((< c 0) "n/a")               ; chars not available
3279           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3280           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3281           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3282           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3283
3284
3285 (defun gnus-summary-set-local-parameters (group)
3286   "Go through the local params of GROUP and set all variable specs in that list."
3287   (let ((params (gnus-group-find-parameter group))
3288         (vars '(quit-config))           ; Ignore quit-config.
3289         elem)
3290     (while params
3291       (setq elem (car params)
3292             params (cdr params))
3293       (and (consp elem)                 ; Has to be a cons.
3294            (consp (cdr elem))           ; The cdr has to be a list.
3295            (symbolp (car elem))         ; Has to be a symbol in there.
3296            (not (memq (car elem) vars))
3297            (ignore-errors               ; So we set it.
3298              (push (car elem) vars)
3299              (make-local-variable (car elem))
3300              (set (car elem) (eval (nth 1 elem))))))))
3301
3302 (defun gnus-summary-read-group (group &optional show-all no-article
3303                                       kill-buffer no-display backward
3304                                       select-articles)
3305   "Start reading news in newsgroup GROUP.
3306 If SHOW-ALL is non-nil, already read articles are also listed.
3307 If NO-ARTICLE is non-nil, no article is selected initially.
3308 If NO-DISPLAY, don't generate a summary buffer."
3309   (let (result)
3310     (while (and group
3311                 (null (setq result
3312                             (let ((gnus-auto-select-next nil))
3313                               (or (gnus-summary-read-group-1
3314                                    group show-all no-article
3315                                    kill-buffer no-display
3316                                    select-articles)
3317                                   (setq show-all nil
3318                                         select-articles nil)))))
3319                 (eq gnus-auto-select-next 'quietly))
3320       (set-buffer gnus-group-buffer)
3321       ;; The entry function called above goes to the next
3322       ;; group automatically, so we go two groups back
3323       ;; if we are searching for the previous group.
3324       (when backward
3325         (gnus-group-prev-unread-group 2))
3326       (if (not (equal group (gnus-group-group-name)))
3327           (setq group (gnus-group-group-name))
3328         (setq group nil)))
3329     result))
3330
3331 (defun gnus-summary-read-group-1 (group show-all no-article
3332                                         kill-buffer no-display
3333                                         &optional select-articles)
3334   ;; Killed foreign groups can't be entered.
3335   ;;  (when (and (not (gnus-group-native-p group))
3336   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3337   ;;    (error "Dead non-native groups can't be entered"))
3338   (gnus-message 5 "Retrieving newsgroup: %s..."
3339                 (gnus-group-decoded-name group))
3340   (let* ((new-group (gnus-summary-setup-buffer group))
3341          (quit-config (gnus-group-quit-config group))
3342          (did-select (and new-group (gnus-select-newsgroup
3343                                      group show-all select-articles))))
3344     (cond
3345      ;; This summary buffer exists already, so we just select it.
3346      ((not new-group)
3347       (gnus-set-global-variables)
3348       (when kill-buffer
3349         (gnus-kill-or-deaden-summary kill-buffer))
3350       (gnus-configure-windows 'summary 'force)
3351       (gnus-set-mode-line 'summary)
3352       (gnus-summary-position-point)
3353       (message "")
3354       t)
3355      ;; We couldn't select this group.
3356      ((null did-select)
3357       (when (and (eq major-mode 'gnus-summary-mode)
3358                  (not (equal (current-buffer) kill-buffer)))
3359         (kill-buffer (current-buffer))
3360         (if (not quit-config)
3361             (progn
3362               ;; Update the info -- marks might need to be removed,
3363               ;; for instance.
3364               (gnus-summary-update-info)
3365               (set-buffer gnus-group-buffer)
3366               (gnus-group-jump-to-group group)
3367               (gnus-group-next-unread-group 1))
3368           (gnus-handle-ephemeral-exit quit-config)))
3369       (let ((grpinfo (gnus-get-info group)))
3370         (if (null (gnus-info-read grpinfo))
3371             (gnus-message 3 "Group %s contains no messages"
3372                           (gnus-group-decoded-name group))
3373           (gnus-message 3 "Can't select group")))
3374       nil)
3375      ;; The user did a `C-g' while prompting for number of articles,
3376      ;; so we exit this group.
3377      ((eq did-select 'quit)
3378       (and (eq major-mode 'gnus-summary-mode)
3379            (not (equal (current-buffer) kill-buffer))
3380            (kill-buffer (current-buffer)))
3381       (when kill-buffer
3382         (gnus-kill-or-deaden-summary kill-buffer))
3383       (if (not quit-config)
3384           (progn
3385             (set-buffer gnus-group-buffer)
3386             (gnus-group-jump-to-group group)
3387             (gnus-group-next-unread-group 1)
3388             (gnus-configure-windows 'group 'force))
3389         (gnus-handle-ephemeral-exit quit-config))
3390       ;; Finally signal the quit.
3391       (signal 'quit nil))
3392      ;; The group was successfully selected.
3393      (t
3394       (gnus-set-global-variables)
3395       ;; Save the active value in effect when the group was entered.
3396       (setq gnus-newsgroup-active
3397             (gnus-copy-sequence
3398              (gnus-active gnus-newsgroup-name)))
3399       ;; You can change the summary buffer in some way with this hook.
3400       (gnus-run-hooks 'gnus-select-group-hook)
3401       (gnus-update-format-specifications
3402        nil 'summary 'summary-mode 'summary-dummy)
3403       (gnus-update-summary-mark-positions)
3404       ;; Do score processing.
3405       (when gnus-use-scoring
3406         (gnus-possibly-score-headers))
3407       ;; Check whether to fill in the gaps in the threads.
3408       (when gnus-build-sparse-threads
3409         (gnus-build-sparse-threads))
3410       ;; Find the initial limit.
3411       (if gnus-show-threads
3412           (if show-all
3413               (let ((gnus-newsgroup-dormant nil))
3414                 (gnus-summary-initial-limit show-all))
3415             (gnus-summary-initial-limit show-all))
3416         ;; When unthreaded, all articles are always shown.
3417         (setq gnus-newsgroup-limit
3418               (mapcar
3419                (lambda (header) (mail-header-number header))
3420                gnus-newsgroup-headers)))
3421       ;; Generate the summary buffer.
3422       (unless no-display
3423         (gnus-summary-prepare))
3424       (when gnus-use-trees
3425         (gnus-tree-open group)
3426         (setq gnus-summary-highlight-line-function
3427               'gnus-tree-highlight-article))
3428       ;; If the summary buffer is empty, but there are some low-scored
3429       ;; articles or some excluded dormants, we include these in the
3430       ;; buffer.
3431       (when (and (zerop (buffer-size))
3432                  (not no-display))
3433         (cond (gnus-newsgroup-dormant
3434                (gnus-summary-limit-include-dormant))
3435               ((and gnus-newsgroup-scored show-all)
3436                (gnus-summary-limit-include-expunged t))))
3437       ;; Function `gnus-apply-kill-file' must be called in this hook.
3438       (gnus-run-hooks 'gnus-apply-kill-hook)
3439       (if (and (zerop (buffer-size))
3440                (not no-display))
3441           (progn
3442             ;; This newsgroup is empty.
3443             (gnus-summary-catchup-and-exit nil t)
3444             (gnus-message 6 "No unread news")
3445             (when kill-buffer
3446               (gnus-kill-or-deaden-summary kill-buffer))
3447             ;; Return nil from this function.
3448             nil)
3449         ;; Hide conversation thread subtrees.  We cannot do this in
3450         ;; gnus-summary-prepare-hook since kill processing may not
3451         ;; work with hidden articles.
3452         (gnus-summary-maybe-hide-threads)
3453         (when kill-buffer
3454           (gnus-kill-or-deaden-summary kill-buffer))
3455         (gnus-summary-auto-select-subject)
3456         ;; Show first unread article if requested.
3457         (if (and (not no-article)
3458                  (not no-display)
3459                  gnus-newsgroup-unreads
3460                  gnus-auto-select-first)
3461             (progn
3462               (gnus-configure-windows 'summary)
3463               (let ((art (gnus-summary-article-number)))
3464                 (unless (or (memq art gnus-newsgroup-undownloaded)
3465                             (memq art gnus-newsgroup-downloadable))
3466                   (gnus-summary-goto-article art))))
3467           ;; Don't select any articles.
3468           (gnus-summary-position-point)
3469           (gnus-configure-windows 'summary 'force)
3470           (gnus-set-mode-line 'summary))
3471         (when (get-buffer-window gnus-group-buffer t)
3472           ;; Gotta use windows, because recenter does weird stuff if
3473           ;; the current buffer ain't the displayed window.
3474           (let ((owin (selected-window)))
3475             (select-window (get-buffer-window gnus-group-buffer t))
3476             (when (gnus-group-goto-group group)
3477               (recenter))
3478             (select-window owin)))
3479         ;; Mark this buffer as "prepared".
3480         (setq gnus-newsgroup-prepared t)
3481         (gnus-run-hooks 'gnus-summary-prepared-hook)
3482         t)))))
3483
3484 (defun gnus-summary-auto-select-subject ()
3485   "Select the subject line on initial group entry."
3486   (goto-char (point-min))
3487   (cond
3488    ((eq gnus-auto-select-subject 'best)
3489     (gnus-summary-best-unread-subject))
3490    ((eq gnus-auto-select-subject 'unread)
3491     (gnus-summary-first-unread-subject))
3492    ((eq gnus-auto-select-subject 'unseen)
3493     (gnus-summary-first-unseen-subject))
3494    ((eq gnus-auto-select-subject 'unseen-or-unread)
3495     (gnus-summary-first-unseen-or-unread-subject))
3496    ((eq gnus-auto-select-subject 'first)
3497     ;; Do nothing.
3498     )
3499    ((gnus-functionp gnus-auto-select-subject)
3500     (funcall gnus-auto-select-subject))))
3501
3502 (defun gnus-summary-prepare ()
3503   "Generate the summary buffer."
3504   (interactive)
3505   (let ((buffer-read-only nil))
3506     (erase-buffer)
3507     (setq gnus-newsgroup-data nil
3508           gnus-newsgroup-data-reverse nil)
3509     (gnus-run-hooks 'gnus-summary-generate-hook)
3510     ;; Generate the buffer, either with threads or without.
3511     (when gnus-newsgroup-headers
3512       (gnus-summary-prepare-threads
3513        (if gnus-show-threads
3514            (gnus-sort-gathered-threads
3515             (funcall gnus-summary-thread-gathering-function
3516                      (gnus-sort-threads
3517                       (gnus-cut-threads (gnus-make-threads)))))
3518          ;; Unthreaded display.
3519          (gnus-sort-articles gnus-newsgroup-headers))))
3520     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3521     ;; Call hooks for modifying summary buffer.
3522     (goto-char (point-min))
3523     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3524
3525 (defsubst gnus-general-simplify-subject (subject)
3526   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3527   (setq subject
3528         (cond
3529          ;; Truncate the subject.
3530          (gnus-simplify-subject-functions
3531           (gnus-map-function gnus-simplify-subject-functions subject))
3532          ((numberp gnus-summary-gather-subject-limit)
3533           (setq subject (gnus-simplify-subject-re subject))
3534           (if (> (length subject) gnus-summary-gather-subject-limit)
3535               (substring subject 0 gnus-summary-gather-subject-limit)
3536             subject))
3537          ;; Fuzzily simplify it.
3538          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3539           (gnus-simplify-subject-fuzzy subject))
3540          ;; Just remove the leading "Re:".
3541          (t
3542           (gnus-simplify-subject-re subject))))
3543
3544   (if (and gnus-summary-gather-exclude-subject
3545            (string-match gnus-summary-gather-exclude-subject subject))
3546       nil                         ; This article shouldn't be gathered
3547     subject))
3548
3549 (defun gnus-summary-simplify-subject-query ()
3550   "Query where the respool algorithm would put this article."
3551   (interactive)
3552   (gnus-summary-select-article)
3553   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3554
3555 (defun gnus-gather-threads-by-subject (threads)
3556   "Gather threads by looking at Subject headers."
3557   (if (not gnus-summary-make-false-root)
3558       threads
3559     (let ((hashtb (gnus-make-hashtable 1024))
3560           (prev threads)
3561           (result threads)
3562           subject hthread whole-subject)
3563       (while threads
3564         (setq subject (gnus-general-simplify-subject
3565                        (setq whole-subject (mail-header-subject
3566                                             (caar threads)))))
3567         (when subject
3568           (if (setq hthread (gnus-gethash subject hashtb))
3569               (progn
3570                 ;; We enter a dummy root into the thread, if we
3571                 ;; haven't done that already.
3572                 (unless (stringp (caar hthread))
3573                   (setcar hthread (list whole-subject (car hthread))))
3574                 ;; We add this new gathered thread to this gathered
3575                 ;; thread.
3576                 (setcdr (car hthread)
3577                         (nconc (cdar hthread) (list (car threads))))
3578                 ;; Remove it from the list of threads.
3579                 (setcdr prev (cdr threads))
3580                 (setq threads prev))
3581             ;; Enter this thread into the hash table.
3582             (gnus-sethash subject threads hashtb)))
3583         (setq prev threads)
3584         (setq threads (cdr threads)))
3585       result)))
3586
3587 (defun gnus-gather-threads-by-references (threads)
3588   "Gather threads by looking at References headers."
3589   (let ((idhashtb (gnus-make-hashtable 1024))
3590         (thhashtb (gnus-make-hashtable 1024))
3591         (prev threads)
3592         (result threads)
3593         ids references id gthread gid entered ref)
3594     (while threads
3595       (when (setq references (mail-header-references (caar threads)))
3596         (setq id (mail-header-id (caar threads))
3597               ids (inline (gnus-split-references references))
3598               entered nil)
3599         (while (setq ref (pop ids))
3600           (setq ids (delete ref ids))
3601           (if (not (setq gid (gnus-gethash ref idhashtb)))
3602               (progn
3603                 (gnus-sethash ref id idhashtb)
3604                 (gnus-sethash id threads thhashtb))
3605             (setq gthread (gnus-gethash gid thhashtb))
3606             (unless entered
3607               ;; We enter a dummy root into the thread, if we
3608               ;; haven't done that already.
3609               (unless (stringp (caar gthread))
3610                 (setcar gthread (list (mail-header-subject (caar gthread))
3611                                       (car gthread))))
3612               ;; We add this new gathered thread to this gathered
3613               ;; thread.
3614               (setcdr (car gthread)
3615                       (nconc (cdar gthread) (list (car threads)))))
3616             ;; Add it into the thread hash table.
3617             (gnus-sethash id gthread thhashtb)
3618             (setq entered t)
3619             ;; Remove it from the list of threads.
3620             (setcdr prev (cdr threads))
3621             (setq threads prev))))
3622       (setq prev threads)
3623       (setq threads (cdr threads)))
3624     result))
3625
3626 (defun gnus-sort-gathered-threads (threads)
3627   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3628   (let ((result threads))
3629     (while threads
3630       (when (stringp (caar threads))
3631         (setcdr (car threads)
3632                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3633       (setq threads (cdr threads)))
3634     result))
3635
3636 (defun gnus-thread-loop-p (root thread)
3637   "Say whether ROOT is in THREAD."
3638   (let ((stack (list thread))
3639         (infloop 0)
3640         th)
3641     (while (setq thread (pop stack))
3642       (setq th (cdr thread))
3643       (while (and th
3644                   (not (eq (caar th) root)))
3645         (pop th))
3646       (if th
3647           ;; We have found a loop.
3648           (let (ref-dep)
3649             (setcdr thread (delq (car th) (cdr thread)))
3650             (if (boundp (setq ref-dep (intern "none"
3651                                               gnus-newsgroup-dependencies)))
3652                 (setcdr (symbol-value ref-dep)
3653                         (nconc (cdr (symbol-value ref-dep))
3654                                (list (car th))))
3655               (set ref-dep (list nil (car th))))
3656             (setq infloop 1
3657                   stack nil))
3658         ;; Push all the subthreads onto the stack.
3659         (push (cdr thread) stack)))
3660     infloop))
3661
3662 (defun gnus-make-threads ()
3663   "Go through the dependency hashtb and find the roots.  Return all threads."
3664   (let (threads)
3665     (while (catch 'infloop
3666              (mapatoms
3667               (lambda (refs)
3668                 ;; Deal with self-referencing References loops.
3669                 (when (and (car (symbol-value refs))
3670                            (not (zerop
3671                                  (apply
3672                                   '+
3673                                   (mapcar
3674                                    (lambda (thread)
3675                                      (gnus-thread-loop-p
3676                                       (car (symbol-value refs)) thread))
3677                                    (cdr (symbol-value refs)))))))
3678                   (setq threads nil)
3679                   (throw 'infloop t))
3680                 (unless (car (symbol-value refs))
3681                   ;; These threads do not refer back to any other
3682                   ;; articles, so they're roots.
3683                   (setq threads (append (cdr (symbol-value refs)) threads))))
3684               gnus-newsgroup-dependencies)))
3685     threads))
3686
3687 ;; Build the thread tree.
3688 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3689   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3690
3691 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3692 if it was already present.
3693
3694 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3695 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3696 Message-IDs will be renamed to a unique Message-ID before being
3697 entered.
3698
3699 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3700   (let* ((id (mail-header-id header))
3701          (id-dep (and id (intern id dependencies)))
3702          parent-id ref ref-dep ref-header replaced)
3703     ;; Enter this `header' in the `dependencies' table.
3704     (cond
3705      ((not id-dep)
3706       (setq header nil))
3707      ;; The first two cases do the normal part: enter a new `header'
3708      ;; in the `dependencies' table.
3709      ((not (boundp id-dep))
3710       (set id-dep (list header)))
3711      ((null (car (symbol-value id-dep)))
3712       (setcar (symbol-value id-dep) header))
3713
3714      ;; From here the `header' was already present in the
3715      ;; `dependencies' table.
3716      (force-new
3717       ;; Overrides an existing entry;
3718       ;; just set the header part of the entry.
3719       (setcar (symbol-value id-dep) header)
3720       (setq replaced t))
3721
3722      ;; Renames the existing `header' to a unique Message-ID.
3723      ((not gnus-summary-ignore-duplicates)
3724       ;; An article with this Message-ID has already been seen.
3725       ;; We rename the Message-ID.
3726       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3727            (list header))
3728       (mail-header-set-id header id))
3729
3730      ;; The last case ignores an existing entry, except it adds any
3731      ;; additional Xrefs (in case the two articles came from different
3732      ;; servers.
3733      ;; Also sets `header' to `nil' meaning that the `dependencies'
3734      ;; table was *not* modified.
3735      (t
3736       (mail-header-set-xref
3737        (car (symbol-value id-dep))
3738        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3739                    "")
3740                (or (mail-header-xref header) "")))
3741       (setq header nil)))
3742
3743     (when (and header (not replaced))
3744       ;; First check that we are not creating a References loop.
3745       (setq parent-id (gnus-parent-id (mail-header-references header)))
3746       (setq ref parent-id)
3747       (while (and ref
3748                   (setq ref-dep (intern-soft ref dependencies))
3749                   (boundp ref-dep)
3750                   (setq ref-header (car (symbol-value ref-dep))))
3751         (if (string= id ref)
3752             ;; Yuk!  This is a reference loop.  Make the article be a
3753             ;; root article.
3754             (progn
3755               (mail-header-set-references (car (symbol-value id-dep)) "none")
3756               (setq ref nil)
3757               (setq parent-id nil))
3758           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3759       (setq ref-dep (intern (or parent-id "none") dependencies))
3760       (if (boundp ref-dep)
3761           (setcdr (symbol-value ref-dep)
3762                   (nconc (cdr (symbol-value ref-dep))
3763                          (list (symbol-value id-dep))))
3764         (set ref-dep (list nil (symbol-value id-dep)))))
3765     header))
3766
3767 (defun gnus-extract-message-id-from-in-reply-to (string)
3768   (if (string-match "<[^>]+>" string)
3769       (substring string (match-beginning 0) (match-end 0))
3770     nil))
3771
3772 (defun gnus-build-sparse-threads ()
3773   (let ((headers gnus-newsgroup-headers)
3774         (mail-parse-charset gnus-newsgroup-charset)
3775         (gnus-summary-ignore-duplicates t)
3776         header references generation relations
3777         subject child end new-child date)
3778     ;; First we create an alist of generations/relations, where
3779     ;; generations is how much we trust the relation, and the relation
3780     ;; is parent/child.
3781     (gnus-message 7 "Making sparse threads...")
3782     (save-excursion
3783       (nnheader-set-temp-buffer " *gnus sparse threads*")
3784       (while (setq header (pop headers))
3785         (when (and (setq references (mail-header-references header))
3786                    (not (string= references "")))
3787           (insert references)
3788           (setq child (mail-header-id header)
3789                 subject (mail-header-subject header)
3790                 date (mail-header-date header)
3791                 generation 0)
3792           (while (search-backward ">" nil t)
3793             (setq end (1+ (point)))
3794             (when (search-backward "<" nil t)
3795               (setq new-child (buffer-substring (point) end))
3796               (push (list (incf generation)
3797                           child (setq child new-child)
3798                           subject date)
3799                     relations)))
3800           (when child
3801             (push (list (1+ generation) child nil subject) relations))
3802           (erase-buffer)))
3803       (kill-buffer (current-buffer)))
3804     ;; Sort over trustworthiness.
3805     (mapcar
3806      (lambda (relation)
3807        (when (gnus-dependencies-add-header
3808               (make-full-mail-header
3809                gnus-reffed-article-number
3810                (nth 3 relation) "" (or (nth 4 relation) "")
3811                (nth 1 relation)
3812                (or (nth 2 relation) "") 0 0 "")
3813               gnus-newsgroup-dependencies nil)
3814          (push gnus-reffed-article-number gnus-newsgroup-limit)
3815          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3816          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3817                gnus-newsgroup-reads)
3818          (decf gnus-reffed-article-number)))
3819      (sort relations 'car-less-than-car))
3820     (gnus-message 7 "Making sparse threads...done")))
3821
3822 (defun gnus-build-old-threads ()
3823   ;; Look at all the articles that refer back to old articles, and
3824   ;; fetch the headers for the articles that aren't there.  This will
3825   ;; build complete threads - if the roots haven't been expired by the
3826   ;; server, that is.
3827   (let ((mail-parse-charset gnus-newsgroup-charset)
3828         id heads)
3829     (mapatoms
3830      (lambda (refs)
3831        (when (not (car (symbol-value refs)))
3832          (setq heads (cdr (symbol-value refs)))
3833          (while heads
3834            (if (memq (mail-header-number (caar heads))
3835                      gnus-newsgroup-dormant)
3836                (setq heads (cdr heads))
3837              (setq id (symbol-name refs))
3838              (while (and (setq id (gnus-build-get-header id))
3839                          (not (car (gnus-id-to-thread id)))))
3840              (setq heads nil)))))
3841      gnus-newsgroup-dependencies)))
3842
3843 ;; This function has to be called with point after the article number
3844 ;; on the beginning of the line.
3845 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3846   (let ((eol (gnus-point-at-eol))
3847         (buffer (current-buffer))
3848         header references in-reply-to)
3849
3850     ;; overview: [num subject from date id refs chars lines misc]
3851     (unwind-protect
3852         (let (x)
3853           (narrow-to-region (point) eol)
3854           (unless (eobp)
3855             (forward-char))
3856
3857           (setq header
3858                 (make-full-mail-header
3859                  number                 ; number
3860                  (condition-case ()     ; subject
3861                      (funcall gnus-decode-encoded-word-function
3862                               (setq x (nnheader-nov-field)))
3863                    (error x))
3864                  (condition-case ()     ; from
3865                      (funcall gnus-decode-encoded-word-function
3866                               (setq x (nnheader-nov-field)))
3867                    (error x))
3868                  (nnheader-nov-field)   ; date
3869                  (nnheader-nov-read-message-id) ; id
3870                  (setq references (nnheader-nov-field)) ; refs
3871                  (nnheader-nov-read-integer) ; chars
3872                  (nnheader-nov-read-integer) ; lines
3873                  (unless (eobp)
3874                    (if (looking-at "Xref: ")
3875                        (goto-char (match-end 0)))
3876                    (nnheader-nov-field)) ; Xref
3877                  (nnheader-nov-parse-extra)))) ; extra
3878
3879       (widen))
3880
3881     (when (and (string= references "")
3882                (setq in-reply-to (mail-header-extra header))
3883                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3884       (mail-header-set-references
3885        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3886
3887     (when gnus-alter-header-function
3888       (funcall gnus-alter-header-function header))
3889     (gnus-dependencies-add-header header dependencies force-new)))
3890
3891 (defun gnus-build-get-header (id)
3892   "Look through the buffer of NOV lines and find the header to ID.
3893 Enter this line into the dependencies hash table, and return
3894 the id of the parent article (if any)."
3895   (let ((deps gnus-newsgroup-dependencies)
3896         found header)
3897     (prog1
3898         (save-excursion
3899           (set-buffer nntp-server-buffer)
3900           (let ((case-fold-search nil))
3901             (goto-char (point-min))
3902             (while (and (not found)
3903                         (search-forward id nil t))
3904               (beginning-of-line)
3905               (setq found (looking-at
3906                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3907                                    (regexp-quote id))))
3908               (or found (beginning-of-line 2)))
3909             (when found
3910               (beginning-of-line)
3911               (and
3912                (setq header (gnus-nov-parse-line
3913                              (read (current-buffer)) deps))
3914                (gnus-parent-id (mail-header-references header))))))
3915       (when header
3916         (let ((number (mail-header-number header)))
3917           (push number gnus-newsgroup-limit)
3918           (push header gnus-newsgroup-headers)
3919           (if (memq number gnus-newsgroup-unselected)
3920               (progn
3921                 (setq gnus-newsgroup-unreads
3922                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3923                                                number))
3924                 (setq gnus-newsgroup-unselected
3925                       (delq number gnus-newsgroup-unselected)))
3926             (push number gnus-newsgroup-ancient)))))))
3927
3928 (defun gnus-build-all-threads ()
3929   "Read all the headers."
3930   (let ((gnus-summary-ignore-duplicates t)
3931         (mail-parse-charset gnus-newsgroup-charset)
3932         (dependencies gnus-newsgroup-dependencies)
3933         header article)
3934     (save-excursion
3935       (set-buffer nntp-server-buffer)
3936       (let ((case-fold-search nil))
3937         (goto-char (point-min))
3938         (while (not (eobp))
3939           (ignore-errors
3940             (setq article (read (current-buffer))
3941                   header (gnus-nov-parse-line article dependencies)))
3942           (when header
3943             (save-excursion
3944               (set-buffer gnus-summary-buffer)
3945               (push header gnus-newsgroup-headers)
3946               (if (memq (setq article (mail-header-number header))
3947                         gnus-newsgroup-unselected)
3948                   (progn
3949                     (setq gnus-newsgroup-unreads
3950                           (gnus-add-to-sorted-list
3951                            gnus-newsgroup-unreads article))
3952                     (setq gnus-newsgroup-unselected
3953                           (delq article gnus-newsgroup-unselected)))
3954                 (push article gnus-newsgroup-ancient)))
3955             (forward-line 1)))))))
3956
3957 (defun gnus-summary-update-article-line (article header)
3958   "Update the line for ARTICLE using HEADERS."
3959   (let* ((id (mail-header-id header))
3960          (thread (gnus-id-to-thread id)))
3961     (unless thread
3962       (error "Article in no thread"))
3963     ;; Update the thread.
3964     (setcar thread header)
3965     (gnus-summary-goto-subject article)
3966     (let* ((datal (gnus-data-find-list article))
3967            (data (car datal))
3968            (length (when (cdr datal)
3969                      (- (gnus-data-pos data)
3970                         (gnus-data-pos (cadr datal)))))
3971            (buffer-read-only nil)
3972            (level (gnus-summary-thread-level)))
3973       (gnus-delete-line)
3974       (gnus-summary-insert-line
3975        header level nil (gnus-article-mark article)
3976        (memq article gnus-newsgroup-replied)
3977        (memq article gnus-newsgroup-expirable)
3978        ;; Only insert the Subject string when it's different
3979        ;; from the previous Subject string.
3980        (if (and
3981             gnus-show-threads
3982             (gnus-subject-equal
3983              (condition-case ()
3984                  (mail-header-subject
3985                   (gnus-data-header
3986                    (cadr
3987                     (gnus-data-find-list
3988                      article
3989                      (gnus-data-list t)))))
3990                ;; Error on the side of excessive subjects.
3991                (error ""))
3992              (mail-header-subject header)))
3993            ""
3994          (mail-header-subject header))
3995        nil (cdr (assq article gnus-newsgroup-scored))
3996        (memq article gnus-newsgroup-processable))
3997       (when length
3998         (gnus-data-update-list
3999          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
4000
4001 (defun gnus-summary-update-article (article &optional iheader)
4002   "Update ARTICLE in the summary buffer."
4003   (set-buffer gnus-summary-buffer)
4004   (let* ((header (gnus-summary-article-header article))
4005          (id (mail-header-id header))
4006          (data (gnus-data-find article))
4007          (thread (gnus-id-to-thread id))
4008          (references (mail-header-references header))
4009          (parent
4010           (gnus-id-to-thread
4011            (or (gnus-parent-id
4012                 (when (and references
4013                            (not (equal "" references)))
4014                   references))
4015                "none")))
4016          (buffer-read-only nil)
4017          (old (car thread)))
4018     (when thread
4019       (unless iheader
4020         (setcar thread nil)
4021         (when parent
4022           (delq thread parent)))
4023       (if (gnus-summary-insert-subject id header)
4024        ;; Set the (possibly) new article number in the data structure.
4025           (gnus-data-set-number data (gnus-id-to-article id))
4026         (setcar thread old)
4027         nil))))
4028
4029 (defun gnus-rebuild-thread (id &optional line)
4030   "Rebuild the thread containing ID.
4031 If LINE, insert the rebuilt thread starting on line LINE."
4032   (let ((buffer-read-only nil)
4033         old-pos current thread data)
4034     (if (not gnus-show-threads)
4035         (setq thread (list (car (gnus-id-to-thread id))))
4036       ;; Get the thread this article is part of.
4037       (setq thread (gnus-remove-thread id)))
4038     (setq old-pos (gnus-point-at-bol))
4039     (setq current (save-excursion
4040                     (and (re-search-backward "[\r\n]" nil t)
4041                          (gnus-summary-article-number))))
4042     ;; If this is a gathered thread, we have to go some re-gathering.
4043     (when (stringp (car thread))
4044       (let ((subject (car thread))
4045             roots thr)
4046         (setq thread (cdr thread))
4047         (while thread
4048           (unless (memq (setq thr (gnus-id-to-thread
4049                                    (gnus-root-id
4050                                     (mail-header-id (caar thread)))))
4051                         roots)
4052             (push thr roots))
4053           (setq thread (cdr thread)))
4054         ;; We now have all (unique) roots.
4055         (if (= (length roots) 1)
4056             ;; All the loose roots are now one solid root.
4057             (setq thread (car roots))
4058           (setq thread (cons subject (gnus-sort-threads roots))))))
4059     (let (threads)
4060       ;; We then insert this thread into the summary buffer.
4061       (when line
4062         (goto-char (point-min))
4063         (forward-line (1- line)))
4064       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4065         (if gnus-show-threads
4066             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4067           (gnus-summary-prepare-unthreaded thread))
4068         (setq data (nreverse gnus-newsgroup-data))
4069         (setq threads gnus-newsgroup-threads))
4070       ;; We splice the new data into the data structure.
4071       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4072       ;;!!! then we want to insert at the beginning of the buffer.
4073       ;;!!! That happens to be true with Gnus now, but that may
4074       ;;!!! change in the future.  Perhaps.
4075       (gnus-data-enter-list
4076        (if line nil current) data (- (point) old-pos))
4077       (setq gnus-newsgroup-threads
4078             (nconc threads gnus-newsgroup-threads))
4079       (gnus-data-compute-positions))))
4080
4081 (defun gnus-number-to-header (number)
4082   "Return the header for article NUMBER."
4083   (let ((headers gnus-newsgroup-headers))
4084     (while (and headers
4085                 (not (= number (mail-header-number (car headers)))))
4086       (pop headers))
4087     (when headers
4088       (car headers))))
4089
4090 (defun gnus-parent-headers (in-headers &optional generation)
4091   "Return the headers of the GENERATIONeth parent of HEADERS."
4092   (unless generation
4093     (setq generation 1))
4094   (let ((parent t)
4095         (headers in-headers)
4096         references)
4097     (while (and parent
4098                 (not (zerop generation))
4099                 (setq references (mail-header-references headers)))
4100       (setq headers (if (and references
4101                              (setq parent (gnus-parent-id references)))
4102                         (car (gnus-id-to-thread parent))
4103                       nil))
4104       (decf generation))
4105     (and (not (eq headers in-headers))
4106          headers)))
4107
4108 (defun gnus-id-to-thread (id)
4109   "Return the (sub-)thread where ID appears."
4110   (gnus-gethash id gnus-newsgroup-dependencies))
4111
4112 (defun gnus-id-to-article (id)
4113   "Return the article number of ID."
4114   (let ((thread (gnus-id-to-thread id)))
4115     (when (and thread
4116                (car thread))
4117       (mail-header-number (car thread)))))
4118
4119 (defun gnus-id-to-header (id)
4120   "Return the article headers of ID."
4121   (car (gnus-id-to-thread id)))
4122
4123 (defun gnus-article-displayed-root-p (article)
4124   "Say whether ARTICLE is a root(ish) article."
4125   (let ((level (gnus-summary-thread-level article))
4126         (refs (mail-header-references  (gnus-summary-article-header article)))
4127         particle)
4128     (cond
4129      ((null level) nil)
4130      ((zerop level) t)
4131      ((null refs) t)
4132      ((null (gnus-parent-id refs)) t)
4133      ((and (= 1 level)
4134            (null (setq particle (gnus-id-to-article
4135                                  (gnus-parent-id refs))))
4136            (null (gnus-summary-thread-level particle)))))))
4137
4138 (defun gnus-root-id (id)
4139   "Return the id of the root of the thread where ID appears."
4140   (let (last-id prev)
4141     (while (and id (setq prev (car (gnus-id-to-thread id))))
4142       (setq last-id id
4143             id (gnus-parent-id (mail-header-references prev))))
4144     last-id))
4145
4146 (defun gnus-articles-in-thread (thread)
4147   "Return the list of articles in THREAD."
4148   (cons (mail-header-number (car thread))
4149         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4150
4151 (defun gnus-remove-thread (id &optional dont-remove)
4152   "Remove the thread that has ID in it."
4153   (let (headers thread last-id)
4154     ;; First go up in this thread until we find the root.
4155     (setq last-id (gnus-root-id id)
4156           headers (message-flatten-list (gnus-id-to-thread last-id)))
4157     ;; We have now found the real root of this thread.  It might have
4158     ;; been gathered into some loose thread, so we have to search
4159     ;; through the threads to find the thread we wanted.
4160     (let ((threads gnus-newsgroup-threads)
4161           sub)
4162       (while threads
4163         (setq sub (car threads))
4164         (if (stringp (car sub))
4165             ;; This is a gathered thread, so we look at the roots
4166             ;; below it to find whether this article is in this
4167             ;; gathered root.
4168             (progn
4169               (setq sub (cdr sub))
4170               (while sub
4171                 (when (member (caar sub) headers)
4172                   (setq thread (car threads)
4173                         threads nil
4174                         sub nil))
4175                 (setq sub (cdr sub))))
4176           ;; It's an ordinary thread, so we check it.
4177           (when (eq (car sub) (car headers))
4178             (setq thread sub
4179                   threads nil)))
4180         (setq threads (cdr threads)))
4181       ;; If this article is in no thread, then it's a root.
4182       (if thread
4183           (unless dont-remove
4184             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4185         (setq thread (gnus-id-to-thread last-id)))
4186       (when thread
4187         (prog1
4188             thread                      ; We return this thread.
4189           (unless dont-remove
4190             (if (stringp (car thread))
4191                 (progn
4192                   ;; If we use dummy roots, then we have to remove the
4193                   ;; dummy root as well.
4194                   (when (eq gnus-summary-make-false-root 'dummy)
4195                     ;; We go to the dummy root by going to
4196                     ;; the first sub-"thread", and then one line up.
4197                     (gnus-summary-goto-article
4198                      (mail-header-number (caadr thread)))
4199                     (forward-line -1)
4200                     (gnus-delete-line)
4201                     (gnus-data-compute-positions))
4202                   (setq thread (cdr thread))
4203                   (while thread
4204                     (gnus-remove-thread-1 (car thread))
4205                     (setq thread (cdr thread))))
4206               (gnus-remove-thread-1 thread))))))))
4207
4208 (defun gnus-remove-thread-1 (thread)
4209   "Remove the thread THREAD recursively."
4210   (let ((number (mail-header-number (pop thread)))
4211         d)
4212     (setq thread (reverse thread))
4213     (while thread
4214       (gnus-remove-thread-1 (pop thread)))
4215     (when (setq d (gnus-data-find number))
4216       (goto-char (gnus-data-pos d))
4217       (gnus-summary-show-thread)
4218       (gnus-data-remove
4219        number
4220        (- (gnus-point-at-bol)
4221           (prog1
4222               (1+ (gnus-point-at-eol))
4223             (gnus-delete-line)))))))
4224
4225 (defun gnus-sort-threads-1 (threads func)
4226   (sort (mapcar (lambda (thread)
4227                   (cons (car thread)
4228                         (and (cdr thread)
4229                              (gnus-sort-threads-1 (cdr thread) func))))
4230                 threads) func))
4231
4232 (defun gnus-sort-threads (threads)
4233   "Sort THREADS."
4234   (if (not gnus-thread-sort-functions)
4235       threads
4236     (gnus-message 8 "Sorting threads...")
4237     (prog1
4238         (gnus-sort-threads-1
4239          threads
4240          (gnus-make-sort-function gnus-thread-sort-functions))
4241       (gnus-message 8 "Sorting threads...done"))))
4242
4243 (defun gnus-sort-articles (articles)
4244   "Sort ARTICLES."
4245   (when gnus-article-sort-functions
4246     (gnus-message 7 "Sorting articles...")
4247     (prog1
4248         (setq gnus-newsgroup-headers
4249               (sort articles (gnus-make-sort-function
4250                               gnus-article-sort-functions)))
4251       (gnus-message 7 "Sorting articles...done"))))
4252
4253 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4254 (defmacro gnus-thread-header (thread)
4255   "Return header of first article in THREAD.
4256 Note that THREAD must never, ever be anything else than a variable -
4257 using some other form will lead to serious barfage."
4258   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4259   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4260   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4261         (vector thread) 2))
4262
4263 (defsubst gnus-article-sort-by-number (h1 h2)
4264   "Sort articles by article number."
4265   (< (mail-header-number h1)
4266      (mail-header-number h2)))
4267
4268 (defun gnus-thread-sort-by-number (h1 h2)
4269   "Sort threads by root article number."
4270   (gnus-article-sort-by-number
4271    (gnus-thread-header h1) (gnus-thread-header h2)))
4272
4273 (defsubst gnus-article-sort-by-random (h1 h2)
4274   "Sort articles by article number."
4275   (zerop (random 2)))
4276
4277 (defun gnus-thread-sort-by-random (h1 h2)
4278   "Sort threads by root article number."
4279   (gnus-article-sort-by-random
4280    (gnus-thread-header h1) (gnus-thread-header h2)))
4281
4282 (defsubst gnus-article-sort-by-lines (h1 h2)
4283   "Sort articles by article Lines header."
4284   (< (mail-header-lines h1)
4285      (mail-header-lines h2)))
4286
4287 (defun gnus-thread-sort-by-lines (h1 h2)
4288   "Sort threads by root article Lines header."
4289   (gnus-article-sort-by-lines
4290    (gnus-thread-header h1) (gnus-thread-header h2)))
4291
4292 (defsubst gnus-article-sort-by-chars (h1 h2)
4293   "Sort articles by octet length."
4294   (< (mail-header-chars h1)
4295      (mail-header-chars h2)))
4296
4297 (defun gnus-thread-sort-by-chars (h1 h2)
4298   "Sort threads by root article octet length."
4299   (gnus-article-sort-by-chars
4300    (gnus-thread-header h1) (gnus-thread-header h2)))
4301
4302 (defsubst gnus-article-sort-by-author (h1 h2)
4303   "Sort articles by root author."
4304   (string-lessp
4305    (let ((extract (funcall
4306                    gnus-extract-address-components
4307                    (mail-header-from h1))))
4308      (or (car extract) (cadr extract) ""))
4309    (let ((extract (funcall
4310                    gnus-extract-address-components
4311                    (mail-header-from h2))))
4312      (or (car extract) (cadr extract) ""))))
4313
4314 (defun gnus-thread-sort-by-author (h1 h2)
4315   "Sort threads by root author."
4316   (gnus-article-sort-by-author
4317    (gnus-thread-header h1)  (gnus-thread-header h2)))
4318
4319 (defsubst gnus-article-sort-by-subject (h1 h2)
4320   "Sort articles by root subject."
4321   (string-lessp
4322    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4323    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4324
4325 (defun gnus-thread-sort-by-subject (h1 h2)
4326   "Sort threads by root subject."
4327   (gnus-article-sort-by-subject
4328    (gnus-thread-header h1) (gnus-thread-header h2)))
4329
4330 (defsubst gnus-article-sort-by-date (h1 h2)
4331   "Sort articles by root article date."
4332   (time-less-p
4333    (gnus-date-get-time (mail-header-date h1))
4334    (gnus-date-get-time (mail-header-date h2))))
4335
4336 (defun gnus-thread-sort-by-date (h1 h2)
4337   "Sort threads by root article date."
4338   (gnus-article-sort-by-date
4339    (gnus-thread-header h1) (gnus-thread-header h2)))
4340
4341 (defsubst gnus-article-sort-by-score (h1 h2)
4342   "Sort articles by root article score.
4343 Unscored articles will be counted as having a score of zero."
4344   (> (or (cdr (assq (mail-header-number h1)
4345                     gnus-newsgroup-scored))
4346          gnus-summary-default-score 0)
4347      (or (cdr (assq (mail-header-number h2)
4348                     gnus-newsgroup-scored))
4349          gnus-summary-default-score 0)))
4350
4351 (defun gnus-thread-sort-by-score (h1 h2)
4352   "Sort threads by root article score."
4353   (gnus-article-sort-by-score
4354    (gnus-thread-header h1) (gnus-thread-header h2)))
4355
4356 (defun gnus-thread-sort-by-total-score (h1 h2)
4357   "Sort threads by the sum of all scores in the thread.
4358 Unscored articles will be counted as having a score of zero."
4359   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4360
4361 (defun gnus-thread-total-score (thread)
4362   ;; This function find the total score of THREAD.
4363   (cond
4364    ((null thread)
4365     0)
4366    ((consp thread)
4367     (if (stringp (car thread))
4368         (apply gnus-thread-score-function 0
4369                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4370       (gnus-thread-total-score-1 thread)))
4371    (t
4372     (gnus-thread-total-score-1 (list thread)))))
4373
4374 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4375   "Sort threads such that the thread with the most recently arrived article comes first."
4376   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4377
4378 (defun gnus-thread-highest-number (thread)
4379   "Return the highest article number in THREAD."
4380   (apply 'max (mapcar (lambda (header)
4381                         (mail-header-number header))
4382                       (message-flatten-list thread))))
4383
4384 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4385   "Sort threads such that the thread with the most recently dated article comes first."
4386   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4387
4388 (defun gnus-thread-latest-date (thread)
4389   "Return the highest article date in THREAD."
4390   (let ((previous-time 0))
4391     (apply 'max (mapcar
4392                  (lambda (header)
4393                    (setq previous-time
4394                          (time-to-seconds
4395                           (mail-header-parse-date
4396                            (condition-case ()
4397                                (mail-header-date header)
4398                              (error previous-time))))))
4399                  (sort
4400                   (message-flatten-list thread)
4401                   (lambda (h1 h2)
4402                     (< (mail-header-number h1)
4403                        (mail-header-number h2))))))))
4404
4405 (defun gnus-thread-total-score-1 (root)
4406   ;; This function find the total score of the thread below ROOT.
4407   (setq root (car root))
4408   (apply gnus-thread-score-function
4409          (or (append
4410               (mapcar 'gnus-thread-total-score
4411                       (cdr (gnus-id-to-thread (mail-header-id root))))
4412               (when (> (mail-header-number root) 0)
4413                 (list (or (cdr (assq (mail-header-number root)
4414                                      gnus-newsgroup-scored))
4415                           gnus-summary-default-score 0))))
4416              (list gnus-summary-default-score)
4417              '(0))))
4418
4419 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4420 (defvar gnus-tmp-prev-subject nil)
4421 (defvar gnus-tmp-false-parent nil)
4422 (defvar gnus-tmp-root-expunged nil)
4423 (defvar gnus-tmp-dummy-line nil)
4424
4425 (eval-when-compile (defvar gnus-tmp-header))
4426 (defun gnus-extra-header (type &optional header)
4427   "Return the extra header of TYPE."
4428   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4429       ""))
4430
4431 (defvar gnus-tmp-thread-tree-header-string "")
4432
4433 (defcustom gnus-sum-thread-tree-root "> "
4434   "With %B spec, used for the root of a thread.
4435 If nil, use subject instead."
4436   :type 'string
4437   :group 'gnus-thread)
4438 (defcustom gnus-sum-thread-tree-single-indent ""
4439   "With %B spec, used for a thread with just one message.
4440 If nil, use subject instead."
4441   :type 'string
4442   :group 'gnus-thread)
4443 (defcustom gnus-sum-thread-tree-vertical "| "
4444   "With %B spec, used for drawing a vertical line."
4445   :type 'string
4446   :group 'gnus-thread)
4447 (defcustom gnus-sum-thread-tree-indent "  "
4448   "With %B spec, used for indenting."
4449   :type 'string
4450   :group 'gnus-thread)
4451 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4452   "With %B spec, used for a leaf with brothers."
4453   :type 'string
4454   :group 'gnus-thread)
4455 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4456   "With %B spec, used for a leaf without brothers."
4457   :type 'string
4458   :group 'gnus-thread)
4459
4460 (defun gnus-summary-prepare-threads (threads)
4461   "Prepare summary buffer from THREADS and indentation LEVEL.
4462 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4463 or a straight list of headers."
4464   (gnus-message 7 "Generating summary...")
4465
4466   (setq gnus-newsgroup-threads threads)
4467   (beginning-of-line)
4468
4469   (let ((gnus-tmp-level 0)
4470         (default-score (or gnus-summary-default-score 0))
4471         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4472         thread number subject stack state gnus-tmp-gathered beg-match
4473         new-roots gnus-tmp-new-adopts thread-end simp-subject
4474         gnus-tmp-header gnus-tmp-unread
4475         gnus-tmp-replied gnus-tmp-subject-or-nil
4476         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4477         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4478         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4479         tree-stack)
4480
4481     (setq gnus-tmp-prev-subject nil)
4482
4483     (if (vectorp (car threads))
4484         ;; If this is a straight (sic) list of headers, then a
4485         ;; threaded summary display isn't required, so we just create
4486         ;; an unthreaded one.
4487         (gnus-summary-prepare-unthreaded threads)
4488
4489       ;; Do the threaded display.
4490
4491       (while (or threads stack gnus-tmp-new-adopts new-roots)
4492
4493         (if (and (= gnus-tmp-level 0)
4494                  (or (not stack)
4495                      (= (caar stack) 0))
4496                  (not gnus-tmp-false-parent)
4497                  (or gnus-tmp-new-adopts new-roots))
4498             (if gnus-tmp-new-adopts
4499                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4500                       thread (list (car gnus-tmp-new-adopts))
4501                       gnus-tmp-header (caar thread)
4502                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4503               (when new-roots
4504                 (setq thread (list (car new-roots))
4505                       gnus-tmp-header (caar thread)
4506                       new-roots (cdr new-roots))))
4507
4508           (if threads
4509               ;; If there are some threads, we do them before the
4510               ;; threads on the stack.
4511               (setq thread threads
4512                     gnus-tmp-header (caar thread))
4513             ;; There were no current threads, so we pop something off
4514             ;; the stack.
4515             (setq state (car stack)
4516                   gnus-tmp-level (car state)
4517                   tree-stack (cadr state)
4518                   thread (caddr state)
4519                   stack (cdr stack)
4520                   gnus-tmp-header (caar thread))))
4521
4522         (setq gnus-tmp-false-parent nil)
4523         (setq gnus-tmp-root-expunged nil)
4524         (setq thread-end nil)
4525
4526         (if (stringp gnus-tmp-header)
4527             ;; The header is a dummy root.
4528             (cond
4529              ((eq gnus-summary-make-false-root 'adopt)
4530               ;; We let the first article adopt the rest.
4531               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4532                                                (cddar thread)))
4533               (setq gnus-tmp-gathered
4534                     (nconc (mapcar
4535                             (lambda (h) (mail-header-number (car h)))
4536                             (cddar thread))
4537                            gnus-tmp-gathered))
4538               (setq thread (cons (list (caar thread)
4539                                        (cadar thread))
4540                                  (cdr thread)))
4541               (setq gnus-tmp-level -1
4542                     gnus-tmp-false-parent t))
4543              ((eq gnus-summary-make-false-root 'empty)
4544               ;; We print adopted articles with empty subject fields.
4545               (setq gnus-tmp-gathered
4546                     (nconc (mapcar
4547                             (lambda (h) (mail-header-number (car h)))
4548                             (cddar thread))
4549                            gnus-tmp-gathered))
4550               (setq gnus-tmp-level -1))
4551              ((eq gnus-summary-make-false-root 'dummy)
4552               ;; We remember that we probably want to output a dummy
4553               ;; root.
4554               (setq gnus-tmp-dummy-line gnus-tmp-header)
4555               (setq gnus-tmp-prev-subject gnus-tmp-header))
4556              (t
4557               ;; We do not make a root for the gathered
4558               ;; sub-threads at all.
4559               (setq gnus-tmp-level -1)))
4560
4561           (setq number (mail-header-number gnus-tmp-header)
4562                 subject (mail-header-subject gnus-tmp-header)
4563                 simp-subject (gnus-simplify-subject-fully subject))
4564
4565           (cond
4566            ;; If the thread has changed subject, we might want to make
4567            ;; this subthread into a root.
4568            ((and (null gnus-thread-ignore-subject)
4569                  (not (zerop gnus-tmp-level))
4570                  gnus-tmp-prev-subject
4571                  (not (string= gnus-tmp-prev-subject simp-subject)))
4572             (setq new-roots (nconc new-roots (list (car thread)))
4573                   thread-end t
4574                   gnus-tmp-header nil))
4575            ;; If the article lies outside the current limit,
4576            ;; then we do not display it.
4577            ((not (memq number gnus-newsgroup-limit))
4578             (setq gnus-tmp-gathered
4579                   (nconc (mapcar
4580                           (lambda (h) (mail-header-number (car h)))
4581                           (cdar thread))
4582                          gnus-tmp-gathered))
4583             (setq gnus-tmp-new-adopts (if (cdar thread)
4584                                           (append gnus-tmp-new-adopts
4585                                                   (cdar thread))
4586                                         gnus-tmp-new-adopts)
4587                   thread-end t
4588                   gnus-tmp-header nil)
4589             (when (zerop gnus-tmp-level)
4590               (setq gnus-tmp-root-expunged t)))
4591            ;; Perhaps this article is to be marked as read?
4592            ((and gnus-summary-mark-below
4593                  (< (or (cdr (assq number gnus-newsgroup-scored))
4594                         default-score)
4595                     gnus-summary-mark-below)
4596                  ;; Don't touch sparse articles.
4597                  (not (gnus-summary-article-sparse-p number))
4598                  (not (gnus-summary-article-ancient-p number)))
4599             (setq gnus-newsgroup-unreads
4600                   (delq number gnus-newsgroup-unreads))
4601             (if gnus-newsgroup-auto-expire
4602                 (setq gnus-newsgroup-expirable
4603                       (gnus-add-to-sorted-list
4604                        gnus-newsgroup-expirable number))
4605               (push (cons number gnus-low-score-mark)
4606                     gnus-newsgroup-reads))))
4607
4608           (when gnus-tmp-header
4609             ;; We may have an old dummy line to output before this
4610             ;; article.
4611             (when (and gnus-tmp-dummy-line
4612                        (gnus-subject-equal
4613                         gnus-tmp-dummy-line
4614                         (mail-header-subject gnus-tmp-header)))
4615               (gnus-summary-insert-dummy-line
4616                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4617               (setq gnus-tmp-dummy-line nil))
4618
4619             ;; Compute the mark.
4620             (setq gnus-tmp-unread (gnus-article-mark number))
4621
4622             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4623                                   gnus-tmp-header gnus-tmp-level)
4624                   gnus-newsgroup-data)
4625
4626             ;; Actually insert the line.
4627             (setq
4628              gnus-tmp-subject-or-nil
4629              (cond
4630               ((and gnus-thread-ignore-subject
4631                     gnus-tmp-prev-subject
4632                     (not (string= gnus-tmp-prev-subject simp-subject)))
4633                subject)
4634               ((zerop gnus-tmp-level)
4635                (if (and (eq gnus-summary-make-false-root 'empty)
4636                         (memq number gnus-tmp-gathered)
4637                         gnus-tmp-prev-subject
4638                         (string= gnus-tmp-prev-subject simp-subject))
4639                    gnus-summary-same-subject
4640                  subject))
4641               (t gnus-summary-same-subject)))
4642             (if (and (eq gnus-summary-make-false-root 'adopt)
4643                      (= gnus-tmp-level 1)
4644                      (memq number gnus-tmp-gathered))
4645                 (setq gnus-tmp-opening-bracket ?\<
4646                       gnus-tmp-closing-bracket ?\>)
4647               (setq gnus-tmp-opening-bracket ?\[
4648                     gnus-tmp-closing-bracket ?\]))
4649             (setq
4650              gnus-tmp-indentation
4651              (aref gnus-thread-indent-array gnus-tmp-level)
4652              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4653              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4654                                 gnus-summary-default-score 0)
4655              gnus-tmp-score-char
4656              (if (or (null gnus-summary-default-score)
4657                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4658                          gnus-summary-zcore-fuzz))
4659                  ?                      ;Whitespace
4660                (if (< gnus-tmp-score gnus-summary-default-score)
4661                    gnus-score-below-mark gnus-score-over-mark))
4662              gnus-tmp-replied
4663              (cond ((memq number gnus-newsgroup-processable)
4664                     gnus-process-mark)
4665                    ((memq number gnus-newsgroup-cached)
4666                     gnus-cached-mark)
4667                    ((memq number gnus-newsgroup-replied)
4668                     gnus-replied-mark)
4669                    ((memq number gnus-newsgroup-forwarded)
4670                     gnus-forwarded-mark)
4671                    ((memq number gnus-newsgroup-saved)
4672                     gnus-saved-mark)
4673                    ((memq number gnus-newsgroup-recent)
4674                     gnus-recent-mark)
4675                    ((memq number gnus-newsgroup-unseen)
4676                     gnus-unseen-mark)
4677                    (t gnus-no-mark))
4678              gnus-tmp-from (mail-header-from gnus-tmp-header)
4679              gnus-tmp-name
4680              (cond
4681               ((string-match "<[^>]+> *$" gnus-tmp-from)
4682                (setq beg-match (match-beginning 0))
4683                (or (and (string-match "^\".+\"" gnus-tmp-from)
4684                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4685                    (substring gnus-tmp-from 0 beg-match)))
4686               ((string-match "(.+)" gnus-tmp-from)
4687                (substring gnus-tmp-from
4688                           (1+ (match-beginning 0)) (1- (match-end 0))))
4689               (t gnus-tmp-from))
4690              gnus-tmp-thread-tree-header-string
4691              (cond
4692               ((not gnus-show-threads) "")
4693               ((zerop gnus-tmp-level)
4694                (if (cdar thread)
4695                    (or gnus-sum-thread-tree-root subject)
4696                  (or gnus-sum-thread-tree-single-indent subject)))
4697               (t
4698                (concat (apply 'concat
4699                               (mapcar (lambda (item)
4700                                         (if (= item 1)
4701                                             gnus-sum-thread-tree-vertical
4702                                           gnus-sum-thread-tree-indent))
4703                                       (cdr (reverse tree-stack))))
4704                        (if (nth 1 thread)
4705                            gnus-sum-thread-tree-leaf-with-other
4706                          gnus-sum-thread-tree-single-leaf)))))
4707             (when (string= gnus-tmp-name "")
4708               (setq gnus-tmp-name gnus-tmp-from))
4709             (unless (numberp gnus-tmp-lines)
4710               (setq gnus-tmp-lines -1))
4711             (if (= gnus-tmp-lines -1)
4712                 (setq gnus-tmp-lines "?")
4713               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4714             (gnus-put-text-property
4715              (point)
4716              (progn (eval gnus-summary-line-format-spec) (point))
4717              'gnus-number number)
4718             (when gnus-visual-p
4719               (forward-line -1)
4720               (gnus-run-hooks 'gnus-summary-update-hook)
4721               (forward-line 1))
4722
4723             (setq gnus-tmp-prev-subject simp-subject)))
4724
4725         (when (nth 1 thread)
4726           (push (list (max 0 gnus-tmp-level)
4727                       (copy-list tree-stack)
4728                       (nthcdr 1 thread))
4729                 stack))
4730         (push (if (nth 1 thread) 1 0) tree-stack)
4731         (incf gnus-tmp-level)
4732         (setq threads (if thread-end nil (cdar thread)))
4733         (unless threads
4734           (setq gnus-tmp-level 0)))))
4735   (gnus-message 7 "Generating summary...done"))
4736
4737 (defun gnus-summary-prepare-unthreaded (headers)
4738   "Generate an unthreaded summary buffer based on HEADERS."
4739   (let (header number mark)
4740
4741     (beginning-of-line)
4742
4743     (while headers
4744       ;; We may have to root out some bad articles...
4745       (when (memq (setq number (mail-header-number
4746                                 (setq header (pop headers))))
4747                   gnus-newsgroup-limit)
4748         ;; Mark article as read when it has a low score.
4749         (when (and gnus-summary-mark-below
4750                    (< (or (cdr (assq number gnus-newsgroup-scored))
4751                           gnus-summary-default-score 0)
4752                       gnus-summary-mark-below)
4753                    (not (gnus-summary-article-ancient-p number)))
4754           (setq gnus-newsgroup-unreads
4755                 (delq number gnus-newsgroup-unreads))
4756           (if gnus-newsgroup-auto-expire
4757               (push number gnus-newsgroup-expirable)
4758             (push (cons number gnus-low-score-mark)
4759                   gnus-newsgroup-reads)))
4760
4761         (setq mark (gnus-article-mark number))
4762         (push (gnus-data-make number mark (1+ (point)) header 0)
4763               gnus-newsgroup-data)
4764         (gnus-summary-insert-line
4765          header 0 number
4766          mark (memq number gnus-newsgroup-replied)
4767          (memq number gnus-newsgroup-expirable)
4768          (mail-header-subject header) nil
4769          (cdr (assq number gnus-newsgroup-scored))
4770          (memq number gnus-newsgroup-processable))))))
4771
4772 (defun gnus-summary-remove-list-identifiers ()
4773   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4774   (let ((regexp (if (consp gnus-list-identifiers)
4775                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4776                   gnus-list-identifiers))
4777         changed subject)
4778     (when regexp
4779       (dolist (header gnus-newsgroup-headers)
4780         (setq subject (mail-header-subject header)
4781               changed nil)
4782         (while (string-match
4783                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4784                 subject)
4785           (setq subject
4786                 (concat (substring subject 0 (match-beginning 2))
4787                         (substring subject (match-end 0)))
4788                 changed t))
4789         (when (and changed
4790                    (string-match
4791                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4792           (setq subject
4793                 (concat (substring subject 0 (match-beginning 1))
4794                         (substring subject (match-end 1)))))
4795         (when changed
4796           (mail-header-set-subject header subject))))))
4797
4798 (defun gnus-fetch-headers (articles)
4799   "Fetch headers of ARTICLES."
4800   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4801     (gnus-message 5 "Fetching headers for %s..." name)
4802     (prog1
4803         (if (eq 'nov
4804                 (setq gnus-headers-retrieved-by
4805                       (gnus-retrieve-headers
4806                        articles gnus-newsgroup-name
4807                        ;; We might want to fetch old headers, but
4808                        ;; not if there is only 1 article.
4809                        (and (or (and
4810                                  (not (eq gnus-fetch-old-headers 'some))
4811                                  (not (numberp gnus-fetch-old-headers)))
4812                                 (> (length articles) 1))
4813                             gnus-fetch-old-headers))))
4814             (gnus-get-newsgroup-headers-xover
4815              articles nil nil gnus-newsgroup-name t)
4816           (gnus-get-newsgroup-headers))
4817       (gnus-message 5 "Fetching headers for %s...done" name))))
4818
4819 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4820   "Select newsgroup GROUP.
4821 If READ-ALL is non-nil, all articles in the group are selected.
4822 If SELECT-ARTICLES, only select those articles from GROUP."
4823   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4824          ;;!!! Dirty hack; should be removed.
4825          (gnus-summary-ignore-duplicates
4826           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4827               t
4828             gnus-summary-ignore-duplicates))
4829          (info (nth 2 entry))
4830          articles fetched-articles cached)
4831
4832     (unless (gnus-check-server
4833              (set (make-local-variable 'gnus-current-select-method)
4834                   (gnus-find-method-for-group group)))
4835       (error "Couldn't open server"))
4836
4837     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4838         (gnus-activate-group group)     ; Or we can activate it...
4839         (progn                          ; Or we bug out.
4840           (when (equal major-mode 'gnus-summary-mode)
4841             (kill-buffer (current-buffer)))
4842           (error "Couldn't activate group %s: %s"
4843                  group (gnus-status-message group))))
4844
4845     (unless (gnus-request-group group t)
4846       (when (equal major-mode 'gnus-summary-mode)
4847         (kill-buffer (current-buffer)))
4848       (error "Couldn't request group %s: %s"
4849              group (gnus-status-message group)))
4850
4851     (setq gnus-newsgroup-name group
4852           gnus-newsgroup-unselected nil
4853           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4854
4855     (let ((display (gnus-group-find-parameter group 'display)))
4856       (setq gnus-newsgroup-display
4857             (cond
4858              ((not (zerop (or (car-safe read-all) 0)))
4859               ;; The user entered the group with C-u SPC/RET, let's show
4860               ;; all articles.
4861               'gnus-not-ignore)
4862              ((eq display 'all)
4863               'gnus-not-ignore)
4864              ((arrayp display)
4865               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4866              ((numberp display)
4867               ;; The following is probably the "correct" solution, but
4868               ;; it makes Gnus fetch all headers and then limit the
4869               ;; articles (which is slow), so instead we hack the
4870               ;; select-articles parameter instead. -- Simon Josefsson
4871               ;; <jas@kth.se>
4872               ;;
4873               ;; (gnus-byte-compile
4874               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4875               ;;                         display)))))
4876               (setq select-articles
4877                     (gnus-uncompress-range
4878                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4879                              (if (> tmp 0)
4880                                  tmp
4881                                1))
4882                            (cdr (gnus-active group)))))
4883               nil)
4884              (t
4885               nil))))
4886
4887     (gnus-summary-setup-default-charset)
4888
4889     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4890     (when (gnus-virtual-group-p group)
4891       (setq cached gnus-newsgroup-cached))
4892
4893     (setq gnus-newsgroup-unreads
4894           (gnus-sorted-ndifference
4895            (gnus-sorted-ndifference gnus-newsgroup-unreads
4896                                     gnus-newsgroup-marked)
4897            gnus-newsgroup-dormant))
4898
4899     (setq gnus-newsgroup-processable nil)
4900
4901     (gnus-update-read-articles group gnus-newsgroup-unreads)
4902
4903     ;; Adjust and set lists of article marks.
4904     (when info
4905       (gnus-adjust-marked-articles info))
4906     (if (setq articles select-articles)
4907         (setq gnus-newsgroup-unselected
4908               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4909       (setq articles (gnus-articles-to-read group read-all)))
4910
4911     (cond
4912      ((null articles)
4913       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4914       'quit)
4915      ((eq articles 0) nil)
4916      (t
4917       ;; Init the dependencies hash table.
4918       (setq gnus-newsgroup-dependencies
4919             (gnus-make-hashtable (length articles)))
4920       (gnus-set-global-variables)
4921       ;; Retrieve the headers and read them in.
4922
4923       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4924
4925       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4926       (when cached
4927         (setq gnus-newsgroup-cached cached))
4928
4929       ;; Suppress duplicates?
4930       (when gnus-suppress-duplicates
4931         (gnus-dup-suppress-articles))
4932
4933       ;; Set the initial limit.
4934       (setq gnus-newsgroup-limit (copy-sequence articles))
4935       ;; Remove canceled articles from the list of unread articles.
4936       (setq fetched-articles
4937             (mapcar (lambda (headers) (mail-header-number headers))
4938                     gnus-newsgroup-headers))
4939       (setq gnus-newsgroup-articles fetched-articles)
4940       (setq gnus-newsgroup-unreads
4941             (gnus-sorted-nintersection
4942              gnus-newsgroup-unreads fetched-articles))
4943       (gnus-compute-unseen-list)
4944
4945       ;; Removed marked articles that do not exist.
4946       (gnus-update-missing-marks
4947        (gnus-sorted-difference articles fetched-articles))
4948       ;; We might want to build some more threads first.
4949       (when (and gnus-fetch-old-headers
4950                  (eq gnus-headers-retrieved-by 'nov))
4951         (if (eq gnus-fetch-old-headers 'invisible)
4952             (gnus-build-all-threads)
4953           (gnus-build-old-threads)))
4954       ;; Let the Gnus agent mark articles as read.
4955       (when gnus-agent
4956         (gnus-agent-get-undownloaded-list))
4957       ;; Remove list identifiers from subject
4958       (when gnus-list-identifiers
4959         (gnus-summary-remove-list-identifiers))
4960       ;; Check whether auto-expire is to be done in this group.
4961       (setq gnus-newsgroup-auto-expire
4962             (gnus-group-auto-expirable-p group))
4963       ;; Set up the article buffer now, if necessary.
4964       (unless gnus-single-article-buffer
4965         (gnus-article-setup-buffer))
4966       ;; First and last article in this newsgroup.
4967       (when gnus-newsgroup-headers
4968         (setq gnus-newsgroup-begin
4969               (mail-header-number (car gnus-newsgroup-headers))
4970               gnus-newsgroup-end
4971               (mail-header-number
4972                (gnus-last-element gnus-newsgroup-headers))))
4973       ;; GROUP is successfully selected.
4974       (or gnus-newsgroup-headers t)))))
4975
4976 (defun gnus-compute-unseen-list ()
4977   ;; The `seen' marks are treated specially.
4978   (if (not gnus-newsgroup-seen)
4979       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4980     (setq gnus-newsgroup-unseen
4981           (gnus-inverse-list-range-intersection
4982            gnus-newsgroup-articles gnus-newsgroup-seen))))
4983
4984 (defun gnus-summary-display-make-predicate (display)
4985   (require 'gnus-agent)
4986   (when (= (length display) 1)
4987     (setq display (car display)))
4988   (unless gnus-summary-display-cache
4989     (dolist (elem (append '((unread . unread)
4990                             (read . read)
4991                             (unseen . unseen))
4992                           gnus-article-mark-lists))
4993       (push (cons (cdr elem)
4994                   (gnus-byte-compile
4995                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4996             gnus-summary-display-cache)))
4997   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4998         (gnus-category-predicate-cache gnus-summary-display-cache))
4999     (gnus-get-predicate display)))
5000
5001 ;; Uses the dynamically bound `number' variable.
5002 (defvar number)
5003 (defun gnus-article-marked-p (type &optional article)
5004   (let ((article (or article number)))
5005     (cond
5006      ((eq type 'tick)
5007       (memq article gnus-newsgroup-marked))
5008      ((eq type 'spam)
5009       (memq article gnus-newsgroup-spam-marked))
5010      ((eq type 'unsend)
5011       (memq article gnus-newsgroup-unsendable))
5012      ((eq type 'undownload)
5013       (memq article gnus-newsgroup-undownloaded))
5014      ((eq type 'download)
5015       (memq article gnus-newsgroup-downloadable))
5016      ((eq type 'unread)
5017       (memq article gnus-newsgroup-unreads))
5018      ((eq type 'read)
5019       (memq article gnus-newsgroup-reads))
5020      ((eq type 'dormant)
5021       (memq article gnus-newsgroup-dormant) )
5022      ((eq type 'expire)
5023       (memq article gnus-newsgroup-expirable))
5024      ((eq type 'reply)
5025       (memq article gnus-newsgroup-replied))
5026      ((eq type 'killed)
5027       (memq article gnus-newsgroup-killed))
5028      ((eq type 'bookmark)
5029       (assq article gnus-newsgroup-bookmarks))
5030      ((eq type 'score)
5031       (assq article gnus-newsgroup-scored))
5032      ((eq type 'save)
5033       (memq article gnus-newsgroup-saved))
5034      ((eq type 'cache)
5035       (memq article gnus-newsgroup-cached))
5036      ((eq type 'forward)
5037       (memq article gnus-newsgroup-forwarded))
5038      ((eq type 'seen)
5039       (not (memq article gnus-newsgroup-unseen)))
5040      ((eq type 'recent)
5041       (memq article gnus-newsgroup-recent))
5042      (t t))))
5043
5044 (defun gnus-articles-to-read (group &optional read-all)
5045   "Find out what articles the user wants to read."
5046   (let* ((articles
5047           ;; Select all articles if `read-all' is non-nil, or if there
5048           ;; are no unread articles.
5049           (if (or read-all
5050                   (and (zerop (length gnus-newsgroup-marked))
5051                        (zerop (length gnus-newsgroup-unreads)))
5052                   ;; Fetch all if the predicate is non-nil.
5053                   gnus-newsgroup-display)
5054               ;; We want to select the headers for all the articles in
5055               ;; the group, so we select either all the active
5056               ;; articles in the group, or (if that's nil), the
5057               ;; articles in the cache.
5058               (or
5059                (gnus-uncompress-range (gnus-active group))
5060                (gnus-cache-articles-in-group group))
5061             ;; Select only the "normal" subset of articles.
5062             (gnus-sorted-nunion
5063              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5064              gnus-newsgroup-unreads)))
5065          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5066          (scored (length scored-list))
5067          (number (length articles))
5068          (marked (+ (length gnus-newsgroup-marked)
5069                     (length gnus-newsgroup-dormant)))
5070          (select
5071           (cond
5072            ((numberp read-all)
5073             read-all)
5074            ((numberp gnus-newsgroup-display)
5075             gnus-newsgroup-display)
5076            (t
5077             (condition-case ()
5078                 (cond
5079                  ((and (or (<= scored marked) (= scored number))
5080                        (numberp gnus-large-newsgroup)
5081                        (> number gnus-large-newsgroup))
5082                   (let* ((cursor-in-echo-area nil)
5083                          (initial (gnus-parameter-large-newsgroup-initial
5084                                    gnus-newsgroup-name))
5085                          (input
5086                           (read-string
5087                            (format
5088                             "How many articles from %s (%s %d): "
5089                             (gnus-limit-string
5090                              (gnus-group-decoded-name gnus-newsgroup-name)
5091                              35)
5092                             (if initial "max" "default")
5093                             number)
5094                            (if initial
5095                                (cons (number-to-string initial)
5096                                      0)))))
5097                     (if (string-match "^[ \t]*$" input) number input)))
5098                  ((and (> scored marked) (< scored number)
5099                        (> (- scored number) 20))
5100                   (let ((input
5101                          (read-string
5102                           (format "%s %s (%d scored, %d total): "
5103                                   "How many articles from"
5104                                   (gnus-group-decoded-name group)
5105                                   scored number))))
5106                     (if (string-match "^[ \t]*$" input)
5107                         number input)))
5108                  (t number))
5109               (quit
5110                (message "Quit getting the articles to read")
5111                nil))))))
5112     (setq select (if (stringp select) (string-to-number select) select))
5113     (if (or (null select) (zerop select))
5114         select
5115       (if (and (not (zerop scored)) (<= (abs select) scored))
5116           (progn
5117             (setq articles (sort scored-list '<))
5118             (setq number (length articles)))
5119         (setq articles (copy-sequence articles)))
5120
5121       (when (< (abs select) number)
5122         (if (< select 0)
5123             ;; Select the N oldest articles.
5124             (setcdr (nthcdr (1- (abs select)) articles) nil)
5125           ;; Select the N most recent articles.
5126           (setq articles (nthcdr (- number select) articles))))
5127       (setq gnus-newsgroup-unselected
5128             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5129       (when gnus-alter-articles-to-read-function
5130         (setq gnus-newsgroup-unreads
5131               (sort
5132                (funcall gnus-alter-articles-to-read-function
5133                         gnus-newsgroup-name gnus-newsgroup-unreads)
5134                '<)))
5135       articles)))
5136
5137 (defun gnus-killed-articles (killed articles)
5138   (let (out)
5139     (while articles
5140       (when (inline (gnus-member-of-range (car articles) killed))
5141         (push (car articles) out))
5142       (setq articles (cdr articles)))
5143     out))
5144
5145 (defun gnus-uncompress-marks (marks)
5146   "Uncompress the mark ranges in MARKS."
5147   (let ((uncompressed '(score bookmark))
5148         out)
5149     (while marks
5150       (if (memq (caar marks) uncompressed)
5151           (push (car marks) out)
5152         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5153       (setq marks (cdr marks)))
5154     out))
5155
5156 (defun gnus-article-mark-to-type (mark)
5157   "Return the type of MARK."
5158   (or (cadr (assq mark gnus-article-special-mark-lists))
5159       'list))
5160
5161 (defun gnus-article-unpropagatable-p (mark)
5162   "Return whether MARK should be propagated to backend."
5163   (memq mark gnus-article-unpropagated-mark-lists))
5164
5165 (defun gnus-adjust-marked-articles (info)
5166   "Set all article lists and remove all marks that are no longer valid."
5167   (let* ((marked-lists (gnus-info-marks info))
5168          (active (gnus-active (gnus-info-group info)))
5169          (min (car active))
5170          (max (cdr active))
5171          (types gnus-article-mark-lists)
5172          marks var articles article mark mark-type)
5173
5174     (dolist (marks marked-lists)
5175       (setq mark (car marks)
5176             mark-type (gnus-article-mark-to-type mark)
5177             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5178
5179       ;; We set the variable according to the type of the marks list,
5180       ;; and then adjust the marks to a subset of the active articles.
5181       (cond
5182        ;; Adjust "simple" lists.
5183        ((eq mark-type 'list)
5184         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5185         (when (memq mark '(tick dormant expire reply save))
5186           (while articles
5187             (when (or (< (setq article (pop articles)) min) (> article max))
5188               (set var (delq article (symbol-value var)))))))
5189        ;; Adjust assocs.
5190        ((eq mark-type 'tuple)
5191         (set var (setq articles (cdr marks)))
5192         (when (not (listp (cdr (symbol-value var))))
5193           (set var (list (symbol-value var))))
5194         (when (not (listp (cdr articles)))
5195           (setq articles (list articles)))
5196         (while articles
5197           (when (or (not (consp (setq article (pop articles))))
5198                     (< (car article) min)
5199                     (> (car article) max))
5200             (set var (delq article (symbol-value var))))))
5201        ;; Adjust ranges (sloppily).
5202        ((eq mark-type 'range)
5203         (cond
5204          ((eq mark 'seen)
5205           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5206           ;; It should be (seen (NUM1 . NUM2)).
5207           (when (numberp (cddr marks))
5208             (setcdr marks (list (cdr marks))))
5209           (setq articles (cdr marks))
5210           (while (and articles
5211                       (or (and (consp (car articles))
5212                                (> min (cdar articles)))
5213                           (and (numberp (car articles))
5214                                (> min (car articles)))))
5215             (pop articles))
5216           (set var articles))))))))
5217
5218 (defun gnus-update-missing-marks (missing)
5219   "Go through the list of MISSING articles and remove them from the mark lists."
5220   (when missing
5221     (let (var m)
5222       ;; Go through all types.
5223       (dolist (elem gnus-article-mark-lists)
5224         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5225           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5226           (when (symbol-value var)
5227             ;; This list has articles.  So we delete all missing
5228             ;; articles from it.
5229             (setq m missing)
5230             (while m
5231               (set var (delq (pop m) (symbol-value var))))))))))
5232
5233 (defun gnus-update-marks ()
5234   "Enter the various lists of marked articles into the newsgroup info list."
5235   (let ((types gnus-article-mark-lists)
5236         (info (gnus-get-info gnus-newsgroup-name))
5237         type list newmarked symbol delta-marks)
5238     (when info
5239       ;; Add all marks lists to the list of marks lists.
5240       (while (setq type (pop types))
5241         (setq list (symbol-value
5242                     (setq symbol
5243                           (intern (format "gnus-newsgroup-%s" (car type))))))
5244
5245         (when list
5246           ;; Get rid of the entries of the articles that have the
5247           ;; default score.
5248           (when (and (eq (cdr type) 'score)
5249                      gnus-save-score
5250                      list)
5251             (let* ((arts list)
5252                    (prev (cons nil list))
5253                    (all prev))
5254               (while arts
5255                 (if (or (not (consp (car arts)))
5256                         (= (cdar arts) gnus-summary-default-score))
5257                     (setcdr prev (cdr arts))
5258                   (setq prev arts))
5259                 (setq arts (cdr arts)))
5260               (setq list (cdr all)))))
5261
5262         (when (eq (cdr type) 'seen)
5263           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5264
5265         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5266           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5267
5268         (when (and (gnus-check-backend-function
5269                     'request-set-mark gnus-newsgroup-name)
5270                    (not (gnus-article-unpropagatable-p (cdr type))))
5271           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5272                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5273                  (add (gnus-remove-from-range
5274                        (gnus-copy-sequence list) old)))
5275             (when add
5276               (push (list add 'add (list (cdr type))) delta-marks))
5277             (when del
5278               (push (list del 'del (list (cdr type))) delta-marks))))
5279
5280         (when list
5281           (push (cons (cdr type) list) newmarked)))
5282
5283       (when delta-marks
5284         (unless (gnus-check-group gnus-newsgroup-name)
5285           (error "Can't open server for %s" gnus-newsgroup-name))
5286         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5287
5288       ;; Enter these new marks into the info of the group.
5289       (if (nthcdr 3 info)
5290           (setcar (nthcdr 3 info) newmarked)
5291         ;; Add the marks lists to the end of the info.
5292         (when newmarked
5293           (setcdr (nthcdr 2 info) (list newmarked))))
5294
5295       ;; Cut off the end of the info if there's nothing else there.
5296       (let ((i 5))
5297         (while (and (> i 2)
5298                     (not (nth i info)))
5299           (when (nthcdr (decf i) info)
5300             (setcdr (nthcdr i info) nil)))))))
5301
5302 (defun gnus-set-mode-line (where)
5303   "Set the mode line of the article or summary buffers.
5304 If WHERE is `summary', the summary mode line format will be used."
5305   ;; Is this mode line one we keep updated?
5306   (when (and (memq where gnus-updated-mode-lines)
5307              (symbol-value
5308               (intern (format "gnus-%s-mode-line-format-spec" where))))
5309     (let (mode-string)
5310       (save-excursion
5311         ;; We evaluate this in the summary buffer since these
5312         ;; variables are buffer-local to that buffer.
5313         (set-buffer gnus-summary-buffer)
5314        ;; We bind all these variables that are used in the `eval' form
5315         ;; below.
5316         (let* ((mformat (symbol-value
5317                          (intern
5318                           (format "gnus-%s-mode-line-format-spec" where))))
5319                (gnus-tmp-group-name (gnus-group-decoded-name
5320                                      gnus-newsgroup-name))
5321                (gnus-tmp-article-number (or gnus-current-article 0))
5322                (gnus-tmp-unread gnus-newsgroup-unreads)
5323                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5324                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5325                (gnus-tmp-unread-and-unselected
5326                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5327                             (zerop gnus-tmp-unselected))
5328                        "")
5329                       ((zerop gnus-tmp-unselected)
5330                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5331                       (t (format "{%d(+%d) more}"
5332                                  gnus-tmp-unread-and-unticked
5333                                  gnus-tmp-unselected))))
5334                (gnus-tmp-subject
5335                 (if (and gnus-current-headers
5336                          (vectorp gnus-current-headers))
5337                     (gnus-mode-string-quote
5338                      (mail-header-subject gnus-current-headers))
5339                   ""))
5340                bufname-length max-len
5341                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5342           (setq mode-string (eval mformat))
5343           (setq bufname-length (if (string-match "%b" mode-string)
5344                                    (- (length
5345                                        (buffer-name
5346                                         (if (eq where 'summary)
5347                                             nil
5348                                           (get-buffer gnus-article-buffer))))
5349                                       2)
5350                                  0))
5351           (setq max-len (max 4 (if gnus-mode-non-string-length
5352                                    (- (window-width)
5353                                       gnus-mode-non-string-length
5354                                       bufname-length)
5355                                  (length mode-string))))
5356           ;; We might have to chop a bit of the string off...
5357           (when (> (length mode-string) max-len)
5358             (setq mode-string
5359                   (concat (truncate-string-to-width mode-string (- max-len 3))
5360                           "...")))
5361           ;; Pad the mode string a bit.
5362           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5363       ;; Update the mode line.
5364       (setq mode-line-buffer-identification
5365             (gnus-mode-line-buffer-identification (list mode-string)))
5366       (set-buffer-modified-p t))))
5367
5368 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5369   "Go through the HEADERS list and add all Xrefs to a hash table.
5370 The resulting hash table is returned, or nil if no Xrefs were found."
5371   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5372          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5373          (xref-hashtb (gnus-make-hashtable))
5374          start group entry number xrefs header)
5375     (while headers
5376       (setq header (pop headers))
5377       (when (and (setq xrefs (mail-header-xref header))
5378                  (not (memq (setq number (mail-header-number header))
5379                             unreads)))
5380         (setq start 0)
5381         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5382           (setq start (match-end 0))
5383           (setq group (if prefix
5384                           (concat prefix (substring xrefs (match-beginning 1)
5385                                                     (match-end 1)))
5386                         (substring xrefs (match-beginning 1) (match-end 1))))
5387           (setq number
5388                 (string-to-int (substring xrefs (match-beginning 2)
5389                                           (match-end 2))))
5390           (if (setq entry (gnus-gethash group xref-hashtb))
5391               (setcdr entry (cons number (cdr entry)))
5392             (gnus-sethash group (cons number nil) xref-hashtb)))))
5393     (and start xref-hashtb)))
5394
5395 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5396   "Look through all the headers and mark the Xrefs as read."
5397   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5398         name entry info xref-hashtb idlist method nth4)
5399     (save-excursion
5400       (set-buffer gnus-group-buffer)
5401       (when (setq xref-hashtb
5402                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5403         (mapatoms
5404          (lambda (group)
5405            (unless (string= from-newsgroup (setq name (symbol-name group)))
5406              (setq idlist (symbol-value group))
5407              ;; Dead groups are not updated.
5408              (and (prog1
5409                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5410                             info (nth 2 entry))
5411                     (when (stringp (setq nth4 (gnus-info-method info)))
5412                       (setq nth4 (gnus-server-to-method nth4))))
5413                   ;; Only do the xrefs if the group has the same
5414                   ;; select method as the group we have just read.
5415                   (or (gnus-methods-equal-p
5416                        nth4 (gnus-find-method-for-group from-newsgroup))
5417                       virtual
5418                       (equal nth4 (setq method (gnus-find-method-for-group
5419                                                 from-newsgroup)))
5420                       (and (equal (car nth4) (car method))
5421                            (equal (nth 1 nth4) (nth 1 method))))
5422                   gnus-use-cross-reference
5423                   (or (not (eq gnus-use-cross-reference t))
5424                       virtual
5425                       ;; Only do cross-references on subscribed
5426                       ;; groups, if that is what is wanted.
5427                       (<= (gnus-info-level info) gnus-level-subscribed))
5428                   (gnus-group-make-articles-read name idlist))))
5429          xref-hashtb)))))
5430
5431 (defun gnus-compute-read-articles (group articles)
5432   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5433          (info (nth 2 entry))
5434          (active (gnus-active group))
5435          ninfo)
5436     (when entry
5437       ;; First peel off all invalid article numbers.
5438       (when active
5439         (let ((ids articles)
5440               id first)
5441           (while (setq id (pop ids))
5442             (when (and first (> id (cdr active)))
5443               ;; We'll end up in this situation in one particular
5444               ;; obscure situation.  If you re-scan a group and get
5445               ;; a new article that is cross-posted to a different
5446               ;; group that has not been re-scanned, you might get
5447               ;; crossposted article that has a higher number than
5448               ;; Gnus believes possible.  So we re-activate this
5449               ;; group as well.  This might mean doing the
5450               ;; crossposting thingy will *increase* the number
5451               ;; of articles in some groups.  Tsk, tsk.
5452               (setq active (or (gnus-activate-group group) active)))
5453             (when (or (> id (cdr active))
5454                       (< id (car active)))
5455               (setq articles (delq id articles))))))
5456       ;; If the read list is nil, we init it.
5457       (if (and active
5458                (null (gnus-info-read info))
5459                (> (car active) 1))
5460           (setq ninfo (cons 1 (1- (car active))))
5461         (setq ninfo (gnus-info-read info)))
5462       ;; Then we add the read articles to the range.
5463       (gnus-add-to-range
5464        ninfo (setq articles (sort articles '<))))))
5465
5466 (defun gnus-group-make-articles-read (group articles)
5467   "Update the info of GROUP to say that ARTICLES are read."
5468   (let* ((num 0)
5469          (entry (gnus-gethash group gnus-newsrc-hashtb))
5470          (info (nth 2 entry))
5471          (active (gnus-active group))
5472          range)
5473     (when entry
5474       (setq range (gnus-compute-read-articles group articles))
5475       (save-excursion
5476         (set-buffer gnus-group-buffer)
5477         (gnus-undo-register
5478           `(progn
5479              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5480              (gnus-info-set-read ',info ',(gnus-info-read info))
5481              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5482              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5483              (gnus-group-update-group ,group t))))
5484       ;; Add the read articles to the range.
5485       (gnus-info-set-read info range)
5486       (gnus-request-set-mark group (list (list range 'add '(read))))
5487       ;; Then we have to re-compute how many unread
5488       ;; articles there are in this group.
5489       (when active
5490         (cond
5491          ((not range)
5492           (setq num (- (1+ (cdr active)) (car active))))
5493          ((not (listp (cdr range)))
5494           (setq num (- (cdr active) (- (1+ (cdr range))
5495                                        (car range)))))
5496          (t
5497           (while range
5498             (if (numberp (car range))
5499                 (setq num (1+ num))
5500               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5501             (setq range (cdr range)))
5502           (setq num (- (cdr active) num))))
5503         ;; Update the number of unread articles.
5504         (setcar entry num)
5505         ;; Update the group buffer.
5506         (gnus-group-update-group group t)))))
5507
5508 (defvar gnus-newsgroup-none-id 0)
5509
5510 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5511   (let ((cur nntp-server-buffer)
5512         (dependencies
5513          (or dependencies
5514              (save-excursion (set-buffer gnus-summary-buffer)
5515                              gnus-newsgroup-dependencies)))
5516         headers id end ref
5517         (mail-parse-charset gnus-newsgroup-charset)
5518         (mail-parse-ignored-charsets
5519          (save-excursion (condition-case nil
5520                              (set-buffer gnus-summary-buffer)
5521                            (error))
5522                          gnus-newsgroup-ignored-charsets)))
5523     (save-excursion
5524       (set-buffer nntp-server-buffer)
5525       ;; Translate all TAB characters into SPACE characters.
5526       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5527       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5528       (gnus-run-hooks 'gnus-parse-headers-hook)
5529       (let ((case-fold-search t)
5530             in-reply-to header p lines chars)
5531         (goto-char (point-min))
5532         ;; Search to the beginning of the next header.  Error messages
5533         ;; do not begin with 2 or 3.
5534         (while (re-search-forward "^[23][0-9]+ " nil t)
5535           (setq id nil
5536                 ref nil)
5537           ;; This implementation of this function, with nine
5538           ;; search-forwards instead of the one re-search-forward and
5539           ;; a case (which basically was the old function) is actually
5540           ;; about twice as fast, even though it looks messier.  You
5541           ;; can't have everything, I guess.  Speed and elegance
5542           ;; doesn't always go hand in hand.
5543           (setq
5544            header
5545            (vector
5546             ;; Number.
5547             (prog1
5548                 (read cur)
5549               (end-of-line)
5550               (setq p (point))
5551               (narrow-to-region (point)
5552                                 (or (and (search-forward "\n.\n" nil t)
5553                                          (- (point) 2))
5554                                     (point))))
5555             ;; Subject.
5556             (progn
5557               (goto-char p)
5558               (if (search-forward "\nsubject:" nil t)
5559                   (funcall gnus-decode-encoded-word-function
5560                            (nnheader-header-value))
5561                 "(none)"))
5562             ;; From.
5563             (progn
5564               (goto-char p)
5565               (if (search-forward "\nfrom:" nil t)
5566                   (funcall gnus-decode-encoded-word-function
5567                            (nnheader-header-value))
5568                 "(nobody)"))
5569             ;; Date.
5570             (progn
5571               (goto-char p)
5572               (if (search-forward "\ndate:" nil t)
5573                   (nnheader-header-value) ""))
5574             ;; Message-ID.
5575             (progn
5576               (goto-char p)
5577               (setq id (if (re-search-forward
5578                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5579                            ;; We do it this way to make sure the Message-ID
5580                            ;; is (somewhat) syntactically valid.
5581                            (buffer-substring (match-beginning 1)
5582                                              (match-end 1))
5583                          ;; If there was no message-id, we just fake one
5584                          ;; to make subsequent routines simpler.
5585                          (nnheader-generate-fake-message-id))))
5586             ;; References.
5587             (progn
5588               (goto-char p)
5589               (if (search-forward "\nreferences:" nil t)
5590                   (progn
5591                     (setq end (point))
5592                     (prog1
5593                         (nnheader-header-value)
5594                       (setq ref
5595                             (buffer-substring
5596                              (progn
5597                                (end-of-line)
5598                                (search-backward ">" end t)
5599                                (1+ (point)))
5600                              (progn
5601                                (search-backward "<" end t)
5602                                (point))))))
5603                 ;; Get the references from the in-reply-to header if there
5604                 ;; were no references and the in-reply-to header looks
5605                 ;; promising.
5606                 (if (and (search-forward "\nin-reply-to:" nil t)
5607                          (setq in-reply-to (nnheader-header-value))
5608                          (string-match "<[^>]+>" in-reply-to))
5609                     (let (ref2)
5610                       (setq ref (substring in-reply-to (match-beginning 0)
5611                                            (match-end 0)))
5612                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5613                         (setq ref2 (substring in-reply-to (match-beginning 0)
5614                                               (match-end 0)))
5615                         (when (> (length ref2) (length ref))
5616                           (setq ref ref2)))
5617                       ref)
5618                   (setq ref nil))))
5619             ;; Chars.
5620             (progn
5621               (goto-char p)
5622               (if (search-forward "\nchars: " nil t)
5623                   (if (numberp (setq chars (ignore-errors (read cur))))
5624                       chars -1)
5625                 -1))
5626             ;; Lines.
5627             (progn
5628               (goto-char p)
5629               (if (search-forward "\nlines: " nil t)
5630                   (if (numberp (setq lines (ignore-errors (read cur))))
5631                       lines -1)
5632                 -1))
5633             ;; Xref.
5634             (progn
5635               (goto-char p)
5636               (and (search-forward "\nxref:" nil t)
5637                    (nnheader-header-value)))
5638             ;; Extra.
5639             (when gnus-extra-headers
5640               (let ((extra gnus-extra-headers)
5641                     out)
5642                 (while extra
5643                   (goto-char p)
5644                   (when (search-forward
5645                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5646                     (push (cons (car extra) (nnheader-header-value))
5647                           out))
5648                   (pop extra))
5649                 out))))
5650           (when (equal id ref)
5651             (setq ref nil))
5652
5653           (when gnus-alter-header-function
5654             (funcall gnus-alter-header-function header)
5655             (setq id (mail-header-id header)
5656                   ref (gnus-parent-id (mail-header-references header))))
5657
5658           (when (setq header
5659                       (gnus-dependencies-add-header
5660                        header dependencies force-new))
5661             (push header headers))
5662           (goto-char (point-max))
5663           (widen))
5664         (nreverse headers)))))
5665
5666 ;; Goes through the xover lines and returns a list of vectors
5667 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5668                                                   force-new dependencies
5669                                                   group also-fetch-heads)
5670   "Parse the news overview data in the server buffer.
5671 Return a list of headers that match SEQUENCE (see
5672 `nntp-retrieve-headers')."
5673   ;; Get the Xref when the users reads the articles since most/some
5674   ;; NNTP servers do not include Xrefs when using XOVER.
5675   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5676   (let ((mail-parse-charset gnus-newsgroup-charset)
5677         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5678         (cur nntp-server-buffer)
5679         (dependencies (or dependencies gnus-newsgroup-dependencies))
5680         (allp (cond
5681                ((eq gnus-read-all-available-headers t)
5682                 t)
5683                ((stringp gnus-read-all-available-headers)
5684                 (string-match gnus-read-all-available-headers group))
5685                (t
5686                 nil)))
5687         number headers header)
5688     (save-excursion
5689       (set-buffer nntp-server-buffer)
5690       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5691       ;; Allow the user to mangle the headers before parsing them.
5692       (gnus-run-hooks 'gnus-parse-headers-hook)
5693       (goto-char (point-min))
5694       (gnus-parse-without-error
5695         (while (and (or sequence allp)
5696                     (not (eobp)))
5697           (setq number (read cur))
5698           (when (not allp)
5699             (while (and sequence
5700                         (< (car sequence) number))
5701               (setq sequence (cdr sequence))))
5702           (when (and (or allp
5703                          (and sequence
5704                               (eq number (car sequence))))
5705                      (progn
5706                        (setq sequence (cdr sequence))
5707                        (setq header (inline
5708                                       (gnus-nov-parse-line
5709                                        number dependencies force-new)))))
5710             (push header headers))
5711           (forward-line 1)))
5712       ;; A common bug in inn is that if you have posted an article and
5713       ;; then retrieves the active file, it will answer correctly --
5714       ;; the new article is included.  However, a NOV entry for the
5715       ;; article may not have been generated yet, so this may fail.
5716       ;; We work around this problem by retrieving the last few
5717       ;; headers using HEAD.
5718       (if (or (not also-fetch-heads)
5719               (not sequence))
5720           ;; We (probably) got all the headers.
5721           (nreverse headers)
5722         (let ((gnus-nov-is-evil t))
5723           (nconc
5724            (nreverse headers)
5725            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5726              (gnus-get-newsgroup-headers))))))))
5727
5728 (defun gnus-article-get-xrefs ()
5729   "Fill in the Xref value in `gnus-current-headers', if necessary.
5730 This is meant to be called in `gnus-article-internal-prepare-hook'."
5731   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5732                                  gnus-current-headers)))
5733     (or (not gnus-use-cross-reference)
5734         (not headers)
5735         (and (mail-header-xref headers)
5736              (not (string= (mail-header-xref headers) "")))
5737         (let ((case-fold-search t)
5738               xref)
5739           (save-restriction
5740             (nnheader-narrow-to-headers)
5741             (goto-char (point-min))
5742             (when (or (and (not (eobp))
5743                            (eq (downcase (char-after)) ?x)
5744                            (looking-at "Xref:"))
5745                       (search-forward "\nXref:" nil t))
5746               (goto-char (1+ (match-end 0)))
5747               (setq xref (buffer-substring (point)
5748                                            (progn (end-of-line) (point))))
5749               (mail-header-set-xref headers xref)))))))
5750
5751 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5752   "Find article ID and insert the summary line for that article.
5753 OLD-HEADER can either be a header or a line number to insert
5754 the subject line on."
5755   (let* ((line (and (numberp old-header) old-header))
5756          (old-header (and (vectorp old-header) old-header))
5757          (header (cond ((and old-header use-old-header)
5758                         old-header)
5759                        ((and (numberp id)
5760                              (gnus-number-to-header id))
5761                         (gnus-number-to-header id))
5762                        (t
5763                         (gnus-read-header id))))
5764          (number (and (numberp id) id))
5765          d)
5766     (when header
5767       ;; Rebuild the thread that this article is part of and go to the
5768       ;; article we have fetched.
5769       (when (and (not gnus-show-threads)
5770                  old-header)
5771         (when (and number
5772                    (setq d (gnus-data-find (mail-header-number old-header))))
5773           (goto-char (gnus-data-pos d))
5774           (gnus-data-remove
5775            number
5776            (- (gnus-point-at-bol)
5777               (prog1
5778                   (1+ (gnus-point-at-eol))
5779                 (gnus-delete-line))))))
5780       (when old-header
5781         (mail-header-set-number header (mail-header-number old-header)))
5782       (setq gnus-newsgroup-sparse
5783             (delq (setq number (mail-header-number header))
5784                   gnus-newsgroup-sparse))
5785       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5786       (push number gnus-newsgroup-limit)
5787       (gnus-rebuild-thread (mail-header-id header) line)
5788       (gnus-summary-goto-subject number nil t))
5789     (when (and (numberp number)
5790                (> number 0))
5791       ;; We have to update the boundaries even if we can't fetch the
5792       ;; article if ID is a number -- so that the next `P' or `N'
5793       ;; command will fetch the previous (or next) article even
5794       ;; if the one we tried to fetch this time has been canceled.
5795       (when (> number gnus-newsgroup-end)
5796         (setq gnus-newsgroup-end number))
5797       (when (< number gnus-newsgroup-begin)
5798         (setq gnus-newsgroup-begin number))
5799       (setq gnus-newsgroup-unselected
5800             (delq number gnus-newsgroup-unselected)))
5801     ;; Report back a success?
5802     (and header (mail-header-number header))))
5803
5804 ;;; Process/prefix in the summary buffer
5805
5806 (defun gnus-summary-work-articles (n)
5807   "Return a list of articles to be worked upon.
5808 The prefix argument, the list of process marked articles, and the
5809 current article will be taken into consideration."
5810   (save-excursion
5811     (set-buffer gnus-summary-buffer)
5812     (cond
5813      (n
5814       ;; A numerical prefix has been given.
5815       (setq n (prefix-numeric-value n))
5816       (let ((backward (< n 0))
5817             (n (abs (prefix-numeric-value n)))
5818             articles article)
5819         (save-excursion
5820           (while
5821               (and (> n 0)
5822                    (push (setq article (gnus-summary-article-number))
5823                          articles)
5824                    (if backward
5825                        (gnus-summary-find-prev nil article)
5826                      (gnus-summary-find-next nil article)))
5827             (decf n)))
5828         (nreverse articles)))
5829      ((and (gnus-region-active-p) (mark))
5830       (message "region active")
5831       ;; Work on the region between point and mark.
5832       (let ((max (max (point) (mark)))
5833             articles article)
5834         (save-excursion
5835           (goto-char (min (min (point) (mark))))
5836           (while
5837               (and
5838                (push (setq article (gnus-summary-article-number)) articles)
5839                (gnus-summary-find-next nil article)
5840                (< (point) max)))
5841           (nreverse articles))))
5842      (gnus-newsgroup-processable
5843       ;; There are process-marked articles present.
5844       ;; Save current state.
5845       (gnus-summary-save-process-mark)
5846       ;; Return the list.
5847       (reverse gnus-newsgroup-processable))
5848      (t
5849       ;; Just return the current article.
5850       (list (gnus-summary-article-number))))))
5851
5852 (defmacro gnus-summary-iterate (arg &rest forms)
5853   "Iterate over the process/prefixed articles and do FORMS.
5854 ARG is the interactive prefix given to the command.  FORMS will be
5855 executed with point over the summary line of the articles."
5856   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5857     `(let ((,articles (gnus-summary-work-articles ,arg)))
5858        (while ,articles
5859          (gnus-summary-goto-subject (car ,articles))
5860          ,@forms
5861          (pop ,articles)))))
5862
5863 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5864 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5865
5866 (defun gnus-summary-save-process-mark ()
5867   "Push the current set of process marked articles on the stack."
5868   (interactive)
5869   (push (copy-sequence gnus-newsgroup-processable)
5870         gnus-newsgroup-process-stack))
5871
5872 (defun gnus-summary-kill-process-mark ()
5873   "Push the current set of process marked articles on the stack and unmark."
5874   (interactive)
5875   (gnus-summary-save-process-mark)
5876   (gnus-summary-unmark-all-processable))
5877
5878 (defun gnus-summary-yank-process-mark ()
5879   "Pop the last process mark state off the stack and restore it."
5880   (interactive)
5881   (unless gnus-newsgroup-process-stack
5882     (error "Empty mark stack"))
5883   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5884
5885 (defun gnus-summary-process-mark-set (set)
5886   "Make SET into the current process marked articles."
5887   (gnus-summary-unmark-all-processable)
5888   (while set
5889     (gnus-summary-set-process-mark (pop set))))
5890
5891 ;;; Searching and stuff
5892
5893 (defun gnus-summary-search-group (&optional backward use-level)
5894   "Search for next unread newsgroup.
5895 If optional argument BACKWARD is non-nil, search backward instead."
5896   (save-excursion
5897     (set-buffer gnus-group-buffer)
5898     (when (gnus-group-search-forward
5899            backward nil (if use-level (gnus-group-group-level) nil))
5900       (gnus-group-group-name))))
5901
5902 (defun gnus-summary-best-group (&optional exclude-group)
5903   "Find the name of the best unread group.
5904 If EXCLUDE-GROUP, do not go to this group."
5905   (save-excursion
5906     (set-buffer gnus-group-buffer)
5907     (save-excursion
5908       (gnus-group-best-unread-group exclude-group))))
5909
5910 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5911   (if backward (gnus-summary-find-prev)
5912     (let* ((dummy (gnus-summary-article-intangible-p))
5913            (article (or article (gnus-summary-article-number)))
5914            (arts (gnus-data-find-list article))
5915            result)
5916       (when (and (not dummy)
5917                  (or (not gnus-summary-check-current)
5918                      (not unread)
5919                      (not (gnus-data-unread-p (car arts)))))
5920         (setq arts (cdr arts)))
5921       (when (setq result
5922                   (if unread
5923                       (progn
5924                         (while arts
5925                           (when (or (and undownloaded
5926                                          (eq gnus-undownloaded-mark
5927                                              (gnus-data-mark (car arts))))
5928                                     (gnus-data-unread-p (car arts)))
5929                             (setq result (car arts)
5930                                   arts nil))
5931                           (setq arts (cdr arts)))
5932                         result)
5933                     (car arts)))
5934         (goto-char (gnus-data-pos result))
5935         (gnus-data-number result)))))
5936
5937 (defun gnus-summary-find-prev (&optional unread article)
5938   (let* ((eobp (eobp))
5939          (article (or article (gnus-summary-article-number)))
5940          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5941          result)
5942     (when (and (not eobp)
5943                (or (not gnus-summary-check-current)
5944                    (not unread)
5945                    (not (gnus-data-unread-p (car arts)))))
5946       (setq arts (cdr arts)))
5947     (when (setq result
5948                 (if unread
5949                     (progn
5950                       (while arts
5951                         (when (gnus-data-unread-p (car arts))
5952                           (setq result (car arts)
5953                                 arts nil))
5954                         (setq arts (cdr arts)))
5955                       result)
5956                   (car arts)))
5957       (goto-char (gnus-data-pos result))
5958       (gnus-data-number result))))
5959
5960 (defun gnus-summary-find-subject (subject &optional unread backward article)
5961   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5962          (article (or article (gnus-summary-article-number)))
5963          (articles (gnus-data-list backward))
5964          (arts (gnus-data-find-list article articles))
5965          result)
5966     (when (or (not gnus-summary-check-current)
5967               (not unread)
5968               (not (gnus-data-unread-p (car arts))))
5969       (setq arts (cdr arts)))
5970     (while arts
5971       (and (or (not unread)
5972                (gnus-data-unread-p (car arts)))
5973            (vectorp (gnus-data-header (car arts)))
5974            (gnus-subject-equal
5975             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5976            (setq result (car arts)
5977                  arts nil))
5978       (setq arts (cdr arts)))
5979     (and result
5980          (goto-char (gnus-data-pos result))
5981          (gnus-data-number result))))
5982
5983 (defun gnus-summary-search-forward (&optional unread subject backward)
5984   "Search forward for an article.
5985 If UNREAD, look for unread articles.  If SUBJECT, look for
5986 articles with that subject.  If BACKWARD, search backward instead."
5987   (cond (subject (gnus-summary-find-subject subject unread backward))
5988         (backward (gnus-summary-find-prev unread))
5989         (t (gnus-summary-find-next unread))))
5990
5991 (defun gnus-recenter (&optional n)
5992   "Center point in window and redisplay frame.
5993 Also do horizontal recentering."
5994   (interactive "P")
5995   (when (and gnus-auto-center-summary
5996              (not (eq gnus-auto-center-summary 'vertical)))
5997     (gnus-horizontal-recenter))
5998   (recenter n))
5999
6000 (defun gnus-summary-recenter ()
6001   "Center point in the summary window.
6002 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6003 displayed, no centering will be performed."
6004   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6005 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6006   (interactive)
6007   (let* ((top (cond ((< (window-height) 4) 0)
6008                     ((< (window-height) 7) 1)
6009                     (t (if (numberp gnus-auto-center-summary)
6010                            gnus-auto-center-summary
6011                          2))))
6012          (height (1- (window-height)))
6013          (bottom (save-excursion (goto-char (point-max))
6014                                  (forward-line (- height))
6015                                  (point)))
6016          (window (get-buffer-window (current-buffer))))
6017     ;; The user has to want it.
6018     (when gnus-auto-center-summary
6019       (when (get-buffer-window gnus-article-buffer)
6020         ;; Only do recentering when the article buffer is displayed,
6021       ;; Set the window start to either `bottom', which is the biggest
6022         ;; possible valid number, or the second line from the top,
6023         ;; whichever is the least.
6024         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6025           (if (> bottom top-pos)
6026               ;; Keep the second line from the top visible
6027               (set-window-start window top-pos t)
6028             ;; Try to keep the bottom line visible; if it's partially
6029             ;; obscured, either scroll one more line to make it fully
6030             ;; visible, or revert to using TOP-POS.
6031             (save-excursion
6032               (goto-char (point-max))
6033               (forward-line -1)
6034               (let ((last-line-start (point)))
6035                 (goto-char bottom)
6036                 (set-window-start window (point) t)
6037                 (when (not (pos-visible-in-window-p last-line-start window))
6038                   (forward-line 1)
6039                   (set-window-start window (min (point) top-pos) t)))))))
6040       ;; Do horizontal recentering while we're at it.
6041       (when (and (get-buffer-window (current-buffer) t)
6042                  (not (eq gnus-auto-center-summary 'vertical)))
6043         (let ((selected (selected-window)))
6044           (select-window (get-buffer-window (current-buffer) t))
6045           (gnus-summary-position-point)
6046           (gnus-horizontal-recenter)
6047           (select-window selected))))))
6048
6049 (defun gnus-summary-jump-to-group (newsgroup)
6050   "Move point to NEWSGROUP in group mode buffer."
6051   ;; Keep update point of group mode buffer if visible.
6052   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6053       (save-window-excursion
6054         ;; Take care of tree window mode.
6055         (when (get-buffer-window gnus-group-buffer)
6056           (pop-to-buffer gnus-group-buffer))
6057         (gnus-group-jump-to-group newsgroup))
6058     (save-excursion
6059       ;; Take care of tree window mode.
6060       (if (get-buffer-window gnus-group-buffer)
6061           (pop-to-buffer gnus-group-buffer)
6062         (set-buffer gnus-group-buffer))
6063       (gnus-group-jump-to-group newsgroup))))
6064
6065 ;; This function returns a list of article numbers based on the
6066 ;; difference between the ranges of read articles in this group and
6067 ;; the range of active articles.
6068 (defun gnus-list-of-unread-articles (group)
6069   (let* ((read (gnus-info-read (gnus-get-info group)))
6070          (active (or (gnus-active group) (gnus-activate-group group)))
6071          (last (cdr active))
6072          first nlast unread)
6073     ;; If none are read, then all are unread.
6074     (if (not read)
6075         (setq first (car active))
6076       ;; If the range of read articles is a single range, then the
6077       ;; first unread article is the article after the last read
6078       ;; article.  Sounds logical, doesn't it?
6079       (if (and (not (listp (cdr read)))
6080                (or (< (car read) (car active))
6081                    (progn (setq read (list read))
6082                           nil)))
6083           (setq first (max (car active) (1+ (cdr read))))
6084         ;; `read' is a list of ranges.
6085         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6086                                   (caar read)))
6087                   1)
6088           (setq first (car active)))
6089         (while read
6090           (when first
6091             (while (< first nlast)
6092               (push first unread)
6093               (setq first (1+ first))))
6094           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6095           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6096           (setq read (cdr read)))))
6097     ;; And add the last unread articles.
6098     (while (<= first last)
6099       (push first unread)
6100       (setq first (1+ first)))
6101     ;; Return the list of unread articles.
6102     (delq 0 (nreverse unread))))
6103
6104 (defun gnus-list-of-read-articles (group)
6105   "Return a list of unread, unticked and non-dormant articles."
6106   (let* ((info (gnus-get-info group))
6107          (marked (gnus-info-marks info))
6108          (active (gnus-active group)))
6109     (and info active
6110          (gnus-list-range-difference
6111           (gnus-list-range-difference
6112            (gnus-sorted-complement
6113             (gnus-uncompress-range active)
6114             (gnus-list-of-unread-articles group))
6115            (cdr (assq 'dormant marked)))
6116           (cdr (assq 'tick marked))))))
6117
6118 ;; Various summary commands
6119
6120 (defun gnus-summary-select-article-buffer ()
6121   "Reconfigure windows to show article buffer."
6122   (interactive)
6123   (if (not (gnus-buffer-live-p gnus-article-buffer))
6124       (error "There is no article buffer for this summary buffer")
6125     (gnus-configure-windows 'article)
6126     (select-window (get-buffer-window gnus-article-buffer))))
6127
6128 (defun gnus-summary-universal-argument (arg)
6129   "Perform any operation on all articles that are process/prefixed."
6130   (interactive "P")
6131   (let ((articles (gnus-summary-work-articles arg))
6132         func article)
6133     (if (eq
6134          (setq
6135           func
6136           (key-binding
6137            (read-key-sequence
6138             (substitute-command-keys
6139              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6140          'undefined)
6141         (gnus-error 1 "Undefined key")
6142       (save-excursion
6143         (while articles
6144           (gnus-summary-goto-subject (setq article (pop articles)))
6145           (let (gnus-newsgroup-processable)
6146             (command-execute func))
6147           (gnus-summary-remove-process-mark article)))))
6148   (gnus-summary-position-point))
6149
6150 (defun gnus-summary-toggle-truncation (&optional arg)
6151   "Toggle truncation of summary lines.
6152 With arg, turn line truncation on if arg is positive."
6153   (interactive "P")
6154   (setq truncate-lines
6155         (if (null arg) (not truncate-lines)
6156           (> (prefix-numeric-value arg) 0)))
6157   (redraw-display))
6158
6159 (defun gnus-summary-find-uncancelled ()
6160   "Return the number of an uncancelled article.
6161 The current article is considered, then following articles, then previous
6162 articles.  If all articles are cancelled then return a dummy 0."
6163   (let (found)
6164     (dolist (rev '(nil t))
6165       (unless found      ; don't demand the reverse list if we don't need it
6166         (let ((data (gnus-data-find-list
6167                      (gnus-summary-article-number) (gnus-data-list rev))))
6168           (while (and data (not found))
6169             (if (not (eq gnus-canceled-mark (gnus-data-mark (car data))))
6170                 (setq found (gnus-data-number (car data))))
6171             (setq data (cdr data))))))
6172     (or found 0)))
6173
6174 (defun gnus-summary-reselect-current-group (&optional all rescan)
6175   "Exit and then reselect the current newsgroup.
6176 The prefix argument ALL means to select all articles."
6177   (interactive "P")
6178   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6179     (error "Ephemeral groups can't be reselected"))
6180   (let ((current-subject (gnus-summary-find-uncancelled))
6181         (group gnus-newsgroup-name))
6182     (setq gnus-newsgroup-begin nil)
6183     (gnus-summary-exit)
6184     ;; We have to adjust the point of group mode buffer because
6185     ;; point was moved to the next unread newsgroup by exiting.
6186     (gnus-summary-jump-to-group group)
6187     (when rescan
6188       (save-excursion
6189         (gnus-group-get-new-news-this-group 1)))
6190     (gnus-group-read-group all t)
6191     (gnus-summary-goto-subject current-subject nil t)))
6192
6193 (defun gnus-summary-rescan-group (&optional all)
6194   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6195   (interactive "P")
6196   (gnus-summary-reselect-current-group all t))
6197
6198 (defun gnus-summary-update-info (&optional non-destructive)
6199   (save-excursion
6200     (let ((group gnus-newsgroup-name))
6201       (when group
6202         (when gnus-newsgroup-kill-headers
6203           (setq gnus-newsgroup-killed
6204                 (gnus-compress-sequence
6205                  (gnus-sorted-union
6206                   (gnus-list-range-intersection
6207                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6208                   gnus-newsgroup-unreads)
6209                  t)))
6210         (unless (listp (cdr gnus-newsgroup-killed))
6211           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6212         (let ((headers gnus-newsgroup-headers))
6213           ;; Set the new ranges of read articles.
6214           (save-excursion
6215             (set-buffer gnus-group-buffer)
6216             (gnus-undo-force-boundary))
6217           (gnus-update-read-articles
6218            group (gnus-sorted-union
6219                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6220           ;; Set the current article marks.
6221           (let ((gnus-newsgroup-scored
6222                  (if (and (not gnus-save-score)
6223                           (not non-destructive))
6224                      nil
6225                    gnus-newsgroup-scored)))
6226             (save-excursion
6227               (gnus-update-marks)))
6228           ;; Do the cross-ref thing.
6229           (when gnus-use-cross-reference
6230             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6231           ;; Do not switch windows but change the buffer to work.
6232           (set-buffer gnus-group-buffer)
6233           (unless (gnus-ephemeral-group-p group)
6234             (gnus-group-update-group group)))))))
6235
6236 (defun gnus-summary-save-newsrc (&optional force)
6237   "Save the current number of read/marked articles in the dribble buffer.
6238 The dribble buffer will then be saved.
6239 If FORCE (the prefix), also save the .newsrc file(s)."
6240   (interactive "P")
6241   (gnus-summary-update-info t)
6242   (if force
6243       (gnus-save-newsrc-file)
6244     (gnus-dribble-save)))
6245
6246 (defun gnus-summary-exit (&optional temporary)
6247   "Exit reading current newsgroup, and then return to group selection mode.
6248 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6249   (interactive)
6250   (gnus-set-global-variables)
6251   (when (gnus-buffer-live-p gnus-article-buffer)
6252     (save-excursion
6253       (set-buffer gnus-article-buffer)
6254       (mm-destroy-parts gnus-article-mime-handles)
6255       ;; Set it to nil for safety reason.
6256       (setq gnus-article-mime-handle-alist nil)
6257       (setq gnus-article-mime-handles nil)))
6258   (gnus-kill-save-kill-buffer)
6259   (gnus-async-halt-prefetch)
6260   (let* ((group gnus-newsgroup-name)
6261          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6262          (mode major-mode)
6263          (group-point nil)
6264          (buf (current-buffer)))
6265     (unless quit-config
6266       ;; Do adaptive scoring, and possibly save score files.
6267       (when gnus-newsgroup-adaptive
6268         (gnus-score-adaptive))
6269       (when gnus-use-scoring
6270         (gnus-score-save)))
6271     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6272     ;; If we have several article buffers, we kill them at exit.
6273     (unless gnus-single-article-buffer
6274       (gnus-kill-buffer gnus-original-article-buffer)
6275       (setq gnus-article-current nil))
6276     (when gnus-use-cache
6277       (gnus-cache-possibly-remove-articles)
6278       (gnus-cache-save-buffers))
6279     (gnus-async-prefetch-remove-group group)
6280     (when gnus-suppress-duplicates
6281       (gnus-dup-enter-articles))
6282     (when gnus-use-trees
6283       (gnus-tree-close group))
6284     (when gnus-use-cache
6285       (gnus-cache-write-active))
6286     ;; Remove entries for this group.
6287     (nnmail-purge-split-history (gnus-group-real-name group))
6288     ;; Make all changes in this group permanent.
6289     (unless quit-config
6290       (gnus-run-hooks 'gnus-exit-group-hook)
6291       (gnus-summary-update-info))
6292     (gnus-close-group group)
6293     ;; Make sure where we were, and go to next newsgroup.
6294     (set-buffer gnus-group-buffer)
6295     (unless quit-config
6296       (gnus-group-jump-to-group group))
6297     (gnus-run-hooks 'gnus-summary-exit-hook)
6298     (unless (or quit-config
6299                 ;; If this group has disappeared from the summary
6300                 ;; buffer, don't skip forwards.
6301                 (not (string= group (gnus-group-group-name))))
6302       (gnus-group-next-unread-group 1))
6303     (setq group-point (point))
6304     (if temporary
6305         nil                             ;Nothing to do.
6306       ;; If we have several article buffers, we kill them at exit.
6307       (unless gnus-single-article-buffer
6308         (gnus-kill-buffer gnus-article-buffer)
6309         (gnus-kill-buffer gnus-original-article-buffer)
6310         (setq gnus-article-current nil))
6311       (set-buffer buf)
6312       (if (not gnus-kill-summary-on-exit)
6313           (progn
6314             (gnus-deaden-summary)
6315             (setq mode nil))
6316        ;; We set all buffer-local variables to nil.  It is unclear why
6317         ;; this is needed, but if we don't, buffer-local variables are
6318         ;; not garbage-collected, it seems.  This would the lead to en
6319         ;; ever-growing Emacs.
6320         (gnus-summary-clear-local-variables)
6321         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6322           (gnus-summary-clear-local-variables))
6323         (when (get-buffer gnus-article-buffer)
6324           (bury-buffer gnus-article-buffer))
6325         ;; We clear the global counterparts of the buffer-local
6326         ;; variables as well, just to be on the safe side.
6327         (set-buffer gnus-group-buffer)
6328         (gnus-summary-clear-local-variables)
6329         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6330           (gnus-summary-clear-local-variables)))
6331       (setq gnus-current-select-method gnus-select-method)
6332       (pop-to-buffer gnus-group-buffer)
6333       (if (not quit-config)
6334           (progn
6335             (goto-char group-point)
6336             (gnus-configure-windows 'group 'force))
6337         (gnus-handle-ephemeral-exit quit-config))
6338       ;; Return to group mode buffer.
6339       (when (eq mode 'gnus-summary-mode)
6340         (gnus-kill-buffer buf))
6341       ;; Clear the current group name.
6342       (unless quit-config
6343         (setq gnus-newsgroup-name nil)))))
6344
6345 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6346 (defun gnus-summary-exit-no-update (&optional no-questions)
6347   "Quit reading current newsgroup without updating read article info."
6348   (interactive)
6349   (let* ((group gnus-newsgroup-name)
6350          (quit-config (gnus-group-quit-config group)))
6351     (when (or no-questions
6352               gnus-expert-user
6353               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6354       (gnus-async-halt-prefetch)
6355       (mapcar 'funcall
6356               (delq 'gnus-summary-expire-articles
6357                     (copy-sequence gnus-summary-prepare-exit-hook)))
6358       (when (gnus-buffer-live-p gnus-article-buffer)
6359         (save-excursion
6360           (set-buffer gnus-article-buffer)
6361           (mm-destroy-parts gnus-article-mime-handles)
6362           ;; Set it to nil for safety reason.
6363           (setq gnus-article-mime-handle-alist nil)
6364           (setq gnus-article-mime-handles nil)))
6365       ;; If we have several article buffers, we kill them at exit.
6366       (unless gnus-single-article-buffer
6367         (gnus-kill-buffer gnus-article-buffer)
6368         (gnus-kill-buffer gnus-original-article-buffer)
6369         (setq gnus-article-current nil))
6370       (if (not gnus-kill-summary-on-exit)
6371           (gnus-deaden-summary)
6372         (gnus-close-group group)
6373         (gnus-summary-clear-local-variables)
6374         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6375           (gnus-summary-clear-local-variables))
6376         (set-buffer gnus-group-buffer)
6377         (gnus-summary-clear-local-variables)
6378         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6379           (gnus-summary-clear-local-variables))
6380         (when (get-buffer gnus-summary-buffer)
6381           (kill-buffer gnus-summary-buffer)))
6382       (unless gnus-single-article-buffer
6383         (setq gnus-article-current nil))
6384       (when gnus-use-trees
6385         (gnus-tree-close group))
6386       (gnus-async-prefetch-remove-group group)
6387       (when (get-buffer gnus-article-buffer)
6388         (bury-buffer gnus-article-buffer))
6389       ;; Return to the group buffer.
6390       (gnus-configure-windows 'group 'force)
6391       ;; Clear the current group name.
6392       (setq gnus-newsgroup-name nil)
6393       (when (equal (gnus-group-group-name) group)
6394         (gnus-group-next-unread-group 1))
6395       (when quit-config
6396         (gnus-handle-ephemeral-exit quit-config)))))
6397
6398 (defun gnus-handle-ephemeral-exit (quit-config)
6399   "Handle movement when leaving an ephemeral group.
6400 The state which existed when entering the ephemeral is reset."
6401   (if (not (buffer-name (car quit-config)))
6402       (gnus-configure-windows 'group 'force)
6403     (set-buffer (car quit-config))
6404     (cond ((eq major-mode 'gnus-summary-mode)
6405            (gnus-set-global-variables))
6406           ((eq major-mode 'gnus-article-mode)
6407            (save-excursion
6408              ;; The `gnus-summary-buffer' variable may point
6409              ;; to the old summary buffer when using a single
6410              ;; article buffer.
6411              (unless (gnus-buffer-live-p gnus-summary-buffer)
6412                (set-buffer gnus-group-buffer))
6413              (set-buffer gnus-summary-buffer)
6414              (gnus-set-global-variables))))
6415     (if (or (eq (cdr quit-config) 'article)
6416             (eq (cdr quit-config) 'pick))
6417         (progn
6418           ;; The current article may be from the ephemeral group
6419           ;; thus it is best that we reload this article
6420           (gnus-summary-show-article)
6421           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6422               (gnus-configure-windows 'pick 'force)
6423             (gnus-configure-windows (cdr quit-config) 'force)))
6424       (gnus-configure-windows (cdr quit-config) 'force))
6425     (when (eq major-mode 'gnus-summary-mode)
6426       (gnus-summary-next-subject 1 nil t)
6427       (gnus-summary-recenter)
6428       (gnus-summary-position-point))))
6429
6430 ;;; Dead summaries.
6431
6432 (defvar gnus-dead-summary-mode-map nil)
6433
6434 (unless gnus-dead-summary-mode-map
6435   (setq gnus-dead-summary-mode-map (make-keymap))
6436   (suppress-keymap gnus-dead-summary-mode-map)
6437   (substitute-key-definition
6438    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6439   (dolist (key '("\C-d" "\r" "\177" [delete]))
6440     (define-key gnus-dead-summary-mode-map
6441       key 'gnus-summary-wake-up-the-dead))
6442   (dolist (key '("q" "Q"))
6443     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6444
6445 (defvar gnus-dead-summary-mode nil
6446   "Minor mode for Gnus summary buffers.")
6447
6448 (defun gnus-dead-summary-mode (&optional arg)
6449   "Minor mode for Gnus summary buffers."
6450   (interactive "P")
6451   (when (eq major-mode 'gnus-summary-mode)
6452     (make-local-variable 'gnus-dead-summary-mode)
6453     (setq gnus-dead-summary-mode
6454           (if (null arg) (not gnus-dead-summary-mode)
6455             (> (prefix-numeric-value arg) 0)))
6456     (when gnus-dead-summary-mode
6457       (gnus-add-minor-mode
6458        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6459
6460 (defun gnus-deaden-summary ()
6461   "Make the current summary buffer into a dead summary buffer."
6462   ;; Kill any previous dead summary buffer.
6463   (when (and gnus-dead-summary
6464              (buffer-name gnus-dead-summary))
6465     (save-excursion
6466       (set-buffer gnus-dead-summary)
6467       (when gnus-dead-summary-mode
6468         (kill-buffer (current-buffer)))))
6469   ;; Make this the current dead summary.
6470   (setq gnus-dead-summary (current-buffer))
6471   (gnus-dead-summary-mode 1)
6472   (let ((name (buffer-name)))
6473     (when (string-match "Summary" name)
6474       (rename-buffer
6475        (concat (substring name 0 (match-beginning 0)) "Dead "
6476                (substring name (match-beginning 0)))
6477        t)
6478       (bury-buffer))))
6479
6480 (defun gnus-kill-or-deaden-summary (buffer)
6481   "Kill or deaden the summary BUFFER."
6482   (save-excursion
6483     (when (and (buffer-name buffer)
6484                (not gnus-single-article-buffer))
6485       (save-excursion
6486         (set-buffer buffer)
6487         (gnus-kill-buffer gnus-article-buffer)
6488         (gnus-kill-buffer gnus-original-article-buffer)))
6489     (cond
6490      ;; Kill the buffer.
6491      (gnus-kill-summary-on-exit
6492       (when (and gnus-use-trees
6493                  (gnus-buffer-exists-p buffer))
6494         (save-excursion
6495           (set-buffer buffer)
6496           (gnus-tree-close gnus-newsgroup-name)))
6497       (gnus-kill-buffer buffer))
6498      ;; Deaden the buffer.
6499      ((gnus-buffer-exists-p buffer)
6500       (save-excursion
6501         (set-buffer buffer)
6502         (gnus-deaden-summary))))))
6503
6504 (defun gnus-summary-wake-up-the-dead (&rest args)
6505   "Wake up the dead summary buffer."
6506   (interactive)
6507   (gnus-dead-summary-mode -1)
6508   (let ((name (buffer-name)))
6509     (when (string-match "Dead " name)
6510       (rename-buffer
6511        (concat (substring name 0 (match-beginning 0))
6512                (substring name (match-end 0)))
6513        t)))
6514   (gnus-message 3 "This dead summary is now alive again"))
6515
6516 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6517 (defun gnus-summary-fetch-faq (&optional faq-dir)
6518   "Fetch the FAQ for the current group.
6519 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6520 in."
6521   (interactive
6522    (list
6523     (when current-prefix-arg
6524       (completing-read
6525        "FAQ dir: " (and (listp gnus-group-faq-directory)
6526                         (mapcar (lambda (file) (list file))
6527                                 gnus-group-faq-directory))))))
6528   (let (gnus-faq-buffer)
6529     (when (setq gnus-faq-buffer
6530                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6531       (gnus-configure-windows 'summary-faq))))
6532
6533 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6534 (defun gnus-summary-describe-group (&optional force)
6535   "Describe the current newsgroup."
6536   (interactive "P")
6537   (gnus-group-describe-group force gnus-newsgroup-name))
6538
6539 (defun gnus-summary-describe-briefly ()
6540   "Describe summary mode commands briefly."
6541   (interactive)
6542   (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")))
6543
6544 ;; Walking around group mode buffer from summary mode.
6545
6546 (defun gnus-summary-next-group (&optional no-article target-group backward)
6547   "Exit current newsgroup and then select next unread newsgroup.
6548 If prefix argument NO-ARTICLE is non-nil, no article is selected
6549 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6550 previous group instead."
6551   (interactive "P")
6552   ;; Stop pre-fetching.
6553   (gnus-async-halt-prefetch)
6554   (let ((current-group gnus-newsgroup-name)
6555         (current-buffer (current-buffer))
6556         entered)
6557     (while (not entered)
6558       ;; Then we find what group we are supposed to enter.
6559       (set-buffer gnus-group-buffer)
6560       (gnus-group-jump-to-group current-group)
6561       (setq target-group
6562             (or target-group
6563                 (if (eq gnus-keep-same-level 'best)
6564                     (gnus-summary-best-group gnus-newsgroup-name)
6565                   (gnus-summary-search-group backward gnus-keep-same-level))))
6566       (if (not target-group)
6567           ;; There are no further groups, so we return to the group
6568           ;; buffer.
6569           (progn
6570             (gnus-message 5 "Returning to the group buffer")
6571             (setq entered t)
6572             (when (gnus-buffer-live-p current-buffer)
6573               (set-buffer current-buffer)
6574               (gnus-summary-exit))
6575             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6576         ;; We try to enter the target group.
6577         (gnus-group-jump-to-group target-group)
6578         (let ((unreads (gnus-group-group-unread)))
6579           (if (and (or (eq t unreads)
6580                        (and unreads (not (zerop unreads))))
6581                    (progn
6582                      ;; Now we semi-exit this group to update Xrefs
6583                      ;; and all variables.  We can't do a real exit,
6584                      ;; because the window conf must remain the same
6585                      ;; in case the user is prompted for info, and we
6586                      ;; don't want the window conf to change before
6587                      ;; that...
6588                      (when (gnus-buffer-live-p current-buffer)
6589                        (set-buffer current-buffer)
6590                        (gnus-summary-exit t))
6591                      (gnus-summary-read-group
6592                       target-group nil no-article
6593                       (and (buffer-name current-buffer) current-buffer)
6594                       nil backward)))
6595               (setq entered t)
6596             (setq current-group target-group
6597                   target-group nil)))))))
6598
6599 (defun gnus-summary-prev-group (&optional no-article)
6600   "Exit current newsgroup and then select previous unread newsgroup.
6601 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6602   (interactive "P")
6603   (gnus-summary-next-group no-article nil t))
6604
6605 ;; Walking around summary lines.
6606
6607 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6608   "Go to the first unread subject.
6609 If UNREAD is non-nil, go to the first unread article.
6610 Returns the article selected or nil if there are no unread articles."
6611   (interactive "P")
6612   (prog1
6613       (cond
6614        ;; Empty summary.
6615        ((null gnus-newsgroup-data)
6616         (gnus-message 3 "No articles in the group")
6617         nil)
6618        ;; Pick the first article.
6619        ((not unread)
6620         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6621         (gnus-data-number (car gnus-newsgroup-data)))
6622        ;; No unread articles.
6623        ((null gnus-newsgroup-unreads)
6624         (gnus-message 3 "No more unread articles")
6625         nil)
6626        ;; Find the first unread article.
6627        (t
6628         (let ((data gnus-newsgroup-data))
6629           (while (and data
6630                       (and (not (and undownloaded
6631                                      (eq gnus-undownloaded-mark
6632                                          (gnus-data-mark (car data)))))
6633                            (if unseen
6634                                (or (not (memq
6635                                          (gnus-data-number (car data))
6636                                          gnus-newsgroup-unseen))
6637                                    (not (gnus-data-unread-p (car data))))
6638                              (not (gnus-data-unread-p (car data))))))
6639             (setq data (cdr data)))
6640           (when data
6641             (goto-char (gnus-data-pos (car data)))
6642             (gnus-data-number (car data))))))
6643     (gnus-summary-position-point)))
6644
6645 (defun gnus-summary-next-subject (n &optional unread dont-display)
6646   "Go to next N'th summary line.
6647 If N is negative, go to the previous N'th subject line.
6648 If UNREAD is non-nil, only unread articles are selected.
6649 The difference between N and the actual number of steps taken is
6650 returned."
6651   (interactive "p")
6652   (let ((backward (< n 0))
6653         (n (abs n)))
6654     (while (and (> n 0)
6655                 (if backward
6656                     (gnus-summary-find-prev unread)
6657                   (gnus-summary-find-next unread)))
6658       (unless (zerop (setq n (1- n)))
6659         (gnus-summary-show-thread)))
6660     (when (/= 0 n)
6661       (gnus-message 7 "No more%s articles"
6662                     (if unread " unread" "")))
6663     (unless dont-display
6664       (gnus-summary-recenter)
6665       (gnus-summary-position-point))
6666     n))
6667
6668 (defun gnus-summary-next-unread-subject (n)
6669   "Go to next N'th unread summary line."
6670   (interactive "p")
6671   (gnus-summary-next-subject n t))
6672
6673 (defun gnus-summary-prev-subject (n &optional unread)
6674   "Go to previous N'th summary line.
6675 If optional argument UNREAD is non-nil, only unread article is selected."
6676   (interactive "p")
6677   (gnus-summary-next-subject (- n) unread))
6678
6679 (defun gnus-summary-prev-unread-subject (n)
6680   "Go to previous N'th unread summary line."
6681   (interactive "p")
6682   (gnus-summary-next-subject (- n) t))
6683
6684 (defun gnus-summary-goto-subject (article &optional force silent)
6685   "Go the subject line of ARTICLE.
6686 If FORCE, also allow jumping to articles not currently shown."
6687   (interactive "nArticle number: ")
6688   (unless (numberp article)
6689     (error "Article %s is not a number" article))
6690   (let ((b (point))
6691         (data (gnus-data-find article)))
6692     ;; We read in the article if we have to.
6693     (and (not data)
6694          force
6695          (gnus-summary-insert-subject
6696           article
6697           (if (or (numberp force) (vectorp force)) force)
6698           t)
6699          (setq data (gnus-data-find article)))
6700     (goto-char b)
6701     (if (not data)
6702         (progn
6703           (unless silent
6704             (gnus-message 3 "Can't find article %d" article))
6705           nil)
6706       (let ((pt (gnus-data-pos data)))
6707         (goto-char pt)
6708         (gnus-summary-set-article-display-arrow pt))
6709       (gnus-summary-position-point)
6710       article)))
6711
6712 ;; Walking around summary lines with displaying articles.
6713
6714 (defun gnus-summary-expand-window (&optional arg)
6715   "Make the summary buffer take up the entire Emacs frame.
6716 Given a prefix, will force an `article' buffer configuration."
6717   (interactive "P")
6718   (if arg
6719       (gnus-configure-windows 'article 'force)
6720     (gnus-configure-windows 'summary 'force)))
6721
6722 (defun gnus-summary-display-article (article &optional all-header)
6723   "Display ARTICLE in article buffer."
6724   (when (gnus-buffer-live-p gnus-article-buffer)
6725     (with-current-buffer gnus-article-buffer
6726       (mm-enable-multibyte)))
6727   (gnus-set-global-variables)
6728   (when (gnus-buffer-live-p gnus-article-buffer)
6729     (with-current-buffer gnus-article-buffer
6730       (setq gnus-article-charset gnus-newsgroup-charset)
6731       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6732       (mm-enable-multibyte)))
6733   (if (null article)
6734       nil
6735     (prog1
6736         (if gnus-summary-display-article-function
6737             (funcall gnus-summary-display-article-function article all-header)
6738           (gnus-article-prepare article all-header))
6739       (gnus-run-hooks 'gnus-select-article-hook)
6740       (when (and gnus-current-article
6741                  (not (zerop gnus-current-article)))
6742         (gnus-summary-goto-subject gnus-current-article))
6743       (gnus-summary-recenter)
6744       (when (and gnus-use-trees gnus-show-threads)
6745         (gnus-possibly-generate-tree article)
6746         (gnus-highlight-selected-tree article))
6747       ;; Successfully display article.
6748       (gnus-article-set-window-start
6749        (cdr (assq article gnus-newsgroup-bookmarks))))))
6750
6751 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6752   "Select the current article.
6753 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6754 non-nil, the article will be re-fetched even if it already present in
6755 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6756 be displayed."
6757   ;; Make sure we are in the summary buffer to work around bbdb bug.
6758   (unless (eq major-mode 'gnus-summary-mode)
6759     (set-buffer gnus-summary-buffer))
6760   (let ((article (or article (gnus-summary-article-number)))
6761         (all-headers (not (not all-headers))) ;Must be t or nil.
6762         gnus-summary-display-article-function)
6763     (and (not pseudo)
6764          (gnus-summary-article-pseudo-p article)
6765          (error "This is a pseudo-article"))
6766     (save-excursion
6767       (set-buffer gnus-summary-buffer)
6768       (if (or (and gnus-single-article-buffer
6769                    (or (null gnus-current-article)
6770                        (null gnus-article-current)
6771                        (null (get-buffer gnus-article-buffer))
6772                        (not (eq article (cdr gnus-article-current)))
6773                        (not (equal (car gnus-article-current)
6774                                    gnus-newsgroup-name))))
6775               (and (not gnus-single-article-buffer)
6776                    (or (null gnus-current-article)
6777                        (not (eq gnus-current-article article))))
6778               force)
6779           ;; The requested article is different from the current article.
6780           (progn
6781             (gnus-summary-display-article article all-headers)
6782             (when (gnus-buffer-live-p gnus-article-buffer)
6783               (with-current-buffer gnus-article-buffer
6784                 (if (not gnus-article-decoded-p) ;; a local variable
6785                     (mm-disable-multibyte))))
6786             (gnus-article-set-window-start
6787              (cdr (assq article gnus-newsgroup-bookmarks)))
6788             article)
6789         'old))))
6790
6791 (defun gnus-summary-force-verify-and-decrypt ()
6792   (interactive)
6793   (let ((mm-verify-option 'known)
6794         (mm-decrypt-option 'known)
6795         (gnus-buttonized-mime-types (append (list "multipart/signed"
6796                                                   "multipart/encrypted")
6797                                             gnus-buttonized-mime-types)))
6798     (gnus-summary-select-article nil 'force)))
6799
6800 (defun gnus-summary-set-current-mark (&optional current-mark)
6801   "Obsolete function."
6802   nil)
6803
6804 (defun gnus-summary-next-article (&optional unread subject backward push)
6805   "Select the next article.
6806 If UNREAD, only unread articles are selected.
6807 If SUBJECT, only articles with SUBJECT are selected.
6808 If BACKWARD, the previous article is selected instead of the next."
6809   (interactive "P")
6810   (cond
6811    ;; Is there such an article?
6812    ((and (gnus-summary-search-forward unread subject backward)
6813          (or (gnus-summary-display-article (gnus-summary-article-number))
6814              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6815     (gnus-summary-position-point))
6816    ;; If not, we try the first unread, if that is wanted.
6817    ((and subject
6818          gnus-auto-select-same
6819          (gnus-summary-first-unread-article))
6820     (gnus-summary-position-point)
6821     (gnus-message 6 "Wrapped"))
6822    ;; Try to get next/previous article not displayed in this group.
6823    ((and gnus-auto-extend-newsgroup
6824          (not unread) (not subject))
6825     (gnus-summary-goto-article
6826      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6827      nil (count-lines (point-min) (point))))
6828    ;; Go to next/previous group.
6829    (t
6830     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6831       (gnus-summary-jump-to-group gnus-newsgroup-name))
6832     (let ((cmd last-command-char)
6833           (point
6834            (save-excursion
6835              (set-buffer gnus-group-buffer)
6836              (point)))
6837           (group
6838            (if (eq gnus-keep-same-level 'best)
6839                (gnus-summary-best-group gnus-newsgroup-name)
6840              (gnus-summary-search-group backward gnus-keep-same-level))))
6841       ;; For some reason, the group window gets selected.  We change
6842       ;; it back.
6843       (select-window (get-buffer-window (current-buffer)))
6844       ;; Select next unread newsgroup automagically.
6845       (cond
6846        ((or (not gnus-auto-select-next)
6847             (not cmd))
6848         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6849        ((or (eq gnus-auto-select-next 'quietly)
6850             (and (eq gnus-auto-select-next 'slightly-quietly)
6851                  push)
6852             (and (eq gnus-auto-select-next 'almost-quietly)
6853                  (gnus-summary-last-article-p)))
6854         ;; Select quietly.
6855         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6856             (gnus-summary-exit)
6857           (gnus-message 7 "No more%s articles (%s)..."
6858                         (if unread " unread" "")
6859                         (if group (concat "selecting " group)
6860                           "exiting"))
6861           (gnus-summary-next-group nil group backward)))
6862        (t
6863         (when (gnus-key-press-event-p last-input-event)
6864           (gnus-summary-walk-group-buffer
6865            gnus-newsgroup-name cmd unread backward point))))))))
6866
6867 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6868   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6869                       (?\C-p (gnus-group-prev-unread-group 1))))
6870         (cursor-in-echo-area t)
6871         keve key group ended)
6872     (save-excursion
6873       (set-buffer gnus-group-buffer)
6874       (goto-char start)
6875       (setq group
6876             (if (eq gnus-keep-same-level 'best)
6877                 (gnus-summary-best-group gnus-newsgroup-name)
6878               (gnus-summary-search-group backward gnus-keep-same-level))))
6879     (while (not ended)
6880       (gnus-message
6881        5 "No more%s articles%s" (if unread " unread" "")
6882        (if (and group
6883                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6884            (format " (Type %s for %s [%s])"
6885                    (single-key-description cmd) group
6886                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6887          (format " (Type %s to exit %s)"
6888                  (single-key-description cmd)
6889                  gnus-newsgroup-name)))
6890       ;; Confirm auto selection.
6891       (setq key (car (setq keve (gnus-read-event-char))))
6892       (setq ended t)
6893       (cond
6894        ((assq key keystrokes)
6895         (let ((obuf (current-buffer)))
6896           (switch-to-buffer gnus-group-buffer)
6897           (when group
6898             (gnus-group-jump-to-group group))
6899           (eval (cadr (assq key keystrokes)))
6900           (setq group (gnus-group-group-name))
6901           (switch-to-buffer obuf))
6902         (setq ended nil))
6903        ((equal key cmd)
6904         (if (or (not group)
6905                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6906             (gnus-summary-exit)
6907           (gnus-summary-next-group nil group backward)))
6908        (t
6909         (push (cdr keve) unread-command-events))))))
6910
6911 (defun gnus-summary-next-unread-article ()
6912   "Select unread article after current one."
6913   (interactive)
6914   (gnus-summary-next-article
6915    (or (not (eq gnus-summary-goto-unread 'never))
6916        (gnus-summary-last-article-p (gnus-summary-article-number)))
6917    (and gnus-auto-select-same
6918         (gnus-summary-article-subject))))
6919
6920 (defun gnus-summary-prev-article (&optional unread subject)
6921   "Select the article after the current one.
6922 If UNREAD is non-nil, only unread articles are selected."
6923   (interactive "P")
6924   (gnus-summary-next-article unread subject t))
6925
6926 (defun gnus-summary-prev-unread-article ()
6927   "Select unread article before current one."
6928   (interactive)
6929   (gnus-summary-prev-article
6930    (or (not (eq gnus-summary-goto-unread 'never))
6931        (gnus-summary-first-article-p (gnus-summary-article-number)))
6932    (and gnus-auto-select-same
6933         (gnus-summary-article-subject))))
6934
6935 (defun gnus-summary-next-page (&optional lines circular)
6936   "Show next page of the selected article.
6937 If at the end of the current article, select the next article.
6938 LINES says how many lines should be scrolled up.
6939
6940 If CIRCULAR is non-nil, go to the start of the article instead of
6941 selecting the next article when reaching the end of the current
6942 article."
6943   (interactive "P")
6944   (setq gnus-summary-buffer (current-buffer))
6945   (gnus-set-global-variables)
6946   (let ((article (gnus-summary-article-number))
6947         (article-window (get-buffer-window gnus-article-buffer t))
6948         endp)
6949     ;; If the buffer is empty, we have no article.
6950     (unless article
6951       (error "No article to select"))
6952     (gnus-configure-windows 'article)
6953     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6954         (if (and (eq gnus-summary-goto-unread 'never)
6955                  (not (gnus-summary-last-article-p article)))
6956             (gnus-summary-next-article)
6957           (gnus-summary-next-unread-article))
6958       (if (or (null gnus-current-article)
6959               (null gnus-article-current)
6960               (/= article (cdr gnus-article-current))
6961               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6962           ;; Selected subject is different from current article's.
6963           (gnus-summary-display-article article)
6964         (when article-window
6965           (gnus-eval-in-buffer-window gnus-article-buffer
6966             (setq endp (gnus-article-next-page lines)))
6967           (when endp
6968             (cond (circular
6969                    (gnus-summary-beginning-of-article))
6970                   (lines
6971                    (gnus-message 3 "End of message"))
6972                   ((null lines)
6973                    (if (and (eq gnus-summary-goto-unread 'never)
6974                             (not (gnus-summary-last-article-p article)))
6975                        (gnus-summary-next-article)
6976                      (gnus-summary-next-unread-article))))))))
6977     (gnus-summary-recenter)
6978     (gnus-summary-position-point)))
6979
6980 (defun gnus-summary-prev-page (&optional lines move)
6981   "Show previous page of selected article.
6982 Argument LINES specifies lines to be scrolled down.
6983 If MOVE, move to the previous unread article if point is at
6984 the beginning of the buffer."
6985   (interactive "P")
6986   (let ((article (gnus-summary-article-number))
6987         (article-window (get-buffer-window gnus-article-buffer t))
6988         endp)
6989     (gnus-configure-windows 'article)
6990     (if (or (null gnus-current-article)
6991             (null gnus-article-current)
6992             (/= article (cdr gnus-article-current))
6993             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6994         ;; Selected subject is different from current article's.
6995         (gnus-summary-display-article article)
6996       (gnus-summary-recenter)
6997       (when article-window
6998         (gnus-eval-in-buffer-window gnus-article-buffer
6999           (setq endp (gnus-article-prev-page lines)))
7000         (when (and move endp)
7001           (cond (lines
7002                  (gnus-message 3 "Beginning of message"))
7003                 ((null lines)
7004                  (if (and (eq gnus-summary-goto-unread 'never)
7005                           (not (gnus-summary-first-article-p article)))
7006                      (gnus-summary-prev-article)
7007                    (gnus-summary-prev-unread-article))))))))
7008   (gnus-summary-position-point))
7009
7010 (defun gnus-summary-prev-page-or-article (&optional lines)
7011   "Show previous page of selected article.
7012 Argument LINES specifies lines to be scrolled down.
7013 If at the beginning of the article, go to the next article."
7014   (interactive "P")
7015   (gnus-summary-prev-page lines t))
7016
7017 (defun gnus-summary-scroll-up (lines)
7018   "Scroll up (or down) one line current article.
7019 Argument LINES specifies lines to be scrolled up (or down if negative)."
7020   (interactive "p")
7021   (gnus-configure-windows 'article)
7022   (gnus-summary-show-thread)
7023   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7024     (gnus-eval-in-buffer-window gnus-article-buffer
7025       (cond ((> lines 0)
7026              (when (gnus-article-next-page lines)
7027                (gnus-message 3 "End of message")))
7028             ((< lines 0)
7029              (gnus-article-prev-page (- lines))))))
7030   (gnus-summary-recenter)
7031   (gnus-summary-position-point))
7032
7033 (defun gnus-summary-scroll-down (lines)
7034   "Scroll down (or up) one line current article.
7035 Argument LINES specifies lines to be scrolled down (or up if negative)."
7036   (interactive "p")
7037   (gnus-summary-scroll-up (- lines)))
7038
7039 (defun gnus-summary-next-same-subject ()
7040   "Select next article which has the same subject as current one."
7041   (interactive)
7042   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7043
7044 (defun gnus-summary-prev-same-subject ()
7045   "Select previous article which has the same subject as current one."
7046   (interactive)
7047   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7048
7049 (defun gnus-summary-next-unread-same-subject ()
7050   "Select next unread article which has the same subject as current one."
7051   (interactive)
7052   (gnus-summary-next-article t (gnus-summary-article-subject)))
7053
7054 (defun gnus-summary-prev-unread-same-subject ()
7055   "Select previous unread article which has the same subject as current one."
7056   (interactive)
7057   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7058
7059 (defun gnus-summary-first-unread-article ()
7060   "Select the first unread article.
7061 Return nil if there are no unread articles."
7062   (interactive)
7063   (prog1
7064       (when (gnus-summary-first-subject t)
7065         (gnus-summary-show-thread)
7066         (gnus-summary-first-subject t)
7067         (gnus-summary-display-article (gnus-summary-article-number)))
7068     (gnus-summary-position-point)))
7069
7070 (defun gnus-summary-first-unread-subject ()
7071   "Place the point on the subject line of the first unread article.
7072 Return nil if there are no unread articles."
7073   (interactive)
7074   (prog1
7075       (when (gnus-summary-first-subject t)
7076         (gnus-summary-show-thread)
7077         (gnus-summary-first-subject t))
7078     (gnus-summary-position-point)))
7079
7080 (defun gnus-summary-first-unseen-subject ()
7081   "Place the point on the subject line of the first unseen article.
7082 Return nil if there are no unseen articles."
7083   (interactive)
7084   (prog1
7085       (when (gnus-summary-first-subject t t t)
7086         (gnus-summary-show-thread)
7087         (gnus-summary-first-subject t t t))
7088     (gnus-summary-position-point)))
7089
7090 (defun gnus-summary-first-unseen-or-unread-subject ()
7091   "Place the point on the subject line of the first unseen article.
7092 Return nil if there are no unseen articles."
7093   (interactive)
7094   (prog1
7095       (unless (when (gnus-summary-first-subject t t t)
7096                 (gnus-summary-show-thread)
7097                 (gnus-summary-first-subject t t t))
7098         (when (gnus-summary-first-subject t)
7099           (gnus-summary-show-thread)
7100           (gnus-summary-first-subject t)))
7101     (gnus-summary-position-point)))
7102
7103 (defun gnus-summary-first-article ()
7104   "Select the first article.
7105 Return nil if there are no articles."
7106   (interactive)
7107   (prog1
7108       (when (gnus-summary-first-subject)
7109         (gnus-summary-show-thread)
7110         (gnus-summary-first-subject)
7111         (gnus-summary-display-article (gnus-summary-article-number)))
7112     (gnus-summary-position-point)))
7113
7114 (defun gnus-summary-best-unread-article (&optional arg)
7115   "Select the unread article with the highest score.
7116 If given a prefix argument, select the next unread article that has a
7117 score higher than the default score."
7118   (interactive "P")
7119   (let ((article (if arg
7120                      (gnus-summary-better-unread-subject)
7121                    (gnus-summary-best-unread-subject))))
7122     (if article
7123         (gnus-summary-goto-article article)
7124       (error "No unread articles"))))
7125
7126 (defun gnus-summary-best-unread-subject ()
7127   "Select the unread subject with the highest score."
7128   (interactive)
7129   (let ((best -1000000)
7130         (data gnus-newsgroup-data)
7131         article score)
7132     (while data
7133       (and (gnus-data-unread-p (car data))
7134            (> (setq score
7135                     (gnus-summary-article-score (gnus-data-number (car data))))
7136               best)
7137            (setq best score
7138                  article (gnus-data-number (car data))))
7139       (setq data (cdr data)))
7140     (when article
7141       (gnus-summary-goto-subject article))
7142     (gnus-summary-position-point)
7143     article))
7144
7145 (defun gnus-summary-better-unread-subject ()
7146   "Select the first unread subject that has a score over the default score."
7147   (interactive)
7148   (let ((data gnus-newsgroup-data)
7149         article score)
7150     (while (and (setq article (gnus-data-number (car data)))
7151                 (or (gnus-data-read-p (car data))
7152                     (not (> (gnus-summary-article-score article)
7153                             gnus-summary-default-score))))
7154       (setq data (cdr data)))
7155     (when article
7156       (gnus-summary-goto-subject article))
7157     (gnus-summary-position-point)
7158     article))
7159
7160 (defun gnus-summary-last-subject ()
7161   "Go to the last displayed subject line in the group."
7162   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7163     (when article
7164       (gnus-summary-goto-subject article))))
7165
7166 (defun gnus-summary-goto-article (article &optional all-headers force)
7167   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7168 If ALL-HEADERS is non-nil, no header lines are hidden.
7169 If FORCE, go to the article even if it isn't displayed.  If FORCE
7170 is a number, it is the line the article is to be displayed on."
7171   (interactive
7172    (list
7173     (completing-read
7174      "Article number or Message-ID: "
7175      (mapcar (lambda (number) (list (int-to-string number)))
7176              gnus-newsgroup-limit))
7177     current-prefix-arg
7178     t))
7179   (prog1
7180       (if (and (stringp article)
7181                (string-match "@" article))
7182           (gnus-summary-refer-article article)
7183         (when (stringp article)
7184           (setq article (string-to-number article)))
7185         (if (gnus-summary-goto-subject article force)
7186             (gnus-summary-display-article article all-headers)
7187           (gnus-message 4 "Couldn't go to article %s" article) nil))
7188     (gnus-summary-position-point)))
7189
7190 (defun gnus-summary-goto-last-article ()
7191   "Go to the previously read article."
7192   (interactive)
7193   (prog1
7194       (when gnus-last-article
7195         (gnus-summary-goto-article gnus-last-article nil t))
7196     (gnus-summary-position-point)))
7197
7198 (defun gnus-summary-pop-article (number)
7199   "Pop one article off the history and go to the previous.
7200 NUMBER articles will be popped off."
7201   (interactive "p")
7202   (let (to)
7203     (setq gnus-newsgroup-history
7204           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7205     (if to
7206         (gnus-summary-goto-article (car to) nil t)
7207       (error "Article history empty")))
7208   (gnus-summary-position-point))
7209
7210 ;; Summary commands and functions for limiting the summary buffer.
7211
7212 (defun gnus-summary-limit-to-articles (n)
7213   "Limit the summary buffer to the next N articles.
7214 If not given a prefix, use the process marked articles instead."
7215   (interactive "P")
7216   (prog1
7217       (let ((articles (gnus-summary-work-articles n)))
7218         (setq gnus-newsgroup-processable nil)
7219         (gnus-summary-limit articles))
7220     (gnus-summary-position-point)))
7221
7222 (defun gnus-summary-pop-limit (&optional total)
7223   "Restore the previous limit.
7224 If given a prefix, remove all limits."
7225   (interactive "P")
7226   (when total
7227     (setq gnus-newsgroup-limits
7228           (list (mapcar (lambda (h) (mail-header-number h))
7229                         gnus-newsgroup-headers))))
7230   (unless gnus-newsgroup-limits
7231     (error "No limit to pop"))
7232   (prog1
7233       (gnus-summary-limit nil 'pop)
7234     (gnus-summary-position-point)))
7235
7236 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7237   "Limit the summary buffer to articles that have subjects that match a regexp.
7238 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7239   (interactive
7240    (list (read-string (if current-prefix-arg
7241                           "Exclude subject (regexp): "
7242                         "Limit to subject (regexp): "))
7243          nil current-prefix-arg))
7244   (unless header
7245     (setq header "subject"))
7246   (when (not (equal "" subject))
7247     (prog1
7248         (let ((articles (gnus-summary-find-matching
7249                          (or header "subject") subject 'all nil nil
7250                          not-matching)))
7251           (unless articles
7252             (error "Found no matches for \"%s\"" subject))
7253           (gnus-summary-limit articles))
7254       (gnus-summary-position-point))))
7255
7256 (defun gnus-summary-limit-to-author (from &optional not-matching)
7257   "Limit the summary buffer to articles that have authors that match a regexp.
7258 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7259   (interactive
7260    (list (read-string (if current-prefix-arg
7261                           "Exclude author (regexp): "
7262                         "Limit to author (regexp): "))
7263          current-prefix-arg))
7264   (gnus-summary-limit-to-subject from "from" not-matching))
7265
7266 (defun gnus-summary-limit-to-age (age &optional younger-p)
7267   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7268 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7269 articles that are younger than AGE days."
7270   (interactive
7271    (let ((younger current-prefix-arg)
7272          (days-got nil)
7273          days)
7274      (while (not days-got)
7275        (setq days (if younger
7276                       (read-string "Limit to articles within (in days): ")
7277                     (read-string "Limit to articles older than (in days): ")))
7278        (when (> (length days) 0)
7279          (setq days (read days)))
7280        (if (numberp days)
7281            (progn
7282              (setq days-got t)
7283              (if (< days 0)
7284                  (progn
7285                    (setq younger (not younger))
7286                    (setq days (* days -1)))))
7287          (message "Please enter a number.")
7288          (sleep-for 1)))
7289      (list days younger)))
7290   (prog1
7291       (let ((data gnus-newsgroup-data)
7292             (cutoff (days-to-time age))
7293             articles d date is-younger)
7294         (while (setq d (pop data))
7295           (when (and (vectorp (gnus-data-header d))
7296                      (setq date (mail-header-date (gnus-data-header d))))
7297             (setq is-younger (time-less-p
7298                               (time-since (condition-case ()
7299                                               (date-to-time date)
7300                                             (error '(0 0))))
7301                               cutoff))
7302             (when (if younger-p
7303                       is-younger
7304                     (not is-younger))
7305               (push (gnus-data-number d) articles))))
7306         (gnus-summary-limit (nreverse articles)))
7307     (gnus-summary-position-point)))
7308
7309 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7310   "Limit the summary buffer to articles that match an 'extra' header."
7311   (interactive
7312    (let ((header
7313           (intern
7314            (gnus-completing-read-with-default
7315             (symbol-name (car gnus-extra-headers))
7316             (if current-prefix-arg
7317                 "Exclude extra header:"
7318               "Limit extra header:")
7319             (mapcar (lambda (x)
7320                       (cons (symbol-name x) x))
7321                     gnus-extra-headers)
7322             nil
7323             t))))
7324      (list header
7325            (read-string (format "%s header %s (regexp): "
7326                                 (if current-prefix-arg "Exclude" "Limit to")
7327                                 header))
7328            current-prefix-arg)))
7329   (when (not (equal "" regexp))
7330     (prog1
7331         (let ((articles (gnus-summary-find-matching
7332                          (cons 'extra header) regexp 'all nil nil
7333                          not-matching)))
7334           (unless articles
7335             (error "Found no matches for \"%s\"" regexp))
7336           (gnus-summary-limit articles))
7337       (gnus-summary-position-point))))
7338
7339 (defun gnus-summary-limit-to-display-predicate ()
7340   "Limit the summary buffer to the predicated in the `display' group parameter."
7341   (interactive)
7342   (unless gnus-newsgroup-display
7343     (error "There is no `display' group parameter"))
7344   (let (articles)
7345     (dolist (number gnus-newsgroup-articles)
7346       (when (funcall gnus-newsgroup-display)
7347         (push number articles)))
7348     (gnus-summary-limit articles))
7349   (gnus-summary-position-point))
7350
7351 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7352 (make-obsolete
7353  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7354
7355 (defun gnus-summary-limit-to-unread (&optional all)
7356   "Limit the summary buffer to articles that are not marked as read.
7357 If ALL is non-nil, limit strictly to unread articles."
7358   (interactive "P")
7359   (if all
7360       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7361     (gnus-summary-limit-to-marks
7362      ;; Concat all the marks that say that an article is read and have
7363      ;; those removed.
7364      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7365            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7366            gnus-low-score-mark gnus-expirable-mark
7367            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7368            gnus-duplicate-mark gnus-souped-mark)
7369      'reverse)))
7370
7371 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7372 (make-obsolete 'gnus-summary-delete-marked-with
7373                'gnus-summary-limit-exclude-marks)
7374
7375 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7376   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7377 If REVERSE, limit the summary buffer to articles that are marked
7378 with MARKS.  MARKS can either be a string of marks or a list of marks.
7379 Returns how many articles were removed."
7380   (interactive "sMarks: ")
7381   (gnus-summary-limit-to-marks marks t))
7382
7383 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7384   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7385 If REVERSE (the prefix), limit the summary buffer to articles that are
7386 not marked with MARKS.  MARKS can either be a string of marks or a
7387 list of marks.
7388 Returns how many articles were removed."
7389   (interactive "sMarks: \nP")
7390   (prog1
7391       (let ((data gnus-newsgroup-data)
7392             (marks (if (listp marks) marks
7393                      (append marks nil))) ; Transform to list.
7394             articles)
7395         (while data
7396           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7397                   (memq (gnus-data-mark (car data)) marks))
7398             (push (gnus-data-number (car data)) articles))
7399           (setq data (cdr data)))
7400         (gnus-summary-limit articles))
7401     (gnus-summary-position-point)))
7402
7403 (defun gnus-summary-limit-to-score (score)
7404   "Limit to articles with score at or above SCORE."
7405   (interactive "NLimit to articles with score of at least: ")
7406   (let ((data gnus-newsgroup-data)
7407         articles)
7408     (while data
7409       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7410                 score)
7411         (push (gnus-data-number (car data)) articles))
7412       (setq data (cdr data)))
7413     (prog1
7414         (gnus-summary-limit articles)
7415       (gnus-summary-position-point))))
7416
7417 (defun gnus-summary-limit-to-unseen ()
7418   "Limit to unseen articles."
7419   (interactive)
7420   (prog1
7421       (gnus-summary-limit gnus-newsgroup-unseen)
7422     (gnus-summary-position-point)))
7423
7424 (defun gnus-summary-limit-include-thread (id)
7425   "Display all the hidden articles that is in the thread with ID in it.
7426 When called interactively, ID is the Message-ID of the current
7427 article."
7428   (interactive (list (mail-header-id (gnus-summary-article-header))))
7429   (let ((articles (gnus-articles-in-thread
7430                    (gnus-id-to-thread (gnus-root-id id)))))
7431     (prog1
7432         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7433       (gnus-summary-limit-include-matching-articles
7434        "subject"
7435        (regexp-quote (gnus-simplify-subject-re
7436                       (mail-header-subject (gnus-id-to-header id)))))
7437       (gnus-summary-position-point))))
7438
7439 (defun gnus-summary-limit-include-matching-articles (header regexp)
7440   "Display all the hidden articles that have HEADERs that match REGEXP."
7441   (interactive (list (read-string "Match on header: ")
7442                      (read-string "Regexp: ")))
7443   (let ((articles (gnus-find-matching-articles header regexp)))
7444     (prog1
7445         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7446       (gnus-summary-position-point))))
7447
7448 (defun gnus-summary-limit-include-dormant ()
7449   "Display all the hidden articles that are marked as dormant.
7450 Note that this command only works on a subset of the articles currently
7451 fetched for this group."
7452   (interactive)
7453   (unless gnus-newsgroup-dormant
7454     (error "There are no dormant articles in this group"))
7455   (prog1
7456       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7457     (gnus-summary-position-point)))
7458
7459 (defun gnus-summary-limit-exclude-dormant ()
7460   "Hide all dormant articles."
7461   (interactive)
7462   (prog1
7463       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7464     (gnus-summary-position-point)))
7465
7466 (defun gnus-summary-limit-exclude-childless-dormant ()
7467   "Hide all dormant articles that have no children."
7468   (interactive)
7469   (let ((data (gnus-data-list t))
7470         articles d children)
7471     ;; Find all articles that are either not dormant or have
7472     ;; children.
7473     (while (setq d (pop data))
7474       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7475                 (and (setq children
7476                            (gnus-article-children (gnus-data-number d)))
7477                      (let (found)
7478                        (while children
7479                          (when (memq (car children) articles)
7480                            (setq children nil
7481                                  found t))
7482                          (pop children))
7483                        found)))
7484         (push (gnus-data-number d) articles)))
7485     ;; Do the limiting.
7486     (prog1
7487         (gnus-summary-limit articles)
7488       (gnus-summary-position-point))))
7489
7490 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7491   "Mark all unread excluded articles as read.
7492 If ALL, mark even excluded ticked and dormants as read."
7493   (interactive "P")
7494   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7495   (let ((articles (gnus-sorted-ndifference
7496                    (sort
7497                     (mapcar (lambda (h) (mail-header-number h))
7498                             gnus-newsgroup-headers)
7499                     '<)
7500                    gnus-newsgroup-limit))
7501         article)
7502     (setq gnus-newsgroup-unreads
7503           (gnus-sorted-intersection gnus-newsgroup-unreads
7504                                     gnus-newsgroup-limit))
7505     (if all
7506         (setq gnus-newsgroup-dormant nil
7507               gnus-newsgroup-marked nil
7508               gnus-newsgroup-reads
7509               (nconc
7510                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7511                gnus-newsgroup-reads))
7512       (while (setq article (pop articles))
7513         (unless (or (memq article gnus-newsgroup-dormant)
7514                     (memq article gnus-newsgroup-marked))
7515           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7516
7517 (defun gnus-summary-limit (articles &optional pop)
7518   (if pop
7519       ;; We pop the previous limit off the stack and use that.
7520       (setq articles (car gnus-newsgroup-limits)
7521             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7522     ;; We use the new limit, so we push the old limit on the stack.
7523     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7524   ;; Set the limit.
7525   (setq gnus-newsgroup-limit articles)
7526   (let ((total (length gnus-newsgroup-data))
7527         (data (gnus-data-find-list (gnus-summary-article-number)))
7528         (gnus-summary-mark-below nil)   ; Inhibit this.
7529         found)
7530     ;; This will do all the work of generating the new summary buffer
7531     ;; according to the new limit.
7532     (gnus-summary-prepare)
7533     ;; Hide any threads, possibly.
7534     (gnus-summary-maybe-hide-threads)
7535     ;; Try to return to the article you were at, or one in the
7536     ;; neighborhood.
7537     (when data
7538       ;; We try to find some article after the current one.
7539       (while data
7540         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7541           (setq data nil
7542                 found t))
7543         (setq data (cdr data))))
7544     (unless found
7545       ;; If there is no data, that means that we were after the last
7546       ;; article.  The same goes when we can't find any articles
7547       ;; after the current one.
7548       (goto-char (point-max))
7549       (gnus-summary-find-prev))
7550     (gnus-set-mode-line 'summary)
7551     ;; We return how many articles were removed from the summary
7552     ;; buffer as a result of the new limit.
7553     (- total (length gnus-newsgroup-data))))
7554
7555 (defsubst gnus-invisible-cut-children (threads)
7556   (let ((num 0))
7557     (while threads
7558       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7559         (incf num))
7560       (pop threads))
7561     (< num 2)))
7562
7563 (defsubst gnus-cut-thread (thread)
7564   "Go forwards in the thread until we find an article that we want to display."
7565   (when (or (eq gnus-fetch-old-headers 'some)
7566             (eq gnus-fetch-old-headers 'invisible)
7567             (numberp gnus-fetch-old-headers)
7568             (eq gnus-build-sparse-threads 'some)
7569             (eq gnus-build-sparse-threads 'more))
7570     ;; Deal with old-fetched headers and sparse threads.
7571     (while (and
7572             thread
7573             (or
7574              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7575              (gnus-summary-article-ancient-p
7576               (mail-header-number (car thread))))
7577             (if (or (<= (length (cdr thread)) 1)
7578                     (eq gnus-fetch-old-headers 'invisible))
7579                 (setq gnus-newsgroup-limit
7580                       (delq (mail-header-number (car thread))
7581                             gnus-newsgroup-limit)
7582                       thread (cadr thread))
7583               (when (gnus-invisible-cut-children (cdr thread))
7584                 (let ((th (cdr thread)))
7585                   (while th
7586                     (if (memq (mail-header-number (caar th))
7587                               gnus-newsgroup-limit)
7588                         (setq thread (car th)
7589                               th nil)
7590                       (setq th (cdr th))))))))))
7591   thread)
7592
7593 (defun gnus-cut-threads (threads)
7594   "Cut off all uninteresting articles from the beginning of threads."
7595   (when (or (eq gnus-fetch-old-headers 'some)
7596             (eq gnus-fetch-old-headers 'invisible)
7597             (numberp gnus-fetch-old-headers)
7598             (eq gnus-build-sparse-threads 'some)
7599             (eq gnus-build-sparse-threads 'more))
7600     (let ((th threads))
7601       (while th
7602         (setcar th (gnus-cut-thread (car th)))
7603         (setq th (cdr th)))))
7604   ;; Remove nixed out threads.
7605   (delq nil threads))
7606
7607 (defun gnus-summary-initial-limit (&optional show-if-empty)
7608   "Figure out what the initial limit is supposed to be on group entry.
7609 This entails weeding out unwanted dormants, low-scored articles,
7610 fetch-old-headers verbiage, and so on."
7611   ;; Most groups have nothing to remove.
7612   (if (or gnus-inhibit-limiting
7613           (and (null gnus-newsgroup-dormant)
7614                (eq gnus-newsgroup-display 'gnus-not-ignore)
7615                (not (eq gnus-fetch-old-headers 'some))
7616                (not (numberp gnus-fetch-old-headers))
7617                (not (eq gnus-fetch-old-headers 'invisible))
7618                (null gnus-summary-expunge-below)
7619                (not (eq gnus-build-sparse-threads 'some))
7620                (not (eq gnus-build-sparse-threads 'more))
7621                (null gnus-thread-expunge-below)
7622                (not gnus-use-nocem)))
7623       ()                                ; Do nothing.
7624     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7625     (setq gnus-newsgroup-limit nil)
7626     (mapatoms
7627      (lambda (node)
7628        (unless (car (symbol-value node))
7629          ;; These threads have no parents -- they are roots.
7630          (let ((nodes (cdr (symbol-value node)))
7631                thread)
7632            (while nodes
7633              (if (and gnus-thread-expunge-below
7634                       (< (gnus-thread-total-score (car nodes))
7635                          gnus-thread-expunge-below))
7636                  (gnus-expunge-thread (pop nodes))
7637                (setq thread (pop nodes))
7638                (gnus-summary-limit-children thread))))))
7639      gnus-newsgroup-dependencies)
7640     ;; If this limitation resulted in an empty group, we might
7641     ;; pop the previous limit and use it instead.
7642     (when (and (not gnus-newsgroup-limit)
7643                show-if-empty)
7644       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7645     gnus-newsgroup-limit))
7646
7647 (defun gnus-summary-limit-children (thread)
7648   "Return 1 if this subthread is visible and 0 if it is not."
7649   ;; First we get the number of visible children to this thread.  This
7650   ;; is done by recursing down the thread using this function, so this
7651   ;; will really go down to a leaf article first, before slowly
7652   ;; working its way up towards the root.
7653   (when thread
7654     (let ((children
7655            (if (cdr thread)
7656                (apply '+ (mapcar 'gnus-summary-limit-children
7657                                  (cdr thread)))
7658              0))
7659           (number (mail-header-number (car thread)))
7660           score)
7661       (if (and
7662            (not (memq number gnus-newsgroup-marked))
7663            (or
7664             ;; If this article is dormant and has absolutely no visible
7665             ;; children, then this article isn't visible.
7666             (and (memq number gnus-newsgroup-dormant)
7667                  (zerop children))
7668             ;; If this is "fetch-old-headered" and there is no
7669             ;; visible children, then we don't want this article.
7670             (and (or (eq gnus-fetch-old-headers 'some)
7671                      (numberp gnus-fetch-old-headers))
7672                  (gnus-summary-article-ancient-p number)
7673                  (zerop children))
7674             ;; If this is "fetch-old-headered" and `invisible', then
7675             ;; we don't want this article.
7676             (and (eq gnus-fetch-old-headers 'invisible)
7677                  (gnus-summary-article-ancient-p number))
7678             ;; If this is a sparsely inserted article with no children,
7679             ;; we don't want it.
7680             (and (eq gnus-build-sparse-threads 'some)
7681                  (gnus-summary-article-sparse-p number)
7682                  (zerop children))
7683             ;; If we use expunging, and this article is really
7684             ;; low-scored, then we don't want this article.
7685             (when (and gnus-summary-expunge-below
7686                        (< (setq score
7687                                 (or (cdr (assq number gnus-newsgroup-scored))
7688                                     gnus-summary-default-score))
7689                           gnus-summary-expunge-below))
7690               ;; We increase the expunge-tally here, but that has
7691               ;; nothing to do with the limits, really.
7692               (incf gnus-newsgroup-expunged-tally)
7693               ;; We also mark as read here, if that's wanted.
7694               (when (and gnus-summary-mark-below
7695                          (< score gnus-summary-mark-below))
7696                 (setq gnus-newsgroup-unreads
7697                       (delq number gnus-newsgroup-unreads))
7698                 (if gnus-newsgroup-auto-expire
7699                     (push number gnus-newsgroup-expirable)
7700                   (push (cons number gnus-low-score-mark)
7701                         gnus-newsgroup-reads)))
7702               t)
7703             ;; Do the `display' group parameter.
7704             (and gnus-newsgroup-display
7705                  (not (funcall gnus-newsgroup-display)))
7706             ;; Check NoCeM things.
7707             (if (and gnus-use-nocem
7708                      (gnus-nocem-unwanted-article-p
7709                       (mail-header-id (car thread))))
7710                 (progn
7711                   (setq gnus-newsgroup-unreads
7712                         (delq number gnus-newsgroup-unreads))
7713                   t))))
7714           ;; Nope, invisible article.
7715           0
7716         ;; Ok, this article is to be visible, so we add it to the limit
7717         ;; and return 1.
7718         (push number gnus-newsgroup-limit)
7719         1))))
7720
7721 (defun gnus-expunge-thread (thread)
7722   "Mark all articles in THREAD as read."
7723   (let* ((number (mail-header-number (car thread))))
7724     (incf gnus-newsgroup-expunged-tally)
7725     ;; We also mark as read here, if that's wanted.
7726     (setq gnus-newsgroup-unreads
7727           (delq number gnus-newsgroup-unreads))
7728     (if gnus-newsgroup-auto-expire
7729         (push number gnus-newsgroup-expirable)
7730       (push (cons number gnus-low-score-mark)
7731             gnus-newsgroup-reads)))
7732   ;; Go recursively through all subthreads.
7733   (mapcar 'gnus-expunge-thread (cdr thread)))
7734
7735 ;; Summary article oriented commands
7736
7737 (defun gnus-summary-refer-parent-article (n)
7738   "Refer parent article N times.
7739 If N is negative, go to ancestor -N instead.
7740 The difference between N and the number of articles fetched is returned."
7741   (interactive "p")
7742   (let ((skip 1)
7743         error header ref)
7744     (when (not (natnump n))
7745       (setq skip (abs n)
7746             n 1))
7747     (while (and (> n 0)
7748                 (not error))
7749       (setq header (gnus-summary-article-header))
7750       (if (and (eq (mail-header-number header)
7751                    (cdr gnus-article-current))
7752                (equal gnus-newsgroup-name
7753                       (car gnus-article-current)))
7754           ;; If we try to find the parent of the currently
7755           ;; displayed article, then we take a look at the actual
7756           ;; References header, since this is slightly more
7757           ;; reliable than the References field we got from the
7758           ;; server.
7759           (save-excursion
7760             (set-buffer gnus-original-article-buffer)
7761             (nnheader-narrow-to-headers)
7762             (unless (setq ref (message-fetch-field "references"))
7763               (setq ref (message-fetch-field "in-reply-to")))
7764             (widen))
7765         (setq ref
7766               ;; It's not the current article, so we take a bet on
7767               ;; the value we got from the server.
7768               (mail-header-references header)))
7769       (if (and ref
7770                (not (equal ref "")))
7771           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7772             (gnus-message 1 "Couldn't find parent"))
7773         (gnus-message 1 "No references in article %d"
7774                       (gnus-summary-article-number))
7775         (setq error t))
7776       (decf n))
7777     (gnus-summary-position-point)
7778     n))
7779
7780 (defun gnus-summary-refer-references ()
7781   "Fetch all articles mentioned in the References header.
7782 Return the number of articles fetched."
7783   (interactive)
7784   (let ((ref (mail-header-references (gnus-summary-article-header)))
7785         (current (gnus-summary-article-number))
7786         (n 0))
7787     (if (or (not ref)
7788             (equal ref ""))
7789         (error "No References in the current article")
7790       ;; For each Message-ID in the References header...
7791       (while (string-match "<[^>]*>" ref)
7792         (incf n)
7793         ;; ... fetch that article.
7794         (gnus-summary-refer-article
7795          (prog1 (match-string 0 ref)
7796            (setq ref (substring ref (match-end 0))))))
7797       (gnus-summary-goto-subject current)
7798       (gnus-summary-position-point)
7799       n)))
7800
7801 (defun gnus-summary-refer-thread (&optional limit)
7802   "Fetch all articles in the current thread.
7803 If LIMIT (the numerical prefix), fetch that many old headers instead
7804 of what's specified by the `gnus-refer-thread-limit' variable."
7805   (interactive "P")
7806   (let ((id (mail-header-id (gnus-summary-article-header)))
7807         (limit (if limit (prefix-numeric-value limit)
7808                  gnus-refer-thread-limit)))
7809     ;; We want to fetch LIMIT *old* headers, but we also have to
7810     ;; re-fetch all the headers in the current buffer, because many of
7811     ;; them may be undisplayed.  So we adjust LIMIT.
7812     (when (numberp limit)
7813       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7814     (unless (eq gnus-fetch-old-headers 'invisible)
7815       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7816       ;; Retrieve the headers and read them in.
7817       (if (eq (gnus-retrieve-headers
7818                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7819               'nov)
7820           (gnus-build-all-threads)
7821         (error "Can't fetch thread from backends that don't support NOV"))
7822       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7823     (gnus-summary-limit-include-thread id)))
7824
7825 (defun gnus-summary-refer-article (message-id)
7826   "Fetch an article specified by MESSAGE-ID."
7827   (interactive "sMessage-ID: ")
7828   (when (and (stringp message-id)
7829              (not (zerop (length message-id))))
7830     ;; Construct the correct Message-ID if necessary.
7831     ;; Suggested by tale@pawl.rpi.edu.
7832     (unless (string-match "^<" message-id)
7833       (setq message-id (concat "<" message-id)))
7834     (unless (string-match ">$" message-id)
7835       (setq message-id (concat message-id ">")))
7836     (let* ((header (gnus-id-to-header message-id))
7837            (sparse (and header
7838                         (gnus-summary-article-sparse-p
7839                          (mail-header-number header))
7840                         (memq (mail-header-number header)
7841                               gnus-newsgroup-limit)))
7842            number)
7843       (cond
7844        ;; If the article is present in the buffer we just go to it.
7845        ((and header
7846              (or (not (gnus-summary-article-sparse-p
7847                        (mail-header-number header)))
7848                  sparse))
7849         (prog1
7850             (gnus-summary-goto-article
7851              (mail-header-number header) nil t)
7852           (when sparse
7853             (gnus-summary-update-article (mail-header-number header)))))
7854        (t
7855         ;; We fetch the article.
7856         (catch 'found
7857           (dolist (gnus-override-method (gnus-refer-article-methods))
7858             (gnus-check-server gnus-override-method)
7859             ;; Fetch the header, and display the article.
7860             (when (setq number (gnus-summary-insert-subject message-id))
7861               (gnus-summary-select-article nil nil nil number)
7862               (throw 'found t)))
7863           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7864
7865 (defun gnus-refer-article-methods ()
7866   "Return a list of referable methods."
7867   (cond
7868    ;; No method, so we default to current and native.
7869    ((null gnus-refer-article-method)
7870     (list gnus-current-select-method gnus-select-method))
7871    ;; Current.
7872    ((eq 'current gnus-refer-article-method)
7873     (list gnus-current-select-method))
7874    ;; List of select methods.
7875    ((not (and (symbolp (car gnus-refer-article-method))
7876               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7877     (let (out)
7878       (dolist (method gnus-refer-article-method)
7879         (push (if (eq 'current method)
7880                   gnus-current-select-method
7881                 method)
7882               out))
7883       (nreverse out)))
7884    ;; One single select method.
7885    (t
7886     (list gnus-refer-article-method))))
7887
7888 (defun gnus-summary-edit-parameters ()
7889   "Edit the group parameters of the current group."
7890   (interactive)
7891   (gnus-group-edit-group gnus-newsgroup-name 'params))
7892
7893 (defun gnus-summary-customize-parameters ()
7894   "Customize the group parameters of the current group."
7895   (interactive)
7896   (gnus-group-customize gnus-newsgroup-name))
7897
7898 (defun gnus-summary-enter-digest-group (&optional force)
7899   "Enter an nndoc group based on the current article.
7900 If FORCE, force a digest interpretation.  If not, try
7901 to guess what the document format is."
7902   (interactive "P")
7903   (let ((conf gnus-current-window-configuration))
7904     (save-excursion
7905       (gnus-summary-select-article))
7906     (setq gnus-current-window-configuration conf)
7907     (let* ((name (format "%s-%d"
7908                          (gnus-group-prefixed-name
7909                           gnus-newsgroup-name (list 'nndoc ""))
7910                          (save-excursion
7911                            (set-buffer gnus-summary-buffer)
7912                            gnus-current-article)))
7913            (ogroup gnus-newsgroup-name)
7914            (params (append (gnus-info-params (gnus-get-info ogroup))
7915                            (list (cons 'to-group ogroup))
7916                            (list (cons 'save-article-group ogroup))))
7917            (case-fold-search t)
7918            (buf (current-buffer))
7919            dig to-address)
7920       (save-excursion
7921         (set-buffer gnus-original-article-buffer)
7922         ;; Have the digest group inherit the main mail address of
7923         ;; the parent article.
7924         (when (setq to-address (or (gnus-fetch-field "reply-to")
7925                                    (gnus-fetch-field "from")))
7926           (setq params (append
7927                         (list (cons 'to-address
7928                                     (funcall gnus-decode-encoded-word-function
7929                                              to-address))))))
7930         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7931         (insert-buffer-substring gnus-original-article-buffer)
7932         ;; Remove lines that may lead nndoc to misinterpret the
7933         ;; document type.
7934         (narrow-to-region
7935          (goto-char (point-min))
7936          (or (search-forward "\n\n" nil t) (point)))
7937         (goto-char (point-min))
7938         (delete-matching-lines "^Path:\\|^From ")
7939         (widen))
7940       (unwind-protect
7941           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7942                     (gnus-newsgroup-ephemeral-ignored-charsets
7943                      gnus-newsgroup-ignored-charsets))
7944                 (gnus-group-read-ephemeral-group
7945                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7946                               (nndoc-article-type
7947                                ,(if force 'mbox 'guess)))
7948                  t nil nil nil
7949                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7950                                                         "ADAPT")))))
7951               ;; Make all postings to this group go to the parent group.
7952               (nconc (gnus-info-params (gnus-get-info name))
7953                      params)
7954             ;; Couldn't select this doc group.
7955             (switch-to-buffer buf)
7956             (gnus-set-global-variables)
7957             (gnus-configure-windows 'summary)
7958             (gnus-message 3 "Article couldn't be entered?"))
7959         (kill-buffer dig)))))
7960
7961 (defun gnus-summary-read-document (n)
7962   "Open a new group based on the current article(s).
7963 This will allow you to read digests and other similar
7964 documents as newsgroups.
7965 Obeys the standard process/prefix convention."
7966   (interactive "P")
7967   (let* ((articles (gnus-summary-work-articles n))
7968          (ogroup gnus-newsgroup-name)
7969          (params (append (gnus-info-params (gnus-get-info ogroup))
7970                          (list (cons 'to-group ogroup))))
7971          article group egroup groups vgroup)
7972     (while (setq article (pop articles))
7973       (setq group (format "%s-%d" gnus-newsgroup-name article))
7974       (gnus-summary-remove-process-mark article)
7975       (when (gnus-summary-display-article article)
7976         (save-excursion
7977           (with-temp-buffer
7978             (insert-buffer-substring gnus-original-article-buffer)
7979             ;; Remove some headers that may lead nndoc to make
7980             ;; the wrong guess.
7981             (message-narrow-to-head)
7982             (goto-char (point-min))
7983             (delete-matching-lines "^\\(Path\\):\\|^From ")
7984             (widen)
7985             (if (setq egroup
7986                       (gnus-group-read-ephemeral-group
7987                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7988                                      (nndoc-article-type guess))
7989                        t nil t))
7990                 (progn
7991             ;; Make all postings to this group go to the parent group.
7992                   (nconc (gnus-info-params (gnus-get-info egroup))
7993                          params)
7994                   (push egroup groups))
7995               ;; Couldn't select this doc group.
7996               (gnus-error 3 "Article couldn't be entered"))))))
7997     ;; Now we have selected all the documents.
7998     (cond
7999      ((not groups)
8000       (error "None of the articles could be interpreted as documents"))
8001      ((gnus-group-read-ephemeral-group
8002        (setq vgroup (format
8003                      "nnvirtual:%s-%s" gnus-newsgroup-name
8004                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8005        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8006        t
8007        (cons (current-buffer) 'summary)))
8008      (t
8009       (error "Couldn't select virtual nndoc group")))))
8010
8011 (defun gnus-summary-isearch-article (&optional regexp-p)
8012   "Do incremental search forward on the current article.
8013 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8014   (interactive "P")
8015   (gnus-summary-select-article)
8016   (gnus-configure-windows 'article)
8017   (gnus-eval-in-buffer-window gnus-article-buffer
8018     (save-restriction
8019       (widen)
8020       (isearch-forward regexp-p))))
8021
8022 (defun gnus-summary-search-article-forward (regexp &optional backward)
8023   "Search for an article containing REGEXP forward.
8024 If BACKWARD, search backward instead."
8025   (interactive
8026    (list (read-string
8027           (format "Search article %s (regexp%s): "
8028                   (if current-prefix-arg "backward" "forward")
8029                   (if gnus-last-search-regexp
8030                       (concat ", default " gnus-last-search-regexp)
8031                     "")))
8032          current-prefix-arg))
8033   (if (string-equal regexp "")
8034       (setq regexp (or gnus-last-search-regexp ""))
8035     (setq gnus-last-search-regexp regexp)
8036     (setq gnus-article-before-search gnus-current-article))
8037   ;; Intentionally set gnus-last-article.
8038   (setq gnus-last-article gnus-article-before-search)
8039   (let ((gnus-last-article gnus-last-article))
8040     (if (gnus-summary-search-article regexp backward)
8041         (gnus-summary-show-thread)
8042       (error "Search failed: \"%s\"" regexp))))
8043
8044 (defun gnus-summary-search-article-backward (regexp)
8045   "Search for an article containing REGEXP backward."
8046   (interactive
8047    (list (read-string
8048           (format "Search article backward (regexp%s): "
8049                   (if gnus-last-search-regexp
8050                       (concat ", default " gnus-last-search-regexp)
8051                     "")))))
8052   (gnus-summary-search-article-forward regexp 'backward))
8053
8054 (defun gnus-summary-search-article (regexp &optional backward)
8055   "Search for an article containing REGEXP.
8056 Optional argument BACKWARD means do search for backward.
8057 `gnus-select-article-hook' is not called during the search."
8058   ;; We have to require this here to make sure that the following
8059   ;; dynamic binding isn't shadowed by autoloading.
8060   (require 'gnus-async)
8061   (require 'gnus-art)
8062   (let ((gnus-select-article-hook nil)  ;Disable hook.
8063         (gnus-article-prepare-hook nil)
8064         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8065         (gnus-use-article-prefetch nil)
8066         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8067         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8068         (sum (current-buffer))
8069         (gnus-display-mime-function nil)
8070         (found nil)
8071         point)
8072     (gnus-save-hidden-threads
8073       (gnus-summary-select-article)
8074       (set-buffer gnus-article-buffer)
8075       (goto-char (window-point (get-buffer-window (current-buffer))))
8076       (when backward
8077         (forward-line -1))
8078       (while (not found)
8079         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8080         (if (if backward
8081                 (re-search-backward regexp nil t)
8082               (re-search-forward regexp nil t))
8083             ;; We found the regexp.
8084             (progn
8085               (setq found 'found)
8086               (beginning-of-line)
8087               (set-window-start
8088                (get-buffer-window (current-buffer))
8089                (point))
8090               (forward-line 1)
8091               (set-window-point
8092                (get-buffer-window (current-buffer))
8093                (point))
8094               (set-buffer sum)
8095               (setq point (point)))
8096           ;; We didn't find it, so we go to the next article.
8097           (set-buffer sum)
8098           (setq found 'not)
8099           (while (eq found 'not)
8100             (if (not (if backward (gnus-summary-find-prev)
8101                        (gnus-summary-find-next)))
8102                 ;; No more articles.
8103                 (setq found t)
8104               ;; Select the next article and adjust point.
8105               (unless (gnus-summary-article-sparse-p
8106                        (gnus-summary-article-number))
8107                 (setq found nil)
8108                 (gnus-summary-select-article)
8109                 (set-buffer gnus-article-buffer)
8110                 (widen)
8111                 (goto-char (if backward (point-max) (point-min))))))))
8112       (gnus-message 7 ""))
8113     ;; Return whether we found the regexp.
8114     (when (eq found 'found)
8115       (goto-char point)
8116       (gnus-summary-show-thread)
8117       (gnus-summary-goto-subject gnus-current-article)
8118       (gnus-summary-position-point)
8119       t)))
8120
8121 (defun gnus-find-matching-articles (header regexp)
8122   "Return a list of all articles that match REGEXP on HEADER.
8123 This search includes all articles in the current group that Gnus has
8124 fetched headers for, whether they are displayed or not."
8125   (let ((articles nil)
8126         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8127         (case-fold-search t))
8128     (dolist (header gnus-newsgroup-headers)
8129       (when (string-match regexp (funcall func header))
8130         (push (mail-header-number header) articles)))
8131     (nreverse articles)))
8132
8133 (defun gnus-summary-find-matching (header regexp &optional backward unread
8134                                           not-case-fold not-matching)
8135   "Return a list of all articles that match REGEXP on HEADER.
8136 The search stars on the current article and goes forwards unless
8137 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8138 If UNREAD is non-nil, only unread articles will
8139 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8140 in the comparisons. If NOT-MATCHING, return a list of all articles that
8141 not match REGEXP on HEADER."
8142   (let ((case-fold-search (not not-case-fold))
8143         articles d func)
8144     (if (consp header)
8145         (if (eq (car header) 'extra)
8146             (setq func
8147                   `(lambda (h)
8148                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8149                          "")))
8150           (error "%s is an invalid header" header))
8151       (unless (fboundp (intern (concat "mail-header-" header)))
8152         (error "%s is not a valid header" header))
8153       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8154     (dolist (d (if (eq backward 'all)
8155                    gnus-newsgroup-data
8156                  (gnus-data-find-list
8157                   (gnus-summary-article-number)
8158                   (gnus-data-list backward))))
8159       (when (and (or (not unread)       ; We want all articles...
8160                      (gnus-data-unread-p d)) ; Or just unreads.
8161                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8162                  (if not-matching
8163                      (not (string-match
8164                            regexp
8165                            (funcall func (gnus-data-header d))))
8166                    (string-match regexp
8167                                  (funcall func (gnus-data-header d)))))
8168         (push (gnus-data-number d) articles))) ; Success!
8169     (nreverse articles)))
8170
8171 (defun gnus-summary-execute-command (header regexp command &optional backward)
8172   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8173 If HEADER is an empty string (or nil), the match is done on the entire
8174 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8175   (interactive
8176    (list (let ((completion-ignore-case t))
8177            (completing-read
8178             "Header name: "
8179             (mapcar (lambda (header) (list (format "%s" header)))
8180                     (append
8181                      '("Number" "Subject" "From" "Lines" "Date"
8182                        "Message-ID" "Xref" "References" "Body")
8183                      gnus-extra-headers))
8184             nil 'require-match))
8185          (read-string "Regexp: ")
8186          (read-key-sequence "Command: ")
8187          current-prefix-arg))
8188   (when (equal header "Body")
8189     (setq header ""))
8190   ;; Hidden thread subtrees must be searched as well.
8191   (gnus-summary-show-all-threads)
8192   ;; We don't want to change current point nor window configuration.
8193   (save-excursion
8194     (save-window-excursion
8195       (let (gnus-visual
8196             gnus-treat-strip-trailing-blank-lines
8197             gnus-treat-strip-leading-blank-lines
8198             gnus-treat-strip-multiple-blank-lines
8199             gnus-treat-hide-boring-headers
8200             gnus-treat-fold-newsgroups
8201             gnus-article-prepare-hook)
8202         (gnus-message 6 "Executing %s..." (key-description command))
8203         ;; We'd like to execute COMMAND interactively so as to give arguments.
8204         (gnus-execute header regexp
8205                       `(call-interactively ',(key-binding command))
8206                       backward)
8207         (gnus-message 6 "Executing %s...done" (key-description command))))))
8208
8209 (defun gnus-summary-beginning-of-article ()
8210   "Scroll the article back to the beginning."
8211   (interactive)
8212   (gnus-summary-select-article)
8213   (gnus-configure-windows 'article)
8214   (gnus-eval-in-buffer-window gnus-article-buffer
8215     (widen)
8216     (goto-char (point-min))
8217     (when gnus-page-broken
8218       (gnus-narrow-to-page))))
8219
8220 (defun gnus-summary-end-of-article ()
8221   "Scroll to the end of the article."
8222   (interactive)
8223   (gnus-summary-select-article)
8224   (gnus-configure-windows 'article)
8225   (gnus-eval-in-buffer-window gnus-article-buffer
8226     (widen)
8227     (goto-char (point-max))
8228     (recenter -3)
8229     (when gnus-page-broken
8230       (gnus-narrow-to-page))))
8231
8232 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8233   "Truncate to LEN and quote all \"(\"'s in STRING."
8234   (gnus-replace-in-string (if (and len (> (length string) len))
8235                               (substring string 0 len)
8236                             string)
8237                           "[()]" "\\\\\\&"))
8238
8239 (defun gnus-summary-print-article (&optional filename n)
8240   "Generate and print a PostScript image of the N next (mail) articles.
8241
8242 If N is negative, print the N previous articles.  If N is nil and articles
8243 have been marked with the process mark, print these instead.
8244
8245 If the optional first argument FILENAME is nil, send the image to the
8246 printer.  If FILENAME is a string, save the PostScript image in a file with
8247 that name.  If FILENAME is a number, prompt the user for the name of the file
8248 to save in."
8249   (interactive (list (ps-print-preprint current-prefix-arg)))
8250   (dolist (article (gnus-summary-work-articles n))
8251     (gnus-summary-select-article nil nil 'pseudo article)
8252     (gnus-eval-in-buffer-window gnus-article-buffer
8253       (gnus-print-buffer))
8254     (gnus-summary-remove-process-mark article))
8255   (ps-despool filename))
8256
8257 (defun gnus-print-buffer ()
8258   (let ((buffer (generate-new-buffer " *print*")))
8259     (unwind-protect
8260         (progn
8261           (copy-to-buffer buffer (point-min) (point-max))
8262           (set-buffer buffer)
8263           (gnus-article-delete-invisible-text)
8264           (gnus-remove-text-with-property 'gnus-decoration)
8265           (when (gnus-visual-p 'article-highlight 'highlight)
8266             ;; Copy-to-buffer doesn't copy overlay.  So redo
8267             ;; highlight.
8268             (let ((gnus-article-buffer buffer))
8269               (gnus-article-highlight-citation t)
8270               (gnus-article-highlight-signature)))
8271           (let ((ps-left-header
8272                  (list
8273                   (concat "("
8274                           (gnus-summary-print-truncate-and-quote
8275                            (mail-header-subject gnus-current-headers)
8276                            66) ")")
8277                   (concat "("
8278                           (gnus-summary-print-truncate-and-quote
8279                            (mail-header-from gnus-current-headers)
8280                            45) ")")))
8281                 (ps-right-header
8282                  (list
8283                   "/pagenumberstring load"
8284                   (concat "("
8285                           (mail-header-date gnus-current-headers) ")"))))
8286             (gnus-run-hooks 'gnus-ps-print-hook)
8287             (save-excursion
8288               (if window-system
8289                   (ps-spool-buffer-with-faces)
8290                 (ps-spool-buffer)))))
8291       (kill-buffer buffer))))
8292
8293 (defun gnus-summary-show-article (&optional arg)
8294   "Force redisplaying of the current article.
8295 If ARG (the prefix) is a number, show the article with the charset
8296 defined in `gnus-summary-show-article-charset-alist', or the charset
8297 input.
8298 If ARG (the prefix) is non-nil and not a number, show the raw article
8299 without any article massaging functions being run.  Normally, the key strokes
8300 are `C-u g'."
8301   (interactive "P")
8302   (cond
8303    ((numberp arg)
8304     (gnus-summary-show-article t)
8305     (let ((gnus-newsgroup-charset
8306            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8307                (mm-read-coding-system
8308                 "View as charset: " ;; actually it is coding system.
8309                 (save-excursion
8310                   (set-buffer gnus-article-buffer)
8311                   (mm-detect-coding-region (point) (point-max))))))
8312           (gnus-newsgroup-ignored-charsets 'gnus-all))
8313       (gnus-summary-select-article nil 'force)
8314       (let ((deps gnus-newsgroup-dependencies)
8315             head header lines)
8316         (save-excursion
8317           (set-buffer gnus-original-article-buffer)
8318           (save-restriction
8319             (message-narrow-to-head)
8320             (setq head (buffer-string))
8321             (goto-char (point-min))
8322             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8323               (goto-char (point-max))
8324               (widen)
8325               (setq lines (1- (count-lines (point) (point-max))))))
8326           (with-temp-buffer
8327             (insert (format "211 %d Article retrieved.\n"
8328                             (cdr gnus-article-current)))
8329             (insert head)
8330             (if lines (insert (format "Lines: %d\n" lines)))
8331             (insert ".\n")
8332             (let ((nntp-server-buffer (current-buffer)))
8333               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8334         (gnus-data-set-header
8335          (gnus-data-find (cdr gnus-article-current))
8336          header)
8337         (gnus-summary-update-article-line
8338          (cdr gnus-article-current) header)
8339         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8340           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8341    ((not arg)
8342     ;; Select the article the normal way.
8343     (gnus-summary-select-article nil 'force))
8344    (t
8345     ;; We have to require this here to make sure that the following
8346     ;; dynamic binding isn't shadowed by autoloading.
8347     (require 'gnus-async)
8348     (require 'gnus-art)
8349     ;; Bind the article treatment functions to nil.
8350     (let ((gnus-have-all-headers t)
8351           gnus-article-prepare-hook
8352           gnus-article-decode-hook
8353           gnus-display-mime-function
8354           gnus-break-pages)
8355       ;; Destroy any MIME parts.
8356       (when (gnus-buffer-live-p gnus-article-buffer)
8357         (save-excursion
8358           (set-buffer gnus-article-buffer)
8359           (mm-destroy-parts gnus-article-mime-handles)
8360           ;; Set it to nil for safety reason.
8361           (setq gnus-article-mime-handle-alist nil)
8362           (setq gnus-article-mime-handles nil)))
8363       (gnus-summary-select-article nil 'force))))
8364   (gnus-summary-goto-subject gnus-current-article)
8365   (gnus-summary-position-point))
8366
8367 (defun gnus-summary-show-raw-article ()
8368   "Show the raw article without any article massaging functions being run."
8369   (interactive)
8370   (gnus-summary-show-article t))
8371
8372 (defun gnus-summary-verbose-headers (&optional arg)
8373   "Toggle permanent full header display.
8374 If ARG is a positive number, turn header display on.
8375 If ARG is a negative number, turn header display off."
8376   (interactive "P")
8377   (setq gnus-show-all-headers
8378         (cond ((or (not (numberp arg))
8379                    (zerop arg))
8380                (not gnus-show-all-headers))
8381               ((natnump arg)
8382                t)))
8383   (gnus-summary-show-article))
8384
8385 (defun gnus-summary-toggle-header (&optional arg)
8386   "Show the headers if they are hidden, or hide them if they are shown.
8387 If ARG is a positive number, show the entire header.
8388 If ARG is a negative number, hide the unwanted header lines."
8389   (interactive "P")
8390   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8391                      (get-buffer-window gnus-article-buffer t))))
8392     (with-current-buffer gnus-article-buffer
8393       (widen)
8394       (article-narrow-to-head)
8395       (let* ((buffer-read-only nil)
8396              (inhibit-point-motion-hooks t)
8397              (hidden (if (numberp arg)
8398                          (>= arg 0)
8399                        (gnus-article-hidden-text-p 'headers)))
8400              s e)
8401         (delete-region (point-min) (point-max))
8402         (with-current-buffer gnus-original-article-buffer
8403           (goto-char (setq s (point-min)))
8404           (setq e (if (search-forward "\n\n" nil t)
8405                       (1- (point))
8406                     (point-max))))
8407         (insert-buffer-substring gnus-original-article-buffer s e)
8408         (article-decode-encoded-words)
8409         (if hidden
8410             (let ((gnus-treat-hide-headers nil)
8411                   (gnus-treat-hide-boring-headers nil))
8412               (gnus-delete-wash-type 'headers)
8413               (gnus-treat-article 'head))
8414           (gnus-treat-article 'head))
8415         (widen)
8416         (if window
8417             (set-window-start window (goto-char (point-min))))
8418         (setq gnus-page-broken
8419               (when gnus-break-pages
8420                 (gnus-narrow-to-page)
8421                 t))
8422         (gnus-set-mode-line 'article)))))
8423
8424 (defun gnus-summary-show-all-headers ()
8425   "Make all header lines visible."
8426   (interactive)
8427   (gnus-summary-toggle-header 1))
8428
8429 (defun gnus-summary-caesar-message (&optional arg)
8430   "Caesar rotate the current article by 13.
8431 The numerical prefix specifies how many places to rotate each letter
8432 forward."
8433   (interactive "P")
8434   (gnus-summary-select-article)
8435   (let ((mail-header-separator ""))
8436     (gnus-eval-in-buffer-window gnus-article-buffer
8437       (save-restriction
8438         (widen)
8439         (let ((start (window-start))
8440               buffer-read-only)
8441           (message-caesar-buffer-body arg)
8442           (set-window-start (get-buffer-window (current-buffer)) start))))))
8443
8444 (autoload 'unmorse-region "morse"
8445   "Convert morse coded text in region to ordinary ASCII text."
8446   t)
8447
8448 (defun gnus-summary-morse-message (&optional arg)
8449   "Morse decode the current article."
8450   (interactive "P")
8451   (gnus-summary-select-article)
8452   (let ((mail-header-separator ""))
8453     (gnus-eval-in-buffer-window gnus-article-buffer
8454       (save-excursion
8455         (save-restriction
8456           (widen)
8457           (let ((pos (window-start))
8458                 buffer-read-only)
8459             (goto-char (point-min))
8460             (when (message-goto-body)
8461               (gnus-narrow-to-body))
8462             (goto-char (point-min))
8463             (while (re-search-forward "·" (point-max) t)
8464               (replace-match "."))
8465             (unmorse-region (point-min) (point-max))
8466             (widen)
8467             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8468
8469 (defun gnus-summary-stop-page-breaking ()
8470   "Stop page breaking in the current article."
8471   (interactive)
8472   (gnus-summary-select-article)
8473   (gnus-eval-in-buffer-window gnus-article-buffer
8474     (widen)
8475     (when (gnus-visual-p 'page-marker)
8476       (let ((buffer-read-only nil))
8477         (gnus-remove-text-with-property 'gnus-prev)
8478         (gnus-remove-text-with-property 'gnus-next))
8479       (setq gnus-page-broken nil))))
8480
8481 (defun gnus-summary-move-article (&optional n to-newsgroup
8482                                             select-method action)
8483   "Move the current article to a different newsgroup.
8484 If N is a positive number, move the N next articles.
8485 If N is a negative number, move the N previous articles.
8486 If N is nil and any articles have been marked with the process mark,
8487 move those articles instead.
8488 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8489 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8490 re-spool using this method.
8491
8492 When called interactively with TO-NEWSGROUP being nil, the value of
8493 the variable `gnus-move-split-methods' is used for finding a default
8494 for the target newsgroup.
8495
8496 For this function to work, both the current newsgroup and the
8497 newsgroup that you want to move to have to support the `request-move'
8498 and `request-accept' functions.
8499
8500 ACTION can be either `move' (the default), `crosspost' or `copy'."
8501   (interactive "P")
8502   (unless action
8503     (setq action 'move))
8504   ;; Check whether the source group supports the required functions.
8505   (cond ((and (eq action 'move)
8506               (not (gnus-check-backend-function
8507                     'request-move-article gnus-newsgroup-name)))
8508          (error "The current group does not support article moving"))
8509         ((and (eq action 'crosspost)
8510               (not (gnus-check-backend-function
8511                     'request-replace-article gnus-newsgroup-name)))
8512          (error "The current group does not support article editing")))
8513   (let ((articles (gnus-summary-work-articles n))
8514         (prefix (if (gnus-check-backend-function
8515                      'request-move-article gnus-newsgroup-name)
8516                     (gnus-group-real-prefix gnus-newsgroup-name)
8517                   ""))
8518         (names '((move "Move" "Moving")
8519                  (copy "Copy" "Copying")
8520                  (crosspost "Crosspost" "Crossposting")))
8521         (copy-buf (save-excursion
8522                     (nnheader-set-temp-buffer " *copy article*")))
8523         art-group to-method new-xref article to-groups)
8524     (unless (assq action names)
8525       (error "Unknown action %s" action))
8526     ;; Read the newsgroup name.
8527     (when (and (not to-newsgroup)
8528                (not select-method))
8529       (if (and gnus-move-split-methods
8530                (not
8531                 (and (memq gnus-current-article articles)
8532                      (gnus-buffer-live-p gnus-original-article-buffer))))
8533           ;; When `gnus-move-split-methods' is non-nil, we have to
8534           ;; select an article to give `gnus-read-move-group-name' an
8535           ;; opportunity to suggest an appropriate default.  However,
8536           ;; we needn't render or mark the article.
8537           (let ((gnus-display-mime-function nil)
8538                 (gnus-article-prepare-hook nil)
8539                 (gnus-mark-article-hook nil))
8540             (gnus-summary-select-article nil nil nil (car articles))))
8541       (setq to-newsgroup
8542             (gnus-read-move-group-name
8543              (cadr (assq action names))
8544              (symbol-value (intern (format "gnus-current-%s-group" action)))
8545              articles prefix))
8546       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8547     (setq to-method (or select-method
8548                         (gnus-server-to-method
8549                          (gnus-group-method to-newsgroup))))
8550     ;; Check the method we are to move this article to...
8551     (unless (gnus-check-backend-function
8552              'request-accept-article (car to-method))
8553       (error "%s does not support article copying" (car to-method)))
8554     (unless (gnus-check-server to-method)
8555       (error "Can't open server %s" (car to-method)))
8556     (gnus-message 6 "%s to %s: %s..."
8557                   (caddr (assq action names))
8558                   (or (car select-method) to-newsgroup) articles)
8559     (while articles
8560       (setq article (pop articles))
8561       (setq
8562        art-group
8563        (cond
8564         ;; Move the article.
8565         ((eq action 'move)
8566          ;; Remove this article from future suppression.
8567          (gnus-dup-unsuppress-article article)
8568          (gnus-request-move-article
8569           article                       ; Article to move
8570           gnus-newsgroup-name           ; From newsgroup
8571           (nth 1 (gnus-find-method-for-group
8572                   gnus-newsgroup-name)) ; Server
8573           (list 'gnus-request-accept-article
8574                 to-newsgroup (list 'quote select-method)
8575                 (not articles) t)       ; Accept form
8576           (not articles)))              ; Only save nov last time
8577         ;; Copy the article.
8578         ((eq action 'copy)
8579          (save-excursion
8580            (set-buffer copy-buf)
8581            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8582              (gnus-request-accept-article
8583               to-newsgroup select-method (not articles) t))))
8584         ;; Crosspost the article.
8585         ((eq action 'crosspost)
8586          (let ((xref (message-tokenize-header
8587                       (mail-header-xref (gnus-summary-article-header article))
8588                       " ")))
8589            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8590                                   ":" (number-to-string article)))
8591            (unless xref
8592              (setq xref (list (system-name))))
8593            (setq new-xref
8594                  (concat
8595                   (mapconcat 'identity
8596                              (delete "Xref:" (delete new-xref xref))
8597                              " ")
8598                   " " new-xref))
8599            (save-excursion
8600              (set-buffer copy-buf)
8601              ;; First put the article in the destination group.
8602              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8603              (when (consp (setq art-group
8604                                 (gnus-request-accept-article
8605                                  to-newsgroup select-method (not articles))))
8606                (setq new-xref (concat new-xref " " (car art-group)
8607                                       ":"
8608                                       (number-to-string (cdr art-group))))
8609                ;; Now we have the new Xrefs header, so we insert
8610                ;; it and replace the new article.
8611                (nnheader-replace-header "Xref" new-xref)
8612                (gnus-request-replace-article
8613                 (cdr art-group) to-newsgroup (current-buffer))
8614                art-group))))))
8615       (cond
8616        ((not art-group)
8617         (gnus-message 1 "Couldn't %s article %s: %s"
8618                       (cadr (assq action names)) article
8619                       (nnheader-get-report (car to-method))))
8620        ((eq art-group 'junk)
8621         (when (eq action 'move)
8622           (gnus-summary-mark-article article gnus-canceled-mark)
8623           (gnus-message 4 "Deleted article %s" article)))
8624        (t
8625         (let* ((pto-group (gnus-group-prefixed-name
8626                            (car art-group) to-method))
8627                (entry
8628                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8629                (info (nth 2 entry))
8630                (to-group (gnus-info-group info))
8631                to-marks)
8632           ;; Update the group that has been moved to.
8633           (when (and info
8634                      (memq action '(move copy)))
8635             (unless (member to-group to-groups)
8636               (push to-group to-groups))
8637
8638             (unless (memq article gnus-newsgroup-unreads)
8639               (push 'read to-marks)
8640               (gnus-info-set-read
8641                info (gnus-add-to-range (gnus-info-read info)
8642                                        (list (cdr art-group)))))
8643
8644             ;; See whether the article is to be put in the cache.
8645             (let ((marks gnus-article-mark-lists)
8646                   (to-article (cdr art-group)))
8647
8648               ;; Enter the article into the cache in the new group,
8649               ;; if that is required.
8650               (when gnus-use-cache
8651                 (gnus-cache-possibly-enter-article
8652                  to-group to-article
8653                  (memq article gnus-newsgroup-marked)
8654                  (memq article gnus-newsgroup-dormant)
8655                  (memq article gnus-newsgroup-unreads)))
8656
8657               (when gnus-preserve-marks
8658                 ;; Copy any marks over to the new group.
8659                 (when (and (equal to-group gnus-newsgroup-name)
8660                            (not (memq article gnus-newsgroup-unreads)))
8661                   ;; Mark this article as read in this group.
8662                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8663                   (setcdr (gnus-active to-group) to-article)
8664                   (setcdr gnus-newsgroup-active to-article))
8665
8666                 (while marks
8667                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8668                     (when (memq article (symbol-value
8669                                          (intern (format "gnus-newsgroup-%s"
8670                                                          (caar marks)))))
8671                       (push (cdar marks) to-marks)
8672                       ;; If the other group is the same as this group,
8673                       ;; then we have to add the mark to the list.
8674                       (when (equal to-group gnus-newsgroup-name)
8675                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8676                              (cons to-article
8677                                    (symbol-value
8678                                     (intern (format "gnus-newsgroup-%s"
8679                                                     (caar marks)))))))
8680                       ;; Copy the marks to other group.
8681                       (gnus-add-marked-articles
8682                        to-group (cdar marks) (list to-article) info)))
8683                   (setq marks (cdr marks)))
8684
8685                 (gnus-request-set-mark to-group (list (list (list to-article)
8686                                                             'add
8687                                                             to-marks))))
8688
8689               (gnus-dribble-enter
8690                (concat "(gnus-group-set-info '"
8691                        (gnus-prin1-to-string (gnus-get-info to-group))
8692                        ")"))))
8693
8694           ;; Update the Xref header in this article to point to
8695           ;; the new crossposted article we have just created.
8696           (when (eq action 'crosspost)
8697             (save-excursion
8698               (set-buffer copy-buf)
8699               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8700               (nnheader-replace-header "Xref" new-xref)
8701               (gnus-request-replace-article
8702                article gnus-newsgroup-name (current-buffer)))))
8703
8704         ;;;!!!Why is this necessary?
8705         (set-buffer gnus-summary-buffer)
8706
8707         (gnus-summary-goto-subject article)
8708         (when (eq action 'move)
8709           (gnus-summary-mark-article article gnus-canceled-mark))))
8710       (gnus-summary-remove-process-mark article))
8711     ;; Re-activate all groups that have been moved to.
8712     (save-excursion
8713       (set-buffer gnus-group-buffer)
8714       (let ((gnus-group-marked to-groups))
8715         (gnus-group-get-new-news-this-group nil t)))
8716
8717     (gnus-kill-buffer copy-buf)
8718     (gnus-summary-position-point)
8719     (gnus-set-mode-line 'summary)))
8720
8721 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8722   "Move the current article to a different newsgroup.
8723 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8724 When called interactively, if TO-NEWSGROUP is nil, use the value of
8725 the variable `gnus-move-split-methods' for finding a default target
8726 newsgroup.
8727 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8728 re-spool using this method."
8729   (interactive "P")
8730   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8731
8732 (defun gnus-summary-crosspost-article (&optional n)
8733   "Crosspost the current article to some other group."
8734   (interactive "P")
8735   (gnus-summary-move-article n nil nil 'crosspost))
8736
8737 (defcustom gnus-summary-respool-default-method nil
8738   "Default method type for respooling an article.
8739 If nil, use to the current newsgroup method."
8740   :type 'symbol
8741   :group 'gnus-summary-mail)
8742
8743 (defun gnus-summary-respool-article (&optional n method)
8744   "Respool the current article.
8745 The article will be squeezed through the mail spooling process again,
8746 which means that it will be put in some mail newsgroup or other
8747 depending on `nnmail-split-methods'.
8748 If N is a positive number, respool the N next articles.
8749 If N is a negative number, respool the N previous articles.
8750 If N is nil and any articles have been marked with the process mark,
8751 respool those articles instead.
8752
8753 Respooling can be done both from mail groups and \"real\" newsgroups.
8754 In the former case, the articles in question will be moved from the
8755 current group into whatever groups they are destined to.  In the
8756 latter case, they will be copied into the relevant groups."
8757   (interactive
8758    (list current-prefix-arg
8759          (let* ((methods (gnus-methods-using 'respool))
8760                 (methname
8761                  (symbol-name (or gnus-summary-respool-default-method
8762                                   (car (gnus-find-method-for-group
8763                                         gnus-newsgroup-name)))))
8764                 (method
8765                  (gnus-completing-read-with-default
8766                   methname "What backend do you want to use when respooling?"
8767                   methods nil t nil 'gnus-mail-method-history))
8768                 ms)
8769            (cond
8770             ((zerop (length (setq ms (gnus-servers-using-backend
8771                                       (intern method)))))
8772              (list (intern method) ""))
8773             ((= 1 (length ms))
8774              (car ms))
8775             (t
8776              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8777                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8778                            ms-alist))))))))
8779   (unless method
8780     (error "No method given for respooling"))
8781   (if (assoc (symbol-name
8782               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8783              (gnus-methods-using 'respool))
8784       (gnus-summary-move-article n nil method)
8785     (gnus-summary-copy-article n nil method)))
8786
8787 (defun gnus-summary-import-article (file &optional edit)
8788   "Import an arbitrary file into a mail newsgroup."
8789   (interactive "fImport file: \nP")
8790   (let ((group gnus-newsgroup-name)
8791         (now (current-time))
8792         atts lines group-art)
8793     (unless (gnus-check-backend-function 'request-accept-article group)
8794       (error "%s does not support article importing" group))
8795     (or (file-readable-p file)
8796         (not (file-regular-p file))
8797         (error "Can't read %s" file))
8798     (save-excursion
8799       (set-buffer (gnus-get-buffer-create " *import file*"))
8800       (erase-buffer)
8801       (nnheader-insert-file-contents file)
8802       (goto-char (point-min))
8803       (if (nnheader-article-p)
8804           (save-restriction
8805             (goto-char (point-min))
8806             (search-forward "\n\n" nil t)
8807             (narrow-to-region (point-min) (1- (point)))
8808             (goto-char (point-min))
8809             (unless (re-search-forward "^date:" nil t)
8810               (goto-char (point-max))
8811               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8812        ;; This doesn't look like an article, so we fudge some headers.
8813         (setq atts (file-attributes file)
8814               lines (count-lines (point-min) (point-max)))
8815         (insert "From: " (read-string "From: ") "\n"
8816                 "Subject: " (read-string "Subject: ") "\n"
8817                 "Date: " (message-make-date (nth 5 atts)) "\n"
8818                 "Message-ID: " (message-make-message-id) "\n"
8819                 "Lines: " (int-to-string lines) "\n"
8820                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8821       (setq group-art (gnus-request-accept-article group nil t))
8822       (kill-buffer (current-buffer)))
8823     (setq gnus-newsgroup-active (gnus-activate-group group))
8824     (forward-line 1)
8825     (gnus-summary-goto-article (cdr group-art) nil t)
8826     (when edit
8827       (gnus-summary-edit-article))))
8828
8829 (defun gnus-summary-create-article ()
8830   "Create an article in a mail newsgroup."
8831   (interactive)
8832   (let ((group gnus-newsgroup-name)
8833         (now (current-time))
8834         group-art)
8835     (unless (gnus-check-backend-function 'request-accept-article group)
8836       (error "%s does not support article importing" group))
8837     (save-excursion
8838       (set-buffer (gnus-get-buffer-create " *import file*"))
8839       (erase-buffer)
8840       (goto-char (point-min))
8841       ;; This doesn't look like an article, so we fudge some headers.
8842       (insert "From: " (read-string "From: ") "\n"
8843               "Subject: " (read-string "Subject: ") "\n"
8844               "Date: " (message-make-date now) "\n"
8845               "Message-ID: " (message-make-message-id) "\n")
8846       (setq group-art (gnus-request-accept-article group nil t))
8847       (kill-buffer (current-buffer)))
8848     (setq gnus-newsgroup-active (gnus-activate-group group))
8849     (forward-line 1)
8850     (gnus-summary-goto-article (cdr group-art) nil t)
8851     (gnus-summary-edit-article)))
8852
8853 (defun gnus-summary-article-posted-p ()
8854   "Say whether the current (mail) article is available from news as well.
8855 This will be the case if the article has both been mailed and posted."
8856   (interactive)
8857   (let ((id (mail-header-references (gnus-summary-article-header)))
8858         (gnus-override-method (car (gnus-refer-article-methods))))
8859     (if (gnus-request-head id "")
8860         (gnus-message 2 "The current message was found on %s"
8861                       gnus-override-method)
8862       (gnus-message 2 "The current message couldn't be found on %s"
8863                     gnus-override-method)
8864       nil)))
8865
8866 (defun gnus-summary-expire-articles (&optional now)
8867   "Expire all articles that are marked as expirable in the current group."
8868   (interactive)
8869   (when (gnus-check-backend-function
8870          'request-expire-articles gnus-newsgroup-name)
8871     ;; This backend supports expiry.
8872     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8873            (expirable (if total
8874                           (progn
8875                             ;; We need to update the info for
8876                             ;; this group for `gnus-list-of-read-articles'
8877                             ;; to give us the right answer.
8878                             (gnus-run-hooks 'gnus-exit-group-hook)
8879                             (gnus-summary-update-info)
8880                             (gnus-list-of-read-articles gnus-newsgroup-name))
8881                         (setq gnus-newsgroup-expirable
8882                               (sort gnus-newsgroup-expirable '<))))
8883            (expiry-wait (if now 'immediate
8884                           (gnus-group-find-parameter
8885                            gnus-newsgroup-name 'expiry-wait)))
8886            (nnmail-expiry-target
8887             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8888                 nnmail-expiry-target))
8889            es)
8890       (when expirable
8891         ;; There are expirable articles in this group, so we run them
8892         ;; through the expiry process.
8893         (gnus-message 6 "Expiring articles...")
8894         (unless (gnus-check-group gnus-newsgroup-name)
8895           (error "Can't open server for %s" gnus-newsgroup-name))
8896         ;; The list of articles that weren't expired is returned.
8897         (save-excursion
8898           (if expiry-wait
8899               (let ((nnmail-expiry-wait-function nil)
8900                     (nnmail-expiry-wait expiry-wait))
8901                 (setq es (gnus-request-expire-articles
8902                           expirable gnus-newsgroup-name)))
8903             (setq es (gnus-request-expire-articles
8904                       expirable gnus-newsgroup-name)))
8905           (unless total
8906             (setq gnus-newsgroup-expirable es))
8907           ;; We go through the old list of expirable, and mark all
8908           ;; really expired articles as nonexistent.
8909           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8910             (let ((gnus-use-cache nil))
8911               (dolist (article expirable)
8912                 (when (and (not (memq article es))
8913                            (gnus-data-find article))
8914                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8915         (gnus-message 6 "Expiring articles...done")))))
8916
8917 (defun gnus-summary-expire-articles-now ()
8918   "Expunge all expirable articles in the current group.
8919 This means that *all* articles that are marked as expirable will be
8920 deleted forever, right now."
8921   (interactive)
8922   (or gnus-expert-user
8923       (gnus-yes-or-no-p
8924        "Are you really, really, really sure you want to delete all these messages? ")
8925       (error "Phew!"))
8926   (gnus-summary-expire-articles t))
8927
8928 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8929 (defun gnus-summary-delete-article (&optional n)
8930   "Delete the N next (mail) articles.
8931 This command actually deletes articles.  This is not a marking
8932 command.  The article will disappear forever from your life, never to
8933 return.
8934 If N is negative, delete backwards.
8935 If N is nil and articles have been marked with the process mark,
8936 delete these instead."
8937   (interactive "P")
8938   (unless (gnus-check-backend-function 'request-expire-articles
8939                                        gnus-newsgroup-name)
8940     (error "The current newsgroup does not support article deletion"))
8941   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8942     (error "Couldn't open server"))
8943   ;; Compute the list of articles to delete.
8944   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8945         (nnmail-expiry-target 'delete)
8946         not-deleted)
8947     (if (and gnus-novice-user
8948              (not (gnus-yes-or-no-p
8949                    (format "Do you really want to delete %s forever? "
8950                            (if (> (length articles) 1)
8951                                (format "these %s articles" (length articles))
8952                              "this article")))))
8953         ()
8954       ;; Delete the articles.
8955       (setq not-deleted (gnus-request-expire-articles
8956                          articles gnus-newsgroup-name 'force))
8957       (while articles
8958         (gnus-summary-remove-process-mark (car articles))
8959         ;; The backend might not have been able to delete the article
8960         ;; after all.
8961         (unless (memq (car articles) not-deleted)
8962           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8963         (setq articles (cdr articles)))
8964       (when not-deleted
8965         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8966     (gnus-summary-position-point)
8967     (gnus-set-mode-line 'summary)
8968     not-deleted))
8969
8970 (defun gnus-summary-edit-article (&optional arg)
8971   "Edit the current article.
8972 This will have permanent effect only in mail groups.
8973 If ARG is nil, edit the decoded articles.
8974 If ARG is 1, edit the raw articles.
8975 If ARG is 2, edit the raw articles even in read-only groups.
8976 If ARG is 3, edit the articles with the current handles.
8977 Otherwise, allow editing of articles even in read-only
8978 groups."
8979   (interactive "P")
8980   (let (force raw current-handles)
8981     (cond
8982      ((null arg))
8983      ((eq arg 1)
8984       (setq raw t))
8985      ((eq arg 2)
8986       (setq raw t
8987             force t))
8988      ((eq arg 3)
8989       (setq current-handles
8990             (and (gnus-buffer-live-p gnus-article-buffer)
8991                  (with-current-buffer gnus-article-buffer
8992                    (prog1
8993                        gnus-article-mime-handles
8994                      (setq gnus-article-mime-handles nil))))))
8995      (t
8996       (setq force t)))
8997     (when (and raw (not force)
8998                (member gnus-newsgroup-name '("nndraft:delayed"
8999                                              "nndraft:drafts"
9000                                              "nndraft:queue")))
9001       (error "Can't edit the raw article in group %s"
9002              gnus-newsgroup-name))
9003     (save-excursion
9004       (set-buffer gnus-summary-buffer)
9005       (let ((mail-parse-charset gnus-newsgroup-charset)
9006             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9007         (gnus-set-global-variables)
9008         (when (and (not force)
9009                    (gnus-group-read-only-p))
9010           (error "The current newsgroup does not support article editing"))
9011         (gnus-summary-show-article t)
9012         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9013           (with-current-buffer gnus-article-buffer
9014             (mm-enable-multibyte)))
9015         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9016             (setq raw t))
9017         (gnus-article-edit-article
9018          (if raw 'ignore
9019            `(lambda ()
9020               (let ((mbl mml-buffer-list))
9021                 (setq mml-buffer-list nil)
9022                 (mime-to-mml ,'current-handles)
9023                 (let ((mbl1 mml-buffer-list))
9024                   (setq mml-buffer-list mbl)
9025                   (set (make-local-variable 'mml-buffer-list) mbl1))
9026                 (make-local-hook 'kill-buffer-hook)
9027                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9028          `(lambda (no-highlight)
9029             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9030                   (message-options message-options)
9031                   (message-options-set-recipient)
9032                   (mail-parse-ignored-charsets
9033                    ',gnus-newsgroup-ignored-charsets))
9034               ,(if (not raw) '(progn
9035                                 (mml-to-mime)
9036                                 (mml-destroy-buffers)
9037                                 (remove-hook 'kill-buffer-hook
9038                                              'mml-destroy-buffers t)
9039                                 (kill-local-variable 'mml-buffer-list)))
9040               (gnus-summary-edit-article-done
9041                ,(or (mail-header-references gnus-current-headers) "")
9042                ,(gnus-group-read-only-p)
9043                ,gnus-summary-buffer no-highlight))))))))
9044
9045 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9046
9047 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9048                                                  no-highlight)
9049   "Make edits to the current article permanent."
9050   (interactive)
9051   (save-excursion
9052    ;; The buffer restriction contains the entire article if it exists.
9053     (when (article-goto-body)
9054       (let ((lines (count-lines (point) (point-max)))
9055             (length (- (point-max) (point)))
9056             (case-fold-search t)
9057             (body (copy-marker (point))))
9058         (goto-char (point-min))
9059         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9060           (delete-region (match-beginning 1) (match-end 1))
9061           (insert (number-to-string length)))
9062         (goto-char (point-min))
9063         (when (re-search-forward
9064                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9065           (delete-region (match-beginning 1) (match-end 1))
9066           (insert (number-to-string length)))
9067         (goto-char (point-min))
9068         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9069           (delete-region (match-beginning 1) (match-end 1))
9070           (insert (number-to-string lines))))))
9071   ;; Replace the article.
9072   (let ((buf (current-buffer)))
9073     (with-temp-buffer
9074       (insert-buffer-substring buf)
9075
9076       (if (and (not read-only)
9077                (not (gnus-request-replace-article
9078                      (cdr gnus-article-current) (car gnus-article-current)
9079                      (current-buffer) t)))
9080           (error "Couldn't replace article")
9081         ;; Update the summary buffer.
9082         (if (and references
9083                  (equal (message-tokenize-header references " ")
9084                         (message-tokenize-header
9085                          (or (message-fetch-field "references") "") " ")))
9086             ;; We only have to update this line.
9087             (save-excursion
9088               (save-restriction
9089                 (message-narrow-to-head)
9090                 (let ((head (buffer-string))
9091                       header)
9092                   (with-temp-buffer
9093                     (insert (format "211 %d Article retrieved.\n"
9094                                     (cdr gnus-article-current)))
9095                     (insert head)
9096                     (insert ".\n")
9097                     (let ((nntp-server-buffer (current-buffer)))
9098                       (setq header (car (gnus-get-newsgroup-headers
9099                                          nil t))))
9100                     (save-excursion
9101                       (set-buffer gnus-summary-buffer)
9102                       (gnus-data-set-header
9103                        (gnus-data-find (cdr gnus-article-current))
9104                        header)
9105                       (gnus-summary-update-article-line
9106                        (cdr gnus-article-current) header)
9107                       (if (gnus-summary-goto-subject
9108                            (cdr gnus-article-current) nil t)
9109                           (gnus-summary-update-secondary-mark
9110                            (cdr gnus-article-current))))))))
9111           ;; Update threads.
9112           (set-buffer (or buffer gnus-summary-buffer))
9113           (gnus-summary-update-article (cdr gnus-article-current))
9114           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9115               (gnus-summary-update-secondary-mark
9116                (cdr gnus-article-current))))
9117         ;; Prettify the article buffer again.
9118         (unless no-highlight
9119           (save-excursion
9120             (set-buffer gnus-article-buffer)
9121             ;;;!!! Fix this -- article should be rehighlighted.
9122             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9123             (set-buffer gnus-original-article-buffer)
9124             (gnus-request-article
9125              (cdr gnus-article-current)
9126              (car gnus-article-current) (current-buffer))))
9127         ;; Prettify the summary buffer line.
9128         (when (gnus-visual-p 'summary-highlight 'highlight)
9129           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9130
9131 (defun gnus-summary-edit-wash (key)
9132   "Perform editing command KEY in the article buffer."
9133   (interactive
9134    (list
9135     (progn
9136       (message "%s" (concat (this-command-keys) "- "))
9137       (read-char))))
9138   (message "")
9139   (gnus-summary-edit-article)
9140   (execute-kbd-macro (concat (this-command-keys) key))
9141   (gnus-article-edit-done))
9142
9143 ;;; Respooling
9144
9145 (defun gnus-summary-respool-query (&optional silent trace)
9146   "Query where the respool algorithm would put this article."
9147   (interactive)
9148   (let (gnus-mark-article-hook)
9149     (gnus-summary-select-article)
9150     (save-excursion
9151       (set-buffer gnus-original-article-buffer)
9152       (save-restriction
9153         (message-narrow-to-head)
9154         (let ((groups (nnmail-article-group 'identity trace)))
9155           (unless silent
9156             (if groups
9157                 (message "This message would go to %s"
9158                          (mapconcat 'car groups ", "))
9159               (message "This message would go to no groups"))
9160             groups))))))
9161
9162 (defun gnus-summary-respool-trace ()
9163   "Trace where the respool algorithm would put this article.
9164 Display a buffer showing all fancy splitting patterns which matched."
9165   (interactive)
9166   (gnus-summary-respool-query nil t))
9167
9168 ;; Summary marking commands.
9169
9170 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9171   "Mark articles which has the same subject as read, and then select the next.
9172 If UNMARK is positive, remove any kind of mark.
9173 If UNMARK is negative, tick articles."
9174   (interactive "P")
9175   (when unmark
9176     (setq unmark (prefix-numeric-value unmark)))
9177   (let ((count
9178          (gnus-summary-mark-same-subject
9179           (gnus-summary-article-subject) unmark)))
9180     ;; Select next unread article.  If auto-select-same mode, should
9181     ;; select the first unread article.
9182     (gnus-summary-next-article t (and gnus-auto-select-same
9183                                       (gnus-summary-article-subject)))
9184     (gnus-message 7 "%d article%s marked as %s"
9185                   count (if (= count 1) " is" "s are")
9186                   (if unmark "unread" "read"))))
9187
9188 (defun gnus-summary-kill-same-subject (&optional unmark)
9189   "Mark articles which has the same subject as read.
9190 If UNMARK is positive, remove any kind of mark.
9191 If UNMARK is negative, tick articles."
9192   (interactive "P")
9193   (when unmark
9194     (setq unmark (prefix-numeric-value unmark)))
9195   (let ((count
9196          (gnus-summary-mark-same-subject
9197           (gnus-summary-article-subject) unmark)))
9198     ;; If marked as read, go to next unread subject.
9199     (when (null unmark)
9200       ;; Go to next unread subject.
9201       (gnus-summary-next-subject 1 t))
9202     (gnus-message 7 "%d articles are marked as %s"
9203                   count (if unmark "unread" "read"))))
9204
9205 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9206   "Mark articles with same SUBJECT as read, and return marked number.
9207 If optional argument UNMARK is positive, remove any kinds of marks.
9208 If optional argument UNMARK is negative, mark articles as unread instead."
9209   (let ((count 1))
9210     (save-excursion
9211       (cond
9212        ((null unmark)                   ; Mark as read.
9213         (while (and
9214                 (progn
9215                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9216                   (gnus-summary-show-thread) t)
9217                 (gnus-summary-find-subject subject))
9218           (setq count (1+ count))))
9219        ((> unmark 0)                    ; Tick.
9220         (while (and
9221                 (progn
9222                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9223                   (gnus-summary-show-thread) t)
9224                 (gnus-summary-find-subject subject))
9225           (setq count (1+ count))))
9226        (t                               ; Mark as unread.
9227         (while (and
9228                 (progn
9229                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9230                   (gnus-summary-show-thread) t)
9231                 (gnus-summary-find-subject subject))
9232           (setq count (1+ count)))))
9233       (gnus-set-mode-line 'summary)
9234       ;; Return the number of marked articles.
9235       count)))
9236
9237 (defun gnus-summary-mark-as-processable (n &optional unmark)
9238   "Set the process mark on the next N articles.
9239 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9240 the process mark instead.  The difference between N and the actual
9241 number of articles marked is returned."
9242   (interactive "P")
9243   (if (and (null n) (gnus-region-active-p))
9244       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9245     (setq n (prefix-numeric-value n))
9246     (let ((backward (< n 0))
9247           (n (abs n)))
9248       (while (and
9249               (> n 0)
9250               (if unmark
9251                   (gnus-summary-remove-process-mark
9252                    (gnus-summary-article-number))
9253                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9254               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9255         (setq n (1- n)))
9256       (when (/= 0 n)
9257         (gnus-message 7 "No more articles"))
9258       (gnus-summary-recenter)
9259       (gnus-summary-position-point)
9260       n)))
9261
9262 (defun gnus-summary-unmark-as-processable (n)
9263   "Remove the process mark from the next N articles.
9264 If N is negative, unmark backward instead.  The difference between N and
9265 the actual number of articles unmarked is returned."
9266   (interactive "P")
9267   (gnus-summary-mark-as-processable n t))
9268
9269 (defun gnus-summary-unmark-all-processable ()
9270   "Remove the process mark from all articles."
9271   (interactive)
9272   (save-excursion
9273     (while gnus-newsgroup-processable
9274       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9275   (gnus-summary-position-point))
9276
9277 (defun gnus-summary-add-mark (article type)
9278   "Mark ARTICLE with a mark of TYPE."
9279   (let ((vtype (car (assq type gnus-article-mark-lists)))
9280         var)
9281     (if (not vtype)
9282         (error "No such mark type: %s" type)
9283       (setq var (intern (format "gnus-newsgroup-%s" type)))
9284       (set var (cons article (symbol-value var)))
9285       (if (memq type '(processable cached replied forwarded recent saved))
9286           (gnus-summary-update-secondary-mark article)
9287         ;;; !!! This is bogus.  We should find out what primary
9288         ;;; !!! mark we want to set.
9289         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9290
9291 (defun gnus-summary-mark-as-expirable (n)
9292   "Mark N articles forward as expirable.
9293 If N is negative, mark backward instead.  The difference between N and
9294 the actual number of articles marked is returned."
9295   (interactive "p")
9296   (gnus-summary-mark-forward n gnus-expirable-mark))
9297
9298 (defun gnus-summary-mark-as-spam (n)
9299   "Mark N articles forward as spam.
9300 If N is negative, mark backward instead.  The difference between N and
9301 the actual number of articles marked is returned."
9302   (interactive "p")
9303   (gnus-summary-mark-forward n gnus-spam-mark))
9304
9305 (defun gnus-summary-mark-article-as-replied (article)
9306   "Mark ARTICLE as replied to and update the summary line.
9307 ARTICLE can also be a list of articles."
9308   (interactive (list (gnus-summary-article-number)))
9309   (let ((articles (if (listp article) article (list article))))
9310     (dolist (article articles)
9311       (push article gnus-newsgroup-replied)
9312       (let ((buffer-read-only nil))
9313         (when (gnus-summary-goto-subject article nil t)
9314           (gnus-summary-update-secondary-mark article))))))
9315
9316 (defun gnus-summary-mark-article-as-forwarded (article)
9317   "Mark ARTICLE as forwarded and update the summary line.
9318 ARTICLE can also be a list of articles."
9319   (let ((articles (if (listp article) article (list article))))
9320     (dolist (article articles)
9321       (push article gnus-newsgroup-forwarded)
9322       (let ((buffer-read-only nil))
9323         (when (gnus-summary-goto-subject article nil t)
9324           (gnus-summary-update-secondary-mark article))))))
9325
9326 (defun gnus-summary-set-bookmark (article)
9327   "Set a bookmark in current article."
9328   (interactive (list (gnus-summary-article-number)))
9329   (when (or (not (get-buffer gnus-article-buffer))
9330             (not gnus-current-article)
9331             (not gnus-article-current)
9332             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9333     (error "No current article selected"))
9334   ;; Remove old bookmark, if one exists.
9335   (let ((old (assq article gnus-newsgroup-bookmarks)))
9336     (when old
9337       (setq gnus-newsgroup-bookmarks
9338             (delq old gnus-newsgroup-bookmarks))))
9339   ;; Set the new bookmark, which is on the form
9340   ;; (article-number . line-number-in-body).
9341   (push
9342    (cons article
9343          (save-excursion
9344            (set-buffer gnus-article-buffer)
9345            (count-lines
9346             (min (point)
9347                  (save-excursion
9348                    (goto-char (point-min))
9349                    (search-forward "\n\n" nil t)
9350                    (point)))
9351             (point))))
9352    gnus-newsgroup-bookmarks)
9353   (gnus-message 6 "A bookmark has been added to the current article."))
9354
9355 (defun gnus-summary-remove-bookmark (article)
9356   "Remove the bookmark from the current article."
9357   (interactive (list (gnus-summary-article-number)))
9358   ;; Remove old bookmark, if one exists.
9359   (let ((old (assq article gnus-newsgroup-bookmarks)))
9360     (if old
9361         (progn
9362           (setq gnus-newsgroup-bookmarks
9363                 (delq old gnus-newsgroup-bookmarks))
9364           (gnus-message 6 "Removed bookmark."))
9365       (gnus-message 6 "No bookmark in current article."))))
9366
9367 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9368 (defun gnus-summary-mark-as-dormant (n)
9369   "Mark N articles forward as dormant.
9370 If N is negative, mark backward instead.  The difference between N and
9371 the actual number of articles marked is returned."
9372   (interactive "p")
9373   (gnus-summary-mark-forward n gnus-dormant-mark))
9374
9375 (defun gnus-summary-set-process-mark (article)
9376   "Set the process mark on ARTICLE and update the summary line."
9377   (setq gnus-newsgroup-processable
9378         (cons article
9379               (delq article gnus-newsgroup-processable)))
9380   (when (gnus-summary-goto-subject article)
9381     (gnus-summary-show-thread)
9382     (gnus-summary-goto-subject article)
9383     (gnus-summary-update-secondary-mark article)))
9384
9385 (defun gnus-summary-remove-process-mark (article)
9386   "Remove the process mark from ARTICLE and update the summary line."
9387   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9388   (when (gnus-summary-goto-subject article)
9389     (gnus-summary-show-thread)
9390     (gnus-summary-goto-subject article)
9391     (gnus-summary-update-secondary-mark article)))
9392
9393 (defun gnus-summary-set-saved-mark (article)
9394   "Set the process mark on ARTICLE and update the summary line."
9395   (push article gnus-newsgroup-saved)
9396   (when (gnus-summary-goto-subject article)
9397     (gnus-summary-update-secondary-mark article)))
9398
9399 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9400   "Mark N articles as read forwards.
9401 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9402 The difference between N and the actual number of articles marked is
9403 returned.
9404 If NO-EXPIRE, auto-expiry will be inhibited."
9405   (interactive "p")
9406   (gnus-summary-show-thread)
9407   (let ((backward (< n 0))
9408         (gnus-summary-goto-unread
9409          (and gnus-summary-goto-unread
9410               (not (eq gnus-summary-goto-unread 'never))
9411               (not (memq mark (list gnus-unread-mark
9412                                     gnus-ticked-mark gnus-dormant-mark)))))
9413         (n (abs n))
9414         (mark (or mark gnus-del-mark)))
9415     (while (and (> n 0)
9416                 (gnus-summary-mark-article nil mark no-expire)
9417                 (zerop (gnus-summary-next-subject
9418                         (if backward -1 1)
9419                         (and gnus-summary-goto-unread
9420                              (not (eq gnus-summary-goto-unread 'never)))
9421                         t)))
9422       (setq n (1- n)))
9423     (when (/= 0 n)
9424       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9425     (gnus-summary-recenter)
9426     (gnus-summary-position-point)
9427     (gnus-set-mode-line 'summary)
9428     n))
9429
9430 (defun gnus-summary-mark-article-as-read (mark)
9431   "Mark the current article quickly as read with MARK."
9432   (let ((article (gnus-summary-article-number)))
9433     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9434     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9435     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9436     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9437     (push (cons article mark) gnus-newsgroup-reads)
9438     ;; Possibly remove from cache, if that is used.
9439     (when gnus-use-cache
9440       (gnus-cache-enter-remove-article article))
9441     ;; Allow the backend to change the mark.
9442     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9443     ;; Check for auto-expiry.
9444     (when (and gnus-newsgroup-auto-expire
9445                (memq mark gnus-auto-expirable-marks))
9446       (setq mark gnus-expirable-mark)
9447       ;; Let the backend know about the mark change.
9448       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9449       (push article gnus-newsgroup-expirable))
9450     ;; Set the mark in the buffer.
9451     (gnus-summary-update-mark mark 'unread)
9452     t))
9453
9454 (defun gnus-summary-mark-article-as-unread (mark)
9455   "Mark the current article quickly as unread with MARK."
9456   (let* ((article (gnus-summary-article-number))
9457          (old-mark (gnus-summary-article-mark article)))
9458     ;; Allow the backend to change the mark.
9459     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9460     (if (eq mark old-mark)
9461         t
9462       (if (<= article 0)
9463           (progn
9464             (gnus-error 1 "Can't mark negative article numbers")
9465             nil)
9466         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9467         (setq gnus-newsgroup-spam-marked
9468               (delq article gnus-newsgroup-spam-marked))
9469         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9470         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9471         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9472         (cond ((= mark gnus-ticked-mark)
9473                (setq gnus-newsgroup-marked
9474                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9475                                               article)))
9476               ((= mark gnus-spam-mark)
9477                (setq gnus-newsgroup-spam-marked
9478                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9479                                               article)))
9480               ((= mark gnus-dormant-mark)
9481                (setq gnus-newsgroup-dormant
9482                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9483                                               article)))
9484               (t
9485                (setq gnus-newsgroup-unreads
9486                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9487                                               article))))
9488         (gnus-pull article gnus-newsgroup-reads)
9489
9490         ;; See whether the article is to be put in the cache.
9491         (and gnus-use-cache
9492              (vectorp (gnus-summary-article-header article))
9493              (save-excursion
9494                (gnus-cache-possibly-enter-article
9495                 gnus-newsgroup-name article
9496                 (= mark gnus-ticked-mark)
9497                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9498
9499         ;; Fix the mark.
9500         (gnus-summary-update-mark mark 'unread)
9501         t))))
9502
9503 (defun gnus-summary-mark-article (&optional article mark no-expire)
9504   "Mark ARTICLE with MARK.  MARK can be any character.
9505 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9506 `??' (dormant) and `?E' (expirable).
9507 If MARK is nil, then the default character `?r' is used.
9508 If ARTICLE is nil, then the article on the current line will be
9509 marked.
9510 If NO-EXPIRE, auto-expiry will be inhibited."
9511   ;; The mark might be a string.
9512   (when (stringp mark)
9513     (setq mark (aref mark 0)))
9514   ;; If no mark is given, then we check auto-expiring.
9515   (when (null mark)
9516     (setq mark gnus-del-mark))
9517   (when (and (not no-expire)
9518              gnus-newsgroup-auto-expire
9519              (memq mark gnus-auto-expirable-marks))
9520     (setq mark gnus-expirable-mark))
9521   (let ((article (or article (gnus-summary-article-number)))
9522         (old-mark (gnus-summary-article-mark article)))
9523     ;; Allow the backend to change the mark.
9524     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9525     (if (eq mark old-mark)
9526         t
9527       (unless article
9528         (error "No article on current line"))
9529       (if (not (if (or (= mark gnus-unread-mark)
9530                        (= mark gnus-ticked-mark)
9531                        (= mark gnus-spam-mark)
9532                        (= mark gnus-dormant-mark))
9533                    (gnus-mark-article-as-unread article mark)
9534                  (gnus-mark-article-as-read article mark)))
9535           t
9536         ;; See whether the article is to be put in the cache.
9537         (and gnus-use-cache
9538              (not (= mark gnus-canceled-mark))
9539              (vectorp (gnus-summary-article-header article))
9540              (save-excursion
9541                (gnus-cache-possibly-enter-article
9542                 gnus-newsgroup-name article
9543                 (= mark gnus-ticked-mark)
9544                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9545
9546         (when (gnus-summary-goto-subject article nil t)
9547           (let ((buffer-read-only nil))
9548             (gnus-summary-show-thread)
9549             ;; Fix the mark.
9550             (gnus-summary-update-mark mark 'unread)
9551             t))))))
9552
9553 (defun gnus-summary-update-secondary-mark (article)
9554   "Update the secondary (read, process, cache) mark."
9555   (gnus-summary-update-mark
9556    (cond ((memq article gnus-newsgroup-processable)
9557           gnus-process-mark)
9558          ((memq article gnus-newsgroup-cached)
9559           gnus-cached-mark)
9560          ((memq article gnus-newsgroup-replied)
9561           gnus-replied-mark)
9562          ((memq article gnus-newsgroup-forwarded)
9563           gnus-forwarded-mark)
9564          ((memq article gnus-newsgroup-saved)
9565           gnus-saved-mark)
9566          ((memq article gnus-newsgroup-recent)
9567           gnus-recent-mark)
9568          ((memq article gnus-newsgroup-unseen)
9569           gnus-unseen-mark)
9570          (t gnus-no-mark))
9571    'replied)
9572   (when (gnus-visual-p 'summary-highlight 'highlight)
9573     (gnus-run-hooks 'gnus-summary-update-hook))
9574   t)
9575
9576 (defun gnus-summary-update-mark (mark type)
9577   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9578         (buffer-read-only nil))
9579     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9580     (when forward
9581       (when (looking-at "\r")
9582         (incf forward))
9583       (when (<= (+ forward (point)) (point-max))
9584         ;; Go to the right position on the line.
9585         (goto-char (+ forward (point)))
9586         ;; Replace the old mark with the new mark.
9587         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9588         ;; Optionally update the marks by some user rule.
9589         (when (eq type 'unread)
9590           (gnus-data-set-mark
9591            (gnus-data-find (gnus-summary-article-number)) mark)
9592           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9593
9594 (defun gnus-mark-article-as-read (article &optional mark)
9595   "Enter ARTICLE in the pertinent lists and remove it from others."
9596   ;; Make the article expirable.
9597   (let ((mark (or mark gnus-del-mark)))
9598     (setq gnus-newsgroup-expirable
9599           (if (= mark gnus-expirable-mark)
9600               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9601             (delq article gnus-newsgroup-expirable)))
9602     ;; Remove from unread and marked lists.
9603     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9604     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9605     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9606     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9607     (push (cons article mark) gnus-newsgroup-reads)
9608     ;; Possibly remove from cache, if that is used.
9609     (when gnus-use-cache
9610       (gnus-cache-enter-remove-article article))
9611     t))
9612
9613 (defun gnus-mark-article-as-unread (article &optional mark)
9614   "Enter ARTICLE in the pertinent lists and remove it from others."
9615   (let ((mark (or mark gnus-ticked-mark)))
9616     (if (<= article 0)
9617         (progn
9618           (gnus-error 1 "Can't mark negative article numbers")
9619           nil)
9620       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9621             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9622             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9623             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9624             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9625
9626       ;; Unsuppress duplicates?
9627       (when gnus-suppress-duplicates
9628         (gnus-dup-unsuppress-article article))
9629
9630       (cond ((= mark gnus-ticked-mark)
9631              (setq gnus-newsgroup-marked
9632                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9633             ((= mark gnus-spam-mark)
9634              (setq gnus-newsgroup-spam-marked
9635                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9636                                             article)))
9637             ((= mark gnus-dormant-mark)
9638              (setq gnus-newsgroup-dormant
9639                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9640             (t
9641              (setq gnus-newsgroup-unreads
9642                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9643       (gnus-pull article gnus-newsgroup-reads)
9644       t)))
9645
9646 (defalias 'gnus-summary-mark-as-unread-forward
9647   'gnus-summary-tick-article-forward)
9648 (make-obsolete 'gnus-summary-mark-as-unread-forward
9649                'gnus-summary-tick-article-forward)
9650 (defun gnus-summary-tick-article-forward (n)
9651   "Tick N articles forwards.
9652 If N is negative, tick backwards instead.
9653 The difference between N and the number of articles ticked is returned."
9654   (interactive "p")
9655   (gnus-summary-mark-forward n gnus-ticked-mark))
9656
9657 (defalias 'gnus-summary-mark-as-unread-backward
9658   'gnus-summary-tick-article-backward)
9659 (make-obsolete 'gnus-summary-mark-as-unread-backward
9660                'gnus-summary-tick-article-backward)
9661 (defun gnus-summary-tick-article-backward (n)
9662   "Tick N articles backwards.
9663 The difference between N and the number of articles ticked is returned."
9664   (interactive "p")
9665   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9666
9667 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9668 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9669 (defun gnus-summary-tick-article (&optional article clear-mark)
9670   "Mark current article as unread.
9671 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9672 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9673   (interactive)
9674   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9675                                        gnus-ticked-mark)))
9676
9677 (defun gnus-summary-mark-as-read-forward (n)
9678   "Mark N articles as read forwards.
9679 If N is negative, mark backwards instead.
9680 The difference between N and the actual number of articles marked is
9681 returned."
9682   (interactive "p")
9683   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9684
9685 (defun gnus-summary-mark-as-read-backward (n)
9686   "Mark the N articles as read backwards.
9687 The difference between N and the actual number of articles marked is
9688 returned."
9689   (interactive "p")
9690   (gnus-summary-mark-forward
9691    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9692
9693 (defun gnus-summary-mark-as-read (&optional article mark)
9694   "Mark current article as read.
9695 ARTICLE specifies the article to be marked as read.
9696 MARK specifies a string to be inserted at the beginning of the line."
9697   (gnus-summary-mark-article article mark))
9698
9699 (defun gnus-summary-clear-mark-forward (n)
9700   "Clear marks from N articles forward.
9701 If N is negative, clear backward instead.
9702 The difference between N and the number of marks cleared is returned."
9703   (interactive "p")
9704   (gnus-summary-mark-forward n gnus-unread-mark))
9705
9706 (defun gnus-summary-clear-mark-backward (n)
9707   "Clear marks from N articles backward.
9708 The difference between N and the number of marks cleared is returned."
9709   (interactive "p")
9710   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9711
9712 (defun gnus-summary-mark-unread-as-read ()
9713   "Intended to be used by `gnus-summary-mark-article-hook'."
9714   (when (memq gnus-current-article gnus-newsgroup-unreads)
9715     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9716
9717 (defun gnus-summary-mark-read-and-unread-as-read ()
9718   "Intended to be used by `gnus-summary-mark-article-hook'."
9719   (let ((mark (gnus-summary-article-mark)))
9720     (when (or (gnus-unread-mark-p mark)
9721               (gnus-read-mark-p mark))
9722       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9723
9724 (defun gnus-summary-mark-unread-as-ticked ()
9725   "Intended to be used by `gnus-summary-mark-article-hook'."
9726   (when (memq gnus-current-article gnus-newsgroup-unreads)
9727     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9728
9729 (defun gnus-summary-mark-region-as-read (point mark all)
9730   "Mark all unread articles between point and mark as read.
9731 If given a prefix, mark all articles between point and mark as read,
9732 even ticked and dormant ones."
9733   (interactive "r\nP")
9734   (save-excursion
9735     (let (article)
9736       (goto-char point)
9737       (beginning-of-line)
9738       (while (and
9739               (< (point) mark)
9740               (progn
9741                 (when (or all
9742                           (memq (setq article (gnus-summary-article-number))
9743                                 gnus-newsgroup-unreads))
9744                   (gnus-summary-mark-article article gnus-del-mark))
9745                 t)
9746               (gnus-summary-find-next))))))
9747
9748 (defun gnus-summary-mark-below (score mark)
9749   "Mark articles with score less than SCORE with MARK."
9750   (interactive "P\ncMark: ")
9751   (setq score (if score
9752                   (prefix-numeric-value score)
9753                 (or gnus-summary-default-score 0)))
9754   (save-excursion
9755     (set-buffer gnus-summary-buffer)
9756     (goto-char (point-min))
9757     (while
9758         (progn
9759           (and (< (gnus-summary-article-score) score)
9760                (gnus-summary-mark-article nil mark))
9761           (gnus-summary-find-next)))))
9762
9763 (defun gnus-summary-kill-below (&optional score)
9764   "Mark articles with score below SCORE as read."
9765   (interactive "P")
9766   (gnus-summary-mark-below score gnus-killed-mark))
9767
9768 (defun gnus-summary-clear-above (&optional score)
9769   "Clear all marks from articles with score above SCORE."
9770   (interactive "P")
9771   (gnus-summary-mark-above score gnus-unread-mark))
9772
9773 (defun gnus-summary-tick-above (&optional score)
9774   "Tick all articles with score above SCORE."
9775   (interactive "P")
9776   (gnus-summary-mark-above score gnus-ticked-mark))
9777
9778 (defun gnus-summary-mark-above (score mark)
9779   "Mark articles with score over SCORE with MARK."
9780   (interactive "P\ncMark: ")
9781   (setq score (if score
9782                   (prefix-numeric-value score)
9783                 (or gnus-summary-default-score 0)))
9784   (save-excursion
9785     (set-buffer gnus-summary-buffer)
9786     (goto-char (point-min))
9787     (while (and (progn
9788                   (when (> (gnus-summary-article-score) score)
9789                     (gnus-summary-mark-article nil mark))
9790                   t)
9791                 (gnus-summary-find-next)))))
9792
9793 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9794 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9795 (defun gnus-summary-limit-include-expunged (&optional no-error)
9796   "Display all the hidden articles that were expunged for low scores."
9797   (interactive)
9798   (let ((buffer-read-only nil))
9799     (let ((scored gnus-newsgroup-scored)
9800           headers h)
9801       (while scored
9802         (unless (gnus-summary-article-header (caar scored))
9803           (and (setq h (gnus-number-to-header (caar scored)))
9804                (< (cdar scored) gnus-summary-expunge-below)
9805                (push h headers)))
9806         (setq scored (cdr scored)))
9807       (if (not headers)
9808           (when (not no-error)
9809             (error "No expunged articles hidden"))
9810         (goto-char (point-min))
9811         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9812         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9813         (mapcar (lambda (x) (push (mail-header-number x)
9814                                   gnus-newsgroup-limit))
9815                 headers)
9816         (gnus-summary-prepare-unthreaded (nreverse headers))
9817         (goto-char (point-min))
9818         (gnus-summary-position-point)
9819         t))))
9820
9821 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9822   "Mark all unread articles in this newsgroup as read.
9823 If prefix argument ALL is non-nil, ticked and dormant articles will
9824 also be marked as read.
9825 If QUIETLY is non-nil, no questions will be asked.
9826 If TO-HERE is non-nil, it should be a point in the buffer.  All
9827 articles before (after, if REVERSE is set) this point will be marked as read.
9828 Note that this function will only catch up the unread article
9829 in the current summary buffer limitation.
9830 The number of articles marked as read is returned."
9831   (interactive "P")
9832   (prog1
9833       (save-excursion
9834         (when (or quietly
9835                   (not gnus-interactive-catchup) ;Without confirmation?
9836                   gnus-expert-user
9837                   (gnus-y-or-n-p
9838                    (if all
9839                        "Mark absolutely all articles as read? "
9840                      "Mark all unread articles as read? ")))
9841           (if (and not-mark
9842                    (not gnus-newsgroup-adaptive)
9843                    (not gnus-newsgroup-auto-expire)
9844                    (not gnus-suppress-duplicates)
9845                    (or (not gnus-use-cache)
9846                        (eq gnus-use-cache 'passive)))
9847               (progn
9848                 (when all
9849                   (setq gnus-newsgroup-marked nil
9850                         gnus-newsgroup-spam-marked nil
9851                         gnus-newsgroup-dormant nil))
9852                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9853             ;; We actually mark all articles as canceled, which we
9854             ;; have to do when using auto-expiry or adaptive scoring.
9855             (gnus-summary-show-all-threads)
9856             (if (and to-here reverse)
9857                 (progn
9858                   (goto-char to-here)
9859                   (while (and
9860                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9861                           (gnus-summary-find-next (not all) nil nil t))))
9862               (when (gnus-summary-first-subject (not all) t)
9863                 (while (and
9864                         (if to-here (< (point) to-here) t)
9865                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9866                         (gnus-summary-find-next (not all) nil nil t)))))
9867             (gnus-set-mode-line 'summary))
9868           t))
9869     (gnus-summary-position-point)))
9870
9871 (defun gnus-summary-catchup-to-here (&optional all)
9872   "Mark all unticked articles before the current one as read.
9873 If ALL is non-nil, also mark ticked and dormant articles as read."
9874   (interactive "P")
9875   (save-excursion
9876     (gnus-save-hidden-threads
9877       (let ((beg (point)))
9878         ;; We check that there are unread articles.
9879         (when (or all (gnus-summary-find-prev))
9880           (gnus-summary-catchup all t beg)))))
9881   (gnus-summary-position-point))
9882
9883 (defun gnus-summary-catchup-from-here (&optional all)
9884   "Mark all unticked articles after the current one as read.
9885 If ALL is non-nil, also mark ticked and dormant articles as read."
9886   (interactive "P")
9887   (save-excursion
9888     (gnus-save-hidden-threads
9889       (let ((beg (point)))
9890         ;; We check that there are unread articles.
9891         (when (or all (gnus-summary-find-next))
9892           (gnus-summary-catchup all t beg nil t)))))
9893
9894   (gnus-summary-position-point))
9895 (defun gnus-summary-catchup-all (&optional quietly)
9896   "Mark all articles in this newsgroup as read.
9897 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
9898 instead, which marks only unread articles as read."
9899   (interactive "P")
9900   (gnus-summary-catchup t quietly))
9901
9902 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9903   "Mark all unread articles in this group as read, then exit.
9904 If prefix argument ALL is non-nil, all articles are marked as read.
9905 If QUIETLY is non-nil, no questions will be asked."
9906   (interactive "P")
9907   (when (gnus-summary-catchup all quietly nil 'fast)
9908     ;; Select next newsgroup or exit.
9909     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9910              (eq gnus-auto-select-next 'quietly))
9911         (gnus-summary-next-group nil)
9912       (gnus-summary-exit))))
9913
9914 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9915   "Mark all articles in this newsgroup as read, and then exit.
9916 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
9917 instead, which marks only unread articles as read."
9918   (interactive "P")
9919   (gnus-summary-catchup-and-exit t quietly))
9920
9921 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9922   "Mark all articles in this group as read and select the next group.
9923 If given a prefix, mark all articles, unread as well as ticked, as
9924 read."
9925   (interactive "P")
9926   (save-excursion
9927     (gnus-summary-catchup all))
9928   (gnus-summary-next-group))
9929
9930 ;;;
9931 ;;; with article
9932 ;;;
9933
9934 (defmacro gnus-with-article (article &rest forms)
9935   "Select ARTICLE and perform FORMS in the original article buffer.
9936 Then replace the article with the result."
9937   `(progn
9938      ;; We don't want the article to be marked as read.
9939      (let (gnus-mark-article-hook)
9940        (gnus-summary-select-article t t nil ,article))
9941      (set-buffer gnus-original-article-buffer)
9942      ,@forms
9943      (if (not (gnus-check-backend-function
9944                'request-replace-article (car gnus-article-current)))
9945          (gnus-message 5 "Read-only group; not replacing")
9946        (unless (gnus-request-replace-article
9947                 ,article (car gnus-article-current)
9948                 (current-buffer) t)
9949          (error "Couldn't replace article")))
9950      ;; The cache and backlog have to be flushed somewhat.
9951      (when gnus-keep-backlog
9952        (gnus-backlog-remove-article
9953         (car gnus-article-current) (cdr gnus-article-current)))
9954      (when gnus-use-cache
9955        (gnus-cache-update-article
9956         (car gnus-article-current) (cdr gnus-article-current)))))
9957
9958 (put 'gnus-with-article 'lisp-indent-function 1)
9959 (put 'gnus-with-article 'edebug-form-spec '(form body))
9960
9961 ;; Thread-based commands.
9962
9963 (defun gnus-summary-articles-in-thread (&optional article)
9964   "Return a list of all articles in the current thread.
9965 If ARTICLE is non-nil, return all articles in the thread that starts
9966 with that article."
9967   (let* ((article (or article (gnus-summary-article-number)))
9968          (data (gnus-data-find-list article))
9969          (top-level (gnus-data-level (car data)))
9970          (top-subject
9971           (cond ((null gnus-thread-operation-ignore-subject)
9972                  (gnus-simplify-subject-re
9973                   (mail-header-subject (gnus-data-header (car data)))))
9974                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9975                  (gnus-simplify-subject-fuzzy
9976                   (mail-header-subject (gnus-data-header (car data)))))
9977                 (t nil)))
9978          (end-point (save-excursion
9979                       (if (gnus-summary-go-to-next-thread)
9980                           (point) (point-max))))
9981          articles)
9982     (while (and data
9983                 (< (gnus-data-pos (car data)) end-point))
9984       (when (or (not top-subject)
9985                 (string= top-subject
9986                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9987                              (gnus-simplify-subject-fuzzy
9988                               (mail-header-subject
9989                                (gnus-data-header (car data))))
9990                            (gnus-simplify-subject-re
9991                             (mail-header-subject
9992                              (gnus-data-header (car data)))))))
9993         (push (gnus-data-number (car data)) articles))
9994       (unless (and (setq data (cdr data))
9995                    (> (gnus-data-level (car data)) top-level))
9996         (setq data nil)))
9997     ;; Return the list of articles.
9998     (nreverse articles)))
9999
10000 (defun gnus-summary-rethread-current ()
10001   "Rethread the thread the current article is part of."
10002   (interactive)
10003   (let* ((gnus-show-threads t)
10004          (article (gnus-summary-article-number))
10005          (id (mail-header-id (gnus-summary-article-header)))
10006          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10007     (unless id
10008       (error "No article on the current line"))
10009     (gnus-rebuild-thread id)
10010     (gnus-summary-goto-subject article)))
10011
10012 (defun gnus-summary-reparent-thread ()
10013   "Make the current article child of the marked (or previous) article.
10014
10015 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10016 is non-nil or the Subject: of both articles are the same."
10017   (interactive)
10018   (unless (not (gnus-group-read-only-p))
10019     (error "The current newsgroup does not support article editing"))
10020   (unless (<= (length gnus-newsgroup-processable) 1)
10021     (error "No more than one article may be marked"))
10022   (save-window-excursion
10023     (let ((gnus-article-buffer " *reparent*")
10024           (current-article (gnus-summary-article-number))
10025           ;; First grab the marked article, otherwise one line up.
10026           (parent-article (if (not (null gnus-newsgroup-processable))
10027                               (car gnus-newsgroup-processable)
10028                             (save-excursion
10029                               (if (eq (forward-line -1) 0)
10030                                   (gnus-summary-article-number)
10031                                 (error "Beginning of summary buffer"))))))
10032       (unless (not (eq current-article parent-article))
10033         (error "An article may not be self-referential"))
10034       (let ((message-id (mail-header-id
10035                          (gnus-summary-article-header parent-article))))
10036         (unless (and message-id (not (equal message-id "")))
10037           (error "No message-id in desired parent"))
10038         (gnus-with-article current-article
10039           (save-restriction
10040             (goto-char (point-min))
10041             (message-narrow-to-head)
10042             (if (re-search-forward "^References: " nil t)
10043                 (progn
10044                   (re-search-forward "^[^ \t]" nil t)
10045                   (forward-line -1)
10046                   (end-of-line)
10047                   (insert " " message-id))
10048               (insert "References: " message-id "\n"))))
10049         (set-buffer gnus-summary-buffer)
10050         (gnus-summary-unmark-all-processable)
10051         (gnus-summary-update-article current-article)
10052         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10053             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10054         (gnus-summary-rethread-current)
10055         (gnus-message 3 "Article %d is now the child of article %d"
10056                       current-article parent-article)))))
10057
10058 (defun gnus-summary-toggle-threads (&optional arg)
10059   "Toggle showing conversation threads.
10060 If ARG is positive number, turn showing conversation threads on."
10061   (interactive "P")
10062   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10063     (setq gnus-show-threads
10064           (if (null arg) (not gnus-show-threads)
10065             (> (prefix-numeric-value arg) 0)))
10066     (gnus-summary-prepare)
10067     (gnus-summary-goto-subject current)
10068     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10069     (gnus-summary-position-point)))
10070
10071 (defun gnus-summary-show-all-threads ()
10072   "Show all threads."
10073   (interactive)
10074   (save-excursion
10075     (let ((buffer-read-only nil))
10076       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10077   (gnus-summary-position-point))
10078
10079 (defun gnus-summary-show-thread ()
10080   "Show thread subtrees.
10081 Returns nil if no thread was there to be shown."
10082   (interactive)
10083   (let ((buffer-read-only nil)
10084         (orig (point))
10085         ;; first goto end then to beg, to have point at beg after let
10086         (end (progn (end-of-line) (point)))
10087         (beg (progn (beginning-of-line) (point))))
10088     (prog1
10089         ;; Any hidden lines here?
10090         (search-forward "\r" end t)
10091       (subst-char-in-region beg end ?\^M ?\n t)
10092       (goto-char orig)
10093       (gnus-summary-position-point))))
10094
10095 (defun gnus-summary-maybe-hide-threads ()
10096   "If requested, hide the threads that should be hidden."
10097   (when (and gnus-show-threads
10098              gnus-thread-hide-subtree)
10099     (gnus-summary-hide-all-threads
10100      (if (or (consp gnus-thread-hide-subtree)
10101              (gnus-functionp gnus-thread-hide-subtree))
10102          (gnus-make-predicate gnus-thread-hide-subtree)
10103        nil))))
10104
10105 ;;; Hiding predicates.
10106
10107 (defun gnus-article-unread-p (header)
10108   (memq (mail-header-number header) gnus-newsgroup-unreads))
10109
10110 (defun gnus-article-unseen-p (header)
10111   (memq (mail-header-number header) gnus-newsgroup-unseen))
10112
10113 (defun gnus-map-articles (predicate articles)
10114   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10115   (apply 'gnus-or (mapcar predicate
10116                           (mapcar 'gnus-summary-article-header articles))))
10117
10118 (defun gnus-summary-hide-all-threads (&optional predicate)
10119   "Hide all thread subtrees.
10120 If PREDICATE is supplied, threads that satisfy this predicate
10121 will not be hidden."
10122   (interactive)
10123   (save-excursion
10124     (goto-char (point-min))
10125     (let ((end nil))
10126       (while (not end)
10127         (when (or (not predicate)
10128                   (gnus-map-articles
10129                    predicate (gnus-summary-article-children)))
10130             (gnus-summary-hide-thread))
10131         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10132   (gnus-summary-position-point))
10133
10134 (defun gnus-summary-hide-thread ()
10135   "Hide thread subtrees.
10136 If PREDICATE is supplied, threads that satisfy this predicate
10137 will not be hidden.
10138 Returns nil if no threads were there to be hidden."
10139   (interactive)
10140   (let ((buffer-read-only nil)
10141         (start (point))
10142         (article (gnus-summary-article-number)))
10143     (goto-char start)
10144     ;; Go forward until either the buffer ends or the subthread
10145     ;; ends.
10146     (when (and (not (eobp))
10147                (or (zerop (gnus-summary-next-thread 1 t))
10148                    (goto-char (point-max))))
10149       (prog1
10150           (if (and (> (point) start)
10151                    (search-backward "\n" start t))
10152               (progn
10153                 (subst-char-in-region start (point) ?\n ?\^M)
10154                 (gnus-summary-goto-subject article))
10155             (goto-char start)
10156             nil)))))
10157
10158 (defun gnus-summary-go-to-next-thread (&optional previous)
10159   "Go to the same level (or less) next thread.
10160 If PREVIOUS is non-nil, go to previous thread instead.
10161 Return the article number moved to, or nil if moving was impossible."
10162   (let ((level (gnus-summary-thread-level))
10163         (way (if previous -1 1))
10164         (beg (point)))
10165     (forward-line way)
10166     (while (and (not (eobp))
10167                 (< level (gnus-summary-thread-level)))
10168       (forward-line way))
10169     (if (eobp)
10170         (progn
10171           (goto-char beg)
10172           nil)
10173       (setq beg (point))
10174       (prog1
10175           (gnus-summary-article-number)
10176         (goto-char beg)))))
10177
10178 (defun gnus-summary-next-thread (n &optional silent)
10179   "Go to the same level next N'th thread.
10180 If N is negative, search backward instead.
10181 Returns the difference between N and the number of skips actually
10182 done.
10183
10184 If SILENT, don't output messages."
10185   (interactive "p")
10186   (let ((backward (< n 0))
10187         (n (abs n)))
10188     (while (and (> n 0)
10189                 (gnus-summary-go-to-next-thread backward))
10190       (decf n))
10191     (unless silent
10192       (gnus-summary-position-point))
10193     (when (and (not silent) (/= 0 n))
10194       (gnus-message 7 "No more threads"))
10195     n))
10196
10197 (defun gnus-summary-prev-thread (n)
10198   "Go to the same level previous N'th thread.
10199 Returns the difference between N and the number of skips actually
10200 done."
10201   (interactive "p")
10202   (gnus-summary-next-thread (- n)))
10203
10204 (defun gnus-summary-go-down-thread ()
10205   "Go down one level in the current thread."
10206   (let ((children (gnus-summary-article-children)))
10207     (when children
10208       (gnus-summary-goto-subject (car children)))))
10209
10210 (defun gnus-summary-go-up-thread ()
10211   "Go up one level in the current thread."
10212   (let ((parent (gnus-summary-article-parent)))
10213     (when parent
10214       (gnus-summary-goto-subject parent))))
10215
10216 (defun gnus-summary-down-thread (n)
10217   "Go down thread N steps.
10218 If N is negative, go up instead.
10219 Returns the difference between N and how many steps down that were
10220 taken."
10221   (interactive "p")
10222   (let ((up (< n 0))
10223         (n (abs n)))
10224     (while (and (> n 0)
10225                 (if up (gnus-summary-go-up-thread)
10226                   (gnus-summary-go-down-thread)))
10227       (setq n (1- n)))
10228     (gnus-summary-position-point)
10229     (when (/= 0 n)
10230       (gnus-message 7 "Can't go further"))
10231     n))
10232
10233 (defun gnus-summary-up-thread (n)
10234   "Go up thread N steps.
10235 If N is negative, go down instead.
10236 Returns the difference between N and how many steps down that were
10237 taken."
10238   (interactive "p")
10239   (gnus-summary-down-thread (- n)))
10240
10241 (defun gnus-summary-top-thread ()
10242   "Go to the top of the thread."
10243   (interactive)
10244   (while (gnus-summary-go-up-thread))
10245   (gnus-summary-article-number))
10246
10247 (defun gnus-summary-kill-thread (&optional unmark)
10248   "Mark articles under current thread as read.
10249 If the prefix argument is positive, remove any kinds of marks.
10250 If the prefix argument is negative, tick articles instead."
10251   (interactive "P")
10252   (when unmark
10253     (setq unmark (prefix-numeric-value unmark)))
10254   (let ((articles (gnus-summary-articles-in-thread)))
10255     (save-excursion
10256       ;; Expand the thread.
10257       (gnus-summary-show-thread)
10258       ;; Mark all the articles.
10259       (while articles
10260         (gnus-summary-goto-subject (car articles))
10261         (cond ((null unmark)
10262                (gnus-summary-mark-article-as-read gnus-killed-mark))
10263               ((> unmark 0)
10264                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10265               (t
10266                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10267         (setq articles (cdr articles))))
10268     ;; Hide killed subtrees.
10269     (and (null unmark)
10270          gnus-thread-hide-killed
10271          (gnus-summary-hide-thread))
10272     ;; If marked as read, go to next unread subject.
10273     (when (null unmark)
10274       ;; Go to next unread subject.
10275       (gnus-summary-next-subject 1 t)))
10276   (gnus-set-mode-line 'summary))
10277
10278 ;; Summary sorting commands
10279
10280 (defun gnus-summary-sort-by-number (&optional reverse)
10281   "Sort the summary buffer by article number.
10282 Argument REVERSE means reverse order."
10283   (interactive "P")
10284   (gnus-summary-sort 'number reverse))
10285
10286 (defun gnus-summary-sort-by-random (&optional reverse)
10287   "Randomize the order in the summary buffer.
10288 Argument REVERSE means to randomize in reverse order."
10289   (interactive "P")
10290   (gnus-summary-sort 'random reverse))
10291
10292 (defun gnus-summary-sort-by-author (&optional reverse)
10293   "Sort the summary buffer by author name alphabetically.
10294 If `case-fold-search' is non-nil, case of letters is ignored.
10295 Argument REVERSE means reverse order."
10296   (interactive "P")
10297   (gnus-summary-sort 'author reverse))
10298
10299 (defun gnus-summary-sort-by-subject (&optional reverse)
10300   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10301 If `case-fold-search' is non-nil, case of letters is ignored.
10302 Argument REVERSE means reverse order."
10303   (interactive "P")
10304   (gnus-summary-sort 'subject reverse))
10305
10306 (defun gnus-summary-sort-by-date (&optional reverse)
10307   "Sort the summary buffer by date.
10308 Argument REVERSE means reverse order."
10309   (interactive "P")
10310   (gnus-summary-sort 'date reverse))
10311
10312 (defun gnus-summary-sort-by-score (&optional reverse)
10313   "Sort the summary buffer by score.
10314 Argument REVERSE means reverse order."
10315   (interactive "P")
10316   (gnus-summary-sort 'score reverse))
10317
10318 (defun gnus-summary-sort-by-lines (&optional reverse)
10319   "Sort the summary buffer by the number of lines.
10320 Argument REVERSE means reverse order."
10321   (interactive "P")
10322   (gnus-summary-sort 'lines reverse))
10323
10324 (defun gnus-summary-sort-by-chars (&optional reverse)
10325   "Sort the summary buffer by article length.
10326 Argument REVERSE means reverse order."
10327   (interactive "P")
10328   (gnus-summary-sort 'chars reverse))
10329
10330 (defun gnus-summary-sort-by-original (&optional reverse)
10331   "Sort the summary buffer using the default sorting method.
10332 Argument REVERSE means reverse order."
10333   (interactive "P")
10334   (let* ((buffer-read-only)
10335          (gnus-summary-prepare-hook nil))
10336     ;; We do the sorting by regenerating the threads.
10337     (gnus-summary-prepare)
10338     ;; Hide subthreads if needed.
10339     (gnus-summary-maybe-hide-threads)))
10340
10341 (defun gnus-summary-sort (predicate reverse)
10342   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10343   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10344          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10345          (gnus-thread-sort-functions
10346           (if (not reverse)
10347               thread
10348             `(lambda (t1 t2)
10349                (,thread t2 t1))))
10350          (gnus-sort-gathered-threads-function
10351           gnus-thread-sort-functions)
10352          (gnus-article-sort-functions
10353           (if (not reverse)
10354               article
10355             `(lambda (t1 t2)
10356                (,article t2 t1))))
10357          (buffer-read-only)
10358          (gnus-summary-prepare-hook nil))
10359     ;; We do the sorting by regenerating the threads.
10360     (gnus-summary-prepare)
10361     ;; Hide subthreads if needed.
10362     (gnus-summary-maybe-hide-threads)))
10363
10364 ;; Summary saving commands.
10365
10366 (defun gnus-summary-save-article (&optional n not-saved)
10367   "Save the current article using the default saver function.
10368 If N is a positive number, save the N next articles.
10369 If N is a negative number, save the N previous articles.
10370 If N is nil and any articles have been marked with the process mark,
10371 save those articles instead.
10372 The variable `gnus-default-article-saver' specifies the saver function."
10373   (interactive "P")
10374   (let* ((articles (gnus-summary-work-articles n))
10375          (save-buffer (save-excursion
10376                         (nnheader-set-temp-buffer " *Gnus Save*")))
10377          (num (length articles))
10378          header file)
10379     (dolist (article articles)
10380       (setq header (gnus-summary-article-header article))
10381       (if (not (vectorp header))
10382           ;; This is a pseudo-article.
10383           (if (assq 'name header)
10384               (gnus-copy-file (cdr (assq 'name header)))
10385             (gnus-message 1 "Article %d is unsaveable" article))
10386         ;; This is a real article.
10387         (save-window-excursion
10388           (let ((gnus-display-mime-function nil)
10389                 (gnus-article-prepare-hook nil))
10390             (gnus-summary-select-article t nil nil article)))
10391         (save-excursion
10392           (set-buffer save-buffer)
10393           (erase-buffer)
10394           (insert-buffer-substring gnus-original-article-buffer))
10395         (setq file (gnus-article-save save-buffer file num))
10396         (gnus-summary-remove-process-mark article)
10397         (unless not-saved
10398           (gnus-summary-set-saved-mark article))))
10399     (gnus-kill-buffer save-buffer)
10400     (gnus-summary-position-point)
10401     (gnus-set-mode-line 'summary)
10402     n))
10403
10404 (defun gnus-summary-pipe-output (&optional arg)
10405   "Pipe the current article to a subprocess.
10406 If N is a positive number, pipe the N next articles.
10407 If N is a negative number, pipe the N previous articles.
10408 If N is nil and any articles have been marked with the process mark,
10409 pipe those articles instead."
10410   (interactive "P")
10411   (require 'gnus-art)
10412   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10413     (gnus-summary-save-article arg t))
10414   (let ((buffer (get-buffer "*Shell Command Output*")))
10415     (if (and buffer
10416              (with-current-buffer buffer (> (point-max) (point-min))))
10417         (gnus-configure-windows 'pipe))))
10418
10419 (defun gnus-summary-save-article-mail (&optional arg)
10420   "Append the current article to an mail file.
10421 If N is a positive number, save the N next articles.
10422 If N is a negative number, save the N previous articles.
10423 If N is nil and any articles have been marked with the process mark,
10424 save those articles instead."
10425   (interactive "P")
10426   (require 'gnus-art)
10427   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10428     (gnus-summary-save-article arg)))
10429
10430 (defun gnus-summary-save-article-rmail (&optional arg)
10431   "Append the current article to an rmail file.
10432 If N is a positive number, save the N next articles.
10433 If N is a negative number, save the N previous articles.
10434 If N is nil and any articles have been marked with the process mark,
10435 save those articles instead."
10436   (interactive "P")
10437   (require 'gnus-art)
10438   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10439     (gnus-summary-save-article arg)))
10440
10441 (defun gnus-summary-save-article-file (&optional arg)
10442   "Append the current article to a file.
10443 If N is a positive number, save the N next articles.
10444 If N is a negative number, save the N previous articles.
10445 If N is nil and any articles have been marked with the process mark,
10446 save those articles instead."
10447   (interactive "P")
10448   (require 'gnus-art)
10449   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10450     (gnus-summary-save-article arg)))
10451
10452 (defun gnus-summary-write-article-file (&optional arg)
10453   "Write the current article to a file, deleting the previous file.
10454 If N is a positive number, save the N next articles.
10455 If N is a negative number, save the N previous articles.
10456 If N is nil and any articles have been marked with the process mark,
10457 save those articles instead."
10458   (interactive "P")
10459   (require 'gnus-art)
10460   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10461     (gnus-summary-save-article arg)))
10462
10463 (defun gnus-summary-save-article-body-file (&optional arg)
10464   "Append the current article body to a file.
10465 If N is a positive number, save the N next articles.
10466 If N is a negative number, save the N previous articles.
10467 If N is nil and any articles have been marked with the process mark,
10468 save those articles instead."
10469   (interactive "P")
10470   (require 'gnus-art)
10471   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10472     (gnus-summary-save-article arg)))
10473
10474 (defun gnus-summary-muttprint (&optional arg)
10475   "Print the current article using Muttprint.
10476 If N is a positive number, save the N next articles.
10477 If N is a negative number, save the N previous articles.
10478 If N is nil and any articles have been marked with the process mark,
10479 save those articles instead."
10480   (interactive "P")
10481   (require 'gnus-art)
10482   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10483     (gnus-summary-save-article arg t)))
10484
10485 (defun gnus-summary-pipe-message (program)
10486   "Pipe the current article through PROGRAM."
10487   (interactive "sProgram: ")
10488   (gnus-summary-select-article)
10489   (let ((mail-header-separator ""))
10490     (gnus-eval-in-buffer-window gnus-article-buffer
10491       (save-restriction
10492         (widen)
10493         (let ((start (window-start))
10494               buffer-read-only)
10495           (message-pipe-buffer-body program)
10496           (set-window-start (get-buffer-window (current-buffer)) start))))))
10497
10498 (defun gnus-get-split-value (methods)
10499   "Return a value based on the split METHODS."
10500   (let (split-name method result match)
10501     (when methods
10502       (save-excursion
10503         (set-buffer gnus-original-article-buffer)
10504         (save-restriction
10505           (nnheader-narrow-to-headers)
10506           (while (and methods (not split-name))
10507             (goto-char (point-min))
10508             (setq method (pop methods))
10509             (setq match (car method))
10510             (when (cond
10511                    ((stringp match)
10512                     ;; Regular expression.
10513                     (ignore-errors
10514                       (re-search-forward match nil t)))
10515                    ((gnus-functionp match)
10516                     ;; Function.
10517                     (save-restriction
10518                       (widen)
10519                       (setq result (funcall match gnus-newsgroup-name))))
10520                    ((consp match)
10521                     ;; Form.
10522                     (save-restriction
10523                       (widen)
10524                       (setq result (eval match)))))
10525               (setq split-name (cdr method))
10526               (cond ((stringp result)
10527                      (push (expand-file-name
10528                             result gnus-article-save-directory)
10529                            split-name))
10530                     ((consp result)
10531                      (setq split-name (append result split-name)))))))))
10532     (nreverse split-name)))
10533
10534 (defun gnus-valid-move-group-p (group)
10535   (and (boundp group)
10536        (symbol-name group)
10537        (symbol-value group)
10538        (gnus-get-function (gnus-find-method-for-group
10539                            (symbol-name group)) 'request-accept-article t)))
10540
10541 (defun gnus-read-move-group-name (prompt default articles prefix)
10542   "Read a group name."
10543   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10544          (minibuffer-confirm-incomplete nil) ; XEmacs
10545          (prom
10546           (format "%s %s to:"
10547                   prompt
10548                   (if (> (length articles) 1)
10549                       (format "these %d articles" (length articles))
10550                     "this article")))
10551          (to-newsgroup
10552           (cond
10553            ((null split-name)
10554             (gnus-completing-read-with-default
10555              default prom
10556              gnus-active-hashtb
10557              'gnus-valid-move-group-p
10558              nil prefix
10559              'gnus-group-history))
10560            ((= 1 (length split-name))
10561             (gnus-completing-read-with-default
10562              (car split-name) prom
10563              gnus-active-hashtb
10564              'gnus-valid-move-group-p
10565              nil nil
10566              'gnus-group-history))
10567            (t
10568             (gnus-completing-read-with-default
10569              nil prom
10570              (mapcar (lambda (el) (list el))
10571                      (nreverse split-name))
10572              nil nil nil
10573              'gnus-group-history))))
10574          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10575     (when to-newsgroup
10576       (if (or (string= to-newsgroup "")
10577               (string= to-newsgroup prefix))
10578           (setq to-newsgroup default))
10579       (unless to-newsgroup
10580         (error "No group name entered"))
10581       (or (gnus-active to-newsgroup)
10582           (gnus-activate-group to-newsgroup nil nil to-method)
10583           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10584                                      to-newsgroup))
10585               (or (and (gnus-request-create-group to-newsgroup to-method)
10586                        (gnus-activate-group
10587                         to-newsgroup nil nil to-method)
10588                        (gnus-subscribe-group to-newsgroup))
10589                   (error "Couldn't create group %s" to-newsgroup)))
10590           (error "No such group: %s" to-newsgroup)))
10591     to-newsgroup))
10592
10593 (defun gnus-summary-save-parts (type dir n &optional reverse)
10594   "Save parts matching TYPE to DIR.
10595 If REVERSE, save parts that do not match TYPE."
10596   (interactive
10597    (list (read-string "Save parts of type: "
10598                       (or (car gnus-summary-save-parts-type-history)
10599                           gnus-summary-save-parts-default-mime)
10600                       'gnus-summary-save-parts-type-history)
10601          (setq gnus-summary-save-parts-last-directory
10602                (read-file-name "Save to directory: "
10603                                gnus-summary-save-parts-last-directory
10604                                nil t))
10605          current-prefix-arg))
10606   (gnus-summary-iterate n
10607     (let ((gnus-display-mime-function nil)
10608           (gnus-inhibit-treatment t))
10609       (gnus-summary-select-article))
10610     (save-excursion
10611       (set-buffer gnus-article-buffer)
10612       (let ((handles (or gnus-article-mime-handles
10613                          (mm-dissect-buffer nil gnus-article-loose-mime)
10614                          (mm-uu-dissect))))
10615         (when handles
10616           (gnus-summary-save-parts-1 type dir handles reverse)
10617           (unless gnus-article-mime-handles ;; Don't destroy this case.
10618             (mm-destroy-parts handles)))))))
10619
10620 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10621   (if (stringp (car handle))
10622       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10623               (cdr handle))
10624     (when (if reverse
10625               (not (string-match type (mm-handle-media-type handle)))
10626             (string-match type (mm-handle-media-type handle)))
10627       (let ((file (expand-file-name
10628                    (file-name-nondirectory
10629                     (or
10630                      (mail-content-type-get
10631                       (mm-handle-disposition handle) 'filename)
10632                      (concat gnus-newsgroup-name
10633                              "." (number-to-string
10634                                   (cdr gnus-article-current)))))
10635                    dir)))
10636         (unless (file-exists-p file)
10637           (mm-save-part-to-file handle file))))))
10638
10639 ;; Summary extract commands
10640
10641 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10642   (let ((buffer-read-only nil)
10643         (article (gnus-summary-article-number))
10644         after-article b e)
10645     (unless (gnus-summary-goto-subject article)
10646       (error "No such article: %d" article))
10647     (gnus-summary-position-point)
10648     ;; If all commands are to be bunched up on one line, we collect
10649     ;; them here.
10650     (unless gnus-view-pseudos-separately
10651       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10652             files action)
10653         (while ps
10654           (setq action (cdr (assq 'action (car ps))))
10655           (setq files (list (cdr (assq 'name (car ps)))))
10656           (while (and ps (cdr ps)
10657                       (string= (or action "1")
10658                                (or (cdr (assq 'action (cadr ps))) "2")))
10659             (push (cdr (assq 'name (cadr ps))) files)
10660             (setcdr ps (cddr ps)))
10661           (when files
10662             (when (not (string-match "%s" action))
10663               (push " " files))
10664             (push " " files)
10665             (when (assq 'execute (car ps))
10666               (setcdr (assq 'execute (car ps))
10667                       (funcall (if (string-match "%s" action)
10668                                    'format 'concat)
10669                                action
10670                                (mapconcat
10671                                 (lambda (f)
10672                                   (if (equal f " ")
10673                                       f
10674                                     (mm-quote-arg f)))
10675                                 files " ")))))
10676           (setq ps (cdr ps)))))
10677     (if (and gnus-view-pseudos (not not-view))
10678         (while pslist
10679           (when (assq 'execute (car pslist))
10680             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10681                                   (eq gnus-view-pseudos 'not-confirm)))
10682           (setq pslist (cdr pslist)))
10683       (save-excursion
10684         (while pslist
10685           (setq after-article (or (cdr (assq 'article (car pslist)))
10686                                   (gnus-summary-article-number)))
10687           (gnus-summary-goto-subject after-article)
10688           (forward-line 1)
10689           (setq b (point))
10690           (insert "    " (file-name-nondirectory
10691                           (cdr (assq 'name (car pslist))))
10692                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10693           (setq e (point))
10694           (forward-line -1)             ; back to `b'
10695           (gnus-add-text-properties
10696            b (1- e) (list 'gnus-number gnus-reffed-article-number
10697                           gnus-mouse-face-prop gnus-mouse-face))
10698           (gnus-data-enter
10699            after-article gnus-reffed-article-number
10700            gnus-unread-mark b (car pslist) 0 (- e b))
10701           (setq gnus-newsgroup-unreads
10702                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10703                                          gnus-reffed-article-number))
10704           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10705           (setq pslist (cdr pslist)))))))
10706
10707 (defun gnus-pseudos< (p1 p2)
10708   (let ((c1 (cdr (assq 'action p1)))
10709         (c2 (cdr (assq 'action p2))))
10710     (and c1 c2 (string< c1 c2))))
10711
10712 (defun gnus-request-pseudo-article (props)
10713   (cond ((assq 'execute props)
10714          (gnus-execute-command (cdr (assq 'execute props)))))
10715   (let ((gnus-current-article (gnus-summary-article-number)))
10716     (gnus-run-hooks 'gnus-mark-article-hook)))
10717
10718 (defun gnus-execute-command (command &optional automatic)
10719   (save-excursion
10720     (gnus-article-setup-buffer)
10721     (set-buffer gnus-article-buffer)
10722     (setq buffer-read-only nil)
10723     (let ((command (if automatic command
10724                      (read-string "Command: " (cons command 0)))))
10725       (erase-buffer)
10726       (insert "$ " command "\n\n")
10727       (if gnus-view-pseudo-asynchronously
10728           (start-process "gnus-execute" (current-buffer) shell-file-name
10729                          shell-command-switch command)
10730         (call-process shell-file-name nil t nil
10731                       shell-command-switch command)))))
10732
10733 ;; Summary kill commands.
10734
10735 (defun gnus-summary-edit-global-kill (article)
10736   "Edit the \"global\" kill file."
10737   (interactive (list (gnus-summary-article-number)))
10738   (gnus-group-edit-global-kill article))
10739
10740 (defun gnus-summary-edit-local-kill ()
10741   "Edit a local kill file applied to the current newsgroup."
10742   (interactive)
10743   (setq gnus-current-headers (gnus-summary-article-header))
10744   (gnus-group-edit-local-kill
10745    (gnus-summary-article-number) gnus-newsgroup-name))
10746
10747 ;;; Header reading.
10748
10749 (defun gnus-read-header (id &optional header)
10750   "Read the headers of article ID and enter them into the Gnus system."
10751   (let ((group gnus-newsgroup-name)
10752         (gnus-override-method
10753          (or
10754           gnus-override-method
10755           (and (gnus-news-group-p gnus-newsgroup-name)
10756                (car (gnus-refer-article-methods)))))
10757         where)
10758     ;; First we check to see whether the header in question is already
10759     ;; fetched.
10760     (if (stringp id)
10761         ;; This is a Message-ID.
10762         (setq header (or header (gnus-id-to-header id)))
10763       ;; This is an article number.
10764       (setq header (or header (gnus-summary-article-header id))))
10765     (if (and header
10766              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10767         ;; We have found the header.
10768         header
10769       ;; If this is a sparse article, we have to nix out its
10770       ;; previous entry in the thread hashtb.
10771       (when (and header
10772                  (gnus-summary-article-sparse-p (mail-header-number header)))
10773         (let* ((parent (gnus-parent-id (mail-header-references header)))
10774                (thread (and parent (gnus-id-to-thread parent))))
10775           (when thread
10776             (delq (assq header thread) thread))))
10777       ;; We have to really fetch the header to this article.
10778       (save-excursion
10779         (set-buffer nntp-server-buffer)
10780         (when (setq where (gnus-request-head id group))
10781           (nnheader-fold-continuation-lines)
10782           (goto-char (point-max))
10783           (insert ".\n")
10784           (goto-char (point-min))
10785           (insert "211 ")
10786           (princ (cond
10787                   ((numberp id) id)
10788                   ((cdr where) (cdr where))
10789                   (header (mail-header-number header))
10790                   (t gnus-reffed-article-number))
10791                  (current-buffer))
10792           (insert " Article retrieved.\n"))
10793         (if (or (not where)
10794                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10795             ()                          ; Malformed head.
10796           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10797             (when (and (stringp id)
10798                        (not (string= (gnus-group-real-name group)
10799                                      (car where))))
10800               ;; If we fetched by Message-ID and the article came
10801               ;; from a different group, we fudge some bogus article
10802               ;; numbers for this article.
10803               (mail-header-set-number header gnus-reffed-article-number))
10804             (save-excursion
10805               (set-buffer gnus-summary-buffer)
10806               (decf gnus-reffed-article-number)
10807               (gnus-remove-header (mail-header-number header))
10808               (push header gnus-newsgroup-headers)
10809               (setq gnus-current-headers header)
10810               (push (mail-header-number header) gnus-newsgroup-limit)))
10811           header)))))
10812
10813 (defun gnus-remove-header (number)
10814   "Remove header NUMBER from `gnus-newsgroup-headers'."
10815   (if (and gnus-newsgroup-headers
10816            (= number (mail-header-number (car gnus-newsgroup-headers))))
10817       (pop gnus-newsgroup-headers)
10818     (let ((headers gnus-newsgroup-headers))
10819       (while (and (cdr headers)
10820                   (not (= number (mail-header-number (cadr headers)))))
10821         (pop headers))
10822       (when (cdr headers)
10823         (setcdr headers (cddr headers))))))
10824
10825 ;;;
10826 ;;; summary highlights
10827 ;;;
10828
10829 (defun gnus-highlight-selected-summary ()
10830   "Highlight selected article in summary buffer."
10831   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10832   (when gnus-summary-selected-face
10833     (save-excursion
10834       (let* ((beg (progn (beginning-of-line) (point)))
10835              (end (progn (end-of-line) (point)))
10836              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10837              (from (if (get-text-property beg gnus-mouse-face-prop)
10838                        beg
10839                      (or (next-single-property-change
10840                           beg gnus-mouse-face-prop nil end)
10841                          beg)))
10842              (to
10843               (if (= from end)
10844                   (- from 2)
10845                 (or (next-single-property-change
10846                      from gnus-mouse-face-prop nil end)
10847                     end))))
10848         ;; If no mouse-face prop on line we will have to = from = end,
10849         ;; so we highlight the entire line instead.
10850         (when (= (+ to 2) from)
10851           (setq from beg)
10852           (setq to end))
10853         (if gnus-newsgroup-selected-overlay
10854             ;; Move old overlay.
10855             (gnus-move-overlay
10856              gnus-newsgroup-selected-overlay from to (current-buffer))
10857           ;; Create new overlay.
10858           (gnus-overlay-put
10859            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10860            'face gnus-summary-selected-face))))))
10861
10862 (defvar gnus-summary-highlight-line-cached nil)
10863 (defvar gnus-summary-highlight-line-trigger nil)
10864 (defun gnus-summary-highlight-line-0 ()
10865   (if (and (eq gnus-summary-highlight-line-trigger 
10866                gnus-summary-highlight)
10867            gnus-summary-highlight-line-cached)
10868       gnus-summary-highlight-line-cached
10869     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
10870           gnus-summary-highlight-line-cached
10871           (let* ((cond (list 'cond))
10872                  (c cond)
10873                  (list gnus-summary-highlight))
10874             (while list
10875               (setcdr c (cons (list (caar list) (list 'quote (cdar list))) nil))
10876               (setq c (cdr c)
10877                     list (cdr list)))
10878             (gnus-byte-compile (list 'lambda nil cond))))))
10879
10880 (defvar gnus-summary-highlight-line-downloaded-alist nil)
10881 (defvar gnus-summary-highlight-line-downloaded-cached nil)
10882
10883 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10884 (defun gnus-summary-highlight-line ()
10885   "Highlight current line according to `gnus-summary-highlight'."
10886   (let*
10887       ((list gnus-summary-highlight)
10888        (beg (gnus-point-at-bol))
10889        (article (gnus-summary-article-number))
10890        (score (or (cdr (assq (or article gnus-current-article)
10891                              gnus-newsgroup-scored))
10892                   gnus-summary-default-score 0))
10893        (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10894        (inhibit-read-only t)
10895        (default gnus-summary-default-score)
10896        (default-high gnus-summary-default-high-score)
10897        (default-low gnus-summary-default-low-score)
10898        (gnus-tmp-downloaded
10899         (and
10900          (boundp 'gnus-agent-article-alist)
10901          gnus-agent-article-alist
10902          (gnus-agent-group-covered-p gnus-newsgroup-name)
10903          ;; Optimized for when gnus-summary-highlight-line is
10904          ;; called multiple times for articles in ascending
10905          ;; order (i.e. initial generation of summary buffer).
10906          (progn 
10907            (unless (and
10908                     (eq gnus-summary-highlight-line-downloaded-alist
10909                         gnus-agent-article-alist)
10910                     (<= (caar gnus-summary-highlight-line-downloaded-cached)
10911                         article))
10912              (setq gnus-summary-highlight-line-downloaded-alist
10913                    gnus-agent-article-alist)
10914              (setq gnus-summary-highlight-line-downloaded-cached
10915                    gnus-agent-article-alist))
10916            (let (n)
10917              (while (and (< (caar gnus-summary-highlight-line-downloaded-cached)
10918                             article)
10919                          (setq n (cdr gnus-summary-highlight-line-downloaded-cached)))
10920                (setq gnus-summary-highlight-line-downloaded-cached n)))
10921            (and (eq (caar gnus-summary-highlight-line-downloaded-cached)
10922                     article)
10923                 (cdar gnus-summary-highlight-line-downloaded-cached))))))
10924     (let ((face (funcall (gnus-summary-highlight-line-0))))
10925       (unless (eq face (get-text-property beg 'face))
10926         (gnus-put-text-property-excluding-characters-with-faces
10927          beg (gnus-point-at-eol) 'face
10928          (setq face (if (boundp face) (symbol-value face) face)))
10929         (when gnus-summary-highlight-line-function
10930           (funcall gnus-summary-highlight-line-function article face))))))
10931
10932 (defun gnus-update-read-articles (group unread &optional compute)
10933   "Update the list of read articles in GROUP.
10934 UNREAD is a sorted list."
10935   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10936          (entry (gnus-gethash group gnus-newsrc-hashtb))
10937          (info (nth 2 entry))
10938          (prev 1)
10939          read)
10940     (if (or (not info) (not active))
10941         ;; There is no info on this group if it was, in fact,
10942         ;; killed.  Gnus stores no information on killed groups, so
10943         ;; there's nothing to be done.
10944         ;; One could store the information somewhere temporarily,
10945         ;; perhaps...  Hmmm...
10946         ()
10947       ;; Remove any negative articles numbers.
10948       (while (and unread (< (car unread) 0))
10949         (setq unread (cdr unread)))
10950       ;; Remove any expired article numbers
10951       (while (and unread (< (car unread) (car active)))
10952         (setq unread (cdr unread)))
10953       ;; Compute the ranges of read articles by looking at the list of
10954       ;; unread articles.
10955       (while unread
10956         (when (/= (car unread) prev)
10957           (push (if (= prev (1- (car unread))) prev
10958                   (cons prev (1- (car unread))))
10959                 read))
10960         (setq prev (1+ (car unread)))
10961         (setq unread (cdr unread)))
10962       (when (<= prev (cdr active))
10963         (push (cons prev (cdr active)) read))
10964       (setq read (if (> (length read) 1) (nreverse read) read))
10965       (if compute
10966           read
10967         (save-excursion
10968           (let (setmarkundo)
10969             ;; Propagate the read marks to the backend.
10970             (when (gnus-check-backend-function 'request-set-mark group)
10971               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10972                     (add (gnus-remove-from-range read (gnus-info-read info))))
10973                 (when (or add del)
10974                   (unless (gnus-check-group group)
10975                     (error "Can't open server for %s" group))
10976                   (gnus-request-set-mark
10977                    group (delq nil (list (if add (list add 'add '(read)))
10978                                          (if del (list del 'del '(read))))))
10979                   (setq setmarkundo
10980                         `(gnus-request-set-mark
10981                           ,group
10982                           ',(delq nil (list
10983                                        (if del (list del 'add '(read)))
10984                                        (if add (list add 'del '(read))))))))))
10985             (set-buffer gnus-group-buffer)
10986             (gnus-undo-register
10987               `(progn
10988                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10989                  (gnus-info-set-read ',info ',(gnus-info-read info))
10990                  (gnus-get-unread-articles-in-group ',info
10991                                                     (gnus-active ,group))
10992                  (gnus-group-update-group ,group t)
10993                  ,setmarkundo))))
10994         ;; Enter this list into the group info.
10995         (gnus-info-set-read info read)
10996         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10997         (gnus-get-unread-articles-in-group info (gnus-active group))
10998         t))))
10999
11000 (defun gnus-offer-save-summaries ()
11001   "Offer to save all active summary buffers."
11002   (let (buffers)
11003     ;; Go through all buffers and find all summaries.
11004     (dolist (buffer (buffer-list))
11005       (when (and (setq buffer (buffer-name buffer))
11006                  (string-match "Summary" buffer)
11007                  (save-excursion
11008                    (set-buffer buffer)
11009                    ;; We check that this is, indeed, a summary buffer.
11010                    (and (eq major-mode 'gnus-summary-mode)
11011                         ;; Also make sure this isn't bogus.
11012                         gnus-newsgroup-prepared
11013                         ;; Also make sure that this isn't a
11014                         ;; dead summary buffer.
11015                         (not gnus-dead-summary-mode))))
11016         (push buffer buffers)))
11017     ;; Go through all these summary buffers and offer to save them.
11018     (when buffers
11019       (save-excursion
11020         (map-y-or-n-p
11021          "Update summary buffer %s? "
11022          (lambda (buf)
11023            (switch-to-buffer buf)
11024            (gnus-summary-exit))
11025          buffers)))))
11026
11027 (defun gnus-summary-setup-default-charset ()
11028   "Setup newsgroup default charset."
11029   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11030       (setq gnus-newsgroup-charset nil)
11031     (let* ((ignored-charsets
11032             (or gnus-newsgroup-ephemeral-ignored-charsets
11033                 (append
11034                  (and gnus-newsgroup-name
11035                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11036                  gnus-newsgroup-ignored-charsets))))
11037       (setq gnus-newsgroup-charset
11038             (or gnus-newsgroup-ephemeral-charset
11039                 (and gnus-newsgroup-name
11040                      (gnus-parameter-charset gnus-newsgroup-name))
11041                 gnus-default-charset))
11042       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11043            ignored-charsets))))
11044
11045 ;;;
11046 ;;; Mime Commands
11047 ;;;
11048
11049 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11050   "Display the current article buffer fully MIME-buttonized.
11051 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11052 treated as multipart/mixed."
11053   (interactive "P")
11054   (require 'gnus-art)
11055   (let ((gnus-unbuttonized-mime-types nil)
11056         (gnus-mime-display-multipart-as-mixed show-all-parts))
11057     (gnus-summary-show-article)))
11058
11059 (defun gnus-summary-repair-multipart (article)
11060   "Add a Content-Type header to a multipart article without one."
11061   (interactive (list (gnus-summary-article-number)))
11062   (gnus-with-article article
11063     (message-narrow-to-head)
11064     (message-remove-header "Mime-Version")
11065     (goto-char (point-max))
11066     (insert "Mime-Version: 1.0\n")
11067     (widen)
11068     (when (search-forward "\n--" nil t)
11069       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11070         (message-narrow-to-head)
11071         (message-remove-header "Content-Type")
11072         (goto-char (point-max))
11073         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11074                         separator))
11075         (widen))))
11076   (let (gnus-mark-article-hook)
11077     (gnus-summary-select-article t t nil article)))
11078
11079 (defun gnus-summary-toggle-display-buttonized ()
11080   "Toggle the buttonizing of the article buffer."
11081   (interactive)
11082   (require 'gnus-art)
11083   (if (setq gnus-inhibit-mime-unbuttonizing
11084             (not gnus-inhibit-mime-unbuttonizing))
11085       (let ((gnus-unbuttonized-mime-types nil))
11086         (gnus-summary-show-article))
11087     (gnus-summary-show-article)))
11088
11089 ;;;
11090 ;;; Generic summary marking commands
11091 ;;;
11092
11093 (defvar gnus-summary-marking-alist
11094   '((read gnus-del-mark "d")
11095     (unread gnus-unread-mark "u")
11096     (ticked gnus-ticked-mark "!")
11097     (dormant gnus-dormant-mark "?")
11098     (expirable gnus-expirable-mark "e"))
11099   "An alist of names/marks/keystrokes.")
11100
11101 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11102 (defvar gnus-summary-mark-map)
11103
11104 (defun gnus-summary-make-all-marking-commands ()
11105   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11106   (dolist (elem gnus-summary-marking-alist)
11107     (apply 'gnus-summary-make-marking-command elem)))
11108
11109 (defun gnus-summary-make-marking-command (name mark keystroke)
11110   (let ((map (make-sparse-keymap)))
11111     (define-key gnus-summary-generic-mark-map keystroke map)
11112     (dolist (lway `((next "next" next nil "n")
11113                     (next-unread "next unread" next t "N")
11114                     (prev "previous" prev nil "p")
11115                     (prev-unread "previous unread" prev t "P")
11116                     (nomove "" nil nil ,keystroke)))
11117       (let ((func (gnus-summary-make-marking-command-1
11118                    mark (car lway) lway name)))
11119         (setq func (eval func))
11120         (define-key map (nth 4 lway) func)))))
11121
11122 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11123   `(defun ,(intern
11124             (format "gnus-summary-put-mark-as-%s%s"
11125                     name (if (eq way 'nomove)
11126                              ""
11127                            (concat "-" (symbol-name way)))))
11128      (n)
11129      ,(format
11130        "Mark the current article as %s%s.
11131 If N, the prefix, then repeat N times.
11132 If N is negative, move in reverse order.
11133 The difference between N and the actual number of articles marked is
11134 returned."
11135        name (cadr lway))
11136      (interactive "p")
11137      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11138
11139 (defun gnus-summary-generic-mark (n mark move unread)
11140   "Mark N articles with MARK."
11141   (unless (eq major-mode 'gnus-summary-mode)
11142     (error "This command can only be used in the summary buffer"))
11143   (gnus-summary-show-thread)
11144   (let ((nummove
11145          (cond
11146           ((eq move 'next) 1)
11147           ((eq move 'prev) -1)
11148           (t 0))))
11149     (if (zerop nummove)
11150         (setq n 1)
11151       (when (< n 0)
11152         (setq n (abs n)
11153               nummove (* -1 nummove))))
11154     (while (and (> n 0)
11155                 (gnus-summary-mark-article nil mark)
11156                 (zerop (gnus-summary-next-subject nummove unread t)))
11157       (setq n (1- n)))
11158     (when (/= 0 n)
11159       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11160     (gnus-summary-recenter)
11161     (gnus-summary-position-point)
11162     (gnus-set-mode-line 'summary)
11163     n))
11164
11165 (defun gnus-summary-insert-articles (articles)
11166   (when (setq articles
11167               (gnus-sorted-difference articles
11168                                       (mapcar (lambda (h)
11169                                                 (mail-header-number h))
11170                                               gnus-newsgroup-headers)))
11171     (setq gnus-newsgroup-headers
11172           (merge 'list
11173                  gnus-newsgroup-headers
11174                  (gnus-fetch-headers articles)
11175                  'gnus-article-sort-by-number))
11176     ;; Suppress duplicates?
11177     (when gnus-suppress-duplicates
11178       (gnus-dup-suppress-articles))
11179
11180     ;; We might want to build some more threads first.
11181     (when (and gnus-fetch-old-headers
11182                (eq gnus-headers-retrieved-by 'nov))
11183       (if (eq gnus-fetch-old-headers 'invisible)
11184           (gnus-build-all-threads)
11185         (gnus-build-old-threads)))
11186     ;; Let the Gnus agent mark articles as read.
11187     (when gnus-agent
11188       (gnus-agent-get-undownloaded-list))
11189     ;; Remove list identifiers from subject
11190     (when gnus-list-identifiers
11191       (gnus-summary-remove-list-identifiers))
11192     ;; First and last article in this newsgroup.
11193     (when gnus-newsgroup-headers
11194       (setq gnus-newsgroup-begin
11195             (mail-header-number (car gnus-newsgroup-headers))
11196             gnus-newsgroup-end
11197             (mail-header-number
11198              (gnus-last-element gnus-newsgroup-headers))))
11199     (when gnus-use-scoring
11200       (gnus-possibly-score-headers))))
11201
11202 (defun gnus-summary-insert-old-articles (&optional all)
11203   "Insert all old articles in this group.
11204 If ALL is non-nil, already read articles become readable.
11205 If ALL is a number, fetch this number of articles."
11206   (interactive "P")
11207   (prog1
11208       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11209             older len)
11210         (setq older
11211               ;; Some nntp servers lie about their active range.  When this happens, the active
11212               ;; range can be in the millions.
11213               ;; Use a compressed range to avoid creating a huge list.
11214               (gnus-range-difference (list gnus-newsgroup-active) old))
11215         (setq len (gnus-range-length older))
11216         (cond
11217          ((null older) nil)
11218          ((numberp all)
11219           (if (< all len)
11220               (let ((older-range (nreverse older)))
11221                 (setq older nil)
11222
11223                 (while (> all 0)
11224                   (let* ((r (pop older-range))
11225                          (min (if (numberp r) r (car r)))
11226                          (max (if (numberp r) r (cdr r))))
11227                     (while (and (<= min max)
11228                                 (> all 0))
11229                       (push max older)
11230                       (setq all (1- all)
11231                             max (1- max))))))
11232             (setq older (gnus-uncompress-range older))))
11233          (all
11234           (setq older (gnus-uncompress-range older)))
11235          (t
11236           (when (and (numberp gnus-large-newsgroup)
11237                    (> len gnus-large-newsgroup))
11238               (let* ((cursor-in-echo-area nil)
11239                      (initial (gnus-parameter-large-newsgroup-initial
11240                                gnus-newsgroup-name))
11241                      (input
11242                       (read-string
11243                        (format
11244                         "How many articles from %s (%s %d): "
11245                         (gnus-limit-string
11246                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11247                         (if initial "max" "default")
11248                         len)
11249                        (if initial
11250                            (cons (number-to-string initial)
11251                                  0)))))
11252                 (unless (string-match "^[ \t]*$" input)
11253                   (setq all (string-to-number input))
11254                   (if (< all len)
11255                       (let ((older-range (nreverse older)))
11256                         (setq older nil)
11257
11258                         (while (> all 0)
11259                           (let* ((r (pop older-range))
11260                                  (min (if (numberp r) r (car r)))
11261                                  (max (if (numberp r) r (cdr r))))
11262                             (while (and (<= min max)
11263                                         (> all 0))
11264                               (push max older)
11265                               (setq all (1- all)
11266                                     max (1- max))))))))))
11267           (setq older (gnus-uncompress-range older))))
11268         (if (not older)
11269             (message "No old news.")
11270           (gnus-summary-insert-articles older)
11271           (gnus-summary-limit (gnus-sorted-nunion old older))))
11272     (gnus-summary-position-point)))
11273
11274 (defun gnus-summary-insert-new-articles ()
11275   "Insert all new articles in this group."
11276   (interactive)
11277   (prog1
11278       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11279             (old-active gnus-newsgroup-active)
11280             (nnmail-fetched-sources (list t))
11281             i new)
11282         (setq gnus-newsgroup-active
11283               (gnus-activate-group gnus-newsgroup-name 'scan))
11284         (setq i (cdr gnus-newsgroup-active))
11285         (while (> i (cdr old-active))
11286           (push i new)
11287           (decf i))
11288         (if (not new)
11289             (message "No gnus is bad news.")
11290           (gnus-summary-insert-articles new)
11291           (setq gnus-newsgroup-unreads
11292                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11293           (gnus-summary-limit (gnus-sorted-nunion old new))))
11294     (gnus-summary-position-point)))
11295
11296 (gnus-summary-make-all-marking-commands)
11297
11298 (gnus-ems-redefine)
11299
11300 (provide 'gnus-sum)
11301
11302 (run-hooks 'gnus-sum-load-hook)
11303
11304 ;;; gnus-sum.el ends here