ba7f2d945f495456bc25bdf8af906389115ce411
[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   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
147   :group 'gnus-thread
148   :type '(choice (const :tag "off" nil)
149                  regexp))
150
151 (defcustom gnus-build-sparse-threads nil
152   "*If non-nil, fill in the gaps in threads.
153 If `some', only fill in the gaps that are needed to tie loose threads
154 together.  If `more', fill in all leaf nodes that Gnus can find.  If
155 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
156   :group 'gnus-thread
157   :type '(choice (const :tag "off" nil)
158                  (const some)
159                  (const more)
160                  (sexp :menu-tag "all" t)))
161
162 (defcustom gnus-summary-thread-gathering-function
163   'gnus-gather-threads-by-subject
164   "*Function used for gathering loose threads.
165 There are two pre-defined functions: `gnus-gather-threads-by-subject',
166 which only takes Subjects into consideration; and
167 `gnus-gather-threads-by-references', which compared the References
168 headers of the articles to find matches."
169   :group 'gnus-thread
170   :type '(radio (function-item gnus-gather-threads-by-subject)
171                 (function-item gnus-gather-threads-by-references)
172                 (function :tag "other")))
173
174 (defcustom gnus-summary-same-subject ""
175   "*String indicating that the current article has the same subject as the previous.
176 This variable will only be used if the value of
177 `gnus-summary-make-false-root' is `empty'."
178   :group 'gnus-summary-format
179   :type 'string)
180
181 (defcustom gnus-summary-goto-unread t
182   "*If t, 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 (defcustom gnus-summary-highlight
850   '(((eq mark gnus-canceled-mark)
851      . gnus-summary-cancelled-face)
852     ((and (> score default-high)
853           (or (eq mark gnus-dormant-mark)
854               (eq mark gnus-ticked-mark)))
855      . gnus-summary-high-ticked-face)
856     ((and (< score default-low)
857           (or (eq mark gnus-dormant-mark)
858               (eq mark gnus-ticked-mark)))
859      . gnus-summary-low-ticked-face)
860     ((or (eq mark gnus-dormant-mark)
861          (eq mark gnus-ticked-mark))
862      . gnus-summary-normal-ticked-face)
863     ((and (> score default-high) (eq mark gnus-ancient-mark))
864      . gnus-summary-high-ancient-face)
865     ((and (< score default-low) (eq mark gnus-ancient-mark))
866      . gnus-summary-low-ancient-face)
867     ((eq mark gnus-ancient-mark)
868      . gnus-summary-normal-ancient-face)
869     (downloaded
870      . gnus-agent-downloaded-article-face)
871     ((and (> score default-high) (eq mark gnus-unread-mark))
872      . gnus-summary-high-unread-face)
873     ((and (< score default-low) (eq mark gnus-unread-mark))
874      . gnus-summary-low-unread-face)
875     ((eq mark gnus-unread-mark)
876      . gnus-summary-normal-unread-face)
877     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
878                                                   gnus-undownloaded-mark)))
879      . gnus-summary-high-unread-face)
880     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
881                                                  gnus-undownloaded-mark)))
882      . gnus-summary-low-unread-face)
883     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
884           (memq article gnus-newsgroup-unreads))
885      . gnus-summary-normal-unread-face)
886     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
887      . gnus-summary-normal-read-face)
888     ((> score default-high)
889      . gnus-summary-high-read-face)
890     ((< score default-low)
891      . gnus-summary-low-read-face)
892     (t
893      . gnus-summary-normal-read-face))
894   "*Controls the highlighting of summary buffer lines.
895
896 A list of (FORM . FACE) pairs.  When deciding how a a particular
897 summary line should be displayed, each form is evaluated.  The content
898 of the face field after the first true form is used.  You can change
899 how those summary lines are displayed, by editing the face field.
900
901 You can use the following variables in the FORM field.
902
903 score:        The article's score
904 default:      The default article score.
905 default-high: The default score for high scored articles.
906 default-low:  The default score for low scored articles.
907 below:        The score below which articles are automatically marked as read.
908 mark:         The articles mark."
909   :group 'gnus-summary-visual
910   :type '(repeat (cons (sexp :tag "Form" nil)
911                        face)))
912
913 (defcustom gnus-alter-header-function nil
914   "Function called to allow alteration of article header structures.
915 The function is called with one parameter, the article header vector,
916 which it may alter in any way.")
917
918 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
919   "Variable that says which function should be used to decode a string with encoded words.")
920
921 (defcustom gnus-extra-headers '(To Newsgroups)
922   "*Extra headers to parse."
923   :version "21.1"
924   :group 'gnus-summary
925   :type '(repeat symbol))
926
927 (defcustom gnus-ignored-from-addresses
928   (and user-mail-address (regexp-quote user-mail-address))
929   "*Regexp of From headers that may be suppressed in favor of To headers."
930   :version "21.1"
931   :group 'gnus-summary
932   :type 'regexp)
933
934 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
935   "List of charsets that should be ignored.
936 When these charsets are used in the \"charset\" parameter, the
937 default charset will be used instead."
938   :version "21.1"
939   :type '(repeat symbol)
940   :group 'gnus-charset)
941
942 (gnus-define-group-parameter
943  ignored-charsets
944  :type list
945  :function-document
946  "Return the ignored charsets of GROUP."
947  :variable gnus-group-ignored-charsets-alist
948  :variable-default
949  '(("alt\\.chinese\\.text" iso-8859-1))
950  :variable-document
951  "Alist of regexps (to match group names) and charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954  :variable-group gnus-charset
955  :variable-type '(repeat (cons (regexp :tag "Group")
956                                (repeat symbol)))
957  :parameter-type '(choice :tag "Ignored charsets"
958                           :value nil
959                           (repeat (symbol)))
960  :parameter-document       "\
961 List of charsets that should be ignored.
962
963 When these charsets are used in the \"charset\" parameter, the
964 default charset will be used instead.")
965
966 (defcustom gnus-group-highlight-words-alist nil
967   "Alist of group regexps and highlight regexps.
968 This variable uses the same syntax as `gnus-emphasis-alist'."
969   :version "21.1"
970   :type '(repeat (cons (regexp :tag "Group")
971                        (repeat (list (regexp :tag "Highlight regexp")
972                                      (number :tag "Group for entire word" 0)
973                                      (number :tag "Group for displayed part" 0)
974                                      (symbol :tag "Face"
975                                              gnus-emphasis-highlight-words)))))
976   :group 'gnus-summary-visual)
977
978 (defcustom gnus-summary-show-article-charset-alist
979   nil
980   "Alist of number and charset.
981 The article will be shown with the charset corresponding to the
982 numbered argument.
983 For example: ((1 . cn-gb-2312) (2 . big5))."
984   :version "21.1"
985   :type '(repeat (cons (number :tag "Argument" 1)
986                        (symbol :tag "Charset")))
987   :group 'gnus-charset)
988
989 (defcustom gnus-preserve-marks t
990   "Whether marks are preserved when moving, copying and respooling messages."
991   :version "21.1"
992   :type 'boolean
993   :group 'gnus-summary-marks)
994
995 (defcustom gnus-alter-articles-to-read-function nil
996   "Function to be called to alter the list of articles to be selected."
997   :type '(choice (const nil) function)
998   :group 'gnus-summary)
999
1000 (defcustom gnus-orphan-score nil
1001   "*All orphans get this score added.  Set in the score file."
1002   :group 'gnus-score-default
1003   :type '(choice (const nil)
1004                  integer))
1005
1006 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1007   "*A regexp to match MIME parts when saving multiple parts of a message
1008 with gnus-summary-save-parts (X m). This regexp will be used by default
1009 when prompting the user for which type of files to save."
1010   :group 'gnus-summary
1011   :type 'regexp)
1012
1013 (defcustom gnus-read-all-available-headers nil
1014   "Whether Gnus should parse all headers made available to it.
1015 This is mostly relevant for slow backends where the user may
1016 wish to widen the summary buffer to include all headers
1017 that were fetched.  Say, for nnultimate groups."
1018   :group 'gnus-summary
1019   :type '(choice boolean regexp))
1020
1021 (defcustom gnus-summary-muttprint-program "muttprint"
1022   "Command (and optional arguments) used to run Muttprint."
1023   :version "21.3"
1024   :group 'gnus-summary
1025   :type 'string)
1026
1027 (defcustom gnus-article-loose-mime nil
1028   "If non-nil, don't require MIME-Version header.
1029 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1030 supply the MIME-Version header or deliberately strip it From the mail.
1031 Set it to non-nil, Gnus will treat some articles as MIME even if
1032 the MIME-Version header is missed."
1033   :version "21.3"
1034   :type 'boolean
1035   :group 'gnus-article)
1036
1037 ;;; Internal variables
1038
1039 (defvar gnus-summary-display-cache nil)
1040 (defvar gnus-article-mime-handles nil)
1041 (defvar gnus-article-decoded-p nil)
1042 (defvar gnus-article-charset nil)
1043 (defvar gnus-article-ignored-charsets nil)
1044 (defvar gnus-scores-exclude-files nil)
1045 (defvar gnus-page-broken nil)
1046 (defvar gnus-inhibit-mime-unbuttonizing nil)
1047
1048 (defvar gnus-original-article nil)
1049 (defvar gnus-article-internal-prepare-hook nil)
1050 (defvar gnus-newsgroup-process-stack nil)
1051
1052 (defvar gnus-thread-indent-array nil)
1053 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1054 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1055   "Function called to sort the articles within a thread after it has been gathered together.")
1056
1057 (defvar gnus-summary-save-parts-type-history nil)
1058 (defvar gnus-summary-save-parts-last-directory nil)
1059
1060 ;; Avoid highlighting in kill files.
1061 (defvar gnus-summary-inhibit-highlight nil)
1062 (defvar gnus-newsgroup-selected-overlay nil)
1063 (defvar gnus-inhibit-limiting nil)
1064 (defvar gnus-newsgroup-adaptive-score-file nil)
1065 (defvar gnus-current-score-file nil)
1066 (defvar gnus-current-move-group nil)
1067 (defvar gnus-current-copy-group nil)
1068 (defvar gnus-current-crosspost-group nil)
1069 (defvar gnus-newsgroup-display nil)
1070
1071 (defvar gnus-newsgroup-dependencies nil)
1072 (defvar gnus-newsgroup-adaptive nil)
1073 (defvar gnus-summary-display-article-function nil)
1074 (defvar gnus-summary-highlight-line-function nil
1075   "Function called after highlighting a summary line.")
1076
1077 (defvar gnus-summary-line-format-alist
1078   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1079     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1080     (?s gnus-tmp-subject-or-nil ?s)
1081     (?n gnus-tmp-name ?s)
1082     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1083         ?s)
1084     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1085             gnus-tmp-from) ?s)
1086     (?F gnus-tmp-from ?s)
1087     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1088     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1089     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1090     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1091     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1092     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1093     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1094     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1095     (?L gnus-tmp-lines ?s)
1096     (?I gnus-tmp-indentation ?s)
1097     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1098     (?R gnus-tmp-replied ?c)
1099     (?\[ gnus-tmp-opening-bracket ?c)
1100     (?\] gnus-tmp-closing-bracket ?c)
1101     (?\> (make-string gnus-tmp-level ? ) ?s)
1102     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1103     (?i gnus-tmp-score ?d)
1104     (?z gnus-tmp-score-char ?c)
1105     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1106     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1107     (?U gnus-tmp-unread ?c)
1108     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1109         ?s)
1110     (?t (gnus-summary-number-of-articles-in-thread
1111          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1112         ?d)
1113     (?e (gnus-summary-number-of-articles-in-thread
1114          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1115         ?c)
1116     (?u gnus-tmp-user-defined ?s)
1117     (?P (gnus-pick-line-number) ?d)
1118     (?B gnus-tmp-thread-tree-header-string ?s)
1119     (user-date (gnus-user-date
1120                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1121   "An alist of format specifications that can appear in summary lines.
1122 These are paired with what variables they correspond with, along with
1123 the type of the variable (string, integer, character, etc).")
1124
1125 (defvar gnus-summary-dummy-line-format-alist
1126   `((?S gnus-tmp-subject ?s)
1127     (?N gnus-tmp-number ?d)
1128     (?u gnus-tmp-user-defined ?s)))
1129
1130 (defvar gnus-summary-mode-line-format-alist
1131   `((?G gnus-tmp-group-name ?s)
1132     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1133     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1134     (?A gnus-tmp-article-number ?d)
1135     (?Z gnus-tmp-unread-and-unselected ?s)
1136     (?V gnus-version ?s)
1137     (?U gnus-tmp-unread-and-unticked ?d)
1138     (?S gnus-tmp-subject ?s)
1139     (?e gnus-tmp-unselected ?d)
1140     (?u gnus-tmp-user-defined ?s)
1141     (?d (length gnus-newsgroup-dormant) ?d)
1142     (?t (length gnus-newsgroup-marked) ?d)
1143     (?h (length gnus-newsgroup-spam-marked) ?d)
1144     (?r (length gnus-newsgroup-reads) ?d)
1145     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1146     (?E gnus-newsgroup-expunged-tally ?d)
1147     (?s (gnus-current-score-file-nondirectory) ?s)))
1148
1149 (defvar gnus-last-search-regexp nil
1150   "Default regexp for article search command.")
1151
1152 (defvar gnus-last-shell-command nil
1153   "Default shell command on article.")
1154
1155 (defvar gnus-newsgroup-begin nil)
1156 (defvar gnus-newsgroup-end nil)
1157 (defvar gnus-newsgroup-last-rmail nil)
1158 (defvar gnus-newsgroup-last-mail nil)
1159 (defvar gnus-newsgroup-last-folder nil)
1160 (defvar gnus-newsgroup-last-file nil)
1161 (defvar gnus-newsgroup-auto-expire nil)
1162 (defvar gnus-newsgroup-active nil)
1163
1164 (defvar gnus-newsgroup-data nil)
1165 (defvar gnus-newsgroup-data-reverse nil)
1166 (defvar gnus-newsgroup-limit nil)
1167 (defvar gnus-newsgroup-limits nil)
1168
1169 (defvar gnus-newsgroup-unreads nil
1170   "Sorted list of unread articles in the current newsgroup.")
1171
1172 (defvar gnus-newsgroup-unselected nil
1173   "Sorted list of unselected unread articles in the current newsgroup.")
1174
1175 (defvar gnus-newsgroup-reads nil
1176   "Alist of read articles and article marks in the current newsgroup.")
1177
1178 (defvar gnus-newsgroup-expunged-tally nil)
1179
1180 (defvar gnus-newsgroup-marked nil
1181   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1182
1183 (defvar gnus-newsgroup-spam-marked nil
1184   "List of ranges of articles that have been marked as spam.")
1185
1186 (defvar gnus-newsgroup-killed nil
1187   "List of ranges of articles that have been through the scoring process.")
1188
1189 (defvar gnus-newsgroup-cached nil
1190   "Sorted list of articles that come from the article cache.")
1191
1192 (defvar gnus-newsgroup-saved nil
1193   "List of articles that have been saved.")
1194
1195 (defvar gnus-newsgroup-kill-headers nil)
1196
1197 (defvar gnus-newsgroup-replied nil
1198   "List of articles that have been replied to in the current newsgroup.")
1199
1200 (defvar gnus-newsgroup-forwarded nil
1201   "List of articles that have been forwarded in the current newsgroup.")
1202
1203 (defvar gnus-newsgroup-recent nil
1204   "List of articles that have are recent in the current newsgroup.")
1205
1206 (defvar gnus-newsgroup-expirable nil
1207   "Sorted list of articles in the current newsgroup that can be expired.")
1208
1209 (defvar gnus-newsgroup-processable nil
1210   "List of articles in the current newsgroup that can be processed.")
1211
1212 (defvar gnus-newsgroup-downloadable nil
1213   "Sorted list of articles in the current newsgroup that can be processed.")
1214
1215 (defvar gnus-newsgroup-undownloaded nil
1216   "List of articles in the current newsgroup that haven't been downloaded..")
1217
1218 (defvar gnus-newsgroup-unsendable nil
1219   "List of articles in the current newsgroup that won't be sent.")
1220
1221 (defvar gnus-newsgroup-bookmarks nil
1222   "List of articles in the current newsgroup that have bookmarks.")
1223
1224 (defvar gnus-newsgroup-dormant nil
1225   "Sorted list of dormant articles in the current newsgroup.")
1226
1227 (defvar gnus-newsgroup-unseen nil
1228   "List of unseen articles in the current newsgroup.")
1229
1230 (defvar gnus-newsgroup-seen nil
1231   "Range of seen articles in the current newsgroup.")
1232
1233 (defvar gnus-newsgroup-articles nil
1234   "List of articles in the current newsgroup.")
1235
1236 (defvar gnus-newsgroup-scored nil
1237   "List of scored articles in the current newsgroup.")
1238
1239 (defvar gnus-newsgroup-headers nil
1240   "List of article headers in the current newsgroup.")
1241
1242 (defvar gnus-newsgroup-threads nil)
1243
1244 (defvar gnus-newsgroup-prepared nil
1245   "Whether the current group has been prepared properly.")
1246
1247 (defvar gnus-newsgroup-ancient nil
1248   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-sparse nil)
1251
1252 (defvar gnus-current-article nil)
1253 (defvar gnus-article-current nil)
1254 (defvar gnus-current-headers nil)
1255 (defvar gnus-have-all-headers nil)
1256 (defvar gnus-last-article nil)
1257 (defvar gnus-newsgroup-history nil)
1258 (defvar gnus-newsgroup-charset nil)
1259 (defvar gnus-newsgroup-ephemeral-charset nil)
1260 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1261
1262 (defvar gnus-article-before-search nil)
1263
1264 (defconst gnus-summary-local-variables
1265   '(gnus-newsgroup-name
1266     gnus-newsgroup-begin gnus-newsgroup-end
1267     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1268     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1269     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1270     gnus-newsgroup-unselected gnus-newsgroup-marked
1271     gnus-newsgroup-spam-marked
1272     gnus-newsgroup-reads gnus-newsgroup-saved
1273     gnus-newsgroup-replied gnus-newsgroup-forwarded
1274     gnus-newsgroup-recent
1275     gnus-newsgroup-expirable
1276     gnus-newsgroup-processable gnus-newsgroup-killed
1277     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1278     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1279     gnus-newsgroup-seen gnus-newsgroup-articles
1280     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1281     gnus-newsgroup-headers gnus-newsgroup-threads
1282     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1283     gnus-current-article gnus-current-headers gnus-have-all-headers
1284     gnus-last-article gnus-article-internal-prepare-hook
1285     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1286     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1287     gnus-thread-expunge-below
1288     gnus-score-alist gnus-current-score-file
1289     (gnus-summary-expunge-below . global)
1290     (gnus-summary-mark-below . global)
1291     (gnus-orphan-score . global)
1292     gnus-newsgroup-active gnus-scores-exclude-files
1293     gnus-newsgroup-history gnus-newsgroup-ancient
1294     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1295     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1296     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1297     (gnus-newsgroup-expunged-tally . 0)
1298     gnus-cache-removable-articles gnus-newsgroup-cached
1299     gnus-newsgroup-data gnus-newsgroup-data-reverse
1300     gnus-newsgroup-limit gnus-newsgroup-limits
1301     gnus-newsgroup-charset gnus-newsgroup-display)
1302   "Variables that are buffer-local to the summary buffers.")
1303
1304 (defvar gnus-newsgroup-variables nil
1305   "A list of variables that have separate values in different newsgroups.
1306 A list of newsgroup (summary buffer) local variables, or cons of
1307 variables and their default values (when the default values are not
1308 nil), that should be made global while the summary buffer is active.
1309 These variables can be used to set variables in the group parameters
1310 while still allowing them to affect operations done in other
1311 buffers. For example:
1312
1313 \(setq gnus-newsgroup-variables
1314      '(message-use-followup-to
1315        (gnus-visible-headers .
1316          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1317 ")
1318
1319 ;; Byte-compiler warning.
1320 (eval-when-compile (defvar gnus-article-mode-map))
1321
1322 ;; MIME stuff.
1323
1324 (defvar gnus-decode-encoded-word-methods
1325   '(mail-decode-encoded-word-string)
1326   "List of methods used to decode encoded words.
1327
1328 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1329 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1330 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1331 whose names match REGEXP.
1332
1333 For example:
1334 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1335  mail-decode-encoded-word-string
1336  (\"chinese\" . rfc1843-decode-string))")
1337
1338 (defvar gnus-decode-encoded-word-methods-cache nil)
1339
1340 (defun gnus-multi-decode-encoded-word-string (string)
1341   "Apply the functions from `gnus-encoded-word-methods' that match."
1342   (unless (and gnus-decode-encoded-word-methods-cache
1343                (eq gnus-newsgroup-name
1344                    (car gnus-decode-encoded-word-methods-cache)))
1345     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1346     (mapcar (lambda (x)
1347               (if (symbolp x)
1348                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1349                 (if (and gnus-newsgroup-name
1350                          (string-match (car x) gnus-newsgroup-name))
1351                     (nconc gnus-decode-encoded-word-methods-cache
1352                            (list (cdr x))))))
1353             gnus-decode-encoded-word-methods))
1354   (let ((xlist gnus-decode-encoded-word-methods-cache))
1355     (pop xlist)
1356     (while xlist
1357       (setq string (funcall (pop xlist) string))))
1358   string)
1359
1360 ;; Subject simplification.
1361
1362 (defun gnus-simplify-whitespace (str)
1363   "Remove excessive whitespace from STR."
1364   (let ((mystr str))
1365     ;; Multiple spaces.
1366     (while (string-match "[ \t][ \t]+" mystr)
1367       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1368                           " "
1369                           (substring mystr (match-end 0)))))
1370     ;; Leading spaces.
1371     (when (string-match "^[ \t]+" mystr)
1372       (setq mystr (substring mystr (match-end 0))))
1373     ;; Trailing spaces.
1374     (when (string-match "[ \t]+$" mystr)
1375       (setq mystr (substring mystr 0 (match-beginning 0))))
1376     mystr))
1377
1378 (defun gnus-simplify-all-whitespace (str)
1379   "Remove all whitespace from STR."
1380   (let ((mystr str))
1381     (while (string-match "[ \t\n]+" mystr)
1382       (setq mystr (replace-match "" nil nil mystr)))
1383     mystr))
1384
1385 (defsubst gnus-simplify-subject-re (subject)
1386   "Remove \"Re:\" from subject lines."
1387   (if (string-match message-subject-re-regexp subject)
1388       (substring subject (match-end 0))
1389     subject))
1390
1391 (defun gnus-simplify-subject (subject &optional re-only)
1392   "Remove `Re:' and words in parentheses.
1393 If RE-ONLY is non-nil, strip leading `Re:'s only."
1394   (let ((case-fold-search t))           ;Ignore case.
1395     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1396     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1397       (setq subject (substring subject (match-end 0))))
1398     ;; Remove uninteresting prefixes.
1399     (when (and (not re-only)
1400                gnus-simplify-ignored-prefixes
1401                (string-match gnus-simplify-ignored-prefixes subject))
1402       (setq subject (substring subject (match-end 0))))
1403     ;; Remove words in parentheses from end.
1404     (unless re-only
1405       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1406         (setq subject (substring subject 0 (match-beginning 0)))))
1407     ;; Return subject string.
1408     subject))
1409
1410 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1411 ;; all whitespace.
1412 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1413   (goto-char (point-min))
1414   (while (re-search-forward regexp nil t)
1415     (replace-match (or newtext ""))))
1416
1417 (defun gnus-simplify-buffer-fuzzy ()
1418   "Simplify string in the buffer fuzzily.
1419 The string in the accessible portion of the current buffer is simplified.
1420 It is assumed to be a single-line subject.
1421 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1422 matter is removed.  Additional things can be deleted by setting
1423 `gnus-simplify-subject-fuzzy-regexp'."
1424   (let ((case-fold-search t)
1425         (modified-tick))
1426     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1427
1428     (while (not (eq modified-tick (buffer-modified-tick)))
1429       (setq modified-tick (buffer-modified-tick))
1430       (cond
1431        ((listp gnus-simplify-subject-fuzzy-regexp)
1432         (mapcar 'gnus-simplify-buffer-fuzzy-step
1433                 gnus-simplify-subject-fuzzy-regexp))
1434        (gnus-simplify-subject-fuzzy-regexp
1435         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1436       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1437       (gnus-simplify-buffer-fuzzy-step
1438        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1439       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1440
1441     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1442     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1443     (gnus-simplify-buffer-fuzzy-step " $")
1444     (gnus-simplify-buffer-fuzzy-step "^ +")))
1445
1446 (defun gnus-simplify-subject-fuzzy (subject)
1447   "Simplify a subject string fuzzily.
1448 See `gnus-simplify-buffer-fuzzy' for details."
1449   (save-excursion
1450     (gnus-set-work-buffer)
1451     (let ((case-fold-search t))
1452       ;; Remove uninteresting prefixes.
1453       (when (and gnus-simplify-ignored-prefixes
1454                  (string-match gnus-simplify-ignored-prefixes subject))
1455         (setq subject (substring subject (match-end 0))))
1456       (insert subject)
1457       (inline (gnus-simplify-buffer-fuzzy))
1458       (buffer-string))))
1459
1460 (defsubst gnus-simplify-subject-fully (subject)
1461   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1462   (cond
1463    (gnus-simplify-subject-functions
1464     (gnus-map-function gnus-simplify-subject-functions subject))
1465    ((null gnus-summary-gather-subject-limit)
1466     (gnus-simplify-subject-re subject))
1467    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1468     (gnus-simplify-subject-fuzzy subject))
1469    ((numberp gnus-summary-gather-subject-limit)
1470     (gnus-limit-string (gnus-simplify-subject-re subject)
1471                        gnus-summary-gather-subject-limit))
1472    (t
1473     subject)))
1474
1475 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1476   "Check whether two subjects are equal.
1477 If optional argument simple-first is t, first argument is already
1478 simplified."
1479   (cond
1480    ((null simple-first)
1481     (equal (gnus-simplify-subject-fully s1)
1482            (gnus-simplify-subject-fully s2)))
1483    (t
1484     (equal s1
1485            (gnus-simplify-subject-fully s2)))))
1486
1487 (defun gnus-summary-bubble-group ()
1488   "Increase the score of the current group.
1489 This is a handy function to add to `gnus-summary-exit-hook' to
1490 increase the score of each group you read."
1491   (gnus-group-add-score gnus-newsgroup-name))
1492
1493 \f
1494 ;;;
1495 ;;; Gnus summary mode
1496 ;;;
1497
1498 (put 'gnus-summary-mode 'mode-class 'special)
1499
1500 (defvar gnus-article-commands-menu)
1501
1502 (when t
1503   ;; Non-orthogonal keys
1504
1505   (gnus-define-keys gnus-summary-mode-map
1506     " " gnus-summary-next-page
1507     "\177" gnus-summary-prev-page
1508     [delete] gnus-summary-prev-page
1509     [backspace] gnus-summary-prev-page
1510     "\r" gnus-summary-scroll-up
1511     "\M-\r" gnus-summary-scroll-down
1512     "n" gnus-summary-next-unread-article
1513     "p" gnus-summary-prev-unread-article
1514     "N" gnus-summary-next-article
1515     "P" gnus-summary-prev-article
1516     "\M-\C-n" gnus-summary-next-same-subject
1517     "\M-\C-p" gnus-summary-prev-same-subject
1518     "\M-n" gnus-summary-next-unread-subject
1519     "\M-p" gnus-summary-prev-unread-subject
1520     "." gnus-summary-first-unread-article
1521     "," gnus-summary-best-unread-article
1522     "\M-s" gnus-summary-search-article-forward
1523     "\M-r" gnus-summary-search-article-backward
1524     "<" gnus-summary-beginning-of-article
1525     ">" gnus-summary-end-of-article
1526     "j" gnus-summary-goto-article
1527     "^" gnus-summary-refer-parent-article
1528     "\M-^" gnus-summary-refer-article
1529     "u" gnus-summary-tick-article-forward
1530     "!" gnus-summary-tick-article-forward
1531     "U" gnus-summary-tick-article-backward
1532     "d" gnus-summary-mark-as-read-forward
1533     "D" gnus-summary-mark-as-read-backward
1534     "E" gnus-summary-mark-as-expirable
1535     "\M-u" gnus-summary-clear-mark-forward
1536     "\M-U" gnus-summary-clear-mark-backward
1537     "k" gnus-summary-kill-same-subject-and-select
1538     "\C-k" gnus-summary-kill-same-subject
1539     "\M-\C-k" gnus-summary-kill-thread
1540     "\M-\C-l" gnus-summary-lower-thread
1541     "e" gnus-summary-edit-article
1542     "#" gnus-summary-mark-as-processable
1543     "\M-#" gnus-summary-unmark-as-processable
1544     "\M-\C-t" gnus-summary-toggle-threads
1545     "\M-\C-s" gnus-summary-show-thread
1546     "\M-\C-h" gnus-summary-hide-thread
1547     "\M-\C-f" gnus-summary-next-thread
1548     "\M-\C-b" gnus-summary-prev-thread
1549     [(meta down)] gnus-summary-next-thread
1550     [(meta up)] gnus-summary-prev-thread
1551     "\M-\C-u" gnus-summary-up-thread
1552     "\M-\C-d" gnus-summary-down-thread
1553     "&" gnus-summary-execute-command
1554     "c" gnus-summary-catchup-and-exit
1555     "\C-w" gnus-summary-mark-region-as-read
1556     "\C-t" gnus-summary-toggle-truncation
1557     "?" gnus-summary-mark-as-dormant
1558     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1559     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1560     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1561     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1562     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1563     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1564     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1565     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1566     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1567     "\C-c\C-s\C-r" gnus-summary-sort-by-random
1568     "=" gnus-summary-expand-window
1569     "\C-x\C-s" gnus-summary-reselect-current-group
1570     "\M-g" gnus-summary-rescan-group
1571     "w" gnus-summary-stop-page-breaking
1572     "\C-c\C-r" gnus-summary-caesar-message
1573     "f" gnus-summary-followup
1574     "F" gnus-summary-followup-with-original
1575     "C" gnus-summary-cancel-article
1576     "r" gnus-summary-reply
1577     "R" gnus-summary-reply-with-original
1578     "\C-c\C-f" gnus-summary-mail-forward
1579     "o" gnus-summary-save-article
1580     "\C-o" gnus-summary-save-article-mail
1581     "|" gnus-summary-pipe-output
1582     "\M-k" gnus-summary-edit-local-kill
1583     "\M-K" gnus-summary-edit-global-kill
1584     ;; "V" gnus-version
1585     "\C-c\C-d" gnus-summary-describe-group
1586     "q" gnus-summary-exit
1587     "Q" gnus-summary-exit-no-update
1588     "\C-c\C-i" gnus-info-find-node
1589     gnus-mouse-2 gnus-mouse-pick-article
1590     "m" gnus-summary-mail-other-window
1591     "a" gnus-summary-post-news
1592     "i" gnus-summary-news-other-window
1593     "x" gnus-summary-limit-to-unread
1594     "s" gnus-summary-isearch-article
1595     "t" gnus-summary-toggle-header
1596     "g" gnus-summary-show-article
1597     "l" gnus-summary-goto-last-article
1598     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1599     "\C-d" gnus-summary-enter-digest-group
1600     "\M-\C-d" gnus-summary-read-document
1601     "\M-\C-e" gnus-summary-edit-parameters
1602     "\M-\C-a" gnus-summary-customize-parameters
1603     "\C-c\C-b" gnus-bug
1604     "*" gnus-cache-enter-article
1605     "\M-*" gnus-cache-remove-article
1606     "\M-&" gnus-summary-universal-argument
1607     "\C-l" gnus-recenter
1608     "I" gnus-summary-increase-score
1609     "L" gnus-summary-lower-score
1610     "\M-i" gnus-symbolic-argument
1611     "h" gnus-summary-select-article-buffer
1612
1613     "b" gnus-article-view-part
1614     "\M-t" gnus-summary-toggle-display-buttonized
1615
1616     "V" gnus-summary-score-map
1617     "X" gnus-uu-extract-map
1618     "S" gnus-summary-send-map)
1619
1620   ;; Sort of orthogonal keymap
1621   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1622     "t" gnus-summary-tick-article-forward
1623     "!" gnus-summary-tick-article-forward
1624     "d" gnus-summary-mark-as-read-forward
1625     "r" gnus-summary-mark-as-read-forward
1626     "c" gnus-summary-clear-mark-forward
1627     " " gnus-summary-clear-mark-forward
1628     "e" gnus-summary-mark-as-expirable
1629     "x" gnus-summary-mark-as-expirable
1630     "?" gnus-summary-mark-as-dormant
1631     "b" gnus-summary-set-bookmark
1632     "B" gnus-summary-remove-bookmark
1633     "#" gnus-summary-mark-as-processable
1634     "\M-#" gnus-summary-unmark-as-processable
1635     "S" gnus-summary-limit-include-expunged
1636     "C" gnus-summary-catchup
1637     "H" gnus-summary-catchup-to-here
1638     "h" gnus-summary-catchup-from-here
1639     "\C-c" gnus-summary-catchup-all
1640     "k" gnus-summary-kill-same-subject-and-select
1641     "K" gnus-summary-kill-same-subject
1642     "P" gnus-uu-mark-map)
1643
1644   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1645     "c" gnus-summary-clear-above
1646     "u" gnus-summary-tick-above
1647     "m" gnus-summary-mark-above
1648     "k" gnus-summary-kill-below)
1649
1650   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1651     "/" gnus-summary-limit-to-subject
1652     "n" gnus-summary-limit-to-articles
1653     "w" gnus-summary-pop-limit
1654     "s" gnus-summary-limit-to-subject
1655     "a" gnus-summary-limit-to-author
1656     "u" gnus-summary-limit-to-unread
1657     "m" gnus-summary-limit-to-marks
1658     "M" gnus-summary-limit-exclude-marks
1659     "v" gnus-summary-limit-to-score
1660     "*" gnus-summary-limit-include-cached
1661     "D" gnus-summary-limit-include-dormant
1662     "T" gnus-summary-limit-include-thread
1663     "d" gnus-summary-limit-exclude-dormant
1664     "t" gnus-summary-limit-to-age
1665     "." gnus-summary-limit-to-unseen
1666     "x" gnus-summary-limit-to-extra
1667     "p" gnus-summary-limit-to-display-predicate
1668     "E" gnus-summary-limit-include-expunged
1669     "c" gnus-summary-limit-exclude-childless-dormant
1670     "C" gnus-summary-limit-mark-excluded-as-read
1671     "o" gnus-summary-insert-old-articles
1672     "N" gnus-summary-insert-new-articles)
1673
1674   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1675     "n" gnus-summary-next-unread-article
1676     "p" gnus-summary-prev-unread-article
1677     "N" gnus-summary-next-article
1678     "P" gnus-summary-prev-article
1679     "\C-n" gnus-summary-next-same-subject
1680     "\C-p" gnus-summary-prev-same-subject
1681     "\M-n" gnus-summary-next-unread-subject
1682     "\M-p" gnus-summary-prev-unread-subject
1683     "f" gnus-summary-first-unread-article
1684     "b" gnus-summary-best-unread-article
1685     "j" gnus-summary-goto-article
1686     "g" gnus-summary-goto-subject
1687     "l" gnus-summary-goto-last-article
1688     "o" gnus-summary-pop-article)
1689
1690   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1691     "k" gnus-summary-kill-thread
1692     "l" gnus-summary-lower-thread
1693     "i" gnus-summary-raise-thread
1694     "T" gnus-summary-toggle-threads
1695     "t" gnus-summary-rethread-current
1696     "^" gnus-summary-reparent-thread
1697     "s" gnus-summary-show-thread
1698     "S" gnus-summary-show-all-threads
1699     "h" gnus-summary-hide-thread
1700     "H" gnus-summary-hide-all-threads
1701     "n" gnus-summary-next-thread
1702     "p" gnus-summary-prev-thread
1703     "u" gnus-summary-up-thread
1704     "o" gnus-summary-top-thread
1705     "d" gnus-summary-down-thread
1706     "#" gnus-uu-mark-thread
1707     "\M-#" gnus-uu-unmark-thread)
1708
1709   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1710     "g" gnus-summary-prepare
1711     "c" gnus-summary-insert-cached-articles)
1712
1713   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1714     "c" gnus-summary-catchup-and-exit
1715     "C" gnus-summary-catchup-all-and-exit
1716     "E" gnus-summary-exit-no-update
1717     "Q" gnus-summary-exit
1718     "Z" gnus-summary-exit
1719     "n" gnus-summary-catchup-and-goto-next-group
1720     "R" gnus-summary-reselect-current-group
1721     "G" gnus-summary-rescan-group
1722     "N" gnus-summary-next-group
1723     "s" gnus-summary-save-newsrc
1724     "P" gnus-summary-prev-group)
1725
1726   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1727     " " gnus-summary-next-page
1728     "n" gnus-summary-next-page
1729     "\177" gnus-summary-prev-page
1730     [delete] gnus-summary-prev-page
1731     "p" gnus-summary-prev-page
1732     "\r" gnus-summary-scroll-up
1733     "\M-\r" gnus-summary-scroll-down
1734     "<" gnus-summary-beginning-of-article
1735     ">" gnus-summary-end-of-article
1736     "b" gnus-summary-beginning-of-article
1737     "e" gnus-summary-end-of-article
1738     "^" gnus-summary-refer-parent-article
1739     "r" gnus-summary-refer-parent-article
1740     "D" gnus-summary-enter-digest-group
1741     "R" gnus-summary-refer-references
1742     "T" gnus-summary-refer-thread
1743     "g" gnus-summary-show-article
1744     "s" gnus-summary-isearch-article
1745     "P" gnus-summary-print-article
1746     "M" gnus-mailing-list-insinuate
1747     "t" gnus-article-babel)
1748
1749   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1750     "b" gnus-article-add-buttons
1751     "B" gnus-article-add-buttons-to-head
1752     "o" gnus-article-treat-overstrike
1753     "e" gnus-article-emphasize
1754     "w" gnus-article-fill-cited-article
1755     "Q" gnus-article-fill-long-lines
1756     "C" gnus-article-capitalize-sentences
1757     "c" gnus-article-remove-cr
1758     "q" gnus-article-de-quoted-unreadable
1759     "6" gnus-article-de-base64-unreadable
1760     "Z" gnus-article-decode-HZ
1761     "h" gnus-article-wash-html
1762     "u" gnus-article-unsplit-urls
1763     "s" gnus-summary-force-verify-and-decrypt
1764     "f" gnus-article-display-x-face
1765     "l" gnus-summary-stop-page-breaking
1766     "r" gnus-summary-caesar-message
1767     "m" gnus-summary-morse-message
1768     "t" gnus-summary-toggle-header
1769     "g" gnus-treat-smiley
1770     "v" gnus-summary-verbose-headers
1771     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1772     "p" gnus-article-verify-x-pgp-sig
1773     "d" gnus-article-treat-dumbquotes
1774     "k" gnus-article-outlook-deuglify-article)
1775
1776   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1777     "a" gnus-article-hide
1778     "h" gnus-article-hide-headers
1779     "b" gnus-article-hide-boring-headers
1780     "s" gnus-article-hide-signature
1781     "c" gnus-article-hide-citation
1782     "C" gnus-article-hide-citation-in-followups
1783     "l" gnus-article-hide-list-identifiers
1784     "p" gnus-article-hide-pgp
1785     "B" gnus-article-strip-banner
1786     "P" gnus-article-hide-pem
1787     "\C-c" gnus-article-hide-citation-maybe)
1788
1789   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1790     "a" gnus-article-highlight
1791     "h" gnus-article-highlight-headers
1792     "c" gnus-article-highlight-citation
1793     "s" gnus-article-highlight-signature)
1794
1795   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1796     "f" gnus-article-treat-fold-headers
1797     "u" gnus-article-treat-unfold-headers
1798     "n" gnus-article-treat-fold-newsgroups)
1799
1800   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1801     "x" gnus-article-display-x-face
1802     "s" gnus-treat-smiley
1803     "D" gnus-article-remove-images
1804     "f" gnus-treat-from-picon
1805     "m" gnus-treat-mail-picon
1806     "n" gnus-treat-newsgroups-picon)
1807
1808   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1809     "w" gnus-article-decode-mime-words
1810     "c" gnus-article-decode-charset
1811     "v" gnus-mime-view-all-parts
1812     "b" gnus-article-view-part)
1813
1814   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1815     "z" gnus-article-date-ut
1816     "u" gnus-article-date-ut
1817     "l" gnus-article-date-local
1818     "p" gnus-article-date-english
1819     "e" gnus-article-date-lapsed
1820     "o" gnus-article-date-original
1821     "i" gnus-article-date-iso8601
1822     "s" gnus-article-date-user)
1823
1824   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1825     "t" gnus-article-remove-trailing-blank-lines
1826     "l" gnus-article-strip-leading-blank-lines
1827     "m" gnus-article-strip-multiple-blank-lines
1828     "a" gnus-article-strip-blank-lines
1829     "A" gnus-article-strip-all-blank-lines
1830     "s" gnus-article-strip-leading-space
1831     "e" gnus-article-strip-trailing-space
1832     "w" gnus-article-remove-leading-whitespace)
1833
1834   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1835     "v" gnus-version
1836     "f" gnus-summary-fetch-faq
1837     "d" gnus-summary-describe-group
1838     "h" gnus-summary-describe-briefly
1839     "i" gnus-info-find-node
1840     "c" gnus-group-fetch-charter
1841     "C" gnus-group-fetch-control)
1842
1843   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1844     "e" gnus-summary-expire-articles
1845     "\M-\C-e" gnus-summary-expire-articles-now
1846     "\177" gnus-summary-delete-article
1847     [delete] gnus-summary-delete-article
1848     [backspace] gnus-summary-delete-article
1849     "m" gnus-summary-move-article
1850     "r" gnus-summary-respool-article
1851     "w" gnus-summary-edit-article
1852     "c" gnus-summary-copy-article
1853     "B" gnus-summary-crosspost-article
1854     "q" gnus-summary-respool-query
1855     "t" gnus-summary-respool-trace
1856     "i" gnus-summary-import-article
1857     "I" gnus-summary-create-article
1858     "p" gnus-summary-article-posted-p)
1859
1860   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1861     "o" gnus-summary-save-article
1862     "m" gnus-summary-save-article-mail
1863     "F" gnus-summary-write-article-file
1864     "r" gnus-summary-save-article-rmail
1865     "f" gnus-summary-save-article-file
1866     "b" gnus-summary-save-article-body-file
1867     "h" gnus-summary-save-article-folder
1868     "v" gnus-summary-save-article-vm
1869     "p" gnus-summary-pipe-output
1870     "P" gnus-summary-muttprint
1871     "s" gnus-soup-add-article)
1872
1873   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1874     "b" gnus-summary-display-buttonized
1875     "m" gnus-summary-repair-multipart
1876     "v" gnus-article-view-part
1877     "o" gnus-article-save-part
1878     "c" gnus-article-copy-part
1879     "C" gnus-article-view-part-as-charset
1880     "e" gnus-article-view-part-externally
1881     "E" gnus-article-encrypt-body
1882     "i" gnus-article-inline-part
1883     "|" gnus-article-pipe-part)
1884
1885   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1886     "p" gnus-summary-mark-as-processable
1887     "u" gnus-summary-unmark-as-processable
1888     "U" gnus-summary-unmark-all-processable
1889     "v" gnus-uu-mark-over
1890     "s" gnus-uu-mark-series
1891     "r" gnus-uu-mark-region
1892     "g" gnus-uu-unmark-region
1893     "R" gnus-uu-mark-by-regexp
1894     "G" gnus-uu-unmark-by-regexp
1895     "t" gnus-uu-mark-thread
1896     "T" gnus-uu-unmark-thread
1897     "a" gnus-uu-mark-all
1898     "b" gnus-uu-mark-buffer
1899     "S" gnus-uu-mark-sparse
1900     "k" gnus-summary-kill-process-mark
1901     "y" gnus-summary-yank-process-mark
1902     "w" gnus-summary-save-process-mark
1903     "i" gnus-uu-invert-processable)
1904
1905   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1906     ;;"x" gnus-uu-extract-any
1907     "m" gnus-summary-save-parts
1908     "u" gnus-uu-decode-uu
1909     "U" gnus-uu-decode-uu-and-save
1910     "s" gnus-uu-decode-unshar
1911     "S" gnus-uu-decode-unshar-and-save
1912     "o" gnus-uu-decode-save
1913     "O" gnus-uu-decode-save
1914     "b" gnus-uu-decode-binhex
1915     "B" gnus-uu-decode-binhex
1916     "p" gnus-uu-decode-postscript
1917     "P" gnus-uu-decode-postscript-and-save)
1918
1919   (gnus-define-keys
1920       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1921     "u" gnus-uu-decode-uu-view
1922     "U" gnus-uu-decode-uu-and-save-view
1923     "s" gnus-uu-decode-unshar-view
1924     "S" gnus-uu-decode-unshar-and-save-view
1925     "o" gnus-uu-decode-save-view
1926     "O" gnus-uu-decode-save-view
1927     "b" gnus-uu-decode-binhex-view
1928     "B" gnus-uu-decode-binhex-view
1929     "p" gnus-uu-decode-postscript-view
1930     "P" gnus-uu-decode-postscript-and-save-view))
1931
1932 (defvar gnus-article-post-menu nil)
1933
1934 (defconst gnus-summary-menu-maxlen 20)
1935
1936 (defun gnus-summary-menu-split (menu)
1937   ;; If we have lots of elements, divide them into groups of 20
1938   ;; and make a pane (or submenu) for each one.
1939   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1940       (let ((menu menu) sublists next
1941             (i 1))
1942         (while menu
1943           ;; Pull off the next gnus-summary-menu-maxlen elements
1944           ;; and make them the next element of sublist.
1945           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1946           (if next
1947               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1948                       nil))
1949           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1950                                              (aref (car (last menu)) 0)) menu)
1951                                sublists))
1952           (setq i (1+ i))
1953           (setq menu next))
1954         (nreverse sublists))
1955     ;; Few elements--put them all in one pane.
1956     menu))
1957
1958 (defun gnus-summary-make-menu-bar ()
1959   (gnus-turn-off-edit-menu 'summary)
1960
1961   (unless (boundp 'gnus-summary-misc-menu)
1962
1963     (easy-menu-define
1964       gnus-summary-kill-menu gnus-summary-mode-map ""
1965       (cons
1966        "Score"
1967        (nconc
1968         (list
1969          ["Customize" gnus-score-customize t])
1970         (gnus-make-score-map 'increase)
1971         (gnus-make-score-map 'lower)
1972         '(("Mark"
1973            ["Kill below" gnus-summary-kill-below t]
1974            ["Mark above" gnus-summary-mark-above t]
1975            ["Tick above" gnus-summary-tick-above t]
1976            ["Clear above" gnus-summary-clear-above t])
1977           ["Current score" gnus-summary-current-score t]
1978           ["Set score" gnus-summary-set-score t]
1979           ["Switch current score file..." gnus-score-change-score-file t]
1980           ["Set mark below..." gnus-score-set-mark-below t]
1981           ["Set expunge below..." gnus-score-set-expunge-below t]
1982           ["Edit current score file" gnus-score-edit-current-scores t]
1983           ["Edit score file" gnus-score-edit-file t]
1984           ["Trace score" gnus-score-find-trace t]
1985           ["Find words" gnus-score-find-favourite-words t]
1986           ["Rescore buffer" gnus-summary-rescore t]
1987           ["Increase score..." gnus-summary-increase-score t]
1988           ["Lower score..." gnus-summary-lower-score t]))))
1989
1990     ;; Define both the Article menu in the summary buffer and the
1991     ;; equivalent Commands menu in the article buffer here for
1992     ;; consistency.
1993     (let ((innards
1994            `(("Hide"
1995               ["All" gnus-article-hide t]
1996               ["Headers" gnus-article-hide-headers t]
1997               ["Signature" gnus-article-hide-signature t]
1998               ["Citation" gnus-article-hide-citation t]
1999               ["List identifiers" gnus-article-hide-list-identifiers t]
2000               ["PGP" gnus-article-hide-pgp t]
2001               ["Banner" gnus-article-strip-banner t]
2002               ["Boring headers" gnus-article-hide-boring-headers t])
2003              ("Highlight"
2004               ["All" gnus-article-highlight t]
2005               ["Headers" gnus-article-highlight-headers t]
2006               ["Signature" gnus-article-highlight-signature t]
2007               ["Citation" gnus-article-highlight-citation t])
2008              ("MIME"
2009               ["Words" gnus-article-decode-mime-words t]
2010               ["Charset" gnus-article-decode-charset t]
2011               ["QP" gnus-article-de-quoted-unreadable t]
2012               ["Base64" gnus-article-de-base64-unreadable t]
2013               ["View MIME buttons" gnus-summary-display-buttonized t]
2014               ["View all" gnus-mime-view-all-parts t]
2015               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2016               ["Encrypt body" gnus-article-encrypt-body t]
2017               ["Extract all parts" gnus-summary-save-parts t])
2018              ("Date"
2019               ["Local" gnus-article-date-local t]
2020               ["ISO8601" gnus-article-date-iso8601 t]
2021               ["UT" gnus-article-date-ut t]
2022               ["Original" gnus-article-date-original t]
2023               ["Lapsed" gnus-article-date-lapsed t]
2024               ["User-defined" gnus-article-date-user t])
2025              ("Display"
2026               ["Remove images" gnus-article-remove-images t]
2027               ["Toggle smiley" gnus-treat-smiley t]
2028               ["Show X-Face" gnus-article-display-x-face t]
2029               ["Show picons in From" gnus-treat-from-picon t]
2030               ["Show picons in mail headers" gnus-treat-mail-picon t]
2031               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2032               ("View as different encoding"
2033                ,@(gnus-summary-menu-split
2034                   (mapcar
2035                    (lambda (cs)
2036                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2037                      ;; forms for menu commands, we should provide intern'ed
2038                      ;; function symbols.
2039                      (let ((command (intern (format "\
2040 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2041                        (fset command
2042                              `(lambda ()
2043                                 (interactive)
2044                                 (let ((gnus-summary-show-article-charset-alist
2045                                        '((1 . ,cs))))
2046                                   (gnus-summary-show-article 1))))
2047                        `[,(symbol-name cs) ,command t]))
2048                    (sort (if (fboundp 'coding-system-list)
2049                              (coding-system-list)
2050                            (mapcar 'car mm-mime-mule-charset-alist))
2051                          'string<)))))
2052              ("Washing"
2053               ("Remove Blanks"
2054                ["Leading" gnus-article-strip-leading-blank-lines t]
2055                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2056                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2057                ["All of the above" gnus-article-strip-blank-lines t]
2058                ["All" gnus-article-strip-all-blank-lines t]
2059                ["Leading space" gnus-article-strip-leading-space t]
2060                ["Trailing space" gnus-article-strip-trailing-space t]
2061                ["Leading space in headers"
2062                 gnus-article-remove-leading-whitespace t])
2063               ["Overstrike" gnus-article-treat-overstrike t]
2064               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2065               ["Emphasis" gnus-article-emphasize t]
2066               ["Word wrap" gnus-article-fill-cited-article t]
2067               ["Fill long lines" gnus-article-fill-long-lines t]
2068               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2069               ["CR" gnus-article-remove-cr t]
2070               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2071               ["Base64" gnus-article-de-base64-unreadable t]
2072               ["Rot 13" gnus-summary-caesar-message
2073                ,@(if (featurep 'xemacs) '(t)
2074                    '(:help "\"Caesar rotate\" article by 13"))]
2075               ["Morse decode" gnus-summary-morse-message t]
2076               ["Unix pipe..." gnus-summary-pipe-message t]
2077               ["Add buttons" gnus-article-add-buttons t]
2078               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2079               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2080               ["Verbose header" gnus-summary-verbose-headers t]
2081               ["Toggle header" gnus-summary-toggle-header t]
2082               ["Unfold headers" gnus-article-treat-unfold-headers t]
2083               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2084               ["Html" gnus-article-wash-html t]
2085               ["URLs" gnus-article-unsplit-urls t]
2086               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2087               ["HZ" gnus-article-decode-HZ t]
2088               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2089               )
2090              ("Output"
2091               ["Save in default format" gnus-summary-save-article
2092                ,@(if (featurep 'xemacs) '(t)
2093                    '(:help "Save article using default method"))]
2094               ["Save in file" gnus-summary-save-article-file
2095                ,@(if (featurep 'xemacs) '(t)
2096                    '(:help "Save article in file"))]
2097               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2098               ["Save in MH folder" gnus-summary-save-article-folder t]
2099               ["Save in VM folder" gnus-summary-save-article-vm t]
2100               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2101               ["Save body in file" gnus-summary-save-article-body-file t]
2102               ["Pipe through a filter" gnus-summary-pipe-output t]
2103               ["Add to SOUP packet" gnus-soup-add-article t]
2104               ["Print with Muttprint" gnus-summary-muttprint t]
2105               ["Print" gnus-summary-print-article t])
2106              ("Backend"
2107               ["Respool article..." gnus-summary-respool-article t]
2108               ["Move article..." gnus-summary-move-article
2109                (gnus-check-backend-function
2110                 'request-move-article gnus-newsgroup-name)]
2111               ["Copy article..." gnus-summary-copy-article t]
2112               ["Crosspost article..." gnus-summary-crosspost-article
2113                (gnus-check-backend-function
2114                 'request-replace-article gnus-newsgroup-name)]
2115               ["Import file..." gnus-summary-import-article t]
2116               ["Create article..." gnus-summary-create-article t]
2117               ["Check if posted" gnus-summary-article-posted-p t]
2118               ["Edit article" gnus-summary-edit-article
2119                (not (gnus-group-read-only-p))]
2120               ["Delete article" gnus-summary-delete-article
2121                (gnus-check-backend-function
2122                 'request-expire-articles gnus-newsgroup-name)]
2123               ["Query respool" gnus-summary-respool-query t]
2124               ["Trace respool" gnus-summary-respool-trace t]
2125               ["Delete expirable articles" gnus-summary-expire-articles-now
2126                (gnus-check-backend-function
2127                 'request-expire-articles gnus-newsgroup-name)])
2128              ("Extract"
2129               ["Uudecode" gnus-uu-decode-uu
2130                ,@(if (featurep 'xemacs) '(t)
2131                    '(:help "Decode uuencoded article(s)"))]
2132               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2133               ["Unshar" gnus-uu-decode-unshar t]
2134               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2135               ["Save" gnus-uu-decode-save t]
2136               ["Binhex" gnus-uu-decode-binhex t]
2137               ["Postscript" gnus-uu-decode-postscript t]
2138               ["All MIME parts" gnus-summary-save-parts t])
2139              ("Cache"
2140               ["Enter article" gnus-cache-enter-article t]
2141               ["Remove article" gnus-cache-remove-article t])
2142              ["Translate" gnus-article-babel t]
2143              ["Select article buffer" gnus-summary-select-article-buffer t]
2144              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2145              ["Isearch article..." gnus-summary-isearch-article t]
2146              ["Beginning of the article" gnus-summary-beginning-of-article t]
2147              ["End of the article" gnus-summary-end-of-article t]
2148              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2149              ["Fetch referenced articles" gnus-summary-refer-references t]
2150              ["Fetch current thread" gnus-summary-refer-thread t]
2151              ["Fetch article with id..." gnus-summary-refer-article t]
2152              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2153              ["Redisplay" gnus-summary-show-article t]
2154              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2155       (easy-menu-define
2156         gnus-summary-article-menu gnus-summary-mode-map ""
2157         (cons "Article" innards))
2158
2159       (if (not (keymapp gnus-summary-article-menu))
2160           (easy-menu-define
2161             gnus-article-commands-menu gnus-article-mode-map ""
2162             (cons "Commands" innards))
2163         ;; in Emacs, don't share menu.
2164         (setq gnus-article-commands-menu
2165               (copy-keymap gnus-summary-article-menu))
2166         (define-key gnus-article-mode-map [menu-bar commands]
2167           (cons "Commands" gnus-article-commands-menu))))
2168
2169     (easy-menu-define
2170       gnus-summary-thread-menu gnus-summary-mode-map ""
2171       '("Threads"
2172         ["Toggle threading" gnus-summary-toggle-threads t]
2173         ["Hide threads" gnus-summary-hide-all-threads t]
2174         ["Show threads" gnus-summary-show-all-threads t]
2175         ["Hide thread" gnus-summary-hide-thread t]
2176         ["Show thread" gnus-summary-show-thread t]
2177         ["Go to next thread" gnus-summary-next-thread t]
2178         ["Go to previous thread" gnus-summary-prev-thread t]
2179         ["Go down thread" gnus-summary-down-thread t]
2180         ["Go up thread" gnus-summary-up-thread t]
2181         ["Top of thread" gnus-summary-top-thread t]
2182         ["Mark thread as read" gnus-summary-kill-thread t]
2183         ["Lower thread score" gnus-summary-lower-thread t]
2184         ["Raise thread score" gnus-summary-raise-thread t]
2185         ["Rethread current" gnus-summary-rethread-current t]))
2186
2187     (easy-menu-define
2188       gnus-summary-post-menu gnus-summary-mode-map ""
2189       `("Post"
2190         ["Send a message (mail or news)" gnus-summary-post-news
2191          ,@(if (featurep 'xemacs) '(t)
2192              '(:help "Post an article"))]
2193         ["Followup" gnus-summary-followup
2194          ,@(if (featurep 'xemacs) '(t)
2195              '(:help "Post followup to this article"))]
2196         ["Followup and yank" gnus-summary-followup-with-original
2197          ,@(if (featurep 'xemacs) '(t)
2198              '(:help "Post followup to this article, quoting its contents"))]
2199         ["Supersede article" gnus-summary-supersede-article t]
2200         ["Cancel article" gnus-summary-cancel-article
2201          ,@(if (featurep 'xemacs) '(t)
2202              '(:help "Cancel an article you posted"))]
2203         ["Reply" gnus-summary-reply t]
2204         ["Reply and yank" gnus-summary-reply-with-original t]
2205         ["Wide reply" gnus-summary-wide-reply t]
2206         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2207          ,@(if (featurep 'xemacs) '(t)
2208              '(:help "Mail a reply, quoting this article"))]
2209         ["Very wide reply" gnus-summary-very-wide-reply t]
2210         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2211          ,@(if (featurep 'xemacs) '(t)
2212              '(:help "Mail a very wide reply, quoting this article"))]
2213         ["Mail forward" gnus-summary-mail-forward t]
2214         ["Post forward" gnus-summary-post-forward t]
2215         ["Digest and mail" gnus-uu-digest-mail-forward t]
2216         ["Digest and post" gnus-uu-digest-post-forward t]
2217         ["Resend message" gnus-summary-resend-message t]
2218         ["Resend message edit" gnus-summary-resend-message-edit t]
2219         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2220         ["Send a mail" gnus-summary-mail-other-window t]
2221         ["Create a local message" gnus-summary-news-other-window t]
2222         ["Uuencode and post" gnus-uu-post-news
2223          ,@(if (featurep 'xemacs) '(t)
2224              '(:help "Post a uuencoded article"))]
2225         ["Followup via news" gnus-summary-followup-to-mail t]
2226         ["Followup via news and yank"
2227          gnus-summary-followup-to-mail-with-original t]
2228         ;;("Draft"
2229         ;;["Send" gnus-summary-send-draft t]
2230         ;;["Send bounced" gnus-resend-bounced-mail t])
2231         ))
2232
2233     (cond
2234      ((not (keymapp gnus-summary-post-menu))
2235       (setq gnus-article-post-menu gnus-summary-post-menu))
2236      ((not gnus-article-post-menu)
2237       ;; Don't share post menu.
2238       (setq gnus-article-post-menu
2239             (copy-keymap gnus-summary-post-menu))))
2240     (define-key gnus-article-mode-map [menu-bar post]
2241       (cons "Post" gnus-article-post-menu))
2242
2243     (easy-menu-define
2244       gnus-summary-misc-menu gnus-summary-mode-map ""
2245       `("Gnus"
2246         ("Mark Read"
2247          ["Mark as read" gnus-summary-mark-as-read-forward t]
2248          ["Mark same subject and select"
2249           gnus-summary-kill-same-subject-and-select t]
2250          ["Mark same subject" gnus-summary-kill-same-subject t]
2251          ["Catchup" gnus-summary-catchup
2252           ,@(if (featurep 'xemacs) '(t)
2253               '(:help "Mark unread articles in this group as read"))]
2254          ["Catchup all" gnus-summary-catchup-all t]
2255          ["Catchup to here" gnus-summary-catchup-to-here t]
2256          ["Catchup from here" gnus-summary-catchup-from-here t]
2257          ["Catchup region" gnus-summary-mark-region-as-read t]
2258          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2259         ("Mark Various"
2260          ["Tick" gnus-summary-tick-article-forward t]
2261          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2262          ["Remove marks" gnus-summary-clear-mark-forward t]
2263          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2264          ["Set bookmark" gnus-summary-set-bookmark t]
2265          ["Remove bookmark" gnus-summary-remove-bookmark t])
2266         ("Limit to"
2267          ["Marks..." gnus-summary-limit-to-marks t]
2268          ["Subject..." gnus-summary-limit-to-subject t]
2269          ["Author..." gnus-summary-limit-to-author t]
2270          ["Age..." gnus-summary-limit-to-age t]
2271          ["Extra..." gnus-summary-limit-to-extra t]
2272          ["Score..." gnus-summary-limit-to-score t]
2273          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2274          ["Unread" gnus-summary-limit-to-unread t]
2275          ["Unseen" gnus-summary-limit-to-unseen t]
2276          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2277          ["Articles" gnus-summary-limit-to-articles t]
2278          ["Pop limit" gnus-summary-pop-limit t]
2279          ["Show dormant" gnus-summary-limit-include-dormant t]
2280          ["Hide childless dormant"
2281           gnus-summary-limit-exclude-childless-dormant t]
2282          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2283          ["Hide marked" gnus-summary-limit-exclude-marks t]
2284          ["Show expunged" gnus-summary-limit-include-expunged t])
2285         ("Process Mark"
2286          ["Set mark" gnus-summary-mark-as-processable t]
2287          ["Remove mark" gnus-summary-unmark-as-processable t]
2288          ["Remove all marks" gnus-summary-unmark-all-processable t]
2289          ["Mark above" gnus-uu-mark-over t]
2290          ["Mark series" gnus-uu-mark-series t]
2291          ["Mark region" gnus-uu-mark-region t]
2292          ["Unmark region" gnus-uu-unmark-region t]
2293          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2294          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2295          ["Mark all" gnus-uu-mark-all t]
2296          ["Mark buffer" gnus-uu-mark-buffer t]
2297          ["Mark sparse" gnus-uu-mark-sparse t]
2298          ["Mark thread" gnus-uu-mark-thread t]
2299          ["Unmark thread" gnus-uu-unmark-thread t]
2300          ("Process Mark Sets"
2301           ["Kill" gnus-summary-kill-process-mark t]
2302           ["Yank" gnus-summary-yank-process-mark
2303            gnus-newsgroup-process-stack]
2304           ["Save" gnus-summary-save-process-mark t]))
2305         ("Scroll article"
2306          ["Page forward" gnus-summary-next-page
2307           ,@(if (featurep 'xemacs) '(t)
2308               '(:help "Show next page of article"))]
2309          ["Page backward" gnus-summary-prev-page
2310           ,@(if (featurep 'xemacs) '(t)
2311               '(:help "Show previous page of article"))]
2312          ["Line forward" gnus-summary-scroll-up t])
2313         ("Move"
2314          ["Next unread article" gnus-summary-next-unread-article t]
2315          ["Previous unread article" gnus-summary-prev-unread-article t]
2316          ["Next article" gnus-summary-next-article t]
2317          ["Previous article" gnus-summary-prev-article t]
2318          ["Next unread subject" gnus-summary-next-unread-subject t]
2319          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2320          ["Next article same subject" gnus-summary-next-same-subject t]
2321          ["Previous article same subject" gnus-summary-prev-same-subject t]
2322          ["First unread article" gnus-summary-first-unread-article t]
2323          ["Best unread article" gnus-summary-best-unread-article t]
2324          ["Go to subject number..." gnus-summary-goto-subject t]
2325          ["Go to article number..." gnus-summary-goto-article t]
2326          ["Go to the last article" gnus-summary-goto-last-article t]
2327          ["Pop article off history" gnus-summary-pop-article t])
2328         ("Sort"
2329          ["Sort by number" gnus-summary-sort-by-number t]
2330          ["Sort by author" gnus-summary-sort-by-author t]
2331          ["Sort by subject" gnus-summary-sort-by-subject t]
2332          ["Sort by date" gnus-summary-sort-by-date t]
2333          ["Sort by score" gnus-summary-sort-by-score t]
2334          ["Sort by lines" gnus-summary-sort-by-lines t]
2335          ["Sort by characters" gnus-summary-sort-by-chars t]
2336          ["Randomize" gnus-summary-sort-by-random t]
2337          ["Original sort" gnus-summary-sort-by-original t])
2338         ("Help"
2339          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2340          ["Describe group" gnus-summary-describe-group t]
2341          ["Fetch charter" gnus-group-fetch-charter
2342           ,@(if (featurep 'xemacs) nil
2343               '(:help "Display the charter of the current group"))]
2344          ["Fetch control message" gnus-group-fetch-control
2345           ,@(if (featurep 'xemacs) nil
2346               '(:help "Display the archived control message for the current group"))]
2347          ["Read manual" gnus-info-find-node t])
2348         ("Modes"
2349          ["Pick and read" gnus-pick-mode t]
2350          ["Binary" gnus-binary-mode t])
2351         ("Regeneration"
2352          ["Regenerate" gnus-summary-prepare t]
2353          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2354          ["Toggle threading" gnus-summary-toggle-threads t])
2355         ["See old articles" gnus-summary-insert-old-articles t]
2356         ["See new articles" gnus-summary-insert-new-articles t]
2357         ["Filter articles..." gnus-summary-execute-command t]
2358         ["Run command on subjects..." gnus-summary-universal-argument t]
2359         ["Search articles forward..." gnus-summary-search-article-forward t]
2360         ["Search articles backward..." gnus-summary-search-article-backward t]
2361         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2362         ["Expand window" gnus-summary-expand-window t]
2363         ["Expire expirable articles" gnus-summary-expire-articles
2364          (gnus-check-backend-function
2365           'request-expire-articles gnus-newsgroup-name)]
2366         ["Edit local kill file" gnus-summary-edit-local-kill t]
2367         ["Edit main kill file" gnus-summary-edit-global-kill t]
2368         ["Edit group parameters" gnus-summary-edit-parameters t]
2369         ["Customize group parameters" gnus-summary-customize-parameters t]
2370         ["Send a bug report" gnus-bug t]
2371         ("Exit"
2372          ["Catchup and exit" gnus-summary-catchup-and-exit
2373           ,@(if (featurep 'xemacs) '(t)
2374               '(:help "Mark unread articles in this group as read, then exit"))]
2375          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2376          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2377          ["Exit group" gnus-summary-exit
2378           ,@(if (featurep 'xemacs) '(t)
2379               '(:help "Exit current group, return to group selection mode"))]
2380          ["Exit group without updating" gnus-summary-exit-no-update t]
2381          ["Exit and goto next group" gnus-summary-next-group t]
2382          ["Exit and goto prev group" gnus-summary-prev-group t]
2383          ["Reselect group" gnus-summary-reselect-current-group t]
2384          ["Rescan group" gnus-summary-rescan-group t]
2385          ["Update dribble" gnus-summary-save-newsrc t])))
2386
2387     (gnus-run-hooks 'gnus-summary-menu-hook)))
2388
2389 (defvar gnus-summary-tool-bar-map nil)
2390
2391 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2392 (defun gnus-summary-make-tool-bar ()
2393   (if (and (fboundp 'tool-bar-add-item-from-menu)
2394            (default-value 'tool-bar-mode)
2395            (not gnus-summary-tool-bar-map))
2396       (setq gnus-summary-tool-bar-map
2397             (let ((tool-bar-map (make-sparse-keymap))
2398                   (load-path (mm-image-load-path)))
2399               (tool-bar-add-item-from-menu
2400                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2401               (tool-bar-add-item-from-menu
2402                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2403               (tool-bar-add-item-from-menu
2404                'gnus-summary-post-news "post" gnus-summary-mode-map)
2405               (tool-bar-add-item-from-menu
2406                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2407               (tool-bar-add-item-from-menu
2408                'gnus-summary-followup "followup" gnus-summary-mode-map)
2409               (tool-bar-add-item-from-menu
2410                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2411               (tool-bar-add-item-from-menu
2412                'gnus-summary-reply "reply" gnus-summary-mode-map)
2413               (tool-bar-add-item-from-menu
2414                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2415               (tool-bar-add-item-from-menu
2416                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2417               (tool-bar-add-item-from-menu
2418                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2419               (tool-bar-add-item-from-menu
2420                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2421               (tool-bar-add-item-from-menu
2422                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2423               (tool-bar-add-item-from-menu
2424                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2425               (tool-bar-add-item-from-menu
2426                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2427               (tool-bar-add-item-from-menu
2428                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2429               tool-bar-map)))
2430   (if gnus-summary-tool-bar-map
2431       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2432
2433 (defun gnus-score-set-default (var value)
2434   "A version of set that updates the GNU Emacs menu-bar."
2435   (set var value)
2436   ;; It is the message that forces the active status to be updated.
2437   (message ""))
2438
2439 (defun gnus-make-score-map (type)
2440   "Make a summary score map of type TYPE."
2441   (if t
2442       nil
2443     (let ((headers '(("author" "from" string)
2444                      ("subject" "subject" string)
2445                      ("article body" "body" string)
2446                      ("article head" "head" string)
2447                      ("xref" "xref" string)
2448                      ("extra header" "extra" string)
2449                      ("lines" "lines" number)
2450                      ("followups to author" "followup" string)))
2451           (types '((number ("less than" <)
2452                            ("greater than" >)
2453                            ("equal" =))
2454                    (string ("substring" s)
2455                            ("exact string" e)
2456                            ("fuzzy string" f)
2457                            ("regexp" r))))
2458           (perms '(("temporary" (current-time-string))
2459                    ("permanent" nil)
2460                    ("immediate" now)))
2461           header)
2462       (list
2463        (apply
2464         'nconc
2465         (list
2466          (if (eq type 'lower)
2467              "Lower score"
2468            "Increase score"))
2469         (let (outh)
2470           (while headers
2471             (setq header (car headers))
2472             (setq outh
2473                   (cons
2474                    (apply
2475                     'nconc
2476                     (list (car header))
2477                     (let ((ts (cdr (assoc (nth 2 header) types)))
2478                           outt)
2479                       (while ts
2480                         (setq outt
2481                               (cons
2482                                (apply
2483                                 'nconc
2484                                 (list (caar ts))
2485                                 (let ((ps perms)
2486                                       outp)
2487                                   (while ps
2488                                     (setq outp
2489                                           (cons
2490                                            (vector
2491                                             (caar ps)
2492                                             (list
2493                                              'gnus-summary-score-entry
2494                                              (nth 1 header)
2495                                              (if (or (string= (nth 1 header)
2496                                                               "head")
2497                                                      (string= (nth 1 header)
2498                                                               "body"))
2499                                                  ""
2500                                                (list 'gnus-summary-header
2501                                                      (nth 1 header)))
2502                                              (list 'quote (nth 1 (car ts)))
2503                                              (list 'gnus-score-delta-default
2504                                                    nil)
2505                                              (nth 1 (car ps))
2506                                              t)
2507                                             t)
2508                                            outp))
2509                                     (setq ps (cdr ps)))
2510                                   (list (nreverse outp))))
2511                                outt))
2512                         (setq ts (cdr ts)))
2513                       (list (nreverse outt))))
2514                    outh))
2515             (setq headers (cdr headers)))
2516           (list (nreverse outh))))))))
2517
2518 \f
2519
2520 (defun gnus-summary-mode (&optional group)
2521   "Major mode for reading articles.
2522
2523 All normal editing commands are switched off.
2524 \\<gnus-summary-mode-map>
2525 Each line in this buffer represents one article.  To read an
2526 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2527 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2528 respectively.
2529
2530 You can also post articles and send mail from this buffer.  To
2531 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2532 of an article, type `\\[gnus-summary-reply]'.
2533
2534 There are approx. one gazillion commands you can execute in this
2535 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2536
2537 The following commands are available:
2538
2539 \\{gnus-summary-mode-map}"
2540   (interactive)
2541   (kill-all-local-variables)
2542   (when (gnus-visual-p 'summary-menu 'menu)
2543     (gnus-summary-make-menu-bar)
2544     (gnus-summary-make-tool-bar))
2545   (gnus-summary-make-local-variables)
2546   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2547     (gnus-summary-make-local-variables))
2548   (gnus-make-thread-indent-array)
2549   (gnus-simplify-mode-line)
2550   (setq major-mode 'gnus-summary-mode)
2551   (setq mode-name "Summary")
2552   (make-local-variable 'minor-mode-alist)
2553   (use-local-map gnus-summary-mode-map)
2554   (buffer-disable-undo)
2555   (setq buffer-read-only t)             ;Disable modification
2556   (setq truncate-lines t)
2557   (setq selective-display t)
2558   (setq selective-display-ellipses t)   ;Display `...'
2559   (gnus-summary-set-display-table)
2560   (gnus-set-default-directory)
2561   (setq gnus-newsgroup-name group)
2562   (make-local-variable 'gnus-summary-line-format)
2563   (make-local-variable 'gnus-summary-line-format-spec)
2564   (make-local-variable 'gnus-summary-dummy-line-format)
2565   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2566   (make-local-variable 'gnus-summary-mark-positions)
2567   (make-local-hook 'pre-command-hook)
2568   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2569   (gnus-run-hooks 'gnus-summary-mode-hook)
2570   (turn-on-gnus-mailing-list-mode)
2571   (mm-enable-multibyte)
2572   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2573   (gnus-update-summary-mark-positions))
2574
2575 (defun gnus-summary-make-local-variables ()
2576   "Make all the local summary buffer variables."
2577   (let (global)
2578     (dolist (local gnus-summary-local-variables)
2579       (if (consp local)
2580           (progn
2581             (if (eq (cdr local) 'global)
2582                 ;; Copy the global value of the variable.
2583                 (setq global (symbol-value (car local)))
2584               ;; Use the value from the list.
2585               (setq global (eval (cdr local))))
2586             (set (make-local-variable (car local)) global))
2587         ;; Simple nil-valued local variable.
2588         (set (make-local-variable local) nil)))))
2589
2590 (defun gnus-summary-clear-local-variables ()
2591   (let ((locals gnus-summary-local-variables))
2592     (while locals
2593       (if (consp (car locals))
2594           (and (vectorp (caar locals))
2595                (set (caar locals) nil))
2596         (and (vectorp (car locals))
2597              (set (car locals) nil)))
2598       (setq locals (cdr locals)))))
2599
2600 ;; Summary data functions.
2601
2602 (defmacro gnus-data-number (data)
2603   `(car ,data))
2604
2605 (defmacro gnus-data-set-number (data number)
2606   `(setcar ,data ,number))
2607
2608 (defmacro gnus-data-mark (data)
2609   `(nth 1 ,data))
2610
2611 (defmacro gnus-data-set-mark (data mark)
2612   `(setcar (nthcdr 1 ,data) ,mark))
2613
2614 (defmacro gnus-data-pos (data)
2615   `(nth 2 ,data))
2616
2617 (defmacro gnus-data-set-pos (data pos)
2618   `(setcar (nthcdr 2 ,data) ,pos))
2619
2620 (defmacro gnus-data-header (data)
2621   `(nth 3 ,data))
2622
2623 (defmacro gnus-data-set-header (data header)
2624   `(setf (nth 3 ,data) ,header))
2625
2626 (defmacro gnus-data-level (data)
2627   `(nth 4 ,data))
2628
2629 (defmacro gnus-data-unread-p (data)
2630   `(= (nth 1 ,data) gnus-unread-mark))
2631
2632 (defmacro gnus-data-read-p (data)
2633   `(/= (nth 1 ,data) gnus-unread-mark))
2634
2635 (defmacro gnus-data-pseudo-p (data)
2636   `(consp (nth 3 ,data)))
2637
2638 (defmacro gnus-data-find (number)
2639   `(assq ,number gnus-newsgroup-data))
2640
2641 (defmacro gnus-data-find-list (number &optional data)
2642   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2643      (memq (assq ,number bdata)
2644            bdata)))
2645
2646 (defmacro gnus-data-make (number mark pos header level)
2647   `(list ,number ,mark ,pos ,header ,level))
2648
2649 (defun gnus-data-enter (after-article number mark pos header level offset)
2650   (let ((data (gnus-data-find-list after-article)))
2651     (unless data
2652       (error "No such article: %d" after-article))
2653     (setcdr data (cons (gnus-data-make number mark pos header level)
2654                        (cdr data)))
2655     (setq gnus-newsgroup-data-reverse nil)
2656     (gnus-data-update-list (cddr data) offset)))
2657
2658 (defun gnus-data-enter-list (after-article list &optional offset)
2659   (when list
2660     (let ((data (and after-article (gnus-data-find-list after-article)))
2661           (ilist list))
2662       (if (not (or data
2663                    after-article))
2664           (let ((odata gnus-newsgroup-data))
2665             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2666             (when offset
2667               (gnus-data-update-list odata offset)))
2668       ;; Find the last element in the list to be spliced into the main
2669         ;; list.
2670         (while (cdr list)
2671           (setq list (cdr list)))
2672         (if (not data)
2673             (progn
2674               (setcdr list gnus-newsgroup-data)
2675               (setq gnus-newsgroup-data ilist)
2676               (when offset
2677                 (gnus-data-update-list (cdr list) offset)))
2678           (setcdr list (cdr data))
2679           (setcdr data ilist)
2680           (when offset
2681             (gnus-data-update-list (cdr list) offset))))
2682       (setq gnus-newsgroup-data-reverse nil))))
2683
2684 (defun gnus-data-remove (article &optional offset)
2685   (let ((data gnus-newsgroup-data))
2686     (if (= (gnus-data-number (car data)) article)
2687         (progn
2688           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2689                 gnus-newsgroup-data-reverse nil)
2690           (when offset
2691             (gnus-data-update-list gnus-newsgroup-data offset)))
2692       (while (cdr data)
2693         (when (= (gnus-data-number (cadr data)) article)
2694           (setcdr data (cddr data))
2695           (when offset
2696             (gnus-data-update-list (cdr data) offset))
2697           (setq data nil
2698                 gnus-newsgroup-data-reverse nil))
2699         (setq data (cdr data))))))
2700
2701 (defmacro gnus-data-list (backward)
2702   `(if ,backward
2703        (or gnus-newsgroup-data-reverse
2704            (setq gnus-newsgroup-data-reverse
2705                  (reverse gnus-newsgroup-data)))
2706      gnus-newsgroup-data))
2707
2708 (defun gnus-data-update-list (data offset)
2709   "Add OFFSET to the POS of all data entries in DATA."
2710   (setq gnus-newsgroup-data-reverse nil)
2711   (while data
2712     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2713     (setq data (cdr data))))
2714
2715 (defun gnus-summary-article-pseudo-p (article)
2716   "Say whether this article is a pseudo article or not."
2717   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2718
2719 (defmacro gnus-summary-article-sparse-p (article)
2720   "Say whether this article is a sparse article or not."
2721   `(memq ,article gnus-newsgroup-sparse))
2722
2723 (defmacro gnus-summary-article-ancient-p (article)
2724   "Say whether this article is a sparse article or not."
2725   `(memq ,article gnus-newsgroup-ancient))
2726
2727 (defun gnus-article-parent-p (number)
2728   "Say whether this article is a parent or not."
2729   (let ((data (gnus-data-find-list number)))
2730     (and (cdr data)              ; There has to be an article after...
2731          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2732             (gnus-data-level (nth 1 data))))))
2733
2734 (defun gnus-article-children (number)
2735   "Return a list of all children to NUMBER."
2736   (let* ((data (gnus-data-find-list number))
2737          (level (gnus-data-level (car data)))
2738          children)
2739     (setq data (cdr data))
2740     (while (and data
2741                 (= (gnus-data-level (car data)) (1+ level)))
2742       (push (gnus-data-number (car data)) children)
2743       (setq data (cdr data)))
2744     children))
2745
2746 (defmacro gnus-summary-skip-intangible ()
2747   "If the current article is intangible, then jump to a different article."
2748   '(let ((to (get-text-property (point) 'gnus-intangible)))
2749      (and to (gnus-summary-goto-subject to))))
2750
2751 (defmacro gnus-summary-article-intangible-p ()
2752   "Say whether this article is intangible or not."
2753   '(get-text-property (point) 'gnus-intangible))
2754
2755 (defun gnus-article-read-p (article)
2756   "Say whether ARTICLE is read or not."
2757   (not (or (memq article gnus-newsgroup-marked)
2758            (memq article gnus-newsgroup-spam-marked)
2759            (memq article gnus-newsgroup-unreads)
2760            (memq article gnus-newsgroup-unselected)
2761            (memq article gnus-newsgroup-dormant))))
2762
2763 ;; Some summary mode macros.
2764
2765 (defmacro gnus-summary-article-number ()
2766   "The article number of the article on the current line.
2767 If there isn's an article number here, then we return the current
2768 article number."
2769   '(progn
2770      (gnus-summary-skip-intangible)
2771      (or (get-text-property (point) 'gnus-number)
2772          (gnus-summary-last-subject))))
2773
2774 (defmacro gnus-summary-article-header (&optional number)
2775   "Return the header of article NUMBER."
2776   `(gnus-data-header (gnus-data-find
2777                       ,(or number '(gnus-summary-article-number)))))
2778
2779 (defmacro gnus-summary-thread-level (&optional number)
2780   "Return the level of thread that starts with article NUMBER."
2781   `(if (and (eq gnus-summary-make-false-root 'dummy)
2782             (get-text-property (point) 'gnus-intangible))
2783        0
2784      (gnus-data-level (gnus-data-find
2785                        ,(or number '(gnus-summary-article-number))))))
2786
2787 (defmacro gnus-summary-article-mark (&optional number)
2788   "Return the mark of article NUMBER."
2789   `(gnus-data-mark (gnus-data-find
2790                     ,(or number '(gnus-summary-article-number)))))
2791
2792 (defmacro gnus-summary-article-pos (&optional number)
2793   "Return the position of the line of article NUMBER."
2794   `(gnus-data-pos (gnus-data-find
2795                    ,(or number '(gnus-summary-article-number)))))
2796
2797 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2798 (defmacro gnus-summary-article-subject (&optional number)
2799   "Return current subject string or nil if nothing."
2800   `(let ((headers
2801           ,(if number
2802                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2803              '(gnus-data-header (assq (gnus-summary-article-number)
2804                                       gnus-newsgroup-data)))))
2805      (and headers
2806           (vectorp headers)
2807           (mail-header-subject headers))))
2808
2809 (defmacro gnus-summary-article-score (&optional number)
2810   "Return current article score."
2811   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2812                   gnus-newsgroup-scored))
2813        gnus-summary-default-score 0))
2814
2815 (defun gnus-summary-article-children (&optional number)
2816   "Return a list of article numbers that are children of article NUMBER."
2817   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2818          (level (gnus-data-level (car data)))
2819          l children)
2820     (while (and (setq data (cdr data))
2821                 (> (setq l (gnus-data-level (car data))) level))
2822       (and (= (1+ level) l)
2823            (push (gnus-data-number (car data))
2824                  children)))
2825     (nreverse children)))
2826
2827 (defun gnus-summary-article-parent (&optional number)
2828   "Return the article number of the parent of article NUMBER."
2829   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2830                                     (gnus-data-list t)))
2831          (level (gnus-data-level (car data))))
2832     (if (zerop level)
2833         ()                              ; This is a root.
2834       ;; We search until we find an article with a level less than
2835       ;; this one.  That function has to be the parent.
2836       (while (and (setq data (cdr data))
2837                   (not (< (gnus-data-level (car data)) level))))
2838       (and data (gnus-data-number (car data))))))
2839
2840 (defun gnus-unread-mark-p (mark)
2841   "Say whether MARK is the unread mark."
2842   (= mark gnus-unread-mark))
2843
2844 (defun gnus-read-mark-p (mark)
2845   "Say whether MARK is one of the marks that mark as read.
2846 This is all marks except unread, ticked, dormant, and expirable."
2847   (not (or (= mark gnus-unread-mark)
2848            (= mark gnus-ticked-mark)
2849            (= mark gnus-dormant-mark)
2850            (= mark gnus-expirable-mark))))
2851
2852 (defmacro gnus-article-mark (number)
2853   "Return the MARK of article NUMBER.
2854 This macro should only be used when computing the mark the \"first\"
2855 time; i.e., when generating the summary lines.  After that,
2856 `gnus-summary-article-mark' should be used to examine the
2857 marks of articles."
2858   `(cond
2859     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2860 ;;;;    ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2861     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2862     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2863     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2864     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2865     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2866     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2867     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2868            gnus-ancient-mark))))
2869
2870 ;; Saving hidden threads.
2871
2872 (defmacro gnus-save-hidden-threads (&rest forms)
2873   "Save hidden threads, eval FORMS, and restore the hidden threads."
2874   (let ((config (make-symbol "config")))
2875     `(let ((,config (gnus-hidden-threads-configuration)))
2876        (unwind-protect
2877            (save-excursion
2878              ,@forms)
2879          (gnus-restore-hidden-threads-configuration ,config)))))
2880 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2881 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2882
2883 (defun gnus-data-compute-positions ()
2884   "Compute the positions of all articles."
2885   (setq gnus-newsgroup-data-reverse nil)
2886   (let ((data gnus-newsgroup-data))
2887     (save-excursion
2888       (gnus-save-hidden-threads
2889         (gnus-summary-show-all-threads)
2890         (goto-char (point-min))
2891         (while data
2892           (while (get-text-property (point) 'gnus-intangible)
2893             (forward-line 1))
2894           (gnus-data-set-pos (car data) (+ (point) 3))
2895           (setq data (cdr data))
2896           (forward-line 1))))))
2897
2898 (defun gnus-hidden-threads-configuration ()
2899   "Return the current hidden threads configuration."
2900   (save-excursion
2901     (let (config)
2902       (goto-char (point-min))
2903       (while (search-forward "\r" nil t)
2904         (push (1- (point)) config))
2905       config)))
2906
2907 (defun gnus-restore-hidden-threads-configuration (config)
2908   "Restore hidden threads configuration from CONFIG."
2909   (save-excursion
2910     (let (point buffer-read-only)
2911       (while (setq point (pop config))
2912         (when (and (< point (point-max))
2913                    (goto-char point)
2914                    (eq (char-after) ?\n))
2915           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2916
2917 ;; Various summary mode internalish functions.
2918
2919 (defun gnus-mouse-pick-article (e)
2920   (interactive "e")
2921   (mouse-set-point e)
2922   (gnus-summary-next-page nil t))
2923
2924 (defun gnus-summary-set-display-table ()
2925   "Change the display table.
2926 Odd characters have a tendency to mess
2927 up nicely formatted displays - we make all possible glyphs
2928 display only a single character."
2929
2930   ;; We start from the standard display table, if any.
2931   (let ((table (or (copy-sequence standard-display-table)
2932                    (make-display-table)))
2933         (i 32))
2934     ;; Nix out all the control chars...
2935     (while (>= (setq i (1- i)) 0)
2936       (aset table i [??]))
2937    ;; ... but not newline and cr, of course.  (cr is necessary for the
2938     ;; selective display).
2939     (aset table ?\n nil)
2940     (aset table ?\r nil)
2941     ;; We keep TAB as well.
2942     (aset table ?\t nil)
2943     ;; We nix out any glyphs over 126 that are not set already.
2944     (let ((i 256))
2945       (while (>= (setq i (1- i)) 127)
2946         ;; Only modify if the entry is nil.
2947         (unless (aref table i)
2948           (aset table i [??]))))
2949     (setq buffer-display-table table)))
2950
2951 (defun gnus-summary-set-article-display-arrow (pos)
2952   "Update the overlay arrow to point to line at position POS."
2953   (when (and gnus-summary-display-arrow
2954              (boundp 'overlay-arrow-position)
2955              (boundp 'overlay-arrow-string))
2956     (save-excursion
2957       (goto-char pos)
2958       (beginning-of-line)
2959       (unless overlay-arrow-position
2960         (setq overlay-arrow-position (make-marker)))
2961       (setq overlay-arrow-string "=>"
2962             overlay-arrow-position (set-marker overlay-arrow-position
2963                                                (point)
2964                                                (current-buffer))))))
2965
2966 (defun gnus-summary-buffer-name (group)
2967   "Return the summary buffer name of GROUP."
2968   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2969
2970 (defun gnus-summary-setup-buffer (group)
2971   "Initialize summary buffer."
2972   (let ((buffer (gnus-summary-buffer-name group))
2973         (dead-name (concat "*Dead Summary "
2974                            (gnus-group-decoded-name group) "*")))
2975     ;; If a dead summary buffer exists, we kill it.
2976     (when (gnus-buffer-live-p dead-name)
2977       (gnus-kill-buffer dead-name))
2978     (if (get-buffer buffer)
2979         (progn
2980           (set-buffer buffer)
2981           (setq gnus-summary-buffer (current-buffer))
2982           (not gnus-newsgroup-prepared))
2983       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2984       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2985       (gnus-summary-mode group)
2986       (when gnus-carpal
2987         (gnus-carpal-setup-buffer 'summary))
2988       (unless gnus-single-article-buffer
2989         (make-local-variable 'gnus-article-buffer)
2990         (make-local-variable 'gnus-article-current)
2991         (make-local-variable 'gnus-original-article-buffer))
2992       (setq gnus-newsgroup-name group)
2993       ;; Set any local variables in the group parameters.
2994       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2995       t)))
2996
2997 (defun gnus-set-global-variables ()
2998   "Set the global equivalents of the buffer-local variables.
2999 They are set to the latest values they had.  These reflect the summary
3000 buffer that was in action when the last article was fetched."
3001   (when (eq major-mode 'gnus-summary-mode)
3002     (setq gnus-summary-buffer (current-buffer))
3003     (let ((name gnus-newsgroup-name)
3004           (marked gnus-newsgroup-marked)
3005           (spam gnus-newsgroup-spam-marked)
3006           (unread gnus-newsgroup-unreads)
3007           (headers gnus-current-headers)
3008           (data gnus-newsgroup-data)
3009           (summary gnus-summary-buffer)
3010           (article-buffer gnus-article-buffer)
3011           (original gnus-original-article-buffer)
3012           (gac gnus-article-current)
3013           (reffed gnus-reffed-article-number)
3014           (score-file gnus-current-score-file)
3015           (default-charset gnus-newsgroup-charset)
3016           vlist)
3017       (let ((locals gnus-newsgroup-variables))
3018         (while locals
3019           (if (consp (car locals))
3020               (push (eval (caar locals)) vlist)
3021             (push (eval (car locals)) vlist))
3022           (setq locals (cdr locals)))
3023         (setq vlist (nreverse vlist)))
3024       (save-excursion
3025         (set-buffer gnus-group-buffer)
3026         (setq gnus-newsgroup-name name
3027               gnus-newsgroup-marked marked
3028               gnus-newsgroup-spam-marked spam
3029               gnus-newsgroup-unreads unread
3030               gnus-current-headers headers
3031               gnus-newsgroup-data data
3032               gnus-article-current gac
3033               gnus-summary-buffer summary
3034               gnus-article-buffer article-buffer
3035               gnus-original-article-buffer original
3036               gnus-reffed-article-number reffed
3037               gnus-current-score-file score-file
3038               gnus-newsgroup-charset default-charset)
3039         (let ((locals gnus-newsgroup-variables))
3040           (while locals
3041             (if (consp (car locals))
3042                 (set (caar locals) (pop vlist))
3043               (set (car locals) (pop vlist)))
3044             (setq locals (cdr locals))))
3045         ;; The article buffer also has local variables.
3046         (when (gnus-buffer-live-p gnus-article-buffer)
3047           (set-buffer gnus-article-buffer)
3048           (setq gnus-summary-buffer summary))))))
3049
3050 (defun gnus-summary-article-unread-p (article)
3051   "Say whether ARTICLE is unread or not."
3052   (memq article gnus-newsgroup-unreads))
3053
3054 (defun gnus-summary-first-article-p (&optional article)
3055   "Return whether ARTICLE is the first article in the buffer."
3056   (if (not (setq article (or article (gnus-summary-article-number))))
3057       nil
3058     (eq article (caar gnus-newsgroup-data))))
3059
3060 (defun gnus-summary-last-article-p (&optional article)
3061   "Return whether ARTICLE is the last article in the buffer."
3062   (if (not (setq article (or article (gnus-summary-article-number))))
3063       ;; All non-existent numbers are the last article.  :-)
3064       t
3065     (not (cdr (gnus-data-find-list article)))))
3066
3067 (defun gnus-make-thread-indent-array ()
3068   (let ((n 200))
3069     (unless (and gnus-thread-indent-array
3070                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3071       (setq gnus-thread-indent-array (make-vector 201 "")
3072             gnus-thread-indent-array-level gnus-thread-indent-level)
3073       (while (>= n 0)
3074         (aset gnus-thread-indent-array n
3075               (make-string (* n gnus-thread-indent-level) ? ))
3076         (setq n (1- n))))))
3077
3078 (defun gnus-update-summary-mark-positions ()
3079   "Compute where the summary marks are to go."
3080   (save-excursion
3081     (when (gnus-buffer-exists-p gnus-summary-buffer)
3082       (set-buffer gnus-summary-buffer))
3083     (let ((gnus-replied-mark 129)
3084           (gnus-score-below-mark 130)
3085           (gnus-score-over-mark 130)
3086           (gnus-download-mark 131)
3087           (spec gnus-summary-line-format-spec)
3088           gnus-visual pos)
3089       (save-excursion
3090         (gnus-set-work-buffer)
3091         (let ((gnus-summary-line-format-spec spec)
3092               (gnus-newsgroup-downloadable '((0 . t))))
3093           (gnus-summary-insert-line
3094            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
3095            0 nil 128 t nil "" nil 1)
3096           (goto-char (point-min))
3097           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3098                                              (- (point) (point-min) 1)))))
3099           (goto-char (point-min))
3100           (push (cons 'replied (and (search-forward "\201" nil t)
3101                                     (- (point) (point-min) 1)))
3102                 pos)
3103           (goto-char (point-min))
3104           (push (cons 'score (and (search-forward "\202" nil t)
3105                                   (- (point) (point-min) 1)))
3106                 pos)
3107           (goto-char (point-min))
3108           (push (cons 'download
3109                       (and (search-forward "\203" nil t)
3110                            (- (point) (point-min) 1)))
3111                 pos)))
3112       (setq gnus-summary-mark-positions pos))))
3113
3114 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3115   "Insert a dummy root in the summary buffer."
3116   (beginning-of-line)
3117   (gnus-add-text-properties
3118    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3119    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3120
3121 (defun gnus-summary-extract-address-component (from)
3122   (or (car (funcall gnus-extract-address-components from))
3123       from))
3124
3125 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3126   (let ((mail-parse-charset gnus-newsgroup-charset)
3127         ; Is it really necessary to do this next part for each summary line?
3128         ; Luckily, doesn't seem to slow things down much.
3129         (mail-parse-ignored-charsets
3130          (save-excursion (set-buffer gnus-summary-buffer)
3131                          gnus-newsgroup-ignored-charsets)))
3132     (or
3133      (and gnus-ignored-from-addresses
3134           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3135           (let ((extra-headers (mail-header-extra header))
3136                 to
3137                 newsgroups)
3138             (cond
3139              ((setq to (cdr (assq 'To extra-headers)))
3140               (concat "-> "
3141                       (inline
3142                         (gnus-summary-extract-address-component
3143                          (funcall gnus-decode-encoded-word-function to)))))
3144              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3145               (concat "=> " newsgroups)))))
3146      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3147
3148 (defun gnus-summary-insert-line (gnus-tmp-header
3149                                  gnus-tmp-level gnus-tmp-current
3150                                  gnus-tmp-unread gnus-tmp-replied
3151                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3152                                  &optional gnus-tmp-dummy gnus-tmp-score
3153                                  gnus-tmp-process)
3154   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3155          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3156          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3157          (gnus-tmp-score-char
3158           (if (or (null gnus-summary-default-score)
3159                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3160                       gnus-summary-zcore-fuzz))
3161               ?                         ;Whitespace
3162             (if (< gnus-tmp-score gnus-summary-default-score)
3163                 gnus-score-below-mark gnus-score-over-mark)))
3164          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3165          (gnus-tmp-replied
3166           (cond (gnus-tmp-process gnus-process-mark)
3167                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3168                  gnus-cached-mark)
3169                 (gnus-tmp-replied gnus-replied-mark)
3170                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3171                  gnus-forwarded-mark)
3172                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3173                  gnus-saved-mark)
3174                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3175                  gnus-recent-mark)
3176                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3177                  gnus-unseen-mark)
3178                 (t gnus-no-mark)))
3179          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3180          (gnus-tmp-name
3181           (cond
3182            ((string-match "<[^>]+> *$" gnus-tmp-from)
3183             (let ((beg (match-beginning 0)))
3184               (or (and (string-match "^\".+\"" gnus-tmp-from)
3185                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3186                   (substring gnus-tmp-from 0 beg))))
3187            ((string-match "(.+)" gnus-tmp-from)
3188             (substring gnus-tmp-from
3189                        (1+ (match-beginning 0)) (1- (match-end 0))))
3190            (t gnus-tmp-from)))
3191          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3192          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3193          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3194          (buffer-read-only nil))
3195     (when (string= gnus-tmp-name "")
3196       (setq gnus-tmp-name gnus-tmp-from))
3197     (unless (numberp gnus-tmp-lines)
3198       (setq gnus-tmp-lines -1))
3199     (if (= gnus-tmp-lines -1)
3200         (setq gnus-tmp-lines "?")
3201       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3202     (gnus-put-text-property
3203      (point)
3204      (progn (eval gnus-summary-line-format-spec) (point))
3205      'gnus-number gnus-tmp-number)
3206     (when (gnus-visual-p 'summary-highlight 'highlight)
3207       (forward-line -1)
3208       (gnus-run-hooks 'gnus-summary-update-hook)
3209       (forward-line 1))))
3210
3211 (defun gnus-summary-update-line (&optional dont-update)
3212   "Update summary line after change."
3213   (when (and gnus-summary-default-score
3214              (not gnus-summary-inhibit-highlight))
3215     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3216            (article (gnus-summary-article-number))
3217            (score (gnus-summary-article-score article)))
3218       (unless dont-update
3219         (if (and gnus-summary-mark-below
3220                  (< (gnus-summary-article-score)
3221                     gnus-summary-mark-below))
3222             ;; This article has a low score, so we mark it as read.
3223             (when (memq article gnus-newsgroup-unreads)
3224               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3225           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3226             ;; This article was previously marked as read on account
3227             ;; of a low score, but now it has risen, so we mark it as
3228             ;; unread.
3229             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3230         (gnus-summary-update-mark
3231          (if (or (null gnus-summary-default-score)
3232                  (<= (abs (- score gnus-summary-default-score))
3233                      gnus-summary-zcore-fuzz))
3234              ?                          ;Whitespace
3235            (if (< score gnus-summary-default-score)
3236                gnus-score-below-mark gnus-score-over-mark))
3237          'score))
3238       ;; Do visual highlighting.
3239       (when (gnus-visual-p 'summary-highlight 'highlight)
3240         (gnus-run-hooks 'gnus-summary-update-hook)))))
3241
3242 (defvar gnus-tmp-new-adopts nil)
3243
3244 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3245   "Return the number of articles in THREAD.
3246 This may be 0 in some cases -- if none of the articles in
3247 the thread are to be displayed."
3248   (let* ((number
3249          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3250           (cond
3251            ((not (listp thread))
3252             1)
3253            ((and (consp thread) (cdr thread))
3254             (apply
3255              '+ 1 (mapcar
3256                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3257            ((null thread)
3258             1)
3259            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3260             1)
3261            (t 0))))
3262     (when (and level (zerop level) gnus-tmp-new-adopts)
3263       (incf number
3264             (apply '+ (mapcar
3265                        'gnus-summary-number-of-articles-in-thread
3266                        gnus-tmp-new-adopts))))
3267     (if char
3268         (if (> number 1) gnus-not-empty-thread-mark
3269           gnus-empty-thread-mark)
3270       number)))
3271
3272 (defsubst gnus-summary-line-message-size (head)
3273   "Return pretty-printed version of message size.
3274 This function is intended to be used in
3275 `gnus-summary-line-format-alist', which see."
3276   (let ((c (or (mail-header-chars head) -1)))
3277     (cond ((< c 0) "n/a")               ; chars not available
3278           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3279           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3280           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3281           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3282
3283
3284 (defun gnus-summary-set-local-parameters (group)
3285   "Go through the local params of GROUP and set all variable specs in that list."
3286   (let ((params (gnus-group-find-parameter group))
3287         (vars '(quit-config))           ; Ignore quit-config.
3288         elem)
3289     (while params
3290       (setq elem (car params)
3291             params (cdr params))
3292       (and (consp elem)                 ; Has to be a cons.
3293            (consp (cdr elem))           ; The cdr has to be a list.
3294            (symbolp (car elem))         ; Has to be a symbol in there.
3295            (not (memq (car elem) vars))
3296            (ignore-errors               ; So we set it.
3297              (push (car elem) vars)
3298              (make-local-variable (car elem))
3299              (set (car elem) (eval (nth 1 elem))))))))
3300
3301 (defun gnus-summary-read-group (group &optional show-all no-article
3302                                       kill-buffer no-display backward
3303                                       select-articles)
3304   "Start reading news in newsgroup GROUP.
3305 If SHOW-ALL is non-nil, already read articles are also listed.
3306 If NO-ARTICLE is non-nil, no article is selected initially.
3307 If NO-DISPLAY, don't generate a summary buffer."
3308   (let (result)
3309     (while (and group
3310                 (null (setq result
3311                             (let ((gnus-auto-select-next nil))
3312                               (or (gnus-summary-read-group-1
3313                                    group show-all no-article
3314                                    kill-buffer no-display
3315                                    select-articles)
3316                                   (setq show-all nil
3317                                         select-articles nil)))))
3318                 (eq gnus-auto-select-next 'quietly))
3319       (set-buffer gnus-group-buffer)
3320       ;; The entry function called above goes to the next
3321       ;; group automatically, so we go two groups back
3322       ;; if we are searching for the previous group.
3323       (when backward
3324         (gnus-group-prev-unread-group 2))
3325       (if (not (equal group (gnus-group-group-name)))
3326           (setq group (gnus-group-group-name))
3327         (setq group nil)))
3328     result))
3329
3330 (defun gnus-summary-read-group-1 (group show-all no-article
3331                                         kill-buffer no-display
3332                                         &optional select-articles)
3333   ;; Killed foreign groups can't be entered.
3334   ;;  (when (and (not (gnus-group-native-p group))
3335   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3336   ;;    (error "Dead non-native groups can't be entered"))
3337   (gnus-message 5 "Retrieving newsgroup: %s..."
3338                 (gnus-group-decoded-name group))
3339   (let* ((new-group (gnus-summary-setup-buffer group))
3340          (quit-config (gnus-group-quit-config group))
3341          (did-select (and new-group (gnus-select-newsgroup
3342                                      group show-all select-articles))))
3343     (cond
3344      ;; This summary buffer exists already, so we just select it.
3345      ((not new-group)
3346       (gnus-set-global-variables)
3347       (when kill-buffer
3348         (gnus-kill-or-deaden-summary kill-buffer))
3349       (gnus-configure-windows 'summary 'force)
3350       (gnus-set-mode-line 'summary)
3351       (gnus-summary-position-point)
3352       (message "")
3353       t)
3354      ;; We couldn't select this group.
3355      ((null did-select)
3356       (when (and (eq major-mode 'gnus-summary-mode)
3357                  (not (equal (current-buffer) kill-buffer)))
3358         (kill-buffer (current-buffer))
3359         (if (not quit-config)
3360             (progn
3361               ;; Update the info -- marks might need to be removed,
3362               ;; for instance.
3363               (gnus-summary-update-info)
3364               (set-buffer gnus-group-buffer)
3365               (gnus-group-jump-to-group group)
3366               (gnus-group-next-unread-group 1))
3367           (gnus-handle-ephemeral-exit quit-config)))
3368       (let ((grpinfo (gnus-get-info group)))
3369         (if (null (gnus-info-read grpinfo))
3370             (gnus-message 3 "Group %s contains no messages"
3371                           (gnus-group-decoded-name group))
3372           (gnus-message 3 "Can't select group")))
3373       nil)
3374      ;; The user did a `C-g' while prompting for number of articles,
3375      ;; so we exit this group.
3376      ((eq did-select 'quit)
3377       (and (eq major-mode 'gnus-summary-mode)
3378            (not (equal (current-buffer) kill-buffer))
3379            (kill-buffer (current-buffer)))
3380       (when kill-buffer
3381         (gnus-kill-or-deaden-summary kill-buffer))
3382       (if (not quit-config)
3383           (progn
3384             (set-buffer gnus-group-buffer)
3385             (gnus-group-jump-to-group group)
3386             (gnus-group-next-unread-group 1)
3387             (gnus-configure-windows 'group 'force))
3388         (gnus-handle-ephemeral-exit quit-config))
3389       ;; Finally signal the quit.
3390       (signal 'quit nil))
3391      ;; The group was successfully selected.
3392      (t
3393       (gnus-set-global-variables)
3394       ;; Save the active value in effect when the group was entered.
3395       (setq gnus-newsgroup-active
3396             (gnus-copy-sequence
3397              (gnus-active gnus-newsgroup-name)))
3398       ;; You can change the summary buffer in some way with this hook.
3399       (gnus-run-hooks 'gnus-select-group-hook)
3400       (gnus-update-format-specifications
3401        nil 'summary 'summary-mode 'summary-dummy)
3402       (gnus-update-summary-mark-positions)
3403       ;; Do score processing.
3404       (when gnus-use-scoring
3405         (gnus-possibly-score-headers))
3406       ;; Check whether to fill in the gaps in the threads.
3407       (when gnus-build-sparse-threads
3408         (gnus-build-sparse-threads))
3409       ;; Find the initial limit.
3410       (if gnus-show-threads
3411           (if show-all
3412               (let ((gnus-newsgroup-dormant nil))
3413                 (gnus-summary-initial-limit show-all))
3414             (gnus-summary-initial-limit show-all))
3415         ;; When untreaded, all articles are always shown.
3416         (setq gnus-newsgroup-limit
3417               (mapcar
3418                (lambda (header) (mail-header-number header))
3419                gnus-newsgroup-headers)))
3420       ;; Generate the summary buffer.
3421       (unless no-display
3422         (gnus-summary-prepare))
3423       (when gnus-use-trees
3424         (gnus-tree-open group)
3425         (setq gnus-summary-highlight-line-function
3426               'gnus-tree-highlight-article))
3427       ;; If the summary buffer is empty, but there are some low-scored
3428       ;; articles or some excluded dormants, we include these in the
3429       ;; buffer.
3430       (when (and (zerop (buffer-size))
3431                  (not no-display))
3432         (cond (gnus-newsgroup-dormant
3433                (gnus-summary-limit-include-dormant))
3434               ((and gnus-newsgroup-scored show-all)
3435                (gnus-summary-limit-include-expunged t))))
3436       ;; Function `gnus-apply-kill-file' must be called in this hook.
3437       (gnus-run-hooks 'gnus-apply-kill-hook)
3438       (if (and (zerop (buffer-size))
3439                (not no-display))
3440           (progn
3441             ;; This newsgroup is empty.
3442             (gnus-summary-catchup-and-exit nil t)
3443             (gnus-message 6 "No unread news")
3444             (when kill-buffer
3445               (gnus-kill-or-deaden-summary kill-buffer))
3446             ;; Return nil from this function.
3447             nil)
3448         ;; Hide conversation thread subtrees.  We cannot do this in
3449         ;; gnus-summary-prepare-hook since kill processing may not
3450         ;; work with hidden articles.
3451         (gnus-summary-maybe-hide-threads)
3452         (when kill-buffer
3453           (gnus-kill-or-deaden-summary kill-buffer))
3454         (gnus-summary-auto-select-subject)
3455         ;; Show first unread article if requested.
3456         (if (and (not no-article)
3457                  (not no-display)
3458                  gnus-newsgroup-unreads
3459                  gnus-auto-select-first)
3460             (progn
3461               (gnus-configure-windows 'summary)
3462               (let ((art (gnus-summary-article-number)))
3463                 (unless (or (memq art gnus-newsgroup-undownloaded)
3464                             (memq art gnus-newsgroup-downloadable))
3465                   (gnus-summary-goto-article art))))
3466           ;; Don't select any articles.
3467           (gnus-summary-position-point)
3468           (gnus-configure-windows 'summary 'force)
3469           (gnus-set-mode-line 'summary))
3470         (when (get-buffer-window gnus-group-buffer t)
3471           ;; Gotta use windows, because recenter does weird stuff if
3472           ;; the current buffer ain't the displayed window.
3473           (let ((owin (selected-window)))
3474             (select-window (get-buffer-window gnus-group-buffer t))
3475             (when (gnus-group-goto-group group)
3476               (recenter))
3477             (select-window owin)))
3478         ;; Mark this buffer as "prepared".
3479         (setq gnus-newsgroup-prepared t)
3480         (gnus-run-hooks 'gnus-summary-prepared-hook)
3481         t)))))
3482
3483 (defun gnus-summary-auto-select-subject ()
3484   "Select the subject line on initial group entry."
3485   (goto-char (point-min))
3486   (cond
3487    ((eq gnus-auto-select-subject 'best)
3488     (gnus-summary-best-unread-subject))
3489    ((eq gnus-auto-select-subject 'unread)
3490     (gnus-summary-first-unread-subject))
3491    ((eq gnus-auto-select-subject 'unseen)
3492     (gnus-summary-first-unseen-subject))
3493    ((eq gnus-auto-select-subject 'unseen-or-unread)
3494     (gnus-summary-first-unseen-or-unread-subject))
3495    ((eq gnus-auto-select-subject 'first)
3496     ;; Do nothing.
3497     )
3498    ((gnus-functionp gnus-auto-select-subject)
3499     (funcall gnus-auto-select-subject))))
3500
3501 (defun gnus-summary-prepare ()
3502   "Generate the summary buffer."
3503   (interactive)
3504   (let ((buffer-read-only nil))
3505     (erase-buffer)
3506     (setq gnus-newsgroup-data nil
3507           gnus-newsgroup-data-reverse nil)
3508     (gnus-run-hooks 'gnus-summary-generate-hook)
3509     ;; Generate the buffer, either with threads or without.
3510     (when gnus-newsgroup-headers
3511       (gnus-summary-prepare-threads
3512        (if gnus-show-threads
3513            (gnus-sort-gathered-threads
3514             (funcall gnus-summary-thread-gathering-function
3515                      (gnus-sort-threads
3516                       (gnus-cut-threads (gnus-make-threads)))))
3517          ;; Unthreaded display.
3518          (gnus-sort-articles gnus-newsgroup-headers))))
3519     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3520     ;; Call hooks for modifying summary buffer.
3521     (goto-char (point-min))
3522     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3523
3524 (defsubst gnus-general-simplify-subject (subject)
3525   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3526   (setq subject
3527         (cond
3528          ;; Truncate the subject.
3529          (gnus-simplify-subject-functions
3530           (gnus-map-function gnus-simplify-subject-functions subject))
3531          ((numberp gnus-summary-gather-subject-limit)
3532           (setq subject (gnus-simplify-subject-re subject))
3533           (if (> (length subject) gnus-summary-gather-subject-limit)
3534               (substring subject 0 gnus-summary-gather-subject-limit)
3535             subject))
3536          ;; Fuzzily simplify it.
3537          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3538           (gnus-simplify-subject-fuzzy subject))
3539          ;; Just remove the leading "Re:".
3540          (t
3541           (gnus-simplify-subject-re subject))))
3542
3543   (if (and gnus-summary-gather-exclude-subject
3544            (string-match gnus-summary-gather-exclude-subject subject))
3545       nil                         ; This article shouldn't be gathered
3546     subject))
3547
3548 (defun gnus-summary-simplify-subject-query ()
3549   "Query where the respool algorithm would put this article."
3550   (interactive)
3551   (gnus-summary-select-article)
3552   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3553
3554 (defun gnus-gather-threads-by-subject (threads)
3555   "Gather threads by looking at Subject headers."
3556   (if (not gnus-summary-make-false-root)
3557       threads
3558     (let ((hashtb (gnus-make-hashtable 1024))
3559           (prev threads)
3560           (result threads)
3561           subject hthread whole-subject)
3562       (while threads
3563         (setq subject (gnus-general-simplify-subject
3564                        (setq whole-subject (mail-header-subject
3565                                             (caar threads)))))
3566         (when subject
3567           (if (setq hthread (gnus-gethash subject hashtb))
3568               (progn
3569                 ;; We enter a dummy root into the thread, if we
3570                 ;; haven't done that already.
3571                 (unless (stringp (caar hthread))
3572                   (setcar hthread (list whole-subject (car hthread))))
3573                 ;; We add this new gathered thread to this gathered
3574                 ;; thread.
3575                 (setcdr (car hthread)
3576                         (nconc (cdar hthread) (list (car threads))))
3577                 ;; Remove it from the list of threads.
3578                 (setcdr prev (cdr threads))
3579                 (setq threads prev))
3580             ;; Enter this thread into the hash table.
3581             (gnus-sethash subject threads hashtb)))
3582         (setq prev threads)
3583         (setq threads (cdr threads)))
3584       result)))
3585
3586 (defun gnus-gather-threads-by-references (threads)
3587   "Gather threads by looking at References headers."
3588   (let ((idhashtb (gnus-make-hashtable 1024))
3589         (thhashtb (gnus-make-hashtable 1024))
3590         (prev threads)
3591         (result threads)
3592         ids references id gthread gid entered ref)
3593     (while threads
3594       (when (setq references (mail-header-references (caar threads)))
3595         (setq id (mail-header-id (caar threads))
3596               ids (inline (gnus-split-references references))
3597               entered nil)
3598         (while (setq ref (pop ids))
3599           (setq ids (delete ref ids))
3600           (if (not (setq gid (gnus-gethash ref idhashtb)))
3601               (progn
3602                 (gnus-sethash ref id idhashtb)
3603                 (gnus-sethash id threads thhashtb))
3604             (setq gthread (gnus-gethash gid thhashtb))
3605             (unless entered
3606               ;; We enter a dummy root into the thread, if we
3607               ;; haven't done that already.
3608               (unless (stringp (caar gthread))
3609                 (setcar gthread (list (mail-header-subject (caar gthread))
3610                                       (car gthread))))
3611               ;; We add this new gathered thread to this gathered
3612               ;; thread.
3613               (setcdr (car gthread)
3614                       (nconc (cdar gthread) (list (car threads)))))
3615             ;; Add it into the thread hash table.
3616             (gnus-sethash id gthread thhashtb)
3617             (setq entered t)
3618             ;; Remove it from the list of threads.
3619             (setcdr prev (cdr threads))
3620             (setq threads prev))))
3621       (setq prev threads)
3622       (setq threads (cdr threads)))
3623     result))
3624
3625 (defun gnus-sort-gathered-threads (threads)
3626   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3627   (let ((result threads))
3628     (while threads
3629       (when (stringp (caar threads))
3630         (setcdr (car threads)
3631                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3632       (setq threads (cdr threads)))
3633     result))
3634
3635 (defun gnus-thread-loop-p (root thread)
3636   "Say whether ROOT is in THREAD."
3637   (let ((stack (list thread))
3638         (infloop 0)
3639         th)
3640     (while (setq thread (pop stack))
3641       (setq th (cdr thread))
3642       (while (and th
3643                   (not (eq (caar th) root)))
3644         (pop th))
3645       (if th
3646           ;; We have found a loop.
3647           (let (ref-dep)
3648             (setcdr thread (delq (car th) (cdr thread)))
3649             (if (boundp (setq ref-dep (intern "none"
3650                                               gnus-newsgroup-dependencies)))
3651                 (setcdr (symbol-value ref-dep)
3652                         (nconc (cdr (symbol-value ref-dep))
3653                                (list (car th))))
3654               (set ref-dep (list nil (car th))))
3655             (setq infloop 1
3656                   stack nil))
3657         ;; Push all the subthreads onto the stack.
3658         (push (cdr thread) stack)))
3659     infloop))
3660
3661 (defun gnus-make-threads ()
3662   "Go through the dependency hashtb and find the roots.  Return all threads."
3663   (let (threads)
3664     (while (catch 'infloop
3665              (mapatoms
3666               (lambda (refs)
3667                 ;; Deal with self-referencing References loops.
3668                 (when (and (car (symbol-value refs))
3669                            (not (zerop
3670                                  (apply
3671                                   '+
3672                                   (mapcar
3673                                    (lambda (thread)
3674                                      (gnus-thread-loop-p
3675                                       (car (symbol-value refs)) thread))
3676                                    (cdr (symbol-value refs)))))))
3677                   (setq threads nil)
3678                   (throw 'infloop t))
3679                 (unless (car (symbol-value refs))
3680                   ;; These threads do not refer back to any other
3681                   ;; articles, so they're roots.
3682                   (setq threads (append (cdr (symbol-value refs)) threads))))
3683               gnus-newsgroup-dependencies)))
3684     threads))
3685
3686 ;; Build the thread tree.
3687 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3688   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3689
3690 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3691 if it was already present.
3692
3693 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3694 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3695 Message-IDs will be renamed to a unique Message-ID before being
3696 entered.
3697
3698 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3699   (let* ((id (mail-header-id header))
3700          (id-dep (and id (intern id dependencies)))
3701          parent-id ref ref-dep ref-header replaced)
3702     ;; Enter this `header' in the `dependencies' table.
3703     (cond
3704      ((not id-dep)
3705       (setq header nil))
3706      ;; The first two cases do the normal part: enter a new `header'
3707      ;; in the `dependencies' table.
3708      ((not (boundp id-dep))
3709       (set id-dep (list header)))
3710      ((null (car (symbol-value id-dep)))
3711       (setcar (symbol-value id-dep) header))
3712
3713      ;; From here the `header' was already present in the
3714      ;; `dependencies' table.
3715      (force-new
3716       ;; Overrides an existing entry;
3717       ;; just set the header part of the entry.
3718       (setcar (symbol-value id-dep) header)
3719       (setq replaced t))
3720
3721      ;; Renames the existing `header' to a unique Message-ID.
3722      ((not gnus-summary-ignore-duplicates)
3723       ;; An article with this Message-ID has already been seen.
3724       ;; We rename the Message-ID.
3725       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3726            (list header))
3727       (mail-header-set-id header id))
3728
3729      ;; The last case ignores an existing entry, except it adds any
3730      ;; additional Xrefs (in case the two articles came from different
3731      ;; servers.
3732      ;; Also sets `header' to `nil' meaning that the `dependencies'
3733      ;; table was *not* modified.
3734      (t
3735       (mail-header-set-xref
3736        (car (symbol-value id-dep))
3737        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3738                    "")
3739                (or (mail-header-xref header) "")))
3740       (setq header nil)))
3741
3742     (when (and header (not replaced))
3743       ;; First check that we are not creating a References loop.
3744       (setq parent-id (gnus-parent-id (mail-header-references header)))
3745       (setq ref parent-id)
3746       (while (and ref
3747                   (setq ref-dep (intern-soft ref dependencies))
3748                   (boundp ref-dep)
3749                   (setq ref-header (car (symbol-value ref-dep))))
3750         (if (string= id ref)
3751             ;; Yuk!  This is a reference loop.  Make the article be a
3752             ;; root article.
3753             (progn
3754               (mail-header-set-references (car (symbol-value id-dep)) "none")
3755               (setq ref nil)
3756               (setq parent-id nil))
3757           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3758       (setq ref-dep (intern (or parent-id "none") dependencies))
3759       (if (boundp ref-dep)
3760           (setcdr (symbol-value ref-dep)
3761                   (nconc (cdr (symbol-value ref-dep))
3762                          (list (symbol-value id-dep))))
3763         (set ref-dep (list nil (symbol-value id-dep)))))
3764     header))
3765
3766 (defun gnus-extract-message-id-from-in-reply-to (string)
3767   (if (string-match "<[^>]+>" string)
3768       (substring string (match-beginning 0) (match-end 0))
3769     nil))
3770
3771 (defun gnus-build-sparse-threads ()
3772   (let ((headers gnus-newsgroup-headers)
3773         (mail-parse-charset gnus-newsgroup-charset)
3774         (gnus-summary-ignore-duplicates t)
3775         header references generation relations
3776         subject child end new-child date)
3777     ;; First we create an alist of generations/relations, where
3778     ;; generations is how much we trust the relation, and the relation
3779     ;; is parent/child.
3780     (gnus-message 7 "Making sparse threads...")
3781     (save-excursion
3782       (nnheader-set-temp-buffer " *gnus sparse threads*")
3783       (while (setq header (pop headers))
3784         (when (and (setq references (mail-header-references header))
3785                    (not (string= references "")))
3786           (insert references)
3787           (setq child (mail-header-id header)
3788                 subject (mail-header-subject header)
3789                 date (mail-header-date header)
3790                 generation 0)
3791           (while (search-backward ">" nil t)
3792             (setq end (1+ (point)))
3793             (when (search-backward "<" nil t)
3794               (setq new-child (buffer-substring (point) end))
3795               (push (list (incf generation)
3796                           child (setq child new-child)
3797                           subject date)
3798                     relations)))
3799           (when child
3800             (push (list (1+ generation) child nil subject) relations))
3801           (erase-buffer)))
3802       (kill-buffer (current-buffer)))
3803     ;; Sort over trustworthiness.
3804     (mapcar
3805      (lambda (relation)
3806        (when (gnus-dependencies-add-header
3807               (make-full-mail-header
3808                gnus-reffed-article-number
3809                (nth 3 relation) "" (or (nth 4 relation) "")
3810                (nth 1 relation)
3811                (or (nth 2 relation) "") 0 0 "")
3812               gnus-newsgroup-dependencies nil)
3813          (push gnus-reffed-article-number gnus-newsgroup-limit)
3814          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3815          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3816                gnus-newsgroup-reads)
3817          (decf gnus-reffed-article-number)))
3818      (sort relations 'car-less-than-car))
3819     (gnus-message 7 "Making sparse threads...done")))
3820
3821 (defun gnus-build-old-threads ()
3822   ;; Look at all the articles that refer back to old articles, and
3823   ;; fetch the headers for the articles that aren't there.  This will
3824   ;; build complete threads - if the roots haven't been expired by the
3825   ;; server, that is.
3826   (let ((mail-parse-charset gnus-newsgroup-charset)
3827         id heads)
3828     (mapatoms
3829      (lambda (refs)
3830        (when (not (car (symbol-value refs)))
3831          (setq heads (cdr (symbol-value refs)))
3832          (while heads
3833            (if (memq (mail-header-number (caar heads))
3834                      gnus-newsgroup-dormant)
3835                (setq heads (cdr heads))
3836              (setq id (symbol-name refs))
3837              (while (and (setq id (gnus-build-get-header id))
3838                          (not (car (gnus-id-to-thread id)))))
3839              (setq heads nil)))))
3840      gnus-newsgroup-dependencies)))
3841
3842 ;; This function has to be called with point after the article number
3843 ;; on the beginning of the line.
3844 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3845   (let ((eol (gnus-point-at-eol))
3846         (buffer (current-buffer))
3847         header references in-reply-to)
3848
3849     ;; overview: [num subject from date id refs chars lines misc]
3850     (unwind-protect
3851         (let (x)
3852           (narrow-to-region (point) eol)
3853           (unless (eobp)
3854             (forward-char))
3855
3856           (setq header
3857                 (make-full-mail-header
3858                  number                 ; number
3859                  (condition-case ()     ; subject
3860                      (funcall gnus-decode-encoded-word-function
3861                               (setq x (nnheader-nov-field)))
3862                    (error x))
3863                  (condition-case ()     ; from
3864                      (funcall gnus-decode-encoded-word-function
3865                               (setq x (nnheader-nov-field)))
3866                    (error x))
3867                  (nnheader-nov-field)   ; date
3868                  (nnheader-nov-read-message-id) ; id
3869                  (setq references (nnheader-nov-field)) ; refs
3870                  (nnheader-nov-read-integer) ; chars
3871                  (nnheader-nov-read-integer) ; lines
3872                  (unless (eobp)
3873                    (if (looking-at "Xref: ")
3874                        (goto-char (match-end 0)))
3875                    (nnheader-nov-field)) ; Xref
3876                  (nnheader-nov-parse-extra)))) ; extra
3877
3878       (widen))
3879
3880     (when (and (string= references "")
3881                (setq in-reply-to (mail-header-extra header))
3882                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3883       (mail-header-set-references
3884        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3885
3886     (when gnus-alter-header-function
3887       (funcall gnus-alter-header-function header))
3888     (gnus-dependencies-add-header header dependencies force-new)))
3889
3890 (defun gnus-build-get-header (id)
3891   "Look through the buffer of NOV lines and find the header to ID.
3892 Enter this line into the dependencies hash table, and return
3893 the id of the parent article (if any)."
3894   (let ((deps gnus-newsgroup-dependencies)
3895         found header)
3896     (prog1
3897         (save-excursion
3898           (set-buffer nntp-server-buffer)
3899           (let ((case-fold-search nil))
3900             (goto-char (point-min))
3901             (while (and (not found)
3902                         (search-forward id nil t))
3903               (beginning-of-line)
3904               (setq found (looking-at
3905                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3906                                    (regexp-quote id))))
3907               (or found (beginning-of-line 2)))
3908             (when found
3909               (beginning-of-line)
3910               (and
3911                (setq header (gnus-nov-parse-line
3912                              (read (current-buffer)) deps))
3913                (gnus-parent-id (mail-header-references header))))))
3914       (when header
3915         (let ((number (mail-header-number header)))
3916           (push number gnus-newsgroup-limit)
3917           (push header gnus-newsgroup-headers)
3918           (if (memq number gnus-newsgroup-unselected)
3919               (progn
3920                 (setq gnus-newsgroup-unreads
3921                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3922                                                number))
3923                 (setq gnus-newsgroup-unselected
3924                       (delq number gnus-newsgroup-unselected)))
3925             (push number gnus-newsgroup-ancient)))))))
3926
3927 (defun gnus-build-all-threads ()
3928   "Read all the headers."
3929   (let ((gnus-summary-ignore-duplicates t)
3930         (mail-parse-charset gnus-newsgroup-charset)
3931         (dependencies gnus-newsgroup-dependencies)
3932         header article)
3933     (save-excursion
3934       (set-buffer nntp-server-buffer)
3935       (let ((case-fold-search nil))
3936         (goto-char (point-min))
3937         (while (not (eobp))
3938           (ignore-errors
3939             (setq article (read (current-buffer))
3940                   header (gnus-nov-parse-line article dependencies)))
3941           (when header
3942             (save-excursion
3943               (set-buffer gnus-summary-buffer)
3944               (push header gnus-newsgroup-headers)
3945               (if (memq (setq article (mail-header-number header))
3946                         gnus-newsgroup-unselected)
3947                   (progn
3948                     (setq gnus-newsgroup-unreads
3949                           (gnus-add-to-sorted-list
3950                            gnus-newsgroup-unreads article))
3951                     (setq gnus-newsgroup-unselected
3952                           (delq article gnus-newsgroup-unselected)))
3953                 (push article gnus-newsgroup-ancient)))
3954             (forward-line 1)))))))
3955
3956 (defun gnus-summary-update-article-line (article header)
3957   "Update the line for ARTICLE using HEADERS."
3958   (let* ((id (mail-header-id header))
3959          (thread (gnus-id-to-thread id)))
3960     (unless thread
3961       (error "Article in no thread"))
3962     ;; Update the thread.
3963     (setcar thread header)
3964     (gnus-summary-goto-subject article)
3965     (let* ((datal (gnus-data-find-list article))
3966            (data (car datal))
3967            (length (when (cdr datal)
3968                      (- (gnus-data-pos data)
3969                         (gnus-data-pos (cadr datal)))))
3970            (buffer-read-only nil)
3971            (level (gnus-summary-thread-level)))
3972       (gnus-delete-line)
3973       (gnus-summary-insert-line
3974        header level nil (gnus-article-mark article)
3975        (memq article gnus-newsgroup-replied)
3976        (memq article gnus-newsgroup-expirable)
3977        ;; Only insert the Subject string when it's different
3978        ;; from the previous Subject string.
3979        (if (and
3980             gnus-show-threads
3981             (gnus-subject-equal
3982              (condition-case ()
3983                  (mail-header-subject
3984                   (gnus-data-header
3985                    (cadr
3986                     (gnus-data-find-list
3987                      article
3988                      (gnus-data-list t)))))
3989                ;; Error on the side of excessive subjects.
3990                (error ""))
3991              (mail-header-subject header)))
3992            ""
3993          (mail-header-subject header))
3994        nil (cdr (assq article gnus-newsgroup-scored))
3995        (memq article gnus-newsgroup-processable))
3996       (when length
3997         (gnus-data-update-list
3998          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3999
4000 (defun gnus-summary-update-article (article &optional iheader)
4001   "Update ARTICLE in the summary buffer."
4002   (set-buffer gnus-summary-buffer)
4003   (let* ((header (gnus-summary-article-header article))
4004          (id (mail-header-id header))
4005          (data (gnus-data-find article))
4006          (thread (gnus-id-to-thread id))
4007          (references (mail-header-references header))
4008          (parent
4009           (gnus-id-to-thread
4010            (or (gnus-parent-id
4011                 (when (and references
4012                            (not (equal "" references)))
4013                   references))
4014                "none")))
4015          (buffer-read-only nil)
4016          (old (car thread)))
4017     (when thread
4018       (unless iheader
4019         (setcar thread nil)
4020         (when parent
4021           (delq thread parent)))
4022       (if (gnus-summary-insert-subject id header)
4023        ;; Set the (possibly) new article number in the data structure.
4024           (gnus-data-set-number data (gnus-id-to-article id))
4025         (setcar thread old)
4026         nil))))
4027
4028 (defun gnus-rebuild-thread (id &optional line)
4029   "Rebuild the thread containing ID.
4030 If LINE, insert the rebuilt thread starting on line LINE."
4031   (let ((buffer-read-only nil)
4032         old-pos current thread data)
4033     (if (not gnus-show-threads)
4034         (setq thread (list (car (gnus-id-to-thread id))))
4035       ;; Get the thread this article is part of.
4036       (setq thread (gnus-remove-thread id)))
4037     (setq old-pos (gnus-point-at-bol))
4038     (setq current (save-excursion
4039                     (and (re-search-backward "[\r\n]" nil t)
4040                          (gnus-summary-article-number))))
4041     ;; If this is a gathered thread, we have to go some re-gathering.
4042     (when (stringp (car thread))
4043       (let ((subject (car thread))
4044             roots thr)
4045         (setq thread (cdr thread))
4046         (while thread
4047           (unless (memq (setq thr (gnus-id-to-thread
4048                                    (gnus-root-id
4049                                     (mail-header-id (caar thread)))))
4050                         roots)
4051             (push thr roots))
4052           (setq thread (cdr thread)))
4053         ;; We now have all (unique) roots.
4054         (if (= (length roots) 1)
4055             ;; All the loose roots are now one solid root.
4056             (setq thread (car roots))
4057           (setq thread (cons subject (gnus-sort-threads roots))))))
4058     (let (threads)
4059       ;; We then insert this thread into the summary buffer.
4060       (when line
4061         (goto-char (point-min))
4062         (forward-line (1- line)))
4063       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4064         (if gnus-show-threads
4065             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4066           (gnus-summary-prepare-unthreaded thread))
4067         (setq data (nreverse gnus-newsgroup-data))
4068         (setq threads gnus-newsgroup-threads))
4069       ;; We splice the new data into the data structure.
4070       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4071       ;;!!! then we want to insert at the beginning of the buffer.
4072       ;;!!! That happens to be true with Gnus now, but that may
4073       ;;!!! change in the future.  Perhaps.
4074       (gnus-data-enter-list
4075        (if line nil current) data (- (point) old-pos))
4076       (setq gnus-newsgroup-threads
4077             (nconc threads gnus-newsgroup-threads))
4078       (gnus-data-compute-positions))))
4079
4080 (defun gnus-number-to-header (number)
4081   "Return the header for article NUMBER."
4082   (let ((headers gnus-newsgroup-headers))
4083     (while (and headers
4084                 (not (= number (mail-header-number (car headers)))))
4085       (pop headers))
4086     (when headers
4087       (car headers))))
4088
4089 (defun gnus-parent-headers (in-headers &optional generation)
4090   "Return the headers of the GENERATIONeth parent of HEADERS."
4091   (unless generation
4092     (setq generation 1))
4093   (let ((parent t)
4094         (headers in-headers)
4095         references)
4096     (while (and parent
4097                 (not (zerop generation))
4098                 (setq references (mail-header-references headers)))
4099       (setq headers (if (and references
4100                              (setq parent (gnus-parent-id references)))
4101                         (car (gnus-id-to-thread parent))
4102                       nil))
4103       (decf generation))
4104     (and (not (eq headers in-headers))
4105          headers)))
4106
4107 (defun gnus-id-to-thread (id)
4108   "Return the (sub-)thread where ID appears."
4109   (gnus-gethash id gnus-newsgroup-dependencies))
4110
4111 (defun gnus-id-to-article (id)
4112   "Return the article number of ID."
4113   (let ((thread (gnus-id-to-thread id)))
4114     (when (and thread
4115                (car thread))
4116       (mail-header-number (car thread)))))
4117
4118 (defun gnus-id-to-header (id)
4119   "Return the article headers of ID."
4120   (car (gnus-id-to-thread id)))
4121
4122 (defun gnus-article-displayed-root-p (article)
4123   "Say whether ARTICLE is a root(ish) article."
4124   (let ((level (gnus-summary-thread-level article))
4125         (refs (mail-header-references  (gnus-summary-article-header article)))
4126         particle)
4127     (cond
4128      ((null level) nil)
4129      ((zerop level) t)
4130      ((null refs) t)
4131      ((null (gnus-parent-id refs)) t)
4132      ((and (= 1 level)
4133            (null (setq particle (gnus-id-to-article
4134                                  (gnus-parent-id refs))))
4135            (null (gnus-summary-thread-level particle)))))))
4136
4137 (defun gnus-root-id (id)
4138   "Return the id of the root of the thread where ID appears."
4139   (let (last-id prev)
4140     (while (and id (setq prev (car (gnus-id-to-thread id))))
4141       (setq last-id id
4142             id (gnus-parent-id (mail-header-references prev))))
4143     last-id))
4144
4145 (defun gnus-articles-in-thread (thread)
4146   "Return the list of articles in THREAD."
4147   (cons (mail-header-number (car thread))
4148         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4149
4150 (defun gnus-remove-thread (id &optional dont-remove)
4151   "Remove the thread that has ID in it."
4152   (let (headers thread last-id)
4153     ;; First go up in this thread until we find the root.
4154     (setq last-id (gnus-root-id id)
4155           headers (message-flatten-list (gnus-id-to-thread last-id)))
4156     ;; We have now found the real root of this thread.  It might have
4157     ;; been gathered into some loose thread, so we have to search
4158     ;; through the threads to find the thread we wanted.
4159     (let ((threads gnus-newsgroup-threads)
4160           sub)
4161       (while threads
4162         (setq sub (car threads))
4163         (if (stringp (car sub))
4164             ;; This is a gathered thread, so we look at the roots
4165             ;; below it to find whether this article is in this
4166             ;; gathered root.
4167             (progn
4168               (setq sub (cdr sub))
4169               (while sub
4170                 (when (member (caar sub) headers)
4171                   (setq thread (car threads)
4172                         threads nil
4173                         sub nil))
4174                 (setq sub (cdr sub))))
4175           ;; It's an ordinary thread, so we check it.
4176           (when (eq (car sub) (car headers))
4177             (setq thread sub
4178                   threads nil)))
4179         (setq threads (cdr threads)))
4180       ;; If this article is in no thread, then it's a root.
4181       (if thread
4182           (unless dont-remove
4183             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4184         (setq thread (gnus-id-to-thread last-id)))
4185       (when thread
4186         (prog1
4187             thread                      ; We return this thread.
4188           (unless dont-remove
4189             (if (stringp (car thread))
4190                 (progn
4191                   ;; If we use dummy roots, then we have to remove the
4192                   ;; dummy root as well.
4193                   (when (eq gnus-summary-make-false-root 'dummy)
4194                     ;; We go to the dummy root by going to
4195                     ;; the first sub-"thread", and then one line up.
4196                     (gnus-summary-goto-article
4197                      (mail-header-number (caadr thread)))
4198                     (forward-line -1)
4199                     (gnus-delete-line)
4200                     (gnus-data-compute-positions))
4201                   (setq thread (cdr thread))
4202                   (while thread
4203                     (gnus-remove-thread-1 (car thread))
4204                     (setq thread (cdr thread))))
4205               (gnus-remove-thread-1 thread))))))))
4206
4207 (defun gnus-remove-thread-1 (thread)
4208   "Remove the thread THREAD recursively."
4209   (let ((number (mail-header-number (pop thread)))
4210         d)
4211     (setq thread (reverse thread))
4212     (while thread
4213       (gnus-remove-thread-1 (pop thread)))
4214     (when (setq d (gnus-data-find number))
4215       (goto-char (gnus-data-pos d))
4216       (gnus-summary-show-thread)
4217       (gnus-data-remove
4218        number
4219        (- (gnus-point-at-bol)
4220           (prog1
4221               (1+ (gnus-point-at-eol))
4222             (gnus-delete-line)))))))
4223
4224 (defun gnus-sort-threads-1 (threads func)
4225   (sort (mapcar (lambda (thread)
4226                   (cons (car thread)
4227                         (and (cdr thread)
4228                              (gnus-sort-threads-1 (cdr thread) func))))
4229                 threads) func))
4230
4231 (defun gnus-sort-threads (threads)
4232   "Sort THREADS."
4233   (if (not gnus-thread-sort-functions)
4234       threads
4235     (gnus-message 8 "Sorting threads...")
4236     (prog1
4237         (gnus-sort-threads-1
4238          threads
4239          (gnus-make-sort-function gnus-thread-sort-functions))
4240       (gnus-message 8 "Sorting threads...done"))))
4241
4242 (defun gnus-sort-articles (articles)
4243   "Sort ARTICLES."
4244   (when gnus-article-sort-functions
4245     (gnus-message 7 "Sorting articles...")
4246     (prog1
4247         (setq gnus-newsgroup-headers
4248               (sort articles (gnus-make-sort-function
4249                               gnus-article-sort-functions)))
4250       (gnus-message 7 "Sorting articles...done"))))
4251
4252 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4253 (defmacro gnus-thread-header (thread)
4254   "Return header of first article in THREAD.
4255 Note that THREAD must never, ever be anything else than a variable -
4256 using some other form will lead to serious barfage."
4257   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4258   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4259   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4260         (vector thread) 2))
4261
4262 (defsubst gnus-article-sort-by-number (h1 h2)
4263   "Sort articles by article number."
4264   (< (mail-header-number h1)
4265      (mail-header-number h2)))
4266
4267 (defun gnus-thread-sort-by-number (h1 h2)
4268   "Sort threads by root article number."
4269   (gnus-article-sort-by-number
4270    (gnus-thread-header h1) (gnus-thread-header h2)))
4271
4272 (defsubst gnus-article-sort-by-random (h1 h2)
4273   "Sort articles by article number."
4274   (zerop (random 2)))
4275
4276 (defun gnus-thread-sort-by-random (h1 h2)
4277   "Sort threads by root article number."
4278   (gnus-article-sort-by-random
4279    (gnus-thread-header h1) (gnus-thread-header h2)))
4280
4281 (defsubst gnus-article-sort-by-lines (h1 h2)
4282   "Sort articles by article Lines header."
4283   (< (mail-header-lines h1)
4284      (mail-header-lines h2)))
4285
4286 (defun gnus-thread-sort-by-lines (h1 h2)
4287   "Sort threads by root article Lines header."
4288   (gnus-article-sort-by-lines
4289    (gnus-thread-header h1) (gnus-thread-header h2)))
4290
4291 (defsubst gnus-article-sort-by-chars (h1 h2)
4292   "Sort articles by octet length."
4293   (< (mail-header-chars h1)
4294      (mail-header-chars h2)))
4295
4296 (defun gnus-thread-sort-by-chars (h1 h2)
4297   "Sort threads by root article octet length."
4298   (gnus-article-sort-by-chars
4299    (gnus-thread-header h1) (gnus-thread-header h2)))
4300
4301 (defsubst gnus-article-sort-by-author (h1 h2)
4302   "Sort articles by root author."
4303   (string-lessp
4304    (let ((extract (funcall
4305                    gnus-extract-address-components
4306                    (mail-header-from h1))))
4307      (or (car extract) (cadr extract) ""))
4308    (let ((extract (funcall
4309                    gnus-extract-address-components
4310                    (mail-header-from h2))))
4311      (or (car extract) (cadr extract) ""))))
4312
4313 (defun gnus-thread-sort-by-author (h1 h2)
4314   "Sort threads by root author."
4315   (gnus-article-sort-by-author
4316    (gnus-thread-header h1)  (gnus-thread-header h2)))
4317
4318 (defsubst gnus-article-sort-by-subject (h1 h2)
4319   "Sort articles by root subject."
4320   (string-lessp
4321    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4322    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4323
4324 (defun gnus-thread-sort-by-subject (h1 h2)
4325   "Sort threads by root subject."
4326   (gnus-article-sort-by-subject
4327    (gnus-thread-header h1) (gnus-thread-header h2)))
4328
4329 (defsubst gnus-article-sort-by-date (h1 h2)
4330   "Sort articles by root article date."
4331   (time-less-p
4332    (gnus-date-get-time (mail-header-date h1))
4333    (gnus-date-get-time (mail-header-date h2))))
4334
4335 (defun gnus-thread-sort-by-date (h1 h2)
4336   "Sort threads by root article date."
4337   (gnus-article-sort-by-date
4338    (gnus-thread-header h1) (gnus-thread-header h2)))
4339
4340 (defsubst gnus-article-sort-by-score (h1 h2)
4341   "Sort articles by root article score.
4342 Unscored articles will be counted as having a score of zero."
4343   (> (or (cdr (assq (mail-header-number h1)
4344                     gnus-newsgroup-scored))
4345          gnus-summary-default-score 0)
4346      (or (cdr (assq (mail-header-number h2)
4347                     gnus-newsgroup-scored))
4348          gnus-summary-default-score 0)))
4349
4350 (defun gnus-thread-sort-by-score (h1 h2)
4351   "Sort threads by root article score."
4352   (gnus-article-sort-by-score
4353    (gnus-thread-header h1) (gnus-thread-header h2)))
4354
4355 (defun gnus-thread-sort-by-total-score (h1 h2)
4356   "Sort threads by the sum of all scores in the thread.
4357 Unscored articles will be counted as having a score of zero."
4358   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4359
4360 (defun gnus-thread-total-score (thread)
4361   ;; This function find the total score of THREAD.
4362   (cond
4363    ((null thread)
4364     0)
4365    ((consp thread)
4366     (if (stringp (car thread))
4367         (apply gnus-thread-score-function 0
4368                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4369       (gnus-thread-total-score-1 thread)))
4370    (t
4371     (gnus-thread-total-score-1 (list thread)))))
4372
4373 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4374   "Sort threads such that the thread with the most recently arrived article comes first."
4375   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4376
4377 (defun gnus-thread-highest-number (thread)
4378   "Return the highest article number in THREAD."
4379   (apply 'max (mapcar (lambda (header)
4380                         (mail-header-number header))
4381                       (message-flatten-list thread))))
4382
4383 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4384   "Sort threads such that the thread with the most recently dated article comes first."
4385   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4386
4387 (defun gnus-thread-latest-date (thread)
4388   "Return the highest article date in THREAD."
4389   (let ((previous-time 0))
4390     (apply 'max (mapcar
4391                  (lambda (header)
4392                    (setq previous-time
4393                          (time-to-seconds
4394                           (mail-header-parse-date
4395                            (condition-case ()
4396                                (mail-header-date header)
4397                              (error previous-time))))))
4398                  (sort
4399                   (message-flatten-list thread)
4400                   (lambda (h1 h2)
4401                     (< (mail-header-number h1)
4402                        (mail-header-number h2))))))))
4403
4404 (defun gnus-thread-total-score-1 (root)
4405   ;; This function find the total score of the thread below ROOT.
4406   (setq root (car root))
4407   (apply gnus-thread-score-function
4408          (or (append
4409               (mapcar 'gnus-thread-total-score
4410                       (cdr (gnus-id-to-thread (mail-header-id root))))
4411               (when (> (mail-header-number root) 0)
4412                 (list (or (cdr (assq (mail-header-number root)
4413                                      gnus-newsgroup-scored))
4414                           gnus-summary-default-score 0))))
4415              (list gnus-summary-default-score)
4416              '(0))))
4417
4418 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4419 (defvar gnus-tmp-prev-subject nil)
4420 (defvar gnus-tmp-false-parent nil)
4421 (defvar gnus-tmp-root-expunged nil)
4422 (defvar gnus-tmp-dummy-line nil)
4423
4424 (eval-when-compile (defvar gnus-tmp-header))
4425 (defun gnus-extra-header (type &optional header)
4426   "Return the extra header of TYPE."
4427   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4428       ""))
4429
4430 (defvar gnus-tmp-thread-tree-header-string "")
4431
4432 (defcustom gnus-sum-thread-tree-root "> "
4433   "With %B spec, used for the root of a thread.
4434 If nil, use subject instead."
4435   :type 'string
4436   :group 'gnus-thread)
4437 (defcustom gnus-sum-thread-tree-single-indent ""
4438   "With %B spec, used for a thread with just one message.
4439 If nil, use subject instead."
4440   :type 'string
4441   :group 'gnus-thread)
4442 (defcustom gnus-sum-thread-tree-vertical "| "
4443   "With %B spec, used for drawing a vertical line."
4444   :type 'string
4445   :group 'gnus-thread)
4446 (defcustom gnus-sum-thread-tree-indent "  "
4447   "With %B spec, used for indenting."
4448   :type 'string
4449   :group 'gnus-thread)
4450 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4451   "With %B spec, used for a leaf with brothers."
4452   :type 'string
4453   :group 'gnus-thread)
4454 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4455   "With %B spec, used for a leaf without brothers."
4456   :type 'string
4457   :group 'gnus-thread)
4458
4459 (defun gnus-summary-prepare-threads (threads)
4460   "Prepare summary buffer from THREADS and indentation LEVEL.
4461 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4462 or a straight list of headers."
4463   (gnus-message 7 "Generating summary...")
4464
4465   (setq gnus-newsgroup-threads threads)
4466   (beginning-of-line)
4467
4468   (let ((gnus-tmp-level 0)
4469         (default-score (or gnus-summary-default-score 0))
4470         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4471         thread number subject stack state gnus-tmp-gathered beg-match
4472         new-roots gnus-tmp-new-adopts thread-end simp-subject
4473         gnus-tmp-header gnus-tmp-unread
4474         gnus-tmp-replied gnus-tmp-subject-or-nil
4475         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4476         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4477         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4478         tree-stack)
4479
4480     (setq gnus-tmp-prev-subject nil)
4481
4482     (if (vectorp (car threads))
4483         ;; If this is a straight (sic) list of headers, then a
4484         ;; threaded summary display isn't required, so we just create
4485         ;; an unthreaded one.
4486         (gnus-summary-prepare-unthreaded threads)
4487
4488       ;; Do the threaded display.
4489
4490       (while (or threads stack gnus-tmp-new-adopts new-roots)
4491
4492         (if (and (= gnus-tmp-level 0)
4493                  (or (not stack)
4494                      (= (caar stack) 0))
4495                  (not gnus-tmp-false-parent)
4496                  (or gnus-tmp-new-adopts new-roots))
4497             (if gnus-tmp-new-adopts
4498                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4499                       thread (list (car gnus-tmp-new-adopts))
4500                       gnus-tmp-header (caar thread)
4501                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4502               (when new-roots
4503                 (setq thread (list (car new-roots))
4504                       gnus-tmp-header (caar thread)
4505                       new-roots (cdr new-roots))))
4506
4507           (if threads
4508               ;; If there are some threads, we do them before the
4509               ;; threads on the stack.
4510               (setq thread threads
4511                     gnus-tmp-header (caar thread))
4512             ;; There were no current threads, so we pop something off
4513             ;; the stack.
4514             (setq state (car stack)
4515                   gnus-tmp-level (car state)
4516                   tree-stack (cadr state)
4517                   thread (caddr state)
4518                   stack (cdr stack)
4519                   gnus-tmp-header (caar thread))))
4520
4521         (setq gnus-tmp-false-parent nil)
4522         (setq gnus-tmp-root-expunged nil)
4523         (setq thread-end nil)
4524
4525         (if (stringp gnus-tmp-header)
4526             ;; The header is a dummy root.
4527             (cond
4528              ((eq gnus-summary-make-false-root 'adopt)
4529               ;; We let the first article adopt the rest.
4530               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4531                                                (cddar thread)))
4532               (setq gnus-tmp-gathered
4533                     (nconc (mapcar
4534                             (lambda (h) (mail-header-number (car h)))
4535                             (cddar thread))
4536                            gnus-tmp-gathered))
4537               (setq thread (cons (list (caar thread)
4538                                        (cadar thread))
4539                                  (cdr thread)))
4540               (setq gnus-tmp-level -1
4541                     gnus-tmp-false-parent t))
4542              ((eq gnus-summary-make-false-root 'empty)
4543               ;; We print adopted articles with empty subject fields.
4544               (setq gnus-tmp-gathered
4545                     (nconc (mapcar
4546                             (lambda (h) (mail-header-number (car h)))
4547                             (cddar thread))
4548                            gnus-tmp-gathered))
4549               (setq gnus-tmp-level -1))
4550              ((eq gnus-summary-make-false-root 'dummy)
4551               ;; We remember that we probably want to output a dummy
4552               ;; root.
4553               (setq gnus-tmp-dummy-line gnus-tmp-header)
4554               (setq gnus-tmp-prev-subject gnus-tmp-header))
4555              (t
4556               ;; We do not make a root for the gathered
4557               ;; sub-threads at all.
4558               (setq gnus-tmp-level -1)))
4559
4560           (setq number (mail-header-number gnus-tmp-header)
4561                 subject (mail-header-subject gnus-tmp-header)
4562                 simp-subject (gnus-simplify-subject-fully subject))
4563
4564           (cond
4565            ;; If the thread has changed subject, we might want to make
4566            ;; this subthread into a root.
4567            ((and (null gnus-thread-ignore-subject)
4568                  (not (zerop gnus-tmp-level))
4569                  gnus-tmp-prev-subject
4570                  (not (string= gnus-tmp-prev-subject simp-subject)))
4571             (setq new-roots (nconc new-roots (list (car thread)))
4572                   thread-end t
4573                   gnus-tmp-header nil))
4574            ;; If the article lies outside the current limit,
4575            ;; then we do not display it.
4576            ((not (memq number gnus-newsgroup-limit))
4577             (setq gnus-tmp-gathered
4578                   (nconc (mapcar
4579                           (lambda (h) (mail-header-number (car h)))
4580                           (cdar thread))
4581                          gnus-tmp-gathered))
4582             (setq gnus-tmp-new-adopts (if (cdar thread)
4583                                           (append gnus-tmp-new-adopts
4584                                                   (cdar thread))
4585                                         gnus-tmp-new-adopts)
4586                   thread-end t
4587                   gnus-tmp-header nil)
4588             (when (zerop gnus-tmp-level)
4589               (setq gnus-tmp-root-expunged t)))
4590            ;; Perhaps this article is to be marked as read?
4591            ((and gnus-summary-mark-below
4592                  (< (or (cdr (assq number gnus-newsgroup-scored))
4593                         default-score)
4594                     gnus-summary-mark-below)
4595                  ;; Don't touch sparse articles.
4596                  (not (gnus-summary-article-sparse-p number))
4597                  (not (gnus-summary-article-ancient-p number)))
4598             (setq gnus-newsgroup-unreads
4599                   (delq number gnus-newsgroup-unreads))
4600             (if gnus-newsgroup-auto-expire
4601                 (setq gnus-newsgroup-expirable
4602                       (gnus-add-to-sorted-list
4603                        gnus-newsgroup-expirable number))
4604               (push (cons number gnus-low-score-mark)
4605                     gnus-newsgroup-reads))))
4606
4607           (when gnus-tmp-header
4608             ;; We may have an old dummy line to output before this
4609             ;; article.
4610             (when (and gnus-tmp-dummy-line
4611                        (gnus-subject-equal
4612                         gnus-tmp-dummy-line
4613                         (mail-header-subject gnus-tmp-header)))
4614               (gnus-summary-insert-dummy-line
4615                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4616               (setq gnus-tmp-dummy-line nil))
4617
4618             ;; Compute the mark.
4619             (setq gnus-tmp-unread (gnus-article-mark number))
4620
4621             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4622                                   gnus-tmp-header gnus-tmp-level)
4623                   gnus-newsgroup-data)
4624
4625             ;; Actually insert the line.
4626             (setq
4627              gnus-tmp-subject-or-nil
4628              (cond
4629               ((and gnus-thread-ignore-subject
4630                     gnus-tmp-prev-subject
4631                     (not (string= gnus-tmp-prev-subject simp-subject)))
4632                subject)
4633               ((zerop gnus-tmp-level)
4634                (if (and (eq gnus-summary-make-false-root 'empty)
4635                         (memq number gnus-tmp-gathered)
4636                         gnus-tmp-prev-subject
4637                         (string= gnus-tmp-prev-subject simp-subject))
4638                    gnus-summary-same-subject
4639                  subject))
4640               (t gnus-summary-same-subject)))
4641             (if (and (eq gnus-summary-make-false-root 'adopt)
4642                      (= gnus-tmp-level 1)
4643                      (memq number gnus-tmp-gathered))
4644                 (setq gnus-tmp-opening-bracket ?\<
4645                       gnus-tmp-closing-bracket ?\>)
4646               (setq gnus-tmp-opening-bracket ?\[
4647                     gnus-tmp-closing-bracket ?\]))
4648             (setq
4649              gnus-tmp-indentation
4650              (aref gnus-thread-indent-array gnus-tmp-level)
4651              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4652              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4653                                 gnus-summary-default-score 0)
4654              gnus-tmp-score-char
4655              (if (or (null gnus-summary-default-score)
4656                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4657                          gnus-summary-zcore-fuzz))
4658                  ?                      ;Whitespace
4659                (if (< gnus-tmp-score gnus-summary-default-score)
4660                    gnus-score-below-mark gnus-score-over-mark))
4661              gnus-tmp-replied
4662              (cond ((memq number gnus-newsgroup-processable)
4663                     gnus-process-mark)
4664                    ((memq number gnus-newsgroup-cached)
4665                     gnus-cached-mark)
4666                    ((memq number gnus-newsgroup-replied)
4667                     gnus-replied-mark)
4668                    ((memq number gnus-newsgroup-forwarded)
4669                     gnus-forwarded-mark)
4670                    ((memq number gnus-newsgroup-saved)
4671                     gnus-saved-mark)
4672                    ((memq number gnus-newsgroup-recent)
4673                     gnus-recent-mark)
4674                    ((memq number gnus-newsgroup-unseen)
4675                     gnus-unseen-mark)
4676                    (t gnus-no-mark))
4677              gnus-tmp-from (mail-header-from gnus-tmp-header)
4678              gnus-tmp-name
4679              (cond
4680               ((string-match "<[^>]+> *$" gnus-tmp-from)
4681                (setq beg-match (match-beginning 0))
4682                (or (and (string-match "^\".+\"" gnus-tmp-from)
4683                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4684                    (substring gnus-tmp-from 0 beg-match)))
4685               ((string-match "(.+)" gnus-tmp-from)
4686                (substring gnus-tmp-from
4687                           (1+ (match-beginning 0)) (1- (match-end 0))))
4688               (t gnus-tmp-from))
4689              gnus-tmp-thread-tree-header-string
4690              (cond
4691               ((not gnus-show-threads) "")
4692               ((zerop gnus-tmp-level)
4693                (if (cdar thread)
4694                    (or gnus-sum-thread-tree-root subject)
4695                  (or gnus-sum-thread-tree-single-indent subject)))
4696               (t
4697                (concat (apply 'concat
4698                               (mapcar (lambda (item)
4699                                         (if (= item 1)
4700                                             gnus-sum-thread-tree-vertical
4701                                           gnus-sum-thread-tree-indent))
4702                                       (cdr (reverse tree-stack))))
4703                        (if (nth 1 thread)
4704                            gnus-sum-thread-tree-leaf-with-other
4705                          gnus-sum-thread-tree-single-leaf)))))
4706             (when (string= gnus-tmp-name "")
4707               (setq gnus-tmp-name gnus-tmp-from))
4708             (unless (numberp gnus-tmp-lines)
4709               (setq gnus-tmp-lines -1))
4710             (if (= gnus-tmp-lines -1)
4711                 (setq gnus-tmp-lines "?")
4712               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4713             (gnus-put-text-property
4714              (point)
4715              (progn (eval gnus-summary-line-format-spec) (point))
4716              'gnus-number number)
4717             (when gnus-visual-p
4718               (forward-line -1)
4719               (gnus-run-hooks 'gnus-summary-update-hook)
4720               (forward-line 1))
4721
4722             (setq gnus-tmp-prev-subject simp-subject)))
4723
4724         (when (nth 1 thread)
4725           (push (list (max 0 gnus-tmp-level)
4726                       (copy-list tree-stack)
4727                       (nthcdr 1 thread))
4728                 stack))
4729         (push (if (nth 1 thread) 1 0) tree-stack)
4730         (incf gnus-tmp-level)
4731         (setq threads (if thread-end nil (cdar thread)))
4732         (unless threads
4733           (setq gnus-tmp-level 0)))))
4734   (gnus-message 7 "Generating summary...done"))
4735
4736 (defun gnus-summary-prepare-unthreaded (headers)
4737   "Generate an unthreaded summary buffer based on HEADERS."
4738   (let (header number mark)
4739
4740     (beginning-of-line)
4741
4742     (while headers
4743       ;; We may have to root out some bad articles...
4744       (when (memq (setq number (mail-header-number
4745                                 (setq header (pop headers))))
4746                   gnus-newsgroup-limit)
4747         ;; Mark article as read when it has a low score.
4748         (when (and gnus-summary-mark-below
4749                    (< (or (cdr (assq number gnus-newsgroup-scored))
4750                           gnus-summary-default-score 0)
4751                       gnus-summary-mark-below)
4752                    (not (gnus-summary-article-ancient-p number)))
4753           (setq gnus-newsgroup-unreads
4754                 (delq number gnus-newsgroup-unreads))
4755           (if gnus-newsgroup-auto-expire
4756               (push number gnus-newsgroup-expirable)
4757             (push (cons number gnus-low-score-mark)
4758                   gnus-newsgroup-reads)))
4759
4760         (setq mark (gnus-article-mark number))
4761         (push (gnus-data-make number mark (1+ (point)) header 0)
4762               gnus-newsgroup-data)
4763         (gnus-summary-insert-line
4764          header 0 number
4765          mark (memq number gnus-newsgroup-replied)
4766          (memq number gnus-newsgroup-expirable)
4767          (mail-header-subject header) nil
4768          (cdr (assq number gnus-newsgroup-scored))
4769          (memq number gnus-newsgroup-processable))))))
4770
4771 (defun gnus-summary-remove-list-identifiers ()
4772   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4773   (let ((regexp (if (consp gnus-list-identifiers)
4774                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4775                   gnus-list-identifiers))
4776         changed subject)
4777     (when regexp
4778       (dolist (header gnus-newsgroup-headers)
4779         (setq subject (mail-header-subject header)
4780               changed nil)
4781         (while (string-match
4782                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4783                 subject)
4784           (setq subject
4785                 (concat (substring subject 0 (match-beginning 2))
4786                         (substring subject (match-end 0)))
4787                 changed t))
4788         (when (and changed
4789                    (string-match
4790                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4791           (setq subject
4792                 (concat (substring subject 0 (match-beginning 1))
4793                         (substring subject (match-end 1)))))
4794         (when changed
4795           (mail-header-set-subject header subject))))))
4796
4797 (defun gnus-fetch-headers (articles)
4798   "Fetch headers of ARTICLES."
4799   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4800     (gnus-message 5 "Fetching headers for %s..." name)
4801     (prog1
4802         (if (eq 'nov
4803                 (setq gnus-headers-retrieved-by
4804                       (gnus-retrieve-headers
4805                        articles gnus-newsgroup-name
4806                        ;; We might want to fetch old headers, but
4807                        ;; not if there is only 1 article.
4808                        (and (or (and
4809                                  (not (eq gnus-fetch-old-headers 'some))
4810                                  (not (numberp gnus-fetch-old-headers)))
4811                                 (> (length articles) 1))
4812                             gnus-fetch-old-headers))))
4813             (gnus-get-newsgroup-headers-xover
4814              articles nil nil gnus-newsgroup-name t)
4815           (gnus-get-newsgroup-headers))
4816       (gnus-message 5 "Fetching headers for %s...done" name))))
4817
4818 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4819   "Select newsgroup GROUP.
4820 If READ-ALL is non-nil, all articles in the group are selected.
4821 If SELECT-ARTICLES, only select those articles from GROUP."
4822   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4823          ;;!!! Dirty hack; should be removed.
4824          (gnus-summary-ignore-duplicates
4825           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4826               t
4827             gnus-summary-ignore-duplicates))
4828          (info (nth 2 entry))
4829          articles fetched-articles cached)
4830
4831     (unless (gnus-check-server
4832              (set (make-local-variable 'gnus-current-select-method)
4833                   (gnus-find-method-for-group group)))
4834       (error "Couldn't open server"))
4835
4836     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4837         (gnus-activate-group group)     ; Or we can activate it...
4838         (progn                          ; Or we bug out.
4839           (when (equal major-mode 'gnus-summary-mode)
4840             (kill-buffer (current-buffer)))
4841           (error "Couldn't activate group %s: %s"
4842                  group (gnus-status-message group))))
4843
4844     (unless (gnus-request-group group t)
4845       (when (equal major-mode 'gnus-summary-mode)
4846         (kill-buffer (current-buffer)))
4847       (error "Couldn't request group %s: %s"
4848              group (gnus-status-message group)))
4849
4850     (setq gnus-newsgroup-name group
4851           gnus-newsgroup-unselected nil
4852           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4853
4854     (let ((display (gnus-group-find-parameter group 'display)))
4855       (setq gnus-newsgroup-display
4856             (cond
4857              ((not (zerop (or (car-safe read-all) 0)))
4858               ;; The user entered the group with C-u SPC/RET, let's show
4859               ;; all articles.
4860               'gnus-not-ignore)
4861              ((eq display 'all)
4862               'gnus-not-ignore)
4863              ((arrayp display)
4864               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4865              ((numberp display)
4866               ;; The following is probably the "correct" solution, but
4867               ;; it makes Gnus fetch all headers and then limit the
4868               ;; articles (which is slow), so instead we hack the
4869               ;; select-articles parameter instead. -- Simon Josefsson
4870               ;; <jas@kth.se>
4871               ;;
4872               ;; (gnus-byte-compile
4873               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4874               ;;                         display)))))
4875               (setq select-articles
4876                     (gnus-uncompress-range
4877                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4878                              (if (> tmp 0)
4879                                  tmp
4880                                1))
4881                            (cdr (gnus-active group)))))
4882               nil)
4883              (t
4884               nil))))
4885
4886     (gnus-summary-setup-default-charset)
4887
4888     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4889     (when (gnus-virtual-group-p group)
4890       (setq cached gnus-newsgroup-cached))
4891
4892     (setq gnus-newsgroup-unreads
4893           (gnus-sorted-ndifference
4894            (gnus-sorted-ndifference gnus-newsgroup-unreads
4895                                     gnus-newsgroup-marked)
4896            gnus-newsgroup-dormant))
4897
4898     (setq gnus-newsgroup-processable nil)
4899
4900     (gnus-update-read-articles group gnus-newsgroup-unreads)
4901
4902     ;; Adjust and set lists of article marks.
4903     (when info
4904       (gnus-adjust-marked-articles info))
4905     (if (setq articles select-articles)
4906         (setq gnus-newsgroup-unselected
4907               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4908       (setq articles (gnus-articles-to-read group read-all)))
4909
4910     (cond
4911      ((null articles)
4912       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4913       'quit)
4914      ((eq articles 0) nil)
4915      (t
4916       ;; Init the dependencies hash table.
4917       (setq gnus-newsgroup-dependencies
4918             (gnus-make-hashtable (length articles)))
4919       (gnus-set-global-variables)
4920       ;; Retrieve the headers and read them in.
4921
4922       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4923
4924       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4925       (when cached
4926         (setq gnus-newsgroup-cached cached))
4927
4928       ;; Suppress duplicates?
4929       (when gnus-suppress-duplicates
4930         (gnus-dup-suppress-articles))
4931
4932       ;; Set the initial limit.
4933       (setq gnus-newsgroup-limit (copy-sequence articles))
4934       ;; Remove canceled articles from the list of unread articles.
4935       (setq fetched-articles
4936             (mapcar (lambda (headers) (mail-header-number headers))
4937                     gnus-newsgroup-headers))
4938       (setq gnus-newsgroup-articles fetched-articles)
4939       (setq gnus-newsgroup-unreads
4940             (gnus-sorted-nintersection
4941              gnus-newsgroup-unreads fetched-articles))
4942       (gnus-compute-unseen-list)
4943
4944       ;; Removed marked articles that do not exist.
4945       (gnus-update-missing-marks
4946        (gnus-sorted-difference articles fetched-articles))
4947       ;; We might want to build some more threads first.
4948       (when (and gnus-fetch-old-headers
4949                  (eq gnus-headers-retrieved-by 'nov))
4950         (if (eq gnus-fetch-old-headers 'invisible)
4951             (gnus-build-all-threads)
4952           (gnus-build-old-threads)))
4953       ;; Let the Gnus agent mark articles as read.
4954       (when gnus-agent
4955         (gnus-agent-get-undownloaded-list))
4956       ;; Remove list identifiers from subject
4957       (when gnus-list-identifiers
4958         (gnus-summary-remove-list-identifiers))
4959       ;; Check whether auto-expire is to be done in this group.
4960       (setq gnus-newsgroup-auto-expire
4961             (gnus-group-auto-expirable-p group))
4962       ;; Set up the article buffer now, if necessary.
4963       (unless gnus-single-article-buffer
4964         (gnus-article-setup-buffer))
4965       ;; First and last article in this newsgroup.
4966       (when gnus-newsgroup-headers
4967         (setq gnus-newsgroup-begin
4968               (mail-header-number (car gnus-newsgroup-headers))
4969               gnus-newsgroup-end
4970               (mail-header-number
4971                (gnus-last-element gnus-newsgroup-headers))))
4972       ;; GROUP is successfully selected.
4973       (or gnus-newsgroup-headers t)))))
4974
4975 (defun gnus-compute-unseen-list ()
4976   ;; The `seen' marks are treated specially.
4977   (if (not gnus-newsgroup-seen)
4978       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4979     (setq gnus-newsgroup-unseen
4980           (gnus-inverse-list-range-intersection
4981            gnus-newsgroup-articles gnus-newsgroup-seen))))
4982
4983 (defun gnus-summary-display-make-predicate (display)
4984   (require 'gnus-agent)
4985   (when (= (length display) 1)
4986     (setq display (car display)))
4987   (unless gnus-summary-display-cache
4988     (dolist (elem (append '((unread . unread)
4989                             (read . read)
4990                             (unseen . unseen))
4991                           gnus-article-mark-lists))
4992       (push (cons (cdr elem)
4993                   (gnus-byte-compile
4994                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4995             gnus-summary-display-cache)))
4996   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4997         (gnus-category-predicate-cache gnus-summary-display-cache))
4998     (gnus-get-predicate display)))
4999
5000 ;; Uses the dynamically bound `number' variable.
5001 (defvar number)
5002 (defun gnus-article-marked-p (type &optional article)
5003   (let ((article (or article number)))
5004     (cond
5005      ((eq type 'tick)
5006       (memq article gnus-newsgroup-marked))
5007      ((eq type 'spam)
5008       (memq article gnus-newsgroup-spam-marked))
5009      ((eq type 'unsend)
5010       (memq article gnus-newsgroup-unsendable))
5011      ((eq type 'undownload)
5012       (memq article gnus-newsgroup-undownloaded))
5013      ((eq type 'download)
5014       (memq article gnus-newsgroup-downloadable))
5015      ((eq type 'unread)
5016       (memq article gnus-newsgroup-unreads))
5017      ((eq type 'read)
5018       (memq article gnus-newsgroup-reads))
5019      ((eq type 'dormant)
5020       (memq article gnus-newsgroup-dormant) )
5021      ((eq type 'expire)
5022       (memq article gnus-newsgroup-expirable))
5023      ((eq type 'reply)
5024       (memq article gnus-newsgroup-replied))
5025      ((eq type 'killed)
5026       (memq article gnus-newsgroup-killed))
5027      ((eq type 'bookmark)
5028       (assq article gnus-newsgroup-bookmarks))
5029      ((eq type 'score)
5030       (assq article gnus-newsgroup-scored))
5031      ((eq type 'save)
5032       (memq article gnus-newsgroup-saved))
5033      ((eq type 'cache)
5034       (memq article gnus-newsgroup-cached))
5035      ((eq type 'forward)
5036       (memq article gnus-newsgroup-forwarded))
5037      ((eq type 'seen)
5038       (not (memq article gnus-newsgroup-unseen)))
5039      ((eq type 'recent)
5040       (memq article gnus-newsgroup-recent))
5041      (t t))))
5042
5043 (defun gnus-articles-to-read (group &optional read-all)
5044   "Find out what articles the user wants to read."
5045   (let* ((articles
5046           ;; Select all articles if `read-all' is non-nil, or if there
5047           ;; are no unread articles.
5048           (if (or read-all
5049                   (and (zerop (length gnus-newsgroup-marked))
5050                        (zerop (length gnus-newsgroup-unreads)))
5051                   ;; Fetch all if the predicate is non-nil.
5052                   gnus-newsgroup-display)
5053               ;; We want to select the headers for all the articles in
5054               ;; the group, so we select either all the active
5055               ;; articles in the group, or (if that's nil), the
5056               ;; articles in the cache.
5057               (or
5058                (gnus-uncompress-range (gnus-active group))
5059                (gnus-cache-articles-in-group group))
5060             ;; Select only the "normal" subset of articles.
5061             (gnus-sorted-nunion
5062              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5063              gnus-newsgroup-unreads)))
5064          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5065          (scored (length scored-list))
5066          (number (length articles))
5067          (marked (+ (length gnus-newsgroup-marked)
5068                     (length gnus-newsgroup-dormant)))
5069          (select
5070           (cond
5071            ((numberp read-all)
5072             read-all)
5073            ((numberp gnus-newsgroup-display)
5074             gnus-newsgroup-display)
5075            (t
5076             (condition-case ()
5077                 (cond
5078                  ((and (or (<= scored marked) (= scored number))
5079                        (numberp gnus-large-newsgroup)
5080                        (> number gnus-large-newsgroup))
5081                   (let* ((cursor-in-echo-area nil)
5082                          (initial (gnus-parameter-large-newsgroup-initial
5083                                    gnus-newsgroup-name))
5084                          (input
5085                           (read-string
5086                            (format
5087                             "How many articles from %s (%s %d): "
5088                             (gnus-limit-string
5089                              (gnus-group-decoded-name gnus-newsgroup-name)
5090                              35)
5091                             (if initial "max" "default")
5092                             number)
5093                            (if initial
5094                                (cons (number-to-string initial)
5095                                      0)))))
5096                     (if (string-match "^[ \t]*$" input) number input)))
5097                  ((and (> scored marked) (< scored number)
5098                        (> (- scored number) 20))
5099                   (let ((input
5100                          (read-string
5101                           (format "%s %s (%d scored, %d total): "
5102                                   "How many articles from"
5103                                   (gnus-group-decoded-name group)
5104                                   scored number))))
5105                     (if (string-match "^[ \t]*$" input)
5106                         number input)))
5107                  (t number))
5108               (quit
5109                (message "Quit getting the articles to read")
5110                nil))))))
5111     (setq select (if (stringp select) (string-to-number select) select))
5112     (if (or (null select) (zerop select))
5113         select
5114       (if (and (not (zerop scored)) (<= (abs select) scored))
5115           (progn
5116             (setq articles (sort scored-list '<))
5117             (setq number (length articles)))
5118         (setq articles (copy-sequence articles)))
5119
5120       (when (< (abs select) number)
5121         (if (< select 0)
5122             ;; Select the N oldest articles.
5123             (setcdr (nthcdr (1- (abs select)) articles) nil)
5124           ;; Select the N most recent articles.
5125           (setq articles (nthcdr (- number select) articles))))
5126       (setq gnus-newsgroup-unselected
5127             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5128       (when gnus-alter-articles-to-read-function
5129         (setq gnus-newsgroup-unreads
5130               (sort
5131                (funcall gnus-alter-articles-to-read-function
5132                         gnus-newsgroup-name gnus-newsgroup-unreads)
5133                '<)))
5134       articles)))
5135
5136 (defun gnus-killed-articles (killed articles)
5137   (let (out)
5138     (while articles
5139       (when (inline (gnus-member-of-range (car articles) killed))
5140         (push (car articles) out))
5141       (setq articles (cdr articles)))
5142     out))
5143
5144 (defun gnus-uncompress-marks (marks)
5145   "Uncompress the mark ranges in MARKS."
5146   (let ((uncompressed '(score bookmark))
5147         out)
5148     (while marks
5149       (if (memq (caar marks) uncompressed)
5150           (push (car marks) out)
5151         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5152       (setq marks (cdr marks)))
5153     out))
5154
5155 (defun gnus-article-mark-to-type (mark)
5156   "Return the type of MARK."
5157   (or (cadr (assq mark gnus-article-special-mark-lists))
5158       'list))
5159
5160 (defun gnus-article-unpropagatable-p (mark)
5161   "Return whether MARK should be propagated to backend."
5162   (memq mark gnus-article-unpropagated-mark-lists))
5163
5164 (defun gnus-adjust-marked-articles (info)
5165   "Set all article lists and remove all marks that are no longer valid."
5166   (let* ((marked-lists (gnus-info-marks info))
5167          (active (gnus-active (gnus-info-group info)))
5168          (min (car active))
5169          (max (cdr active))
5170          (types gnus-article-mark-lists)
5171          marks var articles article mark mark-type)
5172
5173     (dolist (marks marked-lists)
5174       (setq mark (car marks)
5175             mark-type (gnus-article-mark-to-type mark)
5176             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5177
5178       ;; We set the variable according to the type of the marks list,
5179       ;; and then adjust the marks to a subset of the active articles.
5180       (cond
5181        ;; Adjust "simple" lists.
5182        ((eq mark-type 'list)
5183         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5184         (when (memq mark '(tick dormant expire reply save))
5185           (while articles
5186             (when (or (< (setq article (pop articles)) min) (> article max))
5187               (set var (delq article (symbol-value var)))))))
5188        ;; Adjust assocs.
5189        ((eq mark-type 'tuple)
5190         (set var (setq articles (cdr marks)))
5191         (when (not (listp (cdr (symbol-value var))))
5192           (set var (list (symbol-value var))))
5193         (when (not (listp (cdr articles)))
5194           (setq articles (list articles)))
5195         (while articles
5196           (when (or (not (consp (setq article (pop articles))))
5197                     (< (car article) min)
5198                     (> (car article) max))
5199             (set var (delq article (symbol-value var))))))
5200        ;; Adjust ranges (sloppily).
5201        ((eq mark-type 'range)
5202         (cond
5203          ((eq mark 'seen)
5204           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5205           ;; It should be (seen (NUM1 . NUM2)).
5206           (when (numberp (cddr marks))
5207             (setcdr marks (list (cdr marks))))
5208           (setq articles (cdr marks))
5209           (while (and articles
5210                       (or (and (consp (car articles))
5211                                (> min (cdar articles)))
5212                           (and (numberp (car articles))
5213                                (> min (car articles)))))
5214             (pop articles))
5215           (set var articles))))))))
5216
5217 (defun gnus-update-missing-marks (missing)
5218   "Go through the list of MISSING articles and remove them from the mark lists."
5219   (when missing
5220     (let (var m)
5221       ;; Go through all types.
5222       (dolist (elem gnus-article-mark-lists)
5223         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5224           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5225           (when (symbol-value var)
5226             ;; This list has articles.  So we delete all missing
5227             ;; articles from it.
5228             (setq m missing)
5229             (while m
5230               (set var (delq (pop m) (symbol-value var))))))))))
5231
5232 (defun gnus-update-marks ()
5233   "Enter the various lists of marked articles into the newsgroup info list."
5234   (let ((types gnus-article-mark-lists)
5235         (info (gnus-get-info gnus-newsgroup-name))
5236         type list newmarked symbol delta-marks)
5237     (when info
5238       ;; Add all marks lists to the list of marks lists.
5239       (while (setq type (pop types))
5240         (setq list (symbol-value
5241                     (setq symbol
5242                           (intern (format "gnus-newsgroup-%s" (car type))))))
5243
5244         (when list
5245           ;; Get rid of the entries of the articles that have the
5246           ;; default score.
5247           (when (and (eq (cdr type) 'score)
5248                      gnus-save-score
5249                      list)
5250             (let* ((arts list)
5251                    (prev (cons nil list))
5252                    (all prev))
5253               (while arts
5254                 (if (or (not (consp (car arts)))
5255                         (= (cdar arts) gnus-summary-default-score))
5256                     (setcdr prev (cdr arts))
5257                   (setq prev arts))
5258                 (setq arts (cdr arts)))
5259               (setq list (cdr all)))))
5260
5261         (when (eq (cdr type) 'seen)
5262           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5263
5264         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5265           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5266
5267         (when (and (gnus-check-backend-function
5268                     'request-set-mark gnus-newsgroup-name)
5269                    (not (gnus-article-unpropagatable-p (cdr type))))
5270           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5271                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5272                  (add (gnus-remove-from-range
5273                        (gnus-copy-sequence list) old)))
5274             (when add
5275               (push (list add 'add (list (cdr type))) delta-marks))
5276             (when del
5277               (push (list del 'del (list (cdr type))) delta-marks))))
5278
5279         (when list
5280           (push (cons (cdr type) list) newmarked)))
5281
5282       (when delta-marks
5283         (unless (gnus-check-group gnus-newsgroup-name)
5284           (error "Can't open server for %s" gnus-newsgroup-name))
5285         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5286
5287       ;; Enter these new marks into the info of the group.
5288       (if (nthcdr 3 info)
5289           (setcar (nthcdr 3 info) newmarked)
5290         ;; Add the marks lists to the end of the info.
5291         (when newmarked
5292           (setcdr (nthcdr 2 info) (list newmarked))))
5293
5294       ;; Cut off the end of the info if there's nothing else there.
5295       (let ((i 5))
5296         (while (and (> i 2)
5297                     (not (nth i info)))
5298           (when (nthcdr (decf i) info)
5299             (setcdr (nthcdr i info) nil)))))))
5300
5301 (defun gnus-set-mode-line (where)
5302   "Set the mode line of the article or summary buffers.
5303 If WHERE is `summary', the summary mode line format will be used."
5304   ;; Is this mode line one we keep updated?
5305   (when (and (memq where gnus-updated-mode-lines)
5306              (symbol-value
5307               (intern (format "gnus-%s-mode-line-format-spec" where))))
5308     (let (mode-string)
5309       (save-excursion
5310         ;; We evaluate this in the summary buffer since these
5311         ;; variables are buffer-local to that buffer.
5312         (set-buffer gnus-summary-buffer)
5313        ;; We bind all these variables that are used in the `eval' form
5314         ;; below.
5315         (let* ((mformat (symbol-value
5316                          (intern
5317                           (format "gnus-%s-mode-line-format-spec" where))))
5318                (gnus-tmp-group-name (gnus-group-decoded-name
5319                                      gnus-newsgroup-name))
5320                (gnus-tmp-article-number (or gnus-current-article 0))
5321                (gnus-tmp-unread gnus-newsgroup-unreads)
5322                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5323                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5324                (gnus-tmp-unread-and-unselected
5325                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5326                             (zerop gnus-tmp-unselected))
5327                        "")
5328                       ((zerop gnus-tmp-unselected)
5329                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5330                       (t (format "{%d(+%d) more}"
5331                                  gnus-tmp-unread-and-unticked
5332                                  gnus-tmp-unselected))))
5333                (gnus-tmp-subject
5334                 (if (and gnus-current-headers
5335                          (vectorp gnus-current-headers))
5336                     (gnus-mode-string-quote
5337                      (mail-header-subject gnus-current-headers))
5338                   ""))
5339                bufname-length max-len
5340                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5341           (setq mode-string (eval mformat))
5342           (setq bufname-length (if (string-match "%b" mode-string)
5343                                    (- (length
5344                                        (buffer-name
5345                                         (if (eq where 'summary)
5346                                             nil
5347                                           (get-buffer gnus-article-buffer))))
5348                                       2)
5349                                  0))
5350           (setq max-len (max 4 (if gnus-mode-non-string-length
5351                                    (- (window-width)
5352                                       gnus-mode-non-string-length
5353                                       bufname-length)
5354                                  (length mode-string))))
5355           ;; We might have to chop a bit of the string off...
5356           (when (> (length mode-string) max-len)
5357             (setq mode-string
5358                   (concat (truncate-string-to-width mode-string (- max-len 3))
5359                           "...")))
5360           ;; Pad the mode string a bit.
5361           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5362       ;; Update the mode line.
5363       (setq mode-line-buffer-identification
5364             (gnus-mode-line-buffer-identification (list mode-string)))
5365       (set-buffer-modified-p t))))
5366
5367 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5368   "Go through the HEADERS list and add all Xrefs to a hash table.
5369 The resulting hash table is returned, or nil if no Xrefs were found."
5370   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5371          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5372          (xref-hashtb (gnus-make-hashtable))
5373          start group entry number xrefs header)
5374     (while headers
5375       (setq header (pop headers))
5376       (when (and (setq xrefs (mail-header-xref header))
5377                  (not (memq (setq number (mail-header-number header))
5378                             unreads)))
5379         (setq start 0)
5380         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5381           (setq start (match-end 0))
5382           (setq group (if prefix
5383                           (concat prefix (substring xrefs (match-beginning 1)
5384                                                     (match-end 1)))
5385                         (substring xrefs (match-beginning 1) (match-end 1))))
5386           (setq number
5387                 (string-to-int (substring xrefs (match-beginning 2)
5388                                           (match-end 2))))
5389           (if (setq entry (gnus-gethash group xref-hashtb))
5390               (setcdr entry (cons number (cdr entry)))
5391             (gnus-sethash group (cons number nil) xref-hashtb)))))
5392     (and start xref-hashtb)))
5393
5394 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5395   "Look through all the headers and mark the Xrefs as read."
5396   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5397         name entry info xref-hashtb idlist method nth4)
5398     (save-excursion
5399       (set-buffer gnus-group-buffer)
5400       (when (setq xref-hashtb
5401                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5402         (mapatoms
5403          (lambda (group)
5404            (unless (string= from-newsgroup (setq name (symbol-name group)))
5405              (setq idlist (symbol-value group))
5406              ;; Dead groups are not updated.
5407              (and (prog1
5408                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5409                             info (nth 2 entry))
5410                     (when (stringp (setq nth4 (gnus-info-method info)))
5411                       (setq nth4 (gnus-server-to-method nth4))))
5412                   ;; Only do the xrefs if the group has the same
5413                   ;; select method as the group we have just read.
5414                   (or (gnus-methods-equal-p
5415                        nth4 (gnus-find-method-for-group from-newsgroup))
5416                       virtual
5417                       (equal nth4 (setq method (gnus-find-method-for-group
5418                                                 from-newsgroup)))
5419                       (and (equal (car nth4) (car method))
5420                            (equal (nth 1 nth4) (nth 1 method))))
5421                   gnus-use-cross-reference
5422                   (or (not (eq gnus-use-cross-reference t))
5423                       virtual
5424                       ;; Only do cross-references on subscribed
5425                       ;; groups, if that is what is wanted.
5426                       (<= (gnus-info-level info) gnus-level-subscribed))
5427                   (gnus-group-make-articles-read name idlist))))
5428          xref-hashtb)))))
5429
5430 (defun gnus-compute-read-articles (group articles)
5431   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5432          (info (nth 2 entry))
5433          (active (gnus-active group))
5434          ninfo)
5435     (when entry
5436       ;; First peel off all invalid article numbers.
5437       (when active
5438         (let ((ids articles)
5439               id first)
5440           (while (setq id (pop ids))
5441             (when (and first (> id (cdr active)))
5442               ;; We'll end up in this situation in one particular
5443               ;; obscure situation.  If you re-scan a group and get
5444               ;; a new article that is cross-posted to a different
5445               ;; group that has not been re-scanned, you might get
5446               ;; crossposted article that has a higher number than
5447               ;; Gnus believes possible.  So we re-activate this
5448               ;; group as well.  This might mean doing the
5449               ;; crossposting thingy will *increase* the number
5450               ;; of articles in some groups.  Tsk, tsk.
5451               (setq active (or (gnus-activate-group group) active)))
5452             (when (or (> id (cdr active))
5453                       (< id (car active)))
5454               (setq articles (delq id articles))))))
5455       ;; If the read list is nil, we init it.
5456       (if (and active
5457                (null (gnus-info-read info))
5458                (> (car active) 1))
5459           (setq ninfo (cons 1 (1- (car active))))
5460         (setq ninfo (gnus-info-read info)))
5461       ;; Then we add the read articles to the range.
5462       (gnus-add-to-range
5463        ninfo (setq articles (sort articles '<))))))
5464
5465 (defun gnus-group-make-articles-read (group articles)
5466   "Update the info of GROUP to say that ARTICLES are read."
5467   (let* ((num 0)
5468          (entry (gnus-gethash group gnus-newsrc-hashtb))
5469          (info (nth 2 entry))
5470          (active (gnus-active group))
5471          range)
5472     (when entry
5473       (setq range (gnus-compute-read-articles group articles))
5474       (save-excursion
5475         (set-buffer gnus-group-buffer)
5476         (gnus-undo-register
5477           `(progn
5478              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5479              (gnus-info-set-read ',info ',(gnus-info-read info))
5480              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5481              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5482              (gnus-group-update-group ,group t))))
5483       ;; Add the read articles to the range.
5484       (gnus-info-set-read info range)
5485       (gnus-request-set-mark group (list (list range 'add '(read))))
5486       ;; Then we have to re-compute how many unread
5487       ;; articles there are in this group.
5488       (when active
5489         (cond
5490          ((not range)
5491           (setq num (- (1+ (cdr active)) (car active))))
5492          ((not (listp (cdr range)))
5493           (setq num (- (cdr active) (- (1+ (cdr range))
5494                                        (car range)))))
5495          (t
5496           (while range
5497             (if (numberp (car range))
5498                 (setq num (1+ num))
5499               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5500             (setq range (cdr range)))
5501           (setq num (- (cdr active) num))))
5502         ;; Update the number of unread articles.
5503         (setcar entry num)
5504         ;; Update the group buffer.
5505         (gnus-group-update-group group t)))))
5506
5507 (defvar gnus-newsgroup-none-id 0)
5508
5509 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5510   (let ((cur nntp-server-buffer)
5511         (dependencies
5512          (or dependencies
5513              (save-excursion (set-buffer gnus-summary-buffer)
5514                              gnus-newsgroup-dependencies)))
5515         headers id end ref
5516         (mail-parse-charset gnus-newsgroup-charset)
5517         (mail-parse-ignored-charsets
5518          (save-excursion (condition-case nil
5519                              (set-buffer gnus-summary-buffer)
5520                            (error))
5521                          gnus-newsgroup-ignored-charsets)))
5522     (save-excursion
5523       (set-buffer nntp-server-buffer)
5524       ;; Translate all TAB characters into SPACE characters.
5525       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5526       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5527       (gnus-run-hooks 'gnus-parse-headers-hook)
5528       (let ((case-fold-search t)
5529             in-reply-to header p lines chars)
5530         (goto-char (point-min))
5531         ;; Search to the beginning of the next header.  Error messages
5532         ;; do not begin with 2 or 3.
5533         (while (re-search-forward "^[23][0-9]+ " nil t)
5534           (setq id nil
5535                 ref nil)
5536           ;; This implementation of this function, with nine
5537           ;; search-forwards instead of the one re-search-forward and
5538           ;; a case (which basically was the old function) is actually
5539           ;; about twice as fast, even though it looks messier.  You
5540           ;; can't have everything, I guess.  Speed and elegance
5541           ;; doesn't always go hand in hand.
5542           (setq
5543            header
5544            (vector
5545             ;; Number.
5546             (prog1
5547                 (read cur)
5548               (end-of-line)
5549               (setq p (point))
5550               (narrow-to-region (point)
5551                                 (or (and (search-forward "\n.\n" nil t)
5552                                          (- (point) 2))
5553                                     (point))))
5554             ;; Subject.
5555             (progn
5556               (goto-char p)
5557               (if (search-forward "\nsubject:" nil t)
5558                   (funcall gnus-decode-encoded-word-function
5559                            (nnheader-header-value))
5560                 "(none)"))
5561             ;; From.
5562             (progn
5563               (goto-char p)
5564               (if (search-forward "\nfrom:" nil t)
5565                   (funcall gnus-decode-encoded-word-function
5566                            (nnheader-header-value))
5567                 "(nobody)"))
5568             ;; Date.
5569             (progn
5570               (goto-char p)
5571               (if (search-forward "\ndate:" nil t)
5572                   (nnheader-header-value) ""))
5573             ;; Message-ID.
5574             (progn
5575               (goto-char p)
5576               (setq id (if (re-search-forward
5577                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5578                            ;; We do it this way to make sure the Message-ID
5579                            ;; is (somewhat) syntactically valid.
5580                            (buffer-substring (match-beginning 1)
5581                                              (match-end 1))
5582                          ;; If there was no message-id, we just fake one
5583                          ;; to make subsequent routines simpler.
5584                          (nnheader-generate-fake-message-id))))
5585             ;; References.
5586             (progn
5587               (goto-char p)
5588               (if (search-forward "\nreferences:" nil t)
5589                   (progn
5590                     (setq end (point))
5591                     (prog1
5592                         (nnheader-header-value)
5593                       (setq ref
5594                             (buffer-substring
5595                              (progn
5596                                (end-of-line)
5597                                (search-backward ">" end t)
5598                                (1+ (point)))
5599                              (progn
5600                                (search-backward "<" end t)
5601                                (point))))))
5602                 ;; Get the references from the in-reply-to header if there
5603                 ;; were no references and the in-reply-to header looks
5604                 ;; promising.
5605                 (if (and (search-forward "\nin-reply-to:" nil t)
5606                          (setq in-reply-to (nnheader-header-value))
5607                          (string-match "<[^>]+>" in-reply-to))
5608                     (let (ref2)
5609                       (setq ref (substring in-reply-to (match-beginning 0)
5610                                            (match-end 0)))
5611                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5612                         (setq ref2 (substring in-reply-to (match-beginning 0)
5613                                               (match-end 0)))
5614                         (when (> (length ref2) (length ref))
5615                           (setq ref ref2)))
5616                       ref)
5617                   (setq ref nil))))
5618             ;; Chars.
5619             (progn
5620               (goto-char p)
5621               (if (search-forward "\nchars: " nil t)
5622                   (if (numberp (setq chars (ignore-errors (read cur))))
5623                       chars -1)
5624                 -1))
5625             ;; Lines.
5626             (progn
5627               (goto-char p)
5628               (if (search-forward "\nlines: " nil t)
5629                   (if (numberp (setq lines (ignore-errors (read cur))))
5630                       lines -1)
5631                 -1))
5632             ;; Xref.
5633             (progn
5634               (goto-char p)
5635               (and (search-forward "\nxref:" nil t)
5636                    (nnheader-header-value)))
5637             ;; Extra.
5638             (when gnus-extra-headers
5639               (let ((extra gnus-extra-headers)
5640                     out)
5641                 (while extra
5642                   (goto-char p)
5643                   (when (search-forward
5644                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5645                     (push (cons (car extra) (nnheader-header-value))
5646                           out))
5647                   (pop extra))
5648                 out))))
5649           (when (equal id ref)
5650             (setq ref nil))
5651
5652           (when gnus-alter-header-function
5653             (funcall gnus-alter-header-function header)
5654             (setq id (mail-header-id header)
5655                   ref (gnus-parent-id (mail-header-references header))))
5656
5657           (when (setq header
5658                       (gnus-dependencies-add-header
5659                        header dependencies force-new))
5660             (push header headers))
5661           (goto-char (point-max))
5662           (widen))
5663         (nreverse headers)))))
5664
5665 ;; Goes through the xover lines and returns a list of vectors
5666 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5667                                                   force-new dependencies
5668                                                   group also-fetch-heads)
5669   "Parse the news overview data in the server buffer.
5670 Return a list of headers that match SEQUENCE (see
5671 `nntp-retrieve-headers')."
5672   ;; Get the Xref when the users reads the articles since most/some
5673   ;; NNTP servers do not include Xrefs when using XOVER.
5674   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5675   (let ((mail-parse-charset gnus-newsgroup-charset)
5676         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5677         (cur nntp-server-buffer)
5678         (dependencies (or dependencies gnus-newsgroup-dependencies))
5679         (allp (cond
5680                ((eq gnus-read-all-available-headers t)
5681                 t)
5682                ((stringp gnus-read-all-available-headers)
5683                 (string-match gnus-read-all-available-headers group))
5684                (t
5685                 nil)))
5686         number headers header)
5687     (save-excursion
5688       (set-buffer nntp-server-buffer)
5689       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5690       ;; Allow the user to mangle the headers before parsing them.
5691       (gnus-run-hooks 'gnus-parse-headers-hook)
5692       (goto-char (point-min))
5693       (gnus-parse-without-error
5694         (while (and (or sequence allp)
5695                     (not (eobp)))
5696           (setq number (read cur))
5697           (when (not allp)
5698             (while (and sequence
5699                         (< (car sequence) number))
5700               (setq sequence (cdr sequence))))
5701           (when (and (or allp
5702                          (and sequence
5703                               (eq number (car sequence))))
5704                      (progn
5705                        (setq sequence (cdr sequence))
5706                        (setq header (inline
5707                                       (gnus-nov-parse-line
5708                                        number dependencies force-new)))))
5709             (push header headers))
5710           (forward-line 1)))
5711       ;; A common bug in inn is that if you have posted an article and
5712       ;; then retrieves the active file, it will answer correctly --
5713       ;; the new article is included.  However, a NOV entry for the
5714       ;; article may not have been generated yet, so this may fail.
5715       ;; We work around this problem by retrieving the last few
5716       ;; headers using HEAD.
5717       (if (or (not also-fetch-heads)
5718               (not sequence))
5719           ;; We (probably) got all the headers.
5720           (nreverse headers)
5721         (let ((gnus-nov-is-evil t))
5722           (nconc
5723            (nreverse headers)
5724            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5725              (gnus-get-newsgroup-headers))))))))
5726
5727 (defun gnus-article-get-xrefs ()
5728   "Fill in the Xref value in `gnus-current-headers', if necessary.
5729 This is meant to be called in `gnus-article-internal-prepare-hook'."
5730   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5731                                  gnus-current-headers)))
5732     (or (not gnus-use-cross-reference)
5733         (not headers)
5734         (and (mail-header-xref headers)
5735              (not (string= (mail-header-xref headers) "")))
5736         (let ((case-fold-search t)
5737               xref)
5738           (save-restriction
5739             (nnheader-narrow-to-headers)
5740             (goto-char (point-min))
5741             (when (or (and (not (eobp))
5742                            (eq (downcase (char-after)) ?x)
5743                            (looking-at "Xref:"))
5744                       (search-forward "\nXref:" nil t))
5745               (goto-char (1+ (match-end 0)))
5746               (setq xref (buffer-substring (point)
5747                                            (progn (end-of-line) (point))))
5748               (mail-header-set-xref headers xref)))))))
5749
5750 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5751   "Find article ID and insert the summary line for that article.
5752 OLD-HEADER can either be a header or a line number to insert
5753 the subject line on."
5754   (let* ((line (and (numberp old-header) old-header))
5755          (old-header (and (vectorp old-header) old-header))
5756          (header (cond ((and old-header use-old-header)
5757                         old-header)
5758                        ((and (numberp id)
5759                              (gnus-number-to-header id))
5760                         (gnus-number-to-header id))
5761                        (t
5762                         (gnus-read-header id))))
5763          (number (and (numberp id) id))
5764          d)
5765     (when header
5766       ;; Rebuild the thread that this article is part of and go to the
5767       ;; article we have fetched.
5768       (when (and (not gnus-show-threads)
5769                  old-header)
5770         (when (and number
5771                    (setq d (gnus-data-find (mail-header-number old-header))))
5772           (goto-char (gnus-data-pos d))
5773           (gnus-data-remove
5774            number
5775            (- (gnus-point-at-bol)
5776               (prog1
5777                   (1+ (gnus-point-at-eol))
5778                 (gnus-delete-line))))))
5779       (when old-header
5780         (mail-header-set-number header (mail-header-number old-header)))
5781       (setq gnus-newsgroup-sparse
5782             (delq (setq number (mail-header-number header))
5783                   gnus-newsgroup-sparse))
5784       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5785       (push number gnus-newsgroup-limit)
5786       (gnus-rebuild-thread (mail-header-id header) line)
5787       (gnus-summary-goto-subject number nil t))
5788     (when (and (numberp number)
5789                (> number 0))
5790       ;; We have to update the boundaries even if we can't fetch the
5791       ;; article if ID is a number -- so that the next `P' or `N'
5792       ;; command will fetch the previous (or next) article even
5793       ;; if the one we tried to fetch this time has been canceled.
5794       (when (> number gnus-newsgroup-end)
5795         (setq gnus-newsgroup-end number))
5796       (when (< number gnus-newsgroup-begin)
5797         (setq gnus-newsgroup-begin number))
5798       (setq gnus-newsgroup-unselected
5799             (delq number gnus-newsgroup-unselected)))
5800     ;; Report back a success?
5801     (and header (mail-header-number header))))
5802
5803 ;;; Process/prefix in the summary buffer
5804
5805 (defun gnus-summary-work-articles (n)
5806   "Return a list of articles to be worked upon.
5807 The prefix argument, the list of process marked articles, and the
5808 current article will be taken into consideration."
5809   (save-excursion
5810     (set-buffer gnus-summary-buffer)
5811     (cond
5812      (n
5813       ;; A numerical prefix has been given.
5814       (setq n (prefix-numeric-value n))
5815       (let ((backward (< n 0))
5816             (n (abs (prefix-numeric-value n)))
5817             articles article)
5818         (save-excursion
5819           (while
5820               (and (> n 0)
5821                    (push (setq article (gnus-summary-article-number))
5822                          articles)
5823                    (if backward
5824                        (gnus-summary-find-prev nil article)
5825                      (gnus-summary-find-next nil article)))
5826             (decf n)))
5827         (nreverse articles)))
5828      ((and (gnus-region-active-p) (mark))
5829       (message "region active")
5830       ;; Work on the region between point and mark.
5831       (let ((max (max (point) (mark)))
5832             articles article)
5833         (save-excursion
5834           (goto-char (min (min (point) (mark))))
5835           (while
5836               (and
5837                (push (setq article (gnus-summary-article-number)) articles)
5838                (gnus-summary-find-next nil article)
5839                (< (point) max)))
5840           (nreverse articles))))
5841      (gnus-newsgroup-processable
5842       ;; There are process-marked articles present.
5843       ;; Save current state.
5844       (gnus-summary-save-process-mark)
5845       ;; Return the list.
5846       (reverse gnus-newsgroup-processable))
5847      (t
5848       ;; Just return the current article.
5849       (list (gnus-summary-article-number))))))
5850
5851 (defmacro gnus-summary-iterate (arg &rest forms)
5852   "Iterate over the process/prefixed articles and do FORMS.
5853 ARG is the interactive prefix given to the command.  FORMS will be
5854 executed with point over the summary line of the articles."
5855   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5856     `(let ((,articles (gnus-summary-work-articles ,arg)))
5857        (while ,articles
5858          (gnus-summary-goto-subject (car ,articles))
5859          ,@forms
5860          (pop ,articles)))))
5861
5862 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5863 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5864
5865 (defun gnus-summary-save-process-mark ()
5866   "Push the current set of process marked articles on the stack."
5867   (interactive)
5868   (push (copy-sequence gnus-newsgroup-processable)
5869         gnus-newsgroup-process-stack))
5870
5871 (defun gnus-summary-kill-process-mark ()
5872   "Push the current set of process marked articles on the stack and unmark."
5873   (interactive)
5874   (gnus-summary-save-process-mark)
5875   (gnus-summary-unmark-all-processable))
5876
5877 (defun gnus-summary-yank-process-mark ()
5878   "Pop the last process mark state off the stack and restore it."
5879   (interactive)
5880   (unless gnus-newsgroup-process-stack
5881     (error "Empty mark stack"))
5882   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5883
5884 (defun gnus-summary-process-mark-set (set)
5885   "Make SET into the current process marked articles."
5886   (gnus-summary-unmark-all-processable)
5887   (while set
5888     (gnus-summary-set-process-mark (pop set))))
5889
5890 ;;; Searching and stuff
5891
5892 (defun gnus-summary-search-group (&optional backward use-level)
5893   "Search for next unread newsgroup.
5894 If optional argument BACKWARD is non-nil, search backward instead."
5895   (save-excursion
5896     (set-buffer gnus-group-buffer)
5897     (when (gnus-group-search-forward
5898            backward nil (if use-level (gnus-group-group-level) nil))
5899       (gnus-group-group-name))))
5900
5901 (defun gnus-summary-best-group (&optional exclude-group)
5902   "Find the name of the best unread group.
5903 If EXCLUDE-GROUP, do not go to this group."
5904   (save-excursion
5905     (set-buffer gnus-group-buffer)
5906     (save-excursion
5907       (gnus-group-best-unread-group exclude-group))))
5908
5909 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5910   (if backward (gnus-summary-find-prev)
5911     (let* ((dummy (gnus-summary-article-intangible-p))
5912            (article (or article (gnus-summary-article-number)))
5913            (arts (gnus-data-find-list article))
5914            result)
5915       (when (and (not dummy)
5916                  (or (not gnus-summary-check-current)
5917                      (not unread)
5918                      (not (gnus-data-unread-p (car arts)))))
5919         (setq arts (cdr arts)))
5920       (when (setq result
5921                   (if unread
5922                       (progn
5923                         (while arts
5924                           (when (or (and undownloaded
5925                                          (eq gnus-undownloaded-mark
5926                                              (gnus-data-mark (car arts))))
5927                                     (gnus-data-unread-p (car arts)))
5928                             (setq result (car arts)
5929                                   arts nil))
5930                           (setq arts (cdr arts)))
5931                         result)
5932                     (car arts)))
5933         (goto-char (gnus-data-pos result))
5934         (gnus-data-number result)))))
5935
5936 (defun gnus-summary-find-prev (&optional unread article)
5937   (let* ((eobp (eobp))
5938          (article (or article (gnus-summary-article-number)))
5939          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5940          result)
5941     (when (and (not eobp)
5942                (or (not gnus-summary-check-current)
5943                    (not unread)
5944                    (not (gnus-data-unread-p (car arts)))))
5945       (setq arts (cdr arts)))
5946     (when (setq result
5947                 (if unread
5948                     (progn
5949                       (while arts
5950                         (when (gnus-data-unread-p (car arts))
5951                           (setq result (car arts)
5952                                 arts nil))
5953                         (setq arts (cdr arts)))
5954                       result)
5955                   (car arts)))
5956       (goto-char (gnus-data-pos result))
5957       (gnus-data-number result))))
5958
5959 (defun gnus-summary-find-subject (subject &optional unread backward article)
5960   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5961          (article (or article (gnus-summary-article-number)))
5962          (articles (gnus-data-list backward))
5963          (arts (gnus-data-find-list article articles))
5964          result)
5965     (when (or (not gnus-summary-check-current)
5966               (not unread)
5967               (not (gnus-data-unread-p (car arts))))
5968       (setq arts (cdr arts)))
5969     (while arts
5970       (and (or (not unread)
5971                (gnus-data-unread-p (car arts)))
5972            (vectorp (gnus-data-header (car arts)))
5973            (gnus-subject-equal
5974             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5975            (setq result (car arts)
5976                  arts nil))
5977       (setq arts (cdr arts)))
5978     (and result
5979          (goto-char (gnus-data-pos result))
5980          (gnus-data-number result))))
5981
5982 (defun gnus-summary-search-forward (&optional unread subject backward)
5983   "Search forward for an article.
5984 If UNREAD, look for unread articles.  If SUBJECT, look for
5985 articles with that subject.  If BACKWARD, search backward instead."
5986   (cond (subject (gnus-summary-find-subject subject unread backward))
5987         (backward (gnus-summary-find-prev unread))
5988         (t (gnus-summary-find-next unread))))
5989
5990 (defun gnus-recenter (&optional n)
5991   "Center point in window and redisplay frame.
5992 Also do horizontal recentering."
5993   (interactive "P")
5994   (when (and gnus-auto-center-summary
5995              (not (eq gnus-auto-center-summary 'vertical)))
5996     (gnus-horizontal-recenter))
5997   (recenter n))
5998
5999 (defun gnus-summary-recenter ()
6000   "Center point in the summary window.
6001 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6002 displayed, no centering will be performed."
6003   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6004 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6005   (interactive)
6006   (let* ((top (cond ((< (window-height) 4) 0)
6007                     ((< (window-height) 7) 1)
6008                     (t (if (numberp gnus-auto-center-summary)
6009                            gnus-auto-center-summary
6010                          2))))
6011          (height (1- (window-height)))
6012          (bottom (save-excursion (goto-char (point-max))
6013                                  (forward-line (- height))
6014                                  (point)))
6015          (window (get-buffer-window (current-buffer))))
6016     ;; The user has to want it.
6017     (when gnus-auto-center-summary
6018       (when (get-buffer-window gnus-article-buffer)
6019         ;; Only do recentering when the article buffer is displayed,
6020       ;; Set the window start to either `bottom', which is the biggest
6021         ;; possible valid number, or the second line from the top,
6022         ;; whichever is the least.
6023         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6024           (if (> bottom top-pos)
6025               ;; Keep the second line from the top visible
6026               (set-window-start window top-pos t)
6027             ;; Try to keep the bottom line visible; if it's partially
6028             ;; obscured, either scroll one more line to make it fully
6029             ;; visible, or revert to using TOP-POS.
6030             (save-excursion
6031               (goto-char (point-max))
6032               (forward-line -1)
6033               (let ((last-line-start (point)))
6034                 (goto-char bottom)
6035                 (set-window-start window (point) t)
6036                 (when (not (pos-visible-in-window-p last-line-start window))
6037                   (forward-line 1)
6038                   (set-window-start window (min (point) top-pos) t)))))))
6039       ;; Do horizontal recentering while we're at it.
6040       (when (and (get-buffer-window (current-buffer) t)
6041                  (not (eq gnus-auto-center-summary 'vertical)))
6042         (let ((selected (selected-window)))
6043           (select-window (get-buffer-window (current-buffer) t))
6044           (gnus-summary-position-point)
6045           (gnus-horizontal-recenter)
6046           (select-window selected))))))
6047
6048 (defun gnus-summary-jump-to-group (newsgroup)
6049   "Move point to NEWSGROUP in group mode buffer."
6050   ;; Keep update point of group mode buffer if visible.
6051   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6052       (save-window-excursion
6053         ;; Take care of tree window mode.
6054         (when (get-buffer-window gnus-group-buffer)
6055           (pop-to-buffer gnus-group-buffer))
6056         (gnus-group-jump-to-group newsgroup))
6057     (save-excursion
6058       ;; Take care of tree window mode.
6059       (if (get-buffer-window gnus-group-buffer)
6060           (pop-to-buffer gnus-group-buffer)
6061         (set-buffer gnus-group-buffer))
6062       (gnus-group-jump-to-group newsgroup))))
6063
6064 ;; This function returns a list of article numbers based on the
6065 ;; difference between the ranges of read articles in this group and
6066 ;; the range of active articles.
6067 (defun gnus-list-of-unread-articles (group)
6068   (let* ((read (gnus-info-read (gnus-get-info group)))
6069          (active (or (gnus-active group) (gnus-activate-group group)))
6070          (last (cdr active))
6071          first nlast unread)
6072     ;; If none are read, then all are unread.
6073     (if (not read)
6074         (setq first (car active))
6075       ;; If the range of read articles is a single range, then the
6076       ;; first unread article is the article after the last read
6077       ;; article.  Sounds logical, doesn't it?
6078       (if (and (not (listp (cdr read)))
6079                (or (< (car read) (car active))
6080                    (progn (setq read (list read))
6081                           nil)))
6082           (setq first (max (car active) (1+ (cdr read))))
6083         ;; `read' is a list of ranges.
6084         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6085                                   (caar read)))
6086                   1)
6087           (setq first (car active)))
6088         (while read
6089           (when first
6090             (while (< first nlast)
6091               (push first unread)
6092               (setq first (1+ first))))
6093           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6094           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6095           (setq read (cdr read)))))
6096     ;; And add the last unread articles.
6097     (while (<= first last)
6098       (push first unread)
6099       (setq first (1+ first)))
6100     ;; Return the list of unread articles.
6101     (delq 0 (nreverse unread))))
6102
6103 (defun gnus-list-of-read-articles (group)
6104   "Return a list of unread, unticked and non-dormant articles."
6105   (let* ((info (gnus-get-info group))
6106          (marked (gnus-info-marks info))
6107          (active (gnus-active group)))
6108     (and info active
6109          (gnus-list-range-difference
6110           (gnus-list-range-difference
6111            (gnus-sorted-complement
6112             (gnus-uncompress-range active)
6113             (gnus-list-of-unread-articles group))
6114            (cdr (assq 'dormant marked)))
6115           (cdr (assq 'tick marked))))))
6116
6117 ;; Various summary commands
6118
6119 (defun gnus-summary-select-article-buffer ()
6120   "Reconfigure windows to show article buffer."
6121   (interactive)
6122   (if (not (gnus-buffer-live-p gnus-article-buffer))
6123       (error "There is no article buffer for this summary buffer")
6124     (gnus-configure-windows 'article)
6125     (select-window (get-buffer-window gnus-article-buffer))))
6126
6127 (defun gnus-summary-universal-argument (arg)
6128   "Perform any operation on all articles that are process/prefixed."
6129   (interactive "P")
6130   (let ((articles (gnus-summary-work-articles arg))
6131         func article)
6132     (if (eq
6133          (setq
6134           func
6135           (key-binding
6136            (read-key-sequence
6137             (substitute-command-keys
6138              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6139          'undefined)
6140         (gnus-error 1 "Undefined key")
6141       (save-excursion
6142         (while articles
6143           (gnus-summary-goto-subject (setq article (pop articles)))
6144           (let (gnus-newsgroup-processable)
6145             (command-execute func))
6146           (gnus-summary-remove-process-mark article)))))
6147   (gnus-summary-position-point))
6148
6149 (defun gnus-summary-toggle-truncation (&optional arg)
6150   "Toggle truncation of summary lines.
6151 With arg, turn line truncation on iff arg is positive."
6152   (interactive "P")
6153   (setq truncate-lines
6154         (if (null arg) (not truncate-lines)
6155           (> (prefix-numeric-value arg) 0)))
6156   (redraw-display))
6157
6158 (defun gnus-summary-reselect-current-group (&optional all rescan)
6159   "Exit and then reselect the current newsgroup.
6160 The prefix argument ALL means to select all articles."
6161   (interactive "P")
6162   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6163     (error "Ephemeral groups can't be reselected"))
6164   (let ((current-subject (gnus-summary-article-number))
6165         (group gnus-newsgroup-name))
6166     (setq gnus-newsgroup-begin nil)
6167     (gnus-summary-exit)
6168     ;; We have to adjust the point of group mode buffer because
6169     ;; point was moved to the next unread newsgroup by exiting.
6170     (gnus-summary-jump-to-group group)
6171     (when rescan
6172       (save-excursion
6173         (gnus-group-get-new-news-this-group 1)))
6174     (gnus-group-read-group all t)
6175     (gnus-summary-goto-subject current-subject nil t)))
6176
6177 (defun gnus-summary-rescan-group (&optional all)
6178   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6179   (interactive "P")
6180   (gnus-summary-reselect-current-group all t))
6181
6182 (defun gnus-summary-update-info (&optional non-destructive)
6183   (save-excursion
6184     (let ((group gnus-newsgroup-name))
6185       (when group
6186         (when gnus-newsgroup-kill-headers
6187           (setq gnus-newsgroup-killed
6188                 (gnus-compress-sequence
6189                  (gnus-sorted-union
6190                   (gnus-list-range-intersection
6191                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6192                   gnus-newsgroup-unreads)
6193                  t)))
6194         (unless (listp (cdr gnus-newsgroup-killed))
6195           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6196         (let ((headers gnus-newsgroup-headers))
6197           ;; Set the new ranges of read articles.
6198           (save-excursion
6199             (set-buffer gnus-group-buffer)
6200             (gnus-undo-force-boundary))
6201           (gnus-update-read-articles
6202            group (gnus-sorted-union
6203                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6204           ;; Set the current article marks.
6205           (let ((gnus-newsgroup-scored
6206                  (if (and (not gnus-save-score)
6207                           (not non-destructive))
6208                      nil
6209                    gnus-newsgroup-scored)))
6210             (save-excursion
6211               (gnus-update-marks)))
6212           ;; Do the cross-ref thing.
6213           (when gnus-use-cross-reference
6214             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6215           ;; Do not switch windows but change the buffer to work.
6216           (set-buffer gnus-group-buffer)
6217           (unless (gnus-ephemeral-group-p group)
6218             (gnus-group-update-group group)))))))
6219
6220 (defun gnus-summary-save-newsrc (&optional force)
6221   "Save the current number of read/marked articles in the dribble buffer.
6222 The dribble buffer will then be saved.
6223 If FORCE (the prefix), also save the .newsrc file(s)."
6224   (interactive "P")
6225   (gnus-summary-update-info t)
6226   (if force
6227       (gnus-save-newsrc-file)
6228     (gnus-dribble-save)))
6229
6230 (defun gnus-summary-exit (&optional temporary)
6231   "Exit reading current newsgroup, and then return to group selection mode.
6232 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6233   (interactive)
6234   (gnus-set-global-variables)
6235   (when (gnus-buffer-live-p gnus-article-buffer)
6236     (save-excursion
6237       (set-buffer gnus-article-buffer)
6238       (mm-destroy-parts gnus-article-mime-handles)
6239       ;; Set it to nil for safety reason.
6240       (setq gnus-article-mime-handle-alist nil)
6241       (setq gnus-article-mime-handles nil)))
6242   (gnus-kill-save-kill-buffer)
6243   (gnus-async-halt-prefetch)
6244   (let* ((group gnus-newsgroup-name)
6245          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6246          (mode major-mode)
6247          (group-point nil)
6248          (buf (current-buffer)))
6249     (unless quit-config
6250       ;; Do adaptive scoring, and possibly save score files.
6251       (when gnus-newsgroup-adaptive
6252         (gnus-score-adaptive))
6253       (when gnus-use-scoring
6254         (gnus-score-save)))
6255     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6256     ;; If we have several article buffers, we kill them at exit.
6257     (unless gnus-single-article-buffer
6258       (gnus-kill-buffer gnus-original-article-buffer)
6259       (setq gnus-article-current nil))
6260     (when gnus-use-cache
6261       (gnus-cache-possibly-remove-articles)
6262       (gnus-cache-save-buffers))
6263     (gnus-async-prefetch-remove-group group)
6264     (when gnus-suppress-duplicates
6265       (gnus-dup-enter-articles))
6266     (when gnus-use-trees
6267       (gnus-tree-close group))
6268     (when gnus-use-cache
6269       (gnus-cache-write-active))
6270     ;; Remove entries for this group.
6271     (nnmail-purge-split-history (gnus-group-real-name group))
6272     ;; Make all changes in this group permanent.
6273     (unless quit-config
6274       (gnus-run-hooks 'gnus-exit-group-hook)
6275       (gnus-summary-update-info))
6276     (gnus-close-group group)
6277     ;; Make sure where we were, and go to next newsgroup.
6278     (set-buffer gnus-group-buffer)
6279     (unless quit-config
6280       (gnus-group-jump-to-group group))
6281     (gnus-run-hooks 'gnus-summary-exit-hook)
6282     (unless (or quit-config
6283                 ;; If this group has disappeared from the summary
6284                 ;; buffer, don't skip forwards.
6285                 (not (string= group (gnus-group-group-name))))
6286       (gnus-group-next-unread-group 1))
6287     (setq group-point (point))
6288     (if temporary
6289         nil                             ;Nothing to do.
6290       ;; If we have several article buffers, we kill them at exit.
6291       (unless gnus-single-article-buffer
6292         (gnus-kill-buffer gnus-article-buffer)
6293         (gnus-kill-buffer gnus-original-article-buffer)
6294         (setq gnus-article-current nil))
6295       (set-buffer buf)
6296       (if (not gnus-kill-summary-on-exit)
6297           (progn
6298             (gnus-deaden-summary)
6299             (setq mode nil))
6300        ;; We set all buffer-local variables to nil.  It is unclear why
6301         ;; this is needed, but if we don't, buffer-local variables are
6302         ;; not garbage-collected, it seems.  This would the lead to en
6303         ;; ever-growing Emacs.
6304         (gnus-summary-clear-local-variables)
6305         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6306           (gnus-summary-clear-local-variables))
6307         (when (get-buffer gnus-article-buffer)
6308           (bury-buffer gnus-article-buffer))
6309         ;; We clear the global counterparts of the buffer-local
6310         ;; variables as well, just to be on the safe side.
6311         (set-buffer gnus-group-buffer)
6312         (gnus-summary-clear-local-variables)
6313         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6314           (gnus-summary-clear-local-variables)))
6315       (setq gnus-current-select-method gnus-select-method)
6316       (pop-to-buffer gnus-group-buffer)
6317       (if (not quit-config)
6318           (progn
6319             (goto-char group-point)
6320             (gnus-configure-windows 'group 'force))
6321         (gnus-handle-ephemeral-exit quit-config))
6322       ;; Return to group mode buffer.
6323       (when (eq mode 'gnus-summary-mode)
6324         (gnus-kill-buffer buf))
6325       ;; Clear the current group name.
6326       (unless quit-config
6327         (setq gnus-newsgroup-name nil)))))
6328
6329 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6330 (defun gnus-summary-exit-no-update (&optional no-questions)
6331   "Quit reading current newsgroup without updating read article info."
6332   (interactive)
6333   (let* ((group gnus-newsgroup-name)
6334          (quit-config (gnus-group-quit-config group)))
6335     (when (or no-questions
6336               gnus-expert-user
6337               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6338       (gnus-async-halt-prefetch)
6339       (mapcar 'funcall
6340               (delq 'gnus-summary-expire-articles
6341                     (copy-sequence gnus-summary-prepare-exit-hook)))
6342       (when (gnus-buffer-live-p gnus-article-buffer)
6343         (save-excursion
6344           (set-buffer gnus-article-buffer)
6345           (mm-destroy-parts gnus-article-mime-handles)
6346           ;; Set it to nil for safety reason.
6347           (setq gnus-article-mime-handle-alist nil)
6348           (setq gnus-article-mime-handles nil)))
6349       ;; If we have several article buffers, we kill them at exit.
6350       (unless gnus-single-article-buffer
6351         (gnus-kill-buffer gnus-article-buffer)
6352         (gnus-kill-buffer gnus-original-article-buffer)
6353         (setq gnus-article-current nil))
6354       (if (not gnus-kill-summary-on-exit)
6355           (gnus-deaden-summary)
6356         (gnus-close-group group)
6357         (gnus-summary-clear-local-variables)
6358         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6359           (gnus-summary-clear-local-variables))
6360         (set-buffer gnus-group-buffer)
6361         (gnus-summary-clear-local-variables)
6362         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6363           (gnus-summary-clear-local-variables))
6364         (when (get-buffer gnus-summary-buffer)
6365           (kill-buffer gnus-summary-buffer)))
6366       (unless gnus-single-article-buffer
6367         (setq gnus-article-current nil))
6368       (when gnus-use-trees
6369         (gnus-tree-close group))
6370       (gnus-async-prefetch-remove-group group)
6371       (when (get-buffer gnus-article-buffer)
6372         (bury-buffer gnus-article-buffer))
6373       ;; Return to the group buffer.
6374       (gnus-configure-windows 'group 'force)
6375       ;; Clear the current group name.
6376       (setq gnus-newsgroup-name nil)
6377       (when (equal (gnus-group-group-name) group)
6378         (gnus-group-next-unread-group 1))
6379       (when quit-config
6380         (gnus-handle-ephemeral-exit quit-config)))))
6381
6382 (defun gnus-handle-ephemeral-exit (quit-config)
6383   "Handle movement when leaving an ephemeral group.
6384 The state which existed when entering the ephemeral is reset."
6385   (if (not (buffer-name (car quit-config)))
6386       (gnus-configure-windows 'group 'force)
6387     (set-buffer (car quit-config))
6388     (cond ((eq major-mode 'gnus-summary-mode)
6389            (gnus-set-global-variables))
6390           ((eq major-mode 'gnus-article-mode)
6391            (save-excursion
6392              ;; The `gnus-summary-buffer' variable may point
6393              ;; to the old summary buffer when using a single
6394              ;; article buffer.
6395              (unless (gnus-buffer-live-p gnus-summary-buffer)
6396                (set-buffer gnus-group-buffer))
6397              (set-buffer gnus-summary-buffer)
6398              (gnus-set-global-variables))))
6399     (if (or (eq (cdr quit-config) 'article)
6400             (eq (cdr quit-config) 'pick))
6401         (progn
6402           ;; The current article may be from the ephemeral group
6403           ;; thus it is best that we reload this article
6404           (gnus-summary-show-article)
6405           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6406               (gnus-configure-windows 'pick 'force)
6407             (gnus-configure-windows (cdr quit-config) 'force)))
6408       (gnus-configure-windows (cdr quit-config) 'force))
6409     (when (eq major-mode 'gnus-summary-mode)
6410       (gnus-summary-next-subject 1 nil t)
6411       (gnus-summary-recenter)
6412       (gnus-summary-position-point))))
6413
6414 ;;; Dead summaries.
6415
6416 (defvar gnus-dead-summary-mode-map nil)
6417
6418 (unless gnus-dead-summary-mode-map
6419   (setq gnus-dead-summary-mode-map (make-keymap))
6420   (suppress-keymap gnus-dead-summary-mode-map)
6421   (substitute-key-definition
6422    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6423   (dolist (key '("\C-d" "\r" "\177" [delete]))
6424     (define-key gnus-dead-summary-mode-map
6425       key 'gnus-summary-wake-up-the-dead))
6426   (dolist (key '("q" "Q"))
6427     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6428
6429 (defvar gnus-dead-summary-mode nil
6430   "Minor mode for Gnus summary buffers.")
6431
6432 (defun gnus-dead-summary-mode (&optional arg)
6433   "Minor mode for Gnus summary buffers."
6434   (interactive "P")
6435   (when (eq major-mode 'gnus-summary-mode)
6436     (make-local-variable 'gnus-dead-summary-mode)
6437     (setq gnus-dead-summary-mode
6438           (if (null arg) (not gnus-dead-summary-mode)
6439             (> (prefix-numeric-value arg) 0)))
6440     (when gnus-dead-summary-mode
6441       (gnus-add-minor-mode
6442        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6443
6444 (defun gnus-deaden-summary ()
6445   "Make the current summary buffer into a dead summary buffer."
6446   ;; Kill any previous dead summary buffer.
6447   (when (and gnus-dead-summary
6448              (buffer-name gnus-dead-summary))
6449     (save-excursion
6450       (set-buffer gnus-dead-summary)
6451       (when gnus-dead-summary-mode
6452         (kill-buffer (current-buffer)))))
6453   ;; Make this the current dead summary.
6454   (setq gnus-dead-summary (current-buffer))
6455   (gnus-dead-summary-mode 1)
6456   (let ((name (buffer-name)))
6457     (when (string-match "Summary" name)
6458       (rename-buffer
6459        (concat (substring name 0 (match-beginning 0)) "Dead "
6460                (substring name (match-beginning 0)))
6461        t)
6462       (bury-buffer))))
6463
6464 (defun gnus-kill-or-deaden-summary (buffer)
6465   "Kill or deaden the summary BUFFER."
6466   (save-excursion
6467     (when (and (buffer-name buffer)
6468                (not gnus-single-article-buffer))
6469       (save-excursion
6470         (set-buffer buffer)
6471         (gnus-kill-buffer gnus-article-buffer)
6472         (gnus-kill-buffer gnus-original-article-buffer)))
6473     (cond
6474      ;; Kill the buffer.
6475      (gnus-kill-summary-on-exit
6476       (when (and gnus-use-trees
6477                  (gnus-buffer-exists-p buffer))
6478         (save-excursion
6479           (set-buffer buffer)
6480           (gnus-tree-close gnus-newsgroup-name)))
6481       (gnus-kill-buffer buffer))
6482      ;; Deaden the buffer.
6483      ((gnus-buffer-exists-p buffer)
6484       (save-excursion
6485         (set-buffer buffer)
6486         (gnus-deaden-summary))))))
6487
6488 (defun gnus-summary-wake-up-the-dead (&rest args)
6489   "Wake up the dead summary buffer."
6490   (interactive)
6491   (gnus-dead-summary-mode -1)
6492   (let ((name (buffer-name)))
6493     (when (string-match "Dead " name)
6494       (rename-buffer
6495        (concat (substring name 0 (match-beginning 0))
6496                (substring name (match-end 0)))
6497        t)))
6498   (gnus-message 3 "This dead summary is now alive again"))
6499
6500 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6501 (defun gnus-summary-fetch-faq (&optional faq-dir)
6502   "Fetch the FAQ for the current group.
6503 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6504 in."
6505   (interactive
6506    (list
6507     (when current-prefix-arg
6508       (completing-read
6509        "Faq dir: " (and (listp gnus-group-faq-directory)
6510                         (mapcar (lambda (file) (list file))
6511                                 gnus-group-faq-directory))))))
6512   (let (gnus-faq-buffer)
6513     (when (setq gnus-faq-buffer
6514                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6515       (gnus-configure-windows 'summary-faq))))
6516
6517 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6518 (defun gnus-summary-describe-group (&optional force)
6519   "Describe the current newsgroup."
6520   (interactive "P")
6521   (gnus-group-describe-group force gnus-newsgroup-name))
6522
6523 (defun gnus-summary-describe-briefly ()
6524   "Describe summary mode commands briefly."
6525   (interactive)
6526   (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")))
6527
6528 ;; Walking around group mode buffer from summary mode.
6529
6530 (defun gnus-summary-next-group (&optional no-article target-group backward)
6531   "Exit current newsgroup and then select next unread newsgroup.
6532 If prefix argument NO-ARTICLE is non-nil, no article is selected
6533 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6534 previous group instead."
6535   (interactive "P")
6536   ;; Stop pre-fetching.
6537   (gnus-async-halt-prefetch)
6538   (let ((current-group gnus-newsgroup-name)
6539         (current-buffer (current-buffer))
6540         entered)
6541     (while (not entered)
6542       ;; Then we find what group we are supposed to enter.
6543       (set-buffer gnus-group-buffer)
6544       (gnus-group-jump-to-group current-group)
6545       (setq target-group
6546             (or target-group
6547                 (if (eq gnus-keep-same-level 'best)
6548                     (gnus-summary-best-group gnus-newsgroup-name)
6549                   (gnus-summary-search-group backward gnus-keep-same-level))))
6550       (if (not target-group)
6551           ;; There are no further groups, so we return to the group
6552           ;; buffer.
6553           (progn
6554             (gnus-message 5 "Returning to the group buffer")
6555             (setq entered t)
6556             (when (gnus-buffer-live-p current-buffer)
6557               (set-buffer current-buffer)
6558               (gnus-summary-exit))
6559             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6560         ;; We try to enter the target group.
6561         (gnus-group-jump-to-group target-group)
6562         (let ((unreads (gnus-group-group-unread)))
6563           (if (and (or (eq t unreads)
6564                        (and unreads (not (zerop unreads))))
6565                    (progn
6566                      ;; Now we semi-exit this group to update Xrefs
6567                      ;; and all variables.  We can't do a real exit,
6568                      ;; because the window conf must remain the same
6569                      ;; in case the user is prompted for info, and we
6570                      ;; don't want the window conf to change before
6571                      ;; that...
6572                      (when (gnus-buffer-live-p current-buffer)
6573                        (set-buffer current-buffer)
6574                        (gnus-summary-exit t))
6575                      (gnus-summary-read-group
6576                       target-group nil no-article
6577                       (and (buffer-name current-buffer) current-buffer)
6578                       nil backward)))
6579               (setq entered t)
6580             (setq current-group target-group
6581                   target-group nil)))))))
6582
6583 (defun gnus-summary-prev-group (&optional no-article)
6584   "Exit current newsgroup and then select previous unread newsgroup.
6585 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6586   (interactive "P")
6587   (gnus-summary-next-group no-article nil t))
6588
6589 ;; Walking around summary lines.
6590
6591 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6592   "Go to the first unread subject.
6593 If UNREAD is non-nil, go to the first unread article.
6594 Returns the article selected or nil if there are no unread articles."
6595   (interactive "P")
6596   (prog1
6597       (cond
6598        ;; Empty summary.
6599        ((null gnus-newsgroup-data)
6600         (gnus-message 3 "No articles in the group")
6601         nil)
6602        ;; Pick the first article.
6603        ((not unread)
6604         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6605         (gnus-data-number (car gnus-newsgroup-data)))
6606        ;; No unread articles.
6607        ((null gnus-newsgroup-unreads)
6608         (gnus-message 3 "No more unread articles")
6609         nil)
6610        ;; Find the first unread article.
6611        (t
6612         (let ((data gnus-newsgroup-data))
6613           (while (and data
6614                       (and (not (and undownloaded
6615                                      (eq gnus-undownloaded-mark
6616                                          (gnus-data-mark (car data)))))
6617                            (if unseen
6618                                (or (not (memq
6619                                          (gnus-data-number (car data))
6620                                          gnus-newsgroup-unseen))
6621                                    (not (gnus-data-unread-p (car data))))
6622                              (not (gnus-data-unread-p (car data))))))
6623             (setq data (cdr data)))
6624           (when data
6625             (goto-char (gnus-data-pos (car data)))
6626             (gnus-data-number (car data))))))
6627     (gnus-summary-position-point)))
6628
6629 (defun gnus-summary-next-subject (n &optional unread dont-display)
6630   "Go to next N'th summary line.
6631 If N is negative, go to the previous N'th subject line.
6632 If UNREAD is non-nil, only unread articles are selected.
6633 The difference between N and the actual number of steps taken is
6634 returned."
6635   (interactive "p")
6636   (let ((backward (< n 0))
6637         (n (abs n)))
6638     (while (and (> n 0)
6639                 (if backward
6640                     (gnus-summary-find-prev unread)
6641                   (gnus-summary-find-next unread)))
6642       (unless (zerop (setq n (1- n)))
6643         (gnus-summary-show-thread)))
6644     (when (/= 0 n)
6645       (gnus-message 7 "No more%s articles"
6646                     (if unread " unread" "")))
6647     (unless dont-display
6648       (gnus-summary-recenter)
6649       (gnus-summary-position-point))
6650     n))
6651
6652 (defun gnus-summary-next-unread-subject (n)
6653   "Go to next N'th unread summary line."
6654   (interactive "p")
6655   (gnus-summary-next-subject n t))
6656
6657 (defun gnus-summary-prev-subject (n &optional unread)
6658   "Go to previous N'th summary line.
6659 If optional argument UNREAD is non-nil, only unread article is selected."
6660   (interactive "p")
6661   (gnus-summary-next-subject (- n) unread))
6662
6663 (defun gnus-summary-prev-unread-subject (n)
6664   "Go to previous N'th unread summary line."
6665   (interactive "p")
6666   (gnus-summary-next-subject (- n) t))
6667
6668 (defun gnus-summary-goto-subject (article &optional force silent)
6669   "Go the subject line of ARTICLE.
6670 If FORCE, also allow jumping to articles not currently shown."
6671   (interactive "nArticle number: ")
6672   (unless (numberp article)
6673     (error "Article %s is not a number" article))
6674   (let ((b (point))
6675         (data (gnus-data-find article)))
6676     ;; We read in the article if we have to.
6677     (and (not data)
6678          force
6679          (gnus-summary-insert-subject
6680           article
6681           (if (or (numberp force) (vectorp force)) force)
6682           t)
6683          (setq data (gnus-data-find article)))
6684     (goto-char b)
6685     (if (not data)
6686         (progn
6687           (unless silent
6688             (gnus-message 3 "Can't find article %d" article))
6689           nil)
6690       (let ((pt (gnus-data-pos data)))
6691         (goto-char pt)
6692         (gnus-summary-set-article-display-arrow pt))
6693       (gnus-summary-position-point)
6694       article)))
6695
6696 ;; Walking around summary lines with displaying articles.
6697
6698 (defun gnus-summary-expand-window (&optional arg)
6699   "Make the summary buffer take up the entire Emacs frame.
6700 Given a prefix, will force an `article' buffer configuration."
6701   (interactive "P")
6702   (if arg
6703       (gnus-configure-windows 'article 'force)
6704     (gnus-configure-windows 'summary 'force)))
6705
6706 (defun gnus-summary-display-article (article &optional all-header)
6707   "Display ARTICLE in article buffer."
6708   (when (gnus-buffer-live-p gnus-article-buffer)
6709     (with-current-buffer gnus-article-buffer
6710       (mm-enable-multibyte)))
6711   (gnus-set-global-variables)
6712   (when (gnus-buffer-live-p gnus-article-buffer)
6713     (with-current-buffer gnus-article-buffer
6714       (setq gnus-article-charset gnus-newsgroup-charset)
6715       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6716       (mm-enable-multibyte)))
6717   (if (null article)
6718       nil
6719     (prog1
6720         (if gnus-summary-display-article-function
6721             (funcall gnus-summary-display-article-function article all-header)
6722           (gnus-article-prepare article all-header))
6723       (gnus-run-hooks 'gnus-select-article-hook)
6724       (when (and gnus-current-article
6725                  (not (zerop gnus-current-article)))
6726         (gnus-summary-goto-subject gnus-current-article))
6727       (gnus-summary-recenter)
6728       (when (and gnus-use-trees gnus-show-threads)
6729         (gnus-possibly-generate-tree article)
6730         (gnus-highlight-selected-tree article))
6731       ;; Successfully display article.
6732       (gnus-article-set-window-start
6733        (cdr (assq article gnus-newsgroup-bookmarks))))))
6734
6735 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6736   "Select the current article.
6737 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6738 non-nil, the article will be re-fetched even if it already present in
6739 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6740 be displayed."
6741   ;; Make sure we are in the summary buffer to work around bbdb bug.
6742   (unless (eq major-mode 'gnus-summary-mode)
6743     (set-buffer gnus-summary-buffer))
6744   (let ((article (or article (gnus-summary-article-number)))
6745         (all-headers (not (not all-headers))) ;Must be t or nil.
6746         gnus-summary-display-article-function)
6747     (and (not pseudo)
6748          (gnus-summary-article-pseudo-p article)
6749          (error "This is a pseudo-article"))
6750     (save-excursion
6751       (set-buffer gnus-summary-buffer)
6752       (if (or (and gnus-single-article-buffer
6753                    (or (null gnus-current-article)
6754                        (null gnus-article-current)
6755                        (null (get-buffer gnus-article-buffer))
6756                        (not (eq article (cdr gnus-article-current)))
6757                        (not (equal (car gnus-article-current)
6758                                    gnus-newsgroup-name))))
6759               (and (not gnus-single-article-buffer)
6760                    (or (null gnus-current-article)
6761                        (not (eq gnus-current-article article))))
6762               force)
6763           ;; The requested article is different from the current article.
6764           (progn
6765             (gnus-summary-display-article article all-headers)
6766             (when (gnus-buffer-live-p gnus-article-buffer)
6767               (with-current-buffer gnus-article-buffer
6768                 (if (not gnus-article-decoded-p) ;; a local variable
6769                     (mm-disable-multibyte))))
6770             (gnus-article-set-window-start
6771              (cdr (assq article gnus-newsgroup-bookmarks)))
6772             article)
6773         'old))))
6774
6775 (defun gnus-summary-force-verify-and-decrypt ()
6776   (interactive)
6777   (let ((mm-verify-option 'known)
6778         (mm-decrypt-option 'known)
6779         (gnus-buttonized-mime-types (append (list "multipart/signed"
6780                                                   "multipart/encrypted")
6781                                             gnus-buttonized-mime-types)))
6782     (gnus-summary-select-article nil 'force)))
6783
6784 (defun gnus-summary-set-current-mark (&optional current-mark)
6785   "Obsolete function."
6786   nil)
6787
6788 (defun gnus-summary-next-article (&optional unread subject backward push)
6789   "Select the next article.
6790 If UNREAD, only unread articles are selected.
6791 If SUBJECT, only articles with SUBJECT are selected.
6792 If BACKWARD, the previous article is selected instead of the next."
6793   (interactive "P")
6794   (cond
6795    ;; Is there such an article?
6796    ((and (gnus-summary-search-forward unread subject backward)
6797          (or (gnus-summary-display-article (gnus-summary-article-number))
6798              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6799     (gnus-summary-position-point))
6800    ;; If not, we try the first unread, if that is wanted.
6801    ((and subject
6802          gnus-auto-select-same
6803          (gnus-summary-first-unread-article))
6804     (gnus-summary-position-point)
6805     (gnus-message 6 "Wrapped"))
6806    ;; Try to get next/previous article not displayed in this group.
6807    ((and gnus-auto-extend-newsgroup
6808          (not unread) (not subject))
6809     (gnus-summary-goto-article
6810      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6811      nil (count-lines (point-min) (point))))
6812    ;; Go to next/previous group.
6813    (t
6814     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6815       (gnus-summary-jump-to-group gnus-newsgroup-name))
6816     (let ((cmd last-command-char)
6817           (point
6818            (save-excursion
6819              (set-buffer gnus-group-buffer)
6820              (point)))
6821           (group
6822            (if (eq gnus-keep-same-level 'best)
6823                (gnus-summary-best-group gnus-newsgroup-name)
6824              (gnus-summary-search-group backward gnus-keep-same-level))))
6825       ;; For some reason, the group window gets selected.  We change
6826       ;; it back.
6827       (select-window (get-buffer-window (current-buffer)))
6828       ;; Select next unread newsgroup automagically.
6829       (cond
6830        ((or (not gnus-auto-select-next)
6831             (not cmd))
6832         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6833        ((or (eq gnus-auto-select-next 'quietly)
6834             (and (eq gnus-auto-select-next 'slightly-quietly)
6835                  push)
6836             (and (eq gnus-auto-select-next 'almost-quietly)
6837                  (gnus-summary-last-article-p)))
6838         ;; Select quietly.
6839         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6840             (gnus-summary-exit)
6841           (gnus-message 7 "No more%s articles (%s)..."
6842                         (if unread " unread" "")
6843                         (if group (concat "selecting " group)
6844                           "exiting"))
6845           (gnus-summary-next-group nil group backward)))
6846        (t
6847         (when (gnus-key-press-event-p last-input-event)
6848           (gnus-summary-walk-group-buffer
6849            gnus-newsgroup-name cmd unread backward point))))))))
6850
6851 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6852   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6853                       (?\C-p (gnus-group-prev-unread-group 1))))
6854         (cursor-in-echo-area t)
6855         keve key group ended)
6856     (save-excursion
6857       (set-buffer gnus-group-buffer)
6858       (goto-char start)
6859       (setq group
6860             (if (eq gnus-keep-same-level 'best)
6861                 (gnus-summary-best-group gnus-newsgroup-name)
6862               (gnus-summary-search-group backward gnus-keep-same-level))))
6863     (while (not ended)
6864       (gnus-message
6865        5 "No more%s articles%s" (if unread " unread" "")
6866        (if (and group
6867                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6868            (format " (Type %s for %s [%s])"
6869                    (single-key-description cmd) group
6870                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6871          (format " (Type %s to exit %s)"
6872                  (single-key-description cmd)
6873                  gnus-newsgroup-name)))
6874       ;; Confirm auto selection.
6875       (setq key (car (setq keve (gnus-read-event-char))))
6876       (setq ended t)
6877       (cond
6878        ((assq key keystrokes)
6879         (let ((obuf (current-buffer)))
6880           (switch-to-buffer gnus-group-buffer)
6881           (when group
6882             (gnus-group-jump-to-group group))
6883           (eval (cadr (assq key keystrokes)))
6884           (setq group (gnus-group-group-name))
6885           (switch-to-buffer obuf))
6886         (setq ended nil))
6887        ((equal key cmd)
6888         (if (or (not group)
6889                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6890             (gnus-summary-exit)
6891           (gnus-summary-next-group nil group backward)))
6892        (t
6893         (push (cdr keve) unread-command-events))))))
6894
6895 (defun gnus-summary-next-unread-article ()
6896   "Select unread article after current one."
6897   (interactive)
6898   (gnus-summary-next-article
6899    (or (not (eq gnus-summary-goto-unread 'never))
6900        (gnus-summary-last-article-p (gnus-summary-article-number)))
6901    (and gnus-auto-select-same
6902         (gnus-summary-article-subject))))
6903
6904 (defun gnus-summary-prev-article (&optional unread subject)
6905   "Select the article after the current one.
6906 If UNREAD is non-nil, only unread articles are selected."
6907   (interactive "P")
6908   (gnus-summary-next-article unread subject t))
6909
6910 (defun gnus-summary-prev-unread-article ()
6911   "Select unread article before current one."
6912   (interactive)
6913   (gnus-summary-prev-article
6914    (or (not (eq gnus-summary-goto-unread 'never))
6915        (gnus-summary-first-article-p (gnus-summary-article-number)))
6916    (and gnus-auto-select-same
6917         (gnus-summary-article-subject))))
6918
6919 (defun gnus-summary-next-page (&optional lines circular)
6920   "Show next page of the selected article.
6921 If at the end of the current article, select the next article.
6922 LINES says how many lines should be scrolled up.
6923
6924 If CIRCULAR is non-nil, go to the start of the article instead of
6925 selecting the next article when reaching the end of the current
6926 article."
6927   (interactive "P")
6928   (setq gnus-summary-buffer (current-buffer))
6929   (gnus-set-global-variables)
6930   (let ((article (gnus-summary-article-number))
6931         (article-window (get-buffer-window gnus-article-buffer t))
6932         endp)
6933     ;; If the buffer is empty, we have no article.
6934     (unless article
6935       (error "No article to select"))
6936     (gnus-configure-windows 'article)
6937     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6938         (if (and (eq gnus-summary-goto-unread 'never)
6939                  (not (gnus-summary-last-article-p article)))
6940             (gnus-summary-next-article)
6941           (gnus-summary-next-unread-article))
6942       (if (or (null gnus-current-article)
6943               (null gnus-article-current)
6944               (/= article (cdr gnus-article-current))
6945               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6946           ;; Selected subject is different from current article's.
6947           (gnus-summary-display-article article)
6948         (when article-window
6949           (gnus-eval-in-buffer-window gnus-article-buffer
6950             (setq endp (gnus-article-next-page lines)))
6951           (when endp
6952             (cond (circular
6953                    (gnus-summary-beginning-of-article))
6954                   (lines
6955                    (gnus-message 3 "End of message"))
6956                   ((null lines)
6957                    (if (and (eq gnus-summary-goto-unread 'never)
6958                             (not (gnus-summary-last-article-p article)))
6959                        (gnus-summary-next-article)
6960                      (gnus-summary-next-unread-article))))))))
6961     (gnus-summary-recenter)
6962     (gnus-summary-position-point)))
6963
6964 (defun gnus-summary-prev-page (&optional lines move)
6965   "Show previous page of selected article.
6966 Argument LINES specifies lines to be scrolled down.
6967 If MOVE, move to the previous unread article if point is at
6968 the beginning of the buffer."
6969   (interactive "P")
6970   (let ((article (gnus-summary-article-number))
6971         (article-window (get-buffer-window gnus-article-buffer t))
6972         endp)
6973     (gnus-configure-windows 'article)
6974     (if (or (null gnus-current-article)
6975             (null gnus-article-current)
6976             (/= article (cdr gnus-article-current))
6977             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6978         ;; Selected subject is different from current article's.
6979         (gnus-summary-display-article article)
6980       (gnus-summary-recenter)
6981       (when article-window
6982         (gnus-eval-in-buffer-window gnus-article-buffer
6983           (setq endp (gnus-article-prev-page lines)))
6984         (when (and move endp)
6985           (cond (lines
6986                  (gnus-message 3 "Beginning of message"))
6987                 ((null lines)
6988                  (if (and (eq gnus-summary-goto-unread 'never)
6989                           (not (gnus-summary-first-article-p article)))
6990                      (gnus-summary-prev-article)
6991                    (gnus-summary-prev-unread-article))))))))
6992   (gnus-summary-position-point))
6993
6994 (defun gnus-summary-prev-page-or-article (&optional lines)
6995   "Show previous page of selected article.
6996 Argument LINES specifies lines to be scrolled down.
6997 If at the beginning of the article, go to the next article."
6998   (interactive "P")
6999   (gnus-summary-prev-page lines t))
7000
7001 (defun gnus-summary-scroll-up (lines)
7002   "Scroll up (or down) one line current article.
7003 Argument LINES specifies lines to be scrolled up (or down if negative)."
7004   (interactive "p")
7005   (gnus-configure-windows 'article)
7006   (gnus-summary-show-thread)
7007   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7008     (gnus-eval-in-buffer-window gnus-article-buffer
7009       (cond ((> lines 0)
7010              (when (gnus-article-next-page lines)
7011                (gnus-message 3 "End of message")))
7012             ((< lines 0)
7013              (gnus-article-prev-page (- lines))))))
7014   (gnus-summary-recenter)
7015   (gnus-summary-position-point))
7016
7017 (defun gnus-summary-scroll-down (lines)
7018   "Scroll down (or up) one line current article.
7019 Argument LINES specifies lines to be scrolled down (or up if negative)."
7020   (interactive "p")
7021   (gnus-summary-scroll-up (- lines)))
7022
7023 (defun gnus-summary-next-same-subject ()
7024   "Select next article which has the same subject as current one."
7025   (interactive)
7026   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7027
7028 (defun gnus-summary-prev-same-subject ()
7029   "Select previous article which has the same subject as current one."
7030   (interactive)
7031   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7032
7033 (defun gnus-summary-next-unread-same-subject ()
7034   "Select next unread article which has the same subject as current one."
7035   (interactive)
7036   (gnus-summary-next-article t (gnus-summary-article-subject)))
7037
7038 (defun gnus-summary-prev-unread-same-subject ()
7039   "Select previous unread article which has the same subject as current one."
7040   (interactive)
7041   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7042
7043 (defun gnus-summary-first-unread-article ()
7044   "Select the first unread article.
7045 Return nil if there are no unread articles."
7046   (interactive)
7047   (prog1
7048       (when (gnus-summary-first-subject t)
7049         (gnus-summary-show-thread)
7050         (gnus-summary-first-subject t)
7051         (gnus-summary-display-article (gnus-summary-article-number)))
7052     (gnus-summary-position-point)))
7053
7054 (defun gnus-summary-first-unread-subject ()
7055   "Place the point on the subject line of the first unread article.
7056 Return nil if there are no unread articles."
7057   (interactive)
7058   (prog1
7059       (when (gnus-summary-first-subject t)
7060         (gnus-summary-show-thread)
7061         (gnus-summary-first-subject t))
7062     (gnus-summary-position-point)))
7063
7064 (defun gnus-summary-first-unseen-subject ()
7065   "Place the point on the subject line of the first unseen article.
7066 Return nil if there are no unseen articles."
7067   (interactive)
7068   (prog1
7069       (when (gnus-summary-first-subject t t t)
7070         (gnus-summary-show-thread)
7071         (gnus-summary-first-subject t t t))
7072     (gnus-summary-position-point)))
7073
7074 (defun gnus-summary-first-unseen-or-unread-subject ()
7075   "Place the point on the subject line of the first unseen article.
7076 Return nil if there are no unseen articles."
7077   (interactive)
7078   (prog1
7079       (unless (when (gnus-summary-first-subject t t t)
7080                 (gnus-summary-show-thread)
7081                 (gnus-summary-first-subject t t t))
7082         (when (gnus-summary-first-subject t)
7083           (gnus-summary-show-thread)
7084           (gnus-summary-first-subject t)))
7085     (gnus-summary-position-point)))
7086
7087 (defun gnus-summary-first-article ()
7088   "Select the first article.
7089 Return nil if there are no articles."
7090   (interactive)
7091   (prog1
7092       (when (gnus-summary-first-subject)
7093         (gnus-summary-show-thread)
7094         (gnus-summary-first-subject)
7095         (gnus-summary-display-article (gnus-summary-article-number)))
7096     (gnus-summary-position-point)))
7097
7098 (defun gnus-summary-best-unread-article (&optional arg)
7099   "Select the unread article with the highest score.
7100 If given a prefix argument, select the next unread article that has a
7101 score higher than the default score."
7102   (interactive "P")
7103   (let ((article (if arg
7104                      (gnus-summary-better-unread-subject)
7105                    (gnus-summary-best-unread-subject))))
7106     (if article
7107         (gnus-summary-goto-article article)
7108       (error "No unread articles"))))
7109
7110 (defun gnus-summary-best-unread-subject ()
7111   "Select the unread subject with the highest score."
7112   (interactive)
7113   (let ((best -1000000)
7114         (data gnus-newsgroup-data)
7115         article score)
7116     (while data
7117       (and (gnus-data-unread-p (car data))
7118            (> (setq score
7119                     (gnus-summary-article-score (gnus-data-number (car data))))
7120               best)
7121            (setq best score
7122                  article (gnus-data-number (car data))))
7123       (setq data (cdr data)))
7124     (when article
7125       (gnus-summary-goto-subject article))
7126     (gnus-summary-position-point)
7127     article))
7128
7129 (defun gnus-summary-better-unread-subject ()
7130   "Select the first unread subject that has a score over the default score."
7131   (interactive)
7132   (let ((data gnus-newsgroup-data)
7133         article score)
7134     (while (and (setq article (gnus-data-number (car data)))
7135                 (or (gnus-data-read-p (car data))
7136                     (not (> (gnus-summary-article-score article)
7137                             gnus-summary-default-score))))
7138       (setq data (cdr data)))
7139     (when article
7140       (gnus-summary-goto-subject article))
7141     (gnus-summary-position-point)
7142     article))
7143
7144 (defun gnus-summary-last-subject ()
7145   "Go to the last displayed subject line in the group."
7146   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7147     (when article
7148       (gnus-summary-goto-subject article))))
7149
7150 (defun gnus-summary-goto-article (article &optional all-headers force)
7151   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7152 If ALL-HEADERS is non-nil, no header lines are hidden.
7153 If FORCE, go to the article even if it isn't displayed.  If FORCE
7154 is a number, it is the line the article is to be displayed on."
7155   (interactive
7156    (list
7157     (completing-read
7158      "Article number or Message-ID: "
7159      (mapcar (lambda (number) (list (int-to-string number)))
7160              gnus-newsgroup-limit))
7161     current-prefix-arg
7162     t))
7163   (prog1
7164       (if (and (stringp article)
7165                (string-match "@" article))
7166           (gnus-summary-refer-article article)
7167         (when (stringp article)
7168           (setq article (string-to-number article)))
7169         (if (gnus-summary-goto-subject article force)
7170             (gnus-summary-display-article article all-headers)
7171           (gnus-message 4 "Couldn't go to article %s" article) nil))
7172     (gnus-summary-position-point)))
7173
7174 (defun gnus-summary-goto-last-article ()
7175   "Go to the previously read article."
7176   (interactive)
7177   (prog1
7178       (when gnus-last-article
7179         (gnus-summary-goto-article gnus-last-article nil t))
7180     (gnus-summary-position-point)))
7181
7182 (defun gnus-summary-pop-article (number)
7183   "Pop one article off the history and go to the previous.
7184 NUMBER articles will be popped off."
7185   (interactive "p")
7186   (let (to)
7187     (setq gnus-newsgroup-history
7188           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7189     (if to
7190         (gnus-summary-goto-article (car to) nil t)
7191       (error "Article history empty")))
7192   (gnus-summary-position-point))
7193
7194 ;; Summary commands and functions for limiting the summary buffer.
7195
7196 (defun gnus-summary-limit-to-articles (n)
7197   "Limit the summary buffer to the next N articles.
7198 If not given a prefix, use the process marked articles instead."
7199   (interactive "P")
7200   (prog1
7201       (let ((articles (gnus-summary-work-articles n)))
7202         (setq gnus-newsgroup-processable nil)
7203         (gnus-summary-limit articles))
7204     (gnus-summary-position-point)))
7205
7206 (defun gnus-summary-pop-limit (&optional total)
7207   "Restore the previous limit.
7208 If given a prefix, remove all limits."
7209   (interactive "P")
7210   (when total
7211     (setq gnus-newsgroup-limits
7212           (list (mapcar (lambda (h) (mail-header-number h))
7213                         gnus-newsgroup-headers))))
7214   (unless gnus-newsgroup-limits
7215     (error "No limit to pop"))
7216   (prog1
7217       (gnus-summary-limit nil 'pop)
7218     (gnus-summary-position-point)))
7219
7220 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7221   "Limit the summary buffer to articles that have subjects that match a regexp.
7222 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7223   (interactive
7224    (list (read-string (if current-prefix-arg
7225                           "Exclude subject (regexp): "
7226                         "Limit to subject (regexp): "))
7227          nil current-prefix-arg))
7228   (unless header
7229     (setq header "subject"))
7230   (when (not (equal "" subject))
7231     (prog1
7232         (let ((articles (gnus-summary-find-matching
7233                          (or header "subject") subject 'all nil nil
7234                          not-matching)))
7235           (unless articles
7236             (error "Found no matches for \"%s\"" subject))
7237           (gnus-summary-limit articles))
7238       (gnus-summary-position-point))))
7239
7240 (defun gnus-summary-limit-to-author (from &optional not-matching)
7241   "Limit the summary buffer to articles that have authors that match a regexp.
7242 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7243   (interactive
7244    (list (read-string (if current-prefix-arg
7245                           "Exclude author (regexp): "
7246                         "Limit to author (regexp): "))
7247          current-prefix-arg))
7248   (gnus-summary-limit-to-subject from "from" not-matching))
7249
7250 (defun gnus-summary-limit-to-age (age &optional younger-p)
7251   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7252 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7253 articles that are younger than AGE days."
7254   (interactive
7255    (let ((younger current-prefix-arg)
7256          (days-got nil)
7257          days)
7258      (while (not days-got)
7259        (setq days (if younger
7260                       (read-string "Limit to articles within (in days): ")
7261                     (read-string "Limit to articles older than (in days): ")))
7262        (when (> (length days) 0)
7263          (setq days (read days)))
7264        (if (numberp days)
7265            (progn
7266              (setq days-got t)
7267              (if (< days 0)
7268                  (progn
7269                    (setq younger (not younger))
7270                    (setq days (* days -1)))))
7271          (message "Please enter a number.")
7272          (sleep-for 1)))
7273      (list days younger)))
7274   (prog1
7275       (let ((data gnus-newsgroup-data)
7276             (cutoff (days-to-time age))
7277             articles d date is-younger)
7278         (while (setq d (pop data))
7279           (when (and (vectorp (gnus-data-header d))
7280                      (setq date (mail-header-date (gnus-data-header d))))
7281             (setq is-younger (time-less-p
7282                               (time-since (condition-case ()
7283                                               (date-to-time date)
7284                                             (error '(0 0))))
7285                               cutoff))
7286             (when (if younger-p
7287                       is-younger
7288                     (not is-younger))
7289               (push (gnus-data-number d) articles))))
7290         (gnus-summary-limit (nreverse articles)))
7291     (gnus-summary-position-point)))
7292
7293 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7294   "Limit the summary buffer to articles that match an 'extra' header."
7295   (interactive
7296    (let ((header
7297           (intern
7298            (gnus-completing-read-with-default
7299             (symbol-name (car gnus-extra-headers))
7300             (if current-prefix-arg
7301                 "Exclude extra header:"
7302               "Limit extra header:")
7303             (mapcar (lambda (x)
7304                       (cons (symbol-name x) x))
7305                     gnus-extra-headers)
7306             nil
7307             t))))
7308      (list header
7309            (read-string (format "%s header %s (regexp): "
7310                                 (if current-prefix-arg "Exclude" "Limit to")
7311                                 header))
7312            current-prefix-arg)))
7313   (when (not (equal "" regexp))
7314     (prog1
7315         (let ((articles (gnus-summary-find-matching
7316                          (cons 'extra header) regexp 'all nil nil
7317                          not-matching)))
7318           (unless articles
7319             (error "Found no matches for \"%s\"" regexp))
7320           (gnus-summary-limit articles))
7321       (gnus-summary-position-point))))
7322
7323 (defun gnus-summary-limit-to-display-predicate ()
7324   "Limit the summary buffer to the predicated in the `display' group parameter."
7325   (interactive)
7326   (unless gnus-newsgroup-display
7327     (error "There is no `display' group parameter"))
7328   (let (articles)
7329     (dolist (number gnus-newsgroup-articles)
7330       (when (funcall gnus-newsgroup-display)
7331         (push number articles)))
7332     (gnus-summary-limit articles))
7333   (gnus-summary-position-point))
7334
7335 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7336 (make-obsolete
7337  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7338
7339 (defun gnus-summary-limit-to-unread (&optional all)
7340   "Limit the summary buffer to articles that are not marked as read.
7341 If ALL is non-nil, limit strictly to unread articles."
7342   (interactive "P")
7343   (if all
7344       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7345     (gnus-summary-limit-to-marks
7346      ;; Concat all the marks that say that an article is read and have
7347      ;; those removed.
7348      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7349            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7350            gnus-low-score-mark gnus-expirable-mark
7351            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7352            gnus-duplicate-mark gnus-souped-mark)
7353      'reverse)))
7354
7355 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7356 (make-obsolete 'gnus-summary-delete-marked-with
7357                'gnus-summary-limit-exclude-marks)
7358
7359 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7360   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7361 If REVERSE, limit the summary buffer to articles that are marked
7362 with MARKS.  MARKS can either be a string of marks or a list of marks.
7363 Returns how many articles were removed."
7364   (interactive "sMarks: ")
7365   (gnus-summary-limit-to-marks marks t))
7366
7367 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7368   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7369 If REVERSE (the prefix), limit the summary buffer to articles that are
7370 not marked with MARKS.  MARKS can either be a string of marks or a
7371 list of marks.
7372 Returns how many articles were removed."
7373   (interactive "sMarks: \nP")
7374   (prog1
7375       (let ((data gnus-newsgroup-data)
7376             (marks (if (listp marks) marks
7377                      (append marks nil))) ; Transform to list.
7378             articles)
7379         (while data
7380           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7381                   (memq (gnus-data-mark (car data)) marks))
7382             (push (gnus-data-number (car data)) articles))
7383           (setq data (cdr data)))
7384         (gnus-summary-limit articles))
7385     (gnus-summary-position-point)))
7386
7387 (defun gnus-summary-limit-to-score (score)
7388   "Limit to articles with score at or above SCORE."
7389   (interactive "NLimit to articles with score of at least: ")
7390   (let ((data gnus-newsgroup-data)
7391         articles)
7392     (while data
7393       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7394                 score)
7395         (push (gnus-data-number (car data)) articles))
7396       (setq data (cdr data)))
7397     (prog1
7398         (gnus-summary-limit articles)
7399       (gnus-summary-position-point))))
7400
7401 (defun gnus-summary-limit-to-unseen ()
7402   "Limit to unseen articles."
7403   (interactive)
7404   (prog1
7405       (gnus-summary-limit gnus-newsgroup-unseen)
7406     (gnus-summary-position-point)))
7407
7408 (defun gnus-summary-limit-include-thread (id)
7409   "Display all the hidden articles that is in the thread with ID in it.
7410 When called interactively, ID is the Message-ID of the current
7411 article."
7412   (interactive (list (mail-header-id (gnus-summary-article-header))))
7413   (let ((articles (gnus-articles-in-thread
7414                    (gnus-id-to-thread (gnus-root-id id)))))
7415     (prog1
7416         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7417       (gnus-summary-limit-include-matching-articles
7418        "subject"
7419        (regexp-quote (gnus-simplify-subject-re
7420                       (mail-header-subject (gnus-id-to-header id)))))
7421       (gnus-summary-position-point))))
7422
7423 (defun gnus-summary-limit-include-matching-articles (header regexp)
7424   "Display all the hidden articles that have HEADERs that match REGEXP."
7425   (interactive (list (read-string "Match on header: ")
7426                      (read-string "Regexp: ")))
7427   (let ((articles (gnus-find-matching-articles header regexp)))
7428     (prog1
7429         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7430       (gnus-summary-position-point))))
7431
7432 (defun gnus-summary-limit-include-dormant ()
7433   "Display all the hidden articles that are marked as dormant.
7434 Note that this command only works on a subset of the articles currently
7435 fetched for this group."
7436   (interactive)
7437   (unless gnus-newsgroup-dormant
7438     (error "There are no dormant articles in this group"))
7439   (prog1
7440       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7441     (gnus-summary-position-point)))
7442
7443 (defun gnus-summary-limit-exclude-dormant ()
7444   "Hide all dormant articles."
7445   (interactive)
7446   (prog1
7447       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7448     (gnus-summary-position-point)))
7449
7450 (defun gnus-summary-limit-exclude-childless-dormant ()
7451   "Hide all dormant articles that have no children."
7452   (interactive)
7453   (let ((data (gnus-data-list t))
7454         articles d children)
7455     ;; Find all articles that are either not dormant or have
7456     ;; children.
7457     (while (setq d (pop data))
7458       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7459                 (and (setq children
7460                            (gnus-article-children (gnus-data-number d)))
7461                      (let (found)
7462                        (while children
7463                          (when (memq (car children) articles)
7464                            (setq children nil
7465                                  found t))
7466                          (pop children))
7467                        found)))
7468         (push (gnus-data-number d) articles)))
7469     ;; Do the limiting.
7470     (prog1
7471         (gnus-summary-limit articles)
7472       (gnus-summary-position-point))))
7473
7474 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7475   "Mark all unread excluded articles as read.
7476 If ALL, mark even excluded ticked and dormants as read."
7477   (interactive "P")
7478   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7479   (let ((articles (gnus-sorted-ndifference
7480                    (sort
7481                     (mapcar (lambda (h) (mail-header-number h))
7482                             gnus-newsgroup-headers)
7483                     '<)
7484                    gnus-newsgroup-limit))
7485         article)
7486     (setq gnus-newsgroup-unreads
7487           (gnus-sorted-intersection gnus-newsgroup-unreads
7488                                     gnus-newsgroup-limit))
7489     (if all
7490         (setq gnus-newsgroup-dormant nil
7491               gnus-newsgroup-marked nil
7492               gnus-newsgroup-reads
7493               (nconc
7494                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7495                gnus-newsgroup-reads))
7496       (while (setq article (pop articles))
7497         (unless (or (memq article gnus-newsgroup-dormant)
7498                     (memq article gnus-newsgroup-marked))
7499           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7500
7501 (defun gnus-summary-limit (articles &optional pop)
7502   (if pop
7503       ;; We pop the previous limit off the stack and use that.
7504       (setq articles (car gnus-newsgroup-limits)
7505             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7506     ;; We use the new limit, so we push the old limit on the stack.
7507     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7508   ;; Set the limit.
7509   (setq gnus-newsgroup-limit articles)
7510   (let ((total (length gnus-newsgroup-data))
7511         (data (gnus-data-find-list (gnus-summary-article-number)))
7512         (gnus-summary-mark-below nil)   ; Inhibit this.
7513         found)
7514     ;; This will do all the work of generating the new summary buffer
7515     ;; according to the new limit.
7516     (gnus-summary-prepare)
7517     ;; Hide any threads, possibly.
7518     (gnus-summary-maybe-hide-threads)
7519     ;; Try to return to the article you were at, or one in the
7520     ;; neighborhood.
7521     (when data
7522       ;; We try to find some article after the current one.
7523       (while data
7524         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7525           (setq data nil
7526                 found t))
7527         (setq data (cdr data))))
7528     (unless found
7529       ;; If there is no data, that means that we were after the last
7530       ;; article.  The same goes when we can't find any articles
7531       ;; after the current one.
7532       (goto-char (point-max))
7533       (gnus-summary-find-prev))
7534     (gnus-set-mode-line 'summary)
7535     ;; We return how many articles were removed from the summary
7536     ;; buffer as a result of the new limit.
7537     (- total (length gnus-newsgroup-data))))
7538
7539 (defsubst gnus-invisible-cut-children (threads)
7540   (let ((num 0))
7541     (while threads
7542       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7543         (incf num))
7544       (pop threads))
7545     (< num 2)))
7546
7547 (defsubst gnus-cut-thread (thread)
7548   "Go forwards in the thread until we find an article that we want to display."
7549   (when (or (eq gnus-fetch-old-headers 'some)
7550             (eq gnus-fetch-old-headers 'invisible)
7551             (numberp gnus-fetch-old-headers)
7552             (eq gnus-build-sparse-threads 'some)
7553             (eq gnus-build-sparse-threads 'more))
7554     ;; Deal with old-fetched headers and sparse threads.
7555     (while (and
7556             thread
7557             (or
7558              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7559              (gnus-summary-article-ancient-p
7560               (mail-header-number (car thread))))
7561             (if (or (<= (length (cdr thread)) 1)
7562                     (eq gnus-fetch-old-headers 'invisible))
7563                 (setq gnus-newsgroup-limit
7564                       (delq (mail-header-number (car thread))
7565                             gnus-newsgroup-limit)
7566                       thread (cadr thread))
7567               (when (gnus-invisible-cut-children (cdr thread))
7568                 (let ((th (cdr thread)))
7569                   (while th
7570                     (if (memq (mail-header-number (caar th))
7571                               gnus-newsgroup-limit)
7572                         (setq thread (car th)
7573                               th nil)
7574                       (setq th (cdr th))))))))))
7575   thread)
7576
7577 (defun gnus-cut-threads (threads)
7578   "Cut off all uninteresting articles from the beginning of threads."
7579   (when (or (eq gnus-fetch-old-headers 'some)
7580             (eq gnus-fetch-old-headers 'invisible)
7581             (numberp gnus-fetch-old-headers)
7582             (eq gnus-build-sparse-threads 'some)
7583             (eq gnus-build-sparse-threads 'more))
7584     (let ((th threads))
7585       (while th
7586         (setcar th (gnus-cut-thread (car th)))
7587         (setq th (cdr th)))))
7588   ;; Remove nixed out threads.
7589   (delq nil threads))
7590
7591 (defun gnus-summary-initial-limit (&optional show-if-empty)
7592   "Figure out what the initial limit is supposed to be on group entry.
7593 This entails weeding out unwanted dormants, low-scored articles,
7594 fetch-old-headers verbiage, and so on."
7595   ;; Most groups have nothing to remove.
7596   (if (or gnus-inhibit-limiting
7597           (and (null gnus-newsgroup-dormant)
7598                (eq gnus-newsgroup-display 'gnus-not-ignore)
7599                (not (eq gnus-fetch-old-headers 'some))
7600                (not (numberp gnus-fetch-old-headers))
7601                (not (eq gnus-fetch-old-headers 'invisible))
7602                (null gnus-summary-expunge-below)
7603                (not (eq gnus-build-sparse-threads 'some))
7604                (not (eq gnus-build-sparse-threads 'more))
7605                (null gnus-thread-expunge-below)
7606                (not gnus-use-nocem)))
7607       ()                                ; Do nothing.
7608     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7609     (setq gnus-newsgroup-limit nil)
7610     (mapatoms
7611      (lambda (node)
7612        (unless (car (symbol-value node))
7613          ;; These threads have no parents -- they are roots.
7614          (let ((nodes (cdr (symbol-value node)))
7615                thread)
7616            (while nodes
7617              (if (and gnus-thread-expunge-below
7618                       (< (gnus-thread-total-score (car nodes))
7619                          gnus-thread-expunge-below))
7620                  (gnus-expunge-thread (pop nodes))
7621                (setq thread (pop nodes))
7622                (gnus-summary-limit-children thread))))))
7623      gnus-newsgroup-dependencies)
7624     ;; If this limitation resulted in an empty group, we might
7625     ;; pop the previous limit and use it instead.
7626     (when (and (not gnus-newsgroup-limit)
7627                show-if-empty)
7628       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7629     gnus-newsgroup-limit))
7630
7631 (defun gnus-summary-limit-children (thread)
7632   "Return 1 if this subthread is visible and 0 if it is not."
7633   ;; First we get the number of visible children to this thread.  This
7634   ;; is done by recursing down the thread using this function, so this
7635   ;; will really go down to a leaf article first, before slowly
7636   ;; working its way up towards the root.
7637   (when thread
7638     (let ((children
7639            (if (cdr thread)
7640                (apply '+ (mapcar 'gnus-summary-limit-children
7641                                  (cdr thread)))
7642              0))
7643           (number (mail-header-number (car thread)))
7644           score)
7645       (if (and
7646            (not (memq number gnus-newsgroup-marked))
7647            (or
7648             ;; If this article is dormant and has absolutely no visible
7649             ;; children, then this article isn't visible.
7650             (and (memq number gnus-newsgroup-dormant)
7651                  (zerop children))
7652             ;; If this is "fetch-old-headered" and there is no
7653             ;; visible children, then we don't want this article.
7654             (and (or (eq gnus-fetch-old-headers 'some)
7655                      (numberp gnus-fetch-old-headers))
7656                  (gnus-summary-article-ancient-p number)
7657                  (zerop children))
7658             ;; If this is "fetch-old-headered" and `invisible', then
7659             ;; we don't want this article.
7660             (and (eq gnus-fetch-old-headers 'invisible)
7661                  (gnus-summary-article-ancient-p number))
7662             ;; If this is a sparsely inserted article with no children,
7663             ;; we don't want it.
7664             (and (eq gnus-build-sparse-threads 'some)
7665                  (gnus-summary-article-sparse-p number)
7666                  (zerop children))
7667             ;; If we use expunging, and this article is really
7668             ;; low-scored, then we don't want this article.
7669             (when (and gnus-summary-expunge-below
7670                        (< (setq score
7671                                 (or (cdr (assq number gnus-newsgroup-scored))
7672                                     gnus-summary-default-score))
7673                           gnus-summary-expunge-below))
7674               ;; We increase the expunge-tally here, but that has
7675               ;; nothing to do with the limits, really.
7676               (incf gnus-newsgroup-expunged-tally)
7677               ;; We also mark as read here, if that's wanted.
7678               (when (and gnus-summary-mark-below
7679                          (< score gnus-summary-mark-below))
7680                 (setq gnus-newsgroup-unreads
7681                       (delq number gnus-newsgroup-unreads))
7682                 (if gnus-newsgroup-auto-expire
7683                     (push number gnus-newsgroup-expirable)
7684                   (push (cons number gnus-low-score-mark)
7685                         gnus-newsgroup-reads)))
7686               t)
7687             ;; Do the `display' group parameter.
7688             (and gnus-newsgroup-display
7689                  (not (funcall gnus-newsgroup-display)))
7690             ;; Check NoCeM things.
7691             (if (and gnus-use-nocem
7692                      (gnus-nocem-unwanted-article-p
7693                       (mail-header-id (car thread))))
7694                 (progn
7695                   (setq gnus-newsgroup-unreads
7696                         (delq number gnus-newsgroup-unreads))
7697                   t))))
7698           ;; Nope, invisible article.
7699           0
7700         ;; Ok, this article is to be visible, so we add it to the limit
7701         ;; and return 1.
7702         (push number gnus-newsgroup-limit)
7703         1))))
7704
7705 (defun gnus-expunge-thread (thread)
7706   "Mark all articles in THREAD as read."
7707   (let* ((number (mail-header-number (car thread))))
7708     (incf gnus-newsgroup-expunged-tally)
7709     ;; We also mark as read here, if that's wanted.
7710     (setq gnus-newsgroup-unreads
7711           (delq number gnus-newsgroup-unreads))
7712     (if gnus-newsgroup-auto-expire
7713         (push number gnus-newsgroup-expirable)
7714       (push (cons number gnus-low-score-mark)
7715             gnus-newsgroup-reads)))
7716   ;; Go recursively through all subthreads.
7717   (mapcar 'gnus-expunge-thread (cdr thread)))
7718
7719 ;; Summary article oriented commands
7720
7721 (defun gnus-summary-refer-parent-article (n)
7722   "Refer parent article N times.
7723 If N is negative, go to ancestor -N instead.
7724 The difference between N and the number of articles fetched is returned."
7725   (interactive "p")
7726   (let ((skip 1)
7727         error header ref)
7728     (when (not (natnump n))
7729       (setq skip (abs n)
7730             n 1))
7731     (while (and (> n 0)
7732                 (not error))
7733       (setq header (gnus-summary-article-header))
7734       (if (and (eq (mail-header-number header)
7735                    (cdr gnus-article-current))
7736                (equal gnus-newsgroup-name
7737                       (car gnus-article-current)))
7738           ;; If we try to find the parent of the currently
7739           ;; displayed article, then we take a look at the actual
7740           ;; References header, since this is slightly more
7741           ;; reliable than the References field we got from the
7742           ;; server.
7743           (save-excursion
7744             (set-buffer gnus-original-article-buffer)
7745             (nnheader-narrow-to-headers)
7746             (unless (setq ref (message-fetch-field "references"))
7747               (setq ref (message-fetch-field "in-reply-to")))
7748             (widen))
7749         (setq ref
7750               ;; It's not the current article, so we take a bet on
7751               ;; the value we got from the server.
7752               (mail-header-references header)))
7753       (if (and ref
7754                (not (equal ref "")))
7755           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7756             (gnus-message 1 "Couldn't find parent"))
7757         (gnus-message 1 "No references in article %d"
7758                       (gnus-summary-article-number))
7759         (setq error t))
7760       (decf n))
7761     (gnus-summary-position-point)
7762     n))
7763
7764 (defun gnus-summary-refer-references ()
7765   "Fetch all articles mentioned in the References header.
7766 Return the number of articles fetched."
7767   (interactive)
7768   (let ((ref (mail-header-references (gnus-summary-article-header)))
7769         (current (gnus-summary-article-number))
7770         (n 0))
7771     (if (or (not ref)
7772             (equal ref ""))
7773         (error "No References in the current article")
7774       ;; For each Message-ID in the References header...
7775       (while (string-match "<[^>]*>" ref)
7776         (incf n)
7777         ;; ... fetch that article.
7778         (gnus-summary-refer-article
7779          (prog1 (match-string 0 ref)
7780            (setq ref (substring ref (match-end 0))))))
7781       (gnus-summary-goto-subject current)
7782       (gnus-summary-position-point)
7783       n)))
7784
7785 (defun gnus-summary-refer-thread (&optional limit)
7786   "Fetch all articles in the current thread.
7787 If LIMIT (the numerical prefix), fetch that many old headers instead
7788 of what's specified by the `gnus-refer-thread-limit' variable."
7789   (interactive "P")
7790   (let ((id (mail-header-id (gnus-summary-article-header)))
7791         (limit (if limit (prefix-numeric-value limit)
7792                  gnus-refer-thread-limit)))
7793     ;; We want to fetch LIMIT *old* headers, but we also have to
7794     ;; re-fetch all the headers in the current buffer, because many of
7795     ;; them may be undisplayed.  So we adjust LIMIT.
7796     (when (numberp limit)
7797       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7798     (unless (eq gnus-fetch-old-headers 'invisible)
7799       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7800       ;; Retrieve the headers and read them in.
7801       (if (eq (gnus-retrieve-headers
7802                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7803               'nov)
7804           (gnus-build-all-threads)
7805         (error "Can't fetch thread from backends that don't support NOV"))
7806       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7807     (gnus-summary-limit-include-thread id)))
7808
7809 (defun gnus-summary-refer-article (message-id)
7810   "Fetch an article specified by MESSAGE-ID."
7811   (interactive "sMessage-ID: ")
7812   (when (and (stringp message-id)
7813              (not (zerop (length message-id))))
7814     ;; Construct the correct Message-ID if necessary.
7815     ;; Suggested by tale@pawl.rpi.edu.
7816     (unless (string-match "^<" message-id)
7817       (setq message-id (concat "<" message-id)))
7818     (unless (string-match ">$" message-id)
7819       (setq message-id (concat message-id ">")))
7820     (let* ((header (gnus-id-to-header message-id))
7821            (sparse (and header
7822                         (gnus-summary-article-sparse-p
7823                          (mail-header-number header))
7824                         (memq (mail-header-number header)
7825                               gnus-newsgroup-limit)))
7826            number)
7827       (cond
7828        ;; If the article is present in the buffer we just go to it.
7829        ((and header
7830              (or (not (gnus-summary-article-sparse-p
7831                        (mail-header-number header)))
7832                  sparse))
7833         (prog1
7834             (gnus-summary-goto-article
7835              (mail-header-number header) nil t)
7836           (when sparse
7837             (gnus-summary-update-article (mail-header-number header)))))
7838        (t
7839         ;; We fetch the article.
7840         (catch 'found
7841           (dolist (gnus-override-method (gnus-refer-article-methods))
7842             (gnus-check-server gnus-override-method)
7843             ;; Fetch the header, and display the article.
7844             (when (setq number (gnus-summary-insert-subject message-id))
7845               (gnus-summary-select-article nil nil nil number)
7846               (throw 'found t)))
7847           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7848
7849 (defun gnus-refer-article-methods ()
7850   "Return a list of referrable methods."
7851   (cond
7852    ;; No method, so we default to current and native.
7853    ((null gnus-refer-article-method)
7854     (list gnus-current-select-method gnus-select-method))
7855    ;; Current.
7856    ((eq 'current gnus-refer-article-method)
7857     (list gnus-current-select-method))
7858    ;; List of select methods.
7859    ((not (and (symbolp (car gnus-refer-article-method))
7860               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7861     (let (out)
7862       (dolist (method gnus-refer-article-method)
7863         (push (if (eq 'current method)
7864                   gnus-current-select-method
7865                 method)
7866               out))
7867       (nreverse out)))
7868    ;; One single select method.
7869    (t
7870     (list gnus-refer-article-method))))
7871
7872 (defun gnus-summary-edit-parameters ()
7873   "Edit the group parameters of the current group."
7874   (interactive)
7875   (gnus-group-edit-group gnus-newsgroup-name 'params))
7876
7877 (defun gnus-summary-customize-parameters ()
7878   "Customize the group parameters of the current group."
7879   (interactive)
7880   (gnus-group-customize gnus-newsgroup-name))
7881
7882 (defun gnus-summary-enter-digest-group (&optional force)
7883   "Enter an nndoc group based on the current article.
7884 If FORCE, force a digest interpretation.  If not, try
7885 to guess what the document format is."
7886   (interactive "P")
7887   (let ((conf gnus-current-window-configuration))
7888     (save-excursion
7889       (gnus-summary-select-article))
7890     (setq gnus-current-window-configuration conf)
7891     (let* ((name (format "%s-%d"
7892                          (gnus-group-prefixed-name
7893                           gnus-newsgroup-name (list 'nndoc ""))
7894                          (save-excursion
7895                            (set-buffer gnus-summary-buffer)
7896                            gnus-current-article)))
7897            (ogroup gnus-newsgroup-name)
7898            (params (append (gnus-info-params (gnus-get-info ogroup))
7899                            (list (cons 'to-group ogroup))
7900                            (list (cons 'save-article-group ogroup))))
7901            (case-fold-search t)
7902            (buf (current-buffer))
7903            dig to-address)
7904       (save-excursion
7905         (set-buffer gnus-original-article-buffer)
7906         ;; Have the digest group inherit the main mail address of
7907         ;; the parent article.
7908         (when (setq to-address (or (gnus-fetch-field "reply-to")
7909                                    (gnus-fetch-field "from")))
7910           (setq params (append
7911                         (list (cons 'to-address
7912                                     (funcall gnus-decode-encoded-word-function
7913                                              to-address))))))
7914         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7915         (insert-buffer-substring gnus-original-article-buffer)
7916         ;; Remove lines that may lead nndoc to misinterpret the
7917         ;; document type.
7918         (narrow-to-region
7919          (goto-char (point-min))
7920          (or (search-forward "\n\n" nil t) (point)))
7921         (goto-char (point-min))
7922         (delete-matching-lines "^Path:\\|^From ")
7923         (widen))
7924       (unwind-protect
7925           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7926                     (gnus-newsgroup-ephemeral-ignored-charsets
7927                      gnus-newsgroup-ignored-charsets))
7928                 (gnus-group-read-ephemeral-group
7929                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7930                               (nndoc-article-type
7931                                ,(if force 'mbox 'guess)))
7932                  t nil nil nil
7933                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7934                                                         "ADAPT")))))
7935               ;; Make all postings to this group go to the parent group.
7936               (nconc (gnus-info-params (gnus-get-info name))
7937                      params)
7938             ;; Couldn't select this doc group.
7939             (switch-to-buffer buf)
7940             (gnus-set-global-variables)
7941             (gnus-configure-windows 'summary)
7942             (gnus-message 3 "Article couldn't be entered?"))
7943         (kill-buffer dig)))))
7944
7945 (defun gnus-summary-read-document (n)
7946   "Open a new group based on the current article(s).
7947 This will allow you to read digests and other similar
7948 documents as newsgroups.
7949 Obeys the standard process/prefix convention."
7950   (interactive "P")
7951   (let* ((articles (gnus-summary-work-articles n))
7952          (ogroup gnus-newsgroup-name)
7953          (params (append (gnus-info-params (gnus-get-info ogroup))
7954                          (list (cons 'to-group ogroup))))
7955          article group egroup groups vgroup)
7956     (while (setq article (pop articles))
7957       (setq group (format "%s-%d" gnus-newsgroup-name article))
7958       (gnus-summary-remove-process-mark article)
7959       (when (gnus-summary-display-article article)
7960         (save-excursion
7961           (with-temp-buffer
7962             (insert-buffer-substring gnus-original-article-buffer)
7963             ;; Remove some headers that may lead nndoc to make
7964             ;; the wrong guess.
7965             (message-narrow-to-head)
7966             (goto-char (point-min))
7967             (delete-matching-lines "^\\(Path\\):\\|^From ")
7968             (widen)
7969             (if (setq egroup
7970                       (gnus-group-read-ephemeral-group
7971                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7972                                      (nndoc-article-type guess))
7973                        t nil t))
7974                 (progn
7975             ;; Make all postings to this group go to the parent group.
7976                   (nconc (gnus-info-params (gnus-get-info egroup))
7977                          params)
7978                   (push egroup groups))
7979               ;; Couldn't select this doc group.
7980               (gnus-error 3 "Article couldn't be entered"))))))
7981     ;; Now we have selected all the documents.
7982     (cond
7983      ((not groups)
7984       (error "None of the articles could be interpreted as documents"))
7985      ((gnus-group-read-ephemeral-group
7986        (setq vgroup (format
7987                      "nnvirtual:%s-%s" gnus-newsgroup-name
7988                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7989        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7990        t
7991        (cons (current-buffer) 'summary)))
7992      (t
7993       (error "Couldn't select virtual nndoc group")))))
7994
7995 (defun gnus-summary-isearch-article (&optional regexp-p)
7996   "Do incremental search forward on the current article.
7997 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7998   (interactive "P")
7999   (gnus-summary-select-article)
8000   (gnus-configure-windows 'article)
8001   (gnus-eval-in-buffer-window gnus-article-buffer
8002     (save-restriction
8003       (widen)
8004       (isearch-forward regexp-p))))
8005
8006 (defun gnus-summary-search-article-forward (regexp &optional backward)
8007   "Search for an article containing REGEXP forward.
8008 If BACKWARD, search backward instead."
8009   (interactive
8010    (list (read-string
8011           (format "Search article %s (regexp%s): "
8012                   (if current-prefix-arg "backward" "forward")
8013                   (if gnus-last-search-regexp
8014                       (concat ", default " gnus-last-search-regexp)
8015                     "")))
8016          current-prefix-arg))
8017   (if (string-equal regexp "")
8018       (setq regexp (or gnus-last-search-regexp ""))
8019     (setq gnus-last-search-regexp regexp)
8020     (setq gnus-article-before-search gnus-current-article))
8021   ;; Intentionally set gnus-last-article.
8022   (setq gnus-last-article gnus-article-before-search)
8023   (let ((gnus-last-article gnus-last-article))
8024     (if (gnus-summary-search-article regexp backward)
8025         (gnus-summary-show-thread)
8026       (error "Search failed: \"%s\"" regexp))))
8027
8028 (defun gnus-summary-search-article-backward (regexp)
8029   "Search for an article containing REGEXP backward."
8030   (interactive
8031    (list (read-string
8032           (format "Search article backward (regexp%s): "
8033                   (if gnus-last-search-regexp
8034                       (concat ", default " gnus-last-search-regexp)
8035                     "")))))
8036   (gnus-summary-search-article-forward regexp 'backward))
8037
8038 (defun gnus-summary-search-article (regexp &optional backward)
8039   "Search for an article containing REGEXP.
8040 Optional argument BACKWARD means do search for backward.
8041 `gnus-select-article-hook' is not called during the search."
8042   ;; We have to require this here to make sure that the following
8043   ;; dynamic binding isn't shadowed by autoloading.
8044   (require 'gnus-async)
8045   (require 'gnus-art)
8046   (let ((gnus-select-article-hook nil)  ;Disable hook.
8047         (gnus-article-prepare-hook nil)
8048         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8049         (gnus-use-article-prefetch nil)
8050         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8051         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8052         (sum (current-buffer))
8053         (gnus-display-mime-function nil)
8054         (found nil)
8055         point)
8056     (gnus-save-hidden-threads
8057       (gnus-summary-select-article)
8058       (set-buffer gnus-article-buffer)
8059       (goto-char (window-point (get-buffer-window (current-buffer))))
8060       (when backward
8061         (forward-line -1))
8062       (while (not found)
8063         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8064         (if (if backward
8065                 (re-search-backward regexp nil t)
8066               (re-search-forward regexp nil t))
8067             ;; We found the regexp.
8068             (progn
8069               (setq found 'found)
8070               (beginning-of-line)
8071               (set-window-start
8072                (get-buffer-window (current-buffer))
8073                (point))
8074               (forward-line 1)
8075               (set-window-point
8076                (get-buffer-window (current-buffer))
8077                (point))
8078               (set-buffer sum)
8079               (setq point (point)))
8080           ;; We didn't find it, so we go to the next article.
8081           (set-buffer sum)
8082           (setq found 'not)
8083           (while (eq found 'not)
8084             (if (not (if backward (gnus-summary-find-prev)
8085                        (gnus-summary-find-next)))
8086                 ;; No more articles.
8087                 (setq found t)
8088               ;; Select the next article and adjust point.
8089               (unless (gnus-summary-article-sparse-p
8090                        (gnus-summary-article-number))
8091                 (setq found nil)
8092                 (gnus-summary-select-article)
8093                 (set-buffer gnus-article-buffer)
8094                 (widen)
8095                 (goto-char (if backward (point-max) (point-min))))))))
8096       (gnus-message 7 ""))
8097     ;; Return whether we found the regexp.
8098     (when (eq found 'found)
8099       (goto-char point)
8100       (gnus-summary-show-thread)
8101       (gnus-summary-goto-subject gnus-current-article)
8102       (gnus-summary-position-point)
8103       t)))
8104
8105 (defun gnus-find-matching-articles (header regexp)
8106   "Return a list of all articles that match REGEXP on HEADER.
8107 This search includes all articles in the current group that Gnus has
8108 fetched headers for, whether they are displayed or not."
8109   (let ((articles nil)
8110         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8111         (case-fold-search t))
8112     (dolist (header gnus-newsgroup-headers)
8113       (when (string-match regexp (funcall func header))
8114         (push (mail-header-number header) articles)))
8115     (nreverse articles)))
8116
8117 (defun gnus-summary-find-matching (header regexp &optional backward unread
8118                                           not-case-fold not-matching)
8119   "Return a list of all articles that match REGEXP on HEADER.
8120 The search stars on the current article and goes forwards unless
8121 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8122 If UNREAD is non-nil, only unread articles will
8123 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8124 in the comparisons. If NOT-MATCHING, return a list of all articles that
8125 not match REGEXP on HEADER."
8126   (let ((case-fold-search (not not-case-fold))
8127         articles d func)
8128     (if (consp header)
8129         (if (eq (car header) 'extra)
8130             (setq func
8131                   `(lambda (h)
8132                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8133                          "")))
8134           (error "%s is an invalid header" header))
8135       (unless (fboundp (intern (concat "mail-header-" header)))
8136         (error "%s is not a valid header" header))
8137       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8138     (dolist (d (if (eq backward 'all)
8139                    gnus-newsgroup-data
8140                  (gnus-data-find-list
8141                   (gnus-summary-article-number)
8142                   (gnus-data-list backward))))
8143       (when (and (or (not unread)       ; We want all articles...
8144                      (gnus-data-unread-p d)) ; Or just unreads.
8145                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8146                  (if not-matching
8147                      (not (string-match
8148                            regexp
8149                            (funcall func (gnus-data-header d))))
8150                    (string-match regexp
8151                                  (funcall func (gnus-data-header d)))))
8152         (push (gnus-data-number d) articles))) ; Success!
8153     (nreverse articles)))
8154
8155 (defun gnus-summary-execute-command (header regexp command &optional backward)
8156   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8157 If HEADER is an empty string (or nil), the match is done on the entire
8158 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8159   (interactive
8160    (list (let ((completion-ignore-case t))
8161            (completing-read
8162             "Header name: "
8163             (mapcar (lambda (header) (list (format "%s" header)))
8164                     (append
8165                      '("Number" "Subject" "From" "Lines" "Date"
8166                        "Message-ID" "Xref" "References" "Body")
8167                      gnus-extra-headers))
8168             nil 'require-match))
8169          (read-string "Regexp: ")
8170          (read-key-sequence "Command: ")
8171          current-prefix-arg))
8172   (when (equal header "Body")
8173     (setq header ""))
8174   ;; Hidden thread subtrees must be searched as well.
8175   (gnus-summary-show-all-threads)
8176   ;; We don't want to change current point nor window configuration.
8177   (save-excursion
8178     (save-window-excursion
8179       (let (gnus-visual
8180             gnus-treat-strip-trailing-blank-lines
8181             gnus-treat-strip-leading-blank-lines
8182             gnus-treat-strip-multiple-blank-lines
8183             gnus-treat-hide-boring-headers
8184             gnus-treat-fold-newsgroups
8185             gnus-article-prepare-hook)
8186         (gnus-message 6 "Executing %s..." (key-description command))
8187         ;; We'd like to execute COMMAND interactively so as to give arguments.
8188         (gnus-execute header regexp
8189                       `(call-interactively ',(key-binding command))
8190                       backward)
8191         (gnus-message 6 "Executing %s...done" (key-description command))))))
8192
8193 (defun gnus-summary-beginning-of-article ()
8194   "Scroll the article back to the beginning."
8195   (interactive)
8196   (gnus-summary-select-article)
8197   (gnus-configure-windows 'article)
8198   (gnus-eval-in-buffer-window gnus-article-buffer
8199     (widen)
8200     (goto-char (point-min))
8201     (when gnus-page-broken
8202       (gnus-narrow-to-page))))
8203
8204 (defun gnus-summary-end-of-article ()
8205   "Scroll to the end of the article."
8206   (interactive)
8207   (gnus-summary-select-article)
8208   (gnus-configure-windows 'article)
8209   (gnus-eval-in-buffer-window gnus-article-buffer
8210     (widen)
8211     (goto-char (point-max))
8212     (recenter -3)
8213     (when gnus-page-broken
8214       (gnus-narrow-to-page))))
8215
8216 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8217   "Truncate to LEN and quote all \"(\"'s in STRING."
8218   (gnus-replace-in-string (if (and len (> (length string) len))
8219                               (substring string 0 len)
8220                             string)
8221                           "[()]" "\\\\\\&"))
8222
8223 (defun gnus-summary-print-article (&optional filename n)
8224   "Generate and print a PostScript image of the N next (mail) articles.
8225
8226 If N is negative, print the N previous articles.  If N is nil and articles
8227 have been marked with the process mark, print these instead.
8228
8229 If the optional first argument FILENAME is nil, send the image to the
8230 printer.  If FILENAME is a string, save the PostScript image in a file with
8231 that name.  If FILENAME is a number, prompt the user for the name of the file
8232 to save in."
8233   (interactive (list (ps-print-preprint current-prefix-arg)))
8234   (dolist (article (gnus-summary-work-articles n))
8235     (gnus-summary-select-article nil nil 'pseudo article)
8236     (gnus-eval-in-buffer-window gnus-article-buffer
8237       (gnus-print-buffer))
8238     (gnus-summary-remove-process-mark article))
8239   (ps-despool filename))
8240
8241 (defun gnus-print-buffer ()
8242   (let ((buffer (generate-new-buffer " *print*")))
8243     (unwind-protect
8244         (progn
8245           (copy-to-buffer buffer (point-min) (point-max))
8246           (set-buffer buffer)
8247           (gnus-article-delete-invisible-text)
8248           (gnus-remove-text-with-property 'gnus-decoration)
8249           (when (gnus-visual-p 'article-highlight 'highlight)
8250             ;; Copy-to-buffer doesn't copy overlay.  So redo
8251             ;; highlight.
8252             (let ((gnus-article-buffer buffer))
8253               (gnus-article-highlight-citation t)
8254               (gnus-article-highlight-signature)))
8255           (let ((ps-left-header
8256                  (list
8257                   (concat "("
8258                           (gnus-summary-print-truncate-and-quote
8259                            (mail-header-subject gnus-current-headers)
8260                            66) ")")
8261                   (concat "("
8262                           (gnus-summary-print-truncate-and-quote
8263                            (mail-header-from gnus-current-headers)
8264                            45) ")")))
8265                 (ps-right-header
8266                  (list
8267                   "/pagenumberstring load"
8268                   (concat "("
8269                           (mail-header-date gnus-current-headers) ")"))))
8270             (gnus-run-hooks 'gnus-ps-print-hook)
8271             (save-excursion
8272               (if window-system
8273                   (ps-spool-buffer-with-faces)
8274                 (ps-spool-buffer)))))
8275       (kill-buffer buffer))))
8276
8277 (defun gnus-summary-show-article (&optional arg)
8278   "Force redisplaying of the current article.
8279 If ARG (the prefix) is a number, show the article with the charset
8280 defined in `gnus-summary-show-article-charset-alist', or the charset
8281 input.
8282 If ARG (the prefix) is non-nil and not a number, show the raw article
8283 without any article massaging functions being run.  Normally, the key strokes
8284 are `C-u g'."
8285   (interactive "P")
8286   (cond
8287    ((numberp arg)
8288     (gnus-summary-show-article t)
8289     (let ((gnus-newsgroup-charset
8290            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8291                (mm-read-coding-system
8292                 "View as charset: " ;; actually it is coding system.
8293                 (save-excursion
8294                   (set-buffer gnus-article-buffer)
8295                   (mm-detect-coding-region (point) (point-max))))))
8296           (gnus-newsgroup-ignored-charsets 'gnus-all))
8297       (gnus-summary-select-article nil 'force)
8298       (let ((deps gnus-newsgroup-dependencies)
8299             head header lines)
8300         (save-excursion
8301           (set-buffer gnus-original-article-buffer)
8302           (save-restriction
8303             (message-narrow-to-head)
8304             (setq head (buffer-string))
8305             (goto-char (point-min))
8306             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8307               (goto-char (point-max))
8308               (widen)
8309               (setq lines (1- (count-lines (point) (point-max))))))
8310           (with-temp-buffer
8311             (insert (format "211 %d Article retrieved.\n"
8312                             (cdr gnus-article-current)))
8313             (insert head)
8314             (if lines (insert (format "Lines: %d\n" lines)))
8315             (insert ".\n")
8316             (let ((nntp-server-buffer (current-buffer)))
8317               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8318         (gnus-data-set-header
8319          (gnus-data-find (cdr gnus-article-current))
8320          header)
8321         (gnus-summary-update-article-line
8322          (cdr gnus-article-current) header)
8323         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8324           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8325    ((not arg)
8326     ;; Select the article the normal way.
8327     (gnus-summary-select-article nil 'force))
8328    (t
8329     ;; We have to require this here to make sure that the following
8330     ;; dynamic binding isn't shadowed by autoloading.
8331     (require 'gnus-async)
8332     (require 'gnus-art)
8333     ;; Bind the article treatment functions to nil.
8334     (let ((gnus-have-all-headers t)
8335           gnus-article-prepare-hook
8336           gnus-article-decode-hook
8337           gnus-display-mime-function
8338           gnus-break-pages)
8339       ;; Destroy any MIME parts.
8340       (when (gnus-buffer-live-p gnus-article-buffer)
8341         (save-excursion
8342           (set-buffer gnus-article-buffer)
8343           (mm-destroy-parts gnus-article-mime-handles)
8344           ;; Set it to nil for safety reason.
8345           (setq gnus-article-mime-handle-alist nil)
8346           (setq gnus-article-mime-handles nil)))
8347       (gnus-summary-select-article nil 'force))))
8348   (gnus-summary-goto-subject gnus-current-article)
8349   (gnus-summary-position-point))
8350
8351 (defun gnus-summary-show-raw-article ()
8352   "Show the raw article without any article massaging functions being run."
8353   (interactive)
8354   (gnus-summary-show-article t))
8355
8356 (defun gnus-summary-verbose-headers (&optional arg)
8357   "Toggle permanent full header display.
8358 If ARG is a positive number, turn header display on.
8359 If ARG is a negative number, turn header display off."
8360   (interactive "P")
8361   (setq gnus-show-all-headers
8362         (cond ((or (not (numberp arg))
8363                    (zerop arg))
8364                (not gnus-show-all-headers))
8365               ((natnump arg)
8366                t)))
8367   (gnus-summary-show-article))
8368
8369 (defun gnus-summary-toggle-header (&optional arg)
8370   "Show the headers if they are hidden, or hide them if they are shown.
8371 If ARG is a positive number, show the entire header.
8372 If ARG is a negative number, hide the unwanted header lines."
8373   (interactive "P")
8374   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8375                      (get-buffer-window gnus-article-buffer t))))
8376     (with-current-buffer gnus-article-buffer
8377       (widen)
8378       (article-narrow-to-head)
8379       (let* ((buffer-read-only nil)
8380              (inhibit-point-motion-hooks t)
8381              (hidden (if (numberp arg)
8382                          (>= arg 0)
8383                        (gnus-article-hidden-text-p 'headers)))
8384              s e)
8385         (delete-region (point-min) (point-max))
8386         (with-current-buffer gnus-original-article-buffer
8387           (goto-char (setq s (point-min)))
8388           (setq e (if (search-forward "\n\n" nil t)
8389                       (1- (point))
8390                     (point-max))))
8391         (insert-buffer-substring gnus-original-article-buffer s e)
8392         (article-decode-encoded-words)
8393         (if hidden
8394             (let ((gnus-treat-hide-headers nil)
8395                   (gnus-treat-hide-boring-headers nil))
8396               (gnus-delete-wash-type 'headers)
8397               (gnus-treat-article 'head))
8398           (gnus-treat-article 'head))
8399         (widen)
8400         (if window
8401             (set-window-start window (goto-char (point-min))))
8402         (setq gnus-page-broken
8403               (when gnus-break-pages
8404                 (gnus-narrow-to-page)
8405                 t))
8406         (gnus-set-mode-line 'article)))))
8407
8408 (defun gnus-summary-show-all-headers ()
8409   "Make all header lines visible."
8410   (interactive)
8411   (gnus-summary-toggle-header 1))
8412
8413 (defun gnus-summary-caesar-message (&optional arg)
8414   "Caesar rotate the current article by 13.
8415 The numerical prefix specifies how many places to rotate each letter
8416 forward."
8417   (interactive "P")
8418   (gnus-summary-select-article)
8419   (let ((mail-header-separator ""))
8420     (gnus-eval-in-buffer-window gnus-article-buffer
8421       (save-restriction
8422         (widen)
8423         (let ((start (window-start))
8424               buffer-read-only)
8425           (message-caesar-buffer-body arg)
8426           (set-window-start (get-buffer-window (current-buffer)) start))))))
8427
8428 (autoload 'unmorse-region "morse"
8429   "Convert morse coded text in region to ordinary ASCII text."
8430   t)
8431
8432 (defun gnus-summary-morse-message (&optional arg)
8433   "Morse decode the current article."
8434   (interactive "P")
8435   (gnus-summary-select-article)
8436   (let ((mail-header-separator ""))
8437     (gnus-eval-in-buffer-window gnus-article-buffer
8438       (save-excursion
8439         (save-restriction
8440           (widen)
8441           (let ((pos (window-start))
8442                 buffer-read-only)
8443             (goto-char (point-min))
8444             (when (message-goto-body)
8445               (gnus-narrow-to-body))
8446             (goto-char (point-min))
8447             (while (re-search-forward "·" (point-max) t)
8448               (replace-match "."))
8449             (unmorse-region (point-min) (point-max))
8450             (widen)
8451             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8452
8453 (defun gnus-summary-stop-page-breaking ()
8454   "Stop page breaking in the current article."
8455   (interactive)
8456   (gnus-summary-select-article)
8457   (gnus-eval-in-buffer-window gnus-article-buffer
8458     (widen)
8459     (when (gnus-visual-p 'page-marker)
8460       (let ((buffer-read-only nil))
8461         (gnus-remove-text-with-property 'gnus-prev)
8462         (gnus-remove-text-with-property 'gnus-next))
8463       (setq gnus-page-broken nil))))
8464
8465 (defun gnus-summary-move-article (&optional n to-newsgroup
8466                                             select-method action)
8467   "Move the current article to a different newsgroup.
8468 If N is a positive number, move the N next articles.
8469 If N is a negative number, move the N previous articles.
8470 If N is nil and any articles have been marked with the process mark,
8471 move those articles instead.
8472 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8473 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8474 re-spool using this method.
8475
8476 When called interactively with TO-NEWSGROUP being nil, the value of
8477 the variable `gnus-move-split-methods' is used for finding a default
8478 for the target newsgroup.
8479
8480 For this function to work, both the current newsgroup and the
8481 newsgroup that you want to move to have to support the `request-move'
8482 and `request-accept' functions.
8483
8484 ACTION can be either `move' (the default), `crosspost' or `copy'."
8485   (interactive "P")
8486   (unless action
8487     (setq action 'move))
8488   ;; Check whether the source group supports the required functions.
8489   (cond ((and (eq action 'move)
8490               (not (gnus-check-backend-function
8491                     'request-move-article gnus-newsgroup-name)))
8492          (error "The current group does not support article moving"))
8493         ((and (eq action 'crosspost)
8494               (not (gnus-check-backend-function
8495                     'request-replace-article gnus-newsgroup-name)))
8496          (error "The current group does not support article editing")))
8497   (let ((articles (gnus-summary-work-articles n))
8498         (prefix (if (gnus-check-backend-function
8499                      'request-move-article gnus-newsgroup-name)
8500                     (gnus-group-real-prefix gnus-newsgroup-name)
8501                   ""))
8502         (names '((move "Move" "Moving")
8503                  (copy "Copy" "Copying")
8504                  (crosspost "Crosspost" "Crossposting")))
8505         (copy-buf (save-excursion
8506                     (nnheader-set-temp-buffer " *copy article*")))
8507         art-group to-method new-xref article to-groups)
8508     (unless (assq action names)
8509       (error "Unknown action %s" action))
8510     ;; Read the newsgroup name.
8511     (when (and (not to-newsgroup)
8512                (not select-method))
8513       (if (and gnus-move-split-methods
8514                (not
8515                 (and (memq gnus-current-article articles)
8516                      (gnus-buffer-live-p gnus-original-article-buffer))))
8517           ;; When `gnus-move-split-methods' is non-nil, we have to
8518           ;; select an article to give `gnus-read-move-group-name' an
8519           ;; opportunity to suggest an appropriate default.  However,
8520           ;; we needn't render or mark the article.
8521           (let ((gnus-display-mime-function nil)
8522                 (gnus-article-prepare-hook nil)
8523                 (gnus-mark-article-hook nil))
8524             (gnus-summary-select-article nil nil nil (car articles))))
8525       (setq to-newsgroup
8526             (gnus-read-move-group-name
8527              (cadr (assq action names))
8528              (symbol-value (intern (format "gnus-current-%s-group" action)))
8529              articles prefix))
8530       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8531     (setq to-method (or select-method
8532                         (gnus-server-to-method
8533                          (gnus-group-method to-newsgroup))))
8534     ;; Check the method we are to move this article to...
8535     (unless (gnus-check-backend-function
8536              'request-accept-article (car to-method))
8537       (error "%s does not support article copying" (car to-method)))
8538     (unless (gnus-check-server to-method)
8539       (error "Can't open server %s" (car to-method)))
8540     (gnus-message 6 "%s to %s: %s..."
8541                   (caddr (assq action names))
8542                   (or (car select-method) to-newsgroup) articles)
8543     (while articles
8544       (setq article (pop articles))
8545       (setq
8546        art-group
8547        (cond
8548         ;; Move the article.
8549         ((eq action 'move)
8550          ;; Remove this article from future suppression.
8551          (gnus-dup-unsuppress-article article)
8552          (gnus-request-move-article
8553           article                       ; Article to move
8554           gnus-newsgroup-name           ; From newsgroup
8555           (nth 1 (gnus-find-method-for-group
8556                   gnus-newsgroup-name)) ; Server
8557           (list 'gnus-request-accept-article
8558                 to-newsgroup (list 'quote select-method)
8559                 (not articles) t)       ; Accept form
8560           (not articles)))              ; Only save nov last time
8561         ;; Copy the article.
8562         ((eq action 'copy)
8563          (save-excursion
8564            (set-buffer copy-buf)
8565            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8566              (gnus-request-accept-article
8567               to-newsgroup select-method (not articles) t))))
8568         ;; Crosspost the article.
8569         ((eq action 'crosspost)
8570          (let ((xref (message-tokenize-header
8571                       (mail-header-xref (gnus-summary-article-header article))
8572                       " ")))
8573            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8574                                   ":" (number-to-string article)))
8575            (unless xref
8576              (setq xref (list (system-name))))
8577            (setq new-xref
8578                  (concat
8579                   (mapconcat 'identity
8580                              (delete "Xref:" (delete new-xref xref))
8581                              " ")
8582                   " " new-xref))
8583            (save-excursion
8584              (set-buffer copy-buf)
8585              ;; First put the article in the destination group.
8586              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8587              (when (consp (setq art-group
8588                                 (gnus-request-accept-article
8589                                  to-newsgroup select-method (not articles))))
8590                (setq new-xref (concat new-xref " " (car art-group)
8591                                       ":"
8592                                       (number-to-string (cdr art-group))))
8593                ;; Now we have the new Xrefs header, so we insert
8594                ;; it and replace the new article.
8595                (nnheader-replace-header "Xref" new-xref)
8596                (gnus-request-replace-article
8597                 (cdr art-group) to-newsgroup (current-buffer))
8598                art-group))))))
8599       (cond
8600        ((not art-group)
8601         (gnus-message 1 "Couldn't %s article %s: %s"
8602                       (cadr (assq action names)) article
8603                       (nnheader-get-report (car to-method))))
8604        ((eq art-group 'junk)
8605         (when (eq action 'move)
8606           (gnus-summary-mark-article article gnus-canceled-mark)
8607           (gnus-message 4 "Deleted article %s" article)))
8608        (t
8609         (let* ((pto-group (gnus-group-prefixed-name
8610                            (car art-group) to-method))
8611                (entry
8612                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8613                (info (nth 2 entry))
8614                (to-group (gnus-info-group info))
8615                to-marks)
8616           ;; Update the group that has been moved to.
8617           (when (and info
8618                      (memq action '(move copy)))
8619             (unless (member to-group to-groups)
8620               (push to-group to-groups))
8621
8622             (unless (memq article gnus-newsgroup-unreads)
8623               (push 'read to-marks)
8624               (gnus-info-set-read
8625                info (gnus-add-to-range (gnus-info-read info)
8626                                        (list (cdr art-group)))))
8627
8628             ;; See whether the article is to be put in the cache.
8629             (let ((marks gnus-article-mark-lists)
8630                   (to-article (cdr art-group)))
8631
8632               ;; Enter the article into the cache in the new group,
8633               ;; if that is required.
8634               (when gnus-use-cache
8635                 (gnus-cache-possibly-enter-article
8636                  to-group to-article
8637                  (memq article gnus-newsgroup-marked)
8638                  (memq article gnus-newsgroup-dormant)
8639                  (memq article gnus-newsgroup-unreads)))
8640
8641               (when gnus-preserve-marks
8642                 ;; Copy any marks over to the new group.
8643                 (when (and (equal to-group gnus-newsgroup-name)
8644                            (not (memq article gnus-newsgroup-unreads)))
8645                   ;; Mark this article as read in this group.
8646                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8647                   (setcdr (gnus-active to-group) to-article)
8648                   (setcdr gnus-newsgroup-active to-article))
8649
8650                 (while marks
8651                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8652                     (when (memq article (symbol-value
8653                                          (intern (format "gnus-newsgroup-%s"
8654                                                          (caar marks)))))
8655                       (push (cdar marks) to-marks)
8656                       ;; If the other group is the same as this group,
8657                       ;; then we have to add the mark to the list.
8658                       (when (equal to-group gnus-newsgroup-name)
8659                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8660                              (cons to-article
8661                                    (symbol-value
8662                                     (intern (format "gnus-newsgroup-%s"
8663                                                     (caar marks)))))))
8664                       ;; Copy the marks to other group.
8665                       (gnus-add-marked-articles
8666                        to-group (cdar marks) (list to-article) info)))
8667                   (setq marks (cdr marks)))
8668
8669                 (gnus-request-set-mark to-group (list (list (list to-article)
8670                                                             'add
8671                                                             to-marks))))
8672
8673               (gnus-dribble-enter
8674                (concat "(gnus-group-set-info '"
8675                        (gnus-prin1-to-string (gnus-get-info to-group))
8676                        ")"))))
8677
8678           ;; Update the Xref header in this article to point to
8679           ;; the new crossposted article we have just created.
8680           (when (eq action 'crosspost)
8681             (save-excursion
8682               (set-buffer copy-buf)
8683               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8684               (nnheader-replace-header "Xref" new-xref)
8685               (gnus-request-replace-article
8686                article gnus-newsgroup-name (current-buffer)))))
8687
8688         ;;;!!!Why is this necessary?
8689         (set-buffer gnus-summary-buffer)
8690
8691         (gnus-summary-goto-subject article)
8692         (when (eq action 'move)
8693           (gnus-summary-mark-article article gnus-canceled-mark))))
8694       (gnus-summary-remove-process-mark article))
8695     ;; Re-activate all groups that have been moved to.
8696     (save-excursion
8697       (set-buffer gnus-group-buffer)
8698       (let ((gnus-group-marked to-groups))
8699         (gnus-group-get-new-news-this-group nil t)))
8700
8701     (gnus-kill-buffer copy-buf)
8702     (gnus-summary-position-point)
8703     (gnus-set-mode-line 'summary)))
8704
8705 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8706   "Move the current article to a different newsgroup.
8707 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8708 When called interactively, if TO-NEWSGROUP is nil, use the value of
8709 the variable `gnus-move-split-methods' for finding a default target
8710 newsgroup.
8711 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8712 re-spool using this method."
8713   (interactive "P")
8714   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8715
8716 (defun gnus-summary-crosspost-article (&optional n)
8717   "Crosspost the current article to some other group."
8718   (interactive "P")
8719   (gnus-summary-move-article n nil nil 'crosspost))
8720
8721 (defcustom gnus-summary-respool-default-method nil
8722   "Default method type for respooling an article.
8723 If nil, use to the current newsgroup method."
8724   :type 'symbol
8725   :group 'gnus-summary-mail)
8726
8727 (defun gnus-summary-respool-article (&optional n method)
8728   "Respool the current article.
8729 The article will be squeezed through the mail spooling process again,
8730 which means that it will be put in some mail newsgroup or other
8731 depending on `nnmail-split-methods'.
8732 If N is a positive number, respool the N next articles.
8733 If N is a negative number, respool the N previous articles.
8734 If N is nil and any articles have been marked with the process mark,
8735 respool those articles instead.
8736
8737 Respooling can be done both from mail groups and \"real\" newsgroups.
8738 In the former case, the articles in question will be moved from the
8739 current group into whatever groups they are destined to.  In the
8740 latter case, they will be copied into the relevant groups."
8741   (interactive
8742    (list current-prefix-arg
8743          (let* ((methods (gnus-methods-using 'respool))
8744                 (methname
8745                  (symbol-name (or gnus-summary-respool-default-method
8746                                   (car (gnus-find-method-for-group
8747                                         gnus-newsgroup-name)))))
8748                 (method
8749                  (gnus-completing-read-with-default
8750                   methname "What backend do you want to use when respooling?"
8751                   methods nil t nil 'gnus-mail-method-history))
8752                 ms)
8753            (cond
8754             ((zerop (length (setq ms (gnus-servers-using-backend
8755                                       (intern method)))))
8756              (list (intern method) ""))
8757             ((= 1 (length ms))
8758              (car ms))
8759             (t
8760              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8761                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8762                            ms-alist))))))))
8763   (unless method
8764     (error "No method given for respooling"))
8765   (if (assoc (symbol-name
8766               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8767              (gnus-methods-using 'respool))
8768       (gnus-summary-move-article n nil method)
8769     (gnus-summary-copy-article n nil method)))
8770
8771 (defun gnus-summary-import-article (file &optional edit)
8772   "Import an arbitrary file into a mail newsgroup."
8773   (interactive "fImport file: \nP")
8774   (let ((group gnus-newsgroup-name)
8775         (now (current-time))
8776         atts lines group-art)
8777     (unless (gnus-check-backend-function 'request-accept-article group)
8778       (error "%s does not support article importing" group))
8779     (or (file-readable-p file)
8780         (not (file-regular-p file))
8781         (error "Can't read %s" file))
8782     (save-excursion
8783       (set-buffer (gnus-get-buffer-create " *import file*"))
8784       (erase-buffer)
8785       (nnheader-insert-file-contents file)
8786       (goto-char (point-min))
8787       (if (nnheader-article-p)
8788           (save-restriction
8789             (goto-char (point-min))
8790             (search-forward "\n\n" nil t)
8791             (narrow-to-region (point-min) (1- (point)))
8792             (goto-char (point-min))
8793             (unless (re-search-forward "^date:" nil t)
8794               (goto-char (point-max))
8795               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8796        ;; This doesn't look like an article, so we fudge some headers.
8797         (setq atts (file-attributes file)
8798               lines (count-lines (point-min) (point-max)))
8799         (insert "From: " (read-string "From: ") "\n"
8800                 "Subject: " (read-string "Subject: ") "\n"
8801                 "Date: " (message-make-date (nth 5 atts)) "\n"
8802                 "Message-ID: " (message-make-message-id) "\n"
8803                 "Lines: " (int-to-string lines) "\n"
8804                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8805       (setq group-art (gnus-request-accept-article group nil t))
8806       (kill-buffer (current-buffer)))
8807     (setq gnus-newsgroup-active (gnus-activate-group group))
8808     (forward-line 1)
8809     (gnus-summary-goto-article (cdr group-art) nil t)
8810     (when edit
8811       (gnus-summary-edit-article))))
8812
8813 (defun gnus-summary-create-article ()
8814   "Create an article in a mail newsgroup."
8815   (interactive)
8816   (let ((group gnus-newsgroup-name)
8817         (now (current-time))
8818         group-art)
8819     (unless (gnus-check-backend-function 'request-accept-article group)
8820       (error "%s does not support article importing" group))
8821     (save-excursion
8822       (set-buffer (gnus-get-buffer-create " *import file*"))
8823       (erase-buffer)
8824       (goto-char (point-min))
8825       ;; This doesn't look like an article, so we fudge some headers.
8826       (insert "From: " (read-string "From: ") "\n"
8827               "Subject: " (read-string "Subject: ") "\n"
8828               "Date: " (message-make-date now) "\n"
8829               "Message-ID: " (message-make-message-id) "\n")
8830       (setq group-art (gnus-request-accept-article group nil t))
8831       (kill-buffer (current-buffer)))
8832     (setq gnus-newsgroup-active (gnus-activate-group group))
8833     (forward-line 1)
8834     (gnus-summary-goto-article (cdr group-art) nil t)
8835     (gnus-summary-edit-article)))
8836
8837 (defun gnus-summary-article-posted-p ()
8838   "Say whether the current (mail) article is available from news as well.
8839 This will be the case if the article has both been mailed and posted."
8840   (interactive)
8841   (let ((id (mail-header-references (gnus-summary-article-header)))
8842         (gnus-override-method (car (gnus-refer-article-methods))))
8843     (if (gnus-request-head id "")
8844         (gnus-message 2 "The current message was found on %s"
8845                       gnus-override-method)
8846       (gnus-message 2 "The current message couldn't be found on %s"
8847                     gnus-override-method)
8848       nil)))
8849
8850 (defun gnus-summary-expire-articles (&optional now)
8851   "Expire all articles that are marked as expirable in the current group."
8852   (interactive)
8853   (when (gnus-check-backend-function
8854          'request-expire-articles gnus-newsgroup-name)
8855     ;; This backend supports expiry.
8856     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8857            (expirable (if total
8858                           (progn
8859                             ;; We need to update the info for
8860                             ;; this group for `gnus-list-of-read-articles'
8861                             ;; to give us the right answer.
8862                             (gnus-run-hooks 'gnus-exit-group-hook)
8863                             (gnus-summary-update-info)
8864                             (gnus-list-of-read-articles gnus-newsgroup-name))
8865                         (setq gnus-newsgroup-expirable
8866                               (sort gnus-newsgroup-expirable '<))))
8867            (expiry-wait (if now 'immediate
8868                           (gnus-group-find-parameter
8869                            gnus-newsgroup-name 'expiry-wait)))
8870            (nnmail-expiry-target
8871             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8872                 nnmail-expiry-target))
8873            es)
8874       (when expirable
8875         ;; There are expirable articles in this group, so we run them
8876         ;; through the expiry process.
8877         (gnus-message 6 "Expiring articles...")
8878         (unless (gnus-check-group gnus-newsgroup-name)
8879           (error "Can't open server for %s" gnus-newsgroup-name))
8880         ;; The list of articles that weren't expired is returned.
8881         (save-excursion
8882           (if expiry-wait
8883               (let ((nnmail-expiry-wait-function nil)
8884                     (nnmail-expiry-wait expiry-wait))
8885                 (setq es (gnus-request-expire-articles
8886                           expirable gnus-newsgroup-name)))
8887             (setq es (gnus-request-expire-articles
8888                       expirable gnus-newsgroup-name)))
8889           (unless total
8890             (setq gnus-newsgroup-expirable es))
8891           ;; We go through the old list of expirable, and mark all
8892           ;; really expired articles as nonexistent.
8893           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8894             (let ((gnus-use-cache nil))
8895               (dolist (article expirable)
8896                 (when (and (not (memq article es))
8897                            (gnus-data-find article))
8898                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8899         (gnus-message 6 "Expiring articles...done")))))
8900
8901 (defun gnus-summary-expire-articles-now ()
8902   "Expunge all expirable articles in the current group.
8903 This means that *all* articles that are marked as expirable will be
8904 deleted forever, right now."
8905   (interactive)
8906   (or gnus-expert-user
8907       (gnus-yes-or-no-p
8908        "Are you really, really, really sure you want to delete all these messages? ")
8909       (error "Phew!"))
8910   (gnus-summary-expire-articles t))
8911
8912 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8913 (defun gnus-summary-delete-article (&optional n)
8914   "Delete the N next (mail) articles.
8915 This command actually deletes articles.  This is not a marking
8916 command.  The article will disappear forever from your life, never to
8917 return.
8918 If N is negative, delete backwards.
8919 If N is nil and articles have been marked with the process mark,
8920 delete these instead."
8921   (interactive "P")
8922   (unless (gnus-check-backend-function 'request-expire-articles
8923                                        gnus-newsgroup-name)
8924     (error "The current newsgroup does not support article deletion"))
8925   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8926     (error "Couldn't open server"))
8927   ;; Compute the list of articles to delete.
8928   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8929         (nnmail-expiry-target 'delete)
8930         not-deleted)
8931     (if (and gnus-novice-user
8932              (not (gnus-yes-or-no-p
8933                    (format "Do you really want to delete %s forever? "
8934                            (if (> (length articles) 1)
8935                                (format "these %s articles" (length articles))
8936                              "this article")))))
8937         ()
8938       ;; Delete the articles.
8939       (setq not-deleted (gnus-request-expire-articles
8940                          articles gnus-newsgroup-name 'force))
8941       (while articles
8942         (gnus-summary-remove-process-mark (car articles))
8943         ;; The backend might not have been able to delete the article
8944         ;; after all.
8945         (unless (memq (car articles) not-deleted)
8946           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8947         (setq articles (cdr articles)))
8948       (when not-deleted
8949         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8950     (gnus-summary-position-point)
8951     (gnus-set-mode-line 'summary)
8952     not-deleted))
8953
8954 (defun gnus-summary-edit-article (&optional arg)
8955   "Edit the current article.
8956 This will have permanent effect only in mail groups.
8957 If ARG is nil, edit the decoded articles.
8958 If ARG is 1, edit the raw articles.
8959 If ARG is 2, edit the raw articles even in read-only groups.
8960 If ARG is 3, edit the articles with the current handles.
8961 Otherwise, allow editing of articles even in read-only
8962 groups."
8963   (interactive "P")
8964   (let (force raw current-handles)
8965     (cond
8966      ((null arg))
8967      ((eq arg 1)
8968       (setq raw t))
8969      ((eq arg 2)
8970       (setq raw t
8971             force t))
8972      ((eq arg 3)
8973       (setq current-handles
8974             (and (gnus-buffer-live-p gnus-article-buffer)
8975                  (with-current-buffer gnus-article-buffer
8976                    (prog1
8977                        gnus-article-mime-handles
8978                      (setq gnus-article-mime-handles nil))))))
8979      (t
8980       (setq force t)))
8981     (when (and raw (not force)
8982                (member gnus-newsgroup-name '("nndraft:delayed"
8983                                              "nndraft:drafts"
8984                                              "nndraft:queue")))
8985       (error "Can't edit the raw article in group %s"
8986              gnus-newsgroup-name))
8987     (save-excursion
8988       (set-buffer gnus-summary-buffer)
8989       (let ((mail-parse-charset gnus-newsgroup-charset)
8990             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8991         (gnus-set-global-variables)
8992         (when (and (not force)
8993                    (gnus-group-read-only-p))
8994           (error "The current newsgroup does not support article editing"))
8995         (gnus-summary-show-article t)
8996         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8997           (with-current-buffer gnus-article-buffer
8998             (mm-enable-multibyte)))
8999         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9000             (setq raw t))
9001         (gnus-article-edit-article
9002          (if raw 'ignore
9003            `(lambda ()
9004               (let ((mbl mml-buffer-list))
9005                 (setq mml-buffer-list nil)
9006                 (mime-to-mml ,'current-handles)
9007                 (let ((mbl1 mml-buffer-list))
9008                   (setq mml-buffer-list mbl)
9009                   (set (make-local-variable 'mml-buffer-list) mbl1))
9010                 (make-local-hook 'kill-buffer-hook)
9011                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9012          `(lambda (no-highlight)
9013             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9014                   (message-options message-options)
9015                   (message-options-set-recipient)
9016                   (mail-parse-ignored-charsets
9017                    ',gnus-newsgroup-ignored-charsets))
9018               ,(if (not raw) '(progn
9019                                 (mml-to-mime)
9020                                 (mml-destroy-buffers)
9021                                 (remove-hook 'kill-buffer-hook
9022                                              'mml-destroy-buffers t)
9023                                 (kill-local-variable 'mml-buffer-list)))
9024               (gnus-summary-edit-article-done
9025                ,(or (mail-header-references gnus-current-headers) "")
9026                ,(gnus-group-read-only-p)
9027                ,gnus-summary-buffer no-highlight))))))))
9028
9029 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9030
9031 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9032                                                  no-highlight)
9033   "Make edits to the current article permanent."
9034   (interactive)
9035   (save-excursion
9036    ;; The buffer restriction contains the entire article if it exists.
9037     (when (article-goto-body)
9038       (let ((lines (count-lines (point) (point-max)))
9039             (length (- (point-max) (point)))
9040             (case-fold-search t)
9041             (body (copy-marker (point))))
9042         (goto-char (point-min))
9043         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9044           (delete-region (match-beginning 1) (match-end 1))
9045           (insert (number-to-string length)))
9046         (goto-char (point-min))
9047         (when (re-search-forward
9048                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9049           (delete-region (match-beginning 1) (match-end 1))
9050           (insert (number-to-string length)))
9051         (goto-char (point-min))
9052         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9053           (delete-region (match-beginning 1) (match-end 1))
9054           (insert (number-to-string lines))))))
9055   ;; Replace the article.
9056   (let ((buf (current-buffer)))
9057     (with-temp-buffer
9058       (insert-buffer-substring buf)
9059
9060       (if (and (not read-only)
9061                (not (gnus-request-replace-article
9062                      (cdr gnus-article-current) (car gnus-article-current)
9063                      (current-buffer) t)))
9064           (error "Couldn't replace article")
9065         ;; Update the summary buffer.
9066         (if (and references
9067                  (equal (message-tokenize-header references " ")
9068                         (message-tokenize-header
9069                          (or (message-fetch-field "references") "") " ")))
9070             ;; We only have to update this line.
9071             (save-excursion
9072               (save-restriction
9073                 (message-narrow-to-head)
9074                 (let ((head (buffer-string))
9075                       header)
9076                   (with-temp-buffer
9077                     (insert (format "211 %d Article retrieved.\n"
9078                                     (cdr gnus-article-current)))
9079                     (insert head)
9080                     (insert ".\n")
9081                     (let ((nntp-server-buffer (current-buffer)))
9082                       (setq header (car (gnus-get-newsgroup-headers
9083                                          nil t))))
9084                     (save-excursion
9085                       (set-buffer gnus-summary-buffer)
9086                       (gnus-data-set-header
9087                        (gnus-data-find (cdr gnus-article-current))
9088                        header)
9089                       (gnus-summary-update-article-line
9090                        (cdr gnus-article-current) header)
9091                       (if (gnus-summary-goto-subject
9092                            (cdr gnus-article-current) nil t)
9093                           (gnus-summary-update-secondary-mark
9094                            (cdr gnus-article-current))))))))
9095           ;; Update threads.
9096           (set-buffer (or buffer gnus-summary-buffer))
9097           (gnus-summary-update-article (cdr gnus-article-current))
9098           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9099               (gnus-summary-update-secondary-mark
9100                (cdr gnus-article-current))))
9101         ;; Prettify the article buffer again.
9102         (unless no-highlight
9103           (save-excursion
9104             (set-buffer gnus-article-buffer)
9105             ;;;!!! Fix this -- article should be rehighlighted.
9106             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9107             (set-buffer gnus-original-article-buffer)
9108             (gnus-request-article
9109              (cdr gnus-article-current)
9110              (car gnus-article-current) (current-buffer))))
9111         ;; Prettify the summary buffer line.
9112         (when (gnus-visual-p 'summary-highlight 'highlight)
9113           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9114
9115 (defun gnus-summary-edit-wash (key)
9116   "Perform editing command KEY in the article buffer."
9117   (interactive
9118    (list
9119     (progn
9120       (message "%s" (concat (this-command-keys) "- "))
9121       (read-char))))
9122   (message "")
9123   (gnus-summary-edit-article)
9124   (execute-kbd-macro (concat (this-command-keys) key))
9125   (gnus-article-edit-done))
9126
9127 ;;; Respooling
9128
9129 (defun gnus-summary-respool-query (&optional silent trace)
9130   "Query where the respool algorithm would put this article."
9131   (interactive)
9132   (let (gnus-mark-article-hook)
9133     (gnus-summary-select-article)
9134     (save-excursion
9135       (set-buffer gnus-original-article-buffer)
9136       (save-restriction
9137         (message-narrow-to-head)
9138         (let ((groups (nnmail-article-group 'identity trace)))
9139           (unless silent
9140             (if groups
9141                 (message "This message would go to %s"
9142                          (mapconcat 'car groups ", "))
9143               (message "This message would go to no groups"))
9144             groups))))))
9145
9146 (defun gnus-summary-respool-trace ()
9147   "Trace where the respool algorithm would put this article.
9148 Display a buffer showing all fancy splitting patterns which matched."
9149   (interactive)
9150   (gnus-summary-respool-query nil t))
9151
9152 ;; Summary marking commands.
9153
9154 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9155   "Mark articles which has the same subject as read, and then select the next.
9156 If UNMARK is positive, remove any kind of mark.
9157 If UNMARK is negative, tick articles."
9158   (interactive "P")
9159   (when unmark
9160     (setq unmark (prefix-numeric-value unmark)))
9161   (let ((count
9162          (gnus-summary-mark-same-subject
9163           (gnus-summary-article-subject) unmark)))
9164     ;; Select next unread article.  If auto-select-same mode, should
9165     ;; select the first unread article.
9166     (gnus-summary-next-article t (and gnus-auto-select-same
9167                                       (gnus-summary-article-subject)))
9168     (gnus-message 7 "%d article%s marked as %s"
9169                   count (if (= count 1) " is" "s are")
9170                   (if unmark "unread" "read"))))
9171
9172 (defun gnus-summary-kill-same-subject (&optional unmark)
9173   "Mark articles which has the same subject as read.
9174 If UNMARK is positive, remove any kind of mark.
9175 If UNMARK is negative, tick articles."
9176   (interactive "P")
9177   (when unmark
9178     (setq unmark (prefix-numeric-value unmark)))
9179   (let ((count
9180          (gnus-summary-mark-same-subject
9181           (gnus-summary-article-subject) unmark)))
9182     ;; If marked as read, go to next unread subject.
9183     (when (null unmark)
9184       ;; Go to next unread subject.
9185       (gnus-summary-next-subject 1 t))
9186     (gnus-message 7 "%d articles are marked as %s"
9187                   count (if unmark "unread" "read"))))
9188
9189 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9190   "Mark articles with same SUBJECT as read, and return marked number.
9191 If optional argument UNMARK is positive, remove any kinds of marks.
9192 If optional argument UNMARK is negative, mark articles as unread instead."
9193   (let ((count 1))
9194     (save-excursion
9195       (cond
9196        ((null unmark)                   ; Mark as read.
9197         (while (and
9198                 (progn
9199                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9200                   (gnus-summary-show-thread) t)
9201                 (gnus-summary-find-subject subject))
9202           (setq count (1+ count))))
9203        ((> unmark 0)                    ; Tick.
9204         (while (and
9205                 (progn
9206                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9207                   (gnus-summary-show-thread) t)
9208                 (gnus-summary-find-subject subject))
9209           (setq count (1+ count))))
9210        (t                               ; Mark as unread.
9211         (while (and
9212                 (progn
9213                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9214                   (gnus-summary-show-thread) t)
9215                 (gnus-summary-find-subject subject))
9216           (setq count (1+ count)))))
9217       (gnus-set-mode-line 'summary)
9218       ;; Return the number of marked articles.
9219       count)))
9220
9221 (defun gnus-summary-mark-as-processable (n &optional unmark)
9222   "Set the process mark on the next N articles.
9223 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9224 the process mark instead.  The difference between N and the actual
9225 number of articles marked is returned."
9226   (interactive "P")
9227   (if (and (null n) (gnus-region-active-p))
9228       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9229     (setq n (prefix-numeric-value n))
9230     (let ((backward (< n 0))
9231           (n (abs n)))
9232       (while (and
9233               (> n 0)
9234               (if unmark
9235                   (gnus-summary-remove-process-mark
9236                    (gnus-summary-article-number))
9237                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9238               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9239         (setq n (1- n)))
9240       (when (/= 0 n)
9241         (gnus-message 7 "No more articles"))
9242       (gnus-summary-recenter)
9243       (gnus-summary-position-point)
9244       n)))
9245
9246 (defun gnus-summary-unmark-as-processable (n)
9247   "Remove the process mark from the next N articles.
9248 If N is negative, unmark backward instead.  The difference between N and
9249 the actual number of articles unmarked is returned."
9250   (interactive "P")
9251   (gnus-summary-mark-as-processable n t))
9252
9253 (defun gnus-summary-unmark-all-processable ()
9254   "Remove the process mark from all articles."
9255   (interactive)
9256   (save-excursion
9257     (while gnus-newsgroup-processable
9258       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9259   (gnus-summary-position-point))
9260
9261 (defun gnus-summary-add-mark (article type)
9262   "Mark ARTICLE with a mark of TYPE."
9263   (let ((vtype (car (assq type gnus-article-mark-lists)))
9264         var)
9265     (if (not vtype)
9266         (error "No such mark type: %s" type)
9267       (setq var (intern (format "gnus-newsgroup-%s" type)))
9268       (set var (cons article (symbol-value var)))
9269       (if (memq type '(processable cached replied forwarded recent saved))
9270           (gnus-summary-update-secondary-mark article)
9271         ;;; !!! This is bogus.  We should find out what primary
9272         ;;; !!! mark we want to set.
9273         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9274
9275 (defun gnus-summary-mark-as-expirable (n)
9276   "Mark N articles forward as expirable.
9277 If N is negative, mark backward instead.  The difference between N and
9278 the actual number of articles marked is returned."
9279   (interactive "p")
9280   (gnus-summary-mark-forward n gnus-expirable-mark))
9281
9282 (defun gnus-summary-mark-as-spam (n)
9283   "Mark N articles forward as spam.
9284 If N is negative, mark backward instead.  The difference between N and
9285 the actual number of articles marked is returned."
9286   (interactive "p")
9287   (gnus-summary-mark-forward n gnus-spam-mark))
9288
9289 (defun gnus-summary-mark-article-as-replied (article)
9290   "Mark ARTICLE as replied to and update the summary line.
9291 ARTICLE can also be a list of articles."
9292   (interactive (list (gnus-summary-article-number)))
9293   (let ((articles (if (listp article) article (list article))))
9294     (dolist (article articles)
9295       (push article gnus-newsgroup-replied)
9296       (let ((buffer-read-only nil))
9297         (when (gnus-summary-goto-subject article nil t)
9298           (gnus-summary-update-secondary-mark article))))))
9299
9300 (defun gnus-summary-mark-article-as-forwarded (article)
9301   "Mark ARTICLE as forwarded and update the summary line.
9302 ARTICLE can also be a list of articles."
9303   (let ((articles (if (listp article) article (list article))))
9304     (dolist (article articles)
9305       (push article gnus-newsgroup-forwarded)
9306       (let ((buffer-read-only nil))
9307         (when (gnus-summary-goto-subject article nil t)
9308           (gnus-summary-update-secondary-mark article))))))
9309
9310 (defun gnus-summary-set-bookmark (article)
9311   "Set a bookmark in current article."
9312   (interactive (list (gnus-summary-article-number)))
9313   (when (or (not (get-buffer gnus-article-buffer))
9314             (not gnus-current-article)
9315             (not gnus-article-current)
9316             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9317     (error "No current article selected"))
9318   ;; Remove old bookmark, if one exists.
9319   (let ((old (assq article gnus-newsgroup-bookmarks)))
9320     (when old
9321       (setq gnus-newsgroup-bookmarks
9322             (delq old gnus-newsgroup-bookmarks))))
9323   ;; Set the new bookmark, which is on the form
9324   ;; (article-number . line-number-in-body).
9325   (push
9326    (cons article
9327          (save-excursion
9328            (set-buffer gnus-article-buffer)
9329            (count-lines
9330             (min (point)
9331                  (save-excursion
9332                    (goto-char (point-min))
9333                    (search-forward "\n\n" nil t)
9334                    (point)))
9335             (point))))
9336    gnus-newsgroup-bookmarks)
9337   (gnus-message 6 "A bookmark has been added to the current article."))
9338
9339 (defun gnus-summary-remove-bookmark (article)
9340   "Remove the bookmark from the current article."
9341   (interactive (list (gnus-summary-article-number)))
9342   ;; Remove old bookmark, if one exists.
9343   (let ((old (assq article gnus-newsgroup-bookmarks)))
9344     (if old
9345         (progn
9346           (setq gnus-newsgroup-bookmarks
9347                 (delq old gnus-newsgroup-bookmarks))
9348           (gnus-message 6 "Removed bookmark."))
9349       (gnus-message 6 "No bookmark in current article."))))
9350
9351 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9352 (defun gnus-summary-mark-as-dormant (n)
9353   "Mark N articles forward as dormant.
9354 If N is negative, mark backward instead.  The difference between N and
9355 the actual number of articles marked is returned."
9356   (interactive "p")
9357   (gnus-summary-mark-forward n gnus-dormant-mark))
9358
9359 (defun gnus-summary-set-process-mark (article)
9360   "Set the process mark on ARTICLE and update the summary line."
9361   (setq gnus-newsgroup-processable
9362         (cons article
9363               (delq article gnus-newsgroup-processable)))
9364   (when (gnus-summary-goto-subject article)
9365     (gnus-summary-show-thread)
9366     (gnus-summary-goto-subject article)
9367     (gnus-summary-update-secondary-mark article)))
9368
9369 (defun gnus-summary-remove-process-mark (article)
9370   "Remove the process mark from ARTICLE and update the summary line."
9371   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9372   (when (gnus-summary-goto-subject article)
9373     (gnus-summary-show-thread)
9374     (gnus-summary-goto-subject article)
9375     (gnus-summary-update-secondary-mark article)))
9376
9377 (defun gnus-summary-set-saved-mark (article)
9378   "Set the process mark on ARTICLE and update the summary line."
9379   (push article gnus-newsgroup-saved)
9380   (when (gnus-summary-goto-subject article)
9381     (gnus-summary-update-secondary-mark article)))
9382
9383 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9384   "Mark N articles as read forwards.
9385 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9386 The difference between N and the actual number of articles marked is
9387 returned.
9388 Iff NO-EXPIRE, auto-expiry will be inhibited."
9389   (interactive "p")
9390   (gnus-summary-show-thread)
9391   (let ((backward (< n 0))
9392         (gnus-summary-goto-unread
9393          (and gnus-summary-goto-unread
9394               (not (eq gnus-summary-goto-unread 'never))
9395               (not (memq mark (list gnus-unread-mark
9396                                     gnus-ticked-mark gnus-dormant-mark)))))
9397         (n (abs n))
9398         (mark (or mark gnus-del-mark)))
9399     (while (and (> n 0)
9400                 (gnus-summary-mark-article nil mark no-expire)
9401                 (zerop (gnus-summary-next-subject
9402                         (if backward -1 1)
9403                         (and gnus-summary-goto-unread
9404                              (not (eq gnus-summary-goto-unread 'never)))
9405                         t)))
9406       (setq n (1- n)))
9407     (when (/= 0 n)
9408       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9409     (gnus-summary-recenter)
9410     (gnus-summary-position-point)
9411     (gnus-set-mode-line 'summary)
9412     n))
9413
9414 (defun gnus-summary-mark-article-as-read (mark)
9415   "Mark the current article quickly as read with MARK."
9416   (let ((article (gnus-summary-article-number)))
9417     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9418     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9419     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9420     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9421     (push (cons article mark) gnus-newsgroup-reads)
9422     ;; Possibly remove from cache, if that is used.
9423     (when gnus-use-cache
9424       (gnus-cache-enter-remove-article article))
9425     ;; Allow the backend to change the mark.
9426     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9427     ;; Check for auto-expiry.
9428     (when (and gnus-newsgroup-auto-expire
9429                (memq mark gnus-auto-expirable-marks))
9430       (setq mark gnus-expirable-mark)
9431       ;; Let the backend know about the mark change.
9432       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9433       (push article gnus-newsgroup-expirable))
9434     ;; Set the mark in the buffer.
9435     (gnus-summary-update-mark mark 'unread)
9436     t))
9437
9438 (defun gnus-summary-mark-article-as-unread (mark)
9439   "Mark the current article quickly as unread with MARK."
9440   (let* ((article (gnus-summary-article-number))
9441          (old-mark (gnus-summary-article-mark article)))
9442     ;; Allow the backend to change the mark.
9443     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9444     (if (eq mark old-mark)
9445         t
9446       (if (<= article 0)
9447           (progn
9448             (gnus-error 1 "Can't mark negative article numbers")
9449             nil)
9450         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9451         (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9452         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9453         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9454         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9455         (cond ((= mark gnus-ticked-mark)
9456                (setq gnus-newsgroup-marked
9457                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9458                                               article)))
9459               ((= mark gnus-spam-mark)
9460                (setq gnus-newsgroup-spam-marked
9461                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9462                                               article)))
9463               ((= mark gnus-dormant-mark)
9464                (setq gnus-newsgroup-dormant
9465                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9466                                               article)))
9467               (t
9468                (setq gnus-newsgroup-unreads
9469                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9470                                               article))))
9471         (gnus-pull article gnus-newsgroup-reads)
9472
9473         ;; See whether the article is to be put in the cache.
9474         (and gnus-use-cache
9475              (vectorp (gnus-summary-article-header article))
9476              (save-excursion
9477                (gnus-cache-possibly-enter-article
9478                 gnus-newsgroup-name article
9479                 (= mark gnus-ticked-mark)
9480                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9481
9482         ;; Fix the mark.
9483         (gnus-summary-update-mark mark 'unread)
9484         t))))
9485
9486 (defun gnus-summary-mark-article (&optional article mark no-expire)
9487   "Mark ARTICLE with MARK.  MARK can be any character.
9488 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9489 `??' (dormant) and `?E' (expirable).
9490 If MARK is nil, then the default character `?r' is used.
9491 If ARTICLE is nil, then the article on the current line will be
9492 marked.
9493 Iff NO-EXPIRE, auto-expiry will be inhibited."
9494   ;; The mark might be a string.
9495   (when (stringp mark)
9496     (setq mark (aref mark 0)))
9497   ;; If no mark is given, then we check auto-expiring.
9498   (when (null mark)
9499     (setq mark gnus-del-mark))
9500   (when (and (not no-expire)
9501              gnus-newsgroup-auto-expire
9502              (memq mark gnus-auto-expirable-marks))
9503     (setq mark gnus-expirable-mark))
9504   (let ((article (or article (gnus-summary-article-number)))
9505         (old-mark (gnus-summary-article-mark article)))
9506     ;; Allow the backend to change the mark.
9507     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9508     (if (eq mark old-mark)
9509         t
9510       (unless article
9511         (error "No article on current line"))
9512       (if (not (if (or (= mark gnus-unread-mark)
9513                        (= mark gnus-ticked-mark)
9514                        (= mark gnus-spam-mark)
9515                        (= mark gnus-dormant-mark))
9516                    (gnus-mark-article-as-unread article mark)
9517                  (gnus-mark-article-as-read article mark)))
9518           t
9519         ;; See whether the article is to be put in the cache.
9520         (and gnus-use-cache
9521              (not (= mark gnus-canceled-mark))
9522              (vectorp (gnus-summary-article-header article))
9523              (save-excursion
9524                (gnus-cache-possibly-enter-article
9525                 gnus-newsgroup-name article
9526                 (= mark gnus-ticked-mark)
9527                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9528
9529         (when (gnus-summary-goto-subject article nil t)
9530           (let ((buffer-read-only nil))
9531             (gnus-summary-show-thread)
9532             ;; Fix the mark.
9533             (gnus-summary-update-mark mark 'unread)
9534             t))))))
9535
9536 (defun gnus-summary-update-secondary-mark (article)
9537   "Update the secondary (read, process, cache) mark."
9538   (gnus-summary-update-mark
9539    (cond ((memq article gnus-newsgroup-processable)
9540           gnus-process-mark)
9541          ((memq article gnus-newsgroup-cached)
9542           gnus-cached-mark)
9543          ((memq article gnus-newsgroup-replied)
9544           gnus-replied-mark)
9545          ((memq article gnus-newsgroup-forwarded)
9546           gnus-forwarded-mark)
9547          ((memq article gnus-newsgroup-saved)
9548           gnus-saved-mark)
9549          ((memq article gnus-newsgroup-recent)
9550           gnus-recent-mark)
9551          ((memq article gnus-newsgroup-unseen)
9552           gnus-unseen-mark)
9553          (t gnus-no-mark))
9554    'replied)
9555   (when (gnus-visual-p 'summary-highlight 'highlight)
9556     (gnus-run-hooks 'gnus-summary-update-hook))
9557   t)
9558
9559 (defun gnus-summary-update-mark (mark type)
9560   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9561         (buffer-read-only nil))
9562     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9563     (when forward
9564       (when (looking-at "\r")
9565         (incf forward))
9566       (when (<= (+ forward (point)) (point-max))
9567         ;; Go to the right position on the line.
9568         (goto-char (+ forward (point)))
9569         ;; Replace the old mark with the new mark.
9570         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9571         ;; Optionally update the marks by some user rule.
9572         (when (eq type 'unread)
9573           (gnus-data-set-mark
9574            (gnus-data-find (gnus-summary-article-number)) mark)
9575           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9576
9577 (defun gnus-mark-article-as-read (article &optional mark)
9578   "Enter ARTICLE in the pertinent lists and remove it from others."
9579   ;; Make the article expirable.
9580   (let ((mark (or mark gnus-del-mark)))
9581     (setq gnus-newsgroup-expirable
9582           (if (= mark gnus-expirable-mark)
9583               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9584             (delq article gnus-newsgroup-expirable)))
9585     ;; Remove from unread and marked lists.
9586     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9587     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9588     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9589     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9590     (push (cons article mark) gnus-newsgroup-reads)
9591     ;; Possibly remove from cache, if that is used.
9592     (when gnus-use-cache
9593       (gnus-cache-enter-remove-article article))
9594     t))
9595
9596 (defun gnus-mark-article-as-unread (article &optional mark)
9597   "Enter ARTICLE in the pertinent lists and remove it from others."
9598   (let ((mark (or mark gnus-ticked-mark)))
9599     (if (<= article 0)
9600         (progn
9601           (gnus-error 1 "Can't mark negative article numbers")
9602           nil)
9603       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9604             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9605             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9606             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9607             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9608
9609       ;; Unsuppress duplicates?
9610       (when gnus-suppress-duplicates
9611         (gnus-dup-unsuppress-article article))
9612
9613       (cond ((= mark gnus-ticked-mark)
9614              (setq gnus-newsgroup-marked
9615                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9616             ((= mark gnus-spam-mark)
9617              (setq gnus-newsgroup-spam-marked
9618                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked article)))
9619             ((= mark gnus-dormant-mark)
9620              (setq gnus-newsgroup-dormant
9621                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9622             (t
9623              (setq gnus-newsgroup-unreads
9624                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9625       (gnus-pull article gnus-newsgroup-reads)
9626       t)))
9627
9628 (defalias 'gnus-summary-mark-as-unread-forward
9629   'gnus-summary-tick-article-forward)
9630 (make-obsolete 'gnus-summary-mark-as-unread-forward
9631                'gnus-summary-tick-article-forward)
9632 (defun gnus-summary-tick-article-forward (n)
9633   "Tick N articles forwards.
9634 If N is negative, tick backwards instead.
9635 The difference between N and the number of articles ticked is returned."
9636   (interactive "p")
9637   (gnus-summary-mark-forward n gnus-ticked-mark))
9638
9639 (defalias 'gnus-summary-mark-as-unread-backward
9640   'gnus-summary-tick-article-backward)
9641 (make-obsolete 'gnus-summary-mark-as-unread-backward
9642                'gnus-summary-tick-article-backward)
9643 (defun gnus-summary-tick-article-backward (n)
9644   "Tick N articles backwards.
9645 The difference between N and the number of articles ticked is returned."
9646   (interactive "p")
9647   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9648
9649 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9650 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9651 (defun gnus-summary-tick-article (&optional article clear-mark)
9652   "Mark current article as unread.
9653 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9654 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9655   (interactive)
9656   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9657                                        gnus-ticked-mark)))
9658
9659 (defun gnus-summary-mark-as-read-forward (n)
9660   "Mark N articles as read forwards.
9661 If N is negative, mark backwards instead.
9662 The difference between N and the actual number of articles marked is
9663 returned."
9664   (interactive "p")
9665   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9666
9667 (defun gnus-summary-mark-as-read-backward (n)
9668   "Mark the N articles as read backwards.
9669 The difference between N and the actual number of articles marked is
9670 returned."
9671   (interactive "p")
9672   (gnus-summary-mark-forward
9673    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9674
9675 (defun gnus-summary-mark-as-read (&optional article mark)
9676   "Mark current article as read.
9677 ARTICLE specifies the article to be marked as read.
9678 MARK specifies a string to be inserted at the beginning of the line."
9679   (gnus-summary-mark-article article mark))
9680
9681 (defun gnus-summary-clear-mark-forward (n)
9682   "Clear marks from N articles forward.
9683 If N is negative, clear backward instead.
9684 The difference between N and the number of marks cleared is returned."
9685   (interactive "p")
9686   (gnus-summary-mark-forward n gnus-unread-mark))
9687
9688 (defun gnus-summary-clear-mark-backward (n)
9689   "Clear marks from N articles backward.
9690 The difference between N and the number of marks cleared is returned."
9691   (interactive "p")
9692   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9693
9694 (defun gnus-summary-mark-unread-as-read ()
9695   "Intended to be used by `gnus-summary-mark-article-hook'."
9696   (when (memq gnus-current-article gnus-newsgroup-unreads)
9697     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9698
9699 (defun gnus-summary-mark-read-and-unread-as-read ()
9700   "Intended to be used by `gnus-summary-mark-article-hook'."
9701   (let ((mark (gnus-summary-article-mark)))
9702     (when (or (gnus-unread-mark-p mark)
9703               (gnus-read-mark-p mark))
9704       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9705
9706 (defun gnus-summary-mark-unread-as-ticked ()
9707   "Intended to be used by `gnus-summary-mark-article-hook'."
9708   (when (memq gnus-current-article gnus-newsgroup-unreads)
9709     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9710
9711 (defun gnus-summary-mark-region-as-read (point mark all)
9712   "Mark all unread articles between point and mark as read.
9713 If given a prefix, mark all articles between point and mark as read,
9714 even ticked and dormant ones."
9715   (interactive "r\nP")
9716   (save-excursion
9717     (let (article)
9718       (goto-char point)
9719       (beginning-of-line)
9720       (while (and
9721               (< (point) mark)
9722               (progn
9723                 (when (or all
9724                           (memq (setq article (gnus-summary-article-number))
9725                                 gnus-newsgroup-unreads))
9726                   (gnus-summary-mark-article article gnus-del-mark))
9727                 t)
9728               (gnus-summary-find-next))))))
9729
9730 (defun gnus-summary-mark-below (score mark)
9731   "Mark articles with score less than SCORE with MARK."
9732   (interactive "P\ncMark: ")
9733   (setq score (if score
9734                   (prefix-numeric-value score)
9735                 (or gnus-summary-default-score 0)))
9736   (save-excursion
9737     (set-buffer gnus-summary-buffer)
9738     (goto-char (point-min))
9739     (while
9740         (progn
9741           (and (< (gnus-summary-article-score) score)
9742                (gnus-summary-mark-article nil mark))
9743           (gnus-summary-find-next)))))
9744
9745 (defun gnus-summary-kill-below (&optional score)
9746   "Mark articles with score below SCORE as read."
9747   (interactive "P")
9748   (gnus-summary-mark-below score gnus-killed-mark))
9749
9750 (defun gnus-summary-clear-above (&optional score)
9751   "Clear all marks from articles with score above SCORE."
9752   (interactive "P")
9753   (gnus-summary-mark-above score gnus-unread-mark))
9754
9755 (defun gnus-summary-tick-above (&optional score)
9756   "Tick all articles with score above SCORE."
9757   (interactive "P")
9758   (gnus-summary-mark-above score gnus-ticked-mark))
9759
9760 (defun gnus-summary-mark-above (score mark)
9761   "Mark articles with score over SCORE with MARK."
9762   (interactive "P\ncMark: ")
9763   (setq score (if score
9764                   (prefix-numeric-value score)
9765                 (or gnus-summary-default-score 0)))
9766   (save-excursion
9767     (set-buffer gnus-summary-buffer)
9768     (goto-char (point-min))
9769     (while (and (progn
9770                   (when (> (gnus-summary-article-score) score)
9771                     (gnus-summary-mark-article nil mark))
9772                   t)
9773                 (gnus-summary-find-next)))))
9774
9775 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9776 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9777 (defun gnus-summary-limit-include-expunged (&optional no-error)
9778   "Display all the hidden articles that were expunged for low scores."
9779   (interactive)
9780   (let ((buffer-read-only nil))
9781     (let ((scored gnus-newsgroup-scored)
9782           headers h)
9783       (while scored
9784         (unless (gnus-summary-article-header (caar scored))
9785           (and (setq h (gnus-number-to-header (caar scored)))
9786                (< (cdar scored) gnus-summary-expunge-below)
9787                (push h headers)))
9788         (setq scored (cdr scored)))
9789       (if (not headers)
9790           (when (not no-error)
9791             (error "No expunged articles hidden"))
9792         (goto-char (point-min))
9793         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9794         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9795         (mapcar (lambda (x) (push (mail-header-number x)
9796                                   gnus-newsgroup-limit))
9797                 headers)
9798         (gnus-summary-prepare-unthreaded (nreverse headers))
9799         (goto-char (point-min))
9800         (gnus-summary-position-point)
9801         t))))
9802
9803 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9804   "Mark all unread articles in this newsgroup as read.
9805 If prefix argument ALL is non-nil, ticked and dormant articles will
9806 also be marked as read.
9807 If QUIETLY is non-nil, no questions will be asked.
9808 If TO-HERE is non-nil, it should be a point in the buffer.  All
9809 articles before (after, if REVERSE is set) this point will be marked as read.
9810 Note that this function will only catch up the unread article
9811 in the current summary buffer limitation.
9812 The number of articles marked as read is returned."
9813   (interactive "P")
9814   (prog1
9815       (save-excursion
9816         (when (or quietly
9817                   (not gnus-interactive-catchup) ;Without confirmation?
9818                   gnus-expert-user
9819                   (gnus-y-or-n-p
9820                    (if all
9821                        "Mark absolutely all articles as read? "
9822                      "Mark all unread articles as read? ")))
9823           (if (and not-mark
9824                    (not gnus-newsgroup-adaptive)
9825                    (not gnus-newsgroup-auto-expire)
9826                    (not gnus-suppress-duplicates)
9827                    (or (not gnus-use-cache)
9828                        (eq gnus-use-cache 'passive)))
9829               (progn
9830                 (when all
9831                   (setq gnus-newsgroup-marked nil
9832                         gnus-newsgroup-spam-marked nil
9833                         gnus-newsgroup-dormant nil))
9834                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9835             ;; We actually mark all articles as canceled, which we
9836             ;; have to do when using auto-expiry or adaptive scoring.
9837             (gnus-summary-show-all-threads)
9838             (if (and to-here reverse)
9839                 (progn
9840                   (goto-char to-here)
9841                   (while (and
9842                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9843                           (gnus-summary-find-next (not all) nil nil t))))
9844               (when (gnus-summary-first-subject (not all) t)
9845                 (while (and
9846                         (if to-here (< (point) to-here) t)
9847                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9848                         (gnus-summary-find-next (not all) nil nil t)))))
9849             (gnus-set-mode-line 'summary))
9850           t))
9851     (gnus-summary-position-point)))
9852
9853 (defun gnus-summary-catchup-to-here (&optional all)
9854   "Mark all unticked articles before the current one as read.
9855 If ALL is non-nil, also mark ticked and dormant articles as read."
9856   (interactive "P")
9857   (save-excursion
9858     (gnus-save-hidden-threads
9859       (let ((beg (point)))
9860         ;; We check that there are unread articles.
9861         (when (or all (gnus-summary-find-prev))
9862           (gnus-summary-catchup all t beg)))))
9863   (gnus-summary-position-point))
9864
9865 (defun gnus-summary-catchup-from-here (&optional all)
9866   "Mark all unticked articles after the current one as read.
9867 If ALL is non-nil, also mark ticked and dormant articles as read."
9868   (interactive "P")
9869   (save-excursion
9870     (gnus-save-hidden-threads
9871       (let ((beg (point)))
9872         ;; We check that there are unread articles.
9873         (when (or all (gnus-summary-find-next))
9874           (gnus-summary-catchup all t beg nil t)))))
9875
9876   (gnus-summary-position-point))
9877 (defun gnus-summary-catchup-all (&optional quietly)
9878   "Mark all articles in this newsgroup as read."
9879   (interactive "P")
9880   (gnus-summary-catchup t quietly))
9881
9882 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9883   "Mark all unread articles in this group as read, then exit.
9884 If prefix argument ALL is non-nil, all articles are marked as read.
9885 If QUIETLY is non-nil, no questions will be asked."
9886   (interactive "P")
9887   (when (gnus-summary-catchup all quietly nil 'fast)
9888     ;; Select next newsgroup or exit.
9889     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9890              (eq gnus-auto-select-next 'quietly))
9891         (gnus-summary-next-group nil)
9892       (gnus-summary-exit))))
9893
9894 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9895   "Mark all articles in this newsgroup as read, and then exit."
9896   (interactive "P")
9897   (gnus-summary-catchup-and-exit t quietly))
9898
9899 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9900   "Mark all articles in this group as read and select the next group.
9901 If given a prefix, mark all articles, unread as well as ticked, as
9902 read."
9903   (interactive "P")
9904   (save-excursion
9905     (gnus-summary-catchup all))
9906   (gnus-summary-next-group))
9907
9908 ;;;
9909 ;;; with article
9910 ;;;
9911
9912 (defmacro gnus-with-article (article &rest forms)
9913   "Select ARTICLE and perform FORMS in the original article buffer.
9914 Then replace the article with the result."
9915   `(progn
9916      ;; We don't want the article to be marked as read.
9917      (let (gnus-mark-article-hook)
9918        (gnus-summary-select-article t t nil ,article))
9919      (set-buffer gnus-original-article-buffer)
9920      ,@forms
9921      (if (not (gnus-check-backend-function
9922                'request-replace-article (car gnus-article-current)))
9923          (gnus-message 5 "Read-only group; not replacing")
9924        (unless (gnus-request-replace-article
9925                 ,article (car gnus-article-current)
9926                 (current-buffer) t)
9927          (error "Couldn't replace article")))
9928      ;; The cache and backlog have to be flushed somewhat.
9929      (when gnus-keep-backlog
9930        (gnus-backlog-remove-article
9931         (car gnus-article-current) (cdr gnus-article-current)))
9932      (when gnus-use-cache
9933        (gnus-cache-update-article
9934         (car gnus-article-current) (cdr gnus-article-current)))))
9935
9936 (put 'gnus-with-article 'lisp-indent-function 1)
9937 (put 'gnus-with-article 'edebug-form-spec '(form body))
9938
9939 ;; Thread-based commands.
9940
9941 (defun gnus-summary-articles-in-thread (&optional article)
9942   "Return a list of all articles in the current thread.
9943 If ARTICLE is non-nil, return all articles in the thread that starts
9944 with that article."
9945   (let* ((article (or article (gnus-summary-article-number)))
9946          (data (gnus-data-find-list article))
9947          (top-level (gnus-data-level (car data)))
9948          (top-subject
9949           (cond ((null gnus-thread-operation-ignore-subject)
9950                  (gnus-simplify-subject-re
9951                   (mail-header-subject (gnus-data-header (car data)))))
9952                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9953                  (gnus-simplify-subject-fuzzy
9954                   (mail-header-subject (gnus-data-header (car data)))))
9955                 (t nil)))
9956          (end-point (save-excursion
9957                       (if (gnus-summary-go-to-next-thread)
9958                           (point) (point-max))))
9959          articles)
9960     (while (and data
9961                 (< (gnus-data-pos (car data)) end-point))
9962       (when (or (not top-subject)
9963                 (string= top-subject
9964                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9965                              (gnus-simplify-subject-fuzzy
9966                               (mail-header-subject
9967                                (gnus-data-header (car data))))
9968                            (gnus-simplify-subject-re
9969                             (mail-header-subject
9970                              (gnus-data-header (car data)))))))
9971         (push (gnus-data-number (car data)) articles))
9972       (unless (and (setq data (cdr data))
9973                    (> (gnus-data-level (car data)) top-level))
9974         (setq data nil)))
9975     ;; Return the list of articles.
9976     (nreverse articles)))
9977
9978 (defun gnus-summary-rethread-current ()
9979   "Rethread the thread the current article is part of."
9980   (interactive)
9981   (let* ((gnus-show-threads t)
9982          (article (gnus-summary-article-number))
9983          (id (mail-header-id (gnus-summary-article-header)))
9984          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9985     (unless id
9986       (error "No article on the current line"))
9987     (gnus-rebuild-thread id)
9988     (gnus-summary-goto-subject article)))
9989
9990 (defun gnus-summary-reparent-thread ()
9991   "Make the current article child of the marked (or previous) article.
9992
9993 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9994 is non-nil or the Subject: of both articles are the same."
9995   (interactive)
9996   (unless (not (gnus-group-read-only-p))
9997     (error "The current newsgroup does not support article editing"))
9998   (unless (<= (length gnus-newsgroup-processable) 1)
9999     (error "No more than one article may be marked"))
10000   (save-window-excursion
10001     (let ((gnus-article-buffer " *reparent*")
10002           (current-article (gnus-summary-article-number))
10003           ;; First grab the marked article, otherwise one line up.
10004           (parent-article (if (not (null gnus-newsgroup-processable))
10005                               (car gnus-newsgroup-processable)
10006                             (save-excursion
10007                               (if (eq (forward-line -1) 0)
10008                                   (gnus-summary-article-number)
10009                                 (error "Beginning of summary buffer"))))))
10010       (unless (not (eq current-article parent-article))
10011         (error "An article may not be self-referential"))
10012       (let ((message-id (mail-header-id
10013                          (gnus-summary-article-header parent-article))))
10014         (unless (and message-id (not (equal message-id "")))
10015           (error "No message-id in desired parent"))
10016         (gnus-with-article current-article
10017           (save-restriction
10018             (goto-char (point-min))
10019             (message-narrow-to-head)
10020             (if (re-search-forward "^References: " nil t)
10021                 (progn
10022                   (re-search-forward "^[^ \t]" nil t)
10023                   (forward-line -1)
10024                   (end-of-line)
10025                   (insert " " message-id))
10026               (insert "References: " message-id "\n"))))
10027         (set-buffer gnus-summary-buffer)
10028         (gnus-summary-unmark-all-processable)
10029         (gnus-summary-update-article current-article)
10030         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10031             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10032         (gnus-summary-rethread-current)
10033         (gnus-message 3 "Article %d is now the child of article %d"
10034                       current-article parent-article)))))
10035
10036 (defun gnus-summary-toggle-threads (&optional arg)
10037   "Toggle showing conversation threads.
10038 If ARG is positive number, turn showing conversation threads on."
10039   (interactive "P")
10040   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10041     (setq gnus-show-threads
10042           (if (null arg) (not gnus-show-threads)
10043             (> (prefix-numeric-value arg) 0)))
10044     (gnus-summary-prepare)
10045     (gnus-summary-goto-subject current)
10046     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10047     (gnus-summary-position-point)))
10048
10049 (defun gnus-summary-show-all-threads ()
10050   "Show all threads."
10051   (interactive)
10052   (save-excursion
10053     (let ((buffer-read-only nil))
10054       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10055   (gnus-summary-position-point))
10056
10057 (defun gnus-summary-show-thread ()
10058   "Show thread subtrees.
10059 Returns nil if no thread was there to be shown."
10060   (interactive)
10061   (let ((buffer-read-only nil)
10062         (orig (point))
10063         ;; first goto end then to beg, to have point at beg after let
10064         (end (progn (end-of-line) (point)))
10065         (beg (progn (beginning-of-line) (point))))
10066     (prog1
10067         ;; Any hidden lines here?
10068         (search-forward "\r" end t)
10069       (subst-char-in-region beg end ?\^M ?\n t)
10070       (goto-char orig)
10071       (gnus-summary-position-point))))
10072
10073 (defun gnus-summary-maybe-hide-threads ()
10074   "If requested, hide the threads that should be hidden."
10075   (when (and gnus-show-threads
10076              gnus-thread-hide-subtree)
10077     (gnus-summary-hide-all-threads
10078      (if (or (consp gnus-thread-hide-subtree)
10079              (gnus-functionp gnus-thread-hide-subtree))
10080          (gnus-make-predicate gnus-thread-hide-subtree)
10081        nil))))
10082
10083 ;;; Hiding predicates.
10084
10085 (defun gnus-article-unread-p (header)
10086   (memq (mail-header-number header) gnus-newsgroup-unreads))
10087
10088 (defun gnus-article-unseen-p (header)
10089   (memq (mail-header-number header) gnus-newsgroup-unseen))
10090
10091 (defun gnus-map-articles (predicate articles)
10092   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10093   (apply 'gnus-or (mapcar predicate
10094                           (mapcar 'gnus-summary-article-header articles))))
10095
10096 (defun gnus-summary-hide-all-threads (&optional predicate)
10097   "Hide all thread subtrees.
10098 If PREDICATE is supplied, threads that satisfy this predicate
10099 will not be hidden."
10100   (interactive)
10101   (save-excursion
10102     (goto-char (point-min))
10103     (let ((end nil))
10104       (while (not end)
10105         (when (or (not predicate)
10106                   (gnus-map-articles
10107                    predicate (gnus-summary-article-children)))
10108             (gnus-summary-hide-thread))
10109         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10110   (gnus-summary-position-point))
10111
10112 (defun gnus-summary-hide-thread ()
10113   "Hide thread subtrees.
10114 If PREDICATE is supplied, threads that satisfy this predicate
10115 will not be hidden.
10116 Returns nil if no threads were there to be hidden."
10117   (interactive)
10118   (let ((buffer-read-only nil)
10119         (start (point))
10120         (article (gnus-summary-article-number)))
10121     (goto-char start)
10122     ;; Go forward until either the buffer ends or the subthread
10123     ;; ends.
10124     (when (and (not (eobp))
10125                (or (zerop (gnus-summary-next-thread 1 t))
10126                    (goto-char (point-max))))
10127       (prog1
10128           (if (and (> (point) start)
10129                    (search-backward "\n" start t))
10130               (progn
10131                 (subst-char-in-region start (point) ?\n ?\^M)
10132                 (gnus-summary-goto-subject article))
10133             (goto-char start)
10134             nil)))))
10135
10136 (defun gnus-summary-go-to-next-thread (&optional previous)
10137   "Go to the same level (or less) next thread.
10138 If PREVIOUS is non-nil, go to previous thread instead.
10139 Return the article number moved to, or nil if moving was impossible."
10140   (let ((level (gnus-summary-thread-level))
10141         (way (if previous -1 1))
10142         (beg (point)))
10143     (forward-line way)
10144     (while (and (not (eobp))
10145                 (< level (gnus-summary-thread-level)))
10146       (forward-line way))
10147     (if (eobp)
10148         (progn
10149           (goto-char beg)
10150           nil)
10151       (setq beg (point))
10152       (prog1
10153           (gnus-summary-article-number)
10154         (goto-char beg)))))
10155
10156 (defun gnus-summary-next-thread (n &optional silent)
10157   "Go to the same level next N'th thread.
10158 If N is negative, search backward instead.
10159 Returns the difference between N and the number of skips actually
10160 done.
10161
10162 If SILENT, don't output messages."
10163   (interactive "p")
10164   (let ((backward (< n 0))
10165         (n (abs n)))
10166     (while (and (> n 0)
10167                 (gnus-summary-go-to-next-thread backward))
10168       (decf n))
10169     (unless silent
10170       (gnus-summary-position-point))
10171     (when (and (not silent) (/= 0 n))
10172       (gnus-message 7 "No more threads"))
10173     n))
10174
10175 (defun gnus-summary-prev-thread (n)
10176   "Go to the same level previous N'th thread.
10177 Returns the difference between N and the number of skips actually
10178 done."
10179   (interactive "p")
10180   (gnus-summary-next-thread (- n)))
10181
10182 (defun gnus-summary-go-down-thread ()
10183   "Go down one level in the current thread."
10184   (let ((children (gnus-summary-article-children)))
10185     (when children
10186       (gnus-summary-goto-subject (car children)))))
10187
10188 (defun gnus-summary-go-up-thread ()
10189   "Go up one level in the current thread."
10190   (let ((parent (gnus-summary-article-parent)))
10191     (when parent
10192       (gnus-summary-goto-subject parent))))
10193
10194 (defun gnus-summary-down-thread (n)
10195   "Go down thread N steps.
10196 If N is negative, go up instead.
10197 Returns the difference between N and how many steps down that were
10198 taken."
10199   (interactive "p")
10200   (let ((up (< n 0))
10201         (n (abs n)))
10202     (while (and (> n 0)
10203                 (if up (gnus-summary-go-up-thread)
10204                   (gnus-summary-go-down-thread)))
10205       (setq n (1- n)))
10206     (gnus-summary-position-point)
10207     (when (/= 0 n)
10208       (gnus-message 7 "Can't go further"))
10209     n))
10210
10211 (defun gnus-summary-up-thread (n)
10212   "Go up thread N steps.
10213 If N is negative, go down instead.
10214 Returns the difference between N and how many steps down that were
10215 taken."
10216   (interactive "p")
10217   (gnus-summary-down-thread (- n)))
10218
10219 (defun gnus-summary-top-thread ()
10220   "Go to the top of the thread."
10221   (interactive)
10222   (while (gnus-summary-go-up-thread))
10223   (gnus-summary-article-number))
10224
10225 (defun gnus-summary-kill-thread (&optional unmark)
10226   "Mark articles under current thread as read.
10227 If the prefix argument is positive, remove any kinds of marks.
10228 If the prefix argument is negative, tick articles instead."
10229   (interactive "P")
10230   (when unmark
10231     (setq unmark (prefix-numeric-value unmark)))
10232   (let ((articles (gnus-summary-articles-in-thread)))
10233     (save-excursion
10234       ;; Expand the thread.
10235       (gnus-summary-show-thread)
10236       ;; Mark all the articles.
10237       (while articles
10238         (gnus-summary-goto-subject (car articles))
10239         (cond ((null unmark)
10240                (gnus-summary-mark-article-as-read gnus-killed-mark))
10241               ((> unmark 0)
10242                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10243               (t
10244                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10245         (setq articles (cdr articles))))
10246     ;; Hide killed subtrees.
10247     (and (null unmark)
10248          gnus-thread-hide-killed
10249          (gnus-summary-hide-thread))
10250     ;; If marked as read, go to next unread subject.
10251     (when (null unmark)
10252       ;; Go to next unread subject.
10253       (gnus-summary-next-subject 1 t)))
10254   (gnus-set-mode-line 'summary))
10255
10256 ;; Summary sorting commands
10257
10258 (defun gnus-summary-sort-by-number (&optional reverse)
10259   "Sort the summary buffer by article number.
10260 Argument REVERSE means reverse order."
10261   (interactive "P")
10262   (gnus-summary-sort 'number reverse))
10263
10264 (defun gnus-summary-sort-by-random (&optional reverse)
10265   "Randomize the order in the summary buffer.
10266 Argument REVERSE means to randomize in reverse order."
10267   (interactive "P")
10268   (gnus-summary-sort 'random reverse))
10269
10270 (defun gnus-summary-sort-by-author (&optional reverse)
10271   "Sort the summary buffer by author name alphabetically.
10272 If `case-fold-search' is non-nil, case of letters is ignored.
10273 Argument REVERSE means reverse order."
10274   (interactive "P")
10275   (gnus-summary-sort 'author reverse))
10276
10277 (defun gnus-summary-sort-by-subject (&optional reverse)
10278   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10279 If `case-fold-search' is non-nil, case of letters is ignored.
10280 Argument REVERSE means reverse order."
10281   (interactive "P")
10282   (gnus-summary-sort 'subject reverse))
10283
10284 (defun gnus-summary-sort-by-date (&optional reverse)
10285   "Sort the summary buffer by date.
10286 Argument REVERSE means reverse order."
10287   (interactive "P")
10288   (gnus-summary-sort 'date reverse))
10289
10290 (defun gnus-summary-sort-by-score (&optional reverse)
10291   "Sort the summary buffer by score.
10292 Argument REVERSE means reverse order."
10293   (interactive "P")
10294   (gnus-summary-sort 'score reverse))
10295
10296 (defun gnus-summary-sort-by-lines (&optional reverse)
10297   "Sort the summary buffer by the number of lines.
10298 Argument REVERSE means reverse order."
10299   (interactive "P")
10300   (gnus-summary-sort 'lines reverse))
10301
10302 (defun gnus-summary-sort-by-chars (&optional reverse)
10303   "Sort the summary buffer by article length.
10304 Argument REVERSE means reverse order."
10305   (interactive "P")
10306   (gnus-summary-sort 'chars reverse))
10307
10308 (defun gnus-summary-sort-by-original (&optional reverse)
10309   "Sort the summary buffer using the default sorting method.
10310 Argument REVERSE means reverse order."
10311   (interactive "P")
10312   (let* ((buffer-read-only)
10313          (gnus-summary-prepare-hook nil))
10314     ;; We do the sorting by regenerating the threads.
10315     (gnus-summary-prepare)
10316     ;; Hide subthreads if needed.
10317     (gnus-summary-maybe-hide-threads)))
10318
10319 (defun gnus-summary-sort (predicate reverse)
10320   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10321   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10322          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10323          (gnus-thread-sort-functions
10324           (if (not reverse)
10325               thread
10326             `(lambda (t1 t2)
10327                (,thread t2 t1))))
10328          (gnus-sort-gathered-threads-function
10329           gnus-thread-sort-functions)
10330          (gnus-article-sort-functions
10331           (if (not reverse)
10332               article
10333             `(lambda (t1 t2)
10334                (,article t2 t1))))
10335          (buffer-read-only)
10336          (gnus-summary-prepare-hook nil))
10337     ;; We do the sorting by regenerating the threads.
10338     (gnus-summary-prepare)
10339     ;; Hide subthreads if needed.
10340     (gnus-summary-maybe-hide-threads)))
10341
10342 ;; Summary saving commands.
10343
10344 (defun gnus-summary-save-article (&optional n not-saved)
10345   "Save the current article using the default saver function.
10346 If N is a positive number, save the N next articles.
10347 If N is a negative number, save the N previous articles.
10348 If N is nil and any articles have been marked with the process mark,
10349 save those articles instead.
10350 The variable `gnus-default-article-saver' specifies the saver function."
10351   (interactive "P")
10352   (let* ((articles (gnus-summary-work-articles n))
10353          (save-buffer (save-excursion
10354                         (nnheader-set-temp-buffer " *Gnus Save*")))
10355          (num (length articles))
10356          header file)
10357     (dolist (article articles)
10358       (setq header (gnus-summary-article-header article))
10359       (if (not (vectorp header))
10360           ;; This is a pseudo-article.
10361           (if (assq 'name header)
10362               (gnus-copy-file (cdr (assq 'name header)))
10363             (gnus-message 1 "Article %d is unsaveable" article))
10364         ;; This is a real article.
10365         (save-window-excursion
10366           (let ((gnus-display-mime-function nil)
10367                 (gnus-article-prepare-hook nil))
10368             (gnus-summary-select-article t nil nil article)))
10369         (save-excursion
10370           (set-buffer save-buffer)
10371           (erase-buffer)
10372           (insert-buffer-substring gnus-original-article-buffer))
10373         (setq file (gnus-article-save save-buffer file num))
10374         (gnus-summary-remove-process-mark article)
10375         (unless not-saved
10376           (gnus-summary-set-saved-mark article))))
10377     (gnus-kill-buffer save-buffer)
10378     (gnus-summary-position-point)
10379     (gnus-set-mode-line 'summary)
10380     n))
10381
10382 (defun gnus-summary-pipe-output (&optional arg)
10383   "Pipe the current article to a subprocess.
10384 If N is a positive number, pipe the N next articles.
10385 If N is a negative number, pipe the N previous articles.
10386 If N is nil and any articles have been marked with the process mark,
10387 pipe those articles instead."
10388   (interactive "P")
10389   (require 'gnus-art)
10390   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10391     (gnus-summary-save-article arg t))
10392   (let ((buffer (get-buffer "*Shell Command Output*")))
10393     (if (and buffer
10394              (with-current-buffer buffer (> (point-max) (point-min))))
10395         (gnus-configure-windows 'pipe))))
10396
10397 (defun gnus-summary-save-article-mail (&optional arg)
10398   "Append the current article to an mail file.
10399 If N is a positive number, save the N next articles.
10400 If N is a negative number, save the N previous articles.
10401 If N is nil and any articles have been marked with the process mark,
10402 save those articles instead."
10403   (interactive "P")
10404   (require 'gnus-art)
10405   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10406     (gnus-summary-save-article arg)))
10407
10408 (defun gnus-summary-save-article-rmail (&optional arg)
10409   "Append the current article to an rmail file.
10410 If N is a positive number, save the N next articles.
10411 If N is a negative number, save the N previous articles.
10412 If N is nil and any articles have been marked with the process mark,
10413 save those articles instead."
10414   (interactive "P")
10415   (require 'gnus-art)
10416   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10417     (gnus-summary-save-article arg)))
10418
10419 (defun gnus-summary-save-article-file (&optional arg)
10420   "Append the current article to a 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-file))
10428     (gnus-summary-save-article arg)))
10429
10430 (defun gnus-summary-write-article-file (&optional arg)
10431   "Write the current article to a file, deleting the previous 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-write-to-file))
10439     (gnus-summary-save-article arg)))
10440
10441 (defun gnus-summary-save-article-body-file (&optional arg)
10442   "Append the current article body 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-body-in-file))
10450     (gnus-summary-save-article arg)))
10451
10452 (defun gnus-summary-muttprint (&optional arg)
10453   "Print the current article using Muttprint.
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-pipe-to-muttprint))
10461     (gnus-summary-save-article arg t)))
10462
10463 (defun gnus-summary-pipe-message (program)
10464   "Pipe the current article through PROGRAM."
10465   (interactive "sProgram: ")
10466   (gnus-summary-select-article)
10467   (let ((mail-header-separator ""))
10468     (gnus-eval-in-buffer-window gnus-article-buffer
10469       (save-restriction
10470         (widen)
10471         (let ((start (window-start))
10472               buffer-read-only)
10473           (message-pipe-buffer-body program)
10474           (set-window-start (get-buffer-window (current-buffer)) start))))))
10475
10476 (defun gnus-get-split-value (methods)
10477   "Return a value based on the split METHODS."
10478   (let (split-name method result match)
10479     (when methods
10480       (save-excursion
10481         (set-buffer gnus-original-article-buffer)
10482         (save-restriction
10483           (nnheader-narrow-to-headers)
10484           (while (and methods (not split-name))
10485             (goto-char (point-min))
10486             (setq method (pop methods))
10487             (setq match (car method))
10488             (when (cond
10489                    ((stringp match)
10490                     ;; Regular expression.
10491                     (ignore-errors
10492                       (re-search-forward match nil t)))
10493                    ((gnus-functionp match)
10494                     ;; Function.
10495                     (save-restriction
10496                       (widen)
10497                       (setq result (funcall match gnus-newsgroup-name))))
10498                    ((consp match)
10499                     ;; Form.
10500                     (save-restriction
10501                       (widen)
10502                       (setq result (eval match)))))
10503               (setq split-name (cdr method))
10504               (cond ((stringp result)
10505                      (push (expand-file-name
10506                             result gnus-article-save-directory)
10507                            split-name))
10508                     ((consp result)
10509                      (setq split-name (append result split-name)))))))))
10510     (nreverse split-name)))
10511
10512 (defun gnus-valid-move-group-p (group)
10513   (and (boundp group)
10514        (symbol-name group)
10515        (symbol-value group)
10516        (gnus-get-function (gnus-find-method-for-group
10517                            (symbol-name group)) 'request-accept-article t)))
10518
10519 (defun gnus-read-move-group-name (prompt default articles prefix)
10520   "Read a group name."
10521   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10522          (minibuffer-confirm-incomplete nil) ; XEmacs
10523          (prom
10524           (format "%s %s to:"
10525                   prompt
10526                   (if (> (length articles) 1)
10527                       (format "these %d articles" (length articles))
10528                     "this article")))
10529          (to-newsgroup
10530           (cond
10531            ((null split-name)
10532             (gnus-completing-read-with-default
10533              default prom
10534              gnus-active-hashtb
10535              'gnus-valid-move-group-p
10536              nil prefix
10537              'gnus-group-history))
10538            ((= 1 (length split-name))
10539             (gnus-completing-read-with-default
10540              (car split-name) prom
10541              gnus-active-hashtb
10542              'gnus-valid-move-group-p
10543              nil nil
10544              'gnus-group-history))
10545            (t
10546             (gnus-completing-read-with-default
10547              nil prom
10548              (mapcar (lambda (el) (list el))
10549                      (nreverse split-name))
10550              nil nil nil
10551              'gnus-group-history))))
10552          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10553     (when to-newsgroup
10554       (if (or (string= to-newsgroup "")
10555               (string= to-newsgroup prefix))
10556           (setq to-newsgroup default))
10557       (unless to-newsgroup
10558         (error "No group name entered"))
10559       (or (gnus-active to-newsgroup)
10560           (gnus-activate-group to-newsgroup nil nil to-method)
10561           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10562                                      to-newsgroup))
10563               (or (and (gnus-request-create-group to-newsgroup to-method)
10564                        (gnus-activate-group
10565                         to-newsgroup nil nil to-method)
10566                        (gnus-subscribe-group to-newsgroup))
10567                   (error "Couldn't create group %s" to-newsgroup)))
10568           (error "No such group: %s" to-newsgroup)))
10569     to-newsgroup))
10570
10571 (defun gnus-summary-save-parts (type dir n &optional reverse)
10572   "Save parts matching TYPE to DIR.
10573 If REVERSE, save parts that do not match TYPE."
10574   (interactive
10575    (list (read-string "Save parts of type: "
10576                       (or (car gnus-summary-save-parts-type-history)
10577                           gnus-summary-save-parts-default-mime)
10578                       'gnus-summary-save-parts-type-history)
10579          (setq gnus-summary-save-parts-last-directory
10580                (read-file-name "Save to directory: "
10581                                gnus-summary-save-parts-last-directory
10582                                nil t))
10583          current-prefix-arg))
10584   (gnus-summary-iterate n
10585     (let ((gnus-display-mime-function nil)
10586           (gnus-inhibit-treatment t))
10587       (gnus-summary-select-article))
10588     (save-excursion
10589       (set-buffer gnus-article-buffer)
10590       (let ((handles (or gnus-article-mime-handles
10591                          (mm-dissect-buffer nil gnus-article-loose-mime)
10592                          (mm-uu-dissect))))
10593         (when handles
10594           (gnus-summary-save-parts-1 type dir handles reverse)
10595           (unless gnus-article-mime-handles ;; Don't destroy this case.
10596             (mm-destroy-parts handles)))))))
10597
10598 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10599   (if (stringp (car handle))
10600       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10601               (cdr handle))
10602     (when (if reverse
10603               (not (string-match type (mm-handle-media-type handle)))
10604             (string-match type (mm-handle-media-type handle)))
10605       (let ((file (expand-file-name
10606                    (file-name-nondirectory
10607                     (or
10608                      (mail-content-type-get
10609                       (mm-handle-disposition handle) 'filename)
10610                      (concat gnus-newsgroup-name
10611                              "." (number-to-string
10612                                   (cdr gnus-article-current)))))
10613                    dir)))
10614         (unless (file-exists-p file)
10615           (mm-save-part-to-file handle file))))))
10616
10617 ;; Summary extract commands
10618
10619 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10620   (let ((buffer-read-only nil)
10621         (article (gnus-summary-article-number))
10622         after-article b e)
10623     (unless (gnus-summary-goto-subject article)
10624       (error "No such article: %d" article))
10625     (gnus-summary-position-point)
10626     ;; If all commands are to be bunched up on one line, we collect
10627     ;; them here.
10628     (unless gnus-view-pseudos-separately
10629       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10630             files action)
10631         (while ps
10632           (setq action (cdr (assq 'action (car ps))))
10633           (setq files (list (cdr (assq 'name (car ps)))))
10634           (while (and ps (cdr ps)
10635                       (string= (or action "1")
10636                                (or (cdr (assq 'action (cadr ps))) "2")))
10637             (push (cdr (assq 'name (cadr ps))) files)
10638             (setcdr ps (cddr ps)))
10639           (when files
10640             (when (not (string-match "%s" action))
10641               (push " " files))
10642             (push " " files)
10643             (when (assq 'execute (car ps))
10644               (setcdr (assq 'execute (car ps))
10645                       (funcall (if (string-match "%s" action)
10646                                    'format 'concat)
10647                                action
10648                                (mapconcat
10649                                 (lambda (f)
10650                                   (if (equal f " ")
10651                                       f
10652                                     (mm-quote-arg f)))
10653                                 files " ")))))
10654           (setq ps (cdr ps)))))
10655     (if (and gnus-view-pseudos (not not-view))
10656         (while pslist
10657           (when (assq 'execute (car pslist))
10658             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10659                                   (eq gnus-view-pseudos 'not-confirm)))
10660           (setq pslist (cdr pslist)))
10661       (save-excursion
10662         (while pslist
10663           (setq after-article (or (cdr (assq 'article (car pslist)))
10664                                   (gnus-summary-article-number)))
10665           (gnus-summary-goto-subject after-article)
10666           (forward-line 1)
10667           (setq b (point))
10668           (insert "    " (file-name-nondirectory
10669                           (cdr (assq 'name (car pslist))))
10670                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10671           (setq e (point))
10672           (forward-line -1)             ; back to `b'
10673           (gnus-add-text-properties
10674            b (1- e) (list 'gnus-number gnus-reffed-article-number
10675                           gnus-mouse-face-prop gnus-mouse-face))
10676           (gnus-data-enter
10677            after-article gnus-reffed-article-number
10678            gnus-unread-mark b (car pslist) 0 (- e b))
10679           (setq gnus-newsgroup-unreads
10680                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10681                                          gnus-reffed-article-number))
10682           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10683           (setq pslist (cdr pslist)))))))
10684
10685 (defun gnus-pseudos< (p1 p2)
10686   (let ((c1 (cdr (assq 'action p1)))
10687         (c2 (cdr (assq 'action p2))))
10688     (and c1 c2 (string< c1 c2))))
10689
10690 (defun gnus-request-pseudo-article (props)
10691   (cond ((assq 'execute props)
10692          (gnus-execute-command (cdr (assq 'execute props)))))
10693   (let ((gnus-current-article (gnus-summary-article-number)))
10694     (gnus-run-hooks 'gnus-mark-article-hook)))
10695
10696 (defun gnus-execute-command (command &optional automatic)
10697   (save-excursion
10698     (gnus-article-setup-buffer)
10699     (set-buffer gnus-article-buffer)
10700     (setq buffer-read-only nil)
10701     (let ((command (if automatic command
10702                      (read-string "Command: " (cons command 0)))))
10703       (erase-buffer)
10704       (insert "$ " command "\n\n")
10705       (if gnus-view-pseudo-asynchronously
10706           (start-process "gnus-execute" (current-buffer) shell-file-name
10707                          shell-command-switch command)
10708         (call-process shell-file-name nil t nil
10709                       shell-command-switch command)))))
10710
10711 ;; Summary kill commands.
10712
10713 (defun gnus-summary-edit-global-kill (article)
10714   "Edit the \"global\" kill file."
10715   (interactive (list (gnus-summary-article-number)))
10716   (gnus-group-edit-global-kill article))
10717
10718 (defun gnus-summary-edit-local-kill ()
10719   "Edit a local kill file applied to the current newsgroup."
10720   (interactive)
10721   (setq gnus-current-headers (gnus-summary-article-header))
10722   (gnus-group-edit-local-kill
10723    (gnus-summary-article-number) gnus-newsgroup-name))
10724
10725 ;;; Header reading.
10726
10727 (defun gnus-read-header (id &optional header)
10728   "Read the headers of article ID and enter them into the Gnus system."
10729   (let ((group gnus-newsgroup-name)
10730         (gnus-override-method
10731          (or
10732           gnus-override-method
10733           (and (gnus-news-group-p gnus-newsgroup-name)
10734                (car (gnus-refer-article-methods)))))
10735         where)
10736     ;; First we check to see whether the header in question is already
10737     ;; fetched.
10738     (if (stringp id)
10739         ;; This is a Message-ID.
10740         (setq header (or header (gnus-id-to-header id)))
10741       ;; This is an article number.
10742       (setq header (or header (gnus-summary-article-header id))))
10743     (if (and header
10744              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10745         ;; We have found the header.
10746         header
10747       ;; If this is a sparse article, we have to nix out its
10748       ;; previous entry in the thread hashtb.
10749       (when (and header
10750                  (gnus-summary-article-sparse-p (mail-header-number header)))
10751         (let* ((parent (gnus-parent-id (mail-header-references header)))
10752                (thread (and parent (gnus-id-to-thread parent))))
10753           (when thread
10754             (delq (assq header thread) thread))))
10755       ;; We have to really fetch the header to this article.
10756       (save-excursion
10757         (set-buffer nntp-server-buffer)
10758         (when (setq where (gnus-request-head id group))
10759           (nnheader-fold-continuation-lines)
10760           (goto-char (point-max))
10761           (insert ".\n")
10762           (goto-char (point-min))
10763           (insert "211 ")
10764           (princ (cond
10765                   ((numberp id) id)
10766                   ((cdr where) (cdr where))
10767                   (header (mail-header-number header))
10768                   (t gnus-reffed-article-number))
10769                  (current-buffer))
10770           (insert " Article retrieved.\n"))
10771         (if (or (not where)
10772                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10773             ()                          ; Malformed head.
10774           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10775             (when (and (stringp id)
10776                        (not (string= (gnus-group-real-name group)
10777                                      (car where))))
10778               ;; If we fetched by Message-ID and the article came
10779               ;; from a different group, we fudge some bogus article
10780               ;; numbers for this article.
10781               (mail-header-set-number header gnus-reffed-article-number))
10782             (save-excursion
10783               (set-buffer gnus-summary-buffer)
10784               (decf gnus-reffed-article-number)
10785               (gnus-remove-header (mail-header-number header))
10786               (push header gnus-newsgroup-headers)
10787               (setq gnus-current-headers header)
10788               (push (mail-header-number header) gnus-newsgroup-limit)))
10789           header)))))
10790
10791 (defun gnus-remove-header (number)
10792   "Remove header NUMBER from `gnus-newsgroup-headers'."
10793   (if (and gnus-newsgroup-headers
10794            (= number (mail-header-number (car gnus-newsgroup-headers))))
10795       (pop gnus-newsgroup-headers)
10796     (let ((headers gnus-newsgroup-headers))
10797       (while (and (cdr headers)
10798                   (not (= number (mail-header-number (cadr headers)))))
10799         (pop headers))
10800       (when (cdr headers)
10801         (setcdr headers (cddr headers))))))
10802
10803 ;;;
10804 ;;; summary highlights
10805 ;;;
10806
10807 (defun gnus-highlight-selected-summary ()
10808   "Highlight selected article in summary buffer."
10809   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10810   (when gnus-summary-selected-face
10811     (save-excursion
10812       (let* ((beg (progn (beginning-of-line) (point)))
10813              (end (progn (end-of-line) (point)))
10814              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10815              (from (if (get-text-property beg gnus-mouse-face-prop)
10816                        beg
10817                      (or (next-single-property-change
10818                           beg gnus-mouse-face-prop nil end)
10819                          beg)))
10820              (to
10821               (if (= from end)
10822                   (- from 2)
10823                 (or (next-single-property-change
10824                      from gnus-mouse-face-prop nil end)
10825                     end))))
10826         ;; If no mouse-face prop on line we will have to = from = end,
10827         ;; so we highlight the entire line instead.
10828         (when (= (+ to 2) from)
10829           (setq from beg)
10830           (setq to end))
10831         (if gnus-newsgroup-selected-overlay
10832             ;; Move old overlay.
10833             (gnus-move-overlay
10834              gnus-newsgroup-selected-overlay from to (current-buffer))
10835           ;; Create new overlay.
10836           (gnus-overlay-put
10837            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10838            'face gnus-summary-selected-face))))))
10839
10840 (defvar gnus-summary-highlight-line-cached nil)
10841 (defvar gnus-summary-highlight-line-trigger nil)
10842 (defun gnus-summary-highlight-line-0 ()
10843   (if (and (eq gnus-summary-highlight-line-trigger 
10844                gnus-summary-highlight)
10845            gnus-summary-highlight-line-cached)
10846       gnus-summary-highlight-line-cached
10847     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
10848           gnus-summary-highlight-line-cached
10849           (let* ((cond (list 'cond))
10850                  (c cond)
10851                  (list gnus-summary-highlight))
10852             (while list
10853               (setcdr c (cons (list (caar list) (list 'quote (cdar list))) nil))
10854               (setq c (cdr c)
10855                     list (cdr list)))
10856             (gnus-byte-compile (list 'lambda nil cond))))))
10857
10858 (defvar gnus-summary-highlight-line-downloaded-alist nil)
10859 (defvar gnus-summary-highlight-line-downloaded-cached nil)
10860
10861 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10862 (defun gnus-summary-highlight-line ()
10863   "Highlight current line according to `gnus-summary-highlight'."
10864   (let* ((list gnus-summary-highlight)
10865          (beg (gnus-point-at-bol))
10866          (article (gnus-summary-article-number))
10867          (score (or (cdr (assq (or article gnus-current-article)
10868                                gnus-newsgroup-scored))
10869                     gnus-summary-default-score 0))
10870          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10871          (inhibit-read-only t)
10872          (default gnus-summary-default-score)
10873          (default-high gnus-summary-default-high-score)
10874          (default-low gnus-summary-default-low-score)
10875          (downloaded (and (boundp 'gnus-agent-article-alist)
10876                           gnus-agent-article-alist
10877                           ;; Optimized for when gnus-summary-highlight-line is called multiple times for articles in ascending order (i.e. initial generation of summary buffer).
10878                           (progn 
10879                             (if (and (eq gnus-summary-highlight-line-downloaded-alist gnus-agent-article-alist)
10880                                      (<= (caar gnus-summary-highlight-line-downloaded-cached) article))
10881                                 nil
10882                               (setq gnus-summary-highlight-line-downloaded-alist  gnus-agent-article-alist
10883                                     gnus-summary-highlight-line-downloaded-cached gnus-agent-article-alist))
10884                             (let (n)
10885                               (while (and (< (caar gnus-summary-highlight-line-downloaded-cached) article)
10886                                           (setq n (cdr gnus-summary-highlight-line-downloaded-cached)))
10887                                 (setq gnus-summary-highlight-line-downloaded-cached n)))
10888                             (and (eq (caar gnus-summary-highlight-line-downloaded-cached) article)
10889                                  (cdar gnus-summary-highlight-line-downloaded-cached))))))
10890     (let ((face (funcall (gnus-summary-highlight-line-0))))
10891       (unless (eq face (get-text-property beg 'face))
10892         (gnus-put-text-property-excluding-characters-with-faces
10893          beg (gnus-point-at-eol) 'face
10894          (setq face (if (boundp face) (symbol-value face) face)))
10895         (when gnus-summary-highlight-line-function
10896           (funcall gnus-summary-highlight-line-function article face))))))
10897
10898 (defun gnus-update-read-articles (group unread &optional compute)
10899   "Update the list of read articles in GROUP.
10900 UNREAD is a sorted list."
10901   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10902          (entry (gnus-gethash group gnus-newsrc-hashtb))
10903          (info (nth 2 entry))
10904          (prev 1)
10905          read)
10906     (if (or (not info) (not active))
10907         ;; There is no info on this group if it was, in fact,
10908         ;; killed.  Gnus stores no information on killed groups, so
10909         ;; there's nothing to be done.
10910         ;; One could store the information somewhere temporarily,
10911         ;; perhaps...  Hmmm...
10912         ()
10913       ;; Remove any negative articles numbers.
10914       (while (and unread (< (car unread) 0))
10915         (setq unread (cdr unread)))
10916       ;; Remove any expired article numbers
10917       (while (and unread (< (car unread) (car active)))
10918         (setq unread (cdr unread)))
10919       ;; Compute the ranges of read articles by looking at the list of
10920       ;; unread articles.
10921       (while unread
10922         (when (/= (car unread) prev)
10923           (push (if (= prev (1- (car unread))) prev
10924                   (cons prev (1- (car unread))))
10925                 read))
10926         (setq prev (1+ (car unread)))
10927         (setq unread (cdr unread)))
10928       (when (<= prev (cdr active))
10929         (push (cons prev (cdr active)) read))
10930       (setq read (if (> (length read) 1) (nreverse read) read))
10931       (if compute
10932           read
10933         (save-excursion
10934           (let (setmarkundo)
10935             ;; Propagate the read marks to the backend.
10936             (when (gnus-check-backend-function 'request-set-mark group)
10937               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10938                     (add (gnus-remove-from-range read (gnus-info-read info))))
10939                 (when (or add del)
10940                   (unless (gnus-check-group group)
10941                     (error "Can't open server for %s" group))
10942                   (gnus-request-set-mark
10943                    group (delq nil (list (if add (list add 'add '(read)))
10944                                          (if del (list del 'del '(read))))))
10945                   (setq setmarkundo
10946                         `(gnus-request-set-mark
10947                           ,group
10948                           ',(delq nil (list
10949                                        (if del (list del 'add '(read)))
10950                                        (if add (list add 'del '(read))))))))))
10951             (set-buffer gnus-group-buffer)
10952             (gnus-undo-register
10953               `(progn
10954                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10955                  (gnus-info-set-read ',info ',(gnus-info-read info))
10956                  (gnus-get-unread-articles-in-group ',info
10957                                                     (gnus-active ,group))
10958                  (gnus-group-update-group ,group t)
10959                  ,setmarkundo))))
10960         ;; Enter this list into the group info.
10961         (gnus-info-set-read info read)
10962         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10963         (gnus-get-unread-articles-in-group info (gnus-active group))
10964         t))))
10965
10966 (defun gnus-offer-save-summaries ()
10967   "Offer to save all active summary buffers."
10968   (let (buffers)
10969     ;; Go through all buffers and find all summaries.
10970     (dolist (buffer (buffer-list))
10971       (when (and (setq buffer (buffer-name buffer))
10972                  (string-match "Summary" buffer)
10973                  (save-excursion
10974                    (set-buffer buffer)
10975                    ;; We check that this is, indeed, a summary buffer.
10976                    (and (eq major-mode 'gnus-summary-mode)
10977                         ;; Also make sure this isn't bogus.
10978                         gnus-newsgroup-prepared
10979                         ;; Also make sure that this isn't a
10980                         ;; dead summary buffer.
10981                         (not gnus-dead-summary-mode))))
10982         (push buffer buffers)))
10983     ;; Go through all these summary buffers and offer to save them.
10984     (when buffers
10985       (save-excursion
10986         (map-y-or-n-p
10987          "Update summary buffer %s? "
10988          (lambda (buf)
10989            (switch-to-buffer buf)
10990            (gnus-summary-exit))
10991          buffers)))))
10992
10993 (defun gnus-summary-setup-default-charset ()
10994   "Setup newsgroup default charset."
10995   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10996       (setq gnus-newsgroup-charset nil)
10997     (let* ((ignored-charsets
10998             (or gnus-newsgroup-ephemeral-ignored-charsets
10999                 (append
11000                  (and gnus-newsgroup-name
11001                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11002                  gnus-newsgroup-ignored-charsets))))
11003       (setq gnus-newsgroup-charset
11004             (or gnus-newsgroup-ephemeral-charset
11005                 (and gnus-newsgroup-name
11006                      (gnus-parameter-charset gnus-newsgroup-name))
11007                 gnus-default-charset))
11008       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11009            ignored-charsets))))
11010
11011 ;;;
11012 ;;; Mime Commands
11013 ;;;
11014
11015 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11016   "Display the current article buffer fully MIME-buttonized.
11017 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11018 treated as multipart/mixed."
11019   (interactive "P")
11020   (require 'gnus-art)
11021   (let ((gnus-unbuttonized-mime-types nil)
11022         (gnus-mime-display-multipart-as-mixed show-all-parts))
11023     (gnus-summary-show-article)))
11024
11025 (defun gnus-summary-repair-multipart (article)
11026   "Add a Content-Type header to a multipart article without one."
11027   (interactive (list (gnus-summary-article-number)))
11028   (gnus-with-article article
11029     (message-narrow-to-head)
11030     (message-remove-header "Mime-Version")
11031     (goto-char (point-max))
11032     (insert "Mime-Version: 1.0\n")
11033     (widen)
11034     (when (search-forward "\n--" nil t)
11035       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11036         (message-narrow-to-head)
11037         (message-remove-header "Content-Type")
11038         (goto-char (point-max))
11039         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11040                         separator))
11041         (widen))))
11042   (let (gnus-mark-article-hook)
11043     (gnus-summary-select-article t t nil article)))
11044
11045 (defun gnus-summary-toggle-display-buttonized ()
11046   "Toggle the buttonizing of the article buffer."
11047   (interactive)
11048   (require 'gnus-art)
11049   (if (setq gnus-inhibit-mime-unbuttonizing
11050             (not gnus-inhibit-mime-unbuttonizing))
11051       (let ((gnus-unbuttonized-mime-types nil))
11052         (gnus-summary-show-article))
11053     (gnus-summary-show-article)))
11054
11055 ;;;
11056 ;;; Generic summary marking commands
11057 ;;;
11058
11059 (defvar gnus-summary-marking-alist
11060   '((read gnus-del-mark "d")
11061     (unread gnus-unread-mark "u")
11062     (ticked gnus-ticked-mark "!")
11063     (dormant gnus-dormant-mark "?")
11064     (expirable gnus-expirable-mark "e"))
11065   "An alist of names/marks/keystrokes.")
11066
11067 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11068 (defvar gnus-summary-mark-map)
11069
11070 (defun gnus-summary-make-all-marking-commands ()
11071   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11072   (dolist (elem gnus-summary-marking-alist)
11073     (apply 'gnus-summary-make-marking-command elem)))
11074
11075 (defun gnus-summary-make-marking-command (name mark keystroke)
11076   (let ((map (make-sparse-keymap)))
11077     (define-key gnus-summary-generic-mark-map keystroke map)
11078     (dolist (lway `((next "next" next nil "n")
11079                     (next-unread "next unread" next t "N")
11080                     (prev "previous" prev nil "p")
11081                     (prev-unread "previous unread" prev t "P")
11082                     (nomove "" nil nil ,keystroke)))
11083       (let ((func (gnus-summary-make-marking-command-1
11084                    mark (car lway) lway name)))
11085         (setq func (eval func))
11086         (define-key map (nth 4 lway) func)))))
11087
11088 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11089   `(defun ,(intern
11090             (format "gnus-summary-put-mark-as-%s%s"
11091                     name (if (eq way 'nomove)
11092                              ""
11093                            (concat "-" (symbol-name way)))))
11094      (n)
11095      ,(format
11096        "Mark the current article as %s%s.
11097 If N, the prefix, then repeat N times.
11098 If N is negative, move in reverse order.
11099 The difference between N and the actual number of articles marked is
11100 returned."
11101        name (cadr lway))
11102      (interactive "p")
11103      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11104
11105 (defun gnus-summary-generic-mark (n mark move unread)
11106   "Mark N articles with MARK."
11107   (unless (eq major-mode 'gnus-summary-mode)
11108     (error "This command can only be used in the summary buffer"))
11109   (gnus-summary-show-thread)
11110   (let ((nummove
11111          (cond
11112           ((eq move 'next) 1)
11113           ((eq move 'prev) -1)
11114           (t 0))))
11115     (if (zerop nummove)
11116         (setq n 1)
11117       (when (< n 0)
11118         (setq n (abs n)
11119               nummove (* -1 nummove))))
11120     (while (and (> n 0)
11121                 (gnus-summary-mark-article nil mark)
11122                 (zerop (gnus-summary-next-subject nummove unread t)))
11123       (setq n (1- n)))
11124     (when (/= 0 n)
11125       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11126     (gnus-summary-recenter)
11127     (gnus-summary-position-point)
11128     (gnus-set-mode-line 'summary)
11129     n))
11130
11131 (defun gnus-summary-insert-articles (articles)
11132   (when (setq articles
11133               (gnus-sorted-difference articles
11134                                       (mapcar (lambda (h)
11135                                                 (mail-header-number h))
11136                                               gnus-newsgroup-headers)))
11137     (setq gnus-newsgroup-headers
11138           (merge 'list
11139                  gnus-newsgroup-headers
11140                  (gnus-fetch-headers articles)
11141                  'gnus-article-sort-by-number))
11142     ;; Suppress duplicates?
11143     (when gnus-suppress-duplicates
11144       (gnus-dup-suppress-articles))
11145
11146     ;; We might want to build some more threads first.
11147     (when (and gnus-fetch-old-headers
11148                (eq gnus-headers-retrieved-by 'nov))
11149       (if (eq gnus-fetch-old-headers 'invisible)
11150           (gnus-build-all-threads)
11151         (gnus-build-old-threads)))
11152     ;; Let the Gnus agent mark articles as read.
11153     (when gnus-agent
11154       (gnus-agent-get-undownloaded-list))
11155     ;; Remove list identifiers from subject
11156     (when gnus-list-identifiers
11157       (gnus-summary-remove-list-identifiers))
11158     ;; First and last article in this newsgroup.
11159     (when gnus-newsgroup-headers
11160       (setq gnus-newsgroup-begin
11161             (mail-header-number (car gnus-newsgroup-headers))
11162             gnus-newsgroup-end
11163             (mail-header-number
11164              (gnus-last-element gnus-newsgroup-headers))))
11165     (when gnus-use-scoring
11166       (gnus-possibly-score-headers))))
11167
11168 (defun gnus-summary-insert-old-articles (&optional all)
11169   "Insert all old articles in this group.
11170 If ALL is non-nil, already read articles become readable.
11171 If ALL is a number, fetch this number of articles."
11172   (interactive "P")
11173   (prog1
11174       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11175             older len)
11176         (setq older
11177 ;;; Some nntp servers lie about their active range.  When this happens, the active range can be in the millions.  
11178 ;;;           (gnus-sorted-difference
11179 ;;;            (gnus-uncompress-range (list gnus-newsgroup-active))
11180 ;;;            old)
11181               (gnus-range-difference (list gnus-newsgroup-active) old))
11182         (setq len (gnus-range-length older))
11183         (cond
11184          ((null older) nil)
11185          ((numberp all)
11186           (if (< all len)
11187               (let ((older-range (nreverse older)))
11188                 (setq older nil)
11189
11190                 (while (> all 0)
11191                   (let* ((r (pop older-range))
11192                          (min (if (numberp r) r (car r)))
11193                          (max (if (numberp r) r (cdr r))))
11194                     (while (and (<= min max)
11195                                 (> all 0))
11196                       (push max older)
11197                       (setq all (1- all)
11198                             max (1- max))))))
11199             (setq older (gnus-uncompress-range older))))
11200          (all nil)
11201          (t
11202           (if (and (numberp gnus-large-newsgroup)
11203                    (> len gnus-large-newsgroup))
11204               (let* ((cursor-in-echo-area nil)
11205                      (initial (gnus-parameter-large-newsgroup-initial
11206                                gnus-newsgroup-name))
11207                      (input
11208                       (read-string
11209                        (format
11210                         "How many articles from %s (%s %d): "
11211                         (gnus-limit-string
11212                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11213                         (if initial "max" "default")
11214                         len)
11215                        (if initial
11216                            (cons (number-to-string initial)
11217                                  0)))))
11218                 (unless (string-match "^[ \t]*$" input)
11219                   (setq all (string-to-number input))
11220                   (if (< all len)
11221                       (let ((older-range (nreverse older)))
11222                         (setq older nil)
11223
11224                         (while (> all 0)
11225                           (let* ((r (pop older-range))
11226                                  (min (if (numberp r) r (car r)))
11227                                  (max (if (numberp r) r (cdr r))))
11228                             (while (and (<= min max)
11229                                         (> all 0))
11230                               (push max older)
11231                               (setq all (1- all)
11232                                     max (1- max))))))
11233                     (setq older (gnus-uncompress-range older))))))))
11234         (if (not older)
11235             (message "No old news.")
11236           (gnus-summary-insert-articles older)
11237           (gnus-summary-limit (gnus-sorted-nunion old older))))
11238     (gnus-summary-position-point)))
11239
11240 (defun gnus-summary-insert-new-articles ()
11241   "Insert all new articles in this group."
11242   (interactive)
11243   (prog1
11244       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11245             (old-active gnus-newsgroup-active)
11246             (nnmail-fetched-sources (list t))
11247             i new)
11248         (setq gnus-newsgroup-active
11249               (gnus-activate-group gnus-newsgroup-name 'scan))
11250         (setq i (cdr gnus-newsgroup-active))
11251         (while (> i (cdr old-active))
11252           (push i new)
11253           (decf i))
11254         (if (not new)
11255             (message "No gnus is bad news.")
11256           (gnus-summary-insert-articles new)
11257           (setq gnus-newsgroup-unreads
11258                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11259           (gnus-summary-limit (gnus-sorted-nunion old new))))
11260     (gnus-summary-position-point)))
11261
11262 (gnus-summary-make-all-marking-commands)
11263
11264 (gnus-ems-redefine)
11265
11266 (provide 'gnus-sum)
11267
11268 (run-hooks 'gnus-sum-load-hook)
11269
11270 ;;; gnus-sum.el ends here