(hack-local-variables-prop-line): Bind enable-local-eval.
[bpt/emacs.git] / lisp / gnus.el
1 ;;; gnus.el --- a newsreader for GNU Emacs
2
3 ;; Copyright (C) 1987,88,89,90,93,94,95,96 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 (pipe ([summary 0.25 point]
714 (if gnus-carpal [summary-carpal 4])
715 [pipe 1.0]))
716 (server ([server 1.0 point]
717 (if gnus-carpal [server-carpal 2])))
718 (browse ([browse 1.0 point]
719 (if gnus-carpal [browse-carpal 2])))
720 (group-mail ([mail 1.0 point]))
721 (summary-mail ([mail 1.0 point]))
722 (summary-reply ([article 0.5]
723 [mail 1.0 point]))
724 (info ([nil 1.0 point]))
725 (summary-faq ([summary 0.25]
726 [faq 1.0 point]))
727 (edit-group ([group 0.5]
728 [edit-group 1.0 point]))
729 (edit-server ([server 0.5]
730 [edit-server 1.0 point]))
731 (edit-score ([summary 0.25]
732 [edit-score 1.0 point]))
733 (post ([post 1.0 point]))
734 (reply ([article 0.5]
735 [mail 1.0 point]))
736 (mail-forward ([mail 1.0 point]))
737 (post-forward ([post 1.0 point]))
738 (reply-yank ([mail 1.0 point]))
739 (followup ([article 0.5]
740 [post 1.0 point]))
741 (followup-yank ([post 1.0 point])))
742 "Window configuration for all possible Gnus buffers.
743 This variable is a list of lists. Each of these lists has a NAME and
744 a RULE. The NAMEs are common-sense names like `group', which names a
745 rule used when displaying the group buffer; `summary', which names a
746 rule for what happens when you enter a group and do not display an
747 article buffer; and so on. See the value of this variable for a
748 complete list of NAMEs.
749
750 Each RULE is a list of vectors. The first element in this vector is
751 the name of the buffer to be displayed; the second element is the
752 percentage of the screen this buffer is to occupy (a number in the
753 0.0-0.99 range); the optional third element is `point', which should
754 be present to denote which buffer point is to go to after making this
755 buffer configuration.")
756
757 (defvar gnus-window-to-buffer
758 '((group . gnus-group-buffer)
759 (summary . gnus-summary-buffer)
760 (article . gnus-article-buffer)
761 (server . gnus-server-buffer)
762 (browse . "*Gnus Browse Server*")
763 (pipe . "*Shell Command Output*")
764 (edit-group . gnus-group-edit-buffer)
765 (edit-server . gnus-server-edit-buffer)
766 (group-carpal . gnus-carpal-group-buffer)
767 (summary-carpal . gnus-carpal-summary-buffer)
768 (server-carpal . gnus-carpal-server-buffer)
769 (browse-carpal . gnus-carpal-browse-buffer)
770 (edit-score . gnus-score-edit-buffer)
771 (mail . gnus-mail-buffer)
772 (post . gnus-post-news-buffer)
773 (faq . gnus-faq-buffer))
774 "Mapping from short symbols to buffer names or buffer variables.")
775
776 (defvar gnus-carpal nil
777 "*If non-nil, display clickable icons.")
778
779 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
780 "*Function called with a group name when new group is detected.
781 A few pre-made functions are supplied: `gnus-subscribe-randomly'
782 inserts new groups at the beginning of the list of groups;
783 `gnus-subscribe-alphabetically' inserts new groups in strict
784 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
785 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
786 for your decision.")
787
788 ;; Suggested by a bug report by Hallvard B Furuseth.
789 ;; <h.b.furuseth@usit.uio.no>.
790 (defvar gnus-subscribe-options-newsgroup-method
791 (function gnus-subscribe-alphabetically)
792 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
793 If, for instance, you want to subscribe to all newsgroups in the
794 \"no\" and \"alt\" hierarchies, you'd put the following in your
795 .newsrc file:
796
797 options -n no.all alt.all
798
799 Gnus will the subscribe all new newsgroups in these hierarchies with
800 the subscription method in this variable.")
801
802 (defvar gnus-subscribe-hierarchical-interactive nil
803 "*If non-nil, Gnus will offer to subscribe hierarchically.
804 When a new hierarchy appears, Gnus will ask the user:
805
806 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
807
808 If the user pressed `d', Gnus will descend the hierarchy, `y' will
809 subscribe to all newsgroups in the hierarchy and `s' will skip this
810 hierarchy in its entirety.")
811
812 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
813 "*Function used for sorting the group buffer.
814 This function will be called with group info entries as the arguments
815 for the groups to be sorted. Pre-made functions include
816 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread' and
817 `gnus-group-sort-by-level'")
818
819 ;; Mark variables suggested by Thomas Michanek
820 ;; <Thomas.Michanek@telelogic.se>.
821 (defvar gnus-unread-mark ?
822 "*Mark used for unread articles.")
823 (defvar gnus-ticked-mark ?!
824 "*Mark used for ticked articles.")
825 (defvar gnus-dormant-mark ??
826 "*Mark used for dormant articles.")
827 (defvar gnus-del-mark ?r
828 "*Mark used for del'd articles.")
829 (defvar gnus-read-mark ?R
830 "*Mark used for read articles.")
831 (defvar gnus-expirable-mark ?E
832 "*Mark used for expirable articles.")
833 (defvar gnus-killed-mark ?K
834 "*Mark used for killed articles.")
835 (defvar gnus-kill-file-mark ?X
836 "*Mark used for articles killed by kill files.")
837 (defvar gnus-low-score-mark ?Y
838 "*Mark used for articles with a low score.")
839 (defvar gnus-catchup-mark ?C
840 "*Mark used for articles that are caught up.")
841 (defvar gnus-replied-mark ?A
842 "*Mark used for articles that have been replied to.")
843 (defvar gnus-process-mark ?#
844 "*Process mark.")
845 (defvar gnus-ancient-mark ?O
846 "*Mark used for ancient articles.")
847 (defvar gnus-canceled-mark ?G
848 "*Mark used for canceled articles.")
849 (defvar gnus-score-over-mark ?+
850 "*Score mark used for articles with high scores.")
851 (defvar gnus-score-below-mark ?-
852 "*Score mark used for articles with low scores.")
853 (defvar gnus-empty-thread-mark ?
854 "*There is no thread under the article.")
855 (defvar gnus-not-empty-thread-mark ?=
856 "*There is a thread under the article.")
857 (defvar gnus-dummy-mark ?Z
858 "*This is a dummy article.")
859
860 (defvar gnus-view-pseudo-asynchronously nil
861 "*If non-nil, Gnus will view pseudo-articles asynchronously.")
862
863 (defvar gnus-view-pseudos nil
864 "*If `automatic', pseudo-articles will be viewed automatically.
865 If `not-confirm', pseudos will be viewed automatically, and the user
866 will not be asked to confirm the command.")
867
868 (defvar gnus-view-pseudos-separately t
869 "*If non-nil, one pseudo-article will be created for each file to be viewed.
870 If nil, all files that use the same viewing command will be given as a
871 list of parameters to that command.")
872
873 (defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n"
874 "*Format of group lines.
875 It works along the same lines as a normal formatting string,
876 with some simple extensions.
877
878 %M Only marked articles (character, \"*\" or \" \")
879 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
880 %L Level of subscribedness (integer)
881 %N Number of unread articles (integer)
882 %I Number of dormant articles (integer)
883 %i Number of ticked and dormant (integer)
884 %T Number of ticked articles (integer)
885 %R Number of read articles (integer)
886 %t Total number of articles (integer)
887 %y Number of unread, unticked articles (integer)
888 %G Group name (string)
889 %g Qualified group name (string)
890 %D Group description (string)
891 %s Select method (string)
892 %o Moderated group (char, \"m\")
893 %p Process mark (char)
894 %O Moderated group (string, \"(m)\" or \"\")
895 %n Select from where (string)
896 %z A string that look like `<%s:%n>' if a foreign select method is used
897 %u User defined specifier. The next character in the format string should
898 be a letter. Gnus will call the function gnus-user-format-function-X,
899 where X is the letter following %u. The function will be passed the
900 current header as argument. The function should return a string, which
901 will be inserted into the buffer just like information from any other
902 group specifier.
903
904 Text between %( and %) will be highlighted with `gnus-mouse-face' when
905 the mouse point move inside the area. There can only be one such area.
906
907 Note that this format specification is not always respected. For
908 reasons of efficiency, when listing killed groups, this specification
909 is ignored altogether. If the spec is changed considerably, your
910 output may end up looking strange when listing both alive and killed
911 groups.
912
913 If you use %o or %O, reading the active file will be slower and quite
914 a bit of extra memory will be used. %D will also worsen performance.
915 Also note that if you change the format specification to include any
916 of these specs, you must probably re-start Gnus to see them go into
917 effect.")
918
919 (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
920 "*The format specification of the lines in the summary buffer.
921
922 It works along the same lines as a normal formatting string,
923 with some simple extensions.
924
925 %N Article number, left padded with spaces (string)
926 %S Subject (string)
927 %s Subject if it is at the root of a thread, and \"\" otherwise (string)
928 %n Name of the poster (string)
929 %a Extracted name of the poster (string)
930 %A Extracted address of the poster (string)
931 %F Contents of the From: header (string)
932 %x Contents of the Xref: header (string)
933 %D Date of the article (string)
934 %d Date of the article (string) in DD-MMM format
935 %M Message-id of the article (string)
936 %r References of the article (string)
937 %c Number of characters in the article (integer)
938 %L Number of lines in the article (integer)
939 %I Indentation based on thread level (a string of spaces)
940 %T A string with two possible values: 80 spaces if the article
941 is on thread level two or larger and 0 spaces on level one
942 %R \"A\" if this article has been replied to, \" \" otherwise (character)
943 %U Status of this article (character, \"R\", \"K\", \"-\" or \" \")
944 %[ Opening bracket (character, \"[\" or \"<\")
945 %] Closing bracket (character, \"]\" or \">\")
946 %> Spaces of length thread-level (string)
947 %< Spaces of length (- 20 thread-level) (string)
948 %i Article score (number)
949 %z Article zcore (character)
950 %t Number of articles under the current thread (number).
951 %e Whether the thread is empty or not (character).
952 %u User defined specifier. The next character in the format string should
953 be a letter. Gnus will call the function gnus-user-format-function-X,
954 where X is the letter following %u. The function will be passed the
955 current header as argument. The function should return a string, which
956 will be inserted into the summary just like information from any other
957 summary specifier.
958
959 Text between %( and %) will be highlighted with `gnus-mouse-face'
960 when the mouse point is placed inside the area. There can only be one
961 such area.
962
963 The %U (status), %R (replied) and %z (zcore) specs have to be handled
964 with care. For reasons of efficiency, Gnus will compute what column
965 these characters will end up in, and \"hard-code\" that. This means that
966 it is illegal to have these specs after a variable-length spec. Well,
967 you might not be arrested, but your summary buffer will look strange,
968 which is bad enough.
969
970 The smart choice is to have these specs as for to the left as
971 possible.
972
973 This restriction may disappear in later versions of Gnus.")
974
975 (defvar gnus-summary-dummy-line-format "* : : %S\n"
976 "*The format specification for the dummy roots in the summary buffer.
977 It works along the same lines as a normal formatting string,
978 with some simple extensions.
979
980 %S The subject")
981
982 (defvar gnus-summary-mode-line-format "Gnus: %b [%A] %Z"
983 "*The format specification for the summary mode line.")
984
985 (defvar gnus-article-mode-line-format "Gnus: %b %S"
986 "*The format specification for the article mode line.")
987
988 (defvar gnus-group-mode-line-format "Gnus: %b {%M:%S} "
989 "*The format specification for the group mode line.")
990
991 (defvar gnus-valid-select-methods
992 '(("nntp" post address prompt-address)
993 ("nnspool" post)
994 ("nnvirtual" none virtual prompt-address)
995 ("nnmbox" mail respool)
996 ("nnml" mail respool)
997 ("nnmh" mail respool)
998 ("nndir" none prompt-address address)
999 ("nneething" none prompt-address)
1000 ("nndigest" none)
1001 ("nndoc" none prompt-address)
1002 ("nnbabyl" mail respool)
1003 ("nnkiboze" post virtual)
1004 ;;("nnsoup" post)
1005 ("nnfolder" mail respool))
1006 "An alist of valid select methods.
1007 The first element of each list lists should be a string with the name
1008 of the select method. The other elements may be be the category of
1009 this method (ie. `post', `mail', `none' or whatever) or other
1010 properties that this method has (like being respoolable).
1011 If you implement a new select method, all you should have to change is
1012 this variable. I think.")
1013
1014 (defvar gnus-updated-mode-lines '(group article summary)
1015 "*List of buffers that should update their mode lines.
1016 The list may contain the symbols `group', `article' and `summary'. If
1017 the corresponding symbol is present, Gnus will keep that mode line
1018 updated with information that may be pertinent.
1019 If this variable is nil, screen refresh may be quicker.")
1020
1021 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1022 (defvar gnus-mode-non-string-length nil
1023 "*Max length of mode-line non-string contents.
1024 If this is nil, Gnus will take space as is needed, leaving the rest
1025 of the modeline intact.")
1026
1027 ;see gnus-cus.el
1028 ;(defvar gnus-mouse-face 'highlight
1029 ; "*Face used for mouse highlighting in Gnus.
1030 ;No mouse highlights will be done if `gnus-visual' is nil.")
1031
1032 (defvar gnus-summary-mark-below nil
1033 "*Mark all articles with a score below this variable as read.
1034 This variable is local to each summary buffer and usually set by the
1035 score file.")
1036
1037 (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
1038 "*List of functions used for sorting threads in the summary buffer.
1039 By default, threads are sorted by article number.
1040
1041 Each function takes two threads and return non-nil if the first thread
1042 should be sorted before the other. If you use more than one function,
1043 the primary sort function should be the last.
1044
1045 Ready-mady functions include `gnus-thread-sort-by-number',
1046 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
1047 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
1048 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
1049
1050 (defvar gnus-thread-score-function '+
1051 "*Function used for calculating the total score of a thread.
1052
1053 The function is called with the scores of the article and each
1054 subthread and should then return the score of the thread.
1055
1056 Some functions you can use are `+', `max', or `min'.")
1057
1058 (defvar gnus-options-subscribe nil
1059 "*All new groups matching this regexp will be subscribed unconditionally.
1060 Note that this variable deals only with new newsgroups. This variable
1061 does not affect old newsgroups.")
1062
1063 (defvar gnus-options-not-subscribe nil
1064 "*All new groups matching this regexp will be ignored.
1065 Note that this variable deals only with new newsgroups. This variable
1066 does not affect old (already subscribed) newsgroups.")
1067
1068 (defvar gnus-auto-expirable-newsgroups nil
1069 "*Groups in which to automatically mark read articles as expirable.
1070 If non-nil, this should be a regexp that should match all groups in
1071 which to perform auto-expiry. This only makes sense for mail groups.")
1072
1073 (defvar gnus-hidden-properties '(invisible t intangible t)
1074 "Property list to use for hiding text.")
1075
1076 (defvar gnus-modtime-botch nil
1077 "*Non-nil means .newsrc should be deleted prior to save. Its use is
1078 due to the bogus appearance that .newsrc was modified on disc.")
1079
1080 ;; Hooks.
1081
1082 (defvar gnus-group-mode-hook nil
1083 "*A hook for Gnus group mode.")
1084
1085 (defvar gnus-summary-mode-hook nil
1086 "*A hook for Gnus summary mode.
1087 This hook is run before any variables are set in the summary buffer.")
1088
1089 (defvar gnus-article-mode-hook nil
1090 "*A hook for Gnus article mode.")
1091
1092 (defun gnus-summary-prepare-exit-hook nil
1093 "*A hook called when preparing to exit from the summary buffer.
1094 It calls `gnus-summary-expire-articles' by default.")
1095 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
1096
1097 (defun gnus-summary-exit-hook nil
1098 "*A hook called on exit from the summary buffer.")
1099
1100 (defvar gnus-open-server-hook nil
1101 "*A hook called just before opening connection to the news server.")
1102
1103 (defvar gnus-load-hook nil
1104 "*A hook run while Gnus is loaded.")
1105
1106 (defvar gnus-startup-hook nil
1107 "*A hook called at startup.
1108 This hook is called after Gnus is connected to the NNTP server.")
1109
1110 (defvar gnus-get-new-news-hook nil
1111 "*A hook run just before Gnus checks for new news.")
1112
1113 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
1114 "*A function that is called to generate the group buffer.
1115 The function is called with three arguments: The first is a number;
1116 all group with a level less or equal to that number should be listed,
1117 if the second is non-nil, empty groups should also be displayed. If
1118 the third is non-nil, it is a number. No groups with a level lower
1119 than this number should be displayed.
1120
1121 The only current function implemented is `gnus-group-prepare-flat'.")
1122
1123 (defvar gnus-group-prepare-hook nil
1124 "*A hook called after the group buffer has been generated.
1125 If you want to modify the group buffer, you can use this hook.")
1126
1127 (defvar gnus-summary-prepare-hook nil
1128 "*A hook called after the summary buffer has been generated.
1129 If you want to modify the summary buffer, you can use this hook.")
1130
1131 (defvar gnus-article-prepare-hook nil
1132 "*A hook called after an article has been prepared in the article buffer.
1133 If you want to run a special decoding program like nkf, use this hook.")
1134
1135 ;(defvar gnus-article-display-hook nil
1136 ; "*A hook called after the article is displayed in the article buffer.
1137 ;The hook is designed to change the contents of the article
1138 ;buffer. Typical functions that this hook may contain are
1139 ;`gnus-article-hide-headers' (hide selected headers),
1140 ;`gnus-article-maybe-highlight' (perform fancy article highlighting),
1141 ;`gnus-article-hide-signature' (hide signature) and
1142 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
1143 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
1144 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
1145 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
1146
1147 (defvar gnus-article-x-face-command
1148 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
1149 "String or function to be executed to display an X-Face header.
1150 If it is a string, the command will be executed in a sub-shell
1151 asynchronously. The compressed face will be piped to this command.")
1152
1153 (defvar gnus-article-x-face-too-ugly nil
1154 "Regexp matching posters whose face shouldn't be shown automatically.")
1155
1156 (defvar gnus-select-group-hook nil
1157 "*A hook called when a newsgroup is selected.
1158
1159 If you'd like to simplify subjects like the
1160 `gnus-summary-next-same-subject' command does, you can use the
1161 following hook:
1162
1163 (setq gnus-select-group-hook
1164 (list
1165 (lambda ()
1166 (mapcar (lambda (header)
1167 (mail-header-set-subject
1168 header
1169 (gnus-simplify-subject
1170 (mail-header-subject header) 're-only)))
1171 gnus-newsgroup-headers))))")
1172
1173 (defvar gnus-select-article-hook
1174 '(gnus-summary-show-thread)
1175 "*A hook called when an article is selected.
1176 The default hook shows conversation thread subtrees of the selected
1177 article automatically using `gnus-summary-show-thread'.")
1178
1179 (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
1180 "*A hook called to apply kill files to a group.
1181 This hook is intended to apply a kill file to the selected newsgroup.
1182 The function `gnus-apply-kill-file' is called by default.
1183
1184 Since a general kill file is too heavy to use only for a few
1185 newsgroups, I recommend you to use a lighter hook function. For
1186 example, if you'd like to apply a kill file to articles which contains
1187 a string `rmgroup' in subject in newsgroup `control', you can use the
1188 following hook:
1189
1190 (setq gnus-apply-kill-hook
1191 (list
1192 (lambda ()
1193 (cond ((string-match \"control\" gnus-newsgroup-name)
1194 (gnus-kill \"Subject\" \"rmgroup\")
1195 (gnus-expunge \"X\"))))))")
1196
1197 (defvar gnus-visual-mark-article-hook
1198 (list 'gnus-highlight-selected-summary)
1199 "*Hook run after selecting an article in the summary buffer.
1200 It is meant to be used for highlighting the article in some way. It
1201 is not run if `gnus-visual' is nil.")
1202
1203 (defun gnus-parse-headers-hook nil
1204 "*A hook called before parsing the headers.")
1205
1206 (defvar gnus-exit-group-hook nil
1207 "*A hook called when exiting (not quitting) summary mode.")
1208
1209 (defvar gnus-suspend-gnus-hook nil
1210 "*A hook called when suspending (not exiting) Gnus.")
1211
1212 (defvar gnus-exit-gnus-hook nil
1213 "*A hook called when exiting Gnus.")
1214
1215 (defvar gnus-save-newsrc-hook nil
1216 "*A hook called when saving the newsrc file.")
1217
1218 (defvar gnus-summary-update-hook
1219 (list 'gnus-summary-highlight-line)
1220 "*A hook called when a summary line is changed.
1221 The hook will not be called if `gnus-visual' is nil.
1222
1223 The default function `gnus-summary-highlight-line' will
1224 highlight the line according to the `gnus-summary-highlight'
1225 variable.")
1226
1227 (defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read)
1228 "*A hook called when an article is selected for the first time.
1229 The hook is intended to mark an article as read (or unread)
1230 automatically when it is selected.")
1231
1232 ;; Remove any hilit infestation.
1233 (add-hook 'gnus-startup-hook
1234 (lambda ()
1235 (remove-hook 'gnus-summary-prepare-hook
1236 'hilit-rehighlight-buffer-quietly)
1237 (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
1238 (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read))
1239 (remove-hook 'gnus-article-prepare-hook
1240 'hilit-rehighlight-buffer-quietly)))
1241
1242
1243 \f
1244 ;; Internal variables
1245
1246 ;; Avoid highlighting in kill files.
1247 (defvar gnus-summary-inhibit-highlight nil)
1248 (defvar gnus-newsgroup-selected-overlay nil)
1249
1250 (defvar gnus-article-mode-map nil)
1251 (defvar gnus-dribble-buffer nil)
1252 (defvar gnus-headers-retrieved-by nil)
1253 (defvar gnus-article-reply nil)
1254 (defvar gnus-override-method nil)
1255 (defvar gnus-article-check-size nil)
1256
1257 (defvar gnus-current-score-file nil)
1258 (defvar gnus-internal-global-score-files nil)
1259 (defvar gnus-score-file-list nil)
1260 (defvar gnus-scores-exclude-files nil)
1261
1262 (defvar gnus-current-move-group nil)
1263
1264 (defvar gnus-newsgroup-dependencies nil)
1265 (defvar gnus-newsgroup-threads nil)
1266 (defvar gnus-newsgroup-async nil)
1267 (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
1268
1269 (defvar gnus-newsgroup-adaptive nil)
1270
1271 (defvar gnus-summary-display-table nil)
1272
1273 (defconst gnus-group-line-format-alist
1274 (list (list ?M 'marked ?c)
1275 (list ?S 'subscribed ?c)
1276 (list ?L 'level ?d)
1277 (list ?N 'number ?s)
1278 (list ?I 'number-of-dormant ?d)
1279 (list ?T 'number-of-ticked ?d)
1280 (list ?R 'number-of-read ?s)
1281 (list ?t 'number-total ?d)
1282 (list ?y 'number-of-unread-unticked ?s)
1283 (list ?i 'number-of-ticked-and-dormant ?d)
1284 (list ?g 'group ?s)
1285 (list ?G 'qualified-group ?s)
1286 (list ?D 'newsgroup-description ?s)
1287 (list ?o 'moderated ?c)
1288 (list ?O 'moderated-string ?s)
1289 (list ?p 'process-marked ?c)
1290 (list ?s 'news-server ?s)
1291 (list ?n 'news-method ?s)
1292 (list ?z 'news-method-string ?s)
1293 (list ?u 'user-defined ?s)))
1294
1295 (defconst gnus-summary-line-format-alist
1296 (list (list ?N 'number ?d)
1297 (list ?S 'subject ?s)
1298 (list ?s 'subject-or-nil ?s)
1299 (list ?n 'name ?s)
1300 (list ?A '(car (cdr (funcall gnus-extract-address-components from)))
1301 ?s)
1302 (list ?a '(or (car (funcall gnus-extract-address-components from))
1303 from) ?s)
1304 (list ?F 'from ?s)
1305 (list ?x (macroexpand '(mail-header-xref header)) ?s)
1306 (list ?D (macroexpand '(mail-header-date header)) ?s)
1307 (list ?d '(gnus-dd-mmm (mail-header-date header)) ?s)
1308 (list ?M (macroexpand '(mail-header-id header)) ?s)
1309 (list ?r (macroexpand '(mail-header-references header)) ?s)
1310 (list ?c '(or (mail-header-chars header) 0) ?d)
1311 (list ?L 'lines ?d)
1312 (list ?I 'indentation ?s)
1313 (list ?T '(if (= level 0) "" (make-string (frame-width) ? )) ?s)
1314 (list ?R 'replied ?c)
1315 (list ?\[ 'opening-bracket ?c)
1316 (list ?\] 'closing-bracket ?c)
1317 (list ?\> '(make-string level ? ) ?s)
1318 (list ?\< '(make-string (max 0 (- 20 level)) ? ) ?s)
1319 (list ?i 'score ?d)
1320 (list ?z 'score-char ?c)
1321 (list ?U 'unread ?c)
1322 (list ?t '(gnus-summary-number-of-articles-in-thread
1323 (and (boundp 'thread) (car thread)))
1324 ?d)
1325 (list ?e '(gnus-summary-number-of-articles-in-thread
1326 (and (boundp 'thread) (car thread)) t)
1327 ?c)
1328 (list ?u 'user-defined ?s))
1329 "An alist of format specifications that can appear in summary lines,
1330 and what variables they correspond with, along with the type of the
1331 variable (string, integer, character, etc).")
1332
1333 (defconst gnus-summary-dummy-line-format-alist
1334 (list (list ?S 'subject ?s)
1335 (list ?N 'number ?d)
1336 (list ?u 'user-defined ?s)))
1337
1338 (defconst gnus-summary-mode-line-format-alist
1339 (list (list ?G 'group-name ?s)
1340 (list ?g '(gnus-short-group-name group-name) ?s)
1341 (list ?A 'article-number ?d)
1342 (list ?Z 'unread-and-unselected ?s)
1343 (list ?V 'gnus-version ?s)
1344 (list ?U 'unread ?d)
1345 (list ?S 'subject ?s)
1346 (list ?e 'unselected ?d)
1347 (list ?u 'user-defined ?s)
1348 (list ?b 'buffer-name ?s)
1349 (list ?s '(gnus-current-score-file-nondirectory) ?s)))
1350
1351 (defconst gnus-group-mode-line-format-alist
1352 (list (list ?S 'news-server ?s)
1353 (list ?M 'news-method ?s)
1354 (list ?b '(buffer-name) ?s)
1355 (list ?u 'user-defined ?s)))
1356
1357 (defvar gnus-have-read-active-file nil)
1358
1359 (defconst gnus-maintainer
1360 "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
1361 "The mail address of the Gnus maintainers.")
1362
1363 (defconst gnus-version "Gnus v5.1"
1364 "Version number for this version of Gnus.")
1365
1366 (defvar gnus-info-nodes
1367 '((gnus-group-mode "(gnus)The Group Buffer")
1368 (gnus-summary-mode "(gnus)The Summary Buffer")
1369 (gnus-article-mode "(gnus)The Article Buffer"))
1370 "Assoc list of major modes and related Info nodes.")
1371
1372 (defvar gnus-group-buffer "*Group*")
1373 (defvar gnus-summary-buffer "*Summary*")
1374 (defvar gnus-article-buffer "*Article*")
1375 (defvar gnus-server-buffer "*Server*")
1376
1377 (defvar gnus-work-buffer " *gnus work*")
1378
1379 (defvar gnus-buffer-list nil
1380 "Gnus buffers that should be killed on exit.")
1381
1382 (defvar gnus-server-alist nil
1383 "List of available servers.")
1384
1385 (defvar gnus-variable-list
1386 '(gnus-newsrc-options gnus-newsrc-options-n
1387 gnus-newsrc-last-checked-date
1388 gnus-newsrc-alist gnus-server-alist
1389 gnus-killed-list gnus-zombie-list)
1390 "Gnus variables saved in the quick startup file.")
1391
1392 (defvar gnus-overload-functions
1393 '((news-inews gnus-inews-news "rnewspost"))
1394 "Functions overloaded by gnus.
1395 It is a list of `(original overload &optional file)'.")
1396
1397 (defvar gnus-newsrc-options nil
1398 "Options line in the .newsrc file.")
1399
1400 (defvar gnus-newsrc-options-n nil
1401 "List of regexps representing groups to be subscribed/ignored unconditionally.")
1402
1403 (defvar gnus-newsrc-last-checked-date nil
1404 "Date Gnus last asked server for new newsgroups.")
1405
1406 (defvar gnus-newsrc-alist nil
1407 "Assoc list of read articles.
1408 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1409
1410 (defvar gnus-newsrc-hashtb nil
1411 "Hashtable of gnus-newsrc-alist.")
1412
1413 (defvar gnus-killed-list nil
1414 "List of killed newsgroups.")
1415
1416 (defvar gnus-killed-hashtb nil
1417 "Hash table equivalent of gnus-killed-list.")
1418
1419 (defvar gnus-zombie-list nil
1420 "List of almost dead newsgroups.")
1421
1422 (defvar gnus-description-hashtb nil
1423 "Descriptions of newsgroups.")
1424
1425 (defvar gnus-list-of-killed-groups nil
1426 "List of newsgroups that have recently been killed by the user.")
1427
1428 (defvar gnus-active-hashtb nil
1429 "Hashtable of active articles.")
1430
1431 (defvar gnus-moderated-list nil
1432 "List of moderated newsgroups.")
1433
1434 (defvar gnus-group-marked nil)
1435
1436 (defvar gnus-current-startup-file nil
1437 "Startup file for the current host.")
1438
1439 (defvar gnus-last-search-regexp nil
1440 "Default regexp for article search command.")
1441
1442 (defvar gnus-last-shell-command nil
1443 "Default shell command on article.")
1444
1445 (defvar gnus-current-select-method nil
1446 "The current method for selecting a newsgroup.")
1447
1448 (defvar gnus-group-list-mode nil)
1449
1450 (defvar gnus-article-internal-prepare-hook nil)
1451
1452 (defvar gnus-newsgroup-name nil)
1453 (defvar gnus-newsgroup-begin nil)
1454 (defvar gnus-newsgroup-end nil)
1455 (defvar gnus-newsgroup-last-rmail nil)
1456 (defvar gnus-newsgroup-last-mail nil)
1457 (defvar gnus-newsgroup-last-folder nil)
1458 (defvar gnus-newsgroup-last-file nil)
1459 (defvar gnus-newsgroup-auto-expire nil)
1460 (defvar gnus-newsgroup-active nil)
1461
1462 (defvar gnus-newsgroup-unreads nil
1463 "List of unread articles in the current newsgroup.")
1464
1465 (defvar gnus-newsgroup-unselected nil
1466 "List of unselected unread articles in the current newsgroup.")
1467
1468 (defvar gnus-newsgroup-reads nil
1469 "Alist of read articles and article marks in the current newsgroup.")
1470
1471 (defvar gnus-newsgroup-marked nil
1472 "List of ticked articles in the current newsgroup (a subset of unread art).")
1473
1474 (defvar gnus-newsgroup-killed nil
1475 "List of ranges of articles that have been through the scoring process.")
1476
1477 (defvar gnus-newsgroup-kill-headers nil)
1478
1479 (defvar gnus-newsgroup-replied nil
1480 "List of articles that have been replied to in the current newsgroup.")
1481
1482 (defvar gnus-newsgroup-expirable nil
1483 "List of articles in the current newsgroup that can be expired.")
1484
1485 (defvar gnus-newsgroup-processable nil
1486 "List of articles in the current newsgroup that can be processed.")
1487
1488 (defvar gnus-newsgroup-bookmarks nil
1489 "List of articles in the current newsgroup that have bookmarks.")
1490
1491 (defvar gnus-newsgroup-dormant nil
1492 "List of dormant articles in the current newsgroup.")
1493
1494 (defvar gnus-newsgroup-scored nil
1495 "List of scored articles in the current newsgroup.")
1496
1497 (defvar gnus-newsgroup-headers nil
1498 "List of article headers in the current newsgroup.")
1499 (defvar gnus-newsgroup-headers-hashtb-by-number nil)
1500
1501 (defvar gnus-newsgroup-ancient nil
1502 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1503
1504 (defvar gnus-current-article nil)
1505 (defvar gnus-article-current nil)
1506 (defvar gnus-current-headers nil)
1507 (defvar gnus-have-all-headers nil)
1508 (defvar gnus-last-article nil)
1509 (defvar gnus-newsgroup-history nil)
1510 (defvar gnus-current-kill-article nil)
1511
1512 ;; Save window configuration.
1513 (defvar gnus-prev-winconf nil)
1514
1515 ;; Format specs
1516 (defvar gnus-summary-line-format-spec nil)
1517 (defvar gnus-summary-dummy-line-format-spec nil)
1518 (defvar gnus-group-line-format-spec nil)
1519 (defvar gnus-summary-mode-line-format-spec nil)
1520 (defvar gnus-article-mode-line-format-spec nil)
1521 (defvar gnus-group-mode-line-format-spec nil)
1522 (defvar gnus-summary-mark-positions nil)
1523 (defvar gnus-group-mark-positions nil)
1524
1525 (defvar gnus-summary-expunge-below nil)
1526 (defvar gnus-reffed-article-number nil)
1527
1528 ; Let the byte-compiler know that we know about this variable.
1529 (defvar rmail-default-rmail-file)
1530
1531 (defvar gnus-cache-removable-articles nil)
1532
1533 (defconst gnus-summary-local-variables
1534 '(gnus-newsgroup-name
1535 gnus-newsgroup-begin gnus-newsgroup-end
1536 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1537 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1538 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1539 gnus-newsgroup-unselected gnus-newsgroup-marked
1540 gnus-newsgroup-reads
1541 gnus-newsgroup-replied gnus-newsgroup-expirable
1542 gnus-newsgroup-processable gnus-newsgroup-killed
1543 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1544 gnus-newsgroup-headers gnus-newsgroup-headers-hashtb-by-number
1545 gnus-current-article gnus-current-headers gnus-have-all-headers
1546 gnus-last-article gnus-article-internal-prepare-hook
1547 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1548 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1549 gnus-newsgroup-threads gnus-newsgroup-async
1550 gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1551 gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files
1552 gnus-newsgroup-history gnus-newsgroup-ancient
1553 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1554 gnus-cache-removable-articles)
1555 "Variables that are buffer-local to the summary buffers.")
1556
1557 (defconst gnus-bug-message
1558 "Sending a bug report to the Gnus Towers.
1559 ========================================
1560
1561 The buffer below is a mail buffer. When you press `C-c C-c', it will
1562 be sent to the Gnus Bug Exterminators.
1563
1564 At the bottom of the buffer you'll see lots of variable settings.
1565 Please do not delete those. They will tell the Bug People what your
1566 environment is, so that it will be easier to locate the bugs.
1567
1568 If you have found a bug that makes Emacs go \"beep\", set
1569 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
1570 and include the backtrace in your bug report.
1571
1572 Please describe the bug in annoying, painstaking detail.
1573
1574 Thank you for your help in stamping out bugs.
1575 ")
1576
1577 ;;; End of variables.
1578
1579 ;; Define some autoload functions Gnus might use.
1580 (eval-and-compile
1581
1582 ;; Various
1583 (autoload 'metamail-buffer "metamail")
1584 (autoload 'Info-goto-node "info")
1585 (autoload 'hexl-hex-string-to-integer "hexl")
1586 (autoload 'pp "pp")
1587 (autoload 'pp-to-string "pp")
1588 (autoload 'pp-eval-expression "pp")
1589 (autoload 'mail-extract-address-components "mail-extr")
1590
1591 (autoload 'nnmail-split-fancy "nnmail")
1592 (autoload 'nnvirtual-catchup-group "nnvirtual")
1593
1594 ;; timezone
1595 (autoload 'timezone-make-date-arpa-standard "timezone")
1596 (autoload 'timezone-fix-time "timezone")
1597 (autoload 'timezone-make-sortable-date "timezone")
1598 (autoload 'timezone-make-time-string "timezone")
1599
1600 ;; rmail & friends
1601 (autoload 'mail-position-on-field "sendmail")
1602 (autoload 'mail-setup "sendmail")
1603 (autoload 'rmail-output "rmailout")
1604 (autoload 'news-mail-other-window "rnewspost")
1605 (autoload 'news-reply-yank-original "rnewspost")
1606 (autoload 'news-caesar-buffer-body "rnewspost")
1607 (autoload 'rmail-insert-rmail-file-header "rmail")
1608 (autoload 'rmail-count-new-messages "rmail")
1609 (autoload 'rmail-show-message "rmail")
1610
1611 ;; gnus-soup
1612 ;;(autoload 'gnus-group-brew-soup "gnus-soup" nil t)
1613 ;;(autoload 'gnus-brew-soup "gnus-soup" nil t)
1614 ;;(autoload 'gnus-soup-add-article "gnus-soup" nil t)
1615 ;;(autoload 'gnus-soup-send-replies "gnus-soup" nil t)
1616 ;;(autoload 'gnus-soup-save-areas "gnus-soup" nil t)
1617 ;;(autoload 'gnus-soup-pack-packet "gnus-soup" nil t)
1618 ;;(autoload 'nnsoup-pack-replies "nnsoup" nil t)
1619
1620 ;; gnus-mh
1621 (autoload 'gnus-mail-reply-using-mhe "gnus-mh")
1622 (autoload 'gnus-mail-forward-using-mhe "gnus-mh")
1623 (autoload 'gnus-mail-other-window-using-mhe "gnus-mh")
1624 (autoload 'gnus-summary-save-in-folder "gnus-mh" nil t)
1625 (autoload 'gnus-summary-save-article-folder "gnus-mh")
1626 (autoload 'gnus-Folder-save-name "gnus-mh")
1627 (autoload 'gnus-folder-save-name "gnus-mh")
1628
1629 ;; gnus-vis misc
1630 (autoload 'gnus-group-make-menu-bar "gnus-vis")
1631 (autoload 'gnus-summary-make-menu-bar "gnus-vis")
1632 (autoload 'gnus-server-make-menu-bar "gnus-vis")
1633 (autoload 'gnus-article-make-menu-bar "gnus-vis")
1634 (autoload 'gnus-browse-make-menu-bar "gnus-vis")
1635 (autoload 'gnus-highlight-selected-summary "gnus-vis")
1636 (autoload 'gnus-summary-highlight-line "gnus-vis")
1637 (autoload 'gnus-carpal-setup-buffer "gnus-vis")
1638
1639 ;; gnus-vis article
1640 (autoload 'gnus-article-push-button "gnus-vis" nil t)
1641 (autoload 'gnus-article-press-button "gnus-vis" nil t)
1642 (autoload 'gnus-article-highlight "gnus-vis" nil t)
1643 (autoload 'gnus-article-highlight-some "gnus-vis" nil t)
1644 (autoload 'gnus-article-hide "gnus-vis" nil t)
1645 (autoload 'gnus-article-hide-signature "gnus-vis" nil t)
1646 (autoload 'gnus-article-highlight-headers "gnus-vis" nil t)
1647 (autoload 'gnus-article-highlight-signature "gnus-vis" nil t)
1648 (autoload 'gnus-article-add-buttons "gnus-vis" nil t)
1649 (autoload 'gnus-article-next-button "gnus-vis" nil t)
1650 (autoload 'gnus-article-add-button "gnus-vis")
1651
1652 ;; gnus-cite
1653 (autoload 'gnus-article-highlight-citation "gnus-cite" nil t)
1654 (autoload 'gnus-article-hide-citation-maybe "gnus-cite" nil t)
1655 (autoload 'gnus-article-hide-citation "gnus-cite" nil t)
1656
1657 ;; gnus-kill
1658 (autoload 'gnus-kill "gnus-kill")
1659 (autoload 'gnus-apply-kill-file-internal "gnus-kill")
1660 (autoload 'gnus-kill-file-edit-file "gnus-kill")
1661 (autoload 'gnus-kill-file-raise-followups-to-author "gnus-kill")
1662 (autoload 'gnus-execute "gnus-kill")
1663 (autoload 'gnus-expunge "gnus-kill")
1664
1665 ;; gnus-cache
1666 (autoload 'gnus-cache-possibly-enter-article "gnus-cache")
1667 (autoload 'gnus-cache-save-buffers "gnus-cache")
1668 (autoload 'gnus-cache-possibly-remove-articles "gnus-cache")
1669 (autoload 'gnus-cache-request-article "gnus-cache")
1670 (autoload 'gnus-cache-retrieve-headers "gnus-cache")
1671 (autoload 'gnus-cache-possibly-alter-active "gnus-cache")
1672 (autoload 'gnus-jog-cache "gnus-cache" nil t)
1673 (autoload 'gnus-cache-enter-remove-article "gnus-cache")
1674
1675 ;; gnus-score
1676 (autoload 'gnus-summary-increase-score "gnus-score" nil t)
1677 (autoload 'gnus-summary-lower-score "gnus-score" nil t)
1678 (autoload 'gnus-summary-score-map "gnus-score" nil nil 'keymap)
1679 (autoload 'gnus-score-save "gnus-score")
1680 (autoload 'gnus-score-headers "gnus-score")
1681 (autoload 'gnus-current-score-file-nondirectory "gnus-score")
1682 (autoload 'gnus-score-adaptive "gnus-score")
1683 (autoload 'gnus-score-remove-lines-adaptive "gnus-score")
1684 (autoload 'gnus-score-find-trace "gnus-score")
1685
1686 ;; gnus-edit
1687 (autoload 'gnus-score-customize "gnus-edit" nil t)
1688
1689 ;; gnus-uu
1690 (autoload 'gnus-uu-extract-map "gnus-uu" nil nil 'keymap)
1691 (autoload 'gnus-uu-mark-map "gnus-uu" nil nil 'keymap)
1692 (autoload 'gnus-uu-digest-mail-forward "gnus-uu" nil t)
1693 (autoload 'gnus-uu-digest-post-forward "gnus-uu" nil t)
1694 (autoload 'gnus-uu-mark-series "gnus-uu" nil t)
1695 (autoload 'gnus-uu-mark-region "gnus-uu" nil t)
1696 (autoload 'gnus-uu-mark-by-regexp "gnus-uu" nil t)
1697 (autoload 'gnus-uu-mark-all "gnus-uu" nil t)
1698 (autoload 'gnus-uu-mark-sparse "gnus-uu" nil t)
1699 (autoload 'gnus-uu-mark-thread "gnus-uu" nil t)
1700 (autoload 'gnus-uu-decode-uu "gnus-uu" nil t)
1701 (autoload 'gnus-uu-decode-uu-and-save "gnus-uu" nil t)
1702 (autoload 'gnus-uu-decode-unshar "gnus-uu" nil t)
1703 (autoload 'gnus-uu-decode-unshar-and-save "gnus-uu" nil t)
1704 (autoload 'gnus-uu-decode-save "gnus-uu" nil t)
1705 (autoload 'gnus-uu-decode-binhex "gnus-uu" nil t)
1706 (autoload 'gnus-uu-decode-uu-view "gnus-uu" nil t)
1707 (autoload 'gnus-uu-decode-uu-and-save-view "gnus-uu" nil t)
1708 (autoload 'gnus-uu-decode-unshar-view "gnus-uu" nil t)
1709 (autoload 'gnus-uu-decode-unshar-and-save-view "gnus-uu" nil t)
1710 (autoload 'gnus-uu-decode-save-view "gnus-uu" nil t)
1711 (autoload 'gnus-uu-decode-binhex-view "gnus-uu" nil t)
1712
1713 ;; gnus-msg
1714 (autoload 'gnus-summary-send-map "gnus-msg" nil nil 'keymap)
1715 (autoload 'gnus-group-post-news "gnus-msg" nil t)
1716 (autoload 'gnus-group-mail "gnus-msg" nil t)
1717 (autoload 'gnus-summary-post-news "gnus-msg" nil t)
1718 (autoload 'gnus-summary-followup "gnus-msg" nil t)
1719 (autoload 'gnus-summary-followup-with-original "gnus-msg" nil t)
1720 (autoload 'gnus-summary-followup-and-reply "gnus-msg" nil t)
1721 (autoload 'gnus-summary-followup-and-reply-with-original "gnus-msg" nil t)
1722 (autoload 'gnus-summary-cancel-article "gnus-msg" nil t)
1723 (autoload 'gnus-summary-supersede-article "gnus-msg" nil t)
1724 (autoload 'gnus-post-news "gnus-msg" nil t)
1725 (autoload 'gnus-inews-news "gnus-msg" nil t)
1726 (autoload 'gnus-cancel-news "gnus-msg" nil t)
1727 (autoload 'gnus-summary-reply "gnus-msg" nil t)
1728 (autoload 'gnus-summary-reply-with-original "gnus-msg" nil t)
1729 (autoload 'gnus-summary-mail-forward "gnus-msg" nil t)
1730 (autoload 'gnus-summary-mail-other-window "gnus-msg" nil t)
1731 (autoload 'gnus-mail-reply-using-mail "gnus-msg")
1732 (autoload 'gnus-mail-yank-original "gnus-msg")
1733 (autoload 'gnus-mail-send-and-exit "gnus-msg")
1734 (autoload 'gnus-mail-forward-using-mail "gnus-msg")
1735 (autoload 'gnus-mail-other-window-using-mail "gnus-msg")
1736 (autoload 'gnus-article-mail "gnus-msg")
1737 (autoload 'gnus-bug "gnus-msg" nil t)
1738
1739 ;; gnus-vm
1740 (autoload 'gnus-summary-save-in-vm "gnus-vm" nil t)
1741 (autoload 'gnus-summary-save-article-vm "gnus-vm" nil t)
1742 (autoload 'gnus-mail-forward-using-vm "gnus-vm")
1743 (autoload 'gnus-mail-reply-using-vm "gnus-vm")
1744 (autoload 'gnus-mail-other-window-using-vm "gnus-vm" nil t)
1745 (autoload 'gnus-yank-article "gnus-vm" nil t)
1746
1747 )
1748
1749 \f
1750
1751 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1752 ;; If you want the cursor to go somewhere else, set these two
1753 ;; functions in some startup hook to whatever you want.
1754 (defalias 'gnus-summary-position-cursor 'gnus-goto-colon)
1755 (defalias 'gnus-group-position-cursor 'gnus-goto-colon)
1756
1757 ;;; Various macros and substs.
1758
1759 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
1760 "Pop to BUFFER, evaluate FORMS, and then returns to original window."
1761 (` (let ((GnusStartBufferWindow (selected-window)))
1762 (unwind-protect
1763 (progn
1764 (pop-to-buffer (, buffer))
1765 (,@ forms))
1766 (select-window GnusStartBufferWindow)))))
1767
1768 (defmacro gnus-gethash (string hashtable)
1769 "Get hash value of STRING in HASHTABLE."
1770 ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable))))
1771 ;;(` (abbrev-expansion (, string) (, hashtable)))
1772 (` (symbol-value (intern-soft (, string) (, hashtable)))))
1773
1774 (defmacro gnus-sethash (string value hashtable)
1775 "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
1776 ;; We cannot use define-abbrev since it only accepts string as value.
1777 ;; (set (intern string hashtable) value))
1778 (` (set (intern (, string) (, hashtable)) (, value))))
1779
1780 (defsubst gnus-buffer-substring (beg end)
1781 (buffer-substring (match-beginning beg) (match-end end)))
1782
1783 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1784 ;; function `substring' might cut on a middle of multi-octet
1785 ;; character.
1786 (defun gnus-truncate-string (str width)
1787 (substring str 0 width))
1788
1789 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
1790 ;; to limit the length of a string. This function is necessary since
1791 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
1792 (defsubst gnus-limit-string (str width)
1793 (if (> (length str) width)
1794 (substring str 0 width)
1795 str))
1796
1797 (defsubst gnus-simplify-subject-re (subject)
1798 "Remove \"Re:\" from subject lines."
1799 (let ((case-fold-search t))
1800 (if (string-match "^re: *" subject)
1801 (substring subject (match-end 0))
1802 subject)))
1803
1804 (defsubst gnus-goto-char (point)
1805 (and point (goto-char point)))
1806
1807 (defmacro gnus-buffer-exists-p (buffer)
1808 (` (and (, buffer)
1809 (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
1810 (, buffer)))))
1811
1812 (defmacro gnus-kill-buffer (buffer)
1813 (` (if (gnus-buffer-exists-p (, buffer))
1814 (kill-buffer (, buffer)))))
1815
1816 (defsubst gnus-point-at-bol ()
1817 "Return point at the beginning of line."
1818 (let ((p (point)))
1819 (beginning-of-line)
1820 (prog1
1821 (point)
1822 (goto-char p))))
1823
1824 (defsubst gnus-point-at-eol ()
1825 "Return point at the beginning of line."
1826 (let ((p (point)))
1827 (end-of-line)
1828 (prog1
1829 (point)
1830 (goto-char p))))
1831
1832 ;; Delete the current line (and the next N lines.);
1833 (defmacro gnus-delete-line (&optional n)
1834 (` (delete-region (progn (beginning-of-line) (point))
1835 (progn (forward-line (, (or n 1))) (point)))))
1836
1837 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1838 (defvar gnus-init-inhibit nil)
1839 (defun gnus-read-init-file (&optional inhibit-next)
1840 (if gnus-init-inhibit
1841 (setq gnus-init-inhibit nil)
1842 (setq gnus-init-inhibit inhibit-next)
1843 (and gnus-init-file
1844 (or (and (file-exists-p gnus-init-file)
1845 ;; Don't try to load a directory.
1846 (not (file-directory-p gnus-init-file)))
1847 (file-exists-p (concat gnus-init-file ".el"))
1848 (file-exists-p (concat gnus-init-file ".elc")))
1849 (load gnus-init-file nil t))))
1850
1851 ;;; Load the user startup file.
1852 ;; (eval '(gnus-read-init-file 'inhibit))
1853
1854 ;;; Load the compatibility functions.
1855
1856 (require 'gnus-cus)
1857 (require 'gnus-ems)
1858
1859 \f
1860 ;;;
1861 ;;; Gnus Utility Functions
1862 ;;;
1863
1864 (defun gnus-extract-address-components (from)
1865 (let (name address)
1866 ;; First find the address - the thing with the @ in it. This may
1867 ;; not be accurate in mail addresses, but does the trick most of
1868 ;; the time in news messages.
1869 (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
1870 (setq address (substring from (match-beginning 0) (match-end 0))))
1871 ;; Then we check whether the "name <address>" format is used.
1872 (and address
1873 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1874 ;; Linear white space is not required.
1875 (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
1876 (and (setq name (substring from 0 (match-beginning 0)))
1877 ;; Strip any quotes from the name.
1878 (string-match "\".*\"" name)
1879 (setq name (substring name 1 (1- (match-end 0))))))
1880 ;; If not, then "address (name)" is used.
1881 (or name
1882 (and (string-match "(.+)" from)
1883 (setq name (substring from (1+ (match-beginning 0))
1884 (1- (match-end 0)))))
1885 (and (string-match "()" from)
1886 (setq name address))
1887 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
1888 ;; XOVER might not support folded From headers.
1889 (and (string-match "(.*" from)
1890 (setq name (substring from (1+ (match-beginning 0))
1891 (match-end 0)))))
1892 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1893 (list (or name from) (or address from))))
1894
1895 (defun gnus-fetch-field (field)
1896 "Return the value of the header FIELD of current article."
1897 (save-excursion
1898 (save-restriction
1899 (let ((case-fold-search t))
1900 (gnus-narrow-to-headers)
1901 (mail-fetch-field field)))))
1902
1903 (defun gnus-goto-colon ()
1904 (beginning-of-line)
1905 (search-forward ":" (gnus-point-at-eol) t))
1906
1907 (defun gnus-narrow-to-headers ()
1908 (widen)
1909 (save-excursion
1910 (narrow-to-region
1911 (goto-char (point-min))
1912 (if (search-forward "\n\n" nil t)
1913 (1- (point))
1914 (point-max)))))
1915
1916 (defvar gnus-old-specs nil)
1917
1918 (defun gnus-update-format-specifications ()
1919 (gnus-make-thread-indent-array)
1920
1921 (let ((formats '(summary summary-dummy group
1922 summary-mode group-mode article-mode))
1923 old-format new-format)
1924 (while formats
1925 (setq new-format (symbol-value
1926 (intern (format "gnus-%s-line-format" (car formats)))))
1927 (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs)))
1928 (equal old-format new-format))
1929 (set (intern (format "gnus-%s-line-format-spec" (car formats)))
1930 (gnus-parse-format
1931 new-format
1932 (symbol-value
1933 (intern (format "gnus-%s-line-format-alist"
1934 (if (eq (car formats) 'article-mode)
1935 'summary-mode (car formats))))))))
1936 (setq gnus-old-specs (cons (cons (car formats) new-format)
1937 (delq (car formats) gnus-old-specs)))
1938 (setq formats (cdr formats))))
1939
1940 (gnus-update-group-mark-positions)
1941 (gnus-update-summary-mark-positions)
1942
1943 (if (and (string-match "%D" gnus-group-line-format)
1944 (not gnus-description-hashtb)
1945 gnus-read-active-file)
1946 (gnus-read-all-descriptions-files)))
1947
1948 (defun gnus-update-summary-mark-positions ()
1949 (save-excursion
1950 (let ((gnus-replied-mark 129)
1951 (gnus-score-below-mark 130)
1952 (gnus-score-over-mark 130)
1953 (thread nil)
1954 pos)
1955 (gnus-set-work-buffer)
1956 (gnus-summary-insert-line
1957 nil [0 "" "" "" "" "" 0 0 ""] 0 nil 128 t nil "" nil 1)
1958 (goto-char (point-min))
1959 (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
1960 (- (point) 2)))))
1961 (goto-char (point-min))
1962 (setq pos (cons (cons 'replied (and (search-forward "\201" nil t)
1963 (- (point) 2))) pos))
1964 (goto-char (point-min))
1965 (setq pos (cons (cons 'score (and (search-forward "\202" nil t)
1966 (- (point) 2))) pos))
1967 (setq gnus-summary-mark-positions pos))))
1968
1969 (defun gnus-update-group-mark-positions ()
1970 (save-excursion
1971 (let ((gnus-process-mark 128)
1972 (gnus-group-marked '("dummy.group")))
1973 (gnus-sethash "dummy.group" '(0 . 0) gnus-active-hashtb)
1974 (gnus-set-work-buffer)
1975 (gnus-group-insert-group-line nil "dummy.group" 0 nil 0 nil)
1976 (goto-char (point-min))
1977 (setq gnus-group-mark-positions
1978 (list (cons 'process (and (search-forward "\200" nil t)
1979 (- (point) 2))))))))
1980
1981 (defun gnus-mouse-face-function (form)
1982 (` (let ((string (, form)))
1983 (put-text-property 0 (length string) 'mouse-face gnus-mouse-face string)
1984 string)))
1985
1986 (defun gnus-max-width-function (el max-width)
1987 (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
1988 (` (let* ((val (eval (, el)))
1989 (valstr (if (numberp val)
1990 (int-to-string val) val)))
1991 (if (> (length valstr) (, max-width))
1992 (substring valstr 0 (, max-width))
1993 valstr))))
1994
1995 (defun gnus-parse-format (format spec-alist)
1996 ;; This function parses the FORMAT string with the help of the
1997 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
1998 ;; string. If the FORMAT string contains the specifiers %( and %)
1999 ;; the text between them will have the mouse-face text property.
2000 (if (string-match "\\`\\(.*\\)%(\\(.*\\)%)\\(.*\n?\\)\\'" format)
2001 (if (and gnus-visual gnus-mouse-face)
2002 (let ((pre (substring format (match-beginning 1) (match-end 1)))
2003 (button (substring format (match-beginning 2) (match-end 2)))
2004 (post (substring format (match-beginning 3) (match-end 3))))
2005 (list 'concat
2006 (gnus-parse-simple-format pre spec-alist)
2007 (gnus-mouse-face-function
2008 (gnus-parse-simple-format button spec-alist))
2009 (gnus-parse-simple-format post spec-alist)))
2010 (gnus-parse-simple-format
2011 (concat (substring format (match-beginning 1) (match-end 1))
2012 (substring format (match-beginning 2) (match-end 2))
2013 (substring format (match-beginning 3) (match-end 3)))
2014 spec-alist))
2015 (gnus-parse-simple-format format spec-alist)))
2016
2017 (defun gnus-parse-simple-format (format spec-alist)
2018 ;; This function parses the FORMAT string with the help of the
2019 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
2020 ;; string. The list will consist of the symbol `format', a format
2021 ;; specification string, and a list of forms depending on the
2022 ;; SPEC-ALIST.
2023 (let ((max-width 0)
2024 spec flist fstring newspec elem beg)
2025 (save-excursion
2026 (gnus-set-work-buffer)
2027 (insert format)
2028 (goto-char (point-min))
2029 (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?" nil t)
2030 (setq spec (string-to-char (buffer-substring (match-beginning 2)
2031 (match-end 2))))
2032 ;; First check if there are any specs that look anything like
2033 ;; "%12,12A", ie. with a "max width specification". These have
2034 ;; to be treated specially.
2035 (if (setq beg (match-beginning 1))
2036 (setq max-width
2037 (string-to-int
2038 (buffer-substring (1+ (match-beginning 1)) (match-end 1))))
2039 (setq max-width 0)
2040 (setq beg (match-beginning 2)))
2041 ;; Find the specification from `spec-alist'.
2042 (if (not (setq elem (cdr (assq spec spec-alist))))
2043 (setq elem '("*" ?s)))
2044 ;; Treat user defined format specifiers specially
2045 (and (eq (car elem) 'user-defined)
2046 (setq elem
2047 (list
2048 (list (intern (concat "gnus-user-format-function-"
2049 (buffer-substring
2050 (match-beginning 3)
2051 (match-end 3))))
2052 'header)
2053 ?s))
2054 (delete-region (match-beginning 3) (match-end 3)))
2055 (if (not (zerop max-width))
2056 (let ((el (car elem)))
2057 (cond ((= (car (cdr elem)) ?c)
2058 (setq el (list 'char-to-string el)))
2059 ((= (car (cdr elem)) ?d)
2060 (numberp el) (setq el (list 'int-to-string el))))
2061 (setq flist (cons (gnus-max-width-function el max-width)
2062 flist))
2063 (setq newspec ?s))
2064 (setq flist (cons (car elem) flist))
2065 (setq newspec (car (cdr elem))))
2066 ;; Remove the old specification (and possibly a ",12" string).
2067 (delete-region beg (match-end 2))
2068 ;; Insert the new specification.
2069 (goto-char beg)
2070 (insert newspec))
2071 (setq fstring (buffer-substring 1 (point-max))))
2072 (cons 'format (cons fstring (nreverse flist)))))
2073
2074 (defun gnus-set-work-buffer ()
2075 (if (get-buffer gnus-work-buffer)
2076 (progn
2077 (set-buffer gnus-work-buffer)
2078 (erase-buffer))
2079 (set-buffer (get-buffer-create gnus-work-buffer))
2080 (kill-all-local-variables)
2081 (buffer-disable-undo (current-buffer))
2082 (gnus-add-current-to-buffer-list)))
2083
2084 ;; Article file names when saving.
2085
2086 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2087 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2088 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
2089 Otherwise, it is like ~/News/news/group/num."
2090 (let ((default
2091 (expand-file-name
2092 (concat (if (gnus-use-long-file-name 'not-save)
2093 (gnus-capitalize-newsgroup newsgroup)
2094 (gnus-newsgroup-directory-form newsgroup))
2095 "/" (int-to-string (mail-header-number headers)))
2096 (or gnus-article-save-directory "~/News"))))
2097 (if (and last-file
2098 (string-equal (file-name-directory default)
2099 (file-name-directory last-file))
2100 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2101 default
2102 (or last-file default))))
2103
2104 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2105 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2106 If variable `gnus-use-long-file-name' is non-nil, it is
2107 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2108 (let ((default
2109 (expand-file-name
2110 (concat (if (gnus-use-long-file-name 'not-save)
2111 newsgroup
2112 (gnus-newsgroup-directory-form newsgroup))
2113 "/" (int-to-string (mail-header-number headers)))
2114 (or gnus-article-save-directory "~/News"))))
2115 (if (and last-file
2116 (string-equal (file-name-directory default)
2117 (file-name-directory last-file))
2118 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2119 default
2120 (or last-file default))))
2121
2122 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2123 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2124 If variable `gnus-use-long-file-name' is non-nil, it is
2125 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2126 (or last-file
2127 (expand-file-name
2128 (if (gnus-use-long-file-name 'not-save)
2129 (gnus-capitalize-newsgroup newsgroup)
2130 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2131 (or gnus-article-save-directory "~/News"))))
2132
2133 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2134 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2135 If variable `gnus-use-long-file-name' is non-nil, it is
2136 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2137 (or last-file
2138 (expand-file-name
2139 (if (gnus-use-long-file-name 'not-save)
2140 newsgroup
2141 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2142 (or gnus-article-save-directory "~/News"))))
2143
2144 ;; For subscribing new newsgroup
2145
2146 (defun gnus-subscribe-hierarchical-interactive (groups)
2147 (let ((groups (sort groups 'string<))
2148 prefixes prefix start ans group starts)
2149 (while groups
2150 (setq prefixes (list "^"))
2151 (while (and groups prefixes)
2152 (while (not (string-match (car prefixes) (car groups)))
2153 (setq prefixes (cdr prefixes)))
2154 (setq prefix (car prefixes))
2155 (setq start (1- (length prefix)))
2156 (if (and (string-match "[^\\.]\\." (car groups) start)
2157 (cdr groups)
2158 (setq prefix
2159 (concat "^" (substring (car groups) 0 (match-end 0))))
2160 (string-match prefix (car (cdr groups))))
2161 (progn
2162 (setq prefixes (cons prefix prefixes))
2163 (message "Descend hierarchy %s? ([y]nsq): "
2164 (substring prefix 1 (1- (length prefix))))
2165 (setq ans (read-char))
2166 (cond ((= ans ?n)
2167 (while (and groups
2168 (string-match prefix
2169 (setq group (car groups))))
2170 (setq gnus-killed-list
2171 (cons group gnus-killed-list))
2172 (gnus-sethash group group gnus-killed-hashtb)
2173 (setq groups (cdr groups)))
2174 (setq starts (cdr starts)))
2175 ((= ans ?s)
2176 (while (and groups
2177 (string-match prefix
2178 (setq group (car groups))))
2179 (gnus-sethash group group gnus-killed-hashtb)
2180 (gnus-subscribe-alphabetically (car groups))
2181 (setq groups (cdr groups)))
2182 (setq starts (cdr starts)))
2183 ((= ans ?q)
2184 (while groups
2185 (setq group (car groups))
2186 (setq gnus-killed-list (cons group gnus-killed-list))
2187 (gnus-sethash group group gnus-killed-hashtb)
2188 (setq groups (cdr groups))))
2189 (t nil)))
2190 (message "Subscribe %s? ([n]yq)" (car groups))
2191 (setq ans (read-char))
2192 (setq group (car groups))
2193 (cond ((= ans ?y)
2194 (gnus-subscribe-alphabetically (car groups))
2195 (gnus-sethash group group gnus-killed-hashtb))
2196 ((= ans ?q)
2197 (while groups
2198 (setq group (car groups))
2199 (setq gnus-killed-list (cons group gnus-killed-list))
2200 (gnus-sethash group group gnus-killed-hashtb)
2201 (setq groups (cdr groups))))
2202 (t
2203 (setq gnus-killed-list (cons group gnus-killed-list))
2204 (gnus-sethash group group gnus-killed-hashtb)))
2205 (setq groups (cdr groups)))))))
2206
2207 (defun gnus-subscribe-randomly (newsgroup)
2208 "Subscribe new NEWSGROUP by making it the first newsgroup."
2209 (gnus-subscribe-newsgroup newsgroup))
2210
2211 (defun gnus-subscribe-alphabetically (newgroup)
2212 "Subscribe new NEWSGROUP and insert it in alphabetical order."
2213 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2214 (let ((groups (cdr gnus-newsrc-alist))
2215 before)
2216 (while (and (not before) groups)
2217 (if (string< newgroup (car (car groups)))
2218 (setq before (car (car groups)))
2219 (setq groups (cdr groups))))
2220 (gnus-subscribe-newsgroup newgroup before)))
2221
2222 (defun gnus-subscribe-hierarchically (newgroup)
2223 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
2224 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2225 (save-excursion
2226 (set-buffer (find-file-noselect gnus-current-startup-file))
2227 (let ((groupkey newgroup)
2228 before)
2229 (while (and (not before) groupkey)
2230 (goto-char (point-min))
2231 (let ((groupkey-re
2232 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
2233 (while (and (re-search-forward groupkey-re nil t)
2234 (progn
2235 (setq before (buffer-substring
2236 (match-beginning 1) (match-end 1)))
2237 (string< before newgroup)))))
2238 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
2239 (setq groupkey
2240 (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
2241 (substring groupkey (match-beginning 1) (match-end 1)))))
2242 (gnus-subscribe-newsgroup newgroup before))))
2243
2244 (defun gnus-subscribe-interactively (newsgroup)
2245 "Subscribe new NEWSGROUP interactively.
2246 It is inserted in hierarchical newsgroup order if subscribed. If not,
2247 it is killed."
2248 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
2249 (gnus-subscribe-hierarchically newsgroup)
2250 (setq gnus-killed-list (cons newsgroup gnus-killed-list))))
2251
2252 (defun gnus-subscribe-zombies (newsgroup)
2253 "Make new NEWSGROUP a zombie group."
2254 (setq gnus-zombie-list (cons newsgroup gnus-zombie-list)))
2255
2256 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
2257 "Subscribe new NEWSGROUP.
2258 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
2259 the first newsgroup."
2260 ;; We subscribe the group by changing its level to `subscribed'.
2261 (gnus-group-change-level
2262 newsgroup gnus-level-default-subscribed
2263 gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
2264 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
2265
2266 ;; For directories
2267
2268 (defun gnus-newsgroup-directory-form (newsgroup)
2269 "Make hierarchical directory name from NEWSGROUP name."
2270 (let ((newsgroup (gnus-newsgroup-savable-name newsgroup))
2271 (len (length newsgroup))
2272 idx)
2273 ;; If this is a foreign group, we don't want to translate the
2274 ;; entire name.
2275 (if (setq idx (string-match ":" newsgroup))
2276 (aset newsgroup idx ?/)
2277 (setq idx 0))
2278 ;; Replace all occurrences of `.' with `/'.
2279 (while (< idx len)
2280 (if (= (aref newsgroup idx) ?.)
2281 (aset newsgroup idx ?/))
2282 (setq idx (1+ idx)))
2283 newsgroup))
2284
2285 (defun gnus-newsgroup-savable-name (group)
2286 ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
2287 ;; with dots.
2288 (gnus-replace-chars-in-string group ?/ ?.))
2289
2290 (defun gnus-make-directory (dir)
2291 "Make DIRECTORY recursively."
2292 ;; Why don't we use `(make-directory dir 'parents)'? That's just one
2293 ;; of the many mysteries of the universe.
2294 (let* ((dir (expand-file-name dir default-directory))
2295 dirs err)
2296 (if (string-match "/$" dir)
2297 (setq dir (substring dir 0 (match-beginning 0))))
2298 ;; First go down the path until we find a directory that exists.
2299 (while (not (file-exists-p dir))
2300 (setq dirs (cons dir dirs))
2301 (string-match "/[^/]+$" dir)
2302 (setq dir (substring dir 0 (match-beginning 0))))
2303 ;; Then create all the subdirs.
2304 (while (and dirs (not err))
2305 (condition-case ()
2306 (make-directory (car dirs))
2307 (error (setq err t)))
2308 (setq dirs (cdr dirs)))
2309 ;; We return whether we were successful or not.
2310 (not dirs)))
2311
2312 (defun gnus-capitalize-newsgroup (newsgroup)
2313 "Capitalize NEWSGROUP name."
2314 (and (not (zerop (length newsgroup)))
2315 (concat (char-to-string (upcase (aref newsgroup 0)))
2316 (substring newsgroup 1))))
2317
2318 ;; Var
2319
2320 (defun gnus-simplify-subject (subject &optional re-only)
2321 "Remove `Re:' and words in parentheses.
2322 If optional argument RE-ONLY is non-nil, strip `Re:' only."
2323 (let ((case-fold-search t)) ;Ignore case.
2324 ;; Remove `Re:' and `Re^N:'.
2325 (if (string-match "^re:[ \t]*" subject)
2326 (setq subject (substring subject (match-end 0))))
2327 ;; Remove words in parentheses from end.
2328 (or re-only
2329 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
2330 (setq subject (substring subject 0 (match-beginning 0)))))
2331 ;; Return subject string.
2332 subject))
2333
2334 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
2335 ;; all whitespace.
2336 (defun gnus-simplify-subject-fuzzy (subject)
2337 (let ((case-fold-search t))
2338 (save-excursion
2339 (gnus-set-work-buffer)
2340 (insert subject)
2341 (inline (gnus-simplify-buffer-fuzzy))
2342 (buffer-string))))
2343
2344 (defun gnus-simplify-buffer-fuzzy ()
2345 (goto-char (point-min))
2346 ;; Fix by Stainless Steel Rat <ratinox@ccs.neu.edu>.
2347 (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*"
2348 nil t)
2349 (replace-match "" t t))
2350 (goto-char (point-min))
2351 (while (re-search-forward "[ \t\n]*([^()]*)[ \t\n]*$" nil t)
2352 (replace-match "" t t))
2353 (goto-char (point-min))
2354 (while (re-search-forward "[ \t]+" nil t)
2355 (replace-match " " t t))
2356 (goto-char (point-min))
2357 (while (re-search-forward "[ \t]+$" nil t)
2358 (replace-match "" t t))
2359 (goto-char (point-min))
2360 (while (re-search-forward "^[ \t]+" nil t)
2361 (replace-match "" t t))
2362 (if gnus-simplify-subject-fuzzy-regexp
2363 (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
2364 (replace-match "" t t))))
2365
2366 ;; Add the current buffer to the list of buffers to be killed on exit.
2367 (defun gnus-add-current-to-buffer-list ()
2368 (or (memq (current-buffer) gnus-buffer-list)
2369 (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
2370
2371 (defun gnus-string> (s1 s2)
2372 (not (or (string< s1 s2)
2373 (string= s1 s2))))
2374
2375 ;; Functions accessing headers.
2376 ;; Functions are more convenient than macros in some cases.
2377
2378 (defun gnus-header-number (header)
2379 (mail-header-number header))
2380
2381 (defun gnus-header-subject (header)
2382 (mail-header-subject header))
2383
2384 (defun gnus-header-from (header)
2385 (mail-header-from header))
2386
2387 (defun gnus-header-xref (header)
2388 (mail-header-xref header))
2389
2390 (defun gnus-header-lines (header)
2391 (mail-header-lines header))
2392
2393 (defun gnus-header-date (header)
2394 (mail-header-date header))
2395
2396 (defun gnus-header-id (header)
2397 (mail-header-id header))
2398
2399 (defun gnus-header-message-id (header)
2400 (mail-header-id header))
2401
2402 (defun gnus-header-chars (header)
2403 (mail-header-chars header))
2404
2405 (defun gnus-header-references (header)
2406 (mail-header-references header))
2407
2408 ;;; General various misc type functions.
2409
2410 (defun gnus-clear-system ()
2411 "Clear all variables and buffers."
2412 ;; Clear Gnus variables.
2413 (let ((variables gnus-variable-list))
2414 (while variables
2415 (set (car variables) nil)
2416 (setq variables (cdr variables))))
2417 ;; Clear other internal variables.
2418 (setq gnus-list-of-killed-groups nil
2419 gnus-have-read-active-file nil
2420 gnus-newsrc-alist nil
2421 gnus-newsrc-hashtb nil
2422 gnus-killed-list nil
2423 gnus-zombie-list nil
2424 gnus-killed-hashtb nil
2425 gnus-active-hashtb nil
2426 gnus-moderated-list nil
2427 gnus-description-hashtb nil
2428 gnus-newsgroup-headers nil
2429 gnus-newsgroup-headers-hashtb-by-number nil
2430 gnus-newsgroup-name nil
2431 gnus-server-alist nil
2432 gnus-current-select-method nil)
2433 ;; Reset any score variables.
2434 (and (boundp 'gnus-score-cache)
2435 (set 'gnus-score-cache nil))
2436 (and (boundp 'gnus-internal-global-score-files)
2437 (set 'gnus-internal-global-score-files nil))
2438 ;; Kill the startup file.
2439 (and gnus-current-startup-file
2440 (get-file-buffer gnus-current-startup-file)
2441 (kill-buffer (get-file-buffer gnus-current-startup-file)))
2442 ;; Save any cache buffers.
2443 (and gnus-use-cache (gnus-cache-save-buffers))
2444 ;; Clear the dribble buffer.
2445 (gnus-dribble-clear)
2446 ;; Kill global KILL file buffer.
2447 (if (get-file-buffer (gnus-newsgroup-kill-file nil))
2448 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
2449 (gnus-kill-buffer nntp-server-buffer)
2450 ;; Kill Gnus buffers.
2451 (while gnus-buffer-list
2452 (gnus-kill-buffer (car gnus-buffer-list))
2453 (setq gnus-buffer-list (cdr gnus-buffer-list))))
2454
2455 (defun gnus-windows-old-to-new (setting)
2456 ;; First we take care of the really, really old Gnus 3 actions.
2457 (if (symbolp setting)
2458 (setq setting
2459 (cond ((memq setting '(SelectArticle))
2460 'article)
2461 ((memq setting '(SelectSubject ExpandSubject))
2462 'summary)
2463 ((memq setting '(SelectNewsgroup ExitNewsgroup))
2464 'group)
2465 (t setting))))
2466 (if (or (listp setting)
2467 (not (and gnus-window-configuration
2468 (memq setting '(group summary article)))))
2469 setting
2470 (let* ((setting (if (eq setting 'group)
2471 (if (assq 'newsgroup gnus-window-configuration)
2472 'newsgroup
2473 'newsgroups) setting))
2474 (elem (car (cdr (assq setting gnus-window-configuration))))
2475 (total (apply '+ elem))
2476 (types '(group summary article))
2477 (pbuf (if (eq setting 'newsgroups) 'group 'summary))
2478 (i 0)
2479 perc
2480 out)
2481 (while (< i 3)
2482 (or (not (numberp (nth i elem)))
2483 (zerop (nth i elem))
2484 (progn
2485 (setq perc (/ (* 1.0 (nth 0 elem)) total))
2486 (setq out (cons (if (eq pbuf (nth i types))
2487 (vector (nth i types) perc 'point)
2488 (vector (nth i types) perc))
2489 out))))
2490 (setq i (1+ i)))
2491 (list (nreverse out)))))
2492
2493 (defun gnus-add-configuration (conf)
2494 (setq gnus-buffer-configuration
2495 (cons conf (delq (assq (car conf) gnus-buffer-configuration)
2496 gnus-buffer-configuration))))
2497
2498 (defun gnus-configure-windows (setting &optional force)
2499 (setq setting (gnus-windows-old-to-new setting))
2500 (let ((r (if (symbolp setting)
2501 (cdr (assq setting gnus-buffer-configuration))
2502 setting))
2503 (in-buf (current-buffer))
2504 rule val w height hor ohor heights sub jump-buffer
2505 rel total to-buf all-visible)
2506 (or r (error "No such setting: %s" setting))
2507
2508 (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r)))
2509 ;; All the windows mentioned are already visible, so we just
2510 ;; put point in the assigned buffer, and do not touch the
2511 ;; winconf.
2512 (select-window (get-buffer-window all-visible t))
2513
2514
2515 ;; Either remove all windows or just remove all Gnus windows.
2516 (if gnus-use-full-window
2517 (delete-other-windows)
2518 (gnus-remove-some-windows)
2519 (switch-to-buffer nntp-server-buffer))
2520
2521 (while r
2522 (setq hor (car r)
2523 ohor nil)
2524
2525 ;; We have to do the (possible) horizontal splitting before the
2526 ;; vertical.
2527 (if (and (listp (car hor))
2528 (eq (car (car hor)) 'horizontal))
2529 (progn
2530 (split-window
2531 nil
2532 (if (integerp (nth 1 (car hor)))
2533 (nth 1 (car hor))
2534 (- (frame-width) (floor (* (frame-width) (nth 1 (car hor))))))
2535 t)
2536 (setq hor (cdr hor))))
2537
2538 ;; Go through the rules and eval the elements that are to be
2539 ;; evalled.
2540 (while hor
2541 (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor))))
2542 (progn
2543 ;; Expand short buffer name.
2544 (setq w (aref val 0))
2545 (and (setq w (cdr (assq w gnus-window-to-buffer)))
2546 (progn
2547 (setq val (apply 'vector (mapcar 'identity val)))
2548 (aset val 0 w)))
2549 (setq ohor (cons val ohor))))
2550 (setq hor (cdr hor)))
2551 (setq rule (cons (nreverse ohor) rule))
2552 (setq r (cdr r)))
2553 (setq rule (nreverse rule))
2554
2555 ;; We tally the window sizes.
2556 (setq total (window-height))
2557 (while rule
2558 (setq hor (car rule))
2559 (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal))
2560 (setq hor (cdr hor)))
2561 (setq sub 0)
2562 (while hor
2563 (setq rel (aref (car hor) 1)
2564 heights (cons
2565 (cond ((and (floatp rel) (= 1.0 rel))
2566 'x)
2567 ((integerp rel)
2568 rel)
2569 (t
2570 (max (floor (* total rel)) 4)))
2571 heights)
2572 sub (+ sub (if (numberp (car heights)) (car heights) 0))
2573 hor (cdr hor)))
2574 (setq heights (nreverse heights)
2575 hor (car rule))
2576
2577 ;; We then go through these heights and create windows for them.
2578 (while heights
2579 (setq height (car heights)
2580 heights (cdr heights))
2581 (and (eq height 'x)
2582 (setq height (- total sub)))
2583 (and heights
2584 (split-window nil height))
2585 (setq to-buf (aref (car hor) 0))
2586 (switch-to-buffer
2587 (cond ((not to-buf)
2588 in-buf)
2589 ((symbolp to-buf)
2590 (symbol-value (aref (car hor) 0)))
2591 (t
2592 (aref (car hor) 0))))
2593 (and (> (length (car hor)) 2)
2594 (eq (aref (car hor) 2) 'point)
2595 (setq jump-buffer (current-buffer)))
2596 (other-window 1)
2597 (setq hor (cdr hor)))
2598
2599 (setq rule (cdr rule)))
2600
2601 ;; Finally, we pop to the buffer that's supposed to have point.
2602 (or jump-buffer (error "Missing `point' in spec for %s" setting))
2603
2604 (select-window (get-buffer-window jump-buffer t))
2605 (set-buffer jump-buffer))))
2606
2607 (defun gnus-all-windows-visible-p (rule)
2608 (let (invisible hor jump-buffer val buffer)
2609 ;; Go through the rules and eval the elements that are to be
2610 ;; evalled.
2611 (while (and rule (not invisible))
2612 (setq hor (car rule)
2613 rule (cdr rule))
2614 (while (and hor (not invisible))
2615 (if (setq val (if (vectorp (car hor))
2616 (car hor)
2617 (if (not (eq (car (car hor)) 'horizontal))
2618 (eval (car hor)))))
2619 (progn
2620 ;; Expand short buffer name.
2621 (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer))
2622 (aref val 0)))
2623 (setq buffer (if (symbolp buffer) (symbol-value buffer)
2624 buffer))
2625 (and (> (length val) 2) (eq 'point (aref val 2))
2626 (setq jump-buffer buffer))
2627 (setq invisible (not (and buffer (get-buffer-window buffer))))))
2628 (setq hor (cdr hor))))
2629 (and (not invisible) jump-buffer)))
2630
2631 (defun gnus-window-top-edge (&optional window)
2632 (nth 1 (window-edges window)))
2633
2634 (defun gnus-remove-some-windows ()
2635 (let ((buffers gnus-window-to-buffer)
2636 buf bufs lowest-buf lowest)
2637 (save-excursion
2638 ;; Remove windows on all known Gnus buffers.
2639 (while buffers
2640 (setq buf (cdr (car buffers)))
2641 (if (symbolp buf)
2642 (setq buf (and (boundp buf) (symbol-value buf))))
2643 (and buf
2644 (get-buffer-window buf)
2645 (progn
2646 (setq bufs (cons buf bufs))
2647 (pop-to-buffer buf)
2648 (if (or (not lowest)
2649 (< (gnus-window-top-edge) lowest))
2650 (progn
2651 (setq lowest (gnus-window-top-edge))
2652 (setq lowest-buf buf)))))
2653 (setq buffers (cdr buffers)))
2654 ;; Remove windows on *all* summary buffers.
2655 (let (wins)
2656 (walk-windows
2657 (lambda (win)
2658 (let ((buf (window-buffer win)))
2659 (if (string-match "^\\*Summary" (buffer-name buf))
2660 (progn
2661 (setq bufs (cons buf bufs))
2662 (pop-to-buffer buf)
2663 (if (or (not lowest)
2664 (< (gnus-window-top-edge) lowest))
2665 (progn
2666 (setq lowest-buf buf)
2667 (setq lowest (gnus-window-top-edge))))))))))
2668 (and lowest-buf
2669 (progn
2670 (pop-to-buffer lowest-buf)
2671 (switch-to-buffer nntp-server-buffer)))
2672 (while bufs
2673 (and (not (eq (car bufs) lowest-buf))
2674 (delete-windows-on (car bufs)))
2675 (setq bufs (cdr bufs))))))
2676
2677 (defun gnus-version ()
2678 "Version numbers of this version of Gnus."
2679 (interactive)
2680 (let ((methods gnus-valid-select-methods)
2681 (mess gnus-version)
2682 meth)
2683 ;; Go through all the legal select methods and add their version
2684 ;; numbers to the total version string. Only the backends that are
2685 ;; currently in use will have their message numbers taken into
2686 ;; consideration.
2687 (while methods
2688 (setq meth (intern (concat (car (car methods)) "-version")))
2689 (and (boundp meth)
2690 (stringp (symbol-value meth))
2691 (setq mess (concat mess "; " (symbol-value meth))))
2692 (setq methods (cdr methods)))
2693 (gnus-message 2 mess)))
2694
2695 (defun gnus-info-find-node ()
2696 "Find Info documentation of Gnus."
2697 (interactive)
2698 ;; Enlarge info window if needed.
2699 (let ((mode major-mode))
2700 (gnus-configure-windows 'info)
2701 (Info-goto-node (car (cdr (assq mode gnus-info-nodes))))))
2702
2703 (defun gnus-overload-functions (&optional overloads)
2704 "Overload functions specified by optional argument OVERLOADS.
2705 If nothing is specified, use the variable gnus-overload-functions."
2706 (let ((defs nil)
2707 (overloads (or overloads gnus-overload-functions)))
2708 (while overloads
2709 (setq defs (car overloads))
2710 (setq overloads (cdr overloads))
2711 ;; Load file before overloading function if necessary. Make
2712 ;; sure we cannot use `require' always.
2713 (and (not (fboundp (car defs)))
2714 (car (cdr (cdr defs)))
2715 (load (car (cdr (cdr defs))) nil 'nomessage))
2716 (fset (car defs) (car (cdr defs))))))
2717
2718 (defun gnus-replace-chars-in-string (string &rest pairs)
2719 "Replace characters in STRING from FROM to TO."
2720 (let ((string (substring string 0)) ;Copy string.
2721 (len (length string))
2722 (idx 0)
2723 sym to)
2724 (or (zerop (% (length pairs) 2))
2725 (error "Odd number of translation pairs"))
2726 (setplist 'sym pairs)
2727 ;; Replace all occurrences of FROM with TO.
2728 (while (< idx len)
2729 (if (setq to (get 'sym (aref string idx)))
2730 (aset string idx to))
2731 (setq idx (1+ idx)))
2732 string))
2733
2734 (defun gnus-days-between (date1 date2)
2735 ;; Return the number of days between date1 and date2.
2736 (- (gnus-day-number date1) (gnus-day-number date2)))
2737
2738 (defun gnus-day-number (date)
2739 (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
2740 (timezone-parse-date date))))
2741 (timezone-absolute-from-gregorian
2742 (nth 1 dat) (nth 2 dat) (car dat))))
2743
2744 ;; Returns a floating point number that says how many seconds have
2745 ;; lapsed between Jan 1 12:00:00 1970 and DATE.
2746 (defun gnus-seconds-since-epoch (date)
2747 (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2748 (timezone-parse-date date)))
2749 (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
2750 (timezone-parse-time
2751 (aref (timezone-parse-date date) 3))))
2752 (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2753 (timezone-parse-date "Jan 1 12:00:00 1970")))
2754 (tday (- (timezone-absolute-from-gregorian
2755 (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
2756 (timezone-absolute-from-gregorian
2757 (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
2758 (+ (nth 2 ttime)
2759 (* (nth 1 ttime) 60)
2760 (* 1.0 (nth 0 ttime) 60 60)
2761 (* 1.0 tday 60 60 24))))
2762
2763 (defun gnus-file-newer-than (file date)
2764 (let ((fdate (nth 5 (file-attributes file))))
2765 (or (> (car fdate) (car date))
2766 (and (= (car fdate) (car date))
2767 (> (nth 1 fdate) (nth 1 date))))))
2768
2769 (defun gnus-group-read-only-p (&optional group)
2770 "Check whether GROUP supports editing or not.
2771 If GROUP is nil, `gnus-newsgroup-name' will be checked instead. Note
2772 that that variable is buffer-local to the summary buffers."
2773 (let ((group (or group gnus-newsgroup-name)))
2774 (not (gnus-check-backend-function 'request-replace-article group))))
2775
2776 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
2777 ;; the echo area.
2778 (defun gnus-y-or-n-p (prompt)
2779 (prog1
2780 (y-or-n-p prompt)
2781 (message "")))
2782
2783 (defun gnus-yes-or-no-p (prompt)
2784 (prog1
2785 (yes-or-no-p prompt)
2786 (message "")))
2787
2788 ;; Check whether to use long file names.
2789 (defun gnus-use-long-file-name (symbol)
2790 ;; The variable has to be set...
2791 (and gnus-use-long-file-name
2792 ;; If it isn't a list, then we return t.
2793 (or (not (listp gnus-use-long-file-name))
2794 ;; If it is a list, and the list contains `symbol', we
2795 ;; return nil.
2796 (not (memq symbol gnus-use-long-file-name)))))
2797
2798 ;; I suspect there's a better way, but I haven't taken the time to do
2799 ;; it yet. -erik selberg@cs.washington.edu
2800 (defun gnus-dd-mmm (messy-date)
2801 "Return a string like DD-MMM from a big messy string"
2802 (let ((datevec (timezone-parse-date messy-date)))
2803 (format "%2s-%s"
2804 (or (aref datevec 2) "??")
2805 (capitalize
2806 (or (car
2807 (nth (1- (string-to-number (aref datevec 1)))
2808 timezone-months-assoc))
2809 "???")))))
2810
2811 ;; Make a hash table (default and minimum size is 255).
2812 ;; Optional argument HASHSIZE specifies the table size.
2813 (defun gnus-make-hashtable (&optional hashsize)
2814 (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
2815
2816 ;; Make a number that is suitable for hashing; bigger than MIN and one
2817 ;; less than 2^x.
2818 (defun gnus-create-hash-size (min)
2819 (let ((i 1))
2820 (while (< i min)
2821 (setq i (* 2 i)))
2822 (1- i)))
2823
2824 ;; Show message if message has a lower level than `gnus-verbose'.
2825 ;; Guide-line for numbers:
2826 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
2827 ;; for things that take a long time, 7 - not very important messages
2828 ;; on stuff, 9 - messages inside loops.
2829 (defun gnus-message (level &rest args)
2830 (if (<= level gnus-verbose)
2831 (apply 'message args)
2832 ;; We have to do this format thingy here even if the result isn't
2833 ;; shown - the return value has to be the same as the return value
2834 ;; from `message'.
2835 (apply 'format args)))
2836
2837 ;; Generate a unique new group name.
2838 (defun gnus-generate-new-group-name (leaf)
2839 (let ((name leaf)
2840 (num 0))
2841 (while (gnus-gethash name gnus-newsrc-hashtb)
2842 (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
2843 name))
2844
2845 (defun gnus-ephemeral-group-p (group)
2846 "Say whether GROUP is ephemeral or not."
2847 (assoc 'quit-config (gnus-find-method-for-group group)))
2848
2849 (defun gnus-group-quit-config (group)
2850 "Return the quit-config of GROUP."
2851 (nth 1 (assoc 'quit-config (gnus-find-method-for-group group))))
2852
2853 (defun gnus-simplify-mode-line ()
2854 "Make mode lines a bit simpler."
2855 (setq mode-line-modified "-- ")
2856 (if (listp mode-line-format)
2857 (progn
2858 (make-local-variable 'mode-line-format)
2859 (setq mode-line-format (copy-sequence mode-line-format))
2860 (and (equal (nth 3 mode-line-format) " ")
2861 (setcar (nthcdr 3 mode-line-format) "")))))
2862
2863 ;;; List and range functions
2864
2865 (defun gnus-last-element (list)
2866 "Return last element of LIST."
2867 (while (cdr list)
2868 (setq list (cdr list)))
2869 (car list))
2870
2871 (defun gnus-copy-sequence (list)
2872 "Do a complete, total copy of a list."
2873 (if (and (consp list) (not (consp (cdr list))))
2874 (cons (car list) (cdr list))
2875 (mapcar (lambda (elem) (if (consp elem)
2876 (if (consp (cdr elem))
2877 (gnus-copy-sequence elem)
2878 (cons (car elem) (cdr elem)))
2879 elem))
2880 list)))
2881
2882 (defun gnus-set-difference (list1 list2)
2883 "Return a list of elements of LIST1 that do not appear in LIST2."
2884 (let ((list1 (copy-sequence list1)))
2885 (while list2
2886 (setq list1 (delq (car list2) list1))
2887 (setq list2 (cdr list2)))
2888 list1))
2889
2890 (defun gnus-sorted-complement (list1 list2)
2891 "Return a list of elements of LIST1 that do not appear in LIST2.
2892 Both lists have to be sorted over <."
2893 (let (out)
2894 (if (or (null list1) (null list2))
2895 (or list1 list2)
2896 (while (and list1 list2)
2897 (cond ((= (car list1) (car list2))
2898 (setq list1 (cdr list1)
2899 list2 (cdr list2)))
2900 ((< (car list1) (car list2))
2901 (setq out (cons (car list1) out))
2902 (setq list1 (cdr list1)))
2903 (t
2904 (setq out (cons (car list2) out))
2905 (setq list2 (cdr list2)))))
2906 (nconc (nreverse out) (or list1 list2)))))
2907
2908 (defun gnus-intersection (list1 list2)
2909 (let ((result nil))
2910 (while list2
2911 (if (memq (car list2) list1)
2912 (setq result (cons (car list2) result)))
2913 (setq list2 (cdr list2)))
2914 result))
2915
2916 (defun gnus-sorted-intersection (list1 list2)
2917 ;; LIST1 and LIST2 have to be sorted over <.
2918 (let (out)
2919 (while (and list1 list2)
2920 (cond ((= (car list1) (car list2))
2921 (setq out (cons (car list1) out)
2922 list1 (cdr list1)
2923 list2 (cdr list2)))
2924 ((< (car list1) (car list2))
2925 (setq list1 (cdr list1)))
2926 (t
2927 (setq list2 (cdr list2)))))
2928 (nreverse out)))
2929
2930 (defun gnus-set-sorted-intersection (list1 list2)
2931 ;; LIST1 and LIST2 have to be sorted over <.
2932 ;; This function modifies LIST1.
2933 (let* ((top (cons nil list1))
2934 (prev top))
2935 (while (and list1 list2)
2936 (cond ((= (car list1) (car list2))
2937 (setq prev list1
2938 list1 (cdr list1)
2939 list2 (cdr list2)))
2940 ((< (car list1) (car list2))
2941 (setcdr prev (cdr list1))
2942 (setq list1 (cdr list1)))
2943 (t
2944 (setq list2 (cdr list2)))))
2945 (setcdr prev nil)
2946 (cdr top)))
2947
2948 (defun gnus-compress-sequence (numbers &optional always-list)
2949 "Convert list of numbers to a list of ranges or a single range.
2950 If ALWAYS-LIST is non-nil, this function will always release a list of
2951 ranges."
2952 (let* ((first (car numbers))
2953 (last (car numbers))
2954 result)
2955 (if (null numbers)
2956 nil
2957 (if (not (listp (cdr numbers)))
2958 numbers
2959 (while numbers
2960 (cond ((= last (car numbers)) nil) ;Omit duplicated number
2961 ((= (1+ last) (car numbers)) ;Still in sequence
2962 (setq last (car numbers)))
2963 (t ;End of one sequence
2964 (setq result
2965 (cons (if (= first last) first
2966 (cons first last)) result))
2967 (setq first (car numbers))
2968 (setq last (car numbers))))
2969 (setq numbers (cdr numbers)))
2970 (if (and (not always-list) (null result))
2971 (if (= first last) (list first) (cons first last))
2972 (nreverse (cons (if (= first last) first (cons first last))
2973 result)))))))
2974
2975 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
2976 (defun gnus-uncompress-range (ranges)
2977 "Expand a list of ranges into a list of numbers.
2978 RANGES is either a single range on the form `(num . num)' or a list of
2979 these ranges."
2980 (let (first last result)
2981 (cond
2982 ((null ranges)
2983 nil)
2984 ((not (listp (cdr ranges)))
2985 (setq first (car ranges))
2986 (setq last (cdr ranges))
2987 (while (<= first last)
2988 (setq result (cons first result))
2989 (setq first (1+ first)))
2990 (nreverse result))
2991 (t
2992 (while ranges
2993 (if (atom (car ranges))
2994 (if (numberp (car ranges))
2995 (setq result (cons (car ranges) result)))
2996 (setq first (car (car ranges)))
2997 (setq last (cdr (car ranges)))
2998 (while (<= first last)
2999 (setq result (cons first result))
3000 (setq first (1+ first))))
3001 (setq ranges (cdr ranges)))
3002 (nreverse result)))))
3003
3004 (defun gnus-add-to-range (ranges list)
3005 "Return a list of ranges that has all articles from both RANGES and LIST.
3006 Note: LIST has to be sorted over `<'."
3007 (if (not ranges)
3008 (gnus-compress-sequence list t)
3009 (setq list (copy-sequence list))
3010 (or (listp (cdr ranges))
3011 (setq ranges (list ranges)))
3012 (let ((out ranges)
3013 ilist lowest highest temp)
3014 (while (and ranges list)
3015 (setq ilist list)
3016 (setq lowest (or (and (atom (car ranges)) (car ranges))
3017 (car (car ranges))))
3018 (while (and list (cdr list) (< (car (cdr list)) lowest))
3019 (setq list (cdr list)))
3020 (if (< (car ilist) lowest)
3021 (progn
3022 (setq temp list)
3023 (setq list (cdr list))
3024 (setcdr temp nil)
3025 (setq out (nconc (gnus-compress-sequence ilist t) out))))
3026 (setq highest (or (and (atom (car ranges)) (car ranges))
3027 (cdr (car ranges))))
3028 (while (and list (<= (car list) highest))
3029 (setq list (cdr list)))
3030 (setq ranges (cdr ranges)))
3031 (if list
3032 (setq out (nconc (gnus-compress-sequence list t) out)))
3033 (setq out (sort out (lambda (r1 r2)
3034 (< (or (and (atom r1) r1) (car r1))
3035 (or (and (atom r2) r2) (car r2))))))
3036 (setq ranges out)
3037 (while ranges
3038 (if (atom (car ranges))
3039 (if (cdr ranges)
3040 (if (atom (car (cdr ranges)))
3041 (if (= (1+ (car ranges)) (car (cdr ranges)))
3042 (progn
3043 (setcar ranges (cons (car ranges)
3044 (car (cdr ranges))))
3045 (setcdr ranges (cdr (cdr ranges)))))
3046 (if (= (1+ (car ranges)) (car (car (cdr ranges))))
3047 (progn
3048 (setcar (car (cdr ranges)) (car ranges))
3049 (setcar ranges (car (cdr ranges)))
3050 (setcdr ranges (cdr (cdr ranges)))))))
3051 (if (cdr ranges)
3052 (if (atom (car (cdr ranges)))
3053 (if (= (1+ (cdr (car ranges))) (car (cdr ranges)))
3054 (progn
3055 (setcdr (car ranges) (car (cdr ranges)))
3056 (setcdr ranges (cdr (cdr ranges)))))
3057 (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges))))
3058 (progn
3059 (setcdr (car ranges) (cdr (car (cdr ranges))))
3060 (setcdr ranges (cdr (cdr ranges))))))))
3061 (setq ranges (cdr ranges)))
3062 out)))
3063
3064 (defun gnus-remove-from-range (ranges list)
3065 "Return a list of ranges that has all articles from LIST removed from RANGES.
3066 Note: LIST has to be sorted over `<'."
3067 ;; !!! This function shouldn't look like this, but I've got a headache.
3068 (gnus-compress-sequence
3069 (gnus-sorted-complement
3070 (gnus-uncompress-range ranges) list)))
3071
3072 (defun gnus-member-of-range (number ranges)
3073 (if (not (listp (cdr ranges)))
3074 (and (>= number (car ranges))
3075 (<= number (cdr ranges)))
3076 (let ((not-stop t))
3077 (while (and ranges
3078 (if (numberp (car ranges))
3079 (>= number (car ranges))
3080 (>= number (car (car ranges))))
3081 not-stop)
3082 (if (if (numberp (car ranges))
3083 (= number (car ranges))
3084 (and (>= number (car (car ranges)))
3085 (<= number (cdr (car ranges)))))
3086 (setq not-stop nil))
3087 (setq ranges (cdr ranges)))
3088 (not not-stop))))
3089
3090 \f
3091 ;;;
3092 ;;; Gnus group mode
3093 ;;;
3094
3095 (defvar gnus-group-mode-map nil)
3096 (defvar gnus-group-group-map nil)
3097 (defvar gnus-group-mark-map nil)
3098 (defvar gnus-group-list-map nil)
3099 (defvar gnus-group-help-map nil)
3100 (defvar gnus-group-sub-map nil)
3101 (put 'gnus-group-mode 'mode-class 'special)
3102
3103 (if gnus-group-mode-map
3104 nil
3105 (setq gnus-group-mode-map (make-keymap))
3106 (suppress-keymap gnus-group-mode-map)
3107 (define-key gnus-group-mode-map " " 'gnus-group-read-group)
3108 (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
3109 (define-key gnus-group-mode-map "\r" 'gnus-group-select-group)
3110 (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
3111 (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
3112 (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
3113 (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
3114 (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
3115 (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
3116 (define-key gnus-group-mode-map
3117 "\M-n" 'gnus-group-next-unread-group-same-level)
3118 (define-key gnus-group-mode-map
3119 "\M-p" 'gnus-group-prev-unread-group-same-level)
3120 (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group)
3121 (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group)
3122 (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
3123 (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
3124 (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current)
3125 (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all)
3126 (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
3127 (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
3128 (define-key gnus-group-mode-map "m" 'gnus-group-mail)
3129 (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
3130 (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group)
3131 (define-key gnus-group-mode-map "R" 'gnus-group-restart)
3132 (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file)
3133 (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server)
3134 (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
3135 (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups)
3136 (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group)
3137 (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups)
3138 (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos)
3139 (define-key gnus-group-mode-map "\C-c\M-\C-a" 'gnus-group-description-apropos)
3140 (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
3141 (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
3142 (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
3143 (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
3144 (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
3145 (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
3146 (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
3147 (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed)
3148 (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles)
3149 (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups)
3150 (define-key gnus-group-mode-map "V" 'gnus-version)
3151 (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc)
3152 (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
3153 (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble)
3154 (define-key gnus-group-mode-map "q" 'gnus-group-exit)
3155 (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
3156 (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
3157 (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)
3158 (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method)
3159 (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode)
3160 (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group)
3161 (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
3162 (define-key gnus-group-mode-map ">" 'end-of-buffer)
3163 (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug)
3164 (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups)
3165
3166 (define-key gnus-group-mode-map "#" 'gnus-group-mark-group)
3167 (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group)
3168 (define-prefix-command 'gnus-group-mark-map)
3169 (define-key gnus-group-mode-map "M" 'gnus-group-mark-map)
3170 (define-key gnus-group-mark-map "m" 'gnus-group-mark-group)
3171 (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group)
3172 (define-key gnus-group-mark-map "w" 'gnus-group-mark-region)
3173
3174 (define-prefix-command 'gnus-group-group-map)
3175 (define-key gnus-group-mode-map "G" 'gnus-group-group-map)
3176 (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group)
3177 (define-key gnus-group-group-map "h" 'gnus-group-make-help-group)
3178 (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group)
3179 (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group)
3180 (define-key gnus-group-group-map "m" 'gnus-group-make-group)
3181 (define-key gnus-group-group-map "E" 'gnus-group-edit-group)
3182 (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method)
3183 (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters)
3184 (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual)
3185 (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual)
3186 (define-key gnus-group-group-map "D" 'gnus-group-enter-directory)
3187 (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group)
3188 ;;(define-key gnus-group-group-map "sb" 'gnus-group-brew-soup)
3189 ;;(define-key gnus-group-group-map "sw" 'gnus-soup-save-areas)
3190 ;;(define-key gnus-group-group-map "ss" 'gnus-soup-send-replies)
3191 ;;(define-key gnus-group-group-map "sp" 'gnus-soup-pack-packet)
3192 ;;(define-key gnus-group-group-map "sr" 'nnsoup-pack-replies)
3193
3194 (define-prefix-command 'gnus-group-list-map)
3195 (define-key gnus-group-mode-map "A" 'gnus-group-list-map)
3196 (define-key gnus-group-list-map "k" 'gnus-group-list-killed)
3197 (define-key gnus-group-list-map "z" 'gnus-group-list-zombies)
3198 (define-key gnus-group-list-map "s" 'gnus-group-list-groups)
3199 (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups)
3200 (define-key gnus-group-list-map "a" 'gnus-group-apropos)
3201 (define-key gnus-group-list-map "d" 'gnus-group-description-apropos)
3202 (define-key gnus-group-list-map "m" 'gnus-group-list-matching)
3203 (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching)
3204
3205 (define-prefix-command 'gnus-group-help-map)
3206 (define-key gnus-group-mode-map "H" 'gnus-group-help-map)
3207 (define-key gnus-group-help-map "f" 'gnus-group-fetch-faq)
3208
3209 (define-prefix-command 'gnus-group-sub-map)
3210 (define-key gnus-group-mode-map "S" 'gnus-group-sub-map)
3211 (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level)
3212 (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group)
3213 (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group)
3214 (define-key gnus-group-sub-map "k" 'gnus-group-kill-group)
3215 (define-key gnus-group-sub-map "y" 'gnus-group-yank-group)
3216 (define-key gnus-group-sub-map "w" 'gnus-group-kill-region)
3217 (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies))
3218
3219 (defun gnus-group-mode ()
3220 "Major mode for reading news.
3221
3222 All normal editing commands are switched off.
3223 \\<gnus-group-mode-map>
3224 The group buffer lists (some of) the groups available. For instance,
3225 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
3226 lists all zombie groups.
3227
3228 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
3229 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
3230
3231 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
3232
3233 The following commands are available:
3234
3235 \\{gnus-group-mode-map}"
3236 (interactive)
3237 (if gnus-visual (gnus-group-make-menu-bar))
3238 (kill-all-local-variables)
3239 (gnus-simplify-mode-line)
3240 (setq major-mode 'gnus-group-mode)
3241 (setq mode-name "Group")
3242 (gnus-group-set-mode-line)
3243 (setq mode-line-process nil)
3244 (use-local-map gnus-group-mode-map)
3245 (buffer-disable-undo (current-buffer))
3246 (setq truncate-lines t)
3247 (setq buffer-read-only t)
3248 (run-hooks 'gnus-group-mode-hook))
3249
3250 (defun gnus-mouse-pick-group (e)
3251 (interactive "e")
3252 (mouse-set-point e)
3253 (gnus-group-read-group nil))
3254
3255 ;; Look at LEVEL and find out what the level is really supposed to be.
3256 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
3257 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
3258 (defun gnus-group-default-level (&optional level number-or-nil)
3259 (cond
3260 (gnus-group-use-permanent-levels
3261 (setq gnus-group-default-list-level
3262 (or level gnus-group-default-list-level))
3263 (or gnus-group-default-list-level gnus-level-subscribed))
3264 (number-or-nil
3265 level)
3266 (t
3267 (or level gnus-group-default-list-level gnus-level-subscribed))))
3268
3269
3270 (defvar gnus-tmp-prev-perm nil)
3271
3272 ;;;###autoload
3273 (defun gnus-no-server (&optional arg)
3274 "Read network news.
3275 If ARG is a positive number, Gnus will use that as the
3276 startup level. If ARG is nil, Gnus will be started at level 2.
3277 If ARG is non-nil and not a positive number, Gnus will
3278 prompt the user for the name of an NNTP server to use.
3279 As opposed to `gnus', this command will not connect to the local server."
3280 (interactive "P")
3281 (let ((perm
3282 (cons gnus-group-use-permanent-levels gnus-group-default-list-level)))
3283 (setq gnus-tmp-prev-perm nil)
3284 (setq gnus-group-use-permanent-levels t)
3285 (gnus (or arg (1- gnus-level-default-subscribed)) t)
3286 (setq gnus-tmp-prev-perm perm)))
3287
3288 ;;;###autoload
3289 (defun read-news (&optional arg dont-connect)
3290 "Read network news. This is an alias for the `gnus' command."
3291 (gnus arg dont-connect))
3292
3293 ;;;###autoload
3294 (defun gnus (&optional arg dont-connect)
3295 "Read network news.
3296 If ARG is non-nil and a positive number, Gnus will use that as the
3297 startup level. If ARG is non-nil and not a positive number, Gnus will
3298 prompt the user for the name of an NNTP server to use."
3299 (interactive "P")
3300 (if (get-buffer gnus-group-buffer)
3301 (progn
3302 (switch-to-buffer gnus-group-buffer)
3303 (gnus-group-get-new-news))
3304
3305 (gnus-clear-system)
3306
3307 (nnheader-init-server-buffer)
3308 ;; We do this if `gnus-no-server' has been run.
3309 (if gnus-tmp-prev-perm
3310 (setq gnus-group-use-permanent-levels (car gnus-tmp-prev-perm)
3311 gnus-group-default-list-level (cdr gnus-tmp-prev-perm)
3312 gnus-tmp-prev-perm nil))
3313 (gnus-read-init-file)
3314
3315 (gnus-group-setup-buffer)
3316 (let ((buffer-read-only nil))
3317 (erase-buffer)
3318 (if (not gnus-inhibit-startup-message)
3319 (progn
3320 (gnus-group-startup-message)
3321 (sit-for 0))))
3322
3323 (let ((level (and arg (numberp arg) (> arg 0) arg))
3324 did-connect)
3325 (unwind-protect
3326 (progn
3327 (or dont-connect
3328 (setq did-connect
3329 (gnus-start-news-server (and arg (not level))))))
3330 (if (and (not dont-connect)
3331 (not did-connect))
3332 (gnus-group-quit)
3333 (run-hooks 'gnus-startup-hook)
3334 ;; NNTP server is successfully open.
3335
3336 ;; Find the current startup file name.
3337 (setq gnus-current-startup-file
3338 (gnus-make-newsrc-file gnus-startup-file))
3339
3340 ;; Read the dribble file.
3341 (and gnus-use-dribble-file (gnus-dribble-read-file))
3342
3343 (gnus-summary-make-display-table)
3344 (gnus-setup-news nil level)
3345 (gnus-group-list-groups level)
3346 (gnus-configure-windows 'group))))))
3347
3348 (defun gnus-unload ()
3349 "Unload all Gnus features."
3350 (interactive)
3351 (or (boundp 'load-history)
3352 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
3353 (let ((history load-history)
3354 feature)
3355 (while history
3356 (and (string-match "^gnus" (car (car history)))
3357 (setq feature (cdr (assq 'provide (car history))))
3358 (unload-feature feature 'force))
3359 (setq history (cdr history)))))
3360
3361 (defun gnus-group-startup-message (&optional x y)
3362 "Insert startup message in current buffer."
3363 ;; Insert the message.
3364 (erase-buffer)
3365 (insert
3366 (format "
3367 _ ___ _ _
3368 _ ___ __ ___ __ _ ___
3369 __ _ ___ __ ___
3370 _ ___ _
3371 _ _ __ _
3372 ___ __ _
3373 __ _
3374 _ _ _
3375 _ _ _
3376 _ _ _
3377 __ ___
3378 _ _ _ _
3379 _ _
3380 _ _
3381 _ _
3382 _
3383 __
3384
3385
3386 Gnus * A newsreader for Emacsen
3387 A Praxis release * larsi@ifi.uio.no
3388 "
3389 gnus-version))
3390 ;; And then hack it.
3391 ;; 18 is the longest line.
3392 (indent-rigidly (point-min) (point-max)
3393 (/ (max (- (window-width) (or x 46)) 0) 2))
3394 (goto-char (point-min))
3395 (let* ((pheight (count-lines (point-min) (point-max)))
3396 (wheight (window-height))
3397 (rest (- wheight pheight)))
3398 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
3399
3400
3401
3402 ;; Fontify some.
3403 (goto-char (point-min))
3404 (search-forward "Praxis")
3405 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3406 (goto-char (point-min)))
3407
3408 (defun gnus-group-startup-message-old (&optional x y)
3409 "Insert startup message in current buffer."
3410 ;; Insert the message.
3411 (erase-buffer)
3412 (insert
3413 (format "
3414 %s
3415 A newsreader
3416 for GNU Emacs
3417
3418 Based on GNUS
3419 written by
3420 Masanobu UMEDA
3421
3422 A Praxis Release
3423 larsi@ifi.uio.no
3424 "
3425 gnus-version))
3426 ;; And then hack it.
3427 ;; 18 is the longest line.
3428 (indent-rigidly (point-min) (point-max)
3429 (/ (max (- (window-width) (or x 28)) 0) 2))
3430 (goto-char (point-min))
3431 ;; +4 is fuzzy factor.
3432 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))
3433
3434 ;; Fontify some.
3435 (goto-char (point-min))
3436 (search-forward "Praxis")
3437 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3438 (goto-char (point-min)))
3439
3440 (defun gnus-group-setup-buffer ()
3441 (or (get-buffer gnus-group-buffer)
3442 (progn
3443 (switch-to-buffer gnus-group-buffer)
3444 (gnus-add-current-to-buffer-list)
3445 (gnus-group-mode)
3446 (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
3447
3448 (defun gnus-group-list-groups (&optional level unread)
3449 "List newsgroups with level LEVEL or lower that have unread articles.
3450 Default is all subscribed groups.
3451 If argument UNREAD is non-nil, groups with no unread articles are also
3452 listed."
3453 (interactive (list (if current-prefix-arg
3454 (prefix-numeric-value current-prefix-arg)
3455 (or
3456 (gnus-group-default-level nil t)
3457 gnus-group-default-list-level
3458 gnus-level-subscribed))))
3459 (or level
3460 (setq level (car gnus-group-list-mode)
3461 unread (cdr gnus-group-list-mode)))
3462 (setq level (gnus-group-default-level level))
3463 (gnus-group-setup-buffer) ;May call from out of group buffer
3464 (let ((case-fold-search nil)
3465 (group (gnus-group-group-name)))
3466 (funcall gnus-group-prepare-function level unread nil)
3467 (if (zerop (buffer-size))
3468 (gnus-message 5 gnus-no-groups-message)
3469 (goto-char (point-min))
3470 (if (not group)
3471 ;; Go to the first group with unread articles.
3472 (gnus-group-search-forward nil nil nil t)
3473 ;; Find the right group to put point on. If the current group
3474 ;; has disappeared in the new listing, try to find the next
3475 ;; one. If no next one can be found, just leave point at the
3476 ;; first newsgroup in the buffer.
3477 (if (not (gnus-goto-char
3478 (text-property-any (point-min) (point-max)
3479 'gnus-group (intern group))))
3480 (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb))))
3481 (while (and newsrc
3482 (not (gnus-goto-char
3483 (text-property-any
3484 (point-min) (point-max) 'gnus-group
3485 (intern (car (car newsrc)))))))
3486 (setq newsrc (cdr newsrc)))
3487 (or newsrc (progn (goto-char (point-max))
3488 (forward-line -1))))))
3489 ;; Adjust cursor point.
3490 (gnus-group-position-cursor))))
3491
3492 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
3493 "List all newsgroups with unread articles of level LEVEL or lower.
3494 If ALL is non-nil, list groups that have no unread articles.
3495 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3496 If REGEXP, only list groups matching REGEXP."
3497 (set-buffer gnus-group-buffer)
3498 (let ((buffer-read-only nil)
3499 (newsrc (cdr gnus-newsrc-alist))
3500 (lowest (or lowest 1))
3501 info clevel unread group)
3502 (erase-buffer)
3503 (if (< lowest gnus-level-zombie)
3504 ;; List living groups.
3505 (while newsrc
3506 (setq info (car newsrc)
3507 group (car info)
3508 newsrc (cdr newsrc)
3509 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3510 (and unread ; This group might be bogus
3511 (or (not regexp)
3512 (string-match regexp group))
3513 (<= (setq clevel (car (cdr info))) level)
3514 (>= clevel lowest)
3515 (or all ; We list all groups?
3516 (eq unread t) ; We list unactivated groups
3517 (> unread 0) ; We list groups with unread articles
3518 (cdr (assq 'tick (nth 3 info)))) ; And ticked groups
3519 (gnus-group-insert-group-line
3520 nil group (car (cdr info)) (nth 3 info) unread (nth 4 info)))))
3521
3522 ;; List dead groups.
3523 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
3524 (gnus-group-prepare-flat-list-dead
3525 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
3526 gnus-level-zombie ?Z
3527 regexp))
3528 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
3529 (gnus-group-prepare-flat-list-dead
3530 (setq gnus-killed-list (sort gnus-killed-list 'string<))
3531 gnus-level-killed ?K regexp))
3532
3533 (gnus-group-set-mode-line)
3534 (setq gnus-group-list-mode (cons level all))
3535 (run-hooks 'gnus-group-prepare-hook)))
3536
3537 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
3538 ;; List zombies and killed lists somewhat faster, which was
3539 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
3540 ;; this by ignoring the group format specification altogether.
3541 (let (group beg)
3542 (while groups
3543 (setq group (car groups)
3544 groups (cdr groups))
3545 (if (or (not regexp)
3546 (string-match regexp group))
3547 (progn
3548 (setq beg (point))
3549 (insert (format " %c *: %s\n" mark group))
3550 (add-text-properties
3551 beg (1+ beg)
3552 (list 'gnus-group (intern group)
3553 'gnus-unread t
3554 'gnus-level level)))))))
3555
3556 (defun gnus-group-real-name (group)
3557 "Find the real name of a foreign newsgroup."
3558 (if (string-match ":[^:]+$" group)
3559 (substring group (1+ (match-beginning 0)))
3560 group))
3561
3562 (defun gnus-group-prefixed-name (group method)
3563 "Return the whole name from GROUP and METHOD."
3564 (and (stringp method) (setq method (gnus-server-to-method method)))
3565 (concat (format "%s" (car method))
3566 (if (and
3567 (assoc (format "%s" (car method)) (gnus-methods-using 'address))
3568 (not (string= (nth 1 method) "")))
3569 (concat "+" (nth 1 method)))
3570 ":" group))
3571
3572 (defun gnus-group-real-prefix (group)
3573 "Return the prefix of the current group name."
3574 (if (string-match "^[^:]+:" group)
3575 (substring group 0 (match-end 0))
3576 ""))
3577
3578 (defun gnus-group-method-name (group)
3579 "Return the method used for selecting GROUP."
3580 (let ((prefix (gnus-group-real-prefix group)))
3581 (if (equal prefix "")
3582 gnus-select-method
3583 (if (string-match "^[^\\+]+\\+" prefix)
3584 (list (intern (substring prefix 0 (1- (match-end 0))))
3585 (substring prefix (match-end 0) (1- (length prefix))))
3586 (list (intern (substring prefix 0 (1- (length prefix)))) "")))))
3587
3588 (defun gnus-group-foreign-p (group)
3589 "Return nil if GROUP is native, non-nil if it is foreign."
3590 (string-match ":" group))
3591
3592 (defun gnus-group-set-info (info &optional method-only-group part)
3593 (let* ((entry (gnus-gethash
3594 (or method-only-group (car info)) gnus-newsrc-hashtb))
3595 (part-info info)
3596 (info (if method-only-group (nth 2 entry) info)))
3597 (if (not method-only-group)
3598 ()
3599 (or entry
3600 (error "Trying to change non-existent group %s" method-only-group))
3601 ;; We have received parts of the actual group info - either the
3602 ;; select method or the group parameters. We first check
3603 ;; whether we have to extend the info, and if so, do that.
3604 (let ((len (length info))
3605 (total (if (eq part 'method) 5 6)))
3606 (and (< len total)
3607 (setcdr (nthcdr (1- len) info)
3608 (make-list (- total len) nil)))
3609 ;; Then we enter the new info.
3610 (setcar (nthcdr (1- total) info) part-info)))
3611 ;; We uncompress some lists of marked articles.
3612 (let (marked)
3613 (if (not (setq marked (nth 3 info)))
3614 ()
3615 (while marked
3616 (or (eq 'score (car (car marked)))
3617 (eq 'bookmark (car (car marked)))
3618 (eq 'killed (car (car marked)))
3619 (setcdr (car marked)
3620 (gnus-uncompress-range (cdr (car marked)))))
3621 (setq marked (cdr marked)))))
3622 (if entry
3623 ()
3624 ;; This is a new group, so we just create it.
3625 (save-excursion
3626 (set-buffer gnus-group-buffer)
3627 (if (nth 4 info)
3628 ;; It's a foreign group...
3629 (gnus-group-make-group
3630 (gnus-group-real-name (car info))
3631 (prin1-to-string (car (nth 4 info)))
3632 (nth 1 (nth 4 info)))
3633 ;; It's a native group.
3634 (gnus-group-make-group (car info)))
3635 (gnus-message 6 "Note: New group created")
3636 (setq entry
3637 (gnus-gethash (gnus-group-prefixed-name
3638 (gnus-group-real-name (car info))
3639 (or (nth 4 info) gnus-select-method))
3640 gnus-newsrc-hashtb))))
3641 ;; Whether it was a new group or not, we now have the entry, so we
3642 ;; can do the update.
3643 (if entry
3644 (progn
3645 (setcar (nthcdr 2 entry) info)
3646 (if (and (not (eq (car entry) t))
3647 (gnus-gethash (car info) gnus-active-hashtb))
3648 (let ((marked (nth 3 info)))
3649 (setcar entry
3650 (max 0 (- (length (gnus-list-of-unread-articles
3651 (car info)))
3652 (length (cdr (assq 'tick marked)))
3653 (length (cdr (assq 'dormant marked)))))))))
3654 (error "No such group: %s" (car info)))))
3655
3656 (defun gnus-group-set-method-info (group select-method)
3657 (gnus-group-set-info select-method group 'method))
3658
3659 (defun gnus-group-set-params-info (group params)
3660 (gnus-group-set-info params group 'params))
3661
3662 (defun gnus-group-update-group-line ()
3663 "This function updates the current line in the newsgroup buffer and
3664 moves the point to the colon."
3665 (let* ((buffer-read-only nil)
3666 (group (gnus-group-group-name))
3667 (entry (and group (gnus-gethash group gnus-newsrc-hashtb))))
3668 (if (and entry (not (gnus-ephemeral-group-p group)))
3669 (gnus-dribble-enter
3670 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3671 ")")))
3672 (beginning-of-line)
3673 (delete-region (point) (progn (forward-line 1) (point)))
3674 (gnus-group-insert-group-line-info group)
3675 (forward-line -1)
3676 (gnus-group-position-cursor)))
3677
3678 (defun gnus-group-insert-group-line-info (group)
3679 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
3680 active info)
3681 (if entry
3682 (progn
3683 (setq info (nth 2 entry))
3684 (gnus-group-insert-group-line
3685 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
3686 (setq active (gnus-gethash group gnus-active-hashtb))
3687 (gnus-group-insert-group-line
3688 nil group
3689 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
3690 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))))
3691
3692 (defun gnus-group-insert-group-line (gformat group level marked number method)
3693 (let* ((gformat (or gformat gnus-group-line-format-spec))
3694 (active (gnus-gethash group gnus-active-hashtb))
3695 (number-total (if active (1+ (- (cdr active) (car active))) 0))
3696 (number-of-dormant (length (cdr (assq 'dormant marked))))
3697 (number-of-ticked (length (cdr (assq 'tick marked))))
3698 (number-of-ticked-and-dormant
3699 (+ number-of-ticked number-of-dormant))
3700 (number-of-unread-unticked
3701 (if (numberp number) (int-to-string (max 0 number))
3702 "*"))
3703 (number-of-read
3704 (if (numberp number)
3705 (max 0 (- number-total number))
3706 "*"))
3707 (subscribed (cond ((<= level gnus-level-subscribed) ? )
3708 ((<= level gnus-level-unsubscribed) ?U)
3709 ((= level gnus-level-zombie) ?Z)
3710 (t ?K)))
3711 (qualified-group (gnus-group-real-name group))
3712 (newsgroup-description
3713 (if gnus-description-hashtb
3714 (or (gnus-gethash group gnus-description-hashtb) "")
3715 ""))
3716 (moderated (if (member group gnus-moderated-list) ?m ? ))
3717 (moderated-string (if (eq moderated ?m) "(m)" ""))
3718 (method (gnus-server-get-method group method))
3719 (news-server (or (car (cdr method)) ""))
3720 (news-method (or (car method) ""))
3721 (news-method-string
3722 (if method (format "(%s:%s)" (car method) (car (cdr method))) ""))
3723 (marked (if (and
3724 (numberp number)
3725 (zerop number)
3726 (> number-of-ticked 0))
3727 ?* ? ))
3728 (number (if (eq number t) "*" (+ number number-of-dormant
3729 number-of-ticked)))
3730 (process-marked (if (member group gnus-group-marked)
3731 gnus-process-mark ? ))
3732 (buffer-read-only nil)
3733 header ; passed as parameter to user-funcs.
3734 b)
3735 (beginning-of-line)
3736 (setq b (point))
3737 ;; Insert the text.
3738 (insert (eval gformat))
3739
3740 (add-text-properties
3741 b (1+ b) (list 'gnus-group (intern group)
3742 'gnus-unread (if (numberp number)
3743 (string-to-int number-of-unread-unticked)
3744 t)
3745 'gnus-marked marked
3746 'gnus-level level))))
3747
3748 (defun gnus-group-update-group (group &optional visible-only)
3749 "Update newsgroup info of GROUP.
3750 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already."
3751 (save-excursion
3752 (set-buffer gnus-group-buffer)
3753 (let ((buffer-read-only nil)
3754 visible)
3755 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
3756 (if (and entry
3757 (not (gnus-ephemeral-group-p group)))
3758 (gnus-dribble-enter
3759 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3760 ")"))))
3761 ;; Buffer may be narrowed.
3762 (save-restriction
3763 (widen)
3764 ;; Search a line to modify. If the buffer is large, the search
3765 ;; takes long time. In most cases, current point is on the line
3766 ;; we are looking for. So, first of all, check current line.
3767 (if (or (progn
3768 (beginning-of-line)
3769 (eq (get-text-property (point) 'gnus-group)
3770 (intern group)))
3771 (progn
3772 (gnus-goto-char
3773 (text-property-any
3774 (point-min) (point-max) 'gnus-group (intern group)))))
3775 ;; GROUP is listed in current buffer. So, delete old line.
3776 (progn
3777 (setq visible t)
3778 (beginning-of-line)
3779 (delete-region (point) (progn (forward-line 1) (point))))
3780 ;; No such line in the buffer, find out where it's supposed to
3781 ;; go, and insert it there (or at the end of the buffer).
3782 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
3783 (or visible-only
3784 (let ((entry
3785 (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb)))))
3786 (while (and entry
3787 (car entry)
3788 (not
3789 (gnus-goto-char
3790 (text-property-any
3791 (point-min) (point-max)
3792 'gnus-group (intern (car (car entry)))))))
3793 (setq entry (cdr entry)))
3794 (or entry (goto-char (point-max)))))))
3795 (if (or visible (not visible-only))
3796 (gnus-group-insert-group-line-info group))
3797 (gnus-group-set-mode-line))))
3798
3799 (defun gnus-group-set-mode-line ()
3800 (if (memq 'group gnus-updated-mode-lines)
3801 (let* ((gformat (or gnus-group-mode-line-format-spec
3802 (setq gnus-group-mode-line-format-spec
3803 (gnus-parse-format
3804 gnus-group-mode-line-format
3805 gnus-group-mode-line-format-alist))))
3806 (news-server (car (cdr gnus-select-method)))
3807 (news-method (car gnus-select-method))
3808 (max-len 60)
3809 header ;Dummy binding for user-defined specs.
3810 (mode-string (eval gformat)))
3811 (setq mode-string (eval gformat))
3812 (if (> (length mode-string) max-len)
3813 (setq mode-string (substring mode-string 0 (- max-len 4))))
3814 (setq mode-line-buffer-identification mode-string)
3815 (set-buffer-modified-p t))))
3816
3817 (defun gnus-group-group-name ()
3818 "Get the name of the newsgroup on the current line."
3819 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
3820 (and group (symbol-name group))))
3821
3822 (defun gnus-group-group-level ()
3823 "Get the level of the newsgroup on the current line."
3824 (get-text-property (gnus-point-at-bol) 'gnus-level))
3825
3826 (defun gnus-group-group-unread ()
3827 "Get the number of unread articles of the newsgroup on the current line."
3828 (get-text-property (gnus-point-at-bol) 'gnus-unread))
3829
3830 (defun gnus-group-search-forward (&optional backward all level first-too)
3831 "Find the next newsgroup with unread articles.
3832 If BACKWARD is non-nil, find the previous newsgroup instead.
3833 If ALL is non-nil, just find any newsgroup.
3834 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
3835 group exists.
3836 If FIRST-TOO, the current line is also eligible as a target."
3837 (let ((way (if backward -1 1))
3838 (low gnus-level-killed)
3839 (beg (point))
3840 pos found lev)
3841 (if (and backward (progn (beginning-of-line)) (bobp))
3842 nil
3843 (or first-too (forward-line way))
3844 (while (and
3845 (not (eobp))
3846 (not (setq
3847 found
3848 (and (or all
3849 (and
3850 (let ((unread
3851 (get-text-property (point) 'gnus-unread)))
3852 (or (eq unread t) (and unread (> unread 0))))
3853 (setq lev (get-text-property (point)
3854 'gnus-level))
3855 (<= lev gnus-level-subscribed)))
3856 (or (not level)
3857 (and (setq lev (get-text-property (point)
3858 'gnus-level))
3859 (or (= lev level)
3860 (and (< lev low)
3861 (< level lev)
3862 (progn
3863 (setq low lev)
3864 (setq pos (point))
3865 nil))))))))
3866 (zerop (forward-line way)))))
3867 (if found
3868 (progn (gnus-group-position-cursor) t)
3869 (goto-char (or pos beg))
3870 (and pos t))))
3871
3872 ;;; Gnus group mode commands
3873
3874 ;; Group marking.
3875
3876 (defun gnus-group-mark-group (n &optional unmark no-advance)
3877 "Mark the current group."
3878 (interactive "p")
3879 (let ((buffer-read-only nil)
3880 group)
3881 (while
3882 (and (> n 0)
3883 (setq group (gnus-group-group-name))
3884 (progn
3885 (beginning-of-line)
3886 (forward-char
3887 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
3888 (delete-char 1)
3889 (if unmark
3890 (progn
3891 (insert " ")
3892 (setq gnus-group-marked (delete group gnus-group-marked)))
3893 (insert "#")
3894 (setq gnus-group-marked
3895 (cons group (delete group gnus-group-marked))))
3896 t)
3897 (or no-advance (zerop (gnus-group-next-group 1))))
3898 (setq n (1- n)))
3899 (gnus-summary-position-cursor)
3900 n))
3901
3902 (defun gnus-group-unmark-group (n)
3903 "Remove the mark from the current group."
3904 (interactive "p")
3905 (gnus-group-mark-group n 'unmark))
3906
3907 (defun gnus-group-mark-region (unmark beg end)
3908 "Mark all groups between point and mark.
3909 If UNMARK, remove the mark instead."
3910 (interactive "P\nr")
3911 (let ((num (count-lines beg end)))
3912 (save-excursion
3913 (goto-char beg)
3914 (- num (gnus-group-mark-group num unmark)))))
3915
3916 (defun gnus-group-remove-mark (group)
3917 (and (gnus-group-goto-group group)
3918 (save-excursion
3919 (gnus-group-mark-group 1 'unmark t))))
3920
3921 ;; Return a list of groups to work on. Take into consideration N (the
3922 ;; prefix) and the list of marked groups.
3923 (defun gnus-group-process-prefix (n)
3924 (cond (n
3925 (setq n (prefix-numeric-value n))
3926 ;; There is a prefix, so we return a list of the N next
3927 ;; groups.
3928 (let ((way (if (< n 0) -1 1))
3929 (n (abs n))
3930 group groups)
3931 (save-excursion
3932 (while (and (> n 0)
3933 (setq group (gnus-group-group-name)))
3934 (setq groups (cons group groups))
3935 (setq n (1- n))
3936 (forward-line way)))
3937 (nreverse groups)))
3938 (gnus-group-marked
3939 ;; No prefix, but a list of marked articles.
3940 (reverse gnus-group-marked))
3941 (t
3942 ;; Neither marked articles or a prefix, so we return the
3943 ;; current group.
3944 (let ((group (gnus-group-group-name)))
3945 (and group (list group))))))
3946
3947 ;; Selecting groups.
3948
3949 (defun gnus-group-read-group (&optional all no-article group)
3950 "Read news in this newsgroup.
3951 If the prefix argument ALL is non-nil, already read articles become
3952 readable. If the optional argument NO-ARTICLE is non-nil, no article
3953 will be auto-selected upon group entry."
3954 (interactive "P")
3955 (let ((group (or group (gnus-group-group-name)))
3956 number active marked entry)
3957 (or group (error "No group on current line"))
3958 (setq marked
3959 (nth 3 (nth 2 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))))
3960 ;; This group might be a dead group. In that case we have to get
3961 ;; the number of unread articles from `gnus-active-hashtb'.
3962 (if entry
3963 (setq number (car entry))
3964 (if (setq active (gnus-gethash group gnus-active-hashtb))
3965 (setq number (- (1+ (cdr active)) (car active)))))
3966 (gnus-summary-read-group
3967 group (or all (and (numberp number)
3968 (zerop (+ number (length (cdr (assq 'tick marked)))
3969 (length (cdr (assq 'dormant marked)))))))
3970 no-article)))
3971
3972 (defun gnus-group-select-group (&optional all)
3973 "Select this newsgroup.
3974 No article is selected automatically.
3975 If argument ALL is non-nil, already read articles become readable."
3976 (interactive "P")
3977 (gnus-group-read-group all t))
3978
3979 (defun gnus-group-select-group-all ()
3980 "Select the current group and display all articles in it."
3981 (interactive)
3982 (gnus-group-select-group 'all))
3983
3984 ;; Enter a group that is not in the group buffer. Non-nil is returned
3985 ;; if selection was successful.
3986 (defun gnus-group-read-ephemeral-group
3987 (group method &optional activate quit-config)
3988 (let ((group (if (gnus-group-foreign-p group) group
3989 (gnus-group-prefixed-name group method))))
3990 (gnus-sethash
3991 group
3992 (list t nil (list group gnus-level-default-subscribed nil nil
3993 (append method
3994 (list
3995 (list 'quit-config
3996 (if quit-config quit-config
3997 (cons (current-buffer) 'summary)))))))
3998 gnus-newsrc-hashtb)
3999 (set-buffer gnus-group-buffer)
4000 (or (gnus-check-server method)
4001 (error "Unable to contact server: %s" (gnus-status-message method)))
4002 (if activate (or (gnus-request-group group)
4003 (error "Couldn't request group")))
4004 (condition-case ()
4005 (gnus-group-read-group t t group)
4006 (error nil)
4007 (quit nil))
4008 (not (equal major-mode 'gnus-group-mode))))
4009
4010 (defun gnus-group-jump-to-group (group)
4011 "Jump to newsgroup GROUP."
4012 (interactive
4013 (list (completing-read
4014 "Group: " gnus-active-hashtb nil
4015 (memq gnus-select-method gnus-have-read-active-file))))
4016
4017 (if (equal group "")
4018 (error "Empty group name"))
4019
4020 (let ((b (text-property-any
4021 (point-min) (point-max) 'gnus-group (intern group))))
4022 (if b
4023 ;; Either go to the line in the group buffer...
4024 (goto-char b)
4025 ;; ... or insert the line.
4026 (or
4027 (gnus-gethash group gnus-active-hashtb)
4028 (gnus-activate-group group)
4029 (error "%s error: %s" group (gnus-status-message group)))
4030
4031 (gnus-group-update-group group)
4032 (goto-char (text-property-any
4033 (point-min) (point-max) 'gnus-group (intern group)))))
4034 ;; Adjust cursor point.
4035 (gnus-group-position-cursor))
4036
4037 (defun gnus-group-goto-group (group)
4038 "Goto to newsgroup GROUP."
4039 (let ((b (text-property-any (point-min) (point-max)
4040 'gnus-group (intern group))))
4041 (and b (goto-char b))))
4042
4043 (defun gnus-group-next-group (n)
4044 "Go to next N'th newsgroup.
4045 If N is negative, search backward instead.
4046 Returns the difference between N and the number of skips actually
4047 done."
4048 (interactive "p")
4049 (gnus-group-next-unread-group n t))
4050
4051 (defun gnus-group-next-unread-group (n &optional all level)
4052 "Go to next N'th unread newsgroup.
4053 If N is negative, search backward instead.
4054 If ALL is non-nil, choose any newsgroup, unread or not.
4055 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
4056 such group can be found, the next group with a level higher than
4057 LEVEL.
4058 Returns the difference between N and the number of skips actually
4059 made."
4060 (interactive "p")
4061 (let ((backward (< n 0))
4062 (n (abs n)))
4063 (while (and (> n 0)
4064 (gnus-group-search-forward
4065 backward (or (not gnus-group-goto-unread) all) level))
4066 (setq n (1- n)))
4067 (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
4068 (if level " on this level or higher" "")))
4069 n))
4070
4071 (defun gnus-group-prev-group (n)
4072 "Go to previous N'th newsgroup.
4073 Returns the difference between N and the number of skips actually
4074 done."
4075 (interactive "p")
4076 (gnus-group-next-unread-group (- n) t))
4077
4078 (defun gnus-group-prev-unread-group (n)
4079 "Go to previous N'th unread newsgroup.
4080 Returns the difference between N and the number of skips actually
4081 done."
4082 (interactive "p")
4083 (gnus-group-next-unread-group (- n)))
4084
4085 (defun gnus-group-next-unread-group-same-level (n)
4086 "Go to next N'th unread newsgroup on the same level.
4087 If N is negative, search backward instead.
4088 Returns the difference between N and the number of skips actually
4089 done."
4090 (interactive "p")
4091 (gnus-group-next-unread-group n t (gnus-group-group-level))
4092 (gnus-group-position-cursor))
4093
4094 (defun gnus-group-prev-unread-group-same-level (n)
4095 "Go to next N'th unread newsgroup on the same level.
4096 Returns the difference between N and the number of skips actually
4097 done."
4098 (interactive "p")
4099 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
4100 (gnus-group-position-cursor))
4101
4102 (defun gnus-group-best-unread-group (&optional exclude-group)
4103 "Go to the group with the highest level.
4104 If EXCLUDE-GROUP, do not go to that group."
4105 (interactive)
4106 (goto-char (point-min))
4107 (let ((best 100000)
4108 unread best-point)
4109 (while (setq unread (get-text-property (point) 'gnus-unread))
4110 (if (and (numberp unread) (> unread 0))
4111 (progn
4112 (if (and (< (get-text-property (point) 'gnus-level) best)
4113 (or (not exclude-group)
4114 (not (equal exclude-group (gnus-group-group-name)))))
4115 (progn
4116 (setq best (get-text-property (point) 'gnus-level))
4117 (setq best-point (point))))))
4118 (forward-line 1))
4119 (if best-point (goto-char best-point))
4120 (gnus-summary-position-cursor)
4121 (and best-point (gnus-group-group-name))))
4122
4123 (defun gnus-group-first-unread-group ()
4124 "Go to the first group with unread articles."
4125 (interactive)
4126 (prog1
4127 (let ((opoint (point))
4128 unread)
4129 (goto-char (point-min))
4130 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
4131 (not (zerop unread)) ; Has unread articles.
4132 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
4133 (point) ; Success.
4134 (goto-char opoint)
4135 nil)) ; Not success.
4136 (gnus-group-position-cursor)))
4137
4138 (defun gnus-group-enter-server-mode ()
4139 "Jump to the server buffer."
4140 (interactive)
4141 (gnus-server-setup-buffer)
4142 (gnus-configure-windows 'server)
4143 (gnus-server-prepare))
4144
4145 (defun gnus-group-make-group (name &optional method address)
4146 "Add a new newsgroup.
4147 The user will be prompted for a NAME, for a select METHOD, and an
4148 ADDRESS."
4149 (interactive
4150 (cons
4151 (read-string "Group name: ")
4152 (let ((method
4153 (completing-read
4154 "Method: " (append gnus-valid-select-methods gnus-server-alist)
4155 nil t)))
4156 (if (assoc method gnus-valid-select-methods)
4157 (list method
4158 (if (memq 'prompt-address
4159 (assoc method gnus-valid-select-methods))
4160 (read-string "Address: ")
4161 ""))
4162 (list method nil)))))
4163
4164 (let* ((meth (and method (if address (list (intern method) address) method)))
4165 (nname (if method (gnus-group-prefixed-name name meth) name))
4166 info)
4167 (and (gnus-gethash nname gnus-newsrc-hashtb)
4168 (error "Group %s already exists" nname))
4169 (gnus-group-change-level
4170 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
4171 gnus-level-default-subscribed gnus-level-killed
4172 (and (gnus-group-group-name)
4173 (gnus-gethash (gnus-group-group-name)
4174 gnus-newsrc-hashtb))
4175 t)
4176 (gnus-sethash nname (cons 1 0) gnus-active-hashtb)
4177 (or (gnus-ephemeral-group-p name)
4178 (gnus-dribble-enter
4179 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
4180 (gnus-group-insert-group-line-info nname)
4181
4182 (if (assoc method gnus-valid-select-methods)
4183 (require (intern method)))
4184 (and (gnus-check-backend-function 'request-create-group nname)
4185 (gnus-request-create-group nname))))
4186
4187 (defun gnus-group-edit-group (group &optional part)
4188 "Edit the group on the current line."
4189 (interactive (list (gnus-group-group-name)))
4190 (let ((done-func '(lambda ()
4191 "Exit editing mode and update the information."
4192 (interactive)
4193 (gnus-group-edit-group-done 'part 'group)))
4194 (part (or part 'info))
4195 (winconf (current-window-configuration))
4196 info)
4197 (or group (error "No group on current line"))
4198 (or (setq info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4199 (error "Killed group; can't be edited"))
4200 (set-buffer (get-buffer-create gnus-group-edit-buffer))
4201 (gnus-configure-windows 'edit-group)
4202 (gnus-add-current-to-buffer-list)
4203 (emacs-lisp-mode)
4204 ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4205 (use-local-map (copy-keymap emacs-lisp-mode-map))
4206 (local-set-key "\C-c\C-c" done-func)
4207 (make-local-variable 'gnus-prev-winconf)
4208 (setq gnus-prev-winconf winconf)
4209 ;; We modify the func to let it know what part it is editing.
4210 (setcar (cdr (nth 4 done-func)) (list 'quote part))
4211 (setcar (cdr (cdr (nth 4 done-func))) group)
4212 (erase-buffer)
4213 (insert
4214 (cond
4215 ((eq part 'method)
4216 ";; Type `C-c C-c' after editing the select method.\n\n")
4217 ((eq part 'params)
4218 ";; Type `C-c C-c' after editing the group parameters.\n\n")
4219 ((eq part 'info)
4220 ";; Type `C-c C-c' after editing the group info.\n\n")))
4221 (let ((cinfo (gnus-copy-sequence info))
4222 marked)
4223 (if (not (setq marked (nth 3 cinfo)))
4224 ()
4225 (while marked
4226 (or (eq 'score (car (car marked)))
4227 (eq 'bookmark (car (car marked)))
4228 (eq 'killed (car (car marked)))
4229 (not (numberp (car (cdr (car marked)))))
4230 (setcdr (car marked)
4231 (gnus-compress-sequence (sort (cdr (car marked)) '<) t)))
4232 (setq marked (cdr marked))))
4233 (insert
4234 (pp-to-string
4235 (cond ((eq part 'method)
4236 (or (nth 4 info) "native"))
4237 ((eq part 'params)
4238 (nth 5 info))
4239 (t
4240 cinfo)))
4241 "\n"))))
4242
4243 (defun gnus-group-edit-group-method (group)
4244 "Edit the select method of GROUP."
4245 (interactive (list (gnus-group-group-name)))
4246 (gnus-group-edit-group group 'method))
4247
4248 (defun gnus-group-edit-group-parameters (group)
4249 "Edit the group parameters of GROUP."
4250 (interactive (list (gnus-group-group-name)))
4251 (gnus-group-edit-group group 'params))
4252
4253 (defun gnus-group-edit-group-done (part group)
4254 "Get info from buffer, update variables and jump to the group buffer."
4255 (set-buffer (get-buffer-create gnus-group-edit-buffer))
4256 (goto-char (point-min))
4257 (let ((form (read (current-buffer)))
4258 (winconf gnus-prev-winconf))
4259 (if (eq part 'info)
4260 (gnus-group-set-info form)
4261 (gnus-group-set-info form group part))
4262 (kill-buffer (current-buffer))
4263 (and winconf (set-window-configuration winconf))
4264 (set-buffer gnus-group-buffer)
4265 (gnus-group-update-group (gnus-group-group-name))
4266 (gnus-group-position-cursor)))
4267
4268 (defun gnus-group-make-help-group ()
4269 "Create the Gnus documentation group."
4270 (interactive)
4271 (let ((path (if installation-directory
4272 (cons (concat installation-directory "etc/") load-path)
4273 (cons data-directory load-path)))
4274 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
4275 file)
4276 (and (gnus-gethash name gnus-newsrc-hashtb)
4277 (error "Documentation group already exists"))
4278 (while (and path
4279 (not (file-exists-p
4280 (setq file (concat (file-name-as-directory (car path))
4281 "gnus-tut.txt")))))
4282 (setq path (cdr path)))
4283 (if (not path)
4284 (message "Couldn't find doc group")
4285 (gnus-group-make-group
4286 (gnus-group-real-name name)
4287 (list 'nndoc name
4288 (list 'nndoc-address file)
4289 (list 'nndoc-article-type 'mbox)))))
4290 (gnus-group-position-cursor))
4291
4292 (defun gnus-group-make-doc-group (file type)
4293 "Create a group that uses a single file as the source."
4294 (interactive
4295 (list (read-file-name "File name: ")
4296 (let ((err "")
4297 found char)
4298 (while (not found)
4299 (message "%sFile type (mbox, babyl, digest) [mbd]: " err)
4300 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
4301 ((= char ?b) 'babyl)
4302 ((= char ?d) 'digest)
4303 (t (setq err (format "%c unknown. " char))
4304 nil))))
4305 found)))
4306 (let* ((file (expand-file-name file))
4307 (name (gnus-generate-new-group-name
4308 (gnus-group-prefixed-name
4309 (file-name-nondirectory file) '(nndoc "")))))
4310 (gnus-group-make-group
4311 (gnus-group-real-name name)
4312 (list 'nndoc name
4313 (list 'nndoc-address file)
4314 (list 'nndoc-article-type type)))))
4315
4316 (defun gnus-group-make-archive-group (&optional all)
4317 "Create the (ding) Gnus archive group of the most recent articles.
4318 Given a prefix, create a full group."
4319 (interactive "P")
4320 (let ((group (gnus-group-prefixed-name
4321 (if all "ding.archives" "ding.recent") '(nndir ""))))
4322 (and (gnus-gethash group gnus-newsrc-hashtb)
4323 (error "Archive group already exists"))
4324 (gnus-group-make-group
4325 (gnus-group-real-name group)
4326 "nndir"
4327 (if all gnus-group-archive-directory
4328 gnus-group-recent-archive-directory)))
4329 (gnus-group-position-cursor))
4330
4331 (defun gnus-group-make-directory-group (dir)
4332 "Create an nndir group.
4333 The user will be prompted for a directory. The contents of this
4334 directory will be used as a newsgroup. The directory should contain
4335 mail messages or news articles in files that have numeric names."
4336 (interactive
4337 (list (read-file-name "Create group from directory: ")))
4338 (or (file-exists-p dir) (error "No such directory"))
4339 (or (file-directory-p dir) (error "Not a directory"))
4340 (gnus-group-make-group dir "nndir" dir)
4341 (gnus-group-position-cursor))
4342
4343 (defun gnus-group-make-kiboze-group (group address scores)
4344 "Create an nnkiboze group.
4345 The user will be prompted for a name, a regexp to match groups, and
4346 score file entries for articles to include in the group."
4347 (interactive
4348 (list
4349 (read-string "nnkiboze group name: ")
4350 (read-string "Source groups (regexp): ")
4351 (let ((headers (mapcar (lambda (group) (list group))
4352 '("subject" "from" "number" "date" "message-id"
4353 "references" "chars" "lines" "xref")))
4354 scores header regexp regexps)
4355 (while (not (equal "" (setq header (completing-read
4356 "Match on header: " headers nil t))))
4357 (setq regexps nil)
4358 (while (not (equal "" (setq regexp (read-string
4359 (format "Match on %s (string): "
4360 header)))))
4361 (setq regexps (cons (list regexp nil nil 'r) regexps)))
4362 (setq scores (cons (cons header regexps) scores)))
4363 scores)))
4364 (gnus-group-make-group group "nnkiboze" address)
4365 (save-excursion
4366 (gnus-set-work-buffer)
4367 (let (emacs-lisp-mode-hook)
4368 (pp scores (current-buffer)))
4369 (write-region (point-min) (point-max)
4370 (concat (or gnus-kill-files-directory "~/News")
4371 "nnkiboze:" group "." gnus-score-file-suffix)))
4372 (gnus-group-position-cursor))
4373
4374 (defun gnus-group-add-to-virtual (n vgroup)
4375 "Add the current group to a virtual group."
4376 (interactive
4377 (list current-prefix-arg
4378 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
4379 "nnvirtual:")))
4380 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
4381 (error "%s is not an nnvirtual group" vgroup))
4382 (let* ((groups (gnus-group-process-prefix n))
4383 (method (nth 4 (nth 2 (gnus-gethash vgroup gnus-newsrc-hashtb)))))
4384 (setcar (cdr method)
4385 (concat
4386 (nth 1 method) "\\|"
4387 (mapconcat
4388 (lambda (s)
4389 (gnus-group-remove-mark s)
4390 (concat "\\(^" (regexp-quote s) "$\\)"))
4391 groups "\\|"))))
4392 (gnus-group-position-cursor))
4393
4394 (defun gnus-group-make-empty-virtual (group)
4395 "Create a new, fresh, empty virtual group."
4396 (interactive "sCreate new, empty virtual group: ")
4397 (let* ((method (list 'nnvirtual "^$"))
4398 (pgroup (gnus-group-prefixed-name group method)))
4399 ;; Check whether it exists already.
4400 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
4401 (error "Group %s already exists." pgroup))
4402 ;; Subscribe the new group after the group on the current line.
4403 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
4404 (gnus-group-update-group pgroup)
4405 (forward-line -1)
4406 (gnus-group-position-cursor)))
4407
4408 (defun gnus-group-enter-directory (dir)
4409 "Enter an ephemeral nneething group."
4410 (interactive "DDirectory to read: ")
4411 (let* ((method (list 'nneething dir))
4412 (leaf (gnus-group-prefixed-name
4413 (file-name-nondirectory (directory-file-name dir))
4414 method))
4415 (name (gnus-generate-new-group-name leaf)))
4416 (let ((nneething-read-only t))
4417 (or (gnus-group-read-ephemeral-group
4418 name method t
4419 (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
4420 'summary 'group)))
4421 (error "Couldn't enter %s" dir)))))
4422
4423 ;; Group sorting commands
4424 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
4425
4426 (defun gnus-group-sort-groups ()
4427 "Sort the group buffer using `gnus-group-sort-function'."
4428 (interactive)
4429 (setq gnus-newsrc-alist
4430 (sort (cdr gnus-newsrc-alist) gnus-group-sort-function))
4431 (gnus-make-hashtable-from-newsrc-alist)
4432 (gnus-group-list-groups))
4433
4434 (defun gnus-group-sort-by-alphabet (info1 info2)
4435 (string< (car info1) (car info2)))
4436
4437 (defun gnus-group-sort-by-unread (info1 info2)
4438 (let ((n1 (car (gnus-gethash (car info1) gnus-newsrc-hashtb)))
4439 (n2 (car (gnus-gethash (car info2) gnus-newsrc-hashtb))))
4440 (< (or (and (numberp n1) n1) 0)
4441 (or (and (numberp n2) n2) 0))))
4442
4443 (defun gnus-group-sort-by-level (info1 info2)
4444 (< (nth 1 info1) (nth 1 info2)))
4445
4446 ;; Group catching up.
4447
4448 (defun gnus-group-catchup-current (&optional n all)
4449 "Mark all articles not marked as unread in current newsgroup as read.
4450 If prefix argument N is numeric, the ARG next newsgroups will be
4451 caught up. If ALL is non-nil, marked articles will also be marked as
4452 read. Cross references (Xref: header) of articles are ignored.
4453 The difference between N and actual number of newsgroups that were
4454 caught up is returned."
4455 (interactive "P")
4456 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
4457 gnus-expert-user
4458 (gnus-y-or-n-p
4459 (if all
4460 "Do you really want to mark all articles as read? "
4461 "Mark all unread articles as read? "))))
4462 n
4463 (let ((groups (gnus-group-process-prefix n))
4464 (ret 0))
4465 (while groups
4466 ;; Virtual groups have to be given special treatment.
4467 (let ((method (gnus-find-method-for-group (car groups))))
4468 (if (eq 'nnvirtual (car method))
4469 (nnvirtual-catchup-group
4470 (gnus-group-real-name (car groups)) (nth 1 method) all)))
4471 (gnus-group-remove-mark (car groups))
4472 (if (prog1
4473 (gnus-group-goto-group (car groups))
4474 (gnus-group-catchup (car groups) all))
4475 (gnus-group-update-group-line)
4476 (setq ret (1+ ret)))
4477 (setq groups (cdr groups)))
4478 (gnus-group-next-unread-group 1)
4479 ret)))
4480
4481 (defun gnus-group-catchup-current-all (&optional n)
4482 "Mark all articles in current newsgroup as read.
4483 Cross references (Xref: header) of articles are ignored."
4484 (interactive "P")
4485 (gnus-group-catchup-current n 'all))
4486
4487 (defun gnus-group-catchup (group &optional all)
4488 "Mark all articles in GROUP as read.
4489 If ALL is non-nil, all articles are marked as read.
4490 The return value is the number of articles that were marked as read,
4491 or nil if no action could be taken."
4492 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4493 (num (car entry))
4494 (marked (nth 3 (nth 2 entry))))
4495 (if (not (numberp (car entry)))
4496 (gnus-message 1 "Can't catch up; non-active group")
4497 ;; Do the updating only if the newsgroup isn't killed.
4498 (if (not entry)
4499 ()
4500 (gnus-update-read-articles
4501 group (and (not all) (append (cdr (assq 'tick marked))
4502 (cdr (assq 'dormant marked))))
4503 nil (and (not all) (cdr (assq 'tick marked))))
4504 (and all
4505 (setq marked (nth 3 (nth 2 entry)))
4506 (setcar (nthcdr 3 (nth 2 entry))
4507 (delq (assq 'dormant marked)
4508 (nth 3 (nth 2 entry)))))))
4509 num))
4510
4511 (defun gnus-group-expire-articles (&optional n)
4512 "Expire all expirable articles in the current newsgroup."
4513 (interactive "P")
4514 (let ((groups (gnus-group-process-prefix n))
4515 group)
4516 (or groups (error "No groups to expire"))
4517 (while groups
4518 (setq group (car groups)
4519 groups (cdr groups))
4520 (gnus-group-remove-mark group)
4521 (if (not (gnus-check-backend-function 'request-expire-articles group))
4522 ()
4523 (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4524 (expirable (if (memq 'total-expire (nth 5 info))
4525 (cons nil (gnus-list-of-read-articles group))
4526 (assq 'expire (nth 3 info)))))
4527 (and expirable
4528 (setcdr expirable
4529 (gnus-request-expire-articles
4530 (cdr expirable) group))))))))
4531
4532 (defun gnus-group-expire-all-groups ()
4533 "Expire all expirable articles in all newsgroups."
4534 (interactive)
4535 (save-excursion
4536 (gnus-message 5 "Expiring...")
4537 (let ((gnus-group-marked (mapcar (lambda (info) (car info))
4538 (cdr gnus-newsrc-alist))))
4539 (gnus-group-expire-articles nil)))
4540 (gnus-group-position-cursor)
4541 (gnus-message 5 "Expiring...done"))
4542
4543 (defun gnus-group-set-current-level (n level)
4544 "Set the level of the next N groups to LEVEL."
4545 (interactive "P\nnLevel: ")
4546 (or (and (>= level 1) (<= level gnus-level-killed))
4547 (error "Illegal level: %d" level))
4548 (let ((groups (gnus-group-process-prefix n))
4549 group)
4550 (while groups
4551 (setq group (car groups)
4552 groups (cdr groups))
4553 (gnus-group-remove-mark group)
4554 (gnus-message 6 "Changed level of %s from %d to %d"
4555 group (gnus-group-group-level) level)
4556 (gnus-group-change-level group level
4557 (gnus-group-group-level))
4558 (gnus-group-update-group-line)))
4559 (gnus-group-position-cursor))
4560
4561 (defun gnus-group-unsubscribe-current-group (&optional n)
4562 "Toggle subscription of the current group.
4563 If given numerical prefix, toggle the N next groups."
4564 (interactive "P")
4565 (let ((groups (gnus-group-process-prefix n))
4566 group)
4567 (while groups
4568 (setq group (car groups)
4569 groups (cdr groups))
4570 (gnus-group-remove-mark group)
4571 (gnus-group-unsubscribe-group
4572 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
4573 gnus-level-default-unsubscribed
4574 gnus-level-default-subscribed))
4575 (gnus-group-update-group-line))
4576 (gnus-group-next-group 1)))
4577
4578 (defun gnus-group-unsubscribe-group (group &optional level)
4579 "Toggle subscribe from/to unsubscribe GROUP.
4580 New newsgroup is added to .newsrc automatically."
4581 (interactive
4582 (list (completing-read
4583 "Group: " gnus-active-hashtb nil
4584 (memq gnus-select-method gnus-have-read-active-file))))
4585 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
4586 (cond
4587 ((string-match "^[ \t]$" group)
4588 (error "Empty group name"))
4589 (newsrc
4590 ;; Toggle subscription flag.
4591 (gnus-group-change-level
4592 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
4593 gnus-level-subscribed)
4594 (1+ gnus-level-subscribed)
4595 gnus-level-default-subscribed)))
4596 (gnus-group-update-group group))
4597 ((and (stringp group)
4598 (or (not (memq gnus-select-method gnus-have-read-active-file))
4599 (gnus-gethash group gnus-active-hashtb)))
4600 ;; Add new newsgroup.
4601 (gnus-group-change-level
4602 group
4603 (if level level gnus-level-default-subscribed)
4604 (or (and (member group gnus-zombie-list)
4605 gnus-level-zombie)
4606 gnus-level-killed)
4607 (and (gnus-group-group-name)
4608 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
4609 (gnus-group-update-group group))
4610 (t (error "No such newsgroup: %s" group)))
4611 (gnus-group-position-cursor)))
4612
4613 (defun gnus-group-transpose-groups (n)
4614 "Move the current newsgroup up N places.
4615 If given a negative prefix, move down instead. The difference between
4616 N and the number of steps taken is returned."
4617 (interactive "p")
4618 (or (gnus-group-group-name)
4619 (error "No group on current line"))
4620 (gnus-group-kill-group 1)
4621 (prog1
4622 (forward-line (- n))
4623 (gnus-group-yank-group)
4624 (gnus-group-position-cursor)))
4625
4626 (defun gnus-group-kill-all-zombies ()
4627 "Kill all zombie newsgroups."
4628 (interactive)
4629 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
4630 (setq gnus-zombie-list nil)
4631 (gnus-group-list-groups))
4632
4633 (defun gnus-group-kill-region (begin end)
4634 "Kill newsgroups in current region (excluding current point).
4635 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
4636 (interactive "r")
4637 (let ((lines
4638 ;; Count lines.
4639 (save-excursion
4640 (count-lines
4641 (progn
4642 (goto-char begin)
4643 (beginning-of-line)
4644 (point))
4645 (progn
4646 (goto-char end)
4647 (beginning-of-line)
4648 (point))))))
4649 (goto-char begin)
4650 (beginning-of-line) ;Important when LINES < 1
4651 (gnus-group-kill-group lines)))
4652
4653 (defun gnus-group-kill-group (&optional n)
4654 "The the next N groups.
4655 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
4656 However, only groups that were alive can be yanked; already killed
4657 groups or zombie groups can't be yanked.
4658 The return value is the name of the (last) group that was killed."
4659 (interactive "P")
4660 (let ((buffer-read-only nil)
4661 (groups (gnus-group-process-prefix n))
4662 group entry level)
4663 (while groups
4664 (setq group (car groups)
4665 groups (cdr groups))
4666 (gnus-group-remove-mark group)
4667 (setq level (gnus-group-group-level))
4668 (gnus-delete-line)
4669 (if (setq entry (gnus-gethash group gnus-newsrc-hashtb))
4670 (setq gnus-list-of-killed-groups
4671 (cons (cons (car entry) (nth 2 entry))
4672 gnus-list-of-killed-groups)))
4673 (gnus-group-change-level
4674 (if entry entry group) gnus-level-killed (if entry nil level)))
4675 (gnus-group-position-cursor)
4676 group))
4677
4678 (defun gnus-group-yank-group (&optional arg)
4679 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
4680 inserting it before the current newsgroup. The numeric ARG specifies
4681 how many newsgroups are to be yanked. The name of the (last)
4682 newsgroup yanked is returned."
4683 (interactive "p")
4684 (if (not arg) (setq arg 1))
4685 (let (info group prev)
4686 (while (>= (setq arg (1- arg)) 0)
4687 (if (not (setq info (car gnus-list-of-killed-groups)))
4688 (error "No more newsgroups to yank"))
4689 (setq group (nth 2 info))
4690 ;; Find which newsgroup to insert this one before - search
4691 ;; backward until something suitable is found. If there are no
4692 ;; other newsgroups in this buffer, just make this newsgroup the
4693 ;; first newsgroup.
4694 (setq prev (gnus-group-group-name))
4695 (gnus-group-change-level
4696 info (nth 2 info) gnus-level-killed
4697 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
4698 t)
4699 (gnus-group-insert-group-line-info (nth 1 info))
4700 (setq gnus-list-of-killed-groups
4701 (cdr gnus-list-of-killed-groups)))
4702 (forward-line -1)
4703 (gnus-group-position-cursor)
4704 group))
4705
4706 (defun gnus-group-list-all-groups (&optional arg)
4707 "List all newsgroups with level ARG or lower.
4708 Default is gnus-level-unsubscribed, which lists all subscribed and most
4709 unsubscribed groups."
4710 (interactive "P")
4711 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
4712
4713 (defun gnus-group-list-killed ()
4714 "List all killed newsgroups in the group buffer."
4715 (interactive)
4716 (if (not gnus-killed-list)
4717 (gnus-message 6 "No killed groups")
4718 (let (gnus-group-list-mode)
4719 (funcall gnus-group-prepare-function
4720 gnus-level-killed t gnus-level-killed))
4721 (goto-char (point-min)))
4722 (gnus-group-position-cursor))
4723
4724 (defun gnus-group-list-zombies ()
4725 "List all zombie newsgroups in the group buffer."
4726 (interactive)
4727 (if (not gnus-zombie-list)
4728 (gnus-message 6 "No zombie groups")
4729 (let (gnus-group-list-mode)
4730 (funcall gnus-group-prepare-function
4731 gnus-level-zombie t gnus-level-zombie))
4732 (goto-char (point-min)))
4733 (gnus-group-position-cursor))
4734
4735 (defun gnus-group-get-new-news (&optional arg)
4736 "Get newly arrived articles.
4737 If ARG is non-nil, it should be a number between one and nine to
4738 specify which levels you are interested in re-scanning."
4739 (interactive "P")
4740 (run-hooks 'gnus-get-new-news-hook)
4741 (setq arg (gnus-group-default-level arg t))
4742 (if (and gnus-read-active-file (not arg))
4743 (progn
4744 (gnus-read-active-file)
4745 (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))
4746 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
4747 (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))))
4748 (gnus-group-list-groups))
4749
4750 (defun gnus-group-get-new-news-this-group (&optional n)
4751 "Check for newly arrived news in the current group (and the N-1 next groups).
4752 The difference between N and the number of newsgroup checked is returned.
4753 If N is negative, this group and the N-1 previous groups will be checked."
4754 (interactive "P")
4755 (let* ((groups (gnus-group-process-prefix n))
4756 (ret (if (numberp n) (- n (length groups)) 0))
4757 group)
4758 (while groups
4759 (setq group (car groups)
4760 groups (cdr groups))
4761 (gnus-group-remove-mark group)
4762 (or (gnus-get-new-news-in-group group)
4763 (progn
4764 (ding)
4765 (message "%s error: %s" group (gnus-status-message group))
4766 (sit-for 2))))
4767 (gnus-group-next-unread-group 1 t)
4768 (gnus-summary-position-cursor)
4769 ret))
4770
4771 (defun gnus-get-new-news-in-group (group)
4772 (and group
4773 (gnus-activate-group group)
4774 (progn
4775 (gnus-get-unread-articles-in-group
4776 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))
4777 (gnus-gethash group gnus-active-hashtb))
4778 (gnus-group-update-group-line)
4779 t)))
4780
4781 (defun gnus-group-fetch-faq (group)
4782 "Fetch the FAQ for the current group."
4783 (interactive (list (gnus-group-real-name (gnus-group-group-name))))
4784 (or group (error "No group name given"))
4785 (let ((file (concat gnus-group-faq-directory (gnus-group-real-name group))))
4786 (if (not (file-exists-p file))
4787 (error "No such file: %s" file)
4788 (find-file file))))
4789
4790 (defun gnus-group-describe-group (force &optional group)
4791 "Display a description of the current newsgroup."
4792 (interactive (list current-prefix-arg (gnus-group-group-name)))
4793 (and force (setq gnus-description-hashtb nil))
4794 (let ((method (gnus-find-method-for-group group))
4795 desc)
4796 (or group (error "No group name given"))
4797 (and (or (and gnus-description-hashtb
4798 ;; We check whether this group's method has been
4799 ;; queried for a description file.
4800 (gnus-gethash
4801 (gnus-group-prefixed-name "" method)
4802 gnus-description-hashtb))
4803 (setq desc (gnus-group-get-description group))
4804 (gnus-read-descriptions-file method))
4805 (message
4806 (or desc (gnus-gethash group gnus-description-hashtb)
4807 "No description available")))))
4808
4809 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4810 (defun gnus-group-describe-all-groups (&optional force)
4811 "Pop up a buffer with descriptions of all newsgroups."
4812 (interactive "P")
4813 (and force (setq gnus-description-hashtb nil))
4814 (if (not (or gnus-description-hashtb
4815 (gnus-read-all-descriptions-files)))
4816 (error "Couldn't request descriptions file"))
4817 (let ((buffer-read-only nil)
4818 b)
4819 (erase-buffer)
4820 (mapatoms
4821 (lambda (group)
4822 (setq b (point))
4823 (insert (format " *: %-20s %s\n" (symbol-name group)
4824 (symbol-value group)))
4825 (add-text-properties
4826 b (1+ b) (list 'gnus-group group
4827 'gnus-unread t 'gnus-marked nil
4828 'gnus-level (1+ gnus-level-subscribed))))
4829 gnus-description-hashtb)
4830 (goto-char (point-min))
4831 (gnus-group-position-cursor)))
4832
4833 ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
4834 (defun gnus-group-apropos (regexp &optional search-description)
4835 "List all newsgroups that have names that match a regexp."
4836 (interactive "sGnus apropos (regexp): ")
4837 (let ((prev "")
4838 (obuf (current-buffer))
4839 groups des)
4840 ;; Go through all newsgroups that are known to Gnus.
4841 (mapatoms
4842 (lambda (group)
4843 (and (symbol-name group)
4844 (string-match regexp (symbol-name group))
4845 (setq groups (cons (symbol-name group) groups))))
4846 gnus-active-hashtb)
4847 ;; Go through all descriptions that are known to Gnus.
4848 (if search-description
4849 (mapatoms
4850 (lambda (group)
4851 (and (string-match regexp (symbol-value group))
4852 (gnus-gethash (symbol-name group) gnus-active-hashtb)
4853 (setq groups (cons (symbol-name group) groups))))
4854 gnus-description-hashtb))
4855 (if (not groups)
4856 (gnus-message 3 "No groups matched \"%s\"." regexp)
4857 ;; Print out all the groups.
4858 (save-excursion
4859 (pop-to-buffer "*Gnus Help*")
4860 (buffer-disable-undo (current-buffer))
4861 (erase-buffer)
4862 (setq groups (sort groups 'string<))
4863 (while groups
4864 ;; Groups may be entered twice into the list of groups.
4865 (if (not (string= (car groups) prev))
4866 (progn
4867 (insert (setq prev (car groups)) "\n")
4868 (if (and gnus-description-hashtb
4869 (setq des (gnus-gethash (car groups)
4870 gnus-description-hashtb)))
4871 (insert " " des "\n"))))
4872 (setq groups (cdr groups)))
4873 (goto-char (point-min))))
4874 (pop-to-buffer obuf)))
4875
4876 (defun gnus-group-description-apropos (regexp)
4877 "List all newsgroups that have names or descriptions that match a regexp."
4878 (interactive "sGnus description apropos (regexp): ")
4879 (if (not (or gnus-description-hashtb
4880 (gnus-read-all-descriptions-files)))
4881 (error "Couldn't request descriptions file"))
4882 (gnus-group-apropos regexp t))
4883
4884 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4885 (defun gnus-group-list-matching (level regexp &optional all lowest)
4886 "List all groups with unread articles that match REGEXP.
4887 If the prefix LEVEL is non-nil, it should be a number that says which
4888 level to cut off listing groups.
4889 If ALL, also list groups with no unread articles.
4890 If LOWEST, don't list groups with level lower than LOWEST."
4891 (interactive "P\nsList newsgroups matching: ")
4892 (gnus-group-prepare-flat (or level gnus-level-subscribed)
4893 all (or lowest 1) regexp)
4894 (goto-char (point-min))
4895 (gnus-group-position-cursor))
4896
4897 (defun gnus-group-list-all-matching (level regexp &optional lowest)
4898 "List all groups that match REGEXP.
4899 If the prefix LEVEL is non-nil, it should be a number that says which
4900 level to cut off listing groups.
4901 If LOWEST, don't list groups with level lower than LOWEST."
4902 (interactive "P\nsList newsgroups matching: ")
4903 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
4904
4905 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
4906 (defun gnus-group-save-newsrc ()
4907 "Save the Gnus startup files."
4908 (interactive)
4909 (gnus-save-newsrc-file))
4910
4911 (defun gnus-group-restart (&optional arg)
4912 "Force Gnus to read the .newsrc file."
4913 (interactive "P")
4914 (gnus-save-newsrc-file)
4915 (gnus-setup-news 'force)
4916 (gnus-group-list-groups arg))
4917
4918 (defun gnus-group-read-init-file ()
4919 "Read the Gnus elisp init file."
4920 (interactive)
4921 (gnus-read-init-file))
4922
4923 (defun gnus-group-check-bogus-groups (&optional silent)
4924 "Check bogus newsgroups.
4925 If given a prefix, don't ask for confirmation before removing a bogus
4926 group."
4927 (interactive "P")
4928 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
4929 (gnus-group-list-groups))
4930
4931 (defun gnus-group-edit-global-kill (&optional article group)
4932 "Edit the global kill file.
4933 If GROUP, edit that local kill file instead."
4934 (interactive "P")
4935 (setq gnus-current-kill-article article)
4936 (gnus-kill-file-edit-file group)
4937 (gnus-message
4938 6
4939 (substitute-command-keys
4940 "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)")))
4941
4942 (defun gnus-group-edit-local-kill (article group)
4943 "Edit a local kill file."
4944 (interactive (list nil (gnus-group-group-name)))
4945 (gnus-group-edit-global-kill article group))
4946
4947 (defun gnus-group-force-update ()
4948 "Update `.newsrc' file."
4949 (interactive)
4950 (gnus-save-newsrc-file))
4951
4952 (defun gnus-group-suspend ()
4953 "Suspend the current Gnus session.
4954 In fact, cleanup buffers except for group mode buffer.
4955 The hook gnus-suspend-gnus-hook is called before actually suspending."
4956 (interactive)
4957 (run-hooks 'gnus-suspend-gnus-hook)
4958 ;; Kill Gnus buffers except for group mode buffer.
4959 (let ((group-buf (get-buffer gnus-group-buffer)))
4960 ;; Do this on a separate list in case the user does a ^G before we finish
4961 (let ((gnus-buffer-list
4962 (delq group-buf (delq gnus-dribble-buffer
4963 (append gnus-buffer-list nil)))))
4964 (while gnus-buffer-list
4965 (gnus-kill-buffer (car gnus-buffer-list))
4966 (setq gnus-buffer-list (cdr gnus-buffer-list))))
4967 (if group-buf
4968 (progn
4969 (setq gnus-buffer-list (list group-buf))
4970 (bury-buffer group-buf)
4971 (delete-windows-on group-buf t)))))
4972
4973 (defun gnus-group-clear-dribble ()
4974 "Clear all information from the dribble buffer."
4975 (interactive)
4976 (gnus-dribble-clear))
4977
4978 (defun gnus-group-exit ()
4979 "Quit reading news after updating .newsrc.eld and .newsrc.
4980 The hook `gnus-exit-gnus-hook' is called before actually exiting."
4981 (interactive)
4982 (if (or noninteractive ;For gnus-batch-kill
4983 (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed
4984 (not gnus-interactive-exit) ;Without confirmation
4985 gnus-expert-user
4986 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
4987 (progn
4988 (run-hooks 'gnus-exit-gnus-hook)
4989 ;; Offer to save data from non-quitted summary buffers.
4990 (gnus-offer-save-summaries)
4991 ;; Save the newsrc file(s).
4992 (gnus-save-newsrc-file)
4993 ;; Kill-em-all.
4994 (gnus-close-backends)
4995 ;; Reset everything.
4996 (gnus-clear-system))))
4997
4998 (defun gnus-close-backends ()
4999 ;; Send a close request to all backends that support such a request.
5000 (let ((methods gnus-valid-select-methods)
5001 func)
5002 (while methods
5003 (if (fboundp (setq func (intern (concat (car (car methods))
5004 "-request-close"))))
5005 (funcall func))
5006 (setq methods (cdr methods)))))
5007
5008 (defun gnus-group-quit ()
5009 "Quit reading news without updating .newsrc.eld or .newsrc.
5010 The hook `gnus-exit-gnus-hook' is called before actually exiting."
5011 (interactive)
5012 (if (or noninteractive ;For gnus-batch-kill
5013 (zerop (buffer-size))
5014 (not (gnus-server-opened gnus-select-method))
5015 gnus-expert-user
5016 (not gnus-current-startup-file)
5017 (gnus-yes-or-no-p
5018 (format "Quit reading news without saving %s? "
5019 (file-name-nondirectory gnus-current-startup-file))))
5020 (progn
5021 (run-hooks 'gnus-exit-gnus-hook)
5022 (if gnus-use-full-window
5023 (delete-other-windows)
5024 (gnus-remove-some-windows))
5025 (gnus-dribble-save)
5026 (gnus-close-backends)
5027 (gnus-clear-system))))
5028
5029 (defun gnus-offer-save-summaries ()
5030 (save-excursion
5031 (let ((buflist (buffer-list))
5032 buffers bufname)
5033 (while buflist
5034 (and (setq bufname (buffer-name (car buflist)))
5035 (string-match "Summary" bufname)
5036 (save-excursion
5037 (set-buffer bufname)
5038 ;; We check that this is, indeed, a summary buffer.
5039 (eq major-mode 'gnus-summary-mode))
5040 (setq buffers (cons bufname buffers)))
5041 (setq buflist (cdr buflist)))
5042 (and buffers
5043 (map-y-or-n-p
5044 "Update summary buffer %s? "
5045 (lambda (buf)
5046 (set-buffer buf)
5047 (gnus-summary-exit))
5048 buffers)))))
5049
5050 (defun gnus-group-describe-briefly ()
5051 "Give a one line description of the group mode commands."
5052 (interactive)
5053 (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")))
5054
5055 (defun gnus-group-browse-foreign-server (method)
5056 "Browse a foreign news server.
5057 If called interactively, this function will ask for a select method
5058 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
5059 If not, METHOD should be a list where the first element is the method
5060 and the second element is the address."
5061 (interactive
5062 (list (let ((how (completing-read
5063 "Which backend: "
5064 (append gnus-valid-select-methods gnus-server-alist)
5065 nil t "nntp")))
5066 ;; We either got a backend name or a virtual server name.
5067 ;; If the first, we also need an address.
5068 (if (assoc how gnus-valid-select-methods)
5069 (list (intern how)
5070 ;; Suggested by mapjph@bath.ac.uk.
5071 (completing-read
5072 "Address: "
5073 (mapcar (lambda (server) (list server))
5074 gnus-secondary-servers)))
5075 ;; We got a server name, so we find the method.
5076 (gnus-server-to-method how)))))
5077 (gnus-browse-foreign-server method))
5078
5079 \f
5080 ;;;
5081 ;;; Browse Server Mode
5082 ;;;
5083
5084 (defvar gnus-browse-mode-hook nil)
5085 (defvar gnus-browse-mode-map nil)
5086 (put 'gnus-browse-mode 'mode-class 'special)
5087
5088 (if gnus-browse-mode-map
5089 nil
5090 (setq gnus-browse-mode-map (make-keymap))
5091 (suppress-keymap gnus-browse-mode-map)
5092 (define-key gnus-browse-mode-map " " 'gnus-browse-read-group)
5093 (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group)
5094 (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group)
5095 (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group)
5096 (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group)
5097 (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group)
5098 (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group)
5099 (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group)
5100 (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group)
5101 (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group)
5102 (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group)
5103 (define-key gnus-browse-mode-map "l" 'gnus-browse-exit)
5104 (define-key gnus-browse-mode-map "L" 'gnus-browse-exit)
5105 (define-key gnus-browse-mode-map "q" 'gnus-browse-exit)
5106 (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit)
5107 (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit)
5108 (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly)
5109 (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node)
5110 )
5111
5112 (defvar gnus-browse-current-method nil)
5113 (defvar gnus-browse-return-buffer nil)
5114
5115 (defvar gnus-browse-buffer "*Gnus Browse Server*")
5116
5117 (defun gnus-browse-foreign-server (method &optional return-buffer)
5118 (setq gnus-browse-current-method method)
5119 (setq gnus-browse-return-buffer return-buffer)
5120 (let ((gnus-select-method method)
5121 groups group)
5122 (gnus-message 5 "Connecting to %s..." (nth 1 method))
5123 (or (gnus-check-server method)
5124 (error "Unable to contact server: %s" (gnus-status-message method)))
5125 (or (gnus-request-list method)
5126 (error "Couldn't request list: %s" (gnus-status-message method)))
5127 (get-buffer-create gnus-browse-buffer)
5128 (gnus-add-current-to-buffer-list)
5129 (and gnus-carpal (gnus-carpal-setup-buffer 'browse))
5130 (gnus-configure-windows 'browse)
5131 (buffer-disable-undo (current-buffer))
5132 (let ((buffer-read-only nil))
5133 (erase-buffer))
5134 (gnus-browse-mode)
5135 (setq mode-line-buffer-identification
5136 (format
5137 "Gnus Browse Server {%s:%s}" (car method) (car (cdr method))))
5138 (save-excursion
5139 (set-buffer nntp-server-buffer)
5140 (let ((cur (current-buffer)))
5141 (goto-char (point-min))
5142 (or (string= gnus-ignored-newsgroups "")
5143 (delete-matching-lines gnus-ignored-newsgroups))
5144 (while (re-search-forward
5145 "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
5146 (goto-char (match-end 1))
5147 (setq groups (cons (cons (buffer-substring (match-beginning 1)
5148 (match-end 1))
5149 (max 0 (- (1+ (read cur)) (read cur))))
5150 groups)))))
5151 (setq groups (sort groups
5152 (lambda (l1 l2)
5153 (string< (car l1) (car l2)))))
5154 (let ((buffer-read-only nil))
5155 (while groups
5156 (setq group (car groups))
5157 (insert
5158 (format "K%7d: %s\n" (cdr group) (car group)))
5159 (setq groups (cdr groups))))
5160 (switch-to-buffer (current-buffer))
5161 (goto-char (point-min))
5162 (gnus-group-position-cursor)))
5163
5164 (defun gnus-browse-mode ()
5165 "Major mode for browsing a foreign server.
5166
5167 All normal editing commands are switched off.
5168
5169 \\<gnus-browse-mode-map>
5170 The only things you can do in this buffer is
5171
5172 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
5173 The group will be inserted into the group buffer upon exit from this
5174 buffer.
5175
5176 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
5177
5178 3) `\\[gnus-browse-exit]' to return to the group buffer."
5179 (interactive)
5180 (kill-all-local-variables)
5181 (if gnus-visual (gnus-browse-make-menu-bar))
5182 (gnus-simplify-mode-line)
5183 (setq major-mode 'gnus-browse-mode)
5184 (setq mode-name "Browse Server")
5185 (setq mode-line-process nil)
5186 (use-local-map gnus-browse-mode-map)
5187 (buffer-disable-undo (current-buffer))
5188 (setq truncate-lines t)
5189 (setq buffer-read-only t)
5190 (run-hooks 'gnus-browse-mode-hook))
5191
5192 (defun gnus-browse-read-group (&optional no-article)
5193 "Enter the group at the current line."
5194 (interactive)
5195 (let ((group (gnus-browse-group-name)))
5196 (or (gnus-group-read-ephemeral-group
5197 group gnus-browse-current-method nil
5198 (cons (current-buffer) 'browse))
5199 (error "Couldn't enter %s" group))))
5200
5201 (defun gnus-browse-select-group ()
5202 "Select the current group."
5203 (interactive)
5204 (gnus-browse-read-group 'no))
5205
5206 (defun gnus-browse-next-group (n)
5207 "Go to the next group."
5208 (interactive "p")
5209 (prog1
5210 (forward-line n)
5211 (gnus-group-position-cursor)))
5212
5213 (defun gnus-browse-prev-group (n)
5214 "Go to the next group."
5215 (interactive "p")
5216 (gnus-browse-next-group (- n)))
5217
5218 (defun gnus-browse-unsubscribe-current-group (arg)
5219 "(Un)subscribe to the next ARG groups."
5220 (interactive "p")
5221 (and (eobp)
5222 (error "No group at current line."))
5223 (let ((ward (if (< arg 0) -1 1))
5224 (arg (abs arg)))
5225 (while (and (> arg 0)
5226 (not (eobp))
5227 (gnus-browse-unsubscribe-group)
5228 (zerop (gnus-browse-next-group ward)))
5229 (setq arg (1- arg)))
5230 (gnus-group-position-cursor)
5231 (if (/= 0 arg) (gnus-message 7 "No more newsgroups"))
5232 arg))
5233
5234 (defun gnus-browse-group-name ()
5235 (save-excursion
5236 (beginning-of-line)
5237 (if (not (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t))
5238 ()
5239 (gnus-group-prefixed-name
5240 (buffer-substring (match-beginning 1) (match-end 1))
5241 gnus-browse-current-method))))
5242
5243 (defun gnus-browse-unsubscribe-group ()
5244 "Toggle subscription of the current group in the browse buffer."
5245 (let ((sub nil)
5246 (buffer-read-only nil)
5247 group)
5248 (save-excursion
5249 (beginning-of-line)
5250 ;; If this group it killed, then we want to subscribe it.
5251 (if (= (following-char) ?K) (setq sub t))
5252 (setq group (gnus-browse-group-name))
5253 (delete-char 1)
5254 (if sub
5255 (progn
5256 (gnus-group-change-level
5257 (list t group gnus-level-default-subscribed
5258 nil nil gnus-browse-current-method)
5259 gnus-level-default-subscribed gnus-level-killed
5260 (and (car (nth 1 gnus-newsrc-alist))
5261 (gnus-gethash (car (nth 1 gnus-newsrc-alist))
5262 gnus-newsrc-hashtb))
5263 t)
5264 (insert ? ))
5265 (gnus-group-change-level
5266 group gnus-level-killed gnus-level-default-subscribed)
5267 (insert ?K)))
5268 t))
5269
5270 (defun gnus-browse-exit ()
5271 "Quit browsing and return to the group buffer."
5272 (interactive)
5273 (if (eq major-mode 'gnus-browse-mode)
5274 (kill-buffer (current-buffer)))
5275 (if gnus-browse-return-buffer
5276 (gnus-configure-windows 'server 'force)
5277 (gnus-configure-windows 'group 'force)
5278 (gnus-group-list-groups nil)))
5279
5280 (defun gnus-browse-describe-briefly ()
5281 "Give a one line description of the group mode commands."
5282 (interactive)
5283 (gnus-message 6
5284 (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")))
5285
5286 \f
5287 ;;;
5288 ;;; Gnus summary mode
5289 ;;;
5290
5291 (defvar gnus-summary-mode-map nil)
5292 (defvar gnus-summary-mark-map nil)
5293 (defvar gnus-summary-mscore-map nil)
5294 (defvar gnus-summary-article-map nil)
5295 (defvar gnus-summary-thread-map nil)
5296 (defvar gnus-summary-goto-map nil)
5297 (defvar gnus-summary-exit-map nil)
5298 (defvar gnus-summary-interest-map nil)
5299 (defvar gnus-summary-sort-map nil)
5300 (defvar gnus-summary-backend-map nil)
5301 (defvar gnus-summary-save-map nil)
5302 (defvar gnus-summary-wash-map nil)
5303 (defvar gnus-summary-wash-hide-map nil)
5304 (defvar gnus-summary-wash-highlight-map nil)
5305 (defvar gnus-summary-wash-time-map nil)
5306 (defvar gnus-summary-help-map nil)
5307
5308 (put 'gnus-summary-mode 'mode-class 'special)
5309
5310 (if gnus-summary-mode-map
5311 nil
5312 (setq gnus-summary-mode-map (make-keymap))
5313 (suppress-keymap gnus-summary-mode-map)
5314
5315 ;; Non-orthogonal keys
5316
5317 (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
5318 (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
5319 (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
5320 (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
5321 (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
5322 (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
5323 (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
5324 (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject)
5325 (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject)
5326 (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject)
5327 (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject)
5328 (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
5329 (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article)
5330 (define-key gnus-summary-mode-map
5331 "\M-s" 'gnus-summary-search-article-forward)
5332 (define-key gnus-summary-mode-map
5333 "\M-r" 'gnus-summary-search-article-backward)
5334 (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
5335 (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
5336 (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject)
5337 (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
5338 (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article)
5339 (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward)
5340 (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward)
5341 (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward)
5342 (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
5343 (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
5344 (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable)
5345 (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward)
5346 (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward)
5347 (define-key gnus-summary-mode-map
5348 "k" 'gnus-summary-kill-same-subject-and-select)
5349 (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
5350 (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread)
5351 (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread)
5352 (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article)
5353 (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable)
5354 (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable)
5355 (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads)
5356 (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread)
5357 (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread)
5358 (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread)
5359 (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread)
5360 (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread)
5361 (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread)
5362 (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
5363 (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
5364 (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read)
5365 (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
5366 (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant)
5367 (define-key gnus-summary-mode-map
5368 "\C-c\M-\C-s" 'gnus-summary-show-all-expunged)
5369 (define-key gnus-summary-mode-map
5370 "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
5371 (define-key gnus-summary-mode-map
5372 "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
5373 (define-key gnus-summary-mode-map
5374 "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
5375 (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
5376 (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score)
5377 (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
5378 (define-key gnus-summary-mode-map
5379 "\C-x\C-s" 'gnus-summary-reselect-current-group)
5380 (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group)
5381 (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
5382 (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
5383 (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime)
5384 (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
5385 (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
5386 (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
5387 (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
5388 (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
5389 (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
5390 (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
5391 (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail)
5392 (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
5393 (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill)
5394 (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill)
5395 (define-key gnus-summary-mode-map "V" 'gnus-version)
5396 (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group)
5397 (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
5398 (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update)
5399 (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)
5400 (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article)
5401 (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
5402 (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
5403 (define-key gnus-summary-mode-map
5404 "x" 'gnus-summary-remove-lines-marked-as-read)
5405 ; (define-key gnus-summary-mode-map "X" 'gnus-summary-remove-lines-marked-with)
5406 (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
5407 (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
5408 (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
5409 ; (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
5410 (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
5411 (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view)
5412 (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group)
5413 (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers)
5414 (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug)
5415
5416
5417 ;; Sort of orthogonal keymap
5418 (define-prefix-command 'gnus-summary-mark-map)
5419 (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map)
5420 (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward)
5421 (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward)
5422 (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward)
5423 (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward)
5424 (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward)
5425 (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward)
5426 (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable)
5427 (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable)
5428 (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant)
5429 (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark)
5430 (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark)
5431 (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable)
5432 (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable)
5433 (define-key gnus-summary-mark-map
5434 "\M-r" 'gnus-summary-remove-lines-marked-as-read)
5435 (define-key gnus-summary-mark-map
5436 "\M-\C-r" 'gnus-summary-remove-lines-marked-with)
5437 (define-key gnus-summary-mark-map "D" 'gnus-summary-show-all-dormant)
5438 (define-key gnus-summary-mark-map "\M-D" 'gnus-summary-hide-all-dormant)
5439 (define-key gnus-summary-mark-map "S" 'gnus-summary-show-all-expunged)
5440 (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup)
5441 (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here)
5442 (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all)
5443 (define-key gnus-summary-mark-map
5444 "k" 'gnus-summary-kill-same-subject-and-select)
5445 (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject)
5446
5447 (define-prefix-command 'gnus-summary-mscore-map)
5448 (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map)
5449 (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above)
5450 (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above)
5451 (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above)
5452 (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below)
5453
5454 (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map)
5455
5456 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
5457
5458 (define-prefix-command 'gnus-summary-goto-map)
5459 (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map)
5460 (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article)
5461 (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article)
5462 (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article)
5463 (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article)
5464 (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject)
5465 (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject)
5466 (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject)
5467 (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject)
5468 (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article)
5469 (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article)
5470 (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject)
5471 (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article)
5472 (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article)
5473
5474
5475 (define-prefix-command 'gnus-summary-thread-map)
5476 (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map)
5477 (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread)
5478 (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread)
5479 (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread)
5480 (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads)
5481 (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread)
5482 (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads)
5483 (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread)
5484 (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads)
5485 (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread)
5486 (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread)
5487 (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread)
5488 (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread)
5489 (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread)
5490
5491
5492 (define-prefix-command 'gnus-summary-exit-map)
5493 (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map)
5494 (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit)
5495 (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit)
5496 (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update)
5497 (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit)
5498 (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit)
5499 (define-key gnus-summary-exit-map
5500 "n" 'gnus-summary-catchup-and-goto-next-group)
5501 (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group)
5502 (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group)
5503 (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group)
5504 (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group)
5505
5506
5507 (define-prefix-command 'gnus-summary-article-map)
5508 (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map)
5509 (define-key gnus-summary-article-map " " 'gnus-summary-next-page)
5510 (define-key gnus-summary-article-map "n" 'gnus-summary-next-page)
5511 (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page)
5512 (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page)
5513 (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up)
5514 (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article)
5515 (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article)
5516 (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article)
5517 (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article)
5518 (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article)
5519 (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article)
5520 (define-key gnus-summary-article-map "g" 'gnus-summary-show-article)
5521 (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article)
5522
5523
5524
5525 (define-prefix-command 'gnus-summary-wash-map)
5526 (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map)
5527
5528 (define-prefix-command 'gnus-summary-wash-hide-map)
5529 (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map)
5530 (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide)
5531 (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers)
5532 (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature)
5533 (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation)
5534 (define-key gnus-summary-wash-hide-map
5535 "\C-c" 'gnus-article-hide-citation-maybe)
5536
5537 (define-prefix-command 'gnus-summary-wash-highlight-map)
5538 (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map)
5539 (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight)
5540 (define-key gnus-summary-wash-highlight-map
5541 "h" 'gnus-article-highlight-headers)
5542 (define-key gnus-summary-wash-highlight-map
5543 "c" 'gnus-article-highlight-citation)
5544 (define-key gnus-summary-wash-highlight-map
5545 "s" 'gnus-article-highlight-signature)
5546
5547 (define-prefix-command 'gnus-summary-wash-time-map)
5548 (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map)
5549 (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut)
5550 (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut)
5551 (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local)
5552 (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed)
5553
5554 (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons)
5555 (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike)
5556 (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap)
5557 (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr)
5558 (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable)
5559 (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face)
5560 (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking)
5561 (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message)
5562 (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header)
5563 (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime)
5564
5565
5566 (define-prefix-command 'gnus-summary-help-map)
5567 (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map)
5568 (define-key gnus-summary-help-map "v" 'gnus-version)
5569 (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq)
5570 (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group)
5571 (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly)
5572 (define-key gnus-summary-help-map "i" 'gnus-info-find-node)
5573
5574
5575 (define-prefix-command 'gnus-summary-backend-map)
5576 (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map)
5577 (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles)
5578 (define-key gnus-summary-backend-map "\M-\C-e"
5579 'gnus-summary-expire-articles-now)
5580 (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article)
5581 (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article)
5582 (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article)
5583 (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article)
5584 (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article)
5585 (define-key gnus-summary-backend-map "q" 'gnus-summary-fancy-query)
5586 (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article)
5587
5588
5589 (define-prefix-command 'gnus-summary-save-map)
5590 (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map)
5591 (define-key gnus-summary-save-map "o" 'gnus-summary-save-article)
5592 (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail)
5593 (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail)
5594 (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file)
5595 (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder)
5596 (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm)
5597 (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output)
5598 ; (define-key gnus-summary-save-map "s" 'gnus-soup-add-article)
5599
5600 (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
5601
5602 (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument)
5603 ; (define-key gnus-summary-various-map "\C-s" 'gnus-summary-search-article-forward)
5604 ; (define-key gnus-summary-various-map "\C-r" 'gnus-summary-search-article-backward)
5605 ; (define-key gnus-summary-various-map "r" 'gnus-summary-refer-article)
5606 ; (define-key gnus-summary-various-map "&" 'gnus-summary-execute-command)
5607 ; (define-key gnus-summary-various-map "T" 'gnus-summary-toggle-truncation)
5608 ; (define-key gnus-summary-various-map "e" 'gnus-summary-expand-window)
5609 (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group)
5610 ; (define-key gnus-summary-various-map "k" 'gnus-summary-edit-local-kill)
5611 ; (define-key gnus-summary-various-map "K" 'gnus-summary-edit-global-kill)
5612
5613 (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map)
5614
5615 ; (define-prefix-command 'gnus-summary-sort-map)
5616 ; (define-key gnus-summary-various-map "s" 'gnus-summary-sort-map)
5617 ; (define-key gnus-summary-sort-map "n" 'gnus-summary-sort-by-number)
5618 ; (define-key gnus-summary-sort-map "a" 'gnus-summary-sort-by-author)
5619 ; (define-key gnus-summary-sort-map "s" 'gnus-summary-sort-by-subject)
5620 ; (define-key gnus-summary-sort-map "d" 'gnus-summary-sort-by-date)
5621 ; (define-key gnus-summary-sort-map "i" 'gnus-summary-sort-by-score)
5622
5623 (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score)
5624 (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score)
5625 )
5626
5627
5628 \f
5629
5630 (defun gnus-summary-mode (&optional group)
5631 "Major mode for reading articles.
5632
5633 All normal editing commands are switched off.
5634 \\<gnus-summary-mode-map>
5635 Each line in this buffer represents one article. To read an
5636 article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
5637 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
5638 respectively.
5639
5640 You can also post articles and send mail from this buffer. To
5641 follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
5642 of an article, type `\\[gnus-summary-reply]'.
5643
5644 There are approx. one gazillion commands you can execute in this
5645 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
5646
5647 The following commands are available:
5648
5649 \\{gnus-summary-mode-map}"
5650 (interactive)
5651 (if gnus-visual (gnus-summary-make-menu-bar))
5652 (kill-all-local-variables)
5653 (let ((locals gnus-summary-local-variables))
5654 (while locals
5655 (if (consp (car locals))
5656 (progn
5657 (make-local-variable (car (car locals)))
5658 (set (car (car locals)) (eval (cdr (car locals)))))
5659 (make-local-variable (car locals))
5660 (set (car locals) nil))
5661 (setq locals (cdr locals))))
5662 (gnus-make-thread-indent-array)
5663 (gnus-simplify-mode-line)
5664 (setq major-mode 'gnus-summary-mode)
5665 (setq mode-name "Summary")
5666 (make-local-variable 'minor-mode-alist)
5667 (use-local-map gnus-summary-mode-map)
5668 (buffer-disable-undo (current-buffer))
5669 (setq buffer-read-only t) ;Disable modification
5670 (setq truncate-lines t)
5671 (setq selective-display t)
5672 (setq selective-display-ellipses t) ;Display `...'
5673 (setq buffer-display-table gnus-summary-display-table)
5674 (setq gnus-newsgroup-name group)
5675 (run-hooks 'gnus-summary-mode-hook))
5676
5677 (defun gnus-summary-make-display-table ()
5678 ;; Change the display table. Odd characters have a tendency to mess
5679 ;; up nicely formatted displays - we make all possible glyphs
5680 ;; display only a single character.
5681
5682 ;; We start from the standard display table, if any.
5683 (setq gnus-summary-display-table
5684 (or (copy-sequence standard-display-table)
5685 (make-display-table)))
5686 ;; Nix out all the control chars...
5687 (let ((i 32))
5688 (while (>= (setq i (1- i)) 0)
5689 (aset gnus-summary-display-table i [??])))
5690 ;; ... but not newline and cr, of course. (cr is necessary for the
5691 ;; selective display).
5692 (aset gnus-summary-display-table ?\n nil)
5693 (aset gnus-summary-display-table ?\r nil)
5694 ;; We nix out any glyphs over 126 that are not set already.
5695 (let ((i 256))
5696 (while (>= (setq i (1- i)) 127)
5697 ;; Only modify if the entry is nil.
5698 (or (aref gnus-summary-display-table i)
5699 (aset gnus-summary-display-table i [??])))))
5700
5701 (defun gnus-summary-clear-local-variables ()
5702 (let ((locals gnus-summary-local-variables))
5703 (while locals
5704 (if (consp (car locals))
5705 (and (vectorp (car (car locals)))
5706 (set (car (car locals)) nil))
5707 (and (vectorp (car locals))
5708 (set (car locals) nil)))
5709 (setq locals (cdr locals)))))
5710
5711 ;; Some summary mode macros.
5712
5713 ;; Return a header specified by a NUMBER.
5714 (defun gnus-get-header-by-number (number)
5715 (save-excursion
5716 (set-buffer gnus-summary-buffer)
5717 (or gnus-newsgroup-headers-hashtb-by-number
5718 (gnus-make-headers-hashtable-by-number))
5719 (gnus-gethash (int-to-string number)
5720 gnus-newsgroup-headers-hashtb-by-number)))
5721
5722 ;; Fast version of the function above.
5723 (defmacro gnus-get-header-by-num (number)
5724 (` (gnus-gethash (int-to-string (, number))
5725 gnus-newsgroup-headers-hashtb-by-number)))
5726
5727 (defmacro gnus-summary-search-forward (&optional unread subject backward)
5728 "Search for article forward.
5729 If UNREAD is non-nil, only unread articles are selected.
5730 If SUBJECT is non-nil, the article which has the same subject will be
5731 searched for.
5732 If BACKWARD is non-nil, the search will be performed backwards instead."
5733 (` (gnus-summary-search-subject (, backward) (, unread) (, subject))))
5734
5735 (defmacro gnus-summary-search-backward (&optional unread subject)
5736 "Search for article backward.
5737 If 1st optional argument UNREAD is non-nil, only unread article is selected.
5738 If 2nd optional argument SUBJECT is non-nil, the article which has
5739 the same subject will be searched for."
5740 (` (gnus-summary-search-forward (, unread) (, subject) t)))
5741
5742 (defmacro gnus-summary-article-number (&optional number-or-nil)
5743 "The article number of the article on the current line.
5744 If there isn's an article number here, then we return the current
5745 article number."
5746 (if number-or-nil
5747 '(get-text-property (gnus-point-at-bol) 'gnus-number)
5748 '(or (get-text-property (gnus-point-at-bol) 'gnus-number)
5749 gnus-current-article)))
5750
5751 (defmacro gnus-summary-thread-level ()
5752 "The thread level of the article on the current line."
5753 '(or (get-text-property (gnus-point-at-bol) 'gnus-level)
5754 0))
5755
5756 (defmacro gnus-summary-article-mark ()
5757 "The mark on the current line."
5758 '(get-text-property (gnus-point-at-bol) 'gnus-mark))
5759
5760 (defun gnus-summary-subject-string ()
5761 "Return current subject string or nil if nothing."
5762 (let ((article (gnus-summary-article-number))
5763 header)
5764 (and article
5765 (setq header (gnus-get-header-by-num article))
5766 (vectorp header)
5767 (mail-header-subject header))))
5768
5769 ;; Various summary mode internalish functions.
5770
5771 (defun gnus-mouse-pick-article (e)
5772 (interactive "e")
5773 (mouse-set-point e)
5774 (gnus-summary-next-page nil t))
5775
5776 (defun gnus-summary-setup-buffer (group)
5777 "Initialize summary buffer."
5778 (let ((buffer (concat "*Summary " group "*")))
5779 (if (get-buffer buffer)
5780 (progn
5781 (set-buffer buffer)
5782 (not gnus-newsgroup-begin))
5783 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
5784 (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
5785 (gnus-add-current-to-buffer-list)
5786 (gnus-summary-mode group)
5787 (and gnus-carpal (gnus-carpal-setup-buffer 'summary))
5788 (setq gnus-newsgroup-name group)
5789 t)))
5790
5791 (defun gnus-set-global-variables ()
5792 ;; Set the global equivalents of the summary buffer-local variables
5793 ;; to the latest values they had. These reflect the summary buffer
5794 ;; that was in action when the last article was fetched.
5795 (if (eq major-mode 'gnus-summary-mode)
5796 (progn
5797 (setq gnus-summary-buffer (current-buffer))
5798 (let ((name gnus-newsgroup-name)
5799 (marked gnus-newsgroup-marked)
5800 (unread gnus-newsgroup-unreads)
5801 (headers gnus-current-headers)
5802 (score-file gnus-current-score-file))
5803 (save-excursion
5804 (set-buffer gnus-group-buffer)
5805 (setq gnus-newsgroup-name name)
5806 (setq gnus-newsgroup-marked marked)
5807 (setq gnus-newsgroup-unreads unread)
5808 (setq gnus-current-headers headers)
5809 (setq gnus-current-score-file score-file))))))
5810
5811 (defun gnus-summary-insert-dummy-line (sformat subject number)
5812 (if (not sformat)
5813 (setq sformat gnus-summary-dummy-line-format-spec))
5814 (let (b)
5815 (beginning-of-line)
5816 (setq b (point))
5817 (insert (eval sformat))
5818 (add-text-properties
5819 b (1+ b)
5820 (list 'gnus-number number
5821 'gnus-mark gnus-dummy-mark
5822 'gnus-level 0))))
5823
5824 (defvar gnus-thread-indent-array nil)
5825 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
5826 (defun gnus-make-thread-indent-array ()
5827 (let ((n 200))
5828 (if (and gnus-thread-indent-array
5829 (= gnus-thread-indent-level gnus-thread-indent-array-level))
5830 nil
5831 (setq gnus-thread-indent-array (make-vector 201 "")
5832 gnus-thread-indent-array-level gnus-thread-indent-level)
5833 (while (>= n 0)
5834 (aset gnus-thread-indent-array n
5835 (make-string (* n gnus-thread-indent-level) ? ))
5836 (setq n (1- n))))))
5837
5838 (defun gnus-summary-insert-line
5839 (sformat header level current unread replied expirable subject-or-nil
5840 &optional dummy score process)
5841 (or sformat (setq sformat gnus-summary-line-format-spec))
5842 (let* ((indentation (aref gnus-thread-indent-array level))
5843 (lines (mail-header-lines header))
5844 (score (or score gnus-summary-default-score 0))
5845 (score-char
5846 (if (or (null gnus-summary-default-score)
5847 (<= (abs (- score gnus-summary-default-score))
5848 gnus-summary-zcore-fuzz)) ?
5849 (if (< score gnus-summary-default-score)
5850 gnus-score-below-mark gnus-score-over-mark)))
5851 (replied (cond (process gnus-process-mark)
5852 (replied gnus-replied-mark)
5853 (t gnus-unread-mark)))
5854 (from (mail-header-from header))
5855 (name (cond
5856 ((string-match "(.+)" from)
5857 (substring from (1+ (match-beginning 0)) (1- (match-end 0))))
5858 ((string-match "<[^>]+> *$" from)
5859 (let ((beg (match-beginning 0)))
5860 (or (and (string-match "^\"[^\"]*\"" from)
5861 (substring from (1+ (match-beginning 0))
5862 (1- (match-end 0))))
5863 (substring from 0 beg))))
5864 (t from)))
5865 (subject (mail-header-subject header))
5866 (number (mail-header-number header))
5867 (opening-bracket (if dummy ?\< ?\[))
5868 (closing-bracket (if dummy ?\> ?\]))
5869 (buffer-read-only nil)
5870 (b (progn (beginning-of-line) (point))))
5871 (or (numberp lines) (setq lines 0))
5872 (insert (eval sformat))
5873 (add-text-properties
5874 b (1+ b) (list 'gnus-number number
5875 'gnus-mark (or unread gnus-unread-mark)
5876 'gnus-level level))))
5877
5878 (defun gnus-summary-update-line (&optional dont-update)
5879 ;; Update summary line after change.
5880 (or (not gnus-summary-default-score)
5881 gnus-summary-inhibit-highlight
5882 (let ((gnus-summary-inhibit-highlight t)
5883 (article (gnus-summary-article-number)))
5884 (progn
5885 (or dont-update
5886 (if (and gnus-summary-mark-below
5887 (< (gnus-summary-article-score)
5888 gnus-summary-mark-below))
5889 (and (not (memq article gnus-newsgroup-marked))
5890 (not (memq article gnus-newsgroup-dormant))
5891 (memq article gnus-newsgroup-unreads)
5892 (gnus-summary-mark-article-as-read gnus-low-score-mark))
5893 (and (eq (gnus-summary-article-mark) gnus-low-score-mark)
5894 (gnus-summary-mark-article-as-unread gnus-unread-mark))))
5895 (and gnus-visual
5896 (run-hooks 'gnus-summary-update-hook))))))
5897
5898 (defun gnus-summary-update-lines (&optional beg end)
5899 ;; Mark article as read (or not) by taking into account scores.
5900 (let ((beg (or beg (point-min)))
5901 (end (or end (point-max))))
5902 (if (or (not gnus-summary-default-score)
5903 gnus-summary-inhibit-highlight)
5904 ()
5905 (let ((gnus-summary-inhibit-highlight t)
5906 article)
5907 (save-excursion
5908 (set-buffer gnus-summary-buffer)
5909 (goto-char beg)
5910 (beginning-of-line)
5911 (while (and (not (eobp)) (< (point) end))
5912 (if (and gnus-summary-mark-below
5913 (< (or (cdr (assq
5914 (setq article (get-text-property
5915 (point) 'gnus-number))
5916 gnus-newsgroup-scored))
5917 gnus-summary-default-score 0)
5918 gnus-summary-mark-below))
5919 ;; We want to possibly mark it as read...
5920 (and (not (memq article gnus-newsgroup-marked))
5921 (not (memq article gnus-newsgroup-dormant))
5922 (memq article gnus-newsgroup-unreads)
5923 (gnus-summary-mark-article-as-read gnus-low-score-mark))
5924 ;; We want to possibly mark it as unread.
5925 (and (eq (get-text-property (point) 'gnus-mark)
5926 gnus-low-score-mark)
5927 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
5928 ;; Do the visual highlights at the same time.
5929 (and gnus-visual (run-hooks 'gnus-summary-update-hook))
5930 (forward-line 1)))))))
5931
5932 (defvar gnus-tmp-gathered nil)
5933
5934 (defun gnus-summary-number-of-articles-in-thread (thread &optional char)
5935 ;; Sum up all elements (and sub-elements) in a list.
5936 (let* ((number
5937 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
5938 (if (and (consp thread) (cdr thread))
5939 (apply
5940 '+ 1 (mapcar
5941 'gnus-summary-number-of-articles-in-thread
5942 (cdr thread)))
5943 1)))
5944 (if char
5945 (if (> number 1) gnus-not-empty-thread-mark
5946 gnus-empty-thread-mark)
5947 number)))
5948
5949 (defun gnus-summary-read-group
5950 (group &optional show-all no-article kill-buffer)
5951 "Start reading news in newsgroup GROUP.
5952 If SHOW-ALL is non-nil, already read articles are also listed.
5953 If NO-ARTICLE is non-nil, no article is selected initially."
5954 (gnus-message 5 "Retrieving newsgroup: %s..." group)
5955 (let* ((new-group (gnus-summary-setup-buffer group))
5956 (quit-config (gnus-group-quit-config group))
5957 (did-select (and new-group (gnus-select-newsgroup group show-all))))
5958 (cond
5959 ((not new-group)
5960 (gnus-set-global-variables)
5961 (gnus-kill-buffer kill-buffer)
5962 (gnus-configure-windows 'summary 'force)
5963 (gnus-set-mode-line 'summary)
5964 (gnus-summary-position-cursor)
5965 (message "")
5966 t)
5967 ((null did-select)
5968 (and (eq major-mode 'gnus-summary-mode)
5969 (not (equal (current-buffer) kill-buffer))
5970 (progn
5971 (kill-buffer (current-buffer))
5972 (if (not quit-config)
5973 (progn
5974 (set-buffer gnus-group-buffer)
5975 (gnus-group-jump-to-group group)
5976 (gnus-group-next-unread-group 1))
5977 (if (not (buffer-name (car quit-config)))
5978 (gnus-configure-windows 'group 'force)
5979 (set-buffer (car quit-config))
5980 (and (eq major-mode 'gnus-summary-mode)
5981 (gnus-set-global-variables))
5982 (gnus-configure-windows (cdr quit-config))))))
5983 (message "Can't select group")
5984 nil)
5985 ((eq did-select 'quit)
5986 (and (eq major-mode 'gnus-summary-mode)
5987 (not (equal (current-buffer) kill-buffer))
5988 (kill-buffer (current-buffer)))
5989 (gnus-kill-buffer kill-buffer)
5990 (if (not quit-config)
5991 (progn
5992 (set-buffer gnus-group-buffer)
5993 (gnus-group-jump-to-group group)
5994 (gnus-group-next-unread-group 1)
5995 (gnus-configure-windows 'group 'force))
5996 (if (not (buffer-name (car quit-config)))
5997 (gnus-configure-windows 'group 'force)
5998 (set-buffer (car quit-config))
5999 (and (eq major-mode 'gnus-summary-mode)
6000 (gnus-set-global-variables))
6001 (gnus-configure-windows (cdr quit-config))))
6002 (signal 'quit nil))
6003 (t
6004 (gnus-set-global-variables)
6005 ;; Save the active value in effect when the group was entered.
6006 (setq gnus-newsgroup-active
6007 (gnus-copy-sequence
6008 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
6009 ;; You can change the subjects in this hook.
6010 (run-hooks 'gnus-select-group-hook)
6011 ;; Do score processing.
6012 (and gnus-use-scoring (gnus-possibly-score-headers))
6013 (gnus-update-format-specifications)
6014 ;; Generate the summary buffer.
6015 (gnus-summary-prepare)
6016 (if (zerop (buffer-size))
6017 (cond (gnus-newsgroup-dormant
6018 (gnus-summary-show-all-dormant))
6019 ((and gnus-newsgroup-scored show-all)
6020 (gnus-summary-show-all-expunged))))
6021 ;; Function `gnus-apply-kill-file' must be called in this hook.
6022 (run-hooks 'gnus-apply-kill-hook)
6023 (if (zerop (buffer-size))
6024 (progn
6025 ;; This newsgroup is empty.
6026 (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
6027 (gnus-message 6 "No unread news")
6028 (gnus-kill-buffer kill-buffer)
6029 nil)
6030 ;;(save-excursion
6031 ;; (if kill-buffer
6032 ;; (let ((gnus-summary-buffer kill-buffer))
6033 ;; (gnus-configure-windows 'group))))
6034 ;; Hide conversation thread subtrees. We cannot do this in
6035 ;; gnus-summary-prepare-hook since kill processing may not
6036 ;; work with hidden articles.
6037 (and gnus-show-threads
6038 gnus-thread-hide-subtree
6039 (gnus-summary-hide-all-threads))
6040 ;; Show first unread article if requested.
6041 (goto-char (point-min))
6042 (if (and (not no-article)
6043 gnus-auto-select-first
6044 (gnus-summary-first-unread-article))
6045 ()
6046 (gnus-configure-windows 'summary 'force))
6047 (gnus-set-mode-line 'summary)
6048 (gnus-summary-position-cursor)
6049 ;; If in async mode, we send some info to the backend.
6050 (and gnus-newsgroup-async
6051 (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
6052 (gnus-request-asynchronous
6053 gnus-newsgroup-name
6054 (if (and gnus-asynchronous-article-function
6055 (fboundp gnus-asynchronous-article-function))
6056 (funcall gnus-asynchronous-article-function
6057 gnus-newsgroup-threads)
6058 gnus-newsgroup-threads)))
6059 (gnus-kill-buffer kill-buffer)
6060 (if (not (get-buffer-window gnus-group-buffer))
6061 ()
6062 ;; gotta use windows, because recenter does weird stuff if
6063 ;; the current buffer ain't the displayed window.
6064 (let ((owin (selected-window)))
6065 (select-window (get-buffer-window gnus-group-buffer))
6066 (and (gnus-group-goto-group group)
6067 (recenter))
6068 (select-window owin))))
6069 t))))
6070
6071 (defun gnus-summary-prepare ()
6072 ;; Generate the summary buffer.
6073 (let ((buffer-read-only nil))
6074 (erase-buffer)
6075 (gnus-summary-prepare-threads
6076 (if gnus-show-threads
6077 (gnus-gather-threads
6078 (gnus-sort-threads
6079 (if (and gnus-summary-expunge-below
6080 (not gnus-fetch-old-headers))
6081 (gnus-make-threads-and-expunge)
6082 (gnus-make-threads))))
6083 gnus-newsgroup-headers)
6084 'cull)
6085 (gnus-summary-update-lines)
6086 ;; Create the header hashtb.
6087 (gnus-make-headers-hashtable-by-number)
6088 ;; Call hooks for modifying summary buffer.
6089 ;; Suggested by sven@tde.LTH.Se (Sven Mattisson).
6090 (goto-char (point-min))
6091 (run-hooks 'gnus-summary-prepare-hook)))
6092
6093 (defun gnus-gather-threads (threads)
6094 "Gather threads that have lost their roots."
6095 (if (not gnus-summary-make-false-root)
6096 threads
6097 (let ((hashtb (gnus-make-hashtable 1023))
6098 (prev threads)
6099 (result threads)
6100 subject hthread whole-subject)
6101 (while threads
6102 (setq whole-subject
6103 (setq subject (mail-header-subject (car (car threads)))))
6104 (if gnus-summary-gather-subject-limit
6105 (or (and (numberp gnus-summary-gather-subject-limit)
6106 (> (length subject) gnus-summary-gather-subject-limit)
6107 (setq subject
6108 (substring subject 0
6109 gnus-summary-gather-subject-limit)))
6110 (and (eq 'fuzzy gnus-summary-gather-subject-limit)
6111 (setq subject (gnus-simplify-subject-fuzzy subject))))
6112 (setq subject (gnus-simplify-subject-re subject)))
6113 (if (setq hthread
6114 (gnus-gethash subject hashtb))
6115 (progn
6116 (or (stringp (car (car hthread)))
6117 (setcar hthread (list whole-subject (car hthread))))
6118 (setcdr (car hthread) (nconc (cdr (car hthread))
6119 (list (car threads))))
6120 (setcdr prev (cdr threads))
6121 (setq threads prev))
6122 (gnus-sethash subject threads hashtb))
6123 (setq prev threads)
6124 (setq threads (cdr threads)))
6125 result)))
6126
6127 (defun gnus-make-threads ()
6128 ;; This function takes the dependencies already made by
6129 ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6130 ;; through the dependencies in the hash table and finds all the
6131 ;; roots. Roots do not refer back to any valid articles.
6132 (gnus-message 6 "Threading...")
6133 (let (roots new-roots)
6134 (and gnus-fetch-old-headers
6135 (eq gnus-headers-retrieved-by 'nov)
6136 (gnus-build-old-threads))
6137 (mapatoms
6138 (lambda (refs)
6139 (if (not (car (symbol-value refs)))
6140 (setq roots (append (cdr (symbol-value refs)) roots))
6141 ;; Ok, these refer back to valid articles, but if
6142 ;; `gnus-thread-ignore-subject' is nil, we have to check that
6143 ;; the root has the same subject as its children. The children
6144 ;; that do not are made into roots and removed from the list
6145 ;; of children.
6146 (or gnus-thread-ignore-subject
6147 (let* ((prev (symbol-value refs))
6148 (subject (gnus-simplify-subject-re
6149 (mail-header-subject (car prev))))
6150 (headers (cdr prev)))
6151 (while headers
6152 (if (not (string= subject
6153 (gnus-simplify-subject-re
6154 (mail-header-subject (car headers)))))
6155 (progn
6156 (setq new-roots (cons (car headers) new-roots))
6157 (setcdr prev (cdr headers)))
6158 (setq prev headers))
6159 (setq headers (cdr headers)))))))
6160 gnus-newsgroup-dependencies)
6161
6162 ;; We enter the new roots into the dependencies structure to
6163 ;; ensure that any possible later thread-regeneration will be
6164 ;; possible.
6165 (let ((r new-roots))
6166 (while r
6167 (gnus-sethash (concat (mail-header-id (car r)) ".boo")
6168 (list nil (car r)) gnus-newsgroup-dependencies)
6169 (setq r (cdr r))))
6170
6171 (setq roots (nconc new-roots roots))
6172
6173 (prog1
6174 (mapcar 'gnus-trim-thread
6175 (apply 'append
6176 (mapcar 'gnus-cut-thread
6177 (mapcar 'gnus-make-sub-thread roots))))
6178 (gnus-message 6 "Threading...done"))))
6179
6180
6181 (defun gnus-make-threads-and-expunge ()
6182 ;; This function takes the dependencies already made by
6183 ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6184 ;; through the dependencies in the hash table and finds all the
6185 ;; roots. Roots do not refer back to any valid articles.
6186 (gnus-message 6 "Threading...")
6187 (let ((default (or gnus-summary-default-score 0))
6188 (below gnus-summary-expunge-below)
6189 roots article new-roots)
6190 (and gnus-fetch-old-headers
6191 (eq gnus-headers-retrieved-by 'nov)
6192 (gnus-build-old-threads))
6193 (mapatoms
6194 (lambda (refs)
6195 (if (not (car (symbol-value refs)))
6196 ;; These articles do not refer back to any other articles -
6197 ;; they are roots.
6198 (let ((headers (cdr (symbol-value refs))))
6199 ;; We weed out the low-scored articles.
6200 (while headers
6201 (if (not (< (or (cdr (assq (mail-header-number (car headers))
6202 gnus-newsgroup-scored)) default)
6203 below))
6204 ;; It is over.
6205 (setq roots (cons (car headers) roots))
6206 ;; It is below, so we mark it as read.
6207 (setq gnus-newsgroup-unreads
6208 (delq (mail-header-number (car headers))
6209 gnus-newsgroup-unreads))
6210 (setq gnus-newsgroup-reads
6211 (cons (cons (mail-header-number (car headers))
6212 gnus-low-score-mark)
6213 gnus-newsgroup-reads)))
6214 (setq headers (cdr headers))))
6215 ;; Ok, these refer back to valid articles, but if
6216 ;; `gnus-thread-ignore-subject' is nil, we have to check that
6217 ;; the root has the same subject as its children. The children
6218 ;; that do not are made into roots and removed from the list
6219 ;; of children.
6220 (or gnus-thread-ignore-subject
6221 (let* ((prev (symbol-value refs))
6222 (subject (gnus-simplify-subject-re
6223 (mail-header-subject (car prev))))
6224 (headers (cdr prev)))
6225 (while headers
6226 (if (not (string= subject
6227 (gnus-simplify-subject-re
6228 (mail-header-subject (car headers)))))
6229 (progn
6230 (if (not (< (or (cdr (assq (mail-header-number
6231 (car headers))
6232 gnus-newsgroup-scored))
6233 default) below))
6234 (setq new-roots (cons (car headers) new-roots))
6235 (setq gnus-newsgroup-unreads
6236 (delq (mail-header-number (car headers))
6237 gnus-newsgroup-unreads))
6238 (setq gnus-newsgroup-reads
6239 (cons (cons (mail-header-number (car headers))
6240 gnus-low-score-mark)
6241 gnus-newsgroup-reads)))
6242 (setcdr prev (cdr headers)))
6243 (setq prev headers))
6244 (setq headers (cdr headers)))))
6245 ;; If this article is expunged, some of the children might be
6246 ;; roots.
6247 (if (< (or (cdr (assq (mail-header-number (car (symbol-value refs)))
6248 gnus-newsgroup-scored)) default)
6249 below)
6250 (let* ((prev (symbol-value refs))
6251 (headers (cdr prev)))
6252 (while headers
6253 (setq article (mail-header-number (car headers)))
6254 (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6255 default) below))
6256 (progn (setq new-roots (cons (car headers) new-roots))
6257 (setq prev headers))
6258 (setq gnus-newsgroup-unreads
6259 (delq article gnus-newsgroup-unreads))
6260 (setq gnus-newsgroup-reads
6261 (cons (cons article gnus-low-score-mark)
6262 gnus-newsgroup-reads))
6263 (setcdr prev (cdr headers)))
6264 (setq headers (cdr headers))))
6265 ;; It was not expunged, but we look at expunged children.
6266 (let* ((prev (symbol-value refs))
6267 (headers (cdr prev))
6268 article)
6269 (while headers
6270 (setq article (mail-header-number (car headers)))
6271 (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6272 default) below))
6273 (setq prev headers)
6274 (setq gnus-newsgroup-unreads
6275 (delq article gnus-newsgroup-unreads))
6276 (setq gnus-newsgroup-reads
6277 (cons (cons article gnus-low-score-mark)
6278 gnus-newsgroup-reads))
6279 (setcdr prev (cdr headers)))
6280 (setq headers (cdr headers)))))))
6281 gnus-newsgroup-dependencies)
6282
6283 ;; We enter the new roots into the dependencies structure to
6284 ;; ensure that any possible later thread-regeneration will be
6285 ;; possible.
6286 (let ((r new-roots))
6287 (while r
6288 (gnus-sethash (concat (mail-header-id (car r)) ".boo")
6289 (list nil (car r)) gnus-newsgroup-dependencies)
6290 (setq r (cdr r))))
6291
6292 (setq roots (nconc new-roots roots))
6293
6294 (prog1
6295 (mapcar 'gnus-trim-thread
6296 (apply 'append
6297 (mapcar 'gnus-cut-thread
6298 (mapcar 'gnus-make-sub-thread roots))))
6299 (gnus-message 6 "Threading...done"))))
6300
6301
6302 (defun gnus-cut-thread (thread)
6303 ;; Remove leaf dormant or ancient articles from THREAD.
6304 (let ((head (car thread))
6305 (tail (apply 'append (mapcar 'gnus-cut-thread (cdr thread)))))
6306 (if (and (null tail)
6307 (let ((number (mail-header-number head)))
6308 (or (memq number gnus-newsgroup-ancient)
6309 (memq number gnus-newsgroup-dormant)
6310 (and gnus-summary-expunge-below
6311 (eq gnus-fetch-old-headers 'some)
6312 (< (or (cdr (assq number gnus-newsgroup-scored))
6313 gnus-summary-default-score 0)
6314 gnus-summary-expunge-below)
6315 (progn
6316 (setq gnus-newsgroup-unreads
6317 (delq number gnus-newsgroup-unreads))
6318 (setq gnus-newsgroup-reads
6319 (cons (cons number gnus-low-score-mark)
6320 gnus-newsgroup-reads))
6321 t)))))
6322 nil
6323 (list (cons head tail)))))
6324
6325 (defun gnus-trim-thread (thread)
6326 ;; Remove root ancient articles with only one child from THREAD.
6327 (if (and (eq gnus-fetch-old-headers 'some)
6328 (memq (mail-header-number (car thread)) gnus-newsgroup-ancient)
6329 (= (length thread) 2))
6330 (gnus-trim-thread (nth 1 thread))
6331 thread))
6332
6333 (defun gnus-make-sub-thread (root)
6334 ;; This function makes a sub-tree for a node in the tree.
6335 (let ((children (reverse (cdr (gnus-gethash (downcase (mail-header-id root))
6336 gnus-newsgroup-dependencies)))))
6337 (cons root (mapcar 'gnus-make-sub-thread children))))
6338
6339 (defun gnus-build-old-threads ()
6340 ;; Look at all the articles that refer back to old articles, and
6341 ;; fetch the headers for the articles that aren't there. This will
6342 ;; build complete threads - if the roots haven't been expired by the
6343 ;; server, that is.
6344 (let (id heads)
6345 (mapatoms
6346 (lambda (refs)
6347 (if (not (car (symbol-value refs)))
6348 (progn
6349 (setq heads (cdr (symbol-value refs)))
6350 (while heads
6351 (if (not (memq (mail-header-number (car heads))
6352 gnus-newsgroup-dormant))
6353 (progn
6354 (setq id (symbol-name refs))
6355 (while (and (setq id (gnus-build-get-header id))
6356 (not (car (gnus-gethash
6357 id gnus-newsgroup-dependencies)))))
6358 (setq heads nil))
6359 (setq heads (cdr heads)))))))
6360 gnus-newsgroup-dependencies)))
6361
6362 (defun gnus-build-get-header (id)
6363 ;; Look through the buffer of NOV lines and find the header to
6364 ;; ID. Enter this line into the dependencies hash table, and return
6365 ;; the id of the parent article (if any).
6366 (let ((deps gnus-newsgroup-dependencies)
6367 found header)
6368 (prog1
6369 (save-excursion
6370 (set-buffer nntp-server-buffer)
6371 (goto-char (point-min))
6372 (while (and (not found) (search-forward id nil t))
6373 (beginning-of-line)
6374 (setq found (looking-at
6375 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
6376 (regexp-quote id))))
6377 (or found (beginning-of-line 2)))
6378 (if found
6379 (let (ref)
6380 (beginning-of-line)
6381 (and
6382 (setq header (gnus-nov-parse-line
6383 (read (current-buffer)) deps))
6384 (setq ref (mail-header-references header))
6385 (string-match "\\(<[^>]+>\\) *$" ref)
6386 (substring ref (match-beginning 1) (match-end 1))))))
6387 (and header
6388 (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)
6389 gnus-newsgroup-ancient (cons (mail-header-number header)
6390 gnus-newsgroup-ancient))))))
6391
6392 ;; Re-build the thread containing ID.
6393 (defun gnus-rebuild-thread (id)
6394 (let ((dep gnus-newsgroup-dependencies)
6395 (buffer-read-only nil)
6396 parent headers refs thread art)
6397 (while (and id (setq headers
6398 (car (setq art (gnus-gethash (downcase id) dep)))))
6399 (setq parent art)
6400 (setq id (and (setq refs (mail-header-references headers))
6401 (string-match "\\(<[^>]+>\\) *$" refs)
6402 (substring refs (match-beginning 1) (match-end 1)))))
6403 (setq thread (gnus-make-sub-thread (car parent)))
6404 (gnus-rebuild-remove-articles thread)
6405 (let ((beg (point)))
6406 (gnus-summary-prepare-threads (list thread))
6407 (gnus-summary-update-lines beg (point)))))
6408
6409 ;; Delete all lines in the summary buffer that correspond to articles
6410 ;; in this thread.
6411 (defun gnus-rebuild-remove-articles (thread)
6412 (and (gnus-summary-goto-subject (mail-header-number (car thread)))
6413 (gnus-delete-line))
6414 (mapcar (lambda (th) (gnus-rebuild-remove-articles th)) (cdr thread)))
6415
6416 (defun gnus-sort-threads (threads)
6417 ;; Sort threads as specified in `gnus-thread-sort-functions'.
6418 (let ((fun gnus-thread-sort-functions))
6419 (while fun
6420 (gnus-message 6 "Sorting with %S..." fun)
6421 (setq threads (sort threads (car fun))
6422 fun (cdr fun))))
6423 (if gnus-thread-sort-functions
6424 (gnus-message 6 "Sorting...done"))
6425 threads)
6426
6427 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
6428 (defmacro gnus-thread-header (thread)
6429 ;; Return header of first article in THREAD.
6430 ;; Note that THREAD must never, evr be anything else than a variable -
6431 ;; using some other form will lead to serious barfage.
6432 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
6433 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
6434 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
6435 (vector thread) 2))
6436
6437 (defun gnus-thread-sort-by-number (h1 h2)
6438 "Sort threads by root article number."
6439 (< (mail-header-number (gnus-thread-header h1))
6440 (mail-header-number (gnus-thread-header h2))))
6441
6442 (defun gnus-thread-sort-by-author (h1 h2)
6443 "Sort threads by root author."
6444 (string-lessp
6445 (let ((extract (funcall
6446 gnus-extract-address-components
6447 (mail-header-from (gnus-thread-header h1)))))
6448 (or (car extract) (cdr extract)))
6449 (let ((extract (funcall
6450 gnus-extract-address-components
6451 (mail-header-from (gnus-thread-header h2)))))
6452 (or (car extract) (cdr extract)))))
6453
6454 (defun gnus-thread-sort-by-subject (h1 h2)
6455 "Sort threads by root subject."
6456 (string-lessp
6457 (downcase (gnus-simplify-subject-re
6458 (mail-header-subject (gnus-thread-header h1))))
6459 (downcase (gnus-simplify-subject-re
6460 (mail-header-subject (gnus-thread-header h2))))))
6461
6462 (defun gnus-thread-sort-by-date (h1 h2)
6463 "Sort threads by root article date."
6464 (string-lessp
6465 (gnus-sortable-date (mail-header-date (gnus-thread-header h1)))
6466 (gnus-sortable-date (mail-header-date (gnus-thread-header h2)))))
6467
6468 (defun gnus-thread-sort-by-score (h1 h2)
6469 "Sort threads by root article score.
6470 Unscored articles will be counted as having a score of zero."
6471 (> (or (cdr (assq (mail-header-number (gnus-thread-header h1))
6472 gnus-newsgroup-scored))
6473 gnus-summary-default-score 0)
6474 (or (cdr (assq (mail-header-number (gnus-thread-header h2))
6475 gnus-newsgroup-scored))
6476 gnus-summary-default-score 0)))
6477
6478 (defun gnus-thread-sort-by-total-score (h1 h2)
6479 "Sort threads by the sum of all scores in the thread.
6480 Unscored articles will be counted as having a score of zero."
6481 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
6482
6483 (defun gnus-thread-total-score (thread)
6484 ;; This function find the total score of THREAD.
6485 (if (consp thread)
6486 (if (stringp (car thread))
6487 (apply gnus-thread-score-function 0
6488 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
6489 (gnus-thread-total-score-1 thread))
6490 (gnus-thread-total-score-1 (list thread))))
6491
6492 (defun gnus-thread-total-score-1 (root)
6493 ;; This function find the total score of the thread below ROOT.
6494 (setq root (car root))
6495 (apply gnus-thread-score-function
6496 (or (cdr (assq (mail-header-number root) gnus-newsgroup-scored))
6497 gnus-summary-default-score 0)
6498 (mapcar 'gnus-thread-total-score
6499 (cdr (gnus-gethash (downcase (mail-header-id root))
6500 gnus-newsgroup-dependencies)))))
6501
6502 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
6503 (defvar gnus-tmp-prev-subject "")
6504
6505 (defun gnus-summary-prepare-threads (threads &optional cull)
6506 "Prepare summary buffer from THREADS and indentation LEVEL.
6507 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
6508 or a straight list of headers."
6509 (gnus-message 5 "Generating summary...")
6510 (let ((level 0)
6511 thread header number subject stack state gnus-tmp-gathered)
6512 (if (vectorp (car threads))
6513 ;; If this is a straight (sic) list of headers, then a
6514 ;; threaded summary display isn't required, so we just create
6515 ;; an unthreaded one.
6516 (gnus-summary-prepare-unthreaded threads cull)
6517
6518 ;; Do the threaded display.
6519
6520 (while (or threads stack)
6521
6522 (if threads
6523 ;; If there are some threads, we do them before the
6524 ;; threads on the stack.
6525 (setq thread threads
6526 header (car (car thread)))
6527 ;; There were no current threads, so we pop something off
6528 ;; the stack.
6529 (setq state (car stack)
6530 level (car state)
6531 thread (cdr state)
6532 stack (cdr stack)
6533 header (car (car thread))))
6534
6535 (if (stringp header)
6536 (progn
6537 ;; The header is a dummy root.
6538 (cond
6539 ((eq gnus-summary-make-false-root 'adopt)
6540 ;; We let the first article adopt the rest.
6541 (let ((th (car (cdr (car thread)))))
6542 (while (cdr th)
6543 (setq th (cdr th)))
6544 (setcdr th (cdr (cdr (car thread))))
6545 (setq gnus-tmp-gathered
6546 (nconc (mapcar
6547 (lambda (h) (mail-header-number (car h)))
6548 (cdr (cdr (car thread))))
6549 gnus-tmp-gathered))
6550 (setcdr (cdr (car thread)) nil))
6551 (setq level -1))
6552 ((eq gnus-summary-make-false-root 'empty)
6553 ;; We print adopted articles with empty subject fields.
6554 (setq gnus-tmp-gathered
6555 (nconc (mapcar
6556 (lambda (h) (mail-header-number (car h)))
6557 (cdr (cdr (car thread))))
6558 gnus-tmp-gathered))
6559 (setq level -1))
6560 ((eq gnus-summary-make-false-root 'dummy)
6561 ;; We output a dummy root.
6562 (gnus-summary-insert-dummy-line
6563 nil header (mail-header-number
6564 (car (car (cdr (car thread)))))))
6565 (t
6566 ;; We do not make a root for the gathered
6567 ;; sub-threads at all.
6568 (setq level -1))))
6569
6570 (setq number (mail-header-number header)
6571 subject (mail-header-subject header))
6572
6573 ;; Do the async thing.
6574 (and gnus-newsgroup-async
6575 (setq gnus-newsgroup-threads
6576 (cons (cons number (mail-header-lines header))
6577 gnus-newsgroup-threads)))
6578
6579 ;; We may have to root out some bad articles...
6580 (and cull
6581 (= level 0)
6582 (cond ((and (memq (setq number (mail-header-number header))
6583 gnus-newsgroup-dormant)
6584 (null thread))
6585 (setq header nil))
6586 ((and gnus-summary-expunge-below
6587 (< (or (cdr (assq number gnus-newsgroup-scored))
6588 gnus-summary-default-score 0)
6589 gnus-summary-expunge-below))
6590 (setq header nil)
6591 (setq gnus-newsgroup-unreads
6592 (delq number gnus-newsgroup-unreads))
6593 (setq gnus-newsgroup-reads
6594 (cons (cons number gnus-low-score-mark)
6595 gnus-newsgroup-reads)))))
6596
6597 (and
6598 header
6599 (progn
6600 (inline
6601 (gnus-summary-insert-line
6602 nil header level nil
6603 (cond
6604 ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6605 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6606 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6607 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6608 (t (or (cdr (assq number gnus-newsgroup-reads))
6609 gnus-ancient-mark)))
6610 (memq number gnus-newsgroup-replied)
6611 (memq number gnus-newsgroup-expirable)
6612 (cond
6613 ((and gnus-thread-ignore-subject
6614 (not (string=
6615 (gnus-simplify-subject-re gnus-tmp-prev-subject)
6616 (gnus-simplify-subject-re subject))))
6617 subject)
6618 ((zerop level)
6619 (if (and (eq gnus-summary-make-false-root 'empty)
6620 (memq number gnus-tmp-gathered))
6621 gnus-summary-same-subject
6622 subject))
6623 (t gnus-summary-same-subject))
6624 (and (eq gnus-summary-make-false-root 'adopt)
6625 (memq number gnus-tmp-gathered))
6626 (cdr (assq number gnus-newsgroup-scored))
6627 (memq number gnus-newsgroup-processable))
6628
6629 (setq gnus-tmp-prev-subject subject)))))
6630
6631 (if (nth 1 thread)
6632 (setq stack (cons (cons (max 0 level) (nthcdr 1 thread)) stack)))
6633 (setq level (1+ level))
6634 (setq threads (cdr (car thread))))))
6635 (gnus-message 5 "Generating summary...done"))
6636
6637
6638
6639 (defun gnus-summary-prepare-unthreaded (headers &optional cull)
6640 (let (header number)
6641
6642 ;; Do the async thing, if that is required.
6643 (if gnus-newsgroup-async
6644 (setq gnus-newsgroup-threads
6645 (mapcar (lambda (h)
6646 (cons (mail-header-number h) (mail-header-lines h)))
6647 headers)))
6648
6649 (while headers
6650 (setq header (car headers)
6651 headers (cdr headers)
6652 number (mail-header-number header))
6653
6654 ;; We may have to root out some bad articles...
6655 (cond
6656 ((and cull
6657 (memq (setq number (mail-header-number header))
6658 gnus-newsgroup-dormant)))
6659 ((and cull gnus-summary-expunge-below
6660 (< (or (cdr (assq number gnus-newsgroup-scored))
6661 gnus-summary-default-score 0)
6662 gnus-summary-expunge-below))
6663 (setq gnus-newsgroup-unreads
6664 (delq number gnus-newsgroup-unreads))
6665 (setq gnus-newsgroup-reads
6666 (cons (cons number gnus-low-score-mark)
6667 gnus-newsgroup-reads)))
6668 (t
6669 (gnus-summary-insert-line
6670 nil header 0 nil
6671 (cond ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6672 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6673 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6674 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6675 (t (or (cdr (assq number gnus-newsgroup-reads))
6676 gnus-ancient-mark)))
6677 (memq number gnus-newsgroup-replied)
6678 (memq number gnus-newsgroup-expirable)
6679 (mail-header-subject header) nil
6680 (cdr (assq number gnus-newsgroup-scored))
6681 (memq number gnus-newsgroup-processable)))))))
6682
6683 (defun gnus-select-newsgroup (group &optional read-all)
6684 "Select newsgroup GROUP.
6685 If READ-ALL is non-nil, all articles in the group are selected."
6686 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
6687 (info (nth 2 entry))
6688 articles)
6689
6690 (or (gnus-check-server
6691 (setq gnus-current-select-method (gnus-find-method-for-group group)))
6692 (error "Couldn't open server"))
6693
6694 (or (and entry (not (eq (car entry) t))) ; Either it's active...
6695 (gnus-activate-group group) ; Or we can activate it...
6696 (progn ; Or we bug out.
6697 (kill-buffer (current-buffer))
6698 (error "Couldn't request group %s: %s"
6699 group (gnus-status-message group))))
6700
6701 (setq gnus-newsgroup-name group)
6702 (setq gnus-newsgroup-unselected nil)
6703 (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
6704
6705 (and gnus-asynchronous
6706 (gnus-check-backend-function
6707 'request-asynchronous gnus-newsgroup-name)
6708 (setq gnus-newsgroup-async
6709 (gnus-request-asynchronous gnus-newsgroup-name)))
6710
6711 (setq articles (gnus-articles-to-read group read-all))
6712
6713 (cond
6714 ((null articles)
6715 (gnus-message 3 "Couldn't select newsgroup")
6716 'quit)
6717 ((eq articles 0) nil)
6718 (t
6719 ;; Init the dependencies hash table.
6720 (setq gnus-newsgroup-dependencies
6721 (gnus-make-hashtable (length articles)))
6722 ;; Retrieve the headers and read them in.
6723 (gnus-message 5 "Fetching headers...")
6724 (setq gnus-newsgroup-headers
6725 (if (eq 'nov (setq gnus-headers-retrieved-by
6726 ;; This is a naughty hack. To get the
6727 ;; retrieval of old headers to work, we
6728 ;; set `nntp-nov-gap' to nil (locally),
6729 ;; and then just retrieve the headers.
6730 ;; Mucho magic.
6731 (if gnus-fetch-old-headers
6732 (let (nntp-nov-gap)
6733 (gnus-retrieve-headers
6734 (if (not (eq 1 (car articles)))
6735 (cons 1 articles)
6736 articles)
6737 gnus-newsgroup-name))
6738 (gnus-retrieve-headers
6739 articles gnus-newsgroup-name))))
6740 (progn
6741 (gnus-get-newsgroup-headers-xover articles))
6742 ;; If we were to fetch old headers, but the backend didn't
6743 ;; support XOVER, then it is possible we fetched one article
6744 ;; that we shouldn't have. If that's the case, we remove it.
6745 (if (or (not gnus-fetch-old-headers)
6746 (eq 1 (car articles)))
6747 ()
6748 (save-excursion
6749 (set-buffer nntp-server-buffer)
6750 (goto-char (point-min))
6751 (and
6752 (looking-at "[0-9]+[ \t]+1[ \t]") ; This is not a NOV line.
6753 (delete-region ; So we delete this head.
6754 (point)
6755 (search-forward "\n.\n" nil t)))))
6756 (gnus-get-newsgroup-headers)))
6757 (gnus-message 5 "Fetching headers...done")
6758 ;; Remove canceled articles from the list of unread articles.
6759 (setq gnus-newsgroup-unreads
6760 (gnus-set-sorted-intersection
6761 gnus-newsgroup-unreads
6762 (mapcar (lambda (headers) (mail-header-number headers))
6763 gnus-newsgroup-headers)))
6764 ;; Adjust and set lists of article marks.
6765 (and info
6766 (let (marked)
6767 (gnus-adjust-marked-articles info)
6768 (setq gnus-newsgroup-marked
6769 (copy-sequence
6770 (cdr (assq 'tick (setq marked (nth 3 info))))))
6771 (setq gnus-newsgroup-replied
6772 (copy-sequence (cdr (assq 'reply marked))))
6773 (setq gnus-newsgroup-expirable
6774 (copy-sequence (cdr (assq 'expire marked))))
6775 (setq gnus-newsgroup-killed
6776 (copy-sequence (cdr (assq 'killed marked))))
6777 (setq gnus-newsgroup-bookmarks
6778 (copy-sequence (cdr (assq 'bookmark marked))))
6779 (setq gnus-newsgroup-dormant
6780 (copy-sequence (cdr (assq 'dormant marked))))
6781 (setq gnus-newsgroup-scored
6782 (copy-sequence (cdr (assq 'score marked))))
6783 (setq gnus-newsgroup-processable nil)))
6784 ;; Check whether auto-expire is to be done in this group.
6785 (setq gnus-newsgroup-auto-expire
6786 (or (and (stringp gnus-auto-expirable-newsgroups)
6787 (string-match gnus-auto-expirable-newsgroups group))
6788 (memq 'auto-expire (nth 5 info))))
6789 ;; First and last article in this newsgroup.
6790 (and gnus-newsgroup-headers
6791 (setq gnus-newsgroup-begin
6792 (mail-header-number (car gnus-newsgroup-headers)))
6793 (setq gnus-newsgroup-end
6794 (mail-header-number
6795 (gnus-last-element gnus-newsgroup-headers))))
6796 (setq gnus-reffed-article-number -1)
6797 ;; GROUP is successfully selected.
6798 (or gnus-newsgroup-headers t)))))
6799
6800 (defun gnus-articles-to-read (group read-all)
6801 ;; Find out what articles the user wants to read.
6802 (let* ((articles
6803 ;; Select all articles if `read-all' is non-nil, or if all the
6804 ;; unread articles are dormant articles.
6805 (if (or read-all
6806 (= (length gnus-newsgroup-unreads)
6807 (length gnus-newsgroup-dormant)))
6808 (gnus-uncompress-range
6809 (gnus-gethash group gnus-active-hashtb))
6810 gnus-newsgroup-unreads))
6811 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
6812 (scored (length scored-list))
6813 (number (length articles))
6814 (marked (+ (length gnus-newsgroup-marked)
6815 (length gnus-newsgroup-dormant)))
6816 (select
6817 (cond
6818 ((numberp read-all)
6819 read-all)
6820 (t
6821 (condition-case ()
6822 (cond ((and (or (<= scored marked)
6823 (= scored number))
6824 (numberp gnus-large-newsgroup)
6825 (> number gnus-large-newsgroup))
6826 (let ((input
6827 (read-string
6828 (format
6829 "How many articles from %s (default %d): "
6830 gnus-newsgroup-name number))))
6831 (if (string-match "^[ \t]*$" input)
6832 number input)))
6833 ((and (> scored marked) (< scored number))
6834 (let ((input
6835 (read-string
6836 (format
6837 "%s %s (%d scored, %d total): "
6838 "How many articles from"
6839 group scored number))))
6840 (if (string-match "^[ \t]*$" input)
6841 number input)))
6842 (t number))
6843 (quit nil))))))
6844 (setq select (if (stringp select) (string-to-number select) select))
6845 (if (or (null select) (zerop select))
6846 select
6847 (if (and (not (zerop scored)) (<= (abs select) scored))
6848 (progn
6849 (setq articles (sort scored-list '<))
6850 (setq number (length articles)))
6851 (setq articles (copy-sequence articles)))
6852
6853 (if (< (abs select) number)
6854 (if (< select 0)
6855 ;; Select the N oldest articles.
6856 (setcdr (nthcdr (1- (abs select)) articles) nil)
6857 ;; Select the N most recent articles.
6858 (setq articles (nthcdr (- number select) articles))))
6859 (setq gnus-newsgroup-unselected
6860 (gnus-sorted-intersection
6861 gnus-newsgroup-unreads
6862 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
6863 articles)))
6864
6865 (defun gnus-killed-articles (killed articles)
6866 (let (out)
6867 (while articles
6868 (if (inline (gnus-member-of-range (car articles) killed))
6869 (setq out (cons (car articles) out)))
6870 (setq articles (cdr articles)))
6871 out))
6872
6873 (defun gnus-adjust-marked-articles (info &optional active)
6874 "Remove all marked articles that are no longer legal."
6875 (let ((marked-lists (nth 3 info))
6876 (active (or active (gnus-gethash (car info) gnus-active-hashtb)))
6877 m prev)
6878 ;; There are many types of marked articles.
6879 (while marked-lists
6880 (setq m (cdr (setq prev (car marked-lists))))
6881 (cond ((or (eq 'tick (car prev)) (eq 'dormant (car prev)))
6882 ;; Make sure that all ticked articles are a subset of the
6883 ;; unread/unselected articles.
6884 ;;(while m
6885 ;; (if (or (memq (car m) gnus-newsgroup-unreads)
6886 ;; (memq (car m) gnus-newsgroup-unselected))
6887 ;; (setq prev m)
6888 ;; (setcdr prev (cdr m)))
6889 ;; (setq m (cdr m)))
6890 )
6891 ((eq 'score (car prev))
6892 ;; Scored articles should be a subset of
6893 ;; unread/unselected articles.
6894 (while m
6895 (if (or (memq (car (car m)) gnus-newsgroup-unreads)
6896 (memq (car (car m)) gnus-newsgroup-unreads))
6897 (setq prev m)
6898 (setcdr prev (cdr m)))
6899 (setq m (cdr m))))
6900 ((eq 'bookmark (car prev))
6901 ;; Bookmarks should be a subset of active articles.
6902 (while m
6903 (if (< (car (car m)) (car active))
6904 (setcdr prev (cdr m))
6905 (setq prev m))
6906 (setq m (cdr m))))
6907 ((eq 'killed (car prev))
6908 ;; Articles that have been through the kill process are
6909 ;; to be a subset of active articles.
6910 (while (and m (< (or (and (numberp (car m)) (car m))
6911 (cdr (car m)))
6912 (car active)))
6913 (setcdr prev (cdr m))
6914 (setq m (cdr m)))
6915 (if (and m (< (or (and (numberp (car m)) (car m))
6916 (car (car m)))
6917 (car active)))
6918 (setcar (if (numberp (car m)) m (car m)) (car active))))
6919 ((or (eq 'reply (car prev)) (eq 'expire (car prev)))
6920 ;; The replied and expirable articles have to be articles
6921 ;; that are active.
6922 (while m
6923 (if (< (car m) (car active))
6924 (setcdr prev (cdr m))
6925 (setq prev m))
6926 (setq m (cdr m)))))
6927 (setq marked-lists (cdr marked-lists)))
6928 ;; Remove all lists that are empty.
6929 (setq marked-lists (nth 3 info))
6930 (if marked-lists
6931 (progn
6932 (while (= 1 (length (car marked-lists)))
6933 (setq marked-lists (cdr marked-lists)))
6934 (setq m (cdr (setq prev marked-lists)))
6935 (while m
6936 (if (= 1 (length (car m)))
6937 (setcdr prev (cdr m))
6938 (setq prev m))
6939 (setq m (cdr m)))
6940 (setcar (nthcdr 3 info) marked-lists)))
6941 ;; Finally, if there are no marked lists at all left, and if there
6942 ;; are no elements after the lists in the info list, we just chop
6943 ;; the info list off before the marked lists.
6944 (and (null marked-lists)
6945 (not (nthcdr 4 info))
6946 (setcdr (nthcdr 2 info) nil)))
6947 info)
6948
6949 (defun gnus-set-marked-articles
6950 (info ticked replied expirable killed dormant bookmark score)
6951 "Enter the various lists of marked articles into the newsgroup info list."
6952 (let (newmarked)
6953 (and ticked (setq newmarked (cons (cons 'tick ticked) nil)))
6954 (and replied (setq newmarked (cons (cons 'reply replied) newmarked)))
6955 (and expirable (setq newmarked (cons (cons 'expire expirable)
6956 newmarked)))
6957 (and killed (setq newmarked (cons (cons 'killed killed) newmarked)))
6958 (and dormant (setq newmarked (cons (cons 'dormant dormant) newmarked)))
6959 (and bookmark (setq newmarked (cons (cons 'bookmark bookmark)
6960 newmarked)))
6961 (and score (setq newmarked (cons (cons 'score score) newmarked)))
6962 (if (nthcdr 3 info)
6963 (progn
6964 (setcar (nthcdr 3 info) newmarked)
6965 (and (not newmarked)
6966 (not (nthcdr 4 info))
6967 (setcdr (nthcdr 2 info) nil)))
6968 (if newmarked
6969 (setcdr (nthcdr 2 info) (list newmarked))))))
6970
6971 (defun gnus-add-marked-articles (group type articles &optional info force)
6972 ;; Add ARTICLES of TYPE to the info of GROUP.
6973 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
6974 ;; add, but replace marked articles of TYPE with ARTICLES.
6975 (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
6976 marked m)
6977 (or (not info)
6978 (and (not (setq marked (nthcdr 3 info)))
6979 (setcdr (nthcdr 2 info) (list (list (cons type articles)))))
6980 (and (not (setq m (assq type (car marked))))
6981 (setcar marked (cons (cons type articles) (car marked))))
6982 (if force
6983 (setcdr m articles)
6984 (nconc m articles)))))
6985
6986 (defun gnus-set-mode-line (where)
6987 "This function sets the mode line of the article or summary buffers.
6988 If WHERE is `summary', the summary mode line format will be used."
6989 (if (memq where gnus-updated-mode-lines)
6990 (let (mode-string)
6991 (save-excursion
6992 (set-buffer gnus-summary-buffer)
6993 (let* ((mformat (if (eq where 'article)
6994 gnus-article-mode-line-format-spec
6995 gnus-summary-mode-line-format-spec))
6996 (buffer-name (if (eq where 'article)
6997 (buffer-name
6998 (get-buffer gnus-article-buffer))
6999 (buffer-name)))
7000 (group-name gnus-newsgroup-name)
7001 (article-number (or gnus-current-article 0))
7002 (unread (- (length gnus-newsgroup-unreads)
7003 (length gnus-newsgroup-dormant)))
7004 (unread-and-unticked
7005 (- unread (length gnus-newsgroup-marked)))
7006 (unselected (length gnus-newsgroup-unselected))
7007 (unread-and-unselected
7008 (cond ((and (zerop unread-and-unticked)
7009 (zerop unselected)) "")
7010 ((zerop unselected)
7011 (format "{%d more}" unread-and-unticked))
7012 (t (format "{%d(+%d) more}"
7013 unread-and-unticked unselected))))
7014 (subject
7015 (if gnus-current-headers
7016 (mail-header-subject gnus-current-headers) ""))
7017 (max-len (and gnus-mode-non-string-length
7018 (- (frame-width) gnus-mode-non-string-length)))
7019 header);; passed as argument to any user-format-funcs
7020 (setq mode-string (eval mformat))
7021 (or (numberp max-len)
7022 (setq max-len (length mode-string)))
7023 (if (< max-len 4) (setq max-len 4))
7024 (if (> (length mode-string) max-len)
7025 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
7026 ;; function `substring' might cut on a middle
7027 ;; of multi-octet character.
7028 (setq mode-string
7029 (concat (gnus-truncate-string mode-string (- max-len 3))
7030 "...")))
7031 (setq mode-string (format (format "%%-%ds" max-len)
7032 mode-string))))
7033 (setq mode-line-buffer-identification mode-string)
7034 (set-buffer-modified-p t))))
7035
7036 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
7037 "Go through the HEADERS list and add all Xrefs to a hash table.
7038 The resulting hash table is returned, or nil if no Xrefs were found."
7039 (let* ((from-method (gnus-find-method-for-group from-newsgroup))
7040 (prefix (if (and
7041 (gnus-group-foreign-p from-newsgroup)
7042 (not (memq 'virtual
7043 (assoc (symbol-name (car from-method))
7044 gnus-valid-select-methods))))
7045 (gnus-group-real-prefix from-newsgroup)))
7046 (xref-hashtb (make-vector 63 0))
7047 start group entry number xrefs header)
7048 (while headers
7049 (setq header (car headers))
7050 (if (and (setq xrefs (mail-header-xref header))
7051 (not (memq (mail-header-number header) unreads)))
7052 (progn
7053 (setq start 0)
7054 (while (string-match "\\([^ ]+\\):\\([0-9]+\\)" xrefs start)
7055 (setq start (match-end 0))
7056 (setq group (concat prefix (substring xrefs (match-beginning 1)
7057 (match-end 1))))
7058 (setq number
7059 (string-to-int (substring xrefs (match-beginning 2)
7060 (match-end 2))))
7061 (if (setq entry (gnus-gethash group xref-hashtb))
7062 (setcdr entry (cons number (cdr entry)))
7063 (gnus-sethash group (cons number nil) xref-hashtb)))))
7064 (setq headers (cdr headers)))
7065 (if start xref-hashtb nil)))
7066
7067 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads expirable)
7068 "Look through all the headers and mark the Xrefs as read."
7069 (let ((virtual (memq 'virtual
7070 (assoc (symbol-name (car (gnus-find-method-for-group
7071 from-newsgroup)))
7072 gnus-valid-select-methods)))
7073 name entry info xref-hashtb idlist method
7074 nth4)
7075 (save-excursion
7076 (set-buffer gnus-group-buffer)
7077 (if (setq xref-hashtb
7078 (gnus-create-xref-hashtb from-newsgroup headers unreads))
7079 (mapatoms
7080 (lambda (group)
7081 (if (string= from-newsgroup (setq name (symbol-name group)))
7082 ()
7083 (setq idlist (symbol-value group))
7084 ;; Dead groups are not updated.
7085 (if (and (prog1
7086 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
7087 info (nth 2 entry))
7088 (if (stringp (setq nth4 (nth 4 info)))
7089 (setq nth4 (gnus-server-to-method nth4))))
7090 ;; Only do the xrefs if the group has the same
7091 ;; select method as the group we have just read.
7092 (or (gnus-methods-equal-p
7093 nth4 (gnus-find-method-for-group from-newsgroup))
7094 virtual
7095 (equal nth4
7096 (setq method (gnus-find-method-for-group
7097 from-newsgroup)))
7098 (and (equal (car nth4) (car method))
7099 (equal (nth 1 nth4) (nth 1 method))))
7100 gnus-use-cross-reference
7101 (or (not (eq gnus-use-cross-reference t))
7102 virtual
7103 ;; Only do cross-references on subscribed
7104 ;; groups, if that is what is wanted.
7105 (<= (nth 1 info) gnus-level-subscribed)))
7106 (gnus-group-make-articles-read name idlist expirable))))
7107 xref-hashtb)))))
7108
7109 (defun gnus-group-make-articles-read (group articles expirable)
7110 (let* ((num 0)
7111 (entry (gnus-gethash group gnus-newsrc-hashtb))
7112 (info (nth 2 entry))
7113 (active (gnus-gethash group gnus-active-hashtb))
7114 exps expirable range)
7115 ;; First peel off all illegal article numbers.
7116 (if active
7117 (let ((ids articles)
7118 (ticked (cdr (assq 'tick (nth 3 info))))
7119 (dormant (cdr (assq 'dormant (nth 3 info))))
7120 id first)
7121 (setq exps nil)
7122 (while ids
7123 (setq id (car ids))
7124 (if (and first (> id (cdr active)))
7125 (progn
7126 ;; We'll end up in this situation in one particular
7127 ;; obscure situation. If you re-scan a group and get
7128 ;; a new article that is cross-posted to a different
7129 ;; group that has not been re-scanned, you might get
7130 ;; crossposted article that has a higher number than
7131 ;; Gnus believes possible. So we re-activate this
7132 ;; group as well. This might mean doing the
7133 ;; crossposting thingy will *increase* the number
7134 ;; of articles in some groups. Tsk, tsk.
7135 (setq active (or (gnus-activate-group group) active))))
7136 (if (or (> id (cdr active))
7137 (< id (car active))
7138 (memq id ticked)
7139 (memq id dormant))
7140 (setq articles (delq id articles)))
7141 (and (memq id expirable)
7142 (setq exps (cons id exps)))
7143 (setq ids (cdr ids)))))
7144 ;; Update expirable articles.
7145 (gnus-add-marked-articles nil 'expirable exps info)
7146 (and active
7147 (null (nth 2 info))
7148 (> (car active) 1)
7149 (setcar (nthcdr 2 info) (cons 1 (1- (car active)))))
7150 (setcar (nthcdr 2 info)
7151 (setq range
7152 (gnus-add-to-range
7153 (nth 2 info)
7154 (setq articles (sort articles '<)))))
7155 ;; Then we have to re-compute how many unread
7156 ;; articles there are in this group.
7157 (if active
7158 (progn
7159 (cond
7160 ((not range)
7161 (setq num (- (1+ (cdr active)) (car active))))
7162 ((not (listp (cdr range)))
7163 (setq num (- (cdr active) (- (1+ (cdr range))
7164 (car range)))))
7165 (t
7166 (while range
7167 (if (numberp (car range))
7168 (setq num (1+ num))
7169 (setq num (+ num (- (1+ (cdr (car range)))
7170 (car (car range))))))
7171 (setq range (cdr range)))
7172 (setq num (- (cdr active) num))))
7173 ;; Update the number of unread articles.
7174 (setcar
7175 entry
7176 (max 0 (- num
7177 (length (cdr (assq 'tick (nth 3 info))))
7178 (length
7179 (cdr (assq 'dormant (nth 3 info)))))))
7180 ;; Update the group buffer.
7181 (gnus-group-update-group group t)))))
7182
7183 (defun gnus-methods-equal-p (m1 m2)
7184 (let ((m1 (or m1 gnus-select-method))
7185 (m2 (or m2 gnus-select-method)))
7186 (or (equal m1 m2)
7187 (and (eq (car m1) (car m2))
7188 (or (not (memq 'address (assoc (symbol-name (car m1))
7189 gnus-valid-select-methods)))
7190 (equal (nth 1 m1) (nth 1 m2)))))))
7191
7192 (defsubst gnus-header-value ()
7193 (buffer-substring (match-end 0) (gnus-point-at-eol)))
7194
7195 (defvar gnus-newsgroup-none-id 0)
7196
7197 (defun gnus-get-newsgroup-headers ()
7198 (setq gnus-article-internal-prepare-hook nil)
7199 (let ((cur nntp-server-buffer)
7200 (dependencies gnus-newsgroup-dependencies)
7201 headers id dep end ref)
7202 (save-excursion
7203 (set-buffer nntp-server-buffer)
7204 ;; Allow the user to mangle the headers before parsing them.
7205 (run-hooks 'gnus-parse-headers-hook)
7206 (goto-char (point-min))
7207 ;; Search to the beginning of the next header. Error messages
7208 ;; do not begin with 2 or 3.
7209 (while (re-search-forward "^[23][0-9]+ " nil t)
7210 (let ((header (make-vector 9 nil))
7211 (case-fold-search t)
7212 (p (point))
7213 in-reply-to)
7214 (setq id nil
7215 ref nil)
7216 (mail-header-set-number header (read cur))
7217 ;; This implementation of this function, with nine
7218 ;; search-forwards instead of the one re-search-forward and
7219 ;; a case (which basically was the old function) is actually
7220 ;; about twice as fast, even though it looks messier. You
7221 ;; can't have everything, I guess. Speed and elegance
7222 ;; doesn't always come hand in hand.
7223 (save-restriction
7224 (narrow-to-region (point) (or (save-excursion
7225 (search-forward "\n.\n" nil t))
7226 (point)))
7227 (if (search-forward "\nfrom: " nil t)
7228 (mail-header-set-from header (gnus-header-value))
7229 (mail-header-set-from header "(nobody)"))
7230 (goto-char p)
7231 (if (search-forward "\nsubject: " nil t)
7232 (mail-header-set-subject header (gnus-header-value))
7233 (mail-header-set-subject header "(none)"))
7234 (goto-char p)
7235 (and (search-forward "\nxref: " nil t)
7236 (mail-header-set-xref header (gnus-header-value)))
7237 (goto-char p)
7238 (or (numberp (and (search-forward "\nlines: " nil t)
7239 (mail-header-set-lines header (read cur))))
7240 (mail-header-set-lines header 0))
7241 (goto-char p)
7242 (and (search-forward "\ndate: " nil t)
7243 (mail-header-set-date header (gnus-header-value)))
7244 (goto-char p)
7245 (if (search-forward "\nmessage-id: " nil t)
7246 (mail-header-set-id header (setq id (gnus-header-value)))
7247 ;; If there was no message-id, we just fake one to make
7248 ;; subsequent routines simpler.
7249 (mail-header-set-id
7250 header
7251 (setq id (concat "none+"
7252 (int-to-string
7253 (setq gnus-newsgroup-none-id
7254 (1+ gnus-newsgroup-none-id)))))))
7255 (goto-char p)
7256 (if (search-forward "\nreferences: " nil t)
7257 (progn
7258 (mail-header-set-references header (gnus-header-value))
7259 (setq end (match-end 0))
7260 (save-excursion
7261 (setq ref
7262 (downcase
7263 (buffer-substring
7264 (progn
7265 (end-of-line)
7266 (search-backward ">" end t)
7267 (1+ (point)))
7268 (progn
7269 (search-backward "<" end t)
7270 (point)))))))
7271 ;; Get the references from the in-reply-to header if there
7272 ;; ware no references and the in-reply-to header looks
7273 ;; promising.
7274 (if (and (search-forward "\nin-reply-to: " nil t)
7275 (setq in-reply-to (gnus-header-value))
7276 (string-match "<[^>]+>" in-reply-to))
7277 (progn
7278 (mail-header-set-references
7279 header
7280 (setq ref (substring in-reply-to (match-beginning 0)
7281 (match-end 0))))
7282 (setq ref (downcase ref)))
7283 (setq ref "none")))
7284 ;; We do some threading while we read the headers. The
7285 ;; message-id and the last reference are both entered into
7286 ;; the same hash table. Some tippy-toeing around has to be
7287 ;; done in case an article has arrived before the article
7288 ;; which it refers to.
7289 (if (boundp (setq dep (intern (downcase id) dependencies)))
7290 (if (car (symbol-value dep))
7291 ;; An article with this Message-ID has already
7292 ;; been seen, so we ignore this one, except we add
7293 ;; any additional Xrefs (in case the two articles
7294 ;; came from different servers.
7295 (progn
7296 (mail-header-set-xref
7297 (car (symbol-value dep))
7298 (concat (or (mail-header-xref
7299 (car (symbol-value dep))) "")
7300 (or (mail-header-xref header) "")))
7301 (setq header nil))
7302 (setcar (symbol-value dep) header))
7303 (set dep (list header)))
7304 (if header
7305 (progn
7306 (if (boundp (setq dep (intern ref dependencies)))
7307 (setcdr (symbol-value dep)
7308 (cons header (cdr (symbol-value dep))))
7309 (set dep (list nil header)))
7310 (setq headers (cons header headers))))
7311 (goto-char (point-max))))))
7312 (nreverse headers)))
7313
7314 ;; The following macros and functions were written by Felix Lee
7315 ;; <flee@cse.psu.edu>.
7316
7317 (defmacro gnus-nov-read-integer ()
7318 '(prog1
7319 (if (= (following-char) ?\t)
7320 0
7321 (let ((num (condition-case nil (read buffer) (error nil))))
7322 (if (numberp num) num 0)))
7323 (or (eobp) (forward-char 1))))
7324
7325 (defmacro gnus-nov-skip-field ()
7326 '(search-forward "\t" eol 'move))
7327
7328 (defmacro gnus-nov-field ()
7329 '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
7330
7331 ;; Goes through the xover lines and returns a list of vectors
7332 (defun gnus-get-newsgroup-headers-xover (sequence)
7333 "Parse the news overview data in the server buffer, and return a
7334 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
7335 ;; Get the Xref when the users reads the articles since most/some
7336 ;; NNTP servers do not include Xrefs when using XOVER.
7337 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
7338 (let ((cur nntp-server-buffer)
7339 (dependencies gnus-newsgroup-dependencies)
7340 number headers header)
7341 (save-excursion
7342 (set-buffer nntp-server-buffer)
7343 ;; Allow the user to mangle the headers before parsing them.
7344 (run-hooks 'gnus-parse-headers-hook)
7345 (goto-char (point-min))
7346 (while (and sequence (not (eobp)))
7347 (setq number (read cur))
7348 (while (and sequence (< (car sequence) number))
7349 (setq sequence (cdr sequence)))
7350 (and sequence
7351 (eq number (car sequence))
7352 (progn
7353 (setq sequence (cdr sequence))
7354 (if (setq header
7355 (inline (gnus-nov-parse-line number dependencies)))
7356 (setq headers (cons header headers)))))
7357 (forward-line 1))
7358 (setq headers (nreverse headers)))
7359 headers))
7360
7361 ;; This function has to be called with point after the article number
7362 ;; on the beginning of the line.
7363 (defun gnus-nov-parse-line (number dependencies)
7364 (let ((none 0)
7365 (eol (gnus-point-at-eol))
7366 (buffer (current-buffer))
7367 header ref id dep)
7368
7369 ;; overview: [num subject from date id refs chars lines misc]
7370 (narrow-to-region (point) eol)
7371 (or (eobp) (forward-char))
7372
7373 (condition-case nil
7374 (setq header
7375 (vector
7376 number ; number
7377 (gnus-nov-field) ; subject
7378 (gnus-nov-field) ; from
7379 (gnus-nov-field) ; date
7380 (setq id (or (gnus-nov-field)
7381 (concat "none+"
7382 (int-to-string
7383 (setq none (1+ none)))))) ; id
7384 (progn
7385 (save-excursion
7386 (let ((beg (point)))
7387 (search-forward "\t" eol)
7388 (if (search-backward ">" beg t)
7389 (setq ref
7390 (downcase
7391 (buffer-substring
7392 (1+ (point))
7393 (progn
7394 (search-backward "<" beg t)
7395 (point)))))
7396 (setq ref nil))))
7397 (gnus-nov-field)) ; refs
7398 (gnus-nov-read-integer) ; chars
7399 (gnus-nov-read-integer) ; lines
7400 (if (= (following-char) ?\n)
7401 nil
7402 (gnus-nov-field)) ; misc
7403 ))
7404 (error (progn
7405 (ding)
7406 (message "Strange nov line.")
7407 (setq header nil)
7408 (goto-char eol))))
7409
7410 (widen)
7411
7412 ;; We build the thread tree.
7413 (and header
7414 (if (boundp (setq dep (intern (downcase id) dependencies)))
7415 (if (car (symbol-value dep))
7416 ;; An article with this Message-ID has already been seen,
7417 ;; so we ignore this one, except we add any additional
7418 ;; Xrefs (in case the two articles came from different
7419 ;; servers.
7420 (progn
7421 (mail-header-set-xref
7422 (car (symbol-value dep))
7423 (concat (or (mail-header-xref (car (symbol-value dep))) "")
7424 (or (mail-header-xref header) "")))
7425 (setq header nil))
7426 (setcar (symbol-value dep) header))
7427 (set dep (list header))))
7428 (if header
7429 (progn
7430 (if (boundp (setq dep (intern (or ref "none")
7431 dependencies)))
7432 (setcdr (symbol-value dep)
7433 (cons header (cdr (symbol-value dep))))
7434 (set dep (list nil header)))))
7435 header))
7436
7437 (defun gnus-article-get-xrefs ()
7438 "Fill in the Xref value in `gnus-current-headers', if necessary.
7439 This is meant to be called in `gnus-article-internal-prepare-hook'."
7440 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
7441 gnus-current-headers)))
7442 (or (not gnus-use-cross-reference)
7443 (not headers)
7444 (and (mail-header-xref headers)
7445 (not (string= (mail-header-xref headers) "")))
7446 (let ((case-fold-search t)
7447 xref)
7448 (save-restriction
7449 (gnus-narrow-to-headers)
7450 (goto-char (point-min))
7451 (if (or (and (eq (downcase (following-char)) ?x)
7452 (looking-at "Xref:"))
7453 (search-forward "\nXref:" nil t))
7454 (progn
7455 (goto-char (1+ (match-end 0)))
7456 (setq xref (buffer-substring (point)
7457 (progn (end-of-line) (point))))
7458 (mail-header-set-xref headers xref))))))))
7459
7460 (defalias 'gnus-find-header-by-number 'gnus-get-header-by-number)
7461 (make-obsolete 'gnus-find-header-by-number 'gnus-get-header-by-number)
7462
7463 (defun gnus-make-headers-hashtable-by-number ()
7464 "Make hashtable for the variable gnus-newsgroup-headers by number."
7465 (save-excursion
7466 (set-buffer gnus-summary-buffer)
7467 (let ((headers gnus-newsgroup-headers)
7468 header)
7469 (setq gnus-newsgroup-headers-hashtb-by-number
7470 (gnus-make-hashtable (length headers)))
7471 (while headers
7472 (setq header (car headers))
7473 (gnus-sethash (int-to-string (mail-header-number header))
7474 header gnus-newsgroup-headers-hashtb-by-number)
7475 (setq headers (cdr headers))))))
7476
7477 (defun gnus-more-header-backward ()
7478 "Find new header backward."
7479 (let ((first (car (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7480 (artnum gnus-newsgroup-begin)
7481 (header nil))
7482 (while (and (not header)
7483 (> artnum first))
7484 (setq artnum (1- artnum))
7485 (setq header (gnus-read-header artnum)))
7486 header))
7487
7488 (defun gnus-more-header-forward (&optional backward)
7489 "Find new header forward.
7490 If BACKWARD, find new header backward instead."
7491 (if backward
7492 (gnus-more-header-backward)
7493 (let ((last (cdr (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7494 (artnum gnus-newsgroup-end)
7495 (header nil))
7496 (while (and (not header)
7497 (< artnum last))
7498 (setq artnum (1+ artnum))
7499 (setq header (gnus-read-header artnum)))
7500 header)))
7501
7502 (defun gnus-extend-newsgroup (header &optional backward)
7503 "Extend newsgroup selection with HEADER.
7504 Optional argument BACKWARD means extend toward backward."
7505 (if header
7506 (let ((artnum (mail-header-number header)))
7507 (setq gnus-newsgroup-headers
7508 (if backward
7509 (cons header gnus-newsgroup-headers)
7510 (nconc gnus-newsgroup-headers (list header))))
7511 (setq gnus-newsgroup-unselected
7512 (delq artnum gnus-newsgroup-unselected))
7513 (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum))
7514 (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum)))))
7515
7516 (defun gnus-summary-work-articles (n)
7517 "Return a list of articles to be worked upon. The prefix argument,
7518 the list of process marked articles, and the current article will be
7519 taken into consideration."
7520 (let (articles)
7521 (if (and n (numberp n))
7522 (let ((backward (< n 0))
7523 (n (abs n)))
7524 (save-excursion
7525 (while (and (> n 0)
7526 (setq articles (cons (gnus-summary-article-number)
7527 articles))
7528 (gnus-summary-search-forward nil nil backward))
7529 (setq n (1- n))))
7530 (sort articles (function <)))
7531 (or (reverse gnus-newsgroup-processable)
7532 (list (gnus-summary-article-number))))))
7533
7534 (defun gnus-summary-search-group (&optional backward use-level)
7535 "Search for next unread newsgroup.
7536 If optional argument BACKWARD is non-nil, search backward instead."
7537 (save-excursion
7538 (set-buffer gnus-group-buffer)
7539 (if (gnus-group-search-forward
7540 backward nil (if use-level (gnus-group-group-level) nil))
7541 (gnus-group-group-name))))
7542
7543 (defun gnus-summary-best-group (&optional exclude-group)
7544 "Find the name of the best unread group.
7545 If EXCLUDE-GROUP, do not go to this group."
7546 (save-excursion
7547 (set-buffer gnus-group-buffer)
7548 (save-excursion
7549 (gnus-group-best-unread-group exclude-group))))
7550
7551 (defun gnus-subject-equal (s1 s2)
7552 (cond
7553 ((null gnus-summary-gather-subject-limit)
7554 (equal (gnus-simplify-subject-re s1)
7555 (gnus-simplify-subject-re s2)))
7556 ((eq gnus-summary-gather-subject-limit 'fuzzy)
7557 (equal (gnus-simplify-subject-fuzzy s1)
7558 (gnus-simplify-subject-fuzzy s2)))
7559 ((numberp gnus-summary-gather-subject-limit)
7560 (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit)
7561 (gnus-limit-string s2 gnus-summary-gather-subject-limit)))
7562 (t
7563 (equal s1 s2))))
7564
7565 (defun gnus-summary-search-subject (&optional backward unread subject)
7566 "Search for article forward.
7567 If BACKWARD is non-nil, search backward.
7568 If UNREAD is non-nil, only unread articles are selected.
7569 If SUBJECT is non-nil, the article which has the same subject will be
7570 searched for."
7571 (let ((func (if backward 'previous-single-property-change
7572 'next-single-property-change))
7573 (beg (point))
7574 (did t)
7575 pos psubject)
7576 (beginning-of-line)
7577 (and gnus-summary-check-current unread
7578 (eq (get-text-property (point) 'gnus-mark) gnus-unread-mark)
7579 (setq did nil))
7580 (if (not did)
7581 ()
7582 (forward-char (if backward (if (bobp) 0 -1) (if (eobp) 0 1)))
7583 (while
7584 (and
7585 (setq pos (funcall func (point) 'gnus-number))
7586 (goto-char (if backward (1- pos) pos))
7587 (setq did
7588 (not (and
7589 (or (not unread)
7590 (eq (get-text-property (point) 'gnus-mark)
7591 gnus-unread-mark))
7592 (or (not subject)
7593 (and (setq psubject
7594 (inline (gnus-summary-subject-string)))
7595 (inline
7596 (gnus-subject-equal subject psubject)))))))
7597 (if backward (if (bobp) nil (forward-char -1) t)
7598 (if (eobp) nil (forward-char 1) t)))))
7599 (if did
7600 (progn (goto-char beg) nil)
7601 (prog1
7602 (get-text-property (point) 'gnus-number)
7603 (gnus-summary-show-thread)
7604 (gnus-summary-position-cursor)))))
7605
7606 (defun gnus-summary-pseudo-article ()
7607 "The thread level of the article on the current line."
7608 (get-text-property (gnus-point-at-bol) 'gnus-pseudo))
7609
7610 (defalias 'gnus-summary-score 'gnus-summary-article-score)
7611 (make-obsolete 'gnus-summary-score 'gnus-summary-article-score)
7612 (defun gnus-summary-article-score ()
7613 "Return current article score."
7614 (or (cdr (assq (gnus-summary-article-number) gnus-newsgroup-scored))
7615 gnus-summary-default-score 0))
7616
7617 (defun gnus-summary-recenter ()
7618 "Center point in the summary window.
7619 If `gnus-auto-center-summary' is nil, or the article buffer isn't
7620 displayed, no centering will be performed."
7621 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
7622 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
7623 (let* ((top (cond ((< (window-height) 4) 0)
7624 ((< (window-height) 7) 1)
7625 (t 2)))
7626 (height (1- (window-height)))
7627 (bottom (save-excursion (goto-char (point-max))
7628 (forward-line (- height))
7629 (point)))
7630 (window (get-buffer-window (current-buffer))))
7631 (and
7632 ;; The user has to want it,
7633 gnus-auto-center-summary
7634 ;; the article buffer must be displayed,
7635 (get-buffer-window gnus-article-buffer)
7636 ;; Set the window start to either `bottom', which is the biggest
7637 ;; possible valid number, or the second line from the top,
7638 ;; whichever is the least.
7639 (set-window-start
7640 window (min bottom (save-excursion (forward-line (- top)) (point)))))))
7641
7642 ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
7643 (defun gnus-short-group-name (group &optional levels)
7644 "Collapse GROUP name LEVELS."
7645 (let* ((name "") (foreign "") (depth -1) (skip 1)
7646 (levels (or levels
7647 (progn
7648 (while (string-match "\\." group skip)
7649 (setq skip (match-end 0)
7650 depth (+ depth 1)))
7651 depth))))
7652 (if (string-match ":" group)
7653 (setq foreign (substring group 0 (match-end 0))
7654 group (substring group (match-end 0))))
7655 (while group
7656 (if (and (string-match "\\." group) (> levels 0))
7657 (setq name (concat name (substring group 0 1))
7658 group (substring group (match-end 0))
7659 levels (- levels 1)
7660 name (concat name "."))
7661 (setq name (concat foreign name group)
7662 group nil)))
7663 name))
7664
7665 (defun gnus-summary-jump-to-group (newsgroup)
7666 "Move point to NEWSGROUP in group mode buffer."
7667 ;; Keep update point of group mode buffer if visible.
7668 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
7669 (save-window-excursion
7670 ;; Take care of tree window mode.
7671 (if (get-buffer-window gnus-group-buffer)
7672 (pop-to-buffer gnus-group-buffer))
7673 (gnus-group-jump-to-group newsgroup))
7674 (save-excursion
7675 ;; Take care of tree window mode.
7676 (if (get-buffer-window gnus-group-buffer)
7677 (pop-to-buffer gnus-group-buffer)
7678 (set-buffer gnus-group-buffer))
7679 (gnus-group-jump-to-group newsgroup))))
7680
7681 ;; This function returns a list of article numbers based on the
7682 ;; difference between the ranges of read articles in this group and
7683 ;; the range of active articles.
7684 (defun gnus-list-of-unread-articles (group)
7685 (let* ((read (nth 2 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
7686 (active (gnus-gethash group gnus-active-hashtb))
7687 (last (cdr active))
7688 first nlast unread)
7689 ;; If none are read, then all are unread.
7690 (if (not read)
7691 (setq first (car active))
7692 ;; If the range of read articles is a single range, then the
7693 ;; first unread article is the article after the last read
7694 ;; article. Sounds logical, doesn't it?
7695 (if (not (listp (cdr read)))
7696 (setq first (1+ (cdr read)))
7697 ;; `read' is a list of ranges.
7698 (if (/= (setq nlast (or (and (numberp (car read)) (car read))
7699 (car (car read)))) 1)
7700 (setq first 1))
7701 (while read
7702 (if first
7703 (while (< first nlast)
7704 (setq unread (cons first unread))
7705 (setq first (1+ first))))
7706 (setq first (1+ (if (atom (car read)) (car read) (cdr (car read)))))
7707 (setq nlast (if (atom (car (cdr read)))
7708 (car (cdr read))
7709 (car (car (cdr read)))))
7710 (setq read (cdr read)))))
7711 ;; And add the last unread articles.
7712 (while (<= first last)
7713 (setq unread (cons first unread))
7714 (setq first (1+ first)))
7715 ;; Return the list of unread articles.
7716 (nreverse unread)))
7717
7718 (defun gnus-list-of-read-articles (group)
7719 (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
7720 (active (gnus-gethash group gnus-active-hashtb)))
7721 (and info active
7722 (gnus-sorted-complement
7723 (gnus-uncompress-range active)
7724 (gnus-list-of-unread-articles group)))))
7725
7726 ;; Various summary commands
7727
7728 (defun gnus-summary-universal-argument ()
7729 "Perform any operation on all articles marked with the process mark."
7730 (interactive)
7731 (gnus-set-global-variables)
7732 (let ((articles (reverse gnus-newsgroup-processable))
7733 func)
7734 (or articles (error "No articles marked"))
7735 (or (setq func (key-binding (read-key-sequence "C-c C-u")))
7736 (error "Undefined key"))
7737 (while articles
7738 (gnus-summary-goto-subject (car articles))
7739 (command-execute func)
7740 (gnus-summary-remove-process-mark (car articles))
7741 (setq articles (cdr articles)))))
7742
7743 (defun gnus-summary-toggle-truncation (&optional arg)
7744 "Toggle truncation of summary lines.
7745 With arg, turn line truncation on iff arg is positive."
7746 (interactive "P")
7747 (setq truncate-lines
7748 (if (null arg) (not truncate-lines)
7749 (> (prefix-numeric-value arg) 0)))
7750 (redraw-display))
7751
7752 (defun gnus-summary-reselect-current-group (&optional all)
7753 "Once exit and then reselect the current newsgroup.
7754 The prefix argument ALL means to select all articles."
7755 (interactive "P")
7756 (gnus-set-global-variables)
7757 (let ((current-subject (gnus-summary-article-number))
7758 (group gnus-newsgroup-name))
7759 (setq gnus-newsgroup-begin nil)
7760 (gnus-summary-exit t)
7761 ;; We have to adjust the point of group mode buffer because the
7762 ;; current point was moved to the next unread newsgroup by
7763 ;; exiting.
7764 (gnus-summary-jump-to-group group)
7765 (gnus-group-read-group all t)
7766 (gnus-summary-goto-subject current-subject)))
7767
7768 (defun gnus-summary-rescan-group (&optional all)
7769 "Exit the newsgroup, ask for new articles, and select the newsgroup."
7770 (interactive "P")
7771 (gnus-set-global-variables)
7772 ;; Fix by Ilja Weis <kult@uni-paderborn.de>.
7773 (let ((group gnus-newsgroup-name))
7774 (gnus-summary-exit)
7775 (gnus-summary-jump-to-group group)
7776 (save-excursion
7777 (set-buffer gnus-group-buffer)
7778 (gnus-group-get-new-news-this-group 1))
7779 (gnus-summary-jump-to-group group)
7780 (gnus-group-read-group all)))
7781
7782 (defun gnus-summary-update-info ()
7783 (let* ((group gnus-newsgroup-name))
7784 (if gnus-newsgroup-kill-headers
7785 (setq gnus-newsgroup-killed
7786 (gnus-compress-sequence
7787 (nconc
7788 (gnus-set-sorted-intersection
7789 (gnus-uncompress-range gnus-newsgroup-killed)
7790 (setq gnus-newsgroup-unselected
7791 (sort gnus-newsgroup-unselected '<)))
7792 (setq gnus-newsgroup-unreads
7793 (sort gnus-newsgroup-unreads '<))) t)))
7794 (or (listp (cdr gnus-newsgroup-killed))
7795 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7796 (let ((headers gnus-newsgroup-headers))
7797 (gnus-close-group group)
7798 (run-hooks 'gnus-exit-group-hook)
7799 (gnus-update-read-articles
7800 group gnus-newsgroup-unreads gnus-newsgroup-unselected
7801 gnus-newsgroup-marked
7802 t gnus-newsgroup-replied gnus-newsgroup-expirable
7803 gnus-newsgroup-killed gnus-newsgroup-dormant
7804 gnus-newsgroup-bookmarks
7805 (and gnus-save-score gnus-newsgroup-scored))
7806 (and gnus-use-cross-reference
7807 (gnus-mark-xrefs-as-read
7808 group headers gnus-newsgroup-unreads gnus-newsgroup-expirable))
7809 ;; Do adaptive scoring, and possibly save score files.
7810 (and gnus-newsgroup-adaptive
7811 (gnus-score-adaptive))
7812 (and gnus-use-scoring
7813 (fboundp 'gnus-score-save)
7814 (funcall 'gnus-score-save))
7815 ;; Do not switch windows but change the buffer to work.
7816 (set-buffer gnus-group-buffer)
7817 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
7818 (gnus-group-update-group group)))))
7819
7820 (defun gnus-summary-exit (&optional temporary)
7821 "Exit reading current newsgroup, and then return to group selection mode.
7822 gnus-exit-group-hook is called with no arguments if that value is non-nil."
7823 (interactive)
7824 (gnus-set-global-variables)
7825 (gnus-kill-save-kill-buffer)
7826 (let* ((group gnus-newsgroup-name)
7827 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7828 (mode major-mode)
7829 (buf (current-buffer)))
7830 (run-hooks 'gnus-summary-prepare-exit-hook)
7831 ;; Make all changes in this group permanent.
7832 (gnus-summary-update-info)
7833 (set-buffer buf)
7834 (and gnus-use-cache (gnus-cache-possibly-remove-articles))
7835 ;; Make sure where I was, and go to next newsgroup.
7836 (set-buffer gnus-group-buffer)
7837 (or quit-config
7838 (progn
7839 (gnus-group-jump-to-group group)
7840 (gnus-group-next-unread-group 1)))
7841 (if temporary
7842 nil ;Nothing to do.
7843 ;; We set all buffer-local variables to nil. It is unclear why
7844 ;; this is needed, but if we don't, buffer-local variables are
7845 ;; not garbage-collected, it seems. This would the lead to en
7846 ;; ever-growing Emacs.
7847 (set-buffer buf)
7848 (gnus-summary-clear-local-variables)
7849 ;; We clear the global counterparts of the buffer-local
7850 ;; variables as well, just to be on the safe side.
7851 (gnus-configure-windows 'group 'force)
7852 (gnus-summary-clear-local-variables)
7853 ;; Return to group mode buffer.
7854 (if (eq mode 'gnus-summary-mode)
7855 (gnus-kill-buffer buf))
7856 (if (get-buffer gnus-article-buffer)
7857 (bury-buffer gnus-article-buffer))
7858 (setq gnus-current-select-method gnus-select-method)
7859 (pop-to-buffer gnus-group-buffer)
7860 (if (not quit-config)
7861 (progn
7862 (gnus-group-jump-to-group group)
7863 (gnus-group-next-unread-group 1))
7864 (if (not (buffer-name (car quit-config)))
7865 (gnus-configure-windows 'group 'force)
7866 (set-buffer (car quit-config))
7867 (and (eq major-mode 'gnus-summary-mode)
7868 (gnus-set-global-variables))
7869 (gnus-configure-windows (cdr quit-config))))
7870 (run-hooks 'gnus-summary-exit-hook))))
7871
7872 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7873 (defun gnus-summary-exit-no-update (&optional no-questions)
7874 "Quit reading current newsgroup without updating read article info."
7875 (interactive)
7876 (gnus-set-global-variables)
7877 (let* ((group gnus-newsgroup-name)
7878 (quit-config (gnus-group-quit-config group)))
7879 (if (or no-questions
7880 gnus-expert-user
7881 (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
7882 (progn
7883 (gnus-close-group group)
7884 (gnus-summary-clear-local-variables)
7885 (set-buffer gnus-group-buffer)
7886 (gnus-summary-clear-local-variables)
7887 ;; Return to group selection mode.
7888 (gnus-configure-windows 'group 'force)
7889 (if (get-buffer gnus-summary-buffer)
7890 (kill-buffer gnus-summary-buffer))
7891 (if (get-buffer gnus-article-buffer)
7892 (bury-buffer gnus-article-buffer))
7893 (if (equal (gnus-group-group-name) group)
7894 (gnus-group-next-unread-group 1))
7895 (if quit-config
7896 (progn
7897 (if (not (buffer-name (car quit-config)))
7898 (gnus-configure-windows 'group 'force)
7899 (set-buffer (car quit-config))
7900 (and (eq major-mode 'gnus-summary-mode)
7901 (gnus-set-global-variables))
7902 (gnus-configure-windows (cdr quit-config)))))))))
7903
7904 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7905 (defun gnus-summary-fetch-faq (group)
7906 "Fetch the FAQ for the current group."
7907 (interactive (list gnus-newsgroup-name))
7908 (let (gnus-faq-buffer)
7909 (and (setq gnus-faq-buffer (gnus-group-fetch-faq group))
7910 (gnus-configure-windows 'summary-faq))))
7911
7912 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7913 (defun gnus-summary-describe-group (&optional force)
7914 "Describe the current newsgroup."
7915 (interactive "P")
7916 (gnus-group-describe-group force gnus-newsgroup-name))
7917
7918 (defun gnus-summary-describe-briefly ()
7919 "Describe summary mode commands briefly."
7920 (interactive)
7921 (gnus-message 6
7922 (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")))
7923
7924 ;; Walking around group mode buffer from summary mode.
7925
7926 (defun gnus-summary-next-group (&optional no-article target-group backward)
7927 "Exit current newsgroup and then select next unread newsgroup.
7928 If prefix argument NO-ARTICLE is non-nil, no article is selected
7929 initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
7930 previous group instead."
7931 (interactive "P")
7932 (gnus-set-global-variables)
7933 (let ((current-group gnus-newsgroup-name)
7934 (current-buffer (current-buffer))
7935 entered)
7936 ;; First we semi-exit this group to update Xrefs and all variables.
7937 ;; We can't do a real exit, because the window conf must remain
7938 ;; the same in case the user is prompted for info, and we don't
7939 ;; want the window conf to change before that...
7940 (gnus-summary-exit t)
7941 (while (not entered)
7942 ;; Then we find what group we are supposed to enter.
7943 (set-buffer gnus-group-buffer)
7944 (gnus-group-jump-to-group current-group)
7945 (setq target-group
7946 (or target-group
7947 (if (eq gnus-keep-same-level 'best)
7948 (gnus-summary-best-group gnus-newsgroup-name)
7949 (gnus-summary-search-group backward gnus-keep-same-level))))
7950 (if (not target-group)
7951 ;; There are no further groups, so we return to the group
7952 ;; buffer.
7953 (progn
7954 (gnus-message 5 "Returning to the group buffer")
7955 (setq entered t)
7956 (set-buffer current-buffer)
7957 (gnus-summary-exit))
7958 ;; We try to enter the target group.
7959 (gnus-group-jump-to-group target-group)
7960 (let ((unreads (gnus-group-group-unread)))
7961 (if (and (or (eq t unreads)
7962 (and unreads (not (zerop unreads))))
7963 (gnus-summary-read-group
7964 target-group nil no-article current-buffer))
7965 (setq entered t)
7966 (setq current-group target-group
7967 target-group nil)))))))
7968
7969 (defun gnus-summary-next-group-old (&optional no-article group backward)
7970 "Exit current newsgroup and then select next unread newsgroup.
7971 If prefix argument NO-ARTICLE is non-nil, no article is selected initially.
7972 If BACKWARD, go to previous group instead."
7973 (interactive "P")
7974 (gnus-set-global-variables)
7975 (let ((ingroup gnus-newsgroup-name)
7976 (sumbuf (current-buffer))
7977 num)
7978 (set-buffer gnus-group-buffer)
7979 (if (and group
7980 (or (and (numberp (setq num (car (gnus-gethash
7981 group gnus-newsrc-hashtb))))
7982 (< num 1))
7983 (null num)))
7984 (progn
7985 (gnus-group-jump-to-group group)
7986 (setq group nil))
7987 (gnus-group-jump-to-group ingroup))
7988 (gnus-summary-search-group backward)
7989 (let ((group (or group (gnus-summary-search-group backward))))
7990 (set-buffer sumbuf)
7991 (gnus-summary-exit t) ;Update all information.
7992 (if (null group)
7993 (gnus-summary-exit-no-update t)
7994 (gnus-group-jump-to-group ingroup)
7995 (setq group (gnus-summary-search-group backward))
7996 (gnus-message 5 "Selecting %s..." group)
7997 (set-buffer gnus-group-buffer)
7998 ;; We are now in group mode buffer.
7999 ;; Make sure group mode buffer point is on GROUP.
8000 (gnus-group-jump-to-group group)
8001 (if (not (eq gnus-auto-select-next 'quietly))
8002 (progn
8003 (gnus-summary-read-group group nil no-article sumbuf)
8004 (and (string= gnus-newsgroup-name ingroup)
8005 (bufferp sumbuf) (buffer-name sumbuf)
8006 (progn
8007 (set-buffer (setq gnus-summary-buffer sumbuf))
8008 (gnus-summary-exit-no-update t))))
8009 (let ((prevgroup group))
8010 (gnus-group-jump-to-group ingroup)
8011 (setq group (gnus-summary-search-group backward))
8012 (gnus-summary-read-group group nil no-article sumbuf)
8013 (while (and (string= gnus-newsgroup-name ingroup)
8014 (bufferp sumbuf)
8015 (buffer-name sumbuf)
8016 (not (string= prevgroup (gnus-group-group-name))))
8017 (set-buffer gnus-group-buffer)
8018 (gnus-summary-read-group
8019 (setq prevgroup (gnus-group-group-name))
8020 nil no-article sumbuf))
8021 (and (string= prevgroup (gnus-group-group-name))
8022 ;; We have reached the final group in the group
8023 ;; buffer.
8024 (progn
8025 (if (buffer-name sumbuf)
8026 (progn
8027 (set-buffer sumbuf)
8028 (gnus-summary-exit)))))))))))
8029
8030 (defun gnus-summary-prev-group (&optional no-article)
8031 "Exit current newsgroup and then select previous unread newsgroup.
8032 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
8033 (interactive "P")
8034 (gnus-summary-next-group no-article nil t))
8035
8036 ;; Walking around summary lines.
8037
8038 (defun gnus-summary-first-subject (&optional unread)
8039 "Go to the first unread subject.
8040 If UNREAD is non-nil, go to the first unread article.
8041 Returns nil if there are no unread articles."
8042 (interactive "P")
8043 (prog1
8044 (cond ((not unread)
8045 (goto-char (point-min)))
8046 ((gnus-goto-char
8047 (text-property-any
8048 (point-min) (point-max) 'gnus-mark gnus-unread-mark))
8049 t)
8050 (t
8051 ;; There are no unread articles.
8052 (gnus-message 3 "No more unread articles")
8053 nil))
8054 (gnus-summary-position-cursor)))
8055
8056 (defun gnus-summary-next-subject (n &optional unread dont-display)
8057 "Go to next N'th summary line.
8058 If N is negative, go to the previous N'th subject line.
8059 If UNREAD is non-nil, only unread articles are selected.
8060 The difference between N and the actual number of steps taken is
8061 returned."
8062 (interactive "p")
8063 (let ((backward (< n 0))
8064 (n (abs n)))
8065 (while (and (> n 0)
8066 (gnus-summary-search-forward unread nil backward))
8067 (setq n (1- n)))
8068 (if (/= 0 n) (gnus-message 7 "No more%s articles"
8069 (if unread " unread" "")))
8070 (or dont-display
8071 (progn
8072 (gnus-summary-recenter)
8073 (gnus-summary-position-cursor)))
8074 n))
8075
8076 (defun gnus-summary-next-unread-subject (n)
8077 "Go to next N'th unread summary line."
8078 (interactive "p")
8079 (gnus-summary-next-subject n t))
8080
8081 (defun gnus-summary-prev-subject (n &optional unread)
8082 "Go to previous N'th summary line.
8083 If optional argument UNREAD is non-nil, only unread article is selected."
8084 (interactive "p")
8085 (gnus-summary-next-subject (- n) unread))
8086
8087 (defun gnus-summary-prev-unread-subject (n)
8088 "Go to previous N'th unread summary line."
8089 (interactive "p")
8090 (gnus-summary-next-subject (- n) t))
8091
8092 (defun gnus-summary-goto-subject (article)
8093 "Go the subject line of ARTICLE."
8094 (interactive
8095 (list
8096 (string-to-int
8097 (completing-read "Article number: "
8098 (mapcar
8099 (lambda (headers)
8100 (list
8101 (int-to-string (mail-header-number headers))))
8102 gnus-newsgroup-headers)
8103 nil 'require-match))))
8104 (or article (error "No article number"))
8105 (let ((b (point)))
8106 (if (not (gnus-goto-char (text-property-any (point-min) (point-max)
8107 'gnus-number article)))
8108 ()
8109 (gnus-summary-show-thread)
8110 ;; Skip dummy articles.
8111 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8112 (forward-line 1))
8113 (prog1
8114 (if (not (eobp))
8115 article
8116 (goto-char b)
8117 nil)
8118 (gnus-summary-position-cursor)))))
8119
8120 ;; Walking around summary lines with displaying articles.
8121
8122 (defun gnus-summary-expand-window (&optional arg)
8123 "Make the summary buffer take up the entire Emacs frame.
8124 Given a prefix, will force an `article' buffer configuration."
8125 (interactive "P")
8126 (gnus-set-global-variables)
8127 (if arg
8128 (gnus-configure-windows 'article 'force)
8129 (gnus-configure-windows 'summary 'force)))
8130
8131 (defun gnus-summary-display-article (article &optional all-header)
8132 "Display ARTICLE in article buffer."
8133 (gnus-set-global-variables)
8134 (if (null article)
8135 nil
8136 (prog1
8137 (gnus-article-prepare article all-header)
8138 (gnus-summary-show-thread)
8139 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8140 (progn
8141 (forward-line 1)
8142 (gnus-summary-position-cursor)))
8143 (run-hooks 'gnus-select-article-hook)
8144 (gnus-summary-recenter)
8145 (gnus-summary-goto-subject article)
8146 ;; Successfully display article.
8147 (gnus-summary-update-line)
8148 (gnus-article-set-window-start
8149 (cdr (assq article gnus-newsgroup-bookmarks)))
8150 t)))
8151
8152 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
8153 "Select the current article.
8154 If ALL-HEADERS is non-nil, show all header fields. If FORCE is
8155 non-nil, the article will be re-fetched even if it already present in
8156 the article buffer. If PSEUDO is non-nil, pseudo-articles will also
8157 be displayed."
8158 (and (not pseudo) (gnus-summary-pseudo-article)
8159 (error "This is a pseudo-article."))
8160 (let ((article (or article (gnus-summary-article-number)))
8161 (all-headers (not (not all-headers))) ;Must be T or NIL.
8162 did)
8163 (prog1
8164 (save-excursion
8165 (set-buffer gnus-summary-buffer)
8166 (if (or (null gnus-current-article)
8167 (null gnus-article-current)
8168 (null (get-buffer gnus-article-buffer))
8169 (not (eq article (cdr gnus-article-current)))
8170 (not (equal (car gnus-article-current) gnus-newsgroup-name))
8171 force)
8172 ;; The requested article is different from the current article.
8173 (progn
8174 (gnus-summary-display-article article all-headers)
8175 (setq did article))
8176 (if (or all-headers gnus-show-all-headers)
8177 (gnus-article-show-all-headers))
8178 nil))
8179 (if did
8180 (gnus-article-set-window-start
8181 (cdr (assq article gnus-newsgroup-bookmarks)))))))
8182
8183 (defun gnus-summary-set-current-mark (&optional current-mark)
8184 "Obsolete function."
8185 nil)
8186
8187 (defun gnus-summary-next-article (&optional unread subject backward)
8188 "Select the next article.
8189 If UNREAD, only unread articles are selected.
8190 If SUBJECT, only articles with SUBJECT are selected.
8191 If BACKWARD, the previous article is selected instead of the next."
8192 (interactive "P")
8193 (gnus-set-global-variables)
8194 (let (header)
8195 (cond
8196 ;; Is there such an article?
8197 ((and (gnus-summary-search-forward unread subject backward)
8198 (or (gnus-summary-display-article (gnus-summary-article-number))
8199 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8200 (gnus-summary-position-cursor))
8201 ;; If not, we try the first unread, if that is wanted.
8202 ((and subject
8203 gnus-auto-select-same
8204 (or (gnus-summary-first-unread-article)
8205 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8206 (gnus-summary-position-cursor)
8207 (gnus-message 6 "Wrapped"))
8208 ;; Try to get next/previous article not displayed in this group.
8209 ((and gnus-auto-extend-newsgroup
8210 (not unread) (not subject)
8211 (setq header (gnus-more-header-forward backward)))
8212 (gnus-extend-newsgroup header backward)
8213 (let ((buffer-read-only nil))
8214 (goto-char (if backward (point-min) (point-max)))
8215 (gnus-summary-prepare-threads (list header)))
8216 (gnus-summary-goto-article (if backward gnus-newsgroup-begin
8217 gnus-newsgroup-end)))
8218 ;; Go to next/previous group.
8219 (t
8220 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
8221 (gnus-summary-jump-to-group gnus-newsgroup-name))
8222 (let ((cmd last-command-char)
8223 (group
8224 (if (eq gnus-keep-same-level 'best)
8225 (gnus-summary-best-group gnus-newsgroup-name)
8226 (gnus-summary-search-group backward gnus-keep-same-level))))
8227 ;; For some reason, the group window gets selected. We change
8228 ;; it back.
8229 (select-window (get-buffer-window (current-buffer)))
8230 ;; Keep just the event type of CMD.
8231 ;(and (listp cmd) (setq cmd (car cmd)))
8232 ;; Select next unread newsgroup automagically.
8233 (cond
8234 ((not gnus-auto-select-next)
8235 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
8236 ((eq gnus-auto-select-next 'quietly)
8237 ;; Select quietly.
8238 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
8239 (gnus-summary-exit)
8240 (gnus-message 7 "No more%s articles (%s)..."
8241 (if unread " unread" "")
8242 (if group (concat "selecting " group)
8243 "exiting"))
8244 (gnus-summary-next-group nil group backward)))
8245 (t
8246 (let ((keystrokes '(?\C-n ?\C-p))
8247 key)
8248 (while (or (null key) (memq key keystrokes))
8249 (gnus-message
8250 7 "No more%s articles%s" (if unread " unread" "")
8251 (if (and group
8252 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
8253 (format " (Type %s for %s [%s])"
8254 (single-key-description cmd) group
8255 (car (gnus-gethash group gnus-newsrc-hashtb)))
8256 (format " (Type %s to exit %s)"
8257 (single-key-description cmd)
8258 gnus-newsgroup-name)))
8259 ;; Confirm auto selection.
8260 (let* ((event (read-char)))
8261 (setq key (if (listp event) (car event) event))
8262 (if (memq key keystrokes)
8263 (let ((obuf (current-buffer)))
8264 (switch-to-buffer gnus-group-buffer)
8265 (and group
8266 (gnus-group-jump-to-group group))
8267 (condition-case ()
8268 (execute-kbd-macro (char-to-string key))
8269 (error (ding) nil))
8270 (setq group (gnus-group-group-name))
8271 (switch-to-buffer obuf)))))
8272 (if (equal key cmd)
8273 (if (or (not group)
8274 (gnus-ephemeral-group-p gnus-newsgroup-name))
8275 (gnus-summary-exit)
8276 (gnus-summary-next-group nil group backward))
8277 (execute-kbd-macro (char-to-string key)))))))))))
8278
8279 (defun gnus-summary-next-unread-article ()
8280 "Select unread article after current one."
8281 (interactive)
8282 (gnus-summary-next-article t (and gnus-auto-select-same
8283 (gnus-summary-subject-string))))
8284
8285 (defun gnus-summary-prev-article (&optional unread subject)
8286 "Select the article after the current one.
8287 If UNREAD is non-nil, only unread articles are selected."
8288 (interactive "P")
8289 (gnus-summary-next-article unread subject t))
8290
8291 (defun gnus-summary-prev-unread-article ()
8292 "Select unred article before current one."
8293 (interactive)
8294 (gnus-summary-prev-article t (and gnus-auto-select-same
8295 (gnus-summary-subject-string))))
8296
8297 (defun gnus-summary-next-page (&optional lines circular)
8298 "Show next page of selected article.
8299 If end of article, select next article.
8300 Argument LINES specifies lines to be scrolled up.
8301 If CIRCULAR is non-nil, go to the start of the article instead of
8302 instead of selecting the next article when reaching the end of the
8303 current article."
8304 (interactive "P")
8305 (setq gnus-summary-buffer (current-buffer))
8306 (gnus-set-global-variables)
8307 (let ((article (gnus-summary-article-number))
8308 (endp nil))
8309 (gnus-configure-windows 'article)
8310 (if (or (null gnus-current-article)
8311 (null gnus-article-current)
8312 (/= article (cdr gnus-article-current))
8313 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8314 ;; Selected subject is different from current article's.
8315 (gnus-summary-display-article article)
8316 (gnus-eval-in-buffer-window
8317 gnus-article-buffer
8318 (setq endp (gnus-article-next-page lines)))
8319 (if endp
8320 (cond (circular
8321 (gnus-summary-beginning-of-article))
8322 (lines
8323 (gnus-message 3 "End of message"))
8324 ((null lines)
8325 (gnus-summary-next-unread-article)))))
8326 (gnus-summary-recenter)
8327 (gnus-summary-position-cursor)))
8328
8329 (defun gnus-summary-prev-page (&optional lines)
8330 "Show previous page of selected article.
8331 Argument LINES specifies lines to be scrolled down."
8332 (interactive "P")
8333 (gnus-set-global-variables)
8334 (let ((article (gnus-summary-article-number)))
8335 (gnus-configure-windows 'article)
8336 (if (or (null gnus-current-article)
8337 (null gnus-article-current)
8338 (/= article (cdr gnus-article-current))
8339 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8340 ;; Selected subject is different from current article's.
8341 (gnus-summary-display-article article)
8342 (gnus-summary-recenter)
8343 (gnus-eval-in-buffer-window gnus-article-buffer
8344 (gnus-article-prev-page lines))))
8345 (gnus-summary-position-cursor))
8346
8347 (defun gnus-summary-scroll-up (lines)
8348 "Scroll up (or down) one line current article.
8349 Argument LINES specifies lines to be scrolled up (or down if negative)."
8350 (interactive "p")
8351 (gnus-set-global-variables)
8352 (gnus-configure-windows 'article)
8353 (or (gnus-summary-select-article nil nil 'pseudo)
8354 (gnus-eval-in-buffer-window
8355 gnus-article-buffer
8356 (cond ((> lines 0)
8357 (if (gnus-article-next-page lines)
8358 (gnus-message 3 "End of message")))
8359 ((< lines 0)
8360 (gnus-article-prev-page (- lines))))))
8361 (gnus-summary-recenter)
8362 (gnus-summary-position-cursor))
8363
8364 (defun gnus-summary-next-same-subject ()
8365 "Select next article which has the same subject as current one."
8366 (interactive)
8367 (gnus-set-global-variables)
8368 (gnus-summary-next-article nil (gnus-summary-subject-string)))
8369
8370 (defun gnus-summary-prev-same-subject ()
8371 "Select previous article which has the same subject as current one."
8372 (interactive)
8373 (gnus-set-global-variables)
8374 (gnus-summary-prev-article nil (gnus-summary-subject-string)))
8375
8376 (defun gnus-summary-next-unread-same-subject ()
8377 "Select next unread article which has the same subject as current one."
8378 (interactive)
8379 (gnus-set-global-variables)
8380 (gnus-summary-next-article t (gnus-summary-subject-string)))
8381
8382 (defun gnus-summary-prev-unread-same-subject ()
8383 "Select previous unread article which has the same subject as current one."
8384 (interactive)
8385 (gnus-set-global-variables)
8386 (gnus-summary-prev-article t (gnus-summary-subject-string)))
8387
8388 (defun gnus-summary-first-unread-article ()
8389 "Select the first unread article.
8390 Return nil if there are no unread articles."
8391 (interactive)
8392 (gnus-set-global-variables)
8393 (prog1
8394 (if (gnus-summary-first-subject t)
8395 (progn
8396 (gnus-summary-show-thread)
8397 (gnus-summary-first-subject t)
8398 (gnus-summary-display-article (gnus-summary-article-number))))
8399 (gnus-summary-position-cursor)))
8400
8401 (defun gnus-summary-best-unread-article ()
8402 "Select the unread article with the highest score."
8403 (interactive)
8404 (gnus-set-global-variables)
8405 (let ((best -1000000)
8406 article score)
8407 (save-excursion
8408 (or (gnus-summary-first-subject t)
8409 (error "No unread articles"))
8410 (while
8411 (and
8412 (progn
8413 (and (> (setq score (gnus-summary-article-score)) best)
8414 (setq best score
8415 article (gnus-summary-article-number)))
8416 t)
8417 (gnus-summary-search-subject nil t))))
8418 (if (not article)
8419 (error "No unread articles")
8420 (gnus-summary-goto-article article))
8421 (gnus-summary-position-cursor)))
8422
8423 (defun gnus-summary-goto-article (article &optional all-headers)
8424 "Fetch ARTICLE and display it if it exists.
8425 If ALL-HEADERS is non-nil, no header lines are hidden."
8426 (interactive
8427 (list
8428 (string-to-int
8429 (completing-read
8430 "Article number: "
8431 (mapcar (lambda (headers)
8432 (list (int-to-string (mail-header-number headers))))
8433 gnus-newsgroup-headers)
8434 nil 'require-match))))
8435 (prog1
8436 (and (gnus-summary-goto-subject article)
8437 (gnus-summary-display-article article all-headers))
8438 (gnus-summary-position-cursor)))
8439
8440 (defun gnus-summary-goto-last-article ()
8441 "Go to the previously read article."
8442 (interactive)
8443 (prog1
8444 (and gnus-last-article
8445 (gnus-summary-goto-article gnus-last-article))
8446 (gnus-summary-position-cursor)))
8447
8448 (defun gnus-summary-pop-article (number)
8449 "Pop one article off the history and go to the previous.
8450 NUMBER articles will be popped off."
8451 (interactive "p")
8452 (let (to)
8453 (setq gnus-newsgroup-history
8454 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8455 (if to
8456 (gnus-summary-goto-article (car to))
8457 (error "Article history empty")))
8458 (gnus-summary-position-cursor))
8459
8460 ;; Summary article oriented commands
8461
8462 (defun gnus-summary-refer-parent-article (n)
8463 "Refer parent article N times.
8464 The difference between N and the number of articles fetched is returned."
8465 (interactive "p")
8466 (gnus-set-global-variables)
8467 (while
8468 (and
8469 (> n 0)
8470 (let ((ref (mail-header-references (gnus-get-header-by-num
8471 (gnus-summary-article-number)))))
8472 (if (and ref (not (equal ref ""))
8473 (string-match "<[^<>]*>[ \t]*$" ref))
8474 (gnus-summary-refer-article
8475 (substring ref (match-beginning 0) (match-end 0)))
8476 (gnus-message 1 "No references in article %d"
8477 (gnus-summary-article-number))
8478 nil)))
8479 (setq n (1- n)))
8480 (gnus-summary-position-cursor)
8481 n)
8482
8483 (defun gnus-summary-refer-article (message-id)
8484 "Refer article specified by MESSAGE-ID.
8485 NOTE: This command only works with newsgroups that use real or simulated NNTP."
8486 (interactive "sMessage-ID: ")
8487 (if (or (not (stringp message-id))
8488 (zerop (length message-id)))
8489 ()
8490 ;; Construct the correct Message-ID if necessary.
8491 ;; Suggested by tale@pawl.rpi.edu.
8492 (or (string-match "^<" message-id)
8493 (setq message-id (concat "<" message-id)))
8494 (or (string-match ">$" message-id)
8495 (setq message-id (concat message-id ">")))
8496 (let ((header (car (gnus-gethash (downcase message-id)
8497 gnus-newsgroup-dependencies))))
8498 (if header
8499 (or (gnus-summary-goto-article (mail-header-number header))
8500 ;; The header has been read, but the article had been
8501 ;; expunged, so we insert it again.
8502 (progn
8503 (gnus-summary-insert-line
8504 nil header 0 nil gnus-read-mark nil nil
8505 (mail-header-subject header))
8506 (forward-line -1)
8507 (mail-header-number header)))
8508 (let ((gnus-override-method gnus-refer-article-method)
8509 (gnus-ancient-mark gnus-read-mark)
8510 (tmp-point (window-start
8511 (get-buffer-window gnus-article-buffer)))
8512 number tmp-buf)
8513 (and gnus-refer-article-method
8514 (gnus-check-server gnus-refer-article-method))
8515 ;; Save the old article buffer.
8516 (save-excursion
8517 (set-buffer (gnus-article-setup-buffer))
8518 (gnus-kill-buffer " *temp Article*")
8519 (setq tmp-buf (rename-buffer " *temp Article*")))
8520 (prog1
8521 (if (gnus-article-prepare
8522 message-id nil (gnus-read-header message-id))
8523 (progn
8524 (setq number (mail-header-number gnus-current-headers))
8525 (gnus-rebuild-thread message-id)
8526 (gnus-summary-goto-subject number)
8527 (if (null gnus-use-full-window)
8528 (progn
8529 (delete-windows-on tmp-buf)
8530 (gnus-configure-windows 'article 'force)))
8531 (gnus-summary-recenter)
8532 (gnus-article-set-window-start
8533 (cdr (assq number gnus-newsgroup-bookmarks)))
8534 (and gnus-visual
8535 (run-hooks 'gnus-visual-mark-article-hook))
8536 message-id)
8537 ;; We restore the old article buffer.
8538 (save-excursion
8539 (kill-buffer gnus-article-buffer)
8540 (set-buffer tmp-buf)
8541 (rename-buffer gnus-article-buffer)
8542 (let ((buffer-read-only nil))
8543 (and tmp-point
8544 (set-window-start (get-buffer-window (current-buffer))
8545 tmp-point)))))))))))
8546
8547 (defun gnus-summary-enter-digest-group ()
8548 "Enter a digest group based on the current article."
8549 (interactive)
8550 (gnus-set-global-variables)
8551 (gnus-summary-select-article)
8552 ;; We do not want a narrowed article.
8553 (gnus-summary-stop-page-breaking)
8554 (let ((name (format "%s-%d"
8555 (gnus-group-prefixed-name
8556 gnus-newsgroup-name (list 'nndoc ""))
8557 gnus-current-article))
8558 (ogroup gnus-newsgroup-name)
8559 (buf (current-buffer)))
8560 (if (gnus-group-read-ephemeral-group
8561 name (list 'nndoc name
8562 (list 'nndoc-address (get-buffer gnus-article-buffer))
8563 '(nndoc-article-type digest))
8564 t)
8565 (setcdr (nthcdr 4 (nth 2 (gnus-gethash name gnus-newsrc-hashtb)))
8566 (list (list (cons 'to-group ogroup))))
8567 (switch-to-buffer buf)
8568 (gnus-set-global-variables)
8569 (gnus-configure-windows 'summary)
8570 (gnus-message 3 "Article not a digest?"))))
8571
8572 (defun gnus-summary-isearch-article ()
8573 "Do incremental search forward on current article."
8574 (interactive)
8575 (gnus-set-global-variables)
8576 (gnus-summary-select-article)
8577 (gnus-eval-in-buffer-window
8578 gnus-article-buffer (isearch-forward)))
8579
8580 (defun gnus-summary-search-article-forward (regexp &optional backward)
8581 "Search for an article containing REGEXP forward.
8582 If BACKWARD, search backward instead."
8583 (interactive
8584 (list (read-string
8585 (format "Search article %s (regexp%s): "
8586 (if current-prefix-arg "backward" "forward")
8587 (if gnus-last-search-regexp
8588 (concat ", default " gnus-last-search-regexp)
8589 "")))
8590 current-prefix-arg))
8591 (gnus-set-global-variables)
8592 (if (string-equal regexp "")
8593 (setq regexp (or gnus-last-search-regexp ""))
8594 (setq gnus-last-search-regexp regexp))
8595 (if (gnus-summary-search-article regexp backward)
8596 (gnus-article-set-window-start
8597 (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks)))
8598 (error "Search failed: \"%s\"" regexp)))
8599
8600 (defun gnus-summary-search-article-backward (regexp)
8601 "Search for an article containing REGEXP backward."
8602 (interactive
8603 (list (read-string
8604 (format "Search article backward (regexp%s): "
8605 (if gnus-last-search-regexp
8606 (concat ", default " gnus-last-search-regexp)
8607 "")))))
8608 (gnus-summary-search-article-forward regexp 'backward))
8609
8610 (defun gnus-summary-search-article (regexp &optional backward)
8611 "Search for an article containing REGEXP.
8612 Optional argument BACKWARD means do search for backward.
8613 gnus-select-article-hook is not called during the search."
8614 (let ((gnus-select-article-hook nil) ;Disable hook.
8615 (gnus-mark-article-hook nil) ;Inhibit marking as read.
8616 (re-search
8617 (if backward
8618 (function re-search-backward) (function re-search-forward)))
8619 (found nil)
8620 (last nil))
8621 ;; Hidden thread subtrees must be searched for ,too.
8622 (gnus-summary-show-all-threads)
8623 (if (eobp) (forward-line -1))
8624 ;; First of all, search current article.
8625 ;; We don't want to read article again from NNTP server nor reset
8626 ;; current point.
8627 (gnus-summary-select-article)
8628 (gnus-message 9 "Searching article: %d..." gnus-current-article)
8629 (setq last gnus-current-article)
8630 (gnus-eval-in-buffer-window
8631 gnus-article-buffer
8632 (save-restriction
8633 (widen)
8634 ;; Begin search from current point.
8635 (setq found (funcall re-search regexp nil t))))
8636 ;; Then search next articles.
8637 (while (and (not found)
8638 (gnus-summary-display-article
8639 (gnus-summary-search-subject backward nil nil)))
8640 (gnus-message 9 "Searching article: %d..." gnus-current-article)
8641 (gnus-eval-in-buffer-window
8642 gnus-article-buffer
8643 (save-restriction
8644 (widen)
8645 (goto-char (if backward (point-max) (point-min)))
8646 (setq found (funcall re-search regexp nil t)))))
8647 (message "")
8648 ;; Adjust article pointer.
8649 (or (eq last gnus-current-article)
8650 (setq gnus-last-article last))
8651 ;; Return T if found such article.
8652 found))
8653
8654 (defun gnus-summary-execute-command (header regexp command &optional backward)
8655 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8656 If HEADER is an empty string (or nil), the match is done on the entire
8657 article. If BACKWARD (the prefix) is non-nil, search backward instead."
8658 (interactive
8659 (list (let ((completion-ignore-case t))
8660 (completing-read
8661 "Header name: "
8662 (mapcar (lambda (string) (list string))
8663 '("Number" "Subject" "From" "Lines" "Date"
8664 "Message-ID" "Xref" "References"))
8665 nil 'require-match))
8666 (read-string "Regexp: ")
8667 (read-key-sequence "Command: ")
8668 current-prefix-arg))
8669 (gnus-set-global-variables)
8670 ;; Hidden thread subtrees must be searched as well.
8671 (gnus-summary-show-all-threads)
8672 ;; We don't want to change current point nor window configuration.
8673 (save-excursion
8674 (save-window-excursion
8675 (gnus-message 6 "Executing %s..." (key-description command))
8676 ;; We'd like to execute COMMAND interactively so as to give arguments.
8677 (gnus-execute header regexp
8678 (` (lambda ()
8679 (call-interactively '(, (key-binding command)))))
8680 backward)
8681 (gnus-message 6 "Executing %s...done" (key-description command)))))
8682
8683 (defun gnus-summary-beginning-of-article ()
8684 "Scroll the article back to the beginning."
8685 (interactive)
8686 (gnus-set-global-variables)
8687 (gnus-summary-select-article)
8688 (gnus-configure-windows 'article)
8689 (gnus-eval-in-buffer-window
8690 gnus-article-buffer
8691 (widen)
8692 (goto-char (point-min))
8693 (and gnus-break-pages (gnus-narrow-to-page))))
8694
8695 (defun gnus-summary-end-of-article ()
8696 "Scroll to the end of the article."
8697 (interactive)
8698 (gnus-set-global-variables)
8699 (gnus-summary-select-article)
8700 (gnus-configure-windows 'article)
8701 (gnus-eval-in-buffer-window
8702 gnus-article-buffer
8703 (widen)
8704 (goto-char (point-max))
8705 (recenter -3)
8706 (and gnus-break-pages (gnus-narrow-to-page))))
8707
8708 (defun gnus-summary-show-article ()
8709 "Force re-fetching of the current article."
8710 (interactive)
8711 (gnus-set-global-variables)
8712 (gnus-summary-select-article nil 'force)
8713 (gnus-configure-windows 'article)
8714 (gnus-summary-position-cursor))
8715
8716 (defun gnus-summary-verbose-headers (&optional arg)
8717 "Toggle permanent full header display.
8718 If ARG is a positive number, turn header display on.
8719 If ARG is a negative number, turn header display off."
8720 (interactive "P")
8721 (gnus-set-global-variables)
8722 (gnus-summary-toggle-header arg)
8723 (setq gnus-show-all-headers
8724 (cond ((or (not (numberp arg))
8725 (zerop arg))
8726 (not gnus-show-all-headers))
8727 ((natnump arg)
8728 t))))
8729
8730 (defun gnus-summary-toggle-header (&optional arg)
8731 "Show the headers if they are hidden, or hide them if they are shown.
8732 If ARG is a positive number, show the entire header.
8733 If ARG is a negative number, hide the unwanted header lines."
8734 (interactive "P")
8735 (gnus-set-global-variables)
8736 (save-excursion
8737 (set-buffer gnus-article-buffer)
8738 (let ((buffer-read-only nil))
8739 (if (numberp arg)
8740 (if (> arg 0) (remove-text-properties (point-min) (point-max)
8741 gnus-hidden-properties)
8742 (if (< arg 0) (run-hooks 'gnus-article-display-hook)))
8743 (if (text-property-any (point-min) (point-max) 'invisible t)
8744 (remove-text-properties
8745 (point-min) (point-max) gnus-hidden-properties)
8746 ;; We hide the headers. This song and dance act below is
8747 ;; done because `gnus-have-all-headers' is buffer-local to
8748 ;; the summary buffer, and we only want to temporarily
8749 ;; change it in that buffer. Ugh.
8750 (let ((have gnus-have-all-headers))
8751 (save-excursion
8752 (set-buffer gnus-summary-buffer)
8753 (setq gnus-have-all-headers nil)
8754 (save-excursion
8755 (set-buffer gnus-article-buffer)
8756 (run-hooks 'gnus-article-display-hook))
8757 (setq gnus-have-all-headers have)))))
8758 (set-window-point (get-buffer-window (current-buffer)) (point-min)))))
8759
8760 (defun gnus-summary-show-all-headers ()
8761 "Make all header lines visible."
8762 (interactive)
8763 (gnus-set-global-variables)
8764 (gnus-article-show-all-headers))
8765
8766 (defun gnus-summary-toggle-mime (&optional arg)
8767 "Toggle MIME processing.
8768 If ARG is a positive number, turn MIME processing on."
8769 (interactive "P")
8770 (gnus-set-global-variables)
8771 (setq gnus-show-mime
8772 (if (null arg) (not gnus-show-mime)
8773 (> (prefix-numeric-value arg) 0)))
8774 (gnus-summary-select-article t 'force))
8775
8776 (defun gnus-summary-caesar-message (&optional arg)
8777 "Caesar rotate the current article by 13.
8778 The numerical prefix specifies how manu places to rotate each letter
8779 forward."
8780 (interactive "P")
8781 (gnus-set-global-variables)
8782 (gnus-summary-select-article)
8783 (let ((mail-header-separator ""))
8784 (gnus-eval-in-buffer-window
8785 gnus-article-buffer
8786 (save-restriction
8787 (widen)
8788 (let ((start (window-start)))
8789 (news-caesar-buffer-body arg)
8790 (set-window-start (get-buffer-window (current-buffer)) start))))))
8791
8792 (defun gnus-summary-stop-page-breaking ()
8793 "Stop page breaking in the current article."
8794 (interactive)
8795 (gnus-set-global-variables)
8796 (gnus-summary-select-article)
8797 (gnus-eval-in-buffer-window gnus-article-buffer (widen)))
8798
8799 ;; Suggested by Brian Edmonds <bedmonds@prodigy.bc.ca>.
8800
8801 (defun gnus-summary-move-article (&optional n to-newsgroup select-method)
8802 "Move the current article to a different newsgroup.
8803 If N is a positive number, move the N next articles.
8804 If N is a negative number, move the N previous articles.
8805 If N is nil and any articles have been marked with the process mark,
8806 move those articles instead.
8807 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8808 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8809 re-spool using this method.
8810 For this function to work, both the current newsgroup and the
8811 newsgroup that you want to move to have to support the `request-move'
8812 and `request-accept' functions. (Ie. mail newsgroups at present.)"
8813 (interactive "P")
8814 (gnus-set-global-variables)
8815 (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name)
8816 (error "The current newsgroup does not support article moving"))
8817 (let ((articles (gnus-summary-work-articles n))
8818 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8819 art-group to-method sel-met)
8820 (if (and (not to-newsgroup) (not select-method))
8821 (setq to-newsgroup
8822 (completing-read
8823 (format "Where do you want to move %s? %s"
8824 (if (> (length articles) 1)
8825 (format "these %d articles" (length articles))
8826 "this article")
8827 (if gnus-current-move-group
8828 (format "(%s default) " gnus-current-move-group)
8829 ""))
8830 gnus-active-hashtb nil nil prefix)))
8831 (if to-newsgroup
8832 (progn
8833 (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8834 (setq to-newsgroup (or gnus-current-move-group "")))
8835 (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8836 (gnus-activate-group to-newsgroup)
8837 (error "No such group: %s" to-newsgroup))
8838 (setq gnus-current-move-group to-newsgroup)))
8839 (setq to-method (if select-method (list select-method "")
8840 (gnus-find-method-for-group to-newsgroup)))
8841 (or (gnus-check-backend-function 'request-accept-article (car to-method))
8842 (error "%s does not support article copying" (car to-method)))
8843 (or (gnus-check-server to-method)
8844 (error "Can't open server %s" (car to-method)))
8845 (gnus-message 6 "Moving to %s: %s..."
8846 (or select-method to-newsgroup) articles)
8847 (while articles
8848 (if (setq art-group
8849 (gnus-request-move-article
8850 (car articles) ; Article to move
8851 gnus-newsgroup-name ; From newsgroup
8852 (nth 1 (gnus-find-method-for-group
8853 gnus-newsgroup-name)) ; Server
8854 (list 'gnus-request-accept-article
8855 (if select-method
8856 (list 'quote select-method)
8857 to-newsgroup)
8858 (not (cdr articles))) ; Accept form
8859 (not (cdr articles)))) ; Only save nov last time
8860 (let* ((buffer-read-only nil)
8861 (entry
8862 (or
8863 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8864 (gnus-gethash
8865 (gnus-group-prefixed-name
8866 (car art-group)
8867 (if select-method (list select-method "")
8868 (gnus-find-method-for-group to-newsgroup)))
8869 gnus-newsrc-hashtb)))
8870 (info (nth 2 entry))
8871 (article (car articles)))
8872 (gnus-summary-goto-subject article)
8873 (beginning-of-line)
8874 (delete-region (point) (progn (forward-line 1) (point)))
8875 ;; Update the group that has been moved to.
8876 (if (not info)
8877 () ; This group does not exist yet.
8878 (if (not (memq article gnus-newsgroup-unreads))
8879 (setcar (cdr (cdr info))
8880 (gnus-add-to-range (nth 2 info)
8881 (list (cdr art-group)))))
8882 ;; Copy any marks over to the new group.
8883 (let ((marks '((tick . gnus-newsgroup-marked)
8884 (dormant . gnus-newsgroup-dormant)
8885 (expire . gnus-newsgroup-expirable)
8886 (bookmark . gnus-newsgroup-bookmarks)
8887 (reply . gnus-newsgroup-replied)))
8888 (to-article (cdr art-group)))
8889 (while marks
8890 (if (memq article (symbol-value (cdr (car marks))))
8891 (gnus-add-marked-articles
8892 (car info) (car (car marks)) (list to-article) info))
8893 (setq marks (cdr marks)))))
8894 ;; Update marks.
8895 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8896 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8897 (setq gnus-newsgroup-dormant
8898 (delq article gnus-newsgroup-dormant))
8899 (setq gnus-newsgroup-reads
8900 (cons (cons article gnus-canceled-mark)
8901 gnus-newsgroup-reads)))
8902 (gnus-message 1 "Couldn't move article %s" (car articles)))
8903 (gnus-summary-remove-process-mark (car articles))
8904 (setq articles (cdr articles)))
8905 (gnus-set-mode-line 'summary)))
8906
8907 (defun gnus-summary-respool-article (&optional n respool-method)
8908 "Respool the current article.
8909 The article will be squeezed through the mail spooling process again,
8910 which means that it will be put in some mail newsgroup or other
8911 depending on `nnmail-split-methods'.
8912 If N is a positive number, respool the N next articles.
8913 If N is a negative number, respool the N previous articles.
8914 If N is nil and any articles have been marked with the process mark,
8915 respool those articles instead.
8916
8917 Respooling can be done both from mail groups and \"real\" newsgroups.
8918 In the former case, the articles in question will be moved from the
8919 current group into whatever groups they are destined to. In the
8920 latter case, they will be copied into the relevant groups."
8921 (interactive "P")
8922 (gnus-set-global-variables)
8923 (let ((respool-methods (gnus-methods-using 'respool))
8924 (methname
8925 (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name)))))
8926 (or respool-method
8927 (setq respool-method
8928 (completing-read
8929 "What method do you want to use when respooling? "
8930 respool-methods nil t methname)))
8931 (or (string= respool-method "")
8932 (if (assoc (symbol-name
8933 (car (gnus-find-method-for-group gnus-newsgroup-name)))
8934 respool-methods)
8935 (gnus-summary-move-article n nil (intern respool-method))
8936 (gnus-summary-copy-article n nil (intern respool-method))))))
8937
8938 ;; Suggested by gregj@unidata.com (Gregory J. Grubbs).
8939 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8940 "Move the current article to a different newsgroup.
8941 If N is a positive number, move the N next articles.
8942 If N is a negative number, move the N previous articles.
8943 If N is nil and any articles have been marked with the process mark,
8944 move those articles instead.
8945 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8946 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8947 re-spool using this method.
8948 For this function to work, the newsgroup that you want to move to have
8949 to support the `request-move' and `request-accept'
8950 functions. (Ie. mail newsgroups at present.)"
8951 (interactive "P")
8952 (gnus-set-global-variables)
8953 (let ((articles (gnus-summary-work-articles n))
8954 (copy-buf (get-buffer-create "*copy work*"))
8955 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8956 art-group to-method)
8957 (buffer-disable-undo copy-buf)
8958 (if (and (not to-newsgroup) (not select-method))
8959 (setq to-newsgroup
8960 (completing-read
8961 (format "Where do you want to copy %s? %s"
8962 (if (> (length articles) 1)
8963 (format "these %d articles" (length articles))
8964 "this article")
8965 (if gnus-current-move-group
8966 (format "(%s default) " gnus-current-move-group)
8967 ""))
8968 gnus-active-hashtb nil nil prefix)))
8969 (if to-newsgroup
8970 (progn
8971 (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8972 (setq to-newsgroup (or gnus-current-move-group "")))
8973 (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8974 (gnus-activate-group to-newsgroup)
8975 (error "No such group: %s" to-newsgroup))
8976 (setq gnus-current-move-group to-newsgroup)))
8977 (setq to-method (if select-method (list select-method "")
8978 (gnus-find-method-for-group to-newsgroup)))
8979 (or (gnus-check-backend-function 'request-accept-article (car to-method))
8980 (error "%s does not support article copying" (car to-method)))
8981 (or (gnus-check-server to-method)
8982 (error "Can't open server %s" (car to-method)))
8983 (while articles
8984 (gnus-message 6 "Copying to %s: %s..."
8985 (or select-method to-newsgroup) articles)
8986 (if (setq art-group
8987 (save-excursion
8988 (set-buffer copy-buf)
8989 (gnus-request-article-this-buffer
8990 (car articles) gnus-newsgroup-name)
8991 (gnus-request-accept-article
8992 (if select-method (list 'quote select-method) to-newsgroup)
8993 (not (cdr articles)))))
8994 (let* ((entry
8995 (or
8996 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8997 (gnus-gethash
8998 (gnus-group-prefixed-name
8999 (car art-group)
9000 (if select-method (list select-method "")
9001 (gnus-find-method-for-group to-newsgroup)))
9002 gnus-newsrc-hashtb)))
9003 (info (nth 2 entry))
9004 (article (car articles)))
9005 ;; We copy the info over to the new group.
9006 (if (not info)
9007 () ; This group does not exist (yet).
9008 (if (not (memq article gnus-newsgroup-unreads))
9009 (setcar (cdr (cdr info))
9010 (gnus-add-to-range (nth 2 info)
9011 (list (cdr art-group)))))
9012 ;; Copy any marks over to the new group.
9013 (let ((marks '((tick . gnus-newsgroup-marked)
9014 (dormant . gnus-newsgroup-dormant)
9015 (expire . gnus-newsgroup-expirable)
9016 (bookmark . gnus-newsgroup-bookmarks)
9017 (reply . gnus-newsgroup-replied)))
9018 (to-article (cdr art-group)))
9019 (while marks
9020 (if (memq article (symbol-value (cdr (car marks))))
9021 (gnus-add-marked-articles
9022 (car info) (car (car marks)) (list to-article) info))
9023 (setq marks (cdr marks))))))
9024 (gnus-message 1 "Couldn't copy article %s" (car articles)))
9025 (gnus-summary-remove-process-mark (car articles))
9026 (setq articles (cdr articles)))
9027 (kill-buffer copy-buf)))
9028
9029 (defun gnus-summary-import-article (file)
9030 "Import a random file into a mail newsgroup."
9031 (interactive "fImport file: ")
9032 (let ((group gnus-newsgroup-name)
9033 atts)
9034 (or (gnus-check-backend-function 'request-accept-article group)
9035 (error "%s does not support article importing" group))
9036 (or (file-readable-p file)
9037 (not (file-regular-p file))
9038 (error "Can't read %s" file))
9039 (save-excursion
9040 (set-buffer (get-buffer-create " *import file*"))
9041 (buffer-disable-undo (current-buffer))
9042 (erase-buffer)
9043 (insert-file-contents file)
9044 (goto-char (point-min))
9045 (if (nnheader-article-p)
9046 ()
9047 (setq atts (file-attributes file))
9048 (insert "From: " (read-string "From: ") "\n"
9049 "Subject: " (read-string "Subject: ") "\n"
9050 "Date: " (current-time-string (nth 5 atts)) "\n"
9051 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9052 (gnus-request-accept-article group t)
9053 (kill-buffer (current-buffer)))))
9054
9055 (defun gnus-summary-expire-articles ()
9056 "Expire all articles that are marked as expirable in the current group."
9057 (interactive)
9058 (if (not (gnus-check-backend-function
9059 'request-expire-articles gnus-newsgroup-name))
9060 ()
9061 (let* ((info (nth 2 (gnus-gethash gnus-newsgroup-name
9062 gnus-newsrc-hashtb)))
9063 (total (memq 'total-expire (nth 5 info)))
9064 (expirable (if total
9065 (gnus-list-of-read-articles gnus-newsgroup-name)
9066 (setq gnus-newsgroup-expirable
9067 (sort gnus-newsgroup-expirable '<))))
9068 es)
9069 (if (not expirable)
9070 ()
9071 (gnus-message 6 "Expiring articles...")
9072 ;; The list of articles that weren't expired is returned.
9073 (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name))
9074 (or total (setq gnus-newsgroup-expirable es))
9075 ;; We go through the old list of expirable, and mark all
9076 ;; really expired articles as nonexistent.
9077 (or (eq es expirable) ;If nothing was expired, we don't mark.
9078 (let ((gnus-use-cache nil))
9079 (while expirable
9080 (or (memq (car expirable) es)
9081 (gnus-summary-mark-article
9082 (car expirable) gnus-canceled-mark))
9083 (setq expirable (cdr expirable)))))
9084 (gnus-message 6 "Expiring articles...done")))))
9085
9086 (defun gnus-summary-expire-articles-now ()
9087 "Expunge all expirable articles in the current group.
9088 This means that *all* articles that are marked as expirable will be
9089 deleted forever, right now."
9090 (interactive)
9091 (or gnus-expert-user
9092 (gnus-y-or-n-p
9093 "Are you really, really, really sure you want to expunge? ")
9094 (error "Phew!"))
9095 (let ((nnmail-expiry-wait -1)
9096 (nnmail-expiry-wait-function nil))
9097 (gnus-summary-expire-articles)))
9098
9099 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9100 (defun gnus-summary-delete-article (&optional n)
9101 "Delete the N next (mail) articles.
9102 This command actually deletes articles. This is not a marking
9103 command. The article will disappear forever from you life, never to
9104 return.
9105 If N is negative, delete backwards.
9106 If N is nil and articles have been marked with the process mark,
9107 delete these instead."
9108 (interactive "P")
9109 (or (gnus-check-backend-function 'request-expire-articles
9110 gnus-newsgroup-name)
9111 (error "The current newsgroup does not support article deletion."))
9112 ;; Compute the list of articles to delete.
9113 (let ((articles (gnus-summary-work-articles n))
9114 not-deleted)
9115 (if (and gnus-novice-user
9116 (not (gnus-y-or-n-p
9117 (format "Do you really want to delete %s forever? "
9118 (if (> (length articles) 1) "these articles"
9119 "this article")))))
9120 ()
9121 ;; Delete the articles.
9122 (setq not-deleted (gnus-request-expire-articles
9123 articles gnus-newsgroup-name 'force))
9124 (while articles
9125 (gnus-summary-remove-process-mark (car articles))
9126 ;; The backend might not have been able to delete the article
9127 ;; after all.
9128 (or (memq (car articles) not-deleted)
9129 (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9130 (setq articles (cdr articles))))
9131 (gnus-summary-position-cursor)
9132 (gnus-set-mode-line 'summary)
9133 not-deleted))
9134
9135 (defun gnus-summary-edit-article (&optional force)
9136 "Enter into a buffer and edit the current article.
9137 This will have permanent effect only in mail groups.
9138 If FORCE is non-nil, allow editing of articles even in read-only
9139 groups."
9140 (interactive "P")
9141 (or force
9142 (not (gnus-group-read-only-p))
9143 (error "The current newsgroup does not support article editing."))
9144 (gnus-summary-select-article t)
9145 (gnus-configure-windows 'article)
9146 (select-window (get-buffer-window gnus-article-buffer))
9147 (gnus-message 6 "C-c C-c to end edits")
9148 (setq buffer-read-only nil)
9149 (text-mode)
9150 (use-local-map (copy-keymap (current-local-map)))
9151 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
9152 (buffer-enable-undo)
9153 (widen)
9154 (goto-char (point-min))
9155 (search-forward "\n\n" nil t))
9156
9157 (defun gnus-summary-edit-article-done ()
9158 "Make edits to the current article permanent."
9159 (interactive)
9160 (if (gnus-group-read-only-p)
9161 (progn
9162 (gnus-summary-edit-article-postpone)
9163 (message "The current newsgroup does not support article editing.")
9164 (ding))
9165 (let ((buf (buffer-substring-no-properties (point-min) (point-max))))
9166 (erase-buffer)
9167 (insert buf)
9168 (if (not (gnus-request-replace-article
9169 (cdr gnus-article-current) (car gnus-article-current)
9170 (current-buffer)))
9171 (error "Couldn't replace article.")
9172 (gnus-article-mode)
9173 (use-local-map gnus-article-mode-map)
9174 (setq buffer-read-only t)
9175 (buffer-disable-undo (current-buffer))
9176 (gnus-configure-windows 'summary))
9177 (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))))
9178
9179 (defun gnus-summary-edit-article-postpone ()
9180 "Postpone changes to the current article."
9181 (interactive)
9182 (gnus-article-mode)
9183 (use-local-map gnus-article-mode-map)
9184 (setq buffer-read-only t)
9185 (buffer-disable-undo (current-buffer))
9186 (gnus-configure-windows 'summary)
9187 (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))
9188
9189 (defun gnus-summary-fancy-query ()
9190 "Query where the fancy respool algorithm would put this article."
9191 (interactive)
9192 (gnus-summary-select-article)
9193 (save-excursion
9194 (set-buffer gnus-article-buffer)
9195 (save-restriction
9196 (goto-char (point-min))
9197 (search-forward "\n\n")
9198 (narrow-to-region (point-min) (point))
9199 (pp-eval-expression (list 'quote (nnmail-split-fancy))))))
9200
9201 ;; Summary score commands.
9202
9203 ;; Suggested by boubaker@cenatls.cena.dgac.fr.
9204
9205 (defun gnus-summary-raise-score (n)
9206 "Raise the score of the current article by N."
9207 (interactive "p")
9208 (gnus-summary-set-score (+ (gnus-summary-article-score) n)))
9209
9210 (defun gnus-summary-set-score (n)
9211 "Set the score of the current article to N."
9212 (interactive "p")
9213 ;; Skip dummy header line.
9214 (save-excursion
9215 (gnus-summary-show-thread)
9216 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
9217 (forward-line 1))
9218 (let ((buffer-read-only nil))
9219 ;; Set score.
9220 (gnus-summary-update-mark
9221 (if (= n (or gnus-summary-default-score 0)) ?
9222 (if (< n (or gnus-summary-default-score 0))
9223 gnus-score-below-mark gnus-score-over-mark)) 'score))
9224 (let* ((article (gnus-summary-article-number))
9225 (score (assq article gnus-newsgroup-scored)))
9226 (if score (setcdr score n)
9227 (setq gnus-newsgroup-scored
9228 (cons (cons article n) gnus-newsgroup-scored))))
9229 (gnus-summary-update-line)))
9230
9231 (defun gnus-summary-current-score ()
9232 "Return the score of the current article."
9233 (interactive)
9234 (message "%s" (gnus-summary-article-score)))
9235
9236 ;; Summary marking commands.
9237
9238 (defun gnus-summary-raise-same-subject-and-select (score)
9239 "Raise articles which has the same subject with SCORE and select the next."
9240 (interactive "p")
9241 (let ((subject (gnus-summary-subject-string)))
9242 (gnus-summary-raise-score score)
9243 (while (gnus-summary-search-subject nil nil subject)
9244 (gnus-summary-raise-score score))
9245 (gnus-summary-next-article t)))
9246
9247 (defun gnus-summary-raise-same-subject (score)
9248 "Raise articles which has the same subject with SCORE."
9249 (interactive "p")
9250 (let ((subject (gnus-summary-subject-string)))
9251 (gnus-summary-raise-score score)
9252 (while (gnus-summary-search-subject nil nil subject)
9253 (gnus-summary-raise-score score))
9254 (gnus-summary-next-subject 1 t)))
9255
9256 (defun gnus-score-default (level)
9257 (if level (prefix-numeric-value level)
9258 gnus-score-interactive-default-score))
9259
9260 (defun gnus-summary-raise-thread (&optional score)
9261 "Raise the score of the articles in the current thread with SCORE."
9262 (interactive "P")
9263 (setq score (gnus-score-default score))
9264 (let (e)
9265 (save-excursion
9266 (let ((level (gnus-summary-thread-level)))
9267 (gnus-summary-raise-score score)
9268 (while (and (zerop (gnus-summary-next-subject 1 nil t))
9269 (> (gnus-summary-thread-level) level))
9270 (gnus-summary-raise-score score))
9271 (setq e (point))))
9272 (let ((gnus-summary-check-current t))
9273 (or (zerop (gnus-summary-next-subject 1 t))
9274 (goto-char e))))
9275 (gnus-summary-recenter)
9276 (gnus-summary-position-cursor)
9277 (gnus-set-mode-line 'summary))
9278
9279 (defun gnus-summary-lower-same-subject-and-select (score)
9280 "Raise articles which has the same subject with SCORE and select the next."
9281 (interactive "p")
9282 (gnus-summary-raise-same-subject-and-select (- score)))
9283
9284 (defun gnus-summary-lower-same-subject (score)
9285 "Raise articles which has the same subject with SCORE."
9286 (interactive "p")
9287 (gnus-summary-raise-same-subject (- score)))
9288
9289 (defun gnus-summary-lower-thread (&optional score)
9290 "Lower score of articles in the current thread with SCORE."
9291 (interactive "P")
9292 (gnus-summary-raise-thread (- (1- (gnus-score-default score)))))
9293
9294 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9295 "Mark articles which has the same subject as read, and then select the next.
9296 If UNMARK is positive, remove any kind of mark.
9297 If UNMARK is negative, tick articles."
9298 (interactive "P")
9299 (if unmark
9300 (setq unmark (prefix-numeric-value unmark)))
9301 (let ((count
9302 (gnus-summary-mark-same-subject
9303 (gnus-summary-subject-string) unmark)))
9304 ;; Select next unread article. If auto-select-same mode, should
9305 ;; select the first unread article.
9306 (gnus-summary-next-article t (and gnus-auto-select-same
9307 (gnus-summary-subject-string)))
9308 (gnus-message 7 "%d article%s marked as %s"
9309 count (if (= count 1) " is" "s are")
9310 (if unmark "unread" "read"))))
9311
9312 (defun gnus-summary-kill-same-subject (&optional unmark)
9313 "Mark articles which has the same subject as read.
9314 If UNMARK is positive, remove any kind of mark.
9315 If UNMARK is negative, tick articles."
9316 (interactive "P")
9317 (if unmark
9318 (setq unmark (prefix-numeric-value unmark)))
9319 (let ((count
9320 (gnus-summary-mark-same-subject
9321 (gnus-summary-subject-string) unmark)))
9322 ;; If marked as read, go to next unread subject.
9323 (if (null unmark)
9324 ;; Go to next unread subject.
9325 (gnus-summary-next-subject 1 t))
9326 (gnus-message 7 "%d articles are marked as %s"
9327 count (if unmark "unread" "read"))))
9328
9329 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9330 "Mark articles with same SUBJECT as read, and return marked number.
9331 If optional argument UNMARK is positive, remove any kinds of marks.
9332 If optional argument UNMARK is negative, mark articles as unread instead."
9333 (let ((count 1))
9334 (save-excursion
9335 (cond
9336 ((null unmark) ; Mark as read.
9337 (while (and
9338 (progn
9339 (gnus-summary-mark-article-as-read gnus-killed-mark)
9340 (gnus-summary-show-thread) t)
9341 (gnus-summary-search-forward nil subject))
9342 (setq count (1+ count))))
9343 ((> unmark 0) ; Tick.
9344 (while (and
9345 (progn
9346 (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9347 (gnus-summary-show-thread) t)
9348 (gnus-summary-search-forward nil subject))
9349 (setq count (1+ count))))
9350 (t ; Mark as unread.
9351 (while (and
9352 (progn
9353 (gnus-summary-mark-article-as-unread gnus-unread-mark)
9354 (gnus-summary-show-thread) t)
9355 (gnus-summary-search-forward nil subject))
9356 (setq count (1+ count)))))
9357 (gnus-set-mode-line 'summary)
9358 ;; Return the number of marked articles.
9359 count)))
9360
9361 (defun gnus-summary-mark-as-processable (n &optional unmark)
9362 "Set the process mark on the next N articles.
9363 If N is negative, mark backward instead. If UNMARK is non-nil, remove
9364 the process mark instead. The difference between N and the actual
9365 number of articles marked is returned."
9366 (interactive "p")
9367 (let ((backward (< n 0))
9368 (n (abs n)))
9369 (while (and
9370 (> n 0)
9371 (if unmark
9372 (gnus-summary-remove-process-mark
9373 (gnus-summary-article-number))
9374 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9375 (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9376 (setq n (1- n)))
9377 (if (/= 0 n) (gnus-message 7 "No more articles"))
9378 (gnus-summary-recenter)
9379 (gnus-summary-position-cursor)
9380 n))
9381
9382 (defun gnus-summary-unmark-as-processable (n)
9383 "Remove the process mark from the next N articles.
9384 If N is negative, mark backward instead. The difference between N and
9385 the actual number of articles marked is returned."
9386 (interactive "p")
9387 (gnus-summary-mark-as-processable n t))
9388
9389 (defun gnus-summary-unmark-all-processable ()
9390 "Remove the process mark from all articles."
9391 (interactive)
9392 (save-excursion
9393 (while gnus-newsgroup-processable
9394 (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9395 (gnus-summary-position-cursor))
9396
9397 (defun gnus-summary-mark-as-expirable (n)
9398 "Mark N articles forward as expirable.
9399 If N is negative, mark backward instead. The difference between N and
9400 the actual number of articles marked is returned."
9401 (interactive "p")
9402 (gnus-summary-mark-forward n gnus-expirable-mark))
9403
9404 (defun gnus-summary-mark-article-as-replied (article)
9405 "Mark ARTICLE replied and update the summary line."
9406 (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
9407 (let ((buffer-read-only nil))
9408 (if (gnus-summary-goto-subject article)
9409 (progn
9410 (gnus-summary-update-mark gnus-replied-mark 'replied)
9411 t))))
9412
9413 (defun gnus-summary-set-bookmark (article)
9414 "Set a bookmark in current article."
9415 (interactive (list (gnus-summary-article-number)))
9416 (if (or (not (get-buffer gnus-article-buffer))
9417 (not gnus-current-article)
9418 (not gnus-article-current)
9419 (not (equal gnus-newsgroup-name (car gnus-article-current))))
9420 (error "No current article selected"))
9421 ;; Remove old bookmark, if one exists.
9422 (let ((old (assq article gnus-newsgroup-bookmarks)))
9423 (if old (setq gnus-newsgroup-bookmarks
9424 (delq old gnus-newsgroup-bookmarks))))
9425 ;; Set the new bookmark, which is on the form
9426 ;; (article-number . line-number-in-body).
9427 (setq gnus-newsgroup-bookmarks
9428 (cons
9429 (cons article
9430 (save-excursion
9431 (set-buffer gnus-article-buffer)
9432 (count-lines
9433 (min (point)
9434 (save-excursion
9435 (goto-char (point-min))
9436 (search-forward "\n\n" nil t)
9437 (point)))
9438 (point))))
9439 gnus-newsgroup-bookmarks))
9440 (gnus-message 6 "A bookmark has been added to the current article."))
9441
9442 (defun gnus-summary-remove-bookmark (article)
9443 "Remove the bookmark from the current article."
9444 (interactive (list (gnus-summary-article-number)))
9445 ;; Remove old bookmark, if one exists.
9446 (let ((old (assq article gnus-newsgroup-bookmarks)))
9447 (if old
9448 (progn
9449 (setq gnus-newsgroup-bookmarks
9450 (delq old gnus-newsgroup-bookmarks))
9451 (gnus-message 6 "Removed bookmark."))
9452 (gnus-message 6 "No bookmark in current article."))))
9453
9454 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9455 (defun gnus-summary-mark-as-dormant (n)
9456 "Mark N articles forward as dormant.
9457 If N is negative, mark backward instead. The difference between N and
9458 the actual number of articles marked is returned."
9459 (interactive "p")
9460 (gnus-summary-mark-forward n gnus-dormant-mark))
9461
9462 (defun gnus-summary-set-process-mark (article)
9463 "Set the process mark on ARTICLE and update the summary line."
9464 (setq gnus-newsgroup-processable
9465 (cons article
9466 (delq article gnus-newsgroup-processable)))
9467 (let ((buffer-read-only nil))
9468 (if (gnus-summary-goto-subject article)
9469 (progn
9470 (gnus-summary-show-thread)
9471 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9472 (forward-line 1))
9473 (gnus-summary-update-mark gnus-process-mark 'replied)
9474 t))))
9475
9476 (defun gnus-summary-remove-process-mark (article)
9477 "Remove the process mark from ARTICLE and update the summary line."
9478 (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9479 (let ((buffer-read-only nil))
9480 (if (gnus-summary-goto-subject article)
9481 (progn
9482 (gnus-summary-show-thread)
9483 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9484 (forward-line 1))
9485 (gnus-summary-update-mark ? 'replied)
9486 (if (memq article gnus-newsgroup-replied)
9487 (gnus-summary-update-mark gnus-replied-mark 'replied))
9488 t))))
9489
9490 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9491 "Mark N articles as read forwards.
9492 If N is negative, mark backwards instead.
9493 Mark with MARK. If MARK is ? , ?! or ??, articles will be
9494 marked as unread.
9495 The difference between N and the actual number of articles marked is
9496 returned."
9497 (interactive "p")
9498 (gnus-set-global-variables)
9499 (let ((backward (< n 0))
9500 (gnus-summary-goto-unread
9501 (and gnus-summary-goto-unread
9502 (not (memq mark (list gnus-unread-mark
9503 gnus-ticked-mark gnus-dormant-mark)))))
9504 (n (abs n))
9505 (mark (or mark gnus-del-mark)))
9506 (while (and (> n 0)
9507 (gnus-summary-mark-article nil mark no-expire)
9508 (zerop (gnus-summary-next-subject
9509 (if backward -1 1) gnus-summary-goto-unread t)))
9510 (setq n (1- n)))
9511 (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9512 (gnus-summary-recenter)
9513 (gnus-summary-position-cursor)
9514 (gnus-set-mode-line 'summary)
9515 n))
9516
9517 (defun gnus-summary-mark-article-as-read (mark)
9518 "Mark the current article quickly as read with MARK."
9519 (let ((article (gnus-summary-article-number)))
9520 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9521 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9522 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9523 (setq gnus-newsgroup-reads
9524 (cons (cons article mark) gnus-newsgroup-reads))
9525 ;; Possibly remove from cache, if that is used.
9526 (and gnus-use-cache (gnus-cache-enter-remove-article article))
9527 (and gnus-newsgroup-auto-expire
9528 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9529 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9530 (= mark gnus-read-mark))
9531 (progn
9532 (setq mark gnus-expirable-mark)
9533 (setq gnus-newsgroup-expirable
9534 (cons article gnus-newsgroup-expirable))))
9535 (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9536 (forward-line 1))
9537 ;; Fix the mark.
9538 (gnus-summary-update-mark mark 'unread)
9539 t))
9540
9541 (defun gnus-summary-mark-article-as-unread (mark)
9542 "Mark the current article quickly as unread with MARK."
9543 (let ((article (gnus-summary-article-number)))
9544 (or (memq article gnus-newsgroup-unreads)
9545 (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9546 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9547 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9548 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9549 (setq gnus-newsgroup-reads
9550 (delq (assq article gnus-newsgroup-reads)
9551 gnus-newsgroup-reads))
9552 (if (= mark gnus-ticked-mark)
9553 (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9554 (if (= mark gnus-dormant-mark)
9555 (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))
9556
9557 ;; See whether the article is to be put in the cache.
9558 (and gnus-use-cache
9559 (vectorp (gnus-get-header-by-num article))
9560 (save-excursion
9561 (gnus-cache-possibly-enter-article
9562 gnus-newsgroup-name article
9563 (gnus-get-header-by-num article)
9564 (= mark gnus-ticked-mark)
9565 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9566
9567 (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9568 (forward-line 1))
9569 ;; Fix the mark.
9570 (gnus-summary-update-mark mark 'unread)
9571 t))
9572
9573 (defun gnus-summary-mark-article (&optional article mark no-expire)
9574 "Mark ARTICLE with MARK. MARK can be any character.
9575 Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??'
9576 (dormant) and `?E' (expirable).
9577 If MARK is nil, then the default character `?D' is used.
9578 If ARTICLE is nil, then the article on the current line will be
9579 marked."
9580 (and (stringp mark)
9581 (setq mark (aref mark 0)))
9582 ;; If no mark is given, then we check auto-expiring.
9583 (and (not no-expire)
9584 gnus-newsgroup-auto-expire
9585 (or (not mark)
9586 (and (numberp mark)
9587 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9588 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9589 (= mark gnus-read-mark))))
9590 (setq mark gnus-expirable-mark))
9591 (let* ((mark (or mark gnus-del-mark))
9592 (article (or article (gnus-summary-article-number))))
9593 (or article (error "No article on current line"))
9594 (if (or (= mark gnus-unread-mark)
9595 (= mark gnus-ticked-mark)
9596 (= mark gnus-dormant-mark))
9597 (gnus-mark-article-as-unread article mark)
9598 (gnus-mark-article-as-read article mark))
9599
9600 ;; See whether the article is to be put in the cache.
9601 (and gnus-use-cache
9602 (not (= mark gnus-canceled-mark))
9603 (vectorp (gnus-get-header-by-num article))
9604 (save-excursion
9605 (gnus-cache-possibly-enter-article
9606 gnus-newsgroup-name article
9607 (gnus-get-header-by-num article)
9608 (= mark gnus-ticked-mark)
9609 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9610
9611 (if (gnus-summary-goto-subject article)
9612 (let ((buffer-read-only nil))
9613 (gnus-summary-show-thread)
9614 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9615 (forward-line 1))
9616 ;; Fix the mark.
9617 (gnus-summary-update-mark mark 'unread)
9618 t))))
9619
9620 (defun gnus-summary-update-mark (mark type)
9621 (beginning-of-line)
9622 (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9623 (buffer-read-only nil)
9624 plist)
9625 (if (not forward)
9626 ()
9627 (forward-char forward)
9628 (setq plist (text-properties-at (point)))
9629 (delete-char 1)
9630 (insert mark)
9631 (and plist (add-text-properties (1- (point)) (point) plist))
9632 (and (eq type 'unread)
9633 (progn
9634 (add-text-properties (1- (point)) (point) (list 'gnus-mark mark))
9635 (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9636
9637 (defun gnus-mark-article-as-read (article &optional mark)
9638 "Enter ARTICLE in the pertinent lists and remove it from others."
9639 ;; Make the article expirable.
9640 (let ((mark (or mark gnus-del-mark)))
9641 (if (= mark gnus-expirable-mark)
9642 (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
9643 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9644 ;; Remove from unread and marked lists.
9645 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9646 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9647 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9648 (setq gnus-newsgroup-reads
9649 (cons (cons article mark) gnus-newsgroup-reads))
9650 ;; Possibly remove from cache, if that is used.
9651 (and gnus-use-cache (gnus-cache-enter-remove-article article))))
9652
9653 (defun gnus-mark-article-as-unread (article &optional mark)
9654 "Enter ARTICLE in the pertinent lists and remove it from others."
9655 (let ((mark (or mark gnus-ticked-mark)))
9656 ;; Add to unread list.
9657 (or (memq article gnus-newsgroup-unreads)
9658 (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9659 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9660 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9661 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9662 (setq gnus-newsgroup-reads
9663 (delq (assq article gnus-newsgroup-reads)
9664 gnus-newsgroup-reads))
9665 (if (= mark gnus-ticked-mark)
9666 (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9667 (if (= mark gnus-dormant-mark)
9668 (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))))
9669
9670 (defalias 'gnus-summary-mark-as-unread-forward
9671 'gnus-summary-tick-article-forward)
9672 (make-obsolete 'gnus-summary-mark-as-unread-forward
9673 'gnus-summary-tick-article-forward)
9674 (defun gnus-summary-tick-article-forward (n)
9675 "Tick N articles forwards.
9676 If N is negative, tick backwards instead.
9677 The difference between N and the number of articles ticked is returned."
9678 (interactive "p")
9679 (gnus-summary-mark-forward n gnus-ticked-mark))
9680
9681 (defalias 'gnus-summary-mark-as-unread-backward
9682 'gnus-summary-tick-article-backward)
9683 (make-obsolete 'gnus-summary-mark-as-unread-backward
9684 'gnus-summary-tick-article-backward)
9685 (defun gnus-summary-tick-article-backward (n)
9686 "Tick N articles backwards.
9687 The difference between N and the number of articles ticked is returned."
9688 (interactive "p")
9689 (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9690
9691 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9692 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9693 (defun gnus-summary-tick-article (&optional article clear-mark)
9694 "Mark current article as unread.
9695 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9696 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9697 (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9698 gnus-ticked-mark)))
9699
9700 (defun gnus-summary-mark-as-read-forward (n)
9701 "Mark N articles as read forwards.
9702 If N is negative, mark backwards instead.
9703 The difference between N and the actual number of articles marked is
9704 returned."
9705 (interactive "p")
9706 (gnus-summary-mark-forward n gnus-del-mark t))
9707
9708 (defun gnus-summary-mark-as-read-backward (n)
9709 "Mark the N articles as read backwards.
9710 The difference between N and the actual number of articles marked is
9711 returned."
9712 (interactive "p")
9713 (gnus-summary-mark-forward (- n) gnus-del-mark t))
9714
9715 (defun gnus-summary-mark-as-read (&optional article mark)
9716 "Mark current article as read.
9717 ARTICLE specifies the article to be marked as read.
9718 MARK specifies a string to be inserted at the beginning of the line."
9719 (gnus-summary-mark-article article mark))
9720
9721 (defun gnus-summary-clear-mark-forward (n)
9722 "Clear marks from N articles forward.
9723 If N is negative, clear backward instead.
9724 The difference between N and the number of marks cleared is returned."
9725 (interactive "p")
9726 (gnus-summary-mark-forward n gnus-unread-mark))
9727
9728 (defun gnus-summary-clear-mark-backward (n)
9729 "Clear marks from N articles backward.
9730 The difference between N and the number of marks cleared is returned."
9731 (interactive "p")
9732 (gnus-summary-mark-forward (- n) gnus-unread-mark))
9733
9734 (defun gnus-summary-mark-unread-as-read ()
9735 "Intended to be used by `gnus-summary-mark-article-hook'."
9736 (or (memq gnus-current-article gnus-newsgroup-marked)
9737 (memq gnus-current-article gnus-newsgroup-dormant)
9738 (memq gnus-current-article gnus-newsgroup-expirable)
9739 (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9740
9741 (defun gnus-summary-mark-region-as-read (point mark all)
9742 "Mark all unread articles between point and mark as read.
9743 If given a prefix, mark all articles between point and mark as read,
9744 even ticked and dormant ones."
9745 (interactive "r\nP")
9746 (save-excursion
9747 (goto-char point)
9748 (beginning-of-line)
9749 (while (and
9750 (< (point) mark)
9751 (progn
9752 (and
9753 (or all
9754 (and
9755 (not (memq (gnus-summary-article-number)
9756 gnus-newsgroup-marked))
9757 (not (memq (gnus-summary-article-number)
9758 gnus-newsgroup-dormant))))
9759 (gnus-summary-mark-article
9760 (gnus-summary-article-number) gnus-del-mark))
9761 t)
9762 (zerop (forward-line 1))))))
9763
9764 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
9765 (defalias 'gnus-summary-delete-marked-as-read
9766 'gnus-summary-remove-lines-marked-as-read)
9767 (make-obsolete 'gnus-summary-delete-marked-as-read
9768 'gnus-summary-remove-lines-marked-as-read)
9769 (defun gnus-summary-remove-lines-marked-as-read ()
9770 "Remove lines that are marked as read."
9771 (interactive)
9772 (gnus-summary-remove-lines-marked-with
9773 (concat (mapconcat
9774 (lambda (char) (char-to-string (symbol-value char)))
9775 '(gnus-del-mark gnus-read-mark gnus-ancient-mark
9776 gnus-killed-mark gnus-kill-file-mark
9777 gnus-low-score-mark gnus-expirable-mark
9778 gnus-canceled-mark gnus-catchup-mark)
9779 ""))))
9780
9781 (defalias 'gnus-summary-delete-marked-with
9782 'gnus-summary-remove-lines-marked-with)
9783 (make-obsolete 'gnus-summary-delete-marked-with
9784 'gnus-summary-remove-lines-marked-with)
9785 ;; Rewrite by Daniel Quinlan <quinlan@best.com>.
9786 (defun gnus-summary-remove-lines-marked-with (marks)
9787 "Remove lines that are marked with MARKS (e.g. \"DK\")."
9788 (interactive "sMarks: ")
9789 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
9790 (gnus-set-global-variables)
9791 (let ((buffer-read-only nil)
9792 (orig-article
9793 (let ((gnus-summary-check-current t))
9794 (gnus-summary-search-forward t)
9795 (gnus-summary-article-number)))
9796 (marks (concat "^[" marks "]")))
9797 (goto-char (point-min))
9798 (if gnus-newsgroup-adaptive
9799 (gnus-score-remove-lines-adaptive marks)
9800 (while (re-search-forward marks nil t)
9801 (gnus-delete-line)))
9802 ;; If we use dummy roots, we have to do an additional sweep over
9803 ;; the buffer.
9804 (if (not (eq gnus-summary-make-false-root 'dummy))
9805 ()
9806 (goto-char (point-min))
9807 (setq marks (concat "^[" (char-to-string gnus-dummy-mark) "]"))
9808 (while (re-search-forward marks nil t)
9809 (if (gnus-subject-equal
9810 (gnus-summary-subject-string)
9811 (progn
9812 (forward-line 1)
9813 (gnus-summary-subject-string)))
9814 ()
9815 (forward-line -1)
9816 (gnus-delete-line))))
9817 (or (zerop (buffer-size))
9818 (gnus-summary-goto-subject orig-article)
9819 (if (eobp)
9820 (gnus-summary-prev-subject 1)
9821 (gnus-summary-position-cursor)))))
9822
9823 (defun gnus-summary-expunge-below (&optional score)
9824 "Remove articles with score less than SCORE."
9825 (interactive "P")
9826 (gnus-set-global-variables)
9827 (setq score (if score
9828 (prefix-numeric-value score)
9829 (or gnus-summary-default-score 0)))
9830 (save-excursion
9831 (set-buffer gnus-summary-buffer)
9832 (goto-char (point-min))
9833 (let ((buffer-read-only nil)
9834 beg)
9835 (while (not (eobp))
9836 (if (< (gnus-summary-article-score) score)
9837 (progn
9838 (setq beg (point))
9839 (forward-line 1)
9840 (delete-region beg (point)))
9841 (forward-line 1)))
9842 ;; Adjust point.
9843 (or (zerop (buffer-size))
9844 (if (eobp)
9845 (gnus-summary-prev-subject 1)
9846 (gnus-summary-position-cursor))))))
9847
9848 (defun gnus-summary-mark-below (score mark)
9849 "Mark articles with score less than SCORE with MARK."
9850 (interactive "P\ncMark: ")
9851 (gnus-set-global-variables)
9852 (setq score (if score
9853 (prefix-numeric-value score)
9854 (or gnus-summary-default-score 0)))
9855 (save-excursion
9856 (set-buffer gnus-summary-buffer)
9857 (goto-char (point-min))
9858 (while (not (eobp))
9859 (and (< (gnus-summary-article-score) score)
9860 (gnus-summary-mark-article nil mark))
9861 (forward-line 1))))
9862
9863 (defun gnus-summary-kill-below (&optional score)
9864 "Mark articles with score below SCORE as read."
9865 (interactive "P")
9866 (gnus-set-global-variables)
9867 (gnus-summary-mark-below score gnus-killed-mark))
9868
9869 (defun gnus-summary-clear-above (&optional score)
9870 "Clear all marks from articles with score above SCORE."
9871 (interactive "P")
9872 (gnus-set-global-variables)
9873 (gnus-summary-mark-above score gnus-unread-mark))
9874
9875 (defun gnus-summary-tick-above (&optional score)
9876 "Tick all articles with score above SCORE."
9877 (interactive "P")
9878 (gnus-set-global-variables)
9879 (gnus-summary-mark-above score gnus-ticked-mark))
9880
9881 (defun gnus-summary-mark-above (score mark)
9882 "Mark articles with score over SCORE with MARK."
9883 (interactive "P\ncMark: ")
9884 (gnus-set-global-variables)
9885 (setq score (if score
9886 (prefix-numeric-value score)
9887 (or gnus-summary-default-score 0)))
9888 (save-excursion
9889 (set-buffer gnus-summary-buffer)
9890 (goto-char (point-min))
9891 (while (not (eobp))
9892 (if (> (gnus-summary-article-score) score)
9893 (progn
9894 (gnus-summary-mark-article nil mark)
9895 (forward-line 1))
9896 (forward-line 1)))))
9897
9898 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9899 (defun gnus-summary-show-all-expunged ()
9900 "Display all the hidden articles that were expunged for low scores."
9901 (interactive)
9902 (gnus-set-global-variables)
9903 (let ((buffer-read-only nil))
9904 (let ((scored gnus-newsgroup-scored)
9905 headers h)
9906 (while scored
9907 (or (gnus-summary-goto-subject (car (car scored)))
9908 (and (setq h (gnus-get-header-by-num (car (car scored))))
9909 (< (cdr (car scored)) gnus-summary-expunge-below)
9910 (setq headers (cons h headers))))
9911 (setq scored (cdr scored)))
9912 (or headers (error "No expunged articles hidden."))
9913 (goto-char (point-min))
9914 (save-excursion
9915 (gnus-summary-update-lines
9916 (point)
9917 (progn
9918 (gnus-summary-prepare-unthreaded (nreverse headers))
9919 (point)))))
9920 (goto-char (point-min))
9921 (gnus-summary-position-cursor)))
9922
9923 (defun gnus-summary-show-all-dormant ()
9924 "Display all the hidden articles that are marked as dormant."
9925 (interactive)
9926 (gnus-set-global-variables)
9927 (let ((buffer-read-only nil))
9928 (let ((dormant gnus-newsgroup-dormant)
9929 headers h)
9930 (while dormant
9931 (or (gnus-summary-goto-subject (car dormant))
9932 (and (setq h (gnus-get-header-by-num (car dormant)))
9933 (setq headers (cons h headers))))
9934 (setq dormant (cdr dormant)))
9935 (or headers (error "No dormant articles hidden."))
9936 (goto-char (point-min))
9937 (save-excursion
9938 (gnus-summary-update-lines
9939 (point)
9940 (progn
9941 (gnus-summary-prepare-unthreaded (nreverse headers))
9942 (point)))))
9943 (goto-char (point-min))
9944 (gnus-summary-position-cursor)))
9945
9946 (defun gnus-summary-hide-all-dormant ()
9947 "Hide all dormant articles."
9948 (interactive)
9949 (gnus-set-global-variables)
9950 (gnus-summary-remove-lines-marked-with (char-to-string gnus-dormant-mark))
9951 (gnus-summary-position-cursor))
9952
9953 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
9954 "Mark all articles not marked as unread in this newsgroup as read.
9955 If prefix argument ALL is non-nil, all articles are marked as read.
9956 If QUIETLY is non-nil, no questions will be asked.
9957 If TO-HERE is non-nil, it should be a point in the buffer. All
9958 articles before this point will be marked as read.
9959 The number of articles marked as read is returned."
9960 (interactive "P")
9961 (gnus-set-global-variables)
9962 (prog1
9963 (if (or quietly
9964 (not gnus-interactive-catchup) ;Without confirmation?
9965 gnus-expert-user
9966 (gnus-y-or-n-p
9967 (if all
9968 "Mark absolutely all articles as read? "
9969 "Mark all unread articles as read? ")))
9970 (if (and not-mark
9971 (not gnus-newsgroup-adaptive)
9972 (not gnus-newsgroup-auto-expire))
9973 (progn
9974 (and all (setq gnus-newsgroup-marked nil
9975 gnus-newsgroup-dormant nil))
9976 (setq gnus-newsgroup-unreads
9977 (append gnus-newsgroup-marked gnus-newsgroup-dormant)))
9978 ;; We actually mark all articles as canceled, which we
9979 ;; have to do when using auto-expiry or adaptive scoring.
9980 (gnus-summary-show-all-threads)
9981 (if (gnus-summary-first-subject (not all))
9982 (while (and
9983 (if to-here (< (point) to-here) t)
9984 (gnus-summary-mark-article-as-read gnus-catchup-mark)
9985 (gnus-summary-search-subject nil (not all)))))
9986 (or to-here
9987 (setq gnus-newsgroup-unreads
9988 (append gnus-newsgroup-marked
9989 gnus-newsgroup-dormant)))))
9990 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
9991 (if (and (not to-here) (eq 'nnvirtual (car method)))
9992 (nnvirtual-catchup-group
9993 (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
9994 (gnus-summary-position-cursor)))
9995
9996 (defun gnus-summary-catchup-to-here (&optional all)
9997 "Mark all unticked articles before the current one as read.
9998 If ALL is non-nil, also mark ticked and dormant articles as read."
9999 (interactive "P")
10000 (gnus-set-global-variables)
10001 (save-excursion
10002 (and (zerop (forward-line -1))
10003 (progn
10004 (end-of-line)
10005 (gnus-summary-catchup all t (point))
10006 (gnus-set-mode-line 'summary))))
10007 (gnus-summary-position-cursor))
10008
10009 (defun gnus-summary-catchup-all (&optional quietly)
10010 "Mark all articles in this newsgroup as read."
10011 (interactive "P")
10012 (gnus-set-global-variables)
10013 (gnus-summary-catchup t quietly))
10014
10015 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10016 "Mark all articles not marked as unread in this newsgroup as read, then exit.
10017 If prefix argument ALL is non-nil, all articles are marked as read."
10018 (interactive "P")
10019 (gnus-set-global-variables)
10020 (gnus-summary-catchup all quietly nil 'fast)
10021 ;; Select next newsgroup or exit.
10022 (if (and (eq gnus-auto-select-next 'quietly)
10023 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
10024 (gnus-summary-next-group nil)
10025 (gnus-summary-exit)))
10026
10027 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10028 "Mark all articles in this newsgroup as read, and then exit."
10029 (interactive "P")
10030 (gnus-set-global-variables)
10031 (gnus-summary-catchup-and-exit t quietly))
10032
10033 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
10034 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10035 "Mark all articles in this group as read and select the next group.
10036 If given a prefix, mark all articles, unread as well as ticked, as
10037 read."
10038 (interactive "P")
10039 (gnus-set-global-variables)
10040 (gnus-summary-catchup all)
10041 (gnus-summary-next-group))
10042
10043 ;; Thread-based commands.
10044
10045 (defun gnus-summary-toggle-threads (&optional arg)
10046 "Toggle showing conversation threads.
10047 If ARG is positive number, turn showing conversation threads on."
10048 (interactive "P")
10049 (gnus-set-global-variables)
10050 (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10051 (setq gnus-show-threads
10052 (if (null arg) (not gnus-show-threads)
10053 (> (prefix-numeric-value arg) 0)))
10054 (gnus-summary-prepare)
10055 (gnus-summary-goto-subject current)
10056 (gnus-summary-position-cursor)))
10057
10058 (defun gnus-summary-show-all-threads ()
10059 "Show all threads."
10060 (interactive)
10061 (gnus-set-global-variables)
10062 (save-excursion
10063 (let ((buffer-read-only nil))
10064 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10065 (gnus-summary-position-cursor))
10066
10067 (defun gnus-summary-show-thread ()
10068 "Show thread subtrees.
10069 Returns nil if no thread was there to be shown."
10070 (interactive)
10071 (gnus-set-global-variables)
10072 (let ((buffer-read-only nil)
10073 (orig (prog1 (point) (gnus-summary-hide-thread)))
10074 ;; first goto end then to beg, to have point at beg after let
10075 (end (progn (end-of-line) (point)))
10076 (beg (progn (beginning-of-line) (point))))
10077 (prog1
10078 ;; Any hidden lines here?
10079 (search-forward "\r" end t)
10080 (subst-char-in-region beg end ?\^M ?\n t)
10081 (goto-char orig)
10082 (gnus-summary-position-cursor))))
10083
10084 (defun gnus-summary-hide-all-threads ()
10085 "Hide all thread subtrees."
10086 (interactive)
10087 (gnus-set-global-variables)
10088 (save-excursion
10089 (goto-char (point-min))
10090 (gnus-summary-hide-thread)
10091 (while (and (not (eobp)) (zerop (forward-line 1)))
10092 (gnus-summary-hide-thread)))
10093 (gnus-summary-position-cursor))
10094
10095 (defun gnus-summary-hide-thread ()
10096 "Hide thread subtrees.
10097 Returns nil if no threads were there to be hidden."
10098 (interactive)
10099 (gnus-set-global-variables)
10100 (let ((buffer-read-only nil)
10101 (start (point))
10102 (level (gnus-summary-thread-level))
10103 (end (point)))
10104 ;; Go forward until either the buffer ends or the subthread
10105 ;; ends.
10106 (if (eobp)
10107 ()
10108 (while (and (zerop (forward-line 1))
10109 (> (gnus-summary-thread-level) level))
10110 (setq end (point)))
10111 (prog1
10112 (save-excursion
10113 (goto-char end)
10114 (search-backward "\n" start t))
10115 (subst-char-in-region start end ?\n ?\^M t)
10116 (forward-line -1)
10117 (gnus-summary-position-cursor)))))
10118
10119 (defun gnus-summary-go-to-next-thread (&optional previous)
10120 "Go to the same level (or less) next thread.
10121 If PREVIOUS is non-nil, go to previous thread instead.
10122 Return the article number moved to, or nil if moving was impossible."
10123 (let ((level (gnus-summary-thread-level))
10124 (article (gnus-summary-article-number)))
10125 (if previous
10126 (while (and (zerop (forward-line -1))
10127 (> (gnus-summary-thread-level) level)))
10128 (while (and (save-excursion
10129 (forward-line 1)
10130 (not (eobp)))
10131 (zerop (forward-line 1))
10132 (> (gnus-summary-thread-level) level))))
10133 (gnus-summary-recenter)
10134 (gnus-summary-position-cursor)
10135 (let ((oart (gnus-summary-article-number)))
10136 (and (/= oart article) oart))))
10137
10138 (defun gnus-summary-next-thread (n)
10139 "Go to the same level next N'th thread.
10140 If N is negative, search backward instead.
10141 Returns the difference between N and the number of skips actually
10142 done."
10143 (interactive "p")
10144 (gnus-set-global-variables)
10145 (let ((backward (< n 0))
10146 (n (abs n)))
10147 (while (and (> n 0)
10148 (gnus-summary-go-to-next-thread backward))
10149 (setq n (1- n)))
10150 (gnus-summary-position-cursor)
10151 (if (/= 0 n) (gnus-message 7 "No more threads"))
10152 n))
10153
10154 (defun gnus-summary-prev-thread (n)
10155 "Go to the same level previous N'th thread.
10156 Returns the difference between N and the number of skips actually
10157 done."
10158 (interactive "p")
10159 (gnus-set-global-variables)
10160 (gnus-summary-next-thread (- n)))
10161
10162 (defun gnus-summary-go-down-thread (&optional same)
10163 "Go down one level in the current thread.
10164 If SAME is non-nil, also move to articles of the same level."
10165 (let ((level (gnus-summary-thread-level))
10166 (start (point)))
10167 (if (and (zerop (forward-line 1))
10168 (> (gnus-summary-thread-level) level))
10169 t
10170 (goto-char start)
10171 nil)))
10172
10173 (defun gnus-summary-go-up-thread ()
10174 "Go up one level in the current thread."
10175 (let ((level (gnus-summary-thread-level))
10176 (start (point)))
10177 (while (and (zerop (forward-line -1))
10178 (>= (gnus-summary-thread-level) level)))
10179 (if (>= (gnus-summary-thread-level) level)
10180 (progn
10181 (goto-char start)
10182 nil)
10183 t)))
10184
10185 (defun gnus-summary-down-thread (n)
10186 "Go down thread N steps.
10187 If N is negative, go up instead.
10188 Returns the difference between N and how many steps down that were
10189 taken."
10190 (interactive "p")
10191 (gnus-set-global-variables)
10192 (let ((up (< n 0))
10193 (n (abs n)))
10194 (while (and (> n 0)
10195 (if up (gnus-summary-go-up-thread)
10196 (gnus-summary-go-down-thread)))
10197 (setq n (1- n)))
10198 (gnus-summary-position-cursor)
10199 (if (/= 0 n) (gnus-message 7 "Can't go further"))
10200 n))
10201
10202 (defun gnus-summary-up-thread (n)
10203 "Go up thread N steps.
10204 If N is negative, go up instead.
10205 Returns the difference between N and how many steps down that were
10206 taken."
10207 (interactive "p")
10208 (gnus-set-global-variables)
10209 (gnus-summary-down-thread (- n)))
10210
10211 (defun gnus-summary-kill-thread (&optional unmark)
10212 "Mark articles under current thread as read.
10213 If the prefix argument is positive, remove any kinds of marks.
10214 If the prefix argument is negative, tick articles instead."
10215 (interactive "P")
10216 (gnus-set-global-variables)
10217 (if unmark
10218 (setq unmark (prefix-numeric-value unmark)))
10219 (let ((killing t)
10220 (level (gnus-summary-thread-level)))
10221 (save-excursion
10222 ;; Expand the thread.
10223 (gnus-summary-show-thread)
10224 (while killing
10225 ;; Mark the article...
10226 (cond ((null unmark) (gnus-summary-mark-article-as-read
10227 gnus-killed-mark))
10228 ((> unmark 0) (gnus-summary-mark-article-as-unread
10229 gnus-unread-mark))
10230 (t (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10231 ;; ...and go forward until either the buffer ends or the subtree
10232 ;; ends.
10233 (if (not (and (zerop (forward-line 1))
10234 (> (gnus-summary-thread-level) level)))
10235 (setq killing nil))))
10236 ;; Hide killed subtrees.
10237 (and (null unmark)
10238 gnus-thread-hide-killed
10239 (gnus-summary-hide-thread))
10240 ;; If marked as read, go to next unread subject.
10241 (if (null unmark)
10242 ;; Go to next unread subject.
10243 (gnus-summary-next-subject 1 t)))
10244 (gnus-set-mode-line 'summary))
10245
10246 ;; Summary sorting commands
10247
10248 (defun gnus-summary-sort-by-number (&optional reverse)
10249 "Sort summary buffer by article number.
10250 Argument REVERSE means reverse order."
10251 (interactive "P")
10252 (gnus-set-global-variables)
10253 (gnus-summary-sort
10254 ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants
10255 ;; a function, so we wrap it.
10256 (cons (lambda () (gnus-summary-article-number))
10257 'gnus-thread-sort-by-number) reverse))
10258
10259 (defun gnus-summary-sort-by-author (&optional reverse)
10260 "Sort summary buffer by author name alphabetically.
10261 If case-fold-search is non-nil, case of letters is ignored.
10262 Argument REVERSE means reverse order."
10263 (interactive "P")
10264 (gnus-set-global-variables)
10265 (gnus-summary-sort
10266 (cons
10267 (lambda ()
10268 (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10269 extract)
10270 (if (not (vectorp header))
10271 ""
10272 (setq extract (funcall gnus-extract-address-components
10273 (mail-header-from header)))
10274 (concat (or (car extract) (cdr extract))
10275 "\r" (int-to-string (mail-header-number header))
10276 "\r" (mail-header-subject header)))))
10277 'gnus-thread-sort-by-author)
10278 reverse))
10279
10280 (defun gnus-summary-sort-by-subject (&optional reverse)
10281 "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
10282 If case-fold-search is non-nil, case of letters is ignored.
10283 Argument REVERSE means reverse order."
10284 (interactive "P")
10285 (gnus-set-global-variables)
10286 (gnus-summary-sort
10287 (cons
10288 (lambda ()
10289 (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10290 extract)
10291 (if (not (vectorp header))
10292 ""
10293 (setq extract (funcall gnus-extract-address-components
10294 (mail-header-from header)))
10295 (concat
10296 (downcase (gnus-simplify-subject (gnus-summary-subject-string) t))
10297 "\r" (int-to-string (mail-header-number header))
10298 "\r" (or (car extract) (cdr extract))))))
10299 'gnus-thread-sort-by-subject)
10300 reverse))
10301
10302 (defun gnus-summary-sort-by-date (&optional reverse)
10303 "Sort summary buffer by date.
10304 Argument REVERSE means reverse order."
10305 (interactive "P")
10306 (gnus-set-global-variables)
10307 (gnus-summary-sort
10308 (cons
10309 (lambda ()
10310 (gnus-sortable-date
10311 (mail-header-date
10312 (gnus-get-header-by-num (gnus-summary-article-number)))))
10313 'gnus-thread-sort-by-date)
10314 reverse))
10315
10316 (defun gnus-summary-sort-by-score (&optional reverse)
10317 "Sort summary buffer by score.
10318 Argument REVERSE means reverse order."
10319 (interactive "P")
10320 (gnus-set-global-variables)
10321 (gnus-summary-sort
10322 (cons (lambda () (gnus-summary-article-score))
10323 'gnus-thread-sort-by-score)
10324 (not reverse)))
10325
10326 (defvar gnus-summary-already-sorted nil)
10327 (defun gnus-summary-sort (predicate reverse)
10328 ;; Sort summary buffer by PREDICATE. REVERSE means reverse order.
10329 (if gnus-summary-already-sorted
10330 ()
10331 (let (buffer-read-only)
10332 (if (not gnus-show-threads)
10333 ;; We do untreaded sorting...
10334 (progn
10335 (goto-char (point-min))
10336 (sort-subr reverse 'forward-line 'end-of-line (car predicate)))
10337 ;; ... or we do threaded sorting.
10338 (let ((gnus-thread-sort-functions (list (cdr predicate)))
10339 (gnus-summary-prepare-hook nil)
10340 (gnus-summary-already-sorted nil))
10341 ;; We do that by simply regenerating the threads.
10342 (gnus-summary-prepare)
10343 (and gnus-show-threads
10344 gnus-thread-hide-subtree
10345 (gnus-summary-hide-all-threads))
10346 ;; If in async mode, we send some info to the backend.
10347 (and gnus-newsgroup-async
10348 (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
10349 (gnus-request-asynchronous
10350 gnus-newsgroup-name
10351 (if (and gnus-asynchronous-article-function
10352 (fboundp gnus-asynchronous-article-function))
10353 (funcall gnus-asynchronous-article-function
10354 gnus-newsgroup-threads)
10355 gnus-newsgroup-threads))))))))
10356
10357
10358 (defun gnus-sortable-date (date)
10359 "Make sortable string by string-lessp from DATE.
10360 Timezone package is used."
10361 (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S]
10362 (year (aref date 0))
10363 (month (aref date 1))
10364 (day (aref date 2)))
10365 (timezone-make-sortable-date
10366 year month day
10367 (timezone-make-time-string
10368 (aref date 3) (aref date 4) (aref date 5)))))
10369
10370
10371 ;; Summary saving commands.
10372
10373 (defun gnus-summary-save-article (&optional n)
10374 "Save the current article using the default saver function.
10375 If N is a positive number, save the N next articles.
10376 If N is a negative number, save the N previous articles.
10377 If N is nil and any articles have been marked with the process mark,
10378 save those articles instead.
10379 The variable `gnus-default-article-saver' specifies the saver function."
10380 (interactive "P")
10381 (gnus-set-global-variables)
10382 (let ((articles (gnus-summary-work-articles n)))
10383 (while articles
10384 (let ((header (gnus-get-header-by-num (car articles))))
10385 (if (vectorp header)
10386 (progn
10387 (save-window-excursion
10388 (gnus-summary-select-article t nil nil (car articles)))
10389 (or gnus-save-all-headers
10390 (gnus-article-hide-headers t))
10391 ;; Remove any X-Gnus lines.
10392 (save-excursion
10393 (save-restriction
10394 (set-buffer gnus-article-buffer)
10395 (let ((buffer-read-only nil))
10396 (goto-char (point-min))
10397 (narrow-to-region (point) (or (search-forward "\n\n" nil t)
10398 (point-max)))
10399 (while (re-search-forward "^X-Gnus" nil t)
10400 (beginning-of-line)
10401 (delete-region (point)
10402 (progn (forward-line 1) (point))))
10403 (widen))))
10404 (save-window-excursion
10405 (if gnus-default-article-saver
10406 (funcall gnus-default-article-saver)
10407 (error "No default saver is defined."))))
10408 (if (assq 'name header)
10409 (gnus-copy-file (cdr (assq 'name header)))
10410 (gnus-message 1 "Article %d is unsavable" (car articles)))))
10411 (gnus-summary-remove-process-mark (car articles))
10412 (setq articles (cdr articles)))
10413 (gnus-summary-position-cursor)
10414 n))
10415
10416 (defun gnus-summary-pipe-output (&optional arg)
10417 "Pipe the current article to a subprocess.
10418 If N is a positive number, pipe the N next articles.
10419 If N is a negative number, pipe the N previous articles.
10420 If N is nil and any articles have been marked with the process mark,
10421 pipe those articles instead."
10422 (interactive "P")
10423 (gnus-set-global-variables)
10424 (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10425 (gnus-summary-save-article arg))
10426 (gnus-configure-windows 'pipe))
10427
10428 (defun gnus-summary-save-article-mail (&optional arg)
10429 "Append the current article to an mail file.
10430 If N is a positive number, save the N next articles.
10431 If N is a negative number, save the N previous articles.
10432 If N is nil and any articles have been marked with the process mark,
10433 save those articles instead."
10434 (interactive "P")
10435 (gnus-set-global-variables)
10436 (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10437 (gnus-summary-save-article arg)))
10438
10439 (defun gnus-summary-save-article-rmail (&optional arg)
10440 "Append the current article to an rmail file.
10441 If N is a positive number, save the N next articles.
10442 If N is a negative number, save the N previous articles.
10443 If N is nil and any articles have been marked with the process mark,
10444 save those articles instead."
10445 (interactive "P")
10446 (gnus-set-global-variables)
10447 (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10448 (gnus-summary-save-article arg)))
10449
10450 (defun gnus-summary-save-article-file (&optional arg)
10451 "Append the current article to a file.
10452 If N is a positive number, save the N next articles.
10453 If N is a negative number, save the N previous articles.
10454 If N is nil and any articles have been marked with the process mark,
10455 save those articles instead."
10456 (interactive "P")
10457 (gnus-set-global-variables)
10458 (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10459 (gnus-summary-save-article arg)))
10460
10461 (defun gnus-read-save-file-name (prompt default-name)
10462 (let ((methods gnus-split-methods)
10463 split-name)
10464 (if (not gnus-split-methods)
10465 ()
10466 (save-excursion
10467 (set-buffer gnus-article-buffer)
10468 (gnus-narrow-to-headers)
10469 (while methods
10470 (goto-char (point-min))
10471 (and (condition-case ()
10472 (re-search-forward (car (car methods)) nil t)
10473 (error nil))
10474 (setq split-name (cons (nth 1 (car methods)) split-name)))
10475 (setq methods (cdr methods)))
10476 (widen)))
10477 (cond ((null split-name)
10478 (read-file-name
10479 (concat prompt " (default "
10480 (file-name-nondirectory default-name) ") ")
10481 (file-name-directory default-name)
10482 default-name))
10483 ((= 1 (length split-name))
10484 (read-file-name
10485 (concat prompt " (default " (car split-name) ") ")
10486 gnus-article-save-directory
10487 (concat gnus-article-save-directory (car split-name))))
10488 (t
10489 (setq split-name (mapcar (lambda (el) (list el))
10490 (nreverse split-name)))
10491 (let ((result (completing-read
10492 (concat prompt " ")
10493 split-name nil nil)))
10494 (concat gnus-article-save-directory
10495 (if (string= result "")
10496 (car (car split-name))
10497 result)))))))
10498
10499 (defun gnus-summary-save-in-rmail (&optional filename)
10500 "Append this article to Rmail file.
10501 Optional argument FILENAME specifies file name.
10502 Directory to save to is default to `gnus-article-save-directory' which
10503 is initialized from the SAVEDIR environment variable."
10504 (interactive)
10505 (gnus-set-global-variables)
10506 (let ((default-name
10507 (funcall gnus-rmail-save-name gnus-newsgroup-name
10508 gnus-current-headers gnus-newsgroup-last-rmail)))
10509 (or filename
10510 (setq filename (gnus-read-save-file-name
10511 "Save in rmail file:" default-name)))
10512 (gnus-make-directory (file-name-directory filename))
10513 (gnus-eval-in-buffer-window
10514 gnus-article-buffer
10515 (save-excursion
10516 (save-restriction
10517 (widen)
10518 (gnus-output-to-rmail filename))))
10519 ;; Remember the directory name to save articles
10520 (setq gnus-newsgroup-last-rmail filename)))
10521
10522 (defun gnus-summary-save-in-mail (&optional filename)
10523 "Append this article to Unix mail file.
10524 Optional argument FILENAME specifies file name.
10525 Directory to save to is default to `gnus-article-save-directory' which
10526 is initialized from the SAVEDIR environment variable."
10527 (interactive)
10528 (gnus-set-global-variables)
10529 (let ((default-name
10530 (funcall gnus-mail-save-name gnus-newsgroup-name
10531 gnus-current-headers gnus-newsgroup-last-mail)))
10532 (or filename
10533 (setq filename (gnus-read-save-file-name
10534 "Save in Unix mail file:" default-name)))
10535 (setq filename
10536 (expand-file-name filename
10537 (and default-name
10538 (file-name-directory default-name))))
10539 (gnus-make-directory (file-name-directory filename))
10540 (gnus-eval-in-buffer-window
10541 gnus-article-buffer
10542 (save-excursion
10543 (save-restriction
10544 (widen)
10545 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
10546 (gnus-output-to-rmail filename)
10547 (rmail-output filename 1 t t)))))
10548 ;; Remember the directory name to save articles.
10549 (setq gnus-newsgroup-last-mail filename)))
10550
10551 (defun gnus-summary-save-in-file (&optional filename)
10552 "Append this article to file.
10553 Optional argument FILENAME specifies file name.
10554 Directory to save to is default to `gnus-article-save-directory' which
10555 is initialized from the SAVEDIR environment variable."
10556 (interactive)
10557 (gnus-set-global-variables)
10558 (let ((default-name
10559 (funcall gnus-file-save-name gnus-newsgroup-name
10560 gnus-current-headers gnus-newsgroup-last-file)))
10561 (or filename
10562 (setq filename (gnus-read-save-file-name
10563 "Save in file:" default-name)))
10564 (gnus-make-directory (file-name-directory filename))
10565 (gnus-eval-in-buffer-window
10566 gnus-article-buffer
10567 (save-excursion
10568 (save-restriction
10569 (widen)
10570 (gnus-output-to-file filename))))
10571 ;; Remember the directory name to save articles.
10572 (setq gnus-newsgroup-last-file filename)))
10573
10574 (defun gnus-summary-save-in-pipe (&optional command)
10575 "Pipe this article to subprocess."
10576 (interactive)
10577 (gnus-set-global-variables)
10578 (let ((command (read-string "Shell command on article: "
10579 gnus-last-shell-command)))
10580 (if (string-equal command "")
10581 (setq command gnus-last-shell-command))
10582 (gnus-eval-in-buffer-window
10583 gnus-article-buffer
10584 (save-restriction
10585 (widen)
10586 (shell-command-on-region (point-min) (point-max) command nil)))
10587 (setq gnus-last-shell-command command)))
10588
10589 ;; Summary extract commands
10590
10591 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10592 (let ((buffer-read-only nil)
10593 (article (gnus-summary-article-number))
10594 b)
10595 (or (gnus-summary-goto-subject article)
10596 (error (format "No such article: %d" article)))
10597 (gnus-summary-position-cursor)
10598 ;; If all commands are to be bunched up on one line, we collect
10599 ;; them here.
10600 (if gnus-view-pseudos-separately
10601 ()
10602 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10603 files action)
10604 (while ps
10605 (setq action (cdr (assq 'action (car ps))))
10606 (setq files (list (cdr (assq 'name (car ps)))))
10607 (while (and ps (cdr ps)
10608 (string= (or action "1")
10609 (or (cdr (assq 'action (car (cdr ps)))) "2")))
10610 (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
10611 (setcdr ps (cdr (cdr ps))))
10612 (if (not files)
10613 ()
10614 (if (not (string-match "%s" action))
10615 (setq files (cons " " files)))
10616 (setq files (cons " " files))
10617 (and (assq 'execute (car ps))
10618 (setcdr (assq 'execute (car ps))
10619 (funcall (if (string-match "%s" action)
10620 'format 'concat)
10621 action
10622 (mapconcat (lambda (f) f) files " ")))))
10623 (setq ps (cdr ps)))))
10624 (if (and gnus-view-pseudos (not not-view))
10625 (while pslist
10626 (and (assq 'execute (car pslist))
10627 (gnus-execute-command (cdr (assq 'execute (car pslist)))
10628 (eq gnus-view-pseudos 'not-confirm)))
10629 (setq pslist (cdr pslist)))
10630 (save-excursion
10631 (while pslist
10632 (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
10633 (gnus-summary-article-number)))
10634 (forward-line 1)
10635 (setq b (point))
10636 (insert " " (file-name-nondirectory
10637 (cdr (assq 'name (car pslist))))
10638 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10639 (add-text-properties
10640 b (1+ b) (list 'gnus-number gnus-reffed-article-number
10641 'gnus-mark gnus-unread-mark
10642 'gnus-level 0
10643 'gnus-pseudo (car pslist)))
10644 (forward-line -1)
10645 (gnus-sethash (int-to-string gnus-reffed-article-number)
10646 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
10647 (setq gnus-newsgroup-unreads
10648 (cons gnus-reffed-article-number gnus-newsgroup-unreads))
10649 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10650 (setq pslist (cdr pslist)))))))
10651
10652 (defun gnus-pseudos< (p1 p2)
10653 (let ((c1 (cdr (assq 'action p1)))
10654 (c2 (cdr (assq 'action p2))))
10655 (and c1 c2 (string< c1 c2))))
10656
10657 (defun gnus-request-pseudo-article (props)
10658 (cond ((assq 'execute props)
10659 (gnus-execute-command (cdr (assq 'execute props)))))
10660 (let ((gnus-current-article (gnus-summary-article-number)))
10661 (run-hooks 'gnus-mark-article-hook)))
10662
10663 (defun gnus-execute-command (command &optional automatic)
10664 (save-excursion
10665 (gnus-article-setup-buffer)
10666 (set-buffer gnus-article-buffer)
10667 (let ((command (if automatic command (read-string "Command: " command)))
10668 (buffer-read-only nil))
10669 (erase-buffer)
10670 (insert "$ " command "\n\n")
10671 (if gnus-view-pseudo-asynchronously
10672 (start-process "gnus-execute" nil "sh" "-c" command)
10673 (call-process "sh" nil t nil "-c" command)))))
10674
10675 (defun gnus-copy-file (file &optional to)
10676 "Copy FILE to TO."
10677 (interactive
10678 (list (read-file-name "Copy file: " default-directory)
10679 (read-file-name "Copy file to: " default-directory)))
10680 (gnus-set-global-variables)
10681 (or to (setq to (read-file-name "Copy file to: " default-directory)))
10682 (and (file-directory-p to)
10683 (setq to (concat (file-name-as-directory to)
10684 (file-name-nondirectory file))))
10685 (copy-file file to))
10686
10687 ;; Summary kill commands.
10688
10689 (defun gnus-summary-edit-global-kill (article)
10690 "Edit the \"global\" kill file."
10691 (interactive (list (gnus-summary-article-number)))
10692 (gnus-set-global-variables)
10693 (gnus-group-edit-global-kill article))
10694
10695 (defun gnus-summary-edit-local-kill ()
10696 "Edit a local kill file applied to the current newsgroup."
10697 (interactive)
10698 (gnus-set-global-variables)
10699 (setq gnus-current-headers
10700 (gnus-gethash
10701 (int-to-string (gnus-summary-article-number))
10702 gnus-newsgroup-headers-hashtb-by-number))
10703 (gnus-set-global-variables)
10704 (gnus-group-edit-local-kill
10705 (gnus-summary-article-number) gnus-newsgroup-name))
10706
10707 \f
10708 ;;;
10709 ;;; Gnus article mode
10710 ;;;
10711
10712 (put 'gnus-article-mode 'mode-class 'special)
10713
10714 (defvar gnus-bugaboo nil)
10715
10716 (if gnus-article-mode-map
10717 nil
10718 (setq gnus-article-mode-map (make-keymap))
10719 (suppress-keymap gnus-article-mode-map)
10720 (define-key gnus-article-mode-map " " 'gnus-article-next-page)
10721 (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
10722 (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article)
10723 (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
10724 (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
10725 (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail)
10726 (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
10727 (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button)
10728 (define-key gnus-article-mode-map "\r" 'gnus-article-press-button)
10729 (define-key gnus-article-mode-map "\t" 'gnus-article-next-button)
10730 (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug)
10731
10732 ;; Duplicate almost all summary keystrokes in the article mode map.
10733 (let ((commands
10734 (list
10735 "p" "N" "P" "\M-\C-n" "\M-\C-p"
10736 "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j"
10737 "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k"
10738 "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h"
10739 "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w"
10740 "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a"
10741 "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s"
10742 "\M-g" "w" "\C-c\C-r" "\M-t" "C"
10743 "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d"
10744 "\C-c\C-i" "x" "X" "t" "g" "?" "l"
10745 "\C-c\C-v\C-v" "\C-d" "v"
10746 ;; "Mt" "M!" "Md" "Mr"
10747 ;; "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r"
10748 ;; "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK"
10749 ;; "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p"
10750 ;; "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT"
10751 ;; "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap"
10752 ;; "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am"
10753 ;; "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t"
10754 ;; "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi"
10755 ;; "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or"
10756 ;; "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve"
10757 ;; "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi"
10758 )))
10759 (while (and gnus-bugaboo commands) ; disabled
10760 (define-key gnus-article-mode-map (car commands)
10761 'gnus-article-summary-command)
10762 (setq commands (cdr commands))))
10763
10764 (let ((commands (list "q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
10765 ;; "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
10766 "=" "n" "^" "\M-^")))
10767 (while (and gnus-bugaboo commands) ; disabled
10768 (define-key gnus-article-mode-map (car commands)
10769 'gnus-article-summary-command-nosave)
10770 (setq commands (cdr commands)))))
10771
10772
10773 (defun gnus-article-mode ()
10774 "Major mode for displaying an article.
10775
10776 All normal editing commands are switched off.
10777
10778 The following commands are available:
10779
10780 \\<gnus-article-mode-map>
10781 \\[gnus-article-next-page]\t Scroll the article one page forwards
10782 \\[gnus-article-prev-page]\t Scroll the article one page backwards
10783 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
10784 \\[gnus-article-show-summary]\t Display the summary buffer
10785 \\[gnus-article-mail]\t Send a reply to the address near point
10786 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
10787 \\[gnus-info-find-node]\t Go to the Gnus info node"
10788 (interactive)
10789 (if gnus-visual (gnus-article-make-menu-bar))
10790 (kill-all-local-variables)
10791 (gnus-simplify-mode-line)
10792 (setq mode-name "Article")
10793 (setq major-mode 'gnus-article-mode)
10794 (make-local-variable 'minor-mode-alist)
10795 (or (assq 'gnus-show-mime minor-mode-alist)
10796 (setq minor-mode-alist
10797 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
10798 (use-local-map gnus-article-mode-map)
10799 (make-local-variable 'page-delimiter)
10800 (setq page-delimiter gnus-page-delimiter)
10801 (buffer-disable-undo (current-buffer))
10802 (setq buffer-read-only t) ;Disable modification
10803 (run-hooks 'gnus-article-mode-hook))
10804
10805 (defun gnus-article-setup-buffer ()
10806 "Initialize article mode buffer."
10807 ;; Returns the article buffer.
10808 (if (get-buffer gnus-article-buffer)
10809 (save-excursion
10810 (set-buffer gnus-article-buffer)
10811 (buffer-disable-undo (current-buffer))
10812 (setq buffer-read-only t)
10813 (gnus-add-current-to-buffer-list)
10814 (or (eq major-mode 'gnus-article-mode)
10815 (gnus-article-mode))
10816 (current-buffer))
10817 (save-excursion
10818 (set-buffer (get-buffer-create gnus-article-buffer))
10819 (gnus-add-current-to-buffer-list)
10820 (gnus-article-mode)
10821 (current-buffer))))
10822
10823 ;; Set article window start at LINE, where LINE is the number of lines
10824 ;; from the head of the article.
10825 (defun gnus-article-set-window-start (&optional line)
10826 (set-window-start
10827 (get-buffer-window gnus-article-buffer)
10828 (save-excursion
10829 (set-buffer gnus-article-buffer)
10830 (goto-char (point-min))
10831 (if (not line)
10832 (point-min)
10833 (gnus-message 6 "Moved to bookmark")
10834 (search-forward "\n\n" nil t)
10835 (forward-line line)
10836 (point)))))
10837
10838 (defun gnus-request-article-this-buffer (article group)
10839 "Get an article and insert it into this buffer."
10840 (setq group (or group gnus-newsgroup-name))
10841
10842 ;; Open server if it has closed.
10843 (gnus-check-server (gnus-find-method-for-group group))
10844
10845 ;; Using `gnus-request-article' directly will insert the article into
10846 ;; `nntp-server-buffer' - so we'll save some time by not having to
10847 ;; copy it from the server buffer into the article buffer.
10848
10849 ;; We only request an article by message-id when we do not have the
10850 ;; headers for it, so we'll have to get those.
10851 (and (stringp article)
10852 (let ((gnus-override-method gnus-refer-article-method))
10853 (gnus-read-header article)))
10854
10855 ;; If the article number is negative, that means that this article
10856 ;; doesn't belong in this newsgroup (possibly), so we find its
10857 ;; message-id and request it by id instead of number.
10858 (if (not (numberp article))
10859 ()
10860 (save-excursion
10861 (set-buffer gnus-summary-buffer)
10862 (let ((header (gnus-get-header-by-num article)))
10863 (if (< article 0)
10864 (if (vectorp header)
10865 ;; It's a real article.
10866 (setq article (mail-header-id header))
10867 ;; It is an extracted pseudo-article.
10868 (setq article 'pseudo)
10869 (gnus-request-pseudo-article header)))
10870
10871 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
10872 (if (not (eq (car method) 'nneething))
10873 ()
10874 (let ((dir (concat (file-name-as-directory (nth 1 method))
10875 (mail-header-subject header))))
10876 (if (file-directory-p dir)
10877 (progn
10878 (setq article 'nneething)
10879 (gnus-group-enter-directory dir)))))))))
10880
10881 ;; Check the cache.
10882 (if (and gnus-use-cache
10883 (numberp article)
10884 (gnus-cache-request-article article group))
10885 'article
10886 ;; Get the article and put into the article buffer.
10887 (if (or (stringp article) (numberp article))
10888 (progn
10889 (erase-buffer)
10890 ;; There may be some overlays that we have to kill...
10891 (insert "i")
10892 (let ((overlays (and (fboundp 'overlays-at)
10893 (overlays-at (point-min)))))
10894 (while overlays
10895 (delete-overlay (car overlays))
10896 (setq overlays (cdr overlays))))
10897 (erase-buffer)
10898 (let ((gnus-override-method
10899 (and (stringp article) gnus-refer-article-method)))
10900 (and (gnus-request-article article group (current-buffer))
10901 'article)))
10902 article)))
10903
10904 (defun gnus-read-header (id)
10905 "Read the headers of article ID and enter them into the Gnus system."
10906 (let (header)
10907 (if (not (setq header
10908 (car (if (let ((gnus-nov-is-evil t))
10909 (gnus-retrieve-headers
10910 (list id) gnus-newsgroup-name))
10911 (gnus-get-newsgroup-headers)))))
10912 nil
10913 (if (stringp id)
10914 (mail-header-set-number header gnus-reffed-article-number))
10915 (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers))
10916 (gnus-sethash (int-to-string (mail-header-number header)) header
10917 gnus-newsgroup-headers-hashtb-by-number)
10918 (if (stringp id)
10919 (setq gnus-reffed-article-number (1- gnus-reffed-article-number)))
10920 (setq gnus-current-headers header)
10921 header)))
10922
10923 (defun gnus-article-prepare (article &optional all-headers header)
10924 "Prepare ARTICLE in article mode buffer.
10925 ARTICLE should either be an article number or a Message-ID.
10926 If ARTICLE is an id, HEADER should be the article headers.
10927 If ALL-HEADERS is non-nil, no headers are hidden."
10928 (save-excursion
10929 ;; Make sure we start in a summary buffer.
10930 (or (eq major-mode 'gnus-summary-mode)
10931 (set-buffer gnus-summary-buffer))
10932 (setq gnus-summary-buffer (current-buffer))
10933 ;; Make sure the connection to the server is alive.
10934 (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name))
10935 (progn
10936 (gnus-check-server
10937 (gnus-find-method-for-group gnus-newsgroup-name))
10938 (gnus-request-group gnus-newsgroup-name t)))
10939 (let* ((article (if header (mail-header-number header) article))
10940 (summary-buffer (current-buffer))
10941 (internal-hook gnus-article-internal-prepare-hook)
10942 (group gnus-newsgroup-name)
10943 result)
10944 (save-excursion
10945 (gnus-article-setup-buffer)
10946 (set-buffer gnus-article-buffer)
10947 (if (not (setq result (let ((buffer-read-only nil))
10948 (gnus-request-article-this-buffer
10949 article group))))
10950 ;; There is no such article.
10951 (save-excursion
10952 (if (not (numberp article))
10953 ()
10954 (setq gnus-article-current
10955 (cons gnus-newsgroup-name article))
10956 (set-buffer gnus-summary-buffer)
10957 (setq gnus-current-article article)
10958 (gnus-summary-mark-article article gnus-canceled-mark))
10959 (gnus-message 1 "No such article (may be canceled)")
10960 (ding)
10961 nil)
10962 (if (or (eq result 'pseudo) (eq result 'nneething))
10963 (progn
10964 (save-excursion
10965 (set-buffer summary-buffer)
10966 (setq gnus-last-article gnus-current-article
10967 gnus-newsgroup-history (cons gnus-current-article
10968 gnus-newsgroup-history)
10969 gnus-current-article 0
10970 gnus-current-headers nil
10971 gnus-article-current nil)
10972 (if (eq result 'nneething)
10973 (gnus-configure-windows 'summary)
10974 (gnus-configure-windows 'article))
10975 (gnus-set-global-variables))
10976 (gnus-set-mode-line 'article))
10977 ;; The result from the `request' was an actual article -
10978 ;; or at least some text that is now displayed in the
10979 ;; article buffer.
10980 (if (and (numberp article)
10981 (not (eq article gnus-current-article)))
10982 ;; Seems like a new article has been selected.
10983 ;; `gnus-current-article' must be an article number.
10984 (save-excursion
10985 (set-buffer summary-buffer)
10986 (setq gnus-last-article gnus-current-article
10987 gnus-newsgroup-history (cons gnus-current-article
10988 gnus-newsgroup-history)
10989 gnus-current-article article
10990 gnus-current-headers
10991 (gnus-get-header-by-num gnus-current-article)
10992 gnus-article-current
10993 (cons gnus-newsgroup-name gnus-current-article))
10994 (gnus-summary-show-thread)
10995 (run-hooks 'gnus-mark-article-hook)
10996 (gnus-set-mode-line 'summary)
10997 (and gnus-visual
10998 (run-hooks 'gnus-visual-mark-article-hook))
10999 ;; Set the global newsgroup variables here.
11000 ;; Suggested by Jim Sisolak
11001 ;; <sisolak@trans4.neep.wisc.edu>.
11002 (gnus-set-global-variables)
11003 (setq gnus-have-all-headers
11004 (or all-headers gnus-show-all-headers))
11005 (and gnus-use-cache
11006 (vectorp (gnus-get-header-by-number article))
11007 (gnus-cache-possibly-enter-article
11008 group article
11009 (gnus-get-header-by-number article)
11010 (memq article gnus-newsgroup-marked)
11011 (memq article gnus-newsgroup-dormant)
11012 (memq article gnus-newsgroup-unreads)))))
11013 ;; Hooks for getting information from the article.
11014 ;; This hook must be called before being narrowed.
11015 (let (buffer-read-only)
11016 (run-hooks 'internal-hook)
11017 (run-hooks 'gnus-article-prepare-hook)
11018 ;; Decode MIME message.
11019 (if (and gnus-show-mime
11020 (or (not gnus-strict-mime)
11021 (gnus-fetch-field "Mime-Version")))
11022 (funcall gnus-show-mime-method))
11023 ;; Perform the article display hooks.
11024 (run-hooks 'gnus-article-display-hook))
11025 ;; Do page break.
11026 (goto-char (point-min))
11027 (and gnus-break-pages (gnus-narrow-to-page))
11028 (gnus-set-mode-line 'article)
11029 (gnus-configure-windows 'article)
11030 (goto-char (point-min))
11031 t))))))
11032
11033 (defun gnus-article-show-all-headers ()
11034 "Show all article headers in article mode buffer."
11035 (save-excursion
11036 (gnus-article-setup-buffer)
11037 (set-buffer gnus-article-buffer)
11038 (let ((buffer-read-only nil))
11039 (remove-text-properties (point-min) (point-max)
11040 gnus-hidden-properties))))
11041
11042 (defun gnus-article-hide-headers-if-wanted ()
11043 "Hide unwanted headers if `gnus-have-all-headers' is nil.
11044 Provided for backwards compatibility."
11045 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
11046 (gnus-article-hide-headers)))
11047
11048 (defun gnus-article-hide-headers (&optional delete)
11049 "Hide unwanted headers and possibly sort them as well."
11050 (interactive "P")
11051 (save-excursion
11052 (set-buffer gnus-article-buffer)
11053 (save-restriction
11054 (let ((sorted gnus-sorted-header-list)
11055 (buffer-read-only nil)
11056 want-list beg want-l)
11057 ;; First we narrow to just the headers.
11058 (widen)
11059 (goto-char (point-min))
11060 ;; Hide any "From " lines at the beginning of (mail) articles.
11061 (while (looking-at "From ")
11062 (forward-line 1))
11063 (or (bobp)
11064 (add-text-properties (point-min) (point) gnus-hidden-properties))
11065 ;; Then treat the rest of the header lines.
11066 (narrow-to-region
11067 (point)
11068 (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
11069 ;; Then we use the two regular expressions
11070 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
11071 ;; select which header lines is to remain visible in the
11072 ;; article buffer.
11073 (goto-char (point-min))
11074 (while (re-search-forward "^[^ \t]*:" nil t)
11075 (beginning-of-line)
11076 ;; We add the headers we want to keep to a list and delete
11077 ;; them from the buffer.
11078 (if (or (and (stringp gnus-visible-headers)
11079 (looking-at gnus-visible-headers))
11080 (and (not (stringp gnus-visible-headers))
11081 (stringp gnus-ignored-headers)
11082 (not (looking-at gnus-ignored-headers))))
11083 (progn
11084 (setq beg (point))
11085 (forward-line 1)
11086 ;; Be sure to get multi-line headers...
11087 (re-search-forward "^[^ \t]*:" nil t)
11088 (beginning-of-line)
11089 (setq want-list
11090 (cons (buffer-substring beg (point)) want-list))
11091 (delete-region beg (point))
11092 (goto-char beg))
11093 (forward-line 1)))
11094 ;; Next we perform the sorting by looking at
11095 ;; `gnus-sorted-header-list'.
11096 (goto-char (point-min))
11097 (while (and sorted want-list)
11098 (setq want-l want-list)
11099 (while (and want-l
11100 (not (string-match (car sorted) (car want-l))))
11101 (setq want-l (cdr want-l)))
11102 (if want-l
11103 (progn
11104 (insert (car want-l))
11105 (setq want-list (delq (car want-l) want-list))))
11106 (setq sorted (cdr sorted)))
11107 ;; Any headers that were not matched by the sorted list we
11108 ;; just tack on the end of the visible header list.
11109 (while want-list
11110 (insert (car want-list))
11111 (setq want-list (cdr want-list)))
11112 ;; And finally we make the unwanted headers invisible.
11113 (if delete
11114 (delete-region (point) (point-max))
11115 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
11116 (add-text-properties (point) (point-max) gnus-hidden-properties))))))
11117
11118 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
11119 (defun gnus-article-treat-overstrike ()
11120 "Translate overstrikes into bold text."
11121 (interactive)
11122 (save-excursion
11123 (set-buffer gnus-article-buffer)
11124 (let ((buffer-read-only nil))
11125 (while (search-forward "\b" nil t)
11126 (let ((next (following-char))
11127 (previous (char-after (- (point) 2))))
11128 (cond ((eq next previous)
11129 (put-text-property (- (point) 2) (point)
11130 'invisible t)
11131 (put-text-property (point) (1+ (point))
11132 'face 'bold))
11133 ((eq next ?_)
11134 (put-text-property (1- (point)) (1+ (point))
11135 'invisible t)
11136 (put-text-property (1- (point)) (point)
11137 'face 'underline))
11138 ((eq previous ?_)
11139 (put-text-property (- (point) 2) (point)
11140 'invisible t)
11141 (put-text-property (point) (1+ (point))
11142 'face 'underline))))))))
11143
11144 (defun gnus-article-word-wrap ()
11145 "Format too long lines."
11146 (interactive)
11147 (save-excursion
11148 (set-buffer gnus-article-buffer)
11149 (let ((buffer-read-only nil))
11150 (goto-char (point-min))
11151 (search-forward "\n\n" nil t)
11152 (end-of-line 1)
11153 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
11154 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
11155 (adaptive-fill-mode t))
11156 (while (not (eobp))
11157 (and (>= (current-column) (min fill-column (window-width)))
11158 (/= (preceding-char) ?:)
11159 (fill-paragraph nil))
11160 (end-of-line 2))))))
11161
11162 (defun gnus-article-remove-cr ()
11163 "Remove carriage returns from an article."
11164 (interactive)
11165 (save-excursion
11166 (set-buffer gnus-article-buffer)
11167 (let ((buffer-read-only nil))
11168 (goto-char (point-min))
11169 (while (search-forward "\r" nil t)
11170 (replace-match "" t t)))))
11171
11172 (defun gnus-article-display-x-face (&optional force)
11173 "Look for an X-Face header and display it if present."
11174 (interactive (list 'force))
11175 (save-excursion
11176 (set-buffer gnus-article-buffer)
11177 (let ((inhibit-point-motion-hooks t)
11178 (case-fold-search nil)
11179 from)
11180 (save-restriction
11181 (goto-char (point-min))
11182 (search-forward "\n\n")
11183 (narrow-to-region (point-min) (point))
11184 (goto-char (point-min))
11185 (setq from (mail-fetch-field "from"))
11186 (if (not (and gnus-article-x-face-command
11187 (or force
11188 (not gnus-article-x-face-too-ugly)
11189 (and gnus-article-x-face-too-ugly from
11190 (not (string-match gnus-article-x-face-too-ugly
11191 from))))
11192 (progn
11193 (goto-char (point-min))
11194 (re-search-forward "^X-Face: " nil t))))
11195 nil
11196 (let ((beg (point))
11197 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
11198 (if (symbolp gnus-article-x-face-command)
11199 (and (or (fboundp gnus-article-x-face-command)
11200 (error "%s is not a function"
11201 gnus-article-x-face-command))
11202 (funcall gnus-article-x-face-command beg end))
11203 (call-process-region beg end "sh" nil 0 nil
11204 "-c" gnus-article-x-face-command))))))))
11205
11206 (defun gnus-article-de-quoted-unreadable (&optional force)
11207 "Do a naive translation of a quoted-printable-encoded article.
11208 This is in no way, shape or form meant as a replacement for real MIME
11209 processing, but is simply a stop-gap measure until MIME support is
11210 written.
11211 If FORCE, decode the article whether it is marked as quoted-printable
11212 or not."
11213 (interactive (list 'force))
11214 (save-excursion
11215 (set-buffer gnus-article-buffer)
11216 (let ((case-fold-search t)
11217 (buffer-read-only nil)
11218 (type (gnus-fetch-field "content-transfer-encoding")))
11219 (if (or force (and type (string-match "quoted-printable" type)))
11220 (progn
11221 (goto-char (point-min))
11222 (search-forward "\n\n" nil 'move)
11223 (gnus-mime-decode-quoted-printable (point) (point-max)))))))
11224
11225 (defun gnus-mime-decode-quoted-printable (from to)
11226 ;; Decode quoted-printable from region between FROM and TO.
11227 (save-excursion
11228 (goto-char from)
11229 (while (search-forward "=" to t)
11230 (cond ((eq (following-char) ?\n)
11231 (delete-char -1)
11232 (delete-char 1))
11233 ((looking-at "[0-9A-F][0-9A-F]")
11234 (delete-char -1)
11235 (insert (hexl-hex-string-to-integer
11236 (buffer-substring (point) (+ 2 (point)))))
11237 (delete-char 2))
11238 ((looking-at "=")
11239 (delete-char 1))
11240 ((gnus-message 3 "Malformed MIME quoted-printable message"))))))
11241
11242 (defvar gnus-article-time-units
11243 (list (cons 'year (* 365.25 24 60 60))
11244 (cons 'week (* 7 24 60 60))
11245 (cons 'day (* 24 60 60))
11246 (cons 'hour (* 60 60))
11247 (cons 'minute 60)
11248 (cons 'second 1)))
11249
11250 (defun gnus-article-date-ut (&optional type)
11251 "Convert DATE date to universal time in the current article.
11252 If TYPE is `local', convert to local time; if it is `lapsed', output
11253 how much time has lapsed since DATE."
11254 (interactive (list 'ut))
11255 (let ((date (mail-header-date (or gnus-current-headers
11256 (gnus-get-header-by-number
11257 (gnus-summary-article-number))"")))
11258 (date-regexp "^Date: \\|^X-Sent: "))
11259 (if (or (not date)
11260 (string= date ""))
11261 ()
11262 (save-excursion
11263 (set-buffer gnus-article-buffer)
11264 (let ((buffer-read-only nil))
11265 (goto-char (point-min))
11266 (if (and (re-search-forward date-regexp nil t)
11267 (progn
11268 (beginning-of-line)
11269 (looking-at date-regexp)))
11270 (delete-region (gnus-point-at-bol)
11271 (progn (end-of-line) (1+ (point))))
11272 (goto-char (point-min))
11273 (goto-char (- (search-forward "\n\n") 2)))
11274 (insert
11275 (cond
11276 ((eq type 'local)
11277 (concat "Date: " (condition-case ()
11278 (timezone-make-date-arpa-standard date)
11279 (error date))
11280 "\n"))
11281 ((eq type 'ut)
11282 (concat "Date: "
11283 (condition-case ()
11284 (timezone-make-date-arpa-standard date nil "UT")
11285 (error date))
11286 "\n"))
11287 ((eq type 'lapsed)
11288 ;; If the date is seriously mangled, the timezone
11289 ;; functions are liable to bug out, so we condition-case
11290 ;; the entire thing. We call (current-time) once, rather than
11291 ;; letting current-time-string and current-time-zone default to
11292 ;; it, because that avoids a rare race condition when the time
11293 ;; zone changes between those two calls.
11294 (let* ((now (current-time))
11295 (real-sec (condition-case ()
11296 (- (gnus-seconds-since-epoch
11297 (timezone-make-date-arpa-standard
11298 (current-time-string now)
11299 (current-time-zone now) "UT"))
11300 (gnus-seconds-since-epoch
11301 (timezone-make-date-arpa-standard
11302 date nil "UT")))
11303 (error 0)))
11304 (sec (abs real-sec))
11305 num prev)
11306 (if (zerop sec)
11307 "X-Sent: Now\n"
11308 (concat
11309 "X-Sent: "
11310 (mapconcat
11311 (lambda (unit)
11312 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
11313 ""
11314 (setq sec (- sec (* num (cdr unit))))
11315 (prog1
11316 (concat (if prev ", " "") (int-to-string
11317 (floor num))
11318 " " (symbol-name (car unit))
11319 (if (> num 1) "s" ""))
11320 (setq prev t))))
11321 gnus-article-time-units "")
11322 (if (> real-sec 0)
11323 " ago\n"
11324 " in the future\n")))))
11325 (t
11326 (error "Unknown conversion type: %s" type)))))))))
11327
11328 (defun gnus-article-date-local ()
11329 "Convert the current article date to the local timezone."
11330 (interactive)
11331 (gnus-article-date-ut 'local))
11332
11333 (defun gnus-article-date-lapsed ()
11334 "Convert the current article date to time lapsed since it was sent."
11335 (interactive)
11336 (gnus-article-date-ut 'lapsed))
11337
11338 (defun gnus-article-maybe-highlight ()
11339 "Do some article highlighting if `gnus-visual' is non-nil."
11340 (if gnus-visual (gnus-article-highlight-some)))
11341
11342 ;; Article savers.
11343
11344 (defun gnus-output-to-rmail (file-name)
11345 "Append the current article to an Rmail file named FILE-NAME."
11346 (require 'rmail)
11347 ;; Most of these codes are borrowed from rmailout.el.
11348 (setq file-name (expand-file-name file-name))
11349 (setq rmail-default-rmail-file file-name)
11350 (let ((artbuf (current-buffer))
11351 (tmpbuf (get-buffer-create " *Gnus-output*")))
11352 (save-excursion
11353 (or (get-file-buffer file-name)
11354 (file-exists-p file-name)
11355 (if (gnus-yes-or-no-p
11356 (concat "\"" file-name "\" does not exist, create it? "))
11357 (let ((file-buffer (create-file-buffer file-name)))
11358 (save-excursion
11359 (set-buffer file-buffer)
11360 (rmail-insert-rmail-file-header)
11361 (let ((require-final-newline nil))
11362 (write-region (point-min) (point-max) file-name t 1)))
11363 (kill-buffer file-buffer))
11364 (error "Output file does not exist")))
11365 (set-buffer tmpbuf)
11366 (buffer-disable-undo (current-buffer))
11367 (erase-buffer)
11368 (insert-buffer-substring artbuf)
11369 (gnus-convert-article-to-rmail)
11370 ;; Decide whether to append to a file or to an Emacs buffer.
11371 (let ((outbuf (get-file-buffer file-name)))
11372 (if (not outbuf)
11373 (append-to-file (point-min) (point-max) file-name)
11374 ;; File has been visited, in buffer OUTBUF.
11375 (set-buffer outbuf)
11376 (let ((buffer-read-only nil)
11377 (msg (and (boundp 'rmail-current-message)
11378 (symbol-value 'rmail-current-message))))
11379 ;; If MSG is non-nil, buffer is in RMAIL mode.
11380 (if msg
11381 (progn (widen)
11382 (narrow-to-region (point-max) (point-max))))
11383 (insert-buffer-substring tmpbuf)
11384 (if msg
11385 (progn
11386 (goto-char (point-min))
11387 (widen)
11388 (search-backward "\^_")
11389 (narrow-to-region (point) (point-max))
11390 (goto-char (1+ (point-min)))
11391 (rmail-count-new-messages t)
11392 (rmail-show-message msg)))))))
11393 (kill-buffer tmpbuf)))
11394
11395 (defun gnus-output-to-file (file-name)
11396 "Append the current article to a file named FILE-NAME."
11397 (setq file-name (expand-file-name file-name))
11398 (let ((artbuf (current-buffer))
11399 (tmpbuf (get-buffer-create " *Gnus-output*")))
11400 (save-excursion
11401 (set-buffer tmpbuf)
11402 (buffer-disable-undo (current-buffer))
11403 (erase-buffer)
11404 (insert-buffer-substring artbuf)
11405 ;; Append newline at end of the buffer as separator, and then
11406 ;; save it to file.
11407 (goto-char (point-max))
11408 (insert "\n")
11409 (append-to-file (point-min) (point-max) file-name))
11410 (kill-buffer tmpbuf)))
11411
11412 (defun gnus-convert-article-to-rmail ()
11413 "Convert article in current buffer to Rmail message format."
11414 (let ((buffer-read-only nil))
11415 ;; Convert article directly into Babyl format.
11416 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
11417 (goto-char (point-min))
11418 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
11419 (while (search-forward "\n\^_" nil t) ;single char
11420 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
11421 (goto-char (point-max))
11422 (insert "\^_")))
11423
11424 (defun gnus-narrow-to-page (&optional arg)
11425 "Make text outside current page invisible except for page delimiter.
11426 A numeric arg specifies to move forward or backward by that many pages,
11427 thus showing a page other than the one point was originally in."
11428 (interactive "P")
11429 (setq arg (if arg (prefix-numeric-value arg) 0))
11430 (save-excursion
11431 (forward-page -1) ;Beginning of current page.
11432 (widen)
11433 (if (> arg 0)
11434 (forward-page arg)
11435 (if (< arg 0)
11436 (forward-page (1- arg))))
11437 ;; Find the end of the page.
11438 (forward-page)
11439 ;; If we stopped due to end of buffer, stay there.
11440 ;; If we stopped after a page delimiter, put end of restriction
11441 ;; at the beginning of that line.
11442 ;; These are commented out.
11443 ;; (if (save-excursion (beginning-of-line)
11444 ;; (looking-at page-delimiter))
11445 ;; (beginning-of-line))
11446 (narrow-to-region (point)
11447 (progn
11448 ;; Find the top of the page.
11449 (forward-page -1)
11450 ;; If we found beginning of buffer, stay there.
11451 ;; If extra text follows page delimiter on same line,
11452 ;; include it.
11453 ;; Otherwise, show text starting with following line.
11454 (if (and (eolp) (not (bobp)))
11455 (forward-line 1))
11456 (point)))))
11457
11458 (defun gnus-gmt-to-local ()
11459 "Rewrite Date header described in GMT to local in current buffer.
11460 Intended to be used with gnus-article-prepare-hook."
11461 (save-excursion
11462 (save-restriction
11463 (widen)
11464 (goto-char (point-min))
11465 (narrow-to-region (point-min)
11466 (progn (search-forward "\n\n" nil 'move) (point)))
11467 (goto-char (point-min))
11468 (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t)
11469 (let ((buffer-read-only nil)
11470 (date (buffer-substring-no-properties
11471 (match-beginning 1) (match-end 1))))
11472 (delete-region (match-beginning 1) (match-end 1))
11473 (insert
11474 (timezone-make-date-arpa-standard
11475 date)))))))
11476
11477
11478 ;; Article mode commands
11479
11480 (defun gnus-article-next-page (&optional lines)
11481 "Show next page of current article.
11482 If end of article, return non-nil. Otherwise return nil.
11483 Argument LINES specifies lines to be scrolled up."
11484 (interactive "P")
11485 (move-to-window-line -1)
11486 ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
11487 (if (save-excursion
11488 (end-of-line)
11489 (and (pos-visible-in-window-p) ;Not continuation line.
11490 (eobp)))
11491 ;; Nothing in this page.
11492 (if (or (not gnus-break-pages)
11493 (save-excursion
11494 (save-restriction
11495 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
11496 t ;Nothing more.
11497 (gnus-narrow-to-page 1) ;Go to next page.
11498 nil)
11499 ;; More in this page.
11500 (condition-case ()
11501 (scroll-up lines)
11502 (end-of-buffer
11503 ;; Long lines may cause an end-of-buffer error.
11504 (goto-char (point-max))))
11505 nil))
11506
11507 (defun gnus-article-prev-page (&optional lines)
11508 "Show previous page of current article.
11509 Argument LINES specifies lines to be scrolled down."
11510 (interactive "P")
11511 (move-to-window-line 0)
11512 (if (and gnus-break-pages
11513 (bobp)
11514 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
11515 (progn
11516 (gnus-narrow-to-page -1) ;Go to previous page.
11517 (goto-char (point-max))
11518 (recenter -1))
11519 (scroll-down lines)))
11520
11521 (defun gnus-article-refer-article ()
11522 "Read article specified by message-id around point."
11523 (interactive)
11524 (search-forward ">" nil t) ;Move point to end of "<....>".
11525 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
11526 (let ((message-id
11527 (buffer-substring (match-beginning 1) (match-end 1))))
11528 (set-buffer gnus-summary-buffer)
11529 (gnus-summary-refer-article message-id))
11530 (error "No references around point")))
11531
11532 (defun gnus-article-show-summary ()
11533 "Reconfigure windows to show summary buffer."
11534 (interactive)
11535 (gnus-configure-windows 'article)
11536 (gnus-summary-goto-subject gnus-current-article))
11537
11538 (defun gnus-article-describe-briefly ()
11539 "Describe article mode commands briefly."
11540 (interactive)
11541 (gnus-message 6
11542 (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")))
11543
11544 (defun gnus-article-summary-command ()
11545 "Execute the last keystroke in the summary buffer."
11546 (interactive)
11547 (let ((obuf (current-buffer))
11548 (owin (current-window-configuration))
11549 func)
11550 (switch-to-buffer gnus-summary-buffer 'norecord)
11551 (setq func (lookup-key (current-local-map) (this-command-keys)))
11552 (call-interactively func)
11553 (set-buffer obuf)
11554 (set-window-configuration owin)
11555 (set-window-point (get-buffer-window (current-buffer)) (point))))
11556
11557 (defun gnus-article-summary-command-nosave ()
11558 "Execute the last keystroke in the summary buffer."
11559 (interactive)
11560 (let (func)
11561 (pop-to-buffer gnus-summary-buffer 'norecord)
11562 (setq func (lookup-key (current-local-map) (this-command-keys)))
11563 (call-interactively func)))
11564
11565 \f
11566 ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
11567
11568 ;;;###autoload
11569 (defalias 'gnus-batch-kill 'gnus-batch-score)
11570 ;;;###autoload
11571 (defun gnus-batch-score ()
11572 "Run batched scoring.
11573 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
11574 Newsgroups is a list of strings in Bnews format. If you want to score
11575 the comp hierarchy, you'd say \"comp.all\". If you would not like to
11576 score the alt hierarchy, you'd say \"!alt.all\"."
11577 (interactive)
11578 (let* ((yes-and-no
11579 (gnus-newsrc-parse-options
11580 (apply (function concat)
11581 (mapcar (lambda (g) (concat g " "))
11582 command-line-args-left))))
11583 (gnus-expert-user t)
11584 (nnmail-spool-file nil)
11585 (gnus-use-dribble-file nil)
11586 (yes (car yes-and-no))
11587 (no (cdr yes-and-no))
11588 group newsrc entry
11589 ;; Disable verbose message.
11590 gnus-novice-user gnus-large-newsgroup)
11591 ;; Eat all arguments.
11592 (setq command-line-args-left nil)
11593 ;; Start Gnus.
11594 (gnus)
11595 ;; Apply kills to specified newsgroups in command line arguments.
11596 (setq newsrc (cdr gnus-newsrc-alist))
11597 (while newsrc
11598 (setq group (car (car newsrc)))
11599 (setq entry (gnus-gethash group gnus-newsrc-hashtb))
11600 (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
11601 (and (car entry)
11602 (or (eq (car entry) t)
11603 (not (zerop (car entry)))))
11604 (if yes (string-match yes group) t)
11605 (or (null no) (not (string-match no group))))
11606 (progn
11607 (gnus-summary-read-group group nil t)
11608 (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
11609 (gnus-summary-exit))))
11610 (setq newsrc (cdr newsrc)))
11611 ;; Exit Emacs.
11612 (switch-to-buffer gnus-group-buffer)
11613 (gnus-group-save-newsrc)))
11614
11615 (defun gnus-apply-kill-file ()
11616 "Apply a kill file to the current newsgroup.
11617 Returns the number of articles marked as read."
11618 (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
11619 (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11620 (gnus-apply-kill-file-internal)
11621 0))
11622
11623 (defun gnus-kill-save-kill-buffer ()
11624 (save-excursion
11625 (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11626 (if (get-file-buffer file)
11627 (progn
11628 (set-buffer (get-file-buffer file))
11629 (and (buffer-modified-p) (save-buffer))
11630 (kill-buffer (current-buffer)))))))
11631
11632 (defvar gnus-kill-file-name "KILL"
11633 "Suffix of the kill files.")
11634
11635 (defun gnus-newsgroup-kill-file (newsgroup)
11636 "Return the name of a kill file name for NEWSGROUP.
11637 If NEWSGROUP is nil, return the global kill file name instead."
11638 (cond ((or (null newsgroup)
11639 (string-equal newsgroup ""))
11640 ;; The global KILL file is placed at top of the directory.
11641 (expand-file-name gnus-kill-file-name
11642 (or gnus-kill-files-directory "~/News")))
11643 ((gnus-use-long-file-name 'not-kill)
11644 ;; Append ".KILL" to newsgroup name.
11645 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
11646 "." gnus-kill-file-name)
11647 (or gnus-kill-files-directory "~/News")))
11648 (t
11649 ;; Place "KILL" under the hierarchical directory.
11650 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
11651 "/" gnus-kill-file-name)
11652 (or gnus-kill-files-directory "~/News")))))
11653
11654 \f
11655 ;;;
11656 ;;; Dribble file
11657 ;;;
11658
11659 (defvar gnus-dribble-ignore nil)
11660 (defvar gnus-dribble-eval-file nil)
11661
11662 (defun gnus-dribble-file-name ()
11663 (concat gnus-current-startup-file "-dribble"))
11664
11665 (defun gnus-dribble-enter (string)
11666 (if (and (not gnus-dribble-ignore)
11667 gnus-dribble-buffer
11668 (buffer-name gnus-dribble-buffer))
11669 (let ((obuf (current-buffer)))
11670 (set-buffer gnus-dribble-buffer)
11671 (insert string "\n")
11672 (set-window-point (get-buffer-window (current-buffer)) (point-max))
11673 (set-buffer obuf))))
11674
11675 (defun gnus-dribble-read-file ()
11676 (let ((dribble-file (gnus-dribble-file-name)))
11677 (save-excursion
11678 (set-buffer (setq gnus-dribble-buffer
11679 (get-buffer-create
11680 (file-name-nondirectory dribble-file))))
11681 (gnus-add-current-to-buffer-list)
11682 (erase-buffer)
11683 (set-visited-file-name dribble-file)
11684 (buffer-disable-undo (current-buffer))
11685 (bury-buffer (current-buffer))
11686 (set-buffer-modified-p nil)
11687 (let ((auto (make-auto-save-file-name))
11688 (gnus-dribble-ignore t))
11689 (if (or (file-exists-p auto) (file-exists-p dribble-file))
11690 (progn
11691 (if (file-newer-than-file-p auto dribble-file)
11692 (setq dribble-file auto))
11693 (insert-file-contents dribble-file)
11694 (if (not (zerop (buffer-size)))
11695 (set-buffer-modified-p t))
11696 (if (gnus-y-or-n-p
11697 "Auto-save file exists. Do you want to read it? ")
11698 (setq gnus-dribble-eval-file t))))))))
11699
11700 (defun gnus-dribble-eval-file ()
11701 (if (not gnus-dribble-eval-file)
11702 ()
11703 (setq gnus-dribble-eval-file nil)
11704 (save-excursion
11705 (let ((gnus-dribble-ignore t))
11706 (set-buffer gnus-dribble-buffer)
11707 (eval-buffer (current-buffer))))))
11708
11709 (defun gnus-dribble-delete-file ()
11710 (if (file-exists-p (gnus-dribble-file-name))
11711 (delete-file (gnus-dribble-file-name)))
11712 (if gnus-dribble-buffer
11713 (save-excursion
11714 (set-buffer gnus-dribble-buffer)
11715 (let ((auto (make-auto-save-file-name)))
11716 (if (file-exists-p auto)
11717 (delete-file auto))
11718 (erase-buffer)
11719 (set-buffer-modified-p nil)))))
11720
11721 (defun gnus-dribble-save ()
11722 (if (and gnus-dribble-buffer
11723 (buffer-name gnus-dribble-buffer))
11724 (save-excursion
11725 (set-buffer gnus-dribble-buffer)
11726 (save-buffer))))
11727
11728 (defun gnus-dribble-clear ()
11729 (save-excursion
11730 (if (gnus-buffer-exists-p gnus-dribble-buffer)
11731 (progn
11732 (set-buffer gnus-dribble-buffer)
11733 (erase-buffer)
11734 (set-buffer-modified-p nil)
11735 (setq buffer-saved-size (buffer-size))))))
11736
11737 ;;;
11738 ;;; Server Communication
11739 ;;;
11740
11741 (defun gnus-start-news-server (&optional confirm)
11742 "Open a method for getting news.
11743 If CONFIRM is non-nil, the user will be asked for an NNTP server."
11744 (let (how)
11745 (if gnus-current-select-method
11746 ;; Stream is already opened.
11747 nil
11748 ;; Open NNTP server.
11749 (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
11750 (if confirm
11751 (progn
11752 ;; Read server name with completion.
11753 (setq gnus-nntp-server
11754 (completing-read "NNTP server: "
11755 (mapcar (lambda (server) (list server))
11756 (cons (list gnus-nntp-server)
11757 gnus-secondary-servers))
11758 nil nil gnus-nntp-server))))
11759
11760 (if (and gnus-nntp-server
11761 (stringp gnus-nntp-server)
11762 (not (string= gnus-nntp-server "")))
11763 (setq gnus-select-method
11764 (cond ((or (string= gnus-nntp-server "")
11765 (string= gnus-nntp-server "::"))
11766 (list 'nnspool (system-name)))
11767 ((string-match "^:" gnus-nntp-server)
11768 (list 'nnmh gnus-nntp-server
11769 (list 'nnmh-directory
11770 (file-name-as-directory
11771 (expand-file-name
11772 (concat "~/" (substring
11773 gnus-nntp-server 1)))))
11774 (list 'nnmh-get-new-mail nil)))
11775 (t
11776 (list 'nntp gnus-nntp-server)))))
11777
11778 (setq how (car gnus-select-method))
11779 (cond ((eq how 'nnspool)
11780 (require 'nnspool)
11781 (gnus-message 5 "Looking up local news spool..."))
11782 ((eq how 'nnmh)
11783 (require 'nnmh)
11784 (gnus-message 5 "Looking up mh spool..."))
11785 (t
11786 (require 'nntp)))
11787 (setq gnus-current-select-method gnus-select-method)
11788 (run-hooks 'gnus-open-server-hook)
11789 (or
11790 ;; gnus-open-server-hook might have opened it
11791 (gnus-server-opened gnus-select-method)
11792 (gnus-open-server gnus-select-method)
11793 (gnus-y-or-n-p
11794 (format
11795 "%s open error: '%s'. Continue? "
11796 (nth 1 gnus-select-method)
11797 (gnus-status-message gnus-select-method)))
11798 (progn
11799 (gnus-message 1 "Couldn't open server on %s"
11800 (nth 1 gnus-select-method))
11801 (ding)
11802 nil)))))
11803
11804 (defun gnus-check-server (&optional method)
11805 "If the news server is down, start it up again."
11806 (let ((method (if method method gnus-select-method)))
11807 (and (stringp method)
11808 (setq method (gnus-server-to-method method)))
11809 (if (gnus-server-opened method)
11810 ;; Stream is already opened.
11811 t
11812 ;; Open server.
11813 (gnus-message 5 "Opening server %s on %s..." (car method) (nth 1 method))
11814 (run-hooks 'gnus-open-server-hook)
11815 (prog1
11816 (gnus-open-server method)
11817 (message "")))))
11818
11819 (defun gnus-nntp-message (&optional message)
11820 "Check the status of the NNTP server.
11821 If the status of the server is clear and MESSAGE is non-nil, MESSAGE
11822 is returned insted of the status string."
11823 (let ((status (gnus-status-message (gnus-find-method-for-group
11824 gnus-newsgroup-name)))
11825 (message (or message "")))
11826 (if (and (stringp status) (> (length status) 0))
11827 status message)))
11828
11829 (defun gnus-get-function (method function)
11830 (and (stringp method)
11831 (setq method (gnus-server-to-method method)))
11832 (let ((func (intern (format "%s-%s" (car method) function))))
11833 (if (not (fboundp func))
11834 (progn
11835 (require (car method))
11836 (if (not (fboundp func))
11837 (error "No such function: %s" func))))
11838 func))
11839
11840 ;;; Interface functions to the backends.
11841
11842 (defun gnus-open-server (method)
11843 (funcall (gnus-get-function method 'open-server)
11844 (nth 1 method) (nthcdr 2 method)))
11845
11846 (defun gnus-close-server (method)
11847 (funcall (gnus-get-function method 'close-server) (nth 1 method)))
11848
11849 (defun gnus-request-list (method)
11850 (funcall (gnus-get-function method 'request-list) (nth 1 method)))
11851
11852 (defun gnus-request-list-newsgroups (method)
11853 (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
11854
11855 (defun gnus-request-newgroups (date method)
11856 (funcall (gnus-get-function method 'request-newgroups)
11857 date (nth 1 method)))
11858
11859 (defun gnus-server-opened (method)
11860 (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
11861
11862 (defun gnus-status-message (method)
11863 (let ((method (if (stringp method) (gnus-find-method-for-group method)
11864 method)))
11865 (funcall (gnus-get-function method 'status-message) (nth 1 method))))
11866
11867 (defun gnus-request-group (group &optional dont-check)
11868 (let ((method (gnus-find-method-for-group group)))
11869 (funcall (gnus-get-function method 'request-group)
11870 (gnus-group-real-name group) (nth 1 method) dont-check)))
11871
11872 (defun gnus-request-asynchronous (group &optional articles)
11873 (let ((method (gnus-find-method-for-group group)))
11874 (funcall (gnus-get-function method 'request-asynchronous)
11875 (gnus-group-real-name group) (nth 1 method) articles)))
11876
11877 (defun gnus-list-active-group (group)
11878 (let ((method (gnus-find-method-for-group group))
11879 (func 'list-active-group))
11880 (and (gnus-check-backend-function func group)
11881 (funcall (gnus-get-function method func)
11882 (gnus-group-real-name group) (nth 1 method)))))
11883
11884 (defun gnus-request-group-description (group)
11885 (let ((method (gnus-find-method-for-group group))
11886 (func 'request-group-description))
11887 (and (gnus-check-backend-function func group)
11888 (funcall (gnus-get-function method func)
11889 (gnus-group-real-name group) (nth 1 method)))))
11890
11891 (defun gnus-close-group (group)
11892 (let ((method (gnus-find-method-for-group group)))
11893 (funcall (gnus-get-function method 'close-group)
11894 (gnus-group-real-name group) (nth 1 method))))
11895
11896 (defun gnus-retrieve-headers (articles group)
11897 (let ((method (gnus-find-method-for-group group)))
11898 (if (and gnus-use-cache (numberp (car articles)))
11899 (gnus-cache-retrieve-headers articles group)
11900 (funcall (gnus-get-function method 'retrieve-headers)
11901 articles (gnus-group-real-name group) (nth 1 method)))))
11902
11903 (defun gnus-retrieve-groups (groups method)
11904 (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
11905
11906 (defun gnus-request-article (article group &optional buffer)
11907 (let ((method (gnus-find-method-for-group group)))
11908 (funcall (gnus-get-function method 'request-article)
11909 article (gnus-group-real-name group) (nth 1 method) buffer)))
11910
11911 (defun gnus-request-head (article group)
11912 (let ((method (gnus-find-method-for-group group)))
11913 (funcall (gnus-get-function method 'request-head)
11914 article (gnus-group-real-name group) (nth 1 method))))
11915
11916 (defun gnus-request-body (article group)
11917 (let ((method (gnus-find-method-for-group group)))
11918 (funcall (gnus-get-function method 'request-body)
11919 article (gnus-group-real-name group) (nth 1 method))))
11920
11921 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11922 (defun gnus-request-post-buffer (post group subject header artbuf
11923 info follow-to respect-poster)
11924 (let* ((info (or info (and group (nth 2 (gnus-gethash
11925 group gnus-newsrc-hashtb)))))
11926 (method
11927 (if (and gnus-post-method
11928 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11929 (memq 'post (assoc
11930 (format "%s" (car (gnus-find-method-for-group
11931 gnus-newsgroup-name)))
11932 gnus-valid-select-methods)))
11933 gnus-post-method
11934 (gnus-find-method-for-group gnus-newsgroup-name))))
11935 (or (gnus-check-server method)
11936 (error "Can't open server %s:%s" (car method) (nth 1 method)))
11937 (let ((mail-self-blind nil)
11938 (mail-archive-file-name nil))
11939 (funcall (gnus-get-function method 'request-post-buffer)
11940 post group subject header artbuf info follow-to
11941 respect-poster))))
11942
11943 (defun gnus-request-post (method &optional force)
11944 (and (stringp method)
11945 (setq method (gnus-server-to-method method)))
11946 (and (not force) gnus-post-method
11947 (memq 'post (assoc (format "%s" (car method))
11948 gnus-valid-select-methods))
11949 (setq method gnus-post-method))
11950 (funcall (gnus-get-function method 'request-post)
11951 (nth 1 method)))
11952
11953 (defun gnus-request-expire-articles (articles group &optional force)
11954 (let ((method (gnus-find-method-for-group group)))
11955 (funcall (gnus-get-function method 'request-expire-articles)
11956 articles (gnus-group-real-name group) (nth 1 method)
11957 force)))
11958
11959 (defun gnus-request-move-article
11960 (article group server accept-function &optional last)
11961 (let ((method (gnus-find-method-for-group group)))
11962 (funcall (gnus-get-function method 'request-move-article)
11963 article (gnus-group-real-name group)
11964 (nth 1 method) accept-function last)))
11965
11966 (defun gnus-request-accept-article (group &optional last)
11967 (goto-char (point-max))
11968 (or (bolp) (insert "\n"))
11969 (let ((func (if (symbolp group) group
11970 (car (gnus-find-method-for-group group)))))
11971 (funcall (intern (format "%s-request-accept-article" func))
11972 (if (stringp group) (gnus-group-real-name group) group)
11973 last)))
11974
11975 (defun gnus-request-replace-article (article group buffer)
11976 (let ((func (car (gnus-find-method-for-group group))))
11977 (funcall (intern (format "%s-request-replace-article" func))
11978 article (gnus-group-real-name group) buffer)))
11979
11980 (defun gnus-request-create-group (group)
11981 (let ((method (gnus-find-method-for-group group)))
11982 (funcall (gnus-get-function method 'request-create-group)
11983 (gnus-group-real-name group) (nth 1 method))))
11984
11985 (defun gnus-member-of-valid (symbol group)
11986 (memq symbol (assoc
11987 (format "%s" (car (gnus-find-method-for-group group)))
11988 gnus-valid-select-methods)))
11989
11990 (defun gnus-secondary-method-p (method)
11991 (let ((methods gnus-secondary-select-methods)
11992 (gmethod (gnus-server-get-method nil method)))
11993 (while (and methods
11994 (not (equal (gnus-server-get-method nil (car methods))
11995 gmethod)))
11996 (setq methods (cdr methods)))
11997 methods))
11998
11999 (defun gnus-find-method-for-group (group &optional info)
12000 (or gnus-override-method
12001 (and (not group)
12002 gnus-select-method)
12003 (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
12004 method)
12005 (if (or (not info)
12006 (not (setq method (nth 4 info))))
12007 (setq method gnus-select-method)
12008 (setq method
12009 (cond ((stringp method)
12010 (gnus-server-to-method method))
12011 ((stringp (car method))
12012 (gnus-server-extend-method group method))
12013 (t
12014 method))))
12015 (gnus-server-add-address method))))
12016
12017 (defun gnus-check-backend-function (func group)
12018 (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
12019 group)))
12020 (fboundp (intern (format "%s-%s" method func)))))
12021
12022 (defun gnus-methods-using (method)
12023 (let ((valids gnus-valid-select-methods)
12024 outs)
12025 (while valids
12026 (if (memq method (car valids))
12027 (setq outs (cons (car valids) outs)))
12028 (setq valids (cdr valids)))
12029 outs))
12030
12031 ;;;
12032 ;;; Active & Newsrc File Handling
12033 ;;;
12034
12035 ;; Newsrc related functions.
12036 ;; Gnus internal format of gnus-newsrc-alist:
12037 ;; (("alt.general" 3 (1 . 1))
12038 ;; ("alt.misc" 3 ((1 . 10) (12 . 15)))
12039 ;; ("alt.test" 7 (1 . 99) (45 57 93)) ...)
12040 ;; The first item is the group name; the second is the subscription
12041 ;; level; the third is either a range of a list of ranges of read
12042 ;; articles, the optional fourth element is a list of marked articles,
12043 ;; the optional fifth element is the select method.
12044 ;;
12045 ;; Gnus internal format of gnus-newsrc-hashtb:
12046 ;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...)
12047 ;; This is the entry for "alt.misc". The first element is the number
12048 ;; of unread articles in "alt.misc". The cdr of this entry is the
12049 ;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is
12050 ;; trivial to remove or add new elements into gnus-newsrc-alist
12051 ;; without scanning the entire list. So, to get the actual information
12052 ;; of "alt.misc", you'd say something like
12053 ;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb))
12054 ;;
12055 ;; Gnus internal format of gnus-active-hashtb:
12056 ;; ((1 . 1))
12057 ;; (5 . 10))
12058 ;; (67 . 99)) ...)
12059 ;; The only element in each entry in this hash table is a range of
12060 ;; (possibly) available articles. (Articles in this range may have
12061 ;; been expired or canceled.)
12062 ;;
12063 ;; Gnus internal format of gnus-killed-list and gnus-zombie-list:
12064 ;; ("alt.misc" "alt.test" "alt.general" ...)
12065
12066 (defun gnus-setup-news (&optional rawfile level)
12067 "Setup news information.
12068 If RAWFILE is non-nil, the .newsrc file will also be read.
12069 If LEVEL is non-nil, the news will be set up at level LEVEL."
12070 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
12071 ;; Clear some variables to re-initialize news information.
12072 (if init (setq gnus-newsrc-alist nil
12073 gnus-active-hashtb nil))
12074
12075 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
12076 (if init (gnus-read-newsrc-file rawfile))
12077
12078 ;; If we don't read the complete active file, we fill in the
12079 ;; hashtb here.
12080 (if (or (null gnus-read-active-file)
12081 (eq gnus-read-active-file 'some))
12082 (gnus-update-active-hashtb-from-killed))
12083
12084 ;; Read the active file and create `gnus-active-hashtb'.
12085 ;; If `gnus-read-active-file' is nil, then we just create an empty
12086 ;; hash table. The partial filling out of the hash table will be
12087 ;; done in `gnus-get-unread-articles'.
12088 (and gnus-read-active-file
12089 (not level)
12090 (gnus-read-active-file))
12091
12092 (or gnus-active-hashtb
12093 (setq gnus-active-hashtb (make-vector 4095 0)))
12094
12095 ;; Possibly eval the dribble file.
12096 (and init gnus-use-dribble-file (gnus-dribble-eval-file))
12097
12098 (gnus-update-format-specifications)
12099
12100 ;; Find new newsgroups and treat them.
12101 (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level)
12102 (gnus-check-server gnus-select-method))
12103 (gnus-find-new-newsgroups))
12104
12105 ;; Find the number of unread articles in each non-dead group.
12106 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
12107 (gnus-get-unread-articles (or level (1+ gnus-level-subscribed))))
12108
12109 (if (and init gnus-check-bogus-newsgroups
12110 gnus-read-active-file (not level)
12111 (gnus-server-opened gnus-select-method))
12112 (gnus-check-bogus-newsgroups))))
12113
12114 (defun gnus-find-new-newsgroups ()
12115 "Search for new newsgroups and add them.
12116 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
12117 The `-n' option line from .newsrc is respected."
12118 (interactive)
12119 (or (gnus-check-first-time-used)
12120 (if (or (consp gnus-check-new-newsgroups)
12121 (eq gnus-check-new-newsgroups 'ask-server))
12122 (gnus-ask-server-for-new-groups)
12123 (let ((groups 0)
12124 group new-newsgroups)
12125 (gnus-message 5 "Looking for new newsgroups...")
12126 (or gnus-have-read-active-file (gnus-read-active-file))
12127 (setq gnus-newsrc-last-checked-date (current-time-string))
12128 (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed))
12129 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
12130 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
12131 (mapatoms
12132 (lambda (sym)
12133 (if (or (null (setq group (symbol-name sym)))
12134 (null (symbol-value sym))
12135 (gnus-gethash group gnus-killed-hashtb)
12136 (gnus-gethash group gnus-newsrc-hashtb))
12137 ()
12138 (let ((do-sub (gnus-matches-options-n group)))
12139 (cond
12140 ((eq do-sub 'subscribe)
12141 (setq groups (1+ groups))
12142 (gnus-sethash group group gnus-killed-hashtb)
12143 (funcall gnus-subscribe-options-newsgroup-method group))
12144 ((eq do-sub 'ignore)
12145 nil)
12146 (t
12147 (setq groups (1+ groups))
12148 (gnus-sethash group group gnus-killed-hashtb)
12149 (if gnus-subscribe-hierarchical-interactive
12150 (setq new-newsgroups (cons group new-newsgroups))
12151 (funcall gnus-subscribe-newsgroup-method group)))))))
12152 gnus-active-hashtb)
12153 (if new-newsgroups
12154 (gnus-subscribe-hierarchical-interactive new-newsgroups))
12155 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12156 (if (> groups 0)
12157 (gnus-message 6 "%d new newsgroup%s arrived."
12158 groups (if (> groups 1) "s have" " has"))
12159 (gnus-message 6 "No new newsgroups."))))))
12160
12161 (defun gnus-matches-options-n (group)
12162 ;; Returns `subscribe' if the group is to be unconditionally
12163 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
12164 ;; no match for the group.
12165
12166 ;; First we check the two user variables.
12167 (cond
12168 ((and gnus-options-subscribe
12169 (string-match gnus-options-subscribe group))
12170 'subscribe)
12171 ((and gnus-options-not-subscribe
12172 (string-match gnus-options-not-subscribe group))
12173 'ignore)
12174 ;; Then we go through the list that was retrieved from the .newsrc
12175 ;; file. This list has elements on the form
12176 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
12177 ;; is in the reverse order of the options line) is returned.
12178 (t
12179 (let ((regs gnus-newsrc-options-n))
12180 (while (and regs
12181 (not (string-match (car (car regs)) group)))
12182 (setq regs (cdr regs)))
12183 (and regs (cdr (car regs)))))))
12184
12185 (defun gnus-ask-server-for-new-groups ()
12186 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
12187 (methods (cons gnus-select-method
12188 (append
12189 (and (consp gnus-check-new-newsgroups)
12190 gnus-check-new-newsgroups)
12191 gnus-secondary-select-methods)))
12192 (groups 0)
12193 (new-date (current-time-string))
12194 (hashtb (gnus-make-hashtable 100))
12195 group new-newsgroups got-new method)
12196 ;; Go through both primary and secondary select methods and
12197 ;; request new newsgroups.
12198 (while methods
12199 (setq method (gnus-server-get-method nil (car methods)))
12200 (and (gnus-check-server method)
12201 (gnus-request-newgroups date method)
12202 (save-excursion
12203 (setq got-new t)
12204 (set-buffer nntp-server-buffer)
12205 ;; Enter all the new groups in a hashtable.
12206 (gnus-active-to-gnus-format method hashtb 'ignore)))
12207 (setq methods (cdr methods)))
12208 (and got-new (setq gnus-newsrc-last-checked-date new-date))
12209 ;; Now all new groups from all select methods are in `hashtb'.
12210 (mapatoms
12211 (lambda (group-sym)
12212 (setq group (symbol-name group-sym))
12213 (if (or (null group)
12214 (null (symbol-value group-sym))
12215 (gnus-gethash group gnus-newsrc-hashtb)
12216 (member group gnus-zombie-list)
12217 (member group gnus-killed-list))
12218 ;; The group is already known.
12219 ()
12220 (and (symbol-value group-sym)
12221 (gnus-sethash group (symbol-value group-sym) gnus-active-hashtb))
12222 (let ((do-sub (gnus-matches-options-n group)))
12223 (cond ((eq do-sub 'subscribe)
12224 (setq groups (1+ groups))
12225 (gnus-sethash group group gnus-killed-hashtb)
12226 (funcall
12227 gnus-subscribe-options-newsgroup-method group))
12228 ((eq do-sub 'ignore)
12229 nil)
12230 (t
12231 (setq groups (1+ groups))
12232 (gnus-sethash group group gnus-killed-hashtb)
12233 (if gnus-subscribe-hierarchical-interactive
12234 (setq new-newsgroups (cons group new-newsgroups))
12235 (funcall gnus-subscribe-newsgroup-method group)))))))
12236 hashtb)
12237 (if new-newsgroups
12238 (gnus-subscribe-hierarchical-interactive new-newsgroups))
12239 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12240 (if (> groups 0)
12241 (gnus-message 6 "%d new newsgroup%s arrived."
12242 groups (if (> groups 1) "s have" " has")))
12243 got-new))
12244
12245 (defun gnus-check-first-time-used ()
12246 (if (or (> (length gnus-newsrc-alist) 1)
12247 (file-exists-p gnus-startup-file)
12248 (file-exists-p (concat gnus-startup-file ".el"))
12249 (file-exists-p (concat gnus-startup-file ".eld")))
12250 nil
12251 (gnus-message 6 "First time user; subscribing you to default groups")
12252 (or gnus-have-read-active-file (gnus-read-active-file))
12253 (setq gnus-newsrc-last-checked-date (current-time-string))
12254 (let ((groups gnus-default-subscribed-newsgroups)
12255 group)
12256 (if (eq groups t)
12257 nil
12258 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
12259 (mapatoms
12260 (lambda (sym)
12261 (if (null (setq group (symbol-name sym)))
12262 ()
12263 (let ((do-sub (gnus-matches-options-n group)))
12264 (cond
12265 ((eq do-sub 'subscribe)
12266 (gnus-sethash group group gnus-killed-hashtb)
12267 (funcall gnus-subscribe-options-newsgroup-method group))
12268 ((eq do-sub 'ignore)
12269 nil)
12270 (t
12271 (setq gnus-killed-list (cons group gnus-killed-list)))))))
12272 gnus-active-hashtb)
12273 (while groups
12274 (if (gnus-gethash (car groups) gnus-active-hashtb)
12275 (gnus-group-change-level
12276 (car groups) gnus-level-default-subscribed gnus-level-killed))
12277 (setq groups (cdr groups)))
12278 (gnus-group-make-help-group)
12279 (and gnus-novice-user
12280 (gnus-message 7 "`A k' to list killed groups"))))))
12281
12282 (defun gnus-subscribe-group (group previous &optional method)
12283 (gnus-group-change-level
12284 (if method
12285 (list t group gnus-level-default-subscribed nil nil method)
12286 group)
12287 gnus-level-default-subscribed gnus-level-killed previous t))
12288
12289 ;; `gnus-group-change-level' is the fundamental function for changing
12290 ;; subscription levels of newsgroups. This might mean just changing
12291 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
12292 ;; again, which subscribes/unsubscribes a group, which is equally
12293 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
12294 ;; from 8-9 to 1-7 means that you remove the group from the list of
12295 ;; killed (or zombie) groups and add them to the (kinda) subscribed
12296 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
12297 ;; which is trivial.
12298 ;; ENTRY can either be a string (newsgroup name) or a list (if
12299 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
12300 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
12301 ;; entries.
12302 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
12303 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
12304 ;; after.
12305 (defun gnus-group-change-level (entry level &optional oldlevel
12306 previous fromkilled)
12307 (let (group info active num)
12308 ;; Glean what info we can from the arguments
12309 (if (consp entry)
12310 (if fromkilled (setq group (nth 1 entry))
12311 (setq group (car (nth 2 entry))))
12312 (setq group entry))
12313 (if (and (stringp entry)
12314 oldlevel
12315 (< oldlevel gnus-level-zombie))
12316 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
12317 (if (and (not oldlevel)
12318 (consp entry))
12319 (setq oldlevel (car (cdr (nth 2 entry)))))
12320 (if (stringp previous)
12321 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
12322
12323 (if (and (>= oldlevel gnus-level-zombie)
12324 (gnus-gethash group gnus-newsrc-hashtb))
12325 ;; We are trying to subscribe a group that is already
12326 ;; subscribed.
12327 () ; Do nothing.
12328
12329 (or (gnus-ephemeral-group-p group)
12330 (gnus-dribble-enter
12331 (format "(gnus-group-change-level %S %S %S %S %S)"
12332 group level oldlevel (car (nth 2 previous)) fromkilled)))
12333
12334 ;; Then we remove the newgroup from any old structures, if needed.
12335 ;; If the group was killed, we remove it from the killed or zombie
12336 ;; list. If not, and it is in fact going to be killed, we remove
12337 ;; it from the newsrc hash table and assoc.
12338 (cond ((>= oldlevel gnus-level-zombie)
12339 (if (= oldlevel gnus-level-zombie)
12340 (setq gnus-zombie-list (delete group gnus-zombie-list))
12341 (setq gnus-killed-list (delete group gnus-killed-list))))
12342 (t
12343 (if (and (>= level gnus-level-zombie)
12344 entry)
12345 (progn
12346 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
12347 (if (nth 3 entry)
12348 (setcdr (gnus-gethash (car (nth 3 entry))
12349 gnus-newsrc-hashtb)
12350 (cdr entry)))
12351 (setcdr (cdr entry) (cdr (cdr (cdr entry))))))))
12352
12353 ;; Finally we enter (if needed) the list where it is supposed to
12354 ;; go, and change the subscription level. If it is to be killed,
12355 ;; we enter it into the killed or zombie list.
12356 (cond ((>= level gnus-level-zombie)
12357 ;; Remove from the hash table.
12358 (gnus-sethash group nil gnus-newsrc-hashtb)
12359 (or (gnus-group-foreign-p group)
12360 ;; We do not enter foreign groups into the list of dead
12361 ;; groups.
12362 (if (= level gnus-level-zombie)
12363 (setq gnus-zombie-list (cons group gnus-zombie-list))
12364 (setq gnus-killed-list (cons group gnus-killed-list)))))
12365 (t
12366 ;; If the list is to be entered into the newsrc assoc, and
12367 ;; it was killed, we have to create an entry in the newsrc
12368 ;; hashtb format and fix the pointers in the newsrc assoc.
12369 (if (>= oldlevel gnus-level-zombie)
12370 (progn
12371 (if (listp entry)
12372 (progn
12373 (setq info (cdr entry))
12374 (setq num (car entry)))
12375 (setq active (gnus-gethash group gnus-active-hashtb))
12376 (setq num
12377 (if active (- (1+ (cdr active)) (car active)) t))
12378 ;; Check whether the group is foreign. If so, the
12379 ;; foreign select method has to be entered into the
12380 ;; info.
12381 (let ((method (gnus-group-method-name group)))
12382 (if (eq method gnus-select-method)
12383 (setq info (list group level nil))
12384 (setq info (list group level nil nil method)))))
12385 (or previous
12386 (setq previous
12387 (let ((p gnus-newsrc-alist))
12388 (while (cdr (cdr p))
12389 (setq p (cdr p)))
12390 p)))
12391 (setq entry (cons info (cdr (cdr previous))))
12392 (if (cdr previous)
12393 (progn
12394 (setcdr (cdr previous) entry)
12395 (gnus-sethash group (cons num (cdr previous))
12396 gnus-newsrc-hashtb))
12397 (setcdr previous entry)
12398 (gnus-sethash group (cons num previous)
12399 gnus-newsrc-hashtb))
12400 (if (cdr entry)
12401 (setcdr (gnus-gethash (car (car (cdr entry)))
12402 gnus-newsrc-hashtb)
12403 entry)))
12404 ;; It was alive, and it is going to stay alive, so we
12405 ;; just change the level and don't change any pointers or
12406 ;; hash table entries.
12407 (setcar (cdr (car (cdr (cdr entry)))) level)))))))
12408
12409 (defun gnus-kill-newsgroup (newsgroup)
12410 "Obsolete function. Kills a newsgroup."
12411 (gnus-group-change-level
12412 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
12413
12414 (defun gnus-check-bogus-newsgroups (&optional confirm)
12415 "Remove bogus newsgroups.
12416 If CONFIRM is non-nil, the user has to confirm the deletion of every
12417 newsgroup."
12418 (let ((newsrc (cdr gnus-newsrc-alist))
12419 bogus group entry)
12420 (gnus-message 5 "Checking bogus newsgroups...")
12421 (or gnus-have-read-active-file (gnus-read-active-file))
12422 ;; Find all bogus newsgroup that are subscribed.
12423 (while newsrc
12424 (setq group (car (car newsrc)))
12425 (if (or (gnus-gethash group gnus-active-hashtb) ; Active
12426 (nth 4 (car newsrc)) ; Foreign
12427 (and confirm
12428 (not (gnus-y-or-n-p
12429 (format "Remove bogus newsgroup: %s " group)))))
12430 ;; Don't remove.
12431 ()
12432 ;; Found a bogus newsgroup.
12433 (setq bogus (cons group bogus)))
12434 (setq newsrc (cdr newsrc)))
12435 ;; Remove all bogus subscribed groups by first killing them, and
12436 ;; then removing them from the list of killed groups.
12437 (while bogus
12438 (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb))
12439 (progn
12440 (gnus-group-change-level entry gnus-level-killed)
12441 (setq gnus-killed-list (delete (car bogus) gnus-killed-list))))
12442 (setq bogus (cdr bogus)))
12443 ;; Then we remove all bogus groups from the list of killed and
12444 ;; zombie groups. They are are removed without confirmation.
12445 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
12446 killed)
12447 (while dead-lists
12448 (setq killed (symbol-value (car dead-lists)))
12449 (while killed
12450 (setq group (car killed))
12451 (or (gnus-gethash group gnus-active-hashtb)
12452 ;; The group is bogus.
12453 (set (car dead-lists)
12454 (delete group (symbol-value (car dead-lists)))))
12455 (setq killed (cdr killed)))
12456 (setq dead-lists (cdr dead-lists))))
12457 (gnus-message 5 "Checking bogus newsgroups...done")))
12458
12459 (defun gnus-check-duplicate-killed-groups ()
12460 "Remove duplicates from the list of killed groups."
12461 (interactive)
12462 (let ((killed gnus-killed-list))
12463 (while killed
12464 (gnus-message 9 "%d" (length killed))
12465 (setcdr killed (delete (car killed) (cdr killed)))
12466 (setq killed (cdr killed)))))
12467
12468 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
12469 ;; and compute how many unread articles there are in each group.
12470 (defun gnus-get-unread-articles (&optional level)
12471 (let* ((newsrc (cdr gnus-newsrc-alist))
12472 (level (or level (1+ gnus-level-subscribed)))
12473 (foreign-level
12474 (min
12475 (cond ((and gnus-activate-foreign-newsgroups
12476 (not (numberp gnus-activate-foreign-newsgroups)))
12477 (1+ gnus-level-subscribed))
12478 ((numberp gnus-activate-foreign-newsgroups)
12479 gnus-activate-foreign-newsgroups)
12480 (t 0))
12481 level))
12482 info group active virtuals method)
12483 (gnus-message 5 "Checking new news...")
12484
12485 (while newsrc
12486 (setq info (car newsrc)
12487 group (car info)
12488 active (gnus-gethash group gnus-active-hashtb))
12489
12490 ;; Check newsgroups. If the user doesn't want to check them, or
12491 ;; they can't be checked (for instance, if the news server can't
12492 ;; be reached) we just set the number of unread articles in this
12493 ;; newsgroup to t. This means that Gnus thinks that there are
12494 ;; unread articles, but it has no idea how many.
12495 (if (and (setq method (nth 4 info))
12496 (not (gnus-server-equal gnus-select-method
12497 (gnus-server-get-method nil method)))
12498 (not (gnus-secondary-method-p method)))
12499 ;; These groups are foreign. Check the level.
12500 (if (<= (nth 1 info) foreign-level)
12501 (if (eq (car (if (stringp method)
12502 (gnus-server-to-method method)
12503 (nth 4 info))) 'nnvirtual)
12504 ;; We have to activate the virtual groups after all
12505 ;; the others, so we just pop them on a list for
12506 ;; now.
12507 (setq virtuals (cons info virtuals))
12508 (and (setq active (gnus-activate-group (car info)))
12509 ;; Close the groups as we look at them!
12510 (gnus-close-group group))))
12511
12512 ;; These groups are native or secondary.
12513 (if (and (not gnus-read-active-file)
12514 (<= (nth 1 info) level))
12515 (progn
12516 (or gnus-read-active-file (gnus-check-server method))
12517 (setq active (gnus-activate-group (car info))))))
12518
12519 (if active
12520 (gnus-get-unread-articles-in-group info active)
12521 ;; The group couldn't be reached, so we nix out the number of
12522 ;; unread articles and stuff.
12523 (gnus-sethash group nil gnus-active-hashtb)
12524 (setcar (gnus-gethash group gnus-newsrc-hashtb) t))
12525
12526 (setq newsrc (cdr newsrc)))
12527
12528 ;; Activate the virtual groups. This has to be done after all the
12529 ;; other groups.
12530 ;; !!! If one virtual group contains another virtual group, even
12531 ;; doing it this way might cause problems.
12532 (while virtuals
12533 (and (setq active (gnus-activate-group (car (car virtuals))))
12534 (gnus-get-unread-articles-in-group (car virtuals) active))
12535 (setq virtuals (cdr virtuals)))
12536
12537 (gnus-message 5 "Checking new news...done")))
12538
12539 ;; Create a hash table out of the newsrc alist. The `car's of the
12540 ;; alist elements are used as keys.
12541 (defun gnus-make-hashtable-from-newsrc-alist ()
12542 (let ((alist gnus-newsrc-alist)
12543 (ohashtb gnus-newsrc-hashtb)
12544 prev)
12545 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
12546 (setq alist
12547 (setq prev (setq gnus-newsrc-alist
12548 (if (equal (car (car gnus-newsrc-alist))
12549 "dummy.group")
12550 gnus-newsrc-alist
12551 (cons (list "dummy.group" 0 nil) alist)))))
12552 (while alist
12553 (gnus-sethash (car (car alist))
12554 (cons (and ohashtb (car (gnus-gethash
12555 (car (car alist)) ohashtb)))
12556 prev) gnus-newsrc-hashtb)
12557 (setq prev alist
12558 alist (cdr alist)))))
12559
12560 (defun gnus-make-hashtable-from-killed ()
12561 "Create a hash table from the killed and zombie lists."
12562 (let ((lists '(gnus-killed-list gnus-zombie-list))
12563 list)
12564 (setq gnus-killed-hashtb
12565 (gnus-make-hashtable
12566 (+ (length gnus-killed-list) (length gnus-zombie-list))))
12567 (while lists
12568 (setq list (symbol-value (car lists)))
12569 (setq lists (cdr lists))
12570 (while list
12571 (gnus-sethash (car list) (car list) gnus-killed-hashtb)
12572 (setq list (cdr list))))))
12573
12574 (defun gnus-get-unread-articles-in-group (info active)
12575 (let* ((range (nth 2 info))
12576 (num 0)
12577 (marked (nth 3 info)))
12578 ;; If a cache is present, we may have to alter the active info.
12579 (and gnus-use-cache
12580 (gnus-cache-possibly-alter-active (car info) active))
12581 ;; Modify the list of read articles according to what articles
12582 ;; are available; then tally the unread articles and add the
12583 ;; number to the group hash table entry.
12584 (cond
12585 ((zerop (cdr active))
12586 (setq num 0))
12587 ((not range)
12588 (setq num (- (1+ (cdr active)) (car active))))
12589 ((not (listp (cdr range)))
12590 ;; Fix a single (num . num) range according to the
12591 ;; active hash table.
12592 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
12593 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
12594 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
12595 ;; Compute number of unread articles.
12596 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
12597 (t
12598 ;; The read list is a list of ranges. Fix them according to
12599 ;; the active hash table.
12600 ;; First peel off any elements that are below the lower
12601 ;; active limit.
12602 (while (and (cdr range)
12603 (>= (car active)
12604 (or (and (atom (car (cdr range))) (car (cdr range)))
12605 (car (car (cdr range))))))
12606 (if (numberp (car range))
12607 (setcar range
12608 (cons (car range)
12609 (or (and (numberp (car (cdr range)))
12610 (car (cdr range)))
12611 (cdr (car (cdr range))))))
12612 (setcdr (car range)
12613 (or (and (numberp (nth 1 range)) (nth 1 range))
12614 (cdr (car (cdr range))))))
12615 (setcdr range (cdr (cdr range))))
12616 ;; Adjust the first element to be the same as the lower limit.
12617 (if (and (not (atom (car range)))
12618 (< (cdr (car range)) (car active)))
12619 (setcdr (car range) (1- (car active))))
12620 ;; Then we want to peel off any elements that are higher
12621 ;; than the upper active limit.
12622 (let ((srange range))
12623 ;; Go past all legal elements.
12624 (while (and (cdr srange)
12625 (<= (or (and (atom (car (cdr srange)))
12626 (car (cdr srange)))
12627 (car (car (cdr srange)))) (cdr active)))
12628 (setq srange (cdr srange)))
12629 (if (cdr srange)
12630 ;; Nuke all remaining illegal elements.
12631 (setcdr srange nil))
12632
12633 ;; Adjust the final element.
12634 (if (and (not (atom (car srange)))
12635 (> (cdr (car srange)) (cdr active)))
12636 (setcdr (car srange) (cdr active))))
12637 ;; Compute the number of unread articles.
12638 (while range
12639 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
12640 (cdr (car range))))
12641 (or (and (atom (car range)) (car range))
12642 (car (car range))))))
12643 (setq range (cdr range)))
12644 (setq num (max 0 (- (cdr active) num)))))
12645 (and info
12646 (progn
12647 (and (assq 'tick marked)
12648 (inline (gnus-remove-illegal-marked-articles
12649 (assq 'tick marked) (nth 2 info))))
12650 (and (assq 'dormant marked)
12651 (inline (gnus-remove-illegal-marked-articles
12652 (assq 'dormant marked) (nth 2 info))))
12653 (setcar
12654 (gnus-gethash (car info) gnus-newsrc-hashtb)
12655 (setq num (max 0 (- num (length (cdr (assq 'tick marked)))
12656 (length (cdr (assq 'dormant marked)))))))))
12657 num))
12658
12659 (defun gnus-remove-illegal-marked-articles (marked ranges)
12660 (let ((m (cdr marked)))
12661 ;; Make sure that all ticked articles are a subset of the unread
12662 ;; articles.
12663 (while m
12664 (if (gnus-member-of-range (car m) ranges)
12665 (setcdr marked (cdr m))
12666 (setq marked m))
12667 (setq m (cdr m)))))
12668
12669 (defun gnus-activate-group (group)
12670 ;; Check whether a group has been activated or not.
12671 (let ((method (gnus-find-method-for-group group))
12672 active)
12673 (and (gnus-check-server method)
12674 ;; We escape all bugs and quit here to make it possible to
12675 ;; continue if a group is so out-there that it reports bugs
12676 ;; and stuff.
12677 (condition-case ()
12678 (gnus-request-group group)
12679 (error nil)
12680 (quit nil))
12681 (save-excursion
12682 (set-buffer nntp-server-buffer)
12683 (goto-char (point-min))
12684 ;; Parse the result we got from `gnus-request-group'.
12685 (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
12686 (progn
12687 (goto-char (match-beginning 1))
12688 (gnus-sethash
12689 group (setq active (cons (read (current-buffer))
12690 (read (current-buffer))))
12691 gnus-active-hashtb))
12692 ;; Return the new active info.
12693 active)))))
12694
12695 (defun gnus-update-read-articles
12696 (group unread unselected ticked &optional domarks replied expirable killed
12697 dormant bookmark score)
12698 "Update the list of read and ticked articles in GROUP using the
12699 UNREAD and TICKED lists.
12700 Note: UNSELECTED has to be sorted over `<'.
12701 Returns whether the updating was successful."
12702 (let* ((active (or gnus-newsgroup-active
12703 (gnus-gethash group gnus-active-hashtb)))
12704 (entry (gnus-gethash group gnus-newsrc-hashtb))
12705 (info (nth 2 entry))
12706 (marked (nth 3 info))
12707 (prev 1)
12708 (unread (sort (copy-sequence unread) (function <)))
12709 read)
12710 (if (or (not info) (not active))
12711 ;; There is no info on this group if it was, in fact,
12712 ;; killed. Gnus stores no information on killed groups, so
12713 ;; there's nothing to be done.
12714 ;; One could store the information somewhere temporarily,
12715 ;; perhaps... Hmmm...
12716 ()
12717 ;; Remove any negative articles numbers.
12718 (while (and unread (< (car unread) 0))
12719 (setq unread (cdr unread)))
12720 ;; Remove any expired article numbers
12721 (while (and unread (< (car unread) (car active)))
12722 (setq unread (cdr unread)))
12723 (while (and ticked (< (car ticked) (car active)))
12724 (setq ticked (cdr ticked)))
12725 (while (and dormant (< (car dormant) (car active)))
12726 (setq dormant (cdr dormant)))
12727 (setq unread (sort (append unselected unread) '<))
12728 ;; Weed out duplicates.
12729 (let ((un unread))
12730 (while (cdr un)
12731 (if (eq (car un) (car (cdr un)))
12732 (setcdr un (cdr (cdr un)))
12733 (setq un (cdr un)))))
12734 ;; Compute the ranges of read articles by looking at the list of
12735 ;; unread articles.
12736 (while unread
12737 (if (/= (car unread) prev)
12738 (setq read (cons (if (= prev (1- (car unread))) prev
12739 (cons prev (1- (car unread)))) read)))
12740 (setq prev (1+ (car unread)))
12741 (setq unread (cdr unread)))
12742 (if (<= prev (cdr active))
12743 (setq read (cons (cons prev (cdr active)) read)))
12744 ;; Enter this list into the group info.
12745 (setcar (cdr (cdr info))
12746 (if (> (length read) 1) (nreverse read) read))
12747 ;; Enter the list of ticked articles.
12748 (gnus-set-marked-articles
12749 info ticked
12750 (if domarks replied (cdr (assq 'reply marked)))
12751 (if domarks expirable (cdr (assq 'expire marked)))
12752 (if domarks killed (cdr (assq 'killed marked)))
12753 (if domarks dormant (cdr (assq 'dormant marked)))
12754 (if domarks bookmark (cdr (assq 'bookmark marked)))
12755 (if domarks score (cdr (assq 'score marked))))
12756 ;; Set the number of unread articles in gnus-newsrc-hashtb.
12757 (gnus-get-unread-articles-in-group
12758 info (gnus-gethash group gnus-active-hashtb))
12759 t)))
12760
12761 (defun gnus-make-articles-unread (group articles)
12762 "Mark ARTICLES in GROUP as unread."
12763 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
12764 (gnus-gethash (gnus-group-real-name group)
12765 gnus-newsrc-hashtb))))
12766 (ranges (nth 2 info))
12767 news)
12768 (while articles
12769 (and (gnus-member-of-range (car articles) ranges)
12770 (setq news (cons (car articles) news)))
12771 (setq articles (cdr articles)))
12772 (if (not news)
12773 ()
12774 (setcar (nthcdr 2 info)
12775 (gnus-remove-from-range (nth 2 info) (nreverse news)))
12776 (gnus-group-update-group group t))))
12777
12778 ;; Enter all dead groups into the hashtb.
12779 (defun gnus-update-active-hashtb-from-killed ()
12780 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
12781 (lists (list gnus-killed-list gnus-zombie-list))
12782 killed)
12783 (while lists
12784 (setq killed (car lists))
12785 (while killed
12786 (gnus-sethash (car killed) nil hashtb)
12787 (setq killed (cdr killed)))
12788 (setq lists (cdr lists)))))
12789
12790 ;; Get the active file(s) from the backend(s).
12791 (defun gnus-read-active-file ()
12792 (gnus-group-set-mode-line)
12793 (let ((methods (if (gnus-check-server gnus-select-method)
12794 ;; The native server is available.
12795 (cons gnus-select-method gnus-secondary-select-methods)
12796 ;; The native server is down, so we just do the
12797 ;; secondary ones.
12798 gnus-secondary-select-methods))
12799 list-type)
12800 (setq gnus-have-read-active-file nil)
12801 (save-excursion
12802 (set-buffer nntp-server-buffer)
12803 (while methods
12804 (let* ((method (gnus-server-get-method nil (car methods)))
12805 (where (nth 1 method))
12806 (mesg (format "Reading active file%s via %s..."
12807 (if (and where (not (zerop (length where))))
12808 (concat " from " where) "")
12809 (car method))))
12810 (gnus-message 5 mesg)
12811 (if (not (gnus-check-server method))
12812 ()
12813 (cond
12814 ((and (eq gnus-read-active-file 'some)
12815 (gnus-check-backend-function 'retrieve-groups (car method)))
12816 (let ((newsrc (cdr gnus-newsrc-alist))
12817 (gmethod (gnus-server-get-method nil method))
12818 groups)
12819 (while newsrc
12820 (and (gnus-server-equal
12821 (gnus-find-method-for-group
12822 (car (car newsrc)) (car newsrc))
12823 gmethod)
12824 (setq groups (cons (gnus-group-real-name
12825 (car (car newsrc))) groups)))
12826 (setq newsrc (cdr newsrc)))
12827 (gnus-check-server method)
12828 (setq list-type (gnus-retrieve-groups groups method))
12829 (cond
12830 ((not list-type)
12831 (gnus-message
12832 1 "Cannot read partial active file from %s server."
12833 (car method))
12834 (ding)
12835 (sit-for 2))
12836 ((eq list-type 'active)
12837 (gnus-active-to-gnus-format method gnus-active-hashtb))
12838 (t
12839 (gnus-groups-to-gnus-format method gnus-active-hashtb)))))
12840 (t
12841 (if (not (gnus-request-list method))
12842 (progn
12843 (gnus-message 1 "Cannot read active file from %s server."
12844 (car method))
12845 (ding))
12846 (gnus-active-to-gnus-format method)
12847 ;; We mark this active file as read.
12848 (setq gnus-have-read-active-file
12849 (cons method gnus-have-read-active-file))
12850 (gnus-message 5 "%sdone" mesg))))))
12851 (setq methods (cdr methods))))))
12852
12853 ;; Read an active file and place the results in `gnus-active-hashtb'.
12854 (defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors)
12855 (let ((cur (current-buffer))
12856 (hashtb (or hashtb
12857 (if (and gnus-active-hashtb
12858 (not (equal method gnus-select-method)))
12859 gnus-active-hashtb
12860 (setq gnus-active-hashtb
12861 (if (equal method gnus-select-method)
12862 (gnus-make-hashtable
12863 (count-lines (point-min) (point-max)))
12864 (gnus-make-hashtable 4096))))))
12865 (flag-hashtb (gnus-make-hashtable 60)))
12866 ;; Delete unnecessary lines.
12867 (goto-char (point-min))
12868 (while (search-forward "\nto." nil t)
12869 (delete-region (1+ (match-beginning 0))
12870 (progn (forward-line 1) (point))))
12871 (or (string= gnus-ignored-newsgroups "")
12872 (progn
12873 (goto-char (point-min))
12874 (delete-matching-lines gnus-ignored-newsgroups)))
12875 ;; Make the group names readable as a lisp expression even if they
12876 ;; contain special characters.
12877 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
12878 (goto-char (point-max))
12879 (while (re-search-backward "[][';?()#]" nil t)
12880 (insert ?\\))
12881 ;; If these are groups from a foreign select method, we insert the
12882 ;; group prefix in front of the group names.
12883 (and method (not (gnus-server-equal
12884 (gnus-server-get-method nil method)
12885 (gnus-server-get-method nil gnus-select-method)))
12886 (let ((prefix (gnus-group-prefixed-name "" method)))
12887 (goto-char (point-min))
12888 (while (and (not (eobp))
12889 (progn (insert prefix)
12890 (zerop (forward-line 1)))))))
12891 ;; Store the active file in a hash table.
12892 (goto-char (point-min))
12893 (if (string-match "%[oO]" gnus-group-line-format)
12894 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
12895 ;; If we want information on moderated groups, we use this
12896 ;; loop...
12897 (let* ((mod-hashtb (make-vector 7 0))
12898 (m (intern "m" mod-hashtb))
12899 group max min)
12900 (while (not (eobp))
12901 (condition-case nil
12902 (progn
12903 (narrow-to-region (point) (gnus-point-at-eol))
12904 (setq group (let ((obarray hashtb)) (read cur)))
12905 (if (and (numberp (setq max (read cur)))
12906 (numberp (setq min (read cur)))
12907 (progn
12908 (skip-chars-forward " \t")
12909 (not
12910 (or (= (following-char) ?=)
12911 (= (following-char) ?x)
12912 (= (following-char) ?j)))))
12913 (set group (cons min max))
12914 (set group nil))
12915 ;; Enter moderated groups into a list.
12916 (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
12917 (setq gnus-moderated-list
12918 (cons (symbol-name group) gnus-moderated-list))))
12919 (error
12920 (and group
12921 (symbolp group)
12922 (set group nil))))
12923 (widen)
12924 (forward-line 1)))
12925 ;; And if we do not care about moderation, we use this loop,
12926 ;; which is faster.
12927 (let (group max min)
12928 (while (not (eobp))
12929 (condition-case ()
12930 (progn
12931 (narrow-to-region (point) (gnus-point-at-eol))
12932 ;; group gets set to a symbol interned in the hash table
12933 ;; (what a hack!!) - jwz
12934 (setq group (let ((obarray hashtb)) (read cur)))
12935 (if (and (numberp (setq max (read cur)))
12936 (numberp (setq min (read cur)))
12937 (progn
12938 (skip-chars-forward " \t")
12939 (not
12940 (or (= (following-char) ?=)
12941 (= (following-char) ?x)
12942 (= (following-char) ?j)))))
12943 (set group (cons min max))
12944 (set group nil)))
12945 (error
12946 (progn
12947 (and group
12948 (symbolp group)
12949 (set group nil))
12950 (or ignore-errors
12951 (gnus-message 3 "Warning - illegal active: %s"
12952 (buffer-substring
12953 (gnus-point-at-bol) (gnus-point-at-eol)))))))
12954 (widen)
12955 (forward-line 1))))))
12956
12957 (defun gnus-groups-to-gnus-format (method &optional hashtb)
12958 ;; Parse a "groups" active file.
12959 (let ((cur (current-buffer))
12960 (hashtb (or hashtb
12961 (if (and method gnus-active-hashtb)
12962 gnus-active-hashtb
12963 (setq gnus-active-hashtb
12964 (gnus-make-hashtable
12965 (count-lines (point-min) (point-max)))))))
12966 (prefix (and method
12967 (not (gnus-server-equal
12968 (gnus-server-get-method nil method)
12969 (gnus-server-get-method nil gnus-select-method)))
12970 (gnus-group-prefixed-name "" method))))
12971
12972 (goto-char (point-min))
12973 ;; We split this into to separate loops, one with the prefix
12974 ;; and one without to speed the reading up somewhat.
12975 (if prefix
12976 (let (min max opoint group)
12977 (while (not (eobp))
12978 (condition-case ()
12979 (progn
12980 (read cur) (read cur)
12981 (setq min (read cur)
12982 max (read cur)
12983 opoint (point))
12984 (skip-chars-forward " \t")
12985 (insert prefix)
12986 (goto-char opoint)
12987 (set (let ((obarray hashtb)) (read cur))
12988 (cons min max)))
12989 (error (and group (symbolp group) (set group nil))))
12990 (forward-line 1)))
12991 (let (min max group)
12992 (while (not (eobp))
12993 (condition-case ()
12994 (if (= (following-char) ?2)
12995 (progn
12996 (read cur) (read cur)
12997 (setq min (read cur)
12998 max (read cur))
12999 (set (setq group (let ((obarray hashtb)) (read cur)))
13000 (cons min max))))
13001 (error (and group (symbolp group) (set group nil))))
13002 (forward-line 1))))))
13003
13004 (defun gnus-read-newsrc-file (&optional force)
13005 "Read startup file.
13006 If FORCE is non-nil, the .newsrc file is read."
13007 ;; Reset variables that might be defined in the .newsrc.eld file.
13008 (let ((variables gnus-variable-list))
13009 (while variables
13010 (set (car variables) nil)
13011 (setq variables (cdr variables))))
13012 (let* ((newsrc-file gnus-current-startup-file)
13013 (quick-file (concat newsrc-file ".el")))
13014 (save-excursion
13015 ;; We always load the .newsrc.eld file. If always contains
13016 ;; much information that can not be gotten from the .newsrc
13017 ;; file (ticked articles, killed groups, foreign methods, etc.)
13018 (gnus-read-newsrc-el-file quick-file)
13019
13020 (if (or force
13021 (and (file-newer-than-file-p newsrc-file quick-file)
13022 (file-newer-than-file-p newsrc-file
13023 (concat quick-file "d")))
13024 (not gnus-newsrc-alist))
13025 ;; We read the .newsrc file. Note that if there if a
13026 ;; .newsrc.eld file exists, it has already been read, and
13027 ;; the `gnus-newsrc-hashtb' has been created. While reading
13028 ;; the .newsrc file, Gnus will only use the information it
13029 ;; can find there for changing the data already read -
13030 ;; ie. reading the .newsrc file will not trash the data
13031 ;; already read (except for read articles).
13032 (save-excursion
13033 (gnus-message 5 "Reading %s..." newsrc-file)
13034 (set-buffer (find-file-noselect newsrc-file))
13035 (buffer-disable-undo (current-buffer))
13036 (gnus-newsrc-to-gnus-format)
13037 (kill-buffer (current-buffer))
13038 (gnus-message 5 "Reading %s...done" newsrc-file))))))
13039
13040 (defun gnus-read-newsrc-el-file (file)
13041 (let ((ding-file (concat file "d")))
13042 ;; We always, always read the .eld file.
13043 (gnus-message 5 "Reading %s..." ding-file)
13044 (let (gnus-newsrc-assoc)
13045 (condition-case nil
13046 (load ding-file t t t)
13047 (error nil))
13048 (and gnus-newsrc-assoc (setq gnus-newsrc-alist gnus-newsrc-assoc)))
13049 (let ((inhibit-quit t))
13050 (gnus-uncompress-newsrc-alist))
13051 (gnus-make-hashtable-from-newsrc-alist)
13052 (if (not (file-newer-than-file-p file ding-file))
13053 ()
13054 ;; Old format quick file
13055 (gnus-message 5 "Reading %s..." file)
13056 ;; The .el file is newer than the .eld file, so we read that one
13057 ;; as well.
13058 (gnus-read-old-newsrc-el-file file))))
13059
13060 ;; Parse the old-style quick startup file
13061 (defun gnus-read-old-newsrc-el-file (file)
13062 (let (newsrc killed marked group m)
13063 (prog1
13064 (let ((gnus-killed-assoc nil)
13065 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
13066 (prog1
13067 (condition-case nil
13068 (load file t t t)
13069 (error nil))
13070 (setq newsrc gnus-newsrc-assoc
13071 killed gnus-killed-assoc
13072 marked gnus-marked-assoc)))
13073 (setq gnus-newsrc-alist nil)
13074 (while newsrc
13075 (setq group (car newsrc))
13076 (let ((info (nth 2 (gnus-gethash (car group) gnus-newsrc-hashtb))))
13077 (if info
13078 (progn
13079 (setcar (nthcdr 2 info) (cdr (cdr group)))
13080 (setcar (cdr info)
13081 (if (nth 1 group) gnus-level-default-subscribed
13082 gnus-level-default-unsubscribed))
13083 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
13084 (setq gnus-newsrc-alist
13085 (cons
13086 (setq info
13087 (list (car group)
13088 (if (nth 1 group) gnus-level-default-subscribed
13089 gnus-level-default-unsubscribed)
13090 (cdr (cdr group))))
13091 gnus-newsrc-alist)))
13092 (if (setq m (assoc (car group) marked))
13093 (setcdr (cdr (cdr info))
13094 (cons (list (cons 'tick (cdr m))) nil))))
13095 (setq newsrc (cdr newsrc)))
13096 (setq newsrc killed)
13097 (while newsrc
13098 (setcar newsrc (car (car newsrc)))
13099 (setq newsrc (cdr newsrc)))
13100 (setq gnus-killed-list killed))
13101 ;; The .el file version of this variable does not begin with
13102 ;; "options", while the .eld version does, so we just add it if it
13103 ;; isn't there.
13104 (and
13105 gnus-newsrc-options
13106 (progn
13107 (and (not (string-match "^ *options" gnus-newsrc-options))
13108 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
13109 (and (not (string-match "\n$" gnus-newsrc-options))
13110 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
13111 ;; Finally, if we read some options lines, we parse them.
13112 (or (string= gnus-newsrc-options "")
13113 (gnus-newsrc-parse-options gnus-newsrc-options))))
13114
13115 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
13116 (gnus-make-hashtable-from-newsrc-alist)))
13117
13118 (defun gnus-make-newsrc-file (file)
13119 "Make server dependent file name by catenating FILE and server host name."
13120 (let* ((file (expand-file-name file nil))
13121 (real-file (concat file "-" (nth 1 gnus-select-method))))
13122 (if (or (file-exists-p real-file)
13123 (file-exists-p (concat real-file ".el"))
13124 (file-exists-p (concat real-file ".eld")))
13125 real-file file)))
13126
13127 (defun gnus-uncompress-newsrc-alist ()
13128 ;; Uncompress all lists of marked articles in the newsrc assoc.
13129 (let ((newsrc gnus-newsrc-alist)
13130 marked)
13131 (while newsrc
13132 (if (not (setq marked (nth 3 (car newsrc))))
13133 ()
13134 (while marked
13135 (or (eq 'score (car (car marked)))
13136 (eq 'bookmark (car (car marked)))
13137 (eq 'killed (car (car marked)))
13138 (setcdr (car marked) (gnus-uncompress-range (cdr (car marked)))))
13139 (setq marked (cdr marked))))
13140 (setq newsrc (cdr newsrc)))))
13141
13142 (defun gnus-compress-newsrc-alist ()
13143 ;; Compress all lists of marked articles in the newsrc assoc.
13144 (let ((newsrc gnus-newsrc-alist)
13145 marked)
13146 (while newsrc
13147 (if (not (setq marked (nth 3 (car newsrc))))
13148 ()
13149 (while marked
13150 (or (eq 'score (car (car marked)))
13151 (eq 'bookmark (car (car marked)))
13152 (eq 'killed (car (car marked)))
13153 (setcdr (car marked)
13154 (condition-case ()
13155 (gnus-compress-sequence
13156 (sort (cdr (car marked)) '<) t)
13157 (error (cdr (car marked))))))
13158 (setq marked (cdr marked))))
13159 (setq newsrc (cdr newsrc)))))
13160
13161 (defun gnus-newsrc-to-gnus-format ()
13162 (setq gnus-newsrc-options "")
13163 (setq gnus-newsrc-options-n nil)
13164
13165 (or gnus-active-hashtb
13166 (setq gnus-active-hashtb (make-vector 4095 0)))
13167 (let ((buf (current-buffer))
13168 (already-read (> (length gnus-newsrc-alist) 1))
13169 group subscribed options-symbol newsrc Options-symbol
13170 symbol reads num1)
13171 (goto-char (point-min))
13172 ;; We intern the symbol `options' in the active hashtb so that we
13173 ;; can `eq' against it later.
13174 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
13175 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
13176
13177 (while (not (eobp))
13178 ;; We first read the first word on the line by narrowing and
13179 ;; then reading into `gnus-active-hashtb'. Most groups will
13180 ;; already exist in that hashtb, so this will save some string
13181 ;; space.
13182 (narrow-to-region
13183 (point)
13184 (progn (skip-chars-forward "^ \t!:\n") (point)))
13185 (goto-char (point-min))
13186 (setq symbol
13187 (and (/= (point-min) (point-max))
13188 (let ((obarray gnus-active-hashtb)) (read buf))))
13189 (widen)
13190 ;; Now, the symbol we have read is either `options' or a group
13191 ;; name. If it is an options line, we just add it to a string.
13192 (cond
13193 ((or (eq symbol options-symbol)
13194 (eq symbol Options-symbol))
13195 (setq gnus-newsrc-options
13196 ;; This concating is quite inefficient, but since our
13197 ;; thorough studies show that approx 99.37% of all
13198 ;; .newsrc files only contain a single options line, we
13199 ;; don't give a damn, frankly, my dear.
13200 (concat gnus-newsrc-options
13201 (buffer-substring
13202 (gnus-point-at-bol)
13203 ;; Options may continue on the next line.
13204 (or (and (re-search-forward "^[^ \t]" nil 'move)
13205 (progn (beginning-of-line) (point)))
13206 (point)))))
13207 (forward-line -1))
13208 (symbol
13209 (or (boundp symbol) (set symbol nil))
13210 ;; It was a group name.
13211 (setq subscribed (= (following-char) ?:)
13212 group (symbol-name symbol)
13213 reads nil)
13214 (if (eolp)
13215 ;; If the line ends here, this is clearly a buggy line, so
13216 ;; we put point a the beginning of line and let the cond
13217 ;; below do the error handling.
13218 (beginning-of-line)
13219 ;; We skip to the beginning of the ranges.
13220 (skip-chars-forward "!: \t"))
13221 ;; We are now at the beginning of the list of read articles.
13222 ;; We read them range by range.
13223 (while
13224 (cond
13225 ((looking-at "[0-9]+")
13226 ;; We narrow and read a number instead of buffer-substring/
13227 ;; string-to-int because it's faster. narrow/widen is
13228 ;; faster than save-restriction/narrow, and save-restriction
13229 ;; produces a garbage object.
13230 (setq num1 (progn
13231 (narrow-to-region (match-beginning 0) (match-end 0))
13232 (read buf)))
13233 (widen)
13234 ;; If the next character is a dash, then this is a range.
13235 (if (= (following-char) ?-)
13236 (progn
13237 ;; We read the upper bound of the range.
13238 (forward-char 1)
13239 (if (not (looking-at "[0-9]+"))
13240 ;; This is a buggy line, by we pretend that
13241 ;; it's kinda OK. Perhaps the user should be
13242 ;; dinged?
13243 (setq reads (cons num1 reads))
13244 (setq reads
13245 (cons
13246 (cons num1
13247 (progn
13248 (narrow-to-region (match-beginning 0)
13249 (match-end 0))
13250 (read buf)))
13251 reads))
13252 (widen)))
13253 ;; It was just a simple number, so we add it to the
13254 ;; list of ranges.
13255 (setq reads (cons num1 reads)))
13256 ;; If the next char in ?\n, then we have reached the end
13257 ;; of the line and return nil.
13258 (/= (following-char) ?\n))
13259 ((= (following-char) ?\n)
13260 ;; End of line, so we end.
13261 nil)
13262 (t
13263 ;; Not numbers and not eol, so this might be a buggy
13264 ;; line...
13265 (or (eobp)
13266 ;; If it was eob instead of ?\n, we allow it.
13267 (progn
13268 ;; The line was buggy.
13269 (setq group nil)
13270 (gnus-message 3 "Mangled line: %s"
13271 (buffer-substring (gnus-point-at-bol)
13272 (gnus-point-at-eol)))
13273 (ding)
13274 (sit-for 1)))
13275 nil))
13276 ;; Skip past ", ". Spaces are illegal in these ranges, but
13277 ;; we allow them, because it's a common mistake to put a
13278 ;; space after the comma.
13279 (skip-chars-forward ", "))
13280
13281 ;; We have already read .newsrc.eld, so we gently update the
13282 ;; data in the hash table with the information we have just
13283 ;; read.
13284 (if (not group)
13285 ()
13286 (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
13287 level)
13288 (if info
13289 ;; There is an entry for this file in the alist.
13290 (progn
13291 (setcar (nthcdr 2 info) (nreverse reads))
13292 ;; We update the level very gently. In fact, we
13293 ;; only change it if there's been a status change
13294 ;; from subscribed to unsubscribed, or vice versa.
13295 (setq level (nth 1 info))
13296 (cond ((and (<= level gnus-level-subscribed)
13297 (not subscribed))
13298 (setq level (if reads
13299 gnus-level-default-unsubscribed
13300 (1+ gnus-level-default-unsubscribed))))
13301 ((and (> level gnus-level-subscribed) subscribed)
13302 (setq level gnus-level-default-subscribed)))
13303 (setcar (cdr info) level))
13304 ;; This is a new group.
13305 (setq info (list group
13306 (if subscribed
13307 gnus-level-default-subscribed
13308 (if reads
13309 (1+ gnus-level-subscribed)
13310 gnus-level-default-unsubscribed))
13311 (nreverse reads))))
13312 (setq newsrc (cons info newsrc))))))
13313 (forward-line 1))
13314
13315 (setq newsrc (nreverse newsrc))
13316
13317 (if (not already-read)
13318 ()
13319 ;; We now have two newsrc lists - `newsrc', which is what we
13320 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
13321 ;; what we've read from .newsrc.eld. We have to merge these
13322 ;; lists. We do this by "attaching" any (foreign) groups in the
13323 ;; gnus-newsrc-alist to the (native) group that precedes them.
13324 (let ((rc (cdr gnus-newsrc-alist))
13325 (prev gnus-newsrc-alist)
13326 entry mentry)
13327 (while rc
13328 (or (null (nth 4 (car rc))) ; It's a native group.
13329 (assoc (car (car rc)) newsrc) ; It's already in the alist.
13330 (if (setq entry (assoc (car (car prev)) newsrc))
13331 (setcdr (setq mentry (memq entry newsrc))
13332 (cons (car rc) (cdr mentry)))
13333 (setq newsrc (cons (car rc) newsrc))))
13334 (setq prev rc
13335 rc (cdr rc)))))
13336
13337 (setq gnus-newsrc-alist newsrc)
13338 ;; We make the newsrc hashtb.
13339 (gnus-make-hashtable-from-newsrc-alist)
13340
13341 ;; Finally, if we read some options lines, we parse them.
13342 (or (string= gnus-newsrc-options "")
13343 (gnus-newsrc-parse-options gnus-newsrc-options))))
13344
13345 ;; Parse options lines to find "options -n !all rec.all" and stuff.
13346 ;; The return value will be a list on the form
13347 ;; ((regexp1 . ignore)
13348 ;; (regexp2 . subscribe)...)
13349 ;; When handling new newsgroups, groups that match a `ignore' regexp
13350 ;; will be ignored, and groups that match a `subscribe' regexp will be
13351 ;; subscribed. A line like
13352 ;; options -n !all rec.all
13353 ;; will lead to a list that looks like
13354 ;; (("^rec\\..+" . subscribe)
13355 ;; ("^.+" . ignore))
13356 ;; So all "rec.*" groups will be subscribed, while all the other
13357 ;; groups will be ignored. Note that "options -n !all rec.all" is very
13358 ;; different from "options -n rec.all !all".
13359 (defun gnus-newsrc-parse-options (options)
13360 (let (out eol)
13361 (save-excursion
13362 (gnus-set-work-buffer)
13363 (insert (regexp-quote options))
13364 ;; First we treat all continuation lines.
13365 (goto-char (point-min))
13366 (while (re-search-forward "\n[ \t]+" nil t)
13367 (replace-match " " t t))
13368 ;; Then we transform all "all"s into ".+"s.
13369 (goto-char (point-min))
13370 (while (re-search-forward "\\ball\\b" nil t)
13371 (replace-match ".+" t t))
13372 (goto-char (point-min))
13373 ;; We remove all other options than the "-n" ones.
13374 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
13375 (replace-match " ")
13376 (forward-char -1))
13377 (goto-char (point-min))
13378
13379 ;; We are only interested in "options -n" lines - we
13380 ;; ignore the other option lines.
13381 (while (re-search-forward "[ \t]-n" nil t)
13382 (setq eol
13383 (or (save-excursion
13384 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
13385 (- (point) 2)))
13386 (gnus-point-at-eol)))
13387 ;; Search for all "words"...
13388 (while (re-search-forward "[^ \t,\n]+" eol t)
13389 (if (= (char-after (match-beginning 0)) ?!)
13390 ;; If the word begins with a bang (!), this is a "not"
13391 ;; spec. We put this spec (minus the bang) and the
13392 ;; symbol `ignore' into the list.
13393 (setq out (cons (cons (concat
13394 "^" (buffer-substring
13395 (1+ (match-beginning 0))
13396 (match-end 0)))
13397 'ignore) out))
13398 ;; There was no bang, so this is a "yes" spec.
13399 (setq out (cons (cons (concat
13400 "^" (buffer-substring (match-beginning 0)
13401 (match-end 0)))
13402 'subscribe) out)))))
13403
13404 (setq gnus-newsrc-options-n out))))
13405
13406
13407 (defun gnus-save-newsrc-file ()
13408 "Save .newsrc file."
13409 ;; Note: We cannot save .newsrc file if all newsgroups are removed
13410 ;; from the variable gnus-newsrc-alist.
13411 (and (or gnus-newsrc-alist gnus-killed-list)
13412 gnus-current-startup-file
13413 (progn
13414 (run-hooks 'gnus-save-newsrc-hook)
13415 (save-excursion
13416 (if (and gnus-use-dribble-file
13417 (or (not gnus-dribble-buffer)
13418 (not (buffer-name gnus-dribble-buffer))
13419 (zerop (save-excursion
13420 (set-buffer gnus-dribble-buffer)
13421 (buffer-size)))))
13422 (gnus-message 4 "(No changes need to be saved)")
13423 (if gnus-save-newsrc-file
13424 (progn
13425 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
13426 ;; Make backup file of master newsrc.
13427 (gnus-gnus-to-newsrc-format)
13428 (gnus-message 5 "Saving %s...done"
13429 gnus-current-startup-file)))
13430 ;; Quickly loadable .newsrc.
13431 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
13432 (make-local-variable 'version-control)
13433 (setq version-control 'never)
13434 (setq buffer-file-name (concat gnus-current-startup-file ".eld"))
13435 (gnus-add-current-to-buffer-list)
13436 (buffer-disable-undo (current-buffer))
13437 (erase-buffer)
13438 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
13439 (gnus-gnus-to-quick-newsrc-format)
13440 (save-buffer)
13441 (kill-buffer (current-buffer))
13442 (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file)
13443 (gnus-dribble-delete-file))))))
13444
13445 (defun gnus-gnus-to-quick-newsrc-format ()
13446 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
13447 (insert ";; Gnus startup file.\n")
13448 (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
13449 (insert ";; to read .newsrc.\n")
13450 (insert "(setq gnus-newsrc-file-version "
13451 (prin1-to-string gnus-version) ")\n")
13452 (let ((variables gnus-variable-list)
13453 (inhibit-quit t)
13454 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
13455 variable)
13456 ;; insert lisp expressions.
13457 (gnus-compress-newsrc-alist)
13458 (while variables
13459 (setq variable (car variables))
13460 (and (boundp variable)
13461 (symbol-value variable)
13462 (or gnus-save-killed-list (not (eq variable 'gnus-killed-list)))
13463 (insert "(setq " (symbol-name variable) " '"
13464 (prin1-to-string (symbol-value variable))
13465 ")\n"))
13466 (setq variables (cdr variables)))
13467 (gnus-uncompress-newsrc-alist)))
13468
13469
13470 (defun gnus-gnus-to-newsrc-format ()
13471 ;; Generate and save the .newsrc file.
13472 (let ((newsrc (cdr gnus-newsrc-alist))
13473 info ranges range)
13474 (save-excursion
13475 (set-buffer (create-file-buffer gnus-current-startup-file))
13476 (setq buffer-file-name gnus-current-startup-file)
13477 (buffer-disable-undo (current-buffer))
13478 (erase-buffer)
13479 ;; Write options.
13480 (if gnus-newsrc-options (insert gnus-newsrc-options))
13481 ;; Write subscribed and unsubscribed.
13482 (while newsrc
13483 (setq info (car newsrc))
13484 (if (not (nth 4 info)) ;Don't write foreign groups to .newsrc.
13485 (progn
13486 (insert (car info) (if (> (nth 1 info) gnus-level-subscribed)
13487 "!" ":"))
13488 (if (setq ranges (nth 2 info))
13489 (progn
13490 (insert " ")
13491 (if (not (listp (cdr ranges)))
13492 (if (= (car ranges) (cdr ranges))
13493 (insert (int-to-string (car ranges)))
13494 (insert (int-to-string (car ranges)) "-"
13495 (int-to-string (cdr ranges))))
13496 (while ranges
13497 (setq range (car ranges)
13498 ranges (cdr ranges))
13499 (if (or (atom range) (= (car range) (cdr range)))
13500 (insert (int-to-string
13501 (or (and (atom range) range)
13502 (car range))))
13503 (insert (int-to-string (car range)) "-"
13504 (int-to-string (cdr range))))
13505 (if ranges (insert ","))))))
13506 (insert "\n")))
13507 (setq newsrc (cdr newsrc)))
13508 (make-local-variable 'version-control)
13509 (setq version-control 'never)
13510 ;; It has been reported that sometime the modtime on the .newsrc
13511 ;; file seems to be off. We really do want to overwrite it, so
13512 ;; we clear the modtime here before saving. It's a bit odd,
13513 ;; though...
13514 ;; sometimes the modtime clear isn't sufficient. most brute force:
13515 ;; delete the silly thing entirely first. but this fails to provide
13516 ;; such niceties as .newsrc~ creation.
13517 (if gnus-modtime-botch
13518 (delete-file gnus-startup-file)
13519 (clear-visited-file-modtime))
13520 (save-buffer)
13521 (kill-buffer (current-buffer)))))
13522
13523 (defun gnus-read-all-descriptions-files ()
13524 (let ((methods (cons gnus-select-method gnus-secondary-select-methods)))
13525 (while methods
13526 (gnus-read-descriptions-file (car methods))
13527 (setq methods (cdr methods)))
13528 t))
13529
13530 (defun gnus-read-descriptions-file (&optional method)
13531 (let ((method (or method gnus-select-method)))
13532 ;; We create the hashtable whether we manage to read the desc file
13533 ;; to avoid trying to re-read after a failed read.
13534 (or gnus-description-hashtb
13535 (setq gnus-description-hashtb
13536 (gnus-make-hashtable (length gnus-active-hashtb))))
13537 ;; Mark this method's desc file as read.
13538 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
13539 gnus-description-hashtb)
13540
13541 (gnus-message 5 "Reading descriptions file via %s..." (car method))
13542 (cond
13543 ((not (gnus-check-server method))
13544 (gnus-message 1 "Couldn't open server")
13545 nil)
13546 ((not (gnus-request-list-newsgroups method))
13547 (gnus-message 1 "Couldn't read newsgroups descriptions")
13548 nil)
13549 (t
13550 (let (group)
13551 (save-excursion
13552 (save-restriction
13553 (set-buffer nntp-server-buffer)
13554 (goto-char (point-min))
13555 (if (or (search-forward "\n.\n" nil t)
13556 (goto-char (point-max)))
13557 (progn
13558 (beginning-of-line)
13559 (narrow-to-region (point-min) (point))))
13560 (goto-char (point-min))
13561 (while (not (eobp))
13562 ;; If we get an error, we set group to 0, which is not a
13563 ;; symbol...
13564 (setq group
13565 (condition-case ()
13566 (let ((obarray gnus-description-hashtb))
13567 ;; Group is set to a symbol interned in this
13568 ;; hash table.
13569 (read nntp-server-buffer))
13570 (error 0)))
13571 (skip-chars-forward " \t")
13572 ;; ... which leads to this line being effectively ignored.
13573 (and (symbolp group)
13574 (set group (buffer-substring
13575 (point) (progn (end-of-line) (point)))))
13576 (forward-line 1))))
13577 (gnus-message 5 "Reading descriptions file...done")
13578 t)))))
13579
13580 (defun gnus-group-get-description (group)
13581 ;; Get the description of a group by sending XGTITLE to the server.
13582 (and (gnus-request-group-description group)
13583 (save-excursion
13584 (set-buffer nntp-server-buffer)
13585 (goto-char (point-min))
13586 (and (looking-at "[^ \t]+[ \t]+\\(.*\\)")
13587 (buffer-substring (match-beginning 1) (match-end 1))))))
13588
13589 ;;;
13590 ;;; Server
13591 ;;;
13592
13593 (defvar gnus-server-mode-hook nil
13594 "Hook run in `gnus-server-mode' buffers.")
13595
13596 (defconst gnus-server-line-format " {%(%h:%w%)}\n"
13597 "Format of server lines.
13598 It works along the same lines as a normal formatting string,
13599 with some simple extensions.")
13600
13601 (defvar gnus-server-mode-line-format "Gnus List of servers"
13602 "The format specification for the server mode line.")
13603
13604 (defconst gnus-server-line-format-alist
13605 (list (list ?h 'how ?s)
13606 (list ?n 'name ?s)
13607 (list ?w 'where ?s)
13608 ))
13609
13610 (defconst gnus-server-mode-line-format-alist
13611 (list (list ?S 'news-server ?s)
13612 (list ?M 'news-method ?s)
13613 (list ?u 'user-defined ?s)))
13614
13615 (defvar gnus-server-line-format-spec nil)
13616 (defvar gnus-server-mode-line-format-spec nil)
13617 (defvar gnus-server-killed-servers nil)
13618
13619 (defvar gnus-server-mode-map nil)
13620 (put 'gnus-server-mode 'mode-class 'special)
13621
13622 (if gnus-server-mode-map
13623 nil
13624 (setq gnus-server-mode-map (make-sparse-keymap))
13625 (suppress-keymap gnus-server-mode-map)
13626 (define-key gnus-server-mode-map " " 'gnus-server-read-server)
13627 (define-key gnus-server-mode-map "\r" 'gnus-server-read-server)
13628 (define-key gnus-server-mode-map gnus-mouse-2 'gnus-server-pick-server)
13629 (define-key gnus-server-mode-map "q" 'gnus-server-exit)
13630 (define-key gnus-server-mode-map "l" 'gnus-server-list-servers)
13631 (define-key gnus-server-mode-map "k" 'gnus-server-kill-server)
13632 (define-key gnus-server-mode-map "y" 'gnus-server-yank-server)
13633 (define-key gnus-server-mode-map "c" 'gnus-server-copy-server)
13634 (define-key gnus-server-mode-map "a" 'gnus-server-add-server)
13635 (define-key gnus-server-mode-map "e" 'gnus-server-edit-server))
13636
13637 (defun gnus-server-mode ()
13638 "Major mode for listing and editing servers.
13639
13640 All normal editing commands are switched off.
13641 \\<gnus-server-mode-map>
13642
13643 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
13644
13645 The following commands are available:
13646
13647 \\{gnus-server-mode-map}"
13648 (interactive)
13649 (if gnus-visual (gnus-server-make-menu-bar))
13650 (kill-all-local-variables)
13651 (gnus-simplify-mode-line)
13652 (setq major-mode 'gnus-server-mode)
13653 (setq mode-name "Server")
13654 ; (gnus-group-set-mode-line)
13655 (setq mode-line-process nil)
13656 (use-local-map gnus-server-mode-map)
13657 (buffer-disable-undo (current-buffer))
13658 (setq truncate-lines t)
13659 (setq buffer-read-only t)
13660 (run-hooks 'gnus-server-mode-hook))
13661
13662 (defun gnus-server-insert-server-line (sformat name method)
13663 (let* ((sformat (or sformat gnus-server-line-format-spec))
13664 (how (car method))
13665 (where (nth 1 method))
13666 b)
13667 (beginning-of-line)
13668 (setq b (point))
13669 ;; Insert the text.
13670 (insert (eval sformat))
13671 (add-text-properties b (1+ b) (list 'gnus-server (intern name)))))
13672
13673 (defun gnus-server-setup-buffer ()
13674 (if (get-buffer gnus-server-buffer)
13675 ()
13676 (save-excursion
13677 (set-buffer (get-buffer-create gnus-server-buffer))
13678 (gnus-server-mode)
13679 (and gnus-carpal (gnus-carpal-setup-buffer 'server)))))
13680
13681 (defun gnus-server-prepare ()
13682 (setq gnus-server-mode-line-format-spec
13683 (gnus-parse-format gnus-server-mode-line-format
13684 gnus-server-mode-line-format-alist))
13685 (setq gnus-server-line-format-spec
13686 (gnus-parse-format gnus-server-line-format
13687 gnus-server-line-format-alist))
13688 (let ((alist gnus-server-alist)
13689 (buffer-read-only nil))
13690 (erase-buffer)
13691 (while alist
13692 (gnus-server-insert-server-line nil (car (car alist)) (cdr (car alist)))
13693 (setq alist (cdr alist))))
13694 (goto-char (point-min))
13695 (gnus-server-position-cursor))
13696
13697 (defun gnus-server-server-name ()
13698 (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
13699 (and server (symbol-name server))))
13700
13701 (defalias 'gnus-server-position-cursor 'gnus-goto-colon)
13702
13703 (defconst gnus-server-edit-buffer "*Gnus edit server*")
13704
13705 (defun gnus-server-update-server (server)
13706 (save-excursion
13707 (set-buffer gnus-server-buffer)
13708 (let ((buffer-read-only nil)
13709 (info (cdr (assoc server gnus-server-alist))))
13710 (gnus-dribble-enter
13711 (concat "(gnus-server-set-info \"" server "\" '"
13712 (prin1-to-string info) ")"))
13713 ;; Buffer may be narrowed.
13714 (save-restriction
13715 (widen)
13716 (if (gnus-server-goto-server server)
13717 (delete-region (progn (beginning-of-line) (point))
13718 (progn (forward-line 1) (point))))
13719 (let ((entry (assoc server gnus-server-alist)))
13720 (gnus-server-insert-server-line nil (car entry) (cdr entry))
13721 (gnus-server-position-cursor))))))
13722
13723 (defun gnus-server-set-info (server info)
13724 ;; Enter a select method into the virtual server alist.
13725 (gnus-dribble-enter
13726 (concat "(gnus-server-set-info \"" server "\" '"
13727 (prin1-to-string info) ")"))
13728 (let* ((server (nth 1 info))
13729 (entry (assoc server gnus-server-alist)))
13730 (if entry (setcdr entry info)
13731 (setq gnus-server-alist
13732 (nconc gnus-server-alist (list (cons server info)))))))
13733
13734 (defun gnus-server-to-method (server)
13735 ;; Map virtual server names to select methods.
13736 (or (and (equal server "native") gnus-select-method)
13737 (cdr (assoc server gnus-server-alist))))
13738
13739 (defun gnus-server-extend-method (group method)
13740 ;; This function "extends" a virtual server. If the server is
13741 ;; "hello", and the select method is ("hello" (my-var "something"))
13742 ;; in the group "alt.alt", this will result in a new virtual server
13743 ;; called "helly+alt.alt".
13744 (let ((entry
13745 (gnus-copy-sequence
13746 (if (equal (car method) "native") gnus-select-method
13747 (cdr (assoc (car method) gnus-server-alist))))))
13748 (setcar (cdr entry) (concat (nth 1 entry) "+" group))
13749 (nconc entry (cdr method))))
13750
13751 (defun gnus-server-get-method (group method)
13752 ;; Input either a server name, and extended server name, or a
13753 ;; select method, and return a select method.
13754 (cond ((stringp method)
13755 (gnus-server-to-method method))
13756 ((and (stringp (car method)) group)
13757 (gnus-server-extend-method group method))
13758 (t
13759 (gnus-server-add-address method))))
13760
13761 (defun gnus-server-add-address (method)
13762 (let ((method-name (symbol-name (car method))))
13763 (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
13764 (not (assq (intern (concat method-name "-address")) method)))
13765 (append method (list (list (intern (concat method-name "-address"))
13766 (nth 1 method))))
13767 method)))
13768
13769 (defun gnus-server-equal (s1 s2)
13770 (or (equal s1 s2)
13771 (and (= (length s1) (length s2))
13772 (progn
13773 (while (and s1 (member (car s1) s2))
13774 (setq s1 (cdr s1)))
13775 (null s1)))))
13776
13777 ;;; Interactive server functions.
13778
13779 (defun gnus-server-kill-server (server)
13780 "Kill the server on the current line."
13781 (interactive (list (gnus-server-server-name)))
13782 (or (gnus-server-goto-server server)
13783 (if server (error "No such server: %s" server)
13784 (error "No server on the current line")))
13785 (gnus-dribble-enter "")
13786 (let ((buffer-read-only nil))
13787 (delete-region (progn (beginning-of-line) (point))
13788 (progn (forward-line 1) (point))))
13789 (setq gnus-server-killed-servers
13790 (cons (assoc server gnus-server-alist) gnus-server-killed-servers))
13791 (setq gnus-server-alist (delq (car gnus-server-killed-servers)
13792 gnus-server-alist))
13793 (gnus-server-position-cursor))
13794
13795 (defun gnus-server-yank-server ()
13796 "Yank the previously killed server."
13797 (interactive)
13798 (or gnus-server-killed-servers
13799 (error "No killed servers to be yanked"))
13800 (let ((alist gnus-server-alist)
13801 (server (gnus-server-server-name))
13802 (killed (car gnus-server-killed-servers)))
13803 (if (not server)
13804 (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
13805 (if (string= server (car (car gnus-server-alist)))
13806 (setq gnus-server-alist (cons killed gnus-server-alist))
13807 (while (and (cdr alist)
13808 (not (string= server (car (car (cdr alist))))))
13809 (setq alist (cdr alist)))
13810 (setcdr alist (cons killed (cdr alist)))))
13811 (gnus-server-update-server (car killed))
13812 (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
13813 (gnus-server-position-cursor)))
13814
13815 (defun gnus-server-exit ()
13816 "Return to the group buffer."
13817 (interactive)
13818 (kill-buffer (current-buffer))
13819 (switch-to-buffer gnus-group-buffer))
13820
13821 (defun gnus-server-list-servers ()
13822 "List all available servers."
13823 (interactive)
13824 (let ((cur (gnus-server-server-name)))
13825 (gnus-server-prepare)
13826 (if cur (gnus-server-goto-server cur)
13827 (goto-char (point-max))
13828 (forward-line -1))
13829 (gnus-server-position-cursor)))
13830
13831 (defun gnus-server-copy-server (from to)
13832 (interactive
13833 (list
13834 (or (gnus-server-server-name)
13835 (error "No server on the current line"))
13836 (read-string "Copy to: ")))
13837 (or from (error "No server on current line"))
13838 (or (and to (not (string= to ""))) (error "No name to copy to"))
13839 (and (assoc to gnus-server-alist) (error "%s already exists" to))
13840 (or (assoc from gnus-server-alist)
13841 (error "%s: no such server" from))
13842 (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist))))
13843 (setcar to-entry to)
13844 (setcar (nthcdr 2 to-entry) to)
13845 (setq gnus-server-killed-servers
13846 (cons to-entry gnus-server-killed-servers))
13847 (gnus-server-yank-server)))
13848
13849 (defun gnus-server-add-server (how where)
13850 (interactive
13851 (list (intern (completing-read "Server method: "
13852 gnus-valid-select-methods nil t))
13853 (read-string "Server name: ")))
13854 (setq gnus-server-killed-servers
13855 (cons (list where how where) gnus-server-killed-servers))
13856 (gnus-server-yank-server))
13857
13858 (defun gnus-server-goto-server (server)
13859 "Jump to a server line."
13860 (interactive
13861 (list (completing-read "Goto server: " gnus-server-alist nil t)))
13862 (let ((to (text-property-any (point-min) (point-max)
13863 'gnus-server (intern server))))
13864 (and to
13865 (progn
13866 (goto-char to)
13867 (gnus-server-position-cursor)))))
13868
13869 (defun gnus-server-edit-server (server)
13870 "Edit the server on the current line."
13871 (interactive (list (gnus-server-server-name)))
13872 (or server
13873 (error "No server on current line"))
13874 (let ((winconf (current-window-configuration)))
13875 (get-buffer-create gnus-server-edit-buffer)
13876 (gnus-configure-windows 'edit-server)
13877 (gnus-add-current-to-buffer-list)
13878 (emacs-lisp-mode)
13879 (make-local-variable 'gnus-prev-winconf)
13880 (setq gnus-prev-winconf winconf)
13881 (use-local-map (copy-keymap (current-local-map)))
13882 (let ((done-func '(lambda ()
13883 "Exit editing mode and update the information."
13884 (interactive)
13885 (gnus-server-edit-server-done 'group))))
13886 (setcar (cdr (nth 4 done-func)) server)
13887 (local-set-key "\C-c\C-c" done-func))
13888 (erase-buffer)
13889 (insert ";; Type `C-c C-c' after you have edited the server.\n\n")
13890 (insert (pp-to-string (cdr (assoc server gnus-server-alist))))))
13891
13892 (defun gnus-server-edit-server-done (server)
13893 (interactive)
13894 (set-buffer (get-buffer-create gnus-server-edit-buffer))
13895 (goto-char (point-min))
13896 (let ((form (read (current-buffer)))
13897 (winconf gnus-prev-winconf))
13898 (gnus-server-set-info server form)
13899 (kill-buffer (current-buffer))
13900 (and winconf (set-window-configuration winconf))
13901 (set-buffer gnus-server-buffer)
13902 (gnus-server-update-server (gnus-server-server-name))
13903 (gnus-server-list-servers)
13904 (gnus-server-position-cursor)))
13905
13906 (defun gnus-server-read-server (server)
13907 "Browse a server."
13908 (interactive (list (gnus-server-server-name)))
13909 (gnus-browse-foreign-server (gnus-server-to-method server) (current-buffer)))
13910
13911 (defun gnus-mouse-pick-server (e)
13912 (interactive "e")
13913 (mouse-set-point e)
13914 (gnus-server-read-server (gnus-server-server-name)))
13915
13916 ;;;
13917 ;;; entry points into gnus-score.el
13918 ;;;
13919
13920 ;;; Finding score files.
13921
13922 (defvar gnus-global-score-files nil
13923 "*List of global score files and directories.
13924 Set this variable if you want to use people's score files. One entry
13925 for each score file or each score file directory. Gnus will decide
13926 by itself what score files are applicable to which group.
13927
13928 Say you want to use the single score file
13929 \"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
13930 score files in the \"/ftp.some-where:/pub/score\" directory.
13931
13932 (setq gnus-global-score-files
13933 '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\"
13934 \"/ftp.some-where:/pub/score\"))")
13935
13936 (defun gnus-score-score-files (group)
13937 "Return a list of all possible score files."
13938 ;; Search and set any global score files.
13939 (and gnus-global-score-files
13940 (or gnus-internal-global-score-files
13941 (gnus-score-search-global-directories gnus-global-score-files)))
13942 ;; Fix the kill-file dir variable.
13943 (setq gnus-kill-files-directory
13944 (file-name-as-directory
13945 (or gnus-kill-files-directory "~/News/")))
13946 ;; If we can't read it, there are no score files.
13947 (if (not (file-exists-p (expand-file-name gnus-kill-files-directory)))
13948 (setq gnus-score-file-list nil)
13949 (if (gnus-use-long-file-name 'not-score)
13950 ;; We want long file names.
13951 (if (or (not gnus-score-file-list)
13952 (not (car gnus-score-file-list))
13953 (gnus-file-newer-than gnus-kill-files-directory
13954 (car gnus-score-file-list)))
13955 (setq gnus-score-file-list
13956 (cons (nth 5 (file-attributes gnus-kill-files-directory))
13957 (nreverse
13958 (directory-files
13959 gnus-kill-files-directory t
13960 (gnus-score-file-regexp))))))
13961 ;; We do not use long file names, so we have to do some
13962 ;; directory traversing.
13963 (let ((mdir (length (expand-file-name gnus-kill-files-directory)))
13964 (suffixes (list gnus-score-file-suffix gnus-adaptive-file-suffix))
13965 dir files suffix)
13966 (while suffixes
13967 (setq dir (expand-file-name
13968 (concat gnus-kill-files-directory
13969 (gnus-replace-chars-in-string group ?. ?/))))
13970 (setq dir (gnus-replace-chars-in-string dir ?: ?/))
13971 (setq suffix (car suffixes)
13972 suffixes (cdr suffixes))
13973 (if (file-exists-p (concat dir "/" suffix))
13974 (setq files (cons (concat dir "/" suffix) files)))
13975 (while (>= (1+ (length dir)) mdir)
13976 (and (file-exists-p (concat dir "/all/" suffix))
13977 (setq files (cons (concat dir "/all/" suffix) files)))
13978 (string-match "/[^/]*$" dir)
13979 (setq dir (substring dir 0 (match-beginning 0)))))
13980 (setq gnus-score-file-list
13981 (cons nil (nreverse files)))))
13982 (cdr gnus-score-file-list)))
13983
13984 (defun gnus-score-file-regexp ()
13985 (concat "\\(" gnus-score-file-suffix
13986 "\\|" gnus-adaptive-file-suffix "\\)$"))
13987
13988 (defun gnus-score-find-bnews (group)
13989 "Return a list of score files for GROUP.
13990 The score files are those files in the ~/News directory which matches
13991 GROUP using BNews sys file syntax."
13992 (let* ((sfiles (append (gnus-score-score-files group)
13993 gnus-internal-global-score-files))
13994 (kill-dir (file-name-as-directory
13995 (expand-file-name gnus-kill-files-directory)))
13996 (klen (length kill-dir))
13997 ofiles not-match regexp)
13998 (save-excursion
13999 (set-buffer (get-buffer-create "*gnus score files*"))
14000 (buffer-disable-undo (current-buffer))
14001 ;; Go through all score file names and create regexp with them
14002 ;; as the source.
14003 (while sfiles
14004 (erase-buffer)
14005 (insert (car sfiles))
14006 (goto-char (point-min))
14007 ;; First remove the suffix itself.
14008 (re-search-forward (concat "." (gnus-score-file-regexp)))
14009 (replace-match "" t t)
14010 (goto-char (point-min))
14011 (if (looking-at (regexp-quote kill-dir))
14012 ;; If the file name was just "SCORE", `klen' is one character
14013 ;; too much.
14014 (delete-char (min (1- (point-max)) klen))
14015 (goto-char (point-max))
14016 (search-backward "/")
14017 (delete-region (1+ (point)) (point-min)))
14018 ;; If short file names were used, we have to translate slashes.
14019 (goto-char (point-min))
14020 (while (re-search-forward "[/:]" nil t)
14021 (replace-match "." t t))
14022 ;; Kludge to get rid of "nntp+" problems.
14023 (goto-char (point-min))
14024 (and (looking-at "nn[a-z]+\\+")
14025 (progn
14026 (search-forward "+")
14027 (forward-char -1)
14028 (insert "\\")))
14029 ;; Translate ".all" to "[./].*";
14030 (while (search-forward ".all" nil t)
14031 (replace-match "[./:].*" t t))
14032 (goto-char (point-min))
14033 ;; Translate "all" to ".*".
14034 (while (search-forward "all" nil t)
14035 (replace-match ".*" t t))
14036 (goto-char (point-min))
14037 ;; Deal with "not."s.
14038 (if (looking-at "not.")
14039 (progn
14040 (setq not-match t)
14041 (setq regexp (buffer-substring 5 (point-max))))
14042 (setq regexp (buffer-substring 1 (point-max)))
14043 (setq not-match nil))
14044 ;; Finally - if this resulting regexp matches the group name,
14045 ;; we add this score file to the list of score files
14046 ;; applicable to this group.
14047 (if (or (and not-match
14048 (not (string-match regexp group)))
14049 (and (not not-match)
14050 (string-match regexp group)))
14051 (setq ofiles (cons (car sfiles) ofiles)))
14052 (setq sfiles (cdr sfiles)))
14053 (kill-buffer (current-buffer))
14054 ;; Slight kludge here - the last score file returned should be
14055 ;; the local score file, whether it exists or not. This is so
14056 ;; that any score commands the user enters will go to the right
14057 ;; file, and not end up in some global score file.
14058 (let ((localscore
14059 (expand-file-name
14060 (if (gnus-use-long-file-name 'not-score)
14061 (concat gnus-kill-files-directory group "."
14062 gnus-score-file-suffix)
14063 (concat gnus-kill-files-directory
14064 (gnus-replace-chars-in-string group ?. ?/ ?: ?/)
14065 "/" gnus-score-file-suffix)))))
14066 ;; The local score file might already be there, but it's
14067 ;; supposed to be the very last file, so we delete it from the
14068 ;; list if it's already there, and add it to the head of the
14069 ;; list.
14070 (setq ofiles (cons localscore (delete localscore ofiles))))
14071 (nreverse ofiles))))
14072
14073 (defun gnus-score-find-single (group)
14074 "Return list containing the score file for GROUP."
14075 (list (gnus-score-file-name group gnus-adaptive-file-suffix)
14076 (gnus-score-file-name group)))
14077
14078 (defun gnus-score-find-hierarchical (group)
14079 "Return list of score files for GROUP.
14080 This includes the score file for the group and all its parents."
14081 (let ((all (copy-sequence '(nil)))
14082 (start 0))
14083 (while (string-match "\\." group (1+ start))
14084 (setq start (match-beginning 0))
14085 (setq all (cons (substring group 0 start) all)))
14086 (setq all (cons group all))
14087 (nconc
14088 (mapcar (lambda (newsgroup)
14089 (gnus-score-file-name newsgroup gnus-adaptive-file-suffix))
14090 (setq all (nreverse all)))
14091 (mapcar 'gnus-score-file-name all))))
14092
14093 (defvar gnus-score-file-alist-cache nil)
14094
14095 (defun gnus-score-find-alist (group)
14096 "Return list of score files for GROUP.
14097 The list is determined from the variable gnus-score-file-alist."
14098 (let ((alist gnus-score-file-multiple-match-alist)
14099 score-files)
14100 ;; if this group has been seen before, return the cached entry
14101 (if (setq score-files (assoc group gnus-score-file-alist-cache))
14102 (cdr score-files) ;ensures caching groups with no matches
14103 ;; handle the multiple match alist
14104 (while alist
14105 (and (string-match (car (car alist)) group)
14106 (setq score-files
14107 (nconc score-files (copy-sequence (cdr (car alist))))))
14108 (setq alist (cdr alist)))
14109 (setq alist gnus-score-file-single-match-alist)
14110 ;; handle the single match alist
14111 (while alist
14112 (and (string-match (car (car alist)) group)
14113 ;; progn used just in case ("regexp") has no files
14114 ;; and score-files is still nil. -sj
14115 ;; this can be construed as a "stop searching here" feature :>
14116 ;; and used to simplify regexps in the single-alist
14117 (progn
14118 (setq score-files
14119 (nconc score-files (copy-sequence (cdr (car alist)))))
14120 (setq alist nil)))
14121 (setq alist (cdr alist)))
14122 ;; cache the score files
14123 (setq gnus-score-file-alist-cache
14124 (cons (cons group score-files) gnus-score-file-alist-cache))
14125 score-files)))
14126
14127
14128 (defun gnus-possibly-score-headers (&optional trace)
14129 (let ((func gnus-score-find-score-files-function)
14130 score-files)
14131 (and func (not (listp func))
14132 (setq func (list func)))
14133 ;; Go through all the functions for finding score files (or actual
14134 ;; scores) and add them to a list.
14135 (setq score-files (gnus-score-find-alist gnus-newsgroup-name))
14136 (while func
14137 (and (symbolp (car func))
14138 (fboundp (car func))
14139 (setq score-files
14140 (nconc score-files (funcall (car func) gnus-newsgroup-name))))
14141 (setq func (cdr func)))
14142 (if score-files (gnus-score-headers score-files trace))))
14143
14144 (defun gnus-score-file-name (newsgroup &optional suffix)
14145 "Return the name of a score file for NEWSGROUP."
14146 (let ((suffix (or suffix gnus-score-file-suffix)))
14147 (cond
14148 ((or (null newsgroup)
14149 (string-equal newsgroup ""))
14150 ;; The global score file is placed at top of the directory.
14151 (expand-file-name
14152 suffix (or gnus-kill-files-directory "~/News")))
14153 ((gnus-use-long-file-name 'not-score)
14154 ;; Append ".SCORE" to newsgroup name.
14155 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
14156 "." suffix)
14157 (or gnus-kill-files-directory "~/News")))
14158 (t
14159 ;; Place "SCORE" under the hierarchical directory.
14160 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
14161 "/" suffix)
14162 (or gnus-kill-files-directory "~/News"))))))
14163
14164 (defun gnus-score-search-global-directories (files)
14165 "Scan all global score directories for score files."
14166 ;; Set the variable `gnus-internal-global-score-files' to all
14167 ;; available global score files.
14168 (interactive (list gnus-global-score-files))
14169 (let (out)
14170 (while files
14171 (if (string-match "/$" (car files))
14172 (setq out (nconc (directory-files
14173 (car files) t
14174 (concat (gnus-score-file-regexp) "$"))))
14175 (setq out (cons (car files) out)))
14176 (setq files (cdr files)))
14177 (setq gnus-internal-global-score-files out)))
14178
14179 ;; Allow redefinition of Gnus functions.
14180
14181 (gnus-ems-redefine)
14182
14183 (provide 'gnus)
14184
14185 ;;; gnus.el ends here