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