]> code.delx.au - gnu-emacs/blob - lisp/gnus.el
Initial revision
[gnu-emacs] / lisp / gnus.el
1 ;;; gnus.el --- a newsreader for GNU Emacs
2 ;; Copyright (C) 1987,88,89,90,93,94,95,96 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval '(run-hooks 'gnus-load-hook))
30
31 (require 'mail-utils)
32 (require 'timezone)
33 (require 'nnheader)
34 (require 'nnmail)
35 (require 'backquote)
36 (require 'nnoo)
37
38 (eval-when-compile (require 'cl))
39
40 (defvar gnus-directory (or (getenv "SAVEDIR") "~/News/")
41 "*Directory variable from which all other Gnus file variables are derived.")
42
43 ;; Site dependent variables. These variables should be defined in
44 ;; paths.el.
45
46 (defvar gnus-default-nntp-server nil
47 "Specify a default NNTP server.
48 This variable should be defined in paths.el, and should never be set
49 by the user.
50 If you want to change servers, you should use `gnus-select-method'.
51 See the documentation to that variable.")
52
53 (defvar gnus-backup-default-subscribed-newsgroups
54 '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus")
55 "Default default new newsgroups the first time Gnus is run.
56 Should be set in paths.el, and shouldn't be touched by the user.")
57
58 (defvar gnus-local-organization nil
59 "String with a description of what organization (if any) the user belongs to.
60 The ORGANIZATION environment variable is used instead if it is defined.
61 If this variable contains a function, this function will be called
62 with the current newsgroup name as the argument. The function should
63 return a string.
64
65 In any case, if the string (either in the variable, in the environment
66 variable, or returned by the function) is a file name, the contents of
67 this file will be used as the organization.")
68
69 ;; Customization variables
70
71 ;; Don't touch this variable.
72 (defvar gnus-nntp-service "nntp"
73 "*NNTP service name (\"nntp\" or 119).
74 This is an obsolete variable, which is scarcely used. If you use an
75 nntp server for your newsgroup and want to change the port number
76 used to 899, you would say something along these lines:
77
78 (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))")
79
80 (defvar gnus-nntpserver-file "/etc/nntpserver"
81 "*A file with only the name of the nntp server in it.")
82
83 ;; This function is used to check both the environment variable
84 ;; NNTPSERVER and the /etc/nntpserver file to see whether one can find
85 ;; an nntp server name default.
86 (defun gnus-getenv-nntpserver ()
87 (or (getenv "NNTPSERVER")
88 (and (file-readable-p gnus-nntpserver-file)
89 (save-excursion
90 (set-buffer (get-buffer-create " *gnus nntp*"))
91 (buffer-disable-undo (current-buffer))
92 (insert-file-contents gnus-nntpserver-file)
93 (let ((name (buffer-string)))
94 (prog1
95 (if (string-match "^[ \t\n]*$" name)
96 nil
97 name)
98 (kill-buffer (current-buffer))))))))
99
100 (defvar gnus-select-method
101 (nconc
102 (list 'nntp (or (condition-case ()
103 (gnus-getenv-nntpserver)
104 (error nil))
105 (if (and gnus-default-nntp-server
106 (not (string= gnus-default-nntp-server "")))
107 gnus-default-nntp-server)
108 (system-name)))
109 (if (or (null gnus-nntp-service)
110 (equal gnus-nntp-service "nntp"))
111 nil
112 (list gnus-nntp-service)))
113 "*Default method for selecting a newsgroup.
114 This variable should be a list, where the first element is how the
115 news is to be fetched, the second is the address.
116
117 For instance, if you want to get your news via NNTP from
118 \"flab.flab.edu\", you could say:
119
120 (setq gnus-select-method '(nntp \"flab.flab.edu\"))
121
122 If you want to use your local spool, say:
123
124 (setq gnus-select-method (list 'nnspool (system-name)))
125
126 If you use this variable, you must set `gnus-nntp-server' to nil.
127
128 There is a lot more to know about select methods and virtual servers -
129 see the manual for details.")
130
131 (defvar gnus-message-archive-method
132 `(nnfolder
133 "archive"
134 (nnfolder-directory ,(nnheader-concat message-directory "archive"))
135 (nnfolder-active-file
136 ,(nnheader-concat message-directory "archive/active"))
137 (nnfolder-get-new-mail nil)
138 (nnfolder-inhibit-expiry t))
139 "*Method used for archiving messages you've sent.
140 This should be a mail method.
141
142 It's probably not a very effective to change this variable once you've
143 run Gnus once. After doing that, you must edit this server from the
144 server buffer.")
145
146 (defvar gnus-message-archive-group nil
147 "*Name of the group in which to save the messages you've written.
148 This can either be a string, a list of strings; or an alist
149 of regexps/functions/forms to be evaluated to return a string (or a list
150 of strings). The functions are called with the name of the current
151 group (or nil) as a parameter.
152
153 Normally the group names returned by this variable should be
154 unprefixed -- which implictly means \"store on the archive server\".
155 However, you may wish to store the message on some other server. In
156 that case, just return a fully prefixed name of the group --
157 \"nnml+private:mail.misc\", for instance.")
158
159 (defvar gnus-refer-article-method nil
160 "*Preferred method for fetching an article by Message-ID.
161 If you are reading news from the local spool (with nnspool), fetching
162 articles by Message-ID is painfully slow. By setting this method to an
163 nntp method, you might get acceptable results.
164
165 The value of this variable must be a valid select method as discussed
166 in the documentation of `gnus-select-method'.")
167
168 (defvar gnus-secondary-select-methods nil
169 "*A list of secondary methods that will be used for reading news.
170 This is a list where each element is a complete select method (see
171 `gnus-select-method').
172
173 If, for instance, you want to read your mail with the nnml backend,
174 you could set this variable:
175
176 (setq gnus-secondary-select-methods '((nnml \"\")))")
177
178 (defvar gnus-secondary-servers nil
179 "*List of NNTP servers that the user can choose between interactively.
180 To make Gnus query you for a server, you have to give `gnus' a
181 non-numeric prefix - `C-u M-x gnus', in short.")
182
183 (defvar gnus-nntp-server nil
184 "*The name of the host running the NNTP server.
185 This variable is semi-obsolete. Use the `gnus-select-method'
186 variable instead.")
187
188 (defvar gnus-startup-file "~/.newsrc"
189 "*Your `.newsrc' file.
190 `.newsrc-SERVER' will be used instead if that exists.")
191
192 (defvar gnus-init-file "~/.gnus"
193 "*Your Gnus elisp startup file.
194 If a file with the .el or .elc suffixes exist, it will be read
195 instead.")
196
197 (defvar gnus-group-faq-directory
198 '("/ftp@mirrors.aol.com:/pub/rtfm/usenet/"
199 "/ftp@sunsite.auc.dk:/pub/usenet/"
200 "/ftp@sunsite.doc.ic.ac.uk:/pub/usenet/news-faqs/"
201 "/ftp@src.doc.ic.ac.uk:/usenet/news-FAQS/"
202 "/ftp@ftp.seas.gwu.edu:/pub/rtfm/"
203 "/ftp@rtfm.mit.edu:/pub/usenet/"
204 "/ftp@ftp.uni-paderborn.de:/pub/FAQ/"
205 "/ftp@ftp.sunet.se:/pub/usenet/"
206 "/ftp@nctuccca.edu.tw:/USENET/FAQ/"
207 "/ftp@hwarang.postech.ac.kr:/pub/usenet/"
208 "/ftp@ftp.hk.super.net:/mirror/faqs/")
209 "*Directory where the group FAQs are stored.
210 This will most commonly be on a remote machine, and the file will be
211 fetched by ange-ftp.
212
213 This variable can also be a list of directories. In that case, the
214 first element in the list will be used by default. The others can
215 be used when being prompted for a site.
216
217 Note that Gnus uses an aol machine as the default directory. If this
218 feels fundamentally unclean, just think of it as a way to finally get
219 something of value back from them.
220
221 If the default site is too slow, try one of these:
222
223 North America: mirrors.aol.com /pub/rtfm/usenet
224 ftp.seas.gwu.edu /pub/rtfm
225 rtfm.mit.edu /pub/usenet
226 Europe: ftp.uni-paderborn.de /pub/FAQ
227 src.doc.ic.ac.uk /usenet/news-FAQS
228 ftp.sunet.se /pub/usenet
229 sunsite.auc.dk /pub/usenet
230 Asia: nctuccca.edu.tw /USENET/FAQ
231 hwarang.postech.ac.kr /pub/usenet
232 ftp.hk.super.net /mirror/faqs")
233
234 (defvar gnus-group-archive-directory
235 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
236 "*The address of the (ding) archives.")
237
238 (defvar gnus-group-recent-archive-directory
239 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
240 "*The address of the most recent (ding) articles.")
241
242 (defvar gnus-default-subscribed-newsgroups nil
243 "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
244 It should be a list of strings.
245 If it is `t', Gnus will not do anything special the first time it is
246 started; it'll just use the normal newsgroups subscription methods.")
247
248 (defvar gnus-use-cross-reference t
249 "*Non-nil means that cross referenced articles will be marked as read.
250 If nil, ignore cross references. If t, mark articles as read in
251 subscribed newsgroups. If neither t nor nil, mark as read in all
252 newsgroups.")
253
254 (defvar gnus-single-article-buffer t
255 "*If non-nil, display all articles in the same buffer.
256 If nil, each group will get its own article buffer.")
257
258 (defvar gnus-use-dribble-file t
259 "*Non-nil means that Gnus will use a dribble file to store user updates.
260 If Emacs should crash without saving the .newsrc files, complete
261 information can be restored from the dribble file.")
262
263 (defvar gnus-dribble-directory nil
264 "*The directory where dribble files will be saved.
265 If this variable is nil, the directory where the .newsrc files are
266 saved will be used.")
267
268 (defvar gnus-asynchronous nil
269 "*If non-nil, Gnus will supply backends with data needed for async article fetching.")
270
271 (defvar gnus-kill-summary-on-exit t
272 "*If non-nil, kill the summary buffer when you exit from it.
273 If nil, the summary will become a \"*Dead Summary*\" buffer, and
274 it will be killed sometime later.")
275
276 (defvar gnus-large-newsgroup 200
277 "*The number of articles which indicates a large newsgroup.
278 If the number of articles in a newsgroup is greater than this value,
279 confirmation is required for selecting the newsgroup.")
280
281 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
282 (defvar gnus-no-groups-message "No news is horrible news"
283 "*Message displayed by Gnus when no groups are available.")
284
285 (defvar gnus-use-long-file-name (not (memq system-type '(usg-unix-v xenix)))
286 "*Non-nil means that the default name of a file to save articles in is the group name.
287 If it's nil, the directory form of the group name is used instead.
288
289 If this variable is a list, and the list contains the element
290 `not-score', long file names will not be used for score files; if it
291 contains the element `not-save', long file names will not be used for
292 saving; and if it contains the element `not-kill', long file names
293 will not be used for kill files.
294
295 Note that the default for this variable varies according to what system
296 type you're using. On `usg-unix-v' and `xenix' this variable defaults
297 to nil while on all other systems it defaults to t.")
298
299 (defvar gnus-article-save-directory gnus-directory
300 "*Name of the directory articles will be saved in (default \"~/News\").")
301
302 (defvar gnus-kill-files-directory gnus-directory
303 "*Name of the directory where kill files will be stored (default \"~/News\").")
304
305 (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
306 "*A function to save articles in your favorite format.
307 The function must be interactively callable (in other words, it must
308 be an Emacs command).
309
310 Gnus provides the following functions:
311
312 * gnus-summary-save-in-rmail (Rmail format)
313 * gnus-summary-save-in-mail (Unix mail format)
314 * gnus-summary-save-in-folder (MH folder)
315 * gnus-summary-save-in-file (article format).
316 * gnus-summary-save-in-vm (use VM's folder format).")
317
318 (defvar gnus-prompt-before-saving 'always
319 "*This variable says how much prompting is to be done when saving articles.
320 If it is nil, no prompting will be done, and the articles will be
321 saved to the default files. If this variable is `always', each and
322 every article that is saved will be preceded by a prompt, even when
323 saving large batches of articles. If this variable is neither nil not
324 `always', there the user will be prompted once for a file name for
325 each invocation of the saving commands.")
326
327 (defvar gnus-rmail-save-name (function gnus-plain-save-name)
328 "*A function generating a file name to save articles in Rmail format.
329 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
330
331 (defvar gnus-mail-save-name (function gnus-plain-save-name)
332 "*A function generating a file name to save articles in Unix mail format.
333 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
334
335 (defvar gnus-folder-save-name (function gnus-folder-save-name)
336 "*A function generating a file name to save articles in MH folder.
337 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
338
339 (defvar gnus-file-save-name (function gnus-numeric-save-name)
340 "*A function generating a file name to save articles in article format.
341 The function is called with NEWSGROUP, HEADERS, and optional
342 LAST-FILE.")
343
344 (defvar gnus-split-methods
345 '((gnus-article-archive-name))
346 "*Variable used to suggest where articles are to be saved.
347 For instance, if you would like to save articles related to Gnus in
348 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
349 you could set this variable to something like:
350
351 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
352 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
353
354 This variable is an alist where the where the key is the match and the
355 value is a list of possible files to save in if the match is non-nil.
356
357 If the match is a string, it is used as a regexp match on the
358 article. If the match is a symbol, that symbol will be funcalled
359 from the buffer of the article to be saved with the newsgroup as the
360 parameter. If it is a list, it will be evaled in the same buffer.
361
362 If this form or function returns a string, this string will be used as
363 a possible file name; and if it returns a non-nil list, that list will
364 be used as possible file names.")
365
366 (defvar gnus-move-split-methods nil
367 "*Variable used to suggest where articles are to be moved to.
368 It uses the same syntax as the `gnus-split-methods' variable.")
369
370 (defvar gnus-save-score nil
371 "*If non-nil, save group scoring info.")
372
373 (defvar gnus-use-adaptive-scoring nil
374 "*If non-nil, use some adaptive scoring scheme.")
375
376 (defvar gnus-use-cache 'passive
377 "*If nil, Gnus will ignore the article cache.
378 If `passive', it will allow entering (and reading) articles
379 explicitly entered into the cache. If anything else, use the
380 cache to the full extent of the law.")
381
382 (defvar gnus-use-trees nil
383 "*If non-nil, display a thread tree buffer.")
384
385 (defvar gnus-use-grouplens nil
386 "*If non-nil, use GroupLens ratings.")
387
388 (defvar gnus-keep-backlog nil
389 "*If non-nil, Gnus will keep read articles for later re-retrieval.
390 If it is a number N, then Gnus will only keep the last N articles
391 read. If it is neither nil nor a number, Gnus will keep all read
392 articles. This is not a good idea.")
393
394 (defvar gnus-use-nocem nil
395 "*If non-nil, Gnus will read NoCeM cancel messages.")
396
397 (defvar gnus-use-demon nil
398 "If non-nil, Gnus might use some demons.")
399
400 (defvar gnus-use-scoring t
401 "*If non-nil, enable scoring.")
402
403 (defvar gnus-use-picons nil
404 "*If non-nil, display picons.")
405
406 (defvar gnus-fetch-old-headers nil
407 "*Non-nil means that Gnus will try to build threads by grabbing old headers.
408 If an unread article in the group refers to an older, already read (or
409 just marked as read) article, the old article will not normally be
410 displayed in the Summary buffer. If this variable is non-nil, Gnus
411 will attempt to grab the headers to the old articles, and thereby
412 build complete threads. If it has the value `some', only enough
413 headers to connect otherwise loose threads will be displayed.
414 This variable can also be a number. In that case, no more than that
415 number of old headers will be fetched.
416
417 The server has to support NOV for any of this to work.")
418
419 ;see gnus-cus.el
420 ;(defvar gnus-visual t
421 ; "*If non-nil, will do various highlighting.
422 ;If nil, no mouse highlights (or any other highlights) will be
423 ;performed. This might speed up Gnus some when generating large group
424 ;and summary buffers.")
425
426 (defvar gnus-novice-user t
427 "*Non-nil means that you are a usenet novice.
428 If non-nil, verbose messages may be displayed and confirmations may be
429 required.")
430
431 (defvar gnus-expert-user nil
432 "*Non-nil means that you will never be asked for confirmation about anything.
433 And that means *anything*.")
434
435 (defvar gnus-verbose 7
436 "*Integer that says how verbose Gnus should be.
437 The higher the number, the more messages Gnus will flash to say what
438 it's doing. At zero, Gnus will be totally mute; at five, Gnus will
439 display most important messages; and at ten, Gnus will keep on
440 jabbering all the time.")
441
442 (defvar gnus-keep-same-level nil
443 "*Non-nil means that the next newsgroup after the current will be on the same level.
444 When you type, for instance, `n' after reading the last article in the
445 current newsgroup, you will go to the next newsgroup. If this variable
446 is nil, the next newsgroup will be the next from the group
447 buffer.
448 If this variable is non-nil, Gnus will either put you in the
449 next newsgroup with the same level, or, if no such newsgroup is
450 available, the next newsgroup with the lowest possible level higher
451 than the current level.
452 If this variable is `best', Gnus will make the next newsgroup the one
453 with the best level.")
454
455 (defvar gnus-summary-make-false-root 'adopt
456 "*nil means that Gnus won't gather loose threads.
457 If the root of a thread has expired or been read in a previous
458 session, the information necessary to build a complete thread has been
459 lost. Instead of having many small sub-threads from this original thread
460 scattered all over the summary buffer, Gnus can gather them.
461
462 If non-nil, Gnus will try to gather all loose sub-threads from an
463 original thread into one large thread.
464
465 If this variable is non-nil, it should be one of `none', `adopt',
466 `dummy' or `empty'.
467
468 If this variable is `none', Gnus will not make a false root, but just
469 present the sub-threads after another.
470 If this variable is `dummy', Gnus will create a dummy root that will
471 have all the sub-threads as children.
472 If this variable is `adopt', Gnus will make one of the \"children\"
473 the parent and mark all the step-children as such.
474 If this variable is `empty', the \"children\" are printed with empty
475 subject fields. (Or rather, they will be printed with a string
476 given by the `gnus-summary-same-subject' variable.)")
477
478 (defvar gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
479 "*A regexp to match subjects to be excluded from loose thread gathering.
480 As loose thread gathering is done on subjects only, that means that
481 there can be many false gatherings performed. By rooting out certain
482 common subjects, gathering might become saner.")
483
484 (defvar gnus-summary-gather-subject-limit nil
485 "*Maximum length of subject comparisons when gathering loose threads.
486 Use nil to compare full subjects. Setting this variable to a low
487 number will help gather threads that have been corrupted by
488 newsreaders chopping off subject lines, but it might also mean that
489 unrelated articles that have subject that happen to begin with the
490 same few characters will be incorrectly gathered.
491
492 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
493 comparing subjects.")
494
495 (defvar gnus-simplify-ignored-prefixes nil
496 "*Regexp, matches for which are removed from subject lines when simplifying.")
497
498 (defvar gnus-build-sparse-threads nil
499 "*If non-nil, fill in the gaps in threads.
500 If `some', only fill in the gaps that are needed to tie loose threads
501 together. If `more', fill in all leaf nodes that Gnus can find. If
502 non-nil and non-`some', fill in all gaps that Gnus manages to guess.")
503
504 (defvar gnus-summary-thread-gathering-function 'gnus-gather-threads-by-subject
505 "Function used for gathering loose threads.
506 There are two pre-defined functions: `gnus-gather-threads-by-subject',
507 which only takes Subjects into consideration; and
508 `gnus-gather-threads-by-references', which compared the References
509 headers of the articles to find matches.")
510
511 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
512 (defvar gnus-summary-same-subject ""
513 "*String indicating that the current article has the same subject as the previous.
514 This variable will only be used if the value of
515 `gnus-summary-make-false-root' is `empty'.")
516
517 (defvar gnus-summary-goto-unread t
518 "*If non-nil, marking commands will go to the next unread article.
519 If `never', \\<gnus-summary-mode-map>\\[gnus-summary-next-page] will go to the next article,
520 whether it is read or not.")
521
522 (defvar gnus-group-goto-unread t
523 "*If non-nil, movement commands will go to the next unread and subscribed group.")
524
525 (defvar gnus-goto-next-group-when-activating t
526 "*If non-nil, the \\<gnus-group-mode-map>\\[gnus-group-get-new-news-this-group] command will advance point to the next group.")
527
528 (defvar gnus-check-new-newsgroups t
529 "*Non-nil means that Gnus will add new newsgroups at startup.
530 If this variable is `ask-server', Gnus will ask the server for new
531 groups since the last time it checked. This means that the killed list
532 is no longer necessary, so you could set `gnus-save-killed-list' to
533 nil.
534
535 A variant is to have this variable be a list of select methods. Gnus
536 will then use the `ask-server' method on all these select methods to
537 query for new groups from all those servers.
538
539 Eg.
540 (setq gnus-check-new-newsgroups
541 '((nntp \"some.server\") (nntp \"other.server\")))
542
543 If this variable is nil, then you have to tell Gnus explicitly to
544 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
545
546 (defvar gnus-check-bogus-newsgroups nil
547 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
548 If this variable is nil, then you have to tell Gnus explicitly to
549 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
550
551 (defvar gnus-read-active-file t
552 "*Non-nil means that Gnus will read the entire active file at startup.
553 If this variable is nil, Gnus will only know about the groups in your
554 `.newsrc' file.
555
556 If this variable is `some', Gnus will try to only read the relevant
557 parts of the active file from the server. Not all servers support
558 this, and it might be quite slow with other servers, but this should
559 generally be faster than both the t and nil value.
560
561 If you set this variable to nil or `some', you probably still want to
562 be told about new newsgroups that arrive. To do that, set
563 `gnus-check-new-newsgroups' to `ask-server'. This may not work
564 properly with all servers.")
565
566 (defvar gnus-level-subscribed 5
567 "*Groups with levels less than or equal to this variable are subscribed.")
568
569 (defvar gnus-level-unsubscribed 7
570 "*Groups with levels less than or equal to this variable are unsubscribed.
571 Groups with levels less than `gnus-level-subscribed', which should be
572 less than this variable, are subscribed.")
573
574 (defvar gnus-level-zombie 8
575 "*Groups with this level are zombie groups.")
576
577 (defvar gnus-level-killed 9
578 "*Groups with this level are killed.")
579
580 (defvar gnus-level-default-subscribed 3
581 "*New subscribed groups will be subscribed at this level.")
582
583 (defvar gnus-level-default-unsubscribed 6
584 "*New unsubscribed groups will be unsubscribed at this level.")
585
586 (defvar gnus-activate-level (1+ gnus-level-subscribed)
587 "*Groups higher than this level won't be activated on startup.
588 Setting this variable to something log might save lots of time when
589 you have many groups that you aren't interested in.")
590
591 (defvar gnus-activate-foreign-newsgroups 4
592 "*If nil, Gnus will not check foreign newsgroups at startup.
593 If it is non-nil, it should be a number between one and nine. Foreign
594 newsgroups that have a level lower or equal to this number will be
595 activated on startup. For instance, if you want to active all
596 subscribed newsgroups, but not the rest, you'd set this variable to
597 `gnus-level-subscribed'.
598
599 If you subscribe to lots of newsgroups from different servers, startup
600 might take a while. By setting this variable to nil, you'll save time,
601 but you won't be told how many unread articles there are in the
602 groups.")
603
604 (defvar gnus-save-newsrc-file t
605 "*Non-nil means that Gnus will save the `.newsrc' file.
606 Gnus always saves its own startup file, which is called
607 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
608 be readily understood by other newsreaders. If you don't plan on
609 using other newsreaders, set this variable to nil to save some time on
610 exit.")
611
612 (defvar gnus-save-killed-list t
613 "*If non-nil, save the list of killed groups to the startup file.
614 If you set this variable to nil, you'll save both time (when starting
615 and quitting) and space (both memory and disk), but it will also mean
616 that Gnus has no record of which groups are new and which are old, so
617 the automatic new newsgroups subscription methods become meaningless.
618
619 You should always set `gnus-check-new-newsgroups' to `ask-server' or
620 nil if you set this variable to nil.")
621
622 (defvar gnus-interactive-catchup t
623 "*If non-nil, require your confirmation when catching up a group.")
624
625 (defvar gnus-interactive-exit t
626 "*If non-nil, require your confirmation when exiting Gnus.")
627
628 (defvar gnus-kill-killed t
629 "*If non-nil, Gnus will apply kill files to already killed articles.
630 If it is nil, Gnus will never apply kill files to articles that have
631 already been through the scoring process, which might very well save lots
632 of time.")
633
634 (defvar gnus-extract-address-components 'gnus-extract-address-components
635 "*Function for extracting address components from a From header.
636 Two pre-defined function exist: `gnus-extract-address-components',
637 which is the default, quite fast, and too simplistic solution, and
638 `mail-extract-address-components', which works much better, but is
639 slower.")
640
641 (defvar gnus-summary-default-score 0
642 "*Default article score level.
643 If this variable is nil, scoring will be disabled.")
644
645 (defvar gnus-summary-zcore-fuzz 0
646 "*Fuzziness factor for the zcore in the summary buffer.
647 Articles with scores closer than this to `gnus-summary-default-score'
648 will not be marked.")
649
650 (defvar gnus-simplify-subject-fuzzy-regexp nil
651 "*Strings to be removed when doing fuzzy matches.
652 This can either be a regular expression or list of regular expressions
653 that will be removed from subject strings if fuzzy subject
654 simplification is selected.")
655
656 (defvar gnus-permanently-visible-groups nil
657 "*Regexp to match groups that should always be listed in the group buffer.
658 This means that they will still be listed when there are no unread
659 articles in the groups.")
660
661 (defvar gnus-list-groups-with-ticked-articles t
662 "*If non-nil, list groups that have only ticked articles.
663 If nil, only list groups that have unread articles.")
664
665 (defvar gnus-group-default-list-level gnus-level-subscribed
666 "*Default listing level.
667 Ignored if `gnus-group-use-permanent-levels' is non-nil.")
668
669 (defvar gnus-group-use-permanent-levels nil
670 "*If non-nil, once you set a level, Gnus will use this level.")
671
672 (defvar gnus-group-list-inactive-groups t
673 "*If non-nil, inactive groups will be listed.")
674
675 (defvar gnus-show-mime nil
676 "*If non-nil, do mime processing of articles.
677 The articles will simply be fed to the function given by
678 `gnus-show-mime-method'.")
679
680 (defvar gnus-strict-mime t
681 "*If nil, MIME-decode even if there is no Mime-Version header in the article.")
682
683 (defvar gnus-show-mime-method 'metamail-buffer
684 "*Function to process a MIME message.
685 The function is called from the article buffer.")
686
687 (defvar gnus-decode-encoded-word-method (lambda ())
688 "*Function to decode a MIME encoded-words.
689 The function is called from the article buffer.")
690
691 (defvar gnus-show-threads t
692 "*If non-nil, display threads in summary mode.")
693
694 (defvar gnus-thread-hide-subtree nil
695 "*If non-nil, hide all threads initially.
696 If threads are hidden, you have to run the command
697 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
698 to expose hidden threads.")
699
700 (defvar gnus-thread-hide-killed t
701 "*If non-nil, hide killed threads automatically.")
702
703 (defvar gnus-thread-ignore-subject nil
704 "*If non-nil, ignore subjects and do all threading based on the Reference header.
705 If nil, which is the default, articles that have different subjects
706 from their parents will start separate threads.")
707
708 (defvar gnus-thread-operation-ignore-subject t
709 "*If non-nil, subjects will be ignored when doing thread commands.
710 This affects commands like `gnus-summary-kill-thread' and
711 `gnus-summary-lower-thread'.
712
713 If this variable is nil, articles in the same thread with different
714 subjects will not be included in the operation in question. If this
715 variable is `fuzzy', only articles that have subjects that are fuzzily
716 equal will be included.")
717
718 (defvar gnus-thread-indent-level 4
719 "*Number that says how much each sub-thread should be indented.")
720
721 (defvar gnus-ignored-newsgroups
722 (purecopy (mapconcat 'identity
723 '("^to\\." ; not "real" groups
724 "^[0-9. \t]+ " ; all digits in name
725 "[][\"#'()]" ; bogus characters
726 )
727 "\\|"))
728 "*A regexp to match uninteresting newsgroups in the active file.
729 Any lines in the active file matching this regular expression are
730 removed from the newsgroup list before anything else is done to it,
731 thus making them effectively non-existent.")
732
733 (defvar gnus-ignored-headers
734 "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:\\|^Received:\\|^Mail-from:"
735 "*All headers that match this regexp will be hidden.
736 This variable can also be a list of regexps of headers to be ignored.
737 If `gnus-visible-headers' is non-nil, this variable will be ignored.")
738
739 (defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-"
740 "*All headers that do not match this regexp will be hidden.
741 This variable can also be a list of regexp of headers to remain visible.
742 If this variable is non-nil, `gnus-ignored-headers' will be ignored.")
743
744 (defvar gnus-sorted-header-list
745 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:"
746 "^Cc:" "^Date:" "^Organization:")
747 "*This variable is a list of regular expressions.
748 If it is non-nil, headers that match the regular expressions will
749 be placed first in the article buffer in the sequence specified by
750 this list.")
751
752 (defvar gnus-boring-article-headers
753 '(empty followup-to reply-to)
754 "*Headers that are only to be displayed if they have interesting data.
755 Possible values in this list are `empty', `newsgroups', `followup-to',
756 `reply-to', and `date'.")
757
758 (defvar gnus-show-all-headers nil
759 "*If non-nil, don't hide any headers.")
760
761 (defvar gnus-save-all-headers t
762 "*If non-nil, don't remove any headers before saving.")
763
764 (defvar gnus-saved-headers gnus-visible-headers
765 "*Headers to keep if `gnus-save-all-headers' is nil.
766 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
767 If that variable is nil, however, all headers that match this regexp
768 will be kept while the rest will be deleted before saving.")
769
770 (defvar gnus-inhibit-startup-message nil
771 "*If non-nil, the startup message will not be displayed.")
772
773 (defvar gnus-signature-separator "^-- *$"
774 "Regexp matching signature separator.")
775
776 (defvar gnus-signature-limit nil
777 "Provide a limit to what is considered a signature.
778 If it is a number, no signature may not be longer (in characters) than
779 that number. If it is a function, the function will be called without
780 any parameters, and if it returns nil, there is no signature in the
781 buffer. If it is a string, it will be used as a regexp. If it
782 matches, the text in question is not a signature.")
783
784 (defvar gnus-auto-extend-newsgroup t
785 "*If non-nil, extend newsgroup forward and backward when requested.")
786
787 (defvar gnus-auto-select-first t
788 "*If nil, don't select the first unread article when entering a group.
789 If this variable is `best', select the highest-scored unread article
790 in the group. If neither nil nor `best', select the first unread
791 article.
792
793 If you want to prevent automatic selection of the first unread article
794 in some newsgroups, set the variable to nil in
795 `gnus-select-group-hook'.")
796
797 (defvar gnus-auto-select-next t
798 "*If non-nil, offer to go to the next group from the end of the previous.
799 If the value is t and the next newsgroup is empty, Gnus will exit
800 summary mode and go back to group mode. If the value is neither nil
801 nor t, Gnus will select the following unread newsgroup. In
802 particular, if the value is the symbol `quietly', the next unread
803 newsgroup will be selected without any confirmation, and if it is
804 `almost-quietly', the next group will be selected without any
805 confirmation if you are located on the last article in the group.
806 Finally, if this variable is `slightly-quietly', the `Z n' command
807 will go to the next group without confirmation.")
808
809 (defvar gnus-auto-select-same nil
810 "*If non-nil, select the next article with the same subject.")
811
812 (defvar gnus-summary-check-current nil
813 "*If non-nil, consider the current article when moving.
814 The \"unread\" movement commands will stay on the same line if the
815 current article is unread.")
816
817 (defvar gnus-auto-center-summary t
818 "*If non-nil, always center the current summary buffer.
819 In particular, if `vertical' do only vertical recentering. If non-nil
820 and non-`vertical', do both horizontal and vertical recentering.")
821
822 (defvar gnus-break-pages t
823 "*If non-nil, do page breaking on articles.
824 The page delimiter is specified by the `gnus-page-delimiter'
825 variable.")
826
827 (defvar gnus-page-delimiter "^\^L"
828 "*Regexp describing what to use as article page delimiters.
829 The default value is \"^\^L\", which is a form linefeed at the
830 beginning of a line.")
831
832 (defvar gnus-use-full-window t
833 "*If non-nil, use the entire Emacs screen.")
834
835 (defvar gnus-window-configuration nil
836 "Obsolete variable. See `gnus-buffer-configuration'.")
837
838 (defvar gnus-window-min-width 2
839 "*Minimum width of Gnus buffers.")
840
841 (defvar gnus-window-min-height 1
842 "*Minimum height of Gnus buffers.")
843
844 (defvar gnus-buffer-configuration
845 '((group
846 (vertical 1.0
847 (group 1.0 point)
848 (if gnus-carpal '(group-carpal 4))))
849 (summary
850 (vertical 1.0
851 (summary 1.0 point)
852 (if gnus-carpal '(summary-carpal 4))))
853 (article
854 (cond
855 (gnus-use-picons
856 '(frame 1.0
857 (vertical 1.0
858 (summary 0.25 point)
859 (if gnus-carpal '(summary-carpal 4))
860 (article 1.0))
861 (vertical ((height . 5) (width . 15)
862 (user-position . t)
863 (left . -1) (top . 1))
864 (picons 1.0))))
865 (gnus-use-trees
866 '(vertical 1.0
867 (summary 0.25 point)
868 (tree 0.25)
869 (article 1.0)))
870 (t
871 '(vertical 1.0
872 (summary 0.25 point)
873 (if gnus-carpal '(summary-carpal 4))
874 (article 1.0)))))
875 (server
876 (vertical 1.0
877 (server 1.0 point)
878 (if gnus-carpal '(server-carpal 2))))
879 (browse
880 (vertical 1.0
881 (browse 1.0 point)
882 (if gnus-carpal '(browse-carpal 2))))
883 (message
884 (vertical 1.0
885 (message 1.0 point)))
886 (pick
887 (vertical 1.0
888 (article 1.0 point)))
889 (info
890 (vertical 1.0
891 (info 1.0 point)))
892 (summary-faq
893 (vertical 1.0
894 (summary 0.25)
895 (faq 1.0 point)))
896 (edit-group
897 (vertical 1.0
898 (group 0.5)
899 (edit-group 1.0 point)))
900 (edit-server
901 (vertical 1.0
902 (server 0.5)
903 (edit-server 1.0 point)))
904 (edit-score
905 (vertical 1.0
906 (summary 0.25)
907 (edit-score 1.0 point)))
908 (post
909 (vertical 1.0
910 (post 1.0 point)))
911 (reply
912 (vertical 1.0
913 (article-copy 0.5)
914 (message 1.0 point)))
915 (forward
916 (vertical 1.0
917 (message 1.0 point)))
918 (reply-yank
919 (vertical 1.0
920 (message 1.0 point)))
921 (mail-bounce
922 (vertical 1.0
923 (article 0.5)
924 (message 1.0 point)))
925 (draft
926 (vertical 1.0
927 (draft 1.0 point)))
928 (pipe
929 (vertical 1.0
930 (summary 0.25 point)
931 (if gnus-carpal '(summary-carpal 4))
932 ("*Shell Command Output*" 1.0)))
933 (bug
934 (vertical 1.0
935 ("*Gnus Help Bug*" 0.5)
936 ("*Gnus Bug*" 1.0 point)))
937 (compose-bounce
938 (vertical 1.0
939 (article 0.5)
940 (message 1.0 point))))
941 "Window configuration for all possible Gnus buffers.
942 This variable is a list of lists. Each of these lists has a NAME and
943 a RULE. The NAMEs are commonsense names like `group', which names a
944 rule used when displaying the group buffer; `summary', which names a
945 rule for what happens when you enter a group and do not display an
946 article buffer; and so on. See the value of this variable for a
947 complete list of NAMEs.
948
949 Each RULE is a list of vectors. The first element in this vector is
950 the name of the buffer to be displayed; the second element is the
951 percentage of the screen this buffer is to occupy (a number in the
952 0.0-0.99 range); the optional third element is `point', which should
953 be present to denote which buffer point is to go to after making this
954 buffer configuration.")
955
956 (defvar gnus-window-to-buffer
957 '((group . gnus-group-buffer)
958 (summary . gnus-summary-buffer)
959 (article . gnus-article-buffer)
960 (server . gnus-server-buffer)
961 (browse . "*Gnus Browse Server*")
962 (edit-group . gnus-group-edit-buffer)
963 (edit-server . gnus-server-edit-buffer)
964 (group-carpal . gnus-carpal-group-buffer)
965 (summary-carpal . gnus-carpal-summary-buffer)
966 (server-carpal . gnus-carpal-server-buffer)
967 (browse-carpal . gnus-carpal-browse-buffer)
968 (edit-score . gnus-score-edit-buffer)
969 (message . gnus-message-buffer)
970 (mail . gnus-message-buffer)
971 (post-news . gnus-message-buffer)
972 (faq . gnus-faq-buffer)
973 (picons . "*Picons*")
974 (tree . gnus-tree-buffer)
975 (info . gnus-info-buffer)
976 (article-copy . gnus-article-copy)
977 (draft . gnus-draft-buffer))
978 "Mapping from short symbols to buffer names or buffer variables.")
979
980 (defvar gnus-carpal nil
981 "*If non-nil, display clickable icons.")
982
983 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
984 "*Function called with a group name when new group is detected.
985 A few pre-made functions are supplied: `gnus-subscribe-randomly'
986 inserts new groups at the beginning of the list of groups;
987 `gnus-subscribe-alphabetically' inserts new groups in strict
988 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
989 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
990 for your decision; `gnus-subscribe-killed' kills all new groups;
991 `gnus-subscribe-zombies' will make all new groups into zombies.")
992
993 ;; Suggested by a bug report by Hallvard B Furuseth.
994 ;; <h.b.furuseth@usit.uio.no>.
995 (defvar gnus-subscribe-options-newsgroup-method
996 (function gnus-subscribe-alphabetically)
997 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
998 If, for instance, you want to subscribe to all newsgroups in the
999 \"no\" and \"alt\" hierarchies, you'd put the following in your
1000 .newsrc file:
1001
1002 options -n no.all alt.all
1003
1004 Gnus will the subscribe all new newsgroups in these hierarchies with
1005 the subscription method in this variable.")
1006
1007 (defvar gnus-subscribe-hierarchical-interactive nil
1008 "*If non-nil, Gnus will offer to subscribe hierarchically.
1009 When a new hierarchy appears, Gnus will ask the user:
1010
1011 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
1012
1013 If the user pressed `d', Gnus will descend the hierarchy, `y' will
1014 subscribe to all newsgroups in the hierarchy and `s' will skip this
1015 hierarchy in its entirety.")
1016
1017 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
1018 "*Function used for sorting the group buffer.
1019 This function will be called with group info entries as the arguments
1020 for the groups to be sorted. Pre-made functions include
1021 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread',
1022 `gnus-group-sort-by-level', `gnus-group-sort-by-score', and
1023 `gnus-group-sort-by-rank'.
1024
1025 This variable can also be a list of sorting functions. In that case,
1026 the most significant sort function should be the last function in the
1027 list.")
1028
1029 ;; Mark variables suggested by Thomas Michanek
1030 ;; <Thomas.Michanek@telelogic.se>.
1031 (defvar gnus-unread-mark ?
1032 "*Mark used for unread articles.")
1033 (defvar gnus-ticked-mark ?!
1034 "*Mark used for ticked articles.")
1035 (defvar gnus-dormant-mark ??
1036 "*Mark used for dormant articles.")
1037 (defvar gnus-del-mark ?r
1038 "*Mark used for del'd articles.")
1039 (defvar gnus-read-mark ?R
1040 "*Mark used for read articles.")
1041 (defvar gnus-expirable-mark ?E
1042 "*Mark used for expirable articles.")
1043 (defvar gnus-killed-mark ?K
1044 "*Mark used for killed articles.")
1045 (defvar gnus-souped-mark ?F
1046 "*Mark used for killed articles.")
1047 (defvar gnus-kill-file-mark ?X
1048 "*Mark used for articles killed by kill files.")
1049 (defvar gnus-low-score-mark ?Y
1050 "*Mark used for articles with a low score.")
1051 (defvar gnus-catchup-mark ?C
1052 "*Mark used for articles that are caught up.")
1053 (defvar gnus-replied-mark ?A
1054 "*Mark used for articles that have been replied to.")
1055 (defvar gnus-cached-mark ?*
1056 "*Mark used for articles that are in the cache.")
1057 (defvar gnus-saved-mark ?S
1058 "*Mark used for articles that have been saved to.")
1059 (defvar gnus-process-mark ?#
1060 "*Process mark.")
1061 (defvar gnus-ancient-mark ?O
1062 "*Mark used for ancient articles.")
1063 (defvar gnus-sparse-mark ?Q
1064 "*Mark used for sparsely reffed articles.")
1065 (defvar gnus-canceled-mark ?G
1066 "*Mark used for canceled articles.")
1067 (defvar gnus-score-over-mark ?+
1068 "*Score mark used for articles with high scores.")
1069 (defvar gnus-score-below-mark ?-
1070 "*Score mark used for articles with low scores.")
1071 (defvar gnus-empty-thread-mark ?
1072 "*There is no thread under the article.")
1073 (defvar gnus-not-empty-thread-mark ?=
1074 "*There is a thread under the article.")
1075
1076 (defvar gnus-view-pseudo-asynchronously nil
1077 "*If non-nil, Gnus will view pseudo-articles asynchronously.")
1078
1079 (defvar gnus-view-pseudos nil
1080 "*If `automatic', pseudo-articles will be viewed automatically.
1081 If `not-confirm', pseudos will be viewed automatically, and the user
1082 will not be asked to confirm the command.")
1083
1084 (defvar gnus-view-pseudos-separately t
1085 "*If non-nil, one pseudo-article will be created for each file to be viewed.
1086 If nil, all files that use the same viewing command will be given as a
1087 list of parameters to that command.")
1088
1089 (defvar gnus-insert-pseudo-articles t
1090 "*If non-nil, insert pseudo-articles when decoding articles.")
1091
1092 (defvar gnus-group-line-format "%M%S%p%P%5y: %(%g%)%l\n"
1093 "*Format of group lines.
1094 It works along the same lines as a normal formatting string,
1095 with some simple extensions.
1096
1097 %M Only marked articles (character, \"*\" or \" \")
1098 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
1099 %L Level of subscribedness (integer)
1100 %N Number of unread articles (integer)
1101 %I Number of dormant articles (integer)
1102 %i Number of ticked and dormant (integer)
1103 %T Number of ticked articles (integer)
1104 %R Number of read articles (integer)
1105 %t Total number of articles (integer)
1106 %y Number of unread, unticked articles (integer)
1107 %G Group name (string)
1108 %g Qualified group name (string)
1109 %D Group description (string)
1110 %s Select method (string)
1111 %o Moderated group (char, \"m\")
1112 %p Process mark (char)
1113 %O Moderated group (string, \"(m)\" or \"\")
1114 %P Topic indentation (string)
1115 %l Whether there are GroupLens predictions for this group (string)
1116 %n Select from where (string)
1117 %z A string that look like `<%s:%n>' if a foreign select method is used
1118 %u User defined specifier. The next character in the format string should
1119 be a letter. Gnus will call the function gnus-user-format-function-X,
1120 where X is the letter following %u. The function will be passed the
1121 current header as argument. The function should return a string, which
1122 will be inserted into the buffer just like information from any other
1123 group specifier.
1124
1125 Text between %( and %) will be highlighted with `gnus-mouse-face' when
1126 the mouse point move inside the area. There can only be one such area.
1127
1128 Note that this format specification is not always respected. For
1129 reasons of efficiency, when listing killed groups, this specification
1130 is ignored altogether. If the spec is changed considerably, your
1131 output may end up looking strange when listing both alive and killed
1132 groups.
1133
1134 If you use %o or %O, reading the active file will be slower and quite
1135 a bit of extra memory will be used. %D will also worsen performance.
1136 Also note that if you change the format specification to include any
1137 of these specs, you must probably re-start Gnus to see them go into
1138 effect.")
1139
1140 (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
1141 "*The format specification of the lines in the summary buffer.
1142
1143 It works along the same lines as a normal formatting string,
1144 with some simple extensions.
1145
1146 %N Article number, left padded with spaces (string)
1147 %S Subject (string)
1148 %s Subject if it is at the root of a thread, and \"\" otherwise (string)
1149 %n Name of the poster (string)
1150 %a Extracted name of the poster (string)
1151 %A Extracted address of the poster (string)
1152 %F Contents of the From: header (string)
1153 %x Contents of the Xref: header (string)
1154 %D Date of the article (string)
1155 %d Date of the article (string) in DD-MMM format
1156 %M Message-id of the article (string)
1157 %r References of the article (string)
1158 %c Number of characters in the article (integer)
1159 %L Number of lines in the article (integer)
1160 %I Indentation based on thread level (a string of spaces)
1161 %T A string with two possible values: 80 spaces if the article
1162 is on thread level two or larger and 0 spaces on level one
1163 %R \"A\" if this article has been replied to, \" \" otherwise (character)
1164 %U Status of this article (character, \"R\", \"K\", \"-\" or \" \")
1165 %[ Opening bracket (character, \"[\" or \"<\")
1166 %] Closing bracket (character, \"]\" or \">\")
1167 %> Spaces of length thread-level (string)
1168 %< Spaces of length (- 20 thread-level) (string)
1169 %i Article score (number)
1170 %z Article zcore (character)
1171 %t Number of articles under the current thread (number).
1172 %e Whether the thread is empty or not (character).
1173 %l GroupLens score (string).
1174 %u User defined specifier. The next character in the format string should
1175 be a letter. Gnus will call the function gnus-user-format-function-X,
1176 where X is the letter following %u. The function will be passed the
1177 current header as argument. The function should return a string, which
1178 will be inserted into the summary just like information from any other
1179 summary specifier.
1180
1181 Text between %( and %) will be highlighted with `gnus-mouse-face'
1182 when the mouse point is placed inside the area. There can only be one
1183 such area.
1184
1185 The %U (status), %R (replied) and %z (zcore) specs have to be handled
1186 with care. For reasons of efficiency, Gnus will compute what column
1187 these characters will end up in, and \"hard-code\" that. This means that
1188 it is illegal to have these specs after a variable-length spec. Well,
1189 you might not be arrested, but your summary buffer will look strange,
1190 which is bad enough.
1191
1192 The smart choice is to have these specs as for to the left as
1193 possible.
1194
1195 This restriction may disappear in later versions of Gnus.")
1196
1197 (defvar gnus-summary-dummy-line-format
1198 "* %(: :%) %S\n"
1199 "*The format specification for the dummy roots in the summary buffer.
1200 It works along the same lines as a normal formatting string,
1201 with some simple extensions.
1202
1203 %S The subject")
1204
1205 (defvar gnus-summary-mode-line-format "Gnus: %%b [%A] %Z"
1206 "*The format specification for the summary mode line.
1207 It works along the same lines as a normal formatting string,
1208 with some simple extensions:
1209
1210 %G Group name
1211 %p Unprefixed group name
1212 %A Current article number
1213 %V Gnus version
1214 %U Number of unread articles in the group
1215 %e Number of unselected articles in the group
1216 %Z A string with unread/unselected article counts
1217 %g Shortish group name
1218 %S Subject of the current article
1219 %u User-defined spec
1220 %s Current score file name
1221 %d Number of dormant articles
1222 %r Number of articles that have been marked as read in this session
1223 %E Number of articles expunged by the score files")
1224
1225 (defvar gnus-article-mode-line-format "Gnus: %%b %S"
1226 "*The format specification for the article mode line.
1227 See `gnus-summary-mode-line-format' for a closer description.")
1228
1229 (defvar gnus-group-mode-line-format "Gnus: %%b {%M%:%S}"
1230 "*The format specification for the group mode line.
1231 It works along the same lines as a normal formatting string,
1232 with some simple extensions:
1233
1234 %S The native news server.
1235 %M The native select method.
1236 %: \":\" if %S isn't \"\".")
1237
1238 (defvar gnus-valid-select-methods
1239 '(("nntp" post address prompt-address)
1240 ("nnspool" post address)
1241 ("nnvirtual" post-mail virtual prompt-address)
1242 ("nnmbox" mail respool address)
1243 ("nnml" mail respool address)
1244 ("nnmh" mail respool address)
1245 ("nndir" post-mail prompt-address address)
1246 ("nneething" none address prompt-address)
1247 ("nndoc" none address prompt-address)
1248 ("nnbabyl" mail address respool)
1249 ("nnkiboze" post virtual)
1250 ("nnsoup" post-mail address)
1251 ("nndraft" post-mail)
1252 ("nnfolder" mail respool address))
1253 "An alist of valid select methods.
1254 The first element of each list lists should be a string with the name
1255 of the select method. The other elements may be be the category of
1256 this method (ie. `post', `mail', `none' or whatever) or other
1257 properties that this method has (like being respoolable).
1258 If you implement a new select method, all you should have to change is
1259 this variable. I think.")
1260
1261 (defvar gnus-updated-mode-lines '(group article summary tree)
1262 "*List of buffers that should update their mode lines.
1263 The list may contain the symbols `group', `article' and `summary'. If
1264 the corresponding symbol is present, Gnus will keep that mode line
1265 updated with information that may be pertinent.
1266 If this variable is nil, screen refresh may be quicker.")
1267
1268 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1269 (defvar gnus-mode-non-string-length nil
1270 "*Max length of mode-line non-string contents.
1271 If this is nil, Gnus will take space as is needed, leaving the rest
1272 of the modeline intact.")
1273
1274 ;see gnus-cus.el
1275 ;(defvar gnus-mouse-face 'highlight
1276 ; "*Face used for mouse highlighting in Gnus.
1277 ;No mouse highlights will be done if `gnus-visual' is nil.")
1278
1279 (defvar gnus-summary-mark-below 0
1280 "*Mark all articles with a score below this variable as read.
1281 This variable is local to each summary buffer and usually set by the
1282 score file.")
1283
1284 (defvar gnus-article-sort-functions '(gnus-article-sort-by-number)
1285 "*List of functions used for sorting articles in the summary buffer.
1286 This variable is only used when not using a threaded display.")
1287
1288 (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
1289 "*List of functions used for sorting threads in the summary buffer.
1290 By default, threads are sorted by article number.
1291
1292 Each function takes two threads and return non-nil if the first thread
1293 should be sorted before the other. If you use more than one function,
1294 the primary sort function should be the last. You should probably
1295 always include `gnus-thread-sort-by-number' in the list of sorting
1296 functions -- preferably first.
1297
1298 Ready-mady functions include `gnus-thread-sort-by-number',
1299 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
1300 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
1301 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
1302
1303 (defvar gnus-thread-score-function '+
1304 "*Function used for calculating the total score of a thread.
1305
1306 The function is called with the scores of the article and each
1307 subthread and should then return the score of the thread.
1308
1309 Some functions you can use are `+', `max', or `min'.")
1310
1311 (defvar gnus-summary-expunge-below nil
1312 "All articles that have a score less than this variable will be expunged.")
1313
1314 (defvar gnus-thread-expunge-below nil
1315 "All threads that have a total score less than this variable will be expunged.
1316 See `gnus-thread-score-function' for en explanation of what a
1317 \"thread score\" is.")
1318
1319 (defvar gnus-auto-subscribed-groups
1320 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
1321 "*All new groups that match this regexp will be subscribed automatically.
1322 Note that this variable only deals with new groups. It has no effect
1323 whatsoever on old groups.
1324
1325 New groups that match this regexp will not be handled by
1326 `gnus-subscribe-newsgroup-method'. Instead, they will
1327 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
1328
1329 (defvar gnus-options-subscribe nil
1330 "*All new groups matching this regexp will be subscribed unconditionally.
1331 Note that this variable deals only with new newsgroups. This variable
1332 does not affect old newsgroups.
1333
1334 New groups that match this regexp will not be handled by
1335 `gnus-subscribe-newsgroup-method'. Instead, they will
1336 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
1337
1338 (defvar gnus-options-not-subscribe nil
1339 "*All new groups matching this regexp will be ignored.
1340 Note that this variable deals only with new newsgroups. This variable
1341 does not affect old (already subscribed) newsgroups.")
1342
1343 (defvar gnus-auto-expirable-newsgroups nil
1344 "*Groups in which to automatically mark read articles as expirable.
1345 If non-nil, this should be a regexp that should match all groups in
1346 which to perform auto-expiry. This only makes sense for mail groups.")
1347
1348 (defvar gnus-total-expirable-newsgroups nil
1349 "*Groups in which to perform expiry of all read articles.
1350 Use with extreme caution. All groups that match this regexp will be
1351 expiring - which means that all read articles will be deleted after
1352 (say) one week. (This only goes for mail groups and the like, of
1353 course.)")
1354
1355 (defvar gnus-group-uncollapsed-levels 1
1356 "Number of group name elements to leave alone when making a short group name.")
1357
1358 (defvar gnus-hidden-properties '(invisible t intangible t)
1359 "Property list to use for hiding text.")
1360
1361 (defvar gnus-modtime-botch nil
1362 "*Non-nil means .newsrc should be deleted prior to save.
1363 Its use is due to the bogus appearance that .newsrc was modified on
1364 disc.")
1365
1366 ;; Hooks.
1367
1368 (defvar gnus-group-mode-hook nil
1369 "*A hook for Gnus group mode.")
1370
1371 (defvar gnus-summary-mode-hook nil
1372 "*A hook for Gnus summary mode.
1373 This hook is run before any variables are set in the summary buffer.")
1374
1375 (defvar gnus-article-mode-hook nil
1376 "*A hook for Gnus article mode.")
1377
1378 (defvar gnus-summary-prepare-exit-hook nil
1379 "*A hook called when preparing to exit from the summary buffer.
1380 It calls `gnus-summary-expire-articles' by default.")
1381 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
1382
1383 (defvar gnus-summary-exit-hook nil
1384 "*A hook called on exit from the summary buffer.")
1385
1386 (defvar gnus-group-catchup-group-hook nil
1387 "*A hook run when catching up a group from the group buffer.")
1388
1389 (defvar gnus-group-update-group-hook nil
1390 "*A hook called when updating group lines.")
1391
1392 (defvar gnus-open-server-hook nil
1393 "*A hook called just before opening connection to the news server.")
1394
1395 (defvar gnus-load-hook nil
1396 "*A hook run while Gnus is loaded.")
1397
1398 (defvar gnus-startup-hook nil
1399 "*A hook called at startup.
1400 This hook is called after Gnus is connected to the NNTP server.")
1401
1402 (defvar gnus-get-new-news-hook nil
1403 "*A hook run just before Gnus checks for new news.")
1404
1405 (defvar gnus-after-getting-new-news-hook nil
1406 "*A hook run after Gnus checks for new news.")
1407
1408 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
1409 "*A function that is called to generate the group buffer.
1410 The function is called with three arguments: The first is a number;
1411 all group with a level less or equal to that number should be listed,
1412 if the second is non-nil, empty groups should also be displayed. If
1413 the third is non-nil, it is a number. No groups with a level lower
1414 than this number should be displayed.
1415
1416 The only current function implemented is `gnus-group-prepare-flat'.")
1417
1418 (defvar gnus-group-prepare-hook nil
1419 "*A hook called after the group buffer has been generated.
1420 If you want to modify the group buffer, you can use this hook.")
1421
1422 (defvar gnus-summary-prepare-hook nil
1423 "*A hook called after the summary buffer has been generated.
1424 If you want to modify the summary buffer, you can use this hook.")
1425
1426 (defvar gnus-summary-generate-hook nil
1427 "*A hook run just before generating the summary buffer.
1428 This hook is commonly used to customize threading variables and the
1429 like.")
1430
1431 (defvar gnus-article-prepare-hook nil
1432 "*A hook called after an article has been prepared in the article buffer.
1433 If you want to run a special decoding program like nkf, use this hook.")
1434
1435 ;(defvar gnus-article-display-hook nil
1436 ; "*A hook called after the article is displayed in the article buffer.
1437 ;The hook is designed to change the contents of the article
1438 ;buffer. Typical functions that this hook may contain are
1439 ;`gnus-article-hide-headers' (hide selected headers),
1440 ;`gnus-article-maybe-highlight' (perform fancy article highlighting),
1441 ;`gnus-article-hide-signature' (hide signature) and
1442 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
1443 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
1444 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
1445 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
1446
1447 (defvar gnus-article-x-face-too-ugly nil
1448 "Regexp matching posters whose face shouldn't be shown automatically.")
1449
1450 (defvar gnus-select-group-hook nil
1451 "*A hook called when a newsgroup is selected.
1452
1453 If you'd like to simplify subjects like the
1454 `gnus-summary-next-same-subject' command does, you can use the
1455 following hook:
1456
1457 (setq gnus-select-group-hook
1458 (list
1459 (lambda ()
1460 (mapcar (lambda (header)
1461 (mail-header-set-subject
1462 header
1463 (gnus-simplify-subject
1464 (mail-header-subject header) 're-only)))
1465 gnus-newsgroup-headers))))")
1466
1467 (defvar gnus-select-article-hook nil
1468 "*A hook called when an article is selected.")
1469
1470 (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
1471 "*A hook called to apply kill files to a group.
1472 This hook is intended to apply a kill file to the selected newsgroup.
1473 The function `gnus-apply-kill-file' is called by default.
1474
1475 Since a general kill file is too heavy to use only for a few
1476 newsgroups, I recommend you to use a lighter hook function. For
1477 example, if you'd like to apply a kill file to articles which contains
1478 a string `rmgroup' in subject in newsgroup `control', you can use the
1479 following hook:
1480
1481 (setq gnus-apply-kill-hook
1482 (list
1483 (lambda ()
1484 (cond ((string-match \"control\" gnus-newsgroup-name)
1485 (gnus-kill \"Subject\" \"rmgroup\")
1486 (gnus-expunge \"X\"))))))")
1487
1488 (defvar gnus-visual-mark-article-hook
1489 (list 'gnus-highlight-selected-summary)
1490 "*Hook run after selecting an article in the summary buffer.
1491 It is meant to be used for highlighting the article in some way. It
1492 is not run if `gnus-visual' is nil.")
1493
1494 (defvar gnus-parse-headers-hook nil
1495 "*A hook called before parsing the headers.")
1496 (add-hook 'gnus-parse-headers-hook 'gnus-decode-rfc1522)
1497
1498 (defvar gnus-exit-group-hook nil
1499 "*A hook called when exiting (not quitting) summary mode.")
1500
1501 (defvar gnus-suspend-gnus-hook nil
1502 "*A hook called when suspending (not exiting) Gnus.")
1503
1504 (defvar gnus-exit-gnus-hook nil
1505 "*A hook called when exiting Gnus.")
1506
1507 (defvar gnus-after-exiting-gnus-hook nil
1508 "*A hook called after exiting Gnus.")
1509
1510 (defvar gnus-save-newsrc-hook nil
1511 "*A hook called before saving any of the newsrc files.")
1512
1513 (defvar gnus-save-quick-newsrc-hook nil
1514 "*A hook called just before saving the quick newsrc file.
1515 Can be used to turn version control on or off.")
1516
1517 (defvar gnus-save-standard-newsrc-hook nil
1518 "*A hook called just before saving the standard newsrc file.
1519 Can be used to turn version control on or off.")
1520
1521 (defvar gnus-summary-update-hook
1522 (list 'gnus-summary-highlight-line)
1523 "*A hook called when a summary line is changed.
1524 The hook will not be called if `gnus-visual' is nil.
1525
1526 The default function `gnus-summary-highlight-line' will
1527 highlight the line according to the `gnus-summary-highlight'
1528 variable.")
1529
1530 (defvar gnus-group-update-hook '(gnus-group-highlight-line)
1531 "*A hook called when a group line is changed.
1532 The hook will not be called if `gnus-visual' is nil.
1533
1534 The default function `gnus-group-highlight-line' will
1535 highlight the line according to the `gnus-group-highlight'
1536 variable.")
1537
1538 (defvar gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
1539 "*A hook called when an article is selected for the first time.
1540 The hook is intended to mark an article as read (or unread)
1541 automatically when it is selected.")
1542
1543 (defvar gnus-group-change-level-function nil
1544 "Function run when a group level is changed.
1545 It is called with three parameters -- GROUP, LEVEL and OLDLEVEL.")
1546
1547 ;; Remove any hilit infestation.
1548 (add-hook 'gnus-startup-hook
1549 (lambda ()
1550 (remove-hook 'gnus-summary-prepare-hook
1551 'hilit-rehighlight-buffer-quietly)
1552 (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
1553 (setq gnus-mark-article-hook
1554 '(gnus-summary-mark-read-and-unread-as-read))
1555 (remove-hook 'gnus-article-prepare-hook
1556 'hilit-rehighlight-buffer-quietly)))
1557
1558 \f
1559 ;; Internal variables
1560
1561 (defvar gnus-tree-buffer "*Tree*"
1562 "Buffer where Gnus thread trees are displayed.")
1563
1564 ;; Dummy variable.
1565 (defvar gnus-use-generic-from nil)
1566
1567 (defvar gnus-thread-indent-array nil)
1568 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1569
1570 (defvar gnus-newsrc-file-version nil)
1571
1572 (defvar gnus-method-history nil)
1573 ;; Variable holding the user answers to all method prompts.
1574
1575 (defvar gnus-group-history nil)
1576 ;; Variable holding the user answers to all group prompts.
1577
1578 (defvar gnus-server-alist nil
1579 "List of available servers.")
1580
1581 (defvar gnus-group-indentation-function nil)
1582
1583 (defvar gnus-topic-indentation "") ;; Obsolete variable.
1584
1585 (defvar gnus-goto-missing-group-function nil)
1586
1587 (defvar gnus-override-subscribe-method nil)
1588
1589 (defvar gnus-group-goto-next-group-function nil
1590 "Function to override finding the next group after listing groups.")
1591
1592 (defconst gnus-article-mark-lists
1593 '((marked . tick) (replied . reply)
1594 (expirable . expire) (killed . killed)
1595 (bookmarks . bookmark) (dormant . dormant)
1596 (scored . score) (saved . save)
1597 (cached . cache)
1598 ))
1599
1600 ;; Avoid highlighting in kill files.
1601 (defvar gnus-summary-inhibit-highlight nil)
1602 (defvar gnus-newsgroup-selected-overlay nil)
1603
1604 (defvar gnus-inhibit-hiding nil)
1605 (defvar gnus-group-indentation "")
1606 (defvar gnus-inhibit-limiting nil)
1607 (defvar gnus-created-frames nil)
1608
1609 (defvar gnus-article-mode-map nil)
1610 (defvar gnus-dribble-buffer nil)
1611 (defvar gnus-headers-retrieved-by nil)
1612 (defvar gnus-article-reply nil)
1613 (defvar gnus-override-method nil)
1614 (defvar gnus-article-check-size nil)
1615
1616 (defvar gnus-current-score-file nil)
1617 (defvar gnus-newsgroup-adaptive-score-file nil)
1618 (defvar gnus-scores-exclude-files nil)
1619
1620 (defvar gnus-opened-servers nil)
1621
1622 (defvar gnus-current-move-group nil)
1623 (defvar gnus-current-copy-group nil)
1624 (defvar gnus-current-crosspost-group nil)
1625
1626 (defvar gnus-newsgroup-dependencies nil)
1627 (defvar gnus-newsgroup-async nil)
1628 (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
1629
1630 (defvar gnus-newsgroup-adaptive nil)
1631
1632 (defvar gnus-summary-display-table nil)
1633 (defvar gnus-summary-display-article-function nil)
1634
1635 (defvar gnus-summary-highlight-line-function nil
1636 "Function called after highlighting a summary line.")
1637
1638 (defvar gnus-group-line-format-alist
1639 `((?M gnus-tmp-marked-mark ?c)
1640 (?S gnus-tmp-subscribed ?c)
1641 (?L gnus-tmp-level ?d)
1642 (?N (cond ((eq number t) "*" )
1643 ((numberp number)
1644 (int-to-string
1645 (+ number
1646 (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
1647 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
1648 (t number)) ?s)
1649 (?R gnus-tmp-number-of-read ?s)
1650 (?t gnus-tmp-number-total ?d)
1651 (?y gnus-tmp-number-of-unread ?s)
1652 (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
1653 (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
1654 (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
1655 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
1656 (?g gnus-tmp-group ?s)
1657 (?G gnus-tmp-qualified-group ?s)
1658 (?c (gnus-short-group-name gnus-tmp-group) ?s)
1659 (?D gnus-tmp-newsgroup-description ?s)
1660 (?o gnus-tmp-moderated ?c)
1661 (?O gnus-tmp-moderated-string ?s)
1662 (?p gnus-tmp-process-marked ?c)
1663 (?s gnus-tmp-news-server ?s)
1664 (?n gnus-tmp-news-method ?s)
1665 (?P gnus-group-indentation ?s)
1666 (?l gnus-tmp-grouplens ?s)
1667 (?z gnus-tmp-news-method-string ?s)
1668 (?u gnus-tmp-user-defined ?s)))
1669
1670 (defvar gnus-summary-line-format-alist
1671 `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1672 (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1673 (?s gnus-tmp-subject-or-nil ?s)
1674 (?n gnus-tmp-name ?s)
1675 (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1676 ?s)
1677 (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1678 gnus-tmp-from) ?s)
1679 (?F gnus-tmp-from ?s)
1680 (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1681 (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1682 (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1683 (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1684 (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1685 (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1686 (?L gnus-tmp-lines ?d)
1687 (?I gnus-tmp-indentation ?s)
1688 (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1689 (?R gnus-tmp-replied ?c)
1690 (?\[ gnus-tmp-opening-bracket ?c)
1691 (?\] gnus-tmp-closing-bracket ?c)
1692 (?\> (make-string gnus-tmp-level ? ) ?s)
1693 (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1694 (?i gnus-tmp-score ?d)
1695 (?z gnus-tmp-score-char ?c)
1696 (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1697 (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1698 (?U gnus-tmp-unread ?c)
1699 (?t (gnus-summary-number-of-articles-in-thread
1700 (and (boundp 'thread) (car thread)) gnus-tmp-level)
1701 ?d)
1702 (?e (gnus-summary-number-of-articles-in-thread
1703 (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1704 ?c)
1705 (?u gnus-tmp-user-defined ?s))
1706 "An alist of format specifications that can appear in summary lines,
1707 and what variables they correspond with, along with the type of the
1708 variable (string, integer, character, etc).")
1709
1710 (defvar gnus-summary-dummy-line-format-alist
1711 `((?S gnus-tmp-subject ?s)
1712 (?N gnus-tmp-number ?d)
1713 (?u gnus-tmp-user-defined ?s)))
1714
1715 (defvar gnus-summary-mode-line-format-alist
1716 `((?G gnus-tmp-group-name ?s)
1717 (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1718 (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1719 (?A gnus-tmp-article-number ?d)
1720 (?Z gnus-tmp-unread-and-unselected ?s)
1721 (?V gnus-version ?s)
1722 (?U gnus-tmp-unread-and-unticked ?d)
1723 (?S gnus-tmp-subject ?s)
1724 (?e gnus-tmp-unselected ?d)
1725 (?u gnus-tmp-user-defined ?s)
1726 (?d (length gnus-newsgroup-dormant) ?d)
1727 (?t (length gnus-newsgroup-marked) ?d)
1728 (?r (length gnus-newsgroup-reads) ?d)
1729 (?E gnus-newsgroup-expunged-tally ?d)
1730 (?s (gnus-current-score-file-nondirectory) ?s)))
1731
1732 (defvar gnus-article-mode-line-format-alist
1733 gnus-summary-mode-line-format-alist)
1734
1735 (defvar gnus-group-mode-line-format-alist
1736 `((?S gnus-tmp-news-server ?s)
1737 (?M gnus-tmp-news-method ?s)
1738 (?u gnus-tmp-user-defined ?s)
1739 (?: gnus-tmp-colon ?s)))
1740
1741 (defvar gnus-have-read-active-file nil)
1742
1743 (defconst gnus-maintainer
1744 "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
1745 "The mail address of the Gnus maintainers.")
1746
1747 (defconst gnus-version-number "5.3"
1748 "Version number for this version of Gnus.")
1749
1750 (defconst gnus-version (format "Gnus v%s" gnus-version-number)
1751 "Version string for this version of Gnus.")
1752
1753 (defvar gnus-info-nodes
1754 '((gnus-group-mode "(gnus)The Group Buffer")
1755 (gnus-summary-mode "(gnus)The Summary Buffer")
1756 (gnus-article-mode "(gnus)The Article Buffer")
1757 (gnus-server-mode "(gnus)The Server Buffer")
1758 (gnus-browse-mode "(gnus)Browse Foreign Server")
1759 (gnus-tree-mode "(gnus)Tree Display")
1760 )
1761 "Alist of major modes and related Info nodes.")
1762
1763 (defvar gnus-group-buffer "*Group*")
1764 (defvar gnus-summary-buffer "*Summary*")
1765 (defvar gnus-article-buffer "*Article*")
1766 (defvar gnus-server-buffer "*Server*")
1767
1768 (defvar gnus-work-buffer " *gnus work*")
1769
1770 (defvar gnus-original-article-buffer " *Original Article*")
1771 (defvar gnus-original-article nil)
1772
1773 (defvar gnus-buffer-list nil
1774 "Gnus buffers that should be killed on exit.")
1775
1776 (defvar gnus-slave nil
1777 "Whether this Gnus is a slave or not.")
1778
1779 (defvar gnus-variable-list
1780 '(gnus-newsrc-options gnus-newsrc-options-n
1781 gnus-newsrc-last-checked-date
1782 gnus-newsrc-alist gnus-server-alist
1783 gnus-killed-list gnus-zombie-list
1784 gnus-topic-topology gnus-topic-alist
1785 gnus-format-specs)
1786 "Gnus variables saved in the quick startup file.")
1787
1788 (defvar gnus-newsrc-options nil
1789 "Options line in the .newsrc file.")
1790
1791 (defvar gnus-newsrc-options-n nil
1792 "List of regexps representing groups to be subscribed/ignored unconditionally.")
1793
1794 (defvar gnus-newsrc-last-checked-date nil
1795 "Date Gnus last asked server for new newsgroups.")
1796
1797 (defvar gnus-topic-topology nil
1798 "The complete topic hierarchy.")
1799
1800 (defvar gnus-topic-alist nil
1801 "The complete topic-group alist.")
1802
1803 (defvar gnus-newsrc-alist nil
1804 "Assoc list of read articles.
1805 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1806
1807 (defvar gnus-newsrc-hashtb nil
1808 "Hashtable of gnus-newsrc-alist.")
1809
1810 (defvar gnus-killed-list nil
1811 "List of killed newsgroups.")
1812
1813 (defvar gnus-killed-hashtb nil
1814 "Hash table equivalent of gnus-killed-list.")
1815
1816 (defvar gnus-zombie-list nil
1817 "List of almost dead newsgroups.")
1818
1819 (defvar gnus-description-hashtb nil
1820 "Descriptions of newsgroups.")
1821
1822 (defvar gnus-list-of-killed-groups nil
1823 "List of newsgroups that have recently been killed by the user.")
1824
1825 (defvar gnus-active-hashtb nil
1826 "Hashtable of active articles.")
1827
1828 (defvar gnus-moderated-list nil
1829 "List of moderated newsgroups.")
1830
1831 (defvar gnus-group-marked nil)
1832
1833 (defvar gnus-current-startup-file nil
1834 "Startup file for the current host.")
1835
1836 (defvar gnus-last-search-regexp nil
1837 "Default regexp for article search command.")
1838
1839 (defvar gnus-last-shell-command nil
1840 "Default shell command on article.")
1841
1842 (defvar gnus-current-select-method nil
1843 "The current method for selecting a newsgroup.")
1844
1845 (defvar gnus-group-list-mode nil)
1846
1847 (defvar gnus-article-internal-prepare-hook nil)
1848
1849 (defvar gnus-newsgroup-name nil)
1850 (defvar gnus-newsgroup-begin nil)
1851 (defvar gnus-newsgroup-end nil)
1852 (defvar gnus-newsgroup-last-rmail nil)
1853 (defvar gnus-newsgroup-last-mail nil)
1854 (defvar gnus-newsgroup-last-folder nil)
1855 (defvar gnus-newsgroup-last-file nil)
1856 (defvar gnus-newsgroup-auto-expire nil)
1857 (defvar gnus-newsgroup-active nil)
1858
1859 (defvar gnus-newsgroup-data nil)
1860 (defvar gnus-newsgroup-data-reverse nil)
1861 (defvar gnus-newsgroup-limit nil)
1862 (defvar gnus-newsgroup-limits nil)
1863
1864 (defvar gnus-newsgroup-unreads nil
1865 "List of unread articles in the current newsgroup.")
1866
1867 (defvar gnus-newsgroup-unselected nil
1868 "List of unselected unread articles in the current newsgroup.")
1869
1870 (defvar gnus-newsgroup-reads nil
1871 "Alist of read articles and article marks in the current newsgroup.")
1872
1873 (defvar gnus-newsgroup-expunged-tally nil)
1874
1875 (defvar gnus-newsgroup-marked nil
1876 "List of ticked articles in the current newsgroup (a subset of unread art).")
1877
1878 (defvar gnus-newsgroup-killed nil
1879 "List of ranges of articles that have been through the scoring process.")
1880
1881 (defvar gnus-newsgroup-cached nil
1882 "List of articles that come from the article cache.")
1883
1884 (defvar gnus-newsgroup-saved nil
1885 "List of articles that have been saved.")
1886
1887 (defvar gnus-newsgroup-kill-headers nil)
1888
1889 (defvar gnus-newsgroup-replied nil
1890 "List of articles that have been replied to in the current newsgroup.")
1891
1892 (defvar gnus-newsgroup-expirable nil
1893 "List of articles in the current newsgroup that can be expired.")
1894
1895 (defvar gnus-newsgroup-processable nil
1896 "List of articles in the current newsgroup that can be processed.")
1897
1898 (defvar gnus-newsgroup-bookmarks nil
1899 "List of articles in the current newsgroup that have bookmarks.")
1900
1901 (defvar gnus-newsgroup-dormant nil
1902 "List of dormant articles in the current newsgroup.")
1903
1904 (defvar gnus-newsgroup-scored nil
1905 "List of scored articles in the current newsgroup.")
1906
1907 (defvar gnus-newsgroup-headers nil
1908 "List of article headers in the current newsgroup.")
1909
1910 (defvar gnus-newsgroup-threads nil)
1911
1912 (defvar gnus-newsgroup-prepared nil
1913 "Whether the current group has been prepared properly.")
1914
1915 (defvar gnus-newsgroup-ancient nil
1916 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1917
1918 (defvar gnus-newsgroup-sparse nil)
1919
1920 (defvar gnus-current-article nil)
1921 (defvar gnus-article-current nil)
1922 (defvar gnus-current-headers nil)
1923 (defvar gnus-have-all-headers nil)
1924 (defvar gnus-last-article nil)
1925 (defvar gnus-newsgroup-history nil)
1926 (defvar gnus-current-kill-article nil)
1927
1928 ;; Save window configuration.
1929 (defvar gnus-prev-winconf nil)
1930
1931 (defvar gnus-summary-mark-positions nil)
1932 (defvar gnus-group-mark-positions nil)
1933
1934 (defvar gnus-reffed-article-number nil)
1935
1936 ;;; Let the byte-compiler know that we know about this variable.
1937 (defvar rmail-default-rmail-file)
1938
1939 (defvar gnus-cache-removable-articles nil)
1940
1941 (defvar gnus-dead-summary nil)
1942
1943 (defconst gnus-summary-local-variables
1944 '(gnus-newsgroup-name
1945 gnus-newsgroup-begin gnus-newsgroup-end
1946 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1947 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1948 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1949 gnus-newsgroup-unselected gnus-newsgroup-marked
1950 gnus-newsgroup-reads gnus-newsgroup-saved
1951 gnus-newsgroup-replied gnus-newsgroup-expirable
1952 gnus-newsgroup-processable gnus-newsgroup-killed
1953 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1954 gnus-newsgroup-headers gnus-newsgroup-threads
1955 gnus-newsgroup-prepared gnus-summary-highlight-line-function
1956 gnus-current-article gnus-current-headers gnus-have-all-headers
1957 gnus-last-article gnus-article-internal-prepare-hook
1958 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1959 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1960 gnus-newsgroup-async gnus-thread-expunge-below
1961 gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1962 (gnus-summary-mark-below . global)
1963 gnus-newsgroup-active gnus-scores-exclude-files
1964 gnus-newsgroup-history gnus-newsgroup-ancient
1965 gnus-newsgroup-sparse
1966 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1967 gnus-newsgroup-adaptive-score-file
1968 (gnus-newsgroup-expunged-tally . 0)
1969 gnus-cache-removable-articles gnus-newsgroup-cached
1970 gnus-newsgroup-data gnus-newsgroup-data-reverse
1971 gnus-newsgroup-limit gnus-newsgroup-limits)
1972 "Variables that are buffer-local to the summary buffers.")
1973
1974 (defconst gnus-bug-message
1975 "Sending a bug report to the Gnus Towers.
1976 ========================================
1977
1978 The buffer below is a mail buffer. When you press `C-c C-c', it will
1979 be sent to the Gnus Bug Exterminators.
1980
1981 At the bottom of the buffer you'll see lots of variable settings.
1982 Please do not delete those. They will tell the Bug People what your
1983 environment is, so that it will be easier to locate the bugs.
1984
1985 If you have found a bug that makes Emacs go \"beep\", set
1986 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
1987 and include the backtrace in your bug report.
1988
1989 Please describe the bug in annoying, painstaking detail.
1990
1991 Thank you for your help in stamping out bugs.
1992 ")
1993
1994 ;;; End of variables.
1995
1996 ;; Define some autoload functions Gnus might use.
1997 (eval-and-compile
1998
1999 ;; This little mapcar goes through the list below and marks the
2000 ;; symbols in question as autoloaded functions.
2001 (mapcar
2002 (lambda (package)
2003 (let ((interactive (nth 1 (memq ':interactive package))))
2004 (mapcar
2005 (lambda (function)
2006 (let (keymap)
2007 (when (consp function)
2008 (setq keymap (car (memq 'keymap function)))
2009 (setq function (car function)))
2010 (autoload function (car package) nil interactive keymap)))
2011 (if (eq (nth 1 package) ':interactive)
2012 (cdddr package)
2013 (cdr package)))))
2014 '(("metamail" metamail-buffer)
2015 ("info" Info-goto-node)
2016 ("hexl" hexl-hex-string-to-integer)
2017 ("pp" pp pp-to-string pp-eval-expression)
2018 ("mail-extr" mail-extract-address-components)
2019 ("nnmail" nnmail-split-fancy nnmail-article-group)
2020 ("nnvirtual" nnvirtual-catchup-group)
2021 ("timezone" timezone-make-date-arpa-standard timezone-fix-time
2022 timezone-make-sortable-date timezone-make-time-string)
2023 ("rmailout" rmail-output)
2024 ("rmail" rmail-insert-rmail-file-header rmail-count-new-messages
2025 rmail-show-message)
2026 ("gnus-soup" :interactive t
2027 gnus-group-brew-soup gnus-brew-soup gnus-soup-add-article
2028 gnus-soup-send-replies gnus-soup-save-areas gnus-soup-pack-packet)
2029 ("nnsoup" nnsoup-pack-replies)
2030 ("score-mode" :interactive t gnus-score-mode)
2031 ("gnus-mh" gnus-mh-mail-setup gnus-summary-save-article-folder
2032 gnus-Folder-save-name gnus-folder-save-name)
2033 ("gnus-mh" :interactive t gnus-summary-save-in-folder)
2034 ("gnus-vis" gnus-group-make-menu-bar gnus-summary-make-menu-bar
2035 gnus-server-make-menu-bar gnus-article-make-menu-bar
2036 gnus-browse-make-menu-bar gnus-highlight-selected-summary
2037 gnus-summary-highlight-line gnus-carpal-setup-buffer
2038 gnus-group-highlight-line
2039 gnus-article-add-button gnus-insert-next-page-button
2040 gnus-insert-prev-page-button gnus-visual-turn-off-edit-menu)
2041 ("gnus-vis" :interactive t
2042 gnus-article-push-button gnus-article-press-button
2043 gnus-article-highlight gnus-article-highlight-some
2044 gnus-article-highlight-headers gnus-article-highlight-signature
2045 gnus-article-add-buttons gnus-article-add-buttons-to-head
2046 gnus-article-next-button gnus-article-prev-button)
2047 ("gnus-demon" gnus-demon-add-nocem gnus-demon-add-scanmail
2048 gnus-demon-add-disconnection gnus-demon-add-handler
2049 gnus-demon-remove-handler)
2050 ("gnus-demon" :interactive t
2051 gnus-demon-init gnus-demon-cancel)
2052 ("gnus-salt" gnus-highlight-selected-tree gnus-possibly-generate-tree
2053 gnus-tree-open gnus-tree-close)
2054 ("gnus-nocem" gnus-nocem-scan-groups gnus-nocem-close
2055 gnus-nocem-unwanted-article-p)
2056 ("gnus-srvr" gnus-enter-server-buffer gnus-server-set-info)
2057 ("gnus-srvr" gnus-browse-foreign-server)
2058 ("gnus-cite" :interactive t
2059 gnus-article-highlight-citation gnus-article-hide-citation-maybe
2060 gnus-article-hide-citation gnus-article-fill-cited-article
2061 gnus-article-hide-citation-in-followups)
2062 ("gnus-kill" gnus-kill gnus-apply-kill-file-internal
2063 gnus-kill-file-edit-file gnus-kill-file-raise-followups-to-author
2064 gnus-execute gnus-expunge)
2065 ("gnus-cache" gnus-cache-possibly-enter-article gnus-cache-save-buffers
2066 gnus-cache-possibly-remove-articles gnus-cache-request-article
2067 gnus-cache-retrieve-headers gnus-cache-possibly-alter-active
2068 gnus-cache-enter-remove-article gnus-cached-article-p
2069 gnus-cache-open gnus-cache-close gnus-cache-update-article)
2070 ("gnus-cache" :interactive t gnus-jog-cache gnus-cache-enter-article
2071 gnus-cache-remove-article)
2072 ("gnus-score" :interactive t
2073 gnus-summary-increase-score gnus-summary-lower-score
2074 gnus-score-flush-cache gnus-score-close
2075 gnus-score-raise-same-subject-and-select
2076 gnus-score-raise-same-subject gnus-score-default
2077 gnus-score-raise-thread gnus-score-lower-same-subject-and-select
2078 gnus-score-lower-same-subject gnus-score-lower-thread
2079 gnus-possibly-score-headers gnus-summary-raise-score
2080 gnus-summary-set-score gnus-summary-current-score)
2081 ("gnus-score"
2082 (gnus-summary-score-map keymap) gnus-score-save gnus-score-headers
2083 gnus-current-score-file-nondirectory gnus-score-adaptive
2084 gnus-score-find-trace gnus-score-file-name)
2085 ("gnus-edit" :interactive t gnus-score-customize)
2086 ("gnus-topic" :interactive t gnus-topic-mode)
2087 ("gnus-topic" gnus-topic-remove-group)
2088 ("gnus-salt" :interactive t gnus-pick-mode gnus-binary-mode)
2089 ("gnus-uu" (gnus-uu-extract-map keymap) (gnus-uu-mark-map keymap))
2090 ("gnus-uu" :interactive t
2091 gnus-uu-digest-mail-forward gnus-uu-digest-post-forward
2092 gnus-uu-mark-series gnus-uu-mark-region gnus-uu-mark-buffer
2093 gnus-uu-mark-by-regexp gnus-uu-mark-all
2094 gnus-uu-mark-sparse gnus-uu-mark-thread gnus-uu-decode-uu
2095 gnus-uu-decode-uu-and-save gnus-uu-decode-unshar
2096 gnus-uu-decode-unshar-and-save gnus-uu-decode-save
2097 gnus-uu-decode-binhex gnus-uu-decode-uu-view
2098 gnus-uu-decode-uu-and-save-view gnus-uu-decode-unshar-view
2099 gnus-uu-decode-unshar-and-save-view gnus-uu-decode-save-view
2100 gnus-uu-decode-binhex-view)
2101 ("gnus-msg" (gnus-summary-send-map keymap)
2102 gnus-mail-yank-original gnus-mail-send-and-exit
2103 gnus-article-mail gnus-new-mail gnus-mail-reply)
2104 ("gnus-msg" :interactive t
2105 gnus-group-post-news gnus-group-mail gnus-summary-post-news
2106 gnus-summary-followup gnus-summary-followup-with-original
2107 gnus-summary-cancel-article gnus-summary-supersede-article
2108 gnus-post-news gnus-inews-news
2109 gnus-summary-reply gnus-summary-reply-with-original
2110 gnus-summary-mail-forward gnus-summary-mail-other-window
2111 gnus-bug)
2112 ("gnus-picon" :interactive t gnus-article-display-picons
2113 gnus-group-display-picons gnus-picons-article-display-x-face
2114 gnus-picons-display-x-face)
2115 ("gnus-gl" bbb-login bbb-logout bbb-grouplens-group-p
2116 gnus-grouplens-mode)
2117 ("smiley" :interactive t gnus-smiley-display)
2118 ("gnus-vm" gnus-vm-mail-setup)
2119 ("gnus-vm" :interactive t gnus-summary-save-in-vm
2120 gnus-summary-save-article-vm))))
2121
2122 \f
2123
2124 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
2125 ;; If you want the cursor to go somewhere else, set these two
2126 ;; functions in some startup hook to whatever you want.
2127 (defalias 'gnus-summary-position-point 'gnus-goto-colon)
2128 (defalias 'gnus-group-position-point 'gnus-goto-colon)
2129
2130 ;;; Various macros and substs.
2131
2132 (defun gnus-header-from (header)
2133 (mail-header-from header))
2134
2135 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
2136 "Pop to BUFFER, evaluate FORMS, and then return to the original window."
2137 (let ((tempvar (make-symbol "GnusStartBufferWindow"))
2138 (w (make-symbol "w"))
2139 (buf (make-symbol "buf")))
2140 `(let* ((,tempvar (selected-window))
2141 (,buf ,buffer)
2142 (,w (get-buffer-window ,buf 'visible)))
2143 (unwind-protect
2144 (progn
2145 (if ,w
2146 (select-window ,w)
2147 (pop-to-buffer ,buf))
2148 ,@forms)
2149 (select-window ,tempvar)))))
2150
2151 (put 'gnus-eval-in-buffer-window 'lisp-indent-function 1)
2152 (put 'gnus-eval-in-buffer-window 'lisp-indent-hook 1)
2153 (put 'gnus-eval-in-buffer-window 'edebug-form-spec '(form body))
2154
2155 (defmacro gnus-gethash (string hashtable)
2156 "Get hash value of STRING in HASHTABLE."
2157 `(symbol-value (intern-soft ,string ,hashtable)))
2158
2159 (defmacro gnus-sethash (string value hashtable)
2160 "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
2161 `(set (intern ,string ,hashtable) ,value))
2162
2163 (defmacro gnus-intern-safe (string hashtable)
2164 "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
2165 `(let ((symbol (intern ,string ,hashtable)))
2166 (or (boundp symbol)
2167 (set symbol nil))
2168 symbol))
2169
2170 (defmacro gnus-group-unread (group)
2171 "Get the currently computed number of unread articles in GROUP."
2172 `(car (gnus-gethash ,group gnus-newsrc-hashtb)))
2173
2174 (defmacro gnus-group-entry (group)
2175 "Get the newsrc entry for GROUP."
2176 `(gnus-gethash ,group gnus-newsrc-hashtb))
2177
2178 (defmacro gnus-active (group)
2179 "Get active info on GROUP."
2180 `(gnus-gethash ,group gnus-active-hashtb))
2181
2182 (defmacro gnus-set-active (group active)
2183 "Set GROUP's active info."
2184 `(gnus-sethash ,group ,active gnus-active-hashtb))
2185
2186 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
2187 ;; function `substring' might cut on a middle of multi-octet
2188 ;; character.
2189 (defun gnus-truncate-string (str width)
2190 (substring str 0 width))
2191
2192 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
2193 ;; to limit the length of a string. This function is necessary since
2194 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
2195 (defsubst gnus-limit-string (str width)
2196 (if (> (length str) width)
2197 (substring str 0 width)
2198 str))
2199
2200 (defsubst gnus-simplify-subject-re (subject)
2201 "Remove \"Re:\" from subject lines."
2202 (if (string-match "^[Rr][Ee]: *" subject)
2203 (substring subject (match-end 0))
2204 subject))
2205
2206 (defsubst gnus-functionp (form)
2207 "Return non-nil if FORM is funcallable."
2208 (or (and (symbolp form) (fboundp form))
2209 (and (listp form) (eq (car form) 'lambda))))
2210
2211 (defsubst gnus-goto-char (point)
2212 (and point (goto-char point)))
2213
2214 (defmacro gnus-buffer-exists-p (buffer)
2215 `(let ((buffer ,buffer))
2216 (and buffer
2217 (funcall (if (stringp buffer) 'get-buffer 'buffer-name)
2218 buffer))))
2219
2220 (defmacro gnus-kill-buffer (buffer)
2221 `(let ((buf ,buffer))
2222 (if (gnus-buffer-exists-p buf)
2223 (kill-buffer buf))))
2224
2225 (defsubst gnus-point-at-bol ()
2226 "Return point at the beginning of the line."
2227 (let ((p (point)))
2228 (beginning-of-line)
2229 (prog1
2230 (point)
2231 (goto-char p))))
2232
2233 (defsubst gnus-point-at-eol ()
2234 "Return point at the end of the line."
2235 (let ((p (point)))
2236 (end-of-line)
2237 (prog1
2238 (point)
2239 (goto-char p))))
2240
2241 (defun gnus-alive-p ()
2242 "Say whether Gnus is running or not."
2243 (and gnus-group-buffer
2244 (get-buffer gnus-group-buffer)))
2245
2246 (defun gnus-delete-first (elt list)
2247 "Delete by side effect the first occurrence of ELT as a member of LIST."
2248 (if (equal (car list) elt)
2249 (cdr list)
2250 (let ((total list))
2251 (while (and (cdr list)
2252 (not (equal (cadr list) elt)))
2253 (setq list (cdr list)))
2254 (when (cdr list)
2255 (setcdr list (cddr list)))
2256 total)))
2257
2258 ;; Delete the current line (and the next N lines.);
2259 (defmacro gnus-delete-line (&optional n)
2260 `(delete-region (progn (beginning-of-line) (point))
2261 (progn (forward-line ,(or n 1)) (point))))
2262
2263 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
2264 (defvar gnus-init-inhibit nil)
2265 (defun gnus-read-init-file (&optional inhibit-next)
2266 (if gnus-init-inhibit
2267 (setq gnus-init-inhibit nil)
2268 (setq gnus-init-inhibit inhibit-next)
2269 (and gnus-init-file
2270 (or (and (file-exists-p gnus-init-file)
2271 ;; Don't try to load a directory.
2272 (not (file-directory-p gnus-init-file)))
2273 (file-exists-p (concat gnus-init-file ".el"))
2274 (file-exists-p (concat gnus-init-file ".elc")))
2275 (condition-case var
2276 (load gnus-init-file nil t)
2277 (error
2278 (error "Error in %s: %s" gnus-init-file var))))))
2279
2280 ;; Info access macros.
2281
2282 (defmacro gnus-info-group (info)
2283 `(nth 0 ,info))
2284 (defmacro gnus-info-rank (info)
2285 `(nth 1 ,info))
2286 (defmacro gnus-info-read (info)
2287 `(nth 2 ,info))
2288 (defmacro gnus-info-marks (info)
2289 `(nth 3 ,info))
2290 (defmacro gnus-info-method (info)
2291 `(nth 4 ,info))
2292 (defmacro gnus-info-params (info)
2293 `(nth 5 ,info))
2294
2295 (defmacro gnus-info-level (info)
2296 `(let ((rank (gnus-info-rank ,info)))
2297 (if (consp rank)
2298 (car rank)
2299 rank)))
2300 (defmacro gnus-info-score (info)
2301 `(let ((rank (gnus-info-rank ,info)))
2302 (or (and (consp rank) (cdr rank)) 0)))
2303
2304 (defmacro gnus-info-set-group (info group)
2305 `(setcar ,info ,group))
2306 (defmacro gnus-info-set-rank (info rank)
2307 `(setcar (nthcdr 1 ,info) ,rank))
2308 (defmacro gnus-info-set-read (info read)
2309 `(setcar (nthcdr 2 ,info) ,read))
2310 (defmacro gnus-info-set-marks (info marks)
2311 `(setcar (nthcdr 3 ,info) ,marks))
2312 (defmacro gnus-info-set-method (info method)
2313 `(setcar (nthcdr 4 ,info) ,method))
2314 (defmacro gnus-info-set-params (info params)
2315 `(setcar (nthcdr 5 ,info) ,params))
2316
2317 (defmacro gnus-info-set-level (info level)
2318 `(let ((rank (cdr ,info)))
2319 (if (consp (car rank))
2320 (setcar (car rank) ,level)
2321 (setcar rank ,level))))
2322 (defmacro gnus-info-set-score (info score)
2323 `(let ((rank (cdr ,info)))
2324 (if (consp (car rank))
2325 (setcdr (car rank) ,score)
2326 (setcar rank (cons (car rank) ,score)))))
2327
2328 (defmacro gnus-get-info (group)
2329 `(nth 2 (gnus-gethash ,group gnus-newsrc-hashtb)))
2330
2331 (defun gnus-byte-code (func)
2332 "Return a form that can be `eval'ed based on FUNC."
2333 (let ((fval (symbol-function func)))
2334 (if (byte-code-function-p fval)
2335 (let ((flist (append fval nil)))
2336 (setcar flist 'byte-code)
2337 flist)
2338 (cons 'progn (cddr fval)))))
2339
2340 ;; Find out whether the gnus-visual TYPE is wanted.
2341 (defun gnus-visual-p (&optional type class)
2342 (and gnus-visual ; Has to be non-nil, at least.
2343 (if (not type) ; We don't care about type.
2344 gnus-visual
2345 (if (listp gnus-visual) ; It's a list, so we check it.
2346 (or (memq type gnus-visual)
2347 (memq class gnus-visual))
2348 t))))
2349
2350 ;;; Load the compatability functions.
2351
2352 (require 'gnus-cus)
2353 (require 'gnus-ems)
2354
2355 \f
2356 ;;;
2357 ;;; Shutdown
2358 ;;;
2359
2360 (defvar gnus-shutdown-alist nil)
2361
2362 (defun gnus-add-shutdown (function &rest symbols)
2363 "Run FUNCTION whenever one of SYMBOLS is shut down."
2364 (push (cons function symbols) gnus-shutdown-alist))
2365
2366 (defun gnus-shutdown (symbol)
2367 "Shut down everything that waits for SYMBOL."
2368 (let ((alist gnus-shutdown-alist)
2369 entry)
2370 (while (setq entry (pop alist))
2371 (when (memq symbol (cdr entry))
2372 (funcall (car entry))))))
2373
2374 \f
2375
2376 ;; Format specs. The chunks below are the machine-generated forms
2377 ;; that are to be evaled as the result of the default format strings.
2378 ;; We write them in here to get them byte-compiled. That way the
2379 ;; default actions will be quite fast, while still retaining the full
2380 ;; flexibility of the user-defined format specs.
2381
2382 ;; First we have lots of dummy defvars to let the compiler know these
2383 ;; are really dynamic variables.
2384
2385 (defvar gnus-tmp-unread)
2386 (defvar gnus-tmp-replied)
2387 (defvar gnus-tmp-score-char)
2388 (defvar gnus-tmp-indentation)
2389 (defvar gnus-tmp-opening-bracket)
2390 (defvar gnus-tmp-lines)
2391 (defvar gnus-tmp-name)
2392 (defvar gnus-tmp-closing-bracket)
2393 (defvar gnus-tmp-subject-or-nil)
2394 (defvar gnus-tmp-subject)
2395 (defvar gnus-tmp-marked)
2396 (defvar gnus-tmp-marked-mark)
2397 (defvar gnus-tmp-subscribed)
2398 (defvar gnus-tmp-process-marked)
2399 (defvar gnus-tmp-number-of-unread)
2400 (defvar gnus-tmp-group-name)
2401 (defvar gnus-tmp-group)
2402 (defvar gnus-tmp-article-number)
2403 (defvar gnus-tmp-unread-and-unselected)
2404 (defvar gnus-tmp-news-method)
2405 (defvar gnus-tmp-news-server)
2406 (defvar gnus-tmp-article-number)
2407 (defvar gnus-mouse-face)
2408 (defvar gnus-mouse-face-prop)
2409
2410 (defun gnus-summary-line-format-spec ()
2411 (insert gnus-tmp-unread gnus-tmp-replied
2412 gnus-tmp-score-char gnus-tmp-indentation)
2413 (gnus-put-text-property
2414 (point)
2415 (progn
2416 (insert
2417 gnus-tmp-opening-bracket
2418 (format "%4d: %-20s"
2419 gnus-tmp-lines
2420 (if (> (length gnus-tmp-name) 20)
2421 (substring gnus-tmp-name 0 20)
2422 gnus-tmp-name))
2423 gnus-tmp-closing-bracket)
2424 (point))
2425 gnus-mouse-face-prop gnus-mouse-face)
2426 (insert " " gnus-tmp-subject-or-nil "\n"))
2427
2428 (defvar gnus-summary-line-format-spec
2429 (gnus-byte-code 'gnus-summary-line-format-spec))
2430
2431 (defun gnus-summary-dummy-line-format-spec ()
2432 (insert "* ")
2433 (gnus-put-text-property
2434 (point)
2435 (progn
2436 (insert ": :")
2437 (point))
2438 gnus-mouse-face-prop gnus-mouse-face)
2439 (insert " " gnus-tmp-subject "\n"))
2440
2441 (defvar gnus-summary-dummy-line-format-spec
2442 (gnus-byte-code 'gnus-summary-dummy-line-format-spec))
2443
2444 (defun gnus-group-line-format-spec ()
2445 (insert gnus-tmp-marked-mark gnus-tmp-subscribed
2446 gnus-tmp-process-marked
2447 gnus-group-indentation
2448 (format "%5s: " gnus-tmp-number-of-unread))
2449 (gnus-put-text-property
2450 (point)
2451 (progn
2452 (insert gnus-tmp-group "\n")
2453 (1- (point)))
2454 gnus-mouse-face-prop gnus-mouse-face))
2455 (defvar gnus-group-line-format-spec
2456 (gnus-byte-code 'gnus-group-line-format-spec))
2457
2458 (defvar gnus-format-specs
2459 `((version . ,emacs-version)
2460 (group ,gnus-group-line-format ,gnus-group-line-format-spec)
2461 (summary-dummy ,gnus-summary-dummy-line-format
2462 ,gnus-summary-dummy-line-format-spec)
2463 (summary ,gnus-summary-line-format ,gnus-summary-line-format-spec)))
2464
2465 (defvar gnus-article-mode-line-format-spec nil)
2466 (defvar gnus-summary-mode-line-format-spec nil)
2467 (defvar gnus-group-mode-line-format-spec nil)
2468
2469 ;;; Phew. All that gruft is over, fortunately.
2470
2471 \f
2472 ;;;
2473 ;;; Gnus Utility Functions
2474 ;;;
2475
2476 (defun gnus-extract-address-components (from)
2477 (let (name address)
2478 ;; First find the address - the thing with the @ in it. This may
2479 ;; not be accurate in mail addresses, but does the trick most of
2480 ;; the time in news messages.
2481 (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
2482 (setq address (substring from (match-beginning 0) (match-end 0))))
2483 ;; Then we check whether the "name <address>" format is used.
2484 (and address
2485 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
2486 ;; Linear white space is not required.
2487 (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
2488 (and (setq name (substring from 0 (match-beginning 0)))
2489 ;; Strip any quotes from the name.
2490 (string-match "\".*\"" name)
2491 (setq name (substring name 1 (1- (match-end 0))))))
2492 ;; If not, then "address (name)" is used.
2493 (or name
2494 (and (string-match "(.+)" from)
2495 (setq name (substring from (1+ (match-beginning 0))
2496 (1- (match-end 0)))))
2497 (and (string-match "()" from)
2498 (setq name address))
2499 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
2500 ;; XOVER might not support folded From headers.
2501 (and (string-match "(.*" from)
2502 (setq name (substring from (1+ (match-beginning 0))
2503 (match-end 0)))))
2504 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
2505 (list (or name from) (or address from))))
2506
2507 (defun gnus-fetch-field (field)
2508 "Return the value of the header FIELD of current article."
2509 (save-excursion
2510 (save-restriction
2511 (let ((case-fold-search t)
2512 (inhibit-point-motion-hooks t))
2513 (nnheader-narrow-to-headers)
2514 (message-fetch-field field)))))
2515
2516 (defun gnus-goto-colon ()
2517 (beginning-of-line)
2518 (search-forward ":" (gnus-point-at-eol) t))
2519
2520 ;;;###autoload
2521 (defun gnus-update-format (var)
2522 "Update the format specification near point."
2523 (interactive
2524 (list
2525 (save-excursion
2526 (eval-defun nil)
2527 ;; Find the end of the current word.
2528 (re-search-forward "[ \t\n]" nil t)
2529 ;; Search backward.
2530 (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t)
2531 (match-string 1)))))
2532 (let* ((type (intern (progn (string-match "gnus-\\([-a-z]+\\)-line" var)
2533 (match-string 1 var))))
2534 (entry (assq type gnus-format-specs))
2535 value spec)
2536 (when entry
2537 (setq gnus-format-specs (delq entry gnus-format-specs)))
2538 (set
2539 (intern (format "%s-spec" var))
2540 (gnus-parse-format (setq value (symbol-value (intern var)))
2541 (symbol-value (intern (format "%s-alist" var)))
2542 (not (string-match "mode" var))))
2543 (setq spec (symbol-value (intern (format "%s-spec" var))))
2544 (push (list type value spec) gnus-format-specs)
2545
2546 (pop-to-buffer "*Gnus Format*")
2547 (erase-buffer)
2548 (lisp-interaction-mode)
2549 (insert (pp-to-string spec))))
2550
2551 (defun gnus-update-format-specifications (&optional force)
2552 "Update all (necessary) format specifications."
2553 ;; Make the indentation array.
2554 (gnus-make-thread-indent-array)
2555
2556 ;; See whether all the stored info needs to be flushed.
2557 (when (or force
2558 (not (equal emacs-version
2559 (cdr (assq 'version gnus-format-specs)))))
2560 (setq gnus-format-specs nil))
2561
2562 ;; Go through all the formats and see whether they need updating.
2563 (let ((types '(summary summary-dummy group
2564 summary-mode group-mode article-mode))
2565 new-format entry type val)
2566 (while (setq type (pop types))
2567 ;; Jump to the proper buffer to find out the value of
2568 ;; the variable, if possible. (It may be buffer-local.)
2569 (save-excursion
2570 (let ((buffer (intern (format "gnus-%s-buffer" type)))
2571 val)
2572 (when (and (boundp buffer)
2573 (setq val (symbol-value buffer))
2574 (get-buffer val)
2575 (buffer-name (get-buffer val)))
2576 (set-buffer (get-buffer val)))
2577 (setq new-format (symbol-value
2578 (intern (format "gnus-%s-line-format" type))))))
2579 (setq entry (cdr (assq type gnus-format-specs)))
2580 (if (and entry
2581 (equal (car entry) new-format))
2582 ;; Use the old format.
2583 (set (intern (format "gnus-%s-line-format-spec" type))
2584 (cadr entry))
2585 ;; This is a new format.
2586 (setq val
2587 (if (not (stringp new-format))
2588 ;; This is a function call or something.
2589 new-format
2590 ;; This is a "real" format.
2591 (gnus-parse-format
2592 new-format
2593 (symbol-value
2594 (intern (format "gnus-%s-line-format-alist"
2595 (if (eq type 'article-mode)
2596 'summary-mode type))))
2597 (not (string-match "mode$" (symbol-name type))))))
2598 ;; Enter the new format spec into the list.
2599 (if entry
2600 (progn
2601 (setcar (cdr entry) val)
2602 (setcar entry new-format))
2603 (push (list type new-format val) gnus-format-specs))
2604 (set (intern (format "gnus-%s-line-format-spec" type)) val))))
2605
2606 (unless (assq 'version gnus-format-specs)
2607 (push (cons 'version emacs-version) gnus-format-specs))
2608
2609 (gnus-update-group-mark-positions)
2610 (gnus-update-summary-mark-positions))
2611
2612 (defun gnus-update-summary-mark-positions ()
2613 "Compute where the summary marks are to go."
2614 (save-excursion
2615 (when (and gnus-summary-buffer
2616 (get-buffer gnus-summary-buffer)
2617 (buffer-name (get-buffer gnus-summary-buffer)))
2618 (set-buffer gnus-summary-buffer))
2619 (let ((gnus-replied-mark 129)
2620 (gnus-score-below-mark 130)
2621 (gnus-score-over-mark 130)
2622 (thread nil)
2623 (gnus-visual nil)
2624 (spec gnus-summary-line-format-spec)
2625 pos)
2626 (save-excursion
2627 (gnus-set-work-buffer)
2628 (let ((gnus-summary-line-format-spec spec))
2629 (gnus-summary-insert-line
2630 [0 "" "" "" "" "" 0 0 ""] 0 nil 128 t nil "" nil 1)
2631 (goto-char (point-min))
2632 (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2633 (- (point) 2)))))
2634 (goto-char (point-min))
2635 (push (cons 'replied (and (search-forward "\201" nil t)
2636 (- (point) 2)))
2637 pos)
2638 (goto-char (point-min))
2639 (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2640 pos)))
2641 (setq gnus-summary-mark-positions pos))))
2642
2643 (defun gnus-update-group-mark-positions ()
2644 (save-excursion
2645 (let ((gnus-process-mark 128)
2646 (gnus-group-marked '("dummy.group"))
2647 (gnus-active-hashtb (make-vector 10 0)))
2648 (gnus-set-active "dummy.group" '(0 . 0))
2649 (gnus-set-work-buffer)
2650 (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
2651 (goto-char (point-min))
2652 (setq gnus-group-mark-positions
2653 (list (cons 'process (and (search-forward "\200" nil t)
2654 (- (point) 2))))))))
2655
2656 (defvar gnus-mouse-face-0 'highlight)
2657 (defvar gnus-mouse-face-1 'highlight)
2658 (defvar gnus-mouse-face-2 'highlight)
2659 (defvar gnus-mouse-face-3 'highlight)
2660 (defvar gnus-mouse-face-4 'highlight)
2661
2662 (defun gnus-mouse-face-function (form type)
2663 `(gnus-put-text-property
2664 (point) (progn ,@form (point))
2665 gnus-mouse-face-prop
2666 ,(if (equal type 0)
2667 'gnus-mouse-face
2668 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type)))))))
2669
2670 (defvar gnus-face-0 'bold)
2671 (defvar gnus-face-1 'italic)
2672 (defvar gnus-face-2 'bold-italic)
2673 (defvar gnus-face-3 'bold)
2674 (defvar gnus-face-4 'bold)
2675
2676 (defun gnus-face-face-function (form type)
2677 `(gnus-put-text-property
2678 (point) (progn ,@form (point))
2679 'face ',(symbol-value (intern (format "gnus-face-%d" type)))))
2680
2681 (defun gnus-max-width-function (el max-width)
2682 (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
2683 (if (symbolp el)
2684 `(if (> (length ,el) ,max-width)
2685 (substring ,el 0 ,max-width)
2686 ,el)
2687 `(let ((val (eval ,el)))
2688 (if (numberp val)
2689 (setq val (int-to-string val)))
2690 (if (> (length val) ,max-width)
2691 (substring val 0 ,max-width)
2692 val))))
2693
2694 (defun gnus-parse-format (format spec-alist &optional insert)
2695 ;; This function parses the FORMAT string with the help of the
2696 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
2697 ;; string. If the FORMAT string contains the specifiers %( and %)
2698 ;; the text between them will have the mouse-face text property.
2699 (if (string-match
2700 "\\`\\(.*\\)%[0-9]?[{(]\\(.*\\)%[0-9]?[})]\\(.*\n?\\)\\'"
2701 format)
2702 (gnus-parse-complex-format format spec-alist)
2703 ;; This is a simple format.
2704 (gnus-parse-simple-format format spec-alist insert)))
2705
2706 (defun gnus-parse-complex-format (format spec-alist)
2707 (save-excursion
2708 (gnus-set-work-buffer)
2709 (insert format)
2710 (goto-char (point-min))
2711 (while (re-search-forward "\"" nil t)
2712 (replace-match "\\\"" nil t))
2713 (goto-char (point-min))
2714 (insert "(\"")
2715 (while (re-search-forward "%\\([0-9]+\\)?\\([{}()]\\)" nil t)
2716 (let ((number (if (match-beginning 1)
2717 (match-string 1) "0"))
2718 (delim (aref (match-string 2) 0)))
2719 (if (or (= delim ?\() (= delim ?\{))
2720 (replace-match (concat "\"(" (if (= delim ?\() "mouse" "face")
2721 " " number " \""))
2722 (replace-match "\")\""))))
2723 (goto-char (point-max))
2724 (insert "\")")
2725 (goto-char (point-min))
2726 (let ((form (read (current-buffer))))
2727 (cons 'progn (gnus-complex-form-to-spec form spec-alist)))))
2728
2729 (defun gnus-complex-form-to-spec (form spec-alist)
2730 (delq nil
2731 (mapcar
2732 (lambda (sform)
2733 (if (stringp sform)
2734 (gnus-parse-simple-format sform spec-alist t)
2735 (funcall (intern (format "gnus-%s-face-function" (car sform)))
2736 (gnus-complex-form-to-spec (cddr sform) spec-alist)
2737 (nth 1 sform))))
2738 form)))
2739
2740 (defun gnus-parse-simple-format (format spec-alist &optional insert)
2741 ;; This function parses the FORMAT string with the help of the
2742 ;; SPEC-ALIST and returns a list that can be eval'ed to return a
2743 ;; string.
2744 (let ((max-width 0)
2745 spec flist fstring newspec elem beg result dontinsert)
2746 (save-excursion
2747 (gnus-set-work-buffer)
2748 (insert format)
2749 (goto-char (point-min))
2750 (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?"
2751 nil t)
2752 (if (= (setq spec (string-to-char (match-string 2))) ?%)
2753 (setq newspec "%"
2754 beg (1+ (match-beginning 0)))
2755 ;; First check if there are any specs that look anything like
2756 ;; "%12,12A", ie. with a "max width specification". These have
2757 ;; to be treated specially.
2758 (if (setq beg (match-beginning 1))
2759 (setq max-width
2760 (string-to-int
2761 (buffer-substring
2762 (1+ (match-beginning 1)) (match-end 1))))
2763 (setq max-width 0)
2764 (setq beg (match-beginning 2)))
2765 ;; Find the specification from `spec-alist'.
2766 (unless (setq elem (cdr (assq spec spec-alist)))
2767 (setq elem '("*" ?s)))
2768 ;; Treat user defined format specifiers specially.
2769 (when (eq (car elem) 'gnus-tmp-user-defined)
2770 (setq elem
2771 (list
2772 (list (intern (concat "gnus-user-format-function-"
2773 (match-string 3)))
2774 'gnus-tmp-header) ?s))
2775 (delete-region (match-beginning 3) (match-end 3)))
2776 (if (not (zerop max-width))
2777 (let ((el (car elem)))
2778 (cond ((= (cadr elem) ?c)
2779 (setq el (list 'char-to-string el)))
2780 ((= (cadr elem) ?d)
2781 (setq el (list 'int-to-string el))))
2782 (setq flist (cons (gnus-max-width-function el max-width)
2783 flist))
2784 (setq newspec ?s))
2785 (progn
2786 (setq flist (cons (car elem) flist))
2787 (setq newspec (cadr elem)))))
2788 ;; Remove the old specification (and possibly a ",12" string).
2789 (delete-region beg (match-end 2))
2790 ;; Insert the new specification.
2791 (goto-char beg)
2792 (insert newspec))
2793 (setq fstring (buffer-substring 1 (point-max))))
2794 ;; Do some postprocessing to increase efficiency.
2795 (setq
2796 result
2797 (cond
2798 ;; Emptyness.
2799 ((string= fstring "")
2800 nil)
2801 ;; Not a format string.
2802 ((not (string-match "%" fstring))
2803 (list fstring))
2804 ;; A format string with just a single string spec.
2805 ((string= fstring "%s")
2806 (list (car flist)))
2807 ;; A single character.
2808 ((string= fstring "%c")
2809 (list (car flist)))
2810 ;; A single number.
2811 ((string= fstring "%d")
2812 (setq dontinsert)
2813 (if insert
2814 (list `(princ ,(car flist)))
2815 (list `(int-to-string ,(car flist)))))
2816 ;; Just lots of chars and strings.
2817 ((string-match "\\`\\(%[cs]\\)+\\'" fstring)
2818 (nreverse flist))
2819 ;; A single string spec at the beginning of the spec.
2820 ((string-match "\\`%[sc][^%]+\\'" fstring)
2821 (list (car flist) (substring fstring 2)))
2822 ;; A single string spec in the middle of the spec.
2823 ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring)
2824 (list (match-string 1 fstring) (car flist) (match-string 2 fstring)))
2825 ;; A single string spec in the end of the spec.
2826 ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring)
2827 (list (match-string 1 fstring) (car flist)))
2828 ;; A more complex spec.
2829 (t
2830 (list (cons 'format (cons fstring (nreverse flist)))))))
2831
2832 (if insert
2833 (when result
2834 (if dontinsert
2835 result
2836 (cons 'insert result)))
2837 (cond ((stringp result)
2838 result)
2839 ((consp result)
2840 (cons 'concat result))
2841 (t "")))))
2842
2843 (defun gnus-eval-format (format &optional alist props)
2844 "Eval the format variable FORMAT, using ALIST.
2845 If PROPS, insert the result."
2846 (let ((form (gnus-parse-format format alist props)))
2847 (if props
2848 (gnus-add-text-properties (point) (progn (eval form) (point)) props)
2849 (eval form))))
2850
2851 (defun gnus-remove-text-with-property (prop)
2852 "Delete all text in the current buffer with text property PROP."
2853 (save-excursion
2854 (goto-char (point-min))
2855 (while (not (eobp))
2856 (while (get-text-property (point) prop)
2857 (delete-char 1))
2858 (goto-char (next-single-property-change (point) prop nil (point-max))))))
2859
2860 (defun gnus-set-work-buffer ()
2861 (if (get-buffer gnus-work-buffer)
2862 (progn
2863 (set-buffer gnus-work-buffer)
2864 (erase-buffer))
2865 (set-buffer (get-buffer-create gnus-work-buffer))
2866 (kill-all-local-variables)
2867 (buffer-disable-undo (current-buffer))
2868 (gnus-add-current-to-buffer-list)))
2869
2870 ;; Article file names when saving.
2871
2872 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2873 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2874 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
2875 Otherwise, it is like ~/News/news/group/num."
2876 (let ((default
2877 (expand-file-name
2878 (concat (if (gnus-use-long-file-name 'not-save)
2879 (gnus-capitalize-newsgroup newsgroup)
2880 (gnus-newsgroup-directory-form newsgroup))
2881 "/" (int-to-string (mail-header-number headers)))
2882 gnus-article-save-directory)))
2883 (if (and last-file
2884 (string-equal (file-name-directory default)
2885 (file-name-directory last-file))
2886 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2887 default
2888 (or last-file default))))
2889
2890 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2891 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2892 If variable `gnus-use-long-file-name' is non-nil, it is
2893 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2894 (let ((default
2895 (expand-file-name
2896 (concat (if (gnus-use-long-file-name 'not-save)
2897 newsgroup
2898 (gnus-newsgroup-directory-form newsgroup))
2899 "/" (int-to-string (mail-header-number headers)))
2900 gnus-article-save-directory)))
2901 (if (and last-file
2902 (string-equal (file-name-directory default)
2903 (file-name-directory last-file))
2904 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2905 default
2906 (or last-file default))))
2907
2908 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2909 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2910 If variable `gnus-use-long-file-name' is non-nil, it is
2911 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2912 (or last-file
2913 (expand-file-name
2914 (if (gnus-use-long-file-name 'not-save)
2915 (gnus-capitalize-newsgroup newsgroup)
2916 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2917 gnus-article-save-directory)))
2918
2919 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2920 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2921 If variable `gnus-use-long-file-name' is non-nil, it is
2922 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2923 (or last-file
2924 (expand-file-name
2925 (if (gnus-use-long-file-name 'not-save)
2926 newsgroup
2927 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2928 gnus-article-save-directory)))
2929
2930 ;; For subscribing new newsgroup
2931
2932 (defun gnus-subscribe-hierarchical-interactive (groups)
2933 (let ((groups (sort groups 'string<))
2934 prefixes prefix start ans group starts)
2935 (while groups
2936 (setq prefixes (list "^"))
2937 (while (and groups prefixes)
2938 (while (not (string-match (car prefixes) (car groups)))
2939 (setq prefixes (cdr prefixes)))
2940 (setq prefix (car prefixes))
2941 (setq start (1- (length prefix)))
2942 (if (and (string-match "[^\\.]\\." (car groups) start)
2943 (cdr groups)
2944 (setq prefix
2945 (concat "^" (substring (car groups) 0 (match-end 0))))
2946 (string-match prefix (cadr groups)))
2947 (progn
2948 (setq prefixes (cons prefix prefixes))
2949 (message "Descend hierarchy %s? ([y]nsq): "
2950 (substring prefix 1 (1- (length prefix))))
2951 (while (not (memq (setq ans (read-char)) '(?y ?\n ?n ?s ?q)))
2952 (ding)
2953 (message "Descend hierarchy %s? ([y]nsq): "
2954 (substring prefix 1 (1- (length prefix)))))
2955 (cond ((= ans ?n)
2956 (while (and groups
2957 (string-match prefix
2958 (setq group (car groups))))
2959 (setq gnus-killed-list
2960 (cons group gnus-killed-list))
2961 (gnus-sethash group group gnus-killed-hashtb)
2962 (setq groups (cdr groups)))
2963 (setq starts (cdr starts)))
2964 ((= ans ?s)
2965 (while (and groups
2966 (string-match prefix
2967 (setq group (car groups))))
2968 (gnus-sethash group group gnus-killed-hashtb)
2969 (gnus-subscribe-alphabetically (car groups))
2970 (setq groups (cdr groups)))
2971 (setq starts (cdr starts)))
2972 ((= ans ?q)
2973 (while groups
2974 (setq group (car groups))
2975 (setq gnus-killed-list (cons group gnus-killed-list))
2976 (gnus-sethash group group gnus-killed-hashtb)
2977 (setq groups (cdr groups))))
2978 (t nil)))
2979 (message "Subscribe %s? ([n]yq)" (car groups))
2980 (while (not (memq (setq ans (read-char)) '(?y ?\n ?q ?n)))
2981 (ding)
2982 (message "Subscribe %s? ([n]yq)" (car groups)))
2983 (setq group (car groups))
2984 (cond ((= ans ?y)
2985 (gnus-subscribe-alphabetically (car groups))
2986 (gnus-sethash group group gnus-killed-hashtb))
2987 ((= ans ?q)
2988 (while groups
2989 (setq group (car groups))
2990 (setq gnus-killed-list (cons group gnus-killed-list))
2991 (gnus-sethash group group gnus-killed-hashtb)
2992 (setq groups (cdr groups))))
2993 (t
2994 (setq gnus-killed-list (cons group gnus-killed-list))
2995 (gnus-sethash group group gnus-killed-hashtb)))
2996 (setq groups (cdr groups)))))))
2997
2998 (defun gnus-subscribe-randomly (newsgroup)
2999 "Subscribe new NEWSGROUP by making it the first newsgroup."
3000 (gnus-subscribe-newsgroup newsgroup))
3001
3002 (defun gnus-subscribe-alphabetically (newgroup)
3003 "Subscribe new NEWSGROUP and insert it in alphabetical order."
3004 (let ((groups (cdr gnus-newsrc-alist))
3005 before)
3006 (while (and (not before) groups)
3007 (if (string< newgroup (caar groups))
3008 (setq before (caar groups))
3009 (setq groups (cdr groups))))
3010 (gnus-subscribe-newsgroup newgroup before)))
3011
3012 (defun gnus-subscribe-hierarchically (newgroup)
3013 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
3014 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
3015 (save-excursion
3016 (set-buffer (find-file-noselect gnus-current-startup-file))
3017 (let ((groupkey newgroup)
3018 before)
3019 (while (and (not before) groupkey)
3020 (goto-char (point-min))
3021 (let ((groupkey-re
3022 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
3023 (while (and (re-search-forward groupkey-re nil t)
3024 (progn
3025 (setq before (match-string 1))
3026 (string< before newgroup)))))
3027 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
3028 (setq groupkey
3029 (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
3030 (substring groupkey (match-beginning 1) (match-end 1)))))
3031 (gnus-subscribe-newsgroup newgroup before))
3032 (kill-buffer (current-buffer))))
3033
3034 (defun gnus-subscribe-interactively (group)
3035 "Subscribe the new GROUP interactively.
3036 It is inserted in hierarchical newsgroup order if subscribed. If not,
3037 it is killed."
3038 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
3039 (gnus-subscribe-hierarchically group)
3040 (push group gnus-killed-list)))
3041
3042 (defun gnus-subscribe-zombies (group)
3043 "Make the new GROUP into a zombie group."
3044 (push group gnus-zombie-list))
3045
3046 (defun gnus-subscribe-killed (group)
3047 "Make the new GROUP a killed group."
3048 (push group gnus-killed-list))
3049
3050 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
3051 "Subscribe new NEWSGROUP.
3052 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
3053 the first newsgroup."
3054 ;; We subscribe the group by changing its level to `subscribed'.
3055 (gnus-group-change-level
3056 newsgroup gnus-level-default-subscribed
3057 gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
3058 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
3059
3060 ;; For directories
3061
3062 (defun gnus-newsgroup-directory-form (newsgroup)
3063 "Make hierarchical directory name from NEWSGROUP name."
3064 (let ((newsgroup (gnus-newsgroup-savable-name newsgroup))
3065 (len (length newsgroup))
3066 idx)
3067 ;; If this is a foreign group, we don't want to translate the
3068 ;; entire name.
3069 (if (setq idx (string-match ":" newsgroup))
3070 (aset newsgroup idx ?/)
3071 (setq idx 0))
3072 ;; Replace all occurrences of `.' with `/'.
3073 (while (< idx len)
3074 (if (= (aref newsgroup idx) ?.)
3075 (aset newsgroup idx ?/))
3076 (setq idx (1+ idx)))
3077 newsgroup))
3078
3079 (defun gnus-newsgroup-savable-name (group)
3080 ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
3081 ;; with dots.
3082 (nnheader-replace-chars-in-string group ?/ ?.))
3083
3084 (defun gnus-make-directory (dir)
3085 "Make DIRECTORY recursively."
3086 ;; Why don't we use `(make-directory dir 'parents)'? That's just one
3087 ;; of the many mysteries of the universe.
3088 (let* ((dir (expand-file-name dir default-directory))
3089 dirs err)
3090 (if (string-match "/$" dir)
3091 (setq dir (substring dir 0 (match-beginning 0))))
3092 ;; First go down the path until we find a directory that exists.
3093 (while (not (file-exists-p dir))
3094 (setq dirs (cons dir dirs))
3095 (string-match "/[^/]+$" dir)
3096 (setq dir (substring dir 0 (match-beginning 0))))
3097 ;; Then create all the subdirs.
3098 (while (and dirs (not err))
3099 (condition-case ()
3100 (make-directory (car dirs))
3101 (error (setq err t)))
3102 (setq dirs (cdr dirs)))
3103 ;; We return whether we were successful or not.
3104 (not dirs)))
3105
3106 (defun gnus-capitalize-newsgroup (newsgroup)
3107 "Capitalize NEWSGROUP name."
3108 (and (not (zerop (length newsgroup)))
3109 (concat (char-to-string (upcase (aref newsgroup 0)))
3110 (substring newsgroup 1))))
3111
3112 ;; Various... things.
3113
3114 (defun gnus-simplify-subject (subject &optional re-only)
3115 "Remove `Re:' and words in parentheses.
3116 If RE-ONLY is non-nil, strip leading `Re:'s only."
3117 (let ((case-fold-search t)) ;Ignore case.
3118 ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
3119 (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
3120 (setq subject (substring subject (match-end 0))))
3121 ;; Remove uninteresting prefixes.
3122 (if (and (not re-only)
3123 gnus-simplify-ignored-prefixes
3124 (string-match gnus-simplify-ignored-prefixes subject))
3125 (setq subject (substring subject (match-end 0))))
3126 ;; Remove words in parentheses from end.
3127 (unless re-only
3128 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
3129 (setq subject (substring subject 0 (match-beginning 0)))))
3130 ;; Return subject string.
3131 subject))
3132
3133 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
3134 ;; all whitespace.
3135 ;; Written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
3136 (defun gnus-simplify-buffer-fuzzy ()
3137 (let ((case-fold-search t))
3138 (goto-char (point-min))
3139 (while (search-forward "\t" nil t)
3140 (replace-match " " t t))
3141 (goto-char (point-min))
3142 (re-search-forward "^ *\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;] *" nil t)
3143 (goto-char (match-beginning 0))
3144 (while (or
3145 (looking-at "^ *\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
3146 (looking-at "^[[].*: .*[]]$"))
3147 (goto-char (point-min))
3148 (while (re-search-forward "^ *\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;] *"
3149 nil t)
3150 (replace-match "" t t))
3151 (goto-char (point-min))
3152 (while (re-search-forward "^[[].*: .*[]]$" nil t)
3153 (goto-char (match-end 0))
3154 (delete-char -1)
3155 (delete-region
3156 (progn (goto-char (match-beginning 0)))
3157 (re-search-forward ":"))))
3158 (goto-char (point-min))
3159 (while (re-search-forward " *[[{(][^()\n]*[]})] *$" nil t)
3160 (replace-match "" t t))
3161 (goto-char (point-min))
3162 (while (re-search-forward " +" nil t)
3163 (replace-match " " t t))
3164 (goto-char (point-min))
3165 (while (re-search-forward " $" nil t)
3166 (replace-match "" t t))
3167 (goto-char (point-min))
3168 (while (re-search-forward "^ +" nil t)
3169 (replace-match "" t t))
3170 (goto-char (point-min))
3171 (when gnus-simplify-subject-fuzzy-regexp
3172 (if (listp gnus-simplify-subject-fuzzy-regexp)
3173 (let ((list gnus-simplify-subject-fuzzy-regexp))
3174 (while list
3175 (goto-char (point-min))
3176 (while (re-search-forward (car list) nil t)
3177 (replace-match "" t t))
3178 (setq list (cdr list))))
3179 (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
3180 (replace-match "" t t))))))
3181
3182 (defun gnus-simplify-subject-fuzzy (subject)
3183 "Siplify a subject string fuzzily."
3184 (save-excursion
3185 (gnus-set-work-buffer)
3186 (let ((case-fold-search t))
3187 (insert subject)
3188 (inline (gnus-simplify-buffer-fuzzy))
3189 (buffer-string))))
3190
3191 ;; Add the current buffer to the list of buffers to be killed on exit.
3192 (defun gnus-add-current-to-buffer-list ()
3193 (or (memq (current-buffer) gnus-buffer-list)
3194 (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
3195
3196 (defun gnus-string> (s1 s2)
3197 (not (or (string< s1 s2)
3198 (string= s1 s2))))
3199
3200 (defun gnus-read-active-file-p ()
3201 "Say whether the active file has been read from `gnus-select-method'."
3202 (memq gnus-select-method gnus-have-read-active-file))
3203
3204 ;;; General various misc type functions.
3205
3206 (defun gnus-clear-system ()
3207 "Clear all variables and buffers."
3208 ;; Clear Gnus variables.
3209 (let ((variables gnus-variable-list))
3210 (while variables
3211 (set (car variables) nil)
3212 (setq variables (cdr variables))))
3213 ;; Clear other internal variables.
3214 (setq gnus-list-of-killed-groups nil
3215 gnus-have-read-active-file nil
3216 gnus-newsrc-alist nil
3217 gnus-newsrc-hashtb nil
3218 gnus-killed-list nil
3219 gnus-zombie-list nil
3220 gnus-killed-hashtb nil
3221 gnus-active-hashtb nil
3222 gnus-moderated-list nil
3223 gnus-description-hashtb nil
3224 gnus-current-headers nil
3225 gnus-thread-indent-array nil
3226 gnus-newsgroup-headers nil
3227 gnus-newsgroup-name nil
3228 gnus-server-alist nil
3229 gnus-group-list-mode nil
3230 gnus-opened-servers nil
3231 gnus-group-mark-positions nil
3232 gnus-newsgroup-data nil
3233 gnus-newsgroup-unreads nil
3234 nnoo-state-alist nil
3235 gnus-current-select-method nil)
3236 (gnus-shutdown 'gnus)
3237 ;; Kill the startup file.
3238 (and gnus-current-startup-file
3239 (get-file-buffer gnus-current-startup-file)
3240 (kill-buffer (get-file-buffer gnus-current-startup-file)))
3241 ;; Clear the dribble buffer.
3242 (gnus-dribble-clear)
3243 ;; Kill global KILL file buffer.
3244 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
3245 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
3246 (gnus-kill-buffer nntp-server-buffer)
3247 ;; Kill Gnus buffers.
3248 (while gnus-buffer-list
3249 (gnus-kill-buffer (pop gnus-buffer-list)))
3250 ;; Remove Gnus frames.
3251 (gnus-kill-gnus-frames))
3252
3253 (defun gnus-kill-gnus-frames ()
3254 "Kill all frames Gnus has created."
3255 (while gnus-created-frames
3256 (when (frame-live-p (car gnus-created-frames))
3257 ;; We slap a condition-case around this `delete-frame' to ensure
3258 ;; against errors if we try do delete the single frame that's left.
3259 (condition-case ()
3260 (delete-frame (car gnus-created-frames))
3261 (error nil)))
3262 (pop gnus-created-frames)))
3263
3264 (defun gnus-windows-old-to-new (setting)
3265 ;; First we take care of the really, really old Gnus 3 actions.
3266 (when (symbolp setting)
3267 (setq setting
3268 ;; Take care of ooold GNUS 3.x values.
3269 (cond ((eq setting 'SelectArticle) 'article)
3270 ((memq setting '(SelectSubject ExpandSubject)) 'summary)
3271 ((memq setting '(SelectNewsgroup ExitNewsgroup)) 'group)
3272 (t setting))))
3273 (if (or (listp setting)
3274 (not (and gnus-window-configuration
3275 (memq setting '(group summary article)))))
3276 setting
3277 (let* ((setting (if (eq setting 'group)
3278 (if (assq 'newsgroup gnus-window-configuration)
3279 'newsgroup
3280 'newsgroups) setting))
3281 (elem (cadr (assq setting gnus-window-configuration)))
3282 (total (apply '+ elem))
3283 (types '(group summary article))
3284 (pbuf (if (eq setting 'newsgroups) 'group 'summary))
3285 (i 0)
3286 perc
3287 out)
3288 (while (< i 3)
3289 (or (not (numberp (nth i elem)))
3290 (zerop (nth i elem))
3291 (progn
3292 (setq perc (if (= i 2)
3293 1.0
3294 (/ (float (nth 0 elem)) total)))
3295 (setq out (cons (if (eq pbuf (nth i types))
3296 (list (nth i types) perc 'point)
3297 (list (nth i types) perc))
3298 out))))
3299 (setq i (1+ i)))
3300 `(vertical 1.0 ,@(nreverse out)))))
3301
3302 ;;;###autoload
3303 (defun gnus-add-configuration (conf)
3304 "Add the window configuration CONF to `gnus-buffer-configuration'."
3305 (setq gnus-buffer-configuration
3306 (cons conf (delq (assq (car conf) gnus-buffer-configuration)
3307 gnus-buffer-configuration))))
3308
3309 (defvar gnus-frame-list nil)
3310
3311 (defun gnus-configure-frame (split &optional window)
3312 "Split WINDOW according to SPLIT."
3313 (unless window
3314 (setq window (get-buffer-window (current-buffer))))
3315 (select-window window)
3316 ;; This might be an old-stylee buffer config.
3317 (when (vectorp split)
3318 (setq split (append split nil)))
3319 (when (or (consp (car split))
3320 (vectorp (car split)))
3321 (push 1.0 split)
3322 (push 'vertical split))
3323 ;; The SPLIT might be something that is to be evaled to
3324 ;; return a new SPLIT.
3325 (while (and (not (assq (car split) gnus-window-to-buffer))
3326 (gnus-functionp (car split)))
3327 (setq split (eval split)))
3328 (let* ((type (car split))
3329 (subs (cddr split))
3330 (len (if (eq type 'horizontal) (window-width) (window-height)))
3331 (total 0)
3332 (window-min-width (or gnus-window-min-width window-min-width))
3333 (window-min-height (or gnus-window-min-height window-min-height))
3334 s result new-win rest comp-subs size sub)
3335 (cond
3336 ;; Nothing to do here.
3337 ((null split))
3338 ;; Don't switch buffers.
3339 ((null type)
3340 (and (memq 'point split) window))
3341 ;; This is a buffer to be selected.
3342 ((not (memq type '(frame horizontal vertical)))
3343 (let ((buffer (cond ((stringp type) type)
3344 (t (cdr (assq type gnus-window-to-buffer)))))
3345 buf)
3346 (unless buffer
3347 (error "Illegal buffer type: %s" type))
3348 (unless (setq buf (get-buffer (if (symbolp buffer)
3349 (symbol-value buffer) buffer)))
3350 (setq buf (get-buffer-create (if (symbolp buffer)
3351 (symbol-value buffer) buffer))))
3352 (switch-to-buffer buf)
3353 ;; We return the window if it has the `point' spec.
3354 (and (memq 'point split) window)))
3355 ;; This is a frame split.
3356 ((eq type 'frame)
3357 (unless gnus-frame-list
3358 (setq gnus-frame-list (list (window-frame
3359 (get-buffer-window (current-buffer))))))
3360 (let ((i 0)
3361 params frame fresult)
3362 (while (< i (length subs))
3363 ;; Frame parameter is gotten from the sub-split.
3364 (setq params (cadr (elt subs i)))
3365 ;; It should be a list.
3366 (unless (listp params)
3367 (setq params nil))
3368 ;; Create a new frame?
3369 (unless (setq frame (elt gnus-frame-list i))
3370 (nconc gnus-frame-list (list (setq frame (make-frame params))))
3371 (push frame gnus-created-frames))
3372 ;; Is the old frame still alive?
3373 (unless (frame-live-p frame)
3374 (setcar (nthcdr i gnus-frame-list)
3375 (setq frame (make-frame params))))
3376 ;; Select the frame in question and do more splits there.
3377 (select-frame frame)
3378 (setq fresult (or (gnus-configure-frame (elt subs i)) fresult))
3379 (incf i))
3380 ;; Select the frame that has the selected buffer.
3381 (when fresult
3382 (select-frame (window-frame fresult)))))
3383 ;; This is a normal split.
3384 (t
3385 (when (> (length subs) 0)
3386 ;; First we have to compute the sizes of all new windows.
3387 (while subs
3388 (setq sub (append (pop subs) nil))
3389 (while (and (not (assq (car sub) gnus-window-to-buffer))
3390 (gnus-functionp (car sub)))
3391 (setq sub (eval sub)))
3392 (when sub
3393 (push sub comp-subs)
3394 (setq size (cadar comp-subs))
3395 (cond ((equal size 1.0)
3396 (setq rest (car comp-subs))
3397 (setq s 0))
3398 ((floatp size)
3399 (setq s (floor (* size len))))
3400 ((integerp size)
3401 (setq s size))
3402 (t
3403 (error "Illegal size: %s" size)))
3404 ;; Try to make sure that we are inside the safe limits.
3405 (cond ((zerop s))
3406 ((eq type 'horizontal)
3407 (setq s (max s window-min-width)))
3408 ((eq type 'vertical)
3409 (setq s (max s window-min-height))))
3410 (setcar (cdar comp-subs) s)
3411 (incf total s)))
3412 ;; Take care of the "1.0" spec.
3413 (if rest
3414 (setcar (cdr rest) (- len total))
3415 (error "No 1.0 specs in %s" split))
3416 ;; The we do the actual splitting in a nice recursive
3417 ;; fashion.
3418 (setq comp-subs (nreverse comp-subs))
3419 (while comp-subs
3420 (if (null (cdr comp-subs))
3421 (setq new-win window)
3422 (setq new-win
3423 (split-window window (cadar comp-subs)
3424 (eq type 'horizontal))))
3425 (setq result (or (gnus-configure-frame
3426 (car comp-subs) window) result))
3427 (select-window new-win)
3428 (setq window new-win)
3429 (setq comp-subs (cdr comp-subs))))
3430 ;; Return the proper window, if any.
3431 (when result
3432 (select-window result))))))
3433
3434 (defvar gnus-frame-split-p nil)
3435
3436 (defun gnus-configure-windows (setting &optional force)
3437 (setq setting (gnus-windows-old-to-new setting))
3438 (let ((split (if (symbolp setting)
3439 (cadr (assq setting gnus-buffer-configuration))
3440 setting))
3441 all-visible)
3442
3443 (setq gnus-frame-split-p nil)
3444
3445 (unless split
3446 (error "No such setting: %s" setting))
3447
3448 (if (and (setq all-visible (gnus-all-windows-visible-p split))
3449 (not force))
3450 ;; All the windows mentioned are already visible, so we just
3451 ;; put point in the assigned buffer, and do not touch the
3452 ;; winconf.
3453 (select-window all-visible)
3454
3455 ;; Either remove all windows or just remove all Gnus windows.
3456 (let ((frame (selected-frame)))
3457 (unwind-protect
3458 (if gnus-use-full-window
3459 ;; We want to remove all other windows.
3460 (if (not gnus-frame-split-p)
3461 ;; This is not a `frame' split, so we ignore the
3462 ;; other frames.
3463 (delete-other-windows)
3464 ;; This is a `frame' split, so we delete all windows
3465 ;; on all frames.
3466 (mapcar
3467 (lambda (frame)
3468 (unless (eq (cdr (assq 'minibuffer
3469 (frame-parameters frame)))
3470 'only)
3471 (select-frame frame)
3472 (delete-other-windows)))
3473 (frame-list)))
3474 ;; Just remove some windows.
3475 (gnus-remove-some-windows)
3476 (switch-to-buffer nntp-server-buffer))
3477 (select-frame frame)))
3478
3479 (switch-to-buffer nntp-server-buffer)
3480 (gnus-configure-frame split (get-buffer-window (current-buffer))))))
3481
3482 (defun gnus-all-windows-visible-p (split)
3483 "Say whether all buffers in SPLIT are currently visible.
3484 In particular, the value returned will be the window that
3485 should have point."
3486 (let ((stack (list split))
3487 (all-visible t)
3488 type buffer win buf)
3489 (while (and (setq split (pop stack))
3490 all-visible)
3491 ;; Be backwards compatible.
3492 (when (vectorp split)
3493 (setq split (append split nil)))
3494 (when (or (consp (car split))
3495 (vectorp (car split)))
3496 (push 1.0 split)
3497 (push 'vertical split))
3498 ;; The SPLIT might be something that is to be evaled to
3499 ;; return a new SPLIT.
3500 (while (and (not (assq (car split) gnus-window-to-buffer))
3501 (gnus-functionp (car split)))
3502 (setq split (eval split)))
3503
3504 (setq type (elt split 0))
3505 (cond
3506 ;; Nothing here.
3507 ((null split) t)
3508 ;; A buffer.
3509 ((not (memq type '(horizontal vertical frame)))
3510 (setq buffer (cond ((stringp type) type)
3511 (t (cdr (assq type gnus-window-to-buffer)))))
3512 (unless buffer
3513 (error "Illegal buffer type: %s" type))
3514 (when (setq buf (get-buffer (if (symbolp buffer)
3515 (symbol-value buffer)
3516 buffer)))
3517 (setq win (get-buffer-window buf t)))
3518 (if win
3519 (when (memq 'point split)
3520 (setq all-visible win))
3521 (setq all-visible nil)))
3522 (t
3523 (when (eq type 'frame)
3524 (setq gnus-frame-split-p t))
3525 (setq stack (append (cddr split) stack)))))
3526 (unless (eq all-visible t)
3527 all-visible)))
3528
3529 (defun gnus-window-top-edge (&optional window)
3530 (nth 1 (window-edges window)))
3531
3532 (defun gnus-remove-some-windows ()
3533 (let ((buffers gnus-window-to-buffer)
3534 buf bufs lowest-buf lowest)
3535 (save-excursion
3536 ;; Remove windows on all known Gnus buffers.
3537 (while buffers
3538 (setq buf (cdar buffers))
3539 (if (symbolp buf)
3540 (setq buf (and (boundp buf) (symbol-value buf))))
3541 (and buf
3542 (get-buffer-window buf)
3543 (progn
3544 (setq bufs (cons buf bufs))
3545 (pop-to-buffer buf)
3546 (if (or (not lowest)
3547 (< (gnus-window-top-edge) lowest))
3548 (progn
3549 (setq lowest (gnus-window-top-edge))
3550 (setq lowest-buf buf)))))
3551 (setq buffers (cdr buffers)))
3552 ;; Remove windows on *all* summary buffers.
3553 (walk-windows
3554 (lambda (win)
3555 (let ((buf (window-buffer win)))
3556 (if (string-match "^\\*Summary" (buffer-name buf))
3557 (progn
3558 (setq bufs (cons buf bufs))
3559 (pop-to-buffer buf)
3560 (if (or (not lowest)
3561 (< (gnus-window-top-edge) lowest))
3562 (progn
3563 (setq lowest-buf buf)
3564 (setq lowest (gnus-window-top-edge)))))))))
3565 (and lowest-buf
3566 (progn
3567 (pop-to-buffer lowest-buf)
3568 (switch-to-buffer nntp-server-buffer)))
3569 (while bufs
3570 (and (not (eq (car bufs) lowest-buf))
3571 (delete-windows-on (car bufs)))
3572 (setq bufs (cdr bufs))))))
3573
3574 (defun gnus-version (&optional arg)
3575 "Version number of this version of Gnus.
3576 If ARG, insert string at point."
3577 (interactive "P")
3578 (let ((methods gnus-valid-select-methods)
3579 (mess gnus-version)
3580 meth)
3581 ;; Go through all the legal select methods and add their version
3582 ;; numbers to the total version string. Only the backends that are
3583 ;; currently in use will have their message numbers taken into
3584 ;; consideration.
3585 (while methods
3586 (setq meth (intern (concat (caar methods) "-version")))
3587 (and (boundp meth)
3588 (stringp (symbol-value meth))
3589 (setq mess (concat mess "; " (symbol-value meth))))
3590 (setq methods (cdr methods)))
3591 (if arg
3592 (insert (message mess))
3593 (message mess))))
3594
3595 (defun gnus-info-find-node ()
3596 "Find Info documentation of Gnus."
3597 (interactive)
3598 ;; Enlarge info window if needed.
3599 (let ((mode major-mode)
3600 gnus-info-buffer)
3601 (Info-goto-node (cadr (assq mode gnus-info-nodes)))
3602 (setq gnus-info-buffer (current-buffer))
3603 (gnus-configure-windows 'info)))
3604
3605 (defun gnus-days-between (date1 date2)
3606 ;; Return the number of days between date1 and date2.
3607 (- (gnus-day-number date1) (gnus-day-number date2)))
3608
3609 (defun gnus-day-number (date)
3610 (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
3611 (timezone-parse-date date))))
3612 (timezone-absolute-from-gregorian
3613 (nth 1 dat) (nth 2 dat) (car dat))))
3614
3615 (defun gnus-encode-date (date)
3616 "Convert DATE to internal time."
3617 (let* ((parse (timezone-parse-date date))
3618 (date (mapcar (lambda (d) (and d (string-to-int d))) parse))
3619 (time (mapcar 'string-to-int (timezone-parse-time (aref parse 3)))))
3620 (encode-time (caddr time) (cadr time) (car time)
3621 (caddr date) (cadr date) (car date) (nth 4 date))))
3622
3623 (defun gnus-time-minus (t1 t2)
3624 "Subtract two internal times."
3625 (let ((borrow (< (cadr t1) (cadr t2))))
3626 (list (- (car t1) (car t2) (if borrow 1 0))
3627 (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))
3628
3629 (defun gnus-file-newer-than (file date)
3630 (let ((fdate (nth 5 (file-attributes file))))
3631 (or (> (car fdate) (car date))
3632 (and (= (car fdate) (car date))
3633 (> (nth 1 fdate) (nth 1 date))))))
3634
3635 (defmacro gnus-local-set-keys (&rest plist)
3636 "Set the keys in PLIST in the current keymap."
3637 `(gnus-define-keys-1 (current-local-map) ',plist))
3638
3639 (defmacro gnus-define-keys (keymap &rest plist)
3640 "Define all keys in PLIST in KEYMAP."
3641 `(gnus-define-keys-1 (quote ,keymap) (quote ,plist)))
3642
3643 (put 'gnus-define-keys 'lisp-indent-function 1)
3644 (put 'gnus-define-keys 'lisp-indent-hook 1)
3645 (put 'gnus-define-keymap 'lisp-indent-function 1)
3646 (put 'gnus-define-keymap 'lisp-indent-hook 1)
3647
3648 (defmacro gnus-define-keymap (keymap &rest plist)
3649 "Define all keys in PLIST in KEYMAP."
3650 `(gnus-define-keys-1 ,keymap (quote ,plist)))
3651
3652 (defun gnus-define-keys-1 (keymap plist)
3653 (when (null keymap)
3654 (error "Can't set keys in a null keymap"))
3655 (cond ((symbolp keymap)
3656 (setq keymap (symbol-value keymap)))
3657 ((keymapp keymap))
3658 ((listp keymap)
3659 (set (car keymap) nil)
3660 (define-prefix-command (car keymap))
3661 (define-key (symbol-value (caddr keymap)) (cadr keymap) (car keymap))
3662 (setq keymap (symbol-value (car keymap)))))
3663 (let (key)
3664 (while plist
3665 (when (symbolp (setq key (pop plist)))
3666 (setq key (symbol-value key)))
3667 (define-key keymap key (pop plist)))))
3668
3669 (defun gnus-group-read-only-p (&optional group)
3670 "Check whether GROUP supports editing or not.
3671 If GROUP is nil, `gnus-newsgroup-name' will be checked instead. Note
3672 that that variable is buffer-local to the summary buffers."
3673 (let ((group (or group gnus-newsgroup-name)))
3674 (not (gnus-check-backend-function 'request-replace-article group))))
3675
3676 (defun gnus-group-total-expirable-p (group)
3677 "Check whether GROUP is total-expirable or not."
3678 (let ((params (gnus-info-params (gnus-get-info group))))
3679 (or (memq 'total-expire params)
3680 (cdr (assq 'total-expire params)) ; (total-expire . t)
3681 (and gnus-total-expirable-newsgroups ; Check var.
3682 (string-match gnus-total-expirable-newsgroups group)))))
3683
3684 (defun gnus-group-auto-expirable-p (group)
3685 "Check whether GROUP is total-expirable or not."
3686 (let ((params (gnus-info-params (gnus-get-info group))))
3687 (or (memq 'auto-expire params)
3688 (cdr (assq 'auto-expire params)) ; (auto-expire . t)
3689 (and gnus-auto-expirable-newsgroups ; Check var.
3690 (string-match gnus-auto-expirable-newsgroups group)))))
3691
3692 (defun gnus-virtual-group-p (group)
3693 "Say whether GROUP is virtual or not."
3694 (memq 'virtual (assoc (symbol-name (car (gnus-find-method-for-group group)))
3695 gnus-valid-select-methods)))
3696
3697 (defun gnus-news-group-p (group &optional article)
3698 "Return non-nil if GROUP (and ARTICLE) come from a news server."
3699 (or (gnus-member-of-valid 'post group) ; Ordinary news group.
3700 (and (gnus-member-of-valid 'post-mail group) ; Combined group.
3701 (eq (gnus-request-type group article) 'news))))
3702
3703 (defsubst gnus-simplify-subject-fully (subject)
3704 "Simplify a subject string according to the user's wishes."
3705 (cond
3706 ((null gnus-summary-gather-subject-limit)
3707 (gnus-simplify-subject-re subject))
3708 ((eq gnus-summary-gather-subject-limit 'fuzzy)
3709 (gnus-simplify-subject-fuzzy subject))
3710 ((numberp gnus-summary-gather-subject-limit)
3711 (gnus-limit-string (gnus-simplify-subject-re subject)
3712 gnus-summary-gather-subject-limit))
3713 (t
3714 subject)))
3715
3716 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
3717 "Check whether two subjects are equal. If optional argument
3718 simple-first is t, first argument is already simplified."
3719 (cond
3720 ((null simple-first)
3721 (equal (gnus-simplify-subject-fully s1)
3722 (gnus-simplify-subject-fully s2)))
3723 (t
3724 (equal s1
3725 (gnus-simplify-subject-fully s2)))))
3726
3727 ;; Returns a list of writable groups.
3728 (defun gnus-writable-groups ()
3729 (let ((alist gnus-newsrc-alist)
3730 groups group)
3731 (while (setq group (car (pop alist)))
3732 (unless (gnus-group-read-only-p group)
3733 (push group groups)))
3734 (nreverse groups)))
3735
3736 (defun gnus-completing-read (default prompt &rest args)
3737 ;; Like `completing-read', except that DEFAULT is the default argument.
3738 (let* ((prompt (if default
3739 (concat prompt " (default " default ") ")
3740 (concat prompt " ")))
3741 (answer (apply 'completing-read prompt args)))
3742 (if (or (null answer) (zerop (length answer)))
3743 default
3744 answer)))
3745
3746 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
3747 ;; the echo area.
3748 (defun gnus-y-or-n-p (prompt)
3749 (prog1
3750 (y-or-n-p prompt)
3751 (message "")))
3752
3753 (defun gnus-yes-or-no-p (prompt)
3754 (prog1
3755 (yes-or-no-p prompt)
3756 (message "")))
3757
3758 ;; Check whether to use long file names.
3759 (defun gnus-use-long-file-name (symbol)
3760 ;; The variable has to be set...
3761 (and gnus-use-long-file-name
3762 ;; If it isn't a list, then we return t.
3763 (or (not (listp gnus-use-long-file-name))
3764 ;; If it is a list, and the list contains `symbol', we
3765 ;; return nil.
3766 (not (memq symbol gnus-use-long-file-name)))))
3767
3768 ;; I suspect there's a better way, but I haven't taken the time to do
3769 ;; it yet. -erik selberg@cs.washington.edu
3770 (defun gnus-dd-mmm (messy-date)
3771 "Return a string like DD-MMM from a big messy string"
3772 (let ((datevec (condition-case () (timezone-parse-date messy-date)
3773 (error nil))))
3774 (if (not datevec)
3775 "??-???"
3776 (format "%2s-%s"
3777 (condition-case ()
3778 ;; Make sure leading zeroes are stripped.
3779 (number-to-string (string-to-number (aref datevec 2)))
3780 (error "??"))
3781 (capitalize
3782 (or (car
3783 (nth (1- (string-to-number (aref datevec 1)))
3784 timezone-months-assoc))
3785 "???"))))))
3786
3787 (defun gnus-mode-string-quote (string)
3788 "Quote all \"%\" in STRING."
3789 (save-excursion
3790 (gnus-set-work-buffer)
3791 (insert string)
3792 (goto-char (point-min))
3793 (while (search-forward "%" nil t)
3794 (insert "%"))
3795 (buffer-string)))
3796
3797 ;; Make a hash table (default and minimum size is 255).
3798 ;; Optional argument HASHSIZE specifies the table size.
3799 (defun gnus-make-hashtable (&optional hashsize)
3800 (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
3801
3802 ;; Make a number that is suitable for hashing; bigger than MIN and one
3803 ;; less than 2^x.
3804 (defun gnus-create-hash-size (min)
3805 (let ((i 1))
3806 (while (< i min)
3807 (setq i (* 2 i)))
3808 (1- i)))
3809
3810 ;; Show message if message has a lower level than `gnus-verbose'.
3811 ;; Guideline for numbers:
3812 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
3813 ;; for things that take a long time, 7 - not very important messages
3814 ;; on stuff, 9 - messages inside loops.
3815 (defun gnus-message (level &rest args)
3816 (if (<= level gnus-verbose)
3817 (apply 'message args)
3818 ;; We have to do this format thingy here even if the result isn't
3819 ;; shown - the return value has to be the same as the return value
3820 ;; from `message'.
3821 (apply 'format args)))
3822
3823 (defun gnus-error (level &rest args)
3824 "Beep an error if LEVEL is equal to or less than `gnus-verbose'."
3825 (when (<= (floor level) gnus-verbose)
3826 (apply 'message args)
3827 (ding)
3828 (let (duration)
3829 (when (and (floatp level)
3830 (not (zerop (setq duration (* 10 (- level (floor level)))))))
3831 (sit-for duration))))
3832 nil)
3833
3834 ;; Generate a unique new group name.
3835 (defun gnus-generate-new-group-name (leaf)
3836 (let ((name leaf)
3837 (num 0))
3838 (while (gnus-gethash name gnus-newsrc-hashtb)
3839 (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
3840 name))
3841
3842 (defsubst gnus-hide-text (b e props)
3843 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
3844 (gnus-add-text-properties b e props)
3845 (when (memq 'intangible props)
3846 (gnus-put-text-property (max (1- b) (point-min))
3847 b 'intangible (cddr (memq 'intangible props)))))
3848
3849 (defsubst gnus-unhide-text (b e)
3850 "Remove hidden text properties from region between B and E."
3851 (remove-text-properties b e gnus-hidden-properties)
3852 (when (memq 'intangible gnus-hidden-properties)
3853 (gnus-put-text-property (max (1- b) (point-min))
3854 b 'intangible nil)))
3855
3856 (defun gnus-hide-text-type (b e type)
3857 "Hide text of TYPE between B and E."
3858 (gnus-hide-text b e (cons 'gnus-type (cons type gnus-hidden-properties))))
3859
3860 (defun gnus-parent-headers (headers &optional generation)
3861 "Return the headers of the GENERATIONeth parent of HEADERS."
3862 (unless generation
3863 (setq generation 1))
3864 (let (references parent)
3865 (while (and headers (not (zerop generation)))
3866 (setq references (mail-header-references headers))
3867 (when (and references
3868 (setq parent (gnus-parent-id references))
3869 (setq headers (car (gnus-id-to-thread parent))))
3870 (decf generation)))
3871 headers))
3872
3873 (defun gnus-parent-id (references)
3874 "Return the last Message-ID in REFERENCES."
3875 (when (and references
3876 (string-match "\\(<[^\n<>]+>\\)[ \t\n]*\\'" references))
3877 (substring references (match-beginning 1) (match-end 1))))
3878
3879 (defun gnus-split-references (references)
3880 "Return a list of Message-IDs in REFERENCES."
3881 (let ((beg 0)
3882 ids)
3883 (while (string-match "<[^>]+>" references beg)
3884 (push (substring references (match-beginning 0) (setq beg (match-end 0)))
3885 ids))
3886 (nreverse ids)))
3887
3888 (defun gnus-buffer-live-p (buffer)
3889 "Say whether BUFFER is alive or not."
3890 (and buffer
3891 (get-buffer buffer)
3892 (buffer-name (get-buffer buffer))))
3893
3894 (defun gnus-ephemeral-group-p (group)
3895 "Say whether GROUP is ephemeral or not."
3896 (gnus-group-get-parameter group 'quit-config))
3897
3898 (defun gnus-group-quit-config (group)
3899 "Return the quit-config of GROUP."
3900 (gnus-group-get-parameter group 'quit-config))
3901
3902 (defun gnus-simplify-mode-line ()
3903 "Make mode lines a bit simpler."
3904 (setq mode-line-modified "-- ")
3905 (when (listp mode-line-format)
3906 (make-local-variable 'mode-line-format)
3907 (setq mode-line-format (copy-sequence mode-line-format))
3908 (when (equal (nth 3 mode-line-format) " ")
3909 (setcar (nthcdr 3 mode-line-format) " "))))
3910
3911 ;;; List and range functions
3912
3913 (defun gnus-last-element (list)
3914 "Return last element of LIST."
3915 (while (cdr list)
3916 (setq list (cdr list)))
3917 (car list))
3918
3919 (defun gnus-copy-sequence (list)
3920 "Do a complete, total copy of a list."
3921 (if (and (consp list) (not (consp (cdr list))))
3922 (cons (car list) (cdr list))
3923 (mapcar (lambda (elem) (if (consp elem)
3924 (if (consp (cdr elem))
3925 (gnus-copy-sequence elem)
3926 (cons (car elem) (cdr elem)))
3927 elem))
3928 list)))
3929
3930 (defun gnus-set-difference (list1 list2)
3931 "Return a list of elements of LIST1 that do not appear in LIST2."
3932 (let ((list1 (copy-sequence list1)))
3933 (while list2
3934 (setq list1 (delq (car list2) list1))
3935 (setq list2 (cdr list2)))
3936 list1))
3937
3938 (defun gnus-sorted-complement (list1 list2)
3939 "Return a list of elements of LIST1 that do not appear in LIST2.
3940 Both lists have to be sorted over <."
3941 (let (out)
3942 (if (or (null list1) (null list2))
3943 (or list1 list2)
3944 (while (and list1 list2)
3945 (cond ((= (car list1) (car list2))
3946 (setq list1 (cdr list1)
3947 list2 (cdr list2)))
3948 ((< (car list1) (car list2))
3949 (setq out (cons (car list1) out))
3950 (setq list1 (cdr list1)))
3951 (t
3952 (setq out (cons (car list2) out))
3953 (setq list2 (cdr list2)))))
3954 (nconc (nreverse out) (or list1 list2)))))
3955
3956 (defun gnus-intersection (list1 list2)
3957 (let ((result nil))
3958 (while list2
3959 (if (memq (car list2) list1)
3960 (setq result (cons (car list2) result)))
3961 (setq list2 (cdr list2)))
3962 result))
3963
3964 (defun gnus-sorted-intersection (list1 list2)
3965 ;; LIST1 and LIST2 have to be sorted over <.
3966 (let (out)
3967 (while (and list1 list2)
3968 (cond ((= (car list1) (car list2))
3969 (setq out (cons (car list1) out)
3970 list1 (cdr list1)
3971 list2 (cdr list2)))
3972 ((< (car list1) (car list2))
3973 (setq list1 (cdr list1)))
3974 (t
3975 (setq list2 (cdr list2)))))
3976 (nreverse out)))
3977
3978 (defun gnus-set-sorted-intersection (list1 list2)
3979 ;; LIST1 and LIST2 have to be sorted over <.
3980 ;; This function modifies LIST1.
3981 (let* ((top (cons nil list1))
3982 (prev top))
3983 (while (and list1 list2)
3984 (cond ((= (car list1) (car list2))
3985 (setq prev list1
3986 list1 (cdr list1)
3987 list2 (cdr list2)))
3988 ((< (car list1) (car list2))
3989 (setcdr prev (cdr list1))
3990 (setq list1 (cdr list1)))
3991 (t
3992 (setq list2 (cdr list2)))))
3993 (setcdr prev nil)
3994 (cdr top)))
3995
3996 (defun gnus-compress-sequence (numbers &optional always-list)
3997 "Convert list of numbers to a list of ranges or a single range.
3998 If ALWAYS-LIST is non-nil, this function will always release a list of
3999 ranges."
4000 (let* ((first (car numbers))
4001 (last (car numbers))
4002 result)
4003 (if (null numbers)
4004 nil
4005 (if (not (listp (cdr numbers)))
4006 numbers
4007 (while numbers
4008 (cond ((= last (car numbers)) nil) ;Omit duplicated number
4009 ((= (1+ last) (car numbers)) ;Still in sequence
4010 (setq last (car numbers)))
4011 (t ;End of one sequence
4012 (setq result
4013 (cons (if (= first last) first
4014 (cons first last)) result))
4015 (setq first (car numbers))
4016 (setq last (car numbers))))
4017 (setq numbers (cdr numbers)))
4018 (if (and (not always-list) (null result))
4019 (if (= first last) (list first) (cons first last))
4020 (nreverse (cons (if (= first last) first (cons first last))
4021 result)))))))
4022
4023 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
4024 (defun gnus-uncompress-range (ranges)
4025 "Expand a list of ranges into a list of numbers.
4026 RANGES is either a single range on the form `(num . num)' or a list of
4027 these ranges."
4028 (let (first last result)
4029 (cond
4030 ((null ranges)
4031 nil)
4032 ((not (listp (cdr ranges)))
4033 (setq first (car ranges))
4034 (setq last (cdr ranges))
4035 (while (<= first last)
4036 (setq result (cons first result))
4037 (setq first (1+ first)))
4038 (nreverse result))
4039 (t
4040 (while ranges
4041 (if (atom (car ranges))
4042 (if (numberp (car ranges))
4043 (setq result (cons (car ranges) result)))
4044 (setq first (caar ranges))
4045 (setq last (cdar ranges))
4046 (while (<= first last)
4047 (setq result (cons first result))
4048 (setq first (1+ first))))
4049 (setq ranges (cdr ranges)))
4050 (nreverse result)))))
4051
4052 (defun gnus-add-to-range (ranges list)
4053 "Return a list of ranges that has all articles from both RANGES and LIST.
4054 Note: LIST has to be sorted over `<'."
4055 (if (not ranges)
4056 (gnus-compress-sequence list t)
4057 (setq list (copy-sequence list))
4058 (or (listp (cdr ranges))
4059 (setq ranges (list ranges)))
4060 (let ((out ranges)
4061 ilist lowest highest temp)
4062 (while (and ranges list)
4063 (setq ilist list)
4064 (setq lowest (or (and (atom (car ranges)) (car ranges))
4065 (caar ranges)))
4066 (while (and list (cdr list) (< (cadr list) lowest))
4067 (setq list (cdr list)))
4068 (if (< (car ilist) lowest)
4069 (progn
4070 (setq temp list)
4071 (setq list (cdr list))
4072 (setcdr temp nil)
4073 (setq out (nconc (gnus-compress-sequence ilist t) out))))
4074 (setq highest (or (and (atom (car ranges)) (car ranges))
4075 (cdar ranges)))
4076 (while (and list (<= (car list) highest))
4077 (setq list (cdr list)))
4078 (setq ranges (cdr ranges)))
4079 (if list
4080 (setq out (nconc (gnus-compress-sequence list t) out)))
4081 (setq out (sort out (lambda (r1 r2)
4082 (< (or (and (atom r1) r1) (car r1))
4083 (or (and (atom r2) r2) (car r2))))))
4084 (setq ranges out)
4085 (while ranges
4086 (if (atom (car ranges))
4087 (if (cdr ranges)
4088 (if (atom (cadr ranges))
4089 (if (= (1+ (car ranges)) (cadr ranges))
4090 (progn
4091 (setcar ranges (cons (car ranges)
4092 (cadr ranges)))
4093 (setcdr ranges (cddr ranges))))
4094 (if (= (1+ (car ranges)) (caadr ranges))
4095 (progn
4096 (setcar (cadr ranges) (car ranges))
4097 (setcar ranges (cadr ranges))
4098 (setcdr ranges (cddr ranges))))))
4099 (if (cdr ranges)
4100 (if (atom (cadr ranges))
4101 (if (= (1+ (cdar ranges)) (cadr ranges))
4102 (progn
4103 (setcdr (car ranges) (cadr ranges))
4104 (setcdr ranges (cddr ranges))))
4105 (if (= (1+ (cdar ranges)) (caadr ranges))
4106 (progn
4107 (setcdr (car ranges) (cdadr ranges))
4108 (setcdr ranges (cddr ranges)))))))
4109 (setq ranges (cdr ranges)))
4110 out)))
4111
4112 (defun gnus-remove-from-range (ranges list)
4113 "Return a list of ranges that has all articles from LIST removed from RANGES.
4114 Note: LIST has to be sorted over `<'."
4115 ;; !!! This function shouldn't look like this, but I've got a headache.
4116 (gnus-compress-sequence
4117 (gnus-sorted-complement
4118 (gnus-uncompress-range ranges) list)))
4119
4120 (defun gnus-member-of-range (number ranges)
4121 (if (not (listp (cdr ranges)))
4122 (and (>= number (car ranges))
4123 (<= number (cdr ranges)))
4124 (let ((not-stop t))
4125 (while (and ranges
4126 (if (numberp (car ranges))
4127 (>= number (car ranges))
4128 (>= number (caar ranges)))
4129 not-stop)
4130 (if (if (numberp (car ranges))
4131 (= number (car ranges))
4132 (and (>= number (caar ranges))
4133 (<= number (cdar ranges))))
4134 (setq not-stop nil))
4135 (setq ranges (cdr ranges)))
4136 (not not-stop))))
4137
4138 (defun gnus-range-length (range)
4139 "Return the length RANGE would have if uncompressed."
4140 (length (gnus-uncompress-range range)))
4141
4142 (defun gnus-sublist-p (list sublist)
4143 "Test whether all elements in SUBLIST are members of LIST."
4144 (let ((sublistp t))
4145 (while sublist
4146 (unless (memq (pop sublist) list)
4147 (setq sublistp nil
4148 sublist nil)))
4149 sublistp))
4150
4151 \f
4152 ;;;
4153 ;;; Gnus group mode
4154 ;;;
4155
4156 (defvar gnus-group-mode-map nil)
4157 (put 'gnus-group-mode 'mode-class 'special)
4158
4159 (unless gnus-group-mode-map
4160 (setq gnus-group-mode-map (make-keymap))
4161 (suppress-keymap gnus-group-mode-map)
4162
4163 (gnus-define-keys gnus-group-mode-map
4164 " " gnus-group-read-group
4165 "=" gnus-group-select-group
4166 "\r" gnus-group-select-group
4167 "\M-\r" gnus-group-quick-select-group
4168 "j" gnus-group-jump-to-group
4169 "n" gnus-group-next-unread-group
4170 "p" gnus-group-prev-unread-group
4171 "\177" gnus-group-prev-unread-group
4172 [delete] gnus-group-prev-unread-group
4173 "N" gnus-group-next-group
4174 "P" gnus-group-prev-group
4175 "\M-n" gnus-group-next-unread-group-same-level
4176 "\M-p" gnus-group-prev-unread-group-same-level
4177 "," gnus-group-best-unread-group
4178 "." gnus-group-first-unread-group
4179 "u" gnus-group-unsubscribe-current-group
4180 "U" gnus-group-unsubscribe-group
4181 "c" gnus-group-catchup-current
4182 "C" gnus-group-catchup-current-all
4183 "l" gnus-group-list-groups
4184 "L" gnus-group-list-all-groups
4185 "m" gnus-group-mail
4186 "g" gnus-group-get-new-news
4187 "\M-g" gnus-group-get-new-news-this-group
4188 "R" gnus-group-restart
4189 "r" gnus-group-read-init-file
4190 "B" gnus-group-browse-foreign-server
4191 "b" gnus-group-check-bogus-groups
4192 "F" gnus-find-new-newsgroups
4193 "\C-c\C-d" gnus-group-describe-group
4194 "\M-d" gnus-group-describe-all-groups
4195 "\C-c\C-a" gnus-group-apropos
4196 "\C-c\M-\C-a" gnus-group-description-apropos
4197 "a" gnus-group-post-news
4198 "\ek" gnus-group-edit-local-kill
4199 "\eK" gnus-group-edit-global-kill
4200 "\C-k" gnus-group-kill-group
4201 "\C-y" gnus-group-yank-group
4202 "\C-w" gnus-group-kill-region
4203 "\C-x\C-t" gnus-group-transpose-groups
4204 "\C-c\C-l" gnus-group-list-killed
4205 "\C-c\C-x" gnus-group-expire-articles
4206 "\C-c\M-\C-x" gnus-group-expire-all-groups
4207 "V" gnus-version
4208 "s" gnus-group-save-newsrc
4209 "z" gnus-group-suspend
4210 ; "Z" gnus-group-clear-dribble
4211 "q" gnus-group-exit
4212 "Q" gnus-group-quit
4213 "?" gnus-group-describe-briefly
4214 "\C-c\C-i" gnus-info-find-node
4215 "\M-e" gnus-group-edit-group-method
4216 "^" gnus-group-enter-server-mode
4217 gnus-mouse-2 gnus-mouse-pick-group
4218 "<" beginning-of-buffer
4219 ">" end-of-buffer
4220 "\C-c\C-b" gnus-bug
4221 "\C-c\C-s" gnus-group-sort-groups
4222 "t" gnus-topic-mode
4223 "\C-c\M-g" gnus-activate-all-groups
4224 "\M-&" gnus-group-universal-argument
4225 "#" gnus-group-mark-group
4226 "\M-#" gnus-group-unmark-group)
4227
4228 (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
4229 "m" gnus-group-mark-group
4230 "u" gnus-group-unmark-group
4231 "w" gnus-group-mark-region
4232 "m" gnus-group-mark-buffer
4233 "r" gnus-group-mark-regexp
4234 "U" gnus-group-unmark-all-groups)
4235
4236 (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
4237 "d" gnus-group-make-directory-group
4238 "h" gnus-group-make-help-group
4239 "a" gnus-group-make-archive-group
4240 "k" gnus-group-make-kiboze-group
4241 "m" gnus-group-make-group
4242 "E" gnus-group-edit-group
4243 "e" gnus-group-edit-group-method
4244 "p" gnus-group-edit-group-parameters
4245 "v" gnus-group-add-to-virtual
4246 "V" gnus-group-make-empty-virtual
4247 "D" gnus-group-enter-directory
4248 "f" gnus-group-make-doc-group
4249 "r" gnus-group-rename-group
4250 "\177" gnus-group-delete-group
4251 [delete] gnus-group-delete-group)
4252
4253 (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
4254 "b" gnus-group-brew-soup
4255 "w" gnus-soup-save-areas
4256 "s" gnus-soup-send-replies
4257 "p" gnus-soup-pack-packet
4258 "r" nnsoup-pack-replies)
4259
4260 (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
4261 "s" gnus-group-sort-groups
4262 "a" gnus-group-sort-groups-by-alphabet
4263 "u" gnus-group-sort-groups-by-unread
4264 "l" gnus-group-sort-groups-by-level
4265 "v" gnus-group-sort-groups-by-score
4266 "r" gnus-group-sort-groups-by-rank
4267 "m" gnus-group-sort-groups-by-method)
4268
4269 (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
4270 "k" gnus-group-list-killed
4271 "z" gnus-group-list-zombies
4272 "s" gnus-group-list-groups
4273 "u" gnus-group-list-all-groups
4274 "A" gnus-group-list-active
4275 "a" gnus-group-apropos
4276 "d" gnus-group-description-apropos
4277 "m" gnus-group-list-matching
4278 "M" gnus-group-list-all-matching
4279 "l" gnus-group-list-level)
4280
4281 (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
4282 "f" gnus-score-flush-cache)
4283
4284 (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
4285 "f" gnus-group-fetch-faq)
4286
4287 (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
4288 "l" gnus-group-set-current-level
4289 "t" gnus-group-unsubscribe-current-group
4290 "s" gnus-group-unsubscribe-group
4291 "k" gnus-group-kill-group
4292 "y" gnus-group-yank-group
4293 "w" gnus-group-kill-region
4294 "\C-k" gnus-group-kill-level
4295 "z" gnus-group-kill-all-zombies))
4296
4297 (defun gnus-group-mode ()
4298 "Major mode for reading news.
4299
4300 All normal editing commands are switched off.
4301 \\<gnus-group-mode-map>
4302 The group buffer lists (some of) the groups available. For instance,
4303 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
4304 lists all zombie groups.
4305
4306 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
4307 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
4308
4309 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
4310
4311 The following commands are available:
4312
4313 \\{gnus-group-mode-map}"
4314 (interactive)
4315 (when (and menu-bar-mode
4316 (gnus-visual-p 'group-menu 'menu))
4317 (gnus-group-make-menu-bar))
4318 (kill-all-local-variables)
4319 (gnus-simplify-mode-line)
4320 (setq major-mode 'gnus-group-mode)
4321 (setq mode-name "Group")
4322 (gnus-group-set-mode-line)
4323 (setq mode-line-process nil)
4324 (use-local-map gnus-group-mode-map)
4325 (buffer-disable-undo (current-buffer))
4326 (setq truncate-lines t)
4327 (setq buffer-read-only t)
4328 (gnus-make-local-hook 'post-command-hook)
4329 (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
4330 (run-hooks 'gnus-group-mode-hook))
4331
4332 (defun gnus-clear-inboxes-moved ()
4333 (setq nnmail-moved-inboxes nil))
4334
4335 (defun gnus-mouse-pick-group (e)
4336 "Enter the group under the mouse pointer."
4337 (interactive "e")
4338 (mouse-set-point e)
4339 (gnus-group-read-group nil))
4340
4341 ;; Look at LEVEL and find out what the level is really supposed to be.
4342 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
4343 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
4344 (defun gnus-group-default-level (&optional level number-or-nil)
4345 (cond
4346 (gnus-group-use-permanent-levels
4347 (or (setq gnus-group-use-permanent-levels
4348 (or level (if (numberp gnus-group-use-permanent-levels)
4349 gnus-group-use-permanent-levels
4350 (or gnus-group-default-list-level
4351 gnus-level-subscribed))))
4352 gnus-group-default-list-level gnus-level-subscribed))
4353 (number-or-nil
4354 level)
4355 (t
4356 (or level gnus-group-default-list-level gnus-level-subscribed))))
4357
4358 ;;;###autoload
4359 (defun gnus-slave-no-server (&optional arg)
4360 "Read network news as a slave, without connecting to local server"
4361 (interactive "P")
4362 (gnus-no-server arg t))
4363
4364 ;;;###autoload
4365 (defun gnus-no-server (&optional arg slave)
4366 "Read network news.
4367 If ARG is a positive number, Gnus will use that as the
4368 startup level. If ARG is nil, Gnus will be started at level 2.
4369 If ARG is non-nil and not a positive number, Gnus will
4370 prompt the user for the name of an NNTP server to use.
4371 As opposed to `gnus', this command will not connect to the local server."
4372 (interactive "P")
4373 (let ((val (or arg (1- gnus-level-default-subscribed))))
4374 (gnus val t slave)
4375 (make-local-variable 'gnus-group-use-permanent-levels)
4376 (setq gnus-group-use-permanent-levels val)))
4377
4378 ;;;###autoload
4379 (defun gnus-slave (&optional arg)
4380 "Read news as a slave."
4381 (interactive "P")
4382 (gnus arg nil 'slave))
4383
4384 ;;;###autoload
4385 (defun gnus-other-frame (&optional arg)
4386 "Pop up a frame to read news."
4387 (interactive "P")
4388 (if (get-buffer gnus-group-buffer)
4389 (let ((pop-up-frames t))
4390 (gnus arg))
4391 (select-frame (make-frame))
4392 (gnus arg)))
4393
4394 ;;;###autoload
4395 (defun gnus (&optional arg dont-connect slave)
4396 "Read network news.
4397 If ARG is non-nil and a positive number, Gnus will use that as the
4398 startup level. If ARG is non-nil and not a positive number, Gnus will
4399 prompt the user for the name of an NNTP server to use."
4400 (interactive "P")
4401
4402 (if (get-buffer gnus-group-buffer)
4403 (progn
4404 (switch-to-buffer gnus-group-buffer)
4405 (gnus-group-get-new-news))
4406
4407 (gnus-clear-system)
4408 (nnheader-init-server-buffer)
4409 (gnus-read-init-file)
4410 (setq gnus-slave slave)
4411
4412 (gnus-group-setup-buffer)
4413 (let ((buffer-read-only nil))
4414 (erase-buffer)
4415 (if (not gnus-inhibit-startup-message)
4416 (progn
4417 (gnus-group-startup-message)
4418 (sit-for 0))))
4419
4420 (let ((level (and (numberp arg) (> arg 0) arg))
4421 did-connect)
4422 (unwind-protect
4423 (progn
4424 (or dont-connect
4425 (setq did-connect
4426 (gnus-start-news-server (and arg (not level))))))
4427 (if (and (not dont-connect)
4428 (not did-connect))
4429 (gnus-group-quit)
4430 (run-hooks 'gnus-startup-hook)
4431 ;; NNTP server is successfully open.
4432
4433 ;; Find the current startup file name.
4434 (setq gnus-current-startup-file
4435 (gnus-make-newsrc-file gnus-startup-file))
4436
4437 ;; Read the dribble file.
4438 (when (or gnus-slave gnus-use-dribble-file)
4439 (gnus-dribble-read-file))
4440
4441 ;; Allow using GroupLens predictions.
4442 (when gnus-use-grouplens
4443 (bbb-login)
4444 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
4445
4446 (gnus-summary-make-display-table)
4447 ;; Do the actual startup.
4448 (gnus-setup-news nil level dont-connect)
4449 ;; Generate the group buffer.
4450 (gnus-group-list-groups level)
4451 (gnus-group-first-unread-group)
4452 (gnus-configure-windows 'group)
4453 (gnus-group-set-mode-line))))))
4454
4455 (defun gnus-unload ()
4456 "Unload all Gnus features."
4457 (interactive)
4458 (or (boundp 'load-history)
4459 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
4460 (let ((history load-history)
4461 feature)
4462 (while history
4463 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
4464 (setq feature (cdr (assq 'provide (car history))))
4465 (unload-feature feature 'force))
4466 (setq history (cdr history)))))
4467
4468 (defun gnus-compile ()
4469 "Byte-compile the user-defined format specs."
4470 (interactive)
4471 (let ((entries gnus-format-specs)
4472 entry gnus-tmp-func)
4473 (save-excursion
4474 (gnus-message 7 "Compiling format specs...")
4475
4476 (while entries
4477 (setq entry (pop entries))
4478 (if (eq (car entry) 'version)
4479 (setq gnus-format-specs (delq entry gnus-format-specs))
4480 (when (and (listp (caddr entry))
4481 (not (eq 'byte-code (caaddr entry))))
4482 (fset 'gnus-tmp-func
4483 `(lambda () ,(caddr entry)))
4484 (byte-compile 'gnus-tmp-func)
4485 (setcar (cddr entry) (gnus-byte-code 'gnus-tmp-func)))))
4486
4487 (push (cons 'version emacs-version) gnus-format-specs)
4488
4489 (gnus-message 7 "Compiling user specs...done"))))
4490
4491 (defun gnus-indent-rigidly (start end arg)
4492 "Indent rigidly using only spaces and no tabs."
4493 (save-excursion
4494 (save-restriction
4495 (narrow-to-region start end)
4496 (indent-rigidly start end arg)
4497 (goto-char (point-min))
4498 (while (search-forward "\t" nil t)
4499 (replace-match " " t t)))))
4500
4501 (defun gnus-group-startup-message (&optional x y)
4502 "Insert startup message in current buffer."
4503 ;; Insert the message.
4504 (erase-buffer)
4505 (insert
4506 (format " %s
4507 _ ___ _ _
4508 _ ___ __ ___ __ _ ___
4509 __ _ ___ __ ___
4510 _ ___ _
4511 _ _ __ _
4512 ___ __ _
4513 __ _
4514 _ _ _
4515 _ _ _
4516 _ _ _
4517 __ ___
4518 _ _ _ _
4519 _ _
4520 _ _
4521 _ _
4522 _
4523 __
4524
4525 "
4526 ""))
4527 ;; And then hack it.
4528 (gnus-indent-rigidly (point-min) (point-max)
4529 (/ (max (- (window-width) (or x 46)) 0) 2))
4530 (goto-char (point-min))
4531 (forward-line 1)
4532 (let* ((pheight (count-lines (point-min) (point-max)))
4533 (wheight (window-height))
4534 (rest (- wheight pheight)))
4535 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
4536 ;; Fontify some.
4537 (goto-char (point-min))
4538 (and (search-forward "Praxis" nil t)
4539 (gnus-put-text-property (match-beginning 0) (match-end 0) 'face 'bold))
4540 (goto-char (point-min))
4541 (let* ((mode-string (gnus-group-set-mode-line)))
4542 (setq mode-line-buffer-identification
4543 (list (concat gnus-version (substring (car mode-string) 4))))
4544 (set-buffer-modified-p t)))
4545
4546 (defun gnus-group-setup-buffer ()
4547 (or (get-buffer gnus-group-buffer)
4548 (progn
4549 (switch-to-buffer gnus-group-buffer)
4550 (gnus-add-current-to-buffer-list)
4551 (gnus-group-mode)
4552 (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
4553
4554 (defun gnus-group-list-groups (&optional level unread lowest)
4555 "List newsgroups with level LEVEL or lower that have unread articles.
4556 Default is all subscribed groups.
4557 If argument UNREAD is non-nil, groups with no unread articles are also
4558 listed."
4559 (interactive (list (if current-prefix-arg
4560 (prefix-numeric-value current-prefix-arg)
4561 (or
4562 (gnus-group-default-level nil t)
4563 gnus-group-default-list-level
4564 gnus-level-subscribed))))
4565 (or level
4566 (setq level (car gnus-group-list-mode)
4567 unread (cdr gnus-group-list-mode)))
4568 (setq level (gnus-group-default-level level))
4569 (gnus-group-setup-buffer) ;May call from out of group buffer
4570 (gnus-update-format-specifications)
4571 (let ((case-fold-search nil)
4572 (props (text-properties-at (gnus-point-at-bol)))
4573 (group (gnus-group-group-name)))
4574 (set-buffer gnus-group-buffer)
4575 (funcall gnus-group-prepare-function level unread lowest)
4576 (if (zerop (buffer-size))
4577 (gnus-message 5 gnus-no-groups-message)
4578 (goto-char (point-max))
4579 (when (or (not gnus-group-goto-next-group-function)
4580 (not (funcall gnus-group-goto-next-group-function
4581 group props)))
4582 (if (not group)
4583 ;; Go to the first group with unread articles.
4584 (gnus-group-search-forward t)
4585 ;; Find the right group to put point on. If the current group
4586 ;; has disappeared in the new listing, try to find the next
4587 ;; one. If no next one can be found, just leave point at the
4588 ;; first newsgroup in the buffer.
4589 (if (not (gnus-goto-char
4590 (text-property-any
4591 (point-min) (point-max)
4592 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
4593 (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
4594 (while (and newsrc
4595 (not (gnus-goto-char
4596 (text-property-any
4597 (point-min) (point-max) 'gnus-group
4598 (gnus-intern-safe
4599 (caar newsrc) gnus-active-hashtb)))))
4600 (setq newsrc (cdr newsrc)))
4601 (or newsrc (progn (goto-char (point-max))
4602 (forward-line -1)))))))
4603 ;; Adjust cursor point.
4604 (gnus-group-position-point))))
4605
4606 (defun gnus-group-list-level (level &optional all)
4607 "List groups on LEVEL.
4608 If ALL (the prefix), also list groups that have no unread articles."
4609 (interactive "nList groups on level: \nP")
4610 (gnus-group-list-groups level all level))
4611
4612 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
4613 "List all newsgroups with unread articles of level LEVEL or lower.
4614 If ALL is non-nil, list groups that have no unread articles.
4615 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
4616 If REGEXP, only list groups matching REGEXP."
4617 (set-buffer gnus-group-buffer)
4618 (let ((buffer-read-only nil)
4619 (newsrc (cdr gnus-newsrc-alist))
4620 (lowest (or lowest 1))
4621 info clevel unread group params)
4622 (erase-buffer)
4623 (if (< lowest gnus-level-zombie)
4624 ;; List living groups.
4625 (while newsrc
4626 (setq info (car newsrc)
4627 group (gnus-info-group info)
4628 params (gnus-info-params info)
4629 newsrc (cdr newsrc)
4630 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
4631 (and unread ; This group might be bogus
4632 (or (not regexp)
4633 (string-match regexp group))
4634 (<= (setq clevel (gnus-info-level info)) level)
4635 (>= clevel lowest)
4636 (or all ; We list all groups?
4637 (if (eq unread t) ; Unactivated?
4638 gnus-group-list-inactive-groups ; We list unactivated
4639 (> unread 0)) ; We list groups with unread articles
4640 (and gnus-list-groups-with-ticked-articles
4641 (cdr (assq 'tick (gnus-info-marks info))))
4642 ; And groups with tickeds
4643 ;; Check for permanent visibility.
4644 (and gnus-permanently-visible-groups
4645 (string-match gnus-permanently-visible-groups
4646 group))
4647 (memq 'visible params)
4648 (cdr (assq 'visible params)))
4649 (gnus-group-insert-group-line
4650 group (gnus-info-level info)
4651 (gnus-info-marks info) unread (gnus-info-method info)))))
4652
4653 ;; List dead groups.
4654 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
4655 (gnus-group-prepare-flat-list-dead
4656 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
4657 gnus-level-zombie ?Z
4658 regexp))
4659 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
4660 (gnus-group-prepare-flat-list-dead
4661 (setq gnus-killed-list (sort gnus-killed-list 'string<))
4662 gnus-level-killed ?K regexp))
4663
4664 (gnus-group-set-mode-line)
4665 (setq gnus-group-list-mode (cons level all))
4666 (run-hooks 'gnus-group-prepare-hook)))
4667
4668 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
4669 ;; List zombies and killed lists somewhat faster, which was
4670 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
4671 ;; this by ignoring the group format specification altogether.
4672 (let (group)
4673 (if regexp
4674 ;; This loop is used when listing groups that match some
4675 ;; regexp.
4676 (while groups
4677 (setq group (pop groups))
4678 (when (string-match regexp group)
4679 (gnus-add-text-properties
4680 (point) (prog1 (1+ (point))
4681 (insert " " mark " *: " group "\n"))
4682 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
4683 'gnus-unread t
4684 'gnus-level level))))
4685 ;; This loop is used when listing all groups.
4686 (while groups
4687 (gnus-add-text-properties
4688 (point) (prog1 (1+ (point))
4689 (insert " " mark " *: "
4690 (setq group (pop groups)) "\n"))
4691 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
4692 'gnus-unread t
4693 'gnus-level level))))))
4694
4695 (defmacro gnus-group-real-name (group)
4696 "Find the real name of a foreign newsgroup."
4697 `(let ((gname ,group))
4698 (if (string-match ":[^:]+$" gname)
4699 (substring gname (1+ (match-beginning 0)))
4700 gname)))
4701
4702 (defsubst gnus-server-add-address (method)
4703 (let ((method-name (symbol-name (car method))))
4704 (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
4705 (not (assq (intern (concat method-name "-address")) method)))
4706 (append method (list (list (intern (concat method-name "-address"))
4707 (nth 1 method))))
4708 method)))
4709
4710 (defsubst gnus-server-get-method (group method)
4711 ;; Input either a server name, and extended server name, or a
4712 ;; select method, and return a select method.
4713 (cond ((stringp method)
4714 (gnus-server-to-method method))
4715 ((equal method gnus-select-method)
4716 gnus-select-method)
4717 ((and (stringp (car method)) group)
4718 (gnus-server-extend-method group method))
4719 ((and method (not group)
4720 (equal (cadr method) ""))
4721 method)
4722 (t
4723 (gnus-server-add-address method))))
4724
4725 (defun gnus-server-to-method (server)
4726 "Map virtual server names to select methods."
4727 (or
4728 ;; Is this a method, perhaps?
4729 (and server (listp server) server)
4730 ;; Perhaps this is the native server?
4731 (and (equal server "native") gnus-select-method)
4732 ;; It should be in the server alist.
4733 (cdr (assoc server gnus-server-alist))
4734 ;; If not, we look through all the opened server
4735 ;; to see whether we can find it there.
4736 (let ((opened gnus-opened-servers))
4737 (while (and opened
4738 (not (equal server (format "%s:%s" (caaar opened)
4739 (cadaar opened)))))
4740 (pop opened))
4741 (caar opened))))
4742
4743 (defmacro gnus-method-equal (ss1 ss2)
4744 "Say whether two servers are equal."
4745 `(let ((s1 ,ss1)
4746 (s2 ,ss2))
4747 (or (equal s1 s2)
4748 (and (= (length s1) (length s2))
4749 (progn
4750 (while (and s1 (member (car s1) s2))
4751 (setq s1 (cdr s1)))
4752 (null s1))))))
4753
4754 (defun gnus-server-equal (m1 m2)
4755 "Say whether two methods are equal."
4756 (let ((m1 (cond ((null m1) gnus-select-method)
4757 ((stringp m1) (gnus-server-to-method m1))
4758 (t m1)))
4759 (m2 (cond ((null m2) gnus-select-method)
4760 ((stringp m2) (gnus-server-to-method m2))
4761 (t m2))))
4762 (gnus-method-equal m1 m2)))
4763
4764 (defun gnus-servers-using-backend (backend)
4765 "Return a list of known servers using BACKEND."
4766 (let ((opened gnus-opened-servers)
4767 out)
4768 (while opened
4769 (when (eq backend (caaar opened))
4770 (push (caar opened) out))
4771 (pop opened))
4772 out))
4773
4774 (defun gnus-archive-server-wanted-p ()
4775 "Say whether the user wants to use the archive server."
4776 (cond
4777 ((or (not gnus-message-archive-method)
4778 (not gnus-message-archive-group))
4779 nil)
4780 ((and gnus-message-archive-method gnus-message-archive-group)
4781 t)
4782 (t
4783 (let ((active (cadr (assq 'nnfolder-active-file
4784 gnus-message-archive-method))))
4785 (and active
4786 (file-exists-p active))))))
4787
4788 (defun gnus-group-prefixed-name (group method)
4789 "Return the whole name from GROUP and METHOD."
4790 (and (stringp method) (setq method (gnus-server-to-method method)))
4791 (concat (format "%s" (car method))
4792 (if (and
4793 (or (assoc (format "%s" (car method))
4794 (gnus-methods-using 'address))
4795 (gnus-server-equal method gnus-message-archive-method))
4796 (nth 1 method)
4797 (not (string= (nth 1 method) "")))
4798 (concat "+" (nth 1 method)))
4799 ":" group))
4800
4801 (defun gnus-group-real-prefix (group)
4802 "Return the prefix of the current group name."
4803 (if (string-match "^[^:]+:" group)
4804 (substring group 0 (match-end 0))
4805 ""))
4806
4807 (defun gnus-group-method (group)
4808 "Return the server or method used for selecting GROUP."
4809 (let ((prefix (gnus-group-real-prefix group)))
4810 (if (equal prefix "")
4811 gnus-select-method
4812 (let ((servers gnus-opened-servers)
4813 (server "")
4814 backend possible found)
4815 (if (string-match "^[^\\+]+\\+" prefix)
4816 (setq backend (intern (substring prefix 0 (1- (match-end 0))))
4817 server (substring prefix (match-end 0) (1- (length prefix))))
4818 (setq backend (intern (substring prefix 0 (1- (length prefix))))))
4819 (while servers
4820 (when (eq (caaar servers) backend)
4821 (setq possible (caar servers))
4822 (when (equal (cadaar servers) server)
4823 (setq found (caar servers))))
4824 (pop servers))
4825 (or (car (rassoc found gnus-server-alist))
4826 found
4827 (car (rassoc possible gnus-server-alist))
4828 possible
4829 (list backend server))))))
4830
4831 (defsubst gnus-secondary-method-p (method)
4832 "Return whether METHOD is a secondary select method."
4833 (let ((methods gnus-secondary-select-methods)
4834 (gmethod (gnus-server-get-method nil method)))
4835 (while (and methods
4836 (not (equal (gnus-server-get-method nil (car methods))
4837 gmethod)))
4838 (setq methods (cdr methods)))
4839 methods))
4840
4841 (defun gnus-group-foreign-p (group)
4842 "Say whether a group is foreign or not."
4843 (and (not (gnus-group-native-p group))
4844 (not (gnus-group-secondary-p group))))
4845
4846 (defun gnus-group-native-p (group)
4847 "Say whether the group is native or not."
4848 (not (string-match ":" group)))
4849
4850 (defun gnus-group-secondary-p (group)
4851 "Say whether the group is secondary or not."
4852 (gnus-secondary-method-p (gnus-find-method-for-group group)))
4853
4854 (defun gnus-group-get-parameter (group &optional symbol)
4855 "Returns the group parameters for GROUP.
4856 If SYMBOL, return the value of that symbol in the group parameters."
4857 (let ((params (gnus-info-params (gnus-get-info group))))
4858 (if symbol
4859 (gnus-group-parameter-value params symbol)
4860 params)))
4861
4862 (defun gnus-group-parameter-value (params symbol)
4863 "Return the value of SYMBOL in group PARAMS."
4864 (or (car (memq symbol params)) ; It's either a simple symbol
4865 (cdr (assq symbol params)))) ; or a cons.
4866
4867 (defun gnus-group-add-parameter (group param)
4868 "Add parameter PARAM to GROUP."
4869 (let ((info (gnus-get-info group)))
4870 (if (not info)
4871 () ; This is a dead group. We just ignore it.
4872 ;; Cons the new param to the old one and update.
4873 (gnus-group-set-info (cons param (gnus-info-params info))
4874 group 'params))))
4875
4876 (defun gnus-group-set-parameter (group name value)
4877 "Set parameter NAME to VALUE in GROUP."
4878 (let ((info (gnus-get-info group)))
4879 (if (not info)
4880 () ; This is a dead group. We just ignore it.
4881 (let ((old-params (gnus-info-params info))
4882 (new-params (list (cons name value))))
4883 (while old-params
4884 (if (or (not (listp (car old-params)))
4885 (not (eq (caar old-params) name)))
4886 (setq new-params (append new-params (list (car old-params)))))
4887 (setq old-params (cdr old-params)))
4888 (gnus-group-set-info new-params group 'params)))))
4889
4890 (defun gnus-group-add-score (group &optional score)
4891 "Add SCORE to the GROUP score.
4892 If SCORE is nil, add 1 to the score of GROUP."
4893 (let ((info (gnus-get-info group)))
4894 (when info
4895 (gnus-info-set-score info (+ (gnus-info-score info) (or score 1))))))
4896
4897 (defun gnus-summary-bubble-group ()
4898 "Increase the score of the current group.
4899 This is a handy function to add to `gnus-summary-exit-hook' to
4900 increase the score of each group you read."
4901 (gnus-group-add-score gnus-newsgroup-name))
4902
4903 (defun gnus-group-set-info (info &optional method-only-group part)
4904 (let* ((entry (gnus-gethash
4905 (or method-only-group (gnus-info-group info))
4906 gnus-newsrc-hashtb))
4907 (part-info info)
4908 (info (if method-only-group (nth 2 entry) info))
4909 method)
4910 (when method-only-group
4911 (unless entry
4912 (error "Trying to change non-existent group %s" method-only-group))
4913 ;; We have received parts of the actual group info - either the
4914 ;; select method or the group parameters. We first check
4915 ;; whether we have to extend the info, and if so, do that.
4916 (let ((len (length info))
4917 (total (if (eq part 'method) 5 6)))
4918 (when (< len total)
4919 (setcdr (nthcdr (1- len) info)
4920 (make-list (- total len) nil)))
4921 ;; Then we enter the new info.
4922 (setcar (nthcdr (1- total) info) part-info)))
4923 (unless entry
4924 ;; This is a new group, so we just create it.
4925 (save-excursion
4926 (set-buffer gnus-group-buffer)
4927 (setq method (gnus-info-method info))
4928 (when (gnus-server-equal method "native")
4929 (setq method nil))
4930 (save-excursion
4931 (set-buffer gnus-group-buffer)
4932 (if method
4933 ;; It's a foreign group...
4934 (gnus-group-make-group
4935 (gnus-group-real-name (gnus-info-group info))
4936 (if (stringp method) method
4937 (prin1-to-string (car method)))
4938 (and (consp method)
4939 (nth 1 (gnus-info-method info))))
4940 ;; It's a native group.
4941 (gnus-group-make-group (gnus-info-group info))))
4942 (gnus-message 6 "Note: New group created")
4943 (setq entry
4944 (gnus-gethash (gnus-group-prefixed-name
4945 (gnus-group-real-name (gnus-info-group info))
4946 (or (gnus-info-method info) gnus-select-method))
4947 gnus-newsrc-hashtb))))
4948 ;; Whether it was a new group or not, we now have the entry, so we
4949 ;; can do the update.
4950 (if entry
4951 (progn
4952 (setcar (nthcdr 2 entry) info)
4953 (when (and (not (eq (car entry) t))
4954 (gnus-active (gnus-info-group info)))
4955 (setcar entry (length (gnus-list-of-unread-articles (car info))))))
4956 (error "No such group: %s" (gnus-info-group info)))))
4957
4958 (defun gnus-group-set-method-info (group select-method)
4959 (gnus-group-set-info select-method group 'method))
4960
4961 (defun gnus-group-set-params-info (group params)
4962 (gnus-group-set-info params group 'params))
4963
4964 (defun gnus-group-update-group-line ()
4965 "Update the current line in the group buffer."
4966 (let* ((buffer-read-only nil)
4967 (group (gnus-group-group-name))
4968 (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
4969 gnus-group-indentation)
4970 (when group
4971 (and entry
4972 (not (gnus-ephemeral-group-p group))
4973 (gnus-dribble-enter
4974 (concat "(gnus-group-set-info '"
4975 (prin1-to-string (nth 2 entry)) ")")))
4976 (setq gnus-group-indentation (gnus-group-group-indentation))
4977 (gnus-delete-line)
4978 (gnus-group-insert-group-line-info group)
4979 (forward-line -1)
4980 (gnus-group-position-point))))
4981
4982 (defun gnus-group-insert-group-line-info (group)
4983 "Insert GROUP on the current line."
4984 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
4985 active info)
4986 (if entry
4987 (progn
4988 ;; (Un)subscribed group.
4989 (setq info (nth 2 entry))
4990 (gnus-group-insert-group-line
4991 group (gnus-info-level info) (gnus-info-marks info)
4992 (or (car entry) t) (gnus-info-method info)))
4993 ;; This group is dead.
4994 (gnus-group-insert-group-line
4995 group
4996 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
4997 nil
4998 (if (setq active (gnus-active group))
4999 (- (1+ (cdr active)) (car active)) 0)
5000 nil))))
5001
5002 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
5003 gnus-tmp-marked number
5004 gnus-tmp-method)
5005 "Insert a group line in the group buffer."
5006 (let* ((gnus-tmp-active (gnus-active gnus-tmp-group))
5007 (gnus-tmp-number-total
5008 (if gnus-tmp-active
5009 (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
5010 0))
5011 (gnus-tmp-number-of-unread
5012 (if (numberp number) (int-to-string (max 0 number))
5013 "*"))
5014 (gnus-tmp-number-of-read
5015 (if (numberp number)
5016 (int-to-string (max 0 (- gnus-tmp-number-total number)))
5017 "*"))
5018 (gnus-tmp-subscribed
5019 (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
5020 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
5021 ((= gnus-tmp-level gnus-level-zombie) ?Z)
5022 (t ?K)))
5023 (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group))
5024 (gnus-tmp-newsgroup-description
5025 (if gnus-description-hashtb
5026 (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "")
5027 ""))
5028 (gnus-tmp-moderated
5029 (if (member gnus-tmp-group gnus-moderated-list) ?m ? ))
5030 (gnus-tmp-moderated-string
5031 (if (eq gnus-tmp-moderated ?m) "(m)" ""))
5032 (gnus-tmp-method
5033 (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
5034 (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
5035 (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
5036 (gnus-tmp-news-method-string
5037 (if gnus-tmp-method
5038 (format "(%s:%s)" (car gnus-tmp-method)
5039 (cadr gnus-tmp-method)) ""))
5040 (gnus-tmp-marked-mark
5041 (if (and (numberp number)
5042 (zerop number)
5043 (cdr (assq 'tick gnus-tmp-marked)))
5044 ?* ? ))
5045 (gnus-tmp-process-marked
5046 (if (member gnus-tmp-group gnus-group-marked)
5047 gnus-process-mark ? ))
5048 (gnus-tmp-grouplens
5049 (or (and gnus-use-grouplens
5050 (bbb-grouplens-group-p gnus-tmp-group))
5051 ""))
5052 (buffer-read-only nil)
5053 header gnus-tmp-header) ; passed as parameter to user-funcs.
5054 (beginning-of-line)
5055 (gnus-add-text-properties
5056 (point)
5057 (prog1 (1+ (point))
5058 ;; Insert the text.
5059 (eval gnus-group-line-format-spec))
5060 `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
5061 gnus-unread ,(if (numberp number)
5062 (string-to-int gnus-tmp-number-of-unread)
5063 t)
5064 gnus-marked ,gnus-tmp-marked-mark
5065 gnus-indentation ,gnus-group-indentation
5066 gnus-level ,gnus-tmp-level))
5067 (when (inline (gnus-visual-p 'group-highlight 'highlight))
5068 (forward-line -1)
5069 (run-hooks 'gnus-group-update-hook)
5070 (forward-line))
5071 ;; Allow XEmacs to remove front-sticky text properties.
5072 (gnus-group-remove-excess-properties)))
5073
5074 (defun gnus-group-update-group (group &optional visible-only)
5075 "Update all lines where GROUP appear.
5076 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
5077 already."
5078 (save-excursion
5079 (set-buffer gnus-group-buffer)
5080 ;; The buffer may be narrowed.
5081 (save-restriction
5082 (widen)
5083 (let ((ident (gnus-intern-safe group gnus-active-hashtb))
5084 (loc (point-min))
5085 found buffer-read-only)
5086 ;; Enter the current status into the dribble buffer.
5087 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
5088 (if (and entry (not (gnus-ephemeral-group-p group)))
5089 (gnus-dribble-enter
5090 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
5091 ")"))))
5092 ;; Find all group instances. If topics are in use, each group
5093 ;; may be listed in more than once.
5094 (while (setq loc (text-property-any
5095 loc (point-max) 'gnus-group ident))
5096 (setq found t)
5097 (goto-char loc)
5098 (let ((gnus-group-indentation (gnus-group-group-indentation)))
5099 (gnus-delete-line)
5100 (gnus-group-insert-group-line-info group)
5101 (save-excursion
5102 (forward-line -1)
5103 (run-hooks 'gnus-group-update-group-hook)))
5104 (setq loc (1+ loc)))
5105 (unless (or found visible-only)
5106 ;; No such line in the buffer, find out where it's supposed to
5107 ;; go, and insert it there (or at the end of the buffer).
5108 (if gnus-goto-missing-group-function
5109 (funcall gnus-goto-missing-group-function group)
5110 (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
5111 (while (and entry (car entry)
5112 (not
5113 (gnus-goto-char
5114 (text-property-any
5115 (point-min) (point-max)
5116 'gnus-group (gnus-intern-safe
5117 (caar entry) gnus-active-hashtb)))))
5118 (setq entry (cdr entry)))
5119 (or entry (goto-char (point-max)))))
5120 ;; Finally insert the line.
5121 (let ((gnus-group-indentation (gnus-group-group-indentation)))
5122 (gnus-group-insert-group-line-info group)
5123 (save-excursion
5124 (forward-line -1)
5125 (run-hooks 'gnus-group-update-group-hook))))
5126 (gnus-group-set-mode-line)))))
5127
5128 (defun gnus-group-set-mode-line ()
5129 "Update the mode line in the group buffer."
5130 (when (memq 'group gnus-updated-mode-lines)
5131 ;; Yes, we want to keep this mode line updated.
5132 (save-excursion
5133 (set-buffer gnus-group-buffer)
5134 (let* ((gformat (or gnus-group-mode-line-format-spec
5135 (setq gnus-group-mode-line-format-spec
5136 (gnus-parse-format
5137 gnus-group-mode-line-format
5138 gnus-group-mode-line-format-alist))))
5139 (gnus-tmp-news-server (cadr gnus-select-method))
5140 (gnus-tmp-news-method (car gnus-select-method))
5141 (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
5142 (max-len 60)
5143 gnus-tmp-header ;Dummy binding for user-defined formats
5144 ;; Get the resulting string.
5145 (modified
5146 (and gnus-dribble-buffer
5147 (buffer-name gnus-dribble-buffer)
5148 (buffer-modified-p gnus-dribble-buffer)
5149 (save-excursion
5150 (set-buffer gnus-dribble-buffer)
5151 (not (zerop (buffer-size))))))
5152 (mode-string (eval gformat)))
5153 ;; Say whether the dribble buffer has been modified.
5154 (setq mode-line-modified
5155 (if modified "---*- " "----- "))
5156 ;; If the line is too long, we chop it off.
5157 (when (> (length mode-string) max-len)
5158 (setq mode-string (substring mode-string 0 (- max-len 4))))
5159 (prog1
5160 (setq mode-line-buffer-identification
5161 (gnus-mode-line-buffer-identification
5162 (list mode-string)))
5163 (set-buffer-modified-p modified))))))
5164
5165 (defun gnus-group-group-name ()
5166 "Get the name of the newsgroup on the current line."
5167 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
5168 (and group (symbol-name group))))
5169
5170 (defun gnus-group-group-level ()
5171 "Get the level of the newsgroup on the current line."
5172 (get-text-property (gnus-point-at-bol) 'gnus-level))
5173
5174 (defun gnus-group-group-indentation ()
5175 "Get the indentation of the newsgroup on the current line."
5176 (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
5177 (and gnus-group-indentation-function
5178 (funcall gnus-group-indentation-function))
5179 ""))
5180
5181 (defun gnus-group-group-unread ()
5182 "Get the number of unread articles of the newsgroup on the current line."
5183 (get-text-property (gnus-point-at-bol) 'gnus-unread))
5184
5185 (defun gnus-group-search-forward (&optional backward all level first-too)
5186 "Find the next newsgroup with unread articles.
5187 If BACKWARD is non-nil, find the previous newsgroup instead.
5188 If ALL is non-nil, just find any newsgroup.
5189 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
5190 group exists.
5191 If FIRST-TOO, the current line is also eligible as a target."
5192 (let ((way (if backward -1 1))
5193 (low gnus-level-killed)
5194 (beg (point))
5195 pos found lev)
5196 (if (and backward (progn (beginning-of-line)) (bobp))
5197 nil
5198 (or first-too (forward-line way))
5199 (while (and
5200 (not (eobp))
5201 (not (setq
5202 found
5203 (and (or all
5204 (and
5205 (let ((unread
5206 (get-text-property (point) 'gnus-unread)))
5207 (and (numberp unread) (> unread 0)))
5208 (setq lev (get-text-property (point)
5209 'gnus-level))
5210 (<= lev gnus-level-subscribed)))
5211 (or (not level)
5212 (and (setq lev (get-text-property (point)
5213 'gnus-level))
5214 (or (= lev level)
5215 (and (< lev low)
5216 (< level lev)
5217 (progn
5218 (setq low lev)
5219 (setq pos (point))
5220 nil))))))))
5221 (zerop (forward-line way)))))
5222 (if found
5223 (progn (gnus-group-position-point) t)
5224 (goto-char (or pos beg))
5225 (and pos t))))
5226
5227 ;;; Gnus group mode commands
5228
5229 ;; Group marking.
5230
5231 (defun gnus-group-mark-group (n &optional unmark no-advance)
5232 "Mark the current group."
5233 (interactive "p")
5234 (let ((buffer-read-only nil)
5235 group)
5236 (while (and (> n 0)
5237 (not (eobp)))
5238 (when (setq group (gnus-group-group-name))
5239 ;; Update the mark.
5240 (beginning-of-line)
5241 (forward-char
5242 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
5243 (delete-char 1)
5244 (if unmark
5245 (progn
5246 (insert " ")
5247 (setq gnus-group-marked (delete group gnus-group-marked)))
5248 (insert "#")
5249 (setq gnus-group-marked
5250 (cons group (delete group gnus-group-marked)))))
5251 (or no-advance (gnus-group-next-group 1))
5252 (decf n))
5253 (gnus-summary-position-point)
5254 n))
5255
5256 (defun gnus-group-unmark-group (n)
5257 "Remove the mark from the current group."
5258 (interactive "p")
5259 (gnus-group-mark-group n 'unmark)
5260 (gnus-group-position-point))
5261
5262 (defun gnus-group-unmark-all-groups ()
5263 "Unmark all groups."
5264 (interactive)
5265 (let ((groups gnus-group-marked))
5266 (save-excursion
5267 (while groups
5268 (gnus-group-remove-mark (pop groups)))))
5269 (gnus-group-position-point))
5270
5271 (defun gnus-group-mark-region (unmark beg end)
5272 "Mark all groups between point and mark.
5273 If UNMARK, remove the mark instead."
5274 (interactive "P\nr")
5275 (let ((num (count-lines beg end)))
5276 (save-excursion
5277 (goto-char beg)
5278 (- num (gnus-group-mark-group num unmark)))))
5279
5280 (defun gnus-group-mark-buffer (&optional unmark)
5281 "Mark all groups in the buffer.
5282 If UNMARK, remove the mark instead."
5283 (interactive "P")
5284 (gnus-group-mark-region unmark (point-min) (point-max)))
5285
5286 (defun gnus-group-mark-regexp (regexp)
5287 "Mark all groups that match some regexp."
5288 (interactive "sMark (regexp): ")
5289 (let ((alist (cdr gnus-newsrc-alist))
5290 group)
5291 (while alist
5292 (when (string-match regexp (setq group (gnus-info-group (pop alist))))
5293 (gnus-group-set-mark group))))
5294 (gnus-group-position-point))
5295
5296 (defun gnus-group-remove-mark (group)
5297 "Remove the process mark from GROUP and move point there.
5298 Return nil if the group isn't displayed."
5299 (if (gnus-group-goto-group group)
5300 (save-excursion
5301 (gnus-group-mark-group 1 'unmark t)
5302 t)
5303 (setq gnus-group-marked
5304 (delete group gnus-group-marked))
5305 nil))
5306
5307 (defun gnus-group-set-mark (group)
5308 "Set the process mark on GROUP."
5309 (if (gnus-group-goto-group group)
5310 (save-excursion
5311 (gnus-group-mark-group 1 nil t))
5312 (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
5313
5314 (defun gnus-group-universal-argument (arg &optional groups func)
5315 "Perform any command on all groups accoring to the process/prefix convention."
5316 (interactive "P")
5317 (let ((groups (or groups (gnus-group-process-prefix arg)))
5318 group func)
5319 (if (eq (setq func (or func
5320 (key-binding
5321 (read-key-sequence
5322 (substitute-command-keys
5323 "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
5324 'undefined)
5325 (gnus-error 1 "Undefined key")
5326 (while groups
5327 (gnus-group-remove-mark (setq group (pop groups)))
5328 (command-execute func))))
5329 (gnus-group-position-point))
5330
5331 (defun gnus-group-process-prefix (n)
5332 "Return a list of groups to work on.
5333 Take into consideration N (the prefix) and the list of marked groups."
5334 (cond
5335 (n
5336 (setq n (prefix-numeric-value n))
5337 ;; There is a prefix, so we return a list of the N next
5338 ;; groups.
5339 (let ((way (if (< n 0) -1 1))
5340 (n (abs n))
5341 group groups)
5342 (save-excursion
5343 (while (and (> n 0)
5344 (setq group (gnus-group-group-name)))
5345 (setq groups (cons group groups))
5346 (setq n (1- n))
5347 (gnus-group-next-group way)))
5348 (nreverse groups)))
5349 ((and (boundp 'transient-mark-mode)
5350 transient-mark-mode
5351 (boundp 'mark-active)
5352 mark-active)
5353 ;; Work on the region between point and mark.
5354 (let ((max (max (point) (mark)))
5355 groups)
5356 (save-excursion
5357 (goto-char (min (point) (mark)))
5358 (while
5359 (and
5360 (push (gnus-group-group-name) groups)
5361 (zerop (gnus-group-next-group 1))
5362 (< (point) max)))
5363 (nreverse groups))))
5364 (gnus-group-marked
5365 ;; No prefix, but a list of marked articles.
5366 (reverse gnus-group-marked))
5367 (t
5368 ;; Neither marked articles or a prefix, so we return the
5369 ;; current group.
5370 (let ((group (gnus-group-group-name)))
5371 (and group (list group))))))
5372
5373 ;; Selecting groups.
5374
5375 (defun gnus-group-read-group (&optional all no-article group)
5376 "Read news in this newsgroup.
5377 If the prefix argument ALL is non-nil, already read articles become
5378 readable. IF ALL is a number, fetch this number of articles. If the
5379 optional argument NO-ARTICLE is non-nil, no article will be
5380 auto-selected upon group entry. If GROUP is non-nil, fetch that
5381 group."
5382 (interactive "P")
5383 (let ((group (or group (gnus-group-group-name)))
5384 number active marked entry)
5385 (or group (error "No group on current line"))
5386 (setq marked (nth 3 (nth 2 (setq entry (gnus-gethash
5387 group gnus-newsrc-hashtb)))))
5388 ;; This group might be a dead group. In that case we have to get
5389 ;; the number of unread articles from `gnus-active-hashtb'.
5390 (setq number
5391 (cond ((numberp all) all)
5392 (entry (car entry))
5393 ((setq active (gnus-active group))
5394 (- (1+ (cdr active)) (car active)))))
5395 (gnus-summary-read-group
5396 group (or all (and (numberp number)
5397 (zerop (+ number (gnus-range-length
5398 (cdr (assq 'tick marked)))
5399 (gnus-range-length
5400 (cdr (assq 'dormant marked)))))))
5401 no-article)))
5402
5403 (defun gnus-group-select-group (&optional all)
5404 "Select this newsgroup.
5405 No article is selected automatically.
5406 If ALL is non-nil, already read articles become readable.
5407 If ALL is a number, fetch this number of articles."
5408 (interactive "P")
5409 (gnus-group-read-group all t))
5410
5411 (defun gnus-group-quick-select-group (&optional all)
5412 "Select the current group \"quickly\".
5413 This means that no highlighting or scoring will be performed."
5414 (interactive "P")
5415 (let (gnus-visual
5416 gnus-score-find-score-files-function
5417 gnus-apply-kill-hook
5418 gnus-summary-expunge-below)
5419 (gnus-group-read-group all t)))
5420
5421 (defun gnus-group-visible-select-group (&optional all)
5422 "Select the current group without hiding any articles."
5423 (interactive "P")
5424 (let ((gnus-inhibit-limiting t))
5425 (gnus-group-read-group all t)))
5426
5427 ;;;###autoload
5428 (defun gnus-fetch-group (group)
5429 "Start Gnus if necessary and enter GROUP.
5430 Returns whether the fetching was successful or not."
5431 (interactive "sGroup name: ")
5432 (or (get-buffer gnus-group-buffer)
5433 (gnus))
5434 (gnus-group-read-group nil nil group))
5435
5436 ;; Enter a group that is not in the group buffer. Non-nil is returned
5437 ;; if selection was successful.
5438 (defun gnus-group-read-ephemeral-group
5439 (group method &optional activate quit-config)
5440 (let ((group (if (gnus-group-foreign-p group) group
5441 (gnus-group-prefixed-name group method))))
5442 (gnus-sethash
5443 group
5444 `(t nil (,group ,gnus-level-default-subscribed nil nil ,method
5445 ((quit-config . ,(if quit-config quit-config
5446 (cons (current-buffer) 'summary))))))
5447 gnus-newsrc-hashtb)
5448 (set-buffer gnus-group-buffer)
5449 (or (gnus-check-server method)
5450 (error "Unable to contact server: %s" (gnus-status-message method)))
5451 (if activate (or (gnus-request-group group)
5452 (error "Couldn't request group")))
5453 (condition-case ()
5454 (gnus-group-read-group t t group)
5455 (error nil)
5456 (quit nil))))
5457
5458 (defun gnus-group-jump-to-group (group)
5459 "Jump to newsgroup GROUP."
5460 (interactive
5461 (list (completing-read
5462 "Group: " gnus-active-hashtb nil
5463 (gnus-read-active-file-p)
5464 nil
5465 'gnus-group-history)))
5466
5467 (when (equal group "")
5468 (error "Empty group name"))
5469
5470 (when (string-match "[\000-\032]" group)
5471 (error "Control characters in group: %s" group))
5472
5473 (let ((b (text-property-any
5474 (point-min) (point-max)
5475 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
5476 (unless (gnus-ephemeral-group-p group)
5477 (if b
5478 ;; Either go to the line in the group buffer...
5479 (goto-char b)
5480 ;; ... or insert the line.
5481 (or
5482 (gnus-active group)
5483 (gnus-activate-group group)
5484 (error "%s error: %s" group (gnus-status-message group)))
5485
5486 (gnus-group-update-group group)
5487 (goto-char (text-property-any
5488 (point-min) (point-max)
5489 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))
5490 ;; Adjust cursor point.
5491 (gnus-group-position-point)))
5492
5493 (defun gnus-group-goto-group (group)
5494 "Goto to newsgroup GROUP."
5495 (when group
5496 (let ((b (text-property-any (point-min) (point-max)
5497 'gnus-group (gnus-intern-safe
5498 group gnus-active-hashtb))))
5499 (and b (goto-char b)))))
5500
5501 (defun gnus-group-next-group (n)
5502 "Go to next N'th newsgroup.
5503 If N is negative, search backward instead.
5504 Returns the difference between N and the number of skips actually
5505 done."
5506 (interactive "p")
5507 (gnus-group-next-unread-group n t))
5508
5509 (defun gnus-group-next-unread-group (n &optional all level)
5510 "Go to next N'th unread newsgroup.
5511 If N is negative, search backward instead.
5512 If ALL is non-nil, choose any newsgroup, unread or not.
5513 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
5514 such group can be found, the next group with a level higher than
5515 LEVEL.
5516 Returns the difference between N and the number of skips actually
5517 made."
5518 (interactive "p")
5519 (let ((backward (< n 0))
5520 (n (abs n)))
5521 (while (and (> n 0)
5522 (gnus-group-search-forward
5523 backward (or (not gnus-group-goto-unread) all) level))
5524 (setq n (1- n)))
5525 (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
5526 (if level " on this level or higher" "")))
5527 n))
5528
5529 (defun gnus-group-prev-group (n)
5530 "Go to previous N'th newsgroup.
5531 Returns the difference between N and the number of skips actually
5532 done."
5533 (interactive "p")
5534 (gnus-group-next-unread-group (- n) t))
5535
5536 (defun gnus-group-prev-unread-group (n)
5537 "Go to previous N'th unread newsgroup.
5538 Returns the difference between N and the number of skips actually
5539 done."
5540 (interactive "p")
5541 (gnus-group-next-unread-group (- n)))
5542
5543 (defun gnus-group-next-unread-group-same-level (n)
5544 "Go to next N'th unread newsgroup on the same level.
5545 If N is negative, search backward instead.
5546 Returns the difference between N and the number of skips actually
5547 done."
5548 (interactive "p")
5549 (gnus-group-next-unread-group n t (gnus-group-group-level))
5550 (gnus-group-position-point))
5551
5552 (defun gnus-group-prev-unread-group-same-level (n)
5553 "Go to next N'th unread newsgroup on the same level.
5554 Returns the difference between N and the number of skips actually
5555 done."
5556 (interactive "p")
5557 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
5558 (gnus-group-position-point))
5559
5560 (defun gnus-group-best-unread-group (&optional exclude-group)
5561 "Go to the group with the highest level.
5562 If EXCLUDE-GROUP, do not go to that group."
5563 (interactive)
5564 (goto-char (point-min))
5565 (let ((best 100000)
5566 unread best-point)
5567 (while (not (eobp))
5568 (setq unread (get-text-property (point) 'gnus-unread))
5569 (if (and (numberp unread) (> unread 0))
5570 (progn
5571 (if (and (get-text-property (point) 'gnus-level)
5572 (< (get-text-property (point) 'gnus-level) best)
5573 (or (not exclude-group)
5574 (not (equal exclude-group (gnus-group-group-name)))))
5575 (progn
5576 (setq best (get-text-property (point) 'gnus-level))
5577 (setq best-point (point))))))
5578 (forward-line 1))
5579 (if best-point (goto-char best-point))
5580 (gnus-summary-position-point)
5581 (and best-point (gnus-group-group-name))))
5582
5583 (defun gnus-group-first-unread-group ()
5584 "Go to the first group with unread articles."
5585 (interactive)
5586 (prog1
5587 (let ((opoint (point))
5588 unread)
5589 (goto-char (point-min))
5590 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
5591 (and (numberp unread) ; Not a topic.
5592 (not (zerop unread))) ; Has unread articles.
5593 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
5594 (point) ; Success.
5595 (goto-char opoint)
5596 nil)) ; Not success.
5597 (gnus-group-position-point)))
5598
5599 (defun gnus-group-enter-server-mode ()
5600 "Jump to the server buffer."
5601 (interactive)
5602 (gnus-enter-server-buffer))
5603
5604 (defun gnus-group-make-group (name &optional method address)
5605 "Add a new newsgroup.
5606 The user will be prompted for a NAME, for a select METHOD, and an
5607 ADDRESS."
5608 (interactive
5609 (cons
5610 (read-string "Group name: ")
5611 (let ((method
5612 (completing-read
5613 "Method: " (append gnus-valid-select-methods gnus-server-alist)
5614 nil t nil 'gnus-method-history)))
5615 (cond ((assoc method gnus-valid-select-methods)
5616 (list method
5617 (if (memq 'prompt-address
5618 (assoc method gnus-valid-select-methods))
5619 (read-string "Address: ")
5620 "")))
5621 ((assoc method gnus-server-alist)
5622 (list method))
5623 (t
5624 (list method ""))))))
5625
5626 (let* ((meth (and method (if address (list (intern method) address)
5627 method)))
5628 (nname (if method (gnus-group-prefixed-name name meth) name))
5629 backend info)
5630 (when (gnus-gethash nname gnus-newsrc-hashtb)
5631 (error "Group %s already exists" nname))
5632 ;; Subscribe to the new group.
5633 (gnus-group-change-level
5634 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
5635 gnus-level-default-subscribed gnus-level-killed
5636 (and (gnus-group-group-name)
5637 (gnus-gethash (gnus-group-group-name)
5638 gnus-newsrc-hashtb))
5639 t)
5640 ;; Make it active.
5641 (gnus-set-active nname (cons 1 0))
5642 (or (gnus-ephemeral-group-p name)
5643 (gnus-dribble-enter
5644 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
5645 ;; Insert the line.
5646 (gnus-group-insert-group-line-info nname)
5647 (forward-line -1)
5648 (gnus-group-position-point)
5649
5650 ;; Load the backend and try to make the backend create
5651 ;; the group as well.
5652 (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
5653 nil meth))))
5654 gnus-valid-select-methods)
5655 (require backend))
5656 (gnus-check-server meth)
5657 (and (gnus-check-backend-function 'request-create-group nname)
5658 (gnus-request-create-group nname))
5659 t))
5660
5661 (defun gnus-group-delete-group (group &optional force)
5662 "Delete the current group. Only meaningful with mail groups.
5663 If FORCE (the prefix) is non-nil, all the articles in the group will
5664 be deleted. This is \"deleted\" as in \"removed forever from the face
5665 of the Earth\". There is no undo. The user will be prompted before
5666 doing the deletion."
5667 (interactive
5668 (list (gnus-group-group-name)
5669 current-prefix-arg))
5670 (or group (error "No group to rename"))
5671 (or (gnus-check-backend-function 'request-delete-group group)
5672 (error "This backend does not support group deletion"))
5673 (prog1
5674 (if (not (gnus-yes-or-no-p
5675 (format
5676 "Do you really want to delete %s%s? "
5677 group (if force " and all its contents" ""))))
5678 () ; Whew!
5679 (gnus-message 6 "Deleting group %s..." group)
5680 (if (not (gnus-request-delete-group group force))
5681 (gnus-error 3 "Couldn't delete group %s" group)
5682 (gnus-message 6 "Deleting group %s...done" group)
5683 (gnus-group-goto-group group)
5684 (gnus-group-kill-group 1 t)
5685 (gnus-sethash group nil gnus-active-hashtb)
5686 t))
5687 (gnus-group-position-point)))
5688
5689 (defun gnus-group-rename-group (group new-name)
5690 (interactive
5691 (list
5692 (gnus-group-group-name)
5693 (progn
5694 (or (gnus-check-backend-function
5695 'request-rename-group (gnus-group-group-name))
5696 (error "This backend does not support renaming groups"))
5697 (read-string "New group name: "))))
5698
5699 (or (gnus-check-backend-function 'request-rename-group group)
5700 (error "This backend does not support renaming groups"))
5701
5702 (or group (error "No group to rename"))
5703 (and (string-match "^[ \t]*$" new-name)
5704 (error "Not a valid group name"))
5705
5706 ;; We find the proper prefixed name.
5707 (setq new-name
5708 (gnus-group-prefixed-name
5709 (gnus-group-real-name new-name)
5710 (gnus-info-method (gnus-get-info group))))
5711
5712 (gnus-message 6 "Renaming group %s to %s..." group new-name)
5713 (prog1
5714 (if (not (gnus-request-rename-group group new-name))
5715 (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
5716 ;; We rename the group internally by killing it...
5717 (gnus-group-goto-group group)
5718 (gnus-group-kill-group)
5719 ;; ... changing its name ...
5720 (setcar (cdar gnus-list-of-killed-groups) new-name)
5721 ;; ... and then yanking it. Magic!
5722 (gnus-group-yank-group)
5723 (gnus-set-active new-name (gnus-active group))
5724 (gnus-message 6 "Renaming group %s to %s...done" group new-name)
5725 new-name)
5726 (gnus-group-position-point)))
5727
5728 (defun gnus-group-edit-group (group &optional part)
5729 "Edit the group on the current line."
5730 (interactive (list (gnus-group-group-name)))
5731 (let* ((part (or part 'info))
5732 (done-func `(lambda ()
5733 "Exit editing mode and update the information."
5734 (interactive)
5735 (gnus-group-edit-group-done ',part ,group)))
5736 (winconf (current-window-configuration))
5737 info)
5738 (or group (error "No group on current line"))
5739 (or (setq info (gnus-get-info group))
5740 (error "Killed group; can't be edited"))
5741 (set-buffer (get-buffer-create gnus-group-edit-buffer))
5742 (gnus-configure-windows 'edit-group)
5743 (gnus-add-current-to-buffer-list)
5744 (emacs-lisp-mode)
5745 ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
5746 (use-local-map (copy-keymap emacs-lisp-mode-map))
5747 (local-set-key "\C-c\C-c" done-func)
5748 (make-local-variable 'gnus-prev-winconf)
5749 (setq gnus-prev-winconf winconf)
5750 (erase-buffer)
5751 (insert
5752 (cond
5753 ((eq part 'method)
5754 ";; Type `C-c C-c' after editing the select method.\n\n")
5755 ((eq part 'params)
5756 ";; Type `C-c C-c' after editing the group parameters.\n\n")
5757 ((eq part 'info)
5758 ";; Type `C-c C-c' after editing the group info.\n\n")))
5759 (insert
5760 (pp-to-string
5761 (cond ((eq part 'method)
5762 (or (gnus-info-method info) "native"))
5763 ((eq part 'params)
5764 (gnus-info-params info))
5765 (t info)))
5766 "\n")))
5767
5768 (defun gnus-group-edit-group-method (group)
5769 "Edit the select method of GROUP."
5770 (interactive (list (gnus-group-group-name)))
5771 (gnus-group-edit-group group 'method))
5772
5773 (defun gnus-group-edit-group-parameters (group)
5774 "Edit the group parameters of GROUP."
5775 (interactive (list (gnus-group-group-name)))
5776 (gnus-group-edit-group group 'params))
5777
5778 (defun gnus-group-edit-group-done (part group)
5779 "Get info from buffer, update variables and jump to the group buffer."
5780 (set-buffer (get-buffer-create gnus-group-edit-buffer))
5781 (goto-char (point-min))
5782 (let* ((form (read (current-buffer)))
5783 (winconf gnus-prev-winconf)
5784 (method (cond ((eq part 'info) (nth 4 form))
5785 ((eq part 'method) form)
5786 (t nil)))
5787 (info (cond ((eq part 'info) form)
5788 ((eq part 'method) (gnus-get-info group))
5789 (t nil)))
5790 (new-group (if info
5791 (if (or (not method)
5792 (gnus-server-equal
5793 gnus-select-method method))
5794 (gnus-group-real-name (car info))
5795 (gnus-group-prefixed-name
5796 (gnus-group-real-name (car info)) method))
5797 nil)))
5798 (when (and new-group
5799 (not (equal new-group group)))
5800 (when (gnus-group-goto-group group)
5801 (gnus-group-kill-group 1))
5802 (gnus-activate-group new-group))
5803 ;; Set the info.
5804 (if (and info new-group)
5805 (progn
5806 (setq info (gnus-copy-sequence info))
5807 (setcar info new-group)
5808 (unless (gnus-server-equal method "native")
5809 (unless (nthcdr 3 info)
5810 (nconc info (list nil nil)))
5811 (unless (nthcdr 4 info)
5812 (nconc info (list nil)))
5813 (gnus-info-set-method info method))
5814 (gnus-group-set-info info))
5815 (gnus-group-set-info form (or new-group group) part))
5816 (kill-buffer (current-buffer))
5817 (and winconf (set-window-configuration winconf))
5818 (set-buffer gnus-group-buffer)
5819 (gnus-group-update-group (or new-group group))
5820 (gnus-group-position-point)))
5821
5822 (defun gnus-group-make-help-group ()
5823 "Create the Gnus documentation group."
5824 (interactive)
5825 (let ((path load-path)
5826 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
5827 file dir)
5828 (and (gnus-gethash name gnus-newsrc-hashtb)
5829 (error "Documentation group already exists"))
5830 (while path
5831 (setq dir (file-name-as-directory (expand-file-name (pop path)))
5832 file nil)
5833 (when (or (file-exists-p (setq file (concat dir "gnus-tut.txt")))
5834 (file-exists-p
5835 (setq file (concat (file-name-directory
5836 (directory-file-name dir))
5837 "etc/gnus-tut.txt"))))
5838 (setq path nil)))
5839 (if (not file)
5840 (gnus-message 1 "Couldn't find doc group")
5841 (gnus-group-make-group
5842 (gnus-group-real-name name)
5843 (list 'nndoc "gnus-help"
5844 (list 'nndoc-address file)
5845 (list 'nndoc-article-type 'mbox)))))
5846 (gnus-group-position-point))
5847
5848 (defun gnus-group-make-doc-group (file type)
5849 "Create a group that uses a single file as the source."
5850 (interactive
5851 (list (read-file-name "File name: ")
5852 (and current-prefix-arg 'ask)))
5853 (when (eq type 'ask)
5854 (let ((err "")
5855 char found)
5856 (while (not found)
5857 (message
5858 "%sFile type (mbox, babyl, digest, forward, mmfd, guess) [mbdfag]: "
5859 err)
5860 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
5861 ((= char ?b) 'babyl)
5862 ((= char ?d) 'digest)
5863 ((= char ?f) 'forward)
5864 ((= char ?a) 'mmfd)
5865 (t (setq err (format "%c unknown. " char))
5866 nil))))
5867 (setq type found)))
5868 (let* ((file (expand-file-name file))
5869 (name (gnus-generate-new-group-name
5870 (gnus-group-prefixed-name
5871 (file-name-nondirectory file) '(nndoc "")))))
5872 (gnus-group-make-group
5873 (gnus-group-real-name name)
5874 (list 'nndoc (file-name-nondirectory file)
5875 (list 'nndoc-address file)
5876 (list 'nndoc-article-type (or type 'guess))))))
5877
5878 (defun gnus-group-make-archive-group (&optional all)
5879 "Create the (ding) Gnus archive group of the most recent articles.
5880 Given a prefix, create a full group."
5881 (interactive "P")
5882 (let ((group (gnus-group-prefixed-name
5883 (if all "ding.archives" "ding.recent") '(nndir ""))))
5884 (and (gnus-gethash group gnus-newsrc-hashtb)
5885 (error "Archive group already exists"))
5886 (gnus-group-make-group
5887 (gnus-group-real-name group)
5888 (list 'nndir (if all "hpc" "edu")
5889 (list 'nndir-directory
5890 (if all gnus-group-archive-directory
5891 gnus-group-recent-archive-directory))))))
5892
5893 (defun gnus-group-make-directory-group (dir)
5894 "Create an nndir group.
5895 The user will be prompted for a directory. The contents of this
5896 directory will be used as a newsgroup. The directory should contain
5897 mail messages or news articles in files that have numeric names."
5898 (interactive
5899 (list (read-file-name "Create group from directory: ")))
5900 (or (file-exists-p dir) (error "No such directory"))
5901 (or (file-directory-p dir) (error "Not a directory"))
5902 (let ((ext "")
5903 (i 0)
5904 group)
5905 (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
5906 (setq group
5907 (gnus-group-prefixed-name
5908 (concat (file-name-as-directory (directory-file-name dir))
5909 ext)
5910 '(nndir "")))
5911 (setq ext (format "<%d>" (setq i (1+ i)))))
5912 (gnus-group-make-group
5913 (gnus-group-real-name group)
5914 (list 'nndir group (list 'nndir-directory dir)))))
5915
5916 (defun gnus-group-make-kiboze-group (group address scores)
5917 "Create an nnkiboze group.
5918 The user will be prompted for a name, a regexp to match groups, and
5919 score file entries for articles to include in the group."
5920 (interactive
5921 (list
5922 (read-string "nnkiboze group name: ")
5923 (read-string "Source groups (regexp): ")
5924 (let ((headers (mapcar (lambda (group) (list group))
5925 '("subject" "from" "number" "date" "message-id"
5926 "references" "chars" "lines" "xref"
5927 "followup" "all" "body" "head")))
5928 scores header regexp regexps)
5929 (while (not (equal "" (setq header (completing-read
5930 "Match on header: " headers nil t))))
5931 (setq regexps nil)
5932 (while (not (equal "" (setq regexp (read-string
5933 (format "Match on %s (string): "
5934 header)))))
5935 (setq regexps (cons (list regexp nil nil 'r) regexps)))
5936 (setq scores (cons (cons header regexps) scores)))
5937 scores)))
5938 (gnus-group-make-group group "nnkiboze" address)
5939 (nnheader-temp-write (gnus-score-file-name (concat "nnkiboze:" group))
5940 (let (emacs-lisp-mode-hook)
5941 (pp scores (current-buffer)))))
5942
5943 (defun gnus-group-add-to-virtual (n vgroup)
5944 "Add the current group to a virtual group."
5945 (interactive
5946 (list current-prefix-arg
5947 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
5948 "nnvirtual:")))
5949 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
5950 (error "%s is not an nnvirtual group" vgroup))
5951 (let* ((groups (gnus-group-process-prefix n))
5952 (method (gnus-info-method (gnus-get-info vgroup))))
5953 (setcar (cdr method)
5954 (concat
5955 (nth 1 method) "\\|"
5956 (mapconcat
5957 (lambda (s)
5958 (gnus-group-remove-mark s)
5959 (concat "\\(^" (regexp-quote s) "$\\)"))
5960 groups "\\|"))))
5961 (gnus-group-position-point))
5962
5963 (defun gnus-group-make-empty-virtual (group)
5964 "Create a new, fresh, empty virtual group."
5965 (interactive "sCreate new, empty virtual group: ")
5966 (let* ((method (list 'nnvirtual "^$"))
5967 (pgroup (gnus-group-prefixed-name group method)))
5968 ;; Check whether it exists already.
5969 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
5970 (error "Group %s already exists." pgroup))
5971 ;; Subscribe the new group after the group on the current line.
5972 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
5973 (gnus-group-update-group pgroup)
5974 (forward-line -1)
5975 (gnus-group-position-point)))
5976
5977 (defun gnus-group-enter-directory (dir)
5978 "Enter an ephemeral nneething group."
5979 (interactive "DDirectory to read: ")
5980 (let* ((method (list 'nneething dir '(nneething-read-only t)))
5981 (leaf (gnus-group-prefixed-name
5982 (file-name-nondirectory (directory-file-name dir))
5983 method))
5984 (name (gnus-generate-new-group-name leaf)))
5985 (unless (gnus-group-read-ephemeral-group
5986 name method t
5987 (cons (current-buffer)
5988 (if (eq major-mode 'gnus-summary-mode)
5989 'summary 'group)))
5990 (error "Couldn't enter %s" dir))))
5991
5992 ;; Group sorting commands
5993 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
5994
5995 (defun gnus-group-sort-groups (func &optional reverse)
5996 "Sort the group buffer according to FUNC.
5997 If REVERSE, reverse the sorting order."
5998 (interactive (list gnus-group-sort-function
5999 current-prefix-arg))
6000 (let ((func (cond
6001 ((not (listp func)) func)
6002 ((null func) func)
6003 ((= 1 (length func)) (car func))
6004 (t `(lambda (t1 t2)
6005 ,(gnus-make-sort-function
6006 (reverse func)))))))
6007 ;; We peel off the dummy group from the alist.
6008 (when func
6009 (when (equal (car (gnus-info-group gnus-newsrc-alist)) "dummy.group")
6010 (pop gnus-newsrc-alist))
6011 ;; Do the sorting.
6012 (setq gnus-newsrc-alist
6013 (sort gnus-newsrc-alist func))
6014 (when reverse
6015 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
6016 ;; Regenerate the hash table.
6017 (gnus-make-hashtable-from-newsrc-alist)
6018 (gnus-group-list-groups))))
6019
6020 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
6021 "Sort the group buffer alphabetically by group name.
6022 If REVERSE, sort in reverse order."
6023 (interactive "P")
6024 (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
6025
6026 (defun gnus-group-sort-groups-by-unread (&optional reverse)
6027 "Sort the group buffer by number of unread articles.
6028 If REVERSE, sort in reverse order."
6029 (interactive "P")
6030 (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
6031
6032 (defun gnus-group-sort-groups-by-level (&optional reverse)
6033 "Sort the group buffer by group level.
6034 If REVERSE, sort in reverse order."
6035 (interactive "P")
6036 (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
6037
6038 (defun gnus-group-sort-groups-by-score (&optional reverse)
6039 "Sort the group buffer by group score.
6040 If REVERSE, sort in reverse order."
6041 (interactive "P")
6042 (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
6043
6044 (defun gnus-group-sort-groups-by-rank (&optional reverse)
6045 "Sort the group buffer by group rank.
6046 If REVERSE, sort in reverse order."
6047 (interactive "P")
6048 (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
6049
6050 (defun gnus-group-sort-groups-by-method (&optional reverse)
6051 "Sort the group buffer alphabetically by backend name.
6052 If REVERSE, sort in reverse order."
6053 (interactive "P")
6054 (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
6055
6056 (defun gnus-group-sort-by-alphabet (info1 info2)
6057 "Sort alphabetically."
6058 (string< (gnus-info-group info1) (gnus-info-group info2)))
6059
6060 (defun gnus-group-sort-by-unread (info1 info2)
6061 "Sort by number of unread articles."
6062 (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
6063 (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
6064 (< (or (and (numberp n1) n1) 0)
6065 (or (and (numberp n2) n2) 0))))
6066
6067 (defun gnus-group-sort-by-level (info1 info2)
6068 "Sort by level."
6069 (< (gnus-info-level info1) (gnus-info-level info2)))
6070
6071 (defun gnus-group-sort-by-method (info1 info2)
6072 "Sort alphabetically by backend name."
6073 (string< (symbol-name (car (gnus-find-method-for-group
6074 (gnus-info-group info1) info1)))
6075 (symbol-name (car (gnus-find-method-for-group
6076 (gnus-info-group info2) info2)))))
6077
6078 (defun gnus-group-sort-by-score (info1 info2)
6079 "Sort by group score."
6080 (< (gnus-info-score info1) (gnus-info-score info2)))
6081
6082 (defun gnus-group-sort-by-rank (info1 info2)
6083 "Sort by level and score."
6084 (let ((level1 (gnus-info-level info1))
6085 (level2 (gnus-info-level info2)))
6086 (or (< level1 level2)
6087 (and (= level1 level2)
6088 (> (gnus-info-score info1) (gnus-info-score info2))))))
6089
6090 ;; Group catching up.
6091
6092 (defun gnus-group-clear-data (n)
6093 "Clear all marks and read ranges from the current group."
6094 (interactive "P")
6095 (let ((groups (gnus-group-process-prefix n))
6096 group info)
6097 (while (setq group (pop groups))
6098 (setq info (gnus-get-info group))
6099 (gnus-info-set-read info nil)
6100 (when (gnus-info-marks info)
6101 (gnus-info-set-marks info nil))
6102 (gnus-get-unread-articles-in-group info (gnus-active group) t)
6103 (when (gnus-group-goto-group group)
6104 (gnus-group-remove-mark group)
6105 (gnus-group-update-group-line)))))
6106
6107 (defun gnus-group-catchup-current (&optional n all)
6108 "Mark all articles not marked as unread in current newsgroup as read.
6109 If prefix argument N is numeric, the ARG next newsgroups will be
6110 caught up. If ALL is non-nil, marked articles will also be marked as
6111 read. Cross references (Xref: header) of articles are ignored.
6112 The difference between N and actual number of newsgroups that were
6113 caught up is returned."
6114 (interactive "P")
6115 (unless (gnus-group-group-name)
6116 (error "No group on the current line"))
6117 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
6118 gnus-expert-user
6119 (gnus-y-or-n-p
6120 (if all
6121 "Do you really want to mark all articles as read? "
6122 "Mark all unread articles as read? "))))
6123 n
6124 (let ((groups (gnus-group-process-prefix n))
6125 (ret 0))
6126 (while groups
6127 ;; Virtual groups have to be given special treatment.
6128 (let ((method (gnus-find-method-for-group (car groups))))
6129 (if (eq 'nnvirtual (car method))
6130 (nnvirtual-catchup-group
6131 (gnus-group-real-name (car groups)) (nth 1 method) all)))
6132 (gnus-group-remove-mark (car groups))
6133 (if (>= (gnus-group-group-level) gnus-level-zombie)
6134 (gnus-message 2 "Dead groups can't be caught up")
6135 (if (prog1
6136 (gnus-group-goto-group (car groups))
6137 (gnus-group-catchup (car groups) all))
6138 (gnus-group-update-group-line)
6139 (setq ret (1+ ret))))
6140 (setq groups (cdr groups)))
6141 (gnus-group-next-unread-group 1)
6142 ret)))
6143
6144 (defun gnus-group-catchup-current-all (&optional n)
6145 "Mark all articles in current newsgroup as read.
6146 Cross references (Xref: header) of articles are ignored."
6147 (interactive "P")
6148 (gnus-group-catchup-current n 'all))
6149
6150 (defun gnus-group-catchup (group &optional all)
6151 "Mark all articles in GROUP as read.
6152 If ALL is non-nil, all articles are marked as read.
6153 The return value is the number of articles that were marked as read,
6154 or nil if no action could be taken."
6155 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
6156 (num (car entry)))
6157 ;; Do the updating only if the newsgroup isn't killed.
6158 (if (not (numberp (car entry)))
6159 (gnus-message 1 "Can't catch up; non-active group")
6160 ;; Do auto-expirable marks if that's required.
6161 (when (gnus-group-auto-expirable-p group)
6162 (gnus-add-marked-articles
6163 group 'expire (gnus-list-of-unread-articles group))
6164 (when all
6165 (let ((marks (nth 3 (nth 2 entry))))
6166 (gnus-add-marked-articles
6167 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
6168 (gnus-add-marked-articles
6169 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
6170 (when entry
6171 (gnus-update-read-articles group nil)
6172 ;; Also nix out the lists of marks and dormants.
6173 (when all
6174 (gnus-add-marked-articles group 'tick nil nil 'force)
6175 (gnus-add-marked-articles group 'dormant nil nil 'force))
6176 (run-hooks 'gnus-group-catchup-group-hook)
6177 num))))
6178
6179 (defun gnus-group-expire-articles (&optional n)
6180 "Expire all expirable articles in the current newsgroup."
6181 (interactive "P")
6182 (let ((groups (gnus-group-process-prefix n))
6183 group)
6184 (unless groups
6185 (error "No groups to expire"))
6186 (while (setq group (pop groups))
6187 (gnus-group-remove-mark group)
6188 (when (gnus-check-backend-function 'request-expire-articles group)
6189 (gnus-message 6 "Expiring articles in %s..." group)
6190 (let* ((info (gnus-get-info group))
6191 (expirable (if (gnus-group-total-expirable-p group)
6192 (cons nil (gnus-list-of-read-articles group))
6193 (assq 'expire (gnus-info-marks info))))
6194 (expiry-wait (gnus-group-get-parameter group 'expiry-wait)))
6195 (when expirable
6196 (setcdr
6197 expirable
6198 (gnus-compress-sequence
6199 (if expiry-wait
6200 ;; We set the expiry variables to the groupp
6201 ;; parameter.
6202 (let ((nnmail-expiry-wait-function nil)
6203 (nnmail-expiry-wait expiry-wait))
6204 (gnus-request-expire-articles
6205 (gnus-uncompress-sequence (cdr expirable)) group))
6206 ;; Just expire using the normal expiry values.
6207 (gnus-request-expire-articles
6208 (gnus-uncompress-sequence (cdr expirable)) group))))
6209 (gnus-close-group group))
6210 (gnus-message 6 "Expiring articles in %s...done" group)))
6211 (gnus-group-position-point))))
6212
6213 (defun gnus-group-expire-all-groups ()
6214 "Expire all expirable articles in all newsgroups."
6215 (interactive)
6216 (save-excursion
6217 (gnus-message 5 "Expiring...")
6218 (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
6219 (cdr gnus-newsrc-alist))))
6220 (gnus-group-expire-articles nil)))
6221 (gnus-group-position-point)
6222 (gnus-message 5 "Expiring...done"))
6223
6224 (defun gnus-group-set-current-level (n level)
6225 "Set the level of the next N groups to LEVEL."
6226 (interactive
6227 (list
6228 current-prefix-arg
6229 (string-to-int
6230 (let ((s (read-string
6231 (format "Level (default %s): "
6232 (or (gnus-group-group-level)
6233 gnus-level-default-subscribed)))))
6234 (if (string-match "^\\s-*$" s)
6235 (int-to-string (or (gnus-group-group-level)
6236 gnus-level-default-subscribed))
6237 s)))))
6238 (or (and (>= level 1) (<= level gnus-level-killed))
6239 (error "Illegal level: %d" level))
6240 (let ((groups (gnus-group-process-prefix n))
6241 group)
6242 (while (setq group (pop groups))
6243 (gnus-group-remove-mark group)
6244 (gnus-message 6 "Changed level of %s from %d to %d"
6245 group (or (gnus-group-group-level) gnus-level-killed)
6246 level)
6247 (gnus-group-change-level
6248 group level (or (gnus-group-group-level) gnus-level-killed))
6249 (gnus-group-update-group-line)))
6250 (gnus-group-position-point))
6251
6252 (defun gnus-group-unsubscribe-current-group (&optional n)
6253 "Toggle subscription of the current group.
6254 If given numerical prefix, toggle the N next groups."
6255 (interactive "P")
6256 (let ((groups (gnus-group-process-prefix n))
6257 group)
6258 (while groups
6259 (setq group (car groups)
6260 groups (cdr groups))
6261 (gnus-group-remove-mark group)
6262 (gnus-group-unsubscribe-group
6263 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
6264 gnus-level-default-unsubscribed
6265 gnus-level-default-subscribed) t)
6266 (gnus-group-update-group-line))
6267 (gnus-group-next-group 1)))
6268
6269 (defun gnus-group-unsubscribe-group (group &optional level silent)
6270 "Toggle subscription to GROUP.
6271 Killed newsgroups are subscribed. If SILENT, don't try to update the
6272 group line."
6273 (interactive
6274 (list (completing-read
6275 "Group: " gnus-active-hashtb nil
6276 (gnus-read-active-file-p)
6277 nil
6278 'gnus-group-history)))
6279 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
6280 (cond
6281 ((string-match "^[ \t]$" group)
6282 (error "Empty group name"))
6283 (newsrc
6284 ;; Toggle subscription flag.
6285 (gnus-group-change-level
6286 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
6287 gnus-level-subscribed)
6288 (1+ gnus-level-subscribed)
6289 gnus-level-default-subscribed)))
6290 (unless silent
6291 (gnus-group-update-group group)))
6292 ((and (stringp group)
6293 (or (not (gnus-read-active-file-p))
6294 (gnus-active group)))
6295 ;; Add new newsgroup.
6296 (gnus-group-change-level
6297 group
6298 (if level level gnus-level-default-subscribed)
6299 (or (and (member group gnus-zombie-list)
6300 gnus-level-zombie)
6301 gnus-level-killed)
6302 (and (gnus-group-group-name)
6303 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
6304 (unless silent
6305 (gnus-group-update-group group)))
6306 (t (error "No such newsgroup: %s" group)))
6307 (gnus-group-position-point)))
6308
6309 (defun gnus-group-transpose-groups (n)
6310 "Move the current newsgroup up N places.
6311 If given a negative prefix, move down instead. The difference between
6312 N and the number of steps taken is returned."
6313 (interactive "p")
6314 (or (gnus-group-group-name)
6315 (error "No group on current line"))
6316 (gnus-group-kill-group 1)
6317 (prog1
6318 (forward-line (- n))
6319 (gnus-group-yank-group)
6320 (gnus-group-position-point)))
6321
6322 (defun gnus-group-kill-all-zombies ()
6323 "Kill all zombie newsgroups."
6324 (interactive)
6325 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
6326 (setq gnus-zombie-list nil)
6327 (gnus-group-list-groups))
6328
6329 (defun gnus-group-kill-region (begin end)
6330 "Kill newsgroups in current region (excluding current point).
6331 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
6332 (interactive "r")
6333 (let ((lines
6334 ;; Count lines.
6335 (save-excursion
6336 (count-lines
6337 (progn
6338 (goto-char begin)
6339 (beginning-of-line)
6340 (point))
6341 (progn
6342 (goto-char end)
6343 (beginning-of-line)
6344 (point))))))
6345 (goto-char begin)
6346 (beginning-of-line) ;Important when LINES < 1
6347 (gnus-group-kill-group lines)))
6348
6349 (defun gnus-group-kill-group (&optional n discard)
6350 "Kill the next N groups.
6351 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
6352 However, only groups that were alive can be yanked; already killed
6353 groups or zombie groups can't be yanked.
6354 The return value is the name of the group that was killed, or a list
6355 of groups killed."
6356 (interactive "P")
6357 (let ((buffer-read-only nil)
6358 (groups (gnus-group-process-prefix n))
6359 group entry level out)
6360 (if (< (length groups) 10)
6361 ;; This is faster when there are few groups.
6362 (while groups
6363 (push (setq group (pop groups)) out)
6364 (gnus-group-remove-mark group)
6365 (setq level (gnus-group-group-level))
6366 (gnus-delete-line)
6367 (when (and (not discard)
6368 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
6369 (push (cons (car entry) (nth 2 entry))
6370 gnus-list-of-killed-groups))
6371 (gnus-group-change-level
6372 (if entry entry group) gnus-level-killed (if entry nil level)))
6373 ;; If there are lots and lots of groups to be killed, we use
6374 ;; this thing instead.
6375 (let (entry)
6376 (setq groups (nreverse groups))
6377 (while groups
6378 (gnus-group-remove-mark (setq group (pop groups)))
6379 (gnus-delete-line)
6380 (push group gnus-killed-list)
6381 (setq gnus-newsrc-alist
6382 (delq (assoc group gnus-newsrc-alist)
6383 gnus-newsrc-alist))
6384 (when gnus-group-change-level-function
6385 (funcall gnus-group-change-level-function group 9 3))
6386 (cond
6387 ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
6388 (push (cons (car entry) (nth 2 entry))
6389 gnus-list-of-killed-groups)
6390 (setcdr (cdr entry) (cdddr entry)))
6391 ((member group gnus-zombie-list)
6392 (setq gnus-zombie-list (delete group gnus-zombie-list)))))
6393 (gnus-make-hashtable-from-newsrc-alist)))
6394
6395 (gnus-group-position-point)
6396 (if (< (length out) 2) (car out) (nreverse out))))
6397
6398 (defun gnus-group-yank-group (&optional arg)
6399 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
6400 inserting it before the current newsgroup. The numeric ARG specifies
6401 how many newsgroups are to be yanked. The name of the newsgroup yanked
6402 is returned, or (if several groups are yanked) a list of yanked groups
6403 is returned."
6404 (interactive "p")
6405 (setq arg (or arg 1))
6406 (let (info group prev out)
6407 (while (>= (decf arg) 0)
6408 (if (not (setq info (pop gnus-list-of-killed-groups)))
6409 (error "No more newsgroups to yank"))
6410 (push (setq group (nth 1 info)) out)
6411 ;; Find which newsgroup to insert this one before - search
6412 ;; backward until something suitable is found. If there are no
6413 ;; other newsgroups in this buffer, just make this newsgroup the
6414 ;; first newsgroup.
6415 (setq prev (gnus-group-group-name))
6416 (gnus-group-change-level
6417 info (gnus-info-level (cdr info)) gnus-level-killed
6418 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
6419 t)
6420 (gnus-group-insert-group-line-info group))
6421 (forward-line -1)
6422 (gnus-group-position-point)
6423 (if (< (length out) 2) (car out) (nreverse out))))
6424
6425 (defun gnus-group-kill-level (level)
6426 "Kill all groups that is on a certain LEVEL."
6427 (interactive "nKill all groups on level: ")
6428 (cond
6429 ((= level gnus-level-zombie)
6430 (setq gnus-killed-list
6431 (nconc gnus-zombie-list gnus-killed-list))
6432 (setq gnus-zombie-list nil))
6433 ((and (< level gnus-level-zombie)
6434 (> level 0)
6435 (or gnus-expert-user
6436 (gnus-yes-or-no-p
6437 (format
6438 "Do you really want to kill all groups on level %d? "
6439 level))))
6440 (let* ((prev gnus-newsrc-alist)
6441 (alist (cdr prev)))
6442 (while alist
6443 (if (= (gnus-info-level (car alist)) level)
6444 (progn
6445 (push (gnus-info-group (car alist)) gnus-killed-list)
6446 (setcdr prev (cdr alist)))
6447 (setq prev alist))
6448 (setq alist (cdr alist)))
6449 (gnus-make-hashtable-from-newsrc-alist)
6450 (gnus-group-list-groups)))
6451 (t
6452 (error "Can't kill; illegal level: %d" level))))
6453
6454 (defun gnus-group-list-all-groups (&optional arg)
6455 "List all newsgroups with level ARG or lower.
6456 Default is gnus-level-unsubscribed, which lists all subscribed and most
6457 unsubscribed groups."
6458 (interactive "P")
6459 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
6460
6461 ;; Redefine this to list ALL killed groups if prefix arg used.
6462 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
6463 (defun gnus-group-list-killed (&optional arg)
6464 "List all killed newsgroups in the group buffer.
6465 If ARG is non-nil, list ALL killed groups known to Gnus. This may
6466 entail asking the server for the groups."
6467 (interactive "P")
6468 ;; Find all possible killed newsgroups if arg.
6469 (when arg
6470 (gnus-get-killed-groups))
6471 (if (not gnus-killed-list)
6472 (gnus-message 6 "No killed groups")
6473 (let (gnus-group-list-mode)
6474 (funcall gnus-group-prepare-function
6475 gnus-level-killed t gnus-level-killed))
6476 (goto-char (point-min)))
6477 (gnus-group-position-point))
6478
6479 (defun gnus-group-list-zombies ()
6480 "List all zombie newsgroups in the group buffer."
6481 (interactive)
6482 (if (not gnus-zombie-list)
6483 (gnus-message 6 "No zombie groups")
6484 (let (gnus-group-list-mode)
6485 (funcall gnus-group-prepare-function
6486 gnus-level-zombie t gnus-level-zombie))
6487 (goto-char (point-min)))
6488 (gnus-group-position-point))
6489
6490 (defun gnus-group-list-active ()
6491 "List all groups that are available from the server(s)."
6492 (interactive)
6493 ;; First we make sure that we have really read the active file.
6494 (unless (gnus-read-active-file-p)
6495 (let ((gnus-read-active-file t))
6496 (gnus-read-active-file)))
6497 ;; Find all groups and sort them.
6498 (let ((groups
6499 (sort
6500 (let (list)
6501 (mapatoms
6502 (lambda (sym)
6503 (and (boundp sym)
6504 (symbol-value sym)
6505 (setq list (cons (symbol-name sym) list))))
6506 gnus-active-hashtb)
6507 list)
6508 'string<))
6509 (buffer-read-only nil))
6510 (erase-buffer)
6511 (while groups
6512 (gnus-group-insert-group-line-info (pop groups)))
6513 (goto-char (point-min))))
6514
6515 (defun gnus-activate-all-groups (level)
6516 "Activate absolutely all groups."
6517 (interactive (list 7))
6518 (let ((gnus-activate-level level)
6519 (gnus-activate-foreign-newsgroups level))
6520 (gnus-group-get-new-news)))
6521
6522 (defun gnus-group-get-new-news (&optional arg)
6523 "Get newly arrived articles.
6524 If ARG is a number, it specifies which levels you are interested in
6525 re-scanning. If ARG is non-nil and not a number, this will force
6526 \"hard\" re-reading of the active files from all servers."
6527 (interactive "P")
6528 (run-hooks 'gnus-get-new-news-hook)
6529 ;; We might read in new NoCeM messages here.
6530 (when (and gnus-use-nocem
6531 (null arg))
6532 (gnus-nocem-scan-groups))
6533 ;; If ARG is not a number, then we read the active file.
6534 (when (and arg (not (numberp arg)))
6535 (let ((gnus-read-active-file t))
6536 (gnus-read-active-file))
6537 (setq arg nil))
6538
6539 (setq arg (gnus-group-default-level arg t))
6540 (if (and gnus-read-active-file (not arg))
6541 (progn
6542 (gnus-read-active-file)
6543 (gnus-get-unread-articles arg))
6544 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
6545 (gnus-get-unread-articles arg)))
6546 (run-hooks 'gnus-after-getting-new-news-hook)
6547 (gnus-group-list-groups))
6548
6549 (defun gnus-group-get-new-news-this-group (&optional n)
6550 "Check for newly arrived news in the current group (and the N-1 next groups).
6551 The difference between N and the number of newsgroup checked is returned.
6552 If N is negative, this group and the N-1 previous groups will be checked."
6553 (interactive "P")
6554 (let* ((groups (gnus-group-process-prefix n))
6555 (ret (if (numberp n) (- n (length groups)) 0))
6556 (beg (unless n (point)))
6557 group)
6558 (while (setq group (pop groups))
6559 (gnus-group-remove-mark group)
6560 (if (gnus-activate-group group 'scan)
6561 (progn
6562 (gnus-get-unread-articles-in-group
6563 (gnus-get-info group) (gnus-active group) t)
6564 (unless (gnus-virtual-group-p group)
6565 (gnus-close-group group))
6566 (gnus-group-update-group group))
6567 (if (eq (gnus-server-status (gnus-find-method-for-group group))
6568 'denied)
6569 (gnus-error "Server denied access")
6570 (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
6571 (when beg (goto-char beg))
6572 (when gnus-goto-next-group-when-activating
6573 (gnus-group-next-unread-group 1 t))
6574 (gnus-summary-position-point)
6575 ret))
6576
6577 (defun gnus-group-fetch-faq (group &optional faq-dir)
6578 "Fetch the FAQ for the current group."
6579 (interactive
6580 (list
6581 (and (gnus-group-group-name)
6582 (gnus-group-real-name (gnus-group-group-name)))
6583 (cond (current-prefix-arg
6584 (completing-read
6585 "Faq dir: " (and (listp gnus-group-faq-directory)
6586 (mapcar (lambda (file) (list file))
6587 gnus-group-faq-directory)))))))
6588 (or faq-dir
6589 (setq faq-dir (if (listp gnus-group-faq-directory)
6590 (car gnus-group-faq-directory)
6591 gnus-group-faq-directory)))
6592 (or group (error "No group name given"))
6593 (let ((file (concat (file-name-as-directory faq-dir)
6594 (gnus-group-real-name group))))
6595 (if (not (file-exists-p file))
6596 (error "No such file: %s" file)
6597 (find-file file))))
6598
6599 (defun gnus-group-describe-group (force &optional group)
6600 "Display a description of the current newsgroup."
6601 (interactive (list current-prefix-arg (gnus-group-group-name)))
6602 (let* ((method (gnus-find-method-for-group group))
6603 (mname (gnus-group-prefixed-name "" method))
6604 desc)
6605 (when (and force
6606 gnus-description-hashtb)
6607 (gnus-sethash mname nil gnus-description-hashtb))
6608 (or group (error "No group name given"))
6609 (and (or (and gnus-description-hashtb
6610 ;; We check whether this group's method has been
6611 ;; queried for a description file.
6612 (gnus-gethash mname gnus-description-hashtb))
6613 (setq desc (gnus-group-get-description group))
6614 (gnus-read-descriptions-file method))
6615 (gnus-message 1
6616 (or desc (gnus-gethash group gnus-description-hashtb)
6617 "No description available")))))
6618
6619 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6620 (defun gnus-group-describe-all-groups (&optional force)
6621 "Pop up a buffer with descriptions of all newsgroups."
6622 (interactive "P")
6623 (and force (setq gnus-description-hashtb nil))
6624 (if (not (or gnus-description-hashtb
6625 (gnus-read-all-descriptions-files)))
6626 (error "Couldn't request descriptions file"))
6627 (let ((buffer-read-only nil)
6628 b)
6629 (erase-buffer)
6630 (mapatoms
6631 (lambda (group)
6632 (setq b (point))
6633 (insert (format " *: %-20s %s\n" (symbol-name group)
6634 (symbol-value group)))
6635 (gnus-add-text-properties
6636 b (1+ b) (list 'gnus-group group
6637 'gnus-unread t 'gnus-marked nil
6638 'gnus-level (1+ gnus-level-subscribed))))
6639 gnus-description-hashtb)
6640 (goto-char (point-min))
6641 (gnus-group-position-point)))
6642
6643 ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
6644 (defun gnus-group-apropos (regexp &optional search-description)
6645 "List all newsgroups that have names that match a regexp."
6646 (interactive "sGnus apropos (regexp): ")
6647 (let ((prev "")
6648 (obuf (current-buffer))
6649 groups des)
6650 ;; Go through all newsgroups that are known to Gnus.
6651 (mapatoms
6652 (lambda (group)
6653 (and (symbol-name group)
6654 (string-match regexp (symbol-name group))
6655 (setq groups (cons (symbol-name group) groups))))
6656 gnus-active-hashtb)
6657 ;; Also go through all descriptions that are known to Gnus.
6658 (when search-description
6659 (mapatoms
6660 (lambda (group)
6661 (and (string-match regexp (symbol-value group))
6662 (gnus-active (symbol-name group))
6663 (setq groups (cons (symbol-name group) groups))))
6664 gnus-description-hashtb))
6665 (if (not groups)
6666 (gnus-message 3 "No groups matched \"%s\"." regexp)
6667 ;; Print out all the groups.
6668 (save-excursion
6669 (pop-to-buffer "*Gnus Help*")
6670 (buffer-disable-undo (current-buffer))
6671 (erase-buffer)
6672 (setq groups (sort groups 'string<))
6673 (while groups
6674 ;; Groups may be entered twice into the list of groups.
6675 (if (not (string= (car groups) prev))
6676 (progn
6677 (insert (setq prev (car groups)) "\n")
6678 (if (and gnus-description-hashtb
6679 (setq des (gnus-gethash (car groups)
6680 gnus-description-hashtb)))
6681 (insert " " des "\n"))))
6682 (setq groups (cdr groups)))
6683 (goto-char (point-min))))
6684 (pop-to-buffer obuf)))
6685
6686 (defun gnus-group-description-apropos (regexp)
6687 "List all newsgroups that have names or descriptions that match a regexp."
6688 (interactive "sGnus description apropos (regexp): ")
6689 (if (not (or gnus-description-hashtb
6690 (gnus-read-all-descriptions-files)))
6691 (error "Couldn't request descriptions file"))
6692 (gnus-group-apropos regexp t))
6693
6694 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6695 (defun gnus-group-list-matching (level regexp &optional all lowest)
6696 "List all groups with unread articles that match REGEXP.
6697 If the prefix LEVEL is non-nil, it should be a number that says which
6698 level to cut off listing groups.
6699 If ALL, also list groups with no unread articles.
6700 If LOWEST, don't list groups with level lower than LOWEST.
6701
6702 This command may read the active file."
6703 (interactive "P\nsList newsgroups matching: ")
6704 ;; First make sure active file has been read.
6705 (when (and level
6706 (> (prefix-numeric-value level) gnus-level-killed))
6707 (gnus-get-killed-groups))
6708 (gnus-group-prepare-flat (or level gnus-level-subscribed)
6709 all (or lowest 1) regexp)
6710 (goto-char (point-min))
6711 (gnus-group-position-point))
6712
6713 (defun gnus-group-list-all-matching (level regexp &optional lowest)
6714 "List all groups that match REGEXP.
6715 If the prefix LEVEL is non-nil, it should be a number that says which
6716 level to cut off listing groups.
6717 If LOWEST, don't list groups with level lower than LOWEST."
6718 (interactive "P\nsList newsgroups matching: ")
6719 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
6720
6721 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
6722 (defun gnus-group-save-newsrc (&optional force)
6723 "Save the Gnus startup files.
6724 If FORCE, force saving whether it is necessary or not."
6725 (interactive "P")
6726 (gnus-save-newsrc-file force))
6727
6728 (defun gnus-group-restart (&optional arg)
6729 "Force Gnus to read the .newsrc file."
6730 (interactive "P")
6731 (when (gnus-yes-or-no-p
6732 (format "Are you sure you want to read %s? "
6733 gnus-current-startup-file))
6734 (gnus-save-newsrc-file)
6735 (gnus-setup-news 'force)
6736 (gnus-group-list-groups arg)))
6737
6738 (defun gnus-group-read-init-file ()
6739 "Read the Gnus elisp init file."
6740 (interactive)
6741 (gnus-read-init-file))
6742
6743 (defun gnus-group-check-bogus-groups (&optional silent)
6744 "Check bogus newsgroups.
6745 If given a prefix, don't ask for confirmation before removing a bogus
6746 group."
6747 (interactive "P")
6748 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
6749 (gnus-group-list-groups))
6750
6751 (defun gnus-group-edit-global-kill (&optional article group)
6752 "Edit the global kill file.
6753 If GROUP, edit that local kill file instead."
6754 (interactive "P")
6755 (setq gnus-current-kill-article article)
6756 (gnus-kill-file-edit-file group)
6757 (gnus-message
6758 6
6759 (substitute-command-keys
6760 (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
6761 (if group "local" "global")))))
6762
6763 (defun gnus-group-edit-local-kill (article group)
6764 "Edit a local kill file."
6765 (interactive (list nil (gnus-group-group-name)))
6766 (gnus-group-edit-global-kill article group))
6767
6768 (defun gnus-group-force-update ()
6769 "Update `.newsrc' file."
6770 (interactive)
6771 (gnus-save-newsrc-file))
6772
6773 (defun gnus-group-suspend ()
6774 "Suspend the current Gnus session.
6775 In fact, cleanup buffers except for group mode buffer.
6776 The hook gnus-suspend-gnus-hook is called before actually suspending."
6777 (interactive)
6778 (run-hooks 'gnus-suspend-gnus-hook)
6779 ;; Kill Gnus buffers except for group mode buffer.
6780 (let* ((group-buf (get-buffer gnus-group-buffer))
6781 ;; Do this on a separate list in case the user does a ^G before we finish
6782 (gnus-buffer-list
6783 (delete group-buf (delete gnus-dribble-buffer
6784 (append gnus-buffer-list nil)))))
6785 (while gnus-buffer-list
6786 (gnus-kill-buffer (pop gnus-buffer-list)))
6787 (gnus-kill-gnus-frames)
6788 (when group-buf
6789 (setq gnus-buffer-list (list group-buf))
6790 (bury-buffer group-buf)
6791 (delete-windows-on group-buf t))))
6792
6793 (defun gnus-group-clear-dribble ()
6794 "Clear all information from the dribble buffer."
6795 (interactive)
6796 (gnus-dribble-clear)
6797 (gnus-message 7 "Cleared dribble buffer"))
6798
6799 (defun gnus-group-exit ()
6800 "Quit reading news after updating .newsrc.eld and .newsrc.
6801 The hook `gnus-exit-gnus-hook' is called before actually exiting."
6802 (interactive)
6803 (when
6804 (or noninteractive ;For gnus-batch-kill
6805 (not gnus-interactive-exit) ;Without confirmation
6806 gnus-expert-user
6807 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
6808 (run-hooks 'gnus-exit-gnus-hook)
6809 ;; Offer to save data from non-quitted summary buffers.
6810 (gnus-offer-save-summaries)
6811 ;; Save the newsrc file(s).
6812 (gnus-save-newsrc-file)
6813 ;; Kill-em-all.
6814 (gnus-close-backends)
6815 ;; Reset everything.
6816 (gnus-clear-system)
6817 ;; Allow the user to do things after cleaning up.
6818 (run-hooks 'gnus-after-exiting-gnus-hook)))
6819
6820 (defun gnus-close-backends ()
6821 ;; Send a close request to all backends that support such a request.
6822 (let ((methods gnus-valid-select-methods)
6823 func)
6824 (while methods
6825 (if (fboundp (setq func (intern (concat (caar methods)
6826 "-request-close"))))
6827 (funcall func))
6828 (setq methods (cdr methods)))))
6829
6830 (defun gnus-group-quit ()
6831 "Quit reading news without updating .newsrc.eld or .newsrc.
6832 The hook `gnus-exit-gnus-hook' is called before actually exiting."
6833 (interactive)
6834 (when (or noninteractive ;For gnus-batch-kill
6835 (zerop (buffer-size))
6836 (not (gnus-server-opened gnus-select-method))
6837 gnus-expert-user
6838 (not gnus-current-startup-file)
6839 (gnus-yes-or-no-p
6840 (format "Quit reading news without saving %s? "
6841 (file-name-nondirectory gnus-current-startup-file))))
6842 (run-hooks 'gnus-exit-gnus-hook)
6843 (if gnus-use-full-window
6844 (delete-other-windows)
6845 (gnus-remove-some-windows))
6846 (gnus-dribble-save)
6847 (gnus-close-backends)
6848 (gnus-clear-system)
6849 ;; Allow the user to do things after cleaning up.
6850 (run-hooks 'gnus-after-exiting-gnus-hook)))
6851
6852 (defun gnus-offer-save-summaries ()
6853 "Offer to save all active summary buffers."
6854 (save-excursion
6855 (let ((buflist (buffer-list))
6856 buffers bufname)
6857 ;; Go through all buffers and find all summaries.
6858 (while buflist
6859 (and (setq bufname (buffer-name (car buflist)))
6860 (string-match "Summary" bufname)
6861 (save-excursion
6862 (set-buffer bufname)
6863 ;; We check that this is, indeed, a summary buffer.
6864 (and (eq major-mode 'gnus-summary-mode)
6865 ;; Also make sure this isn't bogus.
6866 gnus-newsgroup-prepared))
6867 (push bufname buffers))
6868 (setq buflist (cdr buflist)))
6869 ;; Go through all these summary buffers and offer to save them.
6870 (when buffers
6871 (map-y-or-n-p
6872 "Update summary buffer %s? "
6873 (lambda (buf) (set-buffer buf) (gnus-summary-exit))
6874 buffers)))))
6875
6876 (defun gnus-group-describe-briefly ()
6877 "Give a one line description of the group mode commands."
6878 (interactive)
6879 (gnus-message 7 (substitute-command-keys "\\<gnus-group-mode-map>\\[gnus-group-read-group]:Select \\[gnus-group-next-unread-group]:Forward \\[gnus-group-prev-unread-group]:Backward \\[gnus-group-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-group-describe-briefly]:This help")))
6880
6881 (defun gnus-group-browse-foreign-server (method)
6882 "Browse a foreign news server.
6883 If called interactively, this function will ask for a select method
6884 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
6885 If not, METHOD should be a list where the first element is the method
6886 and the second element is the address."
6887 (interactive
6888 (list (let ((how (completing-read
6889 "Which backend: "
6890 (append gnus-valid-select-methods gnus-server-alist)
6891 nil t (cons "nntp" 0) 'gnus-method-history)))
6892 ;; We either got a backend name or a virtual server name.
6893 ;; If the first, we also need an address.
6894 (if (assoc how gnus-valid-select-methods)
6895 (list (intern how)
6896 ;; Suggested by mapjph@bath.ac.uk.
6897 (completing-read
6898 "Address: "
6899 (mapcar (lambda (server) (list server))
6900 gnus-secondary-servers)))
6901 ;; We got a server name, so we find the method.
6902 (gnus-server-to-method how)))))
6903 (gnus-browse-foreign-server method))
6904
6905 \f
6906 ;;;
6907 ;;; Gnus summary mode
6908 ;;;
6909
6910 (defvar gnus-summary-mode-map nil)
6911
6912 (put 'gnus-summary-mode 'mode-class 'special)
6913
6914 (unless gnus-summary-mode-map
6915 (setq gnus-summary-mode-map (make-keymap))
6916 (suppress-keymap gnus-summary-mode-map)
6917
6918 ;; Non-orthogonal keys
6919
6920 (gnus-define-keys gnus-summary-mode-map
6921 " " gnus-summary-next-page
6922 "\177" gnus-summary-prev-page
6923 [delete] gnus-summary-prev-page
6924 "\r" gnus-summary-scroll-up
6925 "n" gnus-summary-next-unread-article
6926 "p" gnus-summary-prev-unread-article
6927 "N" gnus-summary-next-article
6928 "P" gnus-summary-prev-article
6929 "\M-\C-n" gnus-summary-next-same-subject
6930 "\M-\C-p" gnus-summary-prev-same-subject
6931 "\M-n" gnus-summary-next-unread-subject
6932 "\M-p" gnus-summary-prev-unread-subject
6933 "." gnus-summary-first-unread-article
6934 "," gnus-summary-best-unread-article
6935 "\M-s" gnus-summary-search-article-forward
6936 "\M-r" gnus-summary-search-article-backward
6937 "<" gnus-summary-beginning-of-article
6938 ">" gnus-summary-end-of-article
6939 "j" gnus-summary-goto-article
6940 "^" gnus-summary-refer-parent-article
6941 "\M-^" gnus-summary-refer-article
6942 "u" gnus-summary-tick-article-forward
6943 "!" gnus-summary-tick-article-forward
6944 "U" gnus-summary-tick-article-backward
6945 "d" gnus-summary-mark-as-read-forward
6946 "D" gnus-summary-mark-as-read-backward
6947 "E" gnus-summary-mark-as-expirable
6948 "\M-u" gnus-summary-clear-mark-forward
6949 "\M-U" gnus-summary-clear-mark-backward
6950 "k" gnus-summary-kill-same-subject-and-select
6951 "\C-k" gnus-summary-kill-same-subject
6952 "\M-\C-k" gnus-summary-kill-thread
6953 "\M-\C-l" gnus-summary-lower-thread
6954 "e" gnus-summary-edit-article
6955 "#" gnus-summary-mark-as-processable
6956 "\M-#" gnus-summary-unmark-as-processable
6957 "\M-\C-t" gnus-summary-toggle-threads
6958 "\M-\C-s" gnus-summary-show-thread
6959 "\M-\C-h" gnus-summary-hide-thread
6960 "\M-\C-f" gnus-summary-next-thread
6961 "\M-\C-b" gnus-summary-prev-thread
6962 "\M-\C-u" gnus-summary-up-thread
6963 "\M-\C-d" gnus-summary-down-thread
6964 "&" gnus-summary-execute-command
6965 "c" gnus-summary-catchup-and-exit
6966 "\C-w" gnus-summary-mark-region-as-read
6967 "\C-t" gnus-summary-toggle-truncation
6968 "?" gnus-summary-mark-as-dormant
6969 "\C-c\M-\C-s" gnus-summary-limit-include-expunged
6970 "\C-c\C-s\C-n" gnus-summary-sort-by-number
6971 "\C-c\C-s\C-a" gnus-summary-sort-by-author
6972 "\C-c\C-s\C-s" gnus-summary-sort-by-subject
6973 "\C-c\C-s\C-d" gnus-summary-sort-by-date
6974 "\C-c\C-s\C-i" gnus-summary-sort-by-score
6975 "=" gnus-summary-expand-window
6976 "\C-x\C-s" gnus-summary-reselect-current-group
6977 "\M-g" gnus-summary-rescan-group
6978 "w" gnus-summary-stop-page-breaking
6979 "\C-c\C-r" gnus-summary-caesar-message
6980 "\M-t" gnus-summary-toggle-mime
6981 "f" gnus-summary-followup
6982 "F" gnus-summary-followup-with-original
6983 "C" gnus-summary-cancel-article
6984 "r" gnus-summary-reply
6985 "R" gnus-summary-reply-with-original
6986 "\C-c\C-f" gnus-summary-mail-forward
6987 "o" gnus-summary-save-article
6988 "\C-o" gnus-summary-save-article-mail
6989 "|" gnus-summary-pipe-output
6990 "\M-k" gnus-summary-edit-local-kill
6991 "\M-K" gnus-summary-edit-global-kill
6992 "V" gnus-version
6993 "\C-c\C-d" gnus-summary-describe-group
6994 "q" gnus-summary-exit
6995 "Q" gnus-summary-exit-no-update
6996 "\C-c\C-i" gnus-info-find-node
6997 gnus-mouse-2 gnus-mouse-pick-article
6998 "m" gnus-summary-mail-other-window
6999 "a" gnus-summary-post-news
7000 "x" gnus-summary-limit-to-unread
7001 "s" gnus-summary-isearch-article
7002 "t" gnus-article-hide-headers
7003 "g" gnus-summary-show-article
7004 "l" gnus-summary-goto-last-article
7005 "\C-c\C-v\C-v" gnus-uu-decode-uu-view
7006 "\C-d" gnus-summary-enter-digest-group
7007 "\C-c\C-b" gnus-bug
7008 "*" gnus-cache-enter-article
7009 "\M-*" gnus-cache-remove-article
7010 "\M-&" gnus-summary-universal-argument
7011 "\C-l" gnus-recenter
7012 "I" gnus-summary-increase-score
7013 "L" gnus-summary-lower-score
7014
7015 "V" gnus-summary-score-map
7016 "X" gnus-uu-extract-map
7017 "S" gnus-summary-send-map)
7018
7019 ;; Sort of orthogonal keymap
7020 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
7021 "t" gnus-summary-tick-article-forward
7022 "!" gnus-summary-tick-article-forward
7023 "d" gnus-summary-mark-as-read-forward
7024 "r" gnus-summary-mark-as-read-forward
7025 "c" gnus-summary-clear-mark-forward
7026 " " gnus-summary-clear-mark-forward
7027 "e" gnus-summary-mark-as-expirable
7028 "x" gnus-summary-mark-as-expirable
7029 "?" gnus-summary-mark-as-dormant
7030 "b" gnus-summary-set-bookmark
7031 "B" gnus-summary-remove-bookmark
7032 "#" gnus-summary-mark-as-processable
7033 "\M-#" gnus-summary-unmark-as-processable
7034 "S" gnus-summary-limit-include-expunged
7035 "C" gnus-summary-catchup
7036 "H" gnus-summary-catchup-to-here
7037 "\C-c" gnus-summary-catchup-all
7038 "k" gnus-summary-kill-same-subject-and-select
7039 "K" gnus-summary-kill-same-subject
7040 "P" gnus-uu-mark-map)
7041
7042 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mode-map)
7043 "c" gnus-summary-clear-above
7044 "u" gnus-summary-tick-above
7045 "m" gnus-summary-mark-above
7046 "k" gnus-summary-kill-below)
7047
7048 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
7049 "/" gnus-summary-limit-to-subject
7050 "n" gnus-summary-limit-to-articles
7051 "w" gnus-summary-pop-limit
7052 "s" gnus-summary-limit-to-subject
7053 "a" gnus-summary-limit-to-author
7054 "u" gnus-summary-limit-to-unread
7055 "m" gnus-summary-limit-to-marks
7056 "v" gnus-summary-limit-to-score
7057 "D" gnus-summary-limit-include-dormant
7058 "d" gnus-summary-limit-exclude-dormant
7059 ;; "t" gnus-summary-limit-exclude-thread
7060 "E" gnus-summary-limit-include-expunged
7061 "c" gnus-summary-limit-exclude-childless-dormant
7062 "C" gnus-summary-limit-mark-excluded-as-read)
7063
7064 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
7065 "n" gnus-summary-next-unread-article
7066 "p" gnus-summary-prev-unread-article
7067 "N" gnus-summary-next-article
7068 "P" gnus-summary-prev-article
7069 "\C-n" gnus-summary-next-same-subject
7070 "\C-p" gnus-summary-prev-same-subject
7071 "\M-n" gnus-summary-next-unread-subject
7072 "\M-p" gnus-summary-prev-unread-subject
7073 "f" gnus-summary-first-unread-article
7074 "b" gnus-summary-best-unread-article
7075 "j" gnus-summary-goto-article
7076 "g" gnus-summary-goto-subject
7077 "l" gnus-summary-goto-last-article
7078 "p" gnus-summary-pop-article)
7079
7080 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
7081 "k" gnus-summary-kill-thread
7082 "l" gnus-summary-lower-thread
7083 "i" gnus-summary-raise-thread
7084 "T" gnus-summary-toggle-threads
7085 "t" gnus-summary-rethread-current
7086 "^" gnus-summary-reparent-thread
7087 "s" gnus-summary-show-thread
7088 "S" gnus-summary-show-all-threads
7089 "h" gnus-summary-hide-thread
7090 "H" gnus-summary-hide-all-threads
7091 "n" gnus-summary-next-thread
7092 "p" gnus-summary-prev-thread
7093 "u" gnus-summary-up-thread
7094 "o" gnus-summary-top-thread
7095 "d" gnus-summary-down-thread
7096 "#" gnus-uu-mark-thread
7097 "\M-#" gnus-uu-unmark-thread)
7098
7099 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
7100 "c" gnus-summary-catchup-and-exit
7101 "C" gnus-summary-catchup-all-and-exit
7102 "E" gnus-summary-exit-no-update
7103 "Q" gnus-summary-exit
7104 "Z" gnus-summary-exit
7105 "n" gnus-summary-catchup-and-goto-next-group
7106 "R" gnus-summary-reselect-current-group
7107 "G" gnus-summary-rescan-group
7108 "N" gnus-summary-next-group
7109 "P" gnus-summary-prev-group)
7110
7111 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
7112 " " gnus-summary-next-page
7113 "n" gnus-summary-next-page
7114 "\177" gnus-summary-prev-page
7115 [delete] gnus-summary-prev-page
7116 "p" gnus-summary-prev-page
7117 "\r" gnus-summary-scroll-up
7118 "<" gnus-summary-beginning-of-article
7119 ">" gnus-summary-end-of-article
7120 "b" gnus-summary-beginning-of-article
7121 "e" gnus-summary-end-of-article
7122 "^" gnus-summary-refer-parent-article
7123 "r" gnus-summary-refer-parent-article
7124 "R" gnus-summary-refer-references
7125 "g" gnus-summary-show-article
7126 "s" gnus-summary-isearch-article)
7127
7128 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
7129 "b" gnus-article-add-buttons
7130 "B" gnus-article-add-buttons-to-head
7131 "o" gnus-article-treat-overstrike
7132 ;; "w" gnus-article-word-wrap
7133 "w" gnus-article-fill-cited-article
7134 "c" gnus-article-remove-cr
7135 "L" gnus-article-remove-trailing-blank-lines
7136 "q" gnus-article-de-quoted-unreadable
7137 "f" gnus-article-display-x-face
7138 "l" gnus-summary-stop-page-breaking
7139 "r" gnus-summary-caesar-message
7140 "t" gnus-article-hide-headers
7141 "v" gnus-summary-verbose-headers
7142 "m" gnus-summary-toggle-mime)
7143
7144 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
7145 "a" gnus-article-hide
7146 "h" gnus-article-hide-headers
7147 "b" gnus-article-hide-boring-headers
7148 "s" gnus-article-hide-signature
7149 "c" gnus-article-hide-citation
7150 "p" gnus-article-hide-pgp
7151 "\C-c" gnus-article-hide-citation-maybe)
7152
7153 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
7154 "a" gnus-article-highlight
7155 "h" gnus-article-highlight-headers
7156 "c" gnus-article-highlight-citation
7157 "s" gnus-article-highlight-signature)
7158
7159 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
7160 "z" gnus-article-date-ut
7161 "u" gnus-article-date-ut
7162 "l" gnus-article-date-local
7163 "e" gnus-article-date-lapsed
7164 "o" gnus-article-date-original)
7165
7166 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
7167 "v" gnus-version
7168 "f" gnus-summary-fetch-faq
7169 "d" gnus-summary-describe-group
7170 "h" gnus-summary-describe-briefly
7171 "i" gnus-info-find-node)
7172
7173 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
7174 "e" gnus-summary-expire-articles
7175 "\M-\C-e" gnus-summary-expire-articles-now
7176 "\177" gnus-summary-delete-article
7177 [delete] gnus-summary-delete-article
7178 "m" gnus-summary-move-article
7179 "r" gnus-summary-respool-article
7180 "w" gnus-summary-edit-article
7181 "c" gnus-summary-copy-article
7182 "B" gnus-summary-crosspost-article
7183 "q" gnus-summary-respool-query
7184 "i" gnus-summary-import-article)
7185
7186 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
7187 "o" gnus-summary-save-article
7188 "m" gnus-summary-save-article-mail
7189 "r" gnus-summary-save-article-rmail
7190 "f" gnus-summary-save-article-file
7191 "b" gnus-summary-save-article-body-file
7192 "h" gnus-summary-save-article-folder
7193 "v" gnus-summary-save-article-vm
7194 "p" gnus-summary-pipe-output
7195 "s" gnus-soup-add-article)
7196 )
7197
7198 \f
7199
7200 (defun gnus-summary-mode (&optional group)
7201 "Major mode for reading articles.
7202
7203 All normal editing commands are switched off.
7204 \\<gnus-summary-mode-map>
7205 Each line in this buffer represents one article. To read an
7206 article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
7207 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
7208 respectively.
7209
7210 You can also post articles and send mail from this buffer. To
7211 follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
7212 of an article, type `\\[gnus-summary-reply]'.
7213
7214 There are approx. one gazillion commands you can execute in this
7215 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
7216
7217 The following commands are available:
7218
7219 \\{gnus-summary-mode-map}"
7220 (interactive)
7221 (when (and menu-bar-mode
7222 (gnus-visual-p 'summary-menu 'menu))
7223 (gnus-summary-make-menu-bar))
7224 (kill-all-local-variables)
7225 (gnus-summary-make-local-variables)
7226 (gnus-make-thread-indent-array)
7227 (gnus-simplify-mode-line)
7228 (setq major-mode 'gnus-summary-mode)
7229 (setq mode-name "Summary")
7230 (make-local-variable 'minor-mode-alist)
7231 (use-local-map gnus-summary-mode-map)
7232 (buffer-disable-undo (current-buffer))
7233 (setq buffer-read-only t) ;Disable modification
7234 (setq truncate-lines t)
7235 (setq selective-display t)
7236 (setq selective-display-ellipses t) ;Display `...'
7237 (setq buffer-display-table gnus-summary-display-table)
7238 (setq gnus-newsgroup-name group)
7239 (make-local-variable 'gnus-summary-line-format)
7240 (make-local-variable 'gnus-summary-line-format-spec)
7241 (make-local-variable 'gnus-summary-mark-positions)
7242 (gnus-make-local-hook 'post-command-hook)
7243 (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
7244 (run-hooks 'gnus-summary-mode-hook))
7245
7246 (defun gnus-summary-make-local-variables ()
7247 "Make all the local summary buffer variables."
7248 (let ((locals gnus-summary-local-variables)
7249 global local)
7250 (while (setq local (pop locals))
7251 (if (consp local)
7252 (progn
7253 (if (eq (cdr local) 'global)
7254 ;; Copy the global value of the variable.
7255 (setq global (symbol-value (car local)))
7256 ;; Use the value from the list.
7257 (setq global (eval (cdr local))))
7258 (make-local-variable (car local))
7259 (set (car local) global))
7260 ;; Simple nil-valued local variable.
7261 (make-local-variable local)
7262 (set local nil)))))
7263
7264 (defun gnus-summary-make-display-table ()
7265 ;; Change the display table. Odd characters have a tendency to mess
7266 ;; up nicely formatted displays - we make all possible glyphs
7267 ;; display only a single character.
7268
7269 ;; We start from the standard display table, if any.
7270 (setq gnus-summary-display-table
7271 (or (copy-sequence standard-display-table)
7272 (make-display-table)))
7273 ;; Nix out all the control chars...
7274 (let ((i 32))
7275 (while (>= (setq i (1- i)) 0)
7276 (aset gnus-summary-display-table i [??])))
7277 ;; ... but not newline and cr, of course. (cr is necessary for the
7278 ;; selective display).
7279 (aset gnus-summary-display-table ?\n nil)
7280 (aset gnus-summary-display-table ?\r nil)
7281 ;; We nix out any glyphs over 126 that are not set already.
7282 (let ((i 256))
7283 (while (>= (setq i (1- i)) 127)
7284 ;; Only modify if the entry is nil.
7285 (or (aref gnus-summary-display-table i)
7286 (aset gnus-summary-display-table i [??])))))
7287
7288 (defun gnus-summary-clear-local-variables ()
7289 (let ((locals gnus-summary-local-variables))
7290 (while locals
7291 (if (consp (car locals))
7292 (and (vectorp (caar locals))
7293 (set (caar locals) nil))
7294 (and (vectorp (car locals))
7295 (set (car locals) nil)))
7296 (setq locals (cdr locals)))))
7297
7298 ;; Summary data functions.
7299
7300 (defmacro gnus-data-number (data)
7301 `(car ,data))
7302
7303 (defmacro gnus-data-set-number (data number)
7304 `(setcar ,data ,number))
7305
7306 (defmacro gnus-data-mark (data)
7307 `(nth 1 ,data))
7308
7309 (defmacro gnus-data-set-mark (data mark)
7310 `(setcar (nthcdr 1 ,data) ,mark))
7311
7312 (defmacro gnus-data-pos (data)
7313 `(nth 2 ,data))
7314
7315 (defmacro gnus-data-set-pos (data pos)
7316 `(setcar (nthcdr 2 ,data) ,pos))
7317
7318 (defmacro gnus-data-header (data)
7319 `(nth 3 ,data))
7320
7321 (defmacro gnus-data-level (data)
7322 `(nth 4 ,data))
7323
7324 (defmacro gnus-data-unread-p (data)
7325 `(= (nth 1 ,data) gnus-unread-mark))
7326
7327 (defmacro gnus-data-pseudo-p (data)
7328 `(consp (nth 3 ,data)))
7329
7330 (defmacro gnus-data-find (number)
7331 `(assq ,number gnus-newsgroup-data))
7332
7333 (defmacro gnus-data-find-list (number &optional data)
7334 `(let ((bdata ,(or data 'gnus-newsgroup-data)))
7335 (memq (assq ,number bdata)
7336 bdata)))
7337
7338 (defmacro gnus-data-make (number mark pos header level)
7339 `(list ,number ,mark ,pos ,header ,level))
7340
7341 (defun gnus-data-enter (after-article number mark pos header level offset)
7342 (let ((data (gnus-data-find-list after-article)))
7343 (or data (error "No such article: %d" after-article))
7344 (setcdr data (cons (gnus-data-make number mark pos header level)
7345 (cdr data)))
7346 (setq gnus-newsgroup-data-reverse nil)
7347 (gnus-data-update-list (cddr data) offset)))
7348
7349 (defun gnus-data-enter-list (after-article list &optional offset)
7350 (when list
7351 (let ((data (and after-article (gnus-data-find-list after-article)))
7352 (ilist list))
7353 (or data (not after-article) (error "No such article: %d" after-article))
7354 ;; Find the last element in the list to be spliced into the main
7355 ;; list.
7356 (while (cdr list)
7357 (setq list (cdr list)))
7358 (if (not data)
7359 (progn
7360 (setcdr list gnus-newsgroup-data)
7361 (setq gnus-newsgroup-data ilist)
7362 (and offset (gnus-data-update-list (cdr list) offset)))
7363 (setcdr list (cdr data))
7364 (setcdr data ilist)
7365 (and offset (gnus-data-update-list (cdr data) offset)))
7366 (setq gnus-newsgroup-data-reverse nil))))
7367
7368 (defun gnus-data-remove (article &optional offset)
7369 (let ((data gnus-newsgroup-data))
7370 (if (= (gnus-data-number (car data)) article)
7371 (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
7372 gnus-newsgroup-data-reverse nil)
7373 (while (cdr data)
7374 (and (= (gnus-data-number (cadr data)) article)
7375 (progn
7376 (setcdr data (cddr data))
7377 (and offset (gnus-data-update-list (cdr data) offset))
7378 (setq data nil
7379 gnus-newsgroup-data-reverse nil)))
7380 (setq data (cdr data))))))
7381
7382 (defmacro gnus-data-list (backward)
7383 `(if ,backward
7384 (or gnus-newsgroup-data-reverse
7385 (setq gnus-newsgroup-data-reverse
7386 (reverse gnus-newsgroup-data)))
7387 gnus-newsgroup-data))
7388
7389 (defun gnus-data-update-list (data offset)
7390 "Add OFFSET to the POS of all data entries in DATA."
7391 (while data
7392 (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
7393 (setq data (cdr data))))
7394
7395 (defun gnus-data-compute-positions ()
7396 "Compute the positions of all articles."
7397 (let ((data gnus-newsgroup-data)
7398 pos)
7399 (while data
7400 (when (setq pos (text-property-any
7401 (point-min) (point-max)
7402 'gnus-number (gnus-data-number (car data))))
7403 (gnus-data-set-pos (car data) (+ pos 3)))
7404 (setq data (cdr data)))))
7405
7406 (defun gnus-summary-article-pseudo-p (article)
7407 "Say whether this article is a pseudo article or not."
7408 (not (vectorp (gnus-data-header (gnus-data-find article)))))
7409
7410 (defun gnus-article-parent-p (number)
7411 "Say whether this article is a parent or not."
7412 (let ((data (gnus-data-find-list number)))
7413 (and (cdr data) ; There has to be an article after...
7414 (< (gnus-data-level (car data)) ; And it has to have a higher level.
7415 (gnus-data-level (nth 1 data))))))
7416
7417 (defun gnus-article-children (number)
7418 "Return a list of all children to NUMBER."
7419 (let* ((data (gnus-data-find-list number))
7420 (level (gnus-data-level (car data)))
7421 children)
7422 (setq data (cdr data))
7423 (while (and data
7424 (= (gnus-data-level (car data)) (1+ level)))
7425 (push (gnus-data-number (car data)) children)
7426 (setq data (cdr data)))
7427 children))
7428
7429 (defmacro gnus-summary-skip-intangible ()
7430 "If the current article is intangible, then jump to a different article."
7431 '(let ((to (get-text-property (point) 'gnus-intangible)))
7432 (and to (gnus-summary-goto-subject to))))
7433
7434 (defmacro gnus-summary-article-intangible-p ()
7435 "Say whether this article is intangible or not."
7436 '(get-text-property (point) 'gnus-intangible))
7437
7438 ;; Some summary mode macros.
7439
7440 (defmacro gnus-summary-article-number ()
7441 "The article number of the article on the current line.
7442 If there isn's an article number here, then we return the current
7443 article number."
7444 '(progn
7445 (gnus-summary-skip-intangible)
7446 (or (get-text-property (point) 'gnus-number)
7447 (gnus-summary-last-subject))))
7448
7449 (defmacro gnus-summary-article-header (&optional number)
7450 `(gnus-data-header (gnus-data-find
7451 ,(or number '(gnus-summary-article-number)))))
7452
7453 (defmacro gnus-summary-thread-level (&optional number)
7454 `(if (and (eq gnus-summary-make-false-root 'dummy)
7455 (get-text-property (point) 'gnus-intangible))
7456 0
7457 (gnus-data-level (gnus-data-find
7458 ,(or number '(gnus-summary-article-number))))))
7459
7460 (defmacro gnus-summary-article-mark (&optional number)
7461 `(gnus-data-mark (gnus-data-find
7462 ,(or number '(gnus-summary-article-number)))))
7463
7464 (defmacro gnus-summary-article-pos (&optional number)
7465 `(gnus-data-pos (gnus-data-find
7466 ,(or number '(gnus-summary-article-number)))))
7467
7468 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
7469 (defmacro gnus-summary-article-subject (&optional number)
7470 "Return current subject string or nil if nothing."
7471 `(let ((headers
7472 ,(if number
7473 `(gnus-data-header (assq ,number gnus-newsgroup-data))
7474 '(gnus-data-header (assq (gnus-summary-article-number)
7475 gnus-newsgroup-data)))))
7476 (and headers
7477 (vectorp headers)
7478 (mail-header-subject headers))))
7479
7480 (defmacro gnus-summary-article-score (&optional number)
7481 "Return current article score."
7482 `(or (cdr (assq ,(or number '(gnus-summary-article-number))
7483 gnus-newsgroup-scored))
7484 gnus-summary-default-score 0))
7485
7486 (defun gnus-summary-article-children (&optional number)
7487 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
7488 (level (gnus-data-level (car data)))
7489 l children)
7490 (while (and (setq data (cdr data))
7491 (> (setq l (gnus-data-level (car data))) level))
7492 (and (= (1+ level) l)
7493 (setq children (cons (gnus-data-number (car data))
7494 children))))
7495 (nreverse children)))
7496
7497 (defun gnus-summary-article-parent (&optional number)
7498 (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
7499 (gnus-data-list t)))
7500 (level (gnus-data-level (car data))))
7501 (if (zerop level)
7502 () ; This is a root.
7503 ;; We search until we find an article with a level less than
7504 ;; this one. That function has to be the parent.
7505 (while (and (setq data (cdr data))
7506 (not (< (gnus-data-level (car data)) level))))
7507 (and data (gnus-data-number (car data))))))
7508
7509 (defun gnus-unread-mark-p (mark)
7510 "Say whether MARK is the unread mark."
7511 (= mark gnus-unread-mark))
7512
7513 (defun gnus-read-mark-p (mark)
7514 "Say whether MARK is one of the marks that mark as read.
7515 This is all marks except unread, ticked, dormant, and expirable."
7516 (not (or (= mark gnus-unread-mark)
7517 (= mark gnus-ticked-mark)
7518 (= mark gnus-dormant-mark)
7519 (= mark gnus-expirable-mark))))
7520
7521 ;; Saving hidden threads.
7522
7523 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
7524 (put 'gnus-save-hidden-threads 'lisp-indent-hook 0)
7525 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
7526
7527 (defmacro gnus-save-hidden-threads (&rest forms)
7528 "Save hidden threads, eval FORMS, and restore the hidden threads."
7529 (let ((config (make-symbol "config")))
7530 `(let ((,config (gnus-hidden-threads-configuration)))
7531 (unwind-protect
7532 (progn
7533 ,@forms)
7534 (gnus-restore-hidden-threads-configuration ,config)))))
7535
7536 (defun gnus-hidden-threads-configuration ()
7537 "Return the current hidden threads configuration."
7538 (save-excursion
7539 (let (config)
7540 (goto-char (point-min))
7541 (while (search-forward "\r" nil t)
7542 (push (1- (point)) config))
7543 config)))
7544
7545 (defun gnus-restore-hidden-threads-configuration (config)
7546 "Restore hidden threads configuration from CONFIG."
7547 (let (point buffer-read-only)
7548 (while (setq point (pop config))
7549 (when (and (< point (point-max))
7550 (goto-char point)
7551 (= (following-char) ?\n))
7552 (subst-char-in-region point (1+ point) ?\n ?\r)))))
7553
7554 ;; Various summary mode internalish functions.
7555
7556 (defun gnus-mouse-pick-article (e)
7557 (interactive "e")
7558 (mouse-set-point e)
7559 (gnus-summary-next-page nil t))
7560
7561 (defun gnus-summary-setup-buffer (group)
7562 "Initialize summary buffer."
7563 (let ((buffer (concat "*Summary " group "*")))
7564 (if (get-buffer buffer)
7565 (progn
7566 (set-buffer buffer)
7567 (setq gnus-summary-buffer (current-buffer))
7568 (not gnus-newsgroup-prepared))
7569 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
7570 (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
7571 (gnus-add-current-to-buffer-list)
7572 (gnus-summary-mode group)
7573 (when gnus-carpal
7574 (gnus-carpal-setup-buffer 'summary))
7575 (unless gnus-single-article-buffer
7576 (make-local-variable 'gnus-article-buffer)
7577 (make-local-variable 'gnus-article-current)
7578 (make-local-variable 'gnus-original-article-buffer))
7579 (setq gnus-newsgroup-name group)
7580 t)))
7581
7582 (defun gnus-set-global-variables ()
7583 ;; Set the global equivalents of the summary buffer-local variables
7584 ;; to the latest values they had. These reflect the summary buffer
7585 ;; that was in action when the last article was fetched.
7586 (when (eq major-mode 'gnus-summary-mode)
7587 (setq gnus-summary-buffer (current-buffer))
7588 (let ((name gnus-newsgroup-name)
7589 (marked gnus-newsgroup-marked)
7590 (unread gnus-newsgroup-unreads)
7591 (headers gnus-current-headers)
7592 (data gnus-newsgroup-data)
7593 (summary gnus-summary-buffer)
7594 (article-buffer gnus-article-buffer)
7595 (original gnus-original-article-buffer)
7596 (gac gnus-article-current)
7597 (score-file gnus-current-score-file))
7598 (save-excursion
7599 (set-buffer gnus-group-buffer)
7600 (setq gnus-newsgroup-name name)
7601 (setq gnus-newsgroup-marked marked)
7602 (setq gnus-newsgroup-unreads unread)
7603 (setq gnus-current-headers headers)
7604 (setq gnus-newsgroup-data data)
7605 (setq gnus-article-current gac)
7606 (setq gnus-summary-buffer summary)
7607 (setq gnus-article-buffer article-buffer)
7608 (setq gnus-original-article-buffer original)
7609 (setq gnus-current-score-file score-file)))))
7610
7611 (defun gnus-summary-last-article-p (&optional article)
7612 "Return whether ARTICLE is the last article in the buffer."
7613 (if (not (setq article (or article (gnus-summary-article-number))))
7614 t ; All non-existant numbers are the last article. :-)
7615 (not (cdr (gnus-data-find-list article)))))
7616
7617 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
7618 "Insert a dummy root in the summary buffer."
7619 (beginning-of-line)
7620 (gnus-add-text-properties
7621 (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
7622 (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
7623
7624 (defun gnus-make-thread-indent-array ()
7625 (let ((n 200))
7626 (unless (and gnus-thread-indent-array
7627 (= gnus-thread-indent-level gnus-thread-indent-array-level))
7628 (setq gnus-thread-indent-array (make-vector 201 "")
7629 gnus-thread-indent-array-level gnus-thread-indent-level)
7630 (while (>= n 0)
7631 (aset gnus-thread-indent-array n
7632 (make-string (* n gnus-thread-indent-level) ? ))
7633 (setq n (1- n))))))
7634
7635 (defun gnus-summary-insert-line
7636 (gnus-tmp-header gnus-tmp-level gnus-tmp-current gnus-tmp-unread
7637 gnus-tmp-replied gnus-tmp-expirable gnus-tmp-subject-or-nil
7638 &optional gnus-tmp-dummy gnus-tmp-score gnus-tmp-process)
7639 (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
7640 (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
7641 (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
7642 (gnus-tmp-score-char
7643 (if (or (null gnus-summary-default-score)
7644 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
7645 gnus-summary-zcore-fuzz)) ?
7646 (if (< gnus-tmp-score gnus-summary-default-score)
7647 gnus-score-below-mark gnus-score-over-mark)))
7648 (gnus-tmp-replied (cond (gnus-tmp-process gnus-process-mark)
7649 ((memq gnus-tmp-current gnus-newsgroup-cached)
7650 gnus-cached-mark)
7651 (gnus-tmp-replied gnus-replied-mark)
7652 ((memq gnus-tmp-current gnus-newsgroup-saved)
7653 gnus-saved-mark)
7654 (t gnus-unread-mark)))
7655 (gnus-tmp-from (mail-header-from gnus-tmp-header))
7656 (gnus-tmp-name
7657 (cond
7658 ((string-match "(.+)" gnus-tmp-from)
7659 (substring gnus-tmp-from
7660 (1+ (match-beginning 0)) (1- (match-end 0))))
7661 ((string-match "<[^>]+> *$" gnus-tmp-from)
7662 (let ((beg (match-beginning 0)))
7663 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
7664 (substring gnus-tmp-from (1+ (match-beginning 0))
7665 (1- (match-end 0))))
7666 (substring gnus-tmp-from 0 beg))))
7667 (t gnus-tmp-from)))
7668 (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
7669 (gnus-tmp-number (mail-header-number gnus-tmp-header))
7670 (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
7671 (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
7672 (buffer-read-only nil))
7673 (when (string= gnus-tmp-name "")
7674 (setq gnus-tmp-name gnus-tmp-from))
7675 (or (numberp gnus-tmp-lines) (setq gnus-tmp-lines 0))
7676 (gnus-put-text-property
7677 (point)
7678 (progn (eval gnus-summary-line-format-spec) (point))
7679 'gnus-number gnus-tmp-number)
7680 (when (gnus-visual-p 'summary-highlight 'highlight)
7681 (forward-line -1)
7682 (run-hooks 'gnus-summary-update-hook)
7683 (forward-line 1))))
7684
7685 (defun gnus-summary-update-line (&optional dont-update)
7686 ;; Update summary line after change.
7687 (when (and gnus-summary-default-score
7688 (not gnus-summary-inhibit-highlight))
7689 (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
7690 (article (gnus-summary-article-number))
7691 (score (gnus-summary-article-score article)))
7692 (unless dont-update
7693 (if (and gnus-summary-mark-below
7694 (< (gnus-summary-article-score)
7695 gnus-summary-mark-below))
7696 ;; This article has a low score, so we mark it as read.
7697 (when (memq article gnus-newsgroup-unreads)
7698 (gnus-summary-mark-article-as-read gnus-low-score-mark))
7699 (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
7700 ;; This article was previously marked as read on account
7701 ;; of a low score, but now it has risen, so we mark it as
7702 ;; unread.
7703 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
7704 (gnus-summary-update-mark
7705 (if (or (null gnus-summary-default-score)
7706 (<= (abs (- score gnus-summary-default-score))
7707 gnus-summary-zcore-fuzz)) ?
7708 (if (< score gnus-summary-default-score)
7709 gnus-score-below-mark gnus-score-over-mark)) 'score))
7710 ;; Do visual highlighting.
7711 (when (gnus-visual-p 'summary-highlight 'highlight)
7712 (run-hooks 'gnus-summary-update-hook)))))
7713
7714 (defvar gnus-tmp-new-adopts nil)
7715
7716 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
7717 ;; Sum up all elements (and sub-elements) in a list.
7718 (let* ((number
7719 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
7720 (cond
7721 ((and (consp thread) (cdr thread))
7722 (apply
7723 '+ 1 (mapcar
7724 'gnus-summary-number-of-articles-in-thread (cdr thread))))
7725 ((null thread)
7726 1)
7727 ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
7728 1)
7729 (t 0))))
7730 (when (and level (zerop level) gnus-tmp-new-adopts)
7731 (incf number
7732 (apply '+ (mapcar
7733 'gnus-summary-number-of-articles-in-thread
7734 gnus-tmp-new-adopts))))
7735 (if char
7736 (if (> number 1) gnus-not-empty-thread-mark
7737 gnus-empty-thread-mark)
7738 number)))
7739
7740 (defun gnus-summary-set-local-parameters (group)
7741 "Go through the local params of GROUP and set all variable specs in that list."
7742 (let ((params (gnus-info-params (gnus-get-info group)))
7743 elem)
7744 (while params
7745 (setq elem (car params)
7746 params (cdr params))
7747 (and (consp elem) ; Has to be a cons.
7748 (consp (cdr elem)) ; The cdr has to be a list.
7749 (symbolp (car elem)) ; Has to be a symbol in there.
7750 (not (memq (car elem)
7751 '(quit-config to-address to-list to-group)))
7752 (progn ; So we set it.
7753 (make-local-variable (car elem))
7754 (set (car elem) (eval (nth 1 elem))))))))
7755
7756 (defun gnus-summary-read-group (group &optional show-all no-article
7757 kill-buffer no-display)
7758 "Start reading news in newsgroup GROUP.
7759 If SHOW-ALL is non-nil, already read articles are also listed.
7760 If NO-ARTICLE is non-nil, no article is selected initially.
7761 If NO-DISPLAY, don't generate a summary buffer."
7762 (gnus-message 5 "Retrieving newsgroup: %s..." group)
7763 (let* ((new-group (gnus-summary-setup-buffer group))
7764 (quit-config (gnus-group-quit-config group))
7765 (did-select (and new-group (gnus-select-newsgroup group show-all))))
7766 (cond
7767 ;; This summary buffer exists already, so we just select it.
7768 ((not new-group)
7769 (gnus-set-global-variables)
7770 (when kill-buffer
7771 (gnus-kill-or-deaden-summary kill-buffer))
7772 (gnus-configure-windows 'summary 'force)
7773 (gnus-set-mode-line 'summary)
7774 (gnus-summary-position-point)
7775 (message "")
7776 t)
7777 ;; We couldn't select this group.
7778 ((null did-select)
7779 (when (and (eq major-mode 'gnus-summary-mode)
7780 (not (equal (current-buffer) kill-buffer)))
7781 (kill-buffer (current-buffer))
7782 (if (not quit-config)
7783 (progn
7784 (set-buffer gnus-group-buffer)
7785 (gnus-group-jump-to-group group)
7786 (gnus-group-next-unread-group 1))
7787 (if (not (buffer-name (car quit-config)))
7788 (gnus-configure-windows 'group 'force)
7789 (set-buffer (car quit-config))
7790 (and (eq major-mode 'gnus-summary-mode)
7791 (gnus-set-global-variables))
7792 (gnus-configure-windows (cdr quit-config)))))
7793 (gnus-message 3 "Can't select group")
7794 nil)
7795 ;; The user did a `C-g' while prompting for number of articles,
7796 ;; so we exit this group.
7797 ((eq did-select 'quit)
7798 (and (eq major-mode 'gnus-summary-mode)
7799 (not (equal (current-buffer) kill-buffer))
7800 (kill-buffer (current-buffer)))
7801 (when kill-buffer
7802 (gnus-kill-or-deaden-summary kill-buffer))
7803 (if (not quit-config)
7804 (progn
7805 (set-buffer gnus-group-buffer)
7806 (gnus-group-jump-to-group group)
7807 (gnus-group-next-unread-group 1)
7808 (gnus-configure-windows 'group 'force))
7809 (if (not (buffer-name (car quit-config)))
7810 (gnus-configure-windows 'group 'force)
7811 (set-buffer (car quit-config))
7812 (and (eq major-mode 'gnus-summary-mode)
7813 (gnus-set-global-variables))
7814 (gnus-configure-windows (cdr quit-config))))
7815 ;; Finally signal the quit.
7816 (signal 'quit nil))
7817 ;; The group was successfully selected.
7818 (t
7819 (gnus-set-global-variables)
7820 ;; Save the active value in effect when the group was entered.
7821 (setq gnus-newsgroup-active
7822 (gnus-copy-sequence
7823 (gnus-active gnus-newsgroup-name)))
7824 ;; You can change the summary buffer in some way with this hook.
7825 (run-hooks 'gnus-select-group-hook)
7826 ;; Set any local variables in the group parameters.
7827 (gnus-summary-set-local-parameters gnus-newsgroup-name)
7828 (gnus-update-format-specifications)
7829 ;; Do score processing.
7830 (when gnus-use-scoring
7831 (gnus-possibly-score-headers))
7832 ;; Check whether to fill in the gaps in the threads.
7833 (when gnus-build-sparse-threads
7834 (gnus-build-sparse-threads))
7835 ;; Find the initial limit.
7836 (if gnus-show-threads
7837 (if show-all
7838 (let ((gnus-newsgroup-dormant nil))
7839 (gnus-summary-initial-limit show-all))
7840 (gnus-summary-initial-limit show-all))
7841 (setq gnus-newsgroup-limit
7842 (mapcar
7843 (lambda (header) (mail-header-number header))
7844 gnus-newsgroup-headers)))
7845 ;; Generate the summary buffer.
7846 (unless no-display
7847 (gnus-summary-prepare))
7848 (when gnus-use-trees
7849 (gnus-tree-open group)
7850 (setq gnus-summary-highlight-line-function
7851 'gnus-tree-highlight-article))
7852 ;; If the summary buffer is empty, but there are some low-scored
7853 ;; articles or some excluded dormants, we include these in the
7854 ;; buffer.
7855 (when (and (zerop (buffer-size))
7856 (not no-display))
7857 (cond (gnus-newsgroup-dormant
7858 (gnus-summary-limit-include-dormant))
7859 ((and gnus-newsgroup-scored show-all)
7860 (gnus-summary-limit-include-expunged))))
7861 ;; Function `gnus-apply-kill-file' must be called in this hook.
7862 (run-hooks 'gnus-apply-kill-hook)
7863 (if (and (zerop (buffer-size))
7864 (not no-display))
7865 (progn
7866 ;; This newsgroup is empty.
7867 (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
7868 (gnus-message 6 "No unread news")
7869 (when kill-buffer
7870 (gnus-kill-or-deaden-summary kill-buffer))
7871 ;; Return nil from this function.
7872 nil)
7873 ;; Hide conversation thread subtrees. We cannot do this in
7874 ;; gnus-summary-prepare-hook since kill processing may not
7875 ;; work with hidden articles.
7876 (and gnus-show-threads
7877 gnus-thread-hide-subtree
7878 (gnus-summary-hide-all-threads))
7879 ;; Show first unread article if requested.
7880 (if (and (not no-article)
7881 (not no-display)
7882 gnus-newsgroup-unreads
7883 gnus-auto-select-first)
7884 (unless (if (eq gnus-auto-select-first 'best)
7885 (gnus-summary-best-unread-article)
7886 (gnus-summary-first-unread-article))
7887 (gnus-configure-windows 'summary))
7888 ;; Don't select any articles, just move point to the first
7889 ;; article in the group.
7890 (goto-char (point-min))
7891 (gnus-summary-position-point)
7892 (gnus-set-mode-line 'summary)
7893 (gnus-configure-windows 'summary 'force))
7894 ;; If we are in async mode, we send some info to the backend.
7895 (when gnus-newsgroup-async
7896 (gnus-request-asynchronous gnus-newsgroup-name gnus-newsgroup-data))
7897 (when kill-buffer
7898 (gnus-kill-or-deaden-summary kill-buffer))
7899 (when (get-buffer-window gnus-group-buffer t)
7900 ;; Gotta use windows, because recenter does wierd stuff if
7901 ;; the current buffer ain't the displayed window.
7902 (let ((owin (selected-window)))
7903 (select-window (get-buffer-window gnus-group-buffer t))
7904 (when (gnus-group-goto-group group)
7905 (recenter))
7906 (select-window owin))))
7907 ;; Mark this buffer as "prepared".
7908 (setq gnus-newsgroup-prepared t)
7909 t))))
7910
7911 (defun gnus-summary-prepare ()
7912 "Generate the summary buffer."
7913 (let ((buffer-read-only nil))
7914 (erase-buffer)
7915 (setq gnus-newsgroup-data nil
7916 gnus-newsgroup-data-reverse nil)
7917 (run-hooks 'gnus-summary-generate-hook)
7918 ;; Generate the buffer, either with threads or without.
7919 (when gnus-newsgroup-headers
7920 (gnus-summary-prepare-threads
7921 (if gnus-show-threads
7922 (gnus-sort-gathered-threads
7923 (funcall gnus-summary-thread-gathering-function
7924 (gnus-sort-threads
7925 (gnus-cut-threads (gnus-make-threads)))))
7926 ;; Unthreaded display.
7927 (gnus-sort-articles gnus-newsgroup-headers))))
7928 (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
7929 ;; Call hooks for modifying summary buffer.
7930 (goto-char (point-min))
7931 (run-hooks 'gnus-summary-prepare-hook)))
7932
7933 (defun gnus-gather-threads-by-subject (threads)
7934 "Gather threads by looking at Subject headers."
7935 (if (not gnus-summary-make-false-root)
7936 threads
7937 (let ((hashtb (gnus-make-hashtable 1023))
7938 (prev threads)
7939 (result threads)
7940 subject hthread whole-subject)
7941 (while threads
7942 (setq whole-subject (mail-header-subject (caar threads)))
7943 (setq subject
7944 (cond
7945 ;; Truncate the subject.
7946 ((numberp gnus-summary-gather-subject-limit)
7947 (setq subject (gnus-simplify-subject-re whole-subject))
7948 (if (> (length subject) gnus-summary-gather-subject-limit)
7949 (substring subject 0 gnus-summary-gather-subject-limit)
7950 subject))
7951 ;; Fuzzily simplify it.
7952 ((eq 'fuzzy gnus-summary-gather-subject-limit)
7953 (gnus-simplify-subject-fuzzy whole-subject))
7954 ;; Just remove the leading "Re:".
7955 (t
7956 (gnus-simplify-subject-re whole-subject))))
7957
7958 (if (and gnus-summary-gather-exclude-subject
7959 (string-match gnus-summary-gather-exclude-subject
7960 subject))
7961 () ; We don't want to do anything with this article.
7962 ;; We simplify the subject before looking it up in the
7963 ;; hash table.
7964
7965 (if (setq hthread (gnus-gethash subject hashtb))
7966 (progn
7967 ;; We enter a dummy root into the thread, if we
7968 ;; haven't done that already.
7969 (unless (stringp (caar hthread))
7970 (setcar hthread (list whole-subject (car hthread))))
7971 ;; We add this new gathered thread to this gathered
7972 ;; thread.
7973 (setcdr (car hthread)
7974 (nconc (cdar hthread) (list (car threads))))
7975 ;; Remove it from the list of threads.
7976 (setcdr prev (cdr threads))
7977 (setq threads prev))
7978 ;; Enter this thread into the hash table.
7979 (gnus-sethash subject threads hashtb)))
7980 (setq prev threads)
7981 (setq threads (cdr threads)))
7982 result)))
7983
7984 (defun gnus-gather-threads-by-references (threads)
7985 "Gather threads by looking at References headers."
7986 (let ((idhashtb (gnus-make-hashtable 1023))
7987 (thhashtb (gnus-make-hashtable 1023))
7988 (prev threads)
7989 (result threads)
7990 ids references id gthread gid entered)
7991 (while threads
7992 (when (setq references (mail-header-references (caar threads)))
7993 (setq id (mail-header-id (caar threads)))
7994 (setq ids (gnus-split-references references))
7995 (setq entered nil)
7996 (while ids
7997 (if (not (setq gid (gnus-gethash (car ids) idhashtb)))
7998 (progn
7999 (gnus-sethash (car ids) id idhashtb)
8000 (gnus-sethash id threads thhashtb))
8001 (setq gthread (gnus-gethash gid thhashtb))
8002 (unless entered
8003 ;; We enter a dummy root into the thread, if we
8004 ;; haven't done that already.
8005 (unless (stringp (caar gthread))
8006 (setcar gthread (list (mail-header-subject (caar gthread))
8007 (car gthread))))
8008 ;; We add this new gathered thread to this gathered
8009 ;; thread.
8010 (setcdr (car gthread)
8011 (nconc (cdar gthread) (list (car threads)))))
8012 ;; Add it into the thread hash table.
8013 (gnus-sethash id gthread thhashtb)
8014 (setq entered t)
8015 ;; Remove it from the list of threads.
8016 (setcdr prev (cdr threads))
8017 (setq threads prev))
8018 (setq ids (cdr ids))))
8019 (setq prev threads)
8020 (setq threads (cdr threads)))
8021 result))
8022
8023 (defun gnus-sort-gathered-threads (threads)
8024 "Sort subtreads inside each gathered thread by article number."
8025 (let ((result threads))
8026 (while threads
8027 (when (stringp (caar threads))
8028 (setcdr (car threads)
8029 (sort (cdar threads) 'gnus-thread-sort-by-number)))
8030 (setq threads (cdr threads)))
8031 result))
8032
8033 (defun gnus-make-threads ()
8034 "Go through the dependency hashtb and find the roots. Return all threads."
8035 (let (threads)
8036 (mapatoms
8037 (lambda (refs)
8038 (unless (car (symbol-value refs))
8039 ;; These threads do not refer back to any other articles,
8040 ;; so they're roots.
8041 (setq threads (append (cdr (symbol-value refs)) threads))))
8042 gnus-newsgroup-dependencies)
8043 threads))
8044
8045 (defun gnus-build-sparse-threads ()
8046 (let ((headers gnus-newsgroup-headers)
8047 (deps gnus-newsgroup-dependencies)
8048 header references generation relations
8049 cthread subject child end pthread relation)
8050 ;; First we create an alist of generations/relations, where
8051 ;; generations is how much we trust the ralation, and the relation
8052 ;; is parent/child.
8053 (gnus-message 7 "Making sparse threads...")
8054 (save-excursion
8055 (nnheader-set-temp-buffer " *gnus sparse threads*")
8056 (while (setq header (pop headers))
8057 (when (and (setq references (mail-header-references header))
8058 (not (string= references "")))
8059 (insert references)
8060 (setq child (mail-header-id header)
8061 subject (mail-header-subject header))
8062 (setq generation 0)
8063 (while (search-backward ">" nil t)
8064 (setq end (1+ (point)))
8065 (when (search-backward "<" nil t)
8066 (push (list (incf generation)
8067 child (setq child (buffer-substring (point) end))
8068 subject)
8069 relations)))
8070 (push (list (1+ generation) child nil subject) relations)
8071 (erase-buffer)))
8072 (kill-buffer (current-buffer)))
8073 ;; Sort over trustworthiness.
8074 (setq relations (sort relations (lambda (r1 r2) (< (car r1) (car r2)))))
8075 (while (setq relation (pop relations))
8076 (when (if (boundp (setq cthread (intern (cadr relation) deps)))
8077 (unless (car (symbol-value cthread))
8078 ;; Make this article the parent of these threads.
8079 (setcar (symbol-value cthread)
8080 (vector gnus-reffed-article-number
8081 (cadddr relation)
8082 "" ""
8083 (cadr relation)
8084 (or (caddr relation) "") 0 0 "")))
8085 (set cthread (list (vector gnus-reffed-article-number
8086 (cadddr relation)
8087 "" "" (cadr relation)
8088 (or (caddr relation) "") 0 0 ""))))
8089 (push gnus-reffed-article-number gnus-newsgroup-limit)
8090 (push gnus-reffed-article-number gnus-newsgroup-sparse)
8091 (push (cons gnus-reffed-article-number gnus-sparse-mark)
8092 gnus-newsgroup-reads)
8093 (decf gnus-reffed-article-number)
8094 ;; Make this new thread the child of its parent.
8095 (if (boundp (setq pthread (intern (or (caddr relation) "none") deps)))
8096 (setcdr (symbol-value pthread)
8097 (nconc (cdr (symbol-value pthread))
8098 (list (symbol-value cthread))))
8099 (set pthread (list nil (symbol-value cthread))))))
8100 (gnus-message 7 "Making sparse threads...done")))
8101
8102 (defun gnus-build-old-threads ()
8103 ;; Look at all the articles that refer back to old articles, and
8104 ;; fetch the headers for the articles that aren't there. This will
8105 ;; build complete threads - if the roots haven't been expired by the
8106 ;; server, that is.
8107 (let (id heads)
8108 (mapatoms
8109 (lambda (refs)
8110 (when (not (car (symbol-value refs)))
8111 (setq heads (cdr (symbol-value refs)))
8112 (while heads
8113 (if (memq (mail-header-number (caar heads))
8114 gnus-newsgroup-dormant)
8115 (setq heads (cdr heads))
8116 (setq id (symbol-name refs))
8117 (while (and (setq id (gnus-build-get-header id))
8118 (not (car (gnus-gethash
8119 id gnus-newsgroup-dependencies)))))
8120 (setq heads nil)))))
8121 gnus-newsgroup-dependencies)))
8122
8123 (defun gnus-build-get-header (id)
8124 ;; Look through the buffer of NOV lines and find the header to
8125 ;; ID. Enter this line into the dependencies hash table, and return
8126 ;; the id of the parent article (if any).
8127 (let ((deps gnus-newsgroup-dependencies)
8128 found header)
8129 (prog1
8130 (save-excursion
8131 (set-buffer nntp-server-buffer)
8132 (goto-char (point-min))
8133 (while (and (not found) (search-forward id nil t))
8134 (beginning-of-line)
8135 (setq found (looking-at
8136 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
8137 (regexp-quote id))))
8138 (or found (beginning-of-line 2)))
8139 (when found
8140 (beginning-of-line)
8141 (and
8142 (setq header (gnus-nov-parse-line
8143 (read (current-buffer)) deps))
8144 (gnus-parent-id (mail-header-references header)))))
8145 (when header
8146 (let ((number (mail-header-number header)))
8147 (push number gnus-newsgroup-limit)
8148 (push header gnus-newsgroup-headers)
8149 (if (memq number gnus-newsgroup-unselected)
8150 (progn
8151 (push number gnus-newsgroup-unreads)
8152 (setq gnus-newsgroup-unselected
8153 (delq number gnus-newsgroup-unselected)))
8154 (push number gnus-newsgroup-ancient)))))))
8155
8156 (defun gnus-summary-update-article (article &optional iheader)
8157 "Update ARTICLE in the summary buffer."
8158 (set-buffer gnus-summary-buffer)
8159 (let* ((header (or iheader (gnus-summary-article-header article)))
8160 (id (mail-header-id header))
8161 (data (gnus-data-find article))
8162 (thread (gnus-id-to-thread id))
8163 (references (mail-header-references header))
8164 (parent
8165 (gnus-id-to-thread
8166 (or (gnus-parent-id
8167 (if (and references
8168 (not (equal "" references)))
8169 references))
8170 "none")))
8171 (buffer-read-only nil)
8172 (old (car thread))
8173 (number (mail-header-number header))
8174 pos)
8175 (when thread
8176 ;; !!! Should this be in or not?
8177 (unless iheader
8178 (setcar thread nil))
8179 (when parent
8180 (delq thread parent))
8181 (if (gnus-summary-insert-subject id header iheader)
8182 ;; Set the (possibly) new article number in the data structure.
8183 (gnus-data-set-number data (gnus-id-to-article id))
8184 (setcar thread old)
8185 nil))))
8186
8187 (defun gnus-rebuild-thread (id)
8188 "Rebuild the thread containing ID."
8189 (let ((buffer-read-only nil)
8190 current thread data)
8191 (if (not gnus-show-threads)
8192 (setq thread (list (car (gnus-id-to-thread id))))
8193 ;; Get the thread this article is part of.
8194 (setq thread (gnus-remove-thread id)))
8195 (setq current (save-excursion
8196 (and (zerop (forward-line -1))
8197 (gnus-summary-article-number))))
8198 ;; If this is a gathered thread, we have to go some re-gathering.
8199 (when (stringp (car thread))
8200 (let ((subject (car thread))
8201 roots thr)
8202 (setq thread (cdr thread))
8203 (while thread
8204 (unless (memq (setq thr (gnus-id-to-thread
8205 (gnus-root-id
8206 (mail-header-id (caar thread)))))
8207 roots)
8208 (push thr roots))
8209 (setq thread (cdr thread)))
8210 ;; We now have all (unique) roots.
8211 (if (= (length roots) 1)
8212 ;; All the loose roots are now one solid root.
8213 (setq thread (car roots))
8214 (setq thread (cons subject (gnus-sort-threads roots))))))
8215 (let (threads)
8216 ;; We then insert this thread into the summary buffer.
8217 (let (gnus-newsgroup-data gnus-newsgroup-threads)
8218 (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
8219 (setq data (nreverse gnus-newsgroup-data))
8220 (setq threads gnus-newsgroup-threads))
8221 ;; We splice the new data into the data structure.
8222 (gnus-data-enter-list current data)
8223 (gnus-data-compute-positions)
8224 (setq gnus-newsgroup-threads (nconc threads gnus-newsgroup-threads)))))
8225
8226 (defun gnus-number-to-header (number)
8227 "Return the header for article NUMBER."
8228 (let ((headers gnus-newsgroup-headers))
8229 (while (and headers
8230 (not (= number (mail-header-number (car headers)))))
8231 (pop headers))
8232 (when headers
8233 (car headers))))
8234
8235 (defun gnus-id-to-thread (id)
8236 "Return the (sub-)thread where ID appears."
8237 (gnus-gethash id gnus-newsgroup-dependencies))
8238
8239 (defun gnus-id-to-article (id)
8240 "Return the article number of ID."
8241 (let ((thread (gnus-id-to-thread id)))
8242 (when (and thread
8243 (car thread))
8244 (mail-header-number (car thread)))))
8245
8246 (defun gnus-id-to-header (id)
8247 "Return the article headers of ID."
8248 (car (gnus-id-to-thread id)))
8249
8250 (defun gnus-article-displayed-root-p (article)
8251 "Say whether ARTICLE is a root(ish) article."
8252 (let ((level (gnus-summary-thread-level article))
8253 (refs (mail-header-references (gnus-summary-article-header article)))
8254 particle)
8255 (cond
8256 ((null level) nil)
8257 ((zerop level) t)
8258 ((null refs) t)
8259 ((null (gnus-parent-id refs)) t)
8260 ((and (= 1 level)
8261 (null (setq particle (gnus-id-to-article
8262 (gnus-parent-id refs))))
8263 (null (gnus-summary-thread-level particle)))))))
8264
8265 (defun gnus-root-id (id)
8266 "Return the id of the root of the thread where ID appears."
8267 (let (last-id prev)
8268 (while (and id (setq prev (car (gnus-gethash
8269 id gnus-newsgroup-dependencies))))
8270 (setq last-id id
8271 id (gnus-parent-id (mail-header-references prev))))
8272 last-id))
8273
8274 (defun gnus-remove-thread (id &optional dont-remove)
8275 "Remove the thread that has ID in it."
8276 (let ((dep gnus-newsgroup-dependencies)
8277 headers thread last-id)
8278 ;; First go up in this thread until we find the root.
8279 (setq last-id (gnus-root-id id))
8280 (setq headers (list (car (gnus-id-to-thread last-id))
8281 (caadr (gnus-id-to-thread last-id))))
8282 ;; We have now found the real root of this thread. It might have
8283 ;; been gathered into some loose thread, so we have to search
8284 ;; through the threads to find the thread we wanted.
8285 (let ((threads gnus-newsgroup-threads)
8286 sub)
8287 (while threads
8288 (setq sub (car threads))
8289 (if (stringp (car sub))
8290 ;; This is a gathered threads, so we look at the roots
8291 ;; below it to find whether this article in in this
8292 ;; gathered root.
8293 (progn
8294 (setq sub (cdr sub))
8295 (while sub
8296 (when (member (caar sub) headers)
8297 (setq thread (car threads)
8298 threads nil
8299 sub nil))
8300 (setq sub (cdr sub))))
8301 ;; It's an ordinary thread, so we check it.
8302 (when (eq (car sub) (car headers))
8303 (setq thread sub
8304 threads nil)))
8305 (setq threads (cdr threads)))
8306 ;; If this article is in no thread, then it's a root.
8307 (if thread
8308 (unless dont-remove
8309 (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
8310 (setq thread (gnus-gethash last-id dep)))
8311 (when thread
8312 (prog1
8313 thread ; We return this thread.
8314 (unless dont-remove
8315 (if (stringp (car thread))
8316 (progn
8317 ;; If we use dummy roots, then we have to remove the
8318 ;; dummy root as well.
8319 (when (eq gnus-summary-make-false-root 'dummy)
8320 ;; Uhm.
8321 )
8322 (setq thread (cdr thread))
8323 (while thread
8324 (gnus-remove-thread-1 (car thread))
8325 (setq thread (cdr thread))))
8326 (gnus-remove-thread-1 thread))))))))
8327
8328 (defun gnus-remove-thread-1 (thread)
8329 "Remove the thread THREAD recursively."
8330 (let ((number (mail-header-number (car thread)))
8331 pos)
8332 (when (setq pos (text-property-any
8333 (point-min) (point-max) 'gnus-number number))
8334 (goto-char pos)
8335 (gnus-delete-line)
8336 (gnus-data-remove number))
8337 (setq thread (cdr thread))
8338 (while thread
8339 (gnus-remove-thread-1 (pop thread)))))
8340
8341 (defun gnus-sort-threads (threads)
8342 "Sort THREADS."
8343 (if (not gnus-thread-sort-functions)
8344 threads
8345 (let ((func (if (= 1 (length gnus-thread-sort-functions))
8346 (car gnus-thread-sort-functions)
8347 `(lambda (t1 t2)
8348 ,(gnus-make-sort-function
8349 (reverse gnus-thread-sort-functions))))))
8350 (gnus-message 7 "Sorting threads...")
8351 (prog1
8352 (sort threads func)
8353 (gnus-message 7 "Sorting threads...done")))))
8354
8355 (defun gnus-sort-articles (articles)
8356 "Sort ARTICLES."
8357 (when gnus-article-sort-functions
8358 (let ((func (if (= 1 (length gnus-article-sort-functions))
8359 (car gnus-article-sort-functions)
8360 `(lambda (t1 t2)
8361 ,(gnus-make-sort-function
8362 (reverse gnus-article-sort-functions))))))
8363 (gnus-message 7 "Sorting articles...")
8364 (prog1
8365 (setq gnus-newsgroup-headers (sort articles func))
8366 (gnus-message 7 "Sorting articles...done")))))
8367
8368 (defun gnus-make-sort-function (funs)
8369 "Return a composite sort condition based on the functions in FUNC."
8370 (if (cdr funs)
8371 `(or (,(car funs) t1 t2)
8372 (and (not (,(car funs) t2 t1))
8373 ,(gnus-make-sort-function (cdr funs))))
8374 `(,(car funs) t1 t2)))
8375
8376 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
8377 (defmacro gnus-thread-header (thread)
8378 ;; Return header of first article in THREAD.
8379 ;; Note that THREAD must never, ever be anything else than a variable -
8380 ;; using some other form will lead to serious barfage.
8381 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
8382 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
8383 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
8384 (vector thread) 2))
8385
8386 (defsubst gnus-article-sort-by-number (h1 h2)
8387 "Sort articles by article number."
8388 (< (mail-header-number h1)
8389 (mail-header-number h2)))
8390
8391 (defun gnus-thread-sort-by-number (h1 h2)
8392 "Sort threads by root article number."
8393 (gnus-article-sort-by-number
8394 (gnus-thread-header h1) (gnus-thread-header h2)))
8395
8396 (defsubst gnus-article-sort-by-author (h1 h2)
8397 "Sort articles by root author."
8398 (string-lessp
8399 (let ((extract (funcall
8400 gnus-extract-address-components
8401 (mail-header-from h1))))
8402 (or (car extract) (cdr extract)))
8403 (let ((extract (funcall
8404 gnus-extract-address-components
8405 (mail-header-from h2))))
8406 (or (car extract) (cdr extract)))))
8407
8408 (defun gnus-thread-sort-by-author (h1 h2)
8409 "Sort threads by root author."
8410 (gnus-article-sort-by-author
8411 (gnus-thread-header h1) (gnus-thread-header h2)))
8412
8413 (defsubst gnus-article-sort-by-subject (h1 h2)
8414 "Sort articles by root subject."
8415 (string-lessp
8416 (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
8417 (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
8418
8419 (defun gnus-thread-sort-by-subject (h1 h2)
8420 "Sort threads by root subject."
8421 (gnus-article-sort-by-subject
8422 (gnus-thread-header h1) (gnus-thread-header h2)))
8423
8424 (defsubst gnus-article-sort-by-date (h1 h2)
8425 "Sort articles by root article date."
8426 (string-lessp
8427 (inline (gnus-sortable-date (mail-header-date h1)))
8428 (inline (gnus-sortable-date (mail-header-date h2)))))
8429
8430 (defun gnus-thread-sort-by-date (h1 h2)
8431 "Sort threads by root article date."
8432 (gnus-article-sort-by-date
8433 (gnus-thread-header h1) (gnus-thread-header h2)))
8434
8435 (defsubst gnus-article-sort-by-score (h1 h2)
8436 "Sort articles by root article score.
8437 Unscored articles will be counted as having a score of zero."
8438 (> (or (cdr (assq (mail-header-number h1)
8439 gnus-newsgroup-scored))
8440 gnus-summary-default-score 0)
8441 (or (cdr (assq (mail-header-number h2)
8442 gnus-newsgroup-scored))
8443 gnus-summary-default-score 0)))
8444
8445 (defun gnus-thread-sort-by-score (h1 h2)
8446 "Sort threads by root article score."
8447 (gnus-article-sort-by-score
8448 (gnus-thread-header h1) (gnus-thread-header h2)))
8449
8450 (defun gnus-thread-sort-by-total-score (h1 h2)
8451 "Sort threads by the sum of all scores in the thread.
8452 Unscored articles will be counted as having a score of zero."
8453 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
8454
8455 (defun gnus-thread-total-score (thread)
8456 ;; This function find the total score of THREAD.
8457 (cond ((null thread)
8458 0)
8459 ((consp thread)
8460 (if (stringp (car thread))
8461 (apply gnus-thread-score-function 0
8462 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
8463 (gnus-thread-total-score-1 thread)))
8464 (t
8465 (gnus-thread-total-score-1 (list thread)))))
8466
8467 (defun gnus-thread-total-score-1 (root)
8468 ;; This function find the total score of the thread below ROOT.
8469 (setq root (car root))
8470 (apply gnus-thread-score-function
8471 (or (append
8472 (mapcar 'gnus-thread-total-score
8473 (cdr (gnus-gethash (mail-header-id root)
8474 gnus-newsgroup-dependencies)))
8475 (if (> (mail-header-number root) 0)
8476 (list (or (cdr (assq (mail-header-number root)
8477 gnus-newsgroup-scored))
8478 gnus-summary-default-score 0))))
8479 (list gnus-summary-default-score)
8480 '(0))))
8481
8482 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
8483 (defvar gnus-tmp-prev-subject nil)
8484 (defvar gnus-tmp-false-parent nil)
8485 (defvar gnus-tmp-root-expunged nil)
8486 (defvar gnus-tmp-dummy-line nil)
8487
8488 (defun gnus-summary-prepare-threads (threads)
8489 "Prepare summary buffer from THREADS and indentation LEVEL.
8490 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
8491 or a straight list of headers."
8492 (gnus-message 7 "Generating summary...")
8493
8494 (setq gnus-newsgroup-threads threads)
8495 (beginning-of-line)
8496
8497 (let ((gnus-tmp-level 0)
8498 (default-score (or gnus-summary-default-score 0))
8499 (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
8500 thread number subject stack state gnus-tmp-gathered beg-match
8501 new-roots gnus-tmp-new-adopts thread-end
8502 gnus-tmp-header gnus-tmp-unread
8503 gnus-tmp-replied gnus-tmp-subject-or-nil
8504 gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
8505 gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
8506 gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
8507
8508 (setq gnus-tmp-prev-subject nil)
8509
8510 (if (vectorp (car threads))
8511 ;; If this is a straight (sic) list of headers, then a
8512 ;; threaded summary display isn't required, so we just create
8513 ;; an unthreaded one.
8514 (gnus-summary-prepare-unthreaded threads)
8515
8516 ;; Do the threaded display.
8517
8518 (while (or threads stack gnus-tmp-new-adopts new-roots)
8519
8520 (if (and (= gnus-tmp-level 0)
8521 (not (setq gnus-tmp-dummy-line nil))
8522 (or (not stack)
8523 (= (caar stack) 0))
8524 (not gnus-tmp-false-parent)
8525 (or gnus-tmp-new-adopts new-roots))
8526 (if gnus-tmp-new-adopts
8527 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
8528 thread (list (car gnus-tmp-new-adopts))
8529 gnus-tmp-header (caar thread)
8530 gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
8531 (if new-roots
8532 (setq thread (list (car new-roots))
8533 gnus-tmp-header (caar thread)
8534 new-roots (cdr new-roots))))
8535
8536 (if threads
8537 ;; If there are some threads, we do them before the
8538 ;; threads on the stack.
8539 (setq thread threads
8540 gnus-tmp-header (caar thread))
8541 ;; There were no current threads, so we pop something off
8542 ;; the stack.
8543 (setq state (car stack)
8544 gnus-tmp-level (car state)
8545 thread (cdr state)
8546 stack (cdr stack)
8547 gnus-tmp-header (caar thread))))
8548
8549 (setq gnus-tmp-false-parent nil)
8550 (setq gnus-tmp-root-expunged nil)
8551 (setq thread-end nil)
8552
8553 (if (stringp gnus-tmp-header)
8554 ;; The header is a dummy root.
8555 (cond
8556 ((eq gnus-summary-make-false-root 'adopt)
8557 ;; We let the first article adopt the rest.
8558 (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
8559 (cddar thread)))
8560 (setq gnus-tmp-gathered
8561 (nconc (mapcar
8562 (lambda (h) (mail-header-number (car h)))
8563 (cddar thread))
8564 gnus-tmp-gathered))
8565 (setq thread (cons (list (caar thread)
8566 (cadar thread))
8567 (cdr thread)))
8568 (setq gnus-tmp-level -1
8569 gnus-tmp-false-parent t))
8570 ((eq gnus-summary-make-false-root 'empty)
8571 ;; We print adopted articles with empty subject fields.
8572 (setq gnus-tmp-gathered
8573 (nconc (mapcar
8574 (lambda (h) (mail-header-number (car h)))
8575 (cddar thread))
8576 gnus-tmp-gathered))
8577 (setq gnus-tmp-level -1))
8578 ((eq gnus-summary-make-false-root 'dummy)
8579 ;; We remember that we probably want to output a dummy
8580 ;; root.
8581 (setq gnus-tmp-dummy-line gnus-tmp-header)
8582 (setq gnus-tmp-prev-subject gnus-tmp-header))
8583 (t
8584 ;; We do not make a root for the gathered
8585 ;; sub-threads at all.
8586 (setq gnus-tmp-level -1)))
8587
8588 (setq number (mail-header-number gnus-tmp-header)
8589 subject (mail-header-subject gnus-tmp-header))
8590
8591 (cond
8592 ;; If the thread has changed subject, we might want to make
8593 ;; this subthread into a root.
8594 ((and (null gnus-thread-ignore-subject)
8595 (not (zerop gnus-tmp-level))
8596 gnus-tmp-prev-subject
8597 (not (inline
8598 (gnus-subject-equal gnus-tmp-prev-subject subject))))
8599 (setq new-roots (nconc new-roots (list (car thread)))
8600 thread-end t
8601 gnus-tmp-header nil))
8602 ;; If the article lies outside the current limit,
8603 ;; then we do not display it.
8604 ((and (not (memq number gnus-newsgroup-limit))
8605 (not gnus-tmp-dummy-line))
8606 (setq gnus-tmp-gathered
8607 (nconc (mapcar
8608 (lambda (h) (mail-header-number (car h)))
8609 (cdar thread))
8610 gnus-tmp-gathered))
8611 (setq gnus-tmp-new-adopts (if (cdar thread)
8612 (append gnus-tmp-new-adopts
8613 (cdar thread))
8614 gnus-tmp-new-adopts)
8615 thread-end t
8616 gnus-tmp-header nil)
8617 (when (zerop gnus-tmp-level)
8618 (setq gnus-tmp-root-expunged t)))
8619 ;; Perhaps this article is to be marked as read?
8620 ((and gnus-summary-mark-below
8621 (< (or (cdr (assq number gnus-newsgroup-scored))
8622 default-score)
8623 gnus-summary-mark-below)
8624 ;; Don't touch sparse articles.
8625 (not (memq number gnus-newsgroup-sparse))
8626 (not (memq number gnus-newsgroup-ancient)))
8627 (setq gnus-newsgroup-unreads
8628 (delq number gnus-newsgroup-unreads))
8629 (if gnus-newsgroup-auto-expire
8630 (push number gnus-newsgroup-expirable)
8631 (push (cons number gnus-low-score-mark)
8632 gnus-newsgroup-reads))))
8633
8634 (when gnus-tmp-header
8635 ;; We may have an old dummy line to output before this
8636 ;; article.
8637 (when gnus-tmp-dummy-line
8638 (gnus-summary-insert-dummy-line
8639 gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
8640 (setq gnus-tmp-dummy-line nil))
8641
8642 ;; Compute the mark.
8643 (setq
8644 gnus-tmp-unread
8645 (cond
8646 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
8647 ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
8648 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
8649 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
8650 (t (or (cdr (assq number gnus-newsgroup-reads))
8651 gnus-ancient-mark))))
8652
8653 (push (gnus-data-make number gnus-tmp-unread (1+ (point))
8654 gnus-tmp-header gnus-tmp-level)
8655 gnus-newsgroup-data)
8656
8657 ;; Actually insert the line.
8658 (setq
8659 gnus-tmp-subject-or-nil
8660 (cond
8661 ((and gnus-thread-ignore-subject
8662 gnus-tmp-prev-subject
8663 (not (inline (gnus-subject-equal
8664 gnus-tmp-prev-subject subject))))
8665 subject)
8666 ((zerop gnus-tmp-level)
8667 (if (and (eq gnus-summary-make-false-root 'empty)
8668 (memq number gnus-tmp-gathered)
8669 gnus-tmp-prev-subject
8670 (inline (gnus-subject-equal
8671 gnus-tmp-prev-subject subject)))
8672 gnus-summary-same-subject
8673 subject))
8674 (t gnus-summary-same-subject)))
8675 (if (and (eq gnus-summary-make-false-root 'adopt)
8676 (= gnus-tmp-level 1)
8677 (memq number gnus-tmp-gathered))
8678 (setq gnus-tmp-opening-bracket ?\<
8679 gnus-tmp-closing-bracket ?\>)
8680 (setq gnus-tmp-opening-bracket ?\[
8681 gnus-tmp-closing-bracket ?\]))
8682 (setq
8683 gnus-tmp-indentation
8684 (aref gnus-thread-indent-array gnus-tmp-level)
8685 gnus-tmp-lines (mail-header-lines gnus-tmp-header)
8686 gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
8687 gnus-summary-default-score 0)
8688 gnus-tmp-score-char
8689 (if (or (null gnus-summary-default-score)
8690 (<= (abs (- gnus-tmp-score gnus-summary-default-score))
8691 gnus-summary-zcore-fuzz)) ?
8692 (if (< gnus-tmp-score gnus-summary-default-score)
8693 gnus-score-below-mark gnus-score-over-mark))
8694 gnus-tmp-replied
8695 (cond ((memq number gnus-newsgroup-processable)
8696 gnus-process-mark)
8697 ((memq number gnus-newsgroup-cached)
8698 gnus-cached-mark)
8699 ((memq number gnus-newsgroup-replied)
8700 gnus-replied-mark)
8701 ((memq number gnus-newsgroup-saved)
8702 gnus-saved-mark)
8703 (t gnus-unread-mark))
8704 gnus-tmp-from (mail-header-from gnus-tmp-header)
8705 gnus-tmp-name
8706 (cond
8707 ((string-match "(.+)" gnus-tmp-from)
8708 (substring gnus-tmp-from
8709 (1+ (match-beginning 0)) (1- (match-end 0))))
8710 ((string-match "<[^>]+> *$" gnus-tmp-from)
8711 (setq beg-match (match-beginning 0))
8712 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
8713 (substring gnus-tmp-from (1+ (match-beginning 0))
8714 (1- (match-end 0))))
8715 (substring gnus-tmp-from 0 beg-match)))
8716 (t gnus-tmp-from)))
8717 (when (string= gnus-tmp-name "")
8718 (setq gnus-tmp-name gnus-tmp-from))
8719 (or (numberp gnus-tmp-lines) (setq gnus-tmp-lines 0))
8720 (gnus-put-text-property
8721 (point)
8722 (progn (eval gnus-summary-line-format-spec) (point))
8723 'gnus-number number)
8724 (when gnus-visual-p
8725 (forward-line -1)
8726 (run-hooks 'gnus-summary-update-hook)
8727 (forward-line 1))
8728
8729 (setq gnus-tmp-prev-subject subject)))
8730
8731 (when (nth 1 thread)
8732 (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
8733 (incf gnus-tmp-level)
8734 (setq threads (if thread-end nil (cdar thread)))
8735 (unless threads
8736 (setq gnus-tmp-level 0)))))
8737 (gnus-message 7 "Generating summary...done"))
8738
8739 (defun gnus-summary-prepare-unthreaded (headers)
8740 "Generate an unthreaded summary buffer based on HEADERS."
8741 (let (header number mark)
8742
8743 (while headers
8744 ;; We may have to root out some bad articles...
8745 (when (memq (setq number (mail-header-number
8746 (setq header (pop headers))))
8747 gnus-newsgroup-limit)
8748 ;; Mark article as read when it has a low score.
8749 (when (and gnus-summary-mark-below
8750 (< (or (cdr (assq number gnus-newsgroup-scored))
8751 gnus-summary-default-score 0)
8752 gnus-summary-mark-below)
8753 (not (memq number gnus-newsgroup-ancient)))
8754 (setq gnus-newsgroup-unreads
8755 (delq number gnus-newsgroup-unreads))
8756 (if gnus-newsgroup-auto-expire
8757 (push number gnus-newsgroup-expirable)
8758 (push (cons number gnus-low-score-mark)
8759 gnus-newsgroup-reads)))
8760
8761 (setq mark
8762 (cond
8763 ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
8764 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
8765 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
8766 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
8767 (t (or (cdr (assq number gnus-newsgroup-reads))
8768 gnus-ancient-mark))))
8769 (setq gnus-newsgroup-data
8770 (cons (gnus-data-make number mark (1+ (point)) header 0)
8771 gnus-newsgroup-data))
8772 (gnus-summary-insert-line
8773 header 0 nil mark (memq number gnus-newsgroup-replied)
8774 (memq number gnus-newsgroup-expirable)
8775 (mail-header-subject header) nil
8776 (cdr (assq number gnus-newsgroup-scored))
8777 (memq number gnus-newsgroup-processable))))))
8778
8779 (defun gnus-select-newsgroup (group &optional read-all)
8780 "Select newsgroup GROUP.
8781 If READ-ALL is non-nil, all articles in the group are selected."
8782 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
8783 (info (nth 2 entry))
8784 articles fetched-articles cached)
8785
8786 (or (gnus-check-server
8787 (setq gnus-current-select-method (gnus-find-method-for-group group)))
8788 (error "Couldn't open server"))
8789
8790 (or (and entry (not (eq (car entry) t))) ; Either it's active...
8791 (gnus-activate-group group) ; Or we can activate it...
8792 (progn ; Or we bug out.
8793 (when (equal major-mode 'gnus-summary-mode)
8794 (kill-buffer (current-buffer)))
8795 (error "Couldn't request group %s: %s"
8796 group (gnus-status-message group))))
8797
8798 (unless (gnus-request-group group t)
8799 (when (equal major-mode 'gnus-summary-mode)
8800 (kill-buffer (current-buffer)))
8801 (error "Couldn't request group %s: %s"
8802 group (gnus-status-message group)))
8803
8804 (setq gnus-newsgroup-name group)
8805 (setq gnus-newsgroup-unselected nil)
8806 (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
8807
8808 (and gnus-asynchronous
8809 (gnus-check-backend-function
8810 'request-asynchronous gnus-newsgroup-name)
8811 (setq gnus-newsgroup-async
8812 (gnus-request-asynchronous gnus-newsgroup-name)))
8813
8814 ;; Adjust and set lists of article marks.
8815 (when info
8816 (gnus-adjust-marked-articles info))
8817
8818 ;; Kludge to avoid having cached articles nixed out in virtual groups.
8819 (when (gnus-virtual-group-p group)
8820 (setq cached gnus-newsgroup-cached))
8821
8822 (setq gnus-newsgroup-unreads
8823 (gnus-set-difference
8824 (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
8825 gnus-newsgroup-dormant))
8826
8827 (setq gnus-newsgroup-processable nil)
8828
8829 (setq articles (gnus-articles-to-read group read-all))
8830
8831 (cond
8832 ((null articles)
8833 ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
8834 'quit)
8835 ((eq articles 0) nil)
8836 (t
8837 ;; Init the dependencies hash table.
8838 (setq gnus-newsgroup-dependencies
8839 (gnus-make-hashtable (length articles)))
8840 ;; Retrieve the headers and read them in.
8841 (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8842 (setq gnus-newsgroup-headers
8843 (if (eq 'nov
8844 (setq gnus-headers-retrieved-by
8845 (gnus-retrieve-headers
8846 articles gnus-newsgroup-name
8847 ;; We might want to fetch old headers, but
8848 ;; not if there is only 1 article.
8849 (and gnus-fetch-old-headers
8850 (or (and
8851 (not (eq gnus-fetch-old-headers 'some))
8852 (not (numberp gnus-fetch-old-headers)))
8853 (> (length articles) 1))))))
8854 (gnus-get-newsgroup-headers-xover articles)
8855 (gnus-get-newsgroup-headers)))
8856 (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
8857
8858 ;; Kludge to avoid having cached articles nixed out in virtual groups.
8859 (when cached
8860 (setq gnus-newsgroup-cached cached))
8861
8862 ;; Set the initial limit.
8863 (setq gnus-newsgroup-limit (copy-sequence articles))
8864 ;; Remove canceled articles from the list of unread articles.
8865 (setq gnus-newsgroup-unreads
8866 (gnus-set-sorted-intersection
8867 gnus-newsgroup-unreads
8868 (setq fetched-articles
8869 (mapcar (lambda (headers) (mail-header-number headers))
8870 gnus-newsgroup-headers))))
8871 ;; Removed marked articles that do not exist.
8872 (gnus-update-missing-marks
8873 (gnus-sorted-complement fetched-articles articles))
8874 ;; We might want to build some more threads first.
8875 (and gnus-fetch-old-headers
8876 (eq gnus-headers-retrieved-by 'nov)
8877 (gnus-build-old-threads))
8878 ;; Check whether auto-expire is to be done in this group.
8879 (setq gnus-newsgroup-auto-expire
8880 (gnus-group-auto-expirable-p group))
8881 ;; Set up the article buffer now, if necessary.
8882 (unless gnus-single-article-buffer
8883 (gnus-article-setup-buffer))
8884 ;; First and last article in this newsgroup.
8885 (when gnus-newsgroup-headers
8886 (setq gnus-newsgroup-begin
8887 (mail-header-number (car gnus-newsgroup-headers))
8888 gnus-newsgroup-end
8889 (mail-header-number
8890 (gnus-last-element gnus-newsgroup-headers))))
8891 (setq gnus-reffed-article-number -1)
8892 ;; GROUP is successfully selected.
8893 (or gnus-newsgroup-headers t)))))
8894
8895 (defun gnus-articles-to-read (group read-all)
8896 ;; Find out what articles the user wants to read.
8897 (let* ((articles
8898 ;; Select all articles if `read-all' is non-nil, or if there
8899 ;; are no unread articles.
8900 (if (or read-all
8901 (and (zerop (length gnus-newsgroup-marked))
8902 (zerop (length gnus-newsgroup-unreads))))
8903 (gnus-uncompress-range (gnus-active group))
8904 (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
8905 (copy-sequence gnus-newsgroup-unreads))
8906 '<)))
8907 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
8908 (scored (length scored-list))
8909 (number (length articles))
8910 (marked (+ (length gnus-newsgroup-marked)
8911 (length gnus-newsgroup-dormant)))
8912 (select
8913 (cond
8914 ((numberp read-all)
8915 read-all)
8916 (t
8917 (condition-case ()
8918 (cond
8919 ((and (or (<= scored marked) (= scored number))
8920 (numberp gnus-large-newsgroup)
8921 (> number gnus-large-newsgroup))
8922 (let ((input
8923 (read-string
8924 (format
8925 "How many articles from %s (default %d): "
8926 gnus-newsgroup-name number))))
8927 (if (string-match "^[ \t]*$" input) number input)))
8928 ((and (> scored marked) (< scored number)
8929 (> (- scored number) 20))
8930 (let ((input
8931 (read-string
8932 (format "%s %s (%d scored, %d total): "
8933 "How many articles from"
8934 group scored number))))
8935 (if (string-match "^[ \t]*$" input)
8936 number input)))
8937 (t number))
8938 (quit nil))))))
8939 (setq select (if (stringp select) (string-to-number select) select))
8940 (if (or (null select) (zerop select))
8941 select
8942 (if (and (not (zerop scored)) (<= (abs select) scored))
8943 (progn
8944 (setq articles (sort scored-list '<))
8945 (setq number (length articles)))
8946 (setq articles (copy-sequence articles)))
8947
8948 (if (< (abs select) number)
8949 (if (< select 0)
8950 ;; Select the N oldest articles.
8951 (setcdr (nthcdr (1- (abs select)) articles) nil)
8952 ;; Select the N most recent articles.
8953 (setq articles (nthcdr (- number select) articles))))
8954 (setq gnus-newsgroup-unselected
8955 (gnus-sorted-intersection
8956 gnus-newsgroup-unreads
8957 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
8958 articles)))
8959
8960 (defun gnus-killed-articles (killed articles)
8961 (let (out)
8962 (while articles
8963 (if (inline (gnus-member-of-range (car articles) killed))
8964 (setq out (cons (car articles) out)))
8965 (setq articles (cdr articles)))
8966 out))
8967
8968 (defun gnus-uncompress-marks (marks)
8969 "Uncompress the mark ranges in MARKS."
8970 (let ((uncompressed '(score bookmark))
8971 out)
8972 (while marks
8973 (if (memq (caar marks) uncompressed)
8974 (push (car marks) out)
8975 (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
8976 (setq marks (cdr marks)))
8977 out))
8978
8979 (defun gnus-adjust-marked-articles (info)
8980 "Set all article lists and remove all marks that are no longer legal."
8981 (let* ((marked-lists (gnus-info-marks info))
8982 (active (gnus-active (gnus-info-group info)))
8983 (min (car active))
8984 (max (cdr active))
8985 (types gnus-article-mark-lists)
8986 (uncompressed '(score bookmark killed))
8987 marks var articles article mark)
8988
8989 (while marked-lists
8990 (setq marks (pop marked-lists))
8991 (set (setq var (intern (format "gnus-newsgroup-%s"
8992 (car (rassq (setq mark (car marks))
8993 types)))))
8994 (if (memq (car marks) uncompressed) (cdr marks)
8995 (gnus-uncompress-range (cdr marks))))
8996
8997 (setq articles (symbol-value var))
8998
8999 ;; All articles have to be subsets of the active articles.
9000 (cond
9001 ;; Adjust "simple" lists.
9002 ((memq mark '(tick dormant expirable reply save))
9003 (while articles
9004 (when (or (< (setq article (pop articles)) min) (> article max))
9005 (set var (delq article (symbol-value var))))))
9006 ;; Adjust assocs.
9007 ((memq mark uncompressed)
9008 (while articles
9009 (when (or (not (consp (setq article (pop articles))))
9010 (< (car article) min)
9011 (> (car article) max))
9012 (set var (delq article (symbol-value var))))))))))
9013
9014 (defun gnus-update-missing-marks (missing)
9015 "Go through the list of MISSING articles and remove them mark lists."
9016 (when missing
9017 (let ((types gnus-article-mark-lists)
9018 var m)
9019 ;; Go through all types.
9020 (while types
9021 (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
9022 (when (symbol-value var)
9023 ;; This list has articles. So we delete all missing articles
9024 ;; from it.
9025 (setq m missing)
9026 (while m
9027 (set var (delq (pop m) (symbol-value var)))))))))
9028
9029 (defun gnus-update-marks ()
9030 "Enter the various lists of marked articles into the newsgroup info list."
9031 (let ((types gnus-article-mark-lists)
9032 (info (gnus-get-info gnus-newsgroup-name))
9033 (uncompressed '(score bookmark killed))
9034 type list newmarked symbol)
9035 (when info
9036 ;; Add all marks lists that are non-nil to the list of marks lists.
9037 (while types
9038 (setq type (pop types))
9039 (when (setq list (symbol-value
9040 (setq symbol
9041 (intern (format "gnus-newsgroup-%s"
9042 (car type))))))
9043 (push (cons (cdr type)
9044 (if (memq (cdr type) uncompressed) list
9045 (gnus-compress-sequence
9046 (set symbol (sort list '<)) t)))
9047 newmarked)))
9048
9049 ;; Enter these new marks into the info of the group.
9050 (if (nthcdr 3 info)
9051 (setcar (nthcdr 3 info) newmarked)
9052 ;; Add the marks lists to the end of the info.
9053 (when newmarked
9054 (setcdr (nthcdr 2 info) (list newmarked))))
9055
9056 ;; Cut off the end of the info if there's nothing else there.
9057 (let ((i 5))
9058 (while (and (> i 2)
9059 (not (nth i info)))
9060 (when (nthcdr (decf i) info)
9061 (setcdr (nthcdr i info) nil)))))))
9062
9063 (defun gnus-add-marked-articles (group type articles &optional info force)
9064 ;; Add ARTICLES of TYPE to the info of GROUP.
9065 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
9066 ;; add, but replace marked articles of TYPE with ARTICLES.
9067 (let ((info (or info (gnus-get-info group)))
9068 (uncompressed '(score bookmark killed))
9069 marked m)
9070 (or (not info)
9071 (and (not (setq marked (nthcdr 3 info)))
9072 (or (null articles)
9073 (setcdr (nthcdr 2 info)
9074 (list (list (cons type (gnus-compress-sequence
9075 articles t)))))))
9076 (and (not (setq m (assq type (car marked))))
9077 (or (null articles)
9078 (setcar marked
9079 (cons (cons type (gnus-compress-sequence articles t) )
9080 (car marked)))))
9081 (if force
9082 (if (null articles)
9083 (setcar (nthcdr 3 info)
9084 (delq (assq type (car marked)) (car marked)))
9085 (setcdr m (gnus-compress-sequence articles t)))
9086 (setcdr m (gnus-compress-sequence
9087 (sort (nconc (gnus-uncompress-range (cdr m))
9088 (copy-sequence articles)) '<) t))))))
9089
9090 (defun gnus-set-mode-line (where)
9091 "This function sets the mode line of the article or summary buffers.
9092 If WHERE is `summary', the summary mode line format will be used."
9093 ;; Is this mode line one we keep updated?
9094 (when (memq where gnus-updated-mode-lines)
9095 (let (mode-string)
9096 (save-excursion
9097 ;; We evaluate this in the summary buffer since these
9098 ;; variables are buffer-local to that buffer.
9099 (set-buffer gnus-summary-buffer)
9100 ;; We bind all these variables that are used in the `eval' form
9101 ;; below.
9102 (let* ((mformat (symbol-value
9103 (intern
9104 (format "gnus-%s-mode-line-format-spec" where))))
9105 (gnus-tmp-group-name gnus-newsgroup-name)
9106 (gnus-tmp-article-number (or gnus-current-article 0))
9107 (gnus-tmp-unread gnus-newsgroup-unreads)
9108 (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
9109 (gnus-tmp-unselected (length gnus-newsgroup-unselected))
9110 (gnus-tmp-unread-and-unselected
9111 (cond ((and (zerop gnus-tmp-unread-and-unticked)
9112 (zerop gnus-tmp-unselected)) "")
9113 ((zerop gnus-tmp-unselected)
9114 (format "{%d more}" gnus-tmp-unread-and-unticked))
9115 (t (format "{%d(+%d) more}"
9116 gnus-tmp-unread-and-unticked
9117 gnus-tmp-unselected))))
9118 (gnus-tmp-subject
9119 (if (and gnus-current-headers
9120 (vectorp gnus-current-headers))
9121 (gnus-mode-string-quote
9122 (mail-header-subject gnus-current-headers)) ""))
9123 max-len
9124 gnus-tmp-header);; passed as argument to any user-format-funcs
9125 (setq mode-string (eval mformat))
9126 (setq max-len (max 4 (if gnus-mode-non-string-length
9127 (- (window-width)
9128 gnus-mode-non-string-length)
9129 (length mode-string))))
9130 ;; We might have to chop a bit of the string off...
9131 (when (> (length mode-string) max-len)
9132 (setq mode-string
9133 (concat (gnus-truncate-string mode-string (- max-len 3))
9134 "...")))
9135 ;; Pad the mode string a bit.
9136 (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
9137 ;; Update the mode line.
9138 (setq mode-line-buffer-identification
9139 (gnus-mode-line-buffer-identification
9140 (list mode-string)))
9141 (set-buffer-modified-p t))))
9142
9143 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
9144 "Go through the HEADERS list and add all Xrefs to a hash table.
9145 The resulting hash table is returned, or nil if no Xrefs were found."
9146 (let* ((virtual (gnus-virtual-group-p from-newsgroup))
9147 (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
9148 (xref-hashtb (make-vector 63 0))
9149 start group entry number xrefs header)
9150 (while headers
9151 (setq header (pop headers))
9152 (when (and (setq xrefs (mail-header-xref header))
9153 (not (memq (setq number (mail-header-number header))
9154 unreads)))
9155 (setq start 0)
9156 (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
9157 (setq start (match-end 0))
9158 (setq group (if prefix
9159 (concat prefix (substring xrefs (match-beginning 1)
9160 (match-end 1)))
9161 (substring xrefs (match-beginning 1) (match-end 1))))
9162 (setq number
9163 (string-to-int (substring xrefs (match-beginning 2)
9164 (match-end 2))))
9165 (if (setq entry (gnus-gethash group xref-hashtb))
9166 (setcdr entry (cons number (cdr entry)))
9167 (gnus-sethash group (cons number nil) xref-hashtb)))))
9168 (and start xref-hashtb)))
9169
9170 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
9171 "Look through all the headers and mark the Xrefs as read."
9172 (let ((virtual (gnus-virtual-group-p from-newsgroup))
9173 name entry info xref-hashtb idlist method nth4)
9174 (save-excursion
9175 (set-buffer gnus-group-buffer)
9176 (when (setq xref-hashtb
9177 (gnus-create-xref-hashtb from-newsgroup headers unreads))
9178 (mapatoms
9179 (lambda (group)
9180 (unless (string= from-newsgroup (setq name (symbol-name group)))
9181 (setq idlist (symbol-value group))
9182 ;; Dead groups are not updated.
9183 (and (prog1
9184 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
9185 info (nth 2 entry))
9186 (if (stringp (setq nth4 (gnus-info-method info)))
9187 (setq nth4 (gnus-server-to-method nth4))))
9188 ;; Only do the xrefs if the group has the same
9189 ;; select method as the group we have just read.
9190 (or (gnus-methods-equal-p
9191 nth4 (gnus-find-method-for-group from-newsgroup))
9192 virtual
9193 (equal nth4 (setq method (gnus-find-method-for-group
9194 from-newsgroup)))
9195 (and (equal (car nth4) (car method))
9196 (equal (nth 1 nth4) (nth 1 method))))
9197 gnus-use-cross-reference
9198 (or (not (eq gnus-use-cross-reference t))
9199 virtual
9200 ;; Only do cross-references on subscribed
9201 ;; groups, if that is what is wanted.
9202 (<= (gnus-info-level info) gnus-level-subscribed))
9203 (gnus-group-make-articles-read name idlist))))
9204 xref-hashtb)))))
9205
9206 (defun gnus-group-make-articles-read (group articles)
9207 (let* ((num 0)
9208 (entry (gnus-gethash group gnus-newsrc-hashtb))
9209 (info (nth 2 entry))
9210 (active (gnus-active group))
9211 range)
9212 ;; First peel off all illegal article numbers.
9213 (if active
9214 (let ((ids articles)
9215 id first)
9216 (while ids
9217 (setq id (car ids))
9218 (if (and first (> id (cdr active)))
9219 (progn
9220 ;; We'll end up in this situation in one particular
9221 ;; obscure situation. If you re-scan a group and get
9222 ;; a new article that is cross-posted to a different
9223 ;; group that has not been re-scanned, you might get
9224 ;; crossposted article that has a higher number than
9225 ;; Gnus believes possible. So we re-activate this
9226 ;; group as well. This might mean doing the
9227 ;; crossposting thingy will *increase* the number
9228 ;; of articles in some groups. Tsk, tsk.
9229 (setq active (or (gnus-activate-group group) active))))
9230 (if (or (> id (cdr active))
9231 (< id (car active)))
9232 (setq articles (delq id articles)))
9233 (setq ids (cdr ids)))))
9234 ;; If the read list is nil, we init it.
9235 (and active
9236 (null (gnus-info-read info))
9237 (> (car active) 1)
9238 (gnus-info-set-read info (cons 1 (1- (car active)))))
9239 ;; Then we add the read articles to the range.
9240 (gnus-info-set-read
9241 info
9242 (setq range
9243 (gnus-add-to-range
9244 (gnus-info-read info) (setq articles (sort articles '<)))))
9245 ;; Then we have to re-compute how many unread
9246 ;; articles there are in this group.
9247 (if active
9248 (progn
9249 (cond
9250 ((not range)
9251 (setq num (- (1+ (cdr active)) (car active))))
9252 ((not (listp (cdr range)))
9253 (setq num (- (cdr active) (- (1+ (cdr range))
9254 (car range)))))
9255 (t
9256 (while range
9257 (if (numberp (car range))
9258 (setq num (1+ num))
9259 (setq num (+ num (- (1+ (cdar range)) (caar range)))))
9260 (setq range (cdr range)))
9261 (setq num (- (cdr active) num))))
9262 ;; Update the number of unread articles.
9263 (setcar entry num)
9264 ;; Update the group buffer.
9265 (gnus-group-update-group group t)))))
9266
9267 (defun gnus-methods-equal-p (m1 m2)
9268 (let ((m1 (or m1 gnus-select-method))
9269 (m2 (or m2 gnus-select-method)))
9270 (or (equal m1 m2)
9271 (and (eq (car m1) (car m2))
9272 (or (not (memq 'address (assoc (symbol-name (car m1))
9273 gnus-valid-select-methods)))
9274 (equal (nth 1 m1) (nth 1 m2)))))))
9275
9276 (defsubst gnus-header-value ()
9277 (buffer-substring (match-end 0) (gnus-point-at-eol)))
9278
9279 (defvar gnus-newsgroup-none-id 0)
9280
9281 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
9282 (let ((cur nntp-server-buffer)
9283 (dependencies
9284 (or dependencies
9285 (save-excursion (set-buffer gnus-summary-buffer)
9286 gnus-newsgroup-dependencies)))
9287 headers id id-dep ref-dep end ref)
9288 (save-excursion
9289 (set-buffer nntp-server-buffer)
9290 (run-hooks 'gnus-parse-headers-hook)
9291 (let ((case-fold-search t)
9292 in-reply-to header p lines)
9293 (goto-char (point-min))
9294 ;; Search to the beginning of the next header. Error messages
9295 ;; do not begin with 2 or 3.
9296 (while (re-search-forward "^[23][0-9]+ " nil t)
9297 (setq id nil
9298 ref nil)
9299 ;; This implementation of this function, with nine
9300 ;; search-forwards instead of the one re-search-forward and
9301 ;; a case (which basically was the old function) is actually
9302 ;; about twice as fast, even though it looks messier. You
9303 ;; can't have everything, I guess. Speed and elegance
9304 ;; doesn't always go hand in hand.
9305 (setq
9306 header
9307 (vector
9308 ;; Number.
9309 (prog1
9310 (read cur)
9311 (end-of-line)
9312 (setq p (point))
9313 (narrow-to-region (point)
9314 (or (and (search-forward "\n.\n" nil t)
9315 (- (point) 2))
9316 (point))))
9317 ;; Subject.
9318 (progn
9319 (goto-char p)
9320 (if (search-forward "\nsubject: " nil t)
9321 (gnus-header-value) "(none)"))
9322 ;; From.
9323 (progn
9324 (goto-char p)
9325 (if (search-forward "\nfrom: " nil t)
9326 (gnus-header-value) "(nobody)"))
9327 ;; Date.
9328 (progn
9329 (goto-char p)
9330 (if (search-forward "\ndate: " nil t)
9331 (gnus-header-value) ""))
9332 ;; Message-ID.
9333 (progn
9334 (goto-char p)
9335 (if (search-forward "\nmessage-id: " nil t)
9336 (setq id (gnus-header-value))
9337 ;; If there was no message-id, we just fake one to make
9338 ;; subsequent routines simpler.
9339 (setq id (concat "none+"
9340 (int-to-string
9341 (setq gnus-newsgroup-none-id
9342 (1+ gnus-newsgroup-none-id)))))))
9343 ;; References.
9344 (progn
9345 (goto-char p)
9346 (if (search-forward "\nreferences: " nil t)
9347 (progn
9348 (setq end (point))
9349 (prog1
9350 (gnus-header-value)
9351 (setq ref
9352 (buffer-substring
9353 (progn
9354 (end-of-line)
9355 (search-backward ">" end t)
9356 (1+ (point)))
9357 (progn
9358 (search-backward "<" end t)
9359 (point))))))
9360 ;; Get the references from the in-reply-to header if there
9361 ;; were no references and the in-reply-to header looks
9362 ;; promising.
9363 (if (and (search-forward "\nin-reply-to: " nil t)
9364 (setq in-reply-to (gnus-header-value))
9365 (string-match "<[^>]+>" in-reply-to))
9366 (setq ref (substring in-reply-to (match-beginning 0)
9367 (match-end 0)))
9368 (setq ref ""))))
9369 ;; Chars.
9370 0
9371 ;; Lines.
9372 (progn
9373 (goto-char p)
9374 (if (search-forward "\nlines: " nil t)
9375 (if (numberp (setq lines (read cur)))
9376 lines 0)
9377 0))
9378 ;; Xref.
9379 (progn
9380 (goto-char p)
9381 (and (search-forward "\nxref: " nil t)
9382 (gnus-header-value)))))
9383 ;; We do the threading while we read the headers. The
9384 ;; message-id and the last reference are both entered into
9385 ;; the same hash table. Some tippy-toeing around has to be
9386 ;; done in case an article has arrived before the article
9387 ;; which it refers to.
9388 (if (boundp (setq id-dep (intern id dependencies)))
9389 (if (and (car (symbol-value id-dep))
9390 (not force-new))
9391 ;; An article with this Message-ID has already
9392 ;; been seen, so we ignore this one, except we add
9393 ;; any additional Xrefs (in case the two articles
9394 ;; came from different servers).
9395 (progn
9396 (mail-header-set-xref
9397 (car (symbol-value id-dep))
9398 (concat (or (mail-header-xref
9399 (car (symbol-value id-dep))) "")
9400 (or (mail-header-xref header) "")))
9401 (setq header nil))
9402 (setcar (symbol-value id-dep) header))
9403 (set id-dep (list header)))
9404 (when header
9405 (if (boundp (setq ref-dep (intern ref dependencies)))
9406 (setcdr (symbol-value ref-dep)
9407 (nconc (cdr (symbol-value ref-dep))
9408 (list (symbol-value id-dep))))
9409 (set ref-dep (list nil (symbol-value id-dep))))
9410 (setq headers (cons header headers)))
9411 (goto-char (point-max))
9412 (widen))
9413 (nreverse headers)))))
9414
9415 ;; The following macros and functions were written by Felix Lee
9416 ;; <flee@cse.psu.edu>.
9417
9418 (defmacro gnus-nov-read-integer ()
9419 '(prog1
9420 (if (= (following-char) ?\t)
9421 0
9422 (let ((num (condition-case nil (read buffer) (error nil))))
9423 (if (numberp num) num 0)))
9424 (or (eobp) (forward-char 1))))
9425
9426 (defmacro gnus-nov-skip-field ()
9427 '(search-forward "\t" eol 'move))
9428
9429 (defmacro gnus-nov-field ()
9430 '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
9431
9432 ;; Goes through the xover lines and returns a list of vectors
9433 (defun gnus-get-newsgroup-headers-xover (sequence &optional
9434 force-new dependencies)
9435 "Parse the news overview data in the server buffer, and return a
9436 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
9437 ;; Get the Xref when the users reads the articles since most/some
9438 ;; NNTP servers do not include Xrefs when using XOVER.
9439 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
9440 (let ((cur nntp-server-buffer)
9441 (dependencies (or dependencies gnus-newsgroup-dependencies))
9442 number headers header)
9443 (save-excursion
9444 (set-buffer nntp-server-buffer)
9445 ;; Allow the user to mangle the headers before parsing them.
9446 (run-hooks 'gnus-parse-headers-hook)
9447 (goto-char (point-min))
9448 (while (and sequence (not (eobp)))
9449 (setq number (read cur))
9450 (while (and sequence (< (car sequence) number))
9451 (setq sequence (cdr sequence)))
9452 (and sequence
9453 (eq number (car sequence))
9454 (progn
9455 (setq sequence (cdr sequence))
9456 (if (setq header
9457 (inline (gnus-nov-parse-line
9458 number dependencies force-new)))
9459 (setq headers (cons header headers)))))
9460 (forward-line 1))
9461 (setq headers (nreverse headers)))
9462 headers))
9463
9464 ;; This function has to be called with point after the article number
9465 ;; on the beginning of the line.
9466 (defun gnus-nov-parse-line (number dependencies &optional force-new)
9467 (let ((none 0)
9468 (eol (gnus-point-at-eol))
9469 (buffer (current-buffer))
9470 header ref id id-dep ref-dep)
9471
9472 ;; overview: [num subject from date id refs chars lines misc]
9473 (narrow-to-region (point) eol)
9474 (or (eobp) (forward-char))
9475
9476 (condition-case nil
9477 (setq header
9478 (vector
9479 number ; number
9480 (gnus-nov-field) ; subject
9481 (gnus-nov-field) ; from
9482 (gnus-nov-field) ; date
9483 (setq id (or (gnus-nov-field)
9484 (concat "none+"
9485 (int-to-string
9486 (setq none (1+ none)))))) ; id
9487 (progn
9488 (save-excursion
9489 (let ((beg (point)))
9490 (search-forward "\t" eol)
9491 (if (search-backward ">" beg t)
9492 (setq ref
9493 (buffer-substring
9494 (1+ (point))
9495 (search-backward "<" beg t)))
9496 (setq ref nil))))
9497 (gnus-nov-field)) ; refs
9498 (gnus-nov-read-integer) ; chars
9499 (gnus-nov-read-integer) ; lines
9500 (if (= (following-char) ?\n)
9501 nil
9502 (gnus-nov-field)) ; misc
9503 ))
9504 (error (progn
9505 (gnus-error 4 "Strange nov line")
9506 (setq header nil)
9507 (goto-char eol))))
9508
9509 (widen)
9510
9511 ;; We build the thread tree.
9512 (when header
9513 (if (boundp (setq id-dep (intern id dependencies)))
9514 (if (and (car (symbol-value id-dep))
9515 (not force-new))
9516 ;; An article with this Message-ID has already been seen,
9517 ;; so we ignore this one, except we add any additional
9518 ;; Xrefs (in case the two articles came from different
9519 ;; servers.
9520 (progn
9521 (mail-header-set-xref
9522 (car (symbol-value id-dep))
9523 (concat (or (mail-header-xref
9524 (car (symbol-value id-dep))) "")
9525 (or (mail-header-xref header) "")))
9526 (setq header nil))
9527 (setcar (symbol-value id-dep) header))
9528 (set id-dep (list header))))
9529 (when header
9530 (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
9531 (setcdr (symbol-value ref-dep)
9532 (nconc (cdr (symbol-value ref-dep))
9533 (list (symbol-value id-dep))))
9534 (set ref-dep (list nil (symbol-value id-dep)))))
9535 header))
9536
9537 (defun gnus-article-get-xrefs ()
9538 "Fill in the Xref value in `gnus-current-headers', if necessary.
9539 This is meant to be called in `gnus-article-internal-prepare-hook'."
9540 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
9541 gnus-current-headers)))
9542 (or (not gnus-use-cross-reference)
9543 (not headers)
9544 (and (mail-header-xref headers)
9545 (not (string= (mail-header-xref headers) "")))
9546 (let ((case-fold-search t)
9547 xref)
9548 (save-restriction
9549 (nnheader-narrow-to-headers)
9550 (goto-char (point-min))
9551 (if (or (and (eq (downcase (following-char)) ?x)
9552 (looking-at "Xref:"))
9553 (search-forward "\nXref:" nil t))
9554 (progn
9555 (goto-char (1+ (match-end 0)))
9556 (setq xref (buffer-substring (point)
9557 (progn (end-of-line) (point))))
9558 (mail-header-set-xref headers xref))))))))
9559
9560 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
9561 "Find article ID and insert the summary line for that article."
9562 (let ((header (if (and old-header use-old-header)
9563 old-header (gnus-read-header id)))
9564 (number (and (numberp id) id))
9565 pos)
9566 (when header
9567 ;; Rebuild the thread that this article is part of and go to the
9568 ;; article we have fetched.
9569 (when (and (not gnus-show-threads)
9570 old-header)
9571 (when (setq pos (text-property-any
9572 (point-min) (point-max) 'gnus-number
9573 (mail-header-number old-header)))
9574 (goto-char pos)
9575 (gnus-delete-line)
9576 (gnus-data-remove (mail-header-number old-header))))
9577 (when old-header
9578 (mail-header-set-number header (mail-header-number old-header)))
9579 (setq gnus-newsgroup-sparse
9580 (delq (setq number (mail-header-number header))
9581 gnus-newsgroup-sparse))
9582 (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
9583 (gnus-rebuild-thread (mail-header-id header))
9584 (gnus-summary-goto-subject number nil t))
9585 (when (and (numberp number)
9586 (> number 0))
9587 ;; We have to update the boundaries even if we can't fetch the
9588 ;; article if ID is a number -- so that the next `P' or `N'
9589 ;; command will fetch the previous (or next) article even
9590 ;; if the one we tried to fetch this time has been canceled.
9591 (and (> number gnus-newsgroup-end)
9592 (setq gnus-newsgroup-end number))
9593 (and (< number gnus-newsgroup-begin)
9594 (setq gnus-newsgroup-begin number))
9595 (setq gnus-newsgroup-unselected
9596 (delq number gnus-newsgroup-unselected)))
9597 ;; Report back a success?
9598 (and header (mail-header-number header))))
9599
9600 (defun gnus-summary-work-articles (n)
9601 "Return a list of articles to be worked upon. The prefix argument,
9602 the list of process marked articles, and the current article will be
9603 taken into consideration."
9604 (cond
9605 (n
9606 ;; A numerical prefix has been given.
9607 (let ((backward (< n 0))
9608 (n (abs (prefix-numeric-value n)))
9609 articles article)
9610 (save-excursion
9611 (while
9612 (and (> n 0)
9613 (push (setq article (gnus-summary-article-number))
9614 articles)
9615 (if backward
9616 (gnus-summary-find-prev nil article)
9617 (gnus-summary-find-next nil article)))
9618 (decf n)))
9619 (nreverse articles)))
9620 ((and (boundp 'transient-mark-mode)
9621 transient-mark-mode
9622 mark-active)
9623 ;; Work on the region between point and mark.
9624 (let ((max (max (point) (mark)))
9625 articles article)
9626 (save-excursion
9627 (goto-char (min (point) (mark)))
9628 (while
9629 (and
9630 (push (setq article (gnus-summary-article-number)) articles)
9631 (gnus-summary-find-next nil article)
9632 (< (point) max)))
9633 (nreverse articles))))
9634 (gnus-newsgroup-processable
9635 ;; There are process-marked articles present.
9636 (reverse gnus-newsgroup-processable))
9637 (t
9638 ;; Just return the current article.
9639 (list (gnus-summary-article-number)))))
9640
9641 (defun gnus-summary-search-group (&optional backward use-level)
9642 "Search for next unread newsgroup.
9643 If optional argument BACKWARD is non-nil, search backward instead."
9644 (save-excursion
9645 (set-buffer gnus-group-buffer)
9646 (if (gnus-group-search-forward
9647 backward nil (if use-level (gnus-group-group-level) nil))
9648 (gnus-group-group-name))))
9649
9650 (defun gnus-summary-best-group (&optional exclude-group)
9651 "Find the name of the best unread group.
9652 If EXCLUDE-GROUP, do not go to this group."
9653 (save-excursion
9654 (set-buffer gnus-group-buffer)
9655 (save-excursion
9656 (gnus-group-best-unread-group exclude-group))))
9657
9658 (defun gnus-summary-find-next (&optional unread article backward)
9659 (if backward (gnus-summary-find-prev)
9660 (let* ((dummy (gnus-summary-article-intangible-p))
9661 (article (or article (gnus-summary-article-number)))
9662 (arts (gnus-data-find-list article))
9663 result)
9664 (when (and (not dummy)
9665 (or (not gnus-summary-check-current)
9666 (not unread)
9667 (not (gnus-data-unread-p (car arts)))))
9668 (setq arts (cdr arts)))
9669 (when (setq result
9670 (if unread
9671 (progn
9672 (while arts
9673 (when (gnus-data-unread-p (car arts))
9674 (setq result (car arts)
9675 arts nil))
9676 (setq arts (cdr arts)))
9677 result)
9678 (car arts)))
9679 (goto-char (gnus-data-pos result))
9680 (gnus-data-number result)))))
9681
9682 (defun gnus-summary-find-prev (&optional unread article)
9683 (let* ((eobp (eobp))
9684 (article (or article (gnus-summary-article-number)))
9685 (arts (gnus-data-find-list article (gnus-data-list 'rev)))
9686 result)
9687 (when (and (not eobp)
9688 (or (not gnus-summary-check-current)
9689 (not unread)
9690 (not (gnus-data-unread-p (car arts)))))
9691 (setq arts (cdr arts)))
9692 (if (setq result
9693 (if unread
9694 (progn
9695 (while arts
9696 (and (gnus-data-unread-p (car arts))
9697 (setq result (car arts)
9698 arts nil))
9699 (setq arts (cdr arts)))
9700 result)
9701 (car arts)))
9702 (progn
9703 (goto-char (gnus-data-pos result))
9704 (gnus-data-number result)))))
9705
9706 (defun gnus-summary-find-subject (subject &optional unread backward article)
9707 (let* ((simp-subject (gnus-simplify-subject-fully subject))
9708 (article (or article (gnus-summary-article-number)))
9709 (articles (gnus-data-list backward))
9710 (arts (gnus-data-find-list article articles))
9711 result)
9712 (when (or (not gnus-summary-check-current)
9713 (not unread)
9714 (not (gnus-data-unread-p (car arts))))
9715 (setq arts (cdr arts)))
9716 (while arts
9717 (and (or (not unread)
9718 (gnus-data-unread-p (car arts)))
9719 (vectorp (gnus-data-header (car arts)))
9720 (gnus-subject-equal
9721 simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
9722 (setq result (car arts)
9723 arts nil))
9724 (setq arts (cdr arts)))
9725 (and result
9726 (goto-char (gnus-data-pos result))
9727 (gnus-data-number result))))
9728
9729 (defun gnus-summary-search-forward (&optional unread subject backward)
9730 "Search forward for an article.
9731 If UNREAD, look for unread articles. If SUBJECT, look for
9732 articles with that subject. If BACKWARD, search backward instead."
9733 (cond (subject (gnus-summary-find-subject subject unread backward))
9734 (backward (gnus-summary-find-prev unread))
9735 (t (gnus-summary-find-next unread))))
9736
9737 (defun gnus-recenter (&optional n)
9738 "Center point in window and redisplay frame.
9739 Also do horizontal recentering."
9740 (interactive "P")
9741 (when (and gnus-auto-center-summary
9742 (not (eq gnus-auto-center-summary 'vertical)))
9743 (gnus-horizontal-recenter))
9744 (recenter n))
9745
9746 (defun gnus-summary-recenter ()
9747 "Center point in the summary window.
9748 If `gnus-auto-center-summary' is nil, or the article buffer isn't
9749 displayed, no centering will be performed."
9750 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
9751 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
9752 (let* ((top (cond ((< (window-height) 4) 0)
9753 ((< (window-height) 7) 1)
9754 (t 2)))
9755 (height (1- (window-height)))
9756 (bottom (save-excursion (goto-char (point-max))
9757 (forward-line (- height))
9758 (point)))
9759 (window (get-buffer-window (current-buffer))))
9760 ;; The user has to want it.
9761 (when gnus-auto-center-summary
9762 (when (get-buffer-window gnus-article-buffer)
9763 ;; Only do recentering when the article buffer is displayed,
9764 ;; Set the window start to either `bottom', which is the biggest
9765 ;; possible valid number, or the second line from the top,
9766 ;; whichever is the least.
9767 (set-window-start
9768 window (min bottom (save-excursion
9769 (forward-line (- top)) (point)))))
9770 ;; Do horizontal recentering while we're at it.
9771 (when (and (get-buffer-window (current-buffer) t)
9772 (not (eq gnus-auto-center-summary 'vertical)))
9773 (let ((selected (selected-window)))
9774 (select-window (get-buffer-window (current-buffer) t))
9775 (gnus-summary-position-point)
9776 (gnus-horizontal-recenter)
9777 (select-window selected))))))
9778
9779 (defun gnus-horizontal-recenter ()
9780 "Recenter the current buffer horizontally."
9781 (if (< (current-column) (/ (window-width) 2))
9782 (set-window-hscroll (get-buffer-window (current-buffer) t) 0)
9783 (let* ((orig (point))
9784 (end (window-end (get-buffer-window (current-buffer) t)))
9785 (max 0))
9786 ;; Find the longest line currently displayed in the window.
9787 (goto-char (window-start))
9788 (while (and (not (eobp))
9789 (< (point) end))
9790 (end-of-line)
9791 (setq max (max max (current-column)))
9792 (forward-line 1))
9793 (goto-char orig)
9794 ;; Scroll horizontally to center (sort of) the point.
9795 (if (> max (window-width))
9796 (set-window-hscroll
9797 (get-buffer-window (current-buffer) t)
9798 (min (- (current-column) (/ (window-width) 3))
9799 (+ 2 (- max (window-width)))))
9800 (set-window-hscroll (get-buffer-window (current-buffer) t) 0))
9801 max)))
9802
9803 ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
9804 (defun gnus-short-group-name (group &optional levels)
9805 "Collapse GROUP name LEVELS."
9806 (let* ((name "")
9807 (foreign "")
9808 (depth 0)
9809 (skip 1)
9810 (levels (or levels
9811 (progn
9812 (while (string-match "\\." group skip)
9813 (setq skip (match-end 0)
9814 depth (+ depth 1)))
9815 depth))))
9816 (if (string-match ":" group)
9817 (setq foreign (substring group 0 (match-end 0))
9818 group (substring group (match-end 0))))
9819 (while group
9820 (if (and (string-match "\\." group)
9821 (> levels (- gnus-group-uncollapsed-levels 1)))
9822 (setq name (concat name (substring group 0 1))
9823 group (substring group (match-end 0))
9824 levels (- levels 1)
9825 name (concat name "."))
9826 (setq name (concat foreign name group)
9827 group nil)))
9828 name))
9829
9830 (defun gnus-summary-jump-to-group (newsgroup)
9831 "Move point to NEWSGROUP in group mode buffer."
9832 ;; Keep update point of group mode buffer if visible.
9833 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
9834 (save-window-excursion
9835 ;; Take care of tree window mode.
9836 (if (get-buffer-window gnus-group-buffer)
9837 (pop-to-buffer gnus-group-buffer))
9838 (gnus-group-jump-to-group newsgroup))
9839 (save-excursion
9840 ;; Take care of tree window mode.
9841 (if (get-buffer-window gnus-group-buffer)
9842 (pop-to-buffer gnus-group-buffer)
9843 (set-buffer gnus-group-buffer))
9844 (gnus-group-jump-to-group newsgroup))))
9845
9846 ;; This function returns a list of article numbers based on the
9847 ;; difference between the ranges of read articles in this group and
9848 ;; the range of active articles.
9849 (defun gnus-list-of-unread-articles (group)
9850 (let* ((read (gnus-info-read (gnus-get-info group)))
9851 (active (gnus-active group))
9852 (last (cdr active))
9853 first nlast unread)
9854 ;; If none are read, then all are unread.
9855 (if (not read)
9856 (setq first (car active))
9857 ;; If the range of read articles is a single range, then the
9858 ;; first unread article is the article after the last read
9859 ;; article. Sounds logical, doesn't it?
9860 (if (not (listp (cdr read)))
9861 (setq first (1+ (cdr read)))
9862 ;; `read' is a list of ranges.
9863 (if (/= (setq nlast (or (and (numberp (car read)) (car read))
9864 (caar read))) 1)
9865 (setq first 1))
9866 (while read
9867 (if first
9868 (while (< first nlast)
9869 (setq unread (cons first unread))
9870 (setq first (1+ first))))
9871 (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
9872 (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
9873 (setq read (cdr read)))))
9874 ;; And add the last unread articles.
9875 (while (<= first last)
9876 (setq unread (cons first unread))
9877 (setq first (1+ first)))
9878 ;; Return the list of unread articles.
9879 (nreverse unread)))
9880
9881 (defun gnus-list-of-read-articles (group)
9882 "Return a list of unread, unticked and non-dormant articles."
9883 (let* ((info (gnus-get-info group))
9884 (marked (gnus-info-marks info))
9885 (active (gnus-active group)))
9886 (and info active
9887 (gnus-set-difference
9888 (gnus-sorted-complement
9889 (gnus-uncompress-range active)
9890 (gnus-list-of-unread-articles group))
9891 (append
9892 (gnus-uncompress-range (cdr (assq 'dormant marked)))
9893 (gnus-uncompress-range (cdr (assq 'tick marked))))))))
9894
9895 ;; Various summary commands
9896
9897 (defun gnus-summary-universal-argument (arg)
9898 "Perform any operation on all articles that are process/prefixed."
9899 (interactive "P")
9900 (gnus-set-global-variables)
9901 (let ((articles (gnus-summary-work-articles arg))
9902 func article)
9903 (if (eq
9904 (setq
9905 func
9906 (key-binding
9907 (read-key-sequence
9908 (substitute-command-keys
9909 "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"
9910 ))))
9911 'undefined)
9912 (gnus-error 1 "Undefined key")
9913 (save-excursion
9914 (while articles
9915 (gnus-summary-goto-subject (setq article (pop articles)))
9916 (command-execute func)
9917 (gnus-summary-remove-process-mark article)))))
9918 (gnus-summary-position-point))
9919
9920 (defun gnus-summary-toggle-truncation (&optional arg)
9921 "Toggle truncation of summary lines.
9922 With arg, turn line truncation on iff arg is positive."
9923 (interactive "P")
9924 (setq truncate-lines
9925 (if (null arg) (not truncate-lines)
9926 (> (prefix-numeric-value arg) 0)))
9927 (redraw-display))
9928
9929 (defun gnus-summary-reselect-current-group (&optional all rescan)
9930 "Exit and then reselect the current newsgroup.
9931 The prefix argument ALL means to select all articles."
9932 (interactive "P")
9933 (gnus-set-global-variables)
9934 (when (gnus-ephemeral-group-p gnus-newsgroup-name)
9935 (error "Ephemeral groups can't be reselected"))
9936 (let ((current-subject (gnus-summary-article-number))
9937 (group gnus-newsgroup-name))
9938 (setq gnus-newsgroup-begin nil)
9939 (gnus-summary-exit)
9940 ;; We have to adjust the point of group mode buffer because the
9941 ;; current point was moved to the next unread newsgroup by
9942 ;; exiting.
9943 (gnus-summary-jump-to-group group)
9944 (when rescan
9945 (save-excursion
9946 (gnus-group-get-new-news-this-group 1)))
9947 (gnus-group-read-group all t)
9948 (gnus-summary-goto-subject current-subject nil t)))
9949
9950 (defun gnus-summary-rescan-group (&optional all)
9951 "Exit the newsgroup, ask for new articles, and select the newsgroup."
9952 (interactive "P")
9953 (gnus-summary-reselect-current-group all t))
9954
9955 (defun gnus-summary-update-info ()
9956 (let* ((group gnus-newsgroup-name))
9957 (when gnus-newsgroup-kill-headers
9958 (setq gnus-newsgroup-killed
9959 (gnus-compress-sequence
9960 (nconc
9961 (gnus-set-sorted-intersection
9962 (gnus-uncompress-range gnus-newsgroup-killed)
9963 (setq gnus-newsgroup-unselected
9964 (sort gnus-newsgroup-unselected '<)))
9965 (setq gnus-newsgroup-unreads
9966 (sort gnus-newsgroup-unreads '<))) t)))
9967 (unless (listp (cdr gnus-newsgroup-killed))
9968 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
9969 (let ((headers gnus-newsgroup-headers))
9970 (run-hooks 'gnus-exit-group-hook)
9971 (unless gnus-save-score
9972 (setq gnus-newsgroup-scored nil))
9973 ;; Set the new ranges of read articles.
9974 (gnus-update-read-articles
9975 group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
9976 ;; Set the current article marks.
9977 (gnus-update-marks)
9978 ;; Do the cross-ref thing.
9979 (when gnus-use-cross-reference
9980 (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
9981 ;; Do adaptive scoring, and possibly save score files.
9982 (when gnus-newsgroup-adaptive
9983 (gnus-score-adaptive))
9984 (when gnus-use-scoring
9985 (gnus-score-save))
9986 ;; Do not switch windows but change the buffer to work.
9987 (set-buffer gnus-group-buffer)
9988 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
9989 (gnus-group-update-group group)))))
9990
9991 (defun gnus-summary-exit (&optional temporary)
9992 "Exit reading current newsgroup, and then return to group selection mode.
9993 gnus-exit-group-hook is called with no arguments if that value is non-nil."
9994 (interactive)
9995 (gnus-set-global-variables)
9996 (gnus-kill-save-kill-buffer)
9997 (let* ((group gnus-newsgroup-name)
9998 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
9999 (mode major-mode)
10000 (buf (current-buffer)))
10001 (run-hooks 'gnus-summary-prepare-exit-hook)
10002 ;; If we have several article buffers, we kill them at exit.
10003 (unless gnus-single-article-buffer
10004 (gnus-kill-buffer gnus-original-article-buffer)
10005 (setq gnus-article-current nil))
10006 (when gnus-use-cache
10007 (gnus-cache-possibly-remove-articles)
10008 (gnus-cache-save-buffers))
10009 (when gnus-use-trees
10010 (gnus-tree-close group))
10011 ;; Make all changes in this group permanent.
10012 (unless quit-config
10013 (gnus-summary-update-info))
10014 (gnus-close-group group)
10015 ;; Make sure where I was, and go to next newsgroup.
10016 (set-buffer gnus-group-buffer)
10017 (unless quit-config
10018 (gnus-group-jump-to-group group))
10019 (run-hooks 'gnus-summary-exit-hook)
10020 (unless quit-config
10021 (gnus-group-next-unread-group 1))
10022 (if temporary
10023 nil ;Nothing to do.
10024 ;; If we have several article buffers, we kill them at exit.
10025 (unless gnus-single-article-buffer
10026 (gnus-kill-buffer gnus-article-buffer)
10027 (gnus-kill-buffer gnus-original-article-buffer)
10028 (setq gnus-article-current nil))
10029 (set-buffer buf)
10030 (if (not gnus-kill-summary-on-exit)
10031 (gnus-deaden-summary)
10032 ;; We set all buffer-local variables to nil. It is unclear why
10033 ;; this is needed, but if we don't, buffer-local variables are
10034 ;; not garbage-collected, it seems. This would the lead to en
10035 ;; ever-growing Emacs.
10036 (gnus-summary-clear-local-variables)
10037 (when (get-buffer gnus-article-buffer)
10038 (bury-buffer gnus-article-buffer))
10039 ;; We clear the global counterparts of the buffer-local
10040 ;; variables as well, just to be on the safe side.
10041 (gnus-configure-windows 'group 'force)
10042 (gnus-summary-clear-local-variables)
10043 ;; Return to group mode buffer.
10044 (if (eq mode 'gnus-summary-mode)
10045 (gnus-kill-buffer buf)))
10046 (setq gnus-current-select-method gnus-select-method)
10047 (pop-to-buffer gnus-group-buffer)
10048 ;; Clear the current group name.
10049 (if (not quit-config)
10050 (progn
10051 (gnus-group-jump-to-group group)
10052 (gnus-group-next-unread-group 1)
10053 (gnus-configure-windows 'group 'force))
10054 (if (not (buffer-name (car quit-config)))
10055 (gnus-configure-windows 'group 'force)
10056 (set-buffer (car quit-config))
10057 (and (eq major-mode 'gnus-summary-mode)
10058 (gnus-set-global-variables))
10059 (gnus-configure-windows (cdr quit-config))))
10060 (unless quit-config
10061 (setq gnus-newsgroup-name nil)))))
10062
10063 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
10064 (defun gnus-summary-exit-no-update (&optional no-questions)
10065 "Quit reading current newsgroup without updating read article info."
10066 (interactive)
10067 (gnus-set-global-variables)
10068 (let* ((group gnus-newsgroup-name)
10069 (quit-config (gnus-group-quit-config group)))
10070 (when (or no-questions
10071 gnus-expert-user
10072 (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
10073 ;; If we have several article buffers, we kill them at exit.
10074 (unless gnus-single-article-buffer
10075 (gnus-kill-buffer gnus-article-buffer)
10076 (gnus-kill-buffer gnus-original-article-buffer)
10077 (setq gnus-article-current nil))
10078 (if (not gnus-kill-summary-on-exit)
10079 (gnus-deaden-summary)
10080 (gnus-close-group group)
10081 (gnus-summary-clear-local-variables)
10082 (set-buffer gnus-group-buffer)
10083 (gnus-summary-clear-local-variables)
10084 (when (get-buffer gnus-summary-buffer)
10085 (kill-buffer gnus-summary-buffer)))
10086 (unless gnus-single-article-buffer
10087 (setq gnus-article-current nil))
10088 (when gnus-use-trees
10089 (gnus-tree-close group))
10090 (when (get-buffer gnus-article-buffer)
10091 (bury-buffer gnus-article-buffer))
10092 ;; Return to the group buffer.
10093 (gnus-configure-windows 'group 'force)
10094 ;; Clear the current group name.
10095 (setq gnus-newsgroup-name nil)
10096 (when (equal (gnus-group-group-name) group)
10097 (gnus-group-next-unread-group 1))
10098 (when quit-config
10099 (if (not (buffer-name (car quit-config)))
10100 (gnus-configure-windows 'group 'force)
10101 (set-buffer (car quit-config))
10102 (when (eq major-mode 'gnus-summary-mode)
10103 (gnus-set-global-variables))
10104 (gnus-configure-windows (cdr quit-config)))))))
10105
10106 ;;; Dead summaries.
10107
10108 (defvar gnus-dead-summary-mode-map nil)
10109
10110 (if gnus-dead-summary-mode-map
10111 nil
10112 (setq gnus-dead-summary-mode-map (make-keymap))
10113 (suppress-keymap gnus-dead-summary-mode-map)
10114 (substitute-key-definition
10115 'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
10116 (let ((keys '("\C-d" "\r" "\177")))
10117 (while keys
10118 (define-key gnus-dead-summary-mode-map
10119 (pop keys) 'gnus-summary-wake-up-the-dead))))
10120
10121 (defvar gnus-dead-summary-mode nil
10122 "Minor mode for Gnus summary buffers.")
10123
10124 (defun gnus-dead-summary-mode (&optional arg)
10125 "Minor mode for Gnus summary buffers."
10126 (interactive "P")
10127 (when (eq major-mode 'gnus-summary-mode)
10128 (make-local-variable 'gnus-dead-summary-mode)
10129 (setq gnus-dead-summary-mode
10130 (if (null arg) (not gnus-dead-summary-mode)
10131 (> (prefix-numeric-value arg) 0)))
10132 (when gnus-dead-summary-mode
10133 (unless (assq 'gnus-dead-summary-mode minor-mode-alist)
10134 (push '(gnus-dead-summary-mode " Dead") minor-mode-alist))
10135 (unless (assq 'gnus-dead-summary-mode minor-mode-map-alist)
10136 (push (cons 'gnus-dead-summary-mode gnus-dead-summary-mode-map)
10137 minor-mode-map-alist)))))
10138
10139 (defun gnus-deaden-summary ()
10140 "Make the current summary buffer into a dead summary buffer."
10141 ;; Kill any previous dead summary buffer.
10142 (when (and gnus-dead-summary
10143 (buffer-name gnus-dead-summary))
10144 (save-excursion
10145 (set-buffer gnus-dead-summary)
10146 (when gnus-dead-summary-mode
10147 (kill-buffer (current-buffer)))))
10148 ;; Make this the current dead summary.
10149 (setq gnus-dead-summary (current-buffer))
10150 (gnus-dead-summary-mode 1)
10151 (let ((name (buffer-name)))
10152 (when (string-match "Summary" name)
10153 (rename-buffer
10154 (concat (substring name 0 (match-beginning 0)) "Dead "
10155 (substring name (match-beginning 0))) t))))
10156
10157 (defun gnus-kill-or-deaden-summary (buffer)
10158 "Kill or deaden the summary BUFFER."
10159 (when (and (buffer-name buffer)
10160 (not gnus-single-article-buffer))
10161 (save-excursion
10162 (set-buffer buffer)
10163 (gnus-kill-buffer gnus-article-buffer)
10164 (gnus-kill-buffer gnus-original-article-buffer)))
10165 (cond (gnus-kill-summary-on-exit
10166 (when (and gnus-use-trees
10167 (and (get-buffer buffer)
10168 (buffer-name (get-buffer buffer))))
10169 (save-excursion
10170 (set-buffer (get-buffer buffer))
10171 (gnus-tree-close gnus-newsgroup-name)))
10172 (gnus-kill-buffer buffer))
10173 ((and (get-buffer buffer)
10174 (buffer-name (get-buffer buffer)))
10175 (save-excursion
10176 (set-buffer buffer)
10177 (gnus-deaden-summary)))))
10178
10179 (defun gnus-summary-wake-up-the-dead (&rest args)
10180 "Wake up the dead summary buffer."
10181 (interactive)
10182 (gnus-dead-summary-mode -1)
10183 (let ((name (buffer-name)))
10184 (when (string-match "Dead " name)
10185 (rename-buffer
10186 (concat (substring name 0 (match-beginning 0))
10187 (substring name (match-end 0))) t)))
10188 (gnus-message 3 "This dead summary is now alive again"))
10189
10190 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
10191 (defun gnus-summary-fetch-faq (&optional faq-dir)
10192 "Fetch the FAQ for the current group.
10193 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
10194 in."
10195 (interactive
10196 (list
10197 (if current-prefix-arg
10198 (completing-read
10199 "Faq dir: " (and (listp gnus-group-faq-directory)
10200 gnus-group-faq-directory)))))
10201 (let (gnus-faq-buffer)
10202 (and (setq gnus-faq-buffer
10203 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
10204 (gnus-configure-windows 'summary-faq))))
10205
10206 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
10207 (defun gnus-summary-describe-group (&optional force)
10208 "Describe the current newsgroup."
10209 (interactive "P")
10210 (gnus-group-describe-group force gnus-newsgroup-name))
10211
10212 (defun gnus-summary-describe-briefly ()
10213 "Describe summary mode commands briefly."
10214 (interactive)
10215 (gnus-message 6
10216 (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")))
10217
10218 ;; Walking around group mode buffer from summary mode.
10219
10220 (defun gnus-summary-next-group (&optional no-article target-group backward)
10221 "Exit current newsgroup and then select next unread newsgroup.
10222 If prefix argument NO-ARTICLE is non-nil, no article is selected
10223 initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
10224 previous group instead."
10225 (interactive "P")
10226 (gnus-set-global-variables)
10227 (let ((current-group gnus-newsgroup-name)
10228 (current-buffer (current-buffer))
10229 entered)
10230 ;; First we semi-exit this group to update Xrefs and all variables.
10231 ;; We can't do a real exit, because the window conf must remain
10232 ;; the same in case the user is prompted for info, and we don't
10233 ;; want the window conf to change before that...
10234 (gnus-summary-exit t)
10235 (while (not entered)
10236 ;; Then we find what group we are supposed to enter.
10237 (set-buffer gnus-group-buffer)
10238 (gnus-group-jump-to-group current-group)
10239 (setq target-group
10240 (or target-group
10241 (if (eq gnus-keep-same-level 'best)
10242 (gnus-summary-best-group gnus-newsgroup-name)
10243 (gnus-summary-search-group backward gnus-keep-same-level))))
10244 (if (not target-group)
10245 ;; There are no further groups, so we return to the group
10246 ;; buffer.
10247 (progn
10248 (gnus-message 5 "Returning to the group buffer")
10249 (setq entered t)
10250 (set-buffer current-buffer)
10251 (gnus-summary-exit))
10252 ;; We try to enter the target group.
10253 (gnus-group-jump-to-group target-group)
10254 (let ((unreads (gnus-group-group-unread)))
10255 (if (and (or (eq t unreads)
10256 (and unreads (not (zerop unreads))))
10257 (gnus-summary-read-group
10258 target-group nil no-article current-buffer))
10259 (setq entered t)
10260 (setq current-group target-group
10261 target-group nil)))))))
10262
10263 (defun gnus-summary-prev-group (&optional no-article)
10264 "Exit current newsgroup and then select previous unread newsgroup.
10265 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
10266 (interactive "P")
10267 (gnus-summary-next-group no-article nil t))
10268
10269 ;; Walking around summary lines.
10270
10271 (defun gnus-summary-first-subject (&optional unread)
10272 "Go to the first unread subject.
10273 If UNREAD is non-nil, go to the first unread article.
10274 Returns the article selected or nil if there are no unread articles."
10275 (interactive "P")
10276 (prog1
10277 (cond
10278 ;; Empty summary.
10279 ((null gnus-newsgroup-data)
10280 (gnus-message 3 "No articles in the group")
10281 nil)
10282 ;; Pick the first article.
10283 ((not unread)
10284 (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
10285 (gnus-data-number (car gnus-newsgroup-data)))
10286 ;; No unread articles.
10287 ((null gnus-newsgroup-unreads)
10288 (gnus-message 3 "No more unread articles")
10289 nil)
10290 ;; Find the first unread article.
10291 (t
10292 (let ((data gnus-newsgroup-data))
10293 (while (and data
10294 (not (gnus-data-unread-p (car data))))
10295 (setq data (cdr data)))
10296 (if data
10297 (progn
10298 (goto-char (gnus-data-pos (car data)))
10299 (gnus-data-number (car data)))))))
10300 (gnus-summary-position-point)))
10301
10302 (defun gnus-summary-next-subject (n &optional unread dont-display)
10303 "Go to next N'th summary line.
10304 If N is negative, go to the previous N'th subject line.
10305 If UNREAD is non-nil, only unread articles are selected.
10306 The difference between N and the actual number of steps taken is
10307 returned."
10308 (interactive "p")
10309 (let ((backward (< n 0))
10310 (n (abs n)))
10311 (while (and (> n 0)
10312 (if backward
10313 (gnus-summary-find-prev unread)
10314 (gnus-summary-find-next unread)))
10315 (setq n (1- n)))
10316 (if (/= 0 n) (gnus-message 7 "No more%s articles"
10317 (if unread " unread" "")))
10318 (unless dont-display
10319 (gnus-summary-recenter)
10320 (gnus-summary-position-point))
10321 n))
10322
10323 (defun gnus-summary-next-unread-subject (n)
10324 "Go to next N'th unread summary line."
10325 (interactive "p")
10326 (gnus-summary-next-subject n t))
10327
10328 (defun gnus-summary-prev-subject (n &optional unread)
10329 "Go to previous N'th summary line.
10330 If optional argument UNREAD is non-nil, only unread article is selected."
10331 (interactive "p")
10332 (gnus-summary-next-subject (- n) unread))
10333
10334 (defun gnus-summary-prev-unread-subject (n)
10335 "Go to previous N'th unread summary line."
10336 (interactive "p")
10337 (gnus-summary-next-subject (- n) t))
10338
10339 (defun gnus-summary-goto-subject (article &optional force silent)
10340 "Go the subject line of ARTICLE.
10341 If FORCE, also allow jumping to articles not currently shown."
10342 (let ((b (point))
10343 (data (gnus-data-find article)))
10344 ;; We read in the article if we have to.
10345 (and (not data)
10346 force
10347 (gnus-summary-insert-subject article (and (vectorp force) force) t)
10348 (setq data (gnus-data-find article)))
10349 (goto-char b)
10350 (if (not data)
10351 (progn
10352 (unless silent
10353 (gnus-message 3 "Can't find article %d" article))
10354 nil)
10355 (goto-char (gnus-data-pos data))
10356 article)))
10357
10358 ;; Walking around summary lines with displaying articles.
10359
10360 (defun gnus-summary-expand-window (&optional arg)
10361 "Make the summary buffer take up the entire Emacs frame.
10362 Given a prefix, will force an `article' buffer configuration."
10363 (interactive "P")
10364 (gnus-set-global-variables)
10365 (if arg
10366 (gnus-configure-windows 'article 'force)
10367 (gnus-configure-windows 'summary 'force)))
10368
10369 (defun gnus-summary-display-article (article &optional all-header)
10370 "Display ARTICLE in article buffer."
10371 (gnus-set-global-variables)
10372 (if (null article)
10373 nil
10374 (prog1
10375 (if gnus-summary-display-article-function
10376 (funcall gnus-summary-display-article-function article all-header)
10377 (gnus-article-prepare article all-header))
10378 (run-hooks 'gnus-select-article-hook)
10379 (unless (zerop gnus-current-article)
10380 (gnus-summary-goto-subject gnus-current-article))
10381 (gnus-summary-recenter)
10382 (when gnus-use-trees
10383 (gnus-possibly-generate-tree article)
10384 (gnus-highlight-selected-tree article))
10385 ;; Successfully display article.
10386 (gnus-article-set-window-start
10387 (cdr (assq article gnus-newsgroup-bookmarks))))))
10388
10389 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
10390 "Select the current article.
10391 If ALL-HEADERS is non-nil, show all header fields. If FORCE is
10392 non-nil, the article will be re-fetched even if it already present in
10393 the article buffer. If PSEUDO is non-nil, pseudo-articles will also
10394 be displayed."
10395 ;; Make sure we are in the summary buffer to work around bbdb bug.
10396 (unless (eq major-mode 'gnus-summary-mode)
10397 (set-buffer gnus-summary-buffer))
10398 (let ((article (or article (gnus-summary-article-number)))
10399 (all-headers (not (not all-headers))) ;Must be T or NIL.
10400 gnus-summary-display-article-function
10401 did)
10402 (and (not pseudo)
10403 (gnus-summary-article-pseudo-p article)
10404 (error "This is a pseudo-article."))
10405 (prog1
10406 (save-excursion
10407 (set-buffer gnus-summary-buffer)
10408 (if (or (and gnus-single-article-buffer
10409 (or (null gnus-current-article)
10410 (null gnus-article-current)
10411 (null (get-buffer gnus-article-buffer))
10412 (not (eq article (cdr gnus-article-current)))
10413 (not (equal (car gnus-article-current)
10414 gnus-newsgroup-name))))
10415 (and (not gnus-single-article-buffer)
10416 (or (null gnus-current-article)
10417 (not (eq gnus-current-article article))))
10418 force)
10419 ;; The requested article is different from the current article.
10420 (prog1
10421 (gnus-summary-display-article article all-headers)
10422 (setq did article))
10423 (if (or all-headers gnus-show-all-headers)
10424 (gnus-article-show-all-headers))
10425 'old))
10426 (if did
10427 (gnus-article-set-window-start
10428 (cdr (assq article gnus-newsgroup-bookmarks)))))))
10429
10430 (defun gnus-summary-set-current-mark (&optional current-mark)
10431 "Obsolete function."
10432 nil)
10433
10434 (defun gnus-summary-next-article (&optional unread subject backward push)
10435 "Select the next article.
10436 If UNREAD, only unread articles are selected.
10437 If SUBJECT, only articles with SUBJECT are selected.
10438 If BACKWARD, the previous article is selected instead of the next."
10439 (interactive "P")
10440 (gnus-set-global-variables)
10441 (cond
10442 ;; Is there such an article?
10443 ((and (gnus-summary-search-forward unread subject backward)
10444 (or (gnus-summary-display-article (gnus-summary-article-number))
10445 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
10446 (gnus-summary-position-point))
10447 ;; If not, we try the first unread, if that is wanted.
10448 ((and subject
10449 gnus-auto-select-same
10450 (gnus-summary-first-unread-article))
10451 (gnus-summary-position-point)
10452 (gnus-message 6 "Wrapped"))
10453 ;; Try to get next/previous article not displayed in this group.
10454 ((and gnus-auto-extend-newsgroup
10455 (not unread) (not subject))
10456 (gnus-summary-goto-article
10457 (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
10458 nil t))
10459 ;; Go to next/previous group.
10460 (t
10461 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
10462 (gnus-summary-jump-to-group gnus-newsgroup-name))
10463 (let ((cmd last-command-char)
10464 (group
10465 (if (eq gnus-keep-same-level 'best)
10466 (gnus-summary-best-group gnus-newsgroup-name)
10467 (gnus-summary-search-group backward gnus-keep-same-level))))
10468 ;; For some reason, the group window gets selected. We change
10469 ;; it back.
10470 (select-window (get-buffer-window (current-buffer)))
10471 ;; Select next unread newsgroup automagically.
10472 (cond
10473 ((or (not gnus-auto-select-next)
10474 (not cmd))
10475 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
10476 ((or (eq gnus-auto-select-next 'quietly)
10477 (and (eq gnus-auto-select-next 'slightly-quietly)
10478 push)
10479 (and (eq gnus-auto-select-next 'almost-quietly)
10480 (gnus-summary-last-article-p)))
10481 ;; Select quietly.
10482 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
10483 (gnus-summary-exit)
10484 (gnus-message 7 "No more%s articles (%s)..."
10485 (if unread " unread" "")
10486 (if group (concat "selecting " group)
10487 "exiting"))
10488 (gnus-summary-next-group nil group backward)))
10489 (t
10490 (gnus-summary-walk-group-buffer
10491 gnus-newsgroup-name cmd unread backward)))))))
10492
10493 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward)
10494 (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
10495 (?\C-p (gnus-group-prev-unread-group 1))))
10496 keve key group ended)
10497 (save-excursion
10498 (set-buffer gnus-group-buffer)
10499 (gnus-summary-jump-to-group from-group)
10500 (setq group
10501 (if (eq gnus-keep-same-level 'best)
10502 (gnus-summary-best-group gnus-newsgroup-name)
10503 (gnus-summary-search-group backward gnus-keep-same-level))))
10504 (while (not ended)
10505 (gnus-message
10506 5 "No more%s articles%s" (if unread " unread" "")
10507 (if (and group
10508 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
10509 (format " (Type %s for %s [%s])"
10510 (single-key-description cmd) group
10511 (car (gnus-gethash group gnus-newsrc-hashtb)))
10512 (format " (Type %s to exit %s)"
10513 (single-key-description cmd)
10514 gnus-newsgroup-name)))
10515 ;; Confirm auto selection.
10516 (setq key (car (setq keve (gnus-read-event-char))))
10517 (setq ended t)
10518 (cond
10519 ((assq key keystrokes)
10520 (let ((obuf (current-buffer)))
10521 (switch-to-buffer gnus-group-buffer)
10522 (and group
10523 (gnus-group-jump-to-group group))
10524 (eval (cadr (assq key keystrokes)))
10525 (setq group (gnus-group-group-name))
10526 (switch-to-buffer obuf))
10527 (setq ended nil))
10528 ((equal key cmd)
10529 (if (or (not group)
10530 (gnus-ephemeral-group-p gnus-newsgroup-name))
10531 (gnus-summary-exit)
10532 (gnus-summary-next-group nil group backward)))
10533 (t
10534 (push (cdr keve) unread-command-events))))))
10535
10536 (defun gnus-read-event-char ()
10537 "Get the next event."
10538 (let ((event (read-event)))
10539 (cons (and (numberp event) event) event)))
10540
10541 (defun gnus-summary-next-unread-article ()
10542 "Select unread article after current one."
10543 (interactive)
10544 (gnus-summary-next-article t (and gnus-auto-select-same
10545 (gnus-summary-article-subject))))
10546
10547 (defun gnus-summary-prev-article (&optional unread subject)
10548 "Select the article after the current one.
10549 If UNREAD is non-nil, only unread articles are selected."
10550 (interactive "P")
10551 (gnus-summary-next-article unread subject t))
10552
10553 (defun gnus-summary-prev-unread-article ()
10554 "Select unred article before current one."
10555 (interactive)
10556 (gnus-summary-prev-article t (and gnus-auto-select-same
10557 (gnus-summary-article-subject))))
10558
10559 (defun gnus-summary-next-page (&optional lines circular)
10560 "Show next page of the selected article.
10561 If at the end of the current article, select the next article.
10562 LINES says how many lines should be scrolled up.
10563
10564 If CIRCULAR is non-nil, go to the start of the article instead of
10565 selecting the next article when reaching the end of the current
10566 article."
10567 (interactive "P")
10568 (setq gnus-summary-buffer (current-buffer))
10569 (gnus-set-global-variables)
10570 (let ((article (gnus-summary-article-number))
10571 (endp nil))
10572 (gnus-configure-windows 'article)
10573 (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
10574 (if (and (eq gnus-summary-goto-unread 'never)
10575 (not (gnus-summary-last-article-p article)))
10576 (gnus-summary-next-article)
10577 (gnus-summary-next-unread-article))
10578 (if (or (null gnus-current-article)
10579 (null gnus-article-current)
10580 (/= article (cdr gnus-article-current))
10581 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
10582 ;; Selected subject is different from current article's.
10583 (gnus-summary-display-article article)
10584 (gnus-eval-in-buffer-window gnus-article-buffer
10585 (setq endp (gnus-article-next-page lines)))
10586 (if endp
10587 (cond (circular
10588 (gnus-summary-beginning-of-article))
10589 (lines
10590 (gnus-message 3 "End of message"))
10591 ((null lines)
10592 (if (and (eq gnus-summary-goto-unread 'never)
10593 (not (gnus-summary-last-article-p article)))
10594 (gnus-summary-next-article)
10595 (gnus-summary-next-unread-article)))))))
10596 (gnus-summary-recenter)
10597 (gnus-summary-position-point)))
10598
10599 (defun gnus-summary-prev-page (&optional lines)
10600 "Show previous page of selected article.
10601 Argument LINES specifies lines to be scrolled down."
10602 (interactive "P")
10603 (gnus-set-global-variables)
10604 (let ((article (gnus-summary-article-number)))
10605 (gnus-configure-windows 'article)
10606 (if (or (null gnus-current-article)
10607 (null gnus-article-current)
10608 (/= article (cdr gnus-article-current))
10609 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
10610 ;; Selected subject is different from current article's.
10611 (gnus-summary-display-article article)
10612 (gnus-summary-recenter)
10613 (gnus-eval-in-buffer-window gnus-article-buffer
10614 (gnus-article-prev-page lines))))
10615 (gnus-summary-position-point))
10616
10617 (defun gnus-summary-scroll-up (lines)
10618 "Scroll up (or down) one line current article.
10619 Argument LINES specifies lines to be scrolled up (or down if negative)."
10620 (interactive "p")
10621 (gnus-set-global-variables)
10622 (gnus-configure-windows 'article)
10623 (gnus-summary-show-thread)
10624 (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
10625 (gnus-eval-in-buffer-window gnus-article-buffer
10626 (cond ((> lines 0)
10627 (if (gnus-article-next-page lines)
10628 (gnus-message 3 "End of message")))
10629 ((< lines 0)
10630 (gnus-article-prev-page (- lines))))))
10631 (gnus-summary-recenter)
10632 (gnus-summary-position-point))
10633
10634 (defun gnus-summary-next-same-subject ()
10635 "Select next article which has the same subject as current one."
10636 (interactive)
10637 (gnus-set-global-variables)
10638 (gnus-summary-next-article nil (gnus-summary-article-subject)))
10639
10640 (defun gnus-summary-prev-same-subject ()
10641 "Select previous article which has the same subject as current one."
10642 (interactive)
10643 (gnus-set-global-variables)
10644 (gnus-summary-prev-article nil (gnus-summary-article-subject)))
10645
10646 (defun gnus-summary-next-unread-same-subject ()
10647 "Select next unread article which has the same subject as current one."
10648 (interactive)
10649 (gnus-set-global-variables)
10650 (gnus-summary-next-article t (gnus-summary-article-subject)))
10651
10652 (defun gnus-summary-prev-unread-same-subject ()
10653 "Select previous unread article which has the same subject as current one."
10654 (interactive)
10655 (gnus-set-global-variables)
10656 (gnus-summary-prev-article t (gnus-summary-article-subject)))
10657
10658 (defun gnus-summary-first-unread-article ()
10659 "Select the first unread article.
10660 Return nil if there are no unread articles."
10661 (interactive)
10662 (gnus-set-global-variables)
10663 (prog1
10664 (if (gnus-summary-first-subject t)
10665 (progn
10666 (gnus-summary-show-thread)
10667 (gnus-summary-first-subject t)
10668 (gnus-summary-display-article (gnus-summary-article-number))))
10669 (gnus-summary-position-point)))
10670
10671 (defun gnus-summary-best-unread-article ()
10672 "Select the unread article with the highest score."
10673 (interactive)
10674 (gnus-set-global-variables)
10675 (let ((best -1000000)
10676 (data gnus-newsgroup-data)
10677 article score)
10678 (while data
10679 (and (gnus-data-unread-p (car data))
10680 (> (setq score
10681 (gnus-summary-article-score (gnus-data-number (car data))))
10682 best)
10683 (setq best score
10684 article (gnus-data-number (car data))))
10685 (setq data (cdr data)))
10686 (prog1
10687 (if article
10688 (gnus-summary-goto-article article)
10689 (error "No unread articles"))
10690 (gnus-summary-position-point))))
10691
10692 (defun gnus-summary-last-subject ()
10693 "Go to the last displayed subject line in the group."
10694 (let ((article (gnus-data-number (car (gnus-data-list t)))))
10695 (when article
10696 (gnus-summary-goto-subject article))))
10697
10698 (defun gnus-summary-goto-article (article &optional all-headers force)
10699 "Fetch ARTICLE and display it if it exists.
10700 If ALL-HEADERS is non-nil, no header lines are hidden."
10701 (interactive
10702 (list
10703 (string-to-int
10704 (completing-read
10705 "Article number: "
10706 (mapcar (lambda (number) (list (int-to-string number)))
10707 gnus-newsgroup-limit)))
10708 current-prefix-arg
10709 t))
10710 (prog1
10711 (if (gnus-summary-goto-subject article force)
10712 (gnus-summary-display-article article all-headers)
10713 (gnus-message 4 "Couldn't go to article %s" article) nil)
10714 (gnus-summary-position-point)))
10715
10716 (defun gnus-summary-goto-last-article ()
10717 "Go to the previously read article."
10718 (interactive)
10719 (prog1
10720 (and gnus-last-article
10721 (gnus-summary-goto-article gnus-last-article))
10722 (gnus-summary-position-point)))
10723
10724 (defun gnus-summary-pop-article (number)
10725 "Pop one article off the history and go to the previous.
10726 NUMBER articles will be popped off."
10727 (interactive "p")
10728 (let (to)
10729 (setq gnus-newsgroup-history
10730 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
10731 (if to
10732 (gnus-summary-goto-article (car to))
10733 (error "Article history empty")))
10734 (gnus-summary-position-point))
10735
10736 ;; Summary commands and functions for limiting the summary buffer.
10737
10738 (defun gnus-summary-limit-to-articles (n)
10739 "Limit the summary buffer to the next N articles.
10740 If not given a prefix, use the process marked articles instead."
10741 (interactive "P")
10742 (gnus-set-global-variables)
10743 (prog1
10744 (let ((articles (gnus-summary-work-articles n)))
10745 (setq gnus-newsgroup-processable nil)
10746 (gnus-summary-limit articles))
10747 (gnus-summary-position-point)))
10748
10749 (defun gnus-summary-pop-limit (&optional total)
10750 "Restore the previous limit.
10751 If given a prefix, remove all limits."
10752 (interactive "P")
10753 (gnus-set-global-variables)
10754 (when total
10755 (setq gnus-newsgroup-limits
10756 (list (mapcar (lambda (h) (mail-header-number h))
10757 gnus-newsgroup-headers))))
10758 (unless gnus-newsgroup-limits
10759 (error "No limit to pop"))
10760 (prog1
10761 (gnus-summary-limit nil 'pop)
10762 (gnus-summary-position-point)))
10763
10764 (defun gnus-summary-limit-to-subject (subject &optional header)
10765 "Limit the summary buffer to articles that have subjects that match a regexp."
10766 (interactive "sRegexp: ")
10767 (unless header
10768 (setq header "subject"))
10769 (when (not (equal "" subject))
10770 (prog1
10771 (let ((articles (gnus-summary-find-matching
10772 (or header "subject") subject 'all)))
10773 (or articles (error "Found no matches for \"%s\"" subject))
10774 (gnus-summary-limit articles))
10775 (gnus-summary-position-point))))
10776
10777 (defun gnus-summary-limit-to-author (from)
10778 "Limit the summary buffer to articles that have authors that match a regexp."
10779 (interactive "sRegexp: ")
10780 (gnus-summary-limit-to-subject from "from"))
10781
10782 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
10783 (make-obsolete
10784 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
10785
10786 (defun gnus-summary-limit-to-unread (&optional all)
10787 "Limit the summary buffer to articles that are not marked as read.
10788 If ALL is non-nil, limit strictly to unread articles."
10789 (interactive "P")
10790 (if all
10791 (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
10792 (gnus-summary-limit-to-marks
10793 ;; Concat all the marks that say that an article is read and have
10794 ;; those removed.
10795 (list gnus-del-mark gnus-read-mark gnus-ancient-mark
10796 gnus-killed-mark gnus-kill-file-mark
10797 gnus-low-score-mark gnus-expirable-mark
10798 gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark)
10799 'reverse)))
10800
10801 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-to-marks)
10802 (make-obsolete 'gnus-summary-delete-marked-with 'gnus-summary-limit-to-marks)
10803
10804 (defun gnus-summary-limit-to-marks (marks &optional reverse)
10805 "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
10806 If REVERSE, limit the summary buffer to articles that are not marked
10807 with MARKS. MARKS can either be a string of marks or a list of marks.
10808 Returns how many articles were removed."
10809 (interactive "sMarks: ")
10810 (gnus-set-global-variables)
10811 (prog1
10812 (let ((data gnus-newsgroup-data)
10813 (marks (if (listp marks) marks
10814 (append marks nil))) ; Transform to list.
10815 articles)
10816 (while data
10817 (and (if reverse (not (memq (gnus-data-mark (car data)) marks))
10818 (memq (gnus-data-mark (car data)) marks))
10819 (setq articles (cons (gnus-data-number (car data)) articles)))
10820 (setq data (cdr data)))
10821 (gnus-summary-limit articles))
10822 (gnus-summary-position-point)))
10823
10824 (defun gnus-summary-limit-to-score (&optional score)
10825 "Limit to articles with score at or above SCORE."
10826 (interactive "P")
10827 (gnus-set-global-variables)
10828 (setq score (if score
10829 (prefix-numeric-value score)
10830 (or gnus-summary-default-score 0)))
10831 (let ((data gnus-newsgroup-data)
10832 articles)
10833 (while data
10834 (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
10835 score)
10836 (push (gnus-data-number (car data)) articles))
10837 (setq data (cdr data)))
10838 (prog1
10839 (gnus-summary-limit articles)
10840 (gnus-summary-position-point))))
10841
10842 (defun gnus-summary-limit-include-dormant ()
10843 "Display all the hidden articles that are marked as dormant."
10844 (interactive)
10845 (gnus-set-global-variables)
10846 (or gnus-newsgroup-dormant
10847 (error "There are no dormant articles in this group"))
10848 (prog1
10849 (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
10850 (gnus-summary-position-point)))
10851
10852 (defun gnus-summary-limit-exclude-dormant ()
10853 "Hide all dormant articles."
10854 (interactive)
10855 (gnus-set-global-variables)
10856 (prog1
10857 (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
10858 (gnus-summary-position-point)))
10859
10860 (defun gnus-summary-limit-exclude-childless-dormant ()
10861 "Hide all dormant articles that have no children."
10862 (interactive)
10863 (gnus-set-global-variables)
10864 (let ((data (gnus-data-list t))
10865 articles d children)
10866 ;; Find all articles that are either not dormant or have
10867 ;; children.
10868 (while (setq d (pop data))
10869 (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
10870 (and (setq children
10871 (gnus-article-children (gnus-data-number d)))
10872 (let (found)
10873 (while children
10874 (when (memq (car children) articles)
10875 (setq children nil
10876 found t))
10877 (pop children))
10878 found)))
10879 (push (gnus-data-number d) articles)))
10880 ;; Do the limiting.
10881 (prog1
10882 (gnus-summary-limit articles)
10883 (gnus-summary-position-point))))
10884
10885 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
10886 "Mark all unread excluded articles as read.
10887 If ALL, mark even excluded ticked and dormants as read."
10888 (interactive "P")
10889 (let ((articles (gnus-sorted-complement
10890 (sort
10891 (mapcar (lambda (h) (mail-header-number h))
10892 gnus-newsgroup-headers)
10893 '<)
10894 (sort gnus-newsgroup-limit '<)))
10895 article)
10896 (setq gnus-newsgroup-unreads nil)
10897 (if all
10898 (setq gnus-newsgroup-dormant nil
10899 gnus-newsgroup-marked nil
10900 gnus-newsgroup-reads
10901 (nconc
10902 (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
10903 gnus-newsgroup-reads))
10904 (while (setq article (pop articles))
10905 (unless (or (memq article gnus-newsgroup-dormant)
10906 (memq article gnus-newsgroup-marked))
10907 (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
10908
10909 (defun gnus-summary-limit (articles &optional pop)
10910 (if pop
10911 ;; We pop the previous limit off the stack and use that.
10912 (setq articles (car gnus-newsgroup-limits)
10913 gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
10914 ;; We use the new limit, so we push the old limit on the stack.
10915 (setq gnus-newsgroup-limits
10916 (cons gnus-newsgroup-limit gnus-newsgroup-limits)))
10917 ;; Set the limit.
10918 (setq gnus-newsgroup-limit articles)
10919 (let ((total (length gnus-newsgroup-data))
10920 (data (gnus-data-find-list (gnus-summary-article-number)))
10921 (gnus-summary-mark-below nil) ; Inhibit this.
10922 found)
10923 ;; This will do all the work of generating the new summary buffer
10924 ;; according to the new limit.
10925 (gnus-summary-prepare)
10926 ;; Hide any threads, possibly.
10927 (and gnus-show-threads
10928 gnus-thread-hide-subtree
10929 (gnus-summary-hide-all-threads))
10930 ;; Try to return to the article you were at, or one in the
10931 ;; neighborhood.
10932 (if data
10933 ;; We try to find some article after the current one.
10934 (while data
10935 (and (gnus-summary-goto-subject
10936 (gnus-data-number (car data)) nil t)
10937 (setq data nil
10938 found t))
10939 (setq data (cdr data))))
10940 (or found
10941 ;; If there is no data, that means that we were after the last
10942 ;; article. The same goes when we can't find any articles
10943 ;; after the current one.
10944 (progn
10945 (goto-char (point-max))
10946 (gnus-summary-find-prev)))
10947 ;; We return how many articles were removed from the summary
10948 ;; buffer as a result of the new limit.
10949 (- total (length gnus-newsgroup-data))))
10950
10951 (defsubst gnus-invisible-cut-children (threads)
10952 (let ((num 0))
10953 (while threads
10954 (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
10955 (incf num))
10956 (pop threads))
10957 (< num 2)))
10958
10959 (defsubst gnus-cut-thread (thread)
10960 "Go forwards in the thread until we find an article that we want to display."
10961 (when (or (eq gnus-fetch-old-headers 'some)
10962 (eq gnus-build-sparse-threads 'some)
10963 (eq gnus-build-sparse-threads 'more))
10964 ;; Deal with old-fetched headers and sparse threads.
10965 (while (and
10966 thread
10967 (or
10968 (memq (mail-header-number (car thread)) gnus-newsgroup-sparse)
10969 (memq (mail-header-number (car thread)) gnus-newsgroup-ancient))
10970 (or (<= (length (cdr thread)) 1)
10971 (gnus-invisible-cut-children (cdr thread))))
10972 (setq thread (cadr thread))))
10973 thread)
10974
10975 (defun gnus-cut-threads (threads)
10976 "Cut off all uninteresting articles from the beginning of threads."
10977 (when (or (eq gnus-fetch-old-headers 'some)
10978 (eq gnus-build-sparse-threads 'some)
10979 (eq gnus-build-sparse-threads 'more))
10980 (let ((th threads))
10981 (while th
10982 (setcar th (gnus-cut-thread (car th)))
10983 (setq th (cdr th)))))
10984 ;; Remove nixed out threads.
10985 (delq nil threads))
10986
10987 (defun gnus-summary-initial-limit (&optional show-if-empty)
10988 "Figure out what the initial limit is supposed to be on group entry.
10989 This entails weeding out unwanted dormants, low-scored articles,
10990 fetch-old-headers verbiage, and so on."
10991 ;; Most groups have nothing to remove.
10992 (if (or gnus-inhibit-limiting
10993 (and (null gnus-newsgroup-dormant)
10994 (not (eq gnus-fetch-old-headers 'some))
10995 (null gnus-summary-expunge-below)
10996 (not (eq gnus-build-sparse-threads 'some))
10997 (not (eq gnus-build-sparse-threads 'more))
10998 (null gnus-thread-expunge-below)
10999 (not gnus-use-nocem)))
11000 () ; Do nothing.
11001 (push gnus-newsgroup-limit gnus-newsgroup-limits)
11002 (setq gnus-newsgroup-limit nil)
11003 (mapatoms
11004 (lambda (node)
11005 (unless (car (symbol-value node))
11006 ;; These threads have no parents -- they are roots.
11007 (let ((nodes (cdr (symbol-value node)))
11008 thread)
11009 (while nodes
11010 (if (and gnus-thread-expunge-below
11011 (< (gnus-thread-total-score (car nodes))
11012 gnus-thread-expunge-below))
11013 (gnus-expunge-thread (pop nodes))
11014 (setq thread (pop nodes))
11015 (gnus-summary-limit-children thread))))))
11016 gnus-newsgroup-dependencies)
11017 ;; If this limitation resulted in an empty group, we might
11018 ;; pop the previous limit and use it instead.
11019 (when (and (not gnus-newsgroup-limit)
11020 show-if-empty)
11021 (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
11022 gnus-newsgroup-limit))
11023
11024 (defun gnus-summary-limit-children (thread)
11025 "Return 1 if this subthread is visible and 0 if it is not."
11026 ;; First we get the number of visible children to this thread. This
11027 ;; is done by recursing down the thread using this function, so this
11028 ;; will really go down to a leaf article first, before slowly
11029 ;; working its way up towards the root.
11030 (when thread
11031 (let ((children
11032 (if (cdr thread)
11033 (apply '+ (mapcar 'gnus-summary-limit-children
11034 (cdr thread)))
11035 0))
11036 (number (mail-header-number (car thread)))
11037 score)
11038 (if (or
11039 ;; If this article is dormant and has absolutely no visible
11040 ;; children, then this article isn't visible.
11041 (and (memq number gnus-newsgroup-dormant)
11042 (= children 0))
11043 ;; If this is "fetch-old-headered" and there is only one
11044 ;; visible child (or less), then we don't want this article.
11045 (and (eq gnus-fetch-old-headers 'some)
11046 (memq number gnus-newsgroup-ancient)
11047 (zerop children))
11048 ;; If this is a sparsely inserted article with no children,
11049 ;; we don't want it.
11050 (and (eq gnus-build-sparse-threads 'some)
11051 (memq number gnus-newsgroup-sparse)
11052 (zerop children))
11053 ;; If we use expunging, and this article is really
11054 ;; low-scored, then we don't want this article.
11055 (when (and gnus-summary-expunge-below
11056 (< (setq score
11057 (or (cdr (assq number gnus-newsgroup-scored))
11058 gnus-summary-default-score))
11059 gnus-summary-expunge-below))
11060 ;; We increase the expunge-tally here, but that has
11061 ;; nothing to do with the limits, really.
11062 (incf gnus-newsgroup-expunged-tally)
11063 ;; We also mark as read here, if that's wanted.
11064 (when (and gnus-summary-mark-below
11065 (< score gnus-summary-mark-below))
11066 (setq gnus-newsgroup-unreads
11067 (delq number gnus-newsgroup-unreads))
11068 (if gnus-newsgroup-auto-expire
11069 (push number gnus-newsgroup-expirable)
11070 (push (cons number gnus-low-score-mark)
11071 gnus-newsgroup-reads)))
11072 t)
11073 (and gnus-use-nocem
11074 (gnus-nocem-unwanted-article-p (mail-header-id (car thread)))))
11075 ;; Nope, invisible article.
11076 0
11077 ;; Ok, this article is to be visible, so we add it to the limit
11078 ;; and return 1.
11079 (setq gnus-newsgroup-limit (cons number gnus-newsgroup-limit))
11080 1))))
11081
11082 (defun gnus-expunge-thread (thread)
11083 "Mark all articles in THREAD as read."
11084 (let* ((number (mail-header-number (car thread))))
11085 (incf gnus-newsgroup-expunged-tally)
11086 ;; We also mark as read here, if that's wanted.
11087 (setq gnus-newsgroup-unreads
11088 (delq number gnus-newsgroup-unreads))
11089 (if gnus-newsgroup-auto-expire
11090 (push number gnus-newsgroup-expirable)
11091 (push (cons number gnus-low-score-mark)
11092 gnus-newsgroup-reads)))
11093 ;; Go recursively through all subthreads.
11094 (mapcar 'gnus-expunge-thread (cdr thread)))
11095
11096 ;; Summary article oriented commands
11097
11098 (defun gnus-summary-refer-parent-article (n)
11099 "Refer parent article N times.
11100 The difference between N and the number of articles fetched is returned."
11101 (interactive "p")
11102 (gnus-set-global-variables)
11103 (while
11104 (and
11105 (> n 0)
11106 (let* ((header (gnus-summary-article-header))
11107 (ref
11108 ;; If we try to find the parent of the currently
11109 ;; displayed article, then we take a look at the actual
11110 ;; References header, since this is slightly more
11111 ;; reliable than the References field we got from the
11112 ;; server.
11113 (if (and (eq (mail-header-number header)
11114 (cdr gnus-article-current))
11115 (equal gnus-newsgroup-name
11116 (car gnus-article-current)))
11117 (save-excursion
11118 (set-buffer gnus-original-article-buffer)
11119 (nnheader-narrow-to-headers)
11120 (prog1
11121 (message-fetch-field "references")
11122 (widen)))
11123 ;; It's not the current article, so we take a bet on
11124 ;; the value we got from the server.
11125 (mail-header-references header))))
11126 (if (setq ref (or ref (mail-header-references header)))
11127 (or (gnus-summary-refer-article (gnus-parent-id ref))
11128 (gnus-message 1 "Couldn't find parent"))
11129 (gnus-message 1 "No references in article %d"
11130 (gnus-summary-article-number))
11131 nil)))
11132 (setq n (1- n)))
11133 (gnus-summary-position-point)
11134 n)
11135
11136 (defun gnus-summary-refer-references ()
11137 "Fetch all articles mentioned in the References header.
11138 Return how many articles were fetched."
11139 (interactive)
11140 (gnus-set-global-variables)
11141 (let ((ref (mail-header-references (gnus-summary-article-header)))
11142 (current (gnus-summary-article-number))
11143 (n 0))
11144 ;; For each Message-ID in the References header...
11145 (while (string-match "<[^>]*>" ref)
11146 (incf n)
11147 ;; ... fetch that article.
11148 (gnus-summary-refer-article
11149 (prog1 (match-string 0 ref)
11150 (setq ref (substring ref (match-end 0))))))
11151 (gnus-summary-goto-subject current)
11152 (gnus-summary-position-point)
11153 n))
11154
11155 (defun gnus-summary-refer-article (message-id)
11156 "Fetch an article specified by MESSAGE-ID."
11157 (interactive "sMessage-ID: ")
11158 (when (and (stringp message-id)
11159 (not (zerop (length message-id))))
11160 ;; Construct the correct Message-ID if necessary.
11161 ;; Suggested by tale@pawl.rpi.edu.
11162 (unless (string-match "^<" message-id)
11163 (setq message-id (concat "<" message-id)))
11164 (unless (string-match ">$" message-id)
11165 (setq message-id (concat message-id ">")))
11166 (let* ((header (gnus-id-to-header message-id))
11167 (sparse (and header
11168 (memq (mail-header-number header)
11169 gnus-newsgroup-sparse))))
11170 (if header
11171 (prog1
11172 ;; The article is present in the buffer, to we just go to it.
11173 (gnus-summary-goto-article
11174 (mail-header-number header) nil header)
11175 (when sparse
11176 (gnus-summary-update-article (mail-header-number header))))
11177 ;; We fetch the article
11178 (let ((gnus-override-method
11179 (and (gnus-news-group-p gnus-newsgroup-name)
11180 gnus-refer-article-method))
11181 number)
11182 ;; Start the special refer-article method, if necessary.
11183 (when (and gnus-refer-article-method
11184 (gnus-news-group-p gnus-newsgroup-name))
11185 (gnus-check-server gnus-refer-article-method))
11186 ;; Fetch the header, and display the article.
11187 (if (setq number (gnus-summary-insert-subject message-id))
11188 (gnus-summary-select-article nil nil nil number)
11189 (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
11190
11191 (defun gnus-summary-enter-digest-group (&optional force)
11192 "Enter a digest group based on the current article."
11193 (interactive "P")
11194 (gnus-set-global-variables)
11195 (gnus-summary-select-article)
11196 (let ((name (format "%s-%d"
11197 (gnus-group-prefixed-name
11198 gnus-newsgroup-name (list 'nndoc ""))
11199 gnus-current-article))
11200 (ogroup gnus-newsgroup-name)
11201 (case-fold-search t)
11202 (buf (current-buffer))
11203 dig)
11204 (save-excursion
11205 (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
11206 (insert-buffer-substring gnus-original-article-buffer)
11207 (narrow-to-region
11208 (goto-char (point-min))
11209 (or (search-forward "\n\n" nil t) (point)))
11210 (goto-char (point-min))
11211 (delete-matching-lines "^\\(Path\\):\\|^From ")
11212 (widen))
11213 (unwind-protect
11214 (if (gnus-group-read-ephemeral-group
11215 name `(nndoc ,name (nndoc-address
11216 ,(get-buffer dig))
11217 (nndoc-article-type ,(if force 'digest 'guess))) t)
11218 ;; Make all postings to this group go to the parent group.
11219 (nconc (gnus-info-params (gnus-get-info name))
11220 (list (cons 'to-group ogroup)))
11221 ;; Couldn't select this doc group.
11222 (switch-to-buffer buf)
11223 (gnus-set-global-variables)
11224 (gnus-configure-windows 'summary)
11225 (gnus-message 3 "Article couldn't be entered?"))
11226 (kill-buffer dig))))
11227
11228 (defun gnus-summary-isearch-article (&optional regexp-p)
11229 "Do incremental search forward on the current article.
11230 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
11231 (interactive "P")
11232 (gnus-set-global-variables)
11233 (gnus-summary-select-article)
11234 (gnus-configure-windows 'article)
11235 (gnus-eval-in-buffer-window gnus-article-buffer
11236 (goto-char (point-min))
11237 (isearch-forward regexp-p)))
11238
11239 (defun gnus-summary-search-article-forward (regexp &optional backward)
11240 "Search for an article containing REGEXP forward.
11241 If BACKWARD, search backward instead."
11242 (interactive
11243 (list (read-string
11244 (format "Search article %s (regexp%s): "
11245 (if current-prefix-arg "backward" "forward")
11246 (if gnus-last-search-regexp
11247 (concat ", default " gnus-last-search-regexp)
11248 "")))
11249 current-prefix-arg))
11250 (gnus-set-global-variables)
11251 (if (string-equal regexp "")
11252 (setq regexp (or gnus-last-search-regexp ""))
11253 (setq gnus-last-search-regexp regexp))
11254 (unless (gnus-summary-search-article regexp backward)
11255 (error "Search failed: \"%s\"" regexp)))
11256
11257 (defun gnus-summary-search-article-backward (regexp)
11258 "Search for an article containing REGEXP backward."
11259 (interactive
11260 (list (read-string
11261 (format "Search article backward (regexp%s): "
11262 (if gnus-last-search-regexp
11263 (concat ", default " gnus-last-search-regexp)
11264 "")))))
11265 (gnus-summary-search-article-forward regexp 'backward))
11266
11267 (defun gnus-summary-search-article (regexp &optional backward)
11268 "Search for an article containing REGEXP.
11269 Optional argument BACKWARD means do search for backward.
11270 `gnus-select-article-hook' is not called during the search."
11271 (let ((gnus-select-article-hook nil) ;Disable hook.
11272 (gnus-article-display-hook nil)
11273 (gnus-mark-article-hook nil) ;Inhibit marking as read.
11274 (re-search
11275 (if backward
11276 're-search-backward 're-search-forward))
11277 (sum (current-buffer))
11278 (found nil))
11279 (gnus-save-hidden-threads
11280 (gnus-summary-select-article)
11281 (set-buffer gnus-article-buffer)
11282 (when backward
11283 (forward-line -1))
11284 (while (not found)
11285 (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
11286 (if (if backward
11287 (re-search-backward regexp nil t)
11288 (re-search-forward regexp nil t))
11289 ;; We found the regexp.
11290 (progn
11291 (setq found 'found)
11292 (beginning-of-line)
11293 (set-window-start
11294 (get-buffer-window (current-buffer))
11295 (point))
11296 (forward-line 1)
11297 (set-buffer sum))
11298 ;; We didn't find it, so we go to the next article.
11299 (set-buffer sum)
11300 (if (not (if backward (gnus-summary-find-prev)
11301 (gnus-summary-find-next)))
11302 ;; No more articles.
11303 (setq found t)
11304 ;; Select the next article and adjust point.
11305 (gnus-summary-select-article)
11306 (set-buffer gnus-article-buffer)
11307 (widen)
11308 (goto-char (if backward (point-max) (point-min))))))
11309 (gnus-message 7 ""))
11310 ;; Return whether we found the regexp.
11311 (when (eq found 'found)
11312 (gnus-summary-show-thread)
11313 (gnus-summary-goto-subject gnus-current-article)
11314 (gnus-summary-position-point)
11315 t)))
11316
11317 (defun gnus-summary-find-matching (header regexp &optional backward unread
11318 not-case-fold)
11319 "Return a list of all articles that match REGEXP on HEADER.
11320 The search stars on the current article and goes forwards unless
11321 BACKWARD is non-nil. If BACKWARD is `all', do all articles.
11322 If UNREAD is non-nil, only unread articles will
11323 be taken into consideration. If NOT-CASE-FOLD, case won't be folded
11324 in the comparisons."
11325 (let ((data (if (eq backward 'all) gnus-newsgroup-data
11326 (gnus-data-find-list
11327 (gnus-summary-article-number) (gnus-data-list backward))))
11328 (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
11329 (case-fold-search (not not-case-fold))
11330 articles d)
11331 (or (fboundp (intern (concat "mail-header-" header)))
11332 (error "%s is not a valid header" header))
11333 (while data
11334 (setq d (car data))
11335 (and (or (not unread) ; We want all articles...
11336 (gnus-data-unread-p d)) ; Or just unreads.
11337 (vectorp (gnus-data-header d)) ; It's not a pseudo.
11338 (string-match regexp (funcall func (gnus-data-header d))) ; Match.
11339 (setq articles (cons (gnus-data-number d) articles))) ; Success!
11340 (setq data (cdr data)))
11341 (nreverse articles)))
11342
11343 (defun gnus-summary-execute-command (header regexp command &optional backward)
11344 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
11345 If HEADER is an empty string (or nil), the match is done on the entire
11346 article. If BACKWARD (the prefix) is non-nil, search backward instead."
11347 (interactive
11348 (list (let ((completion-ignore-case t))
11349 (completing-read
11350 "Header name: "
11351 (mapcar (lambda (string) (list string))
11352 '("Number" "Subject" "From" "Lines" "Date"
11353 "Message-ID" "Xref" "References" "Body"))
11354 nil 'require-match))
11355 (read-string "Regexp: ")
11356 (read-key-sequence "Command: ")
11357 current-prefix-arg))
11358 (when (equal header "Body")
11359 (setq header ""))
11360 (gnus-set-global-variables)
11361 ;; Hidden thread subtrees must be searched as well.
11362 (gnus-summary-show-all-threads)
11363 ;; We don't want to change current point nor window configuration.
11364 (save-excursion
11365 (save-window-excursion
11366 (gnus-message 6 "Executing %s..." (key-description command))
11367 ;; We'd like to execute COMMAND interactively so as to give arguments.
11368 (gnus-execute header regexp
11369 `(lambda () (call-interactively ',(key-binding command)))
11370 backward)
11371 (gnus-message 6 "Executing %s...done" (key-description command)))))
11372
11373 (defun gnus-summary-beginning-of-article ()
11374 "Scroll the article back to the beginning."
11375 (interactive)
11376 (gnus-set-global-variables)
11377 (gnus-summary-select-article)
11378 (gnus-configure-windows 'article)
11379 (gnus-eval-in-buffer-window gnus-article-buffer
11380 (widen)
11381 (goto-char (point-min))
11382 (and gnus-break-pages (gnus-narrow-to-page))))
11383
11384 (defun gnus-summary-end-of-article ()
11385 "Scroll to the end of the article."
11386 (interactive)
11387 (gnus-set-global-variables)
11388 (gnus-summary-select-article)
11389 (gnus-configure-windows 'article)
11390 (gnus-eval-in-buffer-window gnus-article-buffer
11391 (widen)
11392 (goto-char (point-max))
11393 (recenter -3)
11394 (and gnus-break-pages (gnus-narrow-to-page))))
11395
11396 (defun gnus-summary-show-article (&optional arg)
11397 "Force re-fetching of the current article.
11398 If ARG (the prefix) is non-nil, show the raw article without any
11399 article massaging functions being run."
11400 (interactive "P")
11401 (gnus-set-global-variables)
11402 (if (not arg)
11403 ;; Select the article the normal way.
11404 (gnus-summary-select-article nil 'force)
11405 ;; Bind the article treatment functions to nil.
11406 (let ((gnus-have-all-headers t)
11407 gnus-article-display-hook
11408 gnus-article-prepare-hook
11409 gnus-break-pages
11410 gnus-visual)
11411 (gnus-summary-select-article nil 'force)))
11412 (gnus-summary-goto-subject gnus-current-article)
11413 ; (gnus-configure-windows 'article)
11414 (gnus-summary-position-point))
11415
11416 (defun gnus-summary-verbose-headers (&optional arg)
11417 "Toggle permanent full header display.
11418 If ARG is a positive number, turn header display on.
11419 If ARG is a negative number, turn header display off."
11420 (interactive "P")
11421 (gnus-set-global-variables)
11422 (gnus-summary-toggle-header arg)
11423 (setq gnus-show-all-headers
11424 (cond ((or (not (numberp arg))
11425 (zerop arg))
11426 (not gnus-show-all-headers))
11427 ((natnump arg)
11428 t))))
11429
11430 (defun gnus-summary-toggle-header (&optional arg)
11431 "Show the headers if they are hidden, or hide them if they are shown.
11432 If ARG is a positive number, show the entire header.
11433 If ARG is a negative number, hide the unwanted header lines."
11434 (interactive "P")
11435 (gnus-set-global-variables)
11436 (save-excursion
11437 (set-buffer gnus-article-buffer)
11438 (let* ((buffer-read-only nil)
11439 (inhibit-point-motion-hooks t)
11440 (hidden (text-property-any
11441 (goto-char (point-min)) (search-forward "\n\n")
11442 'invisible t))
11443 e)
11444 (goto-char (point-min))
11445 (when (search-forward "\n\n" nil t)
11446 (delete-region (point-min) (1- (point))))
11447 (goto-char (point-min))
11448 (save-excursion
11449 (set-buffer gnus-original-article-buffer)
11450 (goto-char (point-min))
11451 (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
11452 (insert-buffer-substring gnus-original-article-buffer 1 e)
11453 (let ((gnus-inhibit-hiding t))
11454 (run-hooks 'gnus-article-display-hook))
11455 (if (or (not hidden) (and (numberp arg) (< arg 0)))
11456 (gnus-article-hide-headers)))))
11457
11458 (defun gnus-summary-show-all-headers ()
11459 "Make all header lines visible."
11460 (interactive)
11461 (gnus-set-global-variables)
11462 (gnus-article-show-all-headers))
11463
11464 (defun gnus-summary-toggle-mime (&optional arg)
11465 "Toggle MIME processing.
11466 If ARG is a positive number, turn MIME processing on."
11467 (interactive "P")
11468 (gnus-set-global-variables)
11469 (setq gnus-show-mime
11470 (if (null arg) (not gnus-show-mime)
11471 (> (prefix-numeric-value arg) 0)))
11472 (gnus-summary-select-article t 'force))
11473
11474 (defun gnus-summary-caesar-message (&optional arg)
11475 "Caesar rotate the current article by 13.
11476 The numerical prefix specifies how manu places to rotate each letter
11477 forward."
11478 (interactive "P")
11479 (gnus-set-global-variables)
11480 (gnus-summary-select-article)
11481 (let ((mail-header-separator ""))
11482 (gnus-eval-in-buffer-window gnus-article-buffer
11483 (save-restriction
11484 (widen)
11485 (let ((start (window-start))
11486 buffer-read-only)
11487 (message-caesar-buffer-body arg)
11488 (set-window-start (get-buffer-window (current-buffer)) start))))))
11489
11490 (defun gnus-summary-stop-page-breaking ()
11491 "Stop page breaking in the current article."
11492 (interactive)
11493 (gnus-set-global-variables)
11494 (gnus-summary-select-article)
11495 (gnus-eval-in-buffer-window gnus-article-buffer
11496 (widen)))
11497
11498 (defun gnus-summary-move-article (&optional n to-newsgroup select-method action)
11499 "Move the current article to a different newsgroup.
11500 If N is a positive number, move the N next articles.
11501 If N is a negative number, move the N previous articles.
11502 If N is nil and any articles have been marked with the process mark,
11503 move those articles instead.
11504 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
11505 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
11506 re-spool using this method.
11507
11508 For this function to work, both the current newsgroup and the
11509 newsgroup that you want to move to have to support the `request-move'
11510 and `request-accept' functions."
11511 (interactive "P")
11512 (unless action (setq action 'move))
11513 (gnus-set-global-variables)
11514 ;; Check whether the source group supports the required functions.
11515 (cond ((and (eq action 'move)
11516 (not (gnus-check-backend-function
11517 'request-move-article gnus-newsgroup-name)))
11518 (error "The current group does not support article moving"))
11519 ((and (eq action 'crosspost)
11520 (not (gnus-check-backend-function
11521 'request-replace-article gnus-newsgroup-name)))
11522 (error "The current group does not support article editing")))
11523 (let ((articles (gnus-summary-work-articles n))
11524 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
11525 (names '((move "Move" "Moving")
11526 (copy "Copy" "Copying")
11527 (crosspost "Crosspost" "Crossposting")))
11528 (copy-buf (save-excursion
11529 (nnheader-set-temp-buffer " *copy article*")))
11530 art-group to-method new-xref article to-groups)
11531 (unless (assq action names)
11532 (error "Unknown action %s" action))
11533 ;; Read the newsgroup name.
11534 (when (and (not to-newsgroup)
11535 (not select-method))
11536 (setq to-newsgroup
11537 (gnus-read-move-group-name
11538 (cadr (assq action names))
11539 (symbol-value (intern (format "gnus-current-%s-group" action)))
11540 articles prefix))
11541 (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
11542 (setq to-method (or select-method
11543 (gnus-group-name-to-method to-newsgroup)))
11544 ;; Check the method we are to move this article to...
11545 (or (gnus-check-backend-function 'request-accept-article (car to-method))
11546 (error "%s does not support article copying" (car to-method)))
11547 (or (gnus-check-server to-method)
11548 (error "Can't open server %s" (car to-method)))
11549 (gnus-message 6 "%s to %s: %s..."
11550 (caddr (assq action names))
11551 (or (car select-method) to-newsgroup) articles)
11552 (while articles
11553 (setq article (pop articles))
11554 (setq
11555 art-group
11556 (cond
11557 ;; Move the article.
11558 ((eq action 'move)
11559 (gnus-request-move-article
11560 article ; Article to move
11561 gnus-newsgroup-name ; From newsgrouo
11562 (nth 1 (gnus-find-method-for-group
11563 gnus-newsgroup-name)) ; Server
11564 (list 'gnus-request-accept-article
11565 to-newsgroup (list 'quote select-method)
11566 (not articles)) ; Accept form
11567 (not articles))) ; Only save nov last time
11568 ;; Copy the article.
11569 ((eq action 'copy)
11570 (save-excursion
11571 (set-buffer copy-buf)
11572 (gnus-request-article-this-buffer article gnus-newsgroup-name)
11573 (gnus-request-accept-article
11574 to-newsgroup select-method (not articles))))
11575 ;; Crosspost the article.
11576 ((eq action 'crosspost)
11577 (let ((xref (mail-header-xref (gnus-summary-article-header article))))
11578 (setq new-xref (concat gnus-newsgroup-name ":" article))
11579 (if (and xref (not (string= xref "")))
11580 (progn
11581 (when (string-match "^Xref: " xref)
11582 (setq xref (substring xref (match-end 0))))
11583 (setq new-xref (concat xref " " new-xref)))
11584 (setq new-xref (concat (system-name) " " new-xref)))
11585 (save-excursion
11586 (set-buffer copy-buf)
11587 (gnus-request-article-this-buffer article gnus-newsgroup-name)
11588 (nnheader-replace-header "xref" new-xref)
11589 (gnus-request-accept-article
11590 to-newsgroup select-method (not articles)))))))
11591 (if (not art-group)
11592 (gnus-message 1 "Couldn't %s article %s"
11593 (cadr (assq action names)) article)
11594 (let* ((entry
11595 (or
11596 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
11597 (gnus-gethash
11598 (gnus-group-prefixed-name
11599 (car art-group)
11600 (or select-method
11601 (gnus-find-method-for-group to-newsgroup)))
11602 gnus-newsrc-hashtb)))
11603 (info (nth 2 entry))
11604 (to-group (gnus-info-group info)))
11605 ;; Update the group that has been moved to.
11606 (when (and info
11607 (memq action '(move copy)))
11608 (unless (member to-group to-groups)
11609 (push to-group to-groups))
11610
11611 (unless (memq article gnus-newsgroup-unreads)
11612 (gnus-info-set-read
11613 info (gnus-add-to-range (gnus-info-read info)
11614 (list (cdr art-group)))))
11615
11616 ;; Copy any marks over to the new group.
11617 (let ((marks gnus-article-mark-lists)
11618 (to-article (cdr art-group)))
11619
11620 ;; See whether the article is to be put in the cache.
11621 (when gnus-use-cache
11622 (gnus-cache-possibly-enter-article
11623 to-group to-article
11624 (let ((header (copy-sequence
11625 (gnus-summary-article-header article))))
11626 (mail-header-set-number header to-article)
11627 header)
11628 (memq article gnus-newsgroup-marked)
11629 (memq article gnus-newsgroup-dormant)
11630 (memq article gnus-newsgroup-unreads)))
11631
11632 (while marks
11633 (when (memq article (symbol-value
11634 (intern (format "gnus-newsgroup-%s"
11635 (caar marks)))))
11636 ;; If the other group is the same as this group,
11637 ;; then we have to add the mark to the list.
11638 (when (equal to-group gnus-newsgroup-name)
11639 (set (intern (format "gnus-newsgroup-%s" (caar marks)))
11640 (cons to-article
11641 (symbol-value
11642 (intern (format "gnus-newsgroup-%s"
11643 (caar marks)))))))
11644 ;; Copy mark to other group.
11645 (gnus-add-marked-articles
11646 to-group (cdar marks) (list to-article) info))
11647 (setq marks (cdr marks)))))
11648
11649 ;; Update the Xref header in this article to point to
11650 ;; the new crossposted article we have just created.
11651 (when (eq action 'crosspost)
11652 (save-excursion
11653 (set-buffer copy-buf)
11654 (gnus-request-article-this-buffer article gnus-newsgroup-name)
11655 (nnheader-replace-header
11656 "xref" (concat new-xref " " (gnus-group-prefixed-name
11657 (car art-group) to-method)
11658 ":" (cdr art-group)))
11659 (gnus-request-replace-article
11660 article gnus-newsgroup-name (current-buffer)))))
11661
11662 (gnus-summary-goto-subject article)
11663 (when (eq action 'move)
11664 (gnus-summary-mark-article article gnus-canceled-mark)))
11665 (gnus-summary-remove-process-mark article))
11666 ;; Re-activate all groups that have been moved to.
11667 (while to-groups
11668 (gnus-activate-group (pop to-groups)))
11669
11670 (gnus-kill-buffer copy-buf)
11671 (gnus-summary-position-point)
11672 (gnus-set-mode-line 'summary)))
11673
11674 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
11675 "Move the current article to a different newsgroup.
11676 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
11677 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
11678 re-spool using this method."
11679 (interactive "P")
11680 (gnus-summary-move-article n nil select-method 'copy))
11681
11682 (defun gnus-summary-crosspost-article (&optional n)
11683 "Crosspost the current article to some other group."
11684 (interactive "P")
11685 (gnus-summary-move-article n nil nil 'crosspost))
11686
11687 (defvar gnus-summary-respool-default-method nil
11688 "Default method for respooling an article.
11689 If nil, use to the current newsgroup method.")
11690
11691 (defun gnus-summary-respool-article (&optional n method)
11692 "Respool the current article.
11693 The article will be squeezed through the mail spooling process again,
11694 which means that it will be put in some mail newsgroup or other
11695 depending on `nnmail-split-methods'.
11696 If N is a positive number, respool the N next articles.
11697 If N is a negative number, respool the N previous articles.
11698 If N is nil and any articles have been marked with the process mark,
11699 respool those articles instead.
11700
11701 Respooling can be done both from mail groups and \"real\" newsgroups.
11702 In the former case, the articles in question will be moved from the
11703 current group into whatever groups they are destined to. In the
11704 latter case, they will be copied into the relevant groups."
11705 (interactive
11706 (list current-prefix-arg
11707 (let* ((methods (gnus-methods-using 'respool))
11708 (methname
11709 (symbol-name (or gnus-summary-respool-default-method
11710 (car (gnus-find-method-for-group
11711 gnus-newsgroup-name)))))
11712 (method
11713 (gnus-completing-read
11714 methname "What backend do you want to use when respooling?"
11715 methods nil t nil 'gnus-method-history))
11716 ms)
11717 (cond
11718 ((zerop (length (setq ms (gnus-servers-using-backend method))))
11719 (list (intern method) ""))
11720 ((= 1 (length ms))
11721 (car ms))
11722 (t
11723 (cdr (completing-read
11724 "Server name: "
11725 (mapcar (lambda (m) (cons (cadr m) m)) ms) nil t)))))))
11726 (gnus-set-global-variables)
11727 (unless method
11728 (error "No method given for respooling"))
11729 (if (assoc (symbol-name
11730 (car (gnus-find-method-for-group gnus-newsgroup-name)))
11731 (gnus-methods-using 'respool))
11732 (gnus-summary-move-article n nil method)
11733 (gnus-summary-copy-article n nil method)))
11734
11735 (defun gnus-summary-import-article (file)
11736 "Import a random file into a mail newsgroup."
11737 (interactive "fImport file: ")
11738 (gnus-set-global-variables)
11739 (let ((group gnus-newsgroup-name)
11740 (now (current-time))
11741 atts lines)
11742 (or (gnus-check-backend-function 'request-accept-article group)
11743 (error "%s does not support article importing" group))
11744 (or (file-readable-p file)
11745 (not (file-regular-p file))
11746 (error "Can't read %s" file))
11747 (save-excursion
11748 (set-buffer (get-buffer-create " *import file*"))
11749 (buffer-disable-undo (current-buffer))
11750 (erase-buffer)
11751 (insert-file-contents file)
11752 (goto-char (point-min))
11753 (unless (nnheader-article-p)
11754 ;; This doesn't look like an article, so we fudge some headers.
11755 (setq atts (file-attributes file)
11756 lines (count-lines (point-min) (point-max)))
11757 (insert "From: " (read-string "From: ") "\n"
11758 "Subject: " (read-string "Subject: ") "\n"
11759 "Date: " (timezone-make-date-arpa-standard
11760 (current-time-string (nth 5 atts))
11761 (current-time-zone now)
11762 (current-time-zone now)) "\n"
11763 "Message-ID: " (message-make-message-id) "\n"
11764 "Lines: " (int-to-string lines) "\n"
11765 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
11766 (gnus-request-accept-article group nil t)
11767 (kill-buffer (current-buffer)))))
11768
11769 (defun gnus-summary-expire-articles (&optional now)
11770 "Expire all articles that are marked as expirable in the current group."
11771 (interactive)
11772 (gnus-set-global-variables)
11773 (when (gnus-check-backend-function
11774 'request-expire-articles gnus-newsgroup-name)
11775 ;; This backend supports expiry.
11776 (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
11777 (expirable (if total
11778 (gnus-list-of-read-articles gnus-newsgroup-name)
11779 (setq gnus-newsgroup-expirable
11780 (sort gnus-newsgroup-expirable '<))))
11781 (expiry-wait (if now 'immediate
11782 (gnus-group-get-parameter
11783 gnus-newsgroup-name 'expiry-wait)))
11784 es)
11785 (when expirable
11786 ;; There are expirable articles in this group, so we run them
11787 ;; through the expiry process.
11788 (gnus-message 6 "Expiring articles...")
11789 ;; The list of articles that weren't expired is returned.
11790 (if expiry-wait
11791 (let ((nnmail-expiry-wait-function nil)
11792 (nnmail-expiry-wait expiry-wait))
11793 (setq es (gnus-request-expire-articles
11794 expirable gnus-newsgroup-name)))
11795 (setq es (gnus-request-expire-articles
11796 expirable gnus-newsgroup-name)))
11797 (or total (setq gnus-newsgroup-expirable es))
11798 ;; We go through the old list of expirable, and mark all
11799 ;; really expired articles as nonexistent.
11800 (unless (eq es expirable) ;If nothing was expired, we don't mark.
11801 (let ((gnus-use-cache nil))
11802 (while expirable
11803 (unless (memq (car expirable) es)
11804 (when (gnus-data-find (car expirable))
11805 (gnus-summary-mark-article
11806 (car expirable) gnus-canceled-mark)))
11807 (setq expirable (cdr expirable)))))
11808 (gnus-message 6 "Expiring articles...done")))))
11809
11810 (defun gnus-summary-expire-articles-now ()
11811 "Expunge all expirable articles in the current group.
11812 This means that *all* articles that are marked as expirable will be
11813 deleted forever, right now."
11814 (interactive)
11815 (gnus-set-global-variables)
11816 (or gnus-expert-user
11817 (gnus-y-or-n-p
11818 "Are you really, really, really sure you want to delete all these messages? ")
11819 (error "Phew!"))
11820 (gnus-summary-expire-articles t))
11821
11822 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
11823 (defun gnus-summary-delete-article (&optional n)
11824 "Delete the N next (mail) articles.
11825 This command actually deletes articles. This is not a marking
11826 command. The article will disappear forever from your life, never to
11827 return.
11828 If N is negative, delete backwards.
11829 If N is nil and articles have been marked with the process mark,
11830 delete these instead."
11831 (interactive "P")
11832 (gnus-set-global-variables)
11833 (or (gnus-check-backend-function 'request-expire-articles
11834 gnus-newsgroup-name)
11835 (error "The current newsgroup does not support article deletion."))
11836 ;; Compute the list of articles to delete.
11837 (let ((articles (gnus-summary-work-articles n))
11838 not-deleted)
11839 (if (and gnus-novice-user
11840 (not (gnus-y-or-n-p
11841 (format "Do you really want to delete %s forever? "
11842 (if (> (length articles) 1)
11843 (format "these %s articles" (length articles))
11844 "this article")))))
11845 ()
11846 ;; Delete the articles.
11847 (setq not-deleted (gnus-request-expire-articles
11848 articles gnus-newsgroup-name 'force))
11849 (while articles
11850 (gnus-summary-remove-process-mark (car articles))
11851 ;; The backend might not have been able to delete the article
11852 ;; after all.
11853 (or (memq (car articles) not-deleted)
11854 (gnus-summary-mark-article (car articles) gnus-canceled-mark))
11855 (setq articles (cdr articles))))
11856 (gnus-summary-position-point)
11857 (gnus-set-mode-line 'summary)
11858 not-deleted))
11859
11860 (defun gnus-summary-edit-article (&optional force)
11861 "Enter into a buffer and edit the current article.
11862 This will have permanent effect only in mail groups.
11863 If FORCE is non-nil, allow editing of articles even in read-only
11864 groups."
11865 (interactive "P")
11866 (save-excursion
11867 (set-buffer gnus-summary-buffer)
11868 (gnus-set-global-variables)
11869 (when (and (not force)
11870 (gnus-group-read-only-p))
11871 (error "The current newsgroup does not support article editing."))
11872 (gnus-summary-select-article t nil t)
11873 (gnus-configure-windows 'article)
11874 (select-window (get-buffer-window gnus-article-buffer))
11875 (gnus-message 6 "C-c C-c to end edits")
11876 (setq buffer-read-only nil)
11877 (text-mode)
11878 (use-local-map (copy-keymap (current-local-map)))
11879 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
11880 (buffer-enable-undo)
11881 (widen)
11882 (goto-char (point-min))
11883 (search-forward "\n\n" nil t)))
11884
11885 (defun gnus-summary-edit-article-done ()
11886 "Make edits to the current article permanent."
11887 (interactive)
11888 (if (gnus-group-read-only-p)
11889 (progn
11890 (let ((beep (not (eq major-mode 'text-mode))))
11891 (gnus-summary-edit-article-postpone)
11892 (when beep
11893 (gnus-error
11894 3 "The current newsgroup does not support article editing."))))
11895 (let ((buf (format "%s" (buffer-string))))
11896 (erase-buffer)
11897 (insert buf)
11898 (if (not (gnus-request-replace-article
11899 (cdr gnus-article-current) (car gnus-article-current)
11900 (current-buffer)))
11901 (error "Couldn't replace article.")
11902 (gnus-article-mode)
11903 (use-local-map gnus-article-mode-map)
11904 (setq buffer-read-only t)
11905 (buffer-disable-undo (current-buffer))
11906 (gnus-configure-windows 'summary)
11907 (gnus-summary-update-article (cdr gnus-article-current))
11908 (when gnus-use-cache
11909 (gnus-cache-update-article
11910 (car gnus-article-current) (cdr gnus-article-current)))
11911 (when gnus-keep-backlog
11912 (gnus-backlog-remove-article
11913 (car gnus-article-current) (cdr gnus-article-current))))
11914 (save-excursion
11915 (when (get-buffer gnus-original-article-buffer)
11916 (set-buffer gnus-original-article-buffer)
11917 (setq gnus-original-article nil)))
11918 (setq gnus-article-current nil
11919 gnus-current-article nil)
11920 (run-hooks 'gnus-article-display-hook)
11921 (and (gnus-visual-p 'summary-highlight 'highlight)
11922 (run-hooks 'gnus-visual-mark-article-hook)))))
11923
11924 (defun gnus-summary-edit-article-postpone ()
11925 "Postpone changes to the current article."
11926 (interactive)
11927 (gnus-article-mode)
11928 (use-local-map gnus-article-mode-map)
11929 (setq buffer-read-only t)
11930 (buffer-disable-undo (current-buffer))
11931 (gnus-configure-windows 'summary)
11932 (and (gnus-visual-p 'summary-highlight 'highlight)
11933 (run-hooks 'gnus-visual-mark-article-hook)))
11934
11935 (defun gnus-summary-respool-query ()
11936 "Query where the respool algorithm would put this article."
11937 (interactive)
11938 (gnus-set-global-variables)
11939 (gnus-summary-select-article)
11940 (save-excursion
11941 (set-buffer gnus-article-buffer)
11942 (save-restriction
11943 (goto-char (point-min))
11944 (search-forward "\n\n")
11945 (narrow-to-region (point-min) (point))
11946 (pp-eval-expression
11947 (list 'quote (mapcar 'car (nnmail-article-group 'identity)))))))
11948
11949 ;; Summary marking commands.
11950
11951 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
11952 "Mark articles which has the same subject as read, and then select the next.
11953 If UNMARK is positive, remove any kind of mark.
11954 If UNMARK is negative, tick articles."
11955 (interactive "P")
11956 (gnus-set-global-variables)
11957 (if unmark
11958 (setq unmark (prefix-numeric-value unmark)))
11959 (let ((count
11960 (gnus-summary-mark-same-subject
11961 (gnus-summary-article-subject) unmark)))
11962 ;; Select next unread article. If auto-select-same mode, should
11963 ;; select the first unread article.
11964 (gnus-summary-next-article t (and gnus-auto-select-same
11965 (gnus-summary-article-subject)))
11966 (gnus-message 7 "%d article%s marked as %s"
11967 count (if (= count 1) " is" "s are")
11968 (if unmark "unread" "read"))))
11969
11970 (defun gnus-summary-kill-same-subject (&optional unmark)
11971 "Mark articles which has the same subject as read.
11972 If UNMARK is positive, remove any kind of mark.
11973 If UNMARK is negative, tick articles."
11974 (interactive "P")
11975 (gnus-set-global-variables)
11976 (if unmark
11977 (setq unmark (prefix-numeric-value unmark)))
11978 (let ((count
11979 (gnus-summary-mark-same-subject
11980 (gnus-summary-article-subject) unmark)))
11981 ;; If marked as read, go to next unread subject.
11982 (if (null unmark)
11983 ;; Go to next unread subject.
11984 (gnus-summary-next-subject 1 t))
11985 (gnus-message 7 "%d articles are marked as %s"
11986 count (if unmark "unread" "read"))))
11987
11988 (defun gnus-summary-mark-same-subject (subject &optional unmark)
11989 "Mark articles with same SUBJECT as read, and return marked number.
11990 If optional argument UNMARK is positive, remove any kinds of marks.
11991 If optional argument UNMARK is negative, mark articles as unread instead."
11992 (let ((count 1))
11993 (save-excursion
11994 (cond
11995 ((null unmark) ; Mark as read.
11996 (while (and
11997 (progn
11998 (gnus-summary-mark-article-as-read gnus-killed-mark)
11999 (gnus-summary-show-thread) t)
12000 (gnus-summary-find-subject subject))
12001 (setq count (1+ count))))
12002 ((> unmark 0) ; Tick.
12003 (while (and
12004 (progn
12005 (gnus-summary-mark-article-as-unread gnus-ticked-mark)
12006 (gnus-summary-show-thread) t)
12007 (gnus-summary-find-subject subject))
12008 (setq count (1+ count))))
12009 (t ; Mark as unread.
12010 (while (and
12011 (progn
12012 (gnus-summary-mark-article-as-unread gnus-unread-mark)
12013 (gnus-summary-show-thread) t)
12014 (gnus-summary-find-subject subject))
12015 (setq count (1+ count)))))
12016 (gnus-set-mode-line 'summary)
12017 ;; Return the number of marked articles.
12018 count)))
12019
12020 (defun gnus-summary-mark-as-processable (n &optional unmark)
12021 "Set the process mark on the next N articles.
12022 If N is negative, mark backward instead. If UNMARK is non-nil, remove
12023 the process mark instead. The difference between N and the actual
12024 number of articles marked is returned."
12025 (interactive "p")
12026 (gnus-set-global-variables)
12027 (let ((backward (< n 0))
12028 (n (abs n)))
12029 (while (and
12030 (> n 0)
12031 (if unmark
12032 (gnus-summary-remove-process-mark
12033 (gnus-summary-article-number))
12034 (gnus-summary-set-process-mark (gnus-summary-article-number)))
12035 (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
12036 (setq n (1- n)))
12037 (if (/= 0 n) (gnus-message 7 "No more articles"))
12038 (gnus-summary-recenter)
12039 (gnus-summary-position-point)
12040 n))
12041
12042 (defun gnus-summary-unmark-as-processable (n)
12043 "Remove the process mark from the next N articles.
12044 If N is negative, mark backward instead. The difference between N and
12045 the actual number of articles marked is returned."
12046 (interactive "p")
12047 (gnus-set-global-variables)
12048 (gnus-summary-mark-as-processable n t))
12049
12050 (defun gnus-summary-unmark-all-processable ()
12051 "Remove the process mark from all articles."
12052 (interactive)
12053 (gnus-set-global-variables)
12054 (save-excursion
12055 (while gnus-newsgroup-processable
12056 (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
12057 (gnus-summary-position-point))
12058
12059 (defun gnus-summary-mark-as-expirable (n)
12060 "Mark N articles forward as expirable.
12061 If N is negative, mark backward instead. The difference between N and
12062 the actual number of articles marked is returned."
12063 (interactive "p")
12064 (gnus-set-global-variables)
12065 (gnus-summary-mark-forward n gnus-expirable-mark))
12066
12067 (defun gnus-summary-mark-article-as-replied (article)
12068 "Mark ARTICLE replied and update the summary line."
12069 (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
12070 (let ((buffer-read-only nil))
12071 (when (gnus-summary-goto-subject article)
12072 (gnus-summary-update-secondary-mark article))))
12073
12074 (defun gnus-summary-set-bookmark (article)
12075 "Set a bookmark in current article."
12076 (interactive (list (gnus-summary-article-number)))
12077 (gnus-set-global-variables)
12078 (if (or (not (get-buffer gnus-article-buffer))
12079 (not gnus-current-article)
12080 (not gnus-article-current)
12081 (not (equal gnus-newsgroup-name (car gnus-article-current))))
12082 (error "No current article selected"))
12083 ;; Remove old bookmark, if one exists.
12084 (let ((old (assq article gnus-newsgroup-bookmarks)))
12085 (if old (setq gnus-newsgroup-bookmarks
12086 (delq old gnus-newsgroup-bookmarks))))
12087 ;; Set the new bookmark, which is on the form
12088 ;; (article-number . line-number-in-body).
12089 (setq gnus-newsgroup-bookmarks
12090 (cons
12091 (cons article
12092 (save-excursion
12093 (set-buffer gnus-article-buffer)
12094 (count-lines
12095 (min (point)
12096 (save-excursion
12097 (goto-char (point-min))
12098 (search-forward "\n\n" nil t)
12099 (point)))
12100 (point))))
12101 gnus-newsgroup-bookmarks))
12102 (gnus-message 6 "A bookmark has been added to the current article."))
12103
12104 (defun gnus-summary-remove-bookmark (article)
12105 "Remove the bookmark from the current article."
12106 (interactive (list (gnus-summary-article-number)))
12107 (gnus-set-global-variables)
12108 ;; Remove old bookmark, if one exists.
12109 (let ((old (assq article gnus-newsgroup-bookmarks)))
12110 (if old
12111 (progn
12112 (setq gnus-newsgroup-bookmarks
12113 (delq old gnus-newsgroup-bookmarks))
12114 (gnus-message 6 "Removed bookmark."))
12115 (gnus-message 6 "No bookmark in current article."))))
12116
12117 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
12118 (defun gnus-summary-mark-as-dormant (n)
12119 "Mark N articles forward as dormant.
12120 If N is negative, mark backward instead. The difference between N and
12121 the actual number of articles marked is returned."
12122 (interactive "p")
12123 (gnus-set-global-variables)
12124 (gnus-summary-mark-forward n gnus-dormant-mark))
12125
12126 (defun gnus-summary-set-process-mark (article)
12127 "Set the process mark on ARTICLE and update the summary line."
12128 (setq gnus-newsgroup-processable
12129 (cons article
12130 (delq article gnus-newsgroup-processable)))
12131 (when (gnus-summary-goto-subject article)
12132 (gnus-summary-show-thread)
12133 (gnus-summary-update-secondary-mark article)))
12134
12135 (defun gnus-summary-remove-process-mark (article)
12136 "Remove the process mark from ARTICLE and update the summary line."
12137 (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
12138 (when (gnus-summary-goto-subject article)
12139 (gnus-summary-show-thread)
12140 (gnus-summary-update-secondary-mark article)))
12141
12142 (defun gnus-summary-set-saved-mark (article)
12143 "Set the process mark on ARTICLE and update the summary line."
12144 (push article gnus-newsgroup-saved)
12145 (when (gnus-summary-goto-subject article)
12146 (gnus-summary-update-secondary-mark article)))
12147
12148 (defun gnus-summary-mark-forward (n &optional mark no-expire)
12149 "Mark N articles as read forwards.
12150 If N is negative, mark backwards instead. Mark with MARK, ?r by default.
12151 The difference between N and the actual number of articles marked is
12152 returned."
12153 (interactive "p")
12154 (gnus-set-global-variables)
12155 (let ((backward (< n 0))
12156 (gnus-summary-goto-unread
12157 (and gnus-summary-goto-unread
12158 (not (eq gnus-summary-goto-unread 'never))
12159 (not (memq mark (list gnus-unread-mark
12160 gnus-ticked-mark gnus-dormant-mark)))))
12161 (n (abs n))
12162 (mark (or mark gnus-del-mark)))
12163 (while (and (> n 0)
12164 (gnus-summary-mark-article nil mark no-expire)
12165 (zerop (gnus-summary-next-subject
12166 (if backward -1 1)
12167 (and gnus-summary-goto-unread
12168 (not (eq gnus-summary-goto-unread 'never)))
12169 t)))
12170 (setq n (1- n)))
12171 (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12172 (gnus-summary-recenter)
12173 (gnus-summary-position-point)
12174 (gnus-set-mode-line 'summary)
12175 n))
12176
12177 (defun gnus-summary-mark-article-as-read (mark)
12178 "Mark the current article quickly as read with MARK."
12179 (let ((article (gnus-summary-article-number)))
12180 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
12181 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
12182 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
12183 (setq gnus-newsgroup-reads
12184 (cons (cons article mark) gnus-newsgroup-reads))
12185 ;; Possibly remove from cache, if that is used.
12186 (and gnus-use-cache (gnus-cache-enter-remove-article article))
12187 ;; Allow the backend to change the mark.
12188 (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
12189 ;; Check for auto-expiry.
12190 (when (and gnus-newsgroup-auto-expire
12191 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
12192 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
12193 (= mark gnus-ancient-mark)
12194 (= mark gnus-read-mark) (= mark gnus-souped-mark)))
12195 (setq mark gnus-expirable-mark)
12196 (push article gnus-newsgroup-expirable))
12197 ;; Set the mark in the buffer.
12198 (gnus-summary-update-mark mark 'unread)
12199 t))
12200
12201 (defun gnus-summary-mark-article-as-unread (mark)
12202 "Mark the current article quickly as unread with MARK."
12203 (let ((article (gnus-summary-article-number)))
12204 (if (< article 0)
12205 (gnus-error 1 "Unmarkable article")
12206 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
12207 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
12208 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
12209 (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
12210 (cond ((= mark gnus-ticked-mark)
12211 (push article gnus-newsgroup-marked))
12212 ((= mark gnus-dormant-mark)
12213 (push article gnus-newsgroup-dormant))
12214 (t
12215 (push article gnus-newsgroup-unreads)))
12216 (setq gnus-newsgroup-reads
12217 (delq (assq article gnus-newsgroup-reads)
12218 gnus-newsgroup-reads))
12219
12220 ;; See whether the article is to be put in the cache.
12221 (and gnus-use-cache
12222 (vectorp (gnus-summary-article-header article))
12223 (save-excursion
12224 (gnus-cache-possibly-enter-article
12225 gnus-newsgroup-name article
12226 (gnus-summary-article-header article)
12227 (= mark gnus-ticked-mark)
12228 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
12229
12230 ;; Fix the mark.
12231 (gnus-summary-update-mark mark 'unread))
12232 t))
12233
12234 (defun gnus-summary-mark-article (&optional article mark no-expire)
12235 "Mark ARTICLE with MARK. MARK can be any character.
12236 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
12237 `??' (dormant) and `?E' (expirable).
12238 If MARK is nil, then the default character `?D' is used.
12239 If ARTICLE is nil, then the article on the current line will be
12240 marked."
12241 ;; The mark might be a string.
12242 (and (stringp mark)
12243 (setq mark (aref mark 0)))
12244 ;; If no mark is given, then we check auto-expiring.
12245 (and (not no-expire)
12246 gnus-newsgroup-auto-expire
12247 (or (not mark)
12248 (and (numberp mark)
12249 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
12250 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
12251 (= mark gnus-read-mark) (= mark gnus-souped-mark))))
12252 (setq mark gnus-expirable-mark))
12253 (let* ((mark (or mark gnus-del-mark))
12254 (article (or article (gnus-summary-article-number))))
12255 (or article (error "No article on current line"))
12256 (if (or (= mark gnus-unread-mark)
12257 (= mark gnus-ticked-mark)
12258 (= mark gnus-dormant-mark))
12259 (gnus-mark-article-as-unread article mark)
12260 (gnus-mark-article-as-read article mark))
12261
12262 ;; See whether the article is to be put in the cache.
12263 (and gnus-use-cache
12264 (not (= mark gnus-canceled-mark))
12265 (vectorp (gnus-summary-article-header article))
12266 (save-excursion
12267 (gnus-cache-possibly-enter-article
12268 gnus-newsgroup-name article
12269 (gnus-summary-article-header article)
12270 (= mark gnus-ticked-mark)
12271 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
12272
12273 (if (gnus-summary-goto-subject article nil t)
12274 (let ((buffer-read-only nil))
12275 (gnus-summary-show-thread)
12276 ;; Fix the mark.
12277 (gnus-summary-update-mark mark 'unread)
12278 t))))
12279
12280 (defun gnus-summary-update-secondary-mark (article)
12281 "Update the secondary (read, process, cache) mark."
12282 (gnus-summary-update-mark
12283 (cond ((memq article gnus-newsgroup-processable)
12284 gnus-process-mark)
12285 ((memq article gnus-newsgroup-cached)
12286 gnus-cached-mark)
12287 ((memq article gnus-newsgroup-replied)
12288 gnus-replied-mark)
12289 ((memq article gnus-newsgroup-saved)
12290 gnus-saved-mark)
12291 (t gnus-unread-mark))
12292 'replied)
12293 (when (gnus-visual-p 'summary-highlight 'highlight)
12294 (run-hooks 'gnus-summary-update-hook))
12295 t)
12296
12297 (defun gnus-summary-update-mark (mark type)
12298 (beginning-of-line)
12299 (let ((forward (cdr (assq type gnus-summary-mark-positions)))
12300 (buffer-read-only nil))
12301 (when (and forward
12302 (<= (+ forward (point)) (point-max)))
12303 ;; Go to the right position on the line.
12304 (goto-char (+ forward (point)))
12305 ;; Replace the old mark with the new mark.
12306 (subst-char-in-region (point) (1+ (point)) (following-char) mark)
12307 ;; Optionally update the marks by some user rule.
12308 (when (eq type 'unread)
12309 (gnus-data-set-mark
12310 (gnus-data-find (gnus-summary-article-number)) mark)
12311 (gnus-summary-update-line (eq mark gnus-unread-mark))))))
12312
12313 (defun gnus-mark-article-as-read (article &optional mark)
12314 "Enter ARTICLE in the pertinent lists and remove it from others."
12315 ;; Make the article expirable.
12316 (let ((mark (or mark gnus-del-mark)))
12317 (if (= mark gnus-expirable-mark)
12318 (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
12319 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
12320 ;; Remove from unread and marked lists.
12321 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
12322 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
12323 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
12324 (push (cons article mark) gnus-newsgroup-reads)
12325 ;; Possibly remove from cache, if that is used.
12326 (when gnus-use-cache
12327 (gnus-cache-enter-remove-article article))))
12328
12329 (defun gnus-mark-article-as-unread (article &optional mark)
12330 "Enter ARTICLE in the pertinent lists and remove it from others."
12331 (let ((mark (or mark gnus-ticked-mark)))
12332 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
12333 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
12334 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
12335 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
12336 (cond ((= mark gnus-ticked-mark)
12337 (push article gnus-newsgroup-marked))
12338 ((= mark gnus-dormant-mark)
12339 (push article gnus-newsgroup-dormant))
12340 (t
12341 (push article gnus-newsgroup-unreads)))
12342 (setq gnus-newsgroup-reads
12343 (delq (assq article gnus-newsgroup-reads)
12344 gnus-newsgroup-reads))))
12345
12346 (defalias 'gnus-summary-mark-as-unread-forward
12347 'gnus-summary-tick-article-forward)
12348 (make-obsolete 'gnus-summary-mark-as-unread-forward
12349 'gnus-summary-tick-article-forward)
12350 (defun gnus-summary-tick-article-forward (n)
12351 "Tick N articles forwards.
12352 If N is negative, tick backwards instead.
12353 The difference between N and the number of articles ticked is returned."
12354 (interactive "p")
12355 (gnus-summary-mark-forward n gnus-ticked-mark))
12356
12357 (defalias 'gnus-summary-mark-as-unread-backward
12358 'gnus-summary-tick-article-backward)
12359 (make-obsolete 'gnus-summary-mark-as-unread-backward
12360 'gnus-summary-tick-article-backward)
12361 (defun gnus-summary-tick-article-backward (n)
12362 "Tick N articles backwards.
12363 The difference between N and the number of articles ticked is returned."
12364 (interactive "p")
12365 (gnus-summary-mark-forward (- n) gnus-ticked-mark))
12366
12367 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
12368 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
12369 (defun gnus-summary-tick-article (&optional article clear-mark)
12370 "Mark current article as unread.
12371 Optional 1st argument ARTICLE specifies article number to be marked as unread.
12372 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
12373 (interactive)
12374 (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
12375 gnus-ticked-mark)))
12376
12377 (defun gnus-summary-mark-as-read-forward (n)
12378 "Mark N articles as read forwards.
12379 If N is negative, mark backwards instead.
12380 The difference between N and the actual number of articles marked is
12381 returned."
12382 (interactive "p")
12383 (gnus-summary-mark-forward n gnus-del-mark t))
12384
12385 (defun gnus-summary-mark-as-read-backward (n)
12386 "Mark the N articles as read backwards.
12387 The difference between N and the actual number of articles marked is
12388 returned."
12389 (interactive "p")
12390 (gnus-summary-mark-forward (- n) gnus-del-mark t))
12391
12392 (defun gnus-summary-mark-as-read (&optional article mark)
12393 "Mark current article as read.
12394 ARTICLE specifies the article to be marked as read.
12395 MARK specifies a string to be inserted at the beginning of the line."
12396 (gnus-summary-mark-article article mark))
12397
12398 (defun gnus-summary-clear-mark-forward (n)
12399 "Clear marks from N articles forward.
12400 If N is negative, clear backward instead.
12401 The difference between N and the number of marks cleared is returned."
12402 (interactive "p")
12403 (gnus-summary-mark-forward n gnus-unread-mark))
12404
12405 (defun gnus-summary-clear-mark-backward (n)
12406 "Clear marks from N articles backward.
12407 The difference between N and the number of marks cleared is returned."
12408 (interactive "p")
12409 (gnus-summary-mark-forward (- n) gnus-unread-mark))
12410
12411 (defun gnus-summary-mark-unread-as-read ()
12412 "Intended to be used by `gnus-summary-mark-article-hook'."
12413 (when (memq gnus-current-article gnus-newsgroup-unreads)
12414 (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
12415
12416 (defun gnus-summary-mark-read-and-unread-as-read ()
12417 "Intended to be used by `gnus-summary-mark-article-hook'."
12418 (let ((mark (gnus-summary-article-mark)))
12419 (when (or (gnus-unread-mark-p mark)
12420 (gnus-read-mark-p mark))
12421 (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
12422
12423 (defun gnus-summary-mark-region-as-read (point mark all)
12424 "Mark all unread articles between point and mark as read.
12425 If given a prefix, mark all articles between point and mark as read,
12426 even ticked and dormant ones."
12427 (interactive "r\nP")
12428 (save-excursion
12429 (let (article)
12430 (goto-char point)
12431 (beginning-of-line)
12432 (while (and
12433 (< (point) mark)
12434 (progn
12435 (when (or all
12436 (memq (setq article (gnus-summary-article-number))
12437 gnus-newsgroup-unreads))
12438 (gnus-summary-mark-article article gnus-del-mark))
12439 t)
12440 (gnus-summary-find-next))))))
12441
12442 (defun gnus-summary-mark-below (score mark)
12443 "Mark articles with score less than SCORE with MARK."
12444 (interactive "P\ncMark: ")
12445 (gnus-set-global-variables)
12446 (setq score (if score
12447 (prefix-numeric-value score)
12448 (or gnus-summary-default-score 0)))
12449 (save-excursion
12450 (set-buffer gnus-summary-buffer)
12451 (goto-char (point-min))
12452 (while
12453 (progn
12454 (and (< (gnus-summary-article-score) score)
12455 (gnus-summary-mark-article nil mark))
12456 (gnus-summary-find-next)))))
12457
12458 (defun gnus-summary-kill-below (&optional score)
12459 "Mark articles with score below SCORE as read."
12460 (interactive "P")
12461 (gnus-set-global-variables)
12462 (gnus-summary-mark-below score gnus-killed-mark))
12463
12464 (defun gnus-summary-clear-above (&optional score)
12465 "Clear all marks from articles with score above SCORE."
12466 (interactive "P")
12467 (gnus-set-global-variables)
12468 (gnus-summary-mark-above score gnus-unread-mark))
12469
12470 (defun gnus-summary-tick-above (&optional score)
12471 "Tick all articles with score above SCORE."
12472 (interactive "P")
12473 (gnus-set-global-variables)
12474 (gnus-summary-mark-above score gnus-ticked-mark))
12475
12476 (defun gnus-summary-mark-above (score mark)
12477 "Mark articles with score over SCORE with MARK."
12478 (interactive "P\ncMark: ")
12479 (gnus-set-global-variables)
12480 (setq score (if score
12481 (prefix-numeric-value score)
12482 (or gnus-summary-default-score 0)))
12483 (save-excursion
12484 (set-buffer gnus-summary-buffer)
12485 (goto-char (point-min))
12486 (while (and (progn
12487 (if (> (gnus-summary-article-score) score)
12488 (gnus-summary-mark-article nil mark))
12489 t)
12490 (gnus-summary-find-next)))))
12491
12492 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
12493 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
12494 (defun gnus-summary-limit-include-expunged ()
12495 "Display all the hidden articles that were expunged for low scores."
12496 (interactive)
12497 (gnus-set-global-variables)
12498 (let ((buffer-read-only nil))
12499 (let ((scored gnus-newsgroup-scored)
12500 headers h)
12501 (while scored
12502 (or (gnus-summary-goto-subject (caar scored))
12503 (and (setq h (gnus-summary-article-header (caar scored)))
12504 (< (cdar scored) gnus-summary-expunge-below)
12505 (setq headers (cons h headers))))
12506 (setq scored (cdr scored)))
12507 (or headers (error "No expunged articles hidden."))
12508 (goto-char (point-min))
12509 (gnus-summary-prepare-unthreaded (nreverse headers)))
12510 (goto-char (point-min))
12511 (gnus-summary-position-point)))
12512
12513 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
12514 "Mark all articles not marked as unread in this newsgroup as read.
12515 If prefix argument ALL is non-nil, all articles are marked as read.
12516 If QUIETLY is non-nil, no questions will be asked.
12517 If TO-HERE is non-nil, it should be a point in the buffer. All
12518 articles before this point will be marked as read.
12519 The number of articles marked as read is returned."
12520 (interactive "P")
12521 (gnus-set-global-variables)
12522 (prog1
12523 (if (or quietly
12524 (not gnus-interactive-catchup) ;Without confirmation?
12525 gnus-expert-user
12526 (gnus-y-or-n-p
12527 (if all
12528 "Mark absolutely all articles as read? "
12529 "Mark all unread articles as read? ")))
12530 (if (and not-mark
12531 (not gnus-newsgroup-adaptive)
12532 (not gnus-newsgroup-auto-expire))
12533 (progn
12534 (when all
12535 (setq gnus-newsgroup-marked nil
12536 gnus-newsgroup-dormant nil))
12537 (setq gnus-newsgroup-unreads nil))
12538 ;; We actually mark all articles as canceled, which we
12539 ;; have to do when using auto-expiry or adaptive scoring.
12540 (gnus-summary-show-all-threads)
12541 (if (gnus-summary-first-subject (not all))
12542 (while (and
12543 (if to-here (< (point) to-here) t)
12544 (gnus-summary-mark-article-as-read gnus-catchup-mark)
12545 (gnus-summary-find-next (not all)))))
12546 (unless to-here
12547 (setq gnus-newsgroup-unreads nil))
12548 (gnus-set-mode-line 'summary)))
12549 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
12550 (if (and (not to-here) (eq 'nnvirtual (car method)))
12551 (nnvirtual-catchup-group
12552 (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
12553 (gnus-summary-position-point)))
12554
12555 (defun gnus-summary-catchup-to-here (&optional all)
12556 "Mark all unticked articles before the current one as read.
12557 If ALL is non-nil, also mark ticked and dormant articles as read."
12558 (interactive "P")
12559 (gnus-set-global-variables)
12560 (save-excursion
12561 (gnus-save-hidden-threads
12562 (let ((beg (point)))
12563 ;; We check that there are unread articles.
12564 (when (or all (gnus-summary-find-prev))
12565 (gnus-summary-catchup all t beg)))))
12566 (gnus-summary-position-point))
12567
12568 (defun gnus-summary-catchup-all (&optional quietly)
12569 "Mark all articles in this newsgroup as read."
12570 (interactive "P")
12571 (gnus-set-global-variables)
12572 (gnus-summary-catchup t quietly))
12573
12574 (defun gnus-summary-catchup-and-exit (&optional all quietly)
12575 "Mark all articles not marked as unread in this newsgroup as read, then exit.
12576 If prefix argument ALL is non-nil, all articles are marked as read."
12577 (interactive "P")
12578 (gnus-set-global-variables)
12579 (gnus-summary-catchup all quietly nil 'fast)
12580 ;; Select next newsgroup or exit.
12581 (if (eq gnus-auto-select-next 'quietly)
12582 (gnus-summary-next-group nil)
12583 (gnus-summary-exit)))
12584
12585 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
12586 "Mark all articles in this newsgroup as read, and then exit."
12587 (interactive "P")
12588 (gnus-set-global-variables)
12589 (gnus-summary-catchup-and-exit t quietly))
12590
12591 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
12592 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
12593 "Mark all articles in this group as read and select the next group.
12594 If given a prefix, mark all articles, unread as well as ticked, as
12595 read."
12596 (interactive "P")
12597 (gnus-set-global-variables)
12598 (save-excursion
12599 (gnus-summary-catchup all))
12600 (gnus-summary-next-article t nil nil t))
12601
12602 ;; Thread-based commands.
12603
12604 (defun gnus-summary-articles-in-thread (&optional article)
12605 "Return a list of all articles in the current thread.
12606 If ARTICLE is non-nil, return all articles in the thread that starts
12607 with that article."
12608 (let* ((article (or article (gnus-summary-article-number)))
12609 (data (gnus-data-find-list article))
12610 (top-level (gnus-data-level (car data)))
12611 (top-subject
12612 (cond ((null gnus-thread-operation-ignore-subject)
12613 (gnus-simplify-subject-re
12614 (mail-header-subject (gnus-data-header (car data)))))
12615 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
12616 (gnus-simplify-subject-fuzzy
12617 (mail-header-subject (gnus-data-header (car data)))))
12618 (t nil)))
12619 (end-point (save-excursion
12620 (if (gnus-summary-go-to-next-thread)
12621 (point) (point-max))))
12622 articles)
12623 (while (and data
12624 (< (gnus-data-pos (car data)) end-point))
12625 (when (or (not top-subject)
12626 (string= top-subject
12627 (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
12628 (gnus-simplify-subject-fuzzy
12629 (mail-header-subject
12630 (gnus-data-header (car data))))
12631 (gnus-simplify-subject-re
12632 (mail-header-subject
12633 (gnus-data-header (car data)))))))
12634 (push (gnus-data-number (car data)) articles))
12635 (unless (and (setq data (cdr data))
12636 (> (gnus-data-level (car data)) top-level))
12637 (setq data nil)))
12638 ;; Return the list of articles.
12639 (nreverse articles)))
12640
12641 (defun gnus-summary-rethread-current ()
12642 "Rethread the thread the current article is part of."
12643 (interactive)
12644 (gnus-set-global-variables)
12645 (let* ((gnus-show-threads t)
12646 (article (gnus-summary-article-number))
12647 (id (mail-header-id (gnus-summary-article-header)))
12648 (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
12649 (unless id
12650 (error "No article on the current line"))
12651 (gnus-rebuild-thread id)
12652 (gnus-summary-goto-subject article)))
12653
12654 (defun gnus-summary-reparent-thread ()
12655 "Make current article child of the marked (or previous) article.
12656
12657 Note that the re-threading will only work if `gnus-thread-ignore-subject'
12658 is non-nil or the Subject: of both articles are the same."
12659 (interactive)
12660 (or (not (gnus-group-read-only-p))
12661 (error "The current newsgroup does not support article editing."))
12662 (or (<= (length gnus-newsgroup-processable) 1)
12663 (error "No more than one article may be marked."))
12664 (save-window-excursion
12665 (let ((gnus-article-buffer " *reparent*")
12666 (current-article (gnus-summary-article-number))
12667 ; first grab the marked article, otherwise one line up.
12668 (parent-article (if (not (null gnus-newsgroup-processable))
12669 (car gnus-newsgroup-processable)
12670 (save-excursion
12671 (if (eq (forward-line -1) 0)
12672 (gnus-summary-article-number)
12673 (error "Beginning of summary buffer."))))))
12674 (or (not (eq current-article parent-article))
12675 (error "An article may not be self-referential."))
12676 (let ((message-id (mail-header-id
12677 (gnus-summary-article-header parent-article))))
12678 (or (and message-id (not (equal message-id "")))
12679 (error "No message-id in desired parent."))
12680 (gnus-summary-select-article t t nil current-article)
12681 (set-buffer gnus-article-buffer)
12682 (setq buffer-read-only nil)
12683 (let ((buf (format "%s" (buffer-string))))
12684 (erase-buffer)
12685 (insert buf))
12686 (goto-char (point-min))
12687 (if (search-forward-regexp "^References: " nil t)
12688 (insert message-id " " )
12689 (insert "References: " message-id "\n"))
12690 (or (gnus-request-replace-article current-article
12691 (car gnus-article-current)
12692 gnus-article-buffer)
12693 (error "Couldn't replace article."))
12694 (set-buffer gnus-summary-buffer)
12695 (gnus-summary-unmark-all-processable)
12696 (gnus-summary-rethread-current)
12697 (gnus-message 3 "Article %d is now the child of article %d."
12698 current-article parent-article)))))
12699
12700 (defun gnus-summary-toggle-threads (&optional arg)
12701 "Toggle showing conversation threads.
12702 If ARG is positive number, turn showing conversation threads on."
12703 (interactive "P")
12704 (gnus-set-global-variables)
12705 (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
12706 (setq gnus-show-threads
12707 (if (null arg) (not gnus-show-threads)
12708 (> (prefix-numeric-value arg) 0)))
12709 (gnus-summary-prepare)
12710 (gnus-summary-goto-subject current)
12711 (gnus-summary-position-point)))
12712
12713 (defun gnus-summary-show-all-threads ()
12714 "Show all threads."
12715 (interactive)
12716 (gnus-set-global-variables)
12717 (save-excursion
12718 (let ((buffer-read-only nil))
12719 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
12720 (gnus-summary-position-point))
12721
12722 (defun gnus-summary-show-thread ()
12723 "Show thread subtrees.
12724 Returns nil if no thread was there to be shown."
12725 (interactive)
12726 (gnus-set-global-variables)
12727 (let ((buffer-read-only nil)
12728 (orig (point))
12729 ;; first goto end then to beg, to have point at beg after let
12730 (end (progn (end-of-line) (point)))
12731 (beg (progn (beginning-of-line) (point))))
12732 (prog1
12733 ;; Any hidden lines here?
12734 (search-forward "\r" end t)
12735 (subst-char-in-region beg end ?\^M ?\n t)
12736 (goto-char orig)
12737 (gnus-summary-position-point))))
12738
12739 (defun gnus-summary-hide-all-threads ()
12740 "Hide all thread subtrees."
12741 (interactive)
12742 (gnus-set-global-variables)
12743 (save-excursion
12744 (goto-char (point-min))
12745 (gnus-summary-hide-thread)
12746 (while (zerop (gnus-summary-next-thread 1 t))
12747 (gnus-summary-hide-thread)))
12748 (gnus-summary-position-point))
12749
12750 (defun gnus-summary-hide-thread ()
12751 "Hide thread subtrees.
12752 Returns nil if no threads were there to be hidden."
12753 (interactive)
12754 (gnus-set-global-variables)
12755 (let ((buffer-read-only nil)
12756 (start (point))
12757 (article (gnus-summary-article-number)))
12758 (goto-char start)
12759 ;; Go forward until either the buffer ends or the subthread
12760 ;; ends.
12761 (when (and (not (eobp))
12762 (or (zerop (gnus-summary-next-thread 1 t))
12763 (goto-char (point-max))))
12764 (prog1
12765 (if (and (> (point) start)
12766 (search-backward "\n" start t))
12767 (progn
12768 (subst-char-in-region start (point) ?\n ?\^M)
12769 (gnus-summary-goto-subject article))
12770 (goto-char start)
12771 nil)
12772 ;;(gnus-summary-position-point)
12773 ))))
12774
12775 (defun gnus-summary-go-to-next-thread (&optional previous)
12776 "Go to the same level (or less) next thread.
12777 If PREVIOUS is non-nil, go to previous thread instead.
12778 Return the article number moved to, or nil if moving was impossible."
12779 (let ((level (gnus-summary-thread-level))
12780 (way (if previous -1 1))
12781 (beg (point)))
12782 (forward-line way)
12783 (while (and (not (eobp))
12784 (< level (gnus-summary-thread-level)))
12785 (forward-line way))
12786 (if (eobp)
12787 (progn
12788 (goto-char beg)
12789 nil)
12790 (setq beg (point))
12791 (prog1
12792 (gnus-summary-article-number)
12793 (goto-char beg)))))
12794
12795 (defun gnus-summary-go-to-next-thread-old (&optional previous)
12796 "Go to the same level (or less) next thread.
12797 If PREVIOUS is non-nil, go to previous thread instead.
12798 Return the article number moved to, or nil if moving was impossible."
12799 (if (and (eq gnus-summary-make-false-root 'dummy)
12800 (gnus-summary-article-intangible-p))
12801 (let ((beg (point)))
12802 (while (and (zerop (forward-line 1))
12803 (not (gnus-summary-article-intangible-p))
12804 (not (zerop (save-excursion
12805 (gnus-summary-thread-level))))))
12806 (if (eobp)
12807 (progn
12808 (goto-char beg)
12809 nil)
12810 (point)))
12811 (let* ((level (gnus-summary-thread-level))
12812 (article (gnus-summary-article-number))
12813 (data (cdr (gnus-data-find-list article (gnus-data-list previous))))
12814 oart)
12815 (while data
12816 (if (<= (gnus-data-level (car data)) level)
12817 (setq oart (gnus-data-number (car data))
12818 data nil)
12819 (setq data (cdr data))))
12820 (and oart
12821 (gnus-summary-goto-subject oart)))))
12822
12823 (defun gnus-summary-next-thread (n &optional silent)
12824 "Go to the same level next N'th thread.
12825 If N is negative, search backward instead.
12826 Returns the difference between N and the number of skips actually
12827 done.
12828
12829 If SILENT, don't output messages."
12830 (interactive "p")
12831 (gnus-set-global-variables)
12832 (let ((backward (< n 0))
12833 (n (abs n))
12834 old dum int)
12835 (while (and (> n 0)
12836 (gnus-summary-go-to-next-thread backward))
12837 (decf n))
12838 (unless silent
12839 (gnus-summary-position-point))
12840 (when (and (not silent) (/= 0 n))
12841 (gnus-message 7 "No more threads"))
12842 n))
12843
12844 (defun gnus-summary-prev-thread (n)
12845 "Go to the same level previous N'th thread.
12846 Returns the difference between N and the number of skips actually
12847 done."
12848 (interactive "p")
12849 (gnus-set-global-variables)
12850 (gnus-summary-next-thread (- n)))
12851
12852 (defun gnus-summary-go-down-thread ()
12853 "Go down one level in the current thread."
12854 (let ((children (gnus-summary-article-children)))
12855 (and children
12856 (gnus-summary-goto-subject (car children)))))
12857
12858 (defun gnus-summary-go-up-thread ()
12859 "Go up one level in the current thread."
12860 (let ((parent (gnus-summary-article-parent)))
12861 (and parent
12862 (gnus-summary-goto-subject parent))))
12863
12864 (defun gnus-summary-down-thread (n)
12865 "Go down thread N steps.
12866 If N is negative, go up instead.
12867 Returns the difference between N and how many steps down that were
12868 taken."
12869 (interactive "p")
12870 (gnus-set-global-variables)
12871 (let ((up (< n 0))
12872 (n (abs n)))
12873 (while (and (> n 0)
12874 (if up (gnus-summary-go-up-thread)
12875 (gnus-summary-go-down-thread)))
12876 (setq n (1- n)))
12877 (gnus-summary-position-point)
12878 (if (/= 0 n) (gnus-message 7 "Can't go further"))
12879 n))
12880
12881 (defun gnus-summary-up-thread (n)
12882 "Go up thread N steps.
12883 If N is negative, go up instead.
12884 Returns the difference between N and how many steps down that were
12885 taken."
12886 (interactive "p")
12887 (gnus-set-global-variables)
12888 (gnus-summary-down-thread (- n)))
12889
12890 (defun gnus-summary-top-thread ()
12891 "Go to the top of the thread."
12892 (interactive)
12893 (gnus-set-global-variables)
12894 (while (gnus-summary-go-up-thread))
12895 (gnus-summary-article-number))
12896
12897 (defun gnus-summary-kill-thread (&optional unmark)
12898 "Mark articles under current thread as read.
12899 If the prefix argument is positive, remove any kinds of marks.
12900 If the prefix argument is negative, tick articles instead."
12901 (interactive "P")
12902 (gnus-set-global-variables)
12903 (when unmark
12904 (setq unmark (prefix-numeric-value unmark)))
12905 (let ((articles (gnus-summary-articles-in-thread)))
12906 (save-excursion
12907 ;; Expand the thread.
12908 (gnus-summary-show-thread)
12909 ;; Mark all the articles.
12910 (while articles
12911 (gnus-summary-goto-subject (car articles))
12912 (cond ((null unmark)
12913 (gnus-summary-mark-article-as-read gnus-killed-mark))
12914 ((> unmark 0)
12915 (gnus-summary-mark-article-as-unread gnus-unread-mark))
12916 (t
12917 (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
12918 (setq articles (cdr articles))))
12919 ;; Hide killed subtrees.
12920 (and (null unmark)
12921 gnus-thread-hide-killed
12922 (gnus-summary-hide-thread))
12923 ;; If marked as read, go to next unread subject.
12924 (if (null unmark)
12925 ;; Go to next unread subject.
12926 (gnus-summary-next-subject 1 t)))
12927 (gnus-set-mode-line 'summary))
12928
12929 ;; Summary sorting commands
12930
12931 (defun gnus-summary-sort-by-number (&optional reverse)
12932 "Sort summary buffer by article number.
12933 Argument REVERSE means reverse order."
12934 (interactive "P")
12935 (gnus-summary-sort 'number reverse))
12936
12937 (defun gnus-summary-sort-by-author (&optional reverse)
12938 "Sort summary buffer by author name alphabetically.
12939 If case-fold-search is non-nil, case of letters is ignored.
12940 Argument REVERSE means reverse order."
12941 (interactive "P")
12942 (gnus-summary-sort 'author reverse))
12943
12944 (defun gnus-summary-sort-by-subject (&optional reverse)
12945 "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
12946 If case-fold-search is non-nil, case of letters is ignored.
12947 Argument REVERSE means reverse order."
12948 (interactive "P")
12949 (gnus-summary-sort 'subject reverse))
12950
12951 (defun gnus-summary-sort-by-date (&optional reverse)
12952 "Sort summary buffer by date.
12953 Argument REVERSE means reverse order."
12954 (interactive "P")
12955 (gnus-summary-sort 'date reverse))
12956
12957 (defun gnus-summary-sort-by-score (&optional reverse)
12958 "Sort summary buffer by score.
12959 Argument REVERSE means reverse order."
12960 (interactive "P")
12961 (gnus-summary-sort 'score reverse))
12962
12963 (defun gnus-summary-sort (predicate reverse)
12964 "Sort summary buffer by PREDICATE. REVERSE means reverse order."
12965 (gnus-set-global-variables)
12966 (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
12967 (article (intern (format "gnus-article-sort-by-%s" predicate)))
12968 (gnus-thread-sort-functions
12969 (list
12970 (if (not reverse)
12971 thread
12972 `(lambda (t1 t2)
12973 (,thread t2 t1)))))
12974 (gnus-article-sort-functions
12975 (list
12976 (if (not reverse)
12977 article
12978 `(lambda (t1 t2)
12979 (,article t2 t1)))))
12980 (buffer-read-only)
12981 (gnus-summary-prepare-hook nil))
12982 ;; We do the sorting by regenerating the threads.
12983 (gnus-summary-prepare)
12984 ;; Hide subthreads if needed.
12985 (when (and gnus-show-threads gnus-thread-hide-subtree)
12986 (gnus-summary-hide-all-threads)))
12987 ;; If in async mode, we send some info to the backend.
12988 (when gnus-newsgroup-async
12989 (gnus-request-asynchronous
12990 gnus-newsgroup-name gnus-newsgroup-data)))
12991
12992 (defun gnus-sortable-date (date)
12993 "Make sortable string by string-lessp from DATE.
12994 Timezone package is used."
12995 (condition-case ()
12996 (progn
12997 (setq date (inline (timezone-fix-time
12998 date nil
12999 (aref (inline (timezone-parse-date date)) 4))))
13000 (inline
13001 (timezone-make-sortable-date
13002 (aref date 0) (aref date 1) (aref date 2)
13003 (inline
13004 (timezone-make-time-string
13005 (aref date 3) (aref date 4) (aref date 5))))))
13006 (error "")))
13007
13008 ;; Summary saving commands.
13009
13010 (defun gnus-summary-save-article (&optional n not-saved)
13011 "Save the current article using the default saver function.
13012 If N is a positive number, save the N next articles.
13013 If N is a negative number, save the N previous articles.
13014 If N is nil and any articles have been marked with the process mark,
13015 save those articles instead.
13016 The variable `gnus-default-article-saver' specifies the saver function."
13017 (interactive "P")
13018 (gnus-set-global-variables)
13019 (let ((articles (gnus-summary-work-articles n))
13020 (save-buffer (save-excursion
13021 (nnheader-set-temp-buffer " *Gnus Save*")))
13022 file header article)
13023 (while articles
13024 (setq header (gnus-summary-article-header
13025 (setq article (pop articles))))
13026 (if (not (vectorp header))
13027 ;; This is a pseudo-article.
13028 (if (assq 'name header)
13029 (gnus-copy-file (cdr (assq 'name header)))
13030 (gnus-message 1 "Article %d is unsaveable" article))
13031 ;; This is a real article.
13032 (save-window-excursion
13033 (gnus-summary-select-article t nil nil article))
13034 (save-excursion
13035 (set-buffer save-buffer)
13036 (erase-buffer)
13037 (insert-buffer-substring gnus-original-article-buffer))
13038 (unless gnus-save-all-headers
13039 ;; Remove headers accoring to `gnus-saved-headers'.
13040 (let ((gnus-visible-headers
13041 (or gnus-saved-headers gnus-visible-headers))
13042 (gnus-article-buffer save-buffer))
13043 (gnus-article-hide-headers 1 t)))
13044 (save-window-excursion
13045 (if (not gnus-default-article-saver)
13046 (error "No default saver is defined.")
13047 ;; !!! Magic! The saving functions all save
13048 ;; `gnus-original-article-buffer' (or so they think),
13049 ;; but we bind that variable to our save-buffer.
13050 (set-buffer gnus-article-buffer)
13051 (let ((gnus-original-article-buffer save-buffer))
13052 (set-buffer gnus-summary-buffer)
13053 (setq file (funcall
13054 gnus-default-article-saver
13055 (cond
13056 ((not gnus-prompt-before-saving)
13057 'default)
13058 ((eq gnus-prompt-before-saving 'always)
13059 nil)
13060 (t file)))))))
13061 (gnus-summary-remove-process-mark article)
13062 (unless not-saved
13063 (gnus-summary-set-saved-mark article))))
13064 (gnus-kill-buffer save-buffer)
13065 (gnus-summary-position-point)
13066 n))
13067
13068 (defun gnus-summary-pipe-output (&optional arg)
13069 "Pipe the current article to a subprocess.
13070 If N is a positive number, pipe the N next articles.
13071 If N is a negative number, pipe the N previous articles.
13072 If N is nil and any articles have been marked with the process mark,
13073 pipe those articles instead."
13074 (interactive "P")
13075 (gnus-set-global-variables)
13076 (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
13077 (gnus-summary-save-article arg t))
13078 (gnus-configure-windows 'pipe))
13079
13080 (defun gnus-summary-save-article-mail (&optional arg)
13081 "Append the current article to an mail file.
13082 If N is a positive number, save the N next articles.
13083 If N is a negative number, save the N previous articles.
13084 If N is nil and any articles have been marked with the process mark,
13085 save those articles instead."
13086 (interactive "P")
13087 (gnus-set-global-variables)
13088 (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
13089 (gnus-summary-save-article arg)))
13090
13091 (defun gnus-summary-save-article-rmail (&optional arg)
13092 "Append the current article to an rmail file.
13093 If N is a positive number, save the N next articles.
13094 If N is a negative number, save the N previous articles.
13095 If N is nil and any articles have been marked with the process mark,
13096 save those articles instead."
13097 (interactive "P")
13098 (gnus-set-global-variables)
13099 (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
13100 (gnus-summary-save-article arg)))
13101
13102 (defun gnus-summary-save-article-file (&optional arg)
13103 "Append the current article to a file.
13104 If N is a positive number, save the N next articles.
13105 If N is a negative number, save the N previous articles.
13106 If N is nil and any articles have been marked with the process mark,
13107 save those articles instead."
13108 (interactive "P")
13109 (gnus-set-global-variables)
13110 (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
13111 (gnus-summary-save-article arg)))
13112
13113 (defun gnus-summary-save-article-body-file (&optional arg)
13114 "Append the current article body to a file.
13115 If N is a positive number, save the N next articles.
13116 If N is a negative number, save the N previous articles.
13117 If N is nil and any articles have been marked with the process mark,
13118 save those articles instead."
13119 (interactive "P")
13120 (gnus-set-global-variables)
13121 (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
13122 (gnus-summary-save-article arg)))
13123
13124 (defun gnus-get-split-value (methods)
13125 "Return a value based on the split METHODS."
13126 (let (split-name method result match)
13127 (when methods
13128 (save-excursion
13129 (set-buffer gnus-original-article-buffer)
13130 (save-restriction
13131 (nnheader-narrow-to-headers)
13132 (while methods
13133 (goto-char (point-min))
13134 (setq method (pop methods))
13135 (setq match (car method))
13136 (when (cond
13137 ((stringp match)
13138 ;; Regular expression.
13139 (condition-case ()
13140 (re-search-forward match nil t)
13141 (error nil)))
13142 ((gnus-functionp match)
13143 ;; Function.
13144 (save-restriction
13145 (widen)
13146 (setq result (funcall match gnus-newsgroup-name))))
13147 ((consp match)
13148 ;; Form.
13149 (save-restriction
13150 (widen)
13151 (setq result (eval match)))))
13152 (setq split-name (append (cdr method) split-name))
13153 (cond ((stringp result)
13154 (push result split-name))
13155 ((consp result)
13156 (setq split-name (append result split-name)))))))))
13157 split-name))
13158
13159 (defun gnus-read-move-group-name (prompt default articles prefix)
13160 "Read a group name."
13161 (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
13162 (minibuffer-confirm-incomplete nil) ; XEmacs
13163 group-map
13164 (dum (mapatoms
13165 (lambda (g)
13166 (and (boundp g)
13167 (symbol-name g)
13168 (memq 'respool
13169 (assoc (symbol-name
13170 (car (gnus-find-method-for-group
13171 (symbol-name g))))
13172 gnus-valid-select-methods))
13173 (push (list (symbol-name g)) group-map)))
13174 gnus-active-hashtb))
13175 (prom
13176 (format "%s %s to:"
13177 prompt
13178 (if (> (length articles) 1)
13179 (format "these %d articles" (length articles))
13180 "this article")))
13181 (to-newsgroup
13182 (cond
13183 ((null split-name)
13184 (gnus-completing-read default prom
13185 group-map nil nil prefix
13186 'gnus-group-history))
13187 ((= 1 (length split-name))
13188 (gnus-completing-read (car split-name) prom group-map
13189 nil nil nil
13190 'gnus-group-history))
13191 (t
13192 (gnus-completing-read nil prom
13193 (mapcar (lambda (el) (list el))
13194 (nreverse split-name))
13195 nil nil nil
13196 'gnus-group-history)))))
13197 (when to-newsgroup
13198 (if (or (string= to-newsgroup "")
13199 (string= to-newsgroup prefix))
13200 (setq to-newsgroup (or default "")))
13201 (or (gnus-active to-newsgroup)
13202 (gnus-activate-group to-newsgroup)
13203 (if (gnus-y-or-n-p (format "No such group: %s. Create it? "
13204 to-newsgroup))
13205 (or (and (gnus-request-create-group
13206 to-newsgroup (gnus-group-name-to-method to-newsgroup))
13207 (gnus-activate-group to-newsgroup nil nil
13208 (gnus-group-name-to-method
13209 to-newsgroup)))
13210 (error "Couldn't create group %s" to-newsgroup)))
13211 (error "No such group: %s" to-newsgroup)))
13212 to-newsgroup))
13213
13214 (defun gnus-read-save-file-name (prompt default-name)
13215 (let* ((split-name (gnus-get-split-value gnus-split-methods))
13216 (file
13217 ;; Let the split methods have their say.
13218 (cond
13219 ;; No split name was found.
13220 ((null split-name)
13221 (read-file-name
13222 (concat prompt " (default "
13223 (file-name-nondirectory default-name) ") ")
13224 (file-name-directory default-name)
13225 default-name))
13226 ;; A single split name was found
13227 ((= 1 (length split-name))
13228 (let* ((name (car split-name))
13229 (dir (cond ((file-directory-p name)
13230 (file-name-as-directory name))
13231 ((file-exists-p name) name)
13232 (t gnus-article-save-directory))))
13233 (read-file-name
13234 (concat prompt " (default " name ") ")
13235 dir name)))
13236 ;; A list of splits was found.
13237 (t
13238 (setq split-name (nreverse split-name))
13239 (let (result)
13240 (let ((file-name-history (nconc split-name file-name-history)))
13241 (setq result
13242 (read-file-name
13243 (concat prompt " (`M-p' for defaults) ")
13244 gnus-article-save-directory
13245 (car split-name))))
13246 (car (push result file-name-history)))))))
13247 ;; If we have read a directory, we append the default file name.
13248 (when (file-directory-p file)
13249 (setq file (concat (file-name-as-directory file)
13250 (file-name-nondirectory default-name))))
13251 ;; Possibly translate some charaters.
13252 (nnheader-translate-file-chars file)))
13253
13254 (defun gnus-article-archive-name (group)
13255 "Return the first instance of an \"Archive-name\" in the current buffer."
13256 (let ((case-fold-search t))
13257 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
13258 (match-string 1))))
13259
13260 (defun gnus-summary-save-in-rmail (&optional filename)
13261 "Append this article to Rmail file.
13262 Optional argument FILENAME specifies file name.
13263 Directory to save to is default to `gnus-article-save-directory'."
13264 (interactive)
13265 (gnus-set-global-variables)
13266 (let ((default-name
13267 (funcall gnus-rmail-save-name gnus-newsgroup-name
13268 gnus-current-headers gnus-newsgroup-last-rmail)))
13269 (setq filename
13270 (cond ((eq filename 'default)
13271 default-name)
13272 (filename filename)
13273 (t (gnus-read-save-file-name
13274 "Save in rmail file:" default-name))))
13275 (gnus-make-directory (file-name-directory filename))
13276 (gnus-eval-in-buffer-window gnus-original-article-buffer
13277 (save-excursion
13278 (save-restriction
13279 (widen)
13280 (gnus-output-to-rmail filename))))
13281 ;; Remember the directory name to save articles
13282 (setq gnus-newsgroup-last-rmail filename)))
13283
13284 (defun gnus-summary-save-in-mail (&optional filename)
13285 "Append this article to Unix mail file.
13286 Optional argument FILENAME specifies file name.
13287 Directory to save to is default to `gnus-article-save-directory'."
13288 (interactive)
13289 (gnus-set-global-variables)
13290 (let ((default-name
13291 (funcall gnus-mail-save-name gnus-newsgroup-name
13292 gnus-current-headers gnus-newsgroup-last-mail)))
13293 (setq filename
13294 (cond ((eq filename 'default)
13295 default-name)
13296 (filename filename)
13297 (t (gnus-read-save-file-name
13298 "Save in Unix mail file:" default-name))))
13299 (setq filename
13300 (expand-file-name filename
13301 (and default-name
13302 (file-name-directory default-name))))
13303 (gnus-make-directory (file-name-directory filename))
13304 (gnus-eval-in-buffer-window gnus-original-article-buffer
13305 (save-excursion
13306 (save-restriction
13307 (widen)
13308 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
13309 (gnus-output-to-rmail filename)
13310 (let ((mail-use-rfc822 t))
13311 (rmail-output filename 1 t t))))))
13312 ;; Remember the directory name to save articles.
13313 (setq gnus-newsgroup-last-mail filename)))
13314
13315 (defun gnus-summary-save-in-file (&optional filename)
13316 "Append this article to file.
13317 Optional argument FILENAME specifies file name.
13318 Directory to save to is default to `gnus-article-save-directory'."
13319 (interactive)
13320 (gnus-set-global-variables)
13321 (let ((default-name
13322 (funcall gnus-file-save-name gnus-newsgroup-name
13323 gnus-current-headers gnus-newsgroup-last-file)))
13324 (setq filename
13325 (cond ((eq filename 'default)
13326 default-name)
13327 (filename filename)
13328 (t (gnus-read-save-file-name
13329 "Save in file:" default-name))))
13330 (gnus-make-directory (file-name-directory filename))
13331 (gnus-eval-in-buffer-window gnus-original-article-buffer
13332 (save-excursion
13333 (save-restriction
13334 (widen)
13335 (gnus-output-to-file filename))))
13336 ;; Remember the directory name to save articles.
13337 (setq gnus-newsgroup-last-file filename)))
13338
13339 (defun gnus-summary-save-body-in-file (&optional filename)
13340 "Append this article body to a file.
13341 Optional argument FILENAME specifies file name.
13342 The directory to save in defaults to `gnus-article-save-directory'."
13343 (interactive)
13344 (gnus-set-global-variables)
13345 (let ((default-name
13346 (funcall gnus-file-save-name gnus-newsgroup-name
13347 gnus-current-headers gnus-newsgroup-last-file)))
13348 (setq filename
13349 (cond ((eq filename 'default)
13350 default-name)
13351 (filename filename)
13352 (t (gnus-read-save-file-name
13353 "Save body in file:" default-name))))
13354 (gnus-make-directory (file-name-directory filename))
13355 (gnus-eval-in-buffer-window gnus-original-article-buffer
13356 (save-excursion
13357 (save-restriction
13358 (widen)
13359 (goto-char (point-min))
13360 (and (search-forward "\n\n" nil t)
13361 (narrow-to-region (point) (point-max)))
13362 (gnus-output-to-file filename))))
13363 ;; Remember the directory name to save articles.
13364 (setq gnus-newsgroup-last-file filename)))
13365
13366 (defun gnus-summary-save-in-pipe (&optional command)
13367 "Pipe this article to subprocess."
13368 (interactive)
13369 (gnus-set-global-variables)
13370 (setq command
13371 (cond ((eq command 'default)
13372 gnus-last-shell-command)
13373 (command command)
13374 (t (read-string "Shell command on article: "
13375 gnus-last-shell-command))))
13376 (if (string-equal command "")
13377 (setq command gnus-last-shell-command))
13378 (gnus-eval-in-buffer-window gnus-article-buffer
13379 (save-restriction
13380 (widen)
13381 (shell-command-on-region (point-min) (point-max) command nil)))
13382 (setq gnus-last-shell-command command))
13383
13384 ;; Summary extract commands
13385
13386 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
13387 (let ((buffer-read-only nil)
13388 (article (gnus-summary-article-number))
13389 after-article b e)
13390 (or (gnus-summary-goto-subject article)
13391 (error (format "No such article: %d" article)))
13392 (gnus-summary-position-point)
13393 ;; If all commands are to be bunched up on one line, we collect
13394 ;; them here.
13395 (if gnus-view-pseudos-separately
13396 ()
13397 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
13398 files action)
13399 (while ps
13400 (setq action (cdr (assq 'action (car ps))))
13401 (setq files (list (cdr (assq 'name (car ps)))))
13402 (while (and ps (cdr ps)
13403 (string= (or action "1")
13404 (or (cdr (assq 'action (cadr ps))) "2")))
13405 (setq files (cons (cdr (assq 'name (cadr ps))) files))
13406 (setcdr ps (cddr ps)))
13407 (if (not files)
13408 ()
13409 (if (not (string-match "%s" action))
13410 (setq files (cons " " files)))
13411 (setq files (cons " " files))
13412 (and (assq 'execute (car ps))
13413 (setcdr (assq 'execute (car ps))
13414 (funcall (if (string-match "%s" action)
13415 'format 'concat)
13416 action
13417 (mapconcat (lambda (f) f) files " ")))))
13418 (setq ps (cdr ps)))))
13419 (if (and gnus-view-pseudos (not not-view))
13420 (while pslist
13421 (and (assq 'execute (car pslist))
13422 (gnus-execute-command (cdr (assq 'execute (car pslist)))
13423 (eq gnus-view-pseudos 'not-confirm)))
13424 (setq pslist (cdr pslist)))
13425 (save-excursion
13426 (while pslist
13427 (setq after-article (or (cdr (assq 'article (car pslist)))
13428 (gnus-summary-article-number)))
13429 (gnus-summary-goto-subject after-article)
13430 (forward-line 1)
13431 (setq b (point))
13432 (insert " " (file-name-nondirectory
13433 (cdr (assq 'name (car pslist))))
13434 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
13435 (setq e (point))
13436 (forward-line -1) ; back to `b'
13437 (gnus-add-text-properties
13438 b (1- e) (list 'gnus-number gnus-reffed-article-number
13439 gnus-mouse-face-prop gnus-mouse-face))
13440 (gnus-data-enter
13441 after-article gnus-reffed-article-number
13442 gnus-unread-mark b (car pslist) 0 (- e b))
13443 (push gnus-reffed-article-number gnus-newsgroup-unreads)
13444 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
13445 (setq pslist (cdr pslist)))))))
13446
13447 (defun gnus-pseudos< (p1 p2)
13448 (let ((c1 (cdr (assq 'action p1)))
13449 (c2 (cdr (assq 'action p2))))
13450 (and c1 c2 (string< c1 c2))))
13451
13452 (defun gnus-request-pseudo-article (props)
13453 (cond ((assq 'execute props)
13454 (gnus-execute-command (cdr (assq 'execute props)))))
13455 (let ((gnus-current-article (gnus-summary-article-number)))
13456 (run-hooks 'gnus-mark-article-hook)))
13457
13458 (defun gnus-execute-command (command &optional automatic)
13459 (save-excursion
13460 (gnus-article-setup-buffer)
13461 (set-buffer gnus-article-buffer)
13462 (setq buffer-read-only nil)
13463 (let ((command (if automatic command (read-string "Command: " command)))
13464 ;; Just binding this here doesn't help, because there might
13465 ;; be output from the process after exiting the scope of
13466 ;; this `let'.
13467 ;; (buffer-read-only nil)
13468 )
13469 (erase-buffer)
13470 (insert "$ " command "\n\n")
13471 (if gnus-view-pseudo-asynchronously
13472 (start-process "gnus-execute" nil shell-file-name
13473 shell-command-switch command)
13474 (call-process shell-file-name nil t nil
13475 shell-command-switch command)))))
13476
13477 (defun gnus-copy-file (file &optional to)
13478 "Copy FILE to TO."
13479 (interactive
13480 (list (read-file-name "Copy file: " default-directory)
13481 (read-file-name "Copy file to: " default-directory)))
13482 (gnus-set-global-variables)
13483 (or to (setq to (read-file-name "Copy file to: " default-directory)))
13484 (and (file-directory-p to)
13485 (setq to (concat (file-name-as-directory to)
13486 (file-name-nondirectory file))))
13487 (copy-file file to))
13488
13489 ;; Summary kill commands.
13490
13491 (defun gnus-summary-edit-global-kill (article)
13492 "Edit the \"global\" kill file."
13493 (interactive (list (gnus-summary-article-number)))
13494 (gnus-set-global-variables)
13495 (gnus-group-edit-global-kill article))
13496
13497 (defun gnus-summary-edit-local-kill ()
13498 "Edit a local kill file applied to the current newsgroup."
13499 (interactive)
13500 (gnus-set-global-variables)
13501 (setq gnus-current-headers (gnus-summary-article-header))
13502 (gnus-set-global-variables)
13503 (gnus-group-edit-local-kill
13504 (gnus-summary-article-number) gnus-newsgroup-name))
13505
13506 \f
13507 ;;;
13508 ;;; Gnus article mode
13509 ;;;
13510
13511 (put 'gnus-article-mode 'mode-class 'special)
13512
13513 (if gnus-article-mode-map
13514 nil
13515 (setq gnus-article-mode-map (make-keymap))
13516 (suppress-keymap gnus-article-mode-map)
13517
13518 (gnus-define-keys gnus-article-mode-map
13519 " " gnus-article-goto-next-page
13520 "\177" gnus-article-goto-prev-page
13521 [delete] gnus-article-goto-prev-page
13522 "\C-c^" gnus-article-refer-article
13523 "h" gnus-article-show-summary
13524 "s" gnus-article-show-summary
13525 "\C-c\C-m" gnus-article-mail
13526 "?" gnus-article-describe-briefly
13527 gnus-mouse-2 gnus-article-push-button
13528 "\r" gnus-article-press-button
13529 "\t" gnus-article-next-button
13530 "\M-\t" gnus-article-prev-button
13531 "<" beginning-of-buffer
13532 ">" end-of-buffer
13533 "\C-c\C-i" gnus-info-find-node
13534 "\C-c\C-b" gnus-bug)
13535
13536 (substitute-key-definition
13537 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
13538
13539 (defun gnus-article-mode ()
13540 "Major mode for displaying an article.
13541
13542 All normal editing commands are switched off.
13543
13544 The following commands are available:
13545
13546 \\<gnus-article-mode-map>
13547 \\[gnus-article-next-page]\t Scroll the article one page forwards
13548 \\[gnus-article-prev-page]\t Scroll the article one page backwards
13549 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
13550 \\[gnus-article-show-summary]\t Display the summary buffer
13551 \\[gnus-article-mail]\t Send a reply to the address near point
13552 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
13553 \\[gnus-info-find-node]\t Go to the Gnus info node"
13554 (interactive)
13555 (when (and menu-bar-mode
13556 (gnus-visual-p 'article-menu 'menu))
13557 (gnus-article-make-menu-bar))
13558 (kill-all-local-variables)
13559 (gnus-simplify-mode-line)
13560 (setq mode-name "Article")
13561 (setq major-mode 'gnus-article-mode)
13562 (make-local-variable 'minor-mode-alist)
13563 (or (assq 'gnus-show-mime minor-mode-alist)
13564 (setq minor-mode-alist
13565 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
13566 (use-local-map gnus-article-mode-map)
13567 (make-local-variable 'page-delimiter)
13568 (setq page-delimiter gnus-page-delimiter)
13569 (buffer-disable-undo (current-buffer))
13570 (setq buffer-read-only t) ;Disable modification
13571 (run-hooks 'gnus-article-mode-hook))
13572
13573 (defun gnus-article-setup-buffer ()
13574 "Initialize the article buffer."
13575 (let* ((name (if gnus-single-article-buffer "*Article*"
13576 (concat "*Article " gnus-newsgroup-name "*")))
13577 (original
13578 (progn (string-match "\\*Article" name)
13579 (concat " *Original Article"
13580 (substring name (match-end 0))))))
13581 (setq gnus-article-buffer name)
13582 (setq gnus-original-article-buffer original)
13583 ;; This might be a variable local to the summary buffer.
13584 (unless gnus-single-article-buffer
13585 (save-excursion
13586 (set-buffer gnus-summary-buffer)
13587 (setq gnus-article-buffer name)
13588 (setq gnus-original-article-buffer original)
13589 (gnus-set-global-variables))
13590 (make-local-variable 'gnus-summary-buffer))
13591 ;; Init original article buffer.
13592 (save-excursion
13593 (set-buffer (get-buffer-create gnus-original-article-buffer))
13594 (buffer-disable-undo (current-buffer))
13595 (setq major-mode 'gnus-original-article-mode)
13596 (make-local-variable 'gnus-original-article))
13597 (if (get-buffer name)
13598 (save-excursion
13599 (set-buffer name)
13600 (buffer-disable-undo (current-buffer))
13601 (setq buffer-read-only t)
13602 (gnus-add-current-to-buffer-list)
13603 (or (eq major-mode 'gnus-article-mode)
13604 (gnus-article-mode))
13605 (current-buffer))
13606 (save-excursion
13607 (set-buffer (get-buffer-create name))
13608 (gnus-add-current-to-buffer-list)
13609 (gnus-article-mode)
13610 (current-buffer)))))
13611
13612 ;; Set article window start at LINE, where LINE is the number of lines
13613 ;; from the head of the article.
13614 (defun gnus-article-set-window-start (&optional line)
13615 (set-window-start
13616 (get-buffer-window gnus-article-buffer t)
13617 (save-excursion
13618 (set-buffer gnus-article-buffer)
13619 (goto-char (point-min))
13620 (if (not line)
13621 (point-min)
13622 (gnus-message 6 "Moved to bookmark")
13623 (search-forward "\n\n" nil t)
13624 (forward-line line)
13625 (point)))))
13626
13627 (defun gnus-kill-all-overlays ()
13628 "Delete all overlays in the current buffer."
13629 (when (fboundp 'overlay-lists)
13630 (let* ((overlayss (overlay-lists))
13631 (buffer-read-only nil)
13632 (overlays (nconc (car overlayss) (cdr overlayss))))
13633 (while overlays
13634 (delete-overlay (pop overlays))))))
13635
13636 (defun gnus-request-article-this-buffer (article group)
13637 "Get an article and insert it into this buffer."
13638 (let (do-update-line)
13639 (prog1
13640 (save-excursion
13641 (erase-buffer)
13642 (gnus-kill-all-overlays)
13643 (setq group (or group gnus-newsgroup-name))
13644
13645 ;; Open server if it has closed.
13646 (gnus-check-server (gnus-find-method-for-group group))
13647
13648 ;; Using `gnus-request-article' directly will insert the article into
13649 ;; `nntp-server-buffer' - so we'll save some time by not having to
13650 ;; copy it from the server buffer into the article buffer.
13651
13652 ;; We only request an article by message-id when we do not have the
13653 ;; headers for it, so we'll have to get those.
13654 (when (stringp article)
13655 (let ((gnus-override-method gnus-refer-article-method))
13656 (gnus-read-header article)))
13657
13658 ;; If the article number is negative, that means that this article
13659 ;; doesn't belong in this newsgroup (possibly), so we find its
13660 ;; message-id and request it by id instead of number.
13661 (when (and (numberp article)
13662 gnus-summary-buffer
13663 (get-buffer gnus-summary-buffer)
13664 (buffer-name (get-buffer gnus-summary-buffer)))
13665 (save-excursion
13666 (set-buffer gnus-summary-buffer)
13667 (let ((header (gnus-summary-article-header article)))
13668 (if (< article 0)
13669 (cond
13670 ((memq article gnus-newsgroup-sparse)
13671 ;; This is a sparse gap article.
13672 (setq do-update-line article)
13673 (setq article (mail-header-id header))
13674 (let ((gnus-override-method gnus-refer-article-method))
13675 (gnus-read-header article))
13676 (setq gnus-newsgroup-sparse
13677 (delq article gnus-newsgroup-sparse)))
13678 ((vectorp header)
13679 ;; It's a real article.
13680 (setq article (mail-header-id header)))
13681 (t
13682 ;; It is an extracted pseudo-article.
13683 (setq article 'pseudo)
13684 (gnus-request-pseudo-article header))))
13685
13686 (let ((method (gnus-find-method-for-group
13687 gnus-newsgroup-name)))
13688 (if (not (eq (car method) 'nneething))
13689 ()
13690 (let ((dir (concat (file-name-as-directory (nth 1 method))
13691 (mail-header-subject header))))
13692 (if (file-directory-p dir)
13693 (progn
13694 (setq article 'nneething)
13695 (gnus-group-enter-directory dir)))))))))
13696
13697 (cond
13698 ;; Refuse to select canceled articles.
13699 ((and (numberp article)
13700 gnus-summary-buffer
13701 (get-buffer gnus-summary-buffer)
13702 (buffer-name (get-buffer gnus-summary-buffer))
13703 (eq (cdr (save-excursion
13704 (set-buffer gnus-summary-buffer)
13705 (assq article gnus-newsgroup-reads)))
13706 gnus-canceled-mark))
13707 nil)
13708 ;; We first check `gnus-original-article-buffer'.
13709 ((and (get-buffer gnus-original-article-buffer)
13710 (numberp article)
13711 (save-excursion
13712 (set-buffer gnus-original-article-buffer)
13713 (and (equal (car gnus-original-article) group)
13714 (eq (cdr gnus-original-article) article))))
13715 (insert-buffer-substring gnus-original-article-buffer)
13716 'article)
13717 ;; Check the backlog.
13718 ((and gnus-keep-backlog
13719 (gnus-backlog-request-article group article (current-buffer)))
13720 'article)
13721 ;; Check the cache.
13722 ((and gnus-use-cache
13723 (numberp article)
13724 (gnus-cache-request-article article group))
13725 'article)
13726 ;; Get the article and put into the article buffer.
13727 ((or (stringp article) (numberp article))
13728 (let ((gnus-override-method
13729 (and (stringp article) gnus-refer-article-method))
13730 (buffer-read-only nil))
13731 (erase-buffer)
13732 (gnus-kill-all-overlays)
13733 (if (gnus-request-article article group (current-buffer))
13734 (progn
13735 (and gnus-keep-backlog
13736 (numberp article)
13737 (gnus-backlog-enter-article
13738 group article (current-buffer)))
13739 'article))))
13740 ;; It was a pseudo.
13741 (t article)))
13742
13743 ;; Take the article from the original article buffer
13744 ;; and place it in the buffer it's supposed to be in.
13745 (when (and (get-buffer gnus-article-buffer)
13746 ;;(numberp article)
13747 (equal (buffer-name (current-buffer))
13748 (buffer-name (get-buffer gnus-article-buffer))))
13749 (save-excursion
13750 (if (get-buffer gnus-original-article-buffer)
13751 (set-buffer (get-buffer gnus-original-article-buffer))
13752 (set-buffer (get-buffer-create gnus-original-article-buffer))
13753 (buffer-disable-undo (current-buffer))
13754 (setq major-mode 'gnus-original-article-mode)
13755 (setq buffer-read-only t)
13756 (gnus-add-current-to-buffer-list))
13757 (let (buffer-read-only)
13758 (erase-buffer)
13759 (insert-buffer-substring gnus-article-buffer))
13760 (setq gnus-original-article (cons group article))))
13761
13762 ;; Update sparse articles.
13763 (when (and do-update-line
13764 (or (numberp article)
13765 (stringp article)))
13766 (let ((buf (current-buffer)))
13767 (set-buffer gnus-summary-buffer)
13768 (gnus-summary-update-article do-update-line)
13769 (gnus-summary-goto-subject do-update-line nil t)
13770 (set-window-point (get-buffer-window (current-buffer) t)
13771 (point))
13772 (set-buffer buf))))))
13773
13774 (defun gnus-read-header (id &optional header)
13775 "Read the headers of article ID and enter them into the Gnus system."
13776 (let ((group gnus-newsgroup-name)
13777 (gnus-override-method
13778 (and (gnus-news-group-p gnus-newsgroup-name)
13779 gnus-refer-article-method))
13780 where)
13781 ;; First we check to see whether the header in question is already
13782 ;; fetched.
13783 (if (stringp id)
13784 ;; This is a Message-ID.
13785 (setq header (or header (gnus-id-to-header id)))
13786 ;; This is an article number.
13787 (setq header (or header (gnus-summary-article-header id))))
13788 (if (and header
13789 (not (memq (mail-header-number header) gnus-newsgroup-sparse)))
13790 ;; We have found the header.
13791 header
13792 ;; We have to really fetch the header to this article.
13793 (when (setq where (gnus-request-head id group))
13794 (save-excursion
13795 (set-buffer nntp-server-buffer)
13796 (goto-char (point-max))
13797 (insert ".\n")
13798 (goto-char (point-min))
13799 (insert "211 ")
13800 (princ (cond
13801 ((numberp id) id)
13802 ((cdr where) (cdr where))
13803 (header (mail-header-number header))
13804 (t gnus-reffed-article-number))
13805 (current-buffer))
13806 (insert " Article retrieved.\n"))
13807 ;(when (and header
13808 ; (memq (mail-header-number header) gnus-newsgroup-sparse))
13809 ; (setcar (gnus-id-to-thread id) nil))
13810 (if (not (setq header (car (gnus-get-newsgroup-headers))))
13811 () ; Malformed head.
13812 (unless (memq (mail-header-number header) gnus-newsgroup-sparse)
13813 (if (and (stringp id)
13814 (not (string= (gnus-group-real-name group)
13815 (car where))))
13816 ;; If we fetched by Message-ID and the article came
13817 ;; from a different group, we fudge some bogus article
13818 ;; numbers for this article.
13819 (mail-header-set-number header gnus-reffed-article-number))
13820 (decf gnus-reffed-article-number)
13821 (gnus-remove-header (mail-header-number header))
13822 (push header gnus-newsgroup-headers)
13823 (setq gnus-current-headers header)
13824 (push (mail-header-number header) gnus-newsgroup-limit))
13825 header)))))
13826
13827 (defun gnus-remove-header (number)
13828 "Remove header NUMBER from `gnus-newsgroup-headers'."
13829 (if (and gnus-newsgroup-headers
13830 (= number (mail-header-number (car gnus-newsgroup-headers))))
13831 (pop gnus-newsgroup-headers)
13832 (let ((headers gnus-newsgroup-headers))
13833 (while (and (cdr headers)
13834 (not (= number (mail-header-number (cadr headers)))))
13835 (pop headers))
13836 (when (cdr headers)
13837 (setcdr headers (cddr headers))))))
13838
13839 (defun gnus-article-prepare (article &optional all-headers header)
13840 "Prepare ARTICLE in article mode buffer.
13841 ARTICLE should either be an article number or a Message-ID.
13842 If ARTICLE is an id, HEADER should be the article headers.
13843 If ALL-HEADERS is non-nil, no headers are hidden."
13844 (save-excursion
13845 ;; Make sure we start in a summary buffer.
13846 (unless (eq major-mode 'gnus-summary-mode)
13847 (set-buffer gnus-summary-buffer))
13848 (setq gnus-summary-buffer (current-buffer))
13849 ;; Make sure the connection to the server is alive.
13850 (unless (gnus-server-opened
13851 (gnus-find-method-for-group gnus-newsgroup-name))
13852 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
13853 (gnus-request-group gnus-newsgroup-name t))
13854 (let* ((article (if header (mail-header-number header) article))
13855 (summary-buffer (current-buffer))
13856 (internal-hook gnus-article-internal-prepare-hook)
13857 (group gnus-newsgroup-name)
13858 result)
13859 (save-excursion
13860 (gnus-article-setup-buffer)
13861 (set-buffer gnus-article-buffer)
13862 ;; Deactivate active regions.
13863 (when (and (boundp 'transient-mark-mode)
13864 transient-mark-mode)
13865 (setq mark-active nil))
13866 (if (not (setq result (let ((buffer-read-only nil))
13867 (gnus-request-article-this-buffer
13868 article group))))
13869 ;; There is no such article.
13870 (save-excursion
13871 (when (and (numberp article)
13872 (not (memq article gnus-newsgroup-sparse)))
13873 (setq gnus-article-current
13874 (cons gnus-newsgroup-name article))
13875 (set-buffer gnus-summary-buffer)
13876 (setq gnus-current-article article)
13877 (gnus-summary-mark-article article gnus-canceled-mark))
13878 (unless (memq article gnus-newsgroup-sparse)
13879 (gnus-error
13880 1 "No such article (may have expired or been canceled)")))
13881 (if (or (eq result 'pseudo) (eq result 'nneething))
13882 (progn
13883 (save-excursion
13884 (set-buffer summary-buffer)
13885 (setq gnus-last-article gnus-current-article
13886 gnus-newsgroup-history (cons gnus-current-article
13887 gnus-newsgroup-history)
13888 gnus-current-article 0
13889 gnus-current-headers nil
13890 gnus-article-current nil)
13891 (if (eq result 'nneething)
13892 (gnus-configure-windows 'summary)
13893 (gnus-configure-windows 'article))
13894 (gnus-set-global-variables))
13895 (gnus-set-mode-line 'article))
13896 ;; The result from the `request' was an actual article -
13897 ;; or at least some text that is now displayed in the
13898 ;; article buffer.
13899 (if (and (numberp article)
13900 (not (eq article gnus-current-article)))
13901 ;; Seems like a new article has been selected.
13902 ;; `gnus-current-article' must be an article number.
13903 (save-excursion
13904 (set-buffer summary-buffer)
13905 (setq gnus-last-article gnus-current-article
13906 gnus-newsgroup-history (cons gnus-current-article
13907 gnus-newsgroup-history)
13908 gnus-current-article article
13909 gnus-current-headers
13910 (gnus-summary-article-header gnus-current-article)
13911 gnus-article-current
13912 (cons gnus-newsgroup-name gnus-current-article))
13913 (unless (vectorp gnus-current-headers)
13914 (setq gnus-current-headers nil))
13915 (gnus-summary-show-thread)
13916 (run-hooks 'gnus-mark-article-hook)
13917 (gnus-set-mode-line 'summary)
13918 (and (gnus-visual-p 'article-highlight 'highlight)
13919 (run-hooks 'gnus-visual-mark-article-hook))
13920 ;; Set the global newsgroup variables here.
13921 ;; Suggested by Jim Sisolak
13922 ;; <sisolak@trans4.neep.wisc.edu>.
13923 (gnus-set-global-variables)
13924 (setq gnus-have-all-headers
13925 (or all-headers gnus-show-all-headers))
13926 (and gnus-use-cache
13927 (vectorp (gnus-summary-article-header article))
13928 (gnus-cache-possibly-enter-article
13929 group article
13930 (gnus-summary-article-header article)
13931 (memq article gnus-newsgroup-marked)
13932 (memq article gnus-newsgroup-dormant)
13933 (memq article gnus-newsgroup-unreads)))))
13934 (when (or (numberp article)
13935 (stringp article))
13936 ;; Hooks for getting information from the article.
13937 ;; This hook must be called before being narrowed.
13938 (let (buffer-read-only)
13939 (run-hooks 'internal-hook)
13940 (run-hooks 'gnus-article-prepare-hook)
13941 ;; Decode MIME message.
13942 (if gnus-show-mime
13943 (if (or (not gnus-strict-mime)
13944 (gnus-fetch-field "Mime-Version"))
13945 (funcall gnus-show-mime-method)
13946 (funcall gnus-decode-encoded-word-method)))
13947 ;; Perform the article display hooks.
13948 (run-hooks 'gnus-article-display-hook))
13949 ;; Do page break.
13950 (goto-char (point-min))
13951 (and gnus-break-pages (gnus-narrow-to-page)))
13952 (gnus-set-mode-line 'article)
13953 (gnus-configure-windows 'article)
13954 (goto-char (point-min))
13955 t))))))
13956
13957 (defun gnus-article-show-all-headers ()
13958 "Show all article headers in article mode buffer."
13959 (save-excursion
13960 (gnus-article-setup-buffer)
13961 (set-buffer gnus-article-buffer)
13962 (let ((buffer-read-only nil))
13963 (gnus-unhide-text (point-min) (point-max)))))
13964
13965 (defun gnus-article-hide-headers-if-wanted ()
13966 "Hide unwanted headers if `gnus-have-all-headers' is nil.
13967 Provided for backwards compatibility."
13968 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
13969 gnus-inhibit-hiding
13970 (gnus-article-hide-headers)))
13971
13972 (defsubst gnus-article-header-rank ()
13973 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
13974 (let ((list gnus-sorted-header-list)
13975 (i 0))
13976 (while list
13977 (when (looking-at (car list))
13978 (setq list nil))
13979 (setq list (cdr list))
13980 (incf i))
13981 i))
13982
13983 (defun gnus-article-hide-headers (&optional arg delete)
13984 "Toggle whether to hide unwanted headers and possibly sort them as well.
13985 If given a negative prefix, always show; if given a positive prefix,
13986 always hide."
13987 (interactive (gnus-hidden-arg))
13988 (if (gnus-article-check-hidden-text 'headers arg)
13989 ;; Show boring headers as well.
13990 (gnus-article-show-hidden-text 'boring-headers)
13991 ;; This function might be inhibited.
13992 (unless gnus-inhibit-hiding
13993 (save-excursion
13994 (set-buffer gnus-article-buffer)
13995 (save-restriction
13996 (let ((buffer-read-only nil)
13997 (props (nconc (list 'gnus-type 'headers)
13998 gnus-hidden-properties))
13999 (max (1+ (length gnus-sorted-header-list)))
14000 (ignored (when (not (stringp gnus-visible-headers))
14001 (cond ((stringp gnus-ignored-headers)
14002 gnus-ignored-headers)
14003 ((listp gnus-ignored-headers)
14004 (mapconcat 'identity gnus-ignored-headers
14005 "\\|")))))
14006 (visible
14007 (cond ((stringp gnus-visible-headers)
14008 gnus-visible-headers)
14009 ((and gnus-visible-headers
14010 (listp gnus-visible-headers))
14011 (mapconcat 'identity gnus-visible-headers "\\|"))))
14012 (inhibit-point-motion-hooks t)
14013 want-list beg)
14014 ;; First we narrow to just the headers.
14015 (widen)
14016 (goto-char (point-min))
14017 ;; Hide any "From " lines at the beginning of (mail) articles.
14018 (while (looking-at "From ")
14019 (forward-line 1))
14020 (unless (bobp)
14021 (if delete
14022 (delete-region (point-min) (point))
14023 (gnus-hide-text (point-min) (point) props)))
14024 ;; Then treat the rest of the header lines.
14025 (narrow-to-region
14026 (point)
14027 (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
14028 ;; Then we use the two regular expressions
14029 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
14030 ;; select which header lines is to remain visible in the
14031 ;; article buffer.
14032 (goto-char (point-min))
14033 (while (re-search-forward "^[^ \t]*:" nil t)
14034 (beginning-of-line)
14035 ;; We add the headers we want to keep to a list and delete
14036 ;; them from the buffer.
14037 (gnus-put-text-property
14038 (point) (1+ (point)) 'message-rank
14039 (if (or (and visible (looking-at visible))
14040 (and ignored
14041 (not (looking-at ignored))))
14042 (gnus-article-header-rank)
14043 (+ 2 max)))
14044 (forward-line 1))
14045 (message-sort-headers-1)
14046 (when (setq beg (text-property-any
14047 (point-min) (point-max) 'message-rank (+ 2 max)))
14048 ;; We make the unwanted headers invisible.
14049 (if delete
14050 (delete-region beg (point-max))
14051 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
14052 (gnus-hide-text-type beg (point-max) 'headers))
14053 ;; Work around XEmacs lossage.
14054 (gnus-put-text-property (point-min) beg 'invisible nil))))))))
14055
14056 (defun gnus-article-hide-boring-headers (&optional arg)
14057 "Toggle hiding of headers that aren't very interesting.
14058 If given a negative prefix, always show; if given a positive prefix,
14059 always hide."
14060 (interactive (gnus-hidden-arg))
14061 (unless (gnus-article-check-hidden-text 'boring-headers arg)
14062 (save-excursion
14063 (set-buffer gnus-article-buffer)
14064 (save-restriction
14065 (let ((buffer-read-only nil)
14066 (list gnus-boring-article-headers)
14067 (inhibit-point-motion-hooks t)
14068 elem)
14069 (nnheader-narrow-to-headers)
14070 (while list
14071 (setq elem (pop list))
14072 (goto-char (point-min))
14073 (cond
14074 ;; Hide empty headers.
14075 ((eq elem 'empty)
14076 (while (re-search-forward "^[^:]+:[ \t]\n[^ \t]" nil t)
14077 (forward-line -1)
14078 (gnus-hide-text-type
14079 (progn (beginning-of-line) (point))
14080 (progn
14081 (end-of-line)
14082 (if (re-search-forward "^[^ \t]" nil t)
14083 (match-beginning 0)
14084 (point-max)))
14085 'boring-headers)))
14086 ;; Hide boring Newsgroups header.
14087 ((eq elem 'newsgroups)
14088 (when (equal (message-fetch-field "newsgroups")
14089 (gnus-group-real-name gnus-newsgroup-name))
14090 (gnus-article-hide-header "newsgroups")))
14091 ((eq elem 'followup-to)
14092 (when (equal (message-fetch-field "followup-to")
14093 (message-fetch-field "newsgroups"))
14094 (gnus-article-hide-header "followup-to")))
14095 ((eq elem 'reply-to)
14096 (let ((from (message-fetch-field "from"))
14097 (reply-to (message-fetch-field "reply-to")))
14098 (when (and
14099 from reply-to
14100 (equal
14101 (nth 1 (funcall gnus-extract-address-components from))
14102 (nth 1 (funcall gnus-extract-address-components
14103 reply-to))))
14104 (gnus-article-hide-header "reply-to"))))
14105 ((eq elem 'date)
14106 (let ((date (message-fetch-field "date")))
14107 (when (and date
14108 (< (gnus-days-between date (current-time-string))
14109 4))
14110 (gnus-article-hide-header "date")))))))))))
14111
14112 (defun gnus-article-hide-header (header)
14113 (save-excursion
14114 (goto-char (point-min))
14115 (when (re-search-forward (concat "^" header ":") nil t)
14116 (gnus-hide-text-type
14117 (progn (beginning-of-line) (point))
14118 (progn
14119 (end-of-line)
14120 (if (re-search-forward "^[^ \t]" nil t)
14121 (match-beginning 0)
14122 (point-max)))
14123 'boring-headers))))
14124
14125 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
14126 (defun gnus-article-treat-overstrike ()
14127 "Translate overstrikes into bold text."
14128 (interactive)
14129 (save-excursion
14130 (set-buffer gnus-article-buffer)
14131 (let ((buffer-read-only nil))
14132 (while (search-forward "\b" nil t)
14133 (let ((next (following-char))
14134 (previous (char-after (- (point) 2))))
14135 (cond
14136 ((eq next previous)
14137 (gnus-put-text-property (- (point) 2) (point) 'invisible t)
14138 (gnus-put-text-property (point) (1+ (point)) 'face 'bold))
14139 ((eq next ?_)
14140 (gnus-put-text-property (1- (point)) (1+ (point)) 'invisible t)
14141 (gnus-put-text-property
14142 (- (point) 2) (1- (point)) 'face 'underline))
14143 ((eq previous ?_)
14144 (gnus-put-text-property (- (point) 2) (point) 'invisible t)
14145 (gnus-put-text-property
14146 (point) (1+ (point)) 'face 'underline))))))))
14147
14148 (defun gnus-article-word-wrap ()
14149 "Format too long lines."
14150 (interactive)
14151 (save-excursion
14152 (set-buffer gnus-article-buffer)
14153 (let ((buffer-read-only nil))
14154 (widen)
14155 (goto-char (point-min))
14156 (search-forward "\n\n" nil t)
14157 (end-of-line 1)
14158 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
14159 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
14160 (adaptive-fill-mode t))
14161 (while (not (eobp))
14162 (and (>= (current-column) (min fill-column (window-width)))
14163 (/= (preceding-char) ?:)
14164 (fill-paragraph nil))
14165 (end-of-line 2))))))
14166
14167 (defun gnus-article-remove-cr ()
14168 "Remove carriage returns from an article."
14169 (interactive)
14170 (save-excursion
14171 (set-buffer gnus-article-buffer)
14172 (let ((buffer-read-only nil))
14173 (goto-char (point-min))
14174 (while (search-forward "\r" nil t)
14175 (replace-match "" t t)))))
14176
14177 (defun gnus-article-remove-trailing-blank-lines ()
14178 "Remove all trailing blank lines from the article."
14179 (interactive)
14180 (save-excursion
14181 (set-buffer gnus-article-buffer)
14182 (let ((buffer-read-only nil))
14183 (goto-char (point-max))
14184 (delete-region
14185 (point)
14186 (progn
14187 (while (looking-at "^[ \t]*$")
14188 (forward-line -1))
14189 (forward-line 1)
14190 (point))))))
14191
14192 (defun gnus-article-display-x-face (&optional force)
14193 "Look for an X-Face header and display it if present."
14194 (interactive (list 'force))
14195 (save-excursion
14196 (set-buffer gnus-article-buffer)
14197 ;; Delete the old process, if any.
14198 (when (process-status "gnus-x-face")
14199 (delete-process "gnus-x-face"))
14200 (let ((inhibit-point-motion-hooks t)
14201 (case-fold-search nil)
14202 from)
14203 (save-restriction
14204 (nnheader-narrow-to-headers)
14205 (setq from (message-fetch-field "from"))
14206 (goto-char (point-min))
14207 (when (and gnus-article-x-face-command
14208 (or force
14209 ;; Check whether this face is censored.
14210 (not gnus-article-x-face-too-ugly)
14211 (and gnus-article-x-face-too-ugly from
14212 (not (string-match gnus-article-x-face-too-ugly
14213 from))))
14214 ;; Has to be present.
14215 (re-search-forward "^X-Face: " nil t))
14216 ;; We now have the area of the buffer where the X-Face is stored.
14217 (let ((beg (point))
14218 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
14219 ;; We display the face.
14220 (if (symbolp gnus-article-x-face-command)
14221 ;; The command is a lisp function, so we call it.
14222 (if (gnus-functionp gnus-article-x-face-command)
14223 (funcall gnus-article-x-face-command beg end)
14224 (error "%s is not a function" gnus-article-x-face-command))
14225 ;; The command is a string, so we interpret the command
14226 ;; as a, well, command, and fork it off.
14227 (let ((process-connection-type nil))
14228 (process-kill-without-query
14229 (start-process
14230 "gnus-x-face" nil shell-file-name shell-command-switch
14231 gnus-article-x-face-command))
14232 (process-send-region "gnus-x-face" beg end)
14233 (process-send-eof "gnus-x-face")))))))))
14234
14235 (defalias 'gnus-headers-decode-quoted-printable 'gnus-decode-rfc1522)
14236 (defun gnus-decode-rfc1522 ()
14237 "Hack to remove QP encoding from headers."
14238 (let ((case-fold-search t)
14239 (inhibit-point-motion-hooks t)
14240 (buffer-read-only nil)
14241 string)
14242 (save-restriction
14243 (narrow-to-region
14244 (goto-char (point-min))
14245 (or (search-forward "\n\n" nil t) (point-max)))
14246
14247 (goto-char (point-min))
14248 (while (re-search-forward
14249 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
14250 (setq string (match-string 1))
14251 (narrow-to-region (match-beginning 0) (match-end 0))
14252 (delete-region (point-min) (point-max))
14253 (insert string)
14254 (gnus-mime-decode-quoted-printable (goto-char (point-min)) (point-max))
14255 (subst-char-in-region (point-min) (point-max) ?_ ? )
14256 (widen)
14257 (goto-char (point-min))))))
14258
14259 (defun gnus-article-de-quoted-unreadable (&optional force)
14260 "Do a naive translation of a quoted-printable-encoded article.
14261 This is in no way, shape or form meant as a replacement for real MIME
14262 processing, but is simply a stop-gap measure until MIME support is
14263 written.
14264 If FORCE, decode the article whether it is marked as quoted-printable
14265 or not."
14266 (interactive (list 'force))
14267 (save-excursion
14268 (set-buffer gnus-article-buffer)
14269 (let ((case-fold-search t)
14270 (buffer-read-only nil)
14271 (type (gnus-fetch-field "content-transfer-encoding")))
14272 (gnus-decode-rfc1522)
14273 (when (or force
14274 (and type (string-match "quoted-printable" (downcase type))))
14275 (goto-char (point-min))
14276 (search-forward "\n\n" nil 'move)
14277 (gnus-mime-decode-quoted-printable (point) (point-max))))))
14278
14279 (defun gnus-mime-decode-quoted-printable (from to)
14280 "Decode Quoted-Printable in the region between FROM and TO."
14281 (interactive "r")
14282 (goto-char from)
14283 (while (search-forward "=" to t)
14284 (cond ((eq (following-char) ?\n)
14285 (delete-char -1)
14286 (delete-char 1))
14287 ((looking-at "[0-9A-F][0-9A-F]")
14288 (subst-char-in-region
14289 (1- (point)) (point) ?=
14290 (hexl-hex-string-to-integer
14291 (buffer-substring (point) (+ 2 (point)))))
14292 (delete-char 2))
14293 ((looking-at "=")
14294 (delete-char 1))
14295 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
14296
14297 (defun gnus-article-hide-pgp (&optional arg)
14298 "Toggle hiding of any PGP headers and signatures in the current article.
14299 If given a negative prefix, always show; if given a positive prefix,
14300 always hide."
14301 (interactive (gnus-hidden-arg))
14302 (unless (gnus-article-check-hidden-text 'pgp arg)
14303 (save-excursion
14304 (set-buffer gnus-article-buffer)
14305 (let ((props (nconc (list 'gnus-type 'pgp) gnus-hidden-properties))
14306 buffer-read-only beg end)
14307 (widen)
14308 (goto-char (point-min))
14309 ;; Hide the "header".
14310 (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
14311 (gnus-hide-text (match-beginning 0) (match-end 0) props))
14312 (setq beg (point))
14313 ;; Hide the actual signature.
14314 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
14315 (setq end (1+ (match-beginning 0)))
14316 (gnus-hide-text
14317 end
14318 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
14319 (match-end 0)
14320 ;; Perhaps we shouldn't hide to the end of the buffer
14321 ;; if there is no end to the signature?
14322 (point-max))
14323 props))
14324 ;; Hide "- " PGP quotation markers.
14325 (when (and beg end)
14326 (narrow-to-region beg end)
14327 (goto-char (point-min))
14328 (while (re-search-forward "^- " nil t)
14329 (gnus-hide-text (match-beginning 0) (match-end 0) props))
14330 (widen))))))
14331
14332 (defun gnus-article-hide-signature (&optional arg)
14333 "Hide the signature in the current article.
14334 If given a negative prefix, always show; if given a positive prefix,
14335 always hide."
14336 (interactive (gnus-hidden-arg))
14337 (unless (gnus-article-check-hidden-text 'signature arg)
14338 (save-excursion
14339 (set-buffer gnus-article-buffer)
14340 (save-restriction
14341 (let ((buffer-read-only nil))
14342 (when (gnus-narrow-to-signature)
14343 (gnus-hide-text-type (point-min) (point-max) 'signature)))))))
14344
14345 (defun gnus-article-strip-leading-blank-lines ()
14346 "Remove all blank lines from the beginning of the article."
14347 (interactive)
14348 (save-excursion
14349 (set-buffer gnus-article-buffer)
14350 (let (buffer-read-only)
14351 (goto-char (point-min))
14352 (when (search-forward "\n\n" nil t)
14353 (while (looking-at "[ \t]$")
14354 (gnus-delete-line))))))
14355
14356 (defvar mime::preview/content-list)
14357 (defvar mime::preview-content-info/point-min)
14358 (defun gnus-narrow-to-signature ()
14359 "Narrow to the signature."
14360 (widen)
14361 (if (and (boundp 'mime::preview/content-list)
14362 mime::preview/content-list)
14363 (let ((pcinfo (car (last mime::preview/content-list))))
14364 (condition-case ()
14365 (narrow-to-region
14366 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
14367 (point-max))
14368 (error nil))))
14369 (goto-char (point-max))
14370 (when (re-search-backward gnus-signature-separator nil t)
14371 (forward-line 1)
14372 (when (or (null gnus-signature-limit)
14373 (and (numberp gnus-signature-limit)
14374 (< (- (point-max) (point)) gnus-signature-limit))
14375 (and (gnus-functionp gnus-signature-limit)
14376 (funcall gnus-signature-limit))
14377 (and (stringp gnus-signature-limit)
14378 (not (re-search-forward gnus-signature-limit nil t))))
14379 (narrow-to-region (point) (point-max))
14380 t)))
14381
14382 (defun gnus-hidden-arg ()
14383 "Return the current prefix arg as a number, or 0 if no prefix."
14384 (list (if current-prefix-arg
14385 (prefix-numeric-value current-prefix-arg)
14386 0)))
14387
14388 (defun gnus-article-check-hidden-text (type arg)
14389 "Return nil if hiding is necessary.
14390 Arg can be nil or a number. Nil and positive means hide, negative
14391 means show, 0 means toggle."
14392 (save-excursion
14393 (set-buffer gnus-article-buffer)
14394 (let ((hide (gnus-article-hidden-text-p type)))
14395 (cond
14396 ((or (null arg)
14397 (> arg 0))
14398 nil)
14399 ((< arg 0)
14400 (gnus-article-show-hidden-text type))
14401 (t
14402 (if (eq hide 'hidden)
14403 (gnus-article-show-hidden-text type)
14404 nil))))))
14405
14406 (defun gnus-article-hidden-text-p (type)
14407 "Say whether the current buffer contains hidden text of type TYPE."
14408 (let ((pos (text-property-any (point-min) (point-max) 'gnus-type type)))
14409 (when pos
14410 (if (get-text-property pos 'invisible)
14411 'hidden
14412 'shown))))
14413
14414 (defun gnus-article-hide (&optional arg force)
14415 "Hide all the gruft in the current article.
14416 This means that PGP stuff, signatures, cited text and (some)
14417 headers will be hidden.
14418 If given a prefix, show the hidden text instead."
14419 (interactive (list current-prefix-arg 'force))
14420 (gnus-article-hide-headers arg)
14421 (gnus-article-hide-pgp arg)
14422 (gnus-article-hide-citation-maybe arg force)
14423 (gnus-article-hide-signature arg))
14424
14425 (defun gnus-article-show-hidden-text (type &optional hide)
14426 "Show all hidden text of type TYPE.
14427 If HIDE, hide the text instead."
14428 (save-excursion
14429 (set-buffer gnus-article-buffer)
14430 (let ((buffer-read-only nil)
14431 (inhibit-point-motion-hooks t)
14432 (beg (point-min)))
14433 (while (gnus-goto-char (text-property-any
14434 beg (point-max) 'gnus-type type))
14435 (setq beg (point))
14436 (forward-char)
14437 (if hide
14438 (gnus-hide-text beg (point) gnus-hidden-properties)
14439 (gnus-unhide-text beg (point)))
14440 (setq beg (point)))
14441 t)))
14442
14443 (defvar gnus-article-time-units
14444 `((year . ,(* 365.25 24 60 60))
14445 (week . ,(* 7 24 60 60))
14446 (day . ,(* 24 60 60))
14447 (hour . ,(* 60 60))
14448 (minute . 60)
14449 (second . 1))
14450 "Mapping from time units to seconds.")
14451
14452 (defun gnus-article-date-ut (&optional type highlight)
14453 "Convert DATE date to universal time in the current article.
14454 If TYPE is `local', convert to local time; if it is `lapsed', output
14455 how much time has lapsed since DATE."
14456 (interactive (list 'ut t))
14457 (let* ((header (or gnus-current-headers
14458 (gnus-summary-article-header) ""))
14459 (date (and (vectorp header) (mail-header-date header)))
14460 (date-regexp "^Date: \\|^X-Sent: ")
14461 (now (current-time))
14462 (inhibit-point-motion-hooks t)
14463 bface eface)
14464 (when (and date (not (string= date "")))
14465 (save-excursion
14466 (set-buffer gnus-article-buffer)
14467 (save-restriction
14468 (nnheader-narrow-to-headers)
14469 (let ((buffer-read-only nil))
14470 ;; Delete any old Date headers.
14471 (if (re-search-forward date-regexp nil t)
14472 (progn
14473 (setq bface (get-text-property (gnus-point-at-bol) 'face)
14474 eface (get-text-property (1- (gnus-point-at-eol))
14475 'face))
14476 (message-remove-header date-regexp t)
14477 (beginning-of-line))
14478 (goto-char (point-max)))
14479 (insert (gnus-make-date-line date type))
14480 ;; Do highlighting.
14481 (forward-line -1)
14482 (when (and (gnus-visual-p 'article-highlight 'highlight)
14483 (looking-at "\\([^:]+\\): *\\(.*\\)$"))
14484 (gnus-put-text-property (match-beginning 1) (match-end 1)
14485 'face bface)
14486 (gnus-put-text-property (match-beginning 2) (match-end 2)
14487 'face eface))))))))
14488
14489 (defun gnus-make-date-line (date type)
14490 "Return a DATE line of TYPE."
14491 (cond
14492 ;; Convert to the local timezone. We have to slap a
14493 ;; `condition-case' round the calls to the timezone
14494 ;; functions since they aren't particularly resistant to
14495 ;; buggy dates.
14496 ((eq type 'local)
14497 (concat "Date: " (condition-case ()
14498 (timezone-make-date-arpa-standard date)
14499 (error date))
14500 "\n"))
14501 ;; Convert to Universal Time.
14502 ((eq type 'ut)
14503 (concat "Date: "
14504 (condition-case ()
14505 (timezone-make-date-arpa-standard date nil "UT")
14506 (error date))
14507 "\n"))
14508 ;; Get the original date from the article.
14509 ((eq type 'original)
14510 (concat "Date: " date "\n"))
14511 ;; Do an X-Sent lapsed format.
14512 ((eq type 'lapsed)
14513 ;; If the date is seriously mangled, the timezone
14514 ;; functions are liable to bug out, so we condition-case
14515 ;; the entire thing.
14516 (let* ((now (current-time))
14517 (real-time
14518 (condition-case ()
14519 (gnus-time-minus
14520 (gnus-encode-date
14521 (timezone-make-date-arpa-standard
14522 (current-time-string now)
14523 (current-time-zone now) "UT"))
14524 (gnus-encode-date
14525 (timezone-make-date-arpa-standard
14526 date nil "UT")))
14527 (error '(0 0))))
14528 (real-sec (+ (* (float (car real-time)) 65536)
14529 (cadr real-time)))
14530 (sec (abs real-sec))
14531 num prev)
14532 (cond
14533 ((equal real-time '(0 0))
14534 "X-Sent: Unknown\n")
14535 ((zerop sec)
14536 "X-Sent: Now\n")
14537 (t
14538 (concat
14539 "X-Sent: "
14540 ;; This is a bit convoluted, but basically we go
14541 ;; through the time units for years, weeks, etc,
14542 ;; and divide things to see whether that results
14543 ;; in positive answers.
14544 (mapconcat
14545 (lambda (unit)
14546 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
14547 ;; The (remaining) seconds are too few to
14548 ;; be divided into this time unit.
14549 ""
14550 ;; It's big enough, so we output it.
14551 (setq sec (- sec (* num (cdr unit))))
14552 (prog1
14553 (concat (if prev ", " "") (int-to-string
14554 (floor num))
14555 " " (symbol-name (car unit))
14556 (if (> num 1) "s" ""))
14557 (setq prev t))))
14558 gnus-article-time-units "")
14559 ;; If dates are odd, then it might appear like the
14560 ;; article was sent in the future.
14561 (if (> real-sec 0)
14562 " ago\n"
14563 " in the future\n"))))))
14564 (t
14565 (error "Unknown conversion type: %s" type))))
14566
14567 (defun gnus-article-date-local (&optional highlight)
14568 "Convert the current article date to the local timezone."
14569 (interactive (list t))
14570 (gnus-article-date-ut 'local highlight))
14571
14572 (defun gnus-article-date-original (&optional highlight)
14573 "Convert the current article date to what it was originally.
14574 This is only useful if you have used some other date conversion
14575 function and want to see what the date was before converting."
14576 (interactive (list t))
14577 (gnus-article-date-ut 'original highlight))
14578
14579 (defun gnus-article-date-lapsed (&optional highlight)
14580 "Convert the current article date to time lapsed since it was sent."
14581 (interactive (list t))
14582 (gnus-article-date-ut 'lapsed highlight))
14583
14584 (defun gnus-article-maybe-highlight ()
14585 "Do some article highlighting if `gnus-visual' is non-nil."
14586 (if (gnus-visual-p 'article-highlight 'highlight)
14587 (gnus-article-highlight-some)))
14588
14589 ;;; Article savers.
14590
14591 (defun gnus-output-to-rmail (file-name)
14592 "Append the current article to an Rmail file named FILE-NAME."
14593 (require 'rmail)
14594 ;; Most of these codes are borrowed from rmailout.el.
14595 (setq file-name (expand-file-name file-name))
14596 (setq rmail-default-rmail-file file-name)
14597 (let ((artbuf (current-buffer))
14598 (tmpbuf (get-buffer-create " *Gnus-output*")))
14599 (save-excursion
14600 (or (get-file-buffer file-name)
14601 (file-exists-p file-name)
14602 (if (gnus-yes-or-no-p
14603 (concat "\"" file-name "\" does not exist, create it? "))
14604 (let ((file-buffer (create-file-buffer file-name)))
14605 (save-excursion
14606 (set-buffer file-buffer)
14607 (rmail-insert-rmail-file-header)
14608 (let ((require-final-newline nil))
14609 (write-region (point-min) (point-max) file-name t 1)))
14610 (kill-buffer file-buffer))
14611 (error "Output file does not exist")))
14612 (set-buffer tmpbuf)
14613 (buffer-disable-undo (current-buffer))
14614 (erase-buffer)
14615 (insert-buffer-substring artbuf)
14616 (gnus-convert-article-to-rmail)
14617 ;; Decide whether to append to a file or to an Emacs buffer.
14618 (let ((outbuf (get-file-buffer file-name)))
14619 (if (not outbuf)
14620 (append-to-file (point-min) (point-max) file-name)
14621 ;; File has been visited, in buffer OUTBUF.
14622 (set-buffer outbuf)
14623 (let ((buffer-read-only nil)
14624 (msg (and (boundp 'rmail-current-message)
14625 (symbol-value 'rmail-current-message))))
14626 ;; If MSG is non-nil, buffer is in RMAIL mode.
14627 (if msg
14628 (progn (widen)
14629 (narrow-to-region (point-max) (point-max))))
14630 (insert-buffer-substring tmpbuf)
14631 (if msg
14632 (progn
14633 (goto-char (point-min))
14634 (widen)
14635 (search-backward "\^_")
14636 (narrow-to-region (point) (point-max))
14637 (goto-char (1+ (point-min)))
14638 (rmail-count-new-messages t)
14639 (rmail-show-message msg)))))))
14640 (kill-buffer tmpbuf)))
14641
14642 (defun gnus-output-to-file (file-name)
14643 "Append the current article to a file named FILE-NAME."
14644 (let ((artbuf (current-buffer)))
14645 (nnheader-temp-write nil
14646 (insert-buffer-substring artbuf)
14647 ;; Append newline at end of the buffer as separator, and then
14648 ;; save it to file.
14649 (goto-char (point-max))
14650 (insert "\n")
14651 (append-to-file (point-min) (point-max) file-name))))
14652
14653 (defun gnus-convert-article-to-rmail ()
14654 "Convert article in current buffer to Rmail message format."
14655 (let ((buffer-read-only nil))
14656 ;; Convert article directly into Babyl format.
14657 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
14658 (goto-char (point-min))
14659 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
14660 (while (search-forward "\n\^_" nil t) ;single char
14661 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
14662 (goto-char (point-max))
14663 (insert "\^_")))
14664
14665 (defun gnus-narrow-to-page (&optional arg)
14666 "Narrow the article buffer to a page.
14667 If given a numerical ARG, move forward ARG pages."
14668 (interactive "P")
14669 (setq arg (if arg (prefix-numeric-value arg) 0))
14670 (save-excursion
14671 (set-buffer gnus-article-buffer)
14672 (goto-char (point-min))
14673 (widen)
14674 (when (gnus-visual-p 'page-marker)
14675 (let ((buffer-read-only nil))
14676 (gnus-remove-text-with-property 'gnus-prev)
14677 (gnus-remove-text-with-property 'gnus-next)))
14678 (when
14679 (cond ((< arg 0)
14680 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
14681 ((> arg 0)
14682 (re-search-forward page-delimiter nil 'move arg)))
14683 (goto-char (match-end 0)))
14684 (narrow-to-region
14685 (point)
14686 (if (re-search-forward page-delimiter nil 'move)
14687 (match-beginning 0)
14688 (point)))
14689 (when (and (gnus-visual-p 'page-marker)
14690 (not (= (point-min) 1)))
14691 (save-excursion
14692 (goto-char (point-min))
14693 (gnus-insert-prev-page-button)))
14694 (when (and (gnus-visual-p 'page-marker)
14695 (not (= (1- (point-max)) (buffer-size))))
14696 (save-excursion
14697 (goto-char (point-max))
14698 (gnus-insert-next-page-button)))))
14699
14700 ;; Article mode commands
14701
14702 (defun gnus-article-goto-next-page ()
14703 "Show the next page of the article."
14704 (interactive)
14705 (when (gnus-article-next-page)
14706 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
14707
14708 (defun gnus-article-goto-prev-page ()
14709 "Show the next page of the article."
14710 (interactive)
14711 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
14712 (gnus-article-prev-page nil)))
14713
14714 (defun gnus-article-next-page (&optional lines)
14715 "Show the next page of the current article.
14716 If end of article, return non-nil. Otherwise return nil.
14717 Argument LINES specifies lines to be scrolled up."
14718 (interactive "p")
14719 (move-to-window-line -1)
14720 ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
14721 (if (save-excursion
14722 (end-of-line)
14723 (and (pos-visible-in-window-p) ;Not continuation line.
14724 (eobp)))
14725 ;; Nothing in this page.
14726 (if (or (not gnus-break-pages)
14727 (save-excursion
14728 (save-restriction
14729 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
14730 t ;Nothing more.
14731 (gnus-narrow-to-page 1) ;Go to next page.
14732 nil)
14733 ;; More in this page.
14734 (condition-case ()
14735 (scroll-up lines)
14736 (end-of-buffer
14737 ;; Long lines may cause an end-of-buffer error.
14738 (goto-char (point-max))))
14739 (move-to-window-line 0)
14740 nil))
14741
14742 (defun gnus-article-prev-page (&optional lines)
14743 "Show previous page of current article.
14744 Argument LINES specifies lines to be scrolled down."
14745 (interactive "p")
14746 (move-to-window-line 0)
14747 (if (and gnus-break-pages
14748 (bobp)
14749 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
14750 (progn
14751 (gnus-narrow-to-page -1) ;Go to previous page.
14752 (goto-char (point-max))
14753 (recenter -1))
14754 (prog1
14755 (condition-case ()
14756 (scroll-down lines)
14757 (error nil))
14758 (move-to-window-line 0))))
14759
14760 (defun gnus-article-refer-article ()
14761 "Read article specified by message-id around point."
14762 (interactive)
14763 (let ((point (point)))
14764 (search-forward ">" nil t) ;Move point to end of "<....>".
14765 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
14766 (let ((message-id (match-string 1)))
14767 (goto-char point)
14768 (set-buffer gnus-summary-buffer)
14769 (gnus-summary-refer-article message-id))
14770 (goto-char (point))
14771 (error "No references around point"))))
14772
14773 (defun gnus-article-show-summary ()
14774 "Reconfigure windows to show summary buffer."
14775 (interactive)
14776 (gnus-configure-windows 'article)
14777 (gnus-summary-goto-subject gnus-current-article))
14778
14779 (defun gnus-article-describe-briefly ()
14780 "Describe article mode commands briefly."
14781 (interactive)
14782 (gnus-message 6
14783 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
14784
14785 (defun gnus-article-summary-command ()
14786 "Execute the last keystroke in the summary buffer."
14787 (interactive)
14788 (let ((obuf (current-buffer))
14789 (owin (current-window-configuration))
14790 func)
14791 (switch-to-buffer gnus-summary-buffer 'norecord)
14792 (setq func (lookup-key (current-local-map) (this-command-keys)))
14793 (call-interactively func)
14794 (set-buffer obuf)
14795 (set-window-configuration owin)
14796 (set-window-point (get-buffer-window (current-buffer)) (point))))
14797
14798 (defun gnus-article-summary-command-nosave ()
14799 "Execute the last keystroke in the summary buffer."
14800 (interactive)
14801 (let (func)
14802 (pop-to-buffer gnus-summary-buffer 'norecord)
14803 (setq func (lookup-key (current-local-map) (this-command-keys)))
14804 (call-interactively func)))
14805
14806 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
14807 "Read a summary buffer key sequence and execute it from the article buffer."
14808 (interactive "P")
14809 (let ((nosaves
14810 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
14811 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
14812 "=" "^" "\M-^" "|"))
14813 (nosave-but-article
14814 '("A\r"))
14815 keys)
14816 (save-excursion
14817 (set-buffer gnus-summary-buffer)
14818 (push (or key last-command-event) unread-command-events)
14819 (setq keys (read-key-sequence nil)))
14820 (message "")
14821
14822 (if (or (member keys nosaves)
14823 (member keys nosave-but-article))
14824 (let (func)
14825 (save-window-excursion
14826 (pop-to-buffer gnus-summary-buffer 'norecord)
14827 (setq func (lookup-key (current-local-map) keys)))
14828 (if (not func)
14829 (ding)
14830 (set-buffer gnus-summary-buffer)
14831 (call-interactively func))
14832 (when (member keys nosave-but-article)
14833 (pop-to-buffer gnus-article-buffer 'norecord)))
14834 (let ((obuf (current-buffer))
14835 (owin (current-window-configuration))
14836 (opoint (point))
14837 func in-buffer)
14838 (if not-restore-window
14839 (pop-to-buffer gnus-summary-buffer 'norecord)
14840 (switch-to-buffer gnus-summary-buffer 'norecord))
14841 (setq in-buffer (current-buffer))
14842 (if (setq func (lookup-key (current-local-map) keys))
14843 (call-interactively func)
14844 (ding))
14845 (when (eq in-buffer (current-buffer))
14846 (set-buffer obuf)
14847 (unless not-restore-window
14848 (set-window-configuration owin))
14849 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
14850
14851 \f
14852 ;;;
14853 ;;; Kill file handling.
14854 ;;;
14855
14856 ;;;###autoload
14857 (defalias 'gnus-batch-kill 'gnus-batch-score)
14858 ;;;###autoload
14859 (defun gnus-batch-score ()
14860 "Run batched scoring.
14861 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
14862 Newsgroups is a list of strings in Bnews format. If you want to score
14863 the comp hierarchy, you'd say \"comp.all\". If you would not like to
14864 score the alt hierarchy, you'd say \"!alt.all\"."
14865 (interactive)
14866 (let* ((yes-and-no
14867 (gnus-newsrc-parse-options
14868 (apply (function concat)
14869 (mapcar (lambda (g) (concat g " "))
14870 command-line-args-left))))
14871 (gnus-expert-user t)
14872 (nnmail-spool-file nil)
14873 (gnus-use-dribble-file nil)
14874 (yes (car yes-and-no))
14875 (no (cdr yes-and-no))
14876 group newsrc entry
14877 ;; Disable verbose message.
14878 gnus-novice-user gnus-large-newsgroup)
14879 ;; Eat all arguments.
14880 (setq command-line-args-left nil)
14881 ;; Start Gnus.
14882 (gnus)
14883 ;; Apply kills to specified newsgroups in command line arguments.
14884 (setq newsrc (cdr gnus-newsrc-alist))
14885 (while newsrc
14886 (setq group (caar newsrc))
14887 (setq entry (gnus-gethash group gnus-newsrc-hashtb))
14888 (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
14889 (and (car entry)
14890 (or (eq (car entry) t)
14891 (not (zerop (car entry)))))
14892 (if yes (string-match yes group) t)
14893 (or (null no) (not (string-match no group))))
14894 (progn
14895 (gnus-summary-read-group group nil t nil t)
14896 (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
14897 (gnus-summary-exit))))
14898 (setq newsrc (cdr newsrc)))
14899 ;; Exit Emacs.
14900 (switch-to-buffer gnus-group-buffer)
14901 (gnus-group-save-newsrc)))
14902
14903 (defun gnus-apply-kill-file ()
14904 "Apply a kill file to the current newsgroup.
14905 Returns the number of articles marked as read."
14906 (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
14907 (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
14908 (gnus-apply-kill-file-internal)
14909 0))
14910
14911 (defun gnus-kill-save-kill-buffer ()
14912 (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
14913 (when (get-file-buffer file)
14914 (save-excursion
14915 (set-buffer (get-file-buffer file))
14916 (and (buffer-modified-p) (save-buffer))
14917 (kill-buffer (current-buffer))))))
14918
14919 (defvar gnus-kill-file-name "KILL"
14920 "Suffix of the kill files.")
14921
14922 (defun gnus-newsgroup-kill-file (newsgroup)
14923 "Return the name of a kill file name for NEWSGROUP.
14924 If NEWSGROUP is nil, return the global kill file name instead."
14925 (cond
14926 ;; The global KILL file is placed at top of the directory.
14927 ((or (null newsgroup)
14928 (string-equal newsgroup ""))
14929 (expand-file-name gnus-kill-file-name
14930 gnus-kill-files-directory))
14931 ;; Append ".KILL" to newsgroup name.
14932 ((gnus-use-long-file-name 'not-kill)
14933 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
14934 "." gnus-kill-file-name)
14935 gnus-kill-files-directory))
14936 ;; Place "KILL" under the hierarchical directory.
14937 (t
14938 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
14939 "/" gnus-kill-file-name)
14940 gnus-kill-files-directory))))
14941
14942 \f
14943 ;;;
14944 ;;; Dribble file
14945 ;;;
14946
14947 (defvar gnus-dribble-ignore nil)
14948 (defvar gnus-dribble-eval-file nil)
14949
14950 (defun gnus-dribble-file-name ()
14951 "Return the dribble file for the current .newsrc."
14952 (concat
14953 (if gnus-dribble-directory
14954 (concat (file-name-as-directory gnus-dribble-directory)
14955 (file-name-nondirectory gnus-current-startup-file))
14956 gnus-current-startup-file)
14957 "-dribble"))
14958
14959 (defun gnus-dribble-enter (string)
14960 "Enter STRING into the dribble buffer."
14961 (if (and (not gnus-dribble-ignore)
14962 gnus-dribble-buffer
14963 (buffer-name gnus-dribble-buffer))
14964 (let ((obuf (current-buffer)))
14965 (set-buffer gnus-dribble-buffer)
14966 (insert string "\n")
14967 (set-window-point (get-buffer-window (current-buffer)) (point-max))
14968 (bury-buffer gnus-dribble-buffer)
14969 (set-buffer obuf))))
14970
14971 (defun gnus-dribble-read-file ()
14972 "Read the dribble file from disk."
14973 (let ((dribble-file (gnus-dribble-file-name)))
14974 (save-excursion
14975 (set-buffer (setq gnus-dribble-buffer
14976 (get-buffer-create
14977 (file-name-nondirectory dribble-file))))
14978 (gnus-add-current-to-buffer-list)
14979 (erase-buffer)
14980 (setq buffer-file-name dribble-file)
14981 (auto-save-mode t)
14982 (buffer-disable-undo (current-buffer))
14983 (bury-buffer (current-buffer))
14984 (set-buffer-modified-p nil)
14985 (let ((auto (make-auto-save-file-name))
14986 (gnus-dribble-ignore t)
14987 modes)
14988 (when (or (file-exists-p auto) (file-exists-p dribble-file))
14989 ;; Load whichever file is newest -- the auto save file
14990 ;; or the "real" file.
14991 (if (file-newer-than-file-p auto dribble-file)
14992 (insert-file-contents auto)
14993 (insert-file-contents dribble-file))
14994 (unless (zerop (buffer-size))
14995 (set-buffer-modified-p t))
14996 ;; Set the file modes to reflect the .newsrc file modes.
14997 (save-buffer)
14998 (when (and (file-exists-p gnus-current-startup-file)
14999 (setq modes (file-modes gnus-current-startup-file)))
15000 (set-file-modes dribble-file modes))
15001 ;; Possibly eval the file later.
15002 (when (gnus-y-or-n-p
15003 "Auto-save file exists. Do you want to read it? ")
15004 (setq gnus-dribble-eval-file t)))))))
15005
15006 (defun gnus-dribble-eval-file ()
15007 (when gnus-dribble-eval-file
15008 (setq gnus-dribble-eval-file nil)
15009 (save-excursion
15010 (let ((gnus-dribble-ignore t))
15011 (set-buffer gnus-dribble-buffer)
15012 (eval-buffer (current-buffer))))))
15013
15014 (defun gnus-dribble-delete-file ()
15015 (when (file-exists-p (gnus-dribble-file-name))
15016 (delete-file (gnus-dribble-file-name)))
15017 (when gnus-dribble-buffer
15018 (save-excursion
15019 (set-buffer gnus-dribble-buffer)
15020 (let ((auto (make-auto-save-file-name)))
15021 (if (file-exists-p auto)
15022 (delete-file auto))
15023 (erase-buffer)
15024 (set-buffer-modified-p nil)))))
15025
15026 (defun gnus-dribble-save ()
15027 (when (and gnus-dribble-buffer
15028 (buffer-name gnus-dribble-buffer))
15029 (save-excursion
15030 (set-buffer gnus-dribble-buffer)
15031 (save-buffer))))
15032
15033 (defun gnus-dribble-clear ()
15034 (when (gnus-buffer-exists-p gnus-dribble-buffer)
15035 (save-excursion
15036 (set-buffer gnus-dribble-buffer)
15037 (erase-buffer)
15038 (set-buffer-modified-p nil)
15039 (setq buffer-saved-size (buffer-size)))))
15040
15041 \f
15042 ;;;
15043 ;;; Server Communication
15044 ;;;
15045
15046 (defun gnus-start-news-server (&optional confirm)
15047 "Open a method for getting news.
15048 If CONFIRM is non-nil, the user will be asked for an NNTP server."
15049 (let (how)
15050 (if gnus-current-select-method
15051 ;; Stream is already opened.
15052 nil
15053 ;; Open NNTP server.
15054 (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
15055 (if confirm
15056 (progn
15057 ;; Read server name with completion.
15058 (setq gnus-nntp-server
15059 (completing-read "NNTP server: "
15060 (mapcar (lambda (server) (list server))
15061 (cons (list gnus-nntp-server)
15062 gnus-secondary-servers))
15063 nil nil gnus-nntp-server))))
15064
15065 (if (and gnus-nntp-server
15066 (stringp gnus-nntp-server)
15067 (not (string= gnus-nntp-server "")))
15068 (setq gnus-select-method
15069 (cond ((or (string= gnus-nntp-server "")
15070 (string= gnus-nntp-server "::"))
15071 (list 'nnspool (system-name)))
15072 ((string-match "^:" gnus-nntp-server)
15073 (list 'nnmh gnus-nntp-server
15074 (list 'nnmh-directory
15075 (file-name-as-directory
15076 (expand-file-name
15077 (concat "~/" (substring
15078 gnus-nntp-server 1)))))
15079 (list 'nnmh-get-new-mail nil)))
15080 (t
15081 (list 'nntp gnus-nntp-server)))))
15082
15083 (setq how (car gnus-select-method))
15084 (cond ((eq how 'nnspool)
15085 (require 'nnspool)
15086 (gnus-message 5 "Looking up local news spool..."))
15087 ((eq how 'nnmh)
15088 (require 'nnmh)
15089 (gnus-message 5 "Looking up mh spool..."))
15090 (t
15091 (require 'nntp)))
15092 (setq gnus-current-select-method gnus-select-method)
15093 (run-hooks 'gnus-open-server-hook)
15094 (or
15095 ;; gnus-open-server-hook might have opened it
15096 (gnus-server-opened gnus-select-method)
15097 (gnus-open-server gnus-select-method)
15098 (gnus-y-or-n-p
15099 (format
15100 "%s (%s) open error: '%s'. Continue? "
15101 (car gnus-select-method) (cadr gnus-select-method)
15102 (gnus-status-message gnus-select-method)))
15103 (gnus-error 1 "Couldn't open server on %s"
15104 (nth 1 gnus-select-method))))))
15105
15106 (defun gnus-check-group (group)
15107 "Try to make sure that the server where GROUP exists is alive."
15108 (let ((method (gnus-find-method-for-group group)))
15109 (or (gnus-server-opened method)
15110 (gnus-open-server method))))
15111
15112 (defun gnus-check-server (&optional method silent)
15113 "Check whether the connection to METHOD is down.
15114 If METHOD is nil, use `gnus-select-method'.
15115 If it is down, start it up (again)."
15116 (let ((method (or method gnus-select-method)))
15117 ;; Transform virtual server names into select methods.
15118 (when (stringp method)
15119 (setq method (gnus-server-to-method method)))
15120 (if (gnus-server-opened method)
15121 ;; The stream is already opened.
15122 t
15123 ;; Open the server.
15124 (unless silent
15125 (gnus-message 5 "Opening %s server%s..." (car method)
15126 (if (equal (nth 1 method) "") ""
15127 (format " on %s" (nth 1 method)))))
15128 (run-hooks 'gnus-open-server-hook)
15129 (prog1
15130 (gnus-open-server method)
15131 (unless silent
15132 (message ""))))))
15133
15134 (defun gnus-get-function (method function &optional noerror)
15135 "Return a function symbol based on METHOD and FUNCTION."
15136 ;; Translate server names into methods.
15137 (unless method
15138 (error "Attempted use of a nil select method"))
15139 (when (stringp method)
15140 (setq method (gnus-server-to-method method)))
15141 (let ((func (intern (format "%s-%s" (car method) function))))
15142 ;; If the functions isn't bound, we require the backend in
15143 ;; question.
15144 (unless (fboundp func)
15145 (require (car method))
15146 (when (and (not (fboundp func))
15147 (not noerror))
15148 ;; This backend doesn't implement this function.
15149 (error "No such function: %s" func)))
15150 func))
15151
15152 \f
15153 ;;;
15154 ;;; Interface functions to the backends.
15155 ;;;
15156
15157 (defun gnus-open-server (method)
15158 "Open a connection to METHOD."
15159 (when (stringp method)
15160 (setq method (gnus-server-to-method method)))
15161 (let ((elem (assoc method gnus-opened-servers)))
15162 ;; If this method was previously denied, we just return nil.
15163 (if (eq (nth 1 elem) 'denied)
15164 (progn
15165 (gnus-message 1 "Denied server")
15166 nil)
15167 ;; Open the server.
15168 (let ((result
15169 (funcall (gnus-get-function method 'open-server)
15170 (nth 1 method) (nthcdr 2 method))))
15171 ;; If this hasn't been opened before, we add it to the list.
15172 (unless elem
15173 (setq elem (list method nil)
15174 gnus-opened-servers (cons elem gnus-opened-servers)))
15175 ;; Set the status of this server.
15176 (setcar (cdr elem) (if result 'ok 'denied))
15177 ;; Return the result from the "open" call.
15178 result))))
15179
15180 (defun gnus-close-server (method)
15181 "Close the connection to METHOD."
15182 (when (stringp method)
15183 (setq method (gnus-server-to-method method)))
15184 (funcall (gnus-get-function method 'close-server) (nth 1 method)))
15185
15186 (defun gnus-request-list (method)
15187 "Request the active file from METHOD."
15188 (when (stringp method)
15189 (setq method (gnus-server-to-method method)))
15190 (funcall (gnus-get-function method 'request-list) (nth 1 method)))
15191
15192 (defun gnus-request-list-newsgroups (method)
15193 "Request the newsgroups file from METHOD."
15194 (when (stringp method)
15195 (setq method (gnus-server-to-method method)))
15196 (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
15197
15198 (defun gnus-request-newgroups (date method)
15199 "Request all new groups since DATE from METHOD."
15200 (when (stringp method)
15201 (setq method (gnus-server-to-method method)))
15202 (funcall (gnus-get-function method 'request-newgroups)
15203 date (nth 1 method)))
15204
15205 (defun gnus-server-opened (method)
15206 "Check whether a connection to METHOD has been opened."
15207 (when (stringp method)
15208 (setq method (gnus-server-to-method method)))
15209 (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
15210
15211 (defun gnus-status-message (method)
15212 "Return the status message from METHOD.
15213 If METHOD is a string, it is interpreted as a group name. The method
15214 this group uses will be queried."
15215 (let ((method (if (stringp method) (gnus-find-method-for-group method)
15216 method)))
15217 (funcall (gnus-get-function method 'status-message) (nth 1 method))))
15218
15219 (defun gnus-request-group (group &optional dont-check method)
15220 "Request GROUP. If DONT-CHECK, no information is required."
15221 (let ((method (or method (gnus-find-method-for-group group))))
15222 (when (stringp method)
15223 (setq method (gnus-server-to-method method)))
15224 (funcall (gnus-get-function method 'request-group)
15225 (gnus-group-real-name group) (nth 1 method) dont-check)))
15226
15227 (defun gnus-request-asynchronous (group &optional articles)
15228 "Request that GROUP behave asynchronously.
15229 ARTICLES is the `data' of the group."
15230 (let ((method (gnus-find-method-for-group group)))
15231 (funcall (gnus-get-function method 'request-asynchronous)
15232 (gnus-group-real-name group) (nth 1 method) articles)))
15233
15234 (defun gnus-list-active-group (group)
15235 "Request active information on GROUP."
15236 (let ((method (gnus-find-method-for-group group))
15237 (func 'list-active-group))
15238 (when (gnus-check-backend-function func group)
15239 (funcall (gnus-get-function method func)
15240 (gnus-group-real-name group) (nth 1 method)))))
15241
15242 (defun gnus-request-group-description (group)
15243 "Request a description of GROUP."
15244 (let ((method (gnus-find-method-for-group group))
15245 (func 'request-group-description))
15246 (when (gnus-check-backend-function func group)
15247 (funcall (gnus-get-function method func)
15248 (gnus-group-real-name group) (nth 1 method)))))
15249
15250 (defun gnus-close-group (group)
15251 "Request the GROUP be closed."
15252 (let ((method (gnus-find-method-for-group group)))
15253 (funcall (gnus-get-function method 'close-group)
15254 (gnus-group-real-name group) (nth 1 method))))
15255
15256 (defun gnus-retrieve-headers (articles group &optional fetch-old)
15257 "Request headers for ARTICLES in GROUP.
15258 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
15259 (let ((method (gnus-find-method-for-group group)))
15260 (if (and gnus-use-cache (numberp (car articles)))
15261 (gnus-cache-retrieve-headers articles group fetch-old)
15262 (funcall (gnus-get-function method 'retrieve-headers)
15263 articles (gnus-group-real-name group) (nth 1 method)
15264 fetch-old))))
15265
15266 (defun gnus-retrieve-groups (groups method)
15267 "Request active information on GROUPS from METHOD."
15268 (when (stringp method)
15269 (setq method (gnus-server-to-method method)))
15270 (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
15271
15272 (defun gnus-request-type (group &optional article)
15273 "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
15274 (let ((method (gnus-find-method-for-group group)))
15275 (if (not (gnus-check-backend-function 'request-type (car method)))
15276 'unknown
15277 (funcall (gnus-get-function method 'request-type)
15278 (gnus-group-real-name group) article))))
15279
15280 (defun gnus-request-update-mark (group article mark)
15281 "Return the type (`post' or `mail') of GROUP (and ARTICLE)."
15282 (let ((method (gnus-find-method-for-group group)))
15283 (if (not (gnus-check-backend-function 'request-update-mark (car method)))
15284 mark
15285 (funcall (gnus-get-function method 'request-update-mark)
15286 (gnus-group-real-name group) article mark))))
15287
15288 (defun gnus-request-article (article group &optional buffer)
15289 "Request the ARTICLE in GROUP.
15290 ARTICLE can either be an article number or an article Message-ID.
15291 If BUFFER, insert the article in that group."
15292 (let ((method (gnus-find-method-for-group group)))
15293 (funcall (gnus-get-function method 'request-article)
15294 article (gnus-group-real-name group) (nth 1 method) buffer)))
15295
15296 (defun gnus-request-head (article group)
15297 "Request the head of ARTICLE in GROUP."
15298 (let* ((method (gnus-find-method-for-group group))
15299 (head (gnus-get-function method 'request-head t)))
15300 (if (fboundp head)
15301 (funcall head article (gnus-group-real-name group) (nth 1 method))
15302 (let ((res (gnus-request-article article group)))
15303 (when res
15304 (save-excursion
15305 (set-buffer nntp-server-buffer)
15306 (goto-char (point-min))
15307 (when (search-forward "\n\n" nil t)
15308 (delete-region (1- (point)) (point-max)))
15309 (nnheader-fold-continuation-lines)))
15310 res))))
15311
15312 (defun gnus-request-body (article group)
15313 "Request the body of ARTICLE in GROUP."
15314 (let ((method (gnus-find-method-for-group group)))
15315 (funcall (gnus-get-function method 'request-body)
15316 article (gnus-group-real-name group) (nth 1 method))))
15317
15318 (defun gnus-request-post (method)
15319 "Post the current buffer using METHOD."
15320 (when (stringp method)
15321 (setq method (gnus-server-to-method method)))
15322 (funcall (gnus-get-function method 'request-post) (nth 1 method)))
15323
15324 (defun gnus-request-scan (group method)
15325 "Request a SCAN being performed in GROUP from METHOD.
15326 If GROUP is nil, all groups on METHOD are scanned."
15327 (let ((method (if group (gnus-find-method-for-group group) method)))
15328 (funcall (gnus-get-function method 'request-scan)
15329 (and group (gnus-group-real-name group)) (nth 1 method))))
15330
15331 (defsubst gnus-request-update-info (info method)
15332 "Request that METHOD update INFO."
15333 (when (stringp method)
15334 (setq method (gnus-server-to-method method)))
15335 (when (gnus-check-backend-function 'request-update-info (car method))
15336 (funcall (gnus-get-function method 'request-update-info)
15337 (gnus-group-real-name (gnus-info-group info))
15338 info (nth 1 method))))
15339
15340 (defun gnus-request-expire-articles (articles group &optional force)
15341 (let ((method (gnus-find-method-for-group group)))
15342 (funcall (gnus-get-function method 'request-expire-articles)
15343 articles (gnus-group-real-name group) (nth 1 method)
15344 force)))
15345
15346 (defun gnus-request-move-article
15347 (article group server accept-function &optional last)
15348 (let ((method (gnus-find-method-for-group group)))
15349 (funcall (gnus-get-function method 'request-move-article)
15350 article (gnus-group-real-name group)
15351 (nth 1 method) accept-function last)))
15352
15353 (defun gnus-request-accept-article (group method &optional last)
15354 ;; Make sure there's a newline at the end of the article.
15355 (when (stringp method)
15356 (setq method (gnus-server-to-method method)))
15357 (when (and (not method)
15358 (stringp group))
15359 (setq method (gnus-group-name-to-method group)))
15360 (goto-char (point-max))
15361 (unless (bolp)
15362 (insert "\n"))
15363 (let ((func (car (or method (gnus-find-method-for-group group)))))
15364 (funcall (intern (format "%s-request-accept-article" func))
15365 (if (stringp group) (gnus-group-real-name group) group)
15366 (cadr method)
15367 last)))
15368
15369 (defun gnus-request-replace-article (article group buffer)
15370 (let ((func (car (gnus-find-method-for-group group))))
15371 (funcall (intern (format "%s-request-replace-article" func))
15372 article (gnus-group-real-name group) buffer)))
15373
15374 (defun gnus-request-associate-buffer (group)
15375 (let ((method (gnus-find-method-for-group group)))
15376 (funcall (gnus-get-function method 'request-associate-buffer)
15377 (gnus-group-real-name group))))
15378
15379 (defun gnus-request-restore-buffer (article group)
15380 "Request a new buffer restored to the state of ARTICLE."
15381 (let ((method (gnus-find-method-for-group group)))
15382 (funcall (gnus-get-function method 'request-restore-buffer)
15383 article (gnus-group-real-name group) (nth 1 method))))
15384
15385 (defun gnus-request-create-group (group &optional method)
15386 (when (stringp method)
15387 (setq method (gnus-server-to-method method)))
15388 (let ((method (or method (gnus-find-method-for-group group))))
15389 (funcall (gnus-get-function method 'request-create-group)
15390 (gnus-group-real-name group) (nth 1 method))))
15391
15392 (defun gnus-request-delete-group (group &optional force)
15393 (let ((method (gnus-find-method-for-group group)))
15394 (funcall (gnus-get-function method 'request-delete-group)
15395 (gnus-group-real-name group) force (nth 1 method))))
15396
15397 (defun gnus-request-rename-group (group new-name)
15398 (let ((method (gnus-find-method-for-group group)))
15399 (funcall (gnus-get-function method 'request-rename-group)
15400 (gnus-group-real-name group)
15401 (gnus-group-real-name new-name) (nth 1 method))))
15402
15403 (defun gnus-member-of-valid (symbol group)
15404 "Find out if GROUP has SYMBOL as part of its \"valid\" spec."
15405 (memq symbol (assoc
15406 (symbol-name (car (gnus-find-method-for-group group)))
15407 gnus-valid-select-methods)))
15408
15409 (defun gnus-method-option-p (method option)
15410 "Return non-nil if select METHOD has OPTION as a parameter."
15411 (when (stringp method)
15412 (setq method (gnus-server-to-method method)))
15413 (memq option (assoc (format "%s" (car method))
15414 gnus-valid-select-methods)))
15415
15416 (defun gnus-server-extend-method (group method)
15417 ;; This function "extends" a virtual server. If the server is
15418 ;; "hello", and the select method is ("hello" (my-var "something"))
15419 ;; in the group "alt.alt", this will result in a new virtual server
15420 ;; called "hello+alt.alt".
15421 (let ((entry
15422 (gnus-copy-sequence
15423 (if (equal (car method) "native") gnus-select-method
15424 (cdr (assoc (car method) gnus-server-alist))))))
15425 (setcar (cdr entry) (concat (nth 1 entry) "+" group))
15426 (nconc entry (cdr method))))
15427
15428 (defun gnus-server-status (method)
15429 "Return the status of METHOD."
15430 (nth 1 (assoc method gnus-opened-servers)))
15431
15432 (defun gnus-group-name-to-method (group)
15433 "Return a select method suitable for GROUP."
15434 (if (string-match ":" group)
15435 (let ((server (substring group 0 (match-beginning 0))))
15436 (if (string-match "\\+" server)
15437 (list (intern (substring server 0 (match-beginning 0)))
15438 (substring server (match-end 0)))
15439 (list (intern server) "")))
15440 gnus-select-method))
15441
15442 (defun gnus-find-method-for-group (group &optional info)
15443 "Find the select method that GROUP uses."
15444 (or gnus-override-method
15445 (and (not group)
15446 gnus-select-method)
15447 (let ((info (or info (gnus-get-info group)))
15448 method)
15449 (if (or (not info)
15450 (not (setq method (gnus-info-method info)))
15451 (equal method "native"))
15452 gnus-select-method
15453 (setq method
15454 (cond ((stringp method)
15455 (gnus-server-to-method method))
15456 ((stringp (car method))
15457 (gnus-server-extend-method group method))
15458 (t
15459 method)))
15460 (cond ((equal (cadr method) "")
15461 method)
15462 ((null (cadr method))
15463 (list (car method) ""))
15464 (t
15465 (gnus-server-add-address method)))))))
15466
15467 (defun gnus-check-backend-function (func group)
15468 "Check whether GROUP supports function FUNC."
15469 (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
15470 group)))
15471 (fboundp (intern (format "%s-%s" method func)))))
15472
15473 (defun gnus-methods-using (feature)
15474 "Find all methods that have FEATURE."
15475 (let ((valids gnus-valid-select-methods)
15476 outs)
15477 (while valids
15478 (if (memq feature (car valids))
15479 (setq outs (cons (car valids) outs)))
15480 (setq valids (cdr valids)))
15481 outs))
15482
15483 \f
15484 ;;;
15485 ;;; Active & Newsrc File Handling
15486 ;;;
15487
15488 (defun gnus-setup-news (&optional rawfile level dont-connect)
15489 "Setup news information.
15490 If RAWFILE is non-nil, the .newsrc file will also be read.
15491 If LEVEL is non-nil, the news will be set up at level LEVEL."
15492 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
15493
15494 (when init
15495 ;; Clear some variables to re-initialize news information.
15496 (setq gnus-newsrc-alist nil
15497 gnus-active-hashtb nil)
15498 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
15499 (gnus-read-newsrc-file rawfile))
15500
15501 (when (and (not (assoc "archive" gnus-server-alist))
15502 (gnus-archive-server-wanted-p))
15503 (push (cons "archive" gnus-message-archive-method)
15504 gnus-server-alist))
15505
15506 ;; If we don't read the complete active file, we fill in the
15507 ;; hashtb here.
15508 (if (or (null gnus-read-active-file)
15509 (eq gnus-read-active-file 'some))
15510 (gnus-update-active-hashtb-from-killed))
15511
15512 ;; Read the active file and create `gnus-active-hashtb'.
15513 ;; If `gnus-read-active-file' is nil, then we just create an empty
15514 ;; hash table. The partial filling out of the hash table will be
15515 ;; done in `gnus-get-unread-articles'.
15516 (and gnus-read-active-file
15517 (not level)
15518 (gnus-read-active-file))
15519
15520 (or gnus-active-hashtb
15521 (setq gnus-active-hashtb (make-vector 4095 0)))
15522
15523 ;; Initialize the cache.
15524 (when gnus-use-cache
15525 (gnus-cache-open))
15526
15527 ;; Possibly eval the dribble file.
15528 (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
15529
15530 ;; Slave Gnusii should then clear the dribble buffer.
15531 (when (and init gnus-slave)
15532 (gnus-dribble-clear))
15533
15534 (gnus-update-format-specifications)
15535
15536 ;; See whether we need to read the description file.
15537 (if (and (string-match "%[-,0-9]*D" gnus-group-line-format)
15538 (not gnus-description-hashtb)
15539 (not dont-connect)
15540 gnus-read-active-file)
15541 (gnus-read-all-descriptions-files))
15542
15543 ;; Find new newsgroups and treat them.
15544 (if (and init gnus-check-new-newsgroups (not level)
15545 (gnus-check-server gnus-select-method))
15546 (gnus-find-new-newsgroups))
15547
15548 ;; We might read in new NoCeM messages here.
15549 (when (and gnus-use-nocem
15550 (not level)
15551 (not dont-connect))
15552 (gnus-nocem-scan-groups))
15553
15554 ;; Find the number of unread articles in each non-dead group.
15555 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
15556 (gnus-get-unread-articles level))
15557
15558 (if (and init gnus-check-bogus-newsgroups
15559 gnus-read-active-file (not level)
15560 (gnus-server-opened gnus-select-method))
15561 (gnus-check-bogus-newsgroups))))
15562
15563 (defun gnus-find-new-newsgroups (&optional arg)
15564 "Search for new newsgroups and add them.
15565 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
15566 The `-n' option line from .newsrc is respected.
15567 If ARG (the prefix), use the `ask-server' method to query
15568 the server for new groups."
15569 (interactive "P")
15570 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
15571 (null gnus-read-active-file)
15572 (eq gnus-read-active-file 'some))
15573 'ask-server gnus-check-new-newsgroups)))
15574 (unless (gnus-check-first-time-used)
15575 (if (or (consp check)
15576 (eq check 'ask-server))
15577 ;; Ask the server for new groups.
15578 (gnus-ask-server-for-new-groups)
15579 ;; Go through the active hashtb and look for new groups.
15580 (let ((groups 0)
15581 group new-newsgroups)
15582 (gnus-message 5 "Looking for new newsgroups...")
15583 (unless gnus-have-read-active-file
15584 (gnus-read-active-file))
15585 (setq gnus-newsrc-last-checked-date (current-time-string))
15586 (unless gnus-killed-hashtb
15587 (gnus-make-hashtable-from-killed))
15588 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
15589 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
15590 (mapatoms
15591 (lambda (sym)
15592 (if (or (null (setq group (symbol-name sym)))
15593 (not (boundp sym))
15594 (null (symbol-value sym))
15595 (gnus-gethash group gnus-killed-hashtb)
15596 (gnus-gethash group gnus-newsrc-hashtb))
15597 ()
15598 (let ((do-sub (gnus-matches-options-n group)))
15599 (cond
15600 ((eq do-sub 'subscribe)
15601 (setq groups (1+ groups))
15602 (gnus-sethash group group gnus-killed-hashtb)
15603 (funcall gnus-subscribe-options-newsgroup-method group))
15604 ((eq do-sub 'ignore)
15605 nil)
15606 (t
15607 (setq groups (1+ groups))
15608 (gnus-sethash group group gnus-killed-hashtb)
15609 (if gnus-subscribe-hierarchical-interactive
15610 (setq new-newsgroups (cons group new-newsgroups))
15611 (funcall gnus-subscribe-newsgroup-method group)))))))
15612 gnus-active-hashtb)
15613 (when new-newsgroups
15614 (gnus-subscribe-hierarchical-interactive new-newsgroups))
15615 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
15616 (if (> groups 0)
15617 (gnus-message 6 "%d new newsgroup%s arrived."
15618 groups (if (> groups 1) "s have" " has"))
15619 (gnus-message 6 "No new newsgroups.")))))))
15620
15621 (defun gnus-matches-options-n (group)
15622 ;; Returns `subscribe' if the group is to be unconditionally
15623 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
15624 ;; no match for the group.
15625
15626 ;; First we check the two user variables.
15627 (cond
15628 ((and gnus-options-subscribe
15629 (string-match gnus-options-subscribe group))
15630 'subscribe)
15631 ((and gnus-auto-subscribed-groups
15632 (string-match gnus-auto-subscribed-groups group))
15633 'subscribe)
15634 ((and gnus-options-not-subscribe
15635 (string-match gnus-options-not-subscribe group))
15636 'ignore)
15637 ;; Then we go through the list that was retrieved from the .newsrc
15638 ;; file. This list has elements on the form
15639 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
15640 ;; is in the reverse order of the options line) is returned.
15641 (t
15642 (let ((regs gnus-newsrc-options-n))
15643 (while (and regs
15644 (not (string-match (caar regs) group)))
15645 (setq regs (cdr regs)))
15646 (and regs (cdar regs))))))
15647
15648 (defun gnus-ask-server-for-new-groups ()
15649 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
15650 (methods (cons gnus-select-method
15651 (nconc
15652 (when (gnus-archive-server-wanted-p)
15653 (list "archive"))
15654 (append
15655 (and (consp gnus-check-new-newsgroups)
15656 gnus-check-new-newsgroups)
15657 gnus-secondary-select-methods))))
15658 (groups 0)
15659 (new-date (current-time-string))
15660 group new-newsgroups got-new method hashtb
15661 gnus-override-subscribe-method)
15662 ;; Go through both primary and secondary select methods and
15663 ;; request new newsgroups.
15664 (while (setq method (gnus-server-get-method nil (pop methods)))
15665 (setq new-newsgroups nil)
15666 (setq gnus-override-subscribe-method method)
15667 (when (and (gnus-check-server method)
15668 (gnus-request-newgroups date method))
15669 (save-excursion
15670 (setq got-new t)
15671 (setq hashtb (gnus-make-hashtable 100))
15672 (set-buffer nntp-server-buffer)
15673 ;; Enter all the new groups into a hashtable.
15674 (gnus-active-to-gnus-format method hashtb 'ignore))
15675 ;; Now all new groups from `method' are in `hashtb'.
15676 (mapatoms
15677 (lambda (group-sym)
15678 (if (or (null (setq group (symbol-name group-sym)))
15679 (not (boundp group-sym))
15680 (null (symbol-value group-sym))
15681 (gnus-gethash group gnus-newsrc-hashtb)
15682 (member group gnus-zombie-list)
15683 (member group gnus-killed-list))
15684 ;; The group is already known.
15685 ()
15686 ;; Make this group active.
15687 (when (symbol-value group-sym)
15688 (gnus-set-active group (symbol-value group-sym)))
15689 ;; Check whether we want it or not.
15690 (let ((do-sub (gnus-matches-options-n group)))
15691 (cond
15692 ((eq do-sub 'subscribe)
15693 (incf groups)
15694 (gnus-sethash group group gnus-killed-hashtb)
15695 (funcall gnus-subscribe-options-newsgroup-method group))
15696 ((eq do-sub 'ignore)
15697 nil)
15698 (t
15699 (incf groups)
15700 (gnus-sethash group group gnus-killed-hashtb)
15701 (if gnus-subscribe-hierarchical-interactive
15702 (push group new-newsgroups)
15703 (funcall gnus-subscribe-newsgroup-method group)))))))
15704 hashtb))
15705 (when new-newsgroups
15706 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
15707 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
15708 (when (> groups 0)
15709 (gnus-message 6 "%d new newsgroup%s arrived."
15710 groups (if (> groups 1) "s have" " has")))
15711 (and got-new (setq gnus-newsrc-last-checked-date new-date))
15712 got-new))
15713
15714 (defun gnus-check-first-time-used ()
15715 (if (or (> (length gnus-newsrc-alist) 1)
15716 (file-exists-p gnus-startup-file)
15717 (file-exists-p (concat gnus-startup-file ".el"))
15718 (file-exists-p (concat gnus-startup-file ".eld")))
15719 nil
15720 (gnus-message 6 "First time user; subscribing you to default groups")
15721 (unless (gnus-read-active-file-p)
15722 (gnus-read-active-file))
15723 (setq gnus-newsrc-last-checked-date (current-time-string))
15724 (let ((groups gnus-default-subscribed-newsgroups)
15725 group)
15726 (if (eq groups t)
15727 nil
15728 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
15729 (mapatoms
15730 (lambda (sym)
15731 (if (null (setq group (symbol-name sym)))
15732 ()
15733 (let ((do-sub (gnus-matches-options-n group)))
15734 (cond
15735 ((eq do-sub 'subscribe)
15736 (gnus-sethash group group gnus-killed-hashtb)
15737 (funcall gnus-subscribe-options-newsgroup-method group))
15738 ((eq do-sub 'ignore)
15739 nil)
15740 (t
15741 (setq gnus-killed-list (cons group gnus-killed-list)))))))
15742 gnus-active-hashtb)
15743 (while groups
15744 (if (gnus-active (car groups))
15745 (gnus-group-change-level
15746 (car groups) gnus-level-default-subscribed gnus-level-killed))
15747 (setq groups (cdr groups)))
15748 (gnus-group-make-help-group)
15749 (and gnus-novice-user
15750 (gnus-message 7 "`A k' to list killed groups"))))))
15751
15752 (defun gnus-subscribe-group (group previous &optional method)
15753 (gnus-group-change-level
15754 (if method
15755 (list t group gnus-level-default-subscribed nil nil method)
15756 group)
15757 gnus-level-default-subscribed gnus-level-killed previous t))
15758
15759 ;; `gnus-group-change-level' is the fundamental function for changing
15760 ;; subscription levels of newsgroups. This might mean just changing
15761 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
15762 ;; again, which subscribes/unsubscribes a group, which is equally
15763 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
15764 ;; from 8-9 to 1-7 means that you remove the group from the list of
15765 ;; killed (or zombie) groups and add them to the (kinda) subscribed
15766 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
15767 ;; which is trivial.
15768 ;; ENTRY can either be a string (newsgroup name) or a list (if
15769 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
15770 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
15771 ;; entries.
15772 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
15773 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
15774 ;; after.
15775 (defun gnus-group-change-level (entry level &optional oldlevel
15776 previous fromkilled)
15777 (let (group info active num)
15778 ;; Glean what info we can from the arguments
15779 (if (consp entry)
15780 (if fromkilled (setq group (nth 1 entry))
15781 (setq group (car (nth 2 entry))))
15782 (setq group entry))
15783 (if (and (stringp entry)
15784 oldlevel
15785 (< oldlevel gnus-level-zombie))
15786 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
15787 (if (and (not oldlevel)
15788 (consp entry))
15789 (setq oldlevel (gnus-info-level (nth 2 entry)))
15790 (setq oldlevel (or oldlevel 9)))
15791 (if (stringp previous)
15792 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
15793
15794 (if (and (>= oldlevel gnus-level-zombie)
15795 (gnus-gethash group gnus-newsrc-hashtb))
15796 ;; We are trying to subscribe a group that is already
15797 ;; subscribed.
15798 () ; Do nothing.
15799
15800 (or (gnus-ephemeral-group-p group)
15801 (gnus-dribble-enter
15802 (format "(gnus-group-change-level %S %S %S %S %S)"
15803 group level oldlevel (car (nth 2 previous)) fromkilled)))
15804
15805 ;; Then we remove the newgroup from any old structures, if needed.
15806 ;; If the group was killed, we remove it from the killed or zombie
15807 ;; list. If not, and it is in fact going to be killed, we remove
15808 ;; it from the newsrc hash table and assoc.
15809 (cond
15810 ((>= oldlevel gnus-level-zombie)
15811 (if (= oldlevel gnus-level-zombie)
15812 (setq gnus-zombie-list (delete group gnus-zombie-list))
15813 (setq gnus-killed-list (delete group gnus-killed-list))))
15814 (t
15815 (if (and (>= level gnus-level-zombie)
15816 entry)
15817 (progn
15818 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
15819 (if (nth 3 entry)
15820 (setcdr (gnus-gethash (car (nth 3 entry))
15821 gnus-newsrc-hashtb)
15822 (cdr entry)))
15823 (setcdr (cdr entry) (cdddr entry))))))
15824
15825 ;; Finally we enter (if needed) the list where it is supposed to
15826 ;; go, and change the subscription level. If it is to be killed,
15827 ;; we enter it into the killed or zombie list.
15828 (cond
15829 ((>= level gnus-level-zombie)
15830 ;; Remove from the hash table.
15831 (gnus-sethash group nil gnus-newsrc-hashtb)
15832 ;; We do not enter foreign groups into the list of dead
15833 ;; groups.
15834 (unless (gnus-group-foreign-p group)
15835 (if (= level gnus-level-zombie)
15836 (setq gnus-zombie-list (cons group gnus-zombie-list))
15837 (setq gnus-killed-list (cons group gnus-killed-list)))))
15838 (t
15839 ;; If the list is to be entered into the newsrc assoc, and
15840 ;; it was killed, we have to create an entry in the newsrc
15841 ;; hashtb format and fix the pointers in the newsrc assoc.
15842 (if (< oldlevel gnus-level-zombie)
15843 ;; It was alive, and it is going to stay alive, so we
15844 ;; just change the level and don't change any pointers or
15845 ;; hash table entries.
15846 (setcar (cdaddr entry) level)
15847 (if (listp entry)
15848 (setq info (cdr entry)
15849 num (car entry))
15850 (setq active (gnus-active group))
15851 (setq num
15852 (if active (- (1+ (cdr active)) (car active)) t))
15853 ;; Check whether the group is foreign. If so, the
15854 ;; foreign select method has to be entered into the
15855 ;; info.
15856 (let ((method (or gnus-override-subscribe-method
15857 (gnus-group-method group))))
15858 (if (eq method gnus-select-method)
15859 (setq info (list group level nil))
15860 (setq info (list group level nil nil method)))))
15861 (unless previous
15862 (setq previous
15863 (let ((p gnus-newsrc-alist))
15864 (while (cddr p)
15865 (setq p (cdr p)))
15866 p)))
15867 (setq entry (cons info (cddr previous)))
15868 (if (cdr previous)
15869 (progn
15870 (setcdr (cdr previous) entry)
15871 (gnus-sethash group (cons num (cdr previous))
15872 gnus-newsrc-hashtb))
15873 (setcdr previous entry)
15874 (gnus-sethash group (cons num previous)
15875 gnus-newsrc-hashtb))
15876 (when (cdr entry)
15877 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry)))))
15878 (when gnus-group-change-level-function
15879 (funcall gnus-group-change-level-function group level oldlevel)))))
15880
15881 (defun gnus-kill-newsgroup (newsgroup)
15882 "Obsolete function. Kills a newsgroup."
15883 (gnus-group-change-level
15884 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
15885
15886 (defun gnus-check-bogus-newsgroups (&optional confirm)
15887 "Remove bogus newsgroups.
15888 If CONFIRM is non-nil, the user has to confirm the deletion of every
15889 newsgroup."
15890 (let ((newsrc (cdr gnus-newsrc-alist))
15891 bogus group entry info)
15892 (gnus-message 5 "Checking bogus newsgroups...")
15893 (unless (gnus-read-active-file-p)
15894 (gnus-read-active-file))
15895 (when (gnus-read-active-file-p)
15896 ;; Find all bogus newsgroup that are subscribed.
15897 (while newsrc
15898 (setq info (pop newsrc)
15899 group (gnus-info-group info))
15900 (unless (or (gnus-active group) ; Active
15901 (gnus-info-method info) ; Foreign
15902 (and confirm
15903 (not (gnus-y-or-n-p
15904 (format "Remove bogus newsgroup: %s " group)))))
15905 ;; Found a bogus newsgroup.
15906 (push group bogus)))
15907 ;; Remove all bogus subscribed groups by first killing them, and
15908 ;; then removing them from the list of killed groups.
15909 (while bogus
15910 (when (setq entry (gnus-gethash (setq group (pop bogus))
15911 gnus-newsrc-hashtb))
15912 (gnus-group-change-level entry gnus-level-killed)
15913 (setq gnus-killed-list (delete group gnus-killed-list))))
15914 ;; Then we remove all bogus groups from the list of killed and
15915 ;; zombie groups. They are are removed without confirmation.
15916 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
15917 killed)
15918 (while dead-lists
15919 (setq killed (symbol-value (car dead-lists)))
15920 (while killed
15921 (unless (gnus-active (setq group (pop killed)))
15922 ;; The group is bogus.
15923 ;; !!!Slow as hell.
15924 (set (car dead-lists)
15925 (delete group (symbol-value (car dead-lists))))))
15926 (setq dead-lists (cdr dead-lists))))
15927 (gnus-message 5 "Checking bogus newsgroups...done"))))
15928
15929 (defun gnus-check-duplicate-killed-groups ()
15930 "Remove duplicates from the list of killed groups."
15931 (interactive)
15932 (let ((killed gnus-killed-list))
15933 (while killed
15934 (gnus-message 9 "%d" (length killed))
15935 (setcdr killed (delete (car killed) (cdr killed)))
15936 (setq killed (cdr killed)))))
15937
15938 ;; We want to inline a function from gnus-cache, so we cheat here:
15939 (eval-when-compile
15940 (provide 'gnus)
15941 (setq gnus-directory (or (getenv "SAVEDIR") "~/News/"))
15942 (require 'gnus-cache))
15943
15944 (defun gnus-get-unread-articles-in-group (info active &optional update)
15945 (when active
15946 ;; Allow the backend to update the info in the group.
15947 (when (and update
15948 (gnus-request-update-info
15949 info (gnus-find-method-for-group (gnus-info-group info))))
15950 (gnus-activate-group (gnus-info-group info) nil t))
15951 (let* ((range (gnus-info-read info))
15952 (num 0))
15953 ;; If a cache is present, we may have to alter the active info.
15954 (when (and gnus-use-cache info)
15955 (inline (gnus-cache-possibly-alter-active
15956 (gnus-info-group info) active)))
15957 ;; Modify the list of read articles according to what articles
15958 ;; are available; then tally the unread articles and add the
15959 ;; number to the group hash table entry.
15960 (cond
15961 ((zerop (cdr active))
15962 (setq num 0))
15963 ((not range)
15964 (setq num (- (1+ (cdr active)) (car active))))
15965 ((not (listp (cdr range)))
15966 ;; Fix a single (num . num) range according to the
15967 ;; active hash table.
15968 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
15969 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
15970 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
15971 ;; Compute number of unread articles.
15972 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
15973 (t
15974 ;; The read list is a list of ranges. Fix them according to
15975 ;; the active hash table.
15976 ;; First peel off any elements that are below the lower
15977 ;; active limit.
15978 (while (and (cdr range)
15979 (>= (car active)
15980 (or (and (atom (cadr range)) (cadr range))
15981 (caadr range))))
15982 (if (numberp (car range))
15983 (setcar range
15984 (cons (car range)
15985 (or (and (numberp (cadr range))
15986 (cadr range))
15987 (cdadr range))))
15988 (setcdr (car range)
15989 (or (and (numberp (nth 1 range)) (nth 1 range))
15990 (cdadr range))))
15991 (setcdr range (cddr range)))
15992 ;; Adjust the first element to be the same as the lower limit.
15993 (if (and (not (atom (car range)))
15994 (< (cdar range) (car active)))
15995 (setcdr (car range) (1- (car active))))
15996 ;; Then we want to peel off any elements that are higher
15997 ;; than the upper active limit.
15998 (let ((srange range))
15999 ;; Go past all legal elements.
16000 (while (and (cdr srange)
16001 (<= (or (and (atom (cadr srange))
16002 (cadr srange))
16003 (caadr srange)) (cdr active)))
16004 (setq srange (cdr srange)))
16005 (if (cdr srange)
16006 ;; Nuke all remaining illegal elements.
16007 (setcdr srange nil))
16008
16009 ;; Adjust the final element.
16010 (if (and (not (atom (car srange)))
16011 (> (cdar srange) (cdr active)))
16012 (setcdr (car srange) (cdr active))))
16013 ;; Compute the number of unread articles.
16014 (while range
16015 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
16016 (cdar range)))
16017 (or (and (atom (car range)) (car range))
16018 (caar range)))))
16019 (setq range (cdr range)))
16020 (setq num (max 0 (- (cdr active) num)))))
16021 ;; Set the number of unread articles.
16022 (when info
16023 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
16024 num)))
16025
16026 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
16027 ;; and compute how many unread articles there are in each group.
16028 (defun gnus-get-unread-articles (&optional level)
16029 (let* ((newsrc (cdr gnus-newsrc-alist))
16030 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
16031 (foreign-level
16032 (min
16033 (cond ((and gnus-activate-foreign-newsgroups
16034 (not (numberp gnus-activate-foreign-newsgroups)))
16035 (1+ gnus-level-subscribed))
16036 ((numberp gnus-activate-foreign-newsgroups)
16037 gnus-activate-foreign-newsgroups)
16038 (t 0))
16039 level))
16040 info group active method)
16041 (gnus-message 5 "Checking new news...")
16042
16043 (while newsrc
16044 (setq active (gnus-active (setq group (gnus-info-group
16045 (setq info (pop newsrc))))))
16046
16047 ;; Check newsgroups. If the user doesn't want to check them, or
16048 ;; they can't be checked (for instance, if the news server can't
16049 ;; be reached) we just set the number of unread articles in this
16050 ;; newsgroup to t. This means that Gnus thinks that there are
16051 ;; unread articles, but it has no idea how many.
16052 (if (and (setq method (gnus-info-method info))
16053 (not (gnus-server-equal
16054 gnus-select-method
16055 (setq method (gnus-server-get-method nil method))))
16056 (not (gnus-secondary-method-p method)))
16057 ;; These groups are foreign. Check the level.
16058 (when (<= (gnus-info-level info) foreign-level)
16059 (setq active (gnus-activate-group group 'scan))
16060 (unless (inline (gnus-virtual-group-p group))
16061 (inline (gnus-close-group group)))
16062 (when (fboundp (intern (concat (symbol-name (car method))
16063 "-request-update-info")))
16064 (inline (gnus-request-update-info info method))))
16065 ;; These groups are native or secondary.
16066 (when (and (<= (gnus-info-level info) level)
16067 (not gnus-read-active-file))
16068 (setq active (gnus-activate-group group 'scan))
16069 (inline (gnus-close-group group))))
16070
16071 ;; Get the number of unread articles in the group.
16072 (if active
16073 (inline (gnus-get-unread-articles-in-group info active))
16074 ;; The group couldn't be reached, so we nix out the number of
16075 ;; unread articles and stuff.
16076 (gnus-set-active group nil)
16077 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
16078
16079 (gnus-message 5 "Checking new news...done")))
16080
16081 ;; Create a hash table out of the newsrc alist. The `car's of the
16082 ;; alist elements are used as keys.
16083 (defun gnus-make-hashtable-from-newsrc-alist ()
16084 (let ((alist gnus-newsrc-alist)
16085 (ohashtb gnus-newsrc-hashtb)
16086 prev)
16087 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
16088 (setq alist
16089 (setq prev (setq gnus-newsrc-alist
16090 (if (equal (caar gnus-newsrc-alist)
16091 "dummy.group")
16092 gnus-newsrc-alist
16093 (cons (list "dummy.group" 0 nil) alist)))))
16094 (while alist
16095 (gnus-sethash
16096 (caar alist)
16097 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
16098 prev)
16099 gnus-newsrc-hashtb)
16100 (setq prev alist
16101 alist (cdr alist)))))
16102
16103 (defun gnus-make-hashtable-from-killed ()
16104 "Create a hash table from the killed and zombie lists."
16105 (let ((lists '(gnus-killed-list gnus-zombie-list))
16106 list)
16107 (setq gnus-killed-hashtb
16108 (gnus-make-hashtable
16109 (+ (length gnus-killed-list) (length gnus-zombie-list))))
16110 (while (setq list (pop lists))
16111 (setq list (symbol-value list))
16112 (while list
16113 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
16114
16115 (defun gnus-activate-group (group &optional scan dont-check method)
16116 ;; Check whether a group has been activated or not.
16117 ;; If SCAN, request a scan of that group as well.
16118 (let ((method (or method (gnus-find-method-for-group group)))
16119 active)
16120 (and (gnus-check-server method)
16121 ;; We escape all bugs and quit here to make it possible to
16122 ;; continue if a group is so out-there that it reports bugs
16123 ;; and stuff.
16124 (progn
16125 (and scan
16126 (gnus-check-backend-function 'request-scan (car method))
16127 (gnus-request-scan group method))
16128 t)
16129 (condition-case ()
16130 (gnus-request-group group dont-check method)
16131 ; (error nil)
16132 (quit nil))
16133 (save-excursion
16134 (set-buffer nntp-server-buffer)
16135 (goto-char (point-min))
16136 ;; Parse the result we got from `gnus-request-group'.
16137 (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
16138 (progn
16139 (goto-char (match-beginning 1))
16140 (gnus-set-active
16141 group (setq active (cons (read (current-buffer))
16142 (read (current-buffer)))))
16143 ;; Return the new active info.
16144 active))))))
16145
16146 (defun gnus-update-read-articles (group unread)
16147 "Update the list of read and ticked articles in GROUP using the
16148 UNREAD and TICKED lists.
16149 Note: UNSELECTED has to be sorted over `<'.
16150 Returns whether the updating was successful."
16151 (let* ((active (or gnus-newsgroup-active (gnus-active group)))
16152 (entry (gnus-gethash group gnus-newsrc-hashtb))
16153 (info (nth 2 entry))
16154 (prev 1)
16155 (unread (sort (copy-sequence unread) '<))
16156 read)
16157 (if (or (not info) (not active))
16158 ;; There is no info on this group if it was, in fact,
16159 ;; killed. Gnus stores no information on killed groups, so
16160 ;; there's nothing to be done.
16161 ;; One could store the information somewhere temporarily,
16162 ;; perhaps... Hmmm...
16163 ()
16164 ;; Remove any negative articles numbers.
16165 (while (and unread (< (car unread) 0))
16166 (setq unread (cdr unread)))
16167 ;; Remove any expired article numbers
16168 (while (and unread (< (car unread) (car active)))
16169 (setq unread (cdr unread)))
16170 ;; Compute the ranges of read articles by looking at the list of
16171 ;; unread articles.
16172 (while unread
16173 (if (/= (car unread) prev)
16174 (setq read (cons (if (= prev (1- (car unread))) prev
16175 (cons prev (1- (car unread)))) read)))
16176 (setq prev (1+ (car unread)))
16177 (setq unread (cdr unread)))
16178 (when (<= prev (cdr active))
16179 (setq read (cons (cons prev (cdr active)) read)))
16180 ;; Enter this list into the group info.
16181 (gnus-info-set-read
16182 info (if (> (length read) 1) (nreverse read) read))
16183 ;; Set the number of unread articles in gnus-newsrc-hashtb.
16184 (gnus-get-unread-articles-in-group info (gnus-active group))
16185 t)))
16186
16187 (defun gnus-make-articles-unread (group articles)
16188 "Mark ARTICLES in GROUP as unread."
16189 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
16190 (gnus-gethash (gnus-group-real-name group)
16191 gnus-newsrc-hashtb))))
16192 (ranges (gnus-info-read info))
16193 news article)
16194 (while articles
16195 (when (gnus-member-of-range
16196 (setq article (pop articles)) ranges)
16197 (setq news (cons article news))))
16198 (when news
16199 (gnus-info-set-read
16200 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
16201 (gnus-group-update-group group t))))
16202
16203 ;; Enter all dead groups into the hashtb.
16204 (defun gnus-update-active-hashtb-from-killed ()
16205 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
16206 (lists (list gnus-killed-list gnus-zombie-list))
16207 killed)
16208 (while lists
16209 (setq killed (car lists))
16210 (while killed
16211 (gnus-sethash (car killed) nil hashtb)
16212 (setq killed (cdr killed)))
16213 (setq lists (cdr lists)))))
16214
16215 (defun gnus-get-killed-groups ()
16216 "Go through the active hashtb and all all unknown groups as killed."
16217 ;; First make sure active file has been read.
16218 (unless (gnus-read-active-file-p)
16219 (let ((gnus-read-active-file t))
16220 (gnus-read-active-file)))
16221 (or gnus-killed-hashtb (gnus-make-hashtable-from-killed))
16222 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
16223 (mapatoms
16224 (lambda (sym)
16225 (let ((groups 0)
16226 (group (symbol-name sym)))
16227 (if (or (null group)
16228 (gnus-gethash group gnus-killed-hashtb)
16229 (gnus-gethash group gnus-newsrc-hashtb))
16230 ()
16231 (let ((do-sub (gnus-matches-options-n group)))
16232 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
16233 ()
16234 (setq groups (1+ groups))
16235 (setq gnus-killed-list
16236 (cons group gnus-killed-list))
16237 (gnus-sethash group group gnus-killed-hashtb))))))
16238 gnus-active-hashtb))
16239
16240 ;; Get the active file(s) from the backend(s).
16241 (defun gnus-read-active-file ()
16242 (gnus-group-set-mode-line)
16243 (let ((methods
16244 (append
16245 (if (gnus-check-server gnus-select-method)
16246 ;; The native server is available.
16247 (cons gnus-select-method gnus-secondary-select-methods)
16248 ;; The native server is down, so we just do the
16249 ;; secondary ones.
16250 gnus-secondary-select-methods)
16251 ;; Also read from the archive server.
16252 (when (gnus-archive-server-wanted-p)
16253 (list "archive"))))
16254 list-type)
16255 (setq gnus-have-read-active-file nil)
16256 (save-excursion
16257 (set-buffer nntp-server-buffer)
16258 (while methods
16259 (let* ((method (if (stringp (car methods))
16260 (gnus-server-get-method nil (car methods))
16261 (car methods)))
16262 (where (nth 1 method))
16263 (mesg (format "Reading active file%s via %s..."
16264 (if (and where (not (zerop (length where))))
16265 (concat " from " where) "")
16266 (car method))))
16267 (gnus-message 5 mesg)
16268 (when (gnus-check-server method)
16269 ;; Request that the backend scan its incoming messages.
16270 (and (gnus-check-backend-function 'request-scan (car method))
16271 (gnus-request-scan nil method))
16272 (cond
16273 ((and (eq gnus-read-active-file 'some)
16274 (gnus-check-backend-function 'retrieve-groups (car method)))
16275 (let ((newsrc (cdr gnus-newsrc-alist))
16276 (gmethod (gnus-server-get-method nil method))
16277 groups info)
16278 (while (setq info (pop newsrc))
16279 (when (gnus-server-equal
16280 (gnus-find-method-for-group
16281 (gnus-info-group info) info)
16282 gmethod)
16283 (push (gnus-group-real-name (gnus-info-group info))
16284 groups)))
16285 (when groups
16286 (gnus-check-server method)
16287 (setq list-type (gnus-retrieve-groups groups method))
16288 (cond
16289 ((not list-type)
16290 (gnus-error
16291 1.2 "Cannot read partial active file from %s server."
16292 (car method)))
16293 ((eq list-type 'active)
16294 (gnus-active-to-gnus-format method gnus-active-hashtb))
16295 (t
16296 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
16297 (t
16298 (if (not (gnus-request-list method))
16299 (unless (equal method gnus-message-archive-method)
16300 (gnus-error 1 "Cannot read active file from %s server."
16301 (car method)))
16302 (gnus-message 5 mesg)
16303 (gnus-active-to-gnus-format method gnus-active-hashtb)
16304 ;; We mark this active file as read.
16305 (push method gnus-have-read-active-file)
16306 (gnus-message 5 "%sdone" mesg))))))
16307 (setq methods (cdr methods))))))
16308
16309 ;; Read an active file and place the results in `gnus-active-hashtb'.
16310 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
16311 (unless method
16312 (setq method gnus-select-method))
16313 (let ((cur (current-buffer))
16314 (hashtb (or hashtb
16315 (if (and gnus-active-hashtb
16316 (not (equal method gnus-select-method)))
16317 gnus-active-hashtb
16318 (setq gnus-active-hashtb
16319 (if (equal method gnus-select-method)
16320 (gnus-make-hashtable
16321 (count-lines (point-min) (point-max)))
16322 (gnus-make-hashtable 4096)))))))
16323 ;; Delete unnecessary lines.
16324 (goto-char (point-min))
16325 (while (search-forward "\nto." nil t)
16326 (delete-region (1+ (match-beginning 0))
16327 (progn (forward-line 1) (point))))
16328 (or (string= gnus-ignored-newsgroups "")
16329 (progn
16330 (goto-char (point-min))
16331 (delete-matching-lines gnus-ignored-newsgroups)))
16332 ;; Make the group names readable as a lisp expression even if they
16333 ;; contain special characters.
16334 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
16335 (goto-char (point-max))
16336 (while (re-search-backward "[][';?()#]" nil t)
16337 (insert ?\\))
16338 ;; If these are groups from a foreign select method, we insert the
16339 ;; group prefix in front of the group names.
16340 (and method (not (gnus-server-equal
16341 (gnus-server-get-method nil method)
16342 (gnus-server-get-method nil gnus-select-method)))
16343 (let ((prefix (gnus-group-prefixed-name "" method)))
16344 (goto-char (point-min))
16345 (while (and (not (eobp))
16346 (progn (insert prefix)
16347 (zerop (forward-line 1)))))))
16348 ;; Store the active file in a hash table.
16349 (goto-char (point-min))
16350 (if (string-match "%[oO]" gnus-group-line-format)
16351 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
16352 ;; If we want information on moderated groups, we use this
16353 ;; loop...
16354 (let* ((mod-hashtb (make-vector 7 0))
16355 (m (intern "m" mod-hashtb))
16356 group max min)
16357 (while (not (eobp))
16358 (condition-case nil
16359 (progn
16360 (narrow-to-region (point) (gnus-point-at-eol))
16361 (setq group (let ((obarray hashtb)) (read cur)))
16362 (if (and (numberp (setq max (read cur)))
16363 (numberp (setq min (read cur)))
16364 (progn
16365 (skip-chars-forward " \t")
16366 (not
16367 (or (= (following-char) ?=)
16368 (= (following-char) ?x)
16369 (= (following-char) ?j)))))
16370 (set group (cons min max))
16371 (set group nil))
16372 ;; Enter moderated groups into a list.
16373 (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
16374 (setq gnus-moderated-list
16375 (cons (symbol-name group) gnus-moderated-list))))
16376 (error
16377 (and group
16378 (symbolp group)
16379 (set group nil))))
16380 (widen)
16381 (forward-line 1)))
16382 ;; And if we do not care about moderation, we use this loop,
16383 ;; which is faster.
16384 (let (group max min)
16385 (while (not (eobp))
16386 (condition-case ()
16387 (progn
16388 (narrow-to-region (point) (gnus-point-at-eol))
16389 ;; group gets set to a symbol interned in the hash table
16390 ;; (what a hack!!) - jwz
16391 (setq group (let ((obarray hashtb)) (read cur)))
16392 (if (and (numberp (setq max (read cur)))
16393 (numberp (setq min (read cur)))
16394 (progn
16395 (skip-chars-forward " \t")
16396 (not
16397 (or (= (following-char) ?=)
16398 (= (following-char) ?x)
16399 (= (following-char) ?j)))))
16400 (set group (cons min max))
16401 (set group nil)))
16402 (error
16403 (progn
16404 (and group
16405 (symbolp group)
16406 (set group nil))
16407 (or ignore-errors
16408 (gnus-message 3 "Warning - illegal active: %s"
16409 (buffer-substring
16410 (gnus-point-at-bol) (gnus-point-at-eol)))))))
16411 (widen)
16412 (forward-line 1))))))
16413
16414 (defun gnus-groups-to-gnus-format (method &optional hashtb)
16415 ;; Parse a "groups" active file.
16416 (let ((cur (current-buffer))
16417 (hashtb (or hashtb
16418 (if (and method gnus-active-hashtb)
16419 gnus-active-hashtb
16420 (setq gnus-active-hashtb
16421 (gnus-make-hashtable
16422 (count-lines (point-min) (point-max)))))))
16423 (prefix (and method
16424 (not (gnus-server-equal
16425 (gnus-server-get-method nil method)
16426 (gnus-server-get-method nil gnus-select-method)))
16427 (gnus-group-prefixed-name "" method))))
16428
16429 (goto-char (point-min))
16430 ;; We split this into to separate loops, one with the prefix
16431 ;; and one without to speed the reading up somewhat.
16432 (if prefix
16433 (let (min max opoint group)
16434 (while (not (eobp))
16435 (condition-case ()
16436 (progn
16437 (read cur) (read cur)
16438 (setq min (read cur)
16439 max (read cur)
16440 opoint (point))
16441 (skip-chars-forward " \t")
16442 (insert prefix)
16443 (goto-char opoint)
16444 (set (let ((obarray hashtb)) (read cur))
16445 (cons min max)))
16446 (error (and group (symbolp group) (set group nil))))
16447 (forward-line 1)))
16448 (let (min max group)
16449 (while (not (eobp))
16450 (condition-case ()
16451 (if (= (following-char) ?2)
16452 (progn
16453 (read cur) (read cur)
16454 (setq min (read cur)
16455 max (read cur))
16456 (set (setq group (let ((obarray hashtb)) (read cur)))
16457 (cons min max))))
16458 (error (and group (symbolp group) (set group nil))))
16459 (forward-line 1))))))
16460
16461 (defun gnus-read-newsrc-file (&optional force)
16462 "Read startup file.
16463 If FORCE is non-nil, the .newsrc file is read."
16464 ;; Reset variables that might be defined in the .newsrc.eld file.
16465 (let ((variables gnus-variable-list))
16466 (while variables
16467 (set (car variables) nil)
16468 (setq variables (cdr variables))))
16469 (let* ((newsrc-file gnus-current-startup-file)
16470 (quick-file (concat newsrc-file ".el")))
16471 (save-excursion
16472 ;; We always load the .newsrc.eld file. If always contains
16473 ;; much information that can not be gotten from the .newsrc
16474 ;; file (ticked articles, killed groups, foreign methods, etc.)
16475 (gnus-read-newsrc-el-file quick-file)
16476
16477 (if (and (file-exists-p gnus-current-startup-file)
16478 (or force
16479 (and (file-newer-than-file-p newsrc-file quick-file)
16480 (file-newer-than-file-p newsrc-file
16481 (concat quick-file "d")))
16482 (not gnus-newsrc-alist)))
16483 ;; We read the .newsrc file. Note that if there if a
16484 ;; .newsrc.eld file exists, it has already been read, and
16485 ;; the `gnus-newsrc-hashtb' has been created. While reading
16486 ;; the .newsrc file, Gnus will only use the information it
16487 ;; can find there for changing the data already read -
16488 ;; ie. reading the .newsrc file will not trash the data
16489 ;; already read (except for read articles).
16490 (save-excursion
16491 (gnus-message 5 "Reading %s..." newsrc-file)
16492 (set-buffer (find-file-noselect newsrc-file))
16493 (buffer-disable-undo (current-buffer))
16494 (gnus-newsrc-to-gnus-format)
16495 (kill-buffer (current-buffer))
16496 (gnus-message 5 "Reading %s...done" newsrc-file)))
16497
16498 ;; Read any slave files.
16499 (unless gnus-slave
16500 (gnus-master-read-slave-newsrc))
16501
16502 ;; Convert old to new.
16503 (gnus-convert-old-newsrc))))
16504
16505 (defun gnus-continuum-version (version)
16506 "Return VERSION as a floating point number."
16507 (when (or (string-match "^\\([^ ]+\\)? ?Gnus v?\\([0-9.]+\\)$" version)
16508 (string-match "^\\(.?\\)gnus-\\([0-9.]+\\)$" version))
16509 (let* ((alpha (and (match-beginning 1) (match-string 1 version)))
16510 (number (match-string 2 version))
16511 major minor least)
16512 (string-match "\\([0-9]\\)\\.\\([0-9]+\\)\\.?\\([0-9]+\\)?" number)
16513 (setq major (string-to-number (match-string 1 number)))
16514 (setq minor (string-to-number (match-string 2 number)))
16515 (setq least (if (match-beginning 3)
16516 (string-to-number (match-string 3 number))
16517 0))
16518 (string-to-number
16519 (if (zerop major)
16520 (format "%s00%02d%02d"
16521 (cond
16522 ((member alpha '("(ding)" "d")) "4.99")
16523 ((member alpha '("September" "s")) "5.01")
16524 ((member alpha '("Red" "r")) "5.03"))
16525 minor least)
16526 (format "%d.%02d%02d" major minor least))))))
16527
16528 (defun gnus-convert-old-newsrc ()
16529 "Convert old newsrc into the new format, if needed."
16530 (let ((fcv (and gnus-newsrc-file-version
16531 (gnus-continuum-version gnus-newsrc-file-version))))
16532 (cond
16533 ;; No .newsrc.eld file was loaded.
16534 ((null fcv) nil)
16535 ;; Gnus 5 .newsrc.eld was loaded.
16536 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
16537 (gnus-convert-old-ticks)))))
16538
16539 (defun gnus-convert-old-ticks ()
16540 (let ((newsrc (cdr gnus-newsrc-alist))
16541 marks info dormant ticked)
16542 (while (setq info (pop newsrc))
16543 (when (setq marks (gnus-info-marks info))
16544 (setq dormant (cdr (assq 'dormant marks))
16545 ticked (cdr (assq 'tick marks)))
16546 (when (or dormant ticked)
16547 (gnus-info-set-read
16548 info
16549 (gnus-add-to-range
16550 (gnus-info-read info)
16551 (nconc (gnus-uncompress-range dormant)
16552 (gnus-uncompress-range ticked)))))))))
16553
16554 (defun gnus-read-newsrc-el-file (file)
16555 (let ((ding-file (concat file "d")))
16556 ;; We always, always read the .eld file.
16557 (gnus-message 5 "Reading %s..." ding-file)
16558 (let (gnus-newsrc-assoc)
16559 (condition-case nil
16560 (load ding-file t t t)
16561 (error
16562 (gnus-error 1 "Error in %s" ding-file)))
16563 (when gnus-newsrc-assoc
16564 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
16565 (gnus-make-hashtable-from-newsrc-alist)
16566 (when (file-newer-than-file-p file ding-file)
16567 ;; Old format quick file
16568 (gnus-message 5 "Reading %s..." file)
16569 ;; The .el file is newer than the .eld file, so we read that one
16570 ;; as well.
16571 (gnus-read-old-newsrc-el-file file))))
16572
16573 ;; Parse the old-style quick startup file
16574 (defun gnus-read-old-newsrc-el-file (file)
16575 (let (newsrc killed marked group m info)
16576 (prog1
16577 (let ((gnus-killed-assoc nil)
16578 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
16579 (prog1
16580 (condition-case nil
16581 (load file t t t)
16582 (error nil))
16583 (setq newsrc gnus-newsrc-assoc
16584 killed gnus-killed-assoc
16585 marked gnus-marked-assoc)))
16586 (setq gnus-newsrc-alist nil)
16587 (while (setq group (pop newsrc))
16588 (if (setq info (gnus-get-info (car group)))
16589 (progn
16590 (gnus-info-set-read info (cddr group))
16591 (gnus-info-set-level
16592 info (if (nth 1 group) gnus-level-default-subscribed
16593 gnus-level-default-unsubscribed))
16594 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
16595 (push (setq info
16596 (list (car group)
16597 (if (nth 1 group) gnus-level-default-subscribed
16598 gnus-level-default-unsubscribed)
16599 (cddr group)))
16600 gnus-newsrc-alist))
16601 ;; Copy marks into info.
16602 (when (setq m (assoc (car group) marked))
16603 (unless (nthcdr 3 info)
16604 (nconc info (list nil)))
16605 (gnus-info-set-marks
16606 info (list (cons 'tick (gnus-compress-sequence
16607 (sort (cdr m) '<) t))))))
16608 (setq newsrc killed)
16609 (while newsrc
16610 (setcar newsrc (caar newsrc))
16611 (setq newsrc (cdr newsrc)))
16612 (setq gnus-killed-list killed))
16613 ;; The .el file version of this variable does not begin with
16614 ;; "options", while the .eld version does, so we just add it if it
16615 ;; isn't there.
16616 (and
16617 gnus-newsrc-options
16618 (progn
16619 (and (not (string-match "^ *options" gnus-newsrc-options))
16620 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
16621 (and (not (string-match "\n$" gnus-newsrc-options))
16622 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
16623 ;; Finally, if we read some options lines, we parse them.
16624 (or (string= gnus-newsrc-options "")
16625 (gnus-newsrc-parse-options gnus-newsrc-options))))
16626
16627 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
16628 (gnus-make-hashtable-from-newsrc-alist)))
16629
16630 (defun gnus-make-newsrc-file (file)
16631 "Make server dependent file name by catenating FILE and server host name."
16632 (let* ((file (expand-file-name file nil))
16633 (real-file (concat file "-" (nth 1 gnus-select-method))))
16634 (if (or (file-exists-p real-file)
16635 (file-exists-p (concat real-file ".el"))
16636 (file-exists-p (concat real-file ".eld")))
16637 real-file file)))
16638
16639 (defun gnus-newsrc-to-gnus-format ()
16640 (setq gnus-newsrc-options "")
16641 (setq gnus-newsrc-options-n nil)
16642
16643 (or gnus-active-hashtb
16644 (setq gnus-active-hashtb (make-vector 4095 0)))
16645 (let ((buf (current-buffer))
16646 (already-read (> (length gnus-newsrc-alist) 1))
16647 group subscribed options-symbol newsrc Options-symbol
16648 symbol reads num1)
16649 (goto-char (point-min))
16650 ;; We intern the symbol `options' in the active hashtb so that we
16651 ;; can `eq' against it later.
16652 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
16653 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
16654
16655 (while (not (eobp))
16656 ;; We first read the first word on the line by narrowing and
16657 ;; then reading into `gnus-active-hashtb'. Most groups will
16658 ;; already exist in that hashtb, so this will save some string
16659 ;; space.
16660 (narrow-to-region
16661 (point)
16662 (progn (skip-chars-forward "^ \t!:\n") (point)))
16663 (goto-char (point-min))
16664 (setq symbol
16665 (and (/= (point-min) (point-max))
16666 (let ((obarray gnus-active-hashtb)) (read buf))))
16667 (widen)
16668 ;; Now, the symbol we have read is either `options' or a group
16669 ;; name. If it is an options line, we just add it to a string.
16670 (cond
16671 ((or (eq symbol options-symbol)
16672 (eq symbol Options-symbol))
16673 (setq gnus-newsrc-options
16674 ;; This concating is quite inefficient, but since our
16675 ;; thorough studies show that approx 99.37% of all
16676 ;; .newsrc files only contain a single options line, we
16677 ;; don't give a damn, frankly, my dear.
16678 (concat gnus-newsrc-options
16679 (buffer-substring
16680 (gnus-point-at-bol)
16681 ;; Options may continue on the next line.
16682 (or (and (re-search-forward "^[^ \t]" nil 'move)
16683 (progn (beginning-of-line) (point)))
16684 (point)))))
16685 (forward-line -1))
16686 (symbol
16687 ;; Group names can be just numbers.
16688 (when (numberp symbol)
16689 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
16690 (or (boundp symbol) (set symbol nil))
16691 ;; It was a group name.
16692 (setq subscribed (= (following-char) ?:)
16693 group (symbol-name symbol)
16694 reads nil)
16695 (if (eolp)
16696 ;; If the line ends here, this is clearly a buggy line, so
16697 ;; we put point a the beginning of line and let the cond
16698 ;; below do the error handling.
16699 (beginning-of-line)
16700 ;; We skip to the beginning of the ranges.
16701 (skip-chars-forward "!: \t"))
16702 ;; We are now at the beginning of the list of read articles.
16703 ;; We read them range by range.
16704 (while
16705 (cond
16706 ((looking-at "[0-9]+")
16707 ;; We narrow and read a number instead of buffer-substring/
16708 ;; string-to-int because it's faster. narrow/widen is
16709 ;; faster than save-restriction/narrow, and save-restriction
16710 ;; produces a garbage object.
16711 (setq num1 (progn
16712 (narrow-to-region (match-beginning 0) (match-end 0))
16713 (read buf)))
16714 (widen)
16715 ;; If the next character is a dash, then this is a range.
16716 (if (= (following-char) ?-)
16717 (progn
16718 ;; We read the upper bound of the range.
16719 (forward-char 1)
16720 (if (not (looking-at "[0-9]+"))
16721 ;; This is a buggy line, by we pretend that
16722 ;; it's kinda OK. Perhaps the user should be
16723 ;; dinged?
16724 (setq reads (cons num1 reads))
16725 (setq reads
16726 (cons
16727 (cons num1
16728 (progn
16729 (narrow-to-region (match-beginning 0)
16730 (match-end 0))
16731 (read buf)))
16732 reads))
16733 (widen)))
16734 ;; It was just a simple number, so we add it to the
16735 ;; list of ranges.
16736 (setq reads (cons num1 reads)))
16737 ;; If the next char in ?\n, then we have reached the end
16738 ;; of the line and return nil.
16739 (/= (following-char) ?\n))
16740 ((= (following-char) ?\n)
16741 ;; End of line, so we end.
16742 nil)
16743 (t
16744 ;; Not numbers and not eol, so this might be a buggy
16745 ;; line...
16746 (or (eobp)
16747 ;; If it was eob instead of ?\n, we allow it.
16748 (progn
16749 ;; The line was buggy.
16750 (setq group nil)
16751 (gnus-error 3.1 "Mangled line: %s"
16752 (buffer-substring (gnus-point-at-bol)
16753 (gnus-point-at-eol)))))
16754 nil))
16755 ;; Skip past ", ". Spaces are illegal in these ranges, but
16756 ;; we allow them, because it's a common mistake to put a
16757 ;; space after the comma.
16758 (skip-chars-forward ", "))
16759
16760 ;; We have already read .newsrc.eld, so we gently update the
16761 ;; data in the hash table with the information we have just
16762 ;; read.
16763 (when group
16764 (let ((info (gnus-get-info group))
16765 level)
16766 (if info
16767 ;; There is an entry for this file in the alist.
16768 (progn
16769 (gnus-info-set-read info (nreverse reads))
16770 ;; We update the level very gently. In fact, we
16771 ;; only change it if there's been a status change
16772 ;; from subscribed to unsubscribed, or vice versa.
16773 (setq level (gnus-info-level info))
16774 (cond ((and (<= level gnus-level-subscribed)
16775 (not subscribed))
16776 (setq level (if reads
16777 gnus-level-default-unsubscribed
16778 (1+ gnus-level-default-unsubscribed))))
16779 ((and (> level gnus-level-subscribed) subscribed)
16780 (setq level gnus-level-default-subscribed)))
16781 (gnus-info-set-level info level))
16782 ;; This is a new group.
16783 (setq info (list group
16784 (if subscribed
16785 gnus-level-default-subscribed
16786 (if reads
16787 (1+ gnus-level-subscribed)
16788 gnus-level-default-unsubscribed))
16789 (nreverse reads))))
16790 (setq newsrc (cons info newsrc))))))
16791 (forward-line 1))
16792
16793 (setq newsrc (nreverse newsrc))
16794
16795 (if (not already-read)
16796 ()
16797 ;; We now have two newsrc lists - `newsrc', which is what we
16798 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
16799 ;; what we've read from .newsrc.eld. We have to merge these
16800 ;; lists. We do this by "attaching" any (foreign) groups in the
16801 ;; gnus-newsrc-alist to the (native) group that precedes them.
16802 (let ((rc (cdr gnus-newsrc-alist))
16803 (prev gnus-newsrc-alist)
16804 entry mentry)
16805 (while rc
16806 (or (null (nth 4 (car rc))) ; It's a native group.
16807 (assoc (caar rc) newsrc) ; It's already in the alist.
16808 (if (setq entry (assoc (caar prev) newsrc))
16809 (setcdr (setq mentry (memq entry newsrc))
16810 (cons (car rc) (cdr mentry)))
16811 (setq newsrc (cons (car rc) newsrc))))
16812 (setq prev rc
16813 rc (cdr rc)))))
16814
16815 (setq gnus-newsrc-alist newsrc)
16816 ;; We make the newsrc hashtb.
16817 (gnus-make-hashtable-from-newsrc-alist)
16818
16819 ;; Finally, if we read some options lines, we parse them.
16820 (or (string= gnus-newsrc-options "")
16821 (gnus-newsrc-parse-options gnus-newsrc-options))))
16822
16823 ;; Parse options lines to find "options -n !all rec.all" and stuff.
16824 ;; The return value will be a list on the form
16825 ;; ((regexp1 . ignore)
16826 ;; (regexp2 . subscribe)...)
16827 ;; When handling new newsgroups, groups that match a `ignore' regexp
16828 ;; will be ignored, and groups that match a `subscribe' regexp will be
16829 ;; subscribed. A line like
16830 ;; options -n !all rec.all
16831 ;; will lead to a list that looks like
16832 ;; (("^rec\\..+" . subscribe)
16833 ;; ("^.+" . ignore))
16834 ;; So all "rec.*" groups will be subscribed, while all the other
16835 ;; groups will be ignored. Note that "options -n !all rec.all" is very
16836 ;; different from "options -n rec.all !all".
16837 (defun gnus-newsrc-parse-options (options)
16838 (let (out eol)
16839 (save-excursion
16840 (gnus-set-work-buffer)
16841 (insert (regexp-quote options))
16842 ;; First we treat all continuation lines.
16843 (goto-char (point-min))
16844 (while (re-search-forward "\n[ \t]+" nil t)
16845 (replace-match " " t t))
16846 ;; Then we transform all "all"s into ".+"s.
16847 (goto-char (point-min))
16848 (while (re-search-forward "\\ball\\b" nil t)
16849 (replace-match ".+" t t))
16850 (goto-char (point-min))
16851 ;; We remove all other options than the "-n" ones.
16852 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
16853 (replace-match " ")
16854 (forward-char -1))
16855 (goto-char (point-min))
16856
16857 ;; We are only interested in "options -n" lines - we
16858 ;; ignore the other option lines.
16859 (while (re-search-forward "[ \t]-n" nil t)
16860 (setq eol
16861 (or (save-excursion
16862 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
16863 (- (point) 2)))
16864 (gnus-point-at-eol)))
16865 ;; Search for all "words"...
16866 (while (re-search-forward "[^ \t,\n]+" eol t)
16867 (if (= (char-after (match-beginning 0)) ?!)
16868 ;; If the word begins with a bang (!), this is a "not"
16869 ;; spec. We put this spec (minus the bang) and the
16870 ;; symbol `ignore' into the list.
16871 (setq out (cons (cons (concat
16872 "^" (buffer-substring
16873 (1+ (match-beginning 0))
16874 (match-end 0)))
16875 'ignore) out))
16876 ;; There was no bang, so this is a "yes" spec.
16877 (setq out (cons (cons (concat "^" (match-string 0))
16878 'subscribe) out)))))
16879
16880 (setq gnus-newsrc-options-n out))))
16881
16882 (defun gnus-save-newsrc-file (&optional force)
16883 "Save .newsrc file."
16884 ;; Note: We cannot save .newsrc file if all newsgroups are removed
16885 ;; from the variable gnus-newsrc-alist.
16886 (when (and (or gnus-newsrc-alist gnus-killed-list)
16887 gnus-current-startup-file)
16888 (save-excursion
16889 (if (and (or gnus-use-dribble-file gnus-slave)
16890 (not force)
16891 (or (not gnus-dribble-buffer)
16892 (not (buffer-name gnus-dribble-buffer))
16893 (zerop (save-excursion
16894 (set-buffer gnus-dribble-buffer)
16895 (buffer-size)))))
16896 (gnus-message 4 "(No changes need to be saved)")
16897 (run-hooks 'gnus-save-newsrc-hook)
16898 (if gnus-slave
16899 (gnus-slave-save-newsrc)
16900 ;; Save .newsrc.
16901 (when gnus-save-newsrc-file
16902 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
16903 (gnus-gnus-to-newsrc-format)
16904 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
16905 ;; Save .newsrc.eld.
16906 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
16907 (make-local-variable 'version-control)
16908 (setq version-control 'never)
16909 (setq buffer-file-name
16910 (concat gnus-current-startup-file ".eld"))
16911 (setq default-directory (file-name-directory buffer-file-name))
16912 (gnus-add-current-to-buffer-list)
16913 (buffer-disable-undo (current-buffer))
16914 (erase-buffer)
16915 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
16916 (gnus-gnus-to-quick-newsrc-format)
16917 (run-hooks 'gnus-save-quick-newsrc-hook)
16918 (save-buffer)
16919 (kill-buffer (current-buffer))
16920 (gnus-message
16921 5 "Saving %s.eld...done" gnus-current-startup-file))
16922 (gnus-dribble-delete-file)
16923 (gnus-group-set-mode-line)))))
16924
16925 (defun gnus-gnus-to-quick-newsrc-format ()
16926 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
16927 (insert ";; Gnus startup file.\n")
16928 (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
16929 (insert ";; to read .newsrc.\n")
16930 (insert "(setq gnus-newsrc-file-version "
16931 (prin1-to-string gnus-version) ")\n")
16932 (let ((variables
16933 (if gnus-save-killed-list gnus-variable-list
16934 ;; Remove the `gnus-killed-list' from the list of variables
16935 ;; to be saved, if required.
16936 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
16937 ;; Peel off the "dummy" group.
16938 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
16939 variable)
16940 ;; Insert the variables into the file.
16941 (while variables
16942 (when (and (boundp (setq variable (pop variables)))
16943 (symbol-value variable))
16944 (insert "(setq " (symbol-name variable) " '")
16945 (prin1 (symbol-value variable) (current-buffer))
16946 (insert ")\n")))))
16947
16948 (defun gnus-gnus-to-newsrc-format ()
16949 ;; Generate and save the .newsrc file.
16950 (save-excursion
16951 (set-buffer (create-file-buffer gnus-current-startup-file))
16952 (let ((newsrc (cdr gnus-newsrc-alist))
16953 (standard-output (current-buffer))
16954 info ranges range method)
16955 (setq buffer-file-name gnus-current-startup-file)
16956 (setq default-directory (file-name-directory buffer-file-name))
16957 (buffer-disable-undo (current-buffer))
16958 (erase-buffer)
16959 ;; Write options.
16960 (if gnus-newsrc-options (insert gnus-newsrc-options))
16961 ;; Write subscribed and unsubscribed.
16962 (while (setq info (pop newsrc))
16963 ;; Don't write foreign groups to .newsrc.
16964 (when (or (null (setq method (gnus-info-method info)))
16965 (equal method "native")
16966 (gnus-server-equal method gnus-select-method))
16967 (insert (gnus-info-group info)
16968 (if (> (gnus-info-level info) gnus-level-subscribed)
16969 "!" ":"))
16970 (when (setq ranges (gnus-info-read info))
16971 (insert " ")
16972 (if (not (listp (cdr ranges)))
16973 (if (= (car ranges) (cdr ranges))
16974 (princ (car ranges))
16975 (princ (car ranges))
16976 (insert "-")
16977 (princ (cdr ranges)))
16978 (while (setq range (pop ranges))
16979 (if (or (atom range) (= (car range) (cdr range)))
16980 (princ (or (and (atom range) range) (car range)))
16981 (princ (car range))
16982 (insert "-")
16983 (princ (cdr range)))
16984 (if ranges (insert ",")))))
16985 (insert "\n")))
16986 (make-local-variable 'version-control)
16987 (setq version-control 'never)
16988 ;; It has been reported that sometime the modtime on the .newsrc
16989 ;; file seems to be off. We really do want to overwrite it, so
16990 ;; we clear the modtime here before saving. It's a bit odd,
16991 ;; though...
16992 ;; sometimes the modtime clear isn't sufficient. most brute force:
16993 ;; delete the silly thing entirely first. but this fails to provide
16994 ;; such niceties as .newsrc~ creation.
16995 (if gnus-modtime-botch
16996 (delete-file gnus-startup-file)
16997 (clear-visited-file-modtime))
16998 (run-hooks 'gnus-save-standard-newsrc-hook)
16999 (save-buffer)
17000 (kill-buffer (current-buffer)))))
17001
17002 \f
17003 ;;;
17004 ;;; Slave functions.
17005 ;;;
17006
17007 (defun gnus-slave-save-newsrc ()
17008 (save-excursion
17009 (set-buffer gnus-dribble-buffer)
17010 (let ((slave-name
17011 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
17012 (write-region (point-min) (point-max) slave-name nil 'nomesg))))
17013
17014 (defun gnus-master-read-slave-newsrc ()
17015 (let ((slave-files
17016 (directory-files
17017 (file-name-directory gnus-current-startup-file)
17018 t (concat
17019 "^" (regexp-quote
17020 (concat
17021 (file-name-nondirectory gnus-current-startup-file)
17022 "-slave-")))
17023 t))
17024 file)
17025 (if (not slave-files)
17026 () ; There are no slave files to read.
17027 (gnus-message 7 "Reading slave newsrcs...")
17028 (save-excursion
17029 (set-buffer (get-buffer-create " *gnus slave*"))
17030 (buffer-disable-undo (current-buffer))
17031 (setq slave-files
17032 (sort (mapcar (lambda (file)
17033 (list (nth 5 (file-attributes file)) file))
17034 slave-files)
17035 (lambda (f1 f2)
17036 (or (< (caar f1) (caar f2))
17037 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
17038 (while slave-files
17039 (erase-buffer)
17040 (setq file (nth 1 (car slave-files)))
17041 (insert-file-contents file)
17042 (if (condition-case ()
17043 (progn
17044 (eval-buffer (current-buffer))
17045 t)
17046 (error
17047 (gnus-error 3.2 "Possible error in %s" file)
17048 nil))
17049 (or gnus-slave ; Slaves shouldn't delete these files.
17050 (condition-case ()
17051 (delete-file file)
17052 (error nil))))
17053 (setq slave-files (cdr slave-files))))
17054 (gnus-message 7 "Reading slave newsrcs...done"))))
17055
17056 \f
17057 ;;;
17058 ;;; Group description.
17059 ;;;
17060
17061 (defun gnus-read-all-descriptions-files ()
17062 (let ((methods (cons gnus-select-method
17063 (nconc
17064 (when (gnus-archive-server-wanted-p)
17065 (list "archive"))
17066 gnus-secondary-select-methods))))
17067 (while methods
17068 (gnus-read-descriptions-file (car methods))
17069 (setq methods (cdr methods)))
17070 t))
17071
17072 (defun gnus-read-descriptions-file (&optional method)
17073 (let ((method (or method gnus-select-method))
17074 group)
17075 (when (stringp method)
17076 (setq method (gnus-server-to-method method)))
17077 ;; We create the hashtable whether we manage to read the desc file
17078 ;; to avoid trying to re-read after a failed read.
17079 (or gnus-description-hashtb
17080 (setq gnus-description-hashtb
17081 (gnus-make-hashtable (length gnus-active-hashtb))))
17082 ;; Mark this method's desc file as read.
17083 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
17084 gnus-description-hashtb)
17085
17086 (gnus-message 5 "Reading descriptions file via %s..." (car method))
17087 (cond
17088 ((not (gnus-check-server method))
17089 (gnus-message 1 "Couldn't open server")
17090 nil)
17091 ((not (gnus-request-list-newsgroups method))
17092 (gnus-message 1 "Couldn't read newsgroups descriptions")
17093 nil)
17094 (t
17095 (save-excursion
17096 (save-restriction
17097 (set-buffer nntp-server-buffer)
17098 (goto-char (point-min))
17099 (when (or (search-forward "\n.\n" nil t)
17100 (goto-char (point-max)))
17101 (beginning-of-line)
17102 (narrow-to-region (point-min) (point)))
17103 ;; If these are groups from a foreign select method, we insert the
17104 ;; group prefix in front of the group names.
17105 (and method (not (gnus-server-equal
17106 (gnus-server-get-method nil method)
17107 (gnus-server-get-method nil gnus-select-method)))
17108 (let ((prefix (gnus-group-prefixed-name "" method)))
17109 (goto-char (point-min))
17110 (while (and (not (eobp))
17111 (progn (insert prefix)
17112 (zerop (forward-line 1)))))))
17113 (goto-char (point-min))
17114 (while (not (eobp))
17115 ;; If we get an error, we set group to 0, which is not a
17116 ;; symbol...
17117 (setq group
17118 (condition-case ()
17119 (let ((obarray gnus-description-hashtb))
17120 ;; Group is set to a symbol interned in this
17121 ;; hash table.
17122 (read nntp-server-buffer))
17123 (error 0)))
17124 (skip-chars-forward " \t")
17125 ;; ... which leads to this line being effectively ignored.
17126 (and (symbolp group)
17127 (set group (buffer-substring
17128 (point) (progn (end-of-line) (point)))))
17129 (forward-line 1))))
17130 (gnus-message 5 "Reading descriptions file...done")
17131 t))))
17132
17133 (defun gnus-group-get-description (group)
17134 "Get the description of a group by sending XGTITLE to the server."
17135 (when (gnus-request-group-description group)
17136 (save-excursion
17137 (set-buffer nntp-server-buffer)
17138 (goto-char (point-min))
17139 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
17140 (match-string 1)))))
17141
17142 \f
17143 ;;;
17144 ;;; Buffering of read articles.
17145 ;;;
17146
17147 (defvar gnus-backlog-buffer " *Gnus Backlog*")
17148 (defvar gnus-backlog-articles nil)
17149 (defvar gnus-backlog-hashtb nil)
17150
17151 (defun gnus-backlog-buffer ()
17152 "Return the backlog buffer."
17153 (or (get-buffer gnus-backlog-buffer)
17154 (save-excursion
17155 (set-buffer (get-buffer-create gnus-backlog-buffer))
17156 (buffer-disable-undo (current-buffer))
17157 (setq buffer-read-only t)
17158 (gnus-add-current-to-buffer-list)
17159 (get-buffer gnus-backlog-buffer))))
17160
17161 (defun gnus-backlog-setup ()
17162 "Initialize backlog variables."
17163 (unless gnus-backlog-hashtb
17164 (setq gnus-backlog-hashtb (make-vector 1023 0))))
17165
17166 (gnus-add-shutdown 'gnus-backlog-shutdown 'gnus)
17167
17168 (defun gnus-backlog-shutdown ()
17169 "Clear all backlog variables and buffers."
17170 (when (get-buffer gnus-backlog-buffer)
17171 (kill-buffer gnus-backlog-buffer))
17172 (setq gnus-backlog-hashtb nil
17173 gnus-backlog-articles nil))
17174
17175 (defun gnus-backlog-enter-article (group number buffer)
17176 (gnus-backlog-setup)
17177 (let ((ident (intern (concat group ":" (int-to-string number))
17178 gnus-backlog-hashtb))
17179 b)
17180 (if (memq ident gnus-backlog-articles)
17181 () ; It's already kept.
17182 ;; Remove the oldest article, if necessary.
17183 (and (numberp gnus-keep-backlog)
17184 (>= (length gnus-backlog-articles) gnus-keep-backlog)
17185 (gnus-backlog-remove-oldest-article))
17186 (setq gnus-backlog-articles (cons ident gnus-backlog-articles))
17187 ;; Insert the new article.
17188 (save-excursion
17189 (set-buffer (gnus-backlog-buffer))
17190 (let (buffer-read-only)
17191 (goto-char (point-max))
17192 (or (bolp) (insert "\n"))
17193 (setq b (point))
17194 (insert-buffer-substring buffer)
17195 ;; Tag the beginning of the article with the ident.
17196 (gnus-put-text-property b (1+ b) 'gnus-backlog ident))))))
17197
17198 (defun gnus-backlog-remove-oldest-article ()
17199 (save-excursion
17200 (set-buffer (gnus-backlog-buffer))
17201 (goto-char (point-min))
17202 (if (zerop (buffer-size))
17203 () ; The buffer is empty.
17204 (let ((ident (get-text-property (point) 'gnus-backlog))
17205 buffer-read-only)
17206 ;; Remove the ident from the list of articles.
17207 (when ident
17208 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
17209 ;; Delete the article itself.
17210 (delete-region
17211 (point) (next-single-property-change
17212 (1+ (point)) 'gnus-backlog nil (point-max)))))))
17213
17214 (defun gnus-backlog-remove-article (group number)
17215 "Remove article NUMBER in GROUP from the backlog."
17216 (when (numberp number)
17217 (gnus-backlog-setup)
17218 (let ((ident (intern (concat group ":" (int-to-string number))
17219 gnus-backlog-hashtb))
17220 beg end)
17221 (when (memq ident gnus-backlog-articles)
17222 ;; It was in the backlog.
17223 (save-excursion
17224 (set-buffer (gnus-backlog-buffer))
17225 (let (buffer-read-only)
17226 (when (setq beg (text-property-any
17227 (point-min) (point-max) 'gnus-backlog
17228 ident))
17229 ;; Find the end (i. e., the beginning of the next article).
17230 (setq end
17231 (next-single-property-change
17232 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))
17233 (delete-region beg end)
17234 ;; Return success.
17235 t)))))))
17236
17237 (defun gnus-backlog-request-article (group number buffer)
17238 (when (numberp number)
17239 (gnus-backlog-setup)
17240 (let ((ident (intern (concat group ":" (int-to-string number))
17241 gnus-backlog-hashtb))
17242 beg end)
17243 (when (memq ident gnus-backlog-articles)
17244 ;; It was in the backlog.
17245 (save-excursion
17246 (set-buffer (gnus-backlog-buffer))
17247 (if (not (setq beg (text-property-any
17248 (point-min) (point-max) 'gnus-backlog
17249 ident)))
17250 ;; It wasn't in the backlog after all.
17251 (ignore
17252 (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
17253 ;; Find the end (i. e., the beginning of the next article).
17254 (setq end
17255 (next-single-property-change
17256 (1+ beg) 'gnus-backlog (current-buffer) (point-max)))))
17257 (let ((buffer-read-only nil))
17258 (erase-buffer)
17259 (insert-buffer-substring gnus-backlog-buffer beg end)
17260 t)))))
17261
17262 ;; Allow redefinition of Gnus functions.
17263
17264 (gnus-ems-redefine)
17265
17266 (provide 'gnus)
17267
17268 ;;; gnus.el ends here