(gnus-uu-binhex-article, gnus-uu-reginize-string, gnus-uu-expand-numbers)
[bpt/emacs.git] / lisp / gnus / gnus-sum.el
CommitLineData
eec82323 1;;; gnus-sum.el --- summary mode commands for Gnus
676a7cc9 2;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
16409b0b 3;; Free Software Foundation, Inc.
eec82323 4
6748645f 5;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
6;; Keywords: news
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
24
25;;; Commentary:
26
27;;; Code:
28
5ab7173c
RS
29(eval-when-compile (require 'cl))
30
eec82323
LMI
31(require 'gnus)
32(require 'gnus-group)
33(require 'gnus-spec)
34(require 'gnus-range)
35(require 'gnus-int)
36(require 'gnus-undo)
6748645f 37(require 'gnus-util)
16409b0b 38(require 'mm-decode)
08c9a385
DL
39;; Recursive :-(.
40;; (require 'gnus-art)
41(require 'nnoo)
6748645f 42(autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
d4dfaa19 43(autoload 'gnus-cache-write-active "gnus-cache")
08c9a385 44(autoload 'mm-uu-dissect "mm-uu")
eec82323
LMI
45
46(defcustom gnus-kill-summary-on-exit t
47 "*If non-nil, kill the summary buffer when you exit from it.
48If nil, the summary will become a \"*Dead Summary*\" buffer, and
49it will be killed sometime later."
50 :group 'gnus-summary-exit
51 :type 'boolean)
52
53(defcustom gnus-fetch-old-headers nil
54 "*Non-nil means that Gnus will try to build threads by grabbing old headers.
55If an unread article in the group refers to an older, already read (or
56just marked as read) article, the old article will not normally be
57displayed in the Summary buffer. If this variable is non-nil, Gnus
58will attempt to grab the headers to the old articles, and thereby
6748645f
LMI
59build complete threads. If it has the value `some', only enough
60headers to connect otherwise loose threads will be displayed. This
61variable can also be a number. In that case, no more than that number
62of old headers will be fetched. If it has the value `invisible', all
63old headers will be fetched, but none will be displayed.
eec82323
LMI
64
65The server has to support NOV for any of this to work."
66 :group 'gnus-thread
67 :type '(choice (const :tag "off" nil)
68 (const some)
69 number
70 (sexp :menu-tag "other" t)))
71
6748645f
LMI
72(defcustom gnus-refer-thread-limit 200
73 "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
74If t, fetch all the available old headers."
75 :group 'gnus-thread
76 :type '(choice number
77 (sexp :menu-tag "other" t)))
78
eec82323
LMI
79(defcustom gnus-summary-make-false-root 'adopt
80 "*nil means that Gnus won't gather loose threads.
81If the root of a thread has expired or been read in a previous
82session, the information necessary to build a complete thread has been
83lost. Instead of having many small sub-threads from this original thread
84scattered all over the summary buffer, Gnus can gather them.
85
86If non-nil, Gnus will try to gather all loose sub-threads from an
87original thread into one large thread.
88
89If this variable is non-nil, it should be one of `none', `adopt',
90`dummy' or `empty'.
91
92If this variable is `none', Gnus will not make a false root, but just
93present the sub-threads after another.
94If this variable is `dummy', Gnus will create a dummy root that will
95have all the sub-threads as children.
96If this variable is `adopt', Gnus will make one of the \"children\"
97the parent and mark all the step-children as such.
98If this variable is `empty', the \"children\" are printed with empty
99subject fields. (Or rather, they will be printed with a string
100given by the `gnus-summary-same-subject' variable.)"
101 :group 'gnus-thread
102 :type '(choice (const :tag "off" nil)
103 (const none)
104 (const dummy)
105 (const adopt)
106 (const empty)))
107
108(defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
109 "*A regexp to match subjects to be excluded from loose thread gathering.
110As loose thread gathering is done on subjects only, that means that
111there can be many false gatherings performed. By rooting out certain
112common subjects, gathering might become saner."
113 :group 'gnus-thread
114 :type 'regexp)
115
116(defcustom gnus-summary-gather-subject-limit nil
117 "*Maximum length of subject comparisons when gathering loose threads.
118Use nil to compare full subjects. Setting this variable to a low
119number will help gather threads that have been corrupted by
120newsreaders chopping off subject lines, but it might also mean that
121unrelated articles that have subject that happen to begin with the
122same few characters will be incorrectly gathered.
123
124If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
125comparing subjects."
126 :group 'gnus-thread
127 :type '(choice (const :tag "off" nil)
128 (const fuzzy)
129 (sexp :menu-tag "on" t)))
130
6748645f
LMI
131(defcustom gnus-simplify-subject-functions nil
132 "List of functions taking a string argument that simplify subjects.
133The functions are applied recursively.
134
135Useful functions to put in this list include: `gnus-simplify-subject-re',
136`gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
137 :group 'gnus-thread
138 :type '(repeat function))
139
eec82323
LMI
140(defcustom gnus-simplify-ignored-prefixes nil
141 "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
142 :group 'gnus-thread
143 :type '(choice (const :tag "off" nil)
144 regexp))
145
146(defcustom gnus-build-sparse-threads nil
147 "*If non-nil, fill in the gaps in threads.
148If `some', only fill in the gaps that are needed to tie loose threads
149together. If `more', fill in all leaf nodes that Gnus can find. If
150non-nil and non-`some', fill in all gaps that Gnus manages to guess."
151 :group 'gnus-thread
152 :type '(choice (const :tag "off" nil)
153 (const some)
154 (const more)
155 (sexp :menu-tag "all" t)))
156
157(defcustom gnus-summary-thread-gathering-function
158 'gnus-gather-threads-by-subject
6748645f 159 "*Function used for gathering loose threads.
eec82323
LMI
160There are two pre-defined functions: `gnus-gather-threads-by-subject',
161which only takes Subjects into consideration; and
162`gnus-gather-threads-by-references', which compared the References
163headers of the articles to find matches."
164 :group 'gnus-thread
22115a9e
RS
165 :type '(radio (function-item gnus-gather-threads-by-subject)
166 (function-item gnus-gather-threads-by-references)
167 (function :tag "other")))
eec82323 168
eec82323
LMI
169(defcustom gnus-summary-same-subject ""
170 "*String indicating that the current article has the same subject as the previous.
171This variable will only be used if the value of
172`gnus-summary-make-false-root' is `empty'."
173 :group 'gnus-summary-format
174 :type 'string)
175
176(defcustom gnus-summary-goto-unread t
16409b0b
GM
177 "*If t, many commands will go to the next unread article.
178This applies to marking commands as well as other commands that
179\"naturally\" select the next article, like, for instance, `SPC' at
180the end of an article.
181
182If nil, the marking commands do NOT go to the next unread article
183(they go to the next article instead). If `never', commands that
184usually go to the next unread article, will go to the next article,
185whether it is read or not."
eec82323
LMI
186 :group 'gnus-summary-marks
187 :link '(custom-manual "(gnus)Setting Marks")
188 :type '(choice (const :tag "off" nil)
189 (const never)
190 (sexp :menu-tag "on" t)))
191
192(defcustom gnus-summary-default-score 0
193 "*Default article score level.
194All scores generated by the score files will be added to this score.
195If this variable is nil, scoring will be disabled."
196 :group 'gnus-score-default
197 :type '(choice (const :tag "disable")
198 integer))
199
200(defcustom gnus-summary-zcore-fuzz 0
201 "*Fuzziness factor for the zcore in the summary buffer.
202Articles with scores closer than this to `gnus-summary-default-score'
203will not be marked."
204 :group 'gnus-summary-format
205 :type 'integer)
206
207(defcustom gnus-simplify-subject-fuzzy-regexp nil
208 "*Strings to be removed when doing fuzzy matches.
209This can either be a regular expression or list of regular expressions
210that will be removed from subject strings if fuzzy subject
211simplification is selected."
212 :group 'gnus-thread
213 :type '(repeat regexp))
214
215(defcustom gnus-show-threads t
216 "*If non-nil, display threads in summary mode."
217 :group 'gnus-thread
218 :type 'boolean)
219
220(defcustom gnus-thread-hide-subtree nil
221 "*If non-nil, hide all threads initially.
222If threads are hidden, you have to run the command
223`gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
224to expose hidden threads."
225 :group 'gnus-thread
226 :type 'boolean)
227
228(defcustom gnus-thread-hide-killed t
229 "*If non-nil, hide killed threads automatically."
230 :group 'gnus-thread
231 :type 'boolean)
232
6748645f
LMI
233(defcustom gnus-thread-ignore-subject t
234 "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
235If nil, articles that have different subjects from their parents will
236start separate threads."
eec82323
LMI
237 :group 'gnus-thread
238 :type 'boolean)
239
240(defcustom gnus-thread-operation-ignore-subject t
241 "*If non-nil, subjects will be ignored when doing thread commands.
242This affects commands like `gnus-summary-kill-thread' and
243`gnus-summary-lower-thread'.
244
245If this variable is nil, articles in the same thread with different
246subjects will not be included in the operation in question. If this
247variable is `fuzzy', only articles that have subjects that are fuzzily
248equal will be included."
249 :group 'gnus-thread
250 :type '(choice (const :tag "off" nil)
251 (const fuzzy)
252 (sexp :tag "on" t)))
253
254(defcustom gnus-thread-indent-level 4
255 "*Number that says how much each sub-thread should be indented."
256 :group 'gnus-thread
257 :type 'integer)
258
259(defcustom gnus-auto-extend-newsgroup t
260 "*If non-nil, extend newsgroup forward and backward when requested."
261 :group 'gnus-summary-choose
262 :type 'boolean)
263
264(defcustom gnus-auto-select-first t
265 "*If nil, don't select the first unread article when entering a group.
266If this variable is `best', select the highest-scored unread article
16409b0b
GM
267in the group. If t, select the first unread article.
268
269This variable can also be a function to place point on a likely
270subject line. Useful values include `gnus-summary-first-unread-subject',
271`gnus-summary-first-unread-article' and
272`gnus-summary-best-unread-article'.
eec82323
LMI
273
274If you want to prevent automatic selection of the first unread article
275in some newsgroups, set the variable to nil in
276`gnus-select-group-hook'."
277 :group 'gnus-group-select
278 :type '(choice (const :tag "none" nil)
279 (const best)
16409b0b
GM
280 (sexp :menu-tag "first" t)
281 (function-item gnus-summary-first-unread-subject)
282 (function-item gnus-summary-first-unread-article)
283 (function-item gnus-summary-best-unread-article)))
eec82323
LMI
284
285(defcustom gnus-auto-select-next t
286 "*If non-nil, offer to go to the next group from the end of the previous.
287If the value is t and the next newsgroup is empty, Gnus will exit
288summary mode and go back to group mode. If the value is neither nil
289nor t, Gnus will select the following unread newsgroup. In
290particular, if the value is the symbol `quietly', the next unread
291newsgroup will be selected without any confirmation, and if it is
292`almost-quietly', the next group will be selected without any
293confirmation if you are located on the last article in the group.
294Finally, if this variable is `slightly-quietly', the `Z n' command
295will go to the next group without confirmation."
296 :group 'gnus-summary-maneuvering
297 :type '(choice (const :tag "off" nil)
298 (const quietly)
299 (const almost-quietly)
300 (const slightly-quietly)
301 (sexp :menu-tag "on" t)))
302
303(defcustom gnus-auto-select-same nil
6748645f
LMI
304 "*If non-nil, select the next article with the same subject.
305If there are no more articles with the same subject, go to
306the first unread article."
eec82323
LMI
307 :group 'gnus-summary-maneuvering
308 :type 'boolean)
309
310(defcustom gnus-summary-check-current nil
311 "*If non-nil, consider the current article when moving.
312The \"unread\" movement commands will stay on the same line if the
313current article is unread."
314 :group 'gnus-summary-maneuvering
315 :type 'boolean)
316
317(defcustom gnus-auto-center-summary t
318 "*If non-nil, always center the current summary buffer.
319In particular, if `vertical' do only vertical recentering. If non-nil
320and non-`vertical', do both horizontal and vertical recentering."
321 :group 'gnus-summary-maneuvering
322 :type '(choice (const :tag "none" nil)
323 (const vertical)
16409b0b 324 (integer :tag "height")
eec82323
LMI
325 (sexp :menu-tag "both" t)))
326
327(defcustom gnus-show-all-headers nil
328 "*If non-nil, don't hide any headers."
329 :group 'gnus-article-hiding
330 :group 'gnus-article-headers
331 :type 'boolean)
332
333(defcustom gnus-summary-ignore-duplicates nil
334 "*If non-nil, ignore articles with identical Message-ID headers."
335 :group 'gnus-summary
336 :type 'boolean)
6748645f 337
eec82323
LMI
338(defcustom gnus-single-article-buffer t
339 "*If non-nil, display all articles in the same buffer.
340If nil, each group will get its own article buffer."
341 :group 'gnus-article-various
342 :type 'boolean)
343
344(defcustom gnus-break-pages t
345 "*If non-nil, do page breaking on articles.
346The page delimiter is specified by the `gnus-page-delimiter'
347variable."
348 :group 'gnus-article-various
349 :type 'boolean)
350
eec82323
LMI
351(defcustom gnus-move-split-methods nil
352 "*Variable used to suggest where articles are to be moved to.
353It uses the same syntax as the `gnus-split-methods' variable."
354 :group 'gnus-summary-mail
6748645f
LMI
355 :type '(repeat (choice (list :value (fun) function)
356 (cons :value ("" "") regexp (repeat string))
357 (sexp :value nil))))
eec82323 358
16409b0b 359(defcustom gnus-unread-mark ? ;Whitespace
eec82323
LMI
360 "*Mark used for unread articles."
361 :group 'gnus-summary-marks
362 :type 'character)
363
364(defcustom gnus-ticked-mark ?!
365 "*Mark used for ticked articles."
366 :group 'gnus-summary-marks
367 :type 'character)
368
369(defcustom gnus-dormant-mark ??
370 "*Mark used for dormant articles."
371 :group 'gnus-summary-marks
372 :type 'character)
373
374(defcustom gnus-del-mark ?r
375 "*Mark used for del'd articles."
376 :group 'gnus-summary-marks
377 :type 'character)
378
379(defcustom gnus-read-mark ?R
380 "*Mark used for read articles."
381 :group 'gnus-summary-marks
382 :type 'character)
383
384(defcustom gnus-expirable-mark ?E
385 "*Mark used for expirable articles."
386 :group 'gnus-summary-marks
387 :type 'character)
388
389(defcustom gnus-killed-mark ?K
390 "*Mark used for killed articles."
391 :group 'gnus-summary-marks
392 :type 'character)
393
394(defcustom gnus-souped-mark ?F
395 "*Mark used for killed articles."
396 :group 'gnus-summary-marks
397 :type 'character)
398
399(defcustom gnus-kill-file-mark ?X
400 "*Mark used for articles killed by kill files."
401 :group 'gnus-summary-marks
402 :type 'character)
403
404(defcustom gnus-low-score-mark ?Y
405 "*Mark used for articles with a low score."
406 :group 'gnus-summary-marks
407 :type 'character)
408
409(defcustom gnus-catchup-mark ?C
410 "*Mark used for articles that are caught up."
411 :group 'gnus-summary-marks
412 :type 'character)
413
414(defcustom gnus-replied-mark ?A
415 "*Mark used for articles that have been replied to."
416 :group 'gnus-summary-marks
417 :type 'character)
418
419(defcustom gnus-cached-mark ?*
420 "*Mark used for articles that are in the cache."
421 :group 'gnus-summary-marks
422 :type 'character)
423
424(defcustom gnus-saved-mark ?S
425 "*Mark used for articles that have been saved to."
426 :group 'gnus-summary-marks
427 :type 'character)
428
429(defcustom gnus-ancient-mark ?O
430 "*Mark used for ancient articles."
431 :group 'gnus-summary-marks
432 :type 'character)
433
434(defcustom gnus-sparse-mark ?Q
435 "*Mark used for sparsely reffed articles."
436 :group 'gnus-summary-marks
437 :type 'character)
438
439(defcustom gnus-canceled-mark ?G
440 "*Mark used for canceled articles."
441 :group 'gnus-summary-marks
442 :type 'character)
443
444(defcustom gnus-duplicate-mark ?M
445 "*Mark used for duplicate articles."
446 :group 'gnus-summary-marks
447 :type 'character)
448
6748645f
LMI
449(defcustom gnus-undownloaded-mark ?@
450 "*Mark used for articles that weren't downloaded."
451 :group 'gnus-summary-marks
452 :type 'character)
453
454(defcustom gnus-downloadable-mark ?%
455 "*Mark used for articles that are to be downloaded."
456 :group 'gnus-summary-marks
457 :type 'character)
458
459(defcustom gnus-unsendable-mark ?=
460 "*Mark used for articles that won't be sent."
461 :group 'gnus-summary-marks
462 :type 'character)
463
eec82323
LMI
464(defcustom gnus-score-over-mark ?+
465 "*Score mark used for articles with high scores."
466 :group 'gnus-summary-marks
467 :type 'character)
468
469(defcustom gnus-score-below-mark ?-
470 "*Score mark used for articles with low scores."
471 :group 'gnus-summary-marks
472 :type 'character)
473
16409b0b 474(defcustom gnus-empty-thread-mark ? ;Whitespace
eec82323
LMI
475 "*There is no thread under the article."
476 :group 'gnus-summary-marks
477 :type 'character)
478
479(defcustom gnus-not-empty-thread-mark ?=
480 "*There is a thread under the article."
481 :group 'gnus-summary-marks
482 :type 'character)
483
484(defcustom gnus-view-pseudo-asynchronously nil
485 "*If non-nil, Gnus will view pseudo-articles asynchronously."
486 :group 'gnus-extract-view
487 :type 'boolean)
488
16409b0b
GM
489(defcustom gnus-auto-expirable-marks
490 (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
491 gnus-low-score-mark gnus-ancient-mark gnus-read-mark
492 gnus-souped-mark gnus-duplicate-mark)
493 "*The list of marks converted into expiration if a group is auto-expirable."
58e39d05 494 :version "21.1"
16409b0b
GM
495 :group 'gnus-summary
496 :type '(repeat character))
497
498(defcustom gnus-inhibit-user-auto-expire t
499 "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
58e39d05 500 :version "21.1"
16409b0b
GM
501 :group 'gnus-summary
502 :type 'boolean)
503
eec82323
LMI
504(defcustom gnus-view-pseudos nil
505 "*If `automatic', pseudo-articles will be viewed automatically.
506If `not-confirm', pseudos will be viewed automatically, and the user
507will not be asked to confirm the command."
508 :group 'gnus-extract-view
509 :type '(choice (const :tag "off" nil)
510 (const automatic)
511 (const not-confirm)))
512
513(defcustom gnus-view-pseudos-separately t
514 "*If non-nil, one pseudo-article will be created for each file to be viewed.
515If nil, all files that use the same viewing command will be given as a
516list of parameters to that command."
517 :group 'gnus-extract-view
518 :type 'boolean)
519
520(defcustom gnus-insert-pseudo-articles t
521 "*If non-nil, insert pseudo-articles when decoding articles."
522 :group 'gnus-extract-view
523 :type 'boolean)
524
525(defcustom gnus-summary-dummy-line-format
6748645f 526 " %(: :%) %S\n"
eec82323
LMI
527 "*The format specification for the dummy roots in the summary buffer.
528It works along the same lines as a normal formatting string,
529with some simple extensions.
530
531%S The subject"
532 :group 'gnus-threading
533 :type 'string)
534
16409b0b 535(defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
eec82323
LMI
536 "*The format specification for the summary mode line.
537It works along the same lines as a normal formatting string,
538with some simple extensions:
539
540%G Group name
541%p Unprefixed group name
542%A Current article number
6748645f 543%z Current article score
eec82323
LMI
544%V Gnus version
545%U Number of unread articles in the group
546%e Number of unselected articles in the group
547%Z A string with unread/unselected article counts
548%g Shortish group name
549%S Subject of the current article
550%u User-defined spec
551%s Current score file name
552%d Number of dormant articles
553%r Number of articles that have been marked as read in this session
554%E Number of articles expunged by the score files"
555 :group 'gnus-summary-format
556 :type 'string)
557
16409b0b
GM
558(defcustom gnus-list-identifiers nil
559 "Regexp that matches list identifiers to be removed from subject.
560This can also be a list of regexps."
58e39d05 561 :version "21.1"
16409b0b
GM
562 :group 'gnus-summary-format
563 :group 'gnus-article-hiding
564 :type '(choice (const :tag "none" nil)
565 (regexp :value ".*")
566 (repeat :value (".*") regexp)))
567
eec82323
LMI
568(defcustom gnus-summary-mark-below 0
569 "*Mark all articles with a score below this variable as read.
570This variable is local to each summary buffer and usually set by the
571score file."
572 :group 'gnus-score-default
573 :type 'integer)
574
575(defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
576 "*List of functions used for sorting articles in the summary buffer.
577This variable is only used when not using a threaded display."
578 :group 'gnus-summary-sort
579 :type '(repeat (choice (function-item gnus-article-sort-by-number)
580 (function-item gnus-article-sort-by-author)
581 (function-item gnus-article-sort-by-subject)
582 (function-item gnus-article-sort-by-date)
583 (function-item gnus-article-sort-by-score)
584 (function :tag "other"))))
585
586(defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
587 "*List of functions used for sorting threads in the summary buffer.
588By default, threads are sorted by article number.
589
590Each function takes two threads and return non-nil if the first thread
591should be sorted before the other. If you use more than one function,
592the primary sort function should be the last. You should probably
593always include `gnus-thread-sort-by-number' in the list of sorting
594functions -- preferably first.
595
596Ready-made functions include `gnus-thread-sort-by-number',
597`gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
598`gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
599`gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
600 :group 'gnus-summary-sort
601 :type '(repeat (choice (function-item gnus-thread-sort-by-number)
602 (function-item gnus-thread-sort-by-author)
603 (function-item gnus-thread-sort-by-subject)
604 (function-item gnus-thread-sort-by-date)
605 (function-item gnus-thread-sort-by-score)
606 (function-item gnus-thread-sort-by-total-score)
607 (function :tag "other"))))
608
609(defcustom gnus-thread-score-function '+
610 "*Function used for calculating the total score of a thread.
611
612The function is called with the scores of the article and each
613subthread and should then return the score of the thread.
614
615Some functions you can use are `+', `max', or `min'."
616 :group 'gnus-summary-sort
617 :type 'function)
618
619(defcustom gnus-summary-expunge-below nil
6748645f
LMI
620 "All articles that have a score less than this variable will be expunged.
621This variable is local to the summary buffers."
eec82323
LMI
622 :group 'gnus-score-default
623 :type '(choice (const :tag "off" nil)
624 integer))
625
626(defcustom gnus-thread-expunge-below nil
627 "All threads that have a total score less than this variable will be expunged.
628See `gnus-thread-score-function' for en explanation of what a
6748645f
LMI
629\"thread score\" is.
630
631This variable is local to the summary buffers."
16409b0b 632 :group 'gnus-threading
eec82323
LMI
633 :group 'gnus-score-default
634 :type '(choice (const :tag "off" nil)
635 integer))
636
637(defcustom gnus-summary-mode-hook nil
638 "*A hook for Gnus summary mode.
639This hook is run before any variables are set in the summary buffer."
60bd5589 640 :options '(turn-on-gnus-mailing-list-mode)
eec82323
LMI
641 :group 'gnus-summary-various
642 :type 'hook)
643
644(defcustom gnus-summary-menu-hook nil
645 "*Hook run after the creation of the summary mode menu."
646 :group 'gnus-summary-visual
647 :type 'hook)
648
649(defcustom gnus-summary-exit-hook nil
650 "*A hook called on exit from the summary buffer.
651It will be called with point in the group buffer."
652 :group 'gnus-summary-exit
653 :type 'hook)
654
655(defcustom gnus-summary-prepare-hook nil
656 "*A hook called after the summary buffer has been generated.
657If you want to modify the summary buffer, you can use this hook."
658 :group 'gnus-summary-various
659 :type 'hook)
660
6748645f
LMI
661(defcustom gnus-summary-prepared-hook nil
662 "*A hook called as the last thing after the summary buffer has been generated."
663 :group 'gnus-summary-various
664 :type 'hook)
665
eec82323
LMI
666(defcustom gnus-summary-generate-hook nil
667 "*A hook run just before generating the summary buffer.
668This hook is commonly used to customize threading variables and the
669like."
670 :group 'gnus-summary-various
671 :type 'hook)
672
673(defcustom gnus-select-group-hook nil
674 "*A hook called when a newsgroup is selected.
675
676If you'd like to simplify subjects like the
677`gnus-summary-next-same-subject' command does, you can use the
678following hook:
679
680 (setq gnus-select-group-hook
681 (list
682 (lambda ()
683 (mapcar (lambda (header)
684 (mail-header-set-subject
685 header
686 (gnus-simplify-subject
687 (mail-header-subject header) 're-only)))
688 gnus-newsgroup-headers))))"
689 :group 'gnus-group-select
690 :type 'hook)
691
692(defcustom gnus-select-article-hook nil
693 "*A hook called when an article is selected."
694 :group 'gnus-summary-choose
695 :type 'hook)
696
697(defcustom gnus-visual-mark-article-hook
698 (list 'gnus-highlight-selected-summary)
699 "*Hook run after selecting an article in the summary buffer.
700It is meant to be used for highlighting the article in some way. It
701is not run if `gnus-visual' is nil."
702 :group 'gnus-summary-visual
703 :type 'hook)
704
16409b0b 705(defcustom gnus-parse-headers-hook nil
eec82323
LMI
706 "*A hook called before parsing the headers."
707 :group 'gnus-various
708 :type 'hook)
709
710(defcustom gnus-exit-group-hook nil
16409b0b
GM
711 "*A hook called when exiting summary mode.
712This hook is not called from the non-updating exit commands like `Q'."
eec82323
LMI
713 :group 'gnus-various
714 :type 'hook)
715
716(defcustom gnus-summary-update-hook
717 (list 'gnus-summary-highlight-line)
718 "*A hook called when a summary line is changed.
719The hook will not be called if `gnus-visual' is nil.
720
721The default function `gnus-summary-highlight-line' will
722highlight the line according to the `gnus-summary-highlight'
723variable."
724 :group 'gnus-summary-visual
725 :type 'hook)
726
727(defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
728 "*A hook called when an article is selected for the first time.
729The hook is intended to mark an article as read (or unread)
730automatically when it is selected."
731 :group 'gnus-summary-choose
732 :type 'hook)
733
734(defcustom gnus-group-no-more-groups-hook nil
735 "*A hook run when returning to group mode having no more (unread) groups."
736 :group 'gnus-group-select
737 :type 'hook)
738
739(defcustom gnus-ps-print-hook nil
740 "*A hook run before ps-printing something from Gnus."
741 :group 'gnus-summary
742 :type 'hook)
743
744(defcustom gnus-summary-selected-face 'gnus-summary-selected-face
745 "Face used for highlighting the current article in the summary buffer."
746 :group 'gnus-summary-visual
747 :type 'face)
748
749(defcustom gnus-summary-highlight
750 '(((= mark gnus-canceled-mark)
751 . gnus-summary-cancelled-face)
752 ((and (> score default)
753 (or (= mark gnus-dormant-mark)
754 (= mark gnus-ticked-mark)))
755 . gnus-summary-high-ticked-face)
756 ((and (< score default)
757 (or (= mark gnus-dormant-mark)
758 (= mark gnus-ticked-mark)))
759 . gnus-summary-low-ticked-face)
760 ((or (= mark gnus-dormant-mark)
761 (= mark gnus-ticked-mark))
762 . gnus-summary-normal-ticked-face)
763 ((and (> score default) (= mark gnus-ancient-mark))
764 . gnus-summary-high-ancient-face)
765 ((and (< score default) (= mark gnus-ancient-mark))
766 . gnus-summary-low-ancient-face)
767 ((= mark gnus-ancient-mark)
768 . gnus-summary-normal-ancient-face)
769 ((and (> score default) (= mark gnus-unread-mark))
770 . gnus-summary-high-unread-face)
771 ((and (< score default) (= mark gnus-unread-mark))
772 . gnus-summary-low-unread-face)
6748645f
LMI
773 ((= mark gnus-unread-mark)
774 . gnus-summary-normal-unread-face)
775 ((and (> score default) (memq mark (list gnus-downloadable-mark
776 gnus-undownloaded-mark)))
777 . gnus-summary-high-unread-face)
778 ((and (< score default) (memq mark (list gnus-downloadable-mark
779 gnus-undownloaded-mark)))
780 . gnus-summary-low-unread-face)
781 ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
eec82323
LMI
782 . gnus-summary-normal-unread-face)
783 ((> score default)
784 . gnus-summary-high-read-face)
785 ((< score default)
786 . gnus-summary-low-read-face)
787 (t
788 . gnus-summary-normal-read-face))
6748645f 789 "*Controls the highlighting of summary buffer lines.
eec82323
LMI
790
791A list of (FORM . FACE) pairs. When deciding how a a particular
792summary line should be displayed, each form is evaluated. The content
793of the face field after the first true form is used. You can change
794how those summary lines are displayed, by editing the face field.
795
796You can use the following variables in the FORM field.
797
798score: The articles score
799default: The default article score.
800below: The score below which articles are automatically marked as read.
801mark: The articles mark."
802 :group 'gnus-summary-visual
803 :type '(repeat (cons (sexp :tag "Form" nil)
804 face)))
805
6748645f
LMI
806(defcustom gnus-alter-header-function nil
807 "Function called to allow alteration of article header structures.
808The function is called with one parameter, the article header vector,
809which it may alter in any way.")
eec82323 810
16409b0b
GM
811(defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
812 "Variable that says which function should be used to decode a string with encoded words.")
813
814(defcustom gnus-extra-headers nil
815 "*Extra headers to parse."
58e39d05 816 :version "21.1"
16409b0b
GM
817 :group 'gnus-summary
818 :type '(repeat symbol))
819
820(defcustom gnus-ignored-from-addresses
821 (and user-mail-address (regexp-quote user-mail-address))
822 "*Regexp of From headers that may be suppressed in favor of To headers."
58e39d05 823 :version "21.1"
16409b0b
GM
824 :group 'gnus-summary
825 :type 'regexp)
826
827(defcustom gnus-group-charset-alist
828 '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
829 ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
830 ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
831 ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
832 ("^relcom\\>" koi8-r)
833 ("^fido7\\>" koi8-r)
834 ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
835 ("^israel\\>" iso-8859-1)
836 ("^han\\>" euc-kr)
837 ("^alt.chinese.text.big5\\>" chinese-big5)
838 ("^soc.culture.vietnamese\\>" vietnamese-viqr)
839 ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
840 (".*" iso-8859-1))
841 "Alist of regexps (to match group names) and default charsets to be used when reading."
842 :type '(repeat (list (regexp :tag "Group")
843 (symbol :tag "Charset")))
844 :group 'gnus-charset)
845
846(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
847 "List of charsets that should be ignored.
848When these charsets are used in the \"charset\" parameter, the
849default charset will be used instead."
58e39d05 850 :version "21.1"
16409b0b
GM
851 :type '(repeat symbol)
852 :group 'gnus-charset)
853
854(defcustom gnus-group-ignored-charsets-alist
855 '(("alt\\.chinese\\.text" iso-8859-1))
856 "Alist of regexps (to match group names) and charsets that should be ignored.
857When these charsets are used in the \"charset\" parameter, the
858default charset will be used instead."
859 :type '(repeat (cons (regexp :tag "Group")
860 (repeat symbol)))
861 :group 'gnus-charset)
862
863(defcustom gnus-group-highlight-words-alist nil
864 "Alist of group regexps and highlight regexps.
865This variable uses the same syntax as `gnus-emphasis-alist'."
58e39d05 866 :version "21.1"
16409b0b
GM
867 :type '(repeat (cons (regexp :tag "Group")
868 (repeat (list (regexp :tag "Highlight regexp")
869 (number :tag "Group for entire word" 0)
870 (number :tag "Group for displayed part" 0)
871 (symbol :tag "Face"
872 gnus-emphasis-highlight-words)))))
873 :group 'gnus-summary-visual)
874
875(defcustom gnus-summary-show-article-charset-alist
876 nil
877 "Alist of number and charset.
878The article will be shown with the charset corresponding to the
879numbered argument.
880For example: ((1 . cn-gb-2312) (2 . big5))."
58e39d05 881 :version "21.1"
16409b0b
GM
882 :type '(repeat (cons (number :tag "Argument" 1)
883 (symbol :tag "Charset")))
884 :group 'gnus-charset)
885
886(defcustom gnus-preserve-marks t
887 "Whether marks are preserved when moving, copying and respooling messages."
58e39d05 888 :version "21.1"
16409b0b
GM
889 :type 'boolean
890 :group 'gnus-summary-marks)
891
892(defcustom gnus-alter-articles-to-read-function nil
893 "Function to be called to alter the list of articles to be selected."
8fc7a9a1 894 :type '(choice (const nil) function)
16409b0b
GM
895 :group 'gnus-summary)
896
897(defcustom gnus-orphan-score nil
898 "*All orphans get this score added. Set in the score file."
899 :group 'gnus-score-default
900 :type '(choice (const nil)
901 integer))
902
8b93df01
DL
903(defcustom gnus-summary-save-parts-default-mime "image/.*"
904 "*A regexp to match MIME parts when saving multiple parts of a message
905with gnus-summary-save-parts (X m). This regexp will be used by default
906when prompting the user for which type of files to save."
907 :group 'gnus-summary
908 :type 'regexp)
909
910
eec82323
LMI
911;;; Internal variables
912
16409b0b
GM
913(defvar gnus-article-mime-handles nil)
914(defvar gnus-article-decoded-p nil)
eec82323
LMI
915(defvar gnus-scores-exclude-files nil)
916(defvar gnus-page-broken nil)
16409b0b 917(defvar gnus-inhibit-mime-unbuttonizing nil)
eec82323
LMI
918
919(defvar gnus-original-article nil)
920(defvar gnus-article-internal-prepare-hook nil)
921(defvar gnus-newsgroup-process-stack nil)
922
923(defvar gnus-thread-indent-array nil)
924(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
16409b0b
GM
925(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
926 "Function called to sort the articles within a thread after it has been gathered together.")
eec82323 927
8b93df01
DL
928(defvar gnus-summary-save-parts-type-history nil)
929(defvar gnus-summary-save-parts-last-directory nil)
930
eec82323
LMI
931;; Avoid highlighting in kill files.
932(defvar gnus-summary-inhibit-highlight nil)
933(defvar gnus-newsgroup-selected-overlay nil)
934(defvar gnus-inhibit-limiting nil)
935(defvar gnus-newsgroup-adaptive-score-file nil)
936(defvar gnus-current-score-file nil)
937(defvar gnus-current-move-group nil)
938(defvar gnus-current-copy-group nil)
939(defvar gnus-current-crosspost-group nil)
940
941(defvar gnus-newsgroup-dependencies nil)
942(defvar gnus-newsgroup-adaptive nil)
943(defvar gnus-summary-display-article-function nil)
944(defvar gnus-summary-highlight-line-function nil
945 "Function called after highlighting a summary line.")
946
947(defvar gnus-summary-line-format-alist
948 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
949 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
950 (?s gnus-tmp-subject-or-nil ?s)
951 (?n gnus-tmp-name ?s)
952 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
953 ?s)
954 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
955 gnus-tmp-from) ?s)
956 (?F gnus-tmp-from ?s)
957 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
958 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
959 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
6748645f 960 (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
eec82323
LMI
961 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
962 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
963 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
964 (?L gnus-tmp-lines ?d)
965 (?I gnus-tmp-indentation ?s)
966 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
967 (?R gnus-tmp-replied ?c)
968 (?\[ gnus-tmp-opening-bracket ?c)
969 (?\] gnus-tmp-closing-bracket ?c)
970 (?\> (make-string gnus-tmp-level ? ) ?s)
971 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
972 (?i gnus-tmp-score ?d)
973 (?z gnus-tmp-score-char ?c)
974 (?l (bbb-grouplens-score gnus-tmp-header) ?s)
975 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
976 (?U gnus-tmp-unread ?c)
16409b0b 977 (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
eec82323
LMI
978 (?t (gnus-summary-number-of-articles-in-thread
979 (and (boundp 'thread) (car thread)) gnus-tmp-level)
980 ?d)
981 (?e (gnus-summary-number-of-articles-in-thread
982 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
983 ?c)
984 (?u gnus-tmp-user-defined ?s)
985 (?P (gnus-pick-line-number) ?d))
16409b0b
GM
986 "An alist of format specifications that can appear in summary lines.
987These are paired with what variables they correspond with, along with
988the type of the variable (string, integer, character, etc).")
eec82323
LMI
989
990(defvar gnus-summary-dummy-line-format-alist
991 `((?S gnus-tmp-subject ?s)
992 (?N gnus-tmp-number ?d)
993 (?u gnus-tmp-user-defined ?s)))
994
995(defvar gnus-summary-mode-line-format-alist
996 `((?G gnus-tmp-group-name ?s)
997 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
998 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
999 (?A gnus-tmp-article-number ?d)
1000 (?Z gnus-tmp-unread-and-unselected ?s)
1001 (?V gnus-version ?s)
1002 (?U gnus-tmp-unread-and-unticked ?d)
1003 (?S gnus-tmp-subject ?s)
1004 (?e gnus-tmp-unselected ?d)
1005 (?u gnus-tmp-user-defined ?s)
1006 (?d (length gnus-newsgroup-dormant) ?d)
1007 (?t (length gnus-newsgroup-marked) ?d)
1008 (?r (length gnus-newsgroup-reads) ?d)
6748645f 1009 (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
eec82323
LMI
1010 (?E gnus-newsgroup-expunged-tally ?d)
1011 (?s (gnus-current-score-file-nondirectory) ?s)))
1012
1013(defvar gnus-last-search-regexp nil
1014 "Default regexp for article search command.")
1015
1016(defvar gnus-last-shell-command nil
1017 "Default shell command on article.")
1018
1019(defvar gnus-newsgroup-begin nil)
1020(defvar gnus-newsgroup-end nil)
1021(defvar gnus-newsgroup-last-rmail nil)
1022(defvar gnus-newsgroup-last-mail nil)
1023(defvar gnus-newsgroup-last-folder nil)
1024(defvar gnus-newsgroup-last-file nil)
1025(defvar gnus-newsgroup-auto-expire nil)
1026(defvar gnus-newsgroup-active nil)
1027
1028(defvar gnus-newsgroup-data nil)
1029(defvar gnus-newsgroup-data-reverse nil)
1030(defvar gnus-newsgroup-limit nil)
1031(defvar gnus-newsgroup-limits nil)
1032
1033(defvar gnus-newsgroup-unreads nil
1034 "List of unread articles in the current newsgroup.")
1035
1036(defvar gnus-newsgroup-unselected nil
1037 "List of unselected unread articles in the current newsgroup.")
1038
1039(defvar gnus-newsgroup-reads nil
1040 "Alist of read articles and article marks in the current newsgroup.")
1041
1042(defvar gnus-newsgroup-expunged-tally nil)
1043
1044(defvar gnus-newsgroup-marked nil
1045 "List of ticked articles in the current newsgroup (a subset of unread art).")
1046
1047(defvar gnus-newsgroup-killed nil
1048 "List of ranges of articles that have been through the scoring process.")
1049
1050(defvar gnus-newsgroup-cached nil
1051 "List of articles that come from the article cache.")
1052
1053(defvar gnus-newsgroup-saved nil
1054 "List of articles that have been saved.")
1055
1056(defvar gnus-newsgroup-kill-headers nil)
1057
1058(defvar gnus-newsgroup-replied nil
1059 "List of articles that have been replied to in the current newsgroup.")
1060
1061(defvar gnus-newsgroup-expirable nil
1062 "List of articles in the current newsgroup that can be expired.")
1063
1064(defvar gnus-newsgroup-processable nil
1065 "List of articles in the current newsgroup that can be processed.")
1066
6748645f
LMI
1067(defvar gnus-newsgroup-downloadable nil
1068 "List of articles in the current newsgroup that can be processed.")
1069
1070(defvar gnus-newsgroup-undownloaded nil
1071 "List of articles in the current newsgroup that haven't been downloaded..")
1072
1073(defvar gnus-newsgroup-unsendable nil
1074 "List of articles in the current newsgroup that won't be sent.")
1075
eec82323
LMI
1076(defvar gnus-newsgroup-bookmarks nil
1077 "List of articles in the current newsgroup that have bookmarks.")
1078
1079(defvar gnus-newsgroup-dormant nil
1080 "List of dormant articles in the current newsgroup.")
1081
1082(defvar gnus-newsgroup-scored nil
1083 "List of scored articles in the current newsgroup.")
1084
1085(defvar gnus-newsgroup-headers nil
1086 "List of article headers in the current newsgroup.")
1087
1088(defvar gnus-newsgroup-threads nil)
1089
1090(defvar gnus-newsgroup-prepared nil
1091 "Whether the current group has been prepared properly.")
1092
1093(defvar gnus-newsgroup-ancient nil
1094 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1095
1096(defvar gnus-newsgroup-sparse nil)
1097
1098(defvar gnus-current-article nil)
1099(defvar gnus-article-current nil)
1100(defvar gnus-current-headers nil)
1101(defvar gnus-have-all-headers nil)
1102(defvar gnus-last-article nil)
1103(defvar gnus-newsgroup-history nil)
16409b0b
GM
1104(defvar gnus-newsgroup-charset nil)
1105(defvar gnus-newsgroup-ephemeral-charset nil)
1106(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
eec82323
LMI
1107
1108(defconst gnus-summary-local-variables
1109 '(gnus-newsgroup-name
1110 gnus-newsgroup-begin gnus-newsgroup-end
1111 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1112 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1113 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1114 gnus-newsgroup-unselected gnus-newsgroup-marked
1115 gnus-newsgroup-reads gnus-newsgroup-saved
1116 gnus-newsgroup-replied gnus-newsgroup-expirable
1117 gnus-newsgroup-processable gnus-newsgroup-killed
6748645f
LMI
1118 gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1119 gnus-newsgroup-unsendable
eec82323
LMI
1120 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1121 gnus-newsgroup-headers gnus-newsgroup-threads
1122 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1123 gnus-current-article gnus-current-headers gnus-have-all-headers
1124 gnus-last-article gnus-article-internal-prepare-hook
1125 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1126 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1127 gnus-thread-expunge-below
16409b0b
GM
1128 gnus-score-alist gnus-current-score-file
1129 (gnus-summary-expunge-below . global)
eec82323 1130 (gnus-summary-mark-below . global)
16409b0b 1131 (gnus-orphan-score . global)
eec82323
LMI
1132 gnus-newsgroup-active gnus-scores-exclude-files
1133 gnus-newsgroup-history gnus-newsgroup-ancient
1134 gnus-newsgroup-sparse gnus-newsgroup-process-stack
1135 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1136 gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1137 (gnus-newsgroup-expunged-tally . 0)
1138 gnus-cache-removable-articles gnus-newsgroup-cached
1139 gnus-newsgroup-data gnus-newsgroup-data-reverse
16409b0b
GM
1140 gnus-newsgroup-limit gnus-newsgroup-limits
1141 gnus-newsgroup-charset)
eec82323
LMI
1142 "Variables that are buffer-local to the summary buffers.")
1143
1144;; Byte-compiler warning.
60bd5589 1145(eval-when-compile (defvar gnus-article-mode-map))
eec82323 1146
16409b0b
GM
1147;; MIME stuff.
1148
1149(defvar gnus-decode-encoded-word-methods
1150 '(mail-decode-encoded-word-string)
1151 "List of methods used to decode encoded words.
1152
1153This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
1154FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1155(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1156whose names match REGEXP.
1157
1158For example:
1159((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1160 mail-decode-encoded-word-string
1161 (\"chinese\" . rfc1843-decode-string))")
1162
1163(defvar gnus-decode-encoded-word-methods-cache nil)
1164
1165(defun gnus-multi-decode-encoded-word-string (string)
1166 "Apply the functions from `gnus-encoded-word-methods' that match."
1167 (unless (and gnus-decode-encoded-word-methods-cache
1168 (eq gnus-newsgroup-name
1169 (car gnus-decode-encoded-word-methods-cache)))
1170 (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1171 (mapcar (lambda (x)
1172 (if (symbolp x)
1173 (nconc gnus-decode-encoded-word-methods-cache (list x))
1174 (if (and gnus-newsgroup-name
1175 (string-match (car x) gnus-newsgroup-name))
1176 (nconc gnus-decode-encoded-word-methods-cache
1177 (list (cdr x))))))
1178 gnus-decode-encoded-word-methods))
1179 (let ((xlist gnus-decode-encoded-word-methods-cache))
1180 (pop xlist)
1181 (while xlist
1182 (setq string (funcall (pop xlist) string))))
1183 string)
1184
eec82323
LMI
1185;; Subject simplification.
1186
6748645f 1187(defun gnus-simplify-whitespace (str)
16409b0b 1188 "Remove excessive whitespace from STR."
6748645f
LMI
1189 (let ((mystr str))
1190 ;; Multiple spaces.
1191 (while (string-match "[ \t][ \t]+" mystr)
1192 (setq mystr (concat (substring mystr 0 (match-beginning 0))
1193 " "
1194 (substring mystr (match-end 0)))))
1195 ;; Leading spaces.
1196 (when (string-match "^[ \t]+" mystr)
1197 (setq mystr (substring mystr (match-end 0))))
1198 ;; Trailing spaces.
1199 (when (string-match "[ \t]+$" mystr)
1200 (setq mystr (substring mystr 0 (match-beginning 0))))
1201 mystr))
1202
eec82323
LMI
1203(defsubst gnus-simplify-subject-re (subject)
1204 "Remove \"Re:\" from subject lines."
1205 (if (string-match "^[Rr][Ee]: *" subject)
1206 (substring subject (match-end 0))
1207 subject))
1208
1209(defun gnus-simplify-subject (subject &optional re-only)
1210 "Remove `Re:' and words in parentheses.
1211If RE-ONLY is non-nil, strip leading `Re:'s only."
1212 (let ((case-fold-search t)) ;Ignore case.
1213 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1214 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1215 (setq subject (substring subject (match-end 0))))
1216 ;; Remove uninteresting prefixes.
1217 (when (and (not re-only)
1218 gnus-simplify-ignored-prefixes
1219 (string-match gnus-simplify-ignored-prefixes subject))
1220 (setq subject (substring subject (match-end 0))))
1221 ;; Remove words in parentheses from end.
1222 (unless re-only
1223 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1224 (setq subject (substring subject 0 (match-beginning 0)))))
1225 ;; Return subject string.
1226 subject))
1227
1228;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1229;; all whitespace.
1230(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1231 (goto-char (point-min))
1232 (while (re-search-forward regexp nil t)
16409b0b 1233 (replace-match (or newtext ""))))
eec82323
LMI
1234
1235(defun gnus-simplify-buffer-fuzzy ()
1236 "Simplify string in the buffer fuzzily.
1237The string in the accessible portion of the current buffer is simplified.
1238It is assumed to be a single-line subject.
1239Whitespace is generally cleaned up, and miscellaneous leading/trailing
1240matter is removed. Additional things can be deleted by setting
16409b0b 1241`gnus-simplify-subject-fuzzy-regexp'."
eec82323
LMI
1242 (let ((case-fold-search t)
1243 (modified-tick))
1244 (gnus-simplify-buffer-fuzzy-step "\t" " ")
1245
1246 (while (not (eq modified-tick (buffer-modified-tick)))
1247 (setq modified-tick (buffer-modified-tick))
1248 (cond
1249 ((listp gnus-simplify-subject-fuzzy-regexp)
1250 (mapcar 'gnus-simplify-buffer-fuzzy-step
1251 gnus-simplify-subject-fuzzy-regexp))
1252 (gnus-simplify-subject-fuzzy-regexp
1253 (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1254 (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1255 (gnus-simplify-buffer-fuzzy-step
1256 "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1257 (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1258
1259 (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1260 (gnus-simplify-buffer-fuzzy-step " +" " ")
1261 (gnus-simplify-buffer-fuzzy-step " $")
1262 (gnus-simplify-buffer-fuzzy-step "^ +")))
1263
1264(defun gnus-simplify-subject-fuzzy (subject)
1265 "Simplify a subject string fuzzily.
6748645f 1266See `gnus-simplify-buffer-fuzzy' for details."
eec82323
LMI
1267 (save-excursion
1268 (gnus-set-work-buffer)
1269 (let ((case-fold-search t))
6748645f
LMI
1270 ;; Remove uninteresting prefixes.
1271 (when (and gnus-simplify-ignored-prefixes
1272 (string-match gnus-simplify-ignored-prefixes subject))
1273 (setq subject (substring subject (match-end 0))))
eec82323
LMI
1274 (insert subject)
1275 (inline (gnus-simplify-buffer-fuzzy))
1276 (buffer-string))))
1277
1278(defsubst gnus-simplify-subject-fully (subject)
1279 "Simplify a subject string according to gnus-summary-gather-subject-limit."
1280 (cond
6748645f
LMI
1281 (gnus-simplify-subject-functions
1282 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
1283 ((null gnus-summary-gather-subject-limit)
1284 (gnus-simplify-subject-re subject))
1285 ((eq gnus-summary-gather-subject-limit 'fuzzy)
1286 (gnus-simplify-subject-fuzzy subject))
1287 ((numberp gnus-summary-gather-subject-limit)
1288 (gnus-limit-string (gnus-simplify-subject-re subject)
1289 gnus-summary-gather-subject-limit))
1290 (t
1291 subject)))
1292
1293(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
6748645f
LMI
1294 "Check whether two subjects are equal.
1295If optional argument simple-first is t, first argument is already
1296simplified."
eec82323
LMI
1297 (cond
1298 ((null simple-first)
1299 (equal (gnus-simplify-subject-fully s1)
1300 (gnus-simplify-subject-fully s2)))
1301 (t
1302 (equal s1
1303 (gnus-simplify-subject-fully s2)))))
1304
1305(defun gnus-summary-bubble-group ()
1306 "Increase the score of the current group.
1307This is a handy function to add to `gnus-summary-exit-hook' to
1308increase the score of each group you read."
1309 (gnus-group-add-score gnus-newsgroup-name))
1310
1311\f
1312;;;
1313;;; Gnus summary mode
1314;;;
1315
1316(put 'gnus-summary-mode 'mode-class 'special)
1317
1653df0f
SZ
1318(defvar gnus-article-commands-menu)
1319
eec82323
LMI
1320(when t
1321 ;; Non-orthogonal keys
1322
1323 (gnus-define-keys gnus-summary-mode-map
1324 " " gnus-summary-next-page
1325 "\177" gnus-summary-prev-page
1326 [delete] gnus-summary-prev-page
6748645f 1327 [backspace] gnus-summary-prev-page
eec82323 1328 "\r" gnus-summary-scroll-up
6748645f 1329 "\M-\r" gnus-summary-scroll-down
eec82323
LMI
1330 "n" gnus-summary-next-unread-article
1331 "p" gnus-summary-prev-unread-article
1332 "N" gnus-summary-next-article
1333 "P" gnus-summary-prev-article
1334 "\M-\C-n" gnus-summary-next-same-subject
1335 "\M-\C-p" gnus-summary-prev-same-subject
1336 "\M-n" gnus-summary-next-unread-subject
1337 "\M-p" gnus-summary-prev-unread-subject
1338 "." gnus-summary-first-unread-article
1339 "," gnus-summary-best-unread-article
1340 "\M-s" gnus-summary-search-article-forward
1341 "\M-r" gnus-summary-search-article-backward
1342 "<" gnus-summary-beginning-of-article
1343 ">" gnus-summary-end-of-article
1344 "j" gnus-summary-goto-article
1345 "^" gnus-summary-refer-parent-article
1346 "\M-^" gnus-summary-refer-article
1347 "u" gnus-summary-tick-article-forward
1348 "!" gnus-summary-tick-article-forward
1349 "U" gnus-summary-tick-article-backward
1350 "d" gnus-summary-mark-as-read-forward
1351 "D" gnus-summary-mark-as-read-backward
1352 "E" gnus-summary-mark-as-expirable
1353 "\M-u" gnus-summary-clear-mark-forward
1354 "\M-U" gnus-summary-clear-mark-backward
1355 "k" gnus-summary-kill-same-subject-and-select
1356 "\C-k" gnus-summary-kill-same-subject
1357 "\M-\C-k" gnus-summary-kill-thread
1358 "\M-\C-l" gnus-summary-lower-thread
1359 "e" gnus-summary-edit-article
1360 "#" gnus-summary-mark-as-processable
1361 "\M-#" gnus-summary-unmark-as-processable
1362 "\M-\C-t" gnus-summary-toggle-threads
1363 "\M-\C-s" gnus-summary-show-thread
1364 "\M-\C-h" gnus-summary-hide-thread
1365 "\M-\C-f" gnus-summary-next-thread
1366 "\M-\C-b" gnus-summary-prev-thread
16409b0b
GM
1367 [(meta down)] gnus-summary-next-thread
1368 [(meta up)] gnus-summary-prev-thread
eec82323
LMI
1369 "\M-\C-u" gnus-summary-up-thread
1370 "\M-\C-d" gnus-summary-down-thread
1371 "&" gnus-summary-execute-command
1372 "c" gnus-summary-catchup-and-exit
1373 "\C-w" gnus-summary-mark-region-as-read
1374 "\C-t" gnus-summary-toggle-truncation
1375 "?" gnus-summary-mark-as-dormant
1376 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1377 "\C-c\C-s\C-n" gnus-summary-sort-by-number
1378 "\C-c\C-s\C-l" gnus-summary-sort-by-lines
16409b0b 1379 "\C-c\C-s\C-c" gnus-summary-sort-by-chars
eec82323
LMI
1380 "\C-c\C-s\C-a" gnus-summary-sort-by-author
1381 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1382 "\C-c\C-s\C-d" gnus-summary-sort-by-date
1383 "\C-c\C-s\C-i" gnus-summary-sort-by-score
1384 "=" gnus-summary-expand-window
1385 "\C-x\C-s" gnus-summary-reselect-current-group
1386 "\M-g" gnus-summary-rescan-group
1387 "w" gnus-summary-stop-page-breaking
1388 "\C-c\C-r" gnus-summary-caesar-message
eec82323
LMI
1389 "f" gnus-summary-followup
1390 "F" gnus-summary-followup-with-original
1391 "C" gnus-summary-cancel-article
1392 "r" gnus-summary-reply
1393 "R" gnus-summary-reply-with-original
1394 "\C-c\C-f" gnus-summary-mail-forward
1395 "o" gnus-summary-save-article
1396 "\C-o" gnus-summary-save-article-mail
1397 "|" gnus-summary-pipe-output
1398 "\M-k" gnus-summary-edit-local-kill
1399 "\M-K" gnus-summary-edit-global-kill
1400 ;; "V" gnus-version
1401 "\C-c\C-d" gnus-summary-describe-group
1402 "q" gnus-summary-exit
1403 "Q" gnus-summary-exit-no-update
1404 "\C-c\C-i" gnus-info-find-node
1405 gnus-mouse-2 gnus-mouse-pick-article
1406 "m" gnus-summary-mail-other-window
1407 "a" gnus-summary-post-news
1408 "x" gnus-summary-limit-to-unread
1409 "s" gnus-summary-isearch-article
16409b0b 1410 "t" gnus-summary-toggle-header
eec82323
LMI
1411 "g" gnus-summary-show-article
1412 "l" gnus-summary-goto-last-article
1413 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1414 "\C-d" gnus-summary-enter-digest-group
1415 "\M-\C-d" gnus-summary-read-document
6748645f 1416 "\M-\C-e" gnus-summary-edit-parameters
16409b0b 1417 "\M-\C-a" gnus-summary-customize-parameters
eec82323
LMI
1418 "\C-c\C-b" gnus-bug
1419 "*" gnus-cache-enter-article
1420 "\M-*" gnus-cache-remove-article
1421 "\M-&" gnus-summary-universal-argument
1422 "\C-l" gnus-recenter
1423 "I" gnus-summary-increase-score
1424 "L" gnus-summary-lower-score
6748645f
LMI
1425 "\M-i" gnus-symbolic-argument
1426 "h" gnus-summary-select-article-buffer
eec82323 1427
16409b0b
GM
1428 "b" gnus-article-view-part
1429 "\M-t" gnus-summary-toggle-display-buttonized
1430
eec82323
LMI
1431 "V" gnus-summary-score-map
1432 "X" gnus-uu-extract-map
1433 "S" gnus-summary-send-map)
1434
1435 ;; Sort of orthogonal keymap
1436 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1437 "t" gnus-summary-tick-article-forward
1438 "!" gnus-summary-tick-article-forward
1439 "d" gnus-summary-mark-as-read-forward
1440 "r" gnus-summary-mark-as-read-forward
1441 "c" gnus-summary-clear-mark-forward
1442 " " gnus-summary-clear-mark-forward
1443 "e" gnus-summary-mark-as-expirable
1444 "x" gnus-summary-mark-as-expirable
1445 "?" gnus-summary-mark-as-dormant
1446 "b" gnus-summary-set-bookmark
1447 "B" gnus-summary-remove-bookmark
1448 "#" gnus-summary-mark-as-processable
1449 "\M-#" gnus-summary-unmark-as-processable
1450 "S" gnus-summary-limit-include-expunged
1451 "C" gnus-summary-catchup
1452 "H" gnus-summary-catchup-to-here
1453 "\C-c" gnus-summary-catchup-all
1454 "k" gnus-summary-kill-same-subject-and-select
1455 "K" gnus-summary-kill-same-subject
1456 "P" gnus-uu-mark-map)
1457
1458 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1459 "c" gnus-summary-clear-above
1460 "u" gnus-summary-tick-above
1461 "m" gnus-summary-mark-above
1462 "k" gnus-summary-kill-below)
1463
1464 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1465 "/" gnus-summary-limit-to-subject
1466 "n" gnus-summary-limit-to-articles
1467 "w" gnus-summary-pop-limit
1468 "s" gnus-summary-limit-to-subject
1469 "a" gnus-summary-limit-to-author
1470 "u" gnus-summary-limit-to-unread
1471 "m" gnus-summary-limit-to-marks
16409b0b 1472 "M" gnus-summary-limit-exclude-marks
eec82323 1473 "v" gnus-summary-limit-to-score
6748645f 1474 "*" gnus-summary-limit-include-cached
eec82323 1475 "D" gnus-summary-limit-include-dormant
6748645f 1476 "T" gnus-summary-limit-include-thread
eec82323
LMI
1477 "d" gnus-summary-limit-exclude-dormant
1478 "t" gnus-summary-limit-to-age
16409b0b 1479 "x" gnus-summary-limit-to-extra
eec82323
LMI
1480 "E" gnus-summary-limit-include-expunged
1481 "c" gnus-summary-limit-exclude-childless-dormant
1482 "C" gnus-summary-limit-mark-excluded-as-read)
1483
1484 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1485 "n" gnus-summary-next-unread-article
1486 "p" gnus-summary-prev-unread-article
1487 "N" gnus-summary-next-article
1488 "P" gnus-summary-prev-article
1489 "\C-n" gnus-summary-next-same-subject
1490 "\C-p" gnus-summary-prev-same-subject
1491 "\M-n" gnus-summary-next-unread-subject
1492 "\M-p" gnus-summary-prev-unread-subject
1493 "f" gnus-summary-first-unread-article
1494 "b" gnus-summary-best-unread-article
1495 "j" gnus-summary-goto-article
1496 "g" gnus-summary-goto-subject
1497 "l" gnus-summary-goto-last-article
a8151ef7 1498 "o" gnus-summary-pop-article)
eec82323
LMI
1499
1500 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1501 "k" gnus-summary-kill-thread
1502 "l" gnus-summary-lower-thread
1503 "i" gnus-summary-raise-thread
1504 "T" gnus-summary-toggle-threads
1505 "t" gnus-summary-rethread-current
1506 "^" gnus-summary-reparent-thread
1507 "s" gnus-summary-show-thread
1508 "S" gnus-summary-show-all-threads
1509 "h" gnus-summary-hide-thread
1510 "H" gnus-summary-hide-all-threads
1511 "n" gnus-summary-next-thread
1512 "p" gnus-summary-prev-thread
1513 "u" gnus-summary-up-thread
1514 "o" gnus-summary-top-thread
1515 "d" gnus-summary-down-thread
1516 "#" gnus-uu-mark-thread
1517 "\M-#" gnus-uu-unmark-thread)
1518
1519 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1520 "g" gnus-summary-prepare
1521 "c" gnus-summary-insert-cached-articles)
1522
1523 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1524 "c" gnus-summary-catchup-and-exit
1525 "C" gnus-summary-catchup-all-and-exit
1526 "E" gnus-summary-exit-no-update
1527 "Q" gnus-summary-exit
1528 "Z" gnus-summary-exit
1529 "n" gnus-summary-catchup-and-goto-next-group
1530 "R" gnus-summary-reselect-current-group
1531 "G" gnus-summary-rescan-group
1532 "N" gnus-summary-next-group
1533 "s" gnus-summary-save-newsrc
1534 "P" gnus-summary-prev-group)
1535
1536 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1537 " " gnus-summary-next-page
1538 "n" gnus-summary-next-page
1539 "\177" gnus-summary-prev-page
1540 [delete] gnus-summary-prev-page
1541 "p" gnus-summary-prev-page
1542 "\r" gnus-summary-scroll-up
6748645f 1543 "\M-\r" gnus-summary-scroll-down
eec82323
LMI
1544 "<" gnus-summary-beginning-of-article
1545 ">" gnus-summary-end-of-article
1546 "b" gnus-summary-beginning-of-article
1547 "e" gnus-summary-end-of-article
1548 "^" gnus-summary-refer-parent-article
1549 "r" gnus-summary-refer-parent-article
16409b0b 1550 "D" gnus-summary-enter-digest-group
eec82323 1551 "R" gnus-summary-refer-references
6748645f 1552 "T" gnus-summary-refer-thread
eec82323
LMI
1553 "g" gnus-summary-show-article
1554 "s" gnus-summary-isearch-article
16409b0b
GM
1555 "P" gnus-summary-print-article
1556 "t" gnus-article-babel)
eec82323
LMI
1557
1558 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1559 "b" gnus-article-add-buttons
1560 "B" gnus-article-add-buttons-to-head
1561 "o" gnus-article-treat-overstrike
1562 "e" gnus-article-emphasize
1563 "w" gnus-article-fill-cited-article
16409b0b
GM
1564 "Q" gnus-article-fill-long-lines
1565 "C" gnus-article-capitalize-sentences
eec82323
LMI
1566 "c" gnus-article-remove-cr
1567 "q" gnus-article-de-quoted-unreadable
16409b0b
GM
1568 "6" gnus-article-de-base64-unreadable
1569 "Z" gnus-article-decode-HZ
1570 "h" gnus-article-wash-html
eec82323
LMI
1571 "f" gnus-article-display-x-face
1572 "l" gnus-summary-stop-page-breaking
1573 "r" gnus-summary-caesar-message
16409b0b 1574 "t" gnus-summary-toggle-header
eec82323 1575 "v" gnus-summary-verbose-headers
16409b0b 1576 "H" gnus-article-strip-headers-in-body
6748645f 1577 "d" gnus-article-treat-dumbquotes)
eec82323
LMI
1578
1579 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1580 "a" gnus-article-hide
1581 "h" gnus-article-hide-headers
1582 "b" gnus-article-hide-boring-headers
1583 "s" gnus-article-hide-signature
1584 "c" gnus-article-hide-citation
6748645f 1585 "C" gnus-article-hide-citation-in-followups
16409b0b 1586 "l" gnus-article-hide-list-identifiers
eec82323 1587 "p" gnus-article-hide-pgp
16409b0b 1588 "B" gnus-article-strip-banner
eec82323
LMI
1589 "P" gnus-article-hide-pem
1590 "\C-c" gnus-article-hide-citation-maybe)
1591
1592 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1593 "a" gnus-article-highlight
1594 "h" gnus-article-highlight-headers
1595 "c" gnus-article-highlight-citation
1596 "s" gnus-article-highlight-signature)
1597
16409b0b
GM
1598 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1599 "w" gnus-article-decode-mime-words
1600 "c" gnus-article-decode-charset
1601 "v" gnus-mime-view-all-parts
1602 "b" gnus-article-view-part)
1603
eec82323
LMI
1604 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1605 "z" gnus-article-date-ut
1606 "u" gnus-article-date-ut
1607 "l" gnus-article-date-local
1608 "e" gnus-article-date-lapsed
1609 "o" gnus-article-date-original
6748645f 1610 "i" gnus-article-date-iso8601
eec82323
LMI
1611 "s" gnus-article-date-user)
1612
1613 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1614 "t" gnus-article-remove-trailing-blank-lines
1615 "l" gnus-article-strip-leading-blank-lines
1616 "m" gnus-article-strip-multiple-blank-lines
1617 "a" gnus-article-strip-blank-lines
6748645f 1618 "A" gnus-article-strip-all-blank-lines
16409b0b
GM
1619 "s" gnus-article-strip-leading-space
1620 "e" gnus-article-strip-trailing-space)
eec82323
LMI
1621
1622 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1623 "v" gnus-version
1624 "f" gnus-summary-fetch-faq
1625 "d" gnus-summary-describe-group
1626 "h" gnus-summary-describe-briefly
1627 "i" gnus-info-find-node)
1628
1629 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1630 "e" gnus-summary-expire-articles
1631 "\M-\C-e" gnus-summary-expire-articles-now
1632 "\177" gnus-summary-delete-article
1633 [delete] gnus-summary-delete-article
16409b0b 1634 [backspace] gnus-summary-delete-article
eec82323
LMI
1635 "m" gnus-summary-move-article
1636 "r" gnus-summary-respool-article
1637 "w" gnus-summary-edit-article
1638 "c" gnus-summary-copy-article
1639 "B" gnus-summary-crosspost-article
1640 "q" gnus-summary-respool-query
6748645f 1641 "t" gnus-summary-respool-trace
eec82323
LMI
1642 "i" gnus-summary-import-article
1643 "p" gnus-summary-article-posted-p)
1644
1645 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1646 "o" gnus-summary-save-article
1647 "m" gnus-summary-save-article-mail
1648 "F" gnus-summary-write-article-file
1649 "r" gnus-summary-save-article-rmail
1650 "f" gnus-summary-save-article-file
1651 "b" gnus-summary-save-article-body-file
1652 "h" gnus-summary-save-article-folder
1653 "v" gnus-summary-save-article-vm
1654 "p" gnus-summary-pipe-output
16409b0b
GM
1655 "s" gnus-soup-add-article)
1656
1657 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1658 "b" gnus-summary-display-buttonized
1659 "m" gnus-summary-repair-multipart
1660 "v" gnus-article-view-part
1661 "o" gnus-article-save-part
1662 "c" gnus-article-copy-part
1663 "e" gnus-article-externalize-part
1664 "i" gnus-article-inline-part
1665 "|" gnus-article-pipe-part))
eec82323
LMI
1666
1667(defun gnus-summary-make-menu-bar ()
1668 (gnus-turn-off-edit-menu 'summary)
1669
1670 (unless (boundp 'gnus-summary-misc-menu)
1671
1672 (easy-menu-define
1673 gnus-summary-kill-menu gnus-summary-mode-map ""
1674 (cons
1675 "Score"
1676 (nconc
1677 (list
1678 ["Enter score..." gnus-summary-score-entry t]
1679 ["Customize" gnus-score-customize t])
1680 (gnus-make-score-map 'increase)
1681 (gnus-make-score-map 'lower)
1682 '(("Mark"
1683 ["Kill below" gnus-summary-kill-below t]
1684 ["Mark above" gnus-summary-mark-above t]
1685 ["Tick above" gnus-summary-tick-above t]
1686 ["Clear above" gnus-summary-clear-above t])
1687 ["Current score" gnus-summary-current-score t]
1688 ["Set score" gnus-summary-set-score t]
1689 ["Switch current score file..." gnus-score-change-score-file t]
1690 ["Set mark below..." gnus-score-set-mark-below t]
1691 ["Set expunge below..." gnus-score-set-expunge-below t]
1692 ["Edit current score file" gnus-score-edit-current-scores t]
1693 ["Edit score file" gnus-score-edit-file t]
1694 ["Trace score" gnus-score-find-trace t]
1695 ["Find words" gnus-score-find-favourite-words t]
1696 ["Rescore buffer" gnus-summary-rescore t]
1697 ["Increase score..." gnus-summary-increase-score t]
1698 ["Lower score..." gnus-summary-lower-score t]))))
1699
6748645f
LMI
1700 ;; Define both the Article menu in the summary buffer and the equivalent
1701 ;; Commands menu in the article buffer here for consistency.
1702 (let ((innards
1703 '(("Hide"
1704 ["All" gnus-article-hide t]
1705 ["Headers" gnus-article-hide-headers t]
1706 ["Signature" gnus-article-hide-signature t]
1707 ["Citation" gnus-article-hide-citation t]
16409b0b 1708 ["List identifiers" gnus-article-hide-list-identifiers t]
6748645f 1709 ["PGP" gnus-article-hide-pgp t]
16409b0b 1710 ["Banner" gnus-article-strip-banner t]
6748645f
LMI
1711 ["Boring headers" gnus-article-hide-boring-headers t])
1712 ("Highlight"
1713 ["All" gnus-article-highlight t]
1714 ["Headers" gnus-article-highlight-headers t]
1715 ["Signature" gnus-article-highlight-signature t]
1716 ["Citation" gnus-article-highlight-citation t])
16409b0b
GM
1717 ("MIME"
1718 ["Words" gnus-article-decode-mime-words t]
1719 ["Charset" gnus-article-decode-charset t]
1720 ["QP" gnus-article-de-quoted-unreadable t]
1721 ["Base64" gnus-article-de-base64-unreadable t]
1722 ["View all" gnus-mime-view-all-parts t])
6748645f
LMI
1723 ("Date"
1724 ["Local" gnus-article-date-local t]
1725 ["ISO8601" gnus-article-date-iso8601 t]
1726 ["UT" gnus-article-date-ut t]
1727 ["Original" gnus-article-date-original t]
1728 ["Lapsed" gnus-article-date-lapsed t]
1729 ["User-defined" gnus-article-date-user t])
1730 ("Washing"
1731 ("Remove Blanks"
1732 ["Leading" gnus-article-strip-leading-blank-lines t]
1733 ["Multiple" gnus-article-strip-multiple-blank-lines t]
1734 ["Trailing" gnus-article-remove-trailing-blank-lines t]
1735 ["All of the above" gnus-article-strip-blank-lines t]
1736 ["All" gnus-article-strip-all-blank-lines t]
16409b0b
GM
1737 ["Leading space" gnus-article-strip-leading-space t]
1738 ["Trailing space" gnus-article-strip-trailing-space t])
6748645f
LMI
1739 ["Overstrike" gnus-article-treat-overstrike t]
1740 ["Dumb quotes" gnus-article-treat-dumbquotes t]
1741 ["Emphasis" gnus-article-emphasize t]
1742 ["Word wrap" gnus-article-fill-cited-article t]
16409b0b
GM
1743 ["Fill long lines" gnus-article-fill-long-lines t]
1744 ["Capitalize sentences" gnus-article-capitalize-sentences t]
6748645f
LMI
1745 ["CR" gnus-article-remove-cr t]
1746 ["Show X-Face" gnus-article-display-x-face t]
1747 ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
16409b0b 1748 ["Base64" gnus-article-de-base64-unreadable t]
60bd5589
DL
1749 ["Rot 13" gnus-summary-caesar-message
1750 :help "\"Caesar rotate\" article by 13"]
6748645f
LMI
1751 ["Unix pipe" gnus-summary-pipe-message t]
1752 ["Add buttons" gnus-article-add-buttons t]
1753 ["Add buttons to head" gnus-article-add-buttons-to-head t]
1754 ["Stop page breaking" gnus-summary-stop-page-breaking t]
6748645f 1755 ["Verbose header" gnus-summary-verbose-headers t]
16409b0b
GM
1756 ["Toggle header" gnus-summary-toggle-header t]
1757 ["Html" gnus-article-wash-html t]
1758 ["HZ" gnus-article-decode-HZ t])
6748645f 1759 ("Output"
60bd5589
DL
1760 ["Save in default format" gnus-summary-save-article
1761 :help "Save article using default method"]
1762 ["Save in file" gnus-summary-save-article-file
1763 :help "Save article in file"]
6748645f
LMI
1764 ["Save in Unix mail format" gnus-summary-save-article-mail t]
1765 ["Save in MH folder" gnus-summary-save-article-folder t]
1766 ["Save in VM folder" gnus-summary-save-article-vm t]
1767 ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1768 ["Save body in file" gnus-summary-save-article-body-file t]
1769 ["Pipe through a filter" gnus-summary-pipe-output t]
1770 ["Add to SOUP packet" gnus-soup-add-article t]
1771 ["Print" gnus-summary-print-article t])
1772 ("Backend"
1773 ["Respool article..." gnus-summary-respool-article t]
1774 ["Move article..." gnus-summary-move-article
1775 (gnus-check-backend-function
1776 'request-move-article gnus-newsgroup-name)]
1777 ["Copy article..." gnus-summary-copy-article t]
1778 ["Crosspost article..." gnus-summary-crosspost-article
1779 (gnus-check-backend-function
1780 'request-replace-article gnus-newsgroup-name)]
1781 ["Import file..." gnus-summary-import-article t]
1782 ["Check if posted" gnus-summary-article-posted-p t]
1783 ["Edit article" gnus-summary-edit-article
1784 (not (gnus-group-read-only-p))]
1785 ["Delete article" gnus-summary-delete-article
1786 (gnus-check-backend-function
1787 'request-expire-articles gnus-newsgroup-name)]
1788 ["Query respool" gnus-summary-respool-query t]
1789 ["Trace respool" gnus-summary-respool-trace t]
1790 ["Delete expirable articles" gnus-summary-expire-articles-now
1791 (gnus-check-backend-function
1792 'request-expire-articles gnus-newsgroup-name)])
1793 ("Extract"
60bd5589
DL
1794 ["Uudecode" gnus-uu-decode-uu
1795 :help "Decode uuencoded article(s)"]
6748645f
LMI
1796 ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1797 ["Unshar" gnus-uu-decode-unshar t]
1798 ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1799 ["Save" gnus-uu-decode-save t]
1800 ["Binhex" gnus-uu-decode-binhex t]
1801 ["Postscript" gnus-uu-decode-postscript t])
1802 ("Cache"
1803 ["Enter article" gnus-cache-enter-article t]
1804 ["Remove article" gnus-cache-remove-article t])
16409b0b 1805 ["Translate" gnus-article-babel t]
6748645f
LMI
1806 ["Select article buffer" gnus-summary-select-article-buffer t]
1807 ["Enter digest buffer" gnus-summary-enter-digest-group t]
1808 ["Isearch article..." gnus-summary-isearch-article t]
1809 ["Beginning of the article" gnus-summary-beginning-of-article t]
1810 ["End of the article" gnus-summary-end-of-article t]
1811 ["Fetch parent of article" gnus-summary-refer-parent-article t]
1812 ["Fetch referenced articles" gnus-summary-refer-references t]
1813 ["Fetch current thread" gnus-summary-refer-thread t]
1814 ["Fetch article with id..." gnus-summary-refer-article t]
1815 ["Redisplay" gnus-summary-show-article t])))
1816 (easy-menu-define
1817 gnus-summary-article-menu gnus-summary-mode-map ""
1818 (cons "Article" innards))
1819
1653df0f
SZ
1820 (if (not (keymapp gnus-summary-article-menu))
1821 (easy-menu-define
1822 gnus-article-commands-menu gnus-article-mode-map ""
1823 (cons "Commands" innards))
1824 ;; in Emacs, don't share menu.
1825 (setq gnus-article-commands-menu
1826 (copy-keymap gnus-summary-article-menu))
1827 (define-key gnus-article-mode-map [menu-bar commands]
1828 (cons "Commands" gnus-article-commands-menu))))
eec82323
LMI
1829
1830 (easy-menu-define
1831 gnus-summary-thread-menu gnus-summary-mode-map ""
1832 '("Threads"
1833 ["Toggle threading" gnus-summary-toggle-threads t]
1834 ["Hide threads" gnus-summary-hide-all-threads t]
1835 ["Show threads" gnus-summary-show-all-threads t]
1836 ["Hide thread" gnus-summary-hide-thread t]
1837 ["Show thread" gnus-summary-show-thread t]
1838 ["Go to next thread" gnus-summary-next-thread t]
1839 ["Go to previous thread" gnus-summary-prev-thread t]
1840 ["Go down thread" gnus-summary-down-thread t]
1841 ["Go up thread" gnus-summary-up-thread t]
1842 ["Top of thread" gnus-summary-top-thread t]
1843 ["Mark thread as read" gnus-summary-kill-thread t]
1844 ["Lower thread score" gnus-summary-lower-thread t]
1845 ["Raise thread score" gnus-summary-raise-thread t]
16409b0b 1846 ["Rethread current" gnus-summary-rethread-current t]))
eec82323
LMI
1847
1848 (easy-menu-define
1849 gnus-summary-post-menu gnus-summary-mode-map ""
1850 '("Post"
60bd5589
DL
1851 ["Post an article" gnus-summary-post-news
1852 :help "Post an article"]
1853 ["Followup" gnus-summary-followup
1854 :help "Post followup to this article"]
1855 ["Followup and yank" gnus-summary-followup-with-original
1856 :help "Post followup to this article, quoting its contents"]
eec82323 1857 ["Supersede article" gnus-summary-supersede-article t]
60bd5589
DL
1858 ["Cancel article" gnus-summary-cancel-article
1859 :help "Cancel an article you posted"]
eec82323
LMI
1860 ["Reply" gnus-summary-reply t]
1861 ["Reply and yank" gnus-summary-reply-with-original t]
1862 ["Wide reply" gnus-summary-wide-reply t]
60bd5589
DL
1863 ["Wide reply and yank" gnus-summary-wide-reply-with-original
1864 :help "Mail a reply, quoting this article"]
eec82323
LMI
1865 ["Mail forward" gnus-summary-mail-forward t]
1866 ["Post forward" gnus-summary-post-forward t]
1867 ["Digest and mail" gnus-uu-digest-mail-forward t]
1868 ["Digest and post" gnus-uu-digest-post-forward t]
1869 ["Resend message" gnus-summary-resend-message t]
1870 ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1871 ["Send a mail" gnus-summary-mail-other-window t]
60bd5589
DL
1872 ["Uuencode and post" gnus-uu-post-news
1873 :help "Post a uuencoded article"]
eec82323
LMI
1874 ["Followup via news" gnus-summary-followup-to-mail t]
1875 ["Followup via news and yank"
1876 gnus-summary-followup-to-mail-with-original t]
1877 ;;("Draft"
1878 ;;["Send" gnus-summary-send-draft t]
1879 ;;["Send bounced" gnus-resend-bounced-mail t])
1880 ))
1881
1882 (easy-menu-define
1883 gnus-summary-misc-menu gnus-summary-mode-map ""
1884 '("Misc"
1885 ("Mark Read"
1886 ["Mark as read" gnus-summary-mark-as-read-forward t]
1887 ["Mark same subject and select"
1888 gnus-summary-kill-same-subject-and-select t]
1889 ["Mark same subject" gnus-summary-kill-same-subject t]
60bd5589
DL
1890 ["Catchup" gnus-summary-catchup
1891 :help "Mark unread articles in this group as read"]
eec82323
LMI
1892 ["Catchup all" gnus-summary-catchup-all t]
1893 ["Catchup to here" gnus-summary-catchup-to-here t]
1894 ["Catchup region" gnus-summary-mark-region-as-read t]
1895 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1896 ("Mark Various"
1897 ["Tick" gnus-summary-tick-article-forward t]
1898 ["Mark as dormant" gnus-summary-mark-as-dormant t]
1899 ["Remove marks" gnus-summary-clear-mark-forward t]
1900 ["Set expirable mark" gnus-summary-mark-as-expirable t]
1901 ["Set bookmark" gnus-summary-set-bookmark t]
1902 ["Remove bookmark" gnus-summary-remove-bookmark t])
1903 ("Mark Limit"
1904 ["Marks..." gnus-summary-limit-to-marks t]
1905 ["Subject..." gnus-summary-limit-to-subject t]
1906 ["Author..." gnus-summary-limit-to-author t]
1907 ["Age..." gnus-summary-limit-to-age t]
16409b0b 1908 ["Extra..." gnus-summary-limit-to-extra t]
eec82323
LMI
1909 ["Score" gnus-summary-limit-to-score t]
1910 ["Unread" gnus-summary-limit-to-unread t]
1911 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1912 ["Articles" gnus-summary-limit-to-articles t]
1913 ["Pop limit" gnus-summary-pop-limit t]
1914 ["Show dormant" gnus-summary-limit-include-dormant t]
1915 ["Hide childless dormant"
1916 gnus-summary-limit-exclude-childless-dormant t]
1917 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
16409b0b 1918 ["Hide marked" gnus-summary-limit-exclude-marks t]
eec82323
LMI
1919 ["Show expunged" gnus-summary-show-all-expunged t])
1920 ("Process Mark"
1921 ["Set mark" gnus-summary-mark-as-processable t]
1922 ["Remove mark" gnus-summary-unmark-as-processable t]
1923 ["Remove all marks" gnus-summary-unmark-all-processable t]
1924 ["Mark above" gnus-uu-mark-over t]
1925 ["Mark series" gnus-uu-mark-series t]
1926 ["Mark region" gnus-uu-mark-region t]
6748645f 1927 ["Unmark region" gnus-uu-unmark-region t]
eec82323 1928 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
6748645f 1929 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
eec82323
LMI
1930 ["Mark all" gnus-uu-mark-all t]
1931 ["Mark buffer" gnus-uu-mark-buffer t]
1932 ["Mark sparse" gnus-uu-mark-sparse t]
1933 ["Mark thread" gnus-uu-mark-thread t]
1934 ["Unmark thread" gnus-uu-unmark-thread t]
1935 ("Process Mark Sets"
1936 ["Kill" gnus-summary-kill-process-mark t]
1937 ["Yank" gnus-summary-yank-process-mark
1938 gnus-newsgroup-process-stack]
1939 ["Save" gnus-summary-save-process-mark t]))
1940 ("Scroll article"
60bd5589
DL
1941 ["Page forward" gnus-summary-next-page
1942 :help "Show next page of article"]
1943 ["Page backward" gnus-summary-prev-page
1944 :help "Show previous page of article"]
eec82323
LMI
1945 ["Line forward" gnus-summary-scroll-up t])
1946 ("Move"
1947 ["Next unread article" gnus-summary-next-unread-article t]
1948 ["Previous unread article" gnus-summary-prev-unread-article t]
1949 ["Next article" gnus-summary-next-article t]
1950 ["Previous article" gnus-summary-prev-article t]
1951 ["Next unread subject" gnus-summary-next-unread-subject t]
1952 ["Previous unread subject" gnus-summary-prev-unread-subject t]
1953 ["Next article same subject" gnus-summary-next-same-subject t]
1954 ["Previous article same subject" gnus-summary-prev-same-subject t]
1955 ["First unread article" gnus-summary-first-unread-article t]
1956 ["Best unread article" gnus-summary-best-unread-article t]
1957 ["Go to subject number..." gnus-summary-goto-subject t]
1958 ["Go to article number..." gnus-summary-goto-article t]
1959 ["Go to the last article" gnus-summary-goto-last-article t]
1960 ["Pop article off history" gnus-summary-pop-article t])
1961 ("Sort"
1962 ["Sort by number" gnus-summary-sort-by-number t]
1963 ["Sort by author" gnus-summary-sort-by-author t]
1964 ["Sort by subject" gnus-summary-sort-by-subject t]
1965 ["Sort by date" gnus-summary-sort-by-date t]
1966 ["Sort by score" gnus-summary-sort-by-score t]
16409b0b
GM
1967 ["Sort by lines" gnus-summary-sort-by-lines t]
1968 ["Sort by characters" gnus-summary-sort-by-chars t])
eec82323
LMI
1969 ("Help"
1970 ["Fetch group FAQ" gnus-summary-fetch-faq t]
1971 ["Describe group" gnus-summary-describe-group t]
1972 ["Read manual" gnus-info-find-node t])
1973 ("Modes"
1974 ["Pick and read" gnus-pick-mode t]
1975 ["Binary" gnus-binary-mode t])
1976 ("Regeneration"
1977 ["Regenerate" gnus-summary-prepare t]
1978 ["Insert cached articles" gnus-summary-insert-cached-articles t]
1979 ["Toggle threading" gnus-summary-toggle-threads t])
1980 ["Filter articles..." gnus-summary-execute-command t]
1981 ["Run command on subjects..." gnus-summary-universal-argument t]
1982 ["Search articles forward..." gnus-summary-search-article-forward t]
1983 ["Search articles backward..." gnus-summary-search-article-backward t]
1984 ["Toggle line truncation" gnus-summary-toggle-truncation t]
1985 ["Expand window" gnus-summary-expand-window t]
1986 ["Expire expirable articles" gnus-summary-expire-articles
1987 (gnus-check-backend-function
1988 'request-expire-articles gnus-newsgroup-name)]
1989 ["Edit local kill file" gnus-summary-edit-local-kill t]
1990 ["Edit main kill file" gnus-summary-edit-global-kill t]
6748645f 1991 ["Edit group parameters" gnus-summary-edit-parameters t]
16409b0b 1992 ["Customize group parameters" gnus-summary-customize-parameters t]
6748645f 1993 ["Send a bug report" gnus-bug t]
eec82323 1994 ("Exit"
60bd5589
DL
1995 ["Catchup and exit" gnus-summary-catchup-and-exit
1996 :help "Mark unread articles in this group as read, then exit"]
6748645f 1997 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
eec82323 1998 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
60bd5589
DL
1999 ["Exit group" gnus-summary-exit
2000 :help "Exit current group, return to group selection mode"]
eec82323
LMI
2001 ["Exit group without updating" gnus-summary-exit-no-update t]
2002 ["Exit and goto next group" gnus-summary-next-group t]
2003 ["Exit and goto prev group" gnus-summary-prev-group t]
2004 ["Reselect group" gnus-summary-reselect-current-group t]
2005 ["Rescan group" gnus-summary-rescan-group t]
2006 ["Update dribble" gnus-summary-save-newsrc t])))
2007
6748645f 2008 (gnus-run-hooks 'gnus-summary-menu-hook)))
eec82323 2009
60bd5589
DL
2010(defvar gnus-summary-tool-bar-map nil)
2011
9a0026a6 2012;; Emacs 21 tool bar. Should be no-op otherwise.
b1f236d8
SZ
2013;; NB: A new function tool-bar-local-item-from-menu is added in Emacs
2014;; 21.2.50+. Considering many users use Emacs 21, use
2015;; tool-bar-add-item-from-menu here.
60bd5589 2016(defun gnus-summary-make-tool-bar ()
b1f236d8
SZ
2017 (if (and
2018 (condition-case nil (require 'tool-bar) (error nil))
2019 (fboundp 'tool-bar-add-item-from-menu)
2020 (default-value 'tool-bar-mode)
2021 (not gnus-summary-tool-bar-map))
60bd5589
DL
2022 (setq gnus-summary-tool-bar-map
2023 (let ((tool-bar-map (make-sparse-keymap)))
2024 (tool-bar-add-item-from-menu
2025 'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2026 (tool-bar-add-item-from-menu
2027 'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2028 (tool-bar-add-item-from-menu
2029 'gnus-summary-post-news "post" gnus-summary-mode-map)
2030 (tool-bar-add-item-from-menu
2031 'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2032 (tool-bar-add-item-from-menu
2033 'gnus-summary-followup "followup" gnus-summary-mode-map)
2034 (tool-bar-add-item-from-menu
2035 'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2036 (tool-bar-add-item-from-menu
2037 'gnus-summary-reply "reply" gnus-summary-mode-map)
2038 (tool-bar-add-item-from-menu
2039 'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2040 (tool-bar-add-item-from-menu
2041 'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2042 (tool-bar-add-item-from-menu
2043 'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2044 (tool-bar-add-item-from-menu
2045 'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2046 (tool-bar-add-item-from-menu
2047 'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2048 (tool-bar-add-item-from-menu
2049 'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2050 (tool-bar-add-item-from-menu
2051 'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2052 (tool-bar-add-item-from-menu
2053 'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2054 tool-bar-map)))
2055 (if gnus-summary-tool-bar-map
2056 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2057
eec82323
LMI
2058(defun gnus-score-set-default (var value)
2059 "A version of set that updates the GNU Emacs menu-bar."
2060 (set var value)
2061 ;; It is the message that forces the active status to be updated.
2062 (message ""))
2063
2064(defun gnus-make-score-map (type)
2065 "Make a summary score map of type TYPE."
2066 (if t
2067 nil
2068 (let ((headers '(("author" "from" string)
2069 ("subject" "subject" string)
2070 ("article body" "body" string)
2071 ("article head" "head" string)
2072 ("xref" "xref" string)
16409b0b 2073 ("extra header" "extra" string)
eec82323
LMI
2074 ("lines" "lines" number)
2075 ("followups to author" "followup" string)))
2076 (types '((number ("less than" <)
2077 ("greater than" >)
2078 ("equal" =))
2079 (string ("substring" s)
2080 ("exact string" e)
2081 ("fuzzy string" f)
2082 ("regexp" r))))
2083 (perms '(("temporary" (current-time-string))
2084 ("permanent" nil)
2085 ("immediate" now)))
2086 header)
2087 (list
2088 (apply
2089 'nconc
2090 (list
2091 (if (eq type 'lower)
2092 "Lower score"
2093 "Increase score"))
2094 (let (outh)
2095 (while headers
2096 (setq header (car headers))
2097 (setq outh
2098 (cons
2099 (apply
2100 'nconc
2101 (list (car header))
2102 (let ((ts (cdr (assoc (nth 2 header) types)))
2103 outt)
2104 (while ts
2105 (setq outt
2106 (cons
2107 (apply
2108 'nconc
2109 (list (caar ts))
2110 (let ((ps perms)
2111 outp)
2112 (while ps
2113 (setq outp
2114 (cons
2115 (vector
2116 (caar ps)
2117 (list
2118 'gnus-summary-score-entry
2119 (nth 1 header)
2120 (if (or (string= (nth 1 header)
2121 "head")
2122 (string= (nth 1 header)
2123 "body"))
2124 ""
2125 (list 'gnus-summary-header
2126 (nth 1 header)))
2127 (list 'quote (nth 1 (car ts)))
16409b0b
GM
2128 (list 'gnus-score-delta-default
2129 nil)
eec82323
LMI
2130 (nth 1 (car ps))
2131 t)
2132 t)
2133 outp))
2134 (setq ps (cdr ps)))
2135 (list (nreverse outp))))
2136 outt))
2137 (setq ts (cdr ts)))
2138 (list (nreverse outt))))
2139 outh))
2140 (setq headers (cdr headers)))
2141 (list (nreverse outh))))))))
2142
2143\f
2144
2145(defun gnus-summary-mode (&optional group)
2146 "Major mode for reading articles.
2147
2148All normal editing commands are switched off.
2149\\<gnus-summary-mode-map>
2150Each line in this buffer represents one article. To read an
2151article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
2152and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2153respectively.
2154
2155You can also post articles and send mail from this buffer. To
2156follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
2157of an article, type `\\[gnus-summary-reply]'.
2158
2159There are approx. one gazillion commands you can execute in this
2160buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2161
2162The following commands are available:
2163
2164\\{gnus-summary-mode-map}"
2165 (interactive)
eec82323 2166 (kill-all-local-variables)
60bd5589
DL
2167 (when (gnus-visual-p 'summary-menu 'menu)
2168 (gnus-summary-make-menu-bar)
2169 (gnus-summary-make-tool-bar))
eec82323
LMI
2170 (gnus-summary-make-local-variables)
2171 (gnus-make-thread-indent-array)
2172 (gnus-simplify-mode-line)
2173 (setq major-mode 'gnus-summary-mode)
2174 (setq mode-name "Summary")
2175 (make-local-variable 'minor-mode-alist)
2176 (use-local-map gnus-summary-mode-map)
16409b0b 2177 (buffer-disable-undo)
eec82323
LMI
2178 (setq buffer-read-only t) ;Disable modification
2179 (setq truncate-lines t)
2180 (setq selective-display t)
2181 (setq selective-display-ellipses t) ;Display `...'
2182 (gnus-summary-set-display-table)
2183 (gnus-set-default-directory)
2184 (setq gnus-newsgroup-name group)
2185 (make-local-variable 'gnus-summary-line-format)
2186 (make-local-variable 'gnus-summary-line-format-spec)
6748645f
LMI
2187 (make-local-variable 'gnus-summary-dummy-line-format)
2188 (make-local-variable 'gnus-summary-dummy-line-format-spec)
eec82323 2189 (make-local-variable 'gnus-summary-mark-positions)
6748645f
LMI
2190 (make-local-hook 'pre-command-hook)
2191 (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2192 (gnus-run-hooks 'gnus-summary-mode-hook)
d4dfaa19 2193 (mm-enable-multibyte-mule4)
eec82323
LMI
2194 (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2195 (gnus-update-summary-mark-positions))
2196
2197(defun gnus-summary-make-local-variables ()
2198 "Make all the local summary buffer variables."
16409b0b
GM
2199 (let (global)
2200 (dolist (local gnus-summary-local-variables)
eec82323
LMI
2201 (if (consp local)
2202 (progn
2203 (if (eq (cdr local) 'global)
2204 ;; Copy the global value of the variable.
2205 (setq global (symbol-value (car local)))
2206 ;; Use the value from the list.
2207 (setq global (eval (cdr local))))
16409b0b 2208 (set (make-local-variable (car local)) global))
eec82323 2209 ;; Simple nil-valued local variable.
16409b0b 2210 (set (make-local-variable local) nil)))))
eec82323
LMI
2211
2212(defun gnus-summary-clear-local-variables ()
2213 (let ((locals gnus-summary-local-variables))
2214 (while locals
2215 (if (consp (car locals))
2216 (and (vectorp (caar locals))
2217 (set (caar locals) nil))
2218 (and (vectorp (car locals))
2219 (set (car locals) nil)))
2220 (setq locals (cdr locals)))))
2221
2222;; Summary data functions.
2223
2224(defmacro gnus-data-number (data)
2225 `(car ,data))
2226
2227(defmacro gnus-data-set-number (data number)
2228 `(setcar ,data ,number))
2229
2230(defmacro gnus-data-mark (data)
2231 `(nth 1 ,data))
2232
2233(defmacro gnus-data-set-mark (data mark)
2234 `(setcar (nthcdr 1 ,data) ,mark))
2235
2236(defmacro gnus-data-pos (data)
2237 `(nth 2 ,data))
2238
2239(defmacro gnus-data-set-pos (data pos)
2240 `(setcar (nthcdr 2 ,data) ,pos))
2241
2242(defmacro gnus-data-header (data)
2243 `(nth 3 ,data))
2244
2245(defmacro gnus-data-set-header (data header)
2246 `(setf (nth 3 ,data) ,header))
2247
2248(defmacro gnus-data-level (data)
2249 `(nth 4 ,data))
2250
2251(defmacro gnus-data-unread-p (data)
2252 `(= (nth 1 ,data) gnus-unread-mark))
2253
2254(defmacro gnus-data-read-p (data)
2255 `(/= (nth 1 ,data) gnus-unread-mark))
2256
2257(defmacro gnus-data-pseudo-p (data)
2258 `(consp (nth 3 ,data)))
2259
2260(defmacro gnus-data-find (number)
2261 `(assq ,number gnus-newsgroup-data))
2262
2263(defmacro gnus-data-find-list (number &optional data)
2264 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2265 (memq (assq ,number bdata)
2266 bdata)))
2267
2268(defmacro gnus-data-make (number mark pos header level)
2269 `(list ,number ,mark ,pos ,header ,level))
2270
2271(defun gnus-data-enter (after-article number mark pos header level offset)
2272 (let ((data (gnus-data-find-list after-article)))
2273 (unless data
2274 (error "No such article: %d" after-article))
2275 (setcdr data (cons (gnus-data-make number mark pos header level)
2276 (cdr data)))
2277 (setq gnus-newsgroup-data-reverse nil)
2278 (gnus-data-update-list (cddr data) offset)))
2279
2280(defun gnus-data-enter-list (after-article list &optional offset)
2281 (when list
2282 (let ((data (and after-article (gnus-data-find-list after-article)))
2283 (ilist list))
6748645f
LMI
2284 (if (not (or data
2285 after-article))
2286 (let ((odata gnus-newsgroup-data))
2287 (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
eec82323 2288 (when offset
6748645f
LMI
2289 (gnus-data-update-list odata offset)))
2290 ;; Find the last element in the list to be spliced into the main
2291 ;; list.
2292 (while (cdr list)
2293 (setq list (cdr list)))
2294 (if (not data)
2295 (progn
2296 (setcdr list gnus-newsgroup-data)
2297 (setq gnus-newsgroup-data ilist)
2298 (when offset
2299 (gnus-data-update-list (cdr list) offset)))
2300 (setcdr list (cdr data))
2301 (setcdr data ilist)
2302 (when offset
2303 (gnus-data-update-list (cdr list) offset))))
eec82323
LMI
2304 (setq gnus-newsgroup-data-reverse nil))))
2305
2306(defun gnus-data-remove (article &optional offset)
2307 (let ((data gnus-newsgroup-data))
2308 (if (= (gnus-data-number (car data)) article)
2309 (progn
2310 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2311 gnus-newsgroup-data-reverse nil)
2312 (when offset
2313 (gnus-data-update-list gnus-newsgroup-data offset)))
2314 (while (cdr data)
2315 (when (= (gnus-data-number (cadr data)) article)
2316 (setcdr data (cddr data))
2317 (when offset
2318 (gnus-data-update-list (cdr data) offset))
2319 (setq data nil
2320 gnus-newsgroup-data-reverse nil))
2321 (setq data (cdr data))))))
2322
2323(defmacro gnus-data-list (backward)
2324 `(if ,backward
2325 (or gnus-newsgroup-data-reverse
2326 (setq gnus-newsgroup-data-reverse
2327 (reverse gnus-newsgroup-data)))
2328 gnus-newsgroup-data))
2329
2330(defun gnus-data-update-list (data offset)
2331 "Add OFFSET to the POS of all data entries in DATA."
6748645f 2332 (setq gnus-newsgroup-data-reverse nil)
eec82323
LMI
2333 (while data
2334 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2335 (setq data (cdr data))))
2336
eec82323
LMI
2337(defun gnus-summary-article-pseudo-p (article)
2338 "Say whether this article is a pseudo article or not."
2339 (not (vectorp (gnus-data-header (gnus-data-find article)))))
2340
2341(defmacro gnus-summary-article-sparse-p (article)
2342 "Say whether this article is a sparse article or not."
a8151ef7 2343 `(memq ,article gnus-newsgroup-sparse))
eec82323
LMI
2344
2345(defmacro gnus-summary-article-ancient-p (article)
2346 "Say whether this article is a sparse article or not."
2347 `(memq ,article gnus-newsgroup-ancient))
2348
2349(defun gnus-article-parent-p (number)
2350 "Say whether this article is a parent or not."
2351 (let ((data (gnus-data-find-list number)))
2352 (and (cdr data) ; There has to be an article after...
2353 (< (gnus-data-level (car data)) ; And it has to have a higher level.
2354 (gnus-data-level (nth 1 data))))))
2355
2356(defun gnus-article-children (number)
2357 "Return a list of all children to NUMBER."
2358 (let* ((data (gnus-data-find-list number))
2359 (level (gnus-data-level (car data)))
2360 children)
2361 (setq data (cdr data))
2362 (while (and data
2363 (= (gnus-data-level (car data)) (1+ level)))
2364 (push (gnus-data-number (car data)) children)
2365 (setq data (cdr data)))
2366 children))
2367
2368(defmacro gnus-summary-skip-intangible ()
2369 "If the current article is intangible, then jump to a different article."
2370 '(let ((to (get-text-property (point) 'gnus-intangible)))
2371 (and to (gnus-summary-goto-subject to))))
2372
2373(defmacro gnus-summary-article-intangible-p ()
2374 "Say whether this article is intangible or not."
2375 '(get-text-property (point) 'gnus-intangible))
2376
2377(defun gnus-article-read-p (article)
2378 "Say whether ARTICLE is read or not."
2379 (not (or (memq article gnus-newsgroup-marked)
2380 (memq article gnus-newsgroup-unreads)
2381 (memq article gnus-newsgroup-unselected)
2382 (memq article gnus-newsgroup-dormant))))
2383
2384;; Some summary mode macros.
2385
2386(defmacro gnus-summary-article-number ()
2387 "The article number of the article on the current line.
2388If there isn's an article number here, then we return the current
2389article number."
2390 '(progn
2391 (gnus-summary-skip-intangible)
2392 (or (get-text-property (point) 'gnus-number)
2393 (gnus-summary-last-subject))))
2394
2395(defmacro gnus-summary-article-header (&optional number)
6748645f 2396 "Return the header of article NUMBER."
eec82323
LMI
2397 `(gnus-data-header (gnus-data-find
2398 ,(or number '(gnus-summary-article-number)))))
2399
2400(defmacro gnus-summary-thread-level (&optional number)
6748645f 2401 "Return the level of thread that starts with article NUMBER."
eec82323
LMI
2402 `(if (and (eq gnus-summary-make-false-root 'dummy)
2403 (get-text-property (point) 'gnus-intangible))
2404 0
2405 (gnus-data-level (gnus-data-find
2406 ,(or number '(gnus-summary-article-number))))))
2407
2408(defmacro gnus-summary-article-mark (&optional number)
6748645f 2409 "Return the mark of article NUMBER."
eec82323
LMI
2410 `(gnus-data-mark (gnus-data-find
2411 ,(or number '(gnus-summary-article-number)))))
2412
2413(defmacro gnus-summary-article-pos (&optional number)
6748645f 2414 "Return the position of the line of article NUMBER."
eec82323
LMI
2415 `(gnus-data-pos (gnus-data-find
2416 ,(or number '(gnus-summary-article-number)))))
2417
2418(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2419(defmacro gnus-summary-article-subject (&optional number)
2420 "Return current subject string or nil if nothing."
2421 `(let ((headers
2422 ,(if number
2423 `(gnus-data-header (assq ,number gnus-newsgroup-data))
2424 '(gnus-data-header (assq (gnus-summary-article-number)
2425 gnus-newsgroup-data)))))
2426 (and headers
2427 (vectorp headers)
2428 (mail-header-subject headers))))
2429
2430(defmacro gnus-summary-article-score (&optional number)
2431 "Return current article score."
2432 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2433 gnus-newsgroup-scored))
2434 gnus-summary-default-score 0))
2435
2436(defun gnus-summary-article-children (&optional number)
6748645f 2437 "Return a list of article numbers that are children of article NUMBER."
eec82323
LMI
2438 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2439 (level (gnus-data-level (car data)))
2440 l children)
2441 (while (and (setq data (cdr data))
2442 (> (setq l (gnus-data-level (car data))) level))
2443 (and (= (1+ level) l)
2444 (push (gnus-data-number (car data))
2445 children)))
2446 (nreverse children)))
2447
2448(defun gnus-summary-article-parent (&optional number)
6748645f 2449 "Return the article number of the parent of article NUMBER."
eec82323
LMI
2450 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2451 (gnus-data-list t)))
2452 (level (gnus-data-level (car data))))
2453 (if (zerop level)
2454 () ; This is a root.
2455 ;; We search until we find an article with a level less than
2456 ;; this one. That function has to be the parent.
2457 (while (and (setq data (cdr data))
2458 (not (< (gnus-data-level (car data)) level))))
2459 (and data (gnus-data-number (car data))))))
2460
2461(defun gnus-unread-mark-p (mark)
2462 "Say whether MARK is the unread mark."
2463 (= mark gnus-unread-mark))
2464
2465(defun gnus-read-mark-p (mark)
2466 "Say whether MARK is one of the marks that mark as read.
2467This is all marks except unread, ticked, dormant, and expirable."
2468 (not (or (= mark gnus-unread-mark)
2469 (= mark gnus-ticked-mark)
2470 (= mark gnus-dormant-mark)
2471 (= mark gnus-expirable-mark))))
2472
2473(defmacro gnus-article-mark (number)
6748645f
LMI
2474 "Return the MARK of article NUMBER.
2475This macro should only be used when computing the mark the \"first\"
2476time; i.e., when generating the summary lines. After that,
2477`gnus-summary-article-mark' should be used to examine the
2478marks of articles."
eec82323 2479 `(cond
6748645f
LMI
2480 ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2481 ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2482 ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
eec82323
LMI
2483 ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2484 ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2485 ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2486 ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2487 (t (or (cdr (assq ,number gnus-newsgroup-reads))
2488 gnus-ancient-mark))))
2489
2490;; Saving hidden threads.
2491
2492(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2493(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2494
2495(defmacro gnus-save-hidden-threads (&rest forms)
2496 "Save hidden threads, eval FORMS, and restore the hidden threads."
2497 (let ((config (make-symbol "config")))
2498 `(let ((,config (gnus-hidden-threads-configuration)))
2499 (unwind-protect
2500 (save-excursion
2501 ,@forms)
2502 (gnus-restore-hidden-threads-configuration ,config)))))
2503
107ecebb
AS
2504(defun gnus-data-compute-positions ()
2505 "Compute the positions of all articles."
2506 (setq gnus-newsgroup-data-reverse nil)
2507 (let ((data gnus-newsgroup-data))
2508 (save-excursion
2509 (gnus-save-hidden-threads
2510 (gnus-summary-show-all-threads)
2511 (goto-char (point-min))
2512 (while data
2513 (while (get-text-property (point) 'gnus-intangible)
2514 (forward-line 1))
2515 (gnus-data-set-pos (car data) (+ (point) 3))
2516 (setq data (cdr data))
2517 (forward-line 1))))))
2518
16409b0b
GM
2519(defun gnus-hidden-threads-configuration ()
2520 "Return the current hidden threads configuration."
2521 (save-excursion
2522 (let (config)
2523 (goto-char (point-min))
2524 (while (search-forward "\r" nil t)
2525 (push (1- (point)) config))
2526 config)))
2527
2528(defun gnus-restore-hidden-threads-configuration (config)
2529 "Restore hidden threads configuration from CONFIG."
2530 (save-excursion
2531 (let (point buffer-read-only)
2532 (while (setq point (pop config))
2533 (when (and (< point (point-max))
2534 (goto-char point)
2535 (eq (char-after) ?\n))
2536 (subst-char-in-region point (1+ point) ?\n ?\r))))))
2537
eec82323
LMI
2538;; Various summary mode internalish functions.
2539
2540(defun gnus-mouse-pick-article (e)
2541 (interactive "e")
2542 (mouse-set-point e)
2543 (gnus-summary-next-page nil t))
2544
2545(defun gnus-summary-set-display-table ()
16409b0b
GM
2546 "Change the display table.
2547Odd characters have a tendency to mess
2548up nicely formatted displays - we make all possible glyphs
2549display only a single character."
eec82323
LMI
2550
2551 ;; We start from the standard display table, if any.
2552 (let ((table (or (copy-sequence standard-display-table)
2553 (make-display-table)))
2554 (i 32))
2555 ;; Nix out all the control chars...
2556 (while (>= (setq i (1- i)) 0)
2557 (aset table i [??]))
2558 ;; ... but not newline and cr, of course. (cr is necessary for the
2559 ;; selective display).
2560 (aset table ?\n nil)
2561 (aset table ?\r nil)
6748645f
LMI
2562 ;; We keep TAB as well.
2563 (aset table ?\t nil)
eec82323
LMI
2564 ;; We nix out any glyphs over 126 that are not set already.
2565 (let ((i 256))
2566 (while (>= (setq i (1- i)) 127)
2567 ;; Only modify if the entry is nil.
2568 (unless (aref table i)
2569 (aset table i [??]))))
2570 (setq buffer-display-table table)))
2571
2572(defun gnus-summary-setup-buffer (group)
2573 "Initialize summary buffer."
2574 (let ((buffer (concat "*Summary " group "*")))
2575 (if (get-buffer buffer)
2576 (progn
2577 (set-buffer buffer)
2578 (setq gnus-summary-buffer (current-buffer))
2579 (not gnus-newsgroup-prepared))
2580 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6748645f 2581 (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
eec82323
LMI
2582 (gnus-summary-mode group)
2583 (when gnus-carpal
2584 (gnus-carpal-setup-buffer 'summary))
2585 (unless gnus-single-article-buffer
2586 (make-local-variable 'gnus-article-buffer)
2587 (make-local-variable 'gnus-article-current)
2588 (make-local-variable 'gnus-original-article-buffer))
2589 (setq gnus-newsgroup-name group)
2590 t)))
2591
2592(defun gnus-set-global-variables ()
16409b0b
GM
2593 "Set the global equivalents of the buffer-local variables.
2594They are set to the latest values they had. These reflect the summary
2595buffer that was in action when the last article was fetched."
eec82323
LMI
2596 (when (eq major-mode 'gnus-summary-mode)
2597 (setq gnus-summary-buffer (current-buffer))
2598 (let ((name gnus-newsgroup-name)
2599 (marked gnus-newsgroup-marked)
2600 (unread gnus-newsgroup-unreads)
2601 (headers gnus-current-headers)
2602 (data gnus-newsgroup-data)
2603 (summary gnus-summary-buffer)
2604 (article-buffer gnus-article-buffer)
2605 (original gnus-original-article-buffer)
2606 (gac gnus-article-current)
2607 (reffed gnus-reffed-article-number)
16409b0b
GM
2608 (score-file gnus-current-score-file)
2609 (default-charset gnus-newsgroup-charset))
eec82323
LMI
2610 (save-excursion
2611 (set-buffer gnus-group-buffer)
6748645f
LMI
2612 (setq gnus-newsgroup-name name
2613 gnus-newsgroup-marked marked
2614 gnus-newsgroup-unreads unread
2615 gnus-current-headers headers
2616 gnus-newsgroup-data data
2617 gnus-article-current gac
2618 gnus-summary-buffer summary
2619 gnus-article-buffer article-buffer
2620 gnus-original-article-buffer original
2621 gnus-reffed-article-number reffed
16409b0b
GM
2622 gnus-current-score-file score-file
2623 gnus-newsgroup-charset default-charset)
eec82323
LMI
2624 ;; The article buffer also has local variables.
2625 (when (gnus-buffer-live-p gnus-article-buffer)
2626 (set-buffer gnus-article-buffer)
2627 (setq gnus-summary-buffer summary))))))
2628
2629(defun gnus-summary-article-unread-p (article)
2630 "Say whether ARTICLE is unread or not."
2631 (memq article gnus-newsgroup-unreads))
2632
2633(defun gnus-summary-first-article-p (&optional article)
2634 "Return whether ARTICLE is the first article in the buffer."
2635 (if (not (setq article (or article (gnus-summary-article-number))))
2636 nil
2637 (eq article (caar gnus-newsgroup-data))))
2638
2639(defun gnus-summary-last-article-p (&optional article)
2640 "Return whether ARTICLE is the last article in the buffer."
2641 (if (not (setq article (or article (gnus-summary-article-number))))
16409b0b
GM
2642 ;; All non-existent numbers are the last article. :-)
2643 t
eec82323
LMI
2644 (not (cdr (gnus-data-find-list article)))))
2645
2646(defun gnus-make-thread-indent-array ()
2647 (let ((n 200))
2648 (unless (and gnus-thread-indent-array
2649 (= gnus-thread-indent-level gnus-thread-indent-array-level))
2650 (setq gnus-thread-indent-array (make-vector 201 "")
2651 gnus-thread-indent-array-level gnus-thread-indent-level)
2652 (while (>= n 0)
2653 (aset gnus-thread-indent-array n
2654 (make-string (* n gnus-thread-indent-level) ? ))
2655 (setq n (1- n))))))
2656
2657(defun gnus-update-summary-mark-positions ()
2658 "Compute where the summary marks are to go."
2659 (save-excursion
6748645f 2660 (when (gnus-buffer-exists-p gnus-summary-buffer)
eec82323
LMI
2661 (set-buffer gnus-summary-buffer))
2662 (let ((gnus-replied-mark 129)
2663 (gnus-score-below-mark 130)
2664 (gnus-score-over-mark 130)
6748645f 2665 (gnus-download-mark 131)
eec82323 2666 (spec gnus-summary-line-format-spec)
6748645f 2667 gnus-visual pos)
eec82323
LMI
2668 (save-excursion
2669 (gnus-set-work-buffer)
6748645f
LMI
2670 (let ((gnus-summary-line-format-spec spec)
2671 (gnus-newsgroup-downloadable '((0 . t))))
eec82323 2672 (gnus-summary-insert-line
16409b0b 2673 [0 "" "" "" "" "" 0 0 "" nil] 0 nil 128 t nil "" nil 1)
eec82323
LMI
2674 (goto-char (point-min))
2675 (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2676 (- (point) 2)))))
2677 (goto-char (point-min))
2678 (push (cons 'replied (and (search-forward "\201" nil t)
2679 (- (point) 2)))
2680 pos)
2681 (goto-char (point-min))
2682 (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
6748645f
LMI
2683 pos)
2684 (goto-char (point-min))
2685 (push (cons 'download
2686 (and (search-forward "\203" nil t) (- (point) 2)))
eec82323
LMI
2687 pos)))
2688 (setq gnus-summary-mark-positions pos))))
2689
2690(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2691 "Insert a dummy root in the summary buffer."
2692 (beginning-of-line)
2693 (gnus-add-text-properties
2694 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2695 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2696
16409b0b
GM
2697(defun gnus-summary-from-or-to-or-newsgroups (header)
2698 (let ((to (cdr (assq 'To (mail-header-extra header))))
2699 (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2700 (mail-parse-charset gnus-newsgroup-charset)
2701 (mail-parse-ignored-charsets
2702 (save-excursion (set-buffer gnus-summary-buffer)
2703 gnus-newsgroup-ignored-charsets)))
2704 (cond
2705 ((and to
2706 gnus-ignored-from-addresses
2707 (string-match gnus-ignored-from-addresses
2708 (mail-header-from header)))
2709 (concat "-> "
2710 (or (car (funcall gnus-extract-address-components
2711 (funcall
2712 gnus-decode-encoded-word-function to)))
2713 (funcall gnus-decode-encoded-word-function to))))
2714 ((and newsgroups
2715 gnus-ignored-from-addresses
2716 (string-match gnus-ignored-from-addresses
2717 (mail-header-from header)))
2718 (concat "=> " newsgroups))
2719 (t
2720 (or (car (funcall gnus-extract-address-components
2721 (mail-header-from header)))
2722 (mail-header-from header))))))
2723
eec82323
LMI
2724(defun gnus-summary-insert-line (gnus-tmp-header
2725 gnus-tmp-level gnus-tmp-current
2726 gnus-tmp-unread gnus-tmp-replied
2727 gnus-tmp-expirable gnus-tmp-subject-or-nil
2728 &optional gnus-tmp-dummy gnus-tmp-score
2729 gnus-tmp-process)
2730 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2731 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2732 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2733 (gnus-tmp-score-char
2734 (if (or (null gnus-summary-default-score)
2735 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2736 gnus-summary-zcore-fuzz))
16409b0b 2737 ? ;Whitespace
eec82323
LMI
2738 (if (< gnus-tmp-score gnus-summary-default-score)
2739 gnus-score-below-mark gnus-score-over-mark)))
2740 (gnus-tmp-replied
2741 (cond (gnus-tmp-process gnus-process-mark)
2742 ((memq gnus-tmp-current gnus-newsgroup-cached)
2743 gnus-cached-mark)
2744 (gnus-tmp-replied gnus-replied-mark)
2745 ((memq gnus-tmp-current gnus-newsgroup-saved)
2746 gnus-saved-mark)
2747 (t gnus-unread-mark)))
2748 (gnus-tmp-from (mail-header-from gnus-tmp-header))
2749 (gnus-tmp-name
2750 (cond
2751 ((string-match "<[^>]+> *$" gnus-tmp-from)
2752 (let ((beg (match-beginning 0)))
2753 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2754 (substring gnus-tmp-from (1+ (match-beginning 0))
2755 (1- (match-end 0))))
2756 (substring gnus-tmp-from 0 beg))))
2757 ((string-match "(.+)" gnus-tmp-from)
2758 (substring gnus-tmp-from
2759 (1+ (match-beginning 0)) (1- (match-end 0))))
2760 (t gnus-tmp-from)))
2761 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2762 (gnus-tmp-number (mail-header-number gnus-tmp-header))
2763 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2764 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2765 (buffer-read-only nil))
2766 (when (string= gnus-tmp-name "")
2767 (setq gnus-tmp-name gnus-tmp-from))
2768 (unless (numberp gnus-tmp-lines)
2769 (setq gnus-tmp-lines 0))
16409b0b 2770 (gnus-put-text-property
eec82323
LMI
2771 (point)
2772 (progn (eval gnus-summary-line-format-spec) (point))
2773 'gnus-number gnus-tmp-number)
2774 (when (gnus-visual-p 'summary-highlight 'highlight)
2775 (forward-line -1)
6748645f 2776 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
2777 (forward-line 1))))
2778
2779(defun gnus-summary-update-line (&optional dont-update)
16409b0b 2780 "Update summary line after change."
eec82323
LMI
2781 (when (and gnus-summary-default-score
2782 (not gnus-summary-inhibit-highlight))
2783 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2784 (article (gnus-summary-article-number))
2785 (score (gnus-summary-article-score article)))
2786 (unless dont-update
2787 (if (and gnus-summary-mark-below
2788 (< (gnus-summary-article-score)
2789 gnus-summary-mark-below))
2790 ;; This article has a low score, so we mark it as read.
2791 (when (memq article gnus-newsgroup-unreads)
2792 (gnus-summary-mark-article-as-read gnus-low-score-mark))
2793 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2794 ;; This article was previously marked as read on account
2795 ;; of a low score, but now it has risen, so we mark it as
2796 ;; unread.
2797 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2798 (gnus-summary-update-mark
2799 (if (or (null gnus-summary-default-score)
2800 (<= (abs (- score gnus-summary-default-score))
2801 gnus-summary-zcore-fuzz))
16409b0b 2802 ? ;Whitespace
eec82323
LMI
2803 (if (< score gnus-summary-default-score)
2804 gnus-score-below-mark gnus-score-over-mark))
2805 'score))
2806 ;; Do visual highlighting.
2807 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 2808 (gnus-run-hooks 'gnus-summary-update-hook)))))
eec82323
LMI
2809
2810(defvar gnus-tmp-new-adopts nil)
2811
2812(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2813 "Return the number of articles in THREAD.
2814This may be 0 in some cases -- if none of the articles in
2815the thread are to be displayed."
2816 (let* ((number
2817 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2818 (cond
2819 ((not (listp thread))
2820 1)
2821 ((and (consp thread) (cdr thread))
2822 (apply
2823 '+ 1 (mapcar
2824 'gnus-summary-number-of-articles-in-thread (cdr thread))))
2825 ((null thread)
2826 1)
2827 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2828 1)
2829 (t 0))))
2830 (when (and level (zerop level) gnus-tmp-new-adopts)
2831 (incf number
2832 (apply '+ (mapcar
2833 'gnus-summary-number-of-articles-in-thread
2834 gnus-tmp-new-adopts))))
2835 (if char
2836 (if (> number 1) gnus-not-empty-thread-mark
2837 gnus-empty-thread-mark)
2838 number)))
2839
2840(defun gnus-summary-set-local-parameters (group)
2841 "Go through the local params of GROUP and set all variable specs in that list."
2842 (let ((params (gnus-group-find-parameter group))
2843 elem)
2844 (while params
2845 (setq elem (car params)
2846 params (cdr params))
2847 (and (consp elem) ; Has to be a cons.
2848 (consp (cdr elem)) ; The cdr has to be a list.
2849 (symbolp (car elem)) ; Has to be a symbol in there.
6748645f 2850 (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
eec82323
LMI
2851 (ignore-errors ; So we set it.
2852 (make-local-variable (car elem))
2853 (set (car elem) (eval (nth 1 elem))))))))
2854
2855(defun gnus-summary-read-group (group &optional show-all no-article
6748645f
LMI
2856 kill-buffer no-display backward
2857 select-articles)
eec82323
LMI
2858 "Start reading news in newsgroup GROUP.
2859If SHOW-ALL is non-nil, already read articles are also listed.
2860If NO-ARTICLE is non-nil, no article is selected initially.
2861If NO-DISPLAY, don't generate a summary buffer."
2862 (let (result)
2863 (while (and group
2864 (null (setq result
2865 (let ((gnus-auto-select-next nil))
6748645f
LMI
2866 (or (gnus-summary-read-group-1
2867 group show-all no-article
2868 kill-buffer no-display
2869 select-articles)
2870 (setq show-all nil
16409b0b 2871 select-articles nil)))))
eec82323
LMI
2872 (eq gnus-auto-select-next 'quietly))
2873 (set-buffer gnus-group-buffer)
6748645f
LMI
2874 ;; The entry function called above goes to the next
2875 ;; group automatically, so we go two groups back
2876 ;; if we are searching for the previous group.
2877 (when backward
2878 (gnus-group-prev-unread-group 2))
eec82323
LMI
2879 (if (not (equal group (gnus-group-group-name)))
2880 (setq group (gnus-group-group-name))
2881 (setq group nil)))
2882 result))
2883
2884(defun gnus-summary-read-group-1 (group show-all no-article
6748645f
LMI
2885 kill-buffer no-display
2886 &optional select-articles)
eec82323
LMI
2887 ;; Killed foreign groups can't be entered.
2888 (when (and (not (gnus-group-native-p group))
2889 (not (gnus-gethash group gnus-newsrc-hashtb)))
2890 (error "Dead non-native groups can't be entered"))
2891 (gnus-message 5 "Retrieving newsgroup: %s..." group)
2892 (let* ((new-group (gnus-summary-setup-buffer group))
2893 (quit-config (gnus-group-quit-config group))
6748645f
LMI
2894 (did-select (and new-group (gnus-select-newsgroup
2895 group show-all select-articles))))
eec82323
LMI
2896 (cond
2897 ;; This summary buffer exists already, so we just select it.
2898 ((not new-group)
2899 (gnus-set-global-variables)
2900 (when kill-buffer
2901 (gnus-kill-or-deaden-summary kill-buffer))
2902 (gnus-configure-windows 'summary 'force)
2903 (gnus-set-mode-line 'summary)
2904 (gnus-summary-position-point)
2905 (message "")
2906 t)
2907 ;; We couldn't select this group.
2908 ((null did-select)
2909 (when (and (eq major-mode 'gnus-summary-mode)
2910 (not (equal (current-buffer) kill-buffer)))
2911 (kill-buffer (current-buffer))
2912 (if (not quit-config)
2913 (progn
6748645f
LMI
2914 ;; Update the info -- marks might need to be removed,
2915 ;; for instance.
2916 (gnus-summary-update-info)
eec82323
LMI
2917 (set-buffer gnus-group-buffer)
2918 (gnus-group-jump-to-group group)
2919 (gnus-group-next-unread-group 1))
2920 (gnus-handle-ephemeral-exit quit-config)))
2921 (gnus-message 3 "Can't select group")
2922 nil)
2923 ;; The user did a `C-g' while prompting for number of articles,
2924 ;; so we exit this group.
2925 ((eq did-select 'quit)
2926 (and (eq major-mode 'gnus-summary-mode)
2927 (not (equal (current-buffer) kill-buffer))
2928 (kill-buffer (current-buffer)))
2929 (when kill-buffer
2930 (gnus-kill-or-deaden-summary kill-buffer))
2931 (if (not quit-config)
2932 (progn
2933 (set-buffer gnus-group-buffer)
2934 (gnus-group-jump-to-group group)
2935 (gnus-group-next-unread-group 1)
2936 (gnus-configure-windows 'group 'force))
2937 (gnus-handle-ephemeral-exit quit-config))
2938 ;; Finally signal the quit.
2939 (signal 'quit nil))
2940 ;; The group was successfully selected.
2941 (t
2942 (gnus-set-global-variables)
2943 ;; Save the active value in effect when the group was entered.
2944 (setq gnus-newsgroup-active
2945 (gnus-copy-sequence
2946 (gnus-active gnus-newsgroup-name)))
2947 ;; You can change the summary buffer in some way with this hook.
6748645f 2948 (gnus-run-hooks 'gnus-select-group-hook)
eec82323
LMI
2949 ;; Set any local variables in the group parameters.
2950 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2951 (gnus-update-format-specifications
2952 nil 'summary 'summary-mode 'summary-dummy)
16409b0b 2953 (gnus-update-summary-mark-positions)
eec82323
LMI
2954 ;; Do score processing.
2955 (when gnus-use-scoring
2956 (gnus-possibly-score-headers))
2957 ;; Check whether to fill in the gaps in the threads.
2958 (when gnus-build-sparse-threads
2959 (gnus-build-sparse-threads))
2960 ;; Find the initial limit.
2961 (if gnus-show-threads
2962 (if show-all
2963 (let ((gnus-newsgroup-dormant nil))
2964 (gnus-summary-initial-limit show-all))
2965 (gnus-summary-initial-limit show-all))
16409b0b 2966 ;; When untreaded, all articles are always shown.
eec82323
LMI
2967 (setq gnus-newsgroup-limit
2968 (mapcar
2969 (lambda (header) (mail-header-number header))
2970 gnus-newsgroup-headers)))
2971 ;; Generate the summary buffer.
2972 (unless no-display
2973 (gnus-summary-prepare))
2974 (when gnus-use-trees
2975 (gnus-tree-open group)
2976 (setq gnus-summary-highlight-line-function
2977 'gnus-tree-highlight-article))
2978 ;; If the summary buffer is empty, but there are some low-scored
2979 ;; articles or some excluded dormants, we include these in the
2980 ;; buffer.
2981 (when (and (zerop (buffer-size))
2982 (not no-display))
2983 (cond (gnus-newsgroup-dormant
2984 (gnus-summary-limit-include-dormant))
2985 ((and gnus-newsgroup-scored show-all)
2986 (gnus-summary-limit-include-expunged t))))
2987 ;; Function `gnus-apply-kill-file' must be called in this hook.
6748645f 2988 (gnus-run-hooks 'gnus-apply-kill-hook)
eec82323
LMI
2989 (if (and (zerop (buffer-size))
2990 (not no-display))
2991 (progn
2992 ;; This newsgroup is empty.
2993 (gnus-summary-catchup-and-exit nil t)
2994 (gnus-message 6 "No unread news")
2995 (when kill-buffer
2996 (gnus-kill-or-deaden-summary kill-buffer))
2997 ;; Return nil from this function.
2998 nil)
2999 ;; Hide conversation thread subtrees. We cannot do this in
3000 ;; gnus-summary-prepare-hook since kill processing may not
3001 ;; work with hidden articles.
3002 (and gnus-show-threads
3003 gnus-thread-hide-subtree
3004 (gnus-summary-hide-all-threads))
6748645f
LMI
3005 (when kill-buffer
3006 (gnus-kill-or-deaden-summary kill-buffer))
eec82323
LMI
3007 ;; Show first unread article if requested.
3008 (if (and (not no-article)
3009 (not no-display)
3010 gnus-newsgroup-unreads
3011 gnus-auto-select-first)
16409b0b
GM
3012 (progn
3013 (gnus-configure-windows 'summary)
3014 (cond
3015 ((eq gnus-auto-select-first 'best)
3016 (gnus-summary-best-unread-article))
3017 ((eq gnus-auto-select-first t)
3018 (gnus-summary-first-unread-article))
3019 ((gnus-functionp gnus-auto-select-first)
3020 (funcall gnus-auto-select-first))))
eec82323
LMI
3021 ;; Don't select any articles, just move point to the first
3022 ;; article in the group.
3023 (goto-char (point-min))
3024 (gnus-summary-position-point)
6748645f
LMI
3025 (gnus-configure-windows 'summary 'force)
3026 (gnus-set-mode-line 'summary))
eec82323
LMI
3027 (when (get-buffer-window gnus-group-buffer t)
3028 ;; Gotta use windows, because recenter does weird stuff if
3029 ;; the current buffer ain't the displayed window.
3030 (let ((owin (selected-window)))
3031 (select-window (get-buffer-window gnus-group-buffer t))
3032 (when (gnus-group-goto-group group)
3033 (recenter))
3034 (select-window owin)))
3035 ;; Mark this buffer as "prepared".
3036 (setq gnus-newsgroup-prepared t)
6748645f 3037 (gnus-run-hooks 'gnus-summary-prepared-hook)
eec82323
LMI
3038 t)))))
3039
3040(defun gnus-summary-prepare ()
3041 "Generate the summary buffer."
3042 (interactive)
3043 (let ((buffer-read-only nil))
3044 (erase-buffer)
3045 (setq gnus-newsgroup-data nil
3046 gnus-newsgroup-data-reverse nil)
6748645f 3047 (gnus-run-hooks 'gnus-summary-generate-hook)
eec82323
LMI
3048 ;; Generate the buffer, either with threads or without.
3049 (when gnus-newsgroup-headers
3050 (gnus-summary-prepare-threads
3051 (if gnus-show-threads
3052 (gnus-sort-gathered-threads
3053 (funcall gnus-summary-thread-gathering-function
3054 (gnus-sort-threads
3055 (gnus-cut-threads (gnus-make-threads)))))
3056 ;; Unthreaded display.
3057 (gnus-sort-articles gnus-newsgroup-headers))))
3058 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3059 ;; Call hooks for modifying summary buffer.
3060 (goto-char (point-min))
6748645f 3061 (gnus-run-hooks 'gnus-summary-prepare-hook)))
eec82323
LMI
3062
3063(defsubst gnus-general-simplify-subject (subject)
3064 "Simply subject by the same rules as gnus-gather-threads-by-subject."
3065 (setq subject
3066 (cond
3067 ;; Truncate the subject.
6748645f
LMI
3068 (gnus-simplify-subject-functions
3069 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
3070 ((numberp gnus-summary-gather-subject-limit)
3071 (setq subject (gnus-simplify-subject-re subject))
3072 (if (> (length subject) gnus-summary-gather-subject-limit)
3073 (substring subject 0 gnus-summary-gather-subject-limit)
3074 subject))
3075 ;; Fuzzily simplify it.
3076 ((eq 'fuzzy gnus-summary-gather-subject-limit)
3077 (gnus-simplify-subject-fuzzy subject))
3078 ;; Just remove the leading "Re:".
3079 (t
3080 (gnus-simplify-subject-re subject))))
3081
3082 (if (and gnus-summary-gather-exclude-subject
3083 (string-match gnus-summary-gather-exclude-subject subject))
3084 nil ; This article shouldn't be gathered
3085 subject))
3086
3087(defun gnus-summary-simplify-subject-query ()
3088 "Query where the respool algorithm would put this article."
3089 (interactive)
eec82323
LMI
3090 (gnus-summary-select-article)
3091 (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3092
3093(defun gnus-gather-threads-by-subject (threads)
3094 "Gather threads by looking at Subject headers."
3095 (if (not gnus-summary-make-false-root)
3096 threads
3097 (let ((hashtb (gnus-make-hashtable 1024))
3098 (prev threads)
3099 (result threads)
3100 subject hthread whole-subject)
3101 (while threads
3102 (setq subject (gnus-general-simplify-subject
3103 (setq whole-subject (mail-header-subject
3104 (caar threads)))))
3105 (when subject
3106 (if (setq hthread (gnus-gethash subject hashtb))
3107 (progn
3108 ;; We enter a dummy root into the thread, if we
3109 ;; haven't done that already.
3110 (unless (stringp (caar hthread))
3111 (setcar hthread (list whole-subject (car hthread))))
3112 ;; We add this new gathered thread to this gathered
3113 ;; thread.
3114 (setcdr (car hthread)
3115 (nconc (cdar hthread) (list (car threads))))
3116 ;; Remove it from the list of threads.
3117 (setcdr prev (cdr threads))
3118 (setq threads prev))
3119 ;; Enter this thread into the hash table.
3120 (gnus-sethash subject threads hashtb)))
3121 (setq prev threads)
3122 (setq threads (cdr threads)))
3123 result)))
3124
3125(defun gnus-gather-threads-by-references (threads)
3126 "Gather threads by looking at References headers."
3127 (let ((idhashtb (gnus-make-hashtable 1024))
3128 (thhashtb (gnus-make-hashtable 1024))
3129 (prev threads)
3130 (result threads)
3131 ids references id gthread gid entered ref)
3132 (while threads
3133 (when (setq references (mail-header-references (caar threads)))
3134 (setq id (mail-header-id (caar threads))
3135 ids (gnus-split-references references)
3136 entered nil)
3137 (while (setq ref (pop ids))
3138 (setq ids (delete ref ids))
3139 (if (not (setq gid (gnus-gethash ref idhashtb)))
3140 (progn
3141 (gnus-sethash ref id idhashtb)
3142 (gnus-sethash id threads thhashtb))
3143 (setq gthread (gnus-gethash gid thhashtb))
3144 (unless entered
3145 ;; We enter a dummy root into the thread, if we
3146 ;; haven't done that already.
3147 (unless (stringp (caar gthread))
3148 (setcar gthread (list (mail-header-subject (caar gthread))
3149 (car gthread))))
3150 ;; We add this new gathered thread to this gathered
3151 ;; thread.
3152 (setcdr (car gthread)
3153 (nconc (cdar gthread) (list (car threads)))))
3154 ;; Add it into the thread hash table.
3155 (gnus-sethash id gthread thhashtb)
3156 (setq entered t)
3157 ;; Remove it from the list of threads.
3158 (setcdr prev (cdr threads))
3159 (setq threads prev))))
3160 (setq prev threads)
3161 (setq threads (cdr threads)))
3162 result))
3163
3164(defun gnus-sort-gathered-threads (threads)
16409b0b 3165 "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
eec82323
LMI
3166 (let ((result threads))
3167 (while threads
3168 (when (stringp (caar threads))
3169 (setcdr (car threads)
16409b0b 3170 (sort (cdar threads) gnus-sort-gathered-threads-function)))
eec82323
LMI
3171 (setq threads (cdr threads)))
3172 result))
3173
3174(defun gnus-thread-loop-p (root thread)
3175 "Say whether ROOT is in THREAD."
3176 (let ((stack (list thread))
3177 (infloop 0)
3178 th)
3179 (while (setq thread (pop stack))
3180 (setq th (cdr thread))
3181 (while (and th
3182 (not (eq (caar th) root)))
3183 (pop th))
3184 (if th
3185 ;; We have found a loop.
3186 (let (ref-dep)
3187 (setcdr thread (delq (car th) (cdr thread)))
3188 (if (boundp (setq ref-dep (intern "none"
3189 gnus-newsgroup-dependencies)))
3190 (setcdr (symbol-value ref-dep)
3191 (nconc (cdr (symbol-value ref-dep))
3192 (list (car th))))
3193 (set ref-dep (list nil (car th))))
3194 (setq infloop 1
3195 stack nil))
3196 ;; Push all the subthreads onto the stack.
3197 (push (cdr thread) stack)))
3198 infloop))
3199
3200(defun gnus-make-threads ()
3201 "Go through the dependency hashtb and find the roots. Return all threads."
3202 (let (threads)
3203 (while (catch 'infloop
3204 (mapatoms
3205 (lambda (refs)
3206 ;; Deal with self-referencing References loops.
3207 (when (and (car (symbol-value refs))
3208 (not (zerop
3209 (apply
3210 '+
3211 (mapcar
3212 (lambda (thread)
3213 (gnus-thread-loop-p
3214 (car (symbol-value refs)) thread))
3215 (cdr (symbol-value refs)))))))
3216 (setq threads nil)
3217 (throw 'infloop t))
3218 (unless (car (symbol-value refs))
3219 ;; These threads do not refer back to any other articles,
3220 ;; so they're roots.
3221 (setq threads (append (cdr (symbol-value refs)) threads))))
3222 gnus-newsgroup-dependencies)))
3223 threads))
3224
6748645f 3225;; Build the thread tree.
16409b0b 3226(defsubst gnus-dependencies-add-header (header dependencies force-new)
6748645f
LMI
3227 "Enter HEADER into the DEPENDENCIES table if it is not already there.
3228
3229If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3230if it was already present.
3231
3232If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3233will not be entered in the DEPENDENCIES table. Otherwise duplicate
3234Message-IDs will be renamed be renamed to a unique Message-ID before
3235being entered.
3236
3237Returns HEADER if it was entered in the DEPENDENCIES. Returns nil otherwise."
3238 (let* ((id (mail-header-id header))
3239 (id-dep (and id (intern id dependencies)))
3240 ref ref-dep ref-header)
3241 ;; Enter this `header' in the `dependencies' table.
3242 (cond
3243 ((not id-dep)
3244 (setq header nil))
3245 ;; The first two cases do the normal part: enter a new `header'
3246 ;; in the `dependencies' table.
3247 ((not (boundp id-dep))
3248 (set id-dep (list header)))
3249 ((null (car (symbol-value id-dep)))
3250 (setcar (symbol-value id-dep) header))
3251
3252 ;; From here the `header' was already present in the
3253 ;; `dependencies' table.
3254 (force-new
3255 ;; Overrides an existing entry;
3256 ;; just set the header part of the entry.
3257 (setcar (symbol-value id-dep) header))
3258
3259 ;; Renames the existing `header' to a unique Message-ID.
3260 ((not gnus-summary-ignore-duplicates)
3261 ;; An article with this Message-ID has already been seen.
3262 ;; We rename the Message-ID.
3263 (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3264 (list header))
3265 (mail-header-set-id header id))
3266
3267 ;; The last case ignores an existing entry, except it adds any
3268 ;; additional Xrefs (in case the two articles came from different
3269 ;; servers.
3270 ;; Also sets `header' to `nil' meaning that the `dependencies'
3271 ;; table was *not* modified.
3272 (t
3273 (mail-header-set-xref
3274 (car (symbol-value id-dep))
3275 (concat (or (mail-header-xref (car (symbol-value id-dep)))
3276 "")
3277 (or (mail-header-xref header) "")))
3278 (setq header nil)))
3279
3280 (when header
3281 ;; First check if that we are not creating a References loop.
3282 (setq ref (gnus-parent-id (mail-header-references header)))
3283 (while (and ref
3284 (setq ref-dep (intern-soft ref dependencies))
3285 (boundp ref-dep)
3286 (setq ref-header (car (symbol-value ref-dep))))
3287 (if (string= id ref)
3288 ;; Yuk! This is a reference loop. Make the article be a
3289 ;; root article.
3290 (progn
3291 (mail-header-set-references (car (symbol-value id-dep)) "none")
3292 (setq ref nil))
3293 (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3294 (setq ref (gnus-parent-id (mail-header-references header)))
3295 (setq ref-dep (intern (or ref "none") dependencies))
3296 (if (boundp ref-dep)
3297 (setcdr (symbol-value ref-dep)
3298 (nconc (cdr (symbol-value ref-dep))
3299 (list (symbol-value id-dep))))
3300 (set ref-dep (list nil (symbol-value id-dep)))))
3301 header))
3302
eec82323
LMI
3303(defun gnus-build-sparse-threads ()
3304 (let ((headers gnus-newsgroup-headers)
16409b0b 3305 (mail-parse-charset gnus-newsgroup-charset)
6748645f 3306 (gnus-summary-ignore-duplicates t)
eec82323 3307 header references generation relations
6748645f 3308 subject child end new-child date)
eec82323
LMI
3309 ;; First we create an alist of generations/relations, where
3310 ;; generations is how much we trust the relation, and the relation
3311 ;; is parent/child.
3312 (gnus-message 7 "Making sparse threads...")
3313 (save-excursion
3314 (nnheader-set-temp-buffer " *gnus sparse threads*")
3315 (while (setq header (pop headers))
3316 (when (and (setq references (mail-header-references header))
3317 (not (string= references "")))
3318 (insert references)
3319 (setq child (mail-header-id header)
6748645f
LMI
3320 subject (mail-header-subject header)
3321 date (mail-header-date header)
3322 generation 0)
eec82323
LMI
3323 (while (search-backward ">" nil t)
3324 (setq end (1+ (point)))
3325 (when (search-backward "<" nil t)
6748645f 3326 (setq new-child (buffer-substring (point) end))
eec82323 3327 (push (list (incf generation)
6748645f
LMI
3328 child (setq child new-child)
3329 subject date)
eec82323 3330 relations)))
6748645f
LMI
3331 (when child
3332 (push (list (1+ generation) child nil subject) relations))
eec82323
LMI
3333 (erase-buffer)))
3334 (kill-buffer (current-buffer)))
3335 ;; Sort over trustworthiness.
6748645f
LMI
3336 (mapcar
3337 (lambda (relation)
3338 (when (gnus-dependencies-add-header
3339 (make-full-mail-header
3340 gnus-reffed-article-number
3341 (nth 3 relation) "" (or (nth 4 relation) "")
3342 (nth 1 relation)
3343 (or (nth 2 relation) "") 0 0 "")
3344 gnus-newsgroup-dependencies nil)
3345 (push gnus-reffed-article-number gnus-newsgroup-limit)
3346 (push gnus-reffed-article-number gnus-newsgroup-sparse)
3347 (push (cons gnus-reffed-article-number gnus-sparse-mark)
3348 gnus-newsgroup-reads)
3349 (decf gnus-reffed-article-number)))
3350 (sort relations 'car-less-than-car))
eec82323
LMI
3351 (gnus-message 7 "Making sparse threads...done")))
3352
3353(defun gnus-build-old-threads ()
3354 ;; Look at all the articles that refer back to old articles, and
3355 ;; fetch the headers for the articles that aren't there. This will
3356 ;; build complete threads - if the roots haven't been expired by the
3357 ;; server, that is.
16409b0b
GM
3358 (let ((mail-parse-charset gnus-newsgroup-charset)
3359 id heads)
eec82323
LMI
3360 (mapatoms
3361 (lambda (refs)
3362 (when (not (car (symbol-value refs)))
3363 (setq heads (cdr (symbol-value refs)))
3364 (while heads
3365 (if (memq (mail-header-number (caar heads))
3366 gnus-newsgroup-dormant)
3367 (setq heads (cdr heads))
3368 (setq id (symbol-name refs))
3369 (while (and (setq id (gnus-build-get-header id))
6748645f 3370 (not (car (gnus-id-to-thread id)))))
eec82323
LMI
3371 (setq heads nil)))))
3372 gnus-newsgroup-dependencies)))
3373
6748645f
LMI
3374;; This function has to be called with point after the article number
3375;; on the beginning of the line.
3376(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3377 (let ((eol (gnus-point-at-eol))
3378 (buffer (current-buffer))
3379 header)
3380
3381 ;; overview: [num subject from date id refs chars lines misc]
3382 (unwind-protect
3383 (progn
3384 (narrow-to-region (point) eol)
3385 (unless (eobp)
3386 (forward-char))
3387
3388 (setq header
3389 (make-full-mail-header
3390 number ; number
16409b0b
GM
3391 (funcall gnus-decode-encoded-word-function
3392 (nnheader-nov-field)) ; subject
3393 (funcall gnus-decode-encoded-word-function
3394 (nnheader-nov-field)) ; from
3395 (nnheader-nov-field) ; date
3396 (nnheader-nov-read-message-id) ; id
3397 (nnheader-nov-field) ; refs
3398 (nnheader-nov-read-integer) ; chars
3399 (nnheader-nov-read-integer) ; lines
3400 (unless (eobp)
8b93df01
DL
3401 (if (looking-at "Xref: ")
3402 (goto-char (match-end 0)))
3403 (nnheader-nov-field)) ; Xref
16409b0b 3404 (nnheader-nov-parse-extra)))) ; extra
6748645f
LMI
3405
3406 (widen))
3407
3408 (when gnus-alter-header-function
3409 (funcall gnus-alter-header-function header))
3410 (gnus-dependencies-add-header header dependencies force-new)))
3411
eec82323 3412(defun gnus-build-get-header (id)
16409b0b
GM
3413 "Look through the buffer of NOV lines and find the header to ID.
3414Enter this line into the dependencies hash table, and return
3415the id of the parent article (if any)."
eec82323
LMI
3416 (let ((deps gnus-newsgroup-dependencies)
3417 found header)
3418 (prog1
3419 (save-excursion
3420 (set-buffer nntp-server-buffer)
3421 (let ((case-fold-search nil))
3422 (goto-char (point-min))
3423 (while (and (not found)
3424 (search-forward id nil t))
3425 (beginning-of-line)
3426 (setq found (looking-at
3427 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3428 (regexp-quote id))))
3429 (or found (beginning-of-line 2)))
3430 (when found
3431 (beginning-of-line)
3432 (and
3433 (setq header (gnus-nov-parse-line
3434 (read (current-buffer)) deps))
3435 (gnus-parent-id (mail-header-references header))))))
3436 (when header
3437 (let ((number (mail-header-number header)))
3438 (push number gnus-newsgroup-limit)
3439 (push header gnus-newsgroup-headers)
3440 (if (memq number gnus-newsgroup-unselected)
3441 (progn
3442 (push number gnus-newsgroup-unreads)
3443 (setq gnus-newsgroup-unselected
3444 (delq number gnus-newsgroup-unselected)))
3445 (push number gnus-newsgroup-ancient)))))))
3446
6748645f
LMI
3447(defun gnus-build-all-threads ()
3448 "Read all the headers."
3449 (let ((gnus-summary-ignore-duplicates t)
16409b0b 3450 (mail-parse-charset gnus-newsgroup-charset)
6748645f
LMI
3451 (dependencies gnus-newsgroup-dependencies)
3452 header article)
3453 (save-excursion
3454 (set-buffer nntp-server-buffer)
3455 (let ((case-fold-search nil))
3456 (goto-char (point-min))
3457 (while (not (eobp))
3458 (ignore-errors
3459 (setq article (read (current-buffer))
16409b0b 3460 header (gnus-nov-parse-line article dependencies)))
6748645f
LMI
3461 (when header
3462 (save-excursion
3463 (set-buffer gnus-summary-buffer)
3464 (push header gnus-newsgroup-headers)
3465 (if (memq (setq article (mail-header-number header))
3466 gnus-newsgroup-unselected)
3467 (progn
3468 (push article gnus-newsgroup-unreads)
3469 (setq gnus-newsgroup-unselected
3470 (delq article gnus-newsgroup-unselected)))
3471 (push article gnus-newsgroup-ancient)))
3472 (forward-line 1)))))))
3473
eec82323
LMI
3474(defun gnus-summary-update-article-line (article header)
3475 "Update the line for ARTICLE using HEADERS."
3476 (let* ((id (mail-header-id header))
3477 (thread (gnus-id-to-thread id)))
3478 (unless thread
3479 (error "Article in no thread"))
3480 ;; Update the thread.
3481 (setcar thread header)
3482 (gnus-summary-goto-subject article)
3483 (let* ((datal (gnus-data-find-list article))
3484 (data (car datal))
3485 (length (when (cdr datal)
3486 (- (gnus-data-pos data)
3487 (gnus-data-pos (cadr datal)))))
3488 (buffer-read-only nil)
3489 (level (gnus-summary-thread-level)))
3490 (gnus-delete-line)
3491 (gnus-summary-insert-line
3492 header level nil (gnus-article-mark article)
3493 (memq article gnus-newsgroup-replied)
3494 (memq article gnus-newsgroup-expirable)
3495 ;; Only insert the Subject string when it's different
3496 ;; from the previous Subject string.
16409b0b
GM
3497 (if (and
3498 gnus-show-threads
3499 (gnus-subject-equal
3500 (condition-case ()
3501 (mail-header-subject
3502 (gnus-data-header
3503 (cadr
3504 (gnus-data-find-list
3505 article
3506 (gnus-data-list t)))))
3507 ;; Error on the side of excessive subjects.
3508 (error ""))
3509 (mail-header-subject header)))
eec82323
LMI
3510 ""
3511 (mail-header-subject header))
3512 nil (cdr (assq article gnus-newsgroup-scored))
3513 (memq article gnus-newsgroup-processable))
3514 (when length
3515 (gnus-data-update-list
3516 (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3517
3518(defun gnus-summary-update-article (article &optional iheader)
3519 "Update ARTICLE in the summary buffer."
3520 (set-buffer gnus-summary-buffer)
6748645f 3521 (let* ((header (gnus-summary-article-header article))
eec82323
LMI
3522 (id (mail-header-id header))
3523 (data (gnus-data-find article))
3524 (thread (gnus-id-to-thread id))
3525 (references (mail-header-references header))
3526 (parent
3527 (gnus-id-to-thread
3528 (or (gnus-parent-id
3529 (when (and references
3530 (not (equal "" references)))
3531 references))
3532 "none")))
3533 (buffer-read-only nil)
6748645f 3534 (old (car thread)))
eec82323 3535 (when thread
eec82323 3536 (unless iheader
6748645f
LMI
3537 (setcar thread nil)
3538 (when parent
3539 (delq thread parent)))
3540 (if (gnus-summary-insert-subject id header)
eec82323
LMI
3541 ;; Set the (possibly) new article number in the data structure.
3542 (gnus-data-set-number data (gnus-id-to-article id))
3543 (setcar thread old)
3544 nil))))
3545
6748645f
LMI
3546(defun gnus-rebuild-thread (id &optional line)
3547 "Rebuild the thread containing ID.
3548If LINE, insert the rebuilt thread starting on line LINE."
eec82323
LMI
3549 (let ((buffer-read-only nil)
3550 old-pos current thread data)
3551 (if (not gnus-show-threads)
3552 (setq thread (list (car (gnus-id-to-thread id))))
3553 ;; Get the thread this article is part of.
3554 (setq thread (gnus-remove-thread id)))
3555 (setq old-pos (gnus-point-at-bol))
3556 (setq current (save-excursion
94384150 3557 (and (re-search-backward "[\r\n]" nil t)
eec82323
LMI
3558 (gnus-summary-article-number))))
3559 ;; If this is a gathered thread, we have to go some re-gathering.
3560 (when (stringp (car thread))
3561 (let ((subject (car thread))
3562 roots thr)
3563 (setq thread (cdr thread))
3564 (while thread
3565 (unless (memq (setq thr (gnus-id-to-thread
3566 (gnus-root-id
3567 (mail-header-id (caar thread)))))
3568 roots)
3569 (push thr roots))
3570 (setq thread (cdr thread)))
3571 ;; We now have all (unique) roots.
3572 (if (= (length roots) 1)
3573 ;; All the loose roots are now one solid root.
3574 (setq thread (car roots))
3575 (setq thread (cons subject (gnus-sort-threads roots))))))
3576 (let (threads)
3577 ;; We then insert this thread into the summary buffer.
6748645f
LMI
3578 (when line
3579 (goto-char (point-min))
3580 (forward-line (1- line)))
eec82323
LMI
3581 (let (gnus-newsgroup-data gnus-newsgroup-threads)
3582 (if gnus-show-threads
3583 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3584 (gnus-summary-prepare-unthreaded thread))
3585 (setq data (nreverse gnus-newsgroup-data))
3586 (setq threads gnus-newsgroup-threads))
3587 ;; We splice the new data into the data structure.
6748645f
LMI
3588 ;;!!! This is kinda bogus. We assume that in LINE is non-nil,
3589 ;;!!! then we want to insert at the beginning of the buffer.
3590 ;;!!! That happens to be true with Gnus now, but that may
3591 ;;!!! change in the future. Perhaps.
3592 (gnus-data-enter-list
3593 (if line nil current) data (- (point) old-pos))
3594 (setq gnus-newsgroup-threads
3595 (nconc threads gnus-newsgroup-threads))
3596 (gnus-data-compute-positions))))
eec82323
LMI
3597
3598(defun gnus-number-to-header (number)
3599 "Return the header for article NUMBER."
3600 (let ((headers gnus-newsgroup-headers))
3601 (while (and headers
3602 (not (= number (mail-header-number (car headers)))))
3603 (pop headers))
3604 (when headers
3605 (car headers))))
3606
6748645f 3607(defun gnus-parent-headers (in-headers &optional generation)
eec82323
LMI
3608 "Return the headers of the GENERATIONeth parent of HEADERS."
3609 (unless generation
3610 (setq generation 1))
a8151ef7 3611 (let ((parent t)
6748645f 3612 (headers in-headers)
a8151ef7 3613 references)
6748645f
LMI
3614 (while (and parent
3615 (not (zerop generation))
3616 (setq references (mail-header-references headers)))
3617 (setq headers (if (and references
3618 (setq parent (gnus-parent-id references)))
3619 (car (gnus-id-to-thread parent))
3620 nil))
3621 (decf generation))
3622 (and (not (eq headers in-headers))
3623 headers)))
eec82323
LMI
3624
3625(defun gnus-id-to-thread (id)
3626 "Return the (sub-)thread where ID appears."
3627 (gnus-gethash id gnus-newsgroup-dependencies))
3628
3629(defun gnus-id-to-article (id)
3630 "Return the article number of ID."
3631 (let ((thread (gnus-id-to-thread id)))
3632 (when (and thread
3633 (car thread))
3634 (mail-header-number (car thread)))))
3635
3636(defun gnus-id-to-header (id)
3637 "Return the article headers of ID."
3638 (car (gnus-id-to-thread id)))
3639
3640(defun gnus-article-displayed-root-p (article)
3641 "Say whether ARTICLE is a root(ish) article."
3642 (let ((level (gnus-summary-thread-level article))
3643 (refs (mail-header-references (gnus-summary-article-header article)))
3644 particle)
3645 (cond
3646 ((null level) nil)
3647 ((zerop level) t)
3648 ((null refs) t)
3649 ((null (gnus-parent-id refs)) t)
3650 ((and (= 1 level)
3651 (null (setq particle (gnus-id-to-article
3652 (gnus-parent-id refs))))
3653 (null (gnus-summary-thread-level particle)))))))
3654
3655(defun gnus-root-id (id)
3656 "Return the id of the root of the thread where ID appears."
3657 (let (last-id prev)
6748645f 3658 (while (and id (setq prev (car (gnus-id-to-thread id))))
eec82323
LMI
3659 (setq last-id id
3660 id (gnus-parent-id (mail-header-references prev))))
3661 last-id))
3662
6748645f
LMI
3663(defun gnus-articles-in-thread (thread)
3664 "Return the list of articles in THREAD."
3665 (cons (mail-header-number (car thread))
3666 (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3667
eec82323
LMI
3668(defun gnus-remove-thread (id &optional dont-remove)
3669 "Remove the thread that has ID in it."
6748645f 3670 (let (headers thread last-id)
eec82323 3671 ;; First go up in this thread until we find the root.
6748645f
LMI
3672 (setq last-id (gnus-root-id id)
3673 headers (message-flatten-list (gnus-id-to-thread last-id)))
eec82323
LMI
3674 ;; We have now found the real root of this thread. It might have
3675 ;; been gathered into some loose thread, so we have to search
3676 ;; through the threads to find the thread we wanted.
3677 (let ((threads gnus-newsgroup-threads)
3678 sub)
3679 (while threads
3680 (setq sub (car threads))
3681 (if (stringp (car sub))
3682 ;; This is a gathered thread, so we look at the roots
3683 ;; below it to find whether this article is in this
3684 ;; gathered root.
3685 (progn
3686 (setq sub (cdr sub))
3687 (while sub
3688 (when (member (caar sub) headers)
3689 (setq thread (car threads)
3690 threads nil
3691 sub nil))
3692 (setq sub (cdr sub))))
3693 ;; It's an ordinary thread, so we check it.
3694 (when (eq (car sub) (car headers))
3695 (setq thread sub
3696 threads nil)))
3697 (setq threads (cdr threads)))
3698 ;; If this article is in no thread, then it's a root.
3699 (if thread
3700 (unless dont-remove
3701 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
6748645f 3702 (setq thread (gnus-id-to-thread last-id)))
eec82323
LMI
3703 (when thread
3704 (prog1
3705 thread ; We return this thread.
3706 (unless dont-remove
3707 (if (stringp (car thread))
3708 (progn
3709 ;; If we use dummy roots, then we have to remove the
3710 ;; dummy root as well.
3711 (when (eq gnus-summary-make-false-root 'dummy)
6748645f
LMI
3712 ;; We go to the dummy root by going to
3713 ;; the first sub-"thread", and then one line up.
3714 (gnus-summary-goto-article
3715 (mail-header-number (caadr thread)))
3716 (forward-line -1)
eec82323
LMI
3717 (gnus-delete-line)
3718 (gnus-data-compute-positions))
3719 (setq thread (cdr thread))
3720 (while thread
3721 (gnus-remove-thread-1 (car thread))
3722 (setq thread (cdr thread))))
3723 (gnus-remove-thread-1 thread))))))))
3724
3725(defun gnus-remove-thread-1 (thread)
3726 "Remove the thread THREAD recursively."
3727 (let ((number (mail-header-number (pop thread)))
3728 d)
3729 (setq thread (reverse thread))
3730 (while thread
3731 (gnus-remove-thread-1 (pop thread)))
3732 (when (setq d (gnus-data-find number))
3733 (goto-char (gnus-data-pos d))
16409b0b 3734 (gnus-summary-show-thread)
eec82323
LMI
3735 (gnus-data-remove
3736 number
3737 (- (gnus-point-at-bol)
3738 (prog1
3739 (1+ (gnus-point-at-eol))
3740 (gnus-delete-line)))))))
3741
16409b0b
GM
3742(defun gnus-sort-threads-1 (threads func)
3743 (sort (mapcar (lambda (thread)
3744 (cons (car thread)
3745 (and (cdr thread)
3746 (gnus-sort-threads-1 (cdr thread) func))))
3747 threads) func))
3748
eec82323
LMI
3749(defun gnus-sort-threads (threads)
3750 "Sort THREADS."
3751 (if (not gnus-thread-sort-functions)
3752 threads
6748645f 3753 (gnus-message 8 "Sorting threads...")
eec82323 3754 (prog1
16409b0b
GM
3755 (gnus-sort-threads-1
3756 threads
3757 (gnus-make-sort-function gnus-thread-sort-functions))
6748645f 3758 (gnus-message 8 "Sorting threads...done"))))
eec82323
LMI
3759
3760(defun gnus-sort-articles (articles)
3761 "Sort ARTICLES."
3762 (when gnus-article-sort-functions
3763 (gnus-message 7 "Sorting articles...")
3764 (prog1
3765 (setq gnus-newsgroup-headers
3766 (sort articles (gnus-make-sort-function
3767 gnus-article-sort-functions)))
3768 (gnus-message 7 "Sorting articles...done"))))
3769
3770;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3771(defmacro gnus-thread-header (thread)
16409b0b
GM
3772 "Return header of first article in THREAD.
3773Note that THREAD must never, ever be anything else than a variable -
3774using some other form will lead to serious barfage."
eec82323
LMI
3775 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3776 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
16409b0b 3777 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
eec82323
LMI
3778 (vector thread) 2))
3779
3780(defsubst gnus-article-sort-by-number (h1 h2)
3781 "Sort articles by article number."
3782 (< (mail-header-number h1)
3783 (mail-header-number h2)))
3784
3785(defun gnus-thread-sort-by-number (h1 h2)
3786 "Sort threads by root article number."
3787 (gnus-article-sort-by-number
3788 (gnus-thread-header h1) (gnus-thread-header h2)))
3789
3790(defsubst gnus-article-sort-by-lines (h1 h2)
3791 "Sort articles by article Lines header."
3792 (< (mail-header-lines h1)
3793 (mail-header-lines h2)))
3794
3795(defun gnus-thread-sort-by-lines (h1 h2)
3796 "Sort threads by root article Lines header."
3797 (gnus-article-sort-by-lines
3798 (gnus-thread-header h1) (gnus-thread-header h2)))
3799
16409b0b
GM
3800(defsubst gnus-article-sort-by-chars (h1 h2)
3801 "Sort articles by octet length."
3802 (< (mail-header-chars h1)
3803 (mail-header-chars h2)))
3804
3805(defun gnus-thread-sort-by-chars (h1 h2)
3806 "Sort threads by root article octet length."
3807 (gnus-article-sort-by-chars
3808 (gnus-thread-header h1) (gnus-thread-header h2)))
3809
eec82323
LMI
3810(defsubst gnus-article-sort-by-author (h1 h2)
3811 "Sort articles by root author."
3812 (string-lessp
3813 (let ((extract (funcall
3814 gnus-extract-address-components
3815 (mail-header-from h1))))
3816 (or (car extract) (cadr extract) ""))
3817 (let ((extract (funcall
3818 gnus-extract-address-components
3819 (mail-header-from h2))))
3820 (or (car extract) (cadr extract) ""))))
3821
3822(defun gnus-thread-sort-by-author (h1 h2)
3823 "Sort threads by root author."
3824 (gnus-article-sort-by-author
3825 (gnus-thread-header h1) (gnus-thread-header h2)))
3826
3827(defsubst gnus-article-sort-by-subject (h1 h2)
3828 "Sort articles by root subject."
3829 (string-lessp
3830 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3831 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3832
3833(defun gnus-thread-sort-by-subject (h1 h2)
3834 "Sort threads by root subject."
3835 (gnus-article-sort-by-subject
3836 (gnus-thread-header h1) (gnus-thread-header h2)))
3837
3838(defsubst gnus-article-sort-by-date (h1 h2)
3839 "Sort articles by root article date."
16409b0b 3840 (time-less-p
eec82323
LMI
3841 (gnus-date-get-time (mail-header-date h1))
3842 (gnus-date-get-time (mail-header-date h2))))
3843
3844(defun gnus-thread-sort-by-date (h1 h2)
3845 "Sort threads by root article date."
3846 (gnus-article-sort-by-date
3847 (gnus-thread-header h1) (gnus-thread-header h2)))
3848
3849(defsubst gnus-article-sort-by-score (h1 h2)
3850 "Sort articles by root article score.
3851Unscored articles will be counted as having a score of zero."
3852 (> (or (cdr (assq (mail-header-number h1)
3853 gnus-newsgroup-scored))
3854 gnus-summary-default-score 0)
3855 (or (cdr (assq (mail-header-number h2)
3856 gnus-newsgroup-scored))
3857 gnus-summary-default-score 0)))
3858
3859(defun gnus-thread-sort-by-score (h1 h2)
3860 "Sort threads by root article score."
3861 (gnus-article-sort-by-score
3862 (gnus-thread-header h1) (gnus-thread-header h2)))
3863
3864(defun gnus-thread-sort-by-total-score (h1 h2)
3865 "Sort threads by the sum of all scores in the thread.
3866Unscored articles will be counted as having a score of zero."
3867 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3868
3869(defun gnus-thread-total-score (thread)
16409b0b 3870 ;; This function find the total score of THREAD.
eec82323
LMI
3871 (cond ((null thread)
3872 0)
3873 ((consp thread)
3874 (if (stringp (car thread))
3875 (apply gnus-thread-score-function 0
3876 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3877 (gnus-thread-total-score-1 thread)))
3878 (t
3879 (gnus-thread-total-score-1 (list thread)))))
3880
3881(defun gnus-thread-total-score-1 (root)
3882 ;; This function find the total score of the thread below ROOT.
3883 (setq root (car root))
3884 (apply gnus-thread-score-function
3885 (or (append
3886 (mapcar 'gnus-thread-total-score
6748645f 3887 (cdr (gnus-id-to-thread (mail-header-id root))))
eec82323
LMI
3888 (when (> (mail-header-number root) 0)
3889 (list (or (cdr (assq (mail-header-number root)
3890 gnus-newsgroup-scored))
3891 gnus-summary-default-score 0))))
3892 (list gnus-summary-default-score)
3893 '(0))))
3894
3895;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3896(defvar gnus-tmp-prev-subject nil)
3897(defvar gnus-tmp-false-parent nil)
3898(defvar gnus-tmp-root-expunged nil)
3899(defvar gnus-tmp-dummy-line nil)
3900
60bd5589 3901(eval-when-compile (defvar gnus-tmp-header))
16409b0b
GM
3902(defun gnus-extra-header (type &optional header)
3903 "Return the extra header of TYPE."
3904 (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3905 ""))
3906
eec82323
LMI
3907(defun gnus-summary-prepare-threads (threads)
3908 "Prepare summary buffer from THREADS and indentation LEVEL.
3909THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3910or a straight list of headers."
3911 (gnus-message 7 "Generating summary...")
3912
3913 (setq gnus-newsgroup-threads threads)
3914 (beginning-of-line)
3915
3916 (let ((gnus-tmp-level 0)
3917 (default-score (or gnus-summary-default-score 0))
3918 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3919 thread number subject stack state gnus-tmp-gathered beg-match
3920 new-roots gnus-tmp-new-adopts thread-end
3921 gnus-tmp-header gnus-tmp-unread
3922 gnus-tmp-replied gnus-tmp-subject-or-nil
3923 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3924 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3925 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3926
3927 (setq gnus-tmp-prev-subject nil)
3928
3929 (if (vectorp (car threads))
3930 ;; If this is a straight (sic) list of headers, then a
3931 ;; threaded summary display isn't required, so we just create
3932 ;; an unthreaded one.
3933 (gnus-summary-prepare-unthreaded threads)
3934
3935 ;; Do the threaded display.
3936
3937 (while (or threads stack gnus-tmp-new-adopts new-roots)
3938
3939 (if (and (= gnus-tmp-level 0)
eec82323
LMI
3940 (or (not stack)
3941 (= (caar stack) 0))
3942 (not gnus-tmp-false-parent)
3943 (or gnus-tmp-new-adopts new-roots))
3944 (if gnus-tmp-new-adopts
3945 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3946 thread (list (car gnus-tmp-new-adopts))
3947 gnus-tmp-header (caar thread)
3948 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3949 (when new-roots
3950 (setq thread (list (car new-roots))
3951 gnus-tmp-header (caar thread)
3952 new-roots (cdr new-roots))))
3953
3954 (if threads
3955 ;; If there are some threads, we do them before the
3956 ;; threads on the stack.
3957 (setq thread threads
3958 gnus-tmp-header (caar thread))
3959 ;; There were no current threads, so we pop something off
3960 ;; the stack.
3961 (setq state (car stack)
3962 gnus-tmp-level (car state)
3963 thread (cdr state)
3964 stack (cdr stack)
3965 gnus-tmp-header (caar thread))))
3966
3967 (setq gnus-tmp-false-parent nil)
3968 (setq gnus-tmp-root-expunged nil)
3969 (setq thread-end nil)
3970
3971 (if (stringp gnus-tmp-header)
3972 ;; The header is a dummy root.
3973 (cond
3974 ((eq gnus-summary-make-false-root 'adopt)
3975 ;; We let the first article adopt the rest.
3976 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3977 (cddar thread)))
3978 (setq gnus-tmp-gathered
3979 (nconc (mapcar
3980 (lambda (h) (mail-header-number (car h)))
3981 (cddar thread))
3982 gnus-tmp-gathered))
3983 (setq thread (cons (list (caar thread)
3984 (cadar thread))
3985 (cdr thread)))
3986 (setq gnus-tmp-level -1
3987 gnus-tmp-false-parent t))
3988 ((eq gnus-summary-make-false-root 'empty)
3989 ;; We print adopted articles with empty subject fields.
3990 (setq gnus-tmp-gathered
3991 (nconc (mapcar
3992 (lambda (h) (mail-header-number (car h)))
3993 (cddar thread))
3994 gnus-tmp-gathered))
3995 (setq gnus-tmp-level -1))
3996 ((eq gnus-summary-make-false-root 'dummy)
3997 ;; We remember that we probably want to output a dummy
3998 ;; root.
3999 (setq gnus-tmp-dummy-line gnus-tmp-header)
4000 (setq gnus-tmp-prev-subject gnus-tmp-header))
4001 (t
4002 ;; We do not make a root for the gathered
4003 ;; sub-threads at all.
4004 (setq gnus-tmp-level -1)))
4005
4006 (setq number (mail-header-number gnus-tmp-header)
4007 subject (mail-header-subject gnus-tmp-header))
4008
4009 (cond
4010 ;; If the thread has changed subject, we might want to make
4011 ;; this subthread into a root.
4012 ((and (null gnus-thread-ignore-subject)
4013 (not (zerop gnus-tmp-level))
4014 gnus-tmp-prev-subject
4015 (not (inline
4016 (gnus-subject-equal gnus-tmp-prev-subject subject))))
4017 (setq new-roots (nconc new-roots (list (car thread)))
4018 thread-end t
4019 gnus-tmp-header nil))
4020 ;; If the article lies outside the current limit,
4021 ;; then we do not display it.
4022 ((not (memq number gnus-newsgroup-limit))
4023 (setq gnus-tmp-gathered
4024 (nconc (mapcar
4025 (lambda (h) (mail-header-number (car h)))
4026 (cdar thread))
4027 gnus-tmp-gathered))
4028 (setq gnus-tmp-new-adopts (if (cdar thread)
4029 (append gnus-tmp-new-adopts
4030 (cdar thread))
4031 gnus-tmp-new-adopts)
4032 thread-end t
4033 gnus-tmp-header nil)
4034 (when (zerop gnus-tmp-level)
4035 (setq gnus-tmp-root-expunged t)))
4036 ;; Perhaps this article is to be marked as read?
4037 ((and gnus-summary-mark-below
4038 (< (or (cdr (assq number gnus-newsgroup-scored))
4039 default-score)
4040 gnus-summary-mark-below)
4041 ;; Don't touch sparse articles.
4042 (not (gnus-summary-article-sparse-p number))
4043 (not (gnus-summary-article-ancient-p number)))
4044 (setq gnus-newsgroup-unreads
4045 (delq number gnus-newsgroup-unreads))
4046 (if gnus-newsgroup-auto-expire
4047 (push number gnus-newsgroup-expirable)
4048 (push (cons number gnus-low-score-mark)
4049 gnus-newsgroup-reads))))
4050
4051 (when gnus-tmp-header
4052 ;; We may have an old dummy line to output before this
4053 ;; article.
6748645f
LMI
4054 (when (and gnus-tmp-dummy-line
4055 (gnus-subject-equal
4056 gnus-tmp-dummy-line
4057 (mail-header-subject gnus-tmp-header)))
eec82323
LMI
4058 (gnus-summary-insert-dummy-line
4059 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4060 (setq gnus-tmp-dummy-line nil))
4061
4062 ;; Compute the mark.
4063 (setq gnus-tmp-unread (gnus-article-mark number))
4064
4065 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4066 gnus-tmp-header gnus-tmp-level)
4067 gnus-newsgroup-data)
4068
4069 ;; Actually insert the line.
4070 (setq
4071 gnus-tmp-subject-or-nil
4072 (cond
4073 ((and gnus-thread-ignore-subject
4074 gnus-tmp-prev-subject
4075 (not (inline (gnus-subject-equal
4076 gnus-tmp-prev-subject subject))))
4077 subject)
4078 ((zerop gnus-tmp-level)
4079 (if (and (eq gnus-summary-make-false-root 'empty)
4080 (memq number gnus-tmp-gathered)
4081 gnus-tmp-prev-subject
4082 (inline (gnus-subject-equal
4083 gnus-tmp-prev-subject subject)))
4084 gnus-summary-same-subject
4085 subject))
4086 (t gnus-summary-same-subject)))
4087 (if (and (eq gnus-summary-make-false-root 'adopt)
4088 (= gnus-tmp-level 1)
4089 (memq number gnus-tmp-gathered))
4090 (setq gnus-tmp-opening-bracket ?\<
4091 gnus-tmp-closing-bracket ?\>)
4092 (setq gnus-tmp-opening-bracket ?\[
4093 gnus-tmp-closing-bracket ?\]))
4094 (setq
4095 gnus-tmp-indentation
4096 (aref gnus-thread-indent-array gnus-tmp-level)
4097 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4098 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4099 gnus-summary-default-score 0)
4100 gnus-tmp-score-char
4101 (if (or (null gnus-summary-default-score)
4102 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4103 gnus-summary-zcore-fuzz))
16409b0b 4104 ? ;Whitespace
eec82323
LMI
4105 (if (< gnus-tmp-score gnus-summary-default-score)
4106 gnus-score-below-mark gnus-score-over-mark))
4107 gnus-tmp-replied
4108 (cond ((memq number gnus-newsgroup-processable)
4109 gnus-process-mark)
4110 ((memq number gnus-newsgroup-cached)
4111 gnus-cached-mark)
4112 ((memq number gnus-newsgroup-replied)
4113 gnus-replied-mark)
4114 ((memq number gnus-newsgroup-saved)
4115 gnus-saved-mark)
4116 (t gnus-unread-mark))
4117 gnus-tmp-from (mail-header-from gnus-tmp-header)
4118 gnus-tmp-name
4119 (cond
4120 ((string-match "<[^>]+> *$" gnus-tmp-from)
4121 (setq beg-match (match-beginning 0))
4122 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
4123 (substring gnus-tmp-from (1+ (match-beginning 0))
4124 (1- (match-end 0))))
4125 (substring gnus-tmp-from 0 beg-match)))
4126 ((string-match "(.+)" gnus-tmp-from)
4127 (substring gnus-tmp-from
4128 (1+ (match-beginning 0)) (1- (match-end 0))))
4129 (t gnus-tmp-from)))
4130 (when (string= gnus-tmp-name "")
4131 (setq gnus-tmp-name gnus-tmp-from))
4132 (unless (numberp gnus-tmp-lines)
4133 (setq gnus-tmp-lines 0))
16409b0b 4134 (gnus-put-text-property
eec82323
LMI
4135 (point)
4136 (progn (eval gnus-summary-line-format-spec) (point))
4137 'gnus-number number)
4138 (when gnus-visual-p
4139 (forward-line -1)
6748645f 4140 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
4141 (forward-line 1))
4142
4143 (setq gnus-tmp-prev-subject subject)))
4144
4145 (when (nth 1 thread)
4146 (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4147 (incf gnus-tmp-level)
4148 (setq threads (if thread-end nil (cdar thread)))
4149 (unless threads
4150 (setq gnus-tmp-level 0)))))
4151 (gnus-message 7 "Generating summary...done"))
4152
4153(defun gnus-summary-prepare-unthreaded (headers)
4154 "Generate an unthreaded summary buffer based on HEADERS."
4155 (let (header number mark)
4156
4157 (beginning-of-line)
4158
4159 (while headers
4160 ;; We may have to root out some bad articles...
4161 (when (memq (setq number (mail-header-number
4162 (setq header (pop headers))))
4163 gnus-newsgroup-limit)
4164 ;; Mark article as read when it has a low score.
4165 (when (and gnus-summary-mark-below
4166 (< (or (cdr (assq number gnus-newsgroup-scored))
4167 gnus-summary-default-score 0)
4168 gnus-summary-mark-below)
4169 (not (gnus-summary-article-ancient-p number)))
4170 (setq gnus-newsgroup-unreads
4171 (delq number gnus-newsgroup-unreads))
4172 (if gnus-newsgroup-auto-expire
4173 (push number gnus-newsgroup-expirable)
4174 (push (cons number gnus-low-score-mark)
4175 gnus-newsgroup-reads)))
4176
4177 (setq mark (gnus-article-mark number))
4178 (push (gnus-data-make number mark (1+ (point)) header 0)
4179 gnus-newsgroup-data)
4180 (gnus-summary-insert-line
4181 header 0 number
4182 mark (memq number gnus-newsgroup-replied)
4183 (memq number gnus-newsgroup-expirable)
4184 (mail-header-subject header) nil
4185 (cdr (assq number gnus-newsgroup-scored))
4186 (memq number gnus-newsgroup-processable))))))
4187
16409b0b
GM
4188(defun gnus-summary-remove-list-identifiers ()
4189 "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4190 (let ((regexp (if (stringp gnus-list-identifiers)
4191 gnus-list-identifiers
4192 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
4193 (dolist (header gnus-newsgroup-headers)
4194 (when (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
4195 " *\\)\\)+\\(Re: +\\)?\\)")
4196 (mail-header-subject header))
4197 (mail-header-set-subject
4198 header (concat (substring (mail-header-subject header)
4199 0 (match-beginning 1))
4200 (or
4201 (match-string 3 (mail-header-subject header))
4202 (match-string 5 (mail-header-subject header)))
4203 (substring (mail-header-subject header)
4204 (match-end 1))))))))
4205
6748645f 4206(defun gnus-select-newsgroup (group &optional read-all select-articles)
eec82323 4207 "Select newsgroup GROUP.
6748645f
LMI
4208If READ-ALL is non-nil, all articles in the group are selected.
4209If SELECT-ARTICLES, only select those articles from GROUP."
eec82323
LMI
4210 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4211 ;;!!! Dirty hack; should be removed.
4212 (gnus-summary-ignore-duplicates
6748645f 4213 (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
eec82323
LMI
4214 t
4215 gnus-summary-ignore-duplicates))
4216 (info (nth 2 entry))
4217 articles fetched-articles cached)
4218
4219 (unless (gnus-check-server
475e0e0c
GM
4220 (set (make-local-variable 'gnus-current-select-method)
4221 (gnus-find-method-for-group group)))
eec82323
LMI
4222 (error "Couldn't open server"))
4223
4224 (or (and entry (not (eq (car entry) t))) ; Either it's active...
4225 (gnus-activate-group group) ; Or we can activate it...
4226 (progn ; Or we bug out.
4227 (when (equal major-mode 'gnus-summary-mode)
4228 (kill-buffer (current-buffer)))
4229 (error "Couldn't request group %s: %s"
4230 group (gnus-status-message group))))
4231
4232 (unless (gnus-request-group group t)
4233 (when (equal major-mode 'gnus-summary-mode)
4234 (kill-buffer (current-buffer)))
4235 (error "Couldn't request group %s: %s"
4236 group (gnus-status-message group)))
4237
4238 (setq gnus-newsgroup-name group)
4239 (setq gnus-newsgroup-unselected nil)
4240 (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
16409b0b 4241 (gnus-summary-setup-default-charset)
eec82323
LMI
4242
4243 ;; Adjust and set lists of article marks.
4244 (when info
4245 (gnus-adjust-marked-articles info))
4246
4247 ;; Kludge to avoid having cached articles nixed out in virtual groups.
4248 (when (gnus-virtual-group-p group)
4249 (setq cached gnus-newsgroup-cached))
4250
4251 (setq gnus-newsgroup-unreads
4252 (gnus-set-difference
4253 (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4254 gnus-newsgroup-dormant))
4255
4256 (setq gnus-newsgroup-processable nil)
4257
4258 (gnus-update-read-articles group gnus-newsgroup-unreads)
eec82323 4259
6748645f
LMI
4260 (if (setq articles select-articles)
4261 (setq gnus-newsgroup-unselected
4262 (gnus-sorted-intersection
4263 gnus-newsgroup-unreads
4264 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4265 (setq articles (gnus-articles-to-read group read-all)))
eec82323
LMI
4266
4267 (cond
4268 ((null articles)
4269 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4270 'quit)
4271 ((eq articles 0) nil)
4272 (t
4273 ;; Init the dependencies hash table.
4274 (setq gnus-newsgroup-dependencies
4275 (gnus-make-hashtable (length articles)))
16409b0b 4276 (gnus-set-global-variables)
eec82323
LMI
4277 ;; Retrieve the headers and read them in.
4278 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4279 (setq gnus-newsgroup-headers
4280 (if (eq 'nov
4281 (setq gnus-headers-retrieved-by
4282 (gnus-retrieve-headers
4283 articles gnus-newsgroup-name
4284 ;; We might want to fetch old headers, but
4285 ;; not if there is only 1 article.
6748645f 4286 (and (or (and
eec82323
LMI
4287 (not (eq gnus-fetch-old-headers 'some))
4288 (not (numberp gnus-fetch-old-headers)))
6748645f
LMI
4289 (> (length articles) 1))
4290 gnus-fetch-old-headers))))
eec82323
LMI
4291 (gnus-get-newsgroup-headers-xover
4292 articles nil nil gnus-newsgroup-name t)
4293 (gnus-get-newsgroup-headers)))
4294 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4295
4296 ;; Kludge to avoid having cached articles nixed out in virtual groups.
4297 (when cached
4298 (setq gnus-newsgroup-cached cached))
4299
4300 ;; Suppress duplicates?
4301 (when gnus-suppress-duplicates
4302 (gnus-dup-suppress-articles))
4303
4304 ;; Set the initial limit.
4305 (setq gnus-newsgroup-limit (copy-sequence articles))
4306 ;; Remove canceled articles from the list of unread articles.
4307 (setq gnus-newsgroup-unreads
4308 (gnus-set-sorted-intersection
4309 gnus-newsgroup-unreads
4310 (setq fetched-articles
4311 (mapcar (lambda (headers) (mail-header-number headers))
4312 gnus-newsgroup-headers))))
4313 ;; Removed marked articles that do not exist.
4314 (gnus-update-missing-marks
4315 (gnus-sorted-complement fetched-articles articles))
4316 ;; We might want to build some more threads first.
6748645f
LMI
4317 (when (and gnus-fetch-old-headers
4318 (eq gnus-headers-retrieved-by 'nov))
4319 (if (eq gnus-fetch-old-headers 'invisible)
4320 (gnus-build-all-threads)
4321 (gnus-build-old-threads)))
4322 ;; Let the Gnus agent mark articles as read.
4323 (when gnus-agent
4324 (gnus-agent-get-undownloaded-list))
16409b0b
GM
4325 ;; Remove list identifiers from subject
4326 (when gnus-list-identifiers
4327 (gnus-summary-remove-list-identifiers))
eec82323
LMI
4328 ;; Check whether auto-expire is to be done in this group.
4329 (setq gnus-newsgroup-auto-expire
4330 (gnus-group-auto-expirable-p group))
4331 ;; Set up the article buffer now, if necessary.
4332 (unless gnus-single-article-buffer
4333 (gnus-article-setup-buffer))
4334 ;; First and last article in this newsgroup.
4335 (when gnus-newsgroup-headers
4336 (setq gnus-newsgroup-begin
4337 (mail-header-number (car gnus-newsgroup-headers))
4338 gnus-newsgroup-end
4339 (mail-header-number
4340 (gnus-last-element gnus-newsgroup-headers))))
4341 ;; GROUP is successfully selected.
4342 (or gnus-newsgroup-headers t)))))
4343
4344(defun gnus-articles-to-read (group &optional read-all)
16409b0b 4345 "Find out what articles the user wants to read."
eec82323
LMI
4346 (let* ((articles
4347 ;; Select all articles if `read-all' is non-nil, or if there
4348 ;; are no unread articles.
4349 (if (or read-all
4350 (and (zerop (length gnus-newsgroup-marked))
4351 (zerop (length gnus-newsgroup-unreads)))
4352 (eq (gnus-group-find-parameter group 'display)
4353 'all))
16409b0b
GM
4354 (or
4355 (gnus-uncompress-range (gnus-active group))
4356 (gnus-cache-articles-in-group group))
eec82323
LMI
4357 (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4358 (copy-sequence gnus-newsgroup-unreads))
4359 '<)))
4360 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4361 (scored (length scored-list))
4362 (number (length articles))
4363 (marked (+ (length gnus-newsgroup-marked)
4364 (length gnus-newsgroup-dormant)))
4365 (select
4366 (cond
4367 ((numberp read-all)
4368 read-all)
4369 (t
4370 (condition-case ()
4371 (cond
4372 ((and (or (<= scored marked) (= scored number))
4373 (numberp gnus-large-newsgroup)
4374 (> number gnus-large-newsgroup))
4375 (let ((input
4376 (read-string
4377 (format
4378 "How many articles from %s (default %d): "
4379 (gnus-limit-string gnus-newsgroup-name 35)
4380 number))))
4381 (if (string-match "^[ \t]*$" input) number input)))
4382 ((and (> scored marked) (< scored number)
4383 (> (- scored number) 20))
4384 (let ((input
4385 (read-string
4386 (format "%s %s (%d scored, %d total): "
4387 "How many articles from"
4388 group scored number))))
4389 (if (string-match "^[ \t]*$" input)
4390 number input)))
4391 (t number))
d4dfaa19
DL
4392 (quit
4393 (message "Quit getting the articles to read")
4394 nil))))))
eec82323
LMI
4395 (setq select (if (stringp select) (string-to-number select) select))
4396 (if (or (null select) (zerop select))
4397 select
4398 (if (and (not (zerop scored)) (<= (abs select) scored))
4399 (progn
4400 (setq articles (sort scored-list '<))
4401 (setq number (length articles)))
4402 (setq articles (copy-sequence articles)))
4403
4404 (when (< (abs select) number)
4405 (if (< select 0)
4406 ;; Select the N oldest articles.
4407 (setcdr (nthcdr (1- (abs select)) articles) nil)
4408 ;; Select the N most recent articles.
4409 (setq articles (nthcdr (- number select) articles))))
4410 (setq gnus-newsgroup-unselected
4411 (gnus-sorted-intersection
4412 gnus-newsgroup-unreads
4413 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
16409b0b
GM
4414 (when gnus-alter-articles-to-read-function
4415 (setq gnus-newsgroup-unreads
4416 (sort
4417 (funcall gnus-alter-articles-to-read-function
4418 gnus-newsgroup-name gnus-newsgroup-unreads)
4419 '<)))
eec82323
LMI
4420 articles)))
4421
4422(defun gnus-killed-articles (killed articles)
4423 (let (out)
4424 (while articles
4425 (when (inline (gnus-member-of-range (car articles) killed))
4426 (push (car articles) out))
4427 (setq articles (cdr articles)))
4428 out))
4429
4430(defun gnus-uncompress-marks (marks)
4431 "Uncompress the mark ranges in MARKS."
4432 (let ((uncompressed '(score bookmark))
4433 out)
4434 (while marks
4435 (if (memq (caar marks) uncompressed)
4436 (push (car marks) out)
4437 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4438 (setq marks (cdr marks)))
4439 out))
4440
4441(defun gnus-adjust-marked-articles (info)
16409b0b 4442 "Set all article lists and remove all marks that are no longer valid."
eec82323
LMI
4443 (let* ((marked-lists (gnus-info-marks info))
4444 (active (gnus-active (gnus-info-group info)))
4445 (min (car active))
4446 (max (cdr active))
4447 (types gnus-article-mark-lists)
4448 (uncompressed '(score bookmark killed))
4449 marks var articles article mark)
4450
4451 (while marked-lists
4452 (setq marks (pop marked-lists))
4453 (set (setq var (intern (format "gnus-newsgroup-%s"
4454 (car (rassq (setq mark (car marks))
4455 types)))))
4456 (if (memq (car marks) uncompressed) (cdr marks)
4457 (gnus-uncompress-range (cdr marks))))
4458
4459 (setq articles (symbol-value var))
4460
4461 ;; All articles have to be subsets of the active articles.
4462 (cond
4463 ;; Adjust "simple" lists.
4464 ((memq mark '(tick dormant expire reply save))
4465 (while articles
4466 (when (or (< (setq article (pop articles)) min) (> article max))
4467 (set var (delq article (symbol-value var))))))
4468 ;; Adjust assocs.
4469 ((memq mark uncompressed)
a8151ef7
LMI
4470 (when (not (listp (cdr (symbol-value var))))
4471 (set var (list (symbol-value var))))
4472 (when (not (listp (cdr articles)))
4473 (setq articles (list articles)))
eec82323
LMI
4474 (while articles
4475 (when (or (not (consp (setq article (pop articles))))
4476 (< (car article) min)
4477 (> (car article) max))
4478 (set var (delq article (symbol-value var))))))))))
4479
4480(defun gnus-update-missing-marks (missing)
6748645f 4481 "Go through the list of MISSING articles and remove them from the mark lists."
eec82323
LMI
4482 (when missing
4483 (let ((types gnus-article-mark-lists)
4484 var m)
4485 ;; Go through all types.
4486 (while types
4487 (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4488 (when (symbol-value var)
4489 ;; This list has articles. So we delete all missing articles
4490 ;; from it.
4491 (setq m missing)
4492 (while m
4493 (set var (delq (pop m) (symbol-value var)))))))))
4494
4495(defun gnus-update-marks ()
4496 "Enter the various lists of marked articles into the newsgroup info list."
4497 (let ((types gnus-article-mark-lists)
4498 (info (gnus-get-info gnus-newsgroup-name))
4499 (uncompressed '(score bookmark killed))
16409b0b 4500 type list newmarked symbol delta-marks)
eec82323 4501 (when info
16409b0b 4502 ;; Add all marks lists to the list of marks lists.
eec82323 4503 (while (setq type (pop types))
16409b0b
GM
4504 (setq list (symbol-value
4505 (setq symbol
4506 (intern (format "gnus-newsgroup-%s"
4507 (car type))))))
eec82323 4508
16409b0b 4509 (when list
eec82323
LMI
4510 ;; Get rid of the entries of the articles that have the
4511 ;; default score.
4512 (when (and (eq (cdr type) 'score)
4513 gnus-save-score
4514 list)
4515 (let* ((arts list)
4516 (prev (cons nil list))
4517 (all prev))
4518 (while arts
4519 (if (or (not (consp (car arts)))
4520 (= (cdar arts) gnus-summary-default-score))
4521 (setcdr prev (cdr arts))
4522 (setq prev arts))
4523 (setq arts (cdr arts)))
16409b0b
GM
4524 (setq list (cdr all)))))
4525
4526 (unless (memq (cdr type) uncompressed)
4527 (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4528
4529 (when (gnus-check-backend-function
4530 'request-set-mark gnus-newsgroup-name)
4531 ;; propagate flags to server, with the following exceptions:
4532 ;; uncompressed:s are not proper flags (they are cons cells)
4533 ;; cache is a internal gnus flag
4534 ;; download are local to one gnus installation (well)
4535 ;; unsend are for nndraft groups only
4536 ;; xxx: generality of this? this suits nnimap anyway
4537 (unless (memq (cdr type) (append '(cache download unsend)
4538 uncompressed))
4539 (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4540 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4541 (add (gnus-remove-from-range
4542 (gnus-copy-sequence list) old)))
4543 (when add
4544 (push (list add 'add (list (cdr type))) delta-marks))
4545 (when del
4546 (push (list del 'del (list (cdr type))) delta-marks)))))
4547
4548 (when list
4549 (push (cons (cdr type) list) newmarked)))
4550
4551 (when delta-marks
4552 (unless (gnus-check-group gnus-newsgroup-name)
4553 (error "Can't open server for %s" gnus-newsgroup-name))
4554 (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4555
eec82323
LMI
4556 ;; Enter these new marks into the info of the group.
4557 (if (nthcdr 3 info)
4558 (setcar (nthcdr 3 info) newmarked)
4559 ;; Add the marks lists to the end of the info.
4560 (when newmarked
4561 (setcdr (nthcdr 2 info) (list newmarked))))
4562
4563 ;; Cut off the end of the info if there's nothing else there.
4564 (let ((i 5))
4565 (while (and (> i 2)
4566 (not (nth i info)))
4567 (when (nthcdr (decf i) info)
4568 (setcdr (nthcdr i info) nil)))))))
4569
4570(defun gnus-set-mode-line (where)
16409b0b 4571 "Set the mode line of the article or summary buffers.
eec82323
LMI
4572If WHERE is `summary', the summary mode line format will be used."
4573 ;; Is this mode line one we keep updated?
16409b0b
GM
4574 (when (and (memq where gnus-updated-mode-lines)
4575 (symbol-value
4576 (intern (format "gnus-%s-mode-line-format-spec" where))))
eec82323
LMI
4577 (let (mode-string)
4578 (save-excursion
4579 ;; We evaluate this in the summary buffer since these
4580 ;; variables are buffer-local to that buffer.
4581 (set-buffer gnus-summary-buffer)
4582 ;; We bind all these variables that are used in the `eval' form
4583 ;; below.
4584 (let* ((mformat (symbol-value
4585 (intern
4586 (format "gnus-%s-mode-line-format-spec" where))))
16409b0b
GM
4587 (gnus-tmp-group-name (gnus-group-name-decode
4588 gnus-newsgroup-name
4589 (gnus-group-name-charset
4590 nil
4591 gnus-newsgroup-name)))
eec82323
LMI
4592 (gnus-tmp-article-number (or gnus-current-article 0))
4593 (gnus-tmp-unread gnus-newsgroup-unreads)
4594 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4595 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4596 (gnus-tmp-unread-and-unselected
4597 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4598 (zerop gnus-tmp-unselected))
4599 "")
4600 ((zerop gnus-tmp-unselected)
4601 (format "{%d more}" gnus-tmp-unread-and-unticked))
4602 (t (format "{%d(+%d) more}"
4603 gnus-tmp-unread-and-unticked
4604 gnus-tmp-unselected))))
4605 (gnus-tmp-subject
4606 (if (and gnus-current-headers
4607 (vectorp gnus-current-headers))
4608 (gnus-mode-string-quote
4609 (mail-header-subject gnus-current-headers))
4610 ""))
4611 bufname-length max-len
4612 gnus-tmp-header);; passed as argument to any user-format-funcs
4613 (setq mode-string (eval mformat))
4614 (setq bufname-length (if (string-match "%b" mode-string)
4615 (- (length
4616 (buffer-name
4617 (if (eq where 'summary)
4618 nil
4619 (get-buffer gnus-article-buffer))))
4620 2)
4621 0))
4622 (setq max-len (max 4 (if gnus-mode-non-string-length
4623 (- (window-width)
4624 gnus-mode-non-string-length
4625 bufname-length)
4626 (length mode-string))))
4627 ;; We might have to chop a bit of the string off...
4628 (when (> (length mode-string) max-len)
4629 (setq mode-string
16409b0b 4630 (concat (truncate-string-to-width mode-string (- max-len 3))
eec82323
LMI
4631 "...")))
4632 ;; Pad the mode string a bit.
4633 (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4634 ;; Update the mode line.
4635 (setq mode-line-buffer-identification
4636 (gnus-mode-line-buffer-identification (list mode-string)))
4637 (set-buffer-modified-p t))))
4638
4639(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4640 "Go through the HEADERS list and add all Xrefs to a hash table.
4641The resulting hash table is returned, or nil if no Xrefs were found."
4642 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4643 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4644 (xref-hashtb (gnus-make-hashtable))
4645 start group entry number xrefs header)
4646 (while headers
4647 (setq header (pop headers))
4648 (when (and (setq xrefs (mail-header-xref header))
4649 (not (memq (setq number (mail-header-number header))
4650 unreads)))
4651 (setq start 0)
4652 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4653 (setq start (match-end 0))
4654 (setq group (if prefix
4655 (concat prefix (substring xrefs (match-beginning 1)
4656 (match-end 1)))
4657 (substring xrefs (match-beginning 1) (match-end 1))))
4658 (setq number
4659 (string-to-int (substring xrefs (match-beginning 2)
4660 (match-end 2))))
4661 (if (setq entry (gnus-gethash group xref-hashtb))
4662 (setcdr entry (cons number (cdr entry)))
4663 (gnus-sethash group (cons number nil) xref-hashtb)))))
4664 (and start xref-hashtb)))
4665
4666(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4667 "Look through all the headers and mark the Xrefs as read."
4668 (let ((virtual (gnus-virtual-group-p from-newsgroup))
4669 name entry info xref-hashtb idlist method nth4)
4670 (save-excursion
4671 (set-buffer gnus-group-buffer)
4672 (when (setq xref-hashtb
4673 (gnus-create-xref-hashtb from-newsgroup headers unreads))
4674 (mapatoms
4675 (lambda (group)
4676 (unless (string= from-newsgroup (setq name (symbol-name group)))
4677 (setq idlist (symbol-value group))
4678 ;; Dead groups are not updated.
4679 (and (prog1
4680 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4681 info (nth 2 entry))
4682 (when (stringp (setq nth4 (gnus-info-method info)))
4683 (setq nth4 (gnus-server-to-method nth4))))
4684 ;; Only do the xrefs if the group has the same
4685 ;; select method as the group we have just read.
4686 (or (gnus-methods-equal-p
4687 nth4 (gnus-find-method-for-group from-newsgroup))
4688 virtual
4689 (equal nth4 (setq method (gnus-find-method-for-group
4690 from-newsgroup)))
4691 (and (equal (car nth4) (car method))
4692 (equal (nth 1 nth4) (nth 1 method))))
4693 gnus-use-cross-reference
4694 (or (not (eq gnus-use-cross-reference t))
4695 virtual
4696 ;; Only do cross-references on subscribed
4697 ;; groups, if that is what is wanted.
4698 (<= (gnus-info-level info) gnus-level-subscribed))
4699 (gnus-group-make-articles-read name idlist))))
4700 xref-hashtb)))))
4701
6748645f
LMI
4702(defun gnus-compute-read-articles (group articles)
4703 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4704 (info (nth 2 entry))
4705 (active (gnus-active group))
4706 ninfo)
4707 (when entry
16409b0b 4708 ;; First peel off all invalid article numbers.
6748645f
LMI
4709 (when active
4710 (let ((ids articles)
4711 id first)
4712 (while (setq id (pop ids))
4713 (when (and first (> id (cdr active)))
4714 ;; We'll end up in this situation in one particular
4715 ;; obscure situation. If you re-scan a group and get
4716 ;; a new article that is cross-posted to a different
4717 ;; group that has not been re-scanned, you might get
4718 ;; crossposted article that has a higher number than
4719 ;; Gnus believes possible. So we re-activate this
4720 ;; group as well. This might mean doing the
4721 ;; crossposting thingy will *increase* the number
4722 ;; of articles in some groups. Tsk, tsk.
4723 (setq active (or (gnus-activate-group group) active)))
4724 (when (or (> id (cdr active))
4725 (< id (car active)))
4726 (setq articles (delq id articles))))))
4727 ;; If the read list is nil, we init it.
4728 (if (and active
4729 (null (gnus-info-read info))
4730 (> (car active) 1))
4731 (setq ninfo (cons 1 (1- (car active))))
4732 (setq ninfo (gnus-info-read info)))
4733 ;; Then we add the read articles to the range.
4734 (gnus-add-to-range
4735 ninfo (setq articles (sort articles '<))))))
4736
eec82323
LMI
4737(defun gnus-group-make-articles-read (group articles)
4738 "Update the info of GROUP to say that ARTICLES are read."
4739 (let* ((num 0)
4740 (entry (gnus-gethash group gnus-newsrc-hashtb))
4741 (info (nth 2 entry))
4742 (active (gnus-active group))
4743 range)
6748645f
LMI
4744 (when entry
4745 (setq range (gnus-compute-read-articles group articles))
4746 (save-excursion
4747 (set-buffer gnus-group-buffer)
4748 (gnus-undo-register
4749 `(progn
4750 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4751 (gnus-info-set-read ',info ',(gnus-info-read info))
4752 (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4753 (gnus-group-update-group ,group t))))
4754 ;; Add the read articles to the range.
4755 (gnus-info-set-read info range)
4756 ;; Then we have to re-compute how many unread
4757 ;; articles there are in this group.
4758 (when active
4759 (cond
4760 ((not range)
4761 (setq num (- (1+ (cdr active)) (car active))))
4762 ((not (listp (cdr range)))
4763 (setq num (- (cdr active) (- (1+ (cdr range))
4764 (car range)))))
4765 (t
4766 (while range
4767 (if (numberp (car range))
4768 (setq num (1+ num))
4769 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4770 (setq range (cdr range)))
4771 (setq num (- (cdr active) num))))
4772 ;; Update the number of unread articles.
4773 (setcar entry num)
4774 ;; Update the group buffer.
4775 (gnus-group-update-group group t)))))
eec82323 4776
eec82323
LMI
4777(defvar gnus-newsgroup-none-id 0)
4778
4779(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4780 (let ((cur nntp-server-buffer)
4781 (dependencies
4782 (or dependencies
4783 (save-excursion (set-buffer gnus-summary-buffer)
4784 gnus-newsgroup-dependencies)))
16409b0b
GM
4785 headers id end ref
4786 (mail-parse-charset gnus-newsgroup-charset)
4787 (mail-parse-ignored-charsets
4788 (save-excursion (condition-case nil
4789 (set-buffer gnus-summary-buffer)
4790 (error))
4791 gnus-newsgroup-ignored-charsets)))
eec82323
LMI
4792 (save-excursion
4793 (set-buffer nntp-server-buffer)
4794 ;; Translate all TAB characters into SPACE characters.
4795 (subst-char-in-region (point-min) (point-max) ?\t ? t)
16409b0b 4796 (subst-char-in-region (point-min) (point-max) ?\r ? t)
6748645f 4797 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 4798 (let ((case-fold-search t)
6748645f 4799 in-reply-to header p lines chars)
eec82323
LMI
4800 (goto-char (point-min))
4801 ;; Search to the beginning of the next header. Error messages
4802 ;; do not begin with 2 or 3.
4803 (while (re-search-forward "^[23][0-9]+ " nil t)
4804 (setq id nil
4805 ref nil)
4806 ;; This implementation of this function, with nine
4807 ;; search-forwards instead of the one re-search-forward and
4808 ;; a case (which basically was the old function) is actually
4809 ;; about twice as fast, even though it looks messier. You
4810 ;; can't have everything, I guess. Speed and elegance
4811 ;; doesn't always go hand in hand.
4812 (setq
4813 header
4814 (vector
4815 ;; Number.
4816 (prog1
4817 (read cur)
4818 (end-of-line)
4819 (setq p (point))
4820 (narrow-to-region (point)
4821 (or (and (search-forward "\n.\n" nil t)
4822 (- (point) 2))
4823 (point))))
4824 ;; Subject.
4825 (progn
4826 (goto-char p)
4827 (if (search-forward "\nsubject: " nil t)
16409b0b
GM
4828 (funcall gnus-decode-encoded-word-function
4829 (nnheader-header-value))
2bd3dcae 4830 "(none)"))
eec82323
LMI
4831 ;; From.
4832 (progn
4833 (goto-char p)
d4dfaa19
DL
4834 (if (or (search-forward "\nfrom: " nil t)
4835 (search-forward "\nfrom:" nil t))
16409b0b
GM
4836 (funcall gnus-decode-encoded-word-function
4837 (nnheader-header-value))
2bd3dcae 4838 "(nobody)"))
eec82323
LMI
4839 ;; Date.
4840 (progn
4841 (goto-char p)
4842 (if (search-forward "\ndate: " nil t)
4843 (nnheader-header-value) ""))
4844 ;; Message-ID.
4845 (progn
4846 (goto-char p)
6748645f
LMI
4847 (setq id (if (re-search-forward
4848 "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4849 ;; We do it this way to make sure the Message-ID
4850 ;; is (somewhat) syntactically valid.
4851 (buffer-substring (match-beginning 1)
4852 (match-end 1))
eec82323
LMI
4853 ;; If there was no message-id, we just fake one
4854 ;; to make subsequent routines simpler.
4855 (nnheader-generate-fake-message-id))))
4856 ;; References.
4857 (progn
4858 (goto-char p)
4859 (if (search-forward "\nreferences: " nil t)
4860 (progn
4861 (setq end (point))
4862 (prog1
4863 (nnheader-header-value)
4864 (setq ref
4865 (buffer-substring
4866 (progn
4867 (end-of-line)
4868 (search-backward ">" end t)
4869 (1+ (point)))
4870 (progn
4871 (search-backward "<" end t)
4872 (point))))))
4873 ;; Get the references from the in-reply-to header if there
4874 ;; were no references and the in-reply-to header looks
4875 ;; promising.
4876 (if (and (search-forward "\nin-reply-to: " nil t)
4877 (setq in-reply-to (nnheader-header-value))
4878 (string-match "<[^>]+>" in-reply-to))
6748645f
LMI
4879 (let (ref2)
4880 (setq ref (substring in-reply-to (match-beginning 0)
4881 (match-end 0)))
4882 (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4883 (setq ref2 (substring in-reply-to (match-beginning 0)
4884 (match-end 0)))
4885 (when (> (length ref2) (length ref))
4886 (setq ref ref2)))
4887 ref)
eec82323
LMI
4888 (setq ref nil))))
4889 ;; Chars.
6748645f
LMI
4890 (progn
4891 (goto-char p)
4892 (if (search-forward "\nchars: " nil t)
4893 (if (numberp (setq chars (ignore-errors (read cur))))
4894 chars 0)
4895 0))
eec82323
LMI
4896 ;; Lines.
4897 (progn
4898 (goto-char p)
4899 (if (search-forward "\nlines: " nil t)
a8151ef7 4900 (if (numberp (setq lines (ignore-errors (read cur))))
eec82323
LMI
4901 lines 0)
4902 0))
4903 ;; Xref.
4904 (progn
4905 (goto-char p)
4906 (and (search-forward "\nxref: " nil t)
16409b0b
GM
4907 (nnheader-header-value)))
4908 ;; Extra.
4909 (when gnus-extra-headers
4910 (let ((extra gnus-extra-headers)
4911 out)
4912 (while extra
4913 (goto-char p)
4914 (when (search-forward
4915 (concat "\n" (symbol-name (car extra)) ": ") nil t)
4916 (push (cons (car extra) (nnheader-header-value))
4917 out))
4918 (pop extra))
4919 out))))
eec82323
LMI
4920 (when (equal id ref)
4921 (setq ref nil))
6748645f
LMI
4922
4923 (when gnus-alter-header-function
4924 (funcall gnus-alter-header-function header)
4925 (setq id (mail-header-id header)
4926 ref (gnus-parent-id (mail-header-references header))))
4927
4928 (when (setq header
4929 (gnus-dependencies-add-header
4930 header dependencies force-new))
eec82323
LMI
4931 (push header headers))
4932 (goto-char (point-max))
4933 (widen))
4934 (nreverse headers)))))
4935
eec82323
LMI
4936;; Goes through the xover lines and returns a list of vectors
4937(defun gnus-get-newsgroup-headers-xover (sequence &optional
4938 force-new dependencies
4939 group also-fetch-heads)
16409b0b
GM
4940 "Parse the news overview data in the server buffer.
4941Return a list of headers that match SEQUENCE (see
4942`nntp-retrieve-headers')."
eec82323
LMI
4943 ;; Get the Xref when the users reads the articles since most/some
4944 ;; NNTP servers do not include Xrefs when using XOVER.
4945 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
16409b0b
GM
4946 (let ((mail-parse-charset gnus-newsgroup-charset)
4947 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
4948 (cur nntp-server-buffer)
eec82323
LMI
4949 (dependencies (or dependencies gnus-newsgroup-dependencies))
4950 number headers header)
4951 (save-excursion
4952 (set-buffer nntp-server-buffer)
16409b0b 4953 (subst-char-in-region (point-min) (point-max) ?\r ? t)
eec82323 4954 ;; Allow the user to mangle the headers before parsing them.
6748645f 4955 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323
LMI
4956 (goto-char (point-min))
4957 (while (not (eobp))
4958 (condition-case ()
4959 (while (and sequence (not (eobp)))
4960 (setq number (read cur))
4961 (while (and sequence
4962 (< (car sequence) number))
4963 (setq sequence (cdr sequence)))
4964 (and sequence
4965 (eq number (car sequence))
4966 (progn
4967 (setq sequence (cdr sequence))
4968 (setq header (inline
4969 (gnus-nov-parse-line
4970 number dependencies force-new))))
4971 (push header headers))
4972 (forward-line 1))
4973 (error
4974 (gnus-error 4 "Strange nov line (%d)"
4975 (count-lines (point-min) (point)))))
4976 (forward-line 1))
4977 ;; A common bug in inn is that if you have posted an article and
4978 ;; then retrieves the active file, it will answer correctly --
4979 ;; the new article is included. However, a NOV entry for the
4980 ;; article may not have been generated yet, so this may fail.
4981 ;; We work around this problem by retrieving the last few
4982 ;; headers using HEAD.
4983 (if (or (not also-fetch-heads)
4984 (not sequence))
4985 ;; We (probably) got all the headers.
4986 (nreverse headers)
4987 (let ((gnus-nov-is-evil t))
4988 (nconc
4989 (nreverse headers)
4990 (when (gnus-retrieve-headers sequence group)
4991 (gnus-get-newsgroup-headers))))))))
4992
4993(defun gnus-article-get-xrefs ()
4994 "Fill in the Xref value in `gnus-current-headers', if necessary.
4995This is meant to be called in `gnus-article-internal-prepare-hook'."
4996 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4997 gnus-current-headers)))
4998 (or (not gnus-use-cross-reference)
4999 (not headers)
5000 (and (mail-header-xref headers)
5001 (not (string= (mail-header-xref headers) "")))
5002 (let ((case-fold-search t)
5003 xref)
5004 (save-restriction
5005 (nnheader-narrow-to-headers)
5006 (goto-char (point-min))
16409b0b
GM
5007 (when (or (and (not (eobp))
5008 (eq (downcase (char-after)) ?x)
eec82323
LMI
5009 (looking-at "Xref:"))
5010 (search-forward "\nXref:" nil t))
5011 (goto-char (1+ (match-end 0)))
5012 (setq xref (buffer-substring (point)
5013 (progn (end-of-line) (point))))
5014 (mail-header-set-xref headers xref)))))))
5015
5016(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6748645f
LMI
5017 "Find article ID and insert the summary line for that article.
5018OLD-HEADER can either be a header or a line number to insert
5019the subject line on."
5020 (let* ((line (and (numberp old-header) old-header))
5021 (old-header (and (vectorp old-header) old-header))
5022 (header (cond ((and old-header use-old-header)
16409b0b
GM
5023 old-header)
5024 ((and (numberp id)
5025 (gnus-number-to-header id))
5026 (gnus-number-to-header id))
5027 (t
5028 (gnus-read-header id))))
5029 (number (and (numberp id) id))
5030 d)
eec82323
LMI
5031 (when header
5032 ;; Rebuild the thread that this article is part of and go to the
5033 ;; article we have fetched.
5034 (when (and (not gnus-show-threads)
5035 old-header)
6748645f
LMI
5036 (when (and number
5037 (setq d (gnus-data-find (mail-header-number old-header))))
eec82323
LMI
5038 (goto-char (gnus-data-pos d))
5039 (gnus-data-remove
5040 number
5041 (- (gnus-point-at-bol)
5042 (prog1
5043 (1+ (gnus-point-at-eol))
5044 (gnus-delete-line))))))
5045 (when old-header
5046 (mail-header-set-number header (mail-header-number old-header)))
5047 (setq gnus-newsgroup-sparse
5048 (delq (setq number (mail-header-number header))
5049 gnus-newsgroup-sparse))
5050 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6748645f
LMI
5051 (push number gnus-newsgroup-limit)
5052 (gnus-rebuild-thread (mail-header-id header) line)
eec82323
LMI
5053 (gnus-summary-goto-subject number nil t))
5054 (when (and (numberp number)
5055 (> number 0))
5056 ;; We have to update the boundaries even if we can't fetch the
5057 ;; article if ID is a number -- so that the next `P' or `N'
5058 ;; command will fetch the previous (or next) article even
5059 ;; if the one we tried to fetch this time has been canceled.
5060 (when (> number gnus-newsgroup-end)
5061 (setq gnus-newsgroup-end number))
5062 (when (< number gnus-newsgroup-begin)
5063 (setq gnus-newsgroup-begin number))
5064 (setq gnus-newsgroup-unselected
5065 (delq number gnus-newsgroup-unselected)))
5066 ;; Report back a success?
5067 (and header (mail-header-number header))))
5068
5069;;; Process/prefix in the summary buffer
5070
5071(defun gnus-summary-work-articles (n)
6748645f
LMI
5072 "Return a list of articles to be worked upon.
5073The prefix argument, the list of process marked articles, and the
5074current article will be taken into consideration."
5075 (save-excursion
5076 (set-buffer gnus-summary-buffer)
5077 (cond
5078 (n
5079 ;; A numerical prefix has been given.
5080 (setq n (prefix-numeric-value n))
5081 (let ((backward (< n 0))
5082 (n (abs (prefix-numeric-value n)))
5083 articles article)
5084 (save-excursion
5085 (while
5086 (and (> n 0)
5087 (push (setq article (gnus-summary-article-number))
5088 articles)
5089 (if backward
5090 (gnus-summary-find-prev nil article)
5091 (gnus-summary-find-next nil article)))
5092 (decf n)))
5093 (nreverse articles)))
5094 ((and (gnus-region-active-p) (mark))
5095 (message "region active")
5096 ;; Work on the region between point and mark.
5097 (let ((max (max (point) (mark)))
5098 articles article)
5099 (save-excursion
5100 (goto-char (min (min (point) (mark))))
5101 (while
5102 (and
5103 (push (setq article (gnus-summary-article-number)) articles)
5104 (gnus-summary-find-next nil article)
5105 (< (point) max)))
5106 (nreverse articles))))
5107 (gnus-newsgroup-processable
5108 ;; There are process-marked articles present.
5109 ;; Save current state.
5110 (gnus-summary-save-process-mark)
5111 ;; Return the list.
5112 (reverse gnus-newsgroup-processable))
5113 (t
5114 ;; Just return the current article.
5115 (list (gnus-summary-article-number))))))
5116
5117(defmacro gnus-summary-iterate (arg &rest forms)
5118 "Iterate over the process/prefixed articles and do FORMS.
5119ARG is the interactive prefix given to the command. FORMS will be
5120executed with point over the summary line of the articles."
5121 (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5122 `(let ((,articles (gnus-summary-work-articles ,arg)))
5123 (while ,articles
5124 (gnus-summary-goto-subject (car ,articles))
16409b0b
GM
5125 ,@forms
5126 (pop ,articles)))))
6748645f
LMI
5127
5128(put 'gnus-summary-iterate 'lisp-indent-function 1)
5129(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
eec82323
LMI
5130
5131(defun gnus-summary-save-process-mark ()
5132 "Push the current set of process marked articles on the stack."
5133 (interactive)
5134 (push (copy-sequence gnus-newsgroup-processable)
5135 gnus-newsgroup-process-stack))
5136
5137(defun gnus-summary-kill-process-mark ()
5138 "Push the current set of process marked articles on the stack and unmark."
5139 (interactive)
5140 (gnus-summary-save-process-mark)
5141 (gnus-summary-unmark-all-processable))
5142
5143(defun gnus-summary-yank-process-mark ()
5144 "Pop the last process mark state off the stack and restore it."
5145 (interactive)
5146 (unless gnus-newsgroup-process-stack
5147 (error "Empty mark stack"))
5148 (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5149
5150(defun gnus-summary-process-mark-set (set)
5151 "Make SET into the current process marked articles."
5152 (gnus-summary-unmark-all-processable)
5153 (while set
5154 (gnus-summary-set-process-mark (pop set))))
5155
5156;;; Searching and stuff
5157
5158(defun gnus-summary-search-group (&optional backward use-level)
5159 "Search for next unread newsgroup.
5160If optional argument BACKWARD is non-nil, search backward instead."
5161 (save-excursion
5162 (set-buffer gnus-group-buffer)
5163 (when (gnus-group-search-forward
5164 backward nil (if use-level (gnus-group-group-level) nil))
5165 (gnus-group-group-name))))
5166
5167(defun gnus-summary-best-group (&optional exclude-group)
5168 "Find the name of the best unread group.
5169If EXCLUDE-GROUP, do not go to this group."
5170 (save-excursion
5171 (set-buffer gnus-group-buffer)
5172 (save-excursion
5173 (gnus-group-best-unread-group exclude-group))))
5174
6748645f 5175(defun gnus-summary-find-next (&optional unread article backward undownloaded)
eec82323
LMI
5176 (if backward (gnus-summary-find-prev)
5177 (let* ((dummy (gnus-summary-article-intangible-p))
5178 (article (or article (gnus-summary-article-number)))
5179 (arts (gnus-data-find-list article))
5180 result)
5181 (when (and (not dummy)
5182 (or (not gnus-summary-check-current)
5183 (not unread)
5184 (not (gnus-data-unread-p (car arts)))))
5185 (setq arts (cdr arts)))
5186 (when (setq result
5187 (if unread
5188 (progn
5189 (while arts
6748645f
LMI
5190 (when (or (and undownloaded
5191 (eq gnus-undownloaded-mark
5192 (gnus-data-mark (car arts))))
5193 (gnus-data-unread-p (car arts)))
eec82323
LMI
5194 (setq result (car arts)
5195 arts nil))
5196 (setq arts (cdr arts)))
5197 result)
5198 (car arts)))
5199 (goto-char (gnus-data-pos result))
5200 (gnus-data-number result)))))
5201
5202(defun gnus-summary-find-prev (&optional unread article)
5203 (let* ((eobp (eobp))
5204 (article (or article (gnus-summary-article-number)))
5205 (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5206 result)
5207 (when (and (not eobp)
5208 (or (not gnus-summary-check-current)
5209 (not unread)
5210 (not (gnus-data-unread-p (car arts)))))
5211 (setq arts (cdr arts)))
5212 (when (setq result
5213 (if unread
5214 (progn
5215 (while arts
5216 (when (gnus-data-unread-p (car arts))
5217 (setq result (car arts)
5218 arts nil))
5219 (setq arts (cdr arts)))
5220 result)
5221 (car arts)))
5222 (goto-char (gnus-data-pos result))
5223 (gnus-data-number result))))
5224
5225(defun gnus-summary-find-subject (subject &optional unread backward article)
5226 (let* ((simp-subject (gnus-simplify-subject-fully subject))
5227 (article (or article (gnus-summary-article-number)))
5228 (articles (gnus-data-list backward))
5229 (arts (gnus-data-find-list article articles))
5230 result)
5231 (when (or (not gnus-summary-check-current)
5232 (not unread)
5233 (not (gnus-data-unread-p (car arts))))
5234 (setq arts (cdr arts)))
5235 (while arts
5236 (and (or (not unread)
5237 (gnus-data-unread-p (car arts)))
5238 (vectorp (gnus-data-header (car arts)))
5239 (gnus-subject-equal
5240 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5241 (setq result (car arts)
5242 arts nil))
5243 (setq arts (cdr arts)))
5244 (and result
5245 (goto-char (gnus-data-pos result))
5246 (gnus-data-number result))))
5247
5248(defun gnus-summary-search-forward (&optional unread subject backward)
5249 "Search forward for an article.
5250If UNREAD, look for unread articles. If SUBJECT, look for
5251articles with that subject. If BACKWARD, search backward instead."
5252 (cond (subject (gnus-summary-find-subject subject unread backward))
5253 (backward (gnus-summary-find-prev unread))
5254 (t (gnus-summary-find-next unread))))
5255
5256(defun gnus-recenter (&optional n)
5257 "Center point in window and redisplay frame.
5258Also do horizontal recentering."
5259 (interactive "P")
5260 (when (and gnus-auto-center-summary
5261 (not (eq gnus-auto-center-summary 'vertical)))
5262 (gnus-horizontal-recenter))
5263 (recenter n))
5264
5265(defun gnus-summary-recenter ()
5266 "Center point in the summary window.
5267If `gnus-auto-center-summary' is nil, or the article buffer isn't
5268displayed, no centering will be performed."
5269 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5270 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
16409b0b 5271 (interactive)
eec82323
LMI
5272 (let* ((top (cond ((< (window-height) 4) 0)
5273 ((< (window-height) 7) 1)
16409b0b
GM
5274 (t (if (numberp gnus-auto-center-summary)
5275 gnus-auto-center-summary
5276 2))))
eec82323
LMI
5277 (height (1- (window-height)))
5278 (bottom (save-excursion (goto-char (point-max))
5279 (forward-line (- height))
5280 (point)))
5281 (window (get-buffer-window (current-buffer))))
5282 ;; The user has to want it.
5283 (when gnus-auto-center-summary
5284 (when (get-buffer-window gnus-article-buffer)
5285 ;; Only do recentering when the article buffer is displayed,
5286 ;; Set the window start to either `bottom', which is the biggest
5287 ;; possible valid number, or the second line from the top,
5288 ;; whichever is the least.
db7ebd73
MB
5289 (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5290 (if (> bottom top-pos)
5291 ;; Keep the second line from the top visible
5292 (set-window-start window top-pos t)
5293 ;; Try to keep the bottom line visible; if it's partially
5294 ;; obscured, either scroll one more line to make it fully
5295 ;; visible, or revert to using TOP-POS.
5296 (save-excursion
5297 (goto-char (point-max))
5298 (forward-line -1)
5299 (let ((last-line-start (point)))
5300 (goto-char bottom)
5301 (set-window-start window (point) t)
5302 (when (not (pos-visible-in-window-p last-line-start window))
5303 (forward-line 1)
5304 (set-window-start window (min (point) top-pos) t)))))))
eec82323
LMI
5305 ;; Do horizontal recentering while we're at it.
5306 (when (and (get-buffer-window (current-buffer) t)
5307 (not (eq gnus-auto-center-summary 'vertical)))
5308 (let ((selected (selected-window)))
5309 (select-window (get-buffer-window (current-buffer) t))
5310 (gnus-summary-position-point)
5311 (gnus-horizontal-recenter)
5312 (select-window selected))))))
5313
5314(defun gnus-summary-jump-to-group (newsgroup)
5315 "Move point to NEWSGROUP in group mode buffer."
5316 ;; Keep update point of group mode buffer if visible.
5317 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5318 (save-window-excursion
5319 ;; Take care of tree window mode.
5320 (when (get-buffer-window gnus-group-buffer)
5321 (pop-to-buffer gnus-group-buffer))
5322 (gnus-group-jump-to-group newsgroup))
5323 (save-excursion
5324 ;; Take care of tree window mode.
5325 (if (get-buffer-window gnus-group-buffer)
5326 (pop-to-buffer gnus-group-buffer)
5327 (set-buffer gnus-group-buffer))
5328 (gnus-group-jump-to-group newsgroup))))
5329
5330;; This function returns a list of article numbers based on the
5331;; difference between the ranges of read articles in this group and
5332;; the range of active articles.
5333(defun gnus-list-of-unread-articles (group)
5334 (let* ((read (gnus-info-read (gnus-get-info group)))
5335 (active (or (gnus-active group) (gnus-activate-group group)))
5336 (last (cdr active))
5337 first nlast unread)
5338 ;; If none are read, then all are unread.
5339 (if (not read)
5340 (setq first (car active))
5341 ;; If the range of read articles is a single range, then the
5342 ;; first unread article is the article after the last read
5343 ;; article. Sounds logical, doesn't it?
16409b0b
GM
5344 (if (and (not (listp (cdr read)))
5345 (or (< (car read) (car active))
5346 (progn (setq read (list read))
5347 nil)))
6748645f 5348 (setq first (max (car active) (1+ (cdr read))))
eec82323
LMI
5349 ;; `read' is a list of ranges.
5350 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5351 (caar read)))
5352 1)
6748645f 5353 (setq first (car active)))
eec82323
LMI
5354 (while read
5355 (when first
5356 (while (< first nlast)
5357 (push first unread)
5358 (setq first (1+ first))))
5359 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5360 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5361 (setq read (cdr read)))))
5362 ;; And add the last unread articles.
5363 (while (<= first last)
5364 (push first unread)
5365 (setq first (1+ first)))
5366 ;; Return the list of unread articles.
6748645f 5367 (delq 0 (nreverse unread))))
eec82323
LMI
5368
5369(defun gnus-list-of-read-articles (group)
5370 "Return a list of unread, unticked and non-dormant articles."
5371 (let* ((info (gnus-get-info group))
5372 (marked (gnus-info-marks info))
5373 (active (gnus-active group)))
5374 (and info active
5375 (gnus-set-difference
5376 (gnus-sorted-complement
5377 (gnus-uncompress-range active)
5378 (gnus-list-of-unread-articles group))
5379 (append
5380 (gnus-uncompress-range (cdr (assq 'dormant marked)))
5381 (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5382
5383;; Various summary commands
5384
6748645f
LMI
5385(defun gnus-summary-select-article-buffer ()
5386 "Reconfigure windows to show article buffer."
5387 (interactive)
5388 (if (not (gnus-buffer-live-p gnus-article-buffer))
5389 (error "There is no article buffer for this summary buffer")
5390 (gnus-configure-windows 'article)
5391 (select-window (get-buffer-window gnus-article-buffer))))
5392
eec82323
LMI
5393(defun gnus-summary-universal-argument (arg)
5394 "Perform any operation on all articles that are process/prefixed."
5395 (interactive "P")
eec82323
LMI
5396 (let ((articles (gnus-summary-work-articles arg))
5397 func article)
5398 (if (eq
5399 (setq
5400 func
5401 (key-binding
5402 (read-key-sequence
5403 (substitute-command-keys
16409b0b 5404 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
eec82323
LMI
5405 'undefined)
5406 (gnus-error 1 "Undefined key")
5407 (save-excursion
5408 (while articles
5409 (gnus-summary-goto-subject (setq article (pop articles)))
5410 (let (gnus-newsgroup-processable)
5411 (command-execute func))
5412 (gnus-summary-remove-process-mark article)))))
5413 (gnus-summary-position-point))
5414
5415(defun gnus-summary-toggle-truncation (&optional arg)
5416 "Toggle truncation of summary lines.
5417With arg, turn line truncation on iff arg is positive."
5418 (interactive "P")
5419 (setq truncate-lines
5420 (if (null arg) (not truncate-lines)
5421 (> (prefix-numeric-value arg) 0)))
5422 (redraw-display))
5423
5424(defun gnus-summary-reselect-current-group (&optional all rescan)
5425 "Exit and then reselect the current newsgroup.
5426The prefix argument ALL means to select all articles."
5427 (interactive "P")
eec82323
LMI
5428 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5429 (error "Ephemeral groups can't be reselected"))
5430 (let ((current-subject (gnus-summary-article-number))
5431 (group gnus-newsgroup-name))
5432 (setq gnus-newsgroup-begin nil)
5433 (gnus-summary-exit)
5434 ;; We have to adjust the point of group mode buffer because
5435 ;; point was moved to the next unread newsgroup by exiting.
5436 (gnus-summary-jump-to-group group)
5437 (when rescan
5438 (save-excursion
5439 (gnus-group-get-new-news-this-group 1)))
5440 (gnus-group-read-group all t)
5441 (gnus-summary-goto-subject current-subject nil t)))
5442
5443(defun gnus-summary-rescan-group (&optional all)
5444 "Exit the newsgroup, ask for new articles, and select the newsgroup."
5445 (interactive "P")
5446 (gnus-summary-reselect-current-group all t))
5447
5448(defun gnus-summary-update-info (&optional non-destructive)
5449 (save-excursion
5450 (let ((group gnus-newsgroup-name))
6748645f
LMI
5451 (when group
5452 (when gnus-newsgroup-kill-headers
5453 (setq gnus-newsgroup-killed
5454 (gnus-compress-sequence
5455 (nconc
5456 (gnus-set-sorted-intersection
5457 (gnus-uncompress-range gnus-newsgroup-killed)
5458 (setq gnus-newsgroup-unselected
5459 (sort gnus-newsgroup-unselected '<)))
5460 (setq gnus-newsgroup-unreads
5461 (sort gnus-newsgroup-unreads '<)))
5462 t)))
5463 (unless (listp (cdr gnus-newsgroup-killed))
5464 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5465 (let ((headers gnus-newsgroup-headers))
5466 ;; Set the new ranges of read articles.
5467 (save-excursion
5468 (set-buffer gnus-group-buffer)
5469 (gnus-undo-force-boundary))
5470 (gnus-update-read-articles
5471 group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5472 ;; Set the current article marks.
5473 (let ((gnus-newsgroup-scored
5474 (if (and (not gnus-save-score)
5475 (not non-destructive))
5476 nil
5477 gnus-newsgroup-scored)))
5478 (save-excursion
5479 (gnus-update-marks)))
5480 ;; Do the cross-ref thing.
5481 (when gnus-use-cross-reference
5482 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5483 ;; Do not switch windows but change the buffer to work.
a8151ef7 5484 (set-buffer gnus-group-buffer)
6748645f
LMI
5485 (unless (gnus-ephemeral-group-p group)
5486 (gnus-group-update-group group)))))))
eec82323
LMI
5487
5488(defun gnus-summary-save-newsrc (&optional force)
5489 "Save the current number of read/marked articles in the dribble buffer.
5490The dribble buffer will then be saved.
5491If FORCE (the prefix), also save the .newsrc file(s)."
5492 (interactive "P")
5493 (gnus-summary-update-info t)
5494 (if force
5495 (gnus-save-newsrc-file)
5496 (gnus-dribble-save)))
5497
5498(defun gnus-summary-exit (&optional temporary)
5499 "Exit reading current newsgroup, and then return to group selection mode.
16409b0b 5500`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
eec82323
LMI
5501 (interactive)
5502 (gnus-set-global-variables)
16409b0b
GM
5503 (when (gnus-buffer-live-p gnus-article-buffer)
5504 (save-excursion
5505 (set-buffer gnus-article-buffer)
5506 (mm-destroy-parts gnus-article-mime-handles)
5507 ;; Set it to nil for safety reason.
5508 (setq gnus-article-mime-handle-alist nil)
5509 (setq gnus-article-mime-handles nil)))
eec82323 5510 (gnus-kill-save-kill-buffer)
6748645f 5511 (gnus-async-halt-prefetch)
eec82323
LMI
5512 (let* ((group gnus-newsgroup-name)
5513 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5514 (mode major-mode)
a8151ef7 5515 (group-point nil)
eec82323 5516 (buf (current-buffer)))
16409b0b
GM
5517 (unless quit-config
5518 ;; Do adaptive scoring, and possibly save score files.
5519 (when gnus-newsgroup-adaptive
5520 (gnus-score-adaptive))
5521 (when gnus-use-scoring
5522 (gnus-score-save)))
6748645f 5523 (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
eec82323
LMI
5524 ;; If we have several article buffers, we kill them at exit.
5525 (unless gnus-single-article-buffer
5526 (gnus-kill-buffer gnus-original-article-buffer)
5527 (setq gnus-article-current nil))
5528 (when gnus-use-cache
5529 (gnus-cache-possibly-remove-articles)
5530 (gnus-cache-save-buffers))
5531 (gnus-async-prefetch-remove-group group)
5532 (when gnus-suppress-duplicates
5533 (gnus-dup-enter-articles))
5534 (when gnus-use-trees
5535 (gnus-tree-close group))
16409b0b
GM
5536 (when gnus-use-cache
5537 (gnus-cache-write-active))
6748645f
LMI
5538 ;; Remove entries for this group.
5539 (nnmail-purge-split-history (gnus-group-real-name group))
eec82323
LMI
5540 ;; Make all changes in this group permanent.
5541 (unless quit-config
6748645f 5542 (gnus-run-hooks 'gnus-exit-group-hook)
16409b0b 5543 (gnus-summary-update-info))
eec82323
LMI
5544 (gnus-close-group group)
5545 ;; Make sure where we were, and go to next newsgroup.
5546 (set-buffer gnus-group-buffer)
5547 (unless quit-config
5548 (gnus-group-jump-to-group group))
6748645f
LMI
5549 (gnus-run-hooks 'gnus-summary-exit-hook)
5550 (unless (or quit-config
5551 ;; If this group has disappeared from the summary
5552 ;; buffer, don't skip forwards.
5553 (not (string= group (gnus-group-group-name))))
eec82323 5554 (gnus-group-next-unread-group 1))
a8151ef7 5555 (setq group-point (point))
eec82323
LMI
5556 (if temporary
5557 nil ;Nothing to do.
5558 ;; If we have several article buffers, we kill them at exit.
5559 (unless gnus-single-article-buffer
5560 (gnus-kill-buffer gnus-article-buffer)
5561 (gnus-kill-buffer gnus-original-article-buffer)
5562 (setq gnus-article-current nil))
5563 (set-buffer buf)
5564 (if (not gnus-kill-summary-on-exit)
5565 (gnus-deaden-summary)
5566 ;; We set all buffer-local variables to nil. It is unclear why
5567 ;; this is needed, but if we don't, buffer-local variables are
5568 ;; not garbage-collected, it seems. This would the lead to en
5569 ;; ever-growing Emacs.
5570 (gnus-summary-clear-local-variables)
5571 (when (get-buffer gnus-article-buffer)
5572 (bury-buffer gnus-article-buffer))
5573 ;; We clear the global counterparts of the buffer-local
5574 ;; variables as well, just to be on the safe side.
5575 (set-buffer gnus-group-buffer)
5576 (gnus-summary-clear-local-variables)
5577 ;; Return to group mode buffer.
5578 (when (eq mode 'gnus-summary-mode)
5579 (gnus-kill-buffer buf)))
5580 (setq gnus-current-select-method gnus-select-method)
5581 (pop-to-buffer gnus-group-buffer)
eec82323
LMI
5582 (if (not quit-config)
5583 (progn
a8151ef7 5584 (goto-char group-point)
eec82323
LMI
5585 (gnus-configure-windows 'group 'force))
5586 (gnus-handle-ephemeral-exit quit-config))
6748645f 5587 ;; Clear the current group name.
eec82323
LMI
5588 (unless quit-config
5589 (setq gnus-newsgroup-name nil)))))
5590
5591(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5592(defun gnus-summary-exit-no-update (&optional no-questions)
5593 "Quit reading current newsgroup without updating read article info."
5594 (interactive)
eec82323
LMI
5595 (let* ((group gnus-newsgroup-name)
5596 (quit-config (gnus-group-quit-config group)))
5597 (when (or no-questions
5598 gnus-expert-user
5599 (gnus-y-or-n-p "Discard changes to this group and exit? "))
6748645f 5600 (gnus-async-halt-prefetch)
16409b0b
GM
5601 (mapcar 'funcall
5602 (delq 'gnus-summary-expire-articles
5603 (copy-sequence gnus-summary-prepare-exit-hook)))
5604 (when (gnus-buffer-live-p gnus-article-buffer)
5605 (save-excursion
5606 (set-buffer gnus-article-buffer)
5607 (mm-destroy-parts gnus-article-mime-handles)
5608 ;; Set it to nil for safety reason.
5609 (setq gnus-article-mime-handle-alist nil)
5610 (setq gnus-article-mime-handles nil)))
eec82323
LMI
5611 ;; If we have several article buffers, we kill them at exit.
5612 (unless gnus-single-article-buffer
5613 (gnus-kill-buffer gnus-article-buffer)
5614 (gnus-kill-buffer gnus-original-article-buffer)
5615 (setq gnus-article-current nil))
5616 (if (not gnus-kill-summary-on-exit)
5617 (gnus-deaden-summary)
5618 (gnus-close-group group)
5619 (gnus-summary-clear-local-variables)
5620 (set-buffer gnus-group-buffer)
5621 (gnus-summary-clear-local-variables)
5622 (when (get-buffer gnus-summary-buffer)
5623 (kill-buffer gnus-summary-buffer)))
5624 (unless gnus-single-article-buffer
5625 (setq gnus-article-current nil))
5626 (when gnus-use-trees
5627 (gnus-tree-close group))
5628 (gnus-async-prefetch-remove-group group)
5629 (when (get-buffer gnus-article-buffer)
5630 (bury-buffer gnus-article-buffer))
5631 ;; Return to the group buffer.
5632 (gnus-configure-windows 'group 'force)
5633 ;; Clear the current group name.
5634 (setq gnus-newsgroup-name nil)
5635 (when (equal (gnus-group-group-name) group)
5636 (gnus-group-next-unread-group 1))
5637 (when quit-config
5638 (gnus-handle-ephemeral-exit quit-config)))))
5639
5640(defun gnus-handle-ephemeral-exit (quit-config)
6748645f
LMI
5641 "Handle movement when leaving an ephemeral group.
5642The state which existed when entering the ephemeral is reset."
eec82323
LMI
5643 (if (not (buffer-name (car quit-config)))
5644 (gnus-configure-windows 'group 'force)
5645 (set-buffer (car quit-config))
5646 (cond ((eq major-mode 'gnus-summary-mode)
5647 (gnus-set-global-variables))
5648 ((eq major-mode 'gnus-article-mode)
5649 (save-excursion
5650 ;; The `gnus-summary-buffer' variable may point
5651 ;; to the old summary buffer when using a single
5652 ;; article buffer.
5653 (unless (gnus-buffer-live-p gnus-summary-buffer)
5654 (set-buffer gnus-group-buffer))
5655 (set-buffer gnus-summary-buffer)
5656 (gnus-set-global-variables))))
5657 (if (or (eq (cdr quit-config) 'article)
5658 (eq (cdr quit-config) 'pick))
5659 (progn
5660 ;; The current article may be from the ephemeral group
5661 ;; thus it is best that we reload this article
5662 (gnus-summary-show-article)
5663 (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5664 (gnus-configure-windows 'pick 'force)
5665 (gnus-configure-windows (cdr quit-config) 'force)))
5666 (gnus-configure-windows (cdr quit-config) 'force))
5667 (when (eq major-mode 'gnus-summary-mode)
5668 (gnus-summary-next-subject 1 nil t)
5669 (gnus-summary-recenter)
5670 (gnus-summary-position-point))))
5671
5672;;; Dead summaries.
5673
5674(defvar gnus-dead-summary-mode-map nil)
5675
5676(unless gnus-dead-summary-mode-map
5677 (setq gnus-dead-summary-mode-map (make-keymap))
5678 (suppress-keymap gnus-dead-summary-mode-map)
5679 (substitute-key-definition
5680 'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
a8151ef7 5681 (let ((keys '("\C-d" "\r" "\177" [delete])))
eec82323
LMI
5682 (while keys
5683 (define-key gnus-dead-summary-mode-map
5684 (pop keys) 'gnus-summary-wake-up-the-dead))))
5685
5686(defvar gnus-dead-summary-mode nil
5687 "Minor mode for Gnus summary buffers.")
5688
5689(defun gnus-dead-summary-mode (&optional arg)
5690 "Minor mode for Gnus summary buffers."
5691 (interactive "P")
5692 (when (eq major-mode 'gnus-summary-mode)
5693 (make-local-variable 'gnus-dead-summary-mode)
5694 (setq gnus-dead-summary-mode
5695 (if (null arg) (not gnus-dead-summary-mode)
5696 (> (prefix-numeric-value arg) 0)))
5697 (when gnus-dead-summary-mode
a8151ef7
LMI
5698 (gnus-add-minor-mode
5699 'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
eec82323
LMI
5700
5701(defun gnus-deaden-summary ()
5702 "Make the current summary buffer into a dead summary buffer."
5703 ;; Kill any previous dead summary buffer.
5704 (when (and gnus-dead-summary
5705 (buffer-name gnus-dead-summary))
5706 (save-excursion
5707 (set-buffer gnus-dead-summary)
5708 (when gnus-dead-summary-mode
5709 (kill-buffer (current-buffer)))))
5710 ;; Make this the current dead summary.
5711 (setq gnus-dead-summary (current-buffer))
5712 (gnus-dead-summary-mode 1)
5713 (let ((name (buffer-name)))
5714 (when (string-match "Summary" name)
5715 (rename-buffer
5716 (concat (substring name 0 (match-beginning 0)) "Dead "
5717 (substring name (match-beginning 0)))
16409b0b
GM
5718 t)
5719 (bury-buffer))))
eec82323
LMI
5720
5721(defun gnus-kill-or-deaden-summary (buffer)
5722 "Kill or deaden the summary BUFFER."
6748645f
LMI
5723 (save-excursion
5724 (when (and (buffer-name buffer)
5725 (not gnus-single-article-buffer))
5726 (save-excursion
5727 (set-buffer buffer)
5728 (gnus-kill-buffer gnus-article-buffer)
5729 (gnus-kill-buffer gnus-original-article-buffer)))
5730 (cond (gnus-kill-summary-on-exit
5731 (when (and gnus-use-trees
5732 (gnus-buffer-exists-p buffer))
5733 (save-excursion
5734 (set-buffer buffer)
5735 (gnus-tree-close gnus-newsgroup-name)))
5736 (gnus-kill-buffer buffer))
5737 ((gnus-buffer-exists-p buffer)
eec82323 5738 (save-excursion
6748645f
LMI
5739 (set-buffer buffer)
5740 (gnus-deaden-summary))))))
eec82323
LMI
5741
5742(defun gnus-summary-wake-up-the-dead (&rest args)
5743 "Wake up the dead summary buffer."
5744 (interactive)
5745 (gnus-dead-summary-mode -1)
5746 (let ((name (buffer-name)))
5747 (when (string-match "Dead " name)
5748 (rename-buffer
5749 (concat (substring name 0 (match-beginning 0))
5750 (substring name (match-end 0)))
5751 t)))
5752 (gnus-message 3 "This dead summary is now alive again"))
5753
5754;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5755(defun gnus-summary-fetch-faq (&optional faq-dir)
5756 "Fetch the FAQ for the current group.
5757If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5758in."
5759 (interactive
5760 (list
5761 (when current-prefix-arg
5762 (completing-read
5763 "Faq dir: " (and (listp gnus-group-faq-directory)
a8151ef7
LMI
5764 (mapcar (lambda (file) (list file))
5765 gnus-group-faq-directory))))))
eec82323
LMI
5766 (let (gnus-faq-buffer)
5767 (when (setq gnus-faq-buffer
5768 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5769 (gnus-configure-windows 'summary-faq))))
5770
5771;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5772(defun gnus-summary-describe-group (&optional force)
5773 "Describe the current newsgroup."
5774 (interactive "P")
5775 (gnus-group-describe-group force gnus-newsgroup-name))
5776
5777(defun gnus-summary-describe-briefly ()
5778 "Describe summary mode commands briefly."
5779 (interactive)
16409b0b 5780 (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select \\[gnus-summary-next-unread-article]:Forward \\[gnus-summary-prev-unread-article]:Backward \\[gnus-summary-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-summary-describe-briefly]:This help")))
eec82323
LMI
5781
5782;; Walking around group mode buffer from summary mode.
5783
5784(defun gnus-summary-next-group (&optional no-article target-group backward)
5785 "Exit current newsgroup and then select next unread newsgroup.
5786If prefix argument NO-ARTICLE is non-nil, no article is selected
5787initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
5788previous group instead."
5789 (interactive "P")
eec82323
LMI
5790 ;; Stop pre-fetching.
5791 (gnus-async-halt-prefetch)
5792 (let ((current-group gnus-newsgroup-name)
5793 (current-buffer (current-buffer))
5794 entered)
5795 ;; First we semi-exit this group to update Xrefs and all variables.
5796 ;; We can't do a real exit, because the window conf must remain
5797 ;; the same in case the user is prompted for info, and we don't
5798 ;; want the window conf to change before that...
5799 (gnus-summary-exit t)
5800 (while (not entered)
5801 ;; Then we find what group we are supposed to enter.
5802 (set-buffer gnus-group-buffer)
5803 (gnus-group-jump-to-group current-group)
5804 (setq target-group
5805 (or target-group
5806 (if (eq gnus-keep-same-level 'best)
5807 (gnus-summary-best-group gnus-newsgroup-name)
5808 (gnus-summary-search-group backward gnus-keep-same-level))))
5809 (if (not target-group)
5810 ;; There are no further groups, so we return to the group
5811 ;; buffer.
5812 (progn
5813 (gnus-message 5 "Returning to the group buffer")
5814 (setq entered t)
5815 (when (gnus-buffer-live-p current-buffer)
5816 (set-buffer current-buffer)
5817 (gnus-summary-exit))
6748645f 5818 (gnus-run-hooks 'gnus-group-no-more-groups-hook))
eec82323
LMI
5819 ;; We try to enter the target group.
5820 (gnus-group-jump-to-group target-group)
5821 (let ((unreads (gnus-group-group-unread)))
5822 (if (and (or (eq t unreads)
5823 (and unreads (not (zerop unreads))))
5824 (gnus-summary-read-group
a8151ef7 5825 target-group nil no-article
6748645f
LMI
5826 (and (buffer-name current-buffer) current-buffer)
5827 nil backward))
eec82323
LMI
5828 (setq entered t)
5829 (setq current-group target-group
5830 target-group nil)))))))
5831
5832(defun gnus-summary-prev-group (&optional no-article)
5833 "Exit current newsgroup and then select previous unread newsgroup.
5834If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5835 (interactive "P")
5836 (gnus-summary-next-group no-article nil t))
5837
5838;; Walking around summary lines.
5839
6748645f 5840(defun gnus-summary-first-subject (&optional unread undownloaded)
eec82323
LMI
5841 "Go to the first unread subject.
5842If UNREAD is non-nil, go to the first unread article.
5843Returns the article selected or nil if there are no unread articles."
5844 (interactive "P")
5845 (prog1
5846 (cond
5847 ;; Empty summary.
5848 ((null gnus-newsgroup-data)
5849 (gnus-message 3 "No articles in the group")
5850 nil)
5851 ;; Pick the first article.
5852 ((not unread)
5853 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5854 (gnus-data-number (car gnus-newsgroup-data)))
5855 ;; No unread articles.
5856 ((null gnus-newsgroup-unreads)
5857 (gnus-message 3 "No more unread articles")
5858 nil)
5859 ;; Find the first unread article.
5860 (t
5861 (let ((data gnus-newsgroup-data))
5862 (while (and data
6748645f
LMI
5863 (and (not (and undownloaded
5864 (eq gnus-undownloaded-mark
5865 (gnus-data-mark (car data)))))
5866 (not (gnus-data-unread-p (car data)))))
eec82323
LMI
5867 (setq data (cdr data)))
5868 (when data
5869 (goto-char (gnus-data-pos (car data)))
5870 (gnus-data-number (car data))))))
5871 (gnus-summary-position-point)))
5872
5873(defun gnus-summary-next-subject (n &optional unread dont-display)
5874 "Go to next N'th summary line.
5875If N is negative, go to the previous N'th subject line.
5876If UNREAD is non-nil, only unread articles are selected.
5877The difference between N and the actual number of steps taken is
5878returned."
5879 (interactive "p")
5880 (let ((backward (< n 0))
5881 (n (abs n)))
5882 (while (and (> n 0)
5883 (if backward
5884 (gnus-summary-find-prev unread)
5885 (gnus-summary-find-next unread)))
16409b0b
GM
5886 (unless (zerop (setq n (1- n)))
5887 (gnus-summary-show-thread)))
eec82323
LMI
5888 (when (/= 0 n)
5889 (gnus-message 7 "No more%s articles"
5890 (if unread " unread" "")))
5891 (unless dont-display
5892 (gnus-summary-recenter)
5893 (gnus-summary-position-point))
5894 n))
5895
5896(defun gnus-summary-next-unread-subject (n)
5897 "Go to next N'th unread summary line."
5898 (interactive "p")
5899 (gnus-summary-next-subject n t))
5900
5901(defun gnus-summary-prev-subject (n &optional unread)
5902 "Go to previous N'th summary line.
5903If optional argument UNREAD is non-nil, only unread article is selected."
5904 (interactive "p")
5905 (gnus-summary-next-subject (- n) unread))
5906
5907(defun gnus-summary-prev-unread-subject (n)
5908 "Go to previous N'th unread summary line."
5909 (interactive "p")
5910 (gnus-summary-next-subject (- n) t))
5911
5912(defun gnus-summary-goto-subject (article &optional force silent)
5913 "Go the subject line of ARTICLE.
5914If FORCE, also allow jumping to articles not currently shown."
5915 (interactive "nArticle number: ")
5916 (let ((b (point))
5917 (data (gnus-data-find article)))
5918 ;; We read in the article if we have to.
5919 (and (not data)
5920 force
6748645f
LMI
5921 (gnus-summary-insert-subject
5922 article
5923 (if (or (numberp force) (vectorp force)) force)
5924 t)
eec82323
LMI
5925 (setq data (gnus-data-find article)))
5926 (goto-char b)
5927 (if (not data)
5928 (progn
5929 (unless silent
5930 (gnus-message 3 "Can't find article %d" article))
5931 nil)
5932 (goto-char (gnus-data-pos data))
6748645f 5933 (gnus-summary-position-point)
eec82323
LMI
5934 article)))
5935
5936;; Walking around summary lines with displaying articles.
5937
5938(defun gnus-summary-expand-window (&optional arg)
5939 "Make the summary buffer take up the entire Emacs frame.
5940Given a prefix, will force an `article' buffer configuration."
5941 (interactive "P")
eec82323
LMI
5942 (if arg
5943 (gnus-configure-windows 'article 'force)
5944 (gnus-configure-windows 'summary 'force)))
5945
5946(defun gnus-summary-display-article (article &optional all-header)
5947 "Display ARTICLE in article buffer."
d4dfaa19
DL
5948 (when (gnus-buffer-live-p gnus-article-buffer)
5949 (with-current-buffer gnus-article-buffer
5950 (mm-enable-multibyte-mule4)))
eec82323
LMI
5951 (gnus-set-global-variables)
5952 (if (null article)
5953 nil
5954 (prog1
5955 (if gnus-summary-display-article-function
5956 (funcall gnus-summary-display-article-function article all-header)
5957 (gnus-article-prepare article all-header))
6748645f 5958 (gnus-run-hooks 'gnus-select-article-hook)
eec82323
LMI
5959 (when (and gnus-current-article
5960 (not (zerop gnus-current-article)))
5961 (gnus-summary-goto-subject gnus-current-article))
5962 (gnus-summary-recenter)
5963 (when (and gnus-use-trees gnus-show-threads)
5964 (gnus-possibly-generate-tree article)
5965 (gnus-highlight-selected-tree article))
5966 ;; Successfully display article.
5967 (gnus-article-set-window-start
5968 (cdr (assq article gnus-newsgroup-bookmarks))))))
5969
5970(defun gnus-summary-select-article (&optional all-headers force pseudo article)
5971 "Select the current article.
5972If ALL-HEADERS is non-nil, show all header fields. If FORCE is
5973non-nil, the article will be re-fetched even if it already present in
5974the article buffer. If PSEUDO is non-nil, pseudo-articles will also
5975be displayed."
5976 ;; Make sure we are in the summary buffer to work around bbdb bug.
5977 (unless (eq major-mode 'gnus-summary-mode)
5978 (set-buffer gnus-summary-buffer))
5979 (let ((article (or article (gnus-summary-article-number)))
f0529b5b 5980 (all-headers (not (not all-headers))) ;Must be t or nil.
16409b0b 5981 gnus-summary-display-article-function)
eec82323
LMI
5982 (and (not pseudo)
5983 (gnus-summary-article-pseudo-p article)
a8151ef7 5984 (error "This is a pseudo-article"))
16409b0b
GM
5985 (save-excursion
5986 (set-buffer gnus-summary-buffer)
5987 (if (or (and gnus-single-article-buffer
5988 (or (null gnus-current-article)
5989 (null gnus-article-current)
5990 (null (get-buffer gnus-article-buffer))
5991 (not (eq article (cdr gnus-article-current)))
5992 (not (equal (car gnus-article-current)
5993 gnus-newsgroup-name))))
5994 (and (not gnus-single-article-buffer)
5995 (or (null gnus-current-article)
5996 (not (eq gnus-current-article article))))
5997 force)
5998 ;; The requested article is different from the current article.
5999 (progn
16409b0b
GM
6000 (gnus-summary-display-article article all-headers)
6001 (when (gnus-buffer-live-p gnus-article-buffer)
d4dfaa19 6002 (with-current-buffer gnus-article-buffer
16409b0b 6003 (if (not gnus-article-decoded-p) ;; a local variable
d4dfaa19 6004 (mm-disable-multibyte-mule4))))
eec82323
LMI
6005 (when (or all-headers gnus-show-all-headers)
6006 (gnus-article-show-all-headers))
16409b0b
GM
6007 (gnus-article-set-window-start
6008 (cdr (assq article gnus-newsgroup-bookmarks)))
6009 article)
6010 (when (or all-headers gnus-show-all-headers)
6011 (gnus-article-show-all-headers))
6012 'old))))
eec82323
LMI
6013
6014(defun gnus-summary-set-current-mark (&optional current-mark)
6015 "Obsolete function."
6016 nil)
6017
6018(defun gnus-summary-next-article (&optional unread subject backward push)
6019 "Select the next article.
6020If UNREAD, only unread articles are selected.
6021If SUBJECT, only articles with SUBJECT are selected.
6022If BACKWARD, the previous article is selected instead of the next."
6023 (interactive "P")
eec82323
LMI
6024 (cond
6025 ;; Is there such an article?
6026 ((and (gnus-summary-search-forward unread subject backward)
6027 (or (gnus-summary-display-article (gnus-summary-article-number))
6028 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6029 (gnus-summary-position-point))
6030 ;; If not, we try the first unread, if that is wanted.
6031 ((and subject
6032 gnus-auto-select-same
6033 (gnus-summary-first-unread-article))
6034 (gnus-summary-position-point)
6035 (gnus-message 6 "Wrapped"))
6036 ;; Try to get next/previous article not displayed in this group.
6037 ((and gnus-auto-extend-newsgroup
6038 (not unread) (not subject))
6039 (gnus-summary-goto-article
6040 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748645f 6041 nil (count-lines (point-min) (point))))
eec82323
LMI
6042 ;; Go to next/previous group.
6043 (t
6044 (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6045 (gnus-summary-jump-to-group gnus-newsgroup-name))
6046 (let ((cmd last-command-char)
6047 (point
6048 (save-excursion
6049 (set-buffer gnus-group-buffer)
6050 (point)))
6051 (group
6052 (if (eq gnus-keep-same-level 'best)
6053 (gnus-summary-best-group gnus-newsgroup-name)
6054 (gnus-summary-search-group backward gnus-keep-same-level))))
6055 ;; For some reason, the group window gets selected. We change
6056 ;; it back.
6057 (select-window (get-buffer-window (current-buffer)))
6058 ;; Select next unread newsgroup automagically.
6059 (cond
6060 ((or (not gnus-auto-select-next)
6061 (not cmd))
6062 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6063 ((or (eq gnus-auto-select-next 'quietly)
6064 (and (eq gnus-auto-select-next 'slightly-quietly)
6065 push)
6066 (and (eq gnus-auto-select-next 'almost-quietly)
6067 (gnus-summary-last-article-p)))
6068 ;; Select quietly.
6069 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6070 (gnus-summary-exit)
6071 (gnus-message 7 "No more%s articles (%s)..."
6072 (if unread " unread" "")
6073 (if group (concat "selecting " group)
6074 "exiting"))
6075 (gnus-summary-next-group nil group backward)))
6076 (t
6077 (when (gnus-key-press-event-p last-input-event)
6078 (gnus-summary-walk-group-buffer
6079 gnus-newsgroup-name cmd unread backward point))))))))
6080
6081(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6082 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6083 (?\C-p (gnus-group-prev-unread-group 1))))
6084 (cursor-in-echo-area t)
6085 keve key group ended)
6086 (save-excursion
6087 (set-buffer gnus-group-buffer)
6088 (goto-char start)
6089 (setq group
6090 (if (eq gnus-keep-same-level 'best)
6091 (gnus-summary-best-group gnus-newsgroup-name)
6092 (gnus-summary-search-group backward gnus-keep-same-level))))
6093 (while (not ended)
6094 (gnus-message
6095 5 "No more%s articles%s" (if unread " unread" "")
6096 (if (and group
6097 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6098 (format " (Type %s for %s [%s])"
6099 (single-key-description cmd) group
6100 (car (gnus-gethash group gnus-newsrc-hashtb)))
6101 (format " (Type %s to exit %s)"
6102 (single-key-description cmd)
6103 gnus-newsgroup-name)))
6104 ;; Confirm auto selection.
6105 (setq key (car (setq keve (gnus-read-event-char))))
6106 (setq ended t)
6107 (cond
6108 ((assq key keystrokes)
6109 (let ((obuf (current-buffer)))
6110 (switch-to-buffer gnus-group-buffer)
6111 (when group
6112 (gnus-group-jump-to-group group))
6113 (eval (cadr (assq key keystrokes)))
6114 (setq group (gnus-group-group-name))
6115 (switch-to-buffer obuf))
6116 (setq ended nil))
6117 ((equal key cmd)
6118 (if (or (not group)
6119 (gnus-ephemeral-group-p gnus-newsgroup-name))
6120 (gnus-summary-exit)
6121 (gnus-summary-next-group nil group backward)))
6122 (t
6123 (push (cdr keve) unread-command-events))))))
6124
6125(defun gnus-summary-next-unread-article ()
6126 "Select unread article after current one."
6127 (interactive)
6128 (gnus-summary-next-article
6129 (or (not (eq gnus-summary-goto-unread 'never))
6130 (gnus-summary-last-article-p (gnus-summary-article-number)))
6131 (and gnus-auto-select-same
6132 (gnus-summary-article-subject))))
6133
6134(defun gnus-summary-prev-article (&optional unread subject)
6135 "Select the article after the current one.
6136If UNREAD is non-nil, only unread articles are selected."
6137 (interactive "P")
6138 (gnus-summary-next-article unread subject t))
6139
6140(defun gnus-summary-prev-unread-article ()
6141 "Select unread article before current one."
6142 (interactive)
6143 (gnus-summary-prev-article
6144 (or (not (eq gnus-summary-goto-unread 'never))
6145 (gnus-summary-first-article-p (gnus-summary-article-number)))
6146 (and gnus-auto-select-same
6147 (gnus-summary-article-subject))))
6148
6149(defun gnus-summary-next-page (&optional lines circular)
6150 "Show next page of the selected article.
6151If at the end of the current article, select the next article.
6152LINES says how many lines should be scrolled up.
6153
6154If CIRCULAR is non-nil, go to the start of the article instead of
6155selecting the next article when reaching the end of the current
6156article."
6157 (interactive "P")
6158 (setq gnus-summary-buffer (current-buffer))
6159 (gnus-set-global-variables)
6160 (let ((article (gnus-summary-article-number))
6161 (article-window (get-buffer-window gnus-article-buffer t))
6162 endp)
6748645f
LMI
6163 ;; If the buffer is empty, we have no article.
6164 (unless article
6165 (error "No article to select"))
eec82323
LMI
6166 (gnus-configure-windows 'article)
6167 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6168 (if (and (eq gnus-summary-goto-unread 'never)
6169 (not (gnus-summary-last-article-p article)))
6170 (gnus-summary-next-article)
6171 (gnus-summary-next-unread-article))
6172 (if (or (null gnus-current-article)
6173 (null gnus-article-current)
6174 (/= article (cdr gnus-article-current))
6175 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6176 ;; Selected subject is different from current article's.
6177 (gnus-summary-display-article article)
6178 (when article-window
6179 (gnus-eval-in-buffer-window gnus-article-buffer
6180 (setq endp (gnus-article-next-page lines)))
6181 (when endp
6182 (cond (circular
6183 (gnus-summary-beginning-of-article))
6184 (lines
6185 (gnus-message 3 "End of message"))
6186 ((null lines)
6187 (if (and (eq gnus-summary-goto-unread 'never)
6188 (not (gnus-summary-last-article-p article)))
6189 (gnus-summary-next-article)
6190 (gnus-summary-next-unread-article))))))))
6191 (gnus-summary-recenter)
6192 (gnus-summary-position-point)))
6193
6194(defun gnus-summary-prev-page (&optional lines move)
6195 "Show previous page of selected article.
6196Argument LINES specifies lines to be scrolled down.
6197If MOVE, move to the previous unread article if point is at
6198the beginning of the buffer."
6199 (interactive "P")
eec82323
LMI
6200 (let ((article (gnus-summary-article-number))
6201 (article-window (get-buffer-window gnus-article-buffer t))
6202 endp)
6203 (gnus-configure-windows 'article)
6204 (if (or (null gnus-current-article)
6205 (null gnus-article-current)
6206 (/= article (cdr gnus-article-current))
6207 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6208 ;; Selected subject is different from current article's.
6209 (gnus-summary-display-article article)
6210 (gnus-summary-recenter)
6211 (when article-window
6212 (gnus-eval-in-buffer-window gnus-article-buffer
6213 (setq endp (gnus-article-prev-page lines)))
6214 (when (and move endp)
6215 (cond (lines
6216 (gnus-message 3 "Beginning of message"))
6217 ((null lines)
6218 (if (and (eq gnus-summary-goto-unread 'never)
6219 (not (gnus-summary-first-article-p article)))
6220 (gnus-summary-prev-article)
6221 (gnus-summary-prev-unread-article))))))))
6222 (gnus-summary-position-point))
6223
6224(defun gnus-summary-prev-page-or-article (&optional lines)
6225 "Show previous page of selected article.
6226Argument LINES specifies lines to be scrolled down.
6227If at the beginning of the article, go to the next article."
6228 (interactive "P")
6229 (gnus-summary-prev-page lines t))
6230
6231(defun gnus-summary-scroll-up (lines)
6232 "Scroll up (or down) one line current article.
6233Argument LINES specifies lines to be scrolled up (or down if negative)."
6234 (interactive "p")
eec82323
LMI
6235 (gnus-configure-windows 'article)
6236 (gnus-summary-show-thread)
6237 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6238 (gnus-eval-in-buffer-window gnus-article-buffer
6239 (cond ((> lines 0)
6240 (when (gnus-article-next-page lines)
6241 (gnus-message 3 "End of message")))
6242 ((< lines 0)
6243 (gnus-article-prev-page (- lines))))))
6244 (gnus-summary-recenter)
6245 (gnus-summary-position-point))
6246
6748645f
LMI
6247(defun gnus-summary-scroll-down (lines)
6248 "Scroll down (or up) one line current article.
6249Argument LINES specifies lines to be scrolled down (or up if negative)."
6250 (interactive "p")
6251 (gnus-summary-scroll-up (- lines)))
6252
eec82323
LMI
6253(defun gnus-summary-next-same-subject ()
6254 "Select next article which has the same subject as current one."
6255 (interactive)
eec82323
LMI
6256 (gnus-summary-next-article nil (gnus-summary-article-subject)))
6257
6258(defun gnus-summary-prev-same-subject ()
6259 "Select previous article which has the same subject as current one."
6260 (interactive)
eec82323
LMI
6261 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6262
6263(defun gnus-summary-next-unread-same-subject ()
6264 "Select next unread article which has the same subject as current one."
6265 (interactive)
eec82323
LMI
6266 (gnus-summary-next-article t (gnus-summary-article-subject)))
6267
6268(defun gnus-summary-prev-unread-same-subject ()
6269 "Select previous unread article which has the same subject as current one."
6270 (interactive)
eec82323
LMI
6271 (gnus-summary-prev-article t (gnus-summary-article-subject)))
6272
6273(defun gnus-summary-first-unread-article ()
6274 "Select the first unread article.
6275Return nil if there are no unread articles."
6276 (interactive)
eec82323
LMI
6277 (prog1
6278 (when (gnus-summary-first-subject t)
6279 (gnus-summary-show-thread)
6280 (gnus-summary-first-subject t)
6281 (gnus-summary-display-article (gnus-summary-article-number)))
6282 (gnus-summary-position-point)))
6283
16409b0b
GM
6284(defun gnus-summary-first-unread-subject ()
6285 "Place the point on the subject line of the first unread article.
6286Return nil if there are no unread articles."
6287 (interactive)
6288 (prog1
6289 (when (gnus-summary-first-subject t)
6290 (gnus-summary-show-thread)
6291 (gnus-summary-first-subject t))
6292 (gnus-summary-position-point)))
6293
eec82323
LMI
6294(defun gnus-summary-first-article ()
6295 "Select the first article.
6296Return nil if there are no articles."
6297 (interactive)
eec82323
LMI
6298 (prog1
6299 (when (gnus-summary-first-subject)
16409b0b
GM
6300 (gnus-summary-show-thread)
6301 (gnus-summary-first-subject)
6302 (gnus-summary-display-article (gnus-summary-article-number)))
eec82323
LMI
6303 (gnus-summary-position-point)))
6304
6305(defun gnus-summary-best-unread-article ()
6306 "Select the unread article with the highest score."
6307 (interactive)
eec82323
LMI
6308 (let ((best -1000000)
6309 (data gnus-newsgroup-data)
6310 article score)
6311 (while data
6312 (and (gnus-data-unread-p (car data))
6313 (> (setq score
6314 (gnus-summary-article-score (gnus-data-number (car data))))
6315 best)
6316 (setq best score
6317 article (gnus-data-number (car data))))
6318 (setq data (cdr data)))
6319 (prog1
6320 (if article
6321 (gnus-summary-goto-article article)
6322 (error "No unread articles"))
6323 (gnus-summary-position-point))))
6324
6325(defun gnus-summary-last-subject ()
6326 "Go to the last displayed subject line in the group."
6327 (let ((article (gnus-data-number (car (gnus-data-list t)))))
6328 (when article
6329 (gnus-summary-goto-subject article))))
6330
6331(defun gnus-summary-goto-article (article &optional all-headers force)
6748645f
LMI
6332 "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6333If ALL-HEADERS is non-nil, no header lines are hidden.
6334If FORCE, go to the article even if it isn't displayed. If FORCE
6335is a number, it is the line the article is to be displayed on."
eec82323
LMI
6336 (interactive
6337 (list
6748645f
LMI
6338 (completing-read
6339 "Article number or Message-ID: "
6340 (mapcar (lambda (number) (list (int-to-string number)))
6341 gnus-newsgroup-limit))
eec82323
LMI
6342 current-prefix-arg
6343 t))
6344 (prog1
6748645f
LMI
6345 (if (and (stringp article)
6346 (string-match "@" article))
6347 (gnus-summary-refer-article article)
6348 (when (stringp article)
6349 (setq article (string-to-number article)))
6350 (if (gnus-summary-goto-subject article force)
6351 (gnus-summary-display-article article all-headers)
6352 (gnus-message 4 "Couldn't go to article %s" article) nil))
eec82323
LMI
6353 (gnus-summary-position-point)))
6354
6355(defun gnus-summary-goto-last-article ()
6356 "Go to the previously read article."
6357 (interactive)
6358 (prog1
6359 (when gnus-last-article
6748645f 6360 (gnus-summary-goto-article gnus-last-article nil t))
eec82323
LMI
6361 (gnus-summary-position-point)))
6362
6363(defun gnus-summary-pop-article (number)
6364 "Pop one article off the history and go to the previous.
6365NUMBER articles will be popped off."
6366 (interactive "p")
6367 (let (to)
6368 (setq gnus-newsgroup-history
6369 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6370 (if to
6748645f 6371 (gnus-summary-goto-article (car to) nil t)
eec82323
LMI
6372 (error "Article history empty")))
6373 (gnus-summary-position-point))
6374
6375;; Summary commands and functions for limiting the summary buffer.
6376
6377(defun gnus-summary-limit-to-articles (n)
6378 "Limit the summary buffer to the next N articles.
6379If not given a prefix, use the process marked articles instead."
6380 (interactive "P")
eec82323
LMI
6381 (prog1
6382 (let ((articles (gnus-summary-work-articles n)))
6383 (setq gnus-newsgroup-processable nil)
6384 (gnus-summary-limit articles))
6385 (gnus-summary-position-point)))
6386
6387(defun gnus-summary-pop-limit (&optional total)
6388 "Restore the previous limit.
6389If given a prefix, remove all limits."
6390 (interactive "P")
eec82323
LMI
6391 (when total
6392 (setq gnus-newsgroup-limits
6393 (list (mapcar (lambda (h) (mail-header-number h))
6394 gnus-newsgroup-headers))))
6395 (unless gnus-newsgroup-limits
6396 (error "No limit to pop"))
6397 (prog1
6398 (gnus-summary-limit nil 'pop)
6399 (gnus-summary-position-point)))
6400
47b63dfa
SZ
6401(defun gnus-summary-limit-to-subject (subject &optional header not-matching)
6402 "Limit the summary buffer to articles that have subjects that match a regexp.
6403If NOT-MATCHING, excluding articles that have subjects that match a regexp."
6404 (interactive
6405 (list (read-string (if current-prefix-arg
6406 "Exclude subject (regexp): "
6407 "Limit to subject (regexp): "))
6408 nil current-prefix-arg))
eec82323
LMI
6409 (unless header
6410 (setq header "subject"))
6411 (when (not (equal "" subject))
6412 (prog1
6413 (let ((articles (gnus-summary-find-matching
47b63dfa
SZ
6414 (or header "subject") subject 'all nil nil
6415 not-matching)))
eec82323
LMI
6416 (unless articles
6417 (error "Found no matches for \"%s\"" subject))
6418 (gnus-summary-limit articles))
6419 (gnus-summary-position-point))))
6420
ef6e0ec7 6421(defun gnus-summary-limit-to-author (from &optional not-matching)
47b63dfa
SZ
6422 "Limit the summary buffer to articles that have authors that match a regexp.
6423If NOT-MATCHING, excluding articles that have authors that match a regexp."
6424 (interactive
6425 (list (read-string (if current-prefix-arg
6426 "Exclude author (regexp): "
6427 "Limit to author (regexp): "))
ef6e0ec7
SZ
6428 current-prefix-arg))
6429 (gnus-summary-limit-to-subject from "from" not-matching))
eec82323
LMI
6430
6431(defun gnus-summary-limit-to-age (age &optional younger-p)
6432 "Limit the summary buffer to articles that are older than (or equal) AGE days.
6433If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6434articles that are younger than AGE days."
16409b0b
GM
6435 (interactive
6436 (let ((younger current-prefix-arg)
6437 (days-got nil)
6438 days)
6439 (while (not days-got)
6440 (setq days (if younger
6441 (read-string "Limit to articles within (in days): ")
6442 (read-string "Limit to articles old than (in days): ")))
6443 (when (> (length days) 0)
6444 (setq days (read days)))
6445 (if (numberp days)
6446 (setq days-got t)
6447 (message "Please enter a number.")
6448 (sleep-for 1)))
6449 (list days younger)))
eec82323
LMI
6450 (prog1
6451 (let ((data gnus-newsgroup-data)
16409b0b 6452 (cutoff (days-to-time age))
eec82323
LMI
6453 articles d date is-younger)
6454 (while (setq d (pop data))
6455 (when (and (vectorp (gnus-data-header d))
6456 (setq date (mail-header-date (gnus-data-header d))))
16409b0b
GM
6457 (setq is-younger (time-less-p
6458 (time-since (condition-case ()
6459 (date-to-time date)
6460 (error '(0 0))))
eec82323 6461 cutoff))
6748645f
LMI
6462 (when (if younger-p
6463 is-younger
6464 (not is-younger))
eec82323
LMI
6465 (push (gnus-data-number d) articles))))
6466 (gnus-summary-limit (nreverse articles)))
6467 (gnus-summary-position-point)))
6468
47b63dfa 6469(defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
16409b0b
GM
6470 "Limit the summary buffer to articles that match an 'extra' header."
6471 (interactive
6472 (let ((header
6473 (intern
6474 (gnus-completing-read
6475 (symbol-name (car gnus-extra-headers))
47b63dfa
SZ
6476 (if current-prefix-arg
6477 "Exclude extra header:"
6478 "Limit extra header:")
16409b0b
GM
6479 (mapcar (lambda (x)
6480 (cons (symbol-name x) x))
6481 gnus-extra-headers)
6482 nil
6483 t))))
6484 (list header
47b63dfa
SZ
6485 (read-string (format "%s header %s (regexp): "
6486 (if current-prefix-arg "Exclude" "Limit to")
6487 header))
6488 current-prefix-arg)))
16409b0b
GM
6489 (when (not (equal "" regexp))
6490 (prog1
6491 (let ((articles (gnus-summary-find-matching
47b63dfa
SZ
6492 (cons 'extra header) regexp 'all nil nil
6493 not-matching)))
16409b0b
GM
6494 (unless articles
6495 (error "Found no matches for \"%s\"" regexp))
6496 (gnus-summary-limit articles))
6497 (gnus-summary-position-point))))
6498
eec82323
LMI
6499(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6500(make-obsolete
6501 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6502
6503(defun gnus-summary-limit-to-unread (&optional all)
6504 "Limit the summary buffer to articles that are not marked as read.
6505If ALL is non-nil, limit strictly to unread articles."
6506 (interactive "P")
6507 (if all
6508 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6509 (gnus-summary-limit-to-marks
6510 ;; Concat all the marks that say that an article is read and have
6511 ;; those removed.
6512 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6513 gnus-killed-mark gnus-kill-file-mark
6514 gnus-low-score-mark gnus-expirable-mark
6515 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6516 gnus-duplicate-mark gnus-souped-mark)
6517 'reverse)))
6518
6519(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6520(make-obsolete 'gnus-summary-delete-marked-with
81ceefe2 6521 'gnus-summary-limit-exclude-marks)
eec82323
LMI
6522
6523(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6524 "Exclude articles that are marked with MARKS (e.g. \"DK\").
6525If REVERSE, limit the summary buffer to articles that are marked
6526with MARKS. MARKS can either be a string of marks or a list of marks.
6527Returns how many articles were removed."
6528 (interactive "sMarks: ")
6529 (gnus-summary-limit-to-marks marks t))
6530
6531(defun gnus-summary-limit-to-marks (marks &optional reverse)
6532 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6533If REVERSE (the prefix), limit the summary buffer to articles that are
6534not marked with MARKS. MARKS can either be a string of marks or a
6535list of marks.
6536Returns how many articles were removed."
6748645f 6537 (interactive "sMarks: \nP")
eec82323
LMI
6538 (prog1
6539 (let ((data gnus-newsgroup-data)
6540 (marks (if (listp marks) marks
6541 (append marks nil))) ; Transform to list.
6542 articles)
6543 (while data
6544 (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6545 (memq (gnus-data-mark (car data)) marks))
6546 (push (gnus-data-number (car data)) articles))
6547 (setq data (cdr data)))
6548 (gnus-summary-limit articles))
6549 (gnus-summary-position-point)))
6550
6551(defun gnus-summary-limit-to-score (&optional score)
6552 "Limit to articles with score at or above SCORE."
6553 (interactive "P")
eec82323
LMI
6554 (setq score (if score
6555 (prefix-numeric-value score)
6556 (or gnus-summary-default-score 0)))
6557 (let ((data gnus-newsgroup-data)
6558 articles)
6559 (while data
6560 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6561 score)
6562 (push (gnus-data-number (car data)) articles))
6563 (setq data (cdr data)))
6564 (prog1
6565 (gnus-summary-limit articles)
6566 (gnus-summary-position-point))))
6567
6748645f
LMI
6568(defun gnus-summary-limit-include-thread (id)
6569 "Display all the hidden articles that in the current thread."
6570 (interactive (list (mail-header-id (gnus-summary-article-header))))
6571 (let ((articles (gnus-articles-in-thread
6572 (gnus-id-to-thread (gnus-root-id id)))))
6573 (prog1
6574 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6575 (gnus-summary-position-point))))
6576
eec82323 6577(defun gnus-summary-limit-include-dormant ()
6748645f
LMI
6578 "Display all the hidden articles that are marked as dormant.
6579Note that this command only works on a subset of the articles currently
6580fetched for this group."
eec82323 6581 (interactive)
eec82323
LMI
6582 (unless gnus-newsgroup-dormant
6583 (error "There are no dormant articles in this group"))
6584 (prog1
6585 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6586 (gnus-summary-position-point)))
6587
6588(defun gnus-summary-limit-exclude-dormant ()
6589 "Hide all dormant articles."
6590 (interactive)
eec82323
LMI
6591 (prog1
6592 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6593 (gnus-summary-position-point)))
6594
6595(defun gnus-summary-limit-exclude-childless-dormant ()
6596 "Hide all dormant articles that have no children."
6597 (interactive)
eec82323
LMI
6598 (let ((data (gnus-data-list t))
6599 articles d children)
6600 ;; Find all articles that are either not dormant or have
6601 ;; children.
6602 (while (setq d (pop data))
6603 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6604 (and (setq children
6605 (gnus-article-children (gnus-data-number d)))
6606 (let (found)
6607 (while children
6608 (when (memq (car children) articles)
6609 (setq children nil
6610 found t))
6611 (pop children))
6612 found)))
6613 (push (gnus-data-number d) articles)))
6614 ;; Do the limiting.
6615 (prog1
6616 (gnus-summary-limit articles)
6617 (gnus-summary-position-point))))
6618
6619(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6620 "Mark all unread excluded articles as read.
6621If ALL, mark even excluded ticked and dormants as read."
6622 (interactive "P")
6623 (let ((articles (gnus-sorted-complement
6624 (sort
6625 (mapcar (lambda (h) (mail-header-number h))
6626 gnus-newsgroup-headers)
6627 '<)
6628 (sort gnus-newsgroup-limit '<)))
6629 article)
6748645f
LMI
6630 (setq gnus-newsgroup-unreads
6631 (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
eec82323
LMI
6632 (if all
6633 (setq gnus-newsgroup-dormant nil
6634 gnus-newsgroup-marked nil
6635 gnus-newsgroup-reads
6636 (nconc
6637 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6638 gnus-newsgroup-reads))
6639 (while (setq article (pop articles))
6640 (unless (or (memq article gnus-newsgroup-dormant)
6641 (memq article gnus-newsgroup-marked))
6642 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6643
6644(defun gnus-summary-limit (articles &optional pop)
6645 (if pop
6646 ;; We pop the previous limit off the stack and use that.
6647 (setq articles (car gnus-newsgroup-limits)
6648 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6649 ;; We use the new limit, so we push the old limit on the stack.
6650 (push gnus-newsgroup-limit gnus-newsgroup-limits))
6651 ;; Set the limit.
6652 (setq gnus-newsgroup-limit articles)
6653 (let ((total (length gnus-newsgroup-data))
6654 (data (gnus-data-find-list (gnus-summary-article-number)))
6655 (gnus-summary-mark-below nil) ; Inhibit this.
6656 found)
6657 ;; This will do all the work of generating the new summary buffer
6658 ;; according to the new limit.
6659 (gnus-summary-prepare)
6660 ;; Hide any threads, possibly.
6661 (and gnus-show-threads
6662 gnus-thread-hide-subtree
6663 (gnus-summary-hide-all-threads))
6664 ;; Try to return to the article you were at, or one in the
6665 ;; neighborhood.
6666 (when data
6667 ;; We try to find some article after the current one.
6668 (while data
6669 (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6670 (setq data nil
6671 found t))
6672 (setq data (cdr data))))
6673 (unless found
6674 ;; If there is no data, that means that we were after the last
6675 ;; article. The same goes when we can't find any articles
6676 ;; after the current one.
6677 (goto-char (point-max))
6678 (gnus-summary-find-prev))
6748645f 6679 (gnus-set-mode-line 'summary)
eec82323
LMI
6680 ;; We return how many articles were removed from the summary
6681 ;; buffer as a result of the new limit.
6682 (- total (length gnus-newsgroup-data))))
6683
6684(defsubst gnus-invisible-cut-children (threads)
6685 (let ((num 0))
6686 (while threads
6687 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6688 (incf num))
6689 (pop threads))
6690 (< num 2)))
6691
6692(defsubst gnus-cut-thread (thread)
6693 "Go forwards in the thread until we find an article that we want to display."
6694 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 6695 (eq gnus-fetch-old-headers 'invisible)
16409b0b 6696 (numberp gnus-fetch-old-headers)
eec82323
LMI
6697 (eq gnus-build-sparse-threads 'some)
6698 (eq gnus-build-sparse-threads 'more))
6699 ;; Deal with old-fetched headers and sparse threads.
6700 (while (and
6701 thread
6702 (or
6703 (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6704 (gnus-summary-article-ancient-p
6705 (mail-header-number (car thread))))
6748645f
LMI
6706 (if (or (<= (length (cdr thread)) 1)
6707 (eq gnus-fetch-old-headers 'invisible))
6708 (setq gnus-newsgroup-limit
6709 (delq (mail-header-number (car thread))
6710 gnus-newsgroup-limit)
6711 thread (cadr thread))
6712 (when (gnus-invisible-cut-children (cdr thread))
6713 (let ((th (cdr thread)))
6714 (while th
6715 (if (memq (mail-header-number (caar th))
a8151ef7 6716 gnus-newsgroup-limit)
6748645f
LMI
6717 (setq thread (car th)
6718 th nil)
6719 (setq th (cdr th))))))))))
eec82323
LMI
6720 thread)
6721
6722(defun gnus-cut-threads (threads)
6723 "Cut off all uninteresting articles from the beginning of threads."
6724 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 6725 (eq gnus-fetch-old-headers 'invisible)
16409b0b 6726 (numberp gnus-fetch-old-headers)
eec82323
LMI
6727 (eq gnus-build-sparse-threads 'some)
6728 (eq gnus-build-sparse-threads 'more))
6729 (let ((th threads))
6730 (while th
6731 (setcar th (gnus-cut-thread (car th)))
6732 (setq th (cdr th)))))
6733 ;; Remove nixed out threads.
6734 (delq nil threads))
6735
6736(defun gnus-summary-initial-limit (&optional show-if-empty)
6737 "Figure out what the initial limit is supposed to be on group entry.
6738This entails weeding out unwanted dormants, low-scored articles,
6739fetch-old-headers verbiage, and so on."
6740 ;; Most groups have nothing to remove.
6741 (if (or gnus-inhibit-limiting
6742 (and (null gnus-newsgroup-dormant)
6743 (not (eq gnus-fetch-old-headers 'some))
16409b0b 6744 (not (numberp gnus-fetch-old-headers))
6748645f 6745 (not (eq gnus-fetch-old-headers 'invisible))
eec82323
LMI
6746 (null gnus-summary-expunge-below)
6747 (not (eq gnus-build-sparse-threads 'some))
6748 (not (eq gnus-build-sparse-threads 'more))
6749 (null gnus-thread-expunge-below)
6750 (not gnus-use-nocem)))
6751 () ; Do nothing.
6752 (push gnus-newsgroup-limit gnus-newsgroup-limits)
6753 (setq gnus-newsgroup-limit nil)
6754 (mapatoms
6755 (lambda (node)
6756 (unless (car (symbol-value node))
6757 ;; These threads have no parents -- they are roots.
6758 (let ((nodes (cdr (symbol-value node)))
6759 thread)
6760 (while nodes
6761 (if (and gnus-thread-expunge-below
6762 (< (gnus-thread-total-score (car nodes))
6763 gnus-thread-expunge-below))
6764 (gnus-expunge-thread (pop nodes))
6765 (setq thread (pop nodes))
6766 (gnus-summary-limit-children thread))))))
6767 gnus-newsgroup-dependencies)
6768 ;; If this limitation resulted in an empty group, we might
6769 ;; pop the previous limit and use it instead.
6770 (when (and (not gnus-newsgroup-limit)
6771 show-if-empty)
6772 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6773 gnus-newsgroup-limit))
6774
6775(defun gnus-summary-limit-children (thread)
6776 "Return 1 if this subthread is visible and 0 if it is not."
6777 ;; First we get the number of visible children to this thread. This
6778 ;; is done by recursing down the thread using this function, so this
6779 ;; will really go down to a leaf article first, before slowly
6780 ;; working its way up towards the root.
6781 (when thread
6782 (let ((children
6783 (if (cdr thread)
6784 (apply '+ (mapcar 'gnus-summary-limit-children
6785 (cdr thread)))
6786 0))
6787 (number (mail-header-number (car thread)))
6788 score)
6789 (if (and
6790 (not (memq number gnus-newsgroup-marked))
6791 (or
6792 ;; If this article is dormant and has absolutely no visible
6793 ;; children, then this article isn't visible.
6794 (and (memq number gnus-newsgroup-dormant)
6795 (zerop children))
6796 ;; If this is "fetch-old-headered" and there is no
6797 ;; visible children, then we don't want this article.
16409b0b
GM
6798 (and (or (eq gnus-fetch-old-headers 'some)
6799 (numberp gnus-fetch-old-headers))
eec82323
LMI
6800 (gnus-summary-article-ancient-p number)
6801 (zerop children))
6748645f
LMI
6802 ;; If this is "fetch-old-headered" and `invisible', then
6803 ;; we don't want this article.
6804 (and (eq gnus-fetch-old-headers 'invisible)
6805 (gnus-summary-article-ancient-p number))
eec82323
LMI
6806 ;; If this is a sparsely inserted article with no children,
6807 ;; we don't want it.
6808 (and (eq gnus-build-sparse-threads 'some)
6809 (gnus-summary-article-sparse-p number)
6810 (zerop children))
6811 ;; If we use expunging, and this article is really
6812 ;; low-scored, then we don't want this article.
6813 (when (and gnus-summary-expunge-below
6814 (< (setq score
6815 (or (cdr (assq number gnus-newsgroup-scored))
6816 gnus-summary-default-score))
6817 gnus-summary-expunge-below))
6818 ;; We increase the expunge-tally here, but that has
6819 ;; nothing to do with the limits, really.
6820 (incf gnus-newsgroup-expunged-tally)
6821 ;; We also mark as read here, if that's wanted.
6822 (when (and gnus-summary-mark-below
6823 (< score gnus-summary-mark-below))
6824 (setq gnus-newsgroup-unreads
6825 (delq number gnus-newsgroup-unreads))
6826 (if gnus-newsgroup-auto-expire
6827 (push number gnus-newsgroup-expirable)
6828 (push (cons number gnus-low-score-mark)
6829 gnus-newsgroup-reads)))
6830 t)
6831 ;; Check NoCeM things.
6832 (if (and gnus-use-nocem
6833 (gnus-nocem-unwanted-article-p
6834 (mail-header-id (car thread))))
6835 (progn
a8151ef7 6836 (setq gnus-newsgroup-unreads
eec82323
LMI
6837 (delq number gnus-newsgroup-unreads))
6838 t))))
6839 ;; Nope, invisible article.
6840 0
6841 ;; Ok, this article is to be visible, so we add it to the limit
6842 ;; and return 1.
6843 (push number gnus-newsgroup-limit)
6844 1))))
6845
6846(defun gnus-expunge-thread (thread)
6847 "Mark all articles in THREAD as read."
6848 (let* ((number (mail-header-number (car thread))))
6849 (incf gnus-newsgroup-expunged-tally)
6850 ;; We also mark as read here, if that's wanted.
6851 (setq gnus-newsgroup-unreads
6852 (delq number gnus-newsgroup-unreads))
6853 (if gnus-newsgroup-auto-expire
6854 (push number gnus-newsgroup-expirable)
6855 (push (cons number gnus-low-score-mark)
6856 gnus-newsgroup-reads)))
6857 ;; Go recursively through all subthreads.
6858 (mapcar 'gnus-expunge-thread (cdr thread)))
6859
6860;; Summary article oriented commands
6861
6862(defun gnus-summary-refer-parent-article (n)
6863 "Refer parent article N times.
6864If N is negative, go to ancestor -N instead.
6865The difference between N and the number of articles fetched is returned."
6866 (interactive "p")
eec82323
LMI
6867 (let ((skip 1)
6868 error header ref)
6869 (when (not (natnump n))
6870 (setq skip (abs n)
6871 n 1))
6872 (while (and (> n 0)
6873 (not error))
6874 (setq header (gnus-summary-article-header))
6875 (if (and (eq (mail-header-number header)
6876 (cdr gnus-article-current))
6877 (equal gnus-newsgroup-name
6878 (car gnus-article-current)))
6879 ;; If we try to find the parent of the currently
6880 ;; displayed article, then we take a look at the actual
6881 ;; References header, since this is slightly more
6882 ;; reliable than the References field we got from the
6883 ;; server.
6884 (save-excursion
6885 (set-buffer gnus-original-article-buffer)
6886 (nnheader-narrow-to-headers)
6887 (unless (setq ref (message-fetch-field "references"))
6888 (setq ref (message-fetch-field "in-reply-to")))
6889 (widen))
6890 (setq ref
6891 ;; It's not the current article, so we take a bet on
6892 ;; the value we got from the server.
6893 (mail-header-references header)))
6894 (if (and ref
6895 (not (equal ref "")))
6896 (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6897 (gnus-message 1 "Couldn't find parent"))
6898 (gnus-message 1 "No references in article %d"
6899 (gnus-summary-article-number))
6900 (setq error t))
6901 (decf n))
6902 (gnus-summary-position-point)
6903 n))
6904
6905(defun gnus-summary-refer-references ()
6906 "Fetch all articles mentioned in the References header.
6748645f 6907Return the number of articles fetched."
eec82323 6908 (interactive)
eec82323
LMI
6909 (let ((ref (mail-header-references (gnus-summary-article-header)))
6910 (current (gnus-summary-article-number))
6911 (n 0))
6912 (if (or (not ref)
6913 (equal ref ""))
6914 (error "No References in the current article")
6915 ;; For each Message-ID in the References header...
6916 (while (string-match "<[^>]*>" ref)
6917 (incf n)
6918 ;; ... fetch that article.
6919 (gnus-summary-refer-article
6920 (prog1 (match-string 0 ref)
6921 (setq ref (substring ref (match-end 0))))))
6922 (gnus-summary-goto-subject current)
6923 (gnus-summary-position-point)
6924 n)))
6925
6748645f
LMI
6926(defun gnus-summary-refer-thread (&optional limit)
6927 "Fetch all articles in the current thread.
6928If LIMIT (the numerical prefix), fetch that many old headers instead
6929of what's specified by the `gnus-refer-thread-limit' variable."
6930 (interactive "P")
6931 (let ((id (mail-header-id (gnus-summary-article-header)))
6932 (limit (if limit (prefix-numeric-value limit)
6933 gnus-refer-thread-limit)))
6934 ;; We want to fetch LIMIT *old* headers, but we also have to
6935 ;; re-fetch all the headers in the current buffer, because many of
6936 ;; them may be undisplayed. So we adjust LIMIT.
6937 (when (numberp limit)
6938 (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6939 (unless (eq gnus-fetch-old-headers 'invisible)
6940 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6941 ;; Retrieve the headers and read them in.
6942 (if (eq (gnus-retrieve-headers
6943 (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6944 'nov)
6945 (gnus-build-all-threads)
6946 (error "Can't fetch thread from backends that don't support NOV"))
6947 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6948 (gnus-summary-limit-include-thread id)))
6949
16409b0b
GM
6950(defun gnus-summary-refer-article (message-id)
6951 "Fetch an article specified by MESSAGE-ID."
6952 (interactive "sMessage-ID: ")
eec82323
LMI
6953 (when (and (stringp message-id)
6954 (not (zerop (length message-id))))
6955 ;; Construct the correct Message-ID if necessary.
6956 ;; Suggested by tale@pawl.rpi.edu.
6957 (unless (string-match "^<" message-id)
6958 (setq message-id (concat "<" message-id)))
6959 (unless (string-match ">$" message-id)
6960 (setq message-id (concat message-id ">")))
6961 (let* ((header (gnus-id-to-header message-id))
6962 (sparse (and header
6963 (gnus-summary-article-sparse-p
a8151ef7
LMI
6964 (mail-header-number header))
6965 (memq (mail-header-number header)
16409b0b
GM
6966 gnus-newsgroup-limit)))
6967 number)
6748645f
LMI
6968 (cond
6969 ;; If the article is present in the buffer we just go to it.
6970 ((and header
6971 (or (not (gnus-summary-article-sparse-p
6972 (mail-header-number header)))
6973 sparse))
6974 (prog1
6975 (gnus-summary-goto-article
6976 (mail-header-number header) nil t)
6977 (when sparse
6978 (gnus-summary-update-article (mail-header-number header)))))
6979 (t
16409b0b
GM
6980 ;; We fetch the article.
6981 (catch 'found
6982 (dolist (gnus-override-method (gnus-refer-article-methods))
6983 (gnus-check-server gnus-override-method)
6984 ;; Fetch the header, and display the article.
6985 (when (setq number (gnus-summary-insert-subject message-id))
eec82323 6986 (gnus-summary-select-article nil nil nil number)
16409b0b
GM
6987 (throw 'found t)))
6988 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
6989
6990(defun gnus-refer-article-methods ()
6991 "Return a list of referrable methods."
6992 (cond
6993 ;; No method, so we default to current and native.
6994 ((null gnus-refer-article-method)
6995 (list gnus-current-select-method gnus-select-method))
6996 ;; Current.
6997 ((eq 'current gnus-refer-article-method)
6998 (list gnus-current-select-method))
6999 ;; List of select methods.
d4dfaa19
DL
7000 ((not (and (symbolp (car gnus-refer-article-method))
7001 (assq (car gnus-refer-article-method) nnoo-definition-alist)))
16409b0b
GM
7002 (let (out)
7003 (dolist (method gnus-refer-article-method)
7004 (push (if (eq 'current method)
7005 gnus-current-select-method
7006 method)
7007 out))
7008 (nreverse out)))
7009 ;; One single select method.
7010 (t
7011 (list gnus-refer-article-method))))
6748645f
LMI
7012
7013(defun gnus-summary-edit-parameters ()
7014 "Edit the group parameters of the current group."
7015 (interactive)
7016 (gnus-group-edit-group gnus-newsgroup-name 'params))
eec82323 7017
16409b0b
GM
7018(defun gnus-summary-customize-parameters ()
7019 "Customize the group parameters of the current group."
7020 (interactive)
7021 (gnus-group-customize gnus-newsgroup-name))
7022
eec82323
LMI
7023(defun gnus-summary-enter-digest-group (&optional force)
7024 "Enter an nndoc group based on the current article.
7025If FORCE, force a digest interpretation. If not, try
7026to guess what the document format is."
7027 (interactive "P")
eec82323
LMI
7028 (let ((conf gnus-current-window-configuration))
7029 (save-excursion
7030 (gnus-summary-select-article))
7031 (setq gnus-current-window-configuration conf)
7032 (let* ((name (format "%s-%d"
7033 (gnus-group-prefixed-name
7034 gnus-newsgroup-name (list 'nndoc ""))
7035 (save-excursion
7036 (set-buffer gnus-summary-buffer)
7037 gnus-current-article)))
7038 (ogroup gnus-newsgroup-name)
7039 (params (append (gnus-info-params (gnus-get-info ogroup))
7040 (list (cons 'to-group ogroup))
7041 (list (cons 'save-article-group ogroup))))
7042 (case-fold-search t)
7043 (buf (current-buffer))
16409b0b 7044 dig to-address)
eec82323 7045 (save-excursion
16409b0b
GM
7046 (set-buffer gnus-original-article-buffer)
7047 ;; Have the digest group inherit the main mail address of
7048 ;; the parent article.
7049 (when (setq to-address (or (message-fetch-field "reply-to")
7050 (message-fetch-field "from")))
d4dfaa19
DL
7051 (setq params (append
7052 (list (cons 'to-address
7053 (funcall gnus-decode-encoded-word-function
7054 to-address))))))
eec82323
LMI
7055 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7056 (insert-buffer-substring gnus-original-article-buffer)
7057 ;; Remove lines that may lead nndoc to misinterpret the
7058 ;; document type.
7059 (narrow-to-region
7060 (goto-char (point-min))
7061 (or (search-forward "\n\n" nil t) (point)))
7062 (goto-char (point-min))
16409b0b 7063 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
7064 (widen))
7065 (unwind-protect
16409b0b
GM
7066 (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7067 (gnus-newsgroup-ephemeral-ignored-charsets
7068 gnus-newsgroup-ignored-charsets))
7069 (gnus-group-read-ephemeral-group
7070 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7071 (nndoc-article-type
7072 ,(if force 'mbox 'guess))) t))
7073 ;; Make all postings to this group go to the parent group.
eec82323
LMI
7074 (nconc (gnus-info-params (gnus-get-info name))
7075 params)
7076 ;; Couldn't select this doc group.
7077 (switch-to-buffer buf)
7078 (gnus-set-global-variables)
7079 (gnus-configure-windows 'summary)
7080 (gnus-message 3 "Article couldn't be entered?"))
7081 (kill-buffer dig)))))
7082
7083(defun gnus-summary-read-document (n)
7084 "Open a new group based on the current article(s).
7085This will allow you to read digests and other similar
7086documents as newsgroups.
7087Obeys the standard process/prefix convention."
7088 (interactive "P")
7089 (let* ((articles (gnus-summary-work-articles n))
7090 (ogroup gnus-newsgroup-name)
7091 (params (append (gnus-info-params (gnus-get-info ogroup))
7092 (list (cons 'to-group ogroup))))
7093 article group egroup groups vgroup)
7094 (while (setq article (pop articles))
7095 (setq group (format "%s-%d" gnus-newsgroup-name article))
7096 (gnus-summary-remove-process-mark article)
7097 (when (gnus-summary-display-article article)
7098 (save-excursion
16409b0b 7099 (with-temp-buffer
eec82323
LMI
7100 (insert-buffer-substring gnus-original-article-buffer)
7101 ;; Remove some headers that may lead nndoc to make
7102 ;; the wrong guess.
7103 (message-narrow-to-head)
7104 (goto-char (point-min))
7105 (delete-matching-lines "^\\(Path\\):\\|^From ")
7106 (widen)
7107 (if (setq egroup
7108 (gnus-group-read-ephemeral-group
7109 group `(nndoc ,group (nndoc-address ,(current-buffer))
7110 (nndoc-article-type guess))
7111 t nil t))
7112 (progn
7113 ;; Make all postings to this group go to the parent group.
7114 (nconc (gnus-info-params (gnus-get-info egroup))
7115 params)
7116 (push egroup groups))
7117 ;; Couldn't select this doc group.
7118 (gnus-error 3 "Article couldn't be entered"))))))
7119 ;; Now we have selected all the documents.
7120 (cond
7121 ((not groups)
7122 (error "None of the articles could be interpreted as documents"))
7123 ((gnus-group-read-ephemeral-group
7124 (setq vgroup (format
7125 "nnvirtual:%s-%s" gnus-newsgroup-name
7126 (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7127 `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7128 t
7129 (cons (current-buffer) 'summary)))
7130 (t
7131 (error "Couldn't select virtual nndoc group")))))
7132
7133(defun gnus-summary-isearch-article (&optional regexp-p)
7134 "Do incremental search forward on the current article.
7135If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7136 (interactive "P")
eec82323
LMI
7137 (gnus-summary-select-article)
7138 (gnus-configure-windows 'article)
7139 (gnus-eval-in-buffer-window gnus-article-buffer
6748645f
LMI
7140 (save-restriction
7141 (widen)
7142 (isearch-forward regexp-p))))
eec82323
LMI
7143
7144(defun gnus-summary-search-article-forward (regexp &optional backward)
7145 "Search for an article containing REGEXP forward.
7146If BACKWARD, search backward instead."
7147 (interactive
7148 (list (read-string
7149 (format "Search article %s (regexp%s): "
7150 (if current-prefix-arg "backward" "forward")
7151 (if gnus-last-search-regexp
7152 (concat ", default " gnus-last-search-regexp)
7153 "")))
7154 current-prefix-arg))
eec82323
LMI
7155 (if (string-equal regexp "")
7156 (setq regexp (or gnus-last-search-regexp ""))
7157 (setq gnus-last-search-regexp regexp))
7158 (if (gnus-summary-search-article regexp backward)
7159 (gnus-summary-show-thread)
7160 (error "Search failed: \"%s\"" regexp)))
7161
7162(defun gnus-summary-search-article-backward (regexp)
7163 "Search for an article containing REGEXP backward."
7164 (interactive
7165 (list (read-string
7166 (format "Search article backward (regexp%s): "
7167 (if gnus-last-search-regexp
7168 (concat ", default " gnus-last-search-regexp)
7169 "")))))
7170 (gnus-summary-search-article-forward regexp 'backward))
7171
7172(defun gnus-summary-search-article (regexp &optional backward)
7173 "Search for an article containing REGEXP.
7174Optional argument BACKWARD means do search for backward.
7175`gnus-select-article-hook' is not called during the search."
a8151ef7
LMI
7176 ;; We have to require this here to make sure that the following
7177 ;; dynamic binding isn't shadowed by autoloading.
7178 (require 'gnus-async)
16409b0b 7179 (require 'gnus-art)
eec82323 7180 (let ((gnus-select-article-hook nil) ;Disable hook.
16409b0b 7181 (gnus-article-prepare-hook nil)
eec82323
LMI
7182 (gnus-mark-article-hook nil) ;Inhibit marking as read.
7183 (gnus-use-article-prefetch nil)
7184 (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
a8151ef7 7185 (gnus-use-trees nil) ;Inhibit updating tree buffer.
eec82323 7186 (sum (current-buffer))
16409b0b 7187 (gnus-display-mime-function nil)
eec82323
LMI
7188 (found nil)
7189 point)
7190 (gnus-save-hidden-threads
7191 (gnus-summary-select-article)
7192 (set-buffer gnus-article-buffer)
16409b0b 7193 (goto-char (window-point (get-buffer-window (current-buffer))))
eec82323
LMI
7194 (when backward
7195 (forward-line -1))
7196 (while (not found)
7197 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7198 (if (if backward
7199 (re-search-backward regexp nil t)
7200 (re-search-forward regexp nil t))
7201 ;; We found the regexp.
7202 (progn
7203 (setq found 'found)
7204 (beginning-of-line)
7205 (set-window-start
7206 (get-buffer-window (current-buffer))
7207 (point))
7208 (forward-line 1)
16409b0b
GM
7209 (set-window-point
7210 (get-buffer-window (current-buffer))
7211 (point))
eec82323
LMI
7212 (set-buffer sum)
7213 (setq point (point)))
7214 ;; We didn't find it, so we go to the next article.
7215 (set-buffer sum)
7216 (setq found 'not)
7217 (while (eq found 'not)
7218 (if (not (if backward (gnus-summary-find-prev)
7219 (gnus-summary-find-next)))
7220 ;; No more articles.
7221 (setq found t)
7222 ;; Select the next article and adjust point.
7223 (unless (gnus-summary-article-sparse-p
7224 (gnus-summary-article-number))
7225 (setq found nil)
7226 (gnus-summary-select-article)
7227 (set-buffer gnus-article-buffer)
7228 (widen)
7229 (goto-char (if backward (point-max) (point-min))))))))
7230 (gnus-message 7 ""))
7231 ;; Return whether we found the regexp.
7232 (when (eq found 'found)
7233 (goto-char point)
7234 (gnus-summary-show-thread)
7235 (gnus-summary-goto-subject gnus-current-article)
7236 (gnus-summary-position-point)
7237 t)))
7238
7239(defun gnus-summary-find-matching (header regexp &optional backward unread
47b63dfa 7240 not-case-fold not-matching)
eec82323
LMI
7241 "Return a list of all articles that match REGEXP on HEADER.
7242The search stars on the current article and goes forwards unless
7243BACKWARD is non-nil. If BACKWARD is `all', do all articles.
7244If UNREAD is non-nil, only unread articles will
7245be taken into consideration. If NOT-CASE-FOLD, case won't be folded
47b63dfa
SZ
7246in the comparisons. If NOT-MATCHING, return a list of all articles that
7247not match REGEXP on HEADER."
7248 (let ((case-fold-search (not not-case-fold))
16409b0b
GM
7249 articles d func)
7250 (if (consp header)
7251 (if (eq (car header) 'extra)
7252 (setq func
7253 `(lambda (h)
7254 (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7255 "")))
7256 (error "%s is an invalid header" header))
7257 (unless (fboundp (intern (concat "mail-header-" header)))
7258 (error "%s is not a valid header" header))
7259 (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
47b63dfa
SZ
7260 (dolist (d (if (eq backward 'all)
7261 gnus-newsgroup-data
7262 (gnus-data-find-list
7263 (gnus-summary-article-number)
7264 (gnus-data-list backward))))
7265 (when (and (or (not unread) ; We want all articles...
7266 (gnus-data-unread-p d)) ; Or just unreads.
7267 (vectorp (gnus-data-header d)) ; It's not a pseudo.
7268 (if not-matching
7269 (not (string-match
7270 regexp
7271 (funcall func (gnus-data-header d))))
7272 (string-match regexp
7273 (funcall func (gnus-data-header d)))))
7274 (push (gnus-data-number d) articles))) ; Success!
eec82323
LMI
7275 (nreverse articles)))
7276
7277(defun gnus-summary-execute-command (header regexp command &optional backward)
7278 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7279If HEADER is an empty string (or nil), the match is done on the entire
7280article. If BACKWARD (the prefix) is non-nil, search backward instead."
7281 (interactive
7282 (list (let ((completion-ignore-case t))
7283 (completing-read
7284 "Header name: "
7285 (mapcar (lambda (string) (list string))
7286 '("Number" "Subject" "From" "Lines" "Date"
7287 "Message-ID" "Xref" "References" "Body"))
7288 nil 'require-match))
7289 (read-string "Regexp: ")
7290 (read-key-sequence "Command: ")
7291 current-prefix-arg))
7292 (when (equal header "Body")
7293 (setq header ""))
eec82323
LMI
7294 ;; Hidden thread subtrees must be searched as well.
7295 (gnus-summary-show-all-threads)
7296 ;; We don't want to change current point nor window configuration.
7297 (save-excursion
7298 (save-window-excursion
7299 (gnus-message 6 "Executing %s..." (key-description command))
7300 ;; We'd like to execute COMMAND interactively so as to give arguments.
7301 (gnus-execute header regexp
7302 `(call-interactively ',(key-binding command))
7303 backward)
7304 (gnus-message 6 "Executing %s...done" (key-description command)))))
7305
7306(defun gnus-summary-beginning-of-article ()
7307 "Scroll the article back to the beginning."
7308 (interactive)
eec82323
LMI
7309 (gnus-summary-select-article)
7310 (gnus-configure-windows 'article)
7311 (gnus-eval-in-buffer-window gnus-article-buffer
7312 (widen)
7313 (goto-char (point-min))
7314 (when gnus-page-broken
7315 (gnus-narrow-to-page))))
7316
7317(defun gnus-summary-end-of-article ()
7318 "Scroll to the end of the article."
7319 (interactive)
eec82323
LMI
7320 (gnus-summary-select-article)
7321 (gnus-configure-windows 'article)
7322 (gnus-eval-in-buffer-window gnus-article-buffer
7323 (widen)
7324 (goto-char (point-max))
7325 (recenter -3)
7326 (when gnus-page-broken
7327 (gnus-narrow-to-page))))
7328
6748645f
LMI
7329(defun gnus-summary-print-article (&optional filename n)
7330 "Generate and print a PostScript image of the N next (mail) articles.
7331
7332If N is negative, print the N previous articles. If N is nil and articles
7333have been marked with the process mark, print these instead.
eec82323 7334
16409b0b 7335If the optional first argument FILENAME is nil, send the image to the
6748645f
LMI
7336printer. If FILENAME is a string, save the PostScript image in a file with
7337that name. If FILENAME is a number, prompt the user for the name of the file
eec82323 7338to save in."
676a7cc9 7339 (interactive (list (ps-print-preprint current-prefix-arg)))
6748645f
LMI
7340 (dolist (article (gnus-summary-work-articles n))
7341 (gnus-summary-select-article nil nil 'pseudo article)
7342 (gnus-eval-in-buffer-window gnus-article-buffer
7343 (let ((buffer (generate-new-buffer " *print*")))
7344 (unwind-protect
7345 (progn
7346 (copy-to-buffer buffer (point-min) (point-max))
7347 (set-buffer buffer)
7348 (gnus-article-delete-invisible-text)
7349 (let ((ps-left-header
7350 (list
7351 (concat "("
7352 (mail-header-subject gnus-current-headers) ")")
7353 (concat "("
7354 (mail-header-from gnus-current-headers) ")")))
7355 (ps-right-header
7356 (list
7357 "/pagenumberstring load"
7358 (concat "("
7359 (mail-header-date gnus-current-headers) ")"))))
7360 (gnus-run-hooks 'gnus-ps-print-hook)
7361 (save-excursion
676a7cc9
SZ
7362 (ps-spool-buffer-with-faces))))
7363 (kill-buffer buffer))))
7364 (gnus-summary-remove-process-mark article))
7365 (ps-despool filename))
eec82323
LMI
7366
7367(defun gnus-summary-show-article (&optional arg)
7368 "Force re-fetching of the current article.
16409b0b
GM
7369If ARG (the prefix) is a number, show the article with the charset
7370defined in `gnus-summary-show-article-charset-alist', or the charset
7371inputed.
7372If ARG (the prefix) is non-nil and not a number, show the raw article
7373without any article massaging functions being run."
eec82323 7374 (interactive "P")
16409b0b
GM
7375 (cond
7376 ((numberp arg)
7377 (let ((gnus-newsgroup-charset
7378 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7379 (read-coding-system "Charset: ")))
7380 (gnus-newsgroup-ignored-charsets 'gnus-all))
7381 (gnus-summary-select-article nil 'force)))
7382 ((not arg)
7383 ;; Select the article the normal way.
7384 (gnus-summary-select-article nil 'force))
7385 (t
7386 ;; We have to require this here to make sure that the following
7387 ;; dynamic binding isn't shadowed by autoloading.
7388 (require 'gnus-async)
7389 (require 'gnus-art)
eec82323
LMI
7390 ;; Bind the article treatment functions to nil.
7391 (let ((gnus-have-all-headers t)
eec82323 7392 gnus-article-prepare-hook
16409b0b
GM
7393 gnus-article-decode-hook
7394 gnus-display-mime-function
7395 gnus-break-pages)
7396 ;; Destroy any MIME parts.
7397 (when (gnus-buffer-live-p gnus-article-buffer)
7398 (save-excursion
7399 (set-buffer gnus-article-buffer)
7400 (mm-destroy-parts gnus-article-mime-handles)
7401 ;; Set it to nil for safety reason.
7402 (setq gnus-article-mime-handle-alist nil)
7403 (setq gnus-article-mime-handles nil)))
7404 (gnus-summary-select-article nil 'force))))
eec82323
LMI
7405 (gnus-summary-goto-subject gnus-current-article)
7406 (gnus-summary-position-point))
7407
7408(defun gnus-summary-verbose-headers (&optional arg)
7409 "Toggle permanent full header display.
7410If ARG is a positive number, turn header display on.
7411If ARG is a negative number, turn header display off."
7412 (interactive "P")
eec82323
LMI
7413 (setq gnus-show-all-headers
7414 (cond ((or (not (numberp arg))
7415 (zerop arg))
7416 (not gnus-show-all-headers))
7417 ((natnump arg)
7418 t)))
7419 (gnus-summary-show-article))
7420
7421(defun gnus-summary-toggle-header (&optional arg)
7422 "Show the headers if they are hidden, or hide them if they are shown.
7423If ARG is a positive number, show the entire header.
7424If ARG is a negative number, hide the unwanted header lines."
7425 (interactive "P")
eec82323
LMI
7426 (save-excursion
7427 (set-buffer gnus-article-buffer)
16409b0b
GM
7428 (save-restriction
7429 (let* ((buffer-read-only nil)
7430 (inhibit-point-motion-hooks t)
7431 hidden e)
7432 (setq hidden
7433 (if (numberp arg)
7434 (>= arg 0)
7435 (save-restriction
7436 (article-narrow-to-head)
7437 (gnus-article-hidden-text-p 'headers))))
7438 (goto-char (point-min))
7439 (when (search-forward "\n\n" nil t)
7440 (delete-region (point-min) (1- (point))))
eec82323 7441 (goto-char (point-min))
16409b0b
GM
7442 (save-excursion
7443 (set-buffer gnus-original-article-buffer)
7444 (goto-char (point-min))
7445 (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7446 (insert-buffer-substring gnus-original-article-buffer 1 e)
7447 (save-restriction
7448 (narrow-to-region (point-min) (point))
7449 (article-decode-encoded-words)
7450 (if hidden
7451 (let ((gnus-treat-hide-headers nil)
7452 (gnus-treat-hide-boring-headers nil))
7453 (setq gnus-article-wash-types
7454 (delq 'headers gnus-article-wash-types))
7455 (gnus-treat-article 'head))
7456 (gnus-treat-article 'head)))
7457 (gnus-set-mode-line 'article)))))
eec82323
LMI
7458
7459(defun gnus-summary-show-all-headers ()
7460 "Make all header lines visible."
7461 (interactive)
eec82323
LMI
7462 (gnus-article-show-all-headers))
7463
eec82323
LMI
7464(defun gnus-summary-caesar-message (&optional arg)
7465 "Caesar rotate the current article by 13.
7466The numerical prefix specifies how many places to rotate each letter
7467forward."
7468 (interactive "P")
eec82323
LMI
7469 (gnus-summary-select-article)
7470 (let ((mail-header-separator ""))
7471 (gnus-eval-in-buffer-window gnus-article-buffer
7472 (save-restriction
7473 (widen)
7474 (let ((start (window-start))
7475 buffer-read-only)
7476 (message-caesar-buffer-body arg)
7477 (set-window-start (get-buffer-window (current-buffer)) start))))))
7478
7479(defun gnus-summary-stop-page-breaking ()
7480 "Stop page breaking in the current article."
7481 (interactive)
eec82323
LMI
7482 (gnus-summary-select-article)
7483 (gnus-eval-in-buffer-window gnus-article-buffer
7484 (widen)
7485 (when (gnus-visual-p 'page-marker)
7486 (let ((buffer-read-only nil))
7487 (gnus-remove-text-with-property 'gnus-prev)
6748645f
LMI
7488 (gnus-remove-text-with-property 'gnus-next))
7489 (setq gnus-page-broken nil))))
eec82323
LMI
7490
7491(defun gnus-summary-move-article (&optional n to-newsgroup
7492 select-method action)
7493 "Move the current article to a different newsgroup.
7494If N is a positive number, move the N next articles.
7495If N is a negative number, move the N previous articles.
7496If N is nil and any articles have been marked with the process mark,
7497move those articles instead.
7498If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7499If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7500re-spool using this method.
7501
7502For this function to work, both the current newsgroup and the
7503newsgroup that you want to move to have to support the `request-move'
16409b0b
GM
7504and `request-accept' functions.
7505
7506ACTION can be either `move' (the default), `crosspost' or `copy'."
eec82323
LMI
7507 (interactive "P")
7508 (unless action
7509 (setq action 'move))
eec82323
LMI
7510 ;; Disable marking as read.
7511 (let (gnus-mark-article-hook)
7512 (save-window-excursion
7513 (gnus-summary-select-article)))
7514 ;; Check whether the source group supports the required functions.
7515 (cond ((and (eq action 'move)
7516 (not (gnus-check-backend-function
7517 'request-move-article gnus-newsgroup-name)))
7518 (error "The current group does not support article moving"))
7519 ((and (eq action 'crosspost)
7520 (not (gnus-check-backend-function
7521 'request-replace-article gnus-newsgroup-name)))
7522 (error "The current group does not support article editing")))
7523 (let ((articles (gnus-summary-work-articles n))
16409b0b
GM
7524 (prefix (if (gnus-check-backend-function
7525 'request-move-article gnus-newsgroup-name)
7526 (gnus-group-real-prefix gnus-newsgroup-name)
7527 ""))
eec82323
LMI
7528 (names '((move "Move" "Moving")
7529 (copy "Copy" "Copying")
7530 (crosspost "Crosspost" "Crossposting")))
7531 (copy-buf (save-excursion
7532 (nnheader-set-temp-buffer " *copy article*")))
7533 art-group to-method new-xref article to-groups)
7534 (unless (assq action names)
7535 (error "Unknown action %s" action))
7536 ;; Read the newsgroup name.
7537 (when (and (not to-newsgroup)
7538 (not select-method))
7539 (setq to-newsgroup
7540 (gnus-read-move-group-name
7541 (cadr (assq action names))
7542 (symbol-value (intern (format "gnus-current-%s-group" action)))
7543 articles prefix))
7544 (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7545 (setq to-method (or select-method
16409b0b
GM
7546 (gnus-server-to-method
7547 (gnus-group-method to-newsgroup))))
eec82323
LMI
7548 ;; Check the method we are to move this article to...
7549 (unless (gnus-check-backend-function
7550 'request-accept-article (car to-method))
7551 (error "%s does not support article copying" (car to-method)))
7552 (unless (gnus-check-server to-method)
7553 (error "Can't open server %s" (car to-method)))
7554 (gnus-message 6 "%s to %s: %s..."
7555 (caddr (assq action names))
7556 (or (car select-method) to-newsgroup) articles)
7557 (while articles
7558 (setq article (pop articles))
7559 (setq
7560 art-group
7561 (cond
7562 ;; Move the article.
7563 ((eq action 'move)
a8151ef7
LMI
7564 ;; Remove this article from future suppression.
7565 (gnus-dup-unsuppress-article article)
eec82323
LMI
7566 (gnus-request-move-article
7567 article ; Article to move
7568 gnus-newsgroup-name ; From newsgroup
7569 (nth 1 (gnus-find-method-for-group
7570 gnus-newsgroup-name)) ; Server
7571 (list 'gnus-request-accept-article
7572 to-newsgroup (list 'quote select-method)
16409b0b 7573 (not articles) t) ; Accept form
eec82323
LMI
7574 (not articles))) ; Only save nov last time
7575 ;; Copy the article.
7576 ((eq action 'copy)
7577 (save-excursion
7578 (set-buffer copy-buf)
6748645f
LMI
7579 (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7580 (gnus-request-accept-article
16409b0b 7581 to-newsgroup select-method (not articles) t))))
eec82323
LMI
7582 ;; Crosspost the article.
7583 ((eq action 'crosspost)
7584 (let ((xref (message-tokenize-header
7585 (mail-header-xref (gnus-summary-article-header article))
7586 " ")))
7587 (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7588 ":" article))
7589 (unless xref
7590 (setq xref (list (system-name))))
7591 (setq new-xref
7592 (concat
7593 (mapconcat 'identity
7594 (delete "Xref:" (delete new-xref xref))
7595 " ")
7596 " " new-xref))
7597 (save-excursion
7598 (set-buffer copy-buf)
7599 ;; First put the article in the destination group.
7600 (gnus-request-article-this-buffer article gnus-newsgroup-name)
7601 (when (consp (setq art-group
7602 (gnus-request-accept-article
7603 to-newsgroup select-method (not articles))))
7604 (setq new-xref (concat new-xref " " (car art-group)
7605 ":" (cdr art-group)))
7606 ;; Now we have the new Xrefs header, so we insert
7607 ;; it and replace the new article.
7608 (nnheader-replace-header "Xref" new-xref)
7609 (gnus-request-replace-article
7610 (cdr art-group) to-newsgroup (current-buffer))
7611 art-group))))))
7612 (cond
7613 ((not art-group)
16409b0b
GM
7614 (gnus-message 1 "Couldn't %s article %s: %s"
7615 (cadr (assq action names)) article
7616 (nnheader-get-report (car to-method))))
7617 ((eq art-group 'junk)
7618 (when (eq action 'move)
7619 (gnus-summary-mark-article article gnus-canceled-mark)
7620 (gnus-message 4 "Deleted article %s" article)))
eec82323 7621 (t
6748645f
LMI
7622 (let* ((pto-group (gnus-group-prefixed-name
7623 (car art-group) to-method))
7624 (entry
7625 (gnus-gethash pto-group gnus-newsrc-hashtb))
eec82323 7626 (info (nth 2 entry))
16409b0b
GM
7627 (to-group (gnus-info-group info))
7628 to-marks)
eec82323
LMI
7629 ;; Update the group that has been moved to.
7630 (when (and info
7631 (memq action '(move copy)))
7632 (unless (member to-group to-groups)
7633 (push to-group to-groups))
7634
7635 (unless (memq article gnus-newsgroup-unreads)
16409b0b 7636 (push 'read to-marks)
eec82323
LMI
7637 (gnus-info-set-read
7638 info (gnus-add-to-range (gnus-info-read info)
7639 (list (cdr art-group)))))
7640
16409b0b 7641 ;; See whether the article is to be put in the cache.
eec82323
LMI
7642 (let ((marks gnus-article-mark-lists)
7643 (to-article (cdr art-group)))
7644
16409b0b
GM
7645 ;; Enter the article into the cache in the new group,
7646 ;; if that is required.
eec82323
LMI
7647 (when gnus-use-cache
7648 (gnus-cache-possibly-enter-article
7649 to-group to-article
eec82323
LMI
7650 (memq article gnus-newsgroup-marked)
7651 (memq article gnus-newsgroup-dormant)
7652 (memq article gnus-newsgroup-unreads)))
7653
16409b0b
GM
7654 (when gnus-preserve-marks
7655 ;; Copy any marks over to the new group.
7656 (when (and (equal to-group gnus-newsgroup-name)
7657 (not (memq article gnus-newsgroup-unreads)))
7658 ;; Mark this article as read in this group.
7659 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7660 (setcdr (gnus-active to-group) to-article)
7661 (setcdr gnus-newsgroup-active to-article))
7662
7663 (while marks
7664 (when (memq article (symbol-value
7665 (intern (format "gnus-newsgroup-%s"
7666 (caar marks)))))
7667 (push (cdar marks) to-marks)
7668 ;; If the other group is the same as this group,
7669 ;; then we have to add the mark to the list.
7670 (when (equal to-group gnus-newsgroup-name)
7671 (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7672 (cons to-article
7673 (symbol-value
7674 (intern (format "gnus-newsgroup-%s"
7675 (caar marks)))))))
7676 ;; Copy the marks to other group.
7677 (gnus-add-marked-articles
7678 to-group (cdar marks) (list to-article) info))
7679 (setq marks (cdr marks)))
7680
7681 (gnus-request-set-mark to-group (list (list (list to-article)
7682 'set
7683 to-marks))))
eec82323
LMI
7684
7685 (gnus-dribble-enter
7686 (concat "(gnus-group-set-info '"
7687 (gnus-prin1-to-string (gnus-get-info to-group))
7688 ")"))))
7689
7690 ;; Update the Xref header in this article to point to
7691 ;; the new crossposted article we have just created.
7692 (when (eq action 'crosspost)
7693 (save-excursion
7694 (set-buffer copy-buf)
7695 (gnus-request-article-this-buffer article gnus-newsgroup-name)
7696 (nnheader-replace-header "Xref" new-xref)
7697 (gnus-request-replace-article
7698 article gnus-newsgroup-name (current-buffer)))))
7699
6748645f
LMI
7700 ;;;!!!Why is this necessary?
7701 (set-buffer gnus-summary-buffer)
7702
eec82323
LMI
7703 (gnus-summary-goto-subject article)
7704 (when (eq action 'move)
7705 (gnus-summary-mark-article article gnus-canceled-mark))))
7706 (gnus-summary-remove-process-mark article))
7707 ;; Re-activate all groups that have been moved to.
7708 (while to-groups
7709 (save-excursion
7710 (set-buffer gnus-group-buffer)
7711 (when (gnus-group-goto-group (car to-groups) t)
a8151ef7 7712 (gnus-group-get-new-news-this-group 1 t))
eec82323
LMI
7713 (pop to-groups)))
7714
7715 (gnus-kill-buffer copy-buf)
7716 (gnus-summary-position-point)
7717 (gnus-set-mode-line 'summary)))
7718
7719(defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7720 "Move the current article to a different newsgroup.
7721If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7722If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7723re-spool using this method."
7724 (interactive "P")
7725 (gnus-summary-move-article n to-newsgroup select-method 'copy))
7726
7727(defun gnus-summary-crosspost-article (&optional n)
7728 "Crosspost the current article to some other group."
7729 (interactive "P")
7730 (gnus-summary-move-article n nil nil 'crosspost))
7731
7732(defcustom gnus-summary-respool-default-method nil
7733 "Default method for respooling an article.
7734If nil, use to the current newsgroup method."
04ad70ac
KH
7735 :type '(choice (gnus-select-method :value (nnml ""))
7736 (const nil))
eec82323
LMI
7737 :group 'gnus-summary-mail)
7738
7739(defun gnus-summary-respool-article (&optional n method)
7740 "Respool the current article.
7741The article will be squeezed through the mail spooling process again,
7742which means that it will be put in some mail newsgroup or other
7743depending on `nnmail-split-methods'.
7744If N is a positive number, respool the N next articles.
7745If N is a negative number, respool the N previous articles.
7746If N is nil and any articles have been marked with the process mark,
7747respool those articles instead.
7748
7749Respooling can be done both from mail groups and \"real\" newsgroups.
7750In the former case, the articles in question will be moved from the
7751current group into whatever groups they are destined to. In the
7752latter case, they will be copied into the relevant groups."
7753 (interactive
7754 (list current-prefix-arg
7755 (let* ((methods (gnus-methods-using 'respool))
7756 (methname
7757 (symbol-name (or gnus-summary-respool-default-method
7758 (car (gnus-find-method-for-group
7759 gnus-newsgroup-name)))))
7760 (method
7761 (gnus-completing-read
7762 methname "What backend do you want to use when respooling?"
7763 methods nil t nil 'gnus-mail-method-history))
7764 ms)
7765 (cond
7766 ((zerop (length (setq ms (gnus-servers-using-backend
7767 (intern method)))))
7768 (list (intern method) ""))
7769 ((= 1 (length ms))
7770 (car ms))
7771 (t
7772 (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7773 (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7774 ms-alist))))))))
eec82323
LMI
7775 (unless method
7776 (error "No method given for respooling"))
7777 (if (assoc (symbol-name
7778 (car (gnus-find-method-for-group gnus-newsgroup-name)))
7779 (gnus-methods-using 'respool))
7780 (gnus-summary-move-article n nil method)
7781 (gnus-summary-copy-article n nil method)))
7782
7783(defun gnus-summary-import-article (file)
6748645f 7784 "Import an arbitrary file into a mail newsgroup."
eec82323 7785 (interactive "fImport file: ")
eec82323
LMI
7786 (let ((group gnus-newsgroup-name)
7787 (now (current-time))
7788 atts lines)
7789 (unless (gnus-check-backend-function 'request-accept-article group)
7790 (error "%s does not support article importing" group))
7791 (or (file-readable-p file)
7792 (not (file-regular-p file))
7793 (error "Can't read %s" file))
7794 (save-excursion
6748645f 7795 (set-buffer (gnus-get-buffer-create " *import file*"))
eec82323 7796 (erase-buffer)
16409b0b 7797 (nnheader-insert-file-contents file)
eec82323
LMI
7798 (goto-char (point-min))
7799 (unless (nnheader-article-p)
7800 ;; This doesn't look like an article, so we fudge some headers.
7801 (setq atts (file-attributes file)
7802 lines (count-lines (point-min) (point-max)))
7803 (insert "From: " (read-string "From: ") "\n"
7804 "Subject: " (read-string "Subject: ") "\n"
16409b0b 7805 "Date: " (message-make-date (nth 5 atts))
eec82323
LMI
7806 "\n"
7807 "Message-ID: " (message-make-message-id) "\n"
7808 "Lines: " (int-to-string lines) "\n"
7809 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7810 (gnus-request-accept-article group nil t)
7811 (kill-buffer (current-buffer)))))
7812
7813(defun gnus-summary-article-posted-p ()
16409b0b 7814 "Say whether the current (mail) article is available from news as well.
eec82323
LMI
7815This will be the case if the article has both been mailed and posted."
7816 (interactive)
7817 (let ((id (mail-header-references (gnus-summary-article-header)))
16409b0b 7818 (gnus-override-method (car (gnus-refer-article-methods))))
eec82323
LMI
7819 (if (gnus-request-head id "")
7820 (gnus-message 2 "The current message was found on %s"
7821 gnus-override-method)
7822 (gnus-message 2 "The current message couldn't be found on %s"
7823 gnus-override-method)
7824 nil)))
7825
7826(defun gnus-summary-expire-articles (&optional now)
7827 "Expire all articles that are marked as expirable in the current group."
7828 (interactive)
eec82323
LMI
7829 (when (gnus-check-backend-function
7830 'request-expire-articles gnus-newsgroup-name)
7831 ;; This backend supports expiry.
7832 (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7833 (expirable (if total
7834 (progn
7835 ;; We need to update the info for
7836 ;; this group for `gnus-list-of-read-articles'
7837 ;; to give us the right answer.
6748645f 7838 (gnus-run-hooks 'gnus-exit-group-hook)
eec82323
LMI
7839 (gnus-summary-update-info)
7840 (gnus-list-of-read-articles gnus-newsgroup-name))
7841 (setq gnus-newsgroup-expirable
7842 (sort gnus-newsgroup-expirable '<))))
7843 (expiry-wait (if now 'immediate
7844 (gnus-group-find-parameter
7845 gnus-newsgroup-name 'expiry-wait)))
16409b0b
GM
7846 (nnmail-expiry-target
7847 (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
7848 nnmail-expiry-target))
eec82323
LMI
7849 es)
7850 (when expirable
7851 ;; There are expirable articles in this group, so we run them
7852 ;; through the expiry process.
7853 (gnus-message 6 "Expiring articles...")
16409b0b
GM
7854 (unless (gnus-check-group gnus-newsgroup-name)
7855 (error "Can't open server for %s" gnus-newsgroup-name))
eec82323 7856 ;; The list of articles that weren't expired is returned.
6748645f
LMI
7857 (save-excursion
7858 (if expiry-wait
7859 (let ((nnmail-expiry-wait-function nil)
7860 (nnmail-expiry-wait expiry-wait))
7861 (setq es (gnus-request-expire-articles
7862 expirable gnus-newsgroup-name)))
7863 (setq es (gnus-request-expire-articles
7864 expirable gnus-newsgroup-name))))
eec82323
LMI
7865 (unless total
7866 (setq gnus-newsgroup-expirable es))
7867 ;; We go through the old list of expirable, and mark all
7868 ;; really expired articles as nonexistent.
7869 (unless (eq es expirable) ;If nothing was expired, we don't mark.
7870 (let ((gnus-use-cache nil))
7871 (while expirable
7872 (unless (memq (car expirable) es)
7873 (when (gnus-data-find (car expirable))
7874 (gnus-summary-mark-article
7875 (car expirable) gnus-canceled-mark)))
7876 (setq expirable (cdr expirable)))))
7877 (gnus-message 6 "Expiring articles...done")))))
7878
7879(defun gnus-summary-expire-articles-now ()
7880 "Expunge all expirable articles in the current group.
7881This means that *all* articles that are marked as expirable will be
7882deleted forever, right now."
7883 (interactive)
eec82323
LMI
7884 (or gnus-expert-user
7885 (gnus-yes-or-no-p
7886 "Are you really, really, really sure you want to delete all these messages? ")
7887 (error "Phew!"))
7888 (gnus-summary-expire-articles t))
7889
7890;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7891(defun gnus-summary-delete-article (&optional n)
7892 "Delete the N next (mail) articles.
7893This command actually deletes articles. This is not a marking
7894command. The article will disappear forever from your life, never to
7895return.
7896If N is negative, delete backwards.
7897If N is nil and articles have been marked with the process mark,
7898delete these instead."
7899 (interactive "P")
eec82323
LMI
7900 (unless (gnus-check-backend-function 'request-expire-articles
7901 gnus-newsgroup-name)
a8151ef7 7902 (error "The current newsgroup does not support article deletion"))
16409b0b
GM
7903 (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7904 (error "Couldn't open server"))
eec82323 7905 ;; Compute the list of articles to delete.
6748645f 7906 (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
eec82323
LMI
7907 not-deleted)
7908 (if (and gnus-novice-user
7909 (not (gnus-yes-or-no-p
7910 (format "Do you really want to delete %s forever? "
7911 (if (> (length articles) 1)
7912 (format "these %s articles" (length articles))
7913 "this article")))))
7914 ()
7915 ;; Delete the articles.
7916 (setq not-deleted (gnus-request-expire-articles
7917 articles gnus-newsgroup-name 'force))
7918 (while articles
7919 (gnus-summary-remove-process-mark (car articles))
7920 ;; The backend might not have been able to delete the article
7921 ;; after all.
7922 (unless (memq (car articles) not-deleted)
7923 (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7924 (setq articles (cdr articles)))
7925 (when not-deleted
7926 (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7927 (gnus-summary-position-point)
7928 (gnus-set-mode-line 'summary)
7929 not-deleted))
7930
16409b0b 7931(defun gnus-summary-edit-article (&optional arg)
eec82323
LMI
7932 "Edit the current article.
7933This will have permanent effect only in mail groups.
16409b0b
GM
7934If ARG is nil, edit the decoded articles.
7935If ARG is 1, edit the raw articles.
7936If ARG is 2, edit the raw articles even in read-only groups.
7937Otherwise, allow editing of articles even in read-only
eec82323
LMI
7938groups."
7939 (interactive "P")
16409b0b
GM
7940 (let (force raw)
7941 (cond
7942 ((null arg))
7943 ((eq arg 1) (setq raw t))
7944 ((eq arg 2) (setq raw t
7945 force t))
7946 (t (setq force t)))
7947 (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
715a2ca2 7948 (error "Can't edit the raw article in group nndraft:drafts"))
16409b0b
GM
7949 (save-excursion
7950 (set-buffer gnus-summary-buffer)
7951 (let ((mail-parse-charset gnus-newsgroup-charset)
7952 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
7953 (gnus-set-global-variables)
7954 (when (and (not force)
7955 (gnus-group-read-only-p))
7956 (error "The current newsgroup does not support article editing"))
7957 (gnus-summary-show-article t)
7958 (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
7959 (with-current-buffer gnus-article-buffer
d4dfaa19 7960 (mm-enable-multibyte-mule4)))
16409b0b
GM
7961 (if (equal gnus-newsgroup-name "nndraft:drafts")
7962 (setq raw t))
7963 (gnus-article-edit-article
7964 (if raw 'ignore
7965 #'(lambda ()
7966 (let ((mbl mml-buffer-list))
7967 (setq mml-buffer-list nil)
7968 (mime-to-mml)
7969 (make-local-hook 'kill-buffer-hook)
7970 (let ((mml-buffer-list mml-buffer-list))
7971 (setq mml-buffer-list mbl)
7972 (make-local-variable 'mml-buffer-list))
7973 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
7974 `(lambda (no-highlight)
7975 (let ((mail-parse-charset ',gnus-newsgroup-charset)
7976 (mail-parse-ignored-charsets
7977 ',gnus-newsgroup-ignored-charsets))
7978 ,(if (not raw) '(progn
7979 (mml-to-mime)
7980 (mml-destroy-buffers)
7981 (remove-hook 'kill-buffer-hook
7982 'mml-destroy-buffers t)
7983 (kill-local-variable 'mml-buffer-list)))
7984 (gnus-summary-edit-article-done
7985 ,(or (mail-header-references gnus-current-headers) "")
7986 ,(gnus-group-read-only-p)
7987 ,gnus-summary-buffer no-highlight))))))))
eec82323
LMI
7988
7989(defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7990
6748645f
LMI
7991(defun gnus-summary-edit-article-done (&optional references read-only buffer
7992 no-highlight)
eec82323
LMI
7993 "Make edits to the current article permanent."
7994 (interactive)
7995 ;; Replace the article.
6748645f 7996 (let ((buf (current-buffer)))
16409b0b
GM
7997 (with-temp-buffer
7998 (insert-buffer-substring buf)
6748645f
LMI
7999 (if (and (not read-only)
8000 (not (gnus-request-replace-article
8001 (cdr gnus-article-current) (car gnus-article-current)
16409b0b 8002 (current-buffer) t)))
6748645f
LMI
8003 (error "Couldn't replace article")
8004 ;; Update the summary buffer.
8005 (if (and references
8006 (equal (message-tokenize-header references " ")
8007 (message-tokenize-header
8008 (or (message-fetch-field "references") "") " ")))
8009 ;; We only have to update this line.
8010 (save-excursion
8011 (save-restriction
8012 (message-narrow-to-head)
8013 (let ((head (buffer-string))
8014 header)
16409b0b 8015 (with-temp-buffer
6748645f
LMI
8016 (insert (format "211 %d Article retrieved.\n"
8017 (cdr gnus-article-current)))
8018 (insert head)
8019 (insert ".\n")
8020 (let ((nntp-server-buffer (current-buffer)))
8021 (setq header (car (gnus-get-newsgroup-headers
8022 (save-excursion
8023 (set-buffer gnus-summary-buffer)
8024 gnus-newsgroup-dependencies)
8025 t))))
8026 (save-excursion
8027 (set-buffer gnus-summary-buffer)
8028 (gnus-data-set-header
8029 (gnus-data-find (cdr gnus-article-current))
8030 header)
8031 (gnus-summary-update-article-line
8032 (cdr gnus-article-current) header))))))
8033 ;; Update threads.
8034 (set-buffer (or buffer gnus-summary-buffer))
8035 (gnus-summary-update-article (cdr gnus-article-current)))
8036 ;; Prettify the article buffer again.
8037 (unless no-highlight
8038 (save-excursion
8039 (set-buffer gnus-article-buffer)
16409b0b
GM
8040 ;;;!!! Fix this -- article should be rehighlighted.
8041 ;;;(gnus-run-hooks 'gnus-article-display-hook)
6748645f
LMI
8042 (set-buffer gnus-original-article-buffer)
8043 (gnus-request-article
8044 (cdr gnus-article-current)
8045 (car gnus-article-current) (current-buffer))))
8046 ;; Prettify the summary buffer line.
8047 (when (gnus-visual-p 'summary-highlight 'highlight)
8048 (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
eec82323
LMI
8049
8050(defun gnus-summary-edit-wash (key)
6748645f 8051 "Perform editing command KEY in the article buffer."
eec82323
LMI
8052 (interactive
8053 (list
8054 (progn
8055 (message "%s" (concat (this-command-keys) "- "))
8056 (read-char))))
8057 (message "")
8058 (gnus-summary-edit-article)
8059 (execute-kbd-macro (concat (this-command-keys) key))
8060 (gnus-article-edit-done))
8061
8062;;; Respooling
8063
6748645f 8064(defun gnus-summary-respool-query (&optional silent trace)
eec82323
LMI
8065 "Query where the respool algorithm would put this article."
8066 (interactive)
eec82323
LMI
8067 (let (gnus-mark-article-hook)
8068 (gnus-summary-select-article)
8069 (save-excursion
8070 (set-buffer gnus-original-article-buffer)
8071 (save-restriction
8072 (message-narrow-to-head)
6748645f 8073 (let ((groups (nnmail-article-group 'identity trace)))
eec82323
LMI
8074 (unless silent
8075 (if groups
8076 (message "This message would go to %s"
8077 (mapconcat 'car groups ", "))
8078 (message "This message would go to no groups"))
8079 groups))))))
8080
6748645f
LMI
8081(defun gnus-summary-respool-trace ()
8082 "Trace where the respool algorithm would put this article.
8083Display a buffer showing all fancy splitting patterns which matched."
8084 (interactive)
8085 (gnus-summary-respool-query nil t))
8086
eec82323
LMI
8087;; Summary marking commands.
8088
8089(defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8090 "Mark articles which has the same subject as read, and then select the next.
8091If UNMARK is positive, remove any kind of mark.
8092If UNMARK is negative, tick articles."
8093 (interactive "P")
eec82323
LMI
8094 (when unmark
8095 (setq unmark (prefix-numeric-value unmark)))
8096 (let ((count
8097 (gnus-summary-mark-same-subject
8098 (gnus-summary-article-subject) unmark)))
8099 ;; Select next unread article. If auto-select-same mode, should
8100 ;; select the first unread article.
8101 (gnus-summary-next-article t (and gnus-auto-select-same
8102 (gnus-summary-article-subject)))
8103 (gnus-message 7 "%d article%s marked as %s"
8104 count (if (= count 1) " is" "s are")
8105 (if unmark "unread" "read"))))
8106
8107(defun gnus-summary-kill-same-subject (&optional unmark)
8108 "Mark articles which has the same subject as read.
8109If UNMARK is positive, remove any kind of mark.
8110If UNMARK is negative, tick articles."
8111 (interactive "P")
eec82323
LMI
8112 (when unmark
8113 (setq unmark (prefix-numeric-value unmark)))
8114 (let ((count
8115 (gnus-summary-mark-same-subject
8116 (gnus-summary-article-subject) unmark)))
8117 ;; If marked as read, go to next unread subject.
8118 (when (null unmark)
8119 ;; Go to next unread subject.
8120 (gnus-summary-next-subject 1 t))
8121 (gnus-message 7 "%d articles are marked as %s"
8122 count (if unmark "unread" "read"))))
8123
8124(defun gnus-summary-mark-same-subject (subject &optional unmark)
8125 "Mark articles with same SUBJECT as read, and return marked number.
8126If optional argument UNMARK is positive, remove any kinds of marks.
8127If optional argument UNMARK is negative, mark articles as unread instead."
8128 (let ((count 1))
8129 (save-excursion
8130 (cond
8131 ((null unmark) ; Mark as read.
8132 (while (and
8133 (progn
8134 (gnus-summary-mark-article-as-read gnus-killed-mark)
8135 (gnus-summary-show-thread) t)
8136 (gnus-summary-find-subject subject))
8137 (setq count (1+ count))))
8138 ((> unmark 0) ; Tick.
8139 (while (and
8140 (progn
8141 (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8142 (gnus-summary-show-thread) t)
8143 (gnus-summary-find-subject subject))
8144 (setq count (1+ count))))
8145 (t ; Mark as unread.
8146 (while (and
8147 (progn
8148 (gnus-summary-mark-article-as-unread gnus-unread-mark)
8149 (gnus-summary-show-thread) t)
8150 (gnus-summary-find-subject subject))
8151 (setq count (1+ count)))))
8152 (gnus-set-mode-line 'summary)
8153 ;; Return the number of marked articles.
8154 count)))
8155
8156(defun gnus-summary-mark-as-processable (n &optional unmark)
8157 "Set the process mark on the next N articles.
8158If N is negative, mark backward instead. If UNMARK is non-nil, remove
8159the process mark instead. The difference between N and the actual
8160number of articles marked is returned."
8161 (interactive "p")
eec82323
LMI
8162 (let ((backward (< n 0))
8163 (n (abs n)))
8164 (while (and
8165 (> n 0)
8166 (if unmark
8167 (gnus-summary-remove-process-mark
8168 (gnus-summary-article-number))
8169 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8170 (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8171 (setq n (1- n)))
8172 (when (/= 0 n)
8173 (gnus-message 7 "No more articles"))
8174 (gnus-summary-recenter)
8175 (gnus-summary-position-point)
8176 n))
8177
8178(defun gnus-summary-unmark-as-processable (n)
8179 "Remove the process mark from the next N articles.
6748645f
LMI
8180If N is negative, unmark backward instead. The difference between N and
8181the actual number of articles unmarked is returned."
eec82323 8182 (interactive "p")
eec82323
LMI
8183 (gnus-summary-mark-as-processable n t))
8184
8185(defun gnus-summary-unmark-all-processable ()
8186 "Remove the process mark from all articles."
8187 (interactive)
eec82323
LMI
8188 (save-excursion
8189 (while gnus-newsgroup-processable
8190 (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8191 (gnus-summary-position-point))
8192
8193(defun gnus-summary-mark-as-expirable (n)
8194 "Mark N articles forward as expirable.
8195If N is negative, mark backward instead. The difference between N and
8196the actual number of articles marked is returned."
8197 (interactive "p")
eec82323
LMI
8198 (gnus-summary-mark-forward n gnus-expirable-mark))
8199
8200(defun gnus-summary-mark-article-as-replied (article)
8201 "Mark ARTICLE replied and update the summary line."
8202 (push article gnus-newsgroup-replied)
8203 (let ((buffer-read-only nil))
16409b0b 8204 (when (gnus-summary-goto-subject article nil t)
eec82323
LMI
8205 (gnus-summary-update-secondary-mark article))))
8206
8207(defun gnus-summary-set-bookmark (article)
8208 "Set a bookmark in current article."
8209 (interactive (list (gnus-summary-article-number)))
eec82323
LMI
8210 (when (or (not (get-buffer gnus-article-buffer))
8211 (not gnus-current-article)
8212 (not gnus-article-current)
8213 (not (equal gnus-newsgroup-name (car gnus-article-current))))
8214 (error "No current article selected"))
8215 ;; Remove old bookmark, if one exists.
8216 (let ((old (assq article gnus-newsgroup-bookmarks)))
8217 (when old
8218 (setq gnus-newsgroup-bookmarks
8219 (delq old gnus-newsgroup-bookmarks))))
8220 ;; Set the new bookmark, which is on the form
8221 ;; (article-number . line-number-in-body).
8222 (push
8223 (cons article
8224 (save-excursion
8225 (set-buffer gnus-article-buffer)
8226 (count-lines
8227 (min (point)
8228 (save-excursion
8229 (goto-char (point-min))
8230 (search-forward "\n\n" nil t)
8231 (point)))
8232 (point))))
8233 gnus-newsgroup-bookmarks)
8234 (gnus-message 6 "A bookmark has been added to the current article."))
8235
8236(defun gnus-summary-remove-bookmark (article)
8237 "Remove the bookmark from the current article."
8238 (interactive (list (gnus-summary-article-number)))
eec82323
LMI
8239 ;; Remove old bookmark, if one exists.
8240 (let ((old (assq article gnus-newsgroup-bookmarks)))
8241 (if old
8242 (progn
8243 (setq gnus-newsgroup-bookmarks
8244 (delq old gnus-newsgroup-bookmarks))
8245 (gnus-message 6 "Removed bookmark."))
8246 (gnus-message 6 "No bookmark in current article."))))
8247
8248;; Suggested by Daniel Quinlan <quinlan@best.com>.
8249(defun gnus-summary-mark-as-dormant (n)
8250 "Mark N articles forward as dormant.
8251If N is negative, mark backward instead. The difference between N and
8252the actual number of articles marked is returned."
8253 (interactive "p")
eec82323
LMI
8254 (gnus-summary-mark-forward n gnus-dormant-mark))
8255
8256(defun gnus-summary-set-process-mark (article)
8257 "Set the process mark on ARTICLE and update the summary line."
8258 (setq gnus-newsgroup-processable
8259 (cons article
8260 (delq article gnus-newsgroup-processable)))
8261 (when (gnus-summary-goto-subject article)
8262 (gnus-summary-show-thread)
6748645f 8263 (gnus-summary-goto-subject article)
eec82323
LMI
8264 (gnus-summary-update-secondary-mark article)))
8265
8266(defun gnus-summary-remove-process-mark (article)
8267 "Remove the process mark from ARTICLE and update the summary line."
8268 (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8269 (when (gnus-summary-goto-subject article)
8270 (gnus-summary-show-thread)
6748645f 8271 (gnus-summary-goto-subject article)
eec82323
LMI
8272 (gnus-summary-update-secondary-mark article)))
8273
8274(defun gnus-summary-set-saved-mark (article)
8275 "Set the process mark on ARTICLE and update the summary line."
8276 (push article gnus-newsgroup-saved)
8277 (when (gnus-summary-goto-subject article)
8278 (gnus-summary-update-secondary-mark article)))
8279
8280(defun gnus-summary-mark-forward (n &optional mark no-expire)
8281 "Mark N articles as read forwards.
8282If N is negative, mark backwards instead. Mark with MARK, ?r by default.
8283The difference between N and the actual number of articles marked is
16409b0b
GM
8284returned.
8285Iff NO-EXPIRE, auto-expiry will be inhibited."
eec82323 8286 (interactive "p")
16409b0b 8287 (gnus-summary-show-thread)
eec82323
LMI
8288 (let ((backward (< n 0))
8289 (gnus-summary-goto-unread
8290 (and gnus-summary-goto-unread
8291 (not (eq gnus-summary-goto-unread 'never))
8292 (not (memq mark (list gnus-unread-mark
8293 gnus-ticked-mark gnus-dormant-mark)))))
8294 (n (abs n))
8295 (mark (or mark gnus-del-mark)))
8296 (while (and (> n 0)
8297 (gnus-summary-mark-article nil mark no-expire)
8298 (zerop (gnus-summary-next-subject
8299 (if backward -1 1)
8300 (and gnus-summary-goto-unread
8301 (not (eq gnus-summary-goto-unread 'never)))
8302 t)))
8303 (setq n (1- n)))
8304 (when (/= 0 n)
8305 (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8306 (gnus-summary-recenter)
8307 (gnus-summary-position-point)
8308 (gnus-set-mode-line 'summary)
8309 n))
8310
8311(defun gnus-summary-mark-article-as-read (mark)
8312 "Mark the current article quickly as read with MARK."
8313 (let ((article (gnus-summary-article-number)))
8314 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8315 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8316 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8317 (push (cons article mark) gnus-newsgroup-reads)
8318 ;; Possibly remove from cache, if that is used.
8319 (when gnus-use-cache
8320 (gnus-cache-enter-remove-article article))
8321 ;; Allow the backend to change the mark.
8322 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8323 ;; Check for auto-expiry.
8324 (when (and gnus-newsgroup-auto-expire
16409b0b 8325 (memq mark gnus-auto-expirable-marks))
eec82323 8326 (setq mark gnus-expirable-mark)
6748645f
LMI
8327 ;; Let the backend know about the mark change.
8328 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
eec82323
LMI
8329 (push article gnus-newsgroup-expirable))
8330 ;; Set the mark in the buffer.
8331 (gnus-summary-update-mark mark 'unread)
8332 t))
8333
8334(defun gnus-summary-mark-article-as-unread (mark)
8335 "Mark the current article quickly as unread with MARK."
6748645f
LMI
8336 (let* ((article (gnus-summary-article-number))
8337 (old-mark (gnus-summary-article-mark article)))
8338 ;; Allow the backend to change the mark.
8339 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8340 (if (eq mark old-mark)
8341 t
8342 (if (<= article 0)
8343 (progn
8344 (gnus-error 1 "Can't mark negative article numbers")
8345 nil)
8346 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8347 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8348 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8349 (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8350 (cond ((= mark gnus-ticked-mark)
8351 (push article gnus-newsgroup-marked))
8352 ((= mark gnus-dormant-mark)
8353 (push article gnus-newsgroup-dormant))
8354 (t
8355 (push article gnus-newsgroup-unreads)))
8356 (gnus-pull article gnus-newsgroup-reads)
eec82323 8357
6748645f
LMI
8358 ;; See whether the article is to be put in the cache.
8359 (and gnus-use-cache
8360 (vectorp (gnus-summary-article-header article))
8361 (save-excursion
8362 (gnus-cache-possibly-enter-article
8363 gnus-newsgroup-name article
6748645f
LMI
8364 (= mark gnus-ticked-mark)
8365 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8366
8367 ;; Fix the mark.
8368 (gnus-summary-update-mark mark 'unread)
8369 t))))
eec82323
LMI
8370
8371(defun gnus-summary-mark-article (&optional article mark no-expire)
8372 "Mark ARTICLE with MARK. MARK can be any character.
8373Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8374`??' (dormant) and `?E' (expirable).
16409b0b 8375If MARK is nil, then the default character `?r' is used.
eec82323 8376If ARTICLE is nil, then the article on the current line will be
16409b0b
GM
8377marked.
8378Iff NO-EXPIRE, auto-expiry will be inhibited."
eec82323
LMI
8379 ;; The mark might be a string.
8380 (when (stringp mark)
8381 (setq mark (aref mark 0)))
8382 ;; If no mark is given, then we check auto-expiring.
16409b0b
GM
8383 (when (null mark)
8384 (setq mark gnus-del-mark))
8385 (when (and (not no-expire)
8386 gnus-newsgroup-auto-expire
8387 (memq mark gnus-auto-expirable-marks))
8388 (setq mark gnus-expirable-mark))
8389 (let ((article (or article (gnus-summary-article-number)))
8390 (old-mark (gnus-summary-article-mark article)))
6748645f
LMI
8391 ;; Allow the backend to change the mark.
8392 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8393 (if (eq mark old-mark)
8394 t
8395 (unless article
8396 (error "No article on current line"))
8397 (if (not (if (or (= mark gnus-unread-mark)
8398 (= mark gnus-ticked-mark)
8399 (= mark gnus-dormant-mark))
8400 (gnus-mark-article-as-unread article mark)
8401 (gnus-mark-article-as-read article mark)))
8402 t
8403 ;; See whether the article is to be put in the cache.
8404 (and gnus-use-cache
8405 (not (= mark gnus-canceled-mark))
8406 (vectorp (gnus-summary-article-header article))
8407 (save-excursion
8408 (gnus-cache-possibly-enter-article
8409 gnus-newsgroup-name article
6748645f
LMI
8410 (= mark gnus-ticked-mark)
8411 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8412
8413 (when (gnus-summary-goto-subject article nil t)
8414 (let ((buffer-read-only nil))
8415 (gnus-summary-show-thread)
8416 ;; Fix the mark.
8417 (gnus-summary-update-mark mark 'unread)
8418 t))))))
eec82323
LMI
8419
8420(defun gnus-summary-update-secondary-mark (article)
8421 "Update the secondary (read, process, cache) mark."
8422 (gnus-summary-update-mark
8423 (cond ((memq article gnus-newsgroup-processable)
8424 gnus-process-mark)
8425 ((memq article gnus-newsgroup-cached)
8426 gnus-cached-mark)
8427 ((memq article gnus-newsgroup-replied)
8428 gnus-replied-mark)
8429 ((memq article gnus-newsgroup-saved)
8430 gnus-saved-mark)
8431 (t gnus-unread-mark))
8432 'replied)
8433 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 8434 (gnus-run-hooks 'gnus-summary-update-hook))
eec82323
LMI
8435 t)
8436
8437(defun gnus-summary-update-mark (mark type)
8438 (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8439 (buffer-read-only nil))
8440 (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
16409b0b
GM
8441 (when forward
8442 (when (looking-at "\r")
8443 (incf forward))
8444 (when (<= (+ forward (point)) (point-max))
8445 ;; Go to the right position on the line.
8446 (goto-char (+ forward (point)))
8447 ;; Replace the old mark with the new mark.
8448 (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8449 ;; Optionally update the marks by some user rule.
8450 (when (eq type 'unread)
8451 (gnus-data-set-mark
8452 (gnus-data-find (gnus-summary-article-number)) mark)
8453 (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
eec82323
LMI
8454
8455(defun gnus-mark-article-as-read (article &optional mark)
8456 "Enter ARTICLE in the pertinent lists and remove it from others."
8457 ;; Make the article expirable.
8458 (let ((mark (or mark gnus-del-mark)))
8459 (if (= mark gnus-expirable-mark)
8460 (push article gnus-newsgroup-expirable)
8461 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8462 ;; Remove from unread and marked lists.
8463 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8464 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8465 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8466 (push (cons article mark) gnus-newsgroup-reads)
8467 ;; Possibly remove from cache, if that is used.
8468 (when gnus-use-cache
6748645f
LMI
8469 (gnus-cache-enter-remove-article article))
8470 t))
eec82323
LMI
8471
8472(defun gnus-mark-article-as-unread (article &optional mark)
8473 "Enter ARTICLE in the pertinent lists and remove it from others."
8474 (let ((mark (or mark gnus-ticked-mark)))
6748645f
LMI
8475 (if (<= article 0)
8476 (progn
8477 (gnus-error 1 "Can't mark negative article numbers")
8478 nil)
8479 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8480 gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8481 gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8482 gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
eec82323 8483
6748645f
LMI
8484 ;; Unsuppress duplicates?
8485 (when gnus-suppress-duplicates
8486 (gnus-dup-unsuppress-article article))
8487
8488 (cond ((= mark gnus-ticked-mark)
8489 (push article gnus-newsgroup-marked))
8490 ((= mark gnus-dormant-mark)
8491 (push article gnus-newsgroup-dormant))
8492 (t
8493 (push article gnus-newsgroup-unreads)))
8494 (gnus-pull article gnus-newsgroup-reads)
8495 t)))
eec82323
LMI
8496
8497(defalias 'gnus-summary-mark-as-unread-forward
8498 'gnus-summary-tick-article-forward)
8499(make-obsolete 'gnus-summary-mark-as-unread-forward
8500 'gnus-summary-tick-article-forward)
8501(defun gnus-summary-tick-article-forward (n)
8502 "Tick N articles forwards.
8503If N is negative, tick backwards instead.
8504The difference between N and the number of articles ticked is returned."
8505 (interactive "p")
8506 (gnus-summary-mark-forward n gnus-ticked-mark))
8507
8508(defalias 'gnus-summary-mark-as-unread-backward
8509 'gnus-summary-tick-article-backward)
8510(make-obsolete 'gnus-summary-mark-as-unread-backward
8511 'gnus-summary-tick-article-backward)
8512(defun gnus-summary-tick-article-backward (n)
8513 "Tick N articles backwards.
8514The difference between N and the number of articles ticked is returned."
8515 (interactive "p")
8516 (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8517
8518(defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8519(make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8520(defun gnus-summary-tick-article (&optional article clear-mark)
8521 "Mark current article as unread.
8522Optional 1st argument ARTICLE specifies article number to be marked as unread.
8523Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8524 (interactive)
8525 (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8526 gnus-ticked-mark)))
8527
8528(defun gnus-summary-mark-as-read-forward (n)
8529 "Mark N articles as read forwards.
8530If N is negative, mark backwards instead.
8531The difference between N and the actual number of articles marked is
8532returned."
8533 (interactive "p")
16409b0b 8534 (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
eec82323
LMI
8535
8536(defun gnus-summary-mark-as-read-backward (n)
8537 "Mark the N articles as read backwards.
8538The difference between N and the actual number of articles marked is
8539returned."
8540 (interactive "p")
16409b0b
GM
8541 (gnus-summary-mark-forward
8542 (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
eec82323
LMI
8543
8544(defun gnus-summary-mark-as-read (&optional article mark)
8545 "Mark current article as read.
8546ARTICLE specifies the article to be marked as read.
8547MARK specifies a string to be inserted at the beginning of the line."
8548 (gnus-summary-mark-article article mark))
8549
8550(defun gnus-summary-clear-mark-forward (n)
8551 "Clear marks from N articles forward.
8552If N is negative, clear backward instead.
8553The difference between N and the number of marks cleared is returned."
8554 (interactive "p")
8555 (gnus-summary-mark-forward n gnus-unread-mark))
8556
8557(defun gnus-summary-clear-mark-backward (n)
8558 "Clear marks from N articles backward.
8559The difference between N and the number of marks cleared is returned."
8560 (interactive "p")
8561 (gnus-summary-mark-forward (- n) gnus-unread-mark))
8562
8563(defun gnus-summary-mark-unread-as-read ()
8564 "Intended to be used by `gnus-summary-mark-article-hook'."
8565 (when (memq gnus-current-article gnus-newsgroup-unreads)
8566 (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8567
8568(defun gnus-summary-mark-read-and-unread-as-read ()
8569 "Intended to be used by `gnus-summary-mark-article-hook'."
8570 (let ((mark (gnus-summary-article-mark)))
8571 (when (or (gnus-unread-mark-p mark)
8572 (gnus-read-mark-p mark))
8573 (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8574
8575(defun gnus-summary-mark-region-as-read (point mark all)
8576 "Mark all unread articles between point and mark as read.
8577If given a prefix, mark all articles between point and mark as read,
8578even ticked and dormant ones."
8579 (interactive "r\nP")
8580 (save-excursion
8581 (let (article)
8582 (goto-char point)
8583 (beginning-of-line)
8584 (while (and
8585 (< (point) mark)
8586 (progn
8587 (when (or all
8588 (memq (setq article (gnus-summary-article-number))
8589 gnus-newsgroup-unreads))
8590 (gnus-summary-mark-article article gnus-del-mark))
8591 t)
8592 (gnus-summary-find-next))))))
8593
8594(defun gnus-summary-mark-below (score mark)
8595 "Mark articles with score less than SCORE with MARK."
8596 (interactive "P\ncMark: ")
eec82323
LMI
8597 (setq score (if score
8598 (prefix-numeric-value score)
8599 (or gnus-summary-default-score 0)))
8600 (save-excursion
8601 (set-buffer gnus-summary-buffer)
8602 (goto-char (point-min))
8603 (while
8604 (progn
8605 (and (< (gnus-summary-article-score) score)
8606 (gnus-summary-mark-article nil mark))
8607 (gnus-summary-find-next)))))
8608
8609(defun gnus-summary-kill-below (&optional score)
8610 "Mark articles with score below SCORE as read."
8611 (interactive "P")
eec82323
LMI
8612 (gnus-summary-mark-below score gnus-killed-mark))
8613
8614(defun gnus-summary-clear-above (&optional score)
8615 "Clear all marks from articles with score above SCORE."
8616 (interactive "P")
eec82323
LMI
8617 (gnus-summary-mark-above score gnus-unread-mark))
8618
8619(defun gnus-summary-tick-above (&optional score)
8620 "Tick all articles with score above SCORE."
8621 (interactive "P")
eec82323
LMI
8622 (gnus-summary-mark-above score gnus-ticked-mark))
8623
8624(defun gnus-summary-mark-above (score mark)
8625 "Mark articles with score over SCORE with MARK."
8626 (interactive "P\ncMark: ")
eec82323
LMI
8627 (setq score (if score
8628 (prefix-numeric-value score)
8629 (or gnus-summary-default-score 0)))
8630 (save-excursion
8631 (set-buffer gnus-summary-buffer)
8632 (goto-char (point-min))
8633 (while (and (progn
8634 (when (> (gnus-summary-article-score) score)
8635 (gnus-summary-mark-article nil mark))
8636 t)
8637 (gnus-summary-find-next)))))
8638
8639;; Suggested by Daniel Quinlan <quinlan@best.com>.
8640(defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8641(defun gnus-summary-limit-include-expunged (&optional no-error)
8642 "Display all the hidden articles that were expunged for low scores."
8643 (interactive)
eec82323
LMI
8644 (let ((buffer-read-only nil))
8645 (let ((scored gnus-newsgroup-scored)
8646 headers h)
8647 (while scored
8648 (unless (gnus-summary-goto-subject (caar scored))
8649 (and (setq h (gnus-summary-article-header (caar scored)))
8650 (< (cdar scored) gnus-summary-expunge-below)
8651 (push h headers)))
8652 (setq scored (cdr scored)))
8653 (if (not headers)
8654 (when (not no-error)
a8151ef7 8655 (error "No expunged articles hidden"))
eec82323
LMI
8656 (goto-char (point-min))
8657 (gnus-summary-prepare-unthreaded (nreverse headers))
8658 (goto-char (point-min))
8659 (gnus-summary-position-point)
8660 t))))
8661
8662(defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8663 "Mark all unread articles in this newsgroup as read.
8664If prefix argument ALL is non-nil, ticked and dormant articles will
8665also be marked as read.
8666If QUIETLY is non-nil, no questions will be asked.
8667If TO-HERE is non-nil, it should be a point in the buffer. All
8668articles before this point will be marked as read.
8669Note that this function will only catch up the unread article
8670in the current summary buffer limitation.
8671The number of articles marked as read is returned."
8672 (interactive "P")
eec82323
LMI
8673 (prog1
8674 (save-excursion
8675 (when (or quietly
8676 (not gnus-interactive-catchup) ;Without confirmation?
8677 gnus-expert-user
8678 (gnus-y-or-n-p
8679 (if all
8680 "Mark absolutely all articles as read? "
8681 "Mark all unread articles as read? ")))
8682 (if (and not-mark
8683 (not gnus-newsgroup-adaptive)
8684 (not gnus-newsgroup-auto-expire)
a8151ef7
LMI
8685 (not gnus-suppress-duplicates)
8686 (or (not gnus-use-cache)
6748645f 8687 (eq gnus-use-cache 'passive)))
eec82323
LMI
8688 (progn
8689 (when all
8690 (setq gnus-newsgroup-marked nil
8691 gnus-newsgroup-dormant nil))
6748645f 8692 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
eec82323
LMI
8693 ;; We actually mark all articles as canceled, which we
8694 ;; have to do when using auto-expiry or adaptive scoring.
8695 (gnus-summary-show-all-threads)
6748645f 8696 (when (gnus-summary-first-subject (not all) t)
eec82323
LMI
8697 (while (and
8698 (if to-here (< (point) to-here) t)
8699 (gnus-summary-mark-article-as-read gnus-catchup-mark)
6748645f 8700 (gnus-summary-find-next (not all) nil nil t))))
eec82323
LMI
8701 (gnus-set-mode-line 'summary))
8702 t))
8703 (gnus-summary-position-point)))
8704
8705(defun gnus-summary-catchup-to-here (&optional all)
8706 "Mark all unticked articles before the current one as read.
8707If ALL is non-nil, also mark ticked and dormant articles as read."
8708 (interactive "P")
eec82323
LMI
8709 (save-excursion
8710 (gnus-save-hidden-threads
8711 (let ((beg (point)))
8712 ;; We check that there are unread articles.
8713 (when (or all (gnus-summary-find-prev))
8714 (gnus-summary-catchup all t beg)))))
8715 (gnus-summary-position-point))
8716
8717(defun gnus-summary-catchup-all (&optional quietly)
8718 "Mark all articles in this newsgroup as read."
8719 (interactive "P")
eec82323
LMI
8720 (gnus-summary-catchup t quietly))
8721
8722(defun gnus-summary-catchup-and-exit (&optional all quietly)
16409b0b 8723 "Mark all unread articles in this group as read, then exit.
eec82323
LMI
8724If prefix argument ALL is non-nil, all articles are marked as read."
8725 (interactive "P")
eec82323
LMI
8726 (when (gnus-summary-catchup all quietly nil 'fast)
8727 ;; Select next newsgroup or exit.
6748645f
LMI
8728 (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8729 (eq gnus-auto-select-next 'quietly))
eec82323
LMI
8730 (gnus-summary-next-group nil)
8731 (gnus-summary-exit))))
8732
8733(defun gnus-summary-catchup-all-and-exit (&optional quietly)
8734 "Mark all articles in this newsgroup as read, and then exit."
8735 (interactive "P")
eec82323
LMI
8736 (gnus-summary-catchup-and-exit t quietly))
8737
eec82323
LMI
8738(defun gnus-summary-catchup-and-goto-next-group (&optional all)
8739 "Mark all articles in this group as read and select the next group.
8740If given a prefix, mark all articles, unread as well as ticked, as
8741read."
8742 (interactive "P")
eec82323
LMI
8743 (save-excursion
8744 (gnus-summary-catchup all))
16409b0b
GM
8745 (gnus-summary-next-group))
8746
8747;;;
8748;;; with article
8749;;;
8750
8751(defmacro gnus-with-article (article &rest forms)
8752 "Select ARTICLE and perform FORMS in the original article buffer.
8753Then replace the article with the result."
8754 `(progn
8755 ;; We don't want the article to be marked as read.
8756 (let (gnus-mark-article-hook)
8757 (gnus-summary-select-article t t nil ,article))
8758 (set-buffer gnus-original-article-buffer)
8759 ,@forms
8760 (if (not (gnus-check-backend-function
8761 'request-replace-article (car gnus-article-current)))
8762 (gnus-message 5 "Read-only group; not replacing")
8763 (unless (gnus-request-replace-article
8764 ,article (car gnus-article-current)
8765 (current-buffer) t)
8766 (error "Couldn't replace article")))
8767 ;; The cache and backlog have to be flushed somewhat.
8768 (when gnus-keep-backlog
8769 (gnus-backlog-remove-article
8770 (car gnus-article-current) (cdr gnus-article-current)))
8771 (when gnus-use-cache
8772 (gnus-cache-update-article
8773 (car gnus-article-current) (cdr gnus-article-current)))))
8774
8775(put 'gnus-with-article 'lisp-indent-function 1)
8776(put 'gnus-with-article 'edebug-form-spec '(form body))
eec82323
LMI
8777
8778;; Thread-based commands.
8779
8780(defun gnus-summary-articles-in-thread (&optional article)
8781 "Return a list of all articles in the current thread.
8782If ARTICLE is non-nil, return all articles in the thread that starts
8783with that article."
8784 (let* ((article (or article (gnus-summary-article-number)))
8785 (data (gnus-data-find-list article))
8786 (top-level (gnus-data-level (car data)))
8787 (top-subject
8788 (cond ((null gnus-thread-operation-ignore-subject)
8789 (gnus-simplify-subject-re
8790 (mail-header-subject (gnus-data-header (car data)))))
8791 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8792 (gnus-simplify-subject-fuzzy
8793 (mail-header-subject (gnus-data-header (car data)))))
8794 (t nil)))
8795 (end-point (save-excursion
8796 (if (gnus-summary-go-to-next-thread)
8797 (point) (point-max))))
8798 articles)
8799 (while (and data
8800 (< (gnus-data-pos (car data)) end-point))
8801 (when (or (not top-subject)
8802 (string= top-subject
8803 (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8804 (gnus-simplify-subject-fuzzy
8805 (mail-header-subject
8806 (gnus-data-header (car data))))
8807 (gnus-simplify-subject-re
8808 (mail-header-subject
8809 (gnus-data-header (car data)))))))
8810 (push (gnus-data-number (car data)) articles))
8811 (unless (and (setq data (cdr data))
8812 (> (gnus-data-level (car data)) top-level))
8813 (setq data nil)))
8814 ;; Return the list of articles.
8815 (nreverse articles)))
8816
8817(defun gnus-summary-rethread-current ()
8818 "Rethread the thread the current article is part of."
8819 (interactive)
eec82323
LMI
8820 (let* ((gnus-show-threads t)
8821 (article (gnus-summary-article-number))
8822 (id (mail-header-id (gnus-summary-article-header)))
8823 (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8824 (unless id
8825 (error "No article on the current line"))
8826 (gnus-rebuild-thread id)
8827 (gnus-summary-goto-subject article)))
8828
8829(defun gnus-summary-reparent-thread ()
8830 "Make the current article child of the marked (or previous) article.
8831
8832Note that the re-threading will only work if `gnus-thread-ignore-subject'
8833is non-nil or the Subject: of both articles are the same."
8834 (interactive)
8835 (unless (not (gnus-group-read-only-p))
a8151ef7 8836 (error "The current newsgroup does not support article editing"))
eec82323 8837 (unless (<= (length gnus-newsgroup-processable) 1)
a8151ef7 8838 (error "No more than one article may be marked"))
eec82323
LMI
8839 (save-window-excursion
8840 (let ((gnus-article-buffer " *reparent*")
8841 (current-article (gnus-summary-article-number))
8842 ;; First grab the marked article, otherwise one line up.
8843 (parent-article (if (not (null gnus-newsgroup-processable))
8844 (car gnus-newsgroup-processable)
8845 (save-excursion
8846 (if (eq (forward-line -1) 0)
8847 (gnus-summary-article-number)
a8151ef7 8848 (error "Beginning of summary buffer"))))))
eec82323 8849 (unless (not (eq current-article parent-article))
a8151ef7 8850 (error "An article may not be self-referential"))
eec82323
LMI
8851 (let ((message-id (mail-header-id
8852 (gnus-summary-article-header parent-article))))
8853 (unless (and message-id (not (equal message-id "")))
a8151ef7 8854 (error "No message-id in desired parent"))
16409b0b
GM
8855 (gnus-with-article current-article
8856 (save-restriction
eec82323 8857 (goto-char (point-min))
16409b0b 8858 (message-narrow-to-head)
6748645f
LMI
8859 (if (re-search-forward "^References: " nil t)
8860 (progn
8861 (re-search-forward "^[^ \t]" nil t)
8862 (forward-line -1)
8863 (end-of-line)
8864 (insert " " message-id))
16409b0b 8865 (insert "References: " message-id "\n"))))
eec82323
LMI
8866 (set-buffer gnus-summary-buffer)
8867 (gnus-summary-unmark-all-processable)
6748645f 8868 (gnus-summary-update-article current-article)
eec82323 8869 (gnus-summary-rethread-current)
a8151ef7 8870 (gnus-message 3 "Article %d is now the child of article %d"
eec82323
LMI
8871 current-article parent-article)))))
8872
8873(defun gnus-summary-toggle-threads (&optional arg)
8874 "Toggle showing conversation threads.
8875If ARG is positive number, turn showing conversation threads on."
8876 (interactive "P")
eec82323
LMI
8877 (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8878 (setq gnus-show-threads
8879 (if (null arg) (not gnus-show-threads)
8880 (> (prefix-numeric-value arg) 0)))
8881 (gnus-summary-prepare)
8882 (gnus-summary-goto-subject current)
8883 (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8884 (gnus-summary-position-point)))
8885
8886(defun gnus-summary-show-all-threads ()
8887 "Show all threads."
8888 (interactive)
eec82323
LMI
8889 (save-excursion
8890 (let ((buffer-read-only nil))
8891 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8892 (gnus-summary-position-point))
8893
8894(defun gnus-summary-show-thread ()
8895 "Show thread subtrees.
8896Returns nil if no thread was there to be shown."
8897 (interactive)
eec82323
LMI
8898 (let ((buffer-read-only nil)
8899 (orig (point))
8900 ;; first goto end then to beg, to have point at beg after let
8901 (end (progn (end-of-line) (point)))
8902 (beg (progn (beginning-of-line) (point))))
8903 (prog1
8904 ;; Any hidden lines here?
8905 (search-forward "\r" end t)
8906 (subst-char-in-region beg end ?\^M ?\n t)
8907 (goto-char orig)
8908 (gnus-summary-position-point))))
8909
8910(defun gnus-summary-hide-all-threads ()
8911 "Hide all thread subtrees."
8912 (interactive)
eec82323
LMI
8913 (save-excursion
8914 (goto-char (point-min))
8915 (gnus-summary-hide-thread)
8916 (while (zerop (gnus-summary-next-thread 1 t))
8917 (gnus-summary-hide-thread)))
8918 (gnus-summary-position-point))
8919
8920(defun gnus-summary-hide-thread ()
8921 "Hide thread subtrees.
8922Returns nil if no threads were there to be hidden."
8923 (interactive)
eec82323
LMI
8924 (let ((buffer-read-only nil)
8925 (start (point))
8926 (article (gnus-summary-article-number)))
8927 (goto-char start)
8928 ;; Go forward until either the buffer ends or the subthread
8929 ;; ends.
8930 (when (and (not (eobp))
8931 (or (zerop (gnus-summary-next-thread 1 t))
8932 (goto-char (point-max))))
8933 (prog1
8934 (if (and (> (point) start)
8935 (search-backward "\n" start t))
8936 (progn
8937 (subst-char-in-region start (point) ?\n ?\^M)
8938 (gnus-summary-goto-subject article))
8939 (goto-char start)
16409b0b 8940 nil)))))
eec82323
LMI
8941
8942(defun gnus-summary-go-to-next-thread (&optional previous)
8943 "Go to the same level (or less) next thread.
8944If PREVIOUS is non-nil, go to previous thread instead.
8945Return the article number moved to, or nil if moving was impossible."
8946 (let ((level (gnus-summary-thread-level))
8947 (way (if previous -1 1))
8948 (beg (point)))
8949 (forward-line way)
8950 (while (and (not (eobp))
8951 (< level (gnus-summary-thread-level)))
8952 (forward-line way))
8953 (if (eobp)
8954 (progn
8955 (goto-char beg)
8956 nil)
8957 (setq beg (point))
8958 (prog1
8959 (gnus-summary-article-number)
8960 (goto-char beg)))))
8961
8962(defun gnus-summary-next-thread (n &optional silent)
8963 "Go to the same level next N'th thread.
8964If N is negative, search backward instead.
8965Returns the difference between N and the number of skips actually
8966done.
8967
8968If SILENT, don't output messages."
8969 (interactive "p")
eec82323
LMI
8970 (let ((backward (< n 0))
8971 (n (abs n)))
8972 (while (and (> n 0)
8973 (gnus-summary-go-to-next-thread backward))
8974 (decf n))
8975 (unless silent
8976 (gnus-summary-position-point))
8977 (when (and (not silent) (/= 0 n))
8978 (gnus-message 7 "No more threads"))
8979 n))
8980
8981(defun gnus-summary-prev-thread (n)
8982 "Go to the same level previous N'th thread.
8983Returns the difference between N and the number of skips actually
8984done."
8985 (interactive "p")
eec82323
LMI
8986 (gnus-summary-next-thread (- n)))
8987
8988(defun gnus-summary-go-down-thread ()
8989 "Go down one level in the current thread."
8990 (let ((children (gnus-summary-article-children)))
8991 (when children
8992 (gnus-summary-goto-subject (car children)))))
8993
8994(defun gnus-summary-go-up-thread ()
8995 "Go up one level in the current thread."
8996 (let ((parent (gnus-summary-article-parent)))
8997 (when parent
8998 (gnus-summary-goto-subject parent))))
8999
9000(defun gnus-summary-down-thread (n)
9001 "Go down thread N steps.
9002If N is negative, go up instead.
9003Returns the difference between N and how many steps down that were
9004taken."
9005 (interactive "p")
eec82323
LMI
9006 (let ((up (< n 0))
9007 (n (abs n)))
9008 (while (and (> n 0)
9009 (if up (gnus-summary-go-up-thread)
9010 (gnus-summary-go-down-thread)))
9011 (setq n (1- n)))
9012 (gnus-summary-position-point)
9013 (when (/= 0 n)
9014 (gnus-message 7 "Can't go further"))
9015 n))
9016
9017(defun gnus-summary-up-thread (n)
9018 "Go up thread N steps.
9019If N is negative, go up instead.
9020Returns the difference between N and how many steps down that were
9021taken."
9022 (interactive "p")
eec82323
LMI
9023 (gnus-summary-down-thread (- n)))
9024
9025(defun gnus-summary-top-thread ()
9026 "Go to the top of the thread."
9027 (interactive)
eec82323
LMI
9028 (while (gnus-summary-go-up-thread))
9029 (gnus-summary-article-number))
9030
9031(defun gnus-summary-kill-thread (&optional unmark)
9032 "Mark articles under current thread as read.
9033If the prefix argument is positive, remove any kinds of marks.
9034If the prefix argument is negative, tick articles instead."
9035 (interactive "P")
eec82323
LMI
9036 (when unmark
9037 (setq unmark (prefix-numeric-value unmark)))
9038 (let ((articles (gnus-summary-articles-in-thread)))
9039 (save-excursion
9040 ;; Expand the thread.
9041 (gnus-summary-show-thread)
9042 ;; Mark all the articles.
9043 (while articles
9044 (gnus-summary-goto-subject (car articles))
9045 (cond ((null unmark)
9046 (gnus-summary-mark-article-as-read gnus-killed-mark))
9047 ((> unmark 0)
9048 (gnus-summary-mark-article-as-unread gnus-unread-mark))
9049 (t
9050 (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9051 (setq articles (cdr articles))))
9052 ;; Hide killed subtrees.
9053 (and (null unmark)
9054 gnus-thread-hide-killed
9055 (gnus-summary-hide-thread))
9056 ;; If marked as read, go to next unread subject.
9057 (when (null unmark)
9058 ;; Go to next unread subject.
9059 (gnus-summary-next-subject 1 t)))
9060 (gnus-set-mode-line 'summary))
9061
9062;; Summary sorting commands
9063
9064(defun gnus-summary-sort-by-number (&optional reverse)
9065 "Sort the summary buffer by article number.
9066Argument REVERSE means reverse order."
9067 (interactive "P")
9068 (gnus-summary-sort 'number reverse))
9069
9070(defun gnus-summary-sort-by-author (&optional reverse)
9071 "Sort the summary buffer by author name alphabetically.
16409b0b 9072If `case-fold-search' is non-nil, case of letters is ignored.
eec82323
LMI
9073Argument REVERSE means reverse order."
9074 (interactive "P")
9075 (gnus-summary-sort 'author reverse))
9076
9077(defun gnus-summary-sort-by-subject (&optional reverse)
9078 "Sort the summary buffer by subject alphabetically. `Re:'s are ignored.
16409b0b 9079If `case-fold-search' is non-nil, case of letters is ignored.
eec82323
LMI
9080Argument REVERSE means reverse order."
9081 (interactive "P")
9082 (gnus-summary-sort 'subject reverse))
9083
9084(defun gnus-summary-sort-by-date (&optional reverse)
9085 "Sort the summary buffer by date.
9086Argument REVERSE means reverse order."
9087 (interactive "P")
9088 (gnus-summary-sort 'date reverse))
9089
9090(defun gnus-summary-sort-by-score (&optional reverse)
9091 "Sort the summary buffer by score.
9092Argument REVERSE means reverse order."
9093 (interactive "P")
9094 (gnus-summary-sort 'score reverse))
9095
9096(defun gnus-summary-sort-by-lines (&optional reverse)
16409b0b 9097 "Sort the summary buffer by the number of lines.
eec82323
LMI
9098Argument REVERSE means reverse order."
9099 (interactive "P")
9100 (gnus-summary-sort 'lines reverse))
9101
16409b0b
GM
9102(defun gnus-summary-sort-by-chars (&optional reverse)
9103 "Sort the summary buffer by article length.
9104Argument REVERSE means reverse order."
9105 (interactive "P")
9106 (gnus-summary-sort 'chars reverse))
9107
eec82323
LMI
9108(defun gnus-summary-sort (predicate reverse)
9109 "Sort summary buffer by PREDICATE. REVERSE means reverse order."
eec82323
LMI
9110 (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9111 (article (intern (format "gnus-article-sort-by-%s" predicate)))
9112 (gnus-thread-sort-functions
16409b0b
GM
9113 (if (not reverse)
9114 thread
9115 `(lambda (t1 t2)
9116 (,thread t2 t1))))
9117 (gnus-sort-gathered-threads-function
9118 gnus-thread-sort-functions)
eec82323 9119 (gnus-article-sort-functions
16409b0b
GM
9120 (if (not reverse)
9121 article
9122 `(lambda (t1 t2)
9123 (,article t2 t1))))
eec82323
LMI
9124 (buffer-read-only)
9125 (gnus-summary-prepare-hook nil))
9126 ;; We do the sorting by regenerating the threads.
9127 (gnus-summary-prepare)
9128 ;; Hide subthreads if needed.
9129 (when (and gnus-show-threads gnus-thread-hide-subtree)
9130 (gnus-summary-hide-all-threads))))
9131
9132;; Summary saving commands.
9133
9134(defun gnus-summary-save-article (&optional n not-saved)
9135 "Save the current article using the default saver function.
9136If N is a positive number, save the N next articles.
9137If N is a negative number, save the N previous articles.
9138If N is nil and any articles have been marked with the process mark,
9139save those articles instead.
9140The variable `gnus-default-article-saver' specifies the saver function."
9141 (interactive "P")
eec82323
LMI
9142 (let* ((articles (gnus-summary-work-articles n))
9143 (save-buffer (save-excursion
9144 (nnheader-set-temp-buffer " *Gnus Save*")))
9145 (num (length articles))
16409b0b
GM
9146 header file)
9147 (dolist (article articles)
9148 (setq header (gnus-summary-article-header article))
eec82323
LMI
9149 (if (not (vectorp header))
9150 ;; This is a pseudo-article.
9151 (if (assq 'name header)
9152 (gnus-copy-file (cdr (assq 'name header)))
9153 (gnus-message 1 "Article %d is unsaveable" article))
9154 ;; This is a real article.
9155 (save-window-excursion
4e728580
SZ
9156 (let ((gnus-display-mime-function nil)
9157 (gnus-article-prepare-hook nil))
9158 (gnus-summary-select-article t nil nil article)))
eec82323
LMI
9159 (save-excursion
9160 (set-buffer save-buffer)
9161 (erase-buffer)
9162 (insert-buffer-substring gnus-original-article-buffer))
9163 (setq file (gnus-article-save save-buffer file num))
9164 (gnus-summary-remove-process-mark article)
9165 (unless not-saved
9166 (gnus-summary-set-saved-mark article))))
9167 (gnus-kill-buffer save-buffer)
9168 (gnus-summary-position-point)
9169 (gnus-set-mode-line 'summary)
9170 n))
9171
9172(defun gnus-summary-pipe-output (&optional arg)
9173 "Pipe the current article to a subprocess.
9174If N is a positive number, pipe the N next articles.
9175If N is a negative number, pipe the N previous articles.
9176If N is nil and any articles have been marked with the process mark,
9177pipe those articles instead."
9178 (interactive "P")
84169620 9179 (require 'gnus-art)
eec82323
LMI
9180 (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9181 (gnus-summary-save-article arg t))
9182 (gnus-configure-windows 'pipe))
9183
9184(defun gnus-summary-save-article-mail (&optional arg)
9185 "Append the current article to an mail file.
9186If N is a positive number, save the N next articles.
9187If N is a negative number, save the N previous articles.
9188If N is nil and any articles have been marked with the process mark,
9189save those articles instead."
9190 (interactive "P")
84169620 9191 (require 'gnus-art)
eec82323
LMI
9192 (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9193 (gnus-summary-save-article arg)))
9194
9195(defun gnus-summary-save-article-rmail (&optional arg)
9196 "Append the current article to an rmail file.
9197If N is a positive number, save the N next articles.
9198If N is a negative number, save the N previous articles.
9199If N is nil and any articles have been marked with the process mark,
9200save those articles instead."
9201 (interactive "P")
84169620 9202 (require 'gnus-art)
eec82323
LMI
9203 (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9204 (gnus-summary-save-article arg)))
9205
9206(defun gnus-summary-save-article-file (&optional arg)
9207 "Append the current article to a file.
9208If N is a positive number, save the N next articles.
9209If N is a negative number, save the N previous articles.
9210If N is nil and any articles have been marked with the process mark,
9211save those articles instead."
9212 (interactive "P")
84169620 9213 (require 'gnus-art)
eec82323
LMI
9214 (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9215 (gnus-summary-save-article arg)))
9216
9217(defun gnus-summary-write-article-file (&optional arg)
9218 "Write the current article to a file, deleting the previous file.
9219If N is a positive number, save the N next articles.
9220If N is a negative number, save the N previous articles.
9221If N is nil and any articles have been marked with the process mark,
9222save those articles instead."
9223 (interactive "P")
84169620 9224 (require 'gnus-art)
eec82323
LMI
9225 (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9226 (gnus-summary-save-article arg)))
9227
9228(defun gnus-summary-save-article-body-file (&optional arg)
9229 "Append the current article body to a file.
9230If N is a positive number, save the N next articles.
9231If N is a negative number, save the N previous articles.
9232If N is nil and any articles have been marked with the process mark,
9233save those articles instead."
9234 (interactive "P")
84169620 9235 (require 'gnus-art)
eec82323
LMI
9236 (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9237 (gnus-summary-save-article arg)))
9238
9239(defun gnus-summary-pipe-message (program)
9240 "Pipe the current article through PROGRAM."
9241 (interactive "sProgram: ")
eec82323 9242 (gnus-summary-select-article)
6748645f 9243 (let ((mail-header-separator ""))
eec82323
LMI
9244 (gnus-eval-in-buffer-window gnus-article-buffer
9245 (save-restriction
9246 (widen)
9247 (let ((start (window-start))
9248 buffer-read-only)
9249 (message-pipe-buffer-body program)
9250 (set-window-start (get-buffer-window (current-buffer)) start))))))
9251
9252(defun gnus-get-split-value (methods)
9253 "Return a value based on the split METHODS."
9254 (let (split-name method result match)
9255 (when methods
9256 (save-excursion
9257 (set-buffer gnus-original-article-buffer)
9258 (save-restriction
9259 (nnheader-narrow-to-headers)
d4dfaa19 9260 (while (and methods (not split-name))
eec82323
LMI
9261 (goto-char (point-min))
9262 (setq method (pop methods))
9263 (setq match (car method))
9264 (when (cond
9265 ((stringp match)
9266 ;; Regular expression.
9267 (ignore-errors
9268 (re-search-forward match nil t)))
9269 ((gnus-functionp match)
9270 ;; Function.
9271 (save-restriction
9272 (widen)
9273 (setq result (funcall match gnus-newsgroup-name))))
9274 ((consp match)
9275 ;; Form.
9276 (save-restriction
9277 (widen)
9278 (setq result (eval match)))))
d4dfaa19 9279 (setq split-name (cdr method))
eec82323
LMI
9280 (cond ((stringp result)
9281 (push (expand-file-name
9282 result gnus-article-save-directory)
9283 split-name))
9284 ((consp result)
9285 (setq split-name (append result split-name)))))))))
16409b0b 9286 (nreverse split-name)))
eec82323
LMI
9287
9288(defun gnus-valid-move-group-p (group)
9289 (and (boundp group)
9290 (symbol-name group)
16409b0b
GM
9291 (symbol-value group)
9292 (gnus-get-function (gnus-find-method-for-group
9293 (symbol-name group)) 'request-accept-article t)))
eec82323
LMI
9294
9295(defun gnus-read-move-group-name (prompt default articles prefix)
9296 "Read a group name."
9297 (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9298 (minibuffer-confirm-incomplete nil) ; XEmacs
9299 (prom
9300 (format "%s %s to:"
9301 prompt
9302 (if (> (length articles) 1)
9303 (format "these %d articles" (length articles))
9304 "this article")))
9305 (to-newsgroup
9306 (cond
9307 ((null split-name)
9308 (gnus-completing-read default prom
9309 gnus-active-hashtb
9310 'gnus-valid-move-group-p
9311 nil prefix
9312 'gnus-group-history))
9313 ((= 1 (length split-name))
9314 (gnus-completing-read (car split-name) prom
9315 gnus-active-hashtb
9316 'gnus-valid-move-group-p
9317 nil nil
9318 'gnus-group-history))
9319 (t
9320 (gnus-completing-read nil prom
9321 (mapcar (lambda (el) (list el))
9322 (nreverse split-name))
9323 nil nil nil
16409b0b
GM
9324 'gnus-group-history))))
9325 (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
eec82323
LMI
9326 (when to-newsgroup
9327 (if (or (string= to-newsgroup "")
9328 (string= to-newsgroup prefix))
9329 (setq to-newsgroup default))
9330 (unless to-newsgroup
9331 (error "No group name entered"))
9332 (or (gnus-active to-newsgroup)
16409b0b 9333 (gnus-activate-group to-newsgroup nil nil to-method)
eec82323
LMI
9334 (if (gnus-y-or-n-p (format "No such group: %s. Create it? "
9335 to-newsgroup))
16409b0b
GM
9336 (or (and (gnus-request-create-group to-newsgroup to-method)
9337 (gnus-activate-group
9338 to-newsgroup nil nil to-method)
9339 (gnus-subscribe-group to-newsgroup))
eec82323
LMI
9340 (error "Couldn't create group %s" to-newsgroup)))
9341 (error "No such group: %s" to-newsgroup)))
9342 to-newsgroup))
9343
16409b0b
GM
9344(defun gnus-summary-save-parts (type dir n &optional reverse)
9345 "Save parts matching TYPE to DIR.
9346If REVERSE, save parts that do not match TYPE."
9347 (interactive
8b93df01
DL
9348 (list (read-string "Save parts of type: "
9349 (or (car gnus-summary-save-parts-type-history)
9350 gnus-summary-save-parts-default-mime)
9351 'gnus-summary-save-parts-type-history)
9352 (setq gnus-summary-save-parts-last-directory
9353 (read-file-name "Save to directory: "
9354 gnus-summary-save-parts-last-directory
9355 nil t))
16409b0b
GM
9356 current-prefix-arg))
9357 (gnus-summary-iterate n
9358 (let ((gnus-display-mime-function nil)
9359 (gnus-inhibit-treatment t))
9360 (gnus-summary-select-article))
9361 (save-excursion
9362 (set-buffer gnus-article-buffer)
9363 (let ((handles (or gnus-article-mime-handles
9364 (mm-dissect-buffer) (mm-uu-dissect))))
9365 (when handles
9366 (gnus-summary-save-parts-1 type dir handles reverse)
9367 (unless gnus-article-mime-handles ;; Don't destroy this case.
9368 (mm-destroy-parts handles)))))))
9369
9370(defun gnus-summary-save-parts-1 (type dir handle reverse)
9371 (if (stringp (car handle))
9372 (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9373 (cdr handle))
9374 (when (if reverse
9375 (not (string-match type (mm-handle-media-type handle)))
9376 (string-match type (mm-handle-media-type handle)))
9377 (let ((file (expand-file-name
9378 (file-name-nondirectory
9379 (or
9380 (mail-content-type-get
9381 (mm-handle-disposition handle) 'filename)
9382 (concat gnus-newsgroup-name
9383 "." (number-to-string
9384 (cdr gnus-article-current)))))
9385 dir)))
9386 (unless (file-exists-p file)
9387 (mm-save-part-to-file handle file))))))
9388
eec82323
LMI
9389;; Summary extract commands
9390
9391(defun gnus-summary-insert-pseudos (pslist &optional not-view)
9392 (let ((buffer-read-only nil)
9393 (article (gnus-summary-article-number))
9394 after-article b e)
9395 (unless (gnus-summary-goto-subject article)
9396 (error "No such article: %d" article))
9397 (gnus-summary-position-point)
9398 ;; If all commands are to be bunched up on one line, we collect
9399 ;; them here.
9400 (unless gnus-view-pseudos-separately
9401 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9402 files action)
9403 (while ps
9404 (setq action (cdr (assq 'action (car ps))))
9405 (setq files (list (cdr (assq 'name (car ps)))))
9406 (while (and ps (cdr ps)
9407 (string= (or action "1")
9408 (or (cdr (assq 'action (cadr ps))) "2")))
9409 (push (cdr (assq 'name (cadr ps))) files)
9410 (setcdr ps (cddr ps)))
9411 (when files
9412 (when (not (string-match "%s" action))
9413 (push " " files))
9414 (push " " files)
9415 (when (assq 'execute (car ps))
9416 (setcdr (assq 'execute (car ps))
9417 (funcall (if (string-match "%s" action)
9418 'format 'concat)
9419 action
9420 (mapconcat
9421 (lambda (f)
9422 (if (equal f " ")
9423 f
16409b0b 9424 (mm-quote-arg f)))
eec82323
LMI
9425 files " ")))))
9426 (setq ps (cdr ps)))))
9427 (if (and gnus-view-pseudos (not not-view))
9428 (while pslist
9429 (when (assq 'execute (car pslist))
9430 (gnus-execute-command (cdr (assq 'execute (car pslist)))
9431 (eq gnus-view-pseudos 'not-confirm)))
9432 (setq pslist (cdr pslist)))
9433 (save-excursion
9434 (while pslist
9435 (setq after-article (or (cdr (assq 'article (car pslist)))
9436 (gnus-summary-article-number)))
9437 (gnus-summary-goto-subject after-article)
9438 (forward-line 1)
9439 (setq b (point))
9440 (insert " " (file-name-nondirectory
9441 (cdr (assq 'name (car pslist))))
9442 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9443 (setq e (point))
9444 (forward-line -1) ; back to `b'
9445 (gnus-add-text-properties
9446 b (1- e) (list 'gnus-number gnus-reffed-article-number
9447 gnus-mouse-face-prop gnus-mouse-face))
9448 (gnus-data-enter
9449 after-article gnus-reffed-article-number
9450 gnus-unread-mark b (car pslist) 0 (- e b))
9451 (push gnus-reffed-article-number gnus-newsgroup-unreads)
9452 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9453 (setq pslist (cdr pslist)))))))
9454
9455(defun gnus-pseudos< (p1 p2)
9456 (let ((c1 (cdr (assq 'action p1)))
9457 (c2 (cdr (assq 'action p2))))
9458 (and c1 c2 (string< c1 c2))))
9459
9460(defun gnus-request-pseudo-article (props)
9461 (cond ((assq 'execute props)
9462 (gnus-execute-command (cdr (assq 'execute props)))))
9463 (let ((gnus-current-article (gnus-summary-article-number)))
6748645f 9464 (gnus-run-hooks 'gnus-mark-article-hook)))
eec82323
LMI
9465
9466(defun gnus-execute-command (command &optional automatic)
9467 (save-excursion
9468 (gnus-article-setup-buffer)
9469 (set-buffer gnus-article-buffer)
9470 (setq buffer-read-only nil)
a8151ef7
LMI
9471 (let ((command (if automatic command
9472 (read-string "Command: " (cons command 0)))))
eec82323
LMI
9473 (erase-buffer)
9474 (insert "$ " command "\n\n")
9475 (if gnus-view-pseudo-asynchronously
9476 (start-process "gnus-execute" (current-buffer) shell-file-name
9477 shell-command-switch command)
9478 (call-process shell-file-name nil t nil
9479 shell-command-switch command)))))
9480
9481;; Summary kill commands.
9482
9483(defun gnus-summary-edit-global-kill (article)
9484 "Edit the \"global\" kill file."
9485 (interactive (list (gnus-summary-article-number)))
eec82323
LMI
9486 (gnus-group-edit-global-kill article))
9487
9488(defun gnus-summary-edit-local-kill ()
9489 "Edit a local kill file applied to the current newsgroup."
9490 (interactive)
eec82323 9491 (setq gnus-current-headers (gnus-summary-article-header))
eec82323
LMI
9492 (gnus-group-edit-local-kill
9493 (gnus-summary-article-number) gnus-newsgroup-name))
9494
9495;;; Header reading.
9496
9497(defun gnus-read-header (id &optional header)
9498 "Read the headers of article ID and enter them into the Gnus system."
9499 (let ((group gnus-newsgroup-name)
9500 (gnus-override-method
16409b0b
GM
9501 (or
9502 gnus-override-method
9503 (and (gnus-news-group-p gnus-newsgroup-name)
9504 (car (gnus-refer-article-methods)))))
eec82323
LMI
9505 where)
9506 ;; First we check to see whether the header in question is already
9507 ;; fetched.
9508 (if (stringp id)
9509 ;; This is a Message-ID.
9510 (setq header (or header (gnus-id-to-header id)))
9511 ;; This is an article number.
9512 (setq header (or header (gnus-summary-article-header id))))
9513 (if (and header
9514 (not (gnus-summary-article-sparse-p (mail-header-number header))))
9515 ;; We have found the header.
9516 header
6748645f
LMI
9517 ;; If this is a sparse article, we have to nix out its
9518 ;; previous entry in the thread hashtb.
9519 (when (and header
9520 (gnus-summary-article-sparse-p (mail-header-number header)))
9521 (let* ((parent (gnus-parent-id (mail-header-references header)))
9522 (thread (and parent (gnus-id-to-thread parent))))
9523 (when thread
9524 (delq (assq header thread) thread))))
eec82323
LMI
9525 ;; We have to really fetch the header to this article.
9526 (save-excursion
9527 (set-buffer nntp-server-buffer)
9528 (when (setq where (gnus-request-head id group))
9529 (nnheader-fold-continuation-lines)
9530 (goto-char (point-max))
9531 (insert ".\n")
9532 (goto-char (point-min))
9533 (insert "211 ")
9534 (princ (cond
9535 ((numberp id) id)
9536 ((cdr where) (cdr where))
9537 (header (mail-header-number header))
9538 (t gnus-reffed-article-number))
9539 (current-buffer))
9540 (insert " Article retrieved.\n"))
9541 (if (or (not where)
9542 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9543 () ; Malformed head.
9544 (unless (gnus-summary-article-sparse-p (mail-header-number header))
9545 (when (and (stringp id)
9546 (not (string= (gnus-group-real-name group)
9547 (car where))))
9548 ;; If we fetched by Message-ID and the article came
9549 ;; from a different group, we fudge some bogus article
9550 ;; numbers for this article.
9551 (mail-header-set-number header gnus-reffed-article-number))
9552 (save-excursion
9553 (set-buffer gnus-summary-buffer)
9554 (decf gnus-reffed-article-number)
9555 (gnus-remove-header (mail-header-number header))
9556 (push header gnus-newsgroup-headers)
9557 (setq gnus-current-headers header)
9558 (push (mail-header-number header) gnus-newsgroup-limit)))
9559 header)))))
9560
9561(defun gnus-remove-header (number)
9562 "Remove header NUMBER from `gnus-newsgroup-headers'."
9563 (if (and gnus-newsgroup-headers
9564 (= number (mail-header-number (car gnus-newsgroup-headers))))
9565 (pop gnus-newsgroup-headers)
9566 (let ((headers gnus-newsgroup-headers))
9567 (while (and (cdr headers)
9568 (not (= number (mail-header-number (cadr headers)))))
9569 (pop headers))
9570 (when (cdr headers)
9571 (setcdr headers (cddr headers))))))
9572
9573;;;
9574;;; summary highlights
9575;;;
9576
9577(defun gnus-highlight-selected-summary ()
16409b0b 9578 "Highlight selected article in summary buffer."
eec82323 9579 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
eec82323
LMI
9580 (when gnus-summary-selected-face
9581 (save-excursion
9582 (let* ((beg (progn (beginning-of-line) (point)))
9583 (end (progn (end-of-line) (point)))
9584 ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9585 (from (if (get-text-property beg gnus-mouse-face-prop)
9586 beg
9587 (or (next-single-property-change
9588 beg gnus-mouse-face-prop nil end)
9589 beg)))
9590 (to
9591 (if (= from end)
9592 (- from 2)
9593 (or (next-single-property-change
9594 from gnus-mouse-face-prop nil end)
9595 end))))
9596 ;; If no mouse-face prop on line we will have to = from = end,
9597 ;; so we highlight the entire line instead.
9598 (when (= (+ to 2) from)
9599 (setq from beg)
9600 (setq to end))
9601 (if gnus-newsgroup-selected-overlay
9602 ;; Move old overlay.
9603 (gnus-move-overlay
9604 gnus-newsgroup-selected-overlay from to (current-buffer))
9605 ;; Create new overlay.
9606 (gnus-overlay-put
9607 (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9608 'face gnus-summary-selected-face))))))
9609
9610;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9611(defun gnus-summary-highlight-line ()
9612 "Highlight current line according to `gnus-summary-highlight'."
9613 (let* ((list gnus-summary-highlight)
9614 (p (point))
9615 (end (progn (end-of-line) (point)))
9616 ;; now find out where the line starts and leave point there.
9617 (beg (progn (beginning-of-line) (point)))
9618 (article (gnus-summary-article-number))
9619 (score (or (cdr (assq (or article gnus-current-article)
9620 gnus-newsgroup-scored))
9621 gnus-summary-default-score 0))
9622 (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9623 (inhibit-read-only t))
9624 ;; Eval the cars of the lists until we find a match.
9625 (let ((default gnus-summary-default-score))
9626 (while (and list
9627 (not (eval (caar list))))
9628 (setq list (cdr list))))
9629 (let ((face (cdar list)))
9630 (unless (eq face (get-text-property beg 'face))
6748645f 9631 (gnus-put-text-property-excluding-characters-with-faces
eec82323
LMI
9632 beg end 'face
9633 (setq face (if (boundp face) (symbol-value face) face)))
9634 (when gnus-summary-highlight-line-function
9635 (funcall gnus-summary-highlight-line-function article face))))
9636 (goto-char p)))
9637
6748645f 9638(defun gnus-update-read-articles (group unread &optional compute)
eec82323
LMI
9639 "Update the list of read articles in GROUP."
9640 (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9641 (entry (gnus-gethash group gnus-newsrc-hashtb))
9642 (info (nth 2 entry))
9643 (prev 1)
9644 (unread (sort (copy-sequence unread) '<))
9645 read)
9646 (if (or (not info) (not active))
9647 ;; There is no info on this group if it was, in fact,
9648 ;; killed. Gnus stores no information on killed groups, so
9649 ;; there's nothing to be done.
9650 ;; One could store the information somewhere temporarily,
9651 ;; perhaps... Hmmm...
9652 ()
9653 ;; Remove any negative articles numbers.
9654 (while (and unread (< (car unread) 0))
9655 (setq unread (cdr unread)))
9656 ;; Remove any expired article numbers
9657 (while (and unread (< (car unread) (car active)))
9658 (setq unread (cdr unread)))
9659 ;; Compute the ranges of read articles by looking at the list of
9660 ;; unread articles.
9661 (while unread
9662 (when (/= (car unread) prev)
9663 (push (if (= prev (1- (car unread))) prev
9664 (cons prev (1- (car unread))))
9665 read))
9666 (setq prev (1+ (car unread)))
9667 (setq unread (cdr unread)))
9668 (when (<= prev (cdr active))
9669 (push (cons prev (cdr active)) read))
16409b0b 9670 (setq read (if (> (length read) 1) (nreverse read) read))
6748645f 9671 (if compute
16409b0b 9672 read
6748645f 9673 (save-excursion
16409b0b
GM
9674 (let (setmarkundo)
9675 ;; Propagate the read marks to the backend.
9676 (when (gnus-check-backend-function 'request-set-mark group)
9677 (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9678 (add (gnus-remove-from-range read (gnus-info-read info))))
9679 (when (or add del)
9680 (unless (gnus-check-group group)
9681 (error "Can't open server for %s" group))
9682 (gnus-request-set-mark
9683 group (delq nil (list (if add (list add 'add '(read)))
9684 (if del (list del 'del '(read))))))
9685 (setq setmarkundo
9686 `(gnus-request-set-mark
9687 ,group
9688 ',(delq nil (list
9689 (if del (list del 'add '(read)))
9690 (if add (list add 'del '(read))))))))))
9691 (set-buffer gnus-group-buffer)
9692 (gnus-undo-register
9693 `(progn
9694 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9695 (gnus-info-set-read ',info ',(gnus-info-read info))
9696 (gnus-get-unread-articles-in-group ',info
9697 (gnus-active ,group))
9698 (gnus-group-update-group ,group t)
9699 ,setmarkundo))))
6748645f 9700 ;; Enter this list into the group info.
16409b0b 9701 (gnus-info-set-read info read)
6748645f
LMI
9702 ;; Set the number of unread articles in gnus-newsrc-hashtb.
9703 (gnus-get-unread-articles-in-group info (gnus-active group))
9704 t))))
eec82323
LMI
9705
9706(defun gnus-offer-save-summaries ()
9707 "Offer to save all active summary buffers."
9708 (save-excursion
9709 (let ((buflist (buffer-list))
9710 buffers bufname)
9711 ;; Go through all buffers and find all summaries.
9712 (while buflist
9713 (and (setq bufname (buffer-name (car buflist)))
9714 (string-match "Summary" bufname)
9715 (save-excursion
9716 (set-buffer bufname)
9717 ;; We check that this is, indeed, a summary buffer.
9718 (and (eq major-mode 'gnus-summary-mode)
9719 ;; Also make sure this isn't bogus.
9720 gnus-newsgroup-prepared
9721 ;; Also make sure that this isn't a dead summary buffer.
9722 (not gnus-dead-summary-mode)))
9723 (push bufname buffers))
9724 (setq buflist (cdr buflist)))
9725 ;; Go through all these summary buffers and offer to save them.
9726 (when buffers
9727 (map-y-or-n-p
9728 "Update summary buffer %s? "
6748645f
LMI
9729 (lambda (buf)
9730 (switch-to-buffer buf)
9731 (gnus-summary-exit))
eec82323
LMI
9732 buffers)))))
9733
16409b0b
GM
9734(defun gnus-summary-setup-default-charset ()
9735 "Setup newsgroup default charset."
9736 (if (equal gnus-newsgroup-name "nndraft:drafts")
9737 (setq gnus-newsgroup-charset nil)
9738 (let* ((name (and gnus-newsgroup-name
9739 (gnus-group-real-name gnus-newsgroup-name)))
9740 (ignored-charsets
9741 (or gnus-newsgroup-ephemeral-ignored-charsets
9742 (append
9743 (and gnus-newsgroup-name
9744 (or (gnus-group-find-parameter gnus-newsgroup-name
9745 'ignored-charsets t)
9746 (let ((alist gnus-group-ignored-charsets-alist)
9747 elem (charsets nil))
9748 (while (setq elem (pop alist))
9749 (when (and name
9750 (string-match (car elem) name))
9751 (setq alist nil
9752 charsets (cdr elem))))
9753 charsets)))
9754 gnus-newsgroup-ignored-charsets))))
9755 (setq gnus-newsgroup-charset
9756 (or gnus-newsgroup-ephemeral-charset
9757 (and gnus-newsgroup-name
9758 (or (gnus-group-find-parameter gnus-newsgroup-name 'charset)
9759 (let ((alist gnus-group-charset-alist)
9760 elem charset)
9761 (while (setq elem (pop alist))
9762 (when (and name
9763 (string-match (car elem) name))
9764 (setq alist nil
9765 charset (cadr elem))))
9766 charset)))
9767 gnus-default-charset))
9768 (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
9769 ignored-charsets))))
9770
9771;;;
9772;;; Mime Commands
9773;;;
9774
9775(defun gnus-summary-display-buttonized (&optional show-all-parts)
9776 "Display the current article buffer fully MIME-buttonized.
9777If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
9778treated as multipart/mixed."
9779 (interactive "P")
9780 (require 'gnus-art)
9781 (let ((gnus-unbuttonized-mime-types nil)
9782 (gnus-mime-display-multipart-as-mixed show-all-parts))
9783 (gnus-summary-show-article)))
9784
9785(defun gnus-summary-repair-multipart (article)
9786 "Add a Content-Type header to a multipart article without one."
9787 (interactive (list (gnus-summary-article-number)))
9788 (gnus-with-article article
9789 (message-narrow-to-head)
9790 (goto-char (point-max))
9791 (widen)
9792 (when (search-forward "\n--" nil t)
9793 (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
9794 (message-narrow-to-head)
9795 (message-remove-header "Mime-Version")
9796 (message-remove-header "Content-Type")
9797 (goto-char (point-max))
9798 (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
9799 separator))
9800 (insert "Mime-Version: 1.0\n")
9801 (widen))))
9802 (let (gnus-mark-article-hook)
9803 (gnus-summary-select-article t t nil article)))
9804
9805(defun gnus-summary-toggle-display-buttonized ()
9806 "Toggle the buttonizing of the article buffer."
9807 (interactive)
9808 (require 'gnus-art)
9809 (if (setq gnus-inhibit-mime-unbuttonizing
9810 (not gnus-inhibit-mime-unbuttonizing))
9811 (let ((gnus-unbuttonized-mime-types nil))
9812 (gnus-summary-show-article))
9813 (gnus-summary-show-article)))
9814
9815;;;
9816;;; Generic summary marking commands
9817;;;
9818
9819(defvar gnus-summary-marking-alist
9820 '((read gnus-del-mark "d")
9821 (unread gnus-unread-mark "u")
9822 (ticked gnus-ticked-mark "!")
9823 (dormant gnus-dormant-mark "?")
9824 (expirable gnus-expirable-mark "e"))
9825 "An alist of names/marks/keystrokes.")
9826
9827(defvar gnus-summary-generic-mark-map (make-sparse-keymap))
9828(defvar gnus-summary-mark-map)
9829
9830(defun gnus-summary-make-all-marking-commands ()
9831 (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
9832 (dolist (elem gnus-summary-marking-alist)
9833 (apply 'gnus-summary-make-marking-command elem)))
9834
9835(defun gnus-summary-make-marking-command (name mark keystroke)
9836 (let ((map (make-sparse-keymap)))
9837 (define-key gnus-summary-generic-mark-map keystroke map)
9838 (dolist (lway `((next "next" next nil "n")
9839 (next-unread "next unread" next t "N")
9840 (prev "previous" prev nil "p")
9841 (prev-unread "previous unread" prev t "P")
9842 (nomove "" nil nil ,keystroke)))
9843 (let ((func (gnus-summary-make-marking-command-1
9844 mark (car lway) lway name)))
9845 (setq func (eval func))
9846 (define-key map (nth 4 lway) func)))))
9847
9848(defun gnus-summary-make-marking-command-1 (mark way lway name)
9849 `(defun ,(intern
9850 (format "gnus-summary-put-mark-as-%s%s"
9851 name (if (eq way 'nomove)
9852 ""
9853 (concat "-" (symbol-name way)))))
9854 (n)
9855 ,(format
9856 "Mark the current article as %s%s.
9857If N, the prefix, then repeat N times.
9858If N is negative, move in reverse order.
9859The difference between N and the actual number of articles marked is
9860returned."
9861 name (cadr lway))
9862 (interactive "p")
9863 (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
9864
9865(defun gnus-summary-generic-mark (n mark move unread)
9866 "Mark N articles with MARK."
9867 (unless (eq major-mode 'gnus-summary-mode)
9868 (error "This command can only be used in the summary buffer"))
9869 (gnus-summary-show-thread)
9870 (let ((nummove
9871 (cond
9872 ((eq move 'next) 1)
9873 ((eq move 'prev) -1)
9874 (t 0))))
9875 (if (zerop nummove)
9876 (setq n 1)
9877 (when (< n 0)
9878 (setq n (abs n)
9879 nummove (* -1 nummove))))
9880 (while (and (> n 0)
9881 (gnus-summary-mark-article nil mark)
9882 (zerop (gnus-summary-next-subject nummove unread t)))
9883 (setq n (1- n)))
9884 (when (/= 0 n)
9885 (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9886 (gnus-summary-recenter)
9887 (gnus-summary-position-point)
9888 (gnus-set-mode-line 'summary)
9889 n))
9890
9891(gnus-summary-make-all-marking-commands)
9892
a8151ef7
LMI
9893(gnus-ems-redefine)
9894
eec82323
LMI
9895(provide 'gnus-sum)
9896
9897(run-hooks 'gnus-sum-load-hook)
9898
9899;;; gnus-sum.el ends here