]> code.delx.au - gnu-emacs/blob - lisp/gnus.el
(gnus-gnus-to-newsrc-format): Turn off version-control
[gnu-emacs] / lisp / gnus.el
1 ;;; gnus.el --- a newsreader for GNU Emacs
2
3 ;; Copyright (C) 1987,88,89,90,93,94,95 Free Software Foundation, Inc.
4
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Although Gnus looks suspiciously like GNUS, it isn't quite the same
29 ;; beast. Most internal structures have been changed. If you have
30 ;; written packages that depend on any of the hash tables,
31 ;; `gnus-newsrc-alist', `gnus-killed-assoc', marked lists, the .newsrc
32 ;; buffer, or internal knowledge of the `nntp-header-' macros, or
33 ;; dependence on the buffers having a certain format, your code will
34 ;; fail.
35
36 ;;; Code:
37
38 (eval '(run-hooks 'gnus-load-hook))
39
40 (require 'mail-utils)
41 (require 'timezone)
42 (require 'nnheader)
43
44 ;; Site dependent variables. These variables should be defined in
45 ;; paths.el.
46
47 (defvar gnus-default-nntp-server nil
48 "Specify a default NNTP server.
49 This variable should be defined in paths.el, and should never be set
50 by the user.
51 If you want to change servers, you should use `gnus-select-method'.
52 See the documentation to that variable.")
53
54 (defconst gnus-backup-default-subscribed-newsgroups
55 '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus")
56 "Default default new newsgroups the first time Gnus is run.
57 Should be set in paths.el, and shouldn't be touched by the user.")
58
59 (defvar gnus-local-domain nil
60 "Local domain name without a host name.
61 The DOMAINNAME environment variable is used instead if it is defined.
62 If the `system-name' function returns the full Internet name, there is
63 no need to set this variable.")
64
65 (defvar gnus-local-organization nil
66 "String with a description of what organization (if any) the user belongs to.
67 The ORGANIZATION environment variable is used instead if it is defined.
68 If this variable contains a function, this function will be called
69 with the current newsgroup name as the argument. The function should
70 return a string.
71
72 In any case, if the string (either in the variable, in the environment
73 variable, or returned by the function) is a file name, the contents of
74 this file will be used as the organization.")
75
76 (defvar gnus-use-generic-from nil
77 "If nil, the full host name will be the system name prepended to the domain name.
78 If this is a string, the full host name will be this string.
79 If this is non-nil, non-string, the domain name will be used as the
80 full host name.")
81
82 (defvar gnus-use-generic-path nil
83 "If nil, use the NNTP server name in the Path header.
84 If stringp, use this; if non-nil, use no host name (user name only).")
85
86
87 ;; Customization variables
88
89 ;; Don't touch this variable.
90 (defvar gnus-nntp-service "nntp"
91 "*NNTP service name (\"nntp\" or 119).
92 This is an obsolete variable, which is scarcely used. If you use an
93 nntp server for your newsgroup and want to change the port number
94 used to 899, you would say something along these lines:
95
96 (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))")
97
98 (defvar gnus-select-method
99 (nconc
100 (list 'nntp (or (getenv "NNTPSERVER")
101 (if (and gnus-default-nntp-server
102 (not (string= gnus-default-nntp-server "")))
103 gnus-default-nntp-server)
104 (system-name)))
105 (if (or (null gnus-nntp-service)
106 (equal gnus-nntp-service "nntp"))
107 nil
108 (list gnus-nntp-service)))
109 "*Default method for selecting a newsgroup.
110 This variable should be a list, where the first element is how the
111 news is to be fetched, the second is the address.
112
113 For instance, if you want to get your news via NNTP from
114 \"flab.flab.edu\", you could say:
115
116 (setq gnus-select-method '(nntp \"flab.flab.edu\"))
117
118 If you want to use your local spool, say:
119
120 (setq gnus-select-method (list 'nnspool (system-name)))
121
122 If you use this variable, you must set `gnus-nntp-server' to nil.
123
124 There is a lot more to know about select methods and virtual servers -
125 see the manual for details.")
126
127 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
128 (defvar gnus-post-method nil
129 "*Preferred method for posting USENET news.
130 If this variable is nil, Gnus will use the current method to decide
131 which method to use when posting. If it is non-nil, it will override
132 the current method. This method will not be used in mail groups and
133 the like, only in \"real\" newsgroups.
134
135 The value must be a valid method as discussed in the documentation of
136 `gnus-select-method'.")
137
138 (defvar gnus-refer-article-method nil
139 "*Preferred method for fetching an article by Message-ID.
140 If you are reading news from the local spool (with nnspool), fetching
141 articles by Message-ID is painfully slow. By setting this method to an
142 nntp method, you might get acceptable results.
143
144 The value of this variable must be a valid select method as discussed
145 in the documentation of `gnus-select-method'")
146
147 (defvar gnus-secondary-select-methods nil
148 "*A list of secondary methods that will be used for reading news.
149 This is a list where each element is a complete select method (see
150 `gnus-select-method').
151
152 If, for instance, you want to read your mail with the nnml backend,
153 you could set this variable:
154
155 (setq gnus-secondary-select-methods '((nnml \"\")))")
156
157 (defvar gnus-secondary-servers nil
158 "*List of NNTP servers that the user can choose between interactively.
159 To make Gnus query you for a server, you have to give `gnus' a
160 non-numeric prefix - `C-u M-x gnus', in short.")
161
162 (defvar gnus-nntp-server nil
163 "*The name of the host running the NNTP server.
164 This variable is semi-obsolete. Use the `gnus-select-method'
165 variable instead.")
166
167 (defvar gnus-startup-file "~/.newsrc"
168 "*Your `.newsrc' file.
169 `.newsrc-SERVER' will be used instead if that exists.")
170
171 (defvar gnus-init-file "~/.gnus"
172 "*Your Gnus elisp startup file.
173 If a file with the .el or .elc suffixes exist, it will be read
174 instead.")
175
176 (defvar gnus-group-faq-directory
177 "/ftp@mirrors.aol.com:/pub/rtfm/usenet/"
178 "*Directory where the group FAQs are stored.
179 This will most commonly be on a remote machine, and the file will be
180 fetched by ange-ftp.
181
182 Note that Gnus uses an aol machine as the default directory. If this
183 feels fundamentally unclean, just think of it as a way to finally get
184 something of value back from them.
185
186 If the default site is too slow, try one of these:
187
188 North America: ftp.uu.net /usenet/news.answers
189 mirrors.aol.com /pub/rtfm/usenet
190 ftp.seas.gwu.edu /pub/rtfm
191 rtfm.mit.edu /pub/usenet/news.answers
192 Europe: ftp.uni-paderborn.de /pub/FAQ
193 ftp.Germany.EU.net /pub/newsarchive/news.answers
194 ftp.sunet.se /pub/usenet
195 Asia: nctuccca.edu.tw /USENET/FAQ
196 hwarang.postech.ac.kr /pub/usenet/news.answers
197 ftp.hk.super.net /mirror/faqs")
198
199 (defvar gnus-group-archive-directory
200 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
201 "*The address of the (ding) archives.")
202
203 (defvar gnus-group-recent-archive-directory
204 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
205 "*The address of the most recent (ding) articles.")
206
207 (defvar gnus-default-subscribed-newsgroups nil
208 "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
209 It should be a list of strings.
210 If it is `t', Gnus will not do anything special the first time it is
211 started; it'll just use the normal newsgroups subscription methods.")
212
213 (defvar gnus-use-cross-reference t
214 "*Non-nil means that cross referenced articles will be marked as read.
215 If nil, ignore cross references. If t, mark articles as read in
216 subscribed newsgroups. If neither t nor nil, mark as read in all
217 newsgroups.")
218
219 (defvar gnus-use-dribble-file t
220 "*Non-nil means that Gnus will use a dribble file to store user updates.
221 If Emacs should crash without saving the .newsrc files, complete
222 information can be restored from the dribble file.")
223
224 (defvar gnus-asynchronous nil
225 "*If non-nil, Gnus will supply backends with data needed for async article fetching.")
226
227 (defvar gnus-asynchronous-article-function nil
228 "*Function for picking articles to pre-fetch, possibly.")
229
230 (defvar gnus-score-file-single-match-alist nil
231 "*Alist mapping regexps to lists of score files.
232 Each element of this alist should be of the form
233 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
234
235 If the name of a group is matched by REGEXP, the corresponding scorefiles
236 will be used for that group.
237 The first match found is used, subsequent matching entries are ignored (to
238 use multiple matches, see gnus-score-file-multiple-match-alist).
239
240 These score files are loaded in addition to any files returned by
241 gnus-score-find-score-files-function (which see).")
242
243 (defvar gnus-score-file-multiple-match-alist nil
244 "*Alist mapping regexps to lists of score files.
245 Each element of this alist should be of the form
246 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
247
248 If the name of a group is matched by REGEXP, the corresponding scorefiles
249 will be used for that group.
250 If multiple REGEXPs match a group, the score files corresponding to each
251 match will be used (for only one match to be used, see
252 gnus-score-file-single-match-alist).
253
254 These score files are loaded in addition to any files returned by
255 gnus-score-find-score-files-function (which see).")
256
257
258 (defvar gnus-score-file-suffix "SCORE"
259 "*Suffix of the score files.")
260
261 (defvar gnus-adaptive-file-suffix "ADAPT"
262 "*Suffix of the adaptive score files.")
263
264 (defvar gnus-score-find-score-files-function 'gnus-score-find-bnews
265 "*Function used to find score files.
266 The function will be called with the group name as the argument, and
267 should return a list of score files to apply to that group. The score
268 files do not actually have to exist.
269
270 Predefined values are:
271
272 gnus-score-find-single: Only apply the group's own score file.
273 gnus-score-find-hierarchical: Also apply score files from parent groups.
274 gnus-score-find-bnews: Apply score files whose names matches.
275
276 See the documentation to these functions for more information.
277
278 This variable can also be a list of functions to be called. Each
279 function should either return a list of score files, or a list of
280 score alists.")
281
282 (defvar gnus-score-interactive-default-score 1000
283 "*Scoring commands will raise/lower the score with this number as the default.")
284
285 (defvar gnus-large-newsgroup 200
286 "*The number of articles which indicates a large newsgroup.
287 If the number of articles in a newsgroup is greater than this value,
288 confirmation is required for selecting the newsgroup.")
289
290 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
291 (defvar gnus-no-groups-message "No news is horrible news"
292 "*Message displayed by Gnus when no groups are available.")
293
294 (defvar gnus-use-long-file-name (not (memq system-type '(usg-unix-v xenix)))
295 "*Non-nil means that the default name of a file to save articles in is the group name.
296 If it's nil, the directory form of the group name is used instead.
297
298 If this variable is a list, and the list contains the element
299 `not-score', long file names will not be used for score files; if it
300 contains the element `not-save', long file names will not be used for
301 saving; and if it contains the element `not-kill', long file names
302 will not be used for kill files.")
303
304 (defvar gnus-article-save-directory (or (getenv "SAVEDIR") "~/News/")
305 "*Name of the directory articles will be saved in (default \"~/News\").
306 Initialized from the SAVEDIR environment variable.")
307
308 (defvar gnus-kill-files-directory (or (getenv "SAVEDIR") "~/News/")
309 "*Name of the directory where kill files will be stored (default \"~/News\").
310 Initialized from the SAVEDIR environment variable.")
311
312 (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
313 "*A function to save articles in your favorite format.
314 The function must be interactively callable (in other words, it must
315 be an Emacs command).
316
317 Gnus provides the following functions:
318
319 * gnus-summary-save-in-rmail (Rmail format)
320 * gnus-summary-save-in-mail (Unix mail format)
321 * gnus-summary-save-in-folder (MH folder)
322 * gnus-summary-save-in-file (article format).
323 * gnus-summary-save-in-vm (use VM's folder format).")
324
325 (defvar gnus-rmail-save-name (function gnus-plain-save-name)
326 "*A function generating a file name to save articles in Rmail format.
327 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
328
329 (defvar gnus-mail-save-name (function gnus-plain-save-name)
330 "*A function generating a file name to save articles in Unix mail format.
331 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
332
333 (defvar gnus-folder-save-name (function gnus-folder-save-name)
334 "*A function generating a file name to save articles in MH folder.
335 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
336
337 (defvar gnus-file-save-name (function gnus-numeric-save-name)
338 "*A function generating a file name to save articles in article format.
339 The function is called with NEWSGROUP, HEADERS, and optional
340 LAST-FILE.")
341
342 (defvar gnus-split-methods nil
343 "*Variable used to suggest where articles are to be saved.
344 The syntax of this variable is the same as `nnmail-split-methods'.
345
346 For instance, if you would like to save articles related to Gnus in
347 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
348 you could set this variable to something like:
349
350 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
351 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))")
352
353 (defvar gnus-save-score nil
354 "*If non-nil, save group scoring info.")
355
356 (defvar gnus-use-adaptive-scoring nil
357 "*If non-nil, use some adaptive scoring scheme.")
358
359 (defvar gnus-use-cache nil
360 "*If non-nil, Gnus will cache (some) articles locally.")
361
362 (defvar gnus-use-scoring t
363 "*If non-nil, enable scoring.")
364
365 (defvar gnus-fetch-old-headers nil
366 "*Non-nil means that Gnus will try to build threads by grabbing old headers.
367 If an unread article in the group refers to an older, already read (or
368 just marked as read) article, the old article will not normally be
369 displayed in the Summary buffer. If this variable is non-nil, Gnus
370 will attempt to grab the headers to the old articles, and thereby
371 build complete threads. If it has the value `some', only enough
372 headers to connect otherwise loose threads will be displayed.
373
374 The server has to support XOVER for any of this to work.")
375
376 ;see gnus-cus.el
377 ;(defvar gnus-visual t
378 ; "*If non-nil, will do various highlighting.
379 ;If nil, no mouse highlights (or any other highlights) will be
380 ;performed. This might speed up Gnus some when generating large group
381 ;and summary buffers.")
382
383 (defvar gnus-novice-user t
384 "*Non-nil means that you are a usenet novice.
385 If non-nil, verbose messages may be displayed and confirmations may be
386 required.")
387
388 (defvar gnus-expert-user nil
389 "*Non-nil means that you will never be asked for confirmation about anything.
390 And that means *anything*.")
391
392 (defvar gnus-verbose 7
393 "*Integer that says how verbose Gnus should be.
394 The higher the number, the more messages Gnus will flash to say what
395 it's doing. At zero, Gnus will be totally mute; at five, Gnus will
396 display most important messages; and at ten, Gnus will keep on
397 jabbering all the time.")
398
399 (defvar gnus-keep-same-level nil
400 "*Non-nil means that the next newsgroup after the current will be on the same level.
401 When you type, for instance, `n' after reading the last article in the
402 current newsgroup, you will go to the next newsgroup. If this variable
403 is nil, the next newsgroup will be the next from the group
404 buffer.
405 If this variable is non-nil, Gnus will either put you in the
406 next newsgroup with the same level, or, if no such newsgroup is
407 available, the next newsgroup with the lowest possible level higher
408 than the current level.
409 If this variable is `best', Gnus will make the next newsgroup the one
410 with the best level.")
411
412 (defvar gnus-summary-make-false-root 'adopt
413 "*nil means that Gnus won't gather loose threads.
414 If the root of a thread has expired or been read in a previous
415 session, the information necessary to build a complete thread has been
416 lost. Instead of having many small sub-threads from this original thread
417 scattered all over the summary buffer, Gnus can gather them.
418
419 If non-nil, Gnus will try to gather all loose sub-threads from an
420 original thread into one large thread.
421
422 If this variable is non-nil, it should be one of `none', `adopt',
423 `dummy' or `empty'.
424
425 If this variable is `none', Gnus will not make a false root, but just
426 present the sub-threads after another.
427 If this variable is `dummy', Gnus will create a dummy root that will
428 have all the sub-threads as children.
429 If this variable is `adopt', Gnus will make one of the \"children\"
430 the parent and mark all the step-children as such.
431 If this variable is `empty', the \"children\" are printed with empty
432 subject fields. (Or rather, they will be printed with a string
433 given by the `gnus-summary-same-subject' variable.)")
434
435 (defvar gnus-summary-gather-subject-limit nil
436 "*Maximum length of subject comparisons when gathering loose threads.
437 Use nil to compare full subjects. Setting this variable to a low
438 number will help gather threads that have been corrupted by
439 newsreaders chopping off subject lines, but it might also mean that
440 unrelated articles that have subject that happen to begin with the
441 same few characters will be incorrectly gathered.
442
443 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
444 comparing subjects.")
445
446 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
447 (defvar gnus-summary-same-subject ""
448 "*String indicating that the current article has the same subject as the previous.
449 This variable will only be used if the value of
450 `gnus-summary-make-false-root' is `empty'.")
451
452 (defvar gnus-summary-goto-unread t
453 "*If non-nil, marking commands will go to the next unread article.")
454
455 (defvar gnus-group-goto-unread t
456 "*If non-nil, movement commands will go to the next unread and subscribed group.")
457
458 (defvar gnus-check-new-newsgroups t
459 "*Non-nil means that Gnus will add new newsgroups at startup.
460 If this variable is `ask-server', Gnus will ask the server for new
461 groups since the last time it checked. This means that the killed list
462 is no longer necessary, so you could set `gnus-save-killed-list' to
463 nil.
464
465 A variant is to have this variable be a list of select methods. Gnus
466 will then use the `ask-server' method on all these select methods to
467 query for new groups from all those servers.
468
469 Eg.
470 (setq gnus-check-new-newsgroups
471 '((nntp \"some.server\") (nntp \"other.server\")))
472
473 If this variable is nil, then you have to tell Gnus explicitly to
474 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
475
476 (defvar gnus-check-bogus-newsgroups nil
477 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
478 If this variable is nil, then you have to tell Gnus explicitly to
479 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
480
481 (defvar gnus-read-active-file t
482 "*Non-nil means that Gnus will read the entire active file at startup.
483 If this variable is nil, Gnus will only know about the groups in your
484 `.newsrc' file.
485
486 If this variable is `some', Gnus will try to only read the relevant
487 parts of the active file from the server. Not all servers support
488 this, and it might be quite slow with other servers, but this should
489 generally be faster than both the t and nil value.
490
491 If you set this variable to nil or `some', you probably still want to
492 be told about new newsgroups that arrive. To do that, set
493 `gnus-check-new-newsgroups' to `ask-server'. This may not work
494 properly with all servers.")
495
496 (defvar gnus-level-subscribed 5
497 "*Groups with levels less than or equal to this variable are subscribed.")
498
499 (defvar gnus-level-unsubscribed 7
500 "*Groups with levels less than or equal to this variable are unsubscribed.
501 Groups with levels less than `gnus-level-subscribed', which should be
502 less than this variable, are subscribed.")
503
504 (defvar gnus-level-zombie 8
505 "*Groups with this level are zombie groups.")
506
507 (defvar gnus-level-killed 9
508 "*Groups with this level are killed.")
509
510 (defvar gnus-level-default-subscribed 3
511 "*New subscribed groups will be subscribed at this level.")
512
513 (defvar gnus-level-default-unsubscribed 6
514 "*New unsubscribed groups will be unsubscribed at this level.")
515
516 (defvar gnus-activate-foreign-newsgroups 4
517 "*If nil, Gnus will not check foreign newsgroups at startup.
518 If it is non-nil, it should be a number between one and nine. Foreign
519 newsgroups that have a level lower or equal to this number will be
520 activated on startup. For instance, if you want to active all
521 subscribed newsgroups, but not the rest, you'd set this variable to
522 `gnus-level-subscribed'.
523
524 If you subscribe to lots of newsgroups from different servers, startup
525 might take a while. By setting this variable to nil, you'll save time,
526 but you won't be told how many unread articles there are in the
527 groups.")
528
529 (defvar gnus-save-newsrc-file t
530 "*Non-nil means that Gnus will save the `.newsrc' file.
531 Gnus always saves its own startup file, which is called
532 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
533 be readily understood by other newsreaders. If you don't plan on
534 using other newsreaders, set this variable to nil to save some time on
535 exit.")
536
537 (defvar gnus-save-killed-list t
538 "*If non-nil, save the list of killed groups to the startup file.
539 This will save both time (when starting and quitting) and space (both
540 memory and disk), but it will also mean that Gnus has no record of
541 which groups are new and which are old, so the automatic new
542 newsgroups subscription methods become meaningless. You should always
543 set `gnus-check-new-newsgroups' to `ask-server' or nil if you set this
544 variable to nil.")
545
546 (defvar gnus-interactive-catchup t
547 "*If non-nil, require your confirmation when catching up a group.")
548
549 (defvar gnus-interactive-post t
550 "*If non-nil, group name will be asked for when posting.")
551
552 (defvar gnus-interactive-exit t
553 "*If non-nil, require your confirmation when exiting Gnus.")
554
555 (defvar gnus-kill-killed t
556 "*If non-nil, Gnus will apply kill files to already killed articles.
557 If it is nil, Gnus will never apply kill files to articles that have
558 already been through the scoring process, which might very well save lots
559 of time.")
560
561 (defvar gnus-extract-address-components 'gnus-extract-address-components
562 "*Function for extracting address components from a From header.
563 Two pre-defined function exist: `gnus-extract-address-components',
564 which is the default, quite fast, and too simplistic solution, and
565 `mail-extract-address-components', which works much better, but is
566 slower.")
567
568 (defvar gnus-summary-default-score 0
569 "*Default article score level.
570 If this variable is nil, scoring will be disabled.")
571
572 (defvar gnus-summary-zcore-fuzz 0
573 "*Fuzziness factor for the zcore in the summary buffer.
574 Articles with scores closer than this to `gnus-summary-default-score'
575 will not be marked.")
576
577 (defvar gnus-simplify-subject-fuzzy-regexp nil
578 "*Regular expression that will be removed from subject strings if
579 fuzzy subject simplification is selected.")
580
581 (defvar gnus-group-default-list-level gnus-level-subscribed
582 "*Default listing level.
583 Ignored if `gnus-group-use-permanent-levels' is non-nil.")
584
585 (defvar gnus-group-use-permanent-levels nil
586 "*If non-nil, once you set a level, Gnus will use this level.")
587
588 (defvar gnus-show-mime nil
589 "*If non-nil, do mime processing of articles.
590 The articles will simply be fed to the function given by
591 `gnus-show-mime-method'.")
592
593 (defvar gnus-strict-mime t
594 "*If nil, decode MIME header even if there is not Mime-Version field.")
595
596 (defvar gnus-show-mime-method (function metamail-buffer)
597 "*Function to process a MIME message.
598 The function is called from the article buffer.")
599
600 (defvar gnus-show-threads t
601 "*If non-nil, display threads in summary mode.")
602
603 (defvar gnus-thread-hide-subtree nil
604 "*If non-nil, hide all threads initially.
605 If threads are hidden, you have to run the command
606 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
607 to expose hidden threads.")
608
609 (defvar gnus-thread-hide-killed t
610 "*If non-nil, hide killed threads automatically.")
611
612 (defvar gnus-thread-ignore-subject nil
613 "*If non-nil, ignore subjects and do all threading based on the Reference header.
614 If nil, which is the default, articles that have different subjects
615 from their parents will start separate threads.")
616
617 (defvar gnus-thread-indent-level 4
618 "*Number that says how much each sub-thread should be indented.")
619
620 (defvar gnus-ignored-newsgroups
621 (purecopy (mapconcat 'identity
622 '("^to\\." ; not "real" groups
623 "^[0-9. \t]+ " ; all digits in name
624 "[][\"#'()]" ; bogus characters
625 )
626 "\\|"))
627 "*A regexp to match uninteresting newsgroups in the active file.
628 Any lines in the active file matching this regular expression are
629 removed from the newsgroup list before anything else is done to it,
630 thus making them effectively non-existent.")
631
632 (defvar gnus-ignored-headers
633 "^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:"
634 "*All headers that match this regexp will be hidden.
635 If `gnus-visible-headers' is non-nil, this variable will be ignored.")
636
637 (defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:"
638 "*All headers that do not match this regexp will be hidden.
639 If this variable is non-nil, `gnus-ignored-headers' will be ignored.")
640
641 (defvar gnus-sorted-header-list
642 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:"
643 "^Cc:" "^Date:" "^Organization:")
644 "*This variable is a list of regular expressions.
645 If it is non-nil, headers that match the regular expressions will
646 be placed first in the article buffer in the sequence specified by
647 this list.")
648
649 (defvar gnus-show-all-headers nil
650 "*If non-nil, don't hide any headers.")
651
652 (defvar gnus-save-all-headers t
653 "*If non-nil, don't remove any headers before saving.")
654
655 (defvar gnus-inhibit-startup-message nil
656 "*If non-nil, the startup message will not be displayed.")
657
658 (defvar gnus-signature-separator "^-- *$"
659 "Regexp matching signature separator.")
660
661 (defvar gnus-auto-extend-newsgroup t
662 "*If non-nil, extend newsgroup forward and backward when requested.")
663
664 (defvar gnus-auto-select-first t
665 "*If non-nil, select the first unread article when entering a group.
666 If you want to prevent automatic selection of the first unread article
667 in some newsgroups, set the variable to nil in
668 `gnus-select-group-hook'.")
669
670 (defvar gnus-auto-select-next t
671 "*If non-nil, offer to go to the next group from the end of the previous.
672 If the value is t and the next newsgroup is empty, Gnus will exit
673 summary mode and go back to group mode. If the value is neither nil
674 nor t, Gnus will select the following unread newsgroup. In
675 particular, if the value is the symbol `quietly', the next unread
676 newsgroup will be selected without any confirmations.")
677
678 (defvar gnus-auto-select-same nil
679 "*If non-nil, select the next article with the same subject.")
680
681 (defvar gnus-summary-check-current nil
682 "*If non-nil, consider the current article when moving.
683 The \"unread\" movement commands will stay on the same line if the
684 current article is unread.")
685
686 (defvar gnus-auto-center-summary t
687 "*If non-nil, always center the current summary buffer.")
688
689 (defvar gnus-break-pages t
690 "*If non-nil, do page breaking on articles.
691 The page delimiter is specified by the `gnus-page-delimiter'
692 variable.")
693
694 (defvar gnus-page-delimiter "^\^L"
695 "*Regexp describing what to use as article page delimiters.
696 The default value is \"^\^L\", which is a form linefeed at the
697 beginning of a line.")
698
699 (defvar gnus-use-full-window t
700 "*If non-nil, use the entire Emacs screen.")
701
702 (defvar gnus-window-configuration nil
703 "Obsolete variable. See `gnus-buffer-configuration'.")
704
705 (defvar gnus-buffer-configuration
706 '((group ([group 1.0 point]
707 (if gnus-carpal [group-carpal 4])))
708 (summary ([summary 1.0 point]
709 (if gnus-carpal [summary-carpal 4])))
710 (article ([summary 0.25 point]
711 (if gnus-carpal [summary-carpal 4])
712 [article 1.0]))
713 (server ([server 1.0 point]
714 (if gnus-carpal [server-carpal 2])))
715 (browse ([browse 1.0 point]
716 (if gnus-carpal [browse-carpal 2])))
717 (group-mail ([mail 1.0 point]))
718 (summary-mail ([mail 1.0 point]))
719 (summary-reply ([article 0.5]
720 [mail 1.0 point]))
721 (info ([nil 1.0 point]))
722 (summary-faq ([summary 0.25]
723 [faq 1.0 point]))
724 (edit-group ([group 0.5]
725 [edit-group 1.0 point]))
726 (edit-server ([server 0.5]
727 [edit-server 1.0 point]))
728 (edit-score ([summary 0.25]
729 [edit-score 1.0 point]))
730 (post ([post 1.0 point]))
731 (reply ([article 0.5]
732 [mail 1.0 point]))
733 (mail-forward ([mail 1.0 point]))
734 (post-forward ([post 1.0 point]))
735 (reply-yank ([mail 1.0 point]))
736 (followup ([article 0.5]
737 [post 1.0 point]))
738 (followup-yank ([post 1.0 point])))
739 "Window configuration for all possible Gnus buffers.
740 This variable is a list of lists. Each of these lists has a NAME and
741 a RULE. The NAMEs are common-sense names like `group', which names a
742 rule used when displaying the group buffer; `summary', which names a
743 rule for what happens when you enter a group and do not display an
744 article buffer; and so on. See the value of this variable for a
745 complete list of NAMEs.
746
747 Each RULE is a list of vectors. The first element in this vector is
748 the name of the buffer to be displayed; the second element is the
749 percentage of the screen this buffer is to occupy (a number in the
750 0.0-0.99 range); the optional third element is `point', which should
751 be present to denote which buffer point is to go to after making this
752 buffer configuration.")
753
754 (defvar gnus-window-to-buffer
755 '((group . gnus-group-buffer)
756 (summary . gnus-summary-buffer)
757 (article . gnus-article-buffer)
758 (server . gnus-server-buffer)
759 (browse . "*Gnus Browse Server*")
760 (edit-group . gnus-group-edit-buffer)
761 (edit-server . gnus-server-edit-buffer)
762 (group-carpal . gnus-carpal-group-buffer)
763 (summary-carpal . gnus-carpal-summary-buffer)
764 (server-carpal . gnus-carpal-server-buffer)
765 (browse-carpal . gnus-carpal-browse-buffer)
766 (edit-score . gnus-score-edit-buffer)
767 (mail . gnus-mail-buffer)
768 (post . gnus-post-news-buffer)
769 (faq . gnus-faq-buffer))
770 "Mapping from short symbols to buffer names or buffer variables.")
771
772 (defvar gnus-carpal nil
773 "*If non-nil, display clickable icons.")
774
775 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
776 "*Function called with a group name when new group is detected.
777 A few pre-made functions are supplied: `gnus-subscribe-randomly'
778 inserts new groups at the beginning of the list of groups;
779 `gnus-subscribe-alphabetically' inserts new groups in strict
780 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
781 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
782 for your decision.")
783
784 ;; Suggested by a bug report by Hallvard B Furuseth.
785 ;; <h.b.furuseth@usit.uio.no>.
786 (defvar gnus-subscribe-options-newsgroup-method
787 (function gnus-subscribe-alphabetically)
788 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
789 If, for instance, you want to subscribe to all newsgroups in the
790 \"no\" and \"alt\" hierarchies, you'd put the following in your
791 .newsrc file:
792
793 options -n no.all alt.all
794
795 Gnus will the subscribe all new newsgroups in these hierarchies with
796 the subscription method in this variable.")
797
798 (defvar gnus-subscribe-hierarchical-interactive nil
799 "*If non-nil, Gnus will offer to subscribe hierarchically.
800 When a new hierarchy appears, Gnus will ask the user:
801
802 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
803
804 If the user pressed `d', Gnus will descend the hierarchy, `y' will
805 subscribe to all newsgroups in the hierarchy and `s' will skip this
806 hierarchy in its entirety.")
807
808 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
809 "*Function used for sorting the group buffer.
810 This function will be called with group info entries as the arguments
811 for the groups to be sorted. Pre-made functions include
812 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread' and
813 `gnus-group-sort-by-level'")
814
815 ;; Mark variables suggested by Thomas Michanek
816 ;; <Thomas.Michanek@telelogic.se>.
817 (defvar gnus-unread-mark ?
818 "*Mark used for unread articles.")
819 (defvar gnus-ticked-mark ?!
820 "*Mark used for ticked articles.")
821 (defvar gnus-dormant-mark ??
822 "*Mark used for dormant articles.")
823 (defvar gnus-del-mark ?r
824 "*Mark used for del'd articles.")
825 (defvar gnus-read-mark ?R
826 "*Mark used for read articles.")
827 (defvar gnus-expirable-mark ?E
828 "*Mark used for expirable articles.")
829 (defvar gnus-killed-mark ?K
830 "*Mark used for killed articles.")
831 (defvar gnus-kill-file-mark ?X
832 "*Mark used for articles killed by kill files.")
833 (defvar gnus-low-score-mark ?Y
834 "*Mark used for articles with a low score.")
835 (defvar gnus-catchup-mark ?C
836 "*Mark used for articles that are caught up.")
837 (defvar gnus-replied-mark ?A
838 "*Mark used for articles that have been replied to.")
839 (defvar gnus-process-mark ?#
840 "*Process mark.")
841 (defvar gnus-ancient-mark ?O
842 "*Mark used for ancient articles.")
843 (defvar gnus-canceled-mark ?G
844 "*Mark used for canceled articles.")
845 (defvar gnus-score-over-mark ?+
846 "*Score mark used for articles with high scores.")
847 (defvar gnus-score-below-mark ?-
848 "*Score mark used for articles with low scores.")
849 (defvar gnus-empty-thread-mark ?
850 "*There is no thread under the article.")
851 (defvar gnus-not-empty-thread-mark ?=
852 "*There is a thread under the article.")
853 (defvar gnus-dummy-mark ?Z
854 "*This is a dummy article.")
855
856 (defvar gnus-view-pseudo-asynchronously nil
857 "*If non-nil, Gnus will view pseudo-articles asynchronously.")
858
859 (defvar gnus-view-pseudos nil
860 "*If `automatic', pseudo-articles will be viewed automatically.
861 If `not-confirm', pseudos will be viewed automatically, and the user
862 will not be asked to confirm the command.")
863
864 (defvar gnus-view-pseudos-separately t
865 "*If non-nil, one pseudo-article will be created for each file to be viewed.
866 If nil, all files that use the same viewing command will be given as a
867 list of parameters to that command.")
868
869 (defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n"
870 "*Format of group lines.
871 It works along the same lines as a normal formatting string,
872 with some simple extensions.
873
874 %M Only marked articles (character, \"*\" or \" \")
875 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
876 %L Level of subscribedness (integer)
877 %N Number of unread articles (integer)
878 %I Number of dormant articles (integer)
879 %i Number of ticked and dormant (integer)
880 %T Number of ticked articles (integer)
881 %R Number of read articles (integer)
882 %t Total number of articles (integer)
883 %y Number of unread, unticked articles (integer)
884 %G Group name (string)
885 %g Qualified group name (string)
886 %D Group description (string)
887 %s Select method (string)
888 %o Moderated group (char, \"m\")
889 %p Process mark (char)
890 %O Moderated group (string, \"(m)\" or \"\")
891 %n Select from where (string)
892 %z A string that look like `<%s:%n>' if a foreign select method is used
893 %u User defined specifier. The next character in the format string should
894 be a letter. Gnus will call the function gnus-user-format-function-X,
895 where X is the letter following %u. The function will be passed the
896 current header as argument. The function should return a string, which
897 will be inserted into the buffer just like information from any other
898 group specifier.
899
900 Text between %( and %) will be highlighted with `gnus-mouse-face' when
901 the mouse point move inside the area. There can only be one such area.
902
903 Note that this format specification is not always respected. For
904 reasons of efficiency, when listing killed groups, this specification
905 is ignored altogether. If the spec is changed considerably, your
906 output may end up looking strange when listing both alive and killed
907 groups.
908
909 If you use %o or %O, reading the active file will be slower and quite
910 a bit of extra memory will be used. %D will also worsen performance.
911 Also note that if you change the format specification to include any
912 of these specs, you must probably re-start Gnus to see them go into
913 effect.")
914
915 (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
916 "*The format specification of the lines in the summary buffer.
917
918 It works along the same lines as a normal formatting string,
919 with some simple extensions.
920
921 %N Article number, left padded with spaces (string)
922 %S Subject (string)
923 %s Subject if it is at the root of a thread, and \"\" otherwise (string)
924 %n Name of the poster (string)
925 %a Extracted name of the poster (string)
926 %A Extracted address of the poster (string)
927 %F Contents of the From: header (string)
928 %x Contents of the Xref: header (string)
929 %D Date of the article (string)
930 %d Date of the article (string) in DD-MMM format
931 %M Message-id of the article (string)
932 %r References of the article (string)
933 %c Number of characters in the article (integer)
934 %L Number of lines in the article (integer)
935 %I Indentation based on thread level (a string of spaces)
936 %T A string with two possible values: 80 spaces if the article
937 is on thread level two or larger and 0 spaces on level one
938 %R \"A\" if this article has been replied to, \" \" otherwise (character)
939 %U Status of this article (character, \"R\", \"K\", \"-\" or \" \")
940 %[ Opening bracket (character, \"[\" or \"<\")
941 %] Closing bracket (character, \"]\" or \">\")
942 %> Spaces of length thread-level (string)
943 %< Spaces of length (- 20 thread-level) (string)
944 %i Article score (number)
945 %z Article zcore (character)
946 %t Number of articles under the current thread (number).
947 %e Whether the thread is empty or not (character).
948 %u User defined specifier. The next character in the format string should
949 be a letter. Gnus will call the function gnus-user-format-function-X,
950 where X is the letter following %u. The function will be passed the
951 current header as argument. The function should return a string, which
952 will be inserted into the summary just like information from any other
953 summary specifier.
954
955 Text between %( and %) will be highlighted with `gnus-mouse-face'
956 when the mouse point is placed inside the area. There can only be one
957 such area.
958
959 The %U (status), %R (replied) and %z (zcore) specs have to be handled
960 with care. For reasons of efficiency, Gnus will compute what column
961 these characters will end up in, and \"hard-code\" that. This means that
962 it is illegal to have these specs after a variable-length spec. Well,
963 you might not be arrested, but your summary buffer will look strange,
964 which is bad enough.
965
966 The smart choice is to have these specs as for to the left as
967 possible.
968
969 This restriction may disappear in later versions of Gnus.")
970
971 (defvar gnus-summary-dummy-line-format "* : : %S\n"
972 "*The format specification for the dummy roots in the summary buffer.
973 It works along the same lines as a normal formatting string,
974 with some simple extensions.
975
976 %S The subject")
977
978 (defvar gnus-summary-mode-line-format "Gnus: %b [%A] %Z"
979 "*The format specification for the summary mode line.")
980
981 (defvar gnus-article-mode-line-format "Gnus: %b %S"
982 "*The format specification for the article mode line.")
983
984 (defvar gnus-group-mode-line-format "Gnus: %b {%M:%S} "
985 "*The format specification for the group mode line.")
986
987 (defvar gnus-valid-select-methods
988 '(("nntp" post address prompt-address)
989 ("nnspool" post)
990 ("nnvirtual" none virtual prompt-address)
991 ("nnmbox" mail respool)
992 ("nnml" mail respool)
993 ("nnmh" mail respool)
994 ("nndir" none prompt-address address)
995 ("nneething" none prompt-address)
996 ("nndigest" none)
997 ("nndoc" none prompt-address)
998 ("nnbabyl" mail respool)
999 ("nnkiboze" post virtual)
1000 ;;("nnsoup" post)
1001 ("nnfolder" mail respool))
1002 "An alist of valid select methods.
1003 The first element of each list lists should be a string with the name
1004 of the select method. The other elements may be be the category of
1005 this method (ie. `post', `mail', `none' or whatever) or other
1006 properties that this method has (like being respoolable).
1007 If you implement a new select method, all you should have to change is
1008 this variable. I think.")
1009
1010 (defvar gnus-updated-mode-lines '(group article summary)
1011 "*List of buffers that should update their mode lines.
1012 The list may contain the symbols `group', `article' and `summary'. If
1013 the corresponding symbol is present, Gnus will keep that mode line
1014 updated with information that may be pertinent.
1015 If this variable is nil, screen refresh may be quicker.")
1016
1017 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1018 (defvar gnus-mode-non-string-length nil
1019 "*Max length of mode-line non-string contents.
1020 If this is nil, Gnus will take space as is needed, leaving the rest
1021 of the modeline intact.")
1022
1023 ;see gnus-cus.el
1024 ;(defvar gnus-mouse-face 'highlight
1025 ; "*Face used for mouse highlighting in Gnus.
1026 ;No mouse highlights will be done if `gnus-visual' is nil.")
1027
1028 (defvar gnus-summary-mark-below nil
1029 "*Mark all articles with a score below this variable as read.
1030 This variable is local to each summary buffer and usually set by the
1031 score file.")
1032
1033 (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
1034 "*List of functions used for sorting threads in the summary buffer.
1035 By default, threads are sorted by article number.
1036
1037 Each function takes two threads and return non-nil if the first thread
1038 should be sorted before the other. If you use more than one function,
1039 the primary sort function should be the last.
1040
1041 Ready-mady functions include `gnus-thread-sort-by-number',
1042 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
1043 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
1044 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
1045
1046 (defvar gnus-thread-score-function '+
1047 "*Function used for calculating the total score of a thread.
1048
1049 The function is called with the scores of the article and each
1050 subthread and should then return the score of the thread.
1051
1052 Some functions you can use are `+', `max', or `min'.")
1053
1054 (defvar gnus-options-subscribe nil
1055 "*All new groups matching this regexp will be subscribed unconditionally.
1056 Note that this variable deals only with new newsgroups. This variable
1057 does not affect old newsgroups.")
1058
1059 (defvar gnus-options-not-subscribe nil
1060 "*All new groups matching this regexp will be ignored.
1061 Note that this variable deals only with new newsgroups. This variable
1062 does not affect old (already subscribed) newsgroups.")
1063
1064 (defvar gnus-auto-expirable-newsgroups nil
1065 "*Groups in which to automatically mark read articles as expirable.
1066 If non-nil, this should be a regexp that should match all groups in
1067 which to perform auto-expiry. This only makes sense for mail groups.")
1068
1069 (defvar gnus-hidden-properties '(invisible t intangible t)
1070 "Property list to use for hiding text.")
1071
1072 (defvar gnus-modtime-botch nil
1073 "*Non-nil means .newsrc should be deleted prior to save. Its use is
1074 due to the bogus appearance that .newsrc was modified on disc.")
1075
1076 ;; Hooks.
1077
1078 (defvar gnus-group-mode-hook nil
1079 "*A hook for Gnus group mode.")
1080
1081 (defvar gnus-summary-mode-hook nil
1082 "*A hook for Gnus summary mode.
1083 This hook is run before any variables are set in the summary buffer.")
1084
1085 (defvar gnus-article-mode-hook nil
1086 "*A hook for Gnus article mode.")
1087
1088 (defun gnus-summary-prepare-exit-hook nil
1089 "*A hook called when preparing to exit from the summary buffer.
1090 It calls `gnus-summary-expire-articles' by default.")
1091 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
1092
1093 (defun gnus-summary-exit-hook nil
1094 "*A hook called on exit from the summary buffer.")
1095
1096 (defvar gnus-open-server-hook nil
1097 "*A hook called just before opening connection to the news server.")
1098
1099 (defvar gnus-load-hook nil
1100 "*A hook run while Gnus is loaded.")
1101
1102 (defvar gnus-startup-hook nil
1103 "*A hook called at startup.
1104 This hook is called after Gnus is connected to the NNTP server.")
1105
1106 (defvar gnus-get-new-news-hook nil
1107 "*A hook run just before Gnus checks for new news.")
1108
1109 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
1110 "*A function that is called to generate the group buffer.
1111 The function is called with three arguments: The first is a number;
1112 all group with a level less or equal to that number should be listed,
1113 if the second is non-nil, empty groups should also be displayed. If
1114 the third is non-nil, it is a number. No groups with a level lower
1115 than this number should be displayed.
1116
1117 The only current function implemented is `gnus-group-prepare-flat'.")
1118
1119 (defvar gnus-group-prepare-hook nil
1120 "*A hook called after the group buffer has been generated.
1121 If you want to modify the group buffer, you can use this hook.")
1122
1123 (defvar gnus-summary-prepare-hook nil
1124 "*A hook called after the summary buffer has been generated.
1125 If you want to modify the summary buffer, you can use this hook.")
1126
1127 (defvar gnus-article-prepare-hook nil
1128 "*A hook called after an article has been prepared in the article buffer.
1129 If you want to run a special decoding program like nkf, use this hook.")
1130
1131 ;(defvar gnus-article-display-hook nil
1132 ; "*A hook called after the article is displayed in the article buffer.
1133 ;The hook is designed to change the contents of the article
1134 ;buffer. Typical functions that this hook may contain are
1135 ;`gnus-article-hide-headers' (hide selected headers),
1136 ;`gnus-article-maybe-highlight' (perform fancy article highlighting),
1137 ;`gnus-article-hide-signature' (hide signature) and
1138 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
1139 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
1140 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
1141 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
1142
1143 (defvar gnus-article-x-face-command
1144 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
1145 "String or function to be executed to display an X-Face header.
1146 If it is a string, the command will be executed in a sub-shell
1147 asynchronously. The compressed face will be piped to this command.")
1148
1149 (defvar gnus-article-x-face-too-ugly nil
1150 "Regexp matching posters whose face shouldn't be shown automatically.")
1151
1152 (defvar gnus-select-group-hook nil
1153 "*A hook called when a newsgroup is selected.
1154
1155 If you'd like to simplify subjects like the
1156 `gnus-summary-next-same-subject' command does, you can use the
1157 following hook:
1158
1159 (setq gnus-select-group-hook
1160 (list
1161 (lambda ()
1162 (mapcar (lambda (header)
1163 (mail-header-set-subject
1164 header
1165 (gnus-simplify-subject
1166 (mail-header-subject header) 're-only)))
1167 gnus-newsgroup-headers))))")
1168
1169 (defvar gnus-select-article-hook
1170 '(gnus-summary-show-thread)
1171 "*A hook called when an article is selected.
1172 The default hook shows conversation thread subtrees of the selected
1173 article automatically using `gnus-summary-show-thread'.")
1174
1175 (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
1176 "*A hook called to apply kill files to a group.
1177 This hook is intended to apply a kill file to the selected newsgroup.
1178 The function `gnus-apply-kill-file' is called by default.
1179
1180 Since a general kill file is too heavy to use only for a few
1181 newsgroups, I recommend you to use a lighter hook function. For
1182 example, if you'd like to apply a kill file to articles which contains
1183 a string `rmgroup' in subject in newsgroup `control', you can use the
1184 following hook:
1185
1186 (setq gnus-apply-kill-hook
1187 (list
1188 (lambda ()
1189 (cond ((string-match \"control\" gnus-newsgroup-name)
1190 (gnus-kill \"Subject\" \"rmgroup\")
1191 (gnus-expunge \"X\"))))))")
1192
1193 (defvar gnus-visual-mark-article-hook
1194 (list 'gnus-highlight-selected-summary)
1195 "*Hook run after selecting an article in the summary buffer.
1196 It is meant to be used for highlighting the article in some way. It
1197 is not run if `gnus-visual' is nil.")
1198
1199 (defun gnus-parse-headers-hook nil
1200 "*A hook called before parsing the headers.")
1201
1202 (defvar gnus-exit-group-hook nil
1203 "*A hook called when exiting (not quitting) summary mode.")
1204
1205 (defvar gnus-suspend-gnus-hook nil
1206 "*A hook called when suspending (not exiting) Gnus.")
1207
1208 (defvar gnus-exit-gnus-hook nil
1209 "*A hook called when exiting Gnus.")
1210
1211 (defvar gnus-save-newsrc-hook nil
1212 "*A hook called when saving the newsrc file.")
1213
1214 (defvar gnus-summary-update-hook
1215 (list 'gnus-summary-highlight-line)
1216 "*A hook called when a summary line is changed.
1217 The hook will not be called if `gnus-visual' is nil.
1218
1219 The default function `gnus-summary-highlight-line' will
1220 highlight the line according to the `gnus-summary-highlight'
1221 variable.")
1222
1223 (defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read)
1224 "*A hook called when an article is selected for the first time.
1225 The hook is intended to mark an article as read (or unread)
1226 automatically when it is selected.")
1227
1228 ;; Remove any hilit infestation.
1229 (add-hook 'gnus-startup-hook
1230 (lambda ()
1231 (remove-hook 'gnus-summary-prepare-hook
1232 'hilit-rehighlight-buffer-quietly)
1233 (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
1234 (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read))
1235 (remove-hook 'gnus-article-prepare-hook
1236 'hilit-rehighlight-buffer-quietly)))
1237
1238
1239 \f
1240 ;; Internal variables
1241
1242 ;; Avoid highlighting in kill files.
1243 (defvar gnus-summary-inhibit-highlight nil)
1244 (defvar gnus-newsgroup-selected-overlay nil)
1245
1246 (defvar gnus-article-mode-map nil)
1247 (defvar gnus-dribble-buffer nil)
1248 (defvar gnus-headers-retrieved-by nil)
1249 (defvar gnus-article-reply nil)
1250 (defvar gnus-override-method nil)
1251 (defvar gnus-article-check-size nil)
1252
1253 (defvar gnus-current-score-file nil)
1254 (defvar gnus-internal-global-score-files nil)
1255 (defvar gnus-score-file-list nil)
1256 (defvar gnus-scores-exclude-files nil)
1257
1258 (defvar gnus-current-move-group nil)
1259
1260 (defvar gnus-newsgroup-dependencies nil)
1261 (defvar gnus-newsgroup-threads nil)
1262 (defvar gnus-newsgroup-async nil)
1263 (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
1264
1265 (defvar gnus-newsgroup-adaptive nil)
1266
1267 (defvar gnus-summary-display-table nil)
1268
1269 (defconst gnus-group-line-format-alist
1270 (list (list ?M 'marked ?c)
1271 (list ?S 'subscribed ?c)
1272 (list ?L 'level ?d)
1273 (list ?N 'number ?s)
1274 (list ?I 'number-of-dormant ?d)
1275 (list ?T 'number-of-ticked ?d)
1276 (list ?R 'number-of-read ?s)
1277 (list ?t 'number-total ?d)
1278 (list ?y 'number-of-unread-unticked ?s)
1279 (list ?i 'number-of-ticked-and-dormant ?d)
1280 (list ?g 'group ?s)
1281 (list ?G 'qualified-group ?s)
1282 (list ?D 'newsgroup-description ?s)
1283 (list ?o 'moderated ?c)
1284 (list ?O 'moderated-string ?s)
1285 (list ?p 'process-marked ?c)
1286 (list ?s 'news-server ?s)
1287 (list ?n 'news-method ?s)
1288 (list ?z 'news-method-string ?s)
1289 (list ?u 'user-defined ?s)))
1290
1291 (defconst gnus-summary-line-format-alist
1292 (list (list ?N 'number ?d)
1293 (list ?S 'subject ?s)
1294 (list ?s 'subject-or-nil ?s)
1295 (list ?n 'name ?s)
1296 (list ?A '(car (cdr (funcall gnus-extract-address-components from)))
1297 ?s)
1298 (list ?a '(or (car (funcall gnus-extract-address-components from))
1299 from) ?s)
1300 (list ?F 'from ?s)
1301 (list ?x (macroexpand '(mail-header-xref header)) ?s)
1302 (list ?D (macroexpand '(mail-header-date header)) ?s)
1303 (list ?d '(gnus-dd-mmm (mail-header-date header)) ?s)
1304 (list ?M (macroexpand '(mail-header-id header)) ?s)
1305 (list ?r (macroexpand '(mail-header-references header)) ?s)
1306 (list ?c '(or (mail-header-chars header) 0) ?d)
1307 (list ?L 'lines ?d)
1308 (list ?I 'indentation ?s)
1309 (list ?T '(if (= level 0) "" (make-string (frame-width) ? )) ?s)
1310 (list ?R 'replied ?c)
1311 (list ?\[ 'opening-bracket ?c)
1312 (list ?\] 'closing-bracket ?c)
1313 (list ?\> '(make-string level ? ) ?s)
1314 (list ?\< '(make-string (max 0 (- 20 level)) ? ) ?s)
1315 (list ?i 'score ?d)
1316 (list ?z 'score-char ?c)
1317 (list ?U 'unread ?c)
1318 (list ?t '(gnus-summary-number-of-articles-in-thread
1319 (and (boundp 'thread) (car thread)))
1320 ?d)
1321 (list ?e '(gnus-summary-number-of-articles-in-thread
1322 (and (boundp 'thread) (car thread)) t)
1323 ?c)
1324 (list ?u 'user-defined ?s))
1325 "An alist of format specifications that can appear in summary lines,
1326 and what variables they correspond with, along with the type of the
1327 variable (string, integer, character, etc).")
1328
1329 (defconst gnus-summary-dummy-line-format-alist
1330 (list (list ?S 'subject ?s)
1331 (list ?N 'number ?d)
1332 (list ?u 'user-defined ?s)))
1333
1334 (defconst gnus-summary-mode-line-format-alist
1335 (list (list ?G 'group-name ?s)
1336 (list ?g '(gnus-short-group-name group-name) ?s)
1337 (list ?A 'article-number ?d)
1338 (list ?Z 'unread-and-unselected ?s)
1339 (list ?V 'gnus-version ?s)
1340 (list ?U 'unread ?d)
1341 (list ?S 'subject ?s)
1342 (list ?e 'unselected ?d)
1343 (list ?u 'user-defined ?s)
1344 (list ?b 'buffer-name ?s)
1345 (list ?s '(gnus-current-score-file-nondirectory) ?s)))
1346
1347 (defconst gnus-group-mode-line-format-alist
1348 (list (list ?S 'news-server ?s)
1349 (list ?M 'news-method ?s)
1350 (list ?b '(buffer-name) ?s)
1351 (list ?u 'user-defined ?s)))
1352
1353 (defvar gnus-have-read-active-file nil)
1354
1355 (defconst gnus-maintainer
1356 "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
1357 "The mail address of the Gnus maintainers.")
1358
1359 (defconst gnus-version "Gnus v5.1"
1360 "Version number for this version of Gnus.")
1361
1362 (defvar gnus-info-nodes
1363 '((gnus-group-mode "(gnus)The Group Buffer")
1364 (gnus-summary-mode "(gnus)The Summary Buffer")
1365 (gnus-article-mode "(gnus)The Article Buffer"))
1366 "Assoc list of major modes and related Info nodes.")
1367
1368 (defvar gnus-group-buffer "*Group*")
1369 (defvar gnus-summary-buffer "*Summary*")
1370 (defvar gnus-article-buffer "*Article*")
1371 (defvar gnus-server-buffer "*Server*")
1372
1373 (defvar gnus-work-buffer " *gnus work*")
1374
1375 (defvar gnus-buffer-list nil
1376 "Gnus buffers that should be killed on exit.")
1377
1378 (defvar gnus-server-alist nil
1379 "List of available servers.")
1380
1381 (defvar gnus-variable-list
1382 '(gnus-newsrc-options gnus-newsrc-options-n
1383 gnus-newsrc-last-checked-date
1384 gnus-newsrc-alist gnus-server-alist
1385 gnus-killed-list gnus-zombie-list)
1386 "Gnus variables saved in the quick startup file.")
1387
1388 (defvar gnus-overload-functions
1389 '((news-inews gnus-inews-news "rnewspost"))
1390 "Functions overloaded by gnus.
1391 It is a list of `(original overload &optional file)'.")
1392
1393 (defvar gnus-newsrc-options nil
1394 "Options line in the .newsrc file.")
1395
1396 (defvar gnus-newsrc-options-n nil
1397 "List of regexps representing groups to be subscribed/ignored unconditionally.")
1398
1399 (defvar gnus-newsrc-last-checked-date nil
1400 "Date Gnus last asked server for new newsgroups.")
1401
1402 (defvar gnus-newsrc-alist nil
1403 "Assoc list of read articles.
1404 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1405
1406 (defvar gnus-newsrc-hashtb nil
1407 "Hashtable of gnus-newsrc-alist.")
1408
1409 (defvar gnus-killed-list nil
1410 "List of killed newsgroups.")
1411
1412 (defvar gnus-killed-hashtb nil
1413 "Hash table equivalent of gnus-killed-list.")
1414
1415 (defvar gnus-zombie-list nil
1416 "List of almost dead newsgroups.")
1417
1418 (defvar gnus-description-hashtb nil
1419 "Descriptions of newsgroups.")
1420
1421 (defvar gnus-list-of-killed-groups nil
1422 "List of newsgroups that have recently been killed by the user.")
1423
1424 (defvar gnus-active-hashtb nil
1425 "Hashtable of active articles.")
1426
1427 (defvar gnus-moderated-list nil
1428 "List of moderated newsgroups.")
1429
1430 (defvar gnus-group-marked nil)
1431
1432 (defvar gnus-current-startup-file nil
1433 "Startup file for the current host.")
1434
1435 (defvar gnus-last-search-regexp nil
1436 "Default regexp for article search command.")
1437
1438 (defvar gnus-last-shell-command nil
1439 "Default shell command on article.")
1440
1441 (defvar gnus-current-select-method nil
1442 "The current method for selecting a newsgroup.")
1443
1444 (defvar gnus-group-list-mode nil)
1445
1446 (defvar gnus-article-internal-prepare-hook nil)
1447
1448 (defvar gnus-newsgroup-name nil)
1449 (defvar gnus-newsgroup-begin nil)
1450 (defvar gnus-newsgroup-end nil)
1451 (defvar gnus-newsgroup-last-rmail nil)
1452 (defvar gnus-newsgroup-last-mail nil)
1453 (defvar gnus-newsgroup-last-folder nil)
1454 (defvar gnus-newsgroup-last-file nil)
1455 (defvar gnus-newsgroup-auto-expire nil)
1456 (defvar gnus-newsgroup-active nil)
1457
1458 (defvar gnus-newsgroup-unreads nil
1459 "List of unread articles in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-unselected nil
1462 "List of unselected unread articles in the current newsgroup.")
1463
1464 (defvar gnus-newsgroup-reads nil
1465 "Alist of read articles and article marks in the current newsgroup.")
1466
1467 (defvar gnus-newsgroup-marked nil
1468 "List of ticked articles in the current newsgroup (a subset of unread art).")
1469
1470 (defvar gnus-newsgroup-killed nil
1471 "List of ranges of articles that have been through the scoring process.")
1472
1473 (defvar gnus-newsgroup-kill-headers nil)
1474
1475 (defvar gnus-newsgroup-replied nil
1476 "List of articles that have been replied to in the current newsgroup.")
1477
1478 (defvar gnus-newsgroup-expirable nil
1479 "List of articles in the current newsgroup that can be expired.")
1480
1481 (defvar gnus-newsgroup-processable nil
1482 "List of articles in the current newsgroup that can be processed.")
1483
1484 (defvar gnus-newsgroup-bookmarks nil
1485 "List of articles in the current newsgroup that have bookmarks.")
1486
1487 (defvar gnus-newsgroup-dormant nil
1488 "List of dormant articles in the current newsgroup.")
1489
1490 (defvar gnus-newsgroup-scored nil
1491 "List of scored articles in the current newsgroup.")
1492
1493 (defvar gnus-newsgroup-headers nil
1494 "List of article headers in the current newsgroup.")
1495 (defvar gnus-newsgroup-headers-hashtb-by-number nil)
1496
1497 (defvar gnus-newsgroup-ancient nil
1498 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1499
1500 (defvar gnus-current-article nil)
1501 (defvar gnus-article-current nil)
1502 (defvar gnus-current-headers nil)
1503 (defvar gnus-have-all-headers nil)
1504 (defvar gnus-last-article nil)
1505 (defvar gnus-newsgroup-history nil)
1506 (defvar gnus-current-kill-article nil)
1507
1508 ;; Save window configuration.
1509 (defvar gnus-prev-winconf nil)
1510
1511 ;; Format specs
1512 (defvar gnus-summary-line-format-spec nil)
1513 (defvar gnus-summary-dummy-line-format-spec nil)
1514 (defvar gnus-group-line-format-spec nil)
1515 (defvar gnus-summary-mode-line-format-spec nil)
1516 (defvar gnus-article-mode-line-format-spec nil)
1517 (defvar gnus-group-mode-line-format-spec nil)
1518 (defvar gnus-summary-mark-positions nil)
1519 (defvar gnus-group-mark-positions nil)
1520
1521 (defvar gnus-summary-expunge-below nil)
1522 (defvar gnus-reffed-article-number nil)
1523
1524 ; Let the byte-compiler know that we know about this variable.
1525 (defvar rmail-default-rmail-file)
1526
1527 (defvar gnus-cache-removable-articles nil)
1528
1529 (defconst gnus-summary-local-variables
1530 '(gnus-newsgroup-name
1531 gnus-newsgroup-begin gnus-newsgroup-end
1532 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1533 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1534 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1535 gnus-newsgroup-unselected gnus-newsgroup-marked
1536 gnus-newsgroup-reads
1537 gnus-newsgroup-replied gnus-newsgroup-expirable
1538 gnus-newsgroup-processable gnus-newsgroup-killed
1539 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1540 gnus-newsgroup-headers gnus-newsgroup-headers-hashtb-by-number
1541 gnus-current-article gnus-current-headers gnus-have-all-headers
1542 gnus-last-article gnus-article-internal-prepare-hook
1543 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1544 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1545 gnus-newsgroup-threads gnus-newsgroup-async
1546 gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1547 gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files
1548 gnus-newsgroup-history gnus-newsgroup-ancient
1549 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1550 gnus-cache-removable-articles)
1551 "Variables that are buffer-local to the summary buffers.")
1552
1553 (defconst gnus-bug-message
1554 "Sending a bug report to the Gnus Towers.
1555 ========================================
1556
1557 The buffer below is a mail buffer. When you press `C-c C-c', it will
1558 be sent to the Gnus Bug Exterminators.
1559
1560 At the bottom of the buffer you'll see lots of variable settings.
1561 Please do not delete those. They will tell the Bug People what your
1562 environment is, so that it will be easier to locate the bugs.
1563
1564 If you have found a bug that makes Emacs go \"beep\", set
1565 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
1566 and include the backtrace in your bug report.
1567
1568 Please describe the bug in annoying, painstaking detail.
1569
1570 Thank you for your help in stamping out bugs.
1571 ")
1572
1573 ;;; End of variables.
1574
1575 ;; Define some autoload functions Gnus might use.
1576 (eval-and-compile
1577
1578 ;; Various
1579 (autoload 'metamail-buffer "metamail")
1580 (autoload 'Info-goto-node "info")
1581 (autoload 'hexl-hex-string-to-integer "hexl")
1582 (autoload 'pp "pp")
1583 (autoload 'pp-to-string "pp")
1584 (autoload 'pp-eval-expression "pp")
1585 (autoload 'mail-extract-address-components "mail-extr")
1586
1587 (autoload 'nnmail-split-fancy "nnmail")
1588 (autoload 'nnvirtual-catchup-group "nnvirtual")
1589
1590 ;; timezone
1591 (autoload 'timezone-make-date-arpa-standard "timezone")
1592 (autoload 'timezone-fix-time "timezone")
1593 (autoload 'timezone-make-sortable-date "timezone")
1594 (autoload 'timezone-make-time-string "timezone")
1595
1596 ;; rmail & friends
1597 (autoload 'mail-position-on-field "sendmail")
1598 (autoload 'mail-setup "sendmail")
1599 (autoload 'rmail-output "rmailout")
1600 (autoload 'news-mail-other-window "rnewspost")
1601 (autoload 'news-reply-yank-original "rnewspost")
1602 (autoload 'news-caesar-buffer-body "rnewspost")
1603 (autoload 'rmail-insert-rmail-file-header "rmail")
1604 (autoload 'rmail-count-new-messages "rmail")
1605 (autoload 'rmail-show-message "rmail")
1606
1607 ;; gnus-soup
1608 ;;(autoload 'gnus-group-brew-soup "gnus-soup" nil t)
1609 ;;(autoload 'gnus-brew-soup "gnus-soup" nil t)
1610 ;;(autoload 'gnus-soup-add-article "gnus-soup" nil t)
1611 ;;(autoload 'gnus-soup-send-replies "gnus-soup" nil t)
1612 ;;(autoload 'gnus-soup-save-areas "gnus-soup" nil t)
1613 ;;(autoload 'gnus-soup-pack-packet "gnus-soup" nil t)
1614 ;;(autoload 'nnsoup-pack-replies "nnsoup" nil t)
1615
1616 ;; gnus-mh
1617 (autoload 'gnus-mail-reply-using-mhe "gnus-mh")
1618 (autoload 'gnus-mail-forward-using-mhe "gnus-mh")
1619 (autoload 'gnus-mail-other-window-using-mhe "gnus-mh")
1620 (autoload 'gnus-summary-save-in-folder "gnus-mh" nil t)
1621 (autoload 'gnus-summary-save-article-folder "gnus-mh")
1622 (autoload 'gnus-Folder-save-name "gnus-mh")
1623 (autoload 'gnus-folder-save-name "gnus-mh")
1624
1625 ;; gnus-vis misc
1626 (autoload 'gnus-group-make-menu-bar "gnus-vis")
1627 (autoload 'gnus-summary-make-menu-bar "gnus-vis")
1628 (autoload 'gnus-server-make-menu-bar "gnus-vis")
1629 (autoload 'gnus-article-make-menu-bar "gnus-vis")
1630 (autoload 'gnus-browse-make-menu-bar "gnus-vis")
1631 (autoload 'gnus-highlight-selected-summary "gnus-vis")
1632 (autoload 'gnus-summary-highlight-line "gnus-vis")
1633 (autoload 'gnus-carpal-setup-buffer "gnus-vis")
1634
1635 ;; gnus-vis article
1636 (autoload 'gnus-article-push-button "gnus-vis" nil t)
1637 (autoload 'gnus-article-press-button "gnus-vis" nil t)
1638 (autoload 'gnus-article-highlight "gnus-vis" nil t)
1639 (autoload 'gnus-article-highlight-some "gnus-vis" nil t)
1640 (autoload 'gnus-article-hide "gnus-vis" nil t)
1641 (autoload 'gnus-article-hide-signature "gnus-vis" nil t)
1642 (autoload 'gnus-article-highlight-headers "gnus-vis" nil t)
1643 (autoload 'gnus-article-highlight-signature "gnus-vis" nil t)
1644 (autoload 'gnus-article-add-buttons "gnus-vis" nil t)
1645 (autoload 'gnus-article-next-button "gnus-vis" nil t)
1646 (autoload 'gnus-article-add-button "gnus-vis")
1647
1648 ;; gnus-cite
1649 (autoload 'gnus-article-highlight-citation "gnus-cite" nil t)
1650 (autoload 'gnus-article-hide-citation-maybe "gnus-cite" nil t)
1651 (autoload 'gnus-article-hide-citation "gnus-cite" nil t)
1652
1653 ;; gnus-kill
1654 (autoload 'gnus-kill "gnus-kill")
1655 (autoload 'gnus-apply-kill-file-internal "gnus-kill")
1656 (autoload 'gnus-kill-file-edit-file "gnus-kill")
1657 (autoload 'gnus-kill-file-raise-followups-to-author "gnus-kill")
1658 (autoload 'gnus-execute "gnus-kill")
1659 (autoload 'gnus-expunge "gnus-kill")
1660
1661 ;; gnus-cache
1662 (autoload 'gnus-cache-possibly-enter-article "gnus-cache")
1663 (autoload 'gnus-cache-save-buffers "gnus-cache")
1664 (autoload 'gnus-cache-possibly-remove-articles "gnus-cache")
1665 (autoload 'gnus-cache-request-article "gnus-cache")
1666 (autoload 'gnus-cache-retrieve-headers "gnus-cache")
1667 (autoload 'gnus-cache-possibly-alter-active "gnus-cache")
1668 (autoload 'gnus-jog-cache "gnus-cache" nil t)
1669 (autoload 'gnus-cache-enter-remove-article "gnus-cache")
1670
1671 ;; gnus-score
1672 (autoload 'gnus-summary-increase-score "gnus-score" nil t)
1673 (autoload 'gnus-summary-lower-score "gnus-score" nil t)
1674 (autoload 'gnus-summary-score-map "gnus-score" nil nil 'keymap)
1675 (autoload 'gnus-score-save "gnus-score")
1676 (autoload 'gnus-score-headers "gnus-score")
1677 (autoload 'gnus-current-score-file-nondirectory "gnus-score")
1678 (autoload 'gnus-score-adaptive "gnus-score")
1679 (autoload 'gnus-score-remove-lines-adaptive "gnus-score")
1680 (autoload 'gnus-score-find-trace "gnus-score")
1681
1682 ;; gnus-edit
1683 (autoload 'gnus-score-customize "gnus-edit" nil t)
1684
1685 ;; gnus-uu
1686 (autoload 'gnus-uu-extract-map "gnus-uu" nil nil 'keymap)
1687 (autoload 'gnus-uu-mark-map "gnus-uu" nil nil 'keymap)
1688 (autoload 'gnus-uu-digest-mail-forward "gnus-uu" nil t)
1689 (autoload 'gnus-uu-digest-post-forward "gnus-uu" nil t)
1690 (autoload 'gnus-uu-mark-series "gnus-uu" nil t)
1691 (autoload 'gnus-uu-mark-region "gnus-uu" nil t)
1692 (autoload 'gnus-uu-mark-by-regexp "gnus-uu" nil t)
1693 (autoload 'gnus-uu-mark-all "gnus-uu" nil t)
1694 (autoload 'gnus-uu-mark-sparse "gnus-uu" nil t)
1695 (autoload 'gnus-uu-mark-thread "gnus-uu" nil t)
1696 (autoload 'gnus-uu-decode-uu "gnus-uu" nil t)
1697 (autoload 'gnus-uu-decode-uu-and-save "gnus-uu" nil t)
1698 (autoload 'gnus-uu-decode-unshar "gnus-uu" nil t)
1699 (autoload 'gnus-uu-decode-unshar-and-save "gnus-uu" nil t)
1700 (autoload 'gnus-uu-decode-save "gnus-uu" nil t)
1701 (autoload 'gnus-uu-decode-binhex "gnus-uu" nil t)
1702 (autoload 'gnus-uu-decode-uu-view "gnus-uu" nil t)
1703 (autoload 'gnus-uu-decode-uu-and-save-view "gnus-uu" nil t)
1704 (autoload 'gnus-uu-decode-unshar-view "gnus-uu" nil t)
1705 (autoload 'gnus-uu-decode-unshar-and-save-view "gnus-uu" nil t)
1706 (autoload 'gnus-uu-decode-save-view "gnus-uu" nil t)
1707 (autoload 'gnus-uu-decode-binhex-view "gnus-uu" nil t)
1708
1709 ;; gnus-msg
1710 (autoload 'gnus-summary-send-map "gnus-msg" nil nil 'keymap)
1711 (autoload 'gnus-group-post-news "gnus-msg" nil t)
1712 (autoload 'gnus-group-mail "gnus-msg" nil t)
1713 (autoload 'gnus-summary-post-news "gnus-msg" nil t)
1714 (autoload 'gnus-summary-followup "gnus-msg" nil t)
1715 (autoload 'gnus-summary-followup-with-original "gnus-msg" nil t)
1716 (autoload 'gnus-summary-followup-and-reply "gnus-msg" nil t)
1717 (autoload 'gnus-summary-followup-and-reply-with-original "gnus-msg" nil t)
1718 (autoload 'gnus-summary-cancel-article "gnus-msg" nil t)
1719 (autoload 'gnus-summary-supersede-article "gnus-msg" nil t)
1720 (autoload 'gnus-post-news "gnus-msg" nil t)
1721 (autoload 'gnus-inews-news "gnus-msg" nil t)
1722 (autoload 'gnus-cancel-news "gnus-msg" nil t)
1723 (autoload 'gnus-summary-reply "gnus-msg" nil t)
1724 (autoload 'gnus-summary-reply-with-original "gnus-msg" nil t)
1725 (autoload 'gnus-summary-mail-forward "gnus-msg" nil t)
1726 (autoload 'gnus-summary-mail-other-window "gnus-msg" nil t)
1727 (autoload 'gnus-mail-reply-using-mail "gnus-msg")
1728 (autoload 'gnus-mail-yank-original "gnus-msg")
1729 (autoload 'gnus-mail-send-and-exit "gnus-msg")
1730 (autoload 'gnus-mail-forward-using-mail "gnus-msg")
1731 (autoload 'gnus-mail-other-window-using-mail "gnus-msg")
1732 (autoload 'gnus-article-mail "gnus-msg")
1733 (autoload 'gnus-bug "gnus-msg" nil t)
1734
1735 ;; gnus-vm
1736 (autoload 'gnus-summary-save-in-vm "gnus-vm" nil t)
1737 (autoload 'gnus-summary-save-article-vm "gnus-vm" nil t)
1738 (autoload 'gnus-mail-forward-using-vm "gnus-vm")
1739 (autoload 'gnus-mail-reply-using-vm "gnus-vm")
1740 (autoload 'gnus-mail-other-window-using-vm "gnus-vm" nil t)
1741 (autoload 'gnus-yank-article "gnus-vm" nil t)
1742
1743 )
1744
1745 \f
1746
1747 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1748 ;; If you want the cursor to go somewhere else, set these two
1749 ;; functions in some startup hook to whatever you want.
1750 (defalias 'gnus-summary-position-cursor 'gnus-goto-colon)
1751 (defalias 'gnus-group-position-cursor 'gnus-goto-colon)
1752
1753 ;;; Various macros and substs.
1754
1755 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
1756 "Pop to BUFFER, evaluate FORMS, and then returns to original window."
1757 (` (let ((GnusStartBufferWindow (selected-window)))
1758 (unwind-protect
1759 (progn
1760 (pop-to-buffer (, buffer))
1761 (,@ forms))
1762 (select-window GnusStartBufferWindow)))))
1763
1764 (defmacro gnus-gethash (string hashtable)
1765 "Get hash value of STRING in HASHTABLE."
1766 ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable))))
1767 ;;(` (abbrev-expansion (, string) (, hashtable)))
1768 (` (symbol-value (intern-soft (, string) (, hashtable)))))
1769
1770 (defmacro gnus-sethash (string value hashtable)
1771 "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
1772 ;; We cannot use define-abbrev since it only accepts string as value.
1773 ;; (set (intern string hashtable) value))
1774 (` (set (intern (, string) (, hashtable)) (, value))))
1775
1776 (defsubst gnus-buffer-substring (beg end)
1777 (buffer-substring (match-beginning beg) (match-end end)))
1778
1779 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1780 ;; function `substring' might cut on a middle of multi-octet
1781 ;; character.
1782 (defun gnus-truncate-string (str width)
1783 (substring str 0 width))
1784
1785 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
1786 ;; to limit the length of a string. This function is necessary since
1787 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
1788 (defsubst gnus-limit-string (str width)
1789 (if (> (length str) width)
1790 (substring str 0 width)
1791 str))
1792
1793 (defsubst gnus-simplify-subject-re (subject)
1794 "Remove \"Re:\" from subject lines."
1795 (let ((case-fold-search t))
1796 (if (string-match "^re: *" subject)
1797 (substring subject (match-end 0))
1798 subject)))
1799
1800 (defsubst gnus-goto-char (point)
1801 (and point (goto-char point)))
1802
1803 (defmacro gnus-buffer-exists-p (buffer)
1804 (` (and (, buffer)
1805 (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
1806 (, buffer)))))
1807
1808 (defmacro gnus-kill-buffer (buffer)
1809 (` (if (gnus-buffer-exists-p (, buffer))
1810 (kill-buffer (, buffer)))))
1811
1812 (defsubst gnus-point-at-bol ()
1813 "Return point at the beginning of line."
1814 (let ((p (point)))
1815 (beginning-of-line)
1816 (prog1
1817 (point)
1818 (goto-char p))))
1819
1820 (defsubst gnus-point-at-eol ()
1821 "Return point at the beginning of line."
1822 (let ((p (point)))
1823 (end-of-line)
1824 (prog1
1825 (point)
1826 (goto-char p))))
1827
1828 ;; Delete the current line (and the next N lines.);
1829 (defmacro gnus-delete-line (&optional n)
1830 (` (delete-region (progn (beginning-of-line) (point))
1831 (progn (forward-line (, (or n 1))) (point)))))
1832
1833 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1834 (defvar gnus-init-inhibit nil)
1835 (defun gnus-read-init-file (&optional inhibit-next)
1836 (if gnus-init-inhibit
1837 (setq gnus-init-inhibit nil)
1838 (setq gnus-init-inhibit inhibit-next)
1839 (and gnus-init-file
1840 (or (and (file-exists-p gnus-init-file)
1841 ;; Don't try to load a directory.
1842 (not (file-directory-p gnus-init-file)))
1843 (file-exists-p (concat gnus-init-file ".el"))
1844 (file-exists-p (concat gnus-init-file ".elc")))
1845 (load gnus-init-file nil t))))
1846
1847 ;;; Load the user startup file.
1848 ;; (eval '(gnus-read-init-file 'inhibit))
1849
1850 ;;; Load the compatibility functions.
1851
1852 (require 'gnus-cus)
1853 (require 'gnus-ems)
1854
1855 \f
1856 ;;;
1857 ;;; Gnus Utility Functions
1858 ;;;
1859
1860 (defun gnus-extract-address-components (from)
1861 (let (name address)
1862 ;; First find the address - the thing with the @ in it. This may
1863 ;; not be accurate in mail addresses, but does the trick most of
1864 ;; the time in news messages.
1865 (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
1866 (setq address (substring from (match-beginning 0) (match-end 0))))
1867 ;; Then we check whether the "name <address>" format is used.
1868 (and address
1869 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1870 ;; Linear white space is not required.
1871 (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
1872 (and (setq name (substring from 0 (match-beginning 0)))
1873 ;; Strip any quotes from the name.
1874 (string-match "\".*\"" name)
1875 (setq name (substring name 1 (1- (match-end 0))))))
1876 ;; If not, then "address (name)" is used.
1877 (or name
1878 (and (string-match "(.+)" from)
1879 (setq name (substring from (1+ (match-beginning 0))
1880 (1- (match-end 0)))))
1881 (and (string-match "()" from)
1882 (setq name address))
1883 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
1884 ;; XOVER might not support folded From headers.
1885 (and (string-match "(.*" from)
1886 (setq name (substring from (1+ (match-beginning 0))
1887 (match-end 0)))))
1888 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1889 (list (or name from) (or address from))))
1890
1891 (defun gnus-fetch-field (field)
1892 "Return the value of the header FIELD of current article."
1893 (save-excursion
1894 (save-restriction
1895 (let ((case-fold-search t))
1896 (gnus-narrow-to-headers)
1897 (mail-fetch-field field)))))
1898
1899 (defun gnus-goto-colon ()
1900 (beginning-of-line)
1901 (search-forward ":" (gnus-point-at-eol) t))
1902
1903 (defun gnus-narrow-to-headers ()
1904 (widen)
1905 (save-excursion
1906 (narrow-to-region
1907 (goto-char (point-min))
1908 (if (search-forward "\n\n" nil t)
1909 (1- (point))
1910 (point-max)))))
1911
1912 (defvar gnus-old-specs nil)
1913
1914 (defun gnus-update-format-specifications ()
1915 (gnus-make-thread-indent-array)
1916
1917 (let ((formats '(summary summary-dummy group
1918 summary-mode group-mode article-mode))
1919 old-format new-format)
1920 (while formats
1921 (setq new-format (symbol-value
1922 (intern (format "gnus-%s-line-format" (car formats)))))
1923 (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs)))
1924 (equal old-format new-format))
1925 (set (intern (format "gnus-%s-line-format-spec" (car formats)))
1926 (gnus-parse-format
1927 new-format
1928 (symbol-value
1929 (intern (format "gnus-%s-line-format-alist"
1930 (if (eq (car formats) 'article-mode)
1931 'summary-mode (car formats))))))))
1932 (setq gnus-old-specs (cons (cons (car formats) new-format)
1933 (delq (car formats) gnus-old-specs)))
1934 (setq formats (cdr formats))))
1935
1936 (gnus-update-group-mark-positions)
1937 (gnus-update-summary-mark-positions)
1938
1939 (if (and (string-match "%D" gnus-group-line-format)
1940 (not gnus-description-hashtb)
1941 gnus-read-active-file)
1942 (gnus-read-all-descriptions-files)))
1943
1944 (defun gnus-update-summary-mark-positions ()
1945 (save-excursion
1946 (let ((gnus-replied-mark 129)
1947 (gnus-score-below-mark 130)
1948 (gnus-score-over-mark 130)
1949 (thread nil)
1950 pos)
1951 (gnus-set-work-buffer)
1952 (gnus-summary-insert-line
1953 nil [0 "" "" "" "" "" 0 0 ""] 0 nil 128 t nil "" nil 1)
1954 (goto-char (point-min))
1955 (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
1956 (- (point) 2)))))
1957 (goto-char (point-min))
1958 (setq pos (cons (cons 'replied (and (search-forward "\201" nil t)
1959 (- (point) 2))) pos))
1960 (goto-char (point-min))
1961 (setq pos (cons (cons 'score (and (search-forward "\202" nil t)
1962 (- (point) 2))) pos))
1963 (setq gnus-summary-mark-positions pos))))
1964
1965 (defun gnus-update-group-mark-positions ()
1966 (save-excursion
1967 (let ((gnus-process-mark 128)
1968 (gnus-group-marked '("dummy.group")))
1969 (gnus-sethash "dummy.group" '(0 . 0) gnus-active-hashtb)
1970 (gnus-set-work-buffer)
1971 (gnus-group-insert-group-line nil "dummy.group" 0 nil 0 nil)
1972 (goto-char (point-min))
1973 (setq gnus-group-mark-positions
1974 (list (cons 'process (and (search-forward "\200" nil t)
1975 (- (point) 2))))))))
1976
1977 (defun gnus-mouse-face-function (form)
1978 (` (let ((string (, form)))
1979 (put-text-property 0 (length string) 'mouse-face gnus-mouse-face string)
1980 string)))
1981
1982 (defun gnus-max-width-function (el max-width)
1983 (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
1984 (` (let* ((val (eval (, el)))
1985 (valstr (if (numberp val)
1986 (int-to-string val) val)))
1987 (if (> (length valstr) (, max-width))
1988 (substring valstr 0 (, max-width))
1989 valstr))))
1990
1991 (defun gnus-parse-format (format spec-alist)
1992 ;; This function parses the FORMAT string with the help of the
1993 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
1994 ;; string. If the FORMAT string contains the specifiers %( and %)
1995 ;; the text between them will have the mouse-face text property.
1996 (if (string-match "\\`\\(.*\\)%(\\(.*\\)%)\\(.*\n?\\)\\'" format)
1997 (if (and gnus-visual gnus-mouse-face)
1998 (let ((pre (substring format (match-beginning 1) (match-end 1)))
1999 (button (substring format (match-beginning 2) (match-end 2)))
2000 (post (substring format (match-beginning 3) (match-end 3))))
2001 (list 'concat
2002 (gnus-parse-simple-format pre spec-alist)
2003 (gnus-mouse-face-function
2004 (gnus-parse-simple-format button spec-alist))
2005 (gnus-parse-simple-format post spec-alist)))
2006 (gnus-parse-simple-format
2007 (concat (substring format (match-beginning 1) (match-end 1))
2008 (substring format (match-beginning 2) (match-end 2))
2009 (substring format (match-beginning 3) (match-end 3)))
2010 spec-alist))
2011 (gnus-parse-simple-format format spec-alist)))
2012
2013 (defun gnus-parse-simple-format (format spec-alist)
2014 ;; This function parses the FORMAT string with the help of the
2015 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
2016 ;; string. The list will consist of the symbol `format', a format
2017 ;; specification string, and a list of forms depending on the
2018 ;; SPEC-ALIST.
2019 (let ((max-width 0)
2020 spec flist fstring newspec elem beg)
2021 (save-excursion
2022 (gnus-set-work-buffer)
2023 (insert format)
2024 (goto-char (point-min))
2025 (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?" nil t)
2026 (setq spec (string-to-char (buffer-substring (match-beginning 2)
2027 (match-end 2))))
2028 ;; First check if there are any specs that look anything like
2029 ;; "%12,12A", ie. with a "max width specification". These have
2030 ;; to be treated specially.
2031 (if (setq beg (match-beginning 1))
2032 (setq max-width
2033 (string-to-int
2034 (buffer-substring (1+ (match-beginning 1)) (match-end 1))))
2035 (setq max-width 0)
2036 (setq beg (match-beginning 2)))
2037 ;; Find the specification from `spec-alist'.
2038 (if (not (setq elem (cdr (assq spec spec-alist))))
2039 (setq elem '("*" ?s)))
2040 ;; Treat user defined format specifiers specially
2041 (and (eq (car elem) 'user-defined)
2042 (setq elem
2043 (list
2044 (list (intern (concat "gnus-user-format-function-"
2045 (buffer-substring
2046 (match-beginning 3)
2047 (match-end 3))))
2048 'header)
2049 ?s))
2050 (delete-region (match-beginning 3) (match-end 3)))
2051 (if (not (zerop max-width))
2052 (let ((el (car elem)))
2053 (cond ((= (car (cdr elem)) ?c)
2054 (setq el (list 'char-to-string el)))
2055 ((= (car (cdr elem)) ?d)
2056 (numberp el) (setq el (list 'int-to-string el))))
2057 (setq flist (cons (gnus-max-width-function el max-width)
2058 flist))
2059 (setq newspec ?s))
2060 (setq flist (cons (car elem) flist))
2061 (setq newspec (car (cdr elem))))
2062 ;; Remove the old specification (and possibly a ",12" string).
2063 (delete-region beg (match-end 2))
2064 ;; Insert the new specification.
2065 (goto-char beg)
2066 (insert newspec))
2067 (setq fstring (buffer-substring 1 (point-max))))
2068 (cons 'format (cons fstring (nreverse flist)))))
2069
2070 (defun gnus-set-work-buffer ()
2071 (if (get-buffer gnus-work-buffer)
2072 (progn
2073 (set-buffer gnus-work-buffer)
2074 (erase-buffer))
2075 (set-buffer (get-buffer-create gnus-work-buffer))
2076 (kill-all-local-variables)
2077 (buffer-disable-undo (current-buffer))
2078 (gnus-add-current-to-buffer-list)))
2079
2080 ;; Article file names when saving.
2081
2082 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2083 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2084 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
2085 Otherwise, it is like ~/News/news/group/num."
2086 (let ((default
2087 (expand-file-name
2088 (concat (if (gnus-use-long-file-name 'not-save)
2089 (gnus-capitalize-newsgroup newsgroup)
2090 (gnus-newsgroup-directory-form newsgroup))
2091 "/" (int-to-string (mail-header-number headers)))
2092 (or gnus-article-save-directory "~/News"))))
2093 (if (and last-file
2094 (string-equal (file-name-directory default)
2095 (file-name-directory last-file))
2096 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2097 default
2098 (or last-file default))))
2099
2100 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2101 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2102 If variable `gnus-use-long-file-name' is non-nil, it is
2103 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2104 (let ((default
2105 (expand-file-name
2106 (concat (if (gnus-use-long-file-name 'not-save)
2107 newsgroup
2108 (gnus-newsgroup-directory-form newsgroup))
2109 "/" (int-to-string (mail-header-number headers)))
2110 (or gnus-article-save-directory "~/News"))))
2111 (if (and last-file
2112 (string-equal (file-name-directory default)
2113 (file-name-directory last-file))
2114 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2115 default
2116 (or last-file default))))
2117
2118 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2119 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2120 If variable `gnus-use-long-file-name' is non-nil, it is
2121 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2122 (or last-file
2123 (expand-file-name
2124 (if (gnus-use-long-file-name 'not-save)
2125 (gnus-capitalize-newsgroup newsgroup)
2126 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2127 (or gnus-article-save-directory "~/News"))))
2128
2129 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2130 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2131 If variable `gnus-use-long-file-name' is non-nil, it is
2132 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2133 (or last-file
2134 (expand-file-name
2135 (if (gnus-use-long-file-name 'not-save)
2136 newsgroup
2137 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2138 (or gnus-article-save-directory "~/News"))))
2139
2140 ;; For subscribing new newsgroup
2141
2142 (defun gnus-subscribe-hierarchical-interactive (groups)
2143 (let ((groups (sort groups 'string<))
2144 prefixes prefix start ans group starts)
2145 (while groups
2146 (setq prefixes (list "^"))
2147 (while (and groups prefixes)
2148 (while (not (string-match (car prefixes) (car groups)))
2149 (setq prefixes (cdr prefixes)))
2150 (setq prefix (car prefixes))
2151 (setq start (1- (length prefix)))
2152 (if (and (string-match "[^\\.]\\." (car groups) start)
2153 (cdr groups)
2154 (setq prefix
2155 (concat "^" (substring (car groups) 0 (match-end 0))))
2156 (string-match prefix (car (cdr groups))))
2157 (progn
2158 (setq prefixes (cons prefix prefixes))
2159 (message "Descend hierarchy %s? ([y]nsq): "
2160 (substring prefix 1 (1- (length prefix))))
2161 (setq ans (read-char))
2162 (cond ((= ans ?n)
2163 (while (and groups
2164 (string-match prefix
2165 (setq group (car groups))))
2166 (setq gnus-killed-list
2167 (cons group gnus-killed-list))
2168 (gnus-sethash group group gnus-killed-hashtb)
2169 (setq groups (cdr groups)))
2170 (setq starts (cdr starts)))
2171 ((= ans ?s)
2172 (while (and groups
2173 (string-match prefix
2174 (setq group (car groups))))
2175 (gnus-sethash group group gnus-killed-hashtb)
2176 (gnus-subscribe-alphabetically (car groups))
2177 (setq groups (cdr groups)))
2178 (setq starts (cdr starts)))
2179 ((= ans ?q)
2180 (while groups
2181 (setq group (car groups))
2182 (setq gnus-killed-list (cons group gnus-killed-list))
2183 (gnus-sethash group group gnus-killed-hashtb)
2184 (setq groups (cdr groups))))
2185 (t nil)))
2186 (message "Subscribe %s? ([n]yq)" (car groups))
2187 (setq ans (read-char))
2188 (setq group (car groups))
2189 (cond ((= ans ?y)
2190 (gnus-subscribe-alphabetically (car groups))
2191 (gnus-sethash group group gnus-killed-hashtb))
2192 ((= ans ?q)
2193 (while groups
2194 (setq group (car groups))
2195 (setq gnus-killed-list (cons group gnus-killed-list))
2196 (gnus-sethash group group gnus-killed-hashtb)
2197 (setq groups (cdr groups))))
2198 (t
2199 (setq gnus-killed-list (cons group gnus-killed-list))
2200 (gnus-sethash group group gnus-killed-hashtb)))
2201 (setq groups (cdr groups)))))))
2202
2203 (defun gnus-subscribe-randomly (newsgroup)
2204 "Subscribe new NEWSGROUP by making it the first newsgroup."
2205 (gnus-subscribe-newsgroup newsgroup))
2206
2207 (defun gnus-subscribe-alphabetically (newgroup)
2208 "Subscribe new NEWSGROUP and insert it in alphabetical order."
2209 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2210 (let ((groups (cdr gnus-newsrc-alist))
2211 before)
2212 (while (and (not before) groups)
2213 (if (string< newgroup (car (car groups)))
2214 (setq before (car (car groups)))
2215 (setq groups (cdr groups))))
2216 (gnus-subscribe-newsgroup newgroup before)))
2217
2218 (defun gnus-subscribe-hierarchically (newgroup)
2219 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
2220 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2221 (save-excursion
2222 (set-buffer (find-file-noselect gnus-current-startup-file))
2223 (let ((groupkey newgroup)
2224 before)
2225 (while (and (not before) groupkey)
2226 (goto-char (point-min))
2227 (let ((groupkey-re
2228 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
2229 (while (and (re-search-forward groupkey-re nil t)
2230 (progn
2231 (setq before (buffer-substring
2232 (match-beginning 1) (match-end 1)))
2233 (string< before newgroup)))))
2234 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
2235 (setq groupkey
2236 (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
2237 (substring groupkey (match-beginning 1) (match-end 1)))))
2238 (gnus-subscribe-newsgroup newgroup before))))
2239
2240 (defun gnus-subscribe-interactively (newsgroup)
2241 "Subscribe new NEWSGROUP interactively.
2242 It is inserted in hierarchical newsgroup order if subscribed. If not,
2243 it is killed."
2244 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
2245 (gnus-subscribe-hierarchically newsgroup)
2246 (setq gnus-killed-list (cons newsgroup gnus-killed-list))))
2247
2248 (defun gnus-subscribe-zombies (newsgroup)
2249 "Make new NEWSGROUP a zombie group."
2250 (setq gnus-zombie-list (cons newsgroup gnus-zombie-list)))
2251
2252 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
2253 "Subscribe new NEWSGROUP.
2254 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
2255 the first newsgroup."
2256 ;; We subscribe the group by changing its level to `subscribed'.
2257 (gnus-group-change-level
2258 newsgroup gnus-level-default-subscribed
2259 gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
2260 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
2261
2262 ;; For directories
2263
2264 (defun gnus-newsgroup-directory-form (newsgroup)
2265 "Make hierarchical directory name from NEWSGROUP name."
2266 (let ((newsgroup (gnus-newsgroup-savable-name newsgroup))
2267 (len (length newsgroup))
2268 idx)
2269 ;; If this is a foreign group, we don't want to translate the
2270 ;; entire name.
2271 (if (setq idx (string-match ":" newsgroup))
2272 (aset newsgroup idx ?/)
2273 (setq idx 0))
2274 ;; Replace all occurrences of `.' with `/'.
2275 (while (< idx len)
2276 (if (= (aref newsgroup idx) ?.)
2277 (aset newsgroup idx ?/))
2278 (setq idx (1+ idx)))
2279 newsgroup))
2280
2281 (defun gnus-newsgroup-savable-name (group)
2282 ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
2283 ;; with dots.
2284 (gnus-replace-chars-in-string group ?/ ?.))
2285
2286 (defun gnus-make-directory (dir)
2287 "Make DIRECTORY recursively."
2288 ;; Why don't we use `(make-directory dir 'parents)'? That's just one
2289 ;; of the many mysteries of the universe.
2290 (let* ((dir (expand-file-name dir default-directory))
2291 dirs err)
2292 (if (string-match "/$" dir)
2293 (setq dir (substring dir 0 (match-beginning 0))))
2294 ;; First go down the path until we find a directory that exists.
2295 (while (not (file-exists-p dir))
2296 (setq dirs (cons dir dirs))
2297 (string-match "/[^/]+$" dir)
2298 (setq dir (substring dir 0 (match-beginning 0))))
2299 ;; Then create all the subdirs.
2300 (while (and dirs (not err))
2301 (condition-case ()
2302 (make-directory (car dirs))
2303 (error (setq err t)))
2304 (setq dirs (cdr dirs)))
2305 ;; We return whether we were successful or not.
2306 (not dirs)))
2307
2308 (defun gnus-capitalize-newsgroup (newsgroup)
2309 "Capitalize NEWSGROUP name."
2310 (and (not (zerop (length newsgroup)))
2311 (concat (char-to-string (upcase (aref newsgroup 0)))
2312 (substring newsgroup 1))))
2313
2314 ;; Var
2315
2316 (defun gnus-simplify-subject (subject &optional re-only)
2317 "Remove `Re:' and words in parentheses.
2318 If optional argument RE-ONLY is non-nil, strip `Re:' only."
2319 (let ((case-fold-search t)) ;Ignore case.
2320 ;; Remove `Re:' and `Re^N:'.
2321 (if (string-match "^re:[ \t]*" subject)
2322 (setq subject (substring subject (match-end 0))))
2323 ;; Remove words in parentheses from end.
2324 (or re-only
2325 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
2326 (setq subject (substring subject 0 (match-beginning 0)))))
2327 ;; Return subject string.
2328 subject))
2329
2330 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
2331 ;; all whitespace.
2332 (defun gnus-simplify-subject-fuzzy (subject)
2333 (let ((case-fold-search t))
2334 (save-excursion
2335 (gnus-set-work-buffer)
2336 (insert subject)
2337 (inline (gnus-simplify-buffer-fuzzy))
2338 (buffer-string))))
2339
2340 (defun gnus-simplify-buffer-fuzzy ()
2341 (goto-char (point-min))
2342 ;; Fix by Stainless Steel Rat <ratinox@ccs.neu.edu>.
2343 (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*"
2344 nil t)
2345 (replace-match "" t t))
2346 (goto-char (point-min))
2347 (while (re-search-forward "[ \t\n]*([^()]*)[ \t\n]*$" nil t)
2348 (replace-match "" t t))
2349 (goto-char (point-min))
2350 (while (re-search-forward "[ \t]+" nil t)
2351 (replace-match " " t t))
2352 (goto-char (point-min))
2353 (while (re-search-forward "[ \t]+$" nil t)
2354 (replace-match "" t t))
2355 (goto-char (point-min))
2356 (while (re-search-forward "^[ \t]+" nil t)
2357 (replace-match "" t t))
2358 (if gnus-simplify-subject-fuzzy-regexp
2359 (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
2360 (replace-match "" t t))))
2361
2362 ;; Add the current buffer to the list of buffers to be killed on exit.
2363 (defun gnus-add-current-to-buffer-list ()
2364 (or (memq (current-buffer) gnus-buffer-list)
2365 (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
2366
2367 (defun gnus-string> (s1 s2)
2368 (not (or (string< s1 s2)
2369 (string= s1 s2))))
2370
2371 ;; Functions accessing headers.
2372 ;; Functions are more convenient than macros in some cases.
2373
2374 (defun gnus-header-number (header)
2375 (mail-header-number header))
2376
2377 (defun gnus-header-subject (header)
2378 (mail-header-subject header))
2379
2380 (defun gnus-header-from (header)
2381 (mail-header-from header))
2382
2383 (defun gnus-header-xref (header)
2384 (mail-header-xref header))
2385
2386 (defun gnus-header-lines (header)
2387 (mail-header-lines header))
2388
2389 (defun gnus-header-date (header)
2390 (mail-header-date header))
2391
2392 (defun gnus-header-id (header)
2393 (mail-header-id header))
2394
2395 (defun gnus-header-message-id (header)
2396 (mail-header-id header))
2397
2398 (defun gnus-header-chars (header)
2399 (mail-header-chars header))
2400
2401 (defun gnus-header-references (header)
2402 (mail-header-references header))
2403
2404 ;;; General various misc type functions.
2405
2406 (defun gnus-clear-system ()
2407 "Clear all variables and buffers."
2408 ;; Clear Gnus variables.
2409 (let ((variables gnus-variable-list))
2410 (while variables
2411 (set (car variables) nil)
2412 (setq variables (cdr variables))))
2413 ;; Clear other internal variables.
2414 (setq gnus-list-of-killed-groups nil
2415 gnus-have-read-active-file nil
2416 gnus-newsrc-alist nil
2417 gnus-newsrc-hashtb nil
2418 gnus-killed-list nil
2419 gnus-zombie-list nil
2420 gnus-killed-hashtb nil
2421 gnus-active-hashtb nil
2422 gnus-moderated-list nil
2423 gnus-description-hashtb nil
2424 gnus-newsgroup-headers nil
2425 gnus-newsgroup-headers-hashtb-by-number nil
2426 gnus-newsgroup-name nil
2427 gnus-server-alist nil
2428 gnus-current-select-method nil)
2429 ;; Reset any score variables.
2430 (and (boundp 'gnus-score-cache)
2431 (set 'gnus-score-cache nil))
2432 (and (boundp 'gnus-internal-global-score-files)
2433 (set 'gnus-internal-global-score-files nil))
2434 ;; Kill the startup file.
2435 (and gnus-current-startup-file
2436 (get-file-buffer gnus-current-startup-file)
2437 (kill-buffer (get-file-buffer gnus-current-startup-file)))
2438 ;; Save any cache buffers.
2439 (and gnus-use-cache (gnus-cache-save-buffers))
2440 ;; Clear the dribble buffer.
2441 (gnus-dribble-clear)
2442 ;; Kill global KILL file buffer.
2443 (if (get-file-buffer (gnus-newsgroup-kill-file nil))
2444 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
2445 (gnus-kill-buffer nntp-server-buffer)
2446 ;; Kill Gnus buffers.
2447 (while gnus-buffer-list
2448 (gnus-kill-buffer (car gnus-buffer-list))
2449 (setq gnus-buffer-list (cdr gnus-buffer-list))))
2450
2451 (defun gnus-windows-old-to-new (setting)
2452 ;; First we take care of the really, really old Gnus 3 actions.
2453 (if (symbolp setting)
2454 (setq setting
2455 (cond ((memq setting '(SelectArticle))
2456 'article)
2457 ((memq setting '(SelectSubject ExpandSubject))
2458 'summary)
2459 ((memq setting '(SelectNewsgroup ExitNewsgroup))
2460 'group)
2461 (t setting))))
2462 (if (or (listp setting)
2463 (not (and gnus-window-configuration
2464 (memq setting '(group summary article)))))
2465 setting
2466 (let* ((setting (if (eq setting 'group)
2467 (if (assq 'newsgroup gnus-window-configuration)
2468 'newsgroup
2469 'newsgroups) setting))
2470 (elem (car (cdr (assq setting gnus-window-configuration))))
2471 (total (apply '+ elem))
2472 (types '(group summary article))
2473 (pbuf (if (eq setting 'newsgroups) 'group 'summary))
2474 (i 0)
2475 perc
2476 out)
2477 (while (< i 3)
2478 (or (not (numberp (nth i elem)))
2479 (zerop (nth i elem))
2480 (progn
2481 (setq perc (/ (* 1.0 (nth 0 elem)) total))
2482 (setq out (cons (if (eq pbuf (nth i types))
2483 (vector (nth i types) perc 'point)
2484 (vector (nth i types) perc))
2485 out))))
2486 (setq i (1+ i)))
2487 (list (nreverse out)))))
2488
2489 (defun gnus-add-configuration (conf)
2490 (setq gnus-buffer-configuration
2491 (cons conf (delq (assq (car conf) gnus-buffer-configuration)
2492 gnus-buffer-configuration))))
2493
2494 (defun gnus-configure-windows (setting &optional force)
2495 (setq setting (gnus-windows-old-to-new setting))
2496 (let ((r (if (symbolp setting)
2497 (cdr (assq setting gnus-buffer-configuration))
2498 setting))
2499 (in-buf (current-buffer))
2500 rule val w height hor ohor heights sub jump-buffer
2501 rel total to-buf all-visible)
2502 (or r (error "No such setting: %s" setting))
2503
2504 (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r)))
2505 ;; All the windows mentioned are already visible, so we just
2506 ;; put point in the assigned buffer, and do not touch the
2507 ;; winconf.
2508 (select-window (get-buffer-window all-visible t))
2509
2510
2511 ;; Either remove all windows or just remove all Gnus windows.
2512 (if gnus-use-full-window
2513 (delete-other-windows)
2514 (gnus-remove-some-windows)
2515 (switch-to-buffer nntp-server-buffer))
2516
2517 (while r
2518 (setq hor (car r)
2519 ohor nil)
2520
2521 ;; We have to do the (possible) horizontal splitting before the
2522 ;; vertical.
2523 (if (and (listp (car hor))
2524 (eq (car (car hor)) 'horizontal))
2525 (progn
2526 (split-window
2527 nil
2528 (if (integerp (nth 1 (car hor)))
2529 (nth 1 (car hor))
2530 (- (frame-width) (floor (* (frame-width) (nth 1 (car hor))))))
2531 t)
2532 (setq hor (cdr hor))))
2533
2534 ;; Go through the rules and eval the elements that are to be
2535 ;; evalled.
2536 (while hor
2537 (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor))))
2538 (progn
2539 ;; Expand short buffer name.
2540 (setq w (aref val 0))
2541 (and (setq w (cdr (assq w gnus-window-to-buffer)))
2542 (progn
2543 (setq val (apply 'vector (mapcar 'identity val)))
2544 (aset val 0 w)))
2545 (setq ohor (cons val ohor))))
2546 (setq hor (cdr hor)))
2547 (setq rule (cons (nreverse ohor) rule))
2548 (setq r (cdr r)))
2549 (setq rule (nreverse rule))
2550
2551 ;; We tally the window sizes.
2552 (setq total (window-height))
2553 (while rule
2554 (setq hor (car rule))
2555 (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal))
2556 (setq hor (cdr hor)))
2557 (setq sub 0)
2558 (while hor
2559 (setq rel (aref (car hor) 1)
2560 heights (cons
2561 (cond ((and (floatp rel) (= 1.0 rel))
2562 'x)
2563 ((integerp rel)
2564 rel)
2565 (t
2566 (max (floor (* total rel)) 4)))
2567 heights)
2568 sub (+ sub (if (numberp (car heights)) (car heights) 0))
2569 hor (cdr hor)))
2570 (setq heights (nreverse heights)
2571 hor (car rule))
2572
2573 ;; We then go through these heights and create windows for them.
2574 (while heights
2575 (setq height (car heights)
2576 heights (cdr heights))
2577 (and (eq height 'x)
2578 (setq height (- total sub)))
2579 (and heights
2580 (split-window nil height))
2581 (setq to-buf (aref (car hor) 0))
2582 (switch-to-buffer
2583 (cond ((not to-buf)
2584 in-buf)
2585 ((symbolp to-buf)
2586 (symbol-value (aref (car hor) 0)))
2587 (t
2588 (aref (car hor) 0))))
2589 (and (> (length (car hor)) 2)
2590 (eq (aref (car hor) 2) 'point)
2591 (setq jump-buffer (current-buffer)))
2592 (other-window 1)
2593 (setq hor (cdr hor)))
2594
2595 (setq rule (cdr rule)))
2596
2597 ;; Finally, we pop to the buffer that's supposed to have point.
2598 (or jump-buffer (error "Missing `point' in spec for %s" setting))
2599
2600 (select-window (get-buffer-window jump-buffer t))
2601 (set-buffer jump-buffer))))
2602
2603 (defun gnus-all-windows-visible-p (rule)
2604 (let (invisible hor jump-buffer val buffer)
2605 ;; Go through the rules and eval the elements that are to be
2606 ;; evalled.
2607 (while (and rule (not invisible))
2608 (setq hor (car rule)
2609 rule (cdr rule))
2610 (while (and hor (not invisible))
2611 (if (setq val (if (vectorp (car hor))
2612 (car hor)
2613 (if (not (eq (car (car hor)) 'horizontal))
2614 (eval (car hor)))))
2615 (progn
2616 ;; Expand short buffer name.
2617 (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer))
2618 (aref val 0)))
2619 (setq buffer (if (symbolp buffer) (symbol-value buffer)
2620 buffer))
2621 (and (> (length val) 2) (eq 'point (aref val 2))
2622 (setq jump-buffer buffer))
2623 (setq invisible (not (and buffer (get-buffer-window buffer))))))
2624 (setq hor (cdr hor))))
2625 (and (not invisible) jump-buffer)))
2626
2627 (defun gnus-window-top-edge (&optional window)
2628 (nth 1 (window-edges window)))
2629
2630 (defun gnus-remove-some-windows ()
2631 (let ((buffers gnus-window-to-buffer)
2632 buf bufs lowest-buf lowest)
2633 (save-excursion
2634 ;; Remove windows on all known Gnus buffers.
2635 (while buffers
2636 (setq buf (cdr (car buffers)))
2637 (if (symbolp buf)
2638 (setq buf (and (boundp buf) (symbol-value buf))))
2639 (and buf
2640 (get-buffer-window buf)
2641 (progn
2642 (setq bufs (cons buf bufs))
2643 (pop-to-buffer buf)
2644 (if (or (not lowest)
2645 (< (gnus-window-top-edge) lowest))
2646 (progn
2647 (setq lowest (gnus-window-top-edge))
2648 (setq lowest-buf buf)))))
2649 (setq buffers (cdr buffers)))
2650 ;; Remove windows on *all* summary buffers.
2651 (let (wins)
2652 (walk-windows
2653 (lambda (win)
2654 (let ((buf (window-buffer win)))
2655 (if (string-match "^\\*Summary" (buffer-name buf))
2656 (progn
2657 (setq bufs (cons buf bufs))
2658 (pop-to-buffer buf)
2659 (if (or (not lowest)
2660 (< (gnus-window-top-edge) lowest))
2661 (progn
2662 (setq lowest-buf buf)
2663 (setq lowest (gnus-window-top-edge))))))))))
2664 (and lowest-buf
2665 (progn
2666 (pop-to-buffer lowest-buf)
2667 (switch-to-buffer nntp-server-buffer)))
2668 (while bufs
2669 (and (not (eq (car bufs) lowest-buf))
2670 (delete-windows-on (car bufs)))
2671 (setq bufs (cdr bufs))))))
2672
2673 (defun gnus-version ()
2674 "Version numbers of this version of Gnus."
2675 (interactive)
2676 (let ((methods gnus-valid-select-methods)
2677 (mess gnus-version)
2678 meth)
2679 ;; Go through all the legal select methods and add their version
2680 ;; numbers to the total version string. Only the backends that are
2681 ;; currently in use will have their message numbers taken into
2682 ;; consideration.
2683 (while methods
2684 (setq meth (intern (concat (car (car methods)) "-version")))
2685 (and (boundp meth)
2686 (stringp (symbol-value meth))
2687 (setq mess (concat mess "; " (symbol-value meth))))
2688 (setq methods (cdr methods)))
2689 (gnus-message 2 mess)))
2690
2691 (defun gnus-info-find-node ()
2692 "Find Info documentation of Gnus."
2693 (interactive)
2694 ;; Enlarge info window if needed.
2695 (let ((mode major-mode))
2696 (gnus-configure-windows 'info)
2697 (Info-goto-node (car (cdr (assq mode gnus-info-nodes))))))
2698
2699 (defun gnus-overload-functions (&optional overloads)
2700 "Overload functions specified by optional argument OVERLOADS.
2701 If nothing is specified, use the variable gnus-overload-functions."
2702 (let ((defs nil)
2703 (overloads (or overloads gnus-overload-functions)))
2704 (while overloads
2705 (setq defs (car overloads))
2706 (setq overloads (cdr overloads))
2707 ;; Load file before overloading function if necessary. Make
2708 ;; sure we cannot use `require' always.
2709 (and (not (fboundp (car defs)))
2710 (car (cdr (cdr defs)))
2711 (load (car (cdr (cdr defs))) nil 'nomessage))
2712 (fset (car defs) (car (cdr defs))))))
2713
2714 (defun gnus-replace-chars-in-string (string &rest pairs)
2715 "Replace characters in STRING from FROM to TO."
2716 (let ((string (substring string 0)) ;Copy string.
2717 (len (length string))
2718 (idx 0)
2719 sym to)
2720 (or (zerop (% (length pairs) 2))
2721 (error "Odd number of translation pairs"))
2722 (setplist 'sym pairs)
2723 ;; Replace all occurrences of FROM with TO.
2724 (while (< idx len)
2725 (if (setq to (get 'sym (aref string idx)))
2726 (aset string idx to))
2727 (setq idx (1+ idx)))
2728 string))
2729
2730 (defun gnus-days-between (date1 date2)
2731 ;; Return the number of days between date1 and date2.
2732 (- (gnus-day-number date1) (gnus-day-number date2)))
2733
2734 (defun gnus-day-number (date)
2735 (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
2736 (timezone-parse-date date))))
2737 (timezone-absolute-from-gregorian
2738 (nth 1 dat) (nth 2 dat) (car dat))))
2739
2740 ;; Returns a floating point number that says how many seconds have
2741 ;; lapsed between Jan 1 12:00:00 1970 and DATE.
2742 (defun gnus-seconds-since-epoch (date)
2743 (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2744 (timezone-parse-date date)))
2745 (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
2746 (timezone-parse-time
2747 (aref (timezone-parse-date date) 3))))
2748 (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2749 (timezone-parse-date "Jan 1 12:00:00 1970")))
2750 (tday (- (timezone-absolute-from-gregorian
2751 (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
2752 (timezone-absolute-from-gregorian
2753 (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
2754 (+ (nth 2 ttime)
2755 (* (nth 1 ttime) 60)
2756 (* 1.0 (nth 0 ttime) 60 60)
2757 (* 1.0 tday 60 60 24))))
2758
2759 (defun gnus-file-newer-than (file date)
2760 (let ((fdate (nth 5 (file-attributes file))))
2761 (or (> (car fdate) (car date))
2762 (and (= (car fdate) (car date))
2763 (> (nth 1 fdate) (nth 1 date))))))
2764
2765 (defun gnus-group-read-only-p (&optional group)
2766 "Check whether GROUP supports editing or not.
2767 If GROUP is nil, `gnus-newsgroup-name' will be checked instead. Note
2768 that that variable is buffer-local to the summary buffers."
2769 (let ((group (or group gnus-newsgroup-name)))
2770 (not (gnus-check-backend-function 'request-replace-article group))))
2771
2772 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
2773 ;; the echo area.
2774 (defun gnus-y-or-n-p (prompt)
2775 (prog1
2776 (y-or-n-p prompt)
2777 (message "")))
2778
2779 (defun gnus-yes-or-no-p (prompt)
2780 (prog1
2781 (yes-or-no-p prompt)
2782 (message "")))
2783
2784 ;; Check whether to use long file names.
2785 (defun gnus-use-long-file-name (symbol)
2786 ;; The variable has to be set...
2787 (and gnus-use-long-file-name
2788 ;; If it isn't a list, then we return t.
2789 (or (not (listp gnus-use-long-file-name))
2790 ;; If it is a list, and the list contains `symbol', we
2791 ;; return nil.
2792 (not (memq symbol gnus-use-long-file-name)))))
2793
2794 ;; I suspect there's a better way, but I haven't taken the time to do
2795 ;; it yet. -erik selberg@cs.washington.edu
2796 (defun gnus-dd-mmm (messy-date)
2797 "Return a string like DD-MMM from a big messy string"
2798 (let ((datevec (timezone-parse-date messy-date)))
2799 (format "%2s-%s"
2800 (or (aref datevec 2) "??")
2801 (capitalize
2802 (or (car
2803 (nth (1- (string-to-number (aref datevec 1)))
2804 timezone-months-assoc))
2805 "???")))))
2806
2807 ;; Make a hash table (default and minimum size is 255).
2808 ;; Optional argument HASHSIZE specifies the table size.
2809 (defun gnus-make-hashtable (&optional hashsize)
2810 (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
2811
2812 ;; Make a number that is suitable for hashing; bigger than MIN and one
2813 ;; less than 2^x.
2814 (defun gnus-create-hash-size (min)
2815 (let ((i 1))
2816 (while (< i min)
2817 (setq i (* 2 i)))
2818 (1- i)))
2819
2820 ;; Show message if message has a lower level than `gnus-verbose'.
2821 ;; Guide-line for numbers:
2822 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
2823 ;; for things that take a long time, 7 - not very important messages
2824 ;; on stuff, 9 - messages inside loops.
2825 (defun gnus-message (level &rest args)
2826 (if (<= level gnus-verbose)
2827 (apply 'message args)
2828 ;; We have to do this format thingy here even if the result isn't
2829 ;; shown - the return value has to be the same as the return value
2830 ;; from `message'.
2831 (apply 'format args)))
2832
2833 ;; Generate a unique new group name.
2834 (defun gnus-generate-new-group-name (leaf)
2835 (let ((name leaf)
2836 (num 0))
2837 (while (gnus-gethash name gnus-newsrc-hashtb)
2838 (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
2839 name))
2840
2841 (defun gnus-ephemeral-group-p (group)
2842 "Say whether GROUP is ephemeral or not."
2843 (assoc 'quit-config (gnus-find-method-for-group group)))
2844
2845 (defun gnus-group-quit-config (group)
2846 "Return the quit-config of GROUP."
2847 (nth 1 (assoc 'quit-config (gnus-find-method-for-group group))))
2848
2849 (defun gnus-simplify-mode-line ()
2850 "Make mode lines a bit simpler."
2851 (setq mode-line-modified "-- ")
2852 (if (listp mode-line-format)
2853 (progn
2854 (make-local-variable 'mode-line-format)
2855 (setq mode-line-format (copy-sequence mode-line-format))
2856 (and (equal (nth 3 mode-line-format) " ")
2857 (setcar (nthcdr 3 mode-line-format) "")))))
2858
2859 ;;; List and range functions
2860
2861 (defun gnus-last-element (list)
2862 "Return last element of LIST."
2863 (while (cdr list)
2864 (setq list (cdr list)))
2865 (car list))
2866
2867 (defun gnus-copy-sequence (list)
2868 "Do a complete, total copy of a list."
2869 (if (and (consp list) (not (consp (cdr list))))
2870 (cons (car list) (cdr list))
2871 (mapcar (lambda (elem) (if (consp elem)
2872 (if (consp (cdr elem))
2873 (gnus-copy-sequence elem)
2874 (cons (car elem) (cdr elem)))
2875 elem))
2876 list)))
2877
2878 (defun gnus-set-difference (list1 list2)
2879 "Return a list of elements of LIST1 that do not appear in LIST2."
2880 (let ((list1 (copy-sequence list1)))
2881 (while list2
2882 (setq list1 (delq (car list2) list1))
2883 (setq list2 (cdr list2)))
2884 list1))
2885
2886 (defun gnus-sorted-complement (list1 list2)
2887 "Return a list of elements of LIST1 that do not appear in LIST2.
2888 Both lists have to be sorted over <."
2889 (let (out)
2890 (if (or (null list1) (null list2))
2891 (or list1 list2)
2892 (while (and list1 list2)
2893 (cond ((= (car list1) (car list2))
2894 (setq list1 (cdr list1)
2895 list2 (cdr list2)))
2896 ((< (car list1) (car list2))
2897 (setq out (cons (car list1) out))
2898 (setq list1 (cdr list1)))
2899 (t
2900 (setq out (cons (car list2) out))
2901 (setq list2 (cdr list2)))))
2902 (nconc (nreverse out) (or list1 list2)))))
2903
2904 (defun gnus-intersection (list1 list2)
2905 (let ((result nil))
2906 (while list2
2907 (if (memq (car list2) list1)
2908 (setq result (cons (car list2) result)))
2909 (setq list2 (cdr list2)))
2910 result))
2911
2912 (defun gnus-sorted-intersection (list1 list2)
2913 ;; LIST1 and LIST2 have to be sorted over <.
2914 (let (out)
2915 (while (and list1 list2)
2916 (cond ((= (car list1) (car list2))
2917 (setq out (cons (car list1) out)
2918 list1 (cdr list1)
2919 list2 (cdr list2)))
2920 ((< (car list1) (car list2))
2921 (setq list1 (cdr list1)))
2922 (t
2923 (setq list2 (cdr list2)))))
2924 (nreverse out)))
2925
2926 (defun gnus-set-sorted-intersection (list1 list2)
2927 ;; LIST1 and LIST2 have to be sorted over <.
2928 ;; This function modifies LIST1.
2929 (let* ((top (cons nil list1))
2930 (prev top))
2931 (while (and list1 list2)
2932 (cond ((= (car list1) (car list2))
2933 (setq prev list1
2934 list1 (cdr list1)
2935 list2 (cdr list2)))
2936 ((< (car list1) (car list2))
2937 (setcdr prev (cdr list1))
2938 (setq list1 (cdr list1)))
2939 (t
2940 (setq list2 (cdr list2)))))
2941 (setcdr prev nil)
2942 (cdr top)))
2943
2944 (defun gnus-compress-sequence (numbers &optional always-list)
2945 "Convert list of numbers to a list of ranges or a single range.
2946 If ALWAYS-LIST is non-nil, this function will always release a list of
2947 ranges."
2948 (let* ((first (car numbers))
2949 (last (car numbers))
2950 result)
2951 (if (null numbers)
2952 nil
2953 (if (not (listp (cdr numbers)))
2954 numbers
2955 (while numbers
2956 (cond ((= last (car numbers)) nil) ;Omit duplicated number
2957 ((= (1+ last) (car numbers)) ;Still in sequence
2958 (setq last (car numbers)))
2959 (t ;End of one sequence
2960 (setq result
2961 (cons (if (= first last) first
2962 (cons first last)) result))
2963 (setq first (car numbers))
2964 (setq last (car numbers))))
2965 (setq numbers (cdr numbers)))
2966 (if (and (not always-list) (null result))
2967 (if (= first last) (list first) (cons first last))
2968 (nreverse (cons (if (= first last) first (cons first last))
2969 result)))))))
2970
2971 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
2972 (defun gnus-uncompress-range (ranges)
2973 "Expand a list of ranges into a list of numbers.
2974 RANGES is either a single range on the form `(num . num)' or a list of
2975 these ranges."
2976 (let (first last result)
2977 (cond
2978 ((null ranges)
2979 nil)
2980 ((not (listp (cdr ranges)))
2981 (setq first (car ranges))
2982 (setq last (cdr ranges))
2983 (while (<= first last)
2984 (setq result (cons first result))
2985 (setq first (1+ first)))
2986 (nreverse result))
2987 (t
2988 (while ranges
2989 (if (atom (car ranges))
2990 (if (numberp (car ranges))
2991 (setq result (cons (car ranges) result)))
2992 (setq first (car (car ranges)))
2993 (setq last (cdr (car ranges)))
2994 (while (<= first last)
2995 (setq result (cons first result))
2996 (setq first (1+ first))))
2997 (setq ranges (cdr ranges)))
2998 (nreverse result)))))
2999
3000 (defun gnus-add-to-range (ranges list)
3001 "Return a list of ranges that has all articles from both RANGES and LIST.
3002 Note: LIST has to be sorted over `<'."
3003 (if (not ranges)
3004 (gnus-compress-sequence list t)
3005 (setq list (copy-sequence list))
3006 (or (listp (cdr ranges))
3007 (setq ranges (list ranges)))
3008 (let ((out ranges)
3009 ilist lowest highest temp)
3010 (while (and ranges list)
3011 (setq ilist list)
3012 (setq lowest (or (and (atom (car ranges)) (car ranges))
3013 (car (car ranges))))
3014 (while (and list (cdr list) (< (car (cdr list)) lowest))
3015 (setq list (cdr list)))
3016 (if (< (car ilist) lowest)
3017 (progn
3018 (setq temp list)
3019 (setq list (cdr list))
3020 (setcdr temp nil)
3021 (setq out (nconc (gnus-compress-sequence ilist t) out))))
3022 (setq highest (or (and (atom (car ranges)) (car ranges))
3023 (cdr (car ranges))))
3024 (while (and list (<= (car list) highest))
3025 (setq list (cdr list)))
3026 (setq ranges (cdr ranges)))
3027 (if list
3028 (setq out (nconc (gnus-compress-sequence list t) out)))
3029 (setq out (sort out (lambda (r1 r2)
3030 (< (or (and (atom r1) r1) (car r1))
3031 (or (and (atom r2) r2) (car r2))))))
3032 (setq ranges out)
3033 (while ranges
3034 (if (atom (car ranges))
3035 (if (cdr ranges)
3036 (if (atom (car (cdr ranges)))
3037 (if (= (1+ (car ranges)) (car (cdr ranges)))
3038 (progn
3039 (setcar ranges (cons (car ranges)
3040 (car (cdr ranges))))
3041 (setcdr ranges (cdr (cdr ranges)))))
3042 (if (= (1+ (car ranges)) (car (car (cdr ranges))))
3043 (progn
3044 (setcar (car (cdr ranges)) (car ranges))
3045 (setcar ranges (car (cdr ranges)))
3046 (setcdr ranges (cdr (cdr ranges)))))))
3047 (if (cdr ranges)
3048 (if (atom (car (cdr ranges)))
3049 (if (= (1+ (cdr (car ranges))) (car (cdr ranges)))
3050 (progn
3051 (setcdr (car ranges) (car (cdr ranges)))
3052 (setcdr ranges (cdr (cdr ranges)))))
3053 (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges))))
3054 (progn
3055 (setcdr (car ranges) (cdr (car (cdr ranges))))
3056 (setcdr ranges (cdr (cdr ranges))))))))
3057 (setq ranges (cdr ranges)))
3058 out)))
3059
3060 (defun gnus-remove-from-range (ranges list)
3061 "Return a list of ranges that has all articles from LIST removed from RANGES.
3062 Note: LIST has to be sorted over `<'."
3063 ;; !!! This function shouldn't look like this, but I've got a headache.
3064 (gnus-compress-sequence
3065 (gnus-sorted-complement
3066 (gnus-uncompress-range ranges) list)))
3067
3068 (defun gnus-member-of-range (number ranges)
3069 (if (not (listp (cdr ranges)))
3070 (and (>= number (car ranges))
3071 (<= number (cdr ranges)))
3072 (let ((not-stop t))
3073 (while (and ranges
3074 (if (numberp (car ranges))
3075 (>= number (car ranges))
3076 (>= number (car (car ranges))))
3077 not-stop)
3078 (if (if (numberp (car ranges))
3079 (= number (car ranges))
3080 (and (>= number (car (car ranges)))
3081 (<= number (cdr (car ranges)))))
3082 (setq not-stop nil))
3083 (setq ranges (cdr ranges)))
3084 (not not-stop))))
3085
3086 \f
3087 ;;;
3088 ;;; Gnus group mode
3089 ;;;
3090
3091 (defvar gnus-group-mode-map nil)
3092 (defvar gnus-group-group-map nil)
3093 (defvar gnus-group-mark-map nil)
3094 (defvar gnus-group-list-map nil)
3095 (defvar gnus-group-help-map nil)
3096 (defvar gnus-group-sub-map nil)
3097 (put 'gnus-group-mode 'mode-class 'special)
3098
3099 (if gnus-group-mode-map
3100 nil
3101 (setq gnus-group-mode-map (make-keymap))
3102 (suppress-keymap gnus-group-mode-map)
3103 (define-key gnus-group-mode-map " " 'gnus-group-read-group)
3104 (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
3105 (define-key gnus-group-mode-map "\r" 'gnus-group-select-group)
3106 (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
3107 (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
3108 (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
3109 (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
3110 (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
3111 (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
3112 (define-key gnus-group-mode-map
3113 "\M-n" 'gnus-group-next-unread-group-same-level)
3114 (define-key gnus-group-mode-map
3115 "\M-p" 'gnus-group-prev-unread-group-same-level)
3116 (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group)
3117 (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group)
3118 (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
3119 (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
3120 (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current)
3121 (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all)
3122 (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
3123 (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
3124 (define-key gnus-group-mode-map "m" 'gnus-group-mail)
3125 (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
3126 (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group)
3127 (define-key gnus-group-mode-map "R" 'gnus-group-restart)
3128 (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file)
3129 (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server)
3130 (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
3131 (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups)
3132 (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group)
3133 (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups)
3134 (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos)
3135 (define-key gnus-group-mode-map "\C-c\M-\C-a" 'gnus-group-description-apropos)
3136 (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
3137 (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
3138 (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
3139 (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
3140 (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
3141 (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
3142 (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
3143 (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed)
3144 (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles)
3145 (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups)
3146 (define-key gnus-group-mode-map "V" 'gnus-version)
3147 (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc)
3148 (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
3149 (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble)
3150 (define-key gnus-group-mode-map "q" 'gnus-group-exit)
3151 (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
3152 (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
3153 (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)
3154 (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method)
3155 (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode)
3156 (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group)
3157 (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
3158 (define-key gnus-group-mode-map ">" 'end-of-buffer)
3159 (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug)
3160 (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups)
3161
3162 (define-key gnus-group-mode-map "#" 'gnus-group-mark-group)
3163 (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group)
3164 (define-prefix-command 'gnus-group-mark-map)
3165 (define-key gnus-group-mode-map "M" 'gnus-group-mark-map)
3166 (define-key gnus-group-mark-map "m" 'gnus-group-mark-group)
3167 (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group)
3168 (define-key gnus-group-mark-map "w" 'gnus-group-mark-region)
3169
3170 (define-prefix-command 'gnus-group-group-map)
3171 (define-key gnus-group-mode-map "G" 'gnus-group-group-map)
3172 (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group)
3173 (define-key gnus-group-group-map "h" 'gnus-group-make-help-group)
3174 (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group)
3175 (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group)
3176 (define-key gnus-group-group-map "m" 'gnus-group-make-group)
3177 (define-key gnus-group-group-map "E" 'gnus-group-edit-group)
3178 (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method)
3179 (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters)
3180 (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual)
3181 (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual)
3182 (define-key gnus-group-group-map "D" 'gnus-group-enter-directory)
3183 (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group)
3184 ;;(define-key gnus-group-group-map "sb" 'gnus-group-brew-soup)
3185 ;;(define-key gnus-group-group-map "sw" 'gnus-soup-save-areas)
3186 ;;(define-key gnus-group-group-map "ss" 'gnus-soup-send-replies)
3187 ;;(define-key gnus-group-group-map "sp" 'gnus-soup-pack-packet)
3188 ;;(define-key gnus-group-group-map "sr" 'nnsoup-pack-replies)
3189
3190 (define-prefix-command 'gnus-group-list-map)
3191 (define-key gnus-group-mode-map "A" 'gnus-group-list-map)
3192 (define-key gnus-group-list-map "k" 'gnus-group-list-killed)
3193 (define-key gnus-group-list-map "z" 'gnus-group-list-zombies)
3194 (define-key gnus-group-list-map "s" 'gnus-group-list-groups)
3195 (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups)
3196 (define-key gnus-group-list-map "a" 'gnus-group-apropos)
3197 (define-key gnus-group-list-map "d" 'gnus-group-description-apropos)
3198 (define-key gnus-group-list-map "m" 'gnus-group-list-matching)
3199 (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching)
3200
3201 (define-prefix-command 'gnus-group-help-map)
3202 (define-key gnus-group-mode-map "H" 'gnus-group-help-map)
3203 (define-key gnus-group-help-map "f" 'gnus-group-fetch-faq)
3204
3205 (define-prefix-command 'gnus-group-sub-map)
3206 (define-key gnus-group-mode-map "S" 'gnus-group-sub-map)
3207 (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level)
3208 (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group)
3209 (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group)
3210 (define-key gnus-group-sub-map "k" 'gnus-group-kill-group)
3211 (define-key gnus-group-sub-map "y" 'gnus-group-yank-group)
3212 (define-key gnus-group-sub-map "w" 'gnus-group-kill-region)
3213 (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies))
3214
3215 (defun gnus-group-mode ()
3216 "Major mode for reading news.
3217
3218 All normal editing commands are switched off.
3219 \\<gnus-group-mode-map>
3220 The group buffer lists (some of) the groups available. For instance,
3221 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
3222 lists all zombie groups.
3223
3224 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
3225 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
3226
3227 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
3228
3229 The following commands are available:
3230
3231 \\{gnus-group-mode-map}"
3232 (interactive)
3233 (if gnus-visual (gnus-group-make-menu-bar))
3234 (kill-all-local-variables)
3235 (gnus-simplify-mode-line)
3236 (setq major-mode 'gnus-group-mode)
3237 (setq mode-name "Group")
3238 (gnus-group-set-mode-line)
3239 (setq mode-line-process nil)
3240 (use-local-map gnus-group-mode-map)
3241 (buffer-disable-undo (current-buffer))
3242 (setq truncate-lines t)
3243 (setq buffer-read-only t)
3244 (run-hooks 'gnus-group-mode-hook))
3245
3246 (defun gnus-mouse-pick-group (e)
3247 (interactive "e")
3248 (mouse-set-point e)
3249 (gnus-group-read-group nil))
3250
3251 ;; Look at LEVEL and find out what the level is really supposed to be.
3252 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
3253 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
3254 (defun gnus-group-default-level (&optional level number-or-nil)
3255 (cond
3256 (gnus-group-use-permanent-levels
3257 (setq gnus-group-default-list-level
3258 (or level gnus-group-default-list-level))
3259 (or gnus-group-default-list-level gnus-level-subscribed))
3260 (number-or-nil
3261 level)
3262 (t
3263 (or level gnus-group-default-list-level gnus-level-subscribed))))
3264
3265
3266 (defvar gnus-tmp-prev-perm nil)
3267
3268 ;;;###autoload
3269 (defun gnus-no-server (&optional arg)
3270 "Read network news.
3271 If ARG is a positive number, Gnus will use that as the
3272 startup level. If ARG is nil, Gnus will be started at level 2.
3273 If ARG is non-nil and not a positive number, Gnus will
3274 prompt the user for the name of an NNTP server to use.
3275 As opposed to `gnus', this command will not connect to the local server."
3276 (interactive "P")
3277 (let ((perm
3278 (cons gnus-group-use-permanent-levels gnus-group-default-list-level)))
3279 (setq gnus-tmp-prev-perm nil)
3280 (setq gnus-group-use-permanent-levels t)
3281 (gnus (or arg (1- gnus-level-default-subscribed)) t)
3282 (setq gnus-tmp-prev-perm perm)))
3283
3284 ;;;###autoload
3285 (defun read-news (&optional arg dont-connect)
3286 "Read network news. This is an alias for the `gnus' command."
3287 (gnus arg dont-connect))
3288
3289 ;;;###autoload
3290 (defun gnus (&optional arg dont-connect)
3291 "Read network news.
3292 If ARG is non-nil and a positive number, Gnus will use that as the
3293 startup level. If ARG is non-nil and not a positive number, Gnus will
3294 prompt the user for the name of an NNTP server to use."
3295 (interactive "P")
3296 (if (get-buffer gnus-group-buffer)
3297 (progn
3298 (switch-to-buffer gnus-group-buffer)
3299 (gnus-group-get-new-news))
3300
3301 (gnus-clear-system)
3302
3303 (nnheader-init-server-buffer)
3304 ;; We do this if `gnus-no-server' has been run.
3305 (if gnus-tmp-prev-perm
3306 (setq gnus-group-use-permanent-levels (car gnus-tmp-prev-perm)
3307 gnus-group-default-list-level (cdr gnus-tmp-prev-perm)
3308 gnus-tmp-prev-perm nil))
3309 (gnus-read-init-file)
3310
3311 (gnus-group-setup-buffer)
3312 (let ((buffer-read-only nil))
3313 (erase-buffer)
3314 (if (not gnus-inhibit-startup-message)
3315 (progn
3316 (gnus-group-startup-message)
3317 (sit-for 0))))
3318
3319 (let ((level (and arg (numberp arg) (> arg 0) arg))
3320 did-connect)
3321 (unwind-protect
3322 (progn
3323 (or dont-connect
3324 (setq did-connect
3325 (gnus-start-news-server (and arg (not level))))))
3326 (if (and (not dont-connect)
3327 (not did-connect))
3328 (gnus-group-quit)
3329 (run-hooks 'gnus-startup-hook)
3330 ;; NNTP server is successfully open.
3331
3332 ;; Find the current startup file name.
3333 (setq gnus-current-startup-file
3334 (gnus-make-newsrc-file gnus-startup-file))
3335
3336 ;; Read the dribble file.
3337 (and gnus-use-dribble-file (gnus-dribble-read-file))
3338
3339 (gnus-summary-make-display-table)
3340 (gnus-setup-news nil level)
3341 (gnus-group-list-groups level)
3342 (gnus-configure-windows 'group))))))
3343
3344 (defun gnus-unload ()
3345 "Unload all Gnus features."
3346 (interactive)
3347 (or (boundp 'load-history)
3348 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
3349 (let ((history load-history)
3350 feature)
3351 (while history
3352 (and (string-match "^gnus" (car (car history)))
3353 (setq feature (cdr (assq 'provide (car history))))
3354 (unload-feature feature 'force))
3355 (setq history (cdr history)))))
3356
3357 (defun gnus-group-startup-message (&optional x y)
3358 "Insert startup message in current buffer."
3359 ;; Insert the message.
3360 (erase-buffer)
3361 (insert
3362 (format "
3363 _ ___ _ _
3364 _ ___ __ ___ __ _ ___
3365 __ _ ___ __ ___
3366 _ ___ _
3367 _ _ __ _
3368 ___ __ _
3369 __ _
3370 _ _ _
3371 _ _ _
3372 _ _ _
3373 __ ___
3374 _ _ _ _
3375 _ _
3376 _ _
3377 _ _
3378 _
3379 __
3380
3381
3382 Gnus * A newsreader for Emacsen
3383 A Praxis release * larsi@ifi.uio.no
3384 "
3385 gnus-version))
3386 ;; And then hack it.
3387 ;; 18 is the longest line.
3388 (indent-rigidly (point-min) (point-max)
3389 (/ (max (- (window-width) (or x 46)) 0) 2))
3390 (goto-char (point-min))
3391 (let* ((pheight (count-lines (point-min) (point-max)))
3392 (wheight (window-height))
3393 (rest (- wheight pheight)))
3394 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
3395
3396
3397
3398 ;; Fontify some.
3399 (goto-char (point-min))
3400 (search-forward "Praxis")
3401 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3402 (goto-char (point-min)))
3403
3404 (defun gnus-group-startup-message-old (&optional x y)
3405 "Insert startup message in current buffer."
3406 ;; Insert the message.
3407 (erase-buffer)
3408 (insert
3409 (format "
3410 %s
3411 A newsreader
3412 for GNU Emacs
3413
3414 Based on GNUS
3415 written by
3416 Masanobu UMEDA
3417
3418 A Praxis Release
3419 larsi@ifi.uio.no
3420 "
3421 gnus-version))
3422 ;; And then hack it.
3423 ;; 18 is the longest line.
3424 (indent-rigidly (point-min) (point-max)
3425 (/ (max (- (window-width) (or x 28)) 0) 2))
3426 (goto-char (point-min))
3427 ;; +4 is fuzzy factor.
3428 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))
3429
3430 ;; Fontify some.
3431 (goto-char (point-min))
3432 (search-forward "Praxis")
3433 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3434 (goto-char (point-min)))
3435
3436 (defun gnus-group-setup-buffer ()
3437 (or (get-buffer gnus-group-buffer)
3438 (progn
3439 (switch-to-buffer gnus-group-buffer)
3440 (gnus-add-current-to-buffer-list)
3441 (gnus-group-mode)
3442 (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
3443
3444 (defun gnus-group-list-groups (&optional level unread)
3445 "List newsgroups with level LEVEL or lower that have unread articles.
3446 Default is all subscribed groups.
3447 If argument UNREAD is non-nil, groups with no unread articles are also
3448 listed."
3449 (interactive (list (if current-prefix-arg
3450 (prefix-numeric-value current-prefix-arg)
3451 (or
3452 (gnus-group-default-level nil t)
3453 gnus-group-default-list-level
3454 gnus-level-subscribed))))
3455 (or level
3456 (setq level (car gnus-group-list-mode)
3457 unread (cdr gnus-group-list-mode)))
3458 (setq level (gnus-group-default-level level))
3459 (gnus-group-setup-buffer) ;May call from out of group buffer
3460 (let ((case-fold-search nil)
3461 (group (gnus-group-group-name)))
3462 (funcall gnus-group-prepare-function level unread nil)
3463 (if (zerop (buffer-size))
3464 (gnus-message 5 gnus-no-groups-message)
3465 (goto-char (point-min))
3466 (if (not group)
3467 ;; Go to the first group with unread articles.
3468 (gnus-group-search-forward nil nil nil t)
3469 ;; Find the right group to put point on. If the current group
3470 ;; has disappeared in the new listing, try to find the next
3471 ;; one. If no next one can be found, just leave point at the
3472 ;; first newsgroup in the buffer.
3473 (if (not (gnus-goto-char
3474 (text-property-any (point-min) (point-max)
3475 'gnus-group (intern group))))
3476 (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb))))
3477 (while (and newsrc
3478 (not (gnus-goto-char
3479 (text-property-any
3480 (point-min) (point-max) 'gnus-group
3481 (intern (car (car newsrc)))))))
3482 (setq newsrc (cdr newsrc)))
3483 (or newsrc (progn (goto-char (point-max))
3484 (forward-line -1))))))
3485 ;; Adjust cursor point.
3486 (gnus-group-position-cursor))))
3487
3488 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
3489 "List all newsgroups with unread articles of level LEVEL or lower.
3490 If ALL is non-nil, list groups that have no unread articles.
3491 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3492 If REGEXP, only list groups matching REGEXP."
3493 (set-buffer gnus-group-buffer)
3494 (let ((buffer-read-only nil)
3495 (newsrc (cdr gnus-newsrc-alist))
3496 (lowest (or lowest 1))
3497 info clevel unread group)
3498 (erase-buffer)
3499 (if (< lowest gnus-level-zombie)
3500 ;; List living groups.
3501 (while newsrc
3502 (setq info (car newsrc)
3503 group (car info)
3504 newsrc (cdr newsrc)
3505 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3506 (and unread ; This group might be bogus
3507 (or (not regexp)
3508 (string-match regexp group))
3509 (<= (setq clevel (car (cdr info))) level)
3510 (>= clevel lowest)
3511 (or all ; We list all groups?
3512 (eq unread t) ; We list unactivated groups
3513 (> unread 0) ; We list groups with unread articles
3514 (cdr (assq 'tick (nth 3 info)))) ; And ticked groups
3515 (gnus-group-insert-group-line
3516 nil group (car (cdr info)) (nth 3 info) unread (nth 4 info)))))
3517
3518 ;; List dead groups.
3519 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
3520 (gnus-group-prepare-flat-list-dead
3521 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
3522 gnus-level-zombie ?Z
3523 regexp))
3524 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
3525 (gnus-group-prepare-flat-list-dead
3526 (setq gnus-killed-list (sort gnus-killed-list 'string<))
3527 gnus-level-killed ?K regexp))
3528
3529 (gnus-group-set-mode-line)
3530 (setq gnus-group-list-mode (cons level all))
3531 (run-hooks 'gnus-group-prepare-hook)))
3532
3533 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
3534 ;; List zombies and killed lists somewhat faster, which was
3535 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
3536 ;; this by ignoring the group format specification altogether.
3537 (let (group beg)
3538 (while groups
3539 (setq group (car groups)
3540 groups (cdr groups))
3541 (if (or (not regexp)
3542 (string-match regexp group))
3543 (progn
3544 (setq beg (point))
3545 (insert (format " %c *: %s\n" mark group))
3546 (add-text-properties
3547 beg (1+ beg)
3548 (list 'gnus-group (intern group)
3549 'gnus-unread t
3550 'gnus-level level)))))))
3551
3552 (defun gnus-group-real-name (group)
3553 "Find the real name of a foreign newsgroup."
3554 (if (string-match ":[^:]+$" group)
3555 (substring group (1+ (match-beginning 0)))
3556 group))
3557
3558 (defun gnus-group-prefixed-name (group method)
3559 "Return the whole name from GROUP and METHOD."
3560 (and (stringp method) (setq method (gnus-server-to-method method)))
3561 (concat (format "%s" (car method))
3562 (if (and
3563 (assoc (format "%s" (car method)) (gnus-methods-using 'address))
3564 (not (string= (nth 1 method) "")))
3565 (concat "+" (nth 1 method)))
3566 ":" group))
3567
3568 (defun gnus-group-real-prefix (group)
3569 "Return the prefix of the current group name."
3570 (if (string-match "^[^:]+:" group)
3571 (substring group 0 (match-end 0))
3572 ""))
3573
3574 (defun gnus-group-method-name (group)
3575 "Return the method used for selecting GROUP."
3576 (let ((prefix (gnus-group-real-prefix group)))
3577 (if (equal prefix "")
3578 gnus-select-method
3579 (if (string-match "^[^\\+]+\\+" prefix)
3580 (list (intern (substring prefix 0 (1- (match-end 0))))
3581 (substring prefix (match-end 0) (1- (length prefix))))
3582 (list (intern (substring prefix 0 (1- (length prefix)))) "")))))
3583
3584 (defun gnus-group-foreign-p (group)
3585 "Return nil if GROUP is native, non-nil if it is foreign."
3586 (string-match ":" group))
3587
3588 (defun gnus-group-set-info (info &optional method-only-group part)
3589 (let* ((entry (gnus-gethash
3590 (or method-only-group (car info)) gnus-newsrc-hashtb))
3591 (part-info info)
3592 (info (if method-only-group (nth 2 entry) info)))
3593 (if (not method-only-group)
3594 ()
3595 (or entry
3596 (error "Trying to change non-existent group %s" method-only-group))
3597 ;; We have received parts of the actual group info - either the
3598 ;; select method or the group parameters. We first check
3599 ;; whether we have to extend the info, and if so, do that.
3600 (let ((len (length info))
3601 (total (if (eq part 'method) 5 6)))
3602 (and (< len total)
3603 (setcdr (nthcdr (1- len) info)
3604 (make-list (- total len) nil)))
3605 ;; Then we enter the new info.
3606 (setcar (nthcdr (1- total) info) part-info)))
3607 ;; We uncompress some lists of marked articles.
3608 (let (marked)
3609 (if (not (setq marked (nth 3 info)))
3610 ()
3611 (while marked
3612 (or (eq 'score (car (car marked)))
3613 (eq 'bookmark (car (car marked)))
3614 (eq 'killed (car (car marked)))
3615 (setcdr (car marked)
3616 (gnus-uncompress-range (cdr (car marked)))))
3617 (setq marked (cdr marked)))))
3618 (if entry
3619 ()
3620 ;; This is a new group, so we just create it.
3621 (save-excursion
3622 (set-buffer gnus-group-buffer)
3623 (if (nth 4 info)
3624 ;; It's a foreign group...
3625 (gnus-group-make-group
3626 (gnus-group-real-name (car info))
3627 (prin1-to-string (car (nth 4 info)))
3628 (nth 1 (nth 4 info)))
3629 ;; It's a native group.
3630 (gnus-group-make-group (car info)))
3631 (gnus-message 6 "Note: New group created")
3632 (setq entry
3633 (gnus-gethash (gnus-group-prefixed-name
3634 (gnus-group-real-name (car info))
3635 (or (nth 4 info) gnus-select-method))
3636 gnus-newsrc-hashtb))))
3637 ;; Whether it was a new group or not, we now have the entry, so we
3638 ;; can do the update.
3639 (if entry
3640 (progn
3641 (setcar (nthcdr 2 entry) info)
3642 (if (and (not (eq (car entry) t))
3643 (gnus-gethash (car info) gnus-active-hashtb))
3644 (let ((marked (nth 3 info)))
3645 (setcar entry
3646 (max 0 (- (length (gnus-list-of-unread-articles
3647 (car info)))
3648 (length (cdr (assq 'tick marked)))
3649 (length (cdr (assq 'dormant marked)))))))))
3650 (error "No such group: %s" (car info)))))
3651
3652 (defun gnus-group-set-method-info (group select-method)
3653 (gnus-group-set-info select-method group 'method))
3654
3655 (defun gnus-group-set-params-info (group params)
3656 (gnus-group-set-info params group 'params))
3657
3658 (defun gnus-group-update-group-line ()
3659 "This function updates the current line in the newsgroup buffer and
3660 moves the point to the colon."
3661 (let* ((buffer-read-only nil)
3662 (group (gnus-group-group-name))
3663 (entry (and group (gnus-gethash group gnus-newsrc-hashtb))))
3664 (if (and entry (not (gnus-ephemeral-group-p group)))
3665 (gnus-dribble-enter
3666 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3667 ")")))
3668 (beginning-of-line)
3669 (delete-region (point) (progn (forward-line 1) (point)))
3670 (gnus-group-insert-group-line-info group)
3671 (forward-line -1)
3672 (gnus-group-position-cursor)))
3673
3674 (defun gnus-group-insert-group-line-info (group)
3675 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
3676 active info)
3677 (if entry
3678 (progn
3679 (setq info (nth 2 entry))
3680 (gnus-group-insert-group-line
3681 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
3682 (setq active (gnus-gethash group gnus-active-hashtb))
3683 (gnus-group-insert-group-line
3684 nil group
3685 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
3686 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))))
3687
3688 (defun gnus-group-insert-group-line (gformat group level marked number method)
3689 (let* ((gformat (or gformat gnus-group-line-format-spec))
3690 (active (gnus-gethash group gnus-active-hashtb))
3691 (number-total (if active (1+ (- (cdr active) (car active))) 0))
3692 (number-of-dormant (length (cdr (assq 'dormant marked))))
3693 (number-of-ticked (length (cdr (assq 'tick marked))))
3694 (number-of-ticked-and-dormant
3695 (+ number-of-ticked number-of-dormant))
3696 (number-of-unread-unticked
3697 (if (numberp number) (int-to-string (max 0 number))
3698 "*"))
3699 (number-of-read
3700 (if (numberp number)
3701 (max 0 (- number-total number))
3702 "*"))
3703 (subscribed (cond ((<= level gnus-level-subscribed) ? )
3704 ((<= level gnus-level-unsubscribed) ?U)
3705 ((= level gnus-level-zombie) ?Z)
3706 (t ?K)))
3707 (qualified-group (gnus-group-real-name group))
3708 (newsgroup-description
3709 (if gnus-description-hashtb
3710 (or (gnus-gethash group gnus-description-hashtb) "")
3711 ""))
3712 (moderated (if (member group gnus-moderated-list) ?m ? ))
3713 (moderated-string (if (eq moderated ?m) "(m)" ""))
3714 (method (gnus-server-get-method group method))
3715 (news-server (or (car (cdr method)) ""))
3716 (news-method (or (car method) ""))
3717 (news-method-string
3718 (if method (format "(%s:%s)" (car method) (car (cdr method))) ""))
3719 (marked (if (and
3720 (numberp number)
3721 (zerop number)
3722 (> number-of-ticked 0))
3723 ?* ? ))
3724 (number (if (eq number t) "*" (+ number number-of-dormant
3725 number-of-ticked)))
3726 (process-marked (if (member group gnus-group-marked)
3727 gnus-process-mark ? ))
3728 (buffer-read-only nil)
3729 header ; passed as parameter to user-funcs.
3730 b)
3731 (beginning-of-line)
3732 (setq b (point))
3733 ;; Insert the text.
3734 (insert (eval gformat))
3735
3736 (add-text-properties
3737 b (1+ b) (list 'gnus-group (intern group)
3738 'gnus-unread (if (numberp number)
3739 (string-to-int number-of-unread-unticked)
3740 t)
3741 'gnus-marked marked
3742 'gnus-level level))))
3743
3744 (defun gnus-group-update-group (group &optional visible-only)
3745 "Update newsgroup info of GROUP.
3746 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already."
3747 (save-excursion
3748 (set-buffer gnus-group-buffer)
3749 (let ((buffer-read-only nil)
3750 visible)
3751 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
3752 (if (and entry
3753 (not (gnus-ephemeral-group-p group)))
3754 (gnus-dribble-enter
3755 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3756 ")"))))
3757 ;; Buffer may be narrowed.
3758 (save-restriction
3759 (widen)
3760 ;; Search a line to modify. If the buffer is large, the search
3761 ;; takes long time. In most cases, current point is on the line
3762 ;; we are looking for. So, first of all, check current line.
3763 (if (or (progn
3764 (beginning-of-line)
3765 (eq (get-text-property (point) 'gnus-group)
3766 (intern group)))
3767 (progn
3768 (gnus-goto-char
3769 (text-property-any
3770 (point-min) (point-max) 'gnus-group (intern group)))))
3771 ;; GROUP is listed in current buffer. So, delete old line.
3772 (progn
3773 (setq visible t)
3774 (beginning-of-line)
3775 (delete-region (point) (progn (forward-line 1) (point))))
3776 ;; No such line in the buffer, find out where it's supposed to
3777 ;; go, and insert it there (or at the end of the buffer).
3778 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
3779 (or visible-only
3780 (let ((entry
3781 (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb)))))
3782 (while (and entry
3783 (car entry)
3784 (not
3785 (gnus-goto-char
3786 (text-property-any
3787 (point-min) (point-max)
3788 'gnus-group (intern (car (car entry)))))))
3789 (setq entry (cdr entry)))
3790 (or entry (goto-char (point-max)))))))
3791 (if (or visible (not visible-only))
3792 (gnus-group-insert-group-line-info group))
3793 (gnus-group-set-mode-line))))
3794
3795 (defun gnus-group-set-mode-line ()
3796 (if (memq 'group gnus-updated-mode-lines)
3797 (let* ((gformat (or gnus-group-mode-line-format-spec
3798 (setq gnus-group-mode-line-format-spec
3799 (gnus-parse-format
3800 gnus-group-mode-line-format
3801 gnus-group-mode-line-format-alist))))
3802 (news-server (car (cdr gnus-select-method)))
3803 (news-method (car gnus-select-method))
3804 (max-len 60)
3805 header ;Dummy binding for user-defined specs.
3806 (mode-string (eval gformat)))
3807 (setq mode-string (eval gformat))
3808 (if (> (length mode-string) max-len)
3809 (setq mode-string (substring mode-string 0 (- max-len 4))))
3810 (setq mode-line-buffer-identification mode-string)
3811 (set-buffer-modified-p t))))
3812
3813 (defun gnus-group-group-name ()
3814 "Get the name of the newsgroup on the current line."
3815 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
3816 (and group (symbol-name group))))
3817
3818 (defun gnus-group-group-level ()
3819 "Get the level of the newsgroup on the current line."
3820 (get-text-property (gnus-point-at-bol) 'gnus-level))
3821
3822 (defun gnus-group-group-unread ()
3823 "Get the number of unread articles of the newsgroup on the current line."
3824 (get-text-property (gnus-point-at-bol) 'gnus-unread))
3825
3826 (defun gnus-group-search-forward (&optional backward all level first-too)
3827 "Find the next newsgroup with unread articles.
3828 If BACKWARD is non-nil, find the previous newsgroup instead.
3829 If ALL is non-nil, just find any newsgroup.
3830 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
3831 group exists.
3832 If FIRST-TOO, the current line is also eligible as a target."
3833 (let ((way (if backward -1 1))
3834 (low gnus-level-killed)
3835 (beg (point))
3836 pos found lev)
3837 (if (and backward (progn (beginning-of-line)) (bobp))
3838 nil
3839 (or first-too (forward-line way))
3840 (while (and
3841 (not (eobp))
3842 (not (setq
3843 found
3844 (and (or all
3845 (and
3846 (let ((unread
3847 (get-text-property (point) 'gnus-unread)))
3848 (or (eq unread t) (and unread (> unread 0))))
3849 (setq lev (get-text-property (point)
3850 'gnus-level))
3851 (<= lev gnus-level-subscribed)))
3852 (or (not level)
3853 (and (setq lev (get-text-property (point)
3854 'gnus-level))
3855 (or (= lev level)
3856 (and (< lev low)
3857 (< level lev)
3858 (progn
3859 (setq low lev)
3860 (setq pos (point))
3861 nil))))))))
3862 (zerop (forward-line way)))))
3863 (if found
3864 (progn (gnus-group-position-cursor) t)
3865 (goto-char (or pos beg))
3866 (and pos t))))
3867
3868 ;;; Gnus group mode commands
3869
3870 ;; Group marking.
3871
3872 (defun gnus-group-mark-group (n &optional unmark no-advance)
3873 "Mark the current group."
3874 (interactive "p")
3875 (let ((buffer-read-only nil)
3876 group)
3877 (while
3878 (and (> n 0)
3879 (setq group (gnus-group-group-name))
3880 (progn
3881 (beginning-of-line)
3882 (forward-char
3883 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
3884 (delete-char 1)
3885 (if unmark
3886 (progn
3887 (insert " ")
3888 (setq gnus-group-marked (delete group gnus-group-marked)))
3889 (insert "#")
3890 (setq gnus-group-marked
3891 (cons group (delete group gnus-group-marked))))
3892 t)
3893 (or no-advance (zerop (gnus-group-next-group 1))))
3894 (setq n (1- n)))
3895 (gnus-summary-position-cursor)
3896 n))
3897
3898 (defun gnus-group-unmark-group (n)
3899 "Remove the mark from the current group."
3900 (interactive "p")
3901 (gnus-group-mark-group n 'unmark))
3902
3903 (defun gnus-group-mark-region (unmark beg end)
3904 "Mark all groups between point and mark.
3905 If UNMARK, remove the mark instead."
3906 (interactive "P\nr")
3907 (let ((num (count-lines beg end)))
3908 (save-excursion
3909 (goto-char beg)
3910 (- num (gnus-group-mark-group num unmark)))))
3911
3912 (defun gnus-group-remove-mark (group)
3913 (and (gnus-group-goto-group group)
3914 (save-excursion
3915 (gnus-group-mark-group 1 'unmark t))))
3916
3917 ;; Return a list of groups to work on. Take into consideration N (the
3918 ;; prefix) and the list of marked groups.
3919 (defun gnus-group-process-prefix (n)
3920 (cond (n
3921 (setq n (prefix-numeric-value n))
3922 ;; There is a prefix, so we return a list of the N next
3923 ;; groups.
3924 (let ((way (if (< n 0) -1 1))
3925 (n (abs n))
3926 group groups)
3927 (save-excursion
3928 (while (and (> n 0)
3929 (setq group (gnus-group-group-name)))
3930 (setq groups (cons group groups))
3931 (setq n (1- n))
3932 (forward-line way)))
3933 (nreverse groups)))
3934 (gnus-group-marked
3935 ;; No prefix, but a list of marked articles.
3936 (reverse gnus-group-marked))
3937 (t
3938 ;; Neither marked articles or a prefix, so we return the
3939 ;; current group.
3940 (let ((group (gnus-group-group-name)))
3941 (and group (list group))))))
3942
3943 ;; Selecting groups.
3944
3945 (defun gnus-group-read-group (&optional all no-article group)
3946 "Read news in this newsgroup.
3947 If the prefix argument ALL is non-nil, already read articles become
3948 readable. If the optional argument NO-ARTICLE is non-nil, no article
3949 will be auto-selected upon group entry."
3950 (interactive "P")
3951 (let ((group (or group (gnus-group-group-name)))
3952 number active marked entry)
3953 (or group (error "No group on current line"))
3954 (setq marked
3955 (nth 3 (nth 2 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))))
3956 ;; This group might be a dead group. In that case we have to get
3957 ;; the number of unread articles from `gnus-active-hashtb'.
3958 (if entry
3959 (setq number (car entry))
3960 (if (setq active (gnus-gethash group gnus-active-hashtb))
3961 (setq number (- (1+ (cdr active)) (car active)))))
3962 (gnus-summary-read-group
3963 group (or all (and (numberp number)
3964 (zerop (+ number (length (cdr (assq 'tick marked)))
3965 (length (cdr (assq 'dormant marked)))))))
3966 no-article)))
3967
3968 (defun gnus-group-select-group (&optional all)
3969 "Select this newsgroup.
3970 No article is selected automatically.
3971 If argument ALL is non-nil, already read articles become readable."
3972 (interactive "P")
3973 (gnus-group-read-group all t))
3974
3975 (defun gnus-group-select-group-all ()
3976 "Select the current group and display all articles in it."
3977 (interactive)
3978 (gnus-group-select-group 'all))
3979
3980 ;; Enter a group that is not in the group buffer. Non-nil is returned
3981 ;; if selection was successful.
3982 (defun gnus-group-read-ephemeral-group
3983 (group method &optional activate quit-config)
3984 (let ((group (if (gnus-group-foreign-p group) group
3985 (gnus-group-prefixed-name group method))))
3986 (gnus-sethash
3987 group
3988 (list t nil (list group gnus-level-default-subscribed nil nil
3989 (append method
3990 (list
3991 (list 'quit-config
3992 (if quit-config quit-config
3993 (cons (current-buffer) 'summary)))))))
3994 gnus-newsrc-hashtb)
3995 (set-buffer gnus-group-buffer)
3996 (or (gnus-check-server method)
3997 (error "Unable to contact server: %s" (gnus-status-message method)))
3998 (if activate (or (gnus-request-group group)
3999 (error "Couldn't request group")))
4000 (condition-case ()
4001 (gnus-group-read-group t t group)
4002 (error nil)
4003 (quit nil))
4004 (not (equal major-mode 'gnus-group-mode))))
4005
4006 (defun gnus-group-jump-to-group (group)
4007 "Jump to newsgroup GROUP."
4008 (interactive
4009 (list (completing-read
4010 "Group: " gnus-active-hashtb nil
4011 (memq gnus-select-method gnus-have-read-active-file))))
4012
4013 (if (equal group "")
4014 (error "Empty group name"))
4015
4016 (let ((b (text-property-any
4017 (point-min) (point-max) 'gnus-group (intern group))))
4018 (if b
4019 ;; Either go to the line in the group buffer...
4020 (goto-char b)
4021 ;; ... or insert the line.
4022 (or
4023 (gnus-gethash group gnus-active-hashtb)
4024 (gnus-activate-group group)
4025 (error "%s error: %s" group (gnus-status-message group)))
4026
4027 (gnus-group-update-group group)
4028 (goto-char (text-property-any
4029 (point-min) (point-max) 'gnus-group (intern group)))))
4030 ;; Adjust cursor point.
4031 (gnus-group-position-cursor))
4032
4033 (defun gnus-group-goto-group (group)
4034 "Goto to newsgroup GROUP."
4035 (let ((b (text-property-any (point-min) (point-max)
4036 'gnus-group (intern group))))
4037 (and b (goto-char b))))
4038
4039 (defun gnus-group-next-group (n)
4040 "Go to next N'th newsgroup.
4041 If N is negative, search backward instead.
4042 Returns the difference between N and the number of skips actually
4043 done."
4044 (interactive "p")
4045 (gnus-group-next-unread-group n t))
4046
4047 (defun gnus-group-next-unread-group (n &optional all level)
4048 "Go to next N'th unread newsgroup.
4049 If N is negative, search backward instead.
4050 If ALL is non-nil, choose any newsgroup, unread or not.
4051 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
4052 such group can be found, the next group with a level higher than
4053 LEVEL.
4054 Returns the difference between N and the number of skips actually
4055 made."
4056 (interactive "p")
4057 (let ((backward (< n 0))
4058 (n (abs n)))
4059 (while (and (> n 0)
4060 (gnus-group-search-forward
4061 backward (or (not gnus-group-goto-unread) all) level))
4062 (setq n (1- n)))
4063 (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
4064 (if level " on this level or higher" "")))
4065 n))
4066
4067 (defun gnus-group-prev-group (n)
4068 "Go to previous N'th newsgroup.
4069 Returns the difference between N and the number of skips actually
4070 done."
4071 (interactive "p")
4072 (gnus-group-next-unread-group (- n) t))
4073
4074 (defun gnus-group-prev-unread-group (n)
4075 "Go to previous N'th unread newsgroup.
4076 Returns the difference between N and the number of skips actually
4077 done."
4078 (interactive "p")
4079 (gnus-group-next-unread-group (- n)))
4080
4081 (defun gnus-group-next-unread-group-same-level (n)
4082 "Go to next N'th unread newsgroup on the same level.
4083 If N is negative, search backward instead.
4084 Returns the difference between N and the number of skips actually
4085 done."
4086 (interactive "p")
4087 (gnus-group-next-unread-group n t (gnus-group-group-level))
4088 (gnus-group-position-cursor))
4089
4090 (defun gnus-group-prev-unread-group-same-level (n)
4091 "Go to next N'th unread newsgroup on the same level.
4092 Returns the difference between N and the number of skips actually
4093 done."
4094 (interactive "p")
4095 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
4096 (gnus-group-position-cursor))
4097
4098 (defun gnus-group-best-unread-group (&optional exclude-group)
4099 "Go to the group with the highest level.
4100 If EXCLUDE-GROUP, do not go to that group."
4101 (interactive)
4102 (goto-char (point-min))
4103 (let ((best 100000)
4104 unread best-point)
4105 (while (setq unread (get-text-property (point) 'gnus-unread))
4106 (if (and (numberp unread) (> unread 0))
4107 (progn
4108 (if (and (< (get-text-property (point) 'gnus-level) best)
4109 (or (not exclude-group)
4110 (not (equal exclude-group (gnus-group-group-name)))))
4111 (progn
4112 (setq best (get-text-property (point) 'gnus-level))
4113 (setq best-point (point))))))
4114 (forward-line 1))
4115 (if best-point (goto-char best-point))
4116 (gnus-summary-position-cursor)
4117 (and best-point (gnus-group-group-name))))
4118
4119 (defun gnus-group-first-unread-group ()
4120 "Go to the first group with unread articles."
4121 (interactive)
4122 (prog1
4123 (let ((opoint (point))
4124 unread)
4125 (goto-char (point-min))
4126 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
4127 (not (zerop unread)) ; Has unread articles.
4128 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
4129 (point) ; Success.
4130 (goto-char opoint)
4131 nil)) ; Not success.
4132 (gnus-group-position-cursor)))
4133
4134 (defun gnus-group-enter-server-mode ()
4135 "Jump to the server buffer."
4136 (interactive)
4137 (gnus-server-setup-buffer)
4138 (gnus-configure-windows 'server)
4139 (gnus-server-prepare))
4140
4141 (defun gnus-group-make-group (name &optional method address)
4142 "Add a new newsgroup.
4143 The user will be prompted for a NAME, for a select METHOD, and an
4144 ADDRESS."
4145 (interactive
4146 (cons
4147 (read-string "Group name: ")
4148 (let ((method
4149 (completing-read
4150 "Method: " (append gnus-valid-select-methods gnus-server-alist)
4151 nil t)))
4152 (if (assoc method gnus-valid-select-methods)
4153 (list method
4154 (if (memq 'prompt-address
4155 (assoc method gnus-valid-select-methods))
4156 (read-string "Address: ")
4157 ""))
4158 (list method nil)))))
4159
4160 (let* ((meth (and method (if address (list (intern method) address) method)))
4161 (nname (if method (gnus-group-prefixed-name name meth) name))
4162 info)
4163 (and (gnus-gethash nname gnus-newsrc-hashtb)
4164 (error "Group %s already exists" nname))
4165 (gnus-group-change-level
4166 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
4167 gnus-level-default-subscribed gnus-level-killed
4168 (and (gnus-group-group-name)
4169 (gnus-gethash (gnus-group-group-name)
4170 gnus-newsrc-hashtb))
4171 t)
4172 (gnus-sethash nname (cons 1 0) gnus-active-hashtb)
4173 (or (gnus-ephemeral-group-p name)
4174 (gnus-dribble-enter
4175 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
4176 (gnus-group-insert-group-line-info nname)
4177
4178 (if (assoc method gnus-valid-select-methods)
4179 (require (intern method)))
4180 (and (gnus-check-backend-function 'request-create-group nname)
4181 (gnus-request-create-group nname))))
4182
4183 (defun gnus-group-edit-group (group &optional part)
4184 "Edit the group on the current line."
4185 (interactive (list (gnus-group-group-name)))
4186 (let ((done-func '(lambda ()
4187 "Exit editing mode and update the information."
4188 (interactive)
4189 (gnus-group-edit-group-done 'part 'group)))
4190 (part (or part 'info))
4191 (winconf (current-window-configuration))
4192 info)
4193 (or group (error "No group on current line"))
4194 (or (setq info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4195 (error "Killed group; can't be edited"))
4196 (set-buffer (get-buffer-create gnus-group-edit-buffer))
4197 (gnus-configure-windows 'edit-group)
4198 (gnus-add-current-to-buffer-list)
4199 (emacs-lisp-mode)
4200 ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4201 (use-local-map (copy-keymap emacs-lisp-mode-map))
4202 (local-set-key "\C-c\C-c" done-func)
4203 (make-local-variable 'gnus-prev-winconf)
4204 (setq gnus-prev-winconf winconf)
4205 ;; We modify the func to let it know what part it is editing.
4206 (setcar (cdr (nth 4 done-func)) (list 'quote part))
4207 (setcar (cdr (cdr (nth 4 done-func))) group)
4208 (erase-buffer)
4209 (insert
4210 (cond
4211 ((eq part 'method)
4212 ";; Type `C-c C-c' after editing the select method.\n\n")
4213 ((eq part 'params)
4214 ";; Type `C-c C-c' after editing the group parameters.\n\n")
4215 ((eq part 'info)
4216 ";; Type `C-c C-c' after editing the group info.\n\n")))
4217 (let ((cinfo (gnus-copy-sequence info))
4218 marked)
4219 (if (not (setq marked (nth 3 cinfo)))
4220 ()
4221 (while marked
4222 (or (eq 'score (car (car marked)))
4223 (eq 'bookmark (car (car marked)))
4224 (eq 'killed (car (car marked)))
4225 (not (numberp (car (cdr (car marked)))))
4226 (setcdr (car marked)
4227 (gnus-compress-sequence (sort (cdr (car marked)) '<) t)))
4228 (setq marked (cdr marked))))
4229 (insert
4230 (pp-to-string
4231 (cond ((eq part 'method)
4232 (or (nth 4 info) "native"))
4233 ((eq part 'params)
4234 (nth 5 info))
4235 (t
4236 cinfo)))
4237 "\n"))))
4238
4239 (defun gnus-group-edit-group-method (group)
4240 "Edit the select method of GROUP."
4241 (interactive (list (gnus-group-group-name)))
4242 (gnus-group-edit-group group 'method))
4243
4244 (defun gnus-group-edit-group-parameters (group)
4245 "Edit the group parameters of GROUP."
4246 (interactive (list (gnus-group-group-name)))
4247 (gnus-group-edit-group group 'params))
4248
4249 (defun gnus-group-edit-group-done (part group)
4250 "Get info from buffer, update variables and jump to the group buffer."
4251 (set-buffer (get-buffer-create gnus-group-edit-buffer))
4252 (goto-char (point-min))
4253 (let ((form (read (current-buffer)))
4254 (winconf gnus-prev-winconf))
4255 (if (eq part 'info)
4256 (gnus-group-set-info form)
4257 (gnus-group-set-info form group part))
4258 (kill-buffer (current-buffer))
4259 (and winconf (set-window-configuration winconf))
4260 (set-buffer gnus-group-buffer)
4261 (gnus-group-update-group (gnus-group-group-name))
4262 (gnus-group-position-cursor)))
4263
4264 (defun gnus-group-make-help-group ()
4265 "Create the Gnus documentation group."
4266 (interactive)
4267 (let ((path (if installation-directory
4268 (cons (concat installation-directory "etc/") load-path)
4269 (cons data-directory load-path)))
4270 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
4271 file)
4272 (and (gnus-gethash name gnus-newsrc-hashtb)
4273 (error "Documentation group already exists"))
4274 (while (and path
4275 (not (file-exists-p
4276 (setq file (concat (file-name-as-directory (car path))
4277 "gnus-tut.txt")))))
4278 (setq path (cdr path)))
4279 (if (not path)
4280 (message "Couldn't find doc group")
4281 (gnus-group-make-group
4282 (gnus-group-real-name name)
4283 (list 'nndoc name
4284 (list 'nndoc-address file)
4285 (list 'nndoc-article-type 'mbox)))))
4286 (gnus-group-position-cursor))
4287
4288 (defun gnus-group-make-doc-group (file type)
4289 "Create a group that uses a single file as the source."
4290 (interactive
4291 (list (read-file-name "File name: ")
4292 (let ((err "")
4293 found char)
4294 (while (not found)
4295 (message "%sFile type (mbox, babyl, digest) [mbd]: " err)
4296 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
4297 ((= char ?b) 'babyl)
4298 ((= char ?d) 'digest)
4299 (t (setq err (format "%c unknown. " char))
4300 nil))))
4301 found)))
4302 (let* ((file (expand-file-name file))
4303 (name (gnus-generate-new-group-name
4304 (gnus-group-prefixed-name
4305 (file-name-nondirectory file) '(nndoc "")))))
4306 (gnus-group-make-group
4307 (gnus-group-real-name name)
4308 (list 'nndoc name
4309 (list 'nndoc-address file)
4310 (list 'nndoc-article-type type)))))
4311
4312 (defun gnus-group-make-archive-group (&optional all)
4313 "Create the (ding) Gnus archive group of the most recent articles.
4314 Given a prefix, create a full group."
4315 (interactive "P")
4316 (let ((group (gnus-group-prefixed-name
4317 (if all "ding.archives" "ding.recent") '(nndir ""))))
4318 (and (gnus-gethash group gnus-newsrc-hashtb)
4319 (error "Archive group already exists"))
4320 (gnus-group-make-group
4321 (gnus-group-real-name group)
4322 "nndir"
4323 (if all gnus-group-archive-directory
4324 gnus-group-recent-archive-directory)))
4325 (gnus-group-position-cursor))
4326
4327 (defun gnus-group-make-directory-group (dir)
4328 "Create an nndir group.
4329 The user will be prompted for a directory. The contents of this
4330 directory will be used as a newsgroup. The directory should contain
4331 mail messages or news articles in files that have numeric names."
4332 (interactive
4333 (list (read-file-name "Create group from directory: ")))
4334 (or (file-exists-p dir) (error "No such directory"))
4335 (or (file-directory-p dir) (error "Not a directory"))
4336 (gnus-group-make-group dir "nndir" dir)
4337 (gnus-group-position-cursor))
4338
4339 (defun gnus-group-make-kiboze-group (group address scores)
4340 "Create an nnkiboze group.
4341 The user will be prompted for a name, a regexp to match groups, and
4342 score file entries for articles to include in the group."
4343 (interactive
4344 (list
4345 (read-string "nnkiboze group name: ")
4346 (read-string "Source groups (regexp): ")
4347 (let ((headers (mapcar (lambda (group) (list group))
4348 '("subject" "from" "number" "date" "message-id"
4349 "references" "chars" "lines" "xref")))
4350 scores header regexp regexps)
4351 (while (not (equal "" (setq header (completing-read
4352 "Match on header: " headers nil t))))
4353 (setq regexps nil)
4354 (while (not (equal "" (setq regexp (read-string
4355 (format "Match on %s (string): "
4356 header)))))
4357 (setq regexps (cons (list regexp nil nil 'r) regexps)))
4358 (setq scores (cons (cons header regexps) scores)))
4359 scores)))
4360 (gnus-group-make-group group "nnkiboze" address)
4361 (save-excursion
4362 (gnus-set-work-buffer)
4363 (let (emacs-lisp-mode-hook)
4364 (pp scores (current-buffer)))
4365 (write-region (point-min) (point-max)
4366 (concat (or gnus-kill-files-directory "~/News")
4367 "nnkiboze:" group "." gnus-score-file-suffix)))
4368 (gnus-group-position-cursor))
4369
4370 (defun gnus-group-add-to-virtual (n vgroup)
4371 "Add the current group to a virtual group."
4372 (interactive
4373 (list current-prefix-arg
4374 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
4375 "nnvirtual:")))
4376 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
4377 (error "%s is not an nnvirtual group" vgroup))
4378 (let* ((groups (gnus-group-process-prefix n))
4379 (method (nth 4 (nth 2 (gnus-gethash vgroup gnus-newsrc-hashtb)))))
4380 (setcar (cdr method)
4381 (concat
4382 (nth 1 method) "\\|"
4383 (mapconcat
4384 (lambda (s)
4385 (gnus-group-remove-mark s)
4386 (concat "\\(^" (regexp-quote s) "$\\)"))
4387 groups "\\|"))))
4388 (gnus-group-position-cursor))
4389
4390 (defun gnus-group-make-empty-virtual (group)
4391 "Create a new, fresh, empty virtual group."
4392 (interactive "sCreate new, empty virtual group: ")
4393 (let* ((method (list 'nnvirtual "^$"))
4394 (pgroup (gnus-group-prefixed-name group method)))
4395 ;; Check whether it exists already.
4396 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
4397 (error "Group %s already exists." pgroup))
4398 ;; Subscribe the new group after the group on the current line.
4399 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
4400 (gnus-group-update-group pgroup)
4401 (forward-line -1)
4402 (gnus-group-position-cursor)))
4403
4404 (defun gnus-group-enter-directory (dir)
4405 "Enter an ephemeral nneething group."
4406 (interactive "DDirectory to read: ")
4407 (let* ((method (list 'nneething dir))
4408 (leaf (gnus-group-prefixed-name
4409 (file-name-nondirectory (directory-file-name dir))
4410 method))
4411 (name (gnus-generate-new-group-name leaf)))
4412 (let ((nneething-read-only t))
4413 (or (gnus-group-read-ephemeral-group
4414 name method t
4415 (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
4416 'summary 'group)))
4417 (error "Couldn't enter %s" dir)))))
4418
4419 ;; Group sorting commands
4420 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
4421
4422 (defun gnus-group-sort-groups ()
4423 "Sort the group buffer using `gnus-group-sort-function'."
4424 (interactive)
4425 (setq gnus-newsrc-alist
4426 (sort (cdr gnus-newsrc-alist) gnus-group-sort-function))
4427 (gnus-make-hashtable-from-newsrc-alist)
4428 (gnus-group-list-groups))
4429
4430 (defun gnus-group-sort-by-alphabet (info1 info2)
4431 (string< (car info1) (car info2)))
4432
4433 (defun gnus-group-sort-by-unread (info1 info2)
4434 (let ((n1 (car (gnus-gethash (car info1) gnus-newsrc-hashtb)))
4435 (n2 (car (gnus-gethash (car info2) gnus-newsrc-hashtb))))
4436 (< (or (and (numberp n1) n1) 0)
4437 (or (and (numberp n2) n2) 0))))
4438
4439 (defun gnus-group-sort-by-level (info1 info2)
4440 (< (nth 1 info1) (nth 1 info2)))
4441
4442 ;; Group catching up.
4443
4444 (defun gnus-group-catchup-current (&optional n all)
4445 "Mark all articles not marked as unread in current newsgroup as read.
4446 If prefix argument N is numeric, the ARG next newsgroups will be
4447 caught up. If ALL is non-nil, marked articles will also be marked as
4448 read. Cross references (Xref: header) of articles are ignored.
4449 The difference between N and actual number of newsgroups that were
4450 caught up is returned."
4451 (interactive "P")
4452 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
4453 gnus-expert-user
4454 (gnus-y-or-n-p
4455 (if all
4456 "Do you really want to mark all articles as read? "
4457 "Mark all unread articles as read? "))))
4458 n
4459 (let ((groups (gnus-group-process-prefix n))
4460 (ret 0))
4461 (while groups
4462 ;; Virtual groups have to be given special treatment.
4463 (let ((method (gnus-find-method-for-group (car groups))))
4464 (if (eq 'nnvirtual (car method))
4465 (nnvirtual-catchup-group
4466 (gnus-group-real-name (car groups)) (nth 1 method) all)))
4467 (gnus-group-remove-mark (car groups))
4468 (if (prog1
4469 (gnus-group-goto-group (car groups))
4470 (gnus-group-catchup (car groups) all))
4471 (gnus-group-update-group-line)
4472 (setq ret (1+ ret)))
4473 (setq groups (cdr groups)))
4474 (gnus-group-next-unread-group 1)
4475 ret)))
4476
4477 (defun gnus-group-catchup-current-all (&optional n)
4478 "Mark all articles in current newsgroup as read.
4479 Cross references (Xref: header) of articles are ignored."
4480 (interactive "P")
4481 (gnus-group-catchup-current n 'all))
4482
4483 (defun gnus-group-catchup (group &optional all)
4484 "Mark all articles in GROUP as read.
4485 If ALL is non-nil, all articles are marked as read.
4486 The return value is the number of articles that were marked as read,
4487 or nil if no action could be taken."
4488 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4489 (num (car entry))
4490 (marked (nth 3 (nth 2 entry))))
4491 (if (not (numberp (car entry)))
4492 (gnus-message 1 "Can't catch up; non-active group")
4493 ;; Do the updating only if the newsgroup isn't killed.
4494 (if (not entry)
4495 ()
4496 (gnus-update-read-articles
4497 group (and (not all) (append (cdr (assq 'tick marked))
4498 (cdr (assq 'dormant marked))))
4499 nil (and (not all) (cdr (assq 'tick marked))))
4500 (and all
4501 (setq marked (nth 3 (nth 2 entry)))
4502 (setcar (nthcdr 3 (nth 2 entry))
4503 (delq (assq 'dormant marked)
4504 (nth 3 (nth 2 entry)))))))
4505 num))
4506
4507 (defun gnus-group-expire-articles (&optional n)
4508 "Expire all expirable articles in the current newsgroup."
4509 (interactive "P")
4510 (let ((groups (gnus-group-process-prefix n))
4511 group)
4512 (or groups (error "No groups to expire"))
4513 (while groups
4514 (setq group (car groups)
4515 groups (cdr groups))
4516 (gnus-group-remove-mark group)
4517 (if (not (gnus-check-backend-function 'request-expire-articles group))
4518 ()
4519 (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4520 (expirable (if (memq 'total-expire (nth 5 info))
4521 (cons nil (gnus-list-of-read-articles group))
4522 (assq 'expire (nth 3 info)))))
4523 (and expirable
4524 (setcdr expirable
4525 (gnus-request-expire-articles
4526 (cdr expirable) group))))))))
4527
4528 (defun gnus-group-expire-all-groups ()
4529 "Expire all expirable articles in all newsgroups."
4530 (interactive)
4531 (save-excursion
4532 (gnus-message 5 "Expiring...")
4533 (let ((gnus-group-marked (mapcar (lambda (info) (car info))
4534 (cdr gnus-newsrc-alist))))
4535 (gnus-group-expire-articles nil)))
4536 (gnus-group-position-cursor)
4537 (gnus-message 5 "Expiring...done"))
4538
4539 (defun gnus-group-set-current-level (n level)
4540 "Set the level of the next N groups to LEVEL."
4541 (interactive "P\nnLevel: ")
4542 (or (and (>= level 1) (<= level gnus-level-killed))
4543 (error "Illegal level: %d" level))
4544 (let ((groups (gnus-group-process-prefix n))
4545 group)
4546 (while groups
4547 (setq group (car groups)
4548 groups (cdr groups))
4549 (gnus-group-remove-mark group)
4550 (gnus-message 6 "Changed level of %s from %d to %d"
4551 group (gnus-group-group-level) level)
4552 (gnus-group-change-level group level
4553 (gnus-group-group-level))
4554 (gnus-group-update-group-line)))
4555 (gnus-group-position-cursor))
4556
4557 (defun gnus-group-unsubscribe-current-group (&optional n)
4558 "Toggle subscription of the current group.
4559 If given numerical prefix, toggle the N next groups."
4560 (interactive "P")
4561 (let ((groups (gnus-group-process-prefix n))
4562 group)
4563 (while groups
4564 (setq group (car groups)
4565 groups (cdr groups))
4566 (gnus-group-remove-mark group)
4567 (gnus-group-unsubscribe-group
4568 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
4569 gnus-level-default-unsubscribed
4570 gnus-level-default-subscribed))
4571 (gnus-group-update-group-line))
4572 (gnus-group-next-group 1)))
4573
4574 (defun gnus-group-unsubscribe-group (group &optional level)
4575 "Toggle subscribe from/to unsubscribe GROUP.
4576 New newsgroup is added to .newsrc automatically."
4577 (interactive
4578 (list (completing-read
4579 "Group: " gnus-active-hashtb nil
4580 (memq gnus-select-method gnus-have-read-active-file))))
4581 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
4582 (cond
4583 ((string-match "^[ \t]$" group)
4584 (error "Empty group name"))
4585 (newsrc
4586 ;; Toggle subscription flag.
4587 (gnus-group-change-level
4588 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
4589 gnus-level-subscribed)
4590 (1+ gnus-level-subscribed)
4591 gnus-level-default-subscribed)))
4592 (gnus-group-update-group group))
4593 ((and (stringp group)
4594 (or (not (memq gnus-select-method gnus-have-read-active-file))
4595 (gnus-gethash group gnus-active-hashtb)))
4596 ;; Add new newsgroup.
4597 (gnus-group-change-level
4598 group
4599 (if level level gnus-level-default-subscribed)
4600 (or (and (member group gnus-zombie-list)
4601 gnus-level-zombie)
4602 gnus-level-killed)
4603 (and (gnus-group-group-name)
4604 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
4605 (gnus-group-update-group group))
4606 (t (error "No such newsgroup: %s" group)))
4607 (gnus-group-position-cursor)))
4608
4609 (defun gnus-group-transpose-groups (n)
4610 "Move the current newsgroup up N places.
4611 If given a negative prefix, move down instead. The difference between
4612 N and the number of steps taken is returned."
4613 (interactive "p")
4614 (or (gnus-group-group-name)
4615 (error "No group on current line"))
4616 (gnus-group-kill-group 1)
4617 (prog1
4618 (forward-line (- n))
4619 (gnus-group-yank-group)
4620 (gnus-group-position-cursor)))
4621
4622 (defun gnus-group-kill-all-zombies ()
4623 "Kill all zombie newsgroups."
4624 (interactive)
4625 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
4626 (setq gnus-zombie-list nil)
4627 (gnus-group-list-groups))
4628
4629 (defun gnus-group-kill-region (begin end)
4630 "Kill newsgroups in current region (excluding current point).
4631 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
4632 (interactive "r")
4633 (let ((lines
4634 ;; Count lines.
4635 (save-excursion
4636 (count-lines
4637 (progn
4638 (goto-char begin)
4639 (beginning-of-line)
4640 (point))
4641 (progn
4642 (goto-char end)
4643 (beginning-of-line)
4644 (point))))))
4645 (goto-char begin)
4646 (beginning-of-line) ;Important when LINES < 1
4647 (gnus-group-kill-group lines)))
4648
4649 (defun gnus-group-kill-group (&optional n)
4650 "The the next N groups.
4651 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
4652 However, only groups that were alive can be yanked; already killed
4653 groups or zombie groups can't be yanked.
4654 The return value is the name of the (last) group that was killed."
4655 (interactive "P")
4656 (let ((buffer-read-only nil)
4657 (groups (gnus-group-process-prefix n))
4658 group entry level)
4659 (while groups
4660 (setq group (car groups)
4661 groups (cdr groups))
4662 (gnus-group-remove-mark group)
4663 (setq level (gnus-group-group-level))
4664 (gnus-delete-line)
4665 (if (setq entry (gnus-gethash group gnus-newsrc-hashtb))
4666 (setq gnus-list-of-killed-groups
4667 (cons (cons (car entry) (nth 2 entry))
4668 gnus-list-of-killed-groups)))
4669 (gnus-group-change-level
4670 (if entry entry group) gnus-level-killed (if entry nil level)))
4671 (gnus-group-position-cursor)
4672 group))
4673
4674 (defun gnus-group-yank-group (&optional arg)
4675 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
4676 inserting it before the current newsgroup. The numeric ARG specifies
4677 how many newsgroups are to be yanked. The name of the (last)
4678 newsgroup yanked is returned."
4679 (interactive "p")
4680 (if (not arg) (setq arg 1))
4681 (let (info group prev)
4682 (while (>= (setq arg (1- arg)) 0)
4683 (if (not (setq info (car gnus-list-of-killed-groups)))
4684 (error "No more newsgroups to yank"))
4685 (setq group (nth 2 info))
4686 ;; Find which newsgroup to insert this one before - search
4687 ;; backward until something suitable is found. If there are no
4688 ;; other newsgroups in this buffer, just make this newsgroup the
4689 ;; first newsgroup.
4690 (setq prev (gnus-group-group-name))
4691 (gnus-group-change-level
4692 info (nth 2 info) gnus-level-killed
4693 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
4694 t)
4695 (gnus-group-insert-group-line-info (nth 1 info))
4696 (setq gnus-list-of-killed-groups
4697 (cdr gnus-list-of-killed-groups)))
4698 (forward-line -1)
4699 (gnus-group-position-cursor)
4700 group))
4701
4702 (defun gnus-group-list-all-groups (&optional arg)
4703 "List all newsgroups with level ARG or lower.
4704 Default is gnus-level-unsubscribed, which lists all subscribed and most
4705 unsubscribed groups."
4706 (interactive "P")
4707 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
4708
4709 (defun gnus-group-list-killed ()
4710 "List all killed newsgroups in the group buffer."
4711 (interactive)
4712 (if (not gnus-killed-list)
4713 (gnus-message 6 "No killed groups")
4714 (let (gnus-group-list-mode)
4715 (funcall gnus-group-prepare-function
4716 gnus-level-killed t gnus-level-killed))
4717 (goto-char (point-min)))
4718 (gnus-group-position-cursor))
4719
4720 (defun gnus-group-list-zombies ()
4721 "List all zombie newsgroups in the group buffer."
4722 (interactive)
4723 (if (not gnus-zombie-list)
4724 (gnus-message 6 "No zombie groups")
4725 (let (gnus-group-list-mode)
4726 (funcall gnus-group-prepare-function
4727 gnus-level-zombie t gnus-level-zombie))
4728 (goto-char (point-min)))
4729 (gnus-group-position-cursor))
4730
4731 (defun gnus-group-get-new-news (&optional arg)
4732 "Get newly arrived articles.
4733 If ARG is non-nil, it should be a number between one and nine to
4734 specify which levels you are interested in re-scanning."
4735 (interactive "P")
4736 (run-hooks 'gnus-get-new-news-hook)
4737 (setq arg (gnus-group-default-level arg t))
4738 (if (and gnus-read-active-file (not arg))
4739 (progn
4740 (gnus-read-active-file)
4741 (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))
4742 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
4743 (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))))
4744 (gnus-group-list-groups))
4745
4746 (defun gnus-group-get-new-news-this-group (&optional n)
4747 "Check for newly arrived news in the current group (and the N-1 next groups).
4748 The difference between N and the number of newsgroup checked is returned.
4749 If N is negative, this group and the N-1 previous groups will be checked."
4750 (interactive "P")
4751 (let* ((groups (gnus-group-process-prefix n))
4752 (ret (if (numberp n) (- n (length groups)) 0))
4753 group)
4754 (while groups
4755 (setq group (car groups)
4756 groups (cdr groups))
4757 (gnus-group-remove-mark group)
4758 (or (gnus-get-new-news-in-group group)
4759 (progn
4760 (ding)
4761 (message "%s error: %s" group (gnus-status-message group))
4762 (sit-for 2))))
4763 (gnus-group-next-unread-group 1 t)
4764 (gnus-summary-position-cursor)
4765 ret))
4766
4767 (defun gnus-get-new-news-in-group (group)
4768 (and group
4769 (gnus-activate-group group)
4770 (progn
4771 (gnus-get-unread-articles-in-group
4772 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))
4773 (gnus-gethash group gnus-active-hashtb))
4774 (gnus-group-update-group-line)
4775 t)))
4776
4777 (defun gnus-group-fetch-faq (group)
4778 "Fetch the FAQ for the current group."
4779 (interactive (list (gnus-group-real-name (gnus-group-group-name))))
4780 (or group (error "No group name given"))
4781 (let ((file (concat gnus-group-faq-directory (gnus-group-real-name group))))
4782 (if (not (file-exists-p file))
4783 (error "No such file: %s" file)
4784 (find-file file))))
4785
4786 (defun gnus-group-describe-group (force &optional group)
4787 "Display a description of the current newsgroup."
4788 (interactive (list current-prefix-arg (gnus-group-group-name)))
4789 (and force (setq gnus-description-hashtb nil))
4790 (let ((method (gnus-find-method-for-group group))
4791 desc)
4792 (or group (error "No group name given"))
4793 (and (or (and gnus-description-hashtb
4794 ;; We check whether this group's method has been
4795 ;; queried for a description file.
4796 (gnus-gethash
4797 (gnus-group-prefixed-name "" method)
4798 gnus-description-hashtb))
4799 (setq desc (gnus-group-get-description group))
4800 (gnus-read-descriptions-file method))
4801 (message
4802 (or desc (gnus-gethash group gnus-description-hashtb)
4803 "No description available")))))
4804
4805 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4806 (defun gnus-group-describe-all-groups (&optional force)
4807 "Pop up a buffer with descriptions of all newsgroups."
4808 (interactive "P")
4809 (and force (setq gnus-description-hashtb nil))
4810 (if (not (or gnus-description-hashtb
4811 (gnus-read-all-descriptions-files)))
4812 (error "Couldn't request descriptions file"))
4813 (let ((buffer-read-only nil)
4814 b)
4815 (erase-buffer)
4816 (mapatoms
4817 (lambda (group)
4818 (setq b (point))
4819 (insert (format " *: %-20s %s\n" (symbol-name group)
4820 (symbol-value group)))
4821 (add-text-properties
4822 b (1+ b) (list 'gnus-group group
4823 'gnus-unread t 'gnus-marked nil
4824 'gnus-level (1+ gnus-level-subscribed))))
4825 gnus-description-hashtb)
4826 (goto-char (point-min))
4827 (gnus-group-position-cursor)))
4828
4829 ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
4830 (defun gnus-group-apropos (regexp &optional search-description)
4831 "List all newsgroups that have names that match a regexp."
4832 (interactive "sGnus apropos (regexp): ")
4833 (let ((prev "")
4834 (obuf (current-buffer))
4835 groups des)
4836 ;; Go through all newsgroups that are known to Gnus.
4837 (mapatoms
4838 (lambda (group)
4839 (and (symbol-name group)
4840 (string-match regexp (symbol-name group))
4841 (setq groups (cons (symbol-name group) groups))))
4842 gnus-active-hashtb)
4843 ;; Go through all descriptions that are known to Gnus.
4844 (if search-description
4845 (mapatoms
4846 (lambda (group)
4847 (and (string-match regexp (symbol-value group))
4848 (gnus-gethash (symbol-name group) gnus-active-hashtb)
4849 (setq groups (cons (symbol-name group) groups))))
4850 gnus-description-hashtb))
4851 (if (not groups)
4852 (gnus-message 3 "No groups matched \"%s\"." regexp)
4853 ;; Print out all the groups.
4854 (save-excursion
4855 (pop-to-buffer "*Gnus Help*")
4856 (buffer-disable-undo (current-buffer))
4857 (erase-buffer)
4858 (setq groups (sort groups 'string<))
4859 (while groups
4860 ;; Groups may be entered twice into the list of groups.
4861 (if (not (string= (car groups) prev))
4862 (progn
4863 (insert (setq prev (car groups)) "\n")
4864 (if (and gnus-description-hashtb
4865 (setq des (gnus-gethash (car groups)
4866 gnus-description-hashtb)))
4867 (insert " " des "\n"))))
4868 (setq groups (cdr groups)))
4869 (goto-char (point-min))))
4870 (pop-to-buffer obuf)))
4871
4872 (defun gnus-group-description-apropos (regexp)
4873 "List all newsgroups that have names or descriptions that match a regexp."
4874 (interactive "sGnus description apropos (regexp): ")
4875 (if (not (or gnus-description-hashtb
4876 (gnus-read-all-descriptions-files)))
4877 (error "Couldn't request descriptions file"))
4878 (gnus-group-apropos regexp t))
4879
4880 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4881 (defun gnus-group-list-matching (level regexp &optional all lowest)
4882 "List all groups with unread articles that match REGEXP.
4883 If the prefix LEVEL is non-nil, it should be a number that says which
4884 level to cut off listing groups.
4885 If ALL, also list groups with no unread articles.
4886 If LOWEST, don't list groups with level lower than LOWEST."
4887 (interactive "P\nsList newsgroups matching: ")
4888 (gnus-group-prepare-flat (or level gnus-level-subscribed)
4889 all (or lowest 1) regexp)
4890 (goto-char (point-min))
4891 (gnus-group-position-cursor))
4892
4893 (defun gnus-group-list-all-matching (level regexp &optional lowest)
4894 "List all groups that match REGEXP.
4895 If the prefix LEVEL is non-nil, it should be a number that says which
4896 level to cut off listing groups.
4897 If LOWEST, don't list groups with level lower than LOWEST."
4898 (interactive "P\nsList newsgroups matching: ")
4899 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
4900
4901 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
4902 (defun gnus-group-save-newsrc ()
4903 "Save the Gnus startup files."
4904 (interactive)
4905 (gnus-save-newsrc-file))
4906
4907 (defun gnus-group-restart (&optional arg)
4908 "Force Gnus to read the .newsrc file."
4909 (interactive "P")
4910 (gnus-save-newsrc-file)
4911 (gnus-setup-news 'force)
4912 (gnus-group-list-groups arg))
4913
4914 (defun gnus-group-read-init-file ()
4915 "Read the Gnus elisp init file."
4916 (interactive)
4917 (gnus-read-init-file))
4918
4919 (defun gnus-group-check-bogus-groups (&optional silent)
4920 "Check bogus newsgroups.
4921 If given a prefix, don't ask for confirmation before removing a bogus
4922 group."
4923 (interactive "P")
4924 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
4925 (gnus-group-list-groups))
4926
4927 (defun gnus-group-edit-global-kill (&optional article group)
4928 "Edit the global kill file.
4929 If GROUP, edit that local kill file instead."
4930 (interactive "P")
4931 (setq gnus-current-kill-article article)
4932 (gnus-kill-file-edit-file group)
4933 (gnus-message
4934 6
4935 (substitute-command-keys
4936 "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)")))
4937
4938 (defun gnus-group-edit-local-kill (article group)
4939 "Edit a local kill file."
4940 (interactive (list nil (gnus-group-group-name)))
4941 (gnus-group-edit-global-kill article group))
4942
4943 (defun gnus-group-force-update ()
4944 "Update `.newsrc' file."
4945 (interactive)
4946 (gnus-save-newsrc-file))
4947
4948 (defun gnus-group-suspend ()
4949 "Suspend the current Gnus session.
4950 In fact, cleanup buffers except for group mode buffer.
4951 The hook gnus-suspend-gnus-hook is called before actually suspending."
4952 (interactive)
4953 (run-hooks 'gnus-suspend-gnus-hook)
4954 ;; Kill Gnus buffers except for group mode buffer.
4955 (let ((group-buf (get-buffer gnus-group-buffer)))
4956 ;; Do this on a separate list in case the user does a ^G before we finish
4957 (let ((gnus-buffer-list
4958 (delq group-buf (delq gnus-dribble-buffer
4959 (append gnus-buffer-list nil)))))
4960 (while gnus-buffer-list
4961 (gnus-kill-buffer (car gnus-buffer-list))
4962 (setq gnus-buffer-list (cdr gnus-buffer-list))))
4963 (if group-buf
4964 (progn
4965 (setq gnus-buffer-list (list group-buf))
4966 (bury-buffer group-buf)
4967 (delete-windows-on group-buf t)))))
4968
4969 (defun gnus-group-clear-dribble ()
4970 "Clear all information from the dribble buffer."
4971 (interactive)
4972 (gnus-dribble-clear))
4973
4974 (defun gnus-group-exit ()
4975 "Quit reading news after updating .newsrc.eld and .newsrc.
4976 The hook `gnus-exit-gnus-hook' is called before actually exiting."
4977 (interactive)
4978 (if (or noninteractive ;For gnus-batch-kill
4979 (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed
4980 (not gnus-interactive-exit) ;Without confirmation
4981 gnus-expert-user
4982 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
4983 (progn
4984 (run-hooks 'gnus-exit-gnus-hook)
4985 ;; Offer to save data from non-quitted summary buffers.
4986 (gnus-offer-save-summaries)
4987 ;; Save the newsrc file(s).
4988 (gnus-save-newsrc-file)
4989 ;; Kill-em-all.
4990 (gnus-close-backends)
4991 ;; Reset everything.
4992 (gnus-clear-system))))
4993
4994 (defun gnus-close-backends ()
4995 ;; Send a close request to all backends that support such a request.
4996 (let ((methods gnus-valid-select-methods)
4997 func)
4998 (while methods
4999 (if (fboundp (setq func (intern (concat (car (car methods))
5000 "-request-close"))))
5001 (funcall func))
5002 (setq methods (cdr methods)))))
5003
5004 (defun gnus-group-quit ()
5005 "Quit reading news without updating .newsrc.eld or .newsrc.
5006 The hook `gnus-exit-gnus-hook' is called before actually exiting."
5007 (interactive)
5008 (if (or noninteractive ;For gnus-batch-kill
5009 (zerop (buffer-size))
5010 (not (gnus-server-opened gnus-select-method))
5011 gnus-expert-user
5012 (not gnus-current-startup-file)
5013 (gnus-yes-or-no-p
5014 (format "Quit reading news without saving %s? "
5015 (file-name-nondirectory gnus-current-startup-file))))
5016 (progn
5017 (run-hooks 'gnus-exit-gnus-hook)
5018 (if gnus-use-full-window
5019 (delete-other-windows)
5020 (gnus-remove-some-windows))
5021 (gnus-dribble-save)
5022 (gnus-close-backends)
5023 (gnus-clear-system))))
5024
5025 (defun gnus-offer-save-summaries ()
5026 (save-excursion
5027 (let ((buflist (buffer-list))
5028 buffers bufname)
5029 (while buflist
5030 (and (setq bufname (buffer-name (car buflist)))
5031 (string-match "Summary" bufname)
5032 (save-excursion
5033 (set-buffer bufname)
5034 ;; We check that this is, indeed, a summary buffer.
5035 (eq major-mode 'gnus-summary-mode))
5036 (setq buffers (cons bufname buffers)))
5037 (setq buflist (cdr buflist)))
5038 (and buffers
5039 (map-y-or-n-p
5040 "Update summary buffer %s? "
5041 (lambda (buf)
5042 (set-buffer buf)
5043 (gnus-summary-exit))
5044 buffers)))))
5045
5046 (defun gnus-group-describe-briefly ()
5047 "Give a one line description of the group mode commands."
5048 (interactive)
5049 (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")))
5050
5051 (defun gnus-group-browse-foreign-server (method)
5052 "Browse a foreign news server.
5053 If called interactively, this function will ask for a select method
5054 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
5055 If not, METHOD should be a list where the first element is the method
5056 and the second element is the address."
5057 (interactive
5058 (list (let ((how (completing-read
5059 "Which backend: "
5060 (append gnus-valid-select-methods gnus-server-alist)
5061 nil t "nntp")))
5062 ;; We either got a backend name or a virtual server name.
5063 ;; If the first, we also need an address.
5064 (if (assoc how gnus-valid-select-methods)
5065 (list (intern how)
5066 ;; Suggested by mapjph@bath.ac.uk.
5067 (completing-read
5068 "Address: "
5069 (mapcar (lambda (server) (list server))
5070 gnus-secondary-servers)))
5071 ;; We got a server name, so we find the method.
5072 (gnus-server-to-method how)))))
5073 (gnus-browse-foreign-server method))
5074
5075 \f
5076 ;;;
5077 ;;; Browse Server Mode
5078 ;;;
5079
5080 (defvar gnus-browse-mode-hook nil)
5081 (defvar gnus-browse-mode-map nil)
5082 (put 'gnus-browse-mode 'mode-class 'special)
5083
5084 (if gnus-browse-mode-map
5085 nil
5086 (setq gnus-browse-mode-map (make-keymap))
5087 (suppress-keymap gnus-browse-mode-map)
5088 (define-key gnus-browse-mode-map " " 'gnus-browse-read-group)
5089 (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group)
5090 (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group)
5091 (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group)
5092 (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group)
5093 (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group)
5094 (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group)
5095 (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group)
5096 (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group)
5097 (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group)
5098 (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group)
5099 (define-key gnus-browse-mode-map "l" 'gnus-browse-exit)
5100 (define-key gnus-browse-mode-map "L" 'gnus-browse-exit)
5101 (define-key gnus-browse-mode-map "q" 'gnus-browse-exit)
5102 (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit)
5103 (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit)
5104 (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly)
5105 (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node)
5106 )
5107
5108 (defvar gnus-browse-current-method nil)
5109 (defvar gnus-browse-return-buffer nil)
5110
5111 (defvar gnus-browse-buffer "*Gnus Browse Server*")
5112
5113 (defun gnus-browse-foreign-server (method &optional return-buffer)
5114 (setq gnus-browse-current-method method)
5115 (setq gnus-browse-return-buffer return-buffer)
5116 (let ((gnus-select-method method)
5117 groups group)
5118 (gnus-message 5 "Connecting to %s..." (nth 1 method))
5119 (or (gnus-check-server method)
5120 (error "Unable to contact server: %s" (gnus-status-message method)))
5121 (or (gnus-request-list method)
5122 (error "Couldn't request list: %s" (gnus-status-message method)))
5123 (get-buffer-create gnus-browse-buffer)
5124 (gnus-add-current-to-buffer-list)
5125 (and gnus-carpal (gnus-carpal-setup-buffer 'browse))
5126 (gnus-configure-windows 'browse)
5127 (buffer-disable-undo (current-buffer))
5128 (let ((buffer-read-only nil))
5129 (erase-buffer))
5130 (gnus-browse-mode)
5131 (setq mode-line-buffer-identification
5132 (format
5133 "Gnus Browse Server {%s:%s}" (car method) (car (cdr method))))
5134 (save-excursion
5135 (set-buffer nntp-server-buffer)
5136 (let ((cur (current-buffer)))
5137 (goto-char (point-min))
5138 (or (string= gnus-ignored-newsgroups "")
5139 (delete-matching-lines gnus-ignored-newsgroups))
5140 (while (re-search-forward
5141 "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
5142 (goto-char (match-end 1))
5143 (setq groups (cons (cons (buffer-substring (match-beginning 1)
5144 (match-end 1))
5145 (max 0 (- (1+ (read cur)) (read cur))))
5146 groups)))))
5147 (setq groups (sort groups
5148 (lambda (l1 l2)
5149 (string< (car l1) (car l2)))))
5150 (let ((buffer-read-only nil))
5151 (while groups
5152 (setq group (car groups))
5153 (insert
5154 (format "K%7d: %s\n" (cdr group) (car group)))
5155 (setq groups (cdr groups))))
5156 (switch-to-buffer (current-buffer))
5157 (goto-char (point-min))
5158 (gnus-group-position-cursor)))
5159
5160 (defun gnus-browse-mode ()
5161 "Major mode for browsing a foreign server.
5162
5163 All normal editing commands are switched off.
5164
5165 \\<gnus-browse-mode-map>
5166 The only things you can do in this buffer is
5167
5168 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
5169 The group will be inserted into the group buffer upon exit from this
5170 buffer.
5171
5172 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
5173
5174 3) `\\[gnus-browse-exit]' to return to the group buffer."
5175 (interactive)
5176 (kill-all-local-variables)
5177 (if gnus-visual (gnus-browse-make-menu-bar))
5178 (gnus-simplify-mode-line)
5179 (setq major-mode 'gnus-browse-mode)
5180 (setq mode-name "Browse Server")
5181 (setq mode-line-process nil)
5182 (use-local-map gnus-browse-mode-map)
5183 (buffer-disable-undo (current-buffer))
5184 (setq truncate-lines t)
5185 (setq buffer-read-only t)
5186 (run-hooks 'gnus-browse-mode-hook))
5187
5188 (defun gnus-browse-read-group (&optional no-article)
5189 "Enter the group at the current line."
5190 (interactive)
5191 (let ((group (gnus-browse-group-name)))
5192 (or (gnus-group-read-ephemeral-group
5193 group gnus-browse-current-method nil
5194 (cons (current-buffer) 'browse))
5195 (error "Couldn't enter %s" group))))
5196
5197 (defun gnus-browse-select-group ()
5198 "Select the current group."
5199 (interactive)
5200 (gnus-browse-read-group 'no))
5201
5202 (defun gnus-browse-next-group (n)
5203 "Go to the next group."
5204 (interactive "p")
5205 (prog1
5206 (forward-line n)
5207 (gnus-group-position-cursor)))
5208
5209 (defun gnus-browse-prev-group (n)
5210 "Go to the next group."
5211 (interactive "p")
5212 (gnus-browse-next-group (- n)))
5213
5214 (defun gnus-browse-unsubscribe-current-group (arg)
5215 "(Un)subscribe to the next ARG groups."
5216 (interactive "p")
5217 (and (eobp)
5218 (error "No group at current line."))
5219 (let ((ward (if (< arg 0) -1 1))
5220 (arg (abs arg)))
5221 (while (and (> arg 0)
5222 (not (eobp))
5223 (gnus-browse-unsubscribe-group)
5224 (zerop (gnus-browse-next-group ward)))
5225 (setq arg (1- arg)))
5226 (gnus-group-position-cursor)
5227 (if (/= 0 arg) (gnus-message 7 "No more newsgroups"))
5228 arg))
5229
5230 (defun gnus-browse-group-name ()
5231 (save-excursion
5232 (beginning-of-line)
5233 (if (not (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t))
5234 ()
5235 (gnus-group-prefixed-name
5236 (buffer-substring (match-beginning 1) (match-end 1))
5237 gnus-browse-current-method))))
5238
5239 (defun gnus-browse-unsubscribe-group ()
5240 "Toggle subscription of the current group in the browse buffer."
5241 (let ((sub nil)
5242 (buffer-read-only nil)
5243 group)
5244 (save-excursion
5245 (beginning-of-line)
5246 ;; If this group it killed, then we want to subscribe it.
5247 (if (= (following-char) ?K) (setq sub t))
5248 (setq group (gnus-browse-group-name))
5249 (delete-char 1)
5250 (if sub
5251 (progn
5252 (gnus-group-change-level
5253 (list t group gnus-level-default-subscribed
5254 nil nil gnus-browse-current-method)
5255 gnus-level-default-subscribed gnus-level-killed
5256 (and (car (nth 1 gnus-newsrc-alist))
5257 (gnus-gethash (car (nth 1 gnus-newsrc-alist))
5258 gnus-newsrc-hashtb))
5259 t)
5260 (insert ? ))
5261 (gnus-group-change-level
5262 group gnus-level-killed gnus-level-default-subscribed)
5263 (insert ?K)))
5264 t))
5265
5266 (defun gnus-browse-exit ()
5267 "Quit browsing and return to the group buffer."
5268 (interactive)
5269 (if (eq major-mode 'gnus-browse-mode)
5270 (kill-buffer (current-buffer)))
5271 (if gnus-browse-return-buffer
5272 (gnus-configure-windows 'server 'force)
5273 (gnus-configure-windows 'group 'force)
5274 (gnus-group-list-groups nil)))
5275
5276 (defun gnus-browse-describe-briefly ()
5277 "Give a one line description of the group mode commands."
5278 (interactive)
5279 (gnus-message 6
5280 (substitute-command-keys "\\<gnus-browse-mode-map>\\[gnus-group-next-group]:Forward \\[gnus-group-prev-group]:Backward \\[gnus-browse-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-browse-describe-briefly]:This help")))
5281
5282 \f
5283 ;;;
5284 ;;; Gnus summary mode
5285 ;;;
5286
5287 (defvar gnus-summary-mode-map nil)
5288 (defvar gnus-summary-mark-map nil)
5289 (defvar gnus-summary-mscore-map nil)
5290 (defvar gnus-summary-article-map nil)
5291 (defvar gnus-summary-thread-map nil)
5292 (defvar gnus-summary-goto-map nil)
5293 (defvar gnus-summary-exit-map nil)
5294 (defvar gnus-summary-interest-map nil)
5295 (defvar gnus-summary-sort-map nil)
5296 (defvar gnus-summary-backend-map nil)
5297 (defvar gnus-summary-save-map nil)
5298 (defvar gnus-summary-wash-map nil)
5299 (defvar gnus-summary-wash-hide-map nil)
5300 (defvar gnus-summary-wash-highlight-map nil)
5301 (defvar gnus-summary-wash-time-map nil)
5302 (defvar gnus-summary-help-map nil)
5303
5304 (put 'gnus-summary-mode 'mode-class 'special)
5305
5306 (if gnus-summary-mode-map
5307 nil
5308 (setq gnus-summary-mode-map (make-keymap))
5309 (suppress-keymap gnus-summary-mode-map)
5310
5311 ;; Non-orthogonal keys
5312
5313 (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
5314 (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
5315 (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
5316 (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
5317 (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
5318 (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
5319 (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
5320 (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject)
5321 (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject)
5322 (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject)
5323 (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject)
5324 (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
5325 (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article)
5326 (define-key gnus-summary-mode-map
5327 "\M-s" 'gnus-summary-search-article-forward)
5328 (define-key gnus-summary-mode-map
5329 "\M-r" 'gnus-summary-search-article-backward)
5330 (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
5331 (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
5332 (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject)
5333 (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
5334 (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article)
5335 (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward)
5336 (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward)
5337 (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward)
5338 (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
5339 (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
5340 (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable)
5341 (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward)
5342 (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward)
5343 (define-key gnus-summary-mode-map
5344 "k" 'gnus-summary-kill-same-subject-and-select)
5345 (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
5346 (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread)
5347 (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread)
5348 (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article)
5349 (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable)
5350 (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable)
5351 (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads)
5352 (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread)
5353 (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread)
5354 (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread)
5355 (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread)
5356 (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread)
5357 (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread)
5358 (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
5359 (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
5360 (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read)
5361 (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
5362 (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant)
5363 (define-key gnus-summary-mode-map
5364 "\C-c\M-\C-s" 'gnus-summary-show-all-expunged)
5365 (define-key gnus-summary-mode-map
5366 "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
5367 (define-key gnus-summary-mode-map
5368 "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
5369 (define-key gnus-summary-mode-map
5370 "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
5371 (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
5372 (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score)
5373 (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
5374 (define-key gnus-summary-mode-map
5375 "\C-x\C-s" 'gnus-summary-reselect-current-group)
5376 (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group)
5377 (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
5378 (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
5379 (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime)
5380 (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
5381 (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
5382 (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
5383 (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
5384 (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
5385 (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
5386 (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
5387 (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail)
5388 (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
5389 (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill)
5390 (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill)
5391 (define-key gnus-summary-mode-map "V" 'gnus-version)
5392 (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group)
5393 (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
5394 (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update)
5395 (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)
5396 (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article)
5397 (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
5398 (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
5399 (define-key gnus-summary-mode-map
5400 "x" 'gnus-summary-remove-lines-marked-as-read)
5401 ; (define-key gnus-summary-mode-map "X" 'gnus-summary-remove-lines-marked-with)
5402 (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
5403 (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
5404 (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
5405 ; (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
5406 (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
5407 (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view)
5408 (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group)
5409 (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers)
5410 (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug)
5411
5412
5413 ;; Sort of orthogonal keymap
5414 (define-prefix-command 'gnus-summary-mark-map)
5415 (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map)
5416 (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward)
5417 (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward)
5418 (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward)
5419 (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward)
5420 (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward)
5421 (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward)
5422 (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable)
5423 (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable)
5424 (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant)
5425 (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark)
5426 (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark)
5427 (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable)
5428 (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable)
5429 (define-key gnus-summary-mark-map
5430 "\M-r" 'gnus-summary-remove-lines-marked-as-read)
5431 (define-key gnus-summary-mark-map
5432 "\M-\C-r" 'gnus-summary-remove-lines-marked-with)
5433 (define-key gnus-summary-mark-map "D" 'gnus-summary-show-all-dormant)
5434 (define-key gnus-summary-mark-map "\M-D" 'gnus-summary-hide-all-dormant)
5435 (define-key gnus-summary-mark-map "S" 'gnus-summary-show-all-expunged)
5436 (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup)
5437 (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here)
5438 (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all)
5439 (define-key gnus-summary-mark-map
5440 "k" 'gnus-summary-kill-same-subject-and-select)
5441 (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject)
5442
5443 (define-prefix-command 'gnus-summary-mscore-map)
5444 (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map)
5445 (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above)
5446 (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above)
5447 (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above)
5448 (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below)
5449
5450 (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map)
5451
5452 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
5453
5454 (define-prefix-command 'gnus-summary-goto-map)
5455 (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map)
5456 (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article)
5457 (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article)
5458 (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article)
5459 (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article)
5460 (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject)
5461 (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject)
5462 (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject)
5463 (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject)
5464 (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article)
5465 (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article)
5466 (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject)
5467 (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article)
5468 (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article)
5469
5470
5471 (define-prefix-command 'gnus-summary-thread-map)
5472 (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map)
5473 (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread)
5474 (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread)
5475 (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread)
5476 (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads)
5477 (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread)
5478 (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads)
5479 (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread)
5480 (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads)
5481 (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread)
5482 (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread)
5483 (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread)
5484 (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread)
5485 (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread)
5486
5487
5488 (define-prefix-command 'gnus-summary-exit-map)
5489 (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map)
5490 (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit)
5491 (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit)
5492 (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update)
5493 (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit)
5494 (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit)
5495 (define-key gnus-summary-exit-map
5496 "n" 'gnus-summary-catchup-and-goto-next-group)
5497 (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group)
5498 (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group)
5499 (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group)
5500 (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group)
5501
5502
5503 (define-prefix-command 'gnus-summary-article-map)
5504 (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map)
5505 (define-key gnus-summary-article-map " " 'gnus-summary-next-page)
5506 (define-key gnus-summary-article-map "n" 'gnus-summary-next-page)
5507 (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page)
5508 (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page)
5509 (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up)
5510 (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article)
5511 (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article)
5512 (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article)
5513 (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article)
5514 (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article)
5515 (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article)
5516 (define-key gnus-summary-article-map "g" 'gnus-summary-show-article)
5517 (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article)
5518
5519
5520
5521 (define-prefix-command 'gnus-summary-wash-map)
5522 (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map)
5523
5524 (define-prefix-command 'gnus-summary-wash-hide-map)
5525 (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map)
5526 (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide)
5527 (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers)
5528 (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature)
5529 (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation)
5530 (define-key gnus-summary-wash-hide-map
5531 "\C-c" 'gnus-article-hide-citation-maybe)
5532
5533 (define-prefix-command 'gnus-summary-wash-highlight-map)
5534 (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map)
5535 (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight)
5536 (define-key gnus-summary-wash-highlight-map
5537 "h" 'gnus-article-highlight-headers)
5538 (define-key gnus-summary-wash-highlight-map
5539 "c" 'gnus-article-highlight-citation)
5540 (define-key gnus-summary-wash-highlight-map
5541 "s" 'gnus-article-highlight-signature)
5542
5543 (define-prefix-command 'gnus-summary-wash-time-map)
5544 (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map)
5545 (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut)
5546 (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut)
5547 (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local)
5548 (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed)
5549
5550 (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons)
5551 (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike)
5552 (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap)
5553 (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr)
5554 (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable)
5555 (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face)
5556 (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking)
5557 (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message)
5558 (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header)
5559 (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime)
5560
5561
5562 (define-prefix-command 'gnus-summary-help-map)
5563 (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map)
5564 (define-key gnus-summary-help-map "v" 'gnus-version)
5565 (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq)
5566 (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group)
5567 (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly)
5568 (define-key gnus-summary-help-map "i" 'gnus-info-find-node)
5569
5570
5571 (define-prefix-command 'gnus-summary-backend-map)
5572 (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map)
5573 (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles)
5574 (define-key gnus-summary-backend-map "\M-\C-e"
5575 'gnus-summary-expire-articles-now)
5576 (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article)
5577 (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article)
5578 (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article)
5579 (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article)
5580 (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article)
5581 (define-key gnus-summary-backend-map "q" 'gnus-summary-fancy-query)
5582 (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article)
5583
5584
5585 (define-prefix-command 'gnus-summary-save-map)
5586 (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map)
5587 (define-key gnus-summary-save-map "o" 'gnus-summary-save-article)
5588 (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail)
5589 (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail)
5590 (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file)
5591 (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder)
5592 (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm)
5593 (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output)
5594 ; (define-key gnus-summary-save-map "s" 'gnus-soup-add-article)
5595
5596 (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
5597
5598 (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument)
5599 ; (define-key gnus-summary-various-map "\C-s" 'gnus-summary-search-article-forward)
5600 ; (define-key gnus-summary-various-map "\C-r" 'gnus-summary-search-article-backward)
5601 ; (define-key gnus-summary-various-map "r" 'gnus-summary-refer-article)
5602 ; (define-key gnus-summary-various-map "&" 'gnus-summary-execute-command)
5603 ; (define-key gnus-summary-various-map "T" 'gnus-summary-toggle-truncation)
5604 ; (define-key gnus-summary-various-map "e" 'gnus-summary-expand-window)
5605 (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group)
5606 ; (define-key gnus-summary-various-map "k" 'gnus-summary-edit-local-kill)
5607 ; (define-key gnus-summary-various-map "K" 'gnus-summary-edit-global-kill)
5608
5609 (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map)
5610
5611 ; (define-prefix-command 'gnus-summary-sort-map)
5612 ; (define-key gnus-summary-various-map "s" 'gnus-summary-sort-map)
5613 ; (define-key gnus-summary-sort-map "n" 'gnus-summary-sort-by-number)
5614 ; (define-key gnus-summary-sort-map "a" 'gnus-summary-sort-by-author)
5615 ; (define-key gnus-summary-sort-map "s" 'gnus-summary-sort-by-subject)
5616 ; (define-key gnus-summary-sort-map "d" 'gnus-summary-sort-by-date)
5617 ; (define-key gnus-summary-sort-map "i" 'gnus-summary-sort-by-score)
5618
5619 (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score)
5620 (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score)
5621 )
5622
5623
5624 \f
5625
5626 (defun gnus-summary-mode (&optional group)
5627 "Major mode for reading articles.
5628
5629 All normal editing commands are switched off.
5630 \\<gnus-summary-mode-map>
5631 Each line in this buffer represents one article. To read an
5632 article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
5633 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
5634 respectively.
5635
5636 You can also post articles and send mail from this buffer. To
5637 follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
5638 of an article, type `\\[gnus-summary-reply]'.
5639
5640 There are approx. one gazillion commands you can execute in this
5641 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
5642
5643 The following commands are available:
5644
5645 \\{gnus-summary-mode-map}"
5646 (interactive)
5647 (if gnus-visual (gnus-summary-make-menu-bar))
5648 (kill-all-local-variables)
5649 (let ((locals gnus-summary-local-variables))
5650 (while locals
5651 (if (consp (car locals))
5652 (progn
5653 (make-local-variable (car (car locals)))
5654 (set (car (car locals)) (eval (cdr (car locals)))))
5655 (make-local-variable (car locals))
5656 (set (car locals) nil))
5657 (setq locals (cdr locals))))
5658 (gnus-make-thread-indent-array)
5659 (gnus-simplify-mode-line)
5660 (setq major-mode 'gnus-summary-mode)
5661 (setq mode-name "Summary")
5662 (make-local-variable 'minor-mode-alist)
5663 (use-local-map gnus-summary-mode-map)
5664 (buffer-disable-undo (current-buffer))
5665 (setq buffer-read-only t) ;Disable modification
5666 (setq truncate-lines t)
5667 (setq selective-display t)
5668 (setq selective-display-ellipses t) ;Display `...'
5669 (setq buffer-display-table gnus-summary-display-table)
5670 (setq gnus-newsgroup-name group)
5671 (run-hooks 'gnus-summary-mode-hook))
5672
5673 (defun gnus-summary-make-display-table ()
5674 ;; Change the display table. Odd characters have a tendency to mess
5675 ;; up nicely formatted displays - we make all possible glyphs
5676 ;; display only a single character.
5677
5678 ;; We start from the standard display table, if any.
5679 (setq gnus-summary-display-table
5680 (or (copy-sequence standard-display-table)
5681 (make-display-table)))
5682 ;; Nix out all the control chars...
5683 (let ((i 32))
5684 (while (>= (setq i (1- i)) 0)
5685 (aset gnus-summary-display-table i [??])))
5686 ;; ... but not newline and cr, of course. (cr is necessary for the
5687 ;; selective display).
5688 (aset gnus-summary-display-table ?\n nil)
5689 (aset gnus-summary-display-table ?\r nil)
5690 ;; We nix out any glyphs over 126 that are not set already.
5691 (let ((i 256))
5692 (while (>= (setq i (1- i)) 127)
5693 ;; Only modify if the entry is nil.
5694 (or (aref gnus-summary-display-table i)
5695 (aset gnus-summary-display-table i [??])))))
5696
5697 (defun gnus-summary-clear-local-variables ()
5698 (let ((locals gnus-summary-local-variables))
5699 (while locals
5700 (if (consp (car locals))
5701 (and (vectorp (car (car locals)))
5702 (set (car (car locals)) nil))
5703 (and (vectorp (car locals))
5704 (set (car locals) nil)))
5705 (setq locals (cdr locals)))))
5706
5707 ;; Some summary mode macros.
5708
5709 ;; Return a header specified by a NUMBER.
5710 (defun gnus-get-header-by-number (number)
5711 (save-excursion
5712 (set-buffer gnus-summary-buffer)
5713 (or gnus-newsgroup-headers-hashtb-by-number
5714 (gnus-make-headers-hashtable-by-number))
5715 (gnus-gethash (int-to-string number)
5716 gnus-newsgroup-headers-hashtb-by-number)))
5717
5718 ;; Fast version of the function above.
5719 (defmacro gnus-get-header-by-num (number)
5720 (` (gnus-gethash (int-to-string (, number))
5721 gnus-newsgroup-headers-hashtb-by-number)))
5722
5723 (defmacro gnus-summary-search-forward (&optional unread subject backward)
5724 "Search for article forward.
5725 If UNREAD is non-nil, only unread articles are selected.
5726 If SUBJECT is non-nil, the article which has the same subject will be
5727 searched for.
5728 If BACKWARD is non-nil, the search will be performed backwards instead."
5729 (` (gnus-summary-search-subject (, backward) (, unread) (, subject))))
5730
5731 (defmacro gnus-summary-search-backward (&optional unread subject)
5732 "Search for article backward.
5733 If 1st optional argument UNREAD is non-nil, only unread article is selected.
5734 If 2nd optional argument SUBJECT is non-nil, the article which has
5735 the same subject will be searched for."
5736 (` (gnus-summary-search-forward (, unread) (, subject) t)))
5737
5738 (defmacro gnus-summary-article-number (&optional number-or-nil)
5739 "The article number of the article on the current line.
5740 If there isn's an article number here, then we return the current
5741 article number."
5742 (if number-or-nil
5743 '(get-text-property (gnus-point-at-bol) 'gnus-number)
5744 '(or (get-text-property (gnus-point-at-bol) 'gnus-number)
5745 gnus-current-article)))
5746
5747 (defmacro gnus-summary-thread-level ()
5748 "The thread level of the article on the current line."
5749 '(or (get-text-property (gnus-point-at-bol) 'gnus-level)
5750 0))
5751
5752 (defmacro gnus-summary-article-mark ()
5753 "The mark on the current line."
5754 '(get-text-property (gnus-point-at-bol) 'gnus-mark))
5755
5756 (defun gnus-summary-subject-string ()
5757 "Return current subject string or nil if nothing."
5758 (let ((article (gnus-summary-article-number))
5759 header)
5760 (and article
5761 (setq header (gnus-get-header-by-num article))
5762 (vectorp header)
5763 (mail-header-subject header))))
5764
5765 ;; Various summary mode internalish functions.
5766
5767 (defun gnus-mouse-pick-article (e)
5768 (interactive "e")
5769 (mouse-set-point e)
5770 (gnus-summary-next-page nil t))
5771
5772 (defun gnus-summary-setup-buffer (group)
5773 "Initialize summary buffer."
5774 (let ((buffer (concat "*Summary " group "*")))
5775 (if (get-buffer buffer)
5776 (progn
5777 (set-buffer buffer)
5778 (not gnus-newsgroup-begin))
5779 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
5780 (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
5781 (gnus-add-current-to-buffer-list)
5782 (gnus-summary-mode group)
5783 (and gnus-carpal (gnus-carpal-setup-buffer 'summary))
5784 (setq gnus-newsgroup-name group)
5785 t)))
5786
5787 (defun gnus-set-global-variables ()
5788 ;; Set the global equivalents of the summary buffer-local variables
5789 ;; to the latest values they had. These reflect the summary buffer
5790 ;; that was in action when the last article was fetched.
5791 (if (eq major-mode 'gnus-summary-mode)
5792 (progn
5793 (setq gnus-summary-buffer (current-buffer))
5794 (let ((name gnus-newsgroup-name)
5795 (marked gnus-newsgroup-marked)
5796 (unread gnus-newsgroup-unreads)
5797 (headers gnus-current-headers)
5798 (score-file gnus-current-score-file))
5799 (save-excursion
5800 (set-buffer gnus-group-buffer)
5801 (setq gnus-newsgroup-name name)
5802 (setq gnus-newsgroup-marked marked)
5803 (setq gnus-newsgroup-unreads unread)
5804 (setq gnus-current-headers headers)
5805 (setq gnus-current-score-file score-file))))))
5806
5807 (defun gnus-summary-insert-dummy-line (sformat subject number)
5808 (if (not sformat)
5809 (setq sformat gnus-summary-dummy-line-format-spec))
5810 (let (b)
5811 (beginning-of-line)
5812 (setq b (point))
5813 (insert (eval sformat))
5814 (add-text-properties
5815 b (1+ b)
5816 (list 'gnus-number number
5817 'gnus-mark gnus-dummy-mark
5818 'gnus-level 0))))
5819
5820 (defvar gnus-thread-indent-array nil)
5821 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
5822 (defun gnus-make-thread-indent-array ()
5823 (let ((n 200))
5824 (if (and gnus-thread-indent-array
5825 (= gnus-thread-indent-level gnus-thread-indent-array-level))
5826 nil
5827 (setq gnus-thread-indent-array (make-vector 201 "")
5828 gnus-thread-indent-array-level gnus-thread-indent-level)
5829 (while (>= n 0)
5830 (aset gnus-thread-indent-array n
5831 (make-string (* n gnus-thread-indent-level) ? ))
5832 (setq n (1- n))))))
5833
5834 (defun gnus-summary-insert-line
5835 (sformat header level current unread replied expirable subject-or-nil
5836 &optional dummy score process)
5837 (or sformat (setq sformat gnus-summary-line-format-spec))
5838 (let* ((indentation (aref gnus-thread-indent-array level))
5839 (lines (mail-header-lines header))
5840 (score (or score gnus-summary-default-score 0))
5841 (score-char
5842 (if (or (null gnus-summary-default-score)
5843 (<= (abs (- score gnus-summary-default-score))
5844 gnus-summary-zcore-fuzz)) ?
5845 (if (< score gnus-summary-default-score)
5846 gnus-score-below-mark gnus-score-over-mark)))
5847 (replied (cond (process gnus-process-mark)
5848 (replied gnus-replied-mark)
5849 (t gnus-unread-mark)))
5850 (from (mail-header-from header))
5851 (name (cond
5852 ((string-match "(.+)" from)
5853 (substring from (1+ (match-beginning 0)) (1- (match-end 0))))
5854 ((string-match "<[^>]+> *$" from)
5855 (let ((beg (match-beginning 0)))
5856 (or (and (string-match "^\"[^\"]*\"" from)
5857 (substring from (1+ (match-beginning 0))
5858 (1- (match-end 0))))
5859 (substring from 0 beg))))
5860 (t from)))
5861 (subject (mail-header-subject header))
5862 (number (mail-header-number header))
5863 (opening-bracket (if dummy ?\< ?\[))
5864 (closing-bracket (if dummy ?\> ?\]))
5865 (buffer-read-only nil)
5866 (b (progn (beginning-of-line) (point))))
5867 (or (numberp lines) (setq lines 0))
5868 (insert (eval sformat))
5869 (add-text-properties
5870 b (1+ b) (list 'gnus-number number
5871 'gnus-mark (or unread gnus-unread-mark)
5872 'gnus-level level))))
5873
5874 (defun gnus-summary-update-line (&optional dont-update)
5875 ;; Update summary line after change.
5876 (or (not gnus-summary-default-score)
5877 gnus-summary-inhibit-highlight
5878 (let ((gnus-summary-inhibit-highlight t)
5879 (article (gnus-summary-article-number)))
5880 (progn
5881 (or dont-update
5882 (if (and gnus-summary-mark-below
5883 (< (gnus-summary-article-score)
5884 gnus-summary-mark-below))
5885 (and (not (memq article gnus-newsgroup-marked))
5886 (not (memq article gnus-newsgroup-dormant))
5887 (memq article gnus-newsgroup-unreads)
5888 (gnus-summary-mark-article-as-read gnus-low-score-mark))
5889 (and (eq (gnus-summary-article-mark) gnus-low-score-mark)
5890 (gnus-summary-mark-article-as-unread gnus-unread-mark))))
5891 (and gnus-visual
5892 (run-hooks 'gnus-summary-update-hook))))))
5893
5894 (defun gnus-summary-update-lines (&optional beg end)
5895 ;; Mark article as read (or not) by taking into account scores.
5896 (let ((beg (or beg (point-min)))
5897 (end (or end (point-max))))
5898 (if (or (not gnus-summary-default-score)
5899 gnus-summary-inhibit-highlight)
5900 ()
5901 (let ((gnus-summary-inhibit-highlight t)
5902 article)
5903 (save-excursion
5904 (set-buffer gnus-summary-buffer)
5905 (goto-char beg)
5906 (beginning-of-line)
5907 (while (and (not (eobp)) (< (point) end))
5908 (if (and gnus-summary-mark-below
5909 (< (or (cdr (assq
5910 (setq article (get-text-property
5911 (point) 'gnus-number))
5912 gnus-newsgroup-scored))
5913 gnus-summary-default-score 0)
5914 gnus-summary-mark-below))
5915 ;; We want to possibly mark it as read...
5916 (and (not (memq article gnus-newsgroup-marked))
5917 (not (memq article gnus-newsgroup-dormant))
5918 (memq article gnus-newsgroup-unreads)
5919 (gnus-summary-mark-article-as-read gnus-low-score-mark))
5920 ;; We want to possibly mark it as unread.
5921 (and (eq (get-text-property (point) 'gnus-mark)
5922 gnus-low-score-mark)
5923 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
5924 ;; Do the visual highlights at the same time.
5925 (and gnus-visual (run-hooks 'gnus-summary-update-hook))
5926 (forward-line 1)))))))
5927
5928 (defvar gnus-tmp-gathered nil)
5929
5930 (defun gnus-summary-number-of-articles-in-thread (thread &optional char)
5931 ;; Sum up all elements (and sub-elements) in a list.
5932 (let* ((number
5933 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
5934 (if (and (consp thread) (cdr thread))
5935 (apply
5936 '+ 1 (mapcar
5937 'gnus-summary-number-of-articles-in-thread
5938 (cdr thread)))
5939 1)))
5940 (if char
5941 (if (> number 1) gnus-not-empty-thread-mark
5942 gnus-empty-thread-mark)
5943 number)))
5944
5945 (defun gnus-summary-read-group
5946 (group &optional show-all no-article kill-buffer)
5947 "Start reading news in newsgroup GROUP.
5948 If SHOW-ALL is non-nil, already read articles are also listed.
5949 If NO-ARTICLE is non-nil, no article is selected initially."
5950 (gnus-message 5 "Retrieving newsgroup: %s..." group)
5951 (let* ((new-group (gnus-summary-setup-buffer group))
5952 (quit-config (gnus-group-quit-config group))
5953 (did-select (and new-group (gnus-select-newsgroup group show-all))))
5954 (cond
5955 ((not new-group)
5956 (gnus-set-global-variables)
5957 (gnus-kill-buffer kill-buffer)
5958 (gnus-configure-windows 'summary 'force)
5959 (gnus-set-mode-line 'summary)
5960 (gnus-summary-position-cursor)
5961 (message "")
5962 t)
5963 ((null did-select)
5964 (and (eq major-mode 'gnus-summary-mode)
5965 (not (equal (current-buffer) kill-buffer))
5966 (progn
5967 (kill-buffer (current-buffer))
5968 (if (not quit-config)
5969 (progn
5970 (set-buffer gnus-group-buffer)
5971 (gnus-group-jump-to-group group)
5972 (gnus-group-next-unread-group 1))
5973 (if (not (buffer-name (car quit-config)))
5974 (gnus-configure-windows 'group 'force)
5975 (set-buffer (car quit-config))
5976 (and (eq major-mode 'gnus-summary-mode)
5977 (gnus-set-global-variables))
5978 (gnus-configure-windows (cdr quit-config))))))
5979 (message "Can't select group")
5980 nil)
5981 ((eq did-select 'quit)
5982 (and (eq major-mode 'gnus-summary-mode)
5983 (not (equal (current-buffer) kill-buffer))
5984 (kill-buffer (current-buffer)))
5985 (gnus-kill-buffer kill-buffer)
5986 (if (not quit-config)
5987 (progn
5988 (set-buffer gnus-group-buffer)
5989 (gnus-group-jump-to-group group)
5990 (gnus-group-next-unread-group 1)
5991 (gnus-configure-windows 'group 'force))
5992 (if (not (buffer-name (car quit-config)))
5993 (gnus-configure-windows 'group 'force)
5994 (set-buffer (car quit-config))
5995 (and (eq major-mode 'gnus-summary-mode)
5996 (gnus-set-global-variables))
5997 (gnus-configure-windows (cdr quit-config))))
5998 (signal 'quit nil))
5999 (t
6000 (gnus-set-global-variables)
6001 ;; Save the active value in effect when the group was entered.
6002 (setq gnus-newsgroup-active
6003 (gnus-copy-sequence
6004 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
6005 ;; You can change the subjects in this hook.
6006 (run-hooks 'gnus-select-group-hook)
6007 ;; Do score processing.
6008 (and gnus-use-scoring (gnus-possibly-score-headers))
6009 (gnus-update-format-specifications)
6010 ;; Generate the summary buffer.
6011 (gnus-summary-prepare)
6012 (if (zerop (buffer-size))
6013 (cond (gnus-newsgroup-dormant
6014 (gnus-summary-show-all-dormant))
6015 ((and gnus-newsgroup-scored show-all)
6016 (gnus-summary-show-all-expunged))))
6017 ;; Function `gnus-apply-kill-file' must be called in this hook.
6018 (run-hooks 'gnus-apply-kill-hook)
6019 (if (zerop (buffer-size))
6020 (progn
6021 ;; This newsgroup is empty.
6022 (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
6023 (gnus-message 6 "No unread news")
6024 (gnus-kill-buffer kill-buffer)
6025 nil)
6026 ;;(save-excursion
6027 ;; (if kill-buffer
6028 ;; (let ((gnus-summary-buffer kill-buffer))
6029 ;; (gnus-configure-windows 'group))))
6030 ;; Hide conversation thread subtrees. We cannot do this in
6031 ;; gnus-summary-prepare-hook since kill processing may not
6032 ;; work with hidden articles.
6033 (and gnus-show-threads
6034 gnus-thread-hide-subtree
6035 (gnus-summary-hide-all-threads))
6036 ;; Show first unread article if requested.
6037 (goto-char (point-min))
6038 (if (and (not no-article)
6039 gnus-auto-select-first
6040 (gnus-summary-first-unread-article))
6041 ()
6042 (gnus-configure-windows 'summary 'force))
6043 (gnus-set-mode-line 'summary)
6044 (gnus-summary-position-cursor)
6045 ;; If in async mode, we send some info to the backend.
6046 (and gnus-newsgroup-async
6047 (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
6048 (gnus-request-asynchronous
6049 gnus-newsgroup-name
6050 (if (and gnus-asynchronous-article-function
6051 (fboundp gnus-asynchronous-article-function))
6052 (funcall gnus-asynchronous-article-function
6053 gnus-newsgroup-threads)
6054 gnus-newsgroup-threads)))
6055 (gnus-kill-buffer kill-buffer)
6056 (if (not (get-buffer-window gnus-group-buffer))
6057 ()
6058 ;; gotta use windows, because recenter does weird stuff if
6059 ;; the current buffer ain't the displayed window.
6060 (let ((owin (selected-window)))
6061 (select-window (get-buffer-window gnus-group-buffer))
6062 (and (gnus-group-goto-group group)
6063 (recenter))
6064 (select-window owin))))
6065 t))))
6066
6067 (defun gnus-summary-prepare ()
6068 ;; Generate the summary buffer.
6069 (let ((buffer-read-only nil))
6070 (erase-buffer)
6071 (gnus-summary-prepare-threads
6072 (if gnus-show-threads
6073 (gnus-gather-threads
6074 (gnus-sort-threads
6075 (if (and gnus-summary-expunge-below
6076 (not gnus-fetch-old-headers))
6077 (gnus-make-threads-and-expunge)
6078 (gnus-make-threads))))
6079 gnus-newsgroup-headers)
6080 'cull)
6081 (gnus-summary-update-lines)
6082 ;; Create the header hashtb.
6083 (gnus-make-headers-hashtable-by-number)
6084 ;; Call hooks for modifying summary buffer.
6085 ;; Suggested by sven@tde.LTH.Se (Sven Mattisson).
6086 (goto-char (point-min))
6087 (run-hooks 'gnus-summary-prepare-hook)))
6088
6089 (defun gnus-gather-threads (threads)
6090 "Gather threads that have lost their roots."
6091 (if (not gnus-summary-make-false-root)
6092 threads
6093 (let ((hashtb (gnus-make-hashtable 1023))
6094 (prev threads)
6095 (result threads)
6096 subject hthread whole-subject)
6097 (while threads
6098 (setq whole-subject
6099 (setq subject (mail-header-subject (car (car threads)))))
6100 (if gnus-summary-gather-subject-limit
6101 (or (and (numberp gnus-summary-gather-subject-limit)
6102 (> (length subject) gnus-summary-gather-subject-limit)
6103 (setq subject
6104 (substring subject 0
6105 gnus-summary-gather-subject-limit)))
6106 (and (eq 'fuzzy gnus-summary-gather-subject-limit)
6107 (setq subject (gnus-simplify-subject-fuzzy subject))))
6108 (setq subject (gnus-simplify-subject-re subject)))
6109 (if (setq hthread
6110 (gnus-gethash subject hashtb))
6111 (progn
6112 (or (stringp (car (car hthread)))
6113 (setcar hthread (list whole-subject (car hthread))))
6114 (setcdr (car hthread) (nconc (cdr (car hthread))
6115 (list (car threads))))
6116 (setcdr prev (cdr threads))
6117 (setq threads prev))
6118 (gnus-sethash subject threads hashtb))
6119 (setq prev threads)
6120 (setq threads (cdr threads)))
6121 result)))
6122
6123 (defun gnus-make-threads ()
6124 ;; This function takes the dependencies already made by
6125 ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6126 ;; through the dependencies in the hash table and finds all the
6127 ;; roots. Roots do not refer back to any valid articles.
6128 (gnus-message 6 "Threading...")
6129 (let (roots new-roots)
6130 (and gnus-fetch-old-headers
6131 (eq gnus-headers-retrieved-by 'nov)
6132 (gnus-build-old-threads))
6133 (mapatoms
6134 (lambda (refs)
6135 (if (not (car (symbol-value refs)))
6136 (setq roots (append (cdr (symbol-value refs)) roots))
6137 ;; Ok, these refer back to valid articles, but if
6138 ;; `gnus-thread-ignore-subject' is nil, we have to check that
6139 ;; the root has the same subject as its children. The children
6140 ;; that do not are made into roots and removed from the list
6141 ;; of children.
6142 (or gnus-thread-ignore-subject
6143 (let* ((prev (symbol-value refs))
6144 (subject (gnus-simplify-subject-re
6145 (mail-header-subject (car prev))))
6146 (headers (cdr prev)))
6147 (while headers
6148 (if (not (string= subject
6149 (gnus-simplify-subject-re
6150 (mail-header-subject (car headers)))))
6151 (progn
6152 (setq new-roots (cons (car headers) new-roots))
6153 (setcdr prev (cdr headers)))
6154 (setq prev headers))
6155 (setq headers (cdr headers)))))))
6156 gnus-newsgroup-dependencies)
6157
6158 ;; We enter the new roots into the dependencies structure to
6159 ;; ensure that any possible later thread-regeneration will be
6160 ;; possible.
6161 (let ((r new-roots))
6162 (while r
6163 (gnus-sethash (concat (mail-header-id (car r)) ".boo")
6164 (list nil (car r)) gnus-newsgroup-dependencies)
6165 (setq r (cdr r))))
6166
6167 (setq roots (nconc new-roots roots))
6168
6169 (prog1
6170 (mapcar 'gnus-trim-thread
6171 (apply 'append
6172 (mapcar 'gnus-cut-thread
6173 (mapcar 'gnus-make-sub-thread roots))))
6174 (gnus-message 6 "Threading...done"))))
6175
6176
6177 (defun gnus-make-threads-and-expunge ()
6178 ;; This function takes the dependencies already made by
6179 ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6180 ;; through the dependencies in the hash table and finds all the
6181 ;; roots. Roots do not refer back to any valid articles.
6182 (gnus-message 6 "Threading...")
6183 (let ((default (or gnus-summary-default-score 0))
6184 (below gnus-summary-expunge-below)
6185 roots article new-roots)
6186 (and gnus-fetch-old-headers
6187 (eq gnus-headers-retrieved-by 'nov)
6188 (gnus-build-old-threads))
6189 (mapatoms
6190 (lambda (refs)
6191 (if (not (car (symbol-value refs)))
6192 ;; These articles do not refer back to any other articles -
6193 ;; they are roots.
6194 (let ((headers (cdr (symbol-value refs))))
6195 ;; We weed out the low-scored articles.
6196 (while headers
6197 (if (not (< (or (cdr (assq (mail-header-number (car headers))
6198 gnus-newsgroup-scored)) default)
6199 below))
6200 ;; It is over.
6201 (setq roots (cons (car headers) roots))
6202 ;; It is below, so we mark it as read.
6203 (setq gnus-newsgroup-unreads
6204 (delq (mail-header-number (car headers))
6205 gnus-newsgroup-unreads))
6206 (setq gnus-newsgroup-reads
6207 (cons (cons (mail-header-number (car headers))
6208 gnus-low-score-mark)
6209 gnus-newsgroup-reads)))
6210 (setq headers (cdr headers))))
6211 ;; Ok, these refer back to valid articles, but if
6212 ;; `gnus-thread-ignore-subject' is nil, we have to check that
6213 ;; the root has the same subject as its children. The children
6214 ;; that do not are made into roots and removed from the list
6215 ;; of children.
6216 (or gnus-thread-ignore-subject
6217 (let* ((prev (symbol-value refs))
6218 (subject (gnus-simplify-subject-re
6219 (mail-header-subject (car prev))))
6220 (headers (cdr prev)))
6221 (while headers
6222 (if (not (string= subject
6223 (gnus-simplify-subject-re
6224 (mail-header-subject (car headers)))))
6225 (progn
6226 (if (not (< (or (cdr (assq (mail-header-number
6227 (car headers))
6228 gnus-newsgroup-scored))
6229 default) below))
6230 (setq new-roots (cons (car headers) new-roots))
6231 (setq gnus-newsgroup-unreads
6232 (delq (mail-header-number (car headers))
6233 gnus-newsgroup-unreads))
6234 (setq gnus-newsgroup-reads
6235 (cons (cons (mail-header-number (car headers))
6236 gnus-low-score-mark)
6237 gnus-newsgroup-reads)))
6238 (setcdr prev (cdr headers)))
6239 (setq prev headers))
6240 (setq headers (cdr headers)))))
6241 ;; If this article is expunged, some of the children might be
6242 ;; roots.
6243 (if (< (or (cdr (assq (mail-header-number (car (symbol-value refs)))
6244 gnus-newsgroup-scored)) default)
6245 below)
6246 (let* ((prev (symbol-value refs))
6247 (headers (cdr prev)))
6248 (while headers
6249 (setq article (mail-header-number (car headers)))
6250 (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6251 default) below))
6252 (progn (setq new-roots (cons (car headers) new-roots))
6253 (setq prev headers))
6254 (setq gnus-newsgroup-unreads
6255 (delq article gnus-newsgroup-unreads))
6256 (setq gnus-newsgroup-reads
6257 (cons (cons article gnus-low-score-mark)
6258 gnus-newsgroup-reads))
6259 (setcdr prev (cdr headers)))
6260 (setq headers (cdr headers))))
6261 ;; It was not expunged, but we look at expunged children.
6262 (let* ((prev (symbol-value refs))
6263 (headers (cdr prev))
6264 article)
6265 (while headers
6266 (setq article (mail-header-number (car headers)))
6267 (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6268 default) below))
6269 (setq prev headers)
6270 (setq gnus-newsgroup-unreads
6271 (delq article gnus-newsgroup-unreads))
6272 (setq gnus-newsgroup-reads
6273 (cons (cons article gnus-low-score-mark)
6274 gnus-newsgroup-reads))
6275 (setcdr prev (cdr headers)))
6276 (setq headers (cdr headers)))))))
6277 gnus-newsgroup-dependencies)
6278
6279 ;; We enter the new roots into the dependencies structure to
6280 ;; ensure that any possible later thread-regeneration will be
6281 ;; possible.
6282 (let ((r new-roots))
6283 (while r
6284 (gnus-sethash (concat (mail-header-id (car r)) ".boo")
6285 (list nil (car r)) gnus-newsgroup-dependencies)
6286 (setq r (cdr r))))
6287
6288 (setq roots (nconc new-roots roots))
6289
6290 (prog1
6291 (mapcar 'gnus-trim-thread
6292 (apply 'append
6293 (mapcar 'gnus-cut-thread
6294 (mapcar 'gnus-make-sub-thread roots))))
6295 (gnus-message 6 "Threading...done"))))
6296
6297
6298 (defun gnus-cut-thread (thread)
6299 ;; Remove leaf dormant or ancient articles from THREAD.
6300 (let ((head (car thread))
6301 (tail (apply 'append (mapcar 'gnus-cut-thread (cdr thread)))))
6302 (if (and (null tail)
6303 (let ((number (mail-header-number head)))
6304 (or (memq number gnus-newsgroup-ancient)
6305 (memq number gnus-newsgroup-dormant)
6306 (and gnus-summary-expunge-below
6307 (eq gnus-fetch-old-headers 'some)
6308 (< (or (cdr (assq number gnus-newsgroup-scored))
6309 gnus-summary-default-score 0)
6310 gnus-summary-expunge-below)
6311 (progn
6312 (setq gnus-newsgroup-unreads
6313 (delq number gnus-newsgroup-unreads))
6314 (setq gnus-newsgroup-reads
6315 (cons (cons number gnus-low-score-mark)
6316 gnus-newsgroup-reads))
6317 t)))))
6318 nil
6319 (list (cons head tail)))))
6320
6321 (defun gnus-trim-thread (thread)
6322 ;; Remove root ancient articles with only one child from THREAD.
6323 (if (and (eq gnus-fetch-old-headers 'some)
6324 (memq (mail-header-number (car thread)) gnus-newsgroup-ancient)
6325 (= (length thread) 2))
6326 (gnus-trim-thread (nth 1 thread))
6327 thread))
6328
6329 (defun gnus-make-sub-thread (root)
6330 ;; This function makes a sub-tree for a node in the tree.
6331 (let ((children (reverse (cdr (gnus-gethash (downcase (mail-header-id root))
6332 gnus-newsgroup-dependencies)))))
6333 (cons root (mapcar 'gnus-make-sub-thread children))))
6334
6335 (defun gnus-build-old-threads ()
6336 ;; Look at all the articles that refer back to old articles, and
6337 ;; fetch the headers for the articles that aren't there. This will
6338 ;; build complete threads - if the roots haven't been expired by the
6339 ;; server, that is.
6340 (let (id heads)
6341 (mapatoms
6342 (lambda (refs)
6343 (if (not (car (symbol-value refs)))
6344 (progn
6345 (setq heads (cdr (symbol-value refs)))
6346 (while heads
6347 (if (not (memq (mail-header-number (car heads))
6348 gnus-newsgroup-dormant))
6349 (progn
6350 (setq id (symbol-name refs))
6351 (while (and (setq id (gnus-build-get-header id))
6352 (not (car (gnus-gethash
6353 id gnus-newsgroup-dependencies)))))
6354 (setq heads nil))
6355 (setq heads (cdr heads)))))))
6356 gnus-newsgroup-dependencies)))
6357
6358 (defun gnus-build-get-header (id)
6359 ;; Look through the buffer of NOV lines and find the header to
6360 ;; ID. Enter this line into the dependencies hash table, and return
6361 ;; the id of the parent article (if any).
6362 (let ((deps gnus-newsgroup-dependencies)
6363 found header)
6364 (prog1
6365 (save-excursion
6366 (set-buffer nntp-server-buffer)
6367 (goto-char (point-min))
6368 (while (and (not found) (search-forward id nil t))
6369 (beginning-of-line)
6370 (setq found (looking-at
6371 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
6372 (regexp-quote id))))
6373 (or found (beginning-of-line 2)))
6374 (if found
6375 (let (ref)
6376 (beginning-of-line)
6377 (and
6378 (setq header (gnus-nov-parse-line
6379 (read (current-buffer)) deps))
6380 (setq ref (mail-header-references header))
6381 (string-match "\\(<[^>]+>\\) *$" ref)
6382 (substring ref (match-beginning 1) (match-end 1))))))
6383 (and header
6384 (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)
6385 gnus-newsgroup-ancient (cons (mail-header-number header)
6386 gnus-newsgroup-ancient))))))
6387
6388 ;; Re-build the thread containing ID.
6389 (defun gnus-rebuild-thread (id)
6390 (let ((dep gnus-newsgroup-dependencies)
6391 (buffer-read-only nil)
6392 parent headers refs thread art)
6393 (while (and id (setq headers
6394 (car (setq art (gnus-gethash (downcase id) dep)))))
6395 (setq parent art)
6396 (setq id (and (setq refs (mail-header-references headers))
6397 (string-match "\\(<[^>]+>\\) *$" refs)
6398 (substring refs (match-beginning 1) (match-end 1)))))
6399 (setq thread (gnus-make-sub-thread (car parent)))
6400 (gnus-rebuild-remove-articles thread)
6401 (let ((beg (point)))
6402 (gnus-summary-prepare-threads (list thread))
6403 (gnus-summary-update-lines beg (point)))))
6404
6405 ;; Delete all lines in the summary buffer that correspond to articles
6406 ;; in this thread.
6407 (defun gnus-rebuild-remove-articles (thread)
6408 (and (gnus-summary-goto-subject (mail-header-number (car thread)))
6409 (gnus-delete-line))
6410 (mapcar (lambda (th) (gnus-rebuild-remove-articles th)) (cdr thread)))
6411
6412 (defun gnus-sort-threads (threads)
6413 ;; Sort threads as specified in `gnus-thread-sort-functions'.
6414 (let ((fun gnus-thread-sort-functions))
6415 (while fun
6416 (gnus-message 6 "Sorting with %S..." fun)
6417 (setq threads (sort threads (car fun))
6418 fun (cdr fun))))
6419 (if gnus-thread-sort-functions
6420 (gnus-message 6 "Sorting...done"))
6421 threads)
6422
6423 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
6424 (defmacro gnus-thread-header (thread)
6425 ;; Return header of first article in THREAD.
6426 ;; Note that THREAD must never, evr be anything else than a variable -
6427 ;; using some other form will lead to serious barfage.
6428 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
6429 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
6430 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
6431 (vector thread) 2))
6432
6433 (defun gnus-thread-sort-by-number (h1 h2)
6434 "Sort threads by root article number."
6435 (< (mail-header-number (gnus-thread-header h1))
6436 (mail-header-number (gnus-thread-header h2))))
6437
6438 (defun gnus-thread-sort-by-author (h1 h2)
6439 "Sort threads by root author."
6440 (string-lessp
6441 (let ((extract (funcall
6442 gnus-extract-address-components
6443 (mail-header-from (gnus-thread-header h1)))))
6444 (or (car extract) (cdr extract)))
6445 (let ((extract (funcall
6446 gnus-extract-address-components
6447 (mail-header-from (gnus-thread-header h2)))))
6448 (or (car extract) (cdr extract)))))
6449
6450 (defun gnus-thread-sort-by-subject (h1 h2)
6451 "Sort threads by root subject."
6452 (string-lessp
6453 (downcase (gnus-simplify-subject-re
6454 (mail-header-subject (gnus-thread-header h1))))
6455 (downcase (gnus-simplify-subject-re
6456 (mail-header-subject (gnus-thread-header h2))))))
6457
6458 (defun gnus-thread-sort-by-date (h1 h2)
6459 "Sort threads by root article date."
6460 (string-lessp
6461 (gnus-sortable-date (mail-header-date (gnus-thread-header h1)))
6462 (gnus-sortable-date (mail-header-date (gnus-thread-header h2)))))
6463
6464 (defun gnus-thread-sort-by-score (h1 h2)
6465 "Sort threads by root article score.
6466 Unscored articles will be counted as having a score of zero."
6467 (> (or (cdr (assq (mail-header-number (gnus-thread-header h1))
6468 gnus-newsgroup-scored))
6469 gnus-summary-default-score 0)
6470 (or (cdr (assq (mail-header-number (gnus-thread-header h2))
6471 gnus-newsgroup-scored))
6472 gnus-summary-default-score 0)))
6473
6474 (defun gnus-thread-sort-by-total-score (h1 h2)
6475 "Sort threads by the sum of all scores in the thread.
6476 Unscored articles will be counted as having a score of zero."
6477 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
6478
6479 (defun gnus-thread-total-score (thread)
6480 ;; This function find the total score of THREAD.
6481 (if (consp thread)
6482 (if (stringp (car thread))
6483 (apply gnus-thread-score-function 0
6484 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
6485 (gnus-thread-total-score-1 thread))
6486 (gnus-thread-total-score-1 (list thread))))
6487
6488 (defun gnus-thread-total-score-1 (root)
6489 ;; This function find the total score of the thread below ROOT.
6490 (setq root (car root))
6491 (apply gnus-thread-score-function
6492 (or (cdr (assq (mail-header-number root) gnus-newsgroup-scored))
6493 gnus-summary-default-score 0)
6494 (mapcar 'gnus-thread-total-score
6495 (cdr (gnus-gethash (downcase (mail-header-id root))
6496 gnus-newsgroup-dependencies)))))
6497
6498 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
6499 (defvar gnus-tmp-prev-subject "")
6500
6501 (defun gnus-summary-prepare-threads (threads &optional cull)
6502 "Prepare summary buffer from THREADS and indentation LEVEL.
6503 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
6504 or a straight list of headers."
6505 (message "Generating summary...")
6506 (let ((level 0)
6507 thread header number subject stack state gnus-tmp-gathered)
6508 (if (vectorp (car threads))
6509 ;; If this is a straight (sic) list of headers, then a
6510 ;; threaded summary display isn't required, so we just create
6511 ;; an unthreaded one.
6512 (gnus-summary-prepare-unthreaded threads cull)
6513
6514 ;; Do the threaded display.
6515
6516 (while (or threads stack)
6517
6518 (if threads
6519 ;; If there are some threads, we do them before the
6520 ;; threads on the stack.
6521 (setq thread threads
6522 header (car (car thread)))
6523 ;; There were no current threads, so we pop something off
6524 ;; the stack.
6525 (setq state (car stack)
6526 level (car state)
6527 thread (cdr state)
6528 stack (cdr stack)
6529 header (car (car thread))))
6530
6531 (if (stringp header)
6532 (progn
6533 ;; The header is a dummy root.
6534 (cond
6535 ((eq gnus-summary-make-false-root 'adopt)
6536 ;; We let the first article adopt the rest.
6537 (let ((th (car (cdr (car thread)))))
6538 (while (cdr th)
6539 (setq th (cdr th)))
6540 (setcdr th (cdr (cdr (car thread))))
6541 (setq gnus-tmp-gathered
6542 (nconc (mapcar
6543 (lambda (h) (mail-header-number (car h)))
6544 (cdr (cdr (car thread))))
6545 gnus-tmp-gathered))
6546 (setcdr (cdr (car thread)) nil))
6547 (setq level -1))
6548 ((eq gnus-summary-make-false-root 'empty)
6549 ;; We print adopted articles with empty subject fields.
6550 (setq gnus-tmp-gathered
6551 (nconc (mapcar
6552 (lambda (h) (mail-header-number (car h)))
6553 (cdr (cdr (car thread))))
6554 gnus-tmp-gathered))
6555 (setq level -1))
6556 ((eq gnus-summary-make-false-root 'dummy)
6557 ;; We output a dummy root.
6558 (gnus-summary-insert-dummy-line
6559 nil header (mail-header-number
6560 (car (car (cdr (car thread)))))))
6561 (t
6562 ;; We do not make a root for the gathered
6563 ;; sub-threads at all.
6564 (setq level -1))))
6565
6566 (setq number (mail-header-number header)
6567 subject (mail-header-subject header))
6568
6569 ;; Do the async thing.
6570 (and gnus-newsgroup-async
6571 (setq gnus-newsgroup-threads
6572 (cons (cons number (mail-header-lines header))
6573 gnus-newsgroup-threads)))
6574
6575 ;; We may have to root out some bad articles...
6576 (and cull
6577 (= level 0)
6578 (cond ((and (memq (setq number (mail-header-number header))
6579 gnus-newsgroup-dormant)
6580 (null thread))
6581 (setq header nil))
6582 ((and gnus-summary-expunge-below
6583 (< (or (cdr (assq number gnus-newsgroup-scored))
6584 gnus-summary-default-score 0)
6585 gnus-summary-expunge-below))
6586 (setq header nil)
6587 (setq gnus-newsgroup-unreads
6588 (delq number gnus-newsgroup-unreads))
6589 (setq gnus-newsgroup-reads
6590 (cons (cons number gnus-low-score-mark)
6591 gnus-newsgroup-reads)))))
6592
6593 (and
6594 header
6595 (progn
6596 (inline
6597 (gnus-summary-insert-line
6598 nil header level nil
6599 (cond
6600 ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6601 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6602 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6603 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6604 (t (or (cdr (assq number gnus-newsgroup-reads))
6605 gnus-ancient-mark)))
6606 (memq number gnus-newsgroup-replied)
6607 (memq number gnus-newsgroup-expirable)
6608 (cond
6609 ((and gnus-thread-ignore-subject
6610 (not (string=
6611 (gnus-simplify-subject-re gnus-tmp-prev-subject)
6612 (gnus-simplify-subject-re subject))))
6613 subject)
6614 ((zerop level)
6615 (if (and (eq gnus-summary-make-false-root 'empty)
6616 (memq number gnus-tmp-gathered))
6617 gnus-summary-same-subject
6618 subject))
6619 (t gnus-summary-same-subject))
6620 (and (eq gnus-summary-make-false-root 'adopt)
6621 (memq number gnus-tmp-gathered))
6622 (cdr (assq number gnus-newsgroup-scored))
6623 (memq number gnus-newsgroup-processable))
6624
6625 (setq gnus-tmp-prev-subject subject)))))
6626
6627 (if (nth 1 thread)
6628 (setq stack (cons (cons (max 0 level) (nthcdr 1 thread)) stack)))
6629 (setq level (1+ level))
6630 (setq threads (cdr (car thread))))))
6631 (message "Generating summary...done"))
6632
6633
6634
6635 (defun gnus-summary-prepare-unthreaded (headers &optional cull)
6636 (let (header number)
6637
6638 ;; Do the async thing, if that is required.
6639 (if gnus-newsgroup-async
6640 (setq gnus-newsgroup-threads
6641 (mapcar (lambda (h)
6642 (cons (mail-header-number h) (mail-header-lines h)))
6643 headers)))
6644
6645 (while headers
6646 (setq header (car headers)
6647 headers (cdr headers)
6648 number (mail-header-number header))
6649
6650 ;; We may have to root out some bad articles...
6651 (cond
6652 ((and cull
6653 (memq (setq number (mail-header-number header))
6654 gnus-newsgroup-dormant)))
6655 ((and cull gnus-summary-expunge-below
6656 (< (or (cdr (assq number gnus-newsgroup-scored))
6657 gnus-summary-default-score 0)
6658 gnus-summary-expunge-below))
6659 (setq gnus-newsgroup-unreads
6660 (delq number gnus-newsgroup-unreads))
6661 (setq gnus-newsgroup-reads
6662 (cons (cons number gnus-low-score-mark)
6663 gnus-newsgroup-reads)))
6664 (t
6665 (gnus-summary-insert-line
6666 nil header 0 nil
6667 (cond ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6668 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6669 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6670 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6671 (t (or (cdr (assq number gnus-newsgroup-reads))
6672 gnus-ancient-mark)))
6673 (memq number gnus-newsgroup-replied)
6674 (memq number gnus-newsgroup-expirable)
6675 (mail-header-subject header) nil
6676 (cdr (assq number gnus-newsgroup-scored))
6677 (memq number gnus-newsgroup-processable)))))))
6678
6679 (defun gnus-select-newsgroup (group &optional read-all)
6680 "Select newsgroup GROUP.
6681 If READ-ALL is non-nil, all articles in the group are selected."
6682 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
6683 (info (nth 2 entry))
6684 articles)
6685
6686 (or (gnus-check-server
6687 (setq gnus-current-select-method (gnus-find-method-for-group group)))
6688 (error "Couldn't open server"))
6689
6690 (or (and entry (not (eq (car entry) t))) ; Either it's active...
6691 (gnus-activate-group group) ; Or we can activate it...
6692 (progn ; Or we bug out.
6693 (kill-buffer (current-buffer))
6694 (error "Couldn't request group %s: %s"
6695 group (gnus-status-message group))))
6696
6697 (setq gnus-newsgroup-name group)
6698 (setq gnus-newsgroup-unselected nil)
6699 (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
6700
6701 (and gnus-asynchronous
6702 (gnus-check-backend-function
6703 'request-asynchronous gnus-newsgroup-name)
6704 (setq gnus-newsgroup-async
6705 (gnus-request-asynchronous gnus-newsgroup-name)))
6706
6707 (setq articles (gnus-articles-to-read group read-all))
6708
6709 (cond
6710 ((null articles)
6711 (gnus-message 3 "Couldn't select newsgroup")
6712 'quit)
6713 ((eq articles 0) nil)
6714 (t
6715 ;; Init the dependencies hash table.
6716 (setq gnus-newsgroup-dependencies
6717 (gnus-make-hashtable (length articles)))
6718 ;; Retrieve the headers and read them in.
6719 (gnus-message 5 "Fetching headers...")
6720 (setq gnus-newsgroup-headers
6721 (if (eq 'nov (setq gnus-headers-retrieved-by
6722 ;; This is a naughty hack. To get the
6723 ;; retrieval of old headers to work, we
6724 ;; set `nntp-nov-gap' to nil (locally),
6725 ;; and then just retrieve the headers.
6726 ;; Mucho magic.
6727 (if gnus-fetch-old-headers
6728 (let (nntp-nov-gap)
6729 (gnus-retrieve-headers
6730 (if (not (eq 1 (car articles)))
6731 (cons 1 articles)
6732 articles)
6733 gnus-newsgroup-name))
6734 (gnus-retrieve-headers
6735 articles gnus-newsgroup-name))))
6736 (progn
6737 (gnus-get-newsgroup-headers-xover articles))
6738 ;; If we were to fetch old headers, but the backend didn't
6739 ;; support XOVER, then it is possible we fetched one article
6740 ;; that we shouldn't have. If that's the case, we remove it.
6741 (if (or (not gnus-fetch-old-headers)
6742 (eq 1 (car articles)))
6743 ()
6744 (save-excursion
6745 (set-buffer nntp-server-buffer)
6746 (goto-char (point-min))
6747 (and
6748 (looking-at "[0-9]+[ \t]+1[ \t]") ; This is not a NOV line.
6749 (delete-region ; So we delete this head.
6750 (point)
6751 (search-forward "\n.\n" nil t)))))
6752 (gnus-get-newsgroup-headers)))
6753 (gnus-message 5 "Fetching headers...done")
6754 ;; Remove canceled articles from the list of unread articles.
6755 (setq gnus-newsgroup-unreads
6756 (gnus-set-sorted-intersection
6757 gnus-newsgroup-unreads
6758 (mapcar (lambda (headers) (mail-header-number headers))
6759 gnus-newsgroup-headers)))
6760 ;; Adjust and set lists of article marks.
6761 (and info
6762 (let (marked)
6763 (gnus-adjust-marked-articles info)
6764 (setq gnus-newsgroup-marked
6765 (copy-sequence
6766 (cdr (assq 'tick (setq marked (nth 3 info))))))
6767 (setq gnus-newsgroup-replied
6768 (copy-sequence (cdr (assq 'reply marked))))
6769 (setq gnus-newsgroup-expirable
6770 (copy-sequence (cdr (assq 'expire marked))))
6771 (setq gnus-newsgroup-killed
6772 (copy-sequence (cdr (assq 'killed marked))))
6773 (setq gnus-newsgroup-bookmarks
6774 (copy-sequence (cdr (assq 'bookmark marked))))
6775 (setq gnus-newsgroup-dormant
6776 (copy-sequence (cdr (assq 'dormant marked))))
6777 (setq gnus-newsgroup-scored
6778 (copy-sequence (cdr (assq 'score marked))))
6779 (setq gnus-newsgroup-processable nil)))
6780 ;; Check whether auto-expire is to be done in this group.
6781 (setq gnus-newsgroup-auto-expire
6782 (or (and (stringp gnus-auto-expirable-newsgroups)
6783 (string-match gnus-auto-expirable-newsgroups group))
6784 (memq 'auto-expire (nth 5 info))))
6785 ;; First and last article in this newsgroup.
6786 (and gnus-newsgroup-headers
6787 (setq gnus-newsgroup-begin
6788 (mail-header-number (car gnus-newsgroup-headers)))
6789 (setq gnus-newsgroup-end
6790 (mail-header-number
6791 (gnus-last-element gnus-newsgroup-headers))))
6792 (setq gnus-reffed-article-number -1)
6793 ;; GROUP is successfully selected.
6794 (or gnus-newsgroup-headers t)))))
6795
6796 (defun gnus-articles-to-read (group read-all)
6797 ;; Find out what articles the user wants to read.
6798 (let* ((articles
6799 ;; Select all articles if `read-all' is non-nil, or if all the
6800 ;; unread articles are dormant articles.
6801 (if (or read-all
6802 (= (length gnus-newsgroup-unreads)
6803 (length gnus-newsgroup-dormant)))
6804 (gnus-uncompress-range
6805 (gnus-gethash group gnus-active-hashtb))
6806 gnus-newsgroup-unreads))
6807 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
6808 (scored (length scored-list))
6809 (number (length articles))
6810 (marked (+ (length gnus-newsgroup-marked)
6811 (length gnus-newsgroup-dormant)))
6812 (select
6813 (cond
6814 ((numberp read-all)
6815 read-all)
6816 (t
6817 (condition-case ()
6818 (cond ((and (or (<= scored marked)
6819 (= scored number))
6820 (numberp gnus-large-newsgroup)
6821 (> number gnus-large-newsgroup))
6822 (let ((input
6823 (read-string
6824 (format
6825 "How many articles from %s (default %d): "
6826 gnus-newsgroup-name number))))
6827 (if (string-match "^[ \t]*$" input)
6828 number input)))
6829 ((and (> scored marked) (< scored number))
6830 (let ((input
6831 (read-string
6832 (format
6833 "%s %s (%d scored, %d total): "
6834 "How many articles from"
6835 group scored number))))
6836 (if (string-match "^[ \t]*$" input)
6837 number input)))
6838 (t number))
6839 (quit nil))))))
6840 (setq select (if (stringp select) (string-to-number select) select))
6841 (if (or (null select) (zerop select))
6842 select
6843 (if (and (not (zerop scored)) (<= (abs select) scored))
6844 (progn
6845 (setq articles (sort scored-list '<))
6846 (setq number (length articles)))
6847 (setq articles (copy-sequence articles)))
6848
6849 (if (< (abs select) number)
6850 (if (< select 0)
6851 ;; Select the N oldest articles.
6852 (setcdr (nthcdr (1- (abs select)) articles) nil)
6853 ;; Select the N most recent articles.
6854 (setq articles (nthcdr (- number select) articles))))
6855 (setq gnus-newsgroup-unselected
6856 (gnus-sorted-intersection
6857 gnus-newsgroup-unreads
6858 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
6859 articles)))
6860
6861 (defun gnus-killed-articles (killed articles)
6862 (let (out)
6863 (while articles
6864 (if (inline (gnus-member-of-range (car articles) killed))
6865 (setq out (cons (car articles) out)))
6866 (setq articles (cdr articles)))
6867 out))
6868
6869 (defun gnus-adjust-marked-articles (info &optional active)
6870 "Remove all marked articles that are no longer legal."
6871 (let ((marked-lists (nth 3 info))
6872 (active (or active (gnus-gethash (car info) gnus-active-hashtb)))
6873 m prev)
6874 ;; There are many types of marked articles.
6875 (while marked-lists
6876 (setq m (cdr (setq prev (car marked-lists))))
6877 (cond ((or (eq 'tick (car prev)) (eq 'dormant (car prev)))
6878 ;; Make sure that all ticked articles are a subset of the
6879 ;; unread/unselected articles.
6880 (while m
6881 (if (or (memq (car m) gnus-newsgroup-unreads)
6882 (memq (car m) gnus-newsgroup-unselected))
6883 (setq prev m)
6884 (setcdr prev (cdr m)))
6885 (setq m (cdr m))))
6886 ((eq 'score (car prev))
6887 ;; Scored articles should be a subset of
6888 ;; unread/unselected articles.
6889 (while m
6890 (if (or (memq (car (car m)) gnus-newsgroup-unreads)
6891 (memq (car (car m)) gnus-newsgroup-unreads))
6892 (setq prev m)
6893 (setcdr prev (cdr m)))
6894 (setq m (cdr m))))
6895 ((eq 'bookmark (car prev))
6896 ;; Bookmarks should be a subset of active articles.
6897 (while m
6898 (if (< (car (car m)) (car active))
6899 (setcdr prev (cdr m))
6900 (setq prev m))
6901 (setq m (cdr m))))
6902 ((eq 'killed (car prev))
6903 ;; Articles that have been through the kill process are
6904 ;; to be a subset of active articles.
6905 (while (and m (< (or (and (numberp (car m)) (car m))
6906 (cdr (car m)))
6907 (car active)))
6908 (setcdr prev (cdr m))
6909 (setq m (cdr m)))
6910 (if (and m (< (or (and (numberp (car m)) (car m))
6911 (car (car m)))
6912 (car active)))
6913 (setcar (if (numberp (car m)) m (car m)) (car active))))
6914 ((or (eq 'reply (car prev)) (eq 'expire (car prev)))
6915 ;; The replied and expirable articles have to be articles
6916 ;; that are active.
6917 (while m
6918 (if (< (car m) (car active))
6919 (setcdr prev (cdr m))
6920 (setq prev m))
6921 (setq m (cdr m)))))
6922 (setq marked-lists (cdr marked-lists)))
6923 ;; Remove all lists that are empty.
6924 (setq marked-lists (nth 3 info))
6925 (if marked-lists
6926 (progn
6927 (while (= 1 (length (car marked-lists)))
6928 (setq marked-lists (cdr marked-lists)))
6929 (setq m (cdr (setq prev marked-lists)))
6930 (while m
6931 (if (= 1 (length (car m)))
6932 (setcdr prev (cdr m))
6933 (setq prev m))
6934 (setq m (cdr m)))
6935 (setcar (nthcdr 3 info) marked-lists)))
6936 ;; Finally, if there are no marked lists at all left, and if there
6937 ;; are no elements after the lists in the info list, we just chop
6938 ;; the info list off before the marked lists.
6939 (and (null marked-lists)
6940 (not (nthcdr 4 info))
6941 (setcdr (nthcdr 2 info) nil)))
6942 info)
6943
6944 (defun gnus-set-marked-articles
6945 (info ticked replied expirable killed dormant bookmark score)
6946 "Enter the various lists of marked articles into the newsgroup info list."
6947 (let (newmarked)
6948 (and ticked (setq newmarked (cons (cons 'tick ticked) nil)))
6949 (and replied (setq newmarked (cons (cons 'reply replied) newmarked)))
6950 (and expirable (setq newmarked (cons (cons 'expire expirable)
6951 newmarked)))
6952 (and killed (setq newmarked (cons (cons 'killed killed) newmarked)))
6953 (and dormant (setq newmarked (cons (cons 'dormant dormant) newmarked)))
6954 (and bookmark (setq newmarked (cons (cons 'bookmark bookmark)
6955 newmarked)))
6956 (and score (setq newmarked (cons (cons 'score score) newmarked)))
6957 (if (nthcdr 3 info)
6958 (progn
6959 (setcar (nthcdr 3 info) newmarked)
6960 (and (not newmarked)
6961 (not (nthcdr 4 info))
6962 (setcdr (nthcdr 2 info) nil)))
6963 (if newmarked
6964 (setcdr (nthcdr 2 info) (list newmarked))))))
6965
6966 (defun gnus-add-marked-articles (group type articles &optional info force)
6967 ;; Add ARTICLES of TYPE to the info of GROUP.
6968 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
6969 ;; add, but replace marked articles of TYPE with ARTICLES.
6970 (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
6971 marked m)
6972 (or (not info)
6973 (and (not (setq marked (nthcdr 3 info)))
6974 (setcdr (nthcdr 2 info) (list (list (cons type articles)))))
6975 (and (not (setq m (assq type (car marked))))
6976 (setcar marked (cons (cons type articles) (car marked))))
6977 (if force
6978 (setcdr m articles)
6979 (nconc m articles)))))
6980
6981 (defun gnus-set-mode-line (where)
6982 "This function sets the mode line of the article or summary buffers.
6983 If WHERE is `summary', the summary mode line format will be used."
6984 (if (memq where gnus-updated-mode-lines)
6985 (let (mode-string)
6986 (save-excursion
6987 (set-buffer gnus-summary-buffer)
6988 (let* ((mformat (if (eq where 'article)
6989 gnus-article-mode-line-format-spec
6990 gnus-summary-mode-line-format-spec))
6991 (buffer-name (if (eq where 'article)
6992 (buffer-name
6993 (get-buffer gnus-article-buffer))
6994 (buffer-name)))
6995 (group-name gnus-newsgroup-name)
6996 (article-number (or gnus-current-article 0))
6997 (unread (- (length gnus-newsgroup-unreads)
6998 (length gnus-newsgroup-dormant)))
6999 (unread-and-unticked
7000 (- unread (length gnus-newsgroup-marked)))
7001 (unselected (length gnus-newsgroup-unselected))
7002 (unread-and-unselected
7003 (cond ((and (zerop unread-and-unticked)
7004 (zerop unselected)) "")
7005 ((zerop unselected)
7006 (format "{%d more}" unread-and-unticked))
7007 (t (format "{%d(+%d) more}"
7008 unread-and-unticked unselected))))
7009 (subject
7010 (if gnus-current-headers
7011 (mail-header-subject gnus-current-headers) ""))
7012 (max-len (and gnus-mode-non-string-length
7013 (- (frame-width) gnus-mode-non-string-length)))
7014 header);; passed as argument to any user-format-funcs
7015 (setq mode-string (eval mformat))
7016 (or (numberp max-len)
7017 (setq max-len (length mode-string)))
7018 (if (< max-len 4) (setq max-len 4))
7019 (if (> (length mode-string) max-len)
7020 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
7021 ;; function `substring' might cut on a middle
7022 ;; of multi-octet character.
7023 (setq mode-string
7024 (concat (gnus-truncate-string mode-string (- max-len 3))
7025 "...")))
7026 (setq mode-string (format (format "%%-%ds" max-len)
7027 mode-string))))
7028 (setq mode-line-buffer-identification mode-string)
7029 (set-buffer-modified-p t))))
7030
7031 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
7032 "Go through the HEADERS list and add all Xrefs to a hash table.
7033 The resulting hash table is returned, or nil if no Xrefs were found."
7034 (let* ((from-method (gnus-find-method-for-group from-newsgroup))
7035 (prefix (if (and
7036 (gnus-group-foreign-p from-newsgroup)
7037 (not (memq 'virtual
7038 (assoc (symbol-name (car from-method))
7039 gnus-valid-select-methods))))
7040 (gnus-group-real-prefix from-newsgroup)))
7041 (xref-hashtb (make-vector 63 0))
7042 start group entry number xrefs header)
7043 (while headers
7044 (setq header (car headers))
7045 (if (and (setq xrefs (mail-header-xref header))
7046 (not (memq (mail-header-number header) unreads)))
7047 (progn
7048 (setq start 0)
7049 (while (string-match "\\([^ ]+\\):\\([0-9]+\\)" xrefs start)
7050 (setq start (match-end 0))
7051 (setq group (concat prefix (substring xrefs (match-beginning 1)
7052 (match-end 1))))
7053 (setq number
7054 (string-to-int (substring xrefs (match-beginning 2)
7055 (match-end 2))))
7056 (if (setq entry (gnus-gethash group xref-hashtb))
7057 (setcdr entry (cons number (cdr entry)))
7058 (gnus-sethash group (cons number nil) xref-hashtb)))))
7059 (setq headers (cdr headers)))
7060 (if start xref-hashtb nil)))
7061
7062 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads expirable)
7063 "Look through all the headers and mark the Xrefs as read."
7064 (let ((virtual (memq 'virtual
7065 (assoc (symbol-name (car (gnus-find-method-for-group
7066 from-newsgroup)))
7067 gnus-valid-select-methods)))
7068 name entry info xref-hashtb idlist method
7069 nth4)
7070 (save-excursion
7071 (set-buffer gnus-group-buffer)
7072 (if (setq xref-hashtb
7073 (gnus-create-xref-hashtb from-newsgroup headers unreads))
7074 (mapatoms
7075 (lambda (group)
7076 (if (string= from-newsgroup (setq name (symbol-name group)))
7077 ()
7078 (setq idlist (symbol-value group))
7079 ;; Dead groups are not updated.
7080 (if (and (prog1
7081 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
7082 info (nth 2 entry))
7083 (if (stringp (setq nth4 (nth 4 info)))
7084 (setq nth4 (gnus-server-to-method nth4))))
7085 ;; Only do the xrefs if the group has the same
7086 ;; select method as the group we have just read.
7087 (or (gnus-methods-equal-p
7088 nth4 (gnus-find-method-for-group from-newsgroup))
7089 virtual
7090 (equal nth4
7091 (setq method (gnus-find-method-for-group
7092 from-newsgroup)))
7093 (and (equal (car nth4) (car method))
7094 (equal (nth 1 nth4) (nth 1 method))))
7095 gnus-use-cross-reference
7096 (or (not (eq gnus-use-cross-reference t))
7097 virtual
7098 ;; Only do cross-references on subscribed
7099 ;; groups, if that is what is wanted.
7100 (<= (nth 1 info) gnus-level-subscribed)))
7101 (gnus-group-make-articles-read name idlist expirable))))
7102 xref-hashtb)))))
7103
7104 (defun gnus-group-make-articles-read (group articles expirable)
7105 (let* ((num 0)
7106 (entry (gnus-gethash group gnus-newsrc-hashtb))
7107 (info (nth 2 entry))
7108 (active (gnus-gethash group gnus-active-hashtb))
7109 exps expirable range)
7110 ;; First peel off all illegal article numbers.
7111 (if active
7112 (let ((ids articles)
7113 (ticked (cdr (assq 'tick (nth 3 info))))
7114 (dormant (cdr (assq 'dormant (nth 3 info))))
7115 id first)
7116 (setq exps nil)
7117 (while ids
7118 (setq id (car ids))
7119 (if (and first (> id (cdr active)))
7120 (progn
7121 ;; We'll end up in this situation in one particular
7122 ;; obscure situation. If you re-scan a group and get
7123 ;; a new article that is cross-posted to a different
7124 ;; group that has not been re-scanned, you might get
7125 ;; crossposted article that has a higher number than
7126 ;; Gnus believes possible. So we re-activate this
7127 ;; group as well. This might mean doing the
7128 ;; crossposting thingy will *increase* the number
7129 ;; of articles in some groups. Tsk, tsk.
7130 (setq active (or (gnus-activate-group group) active))))
7131 (if (or (> id (cdr active))
7132 (< id (car active))
7133 (memq id ticked)
7134 (memq id dormant))
7135 (setq articles (delq id articles)))
7136 (and (memq id expirable)
7137 (setq exps (cons id exps)))
7138 (setq ids (cdr ids)))))
7139 ;; Update expirable articles.
7140 (gnus-add-marked-articles nil 'expirable exps info)
7141 (and active
7142 (null (nth 2 info))
7143 (> (car active) 1)
7144 (setcar (nthcdr 2 info) (cons 1 (1- (car active)))))
7145 (setcar (nthcdr 2 info)
7146 (setq range
7147 (gnus-add-to-range
7148 (nth 2 info)
7149 (setq articles (sort articles '<)))))
7150 ;; Then we have to re-compute how many unread
7151 ;; articles there are in this group.
7152 (if active
7153 (progn
7154 (cond
7155 ((not range)
7156 (setq num (- (1+ (cdr active)) (car active))))
7157 ((not (listp (cdr range)))
7158 (setq num (- (cdr active) (- (1+ (cdr range))
7159 (car range)))))
7160 (t
7161 (while range
7162 (if (numberp (car range))
7163 (setq num (1+ num))
7164 (setq num (+ num (- (1+ (cdr (car range)))
7165 (car (car range))))))
7166 (setq range (cdr range)))
7167 (setq num (- (cdr active) num))))
7168 ;; Update the number of unread articles.
7169 (setcar
7170 entry
7171 (max 0 (- num
7172 (length (cdr (assq 'tick (nth 3 info))))
7173 (length
7174 (cdr (assq 'dormant (nth 3 info)))))))
7175 ;; Update the group buffer.
7176 (gnus-group-update-group group t)))))
7177
7178 (defun gnus-methods-equal-p (m1 m2)
7179 (let ((m1 (or m1 gnus-select-method))
7180 (m2 (or m2 gnus-select-method)))
7181 (or (equal m1 m2)
7182 (and (eq (car m1) (car m2))
7183 (or (not (memq 'address (assoc (symbol-name (car m1))
7184 gnus-valid-select-methods)))
7185 (equal (nth 1 m1) (nth 1 m2)))))))
7186
7187 (defsubst gnus-header-value ()
7188 (buffer-substring (match-end 0) (gnus-point-at-eol)))
7189
7190 (defvar gnus-newsgroup-none-id 0)
7191
7192 (defun gnus-get-newsgroup-headers ()
7193 (setq gnus-article-internal-prepare-hook nil)
7194 (let ((cur nntp-server-buffer)
7195 (dependencies gnus-newsgroup-dependencies)
7196 headers id dep end ref)
7197 (save-excursion
7198 (set-buffer nntp-server-buffer)
7199 ;; Allow the user to mangle the headers before parsing them.
7200 (run-hooks 'gnus-parse-headers-hook)
7201 (goto-char (point-min))
7202 ;; Search to the beginning of the next header. Error messages
7203 ;; do not begin with 2 or 3.
7204 (while (re-search-forward "^[23][0-9]+ " nil t)
7205 (let ((header (make-vector 9 nil))
7206 (case-fold-search t)
7207 (p (point))
7208 in-reply-to)
7209 (setq id nil
7210 ref nil)
7211 (mail-header-set-number header (read cur))
7212 ;; This implementation of this function, with nine
7213 ;; search-forwards instead of the one re-search-forward and
7214 ;; a case (which basically was the old function) is actually
7215 ;; about twice as fast, even though it looks messier. You
7216 ;; can't have everything, I guess. Speed and elegance
7217 ;; doesn't always come hand in hand.
7218 (save-restriction
7219 (narrow-to-region (point) (or (save-excursion
7220 (search-forward "\n.\n" nil t))
7221 (point)))
7222 (if (search-forward "\nfrom: " nil t)
7223 (mail-header-set-from header (gnus-header-value))
7224 (mail-header-set-from header "(nobody)"))
7225 (goto-char p)
7226 (if (search-forward "\nsubject: " nil t)
7227 (mail-header-set-subject header (gnus-header-value))
7228 (mail-header-set-subject header "(none)"))
7229 (goto-char p)
7230 (and (search-forward "\nxref: " nil t)
7231 (mail-header-set-xref header (gnus-header-value)))
7232 (goto-char p)
7233 (or (numberp (and (search-forward "\nlines: " nil t)
7234 (mail-header-set-lines header (read cur))))
7235 (mail-header-set-lines header 0))
7236 (goto-char p)
7237 (and (search-forward "\ndate: " nil t)
7238 (mail-header-set-date header (gnus-header-value)))
7239 (goto-char p)
7240 (if (search-forward "\nmessage-id: " nil t)
7241 (mail-header-set-id header (setq id (gnus-header-value)))
7242 ;; If there was no message-id, we just fake one to make
7243 ;; subsequent routines simpler.
7244 (mail-header-set-id
7245 header
7246 (setq id (concat "none+"
7247 (int-to-string
7248 (setq gnus-newsgroup-none-id
7249 (1+ gnus-newsgroup-none-id)))))))
7250 (goto-char p)
7251 (if (search-forward "\nreferences: " nil t)
7252 (progn
7253 (mail-header-set-references header (gnus-header-value))
7254 (setq end (match-end 0))
7255 (save-excursion
7256 (setq ref
7257 (downcase
7258 (buffer-substring
7259 (progn
7260 (end-of-line)
7261 (search-backward ">" end t)
7262 (1+ (point)))
7263 (progn
7264 (search-backward "<" end t)
7265 (point)))))))
7266 ;; Get the references from the in-reply-to header if there
7267 ;; ware no references and the in-reply-to header looks
7268 ;; promising.
7269 (if (and (search-forward "\nin-reply-to: " nil t)
7270 (setq in-reply-to (gnus-header-value))
7271 (string-match "<[^>]+>" in-reply-to))
7272 (progn
7273 (mail-header-set-references
7274 header
7275 (setq ref (substring in-reply-to (match-beginning 0)
7276 (match-end 0))))
7277 (setq ref (downcase ref)))
7278 (setq ref "none")))
7279 ;; We do some threading while we read the headers. The
7280 ;; message-id and the last reference are both entered into
7281 ;; the same hash table. Some tippy-toeing around has to be
7282 ;; done in case an article has arrived before the article
7283 ;; which it refers to.
7284 (if (boundp (setq dep (intern (downcase id) dependencies)))
7285 (if (car (symbol-value dep))
7286 ;; An article with this Message-ID has already
7287 ;; been seen, so we ignore this one, except we add
7288 ;; any additional Xrefs (in case the two articles
7289 ;; came from different servers.
7290 (progn
7291 (mail-header-set-xref
7292 (car (symbol-value dep))
7293 (concat (or (mail-header-xref
7294 (car (symbol-value dep))) "")
7295 (or (mail-header-xref header) "")))
7296 (setq header nil))
7297 (setcar (symbol-value dep) header))
7298 (set dep (list header)))
7299 (if header
7300 (progn
7301 (if (boundp (setq dep (intern ref dependencies)))
7302 (setcdr (symbol-value dep)
7303 (cons header (cdr (symbol-value dep))))
7304 (set dep (list nil header)))
7305 (setq headers (cons header headers))))
7306 (goto-char (point-max))))))
7307 (nreverse headers)))
7308
7309 ;; The following macros and functions were written by Felix Lee
7310 ;; <flee@cse.psu.edu>.
7311
7312 (defmacro gnus-nov-read-integer ()
7313 '(prog1
7314 (if (= (following-char) ?\t)
7315 0
7316 (let ((num (condition-case nil (read buffer) (error nil))))
7317 (if (numberp num) num 0)))
7318 (or (eobp) (forward-char 1))))
7319
7320 (defmacro gnus-nov-skip-field ()
7321 '(search-forward "\t" eol 'move))
7322
7323 (defmacro gnus-nov-field ()
7324 '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
7325
7326 ;; Goes through the xover lines and returns a list of vectors
7327 (defun gnus-get-newsgroup-headers-xover (sequence)
7328 "Parse the news overview data in the server buffer, and return a
7329 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
7330 ;; Get the Xref when the users reads the articles since most/some
7331 ;; NNTP servers do not include Xrefs when using XOVER.
7332 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
7333 (let ((cur nntp-server-buffer)
7334 (dependencies gnus-newsgroup-dependencies)
7335 number headers header)
7336 (save-excursion
7337 (set-buffer nntp-server-buffer)
7338 ;; Allow the user to mangle the headers before parsing them.
7339 (run-hooks 'gnus-parse-headers-hook)
7340 (goto-char (point-min))
7341 (while (and sequence (not (eobp)))
7342 (setq number (read cur))
7343 (while (and sequence (< (car sequence) number))
7344 (setq sequence (cdr sequence)))
7345 (and sequence
7346 (eq number (car sequence))
7347 (progn
7348 (setq sequence (cdr sequence))
7349 (if (setq header
7350 (inline (gnus-nov-parse-line number dependencies)))
7351 (setq headers (cons header headers)))))
7352 (forward-line 1))
7353 (setq headers (nreverse headers)))
7354 headers))
7355
7356 ;; This function has to be called with point after the article number
7357 ;; on the beginning of the line.
7358 (defun gnus-nov-parse-line (number dependencies)
7359 (let ((none 0)
7360 (eol (gnus-point-at-eol))
7361 (buffer (current-buffer))
7362 header ref id dep)
7363
7364 ;; overview: [num subject from date id refs chars lines misc]
7365 (narrow-to-region (point) eol)
7366 (or (eobp) (forward-char))
7367
7368 (condition-case nil
7369 (setq header
7370 (vector
7371 number ; number
7372 (gnus-nov-field) ; subject
7373 (gnus-nov-field) ; from
7374 (gnus-nov-field) ; date
7375 (setq id (or (gnus-nov-field)
7376 (concat "none+"
7377 (int-to-string
7378 (setq none (1+ none)))))) ; id
7379 (progn
7380 (save-excursion
7381 (let ((beg (point)))
7382 (search-forward "\t" eol)
7383 (if (search-backward ">" beg t)
7384 (setq ref
7385 (downcase
7386 (buffer-substring
7387 (1+ (point))
7388 (progn
7389 (search-backward "<" beg t)
7390 (point)))))
7391 (setq ref nil))))
7392 (gnus-nov-field)) ; refs
7393 (gnus-nov-read-integer) ; chars
7394 (gnus-nov-read-integer) ; lines
7395 (if (= (following-char) ?\n)
7396 nil
7397 (gnus-nov-field)) ; misc
7398 ))
7399 (error (progn
7400 (ding)
7401 (message "Strange nov line.")
7402 (setq header nil)
7403 (goto-char eol))))
7404
7405 (widen)
7406
7407 ;; We build the thread tree.
7408 (and header
7409 (if (boundp (setq dep (intern (downcase id) dependencies)))
7410 (if (car (symbol-value dep))
7411 ;; An article with this Message-ID has already been seen,
7412 ;; so we ignore this one, except we add any additional
7413 ;; Xrefs (in case the two articles came from different
7414 ;; servers.
7415 (progn
7416 (mail-header-set-xref
7417 (car (symbol-value dep))
7418 (concat (or (mail-header-xref (car (symbol-value dep))) "")
7419 (or (mail-header-xref header) "")))
7420 (setq header nil))
7421 (setcar (symbol-value dep) header))
7422 (set dep (list header))))
7423 (if header
7424 (progn
7425 (if (boundp (setq dep (intern (or ref "none")
7426 dependencies)))
7427 (setcdr (symbol-value dep)
7428 (cons header (cdr (symbol-value dep))))
7429 (set dep (list nil header)))))
7430 header))
7431
7432 (defun gnus-article-get-xrefs ()
7433 "Fill in the Xref value in `gnus-current-headers', if necessary.
7434 This is meant to be called in `gnus-article-internal-prepare-hook'."
7435 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
7436 gnus-current-headers)))
7437 (or (not gnus-use-cross-reference)
7438 (not headers)
7439 (and (mail-header-xref headers)
7440 (not (string= (mail-header-xref headers) "")))
7441 (let ((case-fold-search t)
7442 xref)
7443 (save-restriction
7444 (gnus-narrow-to-headers)
7445 (goto-char (point-min))
7446 (if (or (and (eq (downcase (following-char)) ?x)
7447 (looking-at "Xref:"))
7448 (search-forward "\nXref:" nil t))
7449 (progn
7450 (goto-char (1+ (match-end 0)))
7451 (setq xref (buffer-substring (point)
7452 (progn (end-of-line) (point))))
7453 (mail-header-set-xref headers xref))))))))
7454
7455 (defalias 'gnus-find-header-by-number 'gnus-get-header-by-number)
7456 (make-obsolete 'gnus-find-header-by-number 'gnus-get-header-by-number)
7457
7458 (defun gnus-make-headers-hashtable-by-number ()
7459 "Make hashtable for the variable gnus-newsgroup-headers by number."
7460 (save-excursion
7461 (set-buffer gnus-summary-buffer)
7462 (let ((headers gnus-newsgroup-headers)
7463 header)
7464 (setq gnus-newsgroup-headers-hashtb-by-number
7465 (gnus-make-hashtable (length headers)))
7466 (while headers
7467 (setq header (car headers))
7468 (gnus-sethash (int-to-string (mail-header-number header))
7469 header gnus-newsgroup-headers-hashtb-by-number)
7470 (setq headers (cdr headers))))))
7471
7472 (defun gnus-more-header-backward ()
7473 "Find new header backward."
7474 (let ((first (car (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7475 (artnum gnus-newsgroup-begin)
7476 (header nil))
7477 (while (and (not header)
7478 (> artnum first))
7479 (setq artnum (1- artnum))
7480 (setq header (gnus-read-header artnum)))
7481 header))
7482
7483 (defun gnus-more-header-forward (&optional backward)
7484 "Find new header forward.
7485 If BACKWARD, find new header backward instead."
7486 (if backward
7487 (gnus-more-header-backward)
7488 (let ((last (cdr (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7489 (artnum gnus-newsgroup-end)
7490 (header nil))
7491 (while (and (not header)
7492 (< artnum last))
7493 (setq artnum (1+ artnum))
7494 (setq header (gnus-read-header artnum)))
7495 header)))
7496
7497 (defun gnus-extend-newsgroup (header &optional backward)
7498 "Extend newsgroup selection with HEADER.
7499 Optional argument BACKWARD means extend toward backward."
7500 (if header
7501 (let ((artnum (mail-header-number header)))
7502 (setq gnus-newsgroup-headers
7503 (if backward
7504 (cons header gnus-newsgroup-headers)
7505 (nconc gnus-newsgroup-headers (list header))))
7506 (setq gnus-newsgroup-unselected
7507 (delq artnum gnus-newsgroup-unselected))
7508 (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum))
7509 (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum)))))
7510
7511 (defun gnus-summary-work-articles (n)
7512 "Return a list of articles to be worked upon. The prefix argument,
7513 the list of process marked articles, and the current article will be
7514 taken into consideration."
7515 (let (articles)
7516 (if (and n (numberp n))
7517 (let ((backward (< n 0))
7518 (n (abs n)))
7519 (save-excursion
7520 (while (and (> n 0)
7521 (setq articles (cons (gnus-summary-article-number)
7522 articles))
7523 (gnus-summary-search-forward nil nil backward))
7524 (setq n (1- n))))
7525 (sort articles (function <)))
7526 (or (reverse gnus-newsgroup-processable)
7527 (list (gnus-summary-article-number))))))
7528
7529 (defun gnus-summary-search-group (&optional backward use-level)
7530 "Search for next unread newsgroup.
7531 If optional argument BACKWARD is non-nil, search backward instead."
7532 (save-excursion
7533 (set-buffer gnus-group-buffer)
7534 (if (gnus-group-search-forward
7535 backward nil (if use-level (gnus-group-group-level) nil))
7536 (gnus-group-group-name))))
7537
7538 (defun gnus-summary-best-group (&optional exclude-group)
7539 "Find the name of the best unread group.
7540 If EXCLUDE-GROUP, do not go to this group."
7541 (save-excursion
7542 (set-buffer gnus-group-buffer)
7543 (save-excursion
7544 (gnus-group-best-unread-group exclude-group))))
7545
7546 (defun gnus-subject-equal (s1 s2)
7547 (cond
7548 ((null gnus-summary-gather-subject-limit)
7549 (equal (gnus-simplify-subject-re s1)
7550 (gnus-simplify-subject-re s2)))
7551 ((eq gnus-summary-gather-subject-limit 'fuzzy)
7552 (equal (gnus-simplify-subject-fuzzy s1)
7553 (gnus-simplify-subject-fuzzy s2)))
7554 ((numberp gnus-summary-gather-subject-limit)
7555 (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit)
7556 (gnus-limit-string s2 gnus-summary-gather-subject-limit)))
7557 (t
7558 (equal s1 s2))))
7559
7560 (defun gnus-summary-search-subject (&optional backward unread subject)
7561 "Search for article forward.
7562 If BACKWARD is non-nil, search backward.
7563 If UNREAD is non-nil, only unread articles are selected.
7564 If SUBJECT is non-nil, the article which has the same subject will be
7565 searched for."
7566 (let ((func (if backward 'previous-single-property-change
7567 'next-single-property-change))
7568 (beg (point))
7569 (did t)
7570 pos psubject)
7571 (beginning-of-line)
7572 (and gnus-summary-check-current unread
7573 (eq (get-text-property (point) 'gnus-mark) gnus-unread-mark)
7574 (setq did nil))
7575 (if (not did)
7576 ()
7577 (forward-char (if backward (if (bobp) 0 -1) (if (eobp) 0 1)))
7578 (while
7579 (and
7580 (setq pos (funcall func (point) 'gnus-number))
7581 (goto-char (if backward (1- pos) pos))
7582 (setq did
7583 (not (and
7584 (or (not unread)
7585 (eq (get-text-property (point) 'gnus-mark)
7586 gnus-unread-mark))
7587 (or (not subject)
7588 (and (setq psubject
7589 (inline (gnus-summary-subject-string)))
7590 (inline
7591 (gnus-subject-equal subject psubject)))))))
7592 (if backward (if (bobp) nil (forward-char -1) t)
7593 (if (eobp) nil (forward-char 1) t)))))
7594 (if did
7595 (progn (goto-char beg) nil)
7596 (prog1
7597 (get-text-property (point) 'gnus-number)
7598 (gnus-summary-show-thread)
7599 (gnus-summary-position-cursor)))))
7600
7601 (defun gnus-summary-pseudo-article ()
7602 "The thread level of the article on the current line."
7603 (get-text-property (gnus-point-at-bol) 'gnus-pseudo))
7604
7605 (defalias 'gnus-summary-score 'gnus-summary-article-score)
7606 (make-obsolete 'gnus-summary-score 'gnus-summary-article-score)
7607 (defun gnus-summary-article-score ()
7608 "Return current article score."
7609 (or (cdr (assq (gnus-summary-article-number) gnus-newsgroup-scored))
7610 gnus-summary-default-score 0))
7611
7612 (defun gnus-summary-recenter ()
7613 "Center point in the summary window.
7614 If `gnus-auto-center-summary' is nil, or the article buffer isn't
7615 displayed, no centering will be performed."
7616 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
7617 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
7618 (let* ((top (cond ((< (window-height) 4) 0)
7619 ((< (window-height) 7) 1)
7620 (t 2)))
7621 (height (1- (window-height)))
7622 (bottom (save-excursion (goto-char (point-max))
7623 (forward-line (- height))
7624 (point)))
7625 (window (get-buffer-window (current-buffer))))
7626 (and
7627 ;; The user has to want it,
7628 gnus-auto-center-summary
7629 ;; the article buffer must be displayed,
7630 (get-buffer-window gnus-article-buffer)
7631 ;; Set the window start to either `bottom', which is the biggest
7632 ;; possible valid number, or the second line from the top,
7633 ;; whichever is the least.
7634 (set-window-start
7635 window (min bottom (save-excursion (forward-line (- top)) (point)))))))
7636
7637 ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
7638 (defun gnus-short-group-name (group &optional levels)
7639 "Collapse GROUP name LEVELS."
7640 (let* ((name "") (foreign "") (depth -1) (skip 1)
7641 (levels (or levels
7642 (progn
7643 (while (string-match "\\." group skip)
7644 (setq skip (match-end 0)
7645 depth (+ depth 1)))
7646 depth))))
7647 (if (string-match ":" group)
7648 (setq foreign (substring group 0 (match-end 0))
7649 group (substring group (match-end 0))))
7650 (while group
7651 (if (and (string-match "\\." group) (> levels 0))
7652 (setq name (concat name (substring group 0 1))
7653 group (substring group (match-end 0))
7654 levels (- levels 1)
7655 name (concat name "."))
7656 (setq name (concat foreign name group)
7657 group nil)))
7658 name))
7659
7660 (defun gnus-summary-jump-to-group (newsgroup)
7661 "Move point to NEWSGROUP in group mode buffer."
7662 ;; Keep update point of group mode buffer if visible.
7663 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
7664 (save-window-excursion
7665 ;; Take care of tree window mode.
7666 (if (get-buffer-window gnus-group-buffer)
7667 (pop-to-buffer gnus-group-buffer))
7668 (gnus-group-jump-to-group newsgroup))
7669 (save-excursion
7670 ;; Take care of tree window mode.
7671 (if (get-buffer-window gnus-group-buffer)
7672 (pop-to-buffer gnus-group-buffer)
7673 (set-buffer gnus-group-buffer))
7674 (gnus-group-jump-to-group newsgroup))))
7675
7676 ;; This function returns a list of article numbers based on the
7677 ;; difference between the ranges of read articles in this group and
7678 ;; the range of active articles.
7679 (defun gnus-list-of-unread-articles (group)
7680 (let* ((read (nth 2 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
7681 (active (gnus-gethash group gnus-active-hashtb))
7682 (last (cdr active))
7683 first nlast unread)
7684 ;; If none are read, then all are unread.
7685 (if (not read)
7686 (setq first (car active))
7687 ;; If the range of read articles is a single range, then the
7688 ;; first unread article is the article after the last read
7689 ;; article. Sounds logical, doesn't it?
7690 (if (not (listp (cdr read)))
7691 (setq first (1+ (cdr read)))
7692 ;; `read' is a list of ranges.
7693 (if (/= (setq nlast (or (and (numberp (car read)) (car read))
7694 (car (car read)))) 1)
7695 (setq first 1))
7696 (while read
7697 (if first
7698 (while (< first nlast)
7699 (setq unread (cons first unread))
7700 (setq first (1+ first))))
7701 (setq first (1+ (if (atom (car read)) (car read) (cdr (car read)))))
7702 (setq nlast (if (atom (car (cdr read)))
7703 (car (cdr read))
7704 (car (car (cdr read)))))
7705 (setq read (cdr read)))))
7706 ;; And add the last unread articles.
7707 (while (<= first last)
7708 (setq unread (cons first unread))
7709 (setq first (1+ first)))
7710 ;; Return the list of unread articles.
7711 (nreverse unread)))
7712
7713 (defun gnus-list-of-read-articles (group)
7714 (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
7715 (active (gnus-gethash group gnus-active-hashtb)))
7716 (and info active
7717 (gnus-sorted-complement
7718 (gnus-uncompress-range active)
7719 (gnus-list-of-unread-articles group)))))
7720
7721 ;; Various summary commands
7722
7723 (defun gnus-summary-universal-argument ()
7724 "Perform any operation on all articles marked with the process mark."
7725 (interactive)
7726 (gnus-set-global-variables)
7727 (let ((articles (reverse gnus-newsgroup-processable))
7728 func)
7729 (or articles (error "No articles marked"))
7730 (or (setq func (key-binding (read-key-sequence "C-c C-u")))
7731 (error "Undefined key"))
7732 (while articles
7733 (gnus-summary-goto-subject (car articles))
7734 (command-execute func)
7735 (gnus-summary-remove-process-mark (car articles))
7736 (setq articles (cdr articles)))))
7737
7738 (defun gnus-summary-toggle-truncation (&optional arg)
7739 "Toggle truncation of summary lines.
7740 With arg, turn line truncation on iff arg is positive."
7741 (interactive "P")
7742 (setq truncate-lines
7743 (if (null arg) (not truncate-lines)
7744 (> (prefix-numeric-value arg) 0)))
7745 (redraw-display))
7746
7747 (defun gnus-summary-reselect-current-group (&optional all)
7748 "Once exit and then reselect the current newsgroup.
7749 The prefix argument ALL means to select all articles."
7750 (interactive "P")
7751 (gnus-set-global-variables)
7752 (let ((current-subject (gnus-summary-article-number))
7753 (group gnus-newsgroup-name))
7754 (setq gnus-newsgroup-begin nil)
7755 (gnus-summary-exit t)
7756 ;; We have to adjust the point of group mode buffer because the
7757 ;; current point was moved to the next unread newsgroup by
7758 ;; exiting.
7759 (gnus-summary-jump-to-group group)
7760 (gnus-group-read-group all t)
7761 (gnus-summary-goto-subject current-subject)))
7762
7763 (defun gnus-summary-rescan-group (&optional all)
7764 "Exit the newsgroup, ask for new articles, and select the newsgroup."
7765 (interactive "P")
7766 (gnus-set-global-variables)
7767 ;; Fix by Ilja Weis <kult@uni-paderborn.de>.
7768 (let ((group gnus-newsgroup-name))
7769 (gnus-summary-exit)
7770 (gnus-summary-jump-to-group group)
7771 (save-excursion
7772 (set-buffer gnus-group-buffer)
7773 (gnus-group-get-new-news-this-group 1))
7774 (gnus-summary-jump-to-group group)
7775 (gnus-group-read-group all)))
7776
7777 (defun gnus-summary-update-info ()
7778 (let* ((group gnus-newsgroup-name))
7779 (if gnus-newsgroup-kill-headers
7780 (setq gnus-newsgroup-killed
7781 (gnus-compress-sequence
7782 (nconc
7783 (gnus-set-sorted-intersection
7784 (gnus-uncompress-range gnus-newsgroup-killed)
7785 (setq gnus-newsgroup-unselected
7786 (sort gnus-newsgroup-unselected '<)))
7787 (setq gnus-newsgroup-unreads
7788 (sort gnus-newsgroup-unreads '<))) t)))
7789 (or (listp (cdr gnus-newsgroup-killed))
7790 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7791 (let ((headers gnus-newsgroup-headers))
7792 (gnus-close-group group)
7793 (run-hooks 'gnus-exit-group-hook)
7794 (gnus-update-read-articles
7795 group gnus-newsgroup-unreads gnus-newsgroup-unselected
7796 gnus-newsgroup-marked
7797 t gnus-newsgroup-replied gnus-newsgroup-expirable
7798 gnus-newsgroup-killed gnus-newsgroup-dormant
7799 gnus-newsgroup-bookmarks
7800 (and gnus-save-score gnus-newsgroup-scored))
7801 (and gnus-use-cross-reference
7802 (gnus-mark-xrefs-as-read
7803 group headers gnus-newsgroup-unreads gnus-newsgroup-expirable))
7804 ;; Do adaptive scoring, and possibly save score files.
7805 (and gnus-newsgroup-adaptive
7806 (gnus-score-adaptive))
7807 (and gnus-use-scoring
7808 (fboundp 'gnus-score-save)
7809 (funcall 'gnus-score-save))
7810 ;; Do not switch windows but change the buffer to work.
7811 (set-buffer gnus-group-buffer)
7812 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
7813 (gnus-group-update-group group)))))
7814
7815 (defun gnus-summary-exit (&optional temporary)
7816 "Exit reading current newsgroup, and then return to group selection mode.
7817 gnus-exit-group-hook is called with no arguments if that value is non-nil."
7818 (interactive)
7819 (gnus-set-global-variables)
7820 (gnus-kill-save-kill-buffer)
7821 (let* ((group gnus-newsgroup-name)
7822 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7823 (mode major-mode)
7824 (buf (current-buffer)))
7825 (run-hooks 'gnus-summary-prepare-exit-hook)
7826 ;; Make all changes in this group permanent.
7827 (gnus-summary-update-info)
7828 (set-buffer buf)
7829 (and gnus-use-cache (gnus-cache-possibly-remove-articles))
7830 ;; Make sure where I was, and go to next newsgroup.
7831 (set-buffer gnus-group-buffer)
7832 (or quit-config
7833 (progn
7834 (gnus-group-jump-to-group group)
7835 (gnus-group-next-unread-group 1)))
7836 (if temporary
7837 nil ;Nothing to do.
7838 ;; We set all buffer-local variables to nil. It is unclear why
7839 ;; this is needed, but if we don't, buffer-local variables are
7840 ;; not garbage-collected, it seems. This would the lead to en
7841 ;; ever-growing Emacs.
7842 (set-buffer buf)
7843 (gnus-summary-clear-local-variables)
7844 ;; We clear the global counterparts of the buffer-local
7845 ;; variables as well, just to be on the safe side.
7846 (gnus-configure-windows 'group 'force)
7847 (gnus-summary-clear-local-variables)
7848 ;; Return to group mode buffer.
7849 (if (eq mode 'gnus-summary-mode)
7850 (gnus-kill-buffer buf))
7851 (if (get-buffer gnus-article-buffer)
7852 (bury-buffer gnus-article-buffer))
7853 (setq gnus-current-select-method gnus-select-method)
7854 (pop-to-buffer gnus-group-buffer)
7855 (if (not quit-config)
7856 (progn
7857 (gnus-group-jump-to-group group)
7858 (gnus-group-next-unread-group 1))
7859 (if (not (buffer-name (car quit-config)))
7860 (gnus-configure-windows 'group 'force)
7861 (set-buffer (car quit-config))
7862 (and (eq major-mode 'gnus-summary-mode)
7863 (gnus-set-global-variables))
7864 (gnus-configure-windows (cdr quit-config))))
7865 (run-hooks 'gnus-summary-exit-hook))))
7866
7867 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7868 (defun gnus-summary-exit-no-update (&optional no-questions)
7869 "Quit reading current newsgroup without updating read article info."
7870 (interactive)
7871 (gnus-set-global-variables)
7872 (let* ((group gnus-newsgroup-name)
7873 (quit-config (gnus-group-quit-config group)))
7874 (if (or no-questions
7875 gnus-expert-user
7876 (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
7877 (progn
7878 (gnus-close-group group)
7879 (gnus-summary-clear-local-variables)
7880 (set-buffer gnus-group-buffer)
7881 (gnus-summary-clear-local-variables)
7882 ;; Return to group selection mode.
7883 (gnus-configure-windows 'group 'force)
7884 (if (get-buffer gnus-summary-buffer)
7885 (kill-buffer gnus-summary-buffer))
7886 (if (get-buffer gnus-article-buffer)
7887 (bury-buffer gnus-article-buffer))
7888 (if (equal (gnus-group-group-name) group)
7889 (gnus-group-next-unread-group 1))
7890 (if quit-config
7891 (progn
7892 (if (not (buffer-name (car quit-config)))
7893 (gnus-configure-windows 'group 'force)
7894 (set-buffer (car quit-config))
7895 (and (eq major-mode 'gnus-summary-mode)
7896 (gnus-set-global-variables))
7897 (gnus-configure-windows (cdr quit-config)))))))))
7898
7899 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7900 (defun gnus-summary-fetch-faq (group)
7901 "Fetch the FAQ for the current group."
7902 (interactive (list gnus-newsgroup-name))
7903 (let (gnus-faq-buffer)
7904 (and (setq gnus-faq-buffer (gnus-group-fetch-faq group))
7905 (gnus-configure-windows 'summary-faq))))
7906
7907 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7908 (defun gnus-summary-describe-group (&optional force)
7909 "Describe the current newsgroup."
7910 (interactive "P")
7911 (gnus-group-describe-group force gnus-newsgroup-name))
7912
7913 (defun gnus-summary-describe-briefly ()
7914 "Describe summary mode commands briefly."
7915 (interactive)
7916 (gnus-message 6
7917 (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")))
7918
7919 ;; Walking around group mode buffer from summary mode.
7920
7921 (defun gnus-summary-next-group (&optional no-article target-group backward)
7922 "Exit current newsgroup and then select next unread newsgroup.
7923 If prefix argument NO-ARTICLE is non-nil, no article is selected
7924 initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
7925 previous group instead."
7926 (interactive "P")
7927 (gnus-set-global-variables)
7928 (let ((current-group gnus-newsgroup-name)
7929 (current-buffer (current-buffer))
7930 entered)
7931 ;; First we semi-exit this group to update Xrefs and all variables.
7932 ;; We can't do a real exit, because the window conf must remain
7933 ;; the same in case the user is prompted for info, and we don't
7934 ;; want the window conf to change before that...
7935 (gnus-summary-exit t)
7936 (while (not entered)
7937 ;; Then we find what group we are supposed to enter.
7938 (set-buffer gnus-group-buffer)
7939 (gnus-group-jump-to-group current-group)
7940 (setq target-group
7941 (or target-group
7942 (if (eq gnus-keep-same-level 'best)
7943 (gnus-summary-best-group gnus-newsgroup-name)
7944 (gnus-summary-search-group backward gnus-keep-same-level))))
7945 (if (not target-group)
7946 ;; There are no further groups, so we return to the group
7947 ;; buffer.
7948 (progn
7949 (gnus-message 5 "Returning to the group buffer")
7950 (setq entered t)
7951 (set-buffer current-buffer)
7952 (gnus-summary-exit))
7953 ;; We try to enter the target group.
7954 (gnus-group-jump-to-group target-group)
7955 (let ((unreads (gnus-group-group-unread)))
7956 (if (and (or (eq t unreads)
7957 (and unreads (not (zerop unreads))))
7958 (gnus-summary-read-group
7959 target-group nil no-article current-buffer))
7960 (setq entered t)
7961 (setq current-group target-group
7962 target-group nil)))))))
7963
7964 (defun gnus-summary-next-group-old (&optional no-article group backward)
7965 "Exit current newsgroup and then select next unread newsgroup.
7966 If prefix argument NO-ARTICLE is non-nil, no article is selected initially.
7967 If BACKWARD, go to previous group instead."
7968 (interactive "P")
7969 (gnus-set-global-variables)
7970 (let ((ingroup gnus-newsgroup-name)
7971 (sumbuf (current-buffer))
7972 num)
7973 (set-buffer gnus-group-buffer)
7974 (if (and group
7975 (or (and (numberp (setq num (car (gnus-gethash
7976 group gnus-newsrc-hashtb))))
7977 (< num 1))
7978 (null num)))
7979 (progn
7980 (gnus-group-jump-to-group group)
7981 (setq group nil))
7982 (gnus-group-jump-to-group ingroup))
7983 (gnus-summary-search-group backward)
7984 (let ((group (or group (gnus-summary-search-group backward))))
7985 (set-buffer sumbuf)
7986 (gnus-summary-exit t) ;Update all information.
7987 (if (null group)
7988 (gnus-summary-exit-no-update t)
7989 (gnus-group-jump-to-group ingroup)
7990 (setq group (gnus-summary-search-group backward))
7991 (gnus-message 5 "Selecting %s..." group)
7992 (set-buffer gnus-group-buffer)
7993 ;; We are now in group mode buffer.
7994 ;; Make sure group mode buffer point is on GROUP.
7995 (gnus-group-jump-to-group group)
7996 (if (not (eq gnus-auto-select-next 'quietly))
7997 (progn
7998 (gnus-summary-read-group group nil no-article sumbuf)
7999 (and (string= gnus-newsgroup-name ingroup)
8000 (bufferp sumbuf) (buffer-name sumbuf)
8001 (progn
8002 (set-buffer (setq gnus-summary-buffer sumbuf))
8003 (gnus-summary-exit-no-update t))))
8004 (let ((prevgroup group))
8005 (gnus-group-jump-to-group ingroup)
8006 (setq group (gnus-summary-search-group backward))
8007 (gnus-summary-read-group group nil no-article sumbuf)
8008 (while (and (string= gnus-newsgroup-name ingroup)
8009 (bufferp sumbuf)
8010 (buffer-name sumbuf)
8011 (not (string= prevgroup (gnus-group-group-name))))
8012 (set-buffer gnus-group-buffer)
8013 (gnus-summary-read-group
8014 (setq prevgroup (gnus-group-group-name))
8015 nil no-article sumbuf))
8016 (and (string= prevgroup (gnus-group-group-name))
8017 ;; We have reached the final group in the group
8018 ;; buffer.
8019 (progn
8020 (if (buffer-name sumbuf)
8021 (progn
8022 (set-buffer sumbuf)
8023 (gnus-summary-exit)))))))))))
8024
8025 (defun gnus-summary-prev-group (&optional no-article)
8026 "Exit current newsgroup and then select previous unread newsgroup.
8027 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
8028 (interactive "P")
8029 (gnus-summary-next-group no-article nil t))
8030
8031 ;; Walking around summary lines.
8032
8033 (defun gnus-summary-first-subject (&optional unread)
8034 "Go to the first unread subject.
8035 If UNREAD is non-nil, go to the first unread article.
8036 Returns nil if there are no unread articles."
8037 (interactive "P")
8038 (prog1
8039 (cond ((not unread)
8040 (goto-char (point-min)))
8041 ((gnus-goto-char
8042 (text-property-any
8043 (point-min) (point-max) 'gnus-mark gnus-unread-mark))
8044 t)
8045 (t
8046 ;; There are no unread articles.
8047 (gnus-message 3 "No more unread articles")
8048 nil))
8049 (gnus-summary-position-cursor)))
8050
8051 (defun gnus-summary-next-subject (n &optional unread dont-display)
8052 "Go to next N'th summary line.
8053 If N is negative, go to the previous N'th subject line.
8054 If UNREAD is non-nil, only unread articles are selected.
8055 The difference between N and the actual number of steps taken is
8056 returned."
8057 (interactive "p")
8058 (let ((backward (< n 0))
8059 (n (abs n)))
8060 (while (and (> n 0)
8061 (gnus-summary-search-forward unread nil backward))
8062 (setq n (1- n)))
8063 (if (/= 0 n) (gnus-message 7 "No more%s articles"
8064 (if unread " unread" "")))
8065 (or dont-display
8066 (progn
8067 (gnus-summary-recenter)
8068 (gnus-summary-position-cursor)))
8069 n))
8070
8071 (defun gnus-summary-next-unread-subject (n)
8072 "Go to next N'th unread summary line."
8073 (interactive "p")
8074 (gnus-summary-next-subject n t))
8075
8076 (defun gnus-summary-prev-subject (n &optional unread)
8077 "Go to previous N'th summary line.
8078 If optional argument UNREAD is non-nil, only unread article is selected."
8079 (interactive "p")
8080 (gnus-summary-next-subject (- n) unread))
8081
8082 (defun gnus-summary-prev-unread-subject (n)
8083 "Go to previous N'th unread summary line."
8084 (interactive "p")
8085 (gnus-summary-next-subject (- n) t))
8086
8087 (defun gnus-summary-goto-subject (article)
8088 "Go the subject line of ARTICLE."
8089 (interactive
8090 (list
8091 (string-to-int
8092 (completing-read "Article number: "
8093 (mapcar
8094 (lambda (headers)
8095 (list
8096 (int-to-string (mail-header-number headers))))
8097 gnus-newsgroup-headers)
8098 nil 'require-match))))
8099 (or article (error "No article number"))
8100 (let ((b (point)))
8101 (if (not (gnus-goto-char (text-property-any (point-min) (point-max)
8102 'gnus-number article)))
8103 ()
8104 (gnus-summary-show-thread)
8105 ;; Skip dummy articles.
8106 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8107 (forward-line 1))
8108 (prog1
8109 (if (not (eobp))
8110 article
8111 (goto-char b)
8112 nil)
8113 (gnus-summary-position-cursor)))))
8114
8115 ;; Walking around summary lines with displaying articles.
8116
8117 (defun gnus-summary-expand-window (&optional arg)
8118 "Make the summary buffer take up the entire Emacs frame.
8119 Given a prefix, will force an `article' buffer configuration."
8120 (interactive "P")
8121 (gnus-set-global-variables)
8122 (if arg
8123 (gnus-configure-windows 'article 'force)
8124 (gnus-configure-windows 'summary 'force)))
8125
8126 (defun gnus-summary-display-article (article &optional all-header)
8127 "Display ARTICLE in article buffer."
8128 (gnus-set-global-variables)
8129 (if (null article)
8130 nil
8131 (prog1
8132 (gnus-article-prepare article all-header)
8133 (gnus-summary-show-thread)
8134 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8135 (progn
8136 (forward-line 1)
8137 (gnus-summary-position-cursor)))
8138 (run-hooks 'gnus-select-article-hook)
8139 (gnus-summary-recenter)
8140 (gnus-summary-goto-subject article)
8141 ;; Successfully display article.
8142 (gnus-summary-update-line)
8143 (gnus-article-set-window-start
8144 (cdr (assq article gnus-newsgroup-bookmarks)))
8145 t)))
8146
8147 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
8148 "Select the current article.
8149 If ALL-HEADERS is non-nil, show all header fields. If FORCE is
8150 non-nil, the article will be re-fetched even if it already present in
8151 the article buffer. If PSEUDO is non-nil, pseudo-articles will also
8152 be displayed."
8153 (and (not pseudo) (gnus-summary-pseudo-article)
8154 (error "This is a pseudo-article."))
8155 (let ((article (or article (gnus-summary-article-number)))
8156 (all-headers (not (not all-headers))) ;Must be T or NIL.
8157 did)
8158 (prog1
8159 (save-excursion
8160 (set-buffer gnus-summary-buffer)
8161 (if (or (null gnus-current-article)
8162 (null gnus-article-current)
8163 (null (get-buffer gnus-article-buffer))
8164 (not (eq article (cdr gnus-article-current)))
8165 (not (equal (car gnus-article-current) gnus-newsgroup-name))
8166 force)
8167 ;; The requested article is different from the current article.
8168 (progn
8169 (gnus-summary-display-article article all-headers)
8170 (setq did article))
8171 (if (or all-headers gnus-show-all-headers)
8172 (gnus-article-show-all-headers))
8173 nil))
8174 (if did
8175 (gnus-article-set-window-start
8176 (cdr (assq article gnus-newsgroup-bookmarks)))))))
8177
8178 (defun gnus-summary-set-current-mark (&optional current-mark)
8179 "Obsolete function."
8180 nil)
8181
8182 (defun gnus-summary-next-article (&optional unread subject backward)
8183 "Select the next article.
8184 If UNREAD, only unread articles are selected.
8185 If SUBJECT, only articles with SUBJECT are selected.
8186 If BACKWARD, the previous article is selected instead of the next."
8187 (interactive "P")
8188 (gnus-set-global-variables)
8189 (let (header)
8190 (cond
8191 ;; Is there such an article?
8192 ((and (gnus-summary-search-forward unread subject backward)
8193 (or (gnus-summary-display-article (gnus-summary-article-number))
8194 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8195 (gnus-summary-position-cursor))
8196 ;; If not, we try the first unread, if that is wanted.
8197 ((and subject
8198 gnus-auto-select-same
8199 (or (gnus-summary-first-unread-article)
8200 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8201 (gnus-summary-position-cursor)
8202 (gnus-message 6 "Wrapped"))
8203 ;; Try to get next/previous article not displayed in this group.
8204 ((and gnus-auto-extend-newsgroup
8205 (not unread) (not subject)
8206 (setq header (gnus-more-header-forward backward)))
8207 (gnus-extend-newsgroup header backward)
8208 (let ((buffer-read-only nil))
8209 (goto-char (if backward (point-min) (point-max)))
8210 (gnus-summary-prepare-threads (list header)))
8211 (gnus-summary-goto-article (if backward gnus-newsgroup-begin
8212 gnus-newsgroup-end)))
8213 ;; Go to next/previous group.
8214 (t
8215 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
8216 (gnus-summary-jump-to-group gnus-newsgroup-name))
8217 (let ((cmd last-command-char)
8218 (group
8219 (if (eq gnus-keep-same-level 'best)
8220 (gnus-summary-best-group gnus-newsgroup-name)
8221 (gnus-summary-search-group backward gnus-keep-same-level))))
8222 ;; For some reason, the group window gets selected. We change
8223 ;; it back.
8224 (select-window (get-buffer-window (current-buffer)))
8225 ;; Keep just the event type of CMD.
8226 ;(and (listp cmd) (setq cmd (car cmd)))
8227 ;; Select next unread newsgroup automagically.
8228 (cond
8229 ((not gnus-auto-select-next)
8230 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
8231 ((eq gnus-auto-select-next 'quietly)
8232 ;; Select quietly.
8233 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
8234 (gnus-summary-exit)
8235 (gnus-message 7 "No more%s articles (%s)..."
8236 (if unread " unread" "")
8237 (if group (concat "selecting " group)
8238 "exiting"))
8239 (gnus-summary-next-group nil group backward)))
8240 (t
8241 (let ((keystrokes '(?\C-n ?\C-p))
8242 key)
8243 (while (or (null key) (memq key keystrokes))
8244 (gnus-message
8245 7 "No more%s articles%s" (if unread " unread" "")
8246 (if (and group
8247 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
8248 (format " (Type %s for %s [%s])"
8249 (single-key-description cmd) group
8250 (car (gnus-gethash group gnus-newsrc-hashtb)))
8251 (format " (Type %s to exit %s)"
8252 (single-key-description cmd)
8253 gnus-newsgroup-name)))
8254 ;; Confirm auto selection.
8255 (let* ((event (read-char)))
8256 (setq key (if (listp event) (car event) event))
8257 (if (memq key keystrokes)
8258 (let ((obuf (current-buffer)))
8259 (switch-to-buffer gnus-group-buffer)
8260 (and group
8261 (gnus-group-jump-to-group group))
8262 (condition-case ()
8263 (execute-kbd-macro (char-to-string key))
8264 (error (ding) nil))
8265 (setq group (gnus-group-group-name))
8266 (switch-to-buffer obuf)))))
8267 (if (equal key cmd)
8268 (if (or (not group)
8269 (gnus-ephemeral-group-p gnus-newsgroup-name))
8270 (gnus-summary-exit)
8271 (gnus-summary-next-group nil group backward))
8272 (execute-kbd-macro (char-to-string key)))))))))))
8273
8274 (defun gnus-summary-next-unread-article ()
8275 "Select unread article after current one."
8276 (interactive)
8277 (gnus-summary-next-article t (and gnus-auto-select-same
8278 (gnus-summary-subject-string))))
8279
8280 (defun gnus-summary-prev-article (&optional unread subject)
8281 "Select the article after the current one.
8282 If UNREAD is non-nil, only unread articles are selected."
8283 (interactive "P")
8284 (gnus-summary-next-article unread subject t))
8285
8286 (defun gnus-summary-prev-unread-article ()
8287 "Select unred article before current one."
8288 (interactive)
8289 (gnus-summary-prev-article t (and gnus-auto-select-same
8290 (gnus-summary-subject-string))))
8291
8292 (defun gnus-summary-next-page (&optional lines circular)
8293 "Show next page of selected article.
8294 If end of article, select next article.
8295 Argument LINES specifies lines to be scrolled up.
8296 If CIRCULAR is non-nil, go to the start of the article instead of
8297 instead of selecting the next article when reaching the end of the
8298 current article."
8299 (interactive "P")
8300 (setq gnus-summary-buffer (current-buffer))
8301 (gnus-set-global-variables)
8302 (let ((article (gnus-summary-article-number))
8303 (endp nil))
8304 (gnus-configure-windows 'article)
8305 (if (or (null gnus-current-article)
8306 (null gnus-article-current)
8307 (/= article (cdr gnus-article-current))
8308 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8309 ;; Selected subject is different from current article's.
8310 (gnus-summary-display-article article)
8311 (gnus-eval-in-buffer-window
8312 gnus-article-buffer
8313 (setq endp (gnus-article-next-page lines)))
8314 (if endp
8315 (cond (circular
8316 (gnus-summary-beginning-of-article))
8317 (lines
8318 (gnus-message 3 "End of message"))
8319 ((null lines)
8320 (gnus-summary-next-unread-article)))))
8321 (gnus-summary-recenter)
8322 (gnus-summary-position-cursor)))
8323
8324 (defun gnus-summary-prev-page (&optional lines)
8325 "Show previous page of selected article.
8326 Argument LINES specifies lines to be scrolled down."
8327 (interactive "P")
8328 (gnus-set-global-variables)
8329 (let ((article (gnus-summary-article-number)))
8330 (gnus-configure-windows 'article)
8331 (if (or (null gnus-current-article)
8332 (null gnus-article-current)
8333 (/= article (cdr gnus-article-current))
8334 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8335 ;; Selected subject is different from current article's.
8336 (gnus-summary-display-article article)
8337 (gnus-summary-recenter)
8338 (gnus-eval-in-buffer-window gnus-article-buffer
8339 (gnus-article-prev-page lines))))
8340 (gnus-summary-position-cursor))
8341
8342 (defun gnus-summary-scroll-up (lines)
8343 "Scroll up (or down) one line current article.
8344 Argument LINES specifies lines to be scrolled up (or down if negative)."
8345 (interactive "p")
8346 (gnus-set-global-variables)
8347 (gnus-configure-windows 'article)
8348 (or (gnus-summary-select-article nil nil 'pseudo)
8349 (gnus-eval-in-buffer-window
8350 gnus-article-buffer
8351 (cond ((> lines 0)
8352 (if (gnus-article-next-page lines)
8353 (gnus-message 3 "End of message")))
8354 ((< lines 0)
8355 (gnus-article-prev-page (- lines))))))
8356 (gnus-summary-recenter)
8357 (gnus-summary-position-cursor))
8358
8359 (defun gnus-summary-next-same-subject ()
8360 "Select next article which has the same subject as current one."
8361 (interactive)
8362 (gnus-set-global-variables)
8363 (gnus-summary-next-article nil (gnus-summary-subject-string)))
8364
8365 (defun gnus-summary-prev-same-subject ()
8366 "Select previous article which has the same subject as current one."
8367 (interactive)
8368 (gnus-set-global-variables)
8369 (gnus-summary-prev-article nil (gnus-summary-subject-string)))
8370
8371 (defun gnus-summary-next-unread-same-subject ()
8372 "Select next unread article which has the same subject as current one."
8373 (interactive)
8374 (gnus-set-global-variables)
8375 (gnus-summary-next-article t (gnus-summary-subject-string)))
8376
8377 (defun gnus-summary-prev-unread-same-subject ()
8378 "Select previous unread article which has the same subject as current one."
8379 (interactive)
8380 (gnus-set-global-variables)
8381 (gnus-summary-prev-article t (gnus-summary-subject-string)))
8382
8383 (defun gnus-summary-first-unread-article ()
8384 "Select the first unread article.
8385 Return nil if there are no unread articles."
8386 (interactive)
8387 (gnus-set-global-variables)
8388 (prog1
8389 (if (gnus-summary-first-subject t)
8390 (progn
8391 (gnus-summary-show-thread)
8392 (gnus-summary-first-subject t)
8393 (gnus-summary-display-article (gnus-summary-article-number))))
8394 (gnus-summary-position-cursor)))
8395
8396 (defun gnus-summary-best-unread-article ()
8397 "Select the unread article with the highest score."
8398 (interactive)
8399 (gnus-set-global-variables)
8400 (let ((best -1000000)
8401 article score)
8402 (save-excursion
8403 (or (gnus-summary-first-subject t)
8404 (error "No unread articles"))
8405 (while
8406 (and
8407 (progn
8408 (and (> (setq score (gnus-summary-article-score)) best)
8409 (setq best score
8410 article (gnus-summary-article-number)))
8411 t)
8412 (gnus-summary-search-subject nil t))))
8413 (if (not article)
8414 (error "No unread articles")
8415 (gnus-summary-goto-article article))
8416 (gnus-summary-position-cursor)))
8417
8418 (defun gnus-summary-goto-article (article &optional all-headers)
8419 "Fetch ARTICLE and display it if it exists.
8420 If ALL-HEADERS is non-nil, no header lines are hidden."
8421 (interactive
8422 (list
8423 (string-to-int
8424 (completing-read
8425 "Article number: "
8426 (mapcar (lambda (headers)
8427 (list (int-to-string (mail-header-number headers))))
8428 gnus-newsgroup-headers)
8429 nil 'require-match))))
8430 (prog1
8431 (and (gnus-summary-goto-subject article)
8432 (gnus-summary-display-article article all-headers))
8433 (gnus-summary-position-cursor)))
8434
8435 (defun gnus-summary-goto-last-article ()
8436 "Go to the previously read article."
8437 (interactive)
8438 (prog1
8439 (and gnus-last-article
8440 (gnus-summary-goto-article gnus-last-article))
8441 (gnus-summary-position-cursor)))
8442
8443 (defun gnus-summary-pop-article (number)
8444 "Pop one article off the history and go to the previous.
8445 NUMBER articles will be popped off."
8446 (interactive "p")
8447 (let (to)
8448 (setq gnus-newsgroup-history
8449 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8450 (if to
8451 (gnus-summary-goto-article (car to))
8452 (error "Article history empty")))
8453 (gnus-summary-position-cursor))
8454
8455 ;; Summary article oriented commands
8456
8457 (defun gnus-summary-refer-parent-article (n)
8458 "Refer parent article N times.
8459 The difference between N and the number of articles fetched is returned."
8460 (interactive "p")
8461 (gnus-set-global-variables)
8462 (while
8463 (and
8464 (> n 0)
8465 (let ((ref (mail-header-references (gnus-get-header-by-num
8466 (gnus-summary-article-number)))))
8467 (if (and ref (not (equal ref ""))
8468 (string-match "<[^<>]*>[ \t]*$" ref))
8469 (gnus-summary-refer-article
8470 (substring ref (match-beginning 0) (match-end 0)))
8471 (gnus-message 1 "No references in article %d"
8472 (gnus-summary-article-number))
8473 nil)))
8474 (setq n (1- n)))
8475 (gnus-summary-position-cursor)
8476 n)
8477
8478 (defun gnus-summary-refer-article (message-id)
8479 "Refer article specified by MESSAGE-ID.
8480 NOTE: This command only works with newsgroups that use real or simulated NNTP."
8481 (interactive "sMessage-ID: ")
8482 (if (or (not (stringp message-id))
8483 (zerop (length message-id)))
8484 ()
8485 ;; Construct the correct Message-ID if necessary.
8486 ;; Suggested by tale@pawl.rpi.edu.
8487 (or (string-match "^<" message-id)
8488 (setq message-id (concat "<" message-id)))
8489 (or (string-match ">$" message-id)
8490 (setq message-id (concat message-id ">")))
8491 (let ((header (car (gnus-gethash (downcase message-id)
8492 gnus-newsgroup-dependencies))))
8493 (if header
8494 (or (gnus-summary-goto-article (mail-header-number header))
8495 ;; The header has been read, but the article had been
8496 ;; expunged, so we insert it again.
8497 (progn
8498 (gnus-summary-insert-line
8499 nil header 0 nil gnus-read-mark nil nil
8500 (mail-header-subject header))
8501 (forward-line -1)
8502 (mail-header-number header)))
8503 (let ((gnus-override-method gnus-refer-article-method)
8504 (gnus-ancient-mark gnus-read-mark)
8505 (tmp-point (window-start
8506 (get-buffer-window gnus-article-buffer)))
8507 number tmp-buf)
8508 (and gnus-refer-article-method
8509 (gnus-check-server gnus-refer-article-method))
8510 ;; Save the old article buffer.
8511 (save-excursion
8512 (set-buffer (gnus-article-setup-buffer))
8513 (gnus-kill-buffer " *temp Article*")
8514 (setq tmp-buf (rename-buffer " *temp Article*")))
8515 (prog1
8516 (if (gnus-article-prepare
8517 message-id nil (gnus-read-header message-id))
8518 (progn
8519 (setq number (mail-header-number gnus-current-headers))
8520 (gnus-rebuild-thread message-id)
8521 (gnus-summary-goto-subject number)
8522 (if (null gnus-use-full-window)
8523 (progn
8524 (delete-windows-on tmp-buf)
8525 (gnus-configure-windows 'article 'force)))
8526 (gnus-summary-recenter)
8527 (gnus-article-set-window-start
8528 (cdr (assq number gnus-newsgroup-bookmarks)))
8529 (and gnus-visual
8530 (run-hooks 'gnus-visual-mark-article-hook))
8531 message-id)
8532 ;; We restore the old article buffer.
8533 (save-excursion
8534 (kill-buffer gnus-article-buffer)
8535 (set-buffer tmp-buf)
8536 (rename-buffer gnus-article-buffer)
8537 (let ((buffer-read-only nil))
8538 (and tmp-point
8539 (set-window-start (get-buffer-window (current-buffer))
8540 tmp-point)))))))))))
8541
8542 (defun gnus-summary-enter-digest-group ()
8543 "Enter a digest group based on the current article."
8544 (interactive)
8545 (gnus-set-global-variables)
8546 (gnus-summary-select-article)
8547 ;; We do not want a narrowed article.
8548 (gnus-summary-stop-page-breaking)
8549 (let ((name (format "%s-%d"
8550 (gnus-group-prefixed-name
8551 gnus-newsgroup-name (list 'nndoc ""))
8552 gnus-current-article))
8553 (ogroup gnus-newsgroup-name)
8554 (buf (current-buffer)))
8555 (if (gnus-group-read-ephemeral-group
8556 name (list 'nndoc name
8557 (list 'nndoc-address (get-buffer gnus-article-buffer))
8558 '(nndoc-article-type digest))
8559 t)
8560 (setcdr (nthcdr 4 (nth 2 (gnus-gethash name gnus-newsrc-hashtb)))
8561 (list (list (cons 'to-group ogroup))))
8562 (switch-to-buffer buf)
8563 (gnus-set-global-variables)
8564 (gnus-configure-windows 'summary)
8565 (gnus-message 3 "Article not a digest?"))))
8566
8567 (defun gnus-summary-isearch-article ()
8568 "Do incremental search forward on current article."
8569 (interactive)
8570 (gnus-set-global-variables)
8571 (gnus-summary-select-article)
8572 (gnus-eval-in-buffer-window
8573 gnus-article-buffer (isearch-forward)))
8574
8575 (defun gnus-summary-search-article-forward (regexp &optional backward)
8576 "Search for an article containing REGEXP forward.
8577 If BACKWARD, search backward instead."
8578 (interactive
8579 (list (read-string
8580 (format "Search article %s (regexp%s): "
8581 (if current-prefix-arg "backward" "forward")
8582 (if gnus-last-search-regexp
8583 (concat ", default " gnus-last-search-regexp)
8584 "")))
8585 current-prefix-arg))
8586 (gnus-set-global-variables)
8587 (if (string-equal regexp "")
8588 (setq regexp (or gnus-last-search-regexp ""))
8589 (setq gnus-last-search-regexp regexp))
8590 (if (gnus-summary-search-article regexp backward)
8591 (gnus-article-set-window-start
8592 (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks)))
8593 (error "Search failed: \"%s\"" regexp)))
8594
8595 (defun gnus-summary-search-article-backward (regexp)
8596 "Search for an article containing REGEXP backward."
8597 (interactive
8598 (list (read-string
8599 (format "Search article backward (regexp%s): "
8600 (if gnus-last-search-regexp
8601 (concat ", default " gnus-last-search-regexp)
8602 "")))))
8603 (gnus-summary-search-article-forward regexp 'backward))
8604
8605 (defun gnus-summary-search-article (regexp &optional backward)
8606 "Search for an article containing REGEXP.
8607 Optional argument BACKWARD means do search for backward.
8608 gnus-select-article-hook is not called during the search."
8609 (let ((gnus-select-article-hook nil) ;Disable hook.
8610 (gnus-mark-article-hook nil) ;Inhibit marking as read.
8611 (re-search
8612 (if backward
8613 (function re-search-backward) (function re-search-forward)))
8614 (found nil)
8615 (last nil))
8616 ;; Hidden thread subtrees must be searched for ,too.
8617 (gnus-summary-show-all-threads)
8618 (if (eobp) (forward-line -1))
8619 ;; First of all, search current article.
8620 ;; We don't want to read article again from NNTP server nor reset
8621 ;; current point.
8622 (gnus-summary-select-article)
8623 (gnus-message 9 "Searching article: %d..." gnus-current-article)
8624 (setq last gnus-current-article)
8625 (gnus-eval-in-buffer-window
8626 gnus-article-buffer
8627 (save-restriction
8628 (widen)
8629 ;; Begin search from current point.
8630 (setq found (funcall re-search regexp nil t))))
8631 ;; Then search next articles.
8632 (while (and (not found)
8633 (gnus-summary-display-article
8634 (gnus-summary-search-subject backward nil nil)))
8635 (gnus-message 9 "Searching article: %d..." gnus-current-article)
8636 (gnus-eval-in-buffer-window
8637 gnus-article-buffer
8638 (save-restriction
8639 (widen)
8640 (goto-char (if backward (point-max) (point-min)))
8641 (setq found (funcall re-search regexp nil t)))))
8642 (message "")
8643 ;; Adjust article pointer.
8644 (or (eq last gnus-current-article)
8645 (setq gnus-last-article last))
8646 ;; Return T if found such article.
8647 found))
8648
8649 (defun gnus-summary-execute-command (header regexp command &optional backward)
8650 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8651 If HEADER is an empty string (or nil), the match is done on the entire
8652 article. If BACKWARD (the prefix) is non-nil, search backward instead."
8653 (interactive
8654 (list (let ((completion-ignore-case t))
8655 (completing-read
8656 "Header name: "
8657 (mapcar (lambda (string) (list string))
8658 '("Number" "Subject" "From" "Lines" "Date"
8659 "Message-ID" "Xref" "References"))
8660 nil 'require-match))
8661 (read-string "Regexp: ")
8662 (read-key-sequence "Command: ")
8663 current-prefix-arg))
8664 (gnus-set-global-variables)
8665 ;; Hidden thread subtrees must be searched as well.
8666 (gnus-summary-show-all-threads)
8667 ;; We don't want to change current point nor window configuration.
8668 (save-excursion
8669 (save-window-excursion
8670 (gnus-message 6 "Executing %s..." (key-description command))
8671 ;; We'd like to execute COMMAND interactively so as to give arguments.
8672 (gnus-execute header regexp
8673 (` (lambda ()
8674 (call-interactively '(, (key-binding command)))))
8675 backward)
8676 (gnus-message 6 "Executing %s...done" (key-description command)))))
8677
8678 (defun gnus-summary-beginning-of-article ()
8679 "Scroll the article back to the beginning."
8680 (interactive)
8681 (gnus-set-global-variables)
8682 (gnus-summary-select-article)
8683 (gnus-configure-windows 'article)
8684 (gnus-eval-in-buffer-window
8685 gnus-article-buffer
8686 (widen)
8687 (goto-char (point-min))
8688 (and gnus-break-pages (gnus-narrow-to-page))))
8689
8690 (defun gnus-summary-end-of-article ()
8691 "Scroll to the end of the article."
8692 (interactive)
8693 (gnus-set-global-variables)
8694 (gnus-summary-select-article)
8695 (gnus-configure-windows 'article)
8696 (gnus-eval-in-buffer-window
8697 gnus-article-buffer
8698 (widen)
8699 (goto-char (point-max))
8700 (recenter -3)
8701 (and gnus-break-pages (gnus-narrow-to-page))))
8702
8703 (defun gnus-summary-show-article ()
8704 "Force re-fetching of the current article."
8705 (interactive)
8706 (gnus-set-global-variables)
8707 (gnus-summary-select-article nil 'force)
8708 (gnus-configure-windows 'article)
8709 (gnus-summary-position-cursor))
8710
8711 (defun gnus-summary-verbose-headers (&optional arg)
8712 "Toggle permanent full header display.
8713 If ARG is a positive number, turn header display on.
8714 If ARG is a negative number, turn header display off."
8715 (interactive "P")
8716 (gnus-set-global-variables)
8717 (gnus-summary-toggle-header arg)
8718 (setq gnus-show-all-headers
8719 (cond ((or (not (numberp arg))
8720 (zerop arg))
8721 (not gnus-show-all-headers))
8722 ((natnump arg)
8723 t))))
8724
8725 (defun gnus-summary-toggle-header (&optional arg)
8726 "Show the headers if they are hidden, or hide them if they are shown.
8727 If ARG is a positive number, show the entire header.
8728 If ARG is a negative number, hide the unwanted header lines."
8729 (interactive "P")
8730 (gnus-set-global-variables)
8731 (save-excursion
8732 (set-buffer gnus-article-buffer)
8733 (let ((buffer-read-only nil))
8734 (if (numberp arg)
8735 (if (> arg 0) (remove-text-properties (point-min) (point-max)
8736 gnus-hidden-properties)
8737 (if (< arg 0) (run-hooks 'gnus-article-display-hook)))
8738 (if (text-property-any (point-min) (point-max) 'invisible t)
8739 (remove-text-properties
8740 (point-min) (point-max) gnus-hidden-properties)
8741 ;; We hide the headers. This song and dance act below is
8742 ;; done because `gnus-have-all-headers' is buffer-local to
8743 ;; the summary buffer, and we only want to temporarily
8744 ;; change it in that buffer. Ugh.
8745 (let ((have gnus-have-all-headers))
8746 (save-excursion
8747 (set-buffer gnus-summary-buffer)
8748 (setq gnus-have-all-headers nil)
8749 (save-excursion
8750 (set-buffer gnus-article-buffer)
8751 (run-hooks 'gnus-article-display-hook))
8752 (setq gnus-have-all-headers have)))))
8753 (set-window-point (get-buffer-window (current-buffer)) (point-min)))))
8754
8755 (defun gnus-summary-show-all-headers ()
8756 "Make all header lines visible."
8757 (interactive)
8758 (gnus-set-global-variables)
8759 (gnus-article-show-all-headers))
8760
8761 (defun gnus-summary-toggle-mime (&optional arg)
8762 "Toggle MIME processing.
8763 If ARG is a positive number, turn MIME processing on."
8764 (interactive "P")
8765 (gnus-set-global-variables)
8766 (setq gnus-show-mime
8767 (if (null arg) (not gnus-show-mime)
8768 (> (prefix-numeric-value arg) 0)))
8769 (gnus-summary-select-article t 'force))
8770
8771 (defun gnus-summary-caesar-message (&optional arg)
8772 "Caesar rotate the current article by 13.
8773 The numerical prefix specifies how manu places to rotate each letter
8774 forward."
8775 (interactive "P")
8776 (gnus-set-global-variables)
8777 (gnus-summary-select-article)
8778 (let ((mail-header-separator ""))
8779 (gnus-eval-in-buffer-window
8780 gnus-article-buffer
8781 (save-restriction
8782 (widen)
8783 (let ((start (window-start)))
8784 (news-caesar-buffer-body arg)
8785 (set-window-start (get-buffer-window (current-buffer)) start))))))
8786
8787 (defun gnus-summary-stop-page-breaking ()
8788 "Stop page breaking in the current article."
8789 (interactive)
8790 (gnus-set-global-variables)
8791 (gnus-summary-select-article)
8792 (gnus-eval-in-buffer-window gnus-article-buffer (widen)))
8793
8794 ;; Suggested by Brian Edmonds <bedmonds@prodigy.bc.ca>.
8795
8796 (defun gnus-summary-move-article (&optional n to-newsgroup select-method)
8797 "Move the current article to a different newsgroup.
8798 If N is a positive number, move the N next articles.
8799 If N is a negative number, move the N previous articles.
8800 If N is nil and any articles have been marked with the process mark,
8801 move those articles instead.
8802 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8803 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8804 re-spool using this method.
8805 For this function to work, both the current newsgroup and the
8806 newsgroup that you want to move to have to support the `request-move'
8807 and `request-accept' functions. (Ie. mail newsgroups at present.)"
8808 (interactive "P")
8809 (gnus-set-global-variables)
8810 (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name)
8811 (error "The current newsgroup does not support article moving"))
8812 (let ((articles (gnus-summary-work-articles n))
8813 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8814 art-group to-method sel-met)
8815 (if (and (not to-newsgroup) (not select-method))
8816 (setq to-newsgroup
8817 (completing-read
8818 (format "Where do you want to move %s? %s"
8819 (if (> (length articles) 1)
8820 (format "these %d articles" (length articles))
8821 "this article")
8822 (if gnus-current-move-group
8823 (format "(%s default) " gnus-current-move-group)
8824 ""))
8825 gnus-active-hashtb nil nil prefix)))
8826 (if to-newsgroup
8827 (progn
8828 (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8829 (setq to-newsgroup (or gnus-current-move-group "")))
8830 (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8831 (gnus-activate-group to-newsgroup)
8832 (error "No such group: %s" to-newsgroup))
8833 (setq gnus-current-move-group to-newsgroup)))
8834 (setq to-method (if select-method (list select-method "")
8835 (gnus-find-method-for-group to-newsgroup)))
8836 (or (gnus-check-backend-function 'request-accept-article (car to-method))
8837 (error "%s does not support article copying" (car to-method)))
8838 (or (gnus-check-server to-method)
8839 (error "Can't open server %s" (car to-method)))
8840 (gnus-message 6 "Moving to %s: %s..."
8841 (or select-method to-newsgroup) articles)
8842 (while articles
8843 (if (setq art-group
8844 (gnus-request-move-article
8845 (car articles) ; Article to move
8846 gnus-newsgroup-name ; From newsgroup
8847 (nth 1 (gnus-find-method-for-group
8848 gnus-newsgroup-name)) ; Server
8849 (list 'gnus-request-accept-article
8850 (if select-method
8851 (list 'quote select-method)
8852 to-newsgroup)
8853 (not (cdr articles))) ; Accept form
8854 (not (cdr articles)))) ; Only save nov last time
8855 (let* ((buffer-read-only nil)
8856 (entry
8857 (or
8858 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8859 (gnus-gethash
8860 (gnus-group-prefixed-name
8861 (car art-group)
8862 (if select-method (list select-method "")
8863 (gnus-find-method-for-group to-newsgroup)))
8864 gnus-newsrc-hashtb)))
8865 (info (nth 2 entry))
8866 (article (car articles)))
8867 (gnus-summary-goto-subject article)
8868 (beginning-of-line)
8869 (delete-region (point) (progn (forward-line 1) (point)))
8870 ;; Update the group that has been moved to.
8871 (if (not info)
8872 () ; This group does not exist yet.
8873 (if (not (memq article gnus-newsgroup-unreads))
8874 (setcar (cdr (cdr info))
8875 (gnus-add-to-range (nth 2 info)
8876 (list (cdr art-group)))))
8877 ;; Copy any marks over to the new group.
8878 (let ((marks '((tick . gnus-newsgroup-marked)
8879 (dormant . gnus-newsgroup-dormant)
8880 (expire . gnus-newsgroup-expirable)
8881 (bookmark . gnus-newsgroup-bookmarks)
8882 (reply . gnus-newsgroup-replied)))
8883 (to-article (cdr art-group)))
8884 (while marks
8885 (if (memq article (symbol-value (cdr (car marks))))
8886 (gnus-add-marked-articles
8887 (car info) (car (car marks)) (list to-article) info))
8888 (setq marks (cdr marks)))))
8889 ;; Update marks.
8890 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8891 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8892 (setq gnus-newsgroup-dormant
8893 (delq article gnus-newsgroup-dormant))
8894 (setq gnus-newsgroup-reads
8895 (cons (cons article gnus-canceled-mark)
8896 gnus-newsgroup-reads)))
8897 (gnus-message 1 "Couldn't move article %s" (car articles)))
8898 (gnus-summary-remove-process-mark (car articles))
8899 (setq articles (cdr articles)))
8900 (gnus-set-mode-line 'summary)))
8901
8902 (defun gnus-summary-respool-article (&optional n respool-method)
8903 "Respool the current article.
8904 The article will be squeezed through the mail spooling process again,
8905 which means that it will be put in some mail newsgroup or other
8906 depending on `nnmail-split-methods'.
8907 If N is a positive number, respool the N next articles.
8908 If N is a negative number, respool the N previous articles.
8909 If N is nil and any articles have been marked with the process mark,
8910 respool those articles instead.
8911
8912 Respooling can be done both from mail groups and \"real\" newsgroups.
8913 In the former case, the articles in question will be moved from the
8914 current group into whatever groups they are destined to. In the
8915 latter case, they will be copied into the relevant groups."
8916 (interactive "P")
8917 (gnus-set-global-variables)
8918 (let ((respool-methods (gnus-methods-using 'respool))
8919 (methname
8920 (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name)))))
8921 (or respool-method
8922 (setq respool-method
8923 (completing-read
8924 "What method do you want to use when respooling? "
8925 respool-methods nil t methname)))
8926 (or (string= respool-method "")
8927 (if (assoc (symbol-name
8928 (car (gnus-find-method-for-group gnus-newsgroup-name)))
8929 respool-methods)
8930 (gnus-summary-move-article n nil (intern respool-method))
8931 (gnus-summary-copy-article n nil (intern respool-method))))))
8932
8933 ;; Suggested by gregj@unidata.com (Gregory J. Grubbs).
8934 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8935 "Move the current article to a different newsgroup.
8936 If N is a positive number, move the N next articles.
8937 If N is a negative number, move the N previous articles.
8938 If N is nil and any articles have been marked with the process mark,
8939 move those articles instead.
8940 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8941 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8942 re-spool using this method.
8943 For this function to work, the newsgroup that you want to move to have
8944 to support the `request-move' and `request-accept'
8945 functions. (Ie. mail newsgroups at present.)"
8946 (interactive "P")
8947 (gnus-set-global-variables)
8948 (let ((articles (gnus-summary-work-articles n))
8949 (copy-buf (get-buffer-create "*copy work*"))
8950 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8951 art-group to-method)
8952 (buffer-disable-undo copy-buf)
8953 (if (and (not to-newsgroup) (not select-method))
8954 (setq to-newsgroup
8955 (completing-read
8956 (format "Where do you want to copy %s? %s"
8957 (if (> (length articles) 1)
8958 (format "these %d articles" (length articles))
8959 "this article")
8960 (if gnus-current-move-group
8961 (format "(%s default) " gnus-current-move-group)
8962 ""))
8963 gnus-active-hashtb nil nil prefix)))
8964 (if to-newsgroup
8965 (progn
8966 (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8967 (setq to-newsgroup (or gnus-current-move-group "")))
8968 (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8969 (gnus-activate-group to-newsgroup)
8970 (error "No such group: %s" to-newsgroup))
8971 (setq gnus-current-move-group to-newsgroup)))
8972 (setq to-method (if select-method (list select-method "")
8973 (gnus-find-method-for-group to-newsgroup)))
8974 (or (gnus-check-backend-function 'request-accept-article (car to-method))
8975 (error "%s does not support article copying" (car to-method)))
8976 (or (gnus-check-server to-method)
8977 (error "Can't open server %s" (car to-method)))
8978 (while articles
8979 (gnus-message 6 "Copying to %s: %s..."
8980 (or select-method to-newsgroup) articles)
8981 (if (setq art-group
8982 (save-excursion
8983 (set-buffer copy-buf)
8984 (gnus-request-article-this-buffer
8985 (car articles) gnus-newsgroup-name)
8986 (gnus-request-accept-article
8987 (if select-method (list 'quote select-method) to-newsgroup)
8988 (not (cdr articles)))))
8989 (let* ((entry
8990 (or
8991 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8992 (gnus-gethash
8993 (gnus-group-prefixed-name
8994 (car art-group)
8995 (if select-method (list select-method "")
8996 (gnus-find-method-for-group to-newsgroup)))
8997 gnus-newsrc-hashtb)))
8998 (info (nth 2 entry))
8999 (article (car articles)))
9000 ;; We copy the info over to the new group.
9001 (if (not info)
9002 () ; This group does not exist (yet).
9003 (if (not (memq article gnus-newsgroup-unreads))
9004 (setcar (cdr (cdr info))
9005 (gnus-add-to-range (nth 2 info)
9006 (list (cdr art-group)))))
9007 ;; Copy any marks over to the new group.
9008 (let ((marks '((tick . gnus-newsgroup-marked)
9009 (dormant . gnus-newsgroup-dormant)
9010 (expire . gnus-newsgroup-expirable)
9011 (bookmark . gnus-newsgroup-bookmarks)
9012 (reply . gnus-newsgroup-replied)))
9013 (to-article (cdr art-group)))
9014 (while marks
9015 (if (memq article (symbol-value (cdr (car marks))))
9016 (gnus-add-marked-articles
9017 (car info) (car (car marks)) (list to-article) info))
9018 (setq marks (cdr marks))))))
9019 (gnus-message 1 "Couldn't copy article %s" (car articles)))
9020 (gnus-summary-remove-process-mark (car articles))
9021 (setq articles (cdr articles)))
9022 (kill-buffer copy-buf)))
9023
9024 (defun gnus-summary-import-article (file)
9025 "Import a random file into a mail newsgroup."
9026 (interactive "fImport file: ")
9027 (let ((group gnus-newsgroup-name)
9028 atts)
9029 (or (gnus-check-backend-function 'request-accept-article group)
9030 (error "%s does not support article importing" group))
9031 (or (file-readable-p file)
9032 (not (file-regular-p file))
9033 (error "Can't read %s" file))
9034 (save-excursion
9035 (set-buffer (get-buffer-create " *import file*"))
9036 (buffer-disable-undo (current-buffer))
9037 (erase-buffer)
9038 (insert-file-contents file)
9039 (goto-char (point-min))
9040 (if (nnheader-article-p)
9041 ()
9042 (setq atts (file-attributes file))
9043 (insert "From: " (read-string "From: ") "\n"
9044 "Subject: " (read-string "Subject: ") "\n"
9045 "Date: " (current-time-string (nth 5 atts)) "\n"
9046 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9047 (gnus-request-accept-article group t)
9048 (kill-buffer (current-buffer)))))
9049
9050 (defun gnus-summary-expire-articles ()
9051 "Expire all articles that are marked as expirable in the current group."
9052 (interactive)
9053 (if (not (gnus-check-backend-function
9054 'request-expire-articles gnus-newsgroup-name))
9055 ()
9056 (let* ((info (nth 2 (gnus-gethash gnus-newsgroup-name
9057 gnus-newsrc-hashtb)))
9058 (total (memq 'total-expire (nth 5 info)))
9059 (expirable (if total
9060 (gnus-list-of-read-articles gnus-newsgroup-name)
9061 (setq gnus-newsgroup-expirable
9062 (sort gnus-newsgroup-expirable '<))))
9063 es)
9064 (if (not expirable)
9065 ()
9066 (gnus-message 6 "Expiring articles...")
9067 ;; The list of articles that weren't expired is returned.
9068 (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name))
9069 (or total (setq gnus-newsgroup-expirable es))
9070 ;; We go through the old list of expirable, and mark all
9071 ;; really expired articles as nonexistent.
9072 (or (eq es expirable) ;If nothing was expired, we don't mark.
9073 (let ((gnus-use-cache nil))
9074 (while expirable
9075 (or (memq (car expirable) es)
9076 (gnus-summary-mark-article
9077 (car expirable) gnus-canceled-mark))
9078 (setq expirable (cdr expirable)))))
9079 (gnus-message 6 "Expiring articles...done")))))
9080
9081 (defun gnus-summary-expire-articles-now ()
9082 "Expunge all expirable articles in the current group.
9083 This means that *all* articles that are marked as expirable will be
9084 deleted forever, right now."
9085 (interactive)
9086 (or gnus-expert-user
9087 (gnus-y-or-n-p
9088 "Are you really, really, really sure you want to expunge? ")
9089 (error "Phew!"))
9090 (let ((nnmail-expiry-wait -1)
9091 (nnmail-expiry-wait-function nil))
9092 (gnus-summary-expire-articles)))
9093
9094 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9095 (defun gnus-summary-delete-article (&optional n)
9096 "Delete the N next (mail) articles.
9097 This command actually deletes articles. This is not a marking
9098 command. The article will disappear forever from you life, never to
9099 return.
9100 If N is negative, delete backwards.
9101 If N is nil and articles have been marked with the process mark,
9102 delete these instead."
9103 (interactive "P")
9104 (or (gnus-check-backend-function 'request-expire-articles
9105 gnus-newsgroup-name)
9106 (error "The current newsgroup does not support article deletion."))
9107 ;; Compute the list of articles to delete.
9108 (let ((articles (gnus-summary-work-articles n))
9109 not-deleted)
9110 (if (and gnus-novice-user
9111 (not (gnus-y-or-n-p
9112 (format "Do you really want to delete %s forever? "
9113 (if (> (length articles) 1) "these articles"
9114 "this article")))))
9115 ()
9116 ;; Delete the articles.
9117 (setq not-deleted (gnus-request-expire-articles
9118 articles gnus-newsgroup-name 'force))
9119 (while articles
9120 (gnus-summary-remove-process-mark (car articles))
9121 ;; The backend might not have been able to delete the article
9122 ;; after all.
9123 (or (memq (car articles) not-deleted)
9124 (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9125 (setq articles (cdr articles))))
9126 (gnus-summary-position-cursor)
9127 (gnus-set-mode-line 'summary)
9128 not-deleted))
9129
9130 (defun gnus-summary-edit-article (&optional force)
9131 "Enter into a buffer and edit the current article.
9132 This will have permanent effect only in mail groups.
9133 If FORCE is non-nil, allow editing of articles even in read-only
9134 groups."
9135 (interactive "P")
9136 (or force
9137 (not (gnus-group-read-only-p))
9138 (error "The current newsgroup does not support article editing."))
9139 (gnus-summary-select-article t)
9140 (gnus-configure-windows 'article)
9141 (select-window (get-buffer-window gnus-article-buffer))
9142 (gnus-message 6 "C-c C-c to end edits")
9143 (setq buffer-read-only nil)
9144 (text-mode)
9145 (use-local-map (copy-keymap (current-local-map)))
9146 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
9147 (buffer-enable-undo)
9148 (widen)
9149 (goto-char (point-min))
9150 (search-forward "\n\n" nil t))
9151
9152 (defun gnus-summary-edit-article-done ()
9153 "Make edits to the current article permanent."
9154 (interactive)
9155 (if (gnus-group-read-only-p)
9156 (progn
9157 (gnus-summary-edit-article-postpone)
9158 (message "The current newsgroup does not support article editing.")
9159 (ding))
9160 (let ((buf (buffer-substring-no-properties (point-min) (point-max))))
9161 (erase-buffer)
9162 (insert buf)
9163 (if (not (gnus-request-replace-article
9164 (cdr gnus-article-current) (car gnus-article-current)
9165 (current-buffer)))
9166 (error "Couldn't replace article.")
9167 (gnus-article-mode)
9168 (use-local-map gnus-article-mode-map)
9169 (setq buffer-read-only t)
9170 (buffer-disable-undo (current-buffer))
9171 (gnus-configure-windows 'summary))
9172 (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))))
9173
9174 (defun gnus-summary-edit-article-postpone ()
9175 "Postpone changes to the current article."
9176 (interactive)
9177 (gnus-article-mode)
9178 (use-local-map gnus-article-mode-map)
9179 (setq buffer-read-only t)
9180 (buffer-disable-undo (current-buffer))
9181 (gnus-configure-windows 'summary)
9182 (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))
9183
9184 (defun gnus-summary-fancy-query ()
9185 "Query where the fancy respool algorithm would put this article."
9186 (interactive)
9187 (gnus-summary-select-article)
9188 (save-excursion
9189 (set-buffer gnus-article-buffer)
9190 (save-restriction
9191 (goto-char (point-min))
9192 (search-forward "\n\n")
9193 (narrow-to-region (point-min) (point))
9194 (pp-eval-expression (list 'quote (nnmail-split-fancy))))))
9195
9196 ;; Summary score commands.
9197
9198 ;; Suggested by boubaker@cenatls.cena.dgac.fr.
9199
9200 (defun gnus-summary-raise-score (n)
9201 "Raise the score of the current article by N."
9202 (interactive "p")
9203 (gnus-summary-set-score (+ (gnus-summary-article-score) n)))
9204
9205 (defun gnus-summary-set-score (n)
9206 "Set the score of the current article to N."
9207 (interactive "p")
9208 ;; Skip dummy header line.
9209 (save-excursion
9210 (gnus-summary-show-thread)
9211 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
9212 (forward-line 1))
9213 (let ((buffer-read-only nil))
9214 ;; Set score.
9215 (gnus-summary-update-mark
9216 (if (= n (or gnus-summary-default-score 0)) ?
9217 (if (< n (or gnus-summary-default-score 0))
9218 gnus-score-below-mark gnus-score-over-mark)) 'score))
9219 (let* ((article (gnus-summary-article-number))
9220 (score (assq article gnus-newsgroup-scored)))
9221 (if score (setcdr score n)
9222 (setq gnus-newsgroup-scored
9223 (cons (cons article n) gnus-newsgroup-scored))))
9224 (gnus-summary-update-line)))
9225
9226 (defun gnus-summary-current-score ()
9227 "Return the score of the current article."
9228 (interactive)
9229 (message "%s" (gnus-summary-article-score)))
9230
9231 ;; Summary marking commands.
9232
9233 (defun gnus-summary-raise-same-subject-and-select (score)
9234 "Raise articles which has the same subject with SCORE and select the next."
9235 (interactive "p")
9236 (let ((subject (gnus-summary-subject-string)))
9237 (gnus-summary-raise-score score)
9238 (while (gnus-summary-search-subject nil nil subject)
9239 (gnus-summary-raise-score score))
9240 (gnus-summary-next-article t)))
9241
9242 (defun gnus-summary-raise-same-subject (score)
9243 "Raise articles which has the same subject with SCORE."
9244 (interactive "p")
9245 (let ((subject (gnus-summary-subject-string)))
9246 (gnus-summary-raise-score score)
9247 (while (gnus-summary-search-subject nil nil subject)
9248 (gnus-summary-raise-score score))
9249 (gnus-summary-next-subject 1 t)))
9250
9251 (defun gnus-score-default (level)
9252 (if level (prefix-numeric-value level)
9253 gnus-score-interactive-default-score))
9254
9255 (defun gnus-summary-raise-thread (&optional score)
9256 "Raise the score of the articles in the current thread with SCORE."
9257 (interactive "P")
9258 (setq score (gnus-score-default score))
9259 (let (e)
9260 (save-excursion
9261 (let ((level (gnus-summary-thread-level)))
9262 (gnus-summary-raise-score score)
9263 (while (and (zerop (gnus-summary-next-subject 1 nil t))
9264 (> (gnus-summary-thread-level) level))
9265 (gnus-summary-raise-score score))
9266 (setq e (point))))
9267 (let ((gnus-summary-check-current t))
9268 (or (zerop (gnus-summary-next-subject 1 t))
9269 (goto-char e))))
9270 (gnus-summary-recenter)
9271 (gnus-summary-position-cursor)
9272 (gnus-set-mode-line 'summary))
9273
9274 (defun gnus-summary-lower-same-subject-and-select (score)
9275 "Raise articles which has the same subject with SCORE and select the next."
9276 (interactive "p")
9277 (gnus-summary-raise-same-subject-and-select (- score)))
9278
9279 (defun gnus-summary-lower-same-subject (score)
9280 "Raise articles which has the same subject with SCORE."
9281 (interactive "p")
9282 (gnus-summary-raise-same-subject (- score)))
9283
9284 (defun gnus-summary-lower-thread (&optional score)
9285 "Lower score of articles in the current thread with SCORE."
9286 (interactive "P")
9287 (gnus-summary-raise-thread (- (1- (gnus-score-default score)))))
9288
9289 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9290 "Mark articles which has the same subject as read, and then select the next.
9291 If UNMARK is positive, remove any kind of mark.
9292 If UNMARK is negative, tick articles."
9293 (interactive "P")
9294 (if unmark
9295 (setq unmark (prefix-numeric-value unmark)))
9296 (let ((count
9297 (gnus-summary-mark-same-subject
9298 (gnus-summary-subject-string) unmark)))
9299 ;; Select next unread article. If auto-select-same mode, should
9300 ;; select the first unread article.
9301 (gnus-summary-next-article t (and gnus-auto-select-same
9302 (gnus-summary-subject-string)))
9303 (gnus-message 7 "%d article%s marked as %s"
9304 count (if (= count 1) " is" "s are")
9305 (if unmark "unread" "read"))))
9306
9307 (defun gnus-summary-kill-same-subject (&optional unmark)
9308 "Mark articles which has the same subject as read.
9309 If UNMARK is positive, remove any kind of mark.
9310 If UNMARK is negative, tick articles."
9311 (interactive "P")
9312 (if unmark
9313 (setq unmark (prefix-numeric-value unmark)))
9314 (let ((count
9315 (gnus-summary-mark-same-subject
9316 (gnus-summary-subject-string) unmark)))
9317 ;; If marked as read, go to next unread subject.
9318 (if (null unmark)
9319 ;; Go to next unread subject.
9320 (gnus-summary-next-subject 1 t))
9321 (gnus-message 7 "%d articles are marked as %s"
9322 count (if unmark "unread" "read"))))
9323
9324 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9325 "Mark articles with same SUBJECT as read, and return marked number.
9326 If optional argument UNMARK is positive, remove any kinds of marks.
9327 If optional argument UNMARK is negative, mark articles as unread instead."
9328 (let ((count 1))
9329 (save-excursion
9330 (cond
9331 ((null unmark) ; Mark as read.
9332 (while (and
9333 (progn
9334 (gnus-summary-mark-article-as-read gnus-killed-mark)
9335 (gnus-summary-show-thread) t)
9336 (gnus-summary-search-forward nil subject))
9337 (setq count (1+ count))))
9338 ((> unmark 0) ; Tick.
9339 (while (and
9340 (progn
9341 (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9342 (gnus-summary-show-thread) t)
9343 (gnus-summary-search-forward nil subject))
9344 (setq count (1+ count))))
9345 (t ; Mark as unread.
9346 (while (and
9347 (progn
9348 (gnus-summary-mark-article-as-unread gnus-unread-mark)
9349 (gnus-summary-show-thread) t)
9350 (gnus-summary-search-forward nil subject))
9351 (setq count (1+ count)))))
9352 (gnus-set-mode-line 'summary)
9353 ;; Return the number of marked articles.
9354 count)))
9355
9356 (defun gnus-summary-mark-as-processable (n &optional unmark)
9357 "Set the process mark on the next N articles.
9358 If N is negative, mark backward instead. If UNMARK is non-nil, remove
9359 the process mark instead. The difference between N and the actual
9360 number of articles marked is returned."
9361 (interactive "p")
9362 (let ((backward (< n 0))
9363 (n (abs n)))
9364 (while (and
9365 (> n 0)
9366 (if unmark
9367 (gnus-summary-remove-process-mark
9368 (gnus-summary-article-number))
9369 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9370 (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9371 (setq n (1- n)))
9372 (if (/= 0 n) (gnus-message 7 "No more articles"))
9373 (gnus-summary-recenter)
9374 (gnus-summary-position-cursor)
9375 n))
9376
9377 (defun gnus-summary-unmark-as-processable (n)
9378 "Remove the process mark from the next N articles.
9379 If N is negative, mark backward instead. The difference between N and
9380 the actual number of articles marked is returned."
9381 (interactive "p")
9382 (gnus-summary-mark-as-processable n t))
9383
9384 (defun gnus-summary-unmark-all-processable ()
9385 "Remove the process mark from all articles."
9386 (interactive)
9387 (save-excursion
9388 (while gnus-newsgroup-processable
9389 (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9390 (gnus-summary-position-cursor))
9391
9392 (defun gnus-summary-mark-as-expirable (n)
9393 "Mark N articles forward as expirable.
9394 If N is negative, mark backward instead. The difference between N and
9395 the actual number of articles marked is returned."
9396 (interactive "p")
9397 (gnus-summary-mark-forward n gnus-expirable-mark))
9398
9399 (defun gnus-summary-mark-article-as-replied (article)
9400 "Mark ARTICLE replied and update the summary line."
9401 (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
9402 (let ((buffer-read-only nil))
9403 (if (gnus-summary-goto-subject article)
9404 (progn
9405 (gnus-summary-update-mark gnus-replied-mark 'replied)
9406 t))))
9407
9408 (defun gnus-summary-set-bookmark (article)
9409 "Set a bookmark in current article."
9410 (interactive (list (gnus-summary-article-number)))
9411 (if (or (not (get-buffer gnus-article-buffer))
9412 (not gnus-current-article)
9413 (not gnus-article-current)
9414 (not (equal gnus-newsgroup-name (car gnus-article-current))))
9415 (error "No current article selected"))
9416 ;; Remove old bookmark, if one exists.
9417 (let ((old (assq article gnus-newsgroup-bookmarks)))
9418 (if old (setq gnus-newsgroup-bookmarks
9419 (delq old gnus-newsgroup-bookmarks))))
9420 ;; Set the new bookmark, which is on the form
9421 ;; (article-number . line-number-in-body).
9422 (setq gnus-newsgroup-bookmarks
9423 (cons
9424 (cons article
9425 (save-excursion
9426 (set-buffer gnus-article-buffer)
9427 (count-lines
9428 (min (point)
9429 (save-excursion
9430 (goto-char (point-min))
9431 (search-forward "\n\n" nil t)
9432 (point)))
9433 (point))))
9434 gnus-newsgroup-bookmarks))
9435 (gnus-message 6 "A bookmark has been added to the current article."))
9436
9437 (defun gnus-summary-remove-bookmark (article)
9438 "Remove the bookmark from the current article."
9439 (interactive (list (gnus-summary-article-number)))
9440 ;; Remove old bookmark, if one exists.
9441 (let ((old (assq article gnus-newsgroup-bookmarks)))
9442 (if old
9443 (progn
9444 (setq gnus-newsgroup-bookmarks
9445 (delq old gnus-newsgroup-bookmarks))
9446 (gnus-message 6 "Removed bookmark."))
9447 (gnus-message 6 "No bookmark in current article."))))
9448
9449 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9450 (defun gnus-summary-mark-as-dormant (n)
9451 "Mark N articles forward as dormant.
9452 If N is negative, mark backward instead. The difference between N and
9453 the actual number of articles marked is returned."
9454 (interactive "p")
9455 (gnus-summary-mark-forward n gnus-dormant-mark))
9456
9457 (defun gnus-summary-set-process-mark (article)
9458 "Set the process mark on ARTICLE and update the summary line."
9459 (setq gnus-newsgroup-processable
9460 (cons article
9461 (delq article gnus-newsgroup-processable)))
9462 (let ((buffer-read-only nil))
9463 (if (gnus-summary-goto-subject article)
9464 (progn
9465 (gnus-summary-show-thread)
9466 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9467 (forward-line 1))
9468 (gnus-summary-update-mark gnus-process-mark 'replied)
9469 t))))
9470
9471 (defun gnus-summary-remove-process-mark (article)
9472 "Remove the process mark from ARTICLE and update the summary line."
9473 (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9474 (let ((buffer-read-only nil))
9475 (if (gnus-summary-goto-subject article)
9476 (progn
9477 (gnus-summary-show-thread)
9478 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9479 (forward-line 1))
9480 (gnus-summary-update-mark ? 'replied)
9481 (if (memq article gnus-newsgroup-replied)
9482 (gnus-summary-update-mark gnus-replied-mark 'replied))
9483 t))))
9484
9485 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9486 "Mark N articles as read forwards.
9487 If N is negative, mark backwards instead.
9488 Mark with MARK. If MARK is ? , ?! or ??, articles will be
9489 marked as unread.
9490 The difference between N and the actual number of articles marked is
9491 returned."
9492 (interactive "p")
9493 (gnus-set-global-variables)
9494 (let ((backward (< n 0))
9495 (gnus-summary-goto-unread
9496 (and gnus-summary-goto-unread
9497 (not (memq mark (list gnus-unread-mark
9498 gnus-ticked-mark gnus-dormant-mark)))))
9499 (n (abs n))
9500 (mark (or mark gnus-del-mark)))
9501 (while (and (> n 0)
9502 (gnus-summary-mark-article nil mark no-expire)
9503 (zerop (gnus-summary-next-subject
9504 (if backward -1 1) gnus-summary-goto-unread t)))
9505 (setq n (1- n)))
9506 (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9507 (gnus-summary-recenter)
9508 (gnus-summary-position-cursor)
9509 (gnus-set-mode-line 'summary)
9510 n))
9511
9512 (defun gnus-summary-mark-article-as-read (mark)
9513 "Mark the current article quickly as read with MARK."
9514 (let ((article (gnus-summary-article-number)))
9515 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9516 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9517 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9518 (setq gnus-newsgroup-reads
9519 (cons (cons article mark) gnus-newsgroup-reads))
9520 ;; Possibly remove from cache, if that is used.
9521 (and gnus-use-cache (gnus-cache-enter-remove-article article))
9522 (and gnus-newsgroup-auto-expire
9523 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9524 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9525 (= mark gnus-read-mark))
9526 (progn
9527 (setq mark gnus-expirable-mark)
9528 (setq gnus-newsgroup-expirable
9529 (cons article gnus-newsgroup-expirable))))
9530 (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9531 (forward-line 1))
9532 ;; Fix the mark.
9533 (gnus-summary-update-mark mark 'unread)
9534 t))
9535
9536 (defun gnus-summary-mark-article-as-unread (mark)
9537 "Mark the current article quickly as unread with MARK."
9538 (let ((article (gnus-summary-article-number)))
9539 (or (memq article gnus-newsgroup-unreads)
9540 (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9541 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9542 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9543 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9544 (setq gnus-newsgroup-reads
9545 (delq (assq article gnus-newsgroup-reads)
9546 gnus-newsgroup-reads))
9547 (if (= mark gnus-ticked-mark)
9548 (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9549 (if (= mark gnus-dormant-mark)
9550 (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))
9551
9552 ;; See whether the article is to be put in the cache.
9553 (and gnus-use-cache
9554 (vectorp (gnus-get-header-by-num article))
9555 (save-excursion
9556 (gnus-cache-possibly-enter-article
9557 gnus-newsgroup-name article
9558 (gnus-get-header-by-num article)
9559 (= mark gnus-ticked-mark)
9560 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9561
9562 (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9563 (forward-line 1))
9564 ;; Fix the mark.
9565 (gnus-summary-update-mark mark 'unread)
9566 t))
9567
9568 (defun gnus-summary-mark-article (&optional article mark no-expire)
9569 "Mark ARTICLE with MARK. MARK can be any character.
9570 Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??'
9571 (dormant) and `?E' (expirable).
9572 If MARK is nil, then the default character `?D' is used.
9573 If ARTICLE is nil, then the article on the current line will be
9574 marked."
9575 (and (stringp mark)
9576 (setq mark (aref mark 0)))
9577 ;; If no mark is given, then we check auto-expiring.
9578 (and (not no-expire)
9579 gnus-newsgroup-auto-expire
9580 (or (not mark)
9581 (and (numberp mark)
9582 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9583 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9584 (= mark gnus-read-mark))))
9585 (setq mark gnus-expirable-mark))
9586 (let* ((mark (or mark gnus-del-mark))
9587 (article (or article (gnus-summary-article-number))))
9588 (or article (error "No article on current line"))
9589 (if (or (= mark gnus-unread-mark)
9590 (= mark gnus-ticked-mark)
9591 (= mark gnus-dormant-mark))
9592 (gnus-mark-article-as-unread article mark)
9593 (gnus-mark-article-as-read article mark))
9594
9595 ;; See whether the article is to be put in the cache.
9596 (and gnus-use-cache
9597 (not (= mark gnus-canceled-mark))
9598 (vectorp (gnus-get-header-by-num article))
9599 (save-excursion
9600 (gnus-cache-possibly-enter-article
9601 gnus-newsgroup-name article
9602 (gnus-get-header-by-num article)
9603 (= mark gnus-ticked-mark)
9604 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9605
9606 (if (gnus-summary-goto-subject article)
9607 (let ((buffer-read-only nil))
9608 (gnus-summary-show-thread)
9609 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9610 (forward-line 1))
9611 ;; Fix the mark.
9612 (gnus-summary-update-mark mark 'unread)
9613 t))))
9614
9615 (defun gnus-summary-update-mark (mark type)
9616 (beginning-of-line)
9617 (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9618 (buffer-read-only nil)
9619 plist)
9620 (if (not forward)
9621 ()
9622 (forward-char forward)
9623 (setq plist (text-properties-at (point)))
9624 (delete-char 1)
9625 (insert mark)
9626 (and plist (add-text-properties (1- (point)) (point) plist))
9627 (and (eq type 'unread)
9628 (progn
9629 (add-text-properties (1- (point)) (point) (list 'gnus-mark mark))
9630 (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9631
9632 (defun gnus-mark-article-as-read (article &optional mark)
9633 "Enter ARTICLE in the pertinent lists and remove it from others."
9634 ;; Make the article expirable.
9635 (let ((mark (or mark gnus-del-mark)))
9636 (if (= mark gnus-expirable-mark)
9637 (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
9638 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9639 ;; Remove from unread and marked lists.
9640 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9641 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9642 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9643 (setq gnus-newsgroup-reads
9644 (cons (cons article mark) gnus-newsgroup-reads))
9645 ;; Possibly remove from cache, if that is used.
9646 (and gnus-use-cache (gnus-cache-enter-remove-article article))))
9647
9648 (defun gnus-mark-article-as-unread (article &optional mark)
9649 "Enter ARTICLE in the pertinent lists and remove it from others."
9650 (let ((mark (or mark gnus-ticked-mark)))
9651 ;; Add to unread list.
9652 (or (memq article gnus-newsgroup-unreads)
9653 (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9654 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9655 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9656 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9657 (setq gnus-newsgroup-reads
9658 (delq (assq article gnus-newsgroup-reads)
9659 gnus-newsgroup-reads))
9660 (if (= mark gnus-ticked-mark)
9661 (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9662 (if (= mark gnus-dormant-mark)
9663 (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))))
9664
9665 (defalias 'gnus-summary-mark-as-unread-forward
9666 'gnus-summary-tick-article-forward)
9667 (make-obsolete 'gnus-summary-mark-as-unread-forward
9668 'gnus-summary-tick-article-forward)
9669 (defun gnus-summary-tick-article-forward (n)
9670 "Tick N articles forwards.
9671 If N is negative, tick backwards instead.
9672 The difference between N and the number of articles ticked is returned."
9673 (interactive "p")
9674 (gnus-summary-mark-forward n gnus-ticked-mark))
9675
9676 (defalias 'gnus-summary-mark-as-unread-backward
9677 'gnus-summary-tick-article-backward)
9678 (make-obsolete 'gnus-summary-mark-as-unread-backward
9679 'gnus-summary-tick-article-backward)
9680 (defun gnus-summary-tick-article-backward (n)
9681 "Tick N articles backwards.
9682 The difference between N and the number of articles ticked is returned."
9683 (interactive "p")
9684 (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9685
9686 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9687 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9688 (defun gnus-summary-tick-article (&optional article clear-mark)
9689 "Mark current article as unread.
9690 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9691 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9692 (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9693 gnus-ticked-mark)))
9694
9695 (defun gnus-summary-mark-as-read-forward (n)
9696 "Mark N articles as read forwards.
9697 If N is negative, mark backwards instead.
9698 The difference between N and the actual number of articles marked is
9699 returned."
9700 (interactive "p")
9701 (gnus-summary-mark-forward n gnus-del-mark t))
9702
9703 (defun gnus-summary-mark-as-read-backward (n)
9704 "Mark the N articles as read backwards.
9705 The difference between N and the actual number of articles marked is
9706 returned."
9707 (interactive "p")
9708 (gnus-summary-mark-forward (- n) gnus-del-mark t))
9709
9710 (defun gnus-summary-mark-as-read (&optional article mark)
9711 "Mark current article as read.
9712 ARTICLE specifies the article to be marked as read.
9713 MARK specifies a string to be inserted at the beginning of the line."
9714 (gnus-summary-mark-article article mark))
9715
9716 (defun gnus-summary-clear-mark-forward (n)
9717 "Clear marks from N articles forward.
9718 If N is negative, clear backward instead.
9719 The difference between N and the number of marks cleared is returned."
9720 (interactive "p")
9721 (gnus-summary-mark-forward n gnus-unread-mark))
9722
9723 (defun gnus-summary-clear-mark-backward (n)
9724 "Clear marks from N articles backward.
9725 The difference between N and the number of marks cleared is returned."
9726 (interactive "p")
9727 (gnus-summary-mark-forward (- n) gnus-unread-mark))
9728
9729 (defun gnus-summary-mark-unread-as-read ()
9730 "Intended to be used by `gnus-summary-mark-article-hook'."
9731 (or (memq gnus-current-article gnus-newsgroup-marked)
9732 (memq gnus-current-article gnus-newsgroup-dormant)
9733 (memq gnus-current-article gnus-newsgroup-expirable)
9734 (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9735
9736 (defun gnus-summary-mark-region-as-read (point mark all)
9737 "Mark all unread articles between point and mark as read.
9738 If given a prefix, mark all articles between point and mark as read,
9739 even ticked and dormant ones."
9740 (interactive "r\nP")
9741 (save-excursion
9742 (goto-char point)
9743 (beginning-of-line)
9744 (while (and
9745 (< (point) mark)
9746 (progn
9747 (and
9748 (or all
9749 (and
9750 (not (memq (gnus-summary-article-number)
9751 gnus-newsgroup-marked))
9752 (not (memq (gnus-summary-article-number)
9753 gnus-newsgroup-dormant))))
9754 (gnus-summary-mark-article
9755 (gnus-summary-article-number) gnus-del-mark))
9756 t)
9757 (zerop (forward-line 1))))))
9758
9759 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
9760 (defalias 'gnus-summary-delete-marked-as-read
9761 'gnus-summary-remove-lines-marked-as-read)
9762 (make-obsolete 'gnus-summary-delete-marked-as-read
9763 'gnus-summary-remove-lines-marked-as-read)
9764 (defun gnus-summary-remove-lines-marked-as-read ()
9765 "Remove lines that are marked as read."
9766 (interactive)
9767 (gnus-summary-remove-lines-marked-with
9768 (concat (mapconcat
9769 (lambda (char) (char-to-string (symbol-value char)))
9770 '(gnus-del-mark gnus-read-mark gnus-ancient-mark
9771 gnus-killed-mark gnus-kill-file-mark
9772 gnus-low-score-mark gnus-expirable-mark
9773 gnus-canceled-mark gnus-catchup-mark)
9774 ""))))
9775
9776 (defalias 'gnus-summary-delete-marked-with
9777 'gnus-summary-remove-lines-marked-with)
9778 (make-obsolete 'gnus-summary-delete-marked-with
9779 'gnus-summary-remove-lines-marked-with)
9780 ;; Rewrite by Daniel Quinlan <quinlan@best.com>.
9781 (defun gnus-summary-remove-lines-marked-with (marks)
9782 "Remove lines that are marked with MARKS (e.g. \"DK\")."
9783 (interactive "sMarks: ")
9784 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
9785 (gnus-set-global-variables)
9786 (let ((buffer-read-only nil)
9787 (orig-article
9788 (let ((gnus-summary-check-current t))
9789 (gnus-summary-search-forward t)
9790 (gnus-summary-article-number)))
9791 (marks (concat "^[" marks "]")))
9792 (goto-char (point-min))
9793 (if gnus-newsgroup-adaptive
9794 (gnus-score-remove-lines-adaptive marks)
9795 (while (re-search-forward marks nil t)
9796 (gnus-delete-line)))
9797 ;; If we use dummy roots, we have to do an additional sweep over
9798 ;; the buffer.
9799 (if (not (eq gnus-summary-make-false-root 'dummy))
9800 ()
9801 (goto-char (point-min))
9802 (setq marks (concat "^[" (char-to-string gnus-dummy-mark) "]"))
9803 (while (re-search-forward marks nil t)
9804 (if (gnus-subject-equal
9805 (gnus-summary-subject-string)
9806 (progn
9807 (forward-line 1)
9808 (gnus-summary-subject-string)))
9809 ()
9810 (forward-line -1)
9811 (gnus-delete-line))))
9812 (or (zerop (buffer-size))
9813 (gnus-summary-goto-subject orig-article)
9814 (if (eobp)
9815 (gnus-summary-prev-subject 1)
9816 (gnus-summary-position-cursor)))))
9817
9818 (defun gnus-summary-expunge-below (&optional score)
9819 "Remove articles with score less than SCORE."
9820 (interactive "P")
9821 (gnus-set-global-variables)
9822 (setq score (if score
9823 (prefix-numeric-value score)
9824 (or gnus-summary-default-score 0)))
9825 (save-excursion
9826 (set-buffer gnus-summary-buffer)
9827 (goto-char (point-min))
9828 (let ((buffer-read-only nil)
9829 beg)
9830 (while (not (eobp))
9831 (if (< (gnus-summary-article-score) score)
9832 (progn
9833 (setq beg (point))
9834 (forward-line 1)
9835 (delete-region beg (point)))
9836 (forward-line 1)))
9837 ;; Adjust point.
9838 (or (zerop (buffer-size))
9839 (if (eobp)
9840 (gnus-summary-prev-subject 1)
9841 (gnus-summary-position-cursor))))))
9842
9843 (defun gnus-summary-mark-below (score mark)
9844 "Mark articles with score less than SCORE with MARK."
9845 (interactive "P\ncMark: ")
9846 (gnus-set-global-variables)
9847 (setq score (if score
9848 (prefix-numeric-value score)
9849 (or gnus-summary-default-score 0)))
9850 (save-excursion
9851 (set-buffer gnus-summary-buffer)
9852 (goto-char (point-min))
9853 (while (not (eobp))
9854 (and (< (gnus-summary-article-score) score)
9855 (gnus-summary-mark-article nil mark))
9856 (forward-line 1))))
9857
9858 (defun gnus-summary-kill-below (&optional score)
9859 "Mark articles with score below SCORE as read."
9860 (interactive "P")
9861 (gnus-set-global-variables)
9862 (gnus-summary-mark-below score gnus-killed-mark))
9863
9864 (defun gnus-summary-clear-above (&optional score)
9865 "Clear all marks from articles with score above SCORE."
9866 (interactive "P")
9867 (gnus-set-global-variables)
9868 (gnus-summary-mark-above score gnus-unread-mark))
9869
9870 (defun gnus-summary-tick-above (&optional score)
9871 "Tick all articles with score above SCORE."
9872 (interactive "P")
9873 (gnus-set-global-variables)
9874 (gnus-summary-mark-above score gnus-ticked-mark))
9875
9876 (defun gnus-summary-mark-above (score mark)
9877 "Mark articles with score over SCORE with MARK."
9878 (interactive "P\ncMark: ")
9879 (gnus-set-global-variables)
9880 (setq score (if score
9881 (prefix-numeric-value score)
9882 (or gnus-summary-default-score 0)))
9883 (save-excursion
9884 (set-buffer gnus-summary-buffer)
9885 (goto-char (point-min))
9886 (while (not (eobp))
9887 (if (> (gnus-summary-article-score) score)
9888 (progn
9889 (gnus-summary-mark-article nil mark)
9890 (forward-line 1))
9891 (forward-line 1)))))
9892
9893 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9894 (defun gnus-summary-show-all-expunged ()
9895 "Display all the hidden articles that were expunged for low scores."
9896 (interactive)
9897 (gnus-set-global-variables)
9898 (let ((buffer-read-only nil))
9899 (let ((scored gnus-newsgroup-scored)
9900 headers h)
9901 (while scored
9902 (or (gnus-summary-goto-subject (car (car scored)))
9903 (and (setq h (gnus-get-header-by-num (car (car scored))))
9904 (< (cdr (car scored)) gnus-summary-expunge-below)
9905 (setq headers (cons h headers))))
9906 (setq scored (cdr scored)))
9907 (or headers (error "No expunged articles hidden."))
9908 (goto-char (point-min))
9909 (save-excursion
9910 (gnus-summary-update-lines
9911 (point)
9912 (progn
9913 (gnus-summary-prepare-unthreaded (nreverse headers))
9914 (point)))))
9915 (goto-char (point-min))
9916 (gnus-summary-position-cursor)))
9917
9918 (defun gnus-summary-show-all-dormant ()
9919 "Display all the hidden articles that are marked as dormant."
9920 (interactive)
9921 (gnus-set-global-variables)
9922 (let ((buffer-read-only nil))
9923 (let ((dormant gnus-newsgroup-dormant)
9924 headers h)
9925 (while dormant
9926 (or (gnus-summary-goto-subject (car dormant))
9927 (and (setq h (gnus-get-header-by-num (car dormant)))
9928 (setq headers (cons h headers))))
9929 (setq dormant (cdr dormant)))
9930 (or headers (error "No dormant articles hidden."))
9931 (goto-char (point-min))
9932 (save-excursion
9933 (gnus-summary-update-lines
9934 (point)
9935 (progn
9936 (gnus-summary-prepare-unthreaded (nreverse headers))
9937 (point)))))
9938 (goto-char (point-min))
9939 (gnus-summary-position-cursor)))
9940
9941 (defun gnus-summary-hide-all-dormant ()
9942 "Hide all dormant articles."
9943 (interactive)
9944 (gnus-set-global-variables)
9945 (gnus-summary-remove-lines-marked-with (char-to-string gnus-dormant-mark))
9946 (gnus-summary-position-cursor))
9947
9948 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
9949 "Mark all articles not marked as unread in this newsgroup as read.
9950 If prefix argument ALL is non-nil, all articles are marked as read.
9951 If QUIETLY is non-nil, no questions will be asked.
9952 If TO-HERE is non-nil, it should be a point in the buffer. All
9953 articles before this point will be marked as read.
9954 The number of articles marked as read is returned."
9955 (interactive "P")
9956 (gnus-set-global-variables)
9957 (prog1
9958 (if (or quietly
9959 (not gnus-interactive-catchup) ;Without confirmation?
9960 gnus-expert-user
9961 (gnus-y-or-n-p
9962 (if all
9963 "Mark absolutely all articles as read? "
9964 "Mark all unread articles as read? ")))
9965 (if (and not-mark
9966 (not gnus-newsgroup-adaptive)
9967 (not gnus-newsgroup-auto-expire))
9968 (progn
9969 (and all (setq gnus-newsgroup-marked nil
9970 gnus-newsgroup-dormant nil))
9971 (setq gnus-newsgroup-unreads
9972 (append gnus-newsgroup-marked gnus-newsgroup-dormant)))
9973 ;; We actually mark all articles as canceled, which we
9974 ;; have to do when using auto-expiry or adaptive scoring.
9975 (gnus-summary-show-all-threads)
9976 (if (gnus-summary-first-subject (not all))
9977 (while (and
9978 (if to-here (< (point) to-here) t)
9979 (gnus-summary-mark-article-as-read gnus-catchup-mark)
9980 (gnus-summary-search-subject nil (not all)))))
9981 (or to-here
9982 (setq gnus-newsgroup-unreads
9983 (append gnus-newsgroup-marked
9984 gnus-newsgroup-dormant)))))
9985 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
9986 (if (and (not to-here) (eq 'nnvirtual (car method)))
9987 (nnvirtual-catchup-group
9988 (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
9989 (gnus-summary-position-cursor)))
9990
9991 (defun gnus-summary-catchup-to-here (&optional all)
9992 "Mark all unticked articles before the current one as read.
9993 If ALL is non-nil, also mark ticked and dormant articles as read."
9994 (interactive "P")
9995 (gnus-set-global-variables)
9996 (save-excursion
9997 (and (zerop (forward-line -1))
9998 (progn
9999 (end-of-line)
10000 (gnus-summary-catchup all t (point))
10001 (gnus-set-mode-line 'summary))))
10002 (gnus-summary-position-cursor))
10003
10004 (defun gnus-summary-catchup-all (&optional quietly)
10005 "Mark all articles in this newsgroup as read."
10006 (interactive "P")
10007 (gnus-set-global-variables)
10008 (gnus-summary-catchup t quietly))
10009
10010 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10011 "Mark all articles not marked as unread in this newsgroup as read, then exit.
10012 If prefix argument ALL is non-nil, all articles are marked as read."
10013 (interactive "P")
10014 (gnus-set-global-variables)
10015 (gnus-summary-catchup all quietly nil 'fast)
10016 ;; Select next newsgroup or exit.
10017 (if (and (eq gnus-auto-select-next 'quietly)
10018 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
10019 (gnus-summary-next-group nil)
10020 (gnus-summary-exit)))
10021
10022 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10023 "Mark all articles in this newsgroup as read, and then exit."
10024 (interactive "P")
10025 (gnus-set-global-variables)
10026 (gnus-summary-catchup-and-exit t quietly))
10027
10028 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
10029 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10030 "Mark all articles in this group as read and select the next group.
10031 If given a prefix, mark all articles, unread as well as ticked, as
10032 read."
10033 (interactive "P")
10034 (gnus-set-global-variables)
10035 (gnus-summary-catchup all)
10036 (gnus-summary-next-group))
10037
10038 ;; Thread-based commands.
10039
10040 (defun gnus-summary-toggle-threads (&optional arg)
10041 "Toggle showing conversation threads.
10042 If ARG is positive number, turn showing conversation threads on."
10043 (interactive "P")
10044 (gnus-set-global-variables)
10045 (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10046 (setq gnus-show-threads
10047 (if (null arg) (not gnus-show-threads)
10048 (> (prefix-numeric-value arg) 0)))
10049 (gnus-summary-prepare)
10050 (gnus-summary-goto-subject current)
10051 (gnus-summary-position-cursor)))
10052
10053 (defun gnus-summary-show-all-threads ()
10054 "Show all threads."
10055 (interactive)
10056 (gnus-set-global-variables)
10057 (save-excursion
10058 (let ((buffer-read-only nil))
10059 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10060 (gnus-summary-position-cursor))
10061
10062 (defun gnus-summary-show-thread ()
10063 "Show thread subtrees.
10064 Returns nil if no thread was there to be shown."
10065 (interactive)
10066 (gnus-set-global-variables)
10067 (let ((buffer-read-only nil)
10068 (orig (prog1 (point) (gnus-summary-hide-thread)))
10069 ;; first goto end then to beg, to have point at beg after let
10070 (end (progn (end-of-line) (point)))
10071 (beg (progn (beginning-of-line) (point))))
10072 (prog1
10073 ;; Any hidden lines here?
10074 (search-forward "\r" end t)
10075 (subst-char-in-region beg end ?\^M ?\n t)
10076 (goto-char orig)
10077 (gnus-summary-position-cursor))))
10078
10079 (defun gnus-summary-hide-all-threads ()
10080 "Hide all thread subtrees."
10081 (interactive)
10082 (gnus-set-global-variables)
10083 (save-excursion
10084 (goto-char (point-min))
10085 (gnus-summary-hide-thread)
10086 (while (and (not (eobp)) (zerop (forward-line 1)))
10087 (gnus-summary-hide-thread)))
10088 (gnus-summary-position-cursor))
10089
10090 (defun gnus-summary-hide-thread ()
10091 "Hide thread subtrees.
10092 Returns nil if no threads were there to be hidden."
10093 (interactive)
10094 (gnus-set-global-variables)
10095 (let ((buffer-read-only nil)
10096 (start (point))
10097 (level (gnus-summary-thread-level))
10098 (end (point)))
10099 ;; Go forward until either the buffer ends or the subthread
10100 ;; ends.
10101 (if (eobp)
10102 ()
10103 (while (and (zerop (forward-line 1))
10104 (> (gnus-summary-thread-level) level))
10105 (setq end (point)))
10106 (prog1
10107 (save-excursion
10108 (goto-char end)
10109 (search-backward "\n" start t))
10110 (subst-char-in-region start end ?\n ?\^M t)
10111 (forward-line -1)
10112 (gnus-summary-position-cursor)))))
10113
10114 (defun gnus-summary-go-to-next-thread (&optional previous)
10115 "Go to the same level (or less) next thread.
10116 If PREVIOUS is non-nil, go to previous thread instead.
10117 Return the article number moved to, or nil if moving was impossible."
10118 (let ((level (gnus-summary-thread-level))
10119 (article (gnus-summary-article-number)))
10120 (if previous
10121 (while (and (zerop (forward-line -1))
10122 (> (gnus-summary-thread-level) level)))
10123 (while (and (save-excursion
10124 (forward-line 1)
10125 (not (eobp)))
10126 (zerop (forward-line 1))
10127 (> (gnus-summary-thread-level) level))))
10128 (gnus-summary-recenter)
10129 (gnus-summary-position-cursor)
10130 (let ((oart (gnus-summary-article-number)))
10131 (and (/= oart article) oart))))
10132
10133 (defun gnus-summary-next-thread (n)
10134 "Go to the same level next N'th thread.
10135 If N is negative, search backward instead.
10136 Returns the difference between N and the number of skips actually
10137 done."
10138 (interactive "p")
10139 (gnus-set-global-variables)
10140 (let ((backward (< n 0))
10141 (n (abs n)))
10142 (while (and (> n 0)
10143 (gnus-summary-go-to-next-thread backward))
10144 (setq n (1- n)))
10145 (gnus-summary-position-cursor)
10146 (if (/= 0 n) (gnus-message 7 "No more threads"))
10147 n))
10148
10149 (defun gnus-summary-prev-thread (n)
10150 "Go to the same level previous N'th thread.
10151 Returns the difference between N and the number of skips actually
10152 done."
10153 (interactive "p")
10154 (gnus-set-global-variables)
10155 (gnus-summary-next-thread (- n)))
10156
10157 (defun gnus-summary-go-down-thread (&optional same)
10158 "Go down one level in the current thread.
10159 If SAME is non-nil, also move to articles of the same level."
10160 (let ((level (gnus-summary-thread-level))
10161 (start (point)))
10162 (if (and (zerop (forward-line 1))
10163 (> (gnus-summary-thread-level) level))
10164 t
10165 (goto-char start)
10166 nil)))
10167
10168 (defun gnus-summary-go-up-thread ()
10169 "Go up one level in the current thread."
10170 (let ((level (gnus-summary-thread-level))
10171 (start (point)))
10172 (while (and (zerop (forward-line -1))
10173 (>= (gnus-summary-thread-level) level)))
10174 (if (>= (gnus-summary-thread-level) level)
10175 (progn
10176 (goto-char start)
10177 nil)
10178 t)))
10179
10180 (defun gnus-summary-down-thread (n)
10181 "Go down thread N steps.
10182 If N is negative, go up instead.
10183 Returns the difference between N and how many steps down that were
10184 taken."
10185 (interactive "p")
10186 (gnus-set-global-variables)
10187 (let ((up (< n 0))
10188 (n (abs n)))
10189 (while (and (> n 0)
10190 (if up (gnus-summary-go-up-thread)
10191 (gnus-summary-go-down-thread)))
10192 (setq n (1- n)))
10193 (gnus-summary-position-cursor)
10194 (if (/= 0 n) (gnus-message 7 "Can't go further"))
10195 n))
10196
10197 (defun gnus-summary-up-thread (n)
10198 "Go up thread N steps.
10199 If N is negative, go up instead.
10200 Returns the difference between N and how many steps down that were
10201 taken."
10202 (interactive "p")
10203 (gnus-set-global-variables)
10204 (gnus-summary-down-thread (- n)))
10205
10206 (defun gnus-summary-kill-thread (&optional unmark)
10207 "Mark articles under current thread as read.
10208 If the prefix argument is positive, remove any kinds of marks.
10209 If the prefix argument is negative, tick articles instead."
10210 (interactive "P")
10211 (gnus-set-global-variables)
10212 (if unmark
10213 (setq unmark (prefix-numeric-value unmark)))
10214 (let ((killing t)
10215 (level (gnus-summary-thread-level)))
10216 (save-excursion
10217 ;; Expand the thread.
10218 (gnus-summary-show-thread)
10219 (while killing
10220 ;; Mark the article...
10221 (cond ((null unmark) (gnus-summary-mark-article-as-read
10222 gnus-killed-mark))
10223 ((> unmark 0) (gnus-summary-mark-article-as-unread
10224 gnus-unread-mark))
10225 (t (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10226 ;; ...and go forward until either the buffer ends or the subtree
10227 ;; ends.
10228 (if (not (and (zerop (forward-line 1))
10229 (> (gnus-summary-thread-level) level)))
10230 (setq killing nil))))
10231 ;; Hide killed subtrees.
10232 (and (null unmark)
10233 gnus-thread-hide-killed
10234 (gnus-summary-hide-thread))
10235 ;; If marked as read, go to next unread subject.
10236 (if (null unmark)
10237 ;; Go to next unread subject.
10238 (gnus-summary-next-subject 1 t)))
10239 (gnus-set-mode-line 'summary))
10240
10241 ;; Summary sorting commands
10242
10243 (defun gnus-summary-sort-by-number (&optional reverse)
10244 "Sort summary buffer by article number.
10245 Argument REVERSE means reverse order."
10246 (interactive "P")
10247 (gnus-set-global-variables)
10248 (gnus-summary-sort
10249 ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants
10250 ;; a function, so we wrap it.
10251 (cons (lambda () (gnus-summary-article-number))
10252 'gnus-thread-sort-by-number) reverse))
10253
10254 (defun gnus-summary-sort-by-author (&optional reverse)
10255 "Sort summary buffer by author name alphabetically.
10256 If case-fold-search is non-nil, case of letters is ignored.
10257 Argument REVERSE means reverse order."
10258 (interactive "P")
10259 (gnus-set-global-variables)
10260 (gnus-summary-sort
10261 (cons
10262 (lambda ()
10263 (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10264 extract)
10265 (if (not (vectorp header))
10266 ""
10267 (setq extract (funcall gnus-extract-address-components
10268 (mail-header-from header)))
10269 (concat (or (car extract) (cdr extract))
10270 "\r" (int-to-string (mail-header-number header))
10271 "\r" (mail-header-subject header)))))
10272 'gnus-thread-sort-by-author)
10273 reverse))
10274
10275 (defun gnus-summary-sort-by-subject (&optional reverse)
10276 "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
10277 If case-fold-search is non-nil, case of letters is ignored.
10278 Argument REVERSE means reverse order."
10279 (interactive "P")
10280 (gnus-set-global-variables)
10281 (gnus-summary-sort
10282 (cons
10283 (lambda ()
10284 (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10285 extract)
10286 (if (not (vectorp header))
10287 ""
10288 (setq extract (funcall gnus-extract-address-components
10289 (mail-header-from header)))
10290 (concat
10291 (downcase (gnus-simplify-subject (gnus-summary-subject-string) t))
10292 "\r" (int-to-string (mail-header-number header))
10293 "\r" (or (car extract) (cdr extract))))))
10294 'gnus-thread-sort-by-subject)
10295 reverse))
10296
10297 (defun gnus-summary-sort-by-date (&optional reverse)
10298 "Sort summary buffer by date.
10299 Argument REVERSE means reverse order."
10300 (interactive "P")
10301 (gnus-set-global-variables)
10302 (gnus-summary-sort
10303 (cons
10304 (lambda ()
10305 (gnus-sortable-date
10306 (mail-header-date
10307 (gnus-get-header-by-num (gnus-summary-article-number)))))
10308 'gnus-thread-sort-by-date)
10309 reverse))
10310
10311 (defun gnus-summary-sort-by-score (&optional reverse)
10312 "Sort summary buffer by score.
10313 Argument REVERSE means reverse order."
10314 (interactive "P")
10315 (gnus-set-global-variables)
10316 (gnus-summary-sort
10317 (cons (lambda () (gnus-summary-article-score))
10318 'gnus-thread-sort-by-score)
10319 (not reverse)))
10320
10321 (defvar gnus-summary-already-sorted nil)
10322 (defun gnus-summary-sort (predicate reverse)
10323 ;; Sort summary buffer by PREDICATE. REVERSE means reverse order.
10324 (if gnus-summary-already-sorted
10325 ()
10326 (let (buffer-read-only)
10327 (if (not gnus-show-threads)
10328 ;; We do untreaded sorting...
10329 (progn
10330 (goto-char (point-min))
10331 (sort-subr reverse 'forward-line 'end-of-line (car predicate)))
10332 ;; ... or we do threaded sorting.
10333 (let ((gnus-thread-sort-functions (list (cdr predicate)))
10334 (gnus-summary-prepare-hook nil)
10335 (gnus-summary-already-sorted nil))
10336 ;; We do that by simply regenerating the threads.
10337 (gnus-summary-prepare)
10338 (and gnus-show-threads
10339 gnus-thread-hide-subtree
10340 (gnus-summary-hide-all-threads))
10341 ;; If in async mode, we send some info to the backend.
10342 (and gnus-newsgroup-async
10343 (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
10344 (gnus-request-asynchronous
10345 gnus-newsgroup-name
10346 (if (and gnus-asynchronous-article-function
10347 (fboundp gnus-asynchronous-article-function))
10348 (funcall gnus-asynchronous-article-function
10349 gnus-newsgroup-threads)
10350 gnus-newsgroup-threads))))))))
10351
10352
10353 (defun gnus-sortable-date (date)
10354 "Make sortable string by string-lessp from DATE.
10355 Timezone package is used."
10356 (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S]
10357 (year (aref date 0))
10358 (month (aref date 1))
10359 (day (aref date 2)))
10360 (timezone-make-sortable-date
10361 year month day
10362 (timezone-make-time-string
10363 (aref date 3) (aref date 4) (aref date 5)))))
10364
10365
10366 ;; Summary saving commands.
10367
10368 (defun gnus-summary-save-article (&optional n)
10369 "Save the current article using the default saver function.
10370 If N is a positive number, save the N next articles.
10371 If N is a negative number, save the N previous articles.
10372 If N is nil and any articles have been marked with the process mark,
10373 save those articles instead.
10374 The variable `gnus-default-article-saver' specifies the saver function."
10375 (interactive "P")
10376 (gnus-set-global-variables)
10377 (let ((articles (gnus-summary-work-articles n)))
10378 (while articles
10379 (let ((header (gnus-get-header-by-num (car articles))))
10380 (if (vectorp header)
10381 (progn
10382 (save-window-excursion
10383 (gnus-summary-select-article t nil nil (car articles)))
10384 (or gnus-save-all-headers
10385 (gnus-article-hide-headers t))
10386 ;; Remove any X-Gnus lines.
10387 (save-excursion
10388 (save-restriction
10389 (set-buffer gnus-article-buffer)
10390 (let ((buffer-read-only nil))
10391 (goto-char (point-min))
10392 (narrow-to-region (point) (or (search-forward "\n\n" nil t)
10393 (point-max)))
10394 (while (re-search-forward "^X-Gnus" nil t)
10395 (beginning-of-line)
10396 (delete-region (point)
10397 (progn (forward-line 1) (point))))
10398 (widen))))
10399 (save-window-excursion
10400 (if gnus-default-article-saver
10401 (funcall gnus-default-article-saver)
10402 (error "No default saver is defined."))))
10403 (if (assq 'name header)
10404 (gnus-copy-file (cdr (assq 'name header)))
10405 (gnus-message 1 "Article %d is unsavable" (car articles)))))
10406 (gnus-summary-remove-process-mark (car articles))
10407 (setq articles (cdr articles)))
10408 (gnus-summary-position-cursor)
10409 n))
10410
10411 (defun gnus-summary-pipe-output (&optional arg)
10412 "Pipe the current article to a subprocess.
10413 If N is a positive number, pipe the N next articles.
10414 If N is a negative number, pipe the N previous articles.
10415 If N is nil and any articles have been marked with the process mark,
10416 pipe those articles instead."
10417 (interactive "P")
10418 (gnus-set-global-variables)
10419 (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10420 (gnus-summary-save-article arg)))
10421
10422 (defun gnus-summary-save-article-mail (&optional arg)
10423 "Append the current article to an mail file.
10424 If N is a positive number, save the N next articles.
10425 If N is a negative number, save the N previous articles.
10426 If N is nil and any articles have been marked with the process mark,
10427 save those articles instead."
10428 (interactive "P")
10429 (gnus-set-global-variables)
10430 (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10431 (gnus-summary-save-article arg)))
10432
10433 (defun gnus-summary-save-article-rmail (&optional arg)
10434 "Append the current article to an rmail file.
10435 If N is a positive number, save the N next articles.
10436 If N is a negative number, save the N previous articles.
10437 If N is nil and any articles have been marked with the process mark,
10438 save those articles instead."
10439 (interactive "P")
10440 (gnus-set-global-variables)
10441 (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10442 (gnus-summary-save-article arg)))
10443
10444 (defun gnus-summary-save-article-file (&optional arg)
10445 "Append the current article to a file.
10446 If N is a positive number, save the N next articles.
10447 If N is a negative number, save the N previous articles.
10448 If N is nil and any articles have been marked with the process mark,
10449 save those articles instead."
10450 (interactive "P")
10451 (gnus-set-global-variables)
10452 (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10453 (gnus-summary-save-article arg)))
10454
10455 (defun gnus-read-save-file-name (prompt default-name)
10456 (let ((methods gnus-split-methods)
10457 split-name)
10458 (if (not gnus-split-methods)
10459 ()
10460 (save-excursion
10461 (set-buffer gnus-article-buffer)
10462 (gnus-narrow-to-headers)
10463 (while methods
10464 (goto-char (point-min))
10465 (and (condition-case ()
10466 (re-search-forward (car (car methods)) nil t)
10467 (error nil))
10468 (setq split-name (cons (nth 1 (car methods)) split-name)))
10469 (setq methods (cdr methods)))
10470 (widen)))
10471 (cond ((null split-name)
10472 (read-file-name
10473 (concat prompt " (default "
10474 (file-name-nondirectory default-name) ") ")
10475 (file-name-directory default-name)
10476 default-name))
10477 ((= 1 (length split-name))
10478 (read-file-name
10479 (concat prompt " (default " (car split-name) ") ")
10480 gnus-article-save-directory
10481 (concat gnus-article-save-directory (car split-name))))
10482 (t
10483 (setq split-name (mapcar (lambda (el) (list el))
10484 (nreverse split-name)))
10485 (let ((result (completing-read
10486 (concat prompt " ")
10487 split-name nil nil)))
10488 (concat gnus-article-save-directory
10489 (if (string= result "")
10490 (car (car split-name))
10491 result)))))))
10492
10493 (defun gnus-summary-save-in-rmail (&optional filename)
10494 "Append this article to Rmail file.
10495 Optional argument FILENAME specifies file name.
10496 Directory to save to is default to `gnus-article-save-directory' which
10497 is initialized from the SAVEDIR environment variable."
10498 (interactive)
10499 (gnus-set-global-variables)
10500 (let ((default-name
10501 (funcall gnus-rmail-save-name gnus-newsgroup-name
10502 gnus-current-headers gnus-newsgroup-last-rmail)))
10503 (or filename
10504 (setq filename (gnus-read-save-file-name
10505 "Save in rmail file:" default-name)))
10506 (gnus-make-directory (file-name-directory filename))
10507 (gnus-eval-in-buffer-window
10508 gnus-article-buffer
10509 (save-excursion
10510 (save-restriction
10511 (widen)
10512 (gnus-output-to-rmail filename))))
10513 ;; Remember the directory name to save articles
10514 (setq gnus-newsgroup-last-rmail filename)))
10515
10516 (defun gnus-summary-save-in-mail (&optional filename)
10517 "Append this article to Unix mail file.
10518 Optional argument FILENAME specifies file name.
10519 Directory to save to is default to `gnus-article-save-directory' which
10520 is initialized from the SAVEDIR environment variable."
10521 (interactive)
10522 (gnus-set-global-variables)
10523 (let ((default-name
10524 (funcall gnus-mail-save-name gnus-newsgroup-name
10525 gnus-current-headers gnus-newsgroup-last-mail)))
10526 (or filename
10527 (setq filename (gnus-read-save-file-name
10528 "Save in Unix mail file:" default-name)))
10529 (setq filename
10530 (expand-file-name filename
10531 (and default-name
10532 (file-name-directory default-name))))
10533 (gnus-make-directory (file-name-directory filename))
10534 (gnus-eval-in-buffer-window
10535 gnus-article-buffer
10536 (save-excursion
10537 (save-restriction
10538 (widen)
10539 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
10540 (gnus-output-to-rmail filename)
10541 (rmail-output filename 1 t t)))))
10542 ;; Remember the directory name to save articles.
10543 (setq gnus-newsgroup-last-mail filename)))
10544
10545 (defun gnus-summary-save-in-file (&optional filename)
10546 "Append this article to file.
10547 Optional argument FILENAME specifies file name.
10548 Directory to save to is default to `gnus-article-save-directory' which
10549 is initialized from the SAVEDIR environment variable."
10550 (interactive)
10551 (gnus-set-global-variables)
10552 (let ((default-name
10553 (funcall gnus-file-save-name gnus-newsgroup-name
10554 gnus-current-headers gnus-newsgroup-last-file)))
10555 (or filename
10556 (setq filename (gnus-read-save-file-name
10557 "Save in file:" default-name)))
10558 (gnus-make-directory (file-name-directory filename))
10559 (gnus-eval-in-buffer-window
10560 gnus-article-buffer
10561 (save-excursion
10562 (save-restriction
10563 (widen)
10564 (gnus-output-to-file filename))))
10565 ;; Remember the directory name to save articles.
10566 (setq gnus-newsgroup-last-file filename)))
10567
10568 (defun gnus-summary-save-in-pipe (&optional command)
10569 "Pipe this article to subprocess."
10570 (interactive)
10571 (gnus-set-global-variables)
10572 (let ((command (read-string "Shell command on article: "
10573 gnus-last-shell-command)))
10574 (if (string-equal command "")
10575 (setq command gnus-last-shell-command))
10576 (gnus-eval-in-buffer-window
10577 gnus-article-buffer
10578 (save-restriction
10579 (widen)
10580 (shell-command-on-region (point-min) (point-max) command nil)))
10581 (setq gnus-last-shell-command command)))
10582
10583 ;; Summary extract commands
10584
10585 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10586 (let ((buffer-read-only nil)
10587 (article (gnus-summary-article-number))
10588 b)
10589 (or (gnus-summary-goto-subject article)
10590 (error (format "No such article: %d" article)))
10591 (gnus-summary-position-cursor)
10592 ;; If all commands are to be bunched up on one line, we collect
10593 ;; them here.
10594 (if gnus-view-pseudos-separately
10595 ()
10596 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10597 files action)
10598 (while ps
10599 (setq action (cdr (assq 'action (car ps))))
10600 (setq files (list (cdr (assq 'name (car ps)))))
10601 (while (and ps (cdr ps)
10602 (string= (or action "1")
10603 (or (cdr (assq 'action (car (cdr ps)))) "2")))
10604 (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
10605 (setcdr ps (cdr (cdr ps))))
10606 (if (not files)
10607 ()
10608 (if (not (string-match "%s" action))
10609 (setq files (cons " " files)))
10610 (setq files (cons " " files))
10611 (and (assq 'execute (car ps))
10612 (setcdr (assq 'execute (car ps))
10613 (funcall (if (string-match "%s" action)
10614 'format 'concat)
10615 action
10616 (mapconcat (lambda (f) f) files " ")))))
10617 (setq ps (cdr ps)))))
10618 (if (and gnus-view-pseudos (not not-view))
10619 (while pslist
10620 (and (assq 'execute (car pslist))
10621 (gnus-execute-command (cdr (assq 'execute (car pslist)))
10622 (eq gnus-view-pseudos 'not-confirm)))
10623 (setq pslist (cdr pslist)))
10624 (save-excursion
10625 (while pslist
10626 (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
10627 (gnus-summary-article-number)))
10628 (forward-line 1)
10629 (setq b (point))
10630 (insert " " (file-name-nondirectory
10631 (cdr (assq 'name (car pslist))))
10632 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10633 (add-text-properties
10634 b (1+ b) (list 'gnus-number gnus-reffed-article-number
10635 'gnus-mark gnus-unread-mark
10636 'gnus-level 0
10637 'gnus-pseudo (car pslist)))
10638 (forward-line -1)
10639 (gnus-sethash (int-to-string gnus-reffed-article-number)
10640 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
10641 (setq gnus-newsgroup-unreads
10642 (cons gnus-reffed-article-number gnus-newsgroup-unreads))
10643 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10644 (setq pslist (cdr pslist)))))))
10645
10646 (defun gnus-pseudos< (p1 p2)
10647 (let ((c1 (cdr (assq 'action p1)))
10648 (c2 (cdr (assq 'action p2))))
10649 (and c1 c2 (string< c1 c2))))
10650
10651 (defun gnus-request-pseudo-article (props)
10652 (cond ((assq 'execute props)
10653 (gnus-execute-command (cdr (assq 'execute props)))))
10654 (let ((gnus-current-article (gnus-summary-article-number)))
10655 (run-hooks 'gnus-mark-article-hook)))
10656
10657 (defun gnus-execute-command (command &optional automatic)
10658 (save-excursion
10659 (gnus-article-setup-buffer)
10660 (set-buffer gnus-article-buffer)
10661 (let ((command (if automatic command (read-string "Command: " command)))
10662 (buffer-read-only nil))
10663 (erase-buffer)
10664 (insert "$ " command "\n\n")
10665 (if gnus-view-pseudo-asynchronously
10666 (start-process "gnus-execute" nil "sh" "-c" command)
10667 (call-process "sh" nil t nil "-c" command)))))
10668
10669 (defun gnus-copy-file (file &optional to)
10670 "Copy FILE to TO."
10671 (interactive
10672 (list (read-file-name "Copy file: " default-directory)
10673 (read-file-name "Copy file to: " default-directory)))
10674 (gnus-set-global-variables)
10675 (or to (setq to (read-file-name "Copy file to: " default-directory)))
10676 (and (file-directory-p to)
10677 (setq to (concat (file-name-as-directory to)
10678 (file-name-nondirectory file))))
10679 (copy-file file to))
10680
10681 ;; Summary kill commands.
10682
10683 (defun gnus-summary-edit-global-kill (article)
10684 "Edit the \"global\" kill file."
10685 (interactive (list (gnus-summary-article-number)))
10686 (gnus-set-global-variables)
10687 (gnus-group-edit-global-kill article))
10688
10689 (defun gnus-summary-edit-local-kill ()
10690 "Edit a local kill file applied to the current newsgroup."
10691 (interactive)
10692 (gnus-set-global-variables)
10693 (setq gnus-current-headers
10694 (gnus-gethash
10695 (int-to-string (gnus-summary-article-number))
10696 gnus-newsgroup-headers-hashtb-by-number))
10697 (gnus-set-global-variables)
10698 (gnus-group-edit-local-kill
10699 (gnus-summary-article-number) gnus-newsgroup-name))
10700
10701 \f
10702 ;;;
10703 ;;; Gnus article mode
10704 ;;;
10705
10706 (put 'gnus-article-mode 'mode-class 'special)
10707
10708 (defvar gnus-bugaboo nil)
10709
10710 (if gnus-article-mode-map
10711 nil
10712 (setq gnus-article-mode-map (make-keymap))
10713 (suppress-keymap gnus-article-mode-map)
10714 (define-key gnus-article-mode-map " " 'gnus-article-next-page)
10715 (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
10716 (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article)
10717 (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
10718 (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
10719 (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail)
10720 (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
10721 (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button)
10722 (define-key gnus-article-mode-map "\r" 'gnus-article-press-button)
10723 (define-key gnus-article-mode-map "\t" 'gnus-article-next-button)
10724 (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug)
10725
10726 ;; Duplicate almost all summary keystrokes in the article mode map.
10727 (let ((commands
10728 (list
10729 "p" "N" "P" "\M-\C-n" "\M-\C-p"
10730 "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j"
10731 "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k"
10732 "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h"
10733 "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w"
10734 "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a"
10735 "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s"
10736 "\M-g" "w" "\C-c\C-r" "\M-t" "C"
10737 "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d"
10738 "\C-c\C-i" "x" "X" "t" "g" "?" "l"
10739 "\C-c\C-v\C-v" "\C-d" "v"
10740 ;; "Mt" "M!" "Md" "Mr"
10741 ;; "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r"
10742 ;; "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK"
10743 ;; "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p"
10744 ;; "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT"
10745 ;; "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap"
10746 ;; "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am"
10747 ;; "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t"
10748 ;; "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi"
10749 ;; "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or"
10750 ;; "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve"
10751 ;; "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi"
10752 )))
10753 (while (and gnus-bugaboo commands) ; disabled
10754 (define-key gnus-article-mode-map (car commands)
10755 'gnus-article-summary-command)
10756 (setq commands (cdr commands))))
10757
10758 (let ((commands (list "q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
10759 ;; "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
10760 "=" "n" "^" "\M-^")))
10761 (while (and gnus-bugaboo commands) ; disabled
10762 (define-key gnus-article-mode-map (car commands)
10763 'gnus-article-summary-command-nosave)
10764 (setq commands (cdr commands)))))
10765
10766
10767 (defun gnus-article-mode ()
10768 "Major mode for displaying an article.
10769
10770 All normal editing commands are switched off.
10771
10772 The following commands are available:
10773
10774 \\<gnus-article-mode-map>
10775 \\[gnus-article-next-page]\t Scroll the article one page forwards
10776 \\[gnus-article-prev-page]\t Scroll the article one page backwards
10777 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
10778 \\[gnus-article-show-summary]\t Display the summary buffer
10779 \\[gnus-article-mail]\t Send a reply to the address near point
10780 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
10781 \\[gnus-info-find-node]\t Go to the Gnus info node"
10782 (interactive)
10783 (if gnus-visual (gnus-article-make-menu-bar))
10784 (kill-all-local-variables)
10785 (gnus-simplify-mode-line)
10786 (setq mode-name "Article")
10787 (setq major-mode 'gnus-article-mode)
10788 (make-local-variable 'minor-mode-alist)
10789 (or (assq 'gnus-show-mime minor-mode-alist)
10790 (setq minor-mode-alist
10791 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
10792 (use-local-map gnus-article-mode-map)
10793 (make-local-variable 'page-delimiter)
10794 (setq page-delimiter gnus-page-delimiter)
10795 (buffer-disable-undo (current-buffer))
10796 (setq buffer-read-only t) ;Disable modification
10797 (run-hooks 'gnus-article-mode-hook))
10798
10799 (defun gnus-article-setup-buffer ()
10800 "Initialize article mode buffer."
10801 ;; Returns the article buffer.
10802 (if (get-buffer gnus-article-buffer)
10803 (save-excursion
10804 (set-buffer gnus-article-buffer)
10805 (buffer-disable-undo (current-buffer))
10806 (setq buffer-read-only t)
10807 (gnus-add-current-to-buffer-list)
10808 (or (eq major-mode 'gnus-article-mode)
10809 (gnus-article-mode))
10810 (current-buffer))
10811 (save-excursion
10812 (set-buffer (get-buffer-create gnus-article-buffer))
10813 (gnus-add-current-to-buffer-list)
10814 (gnus-article-mode)
10815 (current-buffer))))
10816
10817 ;; Set article window start at LINE, where LINE is the number of lines
10818 ;; from the head of the article.
10819 (defun gnus-article-set-window-start (&optional line)
10820 (set-window-start
10821 (get-buffer-window gnus-article-buffer)
10822 (save-excursion
10823 (set-buffer gnus-article-buffer)
10824 (goto-char (point-min))
10825 (if (not line)
10826 (point-min)
10827 (gnus-message 6 "Moved to bookmark")
10828 (search-forward "\n\n" nil t)
10829 (forward-line line)
10830 (point)))))
10831
10832 (defun gnus-request-article-this-buffer (article group)
10833 "Get an article and insert it into this buffer."
10834 (setq group (or group gnus-newsgroup-name))
10835
10836 ;; Open server if it has closed.
10837 (gnus-check-server (gnus-find-method-for-group group))
10838
10839 ;; Using `gnus-request-article' directly will insert the article into
10840 ;; `nntp-server-buffer' - so we'll save some time by not having to
10841 ;; copy it from the server buffer into the article buffer.
10842
10843 ;; We only request an article by message-id when we do not have the
10844 ;; headers for it, so we'll have to get those.
10845 (and (stringp article)
10846 (let ((gnus-override-method gnus-refer-article-method))
10847 (gnus-read-header article)))
10848
10849 ;; If the article number is negative, that means that this article
10850 ;; doesn't belong in this newsgroup (possibly), so we find its
10851 ;; message-id and request it by id instead of number.
10852 (if (not (numberp article))
10853 ()
10854 (save-excursion
10855 (set-buffer gnus-summary-buffer)
10856 (let ((header (gnus-get-header-by-num article)))
10857 (if (< article 0)
10858 (if (vectorp header)
10859 ;; It's a real article.
10860 (setq article (mail-header-id header))
10861 ;; It is an extracted pseudo-article.
10862 (setq article 'pseudo)
10863 (gnus-request-pseudo-article header)))
10864
10865 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
10866 (if (not (eq (car method) 'nneething))
10867 ()
10868 (let ((dir (concat (file-name-as-directory (nth 1 method))
10869 (mail-header-subject header))))
10870 (if (file-directory-p dir)
10871 (progn
10872 (setq article 'nneething)
10873 (gnus-group-enter-directory dir)))))))))
10874
10875 ;; Check the cache.
10876 (if (and gnus-use-cache
10877 (numberp article)
10878 (gnus-cache-request-article article group))
10879 'article
10880 ;; Get the article and put into the article buffer.
10881 (if (or (stringp article) (numberp article))
10882 (progn
10883 (erase-buffer)
10884 ;; There may be some overlays that we have to kill...
10885 (insert "i")
10886 (let ((overlays (and (fboundp 'overlays-at)
10887 (overlays-at (point-min)))))
10888 (while overlays
10889 (delete-overlay (car overlays))
10890 (setq overlays (cdr overlays))))
10891 (erase-buffer)
10892 (let ((gnus-override-method
10893 (and (stringp article) gnus-refer-article-method)))
10894 (and (gnus-request-article article group (current-buffer))
10895 'article)))
10896 article)))
10897
10898 (defun gnus-read-header (id)
10899 "Read the headers of article ID and enter them into the Gnus system."
10900 (let (header)
10901 (if (not (setq header
10902 (car (if (let ((gnus-nov-is-evil t))
10903 (gnus-retrieve-headers
10904 (list id) gnus-newsgroup-name))
10905 (gnus-get-newsgroup-headers)))))
10906 nil
10907 (if (stringp id)
10908 (mail-header-set-number header gnus-reffed-article-number))
10909 (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers))
10910 (gnus-sethash (int-to-string (mail-header-number header)) header
10911 gnus-newsgroup-headers-hashtb-by-number)
10912 (if (stringp id)
10913 (setq gnus-reffed-article-number (1- gnus-reffed-article-number)))
10914 (setq gnus-current-headers header)
10915 header)))
10916
10917 (defun gnus-article-prepare (article &optional all-headers header)
10918 "Prepare ARTICLE in article mode buffer.
10919 ARTICLE should either be an article number or a Message-ID.
10920 If ARTICLE is an id, HEADER should be the article headers.
10921 If ALL-HEADERS is non-nil, no headers are hidden."
10922 (save-excursion
10923 ;; Make sure we start in a summary buffer.
10924 (or (eq major-mode 'gnus-summary-mode)
10925 (set-buffer gnus-summary-buffer))
10926 (setq gnus-summary-buffer (current-buffer))
10927 ;; Make sure the connection to the server is alive.
10928 (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name))
10929 (progn
10930 (gnus-check-server
10931 (gnus-find-method-for-group gnus-newsgroup-name))
10932 (gnus-request-group gnus-newsgroup-name t)))
10933 (let* ((article (if header (mail-header-number header) article))
10934 (summary-buffer (current-buffer))
10935 (internal-hook gnus-article-internal-prepare-hook)
10936 (group gnus-newsgroup-name)
10937 result)
10938 (save-excursion
10939 (gnus-article-setup-buffer)
10940 (set-buffer gnus-article-buffer)
10941 (if (not (setq result (let ((buffer-read-only nil))
10942 (gnus-request-article-this-buffer
10943 article group))))
10944 ;; There is no such article.
10945 (save-excursion
10946 (if (not (numberp article))
10947 ()
10948 (setq gnus-article-current
10949 (cons gnus-newsgroup-name article))
10950 (set-buffer gnus-summary-buffer)
10951 (setq gnus-current-article article)
10952 (gnus-summary-mark-article article gnus-canceled-mark))
10953 (gnus-message 1 "No such article (may be canceled)")
10954 (ding)
10955 nil)
10956 (if (or (eq result 'pseudo) (eq result 'nneething))
10957 (progn
10958 (save-excursion
10959 (set-buffer summary-buffer)
10960 (setq gnus-last-article gnus-current-article
10961 gnus-newsgroup-history (cons gnus-current-article
10962 gnus-newsgroup-history)
10963 gnus-current-article 0
10964 gnus-current-headers nil
10965 gnus-article-current nil)
10966 (if (eq result 'nneething)
10967 (gnus-configure-windows 'summary)
10968 (gnus-configure-windows 'article))
10969 (gnus-set-global-variables))
10970 (gnus-set-mode-line 'article))
10971 ;; The result from the `request' was an actual article -
10972 ;; or at least some text that is now displayed in the
10973 ;; article buffer.
10974 (if (and (numberp article)
10975 (not (eq article gnus-current-article)))
10976 ;; Seems like a new article has been selected.
10977 ;; `gnus-current-article' must be an article number.
10978 (save-excursion
10979 (set-buffer summary-buffer)
10980 (setq gnus-last-article gnus-current-article
10981 gnus-newsgroup-history (cons gnus-current-article
10982 gnus-newsgroup-history)
10983 gnus-current-article article
10984 gnus-current-headers
10985 (gnus-get-header-by-num gnus-current-article)
10986 gnus-article-current
10987 (cons gnus-newsgroup-name gnus-current-article))
10988 (gnus-summary-show-thread)
10989 (run-hooks 'gnus-mark-article-hook)
10990 (gnus-set-mode-line 'summary)
10991 (and gnus-visual
10992 (run-hooks 'gnus-visual-mark-article-hook))
10993 ;; Set the global newsgroup variables here.
10994 ;; Suggested by Jim Sisolak
10995 ;; <sisolak@trans4.neep.wisc.edu>.
10996 (gnus-set-global-variables)
10997 (setq gnus-have-all-headers
10998 (or all-headers gnus-show-all-headers))
10999 (and gnus-use-cache
11000 (vectorp (gnus-get-header-by-number article))
11001 (gnus-cache-possibly-enter-article
11002 group article
11003 (gnus-get-header-by-number article)
11004 (memq article gnus-newsgroup-marked)
11005 (memq article gnus-newsgroup-dormant)
11006 (memq article gnus-newsgroup-unreads)))))
11007 ;; Hooks for getting information from the article.
11008 ;; This hook must be called before being narrowed.
11009 (let (buffer-read-only)
11010 (run-hooks 'internal-hook)
11011 (run-hooks 'gnus-article-prepare-hook)
11012 ;; Decode MIME message.
11013 (if (and gnus-show-mime
11014 (or (not gnus-strict-mime)
11015 (gnus-fetch-field "Mime-Version")))
11016 (funcall gnus-show-mime-method))
11017 ;; Perform the article display hooks.
11018 (run-hooks 'gnus-article-display-hook))
11019 ;; Do page break.
11020 (goto-char (point-min))
11021 (and gnus-break-pages (gnus-narrow-to-page))
11022 (gnus-set-mode-line 'article)
11023 (gnus-configure-windows 'article)
11024 (goto-char (point-min))
11025 t))))))
11026
11027 (defun gnus-article-show-all-headers ()
11028 "Show all article headers in article mode buffer."
11029 (save-excursion
11030 (gnus-article-setup-buffer)
11031 (set-buffer gnus-article-buffer)
11032 (let ((buffer-read-only nil))
11033 (remove-text-properties (point-min) (point-max)
11034 gnus-hidden-properties))))
11035
11036 (defun gnus-article-hide-headers-if-wanted ()
11037 "Hide unwanted headers if `gnus-have-all-headers' is nil.
11038 Provided for backwards compatibility."
11039 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
11040 (gnus-article-hide-headers)))
11041
11042 (defun gnus-article-hide-headers (&optional delete)
11043 "Hide unwanted headers and possibly sort them as well."
11044 (interactive "P")
11045 (save-excursion
11046 (set-buffer gnus-article-buffer)
11047 (save-restriction
11048 (let ((sorted gnus-sorted-header-list)
11049 (buffer-read-only nil)
11050 want-list beg want-l)
11051 ;; First we narrow to just the headers.
11052 (widen)
11053 (goto-char (point-min))
11054 ;; Hide any "From " lines at the beginning of (mail) articles.
11055 (while (looking-at "From ")
11056 (forward-line 1))
11057 (or (bobp)
11058 (add-text-properties (point-min) (point) gnus-hidden-properties))
11059 ;; Then treat the rest of the header lines.
11060 (narrow-to-region
11061 (point)
11062 (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
11063 ;; Then we use the two regular expressions
11064 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
11065 ;; select which header lines is to remain visible in the
11066 ;; article buffer.
11067 (goto-char (point-min))
11068 (while (re-search-forward "^[^ \t]*:" nil t)
11069 (beginning-of-line)
11070 ;; We add the headers we want to keep to a list and delete
11071 ;; them from the buffer.
11072 (if (or (and (stringp gnus-visible-headers)
11073 (looking-at gnus-visible-headers))
11074 (and (not (stringp gnus-visible-headers))
11075 (stringp gnus-ignored-headers)
11076 (not (looking-at gnus-ignored-headers))))
11077 (progn
11078 (setq beg (point))
11079 (forward-line 1)
11080 ;; Be sure to get multi-line headers...
11081 (re-search-forward "^[^ \t]*:" nil t)
11082 (beginning-of-line)
11083 (setq want-list
11084 (cons (buffer-substring beg (point)) want-list))
11085 (delete-region beg (point))
11086 (goto-char beg))
11087 (forward-line 1)))
11088 ;; Next we perform the sorting by looking at
11089 ;; `gnus-sorted-header-list'.
11090 (goto-char (point-min))
11091 (while (and sorted want-list)
11092 (setq want-l want-list)
11093 (while (and want-l
11094 (not (string-match (car sorted) (car want-l))))
11095 (setq want-l (cdr want-l)))
11096 (if want-l
11097 (progn
11098 (insert (car want-l))
11099 (setq want-list (delq (car want-l) want-list))))
11100 (setq sorted (cdr sorted)))
11101 ;; Any headers that were not matched by the sorted list we
11102 ;; just tack on the end of the visible header list.
11103 (while want-list
11104 (insert (car want-list))
11105 (setq want-list (cdr want-list)))
11106 ;; And finally we make the unwanted headers invisible.
11107 (if delete
11108 (delete-region (point) (point-max))
11109 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
11110 (add-text-properties (point) (point-max) gnus-hidden-properties))))))
11111
11112 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
11113 (defun gnus-article-treat-overstrike ()
11114 "Translate overstrikes into bold text."
11115 (interactive)
11116 (save-excursion
11117 (set-buffer gnus-article-buffer)
11118 (let ((buffer-read-only nil))
11119 (while (search-forward "\b" nil t)
11120 (let ((next (following-char))
11121 (previous (char-after (- (point) 2))))
11122 (cond ((eq next previous)
11123 (put-text-property (- (point) 2) (point)
11124 'invisible t)
11125 (put-text-property (point) (1+ (point))
11126 'face 'bold))
11127 ((eq next ?_)
11128 (put-text-property (1- (point)) (1+ (point))
11129 'invisible t)
11130 (put-text-property (1- (point)) (point)
11131 'face 'underline))
11132 ((eq previous ?_)
11133 (put-text-property (- (point) 2) (point)
11134 'invisible t)
11135 (put-text-property (point) (1+ (point))
11136 'face 'underline))))))))
11137
11138 (defun gnus-article-word-wrap ()
11139 "Format too long lines."
11140 (interactive)
11141 (save-excursion
11142 (set-buffer gnus-article-buffer)
11143 (let ((buffer-read-only nil))
11144 (goto-char (point-min))
11145 (search-forward "\n\n" nil t)
11146 (end-of-line 1)
11147 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
11148 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
11149 (adaptive-fill-mode t))
11150 (while (not (eobp))
11151 (and (>= (current-column) (min fill-column (window-width)))
11152 (/= (preceding-char) ?:)
11153 (fill-paragraph nil))
11154 (end-of-line 2))))))
11155
11156 (defun gnus-article-remove-cr ()
11157 "Remove carriage returns from an article."
11158 (interactive)
11159 (save-excursion
11160 (set-buffer gnus-article-buffer)
11161 (let ((buffer-read-only nil))
11162 (goto-char (point-min))
11163 (while (search-forward "\r" nil t)
11164 (replace-match "" t t)))))
11165
11166 (defun gnus-article-display-x-face (&optional force)
11167 "Look for an X-Face header and display it if present."
11168 (interactive (list 'force))
11169 (save-excursion
11170 (set-buffer gnus-article-buffer)
11171 (let ((inhibit-point-motion-hooks t)
11172 (case-fold-search nil)
11173 from)
11174 (save-restriction
11175 (goto-char (point-min))
11176 (search-forward "\n\n")
11177 (narrow-to-region (point-min) (point))
11178 (goto-char (point-min))
11179 (setq from (mail-fetch-field "from"))
11180 (if (not (and gnus-article-x-face-command
11181 (or force
11182 (not gnus-article-x-face-too-ugly)
11183 (and gnus-article-x-face-too-ugly from
11184 (not (string-match gnus-article-x-face-too-ugly
11185 from))))
11186 (progn
11187 (goto-char (point-min))
11188 (re-search-forward "^X-Face: " nil t))))
11189 nil
11190 (let ((beg (point))
11191 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
11192 (if (symbolp gnus-article-x-face-command)
11193 (and (or (fboundp gnus-article-x-face-command)
11194 (error "%s is not a function"
11195 gnus-article-x-face-command))
11196 (funcall gnus-article-x-face-command beg end))
11197 (call-process-region beg end "sh" nil 0 nil
11198 "-c" gnus-article-x-face-command))))))))
11199
11200 (defun gnus-article-de-quoted-unreadable (&optional force)
11201 "Do a naive translation of a quoted-printable-encoded article.
11202 This is in no way, shape or form meant as a replacement for real MIME
11203 processing, but is simply a stop-gap measure until MIME support is
11204 written.
11205 If FORCE, decode the article whether it is marked as quoted-printable
11206 or not."
11207 (interactive (list 'force))
11208 (save-excursion
11209 (set-buffer gnus-article-buffer)
11210 (let ((case-fold-search t)
11211 (buffer-read-only nil)
11212 (type (gnus-fetch-field "content-transfer-encoding")))
11213 (if (or force (and type (string-match "quoted-printable" type)))
11214 (progn
11215 (goto-char (point-min))
11216 (search-forward "\n\n" nil 'move)
11217 (gnus-mime-decode-quoted-printable (point) (point-max)))))))
11218
11219 (defun gnus-mime-decode-quoted-printable (from to)
11220 ;; Decode quoted-printable from region between FROM and TO.
11221 (save-excursion
11222 (goto-char from)
11223 (while (search-forward "=" to t)
11224 (cond ((eq (following-char) ?\n)
11225 (delete-char -1)
11226 (delete-char 1))
11227 ((looking-at "[0-9A-F][0-9A-F]")
11228 (delete-char -1)
11229 (insert (hexl-hex-string-to-integer
11230 (buffer-substring (point) (+ 2 (point)))))
11231 (delete-char 2))
11232 ((looking-at "=")
11233 (delete-char 1))
11234 ((gnus-message 3 "Malformed MIME quoted-printable message"))))))
11235
11236 (defvar gnus-article-time-units
11237 (list (cons 'year (* 365.25 24 60 60))
11238 (cons 'week (* 7 24 60 60))
11239 (cons 'day (* 24 60 60))
11240 (cons 'hour (* 60 60))
11241 (cons 'minute 60)
11242 (cons 'second 1)))
11243
11244 (defun gnus-article-date-ut (&optional type)
11245 "Convert DATE date to universal time in the current article.
11246 If TYPE is `local', convert to local time; if it is `lapsed', output
11247 how much time has lapsed since DATE."
11248 (interactive (list 'ut))
11249 (let ((date (mail-header-date (or gnus-current-headers
11250 (gnus-get-header-by-number
11251 (gnus-summary-article-number))"")))
11252 (date-regexp "^Date: \\|^X-Sent: "))
11253 (if (or (not date)
11254 (string= date ""))
11255 ()
11256 (save-excursion
11257 (set-buffer gnus-article-buffer)
11258 (let ((buffer-read-only nil))
11259 (goto-char (point-min))
11260 (if (and (re-search-forward date-regexp nil t)
11261 (progn
11262 (beginning-of-line)
11263 (looking-at date-regexp)))
11264 (delete-region (gnus-point-at-bol)
11265 (progn (end-of-line) (1+ (point))))
11266 (goto-char (point-min))
11267 (goto-char (- (search-forward "\n\n") 2)))
11268 (insert
11269 (cond
11270 ((eq type 'local)
11271 (concat "Date: " (condition-case ()
11272 (timezone-make-date-arpa-standard date)
11273 (error date))
11274 "\n"))
11275 ((eq type 'ut)
11276 (concat "Date: "
11277 (condition-case ()
11278 (timezone-make-date-arpa-standard date nil "UT")
11279 (error date))
11280 "\n"))
11281 ((eq type 'lapsed)
11282 ;; If the date is seriously mangled, the timezone
11283 ;; functions are liable to bug out, so we condition-case
11284 ;; the entire thing.
11285 (let* ((real-sec (condition-case ()
11286 (- (gnus-seconds-since-epoch
11287 (timezone-make-date-arpa-standard
11288 (current-time-string)
11289 (current-time-zone) "UT"))
11290 (gnus-seconds-since-epoch
11291 (timezone-make-date-arpa-standard
11292 date nil "UT")))
11293 (error 0)))
11294 (sec (abs real-sec))
11295 num prev)
11296 (if (zerop sec)
11297 "X-Sent: Now\n"
11298 (concat
11299 "X-Sent: "
11300 (mapconcat
11301 (lambda (unit)
11302 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
11303 ""
11304 (setq sec (- sec (* num (cdr unit))))
11305 (prog1
11306 (concat (if prev ", " "") (int-to-string
11307 (floor num))
11308 " " (symbol-name (car unit))
11309 (if (> num 1) "s" ""))
11310 (setq prev t))))
11311 gnus-article-time-units "")
11312 (if (> real-sec 0)
11313 " ago\n"
11314 " in the future\n")))))
11315 (t
11316 (error "Unknown conversion type: %s" type)))))))))
11317
11318 (defun gnus-article-date-local ()
11319 "Convert the current article date to the local timezone."
11320 (interactive)
11321 (gnus-article-date-ut 'local))
11322
11323 (defun gnus-article-date-lapsed ()
11324 "Convert the current article date to time lapsed since it was sent."
11325 (interactive)
11326 (gnus-article-date-ut 'lapsed))
11327
11328 (defun gnus-article-maybe-highlight ()
11329 "Do some article highlighting if `gnus-visual' is non-nil."
11330 (if gnus-visual (gnus-article-highlight-some)))
11331
11332 ;; Article savers.
11333
11334 (defun gnus-output-to-rmail (file-name)
11335 "Append the current article to an Rmail file named FILE-NAME."
11336 (require 'rmail)
11337 ;; Most of these codes are borrowed from rmailout.el.
11338 (setq file-name (expand-file-name file-name))
11339 (setq rmail-default-rmail-file file-name)
11340 (let ((artbuf (current-buffer))
11341 (tmpbuf (get-buffer-create " *Gnus-output*")))
11342 (save-excursion
11343 (or (get-file-buffer file-name)
11344 (file-exists-p file-name)
11345 (if (gnus-yes-or-no-p
11346 (concat "\"" file-name "\" does not exist, create it? "))
11347 (let ((file-buffer (create-file-buffer file-name)))
11348 (save-excursion
11349 (set-buffer file-buffer)
11350 (rmail-insert-rmail-file-header)
11351 (let ((require-final-newline nil))
11352 (write-region (point-min) (point-max) file-name t 1)))
11353 (kill-buffer file-buffer))
11354 (error "Output file does not exist")))
11355 (set-buffer tmpbuf)
11356 (buffer-disable-undo (current-buffer))
11357 (erase-buffer)
11358 (insert-buffer-substring artbuf)
11359 (gnus-convert-article-to-rmail)
11360 ;; Decide whether to append to a file or to an Emacs buffer.
11361 (let ((outbuf (get-file-buffer file-name)))
11362 (if (not outbuf)
11363 (append-to-file (point-min) (point-max) file-name)
11364 ;; File has been visited, in buffer OUTBUF.
11365 (set-buffer outbuf)
11366 (let ((buffer-read-only nil)
11367 (msg (and (boundp 'rmail-current-message)
11368 (symbol-value 'rmail-current-message))))
11369 ;; If MSG is non-nil, buffer is in RMAIL mode.
11370 (if msg
11371 (progn (widen)
11372 (narrow-to-region (point-max) (point-max))))
11373 (insert-buffer-substring tmpbuf)
11374 (if msg
11375 (progn
11376 (goto-char (point-min))
11377 (widen)
11378 (search-backward "\^_")
11379 (narrow-to-region (point) (point-max))
11380 (goto-char (1+ (point-min)))
11381 (rmail-count-new-messages t)
11382 (rmail-show-message msg)))))))
11383 (kill-buffer tmpbuf)))
11384
11385 (defun gnus-output-to-file (file-name)
11386 "Append the current article to a file named FILE-NAME."
11387 (setq file-name (expand-file-name file-name))
11388 (let ((artbuf (current-buffer))
11389 (tmpbuf (get-buffer-create " *Gnus-output*")))
11390 (save-excursion
11391 (set-buffer tmpbuf)
11392 (buffer-disable-undo (current-buffer))
11393 (erase-buffer)
11394 (insert-buffer-substring artbuf)
11395 ;; Append newline at end of the buffer as separator, and then
11396 ;; save it to file.
11397 (goto-char (point-max))
11398 (insert "\n")
11399 (append-to-file (point-min) (point-max) file-name))
11400 (kill-buffer tmpbuf)))
11401
11402 (defun gnus-convert-article-to-rmail ()
11403 "Convert article in current buffer to Rmail message format."
11404 (let ((buffer-read-only nil))
11405 ;; Convert article directly into Babyl format.
11406 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
11407 (goto-char (point-min))
11408 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
11409 (while (search-forward "\n\^_" nil t) ;single char
11410 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
11411 (goto-char (point-max))
11412 (insert "\^_")))
11413
11414 (defun gnus-narrow-to-page (&optional arg)
11415 "Make text outside current page invisible except for page delimiter.
11416 A numeric arg specifies to move forward or backward by that many pages,
11417 thus showing a page other than the one point was originally in."
11418 (interactive "P")
11419 (setq arg (if arg (prefix-numeric-value arg) 0))
11420 (save-excursion
11421 (forward-page -1) ;Beginning of current page.
11422 (widen)
11423 (if (> arg 0)
11424 (forward-page arg)
11425 (if (< arg 0)
11426 (forward-page (1- arg))))
11427 ;; Find the end of the page.
11428 (forward-page)
11429 ;; If we stopped due to end of buffer, stay there.
11430 ;; If we stopped after a page delimiter, put end of restriction
11431 ;; at the beginning of that line.
11432 ;; These are commented out.
11433 ;; (if (save-excursion (beginning-of-line)
11434 ;; (looking-at page-delimiter))
11435 ;; (beginning-of-line))
11436 (narrow-to-region (point)
11437 (progn
11438 ;; Find the top of the page.
11439 (forward-page -1)
11440 ;; If we found beginning of buffer, stay there.
11441 ;; If extra text follows page delimiter on same line,
11442 ;; include it.
11443 ;; Otherwise, show text starting with following line.
11444 (if (and (eolp) (not (bobp)))
11445 (forward-line 1))
11446 (point)))))
11447
11448 (defun gnus-gmt-to-local ()
11449 "Rewrite Date header described in GMT to local in current buffer.
11450 Intended to be used with gnus-article-prepare-hook."
11451 (save-excursion
11452 (save-restriction
11453 (widen)
11454 (goto-char (point-min))
11455 (narrow-to-region (point-min)
11456 (progn (search-forward "\n\n" nil 'move) (point)))
11457 (goto-char (point-min))
11458 (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t)
11459 (let ((buffer-read-only nil)
11460 (date (buffer-substring-no-properties
11461 (match-beginning 1) (match-end 1))))
11462 (delete-region (match-beginning 1) (match-end 1))
11463 (insert
11464 (timezone-make-date-arpa-standard
11465 date nil (current-time-zone))))))))
11466
11467
11468 ;; Article mode commands
11469
11470 (defun gnus-article-next-page (&optional lines)
11471 "Show next page of current article.
11472 If end of article, return non-nil. Otherwise return nil.
11473 Argument LINES specifies lines to be scrolled up."
11474 (interactive "P")
11475 (move-to-window-line -1)
11476 ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
11477 (if (save-excursion
11478 (end-of-line)
11479 (and (pos-visible-in-window-p) ;Not continuation line.
11480 (eobp)))
11481 ;; Nothing in this page.
11482 (if (or (not gnus-break-pages)
11483 (save-excursion
11484 (save-restriction
11485 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
11486 t ;Nothing more.
11487 (gnus-narrow-to-page 1) ;Go to next page.
11488 nil)
11489 ;; More in this page.
11490 (condition-case ()
11491 (scroll-up lines)
11492 (end-of-buffer
11493 ;; Long lines may cause an end-of-buffer error.
11494 (goto-char (point-max))))
11495 nil))
11496
11497 (defun gnus-article-prev-page (&optional lines)
11498 "Show previous page of current article.
11499 Argument LINES specifies lines to be scrolled down."
11500 (interactive "P")
11501 (move-to-window-line 0)
11502 (if (and gnus-break-pages
11503 (bobp)
11504 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
11505 (progn
11506 (gnus-narrow-to-page -1) ;Go to previous page.
11507 (goto-char (point-max))
11508 (recenter -1))
11509 (scroll-down lines)))
11510
11511 (defun gnus-article-refer-article ()
11512 "Read article specified by message-id around point."
11513 (interactive)
11514 (search-forward ">" nil t) ;Move point to end of "<....>".
11515 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
11516 (let ((message-id
11517 (buffer-substring (match-beginning 1) (match-end 1))))
11518 (set-buffer gnus-summary-buffer)
11519 (gnus-summary-refer-article message-id))
11520 (error "No references around point")))
11521
11522 (defun gnus-article-show-summary ()
11523 "Reconfigure windows to show summary buffer."
11524 (interactive)
11525 (gnus-configure-windows 'article)
11526 (gnus-summary-goto-subject gnus-current-article))
11527
11528 (defun gnus-article-describe-briefly ()
11529 "Describe article mode commands briefly."
11530 (interactive)
11531 (gnus-message 6
11532 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-next-page]:Next page \\[gnus-article-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
11533
11534 (defun gnus-article-summary-command ()
11535 "Execute the last keystroke in the summary buffer."
11536 (interactive)
11537 (let ((obuf (current-buffer))
11538 (owin (current-window-configuration))
11539 func)
11540 (switch-to-buffer gnus-summary-buffer 'norecord)
11541 (setq func (lookup-key (current-local-map) (this-command-keys)))
11542 (call-interactively func)
11543 (set-buffer obuf)
11544 (set-window-configuration owin)
11545 (set-window-point (get-buffer-window (current-buffer)) (point))))
11546
11547 (defun gnus-article-summary-command-nosave ()
11548 "Execute the last keystroke in the summary buffer."
11549 (interactive)
11550 (let (func)
11551 (pop-to-buffer gnus-summary-buffer 'norecord)
11552 (setq func (lookup-key (current-local-map) (this-command-keys)))
11553 (call-interactively func)))
11554
11555 \f
11556 ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
11557
11558 ;;;###autoload
11559 (defalias 'gnus-batch-kill 'gnus-batch-score)
11560 ;;;###autoload
11561 (defun gnus-batch-score ()
11562 "Run batched scoring.
11563 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
11564 Newsgroups is a list of strings in Bnews format. If you want to score
11565 the comp hierarchy, you'd say \"comp.all\". If you would not like to
11566 score the alt hierarchy, you'd say \"!alt.all\"."
11567 (interactive)
11568 (let* ((yes-and-no
11569 (gnus-newsrc-parse-options
11570 (apply (function concat)
11571 (mapcar (lambda (g) (concat g " "))
11572 command-line-args-left))))
11573 (gnus-expert-user t)
11574 (nnmail-spool-file nil)
11575 (gnus-use-dribble-file nil)
11576 (yes (car yes-and-no))
11577 (no (cdr yes-and-no))
11578 group newsrc entry
11579 ;; Disable verbose message.
11580 gnus-novice-user gnus-large-newsgroup)
11581 ;; Eat all arguments.
11582 (setq command-line-args-left nil)
11583 ;; Start Gnus.
11584 (gnus)
11585 ;; Apply kills to specified newsgroups in command line arguments.
11586 (setq newsrc (cdr gnus-newsrc-alist))
11587 (while newsrc
11588 (setq group (car (car newsrc)))
11589 (setq entry (gnus-gethash group gnus-newsrc-hashtb))
11590 (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
11591 (and (car entry)
11592 (or (eq (car entry) t)
11593 (not (zerop (car entry)))))
11594 (if yes (string-match yes group) t)
11595 (or (null no) (not (string-match no group))))
11596 (progn
11597 (gnus-summary-read-group group nil t)
11598 (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
11599 (gnus-summary-exit))))
11600 (setq newsrc (cdr newsrc)))
11601 ;; Exit Emacs.
11602 (switch-to-buffer gnus-group-buffer)
11603 (gnus-group-save-newsrc)))
11604
11605 (defun gnus-apply-kill-file ()
11606 "Apply a kill file to the current newsgroup.
11607 Returns the number of articles marked as read."
11608 (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
11609 (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11610 (gnus-apply-kill-file-internal)
11611 0))
11612
11613 (defun gnus-kill-save-kill-buffer ()
11614 (save-excursion
11615 (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11616 (if (get-file-buffer file)
11617 (progn
11618 (set-buffer (get-file-buffer file))
11619 (and (buffer-modified-p) (save-buffer))
11620 (kill-buffer (current-buffer)))))))
11621
11622 (defvar gnus-kill-file-name "KILL"
11623 "Suffix of the kill files.")
11624
11625 (defun gnus-newsgroup-kill-file (newsgroup)
11626 "Return the name of a kill file name for NEWSGROUP.
11627 If NEWSGROUP is nil, return the global kill file name instead."
11628 (cond ((or (null newsgroup)
11629 (string-equal newsgroup ""))
11630 ;; The global KILL file is placed at top of the directory.
11631 (expand-file-name gnus-kill-file-name
11632 (or gnus-kill-files-directory "~/News")))
11633 ((gnus-use-long-file-name 'not-kill)
11634 ;; Append ".KILL" to newsgroup name.
11635 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
11636 "." gnus-kill-file-name)
11637 (or gnus-kill-files-directory "~/News")))
11638 (t
11639 ;; Place "KILL" under the hierarchical directory.
11640 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
11641 "/" gnus-kill-file-name)
11642 (or gnus-kill-files-directory "~/News")))))
11643
11644 \f
11645 ;;;
11646 ;;; Dribble file
11647 ;;;
11648
11649 (defvar gnus-dribble-ignore nil)
11650 (defvar gnus-dribble-eval-file nil)
11651
11652 (defun gnus-dribble-file-name ()
11653 (concat gnus-current-startup-file "-dribble"))
11654
11655 (defun gnus-dribble-enter (string)
11656 (if (and (not gnus-dribble-ignore)
11657 gnus-dribble-buffer
11658 (buffer-name gnus-dribble-buffer))
11659 (let ((obuf (current-buffer)))
11660 (set-buffer gnus-dribble-buffer)
11661 (insert string "\n")
11662 (set-window-point (get-buffer-window (current-buffer)) (point-max))
11663 (set-buffer obuf))))
11664
11665 (defun gnus-dribble-read-file ()
11666 (let ((dribble-file (gnus-dribble-file-name)))
11667 (save-excursion
11668 (set-buffer (setq gnus-dribble-buffer
11669 (get-buffer-create
11670 (file-name-nondirectory dribble-file))))
11671 (gnus-add-current-to-buffer-list)
11672 (erase-buffer)
11673 (set-visited-file-name dribble-file)
11674 (buffer-disable-undo (current-buffer))
11675 (bury-buffer (current-buffer))
11676 (set-buffer-modified-p nil)
11677 (let ((auto (make-auto-save-file-name))
11678 (gnus-dribble-ignore t))
11679 (if (or (file-exists-p auto) (file-exists-p dribble-file))
11680 (progn
11681 (if (file-newer-than-file-p auto dribble-file)
11682 (setq dribble-file auto))
11683 (insert-file-contents dribble-file)
11684 (if (not (zerop (buffer-size)))
11685 (set-buffer-modified-p t))
11686 (if (gnus-y-or-n-p
11687 "Auto-save file exists. Do you want to read it? ")
11688 (setq gnus-dribble-eval-file t))))))))
11689
11690 (defun gnus-dribble-eval-file ()
11691 (if (not gnus-dribble-eval-file)
11692 ()
11693 (setq gnus-dribble-eval-file nil)
11694 (save-excursion
11695 (let ((gnus-dribble-ignore t))
11696 (set-buffer gnus-dribble-buffer)
11697 (eval-buffer (current-buffer))))))
11698
11699 (defun gnus-dribble-delete-file ()
11700 (if (file-exists-p (gnus-dribble-file-name))
11701 (delete-file (gnus-dribble-file-name)))
11702 (if gnus-dribble-buffer
11703 (save-excursion
11704 (set-buffer gnus-dribble-buffer)
11705 (let ((auto (make-auto-save-file-name)))
11706 (if (file-exists-p auto)
11707 (delete-file auto))
11708 (erase-buffer)
11709 (set-buffer-modified-p nil)))))
11710
11711 (defun gnus-dribble-save ()
11712 (if (and gnus-dribble-buffer
11713 (buffer-name gnus-dribble-buffer))
11714 (save-excursion
11715 (set-buffer gnus-dribble-buffer)
11716 (save-buffer))))
11717
11718 (defun gnus-dribble-clear ()
11719 (save-excursion
11720 (if (gnus-buffer-exists-p gnus-dribble-buffer)
11721 (progn
11722 (set-buffer gnus-dribble-buffer)
11723 (erase-buffer)
11724 (set-buffer-modified-p nil)
11725 (setq buffer-saved-size (buffer-size))))))
11726
11727 ;;;
11728 ;;; Server Communication
11729 ;;;
11730
11731 (defun gnus-start-news-server (&optional confirm)
11732 "Open a method for getting news.
11733 If CONFIRM is non-nil, the user will be asked for an NNTP server."
11734 (let (how)
11735 (if gnus-current-select-method
11736 ;; Stream is already opened.
11737 nil
11738 ;; Open NNTP server.
11739 (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
11740 (if confirm
11741 (progn
11742 ;; Read server name with completion.
11743 (setq gnus-nntp-server
11744 (completing-read "NNTP server: "
11745 (mapcar (lambda (server) (list server))
11746 (cons (list gnus-nntp-server)
11747 gnus-secondary-servers))
11748 nil nil gnus-nntp-server))))
11749
11750 (if (and gnus-nntp-server
11751 (stringp gnus-nntp-server)
11752 (not (string= gnus-nntp-server "")))
11753 (setq gnus-select-method
11754 (cond ((or (string= gnus-nntp-server "")
11755 (string= gnus-nntp-server "::"))
11756 (list 'nnspool (system-name)))
11757 ((string-match "^:" gnus-nntp-server)
11758 (list 'nnmh gnus-nntp-server
11759 (list 'nnmh-directory
11760 (file-name-as-directory
11761 (expand-file-name
11762 (concat "~/" (substring
11763 gnus-nntp-server 1)))))
11764 (list 'nnmh-get-new-mail nil)))
11765 (t
11766 (list 'nntp gnus-nntp-server)))))
11767
11768 (setq how (car gnus-select-method))
11769 (cond ((eq how 'nnspool)
11770 (require 'nnspool)
11771 (gnus-message 5 "Looking up local news spool..."))
11772 ((eq how 'nnmh)
11773 (require 'nnmh)
11774 (gnus-message 5 "Looking up mh spool..."))
11775 (t
11776 (require 'nntp)))
11777 (setq gnus-current-select-method gnus-select-method)
11778 (run-hooks 'gnus-open-server-hook)
11779 (or
11780 ;; gnus-open-server-hook might have opened it
11781 (gnus-server-opened gnus-select-method)
11782 (gnus-open-server gnus-select-method)
11783 (gnus-y-or-n-p
11784 (format
11785 "%s open error: '%s'. Continue? "
11786 (nth 1 gnus-select-method)
11787 (gnus-status-message gnus-select-method)))
11788 (progn
11789 (gnus-message 1 "Couldn't open server on %s"
11790 (nth 1 gnus-select-method))
11791 (ding)
11792 nil)))))
11793
11794 (defun gnus-check-server (&optional method)
11795 "If the news server is down, start it up again."
11796 (let ((method (if method method gnus-select-method)))
11797 (and (stringp method)
11798 (setq method (gnus-server-to-method method)))
11799 (if (gnus-server-opened method)
11800 ;; Stream is already opened.
11801 t
11802 ;; Open server.
11803 (gnus-message 5 "Opening server %s on %s..." (car method) (nth 1 method))
11804 (run-hooks 'gnus-open-server-hook)
11805 (prog1
11806 (gnus-open-server method)
11807 (message "")))))
11808
11809 (defun gnus-nntp-message (&optional message)
11810 "Check the status of the NNTP server.
11811 If the status of the server is clear and MESSAGE is non-nil, MESSAGE
11812 is returned insted of the status string."
11813 (let ((status (gnus-status-message (gnus-find-method-for-group
11814 gnus-newsgroup-name)))
11815 (message (or message "")))
11816 (if (and (stringp status) (> (length status) 0))
11817 status message)))
11818
11819 (defun gnus-get-function (method function)
11820 (and (stringp method)
11821 (setq method (gnus-server-to-method method)))
11822 (let ((func (intern (format "%s-%s" (car method) function))))
11823 (if (not (fboundp func))
11824 (progn
11825 (require (car method))
11826 (if (not (fboundp func))
11827 (error "No such function: %s" func))))
11828 func))
11829
11830 ;;; Interface functions to the backends.
11831
11832 (defun gnus-open-server (method)
11833 (funcall (gnus-get-function method 'open-server)
11834 (nth 1 method) (nthcdr 2 method)))
11835
11836 (defun gnus-close-server (method)
11837 (funcall (gnus-get-function method 'close-server) (nth 1 method)))
11838
11839 (defun gnus-request-list (method)
11840 (funcall (gnus-get-function method 'request-list) (nth 1 method)))
11841
11842 (defun gnus-request-list-newsgroups (method)
11843 (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
11844
11845 (defun gnus-request-newgroups (date method)
11846 (funcall (gnus-get-function method 'request-newgroups)
11847 date (nth 1 method)))
11848
11849 (defun gnus-server-opened (method)
11850 (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
11851
11852 (defun gnus-status-message (method)
11853 (let ((method (if (stringp method) (gnus-find-method-for-group method)
11854 method)))
11855 (funcall (gnus-get-function method 'status-message) (nth 1 method))))
11856
11857 (defun gnus-request-group (group &optional dont-check)
11858 (let ((method (gnus-find-method-for-group group)))
11859 (funcall (gnus-get-function method 'request-group)
11860 (gnus-group-real-name group) (nth 1 method) dont-check)))
11861
11862 (defun gnus-request-asynchronous (group &optional articles)
11863 (let ((method (gnus-find-method-for-group group)))
11864 (funcall (gnus-get-function method 'request-asynchronous)
11865 (gnus-group-real-name group) (nth 1 method) articles)))
11866
11867 (defun gnus-list-active-group (group)
11868 (let ((method (gnus-find-method-for-group group))
11869 (func 'list-active-group))
11870 (and (gnus-check-backend-function func group)
11871 (funcall (gnus-get-function method func)
11872 (gnus-group-real-name group) (nth 1 method)))))
11873
11874 (defun gnus-request-group-description (group)
11875 (let ((method (gnus-find-method-for-group group))
11876 (func 'request-group-description))
11877 (and (gnus-check-backend-function func group)
11878 (funcall (gnus-get-function method func)
11879 (gnus-group-real-name group) (nth 1 method)))))
11880
11881 (defun gnus-close-group (group)
11882 (let ((method (gnus-find-method-for-group group)))
11883 (funcall (gnus-get-function method 'close-group)
11884 (gnus-group-real-name group) (nth 1 method))))
11885
11886 (defun gnus-retrieve-headers (articles group)
11887 (let ((method (gnus-find-method-for-group group)))
11888 (if (and gnus-use-cache (numberp (car articles)))
11889 (gnus-cache-retrieve-headers articles group)
11890 (funcall (gnus-get-function method 'retrieve-headers)
11891 articles (gnus-group-real-name group) (nth 1 method)))))
11892
11893 (defun gnus-retrieve-groups (groups method)
11894 (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
11895
11896 (defun gnus-request-article (article group &optional buffer)
11897 (let ((method (gnus-find-method-for-group group)))
11898 (funcall (gnus-get-function method 'request-article)
11899 article (gnus-group-real-name group) (nth 1 method) buffer)))
11900
11901 (defun gnus-request-head (article group)
11902 (let ((method (gnus-find-method-for-group group)))
11903 (funcall (gnus-get-function method 'request-head)
11904 article (gnus-group-real-name group) (nth 1 method))))
11905
11906 (defun gnus-request-body (article group)
11907 (let ((method (gnus-find-method-for-group group)))
11908 (funcall (gnus-get-function method 'request-body)
11909 article (gnus-group-real-name group) (nth 1 method))))
11910
11911 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11912 (defun gnus-request-post-buffer (post group subject header artbuf
11913 info follow-to respect-poster)
11914 (let* ((info (or info (and group (nth 2 (gnus-gethash
11915 group gnus-newsrc-hashtb)))))
11916 (method
11917 (if (and gnus-post-method
11918 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11919 (memq 'post (assoc
11920 (format "%s" (car (gnus-find-method-for-group
11921 gnus-newsgroup-name)))
11922 gnus-valid-select-methods)))
11923 gnus-post-method
11924 (gnus-find-method-for-group gnus-newsgroup-name))))
11925 (or (gnus-check-server method)
11926 (error "Can't open server %s:%s" (car method) (nth 1 method)))
11927 (let ((mail-self-blind nil)
11928 (mail-archive-file-name nil))
11929 (funcall (gnus-get-function method 'request-post-buffer)
11930 post group subject header artbuf info follow-to
11931 respect-poster))))
11932
11933 (defun gnus-request-post (method &optional force)
11934 (and (stringp method)
11935 (setq method (gnus-server-to-method method)))
11936 (and (not force) gnus-post-method
11937 (memq 'post (assoc (format "%s" (car method))
11938 gnus-valid-select-methods))
11939 (setq method gnus-post-method))
11940 (funcall (gnus-get-function method 'request-post)
11941 (nth 1 method)))
11942
11943 (defun gnus-request-expire-articles (articles group &optional force)
11944 (let ((method (gnus-find-method-for-group group)))
11945 (funcall (gnus-get-function method 'request-expire-articles)
11946 articles (gnus-group-real-name group) (nth 1 method)
11947 force)))
11948
11949 (defun gnus-request-move-article
11950 (article group server accept-function &optional last)
11951 (let ((method (gnus-find-method-for-group group)))
11952 (funcall (gnus-get-function method 'request-move-article)
11953 article (gnus-group-real-name group)
11954 (nth 1 method) accept-function last)))
11955
11956 (defun gnus-request-accept-article (group &optional last)
11957 (let ((func (if (symbolp group) group
11958 (car (gnus-find-method-for-group group)))))
11959 (funcall (intern (format "%s-request-accept-article" func))
11960 (if (stringp group) (gnus-group-real-name group) group)
11961 last)))
11962
11963 (defun gnus-request-replace-article (article group buffer)
11964 (let ((func (car (gnus-find-method-for-group group))))
11965 (funcall (intern (format "%s-request-replace-article" func))
11966 article (gnus-group-real-name group) buffer)))
11967
11968 (defun gnus-request-create-group (group)
11969 (let ((method (gnus-find-method-for-group group)))
11970 (funcall (gnus-get-function method 'request-create-group)
11971 (gnus-group-real-name group) (nth 1 method))))
11972
11973 (defun gnus-member-of-valid (symbol group)
11974 (memq symbol (assoc
11975 (format "%s" (car (gnus-find-method-for-group group)))
11976 gnus-valid-select-methods)))
11977
11978 (defun gnus-secondary-method-p (method)
11979 (let ((methods gnus-secondary-select-methods)
11980 (gmethod (gnus-server-get-method nil method)))
11981 (while (and methods
11982 (not (equal (gnus-server-get-method nil (car methods))
11983 gmethod)))
11984 (setq methods (cdr methods)))
11985 methods))
11986
11987 (defun gnus-find-method-for-group (group &optional info)
11988 (or gnus-override-method
11989 (and (not group)
11990 gnus-select-method)
11991 (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
11992 method)
11993 (if (or (not info)
11994 (not (setq method (nth 4 info))))
11995 (setq method gnus-select-method)
11996 (setq method
11997 (cond ((stringp method)
11998 (gnus-server-to-method method))
11999 ((stringp (car method))
12000 (gnus-server-extend-method group method))
12001 (t
12002 method))))
12003 (gnus-server-add-address method))))
12004
12005 (defun gnus-check-backend-function (func group)
12006 (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
12007 group)))
12008 (fboundp (intern (format "%s-%s" method func)))))
12009
12010 (defun gnus-methods-using (method)
12011 (let ((valids gnus-valid-select-methods)
12012 outs)
12013 (while valids
12014 (if (memq method (car valids))
12015 (setq outs (cons (car valids) outs)))
12016 (setq valids (cdr valids)))
12017 outs))
12018
12019 ;;;
12020 ;;; Active & Newsrc File Handling
12021 ;;;
12022
12023 ;; Newsrc related functions.
12024 ;; Gnus internal format of gnus-newsrc-alist:
12025 ;; (("alt.general" 3 (1 . 1))
12026 ;; ("alt.misc" 3 ((1 . 10) (12 . 15)))
12027 ;; ("alt.test" 7 (1 . 99) (45 57 93)) ...)
12028 ;; The first item is the group name; the second is the subscription
12029 ;; level; the third is either a range of a list of ranges of read
12030 ;; articles, the optional fourth element is a list of marked articles,
12031 ;; the optional fifth element is the select method.
12032 ;;
12033 ;; Gnus internal format of gnus-newsrc-hashtb:
12034 ;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...)
12035 ;; This is the entry for "alt.misc". The first element is the number
12036 ;; of unread articles in "alt.misc". The cdr of this entry is the
12037 ;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is
12038 ;; trivial to remove or add new elements into gnus-newsrc-alist
12039 ;; without scanning the entire list. So, to get the actual information
12040 ;; of "alt.misc", you'd say something like
12041 ;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb))
12042 ;;
12043 ;; Gnus internal format of gnus-active-hashtb:
12044 ;; ((1 . 1))
12045 ;; (5 . 10))
12046 ;; (67 . 99)) ...)
12047 ;; The only element in each entry in this hash table is a range of
12048 ;; (possibly) available articles. (Articles in this range may have
12049 ;; been expired or canceled.)
12050 ;;
12051 ;; Gnus internal format of gnus-killed-list and gnus-zombie-list:
12052 ;; ("alt.misc" "alt.test" "alt.general" ...)
12053
12054 (defun gnus-setup-news (&optional rawfile level)
12055 "Setup news information.
12056 If RAWFILE is non-nil, the .newsrc file will also be read.
12057 If LEVEL is non-nil, the news will be set up at level LEVEL."
12058 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
12059 ;; Clear some variables to re-initialize news information.
12060 (if init (setq gnus-newsrc-alist nil
12061 gnus-active-hashtb nil))
12062
12063 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
12064 (if init (gnus-read-newsrc-file rawfile))
12065
12066 ;; If we don't read the complete active file, we fill in the
12067 ;; hashtb here.
12068 (if (or (null gnus-read-active-file)
12069 (eq gnus-read-active-file 'some))
12070 (gnus-update-active-hashtb-from-killed))
12071
12072 ;; Read the active file and create `gnus-active-hashtb'.
12073 ;; If `gnus-read-active-file' is nil, then we just create an empty
12074 ;; hash table. The partial filling out of the hash table will be
12075 ;; done in `gnus-get-unread-articles'.
12076 (and gnus-read-active-file
12077 (not level)
12078 (gnus-read-active-file))
12079
12080 (or gnus-active-hashtb
12081 (setq gnus-active-hashtb (make-vector 4095 0)))
12082
12083 ;; Possibly eval the dribble file.
12084 (and init gnus-use-dribble-file (gnus-dribble-eval-file))
12085
12086 (gnus-update-format-specifications)
12087
12088 ;; Find new newsgroups and treat them.
12089 (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level)
12090 (gnus-check-server gnus-select-method))
12091 (gnus-find-new-newsgroups))
12092
12093 ;; Find the number of unread articles in each non-dead group.
12094 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
12095 (gnus-get-unread-articles (or level (1+ gnus-level-subscribed))))
12096
12097 (if (and init gnus-check-bogus-newsgroups
12098 gnus-read-active-file (not level)
12099 (gnus-server-opened gnus-select-method))
12100 (gnus-check-bogus-newsgroups))))
12101
12102 (defun gnus-find-new-newsgroups ()
12103 "Search for new newsgroups and add them.
12104 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
12105 The `-n' option line from .newsrc is respected."
12106 (interactive)
12107 (or (gnus-check-first-time-used)
12108 (if (or (consp gnus-check-new-newsgroups)
12109 (eq gnus-check-new-newsgroups 'ask-server))
12110 (gnus-ask-server-for-new-groups)
12111 (let ((groups 0)
12112 group new-newsgroups)
12113 (gnus-message 5 "Looking for new newsgroups...")
12114 (or gnus-have-read-active-file (gnus-read-active-file))
12115 (setq gnus-newsrc-last-checked-date (current-time-string))
12116 (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed))
12117 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
12118 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
12119 (mapatoms
12120 (lambda (sym)
12121 (if (or (null (setq group (symbol-name sym)))
12122 (null (symbol-value sym))
12123 (gnus-gethash group gnus-killed-hashtb)
12124 (gnus-gethash group gnus-newsrc-hashtb))
12125 ()
12126 (let ((do-sub (gnus-matches-options-n group)))
12127 (cond
12128 ((eq do-sub 'subscribe)
12129 (setq groups (1+ groups))
12130 (gnus-sethash group group gnus-killed-hashtb)
12131 (funcall gnus-subscribe-options-newsgroup-method group))
12132 ((eq do-sub 'ignore)
12133 nil)
12134 (t
12135 (setq groups (1+ groups))
12136 (gnus-sethash group group gnus-killed-hashtb)
12137 (if gnus-subscribe-hierarchical-interactive
12138 (setq new-newsgroups (cons group new-newsgroups))
12139 (funcall gnus-subscribe-newsgroup-method group)))))))
12140 gnus-active-hashtb)
12141 (if new-newsgroups
12142 (gnus-subscribe-hierarchical-interactive new-newsgroups))
12143 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12144 (if (> groups 0)
12145 (gnus-message 6 "%d new newsgroup%s arrived."
12146 groups (if (> groups 1) "s have" " has"))
12147 (gnus-message 6 "No new newsgroups."))))))
12148
12149 (defun gnus-matches-options-n (group)
12150 ;; Returns `subscribe' if the group is to be unconditionally
12151 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
12152 ;; no match for the group.
12153
12154 ;; First we check the two user variables.
12155 (cond
12156 ((and gnus-options-subscribe
12157 (string-match gnus-options-subscribe group))
12158 'subscribe)
12159 ((and gnus-options-not-subscribe
12160 (string-match gnus-options-not-subscribe group))
12161 'ignore)
12162 ;; Then we go through the list that was retrieved from the .newsrc
12163 ;; file. This list has elements on the form
12164 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
12165 ;; is in the reverse order of the options line) is returned.
12166 (t
12167 (let ((regs gnus-newsrc-options-n))
12168 (while (and regs
12169 (not (string-match (car (car regs)) group)))
12170 (setq regs (cdr regs)))
12171 (and regs (cdr (car regs)))))))
12172
12173 (defun gnus-ask-server-for-new-groups ()
12174 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
12175 (methods (cons gnus-select-method
12176 (append
12177 (and (consp gnus-check-new-newsgroups)
12178 gnus-check-new-newsgroups)
12179 gnus-secondary-select-methods)))
12180 (groups 0)
12181 (new-date (current-time-string))
12182 (hashtb (gnus-make-hashtable 100))
12183 group new-newsgroups got-new method)
12184 ;; Go through both primary and secondary select methods and
12185 ;; request new newsgroups.
12186 (while methods
12187 (setq method (gnus-server-get-method nil (car methods)))
12188 (and (gnus-check-server method)
12189 (gnus-request-newgroups date method)
12190 (save-excursion
12191 (setq got-new t)
12192 (set-buffer nntp-server-buffer)
12193 ;; Enter all the new groups in a hashtable.
12194 (gnus-active-to-gnus-format method hashtb 'ignore)))
12195 (setq methods (cdr methods)))
12196 (and got-new (setq gnus-newsrc-last-checked-date new-date))
12197 ;; Now all new groups from all select methods are in `hashtb'.
12198 (mapatoms
12199 (lambda (group-sym)
12200 (setq group (symbol-name group-sym))
12201 (if (or (null group)
12202 (null (symbol-value group-sym))
12203 (gnus-gethash group gnus-newsrc-hashtb)
12204 (member group gnus-zombie-list)
12205 (member group gnus-killed-list))
12206 ;; The group is already known.
12207 ()
12208 (and (symbol-value group-sym)
12209 (gnus-sethash group (symbol-value group-sym) gnus-active-hashtb))
12210 (let ((do-sub (gnus-matches-options-n group)))
12211 (cond ((eq do-sub 'subscribe)
12212 (setq groups (1+ groups))
12213 (gnus-sethash group group gnus-killed-hashtb)
12214 (funcall
12215 gnus-subscribe-options-newsgroup-method group))
12216 ((eq do-sub 'ignore)
12217 nil)
12218 (t
12219 (setq groups (1+ groups))
12220 (gnus-sethash group group gnus-killed-hashtb)
12221 (if gnus-subscribe-hierarchical-interactive
12222 (setq new-newsgroups (cons group new-newsgroups))
12223 (funcall gnus-subscribe-newsgroup-method group)))))))
12224 hashtb)
12225 (if new-newsgroups
12226 (gnus-subscribe-hierarchical-interactive new-newsgroups))
12227 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12228 (if (> groups 0)
12229 (gnus-message 6 "%d new newsgroup%s arrived."
12230 groups (if (> groups 1) "s have" " has")))
12231 got-new))
12232
12233 (defun gnus-check-first-time-used ()
12234 (if (or (> (length gnus-newsrc-alist) 1)
12235 (file-exists-p gnus-startup-file)
12236 (file-exists-p (concat gnus-startup-file ".el"))
12237 (file-exists-p (concat gnus-startup-file ".eld")))
12238 nil
12239 (gnus-message 6 "First time user; subscribing you to default groups")
12240 (or gnus-have-read-active-file (gnus-read-active-file))
12241 (setq gnus-newsrc-last-checked-date (current-time-string))
12242 (let ((groups gnus-default-subscribed-newsgroups)
12243 group)
12244 (if (eq groups t)
12245 nil
12246 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
12247 (mapatoms
12248 (lambda (sym)
12249 (if (null (setq group (symbol-name sym)))
12250 ()
12251 (let ((do-sub (gnus-matches-options-n group)))
12252 (cond
12253 ((eq do-sub 'subscribe)
12254 (gnus-sethash group group gnus-killed-hashtb)
12255 (funcall gnus-subscribe-options-newsgroup-method group))
12256 ((eq do-sub 'ignore)
12257 nil)
12258 (t
12259 (setq gnus-killed-list (cons group gnus-killed-list)))))))
12260 gnus-active-hashtb)
12261 (while groups
12262 (if (gnus-gethash (car groups) gnus-active-hashtb)
12263 (gnus-group-change-level
12264 (car groups) gnus-level-default-subscribed gnus-level-killed))
12265 (setq groups (cdr groups)))
12266 (gnus-group-make-help-group)
12267 (and gnus-novice-user
12268 (gnus-message 7 "`A k' to list killed groups"))))))
12269
12270 (defun gnus-subscribe-group (group previous &optional method)
12271 (gnus-group-change-level
12272 (if method
12273 (list t group gnus-level-default-subscribed nil nil method)
12274 group)
12275 gnus-level-default-subscribed gnus-level-killed previous t))
12276
12277 ;; `gnus-group-change-level' is the fundamental function for changing
12278 ;; subscription levels of newsgroups. This might mean just changing
12279 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
12280 ;; again, which subscribes/unsubscribes a group, which is equally
12281 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
12282 ;; from 8-9 to 1-7 means that you remove the group from the list of
12283 ;; killed (or zombie) groups and add them to the (kinda) subscribed
12284 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
12285 ;; which is trivial.
12286 ;; ENTRY can either be a string (newsgroup name) or a list (if
12287 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
12288 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
12289 ;; entries.
12290 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
12291 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
12292 ;; after.
12293 (defun gnus-group-change-level (entry level &optional oldlevel
12294 previous fromkilled)
12295 (let (group info active num)
12296 ;; Glean what info we can from the arguments
12297 (if (consp entry)
12298 (if fromkilled (setq group (nth 1 entry))
12299 (setq group (car (nth 2 entry))))
12300 (setq group entry))
12301 (if (and (stringp entry)
12302 oldlevel
12303 (< oldlevel gnus-level-zombie))
12304 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
12305 (if (and (not oldlevel)
12306 (consp entry))
12307 (setq oldlevel (car (cdr (nth 2 entry)))))
12308 (if (stringp previous)
12309 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
12310
12311 (if (and (>= oldlevel gnus-level-zombie)
12312 (gnus-gethash group gnus-newsrc-hashtb))
12313 ;; We are trying to subscribe a group that is already
12314 ;; subscribed.
12315 () ; Do nothing.
12316
12317 (or (gnus-ephemeral-group-p group)
12318 (gnus-dribble-enter
12319 (format "(gnus-group-change-level %S %S %S %S %S)"
12320 group level oldlevel (car (nth 2 previous)) fromkilled)))
12321
12322 ;; Then we remove the newgroup from any old structures, if needed.
12323 ;; If the group was killed, we remove it from the killed or zombie
12324 ;; list. If not, and it is in fact going to be killed, we remove
12325 ;; it from the newsrc hash table and assoc.
12326 (cond ((>= oldlevel gnus-level-zombie)
12327 (if (= oldlevel gnus-level-zombie)
12328 (setq gnus-zombie-list (delete group gnus-zombie-list))
12329 (setq gnus-killed-list (delete group gnus-killed-list))))
12330 (t
12331 (if (and (>= level gnus-level-zombie)
12332 entry)
12333 (progn
12334 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
12335 (if (nth 3 entry)
12336 (setcdr (gnus-gethash (car (nth 3 entry))
12337 gnus-newsrc-hashtb)
12338 (cdr entry)))
12339 (setcdr (cdr entry) (cdr (cdr (cdr entry))))))))
12340
12341 ;; Finally we enter (if needed) the list where it is supposed to
12342 ;; go, and change the subscription level. If it is to be killed,
12343 ;; we enter it into the killed or zombie list.
12344 (cond ((>= level gnus-level-zombie)
12345 ;; Remove from the hash table.
12346 (gnus-sethash group nil gnus-newsrc-hashtb)
12347 (or (gnus-group-foreign-p group)
12348 ;; We do not enter foreign groups into the list of dead
12349 ;; groups.
12350 (if (= level gnus-level-zombie)
12351 (setq gnus-zombie-list (cons group gnus-zombie-list))
12352 (setq gnus-killed-list (cons group gnus-killed-list)))))
12353 (t
12354 ;; If the list is to be entered into the newsrc assoc, and
12355 ;; it was killed, we have to create an entry in the newsrc
12356 ;; hashtb format and fix the pointers in the newsrc assoc.
12357 (if (>= oldlevel gnus-level-zombie)
12358 (progn
12359 (if (listp entry)
12360 (progn
12361 (setq info (cdr entry))
12362 (setq num (car entry)))
12363 (setq active (gnus-gethash group gnus-active-hashtb))
12364 (setq num
12365 (if active (- (1+ (cdr active)) (car active)) t))
12366 ;; Check whether the group is foreign. If so, the
12367 ;; foreign select method has to be entered into the
12368 ;; info.
12369 (let ((method (gnus-group-method-name group)))
12370 (if (eq method gnus-select-method)
12371 (setq info (list group level nil))
12372 (setq info (list group level nil nil method)))))
12373 (or previous
12374 (setq previous
12375 (let ((p gnus-newsrc-alist))
12376 (while (cdr (cdr p))
12377 (setq p (cdr p)))
12378 p)))
12379 (setq entry (cons info (cdr (cdr previous))))
12380 (if (cdr previous)
12381 (progn
12382 (setcdr (cdr previous) entry)
12383 (gnus-sethash group (cons num (cdr previous))
12384 gnus-newsrc-hashtb))
12385 (setcdr previous entry)
12386 (gnus-sethash group (cons num previous)
12387 gnus-newsrc-hashtb))
12388 (if (cdr entry)
12389 (setcdr (gnus-gethash (car (car (cdr entry)))
12390 gnus-newsrc-hashtb)
12391 entry)))
12392 ;; It was alive, and it is going to stay alive, so we
12393 ;; just change the level and don't change any pointers or
12394 ;; hash table entries.
12395 (setcar (cdr (car (cdr (cdr entry)))) level)))))))
12396
12397 (defun gnus-kill-newsgroup (newsgroup)
12398 "Obsolete function. Kills a newsgroup."
12399 (gnus-group-change-level
12400 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
12401
12402 (defun gnus-check-bogus-newsgroups (&optional confirm)
12403 "Remove bogus newsgroups.
12404 If CONFIRM is non-nil, the user has to confirm the deletion of every
12405 newsgroup."
12406 (let ((newsrc (cdr gnus-newsrc-alist))
12407 bogus group entry)
12408 (gnus-message 5 "Checking bogus newsgroups...")
12409 (or gnus-have-read-active-file (gnus-read-active-file))
12410 ;; Find all bogus newsgroup that are subscribed.
12411 (while newsrc
12412 (setq group (car (car newsrc)))
12413 (if (or (gnus-gethash group gnus-active-hashtb) ; Active
12414 (nth 4 (car newsrc)) ; Foreign
12415 (and confirm
12416 (not (gnus-y-or-n-p
12417 (format "Remove bogus newsgroup: %s " group)))))
12418 ;; Don't remove.
12419 ()
12420 ;; Found a bogus newsgroup.
12421 (setq bogus (cons group bogus)))
12422 (setq newsrc (cdr newsrc)))
12423 ;; Remove all bogus subscribed groups by first killing them, and
12424 ;; then removing them from the list of killed groups.
12425 (while bogus
12426 (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb))
12427 (progn
12428 (gnus-group-change-level entry gnus-level-killed)
12429 (setq gnus-killed-list (delete (car bogus) gnus-killed-list))))
12430 (setq bogus (cdr bogus)))
12431 ;; Then we remove all bogus groups from the list of killed and
12432 ;; zombie groups. They are are removed without confirmation.
12433 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
12434 killed)
12435 (while dead-lists
12436 (setq killed (symbol-value (car dead-lists)))
12437 (while killed
12438 (setq group (car killed))
12439 (or (gnus-gethash group gnus-active-hashtb)
12440 ;; The group is bogus.
12441 (set (car dead-lists)
12442 (delete group (symbol-value (car dead-lists)))))
12443 (setq killed (cdr killed)))
12444 (setq dead-lists (cdr dead-lists))))
12445 (gnus-message 5 "Checking bogus newsgroups...done")))
12446
12447 (defun gnus-check-duplicate-killed-groups ()
12448 "Remove duplicates from the list of killed groups."
12449 (interactive)
12450 (let ((killed gnus-killed-list))
12451 (while killed
12452 (gnus-message 9 "%d" (length killed))
12453 (setcdr killed (delete (car killed) (cdr killed)))
12454 (setq killed (cdr killed)))))
12455
12456 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
12457 ;; and compute how many unread articles there are in each group.
12458 (defun gnus-get-unread-articles (&optional level)
12459 (let* ((newsrc (cdr gnus-newsrc-alist))
12460 (level (or level (1+ gnus-level-subscribed)))
12461 (foreign-level
12462 (min
12463 (cond ((and gnus-activate-foreign-newsgroups
12464 (not (numberp gnus-activate-foreign-newsgroups)))
12465 (1+ gnus-level-subscribed))
12466 ((numberp gnus-activate-foreign-newsgroups)
12467 gnus-activate-foreign-newsgroups)
12468 (t 0))
12469 level))
12470 info group active virtuals method)
12471 (gnus-message 5 "Checking new news...")
12472
12473 (while newsrc
12474 (setq info (car newsrc)
12475 group (car info)
12476 active (gnus-gethash group gnus-active-hashtb))
12477
12478 ;; Check newsgroups. If the user doesn't want to check them, or
12479 ;; they can't be checked (for instance, if the news server can't
12480 ;; be reached) we just set the number of unread articles in this
12481 ;; newsgroup to t. This means that Gnus thinks that there are
12482 ;; unread articles, but it has no idea how many.
12483 (if (and (setq method (nth 4 info))
12484 (not (gnus-server-equal gnus-select-method
12485 (gnus-server-get-method nil method)))
12486 (not (gnus-secondary-method-p method)))
12487 ;; These groups are foreign. Check the level.
12488 (if (<= (nth 1 info) foreign-level)
12489 (if (eq (car (if (stringp method)
12490 (gnus-server-to-method method)
12491 (nth 4 info))) 'nnvirtual)
12492 ;; We have to activate the virtual groups after all
12493 ;; the others, so we just pop them on a list for
12494 ;; now.
12495 (setq virtuals (cons info virtuals))
12496 (and (setq active (gnus-activate-group (car info)))
12497 ;; Close the groups as we look at them!
12498 (gnus-close-group group))))
12499
12500 ;; These groups are native or secondary.
12501 (if (and (not gnus-read-active-file)
12502 (<= (nth 1 info) level))
12503 (progn
12504 (or gnus-read-active-file (gnus-check-server method))
12505 (setq active (gnus-activate-group (car info))))))
12506
12507 (if active
12508 (gnus-get-unread-articles-in-group info active)
12509 ;; The group couldn't be reached, so we nix out the number of
12510 ;; unread articles and stuff.
12511 (gnus-sethash group nil gnus-active-hashtb)
12512 (setcar (gnus-gethash group gnus-newsrc-hashtb) t))
12513
12514 (setq newsrc (cdr newsrc)))
12515
12516 ;; Activate the virtual groups. This has to be done after all the
12517 ;; other groups.
12518 ;; !!! If one virtual group contains another virtual group, even
12519 ;; doing it this way might cause problems.
12520 (while virtuals
12521 (and (setq active (gnus-activate-group (car (car virtuals))))
12522 (gnus-get-unread-articles-in-group (car virtuals) active))
12523 (setq virtuals (cdr virtuals)))
12524
12525 (gnus-message 5 "Checking new news...done")))
12526
12527 ;; Create a hash table out of the newsrc alist. The `car's of the
12528 ;; alist elements are used as keys.
12529 (defun gnus-make-hashtable-from-newsrc-alist ()
12530 (let ((alist gnus-newsrc-alist)
12531 (ohashtb gnus-newsrc-hashtb)
12532 prev)
12533 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
12534 (setq alist
12535 (setq prev (setq gnus-newsrc-alist
12536 (if (equal (car (car gnus-newsrc-alist))
12537 "dummy.group")
12538 gnus-newsrc-alist
12539 (cons (list "dummy.group" 0 nil) alist)))))
12540 (while alist
12541 (gnus-sethash (car (car alist))
12542 (cons (and ohashtb (car (gnus-gethash
12543 (car (car alist)) ohashtb)))
12544 prev) gnus-newsrc-hashtb)
12545 (setq prev alist
12546 alist (cdr alist)))))
12547
12548 (defun gnus-make-hashtable-from-killed ()
12549 "Create a hash table from the killed and zombie lists."
12550 (let ((lists '(gnus-killed-list gnus-zombie-list))
12551 list)
12552 (setq gnus-killed-hashtb
12553 (gnus-make-hashtable
12554 (+ (length gnus-killed-list) (length gnus-zombie-list))))
12555 (while lists
12556 (setq list (symbol-value (car lists)))
12557 (setq lists (cdr lists))
12558 (while list
12559 (gnus-sethash (car list) (car list) gnus-killed-hashtb)
12560 (setq list (cdr list))))))
12561
12562 (defun gnus-get-unread-articles-in-group (info active)
12563 (let* ((range (nth 2 info))
12564 (num 0)
12565 (marked (nth 3 info)))
12566 ;; If a cache is present, we may have to alter the active info.
12567 (and gnus-use-cache
12568 (gnus-cache-possibly-alter-active (car info) active))
12569 ;; Modify the list of read articles according to what articles
12570 ;; are available; then tally the unread articles and add the
12571 ;; number to the group hash table entry.
12572 (cond
12573 ((zerop (cdr active))
12574 (setq num 0))
12575 ((not range)
12576 (setq num (- (1+ (cdr active)) (car active))))
12577 ((not (listp (cdr range)))
12578 ;; Fix a single (num . num) range according to the
12579 ;; active hash table.
12580 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
12581 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
12582 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
12583 ;; Compute number of unread articles.
12584 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
12585 (t
12586 ;; The read list is a list of ranges. Fix them according to
12587 ;; the active hash table.
12588 ;; First peel off any elements that are below the lower
12589 ;; active limit.
12590 (while (and (cdr range)
12591 (>= (car active)
12592 (or (and (atom (car (cdr range))) (car (cdr range)))
12593 (car (car (cdr range))))))
12594 (if (numberp (car range))
12595 (setcar range
12596 (cons (car range)
12597 (or (and (numberp (car (cdr range)))
12598 (car (cdr range)))
12599 (cdr (car (cdr range))))))
12600 (setcdr (car range)
12601 (or (and (numberp (nth 1 range)) (nth 1 range))
12602 (cdr (car (cdr range))))))
12603 (setcdr range (cdr (cdr range))))
12604 ;; Adjust the first element to be the same as the lower limit.
12605 (if (and (not (atom (car range)))
12606 (< (cdr (car range)) (car active)))
12607 (setcdr (car range) (1- (car active))))
12608 ;; Then we want to peel off any elements that are higher
12609 ;; than the upper active limit.
12610 (let ((srange range))
12611 ;; Go past all legal elements.
12612 (while (and (cdr srange)
12613 (<= (or (and (atom (car (cdr srange)))
12614 (car (cdr srange)))
12615 (car (car (cdr srange)))) (cdr active)))
12616 (setq srange (cdr srange)))
12617 (if (cdr srange)
12618 ;; Nuke all remaining illegal elements.
12619 (setcdr srange nil))
12620
12621 ;; Adjust the final element.
12622 (if (and (not (atom (car srange)))
12623 (> (cdr (car srange)) (cdr active)))
12624 (setcdr (car srange) (cdr active))))
12625 ;; Compute the number of unread articles.
12626 (while range
12627 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
12628 (cdr (car range))))
12629 (or (and (atom (car range)) (car range))
12630 (car (car range))))))
12631 (setq range (cdr range)))
12632 (setq num (max 0 (- (cdr active) num)))))
12633 (and info
12634 (progn
12635 (and (assq 'tick marked)
12636 (inline (gnus-remove-illegal-marked-articles
12637 (assq 'tick marked) (nth 2 info))))
12638 (and (assq 'dormant marked)
12639 (inline (gnus-remove-illegal-marked-articles
12640 (assq 'dormant marked) (nth 2 info))))
12641 (setcar
12642 (gnus-gethash (car info) gnus-newsrc-hashtb)
12643 (setq num (max 0 (- num (length (cdr (assq 'tick marked)))
12644 (length (cdr (assq 'dormant marked)))))))))
12645 num))
12646
12647 (defun gnus-remove-illegal-marked-articles (marked ranges)
12648 (let ((m (cdr marked)))
12649 ;; Make sure that all ticked articles are a subset of the unread
12650 ;; articles.
12651 (while m
12652 (if (gnus-member-of-range (car m) ranges)
12653 (setcdr marked (cdr m))
12654 (setq marked m))
12655 (setq m (cdr m)))))
12656
12657 (defun gnus-activate-group (group)
12658 ;; Check whether a group has been activated or not.
12659 (let ((method (gnus-find-method-for-group group))
12660 active)
12661 (and (gnus-check-server method)
12662 ;; We escape all bugs and quit here to make it possible to
12663 ;; continue if a group is so out-there that it reports bugs
12664 ;; and stuff.
12665 (condition-case ()
12666 (gnus-request-group group)
12667 (error nil)
12668 (quit nil))
12669 (save-excursion
12670 (set-buffer nntp-server-buffer)
12671 (goto-char (point-min))
12672 ;; Parse the result we got from `gnus-request-group'.
12673 (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
12674 (progn
12675 (goto-char (match-beginning 1))
12676 (gnus-sethash
12677 group (setq active (cons (read (current-buffer))
12678 (read (current-buffer))))
12679 gnus-active-hashtb))
12680 ;; Return the new active info.
12681 active)))))
12682
12683 (defun gnus-update-read-articles
12684 (group unread unselected ticked &optional domarks replied expirable killed
12685 dormant bookmark score)
12686 "Update the list of read and ticked articles in GROUP using the
12687 UNREAD and TICKED lists.
12688 Note: UNSELECTED has to be sorted over `<'.
12689 Returns whether the updating was successful."
12690 (let* ((active (or gnus-newsgroup-active
12691 (gnus-gethash group gnus-active-hashtb)))
12692 (entry (gnus-gethash group gnus-newsrc-hashtb))
12693 (info (nth 2 entry))
12694 (marked (nth 3 info))
12695 (prev 1)
12696 (unread (sort (copy-sequence unread) (function <)))
12697 read)
12698 (if (or (not info) (not active))
12699 ;; There is no info on this group if it was, in fact,
12700 ;; killed. Gnus stores no information on killed groups, so
12701 ;; there's nothing to be done.
12702 ;; One could store the information somewhere temporarily,
12703 ;; perhaps... Hmmm...
12704 ()
12705 ;; Remove any negative articles numbers.
12706 (while (and unread (< (car unread) 0))
12707 (setq unread (cdr unread)))
12708 ;; Remove any expired article numbers
12709 (while (and unread (< (car unread) (car active)))
12710 (setq unread (cdr unread)))
12711 (while (and ticked (< (car ticked) (car active)))
12712 (setq ticked (cdr ticked)))
12713 (while (and dormant (< (car dormant) (car active)))
12714 (setq dormant (cdr dormant)))
12715 (setq unread (sort (append unselected unread) '<))
12716 ;; Compute the ranges of read articles by looking at the list of
12717 ;; unread articles.
12718 (while unread
12719 (if (/= (car unread) prev)
12720 (setq read (cons (if (= prev (1- (car unread))) prev
12721 (cons prev (1- (car unread)))) read)))
12722 (setq prev (1+ (car unread)))
12723 (setq unread (cdr unread)))
12724 (if (<= prev (cdr active))
12725 (setq read (cons (cons prev (cdr active)) read)))
12726 ;; Enter this list into the group info.
12727 (setcar (cdr (cdr info))
12728 (if (> (length read) 1) (nreverse read) read))
12729 ;; Enter the list of ticked articles.
12730 (gnus-set-marked-articles
12731 info ticked
12732 (if domarks replied (cdr (assq 'reply marked)))
12733 (if domarks expirable (cdr (assq 'expire marked)))
12734 (if domarks killed (cdr (assq 'killed marked)))
12735 (if domarks dormant (cdr (assq 'dormant marked)))
12736 (if domarks bookmark (cdr (assq 'bookmark marked)))
12737 (if domarks score (cdr (assq 'score marked))))
12738 ;; Set the number of unread articles in gnus-newsrc-hashtb.
12739 (gnus-get-unread-articles-in-group
12740 info (gnus-gethash group gnus-active-hashtb))
12741 t)))
12742
12743 (defun gnus-make-articles-unread (group articles)
12744 "Mark ARTICLES in GROUP as unread."
12745 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
12746 (gnus-gethash (gnus-group-real-name group)
12747 gnus-newsrc-hashtb))))
12748 (ranges (nth 2 info))
12749 news)
12750 (while articles
12751 (and (gnus-member-of-range (car articles) ranges)
12752 (setq news (cons (car articles) news)))
12753 (setq articles (cdr articles)))
12754 (if (not news)
12755 ()
12756 (setcar (nthcdr 2 info)
12757 (gnus-remove-from-range (nth 2 info) (nreverse news)))
12758 (gnus-group-update-group group t))))
12759
12760 ;; Enter all dead groups into the hashtb.
12761 (defun gnus-update-active-hashtb-from-killed ()
12762 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
12763 (lists (list gnus-killed-list gnus-zombie-list))
12764 killed)
12765 (while lists
12766 (setq killed (car lists))
12767 (while killed
12768 (gnus-sethash (car killed) nil hashtb)
12769 (setq killed (cdr killed)))
12770 (setq lists (cdr lists)))))
12771
12772 ;; Get the active file(s) from the backend(s).
12773 (defun gnus-read-active-file ()
12774 (gnus-group-set-mode-line)
12775 (let ((methods (if (gnus-check-server gnus-select-method)
12776 ;; The native server is available.
12777 (cons gnus-select-method gnus-secondary-select-methods)
12778 ;; The native server is down, so we just do the
12779 ;; secondary ones.
12780 gnus-secondary-select-methods))
12781 list-type)
12782 (setq gnus-have-read-active-file nil)
12783 (save-excursion
12784 (set-buffer nntp-server-buffer)
12785 (while methods
12786 (let* ((method (gnus-server-get-method nil (car methods)))
12787 (where (nth 1 method))
12788 (mesg (format "Reading active file%s via %s..."
12789 (if (and where (not (zerop (length where))))
12790 (concat " from " where) "")
12791 (car method))))
12792 (gnus-message 5 mesg)
12793 (if (not (gnus-check-server method))
12794 ()
12795 (cond
12796 ((and (eq gnus-read-active-file 'some)
12797 (gnus-check-backend-function 'retrieve-groups (car method)))
12798 (let ((newsrc (cdr gnus-newsrc-alist))
12799 (gmethod (gnus-server-get-method nil method))
12800 groups)
12801 (while newsrc
12802 (and (gnus-server-equal
12803 (gnus-find-method-for-group
12804 (car (car newsrc)) (car newsrc))
12805 gmethod)
12806 (setq groups (cons (gnus-group-real-name
12807 (car (car newsrc))) groups)))
12808 (setq newsrc (cdr newsrc)))
12809 (gnus-check-server method)
12810 (setq list-type (gnus-retrieve-groups groups method))
12811 (cond
12812 ((not list-type)
12813 (gnus-message
12814 1 "Cannot read partial active file from %s server."
12815 (car method))
12816 (ding)
12817 (sit-for 2))
12818 ((eq list-type 'active)
12819 (gnus-active-to-gnus-format method gnus-active-hashtb))
12820 (t
12821 (gnus-groups-to-gnus-format method gnus-active-hashtb)))))
12822 (t
12823 (if (not (gnus-request-list method))
12824 (progn
12825 (gnus-message 1 "Cannot read active file from %s server."
12826 (car method))
12827 (ding))
12828 (gnus-active-to-gnus-format method)
12829 ;; We mark this active file as read.
12830 (setq gnus-have-read-active-file
12831 (cons method gnus-have-read-active-file))
12832 (gnus-message 5 "%sdone" mesg))))))
12833 (setq methods (cdr methods))))))
12834
12835 ;; Read an active file and place the results in `gnus-active-hashtb'.
12836 (defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors)
12837 (let ((cur (current-buffer))
12838 (hashtb (or hashtb
12839 (if (and gnus-active-hashtb
12840 (not (equal method gnus-select-method)))
12841 gnus-active-hashtb
12842 (setq gnus-active-hashtb
12843 (if (equal method gnus-select-method)
12844 (gnus-make-hashtable
12845 (count-lines (point-min) (point-max)))
12846 (gnus-make-hashtable 4096))))))
12847 (flag-hashtb (gnus-make-hashtable 60)))
12848 ;; Delete unnecessary lines.
12849 (goto-char (point-min))
12850 (while (search-forward "\nto." nil t)
12851 (delete-region (1+ (match-beginning 0))
12852 (progn (forward-line 1) (point))))
12853 (or (string= gnus-ignored-newsgroups "")
12854 (progn
12855 (goto-char (point-min))
12856 (delete-matching-lines gnus-ignored-newsgroups)))
12857 ;; Make the group names readable as a lisp expression even if they
12858 ;; contain special characters.
12859 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
12860 (goto-char (point-max))
12861 (while (re-search-backward "[][';?()#]" nil t)
12862 (insert ?\\))
12863 ;; If these are groups from a foreign select method, we insert the
12864 ;; group prefix in front of the group names.
12865 (and method (not (gnus-server-equal
12866 (gnus-server-get-method nil method)
12867 (gnus-server-get-method nil gnus-select-method)))
12868 (let ((prefix (gnus-group-prefixed-name "" method)))
12869 (goto-char (point-min))
12870 (while (and (not (eobp))
12871 (progn (insert prefix)
12872 (zerop (forward-line 1)))))))
12873 ;; Store the active file in a hash table.
12874 (goto-char (point-min))
12875 (if (string-match "%[oO]" gnus-group-line-format)
12876 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
12877 ;; If we want information on moderated groups, we use this
12878 ;; loop...
12879 (let* ((mod-hashtb (make-vector 7 0))
12880 (m (intern "m" mod-hashtb))
12881 group max min)
12882 (while (not (eobp))
12883 (condition-case nil
12884 (progn
12885 (narrow-to-region (point) (gnus-point-at-eol))
12886 (setq group (let ((obarray hashtb)) (read cur)))
12887 (if (and (numberp (setq max (read cur)))
12888 (numberp (setq min (read cur)))
12889 (progn
12890 (skip-chars-forward " \t")
12891 (not
12892 (or (= (following-char) ?=)
12893 (= (following-char) ?x)
12894 (= (following-char) ?j)))))
12895 (set group (cons min max))
12896 (set group nil))
12897 ;; Enter moderated groups into a list.
12898 (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
12899 (setq gnus-moderated-list
12900 (cons (symbol-name group) gnus-moderated-list))))
12901 (error
12902 (and group
12903 (symbolp group)
12904 (set group nil))))
12905 (widen)
12906 (forward-line 1)))
12907 ;; And if we do not care about moderation, we use this loop,
12908 ;; which is faster.
12909 (let (group max min)
12910 (while (not (eobp))
12911 (condition-case ()
12912 (progn
12913 (narrow-to-region (point) (gnus-point-at-eol))
12914 ;; group gets set to a symbol interned in the hash table
12915 ;; (what a hack!!) - jwz
12916 (setq group (let ((obarray hashtb)) (read cur)))
12917 (if (and (numberp (setq max (read cur)))
12918 (numberp (setq min (read cur)))
12919 (progn
12920 (skip-chars-forward " \t")
12921 (not
12922 (or (= (following-char) ?=)
12923 (= (following-char) ?x)
12924 (= (following-char) ?j)))))
12925 (set group (cons min max))
12926 (set group nil)))
12927 (error
12928 (progn
12929 (and group
12930 (symbolp group)
12931 (set group nil))
12932 (or ignore-errors
12933 (gnus-message 3 "Warning - illegal active: %s"
12934 (buffer-substring
12935 (gnus-point-at-bol) (gnus-point-at-eol)))))))
12936 (widen)
12937 (forward-line 1))))))
12938
12939 (defun gnus-groups-to-gnus-format (method &optional hashtb)
12940 ;; Parse a "groups" active file.
12941 (let ((cur (current-buffer))
12942 (hashtb (or hashtb
12943 (if (and method gnus-active-hashtb)
12944 gnus-active-hashtb
12945 (setq gnus-active-hashtb
12946 (gnus-make-hashtable
12947 (count-lines (point-min) (point-max)))))))
12948 (prefix (and method
12949 (not (gnus-server-equal
12950 (gnus-server-get-method nil method)
12951 (gnus-server-get-method nil gnus-select-method)))
12952 (gnus-group-prefixed-name "" method))))
12953
12954 (goto-char (point-min))
12955 ;; We split this into to separate loops, one with the prefix
12956 ;; and one without to speed the reading up somewhat.
12957 (if prefix
12958 (let (min max opoint group)
12959 (while (not (eobp))
12960 (condition-case ()
12961 (progn
12962 (read cur) (read cur)
12963 (setq min (read cur)
12964 max (read cur)
12965 opoint (point))
12966 (skip-chars-forward " \t")
12967 (insert prefix)
12968 (goto-char opoint)
12969 (set (let ((obarray hashtb)) (read cur))
12970 (cons min max)))
12971 (error (and group (symbolp group) (set group nil))))
12972 (forward-line 1)))
12973 (let (min max group)
12974 (while (not (eobp))
12975 (condition-case ()
12976 (if (= (following-char) ?2)
12977 (progn
12978 (read cur) (read cur)
12979 (setq min (read cur)
12980 max (read cur))
12981 (set (setq group (let ((obarray hashtb)) (read cur)))
12982 (cons min max))))
12983 (error (and group (symbolp group) (set group nil))))
12984 (forward-line 1))))))
12985
12986 (defun gnus-read-newsrc-file (&optional force)
12987 "Read startup file.
12988 If FORCE is non-nil, the .newsrc file is read."
12989 ;; Reset variables that might be defined in the .newsrc.eld file.
12990 (let ((variables gnus-variable-list))
12991 (while variables
12992 (set (car variables) nil)
12993 (setq variables (cdr variables))))
12994 (let* ((newsrc-file gnus-current-startup-file)
12995 (quick-file (concat newsrc-file ".el")))
12996 (save-excursion
12997 ;; We always load the .newsrc.eld file. If always contains
12998 ;; much information that can not be gotten from the .newsrc
12999 ;; file (ticked articles, killed groups, foreign methods, etc.)
13000 (gnus-read-newsrc-el-file quick-file)
13001
13002 (if (or force
13003 (and (file-newer-than-file-p newsrc-file quick-file)
13004 (file-newer-than-file-p newsrc-file
13005 (concat quick-file "d")))
13006 (not gnus-newsrc-alist))
13007 ;; We read the .newsrc file. Note that if there if a
13008 ;; .newsrc.eld file exists, it has already been read, and
13009 ;; the `gnus-newsrc-hashtb' has been created. While reading
13010 ;; the .newsrc file, Gnus will only use the information it
13011 ;; can find there for changing the data already read -
13012 ;; ie. reading the .newsrc file will not trash the data
13013 ;; already read (except for read articles).
13014 (save-excursion
13015 (gnus-message 5 "Reading %s..." newsrc-file)
13016 (set-buffer (find-file-noselect newsrc-file))
13017 (buffer-disable-undo (current-buffer))
13018 (gnus-newsrc-to-gnus-format)
13019 (kill-buffer (current-buffer))
13020 (gnus-message 5 "Reading %s...done" newsrc-file))))))
13021
13022 (defun gnus-read-newsrc-el-file (file)
13023 (let ((ding-file (concat file "d")))
13024 ;; We always, always read the .eld file.
13025 (gnus-message 5 "Reading %s..." ding-file)
13026 (let (gnus-newsrc-assoc)
13027 (condition-case nil
13028 (load ding-file t t t)
13029 (error nil))
13030 (and gnus-newsrc-assoc (setq gnus-newsrc-alist gnus-newsrc-assoc)))
13031 (let ((inhibit-quit t))
13032 (gnus-uncompress-newsrc-alist))
13033 (gnus-make-hashtable-from-newsrc-alist)
13034 (if (not (file-newer-than-file-p file ding-file))
13035 ()
13036 ;; Old format quick file
13037 (gnus-message 5 "Reading %s..." file)
13038 ;; The .el file is newer than the .eld file, so we read that one
13039 ;; as well.
13040 (gnus-read-old-newsrc-el-file file))))
13041
13042 ;; Parse the old-style quick startup file
13043 (defun gnus-read-old-newsrc-el-file (file)
13044 (let (newsrc killed marked group m)
13045 (prog1
13046 (let ((gnus-killed-assoc nil)
13047 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
13048 (prog1
13049 (condition-case nil
13050 (load file t t t)
13051 (error nil))
13052 (setq newsrc gnus-newsrc-assoc
13053 killed gnus-killed-assoc
13054 marked gnus-marked-assoc)))
13055 (setq gnus-newsrc-alist nil)
13056 (while newsrc
13057 (setq group (car newsrc))
13058 (let ((info (nth 2 (gnus-gethash (car group) gnus-newsrc-hashtb))))
13059 (if info
13060 (progn
13061 (setcar (nthcdr 2 info) (cdr (cdr group)))
13062 (setcar (cdr info)
13063 (if (nth 1 group) gnus-level-default-subscribed
13064 gnus-level-default-unsubscribed))
13065 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
13066 (setq gnus-newsrc-alist
13067 (cons
13068 (setq info
13069 (list (car group)
13070 (if (nth 1 group) gnus-level-default-subscribed
13071 gnus-level-default-unsubscribed)
13072 (cdr (cdr group))))
13073 gnus-newsrc-alist)))
13074 (if (setq m (assoc (car group) marked))
13075 (setcdr (cdr (cdr info))
13076 (cons (list (cons 'tick (cdr m))) nil))))
13077 (setq newsrc (cdr newsrc)))
13078 (setq newsrc killed)
13079 (while newsrc
13080 (setcar newsrc (car (car newsrc)))
13081 (setq newsrc (cdr newsrc)))
13082 (setq gnus-killed-list killed))
13083 ;; The .el file version of this variable does not begin with
13084 ;; "options", while the .eld version does, so we just add it if it
13085 ;; isn't there.
13086 (and
13087 gnus-newsrc-options
13088 (progn
13089 (and (not (string-match "^ *options" gnus-newsrc-options))
13090 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
13091 (and (not (string-match "\n$" gnus-newsrc-options))
13092 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
13093 ;; Finally, if we read some options lines, we parse them.
13094 (or (string= gnus-newsrc-options "")
13095 (gnus-newsrc-parse-options gnus-newsrc-options))))
13096
13097 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
13098 (gnus-make-hashtable-from-newsrc-alist)))
13099
13100 (defun gnus-make-newsrc-file (file)
13101 "Make server dependent file name by catenating FILE and server host name."
13102 (let* ((file (expand-file-name file nil))
13103 (real-file (concat file "-" (nth 1 gnus-select-method))))
13104 (if (or (file-exists-p real-file)
13105 (file-exists-p (concat real-file ".el"))
13106 (file-exists-p (concat real-file ".eld")))
13107 real-file file)))
13108
13109 (defun gnus-uncompress-newsrc-alist ()
13110 ;; Uncompress all lists of marked articles in the newsrc assoc.
13111 (let ((newsrc gnus-newsrc-alist)
13112 marked)
13113 (while newsrc
13114 (if (not (setq marked (nth 3 (car newsrc))))
13115 ()
13116 (while marked
13117 (or (eq 'score (car (car marked)))
13118 (eq 'bookmark (car (car marked)))
13119 (eq 'killed (car (car marked)))
13120 (setcdr (car marked) (gnus-uncompress-range (cdr (car marked)))))
13121 (setq marked (cdr marked))))
13122 (setq newsrc (cdr newsrc)))))
13123
13124 (defun gnus-compress-newsrc-alist ()
13125 ;; Compress all lists of marked articles in the newsrc assoc.
13126 (let ((newsrc gnus-newsrc-alist)
13127 marked)
13128 (while newsrc
13129 (if (not (setq marked (nth 3 (car newsrc))))
13130 ()
13131 (while marked
13132 (or (eq 'score (car (car marked)))
13133 (eq 'bookmark (car (car marked)))
13134 (eq 'killed (car (car marked)))
13135 (setcdr (car marked)
13136 (condition-case ()
13137 (gnus-compress-sequence
13138 (sort (cdr (car marked)) '<) t)
13139 (error (cdr (car marked))))))
13140 (setq marked (cdr marked))))
13141 (setq newsrc (cdr newsrc)))))
13142
13143 (defun gnus-newsrc-to-gnus-format ()
13144 (setq gnus-newsrc-options "")
13145 (setq gnus-newsrc-options-n nil)
13146
13147 (or gnus-active-hashtb
13148 (setq gnus-active-hashtb (make-vector 4095 0)))
13149 (let ((buf (current-buffer))
13150 (already-read (> (length gnus-newsrc-alist) 1))
13151 group subscribed options-symbol newsrc Options-symbol
13152 symbol reads num1)
13153 (goto-char (point-min))
13154 ;; We intern the symbol `options' in the active hashtb so that we
13155 ;; can `eq' against it later.
13156 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
13157 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
13158
13159 (while (not (eobp))
13160 ;; We first read the first word on the line by narrowing and
13161 ;; then reading into `gnus-active-hashtb'. Most groups will
13162 ;; already exist in that hashtb, so this will save some string
13163 ;; space.
13164 (narrow-to-region
13165 (point)
13166 (progn (skip-chars-forward "^ \t!:\n") (point)))
13167 (goto-char (point-min))
13168 (setq symbol
13169 (and (/= (point-min) (point-max))
13170 (let ((obarray gnus-active-hashtb)) (read buf))))
13171 (widen)
13172 ;; Now, the symbol we have read is either `options' or a group
13173 ;; name. If it is an options line, we just add it to a string.
13174 (cond
13175 ((or (eq symbol options-symbol)
13176 (eq symbol Options-symbol))
13177 (setq gnus-newsrc-options
13178 ;; This concating is quite inefficient, but since our
13179 ;; thorough studies show that approx 99.37% of all
13180 ;; .newsrc files only contain a single options line, we
13181 ;; don't give a damn, frankly, my dear.
13182 (concat gnus-newsrc-options
13183 (buffer-substring
13184 (gnus-point-at-bol)
13185 ;; Options may continue on the next line.
13186 (or (and (re-search-forward "^[^ \t]" nil 'move)
13187 (progn (beginning-of-line) (point)))
13188 (point)))))
13189 (forward-line -1))
13190 (symbol
13191 (or (boundp symbol) (set symbol nil))
13192 ;; It was a group name.
13193 (setq subscribed (= (following-char) ?:)
13194 group (symbol-name symbol)
13195 reads nil)
13196 (if (eolp)
13197 ;; If the line ends here, this is clearly a buggy line, so
13198 ;; we put point a the beginning of line and let the cond
13199 ;; below do the error handling.
13200 (beginning-of-line)
13201 ;; We skip to the beginning of the ranges.
13202 (skip-chars-forward "!: \t"))
13203 ;; We are now at the beginning of the list of read articles.
13204 ;; We read them range by range.
13205 (while
13206 (cond
13207 ((looking-at "[0-9]+")
13208 ;; We narrow and read a number instead of buffer-substring/
13209 ;; string-to-int because it's faster. narrow/widen is
13210 ;; faster than save-restriction/narrow, and save-restriction
13211 ;; produces a garbage object.
13212 (setq num1 (progn
13213 (narrow-to-region (match-beginning 0) (match-end 0))
13214 (read buf)))
13215 (widen)
13216 ;; If the next character is a dash, then this is a range.
13217 (if (= (following-char) ?-)
13218 (progn
13219 ;; We read the upper bound of the range.
13220 (forward-char 1)
13221 (if (not (looking-at "[0-9]+"))
13222 ;; This is a buggy line, by we pretend that
13223 ;; it's kinda OK. Perhaps the user should be
13224 ;; dinged?
13225 (setq reads (cons num1 reads))
13226 (setq reads
13227 (cons
13228 (cons num1
13229 (progn
13230 (narrow-to-region (match-beginning 0)
13231 (match-end 0))
13232 (read buf)))
13233 reads))
13234 (widen)))
13235 ;; It was just a simple number, so we add it to the
13236 ;; list of ranges.
13237 (setq reads (cons num1 reads)))
13238 ;; If the next char in ?\n, then we have reached the end
13239 ;; of the line and return nil.
13240 (/= (following-char) ?\n))
13241 ((= (following-char) ?\n)
13242 ;; End of line, so we end.
13243 nil)
13244 (t
13245 ;; Not numbers and not eol, so this might be a buggy
13246 ;; line...
13247 (or (eobp)
13248 ;; If it was eob instead of ?\n, we allow it.
13249 (progn
13250 ;; The line was buggy.
13251 (setq group nil)
13252 (gnus-message 3 "Mangled line: %s"
13253 (buffer-substring (gnus-point-at-bol)
13254 (gnus-point-at-eol)))
13255 (ding)
13256 (sit-for 1)))
13257 nil))
13258 ;; Skip past ", ". Spaces are illegal in these ranges, but
13259 ;; we allow them, because it's a common mistake to put a
13260 ;; space after the comma.
13261 (skip-chars-forward ", "))
13262
13263 ;; We have already read .newsrc.eld, so we gently update the
13264 ;; data in the hash table with the information we have just
13265 ;; read.
13266 (if (not group)
13267 ()
13268 (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
13269 level)
13270 (if info
13271 ;; There is an entry for this file in the alist.
13272 (progn
13273 (setcar (nthcdr 2 info) (nreverse reads))
13274 ;; We update the level very gently. In fact, we
13275 ;; only change it if there's been a status change
13276 ;; from subscribed to unsubscribed, or vice versa.
13277 (setq level (nth 1 info))
13278 (cond ((and (<= level gnus-level-subscribed)
13279 (not subscribed))
13280 (setq level (if reads
13281 gnus-level-default-unsubscribed
13282 (1+ gnus-level-default-unsubscribed))))
13283 ((and (> level gnus-level-subscribed) subscribed)
13284 (setq level gnus-level-default-subscribed)))
13285 (setcar (cdr info) level))
13286 ;; This is a new group.
13287 (setq info (list group
13288 (if subscribed
13289 gnus-level-default-subscribed
13290 (if reads
13291 (1+ gnus-level-subscribed)
13292 gnus-level-default-unsubscribed))
13293 (nreverse reads))))
13294 (setq newsrc (cons info newsrc))))))
13295 (forward-line 1))
13296
13297 (setq newsrc (nreverse newsrc))
13298
13299 (if (not already-read)
13300 ()
13301 ;; We now have two newsrc lists - `newsrc', which is what we
13302 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
13303 ;; what we've read from .newsrc.eld. We have to merge these
13304 ;; lists. We do this by "attaching" any (foreign) groups in the
13305 ;; gnus-newsrc-alist to the (native) group that precedes them.
13306 (let ((rc (cdr gnus-newsrc-alist))
13307 (prev gnus-newsrc-alist)
13308 entry mentry)
13309 (while rc
13310 (or (null (nth 4 (car rc))) ; It's a native group.
13311 (assoc (car (car rc)) newsrc) ; It's already in the alist.
13312 (if (setq entry (assoc (car (car prev)) newsrc))
13313 (setcdr (setq mentry (memq entry newsrc))
13314 (cons (car rc) (cdr mentry)))
13315 (setq newsrc (cons (car rc) newsrc))))
13316 (setq prev rc
13317 rc (cdr rc)))))
13318
13319 (setq gnus-newsrc-alist newsrc)
13320 ;; We make the newsrc hashtb.
13321 (gnus-make-hashtable-from-newsrc-alist)
13322
13323 ;; Finally, if we read some options lines, we parse them.
13324 (or (string= gnus-newsrc-options "")
13325 (gnus-newsrc-parse-options gnus-newsrc-options))))
13326
13327 ;; Parse options lines to find "options -n !all rec.all" and stuff.
13328 ;; The return value will be a list on the form
13329 ;; ((regexp1 . ignore)
13330 ;; (regexp2 . subscribe)...)
13331 ;; When handling new newsgroups, groups that match a `ignore' regexp
13332 ;; will be ignored, and groups that match a `subscribe' regexp will be
13333 ;; subscribed. A line like
13334 ;; options -n !all rec.all
13335 ;; will lead to a list that looks like
13336 ;; (("^rec\\..+" . subscribe)
13337 ;; ("^.+" . ignore))
13338 ;; So all "rec.*" groups will be subscribed, while all the other
13339 ;; groups will be ignored. Note that "options -n !all rec.all" is very
13340 ;; different from "options -n rec.all !all".
13341 (defun gnus-newsrc-parse-options (options)
13342 (let (out eol)
13343 (save-excursion
13344 (gnus-set-work-buffer)
13345 (insert (regexp-quote options))
13346 ;; First we treat all continuation lines.
13347 (goto-char (point-min))
13348 (while (re-search-forward "\n[ \t]+" nil t)
13349 (replace-match " " t t))
13350 ;; Then we transform all "all"s into ".+"s.
13351 (goto-char (point-min))
13352 (while (re-search-forward "\\ball\\b" nil t)
13353 (replace-match ".+" t t))
13354 (goto-char (point-min))
13355 ;; We remove all other options than the "-n" ones.
13356 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
13357 (replace-match " ")
13358 (forward-char -1))
13359 (goto-char (point-min))
13360
13361 ;; We are only interested in "options -n" lines - we
13362 ;; ignore the other option lines.
13363 (while (re-search-forward "[ \t]-n" nil t)
13364 (setq eol
13365 (or (save-excursion
13366 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
13367 (- (point) 2)))
13368 (gnus-point-at-eol)))
13369 ;; Search for all "words"...
13370 (while (re-search-forward "[^ \t,\n]+" eol t)
13371 (if (= (char-after (match-beginning 0)) ?!)
13372 ;; If the word begins with a bang (!), this is a "not"
13373 ;; spec. We put this spec (minus the bang) and the
13374 ;; symbol `ignore' into the list.
13375 (setq out (cons (cons (concat
13376 "^" (buffer-substring
13377 (1+ (match-beginning 0))
13378 (match-end 0)))
13379 'ignore) out))
13380 ;; There was no bang, so this is a "yes" spec.
13381 (setq out (cons (cons (concat
13382 "^" (buffer-substring (match-beginning 0)
13383 (match-end 0)))
13384 'subscribe) out)))))
13385
13386 (setq gnus-newsrc-options-n out))))
13387
13388
13389 (defun gnus-save-newsrc-file ()
13390 "Save .newsrc file."
13391 ;; Note: We cannot save .newsrc file if all newsgroups are removed
13392 ;; from the variable gnus-newsrc-alist.
13393 (and (or gnus-newsrc-alist gnus-killed-list)
13394 gnus-current-startup-file
13395 (progn
13396 (run-hooks 'gnus-save-newsrc-hook)
13397 (save-excursion
13398 (if (and gnus-use-dribble-file
13399 (or (not gnus-dribble-buffer)
13400 (not (buffer-name gnus-dribble-buffer))
13401 (zerop (save-excursion
13402 (set-buffer gnus-dribble-buffer)
13403 (buffer-size)))))
13404 (gnus-message 4 "(No changes need to be saved)")
13405 (if gnus-save-newsrc-file
13406 (progn
13407 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
13408 ;; Make backup file of master newsrc.
13409 (gnus-gnus-to-newsrc-format)
13410 (gnus-message 5 "Saving %s...done"
13411 gnus-current-startup-file)))
13412 ;; Quickly loadable .newsrc.
13413 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
13414 (make-local-variable 'version-control)
13415 (setq version-control 'never)
13416 (setq buffer-file-name (concat gnus-current-startup-file ".eld"))
13417 (gnus-add-current-to-buffer-list)
13418 (buffer-disable-undo (current-buffer))
13419 (erase-buffer)
13420 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
13421 (gnus-gnus-to-quick-newsrc-format)
13422 (save-buffer)
13423 (kill-buffer (current-buffer))
13424 (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file)
13425 (gnus-dribble-delete-file))))))
13426
13427 (defun gnus-gnus-to-quick-newsrc-format ()
13428 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
13429 (insert ";; Gnus startup file.\n")
13430 (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
13431 (insert ";; to read .newsrc.\n")
13432 (insert "(setq gnus-newsrc-file-version "
13433 (prin1-to-string gnus-version) ")\n")
13434 (let ((variables gnus-variable-list)
13435 (inhibit-quit t)
13436 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
13437 variable)
13438 ;; insert lisp expressions.
13439 (gnus-compress-newsrc-alist)
13440 (while variables
13441 (setq variable (car variables))
13442 (and (boundp variable)
13443 (symbol-value variable)
13444 (or gnus-save-killed-list (not (eq variable 'gnus-killed-list)))
13445 (insert "(setq " (symbol-name variable) " '"
13446 (prin1-to-string (symbol-value variable))
13447 ")\n"))
13448 (setq variables (cdr variables)))
13449 (gnus-uncompress-newsrc-alist)))
13450
13451
13452 (defun gnus-gnus-to-newsrc-format ()
13453 ;; Generate and save the .newsrc file.
13454 (let ((newsrc (cdr gnus-newsrc-alist))
13455 info ranges range)
13456 (save-excursion
13457 (set-buffer (create-file-buffer gnus-current-startup-file))
13458 (setq buffer-file-name gnus-current-startup-file)
13459 (buffer-disable-undo (current-buffer))
13460 (erase-buffer)
13461 ;; Write options.
13462 (if gnus-newsrc-options (insert gnus-newsrc-options))
13463 ;; Write subscribed and unsubscribed.
13464 (while newsrc
13465 (setq info (car newsrc))
13466 (if (not (nth 4 info)) ;Don't write foreign groups to .newsrc.
13467 (progn
13468 (insert (car info) (if (> (nth 1 info) gnus-level-subscribed)
13469 "!" ":"))
13470 (if (setq ranges (nth 2 info))
13471 (progn
13472 (insert " ")
13473 (if (not (listp (cdr ranges)))
13474 (if (= (car ranges) (cdr ranges))
13475 (insert (int-to-string (car ranges)))
13476 (insert (int-to-string (car ranges)) "-"
13477 (int-to-string (cdr ranges))))
13478 (while ranges
13479 (setq range (car ranges)
13480 ranges (cdr ranges))
13481 (if (or (atom range) (= (car range) (cdr range)))
13482 (insert (int-to-string
13483 (or (and (atom range) range)
13484 (car range))))
13485 (insert (int-to-string (car range)) "-"
13486 (int-to-string (cdr range))))
13487 (if ranges (insert ","))))))
13488 (insert "\n")))
13489 (setq newsrc (cdr newsrc)))
13490 (make-local-variable 'version-control)
13491 (setq version-control 'never)
13492 ;; It has been reported that sometime the modtime on the .newsrc
13493 ;; file seems to be off. We really do want to overwrite it, so
13494 ;; we clear the modtime here before saving. It's a bit odd,
13495 ;; though...
13496 ;; sometimes the modtime clear isn't sufficient. most brute force:
13497 ;; delete the silly thing entirely first. but this fails to provide
13498 ;; such niceties as .newsrc~ creation.
13499 (if gnus-modtime-botch
13500 (delete-file gnus-startup-file)
13501 (clear-visited-file-modtime))
13502 (save-buffer)
13503 (kill-buffer (current-buffer)))))
13504
13505 (defun gnus-read-all-descriptions-files ()
13506 (let ((methods (cons gnus-select-method gnus-secondary-select-methods)))
13507 (while methods
13508 (gnus-read-descriptions-file (car methods))
13509 (setq methods (cdr methods)))
13510 t))
13511
13512 (defun gnus-read-descriptions-file (&optional method)
13513 (let ((method (or method gnus-select-method)))
13514 ;; We create the hashtable whether we manage to read the desc file
13515 ;; to avoid trying to re-read after a failed read.
13516 (or gnus-description-hashtb
13517 (setq gnus-description-hashtb
13518 (gnus-make-hashtable (length gnus-active-hashtb))))
13519 ;; Mark this method's desc file as read.
13520 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
13521 gnus-description-hashtb)
13522
13523 (gnus-message 5 "Reading descriptions file via %s..." (car method))
13524 (cond
13525 ((not (gnus-check-server method))
13526 (gnus-message 1 "Couldn't open server")
13527 nil)
13528 ((not (gnus-request-list-newsgroups method))
13529 (gnus-message 1 "Couldn't read newsgroups descriptions")
13530 nil)
13531 (t
13532 (let (group)
13533 (save-excursion
13534 (save-restriction
13535 (set-buffer nntp-server-buffer)
13536 (goto-char (point-min))
13537 (if (or (search-forward "\n.\n" nil t)
13538 (goto-char (point-max)))
13539 (progn
13540 (beginning-of-line)
13541 (narrow-to-region (point-min) (point))))
13542 (goto-char (point-min))
13543 (while (not (eobp))
13544 ;; If we get an error, we set group to 0, which is not a
13545 ;; symbol...
13546 (setq group
13547 (condition-case ()
13548 (let ((obarray gnus-description-hashtb))
13549 ;; Group is set to a symbol interned in this
13550 ;; hash table.
13551 (read nntp-server-buffer))
13552 (error 0)))
13553 (skip-chars-forward " \t")
13554 ;; ... which leads to this line being effectively ignored.
13555 (and (symbolp group)
13556 (set group (buffer-substring
13557 (point) (progn (end-of-line) (point)))))
13558 (forward-line 1))))
13559 (gnus-message 5 "Reading descriptions file...done")
13560 t)))))
13561
13562 (defun gnus-group-get-description (group)
13563 ;; Get the description of a group by sending XGTITLE to the server.
13564 (and (gnus-request-group-description group)
13565 (save-excursion
13566 (set-buffer nntp-server-buffer)
13567 (goto-char (point-min))
13568 (and (looking-at "[^ \t]+[ \t]+\\(.*\\)")
13569 (buffer-substring (match-beginning 1) (match-end 1))))))
13570
13571 ;;;
13572 ;;; Server
13573 ;;;
13574
13575 (defvar gnus-server-mode-hook nil
13576 "Hook run in `gnus-server-mode' buffers.")
13577
13578 (defconst gnus-server-line-format " {%(%h:%w%)}\n"
13579 "Format of server lines.
13580 It works along the same lines as a normal formatting string,
13581 with some simple extensions.")
13582
13583 (defvar gnus-server-mode-line-format "Gnus List of servers"
13584 "The format specification for the server mode line.")
13585
13586 (defconst gnus-server-line-format-alist
13587 (list (list ?h 'how ?s)
13588 (list ?n 'name ?s)
13589 (list ?w 'where ?s)
13590 ))
13591
13592 (defconst gnus-server-mode-line-format-alist
13593 (list (list ?S 'news-server ?s)
13594 (list ?M 'news-method ?s)
13595 (list ?u 'user-defined ?s)))
13596
13597 (defvar gnus-server-line-format-spec nil)
13598 (defvar gnus-server-mode-line-format-spec nil)
13599 (defvar gnus-server-killed-servers nil)
13600
13601 (defvar gnus-server-mode-map nil)
13602 (put 'gnus-server-mode 'mode-class 'special)
13603
13604 (if gnus-server-mode-map
13605 nil
13606 (setq gnus-server-mode-map (make-sparse-keymap))
13607 (suppress-keymap gnus-server-mode-map)
13608 (define-key gnus-server-mode-map " " 'gnus-server-read-server)
13609 (define-key gnus-server-mode-map "\r" 'gnus-server-read-server)
13610 (define-key gnus-server-mode-map gnus-mouse-2 'gnus-server-pick-server)
13611 (define-key gnus-server-mode-map "q" 'gnus-server-exit)
13612 (define-key gnus-server-mode-map "l" 'gnus-server-list-servers)
13613 (define-key gnus-server-mode-map "k" 'gnus-server-kill-server)
13614 (define-key gnus-server-mode-map "y" 'gnus-server-yank-server)
13615 (define-key gnus-server-mode-map "c" 'gnus-server-copy-server)
13616 (define-key gnus-server-mode-map "a" 'gnus-server-add-server)
13617 (define-key gnus-server-mode-map "e" 'gnus-server-edit-server))
13618
13619 (defun gnus-server-mode ()
13620 "Major mode for listing and editing servers.
13621
13622 All normal editing commands are switched off.
13623 \\<gnus-server-mode-map>
13624
13625 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
13626
13627 The following commands are available:
13628
13629 \\{gnus-server-mode-map}"
13630 (interactive)
13631 (if gnus-visual (gnus-server-make-menu-bar))
13632 (kill-all-local-variables)
13633 (gnus-simplify-mode-line)
13634 (setq major-mode 'gnus-server-mode)
13635 (setq mode-name "Server")
13636 ; (gnus-group-set-mode-line)
13637 (setq mode-line-process nil)
13638 (use-local-map gnus-server-mode-map)
13639 (buffer-disable-undo (current-buffer))
13640 (setq truncate-lines t)
13641 (setq buffer-read-only t)
13642 (run-hooks 'gnus-server-mode-hook))
13643
13644 (defun gnus-server-insert-server-line (sformat name method)
13645 (let* ((sformat (or sformat gnus-server-line-format-spec))
13646 (how (car method))
13647 (where (nth 1 method))
13648 b)
13649 (beginning-of-line)
13650 (setq b (point))
13651 ;; Insert the text.
13652 (insert (eval sformat))
13653 (add-text-properties b (1+ b) (list 'gnus-server (intern name)))))
13654
13655 (defun gnus-server-setup-buffer ()
13656 (if (get-buffer gnus-server-buffer)
13657 ()
13658 (save-excursion
13659 (set-buffer (get-buffer-create gnus-server-buffer))
13660 (gnus-server-mode)
13661 (and gnus-carpal (gnus-carpal-setup-buffer 'server)))))
13662
13663 (defun gnus-server-prepare ()
13664 (setq gnus-server-mode-line-format-spec
13665 (gnus-parse-format gnus-server-mode-line-format
13666 gnus-server-mode-line-format-alist))
13667 (setq gnus-server-line-format-spec
13668 (gnus-parse-format gnus-server-line-format
13669 gnus-server-line-format-alist))
13670 (let ((alist gnus-server-alist)
13671 (buffer-read-only nil))
13672 (erase-buffer)
13673 (while alist
13674 (gnus-server-insert-server-line nil (car (car alist)) (cdr (car alist)))
13675 (setq alist (cdr alist))))
13676 (goto-char (point-min))
13677 (gnus-server-position-cursor))
13678
13679 (defun gnus-server-server-name ()
13680 (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
13681 (and server (symbol-name server))))
13682
13683 (defalias 'gnus-server-position-cursor 'gnus-goto-colon)
13684
13685 (defconst gnus-server-edit-buffer "*Gnus edit server*")
13686
13687 (defun gnus-server-update-server (server)
13688 (save-excursion
13689 (set-buffer gnus-server-buffer)
13690 (let ((buffer-read-only nil)
13691 (info (cdr (assoc server gnus-server-alist))))
13692 (gnus-dribble-enter
13693 (concat "(gnus-server-set-info \"" server "\" '"
13694 (prin1-to-string info) ")"))
13695 ;; Buffer may be narrowed.
13696 (save-restriction
13697 (widen)
13698 (if (gnus-server-goto-server server)
13699 (delete-region (progn (beginning-of-line) (point))
13700 (progn (forward-line 1) (point))))
13701 (let ((entry (assoc server gnus-server-alist)))
13702 (gnus-server-insert-server-line nil (car entry) (cdr entry))
13703 (gnus-server-position-cursor))))))
13704
13705 (defun gnus-server-set-info (server info)
13706 ;; Enter a select method into the virtual server alist.
13707 (gnus-dribble-enter
13708 (concat "(gnus-server-set-info \"" server "\" '"
13709 (prin1-to-string info) ")"))
13710 (let* ((server (nth 1 info))
13711 (entry (assoc server gnus-server-alist)))
13712 (if entry (setcdr entry info)
13713 (setq gnus-server-alist
13714 (nconc gnus-server-alist (list (cons server info)))))))
13715
13716 (defun gnus-server-to-method (server)
13717 ;; Map virtual server names to select methods.
13718 (or (and (equal server "native") gnus-select-method)
13719 (cdr (assoc server gnus-server-alist))))
13720
13721 (defun gnus-server-extend-method (group method)
13722 ;; This function "extends" a virtual server. If the server is
13723 ;; "hello", and the select method is ("hello" (my-var "something"))
13724 ;; in the group "alt.alt", this will result in a new virtual server
13725 ;; called "helly+alt.alt".
13726 (let ((entry
13727 (gnus-copy-sequence
13728 (if (equal (car method) "native") gnus-select-method
13729 (cdr (assoc (car method) gnus-server-alist))))))
13730 (setcar (cdr entry) (concat (nth 1 entry) "+" group))
13731 (nconc entry (cdr method))))
13732
13733 (defun gnus-server-get-method (group method)
13734 ;; Input either a server name, and extended server name, or a
13735 ;; select method, and return a select method.
13736 (cond ((stringp method)
13737 (gnus-server-to-method method))
13738 ((and (stringp (car method)) group)
13739 (gnus-server-extend-method group method))
13740 (t
13741 (gnus-server-add-address method))))
13742
13743 (defun gnus-server-add-address (method)
13744 (let ((method-name (symbol-name (car method))))
13745 (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
13746 (not (assq (intern (concat method-name "-address")) method)))
13747 (append method (list (list (intern (concat method-name "-address"))
13748 (nth 1 method))))
13749 method)))
13750
13751 (defun gnus-server-equal (s1 s2)
13752 (or (equal s1 s2)
13753 (and (= (length s1) (length s2))
13754 (progn
13755 (while (and s1 (member (car s1) s2))
13756 (setq s1 (cdr s1)))
13757 (null s1)))))
13758
13759 ;;; Interactive server functions.
13760
13761 (defun gnus-server-kill-server (server)
13762 "Kill the server on the current line."
13763 (interactive (list (gnus-server-server-name)))
13764 (or (gnus-server-goto-server server)
13765 (if server (error "No such server: %s" server)
13766 (error "No server on the current line")))
13767 (gnus-dribble-enter "")
13768 (let ((buffer-read-only nil))
13769 (delete-region (progn (beginning-of-line) (point))
13770 (progn (forward-line 1) (point))))
13771 (setq gnus-server-killed-servers
13772 (cons (assoc server gnus-server-alist) gnus-server-killed-servers))
13773 (setq gnus-server-alist (delq (car gnus-server-killed-servers)
13774 gnus-server-alist))
13775 (gnus-server-position-cursor))
13776
13777 (defun gnus-server-yank-server ()
13778 "Yank the previously killed server."
13779 (interactive)
13780 (or gnus-server-killed-servers
13781 (error "No killed servers to be yanked"))
13782 (let ((alist gnus-server-alist)
13783 (server (gnus-server-server-name))
13784 (killed (car gnus-server-killed-servers)))
13785 (if (not server)
13786 (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
13787 (if (string= server (car (car gnus-server-alist)))
13788 (setq gnus-server-alist (cons killed gnus-server-alist))
13789 (while (and (cdr alist)
13790 (not (string= server (car (car (cdr alist))))))
13791 (setq alist (cdr alist)))
13792 (setcdr alist (cons killed (cdr alist)))))
13793 (gnus-server-update-server (car killed))
13794 (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
13795 (gnus-server-position-cursor)))
13796
13797 (defun gnus-server-exit ()
13798 "Return to the group buffer."
13799 (interactive)
13800 (kill-buffer (current-buffer))
13801 (switch-to-buffer gnus-group-buffer))
13802
13803 (defun gnus-server-list-servers ()
13804 "List all available servers."
13805 (interactive)
13806 (let ((cur (gnus-server-server-name)))
13807 (gnus-server-prepare)
13808 (if cur (gnus-server-goto-server cur)
13809 (goto-char (point-max))
13810 (forward-line -1))
13811 (gnus-server-position-cursor)))
13812
13813 (defun gnus-server-copy-server (from to)
13814 (interactive
13815 (list
13816 (or (gnus-server-server-name)
13817 (error "No server on the current line"))
13818 (read-string "Copy to: ")))
13819 (or from (error "No server on current line"))
13820 (or (and to (not (string= to ""))) (error "No name to copy to"))
13821 (and (assoc to gnus-server-alist) (error "%s already exists" to))
13822 (or (assoc from gnus-server-alist)
13823 (error "%s: no such server" from))
13824 (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist))))
13825 (setcar to-entry to)
13826 (setcar (nthcdr 2 to-entry) to)
13827 (setq gnus-server-killed-servers
13828 (cons to-entry gnus-server-killed-servers))
13829 (gnus-server-yank-server)))
13830
13831 (defun gnus-server-add-server (how where)
13832 (interactive
13833 (list (intern (completing-read "Server method: "
13834 gnus-valid-select-methods nil t))
13835 (read-string "Server name: ")))
13836 (setq gnus-server-killed-servers
13837 (cons (list where how where) gnus-server-killed-servers))
13838 (gnus-server-yank-server))
13839
13840 (defun gnus-server-goto-server (server)
13841 "Jump to a server line."
13842 (interactive
13843 (list (completing-read "Goto server: " gnus-server-alist nil t)))
13844 (let ((to (text-property-any (point-min) (point-max)
13845 'gnus-server (intern server))))
13846 (and to
13847 (progn
13848 (goto-char to)
13849 (gnus-server-position-cursor)))))
13850
13851 (defun gnus-server-edit-server (server)
13852 "Edit the server on the current line."
13853 (interactive (list (gnus-server-server-name)))
13854 (or server
13855 (error "No server on current line"))
13856 (let ((winconf (current-window-configuration)))
13857 (get-buffer-create gnus-server-edit-buffer)
13858 (gnus-configure-windows 'edit-server)
13859 (gnus-add-current-to-buffer-list)
13860 (emacs-lisp-mode)
13861 (make-local-variable 'gnus-prev-winconf)
13862 (setq gnus-prev-winconf winconf)
13863 (use-local-map (copy-keymap (current-local-map)))
13864 (let ((done-func '(lambda ()
13865 "Exit editing mode and update the information."
13866 (interactive)
13867 (gnus-server-edit-server-done 'group))))
13868 (setcar (cdr (nth 4 done-func)) server)
13869 (local-set-key "\C-c\C-c" done-func))
13870 (erase-buffer)
13871 (insert ";; Type `C-c C-c' after you have edited the server.\n\n")
13872 (insert (pp-to-string (cdr (assoc server gnus-server-alist))))))
13873
13874 (defun gnus-server-edit-server-done (server)
13875 (interactive)
13876 (set-buffer (get-buffer-create gnus-server-edit-buffer))
13877 (goto-char (point-min))
13878 (let ((form (read (current-buffer)))
13879 (winconf gnus-prev-winconf))
13880 (gnus-server-set-info server form)
13881 (kill-buffer (current-buffer))
13882 (and winconf (set-window-configuration winconf))
13883 (set-buffer gnus-server-buffer)
13884 (gnus-server-update-server (gnus-server-server-name))
13885 (gnus-server-list-servers)
13886 (gnus-server-position-cursor)))
13887
13888 (defun gnus-server-read-server (server)
13889 "Browse a server."
13890 (interactive (list (gnus-server-server-name)))
13891 (gnus-browse-foreign-server (gnus-server-to-method server) (current-buffer)))
13892
13893 (defun gnus-mouse-pick-server (e)
13894 (interactive "e")
13895 (mouse-set-point e)
13896 (gnus-server-read-server (gnus-server-server-name)))
13897
13898 ;;;
13899 ;;; entry points into gnus-score.el
13900 ;;;
13901
13902 ;;; Finding score files.
13903
13904 (defvar gnus-global-score-files nil
13905 "*List of global score files and directories.
13906 Set this variable if you want to use people's score files. One entry
13907 for each score file or each score file directory. Gnus will decide
13908 by itself what score files are applicable to which group.
13909
13910 Say you want to use the single score file
13911 \"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
13912 score files in the \"/ftp.some-where:/pub/score\" directory.
13913
13914 (setq gnus-global-score-files
13915 '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\"
13916 \"/ftp.some-where:/pub/score\"))")
13917
13918 (defun gnus-score-score-files (group)
13919 "Return a list of all possible score files."
13920 ;; Search and set any global score files.
13921 (and gnus-global-score-files
13922 (or gnus-internal-global-score-files
13923 (gnus-score-search-global-directories gnus-global-score-files)))
13924 ;; Fix the kill-file dir variable.
13925 (setq gnus-kill-files-directory
13926 (file-name-as-directory
13927 (or gnus-kill-files-directory "~/News/")))
13928 ;; If we can't read it, there are no score files.
13929 (if (not (file-exists-p (expand-file-name gnus-kill-files-directory)))
13930 (setq gnus-score-file-list nil)
13931 (if (gnus-use-long-file-name 'not-score)
13932 ;; We want long file names.
13933 (if (or (not gnus-score-file-list)
13934 (not (car gnus-score-file-list))
13935 (gnus-file-newer-than gnus-kill-files-directory
13936 (car gnus-score-file-list)))
13937 (setq gnus-score-file-list
13938 (cons (nth 5 (file-attributes gnus-kill-files-directory))
13939 (nreverse
13940 (directory-files
13941 gnus-kill-files-directory t
13942 (gnus-score-file-regexp))))))
13943 ;; We do not use long file names, so we have to do some
13944 ;; directory traversing.
13945 (let ((mdir (length (expand-file-name gnus-kill-files-directory)))
13946 (suffixes (list gnus-score-file-suffix gnus-adaptive-file-suffix))
13947 dir files suffix)
13948 (while suffixes
13949 (setq dir (expand-file-name
13950 (concat gnus-kill-files-directory
13951 (gnus-replace-chars-in-string group ?. ?/))))
13952 (setq dir (gnus-replace-chars-in-string dir ?: ?/))
13953 (setq suffix (car suffixes)
13954 suffixes (cdr suffixes))
13955 (if (file-exists-p (concat dir "/" suffix))
13956 (setq files (cons (concat dir "/" suffix) files)))
13957 (while (>= (1+ (length dir)) mdir)
13958 (and (file-exists-p (concat dir "/all/" suffix))
13959 (setq files (cons (concat dir "/all/" suffix) files)))
13960 (string-match "/[^/]*$" dir)
13961 (setq dir (substring dir 0 (match-beginning 0)))))
13962 (setq gnus-score-file-list
13963 (cons nil (nreverse files)))))
13964 (cdr gnus-score-file-list)))
13965
13966 (defun gnus-score-file-regexp ()
13967 (concat "\\(" gnus-score-file-suffix
13968 "\\|" gnus-adaptive-file-suffix "\\)$"))
13969
13970 (defun gnus-score-find-bnews (group)
13971 "Return a list of score files for GROUP.
13972 The score files are those files in the ~/News directory which matches
13973 GROUP using BNews sys file syntax."
13974 (let* ((sfiles (append (gnus-score-score-files group)
13975 gnus-internal-global-score-files))
13976 (kill-dir (file-name-as-directory
13977 (expand-file-name gnus-kill-files-directory)))
13978 (klen (length kill-dir))
13979 ofiles not-match regexp)
13980 (save-excursion
13981 (set-buffer (get-buffer-create "*gnus score files*"))
13982 (buffer-disable-undo (current-buffer))
13983 ;; Go through all score file names and create regexp with them
13984 ;; as the source.
13985 (while sfiles
13986 (erase-buffer)
13987 (insert (car sfiles))
13988 (goto-char (point-min))
13989 ;; First remove the suffix itself.
13990 (re-search-forward (concat "." (gnus-score-file-regexp)))
13991 (replace-match "" t t)
13992 (goto-char (point-min))
13993 (if (looking-at (regexp-quote kill-dir))
13994 ;; If the file name was just "SCORE", `klen' is one character
13995 ;; too much.
13996 (delete-char (min (1- (point-max)) klen))
13997 (goto-char (point-max))
13998 (search-backward "/")
13999 (delete-region (1+ (point)) (point-min)))
14000 ;; If short file names were used, we have to translate slashes.
14001 (goto-char (point-min))
14002 (while (re-search-forward "[/:]" nil t)
14003 (replace-match "." t t))
14004 ;; Kludge to get rid of "nntp+" problems.
14005 (goto-char (point-min))
14006 (and (looking-at "nn[a-z]+\\+")
14007 (progn
14008 (search-forward "+")
14009 (forward-char -1)
14010 (insert "\\")))
14011 ;; Translate ".all" to "[./].*";
14012 (while (search-forward ".all" nil t)
14013 (replace-match "[./:].*" t t))
14014 (goto-char (point-min))
14015 ;; Translate "all" to ".*".
14016 (while (search-forward "all" nil t)
14017 (replace-match ".*" t t))
14018 (goto-char (point-min))
14019 ;; Deal with "not."s.
14020 (if (looking-at "not.")
14021 (progn
14022 (setq not-match t)
14023 (setq regexp (buffer-substring 5 (point-max))))
14024 (setq regexp (buffer-substring 1 (point-max)))
14025 (setq not-match nil))
14026 ;; Finally - if this resulting regexp matches the group name,
14027 ;; we add this score file to the list of score files
14028 ;; applicable to this group.
14029 (if (or (and not-match
14030 (not (string-match regexp group)))
14031 (and (not not-match)
14032 (string-match regexp group)))
14033 (setq ofiles (cons (car sfiles) ofiles)))
14034 (setq sfiles (cdr sfiles)))
14035 (kill-buffer (current-buffer))
14036 ;; Slight kludge here - the last score file returned should be
14037 ;; the local score file, whether it exists or not. This is so
14038 ;; that any score commands the user enters will go to the right
14039 ;; file, and not end up in some global score file.
14040 (let ((localscore
14041 (expand-file-name
14042 (if (gnus-use-long-file-name 'not-score)
14043 (concat gnus-kill-files-directory group "."
14044 gnus-score-file-suffix)
14045 (concat gnus-kill-files-directory
14046 (gnus-replace-chars-in-string group ?. ?/ ?: ?/)
14047 "/" gnus-score-file-suffix)))))
14048 ;; The local score file might already be there, but it's
14049 ;; supposed to be the very last file, so we delete it from the
14050 ;; list if it's already there, and add it to the head of the
14051 ;; list.
14052 (setq ofiles (cons localscore (delete localscore ofiles))))
14053 (nreverse ofiles))))
14054
14055 (defun gnus-score-find-single (group)
14056 "Return list containing the score file for GROUP."
14057 (list (gnus-score-file-name group gnus-adaptive-file-suffix)
14058 (gnus-score-file-name group)))
14059
14060 (defun gnus-score-find-hierarchical (group)
14061 "Return list of score files for GROUP.
14062 This includes the score file for the group and all its parents."
14063 (let ((all (copy-sequence '(nil)))
14064 (start 0))
14065 (while (string-match "\\." group (1+ start))
14066 (setq start (match-beginning 0))
14067 (setq all (cons (substring group 0 start) all)))
14068 (setq all (cons group all))
14069 (nconc
14070 (mapcar (lambda (newsgroup)
14071 (gnus-score-file-name newsgroup gnus-adaptive-file-suffix))
14072 (setq all (nreverse all)))
14073 (mapcar 'gnus-score-file-name all))))
14074
14075 (defvar gnus-score-file-alist-cache nil)
14076
14077 (defun gnus-score-find-alist (group)
14078 "Return list of score files for GROUP.
14079 The list is determined from the variable gnus-score-file-alist."
14080 (let ((alist gnus-score-file-multiple-match-alist)
14081 score-files)
14082 ;; if this group has been seen before, return the cached entry
14083 (if (setq score-files (assoc group gnus-score-file-alist-cache))
14084 (cdr score-files) ;ensures caching groups with no matches
14085 ;; handle the multiple match alist
14086 (while alist
14087 (and (string-match (car (car alist)) group)
14088 (setq score-files
14089 (nconc score-files (copy-sequence (cdr (car alist))))))
14090 (setq alist (cdr alist)))
14091 (setq alist gnus-score-file-single-match-alist)
14092 ;; handle the single match alist
14093 (while alist
14094 (and (string-match (car (car alist)) group)
14095 ;; progn used just in case ("regexp") has no files
14096 ;; and score-files is still nil. -sj
14097 ;; this can be construed as a "stop searching here" feature :>
14098 ;; and used to simplify regexps in the single-alist
14099 (progn
14100 (setq score-files
14101 (nconc score-files (copy-sequence (cdr (car alist)))))
14102 (setq alist nil)))
14103 (setq alist (cdr alist)))
14104 ;; cache the score files
14105 (setq gnus-score-file-alist-cache
14106 (cons (cons group score-files) gnus-score-file-alist-cache))
14107 score-files)))
14108
14109
14110 (defun gnus-possibly-score-headers (&optional trace)
14111 (let ((func gnus-score-find-score-files-function)
14112 score-files)
14113 (and func (not (listp func))
14114 (setq func (list func)))
14115 ;; Go through all the functions for finding score files (or actual
14116 ;; scores) and add them to a list.
14117 (setq score-files (gnus-score-find-alist gnus-newsgroup-name))
14118 (while func
14119 (and (symbolp (car func))
14120 (fboundp (car func))
14121 (setq score-files
14122 (nconc score-files (funcall (car func) gnus-newsgroup-name))))
14123 (setq func (cdr func)))
14124 (if score-files (gnus-score-headers score-files trace))))
14125
14126 (defun gnus-score-file-name (newsgroup &optional suffix)
14127 "Return the name of a score file for NEWSGROUP."
14128 (let ((suffix (or suffix gnus-score-file-suffix)))
14129 (cond
14130 ((or (null newsgroup)
14131 (string-equal newsgroup ""))
14132 ;; The global score file is placed at top of the directory.
14133 (expand-file-name
14134 suffix (or gnus-kill-files-directory "~/News")))
14135 ((gnus-use-long-file-name 'not-score)
14136 ;; Append ".SCORE" to newsgroup name.
14137 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
14138 "." suffix)
14139 (or gnus-kill-files-directory "~/News")))
14140 (t
14141 ;; Place "SCORE" under the hierarchical directory.
14142 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
14143 "/" suffix)
14144 (or gnus-kill-files-directory "~/News"))))))
14145
14146 (defun gnus-score-search-global-directories (files)
14147 "Scan all global score directories for score files."
14148 ;; Set the variable `gnus-internal-global-score-files' to all
14149 ;; available global score files.
14150 (interactive (list gnus-global-score-files))
14151 (let (out)
14152 (while files
14153 (if (string-match "/$" (car files))
14154 (setq out (nconc (directory-files
14155 (car files) t
14156 (concat (gnus-score-file-regexp) "$"))))
14157 (setq out (cons (car files) out)))
14158 (setq files (cdr files)))
14159 (setq gnus-internal-global-score-files out)))
14160
14161 ;; Allow redefinition of Gnus functions.
14162
14163 (gnus-ems-redefine)
14164
14165 (provide 'gnus)
14166
14167 ;;; gnus.el ends here