(sh-alias-alist): Recognize lignux.
[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 (server ([server 1.0 point]
714 (if gnus-carpal [server-carpal 2])))
715 (browse ([browse 1.0 point]
716 (if gnus-carpal [browse-carpal 2])))
717 (group-mail ([mail 1.0 point]))
718 (summary-mail ([mail 1.0 point]))
719 (summary-reply ([article 0.5]
720 [mail 1.0 point]))
721 (info ([nil 1.0 point]))
722 (summary-faq ([summary 0.25]
723 [faq 1.0 point]))
724 (edit-group ([group 0.5]
725 [edit-group 1.0 point]))
726 (edit-server ([server 0.5]
727 [edit-server 1.0 point]))
728 (edit-score ([summary 0.25]
729 [edit-score 1.0 point]))
730 (post ([post 1.0 point]))
731 (reply ([article 0.5]
732 [mail 1.0 point]))
733 (mail-forward ([mail 1.0 point]))
734 (post-forward ([post 1.0 point]))
735 (reply-yank ([mail 1.0 point]))
736 (followup ([article 0.5]
737 [post 1.0 point]))
738 (followup-yank ([post 1.0 point])))
739 "Window configuration for all possible Gnus buffers.
740 This variable is a list of lists. Each of these lists has a NAME and
741 a RULE. The NAMEs are common-sense names like `group', which names a
742 rule used when displaying the group buffer; `summary', which names a
743 rule for what happens when you enter a group and do not display an
744 article buffer; and so on. See the value of this variable for a
745 complete list of NAMEs.
746
747 Each RULE is a list of vectors. The first element in this vector is
748 the name of the buffer to be displayed; the second element is the
749 percentage of the screen this buffer is to occupy (a number in the
750 0.0-0.99 range); the optional third element is `point', which should
751 be present to denote which buffer point is to go to after making this
752 buffer configuration.")
753
754 (defvar gnus-window-to-buffer
755 '((group . gnus-group-buffer)
756 (summary . gnus-summary-buffer)
757 (article . gnus-article-buffer)
758 (server . gnus-server-buffer)
759 (browse . "*Gnus Browse Server*")
760 (edit-group . gnus-group-edit-buffer)
761 (edit-server . gnus-server-edit-buffer)
762 (group-carpal . gnus-carpal-group-buffer)
763 (summary-carpal . gnus-carpal-summary-buffer)
764 (server-carpal . gnus-carpal-server-buffer)
765 (browse-carpal . gnus-carpal-browse-buffer)
766 (edit-score . gnus-score-edit-buffer)
767 (mail . gnus-mail-buffer)
768 (post . gnus-post-news-buffer)
769 (faq . gnus-faq-buffer))
770 "Mapping from short symbols to buffer names or buffer variables.")
771
772 (defvar gnus-carpal nil
773 "*If non-nil, display clickable icons.")
774
775 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
776 "*Function called with a group name when new group is detected.
777 A few pre-made functions are supplied: `gnus-subscribe-randomly'
778 inserts new groups at the beginning of the list of groups;
779 `gnus-subscribe-alphabetically' inserts new groups in strict
780 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
781 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
782 for your decision.")
783
784 ;; Suggested by a bug report by Hallvard B Furuseth.
785 ;; <h.b.furuseth@usit.uio.no>.
786 (defvar gnus-subscribe-options-newsgroup-method
787 (function gnus-subscribe-alphabetically)
788 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
789 If, for instance, you want to subscribe to all newsgroups in the
790 \"no\" and \"alt\" hierarchies, you'd put the following in your
791 .newsrc file:
792
793 options -n no.all alt.all
794
795 Gnus will the subscribe all new newsgroups in these hierarchies with
796 the subscription method in this variable.")
797
798 (defvar gnus-subscribe-hierarchical-interactive nil
799 "*If non-nil, Gnus will offer to subscribe hierarchically.
800 When a new hierarchy appears, Gnus will ask the user:
801
802 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
803
804 If the user pressed `d', Gnus will descend the hierarchy, `y' will
805 subscribe to all newsgroups in the hierarchy and `s' will skip this
806 hierarchy in its entirety.")
807
808 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
809 "*Function used for sorting the group buffer.
810 This function will be called with group info entries as the arguments
811 for the groups to be sorted. Pre-made functions include
812 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread' and
813 `gnus-group-sort-by-level'")
814
815 ;; Mark variables suggested by Thomas Michanek
816 ;; <Thomas.Michanek@telelogic.se>.
817 (defvar gnus-unread-mark ?
818 "*Mark used for unread articles.")
819 (defvar gnus-ticked-mark ?!
820 "*Mark used for ticked articles.")
821 (defvar gnus-dormant-mark ??
822 "*Mark used for dormant articles.")
823 (defvar gnus-del-mark ?r
824 "*Mark used for del'd articles.")
825 (defvar gnus-read-mark ?R
826 "*Mark used for read articles.")
827 (defvar gnus-expirable-mark ?E
828 "*Mark used for expirable articles.")
829 (defvar gnus-killed-mark ?K
830 "*Mark used for killed articles.")
831 (defvar gnus-kill-file-mark ?X
832 "*Mark used for articles killed by kill files.")
833 (defvar gnus-low-score-mark ?Y
834 "*Mark used for articles with a low score.")
835 (defvar gnus-catchup-mark ?C
836 "*Mark used for articles that are caught up.")
837 (defvar gnus-replied-mark ?A
838 "*Mark used for articles that have been replied to.")
839 (defvar gnus-process-mark ?#
840 "*Process mark.")
841 (defvar gnus-ancient-mark ?O
842 "*Mark used for ancient articles.")
843 (defvar gnus-canceled-mark ?G
844 "*Mark used for canceled articles.")
845 (defvar gnus-score-over-mark ?+
846 "*Score mark used for articles with high scores.")
847 (defvar gnus-score-below-mark ?-
848 "*Score mark used for articles with low scores.")
849 (defvar gnus-empty-thread-mark ?
850 "*There is no thread under the article.")
851 (defvar gnus-not-empty-thread-mark ?=
852 "*There is a thread under the article.")
853 (defvar gnus-dummy-mark ?Z
854 "*This is a dummy article.")
855
856 (defvar gnus-view-pseudo-asynchronously nil
857 "*If non-nil, Gnus will view pseudo-articles asynchronously.")
858
859 (defvar gnus-view-pseudos nil
860 "*If `automatic', pseudo-articles will be viewed automatically.
861 If `not-confirm', pseudos will be viewed automatically, and the user
862 will not be asked to confirm the command.")
863
864 (defvar gnus-view-pseudos-separately t
865 "*If non-nil, one pseudo-article will be created for each file to be viewed.
866 If nil, all files that use the same viewing command will be given as a
867 list of parameters to that command.")
868
869 (defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n"
870 "*Format of group lines.
871 It works along the same lines as a normal formatting string,
872 with some simple extensions.
873
874 %M Only marked articles (character, \"*\" or \" \")
875 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
876 %L Level of subscribedness (integer)
877 %N Number of unread articles (integer)
878 %I Number of dormant articles (integer)
879 %i Number of ticked and dormant (integer)
880 %T Number of ticked articles (integer)
881 %R Number of read articles (integer)
882 %t Total number of articles (integer)
883 %y Number of unread, unticked articles (integer)
884 %G Group name (string)
885 %g Qualified group name (string)
886 %D Group description (string)
887 %s Select method (string)
888 %o Moderated group (char, \"m\")
889 %p Process mark (char)
890 %O Moderated group (string, \"(m)\" or \"\")
891 %n Select from where (string)
892 %z A string that look like `<%s:%n>' if a foreign select method is used
893 %u User defined specifier. The next character in the format string should
894 be a letter. Gnus will call the function gnus-user-format-function-X,
895 where X is the letter following %u. The function will be passed the
896 current header as argument. The function should return a string, which
897 will be inserted into the buffer just like information from any other
898 group specifier.
899
900 Text between %( and %) will be highlighted with `gnus-mouse-face' when
901 the mouse point move inside the area. There can only be one such area.
902
903 Note that this format specification is not always respected. For
904 reasons of efficiency, when listing killed groups, this specification
905 is ignored altogether. If the spec is changed considerably, your
906 output may end up looking strange when listing both alive and killed
907 groups.
908
909 If you use %o or %O, reading the active file will be slower and quite
910 a bit of extra memory will be used. %D will also worsen performance.
911 Also note that if you change the format specification to include any
912 of these specs, you must probably re-start Gnus to see them go into
913 effect.")
914
915 (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
916 "*The format specification of the lines in the summary buffer.
917
918 It works along the same lines as a normal formatting string,
919 with some simple extensions.
920
921 %N Article number, left padded with spaces (string)
922 %S Subject (string)
923 %s Subject if it is at the root of a thread, and \"\" otherwise (string)
924 %n Name of the poster (string)
925 %a Extracted name of the poster (string)
926 %A Extracted address of the poster (string)
927 %F Contents of the From: header (string)
928 %x Contents of the Xref: header (string)
929 %D Date of the article (string)
930 %d Date of the article (string) in DD-MMM format
931 %M Message-id of the article (string)
932 %r References of the article (string)
933 %c Number of characters in the article (integer)
934 %L Number of lines in the article (integer)
935 %I Indentation based on thread level (a string of spaces)
936 %T A string with two possible values: 80 spaces if the article
937 is on thread level two or larger and 0 spaces on level one
938 %R \"A\" if this article has been replied to, \" \" otherwise (character)
939 %U Status of this article (character, \"R\", \"K\", \"-\" or \" \")
940 %[ Opening bracket (character, \"[\" or \"<\")
941 %] Closing bracket (character, \"]\" or \">\")
942 %> Spaces of length thread-level (string)
943 %< Spaces of length (- 20 thread-level) (string)
944 %i Article score (number)
945 %z Article zcore (character)
946 %t Number of articles under the current thread (number).
947 %e Whether the thread is empty or not (character).
948 %u User defined specifier. The next character in the format string should
949 be a letter. Gnus will call the function gnus-user-format-function-X,
950 where X is the letter following %u. The function will be passed the
951 current header as argument. The function should return a string, which
952 will be inserted into the summary just like information from any other
953 summary specifier.
954
955 Text between %( and %) will be highlighted with `gnus-mouse-face'
956 when the mouse point is placed inside the area. There can only be one
957 such area.
958
959 The %U (status), %R (replied) and %z (zcore) specs have to be handled
960 with care. For reasons of efficiency, Gnus will compute what column
961 these characters will end up in, and \"hard-code\" that. This means that
962 it is illegal to have these specs after a variable-length spec. Well,
963 you might not be arrested, but your summary buffer will look strange,
964 which is bad enough.
965
966 The smart choice is to have these specs as for to the left as
967 possible.
968
969 This restriction may disappear in later versions of Gnus.")
970
971 (defvar gnus-summary-dummy-line-format "* : : %S\n"
972 "*The format specification for the dummy roots in the summary buffer.
973 It works along the same lines as a normal formatting string,
974 with some simple extensions.
975
976 %S The subject")
977
978 (defvar gnus-summary-mode-line-format "Gnus: %b [%A] %Z"
979 "*The format specification for the summary mode line.")
980
981 (defvar gnus-article-mode-line-format "Gnus: %b %S"
982 "*The format specification for the article mode line.")
983
984 (defvar gnus-group-mode-line-format "Gnus: %b {%M:%S} "
985 "*The format specification for the group mode line.")
986
987 (defvar gnus-valid-select-methods
988 '(("nntp" post address prompt-address)
989 ("nnspool" post)
990 ("nnvirtual" none virtual prompt-address)
991 ("nnmbox" mail respool)
992 ("nnml" mail respool)
993 ("nnmh" mail respool)
994 ("nndir" none prompt-address address)
995 ("nneething" none prompt-address)
996 ("nndigest" none)
997 ("nndoc" none prompt-address)
998 ("nnbabyl" mail respool)
999 ("nnkiboze" post virtual)
1000 ;;("nnsoup" post)
1001 ("nnfolder" mail respool))
1002 "An alist of valid select methods.
1003 The first element of each list lists should be a string with the name
1004 of the select method. The other elements may be be the category of
1005 this method (ie. `post', `mail', `none' or whatever) or other
1006 properties that this method has (like being respoolable).
1007 If you implement a new select method, all you should have to change is
1008 this variable. I think.")
1009
1010 (defvar gnus-updated-mode-lines '(group article summary)
1011 "*List of buffers that should update their mode lines.
1012 The list may contain the symbols `group', `article' and `summary'. If
1013 the corresponding symbol is present, Gnus will keep that mode line
1014 updated with information that may be pertinent.
1015 If this variable is nil, screen refresh may be quicker.")
1016
1017 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1018 (defvar gnus-mode-non-string-length nil
1019 "*Max length of mode-line non-string contents.
1020 If this is nil, Gnus will take space as is needed, leaving the rest
1021 of the modeline intact.")
1022
1023 ;see gnus-cus.el
1024 ;(defvar gnus-mouse-face 'highlight
1025 ; "*Face used for mouse highlighting in Gnus.
1026 ;No mouse highlights will be done if `gnus-visual' is nil.")
1027
1028 (defvar gnus-summary-mark-below nil
1029 "*Mark all articles with a score below this variable as read.
1030 This variable is local to each summary buffer and usually set by the
1031 score file.")
1032
1033 (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
1034 "*List of functions used for sorting threads in the summary buffer.
1035 By default, threads are sorted by article number.
1036
1037 Each function takes two threads and return non-nil if the first thread
1038 should be sorted before the other. If you use more than one function,
1039 the primary sort function should be the last.
1040
1041 Ready-mady functions include `gnus-thread-sort-by-number',
1042 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
1043 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
1044 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
1045
1046 (defvar gnus-thread-score-function '+
1047 "*Function used for calculating the total score of a thread.
1048
1049 The function is called with the scores of the article and each
1050 subthread and should then return the score of the thread.
1051
1052 Some functions you can use are `+', `max', or `min'.")
1053
1054 (defvar gnus-options-subscribe nil
1055 "*All new groups matching this regexp will be subscribed unconditionally.
1056 Note that this variable deals only with new newsgroups. This variable
1057 does not affect old newsgroups.")
1058
1059 (defvar gnus-options-not-subscribe nil
1060 "*All new groups matching this regexp will be ignored.
1061 Note that this variable deals only with new newsgroups. This variable
1062 does not affect old (already subscribed) newsgroups.")
1063
1064 (defvar gnus-auto-expirable-newsgroups nil
1065 "*Groups in which to automatically mark read articles as expirable.
1066 If non-nil, this should be a regexp that should match all groups in
1067 which to perform auto-expiry. This only makes sense for mail groups.")
1068
1069 (defvar gnus-hidden-properties '(invisible t intangible t)
1070 "Property list to use for hiding text.")
1071
1072 (defvar gnus-modtime-botch nil
1073 "*Non-nil means .newsrc should be deleted prior to save. Its use is
1074 due to the bogus appearance that .newsrc was modified on disc.")
1075
1076 ;; Hooks.
1077
1078 (defvar gnus-group-mode-hook nil
1079 "*A hook for Gnus group mode.")
1080
1081 (defvar gnus-summary-mode-hook nil
1082 "*A hook for Gnus summary mode.
1083 This hook is run before any variables are set in the summary buffer.")
1084
1085 (defvar gnus-article-mode-hook nil
1086 "*A hook for Gnus article mode.")
1087
1088 (defun gnus-summary-prepare-exit-hook nil
1089 "*A hook called when preparing to exit from the summary buffer.
1090 It calls `gnus-summary-expire-articles' by default.")
1091 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
1092
1093 (defun gnus-summary-exit-hook nil
1094 "*A hook called on exit from the summary buffer.")
1095
1096 (defvar gnus-open-server-hook nil
1097 "*A hook called just before opening connection to the news server.")
1098
1099 (defvar gnus-load-hook nil
1100 "*A hook run while Gnus is loaded.")
1101
1102 (defvar gnus-startup-hook nil
1103 "*A hook called at startup.
1104 This hook is called after Gnus is connected to the NNTP server.")
1105
1106 (defvar gnus-get-new-news-hook nil
1107 "*A hook run just before Gnus checks for new news.")
1108
1109 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
1110 "*A function that is called to generate the group buffer.
1111 The function is called with three arguments: The first is a number;
1112 all group with a level less or equal to that number should be listed,
1113 if the second is non-nil, empty groups should also be displayed. If
1114 the third is non-nil, it is a number. No groups with a level lower
1115 than this number should be displayed.
1116
1117 The only current function implemented is `gnus-group-prepare-flat'.")
1118
1119 (defvar gnus-group-prepare-hook nil
1120 "*A hook called after the group buffer has been generated.
1121 If you want to modify the group buffer, you can use this hook.")
1122
1123 (defvar gnus-summary-prepare-hook nil
1124 "*A hook called after the summary buffer has been generated.
1125 If you want to modify the summary buffer, you can use this hook.")
1126
1127 (defvar gnus-article-prepare-hook nil
1128 "*A hook called after an article has been prepared in the article buffer.
1129 If you want to run a special decoding program like nkf, use this hook.")
1130
1131 ;(defvar gnus-article-display-hook nil
1132 ; "*A hook called after the article is displayed in the article buffer.
1133 ;The hook is designed to change the contents of the article
1134 ;buffer. Typical functions that this hook may contain are
1135 ;`gnus-article-hide-headers' (hide selected headers),
1136 ;`gnus-article-maybe-highlight' (perform fancy article highlighting),
1137 ;`gnus-article-hide-signature' (hide signature) and
1138 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
1139 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
1140 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
1141 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
1142
1143 (defvar gnus-article-x-face-command
1144 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
1145 "String or function to be executed to display an X-Face header.
1146 If it is a string, the command will be executed in a sub-shell
1147 asynchronously. The compressed face will be piped to this command.")
1148
1149 (defvar gnus-article-x-face-too-ugly nil
1150 "Regexp matching posters whose face shouldn't be shown automatically.")
1151
1152 (defvar gnus-select-group-hook nil
1153 "*A hook called when a newsgroup is selected.
1154
1155 If you'd like to simplify subjects like the
1156 `gnus-summary-next-same-subject' command does, you can use the
1157 following hook:
1158
1159 (setq gnus-select-group-hook
1160 (list
1161 (lambda ()
1162 (mapcar (lambda (header)
1163 (mail-header-set-subject
1164 header
1165 (gnus-simplify-subject
1166 (mail-header-subject header) 're-only)))
1167 gnus-newsgroup-headers))))")
1168
1169 (defvar gnus-select-article-hook
1170 '(gnus-summary-show-thread)
1171 "*A hook called when an article is selected.
1172 The default hook shows conversation thread subtrees of the selected
1173 article automatically using `gnus-summary-show-thread'.")
1174
1175 (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
1176 "*A hook called to apply kill files to a group.
1177 This hook is intended to apply a kill file to the selected newsgroup.
1178 The function `gnus-apply-kill-file' is called by default.
1179
1180 Since a general kill file is too heavy to use only for a few
1181 newsgroups, I recommend you to use a lighter hook function. For
1182 example, if you'd like to apply a kill file to articles which contains
1183 a string `rmgroup' in subject in newsgroup `control', you can use the
1184 following hook:
1185
1186 (setq gnus-apply-kill-hook
1187 (list
1188 (lambda ()
1189 (cond ((string-match \"control\" gnus-newsgroup-name)
1190 (gnus-kill \"Subject\" \"rmgroup\")
1191 (gnus-expunge \"X\"))))))")
1192
1193 (defvar gnus-visual-mark-article-hook
1194 (list 'gnus-highlight-selected-summary)
1195 "*Hook run after selecting an article in the summary buffer.
1196 It is meant to be used for highlighting the article in some way. It
1197 is not run if `gnus-visual' is nil.")
1198
1199 (defun gnus-parse-headers-hook nil
1200 "*A hook called before parsing the headers.")
1201
1202 (defvar gnus-exit-group-hook nil
1203 "*A hook called when exiting (not quitting) summary mode.")
1204
1205 (defvar gnus-suspend-gnus-hook nil
1206 "*A hook called when suspending (not exiting) Gnus.")
1207
1208 (defvar gnus-exit-gnus-hook nil
1209 "*A hook called when exiting Gnus.")
1210
1211 (defvar gnus-save-newsrc-hook nil
1212 "*A hook called when saving the newsrc file.")
1213
1214 (defvar gnus-summary-update-hook
1215 (list 'gnus-summary-highlight-line)
1216 "*A hook called when a summary line is changed.
1217 The hook will not be called if `gnus-visual' is nil.
1218
1219 The default function `gnus-summary-highlight-line' will
1220 highlight the line according to the `gnus-summary-highlight'
1221 variable.")
1222
1223 (defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read)
1224 "*A hook called when an article is selected for the first time.
1225 The hook is intended to mark an article as read (or unread)
1226 automatically when it is selected.")
1227
1228 ;; Remove any hilit infestation.
1229 (add-hook 'gnus-startup-hook
1230 (lambda ()
1231 (remove-hook 'gnus-summary-prepare-hook
1232 'hilit-rehighlight-buffer-quietly)
1233 (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
1234 (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read))
1235 (remove-hook 'gnus-article-prepare-hook
1236 'hilit-rehighlight-buffer-quietly)))
1237
1238
1239 \f
1240 ;; Internal variables
1241
1242 ;; Avoid highlighting in kill files.
1243 (defvar gnus-summary-inhibit-highlight nil)
1244 (defvar gnus-newsgroup-selected-overlay nil)
1245
1246 (defvar gnus-article-mode-map nil)
1247 (defvar gnus-dribble-buffer nil)
1248 (defvar gnus-headers-retrieved-by nil)
1249 (defvar gnus-article-reply nil)
1250 (defvar gnus-override-method nil)
1251 (defvar gnus-article-check-size nil)
1252
1253 (defvar gnus-current-score-file nil)
1254 (defvar gnus-internal-global-score-files nil)
1255 (defvar gnus-score-file-list nil)
1256 (defvar gnus-scores-exclude-files nil)
1257
1258 (defvar gnus-current-move-group nil)
1259
1260 (defvar gnus-newsgroup-dependencies nil)
1261 (defvar gnus-newsgroup-threads nil)
1262 (defvar gnus-newsgroup-async nil)
1263 (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
1264
1265 (defvar gnus-newsgroup-adaptive nil)
1266
1267 (defvar gnus-summary-display-table nil)
1268
1269 (defconst gnus-group-line-format-alist
1270 (list (list ?M 'marked ?c)
1271 (list ?S 'subscribed ?c)
1272 (list ?L 'level ?d)
1273 (list ?N 'number ?s)
1274 (list ?I 'number-of-dormant ?d)
1275 (list ?T 'number-of-ticked ?d)
1276 (list ?R 'number-of-read ?s)
1277 (list ?t 'number-total ?d)
1278 (list ?y 'number-of-unread-unticked ?s)
1279 (list ?i 'number-of-ticked-and-dormant ?d)
1280 (list ?g 'group ?s)
1281 (list ?G 'qualified-group ?s)
1282 (list ?D 'newsgroup-description ?s)
1283 (list ?o 'moderated ?c)
1284 (list ?O 'moderated-string ?s)
1285 (list ?p 'process-marked ?c)
1286 (list ?s 'news-server ?s)
1287 (list ?n 'news-method ?s)
1288 (list ?z 'news-method-string ?s)
1289 (list ?u 'user-defined ?s)))
1290
1291 (defconst gnus-summary-line-format-alist
1292 (list (list ?N 'number ?d)
1293 (list ?S 'subject ?s)
1294 (list ?s 'subject-or-nil ?s)
1295 (list ?n 'name ?s)
1296 (list ?A '(car (cdr (funcall gnus-extract-address-components from)))
1297 ?s)
1298 (list ?a '(or (car (funcall gnus-extract-address-components from))
1299 from) ?s)
1300 (list ?F 'from ?s)
1301 (list ?x (macroexpand '(mail-header-xref header)) ?s)
1302 (list ?D (macroexpand '(mail-header-date header)) ?s)
1303 (list ?d '(gnus-dd-mmm (mail-header-date header)) ?s)
1304 (list ?M (macroexpand '(mail-header-id header)) ?s)
1305 (list ?r (macroexpand '(mail-header-references header)) ?s)
1306 (list ?c '(or (mail-header-chars header) 0) ?d)
1307 (list ?L 'lines ?d)
1308 (list ?I 'indentation ?s)
1309 (list ?T '(if (= level 0) "" (make-string (frame-width) ? )) ?s)
1310 (list ?R 'replied ?c)
1311 (list ?\[ 'opening-bracket ?c)
1312 (list ?\] 'closing-bracket ?c)
1313 (list ?\> '(make-string level ? ) ?s)
1314 (list ?\< '(make-string (max 0 (- 20 level)) ? ) ?s)
1315 (list ?i 'score ?d)
1316 (list ?z 'score-char ?c)
1317 (list ?U 'unread ?c)
1318 (list ?t '(gnus-summary-number-of-articles-in-thread
1319 (and (boundp 'thread) (car thread)))
1320 ?d)
1321 (list ?e '(gnus-summary-number-of-articles-in-thread
1322 (and (boundp 'thread) (car thread)) t)
1323 ?c)
1324 (list ?u 'user-defined ?s))
1325 "An alist of format specifications that can appear in summary lines,
1326 and what variables they correspond with, along with the type of the
1327 variable (string, integer, character, etc).")
1328
1329 (defconst gnus-summary-dummy-line-format-alist
1330 (list (list ?S 'subject ?s)
1331 (list ?N 'number ?d)
1332 (list ?u 'user-defined ?s)))
1333
1334 (defconst gnus-summary-mode-line-format-alist
1335 (list (list ?G 'group-name ?s)
1336 (list ?g '(gnus-short-group-name group-name) ?s)
1337 (list ?A 'article-number ?d)
1338 (list ?Z 'unread-and-unselected ?s)
1339 (list ?V 'gnus-version ?s)
1340 (list ?U 'unread ?d)
1341 (list ?S 'subject ?s)
1342 (list ?e 'unselected ?d)
1343 (list ?u 'user-defined ?s)
1344 (list ?b 'buffer-name ?s)
1345 (list ?s '(gnus-current-score-file-nondirectory) ?s)))
1346
1347 (defconst gnus-group-mode-line-format-alist
1348 (list (list ?S 'news-server ?s)
1349 (list ?M 'news-method ?s)
1350 (list ?b '(buffer-name) ?s)
1351 (list ?u 'user-defined ?s)))
1352
1353 (defvar gnus-have-read-active-file nil)
1354
1355 (defconst gnus-maintainer
1356 "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
1357 "The mail address of the Gnus maintainers.")
1358
1359 (defconst gnus-version "Gnus v5.1"
1360 "Version number for this version of Gnus.")
1361
1362 (defvar gnus-info-nodes
1363 '((gnus-group-mode "(gnus)The Group Buffer")
1364 (gnus-summary-mode "(gnus)The Summary Buffer")
1365 (gnus-article-mode "(gnus)The Article Buffer"))
1366 "Assoc list of major modes and related Info nodes.")
1367
1368 (defvar gnus-group-buffer "*Group*")
1369 (defvar gnus-summary-buffer "*Summary*")
1370 (defvar gnus-article-buffer "*Article*")
1371 (defvar gnus-server-buffer "*Server*")
1372
1373 (defvar gnus-work-buffer " *gnus work*")
1374
1375 (defvar gnus-buffer-list nil
1376 "Gnus buffers that should be killed on exit.")
1377
1378 (defvar gnus-server-alist nil
1379 "List of available servers.")
1380
1381 (defvar gnus-variable-list
1382 '(gnus-newsrc-options gnus-newsrc-options-n
1383 gnus-newsrc-last-checked-date
1384 gnus-newsrc-alist gnus-server-alist
1385 gnus-killed-list gnus-zombie-list)
1386 "Gnus variables saved in the quick startup file.")
1387
1388 (defvar gnus-overload-functions
1389 '((news-inews gnus-inews-news "rnewspost"))
1390 "Functions overloaded by gnus.
1391 It is a list of `(original overload &optional file)'.")
1392
1393 (defvar gnus-newsrc-options nil
1394 "Options line in the .newsrc file.")
1395
1396 (defvar gnus-newsrc-options-n nil
1397 "List of regexps representing groups to be subscribed/ignored unconditionally.")
1398
1399 (defvar gnus-newsrc-last-checked-date nil
1400 "Date Gnus last asked server for new newsgroups.")
1401
1402 (defvar gnus-newsrc-alist nil
1403 "Assoc list of read articles.
1404 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1405
1406 (defvar gnus-newsrc-hashtb nil
1407 "Hashtable of gnus-newsrc-alist.")
1408
1409 (defvar gnus-killed-list nil
1410 "List of killed newsgroups.")
1411
1412 (defvar gnus-killed-hashtb nil
1413 "Hash table equivalent of gnus-killed-list.")
1414
1415 (defvar gnus-zombie-list nil
1416 "List of almost dead newsgroups.")
1417
1418 (defvar gnus-description-hashtb nil
1419 "Descriptions of newsgroups.")
1420
1421 (defvar gnus-list-of-killed-groups nil
1422 "List of newsgroups that have recently been killed by the user.")
1423
1424 (defvar gnus-active-hashtb nil
1425 "Hashtable of active articles.")
1426
1427 (defvar gnus-moderated-list nil
1428 "List of moderated newsgroups.")
1429
1430 (defvar gnus-group-marked nil)
1431
1432 (defvar gnus-current-startup-file nil
1433 "Startup file for the current host.")
1434
1435 (defvar gnus-last-search-regexp nil
1436 "Default regexp for article search command.")
1437
1438 (defvar gnus-last-shell-command nil
1439 "Default shell command on article.")
1440
1441 (defvar gnus-current-select-method nil
1442 "The current method for selecting a newsgroup.")
1443
1444 (defvar gnus-group-list-mode nil)
1445
1446 (defvar gnus-article-internal-prepare-hook nil)
1447
1448 (defvar gnus-newsgroup-name nil)
1449 (defvar gnus-newsgroup-begin nil)
1450 (defvar gnus-newsgroup-end nil)
1451 (defvar gnus-newsgroup-last-rmail nil)
1452 (defvar gnus-newsgroup-last-mail nil)
1453 (defvar gnus-newsgroup-last-folder nil)
1454 (defvar gnus-newsgroup-last-file nil)
1455 (defvar gnus-newsgroup-auto-expire nil)
1456 (defvar gnus-newsgroup-active nil)
1457
1458 (defvar gnus-newsgroup-unreads nil
1459 "List of unread articles in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-unselected nil
1462 "List of unselected unread articles in the current newsgroup.")
1463
1464 (defvar gnus-newsgroup-reads nil
1465 "Alist of read articles and article marks in the current newsgroup.")
1466
1467 (defvar gnus-newsgroup-marked nil
1468 "List of ticked articles in the current newsgroup (a subset of unread art).")
1469
1470 (defvar gnus-newsgroup-killed nil
1471 "List of ranges of articles that have been through the scoring process.")
1472
1473 (defvar gnus-newsgroup-kill-headers nil)
1474
1475 (defvar gnus-newsgroup-replied nil
1476 "List of articles that have been replied to in the current newsgroup.")
1477
1478 (defvar gnus-newsgroup-expirable nil
1479 "List of articles in the current newsgroup that can be expired.")
1480
1481 (defvar gnus-newsgroup-processable nil
1482 "List of articles in the current newsgroup that can be processed.")
1483
1484 (defvar gnus-newsgroup-bookmarks nil
1485 "List of articles in the current newsgroup that have bookmarks.")
1486
1487 (defvar gnus-newsgroup-dormant nil
1488 "List of dormant articles in the current newsgroup.")
1489
1490 (defvar gnus-newsgroup-scored nil
1491 "List of scored articles in the current newsgroup.")
1492
1493 (defvar gnus-newsgroup-headers nil
1494 "List of article headers in the current newsgroup.")
1495 (defvar gnus-newsgroup-headers-hashtb-by-number nil)
1496
1497 (defvar gnus-newsgroup-ancient nil
1498 "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1499
1500 (defvar gnus-current-article nil)
1501 (defvar gnus-article-current nil)
1502 (defvar gnus-current-headers nil)
1503 (defvar gnus-have-all-headers nil)
1504 (defvar gnus-last-article nil)
1505 (defvar gnus-newsgroup-history nil)
1506 (defvar gnus-current-kill-article nil)
1507
1508 ;; Save window configuration.
1509 (defvar gnus-prev-winconf nil)
1510
1511 ;; Format specs
1512 (defvar gnus-summary-line-format-spec nil)
1513 (defvar gnus-summary-dummy-line-format-spec nil)
1514 (defvar gnus-group-line-format-spec nil)
1515 (defvar gnus-summary-mode-line-format-spec nil)
1516 (defvar gnus-article-mode-line-format-spec nil)
1517 (defvar gnus-group-mode-line-format-spec nil)
1518 (defvar gnus-summary-mark-positions nil)
1519 (defvar gnus-group-mark-positions nil)
1520
1521 (defvar gnus-summary-expunge-below nil)
1522 (defvar gnus-reffed-article-number nil)
1523
1524 ; Let the byte-compiler know that we know about this variable.
1525 (defvar rmail-default-rmail-file)
1526
1527 (defvar gnus-cache-removable-articles nil)
1528
1529 (defconst gnus-summary-local-variables
1530 '(gnus-newsgroup-name
1531 gnus-newsgroup-begin gnus-newsgroup-end
1532 gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1533 gnus-newsgroup-last-folder gnus-newsgroup-last-file
1534 gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1535 gnus-newsgroup-unselected gnus-newsgroup-marked
1536 gnus-newsgroup-reads
1537 gnus-newsgroup-replied gnus-newsgroup-expirable
1538 gnus-newsgroup-processable gnus-newsgroup-killed
1539 gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1540 gnus-newsgroup-headers gnus-newsgroup-headers-hashtb-by-number
1541 gnus-current-article gnus-current-headers gnus-have-all-headers
1542 gnus-last-article gnus-article-internal-prepare-hook
1543 gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1544 gnus-newsgroup-scored gnus-newsgroup-kill-headers
1545 gnus-newsgroup-threads gnus-newsgroup-async
1546 gnus-score-alist gnus-current-score-file gnus-summary-expunge-below
1547 gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files
1548 gnus-newsgroup-history gnus-newsgroup-ancient
1549 (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1550 gnus-cache-removable-articles)
1551 "Variables that are buffer-local to the summary buffers.")
1552
1553 (defconst gnus-bug-message
1554 "Sending a bug report to the Gnus Towers.
1555 ========================================
1556
1557 The buffer below is a mail buffer. When you press `C-c C-c', it will
1558 be sent to the Gnus Bug Exterminators.
1559
1560 At the bottom of the buffer you'll see lots of variable settings.
1561 Please do not delete those. They will tell the Bug People what your
1562 environment is, so that it will be easier to locate the bugs.
1563
1564 If you have found a bug that makes Emacs go \"beep\", set
1565 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
1566 and include the backtrace in your bug report.
1567
1568 Please describe the bug in annoying, painstaking detail.
1569
1570 Thank you for your help in stamping out bugs.
1571 ")
1572
1573 ;;; End of variables.
1574
1575 ;; Define some autoload functions Gnus might use.
1576 (eval-and-compile
1577
1578 ;; Various
1579 (autoload 'metamail-buffer "metamail")
1580 (autoload 'Info-goto-node "info")
1581 (autoload 'hexl-hex-string-to-integer "hexl")
1582 (autoload 'pp "pp")
1583 (autoload 'pp-to-string "pp")
1584 (autoload 'pp-eval-expression "pp")
1585 (autoload 'mail-extract-address-components "mail-extr")
1586
1587 (autoload 'nnmail-split-fancy "nnmail")
1588 (autoload 'nnvirtual-catchup-group "nnvirtual")
1589
1590 ;; timezone
1591 (autoload 'timezone-make-date-arpa-standard "timezone")
1592 (autoload 'timezone-fix-time "timezone")
1593 (autoload 'timezone-make-sortable-date "timezone")
1594 (autoload 'timezone-make-time-string "timezone")
1595
1596 ;; rmail & friends
1597 (autoload 'mail-position-on-field "sendmail")
1598 (autoload 'mail-setup "sendmail")
1599 (autoload 'rmail-output "rmailout")
1600 (autoload 'news-mail-other-window "rnewspost")
1601 (autoload 'news-reply-yank-original "rnewspost")
1602 (autoload 'news-caesar-buffer-body "rnewspost")
1603 (autoload 'rmail-insert-rmail-file-header "rmail")
1604 (autoload 'rmail-count-new-messages "rmail")
1605 (autoload 'rmail-show-message "rmail")
1606
1607 ;; gnus-soup
1608 ;;(autoload 'gnus-group-brew-soup "gnus-soup" nil t)
1609 ;;(autoload 'gnus-brew-soup "gnus-soup" nil t)
1610 ;;(autoload 'gnus-soup-add-article "gnus-soup" nil t)
1611 ;;(autoload 'gnus-soup-send-replies "gnus-soup" nil t)
1612 ;;(autoload 'gnus-soup-save-areas "gnus-soup" nil t)
1613 ;;(autoload 'gnus-soup-pack-packet "gnus-soup" nil t)
1614 ;;(autoload 'nnsoup-pack-replies "nnsoup" nil t)
1615
1616 ;; gnus-mh
1617 (autoload 'gnus-mail-reply-using-mhe "gnus-mh")
1618 (autoload 'gnus-mail-forward-using-mhe "gnus-mh")
1619 (autoload 'gnus-mail-other-window-using-mhe "gnus-mh")
1620 (autoload 'gnus-summary-save-in-folder "gnus-mh" nil t)
1621 (autoload 'gnus-summary-save-article-folder "gnus-mh")
1622 (autoload 'gnus-Folder-save-name "gnus-mh")
1623 (autoload 'gnus-folder-save-name "gnus-mh")
1624
1625 ;; gnus-vis misc
1626 (autoload 'gnus-group-make-menu-bar "gnus-vis")
1627 (autoload 'gnus-summary-make-menu-bar "gnus-vis")
1628 (autoload 'gnus-server-make-menu-bar "gnus-vis")
1629 (autoload 'gnus-article-make-menu-bar "gnus-vis")
1630 (autoload 'gnus-browse-make-menu-bar "gnus-vis")
1631 (autoload 'gnus-highlight-selected-summary "gnus-vis")
1632 (autoload 'gnus-summary-highlight-line "gnus-vis")
1633 (autoload 'gnus-carpal-setup-buffer "gnus-vis")
1634
1635 ;; gnus-vis article
1636 (autoload 'gnus-article-push-button "gnus-vis" nil t)
1637 (autoload 'gnus-article-press-button "gnus-vis" nil t)
1638 (autoload 'gnus-article-highlight "gnus-vis" nil t)
1639 (autoload 'gnus-article-highlight-some "gnus-vis" nil t)
1640 (autoload 'gnus-article-hide "gnus-vis" nil t)
1641 (autoload 'gnus-article-hide-signature "gnus-vis" nil t)
1642 (autoload 'gnus-article-highlight-headers "gnus-vis" nil t)
1643 (autoload 'gnus-article-highlight-signature "gnus-vis" nil t)
1644 (autoload 'gnus-article-add-buttons "gnus-vis" nil t)
1645 (autoload 'gnus-article-next-button "gnus-vis" nil t)
1646 (autoload 'gnus-article-add-button "gnus-vis")
1647
1648 ;; gnus-cite
1649 (autoload 'gnus-article-highlight-citation "gnus-cite" nil t)
1650 (autoload 'gnus-article-hide-citation-maybe "gnus-cite" nil t)
1651 (autoload 'gnus-article-hide-citation "gnus-cite" nil t)
1652
1653 ;; gnus-kill
1654 (autoload 'gnus-kill "gnus-kill")
1655 (autoload 'gnus-apply-kill-file-internal "gnus-kill")
1656 (autoload 'gnus-kill-file-edit-file "gnus-kill")
1657 (autoload 'gnus-kill-file-raise-followups-to-author "gnus-kill")
1658 (autoload 'gnus-execute "gnus-kill")
1659 (autoload 'gnus-expunge "gnus-kill")
1660
1661 ;; gnus-cache
1662 (autoload 'gnus-cache-possibly-enter-article "gnus-cache")
1663 (autoload 'gnus-cache-save-buffers "gnus-cache")
1664 (autoload 'gnus-cache-possibly-remove-articles "gnus-cache")
1665 (autoload 'gnus-cache-request-article "gnus-cache")
1666 (autoload 'gnus-cache-retrieve-headers "gnus-cache")
1667 (autoload 'gnus-cache-possibly-alter-active "gnus-cache")
1668 (autoload 'gnus-jog-cache "gnus-cache" nil t)
1669 (autoload 'gnus-cache-enter-remove-article "gnus-cache")
1670
1671 ;; gnus-score
1672 (autoload 'gnus-summary-increase-score "gnus-score" nil t)
1673 (autoload 'gnus-summary-lower-score "gnus-score" nil t)
1674 (autoload 'gnus-summary-score-map "gnus-score" nil nil 'keymap)
1675 (autoload 'gnus-score-save "gnus-score")
1676 (autoload 'gnus-score-headers "gnus-score")
1677 (autoload 'gnus-current-score-file-nondirectory "gnus-score")
1678 (autoload 'gnus-score-adaptive "gnus-score")
1679 (autoload 'gnus-score-remove-lines-adaptive "gnus-score")
1680 (autoload 'gnus-score-find-trace "gnus-score")
1681
1682 ;; gnus-edit
1683 (autoload 'gnus-score-customize "gnus-edit" nil t)
1684
1685 ;; gnus-uu
1686 (autoload 'gnus-uu-extract-map "gnus-uu" nil nil 'keymap)
1687 (autoload 'gnus-uu-mark-map "gnus-uu" nil nil 'keymap)
1688 (autoload 'gnus-uu-digest-mail-forward "gnus-uu" nil t)
1689 (autoload 'gnus-uu-digest-post-forward "gnus-uu" nil t)
1690 (autoload 'gnus-uu-mark-series "gnus-uu" nil t)
1691 (autoload 'gnus-uu-mark-region "gnus-uu" nil t)
1692 (autoload 'gnus-uu-mark-by-regexp "gnus-uu" nil t)
1693 (autoload 'gnus-uu-mark-all "gnus-uu" nil t)
1694 (autoload 'gnus-uu-mark-sparse "gnus-uu" nil t)
1695 (autoload 'gnus-uu-mark-thread "gnus-uu" nil t)
1696 (autoload 'gnus-uu-decode-uu "gnus-uu" nil t)
1697 (autoload 'gnus-uu-decode-uu-and-save "gnus-uu" nil t)
1698 (autoload 'gnus-uu-decode-unshar "gnus-uu" nil t)
1699 (autoload 'gnus-uu-decode-unshar-and-save "gnus-uu" nil t)
1700 (autoload 'gnus-uu-decode-save "gnus-uu" nil t)
1701 (autoload 'gnus-uu-decode-binhex "gnus-uu" nil t)
1702 (autoload 'gnus-uu-decode-uu-view "gnus-uu" nil t)
1703 (autoload 'gnus-uu-decode-uu-and-save-view "gnus-uu" nil t)
1704 (autoload 'gnus-uu-decode-unshar-view "gnus-uu" nil t)
1705 (autoload 'gnus-uu-decode-unshar-and-save-view "gnus-uu" nil t)
1706 (autoload 'gnus-uu-decode-save-view "gnus-uu" nil t)
1707 (autoload 'gnus-uu-decode-binhex-view "gnus-uu" nil t)
1708
1709 ;; gnus-msg
1710 (autoload 'gnus-summary-send-map "gnus-msg" nil nil 'keymap)
1711 (autoload 'gnus-group-post-news "gnus-msg" nil t)
1712 (autoload 'gnus-group-mail "gnus-msg" nil t)
1713 (autoload 'gnus-summary-post-news "gnus-msg" nil t)
1714 (autoload 'gnus-summary-followup "gnus-msg" nil t)
1715 (autoload 'gnus-summary-followup-with-original "gnus-msg" nil t)
1716 (autoload 'gnus-summary-followup-and-reply "gnus-msg" nil t)
1717 (autoload 'gnus-summary-followup-and-reply-with-original "gnus-msg" nil t)
1718 (autoload 'gnus-summary-cancel-article "gnus-msg" nil t)
1719 (autoload 'gnus-summary-supersede-article "gnus-msg" nil t)
1720 (autoload 'gnus-post-news "gnus-msg" nil t)
1721 (autoload 'gnus-inews-news "gnus-msg" nil t)
1722 (autoload 'gnus-cancel-news "gnus-msg" nil t)
1723 (autoload 'gnus-summary-reply "gnus-msg" nil t)
1724 (autoload 'gnus-summary-reply-with-original "gnus-msg" nil t)
1725 (autoload 'gnus-summary-mail-forward "gnus-msg" nil t)
1726 (autoload 'gnus-summary-mail-other-window "gnus-msg" nil t)
1727 (autoload 'gnus-mail-reply-using-mail "gnus-msg")
1728 (autoload 'gnus-mail-yank-original "gnus-msg")
1729 (autoload 'gnus-mail-send-and-exit "gnus-msg")
1730 (autoload 'gnus-mail-forward-using-mail "gnus-msg")
1731 (autoload 'gnus-mail-other-window-using-mail "gnus-msg")
1732 (autoload 'gnus-article-mail "gnus-msg")
1733 (autoload 'gnus-bug "gnus-msg" nil t)
1734
1735 ;; gnus-vm
1736 (autoload 'gnus-summary-save-in-vm "gnus-vm" nil t)
1737 (autoload 'gnus-summary-save-article-vm "gnus-vm" nil t)
1738 (autoload 'gnus-mail-forward-using-vm "gnus-vm")
1739 (autoload 'gnus-mail-reply-using-vm "gnus-vm")
1740 (autoload 'gnus-mail-other-window-using-vm "gnus-vm" nil t)
1741 (autoload 'gnus-yank-article "gnus-vm" nil t)
1742
1743 )
1744
1745 \f
1746
1747 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1748 ;; If you want the cursor to go somewhere else, set these two
1749 ;; functions in some startup hook to whatever you want.
1750 (defalias 'gnus-summary-position-cursor 'gnus-goto-colon)
1751 (defalias 'gnus-group-position-cursor 'gnus-goto-colon)
1752
1753 ;;; Various macros and substs.
1754
1755 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
1756 "Pop to BUFFER, evaluate FORMS, and then returns to original window."
1757 (` (let ((GnusStartBufferWindow (selected-window)))
1758 (unwind-protect
1759 (progn
1760 (pop-to-buffer (, buffer))
1761 (,@ forms))
1762 (select-window GnusStartBufferWindow)))))
1763
1764 (defmacro gnus-gethash (string hashtable)
1765 "Get hash value of STRING in HASHTABLE."
1766 ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable))))
1767 ;;(` (abbrev-expansion (, string) (, hashtable)))
1768 (` (symbol-value (intern-soft (, string) (, hashtable)))))
1769
1770 (defmacro gnus-sethash (string value hashtable)
1771 "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
1772 ;; We cannot use define-abbrev since it only accepts string as value.
1773 ;; (set (intern string hashtable) value))
1774 (` (set (intern (, string) (, hashtable)) (, value))))
1775
1776 (defsubst gnus-buffer-substring (beg end)
1777 (buffer-substring (match-beginning beg) (match-end end)))
1778
1779 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1780 ;; function `substring' might cut on a middle of multi-octet
1781 ;; character.
1782 (defun gnus-truncate-string (str width)
1783 (substring str 0 width))
1784
1785 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
1786 ;; to limit the length of a string. This function is necessary since
1787 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
1788 (defsubst gnus-limit-string (str width)
1789 (if (> (length str) width)
1790 (substring str 0 width)
1791 str))
1792
1793 (defsubst gnus-simplify-subject-re (subject)
1794 "Remove \"Re:\" from subject lines."
1795 (let ((case-fold-search t))
1796 (if (string-match "^re: *" subject)
1797 (substring subject (match-end 0))
1798 subject)))
1799
1800 (defsubst gnus-goto-char (point)
1801 (and point (goto-char point)))
1802
1803 (defmacro gnus-buffer-exists-p (buffer)
1804 (` (and (, buffer)
1805 (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
1806 (, buffer)))))
1807
1808 (defmacro gnus-kill-buffer (buffer)
1809 (` (if (gnus-buffer-exists-p (, buffer))
1810 (kill-buffer (, buffer)))))
1811
1812 (defsubst gnus-point-at-bol ()
1813 "Return point at the beginning of line."
1814 (let ((p (point)))
1815 (beginning-of-line)
1816 (prog1
1817 (point)
1818 (goto-char p))))
1819
1820 (defsubst gnus-point-at-eol ()
1821 "Return point at the beginning of line."
1822 (let ((p (point)))
1823 (end-of-line)
1824 (prog1
1825 (point)
1826 (goto-char p))))
1827
1828 ;; Delete the current line (and the next N lines.);
1829 (defmacro gnus-delete-line (&optional n)
1830 (` (delete-region (progn (beginning-of-line) (point))
1831 (progn (forward-line (, (or n 1))) (point)))))
1832
1833 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1834 (defvar gnus-init-inhibit nil)
1835 (defun gnus-read-init-file (&optional inhibit-next)
1836 (if gnus-init-inhibit
1837 (setq gnus-init-inhibit nil)
1838 (setq gnus-init-inhibit inhibit-next)
1839 (and gnus-init-file
1840 (or (and (file-exists-p gnus-init-file)
1841 ;; Don't try to load a directory.
1842 (not (file-directory-p gnus-init-file)))
1843 (file-exists-p (concat gnus-init-file ".el"))
1844 (file-exists-p (concat gnus-init-file ".elc")))
1845 (load gnus-init-file nil t))))
1846
1847 ;;; Load the user startup file.
1848 ;; (eval '(gnus-read-init-file 'inhibit))
1849
1850 ;;; Load the compatibility functions.
1851
1852 (require 'gnus-cus)
1853 (require 'gnus-ems)
1854
1855 \f
1856 ;;;
1857 ;;; Gnus Utility Functions
1858 ;;;
1859
1860 (defun gnus-extract-address-components (from)
1861 (let (name address)
1862 ;; First find the address - the thing with the @ in it. This may
1863 ;; not be accurate in mail addresses, but does the trick most of
1864 ;; the time in news messages.
1865 (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
1866 (setq address (substring from (match-beginning 0) (match-end 0))))
1867 ;; Then we check whether the "name <address>" format is used.
1868 (and address
1869 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1870 ;; Linear white space is not required.
1871 (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
1872 (and (setq name (substring from 0 (match-beginning 0)))
1873 ;; Strip any quotes from the name.
1874 (string-match "\".*\"" name)
1875 (setq name (substring name 1 (1- (match-end 0))))))
1876 ;; If not, then "address (name)" is used.
1877 (or name
1878 (and (string-match "(.+)" from)
1879 (setq name (substring from (1+ (match-beginning 0))
1880 (1- (match-end 0)))))
1881 (and (string-match "()" from)
1882 (setq name address))
1883 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
1884 ;; XOVER might not support folded From headers.
1885 (and (string-match "(.*" from)
1886 (setq name (substring from (1+ (match-beginning 0))
1887 (match-end 0)))))
1888 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1889 (list (or name from) (or address from))))
1890
1891 (defun gnus-fetch-field (field)
1892 "Return the value of the header FIELD of current article."
1893 (save-excursion
1894 (save-restriction
1895 (let ((case-fold-search t))
1896 (gnus-narrow-to-headers)
1897 (mail-fetch-field field)))))
1898
1899 (defun gnus-goto-colon ()
1900 (beginning-of-line)
1901 (search-forward ":" (gnus-point-at-eol) t))
1902
1903 (defun gnus-narrow-to-headers ()
1904 (widen)
1905 (save-excursion
1906 (narrow-to-region
1907 (goto-char (point-min))
1908 (if (search-forward "\n\n" nil t)
1909 (1- (point))
1910 (point-max)))))
1911
1912 (defvar gnus-old-specs nil)
1913
1914 (defun gnus-update-format-specifications ()
1915 (gnus-make-thread-indent-array)
1916
1917 (let ((formats '(summary summary-dummy group
1918 summary-mode group-mode article-mode))
1919 old-format new-format)
1920 (while formats
1921 (setq new-format (symbol-value
1922 (intern (format "gnus-%s-line-format" (car formats)))))
1923 (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs)))
1924 (equal old-format new-format))
1925 (set (intern (format "gnus-%s-line-format-spec" (car formats)))
1926 (gnus-parse-format
1927 new-format
1928 (symbol-value
1929 (intern (format "gnus-%s-line-format-alist"
1930 (if (eq (car formats) 'article-mode)
1931 'summary-mode (car formats))))))))
1932 (setq gnus-old-specs (cons (cons (car formats) new-format)
1933 (delq (car formats) gnus-old-specs)))
1934 (setq formats (cdr formats))))
1935
1936 (gnus-update-group-mark-positions)
1937 (gnus-update-summary-mark-positions)
1938
1939 (if (and (string-match "%D" gnus-group-line-format)
1940 (not gnus-description-hashtb)
1941 gnus-read-active-file)
1942 (gnus-read-all-descriptions-files)))
1943
1944 (defun gnus-update-summary-mark-positions ()
1945 (save-excursion
1946 (let ((gnus-replied-mark 129)
1947 (gnus-score-below-mark 130)
1948 (gnus-score-over-mark 130)
1949 (thread nil)
1950 pos)
1951 (gnus-set-work-buffer)
1952 (gnus-summary-insert-line
1953 nil [0 "" "" "" "" "" 0 0 ""] 0 nil 128 t nil "" nil 1)
1954 (goto-char (point-min))
1955 (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
1956 (- (point) 2)))))
1957 (goto-char (point-min))
1958 (setq pos (cons (cons 'replied (and (search-forward "\201" nil t)
1959 (- (point) 2))) pos))
1960 (goto-char (point-min))
1961 (setq pos (cons (cons 'score (and (search-forward "\202" nil t)
1962 (- (point) 2))) pos))
1963 (setq gnus-summary-mark-positions pos))))
1964
1965 (defun gnus-update-group-mark-positions ()
1966 (save-excursion
1967 (let ((gnus-process-mark 128)
1968 (gnus-group-marked '("dummy.group")))
1969 (gnus-sethash "dummy.group" '(0 . 0) gnus-active-hashtb)
1970 (gnus-set-work-buffer)
1971 (gnus-group-insert-group-line nil "dummy.group" 0 nil 0 nil)
1972 (goto-char (point-min))
1973 (setq gnus-group-mark-positions
1974 (list (cons 'process (and (search-forward "\200" nil t)
1975 (- (point) 2))))))))
1976
1977 (defun gnus-mouse-face-function (form)
1978 (` (let ((string (, form)))
1979 (put-text-property 0 (length string) 'mouse-face gnus-mouse-face string)
1980 string)))
1981
1982 (defun gnus-max-width-function (el max-width)
1983 (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
1984 (` (let* ((val (eval (, el)))
1985 (valstr (if (numberp val)
1986 (int-to-string val) val)))
1987 (if (> (length valstr) (, max-width))
1988 (substring valstr 0 (, max-width))
1989 valstr))))
1990
1991 (defun gnus-parse-format (format spec-alist)
1992 ;; This function parses the FORMAT string with the help of the
1993 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
1994 ;; string. If the FORMAT string contains the specifiers %( and %)
1995 ;; the text between them will have the mouse-face text property.
1996 (if (string-match "\\`\\(.*\\)%(\\(.*\\)%)\\(.*\n?\\)\\'" format)
1997 (if (and gnus-visual gnus-mouse-face)
1998 (let ((pre (substring format (match-beginning 1) (match-end 1)))
1999 (button (substring format (match-beginning 2) (match-end 2)))
2000 (post (substring format (match-beginning 3) (match-end 3))))
2001 (list 'concat
2002 (gnus-parse-simple-format pre spec-alist)
2003 (gnus-mouse-face-function
2004 (gnus-parse-simple-format button spec-alist))
2005 (gnus-parse-simple-format post spec-alist)))
2006 (gnus-parse-simple-format
2007 (concat (substring format (match-beginning 1) (match-end 1))
2008 (substring format (match-beginning 2) (match-end 2))
2009 (substring format (match-beginning 3) (match-end 3)))
2010 spec-alist))
2011 (gnus-parse-simple-format format spec-alist)))
2012
2013 (defun gnus-parse-simple-format (format spec-alist)
2014 ;; This function parses the FORMAT string with the help of the
2015 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
2016 ;; string. The list will consist of the symbol `format', a format
2017 ;; specification string, and a list of forms depending on the
2018 ;; SPEC-ALIST.
2019 (let ((max-width 0)
2020 spec flist fstring newspec elem beg)
2021 (save-excursion
2022 (gnus-set-work-buffer)
2023 (insert format)
2024 (goto-char (point-min))
2025 (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?" nil t)
2026 (setq spec (string-to-char (buffer-substring (match-beginning 2)
2027 (match-end 2))))
2028 ;; First check if there are any specs that look anything like
2029 ;; "%12,12A", ie. with a "max width specification". These have
2030 ;; to be treated specially.
2031 (if (setq beg (match-beginning 1))
2032 (setq max-width
2033 (string-to-int
2034 (buffer-substring (1+ (match-beginning 1)) (match-end 1))))
2035 (setq max-width 0)
2036 (setq beg (match-beginning 2)))
2037 ;; Find the specification from `spec-alist'.
2038 (if (not (setq elem (cdr (assq spec spec-alist))))
2039 (setq elem '("*" ?s)))
2040 ;; Treat user defined format specifiers specially
2041 (and (eq (car elem) 'user-defined)
2042 (setq elem
2043 (list
2044 (list (intern (concat "gnus-user-format-function-"
2045 (buffer-substring
2046 (match-beginning 3)
2047 (match-end 3))))
2048 'header)
2049 ?s))
2050 (delete-region (match-beginning 3) (match-end 3)))
2051 (if (not (zerop max-width))
2052 (let ((el (car elem)))
2053 (cond ((= (car (cdr elem)) ?c)
2054 (setq el (list 'char-to-string el)))
2055 ((= (car (cdr elem)) ?d)
2056 (numberp el) (setq el (list 'int-to-string el))))
2057 (setq flist (cons (gnus-max-width-function el max-width)
2058 flist))
2059 (setq newspec ?s))
2060 (setq flist (cons (car elem) flist))
2061 (setq newspec (car (cdr elem))))
2062 ;; Remove the old specification (and possibly a ",12" string).
2063 (delete-region beg (match-end 2))
2064 ;; Insert the new specification.
2065 (goto-char beg)
2066 (insert newspec))
2067 (setq fstring (buffer-substring 1 (point-max))))
2068 (cons 'format (cons fstring (nreverse flist)))))
2069
2070 (defun gnus-set-work-buffer ()
2071 (if (get-buffer gnus-work-buffer)
2072 (progn
2073 (set-buffer gnus-work-buffer)
2074 (erase-buffer))
2075 (set-buffer (get-buffer-create gnus-work-buffer))
2076 (kill-all-local-variables)
2077 (buffer-disable-undo (current-buffer))
2078 (gnus-add-current-to-buffer-list)))
2079
2080 ;; Article file names when saving.
2081
2082 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2083 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2084 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
2085 Otherwise, it is like ~/News/news/group/num."
2086 (let ((default
2087 (expand-file-name
2088 (concat (if (gnus-use-long-file-name 'not-save)
2089 (gnus-capitalize-newsgroup newsgroup)
2090 (gnus-newsgroup-directory-form newsgroup))
2091 "/" (int-to-string (mail-header-number headers)))
2092 (or gnus-article-save-directory "~/News"))))
2093 (if (and last-file
2094 (string-equal (file-name-directory default)
2095 (file-name-directory last-file))
2096 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2097 default
2098 (or last-file default))))
2099
2100 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2101 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2102 If variable `gnus-use-long-file-name' is non-nil, it is
2103 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2104 (let ((default
2105 (expand-file-name
2106 (concat (if (gnus-use-long-file-name 'not-save)
2107 newsgroup
2108 (gnus-newsgroup-directory-form newsgroup))
2109 "/" (int-to-string (mail-header-number headers)))
2110 (or gnus-article-save-directory "~/News"))))
2111 (if (and last-file
2112 (string-equal (file-name-directory default)
2113 (file-name-directory last-file))
2114 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2115 default
2116 (or last-file default))))
2117
2118 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2119 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2120 If variable `gnus-use-long-file-name' is non-nil, it is
2121 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2122 (or last-file
2123 (expand-file-name
2124 (if (gnus-use-long-file-name 'not-save)
2125 (gnus-capitalize-newsgroup newsgroup)
2126 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2127 (or gnus-article-save-directory "~/News"))))
2128
2129 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2130 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2131 If variable `gnus-use-long-file-name' is non-nil, it is
2132 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2133 (or last-file
2134 (expand-file-name
2135 (if (gnus-use-long-file-name 'not-save)
2136 newsgroup
2137 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2138 (or gnus-article-save-directory "~/News"))))
2139
2140 ;; For subscribing new newsgroup
2141
2142 (defun gnus-subscribe-hierarchical-interactive (groups)
2143 (let ((groups (sort groups 'string<))
2144 prefixes prefix start ans group starts)
2145 (while groups
2146 (setq prefixes (list "^"))
2147 (while (and groups prefixes)
2148 (while (not (string-match (car prefixes) (car groups)))
2149 (setq prefixes (cdr prefixes)))
2150 (setq prefix (car prefixes))
2151 (setq start (1- (length prefix)))
2152 (if (and (string-match "[^\\.]\\." (car groups) start)
2153 (cdr groups)
2154 (setq prefix
2155 (concat "^" (substring (car groups) 0 (match-end 0))))
2156 (string-match prefix (car (cdr groups))))
2157 (progn
2158 (setq prefixes (cons prefix prefixes))
2159 (message "Descend hierarchy %s? ([y]nsq): "
2160 (substring prefix 1 (1- (length prefix))))
2161 (setq ans (read-char))
2162 (cond ((= ans ?n)
2163 (while (and groups
2164 (string-match prefix
2165 (setq group (car groups))))
2166 (setq gnus-killed-list
2167 (cons group gnus-killed-list))
2168 (gnus-sethash group group gnus-killed-hashtb)
2169 (setq groups (cdr groups)))
2170 (setq starts (cdr starts)))
2171 ((= ans ?s)
2172 (while (and groups
2173 (string-match prefix
2174 (setq group (car groups))))
2175 (gnus-sethash group group gnus-killed-hashtb)
2176 (gnus-subscribe-alphabetically (car groups))
2177 (setq groups (cdr groups)))
2178 (setq starts (cdr starts)))
2179 ((= ans ?q)
2180 (while groups
2181 (setq group (car groups))
2182 (setq gnus-killed-list (cons group gnus-killed-list))
2183 (gnus-sethash group group gnus-killed-hashtb)
2184 (setq groups (cdr groups))))
2185 (t nil)))
2186 (message "Subscribe %s? ([n]yq)" (car groups))
2187 (setq ans (read-char))
2188 (setq group (car groups))
2189 (cond ((= ans ?y)
2190 (gnus-subscribe-alphabetically (car groups))
2191 (gnus-sethash group group gnus-killed-hashtb))
2192 ((= ans ?q)
2193 (while groups
2194 (setq group (car groups))
2195 (setq gnus-killed-list (cons group gnus-killed-list))
2196 (gnus-sethash group group gnus-killed-hashtb)
2197 (setq groups (cdr groups))))
2198 (t
2199 (setq gnus-killed-list (cons group gnus-killed-list))
2200 (gnus-sethash group group gnus-killed-hashtb)))
2201 (setq groups (cdr groups)))))))
2202
2203 (defun gnus-subscribe-randomly (newsgroup)
2204 "Subscribe new NEWSGROUP by making it the first newsgroup."
2205 (gnus-subscribe-newsgroup newsgroup))
2206
2207 (defun gnus-subscribe-alphabetically (newgroup)
2208 "Subscribe new NEWSGROUP and insert it in alphabetical order."
2209 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2210 (let ((groups (cdr gnus-newsrc-alist))
2211 before)
2212 (while (and (not before) groups)
2213 (if (string< newgroup (car (car groups)))
2214 (setq before (car (car groups)))
2215 (setq groups (cdr groups))))
2216 (gnus-subscribe-newsgroup newgroup before)))
2217
2218 (defun gnus-subscribe-hierarchically (newgroup)
2219 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
2220 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2221 (save-excursion
2222 (set-buffer (find-file-noselect gnus-current-startup-file))
2223 (let ((groupkey newgroup)
2224 before)
2225 (while (and (not before) groupkey)
2226 (goto-char (point-min))
2227 (let ((groupkey-re
2228 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
2229 (while (and (re-search-forward groupkey-re nil t)
2230 (progn
2231 (setq before (buffer-substring
2232 (match-beginning 1) (match-end 1)))
2233 (string< before newgroup)))))
2234 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
2235 (setq groupkey
2236 (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
2237 (substring groupkey (match-beginning 1) (match-end 1)))))
2238 (gnus-subscribe-newsgroup newgroup before))))
2239
2240 (defun gnus-subscribe-interactively (newsgroup)
2241 "Subscribe new NEWSGROUP interactively.
2242 It is inserted in hierarchical newsgroup order if subscribed. If not,
2243 it is killed."
2244 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
2245 (gnus-subscribe-hierarchically newsgroup)
2246 (setq gnus-killed-list (cons newsgroup gnus-killed-list))))
2247
2248 (defun gnus-subscribe-zombies (newsgroup)
2249 "Make new NEWSGROUP a zombie group."
2250 (setq gnus-zombie-list (cons newsgroup gnus-zombie-list)))
2251
2252 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
2253 "Subscribe new NEWSGROUP.
2254 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
2255 the first newsgroup."
2256 ;; We subscribe the group by changing its level to `subscribed'.
2257 (gnus-group-change-level
2258 newsgroup gnus-level-default-subscribed
2259 gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
2260 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
2261
2262 ;; For directories
2263
2264 (defun gnus-newsgroup-directory-form (newsgroup)
2265 "Make hierarchical directory name from NEWSGROUP name."
2266 (let ((newsgroup (gnus-newsgroup-savable-name newsgroup))
2267 (len (length newsgroup))
2268 idx)
2269 ;; If this is a foreign group, we don't want to translate the
2270 ;; entire name.
2271 (if (setq idx (string-match ":" newsgroup))
2272 (aset newsgroup idx ?/)
2273 (setq idx 0))
2274 ;; Replace all occurrences of `.' with `/'.
2275 (while (< idx len)
2276 (if (= (aref newsgroup idx) ?.)
2277 (aset newsgroup idx ?/))
2278 (setq idx (1+ idx)))
2279 newsgroup))
2280
2281 (defun gnus-newsgroup-savable-name (group)
2282 ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
2283 ;; with dots.
2284 (gnus-replace-chars-in-string group ?/ ?.))
2285
2286 (defun gnus-make-directory (dir)
2287 "Make DIRECTORY recursively."
2288 ;; Why don't we use `(make-directory dir 'parents)'? That's just one
2289 ;; of the many mysteries of the universe.
2290 (let* ((dir (expand-file-name dir default-directory))
2291 dirs err)
2292 (if (string-match "/$" dir)
2293 (setq dir (substring dir 0 (match-beginning 0))))
2294 ;; First go down the path until we find a directory that exists.
2295 (while (not (file-exists-p dir))
2296 (setq dirs (cons dir dirs))
2297 (string-match "/[^/]+$" dir)
2298 (setq dir (substring dir 0 (match-beginning 0))))
2299 ;; Then create all the subdirs.
2300 (while (and dirs (not err))
2301 (condition-case ()
2302 (make-directory (car dirs))
2303 (error (setq err t)))
2304 (setq dirs (cdr dirs)))
2305 ;; We return whether we were successful or not.
2306 (not dirs)))
2307
2308 (defun gnus-capitalize-newsgroup (newsgroup)
2309 "Capitalize NEWSGROUP name."
2310 (and (not (zerop (length newsgroup)))
2311 (concat (char-to-string (upcase (aref newsgroup 0)))
2312 (substring newsgroup 1))))
2313
2314 ;; Var
2315
2316 (defun gnus-simplify-subject (subject &optional re-only)
2317 "Remove `Re:' and words in parentheses.
2318 If optional argument RE-ONLY is non-nil, strip `Re:' only."
2319 (let ((case-fold-search t)) ;Ignore case.
2320 ;; Remove `Re:' and `Re^N:'.
2321 (if (string-match "^re:[ \t]*" subject)
2322 (setq subject (substring subject (match-end 0))))
2323 ;; Remove words in parentheses from end.
2324 (or re-only
2325 (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
2326 (setq subject (substring subject 0 (match-beginning 0)))))
2327 ;; Return subject string.
2328 subject))
2329
2330 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
2331 ;; all whitespace.
2332 (defun gnus-simplify-subject-fuzzy (subject)
2333 (let ((case-fold-search t))
2334 (save-excursion
2335 (gnus-set-work-buffer)
2336 (insert subject)
2337 (inline (gnus-simplify-buffer-fuzzy))
2338 (buffer-string))))
2339
2340 (defun gnus-simplify-buffer-fuzzy ()
2341 (goto-char (point-min))
2342 ;; Fix by Stainless Steel Rat <ratinox@ccs.neu.edu>.
2343 (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*"
2344 nil t)
2345 (replace-match "" t t))
2346 (goto-char (point-min))
2347 (while (re-search-forward "[ \t\n]*([^()]*)[ \t\n]*$" nil t)
2348 (replace-match "" t t))
2349 (goto-char (point-min))
2350 (while (re-search-forward "[ \t]+" nil t)
2351 (replace-match " " t t))
2352 (goto-char (point-min))
2353 (while (re-search-forward "[ \t]+$" nil t)
2354 (replace-match "" t t))
2355 (goto-char (point-min))
2356 (while (re-search-forward "^[ \t]+" nil t)
2357 (replace-match "" t t))
2358 (if gnus-simplify-subject-fuzzy-regexp
2359 (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
2360 (replace-match "" t t))))
2361
2362 ;; Add the current buffer to the list of buffers to be killed on exit.
2363 (defun gnus-add-current-to-buffer-list ()
2364 (or (memq (current-buffer) gnus-buffer-list)
2365 (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
2366
2367 (defun gnus-string> (s1 s2)
2368 (not (or (string< s1 s2)
2369 (string= s1 s2))))
2370
2371 ;; Functions accessing headers.
2372 ;; Functions are more convenient than macros in some cases.
2373
2374 (defun gnus-header-number (header)
2375 (mail-header-number header))
2376
2377 (defun gnus-header-subject (header)
2378 (mail-header-subject header))
2379
2380 (defun gnus-header-from (header)
2381 (mail-header-from header))
2382
2383 (defun gnus-header-xref (header)
2384 (mail-header-xref header))
2385
2386 (defun gnus-header-lines (header)
2387 (mail-header-lines header))
2388
2389 (defun gnus-header-date (header)
2390 (mail-header-date header))
2391
2392 (defun gnus-header-id (header)
2393 (mail-header-id header))
2394
2395 (defun gnus-header-message-id (header)
2396 (mail-header-id header))
2397
2398 (defun gnus-header-chars (header)
2399 (mail-header-chars header))
2400
2401 (defun gnus-header-references (header)
2402 (mail-header-references header))
2403
2404 ;;; General various misc type functions.
2405
2406 (defun gnus-clear-system ()
2407 "Clear all variables and buffers."
2408 ;; Clear Gnus variables.
2409 (let ((variables gnus-variable-list))
2410 (while variables
2411 (set (car variables) nil)
2412 (setq variables (cdr variables))))
2413 ;; Clear other internal variables.
2414 (setq gnus-list-of-killed-groups nil
2415 gnus-have-read-active-file nil
2416 gnus-newsrc-alist nil
2417 gnus-newsrc-hashtb nil
2418 gnus-killed-list nil
2419 gnus-zombie-list nil
2420 gnus-killed-hashtb nil
2421 gnus-active-hashtb nil
2422 gnus-moderated-list nil
2423 gnus-description-hashtb nil
2424 gnus-newsgroup-headers nil
2425 gnus-newsgroup-headers-hashtb-by-number nil
2426 gnus-newsgroup-name nil
2427 gnus-server-alist nil
2428 gnus-current-select-method nil)
2429 ;; Reset any score variables.
2430 (and (boundp 'gnus-score-cache)
2431 (set 'gnus-score-cache nil))
2432 (and (boundp 'gnus-internal-global-score-files)
2433 (set 'gnus-internal-global-score-files nil))
2434 ;; Kill the startup file.
2435 (and gnus-current-startup-file
2436 (get-file-buffer gnus-current-startup-file)
2437 (kill-buffer (get-file-buffer gnus-current-startup-file)))
2438 ;; Save any cache buffers.
2439 (and gnus-use-cache (gnus-cache-save-buffers))
2440 ;; Clear the dribble buffer.
2441 (gnus-dribble-clear)
2442 ;; Kill global KILL file buffer.
2443 (if (get-file-buffer (gnus-newsgroup-kill-file nil))
2444 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
2445 (gnus-kill-buffer nntp-server-buffer)
2446 ;; Kill Gnus buffers.
2447 (while gnus-buffer-list
2448 (gnus-kill-buffer (car gnus-buffer-list))
2449 (setq gnus-buffer-list (cdr gnus-buffer-list))))
2450
2451 (defun gnus-windows-old-to-new (setting)
2452 ;; First we take care of the really, really old Gnus 3 actions.
2453 (if (symbolp setting)
2454 (setq setting
2455 (cond ((memq setting '(SelectArticle))
2456 'article)
2457 ((memq setting '(SelectSubject ExpandSubject))
2458 'summary)
2459 ((memq setting '(SelectNewsgroup ExitNewsgroup))
2460 'group)
2461 (t setting))))
2462 (if (or (listp setting)
2463 (not (and gnus-window-configuration
2464 (memq setting '(group summary article)))))
2465 setting
2466 (let* ((setting (if (eq setting 'group)
2467 (if (assq 'newsgroup gnus-window-configuration)
2468 'newsgroup
2469 'newsgroups) setting))
2470 (elem (car (cdr (assq setting gnus-window-configuration))))
2471 (total (apply '+ elem))
2472 (types '(group summary article))
2473 (pbuf (if (eq setting 'newsgroups) 'group 'summary))
2474 (i 0)
2475 perc
2476 out)
2477 (while (< i 3)
2478 (or (not (numberp (nth i elem)))
2479 (zerop (nth i elem))
2480 (progn
2481 (setq perc (/ (* 1.0 (nth 0 elem)) total))
2482 (setq out (cons (if (eq pbuf (nth i types))
2483 (vector (nth i types) perc 'point)
2484 (vector (nth i types) perc))
2485 out))))
2486 (setq i (1+ i)))
2487 (list (nreverse out)))))
2488
2489 (defun gnus-add-configuration (conf)
2490 (setq gnus-buffer-configuration
2491 (cons conf (delq (assq (car conf) gnus-buffer-configuration)
2492 gnus-buffer-configuration))))
2493
2494 (defun gnus-configure-windows (setting &optional force)
2495 (setq setting (gnus-windows-old-to-new setting))
2496 (let ((r (if (symbolp setting)
2497 (cdr (assq setting gnus-buffer-configuration))
2498 setting))
2499 (in-buf (current-buffer))
2500 rule val w height hor ohor heights sub jump-buffer
2501 rel total to-buf all-visible)
2502 (or r (error "No such setting: %s" setting))
2503
2504 (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r)))
2505 ;; All the windows mentioned are already visible, so we just
2506 ;; put point in the assigned buffer, and do not touch the
2507 ;; winconf.
2508 (select-window (get-buffer-window all-visible t))
2509
2510
2511 ;; Either remove all windows or just remove all Gnus windows.
2512 (if gnus-use-full-window
2513 (delete-other-windows)
2514 (gnus-remove-some-windows)
2515 (switch-to-buffer nntp-server-buffer))
2516
2517 (while r
2518 (setq hor (car r)
2519 ohor nil)
2520
2521 ;; We have to do the (possible) horizontal splitting before the
2522 ;; vertical.
2523 (if (and (listp (car hor))
2524 (eq (car (car hor)) 'horizontal))
2525 (progn
2526 (split-window
2527 nil
2528 (if (integerp (nth 1 (car hor)))
2529 (nth 1 (car hor))
2530 (- (frame-width) (floor (* (frame-width) (nth 1 (car hor))))))
2531 t)
2532 (setq hor (cdr hor))))
2533
2534 ;; Go through the rules and eval the elements that are to be
2535 ;; evalled.
2536 (while hor
2537 (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor))))
2538 (progn
2539 ;; Expand short buffer name.
2540 (setq w (aref val 0))
2541 (and (setq w (cdr (assq w gnus-window-to-buffer)))
2542 (progn
2543 (setq val (apply 'vector (mapcar 'identity val)))
2544 (aset val 0 w)))
2545 (setq ohor (cons val ohor))))
2546 (setq hor (cdr hor)))
2547 (setq rule (cons (nreverse ohor) rule))
2548 (setq r (cdr r)))
2549 (setq rule (nreverse rule))
2550
2551 ;; We tally the window sizes.
2552 (setq total (window-height))
2553 (while rule
2554 (setq hor (car rule))
2555 (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal))
2556 (setq hor (cdr hor)))
2557 (setq sub 0)
2558 (while hor
2559 (setq rel (aref (car hor) 1)
2560 heights (cons
2561 (cond ((and (floatp rel) (= 1.0 rel))
2562 'x)
2563 ((integerp rel)
2564 rel)
2565 (t
2566 (max (floor (* total rel)) 4)))
2567 heights)
2568 sub (+ sub (if (numberp (car heights)) (car heights) 0))
2569 hor (cdr hor)))
2570 (setq heights (nreverse heights)
2571 hor (car rule))
2572
2573 ;; We then go through these heights and create windows for them.
2574 (while heights
2575 (setq height (car heights)
2576 heights (cdr heights))
2577 (and (eq height 'x)
2578 (setq height (- total sub)))
2579 (and heights
2580 (split-window nil height))
2581 (setq to-buf (aref (car hor) 0))
2582 (switch-to-buffer
2583 (cond ((not to-buf)
2584 in-buf)
2585 ((symbolp to-buf)
2586 (symbol-value (aref (car hor) 0)))
2587 (t
2588 (aref (car hor) 0))))
2589 (and (> (length (car hor)) 2)
2590 (eq (aref (car hor) 2) 'point)
2591 (setq jump-buffer (current-buffer)))
2592 (other-window 1)
2593 (setq hor (cdr hor)))
2594
2595 (setq rule (cdr rule)))
2596
2597 ;; Finally, we pop to the buffer that's supposed to have point.
2598 (or jump-buffer (error "Missing `point' in spec for %s" setting))
2599
2600 (select-window (get-buffer-window jump-buffer t))
2601 (set-buffer jump-buffer))))
2602
2603 (defun gnus-all-windows-visible-p (rule)
2604 (let (invisible hor jump-buffer val buffer)
2605 ;; Go through the rules and eval the elements that are to be
2606 ;; evalled.
2607 (while (and rule (not invisible))
2608 (setq hor (car rule)
2609 rule (cdr rule))
2610 (while (and hor (not invisible))
2611 (if (setq val (if (vectorp (car hor))
2612 (car hor)
2613 (if (not (eq (car (car hor)) 'horizontal))
2614 (eval (car hor)))))
2615 (progn
2616 ;; Expand short buffer name.
2617 (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer))
2618 (aref val 0)))
2619 (setq buffer (if (symbolp buffer) (symbol-value buffer)
2620 buffer))
2621 (and (> (length val) 2) (eq 'point (aref val 2))
2622 (setq jump-buffer buffer))
2623 (setq invisible (not (and buffer (get-buffer-window buffer))))))
2624 (setq hor (cdr hor))))
2625 (and (not invisible) jump-buffer)))
2626
2627 (defun gnus-window-top-edge (&optional window)
2628 (nth 1 (window-edges window)))
2629
2630 (defun gnus-remove-some-windows ()
2631 (let ((buffers gnus-window-to-buffer)
2632 buf bufs lowest-buf lowest)
2633 (save-excursion
2634 ;; Remove windows on all known Gnus buffers.
2635 (while buffers
2636 (setq buf (cdr (car buffers)))
2637 (if (symbolp buf)
2638 (setq buf (and (boundp buf) (symbol-value buf))))
2639 (and buf
2640 (get-buffer-window buf)
2641 (progn
2642 (setq bufs (cons buf bufs))
2643 (pop-to-buffer buf)
2644 (if (or (not lowest)
2645 (< (gnus-window-top-edge) lowest))
2646 (progn
2647 (setq lowest (gnus-window-top-edge))
2648 (setq lowest-buf buf)))))
2649 (setq buffers (cdr buffers)))
2650 ;; Remove windows on *all* summary buffers.
2651 (let (wins)
2652 (walk-windows
2653 (lambda (win)
2654 (let ((buf (window-buffer win)))
2655 (if (string-match "^\\*Summary" (buffer-name buf))
2656 (progn
2657 (setq bufs (cons buf bufs))
2658 (pop-to-buffer buf)
2659 (if (or (not lowest)
2660 (< (gnus-window-top-edge) lowest))
2661 (progn
2662 (setq lowest-buf buf)
2663 (setq lowest (gnus-window-top-edge))))))))))
2664 (and lowest-buf
2665 (progn
2666 (pop-to-buffer lowest-buf)
2667 (switch-to-buffer nntp-server-buffer)))
2668 (while bufs
2669 (and (not (eq (car bufs) lowest-buf))
2670 (delete-windows-on (car bufs)))
2671 (setq bufs (cdr bufs))))))
2672
2673 (defun gnus-version ()
2674 "Version numbers of this version of Gnus."
2675 (interactive)
2676 (let ((methods gnus-valid-select-methods)
2677 (mess gnus-version)
2678 meth)
2679 ;; Go through all the legal select methods and add their version
2680 ;; numbers to the total version string. Only the backends that are
2681 ;; currently in use will have their message numbers taken into
2682 ;; consideration.
2683 (while methods
2684 (setq meth (intern (concat (car (car methods)) "-version")))
2685 (and (boundp meth)
2686 (stringp (symbol-value meth))
2687 (setq mess (concat mess "; " (symbol-value meth))))
2688 (setq methods (cdr methods)))
2689 (gnus-message 2 mess)))
2690
2691 (defun gnus-info-find-node ()
2692 "Find Info documentation of Gnus."
2693 (interactive)
2694 ;; Enlarge info window if needed.
2695 (let ((mode major-mode))
2696 (gnus-configure-windows 'info)
2697 (Info-goto-node (car (cdr (assq mode gnus-info-nodes))))))
2698
2699 (defun gnus-overload-functions (&optional overloads)
2700 "Overload functions specified by optional argument OVERLOADS.
2701 If nothing is specified, use the variable gnus-overload-functions."
2702 (let ((defs nil)
2703 (overloads (or overloads gnus-overload-functions)))
2704 (while overloads
2705 (setq defs (car overloads))
2706 (setq overloads (cdr overloads))
2707 ;; Load file before overloading function if necessary. Make
2708 ;; sure we cannot use `require' always.
2709 (and (not (fboundp (car defs)))
2710 (car (cdr (cdr defs)))
2711 (load (car (cdr (cdr defs))) nil 'nomessage))
2712 (fset (car defs) (car (cdr defs))))))
2713
2714 (defun gnus-replace-chars-in-string (string &rest pairs)
2715 "Replace characters in STRING from FROM to TO."
2716 (let ((string (substring string 0)) ;Copy string.
2717 (len (length string))
2718 (idx 0)
2719 sym to)
2720 (or (zerop (% (length pairs) 2))
2721 (error "Odd number of translation pairs"))
2722 (setplist 'sym pairs)
2723 ;; Replace all occurrences of FROM with TO.
2724 (while (< idx len)
2725 (if (setq to (get 'sym (aref string idx)))
2726 (aset string idx to))
2727 (setq idx (1+ idx)))
2728 string))
2729
2730 (defun gnus-days-between (date1 date2)
2731 ;; Return the number of days between date1 and date2.
2732 (- (gnus-day-number date1) (gnus-day-number date2)))
2733
2734 (defun gnus-day-number (date)
2735 (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
2736 (timezone-parse-date date))))
2737 (timezone-absolute-from-gregorian
2738 (nth 1 dat) (nth 2 dat) (car dat))))
2739
2740 ;; Returns a floating point number that says how many seconds have
2741 ;; lapsed between Jan 1 12:00:00 1970 and DATE.
2742 (defun gnus-seconds-since-epoch (date)
2743 (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2744 (timezone-parse-date date)))
2745 (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
2746 (timezone-parse-time
2747 (aref (timezone-parse-date date) 3))))
2748 (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2749 (timezone-parse-date "Jan 1 12:00:00 1970")))
2750 (tday (- (timezone-absolute-from-gregorian
2751 (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
2752 (timezone-absolute-from-gregorian
2753 (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
2754 (+ (nth 2 ttime)
2755 (* (nth 1 ttime) 60)
2756 (* 1.0 (nth 0 ttime) 60 60)
2757 (* 1.0 tday 60 60 24))))
2758
2759 (defun gnus-file-newer-than (file date)
2760 (let ((fdate (nth 5 (file-attributes file))))
2761 (or (> (car fdate) (car date))
2762 (and (= (car fdate) (car date))
2763 (> (nth 1 fdate) (nth 1 date))))))
2764
2765 (defun gnus-group-read-only-p (&optional group)
2766 "Check whether GROUP supports editing or not.
2767 If GROUP is nil, `gnus-newsgroup-name' will be checked instead. Note
2768 that that variable is buffer-local to the summary buffers."
2769 (let ((group (or group gnus-newsgroup-name)))
2770 (not (gnus-check-backend-function 'request-replace-article group))))
2771
2772 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
2773 ;; the echo area.
2774 (defun gnus-y-or-n-p (prompt)
2775 (prog1
2776 (y-or-n-p prompt)
2777 (message "")))
2778
2779 (defun gnus-yes-or-no-p (prompt)
2780 (prog1
2781 (yes-or-no-p prompt)
2782 (message "")))
2783
2784 ;; Check whether to use long file names.
2785 (defun gnus-use-long-file-name (symbol)
2786 ;; The variable has to be set...
2787 (and gnus-use-long-file-name
2788 ;; If it isn't a list, then we return t.
2789 (or (not (listp gnus-use-long-file-name))
2790 ;; If it is a list, and the list contains `symbol', we
2791 ;; return nil.
2792 (not (memq symbol gnus-use-long-file-name)))))
2793
2794 ;; I suspect there's a better way, but I haven't taken the time to do
2795 ;; it yet. -erik selberg@cs.washington.edu
2796 (defun gnus-dd-mmm (messy-date)
2797 "Return a string like DD-MMM from a big messy string"
2798 (let ((datevec (timezone-parse-date messy-date)))
2799 (format "%2s-%s"
2800 (or (aref datevec 2) "??")
2801 (capitalize
2802 (or (car
2803 (nth (1- (string-to-number (aref datevec 1)))
2804 timezone-months-assoc))
2805 "???")))))
2806
2807 ;; Make a hash table (default and minimum size is 255).
2808 ;; Optional argument HASHSIZE specifies the table size.
2809 (defun gnus-make-hashtable (&optional hashsize)
2810 (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
2811
2812 ;; Make a number that is suitable for hashing; bigger than MIN and one
2813 ;; less than 2^x.
2814 (defun gnus-create-hash-size (min)
2815 (let ((i 1))
2816 (while (< i min)
2817 (setq i (* 2 i)))
2818 (1- i)))
2819
2820 ;; Show message if message has a lower level than `gnus-verbose'.
2821 ;; Guide-line for numbers:
2822 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
2823 ;; for things that take a long time, 7 - not very important messages
2824 ;; on stuff, 9 - messages inside loops.
2825 (defun gnus-message (level &rest args)
2826 (if (<= level gnus-verbose)
2827 (apply 'message args)
2828 ;; We have to do this format thingy here even if the result isn't
2829 ;; shown - the return value has to be the same as the return value
2830 ;; from `message'.
2831 (apply 'format args)))
2832
2833 ;; Generate a unique new group name.
2834 (defun gnus-generate-new-group-name (leaf)
2835 (let ((name leaf)
2836 (num 0))
2837 (while (gnus-gethash name gnus-newsrc-hashtb)
2838 (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
2839 name))
2840
2841 (defun gnus-ephemeral-group-p (group)
2842 "Say whether GROUP is ephemeral or not."
2843 (assoc 'quit-config (gnus-find-method-for-group group)))
2844
2845 (defun gnus-group-quit-config (group)
2846 "Return the quit-config of GROUP."
2847 (nth 1 (assoc 'quit-config (gnus-find-method-for-group group))))
2848
2849 (defun gnus-simplify-mode-line ()
2850 "Make mode lines a bit simpler."
2851 (setq mode-line-modified "-- ")
2852 (if (listp mode-line-format)
2853 (progn
2854 (make-local-variable 'mode-line-format)
2855 (setq mode-line-format (copy-sequence mode-line-format))
2856 (and (equal (nth 3 mode-line-format) " ")
2857 (setcar (nthcdr 3 mode-line-format) "")))))
2858
2859 ;;; List and range functions
2860
2861 (defun gnus-last-element (list)
2862 "Return last element of LIST."
2863 (while (cdr list)
2864 (setq list (cdr list)))
2865 (car list))
2866
2867 (defun gnus-copy-sequence (list)
2868 "Do a complete, total copy of a list."
2869 (if (and (consp list) (not (consp (cdr list))))
2870 (cons (car list) (cdr list))
2871 (mapcar (lambda (elem) (if (consp elem)
2872 (if (consp (cdr elem))
2873 (gnus-copy-sequence elem)
2874 (cons (car elem) (cdr elem)))
2875 elem))
2876 list)))
2877
2878 (defun gnus-set-difference (list1 list2)
2879 "Return a list of elements of LIST1 that do not appear in LIST2."
2880 (let ((list1 (copy-sequence list1)))
2881 (while list2
2882 (setq list1 (delq (car list2) list1))
2883 (setq list2 (cdr list2)))
2884 list1))
2885
2886 (defun gnus-sorted-complement (list1 list2)
2887 "Return a list of elements of LIST1 that do not appear in LIST2.
2888 Both lists have to be sorted over <."
2889 (let (out)
2890 (if (or (null list1) (null list2))
2891 (or list1 list2)
2892 (while (and list1 list2)
2893 (cond ((= (car list1) (car list2))
2894 (setq list1 (cdr list1)
2895 list2 (cdr list2)))
2896 ((< (car list1) (car list2))
2897 (setq out (cons (car list1) out))
2898 (setq list1 (cdr list1)))
2899 (t
2900 (setq out (cons (car list2) out))
2901 (setq list2 (cdr list2)))))
2902 (nconc (nreverse out) (or list1 list2)))))
2903
2904 (defun gnus-intersection (list1 list2)
2905 (let ((result nil))
2906 (while list2
2907 (if (memq (car list2) list1)
2908 (setq result (cons (car list2) result)))
2909 (setq list2 (cdr list2)))
2910 result))
2911
2912 (defun gnus-sorted-intersection (list1 list2)
2913 ;; LIST1 and LIST2 have to be sorted over <.
2914 (let (out)
2915 (while (and list1 list2)
2916 (cond ((= (car list1) (car list2))
2917 (setq out (cons (car list1) out)
2918 list1 (cdr list1)
2919 list2 (cdr list2)))
2920 ((< (car list1) (car list2))
2921 (setq list1 (cdr list1)))
2922 (t
2923 (setq list2 (cdr list2)))))
2924 (nreverse out)))
2925
2926 (defun gnus-set-sorted-intersection (list1 list2)
2927 ;; LIST1 and LIST2 have to be sorted over <.
2928 ;; This function modifies LIST1.
2929 (let* ((top (cons nil list1))
2930 (prev top))
2931 (while (and list1 list2)
2932 (cond ((= (car list1) (car list2))
2933 (setq prev list1
2934 list1 (cdr list1)
2935 list2 (cdr list2)))
2936 ((< (car list1) (car list2))
2937 (setcdr prev (cdr list1))
2938 (setq list1 (cdr list1)))
2939 (t
2940 (setq list2 (cdr list2)))))
2941 (setcdr prev nil)
2942 (cdr top)))
2943
2944 (defun gnus-compress-sequence (numbers &optional always-list)
2945 "Convert list of numbers to a list of ranges or a single range.
2946 If ALWAYS-LIST is non-nil, this function will always release a list of
2947 ranges."
2948 (let* ((first (car numbers))
2949 (last (car numbers))
2950 result)
2951 (if (null numbers)
2952 nil
2953 (if (not (listp (cdr numbers)))
2954 numbers
2955 (while numbers
2956 (cond ((= last (car numbers)) nil) ;Omit duplicated number
2957 ((= (1+ last) (car numbers)) ;Still in sequence
2958 (setq last (car numbers)))
2959 (t ;End of one sequence
2960 (setq result
2961 (cons (if (= first last) first
2962 (cons first last)) result))
2963 (setq first (car numbers))
2964 (setq last (car numbers))))
2965 (setq numbers (cdr numbers)))
2966 (if (and (not always-list) (null result))
2967 (if (= first last) (list first) (cons first last))
2968 (nreverse (cons (if (= first last) first (cons first last))
2969 result)))))))
2970
2971 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
2972 (defun gnus-uncompress-range (ranges)
2973 "Expand a list of ranges into a list of numbers.
2974 RANGES is either a single range on the form `(num . num)' or a list of
2975 these ranges."
2976 (let (first last result)
2977 (cond
2978 ((null ranges)
2979 nil)
2980 ((not (listp (cdr ranges)))
2981 (setq first (car ranges))
2982 (setq last (cdr ranges))
2983 (while (<= first last)
2984 (setq result (cons first result))
2985 (setq first (1+ first)))
2986 (nreverse result))
2987 (t
2988 (while ranges
2989 (if (atom (car ranges))
2990 (if (numberp (car ranges))
2991 (setq result (cons (car ranges) result)))
2992 (setq first (car (car ranges)))
2993 (setq last (cdr (car ranges)))
2994 (while (<= first last)
2995 (setq result (cons first result))
2996 (setq first (1+ first))))
2997 (setq ranges (cdr ranges)))
2998 (nreverse result)))))
2999
3000 (defun gnus-add-to-range (ranges list)
3001 "Return a list of ranges that has all articles from both RANGES and LIST.
3002 Note: LIST has to be sorted over `<'."
3003 (if (not ranges)
3004 (gnus-compress-sequence list t)
3005 (setq list (copy-sequence list))
3006 (or (listp (cdr ranges))
3007 (setq ranges (list ranges)))
3008 (let ((out ranges)
3009 ilist lowest highest temp)
3010 (while (and ranges list)
3011 (setq ilist list)
3012 (setq lowest (or (and (atom (car ranges)) (car ranges))
3013 (car (car ranges))))
3014 (while (and list (cdr list) (< (car (cdr list)) lowest))
3015 (setq list (cdr list)))
3016 (if (< (car ilist) lowest)
3017 (progn
3018 (setq temp list)
3019 (setq list (cdr list))
3020 (setcdr temp nil)
3021 (setq out (nconc (gnus-compress-sequence ilist t) out))))
3022 (setq highest (or (and (atom (car ranges)) (car ranges))
3023 (cdr (car ranges))))
3024 (while (and list (<= (car list) highest))
3025 (setq list (cdr list)))
3026 (setq ranges (cdr ranges)))
3027 (if list
3028 (setq out (nconc (gnus-compress-sequence list t) out)))
3029 (setq out (sort out (lambda (r1 r2)
3030 (< (or (and (atom r1) r1) (car r1))
3031 (or (and (atom r2) r2) (car r2))))))
3032 (setq ranges out)
3033 (while ranges
3034 (if (atom (car ranges))
3035 (if (cdr ranges)
3036 (if (atom (car (cdr ranges)))
3037 (if (= (1+ (car ranges)) (car (cdr ranges)))
3038 (progn
3039 (setcar ranges (cons (car ranges)
3040 (car (cdr ranges))))
3041 (setcdr ranges (cdr (cdr ranges)))))
3042 (if (= (1+ (car ranges)) (car (car (cdr ranges))))
3043 (progn
3044 (setcar (car (cdr ranges)) (car ranges))
3045 (setcar ranges (car (cdr ranges)))
3046 (setcdr ranges (cdr (cdr ranges)))))))
3047 (if (cdr ranges)
3048 (if (atom (car (cdr ranges)))
3049 (if (= (1+ (cdr (car ranges))) (car (cdr ranges)))
3050 (progn
3051 (setcdr (car ranges) (car (cdr ranges)))
3052 (setcdr ranges (cdr (cdr ranges)))))
3053 (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges))))
3054 (progn
3055 (setcdr (car ranges) (cdr (car (cdr ranges))))
3056 (setcdr ranges (cdr (cdr ranges))))))))
3057 (setq ranges (cdr ranges)))
3058 out)))
3059
3060 (defun gnus-remove-from-range (ranges list)
3061 "Return a list of ranges that has all articles from LIST removed from RANGES.
3062 Note: LIST has to be sorted over `<'."
3063 ;; !!! This function shouldn't look like this, but I've got a headache.
3064 (gnus-compress-sequence
3065 (gnus-sorted-complement
3066 (gnus-uncompress-range ranges) list)))
3067
3068 (defun gnus-member-of-range (number ranges)
3069 (if (not (listp (cdr ranges)))
3070 (and (>= number (car ranges))
3071 (<= number (cdr ranges)))
3072 (let ((not-stop t))
3073 (while (and ranges
3074 (if (numberp (car ranges))
3075 (>= number (car ranges))
3076 (>= number (car (car ranges))))
3077 not-stop)
3078 (if (if (numberp (car ranges))
3079 (= number (car ranges))
3080 (and (>= number (car (car ranges)))
3081 (<= number (cdr (car ranges)))))
3082 (setq not-stop nil))
3083 (setq ranges (cdr ranges)))
3084 (not not-stop))))
3085
3086 \f
3087 ;;;
3088 ;;; Gnus group mode
3089 ;;;
3090
3091 (defvar gnus-group-mode-map nil)
3092 (defvar gnus-group-group-map nil)
3093 (defvar gnus-group-mark-map nil)
3094 (defvar gnus-group-list-map nil)
3095 (defvar gnus-group-help-map nil)
3096 (defvar gnus-group-sub-map nil)
3097 (put 'gnus-group-mode 'mode-class 'special)
3098
3099 (if gnus-group-mode-map
3100 nil
3101 (setq gnus-group-mode-map (make-keymap))
3102 (suppress-keymap gnus-group-mode-map)
3103 (define-key gnus-group-mode-map " " 'gnus-group-read-group)
3104 (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
3105 (define-key gnus-group-mode-map "\r" 'gnus-group-select-group)
3106 (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
3107 (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
3108 (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
3109 (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
3110 (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
3111 (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
3112 (define-key gnus-group-mode-map
3113 "\M-n" 'gnus-group-next-unread-group-same-level)
3114 (define-key gnus-group-mode-map
3115 "\M-p" 'gnus-group-prev-unread-group-same-level)
3116 (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group)
3117 (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group)
3118 (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
3119 (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
3120 (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current)
3121 (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all)
3122 (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
3123 (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
3124 (define-key gnus-group-mode-map "m" 'gnus-group-mail)
3125 (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
3126 (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group)
3127 (define-key gnus-group-mode-map "R" 'gnus-group-restart)
3128 (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file)
3129 (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server)
3130 (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
3131 (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups)
3132 (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group)
3133 (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups)
3134 (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos)
3135 (define-key gnus-group-mode-map "\C-c\M-\C-a" 'gnus-group-description-apropos)
3136 (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
3137 (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
3138 (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
3139 (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
3140 (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
3141 (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
3142 (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
3143 (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed)
3144 (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles)
3145 (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups)
3146 (define-key gnus-group-mode-map "V" 'gnus-version)
3147 (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc)
3148 (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
3149 (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble)
3150 (define-key gnus-group-mode-map "q" 'gnus-group-exit)
3151 (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
3152 (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
3153 (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)
3154 (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method)
3155 (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode)
3156 (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group)
3157 (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
3158 (define-key gnus-group-mode-map ">" 'end-of-buffer)
3159 (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug)
3160 (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups)
3161
3162 (define-key gnus-group-mode-map "#" 'gnus-group-mark-group)
3163 (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group)
3164 (define-prefix-command 'gnus-group-mark-map)
3165 (define-key gnus-group-mode-map "M" 'gnus-group-mark-map)
3166 (define-key gnus-group-mark-map "m" 'gnus-group-mark-group)
3167 (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group)
3168 (define-key gnus-group-mark-map "w" 'gnus-group-mark-region)
3169
3170 (define-prefix-command 'gnus-group-group-map)
3171 (define-key gnus-group-mode-map "G" 'gnus-group-group-map)
3172 (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group)
3173 (define-key gnus-group-group-map "h" 'gnus-group-make-help-group)
3174 (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group)
3175 (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group)
3176 (define-key gnus-group-group-map "m" 'gnus-group-make-group)
3177 (define-key gnus-group-group-map "E" 'gnus-group-edit-group)
3178 (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method)
3179 (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters)
3180 (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual)
3181 (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual)
3182 (define-key gnus-group-group-map "D" 'gnus-group-enter-directory)
3183 (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group)
3184 ;;(define-key gnus-group-group-map "sb" 'gnus-group-brew-soup)
3185 ;;(define-key gnus-group-group-map "sw" 'gnus-soup-save-areas)
3186 ;;(define-key gnus-group-group-map "ss" 'gnus-soup-send-replies)
3187 ;;(define-key gnus-group-group-map "sp" 'gnus-soup-pack-packet)
3188 ;;(define-key gnus-group-group-map "sr" 'nnsoup-pack-replies)
3189
3190 (define-prefix-command 'gnus-group-list-map)
3191 (define-key gnus-group-mode-map "A" 'gnus-group-list-map)
3192 (define-key gnus-group-list-map "k" 'gnus-group-list-killed)
3193 (define-key gnus-group-list-map "z" 'gnus-group-list-zombies)
3194 (define-key gnus-group-list-map "s" 'gnus-group-list-groups)
3195 (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups)
3196 (define-key gnus-group-list-map "a" 'gnus-group-apropos)
3197 (define-key gnus-group-list-map "d" 'gnus-group-description-apropos)
3198 (define-key gnus-group-list-map "m" 'gnus-group-list-matching)
3199 (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching)
3200
3201 (define-prefix-command 'gnus-group-help-map)
3202 (define-key gnus-group-mode-map "H" 'gnus-group-help-map)
3203 (define-key gnus-group-help-map "f" 'gnus-group-fetch-faq)
3204
3205 (define-prefix-command 'gnus-group-sub-map)
3206 (define-key gnus-group-mode-map "S" 'gnus-group-sub-map)
3207 (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level)
3208 (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group)
3209 (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group)
3210 (define-key gnus-group-sub-map "k" 'gnus-group-kill-group)
3211 (define-key gnus-group-sub-map "y" 'gnus-group-yank-group)
3212 (define-key gnus-group-sub-map "w" 'gnus-group-kill-region)
3213 (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies))
3214
3215 (defun gnus-group-mode ()
3216 "Major mode for reading news.
3217
3218 All normal editing commands are switched off.
3219 \\<gnus-group-mode-map>
3220 The group buffer lists (some of) the groups available. For instance,
3221 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
3222 lists all zombie groups.
3223
3224 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
3225 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
3226
3227 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
3228
3229 The following commands are available:
3230
3231 \\{gnus-group-mode-map}"
3232 (interactive)
3233 (if gnus-visual (gnus-group-make-menu-bar))
3234 (kill-all-local-variables)
3235 (gnus-simplify-mode-line)
3236 (setq major-mode 'gnus-group-mode)
3237 (setq mode-name "Group")
3238 (gnus-group-set-mode-line)
3239 (setq mode-line-process nil)
3240 (use-local-map gnus-group-mode-map)
3241 (buffer-disable-undo (current-buffer))
3242 (setq truncate-lines t)
3243 (setq buffer-read-only t)
3244 (run-hooks 'gnus-group-mode-hook))
3245
3246 (defun gnus-mouse-pick-group (e)
3247 (interactive "e")
3248 (mouse-set-point e)
3249 (gnus-group-read-group nil))
3250
3251 ;; Look at LEVEL and find out what the level is really supposed to be.
3252 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
3253 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
3254 (defun gnus-group-default-level (&optional level number-or-nil)
3255 (cond
3256 (gnus-group-use-permanent-levels
3257 (setq gnus-group-default-list-level
3258 (or level gnus-group-default-list-level))
3259 (or gnus-group-default-list-level gnus-level-subscribed))
3260 (number-or-nil
3261 level)
3262 (t
3263 (or level gnus-group-default-list-level gnus-level-subscribed))))
3264
3265
3266 (defvar gnus-tmp-prev-perm nil)
3267
3268 ;;;###autoload
3269 (defun gnus-no-server (&optional arg)
3270 "Read network news.
3271 If ARG is a positive number, Gnus will use that as the
3272 startup level. If ARG is nil, Gnus will be started at level 2.
3273 If ARG is non-nil and not a positive number, Gnus will
3274 prompt the user for the name of an NNTP server to use.
3275 As opposed to `gnus', this command will not connect to the local server."
3276 (interactive "P")
3277 (let ((perm
3278 (cons gnus-group-use-permanent-levels gnus-group-default-list-level)))
3279 (setq gnus-tmp-prev-perm nil)
3280 (setq gnus-group-use-permanent-levels t)
3281 (gnus (or arg (1- gnus-level-default-subscribed)) t)
3282 (setq gnus-tmp-prev-perm perm)))
3283
3284 ;;;###autoload
3285 (defun read-news (&optional arg dont-connect)
3286 "Read network news. This is an alias for the `gnus' command."
3287 (gnus arg dont-connect))
3288
3289 ;;;###autoload
3290 (defun gnus (&optional arg dont-connect)
3291 "Read network news.
3292 If ARG is non-nil and a positive number, Gnus will use that as the
3293 startup level. If ARG is non-nil and not a positive number, Gnus will
3294 prompt the user for the name of an NNTP server to use."
3295 (interactive "P")
3296 (if (get-buffer gnus-group-buffer)
3297 (progn
3298 (switch-to-buffer gnus-group-buffer)
3299 (gnus-group-get-new-news))
3300
3301 (gnus-clear-system)
3302
3303 (nnheader-init-server-buffer)
3304 ;; We do this if `gnus-no-server' has been run.
3305 (if gnus-tmp-prev-perm
3306 (setq gnus-group-use-permanent-levels (car gnus-tmp-prev-perm)
3307 gnus-group-default-list-level (cdr gnus-tmp-prev-perm)
3308 gnus-tmp-prev-perm nil))
3309 (gnus-read-init-file)
3310
3311 (gnus-group-setup-buffer)
3312 (let ((buffer-read-only nil))
3313 (erase-buffer)
3314 (if (not gnus-inhibit-startup-message)
3315 (progn
3316 (gnus-group-startup-message)
3317 (sit-for 0))))
3318
3319 (let ((level (and arg (numberp arg) (> arg 0) arg))
3320 did-connect)
3321 (unwind-protect
3322 (progn
3323 (or dont-connect
3324 (setq did-connect
3325 (gnus-start-news-server (and arg (not level))))))
3326 (if (and (not dont-connect)
3327 (not did-connect))
3328 (gnus-group-quit)
3329 (run-hooks 'gnus-startup-hook)
3330 ;; NNTP server is successfully open.
3331
3332 ;; Find the current startup file name.
3333 (setq gnus-current-startup-file
3334 (gnus-make-newsrc-file gnus-startup-file))
3335
3336 ;; Read the dribble file.
3337 (and gnus-use-dribble-file (gnus-dribble-read-file))
3338
3339 (gnus-summary-make-display-table)
3340 (gnus-setup-news nil level)
3341 (gnus-group-list-groups level)
3342 (gnus-configure-windows 'group))))))
3343
3344 (defun gnus-unload ()
3345 "Unload all Gnus features."
3346 (interactive)
3347 (or (boundp 'load-history)
3348 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
3349 (let ((history load-history)
3350 feature)
3351 (while history
3352 (and (string-match "^gnus" (car (car history)))
3353 (setq feature (cdr (assq 'provide (car history))))
3354 (unload-feature feature 'force))
3355 (setq history (cdr history)))))
3356
3357 (defun gnus-group-startup-message (&optional x y)
3358 "Insert startup message in current buffer."
3359 ;; Insert the message.
3360 (erase-buffer)
3361 (insert
3362 (format "
3363 _ ___ _ _
3364 _ ___ __ ___ __ _ ___
3365 __ _ ___ __ ___
3366 _ ___ _
3367 _ _ __ _
3368 ___ __ _
3369 __ _
3370 _ _ _
3371 _ _ _
3372 _ _ _
3373 __ ___
3374 _ _ _ _
3375 _ _
3376 _ _
3377 _ _
3378 _
3379 __
3380
3381
3382 Gnus * A newsreader for Emacsen
3383 A Praxis release * larsi@ifi.uio.no
3384 "
3385 gnus-version))
3386 ;; And then hack it.
3387 ;; 18 is the longest line.
3388 (indent-rigidly (point-min) (point-max)
3389 (/ (max (- (window-width) (or x 46)) 0) 2))
3390 (goto-char (point-min))
3391 (let* ((pheight (count-lines (point-min) (point-max)))
3392 (wheight (window-height))
3393 (rest (- wheight pheight)))
3394 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
3395
3396
3397
3398 ;; Fontify some.
3399 (goto-char (point-min))
3400 (search-forward "Praxis")
3401 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3402 (goto-char (point-min)))
3403
3404 (defun gnus-group-startup-message-old (&optional x y)
3405 "Insert startup message in current buffer."
3406 ;; Insert the message.
3407 (erase-buffer)
3408 (insert
3409 (format "
3410 %s
3411 A newsreader
3412 for GNU Emacs
3413
3414 Based on GNUS
3415 written by
3416 Masanobu UMEDA
3417
3418 A Praxis Release
3419 larsi@ifi.uio.no
3420 "
3421 gnus-version))
3422 ;; And then hack it.
3423 ;; 18 is the longest line.
3424 (indent-rigidly (point-min) (point-max)
3425 (/ (max (- (window-width) (or x 28)) 0) 2))
3426 (goto-char (point-min))
3427 ;; +4 is fuzzy factor.
3428 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))
3429
3430 ;; Fontify some.
3431 (goto-char (point-min))
3432 (search-forward "Praxis")
3433 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3434 (goto-char (point-min)))
3435
3436 (defun gnus-group-setup-buffer ()
3437 (or (get-buffer gnus-group-buffer)
3438 (progn
3439 (switch-to-buffer gnus-group-buffer)
3440 (gnus-add-current-to-buffer-list)
3441 (gnus-group-mode)
3442 (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
3443
3444 (defun gnus-group-list-groups (&optional level unread)
3445 "List newsgroups with level LEVEL or lower that have unread articles.
3446 Default is all subscribed groups.
3447 If argument UNREAD is non-nil, groups with no unread articles are also
3448 listed."
3449 (interactive (list (if current-prefix-arg
3450 (prefix-numeric-value current-prefix-arg)
3451 (or
3452 (gnus-group-default-level nil t)
3453 gnus-group-default-list-level
3454 gnus-level-subscribed))))
3455 (or level
3456 (setq level (car gnus-group-list-mode)
3457 unread (cdr gnus-group-list-mode)))
3458 (setq level (gnus-group-default-level level))
3459 (gnus-group-setup-buffer) ;May call from out of group buffer
3460 (let ((case-fold-search nil)
3461 (group (gnus-group-group-name)))
3462 (funcall gnus-group-prepare-function level unread nil)
3463 (if (zerop (buffer-size))
3464 (gnus-message 5 gnus-no-groups-message)
3465 (goto-char (point-min))
3466 (if (not group)
3467 ;; Go to the first group with unread articles.
3468 (gnus-group-search-forward nil nil nil t)
3469 ;; Find the right group to put point on. If the current group
3470 ;; has disappeared in the new listing, try to find the next
3471 ;; one. If no next one can be found, just leave point at the
3472 ;; first newsgroup in the buffer.
3473 (if (not (gnus-goto-char
3474 (text-property-any (point-min) (point-max)
3475 'gnus-group (intern group))))
3476 (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb))))
3477 (while (and newsrc
3478 (not (gnus-goto-char
3479 (text-property-any
3480 (point-min) (point-max) 'gnus-group
3481 (intern (car (car newsrc)))))))
3482 (setq newsrc (cdr newsrc)))
3483 (or newsrc (progn (goto-char (point-max))
3484 (forward-line -1))))))
3485 ;; Adjust cursor point.
3486 (gnus-group-position-cursor))))
3487
3488 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
3489 "List all newsgroups with unread articles of level LEVEL or lower.
3490 If ALL is non-nil, list groups that have no unread articles.
3491 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3492 If REGEXP, only list groups matching REGEXP."
3493 (set-buffer gnus-group-buffer)
3494 (let ((buffer-read-only nil)
3495 (newsrc (cdr gnus-newsrc-alist))
3496 (lowest (or lowest 1))
3497 info clevel unread group)
3498 (erase-buffer)
3499 (if (< lowest gnus-level-zombie)
3500 ;; List living groups.
3501 (while newsrc
3502 (setq info (car newsrc)
3503 group (car info)
3504 newsrc (cdr newsrc)
3505 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3506 (and unread ; This group might be bogus
3507 (or (not regexp)
3508 (string-match regexp group))
3509 (<= (setq clevel (car (cdr info))) level)
3510 (>= clevel lowest)
3511 (or all ; We list all groups?
3512 (eq unread t) ; We list unactivated groups
3513 (> unread 0) ; We list groups with unread articles
3514 (cdr (assq 'tick (nth 3 info)))) ; And ticked groups
3515 (gnus-group-insert-group-line
3516 nil group (car (cdr info)) (nth 3 info) unread (nth 4 info)))))
3517
3518 ;; List dead groups.
3519 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
3520 (gnus-group-prepare-flat-list-dead
3521 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
3522 gnus-level-zombie ?Z
3523 regexp))
3524 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
3525 (gnus-group-prepare-flat-list-dead
3526 (setq gnus-killed-list (sort gnus-killed-list 'string<))
3527 gnus-level-killed ?K regexp))
3528
3529 (gnus-group-set-mode-line)
3530 (setq gnus-group-list-mode (cons level all))
3531 (run-hooks 'gnus-group-prepare-hook)))
3532
3533 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
3534 ;; List zombies and killed lists somewhat faster, which was
3535 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
3536 ;; this by ignoring the group format specification altogether.
3537 (let (group beg)
3538 (while groups
3539 (setq group (car groups)
3540 groups (cdr groups))
3541 (if (or (not regexp)
3542 (string-match regexp group))
3543 (progn
3544 (setq beg (point))
3545 (insert (format " %c *: %s\n" mark group))
3546 (add-text-properties
3547 beg (1+ beg)
3548 (list 'gnus-group (intern group)
3549 'gnus-unread t
3550 'gnus-level level)))))))
3551
3552 (defun gnus-group-real-name (group)
3553 "Find the real name of a foreign newsgroup."
3554 (if (string-match ":[^:]+$" group)
3555 (substring group (1+ (match-beginning 0)))
3556 group))
3557
3558 (defun gnus-group-prefixed-name (group method)
3559 "Return the whole name from GROUP and METHOD."
3560 (and (stringp method) (setq method (gnus-server-to-method method)))
3561 (concat (format "%s" (car method))
3562 (if (and
3563 (assoc (format "%s" (car method)) (gnus-methods-using 'address))
3564 (not (string= (nth 1 method) "")))
3565 (concat "+" (nth 1 method)))
3566 ":" group))
3567
3568 (defun gnus-group-real-prefix (group)
3569 "Return the prefix of the current group name."
3570 (if (string-match "^[^:]+:" group)
3571 (substring group 0 (match-end 0))
3572 ""))
3573
3574 (defun gnus-group-method-name (group)
3575 "Return the method used for selecting GROUP."
3576 (let ((prefix (gnus-group-real-prefix group)))
3577 (if (equal prefix "")
3578 gnus-select-method
3579 (if (string-match "^[^\\+]+\\+" prefix)
3580 (list (intern (substring prefix 0 (1- (match-end 0))))
3581 (substring prefix (match-end 0) (1- (length prefix))))
3582 (list (intern (substring prefix 0 (1- (length prefix)))) "")))))
3583
3584 (defun gnus-group-foreign-p (group)
3585 "Return nil if GROUP is native, non-nil if it is foreign."
3586 (string-match ":" group))
3587
3588 (defun gnus-group-set-info (info &optional method-only-group part)
3589 (let* ((entry (gnus-gethash
3590 (or method-only-group (car info)) gnus-newsrc-hashtb))
3591 (part-info info)
3592 (info (if method-only-group (nth 2 entry) info)))
3593 (if (not method-only-group)
3594 ()
3595 (or entry
3596 (error "Trying to change non-existent group %s" method-only-group))
3597 ;; We have received parts of the actual group info - either the
3598 ;; select method or the group parameters. We first check
3599 ;; whether we have to extend the info, and if so, do that.
3600 (let ((len (length info))
3601 (total (if (eq part 'method) 5 6)))
3602 (and (< len total)
3603 (setcdr (nthcdr (1- len) info)
3604 (make-list (- total len) nil)))
3605 ;; Then we enter the new info.
3606 (setcar (nthcdr (1- total) info) part-info)))
3607 ;; We uncompress some lists of marked articles.
3608 (let (marked)
3609 (if (not (setq marked (nth 3 info)))
3610 ()
3611 (while marked
3612 (or (eq 'score (car (car marked)))
3613 (eq 'bookmark (car (car marked)))
3614 (eq 'killed (car (car marked)))
3615 (setcdr (car marked)
3616 (gnus-uncompress-range (cdr (car marked)))))
3617 (setq marked (cdr marked)))))
3618 (if entry
3619 ()
3620 ;; This is a new group, so we just create it.
3621 (save-excursion
3622 (set-buffer gnus-group-buffer)
3623 (if (nth 4 info)
3624 ;; It's a foreign group...
3625 (gnus-group-make-group
3626 (gnus-group-real-name (car info))
3627 (prin1-to-string (car (nth 4 info)))
3628 (nth 1 (nth 4 info)))
3629 ;; It's a native group.
3630 (gnus-group-make-group (car info)))
3631 (gnus-message 6 "Note: New group created")
3632 (setq entry
3633 (gnus-gethash (gnus-group-prefixed-name
3634 (gnus-group-real-name (car info))
3635 (or (nth 4 info) gnus-select-method))
3636 gnus-newsrc-hashtb))))
3637 ;; Whether it was a new group or not, we now have the entry, so we
3638 ;; can do the update.
3639 (if entry
3640 (progn
3641 (setcar (nthcdr 2 entry) info)
3642 (if (and (not (eq (car entry) t))
3643 (gnus-gethash (car info) gnus-active-hashtb))
3644 (let ((marked (nth 3 info)))
3645 (setcar entry
3646 (max 0 (- (length (gnus-list-of-unread-articles
3647 (car info)))
3648 (length (cdr (assq 'tick marked)))
3649 (length (cdr (assq 'dormant marked)))))))))
3650 (error "No such group: %s" (car info)))))
3651
3652 (defun gnus-group-set-method-info (group select-method)
3653 (gnus-group-set-info select-method group 'method))
3654
3655 (defun gnus-group-set-params-info (group params)
3656 (gnus-group-set-info params group 'params))
3657
3658 (defun gnus-group-update-group-line ()
3659 "This function updates the current line in the newsgroup buffer and
3660 moves the point to the colon."
3661 (let* ((buffer-read-only nil)
3662 (group (gnus-group-group-name))
3663 (entry (and group (gnus-gethash group gnus-newsrc-hashtb))))
3664 (if (and entry (not (gnus-ephemeral-group-p group)))
3665 (gnus-dribble-enter
3666 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3667 ")")))
3668 (beginning-of-line)
3669 (delete-region (point) (progn (forward-line 1) (point)))
3670 (gnus-group-insert-group-line-info group)
3671 (forward-line -1)
3672 (gnus-group-position-cursor)))
3673
3674 (defun gnus-group-insert-group-line-info (group)
3675 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
3676 active info)
3677 (if entry
3678 (progn
3679 (setq info (nth 2 entry))
3680 (gnus-group-insert-group-line
3681 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
3682 (setq active (gnus-gethash group gnus-active-hashtb))
3683 (gnus-group-insert-group-line
3684 nil group
3685 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
3686 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))))
3687
3688 (defun gnus-group-insert-group-line (gformat group level marked number method)
3689 (let* ((gformat (or gformat gnus-group-line-format-spec))
3690 (active (gnus-gethash group gnus-active-hashtb))
3691 (number-total (if active (1+ (- (cdr active) (car active))) 0))
3692 (number-of-dormant (length (cdr (assq 'dormant marked))))
3693 (number-of-ticked (length (cdr (assq 'tick marked))))
3694 (number-of-ticked-and-dormant
3695 (+ number-of-ticked number-of-dormant))
3696 (number-of-unread-unticked
3697 (if (numberp number) (int-to-string (max 0 number))
3698 "*"))
3699 (number-of-read
3700 (if (numberp number)
3701 (max 0 (- number-total number))
3702 "*"))
3703 (subscribed (cond ((<= level gnus-level-subscribed) ? )
3704 ((<= level gnus-level-unsubscribed) ?U)
3705 ((= level gnus-level-zombie) ?Z)
3706 (t ?K)))
3707 (qualified-group (gnus-group-real-name group))
3708 (newsgroup-description
3709 (if gnus-description-hashtb
3710 (or (gnus-gethash group gnus-description-hashtb) "")
3711 ""))
3712 (moderated (if (member group gnus-moderated-list) ?m ? ))
3713 (moderated-string (if (eq moderated ?m) "(m)" ""))
3714 (method (gnus-server-get-method group method))
3715 (news-server (or (car (cdr method)) ""))
3716 (news-method (or (car method) ""))
3717 (news-method-string
3718 (if method (format "(%s:%s)" (car method) (car (cdr method))) ""))
3719 (marked (if (and
3720 (numberp number)
3721 (zerop number)
3722 (> number-of-ticked 0))
3723 ?* ? ))
3724 (number (if (eq number t) "*" (+ number number-of-dormant
3725 number-of-ticked)))
3726 (process-marked (if (member group gnus-group-marked)
3727 gnus-process-mark ? ))
3728 (buffer-read-only nil)
3729 header ; passed as parameter to user-funcs.
3730 b)
3731 (beginning-of-line)
3732 (setq b (point))
3733 ;; Insert the text.
3734 (insert (eval gformat))
3735
3736 (add-text-properties
3737 b (1+ b) (list 'gnus-group (intern group)
3738 'gnus-unread (if (numberp number)
3739 (string-to-int number-of-unread-unticked)
3740 t)
3741 'gnus-marked marked
3742 'gnus-level level))))
3743
3744 (defun gnus-group-update-group (group &optional visible-only)
3745 "Update newsgroup info of GROUP.
3746 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already."
3747 (save-excursion
3748 (set-buffer gnus-group-buffer)
3749 (let ((buffer-read-only nil)
3750 visible)
3751 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
3752 (if (and entry
3753 (not (gnus-ephemeral-group-p group)))
3754 (gnus-dribble-enter
3755 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3756 ")"))))
3757 ;; Buffer may be narrowed.
3758 (save-restriction
3759 (widen)
3760 ;; Search a line to modify. If the buffer is large, the search
3761 ;; takes long time. In most cases, current point is on the line
3762 ;; we are looking for. So, first of all, check current line.
3763 (if (or (progn
3764 (beginning-of-line)
3765 (eq (get-text-property (point) 'gnus-group)
3766 (intern group)))
3767 (progn
3768 (gnus-goto-char
3769 (text-property-any
3770 (point-min) (point-max) 'gnus-group (intern group)))))
3771 ;; GROUP is listed in current buffer. So, delete old line.
3772 (progn
3773 (setq visible t)
3774 (beginning-of-line)
3775 (delete-region (point) (progn (forward-line 1) (point))))
3776 ;; No such line in the buffer, find out where it's supposed to
3777 ;; go, and insert it there (or at the end of the buffer).
3778 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
3779 (or visible-only
3780 (let ((entry
3781 (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb)))))
3782 (while (and entry
3783 (car entry)
3784 (not
3785 (gnus-goto-char
3786 (text-property-any
3787 (point-min) (point-max)
3788 'gnus-group (intern (car (car entry)))))))
3789 (setq entry (cdr entry)))
3790 (or entry (goto-char (point-max)))))))
3791 (if (or visible (not visible-only))
3792 (gnus-group-insert-group-line-info group))
3793 (gnus-group-set-mode-line))))
3794
3795 (defun gnus-group-set-mode-line ()
3796 (if (memq 'group gnus-updated-mode-lines)
3797 (let* ((gformat (or gnus-group-mode-line-format-spec
3798 (setq gnus-group-mode-line-format-spec
3799 (gnus-parse-format
3800 gnus-group-mode-line-format
3801 gnus-group-mode-line-format-alist))))
3802 (news-server (car (cdr gnus-select-method)))
3803 (news-method (car gnus-select-method))
3804 (max-len 60)
3805 header ;Dummy binding for user-defined specs.
3806 (mode-string (eval gformat)))
3807 (setq mode-string (eval gformat))
3808 (if (> (length mode-string) max-len)
3809 (setq mode-string (substring mode-string 0 (- max-len 4))))
3810 (setq mode-line-buffer-identification mode-string)
3811 (set-buffer-modified-p t))))
3812
3813 (defun gnus-group-group-name ()
3814 "Get the name of the newsgroup on the current line."
3815 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
3816 (and group (symbol-name group))))
3817
3818 (defun gnus-group-group-level ()
3819 "Get the level of the newsgroup on the current line."
3820 (get-text-property (gnus-point-at-bol) 'gnus-level))
3821
3822 (defun gnus-group-group-unread ()
3823 "Get the number of unread articles of the newsgroup on the current line."
3824 (get-text-property (gnus-point-at-bol) 'gnus-unread))
3825
3826 (defun gnus-group-search-forward (&optional backward all level first-too)
3827 "Find the next newsgroup with unread articles.
3828 If BACKWARD is non-nil, find the previous newsgroup instead.
3829 If ALL is non-nil, just find any newsgroup.
3830 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
3831 group exists.
3832 If FIRST-TOO, the current line is also eligible as a target."
3833 (let ((way (if backward -1 1))
3834 (low gnus-level-killed)
3835 (beg (point))
3836 pos found lev)
3837 (if (and backward (progn (beginning-of-line)) (bobp))
3838 nil
3839 (or first-too (forward-line way))
3840 (while (and
3841 (not (eobp))
3842 (not (setq
3843 found
3844 (and (or all
3845 (and
3846 (let ((unread
3847 (get-text-property (point) 'gnus-unread)))
3848 (or (eq unread t) (and unread (> unread 0))))
3849 (setq lev (get-text-property (point)
3850 'gnus-level))
3851 (<= lev gnus-level-subscribed)))
3852 (or (not level)
3853 (and (setq lev (get-text-property (point)
3854 'gnus-level))
3855 (or (= lev level)
3856 (and (< lev low)
3857 (< level lev)
3858 (progn
3859 (setq low lev)
3860 (setq pos (point))
3861 nil))))))))
3862 (zerop (forward-line way)))))
3863 (if found
3864 (progn (gnus-group-position-cursor) t)
3865 (goto-char (or pos beg))
3866 (and pos t))))
3867
3868 ;;; Gnus group mode commands
3869
3870 ;; Group marking.
3871
3872 (defun gnus-group-mark-group (n &optional unmark no-advance)
3873 "Mark the current group."
3874 (interactive "p")
3875 (let ((buffer-read-only nil)
3876 group)
3877 (while
3878 (and (> n 0)
3879 (setq group (gnus-group-group-name))
3880 (progn
3881 (beginning-of-line)
3882 (forward-char
3883 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
3884 (delete-char 1)
3885 (if unmark
3886 (progn
3887 (insert " ")
3888 (setq gnus-group-marked (delete group gnus-group-marked)))
3889 (insert "#")
3890 (setq gnus-group-marked
3891 (cons group (delete group gnus-group-marked))))
3892 t)
3893 (or no-advance (zerop (gnus-group-next-group 1))))
3894 (setq n (1- n)))
3895 (gnus-summary-position-cursor)
3896 n))
3897
3898 (defun gnus-group-unmark-group (n)
3899 "Remove the mark from the current group."
3900 (interactive "p")
3901 (gnus-group-mark-group n 'unmark))
3902
3903 (defun gnus-group-mark-region (unmark beg end)
3904 "Mark all groups between point and mark.
3905 If UNMARK, remove the mark instead."
3906 (interactive "P\nr")
3907 (let ((num (count-lines beg end)))
3908 (save-excursion
3909 (goto-char beg)
3910 (- num (gnus-group-mark-group num unmark)))))
3911
3912 (defun gnus-group-remove-mark (group)
3913 (and (gnus-group-goto-group group)
3914 (save-excursion
3915 (gnus-group-mark-group 1 'unmark t))))
3916
3917 ;; Return a list of groups to work on. Take into consideration N (the
3918 ;; prefix) and the list of marked groups.
3919 (defun gnus-group-process-prefix (n)
3920 (cond (n
3921 (setq n (prefix-numeric-value n))
3922 ;; There is a prefix, so we return a list of the N next
3923 ;; groups.
3924 (let ((way (if (< n 0) -1 1))
3925 (n (abs n))
3926 group groups)
3927 (save-excursion
3928 (while (and (> n 0)
3929 (setq group (gnus-group-group-name)))
3930 (setq groups (cons group groups))
3931 (setq n (1- n))
3932 (forward-line way)))
3933 (nreverse groups)))
3934 (gnus-group-marked
3935 ;; No prefix, but a list of marked articles.
3936 (reverse gnus-group-marked))
3937 (t
3938 ;; Neither marked articles or a prefix, so we return the
3939 ;; current group.
3940 (let ((group (gnus-group-group-name)))
3941 (and group (list group))))))
3942
3943 ;; Selecting groups.
3944
3945 (defun gnus-group-read-group (&optional all no-article group)
3946 "Read news in this newsgroup.
3947 If the prefix argument ALL is non-nil, already read articles become
3948 readable. If the optional argument NO-ARTICLE is non-nil, no article
3949 will be auto-selected upon group entry."
3950 (interactive "P")
3951 (let ((group (or group (gnus-group-group-name)))
3952 number active marked entry)
3953 (or group (error "No group on current line"))
3954 (setq marked
3955 (nth 3 (nth 2 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))))
3956 ;; This group might be a dead group. In that case we have to get
3957 ;; the number of unread articles from `gnus-active-hashtb'.
3958 (if entry
3959 (setq number (car entry))
3960 (if (setq active (gnus-gethash group gnus-active-hashtb))
3961 (setq number (- (1+ (cdr active)) (car active)))))
3962 (gnus-summary-read-group
3963 group (or all (and (numberp number)
3964 (zerop (+ number (length (cdr (assq 'tick marked)))
3965 (length (cdr (assq 'dormant marked)))))))
3966 no-article)))
3967
3968 (defun gnus-group-select-group (&optional all)
3969 "Select this newsgroup.
3970 No article is selected automatically.
3971 If argument ALL is non-nil, already read articles become readable."
3972 (interactive "P")
3973 (gnus-group-read-group all t))
3974
3975 (defun gnus-group-select-group-all ()
3976 "Select the current group and display all articles in it."
3977 (interactive)
3978 (gnus-group-select-group 'all))
3979
3980 ;; Enter a group that is not in the group buffer. Non-nil is returned
3981 ;; if selection was successful.
3982 (defun gnus-group-read-ephemeral-group
3983 (group method &optional activate quit-config)
3984 (let ((group (if (gnus-group-foreign-p group) group
3985 (gnus-group-prefixed-name group method))))
3986 (gnus-sethash
3987 group
3988 (list t nil (list group gnus-level-default-subscribed nil nil
3989 (append method
3990 (list
3991 (list 'quit-config
3992 (if quit-config quit-config
3993 (cons (current-buffer) 'summary)))))))
3994 gnus-newsrc-hashtb)
3995 (set-buffer gnus-group-buffer)
3996 (or (gnus-check-server method)
3997 (error "Unable to contact server: %s" (gnus-status-message method)))
3998 (if activate (or (gnus-request-group group)
3999 (error "Couldn't request group")))
4000 (condition-case ()
4001 (gnus-group-read-group t t group)
4002 (error nil)
4003 (quit nil))
4004 (not (equal major-mode 'gnus-group-mode))))
4005
4006 (defun gnus-group-jump-to-group (group)
4007 "Jump to newsgroup GROUP."
4008 (interactive
4009 (list (completing-read
4010 "Group: " gnus-active-hashtb nil
4011 (memq gnus-select-method gnus-have-read-active-file))))
4012
4013 (if (equal group "")
4014 (error "Empty group name"))
4015
4016 (let ((b (text-property-any
4017 (point-min) (point-max) 'gnus-group (intern group))))
4018 (if b
4019 ;; Either go to the line in the group buffer...
4020 (goto-char b)
4021 ;; ... or insert the line.
4022 (or
4023 (gnus-gethash group gnus-active-hashtb)
4024 (gnus-activate-group group)
4025 (error "%s error: %s" group (gnus-status-message group)))
4026
4027 (gnus-group-update-group group)
4028 (goto-char (text-property-any
4029 (point-min) (point-max) 'gnus-group (intern group)))))
4030 ;; Adjust cursor point.
4031 (gnus-group-position-cursor))
4032
4033 (defun gnus-group-goto-group (group)
4034 "Goto to newsgroup GROUP."
4035 (let ((b (text-property-any (point-min) (point-max)
4036 'gnus-group (intern group))))
4037 (and b (goto-char b))))
4038
4039 (defun gnus-group-next-group (n)
4040 "Go to next N'th newsgroup.
4041 If N is negative, search backward instead.
4042 Returns the difference between N and the number of skips actually
4043 done."
4044 (interactive "p")
4045 (gnus-group-next-unread-group n t))
4046
4047 (defun gnus-group-next-unread-group (n &optional all level)
4048 "Go to next N'th unread newsgroup.
4049 If N is negative, search backward instead.
4050 If ALL is non-nil, choose any newsgroup, unread or not.
4051 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
4052 such group can be found, the next group with a level higher than
4053 LEVEL.
4054 Returns the difference between N and the number of skips actually
4055 made."
4056 (interactive "p")
4057 (let ((backward (< n 0))
4058 (n (abs n)))
4059 (while (and (> n 0)
4060 (gnus-group-search-forward
4061 backward (or (not gnus-group-goto-unread) all) level))
4062 (setq n (1- n)))
4063 (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
4064 (if level " on this level or higher" "")))
4065 n))
4066
4067 (defun gnus-group-prev-group (n)
4068 "Go to previous N'th newsgroup.
4069 Returns the difference between N and the number of skips actually
4070 done."
4071 (interactive "p")
4072 (gnus-group-next-unread-group (- n) t))
4073
4074 (defun gnus-group-prev-unread-group (n)
4075 "Go to previous N'th unread newsgroup.
4076 Returns the difference between N and the number of skips actually
4077 done."
4078 (interactive "p")
4079 (gnus-group-next-unread-group (- n)))
4080
4081 (defun gnus-group-next-unread-group-same-level (n)
4082 "Go to next N'th unread newsgroup on the same level.
4083 If N is negative, search backward instead.
4084 Returns the difference between N and the number of skips actually
4085 done."
4086 (interactive "p")
4087 (gnus-group-next-unread-group n t (gnus-group-group-level))
4088 (gnus-group-position-cursor))
4089
4090 (defun gnus-group-prev-unread-group-same-level (n)
4091 "Go to next N'th unread newsgroup on the same level.
4092 Returns the difference between N and the number of skips actually
4093 done."
4094 (interactive "p")
4095 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
4096 (gnus-group-position-cursor))
4097
4098 (defun gnus-group-best-unread-group (&optional exclude-group)
4099 "Go to the group with the highest level.
4100 If EXCLUDE-GROUP, do not go to that group."
4101 (interactive)
4102 (goto-char (point-min))
4103 (let ((best 100000)
4104 unread best-point)
4105 (while (setq unread (get-text-property (point) 'gnus-unread))
4106 (if (and (numberp unread) (> unread 0))
4107 (progn
4108 (if (and (< (get-text-property (point) 'gnus-level) best)
4109 (or (not exclude-group)
4110 (not (equal exclude-group (gnus-group-group-name)))))
4111 (progn
4112 (setq best (get-text-property (point) 'gnus-level))
4113 (setq best-point (point))))))
4114 (forward-line 1))
4115 (if best-point (goto-char best-point))
4116 (gnus-summary-position-cursor)
4117 (and best-point (gnus-group-group-name))))
4118
4119 (defun gnus-group-first-unread-group ()
4120 "Go to the first group with unread articles."
4121 (interactive)
4122 (prog1
4123 (let ((opoint (point))
4124 unread)
4125 (goto-char (point-min))
4126 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
4127 (not (zerop unread)) ; Has unread articles.
4128 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
4129 (point) ; Success.
4130 (goto-char opoint)
4131 nil)) ; Not success.
4132 (gnus-group-position-cursor)))
4133
4134 (defun gnus-group-enter-server-mode ()
4135 "Jump to the server buffer."
4136 (interactive)
4137 (gnus-server-setup-buffer)
4138 (gnus-configure-windows 'server)
4139 (gnus-server-prepare))
4140
4141 (defun gnus-group-make-group (name &optional method address)
4142 "Add a new newsgroup.
4143 The user will be prompted for a NAME, for a select METHOD, and an
4144 ADDRESS."
4145 (interactive
4146 (cons
4147 (read-string "Group name: ")
4148 (let ((method
4149 (completing-read
4150 "Method: " (append gnus-valid-select-methods gnus-server-alist)
4151 nil t)))
4152 (if (assoc method gnus-valid-select-methods)
4153 (list method
4154 (if (memq 'prompt-address
4155 (assoc method gnus-valid-select-methods))
4156 (read-string "Address: ")
4157 ""))
4158 (list method nil)))))
4159
4160 (let* ((meth (and method (if address (list (intern method) address) method)))
4161 (nname (if method (gnus-group-prefixed-name name meth) name))
4162 info)
4163 (and (gnus-gethash nname gnus-newsrc-hashtb)
4164 (error "Group %s already exists" nname))
4165 (gnus-group-change-level
4166 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
4167 gnus-level-default-subscribed gnus-level-killed
4168 (and (gnus-group-group-name)
4169 (gnus-gethash (gnus-group-group-name)
4170 gnus-newsrc-hashtb))
4171 t)
4172 (gnus-sethash nname (cons 1 0) gnus-active-hashtb)
4173 (or (gnus-ephemeral-group-p name)
4174 (gnus-dribble-enter
4175 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
4176 (gnus-group-insert-group-line-info nname)
4177
4178 (if (assoc method gnus-valid-select-methods)
4179 (require (intern method)))
4180 (and (gnus-check-backend-function 'request-create-group nname)
4181 (gnus-request-create-group nname))))
4182
4183 (defun gnus-group-edit-group (group &optional part)
4184 "Edit the group on the current line."
4185 (interactive (list (gnus-group-group-name)))
4186 (let ((done-func '(lambda ()
4187 "Exit editing mode and update the information."
4188 (interactive)
4189 (gnus-group-edit-group-done 'part 'group)))
4190 (part (or part 'info))
4191 (winconf (current-window-configuration))
4192 info)
4193 (or group (error "No group on current line"))
4194 (or (setq info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4195 (error "Killed group; can't be edited"))
4196 (set-buffer (get-buffer-create gnus-group-edit-buffer))
4197 (gnus-configure-windows 'edit-group)
4198 (gnus-add-current-to-buffer-list)
4199 (emacs-lisp-mode)
4200 ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4201 (use-local-map (copy-keymap emacs-lisp-mode-map))
4202 (local-set-key "\C-c\C-c" done-func)
4203 (make-local-variable 'gnus-prev-winconf)
4204 (setq gnus-prev-winconf winconf)
4205 ;; We modify the func to let it know what part it is editing.
4206 (setcar (cdr (nth 4 done-func)) (list 'quote part))
4207 (setcar (cdr (cdr (nth 4 done-func))) group)
4208 (erase-buffer)
4209 (insert
4210 (cond
4211 ((eq part 'method)
4212 ";; Type `C-c C-c' after editing the select method.\n\n")
4213 ((eq part 'params)
4214 ";; Type `C-c C-c' after editing the group parameters.\n\n")
4215 ((eq part 'info)
4216 ";; Type `C-c C-c' after editing the group info.\n\n")))
4217 (let ((cinfo (gnus-copy-sequence info))
4218 marked)
4219 (if (not (setq marked (nth 3 cinfo)))
4220 ()
4221 (while marked
4222 (or (eq 'score (car (car marked)))
4223 (eq 'bookmark (car (car marked)))
4224 (eq 'killed (car (car marked)))
4225 (not (numberp (car (cdr (car marked)))))
4226 (setcdr (car marked)
4227 (gnus-compress-sequence (sort (cdr (car marked)) '<) t)))
4228 (setq marked (cdr marked))))
4229 (insert
4230 (pp-to-string
4231 (cond ((eq part 'method)
4232 (or (nth 4 info) "native"))
4233 ((eq part 'params)
4234 (nth 5 info))
4235 (t
4236 cinfo)))
4237 "\n"))))
4238
4239 (defun gnus-group-edit-group-method (group)
4240 "Edit the select method of GROUP."
4241 (interactive (list (gnus-group-group-name)))
4242 (gnus-group-edit-group group 'method))
4243
4244 (defun gnus-group-edit-group-parameters (group)
4245 "Edit the group parameters of GROUP."
4246 (interactive (list (gnus-group-group-name)))
4247 (gnus-group-edit-group group 'params))
4248
4249 (defun gnus-group-edit-group-done (part group)
4250 "Get info from buffer, update variables and jump to the group buffer."
4251 (set-buffer (get-buffer-create gnus-group-edit-buffer))
4252 (goto-char (point-min))
4253 (let ((form (read (current-buffer)))
4254 (winconf gnus-prev-winconf))
4255 (if (eq part 'info)
4256 (gnus-group-set-info form)
4257 (gnus-group-set-info form group part))
4258 (kill-buffer (current-buffer))
4259 (and winconf (set-window-configuration winconf))
4260 (set-buffer gnus-group-buffer)
4261 (gnus-group-update-group (gnus-group-group-name))
4262 (gnus-group-position-cursor)))
4263
4264 (defun gnus-group-make-help-group ()
4265 "Create the Gnus documentation group."
4266 (interactive)
4267 (let ((path (if installation-directory
4268 (cons (concat installation-directory "etc/") load-path)
4269 (cons data-directory load-path)))
4270 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
4271 file)
4272 (and (gnus-gethash name gnus-newsrc-hashtb)
4273 (error "Documentation group already exists"))
4274 (while (and path
4275 (not (file-exists-p
4276 (setq file (concat (file-name-as-directory (car path))
4277 "gnus-tut.txt")))))
4278 (setq path (cdr path)))
4279 (if (not path)
4280 (message "Couldn't find doc group")
4281 (gnus-group-make-group
4282 (gnus-group-real-name name)
4283 (list 'nndoc name
4284 (list 'nndoc-address file)
4285 (list 'nndoc-article-type 'mbox)))))
4286 (gnus-group-position-cursor))
4287
4288 (defun gnus-group-make-doc-group (file type)
4289 "Create a group that uses a single file as the source."
4290 (interactive
4291 (list (read-file-name "File name: ")
4292 (let ((err "")
4293 found char)
4294 (while (not found)
4295 (message "%sFile type (mbox, babyl, digest) [mbd]: " err)
4296 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
4297 ((= char ?b) 'babyl)
4298 ((= char ?d) 'digest)
4299 (t (setq err (format "%c unknown. " char))
4300 nil))))
4301 found)))
4302 (let* ((file (expand-file-name file))
4303 (name (gnus-generate-new-group-name
4304 (gnus-group-prefixed-name
4305 (file-name-nondirectory file) '(nndoc "")))))
4306 (gnus-group-make-group
4307 (gnus-group-real-name name)
4308 (list 'nndoc name
4309 (list 'nndoc-address file)
4310 (list 'nndoc-article-type type)))))
4311
4312 (defun gnus-group-make-archive-group (&optional all)
4313 "Create the (ding) Gnus archive group of the most recent articles.
4314 Given a prefix, create a full group."
4315 (interactive "P")
4316 (let ((group (gnus-group-prefixed-name
4317 (if all "ding.archives" "ding.recent") '(nndir ""))))
4318 (and (gnus-gethash group gnus-newsrc-hashtb)
4319 (error "Archive group already exists"))
4320 (gnus-group-make-group
4321 (gnus-group-real-name group)
4322 "nndir"
4323 (if all gnus-group-archive-directory
4324 gnus-group-recent-archive-directory)))
4325 (gnus-group-position-cursor))
4326
4327 (defun gnus-group-make-directory-group (dir)
4328 "Create an nndir group.
4329 The user will be prompted for a directory. The contents of this
4330 directory will be used as a newsgroup. The directory should contain
4331 mail messages or news articles in files that have numeric names."
4332 (interactive
4333 (list (read-file-name "Create group from directory: ")))
4334 (or (file-exists-p dir) (error "No such directory"))
4335 (or (file-directory-p dir) (error "Not a directory"))
4336 (gnus-group-make-group dir "nndir" dir)
4337 (gnus-group-position-cursor))
4338
4339 (defun gnus-group-make-kiboze-group (group address scores)
4340 "Create an nnkiboze group.
4341 The user will be prompted for a name, a regexp to match groups, and
4342 score file entries for articles to include in the group."
4343 (interactive
4344 (list
4345 (read-string "nnkiboze group name: ")
4346 (read-string "Source groups (regexp): ")
4347 (let ((headers (mapcar (lambda (group) (list group))
4348 '("subject" "from" "number" "date" "message-id"
4349 "references" "chars" "lines" "xref")))
4350 scores header regexp regexps)
4351 (while (not (equal "" (setq header (completing-read
4352 "Match on header: " headers nil t))))
4353 (setq regexps nil)
4354 (while (not (equal "" (setq regexp (read-string
4355 (format "Match on %s (string): "
4356 header)))))
4357 (setq regexps (cons (list regexp nil nil 'r) regexps)))
4358 (setq scores (cons (cons header regexps) scores)))
4359 scores)))
4360 (gnus-group-make-group group "nnkiboze" address)
4361 (save-excursion
4362 (gnus-set-work-buffer)
4363 (let (emacs-lisp-mode-hook)
4364 (pp scores (current-buffer)))
4365 (write-region (point-min) (point-max)
4366 (concat (or gnus-kill-files-directory "~/News")
4367 "nnkiboze:" group "." gnus-score-file-suffix)))
4368 (gnus-group-position-cursor))
4369
4370 (defun gnus-group-add-to-virtual (n vgroup)
4371 "Add the current group to a virtual group."
4372 (interactive
4373 (list current-prefix-arg
4374 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
4375 "nnvirtual:")))
4376 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
4377 (error "%s is not an nnvirtual group" vgroup))
4378 (let* ((groups (gnus-group-process-prefix n))
4379 (method (nth 4 (nth 2 (gnus-gethash vgroup gnus-newsrc-hashtb)))))
4380 (setcar (cdr method)
4381 (concat
4382 (nth 1 method) "\\|"
4383 (mapconcat
4384 (lambda (s)
4385 (gnus-group-remove-mark s)
4386 (concat "\\(^" (regexp-quote s) "$\\)"))
4387 groups "\\|"))))
4388 (gnus-group-position-cursor))
4389
4390 (defun gnus-group-make-empty-virtual (group)
4391 "Create a new, fresh, empty virtual group."
4392 (interactive "sCreate new, empty virtual group: ")
4393 (let* ((method (list 'nnvirtual "^$"))
4394 (pgroup (gnus-group-prefixed-name group method)))
4395 ;; Check whether it exists already.
4396 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
4397 (error "Group %s already exists." pgroup))
4398 ;; Subscribe the new group after the group on the current line.
4399 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
4400 (gnus-group-update-group pgroup)
4401 (forward-line -1)
4402 (gnus-group-position-cursor)))
4403
4404 (defun gnus-group-enter-directory (dir)
4405 "Enter an ephemeral nneething group."
4406 (interactive "DDirectory to read: ")
4407 (let* ((method (list 'nneething dir))
4408 (leaf (gnus-group-prefixed-name
4409 (file-name-nondirectory (directory-file-name dir))
4410 method))
4411 (name (gnus-generate-new-group-name leaf)))
4412 (let ((nneething-read-only t))
4413 (or (gnus-group-read-ephemeral-group
4414 name method t
4415 (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
4416 'summary 'group)))
4417 (error "Couldn't enter %s" dir)))))
4418
4419 ;; Group sorting commands
4420 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
4421
4422 (defun gnus-group-sort-groups ()
4423 "Sort the group buffer using `gnus-group-sort-function'."
4424 (interactive)
4425 (setq gnus-newsrc-alist
4426 (sort (cdr gnus-newsrc-alist) gnus-group-sort-function))
4427 (gnus-make-hashtable-from-newsrc-alist)
4428 (gnus-group-list-groups))
4429
4430 (defun gnus-group-sort-by-alphabet (info1 info2)
4431 (string< (car info1) (car info2)))
4432
4433 (defun gnus-group-sort-by-unread (info1 info2)
4434 (let ((n1 (car (gnus-gethash (car info1) gnus-newsrc-hashtb)))
4435 (n2 (car (gnus-gethash (car info2) gnus-newsrc-hashtb))))
4436 (< (or (and (numberp n1) n1) 0)
4437 (or (and (numberp n2) n2) 0))))
4438
4439 (defun gnus-group-sort-by-level (info1 info2)
4440 (< (nth 1 info1) (nth 1 info2)))
4441
4442 ;; Group catching up.
4443
4444 (defun gnus-group-catchup-current (&optional n all)
4445 "Mark all articles not marked as unread in current newsgroup as read.
4446 If prefix argument N is numeric, the ARG next newsgroups will be
4447 caught up. If ALL is non-nil, marked articles will also be marked as
4448 read. Cross references (Xref: header) of articles are ignored.
4449 The difference between N and actual number of newsgroups that were
4450 caught up is returned."
4451 (interactive "P")
4452 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
4453 gnus-expert-user
4454 (gnus-y-or-n-p
4455 (if all
4456 "Do you really want to mark all articles as read? "
4457 "Mark all unread articles as read? "))))
4458 n
4459 (let ((groups (gnus-group-process-prefix n))
4460 (ret 0))
4461 (while groups
4462 ;; Virtual groups have to be given special treatment.
4463 (let ((method (gnus-find-method-for-group (car groups))))
4464 (if (eq 'nnvirtual (car method))
4465 (nnvirtual-catchup-group
4466 (gnus-group-real-name (car groups)) (nth 1 method) all)))
4467 (gnus-group-remove-mark (car groups))
4468 (if (prog1
4469 (gnus-group-goto-group (car groups))
4470 (gnus-group-catchup (car groups) all))
4471 (gnus-group-update-group-line)
4472 (setq ret (1+ ret)))
4473 (setq groups (cdr groups)))
4474 (gnus-group-next-unread-group 1)
4475 ret)))
4476
4477 (defun gnus-group-catchup-current-all (&optional n)
4478 "Mark all articles in current newsgroup as read.
4479 Cross references (Xref: header) of articles are ignored."
4480 (interactive "P")
4481 (gnus-group-catchup-current n 'all))
4482
4483 (defun gnus-group-catchup (group &optional all)
4484 "Mark all articles in GROUP as read.
4485 If ALL is non-nil, all articles are marked as read.
4486 The return value is the number of articles that were marked as read,
4487 or nil if no action could be taken."
4488 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4489 (num (car entry))
4490 (marked (nth 3 (nth 2 entry))))
4491 (if (not (numberp (car entry)))
4492 (gnus-message 1 "Can't catch up; non-active group")
4493 ;; Do the updating only if the newsgroup isn't killed.
4494 (if (not entry)
4495 ()
4496 (gnus-update-read-articles
4497 group (and (not all) (append (cdr (assq 'tick marked))
4498 (cdr (assq 'dormant marked))))
4499 nil (and (not all) (cdr (assq 'tick marked))))
4500 (and all
4501 (setq marked (nth 3 (nth 2 entry)))
4502 (setcar (nthcdr 3 (nth 2 entry))
4503 (delq (assq 'dormant marked)
4504 (nth 3 (nth 2 entry)))))))
4505 num))
4506
4507 (defun gnus-group-expire-articles (&optional n)
4508 "Expire all expirable articles in the current newsgroup."
4509 (interactive "P")
4510 (let ((groups (gnus-group-process-prefix n))
4511 group)
4512 (or groups (error "No groups to expire"))
4513 (while groups
4514 (setq group (car groups)
4515 groups (cdr groups))
4516 (gnus-group-remove-mark group)
4517 (if (not (gnus-check-backend-function 'request-expire-articles group))
4518 ()
4519 (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4520 (expirable (if (memq 'total-expire (nth 5 info))
4521 (cons nil (gnus-list-of-read-articles group))
4522 (assq 'expire (nth 3 info)))))
4523 (and expirable
4524 (setcdr expirable
4525 (gnus-request-expire-articles
4526 (cdr expirable) group))))))))
4527
4528 (defun gnus-group-expire-all-groups ()
4529 "Expire all expirable articles in all newsgroups."
4530 (interactive)
4531 (save-excursion
4532 (gnus-message 5 "Expiring...")
4533 (let ((gnus-group-marked (mapcar (lambda (info) (car info))
4534 (cdr gnus-newsrc-alist))))
4535 (gnus-group-expire-articles nil)))
4536 (gnus-group-position-cursor)
4537 (gnus-message 5 "Expiring...done"))
4538
4539 (defun gnus-group-set-current-level (n level)
4540 "Set the level of the next N groups to LEVEL."
4541 (interactive "P\nnLevel: ")
4542 (or (and (>= level 1) (<= level gnus-level-killed))
4543 (error "Illegal level: %d" level))
4544 (let ((groups (gnus-group-process-prefix n))
4545 group)
4546 (while groups
4547 (setq group (car groups)
4548 groups (cdr groups))
4549 (gnus-group-remove-mark group)
4550 (gnus-message 6 "Changed level of %s from %d to %d"
4551 group (gnus-group-group-level) level)
4552 (gnus-group-change-level group level
4553 (gnus-group-group-level))
4554 (gnus-group-update-group-line)))
4555 (gnus-group-position-cursor))
4556
4557 (defun gnus-group-unsubscribe-current-group (&optional n)
4558 "Toggle subscription of the current group.
4559 If given numerical prefix, toggle the N next groups."
4560 (interactive "P")
4561 (let ((groups (gnus-group-process-prefix n))
4562 group)
4563 (while groups
4564 (setq group (car groups)
4565 groups (cdr groups))
4566 (gnus-group-remove-mark group)
4567 (gnus-group-unsubscribe-group
4568 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
4569 gnus-level-default-unsubscribed
4570 gnus-level-default-subscribed))
4571 (gnus-group-update-group-line))
4572 (gnus-group-next-group 1)))
4573
4574 (defun gnus-group-unsubscribe-group (group &optional level)
4575 "Toggle subscribe from/to unsubscribe GROUP.
4576 New newsgroup is added to .newsrc automatically."
4577 (interactive
4578 (list (completing-read
4579 "Group: " gnus-active-hashtb nil
4580 (memq gnus-select-method gnus-have-read-active-file))))
4581 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
4582 (cond
4583 ((string-match "^[ \t]$" group)
4584 (error "Empty group name"))
4585 (newsrc
4586 ;; Toggle subscription flag.
4587 (gnus-group-change-level
4588 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
4589 gnus-level-subscribed)
4590 (1+ gnus-level-subscribed)
4591 gnus-level-default-subscribed)))
4592 (gnus-group-update-group group))
4593 ((and (stringp group)
4594 (or (not (memq gnus-select-method gnus-have-read-active-file))
4595 (gnus-gethash group gnus-active-hashtb)))
4596 ;; Add new newsgroup.
4597 (gnus-group-change-level
4598 group
4599 (if level level gnus-level-default-subscribed)
4600 (or (and (member group gnus-zombie-list)
4601 gnus-level-zombie)
4602 gnus-level-killed)
4603 (and (gnus-group-group-name)
4604 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
4605 (gnus-group-update-group group))
4606 (t (error "No such newsgroup: %s" group)))
4607 (gnus-group-position-cursor)))
4608
4609 (defun gnus-group-transpose-groups (n)
4610 "Move the current newsgroup up N places.
4611 If given a negative prefix, move down instead. The difference between
4612 N and the number of steps taken is returned."
4613 (interactive "p")
4614 (or (gnus-group-group-name)
4615 (error "No group on current line"))
4616 (gnus-group-kill-group 1)
4617 (prog1
4618 (forward-line (- n))
4619 (gnus-group-yank-group)
4620 (gnus-group-position-cursor)))
4621
4622 (defun gnus-group-kill-all-zombies ()
4623 "Kill all zombie newsgroups."
4624 (interactive)
4625 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
4626 (setq gnus-zombie-list nil)
4627 (gnus-group-list-groups))
4628
4629 (defun gnus-group-kill-region (begin end)
4630 "Kill newsgroups in current region (excluding current point).
4631 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
4632 (interactive "r")
4633 (let ((lines
4634 ;; Count lines.
4635 (save-excursion
4636 (count-lines
4637 (progn
4638 (goto-char begin)
4639 (beginning-of-line)
4640 (point))
4641 (progn
4642 (goto-char end)
4643 (beginning-of-line)
4644 (point))))))
4645 (goto-char begin)
4646 (beginning-of-line) ;Important when LINES < 1
4647 (gnus-group-kill-group lines)))
4648
4649 (defun gnus-group-kill-group (&optional n)
4650 "The the next N groups.
4651 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
4652 However, only groups that were alive can be yanked; already killed
4653 groups or zombie groups can't be yanked.
4654 The return value is the name of the (last) group that was killed."
4655 (interactive "P")
4656 (let ((buffer-read-only nil)
4657 (groups (gnus-group-process-prefix n))
4658 group entry level)
4659 (while groups
4660 (setq group (car groups)
4661 groups (cdr groups))
4662 (gnus-group-remove-mark group)
4663 (setq level (gnus-group-group-level))
4664 (gnus-delete-line)
4665 (if (setq entry (gnus-gethash group gnus-newsrc-hashtb))
4666 (setq gnus-list-of-killed-groups
4667 (cons (cons (car entry) (nth 2 entry))
4668 gnus-list-of-killed-groups)))
4669 (gnus-group-change-level
4670 (if entry entry group) gnus-level-killed (if entry nil level)))
4671 (gnus-group-position-cursor)
4672 group))
4673
4674 (defun gnus-group-yank-group (&optional arg)
4675 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
4676 inserting it before the current newsgroup. The numeric ARG specifies
4677 how many newsgroups are to be yanked. The name of the (last)
4678 newsgroup yanked is returned."
4679 (interactive "p")
4680 (if (not arg) (setq arg 1))
4681 (let (info group prev)
4682 (while (>= (setq arg (1- arg)) 0)
4683 (if (not (setq info (car gnus-list-of-killed-groups)))
4684 (error "No more newsgroups to yank"))
4685 (setq group (nth 2 info))
4686 ;; Find which newsgroup to insert this one before - search
4687 ;; backward until something suitable is found. If there are no
4688 ;; other newsgroups in this buffer, just make this newsgroup the
4689 ;; first newsgroup.
4690 (setq prev (gnus-group-group-name))
4691 (gnus-group-change-level
4692 info (nth 2 info) gnus-level-killed
4693 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
4694 t)
4695 (gnus-group-insert-group-line-info (nth 1 info))
4696 (setq gnus-list-of-killed-groups
4697 (cdr gnus-list-of-killed-groups)))
4698 (forward-line -1)
4699 (gnus-group-position-cursor)
4700 group))
4701
4702 (defun gnus-group-list-all-groups (&optional arg)
4703 "List all newsgroups with level ARG or lower.
4704 Default is gnus-level-unsubscribed, which lists all subscribed and most
4705 unsubscribed groups."
4706 (interactive "P")
4707 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
4708
4709 (defun gnus-group-list-killed ()
4710 "List all killed newsgroups in the group buffer."
4711 (interactive)
4712 (if (not gnus-killed-list)
4713 (gnus-message 6 "No killed groups")
4714 (let (gnus-group-list-mode)
4715 (funcall gnus-group-prepare-function
4716 gnus-level-killed t gnus-level-killed))
4717 (goto-char (point-min)))
4718 (gnus-group-position-cursor))
4719
4720 (defun gnus-group-list-zombies ()
4721 "List all zombie newsgroups in the group buffer."
4722 (interactive)
4723 (if (not gnus-zombie-list)
4724 (gnus-message 6 "No zombie groups")
4725 (let (gnus-group-list-mode)
4726 (funcall gnus-group-prepare-function
4727 gnus-level-zombie t gnus-level-zombie))
4728 (goto-char (point-min)))
4729 (gnus-group-position-cursor))
4730
4731 (defun gnus-group-get-new-news (&optional arg)
4732 "Get newly arrived articles.
4733 If ARG is non-nil, it should be a number between one and nine to
4734 specify which levels you are interested in re-scanning."
4735 (interactive "P")
4736 (run-hooks 'gnus-get-new-news-hook)
4737 (setq arg (gnus-group-default-level arg t))
4738 (if (and gnus-read-active-file (not arg))
4739 (progn
4740 (gnus-read-active-file)
4741 (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))
4742 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
4743 (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))))
4744 (gnus-group-list-groups))
4745
4746 (defun gnus-group-get-new-news-this-group (&optional n)
4747 "Check for newly arrived news in the current group (and the N-1 next groups).
4748 The difference between N and the number of newsgroup checked is returned.
4749 If N is negative, this group and the N-1 previous groups will be checked."
4750 (interactive "P")
4751 (let* ((groups (gnus-group-process-prefix n))
4752 (ret (if (numberp n) (- n (length groups)) 0))
4753 group)
4754 (while groups
4755 (setq group (car groups)
4756 groups (cdr groups))
4757 (gnus-group-remove-mark group)
4758 (or (gnus-get-new-news-in-group group)
4759 (progn
4760 (ding)
4761 (message "%s error: %s" group (gnus-status-message group))
4762 (sit-for 2))))
4763 (gnus-group-next-unread-group 1 t)
4764 (gnus-summary-position-cursor)
4765 ret))
4766
4767 (defun gnus-get-new-news-in-group (group)
4768 (and group
4769 (gnus-activate-group group)
4770 (progn
4771 (gnus-get-unread-articles-in-group
4772 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))
4773 (gnus-gethash group gnus-active-hashtb))
4774 (gnus-group-update-group-line)
4775 t)))
4776
4777 (defun gnus-group-fetch-faq (group)
4778 "Fetch the FAQ for the current group."
4779 (interactive (list (gnus-group-real-name (gnus-group-group-name))))
4780 (or group (error "No group name given"))
4781 (let ((file (concat gnus-group-faq-directory (gnus-group-real-name group))))
4782 (if (not (file-exists-p file))
4783 (error "No such file: %s" file)
4784 (find-file file))))
4785
4786 (defun gnus-group-describe-group (force &optional group)
4787 "Display a description of the current newsgroup."
4788 (interactive (list current-prefix-arg (gnus-group-group-name)))
4789 (and force (setq gnus-description-hashtb nil))
4790 (let ((method (gnus-find-method-for-group group))
4791 desc)
4792 (or group (error "No group name given"))
4793 (and (or (and gnus-description-hashtb
4794 ;; We check whether this group's method has been
4795 ;; queried for a description file.
4796 (gnus-gethash
4797 (gnus-group-prefixed-name "" method)
4798 gnus-description-hashtb))
4799 (setq desc (gnus-group-get-description group))
4800 (gnus-read-descriptions-file method))
4801 (message
4802 (or desc (gnus-gethash group gnus-description-hashtb)
4803 "No description available")))))
4804
4805 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4806 (defun gnus-group-describe-all-groups (&optional force)
4807 "Pop up a buffer with descriptions of all newsgroups."
4808 (interactive "P")
4809 (and force (setq gnus-description-hashtb nil))
4810 (if (not (or gnus-description-hashtb
4811 (gnus-read-all-descriptions-files)))
4812 (error "Couldn't request descriptions file"))
4813 (let ((buffer-read-only nil)
4814 b)
4815 (erase-buffer)
4816 (mapatoms
4817 (lambda (group)
4818 (setq b (point))
4819 (insert (format " *: %-20s %s\n" (symbol-name group)
4820 (symbol-value group)))
4821 (add-text-properties
4822 b (1+ b) (list 'gnus-group group
4823 'gnus-unread t 'gnus-marked nil
4824 'gnus-level (1+ gnus-level-subscribed))))
4825 gnus-description-hashtb)
4826 (goto-char (point-min))
4827 (gnus-group-position-cursor)))
4828
4829 ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
4830 (defun gnus-group-apropos (regexp &optional search-description)
4831 "List all newsgroups that have names that match a regexp."
4832 (interactive "sGnus apropos (regexp): ")
4833 (let ((prev "")
4834 (obuf (current-buffer))
4835 groups des)
4836 ;; Go through all newsgroups that are known to Gnus.
4837 (mapatoms
4838 (lambda (group)
4839 (and (symbol-name group)
4840 (string-match regexp (symbol-name group))
4841 (setq groups (cons (symbol-name group) groups))))
4842 gnus-active-hashtb)
4843 ;; Go through all descriptions that are known to Gnus.
4844 (if search-description
4845 (mapatoms
4846 (lambda (group)
4847 (and (string-match regexp (symbol-value group))
4848 (gnus-gethash (symbol-name group) gnus-active-hashtb)
4849 (setq groups (cons (symbol-name group) groups))))
4850 gnus-description-hashtb))
4851 (if (not groups)
4852 (gnus-message 3 "No groups matched \"%s\"." regexp)
4853 ;; Print out all the groups.
4854 (save-excursion
4855 (pop-to-buffer "*Gnus Help*")
4856 (buffer-disable-undo (current-buffer))
4857 (erase-buffer)
4858 (setq groups (sort groups 'string<))
4859 (while groups
4860 ;; Groups may be entered twice into the list of groups.
4861 (if (not (string= (car groups) prev))
4862 (progn
4863 (insert (setq prev (car groups)) "\n")
4864 (if (and gnus-description-hashtb
4865 (setq des (gnus-gethash (car groups)
4866 gnus-description-hashtb)))
4867 (insert " " des "\n"))))
4868 (setq groups (cdr groups)))
4869 (goto-char (point-min))))
4870 (pop-to-buffer obuf)))
4871
4872 (defun gnus-group-description-apropos (regexp)
4873 "List all newsgroups that have names or descriptions that match a regexp."
4874 (interactive "sGnus description apropos (regexp): ")
4875 (if (not (or gnus-description-hashtb
4876 (gnus-read-all-descriptions-files)))
4877 (error "Couldn't request descriptions file"))
4878 (gnus-group-apropos regexp t))
4879
4880 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4881 (defun gnus-group-list-matching (level regexp &optional all lowest)
4882 "List all groups with unread articles that match REGEXP.
4883 If the prefix LEVEL is non-nil, it should be a number that says which
4884 level to cut off listing groups.
4885 If ALL, also list groups with no unread articles.
4886 If LOWEST, don't list groups with level lower than LOWEST."
4887 (interactive "P\nsList newsgroups matching: ")
4888 (gnus-group-prepare-flat (or level gnus-level-subscribed)
4889 all (or lowest 1) regexp)
4890 (goto-char (point-min))
4891 (gnus-group-position-cursor))
4892
4893 (defun gnus-group-list-all-matching (level regexp &optional lowest)
4894 "List all groups that match REGEXP.
4895 If the prefix LEVEL is non-nil, it should be a number that says which
4896 level to cut off listing groups.
4897 If LOWEST, don't list groups with level lower than LOWEST."
4898 (interactive "P\nsList newsgroups matching: ")
4899 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
4900
4901 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
4902 (defun gnus-group-save-newsrc ()
4903 "Save the Gnus startup files."
4904 (interactive)
4905 (gnus-save-newsrc-file))
4906
4907 (defun gnus-group-restart (&optional arg)
4908 "Force Gnus to read the .newsrc file."
4909 (interactive "P")
4910 (gnus-save-newsrc-file)
4911 (gnus-setup-news 'force)
4912 (gnus-group-list-groups arg))
4913
4914 (defun gnus-group-read-init-file ()
4915 "Read the Gnus elisp init file."
4916 (interactive)
4917 (gnus-read-init-file))
4918
4919 (defun gnus-group-check-bogus-groups (&optional silent)
4920 "Check bogus newsgroups.
4921 If given a prefix, don't ask for confirmation before removing a bogus
4922 group."
4923 (interactive "P")
4924 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
4925 (gnus-group-list-groups))
4926
4927 (defun gnus-group-edit-global-kill (&optional article group)
4928 "Edit the global kill file.
4929 If GROUP, edit that local kill file instead."
4930 (interactive "P")
4931 (setq gnus-current-kill-article article)
4932 (gnus-kill-file-edit-file group)
4933 (gnus-message
4934 6
4935 (substitute-command-keys
4936 "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)")))
4937
4938 (defun gnus-group-edit-local-kill (article group)
4939 "Edit a local kill file."
4940 (interactive (list nil (gnus-group-group-name)))
4941 (gnus-group-edit-global-kill article group))
4942
4943 (defun gnus-group-force-update ()
4944 "Update `.newsrc' file."
4945 (interactive)
4946 (gnus-save-newsrc-file))
4947
4948 (defun gnus-group-suspend ()
4949 "Suspend the current Gnus session.
4950 In fact, cleanup buffers except for group mode buffer.
4951 The hook gnus-suspend-gnus-hook is called before actually suspending."
4952 (interactive)
4953 (run-hooks 'gnus-suspend-gnus-hook)
4954 ;; Kill Gnus buffers except for group mode buffer.
4955 (let ((group-buf (get-buffer gnus-group-buffer)))
4956 ;; Do this on a separate list in case the user does a ^G before we finish
4957 (let ((gnus-buffer-list
4958 (delq group-buf (delq gnus-dribble-buffer
4959 (append gnus-buffer-list nil)))))
4960 (while gnus-buffer-list
4961 (gnus-kill-buffer (car gnus-buffer-list))
4962 (setq gnus-buffer-list (cdr gnus-buffer-list))))
4963 (if group-buf
4964 (progn
4965 (setq gnus-buffer-list (list group-buf))
4966 (bury-buffer group-buf)
4967 (delete-windows-on group-buf t)))))
4968
4969 (defun gnus-group-clear-dribble ()
4970 "Clear all information from the dribble buffer."
4971 (interactive)
4972 (gnus-dribble-clear))
4973
4974 (defun gnus-group-exit ()
4975 "Quit reading news after updating .newsrc.eld and .newsrc.
4976 The hook `gnus-exit-gnus-hook' is called before actually exiting."
4977 (interactive)
4978 (if (or noninteractive ;For gnus-batch-kill
4979 (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed
4980 (not gnus-interactive-exit) ;Without confirmation
4981 gnus-expert-user
4982 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
4983 (progn
4984 (run-hooks 'gnus-exit-gnus-hook)
4985 ;; Offer to save data from non-quitted summary buffers.
4986 (gnus-offer-save-summaries)
4987 ;; Save the newsrc file(s).
4988 (gnus-save-newsrc-file)
4989 ;; Kill-em-all.
4990 (gnus-close-backends)
4991 ;; Reset everything.
4992 (gnus-clear-system))))
4993
4994 (defun gnus-close-backends ()
4995 ;; Send a close request to all backends that support such a request.
4996 (let ((methods gnus-valid-select-methods)
4997 func)
4998 (while methods
4999 (if (fboundp (setq func (intern (concat (car (car methods))
5000 "-request-close"))))
5001 (funcall func))
5002 (setq methods (cdr methods)))))
5003
5004 (defun gnus-group-quit ()
5005 "Quit reading news without updating .newsrc.eld or .newsrc.
5006 The hook `gnus-exit-gnus-hook' is called before actually exiting."
5007 (interactive)
5008 (if (or noninteractive ;For gnus-batch-kill
5009 (zerop (buffer-size))
5010 (not (gnus-server-opened gnus-select-method))
5011 gnus-expert-user
5012 (not gnus-current-startup-file)
5013 (gnus-yes-or-no-p
5014 (format "Quit reading news without saving %s? "
5015 (file-name-nondirectory gnus-current-startup-file))))
5016 (progn
5017 (run-hooks 'gnus-exit-gnus-hook)
5018 (if gnus-use-full-window
5019 (delete-other-windows)
5020 (gnus-remove-some-windows))
5021 (gnus-dribble-save)
5022 (gnus-close-backends)
5023 (gnus-clear-system))))
5024
5025 (defun gnus-offer-save-summaries ()
5026 (save-excursion
5027 (let ((buflist (buffer-list))
5028 buffers bufname)
5029 (while buflist
5030 (and (setq bufname (buffer-name (car buflist)))
5031 (string-match "Summary" bufname)
5032 (save-excursion
5033 (set-buffer bufname)
5034 ;; We check that this is, indeed, a summary buffer.
5035 (eq major-mode 'gnus-summary-mode))
5036 (setq buffers (cons bufname buffers)))
5037 (setq buflist (cdr buflist)))
5038 (and buffers
5039 (map-y-or-n-p
5040 "Update summary buffer %s? "
5041 (lambda (buf)
5042 (set-buffer buf)
5043 (gnus-summary-exit))
5044 buffers)))))
5045
5046 (defun gnus-group-describe-briefly ()
5047 "Give a one line description of the group mode commands."
5048 (interactive)
5049 (gnus-message 7 (substitute-command-keys "\\<gnus-group-mode-map>\\[gnus-group-read-group]:Select \\[gnus-group-next-unread-group]:Forward \\[gnus-group-prev-unread-group]:Backward \\[gnus-group-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-group-describe-briefly]:This help")))
5050
5051 (defun gnus-group-browse-foreign-server (method)
5052 "Browse a foreign news server.
5053 If called interactively, this function will ask for a select method
5054 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
5055 If not, METHOD should be a list where the first element is the method
5056 and the second element is the address."
5057 (interactive
5058 (list (let ((how (completing-read
5059 "Which backend: "
5060 (append gnus-valid-select-methods gnus-server-alist)
5061 nil t "nntp")))
5062 ;; We either got a backend name or a virtual server name.
5063 ;; If the first, we also need an address.
5064 (if (assoc how gnus-valid-select-methods)
5065 (list (intern how)
5066 ;; Suggested by mapjph@bath.ac.uk.
5067 (completing-read
5068 "Address: "
5069 (mapcar (lambda (server) (list server))
5070 gnus-secondary-servers)))
5071 ;; We got a server name, so we find the method.
5072 (gnus-server-to-method how)))))
5073 (gnus-browse-foreign-server method))
5074
5075 \f
5076 ;;;
5077 ;;; Browse Server Mode
5078 ;;;
5079
5080 (defvar gnus-browse-mode-hook nil)
5081 (defvar gnus-browse-mode-map nil)
5082 (put 'gnus-browse-mode 'mode-class 'special)
5083
5084 (if gnus-browse-mode-map
5085 nil
5086 (setq gnus-browse-mode-map (make-keymap))
5087 (suppress-keymap gnus-browse-mode-map)
5088 (define-key gnus-browse-mode-map " " 'gnus-browse-read-group)
5089 (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group)
5090 (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group)
5091 (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group)
5092 (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group)
5093 (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group)
5094 (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group)
5095 (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group)
5096 (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group)
5097 (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group)
5098 (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group)
5099 (define-key gnus-browse-mode-map "l" 'gnus-browse-exit)
5100 (define-key gnus-browse-mode-map "L" 'gnus-browse-exit)
5101 (define-key gnus-browse-mode-map "q" 'gnus-browse-exit)
5102 (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit)
5103 (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit)
5104 (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly)
5105 (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node)
5106 )
5107
5108 (defvar gnus-browse-current-method nil)
5109 (defvar gnus-browse-return-buffer nil)
5110
5111 (defvar gnus-browse-buffer "*Gnus Browse Server*")
5112
5113 (defun gnus-browse-foreign-server (method &optional return-buffer)
5114 (setq gnus-browse-current-method method)
5115 (setq gnus-browse-return-buffer return-buffer)
5116 (let ((gnus-select-method method)
5117 groups group)
5118 (gnus-message 5 "Connecting to %s..." (nth 1 method))
5119 (or (gnus-check-server method)
5120 (error "Unable to contact server: %s" (gnus-status-message method)))
5121 (or (gnus-request-list method)
5122 (error "Couldn't request list: %s" (gnus-status-message method)))
5123 (get-buffer-create gnus-browse-buffer)
5124 (gnus-add-current-to-buffer-list)
5125 (and gnus-carpal (gnus-carpal-setup-buffer 'browse))
5126 (gnus-configure-windows 'browse)
5127 (buffer-disable-undo (current-buffer))
5128 (let ((buffer-read-only nil))
5129 (erase-buffer))
5130 (gnus-browse-mode)
5131 (setq mode-line-buffer-identification
5132 (format
5133 "Gnus Browse Server {%s:%s}" (car method) (car (cdr method))))
5134 (save-excursion
5135 (set-buffer nntp-server-buffer)
5136 (let ((cur (current-buffer)))
5137 (goto-char (point-min))
5138 (or (string= gnus-ignored-newsgroups "")
5139 (delete-matching-lines gnus-ignored-newsgroups))
5140 (while (re-search-forward
5141 "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
5142 (goto-char (match-end 1))
5143 (setq groups (cons (cons (buffer-substring (match-beginning 1)
5144 (match-end 1))
5145 (max 0 (- (1+ (read cur)) (read cur))))
5146 groups)))))
5147 (setq groups (sort groups
5148 (lambda (l1 l2)
5149 (string< (car l1) (car l2)))))
5150 (let ((buffer-read-only nil))
5151 (while groups
5152 (setq group (car groups))
5153 (insert
5154 (format "K%7d: %s\n" (cdr group) (car group)))
5155 (setq groups (cdr groups))))
5156 (switch-to-buffer (current-buffer))
5157 (goto-char (point-min))
5158 (gnus-group-position-cursor)))
5159
5160 (defun gnus-browse-mode ()
5161 "Major mode for browsing a foreign server.
5162
5163 All normal editing commands are switched off.
5164
5165 \\<gnus-browse-mode-map>
5166 The only things you can do in this buffer is
5167
5168 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
5169 The group will be inserted into the group buffer upon exit from this
5170 buffer.
5171
5172 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
5173
5174 3) `\\[gnus-browse-exit]' to return to the group buffer."
5175 (interactive)
5176 (kill-all-local-variables)
5177 (if gnus-visual (gnus-browse-make-menu-bar))
5178 (gnus-simplify-mode-line)
5179 (setq major-mode 'gnus-browse-mode)
5180 (setq mode-name "Browse Server")
5181 (setq mode-line-process nil)
5182 (use-local-map gnus-browse-mode-map)
5183 (buffer-disable-undo (current-buffer))
5184 (setq truncate-lines t)
5185 (setq buffer-read-only t)
5186 (run-hooks 'gnus-browse-mode-hook))
5187
5188 (defun gnus-browse-read-group (&optional no-article)
5189 "Enter the group at the current line."
5190 (interactive)
5191 (let ((group (gnus-browse-group-name)))
5192 (or (gnus-group-read-ephemeral-group
5193 group gnus-browse-current-method nil
5194 (cons (current-buffer) 'browse))
5195 (error "Couldn't enter %s" group))))
5196
5197 (defun gnus-browse-select-group ()
5198 "Select the current group."
5199 (interactive)
5200 (gnus-browse-read-group 'no))
5201
5202 (defun gnus-browse-next-group (n)
5203 "Go to the next group."
5204 (interactive "p")
5205 (prog1
5206 (forward-line n)
5207 (gnus-group-position-cursor)))
5208
5209 (defun gnus-browse-prev-group (n)
5210 "Go to the next group."
5211 (interactive "p")
5212 (gnus-browse-next-group (- n)))
5213
5214 (defun gnus-browse-unsubscribe-current-group (arg)
5215 "(Un)subscribe to the next ARG groups."
5216 (interactive "p")
5217 (and (eobp)
5218 (error "No group at current line."))
5219 (let ((ward (if (< arg 0) -1 1))
5220 (arg (abs arg)))
5221 (while (and (> arg 0)
5222 (not (eobp))
5223 (gnus-browse-unsubscribe-group)
5224 (zerop (gnus-browse-next-group ward)))
5225 (setq arg (1- arg)))
5226 (gnus-group-position-cursor)
5227 (if (/= 0 arg) (gnus-message 7 "No more newsgroups"))
5228 arg))
5229
5230 (defun gnus-browse-group-name ()
5231 (save-excursion
5232 (beginning-of-line)
5233 (if (not (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t))
5234 ()
5235 (gnus-group-prefixed-name
5236 (buffer-substring (match-beginning 1) (match-end 1))
5237 gnus-browse-current-method))))
5238
5239 (defun gnus-browse-unsubscribe-group ()
5240 "Toggle subscription of the current group in the browse buffer."
5241 (let ((sub nil)
5242 (buffer-read-only nil)
5243 group)
5244 (save-excursion
5245 (beginning-of-line)
5246 ;; If this group it killed, then we want to subscribe it.
5247 (if (= (following-char) ?K) (setq sub t))
5248 (setq group (gnus-browse-group-name))
5249 (delete-char 1)
5250 (if sub
5251 (progn
5252 (gnus-group-change-level
5253 (list t group gnus-level-default-subscribed
5254 nil nil gnus-browse-current-method)
5255 gnus-level-default-subscribed gnus-level-killed
5256 (and (car (nth 1 gnus-newsrc-alist))
5257 (gnus-gethash (car (nth 1 gnus-newsrc-alist))
5258 gnus-newsrc-hashtb))
5259 t)
5260 (insert ? ))
5261 (gnus-group-change-level
5262 group gnus-level-killed gnus-level-default-subscribed)
5263 (insert ?K)))
5264 t))
5265
5266 (defun gnus-browse-exit ()
5267 "Quit browsing and return to the group buffer."
5268 (interactive)
5269 (if (eq major-mode 'gnus-browse-mode)
5270 (kill-buffer (current-buffer)))
5271 (if gnus-browse-return-buffer
5272 (gnus-configure-windows 'server 'force)
5273 (gnus-configure-windows 'group 'force)
5274 (gnus-group-list-groups nil)))
5275
5276 (defun gnus-browse-describe-briefly ()
5277 "Give a one line description of the group mode commands."
5278 (interactive)
5279 (gnus-message 6
5280 (substitute-command-keys "\\<gnus-browse-mode-map>\\[gnus-group-next-group]:Forward \\[gnus-group-prev-group]:Backward \\[gnus-browse-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-browse-describe-briefly]:This help")))
5281
5282 \f
5283 ;;;
5284 ;;; Gnus summary mode
5285 ;;;
5286
5287 (defvar gnus-summary-mode-map nil)
5288 (defvar gnus-summary-mark-map nil)
5289 (defvar gnus-summary-mscore-map nil)
5290 (defvar gnus-summary-article-map nil)
5291 (defvar gnus-summary-thread-map nil)
5292 (defvar gnus-summary-goto-map nil)
5293 (defvar gnus-summary-exit-map nil)
5294 (defvar gnus-summary-interest-map nil)
5295 (defvar gnus-summary-sort-map nil)
5296 (defvar gnus-summary-backend-map nil)
5297 (defvar gnus-summary-save-map nil)
5298 (defvar gnus-summary-wash-map nil)
5299 (defvar gnus-summary-wash-hide-map nil)
5300 (defvar gnus-summary-wash-highlight-map nil)
5301 (defvar gnus-summary-wash-time-map nil)
5302 (defvar gnus-summary-help-map nil)
5303
5304 (put 'gnus-summary-mode 'mode-class 'special)
5305
5306 (if gnus-summary-mode-map
5307 nil
5308 (setq gnus-summary-mode-map (make-keymap))
5309 (suppress-keymap gnus-summary-mode-map)
5310
5311 ;; Non-orthogonal keys
5312
5313 (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
5314 (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
5315 (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
5316 (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
5317 (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
5318 (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
5319 (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
5320 (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject)
5321 (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject)
5322 (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject)
5323 (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject)
5324 (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
5325 (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article)
5326 (define-key gnus-summary-mode-map
5327 "\M-s" 'gnus-summary-search-article-forward)
5328 (define-key gnus-summary-mode-map
5329 "\M-r" 'gnus-summary-search-article-backward)
5330 (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
5331 (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
5332 (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject)
5333 (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
5334 (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article)
5335 (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward)
5336 (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward)
5337 (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward)
5338 (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
5339 (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
5340 (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable)
5341 (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward)
5342 (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward)
5343 (define-key gnus-summary-mode-map
5344 "k" 'gnus-summary-kill-same-subject-and-select)
5345 (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
5346 (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread)
5347 (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread)
5348 (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article)
5349 (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable)
5350 (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable)
5351 (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads)
5352 (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread)
5353 (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread)
5354 (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread)
5355 (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread)
5356 (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread)
5357 (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread)
5358 (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
5359 (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
5360 (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read)
5361 (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
5362 (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant)
5363 (define-key gnus-summary-mode-map
5364 "\C-c\M-\C-s" 'gnus-summary-show-all-expunged)
5365 (define-key gnus-summary-mode-map
5366 "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
5367 (define-key gnus-summary-mode-map
5368 "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
5369 (define-key gnus-summary-mode-map
5370 "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
5371 (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
5372 (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score)
5373 (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
5374 (define-key gnus-summary-mode-map
5375 "\C-x\C-s" 'gnus-summary-reselect-current-group)
5376 (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group)
5377 (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
5378 (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
5379 (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime)
5380 (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
5381 (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
5382 (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
5383 (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
5384 (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
5385 (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
5386 (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
5387 (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail)
5388 (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
5389 (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill)
5390 (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill)
5391 (define-key gnus-summary-mode-map "V" 'gnus-version)
5392 (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group)
5393 (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
5394 (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update)
5395 (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)
5396 (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article)
5397 (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
5398 (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
5399 (define-key gnus-summary-mode-map
5400 "x" 'gnus-summary-remove-lines-marked-as-read)
5401 ; (define-key gnus-summary-mode-map "X" 'gnus-summary-remove-lines-marked-with)
5402 (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
5403 (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
5404 (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
5405 ; (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
5406 (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
5407 (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view)
5408 (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group)
5409 (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers)
5410 (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug)
5411
5412
5413 ;; Sort of orthogonal keymap
5414 (define-prefix-command 'gnus-summary-mark-map)
5415 (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map)
5416 (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward)
5417 (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward)
5418 (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward)
5419 (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward)
5420 (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward)
5421 (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward)
5422 (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable)
5423 (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable)
5424 (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant)
5425 (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark)
5426 (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark)
5427 (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable)
5428 (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable)
5429 (define-key gnus-summary-mark-map
5430 "\M-r" 'gnus-summary-remove-lines-marked-as-read)
5431 (define-key gnus-summary-mark-map
5432 "\M-\C-r" 'gnus-summary-remove-lines-marked-with)
5433 (define-key gnus-summary-mark-map "D" 'gnus-summary-show-all-dormant)
5434 (define-key gnus-summary-mark-map "\M-D" 'gnus-summary-hide-all-dormant)
5435 (define-key gnus-summary-mark-map "S" 'gnus-summary-show-all-expunged)
5436 (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup)
5437 (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here)
5438 (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all)
5439 (define-key gnus-summary-mark-map
5440 "k" 'gnus-summary-kill-same-subject-and-select)
5441 (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject)
5442
5443 (define-prefix-command 'gnus-summary-mscore-map)
5444 (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map)
5445 (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above)
5446 (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above)
5447 (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above)
5448 (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below)
5449
5450 (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map)
5451
5452 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
5453
5454 (define-prefix-command 'gnus-summary-goto-map)
5455 (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map)
5456 (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article)
5457 (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article)
5458 (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article)
5459 (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article)
5460 (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject)
5461 (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject)
5462 (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject)
5463 (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject)
5464 (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article)
5465 (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article)
5466 (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject)
5467 (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article)
5468 (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article)
5469
5470
5471 (define-prefix-command 'gnus-summary-thread-map)
5472 (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map)
5473 (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread)
5474 (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread)
5475 (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread)
5476 (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads)
5477 (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread)
5478 (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads)
5479 (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread)
5480 (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads)
5481 (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread)
5482 (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread)
5483 (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread)
5484 (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread)
5485 (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread)
5486
5487
5488 (define-prefix-command 'gnus-summary-exit-map)
5489 (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map)
5490 (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit)
5491 (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit)
5492 (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update)
5493 (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit)
5494 (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit)
5495 (define-key gnus-summary-exit-map
5496 "n" 'gnus-summary-catchup-and-goto-next-group)
5497 (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group)
5498 (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group)
5499 (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group)
5500 (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group)
5501
5502
5503 (define-prefix-command 'gnus-summary-article-map)
5504 (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map)
5505 (define-key gnus-summary-article-map " " 'gnus-summary-next-page)
5506 (define-key gnus-summary-article-map "n" 'gnus-summary-next-page)
5507 (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page)
5508 (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page)
5509 (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up)
5510 (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article)
5511 (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article)
5512 (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article)
5513 (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article)
5514 (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article)
5515 (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article)
5516 (define-key gnus-summary-article-map "g" 'gnus-summary-show-article)
5517 (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article)
5518
5519
5520
5521 (define-prefix-command 'gnus-summary-wash-map)
5522 (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map)
5523
5524 (define-prefix-command 'gnus-summary-wash-hide-map)
5525 (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map)
5526 (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide)
5527 (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers)
5528 (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature)
5529 (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation)
5530 (define-key gnus-summary-wash-hide-map
5531 "\C-c" 'gnus-article-hide-citation-maybe)
5532
5533 (define-prefix-command 'gnus-summary-wash-highlight-map)
5534 (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map)
5535 (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight)
5536 (define-key gnus-summary-wash-highlight-map
5537 "h" 'gnus-article-highlight-headers)
5538 (define-key gnus-summary-wash-highlight-map
5539 "c" 'gnus-article-highlight-citation)
5540 (define-key gnus-summary-wash-highlight-map
5541 "s" 'gnus-article-highlight-signature)
5542
5543 (define-prefix-command 'gnus-summary-wash-time-map)
5544 (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map)
5545 (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut)
5546 (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut)
5547 (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local)
5548 (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed)
5549
5550 (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons)
5551 (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike)
5552 (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap)
5553 (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr)
5554 (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable)
5555 (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face)
5556 (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking)
5557 (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message)
5558 (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header)
5559 (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime)
5560
5561
5562 (define-prefix-command 'gnus-summary-help-map)
5563 (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map)
5564 (define-key gnus-summary-help-map "v" 'gnus-version)
5565 (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq)
5566 (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group)
5567 (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly)
5568 (define-key gnus-summary-help-map "i" 'gnus-info-find-node)
5569
5570
5571 (define-prefix-command 'gnus-summary-backend-map)
5572 (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map)
5573 (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles)
5574 (define-key gnus-summary-backend-map "\M-\C-e"
5575 'gnus-summary-expire-articles-now)
5576 (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article)
5577 (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article)
5578 (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article)
5579 (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article)
5580 (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article)
5581 (define-key gnus-summary-backend-map "q" 'gnus-summary-fancy-query)
5582 (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article)
5583
5584
5585 (define-prefix-command 'gnus-summary-save-map)
5586 (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map)
5587 (define-key gnus-summary-save-map "o" 'gnus-summary-save-article)
5588 (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail)
5589 (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail)
5590 (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file)
5591 (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder)
5592 (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm)
5593 (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output)
5594 ; (define-key gnus-summary-save-map "s" 'gnus-soup-add-article)
5595
5596 (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
5597
5598 (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument)
5599 ; (define-key gnus-summary-various-map "\C-s" 'gnus-summary-search-article-forward)
5600 ; (define-key gnus-summary-various-map "\C-r" 'gnus-summary-search-article-backward)
5601 ; (define-key gnus-summary-various-map "r" 'gnus-summary-refer-article)
5602 ; (define-key gnus-summary-various-map "&" 'gnus-summary-execute-command)
5603 ; (define-key gnus-summary-various-map "T" 'gnus-summary-toggle-truncation)
5604 ; (define-key gnus-summary-various-map "e" 'gnus-summary-expand-window)
5605 (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group)
5606 ; (define-key gnus-summary-various-map "k" 'gnus-summary-edit-local-kill)
5607 ; (define-key gnus-summary-various-map "K" 'gnus-summary-edit-global-kill)
5608
5609 (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map)
5610
5611 ; (define-prefix-command 'gnus-summary-sort-map)
5612 ; (define-key gnus-summary-various-map "s" 'gnus-summary-sort-map)
5613 ; (define-key gnus-summary-sort-map "n" 'gnus-summary-sort-by-number)
5614 ; (define-key gnus-summary-sort-map "a" 'gnus-summary-sort-by-author)
5615 ; (define-key gnus-summary-sort-map "s" 'gnus-summary-sort-by-subject)
5616 ; (define-key gnus-summary-sort-map "d" 'gnus-summary-sort-by-date)
5617 ; (define-key gnus-summary-sort-map "i" 'gnus-summary-sort-by-score)
5618
5619 (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score)
5620 (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score)
5621 )
5622
5623
5624 \f
5625
5626 (defun gnus-summary-mode (&optional group)
5627 "Major mode for reading articles.
5628
5629 All normal editing commands are switched off.
5630 \\<gnus-summary-mode-map>
5631 Each line in this buffer represents one article. To read an
5632 article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
5633 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
5634 respectively.
5635
5636 You can also post articles and send mail from this buffer. To
5637 follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author
5638 of an article, type `\\[gnus-summary-reply]'.
5639
5640 There are approx. one gazillion commands you can execute in this
5641 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
5642
5643 The following commands are available:
5644
5645 \\{gnus-summary-mode-map}"
5646 (interactive)
5647 (if gnus-visual (gnus-summary-make-menu-bar))
5648 (kill-all-local-variables)
5649 (let ((locals gnus-summary-local-variables))
5650 (while locals
5651 (if (consp (car locals))
5652 (progn
5653 (make-local-variable (car (car locals)))
5654 (set (car (car locals)) (eval (cdr (car locals)))))
5655 (make-local-variable (car locals))
5656 (set (car locals) nil))
5657 (setq locals (cdr locals))))
5658 (gnus-make-thread-indent-array)
5659 (gnus-simplify-mode-line)
5660 (setq major-mode 'gnus-summary-mode)
5661 (setq mode-name "Summary")
5662 (make-local-variable 'minor-mode-alist)
5663 (use-local-map gnus-summary-mode-map)
5664 (buffer-disable-undo (current-buffer))
5665 (setq buffer-read-only t) ;Disable modification
5666 (setq truncate-lines t)
5667 (setq selective-display t)
5668 (setq selective-display-ellipses t) ;Display `...'
5669 (setq buffer-display-table gnus-summary-display-table)
5670 (setq gnus-newsgroup-name group)
5671 (run-hooks 'gnus-summary-mode-hook))
5672
5673 (defun gnus-summary-make-display-table ()
5674 ;; Change the display table. Odd characters have a tendency to mess
5675 ;; up nicely formatted displays - we make all possible glyphs
5676 ;; display only a single character.
5677
5678 ;; We start from the standard display table, if any.
5679 (setq gnus-summary-display-table
5680 (or (copy-sequence standard-display-table)
5681 (make-display-table)))
5682 ;; Nix out all the control chars...
5683 (let ((i 32))
5684 (while (>= (setq i (1- i)) 0)
5685 (aset gnus-summary-display-table i [??])))
5686 ;; ... but not newline and cr, of course. (cr is necessary for the
5687 ;; selective display).
5688 (aset gnus-summary-display-table ?\n nil)
5689 (aset gnus-summary-display-table ?\r nil)
5690 ;; We nix out any glyphs over 126 that are not set already.
5691 (let ((i 256))
5692 (while (>= (setq i (1- i)) 127)
5693 ;; Only modify if the entry is nil.
5694 (or (aref gnus-summary-display-table i)
5695 (aset gnus-summary-display-table i [??])))))
5696
5697 (defun gnus-summary-clear-local-variables ()
5698 (let ((locals gnus-summary-local-variables))
5699 (while locals
5700 (if (consp (car locals))
5701 (and (vectorp (car (car locals)))
5702 (set (car (car locals)) nil))
5703 (and (vectorp (car locals))
5704 (set (car locals) nil)))
5705 (setq locals (cdr locals)))))
5706
5707 ;; Some summary mode macros.
5708
5709 ;; Return a header specified by a NUMBER.
5710 (defun gnus-get-header-by-number (number)
5711 (save-excursion
5712 (set-buffer gnus-summary-buffer)
5713 (or gnus-newsgroup-headers-hashtb-by-number
5714 (gnus-make-headers-hashtable-by-number))
5715 (gnus-gethash (int-to-string number)
5716 gnus-newsgroup-headers-hashtb-by-number)))
5717
5718 ;; Fast version of the function above.
5719 (defmacro gnus-get-header-by-num (number)
5720 (` (gnus-gethash (int-to-string (, number))
5721 gnus-newsgroup-headers-hashtb-by-number)))
5722
5723 (defmacro gnus-summary-search-forward (&optional unread subject backward)
5724 "Search for article forward.
5725 If UNREAD is non-nil, only unread articles are selected.
5726 If SUBJECT is non-nil, the article which has the same subject will be
5727 searched for.
5728 If BACKWARD is non-nil, the search will be performed backwards instead."
5729 (` (gnus-summary-search-subject (, backward) (, unread) (, subject))))
5730
5731 (defmacro gnus-summary-search-backward (&optional unread subject)
5732 "Search for article backward.
5733 If 1st optional argument UNREAD is non-nil, only unread article is selected.
5734 If 2nd optional argument SUBJECT is non-nil, the article which has
5735 the same subject will be searched for."
5736 (` (gnus-summary-search-forward (, unread) (, subject) t)))
5737
5738 (defmacro gnus-summary-article-number (&optional number-or-nil)
5739 "The article number of the article on the current line.
5740 If there isn's an article number here, then we return the current
5741 article number."
5742 (if number-or-nil
5743 '(get-text-property (gnus-point-at-bol) 'gnus-number)
5744 '(or (get-text-property (gnus-point-at-bol) 'gnus-number)
5745 gnus-current-article)))
5746
5747 (defmacro gnus-summary-thread-level ()
5748 "The thread level of the article on the current line."
5749 '(or (get-text-property (gnus-point-at-bol) 'gnus-level)
5750 0))
5751
5752 (defmacro gnus-summary-article-mark ()
5753 "The mark on the current line."
5754 '(get-text-property (gnus-point-at-bol) 'gnus-mark))
5755
5756 (defun gnus-summary-subject-string ()
5757 "Return current subject string or nil if nothing."
5758 (let ((article (gnus-summary-article-number))
5759 header)
5760 (and article
5761 (setq header (gnus-get-header-by-num article))
5762 (vectorp header)
5763 (mail-header-subject header))))
5764
5765 ;; Various summary mode internalish functions.
5766
5767 (defun gnus-mouse-pick-article (e)
5768 (interactive "e")
5769 (mouse-set-point e)
5770 (gnus-summary-next-page nil t))
5771
5772 (defun gnus-summary-setup-buffer (group)
5773 "Initialize summary buffer."
5774 (let ((buffer (concat "*Summary " group "*")))
5775 (if (get-buffer buffer)
5776 (progn
5777 (set-buffer buffer)
5778 (not gnus-newsgroup-begin))
5779 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
5780 (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
5781 (gnus-add-current-to-buffer-list)
5782 (gnus-summary-mode group)
5783 (and gnus-carpal (gnus-carpal-setup-buffer 'summary))
5784 (setq gnus-newsgroup-name group)
5785 t)))
5786
5787 (defun gnus-set-global-variables ()
5788 ;; Set the global equivalents of the summary buffer-local variables
5789 ;; to the latest values they had. These reflect the summary buffer
5790 ;; that was in action when the last article was fetched.
5791 (if (eq major-mode 'gnus-summary-mode)
5792 (progn
5793 (setq gnus-summary-buffer (current-buffer))
5794 (let ((name gnus-newsgroup-name)
5795 (marked gnus-newsgroup-marked)
5796 (unread gnus-newsgroup-unreads)
5797 (headers gnus-current-headers)
5798 (score-file gnus-current-score-file))
5799 (save-excursion
5800 (set-buffer gnus-group-buffer)
5801 (setq gnus-newsgroup-name name)
5802 (setq gnus-newsgroup-marked marked)
5803 (setq gnus-newsgroup-unreads unread)
5804 (setq gnus-current-headers headers)
5805 (setq gnus-current-score-file score-file))))))
5806
5807 (defun gnus-summary-insert-dummy-line (sformat subject number)
5808 (if (not sformat)
5809 (setq sformat gnus-summary-dummy-line-format-spec))
5810 (let (b)
5811 (beginning-of-line)
5812 (setq b (point))
5813 (insert (eval sformat))
5814 (add-text-properties
5815 b (1+ b)
5816 (list 'gnus-number number
5817 'gnus-mark gnus-dummy-mark
5818 'gnus-level 0))))
5819
5820 (defvar gnus-thread-indent-array nil)
5821 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
5822 (defun gnus-make-thread-indent-array ()
5823 (let ((n 200))
5824 (if (and gnus-thread-indent-array
5825 (= gnus-thread-indent-level gnus-thread-indent-array-level))
5826 nil
5827 (setq gnus-thread-indent-array (make-vector 201 "")
5828 gnus-thread-indent-array-level gnus-thread-indent-level)
5829 (while (>= n 0)
5830 (aset gnus-thread-indent-array n
5831 (make-string (* n gnus-thread-indent-level) ? ))
5832 (setq n (1- n))))))
5833
5834 (defun gnus-summary-insert-line
5835 (sformat header level current unread replied expirable subject-or-nil
5836 &optional dummy score process)
5837 (or sformat (setq sformat gnus-summary-line-format-spec))
5838 (let* ((indentation (aref gnus-thread-indent-array level))
5839 (lines (mail-header-lines header))
5840 (score (or score gnus-summary-default-score 0))
5841 (score-char
5842 (if (or (null gnus-summary-default-score)
5843 (<= (abs (- score gnus-summary-default-score))
5844 gnus-summary-zcore-fuzz)) ?
5845 (if (< score gnus-summary-default-score)
5846 gnus-score-below-mark gnus-score-over-mark)))
5847 (replied (cond (process gnus-process-mark)
5848 (replied gnus-replied-mark)
5849 (t gnus-unread-mark)))
5850 (from (mail-header-from header))
5851 (name (cond
5852 ((string-match "(.+)" from)
5853 (substring from (1+ (match-beginning 0)) (1- (match-end 0))))
5854 ((string-match "<[^>]+> *$" from)
5855 (let ((beg (match-beginning 0)))
5856 (or (and (string-match "^\"[^\"]*\"" from)
5857 (substring from (1+ (match-beginning 0))
5858 (1- (match-end 0))))
5859 (substring from 0 beg))))
5860 (t from)))
5861 (subject (mail-header-subject header))
5862 (number (mail-header-number header))
5863 (opening-bracket (if dummy ?\< ?\[))
5864 (closing-bracket (if dummy ?\> ?\]))
5865 (buffer-read-only nil)
5866 (b (progn (beginning-of-line) (point))))
5867 (or (numberp lines) (setq lines 0))
5868 (insert (eval sformat))
5869 (add-text-properties
5870 b (1+ b) (list 'gnus-number number
5871 'gnus-mark (or unread gnus-unread-mark)
5872 'gnus-level level))))
5873
5874 (defun gnus-summary-update-line (&optional dont-update)
5875 ;; Update summary line after change.
5876 (or (not gnus-summary-default-score)
5877 gnus-summary-inhibit-highlight
5878 (let ((gnus-summary-inhibit-highlight t)
5879 (article (gnus-summary-article-number)))
5880 (progn
5881 (or dont-update
5882 (if (and gnus-summary-mark-below
5883 (< (gnus-summary-article-score)
5884 gnus-summary-mark-below))
5885 (and (not (memq article gnus-newsgroup-marked))
5886 (not (memq article gnus-newsgroup-dormant))
5887 (memq article gnus-newsgroup-unreads)
5888 (gnus-summary-mark-article-as-read gnus-low-score-mark))
5889 (and (eq (gnus-summary-article-mark) gnus-low-score-mark)
5890 (gnus-summary-mark-article-as-unread gnus-unread-mark))))
5891 (and gnus-visual
5892 (run-hooks 'gnus-summary-update-hook))))))
5893
5894 (defun gnus-summary-update-lines (&optional beg end)
5895 ;; Mark article as read (or not) by taking into account scores.
5896 (let ((beg (or beg (point-min)))
5897 (end (or end (point-max))))
5898 (if (or (not gnus-summary-default-score)
5899 gnus-summary-inhibit-highlight)
5900 ()
5901 (let ((gnus-summary-inhibit-highlight t)
5902 article)
5903 (save-excursion
5904 (set-buffer gnus-summary-buffer)
5905 (goto-char beg)
5906 (beginning-of-line)
5907 (while (and (not (eobp)) (< (point) end))
5908 (if (and gnus-summary-mark-below
5909 (< (or (cdr (assq
5910 (setq article (get-text-property
5911 (point) 'gnus-number))
5912 gnus-newsgroup-scored))
5913 gnus-summary-default-score 0)
5914 gnus-summary-mark-below))
5915 ;; We want to possibly mark it as read...
5916 (and (not (memq article gnus-newsgroup-marked))
5917 (not (memq article gnus-newsgroup-dormant))
5918 (memq article gnus-newsgroup-unreads)
5919 (gnus-summary-mark-article-as-read gnus-low-score-mark))
5920 ;; We want to possibly mark it as unread.
5921 (and (eq (get-text-property (point) 'gnus-mark)
5922 gnus-low-score-mark)
5923 (gnus-summary-mark-article-as-unread gnus-unread-mark)))
5924 ;; Do the visual highlights at the same time.
5925 (and gnus-visual (run-hooks 'gnus-summary-update-hook))
5926 (forward-line 1)))))))
5927
5928 (defvar gnus-tmp-gathered nil)
5929
5930 (defun gnus-summary-number-of-articles-in-thread (thread &optional char)
5931 ;; Sum up all elements (and sub-elements) in a list.
5932 (let* ((number
5933 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
5934 (if (and (consp thread) (cdr thread))
5935 (apply
5936 '+ 1 (mapcar
5937 'gnus-summary-number-of-articles-in-thread
5938 (cdr thread)))
5939 1)))
5940 (if char
5941 (if (> number 1) gnus-not-empty-thread-mark
5942 gnus-empty-thread-mark)
5943 number)))
5944
5945 (defun gnus-summary-read-group
5946 (group &optional show-all no-article kill-buffer)
5947 "Start reading news in newsgroup GROUP.
5948 If SHOW-ALL is non-nil, already read articles are also listed.
5949 If NO-ARTICLE is non-nil, no article is selected initially."
5950 (gnus-message 5 "Retrieving newsgroup: %s..." group)
5951 (let* ((new-group (gnus-summary-setup-buffer group))
5952 (quit-config (gnus-group-quit-config group))
5953 (did-select (and new-group (gnus-select-newsgroup group show-all))))
5954 (cond
5955 ((not new-group)
5956 (gnus-set-global-variables)
5957 (gnus-kill-buffer kill-buffer)
5958 (gnus-configure-windows 'summary 'force)
5959 (gnus-set-mode-line 'summary)
5960 (gnus-summary-position-cursor)
5961 (message "")
5962 t)
5963 ((null did-select)
5964 (and (eq major-mode 'gnus-summary-mode)
5965 (not (equal (current-buffer) kill-buffer))
5966 (progn
5967 (kill-buffer (current-buffer))
5968 (if (not quit-config)
5969 (progn
5970 (set-buffer gnus-group-buffer)
5971 (gnus-group-jump-to-group group)
5972 (gnus-group-next-unread-group 1))
5973 (if (not (buffer-name (car quit-config)))
5974 (gnus-configure-windows 'group 'force)
5975 (set-buffer (car quit-config))
5976 (and (eq major-mode 'gnus-summary-mode)
5977 (gnus-set-global-variables))
5978 (gnus-configure-windows (cdr quit-config))))))
5979 (message "Can't select group")
5980 nil)
5981 ((eq did-select 'quit)
5982 (and (eq major-mode 'gnus-summary-mode)
5983 (not (equal (current-buffer) kill-buffer))
5984 (kill-buffer (current-buffer)))
5985 (gnus-kill-buffer kill-buffer)
5986 (if (not quit-config)
5987 (progn
5988 (set-buffer gnus-group-buffer)
5989 (gnus-group-jump-to-group group)
5990 (gnus-group-next-unread-group 1)
5991 (gnus-configure-windows 'group 'force))
5992 (if (not (buffer-name (car quit-config)))
5993 (gnus-configure-windows 'group 'force)
5994 (set-buffer (car quit-config))
5995 (and (eq major-mode 'gnus-summary-mode)
5996 (gnus-set-global-variables))
5997 (gnus-configure-windows (cdr quit-config))))
5998 (signal 'quit nil))
5999 (t
6000 (gnus-set-global-variables)
6001 ;; Save the active value in effect when the group was entered.
6002 (setq gnus-newsgroup-active
6003 (gnus-copy-sequence
6004 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
6005 ;; You can change the subjects in this hook.
6006 (run-hooks 'gnus-select-group-hook)
6007 ;; Do score processing.
6008 (and gnus-use-scoring (gnus-possibly-score-headers))
6009 (gnus-update-format-specifications)
6010 ;; Generate the summary buffer.
6011 (gnus-summary-prepare)
6012 (if (zerop (buffer-size))
6013 (cond (gnus-newsgroup-dormant
6014 (gnus-summary-show-all-dormant))
6015 ((and gnus-newsgroup-scored show-all)
6016 (gnus-summary-show-all-expunged))))
6017 ;; Function `gnus-apply-kill-file' must be called in this hook.
6018 (run-hooks 'gnus-apply-kill-hook)
6019 (if (zerop (buffer-size))
6020 (progn
6021 ;; This newsgroup is empty.
6022 (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
6023 (gnus-message 6 "No unread news")
6024 (gnus-kill-buffer kill-buffer)
6025 nil)
6026 ;;(save-excursion
6027 ;; (if kill-buffer
6028 ;; (let ((gnus-summary-buffer kill-buffer))
6029 ;; (gnus-configure-windows 'group))))
6030 ;; Hide conversation thread subtrees. We cannot do this in
6031 ;; gnus-summary-prepare-hook since kill processing may not
6032 ;; work with hidden articles.
6033 (and gnus-show-threads
6034 gnus-thread-hide-subtree
6035 (gnus-summary-hide-all-threads))
6036 ;; Show first unread article if requested.
6037 (goto-char (point-min))
6038 (if (and (not no-article)
6039 gnus-auto-select-first
6040 (gnus-summary-first-unread-article))
6041 ()
6042 (gnus-configure-windows 'summary 'force))
6043 (gnus-set-mode-line 'summary)
6044 (gnus-summary-position-cursor)
6045 ;; If in async mode, we send some info to the backend.
6046 (and gnus-newsgroup-async
6047 (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
6048 (gnus-request-asynchronous
6049 gnus-newsgroup-name
6050 (if (and gnus-asynchronous-article-function
6051 (fboundp gnus-asynchronous-article-function))
6052 (funcall gnus-asynchronous-article-function
6053 gnus-newsgroup-threads)
6054 gnus-newsgroup-threads)))
6055 (gnus-kill-buffer kill-buffer)
6056 (if (not (get-buffer-window gnus-group-buffer))
6057 ()
6058 ;; gotta use windows, because recenter does weird stuff if
6059 ;; the current buffer ain't the displayed window.
6060 (let ((owin (selected-window)))
6061 (select-window (get-buffer-window gnus-group-buffer))
6062 (and (gnus-group-goto-group group)
6063 (recenter))
6064 (select-window owin))))
6065 t))))
6066
6067 (defun gnus-summary-prepare ()
6068 ;; Generate the summary buffer.
6069 (let ((buffer-read-only nil))
6070 (erase-buffer)
6071 (gnus-summary-prepare-threads
6072 (if gnus-show-threads
6073 (gnus-gather-threads
6074 (gnus-sort-threads
6075 (if (and gnus-summary-expunge-below
6076 (not gnus-fetch-old-headers))
6077 (gnus-make-threads-and-expunge)
6078 (gnus-make-threads))))
6079 gnus-newsgroup-headers)
6080 'cull)
6081 (gnus-summary-update-lines)
6082 ;; Create the header hashtb.
6083 (gnus-make-headers-hashtable-by-number)
6084 ;; Call hooks for modifying summary buffer.
6085 ;; Suggested by sven@tde.LTH.Se (Sven Mattisson).
6086 (goto-char (point-min))
6087 (run-hooks 'gnus-summary-prepare-hook)))
6088
6089 (defun gnus-gather-threads (threads)
6090 "Gather threads that have lost their roots."
6091 (if (not gnus-summary-make-false-root)
6092 threads
6093 (let ((hashtb (gnus-make-hashtable 1023))
6094 (prev threads)
6095 (result threads)
6096 subject hthread whole-subject)
6097 (while threads
6098 (setq whole-subject
6099 (setq subject (mail-header-subject (car (car threads)))))
6100 (if gnus-summary-gather-subject-limit
6101 (or (and (numberp gnus-summary-gather-subject-limit)
6102 (> (length subject) gnus-summary-gather-subject-limit)
6103 (setq subject
6104 (substring subject 0
6105 gnus-summary-gather-subject-limit)))
6106 (and (eq 'fuzzy gnus-summary-gather-subject-limit)
6107 (setq subject (gnus-simplify-subject-fuzzy subject))))
6108 (setq subject (gnus-simplify-subject-re subject)))
6109 (if (setq hthread
6110 (gnus-gethash subject hashtb))
6111 (progn
6112 (or (stringp (car (car hthread)))
6113 (setcar hthread (list whole-subject (car hthread))))
6114 (setcdr (car hthread) (nconc (cdr (car hthread))
6115 (list (car threads))))
6116 (setcdr prev (cdr threads))
6117 (setq threads prev))
6118 (gnus-sethash subject threads hashtb))
6119 (setq prev threads)
6120 (setq threads (cdr threads)))
6121 result)))
6122
6123 (defun gnus-make-threads ()
6124 ;; This function takes the dependencies already made by
6125 ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6126 ;; through the dependencies in the hash table and finds all the
6127 ;; roots. Roots do not refer back to any valid articles.
6128 (gnus-message 6 "Threading...")
6129 (let (roots new-roots)
6130 (and gnus-fetch-old-headers
6131 (eq gnus-headers-retrieved-by 'nov)
6132 (gnus-build-old-threads))
6133 (mapatoms
6134 (lambda (refs)
6135 (if (not (car (symbol-value refs)))
6136 (setq roots (append (cdr (symbol-value refs)) roots))
6137 ;; Ok, these refer back to valid articles, but if
6138 ;; `gnus-thread-ignore-subject' is nil, we have to check that
6139 ;; the root has the same subject as its children. The children
6140 ;; that do not are made into roots and removed from the list
6141 ;; of children.
6142 (or gnus-thread-ignore-subject
6143 (let* ((prev (symbol-value refs))
6144 (subject (gnus-simplify-subject-re
6145 (mail-header-subject (car prev))))
6146 (headers (cdr prev)))
6147 (while headers
6148 (if (not (string= subject
6149 (gnus-simplify-subject-re
6150 (mail-header-subject (car headers)))))
6151 (progn
6152 (setq new-roots (cons (car headers) new-roots))
6153 (setcdr prev (cdr headers)))
6154 (setq prev headers))
6155 (setq headers (cdr headers)))))))
6156 gnus-newsgroup-dependencies)
6157
6158 ;; We enter the new roots into the dependencies structure to
6159 ;; ensure that any possible later thread-regeneration will be
6160 ;; possible.
6161 (let ((r new-roots))
6162 (while r
6163 (gnus-sethash (concat (mail-header-id (car r)) ".boo")
6164 (list nil (car r)) gnus-newsgroup-dependencies)
6165 (setq r (cdr r))))
6166
6167 (setq roots (nconc new-roots roots))
6168
6169 (prog1
6170 (mapcar 'gnus-trim-thread
6171 (apply 'append
6172 (mapcar 'gnus-cut-thread
6173 (mapcar 'gnus-make-sub-thread roots))))
6174 (gnus-message 6 "Threading...done"))))
6175
6176
6177 (defun gnus-make-threads-and-expunge ()
6178 ;; This function takes the dependencies already made by
6179 ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6180 ;; through the dependencies in the hash table and finds all the
6181 ;; roots. Roots do not refer back to any valid articles.
6182 (gnus-message 6 "Threading...")
6183 (let ((default (or gnus-summary-default-score 0))
6184 (below gnus-summary-expunge-below)
6185 roots article new-roots)
6186 (and gnus-fetch-old-headers
6187 (eq gnus-headers-retrieved-by 'nov)
6188 (gnus-build-old-threads))
6189 (mapatoms
6190 (lambda (refs)
6191 (if (not (car (symbol-value refs)))
6192 ;; These articles do not refer back to any other articles -
6193 ;; they are roots.
6194 (let ((headers (cdr (symbol-value refs))))
6195 ;; We weed out the low-scored articles.
6196 (while headers
6197 (if (not (< (or (cdr (assq (mail-header-number (car headers))
6198 gnus-newsgroup-scored)) default)
6199 below))
6200 ;; It is over.
6201 (setq roots (cons (car headers) roots))
6202 ;; It is below, so we mark it as read.
6203 (setq gnus-newsgroup-unreads
6204 (delq (mail-header-number (car headers))
6205 gnus-newsgroup-unreads))
6206 (setq gnus-newsgroup-reads
6207 (cons (cons (mail-header-number (car headers))
6208 gnus-low-score-mark)
6209 gnus-newsgroup-reads)))
6210 (setq headers (cdr headers))))
6211 ;; Ok, these refer back to valid articles, but if
6212 ;; `gnus-thread-ignore-subject' is nil, we have to check that
6213 ;; the root has the same subject as its children. The children
6214 ;; that do not are made into roots and removed from the list
6215 ;; of children.
6216 (or gnus-thread-ignore-subject
6217 (let* ((prev (symbol-value refs))
6218 (subject (gnus-simplify-subject-re
6219 (mail-header-subject (car prev))))
6220 (headers (cdr prev)))
6221 (while headers
6222 (if (not (string= subject
6223 (gnus-simplify-subject-re
6224 (mail-header-subject (car headers)))))
6225 (progn
6226 (if (not (< (or (cdr (assq (mail-header-number
6227 (car headers))
6228 gnus-newsgroup-scored))
6229 default) below))
6230 (setq new-roots (cons (car headers) new-roots))
6231 (setq gnus-newsgroup-unreads
6232 (delq (mail-header-number (car headers))
6233 gnus-newsgroup-unreads))
6234 (setq gnus-newsgroup-reads
6235 (cons (cons (mail-header-number (car headers))
6236 gnus-low-score-mark)
6237 gnus-newsgroup-reads)))
6238 (setcdr prev (cdr headers)))
6239 (setq prev headers))
6240 (setq headers (cdr headers)))))
6241 ;; If this article is expunged, some of the children might be
6242 ;; roots.
6243 (if (< (or (cdr (assq (mail-header-number (car (symbol-value refs)))
6244 gnus-newsgroup-scored)) default)
6245 below)
6246 (let* ((prev (symbol-value refs))
6247 (headers (cdr prev)))
6248 (while headers
6249 (setq article (mail-header-number (car headers)))
6250 (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6251 default) below))
6252 (progn (setq new-roots (cons (car headers) new-roots))
6253 (setq prev headers))
6254 (setq gnus-newsgroup-unreads
6255 (delq article gnus-newsgroup-unreads))
6256 (setq gnus-newsgroup-reads
6257 (cons (cons article gnus-low-score-mark)
6258 gnus-newsgroup-reads))
6259 (setcdr prev (cdr headers)))
6260 (setq headers (cdr headers))))
6261 ;; It was not expunged, but we look at expunged children.
6262 (let* ((prev (symbol-value refs))
6263 (headers (cdr prev))
6264 article)
6265 (while headers
6266 (setq article (mail-header-number (car headers)))
6267 (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6268 default) below))
6269 (setq prev headers)
6270 (setq gnus-newsgroup-unreads
6271 (delq article gnus-newsgroup-unreads))
6272 (setq gnus-newsgroup-reads
6273 (cons (cons article gnus-low-score-mark)
6274 gnus-newsgroup-reads))
6275 (setcdr prev (cdr headers)))
6276 (setq headers (cdr headers)))))))
6277 gnus-newsgroup-dependencies)
6278
6279 ;; We enter the new roots into the dependencies structure to
6280 ;; ensure that any possible later thread-regeneration will be
6281 ;; possible.
6282 (let ((r new-roots))
6283 (while r
6284 (gnus-sethash (concat (mail-header-id (car r)) ".boo")
6285 (list nil (car r)) gnus-newsgroup-dependencies)
6286 (setq r (cdr r))))
6287
6288 (setq roots (nconc new-roots roots))
6289
6290 (prog1
6291 (mapcar 'gnus-trim-thread
6292 (apply 'append
6293 (mapcar 'gnus-cut-thread
6294 (mapcar 'gnus-make-sub-thread roots))))
6295 (gnus-message 6 "Threading...done"))))
6296
6297
6298 (defun gnus-cut-thread (thread)
6299 ;; Remove leaf dormant or ancient articles from THREAD.
6300 (let ((head (car thread))
6301 (tail (apply 'append (mapcar 'gnus-cut-thread (cdr thread)))))
6302 (if (and (null tail)
6303 (let ((number (mail-header-number head)))
6304 (or (memq number gnus-newsgroup-ancient)
6305 (memq number gnus-newsgroup-dormant)
6306 (and gnus-summary-expunge-below
6307 (eq gnus-fetch-old-headers 'some)
6308 (< (or (cdr (assq number gnus-newsgroup-scored))
6309 gnus-summary-default-score 0)
6310 gnus-summary-expunge-below)
6311 (progn
6312 (setq gnus-newsgroup-unreads
6313 (delq number gnus-newsgroup-unreads))
6314 (setq gnus-newsgroup-reads
6315 (cons (cons number gnus-low-score-mark)
6316 gnus-newsgroup-reads))
6317 t)))))
6318 nil
6319 (list (cons head tail)))))
6320
6321 (defun gnus-trim-thread (thread)
6322 ;; Remove root ancient articles with only one child from THREAD.
6323 (if (and (eq gnus-fetch-old-headers 'some)
6324 (memq (mail-header-number (car thread)) gnus-newsgroup-ancient)
6325 (= (length thread) 2))
6326 (gnus-trim-thread (nth 1 thread))
6327 thread))
6328
6329 (defun gnus-make-sub-thread (root)
6330 ;; This function makes a sub-tree for a node in the tree.
6331 (let ((children (reverse (cdr (gnus-gethash (downcase (mail-header-id root))
6332 gnus-newsgroup-dependencies)))))
6333 (cons root (mapcar 'gnus-make-sub-thread children))))
6334
6335 (defun gnus-build-old-threads ()
6336 ;; Look at all the articles that refer back to old articles, and
6337 ;; fetch the headers for the articles that aren't there. This will
6338 ;; build complete threads - if the roots haven't been expired by the
6339 ;; server, that is.
6340 (let (id heads)
6341 (mapatoms
6342 (lambda (refs)
6343 (if (not (car (symbol-value refs)))
6344 (progn
6345 (setq heads (cdr (symbol-value refs)))
6346 (while heads
6347 (if (not (memq (mail-header-number (car heads))
6348 gnus-newsgroup-dormant))
6349 (progn
6350 (setq id (symbol-name refs))
6351 (while (and (setq id (gnus-build-get-header id))
6352 (not (car (gnus-gethash
6353 id gnus-newsgroup-dependencies)))))
6354 (setq heads nil))
6355 (setq heads (cdr heads)))))))
6356 gnus-newsgroup-dependencies)))
6357
6358 (defun gnus-build-get-header (id)
6359 ;; Look through the buffer of NOV lines and find the header to
6360 ;; ID. Enter this line into the dependencies hash table, and return
6361 ;; the id of the parent article (if any).
6362 (let ((deps gnus-newsgroup-dependencies)
6363 found header)
6364 (prog1
6365 (save-excursion
6366 (set-buffer nntp-server-buffer)
6367 (goto-char (point-min))
6368 (while (and (not found) (search-forward id nil t))
6369 (beginning-of-line)
6370 (setq found (looking-at
6371 (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
6372 (regexp-quote id))))
6373 (or found (beginning-of-line 2)))
6374 (if found
6375 (let (ref)
6376 (beginning-of-line)
6377 (and
6378 (setq header (gnus-nov-parse-line
6379 (read (current-buffer)) deps))
6380 (setq ref (mail-header-references header))
6381 (string-match "\\(<[^>]+>\\) *$" ref)
6382 (substring ref (match-beginning 1) (match-end 1))))))
6383 (and header
6384 (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)
6385 gnus-newsgroup-ancient (cons (mail-header-number header)
6386 gnus-newsgroup-ancient))))))
6387
6388 ;; Re-build the thread containing ID.
6389 (defun gnus-rebuild-thread (id)
6390 (let ((dep gnus-newsgroup-dependencies)
6391 (buffer-read-only nil)
6392 parent headers refs thread art)
6393 (while (and id (setq headers
6394 (car (setq art (gnus-gethash (downcase id) dep)))))
6395 (setq parent art)
6396 (setq id (and (setq refs (mail-header-references headers))
6397 (string-match "\\(<[^>]+>\\) *$" refs)
6398 (substring refs (match-beginning 1) (match-end 1)))))
6399 (setq thread (gnus-make-sub-thread (car parent)))
6400 (gnus-rebuild-remove-articles thread)
6401 (let ((beg (point)))
6402 (gnus-summary-prepare-threads (list thread))
6403 (gnus-summary-update-lines beg (point)))))
6404
6405 ;; Delete all lines in the summary buffer that correspond to articles
6406 ;; in this thread.
6407 (defun gnus-rebuild-remove-articles (thread)
6408 (and (gnus-summary-goto-subject (mail-header-number (car thread)))
6409 (gnus-delete-line))
6410 (mapcar (lambda (th) (gnus-rebuild-remove-articles th)) (cdr thread)))
6411
6412 (defun gnus-sort-threads (threads)
6413 ;; Sort threads as specified in `gnus-thread-sort-functions'.
6414 (let ((fun gnus-thread-sort-functions))
6415 (while fun
6416 (gnus-message 6 "Sorting with %S..." fun)
6417 (setq threads (sort threads (car fun))
6418 fun (cdr fun))))
6419 (if gnus-thread-sort-functions
6420 (gnus-message 6 "Sorting...done"))
6421 threads)
6422
6423 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
6424 (defmacro gnus-thread-header (thread)
6425 ;; Return header of first article in THREAD.
6426 ;; Note that THREAD must never, evr be anything else than a variable -
6427 ;; using some other form will lead to serious barfage.
6428 (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
6429 ;; (8% speedup to gnus-summary-prepare, just for fun :-)
6430 (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ;
6431 (vector thread) 2))
6432
6433 (defun gnus-thread-sort-by-number (h1 h2)
6434 "Sort threads by root article number."
6435 (< (mail-header-number (gnus-thread-header h1))
6436 (mail-header-number (gnus-thread-header h2))))
6437
6438 (defun gnus-thread-sort-by-author (h1 h2)
6439 "Sort threads by root author."
6440 (string-lessp
6441 (let ((extract (funcall
6442 gnus-extract-address-components
6443 (mail-header-from (gnus-thread-header h1)))))
6444 (or (car extract) (cdr extract)))
6445 (let ((extract (funcall
6446 gnus-extract-address-components
6447 (mail-header-from (gnus-thread-header h2)))))
6448 (or (car extract) (cdr extract)))))
6449
6450 (defun gnus-thread-sort-by-subject (h1 h2)
6451 "Sort threads by root subject."
6452 (string-lessp
6453 (downcase (gnus-simplify-subject-re
6454 (mail-header-subject (gnus-thread-header h1))))
6455 (downcase (gnus-simplify-subject-re
6456 (mail-header-subject (gnus-thread-header h2))))))
6457
6458 (defun gnus-thread-sort-by-date (h1 h2)
6459 "Sort threads by root article date."
6460 (string-lessp
6461 (gnus-sortable-date (mail-header-date (gnus-thread-header h1)))
6462 (gnus-sortable-date (mail-header-date (gnus-thread-header h2)))))
6463
6464 (defun gnus-thread-sort-by-score (h1 h2)
6465 "Sort threads by root article score.
6466 Unscored articles will be counted as having a score of zero."
6467 (> (or (cdr (assq (mail-header-number (gnus-thread-header h1))
6468 gnus-newsgroup-scored))
6469 gnus-summary-default-score 0)
6470 (or (cdr (assq (mail-header-number (gnus-thread-header h2))
6471 gnus-newsgroup-scored))
6472 gnus-summary-default-score 0)))
6473
6474 (defun gnus-thread-sort-by-total-score (h1 h2)
6475 "Sort threads by the sum of all scores in the thread.
6476 Unscored articles will be counted as having a score of zero."
6477 (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
6478
6479 (defun gnus-thread-total-score (thread)
6480 ;; This function find the total score of THREAD.
6481 (if (consp thread)
6482 (if (stringp (car thread))
6483 (apply gnus-thread-score-function 0
6484 (mapcar 'gnus-thread-total-score-1 (cdr thread)))
6485 (gnus-thread-total-score-1 thread))
6486 (gnus-thread-total-score-1 (list thread))))
6487
6488 (defun gnus-thread-total-score-1 (root)
6489 ;; This function find the total score of the thread below ROOT.
6490 (setq root (car root))
6491 (apply gnus-thread-score-function
6492 (or (cdr (assq (mail-header-number root) gnus-newsgroup-scored))
6493 gnus-summary-default-score 0)
6494 (mapcar 'gnus-thread-total-score
6495 (cdr (gnus-gethash (downcase (mail-header-id root))
6496 gnus-newsgroup-dependencies)))))
6497
6498 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
6499 (defvar gnus-tmp-prev-subject "")
6500
6501 (defun gnus-summary-prepare-threads (threads &optional cull)
6502 "Prepare summary buffer from THREADS and indentation LEVEL.
6503 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
6504 or a straight list of headers."
6505 (message "Generating summary...")
6506 (let ((level 0)
6507 thread header number subject stack state gnus-tmp-gathered)
6508 (if (vectorp (car threads))
6509 ;; If this is a straight (sic) list of headers, then a
6510 ;; threaded summary display isn't required, so we just create
6511 ;; an unthreaded one.
6512 (gnus-summary-prepare-unthreaded threads cull)
6513
6514 ;; Do the threaded display.
6515
6516 (while (or threads stack)
6517
6518 (if threads
6519 ;; If there are some threads, we do them before the
6520 ;; threads on the stack.
6521 (setq thread threads
6522 header (car (car thread)))
6523 ;; There were no current threads, so we pop something off
6524 ;; the stack.
6525 (setq state (car stack)
6526 level (car state)
6527 thread (cdr state)
6528 stack (cdr stack)
6529 header (car (car thread))))
6530
6531 (if (stringp header)
6532 (progn
6533 ;; The header is a dummy root.
6534 (cond
6535 ((eq gnus-summary-make-false-root 'adopt)
6536 ;; We let the first article adopt the rest.
6537 (let ((th (car (cdr (car thread)))))
6538 (while (cdr th)
6539 (setq th (cdr th)))
6540 (setcdr th (cdr (cdr (car thread))))
6541 (setq gnus-tmp-gathered
6542 (nconc (mapcar
6543 (lambda (h) (mail-header-number (car h)))
6544 (cdr (cdr (car thread))))
6545 gnus-tmp-gathered))
6546 (setcdr (cdr (car thread)) nil))
6547 (setq level -1))
6548 ((eq gnus-summary-make-false-root 'empty)
6549 ;; We print adopted articles with empty subject fields.
6550 (setq gnus-tmp-gathered
6551 (nconc (mapcar
6552 (lambda (h) (mail-header-number (car h)))
6553 (cdr (cdr (car thread))))
6554 gnus-tmp-gathered))
6555 (setq level -1))
6556 ((eq gnus-summary-make-false-root 'dummy)
6557 ;; We output a dummy root.
6558 (gnus-summary-insert-dummy-line
6559 nil header (mail-header-number
6560 (car (car (cdr (car thread)))))))
6561 (t
6562 ;; We do not make a root for the gathered
6563 ;; sub-threads at all.
6564 (setq level -1))))
6565
6566 (setq number (mail-header-number header)
6567 subject (mail-header-subject header))
6568
6569 ;; Do the async thing.
6570 (and gnus-newsgroup-async
6571 (setq gnus-newsgroup-threads
6572 (cons (cons number (mail-header-lines header))
6573 gnus-newsgroup-threads)))
6574
6575 ;; We may have to root out some bad articles...
6576 (and cull
6577 (= level 0)
6578 (cond ((and (memq (setq number (mail-header-number header))
6579 gnus-newsgroup-dormant)
6580 (null thread))
6581 (setq header nil))
6582 ((and gnus-summary-expunge-below
6583 (< (or (cdr (assq number gnus-newsgroup-scored))
6584 gnus-summary-default-score 0)
6585 gnus-summary-expunge-below))
6586 (setq header nil)
6587 (setq gnus-newsgroup-unreads
6588 (delq number gnus-newsgroup-unreads))
6589 (setq gnus-newsgroup-reads
6590 (cons (cons number gnus-low-score-mark)
6591 gnus-newsgroup-reads)))))
6592
6593 (and
6594 header
6595 (progn
6596 (inline
6597 (gnus-summary-insert-line
6598 nil header level nil
6599 (cond
6600 ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6601 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6602 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6603 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6604 (t (or (cdr (assq number gnus-newsgroup-reads))
6605 gnus-ancient-mark)))
6606 (memq number gnus-newsgroup-replied)
6607 (memq number gnus-newsgroup-expirable)
6608 (cond
6609 ((and gnus-thread-ignore-subject
6610 (not (string=
6611 (gnus-simplify-subject-re gnus-tmp-prev-subject)
6612 (gnus-simplify-subject-re subject))))
6613 subject)
6614 ((zerop level)
6615 (if (and (eq gnus-summary-make-false-root 'empty)
6616 (memq number gnus-tmp-gathered))
6617 gnus-summary-same-subject
6618 subject))
6619 (t gnus-summary-same-subject))
6620 (and (eq gnus-summary-make-false-root 'adopt)
6621 (memq number gnus-tmp-gathered))
6622 (cdr (assq number gnus-newsgroup-scored))
6623 (memq number gnus-newsgroup-processable))
6624
6625 (setq gnus-tmp-prev-subject subject)))))
6626
6627 (if (nth 1 thread)
6628 (setq stack (cons (cons (max 0 level) (nthcdr 1 thread)) stack)))
6629 (setq level (1+ level))
6630 (setq threads (cdr (car thread))))))
6631 (message "Generating summary...done"))
6632
6633
6634
6635 (defun gnus-summary-prepare-unthreaded (headers &optional cull)
6636 (let (header number)
6637
6638 ;; Do the async thing, if that is required.
6639 (if gnus-newsgroup-async
6640 (setq gnus-newsgroup-threads
6641 (mapcar (lambda (h)
6642 (cons (mail-header-number h) (mail-header-lines h)))
6643 headers)))
6644
6645 (while headers
6646 (setq header (car headers)
6647 headers (cdr headers)
6648 number (mail-header-number header))
6649
6650 ;; We may have to root out some bad articles...
6651 (cond
6652 ((and cull
6653 (memq (setq number (mail-header-number header))
6654 gnus-newsgroup-dormant)))
6655 ((and cull gnus-summary-expunge-below
6656 (< (or (cdr (assq number gnus-newsgroup-scored))
6657 gnus-summary-default-score 0)
6658 gnus-summary-expunge-below))
6659 (setq gnus-newsgroup-unreads
6660 (delq number gnus-newsgroup-unreads))
6661 (setq gnus-newsgroup-reads
6662 (cons (cons number gnus-low-score-mark)
6663 gnus-newsgroup-reads)))
6664 (t
6665 (gnus-summary-insert-line
6666 nil header 0 nil
6667 (cond ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6668 ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6669 ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6670 ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6671 (t (or (cdr (assq number gnus-newsgroup-reads))
6672 gnus-ancient-mark)))
6673 (memq number gnus-newsgroup-replied)
6674 (memq number gnus-newsgroup-expirable)
6675 (mail-header-subject header) nil
6676 (cdr (assq number gnus-newsgroup-scored))
6677 (memq number gnus-newsgroup-processable)))))))
6678
6679 (defun gnus-select-newsgroup (group &optional read-all)
6680 "Select newsgroup GROUP.
6681 If READ-ALL is non-nil, all articles in the group are selected."
6682 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
6683 (info (nth 2 entry))
6684 articles)
6685
6686 (or (gnus-check-server
6687 (setq gnus-current-select-method (gnus-find-method-for-group group)))
6688 (error "Couldn't open server"))
6689
6690 (or (and entry (not (eq (car entry) t))) ; Either it's active...
6691 (gnus-activate-group group) ; Or we can activate it...
6692 (progn ; Or we bug out.
6693 (kill-buffer (current-buffer))
6694 (error "Couldn't request group %s: %s"
6695 group (gnus-status-message group))))
6696
6697 (setq gnus-newsgroup-name group)
6698 (setq gnus-newsgroup-unselected nil)
6699 (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
6700
6701 (and gnus-asynchronous
6702 (gnus-check-backend-function
6703 'request-asynchronous gnus-newsgroup-name)
6704 (setq gnus-newsgroup-async
6705 (gnus-request-asynchronous gnus-newsgroup-name)))
6706
6707 (setq articles (gnus-articles-to-read group read-all))
6708
6709 (cond
6710 ((null articles)
6711 (gnus-message 3 "Couldn't select newsgroup")
6712 'quit)
6713 ((eq articles 0) nil)
6714 (t
6715 ;; Init the dependencies hash table.
6716 (setq gnus-newsgroup-dependencies
6717 (gnus-make-hashtable (length articles)))
6718 ;; Retrieve the headers and read them in.
6719 (gnus-message 5 "Fetching headers...")
6720 (setq gnus-newsgroup-headers
6721 (if (eq 'nov (setq gnus-headers-retrieved-by
6722 ;; This is a naughty hack. To get the
6723 ;; retrieval of old headers to work, we
6724 ;; set `nntp-nov-gap' to nil (locally),
6725 ;; and then just retrieve the headers.
6726 ;; Mucho magic.
6727 (if gnus-fetch-old-headers
6728 (let (nntp-nov-gap)
6729 (gnus-retrieve-headers
6730 (if (not (eq 1 (car articles)))
6731 (cons 1 articles)
6732 articles)
6733 gnus-newsgroup-name))
6734 (gnus-retrieve-headers
6735 articles gnus-newsgroup-name))))
6736 (progn
6737 (gnus-get-newsgroup-headers-xover articles))
6738 ;; If we were to fetch old headers, but the backend didn't
6739 ;; support XOVER, then it is possible we fetched one article
6740 ;; that we shouldn't have. If that's the case, we remove it.
6741 (if (or (not gnus-fetch-old-headers)
6742 (eq 1 (car articles)))
6743 ()
6744 (save-excursion
6745 (set-buffer nntp-server-buffer)
6746 (goto-char (point-min))
6747 (and
6748 (looking-at "[0-9]+[ \t]+1[ \t]") ; This is not a NOV line.
6749 (delete-region ; So we delete this head.
6750 (point)
6751 (search-forward "\n.\n" nil t)))))
6752 (gnus-get-newsgroup-headers)))
6753 (gnus-message 5 "Fetching headers...done")
6754 ;; Remove canceled articles from the list of unread articles.
6755 (setq gnus-newsgroup-unreads
6756 (gnus-set-sorted-intersection
6757 gnus-newsgroup-unreads
6758 (mapcar (lambda (headers) (mail-header-number headers))
6759 gnus-newsgroup-headers)))
6760 ;; Adjust and set lists of article marks.
6761 (and info
6762 (let (marked)
6763 (gnus-adjust-marked-articles info)
6764 (setq gnus-newsgroup-marked
6765 (copy-sequence
6766 (cdr (assq 'tick (setq marked (nth 3 info))))))
6767 (setq gnus-newsgroup-replied
6768 (copy-sequence (cdr (assq 'reply marked))))
6769 (setq gnus-newsgroup-expirable
6770 (copy-sequence (cdr (assq 'expire marked))))
6771 (setq gnus-newsgroup-killed
6772 (copy-sequence (cdr (assq 'killed marked))))
6773 (setq gnus-newsgroup-bookmarks
6774 (copy-sequence (cdr (assq 'bookmark marked))))
6775 (setq gnus-newsgroup-dormant
6776 (copy-sequence (cdr (assq 'dormant marked))))
6777 (setq gnus-newsgroup-scored
6778 (copy-sequence (cdr (assq 'score marked))))
6779 (setq gnus-newsgroup-processable nil)))
6780 ;; Check whether auto-expire is to be done in this group.
6781 (setq gnus-newsgroup-auto-expire
6782 (or (and (stringp gnus-auto-expirable-newsgroups)
6783 (string-match gnus-auto-expirable-newsgroups group))
6784 (memq 'auto-expire (nth 5 info))))
6785 ;; First and last article in this newsgroup.
6786 (and gnus-newsgroup-headers
6787 (setq gnus-newsgroup-begin
6788 (mail-header-number (car gnus-newsgroup-headers)))
6789 (setq gnus-newsgroup-end
6790 (mail-header-number
6791 (gnus-last-element gnus-newsgroup-headers))))
6792 (setq gnus-reffed-article-number -1)
6793 ;; GROUP is successfully selected.
6794 (or gnus-newsgroup-headers t)))))
6795
6796 (defun gnus-articles-to-read (group read-all)
6797 ;; Find out what articles the user wants to read.
6798 (let* ((articles
6799 ;; Select all articles if `read-all' is non-nil, or if all the
6800 ;; unread articles are dormant articles.
6801 (if (or read-all
6802 (= (length gnus-newsgroup-unreads)
6803 (length gnus-newsgroup-dormant)))
6804 (gnus-uncompress-range
6805 (gnus-gethash group gnus-active-hashtb))
6806 gnus-newsgroup-unreads))
6807 (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
6808 (scored (length scored-list))
6809 (number (length articles))
6810 (marked (+ (length gnus-newsgroup-marked)
6811 (length gnus-newsgroup-dormant)))
6812 (select
6813 (cond
6814 ((numberp read-all)
6815 read-all)
6816 (t
6817 (condition-case ()
6818 (cond ((and (or (<= scored marked)
6819 (= scored number))
6820 (numberp gnus-large-newsgroup)
6821 (> number gnus-large-newsgroup))
6822 (let ((input
6823 (read-string
6824 (format
6825 "How many articles from %s (default %d): "
6826 gnus-newsgroup-name number))))
6827 (if (string-match "^[ \t]*$" input)
6828 number input)))
6829 ((and (> scored marked) (< scored number))
6830 (let ((input
6831 (read-string
6832 (format
6833 "%s %s (%d scored, %d total): "
6834 "How many articles from"
6835 group scored number))))
6836 (if (string-match "^[ \t]*$" input)
6837 number input)))
6838 (t number))
6839 (quit nil))))))
6840 (setq select (if (stringp select) (string-to-number select) select))
6841 (if (or (null select) (zerop select))
6842 select
6843 (if (and (not (zerop scored)) (<= (abs select) scored))
6844 (progn
6845 (setq articles (sort scored-list '<))
6846 (setq number (length articles)))
6847 (setq articles (copy-sequence articles)))
6848
6849 (if (< (abs select) number)
6850 (if (< select 0)
6851 ;; Select the N oldest articles.
6852 (setcdr (nthcdr (1- (abs select)) articles) nil)
6853 ;; Select the N most recent articles.
6854 (setq articles (nthcdr (- number select) articles))))
6855 (setq gnus-newsgroup-unselected
6856 (gnus-sorted-intersection
6857 gnus-newsgroup-unreads
6858 (gnus-sorted-complement gnus-newsgroup-unreads articles)))
6859 articles)))
6860
6861 (defun gnus-killed-articles (killed articles)
6862 (let (out)
6863 (while articles
6864 (if (inline (gnus-member-of-range (car articles) killed))
6865 (setq out (cons (car articles) out)))
6866 (setq articles (cdr articles)))
6867 out))
6868
6869 (defun gnus-adjust-marked-articles (info &optional active)
6870 "Remove all marked articles that are no longer legal."
6871 (let ((marked-lists (nth 3 info))
6872 (active (or active (gnus-gethash (car info) gnus-active-hashtb)))
6873 m prev)
6874 ;; There are many types of marked articles.
6875 (while marked-lists
6876 (setq m (cdr (setq prev (car marked-lists))))
6877 (cond ((or (eq 'tick (car prev)) (eq 'dormant (car prev)))
6878 ;; Make sure that all ticked articles are a subset of the
6879 ;; unread/unselected articles.
6880 ;;(while m
6881 ;; (if (or (memq (car m) gnus-newsgroup-unreads)
6882 ;; (memq (car m) gnus-newsgroup-unselected))
6883 ;; (setq prev m)
6884 ;; (setcdr prev (cdr m)))
6885 ;; (setq m (cdr m)))
6886 )
6887 ((eq 'score (car prev))
6888 ;; Scored articles should be a subset of
6889 ;; unread/unselected articles.
6890 (while m
6891 (if (or (memq (car (car m)) gnus-newsgroup-unreads)
6892 (memq (car (car m)) gnus-newsgroup-unreads))
6893 (setq prev m)
6894 (setcdr prev (cdr m)))
6895 (setq m (cdr m))))
6896 ((eq 'bookmark (car prev))
6897 ;; Bookmarks should be a subset of active articles.
6898 (while m
6899 (if (< (car (car m)) (car active))
6900 (setcdr prev (cdr m))
6901 (setq prev m))
6902 (setq m (cdr m))))
6903 ((eq 'killed (car prev))
6904 ;; Articles that have been through the kill process are
6905 ;; to be a subset of active articles.
6906 (while (and m (< (or (and (numberp (car m)) (car m))
6907 (cdr (car m)))
6908 (car active)))
6909 (setcdr prev (cdr m))
6910 (setq m (cdr m)))
6911 (if (and m (< (or (and (numberp (car m)) (car m))
6912 (car (car m)))
6913 (car active)))
6914 (setcar (if (numberp (car m)) m (car m)) (car active))))
6915 ((or (eq 'reply (car prev)) (eq 'expire (car prev)))
6916 ;; The replied and expirable articles have to be articles
6917 ;; that are active.
6918 (while m
6919 (if (< (car m) (car active))
6920 (setcdr prev (cdr m))
6921 (setq prev m))
6922 (setq m (cdr m)))))
6923 (setq marked-lists (cdr marked-lists)))
6924 ;; Remove all lists that are empty.
6925 (setq marked-lists (nth 3 info))
6926 (if marked-lists
6927 (progn
6928 (while (= 1 (length (car marked-lists)))
6929 (setq marked-lists (cdr marked-lists)))
6930 (setq m (cdr (setq prev marked-lists)))
6931 (while m
6932 (if (= 1 (length (car m)))
6933 (setcdr prev (cdr m))
6934 (setq prev m))
6935 (setq m (cdr m)))
6936 (setcar (nthcdr 3 info) marked-lists)))
6937 ;; Finally, if there are no marked lists at all left, and if there
6938 ;; are no elements after the lists in the info list, we just chop
6939 ;; the info list off before the marked lists.
6940 (and (null marked-lists)
6941 (not (nthcdr 4 info))
6942 (setcdr (nthcdr 2 info) nil)))
6943 info)
6944
6945 (defun gnus-set-marked-articles
6946 (info ticked replied expirable killed dormant bookmark score)
6947 "Enter the various lists of marked articles into the newsgroup info list."
6948 (let (newmarked)
6949 (and ticked (setq newmarked (cons (cons 'tick ticked) nil)))
6950 (and replied (setq newmarked (cons (cons 'reply replied) newmarked)))
6951 (and expirable (setq newmarked (cons (cons 'expire expirable)
6952 newmarked)))
6953 (and killed (setq newmarked (cons (cons 'killed killed) newmarked)))
6954 (and dormant (setq newmarked (cons (cons 'dormant dormant) newmarked)))
6955 (and bookmark (setq newmarked (cons (cons 'bookmark bookmark)
6956 newmarked)))
6957 (and score (setq newmarked (cons (cons 'score score) newmarked)))
6958 (if (nthcdr 3 info)
6959 (progn
6960 (setcar (nthcdr 3 info) newmarked)
6961 (and (not newmarked)
6962 (not (nthcdr 4 info))
6963 (setcdr (nthcdr 2 info) nil)))
6964 (if newmarked
6965 (setcdr (nthcdr 2 info) (list newmarked))))))
6966
6967 (defun gnus-add-marked-articles (group type articles &optional info force)
6968 ;; Add ARTICLES of TYPE to the info of GROUP.
6969 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
6970 ;; add, but replace marked articles of TYPE with ARTICLES.
6971 (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
6972 marked m)
6973 (or (not info)
6974 (and (not (setq marked (nthcdr 3 info)))
6975 (setcdr (nthcdr 2 info) (list (list (cons type articles)))))
6976 (and (not (setq m (assq type (car marked))))
6977 (setcar marked (cons (cons type articles) (car marked))))
6978 (if force
6979 (setcdr m articles)
6980 (nconc m articles)))))
6981
6982 (defun gnus-set-mode-line (where)
6983 "This function sets the mode line of the article or summary buffers.
6984 If WHERE is `summary', the summary mode line format will be used."
6985 (if (memq where gnus-updated-mode-lines)
6986 (let (mode-string)
6987 (save-excursion
6988 (set-buffer gnus-summary-buffer)
6989 (let* ((mformat (if (eq where 'article)
6990 gnus-article-mode-line-format-spec
6991 gnus-summary-mode-line-format-spec))
6992 (buffer-name (if (eq where 'article)
6993 (buffer-name
6994 (get-buffer gnus-article-buffer))
6995 (buffer-name)))
6996 (group-name gnus-newsgroup-name)
6997 (article-number (or gnus-current-article 0))
6998 (unread (- (length gnus-newsgroup-unreads)
6999 (length gnus-newsgroup-dormant)))
7000 (unread-and-unticked
7001 (- unread (length gnus-newsgroup-marked)))
7002 (unselected (length gnus-newsgroup-unselected))
7003 (unread-and-unselected
7004 (cond ((and (zerop unread-and-unticked)
7005 (zerop unselected)) "")
7006 ((zerop unselected)
7007 (format "{%d more}" unread-and-unticked))
7008 (t (format "{%d(+%d) more}"
7009 unread-and-unticked unselected))))
7010 (subject
7011 (if gnus-current-headers
7012 (mail-header-subject gnus-current-headers) ""))
7013 (max-len (and gnus-mode-non-string-length
7014 (- (frame-width) gnus-mode-non-string-length)))
7015 header);; passed as argument to any user-format-funcs
7016 (setq mode-string (eval mformat))
7017 (or (numberp max-len)
7018 (setq max-len (length mode-string)))
7019 (if (< max-len 4) (setq max-len 4))
7020 (if (> (length mode-string) max-len)
7021 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
7022 ;; function `substring' might cut on a middle
7023 ;; of multi-octet character.
7024 (setq mode-string
7025 (concat (gnus-truncate-string mode-string (- max-len 3))
7026 "...")))
7027 (setq mode-string (format (format "%%-%ds" max-len)
7028 mode-string))))
7029 (setq mode-line-buffer-identification mode-string)
7030 (set-buffer-modified-p t))))
7031
7032 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
7033 "Go through the HEADERS list and add all Xrefs to a hash table.
7034 The resulting hash table is returned, or nil if no Xrefs were found."
7035 (let* ((from-method (gnus-find-method-for-group from-newsgroup))
7036 (prefix (if (and
7037 (gnus-group-foreign-p from-newsgroup)
7038 (not (memq 'virtual
7039 (assoc (symbol-name (car from-method))
7040 gnus-valid-select-methods))))
7041 (gnus-group-real-prefix from-newsgroup)))
7042 (xref-hashtb (make-vector 63 0))
7043 start group entry number xrefs header)
7044 (while headers
7045 (setq header (car headers))
7046 (if (and (setq xrefs (mail-header-xref header))
7047 (not (memq (mail-header-number header) unreads)))
7048 (progn
7049 (setq start 0)
7050 (while (string-match "\\([^ ]+\\):\\([0-9]+\\)" xrefs start)
7051 (setq start (match-end 0))
7052 (setq group (concat prefix (substring xrefs (match-beginning 1)
7053 (match-end 1))))
7054 (setq number
7055 (string-to-int (substring xrefs (match-beginning 2)
7056 (match-end 2))))
7057 (if (setq entry (gnus-gethash group xref-hashtb))
7058 (setcdr entry (cons number (cdr entry)))
7059 (gnus-sethash group (cons number nil) xref-hashtb)))))
7060 (setq headers (cdr headers)))
7061 (if start xref-hashtb nil)))
7062
7063 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads expirable)
7064 "Look through all the headers and mark the Xrefs as read."
7065 (let ((virtual (memq 'virtual
7066 (assoc (symbol-name (car (gnus-find-method-for-group
7067 from-newsgroup)))
7068 gnus-valid-select-methods)))
7069 name entry info xref-hashtb idlist method
7070 nth4)
7071 (save-excursion
7072 (set-buffer gnus-group-buffer)
7073 (if (setq xref-hashtb
7074 (gnus-create-xref-hashtb from-newsgroup headers unreads))
7075 (mapatoms
7076 (lambda (group)
7077 (if (string= from-newsgroup (setq name (symbol-name group)))
7078 ()
7079 (setq idlist (symbol-value group))
7080 ;; Dead groups are not updated.
7081 (if (and (prog1
7082 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
7083 info (nth 2 entry))
7084 (if (stringp (setq nth4 (nth 4 info)))
7085 (setq nth4 (gnus-server-to-method nth4))))
7086 ;; Only do the xrefs if the group has the same
7087 ;; select method as the group we have just read.
7088 (or (gnus-methods-equal-p
7089 nth4 (gnus-find-method-for-group from-newsgroup))
7090 virtual
7091 (equal nth4
7092 (setq method (gnus-find-method-for-group
7093 from-newsgroup)))
7094 (and (equal (car nth4) (car method))
7095 (equal (nth 1 nth4) (nth 1 method))))
7096 gnus-use-cross-reference
7097 (or (not (eq gnus-use-cross-reference t))
7098 virtual
7099 ;; Only do cross-references on subscribed
7100 ;; groups, if that is what is wanted.
7101 (<= (nth 1 info) gnus-level-subscribed)))
7102 (gnus-group-make-articles-read name idlist expirable))))
7103 xref-hashtb)))))
7104
7105 (defun gnus-group-make-articles-read (group articles expirable)
7106 (let* ((num 0)
7107 (entry (gnus-gethash group gnus-newsrc-hashtb))
7108 (info (nth 2 entry))
7109 (active (gnus-gethash group gnus-active-hashtb))
7110 exps expirable range)
7111 ;; First peel off all illegal article numbers.
7112 (if active
7113 (let ((ids articles)
7114 (ticked (cdr (assq 'tick (nth 3 info))))
7115 (dormant (cdr (assq 'dormant (nth 3 info))))
7116 id first)
7117 (setq exps nil)
7118 (while ids
7119 (setq id (car ids))
7120 (if (and first (> id (cdr active)))
7121 (progn
7122 ;; We'll end up in this situation in one particular
7123 ;; obscure situation. If you re-scan a group and get
7124 ;; a new article that is cross-posted to a different
7125 ;; group that has not been re-scanned, you might get
7126 ;; crossposted article that has a higher number than
7127 ;; Gnus believes possible. So we re-activate this
7128 ;; group as well. This might mean doing the
7129 ;; crossposting thingy will *increase* the number
7130 ;; of articles in some groups. Tsk, tsk.
7131 (setq active (or (gnus-activate-group group) active))))
7132 (if (or (> id (cdr active))
7133 (< id (car active))
7134 (memq id ticked)
7135 (memq id dormant))
7136 (setq articles (delq id articles)))
7137 (and (memq id expirable)
7138 (setq exps (cons id exps)))
7139 (setq ids (cdr ids)))))
7140 ;; Update expirable articles.
7141 (gnus-add-marked-articles nil 'expirable exps info)
7142 (and active
7143 (null (nth 2 info))
7144 (> (car active) 1)
7145 (setcar (nthcdr 2 info) (cons 1 (1- (car active)))))
7146 (setcar (nthcdr 2 info)
7147 (setq range
7148 (gnus-add-to-range
7149 (nth 2 info)
7150 (setq articles (sort articles '<)))))
7151 ;; Then we have to re-compute how many unread
7152 ;; articles there are in this group.
7153 (if active
7154 (progn
7155 (cond
7156 ((not range)
7157 (setq num (- (1+ (cdr active)) (car active))))
7158 ((not (listp (cdr range)))
7159 (setq num (- (cdr active) (- (1+ (cdr range))
7160 (car range)))))
7161 (t
7162 (while range
7163 (if (numberp (car range))
7164 (setq num (1+ num))
7165 (setq num (+ num (- (1+ (cdr (car range)))
7166 (car (car range))))))
7167 (setq range (cdr range)))
7168 (setq num (- (cdr active) num))))
7169 ;; Update the number of unread articles.
7170 (setcar
7171 entry
7172 (max 0 (- num
7173 (length (cdr (assq 'tick (nth 3 info))))
7174 (length
7175 (cdr (assq 'dormant (nth 3 info)))))))
7176 ;; Update the group buffer.
7177 (gnus-group-update-group group t)))))
7178
7179 (defun gnus-methods-equal-p (m1 m2)
7180 (let ((m1 (or m1 gnus-select-method))
7181 (m2 (or m2 gnus-select-method)))
7182 (or (equal m1 m2)
7183 (and (eq (car m1) (car m2))
7184 (or (not (memq 'address (assoc (symbol-name (car m1))
7185 gnus-valid-select-methods)))
7186 (equal (nth 1 m1) (nth 1 m2)))))))
7187
7188 (defsubst gnus-header-value ()
7189 (buffer-substring (match-end 0) (gnus-point-at-eol)))
7190
7191 (defvar gnus-newsgroup-none-id 0)
7192
7193 (defun gnus-get-newsgroup-headers ()
7194 (setq gnus-article-internal-prepare-hook nil)
7195 (let ((cur nntp-server-buffer)
7196 (dependencies gnus-newsgroup-dependencies)
7197 headers id dep end ref)
7198 (save-excursion
7199 (set-buffer nntp-server-buffer)
7200 ;; Allow the user to mangle the headers before parsing them.
7201 (run-hooks 'gnus-parse-headers-hook)
7202 (goto-char (point-min))
7203 ;; Search to the beginning of the next header. Error messages
7204 ;; do not begin with 2 or 3.
7205 (while (re-search-forward "^[23][0-9]+ " nil t)
7206 (let ((header (make-vector 9 nil))
7207 (case-fold-search t)
7208 (p (point))
7209 in-reply-to)
7210 (setq id nil
7211 ref nil)
7212 (mail-header-set-number header (read cur))
7213 ;; This implementation of this function, with nine
7214 ;; search-forwards instead of the one re-search-forward and
7215 ;; a case (which basically was the old function) is actually
7216 ;; about twice as fast, even though it looks messier. You
7217 ;; can't have everything, I guess. Speed and elegance
7218 ;; doesn't always come hand in hand.
7219 (save-restriction
7220 (narrow-to-region (point) (or (save-excursion
7221 (search-forward "\n.\n" nil t))
7222 (point)))
7223 (if (search-forward "\nfrom: " nil t)
7224 (mail-header-set-from header (gnus-header-value))
7225 (mail-header-set-from header "(nobody)"))
7226 (goto-char p)
7227 (if (search-forward "\nsubject: " nil t)
7228 (mail-header-set-subject header (gnus-header-value))
7229 (mail-header-set-subject header "(none)"))
7230 (goto-char p)
7231 (and (search-forward "\nxref: " nil t)
7232 (mail-header-set-xref header (gnus-header-value)))
7233 (goto-char p)
7234 (or (numberp (and (search-forward "\nlines: " nil t)
7235 (mail-header-set-lines header (read cur))))
7236 (mail-header-set-lines header 0))
7237 (goto-char p)
7238 (and (search-forward "\ndate: " nil t)
7239 (mail-header-set-date header (gnus-header-value)))
7240 (goto-char p)
7241 (if (search-forward "\nmessage-id: " nil t)
7242 (mail-header-set-id header (setq id (gnus-header-value)))
7243 ;; If there was no message-id, we just fake one to make
7244 ;; subsequent routines simpler.
7245 (mail-header-set-id
7246 header
7247 (setq id (concat "none+"
7248 (int-to-string
7249 (setq gnus-newsgroup-none-id
7250 (1+ gnus-newsgroup-none-id)))))))
7251 (goto-char p)
7252 (if (search-forward "\nreferences: " nil t)
7253 (progn
7254 (mail-header-set-references header (gnus-header-value))
7255 (setq end (match-end 0))
7256 (save-excursion
7257 (setq ref
7258 (downcase
7259 (buffer-substring
7260 (progn
7261 (end-of-line)
7262 (search-backward ">" end t)
7263 (1+ (point)))
7264 (progn
7265 (search-backward "<" end t)
7266 (point)))))))
7267 ;; Get the references from the in-reply-to header if there
7268 ;; ware no references and the in-reply-to header looks
7269 ;; promising.
7270 (if (and (search-forward "\nin-reply-to: " nil t)
7271 (setq in-reply-to (gnus-header-value))
7272 (string-match "<[^>]+>" in-reply-to))
7273 (progn
7274 (mail-header-set-references
7275 header
7276 (setq ref (substring in-reply-to (match-beginning 0)
7277 (match-end 0))))
7278 (setq ref (downcase ref)))
7279 (setq ref "none")))
7280 ;; We do some threading while we read the headers. The
7281 ;; message-id and the last reference are both entered into
7282 ;; the same hash table. Some tippy-toeing around has to be
7283 ;; done in case an article has arrived before the article
7284 ;; which it refers to.
7285 (if (boundp (setq dep (intern (downcase id) dependencies)))
7286 (if (car (symbol-value dep))
7287 ;; An article with this Message-ID has already
7288 ;; been seen, so we ignore this one, except we add
7289 ;; any additional Xrefs (in case the two articles
7290 ;; came from different servers.
7291 (progn
7292 (mail-header-set-xref
7293 (car (symbol-value dep))
7294 (concat (or (mail-header-xref
7295 (car (symbol-value dep))) "")
7296 (or (mail-header-xref header) "")))
7297 (setq header nil))
7298 (setcar (symbol-value dep) header))
7299 (set dep (list header)))
7300 (if header
7301 (progn
7302 (if (boundp (setq dep (intern ref dependencies)))
7303 (setcdr (symbol-value dep)
7304 (cons header (cdr (symbol-value dep))))
7305 (set dep (list nil header)))
7306 (setq headers (cons header headers))))
7307 (goto-char (point-max))))))
7308 (nreverse headers)))
7309
7310 ;; The following macros and functions were written by Felix Lee
7311 ;; <flee@cse.psu.edu>.
7312
7313 (defmacro gnus-nov-read-integer ()
7314 '(prog1
7315 (if (= (following-char) ?\t)
7316 0
7317 (let ((num (condition-case nil (read buffer) (error nil))))
7318 (if (numberp num) num 0)))
7319 (or (eobp) (forward-char 1))))
7320
7321 (defmacro gnus-nov-skip-field ()
7322 '(search-forward "\t" eol 'move))
7323
7324 (defmacro gnus-nov-field ()
7325 '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
7326
7327 ;; Goes through the xover lines and returns a list of vectors
7328 (defun gnus-get-newsgroup-headers-xover (sequence)
7329 "Parse the news overview data in the server buffer, and return a
7330 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
7331 ;; Get the Xref when the users reads the articles since most/some
7332 ;; NNTP servers do not include Xrefs when using XOVER.
7333 (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
7334 (let ((cur nntp-server-buffer)
7335 (dependencies gnus-newsgroup-dependencies)
7336 number headers header)
7337 (save-excursion
7338 (set-buffer nntp-server-buffer)
7339 ;; Allow the user to mangle the headers before parsing them.
7340 (run-hooks 'gnus-parse-headers-hook)
7341 (goto-char (point-min))
7342 (while (and sequence (not (eobp)))
7343 (setq number (read cur))
7344 (while (and sequence (< (car sequence) number))
7345 (setq sequence (cdr sequence)))
7346 (and sequence
7347 (eq number (car sequence))
7348 (progn
7349 (setq sequence (cdr sequence))
7350 (if (setq header
7351 (inline (gnus-nov-parse-line number dependencies)))
7352 (setq headers (cons header headers)))))
7353 (forward-line 1))
7354 (setq headers (nreverse headers)))
7355 headers))
7356
7357 ;; This function has to be called with point after the article number
7358 ;; on the beginning of the line.
7359 (defun gnus-nov-parse-line (number dependencies)
7360 (let ((none 0)
7361 (eol (gnus-point-at-eol))
7362 (buffer (current-buffer))
7363 header ref id dep)
7364
7365 ;; overview: [num subject from date id refs chars lines misc]
7366 (narrow-to-region (point) eol)
7367 (or (eobp) (forward-char))
7368
7369 (condition-case nil
7370 (setq header
7371 (vector
7372 number ; number
7373 (gnus-nov-field) ; subject
7374 (gnus-nov-field) ; from
7375 (gnus-nov-field) ; date
7376 (setq id (or (gnus-nov-field)
7377 (concat "none+"
7378 (int-to-string
7379 (setq none (1+ none)))))) ; id
7380 (progn
7381 (save-excursion
7382 (let ((beg (point)))
7383 (search-forward "\t" eol)
7384 (if (search-backward ">" beg t)
7385 (setq ref
7386 (downcase
7387 (buffer-substring
7388 (1+ (point))
7389 (progn
7390 (search-backward "<" beg t)
7391 (point)))))
7392 (setq ref nil))))
7393 (gnus-nov-field)) ; refs
7394 (gnus-nov-read-integer) ; chars
7395 (gnus-nov-read-integer) ; lines
7396 (if (= (following-char) ?\n)
7397 nil
7398 (gnus-nov-field)) ; misc
7399 ))
7400 (error (progn
7401 (ding)
7402 (message "Strange nov line.")
7403 (setq header nil)
7404 (goto-char eol))))
7405
7406 (widen)
7407
7408 ;; We build the thread tree.
7409 (and header
7410 (if (boundp (setq dep (intern (downcase id) dependencies)))
7411 (if (car (symbol-value dep))
7412 ;; An article with this Message-ID has already been seen,
7413 ;; so we ignore this one, except we add any additional
7414 ;; Xrefs (in case the two articles came from different
7415 ;; servers.
7416 (progn
7417 (mail-header-set-xref
7418 (car (symbol-value dep))
7419 (concat (or (mail-header-xref (car (symbol-value dep))) "")
7420 (or (mail-header-xref header) "")))
7421 (setq header nil))
7422 (setcar (symbol-value dep) header))
7423 (set dep (list header))))
7424 (if header
7425 (progn
7426 (if (boundp (setq dep (intern (or ref "none")
7427 dependencies)))
7428 (setcdr (symbol-value dep)
7429 (cons header (cdr (symbol-value dep))))
7430 (set dep (list nil header)))))
7431 header))
7432
7433 (defun gnus-article-get-xrefs ()
7434 "Fill in the Xref value in `gnus-current-headers', if necessary.
7435 This is meant to be called in `gnus-article-internal-prepare-hook'."
7436 (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
7437 gnus-current-headers)))
7438 (or (not gnus-use-cross-reference)
7439 (not headers)
7440 (and (mail-header-xref headers)
7441 (not (string= (mail-header-xref headers) "")))
7442 (let ((case-fold-search t)
7443 xref)
7444 (save-restriction
7445 (gnus-narrow-to-headers)
7446 (goto-char (point-min))
7447 (if (or (and (eq (downcase (following-char)) ?x)
7448 (looking-at "Xref:"))
7449 (search-forward "\nXref:" nil t))
7450 (progn
7451 (goto-char (1+ (match-end 0)))
7452 (setq xref (buffer-substring (point)
7453 (progn (end-of-line) (point))))
7454 (mail-header-set-xref headers xref))))))))
7455
7456 (defalias 'gnus-find-header-by-number 'gnus-get-header-by-number)
7457 (make-obsolete 'gnus-find-header-by-number 'gnus-get-header-by-number)
7458
7459 (defun gnus-make-headers-hashtable-by-number ()
7460 "Make hashtable for the variable gnus-newsgroup-headers by number."
7461 (save-excursion
7462 (set-buffer gnus-summary-buffer)
7463 (let ((headers gnus-newsgroup-headers)
7464 header)
7465 (setq gnus-newsgroup-headers-hashtb-by-number
7466 (gnus-make-hashtable (length headers)))
7467 (while headers
7468 (setq header (car headers))
7469 (gnus-sethash (int-to-string (mail-header-number header))
7470 header gnus-newsgroup-headers-hashtb-by-number)
7471 (setq headers (cdr headers))))))
7472
7473 (defun gnus-more-header-backward ()
7474 "Find new header backward."
7475 (let ((first (car (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7476 (artnum gnus-newsgroup-begin)
7477 (header nil))
7478 (while (and (not header)
7479 (> artnum first))
7480 (setq artnum (1- artnum))
7481 (setq header (gnus-read-header artnum)))
7482 header))
7483
7484 (defun gnus-more-header-forward (&optional backward)
7485 "Find new header forward.
7486 If BACKWARD, find new header backward instead."
7487 (if backward
7488 (gnus-more-header-backward)
7489 (let ((last (cdr (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7490 (artnum gnus-newsgroup-end)
7491 (header nil))
7492 (while (and (not header)
7493 (< artnum last))
7494 (setq artnum (1+ artnum))
7495 (setq header (gnus-read-header artnum)))
7496 header)))
7497
7498 (defun gnus-extend-newsgroup (header &optional backward)
7499 "Extend newsgroup selection with HEADER.
7500 Optional argument BACKWARD means extend toward backward."
7501 (if header
7502 (let ((artnum (mail-header-number header)))
7503 (setq gnus-newsgroup-headers
7504 (if backward
7505 (cons header gnus-newsgroup-headers)
7506 (nconc gnus-newsgroup-headers (list header))))
7507 (setq gnus-newsgroup-unselected
7508 (delq artnum gnus-newsgroup-unselected))
7509 (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum))
7510 (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum)))))
7511
7512 (defun gnus-summary-work-articles (n)
7513 "Return a list of articles to be worked upon. The prefix argument,
7514 the list of process marked articles, and the current article will be
7515 taken into consideration."
7516 (let (articles)
7517 (if (and n (numberp n))
7518 (let ((backward (< n 0))
7519 (n (abs n)))
7520 (save-excursion
7521 (while (and (> n 0)
7522 (setq articles (cons (gnus-summary-article-number)
7523 articles))
7524 (gnus-summary-search-forward nil nil backward))
7525 (setq n (1- n))))
7526 (sort articles (function <)))
7527 (or (reverse gnus-newsgroup-processable)
7528 (list (gnus-summary-article-number))))))
7529
7530 (defun gnus-summary-search-group (&optional backward use-level)
7531 "Search for next unread newsgroup.
7532 If optional argument BACKWARD is non-nil, search backward instead."
7533 (save-excursion
7534 (set-buffer gnus-group-buffer)
7535 (if (gnus-group-search-forward
7536 backward nil (if use-level (gnus-group-group-level) nil))
7537 (gnus-group-group-name))))
7538
7539 (defun gnus-summary-best-group (&optional exclude-group)
7540 "Find the name of the best unread group.
7541 If EXCLUDE-GROUP, do not go to this group."
7542 (save-excursion
7543 (set-buffer gnus-group-buffer)
7544 (save-excursion
7545 (gnus-group-best-unread-group exclude-group))))
7546
7547 (defun gnus-subject-equal (s1 s2)
7548 (cond
7549 ((null gnus-summary-gather-subject-limit)
7550 (equal (gnus-simplify-subject-re s1)
7551 (gnus-simplify-subject-re s2)))
7552 ((eq gnus-summary-gather-subject-limit 'fuzzy)
7553 (equal (gnus-simplify-subject-fuzzy s1)
7554 (gnus-simplify-subject-fuzzy s2)))
7555 ((numberp gnus-summary-gather-subject-limit)
7556 (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit)
7557 (gnus-limit-string s2 gnus-summary-gather-subject-limit)))
7558 (t
7559 (equal s1 s2))))
7560
7561 (defun gnus-summary-search-subject (&optional backward unread subject)
7562 "Search for article forward.
7563 If BACKWARD is non-nil, search backward.
7564 If UNREAD is non-nil, only unread articles are selected.
7565 If SUBJECT is non-nil, the article which has the same subject will be
7566 searched for."
7567 (let ((func (if backward 'previous-single-property-change
7568 'next-single-property-change))
7569 (beg (point))
7570 (did t)
7571 pos psubject)
7572 (beginning-of-line)
7573 (and gnus-summary-check-current unread
7574 (eq (get-text-property (point) 'gnus-mark) gnus-unread-mark)
7575 (setq did nil))
7576 (if (not did)
7577 ()
7578 (forward-char (if backward (if (bobp) 0 -1) (if (eobp) 0 1)))
7579 (while
7580 (and
7581 (setq pos (funcall func (point) 'gnus-number))
7582 (goto-char (if backward (1- pos) pos))
7583 (setq did
7584 (not (and
7585 (or (not unread)
7586 (eq (get-text-property (point) 'gnus-mark)
7587 gnus-unread-mark))
7588 (or (not subject)
7589 (and (setq psubject
7590 (inline (gnus-summary-subject-string)))
7591 (inline
7592 (gnus-subject-equal subject psubject)))))))
7593 (if backward (if (bobp) nil (forward-char -1) t)
7594 (if (eobp) nil (forward-char 1) t)))))
7595 (if did
7596 (progn (goto-char beg) nil)
7597 (prog1
7598 (get-text-property (point) 'gnus-number)
7599 (gnus-summary-show-thread)
7600 (gnus-summary-position-cursor)))))
7601
7602 (defun gnus-summary-pseudo-article ()
7603 "The thread level of the article on the current line."
7604 (get-text-property (gnus-point-at-bol) 'gnus-pseudo))
7605
7606 (defalias 'gnus-summary-score 'gnus-summary-article-score)
7607 (make-obsolete 'gnus-summary-score 'gnus-summary-article-score)
7608 (defun gnus-summary-article-score ()
7609 "Return current article score."
7610 (or (cdr (assq (gnus-summary-article-number) gnus-newsgroup-scored))
7611 gnus-summary-default-score 0))
7612
7613 (defun gnus-summary-recenter ()
7614 "Center point in the summary window.
7615 If `gnus-auto-center-summary' is nil, or the article buffer isn't
7616 displayed, no centering will be performed."
7617 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
7618 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
7619 (let* ((top (cond ((< (window-height) 4) 0)
7620 ((< (window-height) 7) 1)
7621 (t 2)))
7622 (height (1- (window-height)))
7623 (bottom (save-excursion (goto-char (point-max))
7624 (forward-line (- height))
7625 (point)))
7626 (window (get-buffer-window (current-buffer))))
7627 (and
7628 ;; The user has to want it,
7629 gnus-auto-center-summary
7630 ;; the article buffer must be displayed,
7631 (get-buffer-window gnus-article-buffer)
7632 ;; Set the window start to either `bottom', which is the biggest
7633 ;; possible valid number, or the second line from the top,
7634 ;; whichever is the least.
7635 (set-window-start
7636 window (min bottom (save-excursion (forward-line (- top)) (point)))))))
7637
7638 ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
7639 (defun gnus-short-group-name (group &optional levels)
7640 "Collapse GROUP name LEVELS."
7641 (let* ((name "") (foreign "") (depth -1) (skip 1)
7642 (levels (or levels
7643 (progn
7644 (while (string-match "\\." group skip)
7645 (setq skip (match-end 0)
7646 depth (+ depth 1)))
7647 depth))))
7648 (if (string-match ":" group)
7649 (setq foreign (substring group 0 (match-end 0))
7650 group (substring group (match-end 0))))
7651 (while group
7652 (if (and (string-match "\\." group) (> levels 0))
7653 (setq name (concat name (substring group 0 1))
7654 group (substring group (match-end 0))
7655 levels (- levels 1)
7656 name (concat name "."))
7657 (setq name (concat foreign name group)
7658 group nil)))
7659 name))
7660
7661 (defun gnus-summary-jump-to-group (newsgroup)
7662 "Move point to NEWSGROUP in group mode buffer."
7663 ;; Keep update point of group mode buffer if visible.
7664 (if (eq (current-buffer) (get-buffer gnus-group-buffer))
7665 (save-window-excursion
7666 ;; Take care of tree window mode.
7667 (if (get-buffer-window gnus-group-buffer)
7668 (pop-to-buffer gnus-group-buffer))
7669 (gnus-group-jump-to-group newsgroup))
7670 (save-excursion
7671 ;; Take care of tree window mode.
7672 (if (get-buffer-window gnus-group-buffer)
7673 (pop-to-buffer gnus-group-buffer)
7674 (set-buffer gnus-group-buffer))
7675 (gnus-group-jump-to-group newsgroup))))
7676
7677 ;; This function returns a list of article numbers based on the
7678 ;; difference between the ranges of read articles in this group and
7679 ;; the range of active articles.
7680 (defun gnus-list-of-unread-articles (group)
7681 (let* ((read (nth 2 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
7682 (active (gnus-gethash group gnus-active-hashtb))
7683 (last (cdr active))
7684 first nlast unread)
7685 ;; If none are read, then all are unread.
7686 (if (not read)
7687 (setq first (car active))
7688 ;; If the range of read articles is a single range, then the
7689 ;; first unread article is the article after the last read
7690 ;; article. Sounds logical, doesn't it?
7691 (if (not (listp (cdr read)))
7692 (setq first (1+ (cdr read)))
7693 ;; `read' is a list of ranges.
7694 (if (/= (setq nlast (or (and (numberp (car read)) (car read))
7695 (car (car read)))) 1)
7696 (setq first 1))
7697 (while read
7698 (if first
7699 (while (< first nlast)
7700 (setq unread (cons first unread))
7701 (setq first (1+ first))))
7702 (setq first (1+ (if (atom (car read)) (car read) (cdr (car read)))))
7703 (setq nlast (if (atom (car (cdr read)))
7704 (car (cdr read))
7705 (car (car (cdr read)))))
7706 (setq read (cdr read)))))
7707 ;; And add the last unread articles.
7708 (while (<= first last)
7709 (setq unread (cons first unread))
7710 (setq first (1+ first)))
7711 ;; Return the list of unread articles.
7712 (nreverse unread)))
7713
7714 (defun gnus-list-of-read-articles (group)
7715 (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
7716 (active (gnus-gethash group gnus-active-hashtb)))
7717 (and info active
7718 (gnus-sorted-complement
7719 (gnus-uncompress-range active)
7720 (gnus-list-of-unread-articles group)))))
7721
7722 ;; Various summary commands
7723
7724 (defun gnus-summary-universal-argument ()
7725 "Perform any operation on all articles marked with the process mark."
7726 (interactive)
7727 (gnus-set-global-variables)
7728 (let ((articles (reverse gnus-newsgroup-processable))
7729 func)
7730 (or articles (error "No articles marked"))
7731 (or (setq func (key-binding (read-key-sequence "C-c C-u")))
7732 (error "Undefined key"))
7733 (while articles
7734 (gnus-summary-goto-subject (car articles))
7735 (command-execute func)
7736 (gnus-summary-remove-process-mark (car articles))
7737 (setq articles (cdr articles)))))
7738
7739 (defun gnus-summary-toggle-truncation (&optional arg)
7740 "Toggle truncation of summary lines.
7741 With arg, turn line truncation on iff arg is positive."
7742 (interactive "P")
7743 (setq truncate-lines
7744 (if (null arg) (not truncate-lines)
7745 (> (prefix-numeric-value arg) 0)))
7746 (redraw-display))
7747
7748 (defun gnus-summary-reselect-current-group (&optional all)
7749 "Once exit and then reselect the current newsgroup.
7750 The prefix argument ALL means to select all articles."
7751 (interactive "P")
7752 (gnus-set-global-variables)
7753 (let ((current-subject (gnus-summary-article-number))
7754 (group gnus-newsgroup-name))
7755 (setq gnus-newsgroup-begin nil)
7756 (gnus-summary-exit t)
7757 ;; We have to adjust the point of group mode buffer because the
7758 ;; current point was moved to the next unread newsgroup by
7759 ;; exiting.
7760 (gnus-summary-jump-to-group group)
7761 (gnus-group-read-group all t)
7762 (gnus-summary-goto-subject current-subject)))
7763
7764 (defun gnus-summary-rescan-group (&optional all)
7765 "Exit the newsgroup, ask for new articles, and select the newsgroup."
7766 (interactive "P")
7767 (gnus-set-global-variables)
7768 ;; Fix by Ilja Weis <kult@uni-paderborn.de>.
7769 (let ((group gnus-newsgroup-name))
7770 (gnus-summary-exit)
7771 (gnus-summary-jump-to-group group)
7772 (save-excursion
7773 (set-buffer gnus-group-buffer)
7774 (gnus-group-get-new-news-this-group 1))
7775 (gnus-summary-jump-to-group group)
7776 (gnus-group-read-group all)))
7777
7778 (defun gnus-summary-update-info ()
7779 (let* ((group gnus-newsgroup-name))
7780 (if gnus-newsgroup-kill-headers
7781 (setq gnus-newsgroup-killed
7782 (gnus-compress-sequence
7783 (nconc
7784 (gnus-set-sorted-intersection
7785 (gnus-uncompress-range gnus-newsgroup-killed)
7786 (setq gnus-newsgroup-unselected
7787 (sort gnus-newsgroup-unselected '<)))
7788 (setq gnus-newsgroup-unreads
7789 (sort gnus-newsgroup-unreads '<))) t)))
7790 (or (listp (cdr gnus-newsgroup-killed))
7791 (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7792 (let ((headers gnus-newsgroup-headers))
7793 (gnus-close-group group)
7794 (run-hooks 'gnus-exit-group-hook)
7795 (gnus-update-read-articles
7796 group gnus-newsgroup-unreads gnus-newsgroup-unselected
7797 gnus-newsgroup-marked
7798 t gnus-newsgroup-replied gnus-newsgroup-expirable
7799 gnus-newsgroup-killed gnus-newsgroup-dormant
7800 gnus-newsgroup-bookmarks
7801 (and gnus-save-score gnus-newsgroup-scored))
7802 (and gnus-use-cross-reference
7803 (gnus-mark-xrefs-as-read
7804 group headers gnus-newsgroup-unreads gnus-newsgroup-expirable))
7805 ;; Do adaptive scoring, and possibly save score files.
7806 (and gnus-newsgroup-adaptive
7807 (gnus-score-adaptive))
7808 (and gnus-use-scoring
7809 (fboundp 'gnus-score-save)
7810 (funcall 'gnus-score-save))
7811 ;; Do not switch windows but change the buffer to work.
7812 (set-buffer gnus-group-buffer)
7813 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
7814 (gnus-group-update-group group)))))
7815
7816 (defun gnus-summary-exit (&optional temporary)
7817 "Exit reading current newsgroup, and then return to group selection mode.
7818 gnus-exit-group-hook is called with no arguments if that value is non-nil."
7819 (interactive)
7820 (gnus-set-global-variables)
7821 (gnus-kill-save-kill-buffer)
7822 (let* ((group gnus-newsgroup-name)
7823 (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7824 (mode major-mode)
7825 (buf (current-buffer)))
7826 (run-hooks 'gnus-summary-prepare-exit-hook)
7827 ;; Make all changes in this group permanent.
7828 (gnus-summary-update-info)
7829 (set-buffer buf)
7830 (and gnus-use-cache (gnus-cache-possibly-remove-articles))
7831 ;; Make sure where I was, and go to next newsgroup.
7832 (set-buffer gnus-group-buffer)
7833 (or quit-config
7834 (progn
7835 (gnus-group-jump-to-group group)
7836 (gnus-group-next-unread-group 1)))
7837 (if temporary
7838 nil ;Nothing to do.
7839 ;; We set all buffer-local variables to nil. It is unclear why
7840 ;; this is needed, but if we don't, buffer-local variables are
7841 ;; not garbage-collected, it seems. This would the lead to en
7842 ;; ever-growing Emacs.
7843 (set-buffer buf)
7844 (gnus-summary-clear-local-variables)
7845 ;; We clear the global counterparts of the buffer-local
7846 ;; variables as well, just to be on the safe side.
7847 (gnus-configure-windows 'group 'force)
7848 (gnus-summary-clear-local-variables)
7849 ;; Return to group mode buffer.
7850 (if (eq mode 'gnus-summary-mode)
7851 (gnus-kill-buffer buf))
7852 (if (get-buffer gnus-article-buffer)
7853 (bury-buffer gnus-article-buffer))
7854 (setq gnus-current-select-method gnus-select-method)
7855 (pop-to-buffer gnus-group-buffer)
7856 (if (not quit-config)
7857 (progn
7858 (gnus-group-jump-to-group group)
7859 (gnus-group-next-unread-group 1))
7860 (if (not (buffer-name (car quit-config)))
7861 (gnus-configure-windows 'group 'force)
7862 (set-buffer (car quit-config))
7863 (and (eq major-mode 'gnus-summary-mode)
7864 (gnus-set-global-variables))
7865 (gnus-configure-windows (cdr quit-config))))
7866 (run-hooks 'gnus-summary-exit-hook))))
7867
7868 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7869 (defun gnus-summary-exit-no-update (&optional no-questions)
7870 "Quit reading current newsgroup without updating read article info."
7871 (interactive)
7872 (gnus-set-global-variables)
7873 (let* ((group gnus-newsgroup-name)
7874 (quit-config (gnus-group-quit-config group)))
7875 (if (or no-questions
7876 gnus-expert-user
7877 (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
7878 (progn
7879 (gnus-close-group group)
7880 (gnus-summary-clear-local-variables)
7881 (set-buffer gnus-group-buffer)
7882 (gnus-summary-clear-local-variables)
7883 ;; Return to group selection mode.
7884 (gnus-configure-windows 'group 'force)
7885 (if (get-buffer gnus-summary-buffer)
7886 (kill-buffer gnus-summary-buffer))
7887 (if (get-buffer gnus-article-buffer)
7888 (bury-buffer gnus-article-buffer))
7889 (if (equal (gnus-group-group-name) group)
7890 (gnus-group-next-unread-group 1))
7891 (if quit-config
7892 (progn
7893 (if (not (buffer-name (car quit-config)))
7894 (gnus-configure-windows 'group 'force)
7895 (set-buffer (car quit-config))
7896 (and (eq major-mode 'gnus-summary-mode)
7897 (gnus-set-global-variables))
7898 (gnus-configure-windows (cdr quit-config)))))))))
7899
7900 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7901 (defun gnus-summary-fetch-faq (group)
7902 "Fetch the FAQ for the current group."
7903 (interactive (list gnus-newsgroup-name))
7904 (let (gnus-faq-buffer)
7905 (and (setq gnus-faq-buffer (gnus-group-fetch-faq group))
7906 (gnus-configure-windows 'summary-faq))))
7907
7908 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7909 (defun gnus-summary-describe-group (&optional force)
7910 "Describe the current newsgroup."
7911 (interactive "P")
7912 (gnus-group-describe-group force gnus-newsgroup-name))
7913
7914 (defun gnus-summary-describe-briefly ()
7915 "Describe summary mode commands briefly."
7916 (interactive)
7917 (gnus-message 6
7918 (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")))
7919
7920 ;; Walking around group mode buffer from summary mode.
7921
7922 (defun gnus-summary-next-group (&optional no-article target-group backward)
7923 "Exit current newsgroup and then select next unread newsgroup.
7924 If prefix argument NO-ARTICLE is non-nil, no article is selected
7925 initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
7926 previous group instead."
7927 (interactive "P")
7928 (gnus-set-global-variables)
7929 (let ((current-group gnus-newsgroup-name)
7930 (current-buffer (current-buffer))
7931 entered)
7932 ;; First we semi-exit this group to update Xrefs and all variables.
7933 ;; We can't do a real exit, because the window conf must remain
7934 ;; the same in case the user is prompted for info, and we don't
7935 ;; want the window conf to change before that...
7936 (gnus-summary-exit t)
7937 (while (not entered)
7938 ;; Then we find what group we are supposed to enter.
7939 (set-buffer gnus-group-buffer)
7940 (gnus-group-jump-to-group current-group)
7941 (setq target-group
7942 (or target-group
7943 (if (eq gnus-keep-same-level 'best)
7944 (gnus-summary-best-group gnus-newsgroup-name)
7945 (gnus-summary-search-group backward gnus-keep-same-level))))
7946 (if (not target-group)
7947 ;; There are no further groups, so we return to the group
7948 ;; buffer.
7949 (progn
7950 (gnus-message 5 "Returning to the group buffer")
7951 (setq entered t)
7952 (set-buffer current-buffer)
7953 (gnus-summary-exit))
7954 ;; We try to enter the target group.
7955 (gnus-group-jump-to-group target-group)
7956 (let ((unreads (gnus-group-group-unread)))
7957 (if (and (or (eq t unreads)
7958 (and unreads (not (zerop unreads))))
7959 (gnus-summary-read-group
7960 target-group nil no-article current-buffer))
7961 (setq entered t)
7962 (setq current-group target-group
7963 target-group nil)))))))
7964
7965 (defun gnus-summary-next-group-old (&optional no-article group backward)
7966 "Exit current newsgroup and then select next unread newsgroup.
7967 If prefix argument NO-ARTICLE is non-nil, no article is selected initially.
7968 If BACKWARD, go to previous group instead."
7969 (interactive "P")
7970 (gnus-set-global-variables)
7971 (let ((ingroup gnus-newsgroup-name)
7972 (sumbuf (current-buffer))
7973 num)
7974 (set-buffer gnus-group-buffer)
7975 (if (and group
7976 (or (and (numberp (setq num (car (gnus-gethash
7977 group gnus-newsrc-hashtb))))
7978 (< num 1))
7979 (null num)))
7980 (progn
7981 (gnus-group-jump-to-group group)
7982 (setq group nil))
7983 (gnus-group-jump-to-group ingroup))
7984 (gnus-summary-search-group backward)
7985 (let ((group (or group (gnus-summary-search-group backward))))
7986 (set-buffer sumbuf)
7987 (gnus-summary-exit t) ;Update all information.
7988 (if (null group)
7989 (gnus-summary-exit-no-update t)
7990 (gnus-group-jump-to-group ingroup)
7991 (setq group (gnus-summary-search-group backward))
7992 (gnus-message 5 "Selecting %s..." group)
7993 (set-buffer gnus-group-buffer)
7994 ;; We are now in group mode buffer.
7995 ;; Make sure group mode buffer point is on GROUP.
7996 (gnus-group-jump-to-group group)
7997 (if (not (eq gnus-auto-select-next 'quietly))
7998 (progn
7999 (gnus-summary-read-group group nil no-article sumbuf)
8000 (and (string= gnus-newsgroup-name ingroup)
8001 (bufferp sumbuf) (buffer-name sumbuf)
8002 (progn
8003 (set-buffer (setq gnus-summary-buffer sumbuf))
8004 (gnus-summary-exit-no-update t))))
8005 (let ((prevgroup group))
8006 (gnus-group-jump-to-group ingroup)
8007 (setq group (gnus-summary-search-group backward))
8008 (gnus-summary-read-group group nil no-article sumbuf)
8009 (while (and (string= gnus-newsgroup-name ingroup)
8010 (bufferp sumbuf)
8011 (buffer-name sumbuf)
8012 (not (string= prevgroup (gnus-group-group-name))))
8013 (set-buffer gnus-group-buffer)
8014 (gnus-summary-read-group
8015 (setq prevgroup (gnus-group-group-name))
8016 nil no-article sumbuf))
8017 (and (string= prevgroup (gnus-group-group-name))
8018 ;; We have reached the final group in the group
8019 ;; buffer.
8020 (progn
8021 (if (buffer-name sumbuf)
8022 (progn
8023 (set-buffer sumbuf)
8024 (gnus-summary-exit)))))))))))
8025
8026 (defun gnus-summary-prev-group (&optional no-article)
8027 "Exit current newsgroup and then select previous unread newsgroup.
8028 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
8029 (interactive "P")
8030 (gnus-summary-next-group no-article nil t))
8031
8032 ;; Walking around summary lines.
8033
8034 (defun gnus-summary-first-subject (&optional unread)
8035 "Go to the first unread subject.
8036 If UNREAD is non-nil, go to the first unread article.
8037 Returns nil if there are no unread articles."
8038 (interactive "P")
8039 (prog1
8040 (cond ((not unread)
8041 (goto-char (point-min)))
8042 ((gnus-goto-char
8043 (text-property-any
8044 (point-min) (point-max) 'gnus-mark gnus-unread-mark))
8045 t)
8046 (t
8047 ;; There are no unread articles.
8048 (gnus-message 3 "No more unread articles")
8049 nil))
8050 (gnus-summary-position-cursor)))
8051
8052 (defun gnus-summary-next-subject (n &optional unread dont-display)
8053 "Go to next N'th summary line.
8054 If N is negative, go to the previous N'th subject line.
8055 If UNREAD is non-nil, only unread articles are selected.
8056 The difference between N and the actual number of steps taken is
8057 returned."
8058 (interactive "p")
8059 (let ((backward (< n 0))
8060 (n (abs n)))
8061 (while (and (> n 0)
8062 (gnus-summary-search-forward unread nil backward))
8063 (setq n (1- n)))
8064 (if (/= 0 n) (gnus-message 7 "No more%s articles"
8065 (if unread " unread" "")))
8066 (or dont-display
8067 (progn
8068 (gnus-summary-recenter)
8069 (gnus-summary-position-cursor)))
8070 n))
8071
8072 (defun gnus-summary-next-unread-subject (n)
8073 "Go to next N'th unread summary line."
8074 (interactive "p")
8075 (gnus-summary-next-subject n t))
8076
8077 (defun gnus-summary-prev-subject (n &optional unread)
8078 "Go to previous N'th summary line.
8079 If optional argument UNREAD is non-nil, only unread article is selected."
8080 (interactive "p")
8081 (gnus-summary-next-subject (- n) unread))
8082
8083 (defun gnus-summary-prev-unread-subject (n)
8084 "Go to previous N'th unread summary line."
8085 (interactive "p")
8086 (gnus-summary-next-subject (- n) t))
8087
8088 (defun gnus-summary-goto-subject (article)
8089 "Go the subject line of ARTICLE."
8090 (interactive
8091 (list
8092 (string-to-int
8093 (completing-read "Article number: "
8094 (mapcar
8095 (lambda (headers)
8096 (list
8097 (int-to-string (mail-header-number headers))))
8098 gnus-newsgroup-headers)
8099 nil 'require-match))))
8100 (or article (error "No article number"))
8101 (let ((b (point)))
8102 (if (not (gnus-goto-char (text-property-any (point-min) (point-max)
8103 'gnus-number article)))
8104 ()
8105 (gnus-summary-show-thread)
8106 ;; Skip dummy articles.
8107 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8108 (forward-line 1))
8109 (prog1
8110 (if (not (eobp))
8111 article
8112 (goto-char b)
8113 nil)
8114 (gnus-summary-position-cursor)))))
8115
8116 ;; Walking around summary lines with displaying articles.
8117
8118 (defun gnus-summary-expand-window (&optional arg)
8119 "Make the summary buffer take up the entire Emacs frame.
8120 Given a prefix, will force an `article' buffer configuration."
8121 (interactive "P")
8122 (gnus-set-global-variables)
8123 (if arg
8124 (gnus-configure-windows 'article 'force)
8125 (gnus-configure-windows 'summary 'force)))
8126
8127 (defun gnus-summary-display-article (article &optional all-header)
8128 "Display ARTICLE in article buffer."
8129 (gnus-set-global-variables)
8130 (if (null article)
8131 nil
8132 (prog1
8133 (gnus-article-prepare article all-header)
8134 (gnus-summary-show-thread)
8135 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8136 (progn
8137 (forward-line 1)
8138 (gnus-summary-position-cursor)))
8139 (run-hooks 'gnus-select-article-hook)
8140 (gnus-summary-recenter)
8141 (gnus-summary-goto-subject article)
8142 ;; Successfully display article.
8143 (gnus-summary-update-line)
8144 (gnus-article-set-window-start
8145 (cdr (assq article gnus-newsgroup-bookmarks)))
8146 t)))
8147
8148 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
8149 "Select the current article.
8150 If ALL-HEADERS is non-nil, show all header fields. If FORCE is
8151 non-nil, the article will be re-fetched even if it already present in
8152 the article buffer. If PSEUDO is non-nil, pseudo-articles will also
8153 be displayed."
8154 (and (not pseudo) (gnus-summary-pseudo-article)
8155 (error "This is a pseudo-article."))
8156 (let ((article (or article (gnus-summary-article-number)))
8157 (all-headers (not (not all-headers))) ;Must be T or NIL.
8158 did)
8159 (prog1
8160 (save-excursion
8161 (set-buffer gnus-summary-buffer)
8162 (if (or (null gnus-current-article)
8163 (null gnus-article-current)
8164 (null (get-buffer gnus-article-buffer))
8165 (not (eq article (cdr gnus-article-current)))
8166 (not (equal (car gnus-article-current) gnus-newsgroup-name))
8167 force)
8168 ;; The requested article is different from the current article.
8169 (progn
8170 (gnus-summary-display-article article all-headers)
8171 (setq did article))
8172 (if (or all-headers gnus-show-all-headers)
8173 (gnus-article-show-all-headers))
8174 nil))
8175 (if did
8176 (gnus-article-set-window-start
8177 (cdr (assq article gnus-newsgroup-bookmarks)))))))
8178
8179 (defun gnus-summary-set-current-mark (&optional current-mark)
8180 "Obsolete function."
8181 nil)
8182
8183 (defun gnus-summary-next-article (&optional unread subject backward)
8184 "Select the next article.
8185 If UNREAD, only unread articles are selected.
8186 If SUBJECT, only articles with SUBJECT are selected.
8187 If BACKWARD, the previous article is selected instead of the next."
8188 (interactive "P")
8189 (gnus-set-global-variables)
8190 (let (header)
8191 (cond
8192 ;; Is there such an article?
8193 ((and (gnus-summary-search-forward unread subject backward)
8194 (or (gnus-summary-display-article (gnus-summary-article-number))
8195 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8196 (gnus-summary-position-cursor))
8197 ;; If not, we try the first unread, if that is wanted.
8198 ((and subject
8199 gnus-auto-select-same
8200 (or (gnus-summary-first-unread-article)
8201 (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8202 (gnus-summary-position-cursor)
8203 (gnus-message 6 "Wrapped"))
8204 ;; Try to get next/previous article not displayed in this group.
8205 ((and gnus-auto-extend-newsgroup
8206 (not unread) (not subject)
8207 (setq header (gnus-more-header-forward backward)))
8208 (gnus-extend-newsgroup header backward)
8209 (let ((buffer-read-only nil))
8210 (goto-char (if backward (point-min) (point-max)))
8211 (gnus-summary-prepare-threads (list header)))
8212 (gnus-summary-goto-article (if backward gnus-newsgroup-begin
8213 gnus-newsgroup-end)))
8214 ;; Go to next/previous group.
8215 (t
8216 (or (gnus-ephemeral-group-p gnus-newsgroup-name)
8217 (gnus-summary-jump-to-group gnus-newsgroup-name))
8218 (let ((cmd last-command-char)
8219 (group
8220 (if (eq gnus-keep-same-level 'best)
8221 (gnus-summary-best-group gnus-newsgroup-name)
8222 (gnus-summary-search-group backward gnus-keep-same-level))))
8223 ;; For some reason, the group window gets selected. We change
8224 ;; it back.
8225 (select-window (get-buffer-window (current-buffer)))
8226 ;; Keep just the event type of CMD.
8227 ;(and (listp cmd) (setq cmd (car cmd)))
8228 ;; Select next unread newsgroup automagically.
8229 (cond
8230 ((not gnus-auto-select-next)
8231 (gnus-message 7 "No more%s articles" (if unread " unread" "")))
8232 ((eq gnus-auto-select-next 'quietly)
8233 ;; Select quietly.
8234 (if (gnus-ephemeral-group-p gnus-newsgroup-name)
8235 (gnus-summary-exit)
8236 (gnus-message 7 "No more%s articles (%s)..."
8237 (if unread " unread" "")
8238 (if group (concat "selecting " group)
8239 "exiting"))
8240 (gnus-summary-next-group nil group backward)))
8241 (t
8242 (let ((keystrokes '(?\C-n ?\C-p))
8243 key)
8244 (while (or (null key) (memq key keystrokes))
8245 (gnus-message
8246 7 "No more%s articles%s" (if unread " unread" "")
8247 (if (and group
8248 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
8249 (format " (Type %s for %s [%s])"
8250 (single-key-description cmd) group
8251 (car (gnus-gethash group gnus-newsrc-hashtb)))
8252 (format " (Type %s to exit %s)"
8253 (single-key-description cmd)
8254 gnus-newsgroup-name)))
8255 ;; Confirm auto selection.
8256 (let* ((event (read-char)))
8257 (setq key (if (listp event) (car event) event))
8258 (if (memq key keystrokes)
8259 (let ((obuf (current-buffer)))
8260 (switch-to-buffer gnus-group-buffer)
8261 (and group
8262 (gnus-group-jump-to-group group))
8263 (condition-case ()
8264 (execute-kbd-macro (char-to-string key))
8265 (error (ding) nil))
8266 (setq group (gnus-group-group-name))
8267 (switch-to-buffer obuf)))))
8268 (if (equal key cmd)
8269 (if (or (not group)
8270 (gnus-ephemeral-group-p gnus-newsgroup-name))
8271 (gnus-summary-exit)
8272 (gnus-summary-next-group nil group backward))
8273 (execute-kbd-macro (char-to-string key)))))))))))
8274
8275 (defun gnus-summary-next-unread-article ()
8276 "Select unread article after current one."
8277 (interactive)
8278 (gnus-summary-next-article t (and gnus-auto-select-same
8279 (gnus-summary-subject-string))))
8280
8281 (defun gnus-summary-prev-article (&optional unread subject)
8282 "Select the article after the current one.
8283 If UNREAD is non-nil, only unread articles are selected."
8284 (interactive "P")
8285 (gnus-summary-next-article unread subject t))
8286
8287 (defun gnus-summary-prev-unread-article ()
8288 "Select unred article before current one."
8289 (interactive)
8290 (gnus-summary-prev-article t (and gnus-auto-select-same
8291 (gnus-summary-subject-string))))
8292
8293 (defun gnus-summary-next-page (&optional lines circular)
8294 "Show next page of selected article.
8295 If end of article, select next article.
8296 Argument LINES specifies lines to be scrolled up.
8297 If CIRCULAR is non-nil, go to the start of the article instead of
8298 instead of selecting the next article when reaching the end of the
8299 current article."
8300 (interactive "P")
8301 (setq gnus-summary-buffer (current-buffer))
8302 (gnus-set-global-variables)
8303 (let ((article (gnus-summary-article-number))
8304 (endp nil))
8305 (gnus-configure-windows 'article)
8306 (if (or (null gnus-current-article)
8307 (null gnus-article-current)
8308 (/= article (cdr gnus-article-current))
8309 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8310 ;; Selected subject is different from current article's.
8311 (gnus-summary-display-article article)
8312 (gnus-eval-in-buffer-window
8313 gnus-article-buffer
8314 (setq endp (gnus-article-next-page lines)))
8315 (if endp
8316 (cond (circular
8317 (gnus-summary-beginning-of-article))
8318 (lines
8319 (gnus-message 3 "End of message"))
8320 ((null lines)
8321 (gnus-summary-next-unread-article)))))
8322 (gnus-summary-recenter)
8323 (gnus-summary-position-cursor)))
8324
8325 (defun gnus-summary-prev-page (&optional lines)
8326 "Show previous page of selected article.
8327 Argument LINES specifies lines to be scrolled down."
8328 (interactive "P")
8329 (gnus-set-global-variables)
8330 (let ((article (gnus-summary-article-number)))
8331 (gnus-configure-windows 'article)
8332 (if (or (null gnus-current-article)
8333 (null gnus-article-current)
8334 (/= article (cdr gnus-article-current))
8335 (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8336 ;; Selected subject is different from current article's.
8337 (gnus-summary-display-article article)
8338 (gnus-summary-recenter)
8339 (gnus-eval-in-buffer-window gnus-article-buffer
8340 (gnus-article-prev-page lines))))
8341 (gnus-summary-position-cursor))
8342
8343 (defun gnus-summary-scroll-up (lines)
8344 "Scroll up (or down) one line current article.
8345 Argument LINES specifies lines to be scrolled up (or down if negative)."
8346 (interactive "p")
8347 (gnus-set-global-variables)
8348 (gnus-configure-windows 'article)
8349 (or (gnus-summary-select-article nil nil 'pseudo)
8350 (gnus-eval-in-buffer-window
8351 gnus-article-buffer
8352 (cond ((> lines 0)
8353 (if (gnus-article-next-page lines)
8354 (gnus-message 3 "End of message")))
8355 ((< lines 0)
8356 (gnus-article-prev-page (- lines))))))
8357 (gnus-summary-recenter)
8358 (gnus-summary-position-cursor))
8359
8360 (defun gnus-summary-next-same-subject ()
8361 "Select next article which has the same subject as current one."
8362 (interactive)
8363 (gnus-set-global-variables)
8364 (gnus-summary-next-article nil (gnus-summary-subject-string)))
8365
8366 (defun gnus-summary-prev-same-subject ()
8367 "Select previous article which has the same subject as current one."
8368 (interactive)
8369 (gnus-set-global-variables)
8370 (gnus-summary-prev-article nil (gnus-summary-subject-string)))
8371
8372 (defun gnus-summary-next-unread-same-subject ()
8373 "Select next unread article which has the same subject as current one."
8374 (interactive)
8375 (gnus-set-global-variables)
8376 (gnus-summary-next-article t (gnus-summary-subject-string)))
8377
8378 (defun gnus-summary-prev-unread-same-subject ()
8379 "Select previous unread article which has the same subject as current one."
8380 (interactive)
8381 (gnus-set-global-variables)
8382 (gnus-summary-prev-article t (gnus-summary-subject-string)))
8383
8384 (defun gnus-summary-first-unread-article ()
8385 "Select the first unread article.
8386 Return nil if there are no unread articles."
8387 (interactive)
8388 (gnus-set-global-variables)
8389 (prog1
8390 (if (gnus-summary-first-subject t)
8391 (progn
8392 (gnus-summary-show-thread)
8393 (gnus-summary-first-subject t)
8394 (gnus-summary-display-article (gnus-summary-article-number))))
8395 (gnus-summary-position-cursor)))
8396
8397 (defun gnus-summary-best-unread-article ()
8398 "Select the unread article with the highest score."
8399 (interactive)
8400 (gnus-set-global-variables)
8401 (let ((best -1000000)
8402 article score)
8403 (save-excursion
8404 (or (gnus-summary-first-subject t)
8405 (error "No unread articles"))
8406 (while
8407 (and
8408 (progn
8409 (and (> (setq score (gnus-summary-article-score)) best)
8410 (setq best score
8411 article (gnus-summary-article-number)))
8412 t)
8413 (gnus-summary-search-subject nil t))))
8414 (if (not article)
8415 (error "No unread articles")
8416 (gnus-summary-goto-article article))
8417 (gnus-summary-position-cursor)))
8418
8419 (defun gnus-summary-goto-article (article &optional all-headers)
8420 "Fetch ARTICLE and display it if it exists.
8421 If ALL-HEADERS is non-nil, no header lines are hidden."
8422 (interactive
8423 (list
8424 (string-to-int
8425 (completing-read
8426 "Article number: "
8427 (mapcar (lambda (headers)
8428 (list (int-to-string (mail-header-number headers))))
8429 gnus-newsgroup-headers)
8430 nil 'require-match))))
8431 (prog1
8432 (and (gnus-summary-goto-subject article)
8433 (gnus-summary-display-article article all-headers))
8434 (gnus-summary-position-cursor)))
8435
8436 (defun gnus-summary-goto-last-article ()
8437 "Go to the previously read article."
8438 (interactive)
8439 (prog1
8440 (and gnus-last-article
8441 (gnus-summary-goto-article gnus-last-article))
8442 (gnus-summary-position-cursor)))
8443
8444 (defun gnus-summary-pop-article (number)
8445 "Pop one article off the history and go to the previous.
8446 NUMBER articles will be popped off."
8447 (interactive "p")
8448 (let (to)
8449 (setq gnus-newsgroup-history
8450 (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8451 (if to
8452 (gnus-summary-goto-article (car to))
8453 (error "Article history empty")))
8454 (gnus-summary-position-cursor))
8455
8456 ;; Summary article oriented commands
8457
8458 (defun gnus-summary-refer-parent-article (n)
8459 "Refer parent article N times.
8460 The difference between N and the number of articles fetched is returned."
8461 (interactive "p")
8462 (gnus-set-global-variables)
8463 (while
8464 (and
8465 (> n 0)
8466 (let ((ref (mail-header-references (gnus-get-header-by-num
8467 (gnus-summary-article-number)))))
8468 (if (and ref (not (equal ref ""))
8469 (string-match "<[^<>]*>[ \t]*$" ref))
8470 (gnus-summary-refer-article
8471 (substring ref (match-beginning 0) (match-end 0)))
8472 (gnus-message 1 "No references in article %d"
8473 (gnus-summary-article-number))
8474 nil)))
8475 (setq n (1- n)))
8476 (gnus-summary-position-cursor)
8477 n)
8478
8479 (defun gnus-summary-refer-article (message-id)
8480 "Refer article specified by MESSAGE-ID.
8481 NOTE: This command only works with newsgroups that use real or simulated NNTP."
8482 (interactive "sMessage-ID: ")
8483 (if (or (not (stringp message-id))
8484 (zerop (length message-id)))
8485 ()
8486 ;; Construct the correct Message-ID if necessary.
8487 ;; Suggested by tale@pawl.rpi.edu.
8488 (or (string-match "^<" message-id)
8489 (setq message-id (concat "<" message-id)))
8490 (or (string-match ">$" message-id)
8491 (setq message-id (concat message-id ">")))
8492 (let ((header (car (gnus-gethash (downcase message-id)
8493 gnus-newsgroup-dependencies))))
8494 (if header
8495 (or (gnus-summary-goto-article (mail-header-number header))
8496 ;; The header has been read, but the article had been
8497 ;; expunged, so we insert it again.
8498 (progn
8499 (gnus-summary-insert-line
8500 nil header 0 nil gnus-read-mark nil nil
8501 (mail-header-subject header))
8502 (forward-line -1)
8503 (mail-header-number header)))
8504 (let ((gnus-override-method gnus-refer-article-method)
8505 (gnus-ancient-mark gnus-read-mark)
8506 (tmp-point (window-start
8507 (get-buffer-window gnus-article-buffer)))
8508 number tmp-buf)
8509 (and gnus-refer-article-method
8510 (gnus-check-server gnus-refer-article-method))
8511 ;; Save the old article buffer.
8512 (save-excursion
8513 (set-buffer (gnus-article-setup-buffer))
8514 (gnus-kill-buffer " *temp Article*")
8515 (setq tmp-buf (rename-buffer " *temp Article*")))
8516 (prog1
8517 (if (gnus-article-prepare
8518 message-id nil (gnus-read-header message-id))
8519 (progn
8520 (setq number (mail-header-number gnus-current-headers))
8521 (gnus-rebuild-thread message-id)
8522 (gnus-summary-goto-subject number)
8523 (if (null gnus-use-full-window)
8524 (progn
8525 (delete-windows-on tmp-buf)
8526 (gnus-configure-windows 'article 'force)))
8527 (gnus-summary-recenter)
8528 (gnus-article-set-window-start
8529 (cdr (assq number gnus-newsgroup-bookmarks)))
8530 (and gnus-visual
8531 (run-hooks 'gnus-visual-mark-article-hook))
8532 message-id)
8533 ;; We restore the old article buffer.
8534 (save-excursion
8535 (kill-buffer gnus-article-buffer)
8536 (set-buffer tmp-buf)
8537 (rename-buffer gnus-article-buffer)
8538 (let ((buffer-read-only nil))
8539 (and tmp-point
8540 (set-window-start (get-buffer-window (current-buffer))
8541 tmp-point)))))))))))
8542
8543 (defun gnus-summary-enter-digest-group ()
8544 "Enter a digest group based on the current article."
8545 (interactive)
8546 (gnus-set-global-variables)
8547 (gnus-summary-select-article)
8548 ;; We do not want a narrowed article.
8549 (gnus-summary-stop-page-breaking)
8550 (let ((name (format "%s-%d"
8551 (gnus-group-prefixed-name
8552 gnus-newsgroup-name (list 'nndoc ""))
8553 gnus-current-article))
8554 (ogroup gnus-newsgroup-name)
8555 (buf (current-buffer)))
8556 (if (gnus-group-read-ephemeral-group
8557 name (list 'nndoc name
8558 (list 'nndoc-address (get-buffer gnus-article-buffer))
8559 '(nndoc-article-type digest))
8560 t)
8561 (setcdr (nthcdr 4 (nth 2 (gnus-gethash name gnus-newsrc-hashtb)))
8562 (list (list (cons 'to-group ogroup))))
8563 (switch-to-buffer buf)
8564 (gnus-set-global-variables)
8565 (gnus-configure-windows 'summary)
8566 (gnus-message 3 "Article not a digest?"))))
8567
8568 (defun gnus-summary-isearch-article ()
8569 "Do incremental search forward on current article."
8570 (interactive)
8571 (gnus-set-global-variables)
8572 (gnus-summary-select-article)
8573 (gnus-eval-in-buffer-window
8574 gnus-article-buffer (isearch-forward)))
8575
8576 (defun gnus-summary-search-article-forward (regexp &optional backward)
8577 "Search for an article containing REGEXP forward.
8578 If BACKWARD, search backward instead."
8579 (interactive
8580 (list (read-string
8581 (format "Search article %s (regexp%s): "
8582 (if current-prefix-arg "backward" "forward")
8583 (if gnus-last-search-regexp
8584 (concat ", default " gnus-last-search-regexp)
8585 "")))
8586 current-prefix-arg))
8587 (gnus-set-global-variables)
8588 (if (string-equal regexp "")
8589 (setq regexp (or gnus-last-search-regexp ""))
8590 (setq gnus-last-search-regexp regexp))
8591 (if (gnus-summary-search-article regexp backward)
8592 (gnus-article-set-window-start
8593 (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks)))
8594 (error "Search failed: \"%s\"" regexp)))
8595
8596 (defun gnus-summary-search-article-backward (regexp)
8597 "Search for an article containing REGEXP backward."
8598 (interactive
8599 (list (read-string
8600 (format "Search article backward (regexp%s): "
8601 (if gnus-last-search-regexp
8602 (concat ", default " gnus-last-search-regexp)
8603 "")))))
8604 (gnus-summary-search-article-forward regexp 'backward))
8605
8606 (defun gnus-summary-search-article (regexp &optional backward)
8607 "Search for an article containing REGEXP.
8608 Optional argument BACKWARD means do search for backward.
8609 gnus-select-article-hook is not called during the search."
8610 (let ((gnus-select-article-hook nil) ;Disable hook.
8611 (gnus-mark-article-hook nil) ;Inhibit marking as read.
8612 (re-search
8613 (if backward
8614 (function re-search-backward) (function re-search-forward)))
8615 (found nil)
8616 (last nil))
8617 ;; Hidden thread subtrees must be searched for ,too.
8618 (gnus-summary-show-all-threads)
8619 (if (eobp) (forward-line -1))
8620 ;; First of all, search current article.
8621 ;; We don't want to read article again from NNTP server nor reset
8622 ;; current point.
8623 (gnus-summary-select-article)
8624 (gnus-message 9 "Searching article: %d..." gnus-current-article)
8625 (setq last gnus-current-article)
8626 (gnus-eval-in-buffer-window
8627 gnus-article-buffer
8628 (save-restriction
8629 (widen)
8630 ;; Begin search from current point.
8631 (setq found (funcall re-search regexp nil t))))
8632 ;; Then search next articles.
8633 (while (and (not found)
8634 (gnus-summary-display-article
8635 (gnus-summary-search-subject backward nil nil)))
8636 (gnus-message 9 "Searching article: %d..." gnus-current-article)
8637 (gnus-eval-in-buffer-window
8638 gnus-article-buffer
8639 (save-restriction
8640 (widen)
8641 (goto-char (if backward (point-max) (point-min)))
8642 (setq found (funcall re-search regexp nil t)))))
8643 (message "")
8644 ;; Adjust article pointer.
8645 (or (eq last gnus-current-article)
8646 (setq gnus-last-article last))
8647 ;; Return T if found such article.
8648 found))
8649
8650 (defun gnus-summary-execute-command (header regexp command &optional backward)
8651 "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8652 If HEADER is an empty string (or nil), the match is done on the entire
8653 article. If BACKWARD (the prefix) is non-nil, search backward instead."
8654 (interactive
8655 (list (let ((completion-ignore-case t))
8656 (completing-read
8657 "Header name: "
8658 (mapcar (lambda (string) (list string))
8659 '("Number" "Subject" "From" "Lines" "Date"
8660 "Message-ID" "Xref" "References"))
8661 nil 'require-match))
8662 (read-string "Regexp: ")
8663 (read-key-sequence "Command: ")
8664 current-prefix-arg))
8665 (gnus-set-global-variables)
8666 ;; Hidden thread subtrees must be searched as well.
8667 (gnus-summary-show-all-threads)
8668 ;; We don't want to change current point nor window configuration.
8669 (save-excursion
8670 (save-window-excursion
8671 (gnus-message 6 "Executing %s..." (key-description command))
8672 ;; We'd like to execute COMMAND interactively so as to give arguments.
8673 (gnus-execute header regexp
8674 (` (lambda ()
8675 (call-interactively '(, (key-binding command)))))
8676 backward)
8677 (gnus-message 6 "Executing %s...done" (key-description command)))))
8678
8679 (defun gnus-summary-beginning-of-article ()
8680 "Scroll the article back to the beginning."
8681 (interactive)
8682 (gnus-set-global-variables)
8683 (gnus-summary-select-article)
8684 (gnus-configure-windows 'article)
8685 (gnus-eval-in-buffer-window
8686 gnus-article-buffer
8687 (widen)
8688 (goto-char (point-min))
8689 (and gnus-break-pages (gnus-narrow-to-page))))
8690
8691 (defun gnus-summary-end-of-article ()
8692 "Scroll to the end of the article."
8693 (interactive)
8694 (gnus-set-global-variables)
8695 (gnus-summary-select-article)
8696 (gnus-configure-windows 'article)
8697 (gnus-eval-in-buffer-window
8698 gnus-article-buffer
8699 (widen)
8700 (goto-char (point-max))
8701 (recenter -3)
8702 (and gnus-break-pages (gnus-narrow-to-page))))
8703
8704 (defun gnus-summary-show-article ()
8705 "Force re-fetching of the current article."
8706 (interactive)
8707 (gnus-set-global-variables)
8708 (gnus-summary-select-article nil 'force)
8709 (gnus-configure-windows 'article)
8710 (gnus-summary-position-cursor))
8711
8712 (defun gnus-summary-verbose-headers (&optional arg)
8713 "Toggle permanent full header display.
8714 If ARG is a positive number, turn header display on.
8715 If ARG is a negative number, turn header display off."
8716 (interactive "P")
8717 (gnus-set-global-variables)
8718 (gnus-summary-toggle-header arg)
8719 (setq gnus-show-all-headers
8720 (cond ((or (not (numberp arg))
8721 (zerop arg))
8722 (not gnus-show-all-headers))
8723 ((natnump arg)
8724 t))))
8725
8726 (defun gnus-summary-toggle-header (&optional arg)
8727 "Show the headers if they are hidden, or hide them if they are shown.
8728 If ARG is a positive number, show the entire header.
8729 If ARG is a negative number, hide the unwanted header lines."
8730 (interactive "P")
8731 (gnus-set-global-variables)
8732 (save-excursion
8733 (set-buffer gnus-article-buffer)
8734 (let ((buffer-read-only nil))
8735 (if (numberp arg)
8736 (if (> arg 0) (remove-text-properties (point-min) (point-max)
8737 gnus-hidden-properties)
8738 (if (< arg 0) (run-hooks 'gnus-article-display-hook)))
8739 (if (text-property-any (point-min) (point-max) 'invisible t)
8740 (remove-text-properties
8741 (point-min) (point-max) gnus-hidden-properties)
8742 ;; We hide the headers. This song and dance act below is
8743 ;; done because `gnus-have-all-headers' is buffer-local to
8744 ;; the summary buffer, and we only want to temporarily
8745 ;; change it in that buffer. Ugh.
8746 (let ((have gnus-have-all-headers))
8747 (save-excursion
8748 (set-buffer gnus-summary-buffer)
8749 (setq gnus-have-all-headers nil)
8750 (save-excursion
8751 (set-buffer gnus-article-buffer)
8752 (run-hooks 'gnus-article-display-hook))
8753 (setq gnus-have-all-headers have)))))
8754 (set-window-point (get-buffer-window (current-buffer)) (point-min)))))
8755
8756 (defun gnus-summary-show-all-headers ()
8757 "Make all header lines visible."
8758 (interactive)
8759 (gnus-set-global-variables)
8760 (gnus-article-show-all-headers))
8761
8762 (defun gnus-summary-toggle-mime (&optional arg)
8763 "Toggle MIME processing.
8764 If ARG is a positive number, turn MIME processing on."
8765 (interactive "P")
8766 (gnus-set-global-variables)
8767 (setq gnus-show-mime
8768 (if (null arg) (not gnus-show-mime)
8769 (> (prefix-numeric-value arg) 0)))
8770 (gnus-summary-select-article t 'force))
8771
8772 (defun gnus-summary-caesar-message (&optional arg)
8773 "Caesar rotate the current article by 13.
8774 The numerical prefix specifies how manu places to rotate each letter
8775 forward."
8776 (interactive "P")
8777 (gnus-set-global-variables)
8778 (gnus-summary-select-article)
8779 (let ((mail-header-separator ""))
8780 (gnus-eval-in-buffer-window
8781 gnus-article-buffer
8782 (save-restriction
8783 (widen)
8784 (let ((start (window-start)))
8785 (news-caesar-buffer-body arg)
8786 (set-window-start (get-buffer-window (current-buffer)) start))))))
8787
8788 (defun gnus-summary-stop-page-breaking ()
8789 "Stop page breaking in the current article."
8790 (interactive)
8791 (gnus-set-global-variables)
8792 (gnus-summary-select-article)
8793 (gnus-eval-in-buffer-window gnus-article-buffer (widen)))
8794
8795 ;; Suggested by Brian Edmonds <bedmonds@prodigy.bc.ca>.
8796
8797 (defun gnus-summary-move-article (&optional n to-newsgroup select-method)
8798 "Move the current article to a different newsgroup.
8799 If N is a positive number, move the N next articles.
8800 If N is a negative number, move the N previous articles.
8801 If N is nil and any articles have been marked with the process mark,
8802 move those articles instead.
8803 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8804 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8805 re-spool using this method.
8806 For this function to work, both the current newsgroup and the
8807 newsgroup that you want to move to have to support the `request-move'
8808 and `request-accept' functions. (Ie. mail newsgroups at present.)"
8809 (interactive "P")
8810 (gnus-set-global-variables)
8811 (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name)
8812 (error "The current newsgroup does not support article moving"))
8813 (let ((articles (gnus-summary-work-articles n))
8814 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8815 art-group to-method sel-met)
8816 (if (and (not to-newsgroup) (not select-method))
8817 (setq to-newsgroup
8818 (completing-read
8819 (format "Where do you want to move %s? %s"
8820 (if (> (length articles) 1)
8821 (format "these %d articles" (length articles))
8822 "this article")
8823 (if gnus-current-move-group
8824 (format "(%s default) " gnus-current-move-group)
8825 ""))
8826 gnus-active-hashtb nil nil prefix)))
8827 (if to-newsgroup
8828 (progn
8829 (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8830 (setq to-newsgroup (or gnus-current-move-group "")))
8831 (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8832 (gnus-activate-group to-newsgroup)
8833 (error "No such group: %s" to-newsgroup))
8834 (setq gnus-current-move-group to-newsgroup)))
8835 (setq to-method (if select-method (list select-method "")
8836 (gnus-find-method-for-group to-newsgroup)))
8837 (or (gnus-check-backend-function 'request-accept-article (car to-method))
8838 (error "%s does not support article copying" (car to-method)))
8839 (or (gnus-check-server to-method)
8840 (error "Can't open server %s" (car to-method)))
8841 (gnus-message 6 "Moving to %s: %s..."
8842 (or select-method to-newsgroup) articles)
8843 (while articles
8844 (if (setq art-group
8845 (gnus-request-move-article
8846 (car articles) ; Article to move
8847 gnus-newsgroup-name ; From newsgroup
8848 (nth 1 (gnus-find-method-for-group
8849 gnus-newsgroup-name)) ; Server
8850 (list 'gnus-request-accept-article
8851 (if select-method
8852 (list 'quote select-method)
8853 to-newsgroup)
8854 (not (cdr articles))) ; Accept form
8855 (not (cdr articles)))) ; Only save nov last time
8856 (let* ((buffer-read-only nil)
8857 (entry
8858 (or
8859 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8860 (gnus-gethash
8861 (gnus-group-prefixed-name
8862 (car art-group)
8863 (if select-method (list select-method "")
8864 (gnus-find-method-for-group to-newsgroup)))
8865 gnus-newsrc-hashtb)))
8866 (info (nth 2 entry))
8867 (article (car articles)))
8868 (gnus-summary-goto-subject article)
8869 (beginning-of-line)
8870 (delete-region (point) (progn (forward-line 1) (point)))
8871 ;; Update the group that has been moved to.
8872 (if (not info)
8873 () ; This group does not exist yet.
8874 (if (not (memq article gnus-newsgroup-unreads))
8875 (setcar (cdr (cdr info))
8876 (gnus-add-to-range (nth 2 info)
8877 (list (cdr art-group)))))
8878 ;; Copy any marks over to the new group.
8879 (let ((marks '((tick . gnus-newsgroup-marked)
8880 (dormant . gnus-newsgroup-dormant)
8881 (expire . gnus-newsgroup-expirable)
8882 (bookmark . gnus-newsgroup-bookmarks)
8883 (reply . gnus-newsgroup-replied)))
8884 (to-article (cdr art-group)))
8885 (while marks
8886 (if (memq article (symbol-value (cdr (car marks))))
8887 (gnus-add-marked-articles
8888 (car info) (car (car marks)) (list to-article) info))
8889 (setq marks (cdr marks)))))
8890 ;; Update marks.
8891 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8892 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8893 (setq gnus-newsgroup-dormant
8894 (delq article gnus-newsgroup-dormant))
8895 (setq gnus-newsgroup-reads
8896 (cons (cons article gnus-canceled-mark)
8897 gnus-newsgroup-reads)))
8898 (gnus-message 1 "Couldn't move article %s" (car articles)))
8899 (gnus-summary-remove-process-mark (car articles))
8900 (setq articles (cdr articles)))
8901 (gnus-set-mode-line 'summary)))
8902
8903 (defun gnus-summary-respool-article (&optional n respool-method)
8904 "Respool the current article.
8905 The article will be squeezed through the mail spooling process again,
8906 which means that it will be put in some mail newsgroup or other
8907 depending on `nnmail-split-methods'.
8908 If N is a positive number, respool the N next articles.
8909 If N is a negative number, respool the N previous articles.
8910 If N is nil and any articles have been marked with the process mark,
8911 respool those articles instead.
8912
8913 Respooling can be done both from mail groups and \"real\" newsgroups.
8914 In the former case, the articles in question will be moved from the
8915 current group into whatever groups they are destined to. In the
8916 latter case, they will be copied into the relevant groups."
8917 (interactive "P")
8918 (gnus-set-global-variables)
8919 (let ((respool-methods (gnus-methods-using 'respool))
8920 (methname
8921 (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name)))))
8922 (or respool-method
8923 (setq respool-method
8924 (completing-read
8925 "What method do you want to use when respooling? "
8926 respool-methods nil t methname)))
8927 (or (string= respool-method "")
8928 (if (assoc (symbol-name
8929 (car (gnus-find-method-for-group gnus-newsgroup-name)))
8930 respool-methods)
8931 (gnus-summary-move-article n nil (intern respool-method))
8932 (gnus-summary-copy-article n nil (intern respool-method))))))
8933
8934 ;; Suggested by gregj@unidata.com (Gregory J. Grubbs).
8935 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8936 "Move the current article to a different newsgroup.
8937 If N is a positive number, move the N next articles.
8938 If N is a negative number, move the N previous articles.
8939 If N is nil and any articles have been marked with the process mark,
8940 move those articles instead.
8941 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8942 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8943 re-spool using this method.
8944 For this function to work, the newsgroup that you want to move to have
8945 to support the `request-move' and `request-accept'
8946 functions. (Ie. mail newsgroups at present.)"
8947 (interactive "P")
8948 (gnus-set-global-variables)
8949 (let ((articles (gnus-summary-work-articles n))
8950 (copy-buf (get-buffer-create "*copy work*"))
8951 (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8952 art-group to-method)
8953 (buffer-disable-undo copy-buf)
8954 (if (and (not to-newsgroup) (not select-method))
8955 (setq to-newsgroup
8956 (completing-read
8957 (format "Where do you want to copy %s? %s"
8958 (if (> (length articles) 1)
8959 (format "these %d articles" (length articles))
8960 "this article")
8961 (if gnus-current-move-group
8962 (format "(%s default) " gnus-current-move-group)
8963 ""))
8964 gnus-active-hashtb nil nil prefix)))
8965 (if to-newsgroup
8966 (progn
8967 (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8968 (setq to-newsgroup (or gnus-current-move-group "")))
8969 (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8970 (gnus-activate-group to-newsgroup)
8971 (error "No such group: %s" to-newsgroup))
8972 (setq gnus-current-move-group to-newsgroup)))
8973 (setq to-method (if select-method (list select-method "")
8974 (gnus-find-method-for-group to-newsgroup)))
8975 (or (gnus-check-backend-function 'request-accept-article (car to-method))
8976 (error "%s does not support article copying" (car to-method)))
8977 (or (gnus-check-server to-method)
8978 (error "Can't open server %s" (car to-method)))
8979 (while articles
8980 (gnus-message 6 "Copying to %s: %s..."
8981 (or select-method to-newsgroup) articles)
8982 (if (setq art-group
8983 (save-excursion
8984 (set-buffer copy-buf)
8985 (gnus-request-article-this-buffer
8986 (car articles) gnus-newsgroup-name)
8987 (gnus-request-accept-article
8988 (if select-method (list 'quote select-method) to-newsgroup)
8989 (not (cdr articles)))))
8990 (let* ((entry
8991 (or
8992 (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8993 (gnus-gethash
8994 (gnus-group-prefixed-name
8995 (car art-group)
8996 (if select-method (list select-method "")
8997 (gnus-find-method-for-group to-newsgroup)))
8998 gnus-newsrc-hashtb)))
8999 (info (nth 2 entry))
9000 (article (car articles)))
9001 ;; We copy the info over to the new group.
9002 (if (not info)
9003 () ; This group does not exist (yet).
9004 (if (not (memq article gnus-newsgroup-unreads))
9005 (setcar (cdr (cdr info))
9006 (gnus-add-to-range (nth 2 info)
9007 (list (cdr art-group)))))
9008 ;; Copy any marks over to the new group.
9009 (let ((marks '((tick . gnus-newsgroup-marked)
9010 (dormant . gnus-newsgroup-dormant)
9011 (expire . gnus-newsgroup-expirable)
9012 (bookmark . gnus-newsgroup-bookmarks)
9013 (reply . gnus-newsgroup-replied)))
9014 (to-article (cdr art-group)))
9015 (while marks
9016 (if (memq article (symbol-value (cdr (car marks))))
9017 (gnus-add-marked-articles
9018 (car info) (car (car marks)) (list to-article) info))
9019 (setq marks (cdr marks))))))
9020 (gnus-message 1 "Couldn't copy article %s" (car articles)))
9021 (gnus-summary-remove-process-mark (car articles))
9022 (setq articles (cdr articles)))
9023 (kill-buffer copy-buf)))
9024
9025 (defun gnus-summary-import-article (file)
9026 "Import a random file into a mail newsgroup."
9027 (interactive "fImport file: ")
9028 (let ((group gnus-newsgroup-name)
9029 atts)
9030 (or (gnus-check-backend-function 'request-accept-article group)
9031 (error "%s does not support article importing" group))
9032 (or (file-readable-p file)
9033 (not (file-regular-p file))
9034 (error "Can't read %s" file))
9035 (save-excursion
9036 (set-buffer (get-buffer-create " *import file*"))
9037 (buffer-disable-undo (current-buffer))
9038 (erase-buffer)
9039 (insert-file-contents file)
9040 (goto-char (point-min))
9041 (if (nnheader-article-p)
9042 ()
9043 (setq atts (file-attributes file))
9044 (insert "From: " (read-string "From: ") "\n"
9045 "Subject: " (read-string "Subject: ") "\n"
9046 "Date: " (current-time-string (nth 5 atts)) "\n"
9047 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9048 (gnus-request-accept-article group t)
9049 (kill-buffer (current-buffer)))))
9050
9051 (defun gnus-summary-expire-articles ()
9052 "Expire all articles that are marked as expirable in the current group."
9053 (interactive)
9054 (if (not (gnus-check-backend-function
9055 'request-expire-articles gnus-newsgroup-name))
9056 ()
9057 (let* ((info (nth 2 (gnus-gethash gnus-newsgroup-name
9058 gnus-newsrc-hashtb)))
9059 (total (memq 'total-expire (nth 5 info)))
9060 (expirable (if total
9061 (gnus-list-of-read-articles gnus-newsgroup-name)
9062 (setq gnus-newsgroup-expirable
9063 (sort gnus-newsgroup-expirable '<))))
9064 es)
9065 (if (not expirable)
9066 ()
9067 (gnus-message 6 "Expiring articles...")
9068 ;; The list of articles that weren't expired is returned.
9069 (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name))
9070 (or total (setq gnus-newsgroup-expirable es))
9071 ;; We go through the old list of expirable, and mark all
9072 ;; really expired articles as nonexistent.
9073 (or (eq es expirable) ;If nothing was expired, we don't mark.
9074 (let ((gnus-use-cache nil))
9075 (while expirable
9076 (or (memq (car expirable) es)
9077 (gnus-summary-mark-article
9078 (car expirable) gnus-canceled-mark))
9079 (setq expirable (cdr expirable)))))
9080 (gnus-message 6 "Expiring articles...done")))))
9081
9082 (defun gnus-summary-expire-articles-now ()
9083 "Expunge all expirable articles in the current group.
9084 This means that *all* articles that are marked as expirable will be
9085 deleted forever, right now."
9086 (interactive)
9087 (or gnus-expert-user
9088 (gnus-y-or-n-p
9089 "Are you really, really, really sure you want to expunge? ")
9090 (error "Phew!"))
9091 (let ((nnmail-expiry-wait -1)
9092 (nnmail-expiry-wait-function nil))
9093 (gnus-summary-expire-articles)))
9094
9095 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9096 (defun gnus-summary-delete-article (&optional n)
9097 "Delete the N next (mail) articles.
9098 This command actually deletes articles. This is not a marking
9099 command. The article will disappear forever from you life, never to
9100 return.
9101 If N is negative, delete backwards.
9102 If N is nil and articles have been marked with the process mark,
9103 delete these instead."
9104 (interactive "P")
9105 (or (gnus-check-backend-function 'request-expire-articles
9106 gnus-newsgroup-name)
9107 (error "The current newsgroup does not support article deletion."))
9108 ;; Compute the list of articles to delete.
9109 (let ((articles (gnus-summary-work-articles n))
9110 not-deleted)
9111 (if (and gnus-novice-user
9112 (not (gnus-y-or-n-p
9113 (format "Do you really want to delete %s forever? "
9114 (if (> (length articles) 1) "these articles"
9115 "this article")))))
9116 ()
9117 ;; Delete the articles.
9118 (setq not-deleted (gnus-request-expire-articles
9119 articles gnus-newsgroup-name 'force))
9120 (while articles
9121 (gnus-summary-remove-process-mark (car articles))
9122 ;; The backend might not have been able to delete the article
9123 ;; after all.
9124 (or (memq (car articles) not-deleted)
9125 (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9126 (setq articles (cdr articles))))
9127 (gnus-summary-position-cursor)
9128 (gnus-set-mode-line 'summary)
9129 not-deleted))
9130
9131 (defun gnus-summary-edit-article (&optional force)
9132 "Enter into a buffer and edit the current article.
9133 This will have permanent effect only in mail groups.
9134 If FORCE is non-nil, allow editing of articles even in read-only
9135 groups."
9136 (interactive "P")
9137 (or force
9138 (not (gnus-group-read-only-p))
9139 (error "The current newsgroup does not support article editing."))
9140 (gnus-summary-select-article t)
9141 (gnus-configure-windows 'article)
9142 (select-window (get-buffer-window gnus-article-buffer))
9143 (gnus-message 6 "C-c C-c to end edits")
9144 (setq buffer-read-only nil)
9145 (text-mode)
9146 (use-local-map (copy-keymap (current-local-map)))
9147 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
9148 (buffer-enable-undo)
9149 (widen)
9150 (goto-char (point-min))
9151 (search-forward "\n\n" nil t))
9152
9153 (defun gnus-summary-edit-article-done ()
9154 "Make edits to the current article permanent."
9155 (interactive)
9156 (if (gnus-group-read-only-p)
9157 (progn
9158 (gnus-summary-edit-article-postpone)
9159 (message "The current newsgroup does not support article editing.")
9160 (ding))
9161 (let ((buf (buffer-substring-no-properties (point-min) (point-max))))
9162 (erase-buffer)
9163 (insert buf)
9164 (if (not (gnus-request-replace-article
9165 (cdr gnus-article-current) (car gnus-article-current)
9166 (current-buffer)))
9167 (error "Couldn't replace article.")
9168 (gnus-article-mode)
9169 (use-local-map gnus-article-mode-map)
9170 (setq buffer-read-only t)
9171 (buffer-disable-undo (current-buffer))
9172 (gnus-configure-windows 'summary))
9173 (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))))
9174
9175 (defun gnus-summary-edit-article-postpone ()
9176 "Postpone changes to the current article."
9177 (interactive)
9178 (gnus-article-mode)
9179 (use-local-map gnus-article-mode-map)
9180 (setq buffer-read-only t)
9181 (buffer-disable-undo (current-buffer))
9182 (gnus-configure-windows 'summary)
9183 (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))
9184
9185 (defun gnus-summary-fancy-query ()
9186 "Query where the fancy respool algorithm would put this article."
9187 (interactive)
9188 (gnus-summary-select-article)
9189 (save-excursion
9190 (set-buffer gnus-article-buffer)
9191 (save-restriction
9192 (goto-char (point-min))
9193 (search-forward "\n\n")
9194 (narrow-to-region (point-min) (point))
9195 (pp-eval-expression (list 'quote (nnmail-split-fancy))))))
9196
9197 ;; Summary score commands.
9198
9199 ;; Suggested by boubaker@cenatls.cena.dgac.fr.
9200
9201 (defun gnus-summary-raise-score (n)
9202 "Raise the score of the current article by N."
9203 (interactive "p")
9204 (gnus-summary-set-score (+ (gnus-summary-article-score) n)))
9205
9206 (defun gnus-summary-set-score (n)
9207 "Set the score of the current article to N."
9208 (interactive "p")
9209 ;; Skip dummy header line.
9210 (save-excursion
9211 (gnus-summary-show-thread)
9212 (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
9213 (forward-line 1))
9214 (let ((buffer-read-only nil))
9215 ;; Set score.
9216 (gnus-summary-update-mark
9217 (if (= n (or gnus-summary-default-score 0)) ?
9218 (if (< n (or gnus-summary-default-score 0))
9219 gnus-score-below-mark gnus-score-over-mark)) 'score))
9220 (let* ((article (gnus-summary-article-number))
9221 (score (assq article gnus-newsgroup-scored)))
9222 (if score (setcdr score n)
9223 (setq gnus-newsgroup-scored
9224 (cons (cons article n) gnus-newsgroup-scored))))
9225 (gnus-summary-update-line)))
9226
9227 (defun gnus-summary-current-score ()
9228 "Return the score of the current article."
9229 (interactive)
9230 (message "%s" (gnus-summary-article-score)))
9231
9232 ;; Summary marking commands.
9233
9234 (defun gnus-summary-raise-same-subject-and-select (score)
9235 "Raise articles which has the same subject with SCORE and select the next."
9236 (interactive "p")
9237 (let ((subject (gnus-summary-subject-string)))
9238 (gnus-summary-raise-score score)
9239 (while (gnus-summary-search-subject nil nil subject)
9240 (gnus-summary-raise-score score))
9241 (gnus-summary-next-article t)))
9242
9243 (defun gnus-summary-raise-same-subject (score)
9244 "Raise articles which has the same subject with SCORE."
9245 (interactive "p")
9246 (let ((subject (gnus-summary-subject-string)))
9247 (gnus-summary-raise-score score)
9248 (while (gnus-summary-search-subject nil nil subject)
9249 (gnus-summary-raise-score score))
9250 (gnus-summary-next-subject 1 t)))
9251
9252 (defun gnus-score-default (level)
9253 (if level (prefix-numeric-value level)
9254 gnus-score-interactive-default-score))
9255
9256 (defun gnus-summary-raise-thread (&optional score)
9257 "Raise the score of the articles in the current thread with SCORE."
9258 (interactive "P")
9259 (setq score (gnus-score-default score))
9260 (let (e)
9261 (save-excursion
9262 (let ((level (gnus-summary-thread-level)))
9263 (gnus-summary-raise-score score)
9264 (while (and (zerop (gnus-summary-next-subject 1 nil t))
9265 (> (gnus-summary-thread-level) level))
9266 (gnus-summary-raise-score score))
9267 (setq e (point))))
9268 (let ((gnus-summary-check-current t))
9269 (or (zerop (gnus-summary-next-subject 1 t))
9270 (goto-char e))))
9271 (gnus-summary-recenter)
9272 (gnus-summary-position-cursor)
9273 (gnus-set-mode-line 'summary))
9274
9275 (defun gnus-summary-lower-same-subject-and-select (score)
9276 "Raise articles which has the same subject with SCORE and select the next."
9277 (interactive "p")
9278 (gnus-summary-raise-same-subject-and-select (- score)))
9279
9280 (defun gnus-summary-lower-same-subject (score)
9281 "Raise articles which has the same subject with SCORE."
9282 (interactive "p")
9283 (gnus-summary-raise-same-subject (- score)))
9284
9285 (defun gnus-summary-lower-thread (&optional score)
9286 "Lower score of articles in the current thread with SCORE."
9287 (interactive "P")
9288 (gnus-summary-raise-thread (- (1- (gnus-score-default score)))))
9289
9290 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9291 "Mark articles which has the same subject as read, and then select the next.
9292 If UNMARK is positive, remove any kind of mark.
9293 If UNMARK is negative, tick articles."
9294 (interactive "P")
9295 (if unmark
9296 (setq unmark (prefix-numeric-value unmark)))
9297 (let ((count
9298 (gnus-summary-mark-same-subject
9299 (gnus-summary-subject-string) unmark)))
9300 ;; Select next unread article. If auto-select-same mode, should
9301 ;; select the first unread article.
9302 (gnus-summary-next-article t (and gnus-auto-select-same
9303 (gnus-summary-subject-string)))
9304 (gnus-message 7 "%d article%s marked as %s"
9305 count (if (= count 1) " is" "s are")
9306 (if unmark "unread" "read"))))
9307
9308 (defun gnus-summary-kill-same-subject (&optional unmark)
9309 "Mark articles which has the same subject as read.
9310 If UNMARK is positive, remove any kind of mark.
9311 If UNMARK is negative, tick articles."
9312 (interactive "P")
9313 (if unmark
9314 (setq unmark (prefix-numeric-value unmark)))
9315 (let ((count
9316 (gnus-summary-mark-same-subject
9317 (gnus-summary-subject-string) unmark)))
9318 ;; If marked as read, go to next unread subject.
9319 (if (null unmark)
9320 ;; Go to next unread subject.
9321 (gnus-summary-next-subject 1 t))
9322 (gnus-message 7 "%d articles are marked as %s"
9323 count (if unmark "unread" "read"))))
9324
9325 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9326 "Mark articles with same SUBJECT as read, and return marked number.
9327 If optional argument UNMARK is positive, remove any kinds of marks.
9328 If optional argument UNMARK is negative, mark articles as unread instead."
9329 (let ((count 1))
9330 (save-excursion
9331 (cond
9332 ((null unmark) ; Mark as read.
9333 (while (and
9334 (progn
9335 (gnus-summary-mark-article-as-read gnus-killed-mark)
9336 (gnus-summary-show-thread) t)
9337 (gnus-summary-search-forward nil subject))
9338 (setq count (1+ count))))
9339 ((> unmark 0) ; Tick.
9340 (while (and
9341 (progn
9342 (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9343 (gnus-summary-show-thread) t)
9344 (gnus-summary-search-forward nil subject))
9345 (setq count (1+ count))))
9346 (t ; Mark as unread.
9347 (while (and
9348 (progn
9349 (gnus-summary-mark-article-as-unread gnus-unread-mark)
9350 (gnus-summary-show-thread) t)
9351 (gnus-summary-search-forward nil subject))
9352 (setq count (1+ count)))))
9353 (gnus-set-mode-line 'summary)
9354 ;; Return the number of marked articles.
9355 count)))
9356
9357 (defun gnus-summary-mark-as-processable (n &optional unmark)
9358 "Set the process mark on the next N articles.
9359 If N is negative, mark backward instead. If UNMARK is non-nil, remove
9360 the process mark instead. The difference between N and the actual
9361 number of articles marked is returned."
9362 (interactive "p")
9363 (let ((backward (< n 0))
9364 (n (abs n)))
9365 (while (and
9366 (> n 0)
9367 (if unmark
9368 (gnus-summary-remove-process-mark
9369 (gnus-summary-article-number))
9370 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9371 (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9372 (setq n (1- n)))
9373 (if (/= 0 n) (gnus-message 7 "No more articles"))
9374 (gnus-summary-recenter)
9375 (gnus-summary-position-cursor)
9376 n))
9377
9378 (defun gnus-summary-unmark-as-processable (n)
9379 "Remove the process mark from the next N articles.
9380 If N is negative, mark backward instead. The difference between N and
9381 the actual number of articles marked is returned."
9382 (interactive "p")
9383 (gnus-summary-mark-as-processable n t))
9384
9385 (defun gnus-summary-unmark-all-processable ()
9386 "Remove the process mark from all articles."
9387 (interactive)
9388 (save-excursion
9389 (while gnus-newsgroup-processable
9390 (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9391 (gnus-summary-position-cursor))
9392
9393 (defun gnus-summary-mark-as-expirable (n)
9394 "Mark N articles forward as expirable.
9395 If N is negative, mark backward instead. The difference between N and
9396 the actual number of articles marked is returned."
9397 (interactive "p")
9398 (gnus-summary-mark-forward n gnus-expirable-mark))
9399
9400 (defun gnus-summary-mark-article-as-replied (article)
9401 "Mark ARTICLE replied and update the summary line."
9402 (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
9403 (let ((buffer-read-only nil))
9404 (if (gnus-summary-goto-subject article)
9405 (progn
9406 (gnus-summary-update-mark gnus-replied-mark 'replied)
9407 t))))
9408
9409 (defun gnus-summary-set-bookmark (article)
9410 "Set a bookmark in current article."
9411 (interactive (list (gnus-summary-article-number)))
9412 (if (or (not (get-buffer gnus-article-buffer))
9413 (not gnus-current-article)
9414 (not gnus-article-current)
9415 (not (equal gnus-newsgroup-name (car gnus-article-current))))
9416 (error "No current article selected"))
9417 ;; Remove old bookmark, if one exists.
9418 (let ((old (assq article gnus-newsgroup-bookmarks)))
9419 (if old (setq gnus-newsgroup-bookmarks
9420 (delq old gnus-newsgroup-bookmarks))))
9421 ;; Set the new bookmark, which is on the form
9422 ;; (article-number . line-number-in-body).
9423 (setq gnus-newsgroup-bookmarks
9424 (cons
9425 (cons article
9426 (save-excursion
9427 (set-buffer gnus-article-buffer)
9428 (count-lines
9429 (min (point)
9430 (save-excursion
9431 (goto-char (point-min))
9432 (search-forward "\n\n" nil t)
9433 (point)))
9434 (point))))
9435 gnus-newsgroup-bookmarks))
9436 (gnus-message 6 "A bookmark has been added to the current article."))
9437
9438 (defun gnus-summary-remove-bookmark (article)
9439 "Remove the bookmark from the current article."
9440 (interactive (list (gnus-summary-article-number)))
9441 ;; Remove old bookmark, if one exists.
9442 (let ((old (assq article gnus-newsgroup-bookmarks)))
9443 (if old
9444 (progn
9445 (setq gnus-newsgroup-bookmarks
9446 (delq old gnus-newsgroup-bookmarks))
9447 (gnus-message 6 "Removed bookmark."))
9448 (gnus-message 6 "No bookmark in current article."))))
9449
9450 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9451 (defun gnus-summary-mark-as-dormant (n)
9452 "Mark N articles forward as dormant.
9453 If N is negative, mark backward instead. The difference between N and
9454 the actual number of articles marked is returned."
9455 (interactive "p")
9456 (gnus-summary-mark-forward n gnus-dormant-mark))
9457
9458 (defun gnus-summary-set-process-mark (article)
9459 "Set the process mark on ARTICLE and update the summary line."
9460 (setq gnus-newsgroup-processable
9461 (cons article
9462 (delq article gnus-newsgroup-processable)))
9463 (let ((buffer-read-only nil))
9464 (if (gnus-summary-goto-subject article)
9465 (progn
9466 (gnus-summary-show-thread)
9467 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9468 (forward-line 1))
9469 (gnus-summary-update-mark gnus-process-mark 'replied)
9470 t))))
9471
9472 (defun gnus-summary-remove-process-mark (article)
9473 "Remove the process mark from ARTICLE and update the summary line."
9474 (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9475 (let ((buffer-read-only nil))
9476 (if (gnus-summary-goto-subject article)
9477 (progn
9478 (gnus-summary-show-thread)
9479 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9480 (forward-line 1))
9481 (gnus-summary-update-mark ? 'replied)
9482 (if (memq article gnus-newsgroup-replied)
9483 (gnus-summary-update-mark gnus-replied-mark 'replied))
9484 t))))
9485
9486 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9487 "Mark N articles as read forwards.
9488 If N is negative, mark backwards instead.
9489 Mark with MARK. If MARK is ? , ?! or ??, articles will be
9490 marked as unread.
9491 The difference between N and the actual number of articles marked is
9492 returned."
9493 (interactive "p")
9494 (gnus-set-global-variables)
9495 (let ((backward (< n 0))
9496 (gnus-summary-goto-unread
9497 (and gnus-summary-goto-unread
9498 (not (memq mark (list gnus-unread-mark
9499 gnus-ticked-mark gnus-dormant-mark)))))
9500 (n (abs n))
9501 (mark (or mark gnus-del-mark)))
9502 (while (and (> n 0)
9503 (gnus-summary-mark-article nil mark no-expire)
9504 (zerop (gnus-summary-next-subject
9505 (if backward -1 1) gnus-summary-goto-unread t)))
9506 (setq n (1- n)))
9507 (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9508 (gnus-summary-recenter)
9509 (gnus-summary-position-cursor)
9510 (gnus-set-mode-line 'summary)
9511 n))
9512
9513 (defun gnus-summary-mark-article-as-read (mark)
9514 "Mark the current article quickly as read with MARK."
9515 (let ((article (gnus-summary-article-number)))
9516 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9517 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9518 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9519 (setq gnus-newsgroup-reads
9520 (cons (cons article mark) gnus-newsgroup-reads))
9521 ;; Possibly remove from cache, if that is used.
9522 (and gnus-use-cache (gnus-cache-enter-remove-article article))
9523 (and gnus-newsgroup-auto-expire
9524 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9525 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9526 (= mark gnus-read-mark))
9527 (progn
9528 (setq mark gnus-expirable-mark)
9529 (setq gnus-newsgroup-expirable
9530 (cons article gnus-newsgroup-expirable))))
9531 (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9532 (forward-line 1))
9533 ;; Fix the mark.
9534 (gnus-summary-update-mark mark 'unread)
9535 t))
9536
9537 (defun gnus-summary-mark-article-as-unread (mark)
9538 "Mark the current article quickly as unread with MARK."
9539 (let ((article (gnus-summary-article-number)))
9540 (or (memq article gnus-newsgroup-unreads)
9541 (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9542 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9543 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9544 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9545 (setq gnus-newsgroup-reads
9546 (delq (assq article gnus-newsgroup-reads)
9547 gnus-newsgroup-reads))
9548 (if (= mark gnus-ticked-mark)
9549 (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9550 (if (= mark gnus-dormant-mark)
9551 (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))
9552
9553 ;; See whether the article is to be put in the cache.
9554 (and gnus-use-cache
9555 (vectorp (gnus-get-header-by-num article))
9556 (save-excursion
9557 (gnus-cache-possibly-enter-article
9558 gnus-newsgroup-name article
9559 (gnus-get-header-by-num article)
9560 (= mark gnus-ticked-mark)
9561 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9562
9563 (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9564 (forward-line 1))
9565 ;; Fix the mark.
9566 (gnus-summary-update-mark mark 'unread)
9567 t))
9568
9569 (defun gnus-summary-mark-article (&optional article mark no-expire)
9570 "Mark ARTICLE with MARK. MARK can be any character.
9571 Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??'
9572 (dormant) and `?E' (expirable).
9573 If MARK is nil, then the default character `?D' is used.
9574 If ARTICLE is nil, then the article on the current line will be
9575 marked."
9576 (and (stringp mark)
9577 (setq mark (aref mark 0)))
9578 ;; If no mark is given, then we check auto-expiring.
9579 (and (not no-expire)
9580 gnus-newsgroup-auto-expire
9581 (or (not mark)
9582 (and (numberp mark)
9583 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9584 (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9585 (= mark gnus-read-mark))))
9586 (setq mark gnus-expirable-mark))
9587 (let* ((mark (or mark gnus-del-mark))
9588 (article (or article (gnus-summary-article-number))))
9589 (or article (error "No article on current line"))
9590 (if (or (= mark gnus-unread-mark)
9591 (= mark gnus-ticked-mark)
9592 (= mark gnus-dormant-mark))
9593 (gnus-mark-article-as-unread article mark)
9594 (gnus-mark-article-as-read article mark))
9595
9596 ;; See whether the article is to be put in the cache.
9597 (and gnus-use-cache
9598 (not (= mark gnus-canceled-mark))
9599 (vectorp (gnus-get-header-by-num article))
9600 (save-excursion
9601 (gnus-cache-possibly-enter-article
9602 gnus-newsgroup-name article
9603 (gnus-get-header-by-num article)
9604 (= mark gnus-ticked-mark)
9605 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9606
9607 (if (gnus-summary-goto-subject article)
9608 (let ((buffer-read-only nil))
9609 (gnus-summary-show-thread)
9610 (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9611 (forward-line 1))
9612 ;; Fix the mark.
9613 (gnus-summary-update-mark mark 'unread)
9614 t))))
9615
9616 (defun gnus-summary-update-mark (mark type)
9617 (beginning-of-line)
9618 (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9619 (buffer-read-only nil)
9620 plist)
9621 (if (not forward)
9622 ()
9623 (forward-char forward)
9624 (setq plist (text-properties-at (point)))
9625 (delete-char 1)
9626 (insert mark)
9627 (and plist (add-text-properties (1- (point)) (point) plist))
9628 (and (eq type 'unread)
9629 (progn
9630 (add-text-properties (1- (point)) (point) (list 'gnus-mark mark))
9631 (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9632
9633 (defun gnus-mark-article-as-read (article &optional mark)
9634 "Enter ARTICLE in the pertinent lists and remove it from others."
9635 ;; Make the article expirable.
9636 (let ((mark (or mark gnus-del-mark)))
9637 (if (= mark gnus-expirable-mark)
9638 (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
9639 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9640 ;; Remove from unread and marked lists.
9641 (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9642 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9643 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9644 (setq gnus-newsgroup-reads
9645 (cons (cons article mark) gnus-newsgroup-reads))
9646 ;; Possibly remove from cache, if that is used.
9647 (and gnus-use-cache (gnus-cache-enter-remove-article article))))
9648
9649 (defun gnus-mark-article-as-unread (article &optional mark)
9650 "Enter ARTICLE in the pertinent lists and remove it from others."
9651 (let ((mark (or mark gnus-ticked-mark)))
9652 ;; Add to unread list.
9653 (or (memq article gnus-newsgroup-unreads)
9654 (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9655 (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9656 (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9657 (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9658 (setq gnus-newsgroup-reads
9659 (delq (assq article gnus-newsgroup-reads)
9660 gnus-newsgroup-reads))
9661 (if (= mark gnus-ticked-mark)
9662 (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9663 (if (= mark gnus-dormant-mark)
9664 (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))))
9665
9666 (defalias 'gnus-summary-mark-as-unread-forward
9667 'gnus-summary-tick-article-forward)
9668 (make-obsolete 'gnus-summary-mark-as-unread-forward
9669 'gnus-summary-tick-article-forward)
9670 (defun gnus-summary-tick-article-forward (n)
9671 "Tick N articles forwards.
9672 If N is negative, tick backwards instead.
9673 The difference between N and the number of articles ticked is returned."
9674 (interactive "p")
9675 (gnus-summary-mark-forward n gnus-ticked-mark))
9676
9677 (defalias 'gnus-summary-mark-as-unread-backward
9678 'gnus-summary-tick-article-backward)
9679 (make-obsolete 'gnus-summary-mark-as-unread-backward
9680 'gnus-summary-tick-article-backward)
9681 (defun gnus-summary-tick-article-backward (n)
9682 "Tick N articles backwards.
9683 The difference between N and the number of articles ticked is returned."
9684 (interactive "p")
9685 (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9686
9687 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9688 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9689 (defun gnus-summary-tick-article (&optional article clear-mark)
9690 "Mark current article as unread.
9691 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9692 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9693 (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9694 gnus-ticked-mark)))
9695
9696 (defun gnus-summary-mark-as-read-forward (n)
9697 "Mark N articles as read forwards.
9698 If N is negative, mark backwards instead.
9699 The difference between N and the actual number of articles marked is
9700 returned."
9701 (interactive "p")
9702 (gnus-summary-mark-forward n gnus-del-mark t))
9703
9704 (defun gnus-summary-mark-as-read-backward (n)
9705 "Mark the N articles as read backwards.
9706 The difference between N and the actual number of articles marked is
9707 returned."
9708 (interactive "p")
9709 (gnus-summary-mark-forward (- n) gnus-del-mark t))
9710
9711 (defun gnus-summary-mark-as-read (&optional article mark)
9712 "Mark current article as read.
9713 ARTICLE specifies the article to be marked as read.
9714 MARK specifies a string to be inserted at the beginning of the line."
9715 (gnus-summary-mark-article article mark))
9716
9717 (defun gnus-summary-clear-mark-forward (n)
9718 "Clear marks from N articles forward.
9719 If N is negative, clear backward instead.
9720 The difference between N and the number of marks cleared is returned."
9721 (interactive "p")
9722 (gnus-summary-mark-forward n gnus-unread-mark))
9723
9724 (defun gnus-summary-clear-mark-backward (n)
9725 "Clear marks from N articles backward.
9726 The difference between N and the number of marks cleared is returned."
9727 (interactive "p")
9728 (gnus-summary-mark-forward (- n) gnus-unread-mark))
9729
9730 (defun gnus-summary-mark-unread-as-read ()
9731 "Intended to be used by `gnus-summary-mark-article-hook'."
9732 (or (memq gnus-current-article gnus-newsgroup-marked)
9733 (memq gnus-current-article gnus-newsgroup-dormant)
9734 (memq gnus-current-article gnus-newsgroup-expirable)
9735 (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9736
9737 (defun gnus-summary-mark-region-as-read (point mark all)
9738 "Mark all unread articles between point and mark as read.
9739 If given a prefix, mark all articles between point and mark as read,
9740 even ticked and dormant ones."
9741 (interactive "r\nP")
9742 (save-excursion
9743 (goto-char point)
9744 (beginning-of-line)
9745 (while (and
9746 (< (point) mark)
9747 (progn
9748 (and
9749 (or all
9750 (and
9751 (not (memq (gnus-summary-article-number)
9752 gnus-newsgroup-marked))
9753 (not (memq (gnus-summary-article-number)
9754 gnus-newsgroup-dormant))))
9755 (gnus-summary-mark-article
9756 (gnus-summary-article-number) gnus-del-mark))
9757 t)
9758 (zerop (forward-line 1))))))
9759
9760 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
9761 (defalias 'gnus-summary-delete-marked-as-read
9762 'gnus-summary-remove-lines-marked-as-read)
9763 (make-obsolete 'gnus-summary-delete-marked-as-read
9764 'gnus-summary-remove-lines-marked-as-read)
9765 (defun gnus-summary-remove-lines-marked-as-read ()
9766 "Remove lines that are marked as read."
9767 (interactive)
9768 (gnus-summary-remove-lines-marked-with
9769 (concat (mapconcat
9770 (lambda (char) (char-to-string (symbol-value char)))
9771 '(gnus-del-mark gnus-read-mark gnus-ancient-mark
9772 gnus-killed-mark gnus-kill-file-mark
9773 gnus-low-score-mark gnus-expirable-mark
9774 gnus-canceled-mark gnus-catchup-mark)
9775 ""))))
9776
9777 (defalias 'gnus-summary-delete-marked-with
9778 'gnus-summary-remove-lines-marked-with)
9779 (make-obsolete 'gnus-summary-delete-marked-with
9780 'gnus-summary-remove-lines-marked-with)
9781 ;; Rewrite by Daniel Quinlan <quinlan@best.com>.
9782 (defun gnus-summary-remove-lines-marked-with (marks)
9783 "Remove lines that are marked with MARKS (e.g. \"DK\")."
9784 (interactive "sMarks: ")
9785 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
9786 (gnus-set-global-variables)
9787 (let ((buffer-read-only nil)
9788 (orig-article
9789 (let ((gnus-summary-check-current t))
9790 (gnus-summary-search-forward t)
9791 (gnus-summary-article-number)))
9792 (marks (concat "^[" marks "]")))
9793 (goto-char (point-min))
9794 (if gnus-newsgroup-adaptive
9795 (gnus-score-remove-lines-adaptive marks)
9796 (while (re-search-forward marks nil t)
9797 (gnus-delete-line)))
9798 ;; If we use dummy roots, we have to do an additional sweep over
9799 ;; the buffer.
9800 (if (not (eq gnus-summary-make-false-root 'dummy))
9801 ()
9802 (goto-char (point-min))
9803 (setq marks (concat "^[" (char-to-string gnus-dummy-mark) "]"))
9804 (while (re-search-forward marks nil t)
9805 (if (gnus-subject-equal
9806 (gnus-summary-subject-string)
9807 (progn
9808 (forward-line 1)
9809 (gnus-summary-subject-string)))
9810 ()
9811 (forward-line -1)
9812 (gnus-delete-line))))
9813 (or (zerop (buffer-size))
9814 (gnus-summary-goto-subject orig-article)
9815 (if (eobp)
9816 (gnus-summary-prev-subject 1)
9817 (gnus-summary-position-cursor)))))
9818
9819 (defun gnus-summary-expunge-below (&optional score)
9820 "Remove articles with score less than SCORE."
9821 (interactive "P")
9822 (gnus-set-global-variables)
9823 (setq score (if score
9824 (prefix-numeric-value score)
9825 (or gnus-summary-default-score 0)))
9826 (save-excursion
9827 (set-buffer gnus-summary-buffer)
9828 (goto-char (point-min))
9829 (let ((buffer-read-only nil)
9830 beg)
9831 (while (not (eobp))
9832 (if (< (gnus-summary-article-score) score)
9833 (progn
9834 (setq beg (point))
9835 (forward-line 1)
9836 (delete-region beg (point)))
9837 (forward-line 1)))
9838 ;; Adjust point.
9839 (or (zerop (buffer-size))
9840 (if (eobp)
9841 (gnus-summary-prev-subject 1)
9842 (gnus-summary-position-cursor))))))
9843
9844 (defun gnus-summary-mark-below (score mark)
9845 "Mark articles with score less than SCORE with MARK."
9846 (interactive "P\ncMark: ")
9847 (gnus-set-global-variables)
9848 (setq score (if score
9849 (prefix-numeric-value score)
9850 (or gnus-summary-default-score 0)))
9851 (save-excursion
9852 (set-buffer gnus-summary-buffer)
9853 (goto-char (point-min))
9854 (while (not (eobp))
9855 (and (< (gnus-summary-article-score) score)
9856 (gnus-summary-mark-article nil mark))
9857 (forward-line 1))))
9858
9859 (defun gnus-summary-kill-below (&optional score)
9860 "Mark articles with score below SCORE as read."
9861 (interactive "P")
9862 (gnus-set-global-variables)
9863 (gnus-summary-mark-below score gnus-killed-mark))
9864
9865 (defun gnus-summary-clear-above (&optional score)
9866 "Clear all marks from articles with score above SCORE."
9867 (interactive "P")
9868 (gnus-set-global-variables)
9869 (gnus-summary-mark-above score gnus-unread-mark))
9870
9871 (defun gnus-summary-tick-above (&optional score)
9872 "Tick all articles with score above SCORE."
9873 (interactive "P")
9874 (gnus-set-global-variables)
9875 (gnus-summary-mark-above score gnus-ticked-mark))
9876
9877 (defun gnus-summary-mark-above (score mark)
9878 "Mark articles with score over SCORE with MARK."
9879 (interactive "P\ncMark: ")
9880 (gnus-set-global-variables)
9881 (setq score (if score
9882 (prefix-numeric-value score)
9883 (or gnus-summary-default-score 0)))
9884 (save-excursion
9885 (set-buffer gnus-summary-buffer)
9886 (goto-char (point-min))
9887 (while (not (eobp))
9888 (if (> (gnus-summary-article-score) score)
9889 (progn
9890 (gnus-summary-mark-article nil mark)
9891 (forward-line 1))
9892 (forward-line 1)))))
9893
9894 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9895 (defun gnus-summary-show-all-expunged ()
9896 "Display all the hidden articles that were expunged for low scores."
9897 (interactive)
9898 (gnus-set-global-variables)
9899 (let ((buffer-read-only nil))
9900 (let ((scored gnus-newsgroup-scored)
9901 headers h)
9902 (while scored
9903 (or (gnus-summary-goto-subject (car (car scored)))
9904 (and (setq h (gnus-get-header-by-num (car (car scored))))
9905 (< (cdr (car scored)) gnus-summary-expunge-below)
9906 (setq headers (cons h headers))))
9907 (setq scored (cdr scored)))
9908 (or headers (error "No expunged articles hidden."))
9909 (goto-char (point-min))
9910 (save-excursion
9911 (gnus-summary-update-lines
9912 (point)
9913 (progn
9914 (gnus-summary-prepare-unthreaded (nreverse headers))
9915 (point)))))
9916 (goto-char (point-min))
9917 (gnus-summary-position-cursor)))
9918
9919 (defun gnus-summary-show-all-dormant ()
9920 "Display all the hidden articles that are marked as dormant."
9921 (interactive)
9922 (gnus-set-global-variables)
9923 (let ((buffer-read-only nil))
9924 (let ((dormant gnus-newsgroup-dormant)
9925 headers h)
9926 (while dormant
9927 (or (gnus-summary-goto-subject (car dormant))
9928 (and (setq h (gnus-get-header-by-num (car dormant)))
9929 (setq headers (cons h headers))))
9930 (setq dormant (cdr dormant)))
9931 (or headers (error "No dormant articles hidden."))
9932 (goto-char (point-min))
9933 (save-excursion
9934 (gnus-summary-update-lines
9935 (point)
9936 (progn
9937 (gnus-summary-prepare-unthreaded (nreverse headers))
9938 (point)))))
9939 (goto-char (point-min))
9940 (gnus-summary-position-cursor)))
9941
9942 (defun gnus-summary-hide-all-dormant ()
9943 "Hide all dormant articles."
9944 (interactive)
9945 (gnus-set-global-variables)
9946 (gnus-summary-remove-lines-marked-with (char-to-string gnus-dormant-mark))
9947 (gnus-summary-position-cursor))
9948
9949 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
9950 "Mark all articles not marked as unread in this newsgroup as read.
9951 If prefix argument ALL is non-nil, all articles are marked as read.
9952 If QUIETLY is non-nil, no questions will be asked.
9953 If TO-HERE is non-nil, it should be a point in the buffer. All
9954 articles before this point will be marked as read.
9955 The number of articles marked as read is returned."
9956 (interactive "P")
9957 (gnus-set-global-variables)
9958 (prog1
9959 (if (or quietly
9960 (not gnus-interactive-catchup) ;Without confirmation?
9961 gnus-expert-user
9962 (gnus-y-or-n-p
9963 (if all
9964 "Mark absolutely all articles as read? "
9965 "Mark all unread articles as read? ")))
9966 (if (and not-mark
9967 (not gnus-newsgroup-adaptive)
9968 (not gnus-newsgroup-auto-expire))
9969 (progn
9970 (and all (setq gnus-newsgroup-marked nil
9971 gnus-newsgroup-dormant nil))
9972 (setq gnus-newsgroup-unreads
9973 (append gnus-newsgroup-marked gnus-newsgroup-dormant)))
9974 ;; We actually mark all articles as canceled, which we
9975 ;; have to do when using auto-expiry or adaptive scoring.
9976 (gnus-summary-show-all-threads)
9977 (if (gnus-summary-first-subject (not all))
9978 (while (and
9979 (if to-here (< (point) to-here) t)
9980 (gnus-summary-mark-article-as-read gnus-catchup-mark)
9981 (gnus-summary-search-subject nil (not all)))))
9982 (or to-here
9983 (setq gnus-newsgroup-unreads
9984 (append gnus-newsgroup-marked
9985 gnus-newsgroup-dormant)))))
9986 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
9987 (if (and (not to-here) (eq 'nnvirtual (car method)))
9988 (nnvirtual-catchup-group
9989 (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
9990 (gnus-summary-position-cursor)))
9991
9992 (defun gnus-summary-catchup-to-here (&optional all)
9993 "Mark all unticked articles before the current one as read.
9994 If ALL is non-nil, also mark ticked and dormant articles as read."
9995 (interactive "P")
9996 (gnus-set-global-variables)
9997 (save-excursion
9998 (and (zerop (forward-line -1))
9999 (progn
10000 (end-of-line)
10001 (gnus-summary-catchup all t (point))
10002 (gnus-set-mode-line 'summary))))
10003 (gnus-summary-position-cursor))
10004
10005 (defun gnus-summary-catchup-all (&optional quietly)
10006 "Mark all articles in this newsgroup as read."
10007 (interactive "P")
10008 (gnus-set-global-variables)
10009 (gnus-summary-catchup t quietly))
10010
10011 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10012 "Mark all articles not marked as unread in this newsgroup as read, then exit.
10013 If prefix argument ALL is non-nil, all articles are marked as read."
10014 (interactive "P")
10015 (gnus-set-global-variables)
10016 (gnus-summary-catchup all quietly nil 'fast)
10017 ;; Select next newsgroup or exit.
10018 (if (and (eq gnus-auto-select-next 'quietly)
10019 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
10020 (gnus-summary-next-group nil)
10021 (gnus-summary-exit)))
10022
10023 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10024 "Mark all articles in this newsgroup as read, and then exit."
10025 (interactive "P")
10026 (gnus-set-global-variables)
10027 (gnus-summary-catchup-and-exit t quietly))
10028
10029 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
10030 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10031 "Mark all articles in this group as read and select the next group.
10032 If given a prefix, mark all articles, unread as well as ticked, as
10033 read."
10034 (interactive "P")
10035 (gnus-set-global-variables)
10036 (gnus-summary-catchup all)
10037 (gnus-summary-next-group))
10038
10039 ;; Thread-based commands.
10040
10041 (defun gnus-summary-toggle-threads (&optional arg)
10042 "Toggle showing conversation threads.
10043 If ARG is positive number, turn showing conversation threads on."
10044 (interactive "P")
10045 (gnus-set-global-variables)
10046 (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10047 (setq gnus-show-threads
10048 (if (null arg) (not gnus-show-threads)
10049 (> (prefix-numeric-value arg) 0)))
10050 (gnus-summary-prepare)
10051 (gnus-summary-goto-subject current)
10052 (gnus-summary-position-cursor)))
10053
10054 (defun gnus-summary-show-all-threads ()
10055 "Show all threads."
10056 (interactive)
10057 (gnus-set-global-variables)
10058 (save-excursion
10059 (let ((buffer-read-only nil))
10060 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10061 (gnus-summary-position-cursor))
10062
10063 (defun gnus-summary-show-thread ()
10064 "Show thread subtrees.
10065 Returns nil if no thread was there to be shown."
10066 (interactive)
10067 (gnus-set-global-variables)
10068 (let ((buffer-read-only nil)
10069 (orig (prog1 (point) (gnus-summary-hide-thread)))
10070 ;; first goto end then to beg, to have point at beg after let
10071 (end (progn (end-of-line) (point)))
10072 (beg (progn (beginning-of-line) (point))))
10073 (prog1
10074 ;; Any hidden lines here?
10075 (search-forward "\r" end t)
10076 (subst-char-in-region beg end ?\^M ?\n t)
10077 (goto-char orig)
10078 (gnus-summary-position-cursor))))
10079
10080 (defun gnus-summary-hide-all-threads ()
10081 "Hide all thread subtrees."
10082 (interactive)
10083 (gnus-set-global-variables)
10084 (save-excursion
10085 (goto-char (point-min))
10086 (gnus-summary-hide-thread)
10087 (while (and (not (eobp)) (zerop (forward-line 1)))
10088 (gnus-summary-hide-thread)))
10089 (gnus-summary-position-cursor))
10090
10091 (defun gnus-summary-hide-thread ()
10092 "Hide thread subtrees.
10093 Returns nil if no threads were there to be hidden."
10094 (interactive)
10095 (gnus-set-global-variables)
10096 (let ((buffer-read-only nil)
10097 (start (point))
10098 (level (gnus-summary-thread-level))
10099 (end (point)))
10100 ;; Go forward until either the buffer ends or the subthread
10101 ;; ends.
10102 (if (eobp)
10103 ()
10104 (while (and (zerop (forward-line 1))
10105 (> (gnus-summary-thread-level) level))
10106 (setq end (point)))
10107 (prog1
10108 (save-excursion
10109 (goto-char end)
10110 (search-backward "\n" start t))
10111 (subst-char-in-region start end ?\n ?\^M t)
10112 (forward-line -1)
10113 (gnus-summary-position-cursor)))))
10114
10115 (defun gnus-summary-go-to-next-thread (&optional previous)
10116 "Go to the same level (or less) next thread.
10117 If PREVIOUS is non-nil, go to previous thread instead.
10118 Return the article number moved to, or nil if moving was impossible."
10119 (let ((level (gnus-summary-thread-level))
10120 (article (gnus-summary-article-number)))
10121 (if previous
10122 (while (and (zerop (forward-line -1))
10123 (> (gnus-summary-thread-level) level)))
10124 (while (and (save-excursion
10125 (forward-line 1)
10126 (not (eobp)))
10127 (zerop (forward-line 1))
10128 (> (gnus-summary-thread-level) level))))
10129 (gnus-summary-recenter)
10130 (gnus-summary-position-cursor)
10131 (let ((oart (gnus-summary-article-number)))
10132 (and (/= oart article) oart))))
10133
10134 (defun gnus-summary-next-thread (n)
10135 "Go to the same level next N'th thread.
10136 If N is negative, search backward instead.
10137 Returns the difference between N and the number of skips actually
10138 done."
10139 (interactive "p")
10140 (gnus-set-global-variables)
10141 (let ((backward (< n 0))
10142 (n (abs n)))
10143 (while (and (> n 0)
10144 (gnus-summary-go-to-next-thread backward))
10145 (setq n (1- n)))
10146 (gnus-summary-position-cursor)
10147 (if (/= 0 n) (gnus-message 7 "No more threads"))
10148 n))
10149
10150 (defun gnus-summary-prev-thread (n)
10151 "Go to the same level previous N'th thread.
10152 Returns the difference between N and the number of skips actually
10153 done."
10154 (interactive "p")
10155 (gnus-set-global-variables)
10156 (gnus-summary-next-thread (- n)))
10157
10158 (defun gnus-summary-go-down-thread (&optional same)
10159 "Go down one level in the current thread.
10160 If SAME is non-nil, also move to articles of the same level."
10161 (let ((level (gnus-summary-thread-level))
10162 (start (point)))
10163 (if (and (zerop (forward-line 1))
10164 (> (gnus-summary-thread-level) level))
10165 t
10166 (goto-char start)
10167 nil)))
10168
10169 (defun gnus-summary-go-up-thread ()
10170 "Go up one level in the current thread."
10171 (let ((level (gnus-summary-thread-level))
10172 (start (point)))
10173 (while (and (zerop (forward-line -1))
10174 (>= (gnus-summary-thread-level) level)))
10175 (if (>= (gnus-summary-thread-level) level)
10176 (progn
10177 (goto-char start)
10178 nil)
10179 t)))
10180
10181 (defun gnus-summary-down-thread (n)
10182 "Go down thread N steps.
10183 If N is negative, go up instead.
10184 Returns the difference between N and how many steps down that were
10185 taken."
10186 (interactive "p")
10187 (gnus-set-global-variables)
10188 (let ((up (< n 0))
10189 (n (abs n)))
10190 (while (and (> n 0)
10191 (if up (gnus-summary-go-up-thread)
10192 (gnus-summary-go-down-thread)))
10193 (setq n (1- n)))
10194 (gnus-summary-position-cursor)
10195 (if (/= 0 n) (gnus-message 7 "Can't go further"))
10196 n))
10197
10198 (defun gnus-summary-up-thread (n)
10199 "Go up thread N steps.
10200 If N is negative, go up instead.
10201 Returns the difference between N and how many steps down that were
10202 taken."
10203 (interactive "p")
10204 (gnus-set-global-variables)
10205 (gnus-summary-down-thread (- n)))
10206
10207 (defun gnus-summary-kill-thread (&optional unmark)
10208 "Mark articles under current thread as read.
10209 If the prefix argument is positive, remove any kinds of marks.
10210 If the prefix argument is negative, tick articles instead."
10211 (interactive "P")
10212 (gnus-set-global-variables)
10213 (if unmark
10214 (setq unmark (prefix-numeric-value unmark)))
10215 (let ((killing t)
10216 (level (gnus-summary-thread-level)))
10217 (save-excursion
10218 ;; Expand the thread.
10219 (gnus-summary-show-thread)
10220 (while killing
10221 ;; Mark the article...
10222 (cond ((null unmark) (gnus-summary-mark-article-as-read
10223 gnus-killed-mark))
10224 ((> unmark 0) (gnus-summary-mark-article-as-unread
10225 gnus-unread-mark))
10226 (t (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10227 ;; ...and go forward until either the buffer ends or the subtree
10228 ;; ends.
10229 (if (not (and (zerop (forward-line 1))
10230 (> (gnus-summary-thread-level) level)))
10231 (setq killing nil))))
10232 ;; Hide killed subtrees.
10233 (and (null unmark)
10234 gnus-thread-hide-killed
10235 (gnus-summary-hide-thread))
10236 ;; If marked as read, go to next unread subject.
10237 (if (null unmark)
10238 ;; Go to next unread subject.
10239 (gnus-summary-next-subject 1 t)))
10240 (gnus-set-mode-line 'summary))
10241
10242 ;; Summary sorting commands
10243
10244 (defun gnus-summary-sort-by-number (&optional reverse)
10245 "Sort summary buffer by article number.
10246 Argument REVERSE means reverse order."
10247 (interactive "P")
10248 (gnus-set-global-variables)
10249 (gnus-summary-sort
10250 ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants
10251 ;; a function, so we wrap it.
10252 (cons (lambda () (gnus-summary-article-number))
10253 'gnus-thread-sort-by-number) reverse))
10254
10255 (defun gnus-summary-sort-by-author (&optional reverse)
10256 "Sort summary buffer by author name alphabetically.
10257 If case-fold-search is non-nil, case of letters is ignored.
10258 Argument REVERSE means reverse order."
10259 (interactive "P")
10260 (gnus-set-global-variables)
10261 (gnus-summary-sort
10262 (cons
10263 (lambda ()
10264 (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10265 extract)
10266 (if (not (vectorp header))
10267 ""
10268 (setq extract (funcall gnus-extract-address-components
10269 (mail-header-from header)))
10270 (concat (or (car extract) (cdr extract))
10271 "\r" (int-to-string (mail-header-number header))
10272 "\r" (mail-header-subject header)))))
10273 'gnus-thread-sort-by-author)
10274 reverse))
10275
10276 (defun gnus-summary-sort-by-subject (&optional reverse)
10277 "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
10278 If case-fold-search is non-nil, case of letters is ignored.
10279 Argument REVERSE means reverse order."
10280 (interactive "P")
10281 (gnus-set-global-variables)
10282 (gnus-summary-sort
10283 (cons
10284 (lambda ()
10285 (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10286 extract)
10287 (if (not (vectorp header))
10288 ""
10289 (setq extract (funcall gnus-extract-address-components
10290 (mail-header-from header)))
10291 (concat
10292 (downcase (gnus-simplify-subject (gnus-summary-subject-string) t))
10293 "\r" (int-to-string (mail-header-number header))
10294 "\r" (or (car extract) (cdr extract))))))
10295 'gnus-thread-sort-by-subject)
10296 reverse))
10297
10298 (defun gnus-summary-sort-by-date (&optional reverse)
10299 "Sort summary buffer by date.
10300 Argument REVERSE means reverse order."
10301 (interactive "P")
10302 (gnus-set-global-variables)
10303 (gnus-summary-sort
10304 (cons
10305 (lambda ()
10306 (gnus-sortable-date
10307 (mail-header-date
10308 (gnus-get-header-by-num (gnus-summary-article-number)))))
10309 'gnus-thread-sort-by-date)
10310 reverse))
10311
10312 (defun gnus-summary-sort-by-score (&optional reverse)
10313 "Sort summary buffer by score.
10314 Argument REVERSE means reverse order."
10315 (interactive "P")
10316 (gnus-set-global-variables)
10317 (gnus-summary-sort
10318 (cons (lambda () (gnus-summary-article-score))
10319 'gnus-thread-sort-by-score)
10320 (not reverse)))
10321
10322 (defvar gnus-summary-already-sorted nil)
10323 (defun gnus-summary-sort (predicate reverse)
10324 ;; Sort summary buffer by PREDICATE. REVERSE means reverse order.
10325 (if gnus-summary-already-sorted
10326 ()
10327 (let (buffer-read-only)
10328 (if (not gnus-show-threads)
10329 ;; We do untreaded sorting...
10330 (progn
10331 (goto-char (point-min))
10332 (sort-subr reverse 'forward-line 'end-of-line (car predicate)))
10333 ;; ... or we do threaded sorting.
10334 (let ((gnus-thread-sort-functions (list (cdr predicate)))
10335 (gnus-summary-prepare-hook nil)
10336 (gnus-summary-already-sorted nil))
10337 ;; We do that by simply regenerating the threads.
10338 (gnus-summary-prepare)
10339 (and gnus-show-threads
10340 gnus-thread-hide-subtree
10341 (gnus-summary-hide-all-threads))
10342 ;; If in async mode, we send some info to the backend.
10343 (and gnus-newsgroup-async
10344 (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
10345 (gnus-request-asynchronous
10346 gnus-newsgroup-name
10347 (if (and gnus-asynchronous-article-function
10348 (fboundp gnus-asynchronous-article-function))
10349 (funcall gnus-asynchronous-article-function
10350 gnus-newsgroup-threads)
10351 gnus-newsgroup-threads))))))))
10352
10353
10354 (defun gnus-sortable-date (date)
10355 "Make sortable string by string-lessp from DATE.
10356 Timezone package is used."
10357 (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S]
10358 (year (aref date 0))
10359 (month (aref date 1))
10360 (day (aref date 2)))
10361 (timezone-make-sortable-date
10362 year month day
10363 (timezone-make-time-string
10364 (aref date 3) (aref date 4) (aref date 5)))))
10365
10366
10367 ;; Summary saving commands.
10368
10369 (defun gnus-summary-save-article (&optional n)
10370 "Save the current article using the default saver function.
10371 If N is a positive number, save the N next articles.
10372 If N is a negative number, save the N previous articles.
10373 If N is nil and any articles have been marked with the process mark,
10374 save those articles instead.
10375 The variable `gnus-default-article-saver' specifies the saver function."
10376 (interactive "P")
10377 (gnus-set-global-variables)
10378 (let ((articles (gnus-summary-work-articles n)))
10379 (while articles
10380 (let ((header (gnus-get-header-by-num (car articles))))
10381 (if (vectorp header)
10382 (progn
10383 (save-window-excursion
10384 (gnus-summary-select-article t nil nil (car articles)))
10385 (or gnus-save-all-headers
10386 (gnus-article-hide-headers t))
10387 ;; Remove any X-Gnus lines.
10388 (save-excursion
10389 (save-restriction
10390 (set-buffer gnus-article-buffer)
10391 (let ((buffer-read-only nil))
10392 (goto-char (point-min))
10393 (narrow-to-region (point) (or (search-forward "\n\n" nil t)
10394 (point-max)))
10395 (while (re-search-forward "^X-Gnus" nil t)
10396 (beginning-of-line)
10397 (delete-region (point)
10398 (progn (forward-line 1) (point))))
10399 (widen))))
10400 (save-window-excursion
10401 (if gnus-default-article-saver
10402 (funcall gnus-default-article-saver)
10403 (error "No default saver is defined."))))
10404 (if (assq 'name header)
10405 (gnus-copy-file (cdr (assq 'name header)))
10406 (gnus-message 1 "Article %d is unsavable" (car articles)))))
10407 (gnus-summary-remove-process-mark (car articles))
10408 (setq articles (cdr articles)))
10409 (gnus-summary-position-cursor)
10410 n))
10411
10412 (defun gnus-summary-pipe-output (&optional arg)
10413 "Pipe the current article to a subprocess.
10414 If N is a positive number, pipe the N next articles.
10415 If N is a negative number, pipe the N previous articles.
10416 If N is nil and any articles have been marked with the process mark,
10417 pipe those articles instead."
10418 (interactive "P")
10419 (gnus-set-global-variables)
10420 (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10421 (gnus-summary-save-article arg)))
10422
10423 (defun gnus-summary-save-article-mail (&optional arg)
10424 "Append the current article to an mail file.
10425 If N is a positive number, save the N next articles.
10426 If N is a negative number, save the N previous articles.
10427 If N is nil and any articles have been marked with the process mark,
10428 save those articles instead."
10429 (interactive "P")
10430 (gnus-set-global-variables)
10431 (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10432 (gnus-summary-save-article arg)))
10433
10434 (defun gnus-summary-save-article-rmail (&optional arg)
10435 "Append the current article to an rmail file.
10436 If N is a positive number, save the N next articles.
10437 If N is a negative number, save the N previous articles.
10438 If N is nil and any articles have been marked with the process mark,
10439 save those articles instead."
10440 (interactive "P")
10441 (gnus-set-global-variables)
10442 (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10443 (gnus-summary-save-article arg)))
10444
10445 (defun gnus-summary-save-article-file (&optional arg)
10446 "Append the current article to a file.
10447 If N is a positive number, save the N next articles.
10448 If N is a negative number, save the N previous articles.
10449 If N is nil and any articles have been marked with the process mark,
10450 save those articles instead."
10451 (interactive "P")
10452 (gnus-set-global-variables)
10453 (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10454 (gnus-summary-save-article arg)))
10455
10456 (defun gnus-read-save-file-name (prompt default-name)
10457 (let ((methods gnus-split-methods)
10458 split-name)
10459 (if (not gnus-split-methods)
10460 ()
10461 (save-excursion
10462 (set-buffer gnus-article-buffer)
10463 (gnus-narrow-to-headers)
10464 (while methods
10465 (goto-char (point-min))
10466 (and (condition-case ()
10467 (re-search-forward (car (car methods)) nil t)
10468 (error nil))
10469 (setq split-name (cons (nth 1 (car methods)) split-name)))
10470 (setq methods (cdr methods)))
10471 (widen)))
10472 (cond ((null split-name)
10473 (read-file-name
10474 (concat prompt " (default "
10475 (file-name-nondirectory default-name) ") ")
10476 (file-name-directory default-name)
10477 default-name))
10478 ((= 1 (length split-name))
10479 (read-file-name
10480 (concat prompt " (default " (car split-name) ") ")
10481 gnus-article-save-directory
10482 (concat gnus-article-save-directory (car split-name))))
10483 (t
10484 (setq split-name (mapcar (lambda (el) (list el))
10485 (nreverse split-name)))
10486 (let ((result (completing-read
10487 (concat prompt " ")
10488 split-name nil nil)))
10489 (concat gnus-article-save-directory
10490 (if (string= result "")
10491 (car (car split-name))
10492 result)))))))
10493
10494 (defun gnus-summary-save-in-rmail (&optional filename)
10495 "Append this article to Rmail file.
10496 Optional argument FILENAME specifies file name.
10497 Directory to save to is default to `gnus-article-save-directory' which
10498 is initialized from the SAVEDIR environment variable."
10499 (interactive)
10500 (gnus-set-global-variables)
10501 (let ((default-name
10502 (funcall gnus-rmail-save-name gnus-newsgroup-name
10503 gnus-current-headers gnus-newsgroup-last-rmail)))
10504 (or filename
10505 (setq filename (gnus-read-save-file-name
10506 "Save in rmail file:" default-name)))
10507 (gnus-make-directory (file-name-directory filename))
10508 (gnus-eval-in-buffer-window
10509 gnus-article-buffer
10510 (save-excursion
10511 (save-restriction
10512 (widen)
10513 (gnus-output-to-rmail filename))))
10514 ;; Remember the directory name to save articles
10515 (setq gnus-newsgroup-last-rmail filename)))
10516
10517 (defun gnus-summary-save-in-mail (&optional filename)
10518 "Append this article to Unix mail file.
10519 Optional argument FILENAME specifies file name.
10520 Directory to save to is default to `gnus-article-save-directory' which
10521 is initialized from the SAVEDIR environment variable."
10522 (interactive)
10523 (gnus-set-global-variables)
10524 (let ((default-name
10525 (funcall gnus-mail-save-name gnus-newsgroup-name
10526 gnus-current-headers gnus-newsgroup-last-mail)))
10527 (or filename
10528 (setq filename (gnus-read-save-file-name
10529 "Save in Unix mail file:" default-name)))
10530 (setq filename
10531 (expand-file-name filename
10532 (and default-name
10533 (file-name-directory default-name))))
10534 (gnus-make-directory (file-name-directory filename))
10535 (gnus-eval-in-buffer-window
10536 gnus-article-buffer
10537 (save-excursion
10538 (save-restriction
10539 (widen)
10540 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
10541 (gnus-output-to-rmail filename)
10542 (rmail-output filename 1 t t)))))
10543 ;; Remember the directory name to save articles.
10544 (setq gnus-newsgroup-last-mail filename)))
10545
10546 (defun gnus-summary-save-in-file (&optional filename)
10547 "Append this article to file.
10548 Optional argument FILENAME specifies file name.
10549 Directory to save to is default to `gnus-article-save-directory' which
10550 is initialized from the SAVEDIR environment variable."
10551 (interactive)
10552 (gnus-set-global-variables)
10553 (let ((default-name
10554 (funcall gnus-file-save-name gnus-newsgroup-name
10555 gnus-current-headers gnus-newsgroup-last-file)))
10556 (or filename
10557 (setq filename (gnus-read-save-file-name
10558 "Save in file:" default-name)))
10559 (gnus-make-directory (file-name-directory filename))
10560 (gnus-eval-in-buffer-window
10561 gnus-article-buffer
10562 (save-excursion
10563 (save-restriction
10564 (widen)
10565 (gnus-output-to-file filename))))
10566 ;; Remember the directory name to save articles.
10567 (setq gnus-newsgroup-last-file filename)))
10568
10569 (defun gnus-summary-save-in-pipe (&optional command)
10570 "Pipe this article to subprocess."
10571 (interactive)
10572 (gnus-set-global-variables)
10573 (let ((command (read-string "Shell command on article: "
10574 gnus-last-shell-command)))
10575 (if (string-equal command "")
10576 (setq command gnus-last-shell-command))
10577 (gnus-eval-in-buffer-window
10578 gnus-article-buffer
10579 (save-restriction
10580 (widen)
10581 (shell-command-on-region (point-min) (point-max) command nil)))
10582 (setq gnus-last-shell-command command)))
10583
10584 ;; Summary extract commands
10585
10586 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10587 (let ((buffer-read-only nil)
10588 (article (gnus-summary-article-number))
10589 b)
10590 (or (gnus-summary-goto-subject article)
10591 (error (format "No such article: %d" article)))
10592 (gnus-summary-position-cursor)
10593 ;; If all commands are to be bunched up on one line, we collect
10594 ;; them here.
10595 (if gnus-view-pseudos-separately
10596 ()
10597 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10598 files action)
10599 (while ps
10600 (setq action (cdr (assq 'action (car ps))))
10601 (setq files (list (cdr (assq 'name (car ps)))))
10602 (while (and ps (cdr ps)
10603 (string= (or action "1")
10604 (or (cdr (assq 'action (car (cdr ps)))) "2")))
10605 (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
10606 (setcdr ps (cdr (cdr ps))))
10607 (if (not files)
10608 ()
10609 (if (not (string-match "%s" action))
10610 (setq files (cons " " files)))
10611 (setq files (cons " " files))
10612 (and (assq 'execute (car ps))
10613 (setcdr (assq 'execute (car ps))
10614 (funcall (if (string-match "%s" action)
10615 'format 'concat)
10616 action
10617 (mapconcat (lambda (f) f) files " ")))))
10618 (setq ps (cdr ps)))))
10619 (if (and gnus-view-pseudos (not not-view))
10620 (while pslist
10621 (and (assq 'execute (car pslist))
10622 (gnus-execute-command (cdr (assq 'execute (car pslist)))
10623 (eq gnus-view-pseudos 'not-confirm)))
10624 (setq pslist (cdr pslist)))
10625 (save-excursion
10626 (while pslist
10627 (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
10628 (gnus-summary-article-number)))
10629 (forward-line 1)
10630 (setq b (point))
10631 (insert " " (file-name-nondirectory
10632 (cdr (assq 'name (car pslist))))
10633 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10634 (add-text-properties
10635 b (1+ b) (list 'gnus-number gnus-reffed-article-number
10636 'gnus-mark gnus-unread-mark
10637 'gnus-level 0
10638 'gnus-pseudo (car pslist)))
10639 (forward-line -1)
10640 (gnus-sethash (int-to-string gnus-reffed-article-number)
10641 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
10642 (setq gnus-newsgroup-unreads
10643 (cons gnus-reffed-article-number gnus-newsgroup-unreads))
10644 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10645 (setq pslist (cdr pslist)))))))
10646
10647 (defun gnus-pseudos< (p1 p2)
10648 (let ((c1 (cdr (assq 'action p1)))
10649 (c2 (cdr (assq 'action p2))))
10650 (and c1 c2 (string< c1 c2))))
10651
10652 (defun gnus-request-pseudo-article (props)
10653 (cond ((assq 'execute props)
10654 (gnus-execute-command (cdr (assq 'execute props)))))
10655 (let ((gnus-current-article (gnus-summary-article-number)))
10656 (run-hooks 'gnus-mark-article-hook)))
10657
10658 (defun gnus-execute-command (command &optional automatic)
10659 (save-excursion
10660 (gnus-article-setup-buffer)
10661 (set-buffer gnus-article-buffer)
10662 (let ((command (if automatic command (read-string "Command: " command)))
10663 (buffer-read-only nil))
10664 (erase-buffer)
10665 (insert "$ " command "\n\n")
10666 (if gnus-view-pseudo-asynchronously
10667 (start-process "gnus-execute" nil "sh" "-c" command)
10668 (call-process "sh" nil t nil "-c" command)))))
10669
10670 (defun gnus-copy-file (file &optional to)
10671 "Copy FILE to TO."
10672 (interactive
10673 (list (read-file-name "Copy file: " default-directory)
10674 (read-file-name "Copy file to: " default-directory)))
10675 (gnus-set-global-variables)
10676 (or to (setq to (read-file-name "Copy file to: " default-directory)))
10677 (and (file-directory-p to)
10678 (setq to (concat (file-name-as-directory to)
10679 (file-name-nondirectory file))))
10680 (copy-file file to))
10681
10682 ;; Summary kill commands.
10683
10684 (defun gnus-summary-edit-global-kill (article)
10685 "Edit the \"global\" kill file."
10686 (interactive (list (gnus-summary-article-number)))
10687 (gnus-set-global-variables)
10688 (gnus-group-edit-global-kill article))
10689
10690 (defun gnus-summary-edit-local-kill ()
10691 "Edit a local kill file applied to the current newsgroup."
10692 (interactive)
10693 (gnus-set-global-variables)
10694 (setq gnus-current-headers
10695 (gnus-gethash
10696 (int-to-string (gnus-summary-article-number))
10697 gnus-newsgroup-headers-hashtb-by-number))
10698 (gnus-set-global-variables)
10699 (gnus-group-edit-local-kill
10700 (gnus-summary-article-number) gnus-newsgroup-name))
10701
10702 \f
10703 ;;;
10704 ;;; Gnus article mode
10705 ;;;
10706
10707 (put 'gnus-article-mode 'mode-class 'special)
10708
10709 (defvar gnus-bugaboo nil)
10710
10711 (if gnus-article-mode-map
10712 nil
10713 (setq gnus-article-mode-map (make-keymap))
10714 (suppress-keymap gnus-article-mode-map)
10715 (define-key gnus-article-mode-map " " 'gnus-article-next-page)
10716 (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
10717 (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article)
10718 (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
10719 (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
10720 (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail)
10721 (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
10722 (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button)
10723 (define-key gnus-article-mode-map "\r" 'gnus-article-press-button)
10724 (define-key gnus-article-mode-map "\t" 'gnus-article-next-button)
10725 (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug)
10726
10727 ;; Duplicate almost all summary keystrokes in the article mode map.
10728 (let ((commands
10729 (list
10730 "p" "N" "P" "\M-\C-n" "\M-\C-p"
10731 "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j"
10732 "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k"
10733 "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h"
10734 "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w"
10735 "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a"
10736 "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s"
10737 "\M-g" "w" "\C-c\C-r" "\M-t" "C"
10738 "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d"
10739 "\C-c\C-i" "x" "X" "t" "g" "?" "l"
10740 "\C-c\C-v\C-v" "\C-d" "v"
10741 ;; "Mt" "M!" "Md" "Mr"
10742 ;; "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r"
10743 ;; "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK"
10744 ;; "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p"
10745 ;; "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT"
10746 ;; "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap"
10747 ;; "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am"
10748 ;; "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t"
10749 ;; "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi"
10750 ;; "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or"
10751 ;; "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve"
10752 ;; "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi"
10753 )))
10754 (while (and gnus-bugaboo commands) ; disabled
10755 (define-key gnus-article-mode-map (car commands)
10756 'gnus-article-summary-command)
10757 (setq commands (cdr commands))))
10758
10759 (let ((commands (list "q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
10760 ;; "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
10761 "=" "n" "^" "\M-^")))
10762 (while (and gnus-bugaboo commands) ; disabled
10763 (define-key gnus-article-mode-map (car commands)
10764 'gnus-article-summary-command-nosave)
10765 (setq commands (cdr commands)))))
10766
10767
10768 (defun gnus-article-mode ()
10769 "Major mode for displaying an article.
10770
10771 All normal editing commands are switched off.
10772
10773 The following commands are available:
10774
10775 \\<gnus-article-mode-map>
10776 \\[gnus-article-next-page]\t Scroll the article one page forwards
10777 \\[gnus-article-prev-page]\t Scroll the article one page backwards
10778 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
10779 \\[gnus-article-show-summary]\t Display the summary buffer
10780 \\[gnus-article-mail]\t Send a reply to the address near point
10781 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
10782 \\[gnus-info-find-node]\t Go to the Gnus info node"
10783 (interactive)
10784 (if gnus-visual (gnus-article-make-menu-bar))
10785 (kill-all-local-variables)
10786 (gnus-simplify-mode-line)
10787 (setq mode-name "Article")
10788 (setq major-mode 'gnus-article-mode)
10789 (make-local-variable 'minor-mode-alist)
10790 (or (assq 'gnus-show-mime minor-mode-alist)
10791 (setq minor-mode-alist
10792 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
10793 (use-local-map gnus-article-mode-map)
10794 (make-local-variable 'page-delimiter)
10795 (setq page-delimiter gnus-page-delimiter)
10796 (buffer-disable-undo (current-buffer))
10797 (setq buffer-read-only t) ;Disable modification
10798 (run-hooks 'gnus-article-mode-hook))
10799
10800 (defun gnus-article-setup-buffer ()
10801 "Initialize article mode buffer."
10802 ;; Returns the article buffer.
10803 (if (get-buffer gnus-article-buffer)
10804 (save-excursion
10805 (set-buffer gnus-article-buffer)
10806 (buffer-disable-undo (current-buffer))
10807 (setq buffer-read-only t)
10808 (gnus-add-current-to-buffer-list)
10809 (or (eq major-mode 'gnus-article-mode)
10810 (gnus-article-mode))
10811 (current-buffer))
10812 (save-excursion
10813 (set-buffer (get-buffer-create gnus-article-buffer))
10814 (gnus-add-current-to-buffer-list)
10815 (gnus-article-mode)
10816 (current-buffer))))
10817
10818 ;; Set article window start at LINE, where LINE is the number of lines
10819 ;; from the head of the article.
10820 (defun gnus-article-set-window-start (&optional line)
10821 (set-window-start
10822 (get-buffer-window gnus-article-buffer)
10823 (save-excursion
10824 (set-buffer gnus-article-buffer)
10825 (goto-char (point-min))
10826 (if (not line)
10827 (point-min)
10828 (gnus-message 6 "Moved to bookmark")
10829 (search-forward "\n\n" nil t)
10830 (forward-line line)
10831 (point)))))
10832
10833 (defun gnus-request-article-this-buffer (article group)
10834 "Get an article and insert it into this buffer."
10835 (setq group (or group gnus-newsgroup-name))
10836
10837 ;; Open server if it has closed.
10838 (gnus-check-server (gnus-find-method-for-group group))
10839
10840 ;; Using `gnus-request-article' directly will insert the article into
10841 ;; `nntp-server-buffer' - so we'll save some time by not having to
10842 ;; copy it from the server buffer into the article buffer.
10843
10844 ;; We only request an article by message-id when we do not have the
10845 ;; headers for it, so we'll have to get those.
10846 (and (stringp article)
10847 (let ((gnus-override-method gnus-refer-article-method))
10848 (gnus-read-header article)))
10849
10850 ;; If the article number is negative, that means that this article
10851 ;; doesn't belong in this newsgroup (possibly), so we find its
10852 ;; message-id and request it by id instead of number.
10853 (if (not (numberp article))
10854 ()
10855 (save-excursion
10856 (set-buffer gnus-summary-buffer)
10857 (let ((header (gnus-get-header-by-num article)))
10858 (if (< article 0)
10859 (if (vectorp header)
10860 ;; It's a real article.
10861 (setq article (mail-header-id header))
10862 ;; It is an extracted pseudo-article.
10863 (setq article 'pseudo)
10864 (gnus-request-pseudo-article header)))
10865
10866 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
10867 (if (not (eq (car method) 'nneething))
10868 ()
10869 (let ((dir (concat (file-name-as-directory (nth 1 method))
10870 (mail-header-subject header))))
10871 (if (file-directory-p dir)
10872 (progn
10873 (setq article 'nneething)
10874 (gnus-group-enter-directory dir)))))))))
10875
10876 ;; Check the cache.
10877 (if (and gnus-use-cache
10878 (numberp article)
10879 (gnus-cache-request-article article group))
10880 'article
10881 ;; Get the article and put into the article buffer.
10882 (if (or (stringp article) (numberp article))
10883 (progn
10884 (erase-buffer)
10885 ;; There may be some overlays that we have to kill...
10886 (insert "i")
10887 (let ((overlays (and (fboundp 'overlays-at)
10888 (overlays-at (point-min)))))
10889 (while overlays
10890 (delete-overlay (car overlays))
10891 (setq overlays (cdr overlays))))
10892 (erase-buffer)
10893 (let ((gnus-override-method
10894 (and (stringp article) gnus-refer-article-method)))
10895 (and (gnus-request-article article group (current-buffer))
10896 'article)))
10897 article)))
10898
10899 (defun gnus-read-header (id)
10900 "Read the headers of article ID and enter them into the Gnus system."
10901 (let (header)
10902 (if (not (setq header
10903 (car (if (let ((gnus-nov-is-evil t))
10904 (gnus-retrieve-headers
10905 (list id) gnus-newsgroup-name))
10906 (gnus-get-newsgroup-headers)))))
10907 nil
10908 (if (stringp id)
10909 (mail-header-set-number header gnus-reffed-article-number))
10910 (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers))
10911 (gnus-sethash (int-to-string (mail-header-number header)) header
10912 gnus-newsgroup-headers-hashtb-by-number)
10913 (if (stringp id)
10914 (setq gnus-reffed-article-number (1- gnus-reffed-article-number)))
10915 (setq gnus-current-headers header)
10916 header)))
10917
10918 (defun gnus-article-prepare (article &optional all-headers header)
10919 "Prepare ARTICLE in article mode buffer.
10920 ARTICLE should either be an article number or a Message-ID.
10921 If ARTICLE is an id, HEADER should be the article headers.
10922 If ALL-HEADERS is non-nil, no headers are hidden."
10923 (save-excursion
10924 ;; Make sure we start in a summary buffer.
10925 (or (eq major-mode 'gnus-summary-mode)
10926 (set-buffer gnus-summary-buffer))
10927 (setq gnus-summary-buffer (current-buffer))
10928 ;; Make sure the connection to the server is alive.
10929 (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name))
10930 (progn
10931 (gnus-check-server
10932 (gnus-find-method-for-group gnus-newsgroup-name))
10933 (gnus-request-group gnus-newsgroup-name t)))
10934 (let* ((article (if header (mail-header-number header) article))
10935 (summary-buffer (current-buffer))
10936 (internal-hook gnus-article-internal-prepare-hook)
10937 (group gnus-newsgroup-name)
10938 result)
10939 (save-excursion
10940 (gnus-article-setup-buffer)
10941 (set-buffer gnus-article-buffer)
10942 (if (not (setq result (let ((buffer-read-only nil))
10943 (gnus-request-article-this-buffer
10944 article group))))
10945 ;; There is no such article.
10946 (save-excursion
10947 (if (not (numberp article))
10948 ()
10949 (setq gnus-article-current
10950 (cons gnus-newsgroup-name article))
10951 (set-buffer gnus-summary-buffer)
10952 (setq gnus-current-article article)
10953 (gnus-summary-mark-article article gnus-canceled-mark))
10954 (gnus-message 1 "No such article (may be canceled)")
10955 (ding)
10956 nil)
10957 (if (or (eq result 'pseudo) (eq result 'nneething))
10958 (progn
10959 (save-excursion
10960 (set-buffer summary-buffer)
10961 (setq gnus-last-article gnus-current-article
10962 gnus-newsgroup-history (cons gnus-current-article
10963 gnus-newsgroup-history)
10964 gnus-current-article 0
10965 gnus-current-headers nil
10966 gnus-article-current nil)
10967 (if (eq result 'nneething)
10968 (gnus-configure-windows 'summary)
10969 (gnus-configure-windows 'article))
10970 (gnus-set-global-variables))
10971 (gnus-set-mode-line 'article))
10972 ;; The result from the `request' was an actual article -
10973 ;; or at least some text that is now displayed in the
10974 ;; article buffer.
10975 (if (and (numberp article)
10976 (not (eq article gnus-current-article)))
10977 ;; Seems like a new article has been selected.
10978 ;; `gnus-current-article' must be an article number.
10979 (save-excursion
10980 (set-buffer summary-buffer)
10981 (setq gnus-last-article gnus-current-article
10982 gnus-newsgroup-history (cons gnus-current-article
10983 gnus-newsgroup-history)
10984 gnus-current-article article
10985 gnus-current-headers
10986 (gnus-get-header-by-num gnus-current-article)
10987 gnus-article-current
10988 (cons gnus-newsgroup-name gnus-current-article))
10989 (gnus-summary-show-thread)
10990 (run-hooks 'gnus-mark-article-hook)
10991 (gnus-set-mode-line 'summary)
10992 (and gnus-visual
10993 (run-hooks 'gnus-visual-mark-article-hook))
10994 ;; Set the global newsgroup variables here.
10995 ;; Suggested by Jim Sisolak
10996 ;; <sisolak@trans4.neep.wisc.edu>.
10997 (gnus-set-global-variables)
10998 (setq gnus-have-all-headers
10999 (or all-headers gnus-show-all-headers))
11000 (and gnus-use-cache
11001 (vectorp (gnus-get-header-by-number article))
11002 (gnus-cache-possibly-enter-article
11003 group article
11004 (gnus-get-header-by-number article)
11005 (memq article gnus-newsgroup-marked)
11006 (memq article gnus-newsgroup-dormant)
11007 (memq article gnus-newsgroup-unreads)))))
11008 ;; Hooks for getting information from the article.
11009 ;; This hook must be called before being narrowed.
11010 (let (buffer-read-only)
11011 (run-hooks 'internal-hook)
11012 (run-hooks 'gnus-article-prepare-hook)
11013 ;; Decode MIME message.
11014 (if (and gnus-show-mime
11015 (or (not gnus-strict-mime)
11016 (gnus-fetch-field "Mime-Version")))
11017 (funcall gnus-show-mime-method))
11018 ;; Perform the article display hooks.
11019 (run-hooks 'gnus-article-display-hook))
11020 ;; Do page break.
11021 (goto-char (point-min))
11022 (and gnus-break-pages (gnus-narrow-to-page))
11023 (gnus-set-mode-line 'article)
11024 (gnus-configure-windows 'article)
11025 (goto-char (point-min))
11026 t))))))
11027
11028 (defun gnus-article-show-all-headers ()
11029 "Show all article headers in article mode buffer."
11030 (save-excursion
11031 (gnus-article-setup-buffer)
11032 (set-buffer gnus-article-buffer)
11033 (let ((buffer-read-only nil))
11034 (remove-text-properties (point-min) (point-max)
11035 gnus-hidden-properties))))
11036
11037 (defun gnus-article-hide-headers-if-wanted ()
11038 "Hide unwanted headers if `gnus-have-all-headers' is nil.
11039 Provided for backwards compatibility."
11040 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
11041 (gnus-article-hide-headers)))
11042
11043 (defun gnus-article-hide-headers (&optional delete)
11044 "Hide unwanted headers and possibly sort them as well."
11045 (interactive "P")
11046 (save-excursion
11047 (set-buffer gnus-article-buffer)
11048 (save-restriction
11049 (let ((sorted gnus-sorted-header-list)
11050 (buffer-read-only nil)
11051 want-list beg want-l)
11052 ;; First we narrow to just the headers.
11053 (widen)
11054 (goto-char (point-min))
11055 ;; Hide any "From " lines at the beginning of (mail) articles.
11056 (while (looking-at "From ")
11057 (forward-line 1))
11058 (or (bobp)
11059 (add-text-properties (point-min) (point) gnus-hidden-properties))
11060 ;; Then treat the rest of the header lines.
11061 (narrow-to-region
11062 (point)
11063 (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
11064 ;; Then we use the two regular expressions
11065 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
11066 ;; select which header lines is to remain visible in the
11067 ;; article buffer.
11068 (goto-char (point-min))
11069 (while (re-search-forward "^[^ \t]*:" nil t)
11070 (beginning-of-line)
11071 ;; We add the headers we want to keep to a list and delete
11072 ;; them from the buffer.
11073 (if (or (and (stringp gnus-visible-headers)
11074 (looking-at gnus-visible-headers))
11075 (and (not (stringp gnus-visible-headers))
11076 (stringp gnus-ignored-headers)
11077 (not (looking-at gnus-ignored-headers))))
11078 (progn
11079 (setq beg (point))
11080 (forward-line 1)
11081 ;; Be sure to get multi-line headers...
11082 (re-search-forward "^[^ \t]*:" nil t)
11083 (beginning-of-line)
11084 (setq want-list
11085 (cons (buffer-substring beg (point)) want-list))
11086 (delete-region beg (point))
11087 (goto-char beg))
11088 (forward-line 1)))
11089 ;; Next we perform the sorting by looking at
11090 ;; `gnus-sorted-header-list'.
11091 (goto-char (point-min))
11092 (while (and sorted want-list)
11093 (setq want-l want-list)
11094 (while (and want-l
11095 (not (string-match (car sorted) (car want-l))))
11096 (setq want-l (cdr want-l)))
11097 (if want-l
11098 (progn
11099 (insert (car want-l))
11100 (setq want-list (delq (car want-l) want-list))))
11101 (setq sorted (cdr sorted)))
11102 ;; Any headers that were not matched by the sorted list we
11103 ;; just tack on the end of the visible header list.
11104 (while want-list
11105 (insert (car want-list))
11106 (setq want-list (cdr want-list)))
11107 ;; And finally we make the unwanted headers invisible.
11108 (if delete
11109 (delete-region (point) (point-max))
11110 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
11111 (add-text-properties (point) (point-max) gnus-hidden-properties))))))
11112
11113 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
11114 (defun gnus-article-treat-overstrike ()
11115 "Translate overstrikes into bold text."
11116 (interactive)
11117 (save-excursion
11118 (set-buffer gnus-article-buffer)
11119 (let ((buffer-read-only nil))
11120 (while (search-forward "\b" nil t)
11121 (let ((next (following-char))
11122 (previous (char-after (- (point) 2))))
11123 (cond ((eq next previous)
11124 (put-text-property (- (point) 2) (point)
11125 'invisible t)
11126 (put-text-property (point) (1+ (point))
11127 'face 'bold))
11128 ((eq next ?_)
11129 (put-text-property (1- (point)) (1+ (point))
11130 'invisible t)
11131 (put-text-property (1- (point)) (point)
11132 'face 'underline))
11133 ((eq previous ?_)
11134 (put-text-property (- (point) 2) (point)
11135 'invisible t)
11136 (put-text-property (point) (1+ (point))
11137 'face 'underline))))))))
11138
11139 (defun gnus-article-word-wrap ()
11140 "Format too long lines."
11141 (interactive)
11142 (save-excursion
11143 (set-buffer gnus-article-buffer)
11144 (let ((buffer-read-only nil))
11145 (goto-char (point-min))
11146 (search-forward "\n\n" nil t)
11147 (end-of-line 1)
11148 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
11149 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
11150 (adaptive-fill-mode t))
11151 (while (not (eobp))
11152 (and (>= (current-column) (min fill-column (window-width)))
11153 (/= (preceding-char) ?:)
11154 (fill-paragraph nil))
11155 (end-of-line 2))))))
11156
11157 (defun gnus-article-remove-cr ()
11158 "Remove carriage returns from an article."
11159 (interactive)
11160 (save-excursion
11161 (set-buffer gnus-article-buffer)
11162 (let ((buffer-read-only nil))
11163 (goto-char (point-min))
11164 (while (search-forward "\r" nil t)
11165 (replace-match "" t t)))))
11166
11167 (defun gnus-article-display-x-face (&optional force)
11168 "Look for an X-Face header and display it if present."
11169 (interactive (list 'force))
11170 (save-excursion
11171 (set-buffer gnus-article-buffer)
11172 (let ((inhibit-point-motion-hooks t)
11173 (case-fold-search nil)
11174 from)
11175 (save-restriction
11176 (goto-char (point-min))
11177 (search-forward "\n\n")
11178 (narrow-to-region (point-min) (point))
11179 (goto-char (point-min))
11180 (setq from (mail-fetch-field "from"))
11181 (if (not (and gnus-article-x-face-command
11182 (or force
11183 (not gnus-article-x-face-too-ugly)
11184 (and gnus-article-x-face-too-ugly from
11185 (not (string-match gnus-article-x-face-too-ugly
11186 from))))
11187 (progn
11188 (goto-char (point-min))
11189 (re-search-forward "^X-Face: " nil t))))
11190 nil
11191 (let ((beg (point))
11192 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
11193 (if (symbolp gnus-article-x-face-command)
11194 (and (or (fboundp gnus-article-x-face-command)
11195 (error "%s is not a function"
11196 gnus-article-x-face-command))
11197 (funcall gnus-article-x-face-command beg end))
11198 (call-process-region beg end "sh" nil 0 nil
11199 "-c" gnus-article-x-face-command))))))))
11200
11201 (defun gnus-article-de-quoted-unreadable (&optional force)
11202 "Do a naive translation of a quoted-printable-encoded article.
11203 This is in no way, shape or form meant as a replacement for real MIME
11204 processing, but is simply a stop-gap measure until MIME support is
11205 written.
11206 If FORCE, decode the article whether it is marked as quoted-printable
11207 or not."
11208 (interactive (list 'force))
11209 (save-excursion
11210 (set-buffer gnus-article-buffer)
11211 (let ((case-fold-search t)
11212 (buffer-read-only nil)
11213 (type (gnus-fetch-field "content-transfer-encoding")))
11214 (if (or force (and type (string-match "quoted-printable" type)))
11215 (progn
11216 (goto-char (point-min))
11217 (search-forward "\n\n" nil 'move)
11218 (gnus-mime-decode-quoted-printable (point) (point-max)))))))
11219
11220 (defun gnus-mime-decode-quoted-printable (from to)
11221 ;; Decode quoted-printable from region between FROM and TO.
11222 (save-excursion
11223 (goto-char from)
11224 (while (search-forward "=" to t)
11225 (cond ((eq (following-char) ?\n)
11226 (delete-char -1)
11227 (delete-char 1))
11228 ((looking-at "[0-9A-F][0-9A-F]")
11229 (delete-char -1)
11230 (insert (hexl-hex-string-to-integer
11231 (buffer-substring (point) (+ 2 (point)))))
11232 (delete-char 2))
11233 ((looking-at "=")
11234 (delete-char 1))
11235 ((gnus-message 3 "Malformed MIME quoted-printable message"))))))
11236
11237 (defvar gnus-article-time-units
11238 (list (cons 'year (* 365.25 24 60 60))
11239 (cons 'week (* 7 24 60 60))
11240 (cons 'day (* 24 60 60))
11241 (cons 'hour (* 60 60))
11242 (cons 'minute 60)
11243 (cons 'second 1)))
11244
11245 (defun gnus-article-date-ut (&optional type)
11246 "Convert DATE date to universal time in the current article.
11247 If TYPE is `local', convert to local time; if it is `lapsed', output
11248 how much time has lapsed since DATE."
11249 (interactive (list 'ut))
11250 (let ((date (mail-header-date (or gnus-current-headers
11251 (gnus-get-header-by-number
11252 (gnus-summary-article-number))"")))
11253 (date-regexp "^Date: \\|^X-Sent: "))
11254 (if (or (not date)
11255 (string= date ""))
11256 ()
11257 (save-excursion
11258 (set-buffer gnus-article-buffer)
11259 (let ((buffer-read-only nil))
11260 (goto-char (point-min))
11261 (if (and (re-search-forward date-regexp nil t)
11262 (progn
11263 (beginning-of-line)
11264 (looking-at date-regexp)))
11265 (delete-region (gnus-point-at-bol)
11266 (progn (end-of-line) (1+ (point))))
11267 (goto-char (point-min))
11268 (goto-char (- (search-forward "\n\n") 2)))
11269 (insert
11270 (cond
11271 ((eq type 'local)
11272 (concat "Date: " (condition-case ()
11273 (timezone-make-date-arpa-standard date)
11274 (error date))
11275 "\n"))
11276 ((eq type 'ut)
11277 (concat "Date: "
11278 (condition-case ()
11279 (timezone-make-date-arpa-standard date nil "UT")
11280 (error date))
11281 "\n"))
11282 ((eq type 'lapsed)
11283 ;; If the date is seriously mangled, the timezone
11284 ;; functions are liable to bug out, so we condition-case
11285 ;; the entire thing.
11286 (let* ((real-sec (condition-case ()
11287 (- (gnus-seconds-since-epoch
11288 (timezone-make-date-arpa-standard
11289 (current-time-string)
11290 (current-time-zone) "UT"))
11291 (gnus-seconds-since-epoch
11292 (timezone-make-date-arpa-standard
11293 date nil "UT")))
11294 (error 0)))
11295 (sec (abs real-sec))
11296 num prev)
11297 (if (zerop sec)
11298 "X-Sent: Now\n"
11299 (concat
11300 "X-Sent: "
11301 (mapconcat
11302 (lambda (unit)
11303 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
11304 ""
11305 (setq sec (- sec (* num (cdr unit))))
11306 (prog1
11307 (concat (if prev ", " "") (int-to-string
11308 (floor num))
11309 " " (symbol-name (car unit))
11310 (if (> num 1) "s" ""))
11311 (setq prev t))))
11312 gnus-article-time-units "")
11313 (if (> real-sec 0)
11314 " ago\n"
11315 " in the future\n")))))
11316 (t
11317 (error "Unknown conversion type: %s" type)))))))))
11318
11319 (defun gnus-article-date-local ()
11320 "Convert the current article date to the local timezone."
11321 (interactive)
11322 (gnus-article-date-ut 'local))
11323
11324 (defun gnus-article-date-lapsed ()
11325 "Convert the current article date to time lapsed since it was sent."
11326 (interactive)
11327 (gnus-article-date-ut 'lapsed))
11328
11329 (defun gnus-article-maybe-highlight ()
11330 "Do some article highlighting if `gnus-visual' is non-nil."
11331 (if gnus-visual (gnus-article-highlight-some)))
11332
11333 ;; Article savers.
11334
11335 (defun gnus-output-to-rmail (file-name)
11336 "Append the current article to an Rmail file named FILE-NAME."
11337 (require 'rmail)
11338 ;; Most of these codes are borrowed from rmailout.el.
11339 (setq file-name (expand-file-name file-name))
11340 (setq rmail-default-rmail-file file-name)
11341 (let ((artbuf (current-buffer))
11342 (tmpbuf (get-buffer-create " *Gnus-output*")))
11343 (save-excursion
11344 (or (get-file-buffer file-name)
11345 (file-exists-p file-name)
11346 (if (gnus-yes-or-no-p
11347 (concat "\"" file-name "\" does not exist, create it? "))
11348 (let ((file-buffer (create-file-buffer file-name)))
11349 (save-excursion
11350 (set-buffer file-buffer)
11351 (rmail-insert-rmail-file-header)
11352 (let ((require-final-newline nil))
11353 (write-region (point-min) (point-max) file-name t 1)))
11354 (kill-buffer file-buffer))
11355 (error "Output file does not exist")))
11356 (set-buffer tmpbuf)
11357 (buffer-disable-undo (current-buffer))
11358 (erase-buffer)
11359 (insert-buffer-substring artbuf)
11360 (gnus-convert-article-to-rmail)
11361 ;; Decide whether to append to a file or to an Emacs buffer.
11362 (let ((outbuf (get-file-buffer file-name)))
11363 (if (not outbuf)
11364 (append-to-file (point-min) (point-max) file-name)
11365 ;; File has been visited, in buffer OUTBUF.
11366 (set-buffer outbuf)
11367 (let ((buffer-read-only nil)
11368 (msg (and (boundp 'rmail-current-message)
11369 (symbol-value 'rmail-current-message))))
11370 ;; If MSG is non-nil, buffer is in RMAIL mode.
11371 (if msg
11372 (progn (widen)
11373 (narrow-to-region (point-max) (point-max))))
11374 (insert-buffer-substring tmpbuf)
11375 (if msg
11376 (progn
11377 (goto-char (point-min))
11378 (widen)
11379 (search-backward "\^_")
11380 (narrow-to-region (point) (point-max))
11381 (goto-char (1+ (point-min)))
11382 (rmail-count-new-messages t)
11383 (rmail-show-message msg)))))))
11384 (kill-buffer tmpbuf)))
11385
11386 (defun gnus-output-to-file (file-name)
11387 "Append the current article to a file named FILE-NAME."
11388 (setq file-name (expand-file-name file-name))
11389 (let ((artbuf (current-buffer))
11390 (tmpbuf (get-buffer-create " *Gnus-output*")))
11391 (save-excursion
11392 (set-buffer tmpbuf)
11393 (buffer-disable-undo (current-buffer))
11394 (erase-buffer)
11395 (insert-buffer-substring artbuf)
11396 ;; Append newline at end of the buffer as separator, and then
11397 ;; save it to file.
11398 (goto-char (point-max))
11399 (insert "\n")
11400 (append-to-file (point-min) (point-max) file-name))
11401 (kill-buffer tmpbuf)))
11402
11403 (defun gnus-convert-article-to-rmail ()
11404 "Convert article in current buffer to Rmail message format."
11405 (let ((buffer-read-only nil))
11406 ;; Convert article directly into Babyl format.
11407 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
11408 (goto-char (point-min))
11409 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
11410 (while (search-forward "\n\^_" nil t) ;single char
11411 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
11412 (goto-char (point-max))
11413 (insert "\^_")))
11414
11415 (defun gnus-narrow-to-page (&optional arg)
11416 "Make text outside current page invisible except for page delimiter.
11417 A numeric arg specifies to move forward or backward by that many pages,
11418 thus showing a page other than the one point was originally in."
11419 (interactive "P")
11420 (setq arg (if arg (prefix-numeric-value arg) 0))
11421 (save-excursion
11422 (forward-page -1) ;Beginning of current page.
11423 (widen)
11424 (if (> arg 0)
11425 (forward-page arg)
11426 (if (< arg 0)
11427 (forward-page (1- arg))))
11428 ;; Find the end of the page.
11429 (forward-page)
11430 ;; If we stopped due to end of buffer, stay there.
11431 ;; If we stopped after a page delimiter, put end of restriction
11432 ;; at the beginning of that line.
11433 ;; These are commented out.
11434 ;; (if (save-excursion (beginning-of-line)
11435 ;; (looking-at page-delimiter))
11436 ;; (beginning-of-line))
11437 (narrow-to-region (point)
11438 (progn
11439 ;; Find the top of the page.
11440 (forward-page -1)
11441 ;; If we found beginning of buffer, stay there.
11442 ;; If extra text follows page delimiter on same line,
11443 ;; include it.
11444 ;; Otherwise, show text starting with following line.
11445 (if (and (eolp) (not (bobp)))
11446 (forward-line 1))
11447 (point)))))
11448
11449 (defun gnus-gmt-to-local ()
11450 "Rewrite Date header described in GMT to local in current buffer.
11451 Intended to be used with gnus-article-prepare-hook."
11452 (save-excursion
11453 (save-restriction
11454 (widen)
11455 (goto-char (point-min))
11456 (narrow-to-region (point-min)
11457 (progn (search-forward "\n\n" nil 'move) (point)))
11458 (goto-char (point-min))
11459 (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t)
11460 (let ((buffer-read-only nil)
11461 (date (buffer-substring-no-properties
11462 (match-beginning 1) (match-end 1))))
11463 (delete-region (match-beginning 1) (match-end 1))
11464 (insert
11465 (timezone-make-date-arpa-standard
11466 date nil (current-time-zone))))))))
11467
11468
11469 ;; Article mode commands
11470
11471 (defun gnus-article-next-page (&optional lines)
11472 "Show next page of current article.
11473 If end of article, return non-nil. Otherwise return nil.
11474 Argument LINES specifies lines to be scrolled up."
11475 (interactive "P")
11476 (move-to-window-line -1)
11477 ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
11478 (if (save-excursion
11479 (end-of-line)
11480 (and (pos-visible-in-window-p) ;Not continuation line.
11481 (eobp)))
11482 ;; Nothing in this page.
11483 (if (or (not gnus-break-pages)
11484 (save-excursion
11485 (save-restriction
11486 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
11487 t ;Nothing more.
11488 (gnus-narrow-to-page 1) ;Go to next page.
11489 nil)
11490 ;; More in this page.
11491 (condition-case ()
11492 (scroll-up lines)
11493 (end-of-buffer
11494 ;; Long lines may cause an end-of-buffer error.
11495 (goto-char (point-max))))
11496 nil))
11497
11498 (defun gnus-article-prev-page (&optional lines)
11499 "Show previous page of current article.
11500 Argument LINES specifies lines to be scrolled down."
11501 (interactive "P")
11502 (move-to-window-line 0)
11503 (if (and gnus-break-pages
11504 (bobp)
11505 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
11506 (progn
11507 (gnus-narrow-to-page -1) ;Go to previous page.
11508 (goto-char (point-max))
11509 (recenter -1))
11510 (scroll-down lines)))
11511
11512 (defun gnus-article-refer-article ()
11513 "Read article specified by message-id around point."
11514 (interactive)
11515 (search-forward ">" nil t) ;Move point to end of "<....>".
11516 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
11517 (let ((message-id
11518 (buffer-substring (match-beginning 1) (match-end 1))))
11519 (set-buffer gnus-summary-buffer)
11520 (gnus-summary-refer-article message-id))
11521 (error "No references around point")))
11522
11523 (defun gnus-article-show-summary ()
11524 "Reconfigure windows to show summary buffer."
11525 (interactive)
11526 (gnus-configure-windows 'article)
11527 (gnus-summary-goto-subject gnus-current-article))
11528
11529 (defun gnus-article-describe-briefly ()
11530 "Describe article mode commands briefly."
11531 (interactive)
11532 (gnus-message 6
11533 (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")))
11534
11535 (defun gnus-article-summary-command ()
11536 "Execute the last keystroke in the summary buffer."
11537 (interactive)
11538 (let ((obuf (current-buffer))
11539 (owin (current-window-configuration))
11540 func)
11541 (switch-to-buffer gnus-summary-buffer 'norecord)
11542 (setq func (lookup-key (current-local-map) (this-command-keys)))
11543 (call-interactively func)
11544 (set-buffer obuf)
11545 (set-window-configuration owin)
11546 (set-window-point (get-buffer-window (current-buffer)) (point))))
11547
11548 (defun gnus-article-summary-command-nosave ()
11549 "Execute the last keystroke in the summary buffer."
11550 (interactive)
11551 (let (func)
11552 (pop-to-buffer gnus-summary-buffer 'norecord)
11553 (setq func (lookup-key (current-local-map) (this-command-keys)))
11554 (call-interactively func)))
11555
11556 \f
11557 ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
11558
11559 ;;;###autoload
11560 (defalias 'gnus-batch-kill 'gnus-batch-score)
11561 ;;;###autoload
11562 (defun gnus-batch-score ()
11563 "Run batched scoring.
11564 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
11565 Newsgroups is a list of strings in Bnews format. If you want to score
11566 the comp hierarchy, you'd say \"comp.all\". If you would not like to
11567 score the alt hierarchy, you'd say \"!alt.all\"."
11568 (interactive)
11569 (let* ((yes-and-no
11570 (gnus-newsrc-parse-options
11571 (apply (function concat)
11572 (mapcar (lambda (g) (concat g " "))
11573 command-line-args-left))))
11574 (gnus-expert-user t)
11575 (nnmail-spool-file nil)
11576 (gnus-use-dribble-file nil)
11577 (yes (car yes-and-no))
11578 (no (cdr yes-and-no))
11579 group newsrc entry
11580 ;; Disable verbose message.
11581 gnus-novice-user gnus-large-newsgroup)
11582 ;; Eat all arguments.
11583 (setq command-line-args-left nil)
11584 ;; Start Gnus.
11585 (gnus)
11586 ;; Apply kills to specified newsgroups in command line arguments.
11587 (setq newsrc (cdr gnus-newsrc-alist))
11588 (while newsrc
11589 (setq group (car (car newsrc)))
11590 (setq entry (gnus-gethash group gnus-newsrc-hashtb))
11591 (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
11592 (and (car entry)
11593 (or (eq (car entry) t)
11594 (not (zerop (car entry)))))
11595 (if yes (string-match yes group) t)
11596 (or (null no) (not (string-match no group))))
11597 (progn
11598 (gnus-summary-read-group group nil t)
11599 (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
11600 (gnus-summary-exit))))
11601 (setq newsrc (cdr newsrc)))
11602 ;; Exit Emacs.
11603 (switch-to-buffer gnus-group-buffer)
11604 (gnus-group-save-newsrc)))
11605
11606 (defun gnus-apply-kill-file ()
11607 "Apply a kill file to the current newsgroup.
11608 Returns the number of articles marked as read."
11609 (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
11610 (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11611 (gnus-apply-kill-file-internal)
11612 0))
11613
11614 (defun gnus-kill-save-kill-buffer ()
11615 (save-excursion
11616 (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11617 (if (get-file-buffer file)
11618 (progn
11619 (set-buffer (get-file-buffer file))
11620 (and (buffer-modified-p) (save-buffer))
11621 (kill-buffer (current-buffer)))))))
11622
11623 (defvar gnus-kill-file-name "KILL"
11624 "Suffix of the kill files.")
11625
11626 (defun gnus-newsgroup-kill-file (newsgroup)
11627 "Return the name of a kill file name for NEWSGROUP.
11628 If NEWSGROUP is nil, return the global kill file name instead."
11629 (cond ((or (null newsgroup)
11630 (string-equal newsgroup ""))
11631 ;; The global KILL file is placed at top of the directory.
11632 (expand-file-name gnus-kill-file-name
11633 (or gnus-kill-files-directory "~/News")))
11634 ((gnus-use-long-file-name 'not-kill)
11635 ;; Append ".KILL" to newsgroup name.
11636 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
11637 "." gnus-kill-file-name)
11638 (or gnus-kill-files-directory "~/News")))
11639 (t
11640 ;; Place "KILL" under the hierarchical directory.
11641 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
11642 "/" gnus-kill-file-name)
11643 (or gnus-kill-files-directory "~/News")))))
11644
11645 \f
11646 ;;;
11647 ;;; Dribble file
11648 ;;;
11649
11650 (defvar gnus-dribble-ignore nil)
11651 (defvar gnus-dribble-eval-file nil)
11652
11653 (defun gnus-dribble-file-name ()
11654 (concat gnus-current-startup-file "-dribble"))
11655
11656 (defun gnus-dribble-enter (string)
11657 (if (and (not gnus-dribble-ignore)
11658 gnus-dribble-buffer
11659 (buffer-name gnus-dribble-buffer))
11660 (let ((obuf (current-buffer)))
11661 (set-buffer gnus-dribble-buffer)
11662 (insert string "\n")
11663 (set-window-point (get-buffer-window (current-buffer)) (point-max))
11664 (set-buffer obuf))))
11665
11666 (defun gnus-dribble-read-file ()
11667 (let ((dribble-file (gnus-dribble-file-name)))
11668 (save-excursion
11669 (set-buffer (setq gnus-dribble-buffer
11670 (get-buffer-create
11671 (file-name-nondirectory dribble-file))))
11672 (gnus-add-current-to-buffer-list)
11673 (erase-buffer)
11674 (set-visited-file-name dribble-file)
11675 (buffer-disable-undo (current-buffer))
11676 (bury-buffer (current-buffer))
11677 (set-buffer-modified-p nil)
11678 (let ((auto (make-auto-save-file-name))
11679 (gnus-dribble-ignore t))
11680 (if (or (file-exists-p auto) (file-exists-p dribble-file))
11681 (progn
11682 (if (file-newer-than-file-p auto dribble-file)
11683 (setq dribble-file auto))
11684 (insert-file-contents dribble-file)
11685 (if (not (zerop (buffer-size)))
11686 (set-buffer-modified-p t))
11687 (if (gnus-y-or-n-p
11688 "Auto-save file exists. Do you want to read it? ")
11689 (setq gnus-dribble-eval-file t))))))))
11690
11691 (defun gnus-dribble-eval-file ()
11692 (if (not gnus-dribble-eval-file)
11693 ()
11694 (setq gnus-dribble-eval-file nil)
11695 (save-excursion
11696 (let ((gnus-dribble-ignore t))
11697 (set-buffer gnus-dribble-buffer)
11698 (eval-buffer (current-buffer))))))
11699
11700 (defun gnus-dribble-delete-file ()
11701 (if (file-exists-p (gnus-dribble-file-name))
11702 (delete-file (gnus-dribble-file-name)))
11703 (if gnus-dribble-buffer
11704 (save-excursion
11705 (set-buffer gnus-dribble-buffer)
11706 (let ((auto (make-auto-save-file-name)))
11707 (if (file-exists-p auto)
11708 (delete-file auto))
11709 (erase-buffer)
11710 (set-buffer-modified-p nil)))))
11711
11712 (defun gnus-dribble-save ()
11713 (if (and gnus-dribble-buffer
11714 (buffer-name gnus-dribble-buffer))
11715 (save-excursion
11716 (set-buffer gnus-dribble-buffer)
11717 (save-buffer))))
11718
11719 (defun gnus-dribble-clear ()
11720 (save-excursion
11721 (if (gnus-buffer-exists-p gnus-dribble-buffer)
11722 (progn
11723 (set-buffer gnus-dribble-buffer)
11724 (erase-buffer)
11725 (set-buffer-modified-p nil)
11726 (setq buffer-saved-size (buffer-size))))))
11727
11728 ;;;
11729 ;;; Server Communication
11730 ;;;
11731
11732 (defun gnus-start-news-server (&optional confirm)
11733 "Open a method for getting news.
11734 If CONFIRM is non-nil, the user will be asked for an NNTP server."
11735 (let (how)
11736 (if gnus-current-select-method
11737 ;; Stream is already opened.
11738 nil
11739 ;; Open NNTP server.
11740 (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
11741 (if confirm
11742 (progn
11743 ;; Read server name with completion.
11744 (setq gnus-nntp-server
11745 (completing-read "NNTP server: "
11746 (mapcar (lambda (server) (list server))
11747 (cons (list gnus-nntp-server)
11748 gnus-secondary-servers))
11749 nil nil gnus-nntp-server))))
11750
11751 (if (and gnus-nntp-server
11752 (stringp gnus-nntp-server)
11753 (not (string= gnus-nntp-server "")))
11754 (setq gnus-select-method
11755 (cond ((or (string= gnus-nntp-server "")
11756 (string= gnus-nntp-server "::"))
11757 (list 'nnspool (system-name)))
11758 ((string-match "^:" gnus-nntp-server)
11759 (list 'nnmh gnus-nntp-server
11760 (list 'nnmh-directory
11761 (file-name-as-directory
11762 (expand-file-name
11763 (concat "~/" (substring
11764 gnus-nntp-server 1)))))
11765 (list 'nnmh-get-new-mail nil)))
11766 (t
11767 (list 'nntp gnus-nntp-server)))))
11768
11769 (setq how (car gnus-select-method))
11770 (cond ((eq how 'nnspool)
11771 (require 'nnspool)
11772 (gnus-message 5 "Looking up local news spool..."))
11773 ((eq how 'nnmh)
11774 (require 'nnmh)
11775 (gnus-message 5 "Looking up mh spool..."))
11776 (t
11777 (require 'nntp)))
11778 (setq gnus-current-select-method gnus-select-method)
11779 (run-hooks 'gnus-open-server-hook)
11780 (or
11781 ;; gnus-open-server-hook might have opened it
11782 (gnus-server-opened gnus-select-method)
11783 (gnus-open-server gnus-select-method)
11784 (gnus-y-or-n-p
11785 (format
11786 "%s open error: '%s'. Continue? "
11787 (nth 1 gnus-select-method)
11788 (gnus-status-message gnus-select-method)))
11789 (progn
11790 (gnus-message 1 "Couldn't open server on %s"
11791 (nth 1 gnus-select-method))
11792 (ding)
11793 nil)))))
11794
11795 (defun gnus-check-server (&optional method)
11796 "If the news server is down, start it up again."
11797 (let ((method (if method method gnus-select-method)))
11798 (and (stringp method)
11799 (setq method (gnus-server-to-method method)))
11800 (if (gnus-server-opened method)
11801 ;; Stream is already opened.
11802 t
11803 ;; Open server.
11804 (gnus-message 5 "Opening server %s on %s..." (car method) (nth 1 method))
11805 (run-hooks 'gnus-open-server-hook)
11806 (prog1
11807 (gnus-open-server method)
11808 (message "")))))
11809
11810 (defun gnus-nntp-message (&optional message)
11811 "Check the status of the NNTP server.
11812 If the status of the server is clear and MESSAGE is non-nil, MESSAGE
11813 is returned insted of the status string."
11814 (let ((status (gnus-status-message (gnus-find-method-for-group
11815 gnus-newsgroup-name)))
11816 (message (or message "")))
11817 (if (and (stringp status) (> (length status) 0))
11818 status message)))
11819
11820 (defun gnus-get-function (method function)
11821 (and (stringp method)
11822 (setq method (gnus-server-to-method method)))
11823 (let ((func (intern (format "%s-%s" (car method) function))))
11824 (if (not (fboundp func))
11825 (progn
11826 (require (car method))
11827 (if (not (fboundp func))
11828 (error "No such function: %s" func))))
11829 func))
11830
11831 ;;; Interface functions to the backends.
11832
11833 (defun gnus-open-server (method)
11834 (funcall (gnus-get-function method 'open-server)
11835 (nth 1 method) (nthcdr 2 method)))
11836
11837 (defun gnus-close-server (method)
11838 (funcall (gnus-get-function method 'close-server) (nth 1 method)))
11839
11840 (defun gnus-request-list (method)
11841 (funcall (gnus-get-function method 'request-list) (nth 1 method)))
11842
11843 (defun gnus-request-list-newsgroups (method)
11844 (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
11845
11846 (defun gnus-request-newgroups (date method)
11847 (funcall (gnus-get-function method 'request-newgroups)
11848 date (nth 1 method)))
11849
11850 (defun gnus-server-opened (method)
11851 (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
11852
11853 (defun gnus-status-message (method)
11854 (let ((method (if (stringp method) (gnus-find-method-for-group method)
11855 method)))
11856 (funcall (gnus-get-function method 'status-message) (nth 1 method))))
11857
11858 (defun gnus-request-group (group &optional dont-check)
11859 (let ((method (gnus-find-method-for-group group)))
11860 (funcall (gnus-get-function method 'request-group)
11861 (gnus-group-real-name group) (nth 1 method) dont-check)))
11862
11863 (defun gnus-request-asynchronous (group &optional articles)
11864 (let ((method (gnus-find-method-for-group group)))
11865 (funcall (gnus-get-function method 'request-asynchronous)
11866 (gnus-group-real-name group) (nth 1 method) articles)))
11867
11868 (defun gnus-list-active-group (group)
11869 (let ((method (gnus-find-method-for-group group))
11870 (func 'list-active-group))
11871 (and (gnus-check-backend-function func group)
11872 (funcall (gnus-get-function method func)
11873 (gnus-group-real-name group) (nth 1 method)))))
11874
11875 (defun gnus-request-group-description (group)
11876 (let ((method (gnus-find-method-for-group group))
11877 (func 'request-group-description))
11878 (and (gnus-check-backend-function func group)
11879 (funcall (gnus-get-function method func)
11880 (gnus-group-real-name group) (nth 1 method)))))
11881
11882 (defun gnus-close-group (group)
11883 (let ((method (gnus-find-method-for-group group)))
11884 (funcall (gnus-get-function method 'close-group)
11885 (gnus-group-real-name group) (nth 1 method))))
11886
11887 (defun gnus-retrieve-headers (articles group)
11888 (let ((method (gnus-find-method-for-group group)))
11889 (if (and gnus-use-cache (numberp (car articles)))
11890 (gnus-cache-retrieve-headers articles group)
11891 (funcall (gnus-get-function method 'retrieve-headers)
11892 articles (gnus-group-real-name group) (nth 1 method)))))
11893
11894 (defun gnus-retrieve-groups (groups method)
11895 (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
11896
11897 (defun gnus-request-article (article group &optional buffer)
11898 (let ((method (gnus-find-method-for-group group)))
11899 (funcall (gnus-get-function method 'request-article)
11900 article (gnus-group-real-name group) (nth 1 method) buffer)))
11901
11902 (defun gnus-request-head (article group)
11903 (let ((method (gnus-find-method-for-group group)))
11904 (funcall (gnus-get-function method 'request-head)
11905 article (gnus-group-real-name group) (nth 1 method))))
11906
11907 (defun gnus-request-body (article group)
11908 (let ((method (gnus-find-method-for-group group)))
11909 (funcall (gnus-get-function method 'request-body)
11910 article (gnus-group-real-name group) (nth 1 method))))
11911
11912 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11913 (defun gnus-request-post-buffer (post group subject header artbuf
11914 info follow-to respect-poster)
11915 (let* ((info (or info (and group (nth 2 (gnus-gethash
11916 group gnus-newsrc-hashtb)))))
11917 (method
11918 (if (and gnus-post-method
11919 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11920 (memq 'post (assoc
11921 (format "%s" (car (gnus-find-method-for-group
11922 gnus-newsgroup-name)))
11923 gnus-valid-select-methods)))
11924 gnus-post-method
11925 (gnus-find-method-for-group gnus-newsgroup-name))))
11926 (or (gnus-check-server method)
11927 (error "Can't open server %s:%s" (car method) (nth 1 method)))
11928 (let ((mail-self-blind nil)
11929 (mail-archive-file-name nil))
11930 (funcall (gnus-get-function method 'request-post-buffer)
11931 post group subject header artbuf info follow-to
11932 respect-poster))))
11933
11934 (defun gnus-request-post (method &optional force)
11935 (and (stringp method)
11936 (setq method (gnus-server-to-method method)))
11937 (and (not force) gnus-post-method
11938 (memq 'post (assoc (format "%s" (car method))
11939 gnus-valid-select-methods))
11940 (setq method gnus-post-method))
11941 (funcall (gnus-get-function method 'request-post)
11942 (nth 1 method)))
11943
11944 (defun gnus-request-expire-articles (articles group &optional force)
11945 (let ((method (gnus-find-method-for-group group)))
11946 (funcall (gnus-get-function method 'request-expire-articles)
11947 articles (gnus-group-real-name group) (nth 1 method)
11948 force)))
11949
11950 (defun gnus-request-move-article
11951 (article group server accept-function &optional last)
11952 (let ((method (gnus-find-method-for-group group)))
11953 (funcall (gnus-get-function method 'request-move-article)
11954 article (gnus-group-real-name group)
11955 (nth 1 method) accept-function last)))
11956
11957 (defun gnus-request-accept-article (group &optional last)
11958 (goto-char (point-max))
11959 (or (bolp) (insert "\n"))
11960 (let ((func (if (symbolp group) group
11961 (car (gnus-find-method-for-group group)))))
11962 (funcall (intern (format "%s-request-accept-article" func))
11963 (if (stringp group) (gnus-group-real-name group) group)
11964 last)))
11965
11966 (defun gnus-request-replace-article (article group buffer)
11967 (let ((func (car (gnus-find-method-for-group group))))
11968 (funcall (intern (format "%s-request-replace-article" func))
11969 article (gnus-group-real-name group) buffer)))
11970
11971 (defun gnus-request-create-group (group)
11972 (let ((method (gnus-find-method-for-group group)))
11973 (funcall (gnus-get-function method 'request-create-group)
11974 (gnus-group-real-name group) (nth 1 method))))
11975
11976 (defun gnus-member-of-valid (symbol group)
11977 (memq symbol (assoc
11978 (format "%s" (car (gnus-find-method-for-group group)))
11979 gnus-valid-select-methods)))
11980
11981 (defun gnus-secondary-method-p (method)
11982 (let ((methods gnus-secondary-select-methods)
11983 (gmethod (gnus-server-get-method nil method)))
11984 (while (and methods
11985 (not (equal (gnus-server-get-method nil (car methods))
11986 gmethod)))
11987 (setq methods (cdr methods)))
11988 methods))
11989
11990 (defun gnus-find-method-for-group (group &optional info)
11991 (or gnus-override-method
11992 (and (not group)
11993 gnus-select-method)
11994 (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
11995 method)
11996 (if (or (not info)
11997 (not (setq method (nth 4 info))))
11998 (setq method gnus-select-method)
11999 (setq method
12000 (cond ((stringp method)
12001 (gnus-server-to-method method))
12002 ((stringp (car method))
12003 (gnus-server-extend-method group method))
12004 (t
12005 method))))
12006 (gnus-server-add-address method))))
12007
12008 (defun gnus-check-backend-function (func group)
12009 (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
12010 group)))
12011 (fboundp (intern (format "%s-%s" method func)))))
12012
12013 (defun gnus-methods-using (method)
12014 (let ((valids gnus-valid-select-methods)
12015 outs)
12016 (while valids
12017 (if (memq method (car valids))
12018 (setq outs (cons (car valids) outs)))
12019 (setq valids (cdr valids)))
12020 outs))
12021
12022 ;;;
12023 ;;; Active & Newsrc File Handling
12024 ;;;
12025
12026 ;; Newsrc related functions.
12027 ;; Gnus internal format of gnus-newsrc-alist:
12028 ;; (("alt.general" 3 (1 . 1))
12029 ;; ("alt.misc" 3 ((1 . 10) (12 . 15)))
12030 ;; ("alt.test" 7 (1 . 99) (45 57 93)) ...)
12031 ;; The first item is the group name; the second is the subscription
12032 ;; level; the third is either a range of a list of ranges of read
12033 ;; articles, the optional fourth element is a list of marked articles,
12034 ;; the optional fifth element is the select method.
12035 ;;
12036 ;; Gnus internal format of gnus-newsrc-hashtb:
12037 ;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...)
12038 ;; This is the entry for "alt.misc". The first element is the number
12039 ;; of unread articles in "alt.misc". The cdr of this entry is the
12040 ;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is
12041 ;; trivial to remove or add new elements into gnus-newsrc-alist
12042 ;; without scanning the entire list. So, to get the actual information
12043 ;; of "alt.misc", you'd say something like
12044 ;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb))
12045 ;;
12046 ;; Gnus internal format of gnus-active-hashtb:
12047 ;; ((1 . 1))
12048 ;; (5 . 10))
12049 ;; (67 . 99)) ...)
12050 ;; The only element in each entry in this hash table is a range of
12051 ;; (possibly) available articles. (Articles in this range may have
12052 ;; been expired or canceled.)
12053 ;;
12054 ;; Gnus internal format of gnus-killed-list and gnus-zombie-list:
12055 ;; ("alt.misc" "alt.test" "alt.general" ...)
12056
12057 (defun gnus-setup-news (&optional rawfile level)
12058 "Setup news information.
12059 If RAWFILE is non-nil, the .newsrc file will also be read.
12060 If LEVEL is non-nil, the news will be set up at level LEVEL."
12061 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
12062 ;; Clear some variables to re-initialize news information.
12063 (if init (setq gnus-newsrc-alist nil
12064 gnus-active-hashtb nil))
12065
12066 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
12067 (if init (gnus-read-newsrc-file rawfile))
12068
12069 ;; If we don't read the complete active file, we fill in the
12070 ;; hashtb here.
12071 (if (or (null gnus-read-active-file)
12072 (eq gnus-read-active-file 'some))
12073 (gnus-update-active-hashtb-from-killed))
12074
12075 ;; Read the active file and create `gnus-active-hashtb'.
12076 ;; If `gnus-read-active-file' is nil, then we just create an empty
12077 ;; hash table. The partial filling out of the hash table will be
12078 ;; done in `gnus-get-unread-articles'.
12079 (and gnus-read-active-file
12080 (not level)
12081 (gnus-read-active-file))
12082
12083 (or gnus-active-hashtb
12084 (setq gnus-active-hashtb (make-vector 4095 0)))
12085
12086 ;; Possibly eval the dribble file.
12087 (and init gnus-use-dribble-file (gnus-dribble-eval-file))
12088
12089 (gnus-update-format-specifications)
12090
12091 ;; Find new newsgroups and treat them.
12092 (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level)
12093 (gnus-check-server gnus-select-method))
12094 (gnus-find-new-newsgroups))
12095
12096 ;; Find the number of unread articles in each non-dead group.
12097 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
12098 (gnus-get-unread-articles (or level (1+ gnus-level-subscribed))))
12099
12100 (if (and init gnus-check-bogus-newsgroups
12101 gnus-read-active-file (not level)
12102 (gnus-server-opened gnus-select-method))
12103 (gnus-check-bogus-newsgroups))))
12104
12105 (defun gnus-find-new-newsgroups ()
12106 "Search for new newsgroups and add them.
12107 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
12108 The `-n' option line from .newsrc is respected."
12109 (interactive)
12110 (or (gnus-check-first-time-used)
12111 (if (or (consp gnus-check-new-newsgroups)
12112 (eq gnus-check-new-newsgroups 'ask-server))
12113 (gnus-ask-server-for-new-groups)
12114 (let ((groups 0)
12115 group new-newsgroups)
12116 (gnus-message 5 "Looking for new newsgroups...")
12117 (or gnus-have-read-active-file (gnus-read-active-file))
12118 (setq gnus-newsrc-last-checked-date (current-time-string))
12119 (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed))
12120 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
12121 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
12122 (mapatoms
12123 (lambda (sym)
12124 (if (or (null (setq group (symbol-name sym)))
12125 (null (symbol-value sym))
12126 (gnus-gethash group gnus-killed-hashtb)
12127 (gnus-gethash group gnus-newsrc-hashtb))
12128 ()
12129 (let ((do-sub (gnus-matches-options-n group)))
12130 (cond
12131 ((eq do-sub 'subscribe)
12132 (setq groups (1+ groups))
12133 (gnus-sethash group group gnus-killed-hashtb)
12134 (funcall gnus-subscribe-options-newsgroup-method group))
12135 ((eq do-sub 'ignore)
12136 nil)
12137 (t
12138 (setq groups (1+ groups))
12139 (gnus-sethash group group gnus-killed-hashtb)
12140 (if gnus-subscribe-hierarchical-interactive
12141 (setq new-newsgroups (cons group new-newsgroups))
12142 (funcall gnus-subscribe-newsgroup-method group)))))))
12143 gnus-active-hashtb)
12144 (if new-newsgroups
12145 (gnus-subscribe-hierarchical-interactive new-newsgroups))
12146 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12147 (if (> groups 0)
12148 (gnus-message 6 "%d new newsgroup%s arrived."
12149 groups (if (> groups 1) "s have" " has"))
12150 (gnus-message 6 "No new newsgroups."))))))
12151
12152 (defun gnus-matches-options-n (group)
12153 ;; Returns `subscribe' if the group is to be unconditionally
12154 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
12155 ;; no match for the group.
12156
12157 ;; First we check the two user variables.
12158 (cond
12159 ((and gnus-options-subscribe
12160 (string-match gnus-options-subscribe group))
12161 'subscribe)
12162 ((and gnus-options-not-subscribe
12163 (string-match gnus-options-not-subscribe group))
12164 'ignore)
12165 ;; Then we go through the list that was retrieved from the .newsrc
12166 ;; file. This list has elements on the form
12167 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
12168 ;; is in the reverse order of the options line) is returned.
12169 (t
12170 (let ((regs gnus-newsrc-options-n))
12171 (while (and regs
12172 (not (string-match (car (car regs)) group)))
12173 (setq regs (cdr regs)))
12174 (and regs (cdr (car regs)))))))
12175
12176 (defun gnus-ask-server-for-new-groups ()
12177 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
12178 (methods (cons gnus-select-method
12179 (append
12180 (and (consp gnus-check-new-newsgroups)
12181 gnus-check-new-newsgroups)
12182 gnus-secondary-select-methods)))
12183 (groups 0)
12184 (new-date (current-time-string))
12185 (hashtb (gnus-make-hashtable 100))
12186 group new-newsgroups got-new method)
12187 ;; Go through both primary and secondary select methods and
12188 ;; request new newsgroups.
12189 (while methods
12190 (setq method (gnus-server-get-method nil (car methods)))
12191 (and (gnus-check-server method)
12192 (gnus-request-newgroups date method)
12193 (save-excursion
12194 (setq got-new t)
12195 (set-buffer nntp-server-buffer)
12196 ;; Enter all the new groups in a hashtable.
12197 (gnus-active-to-gnus-format method hashtb 'ignore)))
12198 (setq methods (cdr methods)))
12199 (and got-new (setq gnus-newsrc-last-checked-date new-date))
12200 ;; Now all new groups from all select methods are in `hashtb'.
12201 (mapatoms
12202 (lambda (group-sym)
12203 (setq group (symbol-name group-sym))
12204 (if (or (null group)
12205 (null (symbol-value group-sym))
12206 (gnus-gethash group gnus-newsrc-hashtb)
12207 (member group gnus-zombie-list)
12208 (member group gnus-killed-list))
12209 ;; The group is already known.
12210 ()
12211 (and (symbol-value group-sym)
12212 (gnus-sethash group (symbol-value group-sym) gnus-active-hashtb))
12213 (let ((do-sub (gnus-matches-options-n group)))
12214 (cond ((eq do-sub 'subscribe)
12215 (setq groups (1+ groups))
12216 (gnus-sethash group group gnus-killed-hashtb)
12217 (funcall
12218 gnus-subscribe-options-newsgroup-method group))
12219 ((eq do-sub 'ignore)
12220 nil)
12221 (t
12222 (setq groups (1+ groups))
12223 (gnus-sethash group group gnus-killed-hashtb)
12224 (if gnus-subscribe-hierarchical-interactive
12225 (setq new-newsgroups (cons group new-newsgroups))
12226 (funcall gnus-subscribe-newsgroup-method group)))))))
12227 hashtb)
12228 (if new-newsgroups
12229 (gnus-subscribe-hierarchical-interactive new-newsgroups))
12230 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12231 (if (> groups 0)
12232 (gnus-message 6 "%d new newsgroup%s arrived."
12233 groups (if (> groups 1) "s have" " has")))
12234 got-new))
12235
12236 (defun gnus-check-first-time-used ()
12237 (if (or (> (length gnus-newsrc-alist) 1)
12238 (file-exists-p gnus-startup-file)
12239 (file-exists-p (concat gnus-startup-file ".el"))
12240 (file-exists-p (concat gnus-startup-file ".eld")))
12241 nil
12242 (gnus-message 6 "First time user; subscribing you to default groups")
12243 (or gnus-have-read-active-file (gnus-read-active-file))
12244 (setq gnus-newsrc-last-checked-date (current-time-string))
12245 (let ((groups gnus-default-subscribed-newsgroups)
12246 group)
12247 (if (eq groups t)
12248 nil
12249 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
12250 (mapatoms
12251 (lambda (sym)
12252 (if (null (setq group (symbol-name sym)))
12253 ()
12254 (let ((do-sub (gnus-matches-options-n group)))
12255 (cond
12256 ((eq do-sub 'subscribe)
12257 (gnus-sethash group group gnus-killed-hashtb)
12258 (funcall gnus-subscribe-options-newsgroup-method group))
12259 ((eq do-sub 'ignore)
12260 nil)
12261 (t
12262 (setq gnus-killed-list (cons group gnus-killed-list)))))))
12263 gnus-active-hashtb)
12264 (while groups
12265 (if (gnus-gethash (car groups) gnus-active-hashtb)
12266 (gnus-group-change-level
12267 (car groups) gnus-level-default-subscribed gnus-level-killed))
12268 (setq groups (cdr groups)))
12269 (gnus-group-make-help-group)
12270 (and gnus-novice-user
12271 (gnus-message 7 "`A k' to list killed groups"))))))
12272
12273 (defun gnus-subscribe-group (group previous &optional method)
12274 (gnus-group-change-level
12275 (if method
12276 (list t group gnus-level-default-subscribed nil nil method)
12277 group)
12278 gnus-level-default-subscribed gnus-level-killed previous t))
12279
12280 ;; `gnus-group-change-level' is the fundamental function for changing
12281 ;; subscription levels of newsgroups. This might mean just changing
12282 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
12283 ;; again, which subscribes/unsubscribes a group, which is equally
12284 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
12285 ;; from 8-9 to 1-7 means that you remove the group from the list of
12286 ;; killed (or zombie) groups and add them to the (kinda) subscribed
12287 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
12288 ;; which is trivial.
12289 ;; ENTRY can either be a string (newsgroup name) or a list (if
12290 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
12291 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
12292 ;; entries.
12293 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
12294 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
12295 ;; after.
12296 (defun gnus-group-change-level (entry level &optional oldlevel
12297 previous fromkilled)
12298 (let (group info active num)
12299 ;; Glean what info we can from the arguments
12300 (if (consp entry)
12301 (if fromkilled (setq group (nth 1 entry))
12302 (setq group (car (nth 2 entry))))
12303 (setq group entry))
12304 (if (and (stringp entry)
12305 oldlevel
12306 (< oldlevel gnus-level-zombie))
12307 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
12308 (if (and (not oldlevel)
12309 (consp entry))
12310 (setq oldlevel (car (cdr (nth 2 entry)))))
12311 (if (stringp previous)
12312 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
12313
12314 (if (and (>= oldlevel gnus-level-zombie)
12315 (gnus-gethash group gnus-newsrc-hashtb))
12316 ;; We are trying to subscribe a group that is already
12317 ;; subscribed.
12318 () ; Do nothing.
12319
12320 (or (gnus-ephemeral-group-p group)
12321 (gnus-dribble-enter
12322 (format "(gnus-group-change-level %S %S %S %S %S)"
12323 group level oldlevel (car (nth 2 previous)) fromkilled)))
12324
12325 ;; Then we remove the newgroup from any old structures, if needed.
12326 ;; If the group was killed, we remove it from the killed or zombie
12327 ;; list. If not, and it is in fact going to be killed, we remove
12328 ;; it from the newsrc hash table and assoc.
12329 (cond ((>= oldlevel gnus-level-zombie)
12330 (if (= oldlevel gnus-level-zombie)
12331 (setq gnus-zombie-list (delete group gnus-zombie-list))
12332 (setq gnus-killed-list (delete group gnus-killed-list))))
12333 (t
12334 (if (and (>= level gnus-level-zombie)
12335 entry)
12336 (progn
12337 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
12338 (if (nth 3 entry)
12339 (setcdr (gnus-gethash (car (nth 3 entry))
12340 gnus-newsrc-hashtb)
12341 (cdr entry)))
12342 (setcdr (cdr entry) (cdr (cdr (cdr entry))))))))
12343
12344 ;; Finally we enter (if needed) the list where it is supposed to
12345 ;; go, and change the subscription level. If it is to be killed,
12346 ;; we enter it into the killed or zombie list.
12347 (cond ((>= level gnus-level-zombie)
12348 ;; Remove from the hash table.
12349 (gnus-sethash group nil gnus-newsrc-hashtb)
12350 (or (gnus-group-foreign-p group)
12351 ;; We do not enter foreign groups into the list of dead
12352 ;; groups.
12353 (if (= level gnus-level-zombie)
12354 (setq gnus-zombie-list (cons group gnus-zombie-list))
12355 (setq gnus-killed-list (cons group gnus-killed-list)))))
12356 (t
12357 ;; If the list is to be entered into the newsrc assoc, and
12358 ;; it was killed, we have to create an entry in the newsrc
12359 ;; hashtb format and fix the pointers in the newsrc assoc.
12360 (if (>= oldlevel gnus-level-zombie)
12361 (progn
12362 (if (listp entry)
12363 (progn
12364 (setq info (cdr entry))
12365 (setq num (car entry)))
12366 (setq active (gnus-gethash group gnus-active-hashtb))
12367 (setq num
12368 (if active (- (1+ (cdr active)) (car active)) t))
12369 ;; Check whether the group is foreign. If so, the
12370 ;; foreign select method has to be entered into the
12371 ;; info.
12372 (let ((method (gnus-group-method-name group)))
12373 (if (eq method gnus-select-method)
12374 (setq info (list group level nil))
12375 (setq info (list group level nil nil method)))))
12376 (or previous
12377 (setq previous
12378 (let ((p gnus-newsrc-alist))
12379 (while (cdr (cdr p))
12380 (setq p (cdr p)))
12381 p)))
12382 (setq entry (cons info (cdr (cdr previous))))
12383 (if (cdr previous)
12384 (progn
12385 (setcdr (cdr previous) entry)
12386 (gnus-sethash group (cons num (cdr previous))
12387 gnus-newsrc-hashtb))
12388 (setcdr previous entry)
12389 (gnus-sethash group (cons num previous)
12390 gnus-newsrc-hashtb))
12391 (if (cdr entry)
12392 (setcdr (gnus-gethash (car (car (cdr entry)))
12393 gnus-newsrc-hashtb)
12394 entry)))
12395 ;; It was alive, and it is going to stay alive, so we
12396 ;; just change the level and don't change any pointers or
12397 ;; hash table entries.
12398 (setcar (cdr (car (cdr (cdr entry)))) level)))))))
12399
12400 (defun gnus-kill-newsgroup (newsgroup)
12401 "Obsolete function. Kills a newsgroup."
12402 (gnus-group-change-level
12403 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
12404
12405 (defun gnus-check-bogus-newsgroups (&optional confirm)
12406 "Remove bogus newsgroups.
12407 If CONFIRM is non-nil, the user has to confirm the deletion of every
12408 newsgroup."
12409 (let ((newsrc (cdr gnus-newsrc-alist))
12410 bogus group entry)
12411 (gnus-message 5 "Checking bogus newsgroups...")
12412 (or gnus-have-read-active-file (gnus-read-active-file))
12413 ;; Find all bogus newsgroup that are subscribed.
12414 (while newsrc
12415 (setq group (car (car newsrc)))
12416 (if (or (gnus-gethash group gnus-active-hashtb) ; Active
12417 (nth 4 (car newsrc)) ; Foreign
12418 (and confirm
12419 (not (gnus-y-or-n-p
12420 (format "Remove bogus newsgroup: %s " group)))))
12421 ;; Don't remove.
12422 ()
12423 ;; Found a bogus newsgroup.
12424 (setq bogus (cons group bogus)))
12425 (setq newsrc (cdr newsrc)))
12426 ;; Remove all bogus subscribed groups by first killing them, and
12427 ;; then removing them from the list of killed groups.
12428 (while bogus
12429 (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb))
12430 (progn
12431 (gnus-group-change-level entry gnus-level-killed)
12432 (setq gnus-killed-list (delete (car bogus) gnus-killed-list))))
12433 (setq bogus (cdr bogus)))
12434 ;; Then we remove all bogus groups from the list of killed and
12435 ;; zombie groups. They are are removed without confirmation.
12436 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
12437 killed)
12438 (while dead-lists
12439 (setq killed (symbol-value (car dead-lists)))
12440 (while killed
12441 (setq group (car killed))
12442 (or (gnus-gethash group gnus-active-hashtb)
12443 ;; The group is bogus.
12444 (set (car dead-lists)
12445 (delete group (symbol-value (car dead-lists)))))
12446 (setq killed (cdr killed)))
12447 (setq dead-lists (cdr dead-lists))))
12448 (gnus-message 5 "Checking bogus newsgroups...done")))
12449
12450 (defun gnus-check-duplicate-killed-groups ()
12451 "Remove duplicates from the list of killed groups."
12452 (interactive)
12453 (let ((killed gnus-killed-list))
12454 (while killed
12455 (gnus-message 9 "%d" (length killed))
12456 (setcdr killed (delete (car killed) (cdr killed)))
12457 (setq killed (cdr killed)))))
12458
12459 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
12460 ;; and compute how many unread articles there are in each group.
12461 (defun gnus-get-unread-articles (&optional level)
12462 (let* ((newsrc (cdr gnus-newsrc-alist))
12463 (level (or level (1+ gnus-level-subscribed)))
12464 (foreign-level
12465 (min
12466 (cond ((and gnus-activate-foreign-newsgroups
12467 (not (numberp gnus-activate-foreign-newsgroups)))
12468 (1+ gnus-level-subscribed))
12469 ((numberp gnus-activate-foreign-newsgroups)
12470 gnus-activate-foreign-newsgroups)
12471 (t 0))
12472 level))
12473 info group active virtuals method)
12474 (gnus-message 5 "Checking new news...")
12475
12476 (while newsrc
12477 (setq info (car newsrc)
12478 group (car info)
12479 active (gnus-gethash group gnus-active-hashtb))
12480
12481 ;; Check newsgroups. If the user doesn't want to check them, or
12482 ;; they can't be checked (for instance, if the news server can't
12483 ;; be reached) we just set the number of unread articles in this
12484 ;; newsgroup to t. This means that Gnus thinks that there are
12485 ;; unread articles, but it has no idea how many.
12486 (if (and (setq method (nth 4 info))
12487 (not (gnus-server-equal gnus-select-method
12488 (gnus-server-get-method nil method)))
12489 (not (gnus-secondary-method-p method)))
12490 ;; These groups are foreign. Check the level.
12491 (if (<= (nth 1 info) foreign-level)
12492 (if (eq (car (if (stringp method)
12493 (gnus-server-to-method method)
12494 (nth 4 info))) 'nnvirtual)
12495 ;; We have to activate the virtual groups after all
12496 ;; the others, so we just pop them on a list for
12497 ;; now.
12498 (setq virtuals (cons info virtuals))
12499 (and (setq active (gnus-activate-group (car info)))
12500 ;; Close the groups as we look at them!
12501 (gnus-close-group group))))
12502
12503 ;; These groups are native or secondary.
12504 (if (and (not gnus-read-active-file)
12505 (<= (nth 1 info) level))
12506 (progn
12507 (or gnus-read-active-file (gnus-check-server method))
12508 (setq active (gnus-activate-group (car info))))))
12509
12510 (if active
12511 (gnus-get-unread-articles-in-group info active)
12512 ;; The group couldn't be reached, so we nix out the number of
12513 ;; unread articles and stuff.
12514 (gnus-sethash group nil gnus-active-hashtb)
12515 (setcar (gnus-gethash group gnus-newsrc-hashtb) t))
12516
12517 (setq newsrc (cdr newsrc)))
12518
12519 ;; Activate the virtual groups. This has to be done after all the
12520 ;; other groups.
12521 ;; !!! If one virtual group contains another virtual group, even
12522 ;; doing it this way might cause problems.
12523 (while virtuals
12524 (and (setq active (gnus-activate-group (car (car virtuals))))
12525 (gnus-get-unread-articles-in-group (car virtuals) active))
12526 (setq virtuals (cdr virtuals)))
12527
12528 (gnus-message 5 "Checking new news...done")))
12529
12530 ;; Create a hash table out of the newsrc alist. The `car's of the
12531 ;; alist elements are used as keys.
12532 (defun gnus-make-hashtable-from-newsrc-alist ()
12533 (let ((alist gnus-newsrc-alist)
12534 (ohashtb gnus-newsrc-hashtb)
12535 prev)
12536 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
12537 (setq alist
12538 (setq prev (setq gnus-newsrc-alist
12539 (if (equal (car (car gnus-newsrc-alist))
12540 "dummy.group")
12541 gnus-newsrc-alist
12542 (cons (list "dummy.group" 0 nil) alist)))))
12543 (while alist
12544 (gnus-sethash (car (car alist))
12545 (cons (and ohashtb (car (gnus-gethash
12546 (car (car alist)) ohashtb)))
12547 prev) gnus-newsrc-hashtb)
12548 (setq prev alist
12549 alist (cdr alist)))))
12550
12551 (defun gnus-make-hashtable-from-killed ()
12552 "Create a hash table from the killed and zombie lists."
12553 (let ((lists '(gnus-killed-list gnus-zombie-list))
12554 list)
12555 (setq gnus-killed-hashtb
12556 (gnus-make-hashtable
12557 (+ (length gnus-killed-list) (length gnus-zombie-list))))
12558 (while lists
12559 (setq list (symbol-value (car lists)))
12560 (setq lists (cdr lists))
12561 (while list
12562 (gnus-sethash (car list) (car list) gnus-killed-hashtb)
12563 (setq list (cdr list))))))
12564
12565 (defun gnus-get-unread-articles-in-group (info active)
12566 (let* ((range (nth 2 info))
12567 (num 0)
12568 (marked (nth 3 info)))
12569 ;; If a cache is present, we may have to alter the active info.
12570 (and gnus-use-cache
12571 (gnus-cache-possibly-alter-active (car info) active))
12572 ;; Modify the list of read articles according to what articles
12573 ;; are available; then tally the unread articles and add the
12574 ;; number to the group hash table entry.
12575 (cond
12576 ((zerop (cdr active))
12577 (setq num 0))
12578 ((not range)
12579 (setq num (- (1+ (cdr active)) (car active))))
12580 ((not (listp (cdr range)))
12581 ;; Fix a single (num . num) range according to the
12582 ;; active hash table.
12583 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
12584 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
12585 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
12586 ;; Compute number of unread articles.
12587 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
12588 (t
12589 ;; The read list is a list of ranges. Fix them according to
12590 ;; the active hash table.
12591 ;; First peel off any elements that are below the lower
12592 ;; active limit.
12593 (while (and (cdr range)
12594 (>= (car active)
12595 (or (and (atom (car (cdr range))) (car (cdr range)))
12596 (car (car (cdr range))))))
12597 (if (numberp (car range))
12598 (setcar range
12599 (cons (car range)
12600 (or (and (numberp (car (cdr range)))
12601 (car (cdr range)))
12602 (cdr (car (cdr range))))))
12603 (setcdr (car range)
12604 (or (and (numberp (nth 1 range)) (nth 1 range))
12605 (cdr (car (cdr range))))))
12606 (setcdr range (cdr (cdr range))))
12607 ;; Adjust the first element to be the same as the lower limit.
12608 (if (and (not (atom (car range)))
12609 (< (cdr (car range)) (car active)))
12610 (setcdr (car range) (1- (car active))))
12611 ;; Then we want to peel off any elements that are higher
12612 ;; than the upper active limit.
12613 (let ((srange range))
12614 ;; Go past all legal elements.
12615 (while (and (cdr srange)
12616 (<= (or (and (atom (car (cdr srange)))
12617 (car (cdr srange)))
12618 (car (car (cdr srange)))) (cdr active)))
12619 (setq srange (cdr srange)))
12620 (if (cdr srange)
12621 ;; Nuke all remaining illegal elements.
12622 (setcdr srange nil))
12623
12624 ;; Adjust the final element.
12625 (if (and (not (atom (car srange)))
12626 (> (cdr (car srange)) (cdr active)))
12627 (setcdr (car srange) (cdr active))))
12628 ;; Compute the number of unread articles.
12629 (while range
12630 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
12631 (cdr (car range))))
12632 (or (and (atom (car range)) (car range))
12633 (car (car range))))))
12634 (setq range (cdr range)))
12635 (setq num (max 0 (- (cdr active) num)))))
12636 (and info
12637 (progn
12638 (and (assq 'tick marked)
12639 (inline (gnus-remove-illegal-marked-articles
12640 (assq 'tick marked) (nth 2 info))))
12641 (and (assq 'dormant marked)
12642 (inline (gnus-remove-illegal-marked-articles
12643 (assq 'dormant marked) (nth 2 info))))
12644 (setcar
12645 (gnus-gethash (car info) gnus-newsrc-hashtb)
12646 (setq num (max 0 (- num (length (cdr (assq 'tick marked)))
12647 (length (cdr (assq 'dormant marked)))))))))
12648 num))
12649
12650 (defun gnus-remove-illegal-marked-articles (marked ranges)
12651 (let ((m (cdr marked)))
12652 ;; Make sure that all ticked articles are a subset of the unread
12653 ;; articles.
12654 (while m
12655 (if (gnus-member-of-range (car m) ranges)
12656 (setcdr marked (cdr m))
12657 (setq marked m))
12658 (setq m (cdr m)))))
12659
12660 (defun gnus-activate-group (group)
12661 ;; Check whether a group has been activated or not.
12662 (let ((method (gnus-find-method-for-group group))
12663 active)
12664 (and (gnus-check-server method)
12665 ;; We escape all bugs and quit here to make it possible to
12666 ;; continue if a group is so out-there that it reports bugs
12667 ;; and stuff.
12668 (condition-case ()
12669 (gnus-request-group group)
12670 (error nil)
12671 (quit nil))
12672 (save-excursion
12673 (set-buffer nntp-server-buffer)
12674 (goto-char (point-min))
12675 ;; Parse the result we got from `gnus-request-group'.
12676 (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
12677 (progn
12678 (goto-char (match-beginning 1))
12679 (gnus-sethash
12680 group (setq active (cons (read (current-buffer))
12681 (read (current-buffer))))
12682 gnus-active-hashtb))
12683 ;; Return the new active info.
12684 active)))))
12685
12686 (defun gnus-update-read-articles
12687 (group unread unselected ticked &optional domarks replied expirable killed
12688 dormant bookmark score)
12689 "Update the list of read and ticked articles in GROUP using the
12690 UNREAD and TICKED lists.
12691 Note: UNSELECTED has to be sorted over `<'.
12692 Returns whether the updating was successful."
12693 (let* ((active (or gnus-newsgroup-active
12694 (gnus-gethash group gnus-active-hashtb)))
12695 (entry (gnus-gethash group gnus-newsrc-hashtb))
12696 (info (nth 2 entry))
12697 (marked (nth 3 info))
12698 (prev 1)
12699 (unread (sort (copy-sequence unread) (function <)))
12700 read)
12701 (if (or (not info) (not active))
12702 ;; There is no info on this group if it was, in fact,
12703 ;; killed. Gnus stores no information on killed groups, so
12704 ;; there's nothing to be done.
12705 ;; One could store the information somewhere temporarily,
12706 ;; perhaps... Hmmm...
12707 ()
12708 ;; Remove any negative articles numbers.
12709 (while (and unread (< (car unread) 0))
12710 (setq unread (cdr unread)))
12711 ;; Remove any expired article numbers
12712 (while (and unread (< (car unread) (car active)))
12713 (setq unread (cdr unread)))
12714 (while (and ticked (< (car ticked) (car active)))
12715 (setq ticked (cdr ticked)))
12716 (while (and dormant (< (car dormant) (car active)))
12717 (setq dormant (cdr dormant)))
12718 (setq unread (sort (append unselected unread) '<))
12719 ;; Weed out duplicates.
12720 (let ((un unread))
12721 (while (cdr un)
12722 (if (eq (car un) (car (cdr un)))
12723 (setcdr un (cdr (cdr un)))
12724 (setq un (cdr un)))))
12725 ;; Compute the ranges of read articles by looking at the list of
12726 ;; unread articles.
12727 (while unread
12728 (if (/= (car unread) prev)
12729 (setq read (cons (if (= prev (1- (car unread))) prev
12730 (cons prev (1- (car unread)))) read)))
12731 (setq prev (1+ (car unread)))
12732 (setq unread (cdr unread)))
12733 (if (<= prev (cdr active))
12734 (setq read (cons (cons prev (cdr active)) read)))
12735 ;; Enter this list into the group info.
12736 (setcar (cdr (cdr info))
12737 (if (> (length read) 1) (nreverse read) read))
12738 ;; Enter the list of ticked articles.
12739 (gnus-set-marked-articles
12740 info ticked
12741 (if domarks replied (cdr (assq 'reply marked)))
12742 (if domarks expirable (cdr (assq 'expire marked)))
12743 (if domarks killed (cdr (assq 'killed marked)))
12744 (if domarks dormant (cdr (assq 'dormant marked)))
12745 (if domarks bookmark (cdr (assq 'bookmark marked)))
12746 (if domarks score (cdr (assq 'score marked))))
12747 ;; Set the number of unread articles in gnus-newsrc-hashtb.
12748 (gnus-get-unread-articles-in-group
12749 info (gnus-gethash group gnus-active-hashtb))
12750 t)))
12751
12752 (defun gnus-make-articles-unread (group articles)
12753 "Mark ARTICLES in GROUP as unread."
12754 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
12755 (gnus-gethash (gnus-group-real-name group)
12756 gnus-newsrc-hashtb))))
12757 (ranges (nth 2 info))
12758 news)
12759 (while articles
12760 (and (gnus-member-of-range (car articles) ranges)
12761 (setq news (cons (car articles) news)))
12762 (setq articles (cdr articles)))
12763 (if (not news)
12764 ()
12765 (setcar (nthcdr 2 info)
12766 (gnus-remove-from-range (nth 2 info) (nreverse news)))
12767 (gnus-group-update-group group t))))
12768
12769 ;; Enter all dead groups into the hashtb.
12770 (defun gnus-update-active-hashtb-from-killed ()
12771 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
12772 (lists (list gnus-killed-list gnus-zombie-list))
12773 killed)
12774 (while lists
12775 (setq killed (car lists))
12776 (while killed
12777 (gnus-sethash (car killed) nil hashtb)
12778 (setq killed (cdr killed)))
12779 (setq lists (cdr lists)))))
12780
12781 ;; Get the active file(s) from the backend(s).
12782 (defun gnus-read-active-file ()
12783 (gnus-group-set-mode-line)
12784 (let ((methods (if (gnus-check-server gnus-select-method)
12785 ;; The native server is available.
12786 (cons gnus-select-method gnus-secondary-select-methods)
12787 ;; The native server is down, so we just do the
12788 ;; secondary ones.
12789 gnus-secondary-select-methods))
12790 list-type)
12791 (setq gnus-have-read-active-file nil)
12792 (save-excursion
12793 (set-buffer nntp-server-buffer)
12794 (while methods
12795 (let* ((method (gnus-server-get-method nil (car methods)))
12796 (where (nth 1 method))
12797 (mesg (format "Reading active file%s via %s..."
12798 (if (and where (not (zerop (length where))))
12799 (concat " from " where) "")
12800 (car method))))
12801 (gnus-message 5 mesg)
12802 (if (not (gnus-check-server method))
12803 ()
12804 (cond
12805 ((and (eq gnus-read-active-file 'some)
12806 (gnus-check-backend-function 'retrieve-groups (car method)))
12807 (let ((newsrc (cdr gnus-newsrc-alist))
12808 (gmethod (gnus-server-get-method nil method))
12809 groups)
12810 (while newsrc
12811 (and (gnus-server-equal
12812 (gnus-find-method-for-group
12813 (car (car newsrc)) (car newsrc))
12814 gmethod)
12815 (setq groups (cons (gnus-group-real-name
12816 (car (car newsrc))) groups)))
12817 (setq newsrc (cdr newsrc)))
12818 (gnus-check-server method)
12819 (setq list-type (gnus-retrieve-groups groups method))
12820 (cond
12821 ((not list-type)
12822 (gnus-message
12823 1 "Cannot read partial active file from %s server."
12824 (car method))
12825 (ding)
12826 (sit-for 2))
12827 ((eq list-type 'active)
12828 (gnus-active-to-gnus-format method gnus-active-hashtb))
12829 (t
12830 (gnus-groups-to-gnus-format method gnus-active-hashtb)))))
12831 (t
12832 (if (not (gnus-request-list method))
12833 (progn
12834 (gnus-message 1 "Cannot read active file from %s server."
12835 (car method))
12836 (ding))
12837 (gnus-active-to-gnus-format method)
12838 ;; We mark this active file as read.
12839 (setq gnus-have-read-active-file
12840 (cons method gnus-have-read-active-file))
12841 (gnus-message 5 "%sdone" mesg))))))
12842 (setq methods (cdr methods))))))
12843
12844 ;; Read an active file and place the results in `gnus-active-hashtb'.
12845 (defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors)
12846 (let ((cur (current-buffer))
12847 (hashtb (or hashtb
12848 (if (and gnus-active-hashtb
12849 (not (equal method gnus-select-method)))
12850 gnus-active-hashtb
12851 (setq gnus-active-hashtb
12852 (if (equal method gnus-select-method)
12853 (gnus-make-hashtable
12854 (count-lines (point-min) (point-max)))
12855 (gnus-make-hashtable 4096))))))
12856 (flag-hashtb (gnus-make-hashtable 60)))
12857 ;; Delete unnecessary lines.
12858 (goto-char (point-min))
12859 (while (search-forward "\nto." nil t)
12860 (delete-region (1+ (match-beginning 0))
12861 (progn (forward-line 1) (point))))
12862 (or (string= gnus-ignored-newsgroups "")
12863 (progn
12864 (goto-char (point-min))
12865 (delete-matching-lines gnus-ignored-newsgroups)))
12866 ;; Make the group names readable as a lisp expression even if they
12867 ;; contain special characters.
12868 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
12869 (goto-char (point-max))
12870 (while (re-search-backward "[][';?()#]" nil t)
12871 (insert ?\\))
12872 ;; If these are groups from a foreign select method, we insert the
12873 ;; group prefix in front of the group names.
12874 (and method (not (gnus-server-equal
12875 (gnus-server-get-method nil method)
12876 (gnus-server-get-method nil gnus-select-method)))
12877 (let ((prefix (gnus-group-prefixed-name "" method)))
12878 (goto-char (point-min))
12879 (while (and (not (eobp))
12880 (progn (insert prefix)
12881 (zerop (forward-line 1)))))))
12882 ;; Store the active file in a hash table.
12883 (goto-char (point-min))
12884 (if (string-match "%[oO]" gnus-group-line-format)
12885 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
12886 ;; If we want information on moderated groups, we use this
12887 ;; loop...
12888 (let* ((mod-hashtb (make-vector 7 0))
12889 (m (intern "m" mod-hashtb))
12890 group max min)
12891 (while (not (eobp))
12892 (condition-case nil
12893 (progn
12894 (narrow-to-region (point) (gnus-point-at-eol))
12895 (setq group (let ((obarray hashtb)) (read cur)))
12896 (if (and (numberp (setq max (read cur)))
12897 (numberp (setq min (read cur)))
12898 (progn
12899 (skip-chars-forward " \t")
12900 (not
12901 (or (= (following-char) ?=)
12902 (= (following-char) ?x)
12903 (= (following-char) ?j)))))
12904 (set group (cons min max))
12905 (set group nil))
12906 ;; Enter moderated groups into a list.
12907 (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
12908 (setq gnus-moderated-list
12909 (cons (symbol-name group) gnus-moderated-list))))
12910 (error
12911 (and group
12912 (symbolp group)
12913 (set group nil))))
12914 (widen)
12915 (forward-line 1)))
12916 ;; And if we do not care about moderation, we use this loop,
12917 ;; which is faster.
12918 (let (group max min)
12919 (while (not (eobp))
12920 (condition-case ()
12921 (progn
12922 (narrow-to-region (point) (gnus-point-at-eol))
12923 ;; group gets set to a symbol interned in the hash table
12924 ;; (what a hack!!) - jwz
12925 (setq group (let ((obarray hashtb)) (read cur)))
12926 (if (and (numberp (setq max (read cur)))
12927 (numberp (setq min (read cur)))
12928 (progn
12929 (skip-chars-forward " \t")
12930 (not
12931 (or (= (following-char) ?=)
12932 (= (following-char) ?x)
12933 (= (following-char) ?j)))))
12934 (set group (cons min max))
12935 (set group nil)))
12936 (error
12937 (progn
12938 (and group
12939 (symbolp group)
12940 (set group nil))
12941 (or ignore-errors
12942 (gnus-message 3 "Warning - illegal active: %s"
12943 (buffer-substring
12944 (gnus-point-at-bol) (gnus-point-at-eol)))))))
12945 (widen)
12946 (forward-line 1))))))
12947
12948 (defun gnus-groups-to-gnus-format (method &optional hashtb)
12949 ;; Parse a "groups" active file.
12950 (let ((cur (current-buffer))
12951 (hashtb (or hashtb
12952 (if (and method gnus-active-hashtb)
12953 gnus-active-hashtb
12954 (setq gnus-active-hashtb
12955 (gnus-make-hashtable
12956 (count-lines (point-min) (point-max)))))))
12957 (prefix (and method
12958 (not (gnus-server-equal
12959 (gnus-server-get-method nil method)
12960 (gnus-server-get-method nil gnus-select-method)))
12961 (gnus-group-prefixed-name "" method))))
12962
12963 (goto-char (point-min))
12964 ;; We split this into to separate loops, one with the prefix
12965 ;; and one without to speed the reading up somewhat.
12966 (if prefix
12967 (let (min max opoint group)
12968 (while (not (eobp))
12969 (condition-case ()
12970 (progn
12971 (read cur) (read cur)
12972 (setq min (read cur)
12973 max (read cur)
12974 opoint (point))
12975 (skip-chars-forward " \t")
12976 (insert prefix)
12977 (goto-char opoint)
12978 (set (let ((obarray hashtb)) (read cur))
12979 (cons min max)))
12980 (error (and group (symbolp group) (set group nil))))
12981 (forward-line 1)))
12982 (let (min max group)
12983 (while (not (eobp))
12984 (condition-case ()
12985 (if (= (following-char) ?2)
12986 (progn
12987 (read cur) (read cur)
12988 (setq min (read cur)
12989 max (read cur))
12990 (set (setq group (let ((obarray hashtb)) (read cur)))
12991 (cons min max))))
12992 (error (and group (symbolp group) (set group nil))))
12993 (forward-line 1))))))
12994
12995 (defun gnus-read-newsrc-file (&optional force)
12996 "Read startup file.
12997 If FORCE is non-nil, the .newsrc file is read."
12998 ;; Reset variables that might be defined in the .newsrc.eld file.
12999 (let ((variables gnus-variable-list))
13000 (while variables
13001 (set (car variables) nil)
13002 (setq variables (cdr variables))))
13003 (let* ((newsrc-file gnus-current-startup-file)
13004 (quick-file (concat newsrc-file ".el")))
13005 (save-excursion
13006 ;; We always load the .newsrc.eld file. If always contains
13007 ;; much information that can not be gotten from the .newsrc
13008 ;; file (ticked articles, killed groups, foreign methods, etc.)
13009 (gnus-read-newsrc-el-file quick-file)
13010
13011 (if (or force
13012 (and (file-newer-than-file-p newsrc-file quick-file)
13013 (file-newer-than-file-p newsrc-file
13014 (concat quick-file "d")))
13015 (not gnus-newsrc-alist))
13016 ;; We read the .newsrc file. Note that if there if a
13017 ;; .newsrc.eld file exists, it has already been read, and
13018 ;; the `gnus-newsrc-hashtb' has been created. While reading
13019 ;; the .newsrc file, Gnus will only use the information it
13020 ;; can find there for changing the data already read -
13021 ;; ie. reading the .newsrc file will not trash the data
13022 ;; already read (except for read articles).
13023 (save-excursion
13024 (gnus-message 5 "Reading %s..." newsrc-file)
13025 (set-buffer (find-file-noselect newsrc-file))
13026 (buffer-disable-undo (current-buffer))
13027 (gnus-newsrc-to-gnus-format)
13028 (kill-buffer (current-buffer))
13029 (gnus-message 5 "Reading %s...done" newsrc-file))))))
13030
13031 (defun gnus-read-newsrc-el-file (file)
13032 (let ((ding-file (concat file "d")))
13033 ;; We always, always read the .eld file.
13034 (gnus-message 5 "Reading %s..." ding-file)
13035 (let (gnus-newsrc-assoc)
13036 (condition-case nil
13037 (load ding-file t t t)
13038 (error nil))
13039 (and gnus-newsrc-assoc (setq gnus-newsrc-alist gnus-newsrc-assoc)))
13040 (let ((inhibit-quit t))
13041 (gnus-uncompress-newsrc-alist))
13042 (gnus-make-hashtable-from-newsrc-alist)
13043 (if (not (file-newer-than-file-p file ding-file))
13044 ()
13045 ;; Old format quick file
13046 (gnus-message 5 "Reading %s..." file)
13047 ;; The .el file is newer than the .eld file, so we read that one
13048 ;; as well.
13049 (gnus-read-old-newsrc-el-file file))))
13050
13051 ;; Parse the old-style quick startup file
13052 (defun gnus-read-old-newsrc-el-file (file)
13053 (let (newsrc killed marked group m)
13054 (prog1
13055 (let ((gnus-killed-assoc nil)
13056 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
13057 (prog1
13058 (condition-case nil
13059 (load file t t t)
13060 (error nil))
13061 (setq newsrc gnus-newsrc-assoc
13062 killed gnus-killed-assoc
13063 marked gnus-marked-assoc)))
13064 (setq gnus-newsrc-alist nil)
13065 (while newsrc
13066 (setq group (car newsrc))
13067 (let ((info (nth 2 (gnus-gethash (car group) gnus-newsrc-hashtb))))
13068 (if info
13069 (progn
13070 (setcar (nthcdr 2 info) (cdr (cdr group)))
13071 (setcar (cdr info)
13072 (if (nth 1 group) gnus-level-default-subscribed
13073 gnus-level-default-unsubscribed))
13074 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
13075 (setq gnus-newsrc-alist
13076 (cons
13077 (setq info
13078 (list (car group)
13079 (if (nth 1 group) gnus-level-default-subscribed
13080 gnus-level-default-unsubscribed)
13081 (cdr (cdr group))))
13082 gnus-newsrc-alist)))
13083 (if (setq m (assoc (car group) marked))
13084 (setcdr (cdr (cdr info))
13085 (cons (list (cons 'tick (cdr m))) nil))))
13086 (setq newsrc (cdr newsrc)))
13087 (setq newsrc killed)
13088 (while newsrc
13089 (setcar newsrc (car (car newsrc)))
13090 (setq newsrc (cdr newsrc)))
13091 (setq gnus-killed-list killed))
13092 ;; The .el file version of this variable does not begin with
13093 ;; "options", while the .eld version does, so we just add it if it
13094 ;; isn't there.
13095 (and
13096 gnus-newsrc-options
13097 (progn
13098 (and (not (string-match "^ *options" gnus-newsrc-options))
13099 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
13100 (and (not (string-match "\n$" gnus-newsrc-options))
13101 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
13102 ;; Finally, if we read some options lines, we parse them.
13103 (or (string= gnus-newsrc-options "")
13104 (gnus-newsrc-parse-options gnus-newsrc-options))))
13105
13106 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
13107 (gnus-make-hashtable-from-newsrc-alist)))
13108
13109 (defun gnus-make-newsrc-file (file)
13110 "Make server dependent file name by catenating FILE and server host name."
13111 (let* ((file (expand-file-name file nil))
13112 (real-file (concat file "-" (nth 1 gnus-select-method))))
13113 (if (or (file-exists-p real-file)
13114 (file-exists-p (concat real-file ".el"))
13115 (file-exists-p (concat real-file ".eld")))
13116 real-file file)))
13117
13118 (defun gnus-uncompress-newsrc-alist ()
13119 ;; Uncompress all lists of marked articles in the newsrc assoc.
13120 (let ((newsrc gnus-newsrc-alist)
13121 marked)
13122 (while newsrc
13123 (if (not (setq marked (nth 3 (car newsrc))))
13124 ()
13125 (while marked
13126 (or (eq 'score (car (car marked)))
13127 (eq 'bookmark (car (car marked)))
13128 (eq 'killed (car (car marked)))
13129 (setcdr (car marked) (gnus-uncompress-range (cdr (car marked)))))
13130 (setq marked (cdr marked))))
13131 (setq newsrc (cdr newsrc)))))
13132
13133 (defun gnus-compress-newsrc-alist ()
13134 ;; Compress all lists of marked articles in the newsrc assoc.
13135 (let ((newsrc gnus-newsrc-alist)
13136 marked)
13137 (while newsrc
13138 (if (not (setq marked (nth 3 (car newsrc))))
13139 ()
13140 (while marked
13141 (or (eq 'score (car (car marked)))
13142 (eq 'bookmark (car (car marked)))
13143 (eq 'killed (car (car marked)))
13144 (setcdr (car marked)
13145 (condition-case ()
13146 (gnus-compress-sequence
13147 (sort (cdr (car marked)) '<) t)
13148 (error (cdr (car marked))))))
13149 (setq marked (cdr marked))))
13150 (setq newsrc (cdr newsrc)))))
13151
13152 (defun gnus-newsrc-to-gnus-format ()
13153 (setq gnus-newsrc-options "")
13154 (setq gnus-newsrc-options-n nil)
13155
13156 (or gnus-active-hashtb
13157 (setq gnus-active-hashtb (make-vector 4095 0)))
13158 (let ((buf (current-buffer))
13159 (already-read (> (length gnus-newsrc-alist) 1))
13160 group subscribed options-symbol newsrc Options-symbol
13161 symbol reads num1)
13162 (goto-char (point-min))
13163 ;; We intern the symbol `options' in the active hashtb so that we
13164 ;; can `eq' against it later.
13165 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
13166 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
13167
13168 (while (not (eobp))
13169 ;; We first read the first word on the line by narrowing and
13170 ;; then reading into `gnus-active-hashtb'. Most groups will
13171 ;; already exist in that hashtb, so this will save some string
13172 ;; space.
13173 (narrow-to-region
13174 (point)
13175 (progn (skip-chars-forward "^ \t!:\n") (point)))
13176 (goto-char (point-min))
13177 (setq symbol
13178 (and (/= (point-min) (point-max))
13179 (let ((obarray gnus-active-hashtb)) (read buf))))
13180 (widen)
13181 ;; Now, the symbol we have read is either `options' or a group
13182 ;; name. If it is an options line, we just add it to a string.
13183 (cond
13184 ((or (eq symbol options-symbol)
13185 (eq symbol Options-symbol))
13186 (setq gnus-newsrc-options
13187 ;; This concating is quite inefficient, but since our
13188 ;; thorough studies show that approx 99.37% of all
13189 ;; .newsrc files only contain a single options line, we
13190 ;; don't give a damn, frankly, my dear.
13191 (concat gnus-newsrc-options
13192 (buffer-substring
13193 (gnus-point-at-bol)
13194 ;; Options may continue on the next line.
13195 (or (and (re-search-forward "^[^ \t]" nil 'move)
13196 (progn (beginning-of-line) (point)))
13197 (point)))))
13198 (forward-line -1))
13199 (symbol
13200 (or (boundp symbol) (set symbol nil))
13201 ;; It was a group name.
13202 (setq subscribed (= (following-char) ?:)
13203 group (symbol-name symbol)
13204 reads nil)
13205 (if (eolp)
13206 ;; If the line ends here, this is clearly a buggy line, so
13207 ;; we put point a the beginning of line and let the cond
13208 ;; below do the error handling.
13209 (beginning-of-line)
13210 ;; We skip to the beginning of the ranges.
13211 (skip-chars-forward "!: \t"))
13212 ;; We are now at the beginning of the list of read articles.
13213 ;; We read them range by range.
13214 (while
13215 (cond
13216 ((looking-at "[0-9]+")
13217 ;; We narrow and read a number instead of buffer-substring/
13218 ;; string-to-int because it's faster. narrow/widen is
13219 ;; faster than save-restriction/narrow, and save-restriction
13220 ;; produces a garbage object.
13221 (setq num1 (progn
13222 (narrow-to-region (match-beginning 0) (match-end 0))
13223 (read buf)))
13224 (widen)
13225 ;; If the next character is a dash, then this is a range.
13226 (if (= (following-char) ?-)
13227 (progn
13228 ;; We read the upper bound of the range.
13229 (forward-char 1)
13230 (if (not (looking-at "[0-9]+"))
13231 ;; This is a buggy line, by we pretend that
13232 ;; it's kinda OK. Perhaps the user should be
13233 ;; dinged?
13234 (setq reads (cons num1 reads))
13235 (setq reads
13236 (cons
13237 (cons num1
13238 (progn
13239 (narrow-to-region (match-beginning 0)
13240 (match-end 0))
13241 (read buf)))
13242 reads))
13243 (widen)))
13244 ;; It was just a simple number, so we add it to the
13245 ;; list of ranges.
13246 (setq reads (cons num1 reads)))
13247 ;; If the next char in ?\n, then we have reached the end
13248 ;; of the line and return nil.
13249 (/= (following-char) ?\n))
13250 ((= (following-char) ?\n)
13251 ;; End of line, so we end.
13252 nil)
13253 (t
13254 ;; Not numbers and not eol, so this might be a buggy
13255 ;; line...
13256 (or (eobp)
13257 ;; If it was eob instead of ?\n, we allow it.
13258 (progn
13259 ;; The line was buggy.
13260 (setq group nil)
13261 (gnus-message 3 "Mangled line: %s"
13262 (buffer-substring (gnus-point-at-bol)
13263 (gnus-point-at-eol)))
13264 (ding)
13265 (sit-for 1)))
13266 nil))
13267 ;; Skip past ", ". Spaces are illegal in these ranges, but
13268 ;; we allow them, because it's a common mistake to put a
13269 ;; space after the comma.
13270 (skip-chars-forward ", "))
13271
13272 ;; We have already read .newsrc.eld, so we gently update the
13273 ;; data in the hash table with the information we have just
13274 ;; read.
13275 (if (not group)
13276 ()
13277 (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
13278 level)
13279 (if info
13280 ;; There is an entry for this file in the alist.
13281 (progn
13282 (setcar (nthcdr 2 info) (nreverse reads))
13283 ;; We update the level very gently. In fact, we
13284 ;; only change it if there's been a status change
13285 ;; from subscribed to unsubscribed, or vice versa.
13286 (setq level (nth 1 info))
13287 (cond ((and (<= level gnus-level-subscribed)
13288 (not subscribed))
13289 (setq level (if reads
13290 gnus-level-default-unsubscribed
13291 (1+ gnus-level-default-unsubscribed))))
13292 ((and (> level gnus-level-subscribed) subscribed)
13293 (setq level gnus-level-default-subscribed)))
13294 (setcar (cdr info) level))
13295 ;; This is a new group.
13296 (setq info (list group
13297 (if subscribed
13298 gnus-level-default-subscribed
13299 (if reads
13300 (1+ gnus-level-subscribed)
13301 gnus-level-default-unsubscribed))
13302 (nreverse reads))))
13303 (setq newsrc (cons info newsrc))))))
13304 (forward-line 1))
13305
13306 (setq newsrc (nreverse newsrc))
13307
13308 (if (not already-read)
13309 ()
13310 ;; We now have two newsrc lists - `newsrc', which is what we
13311 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
13312 ;; what we've read from .newsrc.eld. We have to merge these
13313 ;; lists. We do this by "attaching" any (foreign) groups in the
13314 ;; gnus-newsrc-alist to the (native) group that precedes them.
13315 (let ((rc (cdr gnus-newsrc-alist))
13316 (prev gnus-newsrc-alist)
13317 entry mentry)
13318 (while rc
13319 (or (null (nth 4 (car rc))) ; It's a native group.
13320 (assoc (car (car rc)) newsrc) ; It's already in the alist.
13321 (if (setq entry (assoc (car (car prev)) newsrc))
13322 (setcdr (setq mentry (memq entry newsrc))
13323 (cons (car rc) (cdr mentry)))
13324 (setq newsrc (cons (car rc) newsrc))))
13325 (setq prev rc
13326 rc (cdr rc)))))
13327
13328 (setq gnus-newsrc-alist newsrc)
13329 ;; We make the newsrc hashtb.
13330 (gnus-make-hashtable-from-newsrc-alist)
13331
13332 ;; Finally, if we read some options lines, we parse them.
13333 (or (string= gnus-newsrc-options "")
13334 (gnus-newsrc-parse-options gnus-newsrc-options))))
13335
13336 ;; Parse options lines to find "options -n !all rec.all" and stuff.
13337 ;; The return value will be a list on the form
13338 ;; ((regexp1 . ignore)
13339 ;; (regexp2 . subscribe)...)
13340 ;; When handling new newsgroups, groups that match a `ignore' regexp
13341 ;; will be ignored, and groups that match a `subscribe' regexp will be
13342 ;; subscribed. A line like
13343 ;; options -n !all rec.all
13344 ;; will lead to a list that looks like
13345 ;; (("^rec\\..+" . subscribe)
13346 ;; ("^.+" . ignore))
13347 ;; So all "rec.*" groups will be subscribed, while all the other
13348 ;; groups will be ignored. Note that "options -n !all rec.all" is very
13349 ;; different from "options -n rec.all !all".
13350 (defun gnus-newsrc-parse-options (options)
13351 (let (out eol)
13352 (save-excursion
13353 (gnus-set-work-buffer)
13354 (insert (regexp-quote options))
13355 ;; First we treat all continuation lines.
13356 (goto-char (point-min))
13357 (while (re-search-forward "\n[ \t]+" nil t)
13358 (replace-match " " t t))
13359 ;; Then we transform all "all"s into ".+"s.
13360 (goto-char (point-min))
13361 (while (re-search-forward "\\ball\\b" nil t)
13362 (replace-match ".+" t t))
13363 (goto-char (point-min))
13364 ;; We remove all other options than the "-n" ones.
13365 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
13366 (replace-match " ")
13367 (forward-char -1))
13368 (goto-char (point-min))
13369
13370 ;; We are only interested in "options -n" lines - we
13371 ;; ignore the other option lines.
13372 (while (re-search-forward "[ \t]-n" nil t)
13373 (setq eol
13374 (or (save-excursion
13375 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
13376 (- (point) 2)))
13377 (gnus-point-at-eol)))
13378 ;; Search for all "words"...
13379 (while (re-search-forward "[^ \t,\n]+" eol t)
13380 (if (= (char-after (match-beginning 0)) ?!)
13381 ;; If the word begins with a bang (!), this is a "not"
13382 ;; spec. We put this spec (minus the bang) and the
13383 ;; symbol `ignore' into the list.
13384 (setq out (cons (cons (concat
13385 "^" (buffer-substring
13386 (1+ (match-beginning 0))
13387 (match-end 0)))
13388 'ignore) out))
13389 ;; There was no bang, so this is a "yes" spec.
13390 (setq out (cons (cons (concat
13391 "^" (buffer-substring (match-beginning 0)
13392 (match-end 0)))
13393 'subscribe) out)))))
13394
13395 (setq gnus-newsrc-options-n out))))
13396
13397
13398 (defun gnus-save-newsrc-file ()
13399 "Save .newsrc file."
13400 ;; Note: We cannot save .newsrc file if all newsgroups are removed
13401 ;; from the variable gnus-newsrc-alist.
13402 (and (or gnus-newsrc-alist gnus-killed-list)
13403 gnus-current-startup-file
13404 (progn
13405 (run-hooks 'gnus-save-newsrc-hook)
13406 (save-excursion
13407 (if (and gnus-use-dribble-file
13408 (or (not gnus-dribble-buffer)
13409 (not (buffer-name gnus-dribble-buffer))
13410 (zerop (save-excursion
13411 (set-buffer gnus-dribble-buffer)
13412 (buffer-size)))))
13413 (gnus-message 4 "(No changes need to be saved)")
13414 (if gnus-save-newsrc-file
13415 (progn
13416 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
13417 ;; Make backup file of master newsrc.
13418 (gnus-gnus-to-newsrc-format)
13419 (gnus-message 5 "Saving %s...done"
13420 gnus-current-startup-file)))
13421 ;; Quickly loadable .newsrc.
13422 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
13423 (make-local-variable 'version-control)
13424 (setq version-control 'never)
13425 (setq buffer-file-name (concat gnus-current-startup-file ".eld"))
13426 (gnus-add-current-to-buffer-list)
13427 (buffer-disable-undo (current-buffer))
13428 (erase-buffer)
13429 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
13430 (gnus-gnus-to-quick-newsrc-format)
13431 (save-buffer)
13432 (kill-buffer (current-buffer))
13433 (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file)
13434 (gnus-dribble-delete-file))))))
13435
13436 (defun gnus-gnus-to-quick-newsrc-format ()
13437 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
13438 (insert ";; Gnus startup file.\n")
13439 (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
13440 (insert ";; to read .newsrc.\n")
13441 (insert "(setq gnus-newsrc-file-version "
13442 (prin1-to-string gnus-version) ")\n")
13443 (let ((variables gnus-variable-list)
13444 (inhibit-quit t)
13445 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
13446 variable)
13447 ;; insert lisp expressions.
13448 (gnus-compress-newsrc-alist)
13449 (while variables
13450 (setq variable (car variables))
13451 (and (boundp variable)
13452 (symbol-value variable)
13453 (or gnus-save-killed-list (not (eq variable 'gnus-killed-list)))
13454 (insert "(setq " (symbol-name variable) " '"
13455 (prin1-to-string (symbol-value variable))
13456 ")\n"))
13457 (setq variables (cdr variables)))
13458 (gnus-uncompress-newsrc-alist)))
13459
13460
13461 (defun gnus-gnus-to-newsrc-format ()
13462 ;; Generate and save the .newsrc file.
13463 (let ((newsrc (cdr gnus-newsrc-alist))
13464 info ranges range)
13465 (save-excursion
13466 (set-buffer (create-file-buffer gnus-current-startup-file))
13467 (setq buffer-file-name gnus-current-startup-file)
13468 (buffer-disable-undo (current-buffer))
13469 (erase-buffer)
13470 ;; Write options.
13471 (if gnus-newsrc-options (insert gnus-newsrc-options))
13472 ;; Write subscribed and unsubscribed.
13473 (while newsrc
13474 (setq info (car newsrc))
13475 (if (not (nth 4 info)) ;Don't write foreign groups to .newsrc.
13476 (progn
13477 (insert (car info) (if (> (nth 1 info) gnus-level-subscribed)
13478 "!" ":"))
13479 (if (setq ranges (nth 2 info))
13480 (progn
13481 (insert " ")
13482 (if (not (listp (cdr ranges)))
13483 (if (= (car ranges) (cdr ranges))
13484 (insert (int-to-string (car ranges)))
13485 (insert (int-to-string (car ranges)) "-"
13486 (int-to-string (cdr ranges))))
13487 (while ranges
13488 (setq range (car ranges)
13489 ranges (cdr ranges))
13490 (if (or (atom range) (= (car range) (cdr range)))
13491 (insert (int-to-string
13492 (or (and (atom range) range)
13493 (car range))))
13494 (insert (int-to-string (car range)) "-"
13495 (int-to-string (cdr range))))
13496 (if ranges (insert ","))))))
13497 (insert "\n")))
13498 (setq newsrc (cdr newsrc)))
13499 (make-local-variable 'version-control)
13500 (setq version-control 'never)
13501 ;; It has been reported that sometime the modtime on the .newsrc
13502 ;; file seems to be off. We really do want to overwrite it, so
13503 ;; we clear the modtime here before saving. It's a bit odd,
13504 ;; though...
13505 ;; sometimes the modtime clear isn't sufficient. most brute force:
13506 ;; delete the silly thing entirely first. but this fails to provide
13507 ;; such niceties as .newsrc~ creation.
13508 (if gnus-modtime-botch
13509 (delete-file gnus-startup-file)
13510 (clear-visited-file-modtime))
13511 (save-buffer)
13512 (kill-buffer (current-buffer)))))
13513
13514 (defun gnus-read-all-descriptions-files ()
13515 (let ((methods (cons gnus-select-method gnus-secondary-select-methods)))
13516 (while methods
13517 (gnus-read-descriptions-file (car methods))
13518 (setq methods (cdr methods)))
13519 t))
13520
13521 (defun gnus-read-descriptions-file (&optional method)
13522 (let ((method (or method gnus-select-method)))
13523 ;; We create the hashtable whether we manage to read the desc file
13524 ;; to avoid trying to re-read after a failed read.
13525 (or gnus-description-hashtb
13526 (setq gnus-description-hashtb
13527 (gnus-make-hashtable (length gnus-active-hashtb))))
13528 ;; Mark this method's desc file as read.
13529 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
13530 gnus-description-hashtb)
13531
13532 (gnus-message 5 "Reading descriptions file via %s..." (car method))
13533 (cond
13534 ((not (gnus-check-server method))
13535 (gnus-message 1 "Couldn't open server")
13536 nil)
13537 ((not (gnus-request-list-newsgroups method))
13538 (gnus-message 1 "Couldn't read newsgroups descriptions")
13539 nil)
13540 (t
13541 (let (group)
13542 (save-excursion
13543 (save-restriction
13544 (set-buffer nntp-server-buffer)
13545 (goto-char (point-min))
13546 (if (or (search-forward "\n.\n" nil t)
13547 (goto-char (point-max)))
13548 (progn
13549 (beginning-of-line)
13550 (narrow-to-region (point-min) (point))))
13551 (goto-char (point-min))
13552 (while (not (eobp))
13553 ;; If we get an error, we set group to 0, which is not a
13554 ;; symbol...
13555 (setq group
13556 (condition-case ()
13557 (let ((obarray gnus-description-hashtb))
13558 ;; Group is set to a symbol interned in this
13559 ;; hash table.
13560 (read nntp-server-buffer))
13561 (error 0)))
13562 (skip-chars-forward " \t")
13563 ;; ... which leads to this line being effectively ignored.
13564 (and (symbolp group)
13565 (set group (buffer-substring
13566 (point) (progn (end-of-line) (point)))))
13567 (forward-line 1))))
13568 (gnus-message 5 "Reading descriptions file...done")
13569 t)))))
13570
13571 (defun gnus-group-get-description (group)
13572 ;; Get the description of a group by sending XGTITLE to the server.
13573 (and (gnus-request-group-description group)
13574 (save-excursion
13575 (set-buffer nntp-server-buffer)
13576 (goto-char (point-min))
13577 (and (looking-at "[^ \t]+[ \t]+\\(.*\\)")
13578 (buffer-substring (match-beginning 1) (match-end 1))))))
13579
13580 ;;;
13581 ;;; Server
13582 ;;;
13583
13584 (defvar gnus-server-mode-hook nil
13585 "Hook run in `gnus-server-mode' buffers.")
13586
13587 (defconst gnus-server-line-format " {%(%h:%w%)}\n"
13588 "Format of server lines.
13589 It works along the same lines as a normal formatting string,
13590 with some simple extensions.")
13591
13592 (defvar gnus-server-mode-line-format "Gnus List of servers"
13593 "The format specification for the server mode line.")
13594
13595 (defconst gnus-server-line-format-alist
13596 (list (list ?h 'how ?s)
13597 (list ?n 'name ?s)
13598 (list ?w 'where ?s)
13599 ))
13600
13601 (defconst gnus-server-mode-line-format-alist
13602 (list (list ?S 'news-server ?s)
13603 (list ?M 'news-method ?s)
13604 (list ?u 'user-defined ?s)))
13605
13606 (defvar gnus-server-line-format-spec nil)
13607 (defvar gnus-server-mode-line-format-spec nil)
13608 (defvar gnus-server-killed-servers nil)
13609
13610 (defvar gnus-server-mode-map nil)
13611 (put 'gnus-server-mode 'mode-class 'special)
13612
13613 (if gnus-server-mode-map
13614 nil
13615 (setq gnus-server-mode-map (make-sparse-keymap))
13616 (suppress-keymap gnus-server-mode-map)
13617 (define-key gnus-server-mode-map " " 'gnus-server-read-server)
13618 (define-key gnus-server-mode-map "\r" 'gnus-server-read-server)
13619 (define-key gnus-server-mode-map gnus-mouse-2 'gnus-server-pick-server)
13620 (define-key gnus-server-mode-map "q" 'gnus-server-exit)
13621 (define-key gnus-server-mode-map "l" 'gnus-server-list-servers)
13622 (define-key gnus-server-mode-map "k" 'gnus-server-kill-server)
13623 (define-key gnus-server-mode-map "y" 'gnus-server-yank-server)
13624 (define-key gnus-server-mode-map "c" 'gnus-server-copy-server)
13625 (define-key gnus-server-mode-map "a" 'gnus-server-add-server)
13626 (define-key gnus-server-mode-map "e" 'gnus-server-edit-server))
13627
13628 (defun gnus-server-mode ()
13629 "Major mode for listing and editing servers.
13630
13631 All normal editing commands are switched off.
13632 \\<gnus-server-mode-map>
13633
13634 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
13635
13636 The following commands are available:
13637
13638 \\{gnus-server-mode-map}"
13639 (interactive)
13640 (if gnus-visual (gnus-server-make-menu-bar))
13641 (kill-all-local-variables)
13642 (gnus-simplify-mode-line)
13643 (setq major-mode 'gnus-server-mode)
13644 (setq mode-name "Server")
13645 ; (gnus-group-set-mode-line)
13646 (setq mode-line-process nil)
13647 (use-local-map gnus-server-mode-map)
13648 (buffer-disable-undo (current-buffer))
13649 (setq truncate-lines t)
13650 (setq buffer-read-only t)
13651 (run-hooks 'gnus-server-mode-hook))
13652
13653 (defun gnus-server-insert-server-line (sformat name method)
13654 (let* ((sformat (or sformat gnus-server-line-format-spec))
13655 (how (car method))
13656 (where (nth 1 method))
13657 b)
13658 (beginning-of-line)
13659 (setq b (point))
13660 ;; Insert the text.
13661 (insert (eval sformat))
13662 (add-text-properties b (1+ b) (list 'gnus-server (intern name)))))
13663
13664 (defun gnus-server-setup-buffer ()
13665 (if (get-buffer gnus-server-buffer)
13666 ()
13667 (save-excursion
13668 (set-buffer (get-buffer-create gnus-server-buffer))
13669 (gnus-server-mode)
13670 (and gnus-carpal (gnus-carpal-setup-buffer 'server)))))
13671
13672 (defun gnus-server-prepare ()
13673 (setq gnus-server-mode-line-format-spec
13674 (gnus-parse-format gnus-server-mode-line-format
13675 gnus-server-mode-line-format-alist))
13676 (setq gnus-server-line-format-spec
13677 (gnus-parse-format gnus-server-line-format
13678 gnus-server-line-format-alist))
13679 (let ((alist gnus-server-alist)
13680 (buffer-read-only nil))
13681 (erase-buffer)
13682 (while alist
13683 (gnus-server-insert-server-line nil (car (car alist)) (cdr (car alist)))
13684 (setq alist (cdr alist))))
13685 (goto-char (point-min))
13686 (gnus-server-position-cursor))
13687
13688 (defun gnus-server-server-name ()
13689 (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
13690 (and server (symbol-name server))))
13691
13692 (defalias 'gnus-server-position-cursor 'gnus-goto-colon)
13693
13694 (defconst gnus-server-edit-buffer "*Gnus edit server*")
13695
13696 (defun gnus-server-update-server (server)
13697 (save-excursion
13698 (set-buffer gnus-server-buffer)
13699 (let ((buffer-read-only nil)
13700 (info (cdr (assoc server gnus-server-alist))))
13701 (gnus-dribble-enter
13702 (concat "(gnus-server-set-info \"" server "\" '"
13703 (prin1-to-string info) ")"))
13704 ;; Buffer may be narrowed.
13705 (save-restriction
13706 (widen)
13707 (if (gnus-server-goto-server server)
13708 (delete-region (progn (beginning-of-line) (point))
13709 (progn (forward-line 1) (point))))
13710 (let ((entry (assoc server gnus-server-alist)))
13711 (gnus-server-insert-server-line nil (car entry) (cdr entry))
13712 (gnus-server-position-cursor))))))
13713
13714 (defun gnus-server-set-info (server info)
13715 ;; Enter a select method into the virtual server alist.
13716 (gnus-dribble-enter
13717 (concat "(gnus-server-set-info \"" server "\" '"
13718 (prin1-to-string info) ")"))
13719 (let* ((server (nth 1 info))
13720 (entry (assoc server gnus-server-alist)))
13721 (if entry (setcdr entry info)
13722 (setq gnus-server-alist
13723 (nconc gnus-server-alist (list (cons server info)))))))
13724
13725 (defun gnus-server-to-method (server)
13726 ;; Map virtual server names to select methods.
13727 (or (and (equal server "native") gnus-select-method)
13728 (cdr (assoc server gnus-server-alist))))
13729
13730 (defun gnus-server-extend-method (group method)
13731 ;; This function "extends" a virtual server. If the server is
13732 ;; "hello", and the select method is ("hello" (my-var "something"))
13733 ;; in the group "alt.alt", this will result in a new virtual server
13734 ;; called "helly+alt.alt".
13735 (let ((entry
13736 (gnus-copy-sequence
13737 (if (equal (car method) "native") gnus-select-method
13738 (cdr (assoc (car method) gnus-server-alist))))))
13739 (setcar (cdr entry) (concat (nth 1 entry) "+" group))
13740 (nconc entry (cdr method))))
13741
13742 (defun gnus-server-get-method (group method)
13743 ;; Input either a server name, and extended server name, or a
13744 ;; select method, and return a select method.
13745 (cond ((stringp method)
13746 (gnus-server-to-method method))
13747 ((and (stringp (car method)) group)
13748 (gnus-server-extend-method group method))
13749 (t
13750 (gnus-server-add-address method))))
13751
13752 (defun gnus-server-add-address (method)
13753 (let ((method-name (symbol-name (car method))))
13754 (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
13755 (not (assq (intern (concat method-name "-address")) method)))
13756 (append method (list (list (intern (concat method-name "-address"))
13757 (nth 1 method))))
13758 method)))
13759
13760 (defun gnus-server-equal (s1 s2)
13761 (or (equal s1 s2)
13762 (and (= (length s1) (length s2))
13763 (progn
13764 (while (and s1 (member (car s1) s2))
13765 (setq s1 (cdr s1)))
13766 (null s1)))))
13767
13768 ;;; Interactive server functions.
13769
13770 (defun gnus-server-kill-server (server)
13771 "Kill the server on the current line."
13772 (interactive (list (gnus-server-server-name)))
13773 (or (gnus-server-goto-server server)
13774 (if server (error "No such server: %s" server)
13775 (error "No server on the current line")))
13776 (gnus-dribble-enter "")
13777 (let ((buffer-read-only nil))
13778 (delete-region (progn (beginning-of-line) (point))
13779 (progn (forward-line 1) (point))))
13780 (setq gnus-server-killed-servers
13781 (cons (assoc server gnus-server-alist) gnus-server-killed-servers))
13782 (setq gnus-server-alist (delq (car gnus-server-killed-servers)
13783 gnus-server-alist))
13784 (gnus-server-position-cursor))
13785
13786 (defun gnus-server-yank-server ()
13787 "Yank the previously killed server."
13788 (interactive)
13789 (or gnus-server-killed-servers
13790 (error "No killed servers to be yanked"))
13791 (let ((alist gnus-server-alist)
13792 (server (gnus-server-server-name))
13793 (killed (car gnus-server-killed-servers)))
13794 (if (not server)
13795 (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
13796 (if (string= server (car (car gnus-server-alist)))
13797 (setq gnus-server-alist (cons killed gnus-server-alist))
13798 (while (and (cdr alist)
13799 (not (string= server (car (car (cdr alist))))))
13800 (setq alist (cdr alist)))
13801 (setcdr alist (cons killed (cdr alist)))))
13802 (gnus-server-update-server (car killed))
13803 (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
13804 (gnus-server-position-cursor)))
13805
13806 (defun gnus-server-exit ()
13807 "Return to the group buffer."
13808 (interactive)
13809 (kill-buffer (current-buffer))
13810 (switch-to-buffer gnus-group-buffer))
13811
13812 (defun gnus-server-list-servers ()
13813 "List all available servers."
13814 (interactive)
13815 (let ((cur (gnus-server-server-name)))
13816 (gnus-server-prepare)
13817 (if cur (gnus-server-goto-server cur)
13818 (goto-char (point-max))
13819 (forward-line -1))
13820 (gnus-server-position-cursor)))
13821
13822 (defun gnus-server-copy-server (from to)
13823 (interactive
13824 (list
13825 (or (gnus-server-server-name)
13826 (error "No server on the current line"))
13827 (read-string "Copy to: ")))
13828 (or from (error "No server on current line"))
13829 (or (and to (not (string= to ""))) (error "No name to copy to"))
13830 (and (assoc to gnus-server-alist) (error "%s already exists" to))
13831 (or (assoc from gnus-server-alist)
13832 (error "%s: no such server" from))
13833 (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist))))
13834 (setcar to-entry to)
13835 (setcar (nthcdr 2 to-entry) to)
13836 (setq gnus-server-killed-servers
13837 (cons to-entry gnus-server-killed-servers))
13838 (gnus-server-yank-server)))
13839
13840 (defun gnus-server-add-server (how where)
13841 (interactive
13842 (list (intern (completing-read "Server method: "
13843 gnus-valid-select-methods nil t))
13844 (read-string "Server name: ")))
13845 (setq gnus-server-killed-servers
13846 (cons (list where how where) gnus-server-killed-servers))
13847 (gnus-server-yank-server))
13848
13849 (defun gnus-server-goto-server (server)
13850 "Jump to a server line."
13851 (interactive
13852 (list (completing-read "Goto server: " gnus-server-alist nil t)))
13853 (let ((to (text-property-any (point-min) (point-max)
13854 'gnus-server (intern server))))
13855 (and to
13856 (progn
13857 (goto-char to)
13858 (gnus-server-position-cursor)))))
13859
13860 (defun gnus-server-edit-server (server)
13861 "Edit the server on the current line."
13862 (interactive (list (gnus-server-server-name)))
13863 (or server
13864 (error "No server on current line"))
13865 (let ((winconf (current-window-configuration)))
13866 (get-buffer-create gnus-server-edit-buffer)
13867 (gnus-configure-windows 'edit-server)
13868 (gnus-add-current-to-buffer-list)
13869 (emacs-lisp-mode)
13870 (make-local-variable 'gnus-prev-winconf)
13871 (setq gnus-prev-winconf winconf)
13872 (use-local-map (copy-keymap (current-local-map)))
13873 (let ((done-func '(lambda ()
13874 "Exit editing mode and update the information."
13875 (interactive)
13876 (gnus-server-edit-server-done 'group))))
13877 (setcar (cdr (nth 4 done-func)) server)
13878 (local-set-key "\C-c\C-c" done-func))
13879 (erase-buffer)
13880 (insert ";; Type `C-c C-c' after you have edited the server.\n\n")
13881 (insert (pp-to-string (cdr (assoc server gnus-server-alist))))))
13882
13883 (defun gnus-server-edit-server-done (server)
13884 (interactive)
13885 (set-buffer (get-buffer-create gnus-server-edit-buffer))
13886 (goto-char (point-min))
13887 (let ((form (read (current-buffer)))
13888 (winconf gnus-prev-winconf))
13889 (gnus-server-set-info server form)
13890 (kill-buffer (current-buffer))
13891 (and winconf (set-window-configuration winconf))
13892 (set-buffer gnus-server-buffer)
13893 (gnus-server-update-server (gnus-server-server-name))
13894 (gnus-server-list-servers)
13895 (gnus-server-position-cursor)))
13896
13897 (defun gnus-server-read-server (server)
13898 "Browse a server."
13899 (interactive (list (gnus-server-server-name)))
13900 (gnus-browse-foreign-server (gnus-server-to-method server) (current-buffer)))
13901
13902 (defun gnus-mouse-pick-server (e)
13903 (interactive "e")
13904 (mouse-set-point e)
13905 (gnus-server-read-server (gnus-server-server-name)))
13906
13907 ;;;
13908 ;;; entry points into gnus-score.el
13909 ;;;
13910
13911 ;;; Finding score files.
13912
13913 (defvar gnus-global-score-files nil
13914 "*List of global score files and directories.
13915 Set this variable if you want to use people's score files. One entry
13916 for each score file or each score file directory. Gnus will decide
13917 by itself what score files are applicable to which group.
13918
13919 Say you want to use the single score file
13920 \"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
13921 score files in the \"/ftp.some-where:/pub/score\" directory.
13922
13923 (setq gnus-global-score-files
13924 '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\"
13925 \"/ftp.some-where:/pub/score\"))")
13926
13927 (defun gnus-score-score-files (group)
13928 "Return a list of all possible score files."
13929 ;; Search and set any global score files.
13930 (and gnus-global-score-files
13931 (or gnus-internal-global-score-files
13932 (gnus-score-search-global-directories gnus-global-score-files)))
13933 ;; Fix the kill-file dir variable.
13934 (setq gnus-kill-files-directory
13935 (file-name-as-directory
13936 (or gnus-kill-files-directory "~/News/")))
13937 ;; If we can't read it, there are no score files.
13938 (if (not (file-exists-p (expand-file-name gnus-kill-files-directory)))
13939 (setq gnus-score-file-list nil)
13940 (if (gnus-use-long-file-name 'not-score)
13941 ;; We want long file names.
13942 (if (or (not gnus-score-file-list)
13943 (not (car gnus-score-file-list))
13944 (gnus-file-newer-than gnus-kill-files-directory
13945 (car gnus-score-file-list)))
13946 (setq gnus-score-file-list
13947 (cons (nth 5 (file-attributes gnus-kill-files-directory))
13948 (nreverse
13949 (directory-files
13950 gnus-kill-files-directory t
13951 (gnus-score-file-regexp))))))
13952 ;; We do not use long file names, so we have to do some
13953 ;; directory traversing.
13954 (let ((mdir (length (expand-file-name gnus-kill-files-directory)))
13955 (suffixes (list gnus-score-file-suffix gnus-adaptive-file-suffix))
13956 dir files suffix)
13957 (while suffixes
13958 (setq dir (expand-file-name
13959 (concat gnus-kill-files-directory
13960 (gnus-replace-chars-in-string group ?. ?/))))
13961 (setq dir (gnus-replace-chars-in-string dir ?: ?/))
13962 (setq suffix (car suffixes)
13963 suffixes (cdr suffixes))
13964 (if (file-exists-p (concat dir "/" suffix))
13965 (setq files (cons (concat dir "/" suffix) files)))
13966 (while (>= (1+ (length dir)) mdir)
13967 (and (file-exists-p (concat dir "/all/" suffix))
13968 (setq files (cons (concat dir "/all/" suffix) files)))
13969 (string-match "/[^/]*$" dir)
13970 (setq dir (substring dir 0 (match-beginning 0)))))
13971 (setq gnus-score-file-list
13972 (cons nil (nreverse files)))))
13973 (cdr gnus-score-file-list)))
13974
13975 (defun gnus-score-file-regexp ()
13976 (concat "\\(" gnus-score-file-suffix
13977 "\\|" gnus-adaptive-file-suffix "\\)$"))
13978
13979 (defun gnus-score-find-bnews (group)
13980 "Return a list of score files for GROUP.
13981 The score files are those files in the ~/News directory which matches
13982 GROUP using BNews sys file syntax."
13983 (let* ((sfiles (append (gnus-score-score-files group)
13984 gnus-internal-global-score-files))
13985 (kill-dir (file-name-as-directory
13986 (expand-file-name gnus-kill-files-directory)))
13987 (klen (length kill-dir))
13988 ofiles not-match regexp)
13989 (save-excursion
13990 (set-buffer (get-buffer-create "*gnus score files*"))
13991 (buffer-disable-undo (current-buffer))
13992 ;; Go through all score file names and create regexp with them
13993 ;; as the source.
13994 (while sfiles
13995 (erase-buffer)
13996 (insert (car sfiles))
13997 (goto-char (point-min))
13998 ;; First remove the suffix itself.
13999 (re-search-forward (concat "." (gnus-score-file-regexp)))
14000 (replace-match "" t t)
14001 (goto-char (point-min))
14002 (if (looking-at (regexp-quote kill-dir))
14003 ;; If the file name was just "SCORE", `klen' is one character
14004 ;; too much.
14005 (delete-char (min (1- (point-max)) klen))
14006 (goto-char (point-max))
14007 (search-backward "/")
14008 (delete-region (1+ (point)) (point-min)))
14009 ;; If short file names were used, we have to translate slashes.
14010 (goto-char (point-min))
14011 (while (re-search-forward "[/:]" nil t)
14012 (replace-match "." t t))
14013 ;; Kludge to get rid of "nntp+" problems.
14014 (goto-char (point-min))
14015 (and (looking-at "nn[a-z]+\\+")
14016 (progn
14017 (search-forward "+")
14018 (forward-char -1)
14019 (insert "\\")))
14020 ;; Translate ".all" to "[./].*";
14021 (while (search-forward ".all" nil t)
14022 (replace-match "[./:].*" t t))
14023 (goto-char (point-min))
14024 ;; Translate "all" to ".*".
14025 (while (search-forward "all" nil t)
14026 (replace-match ".*" t t))
14027 (goto-char (point-min))
14028 ;; Deal with "not."s.
14029 (if (looking-at "not.")
14030 (progn
14031 (setq not-match t)
14032 (setq regexp (buffer-substring 5 (point-max))))
14033 (setq regexp (buffer-substring 1 (point-max)))
14034 (setq not-match nil))
14035 ;; Finally - if this resulting regexp matches the group name,
14036 ;; we add this score file to the list of score files
14037 ;; applicable to this group.
14038 (if (or (and not-match
14039 (not (string-match regexp group)))
14040 (and (not not-match)
14041 (string-match regexp group)))
14042 (setq ofiles (cons (car sfiles) ofiles)))
14043 (setq sfiles (cdr sfiles)))
14044 (kill-buffer (current-buffer))
14045 ;; Slight kludge here - the last score file returned should be
14046 ;; the local score file, whether it exists or not. This is so
14047 ;; that any score commands the user enters will go to the right
14048 ;; file, and not end up in some global score file.
14049 (let ((localscore
14050 (expand-file-name
14051 (if (gnus-use-long-file-name 'not-score)
14052 (concat gnus-kill-files-directory group "."
14053 gnus-score-file-suffix)
14054 (concat gnus-kill-files-directory
14055 (gnus-replace-chars-in-string group ?. ?/ ?: ?/)
14056 "/" gnus-score-file-suffix)))))
14057 ;; The local score file might already be there, but it's
14058 ;; supposed to be the very last file, so we delete it from the
14059 ;; list if it's already there, and add it to the head of the
14060 ;; list.
14061 (setq ofiles (cons localscore (delete localscore ofiles))))
14062 (nreverse ofiles))))
14063
14064 (defun gnus-score-find-single (group)
14065 "Return list containing the score file for GROUP."
14066 (list (gnus-score-file-name group gnus-adaptive-file-suffix)
14067 (gnus-score-file-name group)))
14068
14069 (defun gnus-score-find-hierarchical (group)
14070 "Return list of score files for GROUP.
14071 This includes the score file for the group and all its parents."
14072 (let ((all (copy-sequence '(nil)))
14073 (start 0))
14074 (while (string-match "\\." group (1+ start))
14075 (setq start (match-beginning 0))
14076 (setq all (cons (substring group 0 start) all)))
14077 (setq all (cons group all))
14078 (nconc
14079 (mapcar (lambda (newsgroup)
14080 (gnus-score-file-name newsgroup gnus-adaptive-file-suffix))
14081 (setq all (nreverse all)))
14082 (mapcar 'gnus-score-file-name all))))
14083
14084 (defvar gnus-score-file-alist-cache nil)
14085
14086 (defun gnus-score-find-alist (group)
14087 "Return list of score files for GROUP.
14088 The list is determined from the variable gnus-score-file-alist."
14089 (let ((alist gnus-score-file-multiple-match-alist)
14090 score-files)
14091 ;; if this group has been seen before, return the cached entry
14092 (if (setq score-files (assoc group gnus-score-file-alist-cache))
14093 (cdr score-files) ;ensures caching groups with no matches
14094 ;; handle the multiple match alist
14095 (while alist
14096 (and (string-match (car (car alist)) group)
14097 (setq score-files
14098 (nconc score-files (copy-sequence (cdr (car alist))))))
14099 (setq alist (cdr alist)))
14100 (setq alist gnus-score-file-single-match-alist)
14101 ;; handle the single match alist
14102 (while alist
14103 (and (string-match (car (car alist)) group)
14104 ;; progn used just in case ("regexp") has no files
14105 ;; and score-files is still nil. -sj
14106 ;; this can be construed as a "stop searching here" feature :>
14107 ;; and used to simplify regexps in the single-alist
14108 (progn
14109 (setq score-files
14110 (nconc score-files (copy-sequence (cdr (car alist)))))
14111 (setq alist nil)))
14112 (setq alist (cdr alist)))
14113 ;; cache the score files
14114 (setq gnus-score-file-alist-cache
14115 (cons (cons group score-files) gnus-score-file-alist-cache))
14116 score-files)))
14117
14118
14119 (defun gnus-possibly-score-headers (&optional trace)
14120 (let ((func gnus-score-find-score-files-function)
14121 score-files)
14122 (and func (not (listp func))
14123 (setq func (list func)))
14124 ;; Go through all the functions for finding score files (or actual
14125 ;; scores) and add them to a list.
14126 (setq score-files (gnus-score-find-alist gnus-newsgroup-name))
14127 (while func
14128 (and (symbolp (car func))
14129 (fboundp (car func))
14130 (setq score-files
14131 (nconc score-files (funcall (car func) gnus-newsgroup-name))))
14132 (setq func (cdr func)))
14133 (if score-files (gnus-score-headers score-files trace))))
14134
14135 (defun gnus-score-file-name (newsgroup &optional suffix)
14136 "Return the name of a score file for NEWSGROUP."
14137 (let ((suffix (or suffix gnus-score-file-suffix)))
14138 (cond
14139 ((or (null newsgroup)
14140 (string-equal newsgroup ""))
14141 ;; The global score file is placed at top of the directory.
14142 (expand-file-name
14143 suffix (or gnus-kill-files-directory "~/News")))
14144 ((gnus-use-long-file-name 'not-score)
14145 ;; Append ".SCORE" to newsgroup name.
14146 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
14147 "." suffix)
14148 (or gnus-kill-files-directory "~/News")))
14149 (t
14150 ;; Place "SCORE" under the hierarchical directory.
14151 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
14152 "/" suffix)
14153 (or gnus-kill-files-directory "~/News"))))))
14154
14155 (defun gnus-score-search-global-directories (files)
14156 "Scan all global score directories for score files."
14157 ;; Set the variable `gnus-internal-global-score-files' to all
14158 ;; available global score files.
14159 (interactive (list gnus-global-score-files))
14160 (let (out)
14161 (while files
14162 (if (string-match "/$" (car files))
14163 (setq out (nconc (directory-files
14164 (car files) t
14165 (concat (gnus-score-file-regexp) "$"))))
14166 (setq out (cons (car files) out)))
14167 (setq files (cdr files)))
14168 (setq gnus-internal-global-score-files out)))
14169
14170 ;; Allow redefinition of Gnus functions.
14171
14172 (gnus-ems-redefine)
14173
14174 (provide 'gnus)
14175
14176 ;;; gnus.el ends here