(nnmail-expiry-target)
[bpt/emacs.git] / lisp / gnus / gnus-sum.el
CommitLineData
eec82323 1;;; gnus-sum.el --- summary mode commands for Gnus
16409b0b
GM
2;; Copyright (C) 1996, 1997, 1998, 1999, 2000
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."
494 :group 'gnus-summary
495 :type '(repeat character))
496
497(defcustom gnus-inhibit-user-auto-expire t
498 "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
499 :group 'gnus-summary
500 :type 'boolean)
501
eec82323
LMI
502(defcustom gnus-view-pseudos nil
503 "*If `automatic', pseudo-articles will be viewed automatically.
504If `not-confirm', pseudos will be viewed automatically, and the user
505will not be asked to confirm the command."
506 :group 'gnus-extract-view
507 :type '(choice (const :tag "off" nil)
508 (const automatic)
509 (const not-confirm)))
510
511(defcustom gnus-view-pseudos-separately t
512 "*If non-nil, one pseudo-article will be created for each file to be viewed.
513If nil, all files that use the same viewing command will be given as a
514list of parameters to that command."
515 :group 'gnus-extract-view
516 :type 'boolean)
517
518(defcustom gnus-insert-pseudo-articles t
519 "*If non-nil, insert pseudo-articles when decoding articles."
520 :group 'gnus-extract-view
521 :type 'boolean)
522
523(defcustom gnus-summary-dummy-line-format
6748645f 524 " %(: :%) %S\n"
eec82323
LMI
525 "*The format specification for the dummy roots in the summary buffer.
526It works along the same lines as a normal formatting string,
527with some simple extensions.
528
529%S The subject"
530 :group 'gnus-threading
531 :type 'string)
532
16409b0b 533(defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
eec82323
LMI
534 "*The format specification for the summary mode line.
535It works along the same lines as a normal formatting string,
536with some simple extensions:
537
538%G Group name
539%p Unprefixed group name
540%A Current article number
6748645f 541%z Current article score
eec82323
LMI
542%V Gnus version
543%U Number of unread articles in the group
544%e Number of unselected articles in the group
545%Z A string with unread/unselected article counts
546%g Shortish group name
547%S Subject of the current article
548%u User-defined spec
549%s Current score file name
550%d Number of dormant articles
551%r Number of articles that have been marked as read in this session
552%E Number of articles expunged by the score files"
553 :group 'gnus-summary-format
554 :type 'string)
555
16409b0b
GM
556(defcustom gnus-list-identifiers nil
557 "Regexp that matches list identifiers to be removed from subject.
558This can also be a list of regexps."
559 :group 'gnus-summary-format
560 :group 'gnus-article-hiding
561 :type '(choice (const :tag "none" nil)
562 (regexp :value ".*")
563 (repeat :value (".*") regexp)))
564
eec82323
LMI
565(defcustom gnus-summary-mark-below 0
566 "*Mark all articles with a score below this variable as read.
567This variable is local to each summary buffer and usually set by the
568score file."
569 :group 'gnus-score-default
570 :type 'integer)
571
572(defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
573 "*List of functions used for sorting articles in the summary buffer.
574This variable is only used when not using a threaded display."
575 :group 'gnus-summary-sort
576 :type '(repeat (choice (function-item gnus-article-sort-by-number)
577 (function-item gnus-article-sort-by-author)
578 (function-item gnus-article-sort-by-subject)
579 (function-item gnus-article-sort-by-date)
580 (function-item gnus-article-sort-by-score)
581 (function :tag "other"))))
582
583(defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
584 "*List of functions used for sorting threads in the summary buffer.
585By default, threads are sorted by article number.
586
587Each function takes two threads and return non-nil if the first thread
588should be sorted before the other. If you use more than one function,
589the primary sort function should be the last. You should probably
590always include `gnus-thread-sort-by-number' in the list of sorting
591functions -- preferably first.
592
593Ready-made functions include `gnus-thread-sort-by-number',
594`gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
595`gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
596`gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
597 :group 'gnus-summary-sort
598 :type '(repeat (choice (function-item gnus-thread-sort-by-number)
599 (function-item gnus-thread-sort-by-author)
600 (function-item gnus-thread-sort-by-subject)
601 (function-item gnus-thread-sort-by-date)
602 (function-item gnus-thread-sort-by-score)
603 (function-item gnus-thread-sort-by-total-score)
604 (function :tag "other"))))
605
606(defcustom gnus-thread-score-function '+
607 "*Function used for calculating the total score of a thread.
608
609The function is called with the scores of the article and each
610subthread and should then return the score of the thread.
611
612Some functions you can use are `+', `max', or `min'."
613 :group 'gnus-summary-sort
614 :type 'function)
615
616(defcustom gnus-summary-expunge-below nil
6748645f
LMI
617 "All articles that have a score less than this variable will be expunged.
618This variable is local to the summary buffers."
eec82323
LMI
619 :group 'gnus-score-default
620 :type '(choice (const :tag "off" nil)
621 integer))
622
623(defcustom gnus-thread-expunge-below nil
624 "All threads that have a total score less than this variable will be expunged.
625See `gnus-thread-score-function' for en explanation of what a
6748645f
LMI
626\"thread score\" is.
627
628This variable is local to the summary buffers."
16409b0b 629 :group 'gnus-threading
eec82323
LMI
630 :group 'gnus-score-default
631 :type '(choice (const :tag "off" nil)
632 integer))
633
634(defcustom gnus-summary-mode-hook nil
635 "*A hook for Gnus summary mode.
636This hook is run before any variables are set in the summary buffer."
60bd5589 637 :options '(turn-on-gnus-mailing-list-mode)
eec82323
LMI
638 :group 'gnus-summary-various
639 :type 'hook)
640
641(defcustom gnus-summary-menu-hook nil
642 "*Hook run after the creation of the summary mode menu."
643 :group 'gnus-summary-visual
644 :type 'hook)
645
646(defcustom gnus-summary-exit-hook nil
647 "*A hook called on exit from the summary buffer.
648It will be called with point in the group buffer."
649 :group 'gnus-summary-exit
650 :type 'hook)
651
652(defcustom gnus-summary-prepare-hook nil
653 "*A hook called after the summary buffer has been generated.
654If you want to modify the summary buffer, you can use this hook."
655 :group 'gnus-summary-various
656 :type 'hook)
657
6748645f
LMI
658(defcustom gnus-summary-prepared-hook nil
659 "*A hook called as the last thing after the summary buffer has been generated."
660 :group 'gnus-summary-various
661 :type 'hook)
662
eec82323
LMI
663(defcustom gnus-summary-generate-hook nil
664 "*A hook run just before generating the summary buffer.
665This hook is commonly used to customize threading variables and the
666like."
667 :group 'gnus-summary-various
668 :type 'hook)
669
670(defcustom gnus-select-group-hook nil
671 "*A hook called when a newsgroup is selected.
672
673If you'd like to simplify subjects like the
674`gnus-summary-next-same-subject' command does, you can use the
675following hook:
676
677 (setq gnus-select-group-hook
678 (list
679 (lambda ()
680 (mapcar (lambda (header)
681 (mail-header-set-subject
682 header
683 (gnus-simplify-subject
684 (mail-header-subject header) 're-only)))
685 gnus-newsgroup-headers))))"
686 :group 'gnus-group-select
687 :type 'hook)
688
689(defcustom gnus-select-article-hook nil
690 "*A hook called when an article is selected."
691 :group 'gnus-summary-choose
692 :type 'hook)
693
694(defcustom gnus-visual-mark-article-hook
695 (list 'gnus-highlight-selected-summary)
696 "*Hook run after selecting an article in the summary buffer.
697It is meant to be used for highlighting the article in some way. It
698is not run if `gnus-visual' is nil."
699 :group 'gnus-summary-visual
700 :type 'hook)
701
16409b0b 702(defcustom gnus-parse-headers-hook nil
eec82323
LMI
703 "*A hook called before parsing the headers."
704 :group 'gnus-various
705 :type 'hook)
706
707(defcustom gnus-exit-group-hook nil
16409b0b
GM
708 "*A hook called when exiting summary mode.
709This hook is not called from the non-updating exit commands like `Q'."
eec82323
LMI
710 :group 'gnus-various
711 :type 'hook)
712
713(defcustom gnus-summary-update-hook
714 (list 'gnus-summary-highlight-line)
715 "*A hook called when a summary line is changed.
716The hook will not be called if `gnus-visual' is nil.
717
718The default function `gnus-summary-highlight-line' will
719highlight the line according to the `gnus-summary-highlight'
720variable."
721 :group 'gnus-summary-visual
722 :type 'hook)
723
724(defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
725 "*A hook called when an article is selected for the first time.
726The hook is intended to mark an article as read (or unread)
727automatically when it is selected."
728 :group 'gnus-summary-choose
729 :type 'hook)
730
731(defcustom gnus-group-no-more-groups-hook nil
732 "*A hook run when returning to group mode having no more (unread) groups."
733 :group 'gnus-group-select
734 :type 'hook)
735
736(defcustom gnus-ps-print-hook nil
737 "*A hook run before ps-printing something from Gnus."
738 :group 'gnus-summary
739 :type 'hook)
740
741(defcustom gnus-summary-selected-face 'gnus-summary-selected-face
742 "Face used for highlighting the current article in the summary buffer."
743 :group 'gnus-summary-visual
744 :type 'face)
745
746(defcustom gnus-summary-highlight
747 '(((= mark gnus-canceled-mark)
748 . gnus-summary-cancelled-face)
749 ((and (> score default)
750 (or (= mark gnus-dormant-mark)
751 (= mark gnus-ticked-mark)))
752 . gnus-summary-high-ticked-face)
753 ((and (< score default)
754 (or (= mark gnus-dormant-mark)
755 (= mark gnus-ticked-mark)))
756 . gnus-summary-low-ticked-face)
757 ((or (= mark gnus-dormant-mark)
758 (= mark gnus-ticked-mark))
759 . gnus-summary-normal-ticked-face)
760 ((and (> score default) (= mark gnus-ancient-mark))
761 . gnus-summary-high-ancient-face)
762 ((and (< score default) (= mark gnus-ancient-mark))
763 . gnus-summary-low-ancient-face)
764 ((= mark gnus-ancient-mark)
765 . gnus-summary-normal-ancient-face)
766 ((and (> score default) (= mark gnus-unread-mark))
767 . gnus-summary-high-unread-face)
768 ((and (< score default) (= mark gnus-unread-mark))
769 . gnus-summary-low-unread-face)
6748645f
LMI
770 ((= mark gnus-unread-mark)
771 . gnus-summary-normal-unread-face)
772 ((and (> score default) (memq mark (list gnus-downloadable-mark
773 gnus-undownloaded-mark)))
774 . gnus-summary-high-unread-face)
775 ((and (< score default) (memq mark (list gnus-downloadable-mark
776 gnus-undownloaded-mark)))
777 . gnus-summary-low-unread-face)
778 ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
eec82323
LMI
779 . gnus-summary-normal-unread-face)
780 ((> score default)
781 . gnus-summary-high-read-face)
782 ((< score default)
783 . gnus-summary-low-read-face)
784 (t
785 . gnus-summary-normal-read-face))
6748645f 786 "*Controls the highlighting of summary buffer lines.
eec82323
LMI
787
788A list of (FORM . FACE) pairs. When deciding how a a particular
789summary line should be displayed, each form is evaluated. The content
790of the face field after the first true form is used. You can change
791how those summary lines are displayed, by editing the face field.
792
793You can use the following variables in the FORM field.
794
795score: The articles score
796default: The default article score.
797below: The score below which articles are automatically marked as read.
798mark: The articles mark."
799 :group 'gnus-summary-visual
800 :type '(repeat (cons (sexp :tag "Form" nil)
801 face)))
802
6748645f
LMI
803(defcustom gnus-alter-header-function nil
804 "Function called to allow alteration of article header structures.
805The function is called with one parameter, the article header vector,
806which it may alter in any way.")
eec82323 807
16409b0b
GM
808(defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
809 "Variable that says which function should be used to decode a string with encoded words.")
810
811(defcustom gnus-extra-headers nil
812 "*Extra headers to parse."
813 :group 'gnus-summary
814 :type '(repeat symbol))
815
816(defcustom gnus-ignored-from-addresses
817 (and user-mail-address (regexp-quote user-mail-address))
818 "*Regexp of From headers that may be suppressed in favor of To headers."
819 :group 'gnus-summary
820 :type 'regexp)
821
822(defcustom gnus-group-charset-alist
823 '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
824 ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
825 ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
826 ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
827 ("^relcom\\>" koi8-r)
828 ("^fido7\\>" koi8-r)
829 ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
830 ("^israel\\>" iso-8859-1)
831 ("^han\\>" euc-kr)
832 ("^alt.chinese.text.big5\\>" chinese-big5)
833 ("^soc.culture.vietnamese\\>" vietnamese-viqr)
834 ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
835 (".*" iso-8859-1))
836 "Alist of regexps (to match group names) and default charsets to be used when reading."
837 :type '(repeat (list (regexp :tag "Group")
838 (symbol :tag "Charset")))
839 :group 'gnus-charset)
840
841(defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
842 "List of charsets that should be ignored.
843When these charsets are used in the \"charset\" parameter, the
844default charset will be used instead."
845 :type '(repeat symbol)
846 :group 'gnus-charset)
847
848(defcustom gnus-group-ignored-charsets-alist
849 '(("alt\\.chinese\\.text" iso-8859-1))
850 "Alist of regexps (to match group names) and charsets that should be ignored.
851When these charsets are used in the \"charset\" parameter, the
852default charset will be used instead."
853 :type '(repeat (cons (regexp :tag "Group")
854 (repeat symbol)))
855 :group 'gnus-charset)
856
857(defcustom gnus-group-highlight-words-alist nil
858 "Alist of group regexps and highlight regexps.
859This variable uses the same syntax as `gnus-emphasis-alist'."
860 :type '(repeat (cons (regexp :tag "Group")
861 (repeat (list (regexp :tag "Highlight regexp")
862 (number :tag "Group for entire word" 0)
863 (number :tag "Group for displayed part" 0)
864 (symbol :tag "Face"
865 gnus-emphasis-highlight-words)))))
866 :group 'gnus-summary-visual)
867
868(defcustom gnus-summary-show-article-charset-alist
869 nil
870 "Alist of number and charset.
871The article will be shown with the charset corresponding to the
872numbered argument.
873For example: ((1 . cn-gb-2312) (2 . big5))."
874 :type '(repeat (cons (number :tag "Argument" 1)
875 (symbol :tag "Charset")))
876 :group 'gnus-charset)
877
878(defcustom gnus-preserve-marks t
879 "Whether marks are preserved when moving, copying and respooling messages."
880 :type 'boolean
881 :group 'gnus-summary-marks)
882
883(defcustom gnus-alter-articles-to-read-function nil
884 "Function to be called to alter the list of articles to be selected."
885 :type 'function
886 :group 'gnus-summary)
887
888(defcustom gnus-orphan-score nil
889 "*All orphans get this score added. Set in the score file."
890 :group 'gnus-score-default
891 :type '(choice (const nil)
892 integer))
893
8b93df01
DL
894(defcustom gnus-summary-save-parts-default-mime "image/.*"
895 "*A regexp to match MIME parts when saving multiple parts of a message
896with gnus-summary-save-parts (X m). This regexp will be used by default
897when prompting the user for which type of files to save."
898 :group 'gnus-summary
899 :type 'regexp)
900
901
eec82323
LMI
902;;; Internal variables
903
16409b0b
GM
904(defvar gnus-article-mime-handles nil)
905(defvar gnus-article-decoded-p nil)
eec82323
LMI
906(defvar gnus-scores-exclude-files nil)
907(defvar gnus-page-broken nil)
16409b0b 908(defvar gnus-inhibit-mime-unbuttonizing nil)
eec82323
LMI
909
910(defvar gnus-original-article nil)
911(defvar gnus-article-internal-prepare-hook nil)
912(defvar gnus-newsgroup-process-stack nil)
913
914(defvar gnus-thread-indent-array nil)
915(defvar gnus-thread-indent-array-level gnus-thread-indent-level)
16409b0b
GM
916(defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
917 "Function called to sort the articles within a thread after it has been gathered together.")
eec82323 918
8b93df01
DL
919(defvar gnus-summary-save-parts-type-history nil)
920(defvar gnus-summary-save-parts-last-directory nil)
921
eec82323
LMI
922;; Avoid highlighting in kill files.
923(defvar gnus-summary-inhibit-highlight nil)
924(defvar gnus-newsgroup-selected-overlay nil)
925(defvar gnus-inhibit-limiting nil)
926(defvar gnus-newsgroup-adaptive-score-file nil)
927(defvar gnus-current-score-file nil)
928(defvar gnus-current-move-group nil)
929(defvar gnus-current-copy-group nil)
930(defvar gnus-current-crosspost-group nil)
931
932(defvar gnus-newsgroup-dependencies nil)
933(defvar gnus-newsgroup-adaptive nil)
934(defvar gnus-summary-display-article-function nil)
935(defvar gnus-summary-highlight-line-function nil
936 "Function called after highlighting a summary line.")
937
938(defvar gnus-summary-line-format-alist
939 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
940 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
941 (?s gnus-tmp-subject-or-nil ?s)
942 (?n gnus-tmp-name ?s)
943 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
944 ?s)
945 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
946 gnus-tmp-from) ?s)
947 (?F gnus-tmp-from ?s)
948 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
949 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
950 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
6748645f 951 (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
eec82323
LMI
952 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
953 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
954 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
955 (?L gnus-tmp-lines ?d)
956 (?I gnus-tmp-indentation ?s)
957 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
958 (?R gnus-tmp-replied ?c)
959 (?\[ gnus-tmp-opening-bracket ?c)
960 (?\] gnus-tmp-closing-bracket ?c)
961 (?\> (make-string gnus-tmp-level ? ) ?s)
962 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
963 (?i gnus-tmp-score ?d)
964 (?z gnus-tmp-score-char ?c)
965 (?l (bbb-grouplens-score gnus-tmp-header) ?s)
966 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
967 (?U gnus-tmp-unread ?c)
16409b0b 968 (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
eec82323
LMI
969 (?t (gnus-summary-number-of-articles-in-thread
970 (and (boundp 'thread) (car thread)) gnus-tmp-level)
971 ?d)
972 (?e (gnus-summary-number-of-articles-in-thread
973 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
974 ?c)
975 (?u gnus-tmp-user-defined ?s)
976 (?P (gnus-pick-line-number) ?d))
16409b0b
GM
977 "An alist of format specifications that can appear in summary lines.
978These are paired with what variables they correspond with, along with
979the type of the variable (string, integer, character, etc).")
eec82323
LMI
980
981(defvar gnus-summary-dummy-line-format-alist
982 `((?S gnus-tmp-subject ?s)
983 (?N gnus-tmp-number ?d)
984 (?u gnus-tmp-user-defined ?s)))
985
986(defvar gnus-summary-mode-line-format-alist
987 `((?G gnus-tmp-group-name ?s)
988 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
989 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
990 (?A gnus-tmp-article-number ?d)
991 (?Z gnus-tmp-unread-and-unselected ?s)
992 (?V gnus-version ?s)
993 (?U gnus-tmp-unread-and-unticked ?d)
994 (?S gnus-tmp-subject ?s)
995 (?e gnus-tmp-unselected ?d)
996 (?u gnus-tmp-user-defined ?s)
997 (?d (length gnus-newsgroup-dormant) ?d)
998 (?t (length gnus-newsgroup-marked) ?d)
999 (?r (length gnus-newsgroup-reads) ?d)
6748645f 1000 (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
eec82323
LMI
1001 (?E gnus-newsgroup-expunged-tally ?d)
1002 (?s (gnus-current-score-file-nondirectory) ?s)))
1003
1004(defvar gnus-last-search-regexp nil
1005 "Default regexp for article search command.")
1006
1007(defvar gnus-last-shell-command nil
1008 "Default shell command on article.")
1009
1010(defvar gnus-newsgroup-begin nil)
1011(defvar gnus-newsgroup-end nil)
1012(defvar gnus-newsgroup-last-rmail nil)
1013(defvar gnus-newsgroup-last-mail nil)
1014(defvar gnus-newsgroup-last-folder nil)
1015(defvar gnus-newsgroup-last-file nil)
1016(defvar gnus-newsgroup-auto-expire nil)
1017(defvar gnus-newsgroup-active nil)
1018
1019(defvar gnus-newsgroup-data nil)
1020(defvar gnus-newsgroup-data-reverse nil)
1021(defvar gnus-newsgroup-limit nil)
1022(defvar gnus-newsgroup-limits nil)
1023
1024(defvar gnus-newsgroup-unreads nil
1025 "List of unread articles in the current newsgroup.")
1026
1027(defvar gnus-newsgroup-unselected nil
1028 "List of unselected unread articles in the current newsgroup.")
1029
1030(defvar gnus-newsgroup-reads nil
1031 "Alist of read articles and article marks in the current newsgroup.")
1032
1033(defvar gnus-newsgroup-expunged-tally nil)
1034
1035(defvar gnus-newsgroup-marked nil
1036 "List of ticked articles in the current newsgroup (a subset of unread art).")
1037
1038(defvar gnus-newsgroup-killed nil
1039 "List of ranges of articles that have been through the scoring process.")
1040
1041(defvar gnus-newsgroup-cached nil
1042 "List of articles that come from the article cache.")
1043
1044(defvar gnus-newsgroup-saved nil
1045 "List of articles that have been saved.")
1046
1047(defvar gnus-newsgroup-kill-headers nil)
1048
1049(defvar gnus-newsgroup-replied nil
1050 "List of articles that have been replied to in the current newsgroup.")
1051
1052(defvar gnus-newsgroup-expirable nil
1053 "List of articles in the current newsgroup that can be expired.")
1054
1055(defvar gnus-newsgroup-processable nil
1056 "List of articles in the current newsgroup that can be processed.")
1057
6748645f
LMI
1058(defvar gnus-newsgroup-downloadable nil
1059 "List of articles in the current newsgroup that can be processed.")
1060
1061(defvar gnus-newsgroup-undownloaded nil
1062 "List of articles in the current newsgroup that haven't been downloaded..")
1063
1064(defvar gnus-newsgroup-unsendable nil
1065 "List of articles in the current newsgroup that won't be sent.")
1066
eec82323
LMI
1067(defvar gnus-newsgroup-bookmarks nil
1068 "List of articles in the current newsgroup that have bookmarks.")
1069
1070(defvar gnus-newsgroup-dormant nil
1071 "List of dormant articles in the current newsgroup.")
1072
1073(defvar gnus-newsgroup-scored nil
1074 "List of scored articles in the current newsgroup.")
1075
1076(defvar gnus-newsgroup-headers nil
1077 "List of article headers in the current newsgroup.")
1078
1079(defvar gnus-newsgroup-threads nil)
1080
1081(defvar gnus-newsgroup-prepared nil
1082 "Whether the current group has been prepared properly.")
1083
1084(defvar gnus-newsgroup-ancient nil
1085 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1086
1087(defvar gnus-newsgroup-sparse nil)
1088
1089(defvar gnus-current-article nil)
1090(defvar gnus-article-current nil)
1091(defvar gnus-current-headers nil)
1092(defvar gnus-have-all-headers nil)
1093(defvar gnus-last-article nil)
1094(defvar gnus-newsgroup-history nil)
16409b0b
GM
1095(defvar gnus-newsgroup-charset nil)
1096(defvar gnus-newsgroup-ephemeral-charset nil)
1097(defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
eec82323
LMI
1098
1099(defconst gnus-summary-local-variables
1100 '(gnus-newsgroup-name
1101 gnus-newsgroup-begin gnus-newsgroup-end
1102 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1103 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1104 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1105 gnus-newsgroup-unselected gnus-newsgroup-marked
1106 gnus-newsgroup-reads gnus-newsgroup-saved
1107 gnus-newsgroup-replied gnus-newsgroup-expirable
1108 gnus-newsgroup-processable gnus-newsgroup-killed
6748645f
LMI
1109 gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1110 gnus-newsgroup-unsendable
eec82323
LMI
1111 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1112 gnus-newsgroup-headers gnus-newsgroup-threads
1113 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1114 gnus-current-article gnus-current-headers gnus-have-all-headers
1115 gnus-last-article gnus-article-internal-prepare-hook
1116 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1117 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1118 gnus-thread-expunge-below
16409b0b
GM
1119 gnus-score-alist gnus-current-score-file
1120 (gnus-summary-expunge-below . global)
eec82323 1121 (gnus-summary-mark-below . global)
16409b0b 1122 (gnus-orphan-score . global)
eec82323
LMI
1123 gnus-newsgroup-active gnus-scores-exclude-files
1124 gnus-newsgroup-history gnus-newsgroup-ancient
1125 gnus-newsgroup-sparse gnus-newsgroup-process-stack
1126 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1127 gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1128 (gnus-newsgroup-expunged-tally . 0)
1129 gnus-cache-removable-articles gnus-newsgroup-cached
1130 gnus-newsgroup-data gnus-newsgroup-data-reverse
16409b0b
GM
1131 gnus-newsgroup-limit gnus-newsgroup-limits
1132 gnus-newsgroup-charset)
eec82323
LMI
1133 "Variables that are buffer-local to the summary buffers.")
1134
1135;; Byte-compiler warning.
60bd5589 1136(eval-when-compile (defvar gnus-article-mode-map))
eec82323 1137
16409b0b
GM
1138;; MIME stuff.
1139
1140(defvar gnus-decode-encoded-word-methods
1141 '(mail-decode-encoded-word-string)
1142 "List of methods used to decode encoded words.
1143
1144This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
1145FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
1146(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1147whose names match REGEXP.
1148
1149For example:
1150((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1151 mail-decode-encoded-word-string
1152 (\"chinese\" . rfc1843-decode-string))")
1153
1154(defvar gnus-decode-encoded-word-methods-cache nil)
1155
1156(defun gnus-multi-decode-encoded-word-string (string)
1157 "Apply the functions from `gnus-encoded-word-methods' that match."
1158 (unless (and gnus-decode-encoded-word-methods-cache
1159 (eq gnus-newsgroup-name
1160 (car gnus-decode-encoded-word-methods-cache)))
1161 (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1162 (mapcar (lambda (x)
1163 (if (symbolp x)
1164 (nconc gnus-decode-encoded-word-methods-cache (list x))
1165 (if (and gnus-newsgroup-name
1166 (string-match (car x) gnus-newsgroup-name))
1167 (nconc gnus-decode-encoded-word-methods-cache
1168 (list (cdr x))))))
1169 gnus-decode-encoded-word-methods))
1170 (let ((xlist gnus-decode-encoded-word-methods-cache))
1171 (pop xlist)
1172 (while xlist
1173 (setq string (funcall (pop xlist) string))))
1174 string)
1175
eec82323
LMI
1176;; Subject simplification.
1177
6748645f 1178(defun gnus-simplify-whitespace (str)
16409b0b 1179 "Remove excessive whitespace from STR."
6748645f
LMI
1180 (let ((mystr str))
1181 ;; Multiple spaces.
1182 (while (string-match "[ \t][ \t]+" mystr)
1183 (setq mystr (concat (substring mystr 0 (match-beginning 0))
1184 " "
1185 (substring mystr (match-end 0)))))
1186 ;; Leading spaces.
1187 (when (string-match "^[ \t]+" mystr)
1188 (setq mystr (substring mystr (match-end 0))))
1189 ;; Trailing spaces.
1190 (when (string-match "[ \t]+$" mystr)
1191 (setq mystr (substring mystr 0 (match-beginning 0))))
1192 mystr))
1193
eec82323
LMI
1194(defsubst gnus-simplify-subject-re (subject)
1195 "Remove \"Re:\" from subject lines."
1196 (if (string-match "^[Rr][Ee]: *" subject)
1197 (substring subject (match-end 0))
1198 subject))
1199
1200(defun gnus-simplify-subject (subject &optional re-only)
1201 "Remove `Re:' and words in parentheses.
1202If RE-ONLY is non-nil, strip leading `Re:'s only."
1203 (let ((case-fold-search t)) ;Ignore case.
1204 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1205 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1206 (setq subject (substring subject (match-end 0))))
1207 ;; Remove uninteresting prefixes.
1208 (when (and (not re-only)
1209 gnus-simplify-ignored-prefixes
1210 (string-match gnus-simplify-ignored-prefixes subject))
1211 (setq subject (substring subject (match-end 0))))
1212 ;; Remove words in parentheses from end.
1213 (unless re-only
1214 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1215 (setq subject (substring subject 0 (match-beginning 0)))))
1216 ;; Return subject string.
1217 subject))
1218
1219;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1220;; all whitespace.
1221(defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1222 (goto-char (point-min))
1223 (while (re-search-forward regexp nil t)
16409b0b 1224 (replace-match (or newtext ""))))
eec82323
LMI
1225
1226(defun gnus-simplify-buffer-fuzzy ()
1227 "Simplify string in the buffer fuzzily.
1228The string in the accessible portion of the current buffer is simplified.
1229It is assumed to be a single-line subject.
1230Whitespace is generally cleaned up, and miscellaneous leading/trailing
1231matter is removed. Additional things can be deleted by setting
16409b0b 1232`gnus-simplify-subject-fuzzy-regexp'."
eec82323
LMI
1233 (let ((case-fold-search t)
1234 (modified-tick))
1235 (gnus-simplify-buffer-fuzzy-step "\t" " ")
1236
1237 (while (not (eq modified-tick (buffer-modified-tick)))
1238 (setq modified-tick (buffer-modified-tick))
1239 (cond
1240 ((listp gnus-simplify-subject-fuzzy-regexp)
1241 (mapcar 'gnus-simplify-buffer-fuzzy-step
1242 gnus-simplify-subject-fuzzy-regexp))
1243 (gnus-simplify-subject-fuzzy-regexp
1244 (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1245 (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1246 (gnus-simplify-buffer-fuzzy-step
1247 "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1248 (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1249
1250 (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1251 (gnus-simplify-buffer-fuzzy-step " +" " ")
1252 (gnus-simplify-buffer-fuzzy-step " $")
1253 (gnus-simplify-buffer-fuzzy-step "^ +")))
1254
1255(defun gnus-simplify-subject-fuzzy (subject)
1256 "Simplify a subject string fuzzily.
6748645f 1257See `gnus-simplify-buffer-fuzzy' for details."
eec82323
LMI
1258 (save-excursion
1259 (gnus-set-work-buffer)
1260 (let ((case-fold-search t))
6748645f
LMI
1261 ;; Remove uninteresting prefixes.
1262 (when (and gnus-simplify-ignored-prefixes
1263 (string-match gnus-simplify-ignored-prefixes subject))
1264 (setq subject (substring subject (match-end 0))))
eec82323
LMI
1265 (insert subject)
1266 (inline (gnus-simplify-buffer-fuzzy))
1267 (buffer-string))))
1268
1269(defsubst gnus-simplify-subject-fully (subject)
1270 "Simplify a subject string according to gnus-summary-gather-subject-limit."
1271 (cond
6748645f
LMI
1272 (gnus-simplify-subject-functions
1273 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
1274 ((null gnus-summary-gather-subject-limit)
1275 (gnus-simplify-subject-re subject))
1276 ((eq gnus-summary-gather-subject-limit 'fuzzy)
1277 (gnus-simplify-subject-fuzzy subject))
1278 ((numberp gnus-summary-gather-subject-limit)
1279 (gnus-limit-string (gnus-simplify-subject-re subject)
1280 gnus-summary-gather-subject-limit))
1281 (t
1282 subject)))
1283
1284(defsubst gnus-subject-equal (s1 s2 &optional simple-first)
6748645f
LMI
1285 "Check whether two subjects are equal.
1286If optional argument simple-first is t, first argument is already
1287simplified."
eec82323
LMI
1288 (cond
1289 ((null simple-first)
1290 (equal (gnus-simplify-subject-fully s1)
1291 (gnus-simplify-subject-fully s2)))
1292 (t
1293 (equal s1
1294 (gnus-simplify-subject-fully s2)))))
1295
1296(defun gnus-summary-bubble-group ()
1297 "Increase the score of the current group.
1298This is a handy function to add to `gnus-summary-exit-hook' to
1299increase the score of each group you read."
1300 (gnus-group-add-score gnus-newsgroup-name))
1301
1302\f
1303;;;
1304;;; Gnus summary mode
1305;;;
1306
1307(put 'gnus-summary-mode 'mode-class 'special)
1308
1309(when t
1310 ;; Non-orthogonal keys
1311
1312 (gnus-define-keys gnus-summary-mode-map
1313 " " gnus-summary-next-page
1314 "\177" gnus-summary-prev-page
1315 [delete] gnus-summary-prev-page
6748645f 1316 [backspace] gnus-summary-prev-page
eec82323 1317 "\r" gnus-summary-scroll-up
6748645f 1318 "\M-\r" gnus-summary-scroll-down
eec82323
LMI
1319 "n" gnus-summary-next-unread-article
1320 "p" gnus-summary-prev-unread-article
1321 "N" gnus-summary-next-article
1322 "P" gnus-summary-prev-article
1323 "\M-\C-n" gnus-summary-next-same-subject
1324 "\M-\C-p" gnus-summary-prev-same-subject
1325 "\M-n" gnus-summary-next-unread-subject
1326 "\M-p" gnus-summary-prev-unread-subject
1327 "." gnus-summary-first-unread-article
1328 "," gnus-summary-best-unread-article
1329 "\M-s" gnus-summary-search-article-forward
1330 "\M-r" gnus-summary-search-article-backward
1331 "<" gnus-summary-beginning-of-article
1332 ">" gnus-summary-end-of-article
1333 "j" gnus-summary-goto-article
1334 "^" gnus-summary-refer-parent-article
1335 "\M-^" gnus-summary-refer-article
1336 "u" gnus-summary-tick-article-forward
1337 "!" gnus-summary-tick-article-forward
1338 "U" gnus-summary-tick-article-backward
1339 "d" gnus-summary-mark-as-read-forward
1340 "D" gnus-summary-mark-as-read-backward
1341 "E" gnus-summary-mark-as-expirable
1342 "\M-u" gnus-summary-clear-mark-forward
1343 "\M-U" gnus-summary-clear-mark-backward
1344 "k" gnus-summary-kill-same-subject-and-select
1345 "\C-k" gnus-summary-kill-same-subject
1346 "\M-\C-k" gnus-summary-kill-thread
1347 "\M-\C-l" gnus-summary-lower-thread
1348 "e" gnus-summary-edit-article
1349 "#" gnus-summary-mark-as-processable
1350 "\M-#" gnus-summary-unmark-as-processable
1351 "\M-\C-t" gnus-summary-toggle-threads
1352 "\M-\C-s" gnus-summary-show-thread
1353 "\M-\C-h" gnus-summary-hide-thread
1354 "\M-\C-f" gnus-summary-next-thread
1355 "\M-\C-b" gnus-summary-prev-thread
16409b0b
GM
1356 [(meta down)] gnus-summary-next-thread
1357 [(meta up)] gnus-summary-prev-thread
eec82323
LMI
1358 "\M-\C-u" gnus-summary-up-thread
1359 "\M-\C-d" gnus-summary-down-thread
1360 "&" gnus-summary-execute-command
1361 "c" gnus-summary-catchup-and-exit
1362 "\C-w" gnus-summary-mark-region-as-read
1363 "\C-t" gnus-summary-toggle-truncation
1364 "?" gnus-summary-mark-as-dormant
1365 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1366 "\C-c\C-s\C-n" gnus-summary-sort-by-number
1367 "\C-c\C-s\C-l" gnus-summary-sort-by-lines
16409b0b 1368 "\C-c\C-s\C-c" gnus-summary-sort-by-chars
eec82323
LMI
1369 "\C-c\C-s\C-a" gnus-summary-sort-by-author
1370 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1371 "\C-c\C-s\C-d" gnus-summary-sort-by-date
1372 "\C-c\C-s\C-i" gnus-summary-sort-by-score
1373 "=" gnus-summary-expand-window
1374 "\C-x\C-s" gnus-summary-reselect-current-group
1375 "\M-g" gnus-summary-rescan-group
1376 "w" gnus-summary-stop-page-breaking
1377 "\C-c\C-r" gnus-summary-caesar-message
eec82323
LMI
1378 "f" gnus-summary-followup
1379 "F" gnus-summary-followup-with-original
1380 "C" gnus-summary-cancel-article
1381 "r" gnus-summary-reply
1382 "R" gnus-summary-reply-with-original
1383 "\C-c\C-f" gnus-summary-mail-forward
1384 "o" gnus-summary-save-article
1385 "\C-o" gnus-summary-save-article-mail
1386 "|" gnus-summary-pipe-output
1387 "\M-k" gnus-summary-edit-local-kill
1388 "\M-K" gnus-summary-edit-global-kill
1389 ;; "V" gnus-version
1390 "\C-c\C-d" gnus-summary-describe-group
1391 "q" gnus-summary-exit
1392 "Q" gnus-summary-exit-no-update
1393 "\C-c\C-i" gnus-info-find-node
1394 gnus-mouse-2 gnus-mouse-pick-article
1395 "m" gnus-summary-mail-other-window
1396 "a" gnus-summary-post-news
1397 "x" gnus-summary-limit-to-unread
1398 "s" gnus-summary-isearch-article
16409b0b 1399 "t" gnus-summary-toggle-header
eec82323
LMI
1400 "g" gnus-summary-show-article
1401 "l" gnus-summary-goto-last-article
1402 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1403 "\C-d" gnus-summary-enter-digest-group
1404 "\M-\C-d" gnus-summary-read-document
6748645f 1405 "\M-\C-e" gnus-summary-edit-parameters
16409b0b 1406 "\M-\C-a" gnus-summary-customize-parameters
eec82323
LMI
1407 "\C-c\C-b" gnus-bug
1408 "*" gnus-cache-enter-article
1409 "\M-*" gnus-cache-remove-article
1410 "\M-&" gnus-summary-universal-argument
1411 "\C-l" gnus-recenter
1412 "I" gnus-summary-increase-score
1413 "L" gnus-summary-lower-score
6748645f
LMI
1414 "\M-i" gnus-symbolic-argument
1415 "h" gnus-summary-select-article-buffer
eec82323 1416
16409b0b
GM
1417 "b" gnus-article-view-part
1418 "\M-t" gnus-summary-toggle-display-buttonized
1419
eec82323
LMI
1420 "V" gnus-summary-score-map
1421 "X" gnus-uu-extract-map
1422 "S" gnus-summary-send-map)
1423
1424 ;; Sort of orthogonal keymap
1425 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1426 "t" gnus-summary-tick-article-forward
1427 "!" gnus-summary-tick-article-forward
1428 "d" gnus-summary-mark-as-read-forward
1429 "r" gnus-summary-mark-as-read-forward
1430 "c" gnus-summary-clear-mark-forward
1431 " " gnus-summary-clear-mark-forward
1432 "e" gnus-summary-mark-as-expirable
1433 "x" gnus-summary-mark-as-expirable
1434 "?" gnus-summary-mark-as-dormant
1435 "b" gnus-summary-set-bookmark
1436 "B" gnus-summary-remove-bookmark
1437 "#" gnus-summary-mark-as-processable
1438 "\M-#" gnus-summary-unmark-as-processable
1439 "S" gnus-summary-limit-include-expunged
1440 "C" gnus-summary-catchup
1441 "H" gnus-summary-catchup-to-here
1442 "\C-c" gnus-summary-catchup-all
1443 "k" gnus-summary-kill-same-subject-and-select
1444 "K" gnus-summary-kill-same-subject
1445 "P" gnus-uu-mark-map)
1446
1447 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1448 "c" gnus-summary-clear-above
1449 "u" gnus-summary-tick-above
1450 "m" gnus-summary-mark-above
1451 "k" gnus-summary-kill-below)
1452
1453 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1454 "/" gnus-summary-limit-to-subject
1455 "n" gnus-summary-limit-to-articles
1456 "w" gnus-summary-pop-limit
1457 "s" gnus-summary-limit-to-subject
1458 "a" gnus-summary-limit-to-author
1459 "u" gnus-summary-limit-to-unread
1460 "m" gnus-summary-limit-to-marks
16409b0b 1461 "M" gnus-summary-limit-exclude-marks
eec82323 1462 "v" gnus-summary-limit-to-score
6748645f 1463 "*" gnus-summary-limit-include-cached
eec82323 1464 "D" gnus-summary-limit-include-dormant
6748645f 1465 "T" gnus-summary-limit-include-thread
eec82323
LMI
1466 "d" gnus-summary-limit-exclude-dormant
1467 "t" gnus-summary-limit-to-age
16409b0b 1468 "x" gnus-summary-limit-to-extra
eec82323
LMI
1469 "E" gnus-summary-limit-include-expunged
1470 "c" gnus-summary-limit-exclude-childless-dormant
1471 "C" gnus-summary-limit-mark-excluded-as-read)
1472
1473 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1474 "n" gnus-summary-next-unread-article
1475 "p" gnus-summary-prev-unread-article
1476 "N" gnus-summary-next-article
1477 "P" gnus-summary-prev-article
1478 "\C-n" gnus-summary-next-same-subject
1479 "\C-p" gnus-summary-prev-same-subject
1480 "\M-n" gnus-summary-next-unread-subject
1481 "\M-p" gnus-summary-prev-unread-subject
1482 "f" gnus-summary-first-unread-article
1483 "b" gnus-summary-best-unread-article
1484 "j" gnus-summary-goto-article
1485 "g" gnus-summary-goto-subject
1486 "l" gnus-summary-goto-last-article
a8151ef7 1487 "o" gnus-summary-pop-article)
eec82323
LMI
1488
1489 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1490 "k" gnus-summary-kill-thread
1491 "l" gnus-summary-lower-thread
1492 "i" gnus-summary-raise-thread
1493 "T" gnus-summary-toggle-threads
1494 "t" gnus-summary-rethread-current
1495 "^" gnus-summary-reparent-thread
1496 "s" gnus-summary-show-thread
1497 "S" gnus-summary-show-all-threads
1498 "h" gnus-summary-hide-thread
1499 "H" gnus-summary-hide-all-threads
1500 "n" gnus-summary-next-thread
1501 "p" gnus-summary-prev-thread
1502 "u" gnus-summary-up-thread
1503 "o" gnus-summary-top-thread
1504 "d" gnus-summary-down-thread
1505 "#" gnus-uu-mark-thread
1506 "\M-#" gnus-uu-unmark-thread)
1507
1508 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1509 "g" gnus-summary-prepare
1510 "c" gnus-summary-insert-cached-articles)
1511
1512 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1513 "c" gnus-summary-catchup-and-exit
1514 "C" gnus-summary-catchup-all-and-exit
1515 "E" gnus-summary-exit-no-update
1516 "Q" gnus-summary-exit
1517 "Z" gnus-summary-exit
1518 "n" gnus-summary-catchup-and-goto-next-group
1519 "R" gnus-summary-reselect-current-group
1520 "G" gnus-summary-rescan-group
1521 "N" gnus-summary-next-group
1522 "s" gnus-summary-save-newsrc
1523 "P" gnus-summary-prev-group)
1524
1525 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1526 " " gnus-summary-next-page
1527 "n" gnus-summary-next-page
1528 "\177" gnus-summary-prev-page
1529 [delete] gnus-summary-prev-page
1530 "p" gnus-summary-prev-page
1531 "\r" gnus-summary-scroll-up
6748645f 1532 "\M-\r" gnus-summary-scroll-down
eec82323
LMI
1533 "<" gnus-summary-beginning-of-article
1534 ">" gnus-summary-end-of-article
1535 "b" gnus-summary-beginning-of-article
1536 "e" gnus-summary-end-of-article
1537 "^" gnus-summary-refer-parent-article
1538 "r" gnus-summary-refer-parent-article
16409b0b 1539 "D" gnus-summary-enter-digest-group
eec82323 1540 "R" gnus-summary-refer-references
6748645f 1541 "T" gnus-summary-refer-thread
eec82323
LMI
1542 "g" gnus-summary-show-article
1543 "s" gnus-summary-isearch-article
16409b0b
GM
1544 "P" gnus-summary-print-article
1545 "t" gnus-article-babel)
eec82323
LMI
1546
1547 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1548 "b" gnus-article-add-buttons
1549 "B" gnus-article-add-buttons-to-head
1550 "o" gnus-article-treat-overstrike
1551 "e" gnus-article-emphasize
1552 "w" gnus-article-fill-cited-article
16409b0b
GM
1553 "Q" gnus-article-fill-long-lines
1554 "C" gnus-article-capitalize-sentences
eec82323
LMI
1555 "c" gnus-article-remove-cr
1556 "q" gnus-article-de-quoted-unreadable
16409b0b
GM
1557 "6" gnus-article-de-base64-unreadable
1558 "Z" gnus-article-decode-HZ
1559 "h" gnus-article-wash-html
eec82323
LMI
1560 "f" gnus-article-display-x-face
1561 "l" gnus-summary-stop-page-breaking
1562 "r" gnus-summary-caesar-message
16409b0b 1563 "t" gnus-summary-toggle-header
eec82323 1564 "v" gnus-summary-verbose-headers
16409b0b 1565 "H" gnus-article-strip-headers-in-body
6748645f 1566 "d" gnus-article-treat-dumbquotes)
eec82323
LMI
1567
1568 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1569 "a" gnus-article-hide
1570 "h" gnus-article-hide-headers
1571 "b" gnus-article-hide-boring-headers
1572 "s" gnus-article-hide-signature
1573 "c" gnus-article-hide-citation
6748645f 1574 "C" gnus-article-hide-citation-in-followups
16409b0b 1575 "l" gnus-article-hide-list-identifiers
eec82323 1576 "p" gnus-article-hide-pgp
16409b0b 1577 "B" gnus-article-strip-banner
eec82323
LMI
1578 "P" gnus-article-hide-pem
1579 "\C-c" gnus-article-hide-citation-maybe)
1580
1581 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1582 "a" gnus-article-highlight
1583 "h" gnus-article-highlight-headers
1584 "c" gnus-article-highlight-citation
1585 "s" gnus-article-highlight-signature)
1586
16409b0b
GM
1587 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1588 "w" gnus-article-decode-mime-words
1589 "c" gnus-article-decode-charset
1590 "v" gnus-mime-view-all-parts
1591 "b" gnus-article-view-part)
1592
eec82323
LMI
1593 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1594 "z" gnus-article-date-ut
1595 "u" gnus-article-date-ut
1596 "l" gnus-article-date-local
1597 "e" gnus-article-date-lapsed
1598 "o" gnus-article-date-original
6748645f 1599 "i" gnus-article-date-iso8601
eec82323
LMI
1600 "s" gnus-article-date-user)
1601
1602 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1603 "t" gnus-article-remove-trailing-blank-lines
1604 "l" gnus-article-strip-leading-blank-lines
1605 "m" gnus-article-strip-multiple-blank-lines
1606 "a" gnus-article-strip-blank-lines
6748645f 1607 "A" gnus-article-strip-all-blank-lines
16409b0b
GM
1608 "s" gnus-article-strip-leading-space
1609 "e" gnus-article-strip-trailing-space)
eec82323
LMI
1610
1611 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1612 "v" gnus-version
1613 "f" gnus-summary-fetch-faq
1614 "d" gnus-summary-describe-group
1615 "h" gnus-summary-describe-briefly
1616 "i" gnus-info-find-node)
1617
1618 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1619 "e" gnus-summary-expire-articles
1620 "\M-\C-e" gnus-summary-expire-articles-now
1621 "\177" gnus-summary-delete-article
1622 [delete] gnus-summary-delete-article
16409b0b 1623 [backspace] gnus-summary-delete-article
eec82323
LMI
1624 "m" gnus-summary-move-article
1625 "r" gnus-summary-respool-article
1626 "w" gnus-summary-edit-article
1627 "c" gnus-summary-copy-article
1628 "B" gnus-summary-crosspost-article
1629 "q" gnus-summary-respool-query
6748645f 1630 "t" gnus-summary-respool-trace
eec82323
LMI
1631 "i" gnus-summary-import-article
1632 "p" gnus-summary-article-posted-p)
1633
1634 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1635 "o" gnus-summary-save-article
1636 "m" gnus-summary-save-article-mail
1637 "F" gnus-summary-write-article-file
1638 "r" gnus-summary-save-article-rmail
1639 "f" gnus-summary-save-article-file
1640 "b" gnus-summary-save-article-body-file
1641 "h" gnus-summary-save-article-folder
1642 "v" gnus-summary-save-article-vm
1643 "p" gnus-summary-pipe-output
16409b0b
GM
1644 "s" gnus-soup-add-article)
1645
1646 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1647 "b" gnus-summary-display-buttonized
1648 "m" gnus-summary-repair-multipart
1649 "v" gnus-article-view-part
1650 "o" gnus-article-save-part
1651 "c" gnus-article-copy-part
1652 "e" gnus-article-externalize-part
1653 "i" gnus-article-inline-part
1654 "|" gnus-article-pipe-part))
eec82323
LMI
1655
1656(defun gnus-summary-make-menu-bar ()
1657 (gnus-turn-off-edit-menu 'summary)
1658
1659 (unless (boundp 'gnus-summary-misc-menu)
1660
1661 (easy-menu-define
1662 gnus-summary-kill-menu gnus-summary-mode-map ""
1663 (cons
1664 "Score"
1665 (nconc
1666 (list
1667 ["Enter score..." gnus-summary-score-entry t]
1668 ["Customize" gnus-score-customize t])
1669 (gnus-make-score-map 'increase)
1670 (gnus-make-score-map 'lower)
1671 '(("Mark"
1672 ["Kill below" gnus-summary-kill-below t]
1673 ["Mark above" gnus-summary-mark-above t]
1674 ["Tick above" gnus-summary-tick-above t]
1675 ["Clear above" gnus-summary-clear-above t])
1676 ["Current score" gnus-summary-current-score t]
1677 ["Set score" gnus-summary-set-score t]
1678 ["Switch current score file..." gnus-score-change-score-file t]
1679 ["Set mark below..." gnus-score-set-mark-below t]
1680 ["Set expunge below..." gnus-score-set-expunge-below t]
1681 ["Edit current score file" gnus-score-edit-current-scores t]
1682 ["Edit score file" gnus-score-edit-file t]
1683 ["Trace score" gnus-score-find-trace t]
1684 ["Find words" gnus-score-find-favourite-words t]
1685 ["Rescore buffer" gnus-summary-rescore t]
1686 ["Increase score..." gnus-summary-increase-score t]
1687 ["Lower score..." gnus-summary-lower-score t]))))
1688
6748645f
LMI
1689 ;; Define both the Article menu in the summary buffer and the equivalent
1690 ;; Commands menu in the article buffer here for consistency.
1691 (let ((innards
1692 '(("Hide"
1693 ["All" gnus-article-hide t]
1694 ["Headers" gnus-article-hide-headers t]
1695 ["Signature" gnus-article-hide-signature t]
1696 ["Citation" gnus-article-hide-citation t]
16409b0b 1697 ["List identifiers" gnus-article-hide-list-identifiers t]
6748645f 1698 ["PGP" gnus-article-hide-pgp t]
16409b0b 1699 ["Banner" gnus-article-strip-banner t]
6748645f
LMI
1700 ["Boring headers" gnus-article-hide-boring-headers t])
1701 ("Highlight"
1702 ["All" gnus-article-highlight t]
1703 ["Headers" gnus-article-highlight-headers t]
1704 ["Signature" gnus-article-highlight-signature t]
1705 ["Citation" gnus-article-highlight-citation t])
16409b0b
GM
1706 ("MIME"
1707 ["Words" gnus-article-decode-mime-words t]
1708 ["Charset" gnus-article-decode-charset t]
1709 ["QP" gnus-article-de-quoted-unreadable t]
1710 ["Base64" gnus-article-de-base64-unreadable t]
1711 ["View all" gnus-mime-view-all-parts t])
6748645f
LMI
1712 ("Date"
1713 ["Local" gnus-article-date-local t]
1714 ["ISO8601" gnus-article-date-iso8601 t]
1715 ["UT" gnus-article-date-ut t]
1716 ["Original" gnus-article-date-original t]
1717 ["Lapsed" gnus-article-date-lapsed t]
1718 ["User-defined" gnus-article-date-user t])
1719 ("Washing"
1720 ("Remove Blanks"
1721 ["Leading" gnus-article-strip-leading-blank-lines t]
1722 ["Multiple" gnus-article-strip-multiple-blank-lines t]
1723 ["Trailing" gnus-article-remove-trailing-blank-lines t]
1724 ["All of the above" gnus-article-strip-blank-lines t]
1725 ["All" gnus-article-strip-all-blank-lines t]
16409b0b
GM
1726 ["Leading space" gnus-article-strip-leading-space t]
1727 ["Trailing space" gnus-article-strip-trailing-space t])
6748645f
LMI
1728 ["Overstrike" gnus-article-treat-overstrike t]
1729 ["Dumb quotes" gnus-article-treat-dumbquotes t]
1730 ["Emphasis" gnus-article-emphasize t]
1731 ["Word wrap" gnus-article-fill-cited-article t]
16409b0b
GM
1732 ["Fill long lines" gnus-article-fill-long-lines t]
1733 ["Capitalize sentences" gnus-article-capitalize-sentences t]
6748645f
LMI
1734 ["CR" gnus-article-remove-cr t]
1735 ["Show X-Face" gnus-article-display-x-face t]
1736 ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
16409b0b 1737 ["Base64" gnus-article-de-base64-unreadable t]
60bd5589
DL
1738 ["Rot 13" gnus-summary-caesar-message
1739 :help "\"Caesar rotate\" article by 13"]
6748645f
LMI
1740 ["Unix pipe" gnus-summary-pipe-message t]
1741 ["Add buttons" gnus-article-add-buttons t]
1742 ["Add buttons to head" gnus-article-add-buttons-to-head t]
1743 ["Stop page breaking" gnus-summary-stop-page-breaking t]
6748645f 1744 ["Verbose header" gnus-summary-verbose-headers t]
16409b0b
GM
1745 ["Toggle header" gnus-summary-toggle-header t]
1746 ["Html" gnus-article-wash-html t]
1747 ["HZ" gnus-article-decode-HZ t])
6748645f 1748 ("Output"
60bd5589
DL
1749 ["Save in default format" gnus-summary-save-article
1750 :help "Save article using default method"]
1751 ["Save in file" gnus-summary-save-article-file
1752 :help "Save article in file"]
6748645f
LMI
1753 ["Save in Unix mail format" gnus-summary-save-article-mail t]
1754 ["Save in MH folder" gnus-summary-save-article-folder t]
1755 ["Save in VM folder" gnus-summary-save-article-vm t]
1756 ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1757 ["Save body in file" gnus-summary-save-article-body-file t]
1758 ["Pipe through a filter" gnus-summary-pipe-output t]
1759 ["Add to SOUP packet" gnus-soup-add-article t]
1760 ["Print" gnus-summary-print-article t])
1761 ("Backend"
1762 ["Respool article..." gnus-summary-respool-article t]
1763 ["Move article..." gnus-summary-move-article
1764 (gnus-check-backend-function
1765 'request-move-article gnus-newsgroup-name)]
1766 ["Copy article..." gnus-summary-copy-article t]
1767 ["Crosspost article..." gnus-summary-crosspost-article
1768 (gnus-check-backend-function
1769 'request-replace-article gnus-newsgroup-name)]
1770 ["Import file..." gnus-summary-import-article t]
1771 ["Check if posted" gnus-summary-article-posted-p t]
1772 ["Edit article" gnus-summary-edit-article
1773 (not (gnus-group-read-only-p))]
1774 ["Delete article" gnus-summary-delete-article
1775 (gnus-check-backend-function
1776 'request-expire-articles gnus-newsgroup-name)]
1777 ["Query respool" gnus-summary-respool-query t]
1778 ["Trace respool" gnus-summary-respool-trace t]
1779 ["Delete expirable articles" gnus-summary-expire-articles-now
1780 (gnus-check-backend-function
1781 'request-expire-articles gnus-newsgroup-name)])
1782 ("Extract"
60bd5589
DL
1783 ["Uudecode" gnus-uu-decode-uu
1784 :help "Decode uuencoded article(s)"]
6748645f
LMI
1785 ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1786 ["Unshar" gnus-uu-decode-unshar t]
1787 ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1788 ["Save" gnus-uu-decode-save t]
1789 ["Binhex" gnus-uu-decode-binhex t]
1790 ["Postscript" gnus-uu-decode-postscript t])
1791 ("Cache"
1792 ["Enter article" gnus-cache-enter-article t]
1793 ["Remove article" gnus-cache-remove-article t])
16409b0b 1794 ["Translate" gnus-article-babel t]
6748645f
LMI
1795 ["Select article buffer" gnus-summary-select-article-buffer t]
1796 ["Enter digest buffer" gnus-summary-enter-digest-group t]
1797 ["Isearch article..." gnus-summary-isearch-article t]
1798 ["Beginning of the article" gnus-summary-beginning-of-article t]
1799 ["End of the article" gnus-summary-end-of-article t]
1800 ["Fetch parent of article" gnus-summary-refer-parent-article t]
1801 ["Fetch referenced articles" gnus-summary-refer-references t]
1802 ["Fetch current thread" gnus-summary-refer-thread t]
1803 ["Fetch article with id..." gnus-summary-refer-article t]
1804 ["Redisplay" gnus-summary-show-article t])))
1805 (easy-menu-define
1806 gnus-summary-article-menu gnus-summary-mode-map ""
1807 (cons "Article" innards))
1808
1809 (easy-menu-define
1810 gnus-article-commands-menu gnus-article-mode-map ""
1811 (cons "Commands" innards)))
eec82323
LMI
1812
1813 (easy-menu-define
1814 gnus-summary-thread-menu gnus-summary-mode-map ""
1815 '("Threads"
1816 ["Toggle threading" gnus-summary-toggle-threads t]
1817 ["Hide threads" gnus-summary-hide-all-threads t]
1818 ["Show threads" gnus-summary-show-all-threads t]
1819 ["Hide thread" gnus-summary-hide-thread t]
1820 ["Show thread" gnus-summary-show-thread t]
1821 ["Go to next thread" gnus-summary-next-thread t]
1822 ["Go to previous thread" gnus-summary-prev-thread t]
1823 ["Go down thread" gnus-summary-down-thread t]
1824 ["Go up thread" gnus-summary-up-thread t]
1825 ["Top of thread" gnus-summary-top-thread t]
1826 ["Mark thread as read" gnus-summary-kill-thread t]
1827 ["Lower thread score" gnus-summary-lower-thread t]
1828 ["Raise thread score" gnus-summary-raise-thread t]
16409b0b 1829 ["Rethread current" gnus-summary-rethread-current t]))
eec82323
LMI
1830
1831 (easy-menu-define
1832 gnus-summary-post-menu gnus-summary-mode-map ""
1833 '("Post"
60bd5589
DL
1834 ["Post an article" gnus-summary-post-news
1835 :help "Post an article"]
1836 ["Followup" gnus-summary-followup
1837 :help "Post followup to this article"]
1838 ["Followup and yank" gnus-summary-followup-with-original
1839 :help "Post followup to this article, quoting its contents"]
eec82323 1840 ["Supersede article" gnus-summary-supersede-article t]
60bd5589
DL
1841 ["Cancel article" gnus-summary-cancel-article
1842 :help "Cancel an article you posted"]
eec82323
LMI
1843 ["Reply" gnus-summary-reply t]
1844 ["Reply and yank" gnus-summary-reply-with-original t]
1845 ["Wide reply" gnus-summary-wide-reply t]
60bd5589
DL
1846 ["Wide reply and yank" gnus-summary-wide-reply-with-original
1847 :help "Mail a reply, quoting this article"]
eec82323
LMI
1848 ["Mail forward" gnus-summary-mail-forward t]
1849 ["Post forward" gnus-summary-post-forward t]
1850 ["Digest and mail" gnus-uu-digest-mail-forward t]
1851 ["Digest and post" gnus-uu-digest-post-forward t]
1852 ["Resend message" gnus-summary-resend-message t]
1853 ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1854 ["Send a mail" gnus-summary-mail-other-window t]
60bd5589
DL
1855 ["Uuencode and post" gnus-uu-post-news
1856 :help "Post a uuencoded article"]
eec82323
LMI
1857 ["Followup via news" gnus-summary-followup-to-mail t]
1858 ["Followup via news and yank"
1859 gnus-summary-followup-to-mail-with-original t]
1860 ;;("Draft"
1861 ;;["Send" gnus-summary-send-draft t]
1862 ;;["Send bounced" gnus-resend-bounced-mail t])
1863 ))
1864
1865 (easy-menu-define
1866 gnus-summary-misc-menu gnus-summary-mode-map ""
1867 '("Misc"
1868 ("Mark Read"
1869 ["Mark as read" gnus-summary-mark-as-read-forward t]
1870 ["Mark same subject and select"
1871 gnus-summary-kill-same-subject-and-select t]
1872 ["Mark same subject" gnus-summary-kill-same-subject t]
60bd5589
DL
1873 ["Catchup" gnus-summary-catchup
1874 :help "Mark unread articles in this group as read"]
eec82323
LMI
1875 ["Catchup all" gnus-summary-catchup-all t]
1876 ["Catchup to here" gnus-summary-catchup-to-here t]
1877 ["Catchup region" gnus-summary-mark-region-as-read t]
1878 ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1879 ("Mark Various"
1880 ["Tick" gnus-summary-tick-article-forward t]
1881 ["Mark as dormant" gnus-summary-mark-as-dormant t]
1882 ["Remove marks" gnus-summary-clear-mark-forward t]
1883 ["Set expirable mark" gnus-summary-mark-as-expirable t]
1884 ["Set bookmark" gnus-summary-set-bookmark t]
1885 ["Remove bookmark" gnus-summary-remove-bookmark t])
1886 ("Mark Limit"
1887 ["Marks..." gnus-summary-limit-to-marks t]
1888 ["Subject..." gnus-summary-limit-to-subject t]
1889 ["Author..." gnus-summary-limit-to-author t]
1890 ["Age..." gnus-summary-limit-to-age t]
16409b0b 1891 ["Extra..." gnus-summary-limit-to-extra t]
eec82323
LMI
1892 ["Score" gnus-summary-limit-to-score t]
1893 ["Unread" gnus-summary-limit-to-unread t]
1894 ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1895 ["Articles" gnus-summary-limit-to-articles t]
1896 ["Pop limit" gnus-summary-pop-limit t]
1897 ["Show dormant" gnus-summary-limit-include-dormant t]
1898 ["Hide childless dormant"
1899 gnus-summary-limit-exclude-childless-dormant t]
1900 ;;["Hide thread" gnus-summary-limit-exclude-thread t]
16409b0b 1901 ["Hide marked" gnus-summary-limit-exclude-marks t]
eec82323
LMI
1902 ["Show expunged" gnus-summary-show-all-expunged t])
1903 ("Process Mark"
1904 ["Set mark" gnus-summary-mark-as-processable t]
1905 ["Remove mark" gnus-summary-unmark-as-processable t]
1906 ["Remove all marks" gnus-summary-unmark-all-processable t]
1907 ["Mark above" gnus-uu-mark-over t]
1908 ["Mark series" gnus-uu-mark-series t]
1909 ["Mark region" gnus-uu-mark-region t]
6748645f 1910 ["Unmark region" gnus-uu-unmark-region t]
eec82323 1911 ["Mark by regexp..." gnus-uu-mark-by-regexp t]
6748645f 1912 ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
eec82323
LMI
1913 ["Mark all" gnus-uu-mark-all t]
1914 ["Mark buffer" gnus-uu-mark-buffer t]
1915 ["Mark sparse" gnus-uu-mark-sparse t]
1916 ["Mark thread" gnus-uu-mark-thread t]
1917 ["Unmark thread" gnus-uu-unmark-thread t]
1918 ("Process Mark Sets"
1919 ["Kill" gnus-summary-kill-process-mark t]
1920 ["Yank" gnus-summary-yank-process-mark
1921 gnus-newsgroup-process-stack]
1922 ["Save" gnus-summary-save-process-mark t]))
1923 ("Scroll article"
60bd5589
DL
1924 ["Page forward" gnus-summary-next-page
1925 :help "Show next page of article"]
1926 ["Page backward" gnus-summary-prev-page
1927 :help "Show previous page of article"]
eec82323
LMI
1928 ["Line forward" gnus-summary-scroll-up t])
1929 ("Move"
1930 ["Next unread article" gnus-summary-next-unread-article t]
1931 ["Previous unread article" gnus-summary-prev-unread-article t]
1932 ["Next article" gnus-summary-next-article t]
1933 ["Previous article" gnus-summary-prev-article t]
1934 ["Next unread subject" gnus-summary-next-unread-subject t]
1935 ["Previous unread subject" gnus-summary-prev-unread-subject t]
1936 ["Next article same subject" gnus-summary-next-same-subject t]
1937 ["Previous article same subject" gnus-summary-prev-same-subject t]
1938 ["First unread article" gnus-summary-first-unread-article t]
1939 ["Best unread article" gnus-summary-best-unread-article t]
1940 ["Go to subject number..." gnus-summary-goto-subject t]
1941 ["Go to article number..." gnus-summary-goto-article t]
1942 ["Go to the last article" gnus-summary-goto-last-article t]
1943 ["Pop article off history" gnus-summary-pop-article t])
1944 ("Sort"
1945 ["Sort by number" gnus-summary-sort-by-number t]
1946 ["Sort by author" gnus-summary-sort-by-author t]
1947 ["Sort by subject" gnus-summary-sort-by-subject t]
1948 ["Sort by date" gnus-summary-sort-by-date t]
1949 ["Sort by score" gnus-summary-sort-by-score t]
16409b0b
GM
1950 ["Sort by lines" gnus-summary-sort-by-lines t]
1951 ["Sort by characters" gnus-summary-sort-by-chars t])
eec82323
LMI
1952 ("Help"
1953 ["Fetch group FAQ" gnus-summary-fetch-faq t]
1954 ["Describe group" gnus-summary-describe-group t]
1955 ["Read manual" gnus-info-find-node t])
1956 ("Modes"
1957 ["Pick and read" gnus-pick-mode t]
1958 ["Binary" gnus-binary-mode t])
1959 ("Regeneration"
1960 ["Regenerate" gnus-summary-prepare t]
1961 ["Insert cached articles" gnus-summary-insert-cached-articles t]
1962 ["Toggle threading" gnus-summary-toggle-threads t])
1963 ["Filter articles..." gnus-summary-execute-command t]
1964 ["Run command on subjects..." gnus-summary-universal-argument t]
1965 ["Search articles forward..." gnus-summary-search-article-forward t]
1966 ["Search articles backward..." gnus-summary-search-article-backward t]
1967 ["Toggle line truncation" gnus-summary-toggle-truncation t]
1968 ["Expand window" gnus-summary-expand-window t]
1969 ["Expire expirable articles" gnus-summary-expire-articles
1970 (gnus-check-backend-function
1971 'request-expire-articles gnus-newsgroup-name)]
1972 ["Edit local kill file" gnus-summary-edit-local-kill t]
1973 ["Edit main kill file" gnus-summary-edit-global-kill t]
6748645f 1974 ["Edit group parameters" gnus-summary-edit-parameters t]
16409b0b 1975 ["Customize group parameters" gnus-summary-customize-parameters t]
6748645f 1976 ["Send a bug report" gnus-bug t]
eec82323 1977 ("Exit"
60bd5589
DL
1978 ["Catchup and exit" gnus-summary-catchup-and-exit
1979 :help "Mark unread articles in this group as read, then exit"]
6748645f 1980 ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
eec82323 1981 ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
60bd5589
DL
1982 ["Exit group" gnus-summary-exit
1983 :help "Exit current group, return to group selection mode"]
eec82323
LMI
1984 ["Exit group without updating" gnus-summary-exit-no-update t]
1985 ["Exit and goto next group" gnus-summary-next-group t]
1986 ["Exit and goto prev group" gnus-summary-prev-group t]
1987 ["Reselect group" gnus-summary-reselect-current-group t]
1988 ["Rescan group" gnus-summary-rescan-group t]
1989 ["Update dribble" gnus-summary-save-newsrc t])))
1990
6748645f 1991 (gnus-run-hooks 'gnus-summary-menu-hook)))
eec82323 1992
60bd5589
DL
1993(defvar gnus-summary-tool-bar-map nil)
1994
9a0026a6 1995;; Emacs 21 tool bar. Should be no-op otherwise.
60bd5589
DL
1996(defun gnus-summary-make-tool-bar ()
1997 (if (and (fboundp 'tool-bar-add-item-from-menu)
1998 (default-value 'tool-bar-mode)
1999 (not gnus-summary-tool-bar-map))
2000 (setq gnus-summary-tool-bar-map
2001 (let ((tool-bar-map (make-sparse-keymap)))
2002 (tool-bar-add-item-from-menu
2003 'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2004 (tool-bar-add-item-from-menu
2005 'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2006 (tool-bar-add-item-from-menu
2007 'gnus-summary-post-news "post" gnus-summary-mode-map)
2008 (tool-bar-add-item-from-menu
2009 'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2010 (tool-bar-add-item-from-menu
2011 'gnus-summary-followup "followup" gnus-summary-mode-map)
2012 (tool-bar-add-item-from-menu
2013 'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2014 (tool-bar-add-item-from-menu
2015 'gnus-summary-reply "reply" gnus-summary-mode-map)
2016 (tool-bar-add-item-from-menu
2017 'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2018 (tool-bar-add-item-from-menu
2019 'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2020 (tool-bar-add-item-from-menu
2021 'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2022 (tool-bar-add-item-from-menu
2023 'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2024 (tool-bar-add-item-from-menu
2025 'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2026 (tool-bar-add-item-from-menu
2027 'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2028 (tool-bar-add-item-from-menu
2029 'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2030 (tool-bar-add-item-from-menu
2031 'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2032 tool-bar-map)))
2033 (if gnus-summary-tool-bar-map
2034 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2035
eec82323
LMI
2036(defun gnus-score-set-default (var value)
2037 "A version of set that updates the GNU Emacs menu-bar."
2038 (set var value)
2039 ;; It is the message that forces the active status to be updated.
2040 (message ""))
2041
2042(defun gnus-make-score-map (type)
2043 "Make a summary score map of type TYPE."
2044 (if t
2045 nil
2046 (let ((headers '(("author" "from" string)
2047 ("subject" "subject" string)
2048 ("article body" "body" string)
2049 ("article head" "head" string)
2050 ("xref" "xref" string)
16409b0b 2051 ("extra header" "extra" string)
eec82323
LMI
2052 ("lines" "lines" number)
2053 ("followups to author" "followup" string)))
2054 (types '((number ("less than" <)
2055 ("greater than" >)
2056 ("equal" =))
2057 (string ("substring" s)
2058 ("exact string" e)
2059 ("fuzzy string" f)
2060 ("regexp" r))))
2061 (perms '(("temporary" (current-time-string))
2062 ("permanent" nil)
2063 ("immediate" now)))
2064 header)
2065 (list
2066 (apply
2067 'nconc
2068 (list
2069 (if (eq type 'lower)
2070 "Lower score"
2071 "Increase score"))
2072 (let (outh)
2073 (while headers
2074 (setq header (car headers))
2075 (setq outh
2076 (cons
2077 (apply
2078 'nconc
2079 (list (car header))
2080 (let ((ts (cdr (assoc (nth 2 header) types)))
2081 outt)
2082 (while ts
2083 (setq outt
2084 (cons
2085 (apply
2086 'nconc
2087 (list (caar ts))
2088 (let ((ps perms)
2089 outp)
2090 (while ps
2091 (setq outp
2092 (cons
2093 (vector
2094 (caar ps)
2095 (list
2096 'gnus-summary-score-entry
2097 (nth 1 header)
2098 (if (or (string= (nth 1 header)
2099 "head")
2100 (string= (nth 1 header)
2101 "body"))
2102 ""
2103 (list 'gnus-summary-header
2104 (nth 1 header)))
2105 (list 'quote (nth 1 (car ts)))
16409b0b
GM
2106 (list 'gnus-score-delta-default
2107 nil)
eec82323
LMI
2108 (nth 1 (car ps))
2109 t)
2110 t)
2111 outp))
2112 (setq ps (cdr ps)))
2113 (list (nreverse outp))))
2114 outt))
2115 (setq ts (cdr ts)))
2116 (list (nreverse outt))))
2117 outh))
2118 (setq headers (cdr headers)))
2119 (list (nreverse outh))))))))
2120
2121\f
2122
2123(defun gnus-summary-mode (&optional group)
2124 "Major mode for reading articles.
2125
2126All normal editing commands are switched off.
2127\\<gnus-summary-mode-map>
2128Each line in this buffer represents one article. To read an
2129article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
2130and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2131respectively.
2132
2133You can also post articles and send mail from this buffer. To
2134follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
2135of an article, type `\\[gnus-summary-reply]'.
2136
2137There are approx. one gazillion commands you can execute in this
2138buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2139
2140The following commands are available:
2141
2142\\{gnus-summary-mode-map}"
2143 (interactive)
eec82323 2144 (kill-all-local-variables)
60bd5589
DL
2145 (when (gnus-visual-p 'summary-menu 'menu)
2146 (gnus-summary-make-menu-bar)
2147 (gnus-summary-make-tool-bar))
eec82323
LMI
2148 (gnus-summary-make-local-variables)
2149 (gnus-make-thread-indent-array)
2150 (gnus-simplify-mode-line)
2151 (setq major-mode 'gnus-summary-mode)
2152 (setq mode-name "Summary")
2153 (make-local-variable 'minor-mode-alist)
2154 (use-local-map gnus-summary-mode-map)
16409b0b 2155 (buffer-disable-undo)
eec82323
LMI
2156 (setq buffer-read-only t) ;Disable modification
2157 (setq truncate-lines t)
2158 (setq selective-display t)
2159 (setq selective-display-ellipses t) ;Display `...'
2160 (gnus-summary-set-display-table)
2161 (gnus-set-default-directory)
2162 (setq gnus-newsgroup-name group)
2163 (make-local-variable 'gnus-summary-line-format)
2164 (make-local-variable 'gnus-summary-line-format-spec)
6748645f
LMI
2165 (make-local-variable 'gnus-summary-dummy-line-format)
2166 (make-local-variable 'gnus-summary-dummy-line-format-spec)
eec82323 2167 (make-local-variable 'gnus-summary-mark-positions)
6748645f
LMI
2168 (make-local-hook 'pre-command-hook)
2169 (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2170 (gnus-run-hooks 'gnus-summary-mode-hook)
d4dfaa19 2171 (mm-enable-multibyte-mule4)
eec82323
LMI
2172 (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2173 (gnus-update-summary-mark-positions))
2174
2175(defun gnus-summary-make-local-variables ()
2176 "Make all the local summary buffer variables."
16409b0b
GM
2177 (let (global)
2178 (dolist (local gnus-summary-local-variables)
eec82323
LMI
2179 (if (consp local)
2180 (progn
2181 (if (eq (cdr local) 'global)
2182 ;; Copy the global value of the variable.
2183 (setq global (symbol-value (car local)))
2184 ;; Use the value from the list.
2185 (setq global (eval (cdr local))))
16409b0b 2186 (set (make-local-variable (car local)) global))
eec82323 2187 ;; Simple nil-valued local variable.
16409b0b 2188 (set (make-local-variable local) nil)))))
eec82323
LMI
2189
2190(defun gnus-summary-clear-local-variables ()
2191 (let ((locals gnus-summary-local-variables))
2192 (while locals
2193 (if (consp (car locals))
2194 (and (vectorp (caar locals))
2195 (set (caar locals) nil))
2196 (and (vectorp (car locals))
2197 (set (car locals) nil)))
2198 (setq locals (cdr locals)))))
2199
2200;; Summary data functions.
2201
2202(defmacro gnus-data-number (data)
2203 `(car ,data))
2204
2205(defmacro gnus-data-set-number (data number)
2206 `(setcar ,data ,number))
2207
2208(defmacro gnus-data-mark (data)
2209 `(nth 1 ,data))
2210
2211(defmacro gnus-data-set-mark (data mark)
2212 `(setcar (nthcdr 1 ,data) ,mark))
2213
2214(defmacro gnus-data-pos (data)
2215 `(nth 2 ,data))
2216
2217(defmacro gnus-data-set-pos (data pos)
2218 `(setcar (nthcdr 2 ,data) ,pos))
2219
2220(defmacro gnus-data-header (data)
2221 `(nth 3 ,data))
2222
2223(defmacro gnus-data-set-header (data header)
2224 `(setf (nth 3 ,data) ,header))
2225
2226(defmacro gnus-data-level (data)
2227 `(nth 4 ,data))
2228
2229(defmacro gnus-data-unread-p (data)
2230 `(= (nth 1 ,data) gnus-unread-mark))
2231
2232(defmacro gnus-data-read-p (data)
2233 `(/= (nth 1 ,data) gnus-unread-mark))
2234
2235(defmacro gnus-data-pseudo-p (data)
2236 `(consp (nth 3 ,data)))
2237
2238(defmacro gnus-data-find (number)
2239 `(assq ,number gnus-newsgroup-data))
2240
2241(defmacro gnus-data-find-list (number &optional data)
2242 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2243 (memq (assq ,number bdata)
2244 bdata)))
2245
2246(defmacro gnus-data-make (number mark pos header level)
2247 `(list ,number ,mark ,pos ,header ,level))
2248
2249(defun gnus-data-enter (after-article number mark pos header level offset)
2250 (let ((data (gnus-data-find-list after-article)))
2251 (unless data
2252 (error "No such article: %d" after-article))
2253 (setcdr data (cons (gnus-data-make number mark pos header level)
2254 (cdr data)))
2255 (setq gnus-newsgroup-data-reverse nil)
2256 (gnus-data-update-list (cddr data) offset)))
2257
2258(defun gnus-data-enter-list (after-article list &optional offset)
2259 (when list
2260 (let ((data (and after-article (gnus-data-find-list after-article)))
2261 (ilist list))
6748645f
LMI
2262 (if (not (or data
2263 after-article))
2264 (let ((odata gnus-newsgroup-data))
2265 (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
eec82323 2266 (when offset
6748645f
LMI
2267 (gnus-data-update-list odata offset)))
2268 ;; Find the last element in the list to be spliced into the main
2269 ;; list.
2270 (while (cdr list)
2271 (setq list (cdr list)))
2272 (if (not data)
2273 (progn
2274 (setcdr list gnus-newsgroup-data)
2275 (setq gnus-newsgroup-data ilist)
2276 (when offset
2277 (gnus-data-update-list (cdr list) offset)))
2278 (setcdr list (cdr data))
2279 (setcdr data ilist)
2280 (when offset
2281 (gnus-data-update-list (cdr list) offset))))
eec82323
LMI
2282 (setq gnus-newsgroup-data-reverse nil))))
2283
2284(defun gnus-data-remove (article &optional offset)
2285 (let ((data gnus-newsgroup-data))
2286 (if (= (gnus-data-number (car data)) article)
2287 (progn
2288 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2289 gnus-newsgroup-data-reverse nil)
2290 (when offset
2291 (gnus-data-update-list gnus-newsgroup-data offset)))
2292 (while (cdr data)
2293 (when (= (gnus-data-number (cadr data)) article)
2294 (setcdr data (cddr data))
2295 (when offset
2296 (gnus-data-update-list (cdr data) offset))
2297 (setq data nil
2298 gnus-newsgroup-data-reverse nil))
2299 (setq data (cdr data))))))
2300
2301(defmacro gnus-data-list (backward)
2302 `(if ,backward
2303 (or gnus-newsgroup-data-reverse
2304 (setq gnus-newsgroup-data-reverse
2305 (reverse gnus-newsgroup-data)))
2306 gnus-newsgroup-data))
2307
2308(defun gnus-data-update-list (data offset)
2309 "Add OFFSET to the POS of all data entries in DATA."
6748645f 2310 (setq gnus-newsgroup-data-reverse nil)
eec82323
LMI
2311 (while data
2312 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2313 (setq data (cdr data))))
2314
eec82323
LMI
2315(defun gnus-summary-article-pseudo-p (article)
2316 "Say whether this article is a pseudo article or not."
2317 (not (vectorp (gnus-data-header (gnus-data-find article)))))
2318
2319(defmacro gnus-summary-article-sparse-p (article)
2320 "Say whether this article is a sparse article or not."
a8151ef7 2321 `(memq ,article gnus-newsgroup-sparse))
eec82323
LMI
2322
2323(defmacro gnus-summary-article-ancient-p (article)
2324 "Say whether this article is a sparse article or not."
2325 `(memq ,article gnus-newsgroup-ancient))
2326
2327(defun gnus-article-parent-p (number)
2328 "Say whether this article is a parent or not."
2329 (let ((data (gnus-data-find-list number)))
2330 (and (cdr data) ; There has to be an article after...
2331 (< (gnus-data-level (car data)) ; And it has to have a higher level.
2332 (gnus-data-level (nth 1 data))))))
2333
2334(defun gnus-article-children (number)
2335 "Return a list of all children to NUMBER."
2336 (let* ((data (gnus-data-find-list number))
2337 (level (gnus-data-level (car data)))
2338 children)
2339 (setq data (cdr data))
2340 (while (and data
2341 (= (gnus-data-level (car data)) (1+ level)))
2342 (push (gnus-data-number (car data)) children)
2343 (setq data (cdr data)))
2344 children))
2345
2346(defmacro gnus-summary-skip-intangible ()
2347 "If the current article is intangible, then jump to a different article."
2348 '(let ((to (get-text-property (point) 'gnus-intangible)))
2349 (and to (gnus-summary-goto-subject to))))
2350
2351(defmacro gnus-summary-article-intangible-p ()
2352 "Say whether this article is intangible or not."
2353 '(get-text-property (point) 'gnus-intangible))
2354
2355(defun gnus-article-read-p (article)
2356 "Say whether ARTICLE is read or not."
2357 (not (or (memq article gnus-newsgroup-marked)
2358 (memq article gnus-newsgroup-unreads)
2359 (memq article gnus-newsgroup-unselected)
2360 (memq article gnus-newsgroup-dormant))))
2361
2362;; Some summary mode macros.
2363
2364(defmacro gnus-summary-article-number ()
2365 "The article number of the article on the current line.
2366If there isn's an article number here, then we return the current
2367article number."
2368 '(progn
2369 (gnus-summary-skip-intangible)
2370 (or (get-text-property (point) 'gnus-number)
2371 (gnus-summary-last-subject))))
2372
2373(defmacro gnus-summary-article-header (&optional number)
6748645f 2374 "Return the header of article NUMBER."
eec82323
LMI
2375 `(gnus-data-header (gnus-data-find
2376 ,(or number '(gnus-summary-article-number)))))
2377
2378(defmacro gnus-summary-thread-level (&optional number)
6748645f 2379 "Return the level of thread that starts with article NUMBER."
eec82323
LMI
2380 `(if (and (eq gnus-summary-make-false-root 'dummy)
2381 (get-text-property (point) 'gnus-intangible))
2382 0
2383 (gnus-data-level (gnus-data-find
2384 ,(or number '(gnus-summary-article-number))))))
2385
2386(defmacro gnus-summary-article-mark (&optional number)
6748645f 2387 "Return the mark of article NUMBER."
eec82323
LMI
2388 `(gnus-data-mark (gnus-data-find
2389 ,(or number '(gnus-summary-article-number)))))
2390
2391(defmacro gnus-summary-article-pos (&optional number)
6748645f 2392 "Return the position of the line of article NUMBER."
eec82323
LMI
2393 `(gnus-data-pos (gnus-data-find
2394 ,(or number '(gnus-summary-article-number)))))
2395
2396(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2397(defmacro gnus-summary-article-subject (&optional number)
2398 "Return current subject string or nil if nothing."
2399 `(let ((headers
2400 ,(if number
2401 `(gnus-data-header (assq ,number gnus-newsgroup-data))
2402 '(gnus-data-header (assq (gnus-summary-article-number)
2403 gnus-newsgroup-data)))))
2404 (and headers
2405 (vectorp headers)
2406 (mail-header-subject headers))))
2407
2408(defmacro gnus-summary-article-score (&optional number)
2409 "Return current article score."
2410 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2411 gnus-newsgroup-scored))
2412 gnus-summary-default-score 0))
2413
2414(defun gnus-summary-article-children (&optional number)
6748645f 2415 "Return a list of article numbers that are children of article NUMBER."
eec82323
LMI
2416 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2417 (level (gnus-data-level (car data)))
2418 l children)
2419 (while (and (setq data (cdr data))
2420 (> (setq l (gnus-data-level (car data))) level))
2421 (and (= (1+ level) l)
2422 (push (gnus-data-number (car data))
2423 children)))
2424 (nreverse children)))
2425
2426(defun gnus-summary-article-parent (&optional number)
6748645f 2427 "Return the article number of the parent of article NUMBER."
eec82323
LMI
2428 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2429 (gnus-data-list t)))
2430 (level (gnus-data-level (car data))))
2431 (if (zerop level)
2432 () ; This is a root.
2433 ;; We search until we find an article with a level less than
2434 ;; this one. That function has to be the parent.
2435 (while (and (setq data (cdr data))
2436 (not (< (gnus-data-level (car data)) level))))
2437 (and data (gnus-data-number (car data))))))
2438
2439(defun gnus-unread-mark-p (mark)
2440 "Say whether MARK is the unread mark."
2441 (= mark gnus-unread-mark))
2442
2443(defun gnus-read-mark-p (mark)
2444 "Say whether MARK is one of the marks that mark as read.
2445This is all marks except unread, ticked, dormant, and expirable."
2446 (not (or (= mark gnus-unread-mark)
2447 (= mark gnus-ticked-mark)
2448 (= mark gnus-dormant-mark)
2449 (= mark gnus-expirable-mark))))
2450
2451(defmacro gnus-article-mark (number)
6748645f
LMI
2452 "Return the MARK of article NUMBER.
2453This macro should only be used when computing the mark the \"first\"
2454time; i.e., when generating the summary lines. After that,
2455`gnus-summary-article-mark' should be used to examine the
2456marks of articles."
eec82323 2457 `(cond
6748645f
LMI
2458 ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2459 ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2460 ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
eec82323
LMI
2461 ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2462 ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2463 ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2464 ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2465 (t (or (cdr (assq ,number gnus-newsgroup-reads))
2466 gnus-ancient-mark))))
2467
2468;; Saving hidden threads.
2469
2470(put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2471(put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2472
2473(defmacro gnus-save-hidden-threads (&rest forms)
2474 "Save hidden threads, eval FORMS, and restore the hidden threads."
2475 (let ((config (make-symbol "config")))
2476 `(let ((,config (gnus-hidden-threads-configuration)))
2477 (unwind-protect
2478 (save-excursion
2479 ,@forms)
2480 (gnus-restore-hidden-threads-configuration ,config)))))
2481
107ecebb
AS
2482(defun gnus-data-compute-positions ()
2483 "Compute the positions of all articles."
2484 (setq gnus-newsgroup-data-reverse nil)
2485 (let ((data gnus-newsgroup-data))
2486 (save-excursion
2487 (gnus-save-hidden-threads
2488 (gnus-summary-show-all-threads)
2489 (goto-char (point-min))
2490 (while data
2491 (while (get-text-property (point) 'gnus-intangible)
2492 (forward-line 1))
2493 (gnus-data-set-pos (car data) (+ (point) 3))
2494 (setq data (cdr data))
2495 (forward-line 1))))))
2496
16409b0b
GM
2497(defun gnus-hidden-threads-configuration ()
2498 "Return the current hidden threads configuration."
2499 (save-excursion
2500 (let (config)
2501 (goto-char (point-min))
2502 (while (search-forward "\r" nil t)
2503 (push (1- (point)) config))
2504 config)))
2505
2506(defun gnus-restore-hidden-threads-configuration (config)
2507 "Restore hidden threads configuration from CONFIG."
2508 (save-excursion
2509 (let (point buffer-read-only)
2510 (while (setq point (pop config))
2511 (when (and (< point (point-max))
2512 (goto-char point)
2513 (eq (char-after) ?\n))
2514 (subst-char-in-region point (1+ point) ?\n ?\r))))))
2515
eec82323
LMI
2516;; Various summary mode internalish functions.
2517
2518(defun gnus-mouse-pick-article (e)
2519 (interactive "e")
2520 (mouse-set-point e)
2521 (gnus-summary-next-page nil t))
2522
2523(defun gnus-summary-set-display-table ()
16409b0b
GM
2524 "Change the display table.
2525Odd characters have a tendency to mess
2526up nicely formatted displays - we make all possible glyphs
2527display only a single character."
eec82323
LMI
2528
2529 ;; We start from the standard display table, if any.
2530 (let ((table (or (copy-sequence standard-display-table)
2531 (make-display-table)))
2532 (i 32))
2533 ;; Nix out all the control chars...
2534 (while (>= (setq i (1- i)) 0)
2535 (aset table i [??]))
2536 ;; ... but not newline and cr, of course. (cr is necessary for the
2537 ;; selective display).
2538 (aset table ?\n nil)
2539 (aset table ?\r nil)
6748645f
LMI
2540 ;; We keep TAB as well.
2541 (aset table ?\t nil)
eec82323
LMI
2542 ;; We nix out any glyphs over 126 that are not set already.
2543 (let ((i 256))
2544 (while (>= (setq i (1- i)) 127)
2545 ;; Only modify if the entry is nil.
2546 (unless (aref table i)
2547 (aset table i [??]))))
2548 (setq buffer-display-table table)))
2549
2550(defun gnus-summary-setup-buffer (group)
2551 "Initialize summary buffer."
2552 (let ((buffer (concat "*Summary " group "*")))
2553 (if (get-buffer buffer)
2554 (progn
2555 (set-buffer buffer)
2556 (setq gnus-summary-buffer (current-buffer))
2557 (not gnus-newsgroup-prepared))
2558 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6748645f 2559 (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
eec82323
LMI
2560 (gnus-summary-mode group)
2561 (when gnus-carpal
2562 (gnus-carpal-setup-buffer 'summary))
2563 (unless gnus-single-article-buffer
2564 (make-local-variable 'gnus-article-buffer)
2565 (make-local-variable 'gnus-article-current)
2566 (make-local-variable 'gnus-original-article-buffer))
2567 (setq gnus-newsgroup-name group)
2568 t)))
2569
2570(defun gnus-set-global-variables ()
16409b0b
GM
2571 "Set the global equivalents of the buffer-local variables.
2572They are set to the latest values they had. These reflect the summary
2573buffer that was in action when the last article was fetched."
eec82323
LMI
2574 (when (eq major-mode 'gnus-summary-mode)
2575 (setq gnus-summary-buffer (current-buffer))
2576 (let ((name gnus-newsgroup-name)
2577 (marked gnus-newsgroup-marked)
2578 (unread gnus-newsgroup-unreads)
2579 (headers gnus-current-headers)
2580 (data gnus-newsgroup-data)
2581 (summary gnus-summary-buffer)
2582 (article-buffer gnus-article-buffer)
2583 (original gnus-original-article-buffer)
2584 (gac gnus-article-current)
2585 (reffed gnus-reffed-article-number)
16409b0b
GM
2586 (score-file gnus-current-score-file)
2587 (default-charset gnus-newsgroup-charset))
eec82323
LMI
2588 (save-excursion
2589 (set-buffer gnus-group-buffer)
6748645f
LMI
2590 (setq gnus-newsgroup-name name
2591 gnus-newsgroup-marked marked
2592 gnus-newsgroup-unreads unread
2593 gnus-current-headers headers
2594 gnus-newsgroup-data data
2595 gnus-article-current gac
2596 gnus-summary-buffer summary
2597 gnus-article-buffer article-buffer
2598 gnus-original-article-buffer original
2599 gnus-reffed-article-number reffed
16409b0b
GM
2600 gnus-current-score-file score-file
2601 gnus-newsgroup-charset default-charset)
eec82323
LMI
2602 ;; The article buffer also has local variables.
2603 (when (gnus-buffer-live-p gnus-article-buffer)
2604 (set-buffer gnus-article-buffer)
2605 (setq gnus-summary-buffer summary))))))
2606
2607(defun gnus-summary-article-unread-p (article)
2608 "Say whether ARTICLE is unread or not."
2609 (memq article gnus-newsgroup-unreads))
2610
2611(defun gnus-summary-first-article-p (&optional article)
2612 "Return whether ARTICLE is the first article in the buffer."
2613 (if (not (setq article (or article (gnus-summary-article-number))))
2614 nil
2615 (eq article (caar gnus-newsgroup-data))))
2616
2617(defun gnus-summary-last-article-p (&optional article)
2618 "Return whether ARTICLE is the last article in the buffer."
2619 (if (not (setq article (or article (gnus-summary-article-number))))
16409b0b
GM
2620 ;; All non-existent numbers are the last article. :-)
2621 t
eec82323
LMI
2622 (not (cdr (gnus-data-find-list article)))))
2623
2624(defun gnus-make-thread-indent-array ()
2625 (let ((n 200))
2626 (unless (and gnus-thread-indent-array
2627 (= gnus-thread-indent-level gnus-thread-indent-array-level))
2628 (setq gnus-thread-indent-array (make-vector 201 "")
2629 gnus-thread-indent-array-level gnus-thread-indent-level)
2630 (while (>= n 0)
2631 (aset gnus-thread-indent-array n
2632 (make-string (* n gnus-thread-indent-level) ? ))
2633 (setq n (1- n))))))
2634
2635(defun gnus-update-summary-mark-positions ()
2636 "Compute where the summary marks are to go."
2637 (save-excursion
6748645f 2638 (when (gnus-buffer-exists-p gnus-summary-buffer)
eec82323
LMI
2639 (set-buffer gnus-summary-buffer))
2640 (let ((gnus-replied-mark 129)
2641 (gnus-score-below-mark 130)
2642 (gnus-score-over-mark 130)
6748645f 2643 (gnus-download-mark 131)
eec82323 2644 (spec gnus-summary-line-format-spec)
6748645f 2645 gnus-visual pos)
eec82323
LMI
2646 (save-excursion
2647 (gnus-set-work-buffer)
6748645f
LMI
2648 (let ((gnus-summary-line-format-spec spec)
2649 (gnus-newsgroup-downloadable '((0 . t))))
eec82323 2650 (gnus-summary-insert-line
16409b0b 2651 [0 "" "" "" "" "" 0 0 "" nil] 0 nil 128 t nil "" nil 1)
eec82323
LMI
2652 (goto-char (point-min))
2653 (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2654 (- (point) 2)))))
2655 (goto-char (point-min))
2656 (push (cons 'replied (and (search-forward "\201" nil t)
2657 (- (point) 2)))
2658 pos)
2659 (goto-char (point-min))
2660 (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
6748645f
LMI
2661 pos)
2662 (goto-char (point-min))
2663 (push (cons 'download
2664 (and (search-forward "\203" nil t) (- (point) 2)))
eec82323
LMI
2665 pos)))
2666 (setq gnus-summary-mark-positions pos))))
2667
2668(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2669 "Insert a dummy root in the summary buffer."
2670 (beginning-of-line)
2671 (gnus-add-text-properties
2672 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2673 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2674
16409b0b
GM
2675(defun gnus-summary-from-or-to-or-newsgroups (header)
2676 (let ((to (cdr (assq 'To (mail-header-extra header))))
2677 (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2678 (mail-parse-charset gnus-newsgroup-charset)
2679 (mail-parse-ignored-charsets
2680 (save-excursion (set-buffer gnus-summary-buffer)
2681 gnus-newsgroup-ignored-charsets)))
2682 (cond
2683 ((and to
2684 gnus-ignored-from-addresses
2685 (string-match gnus-ignored-from-addresses
2686 (mail-header-from header)))
2687 (concat "-> "
2688 (or (car (funcall gnus-extract-address-components
2689 (funcall
2690 gnus-decode-encoded-word-function to)))
2691 (funcall gnus-decode-encoded-word-function to))))
2692 ((and newsgroups
2693 gnus-ignored-from-addresses
2694 (string-match gnus-ignored-from-addresses
2695 (mail-header-from header)))
2696 (concat "=> " newsgroups))
2697 (t
2698 (or (car (funcall gnus-extract-address-components
2699 (mail-header-from header)))
2700 (mail-header-from header))))))
2701
eec82323
LMI
2702(defun gnus-summary-insert-line (gnus-tmp-header
2703 gnus-tmp-level gnus-tmp-current
2704 gnus-tmp-unread gnus-tmp-replied
2705 gnus-tmp-expirable gnus-tmp-subject-or-nil
2706 &optional gnus-tmp-dummy gnus-tmp-score
2707 gnus-tmp-process)
2708 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2709 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2710 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2711 (gnus-tmp-score-char
2712 (if (or (null gnus-summary-default-score)
2713 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2714 gnus-summary-zcore-fuzz))
16409b0b 2715 ? ;Whitespace
eec82323
LMI
2716 (if (< gnus-tmp-score gnus-summary-default-score)
2717 gnus-score-below-mark gnus-score-over-mark)))
2718 (gnus-tmp-replied
2719 (cond (gnus-tmp-process gnus-process-mark)
2720 ((memq gnus-tmp-current gnus-newsgroup-cached)
2721 gnus-cached-mark)
2722 (gnus-tmp-replied gnus-replied-mark)
2723 ((memq gnus-tmp-current gnus-newsgroup-saved)
2724 gnus-saved-mark)
2725 (t gnus-unread-mark)))
2726 (gnus-tmp-from (mail-header-from gnus-tmp-header))
2727 (gnus-tmp-name
2728 (cond
2729 ((string-match "<[^>]+> *$" gnus-tmp-from)
2730 (let ((beg (match-beginning 0)))
2731 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
2732 (substring gnus-tmp-from (1+ (match-beginning 0))
2733 (1- (match-end 0))))
2734 (substring gnus-tmp-from 0 beg))))
2735 ((string-match "(.+)" gnus-tmp-from)
2736 (substring gnus-tmp-from
2737 (1+ (match-beginning 0)) (1- (match-end 0))))
2738 (t gnus-tmp-from)))
2739 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2740 (gnus-tmp-number (mail-header-number gnus-tmp-header))
2741 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2742 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2743 (buffer-read-only nil))
2744 (when (string= gnus-tmp-name "")
2745 (setq gnus-tmp-name gnus-tmp-from))
2746 (unless (numberp gnus-tmp-lines)
2747 (setq gnus-tmp-lines 0))
16409b0b 2748 (gnus-put-text-property
eec82323
LMI
2749 (point)
2750 (progn (eval gnus-summary-line-format-spec) (point))
2751 'gnus-number gnus-tmp-number)
2752 (when (gnus-visual-p 'summary-highlight 'highlight)
2753 (forward-line -1)
6748645f 2754 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
2755 (forward-line 1))))
2756
2757(defun gnus-summary-update-line (&optional dont-update)
16409b0b 2758 "Update summary line after change."
eec82323
LMI
2759 (when (and gnus-summary-default-score
2760 (not gnus-summary-inhibit-highlight))
2761 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2762 (article (gnus-summary-article-number))
2763 (score (gnus-summary-article-score article)))
2764 (unless dont-update
2765 (if (and gnus-summary-mark-below
2766 (< (gnus-summary-article-score)
2767 gnus-summary-mark-below))
2768 ;; This article has a low score, so we mark it as read.
2769 (when (memq article gnus-newsgroup-unreads)
2770 (gnus-summary-mark-article-as-read gnus-low-score-mark))
2771 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2772 ;; This article was previously marked as read on account
2773 ;; of a low score, but now it has risen, so we mark it as
2774 ;; unread.
2775 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2776 (gnus-summary-update-mark
2777 (if (or (null gnus-summary-default-score)
2778 (<= (abs (- score gnus-summary-default-score))
2779 gnus-summary-zcore-fuzz))
16409b0b 2780 ? ;Whitespace
eec82323
LMI
2781 (if (< score gnus-summary-default-score)
2782 gnus-score-below-mark gnus-score-over-mark))
2783 'score))
2784 ;; Do visual highlighting.
2785 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 2786 (gnus-run-hooks 'gnus-summary-update-hook)))))
eec82323
LMI
2787
2788(defvar gnus-tmp-new-adopts nil)
2789
2790(defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2791 "Return the number of articles in THREAD.
2792This may be 0 in some cases -- if none of the articles in
2793the thread are to be displayed."
2794 (let* ((number
2795 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2796 (cond
2797 ((not (listp thread))
2798 1)
2799 ((and (consp thread) (cdr thread))
2800 (apply
2801 '+ 1 (mapcar
2802 'gnus-summary-number-of-articles-in-thread (cdr thread))))
2803 ((null thread)
2804 1)
2805 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2806 1)
2807 (t 0))))
2808 (when (and level (zerop level) gnus-tmp-new-adopts)
2809 (incf number
2810 (apply '+ (mapcar
2811 'gnus-summary-number-of-articles-in-thread
2812 gnus-tmp-new-adopts))))
2813 (if char
2814 (if (> number 1) gnus-not-empty-thread-mark
2815 gnus-empty-thread-mark)
2816 number)))
2817
2818(defun gnus-summary-set-local-parameters (group)
2819 "Go through the local params of GROUP and set all variable specs in that list."
2820 (let ((params (gnus-group-find-parameter group))
2821 elem)
2822 (while params
2823 (setq elem (car params)
2824 params (cdr params))
2825 (and (consp elem) ; Has to be a cons.
2826 (consp (cdr elem)) ; The cdr has to be a list.
2827 (symbolp (car elem)) ; Has to be a symbol in there.
6748645f 2828 (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
eec82323
LMI
2829 (ignore-errors ; So we set it.
2830 (make-local-variable (car elem))
2831 (set (car elem) (eval (nth 1 elem))))))))
2832
2833(defun gnus-summary-read-group (group &optional show-all no-article
6748645f
LMI
2834 kill-buffer no-display backward
2835 select-articles)
eec82323
LMI
2836 "Start reading news in newsgroup GROUP.
2837If SHOW-ALL is non-nil, already read articles are also listed.
2838If NO-ARTICLE is non-nil, no article is selected initially.
2839If NO-DISPLAY, don't generate a summary buffer."
2840 (let (result)
2841 (while (and group
2842 (null (setq result
2843 (let ((gnus-auto-select-next nil))
6748645f
LMI
2844 (or (gnus-summary-read-group-1
2845 group show-all no-article
2846 kill-buffer no-display
2847 select-articles)
2848 (setq show-all nil
16409b0b 2849 select-articles nil)))))
eec82323
LMI
2850 (eq gnus-auto-select-next 'quietly))
2851 (set-buffer gnus-group-buffer)
6748645f
LMI
2852 ;; The entry function called above goes to the next
2853 ;; group automatically, so we go two groups back
2854 ;; if we are searching for the previous group.
2855 (when backward
2856 (gnus-group-prev-unread-group 2))
eec82323
LMI
2857 (if (not (equal group (gnus-group-group-name)))
2858 (setq group (gnus-group-group-name))
2859 (setq group nil)))
2860 result))
2861
2862(defun gnus-summary-read-group-1 (group show-all no-article
6748645f
LMI
2863 kill-buffer no-display
2864 &optional select-articles)
eec82323
LMI
2865 ;; Killed foreign groups can't be entered.
2866 (when (and (not (gnus-group-native-p group))
2867 (not (gnus-gethash group gnus-newsrc-hashtb)))
2868 (error "Dead non-native groups can't be entered"))
2869 (gnus-message 5 "Retrieving newsgroup: %s..." group)
2870 (let* ((new-group (gnus-summary-setup-buffer group))
2871 (quit-config (gnus-group-quit-config group))
6748645f
LMI
2872 (did-select (and new-group (gnus-select-newsgroup
2873 group show-all select-articles))))
eec82323
LMI
2874 (cond
2875 ;; This summary buffer exists already, so we just select it.
2876 ((not new-group)
2877 (gnus-set-global-variables)
2878 (when kill-buffer
2879 (gnus-kill-or-deaden-summary kill-buffer))
2880 (gnus-configure-windows 'summary 'force)
2881 (gnus-set-mode-line 'summary)
2882 (gnus-summary-position-point)
2883 (message "")
2884 t)
2885 ;; We couldn't select this group.
2886 ((null did-select)
2887 (when (and (eq major-mode 'gnus-summary-mode)
2888 (not (equal (current-buffer) kill-buffer)))
2889 (kill-buffer (current-buffer))
2890 (if (not quit-config)
2891 (progn
6748645f
LMI
2892 ;; Update the info -- marks might need to be removed,
2893 ;; for instance.
2894 (gnus-summary-update-info)
eec82323
LMI
2895 (set-buffer gnus-group-buffer)
2896 (gnus-group-jump-to-group group)
2897 (gnus-group-next-unread-group 1))
2898 (gnus-handle-ephemeral-exit quit-config)))
2899 (gnus-message 3 "Can't select group")
2900 nil)
2901 ;; The user did a `C-g' while prompting for number of articles,
2902 ;; so we exit this group.
2903 ((eq did-select 'quit)
2904 (and (eq major-mode 'gnus-summary-mode)
2905 (not (equal (current-buffer) kill-buffer))
2906 (kill-buffer (current-buffer)))
2907 (when kill-buffer
2908 (gnus-kill-or-deaden-summary kill-buffer))
2909 (if (not quit-config)
2910 (progn
2911 (set-buffer gnus-group-buffer)
2912 (gnus-group-jump-to-group group)
2913 (gnus-group-next-unread-group 1)
2914 (gnus-configure-windows 'group 'force))
2915 (gnus-handle-ephemeral-exit quit-config))
2916 ;; Finally signal the quit.
2917 (signal 'quit nil))
2918 ;; The group was successfully selected.
2919 (t
2920 (gnus-set-global-variables)
2921 ;; Save the active value in effect when the group was entered.
2922 (setq gnus-newsgroup-active
2923 (gnus-copy-sequence
2924 (gnus-active gnus-newsgroup-name)))
2925 ;; You can change the summary buffer in some way with this hook.
6748645f 2926 (gnus-run-hooks 'gnus-select-group-hook)
eec82323
LMI
2927 ;; Set any local variables in the group parameters.
2928 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2929 (gnus-update-format-specifications
2930 nil 'summary 'summary-mode 'summary-dummy)
16409b0b 2931 (gnus-update-summary-mark-positions)
eec82323
LMI
2932 ;; Do score processing.
2933 (when gnus-use-scoring
2934 (gnus-possibly-score-headers))
2935 ;; Check whether to fill in the gaps in the threads.
2936 (when gnus-build-sparse-threads
2937 (gnus-build-sparse-threads))
2938 ;; Find the initial limit.
2939 (if gnus-show-threads
2940 (if show-all
2941 (let ((gnus-newsgroup-dormant nil))
2942 (gnus-summary-initial-limit show-all))
2943 (gnus-summary-initial-limit show-all))
16409b0b 2944 ;; When untreaded, all articles are always shown.
eec82323
LMI
2945 (setq gnus-newsgroup-limit
2946 (mapcar
2947 (lambda (header) (mail-header-number header))
2948 gnus-newsgroup-headers)))
2949 ;; Generate the summary buffer.
2950 (unless no-display
2951 (gnus-summary-prepare))
2952 (when gnus-use-trees
2953 (gnus-tree-open group)
2954 (setq gnus-summary-highlight-line-function
2955 'gnus-tree-highlight-article))
2956 ;; If the summary buffer is empty, but there are some low-scored
2957 ;; articles or some excluded dormants, we include these in the
2958 ;; buffer.
2959 (when (and (zerop (buffer-size))
2960 (not no-display))
2961 (cond (gnus-newsgroup-dormant
2962 (gnus-summary-limit-include-dormant))
2963 ((and gnus-newsgroup-scored show-all)
2964 (gnus-summary-limit-include-expunged t))))
2965 ;; Function `gnus-apply-kill-file' must be called in this hook.
6748645f 2966 (gnus-run-hooks 'gnus-apply-kill-hook)
eec82323
LMI
2967 (if (and (zerop (buffer-size))
2968 (not no-display))
2969 (progn
2970 ;; This newsgroup is empty.
2971 (gnus-summary-catchup-and-exit nil t)
2972 (gnus-message 6 "No unread news")
2973 (when kill-buffer
2974 (gnus-kill-or-deaden-summary kill-buffer))
2975 ;; Return nil from this function.
2976 nil)
2977 ;; Hide conversation thread subtrees. We cannot do this in
2978 ;; gnus-summary-prepare-hook since kill processing may not
2979 ;; work with hidden articles.
2980 (and gnus-show-threads
2981 gnus-thread-hide-subtree
2982 (gnus-summary-hide-all-threads))
6748645f
LMI
2983 (when kill-buffer
2984 (gnus-kill-or-deaden-summary kill-buffer))
eec82323
LMI
2985 ;; Show first unread article if requested.
2986 (if (and (not no-article)
2987 (not no-display)
2988 gnus-newsgroup-unreads
2989 gnus-auto-select-first)
16409b0b
GM
2990 (progn
2991 (gnus-configure-windows 'summary)
2992 (cond
2993 ((eq gnus-auto-select-first 'best)
2994 (gnus-summary-best-unread-article))
2995 ((eq gnus-auto-select-first t)
2996 (gnus-summary-first-unread-article))
2997 ((gnus-functionp gnus-auto-select-first)
2998 (funcall gnus-auto-select-first))))
eec82323
LMI
2999 ;; Don't select any articles, just move point to the first
3000 ;; article in the group.
3001 (goto-char (point-min))
3002 (gnus-summary-position-point)
6748645f
LMI
3003 (gnus-configure-windows 'summary 'force)
3004 (gnus-set-mode-line 'summary))
eec82323
LMI
3005 (when (get-buffer-window gnus-group-buffer t)
3006 ;; Gotta use windows, because recenter does weird stuff if
3007 ;; the current buffer ain't the displayed window.
3008 (let ((owin (selected-window)))
3009 (select-window (get-buffer-window gnus-group-buffer t))
3010 (when (gnus-group-goto-group group)
3011 (recenter))
3012 (select-window owin)))
3013 ;; Mark this buffer as "prepared".
3014 (setq gnus-newsgroup-prepared t)
6748645f 3015 (gnus-run-hooks 'gnus-summary-prepared-hook)
eec82323
LMI
3016 t)))))
3017
3018(defun gnus-summary-prepare ()
3019 "Generate the summary buffer."
3020 (interactive)
3021 (let ((buffer-read-only nil))
3022 (erase-buffer)
3023 (setq gnus-newsgroup-data nil
3024 gnus-newsgroup-data-reverse nil)
6748645f 3025 (gnus-run-hooks 'gnus-summary-generate-hook)
eec82323
LMI
3026 ;; Generate the buffer, either with threads or without.
3027 (when gnus-newsgroup-headers
3028 (gnus-summary-prepare-threads
3029 (if gnus-show-threads
3030 (gnus-sort-gathered-threads
3031 (funcall gnus-summary-thread-gathering-function
3032 (gnus-sort-threads
3033 (gnus-cut-threads (gnus-make-threads)))))
3034 ;; Unthreaded display.
3035 (gnus-sort-articles gnus-newsgroup-headers))))
3036 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3037 ;; Call hooks for modifying summary buffer.
3038 (goto-char (point-min))
6748645f 3039 (gnus-run-hooks 'gnus-summary-prepare-hook)))
eec82323
LMI
3040
3041(defsubst gnus-general-simplify-subject (subject)
3042 "Simply subject by the same rules as gnus-gather-threads-by-subject."
3043 (setq subject
3044 (cond
3045 ;; Truncate the subject.
6748645f
LMI
3046 (gnus-simplify-subject-functions
3047 (gnus-map-function gnus-simplify-subject-functions subject))
eec82323
LMI
3048 ((numberp gnus-summary-gather-subject-limit)
3049 (setq subject (gnus-simplify-subject-re subject))
3050 (if (> (length subject) gnus-summary-gather-subject-limit)
3051 (substring subject 0 gnus-summary-gather-subject-limit)
3052 subject))
3053 ;; Fuzzily simplify it.
3054 ((eq 'fuzzy gnus-summary-gather-subject-limit)
3055 (gnus-simplify-subject-fuzzy subject))
3056 ;; Just remove the leading "Re:".
3057 (t
3058 (gnus-simplify-subject-re subject))))
3059
3060 (if (and gnus-summary-gather-exclude-subject
3061 (string-match gnus-summary-gather-exclude-subject subject))
3062 nil ; This article shouldn't be gathered
3063 subject))
3064
3065(defun gnus-summary-simplify-subject-query ()
3066 "Query where the respool algorithm would put this article."
3067 (interactive)
eec82323
LMI
3068 (gnus-summary-select-article)
3069 (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3070
3071(defun gnus-gather-threads-by-subject (threads)
3072 "Gather threads by looking at Subject headers."
3073 (if (not gnus-summary-make-false-root)
3074 threads
3075 (let ((hashtb (gnus-make-hashtable 1024))
3076 (prev threads)
3077 (result threads)
3078 subject hthread whole-subject)
3079 (while threads
3080 (setq subject (gnus-general-simplify-subject
3081 (setq whole-subject (mail-header-subject
3082 (caar threads)))))
3083 (when subject
3084 (if (setq hthread (gnus-gethash subject hashtb))
3085 (progn
3086 ;; We enter a dummy root into the thread, if we
3087 ;; haven't done that already.
3088 (unless (stringp (caar hthread))
3089 (setcar hthread (list whole-subject (car hthread))))
3090 ;; We add this new gathered thread to this gathered
3091 ;; thread.
3092 (setcdr (car hthread)
3093 (nconc (cdar hthread) (list (car threads))))
3094 ;; Remove it from the list of threads.
3095 (setcdr prev (cdr threads))
3096 (setq threads prev))
3097 ;; Enter this thread into the hash table.
3098 (gnus-sethash subject threads hashtb)))
3099 (setq prev threads)
3100 (setq threads (cdr threads)))
3101 result)))
3102
3103(defun gnus-gather-threads-by-references (threads)
3104 "Gather threads by looking at References headers."
3105 (let ((idhashtb (gnus-make-hashtable 1024))
3106 (thhashtb (gnus-make-hashtable 1024))
3107 (prev threads)
3108 (result threads)
3109 ids references id gthread gid entered ref)
3110 (while threads
3111 (when (setq references (mail-header-references (caar threads)))
3112 (setq id (mail-header-id (caar threads))
3113 ids (gnus-split-references references)
3114 entered nil)
3115 (while (setq ref (pop ids))
3116 (setq ids (delete ref ids))
3117 (if (not (setq gid (gnus-gethash ref idhashtb)))
3118 (progn
3119 (gnus-sethash ref id idhashtb)
3120 (gnus-sethash id threads thhashtb))
3121 (setq gthread (gnus-gethash gid thhashtb))
3122 (unless entered
3123 ;; We enter a dummy root into the thread, if we
3124 ;; haven't done that already.
3125 (unless (stringp (caar gthread))
3126 (setcar gthread (list (mail-header-subject (caar gthread))
3127 (car gthread))))
3128 ;; We add this new gathered thread to this gathered
3129 ;; thread.
3130 (setcdr (car gthread)
3131 (nconc (cdar gthread) (list (car threads)))))
3132 ;; Add it into the thread hash table.
3133 (gnus-sethash id gthread thhashtb)
3134 (setq entered t)
3135 ;; Remove it from the list of threads.
3136 (setcdr prev (cdr threads))
3137 (setq threads prev))))
3138 (setq prev threads)
3139 (setq threads (cdr threads)))
3140 result))
3141
3142(defun gnus-sort-gathered-threads (threads)
16409b0b 3143 "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
eec82323
LMI
3144 (let ((result threads))
3145 (while threads
3146 (when (stringp (caar threads))
3147 (setcdr (car threads)
16409b0b 3148 (sort (cdar threads) gnus-sort-gathered-threads-function)))
eec82323
LMI
3149 (setq threads (cdr threads)))
3150 result))
3151
3152(defun gnus-thread-loop-p (root thread)
3153 "Say whether ROOT is in THREAD."
3154 (let ((stack (list thread))
3155 (infloop 0)
3156 th)
3157 (while (setq thread (pop stack))
3158 (setq th (cdr thread))
3159 (while (and th
3160 (not (eq (caar th) root)))
3161 (pop th))
3162 (if th
3163 ;; We have found a loop.
3164 (let (ref-dep)
3165 (setcdr thread (delq (car th) (cdr thread)))
3166 (if (boundp (setq ref-dep (intern "none"
3167 gnus-newsgroup-dependencies)))
3168 (setcdr (symbol-value ref-dep)
3169 (nconc (cdr (symbol-value ref-dep))
3170 (list (car th))))
3171 (set ref-dep (list nil (car th))))
3172 (setq infloop 1
3173 stack nil))
3174 ;; Push all the subthreads onto the stack.
3175 (push (cdr thread) stack)))
3176 infloop))
3177
3178(defun gnus-make-threads ()
3179 "Go through the dependency hashtb and find the roots. Return all threads."
3180 (let (threads)
3181 (while (catch 'infloop
3182 (mapatoms
3183 (lambda (refs)
3184 ;; Deal with self-referencing References loops.
3185 (when (and (car (symbol-value refs))
3186 (not (zerop
3187 (apply
3188 '+
3189 (mapcar
3190 (lambda (thread)
3191 (gnus-thread-loop-p
3192 (car (symbol-value refs)) thread))
3193 (cdr (symbol-value refs)))))))
3194 (setq threads nil)
3195 (throw 'infloop t))
3196 (unless (car (symbol-value refs))
3197 ;; These threads do not refer back to any other articles,
3198 ;; so they're roots.
3199 (setq threads (append (cdr (symbol-value refs)) threads))))
3200 gnus-newsgroup-dependencies)))
3201 threads))
3202
6748645f 3203;; Build the thread tree.
16409b0b 3204(defsubst gnus-dependencies-add-header (header dependencies force-new)
6748645f
LMI
3205 "Enter HEADER into the DEPENDENCIES table if it is not already there.
3206
3207If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3208if it was already present.
3209
3210If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3211will not be entered in the DEPENDENCIES table. Otherwise duplicate
3212Message-IDs will be renamed be renamed to a unique Message-ID before
3213being entered.
3214
3215Returns HEADER if it was entered in the DEPENDENCIES. Returns nil otherwise."
3216 (let* ((id (mail-header-id header))
3217 (id-dep (and id (intern id dependencies)))
3218 ref ref-dep ref-header)
3219 ;; Enter this `header' in the `dependencies' table.
3220 (cond
3221 ((not id-dep)
3222 (setq header nil))
3223 ;; The first two cases do the normal part: enter a new `header'
3224 ;; in the `dependencies' table.
3225 ((not (boundp id-dep))
3226 (set id-dep (list header)))
3227 ((null (car (symbol-value id-dep)))
3228 (setcar (symbol-value id-dep) header))
3229
3230 ;; From here the `header' was already present in the
3231 ;; `dependencies' table.
3232 (force-new
3233 ;; Overrides an existing entry;
3234 ;; just set the header part of the entry.
3235 (setcar (symbol-value id-dep) header))
3236
3237 ;; Renames the existing `header' to a unique Message-ID.
3238 ((not gnus-summary-ignore-duplicates)
3239 ;; An article with this Message-ID has already been seen.
3240 ;; We rename the Message-ID.
3241 (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3242 (list header))
3243 (mail-header-set-id header id))
3244
3245 ;; The last case ignores an existing entry, except it adds any
3246 ;; additional Xrefs (in case the two articles came from different
3247 ;; servers.
3248 ;; Also sets `header' to `nil' meaning that the `dependencies'
3249 ;; table was *not* modified.
3250 (t
3251 (mail-header-set-xref
3252 (car (symbol-value id-dep))
3253 (concat (or (mail-header-xref (car (symbol-value id-dep)))
3254 "")
3255 (or (mail-header-xref header) "")))
3256 (setq header nil)))
3257
3258 (when header
3259 ;; First check if that we are not creating a References loop.
3260 (setq ref (gnus-parent-id (mail-header-references header)))
3261 (while (and ref
3262 (setq ref-dep (intern-soft ref dependencies))
3263 (boundp ref-dep)
3264 (setq ref-header (car (symbol-value ref-dep))))
3265 (if (string= id ref)
3266 ;; Yuk! This is a reference loop. Make the article be a
3267 ;; root article.
3268 (progn
3269 (mail-header-set-references (car (symbol-value id-dep)) "none")
3270 (setq ref nil))
3271 (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3272 (setq ref (gnus-parent-id (mail-header-references header)))
3273 (setq ref-dep (intern (or ref "none") dependencies))
3274 (if (boundp ref-dep)
3275 (setcdr (symbol-value ref-dep)
3276 (nconc (cdr (symbol-value ref-dep))
3277 (list (symbol-value id-dep))))
3278 (set ref-dep (list nil (symbol-value id-dep)))))
3279 header))
3280
eec82323
LMI
3281(defun gnus-build-sparse-threads ()
3282 (let ((headers gnus-newsgroup-headers)
16409b0b 3283 (mail-parse-charset gnus-newsgroup-charset)
6748645f 3284 (gnus-summary-ignore-duplicates t)
eec82323 3285 header references generation relations
6748645f 3286 subject child end new-child date)
eec82323
LMI
3287 ;; First we create an alist of generations/relations, where
3288 ;; generations is how much we trust the relation, and the relation
3289 ;; is parent/child.
3290 (gnus-message 7 "Making sparse threads...")
3291 (save-excursion
3292 (nnheader-set-temp-buffer " *gnus sparse threads*")
3293 (while (setq header (pop headers))
3294 (when (and (setq references (mail-header-references header))
3295 (not (string= references "")))
3296 (insert references)
3297 (setq child (mail-header-id header)
6748645f
LMI
3298 subject (mail-header-subject header)
3299 date (mail-header-date header)
3300 generation 0)
eec82323
LMI
3301 (while (search-backward ">" nil t)
3302 (setq end (1+ (point)))
3303 (when (search-backward "<" nil t)
6748645f 3304 (setq new-child (buffer-substring (point) end))
eec82323 3305 (push (list (incf generation)
6748645f
LMI
3306 child (setq child new-child)
3307 subject date)
eec82323 3308 relations)))
6748645f
LMI
3309 (when child
3310 (push (list (1+ generation) child nil subject) relations))
eec82323
LMI
3311 (erase-buffer)))
3312 (kill-buffer (current-buffer)))
3313 ;; Sort over trustworthiness.
6748645f
LMI
3314 (mapcar
3315 (lambda (relation)
3316 (when (gnus-dependencies-add-header
3317 (make-full-mail-header
3318 gnus-reffed-article-number
3319 (nth 3 relation) "" (or (nth 4 relation) "")
3320 (nth 1 relation)
3321 (or (nth 2 relation) "") 0 0 "")
3322 gnus-newsgroup-dependencies nil)
3323 (push gnus-reffed-article-number gnus-newsgroup-limit)
3324 (push gnus-reffed-article-number gnus-newsgroup-sparse)
3325 (push (cons gnus-reffed-article-number gnus-sparse-mark)
3326 gnus-newsgroup-reads)
3327 (decf gnus-reffed-article-number)))
3328 (sort relations 'car-less-than-car))
eec82323
LMI
3329 (gnus-message 7 "Making sparse threads...done")))
3330
3331(defun gnus-build-old-threads ()
3332 ;; Look at all the articles that refer back to old articles, and
3333 ;; fetch the headers for the articles that aren't there. This will
3334 ;; build complete threads - if the roots haven't been expired by the
3335 ;; server, that is.
16409b0b
GM
3336 (let ((mail-parse-charset gnus-newsgroup-charset)
3337 id heads)
eec82323
LMI
3338 (mapatoms
3339 (lambda (refs)
3340 (when (not (car (symbol-value refs)))
3341 (setq heads (cdr (symbol-value refs)))
3342 (while heads
3343 (if (memq (mail-header-number (caar heads))
3344 gnus-newsgroup-dormant)
3345 (setq heads (cdr heads))
3346 (setq id (symbol-name refs))
3347 (while (and (setq id (gnus-build-get-header id))
6748645f 3348 (not (car (gnus-id-to-thread id)))))
eec82323
LMI
3349 (setq heads nil)))))
3350 gnus-newsgroup-dependencies)))
3351
6748645f
LMI
3352;; This function has to be called with point after the article number
3353;; on the beginning of the line.
3354(defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3355 (let ((eol (gnus-point-at-eol))
3356 (buffer (current-buffer))
3357 header)
3358
3359 ;; overview: [num subject from date id refs chars lines misc]
3360 (unwind-protect
3361 (progn
3362 (narrow-to-region (point) eol)
3363 (unless (eobp)
3364 (forward-char))
3365
3366 (setq header
3367 (make-full-mail-header
3368 number ; number
16409b0b
GM
3369 (funcall gnus-decode-encoded-word-function
3370 (nnheader-nov-field)) ; subject
3371 (funcall gnus-decode-encoded-word-function
3372 (nnheader-nov-field)) ; from
3373 (nnheader-nov-field) ; date
3374 (nnheader-nov-read-message-id) ; id
3375 (nnheader-nov-field) ; refs
3376 (nnheader-nov-read-integer) ; chars
3377 (nnheader-nov-read-integer) ; lines
3378 (unless (eobp)
8b93df01
DL
3379 (if (looking-at "Xref: ")
3380 (goto-char (match-end 0)))
3381 (nnheader-nov-field)) ; Xref
16409b0b 3382 (nnheader-nov-parse-extra)))) ; extra
6748645f
LMI
3383
3384 (widen))
3385
3386 (when gnus-alter-header-function
3387 (funcall gnus-alter-header-function header))
3388 (gnus-dependencies-add-header header dependencies force-new)))
3389
eec82323 3390(defun gnus-build-get-header (id)
16409b0b
GM
3391 "Look through the buffer of NOV lines and find the header to ID.
3392Enter this line into the dependencies hash table, and return
3393the id of the parent article (if any)."
eec82323
LMI
3394 (let ((deps gnus-newsgroup-dependencies)
3395 found header)
3396 (prog1
3397 (save-excursion
3398 (set-buffer nntp-server-buffer)
3399 (let ((case-fold-search nil))
3400 (goto-char (point-min))
3401 (while (and (not found)
3402 (search-forward id nil t))
3403 (beginning-of-line)
3404 (setq found (looking-at
3405 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3406 (regexp-quote id))))
3407 (or found (beginning-of-line 2)))
3408 (when found
3409 (beginning-of-line)
3410 (and
3411 (setq header (gnus-nov-parse-line
3412 (read (current-buffer)) deps))
3413 (gnus-parent-id (mail-header-references header))))))
3414 (when header
3415 (let ((number (mail-header-number header)))
3416 (push number gnus-newsgroup-limit)
3417 (push header gnus-newsgroup-headers)
3418 (if (memq number gnus-newsgroup-unselected)
3419 (progn
3420 (push number gnus-newsgroup-unreads)
3421 (setq gnus-newsgroup-unselected
3422 (delq number gnus-newsgroup-unselected)))
3423 (push number gnus-newsgroup-ancient)))))))
3424
6748645f
LMI
3425(defun gnus-build-all-threads ()
3426 "Read all the headers."
3427 (let ((gnus-summary-ignore-duplicates t)
16409b0b 3428 (mail-parse-charset gnus-newsgroup-charset)
6748645f
LMI
3429 (dependencies gnus-newsgroup-dependencies)
3430 header article)
3431 (save-excursion
3432 (set-buffer nntp-server-buffer)
3433 (let ((case-fold-search nil))
3434 (goto-char (point-min))
3435 (while (not (eobp))
3436 (ignore-errors
3437 (setq article (read (current-buffer))
16409b0b 3438 header (gnus-nov-parse-line article dependencies)))
6748645f
LMI
3439 (when header
3440 (save-excursion
3441 (set-buffer gnus-summary-buffer)
3442 (push header gnus-newsgroup-headers)
3443 (if (memq (setq article (mail-header-number header))
3444 gnus-newsgroup-unselected)
3445 (progn
3446 (push article gnus-newsgroup-unreads)
3447 (setq gnus-newsgroup-unselected
3448 (delq article gnus-newsgroup-unselected)))
3449 (push article gnus-newsgroup-ancient)))
3450 (forward-line 1)))))))
3451
eec82323
LMI
3452(defun gnus-summary-update-article-line (article header)
3453 "Update the line for ARTICLE using HEADERS."
3454 (let* ((id (mail-header-id header))
3455 (thread (gnus-id-to-thread id)))
3456 (unless thread
3457 (error "Article in no thread"))
3458 ;; Update the thread.
3459 (setcar thread header)
3460 (gnus-summary-goto-subject article)
3461 (let* ((datal (gnus-data-find-list article))
3462 (data (car datal))
3463 (length (when (cdr datal)
3464 (- (gnus-data-pos data)
3465 (gnus-data-pos (cadr datal)))))
3466 (buffer-read-only nil)
3467 (level (gnus-summary-thread-level)))
3468 (gnus-delete-line)
3469 (gnus-summary-insert-line
3470 header level nil (gnus-article-mark article)
3471 (memq article gnus-newsgroup-replied)
3472 (memq article gnus-newsgroup-expirable)
3473 ;; Only insert the Subject string when it's different
3474 ;; from the previous Subject string.
16409b0b
GM
3475 (if (and
3476 gnus-show-threads
3477 (gnus-subject-equal
3478 (condition-case ()
3479 (mail-header-subject
3480 (gnus-data-header
3481 (cadr
3482 (gnus-data-find-list
3483 article
3484 (gnus-data-list t)))))
3485 ;; Error on the side of excessive subjects.
3486 (error ""))
3487 (mail-header-subject header)))
eec82323
LMI
3488 ""
3489 (mail-header-subject header))
3490 nil (cdr (assq article gnus-newsgroup-scored))
3491 (memq article gnus-newsgroup-processable))
3492 (when length
3493 (gnus-data-update-list
3494 (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3495
3496(defun gnus-summary-update-article (article &optional iheader)
3497 "Update ARTICLE in the summary buffer."
3498 (set-buffer gnus-summary-buffer)
6748645f 3499 (let* ((header (gnus-summary-article-header article))
eec82323
LMI
3500 (id (mail-header-id header))
3501 (data (gnus-data-find article))
3502 (thread (gnus-id-to-thread id))
3503 (references (mail-header-references header))
3504 (parent
3505 (gnus-id-to-thread
3506 (or (gnus-parent-id
3507 (when (and references
3508 (not (equal "" references)))
3509 references))
3510 "none")))
3511 (buffer-read-only nil)
6748645f 3512 (old (car thread)))
eec82323 3513 (when thread
eec82323 3514 (unless iheader
6748645f
LMI
3515 (setcar thread nil)
3516 (when parent
3517 (delq thread parent)))
3518 (if (gnus-summary-insert-subject id header)
eec82323
LMI
3519 ;; Set the (possibly) new article number in the data structure.
3520 (gnus-data-set-number data (gnus-id-to-article id))
3521 (setcar thread old)
3522 nil))))
3523
6748645f
LMI
3524(defun gnus-rebuild-thread (id &optional line)
3525 "Rebuild the thread containing ID.
3526If LINE, insert the rebuilt thread starting on line LINE."
eec82323
LMI
3527 (let ((buffer-read-only nil)
3528 old-pos current thread data)
3529 (if (not gnus-show-threads)
3530 (setq thread (list (car (gnus-id-to-thread id))))
3531 ;; Get the thread this article is part of.
3532 (setq thread (gnus-remove-thread id)))
3533 (setq old-pos (gnus-point-at-bol))
3534 (setq current (save-excursion
3535 (and (zerop (forward-line -1))
3536 (gnus-summary-article-number))))
3537 ;; If this is a gathered thread, we have to go some re-gathering.
3538 (when (stringp (car thread))
3539 (let ((subject (car thread))
3540 roots thr)
3541 (setq thread (cdr thread))
3542 (while thread
3543 (unless (memq (setq thr (gnus-id-to-thread
3544 (gnus-root-id
3545 (mail-header-id (caar thread)))))
3546 roots)
3547 (push thr roots))
3548 (setq thread (cdr thread)))
3549 ;; We now have all (unique) roots.
3550 (if (= (length roots) 1)
3551 ;; All the loose roots are now one solid root.
3552 (setq thread (car roots))
3553 (setq thread (cons subject (gnus-sort-threads roots))))))
3554 (let (threads)
3555 ;; We then insert this thread into the summary buffer.
6748645f
LMI
3556 (when line
3557 (goto-char (point-min))
3558 (forward-line (1- line)))
eec82323
LMI
3559 (let (gnus-newsgroup-data gnus-newsgroup-threads)
3560 (if gnus-show-threads
3561 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3562 (gnus-summary-prepare-unthreaded thread))
3563 (setq data (nreverse gnus-newsgroup-data))
3564 (setq threads gnus-newsgroup-threads))
3565 ;; We splice the new data into the data structure.
6748645f
LMI
3566 ;;!!! This is kinda bogus. We assume that in LINE is non-nil,
3567 ;;!!! then we want to insert at the beginning of the buffer.
3568 ;;!!! That happens to be true with Gnus now, but that may
3569 ;;!!! change in the future. Perhaps.
3570 (gnus-data-enter-list
3571 (if line nil current) data (- (point) old-pos))
3572 (setq gnus-newsgroup-threads
3573 (nconc threads gnus-newsgroup-threads))
3574 (gnus-data-compute-positions))))
eec82323
LMI
3575
3576(defun gnus-number-to-header (number)
3577 "Return the header for article NUMBER."
3578 (let ((headers gnus-newsgroup-headers))
3579 (while (and headers
3580 (not (= number (mail-header-number (car headers)))))
3581 (pop headers))
3582 (when headers
3583 (car headers))))
3584
6748645f 3585(defun gnus-parent-headers (in-headers &optional generation)
eec82323
LMI
3586 "Return the headers of the GENERATIONeth parent of HEADERS."
3587 (unless generation
3588 (setq generation 1))
a8151ef7 3589 (let ((parent t)
6748645f 3590 (headers in-headers)
a8151ef7 3591 references)
6748645f
LMI
3592 (while (and parent
3593 (not (zerop generation))
3594 (setq references (mail-header-references headers)))
3595 (setq headers (if (and references
3596 (setq parent (gnus-parent-id references)))
3597 (car (gnus-id-to-thread parent))
3598 nil))
3599 (decf generation))
3600 (and (not (eq headers in-headers))
3601 headers)))
eec82323
LMI
3602
3603(defun gnus-id-to-thread (id)
3604 "Return the (sub-)thread where ID appears."
3605 (gnus-gethash id gnus-newsgroup-dependencies))
3606
3607(defun gnus-id-to-article (id)
3608 "Return the article number of ID."
3609 (let ((thread (gnus-id-to-thread id)))
3610 (when (and thread
3611 (car thread))
3612 (mail-header-number (car thread)))))
3613
3614(defun gnus-id-to-header (id)
3615 "Return the article headers of ID."
3616 (car (gnus-id-to-thread id)))
3617
3618(defun gnus-article-displayed-root-p (article)
3619 "Say whether ARTICLE is a root(ish) article."
3620 (let ((level (gnus-summary-thread-level article))
3621 (refs (mail-header-references (gnus-summary-article-header article)))
3622 particle)
3623 (cond
3624 ((null level) nil)
3625 ((zerop level) t)
3626 ((null refs) t)
3627 ((null (gnus-parent-id refs)) t)
3628 ((and (= 1 level)
3629 (null (setq particle (gnus-id-to-article
3630 (gnus-parent-id refs))))
3631 (null (gnus-summary-thread-level particle)))))))
3632
3633(defun gnus-root-id (id)
3634 "Return the id of the root of the thread where ID appears."
3635 (let (last-id prev)
6748645f 3636 (while (and id (setq prev (car (gnus-id-to-thread id))))
eec82323
LMI
3637 (setq last-id id
3638 id (gnus-parent-id (mail-header-references prev))))
3639 last-id))
3640
6748645f
LMI
3641(defun gnus-articles-in-thread (thread)
3642 "Return the list of articles in THREAD."
3643 (cons (mail-header-number (car thread))
3644 (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3645
eec82323
LMI
3646(defun gnus-remove-thread (id &optional dont-remove)
3647 "Remove the thread that has ID in it."
6748645f 3648 (let (headers thread last-id)
eec82323 3649 ;; First go up in this thread until we find the root.
6748645f
LMI
3650 (setq last-id (gnus-root-id id)
3651 headers (message-flatten-list (gnus-id-to-thread last-id)))
eec82323
LMI
3652 ;; We have now found the real root of this thread. It might have
3653 ;; been gathered into some loose thread, so we have to search
3654 ;; through the threads to find the thread we wanted.
3655 (let ((threads gnus-newsgroup-threads)
3656 sub)
3657 (while threads
3658 (setq sub (car threads))
3659 (if (stringp (car sub))
3660 ;; This is a gathered thread, so we look at the roots
3661 ;; below it to find whether this article is in this
3662 ;; gathered root.
3663 (progn
3664 (setq sub (cdr sub))
3665 (while sub
3666 (when (member (caar sub) headers)
3667 (setq thread (car threads)
3668 threads nil
3669 sub nil))
3670 (setq sub (cdr sub))))
3671 ;; It's an ordinary thread, so we check it.
3672 (when (eq (car sub) (car headers))
3673 (setq thread sub
3674 threads nil)))
3675 (setq threads (cdr threads)))
3676 ;; If this article is in no thread, then it's a root.
3677 (if thread
3678 (unless dont-remove
3679 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
6748645f 3680 (setq thread (gnus-id-to-thread last-id)))
eec82323
LMI
3681 (when thread
3682 (prog1
3683 thread ; We return this thread.
3684 (unless dont-remove
3685 (if (stringp (car thread))
3686 (progn
3687 ;; If we use dummy roots, then we have to remove the
3688 ;; dummy root as well.
3689 (when (eq gnus-summary-make-false-root 'dummy)
6748645f
LMI
3690 ;; We go to the dummy root by going to
3691 ;; the first sub-"thread", and then one line up.
3692 (gnus-summary-goto-article
3693 (mail-header-number (caadr thread)))
3694 (forward-line -1)
eec82323
LMI
3695 (gnus-delete-line)
3696 (gnus-data-compute-positions))
3697 (setq thread (cdr thread))
3698 (while thread
3699 (gnus-remove-thread-1 (car thread))
3700 (setq thread (cdr thread))))
3701 (gnus-remove-thread-1 thread))))))))
3702
3703(defun gnus-remove-thread-1 (thread)
3704 "Remove the thread THREAD recursively."
3705 (let ((number (mail-header-number (pop thread)))
3706 d)
3707 (setq thread (reverse thread))
3708 (while thread
3709 (gnus-remove-thread-1 (pop thread)))
3710 (when (setq d (gnus-data-find number))
3711 (goto-char (gnus-data-pos d))
16409b0b 3712 (gnus-summary-show-thread)
eec82323
LMI
3713 (gnus-data-remove
3714 number
3715 (- (gnus-point-at-bol)
3716 (prog1
3717 (1+ (gnus-point-at-eol))
3718 (gnus-delete-line)))))))
3719
16409b0b
GM
3720(defun gnus-sort-threads-1 (threads func)
3721 (sort (mapcar (lambda (thread)
3722 (cons (car thread)
3723 (and (cdr thread)
3724 (gnus-sort-threads-1 (cdr thread) func))))
3725 threads) func))
3726
eec82323
LMI
3727(defun gnus-sort-threads (threads)
3728 "Sort THREADS."
3729 (if (not gnus-thread-sort-functions)
3730 threads
6748645f 3731 (gnus-message 8 "Sorting threads...")
eec82323 3732 (prog1
16409b0b
GM
3733 (gnus-sort-threads-1
3734 threads
3735 (gnus-make-sort-function gnus-thread-sort-functions))
6748645f 3736 (gnus-message 8 "Sorting threads...done"))))
eec82323
LMI
3737
3738(defun gnus-sort-articles (articles)
3739 "Sort ARTICLES."
3740 (when gnus-article-sort-functions
3741 (gnus-message 7 "Sorting articles...")
3742 (prog1
3743 (setq gnus-newsgroup-headers
3744 (sort articles (gnus-make-sort-function
3745 gnus-article-sort-functions)))
3746 (gnus-message 7 "Sorting articles...done"))))
3747
3748;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3749(defmacro gnus-thread-header (thread)
16409b0b
GM
3750 "Return header of first article in THREAD.
3751Note that THREAD must never, ever be anything else than a variable -
3752using some other form will lead to serious barfage."
eec82323
LMI
3753 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3754 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
16409b0b 3755 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
eec82323
LMI
3756 (vector thread) 2))
3757
3758(defsubst gnus-article-sort-by-number (h1 h2)
3759 "Sort articles by article number."
3760 (< (mail-header-number h1)
3761 (mail-header-number h2)))
3762
3763(defun gnus-thread-sort-by-number (h1 h2)
3764 "Sort threads by root article number."
3765 (gnus-article-sort-by-number
3766 (gnus-thread-header h1) (gnus-thread-header h2)))
3767
3768(defsubst gnus-article-sort-by-lines (h1 h2)
3769 "Sort articles by article Lines header."
3770 (< (mail-header-lines h1)
3771 (mail-header-lines h2)))
3772
3773(defun gnus-thread-sort-by-lines (h1 h2)
3774 "Sort threads by root article Lines header."
3775 (gnus-article-sort-by-lines
3776 (gnus-thread-header h1) (gnus-thread-header h2)))
3777
16409b0b
GM
3778(defsubst gnus-article-sort-by-chars (h1 h2)
3779 "Sort articles by octet length."
3780 (< (mail-header-chars h1)
3781 (mail-header-chars h2)))
3782
3783(defun gnus-thread-sort-by-chars (h1 h2)
3784 "Sort threads by root article octet length."
3785 (gnus-article-sort-by-chars
3786 (gnus-thread-header h1) (gnus-thread-header h2)))
3787
eec82323
LMI
3788(defsubst gnus-article-sort-by-author (h1 h2)
3789 "Sort articles by root author."
3790 (string-lessp
3791 (let ((extract (funcall
3792 gnus-extract-address-components
3793 (mail-header-from h1))))
3794 (or (car extract) (cadr extract) ""))
3795 (let ((extract (funcall
3796 gnus-extract-address-components
3797 (mail-header-from h2))))
3798 (or (car extract) (cadr extract) ""))))
3799
3800(defun gnus-thread-sort-by-author (h1 h2)
3801 "Sort threads by root author."
3802 (gnus-article-sort-by-author
3803 (gnus-thread-header h1) (gnus-thread-header h2)))
3804
3805(defsubst gnus-article-sort-by-subject (h1 h2)
3806 "Sort articles by root subject."
3807 (string-lessp
3808 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3809 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3810
3811(defun gnus-thread-sort-by-subject (h1 h2)
3812 "Sort threads by root subject."
3813 (gnus-article-sort-by-subject
3814 (gnus-thread-header h1) (gnus-thread-header h2)))
3815
3816(defsubst gnus-article-sort-by-date (h1 h2)
3817 "Sort articles by root article date."
16409b0b 3818 (time-less-p
eec82323
LMI
3819 (gnus-date-get-time (mail-header-date h1))
3820 (gnus-date-get-time (mail-header-date h2))))
3821
3822(defun gnus-thread-sort-by-date (h1 h2)
3823 "Sort threads by root article date."
3824 (gnus-article-sort-by-date
3825 (gnus-thread-header h1) (gnus-thread-header h2)))
3826
3827(defsubst gnus-article-sort-by-score (h1 h2)
3828 "Sort articles by root article score.
3829Unscored articles will be counted as having a score of zero."
3830 (> (or (cdr (assq (mail-header-number h1)
3831 gnus-newsgroup-scored))
3832 gnus-summary-default-score 0)
3833 (or (cdr (assq (mail-header-number h2)
3834 gnus-newsgroup-scored))
3835 gnus-summary-default-score 0)))
3836
3837(defun gnus-thread-sort-by-score (h1 h2)
3838 "Sort threads by root article score."
3839 (gnus-article-sort-by-score
3840 (gnus-thread-header h1) (gnus-thread-header h2)))
3841
3842(defun gnus-thread-sort-by-total-score (h1 h2)
3843 "Sort threads by the sum of all scores in the thread.
3844Unscored articles will be counted as having a score of zero."
3845 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3846
3847(defun gnus-thread-total-score (thread)
16409b0b 3848 ;; This function find the total score of THREAD.
eec82323
LMI
3849 (cond ((null thread)
3850 0)
3851 ((consp thread)
3852 (if (stringp (car thread))
3853 (apply gnus-thread-score-function 0
3854 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3855 (gnus-thread-total-score-1 thread)))
3856 (t
3857 (gnus-thread-total-score-1 (list thread)))))
3858
3859(defun gnus-thread-total-score-1 (root)
3860 ;; This function find the total score of the thread below ROOT.
3861 (setq root (car root))
3862 (apply gnus-thread-score-function
3863 (or (append
3864 (mapcar 'gnus-thread-total-score
6748645f 3865 (cdr (gnus-id-to-thread (mail-header-id root))))
eec82323
LMI
3866 (when (> (mail-header-number root) 0)
3867 (list (or (cdr (assq (mail-header-number root)
3868 gnus-newsgroup-scored))
3869 gnus-summary-default-score 0))))
3870 (list gnus-summary-default-score)
3871 '(0))))
3872
3873;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3874(defvar gnus-tmp-prev-subject nil)
3875(defvar gnus-tmp-false-parent nil)
3876(defvar gnus-tmp-root-expunged nil)
3877(defvar gnus-tmp-dummy-line nil)
3878
60bd5589 3879(eval-when-compile (defvar gnus-tmp-header))
16409b0b
GM
3880(defun gnus-extra-header (type &optional header)
3881 "Return the extra header of TYPE."
3882 (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3883 ""))
3884
eec82323
LMI
3885(defun gnus-summary-prepare-threads (threads)
3886 "Prepare summary buffer from THREADS and indentation LEVEL.
3887THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3888or a straight list of headers."
3889 (gnus-message 7 "Generating summary...")
3890
3891 (setq gnus-newsgroup-threads threads)
3892 (beginning-of-line)
3893
3894 (let ((gnus-tmp-level 0)
3895 (default-score (or gnus-summary-default-score 0))
3896 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3897 thread number subject stack state gnus-tmp-gathered beg-match
3898 new-roots gnus-tmp-new-adopts thread-end
3899 gnus-tmp-header gnus-tmp-unread
3900 gnus-tmp-replied gnus-tmp-subject-or-nil
3901 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3902 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3903 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
3904
3905 (setq gnus-tmp-prev-subject nil)
3906
3907 (if (vectorp (car threads))
3908 ;; If this is a straight (sic) list of headers, then a
3909 ;; threaded summary display isn't required, so we just create
3910 ;; an unthreaded one.
3911 (gnus-summary-prepare-unthreaded threads)
3912
3913 ;; Do the threaded display.
3914
3915 (while (or threads stack gnus-tmp-new-adopts new-roots)
3916
3917 (if (and (= gnus-tmp-level 0)
eec82323
LMI
3918 (or (not stack)
3919 (= (caar stack) 0))
3920 (not gnus-tmp-false-parent)
3921 (or gnus-tmp-new-adopts new-roots))
3922 (if gnus-tmp-new-adopts
3923 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
3924 thread (list (car gnus-tmp-new-adopts))
3925 gnus-tmp-header (caar thread)
3926 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
3927 (when new-roots
3928 (setq thread (list (car new-roots))
3929 gnus-tmp-header (caar thread)
3930 new-roots (cdr new-roots))))
3931
3932 (if threads
3933 ;; If there are some threads, we do them before the
3934 ;; threads on the stack.
3935 (setq thread threads
3936 gnus-tmp-header (caar thread))
3937 ;; There were no current threads, so we pop something off
3938 ;; the stack.
3939 (setq state (car stack)
3940 gnus-tmp-level (car state)
3941 thread (cdr state)
3942 stack (cdr stack)
3943 gnus-tmp-header (caar thread))))
3944
3945 (setq gnus-tmp-false-parent nil)
3946 (setq gnus-tmp-root-expunged nil)
3947 (setq thread-end nil)
3948
3949 (if (stringp gnus-tmp-header)
3950 ;; The header is a dummy root.
3951 (cond
3952 ((eq gnus-summary-make-false-root 'adopt)
3953 ;; We let the first article adopt the rest.
3954 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
3955 (cddar thread)))
3956 (setq gnus-tmp-gathered
3957 (nconc (mapcar
3958 (lambda (h) (mail-header-number (car h)))
3959 (cddar thread))
3960 gnus-tmp-gathered))
3961 (setq thread (cons (list (caar thread)
3962 (cadar thread))
3963 (cdr thread)))
3964 (setq gnus-tmp-level -1
3965 gnus-tmp-false-parent t))
3966 ((eq gnus-summary-make-false-root 'empty)
3967 ;; We print adopted articles with empty subject fields.
3968 (setq gnus-tmp-gathered
3969 (nconc (mapcar
3970 (lambda (h) (mail-header-number (car h)))
3971 (cddar thread))
3972 gnus-tmp-gathered))
3973 (setq gnus-tmp-level -1))
3974 ((eq gnus-summary-make-false-root 'dummy)
3975 ;; We remember that we probably want to output a dummy
3976 ;; root.
3977 (setq gnus-tmp-dummy-line gnus-tmp-header)
3978 (setq gnus-tmp-prev-subject gnus-tmp-header))
3979 (t
3980 ;; We do not make a root for the gathered
3981 ;; sub-threads at all.
3982 (setq gnus-tmp-level -1)))
3983
3984 (setq number (mail-header-number gnus-tmp-header)
3985 subject (mail-header-subject gnus-tmp-header))
3986
3987 (cond
3988 ;; If the thread has changed subject, we might want to make
3989 ;; this subthread into a root.
3990 ((and (null gnus-thread-ignore-subject)
3991 (not (zerop gnus-tmp-level))
3992 gnus-tmp-prev-subject
3993 (not (inline
3994 (gnus-subject-equal gnus-tmp-prev-subject subject))))
3995 (setq new-roots (nconc new-roots (list (car thread)))
3996 thread-end t
3997 gnus-tmp-header nil))
3998 ;; If the article lies outside the current limit,
3999 ;; then we do not display it.
4000 ((not (memq number gnus-newsgroup-limit))
4001 (setq gnus-tmp-gathered
4002 (nconc (mapcar
4003 (lambda (h) (mail-header-number (car h)))
4004 (cdar thread))
4005 gnus-tmp-gathered))
4006 (setq gnus-tmp-new-adopts (if (cdar thread)
4007 (append gnus-tmp-new-adopts
4008 (cdar thread))
4009 gnus-tmp-new-adopts)
4010 thread-end t
4011 gnus-tmp-header nil)
4012 (when (zerop gnus-tmp-level)
4013 (setq gnus-tmp-root-expunged t)))
4014 ;; Perhaps this article is to be marked as read?
4015 ((and gnus-summary-mark-below
4016 (< (or (cdr (assq number gnus-newsgroup-scored))
4017 default-score)
4018 gnus-summary-mark-below)
4019 ;; Don't touch sparse articles.
4020 (not (gnus-summary-article-sparse-p number))
4021 (not (gnus-summary-article-ancient-p number)))
4022 (setq gnus-newsgroup-unreads
4023 (delq number gnus-newsgroup-unreads))
4024 (if gnus-newsgroup-auto-expire
4025 (push number gnus-newsgroup-expirable)
4026 (push (cons number gnus-low-score-mark)
4027 gnus-newsgroup-reads))))
4028
4029 (when gnus-tmp-header
4030 ;; We may have an old dummy line to output before this
4031 ;; article.
6748645f
LMI
4032 (when (and gnus-tmp-dummy-line
4033 (gnus-subject-equal
4034 gnus-tmp-dummy-line
4035 (mail-header-subject gnus-tmp-header)))
eec82323
LMI
4036 (gnus-summary-insert-dummy-line
4037 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4038 (setq gnus-tmp-dummy-line nil))
4039
4040 ;; Compute the mark.
4041 (setq gnus-tmp-unread (gnus-article-mark number))
4042
4043 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4044 gnus-tmp-header gnus-tmp-level)
4045 gnus-newsgroup-data)
4046
4047 ;; Actually insert the line.
4048 (setq
4049 gnus-tmp-subject-or-nil
4050 (cond
4051 ((and gnus-thread-ignore-subject
4052 gnus-tmp-prev-subject
4053 (not (inline (gnus-subject-equal
4054 gnus-tmp-prev-subject subject))))
4055 subject)
4056 ((zerop gnus-tmp-level)
4057 (if (and (eq gnus-summary-make-false-root 'empty)
4058 (memq number gnus-tmp-gathered)
4059 gnus-tmp-prev-subject
4060 (inline (gnus-subject-equal
4061 gnus-tmp-prev-subject subject)))
4062 gnus-summary-same-subject
4063 subject))
4064 (t gnus-summary-same-subject)))
4065 (if (and (eq gnus-summary-make-false-root 'adopt)
4066 (= gnus-tmp-level 1)
4067 (memq number gnus-tmp-gathered))
4068 (setq gnus-tmp-opening-bracket ?\<
4069 gnus-tmp-closing-bracket ?\>)
4070 (setq gnus-tmp-opening-bracket ?\[
4071 gnus-tmp-closing-bracket ?\]))
4072 (setq
4073 gnus-tmp-indentation
4074 (aref gnus-thread-indent-array gnus-tmp-level)
4075 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4076 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4077 gnus-summary-default-score 0)
4078 gnus-tmp-score-char
4079 (if (or (null gnus-summary-default-score)
4080 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4081 gnus-summary-zcore-fuzz))
16409b0b 4082 ? ;Whitespace
eec82323
LMI
4083 (if (< gnus-tmp-score gnus-summary-default-score)
4084 gnus-score-below-mark gnus-score-over-mark))
4085 gnus-tmp-replied
4086 (cond ((memq number gnus-newsgroup-processable)
4087 gnus-process-mark)
4088 ((memq number gnus-newsgroup-cached)
4089 gnus-cached-mark)
4090 ((memq number gnus-newsgroup-replied)
4091 gnus-replied-mark)
4092 ((memq number gnus-newsgroup-saved)
4093 gnus-saved-mark)
4094 (t gnus-unread-mark))
4095 gnus-tmp-from (mail-header-from gnus-tmp-header)
4096 gnus-tmp-name
4097 (cond
4098 ((string-match "<[^>]+> *$" gnus-tmp-from)
4099 (setq beg-match (match-beginning 0))
4100 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
4101 (substring gnus-tmp-from (1+ (match-beginning 0))
4102 (1- (match-end 0))))
4103 (substring gnus-tmp-from 0 beg-match)))
4104 ((string-match "(.+)" gnus-tmp-from)
4105 (substring gnus-tmp-from
4106 (1+ (match-beginning 0)) (1- (match-end 0))))
4107 (t gnus-tmp-from)))
4108 (when (string= gnus-tmp-name "")
4109 (setq gnus-tmp-name gnus-tmp-from))
4110 (unless (numberp gnus-tmp-lines)
4111 (setq gnus-tmp-lines 0))
16409b0b 4112 (gnus-put-text-property
eec82323
LMI
4113 (point)
4114 (progn (eval gnus-summary-line-format-spec) (point))
4115 'gnus-number number)
4116 (when gnus-visual-p
4117 (forward-line -1)
6748645f 4118 (gnus-run-hooks 'gnus-summary-update-hook)
eec82323
LMI
4119 (forward-line 1))
4120
4121 (setq gnus-tmp-prev-subject subject)))
4122
4123 (when (nth 1 thread)
4124 (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4125 (incf gnus-tmp-level)
4126 (setq threads (if thread-end nil (cdar thread)))
4127 (unless threads
4128 (setq gnus-tmp-level 0)))))
4129 (gnus-message 7 "Generating summary...done"))
4130
4131(defun gnus-summary-prepare-unthreaded (headers)
4132 "Generate an unthreaded summary buffer based on HEADERS."
4133 (let (header number mark)
4134
4135 (beginning-of-line)
4136
4137 (while headers
4138 ;; We may have to root out some bad articles...
4139 (when (memq (setq number (mail-header-number
4140 (setq header (pop headers))))
4141 gnus-newsgroup-limit)
4142 ;; Mark article as read when it has a low score.
4143 (when (and gnus-summary-mark-below
4144 (< (or (cdr (assq number gnus-newsgroup-scored))
4145 gnus-summary-default-score 0)
4146 gnus-summary-mark-below)
4147 (not (gnus-summary-article-ancient-p number)))
4148 (setq gnus-newsgroup-unreads
4149 (delq number gnus-newsgroup-unreads))
4150 (if gnus-newsgroup-auto-expire
4151 (push number gnus-newsgroup-expirable)
4152 (push (cons number gnus-low-score-mark)
4153 gnus-newsgroup-reads)))
4154
4155 (setq mark (gnus-article-mark number))
4156 (push (gnus-data-make number mark (1+ (point)) header 0)
4157 gnus-newsgroup-data)
4158 (gnus-summary-insert-line
4159 header 0 number
4160 mark (memq number gnus-newsgroup-replied)
4161 (memq number gnus-newsgroup-expirable)
4162 (mail-header-subject header) nil
4163 (cdr (assq number gnus-newsgroup-scored))
4164 (memq number gnus-newsgroup-processable))))))
4165
16409b0b
GM
4166(defun gnus-summary-remove-list-identifiers ()
4167 "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4168 (let ((regexp (if (stringp gnus-list-identifiers)
4169 gnus-list-identifiers
4170 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
4171 (dolist (header gnus-newsgroup-headers)
4172 (when (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
4173 " *\\)\\)+\\(Re: +\\)?\\)")
4174 (mail-header-subject header))
4175 (mail-header-set-subject
4176 header (concat (substring (mail-header-subject header)
4177 0 (match-beginning 1))
4178 (or
4179 (match-string 3 (mail-header-subject header))
4180 (match-string 5 (mail-header-subject header)))
4181 (substring (mail-header-subject header)
4182 (match-end 1))))))))
4183
6748645f 4184(defun gnus-select-newsgroup (group &optional read-all select-articles)
eec82323 4185 "Select newsgroup GROUP.
6748645f
LMI
4186If READ-ALL is non-nil, all articles in the group are selected.
4187If SELECT-ARTICLES, only select those articles from GROUP."
eec82323
LMI
4188 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4189 ;;!!! Dirty hack; should be removed.
4190 (gnus-summary-ignore-duplicates
6748645f 4191 (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
eec82323
LMI
4192 t
4193 gnus-summary-ignore-duplicates))
4194 (info (nth 2 entry))
4195 articles fetched-articles cached)
4196
4197 (unless (gnus-check-server
4198 (setq gnus-current-select-method
4199 (gnus-find-method-for-group group)))
4200 (error "Couldn't open server"))
4201
4202 (or (and entry (not (eq (car entry) t))) ; Either it's active...
4203 (gnus-activate-group group) ; Or we can activate it...
4204 (progn ; Or we bug out.
4205 (when (equal major-mode 'gnus-summary-mode)
4206 (kill-buffer (current-buffer)))
4207 (error "Couldn't request group %s: %s"
4208 group (gnus-status-message group))))
4209
4210 (unless (gnus-request-group group t)
4211 (when (equal major-mode 'gnus-summary-mode)
4212 (kill-buffer (current-buffer)))
4213 (error "Couldn't request group %s: %s"
4214 group (gnus-status-message group)))
4215
4216 (setq gnus-newsgroup-name group)
4217 (setq gnus-newsgroup-unselected nil)
4218 (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
16409b0b 4219 (gnus-summary-setup-default-charset)
eec82323
LMI
4220
4221 ;; Adjust and set lists of article marks.
4222 (when info
4223 (gnus-adjust-marked-articles info))
4224
4225 ;; Kludge to avoid having cached articles nixed out in virtual groups.
4226 (when (gnus-virtual-group-p group)
4227 (setq cached gnus-newsgroup-cached))
4228
4229 (setq gnus-newsgroup-unreads
4230 (gnus-set-difference
4231 (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4232 gnus-newsgroup-dormant))
4233
4234 (setq gnus-newsgroup-processable nil)
4235
4236 (gnus-update-read-articles group gnus-newsgroup-unreads)
eec82323 4237
6748645f
LMI
4238 (if (setq articles select-articles)
4239 (setq gnus-newsgroup-unselected
4240 (gnus-sorted-intersection
4241 gnus-newsgroup-unreads
4242 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4243 (setq articles (gnus-articles-to-read group read-all)))
eec82323
LMI
4244
4245 (cond
4246 ((null articles)
4247 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4248 'quit)
4249 ((eq articles 0) nil)
4250 (t
4251 ;; Init the dependencies hash table.
4252 (setq gnus-newsgroup-dependencies
4253 (gnus-make-hashtable (length articles)))
16409b0b 4254 (gnus-set-global-variables)
eec82323
LMI
4255 ;; Retrieve the headers and read them in.
4256 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4257 (setq gnus-newsgroup-headers
4258 (if (eq 'nov
4259 (setq gnus-headers-retrieved-by
4260 (gnus-retrieve-headers
4261 articles gnus-newsgroup-name
4262 ;; We might want to fetch old headers, but
4263 ;; not if there is only 1 article.
6748645f 4264 (and (or (and
eec82323
LMI
4265 (not (eq gnus-fetch-old-headers 'some))
4266 (not (numberp gnus-fetch-old-headers)))
6748645f
LMI
4267 (> (length articles) 1))
4268 gnus-fetch-old-headers))))
eec82323
LMI
4269 (gnus-get-newsgroup-headers-xover
4270 articles nil nil gnus-newsgroup-name t)
4271 (gnus-get-newsgroup-headers)))
4272 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4273
4274 ;; Kludge to avoid having cached articles nixed out in virtual groups.
4275 (when cached
4276 (setq gnus-newsgroup-cached cached))
4277
4278 ;; Suppress duplicates?
4279 (when gnus-suppress-duplicates
4280 (gnus-dup-suppress-articles))
4281
4282 ;; Set the initial limit.
4283 (setq gnus-newsgroup-limit (copy-sequence articles))
4284 ;; Remove canceled articles from the list of unread articles.
4285 (setq gnus-newsgroup-unreads
4286 (gnus-set-sorted-intersection
4287 gnus-newsgroup-unreads
4288 (setq fetched-articles
4289 (mapcar (lambda (headers) (mail-header-number headers))
4290 gnus-newsgroup-headers))))
4291 ;; Removed marked articles that do not exist.
4292 (gnus-update-missing-marks
4293 (gnus-sorted-complement fetched-articles articles))
4294 ;; We might want to build some more threads first.
6748645f
LMI
4295 (when (and gnus-fetch-old-headers
4296 (eq gnus-headers-retrieved-by 'nov))
4297 (if (eq gnus-fetch-old-headers 'invisible)
4298 (gnus-build-all-threads)
4299 (gnus-build-old-threads)))
4300 ;; Let the Gnus agent mark articles as read.
4301 (when gnus-agent
4302 (gnus-agent-get-undownloaded-list))
16409b0b
GM
4303 ;; Remove list identifiers from subject
4304 (when gnus-list-identifiers
4305 (gnus-summary-remove-list-identifiers))
eec82323
LMI
4306 ;; Check whether auto-expire is to be done in this group.
4307 (setq gnus-newsgroup-auto-expire
4308 (gnus-group-auto-expirable-p group))
4309 ;; Set up the article buffer now, if necessary.
4310 (unless gnus-single-article-buffer
4311 (gnus-article-setup-buffer))
4312 ;; First and last article in this newsgroup.
4313 (when gnus-newsgroup-headers
4314 (setq gnus-newsgroup-begin
4315 (mail-header-number (car gnus-newsgroup-headers))
4316 gnus-newsgroup-end
4317 (mail-header-number
4318 (gnus-last-element gnus-newsgroup-headers))))
4319 ;; GROUP is successfully selected.
4320 (or gnus-newsgroup-headers t)))))
4321
4322(defun gnus-articles-to-read (group &optional read-all)
16409b0b 4323 "Find out what articles the user wants to read."
eec82323
LMI
4324 (let* ((articles
4325 ;; Select all articles if `read-all' is non-nil, or if there
4326 ;; are no unread articles.
4327 (if (or read-all
4328 (and (zerop (length gnus-newsgroup-marked))
4329 (zerop (length gnus-newsgroup-unreads)))
4330 (eq (gnus-group-find-parameter group 'display)
4331 'all))
16409b0b
GM
4332 (or
4333 (gnus-uncompress-range (gnus-active group))
4334 (gnus-cache-articles-in-group group))
eec82323
LMI
4335 (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4336 (copy-sequence gnus-newsgroup-unreads))
4337 '<)))
4338 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4339 (scored (length scored-list))
4340 (number (length articles))
4341 (marked (+ (length gnus-newsgroup-marked)
4342 (length gnus-newsgroup-dormant)))
4343 (select
4344 (cond
4345 ((numberp read-all)
4346 read-all)
4347 (t
4348 (condition-case ()
4349 (cond
4350 ((and (or (<= scored marked) (= scored number))
4351 (numberp gnus-large-newsgroup)
4352 (> number gnus-large-newsgroup))
4353 (let ((input
4354 (read-string
4355 (format
4356 "How many articles from %s (default %d): "
4357 (gnus-limit-string gnus-newsgroup-name 35)
4358 number))))
4359 (if (string-match "^[ \t]*$" input) number input)))
4360 ((and (> scored marked) (< scored number)
4361 (> (- scored number) 20))
4362 (let ((input
4363 (read-string
4364 (format "%s %s (%d scored, %d total): "
4365 "How many articles from"
4366 group scored number))))
4367 (if (string-match "^[ \t]*$" input)
4368 number input)))
4369 (t number))
d4dfaa19
DL
4370 (quit
4371 (message "Quit getting the articles to read")
4372 nil))))))
eec82323
LMI
4373 (setq select (if (stringp select) (string-to-number select) select))
4374 (if (or (null select) (zerop select))
4375 select
4376 (if (and (not (zerop scored)) (<= (abs select) scored))
4377 (progn
4378 (setq articles (sort scored-list '<))
4379 (setq number (length articles)))
4380 (setq articles (copy-sequence articles)))
4381
4382 (when (< (abs select) number)
4383 (if (< select 0)
4384 ;; Select the N oldest articles.
4385 (setcdr (nthcdr (1- (abs select)) articles) nil)
4386 ;; Select the N most recent articles.
4387 (setq articles (nthcdr (- number select) articles))))
4388 (setq gnus-newsgroup-unselected
4389 (gnus-sorted-intersection
4390 gnus-newsgroup-unreads
4391 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
16409b0b
GM
4392 (when gnus-alter-articles-to-read-function
4393 (setq gnus-newsgroup-unreads
4394 (sort
4395 (funcall gnus-alter-articles-to-read-function
4396 gnus-newsgroup-name gnus-newsgroup-unreads)
4397 '<)))
eec82323
LMI
4398 articles)))
4399
4400(defun gnus-killed-articles (killed articles)
4401 (let (out)
4402 (while articles
4403 (when (inline (gnus-member-of-range (car articles) killed))
4404 (push (car articles) out))
4405 (setq articles (cdr articles)))
4406 out))
4407
4408(defun gnus-uncompress-marks (marks)
4409 "Uncompress the mark ranges in MARKS."
4410 (let ((uncompressed '(score bookmark))
4411 out)
4412 (while marks
4413 (if (memq (caar marks) uncompressed)
4414 (push (car marks) out)
4415 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4416 (setq marks (cdr marks)))
4417 out))
4418
4419(defun gnus-adjust-marked-articles (info)
16409b0b 4420 "Set all article lists and remove all marks that are no longer valid."
eec82323
LMI
4421 (let* ((marked-lists (gnus-info-marks info))
4422 (active (gnus-active (gnus-info-group info)))
4423 (min (car active))
4424 (max (cdr active))
4425 (types gnus-article-mark-lists)
4426 (uncompressed '(score bookmark killed))
4427 marks var articles article mark)
4428
4429 (while marked-lists
4430 (setq marks (pop marked-lists))
4431 (set (setq var (intern (format "gnus-newsgroup-%s"
4432 (car (rassq (setq mark (car marks))
4433 types)))))
4434 (if (memq (car marks) uncompressed) (cdr marks)
4435 (gnus-uncompress-range (cdr marks))))
4436
4437 (setq articles (symbol-value var))
4438
4439 ;; All articles have to be subsets of the active articles.
4440 (cond
4441 ;; Adjust "simple" lists.
4442 ((memq mark '(tick dormant expire reply save))
4443 (while articles
4444 (when (or (< (setq article (pop articles)) min) (> article max))
4445 (set var (delq article (symbol-value var))))))
4446 ;; Adjust assocs.
4447 ((memq mark uncompressed)
a8151ef7
LMI
4448 (when (not (listp (cdr (symbol-value var))))
4449 (set var (list (symbol-value var))))
4450 (when (not (listp (cdr articles)))
4451 (setq articles (list articles)))
eec82323
LMI
4452 (while articles
4453 (when (or (not (consp (setq article (pop articles))))
4454 (< (car article) min)
4455 (> (car article) max))
4456 (set var (delq article (symbol-value var))))))))))
4457
4458(defun gnus-update-missing-marks (missing)
6748645f 4459 "Go through the list of MISSING articles and remove them from the mark lists."
eec82323
LMI
4460 (when missing
4461 (let ((types gnus-article-mark-lists)
4462 var m)
4463 ;; Go through all types.
4464 (while types
4465 (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4466 (when (symbol-value var)
4467 ;; This list has articles. So we delete all missing articles
4468 ;; from it.
4469 (setq m missing)
4470 (while m
4471 (set var (delq (pop m) (symbol-value var)))))))))
4472
4473(defun gnus-update-marks ()
4474 "Enter the various lists of marked articles into the newsgroup info list."
4475 (let ((types gnus-article-mark-lists)
4476 (info (gnus-get-info gnus-newsgroup-name))
4477 (uncompressed '(score bookmark killed))
16409b0b 4478 type list newmarked symbol delta-marks)
eec82323 4479 (when info
16409b0b 4480 ;; Add all marks lists to the list of marks lists.
eec82323 4481 (while (setq type (pop types))
16409b0b
GM
4482 (setq list (symbol-value
4483 (setq symbol
4484 (intern (format "gnus-newsgroup-%s"
4485 (car type))))))
eec82323 4486
16409b0b 4487 (when list
eec82323
LMI
4488 ;; Get rid of the entries of the articles that have the
4489 ;; default score.
4490 (when (and (eq (cdr type) 'score)
4491 gnus-save-score
4492 list)
4493 (let* ((arts list)
4494 (prev (cons nil list))
4495 (all prev))
4496 (while arts
4497 (if (or (not (consp (car arts)))
4498 (= (cdar arts) gnus-summary-default-score))
4499 (setcdr prev (cdr arts))
4500 (setq prev arts))
4501 (setq arts (cdr arts)))
16409b0b
GM
4502 (setq list (cdr all)))))
4503
4504 (unless (memq (cdr type) uncompressed)
4505 (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4506
4507 (when (gnus-check-backend-function
4508 'request-set-mark gnus-newsgroup-name)
4509 ;; propagate flags to server, with the following exceptions:
4510 ;; uncompressed:s are not proper flags (they are cons cells)
4511 ;; cache is a internal gnus flag
4512 ;; download are local to one gnus installation (well)
4513 ;; unsend are for nndraft groups only
4514 ;; xxx: generality of this? this suits nnimap anyway
4515 (unless (memq (cdr type) (append '(cache download unsend)
4516 uncompressed))
4517 (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4518 (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4519 (add (gnus-remove-from-range
4520 (gnus-copy-sequence list) old)))
4521 (when add
4522 (push (list add 'add (list (cdr type))) delta-marks))
4523 (when del
4524 (push (list del 'del (list (cdr type))) delta-marks)))))
4525
4526 (when list
4527 (push (cons (cdr type) list) newmarked)))
4528
4529 (when delta-marks
4530 (unless (gnus-check-group gnus-newsgroup-name)
4531 (error "Can't open server for %s" gnus-newsgroup-name))
4532 (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4533
eec82323
LMI
4534 ;; Enter these new marks into the info of the group.
4535 (if (nthcdr 3 info)
4536 (setcar (nthcdr 3 info) newmarked)
4537 ;; Add the marks lists to the end of the info.
4538 (when newmarked
4539 (setcdr (nthcdr 2 info) (list newmarked))))
4540
4541 ;; Cut off the end of the info if there's nothing else there.
4542 (let ((i 5))
4543 (while (and (> i 2)
4544 (not (nth i info)))
4545 (when (nthcdr (decf i) info)
4546 (setcdr (nthcdr i info) nil)))))))
4547
4548(defun gnus-set-mode-line (where)
16409b0b 4549 "Set the mode line of the article or summary buffers.
eec82323
LMI
4550If WHERE is `summary', the summary mode line format will be used."
4551 ;; Is this mode line one we keep updated?
16409b0b
GM
4552 (when (and (memq where gnus-updated-mode-lines)
4553 (symbol-value
4554 (intern (format "gnus-%s-mode-line-format-spec" where))))
eec82323
LMI
4555 (let (mode-string)
4556 (save-excursion
4557 ;; We evaluate this in the summary buffer since these
4558 ;; variables are buffer-local to that buffer.
4559 (set-buffer gnus-summary-buffer)
4560 ;; We bind all these variables that are used in the `eval' form
4561 ;; below.
4562 (let* ((mformat (symbol-value
4563 (intern
4564 (format "gnus-%s-mode-line-format-spec" where))))
16409b0b
GM
4565 (gnus-tmp-group-name (gnus-group-name-decode
4566 gnus-newsgroup-name
4567 (gnus-group-name-charset
4568 nil
4569 gnus-newsgroup-name)))
eec82323
LMI
4570 (gnus-tmp-article-number (or gnus-current-article 0))
4571 (gnus-tmp-unread gnus-newsgroup-unreads)
4572 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4573 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4574 (gnus-tmp-unread-and-unselected
4575 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4576 (zerop gnus-tmp-unselected))
4577 "")
4578 ((zerop gnus-tmp-unselected)
4579 (format "{%d more}" gnus-tmp-unread-and-unticked))
4580 (t (format "{%d(+%d) more}"
4581 gnus-tmp-unread-and-unticked
4582 gnus-tmp-unselected))))
4583 (gnus-tmp-subject
4584 (if (and gnus-current-headers
4585 (vectorp gnus-current-headers))
4586 (gnus-mode-string-quote
4587 (mail-header-subject gnus-current-headers))
4588 ""))
4589 bufname-length max-len
4590 gnus-tmp-header);; passed as argument to any user-format-funcs
4591 (setq mode-string (eval mformat))
4592 (setq bufname-length (if (string-match "%b" mode-string)
4593 (- (length
4594 (buffer-name
4595 (if (eq where 'summary)
4596 nil
4597 (get-buffer gnus-article-buffer))))
4598 2)
4599 0))
4600 (setq max-len (max 4 (if gnus-mode-non-string-length
4601 (- (window-width)
4602 gnus-mode-non-string-length
4603 bufname-length)
4604 (length mode-string))))
4605 ;; We might have to chop a bit of the string off...
4606 (when (> (length mode-string) max-len)
4607 (setq mode-string
16409b0b 4608 (concat (truncate-string-to-width mode-string (- max-len 3))
eec82323
LMI
4609 "...")))
4610 ;; Pad the mode string a bit.
4611 (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4612 ;; Update the mode line.
4613 (setq mode-line-buffer-identification
4614 (gnus-mode-line-buffer-identification (list mode-string)))
4615 (set-buffer-modified-p t))))
4616
4617(defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4618 "Go through the HEADERS list and add all Xrefs to a hash table.
4619The resulting hash table is returned, or nil if no Xrefs were found."
4620 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4621 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4622 (xref-hashtb (gnus-make-hashtable))
4623 start group entry number xrefs header)
4624 (while headers
4625 (setq header (pop headers))
4626 (when (and (setq xrefs (mail-header-xref header))
4627 (not (memq (setq number (mail-header-number header))
4628 unreads)))
4629 (setq start 0)
4630 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4631 (setq start (match-end 0))
4632 (setq group (if prefix
4633 (concat prefix (substring xrefs (match-beginning 1)
4634 (match-end 1)))
4635 (substring xrefs (match-beginning 1) (match-end 1))))
4636 (setq number
4637 (string-to-int (substring xrefs (match-beginning 2)
4638 (match-end 2))))
4639 (if (setq entry (gnus-gethash group xref-hashtb))
4640 (setcdr entry (cons number (cdr entry)))
4641 (gnus-sethash group (cons number nil) xref-hashtb)))))
4642 (and start xref-hashtb)))
4643
4644(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4645 "Look through all the headers and mark the Xrefs as read."
4646 (let ((virtual (gnus-virtual-group-p from-newsgroup))
4647 name entry info xref-hashtb idlist method nth4)
4648 (save-excursion
4649 (set-buffer gnus-group-buffer)
4650 (when (setq xref-hashtb
4651 (gnus-create-xref-hashtb from-newsgroup headers unreads))
4652 (mapatoms
4653 (lambda (group)
4654 (unless (string= from-newsgroup (setq name (symbol-name group)))
4655 (setq idlist (symbol-value group))
4656 ;; Dead groups are not updated.
4657 (and (prog1
4658 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4659 info (nth 2 entry))
4660 (when (stringp (setq nth4 (gnus-info-method info)))
4661 (setq nth4 (gnus-server-to-method nth4))))
4662 ;; Only do the xrefs if the group has the same
4663 ;; select method as the group we have just read.
4664 (or (gnus-methods-equal-p
4665 nth4 (gnus-find-method-for-group from-newsgroup))
4666 virtual
4667 (equal nth4 (setq method (gnus-find-method-for-group
4668 from-newsgroup)))
4669 (and (equal (car nth4) (car method))
4670 (equal (nth 1 nth4) (nth 1 method))))
4671 gnus-use-cross-reference
4672 (or (not (eq gnus-use-cross-reference t))
4673 virtual
4674 ;; Only do cross-references on subscribed
4675 ;; groups, if that is what is wanted.
4676 (<= (gnus-info-level info) gnus-level-subscribed))
4677 (gnus-group-make-articles-read name idlist))))
4678 xref-hashtb)))))
4679
6748645f
LMI
4680(defun gnus-compute-read-articles (group articles)
4681 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4682 (info (nth 2 entry))
4683 (active (gnus-active group))
4684 ninfo)
4685 (when entry
16409b0b 4686 ;; First peel off all invalid article numbers.
6748645f
LMI
4687 (when active
4688 (let ((ids articles)
4689 id first)
4690 (while (setq id (pop ids))
4691 (when (and first (> id (cdr active)))
4692 ;; We'll end up in this situation in one particular
4693 ;; obscure situation. If you re-scan a group and get
4694 ;; a new article that is cross-posted to a different
4695 ;; group that has not been re-scanned, you might get
4696 ;; crossposted article that has a higher number than
4697 ;; Gnus believes possible. So we re-activate this
4698 ;; group as well. This might mean doing the
4699 ;; crossposting thingy will *increase* the number
4700 ;; of articles in some groups. Tsk, tsk.
4701 (setq active (or (gnus-activate-group group) active)))
4702 (when (or (> id (cdr active))
4703 (< id (car active)))
4704 (setq articles (delq id articles))))))
4705 ;; If the read list is nil, we init it.
4706 (if (and active
4707 (null (gnus-info-read info))
4708 (> (car active) 1))
4709 (setq ninfo (cons 1 (1- (car active))))
4710 (setq ninfo (gnus-info-read info)))
4711 ;; Then we add the read articles to the range.
4712 (gnus-add-to-range
4713 ninfo (setq articles (sort articles '<))))))
4714
eec82323
LMI
4715(defun gnus-group-make-articles-read (group articles)
4716 "Update the info of GROUP to say that ARTICLES are read."
4717 (let* ((num 0)
4718 (entry (gnus-gethash group gnus-newsrc-hashtb))
4719 (info (nth 2 entry))
4720 (active (gnus-active group))
4721 range)
6748645f
LMI
4722 (when entry
4723 (setq range (gnus-compute-read-articles group articles))
4724 (save-excursion
4725 (set-buffer gnus-group-buffer)
4726 (gnus-undo-register
4727 `(progn
4728 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4729 (gnus-info-set-read ',info ',(gnus-info-read info))
4730 (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4731 (gnus-group-update-group ,group t))))
4732 ;; Add the read articles to the range.
4733 (gnus-info-set-read info range)
4734 ;; Then we have to re-compute how many unread
4735 ;; articles there are in this group.
4736 (when active
4737 (cond
4738 ((not range)
4739 (setq num (- (1+ (cdr active)) (car active))))
4740 ((not (listp (cdr range)))
4741 (setq num (- (cdr active) (- (1+ (cdr range))
4742 (car range)))))
4743 (t
4744 (while range
4745 (if (numberp (car range))
4746 (setq num (1+ num))
4747 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4748 (setq range (cdr range)))
4749 (setq num (- (cdr active) num))))
4750 ;; Update the number of unread articles.
4751 (setcar entry num)
4752 ;; Update the group buffer.
4753 (gnus-group-update-group group t)))))
eec82323 4754
eec82323
LMI
4755(defvar gnus-newsgroup-none-id 0)
4756
4757(defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4758 (let ((cur nntp-server-buffer)
4759 (dependencies
4760 (or dependencies
4761 (save-excursion (set-buffer gnus-summary-buffer)
4762 gnus-newsgroup-dependencies)))
16409b0b
GM
4763 headers id end ref
4764 (mail-parse-charset gnus-newsgroup-charset)
4765 (mail-parse-ignored-charsets
4766 (save-excursion (condition-case nil
4767 (set-buffer gnus-summary-buffer)
4768 (error))
4769 gnus-newsgroup-ignored-charsets)))
eec82323
LMI
4770 (save-excursion
4771 (set-buffer nntp-server-buffer)
4772 ;; Translate all TAB characters into SPACE characters.
4773 (subst-char-in-region (point-min) (point-max) ?\t ? t)
16409b0b 4774 (subst-char-in-region (point-min) (point-max) ?\r ? t)
6748645f 4775 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323 4776 (let ((case-fold-search t)
6748645f 4777 in-reply-to header p lines chars)
eec82323
LMI
4778 (goto-char (point-min))
4779 ;; Search to the beginning of the next header. Error messages
4780 ;; do not begin with 2 or 3.
4781 (while (re-search-forward "^[23][0-9]+ " nil t)
4782 (setq id nil
4783 ref nil)
4784 ;; This implementation of this function, with nine
4785 ;; search-forwards instead of the one re-search-forward and
4786 ;; a case (which basically was the old function) is actually
4787 ;; about twice as fast, even though it looks messier. You
4788 ;; can't have everything, I guess. Speed and elegance
4789 ;; doesn't always go hand in hand.
4790 (setq
4791 header
4792 (vector
4793 ;; Number.
4794 (prog1
4795 (read cur)
4796 (end-of-line)
4797 (setq p (point))
4798 (narrow-to-region (point)
4799 (or (and (search-forward "\n.\n" nil t)
4800 (- (point) 2))
4801 (point))))
4802 ;; Subject.
4803 (progn
4804 (goto-char p)
4805 (if (search-forward "\nsubject: " nil t)
16409b0b
GM
4806 (funcall gnus-decode-encoded-word-function
4807 (nnheader-header-value))
2bd3dcae 4808 "(none)"))
eec82323
LMI
4809 ;; From.
4810 (progn
4811 (goto-char p)
d4dfaa19
DL
4812 (if (or (search-forward "\nfrom: " nil t)
4813 (search-forward "\nfrom:" nil t))
16409b0b
GM
4814 (funcall gnus-decode-encoded-word-function
4815 (nnheader-header-value))
2bd3dcae 4816 "(nobody)"))
eec82323
LMI
4817 ;; Date.
4818 (progn
4819 (goto-char p)
4820 (if (search-forward "\ndate: " nil t)
4821 (nnheader-header-value) ""))
4822 ;; Message-ID.
4823 (progn
4824 (goto-char p)
6748645f
LMI
4825 (setq id (if (re-search-forward
4826 "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4827 ;; We do it this way to make sure the Message-ID
4828 ;; is (somewhat) syntactically valid.
4829 (buffer-substring (match-beginning 1)
4830 (match-end 1))
eec82323
LMI
4831 ;; If there was no message-id, we just fake one
4832 ;; to make subsequent routines simpler.
4833 (nnheader-generate-fake-message-id))))
4834 ;; References.
4835 (progn
4836 (goto-char p)
4837 (if (search-forward "\nreferences: " nil t)
4838 (progn
4839 (setq end (point))
4840 (prog1
4841 (nnheader-header-value)
4842 (setq ref
4843 (buffer-substring
4844 (progn
4845 (end-of-line)
4846 (search-backward ">" end t)
4847 (1+ (point)))
4848 (progn
4849 (search-backward "<" end t)
4850 (point))))))
4851 ;; Get the references from the in-reply-to header if there
4852 ;; were no references and the in-reply-to header looks
4853 ;; promising.
4854 (if (and (search-forward "\nin-reply-to: " nil t)
4855 (setq in-reply-to (nnheader-header-value))
4856 (string-match "<[^>]+>" in-reply-to))
6748645f
LMI
4857 (let (ref2)
4858 (setq ref (substring in-reply-to (match-beginning 0)
4859 (match-end 0)))
4860 (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4861 (setq ref2 (substring in-reply-to (match-beginning 0)
4862 (match-end 0)))
4863 (when (> (length ref2) (length ref))
4864 (setq ref ref2)))
4865 ref)
eec82323
LMI
4866 (setq ref nil))))
4867 ;; Chars.
6748645f
LMI
4868 (progn
4869 (goto-char p)
4870 (if (search-forward "\nchars: " nil t)
4871 (if (numberp (setq chars (ignore-errors (read cur))))
4872 chars 0)
4873 0))
eec82323
LMI
4874 ;; Lines.
4875 (progn
4876 (goto-char p)
4877 (if (search-forward "\nlines: " nil t)
a8151ef7 4878 (if (numberp (setq lines (ignore-errors (read cur))))
eec82323
LMI
4879 lines 0)
4880 0))
4881 ;; Xref.
4882 (progn
4883 (goto-char p)
4884 (and (search-forward "\nxref: " nil t)
16409b0b
GM
4885 (nnheader-header-value)))
4886 ;; Extra.
4887 (when gnus-extra-headers
4888 (let ((extra gnus-extra-headers)
4889 out)
4890 (while extra
4891 (goto-char p)
4892 (when (search-forward
4893 (concat "\n" (symbol-name (car extra)) ": ") nil t)
4894 (push (cons (car extra) (nnheader-header-value))
4895 out))
4896 (pop extra))
4897 out))))
eec82323
LMI
4898 (when (equal id ref)
4899 (setq ref nil))
6748645f
LMI
4900
4901 (when gnus-alter-header-function
4902 (funcall gnus-alter-header-function header)
4903 (setq id (mail-header-id header)
4904 ref (gnus-parent-id (mail-header-references header))))
4905
4906 (when (setq header
4907 (gnus-dependencies-add-header
4908 header dependencies force-new))
eec82323
LMI
4909 (push header headers))
4910 (goto-char (point-max))
4911 (widen))
4912 (nreverse headers)))))
4913
eec82323
LMI
4914;; Goes through the xover lines and returns a list of vectors
4915(defun gnus-get-newsgroup-headers-xover (sequence &optional
4916 force-new dependencies
4917 group also-fetch-heads)
16409b0b
GM
4918 "Parse the news overview data in the server buffer.
4919Return a list of headers that match SEQUENCE (see
4920`nntp-retrieve-headers')."
eec82323
LMI
4921 ;; Get the Xref when the users reads the articles since most/some
4922 ;; NNTP servers do not include Xrefs when using XOVER.
4923 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
16409b0b
GM
4924 (let ((mail-parse-charset gnus-newsgroup-charset)
4925 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
4926 (cur nntp-server-buffer)
eec82323
LMI
4927 (dependencies (or dependencies gnus-newsgroup-dependencies))
4928 number headers header)
4929 (save-excursion
4930 (set-buffer nntp-server-buffer)
16409b0b 4931 (subst-char-in-region (point-min) (point-max) ?\r ? t)
eec82323 4932 ;; Allow the user to mangle the headers before parsing them.
6748645f 4933 (gnus-run-hooks 'gnus-parse-headers-hook)
eec82323
LMI
4934 (goto-char (point-min))
4935 (while (not (eobp))
4936 (condition-case ()
4937 (while (and sequence (not (eobp)))
4938 (setq number (read cur))
4939 (while (and sequence
4940 (< (car sequence) number))
4941 (setq sequence (cdr sequence)))
4942 (and sequence
4943 (eq number (car sequence))
4944 (progn
4945 (setq sequence (cdr sequence))
4946 (setq header (inline
4947 (gnus-nov-parse-line
4948 number dependencies force-new))))
4949 (push header headers))
4950 (forward-line 1))
4951 (error
4952 (gnus-error 4 "Strange nov line (%d)"
4953 (count-lines (point-min) (point)))))
4954 (forward-line 1))
4955 ;; A common bug in inn is that if you have posted an article and
4956 ;; then retrieves the active file, it will answer correctly --
4957 ;; the new article is included. However, a NOV entry for the
4958 ;; article may not have been generated yet, so this may fail.
4959 ;; We work around this problem by retrieving the last few
4960 ;; headers using HEAD.
4961 (if (or (not also-fetch-heads)
4962 (not sequence))
4963 ;; We (probably) got all the headers.
4964 (nreverse headers)
4965 (let ((gnus-nov-is-evil t))
4966 (nconc
4967 (nreverse headers)
4968 (when (gnus-retrieve-headers sequence group)
4969 (gnus-get-newsgroup-headers))))))))
4970
4971(defun gnus-article-get-xrefs ()
4972 "Fill in the Xref value in `gnus-current-headers', if necessary.
4973This is meant to be called in `gnus-article-internal-prepare-hook'."
4974 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
4975 gnus-current-headers)))
4976 (or (not gnus-use-cross-reference)
4977 (not headers)
4978 (and (mail-header-xref headers)
4979 (not (string= (mail-header-xref headers) "")))
4980 (let ((case-fold-search t)
4981 xref)
4982 (save-restriction
4983 (nnheader-narrow-to-headers)
4984 (goto-char (point-min))
16409b0b
GM
4985 (when (or (and (not (eobp))
4986 (eq (downcase (char-after)) ?x)
eec82323
LMI
4987 (looking-at "Xref:"))
4988 (search-forward "\nXref:" nil t))
4989 (goto-char (1+ (match-end 0)))
4990 (setq xref (buffer-substring (point)
4991 (progn (end-of-line) (point))))
4992 (mail-header-set-xref headers xref)))))))
4993
4994(defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6748645f
LMI
4995 "Find article ID and insert the summary line for that article.
4996OLD-HEADER can either be a header or a line number to insert
4997the subject line on."
4998 (let* ((line (and (numberp old-header) old-header))
4999 (old-header (and (vectorp old-header) old-header))
5000 (header (cond ((and old-header use-old-header)
16409b0b
GM
5001 old-header)
5002 ((and (numberp id)
5003 (gnus-number-to-header id))
5004 (gnus-number-to-header id))
5005 (t
5006 (gnus-read-header id))))
5007 (number (and (numberp id) id))
5008 d)
eec82323
LMI
5009 (when header
5010 ;; Rebuild the thread that this article is part of and go to the
5011 ;; article we have fetched.
5012 (when (and (not gnus-show-threads)
5013 old-header)
6748645f
LMI
5014 (when (and number
5015 (setq d (gnus-data-find (mail-header-number old-header))))
eec82323
LMI
5016 (goto-char (gnus-data-pos d))
5017 (gnus-data-remove
5018 number
5019 (- (gnus-point-at-bol)
5020 (prog1
5021 (1+ (gnus-point-at-eol))
5022 (gnus-delete-line))))))
5023 (when old-header
5024 (mail-header-set-number header (mail-header-number old-header)))
5025 (setq gnus-newsgroup-sparse
5026 (delq (setq number (mail-header-number header))
5027 gnus-newsgroup-sparse))
5028 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6748645f
LMI
5029 (push number gnus-newsgroup-limit)
5030 (gnus-rebuild-thread (mail-header-id header) line)
eec82323
LMI
5031 (gnus-summary-goto-subject number nil t))
5032 (when (and (numberp number)
5033 (> number 0))
5034 ;; We have to update the boundaries even if we can't fetch the
5035 ;; article if ID is a number -- so that the next `P' or `N'
5036 ;; command will fetch the previous (or next) article even
5037 ;; if the one we tried to fetch this time has been canceled.
5038 (when (> number gnus-newsgroup-end)
5039 (setq gnus-newsgroup-end number))
5040 (when (< number gnus-newsgroup-begin)
5041 (setq gnus-newsgroup-begin number))
5042 (setq gnus-newsgroup-unselected
5043 (delq number gnus-newsgroup-unselected)))
5044 ;; Report back a success?
5045 (and header (mail-header-number header))))
5046
5047;;; Process/prefix in the summary buffer
5048
5049(defun gnus-summary-work-articles (n)
6748645f
LMI
5050 "Return a list of articles to be worked upon.
5051The prefix argument, the list of process marked articles, and the
5052current article will be taken into consideration."
5053 (save-excursion
5054 (set-buffer gnus-summary-buffer)
5055 (cond
5056 (n
5057 ;; A numerical prefix has been given.
5058 (setq n (prefix-numeric-value n))
5059 (let ((backward (< n 0))
5060 (n (abs (prefix-numeric-value n)))
5061 articles article)
5062 (save-excursion
5063 (while
5064 (and (> n 0)
5065 (push (setq article (gnus-summary-article-number))
5066 articles)
5067 (if backward
5068 (gnus-summary-find-prev nil article)
5069 (gnus-summary-find-next nil article)))
5070 (decf n)))
5071 (nreverse articles)))
5072 ((and (gnus-region-active-p) (mark))
5073 (message "region active")
5074 ;; Work on the region between point and mark.
5075 (let ((max (max (point) (mark)))
5076 articles article)
5077 (save-excursion
5078 (goto-char (min (min (point) (mark))))
5079 (while
5080 (and
5081 (push (setq article (gnus-summary-article-number)) articles)
5082 (gnus-summary-find-next nil article)
5083 (< (point) max)))
5084 (nreverse articles))))
5085 (gnus-newsgroup-processable
5086 ;; There are process-marked articles present.
5087 ;; Save current state.
5088 (gnus-summary-save-process-mark)
5089 ;; Return the list.
5090 (reverse gnus-newsgroup-processable))
5091 (t
5092 ;; Just return the current article.
5093 (list (gnus-summary-article-number))))))
5094
5095(defmacro gnus-summary-iterate (arg &rest forms)
5096 "Iterate over the process/prefixed articles and do FORMS.
5097ARG is the interactive prefix given to the command. FORMS will be
5098executed with point over the summary line of the articles."
5099 (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5100 `(let ((,articles (gnus-summary-work-articles ,arg)))
5101 (while ,articles
5102 (gnus-summary-goto-subject (car ,articles))
16409b0b
GM
5103 ,@forms
5104 (pop ,articles)))))
6748645f
LMI
5105
5106(put 'gnus-summary-iterate 'lisp-indent-function 1)
5107(put 'gnus-summary-iterate 'edebug-form-spec '(form body))
eec82323
LMI
5108
5109(defun gnus-summary-save-process-mark ()
5110 "Push the current set of process marked articles on the stack."
5111 (interactive)
5112 (push (copy-sequence gnus-newsgroup-processable)
5113 gnus-newsgroup-process-stack))
5114
5115(defun gnus-summary-kill-process-mark ()
5116 "Push the current set of process marked articles on the stack and unmark."
5117 (interactive)
5118 (gnus-summary-save-process-mark)
5119 (gnus-summary-unmark-all-processable))
5120
5121(defun gnus-summary-yank-process-mark ()
5122 "Pop the last process mark state off the stack and restore it."
5123 (interactive)
5124 (unless gnus-newsgroup-process-stack
5125 (error "Empty mark stack"))
5126 (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5127
5128(defun gnus-summary-process-mark-set (set)
5129 "Make SET into the current process marked articles."
5130 (gnus-summary-unmark-all-processable)
5131 (while set
5132 (gnus-summary-set-process-mark (pop set))))
5133
5134;;; Searching and stuff
5135
5136(defun gnus-summary-search-group (&optional backward use-level)
5137 "Search for next unread newsgroup.
5138If optional argument BACKWARD is non-nil, search backward instead."
5139 (save-excursion
5140 (set-buffer gnus-group-buffer)
5141 (when (gnus-group-search-forward
5142 backward nil (if use-level (gnus-group-group-level) nil))
5143 (gnus-group-group-name))))
5144
5145(defun gnus-summary-best-group (&optional exclude-group)
5146 "Find the name of the best unread group.
5147If EXCLUDE-GROUP, do not go to this group."
5148 (save-excursion
5149 (set-buffer gnus-group-buffer)
5150 (save-excursion
5151 (gnus-group-best-unread-group exclude-group))))
5152
6748645f 5153(defun gnus-summary-find-next (&optional unread article backward undownloaded)
eec82323
LMI
5154 (if backward (gnus-summary-find-prev)
5155 (let* ((dummy (gnus-summary-article-intangible-p))
5156 (article (or article (gnus-summary-article-number)))
5157 (arts (gnus-data-find-list article))
5158 result)
5159 (when (and (not dummy)
5160 (or (not gnus-summary-check-current)
5161 (not unread)
5162 (not (gnus-data-unread-p (car arts)))))
5163 (setq arts (cdr arts)))
5164 (when (setq result
5165 (if unread
5166 (progn
5167 (while arts
6748645f
LMI
5168 (when (or (and undownloaded
5169 (eq gnus-undownloaded-mark
5170 (gnus-data-mark (car arts))))
5171 (gnus-data-unread-p (car arts)))
eec82323
LMI
5172 (setq result (car arts)
5173 arts nil))
5174 (setq arts (cdr arts)))
5175 result)
5176 (car arts)))
5177 (goto-char (gnus-data-pos result))
5178 (gnus-data-number result)))))
5179
5180(defun gnus-summary-find-prev (&optional unread article)
5181 (let* ((eobp (eobp))
5182 (article (or article (gnus-summary-article-number)))
5183 (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5184 result)
5185 (when (and (not eobp)
5186 (or (not gnus-summary-check-current)
5187 (not unread)
5188 (not (gnus-data-unread-p (car arts)))))
5189 (setq arts (cdr arts)))
5190 (when (setq result
5191 (if unread
5192 (progn
5193 (while arts
5194 (when (gnus-data-unread-p (car arts))
5195 (setq result (car arts)
5196 arts nil))
5197 (setq arts (cdr arts)))
5198 result)
5199 (car arts)))
5200 (goto-char (gnus-data-pos result))
5201 (gnus-data-number result))))
5202
5203(defun gnus-summary-find-subject (subject &optional unread backward article)
5204 (let* ((simp-subject (gnus-simplify-subject-fully subject))
5205 (article (or article (gnus-summary-article-number)))
5206 (articles (gnus-data-list backward))
5207 (arts (gnus-data-find-list article articles))
5208 result)
5209 (when (or (not gnus-summary-check-current)
5210 (not unread)
5211 (not (gnus-data-unread-p (car arts))))
5212 (setq arts (cdr arts)))
5213 (while arts
5214 (and (or (not unread)
5215 (gnus-data-unread-p (car arts)))
5216 (vectorp (gnus-data-header (car arts)))
5217 (gnus-subject-equal
5218 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5219 (setq result (car arts)
5220 arts nil))
5221 (setq arts (cdr arts)))
5222 (and result
5223 (goto-char (gnus-data-pos result))
5224 (gnus-data-number result))))
5225
5226(defun gnus-summary-search-forward (&optional unread subject backward)
5227 "Search forward for an article.
5228If UNREAD, look for unread articles. If SUBJECT, look for
5229articles with that subject. If BACKWARD, search backward instead."
5230 (cond (subject (gnus-summary-find-subject subject unread backward))
5231 (backward (gnus-summary-find-prev unread))
5232 (t (gnus-summary-find-next unread))))
5233
5234(defun gnus-recenter (&optional n)
5235 "Center point in window and redisplay frame.
5236Also do horizontal recentering."
5237 (interactive "P")
5238 (when (and gnus-auto-center-summary
5239 (not (eq gnus-auto-center-summary 'vertical)))
5240 (gnus-horizontal-recenter))
5241 (recenter n))
5242
5243(defun gnus-summary-recenter ()
5244 "Center point in the summary window.
5245If `gnus-auto-center-summary' is nil, or the article buffer isn't
5246displayed, no centering will be performed."
5247 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5248 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
16409b0b 5249 (interactive)
eec82323
LMI
5250 (let* ((top (cond ((< (window-height) 4) 0)
5251 ((< (window-height) 7) 1)
16409b0b
GM
5252 (t (if (numberp gnus-auto-center-summary)
5253 gnus-auto-center-summary
5254 2))))
eec82323
LMI
5255 (height (1- (window-height)))
5256 (bottom (save-excursion (goto-char (point-max))
5257 (forward-line (- height))
5258 (point)))
5259 (window (get-buffer-window (current-buffer))))
5260 ;; The user has to want it.
5261 (when gnus-auto-center-summary
5262 (when (get-buffer-window gnus-article-buffer)
5263 ;; Only do recentering when the article buffer is displayed,
5264 ;; Set the window start to either `bottom', which is the biggest
5265 ;; possible valid number, or the second line from the top,
5266 ;; whichever is the least.
5267 (set-window-start
5268 window (min bottom (save-excursion
16409b0b
GM
5269 (forward-line (- top)) (point)))
5270 t))
eec82323
LMI
5271 ;; Do horizontal recentering while we're at it.
5272 (when (and (get-buffer-window (current-buffer) t)
5273 (not (eq gnus-auto-center-summary 'vertical)))
5274 (let ((selected (selected-window)))
5275 (select-window (get-buffer-window (current-buffer) t))
5276 (gnus-summary-position-point)
5277 (gnus-horizontal-recenter)
5278 (select-window selected))))))
5279
5280(defun gnus-summary-jump-to-group (newsgroup)
5281 "Move point to NEWSGROUP in group mode buffer."
5282 ;; Keep update point of group mode buffer if visible.
5283 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5284 (save-window-excursion
5285 ;; Take care of tree window mode.
5286 (when (get-buffer-window gnus-group-buffer)
5287 (pop-to-buffer gnus-group-buffer))
5288 (gnus-group-jump-to-group newsgroup))
5289 (save-excursion
5290 ;; Take care of tree window mode.
5291 (if (get-buffer-window gnus-group-buffer)
5292 (pop-to-buffer gnus-group-buffer)
5293 (set-buffer gnus-group-buffer))
5294 (gnus-group-jump-to-group newsgroup))))
5295
5296;; This function returns a list of article numbers based on the
5297;; difference between the ranges of read articles in this group and
5298;; the range of active articles.
5299(defun gnus-list-of-unread-articles (group)
5300 (let* ((read (gnus-info-read (gnus-get-info group)))
5301 (active (or (gnus-active group) (gnus-activate-group group)))
5302 (last (cdr active))
5303 first nlast unread)
5304 ;; If none are read, then all are unread.
5305 (if (not read)
5306 (setq first (car active))
5307 ;; If the range of read articles is a single range, then the
5308 ;; first unread article is the article after the last read
5309 ;; article. Sounds logical, doesn't it?
16409b0b
GM
5310 (if (and (not (listp (cdr read)))
5311 (or (< (car read) (car active))
5312 (progn (setq read (list read))
5313 nil)))
6748645f 5314 (setq first (max (car active) (1+ (cdr read))))
eec82323
LMI
5315 ;; `read' is a list of ranges.
5316 (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5317 (caar read)))
5318 1)
6748645f 5319 (setq first (car active)))
eec82323
LMI
5320 (while read
5321 (when first
5322 (while (< first nlast)
5323 (push first unread)
5324 (setq first (1+ first))))
5325 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5326 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5327 (setq read (cdr read)))))
5328 ;; And add the last unread articles.
5329 (while (<= first last)
5330 (push first unread)
5331 (setq first (1+ first)))
5332 ;; Return the list of unread articles.
6748645f 5333 (delq 0 (nreverse unread))))
eec82323
LMI
5334
5335(defun gnus-list-of-read-articles (group)
5336 "Return a list of unread, unticked and non-dormant articles."
5337 (let* ((info (gnus-get-info group))
5338 (marked (gnus-info-marks info))
5339 (active (gnus-active group)))
5340 (and info active
5341 (gnus-set-difference
5342 (gnus-sorted-complement
5343 (gnus-uncompress-range active)
5344 (gnus-list-of-unread-articles group))
5345 (append
5346 (gnus-uncompress-range (cdr (assq 'dormant marked)))
5347 (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5348
5349;; Various summary commands
5350
6748645f
LMI
5351(defun gnus-summary-select-article-buffer ()
5352 "Reconfigure windows to show article buffer."
5353 (interactive)
5354 (if (not (gnus-buffer-live-p gnus-article-buffer))
5355 (error "There is no article buffer for this summary buffer")
5356 (gnus-configure-windows 'article)
5357 (select-window (get-buffer-window gnus-article-buffer))))
5358
eec82323
LMI
5359(defun gnus-summary-universal-argument (arg)
5360 "Perform any operation on all articles that are process/prefixed."
5361 (interactive "P")
eec82323
LMI
5362 (let ((articles (gnus-summary-work-articles arg))
5363 func article)
5364 (if (eq
5365 (setq
5366 func
5367 (key-binding
5368 (read-key-sequence
5369 (substitute-command-keys
16409b0b 5370 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
eec82323
LMI
5371 'undefined)
5372 (gnus-error 1 "Undefined key")
5373 (save-excursion
5374 (while articles
5375 (gnus-summary-goto-subject (setq article (pop articles)))
5376 (let (gnus-newsgroup-processable)
5377 (command-execute func))
5378 (gnus-summary-remove-process-mark article)))))
5379 (gnus-summary-position-point))
5380
5381(defun gnus-summary-toggle-truncation (&optional arg)
5382 "Toggle truncation of summary lines.
5383With arg, turn line truncation on iff arg is positive."
5384 (interactive "P")
5385 (setq truncate-lines
5386 (if (null arg) (not truncate-lines)
5387 (> (prefix-numeric-value arg) 0)))
5388 (redraw-display))
5389
5390(defun gnus-summary-reselect-current-group (&optional all rescan)
5391 "Exit and then reselect the current newsgroup.
5392The prefix argument ALL means to select all articles."
5393 (interactive "P")
eec82323
LMI
5394 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5395 (error "Ephemeral groups can't be reselected"))
5396 (let ((current-subject (gnus-summary-article-number))
5397 (group gnus-newsgroup-name))
5398 (setq gnus-newsgroup-begin nil)
5399 (gnus-summary-exit)
5400 ;; We have to adjust the point of group mode buffer because
5401 ;; point was moved to the next unread newsgroup by exiting.
5402 (gnus-summary-jump-to-group group)
5403 (when rescan
5404 (save-excursion
5405 (gnus-group-get-new-news-this-group 1)))
5406 (gnus-group-read-group all t)
5407 (gnus-summary-goto-subject current-subject nil t)))
5408
5409(defun gnus-summary-rescan-group (&optional all)
5410 "Exit the newsgroup, ask for new articles, and select the newsgroup."
5411 (interactive "P")
5412 (gnus-summary-reselect-current-group all t))
5413
5414(defun gnus-summary-update-info (&optional non-destructive)
5415 (save-excursion
5416 (let ((group gnus-newsgroup-name))
6748645f
LMI
5417 (when group
5418 (when gnus-newsgroup-kill-headers
5419 (setq gnus-newsgroup-killed
5420 (gnus-compress-sequence
5421 (nconc
5422 (gnus-set-sorted-intersection
5423 (gnus-uncompress-range gnus-newsgroup-killed)
5424 (setq gnus-newsgroup-unselected
5425 (sort gnus-newsgroup-unselected '<)))
5426 (setq gnus-newsgroup-unreads
5427 (sort gnus-newsgroup-unreads '<)))
5428 t)))
5429 (unless (listp (cdr gnus-newsgroup-killed))
5430 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5431 (let ((headers gnus-newsgroup-headers))
5432 ;; Set the new ranges of read articles.
5433 (save-excursion
5434 (set-buffer gnus-group-buffer)
5435 (gnus-undo-force-boundary))
5436 (gnus-update-read-articles
5437 group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5438 ;; Set the current article marks.
5439 (let ((gnus-newsgroup-scored
5440 (if (and (not gnus-save-score)
5441 (not non-destructive))
5442 nil
5443 gnus-newsgroup-scored)))
5444 (save-excursion
5445 (gnus-update-marks)))
5446 ;; Do the cross-ref thing.
5447 (when gnus-use-cross-reference
5448 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5449 ;; Do not switch windows but change the buffer to work.
a8151ef7 5450 (set-buffer gnus-group-buffer)
6748645f
LMI
5451 (unless (gnus-ephemeral-group-p group)
5452 (gnus-group-update-group group)))))))
eec82323
LMI
5453
5454(defun gnus-summary-save-newsrc (&optional force)
5455 "Save the current number of read/marked articles in the dribble buffer.
5456The dribble buffer will then be saved.
5457If FORCE (the prefix), also save the .newsrc file(s)."
5458 (interactive "P")
5459 (gnus-summary-update-info t)
5460 (if force
5461 (gnus-save-newsrc-file)
5462 (gnus-dribble-save)))
5463
5464(defun gnus-summary-exit (&optional temporary)
5465 "Exit reading current newsgroup, and then return to group selection mode.
16409b0b 5466`gnus-exit-group-hook' is called with no arguments if that value is non-nil."
eec82323
LMI
5467 (interactive)
5468 (gnus-set-global-variables)
16409b0b
GM
5469 (when (gnus-buffer-live-p gnus-article-buffer)
5470 (save-excursion
5471 (set-buffer gnus-article-buffer)
5472 (mm-destroy-parts gnus-article-mime-handles)
5473 ;; Set it to nil for safety reason.
5474 (setq gnus-article-mime-handle-alist nil)
5475 (setq gnus-article-mime-handles nil)))
eec82323 5476 (gnus-kill-save-kill-buffer)
6748645f 5477 (gnus-async-halt-prefetch)
eec82323
LMI
5478 (let* ((group gnus-newsgroup-name)
5479 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5480 (mode major-mode)
a8151ef7 5481 (group-point nil)
eec82323 5482 (buf (current-buffer)))
16409b0b
GM
5483 (unless quit-config
5484 ;; Do adaptive scoring, and possibly save score files.
5485 (when gnus-newsgroup-adaptive
5486 (gnus-score-adaptive))
5487 (when gnus-use-scoring
5488 (gnus-score-save)))
6748645f 5489 (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
eec82323
LMI
5490 ;; If we have several article buffers, we kill them at exit.
5491 (unless gnus-single-article-buffer
5492 (gnus-kill-buffer gnus-original-article-buffer)
5493 (setq gnus-article-current nil))
5494 (when gnus-use-cache
5495 (gnus-cache-possibly-remove-articles)
5496 (gnus-cache-save-buffers))
5497 (gnus-async-prefetch-remove-group group)
5498 (when gnus-suppress-duplicates
5499 (gnus-dup-enter-articles))
5500 (when gnus-use-trees
5501 (gnus-tree-close group))
16409b0b
GM
5502 (when gnus-use-cache
5503 (gnus-cache-write-active))
6748645f
LMI
5504 ;; Remove entries for this group.
5505 (nnmail-purge-split-history (gnus-group-real-name group))
eec82323
LMI
5506 ;; Make all changes in this group permanent.
5507 (unless quit-config
6748645f 5508 (gnus-run-hooks 'gnus-exit-group-hook)
16409b0b 5509 (gnus-summary-update-info))
eec82323
LMI
5510 (gnus-close-group group)
5511 ;; Make sure where we were, and go to next newsgroup.
5512 (set-buffer gnus-group-buffer)
5513 (unless quit-config
5514 (gnus-group-jump-to-group group))
6748645f
LMI
5515 (gnus-run-hooks 'gnus-summary-exit-hook)
5516 (unless (or quit-config
5517 ;; If this group has disappeared from the summary
5518 ;; buffer, don't skip forwards.
5519 (not (string= group (gnus-group-group-name))))
eec82323 5520 (gnus-group-next-unread-group 1))
a8151ef7 5521 (setq group-point (point))
eec82323
LMI
5522 (if temporary
5523 nil ;Nothing to do.
5524 ;; If we have several article buffers, we kill them at exit.
5525 (unless gnus-single-article-buffer
5526 (gnus-kill-buffer gnus-article-buffer)
5527 (gnus-kill-buffer gnus-original-article-buffer)
5528 (setq gnus-article-current nil))
5529 (set-buffer buf)
5530 (if (not gnus-kill-summary-on-exit)
5531 (gnus-deaden-summary)
5532 ;; We set all buffer-local variables to nil. It is unclear why
5533 ;; this is needed, but if we don't, buffer-local variables are
5534 ;; not garbage-collected, it seems. This would the lead to en
5535 ;; ever-growing Emacs.
5536 (gnus-summary-clear-local-variables)
5537 (when (get-buffer gnus-article-buffer)
5538 (bury-buffer gnus-article-buffer))
5539 ;; We clear the global counterparts of the buffer-local
5540 ;; variables as well, just to be on the safe side.
5541 (set-buffer gnus-group-buffer)
5542 (gnus-summary-clear-local-variables)
5543 ;; Return to group mode buffer.
5544 (when (eq mode 'gnus-summary-mode)
5545 (gnus-kill-buffer buf)))
5546 (setq gnus-current-select-method gnus-select-method)
5547 (pop-to-buffer gnus-group-buffer)
eec82323
LMI
5548 (if (not quit-config)
5549 (progn
a8151ef7 5550 (goto-char group-point)
eec82323
LMI
5551 (gnus-configure-windows 'group 'force))
5552 (gnus-handle-ephemeral-exit quit-config))
6748645f 5553 ;; Clear the current group name.
eec82323
LMI
5554 (unless quit-config
5555 (setq gnus-newsgroup-name nil)))))
5556
5557(defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5558(defun gnus-summary-exit-no-update (&optional no-questions)
5559 "Quit reading current newsgroup without updating read article info."
5560 (interactive)
eec82323
LMI
5561 (let* ((group gnus-newsgroup-name)
5562 (quit-config (gnus-group-quit-config group)))
5563 (when (or no-questions
5564 gnus-expert-user
5565 (gnus-y-or-n-p "Discard changes to this group and exit? "))
6748645f 5566 (gnus-async-halt-prefetch)
16409b0b
GM
5567 (mapcar 'funcall
5568 (delq 'gnus-summary-expire-articles
5569 (copy-sequence gnus-summary-prepare-exit-hook)))
5570 (when (gnus-buffer-live-p gnus-article-buffer)
5571 (save-excursion
5572 (set-buffer gnus-article-buffer)
5573 (mm-destroy-parts gnus-article-mime-handles)
5574 ;; Set it to nil for safety reason.
5575 (setq gnus-article-mime-handle-alist nil)
5576 (setq gnus-article-mime-handles nil)))
eec82323
LMI
5577 ;; If we have several article buffers, we kill them at exit.
5578 (unless gnus-single-article-buffer
5579 (gnus-kill-buffer gnus-article-buffer)
5580 (gnus-kill-buffer gnus-original-article-buffer)
5581 (setq gnus-article-current nil))
5582 (if (not gnus-kill-summary-on-exit)
5583 (gnus-deaden-summary)
5584 (gnus-close-group group)
5585 (gnus-summary-clear-local-variables)
5586 (set-buffer gnus-group-buffer)
5587 (gnus-summary-clear-local-variables)
5588 (when (get-buffer gnus-summary-buffer)
5589 (kill-buffer gnus-summary-buffer)))
5590 (unless gnus-single-article-buffer
5591 (setq gnus-article-current nil))
5592 (when gnus-use-trees
5593 (gnus-tree-close group))
5594 (gnus-async-prefetch-remove-group group)
5595 (when (get-buffer gnus-article-buffer)
5596 (bury-buffer gnus-article-buffer))
5597 ;; Return to the group buffer.
5598 (gnus-configure-windows 'group 'force)
5599 ;; Clear the current group name.
5600 (setq gnus-newsgroup-name nil)
5601 (when (equal (gnus-group-group-name) group)
5602 (gnus-group-next-unread-group 1))
5603 (when quit-config
5604 (gnus-handle-ephemeral-exit quit-config)))))
5605
5606(defun gnus-handle-ephemeral-exit (quit-config)
6748645f
LMI
5607 "Handle movement when leaving an ephemeral group.
5608The state which existed when entering the ephemeral is reset."
eec82323
LMI
5609 (if (not (buffer-name (car quit-config)))
5610 (gnus-configure-windows 'group 'force)
5611 (set-buffer (car quit-config))
5612 (cond ((eq major-mode 'gnus-summary-mode)
5613 (gnus-set-global-variables))
5614 ((eq major-mode 'gnus-article-mode)
5615 (save-excursion
5616 ;; The `gnus-summary-buffer' variable may point
5617 ;; to the old summary buffer when using a single
5618 ;; article buffer.
5619 (unless (gnus-buffer-live-p gnus-summary-buffer)
5620 (set-buffer gnus-group-buffer))
5621 (set-buffer gnus-summary-buffer)
5622 (gnus-set-global-variables))))
5623 (if (or (eq (cdr quit-config) 'article)
5624 (eq (cdr quit-config) 'pick))
5625 (progn
5626 ;; The current article may be from the ephemeral group
5627 ;; thus it is best that we reload this article
5628 (gnus-summary-show-article)
5629 (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5630 (gnus-configure-windows 'pick 'force)
5631 (gnus-configure-windows (cdr quit-config) 'force)))
5632 (gnus-configure-windows (cdr quit-config) 'force))
5633 (when (eq major-mode 'gnus-summary-mode)
5634 (gnus-summary-next-subject 1 nil t)
5635 (gnus-summary-recenter)
5636 (gnus-summary-position-point))))
5637
5638;;; Dead summaries.
5639
5640(defvar gnus-dead-summary-mode-map nil)
5641
5642(unless gnus-dead-summary-mode-map
5643 (setq gnus-dead-summary-mode-map (make-keymap))
5644 (suppress-keymap gnus-dead-summary-mode-map)
5645 (substitute-key-definition
5646 'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
a8151ef7 5647 (let ((keys '("\C-d" "\r" "\177" [delete])))
eec82323
LMI
5648 (while keys
5649 (define-key gnus-dead-summary-mode-map
5650 (pop keys) 'gnus-summary-wake-up-the-dead))))
5651
5652(defvar gnus-dead-summary-mode nil
5653 "Minor mode for Gnus summary buffers.")
5654
5655(defun gnus-dead-summary-mode (&optional arg)
5656 "Minor mode for Gnus summary buffers."
5657 (interactive "P")
5658 (when (eq major-mode 'gnus-summary-mode)
5659 (make-local-variable 'gnus-dead-summary-mode)
5660 (setq gnus-dead-summary-mode
5661 (if (null arg) (not gnus-dead-summary-mode)
5662 (> (prefix-numeric-value arg) 0)))
5663 (when gnus-dead-summary-mode
a8151ef7
LMI
5664 (gnus-add-minor-mode
5665 'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
eec82323
LMI
5666
5667(defun gnus-deaden-summary ()
5668 "Make the current summary buffer into a dead summary buffer."
5669 ;; Kill any previous dead summary buffer.
5670 (when (and gnus-dead-summary
5671 (buffer-name gnus-dead-summary))
5672 (save-excursion
5673 (set-buffer gnus-dead-summary)
5674 (when gnus-dead-summary-mode
5675 (kill-buffer (current-buffer)))))
5676 ;; Make this the current dead summary.
5677 (setq gnus-dead-summary (current-buffer))
5678 (gnus-dead-summary-mode 1)
5679 (let ((name (buffer-name)))
5680 (when (string-match "Summary" name)
5681 (rename-buffer
5682 (concat (substring name 0 (match-beginning 0)) "Dead "
5683 (substring name (match-beginning 0)))
16409b0b
GM
5684 t)
5685 (bury-buffer))))
eec82323
LMI
5686
5687(defun gnus-kill-or-deaden-summary (buffer)
5688 "Kill or deaden the summary BUFFER."
6748645f
LMI
5689 (save-excursion
5690 (when (and (buffer-name buffer)
5691 (not gnus-single-article-buffer))
5692 (save-excursion
5693 (set-buffer buffer)
5694 (gnus-kill-buffer gnus-article-buffer)
5695 (gnus-kill-buffer gnus-original-article-buffer)))
5696 (cond (gnus-kill-summary-on-exit
5697 (when (and gnus-use-trees
5698 (gnus-buffer-exists-p buffer))
5699 (save-excursion
5700 (set-buffer buffer)
5701 (gnus-tree-close gnus-newsgroup-name)))
5702 (gnus-kill-buffer buffer))
5703 ((gnus-buffer-exists-p buffer)
eec82323 5704 (save-excursion
6748645f
LMI
5705 (set-buffer buffer)
5706 (gnus-deaden-summary))))))
eec82323
LMI
5707
5708(defun gnus-summary-wake-up-the-dead (&rest args)
5709 "Wake up the dead summary buffer."
5710 (interactive)
5711 (gnus-dead-summary-mode -1)
5712 (let ((name (buffer-name)))
5713 (when (string-match "Dead " name)
5714 (rename-buffer
5715 (concat (substring name 0 (match-beginning 0))
5716 (substring name (match-end 0)))
5717 t)))
5718 (gnus-message 3 "This dead summary is now alive again"))
5719
5720;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5721(defun gnus-summary-fetch-faq (&optional faq-dir)
5722 "Fetch the FAQ for the current group.
5723If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5724in."
5725 (interactive
5726 (list
5727 (when current-prefix-arg
5728 (completing-read
5729 "Faq dir: " (and (listp gnus-group-faq-directory)
a8151ef7
LMI
5730 (mapcar (lambda (file) (list file))
5731 gnus-group-faq-directory))))))
eec82323
LMI
5732 (let (gnus-faq-buffer)
5733 (when (setq gnus-faq-buffer
5734 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5735 (gnus-configure-windows 'summary-faq))))
5736
5737;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5738(defun gnus-summary-describe-group (&optional force)
5739 "Describe the current newsgroup."
5740 (interactive "P")
5741 (gnus-group-describe-group force gnus-newsgroup-name))
5742
5743(defun gnus-summary-describe-briefly ()
5744 "Describe summary mode commands briefly."
5745 (interactive)
16409b0b 5746 (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
5747
5748;; Walking around group mode buffer from summary mode.
5749
5750(defun gnus-summary-next-group (&optional no-article target-group backward)
5751 "Exit current newsgroup and then select next unread newsgroup.
5752If prefix argument NO-ARTICLE is non-nil, no article is selected
5753initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
5754previous group instead."
5755 (interactive "P")
eec82323
LMI
5756 ;; Stop pre-fetching.
5757 (gnus-async-halt-prefetch)
5758 (let ((current-group gnus-newsgroup-name)
5759 (current-buffer (current-buffer))
5760 entered)
5761 ;; First we semi-exit this group to update Xrefs and all variables.
5762 ;; We can't do a real exit, because the window conf must remain
5763 ;; the same in case the user is prompted for info, and we don't
5764 ;; want the window conf to change before that...
5765 (gnus-summary-exit t)
5766 (while (not entered)
5767 ;; Then we find what group we are supposed to enter.
5768 (set-buffer gnus-group-buffer)
5769 (gnus-group-jump-to-group current-group)
5770 (setq target-group
5771 (or target-group
5772 (if (eq gnus-keep-same-level 'best)
5773 (gnus-summary-best-group gnus-newsgroup-name)
5774 (gnus-summary-search-group backward gnus-keep-same-level))))
5775 (if (not target-group)
5776 ;; There are no further groups, so we return to the group
5777 ;; buffer.
5778 (progn
5779 (gnus-message 5 "Returning to the group buffer")
5780 (setq entered t)
5781 (when (gnus-buffer-live-p current-buffer)
5782 (set-buffer current-buffer)
5783 (gnus-summary-exit))
6748645f 5784 (gnus-run-hooks 'gnus-group-no-more-groups-hook))
eec82323
LMI
5785 ;; We try to enter the target group.
5786 (gnus-group-jump-to-group target-group)
5787 (let ((unreads (gnus-group-group-unread)))
5788 (if (and (or (eq t unreads)
5789 (and unreads (not (zerop unreads))))
5790 (gnus-summary-read-group
a8151ef7 5791 target-group nil no-article
6748645f
LMI
5792 (and (buffer-name current-buffer) current-buffer)
5793 nil backward))
eec82323
LMI
5794 (setq entered t)
5795 (setq current-group target-group
5796 target-group nil)))))))
5797
5798(defun gnus-summary-prev-group (&optional no-article)
5799 "Exit current newsgroup and then select previous unread newsgroup.
5800If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5801 (interactive "P")
5802 (gnus-summary-next-group no-article nil t))
5803
5804;; Walking around summary lines.
5805
6748645f 5806(defun gnus-summary-first-subject (&optional unread undownloaded)
eec82323
LMI
5807 "Go to the first unread subject.
5808If UNREAD is non-nil, go to the first unread article.
5809Returns the article selected or nil if there are no unread articles."
5810 (interactive "P")
5811 (prog1
5812 (cond
5813 ;; Empty summary.
5814 ((null gnus-newsgroup-data)
5815 (gnus-message 3 "No articles in the group")
5816 nil)
5817 ;; Pick the first article.
5818 ((not unread)
5819 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5820 (gnus-data-number (car gnus-newsgroup-data)))
5821 ;; No unread articles.
5822 ((null gnus-newsgroup-unreads)
5823 (gnus-message 3 "No more unread articles")
5824 nil)
5825 ;; Find the first unread article.
5826 (t
5827 (let ((data gnus-newsgroup-data))
5828 (while (and data
6748645f
LMI
5829 (and (not (and undownloaded
5830 (eq gnus-undownloaded-mark
5831 (gnus-data-mark (car data)))))
5832 (not (gnus-data-unread-p (car data)))))
eec82323
LMI
5833 (setq data (cdr data)))
5834 (when data
5835 (goto-char (gnus-data-pos (car data)))
5836 (gnus-data-number (car data))))))
5837 (gnus-summary-position-point)))
5838
5839(defun gnus-summary-next-subject (n &optional unread dont-display)
5840 "Go to next N'th summary line.
5841If N is negative, go to the previous N'th subject line.
5842If UNREAD is non-nil, only unread articles are selected.
5843The difference between N and the actual number of steps taken is
5844returned."
5845 (interactive "p")
5846 (let ((backward (< n 0))
5847 (n (abs n)))
5848 (while (and (> n 0)
5849 (if backward
5850 (gnus-summary-find-prev unread)
5851 (gnus-summary-find-next unread)))
16409b0b
GM
5852 (unless (zerop (setq n (1- n)))
5853 (gnus-summary-show-thread)))
eec82323
LMI
5854 (when (/= 0 n)
5855 (gnus-message 7 "No more%s articles"
5856 (if unread " unread" "")))
5857 (unless dont-display
5858 (gnus-summary-recenter)
5859 (gnus-summary-position-point))
5860 n))
5861
5862(defun gnus-summary-next-unread-subject (n)
5863 "Go to next N'th unread summary line."
5864 (interactive "p")
5865 (gnus-summary-next-subject n t))
5866
5867(defun gnus-summary-prev-subject (n &optional unread)
5868 "Go to previous N'th summary line.
5869If optional argument UNREAD is non-nil, only unread article is selected."
5870 (interactive "p")
5871 (gnus-summary-next-subject (- n) unread))
5872
5873(defun gnus-summary-prev-unread-subject (n)
5874 "Go to previous N'th unread summary line."
5875 (interactive "p")
5876 (gnus-summary-next-subject (- n) t))
5877
5878(defun gnus-summary-goto-subject (article &optional force silent)
5879 "Go the subject line of ARTICLE.
5880If FORCE, also allow jumping to articles not currently shown."
5881 (interactive "nArticle number: ")
5882 (let ((b (point))
5883 (data (gnus-data-find article)))
5884 ;; We read in the article if we have to.
5885 (and (not data)
5886 force
6748645f
LMI
5887 (gnus-summary-insert-subject
5888 article
5889 (if (or (numberp force) (vectorp force)) force)
5890 t)
eec82323
LMI
5891 (setq data (gnus-data-find article)))
5892 (goto-char b)
5893 (if (not data)
5894 (progn
5895 (unless silent
5896 (gnus-message 3 "Can't find article %d" article))
5897 nil)
5898 (goto-char (gnus-data-pos data))
6748645f 5899 (gnus-summary-position-point)
eec82323
LMI
5900 article)))
5901
5902;; Walking around summary lines with displaying articles.
5903
5904(defun gnus-summary-expand-window (&optional arg)
5905 "Make the summary buffer take up the entire Emacs frame.
5906Given a prefix, will force an `article' buffer configuration."
5907 (interactive "P")
eec82323
LMI
5908 (if arg
5909 (gnus-configure-windows 'article 'force)
5910 (gnus-configure-windows 'summary 'force)))
5911
5912(defun gnus-summary-display-article (article &optional all-header)
5913 "Display ARTICLE in article buffer."
d4dfaa19
DL
5914 (when (gnus-buffer-live-p gnus-article-buffer)
5915 (with-current-buffer gnus-article-buffer
5916 (mm-enable-multibyte-mule4)))
eec82323
LMI
5917 (gnus-set-global-variables)
5918 (if (null article)
5919 nil
5920 (prog1
5921 (if gnus-summary-display-article-function
5922 (funcall gnus-summary-display-article-function article all-header)
5923 (gnus-article-prepare article all-header))
6748645f 5924 (gnus-run-hooks 'gnus-select-article-hook)
eec82323
LMI
5925 (when (and gnus-current-article
5926 (not (zerop gnus-current-article)))
5927 (gnus-summary-goto-subject gnus-current-article))
5928 (gnus-summary-recenter)
5929 (when (and gnus-use-trees gnus-show-threads)
5930 (gnus-possibly-generate-tree article)
5931 (gnus-highlight-selected-tree article))
5932 ;; Successfully display article.
5933 (gnus-article-set-window-start
5934 (cdr (assq article gnus-newsgroup-bookmarks))))))
5935
5936(defun gnus-summary-select-article (&optional all-headers force pseudo article)
5937 "Select the current article.
5938If ALL-HEADERS is non-nil, show all header fields. If FORCE is
5939non-nil, the article will be re-fetched even if it already present in
5940the article buffer. If PSEUDO is non-nil, pseudo-articles will also
5941be displayed."
5942 ;; Make sure we are in the summary buffer to work around bbdb bug.
5943 (unless (eq major-mode 'gnus-summary-mode)
5944 (set-buffer gnus-summary-buffer))
5945 (let ((article (or article (gnus-summary-article-number)))
5946 (all-headers (not (not all-headers))) ;Must be T or NIL.
16409b0b 5947 gnus-summary-display-article-function)
eec82323
LMI
5948 (and (not pseudo)
5949 (gnus-summary-article-pseudo-p article)
a8151ef7 5950 (error "This is a pseudo-article"))
16409b0b
GM
5951 (save-excursion
5952 (set-buffer gnus-summary-buffer)
5953 (if (or (and gnus-single-article-buffer
5954 (or (null gnus-current-article)
5955 (null gnus-article-current)
5956 (null (get-buffer gnus-article-buffer))
5957 (not (eq article (cdr gnus-article-current)))
5958 (not (equal (car gnus-article-current)
5959 gnus-newsgroup-name))))
5960 (and (not gnus-single-article-buffer)
5961 (or (null gnus-current-article)
5962 (not (eq gnus-current-article article))))
5963 force)
5964 ;; The requested article is different from the current article.
5965 (progn
16409b0b
GM
5966 (gnus-summary-display-article article all-headers)
5967 (when (gnus-buffer-live-p gnus-article-buffer)
d4dfaa19 5968 (with-current-buffer gnus-article-buffer
16409b0b 5969 (if (not gnus-article-decoded-p) ;; a local variable
d4dfaa19 5970 (mm-disable-multibyte-mule4))))
eec82323
LMI
5971 (when (or all-headers gnus-show-all-headers)
5972 (gnus-article-show-all-headers))
16409b0b
GM
5973 (gnus-article-set-window-start
5974 (cdr (assq article gnus-newsgroup-bookmarks)))
5975 article)
5976 (when (or all-headers gnus-show-all-headers)
5977 (gnus-article-show-all-headers))
5978 'old))))
eec82323
LMI
5979
5980(defun gnus-summary-set-current-mark (&optional current-mark)
5981 "Obsolete function."
5982 nil)
5983
5984(defun gnus-summary-next-article (&optional unread subject backward push)
5985 "Select the next article.
5986If UNREAD, only unread articles are selected.
5987If SUBJECT, only articles with SUBJECT are selected.
5988If BACKWARD, the previous article is selected instead of the next."
5989 (interactive "P")
eec82323
LMI
5990 (cond
5991 ;; Is there such an article?
5992 ((and (gnus-summary-search-forward unread subject backward)
5993 (or (gnus-summary-display-article (gnus-summary-article-number))
5994 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
5995 (gnus-summary-position-point))
5996 ;; If not, we try the first unread, if that is wanted.
5997 ((and subject
5998 gnus-auto-select-same
5999 (gnus-summary-first-unread-article))
6000 (gnus-summary-position-point)
6001 (gnus-message 6 "Wrapped"))
6002 ;; Try to get next/previous article not displayed in this group.
6003 ((and gnus-auto-extend-newsgroup
6004 (not unread) (not subject))
6005 (gnus-summary-goto-article
6006 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748645f 6007 nil (count-lines (point-min) (point))))
eec82323
LMI
6008 ;; Go to next/previous group.
6009 (t
6010 (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6011 (gnus-summary-jump-to-group gnus-newsgroup-name))
6012 (let ((cmd last-command-char)
6013 (point
6014 (save-excursion
6015 (set-buffer gnus-group-buffer)
6016 (point)))
6017 (group
6018 (if (eq gnus-keep-same-level 'best)
6019 (gnus-summary-best-group gnus-newsgroup-name)
6020 (gnus-summary-search-group backward gnus-keep-same-level))))
6021 ;; For some reason, the group window gets selected. We change
6022 ;; it back.
6023 (select-window (get-buffer-window (current-buffer)))
6024 ;; Select next unread newsgroup automagically.
6025 (cond
6026 ((or (not gnus-auto-select-next)
6027 (not cmd))
6028 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6029 ((or (eq gnus-auto-select-next 'quietly)
6030 (and (eq gnus-auto-select-next 'slightly-quietly)
6031 push)
6032 (and (eq gnus-auto-select-next 'almost-quietly)
6033 (gnus-summary-last-article-p)))
6034 ;; Select quietly.
6035 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6036 (gnus-summary-exit)
6037 (gnus-message 7 "No more%s articles (%s)..."
6038 (if unread " unread" "")
6039 (if group (concat "selecting " group)
6040 "exiting"))
6041 (gnus-summary-next-group nil group backward)))
6042 (t
6043 (when (gnus-key-press-event-p last-input-event)
6044 (gnus-summary-walk-group-buffer
6045 gnus-newsgroup-name cmd unread backward point))))))))
6046
6047(defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6048 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6049 (?\C-p (gnus-group-prev-unread-group 1))))
6050 (cursor-in-echo-area t)
6051 keve key group ended)
6052 (save-excursion
6053 (set-buffer gnus-group-buffer)
6054 (goto-char start)
6055 (setq group
6056 (if (eq gnus-keep-same-level 'best)
6057 (gnus-summary-best-group gnus-newsgroup-name)
6058 (gnus-summary-search-group backward gnus-keep-same-level))))
6059 (while (not ended)
6060 (gnus-message
6061 5 "No more%s articles%s" (if unread " unread" "")
6062 (if (and group
6063 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6064 (format " (Type %s for %s [%s])"
6065 (single-key-description cmd) group
6066 (car (gnus-gethash group gnus-newsrc-hashtb)))
6067 (format " (Type %s to exit %s)"
6068 (single-key-description cmd)
6069 gnus-newsgroup-name)))
6070 ;; Confirm auto selection.
6071 (setq key (car (setq keve (gnus-read-event-char))))
6072 (setq ended t)
6073 (cond
6074 ((assq key keystrokes)
6075 (let ((obuf (current-buffer)))
6076 (switch-to-buffer gnus-group-buffer)
6077 (when group
6078 (gnus-group-jump-to-group group))
6079 (eval (cadr (assq key keystrokes)))
6080 (setq group (gnus-group-group-name))
6081 (switch-to-buffer obuf))
6082 (setq ended nil))
6083 ((equal key cmd)
6084 (if (or (not group)
6085 (gnus-ephemeral-group-p gnus-newsgroup-name))
6086 (gnus-summary-exit)
6087 (gnus-summary-next-group nil group backward)))
6088 (t
6089 (push (cdr keve) unread-command-events))))))
6090
6091(defun gnus-summary-next-unread-article ()
6092 "Select unread article after current one."
6093 (interactive)
6094 (gnus-summary-next-article
6095 (or (not (eq gnus-summary-goto-unread 'never))
6096 (gnus-summary-last-article-p (gnus-summary-article-number)))
6097 (and gnus-auto-select-same
6098 (gnus-summary-article-subject))))
6099
6100(defun gnus-summary-prev-article (&optional unread subject)
6101 "Select the article after the current one.
6102If UNREAD is non-nil, only unread articles are selected."
6103 (interactive "P")
6104 (gnus-summary-next-article unread subject t))
6105
6106(defun gnus-summary-prev-unread-article ()
6107 "Select unread article before current one."
6108 (interactive)
6109 (gnus-summary-prev-article
6110 (or (not (eq gnus-summary-goto-unread 'never))
6111 (gnus-summary-first-article-p (gnus-summary-article-number)))
6112 (and gnus-auto-select-same
6113 (gnus-summary-article-subject))))
6114
6115(defun gnus-summary-next-page (&optional lines circular)
6116 "Show next page of the selected article.
6117If at the end of the current article, select the next article.
6118LINES says how many lines should be scrolled up.
6119
6120If CIRCULAR is non-nil, go to the start of the article instead of
6121selecting the next article when reaching the end of the current
6122article."
6123 (interactive "P")
6124 (setq gnus-summary-buffer (current-buffer))
6125 (gnus-set-global-variables)
6126 (let ((article (gnus-summary-article-number))
6127 (article-window (get-buffer-window gnus-article-buffer t))
6128 endp)
6748645f
LMI
6129 ;; If the buffer is empty, we have no article.
6130 (unless article
6131 (error "No article to select"))
eec82323
LMI
6132 (gnus-configure-windows 'article)
6133 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6134 (if (and (eq gnus-summary-goto-unread 'never)
6135 (not (gnus-summary-last-article-p article)))
6136 (gnus-summary-next-article)
6137 (gnus-summary-next-unread-article))
6138 (if (or (null gnus-current-article)
6139 (null gnus-article-current)
6140 (/= article (cdr gnus-article-current))
6141 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6142 ;; Selected subject is different from current article's.
6143 (gnus-summary-display-article article)
6144 (when article-window
6145 (gnus-eval-in-buffer-window gnus-article-buffer
6146 (setq endp (gnus-article-next-page lines)))
6147 (when endp
6148 (cond (circular
6149 (gnus-summary-beginning-of-article))
6150 (lines
6151 (gnus-message 3 "End of message"))
6152 ((null lines)
6153 (if (and (eq gnus-summary-goto-unread 'never)
6154 (not (gnus-summary-last-article-p article)))
6155 (gnus-summary-next-article)
6156 (gnus-summary-next-unread-article))))))))
6157 (gnus-summary-recenter)
6158 (gnus-summary-position-point)))
6159
6160(defun gnus-summary-prev-page (&optional lines move)
6161 "Show previous page of selected article.
6162Argument LINES specifies lines to be scrolled down.
6163If MOVE, move to the previous unread article if point is at
6164the beginning of the buffer."
6165 (interactive "P")
eec82323
LMI
6166 (let ((article (gnus-summary-article-number))
6167 (article-window (get-buffer-window gnus-article-buffer t))
6168 endp)
6169 (gnus-configure-windows 'article)
6170 (if (or (null gnus-current-article)
6171 (null gnus-article-current)
6172 (/= article (cdr gnus-article-current))
6173 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6174 ;; Selected subject is different from current article's.
6175 (gnus-summary-display-article article)
6176 (gnus-summary-recenter)
6177 (when article-window
6178 (gnus-eval-in-buffer-window gnus-article-buffer
6179 (setq endp (gnus-article-prev-page lines)))
6180 (when (and move endp)
6181 (cond (lines
6182 (gnus-message 3 "Beginning of message"))
6183 ((null lines)
6184 (if (and (eq gnus-summary-goto-unread 'never)
6185 (not (gnus-summary-first-article-p article)))
6186 (gnus-summary-prev-article)
6187 (gnus-summary-prev-unread-article))))))))
6188 (gnus-summary-position-point))
6189
6190(defun gnus-summary-prev-page-or-article (&optional lines)
6191 "Show previous page of selected article.
6192Argument LINES specifies lines to be scrolled down.
6193If at the beginning of the article, go to the next article."
6194 (interactive "P")
6195 (gnus-summary-prev-page lines t))
6196
6197(defun gnus-summary-scroll-up (lines)
6198 "Scroll up (or down) one line current article.
6199Argument LINES specifies lines to be scrolled up (or down if negative)."
6200 (interactive "p")
eec82323
LMI
6201 (gnus-configure-windows 'article)
6202 (gnus-summary-show-thread)
6203 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6204 (gnus-eval-in-buffer-window gnus-article-buffer
6205 (cond ((> lines 0)
6206 (when (gnus-article-next-page lines)
6207 (gnus-message 3 "End of message")))
6208 ((< lines 0)
6209 (gnus-article-prev-page (- lines))))))
6210 (gnus-summary-recenter)
6211 (gnus-summary-position-point))
6212
6748645f
LMI
6213(defun gnus-summary-scroll-down (lines)
6214 "Scroll down (or up) one line current article.
6215Argument LINES specifies lines to be scrolled down (or up if negative)."
6216 (interactive "p")
6217 (gnus-summary-scroll-up (- lines)))
6218
eec82323
LMI
6219(defun gnus-summary-next-same-subject ()
6220 "Select next article which has the same subject as current one."
6221 (interactive)
eec82323
LMI
6222 (gnus-summary-next-article nil (gnus-summary-article-subject)))
6223
6224(defun gnus-summary-prev-same-subject ()
6225 "Select previous article which has the same subject as current one."
6226 (interactive)
eec82323
LMI
6227 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6228
6229(defun gnus-summary-next-unread-same-subject ()
6230 "Select next unread article which has the same subject as current one."
6231 (interactive)
eec82323
LMI
6232 (gnus-summary-next-article t (gnus-summary-article-subject)))
6233
6234(defun gnus-summary-prev-unread-same-subject ()
6235 "Select previous unread article which has the same subject as current one."
6236 (interactive)
eec82323
LMI
6237 (gnus-summary-prev-article t (gnus-summary-article-subject)))
6238
6239(defun gnus-summary-first-unread-article ()
6240 "Select the first unread article.
6241Return nil if there are no unread articles."
6242 (interactive)
eec82323
LMI
6243 (prog1
6244 (when (gnus-summary-first-subject t)
6245 (gnus-summary-show-thread)
6246 (gnus-summary-first-subject t)
6247 (gnus-summary-display-article (gnus-summary-article-number)))
6248 (gnus-summary-position-point)))
6249
16409b0b
GM
6250(defun gnus-summary-first-unread-subject ()
6251 "Place the point on the subject line of the first unread article.
6252Return nil if there are no unread articles."
6253 (interactive)
6254 (prog1
6255 (when (gnus-summary-first-subject t)
6256 (gnus-summary-show-thread)
6257 (gnus-summary-first-subject t))
6258 (gnus-summary-position-point)))
6259
eec82323
LMI
6260(defun gnus-summary-first-article ()
6261 "Select the first article.
6262Return nil if there are no articles."
6263 (interactive)
eec82323
LMI
6264 (prog1
6265 (when (gnus-summary-first-subject)
16409b0b
GM
6266 (gnus-summary-show-thread)
6267 (gnus-summary-first-subject)
6268 (gnus-summary-display-article (gnus-summary-article-number)))
eec82323
LMI
6269 (gnus-summary-position-point)))
6270
6271(defun gnus-summary-best-unread-article ()
6272 "Select the unread article with the highest score."
6273 (interactive)
eec82323
LMI
6274 (let ((best -1000000)
6275 (data gnus-newsgroup-data)
6276 article score)
6277 (while data
6278 (and (gnus-data-unread-p (car data))
6279 (> (setq score
6280 (gnus-summary-article-score (gnus-data-number (car data))))
6281 best)
6282 (setq best score
6283 article (gnus-data-number (car data))))
6284 (setq data (cdr data)))
6285 (prog1
6286 (if article
6287 (gnus-summary-goto-article article)
6288 (error "No unread articles"))
6289 (gnus-summary-position-point))))
6290
6291(defun gnus-summary-last-subject ()
6292 "Go to the last displayed subject line in the group."
6293 (let ((article (gnus-data-number (car (gnus-data-list t)))))
6294 (when article
6295 (gnus-summary-goto-subject article))))
6296
6297(defun gnus-summary-goto-article (article &optional all-headers force)
6748645f
LMI
6298 "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6299If ALL-HEADERS is non-nil, no header lines are hidden.
6300If FORCE, go to the article even if it isn't displayed. If FORCE
6301is a number, it is the line the article is to be displayed on."
eec82323
LMI
6302 (interactive
6303 (list
6748645f
LMI
6304 (completing-read
6305 "Article number or Message-ID: "
6306 (mapcar (lambda (number) (list (int-to-string number)))
6307 gnus-newsgroup-limit))
eec82323
LMI
6308 current-prefix-arg
6309 t))
6310 (prog1
6748645f
LMI
6311 (if (and (stringp article)
6312 (string-match "@" article))
6313 (gnus-summary-refer-article article)
6314 (when (stringp article)
6315 (setq article (string-to-number article)))
6316 (if (gnus-summary-goto-subject article force)
6317 (gnus-summary-display-article article all-headers)
6318 (gnus-message 4 "Couldn't go to article %s" article) nil))
eec82323
LMI
6319 (gnus-summary-position-point)))
6320
6321(defun gnus-summary-goto-last-article ()
6322 "Go to the previously read article."
6323 (interactive)
6324 (prog1
6325 (when gnus-last-article
6748645f 6326 (gnus-summary-goto-article gnus-last-article nil t))
eec82323
LMI
6327 (gnus-summary-position-point)))
6328
6329(defun gnus-summary-pop-article (number)
6330 "Pop one article off the history and go to the previous.
6331NUMBER articles will be popped off."
6332 (interactive "p")
6333 (let (to)
6334 (setq gnus-newsgroup-history
6335 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6336 (if to
6748645f 6337 (gnus-summary-goto-article (car to) nil t)
eec82323
LMI
6338 (error "Article history empty")))
6339 (gnus-summary-position-point))
6340
6341;; Summary commands and functions for limiting the summary buffer.
6342
6343(defun gnus-summary-limit-to-articles (n)
6344 "Limit the summary buffer to the next N articles.
6345If not given a prefix, use the process marked articles instead."
6346 (interactive "P")
eec82323
LMI
6347 (prog1
6348 (let ((articles (gnus-summary-work-articles n)))
6349 (setq gnus-newsgroup-processable nil)
6350 (gnus-summary-limit articles))
6351 (gnus-summary-position-point)))
6352
6353(defun gnus-summary-pop-limit (&optional total)
6354 "Restore the previous limit.
6355If given a prefix, remove all limits."
6356 (interactive "P")
eec82323
LMI
6357 (when total
6358 (setq gnus-newsgroup-limits
6359 (list (mapcar (lambda (h) (mail-header-number h))
6360 gnus-newsgroup-headers))))
6361 (unless gnus-newsgroup-limits
6362 (error "No limit to pop"))
6363 (prog1
6364 (gnus-summary-limit nil 'pop)
6365 (gnus-summary-position-point)))
6366
6367(defun gnus-summary-limit-to-subject (subject &optional header)
6368 "Limit the summary buffer to articles that have subjects that match a regexp."
6369 (interactive "sLimit to subject (regexp): ")
6370 (unless header
6371 (setq header "subject"))
6372 (when (not (equal "" subject))
6373 (prog1
6374 (let ((articles (gnus-summary-find-matching
6375 (or header "subject") subject 'all)))
6376 (unless articles
6377 (error "Found no matches for \"%s\"" subject))
6378 (gnus-summary-limit articles))
6379 (gnus-summary-position-point))))
6380
6381(defun gnus-summary-limit-to-author (from)
6382 "Limit the summary buffer to articles that have authors that match a regexp."
6383 (interactive "sLimit to author (regexp): ")
6384 (gnus-summary-limit-to-subject from "from"))
6385
6386(defun gnus-summary-limit-to-age (age &optional younger-p)
6387 "Limit the summary buffer to articles that are older than (or equal) AGE days.
6388If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6389articles that are younger than AGE days."
16409b0b
GM
6390 (interactive
6391 (let ((younger current-prefix-arg)
6392 (days-got nil)
6393 days)
6394 (while (not days-got)
6395 (setq days (if younger
6396 (read-string "Limit to articles within (in days): ")
6397 (read-string "Limit to articles old than (in days): ")))
6398 (when (> (length days) 0)
6399 (setq days (read days)))
6400 (if (numberp days)
6401 (setq days-got t)
6402 (message "Please enter a number.")
6403 (sleep-for 1)))
6404 (list days younger)))
eec82323
LMI
6405 (prog1
6406 (let ((data gnus-newsgroup-data)
16409b0b 6407 (cutoff (days-to-time age))
eec82323
LMI
6408 articles d date is-younger)
6409 (while (setq d (pop data))
6410 (when (and (vectorp (gnus-data-header d))
6411 (setq date (mail-header-date (gnus-data-header d))))
16409b0b
GM
6412 (setq is-younger (time-less-p
6413 (time-since (condition-case ()
6414 (date-to-time date)
6415 (error '(0 0))))
eec82323 6416 cutoff))
6748645f
LMI
6417 (when (if younger-p
6418 is-younger
6419 (not is-younger))
eec82323
LMI
6420 (push (gnus-data-number d) articles))))
6421 (gnus-summary-limit (nreverse articles)))
6422 (gnus-summary-position-point)))
6423
16409b0b
GM
6424(defun gnus-summary-limit-to-extra (header regexp)
6425 "Limit the summary buffer to articles that match an 'extra' header."
6426 (interactive
6427 (let ((header
6428 (intern
6429 (gnus-completing-read
6430 (symbol-name (car gnus-extra-headers))
6431 "Limit extra header:"
6432 (mapcar (lambda (x)
6433 (cons (symbol-name x) x))
6434 gnus-extra-headers)
6435 nil
6436 t))))
6437 (list header
6438 (read-string (format "Limit to header %s (regexp): " header)))))
6439 (when (not (equal "" regexp))
6440 (prog1
6441 (let ((articles (gnus-summary-find-matching
6442 (cons 'extra header) regexp 'all)))
6443 (unless articles
6444 (error "Found no matches for \"%s\"" regexp))
6445 (gnus-summary-limit articles))
6446 (gnus-summary-position-point))))
6447
eec82323
LMI
6448(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6449(make-obsolete
6450 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6451
6452(defun gnus-summary-limit-to-unread (&optional all)
6453 "Limit the summary buffer to articles that are not marked as read.
6454If ALL is non-nil, limit strictly to unread articles."
6455 (interactive "P")
6456 (if all
6457 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6458 (gnus-summary-limit-to-marks
6459 ;; Concat all the marks that say that an article is read and have
6460 ;; those removed.
6461 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6462 gnus-killed-mark gnus-kill-file-mark
6463 gnus-low-score-mark gnus-expirable-mark
6464 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6465 gnus-duplicate-mark gnus-souped-mark)
6466 'reverse)))
6467
6468(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6469(make-obsolete 'gnus-summary-delete-marked-with
6470 'gnus-summary-limit-exlude-marks)
6471
6472(defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6473 "Exclude articles that are marked with MARKS (e.g. \"DK\").
6474If REVERSE, limit the summary buffer to articles that are marked
6475with MARKS. MARKS can either be a string of marks or a list of marks.
6476Returns how many articles were removed."
6477 (interactive "sMarks: ")
6478 (gnus-summary-limit-to-marks marks t))
6479
6480(defun gnus-summary-limit-to-marks (marks &optional reverse)
6481 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6482If REVERSE (the prefix), limit the summary buffer to articles that are
6483not marked with MARKS. MARKS can either be a string of marks or a
6484list of marks.
6485Returns how many articles were removed."
6748645f 6486 (interactive "sMarks: \nP")
eec82323
LMI
6487 (prog1
6488 (let ((data gnus-newsgroup-data)
6489 (marks (if (listp marks) marks
6490 (append marks nil))) ; Transform to list.
6491 articles)
6492 (while data
6493 (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6494 (memq (gnus-data-mark (car data)) marks))
6495 (push (gnus-data-number (car data)) articles))
6496 (setq data (cdr data)))
6497 (gnus-summary-limit articles))
6498 (gnus-summary-position-point)))
6499
6500(defun gnus-summary-limit-to-score (&optional score)
6501 "Limit to articles with score at or above SCORE."
6502 (interactive "P")
eec82323
LMI
6503 (setq score (if score
6504 (prefix-numeric-value score)
6505 (or gnus-summary-default-score 0)))
6506 (let ((data gnus-newsgroup-data)
6507 articles)
6508 (while data
6509 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6510 score)
6511 (push (gnus-data-number (car data)) articles))
6512 (setq data (cdr data)))
6513 (prog1
6514 (gnus-summary-limit articles)
6515 (gnus-summary-position-point))))
6516
6748645f
LMI
6517(defun gnus-summary-limit-include-thread (id)
6518 "Display all the hidden articles that in the current thread."
6519 (interactive (list (mail-header-id (gnus-summary-article-header))))
6520 (let ((articles (gnus-articles-in-thread
6521 (gnus-id-to-thread (gnus-root-id id)))))
6522 (prog1
6523 (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6524 (gnus-summary-position-point))))
6525
eec82323 6526(defun gnus-summary-limit-include-dormant ()
6748645f
LMI
6527 "Display all the hidden articles that are marked as dormant.
6528Note that this command only works on a subset of the articles currently
6529fetched for this group."
eec82323 6530 (interactive)
eec82323
LMI
6531 (unless gnus-newsgroup-dormant
6532 (error "There are no dormant articles in this group"))
6533 (prog1
6534 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6535 (gnus-summary-position-point)))
6536
6537(defun gnus-summary-limit-exclude-dormant ()
6538 "Hide all dormant articles."
6539 (interactive)
eec82323
LMI
6540 (prog1
6541 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6542 (gnus-summary-position-point)))
6543
6544(defun gnus-summary-limit-exclude-childless-dormant ()
6545 "Hide all dormant articles that have no children."
6546 (interactive)
eec82323
LMI
6547 (let ((data (gnus-data-list t))
6548 articles d children)
6549 ;; Find all articles that are either not dormant or have
6550 ;; children.
6551 (while (setq d (pop data))
6552 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6553 (and (setq children
6554 (gnus-article-children (gnus-data-number d)))
6555 (let (found)
6556 (while children
6557 (when (memq (car children) articles)
6558 (setq children nil
6559 found t))
6560 (pop children))
6561 found)))
6562 (push (gnus-data-number d) articles)))
6563 ;; Do the limiting.
6564 (prog1
6565 (gnus-summary-limit articles)
6566 (gnus-summary-position-point))))
6567
6568(defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6569 "Mark all unread excluded articles as read.
6570If ALL, mark even excluded ticked and dormants as read."
6571 (interactive "P")
6572 (let ((articles (gnus-sorted-complement
6573 (sort
6574 (mapcar (lambda (h) (mail-header-number h))
6575 gnus-newsgroup-headers)
6576 '<)
6577 (sort gnus-newsgroup-limit '<)))
6578 article)
6748645f
LMI
6579 (setq gnus-newsgroup-unreads
6580 (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
eec82323
LMI
6581 (if all
6582 (setq gnus-newsgroup-dormant nil
6583 gnus-newsgroup-marked nil
6584 gnus-newsgroup-reads
6585 (nconc
6586 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6587 gnus-newsgroup-reads))
6588 (while (setq article (pop articles))
6589 (unless (or (memq article gnus-newsgroup-dormant)
6590 (memq article gnus-newsgroup-marked))
6591 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6592
6593(defun gnus-summary-limit (articles &optional pop)
6594 (if pop
6595 ;; We pop the previous limit off the stack and use that.
6596 (setq articles (car gnus-newsgroup-limits)
6597 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6598 ;; We use the new limit, so we push the old limit on the stack.
6599 (push gnus-newsgroup-limit gnus-newsgroup-limits))
6600 ;; Set the limit.
6601 (setq gnus-newsgroup-limit articles)
6602 (let ((total (length gnus-newsgroup-data))
6603 (data (gnus-data-find-list (gnus-summary-article-number)))
6604 (gnus-summary-mark-below nil) ; Inhibit this.
6605 found)
6606 ;; This will do all the work of generating the new summary buffer
6607 ;; according to the new limit.
6608 (gnus-summary-prepare)
6609 ;; Hide any threads, possibly.
6610 (and gnus-show-threads
6611 gnus-thread-hide-subtree
6612 (gnus-summary-hide-all-threads))
6613 ;; Try to return to the article you were at, or one in the
6614 ;; neighborhood.
6615 (when data
6616 ;; We try to find some article after the current one.
6617 (while data
6618 (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6619 (setq data nil
6620 found t))
6621 (setq data (cdr data))))
6622 (unless found
6623 ;; If there is no data, that means that we were after the last
6624 ;; article. The same goes when we can't find any articles
6625 ;; after the current one.
6626 (goto-char (point-max))
6627 (gnus-summary-find-prev))
6748645f 6628 (gnus-set-mode-line 'summary)
eec82323
LMI
6629 ;; We return how many articles were removed from the summary
6630 ;; buffer as a result of the new limit.
6631 (- total (length gnus-newsgroup-data))))
6632
6633(defsubst gnus-invisible-cut-children (threads)
6634 (let ((num 0))
6635 (while threads
6636 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6637 (incf num))
6638 (pop threads))
6639 (< num 2)))
6640
6641(defsubst gnus-cut-thread (thread)
6642 "Go forwards in the thread until we find an article that we want to display."
6643 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 6644 (eq gnus-fetch-old-headers 'invisible)
16409b0b 6645 (numberp gnus-fetch-old-headers)
eec82323
LMI
6646 (eq gnus-build-sparse-threads 'some)
6647 (eq gnus-build-sparse-threads 'more))
6648 ;; Deal with old-fetched headers and sparse threads.
6649 (while (and
6650 thread
6651 (or
6652 (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6653 (gnus-summary-article-ancient-p
6654 (mail-header-number (car thread))))
6748645f
LMI
6655 (if (or (<= (length (cdr thread)) 1)
6656 (eq gnus-fetch-old-headers 'invisible))
6657 (setq gnus-newsgroup-limit
6658 (delq (mail-header-number (car thread))
6659 gnus-newsgroup-limit)
6660 thread (cadr thread))
6661 (when (gnus-invisible-cut-children (cdr thread))
6662 (let ((th (cdr thread)))
6663 (while th
6664 (if (memq (mail-header-number (caar th))
a8151ef7 6665 gnus-newsgroup-limit)
6748645f
LMI
6666 (setq thread (car th)
6667 th nil)
6668 (setq th (cdr th))))))))))
eec82323
LMI
6669 thread)
6670
6671(defun gnus-cut-threads (threads)
6672 "Cut off all uninteresting articles from the beginning of threads."
6673 (when (or (eq gnus-fetch-old-headers 'some)
6748645f 6674 (eq gnus-fetch-old-headers 'invisible)
16409b0b 6675 (numberp gnus-fetch-old-headers)
eec82323
LMI
6676 (eq gnus-build-sparse-threads 'some)
6677 (eq gnus-build-sparse-threads 'more))
6678 (let ((th threads))
6679 (while th
6680 (setcar th (gnus-cut-thread (car th)))
6681 (setq th (cdr th)))))
6682 ;; Remove nixed out threads.
6683 (delq nil threads))
6684
6685(defun gnus-summary-initial-limit (&optional show-if-empty)
6686 "Figure out what the initial limit is supposed to be on group entry.
6687This entails weeding out unwanted dormants, low-scored articles,
6688fetch-old-headers verbiage, and so on."
6689 ;; Most groups have nothing to remove.
6690 (if (or gnus-inhibit-limiting
6691 (and (null gnus-newsgroup-dormant)
6692 (not (eq gnus-fetch-old-headers 'some))
16409b0b 6693 (not (numberp gnus-fetch-old-headers))
6748645f 6694 (not (eq gnus-fetch-old-headers 'invisible))
eec82323
LMI
6695 (null gnus-summary-expunge-below)
6696 (not (eq gnus-build-sparse-threads 'some))
6697 (not (eq gnus-build-sparse-threads 'more))
6698 (null gnus-thread-expunge-below)
6699 (not gnus-use-nocem)))
6700 () ; Do nothing.
6701 (push gnus-newsgroup-limit gnus-newsgroup-limits)
6702 (setq gnus-newsgroup-limit nil)
6703 (mapatoms
6704 (lambda (node)
6705 (unless (car (symbol-value node))
6706 ;; These threads have no parents -- they are roots.
6707 (let ((nodes (cdr (symbol-value node)))
6708 thread)
6709 (while nodes
6710 (if (and gnus-thread-expunge-below
6711 (< (gnus-thread-total-score (car nodes))
6712 gnus-thread-expunge-below))
6713 (gnus-expunge-thread (pop nodes))
6714 (setq thread (pop nodes))
6715 (gnus-summary-limit-children thread))))))
6716 gnus-newsgroup-dependencies)
6717 ;; If this limitation resulted in an empty group, we might
6718 ;; pop the previous limit and use it instead.
6719 (when (and (not gnus-newsgroup-limit)
6720 show-if-empty)
6721 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6722 gnus-newsgroup-limit))
6723
6724(defun gnus-summary-limit-children (thread)
6725 "Return 1 if this subthread is visible and 0 if it is not."
6726 ;; First we get the number of visible children to this thread. This
6727 ;; is done by recursing down the thread using this function, so this
6728 ;; will really go down to a leaf article first, before slowly
6729 ;; working its way up towards the root.
6730 (when thread
6731 (let ((children
6732 (if (cdr thread)
6733 (apply '+ (mapcar 'gnus-summary-limit-children
6734 (cdr thread)))
6735 0))
6736 (number (mail-header-number (car thread)))
6737 score)
6738 (if (and
6739 (not (memq number gnus-newsgroup-marked))
6740 (or
6741 ;; If this article is dormant and has absolutely no visible
6742 ;; children, then this article isn't visible.
6743 (and (memq number gnus-newsgroup-dormant)
6744 (zerop children))
6745 ;; If this is "fetch-old-headered" and there is no
6746 ;; visible children, then we don't want this article.
16409b0b
GM
6747 (and (or (eq gnus-fetch-old-headers 'some)
6748 (numberp gnus-fetch-old-headers))
eec82323
LMI
6749 (gnus-summary-article-ancient-p number)
6750 (zerop children))
6748645f
LMI
6751 ;; If this is "fetch-old-headered" and `invisible', then
6752 ;; we don't want this article.
6753 (and (eq gnus-fetch-old-headers 'invisible)
6754 (gnus-summary-article-ancient-p number))
eec82323
LMI
6755 ;; If this is a sparsely inserted article with no children,
6756 ;; we don't want it.
6757 (and (eq gnus-build-sparse-threads 'some)
6758 (gnus-summary-article-sparse-p number)
6759 (zerop children))
6760 ;; If we use expunging, and this article is really
6761 ;; low-scored, then we don't want this article.
6762 (when (and gnus-summary-expunge-below
6763 (< (setq score
6764 (or (cdr (assq number gnus-newsgroup-scored))
6765 gnus-summary-default-score))
6766 gnus-summary-expunge-below))
6767 ;; We increase the expunge-tally here, but that has
6768 ;; nothing to do with the limits, really.
6769 (incf gnus-newsgroup-expunged-tally)
6770 ;; We also mark as read here, if that's wanted.
6771 (when (and gnus-summary-mark-below
6772 (< score gnus-summary-mark-below))
6773 (setq gnus-newsgroup-unreads
6774 (delq number gnus-newsgroup-unreads))
6775 (if gnus-newsgroup-auto-expire
6776 (push number gnus-newsgroup-expirable)
6777 (push (cons number gnus-low-score-mark)
6778 gnus-newsgroup-reads)))
6779 t)
6780 ;; Check NoCeM things.
6781 (if (and gnus-use-nocem
6782 (gnus-nocem-unwanted-article-p
6783 (mail-header-id (car thread))))
6784 (progn
a8151ef7 6785 (setq gnus-newsgroup-unreads
eec82323
LMI
6786 (delq number gnus-newsgroup-unreads))
6787 t))))
6788 ;; Nope, invisible article.
6789 0
6790 ;; Ok, this article is to be visible, so we add it to the limit
6791 ;; and return 1.
6792 (push number gnus-newsgroup-limit)
6793 1))))
6794
6795(defun gnus-expunge-thread (thread)
6796 "Mark all articles in THREAD as read."
6797 (let* ((number (mail-header-number (car thread))))
6798 (incf gnus-newsgroup-expunged-tally)
6799 ;; We also mark as read here, if that's wanted.
6800 (setq gnus-newsgroup-unreads
6801 (delq number gnus-newsgroup-unreads))
6802 (if gnus-newsgroup-auto-expire
6803 (push number gnus-newsgroup-expirable)
6804 (push (cons number gnus-low-score-mark)
6805 gnus-newsgroup-reads)))
6806 ;; Go recursively through all subthreads.
6807 (mapcar 'gnus-expunge-thread (cdr thread)))
6808
6809;; Summary article oriented commands
6810
6811(defun gnus-summary-refer-parent-article (n)
6812 "Refer parent article N times.
6813If N is negative, go to ancestor -N instead.
6814The difference between N and the number of articles fetched is returned."
6815 (interactive "p")
eec82323
LMI
6816 (let ((skip 1)
6817 error header ref)
6818 (when (not (natnump n))
6819 (setq skip (abs n)
6820 n 1))
6821 (while (and (> n 0)
6822 (not error))
6823 (setq header (gnus-summary-article-header))
6824 (if (and (eq (mail-header-number header)
6825 (cdr gnus-article-current))
6826 (equal gnus-newsgroup-name
6827 (car gnus-article-current)))
6828 ;; If we try to find the parent of the currently
6829 ;; displayed article, then we take a look at the actual
6830 ;; References header, since this is slightly more
6831 ;; reliable than the References field we got from the
6832 ;; server.
6833 (save-excursion
6834 (set-buffer gnus-original-article-buffer)
6835 (nnheader-narrow-to-headers)
6836 (unless (setq ref (message-fetch-field "references"))
6837 (setq ref (message-fetch-field "in-reply-to")))
6838 (widen))
6839 (setq ref
6840 ;; It's not the current article, so we take a bet on
6841 ;; the value we got from the server.
6842 (mail-header-references header)))
6843 (if (and ref
6844 (not (equal ref "")))
6845 (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6846 (gnus-message 1 "Couldn't find parent"))
6847 (gnus-message 1 "No references in article %d"
6848 (gnus-summary-article-number))
6849 (setq error t))
6850 (decf n))
6851 (gnus-summary-position-point)
6852 n))
6853
6854(defun gnus-summary-refer-references ()
6855 "Fetch all articles mentioned in the References header.
6748645f 6856Return the number of articles fetched."
eec82323 6857 (interactive)
eec82323
LMI
6858 (let ((ref (mail-header-references (gnus-summary-article-header)))
6859 (current (gnus-summary-article-number))
6860 (n 0))
6861 (if (or (not ref)
6862 (equal ref ""))
6863 (error "No References in the current article")
6864 ;; For each Message-ID in the References header...
6865 (while (string-match "<[^>]*>" ref)
6866 (incf n)
6867 ;; ... fetch that article.
6868 (gnus-summary-refer-article
6869 (prog1 (match-string 0 ref)
6870 (setq ref (substring ref (match-end 0))))))
6871 (gnus-summary-goto-subject current)
6872 (gnus-summary-position-point)
6873 n)))
6874
6748645f
LMI
6875(defun gnus-summary-refer-thread (&optional limit)
6876 "Fetch all articles in the current thread.
6877If LIMIT (the numerical prefix), fetch that many old headers instead
6878of what's specified by the `gnus-refer-thread-limit' variable."
6879 (interactive "P")
6880 (let ((id (mail-header-id (gnus-summary-article-header)))
6881 (limit (if limit (prefix-numeric-value limit)
6882 gnus-refer-thread-limit)))
6883 ;; We want to fetch LIMIT *old* headers, but we also have to
6884 ;; re-fetch all the headers in the current buffer, because many of
6885 ;; them may be undisplayed. So we adjust LIMIT.
6886 (when (numberp limit)
6887 (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
6888 (unless (eq gnus-fetch-old-headers 'invisible)
6889 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
6890 ;; Retrieve the headers and read them in.
6891 (if (eq (gnus-retrieve-headers
6892 (list gnus-newsgroup-end) gnus-newsgroup-name limit)
6893 'nov)
6894 (gnus-build-all-threads)
6895 (error "Can't fetch thread from backends that don't support NOV"))
6896 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
6897 (gnus-summary-limit-include-thread id)))
6898
16409b0b
GM
6899(defun gnus-summary-refer-article (message-id)
6900 "Fetch an article specified by MESSAGE-ID."
6901 (interactive "sMessage-ID: ")
eec82323
LMI
6902 (when (and (stringp message-id)
6903 (not (zerop (length message-id))))
6904 ;; Construct the correct Message-ID if necessary.
6905 ;; Suggested by tale@pawl.rpi.edu.
6906 (unless (string-match "^<" message-id)
6907 (setq message-id (concat "<" message-id)))
6908 (unless (string-match ">$" message-id)
6909 (setq message-id (concat message-id ">")))
6910 (let* ((header (gnus-id-to-header message-id))
6911 (sparse (and header
6912 (gnus-summary-article-sparse-p
a8151ef7
LMI
6913 (mail-header-number header))
6914 (memq (mail-header-number header)
16409b0b
GM
6915 gnus-newsgroup-limit)))
6916 number)
6748645f
LMI
6917 (cond
6918 ;; If the article is present in the buffer we just go to it.
6919 ((and header
6920 (or (not (gnus-summary-article-sparse-p
6921 (mail-header-number header)))
6922 sparse))
6923 (prog1
6924 (gnus-summary-goto-article
6925 (mail-header-number header) nil t)
6926 (when sparse
6927 (gnus-summary-update-article (mail-header-number header)))))
6928 (t
16409b0b
GM
6929 ;; We fetch the article.
6930 (catch 'found
6931 (dolist (gnus-override-method (gnus-refer-article-methods))
6932 (gnus-check-server gnus-override-method)
6933 ;; Fetch the header, and display the article.
6934 (when (setq number (gnus-summary-insert-subject message-id))
eec82323 6935 (gnus-summary-select-article nil nil nil number)
16409b0b
GM
6936 (throw 'found t)))
6937 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
6938
6939(defun gnus-refer-article-methods ()
6940 "Return a list of referrable methods."
6941 (cond
6942 ;; No method, so we default to current and native.
6943 ((null gnus-refer-article-method)
6944 (list gnus-current-select-method gnus-select-method))
6945 ;; Current.
6946 ((eq 'current gnus-refer-article-method)
6947 (list gnus-current-select-method))
6948 ;; List of select methods.
d4dfaa19
DL
6949 ((not (and (symbolp (car gnus-refer-article-method))
6950 (assq (car gnus-refer-article-method) nnoo-definition-alist)))
16409b0b
GM
6951 (let (out)
6952 (dolist (method gnus-refer-article-method)
6953 (push (if (eq 'current method)
6954 gnus-current-select-method
6955 method)
6956 out))
6957 (nreverse out)))
6958 ;; One single select method.
6959 (t
6960 (list gnus-refer-article-method))))
6748645f
LMI
6961
6962(defun gnus-summary-edit-parameters ()
6963 "Edit the group parameters of the current group."
6964 (interactive)
6965 (gnus-group-edit-group gnus-newsgroup-name 'params))
eec82323 6966
16409b0b
GM
6967(defun gnus-summary-customize-parameters ()
6968 "Customize the group parameters of the current group."
6969 (interactive)
6970 (gnus-group-customize gnus-newsgroup-name))
6971
eec82323
LMI
6972(defun gnus-summary-enter-digest-group (&optional force)
6973 "Enter an nndoc group based on the current article.
6974If FORCE, force a digest interpretation. If not, try
6975to guess what the document format is."
6976 (interactive "P")
eec82323
LMI
6977 (let ((conf gnus-current-window-configuration))
6978 (save-excursion
6979 (gnus-summary-select-article))
6980 (setq gnus-current-window-configuration conf)
6981 (let* ((name (format "%s-%d"
6982 (gnus-group-prefixed-name
6983 gnus-newsgroup-name (list 'nndoc ""))
6984 (save-excursion
6985 (set-buffer gnus-summary-buffer)
6986 gnus-current-article)))
6987 (ogroup gnus-newsgroup-name)
6988 (params (append (gnus-info-params (gnus-get-info ogroup))
6989 (list (cons 'to-group ogroup))
6990 (list (cons 'save-article-group ogroup))))
6991 (case-fold-search t)
6992 (buf (current-buffer))
16409b0b 6993 dig to-address)
eec82323 6994 (save-excursion
16409b0b
GM
6995 (set-buffer gnus-original-article-buffer)
6996 ;; Have the digest group inherit the main mail address of
6997 ;; the parent article.
6998 (when (setq to-address (or (message-fetch-field "reply-to")
6999 (message-fetch-field "from")))
d4dfaa19
DL
7000 (setq params (append
7001 (list (cons 'to-address
7002 (funcall gnus-decode-encoded-word-function
7003 to-address))))))
eec82323
LMI
7004 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7005 (insert-buffer-substring gnus-original-article-buffer)
7006 ;; Remove lines that may lead nndoc to misinterpret the
7007 ;; document type.
7008 (narrow-to-region
7009 (goto-char (point-min))
7010 (or (search-forward "\n\n" nil t) (point)))
7011 (goto-char (point-min))
16409b0b 7012 (delete-matching-lines "^Path:\\|^From ")
eec82323
LMI
7013 (widen))
7014 (unwind-protect
16409b0b
GM
7015 (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7016 (gnus-newsgroup-ephemeral-ignored-charsets
7017 gnus-newsgroup-ignored-charsets))
7018 (gnus-group-read-ephemeral-group
7019 name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7020 (nndoc-article-type
7021 ,(if force 'mbox 'guess))) t))
7022 ;; Make all postings to this group go to the parent group.
eec82323
LMI
7023 (nconc (gnus-info-params (gnus-get-info name))
7024 params)
7025 ;; Couldn't select this doc group.
7026 (switch-to-buffer buf)
7027 (gnus-set-global-variables)
7028 (gnus-configure-windows 'summary)
7029 (gnus-message 3 "Article couldn't be entered?"))
7030 (kill-buffer dig)))))
7031
7032(defun gnus-summary-read-document (n)
7033 "Open a new group based on the current article(s).
7034This will allow you to read digests and other similar
7035documents as newsgroups.
7036Obeys the standard process/prefix convention."
7037 (interactive "P")
7038 (let* ((articles (gnus-summary-work-articles n))
7039 (ogroup gnus-newsgroup-name)
7040 (params (append (gnus-info-params (gnus-get-info ogroup))
7041 (list (cons 'to-group ogroup))))
7042 article group egroup groups vgroup)
7043 (while (setq article (pop articles))
7044 (setq group (format "%s-%d" gnus-newsgroup-name article))
7045 (gnus-summary-remove-process-mark article)
7046 (when (gnus-summary-display-article article)
7047 (save-excursion
16409b0b 7048 (with-temp-buffer
eec82323
LMI
7049 (insert-buffer-substring gnus-original-article-buffer)
7050 ;; Remove some headers that may lead nndoc to make
7051 ;; the wrong guess.
7052 (message-narrow-to-head)
7053 (goto-char (point-min))
7054 (delete-matching-lines "^\\(Path\\):\\|^From ")
7055 (widen)
7056 (if (setq egroup
7057 (gnus-group-read-ephemeral-group
7058 group `(nndoc ,group (nndoc-address ,(current-buffer))
7059 (nndoc-article-type guess))
7060 t nil t))
7061 (progn
7062 ;; Make all postings to this group go to the parent group.
7063 (nconc (gnus-info-params (gnus-get-info egroup))
7064 params)
7065 (push egroup groups))
7066 ;; Couldn't select this doc group.
7067 (gnus-error 3 "Article couldn't be entered"))))))
7068 ;; Now we have selected all the documents.
7069 (cond
7070 ((not groups)
7071 (error "None of the articles could be interpreted as documents"))
7072 ((gnus-group-read-ephemeral-group
7073 (setq vgroup (format
7074 "nnvirtual:%s-%s" gnus-newsgroup-name
7075 (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7076 `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7077 t
7078 (cons (current-buffer) 'summary)))
7079 (t
7080 (error "Couldn't select virtual nndoc group")))))
7081
7082(defun gnus-summary-isearch-article (&optional regexp-p)
7083 "Do incremental search forward on the current article.
7084If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7085 (interactive "P")
eec82323
LMI
7086 (gnus-summary-select-article)
7087 (gnus-configure-windows 'article)
7088 (gnus-eval-in-buffer-window gnus-article-buffer
6748645f
LMI
7089 (save-restriction
7090 (widen)
7091 (isearch-forward regexp-p))))
eec82323
LMI
7092
7093(defun gnus-summary-search-article-forward (regexp &optional backward)
7094 "Search for an article containing REGEXP forward.
7095If BACKWARD, search backward instead."
7096 (interactive
7097 (list (read-string
7098 (format "Search article %s (regexp%s): "
7099 (if current-prefix-arg "backward" "forward")
7100 (if gnus-last-search-regexp
7101 (concat ", default " gnus-last-search-regexp)
7102 "")))
7103 current-prefix-arg))
eec82323
LMI
7104 (if (string-equal regexp "")
7105 (setq regexp (or gnus-last-search-regexp ""))
7106 (setq gnus-last-search-regexp regexp))
7107 (if (gnus-summary-search-article regexp backward)
7108 (gnus-summary-show-thread)
7109 (error "Search failed: \"%s\"" regexp)))
7110
7111(defun gnus-summary-search-article-backward (regexp)
7112 "Search for an article containing REGEXP backward."
7113 (interactive
7114 (list (read-string
7115 (format "Search article backward (regexp%s): "
7116 (if gnus-last-search-regexp
7117 (concat ", default " gnus-last-search-regexp)
7118 "")))))
7119 (gnus-summary-search-article-forward regexp 'backward))
7120
7121(defun gnus-summary-search-article (regexp &optional backward)
7122 "Search for an article containing REGEXP.
7123Optional argument BACKWARD means do search for backward.
7124`gnus-select-article-hook' is not called during the search."
a8151ef7
LMI
7125 ;; We have to require this here to make sure that the following
7126 ;; dynamic binding isn't shadowed by autoloading.
7127 (require 'gnus-async)
16409b0b 7128 (require 'gnus-art)
eec82323 7129 (let ((gnus-select-article-hook nil) ;Disable hook.
16409b0b 7130 (gnus-article-prepare-hook nil)
eec82323
LMI
7131 (gnus-mark-article-hook nil) ;Inhibit marking as read.
7132 (gnus-use-article-prefetch nil)
7133 (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
a8151ef7 7134 (gnus-use-trees nil) ;Inhibit updating tree buffer.
eec82323 7135 (sum (current-buffer))
16409b0b 7136 (gnus-display-mime-function nil)
eec82323
LMI
7137 (found nil)
7138 point)
7139 (gnus-save-hidden-threads
7140 (gnus-summary-select-article)
7141 (set-buffer gnus-article-buffer)
16409b0b 7142 (goto-char (window-point (get-buffer-window (current-buffer))))
eec82323
LMI
7143 (when backward
7144 (forward-line -1))
7145 (while (not found)
7146 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7147 (if (if backward
7148 (re-search-backward regexp nil t)
7149 (re-search-forward regexp nil t))
7150 ;; We found the regexp.
7151 (progn
7152 (setq found 'found)
7153 (beginning-of-line)
7154 (set-window-start
7155 (get-buffer-window (current-buffer))
7156 (point))
7157 (forward-line 1)
16409b0b
GM
7158 (set-window-point
7159 (get-buffer-window (current-buffer))
7160 (point))
eec82323
LMI
7161 (set-buffer sum)
7162 (setq point (point)))
7163 ;; We didn't find it, so we go to the next article.
7164 (set-buffer sum)
7165 (setq found 'not)
7166 (while (eq found 'not)
7167 (if (not (if backward (gnus-summary-find-prev)
7168 (gnus-summary-find-next)))
7169 ;; No more articles.
7170 (setq found t)
7171 ;; Select the next article and adjust point.
7172 (unless (gnus-summary-article-sparse-p
7173 (gnus-summary-article-number))
7174 (setq found nil)
7175 (gnus-summary-select-article)
7176 (set-buffer gnus-article-buffer)
7177 (widen)
7178 (goto-char (if backward (point-max) (point-min))))))))
7179 (gnus-message 7 ""))
7180 ;; Return whether we found the regexp.
7181 (when (eq found 'found)
7182 (goto-char point)
7183 (gnus-summary-show-thread)
7184 (gnus-summary-goto-subject gnus-current-article)
7185 (gnus-summary-position-point)
7186 t)))
7187
7188(defun gnus-summary-find-matching (header regexp &optional backward unread
7189 not-case-fold)
7190 "Return a list of all articles that match REGEXP on HEADER.
7191The search stars on the current article and goes forwards unless
7192BACKWARD is non-nil. If BACKWARD is `all', do all articles.
7193If UNREAD is non-nil, only unread articles will
7194be taken into consideration. If NOT-CASE-FOLD, case won't be folded
7195in the comparisons."
7196 (let ((data (if (eq backward 'all) gnus-newsgroup-data
7197 (gnus-data-find-list
7198 (gnus-summary-article-number) (gnus-data-list backward))))
eec82323 7199 (case-fold-search (not not-case-fold))
16409b0b
GM
7200 articles d func)
7201 (if (consp header)
7202 (if (eq (car header) 'extra)
7203 (setq func
7204 `(lambda (h)
7205 (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7206 "")))
7207 (error "%s is an invalid header" header))
7208 (unless (fboundp (intern (concat "mail-header-" header)))
7209 (error "%s is not a valid header" header))
7210 (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
eec82323
LMI
7211 (while data
7212 (setq d (car data))
7213 (and (or (not unread) ; We want all articles...
7214 (gnus-data-unread-p d)) ; Or just unreads.
7215 (vectorp (gnus-data-header d)) ; It's not a pseudo.
7216 (string-match regexp (funcall func (gnus-data-header d))) ; Match.
7217 (push (gnus-data-number d) articles)) ; Success!
7218 (setq data (cdr data)))
7219 (nreverse articles)))
7220
7221(defun gnus-summary-execute-command (header regexp command &optional backward)
7222 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7223If HEADER is an empty string (or nil), the match is done on the entire
7224article. If BACKWARD (the prefix) is non-nil, search backward instead."
7225 (interactive
7226 (list (let ((completion-ignore-case t))
7227 (completing-read
7228 "Header name: "
7229 (mapcar (lambda (string) (list string))
7230 '("Number" "Subject" "From" "Lines" "Date"
7231 "Message-ID" "Xref" "References" "Body"))
7232 nil 'require-match))
7233 (read-string "Regexp: ")
7234 (read-key-sequence "Command: ")
7235 current-prefix-arg))
7236 (when (equal header "Body")
7237 (setq header ""))
eec82323
LMI
7238 ;; Hidden thread subtrees must be searched as well.
7239 (gnus-summary-show-all-threads)
7240 ;; We don't want to change current point nor window configuration.
7241 (save-excursion
7242 (save-window-excursion
7243 (gnus-message 6 "Executing %s..." (key-description command))
7244 ;; We'd like to execute COMMAND interactively so as to give arguments.
7245 (gnus-execute header regexp
7246 `(call-interactively ',(key-binding command))
7247 backward)
7248 (gnus-message 6 "Executing %s...done" (key-description command)))))
7249
7250(defun gnus-summary-beginning-of-article ()
7251 "Scroll the article back to the beginning."
7252 (interactive)
eec82323
LMI
7253 (gnus-summary-select-article)
7254 (gnus-configure-windows 'article)
7255 (gnus-eval-in-buffer-window gnus-article-buffer
7256 (widen)
7257 (goto-char (point-min))
7258 (when gnus-page-broken
7259 (gnus-narrow-to-page))))
7260
7261(defun gnus-summary-end-of-article ()
7262 "Scroll to the end of the article."
7263 (interactive)
eec82323
LMI
7264 (gnus-summary-select-article)
7265 (gnus-configure-windows 'article)
7266 (gnus-eval-in-buffer-window gnus-article-buffer
7267 (widen)
7268 (goto-char (point-max))
7269 (recenter -3)
7270 (when gnus-page-broken
7271 (gnus-narrow-to-page))))
7272
6748645f
LMI
7273(defun gnus-summary-print-article (&optional filename n)
7274 "Generate and print a PostScript image of the N next (mail) articles.
7275
7276If N is negative, print the N previous articles. If N is nil and articles
7277have been marked with the process mark, print these instead.
eec82323 7278
16409b0b 7279If the optional first argument FILENAME is nil, send the image to the
6748645f
LMI
7280printer. If FILENAME is a string, save the PostScript image in a file with
7281that name. If FILENAME is a number, prompt the user for the name of the file
eec82323 7282to save in."
6748645f
LMI
7283 (interactive (list (ps-print-preprint current-prefix-arg)
7284 current-prefix-arg))
7285 (dolist (article (gnus-summary-work-articles n))
7286 (gnus-summary-select-article nil nil 'pseudo article)
7287 (gnus-eval-in-buffer-window gnus-article-buffer
7288 (let ((buffer (generate-new-buffer " *print*")))
7289 (unwind-protect
7290 (progn
7291 (copy-to-buffer buffer (point-min) (point-max))
7292 (set-buffer buffer)
7293 (gnus-article-delete-invisible-text)
7294 (let ((ps-left-header
7295 (list
7296 (concat "("
7297 (mail-header-subject gnus-current-headers) ")")
7298 (concat "("
7299 (mail-header-from gnus-current-headers) ")")))
7300 (ps-right-header
7301 (list
7302 "/pagenumberstring load"
7303 (concat "("
7304 (mail-header-date gnus-current-headers) ")"))))
7305 (gnus-run-hooks 'gnus-ps-print-hook)
7306 (save-excursion
7307 (ps-print-buffer-with-faces filename))))
7308 (kill-buffer buffer))))))
eec82323
LMI
7309
7310(defun gnus-summary-show-article (&optional arg)
7311 "Force re-fetching of the current article.
16409b0b
GM
7312If ARG (the prefix) is a number, show the article with the charset
7313defined in `gnus-summary-show-article-charset-alist', or the charset
7314inputed.
7315If ARG (the prefix) is non-nil and not a number, show the raw article
7316without any article massaging functions being run."
eec82323 7317 (interactive "P")
16409b0b
GM
7318 (cond
7319 ((numberp arg)
7320 (let ((gnus-newsgroup-charset
7321 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7322 (read-coding-system "Charset: ")))
7323 (gnus-newsgroup-ignored-charsets 'gnus-all))
7324 (gnus-summary-select-article nil 'force)))
7325 ((not arg)
7326 ;; Select the article the normal way.
7327 (gnus-summary-select-article nil 'force))
7328 (t
7329 ;; We have to require this here to make sure that the following
7330 ;; dynamic binding isn't shadowed by autoloading.
7331 (require 'gnus-async)
7332 (require 'gnus-art)
eec82323
LMI
7333 ;; Bind the article treatment functions to nil.
7334 (let ((gnus-have-all-headers t)
eec82323 7335 gnus-article-prepare-hook
16409b0b
GM
7336 gnus-article-decode-hook
7337 gnus-display-mime-function
7338 gnus-break-pages)
7339 ;; Destroy any MIME parts.
7340 (when (gnus-buffer-live-p gnus-article-buffer)
7341 (save-excursion
7342 (set-buffer gnus-article-buffer)
7343 (mm-destroy-parts gnus-article-mime-handles)
7344 ;; Set it to nil for safety reason.
7345 (setq gnus-article-mime-handle-alist nil)
7346 (setq gnus-article-mime-handles nil)))
7347 (gnus-summary-select-article nil 'force))))
eec82323
LMI
7348 (gnus-summary-goto-subject gnus-current-article)
7349 (gnus-summary-position-point))
7350
7351(defun gnus-summary-verbose-headers (&optional arg)
7352 "Toggle permanent full header display.
7353If ARG is a positive number, turn header display on.
7354If ARG is a negative number, turn header display off."
7355 (interactive "P")
eec82323
LMI
7356 (setq gnus-show-all-headers
7357 (cond ((or (not (numberp arg))
7358 (zerop arg))
7359 (not gnus-show-all-headers))
7360 ((natnump arg)
7361 t)))
7362 (gnus-summary-show-article))
7363
7364(defun gnus-summary-toggle-header (&optional arg)
7365 "Show the headers if they are hidden, or hide them if they are shown.
7366If ARG is a positive number, show the entire header.
7367If ARG is a negative number, hide the unwanted header lines."
7368 (interactive "P")
eec82323
LMI
7369 (save-excursion
7370 (set-buffer gnus-article-buffer)
16409b0b
GM
7371 (save-restriction
7372 (let* ((buffer-read-only nil)
7373 (inhibit-point-motion-hooks t)
7374 hidden e)
7375 (setq hidden
7376 (if (numberp arg)
7377 (>= arg 0)
7378 (save-restriction
7379 (article-narrow-to-head)
7380 (gnus-article-hidden-text-p 'headers))))
7381 (goto-char (point-min))
7382 (when (search-forward "\n\n" nil t)
7383 (delete-region (point-min) (1- (point))))
eec82323 7384 (goto-char (point-min))
16409b0b
GM
7385 (save-excursion
7386 (set-buffer gnus-original-article-buffer)
7387 (goto-char (point-min))
7388 (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7389 (insert-buffer-substring gnus-original-article-buffer 1 e)
7390 (save-restriction
7391 (narrow-to-region (point-min) (point))
7392 (article-decode-encoded-words)
7393 (if hidden
7394 (let ((gnus-treat-hide-headers nil)
7395 (gnus-treat-hide-boring-headers nil))
7396 (setq gnus-article-wash-types
7397 (delq 'headers gnus-article-wash-types))
7398 (gnus-treat-article 'head))
7399 (gnus-treat-article 'head)))
7400 (gnus-set-mode-line 'article)))))
eec82323
LMI
7401
7402(defun gnus-summary-show-all-headers ()
7403 "Make all header lines visible."
7404 (interactive)
eec82323
LMI
7405 (gnus-article-show-all-headers))
7406
eec82323
LMI
7407(defun gnus-summary-caesar-message (&optional arg)
7408 "Caesar rotate the current article by 13.
7409The numerical prefix specifies how many places to rotate each letter
7410forward."
7411 (interactive "P")
eec82323
LMI
7412 (gnus-summary-select-article)
7413 (let ((mail-header-separator ""))
7414 (gnus-eval-in-buffer-window gnus-article-buffer
7415 (save-restriction
7416 (widen)
7417 (let ((start (window-start))
7418 buffer-read-only)
7419 (message-caesar-buffer-body arg)
7420 (set-window-start (get-buffer-window (current-buffer)) start))))))
7421
7422(defun gnus-summary-stop-page-breaking ()
7423 "Stop page breaking in the current article."
7424 (interactive)
eec82323
LMI
7425 (gnus-summary-select-article)
7426 (gnus-eval-in-buffer-window gnus-article-buffer
7427 (widen)
7428 (when (gnus-visual-p 'page-marker)
7429 (let ((buffer-read-only nil))
7430 (gnus-remove-text-with-property 'gnus-prev)
6748645f
LMI
7431 (gnus-remove-text-with-property 'gnus-next))
7432 (setq gnus-page-broken nil))))
eec82323
LMI
7433
7434(defun gnus-summary-move-article (&optional n to-newsgroup
7435 select-method action)
7436 "Move the current article to a different newsgroup.
7437If N is a positive number, move the N next articles.
7438If N is a negative number, move the N previous articles.
7439If N is nil and any articles have been marked with the process mark,
7440move those articles instead.
7441If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7442If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7443re-spool using this method.
7444
7445For this function to work, both the current newsgroup and the
7446newsgroup that you want to move to have to support the `request-move'
16409b0b
GM
7447and `request-accept' functions.
7448
7449ACTION can be either `move' (the default), `crosspost' or `copy'."
eec82323
LMI
7450 (interactive "P")
7451 (unless action
7452 (setq action 'move))
eec82323
LMI
7453 ;; Disable marking as read.
7454 (let (gnus-mark-article-hook)
7455 (save-window-excursion
7456 (gnus-summary-select-article)))
7457 ;; Check whether the source group supports the required functions.
7458 (cond ((and (eq action 'move)
7459 (not (gnus-check-backend-function
7460 'request-move-article gnus-newsgroup-name)))
7461 (error "The current group does not support article moving"))
7462 ((and (eq action 'crosspost)
7463 (not (gnus-check-backend-function
7464 'request-replace-article gnus-newsgroup-name)))
7465 (error "The current group does not support article editing")))
7466 (let ((articles (gnus-summary-work-articles n))
16409b0b
GM
7467 (prefix (if (gnus-check-backend-function
7468 'request-move-article gnus-newsgroup-name)
7469 (gnus-group-real-prefix gnus-newsgroup-name)
7470 ""))
eec82323
LMI
7471 (names '((move "Move" "Moving")
7472 (copy "Copy" "Copying")
7473 (crosspost "Crosspost" "Crossposting")))
7474 (copy-buf (save-excursion
7475 (nnheader-set-temp-buffer " *copy article*")))
7476 art-group to-method new-xref article to-groups)
7477 (unless (assq action names)
7478 (error "Unknown action %s" action))
7479 ;; Read the newsgroup name.
7480 (when (and (not to-newsgroup)
7481 (not select-method))
7482 (setq to-newsgroup
7483 (gnus-read-move-group-name
7484 (cadr (assq action names))
7485 (symbol-value (intern (format "gnus-current-%s-group" action)))
7486 articles prefix))
7487 (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7488 (setq to-method (or select-method
16409b0b
GM
7489 (gnus-server-to-method
7490 (gnus-group-method to-newsgroup))))
eec82323
LMI
7491 ;; Check the method we are to move this article to...
7492 (unless (gnus-check-backend-function
7493 'request-accept-article (car to-method))
7494 (error "%s does not support article copying" (car to-method)))
7495 (unless (gnus-check-server to-method)
7496 (error "Can't open server %s" (car to-method)))
7497 (gnus-message 6 "%s to %s: %s..."
7498 (caddr (assq action names))
7499 (or (car select-method) to-newsgroup) articles)
7500 (while articles
7501 (setq article (pop articles))
7502 (setq
7503 art-group
7504 (cond
7505 ;; Move the article.
7506 ((eq action 'move)
a8151ef7
LMI
7507 ;; Remove this article from future suppression.
7508 (gnus-dup-unsuppress-article article)
eec82323
LMI
7509 (gnus-request-move-article
7510 article ; Article to move
7511 gnus-newsgroup-name ; From newsgroup
7512 (nth 1 (gnus-find-method-for-group
7513 gnus-newsgroup-name)) ; Server
7514 (list 'gnus-request-accept-article
7515 to-newsgroup (list 'quote select-method)
16409b0b 7516 (not articles) t) ; Accept form
eec82323
LMI
7517 (not articles))) ; Only save nov last time
7518 ;; Copy the article.
7519 ((eq action 'copy)
7520 (save-excursion
7521 (set-buffer copy-buf)
6748645f
LMI
7522 (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7523 (gnus-request-accept-article
16409b0b 7524 to-newsgroup select-method (not articles) t))))
eec82323
LMI
7525 ;; Crosspost the article.
7526 ((eq action 'crosspost)
7527 (let ((xref (message-tokenize-header
7528 (mail-header-xref (gnus-summary-article-header article))
7529 " ")))
7530 (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7531 ":" article))
7532 (unless xref
7533 (setq xref (list (system-name))))
7534 (setq new-xref
7535 (concat
7536 (mapconcat 'identity
7537 (delete "Xref:" (delete new-xref xref))
7538 " ")
7539 " " new-xref))
7540 (save-excursion
7541 (set-buffer copy-buf)
7542 ;; First put the article in the destination group.
7543 (gnus-request-article-this-buffer article gnus-newsgroup-name)
7544 (when (consp (setq art-group
7545 (gnus-request-accept-article
7546 to-newsgroup select-method (not articles))))
7547 (setq new-xref (concat new-xref " " (car art-group)
7548 ":" (cdr art-group)))
7549 ;; Now we have the new Xrefs header, so we insert
7550 ;; it and replace the new article.
7551 (nnheader-replace-header "Xref" new-xref)
7552 (gnus-request-replace-article
7553 (cdr art-group) to-newsgroup (current-buffer))
7554 art-group))))))
7555 (cond
7556 ((not art-group)
16409b0b
GM
7557 (gnus-message 1 "Couldn't %s article %s: %s"
7558 (cadr (assq action names)) article
7559 (nnheader-get-report (car to-method))))
7560 ((eq art-group 'junk)
7561 (when (eq action 'move)
7562 (gnus-summary-mark-article article gnus-canceled-mark)
7563 (gnus-message 4 "Deleted article %s" article)))
eec82323 7564 (t
6748645f
LMI
7565 (let* ((pto-group (gnus-group-prefixed-name
7566 (car art-group) to-method))
7567 (entry
7568 (gnus-gethash pto-group gnus-newsrc-hashtb))
eec82323 7569 (info (nth 2 entry))
16409b0b
GM
7570 (to-group (gnus-info-group info))
7571 to-marks)
eec82323
LMI
7572 ;; Update the group that has been moved to.
7573 (when (and info
7574 (memq action '(move copy)))
7575 (unless (member to-group to-groups)
7576 (push to-group to-groups))
7577
7578 (unless (memq article gnus-newsgroup-unreads)
16409b0b 7579 (push 'read to-marks)
eec82323
LMI
7580 (gnus-info-set-read
7581 info (gnus-add-to-range (gnus-info-read info)
7582 (list (cdr art-group)))))
7583
16409b0b 7584 ;; See whether the article is to be put in the cache.
eec82323
LMI
7585 (let ((marks gnus-article-mark-lists)
7586 (to-article (cdr art-group)))
7587
16409b0b
GM
7588 ;; Enter the article into the cache in the new group,
7589 ;; if that is required.
eec82323
LMI
7590 (when gnus-use-cache
7591 (gnus-cache-possibly-enter-article
7592 to-group to-article
eec82323
LMI
7593 (memq article gnus-newsgroup-marked)
7594 (memq article gnus-newsgroup-dormant)
7595 (memq article gnus-newsgroup-unreads)))
7596
16409b0b
GM
7597 (when gnus-preserve-marks
7598 ;; Copy any marks over to the new group.
7599 (when (and (equal to-group gnus-newsgroup-name)
7600 (not (memq article gnus-newsgroup-unreads)))
7601 ;; Mark this article as read in this group.
7602 (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7603 (setcdr (gnus-active to-group) to-article)
7604 (setcdr gnus-newsgroup-active to-article))
7605
7606 (while marks
7607 (when (memq article (symbol-value
7608 (intern (format "gnus-newsgroup-%s"
7609 (caar marks)))))
7610 (push (cdar marks) to-marks)
7611 ;; If the other group is the same as this group,
7612 ;; then we have to add the mark to the list.
7613 (when (equal to-group gnus-newsgroup-name)
7614 (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7615 (cons to-article
7616 (symbol-value
7617 (intern (format "gnus-newsgroup-%s"
7618 (caar marks)))))))
7619 ;; Copy the marks to other group.
7620 (gnus-add-marked-articles
7621 to-group (cdar marks) (list to-article) info))
7622 (setq marks (cdr marks)))
7623
7624 (gnus-request-set-mark to-group (list (list (list to-article)
7625 'set
7626 to-marks))))
eec82323
LMI
7627
7628 (gnus-dribble-enter
7629 (concat "(gnus-group-set-info '"
7630 (gnus-prin1-to-string (gnus-get-info to-group))
7631 ")"))))
7632
7633 ;; Update the Xref header in this article to point to
7634 ;; the new crossposted article we have just created.
7635 (when (eq action 'crosspost)
7636 (save-excursion
7637 (set-buffer copy-buf)
7638 (gnus-request-article-this-buffer article gnus-newsgroup-name)
7639 (nnheader-replace-header "Xref" new-xref)
7640 (gnus-request-replace-article
7641 article gnus-newsgroup-name (current-buffer)))))
7642
6748645f
LMI
7643 ;;;!!!Why is this necessary?
7644 (set-buffer gnus-summary-buffer)
7645
eec82323
LMI
7646 (gnus-summary-goto-subject article)
7647 (when (eq action 'move)
7648 (gnus-summary-mark-article article gnus-canceled-mark))))
7649 (gnus-summary-remove-process-mark article))
7650 ;; Re-activate all groups that have been moved to.
7651 (while to-groups
7652 (save-excursion
7653 (set-buffer gnus-group-buffer)
7654 (when (gnus-group-goto-group (car to-groups) t)
a8151ef7 7655 (gnus-group-get-new-news-this-group 1 t))
eec82323
LMI
7656 (pop to-groups)))
7657
7658 (gnus-kill-buffer copy-buf)
7659 (gnus-summary-position-point)
7660 (gnus-set-mode-line 'summary)))
7661
7662(defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7663 "Move the current article to a different newsgroup.
7664If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7665If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7666re-spool using this method."
7667 (interactive "P")
7668 (gnus-summary-move-article n to-newsgroup select-method 'copy))
7669
7670(defun gnus-summary-crosspost-article (&optional n)
7671 "Crosspost the current article to some other group."
7672 (interactive "P")
7673 (gnus-summary-move-article n nil nil 'crosspost))
7674
7675(defcustom gnus-summary-respool-default-method nil
7676 "Default method for respooling an article.
7677If nil, use to the current newsgroup method."
04ad70ac
KH
7678 :type '(choice (gnus-select-method :value (nnml ""))
7679 (const nil))
eec82323
LMI
7680 :group 'gnus-summary-mail)
7681
7682(defun gnus-summary-respool-article (&optional n method)
7683 "Respool the current article.
7684The article will be squeezed through the mail spooling process again,
7685which means that it will be put in some mail newsgroup or other
7686depending on `nnmail-split-methods'.
7687If N is a positive number, respool the N next articles.
7688If N is a negative number, respool the N previous articles.
7689If N is nil and any articles have been marked with the process mark,
7690respool those articles instead.
7691
7692Respooling can be done both from mail groups and \"real\" newsgroups.
7693In the former case, the articles in question will be moved from the
7694current group into whatever groups they are destined to. In the
7695latter case, they will be copied into the relevant groups."
7696 (interactive
7697 (list current-prefix-arg
7698 (let* ((methods (gnus-methods-using 'respool))
7699 (methname
7700 (symbol-name (or gnus-summary-respool-default-method
7701 (car (gnus-find-method-for-group
7702 gnus-newsgroup-name)))))
7703 (method
7704 (gnus-completing-read
7705 methname "What backend do you want to use when respooling?"
7706 methods nil t nil 'gnus-mail-method-history))
7707 ms)
7708 (cond
7709 ((zerop (length (setq ms (gnus-servers-using-backend
7710 (intern method)))))
7711 (list (intern method) ""))
7712 ((= 1 (length ms))
7713 (car ms))
7714 (t
7715 (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7716 (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7717 ms-alist))))))))
eec82323
LMI
7718 (unless method
7719 (error "No method given for respooling"))
7720 (if (assoc (symbol-name
7721 (car (gnus-find-method-for-group gnus-newsgroup-name)))
7722 (gnus-methods-using 'respool))
7723 (gnus-summary-move-article n nil method)
7724 (gnus-summary-copy-article n nil method)))
7725
7726(defun gnus-summary-import-article (file)
6748645f 7727 "Import an arbitrary file into a mail newsgroup."
eec82323 7728 (interactive "fImport file: ")
eec82323
LMI
7729 (let ((group gnus-newsgroup-name)
7730 (now (current-time))
7731 atts lines)
7732 (unless (gnus-check-backend-function 'request-accept-article group)
7733 (error "%s does not support article importing" group))
7734 (or (file-readable-p file)
7735 (not (file-regular-p file))
7736 (error "Can't read %s" file))
7737 (save-excursion
6748645f 7738 (set-buffer (gnus-get-buffer-create " *import file*"))
eec82323 7739 (erase-buffer)
16409b0b 7740 (nnheader-insert-file-contents file)
eec82323
LMI
7741 (goto-char (point-min))
7742 (unless (nnheader-article-p)
7743 ;; This doesn't look like an article, so we fudge some headers.
7744 (setq atts (file-attributes file)
7745 lines (count-lines (point-min) (point-max)))
7746 (insert "From: " (read-string "From: ") "\n"
7747 "Subject: " (read-string "Subject: ") "\n"
16409b0b 7748 "Date: " (message-make-date (nth 5 atts))
eec82323
LMI
7749 "\n"
7750 "Message-ID: " (message-make-message-id) "\n"
7751 "Lines: " (int-to-string lines) "\n"
7752 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7753 (gnus-request-accept-article group nil t)
7754 (kill-buffer (current-buffer)))))
7755
7756(defun gnus-summary-article-posted-p ()
16409b0b 7757 "Say whether the current (mail) article is available from news as well.
eec82323
LMI
7758This will be the case if the article has both been mailed and posted."
7759 (interactive)
7760 (let ((id (mail-header-references (gnus-summary-article-header)))
16409b0b 7761 (gnus-override-method (car (gnus-refer-article-methods))))
eec82323
LMI
7762 (if (gnus-request-head id "")
7763 (gnus-message 2 "The current message was found on %s"
7764 gnus-override-method)
7765 (gnus-message 2 "The current message couldn't be found on %s"
7766 gnus-override-method)
7767 nil)))
7768
7769(defun gnus-summary-expire-articles (&optional now)
7770 "Expire all articles that are marked as expirable in the current group."
7771 (interactive)
eec82323
LMI
7772 (when (gnus-check-backend-function
7773 'request-expire-articles gnus-newsgroup-name)
7774 ;; This backend supports expiry.
7775 (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
7776 (expirable (if total
7777 (progn
7778 ;; We need to update the info for
7779 ;; this group for `gnus-list-of-read-articles'
7780 ;; to give us the right answer.
6748645f 7781 (gnus-run-hooks 'gnus-exit-group-hook)
eec82323
LMI
7782 (gnus-summary-update-info)
7783 (gnus-list-of-read-articles gnus-newsgroup-name))
7784 (setq gnus-newsgroup-expirable
7785 (sort gnus-newsgroup-expirable '<))))
7786 (expiry-wait (if now 'immediate
7787 (gnus-group-find-parameter
7788 gnus-newsgroup-name 'expiry-wait)))
16409b0b
GM
7789 (nnmail-expiry-target
7790 (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
7791 nnmail-expiry-target))
eec82323
LMI
7792 es)
7793 (when expirable
7794 ;; There are expirable articles in this group, so we run them
7795 ;; through the expiry process.
7796 (gnus-message 6 "Expiring articles...")
16409b0b
GM
7797 (unless (gnus-check-group gnus-newsgroup-name)
7798 (error "Can't open server for %s" gnus-newsgroup-name))
eec82323 7799 ;; The list of articles that weren't expired is returned.
6748645f
LMI
7800 (save-excursion
7801 (if expiry-wait
7802 (let ((nnmail-expiry-wait-function nil)
7803 (nnmail-expiry-wait expiry-wait))
7804 (setq es (gnus-request-expire-articles
7805 expirable gnus-newsgroup-name)))
7806 (setq es (gnus-request-expire-articles
7807 expirable gnus-newsgroup-name))))
eec82323
LMI
7808 (unless total
7809 (setq gnus-newsgroup-expirable es))
7810 ;; We go through the old list of expirable, and mark all
7811 ;; really expired articles as nonexistent.
7812 (unless (eq es expirable) ;If nothing was expired, we don't mark.
7813 (let ((gnus-use-cache nil))
7814 (while expirable
7815 (unless (memq (car expirable) es)
7816 (when (gnus-data-find (car expirable))
7817 (gnus-summary-mark-article
7818 (car expirable) gnus-canceled-mark)))
7819 (setq expirable (cdr expirable)))))
7820 (gnus-message 6 "Expiring articles...done")))))
7821
7822(defun gnus-summary-expire-articles-now ()
7823 "Expunge all expirable articles in the current group.
7824This means that *all* articles that are marked as expirable will be
7825deleted forever, right now."
7826 (interactive)
eec82323
LMI
7827 (or gnus-expert-user
7828 (gnus-yes-or-no-p
7829 "Are you really, really, really sure you want to delete all these messages? ")
7830 (error "Phew!"))
7831 (gnus-summary-expire-articles t))
7832
7833;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
7834(defun gnus-summary-delete-article (&optional n)
7835 "Delete the N next (mail) articles.
7836This command actually deletes articles. This is not a marking
7837command. The article will disappear forever from your life, never to
7838return.
7839If N is negative, delete backwards.
7840If N is nil and articles have been marked with the process mark,
7841delete these instead."
7842 (interactive "P")
eec82323
LMI
7843 (unless (gnus-check-backend-function 'request-expire-articles
7844 gnus-newsgroup-name)
a8151ef7 7845 (error "The current newsgroup does not support article deletion"))
16409b0b
GM
7846 (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7847 (error "Couldn't open server"))
eec82323 7848 ;; Compute the list of articles to delete.
6748645f 7849 (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
eec82323
LMI
7850 not-deleted)
7851 (if (and gnus-novice-user
7852 (not (gnus-yes-or-no-p
7853 (format "Do you really want to delete %s forever? "
7854 (if (> (length articles) 1)
7855 (format "these %s articles" (length articles))
7856 "this article")))))
7857 ()
7858 ;; Delete the articles.
7859 (setq not-deleted (gnus-request-expire-articles
7860 articles gnus-newsgroup-name 'force))
7861 (while articles
7862 (gnus-summary-remove-process-mark (car articles))
7863 ;; The backend might not have been able to delete the article
7864 ;; after all.
7865 (unless (memq (car articles) not-deleted)
7866 (gnus-summary-mark-article (car articles) gnus-canceled-mark))
7867 (setq articles (cdr articles)))
7868 (when not-deleted
7869 (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
7870 (gnus-summary-position-point)
7871 (gnus-set-mode-line 'summary)
7872 not-deleted))
7873
16409b0b 7874(defun gnus-summary-edit-article (&optional arg)
eec82323
LMI
7875 "Edit the current article.
7876This will have permanent effect only in mail groups.
16409b0b
GM
7877If ARG is nil, edit the decoded articles.
7878If ARG is 1, edit the raw articles.
7879If ARG is 2, edit the raw articles even in read-only groups.
7880Otherwise, allow editing of articles even in read-only
eec82323
LMI
7881groups."
7882 (interactive "P")
16409b0b
GM
7883 (let (force raw)
7884 (cond
7885 ((null arg))
7886 ((eq arg 1) (setq raw t))
7887 ((eq arg 2) (setq raw t
7888 force t))
7889 (t (setq force t)))
7890 (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
7891 (error "Can't edit the raw article in group nndraft:drafts."))
7892 (save-excursion
7893 (set-buffer gnus-summary-buffer)
7894 (let ((mail-parse-charset gnus-newsgroup-charset)
7895 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
7896 (gnus-set-global-variables)
7897 (when (and (not force)
7898 (gnus-group-read-only-p))
7899 (error "The current newsgroup does not support article editing"))
7900 (gnus-summary-show-article t)
7901 (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
7902 (with-current-buffer gnus-article-buffer
d4dfaa19 7903 (mm-enable-multibyte-mule4)))
16409b0b
GM
7904 (if (equal gnus-newsgroup-name "nndraft:drafts")
7905 (setq raw t))
7906 (gnus-article-edit-article
7907 (if raw 'ignore
7908 #'(lambda ()
7909 (let ((mbl mml-buffer-list))
7910 (setq mml-buffer-list nil)
7911 (mime-to-mml)
7912 (make-local-hook 'kill-buffer-hook)
7913 (let ((mml-buffer-list mml-buffer-list))
7914 (setq mml-buffer-list mbl)
7915 (make-local-variable 'mml-buffer-list))
7916 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
7917 `(lambda (no-highlight)
7918 (let ((mail-parse-charset ',gnus-newsgroup-charset)
7919 (mail-parse-ignored-charsets
7920 ',gnus-newsgroup-ignored-charsets))
7921 ,(if (not raw) '(progn
7922 (mml-to-mime)
7923 (mml-destroy-buffers)
7924 (remove-hook 'kill-buffer-hook
7925 'mml-destroy-buffers t)
7926 (kill-local-variable 'mml-buffer-list)))
7927 (gnus-summary-edit-article-done
7928 ,(or (mail-header-references gnus-current-headers) "")
7929 ,(gnus-group-read-only-p)
7930 ,gnus-summary-buffer no-highlight))))))))
eec82323
LMI
7931
7932(defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
7933
6748645f
LMI
7934(defun gnus-summary-edit-article-done (&optional references read-only buffer
7935 no-highlight)
eec82323
LMI
7936 "Make edits to the current article permanent."
7937 (interactive)
7938 ;; Replace the article.
6748645f 7939 (let ((buf (current-buffer)))
16409b0b
GM
7940 (with-temp-buffer
7941 (insert-buffer-substring buf)
6748645f
LMI
7942 (if (and (not read-only)
7943 (not (gnus-request-replace-article
7944 (cdr gnus-article-current) (car gnus-article-current)
16409b0b 7945 (current-buffer) t)))
6748645f
LMI
7946 (error "Couldn't replace article")
7947 ;; Update the summary buffer.
7948 (if (and references
7949 (equal (message-tokenize-header references " ")
7950 (message-tokenize-header
7951 (or (message-fetch-field "references") "") " ")))
7952 ;; We only have to update this line.
7953 (save-excursion
7954 (save-restriction
7955 (message-narrow-to-head)
7956 (let ((head (buffer-string))
7957 header)
16409b0b 7958 (with-temp-buffer
6748645f
LMI
7959 (insert (format "211 %d Article retrieved.\n"
7960 (cdr gnus-article-current)))
7961 (insert head)
7962 (insert ".\n")
7963 (let ((nntp-server-buffer (current-buffer)))
7964 (setq header (car (gnus-get-newsgroup-headers
7965 (save-excursion
7966 (set-buffer gnus-summary-buffer)
7967 gnus-newsgroup-dependencies)
7968 t))))
7969 (save-excursion
7970 (set-buffer gnus-summary-buffer)
7971 (gnus-data-set-header
7972 (gnus-data-find (cdr gnus-article-current))
7973 header)
7974 (gnus-summary-update-article-line
7975 (cdr gnus-article-current) header))))))
7976 ;; Update threads.
7977 (set-buffer (or buffer gnus-summary-buffer))
7978 (gnus-summary-update-article (cdr gnus-article-current)))
7979 ;; Prettify the article buffer again.
7980 (unless no-highlight
7981 (save-excursion
7982 (set-buffer gnus-article-buffer)
16409b0b
GM
7983 ;;;!!! Fix this -- article should be rehighlighted.
7984 ;;;(gnus-run-hooks 'gnus-article-display-hook)
6748645f
LMI
7985 (set-buffer gnus-original-article-buffer)
7986 (gnus-request-article
7987 (cdr gnus-article-current)
7988 (car gnus-article-current) (current-buffer))))
7989 ;; Prettify the summary buffer line.
7990 (when (gnus-visual-p 'summary-highlight 'highlight)
7991 (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
eec82323
LMI
7992
7993(defun gnus-summary-edit-wash (key)
6748645f 7994 "Perform editing command KEY in the article buffer."
eec82323
LMI
7995 (interactive
7996 (list
7997 (progn
7998 (message "%s" (concat (this-command-keys) "- "))
7999 (read-char))))
8000 (message "")
8001 (gnus-summary-edit-article)
8002 (execute-kbd-macro (concat (this-command-keys) key))
8003 (gnus-article-edit-done))
8004
8005;;; Respooling
8006
6748645f 8007(defun gnus-summary-respool-query (&optional silent trace)
eec82323
LMI
8008 "Query where the respool algorithm would put this article."
8009 (interactive)
eec82323
LMI
8010 (let (gnus-mark-article-hook)
8011 (gnus-summary-select-article)
8012 (save-excursion
8013 (set-buffer gnus-original-article-buffer)
8014 (save-restriction
8015 (message-narrow-to-head)
6748645f 8016 (let ((groups (nnmail-article-group 'identity trace)))
eec82323
LMI
8017 (unless silent
8018 (if groups
8019 (message "This message would go to %s"
8020 (mapconcat 'car groups ", "))
8021 (message "This message would go to no groups"))
8022 groups))))))
8023
6748645f
LMI
8024(defun gnus-summary-respool-trace ()
8025 "Trace where the respool algorithm would put this article.
8026Display a buffer showing all fancy splitting patterns which matched."
8027 (interactive)
8028 (gnus-summary-respool-query nil t))
8029
eec82323
LMI
8030;; Summary marking commands.
8031
8032(defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8033 "Mark articles which has the same subject as read, and then select the next.
8034If UNMARK is positive, remove any kind of mark.
8035If UNMARK is negative, tick articles."
8036 (interactive "P")
eec82323
LMI
8037 (when unmark
8038 (setq unmark (prefix-numeric-value unmark)))
8039 (let ((count
8040 (gnus-summary-mark-same-subject
8041 (gnus-summary-article-subject) unmark)))
8042 ;; Select next unread article. If auto-select-same mode, should
8043 ;; select the first unread article.
8044 (gnus-summary-next-article t (and gnus-auto-select-same
8045 (gnus-summary-article-subject)))
8046 (gnus-message 7 "%d article%s marked as %s"
8047 count (if (= count 1) " is" "s are")
8048 (if unmark "unread" "read"))))
8049
8050(defun gnus-summary-kill-same-subject (&optional unmark)
8051 "Mark articles which has the same subject as read.
8052If UNMARK is positive, remove any kind of mark.
8053If UNMARK is negative, tick articles."
8054 (interactive "P")
eec82323
LMI
8055 (when unmark
8056 (setq unmark (prefix-numeric-value unmark)))
8057 (let ((count
8058 (gnus-summary-mark-same-subject
8059 (gnus-summary-article-subject) unmark)))
8060 ;; If marked as read, go to next unread subject.
8061 (when (null unmark)
8062 ;; Go to next unread subject.
8063 (gnus-summary-next-subject 1 t))
8064 (gnus-message 7 "%d articles are marked as %s"
8065 count (if unmark "unread" "read"))))
8066
8067(defun gnus-summary-mark-same-subject (subject &optional unmark)
8068 "Mark articles with same SUBJECT as read, and return marked number.
8069If optional argument UNMARK is positive, remove any kinds of marks.
8070If optional argument UNMARK is negative, mark articles as unread instead."
8071 (let ((count 1))
8072 (save-excursion
8073 (cond
8074 ((null unmark) ; Mark as read.
8075 (while (and
8076 (progn
8077 (gnus-summary-mark-article-as-read gnus-killed-mark)
8078 (gnus-summary-show-thread) t)
8079 (gnus-summary-find-subject subject))
8080 (setq count (1+ count))))
8081 ((> unmark 0) ; Tick.
8082 (while (and
8083 (progn
8084 (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8085 (gnus-summary-show-thread) t)
8086 (gnus-summary-find-subject subject))
8087 (setq count (1+ count))))
8088 (t ; Mark as unread.
8089 (while (and
8090 (progn
8091 (gnus-summary-mark-article-as-unread gnus-unread-mark)
8092 (gnus-summary-show-thread) t)
8093 (gnus-summary-find-subject subject))
8094 (setq count (1+ count)))))
8095 (gnus-set-mode-line 'summary)
8096 ;; Return the number of marked articles.
8097 count)))
8098
8099(defun gnus-summary-mark-as-processable (n &optional unmark)
8100 "Set the process mark on the next N articles.
8101If N is negative, mark backward instead. If UNMARK is non-nil, remove
8102the process mark instead. The difference between N and the actual
8103number of articles marked is returned."
8104 (interactive "p")
eec82323
LMI
8105 (let ((backward (< n 0))
8106 (n (abs n)))
8107 (while (and
8108 (> n 0)
8109 (if unmark
8110 (gnus-summary-remove-process-mark
8111 (gnus-summary-article-number))
8112 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8113 (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8114 (setq n (1- n)))
8115 (when (/= 0 n)
8116 (gnus-message 7 "No more articles"))
8117 (gnus-summary-recenter)
8118 (gnus-summary-position-point)
8119 n))
8120
8121(defun gnus-summary-unmark-as-processable (n)
8122 "Remove the process mark from the next N articles.
6748645f
LMI
8123If N is negative, unmark backward instead. The difference between N and
8124the actual number of articles unmarked is returned."
eec82323 8125 (interactive "p")
eec82323
LMI
8126 (gnus-summary-mark-as-processable n t))
8127
8128(defun gnus-summary-unmark-all-processable ()
8129 "Remove the process mark from all articles."
8130 (interactive)
eec82323
LMI
8131 (save-excursion
8132 (while gnus-newsgroup-processable
8133 (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8134 (gnus-summary-position-point))
8135
8136(defun gnus-summary-mark-as-expirable (n)
8137 "Mark N articles forward as expirable.
8138If N is negative, mark backward instead. The difference between N and
8139the actual number of articles marked is returned."
8140 (interactive "p")
eec82323
LMI
8141 (gnus-summary-mark-forward n gnus-expirable-mark))
8142
8143(defun gnus-summary-mark-article-as-replied (article)
8144 "Mark ARTICLE replied and update the summary line."
8145 (push article gnus-newsgroup-replied)
8146 (let ((buffer-read-only nil))
16409b0b 8147 (when (gnus-summary-goto-subject article nil t)
eec82323
LMI
8148 (gnus-summary-update-secondary-mark article))))
8149
8150(defun gnus-summary-set-bookmark (article)
8151 "Set a bookmark in current article."
8152 (interactive (list (gnus-summary-article-number)))
eec82323
LMI
8153 (when (or (not (get-buffer gnus-article-buffer))
8154 (not gnus-current-article)
8155 (not gnus-article-current)
8156 (not (equal gnus-newsgroup-name (car gnus-article-current))))
8157 (error "No current article selected"))
8158 ;; Remove old bookmark, if one exists.
8159 (let ((old (assq article gnus-newsgroup-bookmarks)))
8160 (when old
8161 (setq gnus-newsgroup-bookmarks
8162 (delq old gnus-newsgroup-bookmarks))))
8163 ;; Set the new bookmark, which is on the form
8164 ;; (article-number . line-number-in-body).
8165 (push
8166 (cons article
8167 (save-excursion
8168 (set-buffer gnus-article-buffer)
8169 (count-lines
8170 (min (point)
8171 (save-excursion
8172 (goto-char (point-min))
8173 (search-forward "\n\n" nil t)
8174 (point)))
8175 (point))))
8176 gnus-newsgroup-bookmarks)
8177 (gnus-message 6 "A bookmark has been added to the current article."))
8178
8179(defun gnus-summary-remove-bookmark (article)
8180 "Remove the bookmark from the current article."
8181 (interactive (list (gnus-summary-article-number)))
eec82323
LMI
8182 ;; Remove old bookmark, if one exists.
8183 (let ((old (assq article gnus-newsgroup-bookmarks)))
8184 (if old
8185 (progn
8186 (setq gnus-newsgroup-bookmarks
8187 (delq old gnus-newsgroup-bookmarks))
8188 (gnus-message 6 "Removed bookmark."))
8189 (gnus-message 6 "No bookmark in current article."))))
8190
8191;; Suggested by Daniel Quinlan <quinlan@best.com>.
8192(defun gnus-summary-mark-as-dormant (n)
8193 "Mark N articles forward as dormant.
8194If N is negative, mark backward instead. The difference between N and
8195the actual number of articles marked is returned."
8196 (interactive "p")
eec82323
LMI
8197 (gnus-summary-mark-forward n gnus-dormant-mark))
8198
8199(defun gnus-summary-set-process-mark (article)
8200 "Set the process mark on ARTICLE and update the summary line."
8201 (setq gnus-newsgroup-processable
8202 (cons article
8203 (delq article gnus-newsgroup-processable)))
8204 (when (gnus-summary-goto-subject article)
8205 (gnus-summary-show-thread)
6748645f 8206 (gnus-summary-goto-subject article)
eec82323
LMI
8207 (gnus-summary-update-secondary-mark article)))
8208
8209(defun gnus-summary-remove-process-mark (article)
8210 "Remove the process mark from ARTICLE and update the summary line."
8211 (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8212 (when (gnus-summary-goto-subject article)
8213 (gnus-summary-show-thread)
6748645f 8214 (gnus-summary-goto-subject article)
eec82323
LMI
8215 (gnus-summary-update-secondary-mark article)))
8216
8217(defun gnus-summary-set-saved-mark (article)
8218 "Set the process mark on ARTICLE and update the summary line."
8219 (push article gnus-newsgroup-saved)
8220 (when (gnus-summary-goto-subject article)
8221 (gnus-summary-update-secondary-mark article)))
8222
8223(defun gnus-summary-mark-forward (n &optional mark no-expire)
8224 "Mark N articles as read forwards.
8225If N is negative, mark backwards instead. Mark with MARK, ?r by default.
8226The difference between N and the actual number of articles marked is
16409b0b
GM
8227returned.
8228Iff NO-EXPIRE, auto-expiry will be inhibited."
eec82323 8229 (interactive "p")
16409b0b 8230 (gnus-summary-show-thread)
eec82323
LMI
8231 (let ((backward (< n 0))
8232 (gnus-summary-goto-unread
8233 (and gnus-summary-goto-unread
8234 (not (eq gnus-summary-goto-unread 'never))
8235 (not (memq mark (list gnus-unread-mark
8236 gnus-ticked-mark gnus-dormant-mark)))))
8237 (n (abs n))
8238 (mark (or mark gnus-del-mark)))
8239 (while (and (> n 0)
8240 (gnus-summary-mark-article nil mark no-expire)
8241 (zerop (gnus-summary-next-subject
8242 (if backward -1 1)
8243 (and gnus-summary-goto-unread
8244 (not (eq gnus-summary-goto-unread 'never)))
8245 t)))
8246 (setq n (1- n)))
8247 (when (/= 0 n)
8248 (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8249 (gnus-summary-recenter)
8250 (gnus-summary-position-point)
8251 (gnus-set-mode-line 'summary)
8252 n))
8253
8254(defun gnus-summary-mark-article-as-read (mark)
8255 "Mark the current article quickly as read with MARK."
8256 (let ((article (gnus-summary-article-number)))
8257 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8258 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8259 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8260 (push (cons article mark) gnus-newsgroup-reads)
8261 ;; Possibly remove from cache, if that is used.
8262 (when gnus-use-cache
8263 (gnus-cache-enter-remove-article article))
8264 ;; Allow the backend to change the mark.
8265 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8266 ;; Check for auto-expiry.
8267 (when (and gnus-newsgroup-auto-expire
16409b0b 8268 (memq mark gnus-auto-expirable-marks))
eec82323 8269 (setq mark gnus-expirable-mark)
6748645f
LMI
8270 ;; Let the backend know about the mark change.
8271 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
eec82323
LMI
8272 (push article gnus-newsgroup-expirable))
8273 ;; Set the mark in the buffer.
8274 (gnus-summary-update-mark mark 'unread)
8275 t))
8276
8277(defun gnus-summary-mark-article-as-unread (mark)
8278 "Mark the current article quickly as unread with MARK."
6748645f
LMI
8279 (let* ((article (gnus-summary-article-number))
8280 (old-mark (gnus-summary-article-mark article)))
8281 ;; Allow the backend to change the mark.
8282 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8283 (if (eq mark old-mark)
8284 t
8285 (if (<= article 0)
8286 (progn
8287 (gnus-error 1 "Can't mark negative article numbers")
8288 nil)
8289 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8290 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8291 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8292 (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8293 (cond ((= mark gnus-ticked-mark)
8294 (push article gnus-newsgroup-marked))
8295 ((= mark gnus-dormant-mark)
8296 (push article gnus-newsgroup-dormant))
8297 (t
8298 (push article gnus-newsgroup-unreads)))
8299 (gnus-pull article gnus-newsgroup-reads)
eec82323 8300
6748645f
LMI
8301 ;; See whether the article is to be put in the cache.
8302 (and gnus-use-cache
8303 (vectorp (gnus-summary-article-header article))
8304 (save-excursion
8305 (gnus-cache-possibly-enter-article
8306 gnus-newsgroup-name article
6748645f
LMI
8307 (= mark gnus-ticked-mark)
8308 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8309
8310 ;; Fix the mark.
8311 (gnus-summary-update-mark mark 'unread)
8312 t))))
eec82323
LMI
8313
8314(defun gnus-summary-mark-article (&optional article mark no-expire)
8315 "Mark ARTICLE with MARK. MARK can be any character.
8316Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8317`??' (dormant) and `?E' (expirable).
16409b0b 8318If MARK is nil, then the default character `?r' is used.
eec82323 8319If ARTICLE is nil, then the article on the current line will be
16409b0b
GM
8320marked.
8321Iff NO-EXPIRE, auto-expiry will be inhibited."
eec82323
LMI
8322 ;; The mark might be a string.
8323 (when (stringp mark)
8324 (setq mark (aref mark 0)))
8325 ;; If no mark is given, then we check auto-expiring.
16409b0b
GM
8326 (when (null mark)
8327 (setq mark gnus-del-mark))
8328 (when (and (not no-expire)
8329 gnus-newsgroup-auto-expire
8330 (memq mark gnus-auto-expirable-marks))
8331 (setq mark gnus-expirable-mark))
8332 (let ((article (or article (gnus-summary-article-number)))
8333 (old-mark (gnus-summary-article-mark article)))
6748645f
LMI
8334 ;; Allow the backend to change the mark.
8335 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8336 (if (eq mark old-mark)
8337 t
8338 (unless article
8339 (error "No article on current line"))
8340 (if (not (if (or (= mark gnus-unread-mark)
8341 (= mark gnus-ticked-mark)
8342 (= mark gnus-dormant-mark))
8343 (gnus-mark-article-as-unread article mark)
8344 (gnus-mark-article-as-read article mark)))
8345 t
8346 ;; See whether the article is to be put in the cache.
8347 (and gnus-use-cache
8348 (not (= mark gnus-canceled-mark))
8349 (vectorp (gnus-summary-article-header article))
8350 (save-excursion
8351 (gnus-cache-possibly-enter-article
8352 gnus-newsgroup-name article
6748645f
LMI
8353 (= mark gnus-ticked-mark)
8354 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8355
8356 (when (gnus-summary-goto-subject article nil t)
8357 (let ((buffer-read-only nil))
8358 (gnus-summary-show-thread)
8359 ;; Fix the mark.
8360 (gnus-summary-update-mark mark 'unread)
8361 t))))))
eec82323
LMI
8362
8363(defun gnus-summary-update-secondary-mark (article)
8364 "Update the secondary (read, process, cache) mark."
8365 (gnus-summary-update-mark
8366 (cond ((memq article gnus-newsgroup-processable)
8367 gnus-process-mark)
8368 ((memq article gnus-newsgroup-cached)
8369 gnus-cached-mark)
8370 ((memq article gnus-newsgroup-replied)
8371 gnus-replied-mark)
8372 ((memq article gnus-newsgroup-saved)
8373 gnus-saved-mark)
8374 (t gnus-unread-mark))
8375 'replied)
8376 (when (gnus-visual-p 'summary-highlight 'highlight)
6748645f 8377 (gnus-run-hooks 'gnus-summary-update-hook))
eec82323
LMI
8378 t)
8379
8380(defun gnus-summary-update-mark (mark type)
8381 (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8382 (buffer-read-only nil))
8383 (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
16409b0b
GM
8384 (when forward
8385 (when (looking-at "\r")
8386 (incf forward))
8387 (when (<= (+ forward (point)) (point-max))
8388 ;; Go to the right position on the line.
8389 (goto-char (+ forward (point)))
8390 ;; Replace the old mark with the new mark.
8391 (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8392 ;; Optionally update the marks by some user rule.
8393 (when (eq type 'unread)
8394 (gnus-data-set-mark
8395 (gnus-data-find (gnus-summary-article-number)) mark)
8396 (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
eec82323
LMI
8397
8398(defun gnus-mark-article-as-read (article &optional mark)
8399 "Enter ARTICLE in the pertinent lists and remove it from others."
8400 ;; Make the article expirable.
8401 (let ((mark (or mark gnus-del-mark)))
8402 (if (= mark gnus-expirable-mark)
8403 (push article gnus-newsgroup-expirable)
8404 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8405 ;; Remove from unread and marked lists.
8406 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8407 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8408 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8409 (push (cons article mark) gnus-newsgroup-reads)
8410 ;; Possibly remove from cache, if that is used.
8411 (when gnus-use-cache
6748645f
LMI
8412 (gnus-cache-enter-remove-article article))
8413 t))
eec82323
LMI
8414
8415(defun gnus-mark-article-as-unread (article &optional mark)
8416 "Enter ARTICLE in the pertinent lists and remove it from others."
8417 (let ((mark (or mark gnus-ticked-mark)))
6748645f
LMI
8418 (if (<= article 0)
8419 (progn
8420 (gnus-error 1 "Can't mark negative article numbers")
8421 nil)
8422 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8423 gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8424 gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8425 gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
eec82323 8426
6748645f
LMI
8427 ;; Unsuppress duplicates?
8428 (when gnus-suppress-duplicates
8429 (gnus-dup-unsuppress-article article))
8430
8431 (cond ((= mark gnus-ticked-mark)
8432 (push article gnus-newsgroup-marked))
8433 ((= mark gnus-dormant-mark)
8434 (push article gnus-newsgroup-dormant))
8435 (t
8436 (push article gnus-newsgroup-unreads)))
8437 (gnus-pull article gnus-newsgroup-reads)
8438 t)))
eec82323
LMI
8439
8440(defalias 'gnus-summary-mark-as-unread-forward
8441 'gnus-summary-tick-article-forward)
8442(make-obsolete 'gnus-summary-mark-as-unread-forward
8443 'gnus-summary-tick-article-forward)
8444(defun gnus-summary-tick-article-forward (n)
8445 "Tick N articles forwards.
8446If N is negative, tick backwards instead.
8447The difference between N and the number of articles ticked is returned."
8448 (interactive "p")
8449 (gnus-summary-mark-forward n gnus-ticked-mark))
8450
8451(defalias 'gnus-summary-mark-as-unread-backward
8452 'gnus-summary-tick-article-backward)
8453(make-obsolete 'gnus-summary-mark-as-unread-backward
8454 'gnus-summary-tick-article-backward)
8455(defun gnus-summary-tick-article-backward (n)
8456 "Tick N articles backwards.
8457The difference between N and the number of articles ticked is returned."
8458 (interactive "p")
8459 (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8460
8461(defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8462(make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8463(defun gnus-summary-tick-article (&optional article clear-mark)
8464 "Mark current article as unread.
8465Optional 1st argument ARTICLE specifies article number to be marked as unread.
8466Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8467 (interactive)
8468 (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8469 gnus-ticked-mark)))
8470
8471(defun gnus-summary-mark-as-read-forward (n)
8472 "Mark N articles as read forwards.
8473If N is negative, mark backwards instead.
8474The difference between N and the actual number of articles marked is
8475returned."
8476 (interactive "p")
16409b0b 8477 (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
eec82323
LMI
8478
8479(defun gnus-summary-mark-as-read-backward (n)
8480 "Mark the N articles as read backwards.
8481The difference between N and the actual number of articles marked is
8482returned."
8483 (interactive "p")
16409b0b
GM
8484 (gnus-summary-mark-forward
8485 (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
eec82323
LMI
8486
8487(defun gnus-summary-mark-as-read (&optional article mark)
8488 "Mark current article as read.
8489ARTICLE specifies the article to be marked as read.
8490MARK specifies a string to be inserted at the beginning of the line."
8491 (gnus-summary-mark-article article mark))
8492
8493(defun gnus-summary-clear-mark-forward (n)
8494 "Clear marks from N articles forward.
8495If N is negative, clear backward instead.
8496The difference between N and the number of marks cleared is returned."
8497 (interactive "p")
8498 (gnus-summary-mark-forward n gnus-unread-mark))
8499
8500(defun gnus-summary-clear-mark-backward (n)
8501 "Clear marks from N articles backward.
8502The difference between N and the number of marks cleared is returned."
8503 (interactive "p")
8504 (gnus-summary-mark-forward (- n) gnus-unread-mark))
8505
8506(defun gnus-summary-mark-unread-as-read ()
8507 "Intended to be used by `gnus-summary-mark-article-hook'."
8508 (when (memq gnus-current-article gnus-newsgroup-unreads)
8509 (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8510
8511(defun gnus-summary-mark-read-and-unread-as-read ()
8512 "Intended to be used by `gnus-summary-mark-article-hook'."
8513 (let ((mark (gnus-summary-article-mark)))
8514 (when (or (gnus-unread-mark-p mark)
8515 (gnus-read-mark-p mark))
8516 (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8517
8518(defun gnus-summary-mark-region-as-read (point mark all)
8519 "Mark all unread articles between point and mark as read.
8520If given a prefix, mark all articles between point and mark as read,
8521even ticked and dormant ones."
8522 (interactive "r\nP")
8523 (save-excursion
8524 (let (article)
8525 (goto-char point)
8526 (beginning-of-line)
8527 (while (and
8528 (< (point) mark)
8529 (progn
8530 (when (or all
8531 (memq (setq article (gnus-summary-article-number))
8532 gnus-newsgroup-unreads))
8533 (gnus-summary-mark-article article gnus-del-mark))
8534 t)
8535 (gnus-summary-find-next))))))
8536
8537(defun gnus-summary-mark-below (score mark)
8538 "Mark articles with score less than SCORE with MARK."
8539 (interactive "P\ncMark: ")
eec82323
LMI
8540 (setq score (if score
8541 (prefix-numeric-value score)
8542 (or gnus-summary-default-score 0)))
8543 (save-excursion
8544 (set-buffer gnus-summary-buffer)
8545 (goto-char (point-min))
8546 (while
8547 (progn
8548 (and (< (gnus-summary-article-score) score)
8549 (gnus-summary-mark-article nil mark))
8550 (gnus-summary-find-next)))))
8551
8552(defun gnus-summary-kill-below (&optional score)
8553 "Mark articles with score below SCORE as read."
8554 (interactive "P")
eec82323
LMI
8555 (gnus-summary-mark-below score gnus-killed-mark))
8556
8557(defun gnus-summary-clear-above (&optional score)
8558 "Clear all marks from articles with score above SCORE."
8559 (interactive "P")
eec82323
LMI
8560 (gnus-summary-mark-above score gnus-unread-mark))
8561
8562(defun gnus-summary-tick-above (&optional score)
8563 "Tick all articles with score above SCORE."
8564 (interactive "P")
eec82323
LMI
8565 (gnus-summary-mark-above score gnus-ticked-mark))
8566
8567(defun gnus-summary-mark-above (score mark)
8568 "Mark articles with score over SCORE with MARK."
8569 (interactive "P\ncMark: ")
eec82323
LMI
8570 (setq score (if score
8571 (prefix-numeric-value score)
8572 (or gnus-summary-default-score 0)))
8573 (save-excursion
8574 (set-buffer gnus-summary-buffer)
8575 (goto-char (point-min))
8576 (while (and (progn
8577 (when (> (gnus-summary-article-score) score)
8578 (gnus-summary-mark-article nil mark))
8579 t)
8580 (gnus-summary-find-next)))))
8581
8582;; Suggested by Daniel Quinlan <quinlan@best.com>.
8583(defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8584(defun gnus-summary-limit-include-expunged (&optional no-error)
8585 "Display all the hidden articles that were expunged for low scores."
8586 (interactive)
eec82323
LMI
8587 (let ((buffer-read-only nil))
8588 (let ((scored gnus-newsgroup-scored)
8589 headers h)
8590 (while scored
8591 (unless (gnus-summary-goto-subject (caar scored))
8592 (and (setq h (gnus-summary-article-header (caar scored)))
8593 (< (cdar scored) gnus-summary-expunge-below)
8594 (push h headers)))
8595 (setq scored (cdr scored)))
8596 (if (not headers)
8597 (when (not no-error)
a8151ef7 8598 (error "No expunged articles hidden"))
eec82323
LMI
8599 (goto-char (point-min))
8600 (gnus-summary-prepare-unthreaded (nreverse headers))
8601 (goto-char (point-min))
8602 (gnus-summary-position-point)
8603 t))))
8604
8605(defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8606 "Mark all unread articles in this newsgroup as read.
8607If prefix argument ALL is non-nil, ticked and dormant articles will
8608also be marked as read.
8609If QUIETLY is non-nil, no questions will be asked.
8610If TO-HERE is non-nil, it should be a point in the buffer. All
8611articles before this point will be marked as read.
8612Note that this function will only catch up the unread article
8613in the current summary buffer limitation.
8614The number of articles marked as read is returned."
8615 (interactive "P")
eec82323
LMI
8616 (prog1
8617 (save-excursion
8618 (when (or quietly
8619 (not gnus-interactive-catchup) ;Without confirmation?
8620 gnus-expert-user
8621 (gnus-y-or-n-p
8622 (if all
8623 "Mark absolutely all articles as read? "
8624 "Mark all unread articles as read? ")))
8625 (if (and not-mark
8626 (not gnus-newsgroup-adaptive)
8627 (not gnus-newsgroup-auto-expire)
a8151ef7
LMI
8628 (not gnus-suppress-duplicates)
8629 (or (not gnus-use-cache)
6748645f 8630 (eq gnus-use-cache 'passive)))
eec82323
LMI
8631 (progn
8632 (when all
8633 (setq gnus-newsgroup-marked nil
8634 gnus-newsgroup-dormant nil))
6748645f 8635 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
eec82323
LMI
8636 ;; We actually mark all articles as canceled, which we
8637 ;; have to do when using auto-expiry or adaptive scoring.
8638 (gnus-summary-show-all-threads)
6748645f 8639 (when (gnus-summary-first-subject (not all) t)
eec82323
LMI
8640 (while (and
8641 (if to-here (< (point) to-here) t)
8642 (gnus-summary-mark-article-as-read gnus-catchup-mark)
6748645f 8643 (gnus-summary-find-next (not all) nil nil t))))
eec82323
LMI
8644 (gnus-set-mode-line 'summary))
8645 t))
8646 (gnus-summary-position-point)))
8647
8648(defun gnus-summary-catchup-to-here (&optional all)
8649 "Mark all unticked articles before the current one as read.
8650If ALL is non-nil, also mark ticked and dormant articles as read."
8651 (interactive "P")
eec82323
LMI
8652 (save-excursion
8653 (gnus-save-hidden-threads
8654 (let ((beg (point)))
8655 ;; We check that there are unread articles.
8656 (when (or all (gnus-summary-find-prev))
8657 (gnus-summary-catchup all t beg)))))
8658 (gnus-summary-position-point))
8659
8660(defun gnus-summary-catchup-all (&optional quietly)
8661 "Mark all articles in this newsgroup as read."
8662 (interactive "P")
eec82323
LMI
8663 (gnus-summary-catchup t quietly))
8664
8665(defun gnus-summary-catchup-and-exit (&optional all quietly)
16409b0b 8666 "Mark all unread articles in this group as read, then exit.
eec82323
LMI
8667If prefix argument ALL is non-nil, all articles are marked as read."
8668 (interactive "P")
eec82323
LMI
8669 (when (gnus-summary-catchup all quietly nil 'fast)
8670 ;; Select next newsgroup or exit.
6748645f
LMI
8671 (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8672 (eq gnus-auto-select-next 'quietly))
eec82323
LMI
8673 (gnus-summary-next-group nil)
8674 (gnus-summary-exit))))
8675
8676(defun gnus-summary-catchup-all-and-exit (&optional quietly)
8677 "Mark all articles in this newsgroup as read, and then exit."
8678 (interactive "P")
eec82323
LMI
8679 (gnus-summary-catchup-and-exit t quietly))
8680
eec82323
LMI
8681(defun gnus-summary-catchup-and-goto-next-group (&optional all)
8682 "Mark all articles in this group as read and select the next group.
8683If given a prefix, mark all articles, unread as well as ticked, as
8684read."
8685 (interactive "P")
eec82323
LMI
8686 (save-excursion
8687 (gnus-summary-catchup all))
16409b0b
GM
8688 (gnus-summary-next-group))
8689
8690;;;
8691;;; with article
8692;;;
8693
8694(defmacro gnus-with-article (article &rest forms)
8695 "Select ARTICLE and perform FORMS in the original article buffer.
8696Then replace the article with the result."
8697 `(progn
8698 ;; We don't want the article to be marked as read.
8699 (let (gnus-mark-article-hook)
8700 (gnus-summary-select-article t t nil ,article))
8701 (set-buffer gnus-original-article-buffer)
8702 ,@forms
8703 (if (not (gnus-check-backend-function
8704 'request-replace-article (car gnus-article-current)))
8705 (gnus-message 5 "Read-only group; not replacing")
8706 (unless (gnus-request-replace-article
8707 ,article (car gnus-article-current)
8708 (current-buffer) t)
8709 (error "Couldn't replace article")))
8710 ;; The cache and backlog have to be flushed somewhat.
8711 (when gnus-keep-backlog
8712 (gnus-backlog-remove-article
8713 (car gnus-article-current) (cdr gnus-article-current)))
8714 (when gnus-use-cache
8715 (gnus-cache-update-article
8716 (car gnus-article-current) (cdr gnus-article-current)))))
8717
8718(put 'gnus-with-article 'lisp-indent-function 1)
8719(put 'gnus-with-article 'edebug-form-spec '(form body))
eec82323
LMI
8720
8721;; Thread-based commands.
8722
8723(defun gnus-summary-articles-in-thread (&optional article)
8724 "Return a list of all articles in the current thread.
8725If ARTICLE is non-nil, return all articles in the thread that starts
8726with that article."
8727 (let* ((article (or article (gnus-summary-article-number)))
8728 (data (gnus-data-find-list article))
8729 (top-level (gnus-data-level (car data)))
8730 (top-subject
8731 (cond ((null gnus-thread-operation-ignore-subject)
8732 (gnus-simplify-subject-re
8733 (mail-header-subject (gnus-data-header (car data)))))
8734 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
8735 (gnus-simplify-subject-fuzzy
8736 (mail-header-subject (gnus-data-header (car data)))))
8737 (t nil)))
8738 (end-point (save-excursion
8739 (if (gnus-summary-go-to-next-thread)
8740 (point) (point-max))))
8741 articles)
8742 (while (and data
8743 (< (gnus-data-pos (car data)) end-point))
8744 (when (or (not top-subject)
8745 (string= top-subject
8746 (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
8747 (gnus-simplify-subject-fuzzy
8748 (mail-header-subject
8749 (gnus-data-header (car data))))
8750 (gnus-simplify-subject-re
8751 (mail-header-subject
8752 (gnus-data-header (car data)))))))
8753 (push (gnus-data-number (car data)) articles))
8754 (unless (and (setq data (cdr data))
8755 (> (gnus-data-level (car data)) top-level))
8756 (setq data nil)))
8757 ;; Return the list of articles.
8758 (nreverse articles)))
8759
8760(defun gnus-summary-rethread-current ()
8761 "Rethread the thread the current article is part of."
8762 (interactive)
eec82323
LMI
8763 (let* ((gnus-show-threads t)
8764 (article (gnus-summary-article-number))
8765 (id (mail-header-id (gnus-summary-article-header)))
8766 (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
8767 (unless id
8768 (error "No article on the current line"))
8769 (gnus-rebuild-thread id)
8770 (gnus-summary-goto-subject article)))
8771
8772(defun gnus-summary-reparent-thread ()
8773 "Make the current article child of the marked (or previous) article.
8774
8775Note that the re-threading will only work if `gnus-thread-ignore-subject'
8776is non-nil or the Subject: of both articles are the same."
8777 (interactive)
8778 (unless (not (gnus-group-read-only-p))
a8151ef7 8779 (error "The current newsgroup does not support article editing"))
eec82323 8780 (unless (<= (length gnus-newsgroup-processable) 1)
a8151ef7 8781 (error "No more than one article may be marked"))
eec82323
LMI
8782 (save-window-excursion
8783 (let ((gnus-article-buffer " *reparent*")
8784 (current-article (gnus-summary-article-number))
8785 ;; First grab the marked article, otherwise one line up.
8786 (parent-article (if (not (null gnus-newsgroup-processable))
8787 (car gnus-newsgroup-processable)
8788 (save-excursion
8789 (if (eq (forward-line -1) 0)
8790 (gnus-summary-article-number)
a8151ef7 8791 (error "Beginning of summary buffer"))))))
eec82323 8792 (unless (not (eq current-article parent-article))
a8151ef7 8793 (error "An article may not be self-referential"))
eec82323
LMI
8794 (let ((message-id (mail-header-id
8795 (gnus-summary-article-header parent-article))))
8796 (unless (and message-id (not (equal message-id "")))
a8151ef7 8797 (error "No message-id in desired parent"))
16409b0b
GM
8798 (gnus-with-article current-article
8799 (save-restriction
eec82323 8800 (goto-char (point-min))
16409b0b 8801 (message-narrow-to-head)
6748645f
LMI
8802 (if (re-search-forward "^References: " nil t)
8803 (progn
8804 (re-search-forward "^[^ \t]" nil t)
8805 (forward-line -1)
8806 (end-of-line)
8807 (insert " " message-id))
16409b0b 8808 (insert "References: " message-id "\n"))))
eec82323
LMI
8809 (set-buffer gnus-summary-buffer)
8810 (gnus-summary-unmark-all-processable)
6748645f 8811 (gnus-summary-update-article current-article)
eec82323 8812 (gnus-summary-rethread-current)
a8151ef7 8813 (gnus-message 3 "Article %d is now the child of article %d"
eec82323
LMI
8814 current-article parent-article)))))
8815
8816(defun gnus-summary-toggle-threads (&optional arg)
8817 "Toggle showing conversation threads.
8818If ARG is positive number, turn showing conversation threads on."
8819 (interactive "P")
eec82323
LMI
8820 (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
8821 (setq gnus-show-threads
8822 (if (null arg) (not gnus-show-threads)
8823 (> (prefix-numeric-value arg) 0)))
8824 (gnus-summary-prepare)
8825 (gnus-summary-goto-subject current)
8826 (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
8827 (gnus-summary-position-point)))
8828
8829(defun gnus-summary-show-all-threads ()
8830 "Show all threads."
8831 (interactive)
eec82323
LMI
8832 (save-excursion
8833 (let ((buffer-read-only nil))
8834 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
8835 (gnus-summary-position-point))
8836
8837(defun gnus-summary-show-thread ()
8838 "Show thread subtrees.
8839Returns nil if no thread was there to be shown."
8840 (interactive)
eec82323
LMI
8841 (let ((buffer-read-only nil)
8842 (orig (point))
8843 ;; first goto end then to beg, to have point at beg after let
8844 (end (progn (end-of-line) (point)))
8845 (beg (progn (beginning-of-line) (point))))
8846 (prog1
8847 ;; Any hidden lines here?
8848 (search-forward "\r" end t)
8849 (subst-char-in-region beg end ?\^M ?\n t)
8850 (goto-char orig)
8851 (gnus-summary-position-point))))
8852
8853(defun gnus-summary-hide-all-threads ()
8854 "Hide all thread subtrees."
8855 (interactive)
eec82323
LMI
8856 (save-excursion
8857 (goto-char (point-min))
8858 (gnus-summary-hide-thread)
8859 (while (zerop (gnus-summary-next-thread 1 t))
8860 (gnus-summary-hide-thread)))
8861 (gnus-summary-position-point))
8862
8863(defun gnus-summary-hide-thread ()
8864 "Hide thread subtrees.
8865Returns nil if no threads were there to be hidden."
8866 (interactive)
eec82323
LMI
8867 (let ((buffer-read-only nil)
8868 (start (point))
8869 (article (gnus-summary-article-number)))
8870 (goto-char start)
8871 ;; Go forward until either the buffer ends or the subthread
8872 ;; ends.
8873 (when (and (not (eobp))
8874 (or (zerop (gnus-summary-next-thread 1 t))
8875 (goto-char (point-max))))
8876 (prog1
8877 (if (and (> (point) start)
8878 (search-backward "\n" start t))
8879 (progn
8880 (subst-char-in-region start (point) ?\n ?\^M)
8881 (gnus-summary-goto-subject article))
8882 (goto-char start)
16409b0b 8883 nil)))))
eec82323
LMI
8884
8885(defun gnus-summary-go-to-next-thread (&optional previous)
8886 "Go to the same level (or less) next thread.
8887If PREVIOUS is non-nil, go to previous thread instead.
8888Return the article number moved to, or nil if moving was impossible."
8889 (let ((level (gnus-summary-thread-level))
8890 (way (if previous -1 1))
8891 (beg (point)))
8892 (forward-line way)
8893 (while (and (not (eobp))
8894 (< level (gnus-summary-thread-level)))
8895 (forward-line way))
8896 (if (eobp)
8897 (progn
8898 (goto-char beg)
8899 nil)
8900 (setq beg (point))
8901 (prog1
8902 (gnus-summary-article-number)
8903 (goto-char beg)))))
8904
8905(defun gnus-summary-next-thread (n &optional silent)
8906 "Go to the same level next N'th thread.
8907If N is negative, search backward instead.
8908Returns the difference between N and the number of skips actually
8909done.
8910
8911If SILENT, don't output messages."
8912 (interactive "p")
eec82323
LMI
8913 (let ((backward (< n 0))
8914 (n (abs n)))
8915 (while (and (> n 0)
8916 (gnus-summary-go-to-next-thread backward))
8917 (decf n))
8918 (unless silent
8919 (gnus-summary-position-point))
8920 (when (and (not silent) (/= 0 n))
8921 (gnus-message 7 "No more threads"))
8922 n))
8923
8924(defun gnus-summary-prev-thread (n)
8925 "Go to the same level previous N'th thread.
8926Returns the difference between N and the number of skips actually
8927done."
8928 (interactive "p")
eec82323
LMI
8929 (gnus-summary-next-thread (- n)))
8930
8931(defun gnus-summary-go-down-thread ()
8932 "Go down one level in the current thread."
8933 (let ((children (gnus-summary-article-children)))
8934 (when children
8935 (gnus-summary-goto-subject (car children)))))
8936
8937(defun gnus-summary-go-up-thread ()
8938 "Go up one level in the current thread."
8939 (let ((parent (gnus-summary-article-parent)))
8940 (when parent
8941 (gnus-summary-goto-subject parent))))
8942
8943(defun gnus-summary-down-thread (n)
8944 "Go down thread N steps.
8945If N is negative, go up instead.
8946Returns the difference between N and how many steps down that were
8947taken."
8948 (interactive "p")
eec82323
LMI
8949 (let ((up (< n 0))
8950 (n (abs n)))
8951 (while (and (> n 0)
8952 (if up (gnus-summary-go-up-thread)
8953 (gnus-summary-go-down-thread)))
8954 (setq n (1- n)))
8955 (gnus-summary-position-point)
8956 (when (/= 0 n)
8957 (gnus-message 7 "Can't go further"))
8958 n))
8959
8960(defun gnus-summary-up-thread (n)
8961 "Go up thread N steps.
8962If N is negative, go up instead.
8963Returns the difference between N and how many steps down that were
8964taken."
8965 (interactive "p")
eec82323
LMI
8966 (gnus-summary-down-thread (- n)))
8967
8968(defun gnus-summary-top-thread ()
8969 "Go to the top of the thread."
8970 (interactive)
eec82323
LMI
8971 (while (gnus-summary-go-up-thread))
8972 (gnus-summary-article-number))
8973
8974(defun gnus-summary-kill-thread (&optional unmark)
8975 "Mark articles under current thread as read.
8976If the prefix argument is positive, remove any kinds of marks.
8977If the prefix argument is negative, tick articles instead."
8978 (interactive "P")
eec82323
LMI
8979 (when unmark
8980 (setq unmark (prefix-numeric-value unmark)))
8981 (let ((articles (gnus-summary-articles-in-thread)))
8982 (save-excursion
8983 ;; Expand the thread.
8984 (gnus-summary-show-thread)
8985 ;; Mark all the articles.
8986 (while articles
8987 (gnus-summary-goto-subject (car articles))
8988 (cond ((null unmark)
8989 (gnus-summary-mark-article-as-read gnus-killed-mark))
8990 ((> unmark 0)
8991 (gnus-summary-mark-article-as-unread gnus-unread-mark))
8992 (t
8993 (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
8994 (setq articles (cdr articles))))
8995 ;; Hide killed subtrees.
8996 (and (null unmark)
8997 gnus-thread-hide-killed
8998 (gnus-summary-hide-thread))
8999 ;; If marked as read, go to next unread subject.
9000 (when (null unmark)
9001 ;; Go to next unread subject.
9002 (gnus-summary-next-subject 1 t)))
9003 (gnus-set-mode-line 'summary))
9004
9005;; Summary sorting commands
9006
9007(defun gnus-summary-sort-by-number (&optional reverse)
9008 "Sort the summary buffer by article number.
9009Argument REVERSE means reverse order."
9010 (interactive "P")
9011 (gnus-summary-sort 'number reverse))
9012
9013(defun gnus-summary-sort-by-author (&optional reverse)
9014 "Sort the summary buffer by author name alphabetically.
16409b0b 9015If `case-fold-search' is non-nil, case of letters is ignored.
eec82323
LMI
9016Argument REVERSE means reverse order."
9017 (interactive "P")
9018 (gnus-summary-sort 'author reverse))
9019
9020(defun gnus-summary-sort-by-subject (&optional reverse)
9021 "Sort the summary buffer by subject alphabetically. `Re:'s are ignored.
16409b0b 9022If `case-fold-search' is non-nil, case of letters is ignored.
eec82323
LMI
9023Argument REVERSE means reverse order."
9024 (interactive "P")
9025 (gnus-summary-sort 'subject reverse))
9026
9027(defun gnus-summary-sort-by-date (&optional reverse)
9028 "Sort the summary buffer by date.
9029Argument REVERSE means reverse order."
9030 (interactive "P")
9031 (gnus-summary-sort 'date reverse))
9032
9033(defun gnus-summary-sort-by-score (&optional reverse)
9034 "Sort the summary buffer by score.
9035Argument REVERSE means reverse order."
9036 (interactive "P")
9037 (gnus-summary-sort 'score reverse))
9038
9039(defun gnus-summary-sort-by-lines (&optional reverse)
16409b0b 9040 "Sort the summary buffer by the number of lines.
eec82323
LMI
9041Argument REVERSE means reverse order."
9042 (interactive "P")
9043 (gnus-summary-sort 'lines reverse))
9044
16409b0b
GM
9045(defun gnus-summary-sort-by-chars (&optional reverse)
9046 "Sort the summary buffer by article length.
9047Argument REVERSE means reverse order."
9048 (interactive "P")
9049 (gnus-summary-sort 'chars reverse))
9050
eec82323
LMI
9051(defun gnus-summary-sort (predicate reverse)
9052 "Sort summary buffer by PREDICATE. REVERSE means reverse order."
eec82323
LMI
9053 (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9054 (article (intern (format "gnus-article-sort-by-%s" predicate)))
9055 (gnus-thread-sort-functions
16409b0b
GM
9056 (if (not reverse)
9057 thread
9058 `(lambda (t1 t2)
9059 (,thread t2 t1))))
9060 (gnus-sort-gathered-threads-function
9061 gnus-thread-sort-functions)
eec82323 9062 (gnus-article-sort-functions
16409b0b
GM
9063 (if (not reverse)
9064 article
9065 `(lambda (t1 t2)
9066 (,article t2 t1))))
eec82323
LMI
9067 (buffer-read-only)
9068 (gnus-summary-prepare-hook nil))
9069 ;; We do the sorting by regenerating the threads.
9070 (gnus-summary-prepare)
9071 ;; Hide subthreads if needed.
9072 (when (and gnus-show-threads gnus-thread-hide-subtree)
9073 (gnus-summary-hide-all-threads))))
9074
9075;; Summary saving commands.
9076
9077(defun gnus-summary-save-article (&optional n not-saved)
9078 "Save the current article using the default saver function.
9079If N is a positive number, save the N next articles.
9080If N is a negative number, save the N previous articles.
9081If N is nil and any articles have been marked with the process mark,
9082save those articles instead.
9083The variable `gnus-default-article-saver' specifies the saver function."
9084 (interactive "P")
eec82323
LMI
9085 (let* ((articles (gnus-summary-work-articles n))
9086 (save-buffer (save-excursion
9087 (nnheader-set-temp-buffer " *Gnus Save*")))
9088 (num (length articles))
16409b0b
GM
9089 header file)
9090 (dolist (article articles)
9091 (setq header (gnus-summary-article-header article))
eec82323
LMI
9092 (if (not (vectorp header))
9093 ;; This is a pseudo-article.
9094 (if (assq 'name header)
9095 (gnus-copy-file (cdr (assq 'name header)))
9096 (gnus-message 1 "Article %d is unsaveable" article))
9097 ;; This is a real article.
9098 (save-window-excursion
9099 (gnus-summary-select-article t nil nil article))
9100 (save-excursion
9101 (set-buffer save-buffer)
9102 (erase-buffer)
9103 (insert-buffer-substring gnus-original-article-buffer))
9104 (setq file (gnus-article-save save-buffer file num))
9105 (gnus-summary-remove-process-mark article)
9106 (unless not-saved
9107 (gnus-summary-set-saved-mark article))))
9108 (gnus-kill-buffer save-buffer)
9109 (gnus-summary-position-point)
9110 (gnus-set-mode-line 'summary)
9111 n))
9112
9113(defun gnus-summary-pipe-output (&optional arg)
9114 "Pipe the current article to a subprocess.
9115If N is a positive number, pipe the N next articles.
9116If N is a negative number, pipe the N previous articles.
9117If N is nil and any articles have been marked with the process mark,
9118pipe those articles instead."
9119 (interactive "P")
eec82323
LMI
9120 (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9121 (gnus-summary-save-article arg t))
9122 (gnus-configure-windows 'pipe))
9123
9124(defun gnus-summary-save-article-mail (&optional arg)
9125 "Append the current article to an mail file.
9126If N is a positive number, save the N next articles.
9127If N is a negative number, save the N previous articles.
9128If N is nil and any articles have been marked with the process mark,
9129save those articles instead."
9130 (interactive "P")
eec82323
LMI
9131 (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9132 (gnus-summary-save-article arg)))
9133
9134(defun gnus-summary-save-article-rmail (&optional arg)
9135 "Append the current article to an rmail file.
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."
9140 (interactive "P")
eec82323
LMI
9141 (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9142 (gnus-summary-save-article arg)))
9143
9144(defun gnus-summary-save-article-file (&optional arg)
9145 "Append the current article to a file.
9146If N is a positive number, save the N next articles.
9147If N is a negative number, save the N previous articles.
9148If N is nil and any articles have been marked with the process mark,
9149save those articles instead."
9150 (interactive "P")
eec82323
LMI
9151 (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9152 (gnus-summary-save-article arg)))
9153
9154(defun gnus-summary-write-article-file (&optional arg)
9155 "Write the current article to a file, deleting the previous file.
9156If N is a positive number, save the N next articles.
9157If N is a negative number, save the N previous articles.
9158If N is nil and any articles have been marked with the process mark,
9159save those articles instead."
9160 (interactive "P")
eec82323
LMI
9161 (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9162 (gnus-summary-save-article arg)))
9163
9164(defun gnus-summary-save-article-body-file (&optional arg)
9165 "Append the current article body to a file.
9166If N is a positive number, save the N next articles.
9167If N is a negative number, save the N previous articles.
9168If N is nil and any articles have been marked with the process mark,
9169save those articles instead."
9170 (interactive "P")
eec82323
LMI
9171 (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9172 (gnus-summary-save-article arg)))
9173
9174(defun gnus-summary-pipe-message (program)
9175 "Pipe the current article through PROGRAM."
9176 (interactive "sProgram: ")
eec82323 9177 (gnus-summary-select-article)
6748645f 9178 (let ((mail-header-separator ""))
eec82323
LMI
9179 (gnus-eval-in-buffer-window gnus-article-buffer
9180 (save-restriction
9181 (widen)
9182 (let ((start (window-start))
9183 buffer-read-only)
9184 (message-pipe-buffer-body program)
9185 (set-window-start (get-buffer-window (current-buffer)) start))))))
9186
9187(defun gnus-get-split-value (methods)
9188 "Return a value based on the split METHODS."
9189 (let (split-name method result match)
9190 (when methods
9191 (save-excursion
9192 (set-buffer gnus-original-article-buffer)
9193 (save-restriction
9194 (nnheader-narrow-to-headers)
d4dfaa19 9195 (while (and methods (not split-name))
eec82323
LMI
9196 (goto-char (point-min))
9197 (setq method (pop methods))
9198 (setq match (car method))
9199 (when (cond
9200 ((stringp match)
9201 ;; Regular expression.
9202 (ignore-errors
9203 (re-search-forward match nil t)))
9204 ((gnus-functionp match)
9205 ;; Function.
9206 (save-restriction
9207 (widen)
9208 (setq result (funcall match gnus-newsgroup-name))))
9209 ((consp match)
9210 ;; Form.
9211 (save-restriction
9212 (widen)
9213 (setq result (eval match)))))
d4dfaa19 9214 (setq split-name (cdr method))
eec82323
LMI
9215 (cond ((stringp result)
9216 (push (expand-file-name
9217 result gnus-article-save-directory)
9218 split-name))
9219 ((consp result)
9220 (setq split-name (append result split-name)))))))))
16409b0b 9221 (nreverse split-name)))
eec82323
LMI
9222
9223(defun gnus-valid-move-group-p (group)
9224 (and (boundp group)
9225 (symbol-name group)
16409b0b
GM
9226 (symbol-value group)
9227 (gnus-get-function (gnus-find-method-for-group
9228 (symbol-name group)) 'request-accept-article t)))
eec82323
LMI
9229
9230(defun gnus-read-move-group-name (prompt default articles prefix)
9231 "Read a group name."
9232 (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9233 (minibuffer-confirm-incomplete nil) ; XEmacs
9234 (prom
9235 (format "%s %s to:"
9236 prompt
9237 (if (> (length articles) 1)
9238 (format "these %d articles" (length articles))
9239 "this article")))
9240 (to-newsgroup
9241 (cond
9242 ((null split-name)
9243 (gnus-completing-read default prom
9244 gnus-active-hashtb
9245 'gnus-valid-move-group-p
9246 nil prefix
9247 'gnus-group-history))
9248 ((= 1 (length split-name))
9249 (gnus-completing-read (car split-name) prom
9250 gnus-active-hashtb
9251 'gnus-valid-move-group-p
9252 nil nil
9253 'gnus-group-history))
9254 (t
9255 (gnus-completing-read nil prom
9256 (mapcar (lambda (el) (list el))
9257 (nreverse split-name))
9258 nil nil nil
16409b0b
GM
9259 'gnus-group-history))))
9260 (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
eec82323
LMI
9261 (when to-newsgroup
9262 (if (or (string= to-newsgroup "")
9263 (string= to-newsgroup prefix))
9264 (setq to-newsgroup default))
9265 (unless to-newsgroup
9266 (error "No group name entered"))
9267 (or (gnus-active to-newsgroup)
16409b0b 9268 (gnus-activate-group to-newsgroup nil nil to-method)
eec82323
LMI
9269 (if (gnus-y-or-n-p (format "No such group: %s. Create it? "
9270 to-newsgroup))
16409b0b
GM
9271 (or (and (gnus-request-create-group to-newsgroup to-method)
9272 (gnus-activate-group
9273 to-newsgroup nil nil to-method)
9274 (gnus-subscribe-group to-newsgroup))
eec82323
LMI
9275 (error "Couldn't create group %s" to-newsgroup)))
9276 (error "No such group: %s" to-newsgroup)))
9277 to-newsgroup))
9278
16409b0b
GM
9279(defun gnus-summary-save-parts (type dir n &optional reverse)
9280 "Save parts matching TYPE to DIR.
9281If REVERSE, save parts that do not match TYPE."
9282 (interactive
8b93df01
DL
9283 (list (read-string "Save parts of type: "
9284 (or (car gnus-summary-save-parts-type-history)
9285 gnus-summary-save-parts-default-mime)
9286 'gnus-summary-save-parts-type-history)
9287 (setq gnus-summary-save-parts-last-directory
9288 (read-file-name "Save to directory: "
9289 gnus-summary-save-parts-last-directory
9290 nil t))
16409b0b
GM
9291 current-prefix-arg))
9292 (gnus-summary-iterate n
9293 (let ((gnus-display-mime-function nil)
9294 (gnus-inhibit-treatment t))
9295 (gnus-summary-select-article))
9296 (save-excursion
9297 (set-buffer gnus-article-buffer)
9298 (let ((handles (or gnus-article-mime-handles
9299 (mm-dissect-buffer) (mm-uu-dissect))))
9300 (when handles
9301 (gnus-summary-save-parts-1 type dir handles reverse)
9302 (unless gnus-article-mime-handles ;; Don't destroy this case.
9303 (mm-destroy-parts handles)))))))
9304
9305(defun gnus-summary-save-parts-1 (type dir handle reverse)
9306 (if (stringp (car handle))
9307 (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9308 (cdr handle))
9309 (when (if reverse
9310 (not (string-match type (mm-handle-media-type handle)))
9311 (string-match type (mm-handle-media-type handle)))
9312 (let ((file (expand-file-name
9313 (file-name-nondirectory
9314 (or
9315 (mail-content-type-get
9316 (mm-handle-disposition handle) 'filename)
9317 (concat gnus-newsgroup-name
9318 "." (number-to-string
9319 (cdr gnus-article-current)))))
9320 dir)))
9321 (unless (file-exists-p file)
9322 (mm-save-part-to-file handle file))))))
9323
eec82323
LMI
9324;; Summary extract commands
9325
9326(defun gnus-summary-insert-pseudos (pslist &optional not-view)
9327 (let ((buffer-read-only nil)
9328 (article (gnus-summary-article-number))
9329 after-article b e)
9330 (unless (gnus-summary-goto-subject article)
9331 (error "No such article: %d" article))
9332 (gnus-summary-position-point)
9333 ;; If all commands are to be bunched up on one line, we collect
9334 ;; them here.
9335 (unless gnus-view-pseudos-separately
9336 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9337 files action)
9338 (while ps
9339 (setq action (cdr (assq 'action (car ps))))
9340 (setq files (list (cdr (assq 'name (car ps)))))
9341 (while (and ps (cdr ps)
9342 (string= (or action "1")
9343 (or (cdr (assq 'action (cadr ps))) "2")))
9344 (push (cdr (assq 'name (cadr ps))) files)
9345 (setcdr ps (cddr ps)))
9346 (when files
9347 (when (not (string-match "%s" action))
9348 (push " " files))
9349 (push " " files)
9350 (when (assq 'execute (car ps))
9351 (setcdr (assq 'execute (car ps))
9352 (funcall (if (string-match "%s" action)
9353 'format 'concat)
9354 action
9355 (mapconcat
9356 (lambda (f)
9357 (if (equal f " ")
9358 f
16409b0b 9359 (mm-quote-arg f)))
eec82323
LMI
9360 files " ")))))
9361 (setq ps (cdr ps)))))
9362 (if (and gnus-view-pseudos (not not-view))
9363 (while pslist
9364 (when (assq 'execute (car pslist))
9365 (gnus-execute-command (cdr (assq 'execute (car pslist)))
9366 (eq gnus-view-pseudos 'not-confirm)))
9367 (setq pslist (cdr pslist)))
9368 (save-excursion
9369 (while pslist
9370 (setq after-article (or (cdr (assq 'article (car pslist)))
9371 (gnus-summary-article-number)))
9372 (gnus-summary-goto-subject after-article)
9373 (forward-line 1)
9374 (setq b (point))
9375 (insert " " (file-name-nondirectory
9376 (cdr (assq 'name (car pslist))))
9377 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9378 (setq e (point))
9379 (forward-line -1) ; back to `b'
9380 (gnus-add-text-properties
9381 b (1- e) (list 'gnus-number gnus-reffed-article-number
9382 gnus-mouse-face-prop gnus-mouse-face))
9383 (gnus-data-enter
9384 after-article gnus-reffed-article-number
9385 gnus-unread-mark b (car pslist) 0 (- e b))
9386 (push gnus-reffed-article-number gnus-newsgroup-unreads)
9387 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9388 (setq pslist (cdr pslist)))))))
9389
9390(defun gnus-pseudos< (p1 p2)
9391 (let ((c1 (cdr (assq 'action p1)))
9392 (c2 (cdr (assq 'action p2))))
9393 (and c1 c2 (string< c1 c2))))
9394
9395(defun gnus-request-pseudo-article (props)
9396 (cond ((assq 'execute props)
9397 (gnus-execute-command (cdr (assq 'execute props)))))
9398 (let ((gnus-current-article (gnus-summary-article-number)))
6748645f 9399 (gnus-run-hooks 'gnus-mark-article-hook)))
eec82323
LMI
9400
9401(defun gnus-execute-command (command &optional automatic)
9402 (save-excursion
9403 (gnus-article-setup-buffer)
9404 (set-buffer gnus-article-buffer)
9405 (setq buffer-read-only nil)
a8151ef7
LMI
9406 (let ((command (if automatic command
9407 (read-string "Command: " (cons command 0)))))
eec82323
LMI
9408 (erase-buffer)
9409 (insert "$ " command "\n\n")
9410 (if gnus-view-pseudo-asynchronously
9411 (start-process "gnus-execute" (current-buffer) shell-file-name
9412 shell-command-switch command)
9413 (call-process shell-file-name nil t nil
9414 shell-command-switch command)))))
9415
9416;; Summary kill commands.
9417
9418(defun gnus-summary-edit-global-kill (article)
9419 "Edit the \"global\" kill file."
9420 (interactive (list (gnus-summary-article-number)))
eec82323
LMI
9421 (gnus-group-edit-global-kill article))
9422
9423(defun gnus-summary-edit-local-kill ()
9424 "Edit a local kill file applied to the current newsgroup."
9425 (interactive)
eec82323 9426 (setq gnus-current-headers (gnus-summary-article-header))
eec82323
LMI
9427 (gnus-group-edit-local-kill
9428 (gnus-summary-article-number) gnus-newsgroup-name))
9429
9430;;; Header reading.
9431
9432(defun gnus-read-header (id &optional header)
9433 "Read the headers of article ID and enter them into the Gnus system."
9434 (let ((group gnus-newsgroup-name)
9435 (gnus-override-method
16409b0b
GM
9436 (or
9437 gnus-override-method
9438 (and (gnus-news-group-p gnus-newsgroup-name)
9439 (car (gnus-refer-article-methods)))))
eec82323
LMI
9440 where)
9441 ;; First we check to see whether the header in question is already
9442 ;; fetched.
9443 (if (stringp id)
9444 ;; This is a Message-ID.
9445 (setq header (or header (gnus-id-to-header id)))
9446 ;; This is an article number.
9447 (setq header (or header (gnus-summary-article-header id))))
9448 (if (and header
9449 (not (gnus-summary-article-sparse-p (mail-header-number header))))
9450 ;; We have found the header.
9451 header
6748645f
LMI
9452 ;; If this is a sparse article, we have to nix out its
9453 ;; previous entry in the thread hashtb.
9454 (when (and header
9455 (gnus-summary-article-sparse-p (mail-header-number header)))
9456 (let* ((parent (gnus-parent-id (mail-header-references header)))
9457 (thread (and parent (gnus-id-to-thread parent))))
9458 (when thread
9459 (delq (assq header thread) thread))))
eec82323
LMI
9460 ;; We have to really fetch the header to this article.
9461 (save-excursion
9462 (set-buffer nntp-server-buffer)
9463 (when (setq where (gnus-request-head id group))
9464 (nnheader-fold-continuation-lines)
9465 (goto-char (point-max))
9466 (insert ".\n")
9467 (goto-char (point-min))
9468 (insert "211 ")
9469 (princ (cond
9470 ((numberp id) id)
9471 ((cdr where) (cdr where))
9472 (header (mail-header-number header))
9473 (t gnus-reffed-article-number))
9474 (current-buffer))
9475 (insert " Article retrieved.\n"))
9476 (if (or (not where)
9477 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9478 () ; Malformed head.
9479 (unless (gnus-summary-article-sparse-p (mail-header-number header))
9480 (when (and (stringp id)
9481 (not (string= (gnus-group-real-name group)
9482 (car where))))
9483 ;; If we fetched by Message-ID and the article came
9484 ;; from a different group, we fudge some bogus article
9485 ;; numbers for this article.
9486 (mail-header-set-number header gnus-reffed-article-number))
9487 (save-excursion
9488 (set-buffer gnus-summary-buffer)
9489 (decf gnus-reffed-article-number)
9490 (gnus-remove-header (mail-header-number header))
9491 (push header gnus-newsgroup-headers)
9492 (setq gnus-current-headers header)
9493 (push (mail-header-number header) gnus-newsgroup-limit)))
9494 header)))))
9495
9496(defun gnus-remove-header (number)
9497 "Remove header NUMBER from `gnus-newsgroup-headers'."
9498 (if (and gnus-newsgroup-headers
9499 (= number (mail-header-number (car gnus-newsgroup-headers))))
9500 (pop gnus-newsgroup-headers)
9501 (let ((headers gnus-newsgroup-headers))
9502 (while (and (cdr headers)
9503 (not (= number (mail-header-number (cadr headers)))))
9504 (pop headers))
9505 (when (cdr headers)
9506 (setcdr headers (cddr headers))))))
9507
9508;;;
9509;;; summary highlights
9510;;;
9511
9512(defun gnus-highlight-selected-summary ()
16409b0b 9513 "Highlight selected article in summary buffer."
eec82323 9514 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
eec82323
LMI
9515 (when gnus-summary-selected-face
9516 (save-excursion
9517 (let* ((beg (progn (beginning-of-line) (point)))
9518 (end (progn (end-of-line) (point)))
9519 ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9520 (from (if (get-text-property beg gnus-mouse-face-prop)
9521 beg
9522 (or (next-single-property-change
9523 beg gnus-mouse-face-prop nil end)
9524 beg)))
9525 (to
9526 (if (= from end)
9527 (- from 2)
9528 (or (next-single-property-change
9529 from gnus-mouse-face-prop nil end)
9530 end))))
9531 ;; If no mouse-face prop on line we will have to = from = end,
9532 ;; so we highlight the entire line instead.
9533 (when (= (+ to 2) from)
9534 (setq from beg)
9535 (setq to end))
9536 (if gnus-newsgroup-selected-overlay
9537 ;; Move old overlay.
9538 (gnus-move-overlay
9539 gnus-newsgroup-selected-overlay from to (current-buffer))
9540 ;; Create new overlay.
9541 (gnus-overlay-put
9542 (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9543 'face gnus-summary-selected-face))))))
9544
9545;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9546(defun gnus-summary-highlight-line ()
9547 "Highlight current line according to `gnus-summary-highlight'."
9548 (let* ((list gnus-summary-highlight)
9549 (p (point))
9550 (end (progn (end-of-line) (point)))
9551 ;; now find out where the line starts and leave point there.
9552 (beg (progn (beginning-of-line) (point)))
9553 (article (gnus-summary-article-number))
9554 (score (or (cdr (assq (or article gnus-current-article)
9555 gnus-newsgroup-scored))
9556 gnus-summary-default-score 0))
9557 (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9558 (inhibit-read-only t))
9559 ;; Eval the cars of the lists until we find a match.
9560 (let ((default gnus-summary-default-score))
9561 (while (and list
9562 (not (eval (caar list))))
9563 (setq list (cdr list))))
9564 (let ((face (cdar list)))
9565 (unless (eq face (get-text-property beg 'face))
6748645f 9566 (gnus-put-text-property-excluding-characters-with-faces
eec82323
LMI
9567 beg end 'face
9568 (setq face (if (boundp face) (symbol-value face) face)))
9569 (when gnus-summary-highlight-line-function
9570 (funcall gnus-summary-highlight-line-function article face))))
9571 (goto-char p)))
9572
6748645f 9573(defun gnus-update-read-articles (group unread &optional compute)
eec82323
LMI
9574 "Update the list of read articles in GROUP."
9575 (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9576 (entry (gnus-gethash group gnus-newsrc-hashtb))
9577 (info (nth 2 entry))
9578 (prev 1)
9579 (unread (sort (copy-sequence unread) '<))
9580 read)
9581 (if (or (not info) (not active))
9582 ;; There is no info on this group if it was, in fact,
9583 ;; killed. Gnus stores no information on killed groups, so
9584 ;; there's nothing to be done.
9585 ;; One could store the information somewhere temporarily,
9586 ;; perhaps... Hmmm...
9587 ()
9588 ;; Remove any negative articles numbers.
9589 (while (and unread (< (car unread) 0))
9590 (setq unread (cdr unread)))
9591 ;; Remove any expired article numbers
9592 (while (and unread (< (car unread) (car active)))
9593 (setq unread (cdr unread)))
9594 ;; Compute the ranges of read articles by looking at the list of
9595 ;; unread articles.
9596 (while unread
9597 (when (/= (car unread) prev)
9598 (push (if (= prev (1- (car unread))) prev
9599 (cons prev (1- (car unread))))
9600 read))
9601 (setq prev (1+ (car unread)))
9602 (setq unread (cdr unread)))
9603 (when (<= prev (cdr active))
9604 (push (cons prev (cdr active)) read))
16409b0b 9605 (setq read (if (> (length read) 1) (nreverse read) read))
6748645f 9606 (if compute
16409b0b 9607 read
6748645f 9608 (save-excursion
16409b0b
GM
9609 (let (setmarkundo)
9610 ;; Propagate the read marks to the backend.
9611 (when (gnus-check-backend-function 'request-set-mark group)
9612 (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9613 (add (gnus-remove-from-range read (gnus-info-read info))))
9614 (when (or add del)
9615 (unless (gnus-check-group group)
9616 (error "Can't open server for %s" group))
9617 (gnus-request-set-mark
9618 group (delq nil (list (if add (list add 'add '(read)))
9619 (if del (list del 'del '(read))))))
9620 (setq setmarkundo
9621 `(gnus-request-set-mark
9622 ,group
9623 ',(delq nil (list
9624 (if del (list del 'add '(read)))
9625 (if add (list add 'del '(read))))))))))
9626 (set-buffer gnus-group-buffer)
9627 (gnus-undo-register
9628 `(progn
9629 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9630 (gnus-info-set-read ',info ',(gnus-info-read info))
9631 (gnus-get-unread-articles-in-group ',info
9632 (gnus-active ,group))
9633 (gnus-group-update-group ,group t)
9634 ,setmarkundo))))
6748645f 9635 ;; Enter this list into the group info.
16409b0b 9636 (gnus-info-set-read info read)
6748645f
LMI
9637 ;; Set the number of unread articles in gnus-newsrc-hashtb.
9638 (gnus-get-unread-articles-in-group info (gnus-active group))
9639 t))))
eec82323
LMI
9640
9641(defun gnus-offer-save-summaries ()
9642 "Offer to save all active summary buffers."
9643 (save-excursion
9644 (let ((buflist (buffer-list))
9645 buffers bufname)
9646 ;; Go through all buffers and find all summaries.
9647 (while buflist
9648 (and (setq bufname (buffer-name (car buflist)))
9649 (string-match "Summary" bufname)
9650 (save-excursion
9651 (set-buffer bufname)
9652 ;; We check that this is, indeed, a summary buffer.
9653 (and (eq major-mode 'gnus-summary-mode)
9654 ;; Also make sure this isn't bogus.
9655 gnus-newsgroup-prepared
9656 ;; Also make sure that this isn't a dead summary buffer.
9657 (not gnus-dead-summary-mode)))
9658 (push bufname buffers))
9659 (setq buflist (cdr buflist)))
9660 ;; Go through all these summary buffers and offer to save them.
9661 (when buffers
9662 (map-y-or-n-p
9663 "Update summary buffer %s? "
6748645f
LMI
9664 (lambda (buf)
9665 (switch-to-buffer buf)
9666 (gnus-summary-exit))
eec82323
LMI
9667 buffers)))))
9668
16409b0b
GM
9669(defun gnus-summary-setup-default-charset ()
9670 "Setup newsgroup default charset."
9671 (if (equal gnus-newsgroup-name "nndraft:drafts")
9672 (setq gnus-newsgroup-charset nil)
9673 (let* ((name (and gnus-newsgroup-name
9674 (gnus-group-real-name gnus-newsgroup-name)))
9675 (ignored-charsets
9676 (or gnus-newsgroup-ephemeral-ignored-charsets
9677 (append
9678 (and gnus-newsgroup-name
9679 (or (gnus-group-find-parameter gnus-newsgroup-name
9680 'ignored-charsets t)
9681 (let ((alist gnus-group-ignored-charsets-alist)
9682 elem (charsets nil))
9683 (while (setq elem (pop alist))
9684 (when (and name
9685 (string-match (car elem) name))
9686 (setq alist nil
9687 charsets (cdr elem))))
9688 charsets)))
9689 gnus-newsgroup-ignored-charsets))))
9690 (setq gnus-newsgroup-charset
9691 (or gnus-newsgroup-ephemeral-charset
9692 (and gnus-newsgroup-name
9693 (or (gnus-group-find-parameter gnus-newsgroup-name 'charset)
9694 (let ((alist gnus-group-charset-alist)
9695 elem charset)
9696 (while (setq elem (pop alist))
9697 (when (and name
9698 (string-match (car elem) name))
9699 (setq alist nil
9700 charset (cadr elem))))
9701 charset)))
9702 gnus-default-charset))
9703 (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
9704 ignored-charsets))))
9705
9706;;;
9707;;; Mime Commands
9708;;;
9709
9710(defun gnus-summary-display-buttonized (&optional show-all-parts)
9711 "Display the current article buffer fully MIME-buttonized.
9712If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
9713treated as multipart/mixed."
9714 (interactive "P")
9715 (require 'gnus-art)
9716 (let ((gnus-unbuttonized-mime-types nil)
9717 (gnus-mime-display-multipart-as-mixed show-all-parts))
9718 (gnus-summary-show-article)))
9719
9720(defun gnus-summary-repair-multipart (article)
9721 "Add a Content-Type header to a multipart article without one."
9722 (interactive (list (gnus-summary-article-number)))
9723 (gnus-with-article article
9724 (message-narrow-to-head)
9725 (goto-char (point-max))
9726 (widen)
9727 (when (search-forward "\n--" nil t)
9728 (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
9729 (message-narrow-to-head)
9730 (message-remove-header "Mime-Version")
9731 (message-remove-header "Content-Type")
9732 (goto-char (point-max))
9733 (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
9734 separator))
9735 (insert "Mime-Version: 1.0\n")
9736 (widen))))
9737 (let (gnus-mark-article-hook)
9738 (gnus-summary-select-article t t nil article)))
9739
9740(defun gnus-summary-toggle-display-buttonized ()
9741 "Toggle the buttonizing of the article buffer."
9742 (interactive)
9743 (require 'gnus-art)
9744 (if (setq gnus-inhibit-mime-unbuttonizing
9745 (not gnus-inhibit-mime-unbuttonizing))
9746 (let ((gnus-unbuttonized-mime-types nil))
9747 (gnus-summary-show-article))
9748 (gnus-summary-show-article)))
9749
9750;;;
9751;;; Generic summary marking commands
9752;;;
9753
9754(defvar gnus-summary-marking-alist
9755 '((read gnus-del-mark "d")
9756 (unread gnus-unread-mark "u")
9757 (ticked gnus-ticked-mark "!")
9758 (dormant gnus-dormant-mark "?")
9759 (expirable gnus-expirable-mark "e"))
9760 "An alist of names/marks/keystrokes.")
9761
9762(defvar gnus-summary-generic-mark-map (make-sparse-keymap))
9763(defvar gnus-summary-mark-map)
9764
9765(defun gnus-summary-make-all-marking-commands ()
9766 (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
9767 (dolist (elem gnus-summary-marking-alist)
9768 (apply 'gnus-summary-make-marking-command elem)))
9769
9770(defun gnus-summary-make-marking-command (name mark keystroke)
9771 (let ((map (make-sparse-keymap)))
9772 (define-key gnus-summary-generic-mark-map keystroke map)
9773 (dolist (lway `((next "next" next nil "n")
9774 (next-unread "next unread" next t "N")
9775 (prev "previous" prev nil "p")
9776 (prev-unread "previous unread" prev t "P")
9777 (nomove "" nil nil ,keystroke)))
9778 (let ((func (gnus-summary-make-marking-command-1
9779 mark (car lway) lway name)))
9780 (setq func (eval func))
9781 (define-key map (nth 4 lway) func)))))
9782
9783(defun gnus-summary-make-marking-command-1 (mark way lway name)
9784 `(defun ,(intern
9785 (format "gnus-summary-put-mark-as-%s%s"
9786 name (if (eq way 'nomove)
9787 ""
9788 (concat "-" (symbol-name way)))))
9789 (n)
9790 ,(format
9791 "Mark the current article as %s%s.
9792If N, the prefix, then repeat N times.
9793If N is negative, move in reverse order.
9794The difference between N and the actual number of articles marked is
9795returned."
9796 name (cadr lway))
9797 (interactive "p")
9798 (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
9799
9800(defun gnus-summary-generic-mark (n mark move unread)
9801 "Mark N articles with MARK."
9802 (unless (eq major-mode 'gnus-summary-mode)
9803 (error "This command can only be used in the summary buffer"))
9804 (gnus-summary-show-thread)
9805 (let ((nummove
9806 (cond
9807 ((eq move 'next) 1)
9808 ((eq move 'prev) -1)
9809 (t 0))))
9810 (if (zerop nummove)
9811 (setq n 1)
9812 (when (< n 0)
9813 (setq n (abs n)
9814 nummove (* -1 nummove))))
9815 (while (and (> n 0)
9816 (gnus-summary-mark-article nil mark)
9817 (zerop (gnus-summary-next-subject nummove unread t)))
9818 (setq n (1- n)))
9819 (when (/= 0 n)
9820 (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9821 (gnus-summary-recenter)
9822 (gnus-summary-position-point)
9823 (gnus-set-mode-line 'summary)
9824 n))
9825
9826(gnus-summary-make-all-marking-commands)
9827
a8151ef7
LMI
9828(gnus-ems-redefine)
9829
eec82323
LMI
9830(provide 'gnus-sum)
9831
9832(run-hooks 'gnus-sum-load-hook)
9833
9834;;; gnus-sum.el ends here